8364767: G1: Remove use of CollectedHeap::_soft_ref_policy

Reviewed-by: tschatzl, sangheki
This commit is contained in:
Albert Mingkun Yang
2025-08-11 09:42:12 +00:00
parent 10762d408b
commit 0c39228ec1
6 changed files with 7 additions and 38 deletions

View File

@@ -848,12 +848,9 @@ void G1CollectedHeap::do_full_collection(bool clear_all_soft_refs,
size_t allocation_word_size) { size_t allocation_word_size) {
assert_at_safepoint_on_vm_thread(); assert_at_safepoint_on_vm_thread();
const bool do_clear_all_soft_refs = clear_all_soft_refs ||
soft_ref_policy()->should_clear_all_soft_refs();
G1FullGCMark gc_mark; G1FullGCMark gc_mark;
GCTraceTime(Info, gc) tm("Pause Full", nullptr, gc_cause(), true); GCTraceTime(Info, gc) tm("Pause Full", nullptr, gc_cause(), true);
G1FullCollector collector(this, do_clear_all_soft_refs, do_maximal_compaction, gc_mark.tracer()); G1FullCollector collector(this, clear_all_soft_refs, do_maximal_compaction, gc_mark.tracer());
collector.prepare_collection(); collector.prepare_collection();
collector.collect(); collector.collect();
@@ -986,9 +983,6 @@ HeapWord* G1CollectedHeap::satisfy_failed_allocation(size_t word_size) {
return result; return result;
} }
assert(!soft_ref_policy()->should_clear_all_soft_refs(),
"Flag should have been handled and cleared prior to this point");
// What else? We might try synchronous finalization later. If the total // What else? We might try synchronous finalization later. If the total
// space available is large enough for the allocation, then a more // space available is large enough for the allocation, then a more
// complete compaction phase than we've tried so far might be // complete compaction phase than we've tried so far might be

View File

@@ -40,6 +40,7 @@ G1FullGCScope::G1FullGCScope(G1MonitoringSupport* monitoring_support,
bool do_maximal_compaction, bool do_maximal_compaction,
G1FullGCTracer* tracer) : G1FullGCTracer* tracer) :
_rm(), _rm(),
_should_clear_soft_refs(clear_soft),
_do_maximal_compaction(do_maximal_compaction), _do_maximal_compaction(do_maximal_compaction),
_g1h(G1CollectedHeap::heap()), _g1h(G1CollectedHeap::heap()),
_svc_marker(SvcGCMarker::FULL), _svc_marker(SvcGCMarker::FULL),
@@ -47,17 +48,12 @@ G1FullGCScope::G1FullGCScope(G1MonitoringSupport* monitoring_support,
_tracer(tracer), _tracer(tracer),
_active(), _active(),
_tracer_mark(&_timer, _tracer), _tracer_mark(&_timer, _tracer),
_soft_refs(clear_soft, _g1h->soft_ref_policy()),
_monitoring_scope(monitoring_support), _monitoring_scope(monitoring_support),
_heap_printer(_g1h), _heap_printer(_g1h),
_region_compaction_threshold(do_maximal_compaction ? _region_compaction_threshold(do_maximal_compaction ?
G1HeapRegion::GrainWords : G1HeapRegion::GrainWords :
(1 - MarkSweepDeadRatio / 100.0) * G1HeapRegion::GrainWords) { } (1 - MarkSweepDeadRatio / 100.0) * G1HeapRegion::GrainWords) { }
bool G1FullGCScope::should_clear_soft_refs() {
return _soft_refs.should_clear();
}
STWGCTimer* G1FullGCScope::timer() { STWGCTimer* G1FullGCScope::timer() {
return &_timer; return &_timer;
} }

View File

@@ -47,6 +47,7 @@ public:
// Class used to group scoped objects used in the Full GC together. // Class used to group scoped objects used in the Full GC together.
class G1FullGCScope : public StackObj { class G1FullGCScope : public StackObj {
ResourceMark _rm; ResourceMark _rm;
bool _should_clear_soft_refs;
bool _do_maximal_compaction; bool _do_maximal_compaction;
G1CollectedHeap* _g1h; G1CollectedHeap* _g1h;
SvcGCMarker _svc_marker; SvcGCMarker _svc_marker;
@@ -54,7 +55,6 @@ class G1FullGCScope : public StackObj {
G1FullGCTracer* _tracer; G1FullGCTracer* _tracer;
IsSTWGCActiveMark _active; IsSTWGCActiveMark _active;
G1FullGCJFRTracerMark _tracer_mark; G1FullGCJFRTracerMark _tracer_mark;
ClearedAllSoftRefs _soft_refs;
G1FullGCMonitoringScope _monitoring_scope; G1FullGCMonitoringScope _monitoring_scope;
G1HeapPrinterMark _heap_printer; G1HeapPrinterMark _heap_printer;
size_t _region_compaction_threshold; size_t _region_compaction_threshold;
@@ -65,7 +65,7 @@ public:
bool do_maximal_compaction, bool do_maximal_compaction,
G1FullGCTracer* tracer); G1FullGCTracer* tracer);
bool should_clear_soft_refs(); bool should_clear_soft_refs() const { return _should_clear_soft_refs; }
bool do_maximal_compaction() { return _do_maximal_compaction; } bool do_maximal_compaction() { return _do_maximal_compaction; }
STWGCTimer* timer(); STWGCTimer* timer();

View File

@@ -50,7 +50,9 @@ bool VM_G1CollectFull::skip_operation() const {
void VM_G1CollectFull::doit() { void VM_G1CollectFull::doit() {
G1CollectedHeap* g1h = G1CollectedHeap::heap(); G1CollectedHeap* g1h = G1CollectedHeap::heap();
GCCauseSetter x(g1h, _gc_cause); GCCauseSetter x(g1h, _gc_cause);
g1h->do_full_collection(false /* clear_all_soft_refs */, bool clear_all_soft_refs = _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
_gc_cause == GCCause::_wb_full_gc;
g1h->do_full_collection(clear_all_soft_refs /* clear_all_soft_refs */,
false /* do_maximal_compaction */, false /* do_maximal_compaction */,
size_t(0) /* allocation_word_size */); size_t(0) /* allocation_word_size */);
} }

View File

@@ -58,21 +58,4 @@ class SoftRefPolicy {
} }
}; };
class ClearedAllSoftRefs : public StackObj {
bool _clear_all_soft_refs;
SoftRefPolicy* _soft_ref_policy;
public:
ClearedAllSoftRefs(bool clear_all_soft_refs, SoftRefPolicy* soft_ref_policy) :
_clear_all_soft_refs(clear_all_soft_refs),
_soft_ref_policy(soft_ref_policy) {}
~ClearedAllSoftRefs() {
if (_clear_all_soft_refs) {
_soft_ref_policy->cleared_all_soft_refs();
}
}
bool should_clear() { return _clear_all_soft_refs; }
};
#endif // SHARE_GC_SHARED_SOFTREFPOLICY_HPP #endif // SHARE_GC_SHARED_SOFTREFPOLICY_HPP

View File

@@ -1502,12 +1502,6 @@ WB_END
WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true); Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
Universe::heap()->collect(GCCause::_wb_full_gc); Universe::heap()->collect(GCCause::_wb_full_gc);
#if INCLUDE_G1GC
if (UseG1GC) {
// Needs to be cleared explicitly for G1 GC.
Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
}
#endif // INCLUDE_G1GC
WB_END WB_END
WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))