Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
LizBing committed Dec 16, 2023
1 parent 59aea1f commit 855e9a3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
22 changes: 6 additions & 16 deletions src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,10 @@ bool G1ConcurrentRefineThreadControl::ensure_threads_created(uint worker_id, boo

while ((uint)_threads.length() <= worker_id) {
G1ConcurrentRefineThread* rt = create_refinement_thread(_threads.length(), initializing);
_threads.push(rt);

if (rt == nullptr) {
_threads.pop();
return false;
}
_threads.push(rt);
}

return true;
Expand All @@ -96,11 +94,7 @@ jint G1ConcurrentRefineThreadControl::initialize(G1ConcurrentRefine* cr) {
return JNI_ENOMEM;
}

if (UseDynamicNumberOfGCThreads) {
for (uint i = 1; i < max_num_threads(); ++i) {
_threads.push(nullptr);
}
} else {
if (!UseDynamicNumberOfGCThreads) {
if (!ensure_threads_created(max_num_threads() - 1, true)) {
vm_shutdown_during_initialization("Could not allocate refinement threads");
return JNI_ENOMEM;
Expand All @@ -127,18 +121,14 @@ bool G1ConcurrentRefineThreadControl::activate(uint worker_id) {
}

void G1ConcurrentRefineThreadControl::worker_threads_do(ThreadClosure* tc) {
for (uint i = 0; i < max_num_threads(); i++) {
if (_threads.at(i) != nullptr) {
tc->do_thread(_threads.at(i));
}
for (uint i = 0; i < (uint)_threads.length(); i++) {
tc->do_thread(_threads.at(i));
}
}

void G1ConcurrentRefineThreadControl::stop() {
for (uint i = 0; i < max_num_threads(); i++) {
if (_threads.at(i) != nullptr) {
_threads.at(i)->stop();
}
for (uint i = 0; i < (uint)_threads.length(); i++) {
_threads.at(i)->stop();
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class G1ConcurrentRefineThreadControl {
// If initializing is true, ignore InjectGCWorkerCreationFailure.
G1ConcurrentRefineThread* create_refinement_thread(uint worker_id, bool initializing);

bool ensure_threads_created(uint worker_id, bool initializing);

NONCOPYABLE(G1ConcurrentRefineThreadControl);

public:
Expand All @@ -71,9 +73,6 @@ class G1ConcurrentRefineThreadControl {

void worker_threads_do(ThreadClosure* tc);
void stop();

private:
bool ensure_threads_created(uint worker_id, bool initializing);
};

// Controls concurrent refinement.
Expand Down

0 comments on commit 855e9a3

Please sign in to comment.