Skip to content
This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
/ jdk22 Public archive

Commit

Permalink
8324983: Race in CompileBroker::possibly_add_compiler_threads
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, never
Backport-of: 1993652653eab8dd7ce2221a97cd2e401f2dcf56
  • Loading branch information
Doug Simon committed Feb 6, 2024
1 parent 9a4d4ab commit d8dc711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/hotspot/share/compiler/compileBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -841,8 +841,15 @@ void DeoptimizeObjectsALotThread::deoptimize_objects_alot_loop_all() {


JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, CompileQueue* queue, AbstractCompiler* comp, JavaThread* THREAD) {
JavaThread* new_thread = nullptr;
Handle thread_oop(THREAD, JNIHandles::resolve_non_null(thread_handle));

if (java_lang_Thread::thread(thread_oop()) != nullptr) {
assert(type == compiler_t, "should only happen with reused compiler threads");
// The compiler thread hasn't actually exited yet so don't try to reuse it
return nullptr;
}

JavaThread* new_thread = nullptr;
switch (type) {
case compiler_t:
assert(comp != nullptr, "Compiler instance missing.");
Expand Down Expand Up @@ -871,7 +878,6 @@ JavaThread* CompileBroker::make_thread(ThreadType type, jobject thread_handle, C
// JavaThread due to lack of resources. We will handle that failure below.
// Also check new_thread so that static analysis is happy.
if (new_thread != nullptr && new_thread->osthread() != nullptr) {
Handle thread_oop(THREAD, JNIHandles::resolve_non_null(thread_handle));

if (type == compiler_t) {
CompilerThread::cast(new_thread)->set_compiler(comp);
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/share/runtime/javaThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,7 @@ static void ensure_join(JavaThread* thread) {
// Clear the native thread instance - this makes isAlive return false and allows the join()
// to complete once we've done the notify_all below. Needs a release() to obey Java Memory Model
// requirements.
assert(java_lang_Thread::thread(threadObj()) == thread, "must be alive");
java_lang_Thread::release_set_thread(threadObj(), nullptr);
lock.notify_all(thread);
// Ignore pending exception, since we are exiting anyway
Expand Down Expand Up @@ -2155,6 +2156,8 @@ void JavaThread::start_internal_daemon(JavaThread* current, JavaThread* target,
// on a ThreadsList. We don't want to wait for the release when the
// Theads_lock is dropped when the 'mu' destructor is run since the
// JavaThread* is already visible to JVM/TI via the ThreadsList.

assert(java_lang_Thread::thread(thread_oop()) == nullptr, "must not be alive");
java_lang_Thread::release_set_thread(thread_oop(), target); // isAlive == true now
Thread::start(target);
}
Expand Down

1 comment on commit d8dc711

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.