| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2013 Google Inc. All rights reserved. |    2  * Copyright (C) 2013 Google Inc. All rights reserved. | 
|    3  * |    3  * | 
|    4  * Redistribution and use in source and binary forms, with or without |    4  * Redistribution and use in source and binary forms, with or without | 
|    5  * modification, are permitted provided that the following conditions are |    5  * modification, are permitted provided that the following conditions are | 
|    6  * met: |    6  * met: | 
|    7  * |    7  * | 
|    8  *     * Redistributions of source code must retain the above copyright |    8  *     * Redistributions of source code must retain the above copyright | 
|    9  * notice, this list of conditions and the following disclaimer. |    9  * notice, this list of conditions and the following disclaimer. | 
|   10  *     * Redistributions in binary form must reproduce the above |   10  *     * Redistributions in binary form must reproduce the above | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|   25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |   25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |   26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |   27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |   28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
|   29  */ |   29  */ | 
|   30  |   30  | 
|   31 #ifndef ThreadState_h |   31 #ifndef ThreadState_h | 
|   32 #define ThreadState_h |   32 #define ThreadState_h | 
|   33  |   33  | 
|   34 #include "platform/PlatformExport.h" |   34 #include "platform/PlatformExport.h" | 
 |   35 #include "platform/heap/BlinkGC.h" | 
|   35 #include "platform/heap/ThreadingTraits.h" |   36 #include "platform/heap/ThreadingTraits.h" | 
|   36 #include "public/platform/WebThread.h" |   37 #include "public/platform/WebThread.h" | 
|   37 #include "wtf/AddressSanitizer.h" |   38 #include "wtf/AddressSanitizer.h" | 
|   38 #include "wtf/Forward.h" |   39 #include "wtf/Forward.h" | 
|   39 #include "wtf/HashMap.h" |   40 #include "wtf/HashMap.h" | 
|   40 #include "wtf/HashSet.h" |   41 #include "wtf/HashSet.h" | 
|   41 #include "wtf/PassOwnPtr.h" |   42 #include "wtf/PassOwnPtr.h" | 
|   42 #include "wtf/ThreadSpecific.h" |   43 #include "wtf/ThreadSpecific.h" | 
|   43 #include "wtf/Threading.h" |   44 #include "wtf/Threading.h" | 
|   44 #include "wtf/ThreadingPrimitives.h" |   45 #include "wtf/ThreadingPrimitives.h" | 
|   45 #include "wtf/text/WTFString.h" |   46 #include "wtf/text/WTFString.h" | 
|   46  |   47  | 
|   47 namespace v8 { |   48 namespace v8 { | 
|   48 class Isolate; |   49 class Isolate; | 
|   49 }; |   50 }; | 
|   50  |   51  | 
|   51 namespace blink { |   52 namespace blink { | 
|   52  |   53  | 
|   53 #define PRINT_HEAP_STATS 0 // Enable this macro to print heap stats to stderr. |  | 
|   54  |  | 
|   55 class BasePage; |   54 class BasePage; | 
|   56 class CallbackStack; |   55 class CallbackStack; | 
|   57 class CrossThreadPersistentRegion; |   56 class CrossThreadPersistentRegion; | 
|   58 struct GCInfo; |   57 struct GCInfo; | 
|   59 class GarbageCollectedMixinConstructorMarker; |   58 class GarbageCollectedMixinConstructorMarker; | 
|   60 class HeapObjectHeader; |   59 class HeapObjectHeader; | 
|   61 class PersistentRegion; |   60 class PersistentRegion; | 
|   62 class BaseHeap; |   61 class BaseHeap; | 
|   63 class SafePointAwareMutexLocker; |   62 class SafePointAwareMutexLocker; | 
|   64 class SafePointBarrier; |   63 class SafePointBarrier; | 
|   65 class ThreadState; |   64 class ThreadState; | 
|   66 class Visitor; |   65 class Visitor; | 
|   67  |   66  | 
|   68 using Address = uint8_t*; |  | 
|   69  |  | 
|   70 using FinalizationCallback = void (*)(void*); |  | 
|   71 using VisitorCallback = void (*)(Visitor*, void* self); |  | 
|   72 using TraceCallback = VisitorCallback; |  | 
|   73 using WeakCallback = VisitorCallback; |  | 
|   74 using EphemeronCallback = VisitorCallback; |  | 
|   75 using PreFinalizerCallback = bool(*)(void*); |  | 
|   76  |  | 
|   77 // Declare that a class has a pre-finalizer. The pre-finalizer is called |   67 // Declare that a class has a pre-finalizer. The pre-finalizer is called | 
|   78 // before any object gets swept, so it is safe to touch on-heap objects |   68 // before any object gets swept, so it is safe to touch on-heap objects | 
|   79 // that may be collected in the same GC cycle. If you cannot avoid touching |   69 // that may be collected in the same GC cycle. If you cannot avoid touching | 
|   80 // on-heap objects in a destructor (which is not allowed), you can consider |   70 // on-heap objects in a destructor (which is not allowed), you can consider | 
|   81 // using the pre-finalizer. The only restriction is that the pre-finalizer |   71 // using the pre-finalizer. The only restriction is that the pre-finalizer | 
|   82 // must not resurrect dead objects (e.g., store unmarked objects into |   72 // must not resurrect dead objects (e.g., store unmarked objects into | 
|   83 // Members etc). The pre-finalizer is called on the thread that registered |   73 // Members etc). The pre-finalizer is called on the thread that registered | 
|   84 // the pre-finalizer. |   74 // the pre-finalizer. | 
|   85 // |   75 // | 
|   86 // Since a pre-finalizer adds pressure on GC performance, you should use it |   76 // Since a pre-finalizer adds pressure on GC performance, you should use it | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  122     return true;                                    \ |  112     return true;                                    \ | 
|  123 }                                                   \ |  113 }                                                   \ | 
|  124 using UsingPreFinazlizerMacroNeedsTrailingSemiColon = char |  114 using UsingPreFinazlizerMacroNeedsTrailingSemiColon = char | 
|  125  |  115  | 
|  126 #if ENABLE(OILPAN) |  116 #if ENABLE(OILPAN) | 
|  127 #define WILL_BE_USING_PRE_FINALIZER(Class, method) USING_PRE_FINALIZER(Class, me
     thod) |  117 #define WILL_BE_USING_PRE_FINALIZER(Class, method) USING_PRE_FINALIZER(Class, me
     thod) | 
