From 18c925cd33d6f3b1d4365d582dddaa8426f41bea Mon Sep 17 00:00:00 2001 From: Albert Mingkun Yang Date: Fri, 5 Apr 2024 09:59:09 +0000 Subject: [PATCH] 8329661: Refactor ScavengableNMethods::verify_unlisted_nmethods Reviewed-by: stefank, iwalulya --- src/hotspot/share/gc/serial/serialHeap.cpp | 25 ------------------- src/hotspot/share/gc/serial/serialHeap.hpp | 4 --- .../share/gc/shared/scavengableNMethods.cpp | 25 +++---------------- .../share/gc/shared/scavengableNMethods.hpp | 4 +-- 4 files changed, 5 insertions(+), 53 deletions(-) diff --git a/src/hotspot/share/gc/serial/serialHeap.cpp b/src/hotspot/share/gc/serial/serialHeap.cpp index 3497857255e..a7416256164 100644 --- a/src/hotspot/share/gc/serial/serialHeap.cpp +++ b/src/hotspot/share/gc/serial/serialHeap.cpp @@ -725,17 +725,6 @@ HeapWord* SerialHeap::satisfy_failed_allocation(size_t size, bool is_tlab) { return nullptr; } -#ifdef ASSERT -class AssertNonScavengableClosure: public OopClosure { -public: - virtual void do_oop(oop* p) { - assert(!SerialHeap::heap()->is_in_partial_collection(*p), - "Referent should not be scavengable."); } - virtual void do_oop(narrowOop* p) { ShouldNotReachHere(); } -}; -static AssertNonScavengableClosure assert_is_non_scavengable_closure; -#endif - void SerialHeap::process_roots(ScanningOption so, OopClosure* strong_roots, CLDClosure* strong_cld_closure, @@ -766,10 +755,6 @@ void SerialHeap::process_roots(ScanningOption so, // We scan the entire code cache, since CodeCache::do_unloading is not called. CodeCache::blobs_do(code_roots); } - // Verify that the code cache contents are not subject to - // movement by a scavenging collection. - DEBUG_ONLY(CodeBlobToOopClosure assert_code_is_non_scavengable(&assert_is_non_scavengable_closure, !CodeBlobToOopClosure::FixRelocations)); - DEBUG_ONLY(ScavengableNMethods::asserted_non_scavengable_nmethods_do(&assert_code_is_non_scavengable)); } bool SerialHeap::no_allocs_since_save_marks() { @@ -869,16 +854,6 @@ bool SerialHeap::is_in(const void* p) const { return _young_gen->is_in(p) || _old_gen->is_in(p); } -#ifdef ASSERT -// Don't implement this by using is_in_young(). This method is used -// in some cases to check that is_in_young() is correct. -bool SerialHeap::is_in_partial_collection(const void* p) { - assert(is_in_reserved(p) || p == nullptr, - "Does not work if address is non-null and outside of the heap"); - return p < _young_gen->reserved().end() && p != nullptr; -} -#endif - void SerialHeap::object_iterate(ObjectClosure* cl) { _young_gen->object_iterate(cl); _old_gen->object_iterate(cl); diff --git a/src/hotspot/share/gc/serial/serialHeap.hpp b/src/hotspot/share/gc/serial/serialHeap.hpp index f780b55ac68..c71153df317 100644 --- a/src/hotspot/share/gc/serial/serialHeap.hpp +++ b/src/hotspot/share/gc/serial/serialHeap.hpp @@ -178,10 +178,6 @@ public: bool requires_barriers(stackChunkOop obj) const override; -#ifdef ASSERT - bool is_in_partial_collection(const void* p); -#endif - // Optimized nmethod scanning support routines void register_nmethod(nmethod* nm) override; void unregister_nmethod(nmethod* nm) override; diff --git a/src/hotspot/share/gc/shared/scavengableNMethods.cpp b/src/hotspot/share/gc/shared/scavengableNMethods.cpp index 6c8e6259b11..f444d4cffc2 100644 --- a/src/hotspot/share/gc/shared/scavengableNMethods.cpp +++ b/src/hotspot/share/gc/shared/scavengableNMethods.cpp @@ -157,7 +157,7 @@ void ScavengableNMethods::nmethods_do_and_prune(CodeBlobToOopClosure* cl) { } // Check for stray marks. - debug_only(verify_unlisted_nmethods(nullptr)); + debug_only(verify_nmethods()); } void ScavengableNMethods::prune_nmethods_not_into_young() { @@ -188,7 +188,7 @@ void ScavengableNMethods::prune_unlinked_nmethods() { } // Check for stray marks. - debug_only(verify_unlisted_nmethods(nullptr)); + debug_only(verify_nmethods()); } // Walk the list of methods which might contain oops to the java heap. @@ -196,18 +196,6 @@ void ScavengableNMethods::nmethods_do(CodeBlobToOopClosure* cl) { nmethods_do_and_prune(cl); } -#ifndef PRODUCT -void ScavengableNMethods::asserted_non_scavengable_nmethods_do(CodeBlobClosure* cl) { - // While we are here, verify the integrity of the list. - mark_on_list_nmethods(); - for (nmethod* cur = _head; cur != nullptr; cur = gc_data(cur).next()) { - assert(gc_data(cur).on_list(), "else shouldn't be on this list"); - gc_data(cur).clear_marked(); - } - verify_unlisted_nmethods(cl); -} -#endif // PRODUCT - void ScavengableNMethods::unlist_nmethod(nmethod* nm, nmethod* prev) { assert_locked_or_safepoint(CodeCache_lock); @@ -239,9 +227,8 @@ void ScavengableNMethods::mark_on_list_nmethods() { } } -// If the closure is given, run it on the unlisted nmethods. -// Also make sure that the effects of mark_on_list_nmethods is gone. -void ScavengableNMethods::verify_unlisted_nmethods(CodeBlobClosure* cl) { +// Make sure that the effects of mark_on_list_nmethods is gone. +void ScavengableNMethods::verify_nmethods() { NMethodIterator iter(NMethodIterator::all_blobs); while(iter.next()) { nmethod* nm = iter.method(); @@ -250,10 +237,6 @@ void ScavengableNMethods::verify_unlisted_nmethods(CodeBlobClosure* cl) { if (!nm->is_unlinked()) { verify_nmethod(nm); } - - if (cl != nullptr && !gc_data(nm).on_list()) { - cl->do_code_blob(nm); - } } } diff --git a/src/hotspot/share/gc/shared/scavengableNMethods.hpp b/src/hotspot/share/gc/shared/scavengableNMethods.hpp index 94d594cd529..18f130a7425 100644 --- a/src/hotspot/share/gc/shared/scavengableNMethods.hpp +++ b/src/hotspot/share/gc/shared/scavengableNMethods.hpp @@ -55,8 +55,6 @@ public: // Remove nmethods that no longer have scavengable oops. static void nmethods_do(CodeBlobToOopClosure* cl); - static void asserted_non_scavengable_nmethods_do(CodeBlobClosure* cl) PRODUCT_RETURN; - private: static void nmethods_do_and_prune(CodeBlobToOopClosure* cl); static void unlist_nmethod(nmethod* nm, nmethod* prev); @@ -64,7 +62,7 @@ private: static bool has_scavengable_oops(nmethod* nm); static void mark_on_list_nmethods() PRODUCT_RETURN; - static void verify_unlisted_nmethods(CodeBlobClosure* cl) PRODUCT_RETURN; + static void verify_nmethods() PRODUCT_RETURN; }; #endif // SHARE_GC_SHARED_SCAVENGABLENMETHODS_HPP