mirror of
https://github.com/openjdk/jdk.git
synced 2026-07-19 15:39:09 +00:00
8367476: Shenandoah: Remove use of CollectedHeap::_soft_ref_policy
Reviewed-by: ayang, wkemper
This commit is contained in:
parent
d0ea6686eb
commit
976207df1f
@ -29,7 +29,6 @@
|
||||
#include "gc/epsilon/epsilonBarrierSet.hpp"
|
||||
#include "gc/epsilon/epsilonMonitoringSupport.hpp"
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "gc/shared/space.hpp"
|
||||
#include "memory/virtualspace.hpp"
|
||||
#include "services/memoryManager.hpp"
|
||||
|
||||
@ -50,7 +50,6 @@
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "gc/shared/gcHeapSummary.hpp"
|
||||
#include "gc/shared/plab.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "gc/shared/taskqueue.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "memory/iterator.hpp"
|
||||
|
||||
@ -469,14 +469,9 @@ void ParallelScavengeHeap::collect(GCCause::Cause cause) {
|
||||
VMThread::execute(&op);
|
||||
}
|
||||
|
||||
bool ParallelScavengeHeap::must_clear_all_soft_refs() {
|
||||
return _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
|
||||
_gc_cause == GCCause::_wb_full_gc;
|
||||
}
|
||||
|
||||
void ParallelScavengeHeap::collect_at_safepoint(bool full) {
|
||||
assert(!GCLocker::is_active(), "precondition");
|
||||
bool clear_soft_refs = must_clear_all_soft_refs();
|
||||
bool clear_soft_refs = GCCause::should_clear_all_soft_refs(_gc_cause);
|
||||
|
||||
if (!full) {
|
||||
bool success = PSScavenge::invoke(clear_soft_refs);
|
||||
|
||||
@ -96,8 +96,6 @@ class ParallelScavengeHeap : public CollectedHeap {
|
||||
|
||||
void update_parallel_worker_threads_cpu_time();
|
||||
|
||||
bool must_clear_all_soft_refs();
|
||||
|
||||
HeapWord* allocate_new_tlab(size_t min_size, size_t requested_size, size_t* actual_size) override;
|
||||
|
||||
inline bool should_alloc_in_eden(size_t size) const;
|
||||
|
||||
@ -340,11 +340,6 @@ HeapWord* SerialHeap::mem_allocate(size_t size) {
|
||||
false /* is_tlab */);
|
||||
}
|
||||
|
||||
bool SerialHeap::must_clear_all_soft_refs() {
|
||||
return _gc_cause == GCCause::_metadata_GC_clear_soft_refs ||
|
||||
_gc_cause == GCCause::_wb_full_gc;
|
||||
}
|
||||
|
||||
bool SerialHeap::is_young_gc_safe() const {
|
||||
if (!_young_gen->to()->is_empty()) {
|
||||
return false;
|
||||
@ -497,7 +492,7 @@ void SerialHeap::scan_evacuated_objs(YoungGenScanClosure* young_cl,
|
||||
|
||||
void SerialHeap::collect_at_safepoint(bool full) {
|
||||
assert(!GCLocker::is_active(), "precondition");
|
||||
bool clear_soft_refs = must_clear_all_soft_refs();
|
||||
bool clear_soft_refs = GCCause::should_clear_all_soft_refs(_gc_cause);
|
||||
|
||||
if (!full) {
|
||||
bool success = do_young_collection(clear_soft_refs);
|
||||
|
||||
@ -31,7 +31,6 @@
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "gc/shared/oopStorageParState.hpp"
|
||||
#include "gc/shared/preGCValues.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "utilities/growableArray.hpp"
|
||||
|
||||
class CardTableRS;
|
||||
@ -104,10 +103,6 @@ private:
|
||||
|
||||
void do_full_collection(bool clear_all_soft_refs) override;
|
||||
|
||||
// Does the "cause" of GC indicate that
|
||||
// we absolutely __must__ clear soft refs?
|
||||
bool must_clear_all_soft_refs();
|
||||
|
||||
bool is_young_gc_safe() const;
|
||||
|
||||
void gc_prologue();
|
||||
|
||||
@ -276,7 +276,6 @@ bool CollectedHeap::is_oop(oop object) const {
|
||||
CollectedHeap::CollectedHeap() :
|
||||
_capacity_at_last_gc(0),
|
||||
_used_at_last_gc(0),
|
||||
_soft_ref_policy(),
|
||||
_is_stw_gc_active(false),
|
||||
_last_whole_heap_examined_time_ns(os::javaTimeNanos()),
|
||||
_total_collections(0),
|
||||
|
||||
@ -27,7 +27,6 @@
|
||||
|
||||
#include "gc/shared/gcCause.hpp"
|
||||
#include "gc/shared/gcWhen.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "gc/shared/verifyOption.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "memory/metaspace.hpp"
|
||||
@ -104,8 +103,6 @@ class CollectedHeap : public CHeapObj<mtGC> {
|
||||
size_t _capacity_at_last_gc;
|
||||
size_t _used_at_last_gc;
|
||||
|
||||
SoftRefPolicy _soft_ref_policy;
|
||||
|
||||
// First, set it to java_lang_Object.
|
||||
// Then, set it to FillerObject after the FillerObject_klass loading is complete.
|
||||
static Klass* _filler_object_klass;
|
||||
@ -395,9 +392,6 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
// Return the SoftRefPolicy for the heap;
|
||||
SoftRefPolicy* soft_ref_policy() { return &_soft_ref_policy; }
|
||||
|
||||
virtual MemoryUsage memory_usage();
|
||||
virtual GrowableArray<GCMemoryManager*> memory_managers() = 0;
|
||||
virtual GrowableArray<MemoryPool*> memory_pools() = 0;
|
||||
|
||||
@ -103,6 +103,13 @@ class GCCause : public AllStatic {
|
||||
cause == _codecache_GC_aggressive);
|
||||
}
|
||||
|
||||
// Does the "cause" of GC indicate that
|
||||
// we absolutely __must__ clear soft refs?
|
||||
inline static bool should_clear_all_soft_refs(GCCause::Cause cause) {
|
||||
return cause == GCCause::_metadata_GC_clear_soft_refs ||
|
||||
cause == GCCause::_wb_full_gc;
|
||||
}
|
||||
|
||||
// Return a string describing the GCCause.
|
||||
static const char* to_string(GCCause::Cause cause);
|
||||
};
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
#include "gc/shared/gcId.hpp"
|
||||
#include "gc/shared/gcLocker.hpp"
|
||||
#include "gc/shared/gcVMOperations.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "interpreter/oopMapCache.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "memory/classLoaderMetaspace.hpp"
|
||||
|
||||
@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2001, 2024, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef SHARE_GC_SHARED_SOFTREFPOLICY_HPP
|
||||
#define SHARE_GC_SHARED_SOFTREFPOLICY_HPP
|
||||
|
||||
class SoftRefPolicy {
|
||||
private:
|
||||
// Set to true when policy wants soft refs cleared.
|
||||
// Reset to false by gc after it clears all soft refs.
|
||||
bool _should_clear_all_soft_refs;
|
||||
|
||||
public:
|
||||
SoftRefPolicy() :
|
||||
_should_clear_all_soft_refs(false) {}
|
||||
|
||||
bool should_clear_all_soft_refs() { return _should_clear_all_soft_refs; }
|
||||
void set_should_clear_all_soft_refs(bool v) { _should_clear_all_soft_refs = v; }
|
||||
};
|
||||
|
||||
#endif // SHARE_GC_SHARED_SOFTREFPOLICY_HPP
|
||||
@ -114,6 +114,8 @@ void ShenandoahConcurrentGC::entry_concurrent_update_refs_prepare(ShenandoahHeap
|
||||
|
||||
bool ShenandoahConcurrentGC::collect(GCCause::Cause cause) {
|
||||
ShenandoahHeap* const heap = ShenandoahHeap::heap();
|
||||
_generation->ref_processor()->set_soft_reference_policy(
|
||||
GCCause::should_clear_all_soft_refs(cause));
|
||||
|
||||
ShenandoahBreakpointGCScope breakpoint_gc_scope(cause);
|
||||
|
||||
@ -732,7 +734,6 @@ void ShenandoahConcurrentGC::op_init_mark() {
|
||||
// Weak reference processing
|
||||
ShenandoahReferenceProcessor* rp = _generation->ref_processor();
|
||||
rp->reset_thread_locals();
|
||||
rp->set_soft_reference_policy(heap->soft_ref_policy()->should_clear_all_soft_refs());
|
||||
|
||||
// Make above changes visible to worker threads
|
||||
OrderAccess::fence();
|
||||
|
||||
@ -34,6 +34,7 @@
|
||||
#include "gc/shenandoah/shenandoahGeneration.hpp"
|
||||
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
|
||||
#include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
|
||||
#include "gc/shenandoah/shenandoahReferenceProcessor.hpp"
|
||||
#include "gc/shenandoah/shenandoahUtils.hpp"
|
||||
#include "logging/log.hpp"
|
||||
#include "memory/metaspaceStats.hpp"
|
||||
@ -118,7 +119,7 @@ void ShenandoahControlThread::run_service() {
|
||||
// Blow all soft references on this cycle, if handling allocation failure,
|
||||
// either implicit or explicit GC request, or we are requested to do so unconditionally.
|
||||
if (alloc_failure_pending || is_gc_requested || ShenandoahAlwaysClearSoftRefs) {
|
||||
heap->soft_ref_policy()->set_should_clear_all_soft_refs(true);
|
||||
heap->global_generation()->ref_processor()->set_soft_reference_policy(true);
|
||||
}
|
||||
|
||||
const bool gc_requested = (mode != none);
|
||||
@ -193,7 +194,7 @@ void ShenandoahControlThread::run_service() {
|
||||
heap->set_forced_counters_update(false);
|
||||
|
||||
// Retract forceful part of soft refs policy
|
||||
heap->soft_ref_policy()->set_should_clear_all_soft_refs(false);
|
||||
heap->global_generation()->ref_processor()->set_soft_reference_policy(false);
|
||||
|
||||
// Clear metaspace oom flag, if current cycle unloaded classes
|
||||
if (heap->unload_classes()) {
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
|
||||
#include "gc/shenandoah/shenandoahOldGC.hpp"
|
||||
#include "gc/shenandoah/shenandoahOldGeneration.hpp"
|
||||
#include "gc/shenandoah/shenandoahReferenceProcessor.hpp"
|
||||
#include "gc/shenandoah/shenandoahUtils.hpp"
|
||||
#include "gc/shenandoah/shenandoahYoungGeneration.hpp"
|
||||
#include "logging/log.hpp"
|
||||
@ -216,8 +217,9 @@ void ShenandoahGenerationalControlThread::run_gc_cycle(const ShenandoahGCRequest
|
||||
|
||||
// Blow away all soft references on this cycle, if handling allocation failure,
|
||||
// either implicit or explicit GC request, or we are requested to do so unconditionally.
|
||||
if (request.generation->is_global() && (ShenandoahCollectorPolicy::is_allocation_failure(request.cause) || ShenandoahCollectorPolicy::is_explicit_gc(request.cause) || ShenandoahAlwaysClearSoftRefs)) {
|
||||
_heap->soft_ref_policy()->set_should_clear_all_soft_refs(true);
|
||||
if (GCCause::should_clear_all_soft_refs(request.cause) || (request.generation->is_global() &&
|
||||
(ShenandoahCollectorPolicy::is_allocation_failure(request.cause) || ShenandoahCollectorPolicy::is_explicit_gc(request.cause) || ShenandoahAlwaysClearSoftRefs))) {
|
||||
request.generation->ref_processor()->set_soft_reference_policy(true);
|
||||
}
|
||||
|
||||
// GC is starting, bump the internal ID
|
||||
@ -289,7 +291,7 @@ void ShenandoahGenerationalControlThread::run_gc_cycle(const ShenandoahGCRequest
|
||||
_heap->set_forced_counters_update(false);
|
||||
|
||||
// Retract forceful part of soft refs policy
|
||||
_heap->soft_ref_policy()->set_should_clear_all_soft_refs(false);
|
||||
request.generation->ref_processor()->set_soft_reference_policy(false);
|
||||
|
||||
// Clear metaspace oom flag, if current cycle unloaded classes
|
||||
if (_heap->unload_classes()) {
|
||||
|
||||
@ -29,7 +29,6 @@
|
||||
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "gc/shared/markBitMap.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "gc/shenandoah/mode/shenandoahMode.hpp"
|
||||
#include "gc/shenandoah/shenandoahAllocRequest.hpp"
|
||||
#include "gc/shenandoah/shenandoahAsserts.hpp"
|
||||
|
||||
@ -221,8 +221,10 @@ void ShenandoahRefProcThreadLocal::set_discovered_list_head<oop>(oop head) {
|
||||
*discovered_list_addr<oop>() = head;
|
||||
}
|
||||
|
||||
AlwaysClearPolicy ShenandoahReferenceProcessor::_always_clear_policy;
|
||||
|
||||
ShenandoahReferenceProcessor::ShenandoahReferenceProcessor(uint max_workers) :
|
||||
_soft_reference_policy(nullptr),
|
||||
_soft_reference_policy(&_always_clear_policy),
|
||||
_ref_proc_thread_locals(NEW_C_HEAP_ARRAY(ShenandoahRefProcThreadLocal, max_workers, mtGC)),
|
||||
_pending_list(nullptr),
|
||||
_pending_list_tail(&_pending_list),
|
||||
@ -245,12 +247,11 @@ void ShenandoahReferenceProcessor::set_mark_closure(uint worker_id, ShenandoahMa
|
||||
}
|
||||
|
||||
void ShenandoahReferenceProcessor::set_soft_reference_policy(bool clear) {
|
||||
static AlwaysClearPolicy always_clear_policy;
|
||||
static LRUMaxHeapPolicy lru_max_heap_policy;
|
||||
|
||||
if (clear) {
|
||||
log_info(gc, ref)("Clearing All SoftReferences");
|
||||
_soft_reference_policy = &always_clear_policy;
|
||||
_soft_reference_policy = &_always_clear_policy;
|
||||
} else {
|
||||
_soft_reference_policy = &lru_max_heap_policy;
|
||||
}
|
||||
@ -284,7 +285,7 @@ bool ShenandoahReferenceProcessor::is_softly_live(oop reference, ReferenceType t
|
||||
// Ask SoftReference policy
|
||||
const jlong clock = java_lang_ref_SoftReference::clock();
|
||||
assert(clock != 0, "Clock not initialized");
|
||||
assert(_soft_reference_policy != nullptr, "Policy not initialized");
|
||||
assert(_soft_reference_policy != nullptr, "Should never be null");
|
||||
return !_soft_reference_policy->should_clear_reference(reference, clock);
|
||||
}
|
||||
|
||||
|
||||
@ -127,6 +127,8 @@ public:
|
||||
|
||||
class ShenandoahReferenceProcessor : public ReferenceDiscoverer {
|
||||
private:
|
||||
static AlwaysClearPolicy _always_clear_policy;
|
||||
|
||||
ReferencePolicy* _soft_reference_policy;
|
||||
|
||||
ShenandoahRefProcThreadLocal* _ref_proc_thread_locals;
|
||||
|
||||
@ -77,7 +77,6 @@ void ShenandoahSTWMark::mark() {
|
||||
ShenandoahReferenceProcessor* rp = _generation->ref_processor();
|
||||
shenandoah_assert_generations_reconciled();
|
||||
rp->reset_thread_locals();
|
||||
rp->set_soft_reference_policy(heap->soft_ref_policy()->should_clear_all_soft_refs());
|
||||
|
||||
// Init mark, do not expect forwarded pointers in roots
|
||||
if (ShenandoahVerify) {
|
||||
|
||||
@ -25,7 +25,6 @@
|
||||
#define SHARE_GC_Z_ZCOLLECTEDHEAP_HPP
|
||||
|
||||
#include "gc/shared/collectedHeap.hpp"
|
||||
#include "gc/shared/softRefPolicy.hpp"
|
||||
#include "gc/z/zBarrierSet.hpp"
|
||||
#include "gc/z/zHeap.hpp"
|
||||
#include "gc/z/zInitialize.hpp"
|
||||
|
||||
@ -1501,7 +1501,6 @@ WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString
|
||||
WB_END
|
||||
|
||||
WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
|
||||
Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
|
||||
Universe::heap()->collect(GCCause::_wb_full_gc);
|
||||
WB_END
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user