Skip to content

Commit 0c55887

Browse files
committedSep 28, 2023
8309599: WeakHandle and OopHandle release should clear obj pointer
Reviewed-by: dholmes, kbarrett
1 parent 1230aed commit 0c55887

File tree

8 files changed

+12
-11
lines changed

8 files changed

+12
-11
lines changed
 

‎src/hotspot/share/classfile/stringTable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class StringTableConfig : public StackObj {
154154
StringTable::item_added();
155155
return AllocateHeap(size, mtSymbol);
156156
}
157-
static void free_node(void* context, void* memory, Value const& value) {
157+
static void free_node(void* context, void* memory, Value& value) {
158158
value.release(StringTable::_oop_storage);
159159
FreeHeap(memory);
160160
StringTable::item_removed();

‎src/hotspot/share/oops/oopHandle.inline.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ inline void OopHandle::release(OopStorage* storage) {
5252
// Clear the OopHandle first
5353
NativeAccess<>::oop_store(_obj, nullptr);
5454
storage->release(_obj);
55+
_obj = nullptr;
5556
}
5657
}
5758

‎src/hotspot/share/oops/weakHandle.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,14 @@ WeakHandle::WeakHandle(OopStorage* storage, oop obj) :
4646
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, obj);
4747
}
4848

49-
void WeakHandle::release(OopStorage* storage) const {
49+
void WeakHandle::release(OopStorage* storage) {
5050
// Only release if the pointer to the object has been created.
5151
if (_obj != nullptr) {
5252
// Clear the WeakHandle. For race in creating ClassLoaderData, we can release this
5353
// WeakHandle before it is cleared by GC.
5454
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, nullptr);
5555
storage->release(_obj);
56+
_obj = nullptr;
5657
}
5758
}
5859

‎src/hotspot/share/oops/weakHandle.hpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ class WeakHandle {
5252

5353
inline oop resolve() const;
5454
inline oop peek() const;
55-
void release(OopStorage* storage) const;
55+
void release(OopStorage* storage);
5656
bool is_null() const { return _obj == nullptr; }
57-
void set_null() { _obj = nullptr; }
5857

5958
void replace(oop with_obj);
6059

‎src/hotspot/share/prims/jvmtiTagMapTable.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ JvmtiTagMapKey::JvmtiTagMapKey(const JvmtiTagMapKey& src) {
5050
_obj = nullptr;
5151
}
5252

53-
void JvmtiTagMapKey::release_weak_handle() const {
53+
void JvmtiTagMapKey::release_weak_handle() {
5454
_wh.release(JvmtiExport::weak_tag_storage());
5555
}
5656

@@ -71,7 +71,7 @@ JvmtiTagMapTable::JvmtiTagMapTable() : _table(INITIAL_TABLE_SIZE, MAX_TABLE_SIZE
7171

7272
void JvmtiTagMapTable::clear() {
7373
struct RemoveAll {
74-
bool do_entry(const JvmtiTagMapKey& entry, const jlong& tag) {
74+
bool do_entry(JvmtiTagMapKey& entry, const jlong& tag) {
7575
entry.release_weak_handle();
7676
return true;
7777
}
@@ -125,7 +125,7 @@ void JvmtiTagMapTable::add(oop obj, jlong tag) {
125125

126126
void JvmtiTagMapTable::remove(oop obj) {
127127
JvmtiTagMapKey jtme(obj);
128-
auto clean = [] (const JvmtiTagMapKey& entry, jlong tag) {
128+
auto clean = [] (JvmtiTagMapKey& entry, jlong tag) {
129129
entry.release_weak_handle();
130130
};
131131
_table.remove(jtme, clean);
@@ -139,7 +139,7 @@ void JvmtiTagMapTable::remove_dead_entries(GrowableArray<jlong>* objects) {
139139
struct IsDead {
140140
GrowableArray<jlong>* _objects;
141141
IsDead(GrowableArray<jlong>* objects) : _objects(objects) {}
142-
bool do_entry(const JvmtiTagMapKey& entry, jlong tag) {
142+
bool do_entry(JvmtiTagMapKey& entry, jlong tag) {
143143
if (entry.object_no_keepalive() == nullptr) {
144144
if (_objects != nullptr) {
145145
_objects->append(tag);

‎src/hotspot/share/prims/jvmtiTagMapTable.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class JvmtiTagMapKey : public CHeapObj<mtServiceability> {
5050

5151
oop object() const;
5252
oop object_no_keepalive() const;
53-
void release_weak_handle() const;
53+
void release_weak_handle();
5454

5555
static unsigned get_hash(const JvmtiTagMapKey& entry) {
5656
assert(entry._obj != nullptr, "must lookup obj to hash");

‎src/hotspot/share/prims/resolvedMethodTable.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class ResolvedMethodTableConfig : public AllStatic {
8585
ResolvedMethodTable::item_added();
8686
return AllocateHeap(size, mtClass);
8787
}
88-
static void free_node(void* context, void* memory, Value const& value) {
88+
static void free_node(void* context, void* memory, Value& value) {
8989
value.release(ResolvedMethodTable::_oop_storage);
9090
FreeHeap(memory);
9191
ResolvedMethodTable::item_removed();

‎src/hotspot/share/runtime/objectMonitor.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ class ObjectMonitor : public CHeapObj<mtObjectMonitor> {
364364
// Deflation support
365365
bool deflate_monitor();
366366
void install_displaced_markword_in_object(const oop obj);
367-
void release_object() { _object.release(_oop_storage); _object.set_null(); }
367+
void release_object() { _object.release(_oop_storage); }
368368
};
369369

370370
#endif // SHARE_RUNTIME_OBJECTMONITOR_HPP

0 commit comments

Comments
 (0)
Please sign in to comment.