Skip to content

Commit 4a9f8ef

Browse files
author
Ivan Walulya
committed
8057586: Explicit GC ignored if GCLocker is active
Reviewed-by: tschatzl, ayang
1 parent ce493dd commit 4a9f8ef

12 files changed

+328
-22
lines changed

src/hotspot/share/gc/g1/g1CollectedHeap.cpp

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,6 +1928,35 @@ bool G1CollectedHeap::try_collect_concurrently(GCCause::Cause cause,
19281928
}
19291929
}
19301930

1931+
bool G1CollectedHeap::try_collect_fullgc(GCCause::Cause cause,
1932+
const G1GCCounters& counters_before) {
1933+
assert_heap_not_locked();
1934+
1935+
while(true) {
1936+
VM_G1CollectFull op(counters_before.total_collections(),
1937+
counters_before.total_full_collections(),
1938+
cause);
1939+
VMThread::execute(&op);
1940+
1941+
// Request is trivially finished.
1942+
if (!GCCause::is_explicit_full_gc(cause) || op.gc_succeeded()) {
1943+
return op.gc_succeeded();
1944+
}
1945+
1946+
{
1947+
MutexLocker ml(Heap_lock);
1948+
if (counters_before.total_full_collections() != total_full_collections()) {
1949+
return true;
1950+
}
1951+
}
1952+
1953+
if (GCLocker::is_active_and_needs_gc()) {
1954+
// If GCLocker is active, wait until clear before retrying.
1955+
GCLocker::stall_until_clear();
1956+
}
1957+
}
1958+
}
1959+
19311960
bool G1CollectedHeap::try_collect(GCCause::Cause cause,
19321961
const G1GCCounters& counters_before) {
19331962
if (should_do_concurrent_full_gc(cause)) {
@@ -1951,11 +1980,7 @@ bool G1CollectedHeap::try_collect(GCCause::Cause cause,
19511980
return op.gc_succeeded();
19521981
} else {
19531982
// Schedule a Full GC.
1954-
VM_G1CollectFull op(counters_before.total_collections(),
1955-
counters_before.total_full_collections(),
1956-
cause);
1957-
VMThread::execute(&op);
1958-
return op.gc_succeeded();
1983+
return try_collect_fullgc(cause, counters_before);
19591984
}
19601985
}
19611986

src/hotspot/share/gc/g1/g1CollectedHeap.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ class G1CollectedHeap : public CollectedHeap {
283283
uint gc_counter,
284284
uint old_marking_started_before);
285285

286+
bool try_collect_fullgc(GCCause::Cause cause,
287+
const G1GCCounters& counters_before);
288+
286289
// indicates whether we are in young or mixed GC mode
287290
G1CollectorState _collector_state;
288291

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,26 @@ void ParallelScavengeHeap::collect(GCCause::Cause cause) {
549549
return;
550550
}
551551

552-
VM_ParallelGCSystemGC op(gc_count, full_gc_count, cause);
553-
VMThread::execute(&op);
552+
while (true) {
553+
VM_ParallelGCSystemGC op(gc_count, full_gc_count, cause);
554+
VMThread::execute(&op);
555+
556+
if (!GCCause::is_explicit_full_gc(cause) || op.full_gc_succeeded()) {
557+
return;
558+
}
559+
560+
{
561+
MutexLocker ml(Heap_lock);
562+
if (full_gc_count != total_full_collections()) {
563+
return;
564+
}
565+
}
566+
567+
if (GCLocker::is_active_and_needs_gc()) {
568+
// If GCLocker is active, wait until clear before retrying.
569+
GCLocker::stall_until_clear();
570+
}
571+
}
554572
}
555573

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ParallelScavengeHeap : public CollectedHeap {
211211
// will then attempt a full gc. The second collects the entire heap; if
212212
// maximum_compaction is true, it will compact everything and clear all soft
213213
// references.
214-
inline void invoke_scavenge();
214+
inline bool invoke_scavenge();
215215

216216
// Perform a full collection
217217
void do_full_collection(bool clear_all_soft_refs) override;

src/hotspot/share/gc/parallel/parallelScavengeHeap.inline.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2006, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -35,8 +35,8 @@ inline bool ParallelScavengeHeap::should_alloc_in_eden(const size_t size) const
3535
return size < eden_size / 2;
3636
}
3737

