Skip to content

Commit 540188f

Browse files
committedJul 8, 2024
8334445: Parallel: Decouple maximum compaction from SoftReference clearing
Reviewed-by: zgu, lmao
1 parent 3cce31a commit 540188f

File tree

4 files changed

+31
-38
lines changed

4 files changed

+31
-38
lines changed
 

‎src/hotspot/share/gc/parallel/parallelScavengeHeap.cpp

+1-5
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,7 @@ HeapWord* ParallelScavengeHeap::mem_allocate_old_gen(size_t size) {
441441
}
442442

443443
void ParallelScavengeHeap::do_full_collection(bool clear_all_soft_refs) {
444-
// The do_full_collection() parameter clear_all_soft_refs
445-
// is interpreted here as maximum_compaction which will
446-
// cause SoftRefs to be cleared.
447-
bool maximum_compaction = clear_all_soft_refs;
448-
PSParallelCompact::invoke(maximum_compaction);
444+
PSParallelCompact::invoke(clear_all_soft_refs);
449445
}
450446

451447
// Failed allocation policy. Must be called from the VM thread, and

‎src/hotspot/share/gc/parallel/psParallelCompact.cpp

+25-25
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,21 @@ void PSParallelCompact::fill_dense_prefix_end(SpaceId id) {
826826
}
827827
}
828828

