8273482: Remove "foreground work" concept from WorkGang

Reviewed-by: tschatzl, kbarrett
This commit is contained in:
Per Liden 2021-09-10 09:49:45 +00:00
parent 2eaf374c5c
commit c1e39faaa9
6 changed files with 8 additions and 25 deletions

View File

@ -34,17 +34,6 @@
#include "runtime/semaphore.hpp" #include "runtime/semaphore.hpp"
#include "runtime/thread.inline.hpp" #include "runtime/thread.inline.hpp"
static void run_foreground_task_if_needed(AbstractGangTask* task, uint num_workers,
bool add_foreground_work) {
if (add_foreground_work) {
log_develop_trace(gc, workgang)("Running work gang: %s task: %s worker: foreground",
Thread::current()->name(), task->name());
task->work(num_workers);
log_develop_trace(gc, workgang)("Finished work gang: %s task: %s worker: foreground "
"thread: " PTR_FORMAT, Thread::current()->name(), task->name(), p2i(Thread::current()));
}
}
// WorkGang dispatcher implemented with semaphores. // WorkGang dispatcher implemented with semaphores.
// //
// Semaphores don't require the worker threads to re-claim the lock when they wake up. // Semaphores don't require the worker threads to re-claim the lock when they wake up.
@ -79,7 +68,7 @@ public:
// Distributes the task out to num_workers workers. // Distributes the task out to num_workers workers.
// Returns when the task has been completed by all workers. // Returns when the task has been completed by all workers.
void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers, bool add_foreground_work) { void coordinator_execute_on_workers(AbstractGangTask* task, uint num_workers) {
// No workers are allowed to read the state variables until they have been signaled. // No workers are allowed to read the state variables until they have been signaled.
_task = task; _task = task;
_not_finished = num_workers; _not_finished = num_workers;
@ -87,8 +76,6 @@ public:
// Dispatch 'num_workers' number of tasks. // Dispatch 'num_workers' number of tasks.
_start_semaphore->signal(num_workers); _start_semaphore->signal(num_workers);
run_foreground_task_if_needed(task, num_workers, add_foreground_work);
// Wait for the last worker to signal the coordinator. // Wait for the last worker to signal the coordinator.
_end_semaphore->wait(); _end_semaphore->wait();
@ -198,14 +185,14 @@ void WorkGang::run_task(AbstractGangTask* task) {
run_task(task, active_workers()); run_task(task, active_workers());
} }
void WorkGang::run_task(AbstractGangTask* task, uint num_workers, bool add_foreground_work) { void WorkGang::run_task(AbstractGangTask* task, uint num_workers) {
guarantee(num_workers <= total_workers(), guarantee(num_workers <= total_workers(),
"Trying to execute task %s with %u workers which is more than the amount of total workers %u.", "Trying to execute task %s with %u workers which is more than the amount of total workers %u.",
task->name(), num_workers, total_workers()); task->name(), num_workers, total_workers());
guarantee(num_workers > 0, "Trying to execute task %s with zero workers", task->name()); guarantee(num_workers > 0, "Trying to execute task %s with zero workers", task->name());
uint old_num_workers = _active_workers; uint old_num_workers = _active_workers;
update_active_workers(num_workers); update_active_workers(num_workers);
_dispatcher->coordinator_execute_on_workers(task, num_workers, add_foreground_work); _dispatcher->coordinator_execute_on_workers(task, num_workers);
update_active_workers(old_num_workers); update_active_workers(old_num_workers);
} }

View File

@ -167,9 +167,8 @@ class WorkGang : public CHeapObj<mtInternal> {
// Run a task with the given number of workers, returns // Run a task with the given number of workers, returns
// when the task is done. The number of workers must be at most the number of // when the task is done. The number of workers must be at most the number of
// active workers. Additional workers may be created if an insufficient // active workers. Additional workers may be created if an insufficient
// number currently exists. If the add_foreground_work flag is true, the current thread // number currently exists.
// is used to run the task too. void run_task(AbstractGangTask* task, uint num_workers);
void run_task(AbstractGangTask* task, uint num_workers, bool add_foreground_work = false);
}; };
// Temporarily try to set the number of active workers. // Temporarily try to set the number of active workers.

View File

@ -355,7 +355,6 @@ ShenandoahCodeRootsIterator::ShenandoahCodeRootsIterator() :
_par_iterator(CodeCache::heaps()), _par_iterator(CodeCache::heaps()),
_table_snapshot(NULL) { _table_snapshot(NULL) {
assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint"); assert(SafepointSynchronize::is_at_safepoint(), "Must be at safepoint");
assert(!Thread::current()->is_Worker_thread(), "Should not be acquired by workers");
CodeCache_lock->lock_without_safepoint_check(); CodeCache_lock->lock_without_safepoint_check();
_table_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration(); _table_snapshot = ShenandoahCodeRoots::table()->snapshot_for_iteration();
} }

View File

@ -258,7 +258,6 @@ ShenandoahHeapIterationRootScanner::ShenandoahHeapIterationRootScanner() :
} }
void ShenandoahHeapIterationRootScanner::roots_do(OopClosure* oops) { void ShenandoahHeapIterationRootScanner::roots_do(OopClosure* oops) {
assert(Thread::current()->is_VM_thread(), "Only by VM thread");
// Must use _claim_none to avoid interfering with concurrent CLDG iteration // Must use _claim_none to avoid interfering with concurrent CLDG iteration
CLDToOopClosure clds(oops, ClassLoaderData::_claim_none); CLDToOopClosure clds(oops, ClassLoaderData::_claim_none);
MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations); MarkingCodeBlobClosure code(oops, !CodeBlobToOopClosure::FixRelocations);

View File

@ -86,9 +86,8 @@ ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::ShenandoahClassLoad
ClassLoaderDataGraph_lock->lock(); ClassLoaderDataGraph_lock->lock();
} }
// Non-concurrent mode only runs at safepoints by VM thread // Non-concurrent mode only runs at safepoints
assert(CONCURRENT || SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint"); assert(CONCURRENT || SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
assert(CONCURRENT || Thread::current()->is_VM_thread(), "Can only be done by VM thread");
} }
template <bool CONCURRENT, bool SINGLE_THREADED> template <bool CONCURRENT, bool SINGLE_THREADED>

View File

@ -1771,7 +1771,7 @@ void VM_HeapDumper::doit() {
if (gang == NULL) { if (gang == NULL) {
work(0); work(0);
} else { } else {
gang->run_task(this, gang->active_workers(), true); gang->run_task(this);
} }
// Now we clear the global variables, so that a future dumper can run. // Now we clear the global variables, so that a future dumper can run.
@ -1780,7 +1780,7 @@ void VM_HeapDumper::doit() {
} }
void VM_HeapDumper::work(uint worker_id) { void VM_HeapDumper::work(uint worker_id) {
if (!Thread::current()->is_VM_thread()) { if (worker_id != 0) {
writer()->writer_loop(); writer()->writer_loop();
return; return;
} }