Skip to content

Commit 17f2250

Browse files
committedJun 23, 2020
8247879: Rework WeakHandle and OopHandle to dynamically support different OopStorages
Reviewed-by: coleenp, eosterlund
1 parent b7e9449 commit 17f2250

17 files changed

+84
-112
lines changed
 

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
#include "classfile/packageEntry.hpp"
5656
#include "classfile/symbolTable.hpp"
5757
#include "classfile/systemDictionary.hpp"
58+
#include "gc/shared/oopStorageSet.hpp"
5859
#include "logging/log.hpp"
5960
#include "logging/logStream.hpp"
6061
#include "memory/allocation.inline.hpp"
@@ -487,7 +488,7 @@ void ClassLoaderData::add_class(Klass* k, bool publicize /* true */) {
487488
void ClassLoaderData::initialize_holder(Handle loader_or_mirror) {
488489
if (loader_or_mirror() != NULL) {
489490
assert(_holder.is_null(), "never replace holders");
490-
_holder = WeakHandle<vm_weak_data>::create(loader_or_mirror);
491+
_holder = WeakHandle(OopStorageSet::vm_weak(), loader_or_mirror);
491492
}
492493
}
493494

@@ -654,7 +655,7 @@ ClassLoaderData::~ClassLoaderData() {
654655
ClassLoaderDataGraph::dec_instance_classes(cl.instance_class_released());
655656

656657
// Release the WeakHandle
657-
_holder.release();
658+
_holder.release(OopStorageSet::vm_weak());
658659

659660
// Release C heap allocated hashtable for all the packages.
660661
if (_packages != NULL) {

‎src/hotspot/share/classfile/classLoaderData.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,9 @@ class ClassLoaderData : public CHeapObj<mtClass> {
109109

110110
static ClassLoaderData * _the_null_class_loader_data;
111111

112-
WeakHandle<vm_weak_data> _holder; // The oop that determines lifetime of this class loader
113-
OopHandle _class_loader; // The instance of java/lang/ClassLoader associated with
114-
// this ClassLoaderData
112+
WeakHandle _holder; // The oop that determines lifetime of this class loader
113+
OopHandle _class_loader; // The instance of java/lang/ClassLoader associated with
114+
// this ClassLoaderData
115115

116116
ClassLoaderMetaspace * volatile _metaspace; // Meta-space where meta-data defined by the
117117
// classes in the class loader are allocated.

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "classfile/dictionary.hpp"
2828
#include "classfile/protectionDomainCache.hpp"
2929
#include "classfile/systemDictionary.hpp"
30+
#include "gc/shared/oopStorageSet.hpp"
3031
#include "logging/log.hpp"
3132
#include "logging/logStream.hpp"
3233
#include "memory/iterator.hpp"
@@ -406,14 +407,14 @@ oop SymbolPropertyEntry::method_type() const {
406407
}
407408

408409
void SymbolPropertyEntry::set_method_type(oop p) {
409-
_method_type = OopHandle::create(p);
410+
_method_type = OopHandle(OopStorageSet::vm_global(), p);
410411
}
411412

412413
void SymbolPropertyEntry::free_entry() {
413414
// decrement Symbol refcount here because hashtable doesn't.
414415
literal()->decrement_refcount();
415416
// Free OopHandle
416-
_method_type.release();
417+
_method_type.release(OopStorageSet::vm_global());
417418
}
418419

419420
SymbolPropertyTable::SymbolPropertyTable(int table_size)

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "classfile/dictionary.hpp"
2828
#include "classfile/protectionDomainCache.hpp"
2929
#include "classfile/systemDictionary.hpp"
30+
#include "gc/shared/oopStorageSet.hpp"
3031
#include "logging/log.hpp"
3132
#include "logging/logStream.hpp"
3233
#include "memory/iterator.hpp"
@@ -45,7 +46,7 @@ int ProtectionDomainCacheTable::index_for(Handle protection_domain) {
4546
}
4647

4748
ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size)
48-
: Hashtable<WeakHandle<vm_weak_data>, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
49+
: Hashtable<WeakHandle, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry))
4950
{ _dead_entries = false;
5051
_total_oops_removed = 0;
5152
}
@@ -93,7 +94,7 @@ void ProtectionDomainCacheTable::unlink() {
9394
LogStream ls(lt);
9495
ls.print_cr("protection domain unlinked at %d", i);
9596
}
96-
entry->literal().release();
97+
entry->literal().release(OopStorageSet::vm_weak());
9798
*p = entry->next();
9899
free_entry(entry);
99100
}
@@ -180,8 +181,8 @@ ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, uns
180181
protection_domain->print_value_on(&ls);
181182
ls.cr();
182183
}
183-
WeakHandle<vm_weak_data> w = WeakHandle<vm_weak_data>::create(protection_domain);
184+
WeakHandle w(OopStorageSet::vm_weak(), protection_domain);
184185
ProtectionDomainCacheEntry* p = new_entry(hash, w);
185-
Hashtable<WeakHandle<vm_weak_data>, mtClass>::add_entry(index, p);
186+
Hashtable<WeakHandle, mtClass>::add_entry(index, p);
186187
return p;
187188
}

