Skip to content

Commit 3e68d7d

Browse files
committed
8366881: Parallel: Obsolete HeapMaximumCompactionInterval
Reviewed-by: iwalulya
1 parent 85441ce commit 3e68d7d

File tree

5 files changed

+30
-47
lines changed

5 files changed

+30
-47
lines changed

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

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ HeapWord* ParallelScavengeHeap::mem_allocate_work(size_t size, bool is_tlab) {
334334
}
335335

336336
void ParallelScavengeHeap::do_full_collection(bool clear_all_soft_refs) {
337-
PSParallelCompact::invoke(clear_all_soft_refs);
337+
// No need for max-compaction in this context.
338+
const bool should_do_max_compaction = false;
339+
PSParallelCompact::invoke(clear_all_soft_refs, should_do_max_compaction);
338340
}
339341

340342
static bool check_gc_heap_free_limit(size_t free_bytes, size_t capacity_bytes) {
@@ -394,21 +396,11 @@ HeapWord* ParallelScavengeHeap::satisfy_failed_allocation(size_t size, bool is_t
394396
}
395397
}
396398

397-
// If we reach this point, we're really out of memory. Try every trick
398-
// we can to reclaim memory. Force collection of soft references. Force
399-
// a complete compaction of the heap. Any additional methods for finding
400-
// free memory should be here, especially if they are expensive. If this
401-
// attempt fails, an OOM exception will be thrown.
399+
// Last resort GC; clear soft refs and do max-compaction before throwing OOM.
402400
{
403-
// Make sure the heap is fully compacted
404-
uintx old_interval = HeapMaximumCompactionInterval;
405-
HeapMaximumCompactionInterval = 0;
406-
407401
const bool clear_all_soft_refs = true;
408-
PSParallelCompact::invoke(clear_all_soft_refs);
409-
410-
// Restore
411-
HeapMaximumCompactionInterval = old_interval;
402+
const bool should_do_max_compaction = true;
403+
PSParallelCompact::invoke(clear_all_soft_refs, should_do_max_compaction);
412404
}
413405

414406
if (check_gc_overhead_limit()) {
@@ -493,7 +485,8 @@ void ParallelScavengeHeap::collect_at_safepoint(bool full) {
493485
}
494486
// Upgrade to Full-GC if young-gc fails
495487
}
496-
PSParallelCompact::invoke(clear_soft_refs);
488+
const bool should_do_max_compaction = false;
489+
PSParallelCompact::invoke(clear_soft_refs, should_do_max_compaction);
497490
}
498491

499492
void ParallelScavengeHeap::object_iterate(ObjectClosure* cl) {

src/hotspot/share/gc/parallel/parallel_globals.hpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131
product_pd, \
3232
range, \
3333
constraint) \
34-
product(uintx, HeapMaximumCompactionInterval, 20, \
35-
"How often should we maximally compact the heap (not allowing " \
36-
"any dead space)") \
37-
range(0, max_uintx) \
38-
\
3934
product(bool, UseMaximumCompactionOnSystemGC, true, \
4035
"Use maximum compaction in the Parallel Old garbage collector " \
4136
"for a system GC") \

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

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ void PSParallelCompact::fill_dense_prefix_end(SpaceId id) {
826826
}
827827
}
828828

