diff --git a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp index 0c55613efcc..8b0d2d4c8be 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahGeneration.cpp @@ -800,7 +800,7 @@ ShenandoahGeneration::ShenandoahGeneration(ShenandoahGenerationType type, size_t max_capacity) : _type(type), _task_queues(new ShenandoahObjToScanQueueSet(max_workers)), - _ref_processor(new ShenandoahReferenceProcessor(MAX2(max_workers, 1U))), + _ref_processor(new ShenandoahReferenceProcessor(this, MAX2(max_workers, 1U))), _affiliated_region_count(0), _humongous_waste(0), _evacuation_reserve(0), _used(0), _bytes_allocated_since_gc_start(0), _max_capacity(max_capacity), diff --git a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp index f37329d1c44..7187431c8f8 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.cpp @@ -223,13 +223,13 @@ void ShenandoahRefProcThreadLocal::set_discovered_list_head(oop head) { AlwaysClearPolicy ShenandoahReferenceProcessor::_always_clear_policy; -ShenandoahReferenceProcessor::ShenandoahReferenceProcessor(uint max_workers) : +ShenandoahReferenceProcessor::ShenandoahReferenceProcessor(ShenandoahGeneration* generation, uint max_workers) : _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), _iterate_discovered_list_id(0U), - _stats() { + _generation(generation) { for (size_t i = 0; i < max_workers; i++) { _ref_proc_thread_locals[i].reset(); } @@ -311,7 +311,7 @@ bool ShenandoahReferenceProcessor::should_discover(oop reference, ReferenceType return false; } - if (!heap->is_in_active_generation(referent)) { + if (!_generation->contains(referent)) { log_trace(gc,ref)("Referent outside of active generation: " PTR_FORMAT, p2i(referent)); return false; } @@ -329,31 +329,23 @@ bool ShenandoahReferenceProcessor::should_drop(oop reference, ReferenceType type return true; } - shenandoah_assert_mark_complete(raw_referent); - ShenandoahHeap* heap = ShenandoahHeap::heap(); // Check if the referent is still alive, in which case we should drop the reference. if (type == REF_PHANTOM) { - return heap->marking_context()->is_marked(raw_referent); + return _generation->complete_marking_context()->is_marked(raw_referent); } else { - return heap->marking_context()->is_marked_strong(raw_referent); + return _generation->complete_marking_context()->is_marked_strong(raw_referent); } } template void ShenandoahReferenceProcessor::make_inactive(oop reference, ReferenceType type) const { if (type == REF_FINAL) { -#ifdef ASSERT - auto referent = reference_referent_raw(reference); - auto heap = ShenandoahHeap::heap(); - shenandoah_assert_mark_complete(referent); - assert(reference_next(reference) == nullptr, "Already inactive"); - assert(heap->marking_context()->is_marked(referent), "only make inactive final refs with alive referents"); -#endif - // Don't clear referent. It is needed by the Finalizer thread to make the call // to finalize(). A FinalReference is instead made inactive by self-looping the // next field. An application can't call FinalReference.enqueue(), so there is // no race to worry about when setting the next field. + assert(reference_next(reference) == nullptr, "Already inactive"); + assert(_generation->complete_marking_context()->is_marked(reference_referent_raw(reference)), "only make inactive final refs with alive referents"); reference_set_next(reference, reference); } else { // Clear referent @@ -443,12 +435,8 @@ oop ShenandoahReferenceProcessor::drop(oop reference, ReferenceType type) { HeapWord* raw_referent = reference_referent_raw(reference); #ifdef ASSERT - if (raw_referent != nullptr) { - ShenandoahHeap* heap = ShenandoahHeap::heap(); - ShenandoahHeapRegion* region = heap->heap_region_containing(raw_referent); - ShenandoahMarkingContext* ctx = heap->generation_for(region->affiliation())->complete_marking_context(); - assert(ctx->is_marked(raw_referent), "only drop references with alive referents"); - } + assert(raw_referent == nullptr || _generation->complete_marking_context()->is_marked(raw_referent), + "only drop references with alive referents"); #endif // Unlink and return next in list diff --git a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp index 11099f1303d..be11a364ab7 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahReferenceProcessor.hpp @@ -140,6 +140,8 @@ private: ReferenceProcessorStats _stats; + ShenandoahGeneration* _generation; + template bool is_inactive(oop reference, oop referent, ReferenceType type) const; bool is_strongly_live(oop referent) const; @@ -172,7 +174,7 @@ private: void clean_discovered_list(T* list); public: - ShenandoahReferenceProcessor(uint max_workers); + ShenandoahReferenceProcessor(ShenandoahGeneration* generation, uint max_workers); void reset_thread_locals(); void set_mark_closure(uint worker_id, ShenandoahMarkRefsSuperClosure* mark_closure);