‎src/hotspot/share/classfile/protectionDomainCache.hpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@
3535
// to dictionary.hpp pd_set for more information about how protection domain entries
3636
// are used.
3737
// This table is walked during GC, rather than the class loader data graph dictionaries.
38-
class ProtectionDomainCacheEntry : public HashtableEntry<WeakHandle<vm_weak_data>, mtClass> {
38+
class ProtectionDomainCacheEntry : public HashtableEntry<WeakHandle, mtClass> {
3939
friend class VMStructs;
4040
public:
4141
oop object();
4242
oop object_no_keepalive();
4343

4444
ProtectionDomainCacheEntry* next() {
45-
return (ProtectionDomainCacheEntry*)HashtableEntry<WeakHandle<vm_weak_data>, mtClass>::next();
45+
return (ProtectionDomainCacheEntry*)HashtableEntry<WeakHandle, mtClass>::next();
4646
}
4747

4848
ProtectionDomainCacheEntry** next_addr() {
49-
return (ProtectionDomainCacheEntry**)HashtableEntry<WeakHandle<vm_weak_data>, mtClass>::next_addr();
49+
return (ProtectionDomainCacheEntry**)HashtableEntry<WeakHandle, mtClass>::next_addr();
5050
}
5151

5252
void verify();
@@ -61,21 +61,21 @@ class ProtectionDomainCacheEntry : public HashtableEntry<WeakHandle<vm_weak_data
6161
// we only need to iterate over this set.
6262
// The amount of different protection domains used is typically magnitudes smaller
6363
// than the number of system dictionary entries (loaded classes).
64-
class ProtectionDomainCacheTable : public Hashtable<WeakHandle<vm_weak_data>, mtClass> {
64+
class ProtectionDomainCacheTable : public Hashtable<WeakHandle, mtClass> {
6565
friend class VMStructs;
6666
private:
6767
ProtectionDomainCacheEntry* bucket(int i) const {
68-
return (ProtectionDomainCacheEntry*) Hashtable<WeakHandle<vm_weak_data>, mtClass>::bucket(i);
68+
return (ProtectionDomainCacheEntry*) Hashtable<WeakHandle, mtClass>::bucket(i);
6969
}
7070

7171
// The following method is not MT-safe and must be done under lock.
7272
ProtectionDomainCacheEntry** bucket_addr(int i) {
73-
return (ProtectionDomainCacheEntry**) Hashtable<WeakHandle<vm_weak_data>, mtClass>::bucket_addr(i);
73+
return (ProtectionDomainCacheEntry**) Hashtable<WeakHandle, mtClass>::bucket_addr(i);
7474
}
7575

76-
ProtectionDomainCacheEntry* new_entry(unsigned int hash, WeakHandle<vm_weak_data> protection_domain) {
76+
ProtectionDomainCacheEntry* new_entry(unsigned int hash, WeakHandle protection_domain) {
7777
ProtectionDomainCacheEntry* entry = (ProtectionDomainCacheEntry*)
78-
Hashtable<WeakHandle<vm_weak_data>, mtClass>::new_entry(hash, protection_domain);
78+
Hashtable<WeakHandle, mtClass>::new_entry(hash, protection_domain);
7979
return entry;
8080
}
8181

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

+13-13
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ uintx hash_string(const jchar* s, int len, bool useAlt) {
103103
class StringTableConfig : public StackObj {
104104
private:
105105
public:
106-
typedef WeakHandle<vm_string_table_data> Value;
106+
typedef WeakHandle Value;
107107

108108
static uintx get_hash(Value const& value, bool* is_dead) {
109109
EXCEPTION_MARK;
@@ -129,7 +129,7 @@ class StringTableConfig : public StackObj {
129129
return AllocateHeap(size, mtSymbol);
130130
}
131131
static void free_node(void* memory, Value const& value) {
132-
value.release();
132+
value.release(OopStorageSet::string_table_weak());
133133
FreeHeap(memory);
134134
StringTable::item_removed();
135135
}
@@ -150,7 +150,7 @@ class StringTableLookupJchar : StackObj {
150150
uintx get_hash() const {
151151
return _hash;
152152
}
153-
bool equals(WeakHandle<vm_string_table_data>* value, bool* is_dead) {
153+
bool equals(WeakHandle* value, bool* is_dead) {
154154
oop val_oop = value->peek();
155155
if (val_oop == NULL) {
156156
// dead oop, mark this hash dead for cleaning
@@ -182,7 +182,7 @@ class StringTableLookupOop : public StackObj {
182182
return _hash;
183183
}
184184

185-
bool equals(WeakHandle<vm_string_table_data>* value, bool* is_dead) {
185+
bool equals(WeakHandle* value, bool* is_dead) {
186186
oop val_oop = value->peek();
187187
if (val_oop == NULL) {
188188
// dead oop, mark this hash dead for cleaning
@@ -272,7 +272,7 @@ class StringTableGet : public StackObj {
272272
Handle _return;
273273
public:
274274
StringTableGet(Thread* thread) : _thread(thread) {}
275-
void operator()(WeakHandle<vm_string_table_data>* val) {
275+
void operator()(WeakHandle* val) {
276276
oop result = val->resolve();
277277
assert(result != NULL, "Result should be reachable");
278278
_return = Handle(_thread, result);
@@ -368,7 +368,7 @@ oop StringTable::do_intern(Handle string_or_null_h, const jchar* name,
368368
bool rehash_warning;
369369
do {
370370
// Callers have already looked up the String using the jchar* name, so just go to add.
371-
WeakHandle<vm_string_table_data> wh = WeakHandle<vm_string_table_data>::create(string_h);
371+
WeakHandle wh(OopStorageSet::string_table_weak(), string_h);
372372
// The hash table takes ownership of the WeakHandle, even if it's not inserted.
373373
if (_local_table->insert(THREAD, lookup, wh, &rehash_warning)) {
374374
update_needs_rehash(rehash_warning);
@@ -406,7 +406,7 @@ void StringTable::grow(JavaThread* jt) {
406406
}
407407

408408
struct StringTableDoDelete : StackObj {
409-
void operator()(WeakHandle<vm_string_table_data>* val) {
409+
void operator()(WeakHandle* val) {
410410
/* do nothing */
411411
}
412412
};
@@ -415,7 +415,7 @@ struct StringTableDeleteCheck : StackObj {
415415
long _count;
416416
long _item;
417417
StringTableDeleteCheck() : _count(0), _item(0) {}
418-
bool operator()(WeakHandle<vm_string_table_data>* val) {
418+
bool operator()(WeakHandle* val) {
419419
++_item;
420420
oop tmp = val->peek();
421421
if (tmp == NULL) {
@@ -551,7 +551,7 @@ static int literal_size(oop obj) {
551551
}
552552

553553
struct SizeFunc : StackObj {
554-
size_t operator()(WeakHandle<vm_string_table_data>* val) {
554+
size_t operator()(WeakHandle* val) {
555555
oop s = val->peek();
556556
if (s == NULL) {
557557
// Dead
@@ -577,7 +577,7 @@ void StringTable::print_table_statistics(outputStream* st,
577577
// Verification
578578
class VerifyStrings : StackObj {
579579
public:
580-
bool operator()(WeakHandle<vm_string_table_data>* val) {
580+
bool operator()(WeakHandle* val) {
581581
oop s = val->peek();
582582
if (s != NULL) {
583583
assert(java_lang_String::length(s) >= 0, "Length on string must work.");
@@ -601,7 +601,7 @@ class VerifyCompStrings : StackObj {
601601
public:
602602
size_t _errors;
603603
VerifyCompStrings(GrowableArray<oop>* oops) : _oops(oops), _errors(0) {}
604-
bool operator()(WeakHandle<vm_string_table_data>* val) {
604+
bool operator()(WeakHandle* val) {
605605
oop s = val->resolve();
606606
if (s == NULL) {
607607
return true;
@@ -639,7 +639,7 @@ class PrintString : StackObj {
639639
outputStream* _st;
640640
public:
641641
PrintString(Thread* thr, outputStream* st) : _thr(thr), _st(st) {}
642-
bool operator()(WeakHandle<vm_string_table_data>* val) {
642+
bool operator()(WeakHandle* val) {
643643
oop s = val->peek();
644644
if (s == NULL) {
645645
return true;
@@ -744,7 +744,7 @@ oop StringTable::create_archived_string(oop s, Thread* THREAD) {
744744
struct CopyToArchive : StackObj {
745745
CompactHashtableWriter* _writer;
746746
CopyToArchive(CompactHashtableWriter* writer) : _writer(writer) {}
747-
bool operator()(WeakHandle<vm_string_table_data>* val) {
747+
bool operator()(WeakHandle* val) {
748748
oop s = val->peek();
749749
if (s == NULL) {
750750
return true;

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "code/codeCache.hpp"
4747
#include "compiler/compileBroker.hpp"
4848
#include "gc/shared/gcTraceTime.inline.hpp"
49+
#include "gc/shared/oopStorageSet.hpp"
4950
#include "interpreter/bytecodeStream.hpp"
5051
#include "interpreter/interpreter.hpp"
5152
#include "jfr/jfrEvents.hpp"
@@ -175,15 +176,15 @@ void SystemDictionary::compute_java_loaders(TRAPS) {
175176
vmSymbols::void_classloader_signature(),
176177
CHECK);
177178

178-
_java_system_loader = OopHandle::create((oop)result.get_jobject());
179+
_java_system_loader = OopHandle(OopStorageSet::vm_global(), (oop)result.get_jobject());
179180

180181
JavaCalls::call_static(&result,
181182
class_loader_klass,
182183
vmSymbols::getPlatformClassLoader_name(),
183184
vmSymbols::void_classloader_signature(),
184185
CHECK);
185186

186-
_java_platform_loader = OopHandle::create((oop)result.get_jobject());
187+
_java_platform_loader = OopHandle(OopStorageSet::vm_global(), (oop)result.get_jobject());
187188
}
188189

189190
ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, bool create_mirror_cld) {
@@ -2041,7 +2042,7 @@ void SystemDictionary::initialize(TRAPS) {
20412042

20422043
// Allocate private object used as system class loader lock
20432044
oop lock_obj = oopFactory::new_intArray(0, CHECK);
2044-
_system_loader_lock_obj = OopHandle::create(lock_obj);
2045+
_system_loader_lock_obj = OopHandle(OopStorageSet::vm_global(), lock_obj);
20452046

20462047
// Initialize basic classes
20472048
resolve_well_known_classes(CHECK);

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "classfile/systemDictionaryShared.hpp"
3737
#include "classfile/verificationType.hpp"
3838
#include "classfile/vmSymbols.hpp"
39+
#include "gc/shared/oopStorageSet.hpp"
3940
#include "jfr/jfrEvents.hpp"
4041
#include "logging/log.hpp"
4142
#include "memory/allocation.hpp"
@@ -1118,23 +1119,23 @@ void SystemDictionaryShared::allocate_shared_protection_domain_array(int size, T
11181119
if (_shared_protection_domains.resolve() == NULL) {
11191120
oop spd = oopFactory::new_objArray(
11201121
SystemDictionary::ProtectionDomain_klass(), size, CHECK);
1121-
_shared_protection_domains = OopHandle::create(spd);
1122+
_shared_protection_domains = OopHandle(OopStorageSet::vm_global(), spd);
11221123
}
11231124
}
11241125

11251126
void SystemDictionaryShared::allocate_shared_jar_url_array(int size, TRAPS) {
11261127
if (_shared_jar_urls.resolve() == NULL) {
11271128
oop sju = oopFactory::new_objArray(
11281129
SystemDictionary::URL_klass(), size, CHECK);
1129-
_shared_jar_urls = OopHandle::create(sju);
1130+
_shared_jar_urls = OopHandle(OopStorageSet::vm_global(), sju);
11301131
}
11311132
}
11321133

11331134
void SystemDictionaryShared::allocate_shared_jar_manifest_array(int size, TRAPS) {
11341135
if (_shared_jar_manifests.resolve() == NULL) {
11351136
oop sjm = oopFactory::new_objArray(
11361137
SystemDictionary::Jar_Manifest_klass(), size, CHECK);
1137-
_shared_jar_manifests = OopHandle::create(sjm);
1138+
_shared_jar_manifests = OopHandle(OopStorageSet::vm_global(), sjm);
11381139
}
11391140
}
11401141

‎src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "classfile/stringTable.hpp"
3030
#include "classfile/systemDictionary.hpp"
3131
#include "gc/shared/oopStorageParState.inline.hpp"
32+
#include "gc/shared/oopStorageSet.hpp"
3233
#include "gc/shenandoah/shenandoahClosures.inline.hpp"
3334
#include "gc/shenandoah/shenandoahConcurrentRoots.hpp"
3435
#include "gc/shenandoah/shenandoahHeap.inline.hpp"

‎src/hotspot/share/gc/z/zRootsIterator.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "compiler/oopMap.hpp"
2929
#include "gc/shared/barrierSet.hpp"
3030
#include "gc/shared/barrierSetNMethod.hpp"
31+
#include "gc/shared/oopStorageSet.hpp"
3132
#include "gc/shared/oopStorageParState.inline.hpp"
3233
#include "gc/shared/oopStorageSet.hpp"
3334
#include "gc/shared/suspendibleThreadSet.hpp"

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
#ifndef SHARE_OOPS_OOPHANDLE_HPP
2626
#define SHARE_OOPS_OOPHANDLE_HPP
2727

28-
#include "oops/oop.hpp"
28+
#include "oops/oopsHierarchy.hpp"
29+
30+
class OopStorage;
2931

3032
// Simple class for encapsulating oop pointers stored in metadata.
3133
// These are different from Handle. The Handle class stores pointers
@@ -43,13 +45,12 @@ class OopHandle {
4345
public:
4446
OopHandle() : _obj(NULL) {}
4547
explicit OopHandle(oop* w) : _obj(w) {}
46-
47-
inline static OopHandle create(oop obj);
48+
OopHandle(OopStorage* storage, oop obj);
4849

4950
inline oop resolve() const;
5051
inline oop peek() const;
5152

52-
inline void release();
53+
inline void release(OopStorage* storage);
5354

5455
// Used only for removing handle.
5556
oop* ptr_raw() const { return _obj; }

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "oops/access.inline.hpp"
2929
#include "oops/oopHandle.hpp"
3030
#include "gc/shared/oopStorage.inline.hpp"
31-
#include "gc/shared/oopStorageSet.hpp"
3231

3332
inline oop OopHandle::resolve() const {
3433
return (_obj == NULL) ? (oop)NULL : NativeAccess<>::oop_load(_obj);
@@ -38,21 +37,19 @@ inline oop OopHandle::peek() const {
3837
return (_obj == NULL) ? (oop)NULL : NativeAccess<AS_NO_KEEPALIVE>::oop_load(_obj);
3938
}
4039

41-
// Allocate a global handle and return
42-
inline OopHandle OopHandle::create(oop obj) {
43-
oop* handle = OopStorageSet::vm_global()->allocate();
44-
if (handle == NULL) {
40+
inline OopHandle::OopHandle(OopStorage* storage, oop obj) :
41+
_obj(storage->allocate()) {
42+
if (_obj == NULL) {
4543
vm_exit_out_of_memory(sizeof(oop), OOM_MALLOC_ERROR,
4644
"Cannot create oop handle");
4745
}
48-
NativeAccess<>::oop_store(handle, obj);
49-
return OopHandle(handle);
46+
NativeAccess<>::oop_store(_obj, obj);
5047
}
5148

52-
inline void OopHandle::release() {
49+
inline void OopHandle::release(OopStorage* storage) {
5350
// Clear the OopHandle first
5451
NativeAccess<>::oop_store(_obj, (oop)NULL);
55-
OopStorageSet::vm_global()->release(_obj);
52+
storage->release(_obj);
5653
}
5754

5855
#endif // SHARE_OOPS_OOPHANDLE_INLINE_HPP

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

+11-32
Original file line numberDiff line numberDiff line change
@@ -31,52 +31,31 @@
3131
#include "utilities/debug.hpp"
3232
#include "utilities/ostream.hpp"
3333

34-
template <> OopStorage* WeakHandle<vm_weak_data>::get_storage() {
35-
return OopStorageSet::vm_weak();
36-
}
37-
38-
template <> OopStorage* WeakHandle<vm_string_table_data>::get_storage() {
39-
return OopStorageSet::string_table_weak();
40-
}
41-
42-
template <> OopStorage* WeakHandle<vm_resolved_method_table_data>::get_storage() {
43-
return OopStorageSet::resolved_method_table_weak();
44-
}
45-
46-
template <WeakHandleType T>
47-
WeakHandle<T> WeakHandle<T>::create(Handle obj) {
34+
WeakHandle::WeakHandle(OopStorage* storage, Handle obj) :
35+
_obj(storage->allocate()) {
4836
assert(obj() != NULL, "no need to create weak null oop");
49-
oop* oop_addr = get_storage()->allocate();
50-
if (oop_addr == NULL) {
37+
38+
if (_obj == NULL) {
5139
vm_exit_out_of_memory(sizeof(oop*), OOM_MALLOC_ERROR,
5240
"Unable to create new weak oop handle in OopStorage %s",
53-
get_storage()->name());
41+
storage->name());
5442
}
55-
// Create WeakHandle with address returned and store oop into it.
56-
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(oop_addr, obj());
57-
return WeakHandle(oop_addr);
43+
44+
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, obj());
5845
}
5946

60-
template <WeakHandleType T>
61-
void WeakHandle<T>::release() const {
47+
void WeakHandle::release(OopStorage* storage) const {
6248
// Only release if the pointer to the object has been created.
6349
if (_obj != NULL) {
6450
// Clear the WeakHandle. For race in creating ClassLoaderData, we can release this
6551
// WeakHandle before it is cleared by GC.
6652
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, (oop)NULL);
67-
get_storage()->release(_obj);
53+
storage->release(_obj);
6854
}
6955
}
7056

71-
template <WeakHandleType T>
72-
void WeakHandle<T>::print() const { print_on(tty); }
57+
void WeakHandle::print() const { print_on(tty); }
7358

74-
template <WeakHandleType T>
75-
void WeakHandle<T>::print_on(outputStream* st) const {
59+
void WeakHandle::print_on(outputStream* st) const {
7660
st->print("WeakHandle: " PTR_FORMAT, p2i(peek()));
7761
}
78-
79-
// Provide instantiation.
80-
template class WeakHandle<vm_weak_data>;
81-
template class WeakHandle<vm_string_table_data>;
82-
template class WeakHandle<vm_resolved_method_table_data>;

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

+2-10
Original file line numberDiff line numberDiff line change
@@ -39,27 +39,19 @@ class OopStorage;
3939
// This is the vm version of jweak but has different GC lifetimes and policies,
4040
// depending on the type.
4141

42-
enum WeakHandleType {
43-
vm_weak_data,
44-
vm_string_table_data,
45-
vm_resolved_method_table_data
46-
};
47-
48-
template <WeakHandleType T>
4942
class WeakHandle {
5043
public:
5144
private:
5245
oop* _obj;
5346

5447
WeakHandle(oop* w) : _obj(w) {}
55-
static OopStorage* get_storage();
5648
public:
5749
WeakHandle() : _obj(NULL) {} // needed for init
50+
WeakHandle(OopStorage* storage, Handle obj);
5851

59-
static WeakHandle create(Handle obj);
6052
inline oop resolve() const;
6153
inline oop peek() const;
62-
void release() const;
54+
void release(OopStorage* storage) const;
6355
bool is_null() const { return _obj == NULL; }
6456

6557
void replace(oop with_obj);

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

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,17 @@
2828
#include "oops/weakHandle.hpp"
2929
#include "oops/access.inline.hpp"
3030

31-
template <WeakHandleType T>
32-
oop WeakHandle<T>::resolve() const {
31+
inline oop WeakHandle::resolve() const {
3332
assert(!is_null(), "Must be created");
3433
return NativeAccess<ON_PHANTOM_OOP_REF>::oop_load(_obj);
3534
}
3635

37-
template <WeakHandleType T>
38-
oop WeakHandle<T>::peek() const {
36+
inline oop WeakHandle::peek() const {
3937
assert(!is_null(), "Must be created");
4038
return NativeAccess<ON_PHANTOM_OOP_REF | AS_NO_KEEPALIVE>::oop_load(_obj);
4139
}
4240

43-
template <WeakHandleType T>
44-
void WeakHandle<T>::replace(oop with_obj) {
41+
inline void WeakHandle::replace(oop with_obj) {
4542
NativeAccess<ON_PHANTOM_OOP_REF>::oop_store(_obj, with_obj);
4643
}
4744

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef ConcurrentHashTable<ResolvedMethodTableConfig,
6464
class ResolvedMethodTableConfig : public AllStatic {
6565
private:
6666
public:
67-
typedef WeakHandle<vm_resolved_method_table_data> Value;
67+
typedef WeakHandle Value;
6868

6969
static uintx get_hash(Value const& value, bool* is_dead) {
7070
oop val_oop = value.peek();
@@ -83,7 +83,7 @@ class ResolvedMethodTableConfig : public AllStatic {
8383
return AllocateHeap(size, mtClass);
8484
}
8585
static void free_node(void* memory, Value const& value) {
86-
value.release();
86+
value.release(OopStorageSet::resolved_method_table_weak());
8787
FreeHeap(memory);
8888
ResolvedMethodTable::item_removed();
8989
}
@@ -121,7 +121,7 @@ class ResolvedMethodTableLookup : StackObj {
121121
uintx get_hash() const {
122122
return _hash;
123123
}
124-
bool equals(WeakHandle<vm_resolved_method_table_data>* value, bool* is_dead) {
124+
bool equals(WeakHandle* value, bool* is_dead) {
125125
oop val_oop = value->peek();
126126
if (val_oop == NULL) {
127127
// dead oop, mark this hash dead for cleaning
@@ -145,7 +145,7 @@ class ResolvedMethodGet : public StackObj {
145145
Handle _return;
146146
public:
147147
ResolvedMethodGet(Thread* thread, const Method* method) : _thread(thread), _method(method) {}
148-
void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
148+
void operator()(WeakHandle* val) {
149149
oop result = val->resolve();
150150
assert(result != NULL, "Result should be reachable");
151151
_return = Handle(_thread, result);
@@ -193,7 +193,7 @@ oop ResolvedMethodTable::add_method(const Method* method, Handle rmethod_name) {
193193
if (_local_table->get(thread, lookup, rmg)) {
194194
return rmg.get_res_oop();
195195
}
196-
WeakHandle<vm_resolved_method_table_data> wh = WeakHandle<vm_resolved_method_table_data>::create(rmethod_name);
196+
WeakHandle wh(OopStorageSet::resolved_method_table_weak(), rmethod_name);
197197
// The hash table takes ownership of the WeakHandle, even if it's not inserted.
198198
if (_local_table->insert(thread, lookup, wh)) {
199199
log_insert(method);
@@ -282,7 +282,7 @@ void ResolvedMethodTable::grow(JavaThread* jt) {
282282
}
283283

284284
struct ResolvedMethodTableDoDelete : StackObj {
285-
void operator()(WeakHandle<vm_resolved_method_table_data>* val) {
285+
void operator()(WeakHandle* val) {
286286
/* do nothing */
287287
}
288288
};
@@ -291,7 +291,7 @@ struct ResolvedMethodTableDeleteCheck : StackObj {
291291
long _count;
292292
long _item;
293293
ResolvedMethodTableDeleteCheck() : _count(0), _item(0) {}
294-
bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
294+
bool operator()(WeakHandle* val) {
295295
++_item;
296296
oop tmp = val->peek();
297297
if (tmp == NULL) {
@@ -345,7 +345,7 @@ class AdjustMethodEntries : public StackObj {
345345
bool* _trace_name_printed;
346346
public:
347347
AdjustMethodEntries(bool* trace_name_printed) : _trace_name_printed(trace_name_printed) {};
348-
bool operator()(WeakHandle<vm_resolved_method_table_data>* entry) {
348+
bool operator()(WeakHandle* entry) {
349349
oop mem_name = entry->peek();
350350
if (mem_name == NULL) {
351351
// Removed
@@ -387,7 +387,7 @@ void ResolvedMethodTable::adjust_method_entries(bool * trace_name_printed) {
387387
// Verification
388388
class VerifyResolvedMethod : StackObj {
389389
public:
390-
bool operator()(WeakHandle<vm_resolved_method_table_data>* val) {
390+
bool operator()(WeakHandle* val) {
391391
oop obj = val->peek();
392392
if (obj != NULL) {
393393
Method* method = (Method*)java_lang_invoke_ResolvedMethodName::vmtarget(obj);

‎src/hotspot/share/utilities/hashtable.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static int literal_size(oop obj) {
128128
}
129129
}
130130

131-
static int literal_size(WeakHandle<vm_weak_data> v) {
131+
static int literal_size(WeakHandle v) {
132132
return literal_size(v.peek());
133133
}
134134

@@ -223,7 +223,7 @@ template <class T> void print_literal(T l) {
223223
l->print();
224224
}
225225

226-
static void print_literal(WeakHandle<vm_weak_data> l) {
226+
static void print_literal(WeakHandle l) {
227227
l.print();
228228
}
229229

@@ -287,14 +287,13 @@ template class Hashtable<ConstantPool*, mtClass>;
287287
template class Hashtable<Symbol*, mtSymbol>;
288288
template class Hashtable<Klass*, mtClass>;
289289
template class Hashtable<InstanceKlass*, mtClass>;
290-
template class Hashtable<WeakHandle<vm_weak_data>, mtClass>;
290+
template class Hashtable<WeakHandle, mtClass>;
291291
template class Hashtable<Symbol*, mtModule>;
292292
template class Hashtable<oop, mtSymbol>;
293293
template class Hashtable<Symbol*, mtClass>;
294294
template class HashtableEntry<Symbol*, mtSymbol>;
295295
template class HashtableEntry<Symbol*, mtClass>;
296296
template class HashtableEntry<oop, mtSymbol>;
297-
template class HashtableEntry<WeakHandle<vm_weak_data>, mtClass>;
298297
template class HashtableBucket<mtClass>;
299298
template class BasicHashtableEntry<mtSymbol>;
300299
template class BasicHashtableEntry<mtCode>;

0 commit comments

Comments
 (0)
Please sign in to comment.