< prev index next >
src/share/vm/runtime/thread.hpp
Print this page
@@ -37,11 +37,10 @@
#include "runtime/os.hpp"
#include "runtime/osThread.hpp"
#include "runtime/park.hpp"
#include "runtime/safepoint.hpp"
#include "runtime/stubRoutines.hpp"
-#include "runtime/threadLocalStorage.hpp"
#include "runtime/thread_ext.hpp"
#include "runtime/unhandledOops.hpp"
#include "trace/traceBackend.hpp"
#include "trace/traceMacros.hpp"
#include "utilities/exceptions.hpp"
@@ -100,10 +99,13 @@
// - WatcherThread
class Thread: public ThreadShadow {
friend class VMStructs;
private:
+ // Current thread is maintained as a thread-local variable
+ static THREAD_LOCAL_DECL Thread* _thr_current;
+
// Exception handling
// (Note: _pending_exception and friends are in ThreadShadow)
//oop _pending_exception; // pending exception for current thread
// const char* _exception_file; // file information for exception (debugging only)
// int _exception_line; // line information for exception (debugging only)
@@ -258,11 +260,10 @@
NOT_PRODUCT(bool _skip_gcalot;) // Should we elide gc-a-lot?
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
jlong _allocated_bytes; // Cumulative number of bytes allocated on
// the Java heap
@@ -305,13 +306,16 @@
// Constructor
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();
// Testers
virtual bool is_VM_thread() const { return false; }
@@ -335,14 +339,14 @@
// Casts
virtual WorkerThread* as_Worker_thread() const { return NULL; }
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);
static ThreadPriority get_priority(const Thread* const thread);
static void start(Thread* thread);
@@ -647,29 +651,17 @@
static void muxAcquireW(volatile intptr_t * Lock, ParkEvent * ev);
static void muxRelease(volatile intptr_t * Lock);
};
// 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_<os_family>.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");
-#endif
-#endif
- Thread* thread = ThreadLocalStorage::thread();
- assert(thread != NULL, "just checking");
- return thread;
+ assert(_thr_current != NULL, "Thread::current() called on detached thread");
+ return _thr_current;
+}
+
+inline Thread* Thread::current_or_null() {
+ return _thr_current;
}
// Name support for threads. non-JavaThread subclasses with multiple
// uniquely named instances should derive from this.
class NamedThread: public Thread {
@@ -1840,11 +1832,11 @@
void set_claimed_par_id(uint id) { _claimed_par_id = id; }
};
// 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;
}
inline CompilerThread* JavaThread::as_CompilerThread() {
< prev index next >