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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 // Associate ThreadState object with the current thread. After this | 174 // Associate ThreadState object with the current thread. After this |
175 // call thread can start using the garbage collected heap infrastructure. | 175 // call thread can start using the garbage collected heap infrastructure. |
176 // It also has to periodically check for safepoints. | 176 // It also has to periodically check for safepoints. |
177 static void attachCurrentThread(); | 177 static void attachCurrentThread(); |
178 | 178 |
179 // Disassociate attached ThreadState from the current thread. The thread | 179 // Disassociate attached ThreadState from the current thread. The thread |
180 // can no longer use the garbage collected heap after this call. | 180 // can no longer use the garbage collected heap after this call. |
181 static void detachCurrentThread(); | 181 static void detachCurrentThread(); |
182 | 182 |
183 static ThreadState* current() { | 183 static ThreadState* current() { |
184 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | |
185 // TLS lookup is fast in these platforms. | |
186 return **s_threadSpecific; | 184 return **s_threadSpecific; |
187 #else | |
188 uintptr_t dummy; | |
189 uintptr_t addressDiff = | |
190 s_mainThreadStackStart - reinterpret_cast<uintptr_t>(&dummy); | |
191 // This is a fast way to judge if we are in the main thread. | |
192 // If |&dummy| is within |s_mainThreadUnderestimatedStackSize| byte from | |
193 // the stack start of the main thread, we judge that we are in | |
194 // the main thread. | |
195 if (LIKELY(addressDiff < s_mainThreadUnderestimatedStackSize)) { | |
196 ASSERT(**s_threadSpecific == mainThreadState()); | |
197 return mainThreadState(); | |
198 } | |
199 // TLS lookup is slow. | |
200 return **s_threadSpecific; | |
201 #endif | |
202 } | 185 } |
203 | 186 |
204 static ThreadState* mainThreadState() { | 187 static ThreadState* mainThreadState() { |
205 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); | 188 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); |
206 } | 189 } |
207 | 190 |
208 static ThreadState* fromObject(const void*); | 191 static ThreadState* fromObject(const void*); |
209 | 192 |
210 bool isMainThread() const { return this == mainThreadState(); } | 193 bool isMainThread() const { return this == mainThreadState(); } |
211 #if ENABLE(ASSERT) | 194 #if ENABLE(ASSERT) |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 return BlinkGC::Vector1ArenaIndex <= arenaIndex && | 487 return BlinkGC::Vector1ArenaIndex <= arenaIndex && |
505 arenaIndex <= BlinkGC::Vector4ArenaIndex; | 488 arenaIndex <= BlinkGC::Vector4ArenaIndex; |
506 } | 489 } |
507 void allocationPointAdjusted(int arenaIndex); | 490 void allocationPointAdjusted(int arenaIndex); |
508 void promptlyFreed(size_t gcInfoIndex); | 491 void promptlyFreed(size_t gcInfoIndex); |
509 | 492 |
510 void accumulateSweepingTime(double time) { | 493 void accumulateSweepingTime(double time) { |
511 m_accumulatedSweepingTime += time; | 494 m_accumulatedSweepingTime += time; |
512 } | 495 } |
513 | 496 |
514 #if OS(WIN) && COMPILER(MSVC) | |
515 size_t threadStackSize(); | |
516 #endif | |
517 | |
518 void freePersistentNode(PersistentNode*); | 497 void freePersistentNode(PersistentNode*); |
519 | 498 |
520 using PersistentClearCallback = void (*)(void*); | 499 using PersistentClearCallback = void (*)(void*); |
521 | 500 |
522 void registerStaticPersistentNode(PersistentNode*, PersistentClearCallback); | 501 void registerStaticPersistentNode(PersistentNode*, PersistentClearCallback); |
523 void releaseStaticPersistentNodes(); | 502 void releaseStaticPersistentNodes(); |
524 | 503 |
525 #if defined(LEAK_SANITIZER) | 504 #if defined(LEAK_SANITIZER) |
526 void enterStaticReferenceRegistrationDisabledScope(); | 505 void enterStaticReferenceRegistrationDisabledScope(); |
527 void leaveStaticReferenceRegistrationDisabledScope(); | 506 void leaveStaticReferenceRegistrationDisabledScope(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
648 // Should only be called under protection of threadAttachMutex(). | 627 // Should only be called under protection of threadAttachMutex(). |
649 const Vector<std::unique_ptr<BlinkGCInterruptor>>& interruptors() const { | 628 const Vector<std::unique_ptr<BlinkGCInterruptor>>& interruptors() const { |
650 return m_interruptors; | 629 return m_interruptors; |
651 } | 630 } |
652 | 631 |
653 friend class SafePointAwareMutexLocker; | 632 friend class SafePointAwareMutexLocker; |
654 friend class SafePointBarrier; | 633 friend class SafePointBarrier; |
655 friend class SafePointScope; | 634 friend class SafePointScope; |
656 | 635 |
657 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 636 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
658 static uintptr_t s_mainThreadStackStart; | |
659 static uintptr_t s_mainThreadUnderestimatedStackSize; | |
660 | 637 |
661 // We can't create a static member of type ThreadState here | 638 // We can't create a static member of type ThreadState here |
662 // because it will introduce global constructor and destructor. | 639 // because it will introduce global constructor and destructor. |
663 // We would like to manage lifetime of the ThreadState attached | 640 // We would like to manage lifetime of the ThreadState attached |
664 // to the main thread explicitly instead and still use normal | 641 // to the main thread explicitly instead and still use normal |
665 // constructor and destructor for the ThreadState class. | 642 // constructor and destructor for the ThreadState class. |
666 // For this we reserve static storage for the main ThreadState | 643 // For this we reserve static storage for the main ThreadState |
667 // and lazily construct ThreadState in it using placement new. | 644 // and lazily construct ThreadState in it using placement new. |
668 static uint8_t s_mainThreadStateStorage[]; | 645 static uint8_t s_mainThreadStateStorage[]; |
669 | 646 |
670 ThreadHeap* m_heap; | 647 ThreadHeap* m_heap; |
671 ThreadIdentifier m_thread; | 648 ThreadIdentifier m_thread; |
672 std::unique_ptr<PersistentRegion> m_persistentRegion; | 649 std::unique_ptr<PersistentRegion> m_persistentRegion; |
673 BlinkGC::StackState m_stackState; | 650 BlinkGC::StackState m_stackState; |
674 #if OS(WIN) && COMPILER(MSVC) | |
675 size_t m_threadStackSize; | |
676 #endif | |
677 intptr_t* m_startOfStack; | 651 intptr_t* m_startOfStack; |
678 intptr_t* m_endOfStack; | 652 intptr_t* m_endOfStack; |
679 | 653 |
680 void* m_safePointScopeMarker; | 654 void* m_safePointScopeMarker; |
681 Vector<Address> m_safePointStackCopy; | 655 Vector<Address> m_safePointStackCopy; |
682 bool m_atSafePoint; | 656 bool m_atSafePoint; |
683 Vector<std::unique_ptr<BlinkGCInterruptor>> m_interruptors; | 657 Vector<std::unique_ptr<BlinkGCInterruptor>> m_interruptors; |
684 bool m_sweepForbidden; | 658 bool m_sweepForbidden; |
685 size_t m_noAllocationCount; | 659 size_t m_noAllocationCount; |
686 size_t m_gcForbiddenCount; | 660 size_t m_gcForbiddenCount; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
762 class ThreadStateFor<AnyThread> { | 736 class ThreadStateFor<AnyThread> { |
763 STATIC_ONLY(ThreadStateFor); | 737 STATIC_ONLY(ThreadStateFor); |
764 | 738 |
765 public: | 739 public: |
766 static ThreadState* state() { return ThreadState::current(); } | 740 static ThreadState* state() { return ThreadState::current(); } |
767 }; | 741 }; |
768 | 742 |
769 } // namespace blink | 743 } // namespace blink |
770 | 744 |
771 #endif // ThreadState_h | 745 #endif // ThreadState_h |
OLD | NEW |