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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.cpp » ('j') | Source/platform/heap/ThreadState.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/heap/ThreadState.h
diff --git a/Source/platform/heap/ThreadState.h b/Source/platform/heap/ThreadState.h
index 54e561338f10ccdbeae0478031f2e27c7411f688..31230897476178377777e34fe2edf7b72e570fa4 100644
--- a/Source/platform/heap/ThreadState.h
+++ b/Source/platform/heap/ThreadState.h
@@ -375,7 +375,28 @@ public:
// can no longer use the garbage collected heap after this call.
static void detach();
- static ThreadState* current() { return **s_threadSpecific; }
+ static ThreadState* current()
+ {
+#if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD)
+ // TLS lookup is fast in these platforms.
+ return **s_threadSpecific;
+#else
+ intptr_t dummy;
+ 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.
+ // This is a fast way to judge if we are in the main thread.
+ // If |&dummy| is within |s_mainThreadStackSize| byte from
+ // the stack start of the main thread, we judge that we are in
+ // the main thread.
+ ASSERT(s_mainThreadStackSize);
+ if (LIKELY(addressDiff <= s_mainThreadStackSize)) {
+ ASSERT(**s_threadSpecific == mainThreadState());
+ return mainThreadState();
+ }
+ // TLS lookup is slow.
+ return **s_threadSpecific;
+#endif
+ }
+
static ThreadState* mainThreadState()
{
return reinterpret_cast<ThreadState*>(s_mainThreadStateStorage);
@@ -740,6 +761,8 @@ private:
void invokePreFinalizers(Visitor&);
static WTF::ThreadSpecific<ThreadState*>* s_threadSpecific;
+ static intptr_t s_mainThreadStackStart;
+ static intptr_t s_mainThreadStackSize;
static SafePointBarrier* s_safePointBarrier;
// This variable is flipped to true after all threads are stoped
« no previous file with comments | « no previous file | Source/platform/heap/ThreadState.cpp » ('j') | Source/platform/heap/ThreadState.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698