--- old/src/share/vm/runtime/thread.hpp 2015-11-11 15:14:46.758833958 -0500 +++ new/src/share/vm/runtime/thread.hpp 2015-11-11 15:14:44.722718665 -0500 @@ -102,6 +102,12 @@ class Thread: public ThreadShadow { friend class VMStructs; private: + +#ifndef USE_LIBRARY_BASED_TLS_ONLY + // Current thread is maintained as a thread-local variable + static THREAD_LOCAL_DECL Thread* _thr_current; +#endif + // Exception handling // (Note: _pending_exception and friends are in ThreadShadow) //oop _pending_exception; // pending exception for current thread @@ -260,7 +266,6 @@ friend class No_Alloc_Verifier; friend class No_Safepoint_Verifier; friend class Pause_No_Safepoint_Verifier; - friend class ThreadLocalStorage; friend class GC_locker; ThreadLocalAllocBuffer _tlab; // Thread-local eden @@ -307,9 +312,12 @@ Thread(); virtual ~Thread(); - // initializtion - void initialize_thread_local_storage(); + // Manage Thread::current() + void initialize_thread_current(); + private: + void clear_thread_current(); // needed for detaching JNI threads + public: // thread entry point virtual void run(); @@ -337,10 +345,10 @@ virtual char* name() const { return (char*)"Unknown thread"; } - // Returns the current thread + // Returns the current thread (ASSERTS if NULL) static inline Thread* current(); - // ... without having to include thread.inline.hpp. - static Thread* current_noinline(); + // Returns the current thread, or NULL if not attached + static inline Thread* current_or_null(); // Common thread operations static void set_priority(Thread* thread, ThreadPriority priority); @@ -649,25 +657,23 @@ }; // Inline implementation of Thread::current() -// Thread::current is "hot" it's called > 128K times in the 1st 500 msecs of -// startup. -// ThreadLocalStorage::thread is warm -- it's called > 16K times in the same -// period. This is inlined in thread_.inline.hpp. - inline Thread* Thread::current() { -#ifdef ASSERT - // This function is very high traffic. Define PARANOID to enable expensive - // asserts. -#ifdef PARANOID - // Signal handler should call ThreadLocalStorage::get_thread_slow() - Thread* t = ThreadLocalStorage::get_thread_slow(); - assert(t != NULL && !t->is_inside_signal_handler(), - "Don't use Thread::current() inside signal handler"); + Thread* current; +#ifndef USE_LIBRARY_BASED_TLS_ONLY + current = _thr_current; +#else + current = ThreadLocalStorage::thread(); #endif + assert(current != NULL, "Thread::current() called on detached thread"); + return current; +} + +inline Thread* Thread::current_or_null() { +#ifndef USE_LIBRARY_BASED_TLS_ONLY + return _thr_current; +#else + return ThreadLocalStorage::thread(); #endif - Thread* thread = ThreadLocalStorage::thread(); - assert(thread != NULL, "just checking"); - return thread; } // Name support for threads. non-JavaThread subclasses with multiple @@ -1842,7 +1848,7 @@ // Inline implementation of JavaThread::current inline JavaThread* JavaThread::current() { - Thread* thread = ThreadLocalStorage::thread(); + Thread* thread = Thread::current(); assert(thread != NULL && thread->is_Java_thread(), "just checking"); return (JavaThread*)thread; }