38-
inline void ParallelScavengeHeap::invoke_scavenge() {
39-
PSScavenge::invoke();
38+
inline bool ParallelScavengeHeap::invoke_scavenge() {
39+
return PSScavenge::invoke();
4040
}
4141

4242
inline bool ParallelScavengeHeap::is_in_young(const void* p) const {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1678,7 +1678,7 @@ void PSParallelCompact::summary_phase(bool maximum_compaction)
16781678
// may be true because this method can be called without intervening
16791679
// activity. For example when the heap space is tight and full measure
16801680
// are being taken to free space.
1681-
void PSParallelCompact::invoke(bool maximum_heap_compaction) {
1681+
bool PSParallelCompact::invoke(bool maximum_heap_compaction) {
16821682
assert(SafepointSynchronize::is_at_safepoint(), "should be at safepoint");
16831683
assert(Thread::current() == (Thread*)VMThread::vm_thread(),
16841684
"should be in vm thread");
@@ -1695,8 +1695,8 @@ void PSParallelCompact::invoke(bool maximum_heap_compaction) {
16951695
const bool clear_all_soft_refs =
16961696
heap->soft_ref_policy()->should_clear_all_soft_refs();
16971697

1698-
PSParallelCompact::invoke_no_policy(clear_all_soft_refs ||
1699-
maximum_heap_compaction);
1698+
return PSParallelCompact::invoke_no_policy(clear_all_soft_refs ||
1699+
maximum_heap_compaction);
17001700
}
17011701

17021702
// This method contains no policy. You should probably

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ class PSParallelCompact : AllStatic {
11411141

11421142
PSParallelCompact();
11431143

1144-
static void invoke(bool maximum_heap_compaction);
1144+
static bool invoke(bool maximum_heap_compaction);
11451145
static bool invoke_no_policy(bool maximum_heap_compaction);
11461146

11471147
static void post_initialize();

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ static bool is_cause_full(GCCause::Cause cause) {
5858
VM_ParallelGCSystemGC::VM_ParallelGCSystemGC(uint gc_count,
5959
uint full_gc_count,
6060
GCCause::Cause gc_cause) :
61-
VM_GC_Operation(gc_count, gc_cause, full_gc_count, is_cause_full(gc_cause))
61+
VM_GC_Operation(gc_count, gc_cause, full_gc_count, is_cause_full(gc_cause)),
62+
_full_gc_succeeded(false)
6263
{
6364
}
6465

@@ -70,8 +71,8 @@ void VM_ParallelGCSystemGC::doit() {
7071
GCCauseSetter gccs(heap, _gc_cause);
7172
if (!_full) {
7273
// If (and only if) the scavenge fails, this will invoke a full gc.
73-
heap->invoke_scavenge();
74+
_full_gc_succeeded = heap->invoke_scavenge();
7475
} else {
75-
heap->do_full_collection(false);
76+
_full_gc_succeeded = PSParallelCompact::invoke(false);
7677
}
7778
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2007, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2007, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -40,10 +40,12 @@ class VM_ParallelGCFailedAllocation : public VM_CollectForAllocation {
4040
};
4141

4242
class VM_ParallelGCSystemGC: public VM_GC_Operation {
43+
bool _full_gc_succeeded;
4344
public:
4445
VM_ParallelGCSystemGC(uint gc_count, uint full_gc_count, GCCause::Cause gc_cause);
4546
virtual VMOp_Type type() const { return VMOp_ParallelGCSystemGC; }
4647
virtual void doit();
48+
bool full_gc_succeeded() const { return _full_gc_succeeded; }
4749
};
4850

4951
#endif // SHARE_GC_PARALLEL_PSVMOPERATIONS_HPP

src/hotspot/share/gc/shared/gcCause.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ class GCCause : public AllStatic {
9595
cause == GCCause::_dcmd_gc_run);
9696
}
9797

98+
inline static bool is_explicit_full_gc(GCCause::Cause cause) {
99+
return (is_user_requested_gc(cause) ||
100+
is_serviceability_requested_gc(cause) ||
101+
cause == GCCause::_wb_full_gc);
102+
}
103+
98104
inline static bool is_serviceability_requested_gc(GCCause::Cause
99105
cause) {
100106
return (cause == GCCause::_jvmti_force_gc ||

0 commit comments

Comments
 (0)