OSDN Git Service

ART: Use bionic TLS slot for thread-self
authorAndreas Gampe <agampe@google.com>
Wed, 29 Jul 2015 02:51:37 +0000 (19:51 -0700)
committerAndreas Gampe <agampe@google.com>
Wed, 29 Jul 2015 02:51:37 +0000 (19:51 -0700)
Use a private bionic TLS slot to store self instead of using
pthreads.

Change-Id: Icc86a2b7590734637366f9d5e41a5c6d18cc5772

build/Android.common_build.mk
runtime/thread-inl.h
runtime/thread.cc

index 05cfc42..3a1bd09 100644 (file)
@@ -209,6 +209,11 @@ ART_C_INCLUDES := \
   external/vixl/src \
   external/zlib \
 
+# We optimize Thread::Current() with a direct TLS access. This requires access to a private
+# Bionic header.
+# Note: technically we only need this on device, but this avoids the duplication of the includes.
+ART_C_INCLUDES += bionic/libc/private
+
 # Base set of cflags used by all things ART.
 art_cflags := \
   -fno-rtti \
index 39ef68a..53f95a6 100644 (file)
 
 #include "thread.h"
 
+#ifdef HAVE_ANDROID_OS
+#include <bionic_tls.h>  // Access to our own TLS slot.
+#endif
+
 #include <pthread.h>
 
 #include "base/casts.h"
@@ -41,7 +45,11 @@ inline Thread* Thread::Current() {
   if (!is_started_) {
     return nullptr;
   } else {
+#ifdef HAVE_ANDROID_OS
+    void* thread = __get_tls()[TLS_SLOT_ART_THREAD_SELF];
+#else
     void* thread = pthread_getspecific(Thread::pthread_key_self_);
+#endif
     return reinterpret_cast<Thread*>(thread);
   }
 }
index 6949b0b..d5b2870 100644 (file)
@@ -527,7 +527,11 @@ bool Thread::Init(ThreadList* thread_list, JavaVMExt* java_vm, JNIEnvExt* jni_en
   InitCardTable();
   InitTid();
 
+#ifdef HAVE_ANDROID_OS
+  __get_tls()[TLS_SLOT_ART_THREAD_SELF] = this;
+#else
   CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, this), "attach self");
+#endif
   DCHECK_EQ(Thread::Current(), this);
 
   tls32_.thin_lock_thread_id = thread_list->AllocThreadId(this);