< prev index next >
src/share/vm/runtime/thread.cpp
Print this page
*** 76,86 ****
#include "runtime/stubRoutines.hpp"
#include "runtime/sweeper.hpp"
#include "runtime/task.hpp"
#include "runtime/thread.inline.hpp"
#include "runtime/threadCritical.hpp"
- #include "runtime/threadLocalStorage.hpp"
#include "runtime/vframe.hpp"
#include "runtime/vframeArray.hpp"
#include "runtime/vframe_hp.hpp"
#include "runtime/vmThread.hpp"
#include "runtime/vm_operations.hpp"
--- 76,85 ----
*** 140,149 ****
--- 139,152 ----
#define DTRACE_THREAD_PROBE(probe, javathread)
#endif // ndef DTRACE_ENABLED
+ #ifndef USE_LIBRARY_BASED_TLS_ONLY
+ // Current thread is maintained as a thread-local variable
+ THREAD_LOCAL_DECL Thread* Thread::_thr_current = NULL;
+ #endif
// Class hierarchy
// - Thread
// - VMThread
// - WatcherThread
*** 279,304 ****
"bug in forced alignment of thread objects");
}
#endif // ASSERT
}
! // Non-inlined version to be used where thread.inline.hpp shouldn't be included.
! Thread* Thread::current_noinline() {
! return Thread::current();
}
! void Thread::initialize_thread_local_storage() {
! // Note: Make sure this method only calls
! // non-blocking operations. Otherwise, it might not work
! // with the thread-startup/safepoint interaction.
!
! // During Java thread startup, safepoint code should allow this
! // method to complete because it may need to allocate memory to
! // store information for the new thread.
!
! // initialize structure dependent on thread local storage
! ThreadLocalStorage::set_thread(this);
}
void Thread::record_stack_base_and_size() {
set_stack_base(os::current_stack_base());
set_stack_size(os::current_stack_size());
--- 282,306 ----
"bug in forced alignment of thread objects");
}
#endif // ASSERT
}
! void Thread::initialize_thread_current() {
! #ifndef USE_LIBRARY_BASED_TLS_ONLY
! assert(_thr_current == NULL, "Thread::current already initialized");
! _thr_current = this;
! #endif
! assert(ThreadLocalStorage::thread() == NULL, "ThreadLocalStorage::thread already initialized");
! ThreadLocalStorage::set_thread(this);
! assert(Thread::current() == ThreadLocalStorage::thread(), "TLS mismatch!");
}
! void Thread::clear_thread_current() {
! #ifndef USE_LIBRARY_BASED_TLS_ONLY
! _thr_current = NULL;
! #endif
! ThreadLocalStorage::set_thread(NULL);
}
void Thread::record_stack_base_and_size() {
set_stack_base(os::current_stack_base());
set_stack_size(os::current_stack_size());
*** 362,380 ****
// osthread() can be NULL, if creation of thread failed.
if (osthread() != NULL) os::free_thread(osthread());
delete _SR_lock;
! // clear thread local storage if the Thread is deleting itself
if (this == Thread::current()) {
! ThreadLocalStorage::set_thread(NULL);
! } else {
! // In the case where we're not the current thread, invalidate all the
! // caches in case some code tries to get the current thread or the
! // thread that was destroyed, and gets stale information.
! ThreadLocalStorage::invalidate_all();
}
CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();)
}
// NOTE: dummy function for assertion purpose.
void Thread::run() {
--- 364,379 ----
// osthread() can be NULL, if creation of thread failed.
if (osthread() != NULL) os::free_thread(osthread());
delete _SR_lock;
! // clear Thread::current if thread is deleting itself.
! // Needed to ensure JNI correctly detects non-attached threads.
if (this == Thread::current()) {
! clear_thread_current();
}
+
CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();)
}
// NOTE: dummy function for assertion purpose.
void Thread::run() {
*** 1271,1281 ****
void WatcherThread::run() {
assert(this == watcher_thread(), "just checking");
this->record_stack_base_and_size();
- this->initialize_thread_local_storage();
this->set_native_thread_name(this->name());
this->set_active_handles(JNIHandleBlock::allocate_block());
while (true) {
assert(watcher_thread() == Thread::current(), "thread consistency check");
assert(watcher_thread() == this, "thread consistency check");
--- 1270,1279 ----
*** 1324,1336 ****
{
MutexLockerEx mu(Terminator_lock, Mutex::_no_safepoint_check_flag);
_watcher_thread = NULL;
Terminator_lock->notify();
}
-
- // Thread destructor usually does this..
- ThreadLocalStorage::set_thread(NULL);
}
void WatcherThread::start() {
assert(PeriodicTask_lock->owned_by_self(), "PeriodicTask_lock required");
--- 1322,1331 ----
*** 1661,1673 ****
this->record_base_of_stack_pointer();
// Record real stack base and size.
this->record_stack_base_and_size();
- // Initialize thread local storage; set before calling MutexLocker
- this->initialize_thread_local_storage();
-
this->create_stack_guard_pages();
this->cache_global_variables();
// Thread is now sufficient initialized to be handled by the safepoint code as being
--- 1656,1665 ----
*** 1995,2005 ****
JavaThread* JavaThread::active() {
! Thread* thread = ThreadLocalStorage::thread();
assert(thread != NULL, "just checking");
if (thread->is_Java_thread()) {
return (JavaThread*) thread;
} else {
assert(thread->is_VM_thread(), "this must be a vm thread");
--- 1987,1997 ----
JavaThread* JavaThread::active() {
! Thread* thread = Thread::current();
assert(thread != NULL, "just checking");
if (thread->is_Java_thread()) {
return (JavaThread*) thread;
} else {
assert(thread->is_VM_thread(), "this must be a vm thread");
*** 3405,3415 ****
if (os_init_2_result != JNI_OK) return os_init_2_result;
jint adjust_after_os_result = Arguments::adjust_after_os();
if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
! // initialize TLS
ThreadLocalStorage::init();
// Initialize output stream logging
ostream_init_log();
--- 3397,3407 ----
if (os_init_2_result != JNI_OK) return os_init_2_result;
jint adjust_after_os_result = Arguments::adjust_after_os();
if (adjust_after_os_result != JNI_OK) return adjust_after_os_result;
! // Initialize library-based TLS
ThreadLocalStorage::init();
// Initialize output stream logging
ostream_init_log();
*** 3442,3459 ****
#endif // INCLUDE_JVMCI
// Attach the main thread to this os thread
JavaThread* main_thread = new JavaThread();
main_thread->set_thread_state(_thread_in_vm);
! // must do this before set_active_handles and initialize_thread_local_storage
! // Note: on solaris initialize_thread_local_storage() will (indirectly)
! // change the stack size recorded here to one based on the java thread
! // stacksize. This adjusted size is what is used to figure the placement
! // of the guard pages.
main_thread->record_stack_base_and_size();
- main_thread->initialize_thread_local_storage();
-
main_thread->set_active_handles(JNIHandleBlock::allocate_block());
if (!main_thread->set_as_starting_thread()) {
vm_shutdown_during_initialization(
"Failed necessary internal allocation. Out of swap space");
--- 3434,3446 ----
#endif // INCLUDE_JVMCI
// Attach the main thread to this os thread
JavaThread* main_thread = new JavaThread();
main_thread->set_thread_state(_thread_in_vm);
! main_thread->initialize_thread_current();
! // must do this before set_active_handles
main_thread->record_stack_base_and_size();
main_thread->set_active_handles(JNIHandleBlock::allocate_block());
if (!main_thread->set_as_starting_thread()) {
vm_shutdown_during_initialization(
"Failed necessary internal allocation. Out of swap space");
< prev index next >