829-
bool PSParallelCompact::reassess_maximum_compaction(bool maximum_compaction,
830-
size_t total_live_words,
831-
MutableSpace* const old_space,
832-
HeapWord* full_region_prefix_end) {
829+
bool PSParallelCompact::check_maximum_compaction(size_t total_live_words,
830+
MutableSpace* const old_space,
831+
HeapWord* full_region_prefix_end) {
832+
833+
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
834+
835+
// Check System.GC
836+
bool is_max_on_system_gc = UseMaximumCompactionOnSystemGC
837+
&& GCCause::is_user_requested_gc(heap->gc_cause());
838+
833839
// Check if all live objs are larger than old-gen.
834840
const bool is_old_gen_overflowing = (total_live_words > old_space->capacity_in_words());
835841

836842
// JVM flags
837-
const uint total_invocations = ParallelScavengeHeap::heap()->total_full_collections();
843+
const uint total_invocations = heap->total_full_collections();
838844
assert(total_invocations >= _maximum_compaction_gc_num, "sanity");
839845
const size_t gcs_since_max = total_invocations - _maximum_compaction_gc_num;
840846
const bool is_interval_ended = gcs_since_max > HeapMaximumCompactionInterval;
@@ -843,15 +849,15 @@ bool PSParallelCompact::reassess_maximum_compaction(bool maximum_compaction,
843849
const bool is_region_full =
844850
full_region_prefix_end >= _summary_data.region_align_down(old_space->top());
845851

846-
if (maximum_compaction || is_old_gen_overflowing || is_interval_ended || is_region_full) {
852+
if (is_max_on_system_gc || is_old_gen_overflowing || is_interval_ended || is_region_full) {
847853
_maximum_compaction_gc_num = total_invocations;
848854
return true;
849855
}
850856

851857
return false;
852858
}
853859

854-
void PSParallelCompact::summary_phase(bool maximum_compaction)
860+
void PSParallelCompact::summary_phase()
855861
{
856862
GCTraceTime(Info, gc, phases) tm("Summary Phase", &_gc_timer);
857863

@@ -874,10 +880,9 @@ void PSParallelCompact::summary_phase(bool maximum_compaction)
874880
_space_info[i].set_dense_prefix(space->bottom());
875881
}
876882

877-
maximum_compaction = reassess_maximum_compaction(maximum_compaction,
878-
total_live_words,
879-
old_space,
880-
full_region_prefix_end);
883+
bool maximum_compaction = check_maximum_compaction(total_live_words,
884+
old_space,
885+
full_region_prefix_end);
881886
HeapWord* dense_prefix_end =
882887
maximum_compaction ? full_region_prefix_end
883888
: compute_dense_prefix_for_old_space(old_space,
@@ -958,26 +963,23 @@ void PSParallelCompact::summary_phase(bool maximum_compaction)
958963
// may be true because this method can be called without intervening
959964
// activity. For example when the heap space is tight and full measure
960965
// are being taken to free space.
961-
bool PSParallelCompact::invoke(bool maximum_heap_compaction) {
966+
bool PSParallelCompact::invoke(bool clear_all_soft_refs) {
962967
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
963968
assert(Thread::current() == (Thread*)VMThread::vm_thread(),
964969
"should be in vm thread");
965970

966-
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
967-
assert(!heap->is_stw_gc_active(), "not reentrant");
968-
969971
IsSTWGCActiveMark mark;
970972

971-
const bool clear_all_soft_refs =
972-
heap->soft_ref_policy()->should_clear_all_soft_refs();
973+
ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
974+
clear_all_soft_refs = clear_all_soft_refs
975+
|| heap->soft_ref_policy()->should_clear_all_soft_refs();
973976

974-
return PSParallelCompact::invoke_no_policy(clear_all_soft_refs ||
975-
maximum_heap_compaction);
977+
return PSParallelCompact::invoke_no_policy(clear_all_soft_refs);
976978
}
977979

978980
// This method contains no policy. You should probably
979981
// be calling invoke() instead.
980-
bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
982+
bool PSParallelCompact::invoke_no_policy(bool clear_all_soft_refs) {
981983
assert(SafepointSynchronize::is_at_safepoint(), "must be at a safepoint");
982984
assert(ref_processor() != nullptr, "Sanity");
983985

@@ -998,7 +1000,7 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
9981000

9991001
// The scope of casr should end after code that can change
10001002
// SoftRefPolicy::_should_clear_all_soft_refs.
1001-
ClearedAllSoftRefs casr(maximum_heap_compaction,
1003+
ClearedAllSoftRefs casr(clear_all_soft_refs,
10021004
heap->soft_ref_policy());
10031005

10041006
// Make sure data structures are sane, make the heap parsable, and do other
@@ -1033,17 +1035,15 @@ bool PSParallelCompact::invoke_no_policy(bool maximum_heap_compaction) {
10331035
DerivedPointerTable::clear();
10341036
#endif
10351037

1036-
ref_processor()->start_discovery(maximum_heap_compaction);
1038+
ref_processor()->start_discovery(clear_all_soft_refs);
10371039

10381040
ClassUnloadingContext ctx(1 /* num_nmethod_unlink_workers */,
10391041
false /* unregister_nmethods_during_purge */,
10401042
false /* lock_nmethod_free_separately */);
10411043

10421044
marking_phase(&_gc_tracer);
10431045

1044-
bool max_on_system_gc = UseMaximumCompactionOnSystemGC
1045-
&& GCCause::is_user_requested_gc(gc_cause);
1046-
summary_phase(maximum_heap_compaction || max_on_system_gc);
1046+
summary_phase();
10471047

10481048
#if COMPILER2_OR_JVMCI
10491049
assert(DerivedPointerTable::is_active(), "Sanity");

‎src/hotspot/share/gc/parallel/psParallelCompact.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,9 @@ class PSParallelCompact : AllStatic {
723723
static void pre_compact();
724724
static void post_compact();
725725

726-
static bool reassess_maximum_compaction(bool maximum_compaction,
727-
size_t total_live_words,
728-
MutableSpace* const old_space,
729-
HeapWord* full_region_prefix_end);
726+
static bool check_maximum_compaction(size_t total_live_words,
727+
MutableSpace* const old_space,
728+
HeapWord* full_region_prefix_end);
730729

731730
// Mark live objects
732731
static void marking_phase(ParallelOldTracer *gc_tracer);
@@ -739,7 +738,7 @@ class PSParallelCompact : AllStatic {
739738
// make the heap parsable.
740739
static void fill_dense_prefix_end(SpaceId id);
741740

742-
static void summary_phase(bool maximum_compaction);
741+
static void summary_phase();
743742

744743
static void adjust_pointers();
745744
static void forward_to_new_addr();

‎src/hotspot/share/gc/parallel/psScavenge.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,6 @@ bool PSScavenge::invoke() {
235235
assert(!ParallelScavengeHeap::heap()->is_stw_gc_active(), "not reentrant");
236236

237237
ParallelScavengeHeap* const heap = ParallelScavengeHeap::heap();
238-
PSAdaptiveSizePolicy* policy = heap->size_policy();
239238
IsSTWGCActiveMark mark;
240239

241240
const bool scavenge_done = PSScavenge::invoke_no_policy();
@@ -250,8 +249,7 @@ bool PSScavenge::invoke() {
250249

251250
if (need_full_gc) {
252251
GCCauseSetter gccs(heap, GCCause::_adaptive_size_policy);
253-
SoftRefPolicy* srp = heap->soft_ref_policy();
254-
const bool clear_all_softrefs = srp->should_clear_all_soft_refs();
252+
const bool clear_all_softrefs = heap->soft_ref_policy()->should_clear_all_soft_refs();
255253

256254
full_gc_done = PSParallelCompact::invoke_no_policy(clear_all_softrefs);
257255
}

0 commit comments

Comments
 (0)
Please sign in to comment.