8309599: WeakHandle and OopHandle release should clear obj pointer

Reviewed-by: dholmes, kbarrett
This commit is contained in:
Coleen Phillimore 2023-09-28 12:00:20 +00:00
parent 1230aed61d
commit 0c55887bfb
8 changed files with 12 additions and 11 deletions

@ -154,7 +154,7 @@ class StringTableConfig : public StackObj {
StringTable::item_added();
return AllocateHeap(size, mtSymbol);
}
static void free_node(void* context, void* memory, Value const& value) {
static void free_node(void* context, void* memory, Value& value) {
value.release(StringTable::_oop_storage);
FreeHeap(memory);
StringTable::item_removed();

@ -52,6 +52,7 @@ inline void OopHandle::release(OopStorage* storage) {
// Clear the OopHandle first
NativeAccess<>::oop_store(_obj, nullptr);
storage->release(_obj);
_obj = nullptr;
}
}

@ -46,13 +46,14 @@ WeakHandle::WeakHandle(OopStorage* storage, oop obj) :
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, obj);
}
void WeakHandle::release(OopStorage* storage) const {
void WeakHandle::release(OopStorage* storage) {
// Only release if the pointer to the object has been created.
if (_obj != nullptr) {
// Clear the WeakHandle. For race in creating ClassLoaderData, we can release this
// WeakHandle before it is cleared by GC.
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, nullptr);
storage->release(_obj);
_obj = nullptr;
}
}

@ -52,9 +52,8 @@ class WeakHandle {
inline oop resolve() const;
inline oop peek() const;
void release(OopStorage* storage) const;
void release(OopStorage* storage);
bool is_null() const { return _obj == nullptr; }
void set_null() { _obj = nullptr; }
void replace(oop with_obj);

@ -50,7 +50,7 @@ JvmtiTagMapKey::JvmtiTagMapKey(const JvmtiTagMapKey& src) {
_obj = nullptr;
}
void JvmtiTagMapKey::release_weak_handle() const {
void JvmtiTagMapKey::release_weak_handle() {
_wh.release(JvmtiExport::weak_tag_storage());
}
@ -71,7 +71,7 @@ JvmtiTagMapTable::JvmtiTagMapTable() : _table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE
void JvmtiTagMapTable::clear() {
struct RemoveAll {
bool do_entry(const JvmtiTagMapKey& entry, const jlong& tag) {
bool do_entry(JvmtiTagMapKey& entry, const jlong& tag) {
entry.release_weak_handle();
return true;
}
@ -125,7 +125,7 @@ void JvmtiTagMapTable::add(oop obj, jlong tag) {
void JvmtiTagMapTable::remove(oop obj) {
JvmtiTagMapKey jtme(obj);
auto clean = [] (const JvmtiTagMapKey& entry, jlong tag) {
auto clean = [] (JvmtiTagMapKey& entry, jlong tag) {
entry.release_weak_handle();
};
_table.remove(jtme, clean);
@ -139,7 +139,7 @@ void JvmtiTagMapTable::remove_dead_entries(GrowableArray<jlong>* objects) {
struct IsDead {
GrowableArray<jlong>* _objects;
IsDead(GrowableArray<jlong>* objects) : _objects(objects) {}
bool do_entry(const JvmtiTagMapKey& entry, jlong tag) {
bool do_entry(JvmtiTagMapKey& entry, jlong tag) {
if (entry.object_no_keepalive() == nullptr) {
if (_objects != nullptr) {
_objects->append(tag);

@ -50,7 +50,7 @@ class JvmtiTagMapKey : public CHeapObj<mtServiceability> {
oop object() const;
oop object_no_keepalive() const;
void release_weak_handle() const;
void release_weak_handle();
static unsigned get_hash(const JvmtiTagMapKey& entry) {
assert(entry._obj != nullptr, "must lookup obj to hash");

@ -85,7 +85,7 @@ class ResolvedMethodTableConfig : public AllStatic {
ResolvedMethodTable::item_added();
return AllocateHeap(size, mtClass);
}
static void free_node(void* context, void* memory, Value const& value) {
static void free_node(void* context, void* memory, Value& value) {
value.release(ResolvedMethodTable::_oop_storage);
FreeHeap(memory);
ResolvedMethodTable::item_removed();

@ -364,7 +364,7 @@ private:
// Deflation support
bool deflate_monitor();
void install_displaced_markword_in_object(const oop obj);
void release_object() { _object.release(_oop_storage); _object.set_null(); }
void release_object() { _object.release(_oop_storage); }
};
#endif // SHARE_RUNTIME_OBJECTMONITOR_HPP