ART: Use thread_local on the host for ART Thread*
Use thread_local instead of a pthread key for Thread::Current().
Retain the pthread key as we are still using it for some sanity
checks in ThreadExitCallback.
Bug: 138329277
Test: m test-art-host
Change-Id: Idfe43bc279459e307e2165d3a3762af09230bdfd
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 53450ba..84983b8 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -131,6 +131,9 @@
const size_t Thread::kStackOverflowImplicitCheckSize = GetStackOverflowReservedBytes(kRuntimeISA);
bool (*Thread::is_sensitive_thread_hook_)() = nullptr;
Thread* Thread::jit_sensitive_thread_ = nullptr;
+#ifndef __BIONIC__
+thread_local Thread* Thread::self_tls_ = nullptr;
+#endif
static constexpr bool kVerifyImageObjectsMarked = kIsDebugBuild;
@@ -937,6 +940,7 @@
__get_tls()[TLS_SLOT_ART_THREAD_SELF] = this;
#else
CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, this), "attach self");
+ Thread::self_tls_ = this;
#endif
DCHECK_EQ(Thread::Current(), this);
@@ -2191,6 +2195,7 @@
__get_tls()[TLS_SLOT_ART_THREAD_SELF] = self;
#else
CHECK_PTHREAD_CALL(pthread_setspecific, (Thread::pthread_key_self_, self), "reattach self");
+ Thread::self_tls_ = self;
#endif
self->tls32_.thread_exit_check_count = 1;
} else {
@@ -2221,6 +2226,9 @@
if (pthread_getspecific(pthread_key_self_) != nullptr) {
LOG(FATAL) << "Newly-created pthread TLS slot is not nullptr";
}
+#ifndef __BIONIC__
+ CHECK(Thread::self_tls_ == nullptr);
+#endif
}
void Thread::FinishStartup() {