Chromium Code Reviews| 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 27 matching lines...) Expand all Loading... | |
| 38 #include "public/platform/WebThread.h" | 38 #include "public/platform/WebThread.h" |
| 39 #include "wtf/AddressSanitizer.h" | 39 #include "wtf/AddressSanitizer.h" |
| 40 #include "wtf/Allocator.h" | 40 #include "wtf/Allocator.h" |
| 41 #include "wtf/Forward.h" | 41 #include "wtf/Forward.h" |
| 42 #include "wtf/Functional.h" | 42 #include "wtf/Functional.h" |
| 43 #include "wtf/HashMap.h" | 43 #include "wtf/HashMap.h" |
| 44 #include "wtf/HashSet.h" | 44 #include "wtf/HashSet.h" |
| 45 #include "wtf/ThreadSpecific.h" | 45 #include "wtf/ThreadSpecific.h" |
| 46 #include "wtf/Threading.h" | 46 #include "wtf/Threading.h" |
| 47 #include "wtf/ThreadingPrimitives.h" | 47 #include "wtf/ThreadingPrimitives.h" |
| 48 #include "wtf/WTFThreadData.h" | |
| 48 #include <memory> | 49 #include <memory> |
| 49 | 50 |
| 50 namespace v8 { | 51 namespace v8 { |
| 51 class Isolate; | 52 class Isolate; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 namespace blink { | 55 namespace blink { |
| 55 | 56 |
| 56 class BasePage; | 57 class BasePage; |
| 57 class CallbackStack; | 58 class CallbackStack; |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 175 // call thread can start using the garbage collected heap infrastructure. | 176 // call thread can start using the garbage collected heap infrastructure. |
| 176 // It also has to periodically check for safepoints. | 177 // It also has to periodically check for safepoints. |
| 177 static void attachCurrentThread(); | 178 static void attachCurrentThread(); |
| 178 | 179 |
| 179 // Disassociate attached ThreadState from the current thread. The thread | 180 // Disassociate attached ThreadState from the current thread. The thread |
| 180 // can no longer use the garbage collected heap after this call. | 181 // can no longer use the garbage collected heap after this call. |
| 181 static void detachCurrentThread(); | 182 static void detachCurrentThread(); |
| 182 | 183 |
| 183 static ThreadState* current() { | 184 static ThreadState* current() { |
| 184 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | 185 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) |
| 185 // TLS lookup is fast in these platforms. | |
| 186 return **s_threadSpecific; | 186 return **s_threadSpecific; |
| 187 #else | 187 #else |
| 188 uintptr_t dummy; | 188 if (LIKELY(WTF::WTFThreadData::stackBasedIsMainThread())) { |
| 189 uintptr_t addressDiff = | 189 DCHECK_EQ(**s_threadSpecific, mainThreadState()); |
|
haraken
2017/01/16 04:42:30
Ideally s_threadSpecific should be moved into WTFT
Charlie Harrison
2017/01/18 01:49:48
I've just turned this into **s_threadSpecific beca
| |
| 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(); | 190 return mainThreadState(); |
| 198 } | 191 } |
| 199 // TLS lookup is slow. | 192 // TLS lookup is slow. |
| 200 return **s_threadSpecific; | 193 return **s_threadSpecific; |
| 201 #endif | 194 #endif |
| 202 } | 195 } |
| 203 | 196 |
| 204 static ThreadState* mainThreadState() { | 197 static ThreadState* mainThreadState() { |
| 205 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); | 198 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); |
| 206 } | 199 } |
| (...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 648 // Should only be called under protection of threadAttachMutex(). | 641 // Should only be called under protection of threadAttachMutex(). |
| 649 const Vector<std::unique_ptr<BlinkGCInterruptor>>& interruptors() const { | 642 const Vector<std::unique_ptr<BlinkGCInterruptor>>& interruptors() const { |
| 650 return m_interruptors; | 643 return m_interruptors; |
| 651 } | 644 } |
| 652 | 645 |
| 653 friend class SafePointAwareMutexLocker; | 646 friend class SafePointAwareMutexLocker; |
| 654 friend class SafePointBarrier; | 647 friend class SafePointBarrier; |
| 655 friend class SafePointScope; | 648 friend class SafePointScope; |
| 656 | 649 |
| 657 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 650 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
| 658 static uintptr_t s_mainThreadStackStart; | |
| 659 static uintptr_t s_mainThreadUnderestimatedStackSize; | |
| 660 | 651 |
| 661 // We can't create a static member of type ThreadState here | 652 // We can't create a static member of type ThreadState here |
| 662 // because it will introduce global constructor and destructor. | 653 // because it will introduce global constructor and destructor. |
| 663 // We would like to manage lifetime of the ThreadState attached | 654 // We would like to manage lifetime of the ThreadState attached |
| 664 // to the main thread explicitly instead and still use normal | 655 // to the main thread explicitly instead and still use normal |
| 665 // constructor and destructor for the ThreadState class. | 656 // constructor and destructor for the ThreadState class. |
| 666 // For this we reserve static storage for the main ThreadState | 657 // For this we reserve static storage for the main ThreadState |
| 667 // and lazily construct ThreadState in it using placement new. | 658 // and lazily construct ThreadState in it using placement new. |
| 668 static uint8_t s_mainThreadStateStorage[]; | 659 static uint8_t s_mainThreadStateStorage[]; |
| 669 | 660 |
| 670 ThreadHeap* m_heap; | 661 ThreadHeap* m_heap; |
| 671 ThreadIdentifier m_thread; | 662 ThreadIdentifier m_thread; |
| 672 std::unique_ptr<PersistentRegion> m_persistentRegion; | 663 std::unique_ptr<PersistentRegion> m_persistentRegion; |
| 673 BlinkGC::StackState m_stackState; | 664 BlinkGC::StackState m_stackState; |
| 674 #if OS(WIN) && COMPILER(MSVC) | |
| 675 size_t m_threadStackSize; | |
| 676 #endif | |
| 677 intptr_t* m_startOfStack; | 665 intptr_t* m_startOfStack; |
| 678 intptr_t* m_endOfStack; | 666 intptr_t* m_endOfStack; |
| 679 | 667 |
| 680 void* m_safePointScopeMarker; | 668 void* m_safePointScopeMarker; |
| 681 Vector<Address> m_safePointStackCopy; | 669 Vector<Address> m_safePointStackCopy; |
| 682 bool m_atSafePoint; | 670 bool m_atSafePoint; |
| 683 Vector<std::unique_ptr<BlinkGCInterruptor>> m_interruptors; | 671 Vector<std::unique_ptr<BlinkGCInterruptor>> m_interruptors; |
| 684 bool m_sweepForbidden; | 672 bool m_sweepForbidden; |
| 685 size_t m_noAllocationCount; | 673 size_t m_noAllocationCount; |
| 686 size_t m_gcForbiddenCount; | 674 size_t m_gcForbiddenCount; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 762 class ThreadStateFor<AnyThread> { | 750 class ThreadStateFor<AnyThread> { |
| 763 STATIC_ONLY(ThreadStateFor); | 751 STATIC_ONLY(ThreadStateFor); |
| 764 | 752 |
| 765 public: | 753 public: |
| 766 static ThreadState* state() { return ThreadState::current(); } | 754 static ThreadState* state() { return ThreadState::current(); } |
| 767 }; | 755 }; |
| 768 | 756 |
| 769 } // namespace blink | 757 } // namespace blink |
| 770 | 758 |
| 771 #endif // ThreadState_h | 759 #endif // ThreadState_h |
| OLD | NEW |