diff --git a/src/share/vm/prims/jni.cpp b/src/share/vm/prims/jni.cpp index fbf66099a79e4190cbbc1cea75c1d6882e0887be..1cbfa61a17aef21c288cf1e76f7db38c3c774bc0 100644 --- a/src/share/vm/prims/jni.cpp +++ b/src/share/vm/prims/jni.cpp @@ -3401,12 +3401,16 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae thread->set_thread_state(_thread_in_vm); // Must do this before initialize_thread_local_storage thread->record_stack_base_and_size(); + thread->initialize_thread_local_storage(); if (!os::create_attached_thread(thread)) { delete thread; return JNI_ERR; } + // Enable stack overflow checks + thread->create_stack_guard_pages(); + thread->initialize_tlab(); // Crucial that we do not have a safepoint check for this thread, since it has @@ -3452,9 +3456,6 @@ static jint attach_current_thread(JavaVM *vm, void **penv, void *_args, bool dae // to regrab the threads_lock thread->set_attached(); - // Enable stack overflow checks - thread->create_stack_guard_pages(); - // Set java thread status. java_lang_Thread::set_thread_status(thread->threadObj(), java_lang_Thread::RUNNABLE); diff --git a/src/share/vm/runtime/thread.cpp b/src/share/vm/runtime/thread.cpp index 3bdf8dad0f10782f94e0ef17bbb62a47ec016bcc..e05be5e41038442136242291d33914d589d3ba81 100644 --- a/src/share/vm/runtime/thread.cpp +++ b/src/share/vm/runtime/thread.cpp @@ -1637,6 +1637,9 @@ void JavaThread::cleanup_failed_attach_current_thread() { JNIHandleBlock::release_block(block); } + // These have to be removed while this is still a valid thread. + remove_stack_guard_pages(); + if (UseTLAB) { tlab().make_parsable(true); // retire TLAB, if any }