< prev index next >
src/hotspot/share/runtime/thread.cpp
Print this page
rev 52189 : [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,392 ----
#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 (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_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ").",
+ os::current_thread_id());
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);
+ this->run();
+
+ // Note: at this point the thread object may already have deleted itself.
+ // So from here on do not refer to this.
+
+ log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").",
+ os::current_thread_id());
+ }
Thread::~Thread() {
JFR_ONLY(Jfr::on_thread_destruct(this);)
// Notify the barrier set that a thread is being destroyed. Note that a barrier
*** 421,435 ****
}
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".
//
--- 443,452 ----
*** 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");
--- 1389,1398 ----
*** 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
--- 1754,1763 ----
*** 3703,3712 ****
--- 3716,3726 ----
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 >