Skip to content

Commit

Permalink
8324983: race in CompileBroker::possibly_add_compiler_threads
Browse files Browse the repository at this point in the history
Reviewed-by: kvn, dholmes, dnsimon
  • Loading branch information
Tom Rodriguez committed Feb 5, 2024
1 parent 55c1446 commit 1993652
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

3 comments on commit 1993652

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@TheRealMDoerr
Copy link
Contributor

Choose a reason for hiding this comment

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

/backport jdk21u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 1993652 Jun 11, 2024

Choose a reason for hiding this comment

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

@TheRealMDoerr the backport was successfully created on the branch backport-TheRealMDoerr-19936526-master in my personal fork of openjdk/jdk21u-dev. To create a pull request with this backport targeting openjdk/jdk21u-dev:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit 19936526 from the openjdk/jdk repository.

The commit being backported was authored by Tom Rodriguez on 5 Feb 2024 and was reviewed by Vladimir Kozlov, David Holmes and Doug Simon.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk21u-dev:

$ git fetch https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-19936526-master:backport-TheRealMDoerr-19936526-master
$ git checkout backport-TheRealMDoerr-19936526-master
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk21u-dev.git backport-TheRealMDoerr-19936526-master

Please sign in to comment.