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 15 matching lines...) Expand all Loading... |
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/BlinkGC.h" |
36 #include "platform/heap/BlinkGCInterruptor.h" | |
37 #include "platform/heap/ThreadingTraits.h" | 36 #include "platform/heap/ThreadingTraits.h" |
38 #include "public/platform/WebThread.h" | 37 #include "public/platform/WebThread.h" |
39 #include "wtf/AddressSanitizer.h" | 38 #include "wtf/AddressSanitizer.h" |
40 #include "wtf/Allocator.h" | 39 #include "wtf/Allocator.h" |
41 #include "wtf/Forward.h" | 40 #include "wtf/Forward.h" |
42 #include "wtf/Functional.h" | 41 #include "wtf/Functional.h" |
43 #include "wtf/HashMap.h" | 42 #include "wtf/HashMap.h" |
44 #include "wtf/HashSet.h" | 43 #include "wtf/HashSet.h" |
45 #include "wtf/ThreadSpecific.h" | 44 #include "wtf/ThreadSpecific.h" |
46 #include "wtf/Threading.h" | 45 #include "wtf/Threading.h" |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 // Notice that a thread does not have to be paused if it is at safepoint it | 311 // Notice that a thread does not have to be paused if it is at safepoint it |
313 // can continue to run and perform tasks that do not require interaction | 312 // can continue to run and perform tasks that do not require interaction |
314 // with the heap. It will be paused if it attempts to leave the safepoint and | 313 // with the heap. It will be paused if it attempts to leave the safepoint and |
315 // there is a GC in progress. | 314 // there is a GC in progress. |
316 // | 315 // |
317 // Each thread that has ThreadState attached must: | 316 // Each thread that has ThreadState attached must: |
318 // - periodically check if GC is requested from another thread by calling a | 317 // - periodically check if GC is requested from another thread by calling a |
319 // safePoint() method; | 318 // safePoint() method; |
320 // - use SafePointScope around long running loops that have no safePoint() | 319 // - use SafePointScope around long running loops that have no safePoint() |
321 // invocation inside, such loops must not touch any heap object; | 320 // invocation inside, such loops must not touch any heap object; |
322 // - register an BlinkGCInterruptor that can interrupt long running loops | |
323 // that have no calls to safePoint and are not wrapped in a SafePointScope | |
324 // (e.g. BlinkGCInterruptor for JavaScript code) | |
325 // | 321 // |
326 | |
327 // Check if GC is requested by another thread and pause this thread if this is | 322 // Check if GC is requested by another thread and pause this thread if this is |
328 // the case. Can only be called when current thread is in a consistent state. | 323 // the case. Can only be called when current thread is in a consistent state. |
329 void safePoint(BlinkGC::StackState); | 324 void safePoint(BlinkGC::StackState); |
330 | 325 |
331 // Mark current thread as running inside safepoint. | 326 // Mark current thread as running inside safepoint. |
332 void enterSafePoint(BlinkGC::StackState, void*); | 327 void enterSafePoint(BlinkGC::StackState, void*); |
333 void leaveSafePoint(); | 328 void leaveSafePoint(); |
334 | 329 |
335 void addInterruptor(std::unique_ptr<BlinkGCInterruptor>); | |
336 | |
337 void recordStackEnd(intptr_t* endOfStack) { m_endOfStack = endOfStack; } | 330 void recordStackEnd(intptr_t* endOfStack) { m_endOfStack = endOfStack; } |
338 | 331 |
339 // Get one of the heap structures for this thread. | 332 // Get one of the heap structures for this thread. |
340 // The thread heap is split into multiple heap parts based on object types | 333 // The thread heap is split into multiple heap parts based on object types |
341 // and object sizes. | 334 // and object sizes. |
342 BaseArena* arena(int arenaIndex) const { | 335 BaseArena* arena(int arenaIndex) const { |
343 ASSERT(0 <= arenaIndex); | 336 ASSERT(0 <= arenaIndex); |
344 ASSERT(arenaIndex < BlinkGC::NumberOfArenas); | 337 ASSERT(arenaIndex < BlinkGC::NumberOfArenas); |
345 return m_arenas[arenaIndex]; | 338 return m_arenas[arenaIndex]; |
346 } | 339 } |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 | 594 |
602 void invokePreFinalizers(); | 595 void invokePreFinalizers(); |
603 | 596 |
604 void takeSnapshot(SnapshotType); | 597 void takeSnapshot(SnapshotType); |
605 void clearArenaAges(); | 598 void clearArenaAges(); |
606 int arenaIndexOfVectorArenaLeastRecentlyExpanded(int beginArenaIndex, | 599 int arenaIndexOfVectorArenaLeastRecentlyExpanded(int beginArenaIndex, |
607 int endArenaIndex); | 600 int endArenaIndex); |
608 | 601 |
609 void reportMemoryToV8(); | 602 void reportMemoryToV8(); |
610 | 603 |
611 // Should only be called under protection of threadAttachMutex(). | |
612 const Vector<std::unique_ptr<BlinkGCInterruptor>>& interruptors() const { | |
613 return m_interruptors; | |
614 } | |
615 | |
616 friend class SafePointBarrier; | 604 friend class SafePointBarrier; |
617 friend class SafePointScope; | 605 friend class SafePointScope; |
618 | 606 |
619 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 607 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
620 | 608 |
621 // We can't create a static member of type ThreadState here | 609 // We can't create a static member of type ThreadState here |
622 // because it will introduce global constructor and destructor. | 610 // because it will introduce global constructor and destructor. |
623 // We would like to manage lifetime of the ThreadState attached | 611 // We would like to manage lifetime of the ThreadState attached |
624 // to the main thread explicitly instead and still use normal | 612 // to the main thread explicitly instead and still use normal |
625 // constructor and destructor for the ThreadState class. | 613 // constructor and destructor for the ThreadState class. |
626 // For this we reserve static storage for the main ThreadState | 614 // For this we reserve static storage for the main ThreadState |
627 // and lazily construct ThreadState in it using placement new. | 615 // and lazily construct ThreadState in it using placement new. |
628 static uint8_t s_mainThreadStateStorage[]; | 616 static uint8_t s_mainThreadStateStorage[]; |
629 | 617 |
630 ThreadHeap* m_heap; | 618 ThreadHeap* m_heap; |
631 ThreadIdentifier m_thread; | 619 ThreadIdentifier m_thread; |
632 std::unique_ptr<PersistentRegion> m_persistentRegion; | 620 std::unique_ptr<PersistentRegion> m_persistentRegion; |
633 BlinkGC::StackState m_stackState; | 621 BlinkGC::StackState m_stackState; |
634 intptr_t* m_startOfStack; | 622 intptr_t* m_startOfStack; |
635 intptr_t* m_endOfStack; | 623 intptr_t* m_endOfStack; |
636 | 624 |
637 void* m_safePointScopeMarker; | 625 void* m_safePointScopeMarker; |
638 Vector<Address> m_safePointStackCopy; | 626 Vector<Address> m_safePointStackCopy; |
639 Vector<std::unique_ptr<BlinkGCInterruptor>> m_interruptors; | |
640 bool m_sweepForbidden; | 627 bool m_sweepForbidden; |
641 size_t m_noAllocationCount; | 628 size_t m_noAllocationCount; |
642 size_t m_gcForbiddenCount; | 629 size_t m_gcForbiddenCount; |
643 size_t m_mixinsBeingConstructedCount; | 630 size_t m_mixinsBeingConstructedCount; |
644 double m_accumulatedSweepingTime; | 631 double m_accumulatedSweepingTime; |
645 | 632 |
646 BaseArena* m_arenas[BlinkGC::NumberOfArenas]; | 633 BaseArena* m_arenas[BlinkGC::NumberOfArenas]; |
647 int m_vectorBackingArenaIndex; | 634 int m_vectorBackingArenaIndex; |
648 size_t m_arenaAges[BlinkGC::NumberOfArenas]; | 635 size_t m_arenaAges[BlinkGC::NumberOfArenas]; |
649 size_t m_currentArenaAges; | 636 size_t m_currentArenaAges; |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 class ThreadStateFor<AnyThread> { | 702 class ThreadStateFor<AnyThread> { |
716 STATIC_ONLY(ThreadStateFor); | 703 STATIC_ONLY(ThreadStateFor); |
717 | 704 |
718 public: | 705 public: |
719 static ThreadState* state() { return ThreadState::current(); } | 706 static ThreadState* state() { return ThreadState::current(); } |
720 }; | 707 }; |
721 | 708 |
722 } // namespace blink | 709 } // namespace blink |
723 | 710 |
724 #endif // ThreadState_h | 711 #endif // ThreadState_h |
OLD | NEW |