< prev index next >

src/hotspot/share/runtime/thread.cpp

Print this page
rev 52211 : [mq]: tinit

*** 336,370 **** #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()); ! // CR 7190089: on Solaris, primordial thread's stack is adjusted ! // in initialize_thread(). Without the adjustment, stack size is ! // incorrect if stack is set to unlimited (ulimit -s unlimited). ! // So far, only Solaris has real implementation of initialize_thread(). ! // ! // set up any platform-specific state. ! os::initialize_thread(this); // Set stack limits after thread is initialized. if (is_Java_thread()) { ((JavaThread*) this)->set_stack_overflow_limit(); ((JavaThread*) this)->set_reserved_stack_activation(stack_base()); } #if INCLUDE_NMT ! // record thread's native stack, stack grows downward MemTracker::record_thread_stack(stack_end(), stack_size()); #endif // INCLUDE_NMT log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: " PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).", os::current_thread_id(), p2i(stack_base() - stack_size()), p2i(stack_base()), stack_size()/1024); - } Thread::~Thread() { JFR_ONLY(Jfr::on_thread_destruct(this);) // Notify the barrier set that a thread is being destroyed. Note that a barrier --- 336,399 ---- #endif ThreadLocalStorage::set_thread(NULL); } void Thread::record_stack_base_and_size() { + // Note: at this point, Thread object is not yet initialized. Do not rely on + // any members being initialized. Do not rely on Thread::current() being set. + // If possible, refrain from doing anything which may crash or assert since + // quite probably those crash dumps will be useless. set_stack_base(os::current_stack_base()); set_stack_size(os::current_stack_size()); ! ! #ifdef SOLARIS ! if (os::is_primordial_thread()) { ! os::Solaris::correct_stack_boundaries_for_primordial_thread(this); ! } ! #endif // Set stack limits after thread is initialized. if (is_Java_thread()) { ((JavaThread*) this)->set_stack_overflow_limit(); ((JavaThread*) this)->set_reserved_stack_activation(stack_base()); } + } + #if INCLUDE_NMT ! void Thread::register_thread_stack_with_NMT() { MemTracker::record_thread_stack(stack_end(), stack_size()); + } #endif // INCLUDE_NMT + + void Thread::call_run() { + // At this point, Thread object should be fully initialized and + // Thread::current() should be set. + + register_thread_stack_with_NMT(); + log_debug(os, thread)("Thread " UINTX_FORMAT " stack dimensions: " PTR_FORMAT "-" PTR_FORMAT " (" SIZE_FORMAT "k).", os::current_thread_id(), p2i(stack_base() - stack_size()), p2i(stack_base()), stack_size()/1024); + // Invoke <ChildClass>::run() + this->run(); + // Returned from <ChildClass>::run(). Thread finished. + + // Note: at this point the thread object may already have deleted itself. + // So from here on do not dereference *this*. + + // If a thread has not deleted itself ("delete this") as part of its + // termination sequence, we have to ensure thread-local-storage is + // cleared before we actually terminate. No threads should ever be + // deleted asynchronously with respect to their termination. + if (Thread::current_or_null_safe() != NULL) { + assert(Thread::current_or_null_safe() == this, "current thread is wrong"); + Thread::clear_thread_current(); + } + + } Thread::~Thread() { JFR_ONLY(Jfr::on_thread_destruct(this);) // Notify the barrier set that a thread is being destroyed. Note that a barrier
*** 415,435 **** if (osthread() != NULL) os::free_thread(osthread()); // 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() { - ShouldNotReachHere(); - } - #ifdef ASSERT // A JavaThread is considered "dangling" if it is not the current // thread, has been added the Threads list, the system is not at a // safepoint and the Thread is not "protected". // --- 444,459 ---- if (osthread() != NULL) os::free_thread(osthread()); // clear Thread::current if thread is deleting itself. // Needed to ensure JNI correctly detects non-attached threads. if (this == Thread::current()) { ! Thread::clear_thread_current(); } CHECK_UNHANDLED_OOPS_ONLY(if (CheckUnhandledOops) delete unhandled_oops();) } #ifdef ASSERT // A JavaThread is considered "dangling" if it is not the current // thread, has been added the Threads list, the system is not at a // safepoint and the Thread is not "protected". //
*** 1372,1382 **** } void WatcherThread::run() { assert(this == watcher_thread(), "just checking"); - this->record_stack_base_and_size(); 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"); --- 1396,1405 ----
*** 1738,1750 **** this->initialize_tlab(); // used to test validity of stack trace backs this->record_base_of_stack_pointer(); - // Record real stack base and size. - this->record_stack_base_and_size(); - this->create_stack_guard_pages(); this->cache_global_variables(); // Thread is now sufficient initialized to be handled by the safepoint code as being --- 1761,1770 ----
*** 3703,3712 **** --- 3723,3733 ---- 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->register_thread_stack_with_NMT(); 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 >