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 intptr_t dummy; | |
381 unsigned addressDiff = s_mainThreadStackStart - reinterpret_cast<intptr_ t>(&dummy); | |
382 // This is a hacky, fast way to determine if we are in the main thread. | |
383 // If the address of the |dummy| is within 1 MB from the stack start of | |
384 // the main thread, we judge that we are in the main thread. | |
385 if (LIKELY(addressDiff <= 1024 * 1024)) { | |
Mads Ager (chromium)
2014/10/10 13:44:36
There is no way to guarantee that the stack is at
| |
386 ASSERT(**s_threadSpecific == mainThreadState()); | |
387 return mainThreadState(); | |
388 } | |
389 // TLS lookup is slow. | |
390 return **s_threadSpecific; | |
391 } | |
392 | |
379 static ThreadState* mainThreadState() | 393 static ThreadState* mainThreadState() |
380 { | 394 { |
381 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); | 395 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); |
382 } | 396 } |
383 | 397 |
384 bool isMainThread() const { return this == mainThreadState(); } | 398 bool isMainThread() const { return this == mainThreadState(); } |
385 inline bool checkThread() const | 399 inline bool checkThread() const |
386 { | 400 { |
387 ASSERT(m_thread == currentThread()); | 401 ASSERT(m_thread == currentThread()); |
388 return true; | 402 return true; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
733 void cleanupPages(); | 747 void cleanupPages(); |
734 | 748 |
735 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } | 749 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } |
736 | 750 |
737 void performPendingSweepInParallel(); | 751 void performPendingSweepInParallel(); |
738 void waitUntilSweepersDone(); | 752 void waitUntilSweepersDone(); |
739 void unregisterPreFinalizerInternal(void*); | 753 void unregisterPreFinalizerInternal(void*); |
740 void invokePreFinalizers(Visitor&); | 754 void invokePreFinalizers(Visitor&); |
741 | 755 |
742 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; | 756 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; |
757 static intptr_t s_mainThreadStackStart; | |
743 static SafePointBarrier* s_safePointBarrier; | 758 static SafePointBarrier* s_safePointBarrier; |
744 | 759 |
745 // This variable is flipped to true after all threads are stoped | 760 // This variable is flipped to true after all threads are stoped |
746 // and outermost GC has started. | 761 // and outermost GC has started. |
747 static bool s_inGC; | 762 static bool s_inGC; |
748 | 763 |
749 // We can't create a static member of type ThreadState here | 764 // We can't create a static member of type ThreadState here |
750 // because it will introduce global constructor and destructor. | 765 // because it will introduce global constructor and destructor. |
751 // We would like to manage lifetime of the ThreadState attached | 766 // We would like to manage lifetime of the ThreadState attached |
752 // to the main thread explicitly instead and still use normal | 767 // 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 | 930 // whether the page is part of a terminting thread or |
916 // if the page is traced after being terminated (orphaned). | 931 // if the page is traced after being terminated (orphaned). |
917 uintptr_t m_terminating : 1; | 932 uintptr_t m_terminating : 1; |
918 uintptr_t m_tracedAfterOrphaned : 1; | 933 uintptr_t m_tracedAfterOrphaned : 1; |
919 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 | 934 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 |
920 }; | 935 }; |
921 | 936 |
922 } | 937 } |
923 | 938 |
924 #endif // ThreadState_h | 939 #endif // ThreadState_h |
OLD | NEW |