# HG changeset patch # User stuefe # Date 1539761749 -7200 # Wed Oct 17 09:35:49 2018 +0200 # Node ID c0880202bed1aaf9b3268f0e2a14846ce0d51cee # Parent f586d225bd0b12208e265cefdb60aa0f0098dd60 [mq]: 8212173-thread-stack-and-base-initialized-too-late diff -r f586d225bd0b -r c0880202bed1 src/hotspot/os/aix/os_aix.cpp --- a/src/hotspot/os/aix/os_aix.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/os/aix/os_aix.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -776,16 +776,48 @@ // Thread start routine for all newly created threads static void *thread_native_entry(Thread *thread) { - // find out my own stack dimensions - { - // actually, this should do exactly the same as thread->record_stack_base_and_size... - thread->set_stack_base(os::current_stack_base()); - thread->set_stack_size(os::current_stack_size()); - } - const pthread_t pthread_id = ::pthread_self(); const tid_t kernel_thread_id = ::thread_self(); + // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc() + // by the pthread library). In rare cases, this may not be the case, e.g. when third-party + // tools hook pthread_create(). In this case, we may run into problems establishing + // guard pages on those stacks, because the stacks may reside in memory which is not + // protectable (shmated). + if (thread->stack_base() > ::sbrk(0)) { + log_warning(os, thread)("Thread stack not in data segment."); + } + + // Try to randomize the cache line index of hot stack frames. + // This helps when threads of the same stack traces evict each other's + // cache lines. The threads can be either from the same JVM instance, or + // from different JVM instances. The benefit is especially true for + // processors with hyperthreading technology. + + static int counter = 0; + int pid = os::current_process_id(); + alloca(((pid ^ counter++) & 7) * 128); + + thread->initialize_thread_current(); + + OSThread* osthread = thread->osthread(); + + // Thread_id is pthread id. + osthread->set_thread_id(pthread_id); + + // .. but keep kernel thread id too for diagnostics + osthread->set_kernel_thread_id(kernel_thread_id); + + // Initialize signal mask for this thread. + os::Aix::hotspot_sigmask(thread); + + // Initialize floating point control register. + os::Aix::init_thread_fpu_state(); + + assert(osthread->get_state() == RUNNABLE, "invalid os thread state"); + + thread->record_stack_base_and_size(); + LogTarget(Info, os, thread) lt; if (lt.is_enabled()) { address low_address = thread->stack_end(); @@ -796,43 +828,6 @@ (high_address - low_address) / K, os::Aix::query_pagesize(low_address) / K); } - // Normally, pthread stacks on AIX live in the data segment (are allocated with malloc() - // by the pthread library). In rare cases, this may not be the case, e.g. when third-party - // tools hook pthread_create(). In this case, we may run into problems establishing - // guard pages on those stacks, because the stacks may reside in memory which is not - // protectable (shmated). - if (thread->stack_base() > ::sbrk(0)) { - log_warning(os, thread)("Thread stack not in data segment."); - } - - // Try to randomize the cache line index of hot stack frames. - // This helps when threads of the same stack traces evict each other's - // cache lines. The threads can be either from the same JVM instance, or - // from different JVM instances. The benefit is especially true for - // processors with hyperthreading technology. - - static int counter = 0; - int pid = os::current_process_id(); - alloca(((pid ^ counter++) & 7) * 128); - - thread->initialize_thread_current(); - - OSThread* osthread = thread->osthread(); - - // Thread_id is pthread id. - osthread->set_thread_id(pthread_id); - - // .. but keep kernel thread id too for diagnostics - osthread->set_kernel_thread_id(kernel_thread_id); - - // Initialize signal mask for this thread. - os::Aix::hotspot_sigmask(thread); - - // Initialize floating point control register. - os::Aix::init_thread_fpu_state(); - - assert(osthread->get_state() == RUNNABLE, "invalid os thread state"); - // Call one more level start routine. thread->run(); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/os/bsd/os_bsd.cpp --- a/src/hotspot/os/bsd/os_bsd.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/os/bsd/os_bsd.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -660,6 +660,8 @@ osthread->set_thread_id(os::Bsd::gettid()); + thread->record_stack_base_and_size(); + log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", os::current_thread_id(), (uintx) pthread_self()); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/os/linux/os_linux.cpp --- a/src/hotspot/os/linux/os_linux.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/os/linux/os_linux.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -665,6 +665,8 @@ osthread->set_thread_id(os::current_thread_id()); + thread->record_stack_base_and_size(); + log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", os::current_thread_id(), (uintx) pthread_self()); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/os/solaris/os_solaris.cpp --- a/src/hotspot/os/solaris/os_solaris.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/os/solaris/os_solaris.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -742,6 +742,8 @@ osthr->set_lwp_id(_lwp_self()); // Store lwp in case we are bound + thread->record_stack_base_and_size(); + log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ").", os::current_thread_id()); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/os/windows/os_windows.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -447,6 +447,8 @@ res = 20115; // java thread } + thread->record_stack_base_and_size(); + log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ").", os::current_thread_id()); // Install a win32 structured exception handler around every thread created diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/gc/parallel/gcTaskThread.cpp --- a/src/hotspot/share/gc/parallel/gcTaskThread.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/gc/parallel/gcTaskThread.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -114,8 +114,6 @@ // for tasks to be enqueued for execution. void GCTaskThread::run() { - // Set up the thread for stack overflow support - this->record_stack_base_and_size(); this->initialize_named_thread(); // Bind yourself to your processor. if (processor_id() != GCTaskManager::sentinel_worker()) { diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/gc/shared/concurrentGCThread.cpp --- a/src/hotspot/share/gc/shared/concurrentGCThread.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/gc/shared/concurrentGCThread.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -49,7 +49,6 @@ } void ConcurrentGCThread::initialize_in_thread() { - this->record_stack_base_and_size(); this->initialize_named_thread(); this->set_active_handles(JNIHandleBlock::allocate_block()); // From this time Thread::current() should be working. diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/gc/shared/workgroup.cpp --- a/src/hotspot/share/gc/shared/workgroup.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/gc/shared/workgroup.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -297,7 +297,6 @@ } void AbstractGangWorker::initialize() { - this->record_stack_base_and_size(); this->initialize_named_thread(); assert(_gang != NULL, "No gang to run in"); os::set_priority(this, NearMaxPriority); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp --- a/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/jfr/periodic/sampling/jfrThreadSampler.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -455,8 +455,6 @@ void JfrThreadSampler::run() { assert(_sampler_thread == NULL, "invariant"); - record_stack_base_and_size(); - _sampler_thread = this; jlong last_java_ms = get_monotonic_ms(); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/runtime/thread.cpp --- a/src/hotspot/share/runtime/thread.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/runtime/thread.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -1374,7 +1374,6 @@ 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) { @@ -1740,9 +1739,6 @@ // 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(); diff -r f586d225bd0b -r c0880202bed1 src/hotspot/share/runtime/vmThread.cpp --- a/src/hotspot/share/runtime/vmThread.cpp Tue Oct 16 17:43:30 2018 +0200 +++ b/src/hotspot/share/runtime/vmThread.cpp Wed Oct 17 09:35:49 2018 +0200 @@ -243,7 +243,6 @@ assert(this == vm_thread(), "check"); this->initialize_named_thread(); - this->record_stack_base_and_size(); // Notify_lock wait checks on active_handles() to rewait in // case of spurious wakeup, it should wait on the last // value set prior to the notify