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 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
368 | 368 |
369 // Associate ThreadState object with the current thread. After this | 369 // Associate ThreadState object with the current thread. After this |
370 // call thread can start using the garbage collected heap infrastructure. | 370 // call thread can start using the garbage collected heap infrastructure. |
371 // It also has to periodically check for safepoints. | 371 // It also has to periodically check for safepoints. |
372 static void attach(); | 372 static void attach(); |
373 | 373 |
374 // Disassociate attached ThreadState from the current thread. The thread | 374 // Disassociate attached ThreadState from the current thread. The thread |
375 // can no longer use the garbage collected heap after this call. | 375 // can no longer use the garbage collected heap after this call. |
376 static void detach(); | 376 static void detach(); |
377 | 377 |
378 static ThreadState* current() { return **s_threadSpecific; } | 378 static ThreadState* current() |
379 { | |
380 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | |
381 // TLS lookup is fast in these platforms. | |
382 return **s_threadSpecific; | |
383 #else | |
384 intptr_t dummy; | |
385 unsigned addressDiff = s_mainThreadStackStart - reinterpret_cast<intptr_ t>(&dummy); | |
sof
2014/10/12 07:53:55
To remain safe, doesn't this need to be ptrdiff_t
haraken
2014/10/12 08:45:50
Replaced it with uintptr_t. It is important that i
sof
2014/10/12 11:39:17
That type needs to be used for s_maniThreadStackSi
haraken
2014/10/12 12:46:12
Done.
| |
386 // This is a fast way to judge if we are in the main thread. | |
387 // If |&dummy| is within |s_mainThreadStackSize| byte from | |
388 // the stack start of the main thread, we judge that we are in | |
389 // the main thread. | |
390 ASSERT(s_mainThreadStackSize); | |
391 if (LIKELY(addressDiff <= s_mainThreadStackSize)) { | |
392 ASSERT(**s_threadSpecific == mainThreadState()); | |
393 return mainThreadState(); | |
394 } | |
395 // TLS lookup is slow. | |
396 return **s_threadSpecific; | |
397 #endif | |
398 } | |
399 | |
379 static ThreadState* mainThreadState() | 400 static ThreadState* mainThreadState() |
380 { | 401 { |
381 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); | 402 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); |
382 } | 403 } |
383 | 404 |
384 bool isMainThread() const { return this == mainThreadState(); } | 405 bool isMainThread() const { return this == mainThreadState(); } |
385 inline bool checkThread() const | 406 inline bool checkThread() const |
386 { | 407 { |
387 ASSERT(m_thread == currentThread()); | 408 ASSERT(m_thread == currentThread()); |
388 return true; | 409 return true; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 void cleanupPages(); | 754 void cleanupPages(); |
734 | 755 |
735 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } | 756 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
736 | 757 |
737 void performPendingSweepInParallel(); | 758 void performPendingSweepInParallel(); |
738 void waitUntilSweepersDone(); | 759 void waitUntilSweepersDone(); |
739 void unregisterPreFinalizerInternal(void*); | 760 void unregisterPreFinalizerInternal(void*); |
740 void invokePreFinalizers(Visitor&); | 761 void invokePreFinalizers(Visitor&); |
741 | 762 |
742 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 763 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
764 static intptr_t s_mainThreadStackStart; | |
765 static intptr_t s_mainThreadStackSize; | |
743 static SafePointBarrier* s_safePointBarrier; | 766 static SafePointBarrier* s_safePointBarrier; |
744 | 767 |
745 // This variable is flipped to true after all threads are stoped | 768 // This variable is flipped to true after all threads are stoped |
746 // and outermost GC has started. | 769 // and outermost GC has started. |
747 static bool s_inGC; | 770 static bool s_inGC; |
748 | 771 |
749 // We can't create a static member of type ThreadState here | 772 // We can't create a static member of type ThreadState here |
750 // because it will introduce global constructor and destructor. | 773 // because it will introduce global constructor and destructor. |
751 // We would like to manage lifetime of the ThreadState attached | 774 // We would like to manage lifetime of the ThreadState attached |
752 // to the main thread explicitly instead and still use normal | 775 // to the main thread explicitly instead and still use normal |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
915 // whether the page is part of a terminting thread or | 938 // whether the page is part of a terminting thread or |
916 // if the page is traced after being terminated (orphaned). | 939 // if the page is traced after being terminated (orphaned). |
917 uintptr_t m_terminating : 1; | 940 uintptr_t m_terminating : 1; |
918 uintptr_t m_tracedAfterOrphaned : 1; | 941 uintptr_t m_tracedAfterOrphaned : 1; |
919 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 | 942 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 |
920 }; | 943 }; |
921 | 944 |
922 } | 945 } |
923 | 946 |
924 #endif // ThreadState_h | 947 #endif // ThreadState_h |
OLD | NEW |