--- old/src/hotspot/share/gc/g1/g1FullCollector.cpp 2018-03-26 11:42:35.078923733 +0200 +++ new/src/hotspot/share/gc/g1/g1FullCollector.cpp 2018-03-26 11:42:34.766911405 +0200 @@ -37,6 +37,7 @@ #include "gc/g1/g1OopClosures.hpp" #include "gc/g1/g1Policy.hpp" #include "gc/g1/g1StringDedup.hpp" +#include "gc/shared/adaptiveSizePolicy.hpp" #include "gc/shared/gcTraceTime.inline.hpp" #include "gc/shared/preservedMarks.hpp" #include "gc/shared/referenceProcessor.hpp" @@ -72,10 +73,40 @@ return _heap->ref_processor_stw(); } +uint G1FullCollector::calc_active_workers() { + G1CollectedHeap* heap = G1CollectedHeap::heap(); + uint max_worker_count = heap->workers()->total_workers(); + // Only calculate number of workers if UseDynamicNumberOfGCThreads + // is enabled, otherwise use max. + if (!UseDynamicNumberOfGCThreads) { + return max_worker_count; + } + + // Consider G1HeapWastePercent to decide max number of workers. Each worker + // will in average cause half a region waste. + uint max_wasted_regions_allowed = ((heap->num_regions() * G1HeapWastePercent) / 100); + uint waste_worker_count = MAX2((max_wasted_regions_allowed * 2) , 1u); + uint heap_waste_worker_limit = MIN2(waste_worker_count, max_worker_count); + + // Also consider HeapSizePerGCThread by calling AdaptiveSizePolicy to calculate + // the number of workers. + uint current_active_workers = heap->workers()->active_workers(); + uint adaptive_worker_limit = AdaptiveSizePolicy::calc_active_workers(max_worker_count, current_active_workers, 0); + + // Update active workers to the lower of the limits. + uint worker_count = MIN2(heap_waste_worker_limit, adaptive_worker_limit); + log_debug(gc, task)("Requesting %u active workers for full compaction (waste limited workers: %u, adaptive workers: %u)", + worker_count, heap_waste_worker_limit, adaptive_worker_limit); + worker_count = heap->workers()->update_active_workers(worker_count); + log_info(gc, task)("Using %u workers of %u for full compaction", worker_count, max_worker_count); + + return worker_count; +} + G1FullCollector::G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs) : _heap(heap), _scope(memory_manager, explicit_gc, clear_soft_refs), - _num_workers(heap->workers()->active_workers()), + _num_workers(calc_active_workers()), _oop_queue_set(_num_workers), _array_queue_set(_num_workers), _preserved_marks_set(true), --- old/src/hotspot/share/gc/g1/g1FullCollector.hpp 2018-03-26 11:42:35.934957557 +0200 +++ new/src/hotspot/share/gc/g1/g1FullCollector.hpp 2018-03-26 11:42:35.626945386 +0200 @@ -56,6 +56,8 @@ G1IsAliveClosure _is_alive; ReferenceProcessorIsAliveMutator _is_alive_mutator; + static uint calc_active_workers(); + public: G1FullCollector(G1CollectedHeap* heap, GCMemoryManager* memory_manager, bool explicit_gc, bool clear_soft_refs); ~G1FullCollector(); --- old/src/hotspot/share/gc/shared/adaptiveSizePolicy.hpp 2018-03-26 11:42:36.778990906 +0200 +++ new/src/hotspot/share/gc/shared/adaptiveSizePolicy.hpp 2018-03-26 11:42:36.466978578 +0200 @@ -355,6 +355,7 @@ // For ParNew collections // For PS scavenge and ParOld collections // For G1 evacuation pauses (subject to update) + // For G1 Full GCs (subject to update) // Other collection phases inherit the number of // GC workers from the calls above. For example, // a CMS parallel remark uses the same number of GC