| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 // each thread. When threads reach a safe point they record | 180 // each thread. When threads reach a safe point they record |
| 181 // whether or not they have pointers on the stack. | 181 // whether or not they have pointers on the stack. |
| 182 enum StackState { | 182 enum StackState { |
| 183 NoHeapPointersOnStack, | 183 NoHeapPointersOnStack, |
| 184 HeapPointersOnStack | 184 HeapPointersOnStack |
| 185 }; | 185 }; |
| 186 | 186 |
| 187 enum GCType { | 187 enum GCType { |
| 188 GCWithSweep, // Sweeping is completed in Heap::collectGarbage(). | 188 GCWithSweep, // Sweeping is completed in Heap::collectGarbage(). |
| 189 GCWithoutSweep, // Lazy sweeping is scheduled. | 189 GCWithoutSweep, // Lazy sweeping is scheduled. |
| 190 ThreadTerminationGC, // A thread-local GC scheduled before the thread sh
utdown. |
| 190 }; | 191 }; |
| 191 | 192 |
| 192 // See setGCState() for possible state transitions. | 193 // See setGCState() for possible state transitions. |
| 193 enum GCState { | 194 enum GCState { |
| 194 NoGCScheduled, | 195 NoGCScheduled, |
| 195 IdleGCScheduled, | 196 IdleGCScheduled, |
| 196 PreciseGCScheduled, | 197 PreciseGCScheduled, |
| 197 FullGCScheduled, | 198 FullGCScheduled, |
| 198 StoppingOtherThreads, | 199 StoppingOtherThreads, |
| 199 GCRunning, | 200 GCRunning, |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 | 387 |
| 387 // Request all other threads to stop. Must only be called if the current thr
ead is at safepoint. | 388 // Request all other threads to stop. Must only be called if the current thr
ead is at safepoint. |
| 388 static bool stopThreads(); | 389 static bool stopThreads(); |
| 389 static void resumeThreads(); | 390 static void resumeThreads(); |
| 390 | 391 |
| 391 // Check if GC is requested by another thread and pause this thread if this
is the case. | 392 // Check if GC is requested by another thread and pause this thread if this
is the case. |
| 392 // Can only be called when current thread is in a consistent state. | 393 // Can only be called when current thread is in a consistent state. |
| 393 void safePoint(StackState); | 394 void safePoint(StackState); |
| 394 | 395 |
| 395 // Mark current thread as running inside safepoint. | 396 // Mark current thread as running inside safepoint. |
| 396 void enterSafePointWithPointers(void* scopeMarker) { enterSafePoint(HeapPoin
tersOnStack, scopeMarker); } | 397 void enterSafePoint(StackState, void*); |
| 397 void leaveSafePoint(SafePointAwareMutexLocker* = nullptr); | 398 void leaveSafePoint(SafePointAwareMutexLocker* = nullptr); |
| 398 bool isAtSafePoint() const { return m_atSafePoint; } | 399 bool isAtSafePoint() const { return m_atSafePoint; } |
| 399 | 400 |
| 400 // If attached thread enters long running loop that can call back | 401 // If attached thread enters long running loop that can call back |
| 401 // into Blink and leaving and reentering safepoint at every | 402 // into Blink and leaving and reentering safepoint at every |
| 402 // transition between this loop and Blink is deemed too expensive | 403 // transition between this loop and Blink is deemed too expensive |
| 403 // then instead of marking this loop as a GC safepoint thread | 404 // then instead of marking this loop as a GC safepoint thread |
| 404 // can provide an interruptor object which would allow GC | 405 // can provide an interruptor object which would allow GC |
| 405 // to temporarily interrupt and pause this long running loop at | 406 // to temporarily interrupt and pause this long running loop at |
| 406 // an arbitrary moment creating a safepoint for a GC. | 407 // an arbitrary moment creating a safepoint for a GC. |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 615 { | 616 { |
| 616 return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex; | 617 return Vector1HeapIndex <= heapIndex && heapIndex <= Vector4HeapIndex; |
| 617 } | 618 } |
| 618 void allocationPointAdjusted(int heapIndex); | 619 void allocationPointAdjusted(int heapIndex); |
| 619 void promptlyFreed(size_t gcInfoIndex); | 620 void promptlyFreed(size_t gcInfoIndex); |
| 620 | 621 |
| 621 private: | 622 private: |
| 622 ThreadState(); | 623 ThreadState(); |
| 623 ~ThreadState(); | 624 ~ThreadState(); |
| 624 | 625 |
| 625 void enterSafePoint(StackState, void*); | |
| 626 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); | 626 NO_SANITIZE_ADDRESS void copyStackUntilSafePointScope(); |
| 627 void clearSafePointScopeMarker() | 627 void clearSafePointScopeMarker() |
| 628 { | 628 { |
| 629 m_safePointStackCopy.clear(); | 629 m_safePointStackCopy.clear(); |
| 630 m_safePointScopeMarker = nullptr; | 630 m_safePointScopeMarker = nullptr; |
| 631 } | 631 } |
| 632 | 632 |
| 633 // shouldSchedule{Precise,Idle}GC and shouldForceConservativeGC | 633 // shouldSchedule{Precise,Idle}GC and shouldForceConservativeGC |
| 634 // implement the heuristics that are used to determine when to collect garba
ge. | 634 // implement the heuristics that are used to determine when to collect garba
ge. |
| 635 // If shouldForceConservativeGC returns true, we force the garbage | 635 // If shouldForceConservativeGC returns true, we force the garbage |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 }; | 742 }; |
| 743 | 743 |
| 744 template<> class ThreadStateFor<AnyThread> { | 744 template<> class ThreadStateFor<AnyThread> { |
| 745 public: | 745 public: |
| 746 static ThreadState* state() { return ThreadState::current(); } | 746 static ThreadState* state() { return ThreadState::current(); } |
| 747 }; | 747 }; |
| 748 | 748 |
| 749 } // namespace blink | 749 } // namespace blink |
| 750 | 750 |
| 751 #endif // ThreadState_h | 751 #endif // ThreadState_h |
| OLD | NEW |