Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: Source/platform/heap/ThreadState.h

Issue 643883002: Oilpan: Avoid looking up TLS in ThreadState::current() (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 uintptr_t dummy;
385 uintptr_t addressDiff = s_mainThreadStackStart - reinterpret_cast<intptr _t>(&dummy);
Vyacheslav Egorov (Google) 2014/10/13 14:07:23 any reason to cast to intptr_t not uintptr_t here?
haraken 2014/10/13 15:41:38 Done.
386 // This is a fast way to judge if we are in the main thread.
387 // If |&dummy| is within |s_mainThreadUnderestimatedStackSize| byte from
388 // the stack start of the main thread, we judge that we are in
389 // the main thread.
390 if (LIKELY(addressDiff <= s_mainThreadUnderestimatedStackSize)) {
Vyacheslav Egorov (Google) 2014/10/13 14:07:23 I think s_mainThreadStackStart is exclusive, not i
haraken 2014/10/13 15:41:38 Good point. In order to avoid do the subtraction i
391 ASSERT(**s_threadSpecific == mainThreadState());
392 return mainThreadState();
393 }
394 // TLS lookup is slow.
395 return **s_threadSpecific;
396 #endif
397 }
398
379 static ThreadState* mainThreadState() 399 static ThreadState* mainThreadState()
380 { 400 {
381 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage); 401 return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage);
382 } 402 }
383 403
384 bool isMainThread() const { return this == mainThreadState(); } 404 bool isMainThread() const { return this == mainThreadState(); }
385 inline bool checkThread() const 405 inline bool checkThread() const
386 { 406 {
387 ASSERT(m_thread == currentThread()); 407 ASSERT(m_thread == currentThread());
388 return true; 408 return true;
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 void cleanupPages(); 753 void cleanupPages();
734 754
735 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; } 755 void setLowCollectionRate(bool value) { m_lowCollectionRate = value; }
736 756
737 void performPendingSweepInParallel(); 757 void performPendingSweepInParallel();
738 void waitUntilSweepersDone(); 758 void waitUntilSweepersDone();
739 void unregisterPreFinalizerInternal(void*); 759 void unregisterPreFinalizerInternal(void*);
740 void invokePreFinalizers(Visitor&); 760 void invokePreFinalizers(Visitor&);
741 761
742 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific; 762 static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific;
763 static uintptr_t s_mainThreadStackStart;
764 static uintptr_t s_mainThreadUnderestimatedStackSize;
743 static SafePointBarrier* s_safePointBarrier; 765 static SafePointBarrier* s_safePointBarrier;
744 766
745 // This variable is flipped to true after all threads are stoped 767 // This variable is flipped to true after all threads are stoped
746 // and outermost GC has started. 768 // and outermost GC has started.
747 static bool s_inGC; 769 static bool s_inGC;
748 770
749 // We can't create a static member of type ThreadState here 771 // We can't create a static member of type ThreadState here
750 // because it will introduce global constructor and destructor. 772 // because it will introduce global constructor and destructor.
751 // We would like to manage lifetime of the ThreadState attached 773 // We would like to manage lifetime of the ThreadState attached
752 // to the main thread explicitly instead and still use normal 774 // to the main thread explicitly instead and still use normal
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 // whether the page is part of a terminting thread or 937 // whether the page is part of a terminting thread or
916 // if the page is traced after being terminated (orphaned). 938 // if the page is traced after being terminated (orphaned).
917 uintptr_t m_terminating : 1; 939 uintptr_t m_terminating : 1;
918 uintptr_t m_tracedAfterOrphaned : 1; 940 uintptr_t m_tracedAfterOrphaned : 1;
919 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2 941 uintptr_t m_promptlyFreedSize : 17; // == blinkPageSizeLog2
920 }; 942 };
921 943
922 } 944 }
923 945
924 #endif // ThreadState_h 946 #endif // ThreadState_h
OLDNEW
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698