1
1
/*
2
- * Copyright (c) 2005, 2021 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2005, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
33
33
#include " runtime/mutexLocker.hpp"
34
34
#include " utilities/resourceHash.hpp"
35
35
36
- ResourceHashtable<uintptr_t , ResolutionErrorEntry*, 107 , AnyObj::C_HEAP, mtClass> _resolution_error_table;
36
+ class ResolutionErrorKey {
37
+ ConstantPool* _cpool;
38
+ int _index;
39
+
40
+ public:
41
+ ResolutionErrorKey (ConstantPool* cpool, int index) : _cpool(cpool), _index(index) {
42
+ assert (_index > 0 , " should be already encoded or otherwise greater than zero" );
43
+ }
44
+
45
+ ConstantPool* cpool () const { return _cpool; }
46
+
47
+ static unsigned hash (const ResolutionErrorKey& key) {
48
+ Symbol* name = key._cpool ->pool_holder ()->name ();
49
+ return (unsigned int )(name->identity_hash () ^ key._index );
50
+ }
51
+
52
+ static bool equals (const ResolutionErrorKey& l, const ResolutionErrorKey& r) {
53
+ return (l._cpool == r._cpool ) && (l._index == r._index );
54
+ }
55
+ };
56
+
57
+ ResourceHashtable<ResolutionErrorKey, ResolutionErrorEntry*, 107 , AnyObj::C_HEAP, mtClass,
58
+ ResolutionErrorKey::hash,
59
+ ResolutionErrorKey::equals> _resolution_error_table;
37
60
38
61
// create new error entry
39
62
void ResolutionErrorTable::add_entry (const constantPoolHandle& pool, int cp_index,
@@ -43,8 +66,9 @@ void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_inde
43
66
assert_locked_or_safepoint (SystemDictionary_lock);
44
67
assert (!pool.is_null () && error != NULL , " adding NULL obj" );
45
68
46
- ResolutionErrorEntry* entry = new ResolutionErrorEntry (pool (), cp_index, error, message, cause, cause_msg);
47
- _resolution_error_table.put (convert_key (pool, cp_index), entry);
69
+ ResolutionErrorKey key (pool (), cp_index);
70
+ ResolutionErrorEntry *entry = new ResolutionErrorEntry (error, message, cause, cause_msg);
71
+ _resolution_error_table.put (key, entry);
48
72
}
49
73
50
74
// create new nest host error entry
@@ -54,78 +78,54 @@ void ResolutionErrorTable::add_entry(const constantPoolHandle& pool, int cp_inde
54
78
assert_locked_or_safepoint (SystemDictionary_lock);
55
79
assert (!pool.is_null () && message != NULL , " adding NULL obj" );
56
80
57
- ResolutionErrorEntry* entry = new ResolutionErrorEntry (pool (), cp_index, message);
58
- _resolution_error_table.put (convert_key (pool, cp_index), entry);
81
+ ResolutionErrorKey key (pool (), cp_index);
82
+ ResolutionErrorEntry *entry = new ResolutionErrorEntry (message);
83
+ _resolution_error_table.put (key, entry);
59
84
}
60
85
61
86
// find entry in the table
62
87
ResolutionErrorEntry* ResolutionErrorTable::find_entry (const constantPoolHandle& pool, int cp_index) {
63
88
assert_locked_or_safepoint (SystemDictionary_lock);
64
- ResolutionErrorEntry** entry = _resolution_error_table.get (convert_key (pool, cp_index));
65
- if (entry != nullptr ) {
66
- return *entry;
67
- } else {
68
- return nullptr ;
69
- }
70
-
89
+ ResolutionErrorKey key (pool (), cp_index);
90
+ ResolutionErrorEntry** entry = _resolution_error_table.get (key);
91
+ return entry == nullptr ? nullptr : *entry;
71
92
}
72
93
73
- ResolutionErrorEntry::ResolutionErrorEntry (ConstantPool* pool, int cp_index, Symbol* error, Symbol* message,
94
+ ResolutionErrorEntry::ResolutionErrorEntry (Symbol* error, Symbol* message,
74
95
Symbol* cause, Symbol* cause_msg):
75
- _cp_index(cp_index),
76
96
_error(error),
77
97
_message(message),
78
98
_cause(cause),
79
99
_cause_msg(cause_msg),
80
- _pool(pool),
81
100
_nest_host_error(nullptr ) {
82
101
83
- if (_error != nullptr ) {
84
- _error->increment_refcount ();
85
- }
86
-
87
- if (_message != nullptr ) {
88
- _message->increment_refcount ();
89
- }
90
-
91
- if (_cause != nullptr ) {
92
- _cause->increment_refcount ();
93
- }
94
-
95
- if (_cause_msg != nullptr ) {
96
- _cause_msg->increment_refcount ();
97
- }
102
+ Symbol::maybe_increment_refcount (_error);
103
+ Symbol::maybe_increment_refcount (_message);
104
+ Symbol::maybe_increment_refcount (_cause);
105
+ Symbol::maybe_increment_refcount (_cause_msg);
98
106
}
99
107
100
108
ResolutionErrorEntry::~ResolutionErrorEntry () {
101
109
// decrement error refcount
102
- if (error () != NULL ) {
103
- error ()->decrement_refcount ();
104
- }
105
- if (message () != NULL ) {
106
- message ()->decrement_refcount ();
107
- }
108
- if (cause () != NULL ) {
109
- cause ()->decrement_refcount ();
110
- }
111
- if (cause_msg () != NULL ) {
112
- cause_msg ()->decrement_refcount ();
113
- }
110
+ Symbol::maybe_decrement_refcount (_error);
111
+ Symbol::maybe_decrement_refcount (_message);
112
+ Symbol::maybe_decrement_refcount (_cause);
113
+ Symbol::maybe_decrement_refcount (_cause_msg);
114
+
114
115
if (nest_host_error () != NULL ) {
115
116
FREE_C_HEAP_ARRAY (char , nest_host_error ());
116
117
}
117
118
}
118
119
119
- class ResolutionErrorDeleteIterate : StackObj{
120
- private:
120
+ class ResolutionErrorDeleteIterate : StackObj {
121
121
ConstantPool* p;
122
122
123
123
public:
124
124
ResolutionErrorDeleteIterate (ConstantPool* pool):
125
125
p (pool) {};
126
126
127
- bool do_entry (uintptr_t key, ResolutionErrorEntry* value){
128
- if (value -> pool () == p) {
127
+ bool do_entry (const ResolutionErrorKey& key, ResolutionErrorEntry* value){
128
+ if (key. cpool () == p) {
129
129
delete value;
130
130
return true ;
131
131
} else {
@@ -142,10 +142,10 @@ void ResolutionErrorTable::delete_entry(ConstantPool* c) {
142
142
_resolution_error_table.unlink (&deleteIterator);
143
143
}
144
144
145
- class ResolutionIteratePurgeErrors : StackObj{
145
+ class ResolutionIteratePurgeErrors : StackObj {
146
146
public:
147
- bool do_entry (uintptr_t key, ResolutionErrorEntry* value) {
148
- ConstantPool* pool = value -> pool ();
147
+ bool do_entry (const ResolutionErrorKey& key, ResolutionErrorEntry* value){
148
+ ConstantPool* pool = key. cpool ();
149
149
if (!(pool->pool_holder ()->is_loader_alive ())) {
150
150
delete value;
151
151
return true ;
0 commit comments