From af153cda3a11f5c9c1378da01cc67f6ac5b66b70 Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Wed, 14 Jan 2026 14:09:32 +0100 Subject: [PATCH 1/5] Revert "Fixup after comment from Ivan." This reverts commit 2aa8aa4b68027b62a8d4be1b86720fadfa48dda5. --- src/hotspot/share/gc/shared/workerThread.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index ee8abb25488..b3cec90cb42 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -115,7 +115,7 @@ uint WorkerThreads::set_active_workers(uint num_workers) { num_workers, _max_workers); if (_created_workers > 0 && InjectGCWorkerCreationFailure) { - assert(is_init_completed(), "Initialization not completed"); + assert(is_init_completed(), "Would be interesting to see if this ever happens"); log_error(gc, task)("Failed to create worker thread (InjectGCWorkerCreationFailure)"); _active_workers = MIN2(_created_workers, num_workers); return _active_workers; From 3d993accaa14de0049ba964beefd349a3faa0b7e Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Wed, 14 Jan 2026 14:09:54 +0100 Subject: [PATCH 2/5] Revert "8373253: Re-work InjectGCWorkerCreationFailure for future changes" This reverts commit d45ea8817ab2303b2decd8cbb2cd1bf5280aa181. --- src/hotspot/share/gc/shared/workerThread.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index b3cec90cb42..3a999da59dc 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -94,6 +94,9 @@ void WorkerThreads::initialize_workers() { } WorkerThread* WorkerThreads::create_worker(uint name_suffix) { + if (is_init_completed() && InjectGCWorkerCreationFailure) { + return nullptr; + } WorkerThread* const worker = new WorkerThread(_name, name_suffix, &_dispatcher); @@ -114,13 +117,6 @@ uint WorkerThreads::set_active_workers(uint num_workers) { "Invalid number of active workers %u (should be 1-%u)", num_workers, _max_workers); - if (_created_workers > 0 && InjectGCWorkerCreationFailure) { - assert(is_init_completed(), "Would be interesting to see if this ever happens"); - log_error(gc, task)("Failed to create worker thread (InjectGCWorkerCreationFailure)"); - _active_workers = MIN2(_created_workers, num_workers); - return _active_workers; - } - while (_created_workers < num_workers) { WorkerThread* const worker = create_worker(_created_workers); if (worker == nullptr) { From 60acf651e03a5d02f409d1d1c350ebe533b1452c Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Wed, 14 Jan 2026 16:07:36 +0100 Subject: [PATCH 3/5] wip --- src/hotspot/share/gc/shared/workerThread.cpp | 27 +++++++++++++++++++- src/hotspot/share/gc/shared/workerThread.hpp | 1 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index 3a999da59dc..24d1928200f 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -93,8 +93,33 @@ void WorkerThreads::initialize_workers() { } } +bool WorkerThreads::should_inject_gc_worker_creation_failure() const { + if (!InjectGCWorkerCreationFailure) { + // Never inject worker creation failure if not explicitly asked to do so + return false; + } + + if (!is_init_completed()) { + // Never allow creation failures during VM init + return false; + } + + if (_created_workers == 0) { + // Never allow creation failures of the first worker, it will cause the VM to exit + return false; + } + + return true; + + // Inject worker creation failure iff all three below conditions hold: + // 1) explicitly asked to do so (InjectGCWorkerCreationFailure); + // 2) outside VM init (before init, the code will kill the process and the uncommon path can not be tested); + // 3) not the first worker (for the same reason as point number 2 if in the future we will implement lazy init of concurrent mark in g1). + return InjectGCWorkerCreationFailure && is_init_completed() && (_created_workers != 0); +} + WorkerThread* WorkerThreads::create_worker(uint name_suffix) { - if (is_init_completed() && InjectGCWorkerCreationFailure) { + if (should_inject_gc_worker_creation_failure()) { return nullptr; } diff --git a/src/hotspot/share/gc/shared/workerThread.hpp b/src/hotspot/share/gc/shared/workerThread.hpp index d4e92797039..86a6504927c 100644 --- a/src/hotspot/share/gc/shared/workerThread.hpp +++ b/src/hotspot/share/gc/shared/workerThread.hpp @@ -103,6 +103,7 @@ public: WorkerThreads(const char* name, uint max_workers); void initialize_workers(); + bool should_inject_gc_worker_creation_failure() const; uint max_workers() const { return _max_workers; } uint created_workers() const { return _created_workers; } From 5703deb18bc32125e29be454e4c1ff6bcdcfd186 Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Mon, 19 Jan 2026 09:35:51 +0100 Subject: [PATCH 4/5] Proposal by Stefan J --- src/hotspot/share/gc/shared/workerThread.cpp | 15 ++------------- src/hotspot/share/gc/shared/workerThread.hpp | 2 +- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index 24d1928200f..c669c80ac8a 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -93,12 +93,7 @@ void WorkerThreads::initialize_workers() { } } -bool WorkerThreads::should_inject_gc_worker_creation_failure() const { - if (!InjectGCWorkerCreationFailure) { - // Never inject worker creation failure if not explicitly asked to do so - return false; - } - +bool WorkerThreads::allow_creation_failure() const { if (!is_init_completed()) { // Never allow creation failures during VM init return false; @@ -110,16 +105,10 @@ bool WorkerThreads::should_inject_gc_worker_creation_failure() const { } return true; - - // Inject worker creation failure iff all three below conditions hold: - // 1) explicitly asked to do so (InjectGCWorkerCreationFailure); - // 2) outside VM init (before init, the code will kill the process and the uncommon path can not be tested); - // 3) not the first worker (for the same reason as point number 2 if in the future we will implement lazy init of concurrent mark in g1). - return InjectGCWorkerCreationFailure && is_init_completed() && (_created_workers != 0); } WorkerThread* WorkerThreads::create_worker(uint name_suffix) { - if (should_inject_gc_worker_creation_failure()) { + if (InjectGCWorkerCreationFailure && allow_creation_failure()) { return nullptr; } diff --git a/src/hotspot/share/gc/shared/workerThread.hpp b/src/hotspot/share/gc/shared/workerThread.hpp index 86a6504927c..0b4da21ebc4 100644 --- a/src/hotspot/share/gc/shared/workerThread.hpp +++ b/src/hotspot/share/gc/shared/workerThread.hpp @@ -103,7 +103,7 @@ public: WorkerThreads(const char* name, uint max_workers); void initialize_workers(); - bool should_inject_gc_worker_creation_failure() const; + bool allow_creation_failure() const; uint max_workers() const { return _max_workers; } uint created_workers() const { return _created_workers; } From 7aa1f7e8dfa18ef7f58d9f17a6ef79749d5f8923 Mon Sep 17 00:00:00 2001 From: Leo Korinth Date: Mon, 19 Jan 2026 14:23:08 +0100 Subject: [PATCH 5/5] rename of method --- src/hotspot/share/gc/shared/workerThread.cpp | 4 ++-- src/hotspot/share/gc/shared/workerThread.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hotspot/share/gc/shared/workerThread.cpp b/src/hotspot/share/gc/shared/workerThread.cpp index c669c80ac8a..2e6fd768593 100644 --- a/src/hotspot/share/gc/shared/workerThread.cpp +++ b/src/hotspot/share/gc/shared/workerThread.cpp @@ -93,7 +93,7 @@ void WorkerThreads::initialize_workers() { } } -bool WorkerThreads::allow_creation_failure() const { +bool WorkerThreads::allow_inject_creation_failure() const { if (!is_init_completed()) { // Never allow creation failures during VM init return false; @@ -108,7 +108,7 @@ bool WorkerThreads::allow_creation_failure() const { } WorkerThread* WorkerThreads::create_worker(uint name_suffix) { - if (InjectGCWorkerCreationFailure && allow_creation_failure()) { + if (InjectGCWorkerCreationFailure && allow_inject_creation_failure()) { return nullptr; } diff --git a/src/hotspot/share/gc/shared/workerThread.hpp b/src/hotspot/share/gc/shared/workerThread.hpp index 0b4da21ebc4..abb977decc9 100644 --- a/src/hotspot/share/gc/shared/workerThread.hpp +++ b/src/hotspot/share/gc/shared/workerThread.hpp @@ -103,7 +103,7 @@ public: WorkerThreads(const char* name, uint max_workers); void initialize_workers(); - bool allow_creation_failure() const; + bool allow_inject_creation_failure() const; uint max_workers() const { return _max_workers; } uint created_workers() const { return _created_workers; }