|  128 #else |  118 #else | 
|  129 #define WILL_BE_USING_PRE_FINALIZER(Class, method) |  119 #define WILL_BE_USING_PRE_FINALIZER(Class, method) | 
|  130 #endif |  120 #endif | 
|  131  |  121  | 
|  132 // List of typed heaps. The list is used to generate the implementation |  | 
|  133 // of typed heap related methods. |  | 
|  134 // |  | 
|  135 // To create a new typed heap add a H(<ClassName>) to the |  | 
|  136 // FOR_EACH_TYPED_HEAP macro below. |  | 
|  137 #define FOR_EACH_TYPED_HEAP(H)              \ |  | 
|  138     H(Node)                                 \ |  | 
|  139     H(CSSValue) |  | 
|  140  |  | 
|  141 #define TypedHeapEnumName(Type) Type##HeapIndex, |  | 
|  142  |  | 
|  143 #if ENABLE(GC_PROFILING) |  122 #if ENABLE(GC_PROFILING) | 
|  144 const size_t numberOfGenerationsToTrack = 8; |  123 const size_t numberOfGenerationsToTrack = 8; | 
|  145 const size_t maxHeapObjectAge = numberOfGenerationsToTrack - 1; |  124 const size_t maxHeapObjectAge = numberOfGenerationsToTrack - 1; | 
|  146  |  125  | 
|  147 struct AgeCounts { |  126 struct AgeCounts { | 
|  148     int ages[numberOfGenerationsToTrack]; |  127     int ages[numberOfGenerationsToTrack]; | 
|  149     AgeCounts() { std::fill(ages, ages + numberOfGenerationsToTrack, 0); } |  128     AgeCounts() { std::fill(ages, ages + numberOfGenerationsToTrack, 0); } | 
|  150 }; |  129 }; | 
|  151 typedef HashMap<String, AgeCounts> ClassAgeCountsMap; |  130 typedef HashMap<String, AgeCounts> ClassAgeCountsMap; | 
|  152 #endif |  131 #endif | 
|  153  |  132  | 
|  154 class PLATFORM_EXPORT ThreadState { |  133 class PLATFORM_EXPORT ThreadState { | 
|  155     WTF_MAKE_NONCOPYABLE(ThreadState); |  134     WTF_MAKE_NONCOPYABLE(ThreadState); | 
|  156 public: |  135 public: | 
|  157     typedef std::pair<void*, PreFinalizerCallback> PreFinalizer; |  136     typedef std::pair<void*, PreFinalizerCallback> PreFinalizer; | 
|  158  |  137  | 
|  159     // When garbage collecting we need to know whether or not there |  | 
|  160     // can be pointers to Blink GC managed objects on the stack for |  | 
|  161     // each thread. When threads reach a safe point they record |  | 
|  162     // whether or not they have pointers on the stack. |  | 
|  163     enum StackState { |  | 
|  164         NoHeapPointersOnStack, |  | 
|  165         HeapPointersOnStack |  | 
|  166     }; |  | 
|  167  |  | 
|  168     enum GCType { |  | 
|  169         // Both of the marking task and the sweeping task run in |  | 
|  170         // Heap::collectGarbage(). |  | 
|  171         GCWithSweep, |  | 
|  172         // Only the marking task runs in Heap::collectGarbage(). |  | 
|  173         // The sweeping task is split into chunks and scheduled lazily. |  | 
|  174         GCWithoutSweep, |  | 
|  175         // Only the marking task runs just to take a heap snapshot. |  | 
|  176         // The sweeping task doesn't run. The marks added in the marking task |  | 
|  177         // are just cleared. |  | 
|  178         TakeSnapshot, |  | 
|  179         // The marking task does not mark objects outside the heap of the GCing |  | 
|  180         // thread. |  | 
|  181         ThreadTerminationGC, |  | 
|  182     }; |  | 
|  183  |  | 
|  184     // See setGCState() for possible state transitions. |  138     // See setGCState() for possible state transitions. | 
|  185     enum GCState { |  139     enum GCState { | 
|  186         NoGCScheduled, |  140         NoGCScheduled, | 
|  187         IdleGCScheduled, |  141         IdleGCScheduled, | 
|  188         PreciseGCScheduled, |  142         PreciseGCScheduled, | 
|  189         FullGCScheduled, |  143         FullGCScheduled, | 
|  190         PageNavigationGCScheduled, |  144         PageNavigationGCScheduled, | 
|  191         GCRunning, |  145         GCRunning, | 
|  192         EagerSweepScheduled, |  146         EagerSweepScheduled, | 
|  193         LazySweepScheduled, |  147         LazySweepScheduled, | 
|  194         Sweeping, |  148         Sweeping, | 
|  195         SweepingAndIdleGCScheduled, |  149         SweepingAndIdleGCScheduled, | 
|  196         SweepingAndPreciseGCScheduled, |  150         SweepingAndPreciseGCScheduled, | 
|  197     }; |  151     }; | 
|  198  |  152  | 
|  199     enum HeapIndices { |  | 
|  200         EagerSweepHeapIndex = 0, |  | 
|  201         NormalPage1HeapIndex, |  | 
|  202         NormalPage2HeapIndex, |  | 
|  203         NormalPage3HeapIndex, |  | 
|  204         NormalPage4HeapIndex, |  | 
|  205         Vector1HeapIndex, |  | 
|  206         Vector2HeapIndex, |  | 
|  207         Vector3HeapIndex, |  | 
|  208         Vector4HeapIndex, |  | 
|  209         InlineVectorHeapIndex, |  | 
|  210         HashTableHeapIndex, |  | 
|  211         FOR_EACH_TYPED_HEAP(TypedHeapEnumName) |  | 
|  212         LargeObjectHeapIndex, |  | 
|  213         // Values used for iteration of heap segments. |  | 
|  214         NumberOfHeaps, |  | 
|  215     }; |  | 
|  216  |  | 
|  217 #if defined(ADDRESS_SANITIZER) |  | 
|  218     // Heaps can have their object payloads be poisoned, or cleared |  | 
|  219     // of their poisoning. |  | 
|  220     enum Poisoning { |  | 
|  221         SetPoison, |  | 
|  222         ClearPoison, |  | 
|  223     }; |  | 
|  224  |  | 
|  225     enum ObjectsToPoison { |  | 
|  226         UnmarkedOnly, |  | 
|  227         MarkedAndUnmarked, |  | 
|  228     }; |  | 
|  229 #endif |  | 
|  230  |  | 
|  231     enum V8GCType { |  | 
|  232         V8MinorGC, |  | 
|  233         V8MajorGC, |  | 
|  234     }; |  | 
|  235  |  | 
|  236     // The NoAllocationScope class is used in debug mode to catch unwanted |  153     // The NoAllocationScope class is used in debug mode to catch unwanted | 
|  237     // allocations. E.g. allocations during GC. |  154     // allocations. E.g. allocations during GC. | 
|  238     class NoAllocationScope final { |  155     class NoAllocationScope final { | 
|  239     public: |  156     public: | 
|  240         explicit NoAllocationScope(ThreadState* state) : m_state(state) |  157         explicit NoAllocationScope(ThreadState* state) : m_state(state) | 
|  241         { |  158         { | 
|  242             m_state->enterNoAllocationScope(); |  159             m_state->enterNoAllocationScope(); | 
|  243         } |  160         } | 
|  244         ~NoAllocationScope() |  161         ~NoAllocationScope() | 
|  245         { |  162         { | 
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  328 #if ENABLE(ASSERT) |  245 #if ENABLE(ASSERT) | 
|  329     bool checkThread() const { return m_thread == currentThread(); } |  246     bool checkThread() const { return m_thread == currentThread(); } | 
|  330 #endif |  247 #endif | 
|  331  |  248  | 
|  332     void performIdleGC(double deadlineSeconds); |  249     void performIdleGC(double deadlineSeconds); | 
|  333     void performIdleLazySweep(double deadlineSeconds); |  250     void performIdleLazySweep(double deadlineSeconds); | 
|  334  |  251  | 
|  335     void scheduleIdleGC(); |  252     void scheduleIdleGC(); | 
|  336     void scheduleIdleLazySweep(); |  253     void scheduleIdleLazySweep(); | 
|  337     void schedulePreciseGC(); |  254     void schedulePreciseGC(); | 
|  338     void scheduleV8FollowupGCIfNeeded(V8GCType); |  255     void scheduleV8FollowupGCIfNeeded(BlinkGC::V8GCType); | 
|  339     void schedulePageNavigationGCIfNeeded(float estimatedRemovalRatio); |  256     void schedulePageNavigationGCIfNeeded(float estimatedRemovalRatio); | 
|  340     void schedulePageNavigationGC(); |  257     void schedulePageNavigationGC(); | 
|  341     void scheduleGCIfNeeded(); |  258     void scheduleGCIfNeeded(); | 
|  342     void willStartV8GC(); |  259     void willStartV8GC(); | 
|  343     void setGCState(GCState); |  260     void setGCState(GCState); | 
|  344     GCState gcState() const; |  261     GCState gcState() const { return m_gcState; } | 
|  345     bool isInGC() const { return gcState() == GCRunning; } |  262     bool isInGC() const { return gcState() == GCRunning; } | 
|  346     bool isSweepingInProgress() const |  263     bool isSweepingInProgress() const | 
|  347     { |  264     { | 
|  348         return gcState() == Sweeping || gcState() == SweepingAndPreciseGCSchedul
     ed || gcState() == SweepingAndIdleGCScheduled; |  265         return gcState() == Sweeping || gcState() == SweepingAndPreciseGCSchedul
     ed || gcState() == SweepingAndIdleGCScheduled; | 
|  349     } |  266     } | 
|  350  |  267  | 
|  351     // A GC runs in the following sequence. |  268     // A GC runs in the following sequence. | 
|  352     // |  269     // | 
|  353     // 1) All threads park at safe points. |  270     // 1) All threads park at safe points. | 
|  354     // 2) The GCing thread calls preGC() for all ThreadStates. |  271     // 2) The GCing thread calls preGC() for all ThreadStates. | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
|  365     // - We stop the world between 1) and 5). |  282     // - We stop the world between 1) and 5). | 
|  366     // - isInGC() returns true between 2) and 4). |  283     // - isInGC() returns true between 2) and 4). | 
|  367     // - isSweepingInProgress() returns true between 6) and 7). |  284     // - isSweepingInProgress() returns true between 6) and 7). | 
|  368     // - It is valid that the next GC is scheduled while some thread |  285     // - It is valid that the next GC is scheduled while some thread | 
|  369     //   has not yet completed its lazy sweeping of the last GC. |  286     //   has not yet completed its lazy sweeping of the last GC. | 
|  370     //   In this case, the next GC just cancels the remaining lazy sweeping. |  287     //   In this case, the next GC just cancels the remaining lazy sweeping. | 
|  371     //   Specifically, preGC() of the next GC calls makeConsistentForGC() |  288     //   Specifically, preGC() of the next GC calls makeConsistentForGC() | 
|  372     //   and it marks all not-yet-swept objets as dead. |  289     //   and it marks all not-yet-swept objets as dead. | 
|  373     void makeConsistentForGC(); |  290     void makeConsistentForGC(); | 
|  374     void preGC(); |  291     void preGC(); | 
|  375     void postGC(GCType); |  292     void postGC(BlinkGC::GCType); | 
|  376     void preSweep(); |  293     void preSweep(); | 
|  377     void completeSweep(); |  294     void completeSweep(); | 
|  378     void postSweep(); |  295     void postSweep(); | 
|  379     // makeConsistentForMutator() drops marks from marked objects and rebuild |  296     // makeConsistentForMutator() drops marks from marked objects and rebuild | 
|  380     // free lists. This is called after taking a snapshot and before resuming |  297     // free lists. This is called after taking a snapshot and before resuming | 
|  381     // the executions of mutators. |  298     // the executions of mutators. | 
|  382     void makeConsistentForMutator(); |  299     void makeConsistentForMutator(); | 
|  383  |  300  | 
|  384     // Support for disallowing allocation. Mainly used for sanity |  301     // Support for disallowing allocation. Mainly used for sanity | 
|  385     // checks asserts. |  302     // checks asserts. | 
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  419     //   - register an Interruptor that can interrupt long running loops that ha
     ve no calls to safePoint and |  336     //   - register an Interruptor that can interrupt long running loops that ha
     ve no calls to safePoint and | 
|  420     //     are not wrapped in a SafePointScope (e.g. Interruptor for JavaScript 
     code) |  337     //     are not wrapped in a SafePointScope (e.g. Interruptor for JavaScript 
     code) | 
|  421     // |  338     // | 
|  422  |  339  | 
|  423     // Request all other threads to stop. Must only be called if the current thr
     ead is at safepoint. |  340     // Request all other threads to stop. Must only be called if the current thr
     ead is at safepoint. | 
|  424     static bool stopThreads(); |  341     static bool stopThreads(); | 
|  425     static void resumeThreads(); |  342     static void resumeThreads(); | 
|  426  |  343  | 
|  427     // Check if GC is requested by another thread and pause this thread if this 
     is the case. |  344     // Check if GC is requested by another thread and pause this thread if this 
     is the case. | 
|  428     // Can only be called when current thread is in a consistent state. |  345     // Can only be called when current thread is in a consistent state. | 
|  429     void safePoint(StackState); |  346     void safePoint(BlinkGC::StackState); | 
|  430  |  347  | 
|  431     // Mark current thread as running inside safepoint. |  348     // Mark current thread as running inside safepoint. | 
|  432     void enterSafePoint(StackState, void*); |  349     void enterSafePoint(BlinkGC::StackState, void*); | 
|  433     void leaveSafePoint(SafePointAwareMutexLocker* = nullptr); |  350     void leaveSafePoint(SafePointAwareMutexLocker* = nullptr); | 
|  434     bool isAtSafePoint() const { return m_atSafePoint; } |  351     bool isAtSafePoint() const { return m_atSafePoint; } | 
|  435  |  352  | 
|  436     // If attached thread enters long running loop that can call back |  353     // If attached thread enters long running loop that can call back | 
|  437     // into Blink and leaving and reentering safepoint at every |  354     // into Blink and leaving and reentering safepoint at every | 
|  438     // transition between this loop and Blink is deemed too expensive |  355     // transition between this loop and Blink is deemed too expensive | 
|  439     // then instead of marking this loop as a GC safepoint thread |  356     // then instead of marking this loop as a GC safepoint thread | 
|  440     // can provide an interruptor object which would allow GC |  357     // can provide an interruptor object which would allow GC | 
|  441     // to temporarily interrupt and pause this long running loop at |  358     // to temporarily interrupt and pause this long running loop at | 
|  442     // an arbitrary moment creating a safepoint for a GC. |  359     // an arbitrary moment creating a safepoint for a GC. | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  462     { |  379     { | 
|  463         m_endOfStack = endOfStack; |  380         m_endOfStack = endOfStack; | 
|  464     } |  381     } | 
|  465  |  382  | 
|  466     // Get one of the heap structures for this thread. |  383     // Get one of the heap structures for this thread. | 
|  467     // The thread heap is split into multiple heap parts based on object types |  384     // The thread heap is split into multiple heap parts based on object types | 
|  468     // and object sizes. |  385     // and object sizes. | 
|  469     BaseHeap* heap(int heapIndex) const |  386     BaseHeap* heap(int heapIndex) const | 
|  470     { |  387     { | 
|  471         ASSERT(0 <= heapIndex); |  388         ASSERT(0 <= heapIndex); | 
|  472         ASSERT(heapIndex < NumberOfHeaps); |  389         ASSERT(heapIndex < BlinkGC::NumberOfHeaps); | 
|  473         return m_heaps[heapIndex]; |  390         return m_heaps[heapIndex]; | 
|  474     } |  391     } | 
|  475  |  392  | 
|  476 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) |  393 #if ENABLE(ASSERT) || ENABLE(GC_PROFILING) | 
|  477     // Infrastructure to determine if an address is within one of the |  394     // Infrastructure to determine if an address is within one of the | 
|  478     // address ranges for the Blink heap. If the address is in the Blink |  395     // address ranges for the Blink heap. If the address is in the Blink | 
|  479     // heap the containing heap page is returned. |  396     // heap the containing heap page is returned. | 
|  480     BasePage* findPageFromAddress(Address); |  397     BasePage* findPageFromAddress(Address); | 
|  481     BasePage* findPageFromAddress(const void* pointer) { return findPageFromAddr
     ess(reinterpret_cast<Address>(const_cast<void*>(pointer))); } |  398     BasePage* findPageFromAddress(const void* pointer) { return findPageFromAddr
     ess(reinterpret_cast<Address>(const_cast<void*>(pointer))); } | 
|  482 #endif |  399 #endif | 
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  639     { |  556     { | 
|  640         ASSERT(checkThread()); |  557         ASSERT(checkThread()); | 
|  641         size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; |  558         size_t entryIndex = gcInfoIndex & likelyToBePromptlyFreedArrayMask; | 
|  642         --m_likelyToBePromptlyFreed[entryIndex]; |  559         --m_likelyToBePromptlyFreed[entryIndex]; | 
|  643         int heapIndex = m_vectorBackingHeapIndex; |  560         int heapIndex = m_vectorBackingHeapIndex; | 
|  644         // If m_likelyToBePromptlyFreed[entryIndex] > 0, that means that |  561         // If m_likelyToBePromptlyFreed[entryIndex] > 0, that means that | 
|  645         // more than 33% of vectors of the type have been promptly freed |  562         // more than 33% of vectors of the type have been promptly freed | 
|  646         // since the last GC. |  563         // since the last GC. | 
|  647         if (m_likelyToBePromptlyFreed[entryIndex] > 0) { |  564         if (m_likelyToBePromptlyFreed[entryIndex] > 0) { | 
|  648             m_heapAges[heapIndex] = ++m_currentHeapAges; |  565             m_heapAges[heapIndex] = ++m_currentHeapAges; | 
|  649             m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpande
     d(Vector1HeapIndex, Vector4HeapIndex); |  566             m_vectorBackingHeapIndex = heapIndexOfVectorHeapLeastRecentlyExpande
     d(BlinkGC::Vector1HeapIndex, BlinkGC::Vector4HeapIndex); | 
|  650         } |  567         } | 
|  651         ASSERT(isVectorHeapIndex(heapIndex)); |  568         ASSERT(isVectorHeapIndex(heapIndex)); | 
|  652         return m_heaps[heapIndex]; |  569         return m_heaps[heapIndex]; | 
|  653     } |  570     } | 
|  654     BaseHeap* expandedVectorBackingHeap(size_t gcInfoIndex); |  571     BaseHeap* expandedVectorBackingHeap(size_t gcInfoIndex); | 
|  655     static bool isVectorHeapIndex(int heapIndex) |  572     static bool isVectorHeapIndex(int heapIndex) | 
|  656     { |  573     { | 
|  657         return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex; |  574         return BlinkGC::Vector1HeapIndex <= heapIndex && heapIndex <= BlinkGC::V
     ector4HeapIndex; | 
|  658     } |  575     } | 
|  659     void allocationPointAdjusted(int heapIndex); |  576     void allocationPointAdjusted(int heapIndex); | 
|  660     void promptlyFreed(size_t gcInfoIndex); |  577     void promptlyFreed(size_t gcInfoIndex); | 
|  661  |  578  | 
|  662 private: |  579 private: | 
|  663     enum SnapshotType { |  580     enum SnapshotType { | 
|  664         HeapSnapshot, |  581         HeapSnapshot, | 
|  665         FreelistSnapshot |  582         FreelistSnapshot | 
|  666     }; |  583     }; | 
|  667  |  584  | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  703     // Returns true if shouldForceMemoryPressureGC() held and a |  620     // Returns true if shouldForceMemoryPressureGC() held and a | 
|  704     // conservative GC was performed to handle the emergency. |  621     // conservative GC was performed to handle the emergency. | 
|  705     bool forceMemoryPressureGCIfNeeded(); |  622     bool forceMemoryPressureGCIfNeeded(); | 
|  706  |  623  | 
|  707     size_t estimatedLiveSize(size_t currentSize, size_t sizeAtLastGC); |  624     size_t estimatedLiveSize(size_t currentSize, size_t sizeAtLastGC); | 
|  708     size_t totalMemorySize(); |  625     size_t totalMemorySize(); | 
|  709     double heapGrowingRate(); |  626     double heapGrowingRate(); | 
|  710     double partitionAllocGrowingRate(); |  627     double partitionAllocGrowingRate(); | 
|  711     bool judgeGCThreshold(size_t allocatedObjectSizeThreshold, double heapGrowin
     gRateThreshold); |  628     bool judgeGCThreshold(size_t allocatedObjectSizeThreshold, double heapGrowin
     gRateThreshold); | 
|  712  |  629  | 
|  713     void runScheduledGC(StackState); |  630     void runScheduledGC(BlinkGC::StackState); | 
|  714  |  631  | 
|  715     void eagerSweep(); |  632     void eagerSweep(); | 
|  716  |  633  | 
|  717 #if defined(ADDRESS_SANITIZER) |  634 #if defined(ADDRESS_SANITIZER) | 
|  718     void poisonEagerHeap(Poisoning); |  635     void poisonEagerHeap(BlinkGC::Poisoning); | 
|  719     void poisonAllHeaps(); |  636     void poisonAllHeaps(); | 
|  720 #endif |  637 #endif | 
|  721  |  638  | 
|  722     // When ThreadState is detaching from non-main thread its |  639     // When ThreadState is detaching from non-main thread its | 
|  723     // heap is expected to be empty (because it is going away). |  640     // heap is expected to be empty (because it is going away). | 
|  724     // Perform registered cleanup tasks and garbage collection |  641     // Perform registered cleanup tasks and garbage collection | 
|  725     // to sweep away any objects that are left on this heap. |  642     // to sweep away any objects that are left on this heap. | 
|  726     // We assert that nothing must remain after this cleanup. |  643     // We assert that nothing must remain after this cleanup. | 
|  727     // If assertion does not hold we crash as we are potentially |  644     // If assertion does not hold we crash as we are potentially | 
|  728     // in the dangling pointer situation. |  645     // in the dangling pointer situation. | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
|  758     // because it will introduce global constructor and destructor. |  675     // because it will introduce global constructor and destructor. | 
|  759     // We would like to manage lifetime of the ThreadState attached |  676     // We would like to manage lifetime of the ThreadState attached | 
|  760     // to the main thread explicitly instead and still use normal |  677     // to the main thread explicitly instead and still use normal | 
|  761     // constructor and destructor for the ThreadState class. |  678     // constructor and destructor for the ThreadState class. | 
|  762     // For this we reserve static storage for the main ThreadState |  679     // For this we reserve static storage for the main ThreadState | 
|  763     // and lazily construct ThreadState in it using placement new. |  680     // and lazily construct ThreadState in it using placement new. | 
|  764     static uint8_t s_mainThreadStateStorage[]; |  681     static uint8_t s_mainThreadStateStorage[]; | 
|  765  |  682  | 
|  766     ThreadIdentifier m_thread; |  683     ThreadIdentifier m_thread; | 
|  767     OwnPtr<PersistentRegion> m_persistentRegion; |  684     OwnPtr<PersistentRegion> m_persistentRegion; | 
|  768     StackState m_stackState; |  685     BlinkGC::StackState m_stackState; | 
|  769     intptr_t* m_startOfStack; |  686     intptr_t* m_startOfStack; | 
|  770     intptr_t* m_endOfStack; |  687     intptr_t* m_endOfStack; | 
|  771     void* m_safePointScopeMarker; |  688     void* m_safePointScopeMarker; | 
|  772     Vector<Address> m_safePointStackCopy; |  689     Vector<Address> m_safePointStackCopy; | 
|  773     bool m_atSafePoint; |  690     bool m_atSafePoint; | 
|  774     InterruptorVector m_interruptors; |  691     InterruptorVector m_interruptors; | 
|  775     bool m_sweepForbidden; |  692     bool m_sweepForbidden; | 
|  776     size_t m_noAllocationCount; |  693     size_t m_noAllocationCount; | 
|  777     size_t m_gcForbiddenCount; |  694     size_t m_gcForbiddenCount; | 
|  778     BaseHeap* m_heaps[NumberOfHeaps]; |  695     BaseHeap* m_heaps[BlinkGC::NumberOfHeaps]; | 
|  779  |  696  | 
|  780     int m_vectorBackingHeapIndex; |  697     int m_vectorBackingHeapIndex; | 
|  781     size_t m_heapAges[NumberOfHeaps]; |  698     size_t m_heapAges[BlinkGC::NumberOfHeaps]; | 
|  782     size_t m_currentHeapAges; |  699     size_t m_currentHeapAges; | 
|  783  |  700  | 
|  784     bool m_isTerminating; |  701     bool m_isTerminating; | 
|  785     GarbageCollectedMixinConstructorMarker* m_gcMixinMarker; |  702     GarbageCollectedMixinConstructorMarker* m_gcMixinMarker; | 
|  786  |  703  | 
|  787     bool m_shouldFlushHeapDoesNotContainCache; |  704     bool m_shouldFlushHeapDoesNotContainCache; | 
|  788     GCState m_gcState; |  705     GCState m_gcState; | 
|  789  |  706  | 
|  790     CallbackStack* m_threadLocalWeakCallbackStack; |  707     CallbackStack* m_threadLocalWeakCallbackStack; | 
|  791  |  708  | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  826 }; |  743 }; | 
|  827  |  744  | 
|  828 template<> class ThreadStateFor<AnyThread> { |  745 template<> class ThreadStateFor<AnyThread> { | 
|  829 public: |  746 public: | 
|  830     static ThreadState* state() { return ThreadState::current(); } |  747     static ThreadState* state() { return ThreadState::current(); } | 
|  831 }; |  748 }; | 
|  832  |  749  | 
|  833 } // namespace blink |  750 } // namespace blink | 
|  834  |  751  | 
|  835 #endif // ThreadState_h |  752 #endif // ThreadState_h | 
| OLD | NEW |