829-
bool PSParallelCompact::check_maximum_compaction(size_t total_live_words,
829+
bool PSParallelCompact::check_maximum_compaction(bool should_do_max_compaction,
830+
size_t total_live_words,
830831
MutableSpace* const old_space,
831832
HeapWord* full_region_prefix_end) {
832833

@@ -839,25 +840,17 @@ bool PSParallelCompact::check_maximum_compaction(size_t total_live_words,
839840
// Check if all live objs are too much for old-gen.
840841
const bool is_old_gen_too_full = (total_live_words >= old_space->capacity_in_words());
841842

842-
// JVM flags
843-
const uint total_invocations = heap->total_full_collections();
844-
assert(total_invocations >= _maximum_compaction_gc_num, "sanity");
845-
const size_t gcs_since_max = total_invocations - _maximum_compaction_gc_num;
846-
const bool is_interval_ended = gcs_since_max > HeapMaximumCompactionInterval;
847-
848843
// If all regions in old-gen are full
849844
const bool is_region_full =
850845
full_region_prefix_end >= _summary_data.region_align_down(old_space->top());
851846

852-
if (is_max_on_system_gc || is_old_gen_too_full || is_interval_ended || is_region_full) {
853-
_maximum_compaction_gc_num = total_invocations;
854-
return true;
855-
}
856-
857-
return false;
847+
return should_do_max_compaction
848+
|| is_max_on_system_gc
849+
|| is_old_gen_too_full
850+
|| is_region_full;
858851
}
859852

860-
void PSParallelCompact::summary_phase()
853+
void PSParallelCompact::summary_phase(bool should_do_max_compaction)
861854
{
862855
GCTraceTime(Info, gc, phases) tm("Summary Phase", &_gc_timer);
863856

@@ -880,9 +873,10 @@ void PSParallelCompact::summary_phase()
880873
_space_info[i].set_dense_prefix(space->bottom());
881874
}
882875

883-
bool maximum_compaction = check_maximum_compaction(total_live_words,
884-
old_space,
885-
full_region_prefix_end);
876+
should_do_max_compaction = check_maximum_compaction(should_do_max_compaction,
877+
total_live_words,
878+
old_space,
879+
full_region_prefix_end);
886880
{
887881
GCTraceTime(Info, gc, phases) tm("Summary Phase: expand", &_gc_timer);
888882
// Try to expand old-gen in order to fit all live objs and waste.
@@ -891,7 +885,7 @@ void PSParallelCompact::summary_phase()
891885
ParallelScavengeHeap::heap()->old_gen()->try_expand_till_size(target_capacity_bytes);
892886
}
893887

894-
HeapWord* dense_prefix_end = maximum_compaction
888+
HeapWord* dense_prefix_end = should_do_max_compaction
895889
? full_region_prefix_end
896890
: compute_dense_prefix_for_old_space(old_space,
897891
full_region_prefix_end);
@@ -961,11 +955,7 @@ void PSParallelCompact::summary_phase()
961955
}
962956
}
963957

964-
// This method invokes a full collection. The argument controls whether
965-
// soft-refs should be cleared or not.
966-
// Note that this method should only be called from the vm_thread while at a
967-
// safepoint.
968-
bool PSParallelCompact::invoke(bool clear_all_soft_refs) {
958+
bool PSParallelCompact::invoke(bool clear_all_soft_refs, bool should_do_max_compaction) {
969959
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
970960
assert(Thread::current() == (Thread*)VMThread::vm_thread(),
971961
"should be in vm thread");
@@ -1020,7 +1010,7 @@ bool PSParallelCompact::invoke(bool clear_all_soft_refs) {
10201010

10211011
marking_phase(&_gc_tracer);
10221012

1023-
summary_phase();
1013+
summary_phase(should_do_max_compaction);
10241014

10251015
#if COMPILER2_OR_JVMCI
10261016
assert(DerivedPointerTable::is_active(), "Sanity");

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,8 @@ class PSParallelCompact : AllStatic {
727727
static void pre_compact();
728728
static void post_compact();
729729

730-
static bool check_maximum_compaction(size_t total_live_words,
730+
static bool check_maximum_compaction(bool should_do_max_compaction,
731+
size_t total_live_words,
731732
MutableSpace* const old_space,
732733
HeapWord* full_region_prefix_end);
733734

@@ -742,7 +743,7 @@ class PSParallelCompact : AllStatic {
742743
// make the heap parsable.
743744
static void fill_dense_prefix_end(SpaceId id);
744745

745-
static void summary_phase();
746+
static void summary_phase(bool should_do_max_compaction);
746747

747748
static void adjust_pointers();
748749
static void forward_to_new_addr();
@@ -761,7 +762,10 @@ class PSParallelCompact : AllStatic {
761762
public:
762763
static void fill_dead_objs_in_dense_prefix(uint worker_id, uint num_workers);
763764

764-
static bool invoke(bool clear_all_soft_refs);
765+
// This method invokes a full collection.
766+
// clear_all_soft_refs controls whether soft-refs should be cleared or not.
767+
// should_do_max_compaction controls whether all spaces for dead objs should be reclaimed.
768+
static bool invoke(bool clear_all_soft_refs, bool should_do_max_compaction);
765769

766770
template<typename Func>
767771
static void adjust_in_space_helper(SpaceId id, volatile uint* claim_counter, Func&& on_stripe);

src/hotspot/share/runtime/arguments.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,7 @@ static SpecialFlag const special_jvm_flags[] = {
568568
{ "UsePSAdaptiveSurvivorSizePolicy", JDK_Version::undefined(), JDK_Version::jdk(26), JDK_Version::jdk(27) },
569569

570570
{ "PretenureSizeThreshold", JDK_Version::undefined(), JDK_Version::jdk(26), JDK_Version::jdk(27) },
571+
{ "HeapMaximumCompactionInterval",JDK_Version::undefined(), JDK_Version::jdk(26), JDK_Version::jdk(27) },
571572

572573
#ifdef ASSERT
573574
{ "DummyObsoleteTestFlag", JDK_Version::undefined(), JDK_Version::jdk(18), JDK_Version::undefined() },

0 commit comments

Comments
 (0)