From bdffe460cd325f55fffd8e48bd3d15f08d998b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20=C3=96sterlund?= Date: Mon, 6 Mar 2023 11:14:32 +0000 Subject: [PATCH] 8301222: Generalize check_release_entry in OopStorage Reviewed-by: tschatzl, kbarrett --- src/hotspot/share/gc/shared/collectedHeap.cpp | 4 ++++ src/hotspot/share/gc/shared/collectedHeap.hpp | 6 ++++++ src/hotspot/share/gc/shared/oopStorage.cpp | 2 +- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shared/collectedHeap.cpp b/src/hotspot/share/gc/shared/collectedHeap.cpp index 44a0744c0a3..c81bf46693a 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.cpp +++ b/src/hotspot/share/gc/shared/collectedHeap.cpp @@ -152,6 +152,10 @@ MetaspaceSummary CollectedHeap::create_metaspace_summary() { ms_chunk_free_list_summary, class_chunk_free_list_summary); } +bool CollectedHeap::contains_null(const oop* p) const { + return *p == nullptr; +} + void CollectedHeap::print_heap_before_gc() { LogTarget(Debug, gc, heap) lt; if (lt.is_enabled()) { diff --git a/src/hotspot/share/gc/shared/collectedHeap.hpp b/src/hotspot/share/gc/shared/collectedHeap.hpp index 33aa32bb6d6..b67fdb09dcc 100644 --- a/src/hotspot/share/gc/shared/collectedHeap.hpp +++ b/src/hotspot/share/gc/shared/collectedHeap.hpp @@ -446,6 +446,12 @@ class CollectedHeap : public CHeapObj { MetaspaceSummary create_metaspace_summary(); + // GCs are free to represent the bit representation for null differently in memory, + // which is typically not observable when using the Access API. However, if for + // some reason a context doesn't allow using the Access API, then this function + // explicitly checks if the given memory location contains a null value. + virtual bool contains_null(const oop* p) const; + // Print heap information on the given outputStream. virtual void print_on(outputStream* st) const = 0; // The default behavior is to call print_on() on tty. diff --git a/src/hotspot/share/gc/shared/oopStorage.cpp b/src/hotspot/share/gc/shared/oopStorage.cpp index 87b0293b73e..e91f9f2cd41 100644 --- a/src/hotspot/share/gc/shared/oopStorage.cpp +++ b/src/hotspot/share/gc/shared/oopStorage.cpp @@ -766,7 +766,7 @@ bool OopStorage::reduce_deferred_updates() { static inline void check_release_entry(const oop* entry) { assert(entry != nullptr, "Releasing null"); - assert(*entry == nullptr, "Releasing uncleared entry: " PTR_FORMAT, p2i(entry)); + assert(Universe::heap()->contains_null(entry), "Releasing uncleared entry: " PTR_FORMAT, p2i(entry)); } void OopStorage::release(const oop* ptr) {