author | jwilhelm |
Wed, 09 Jan 2019 22:59:49 +0100 | |
changeset 53232 | 32c6cc430526 |
parent 52846 | 6ed72482de52 |
child 53322 | 8ba5b3c76857 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
48781
6ebef5cd0c8d
8194736: Refactor weak oops in ProtectionDomain table to use the Access API
eosterlund
parents:
47774
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
35498
392b50de06c6
8146401: Clean up oop.hpp: add inline directives and fix header files
goetz
parents:
34257
diff
changeset
|
26 |
#include "classfile/classLoaderData.inline.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
49329
diff
changeset
|
27 |
#include "classfile/dictionary.inline.hpp" |
46382
5520c435279b
8178336: Unnecessary SystemDictionary walk for Protection domain liveness
coleenp
parents:
46380
diff
changeset
|
28 |
#include "classfile/protectionDomainCache.hpp" |
7397 | 29 |
#include "classfile/systemDictionary.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
30 |
#include "logging/log.hpp" |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
31 |
#include "logging/logStream.hpp" |
20405 | 32 |
#include "memory/iterator.hpp" |
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
33 |
#include "memory/metaspaceClosure.hpp" |
37248 | 34 |
#include "memory/resourceArea.hpp" |
7397 | 35 |
#include "oops/oop.inline.hpp" |
46729 | 36 |
#include "runtime/atomic.hpp" |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
50039
diff
changeset
|
37 |
#include "runtime/orderAccess.hpp" |
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49348
diff
changeset
|
38 |
#include "runtime/safepointVerifiers.hpp" |
7397 | 39 |
#include "utilities/hashtable.inline.hpp" |
1 | 40 |
|
47774 | 41 |
// Optimization: if any dictionary needs resizing, we set this flag, |
42 |
// so that we dont't have to walk all dictionaries to check if any actually |
|
43 |
// needs resizing, which is costly to do at Safepoint. |
|
44 |
bool Dictionary::_some_dictionary_needs_resizing = false; |
|
45 |
||
46 |
Dictionary::Dictionary(ClassLoaderData* loader_data, int table_size, bool resizable) |
|
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52340
diff
changeset
|
47 |
: Hashtable<InstanceKlass*, mtClass>(table_size, (int)sizeof(DictionaryEntry)), |
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50634
diff
changeset
|
48 |
_resizable(resizable), _needs_resizing(false), _loader_data(loader_data) { |
1 | 49 |
}; |
50 |
||
51 |
||
46729 | 52 |
Dictionary::Dictionary(ClassLoaderData* loader_data, |
53 |
int table_size, HashtableBucket<mtClass>* t, |
|
47774 | 54 |
int number_of_entries, bool resizable) |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52340
diff
changeset
|
55 |
: Hashtable<InstanceKlass*, mtClass>(table_size, (int)sizeof(DictionaryEntry), t, number_of_entries), |
51334
cc2c79d22508
8208671: Runtime, JFR, Serviceability changes to allow enabling -Wreorder
tschatzl
parents:
50634
diff
changeset
|
56 |
_resizable(resizable), _needs_resizing(false), _loader_data(loader_data) { |
1 | 57 |
}; |
58 |
||
46729 | 59 |
Dictionary::~Dictionary() { |
60 |
DictionaryEntry* probe = NULL; |
|
61 |
for (int index = 0; index < table_size(); index++) { |
|
62 |
for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { |
|
63 |
probe = *p; |
|
64 |
*p = probe->next(); |
|
65 |
free_entry(probe); |
|
66 |
} |
|
67 |
} |
|
68 |
assert(number_of_entries() == 0, "should have removed all entries"); |
|
69 |
assert(new_entry_free_list() == NULL, "entry present on Dictionary's free list"); |
|
20405 | 70 |
} |
1 | 71 |
|
46729 | 72 |
DictionaryEntry* Dictionary::new_entry(unsigned int hash, InstanceKlass* klass) { |
73 |
DictionaryEntry* entry = (DictionaryEntry*)Hashtable<InstanceKlass*, mtClass>::allocate_new_entry(hash, klass); |
|
1 | 74 |
entry->set_pd_set(NULL); |
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
75 |
assert(klass->is_instance_klass(), "Must be"); |
1 | 76 |
return entry; |
77 |
} |
|
78 |
||
79 |
||
80 |
void Dictionary::free_entry(DictionaryEntry* entry) { |
|
81 |
// avoid recursion when deleting linked list |
|
47098
e704f55561c3
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents:
46746
diff
changeset
|
82 |
// pd_set is accessed during a safepoint. |
1 | 83 |
while (entry->pd_set() != NULL) { |
84 |
ProtectionDomainEntry* to_delete = entry->pd_set(); |
|
85 |
entry->set_pd_set(to_delete->next()); |
|
86 |
delete to_delete; |
|
87 |
} |
|
46729 | 88 |
// Unlink from the Hashtable prior to freeing |
89 |
unlink_entry(entry); |
|
90 |
FREE_C_HEAP_ARRAY(char, entry); |
|
1 | 91 |
} |
92 |
||
47774 | 93 |
const int _resize_load_trigger = 5; // load factor that will trigger the resize |
94 |
const double _resize_factor = 2.0; // by how much we will resize using current number of entries |
|
95 |
const int _resize_max_size = 40423; // the max dictionary size allowed |
|
96 |
const int _primelist[] = {107, 1009, 2017, 4049, 5051, 10103, 20201, _resize_max_size}; |
|
97 |
const int _prime_array_size = sizeof(_primelist)/sizeof(int); |
|
98 |
||
99 |
// Calculate next "good" dictionary size based on requested count |
|
100 |
static int calculate_dictionary_size(int requested) { |
|
101 |
int newsize = _primelist[0]; |
|
102 |
int index = 0; |
|
103 |
for (newsize = _primelist[index]; index < (_prime_array_size - 1); |
|
104 |
newsize = _primelist[++index]) { |
|
105 |
if (requested <= newsize) { |
|
106 |
break; |
|
107 |
} |
|
108 |
} |
|
109 |
return newsize; |
|
110 |
} |
|
111 |
||
112 |
bool Dictionary::does_any_dictionary_needs_resizing() { |
|
113 |
return Dictionary::_some_dictionary_needs_resizing; |
|
114 |
} |
|
115 |
||
116 |
void Dictionary::check_if_needs_resize() { |
|
117 |
if (_resizable == true) { |
|
118 |
if (number_of_entries() > (_resize_load_trigger*table_size())) { |
|
119 |
_needs_resizing = true; |
|
120 |
Dictionary::_some_dictionary_needs_resizing = true; |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
||
125 |
bool Dictionary::resize_if_needed() { |
|
126 |
int desired_size = 0; |
|
127 |
if (_needs_resizing == true) { |
|
128 |
desired_size = calculate_dictionary_size((int)(_resize_factor*number_of_entries())); |
|
129 |
if (desired_size >= _resize_max_size) { |
|
130 |
desired_size = _resize_max_size; |
|
131 |
// We have reached the limit, turn resizing off |
|
132 |
_resizable = false; |
|
133 |
} |
|
134 |
if ((desired_size != 0) && (desired_size != table_size())) { |
|
135 |
if (!resize(desired_size)) { |
|
136 |
// Something went wrong, turn resizing off |
|
137 |
_resizable = false; |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
||
142 |
_needs_resizing = false; |
|
143 |
Dictionary::_some_dictionary_needs_resizing = false; |
|
144 |
||
145 |
return (desired_size != 0); |
|
146 |
} |
|
1 | 147 |
|
148 |
bool DictionaryEntry::contains_protection_domain(oop protection_domain) const { |
|
149 |
#ifdef ASSERT |
|
49658 | 150 |
if (oopDesc::equals(protection_domain, instance_klass()->protection_domain())) { |
1 | 151 |
// Ensure this doesn't show up in the pd_set (invariant) |
152 |
bool in_pd_set = false; |
|
47098
e704f55561c3
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents:
46746
diff
changeset
|
153 |
for (ProtectionDomainEntry* current = pd_set_acquire(); |
1 | 154 |
current != NULL; |
155 |
current = current->next()) { |
|
49658 | 156 |
if (oopDesc::equals(current->object_no_keepalive(), protection_domain)) { |
1 | 157 |
in_pd_set = true; |
158 |
break; |
|
159 |
} |
|
160 |
} |
|
161 |
if (in_pd_set) { |
|
162 |
assert(false, "A klass's protection domain should not show up " |
|
163 |
"in its sys. dict. PD set"); |
|
164 |
} |
|
165 |
} |
|
166 |
#endif /* ASSERT */ |
|
167 |
||
49658 | 168 |
if (oopDesc::equals(protection_domain, instance_klass()->protection_domain())) { |
1 | 169 |
// Succeeds trivially |
170 |
return true; |
|
171 |
} |
|
172 |
||
47098
e704f55561c3
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents:
46746
diff
changeset
|
173 |
for (ProtectionDomainEntry* current = pd_set_acquire(); |
1 | 174 |
current != NULL; |
175 |
current = current->next()) { |
|
49658 | 176 |
if (oopDesc::equals(current->object_no_keepalive(), protection_domain)) return true; |
1 | 177 |
} |
178 |
return false; |
|
179 |
} |
|
180 |
||
181 |
||
46274
534d019edb92
8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents:
46271
diff
changeset
|
182 |
void DictionaryEntry::add_protection_domain(Dictionary* dict, Handle protection_domain) { |
1 | 183 |
assert_locked_or_safepoint(SystemDictionary_lock); |
46274
534d019edb92
8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents:
46271
diff
changeset
|
184 |
if (!contains_protection_domain(protection_domain())) { |
46729 | 185 |
ProtectionDomainCacheEntry* entry = SystemDictionary::cache_get(protection_domain); |
1 | 186 |
ProtectionDomainEntry* new_head = |
47098
e704f55561c3
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents:
46746
diff
changeset
|
187 |
new ProtectionDomainEntry(entry, pd_set()); |
1 | 188 |
// Warning: Preserve store ordering. The SystemDictionary is read |
189 |
// without locks. The new ProtectionDomainEntry must be |
|
190 |
// complete before other threads can be allowed to see it |
|
191 |
// via a store to _pd_set. |
|
47098
e704f55561c3
8164207: Checking missing load-acquire in relation to _pd_set in dictionary.cpp
coleenp
parents:
46746
diff
changeset
|
192 |
release_set_pd_set(new_head); |
1 | 193 |
} |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
194 |
LogTarget(Trace, protectiondomain) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
195 |
if (lt.is_enabled()) { |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
196 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46475
diff
changeset
|
197 |
print_count(&ls); |
1 | 198 |
} |
199 |
} |
|
200 |
||
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
201 |
// During class loading we may have cached a protection domain that has |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
202 |
// since been unreferenced, so this entry should be cleared. |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49658
diff
changeset
|
203 |
void Dictionary::clean_cached_protection_domains(DictionaryEntry* probe) { |
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
204 |
assert_locked_or_safepoint(SystemDictionary_lock); |
1 | 205 |
|
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
206 |
ProtectionDomainEntry* current = probe->pd_set(); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
207 |
ProtectionDomainEntry* prev = NULL; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
208 |
while (current != NULL) { |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49658
diff
changeset
|
209 |
if (current->object_no_keepalive() == NULL) { |
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
210 |
LogTarget(Debug, protectiondomain) lt; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
211 |
if (lt.is_enabled()) { |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
212 |
ResourceMark rm; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
213 |
// Print out trace information |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
214 |
LogStream ls(lt); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
215 |
ls.print_cr("PD in set is not alive:"); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
216 |
ls.print("class loader: "); loader_data()->class_loader()->print_value_on(&ls); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
217 |
ls.print(" loading: "); probe->instance_klass()->print_value_on(&ls); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
218 |
ls.cr(); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
219 |
} |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
220 |
if (probe->pd_set() == current) { |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
221 |
probe->set_pd_set(current->next()); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
222 |
} else { |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
223 |
assert(prev != NULL, "should be set by alive entry"); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
224 |
prev->set_next(current->next()); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
225 |
} |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
226 |
ProtectionDomainEntry* to_delete = current; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
227 |
current = current->next(); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
228 |
delete to_delete; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
229 |
} else { |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
230 |
prev = current; |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
231 |
current = current->next(); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
232 |
} |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
233 |
} |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
234 |
} |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
235 |
|
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
236 |
|
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49658
diff
changeset
|
237 |
void Dictionary::do_unloading() { |
52846
6ed72482de52
8214522: Last runtime locking issues for concurrent class unloading
eosterlund
parents:
52631
diff
changeset
|
238 |
assert_locked_or_safepoint(SystemDictionary_lock); |
1 | 239 |
|
46729 | 240 |
// The NULL class loader doesn't initiate loading classes from other class loaders |
241 |
if (loader_data() == ClassLoaderData::the_null_class_loader_data()) { |
|
242 |
return; |
|
243 |
} |
|
244 |
||
245 |
// Remove unloaded entries and classes from this dictionary |
|
1 | 246 |
DictionaryEntry* probe = NULL; |
26174
ca46a107cb78
8054402: "klass->is_loader_alive(_is_alive)) failed: must be alive" for anonymous classes
thartmann
parents:
25492
diff
changeset
|
247 |
for (int index = 0; index < table_size(); index++) { |
1 | 248 |
for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { |
249 |
probe = *p; |
|
46729 | 250 |
InstanceKlass* ik = probe->instance_klass(); |
251 |
ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); |
|
1 | 252 |
|
46729 | 253 |
// If the klass that this loader initiated is dead, |
254 |
// (determined by checking the defining class loader) |
|
255 |
// remove this entry. |
|
256 |
if (k_def_class_loader_data->is_unloading()) { |
|
257 |
assert(k_def_class_loader_data != loader_data(), |
|
258 |
"cannot have live defining loader and unreachable klass"); |
|
259 |
*p = probe->next(); |
|
260 |
free_entry(probe); |
|
261 |
continue; |
|
1 | 262 |
} |
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
263 |
// Clean pd_set |
49818
e57e6addb978
8201505: Use WeakHandle for ProtectionDomainCacheTable and ResolvedMethodTable
coleenp
parents:
49658
diff
changeset
|
264 |
clean_cached_protection_domains(probe); |
1 | 265 |
p = probe->next_addr(); |
266 |
} |
|
267 |
} |
|
268 |
} |
|
269 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
270 |
// Just the classes from defining class loaders |
46729 | 271 |
void Dictionary::classes_do(void f(InstanceKlass*)) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
272 |
for (int index = 0; index < table_size(); index++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
273 |
for (DictionaryEntry* probe = bucket(index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
274 |
probe != NULL; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
275 |
probe = probe->next()) { |
46729 | 276 |
InstanceKlass* k = probe->instance_klass(); |
277 |
if (loader_data() == k->class_loader_data()) { |
|
1 | 278 |
f(k); |
279 |
} |
|
280 |
} |
|
281 |
} |
|
282 |
} |
|
283 |
||
284 |
// Added for initialize_itable_for_klass to handle exceptions |
|
285 |
// Just the classes from defining class loaders |
|
46729 | 286 |
void Dictionary::classes_do(void f(InstanceKlass*, TRAPS), TRAPS) { |
1 | 287 |
for (int index = 0; index < table_size(); index++) { |
288 |
for (DictionaryEntry* probe = bucket(index); |
|
289 |
probe != NULL; |
|
290 |
probe = probe->next()) { |
|
46729 | 291 |
InstanceKlass* k = probe->instance_klass(); |
292 |
if (loader_data() == k->class_loader_data()) { |
|
1 | 293 |
f(k, CHECK); |
294 |
} |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
46729 | 299 |
// All classes, and their class loaders, including initiating class loaders |
51530
1f0b605bdc28
8209821: Make JVMTI GetClassLoaderClasses not walk CLDG
coleenp
parents:
51523
diff
changeset
|
300 |
void Dictionary::all_entries_do(KlassClosure* closure) { |
1 | 301 |
for (int index = 0; index < table_size(); index++) { |
302 |
for (DictionaryEntry* probe = bucket(index); |
|
303 |
probe != NULL; |
|
304 |
probe = probe->next()) { |
|
46729 | 305 |
InstanceKlass* k = probe->instance_klass(); |
51530
1f0b605bdc28
8209821: Make JVMTI GetClassLoaderClasses not walk CLDG
coleenp
parents:
51523
diff
changeset
|
306 |
closure->do_klass(k); |
1 | 307 |
} |
308 |
} |
|
309 |
} |
|
310 |
||
46746
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
311 |
// Used to scan and relocate the classes during CDS archive dump. |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
312 |
void Dictionary::classes_do(MetaspaceClosure* it) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
313 |
assert(DumpSharedSpaces, "dump-time only"); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
314 |
for (int index = 0; index < table_size(); index++) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
315 |
for (DictionaryEntry* probe = bucket(index); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
316 |
probe != NULL; |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
317 |
probe = probe->next()) { |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
318 |
it->push(probe->klass_addr()); |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
319 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
320 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
321 |
} |
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
322 |
|
ea379ebb9447
8072061: Automatically determine optimal sizes for the CDS regions
iklam
parents:
46742
diff
changeset
|
323 |
|
1 | 324 |
|
46729 | 325 |
// Add a loaded class to the dictionary. |
1 | 326 |
// Readers of the SystemDictionary aren't always locked, so _buckets |
327 |
// is volatile. The store of the next field in the constructor is |
|
328 |
// also cast to volatile; we do this to ensure store order is maintained |
|
329 |
// by the compilers. |
|
330 |
||
47774 | 331 |
void Dictionary::add_klass(unsigned int hash, Symbol* class_name, |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46274
diff
changeset
|
332 |
InstanceKlass* obj) { |
1 | 333 |
assert_locked_or_safepoint(SystemDictionary_lock); |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46274
diff
changeset
|
334 |
assert(obj != NULL, "adding NULL obj"); |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46274
diff
changeset
|
335 |
assert(obj->name() == class_name, "sanity check on name"); |
1 | 336 |
|
46729 | 337 |
DictionaryEntry* entry = new_entry(hash, obj); |
47774 | 338 |
int index = hash_to_index(hash); |
1 | 339 |
add_entry(index, entry); |
47774 | 340 |
check_if_needs_resize(); |
1 | 341 |
} |
342 |
||
343 |
||
46729 | 344 |
// This routine does not lock the dictionary. |
1 | 345 |
// |
346 |
// Since readers don't hold a lock, we must make sure that system |
|
347 |
// dictionary entries are only removed at a safepoint (when only one |
|
348 |
// thread is running), and are added to in a safe way (all links must |
|
349 |
// be updated in an MT-safe manner). |
|
350 |
// |
|
351 |
// Callers should be aware that an entry could be added just after |
|
352 |
// _buckets[index] is read here, so the caller will not see the new entry. |
|
353 |
DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash, |
|
46729 | 354 |
Symbol* class_name) { |
1 | 355 |
for (DictionaryEntry* entry = bucket(index); |
356 |
entry != NULL; |
|
357 |
entry = entry->next()) { |
|
46729 | 358 |
if (entry->hash() == hash && entry->equals(class_name)) { |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52340
diff
changeset
|
359 |
return entry; |
1 | 360 |
} |
361 |
} |
|
362 |
return NULL; |
|
363 |
} |
|
364 |
||
365 |
||
47774 | 366 |
InstanceKlass* Dictionary::find(unsigned int hash, Symbol* name, |
46729 | 367 |
Handle protection_domain) { |
47774 | 368 |
NoSafepointVerifier nsv; |
369 |
||
370 |
int index = hash_to_index(hash); |
|
46729 | 371 |
DictionaryEntry* entry = get_entry(index, hash, name); |
1 | 372 |
if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) { |
46729 | 373 |
return entry->instance_klass(); |
1 | 374 |
} else { |
375 |
return NULL; |
|
376 |
} |
|
377 |
} |
|
378 |
||
379 |
||
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46274
diff
changeset
|
380 |
InstanceKlass* Dictionary::find_class(int index, unsigned int hash, |
46729 | 381 |
Symbol* name) { |
1 | 382 |
assert_locked_or_safepoint(SystemDictionary_lock); |
46729 | 383 |
assert (index == index_for(name), "incorrect index?"); |
1 | 384 |
|
46729 | 385 |
DictionaryEntry* entry = get_entry(index, hash, name); |
386 |
return (entry != NULL) ? entry->instance_klass() : NULL; |
|
1 | 387 |
} |
388 |
||
389 |
||
390 |
void Dictionary::add_protection_domain(int index, unsigned int hash, |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46274
diff
changeset
|
391 |
InstanceKlass* klass, |
46729 | 392 |
Handle protection_domain, |
1 | 393 |
TRAPS) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
394 |
Symbol* klass_name = klass->name(); |
46729 | 395 |
DictionaryEntry* entry = get_entry(index, hash, klass_name); |
1 | 396 |
|
397 |
assert(entry != NULL,"entry must be present, we just created it"); |
|
398 |
assert(protection_domain() != NULL, |
|
399 |
"real protection domain should be present"); |
|
400 |
||
46274
534d019edb92
8175104: Unhandled oop in ProtectionDomainCacheTable::compute_hash
coleenp
parents:
46271
diff
changeset
|
401 |
entry->add_protection_domain(this, protection_domain); |
1 | 402 |
|
48811
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
403 |
#ifdef ASSERT |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
404 |
assert(loader_data() != ClassLoaderData::the_null_class_loader_data(), "doesn't make sense"); |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
405 |
#endif |
58787a1708d2
8175249: VMThread::run fails in VerifyBeforeExit : Universe::verify
coleenp
parents:
48781
diff
changeset
|
406 |
|
1 | 407 |
assert(entry->contains_protection_domain(protection_domain()), |
408 |
"now protection domain should be present"); |
|
409 |
} |
|
410 |
||
411 |
||
47774 | 412 |
bool Dictionary::is_valid_protection_domain(unsigned int hash, |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
413 |
Symbol* name, |
1 | 414 |
Handle protection_domain) { |
47774 | 415 |
int index = hash_to_index(hash); |
46729 | 416 |
DictionaryEntry* entry = get_entry(index, hash, name); |
1 | 417 |
return entry->is_valid_protection_domain(protection_domain); |
418 |
} |
|
419 |
||
2534 | 420 |
SymbolPropertyTable::SymbolPropertyTable(int table_size) |
13195 | 421 |
: Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry)) |
2534 | 422 |
{ |
423 |
} |
|
13195 | 424 |
SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, |
2534 | 425 |
int number_of_entries) |
13195 | 426 |
: Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries) |
2534 | 427 |
{ |
428 |
} |
|
429 |
||
430 |
||
431 |
SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
432 |
Symbol* sym, |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
433 |
intptr_t sym_mode) { |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
434 |
assert(index == index_for(sym, sym_mode), "incorrect index?"); |
2534 | 435 |
for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
436 |
if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) { |
2534 | 437 |
return p; |
438 |
} |
|
439 |
} |
|
440 |
return NULL; |
|
441 |
} |
|
442 |
||
443 |
||
444 |
SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
445 |
Symbol* sym, intptr_t sym_mode) { |
2534 | 446 |
assert_locked_or_safepoint(SystemDictionary_lock); |
5420
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
447 |
assert(index == index_for(sym, sym_mode), "incorrect index?"); |
586d3988e72b
6939134: JSR 292 adjustments to method handle invocation
jrose
parents:
2534
diff
changeset
|
448 |
assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry"); |
2534 | 449 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7397
diff
changeset
|
450 |
SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode); |
13195 | 451 |
Hashtable<Symbol*, mtSymbol>::add_entry(index, p); |
2534 | 452 |
return p; |
453 |
} |
|
454 |
||
455 |
void SymbolPropertyTable::oops_do(OopClosure* f) { |
|
456 |
for (int index = 0; index < table_size(); index++) { |
|
457 |
for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
458 |
if (p->method_type() != NULL) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
459 |
f->do_oop(p->method_type_addr()); |
2534 | 460 |
} |
461 |
} |
|
462 |
} |
|
463 |
} |
|
464 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
465 |
void SymbolPropertyTable::methods_do(void f(Method*)) { |
2534 | 466 |
for (int index = 0; index < table_size(); index++) { |
467 |
for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
468 |
Method* prop = p->method(); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
469 |
if (prop != NULL) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13195
diff
changeset
|
470 |
f((Method*)prop); |
2534 | 471 |
} |
472 |
} |
|
473 |
} |
|
474 |
} |
|
475 |
||
1 | 476 |
|
477 |
// ---------------------------------------------------------------------------- |
|
478 |
||
46742 | 479 |
void Dictionary::print_on(outputStream* st) const { |
1 | 480 |
ResourceMark rm; |
481 |
||
46729 | 482 |
assert(loader_data() != NULL, "loader data should not be null"); |
51523
73523d329966
8208061: runtime/LoadClass/TestResize.java fails with "Load factor too high" when running in CDS mode.
jiangli
parents:
51334
diff
changeset
|
483 |
st->print_cr("Java dictionary (table_size=%d, classes=%d, resizable=%s)", |
73523d329966
8208061: runtime/LoadClass/TestResize.java fails with "Load factor too high" when running in CDS mode.
jiangli
parents:
51334
diff
changeset
|
484 |
table_size(), number_of_entries(), BOOL_TO_STR(_resizable)); |
46742 | 485 |
st->print_cr("^ indicates that initiating loader is different from defining loader"); |
1 | 486 |
|
487 |
for (int index = 0; index < table_size(); index++) { |
|
488 |
for (DictionaryEntry* probe = bucket(index); |
|
489 |
probe != NULL; |
|
490 |
probe = probe->next()) { |
|
46729 | 491 |
Klass* e = probe->instance_klass(); |
1 | 492 |
bool is_defining_class = |
46729 | 493 |
(loader_data() == e->class_loader_data()); |
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
494 |
st->print("%4d: %s%s", index, is_defining_class ? " " : "^", e->external_name()); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
495 |
ClassLoaderData* cld = e->class_loader_data(); |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52340
diff
changeset
|
496 |
if (!loader_data()->is_the_null_class_loader_data()) { |
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
497 |
// Class loader output for the dictionary for the null class loader data is |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
498 |
// redundant and obvious. |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
499 |
st->print(", "); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
500 |
cld->print_value_on(st); |
39982
1a3808e3f4d9
8138760: [JVMCI] VM warning: Performance bug: SystemDictionary lookup_count=21831450 lookup_length=1275207287 average=58.411479 load=5.572844
gziemski
parents:
38259
diff
changeset
|
501 |
} |
46742 | 502 |
st->cr(); |
1 | 503 |
} |
504 |
} |
|
20405 | 505 |
tty->cr(); |
1 | 506 |
} |
507 |
||
46475
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
508 |
void DictionaryEntry::verify() { |
46729 | 509 |
Klass* e = instance_klass(); |
510 |
guarantee(e->is_instance_klass(), |
|
511 |
"Verify of dictionary failed"); |
|
512 |
e->verify(); |
|
513 |
verify_protection_domain_set(); |
|
514 |
} |
|
515 |
||
516 |
void Dictionary::verify() { |
|
517 |
guarantee(number_of_entries() >= 0, "Verify of dictionary failed"); |
|
518 |
||
46475
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
519 |
ClassLoaderData* cld = loader_data(); |
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
520 |
// class loader must be present; a null class loader is the |
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
521 |
// boostrap loader |
52514
f4e3900c8d08
8213346: Re-implement shared dictionary using CompactHashtable
iklam
parents:
52340
diff
changeset
|
522 |
guarantee(cld != NULL || |
46475
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
523 |
cld->class_loader() == NULL || |
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
524 |
cld->class_loader()->is_instance(), |
75902cea18af
8166848: Performance bug: SystemDictionary - optimization
coleenp
parents:
46382
diff
changeset
|
525 |
"checking type of class_loader"); |
46729 | 526 |
|
527 |
ResourceMark rm; |
|
528 |
stringStream tempst; |
|
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50429
diff
changeset
|
529 |
tempst.print("System Dictionary for %s class loader", cld->loader_name_and_id()); |
46729 | 530 |
verify_table<DictionaryEntry>(tempst.as_string()); |
42073
89e056fd82cc
8166145: runtime/threads/ThreadInterruptTest3 fails with ExitCode 0
gziemski
parents:
39982
diff
changeset
|
531 |
} |