mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 23:04:50 +02:00
6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
Select number of GC threads dynamically based on heap usage and number of Java threads Reviewed-by: johnc, ysr, jcoomes
This commit is contained in:
parent
098ed89645
commit
15070123fa
39 changed files with 1523 additions and 231 deletions
|
@ -152,15 +152,16 @@ void RefProcTaskExecutor::execute(ProcessTask& task)
|
|||
{
|
||||
ParallelScavengeHeap* heap = PSParallelCompact::gc_heap();
|
||||
uint parallel_gc_threads = heap->gc_task_manager()->workers();
|
||||
uint active_gc_threads = heap->gc_task_manager()->active_workers();
|
||||
RegionTaskQueueSet* qset = ParCompactionManager::region_array();
|
||||
ParallelTaskTerminator terminator(parallel_gc_threads, qset);
|
||||
ParallelTaskTerminator terminator(active_gc_threads, qset);
|
||||
GCTaskQueue* q = GCTaskQueue::create();
|
||||
for(uint i=0; i<parallel_gc_threads; i++) {
|
||||
q->enqueue(new RefProcTaskProxy(task, i));
|
||||
}
|
||||
if (task.marks_oops_alive()) {
|
||||
if (parallel_gc_threads>1) {
|
||||
for (uint j=0; j<parallel_gc_threads; j++) {
|
||||
for (uint j=0; j<active_gc_threads; j++) {
|
||||
q->enqueue(new StealMarkingTask(&terminator));
|
||||
}
|
||||
}
|
||||
|
@ -216,7 +217,6 @@ void StealMarkingTask::do_it(GCTaskManager* manager, uint which) {
|
|||
// StealRegionCompactionTask
|
||||
//
|
||||
|
||||
|
||||
StealRegionCompactionTask::StealRegionCompactionTask(ParallelTaskTerminator* t):
|
||||
_terminator(t) {}
|
||||
|
||||
|
@ -229,6 +229,32 @@ void StealRegionCompactionTask::do_it(GCTaskManager* manager, uint which) {
|
|||
ParCompactionManager* cm =
|
||||
ParCompactionManager::gc_thread_compaction_manager(which);
|
||||
|
||||
|
||||
// If not all threads are active, get a draining stack
|
||||
// from the list. Else, just use this threads draining stack.
|
||||
uint which_stack_index;
|
||||
bool use_all_workers = manager->all_workers_active();
|
||||
if (use_all_workers) {
|
||||
which_stack_index = which;
|
||||
assert(manager->active_workers() == ParallelGCThreads,
|
||||
err_msg("all_workers_active has been incorrectly set: "
|
||||
" active %d ParallelGCThreads %d", manager->active_workers(),
|
||||
ParallelGCThreads));
|
||||
} else {
|
||||
which_stack_index = ParCompactionManager::pop_recycled_stack_index();
|
||||
}
|
||||
|
||||
cm->set_region_stack_index(which_stack_index);
|
||||
cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
|
||||
if (TraceDynamicGCThreads) {
|
||||
gclog_or_tty->print_cr("StealRegionCompactionTask::do_it "
|
||||
"region_stack_index %d region_stack = 0x%x "
|
||||
" empty (%d) use all workers %d",
|
||||
which_stack_index, ParCompactionManager::region_list(which_stack_index),
|
||||
cm->region_stack()->is_empty(),
|
||||
use_all_workers);
|
||||
}
|
||||
|
||||
// Has to drain stacks first because there may be regions on
|
||||
// preloaded onto the stack and this thread may never have
|
||||
// done a draining task. Are the draining tasks needed?
|
||||
|
@ -285,6 +311,50 @@ void DrainStacksCompactionTask::do_it(GCTaskManager* manager, uint which) {
|
|||
ParCompactionManager* cm =
|
||||
ParCompactionManager::gc_thread_compaction_manager(which);
|
||||
|
||||
uint which_stack_index;
|
||||
bool use_all_workers = manager->all_workers_active();
|
||||
if (use_all_workers) {
|
||||
which_stack_index = which;
|
||||
assert(manager->active_workers() == ParallelGCThreads,
|
||||
err_msg("all_workers_active has been incorrectly set: "
|
||||
" active %d ParallelGCThreads %d", manager->active_workers(),
|
||||
ParallelGCThreads));
|
||||
} else {
|
||||
which_stack_index = stack_index();
|
||||
}
|
||||
|
||||
cm->set_region_stack(ParCompactionManager::region_list(which_stack_index));
|
||||
if (TraceDynamicGCThreads) {
|
||||
gclog_or_tty->print_cr("DrainStacksCompactionTask::do_it which = %d "
|
||||
"which_stack_index = %d/empty(%d) "
|
||||
"use all workers %d",
|
||||
which, which_stack_index,
|
||||
cm->region_stack()->is_empty(),
|
||||
use_all_workers);
|
||||
}
|
||||
|
||||
cm->set_region_stack_index(which_stack_index);
|
||||
|
||||
// Process any regions already in the compaction managers stacks.
|
||||
cm->drain_region_stacks();
|
||||
|
||||
assert(cm->region_stack()->is_empty(), "Not empty");
|
||||
|
||||
if (!use_all_workers) {
|
||||
// Always give up the region stack.
|
||||
assert(cm->region_stack() ==
|
||||
ParCompactionManager::region_list(cm->region_stack_index()),
|
||||
"region_stack and region_stack_index are inconsistent");
|
||||
ParCompactionManager::push_recycled_stack_index(cm->region_stack_index());
|
||||
|
||||
if (TraceDynamicGCThreads) {
|
||||
void* old_region_stack = (void*) cm->region_stack();
|
||||
int old_region_stack_index = cm->region_stack_index();
|
||||
gclog_or_tty->print_cr("Pushing region stack 0x%x/%d",
|
||||
old_region_stack, old_region_stack_index);
|
||||
}
|
||||
|
||||
cm->set_region_stack(NULL);
|
||||
cm->set_region_stack_index((uint)max_uintx);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue