Fri, 26 Sep 2014 17:48:10 -0400
8047125: (ref) More phantom object references
Reviewed-by: mchung, dfuchs, ahgross, jmasa, brutisso, mgerdin
Contributed-by: kim.barrett@oracle.com
duke@435 | 1 | /* |
coleenp@6316 | 2 | * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #include "precompiled.hpp" |
stefank@2314 | 26 | #include "classfile/dictionary.hpp" |
stefank@2314 | 27 | #include "classfile/systemDictionary.hpp" |
tschatzl@5862 | 28 | #include "memory/iterator.hpp" |
stefank@2314 | 29 | #include "oops/oop.inline.hpp" |
stefank@2314 | 30 | #include "prims/jvmtiRedefineClassesTrace.hpp" |
stefank@2314 | 31 | #include "utilities/hashtable.inline.hpp" |
duke@435 | 32 | |
drchase@6680 | 33 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
duke@435 | 34 | |
duke@435 | 35 | DictionaryEntry* Dictionary::_current_class_entry = NULL; |
duke@435 | 36 | int Dictionary::_current_class_index = 0; |
duke@435 | 37 | |
duke@435 | 38 | |
duke@435 | 39 | Dictionary::Dictionary(int table_size) |
coleenp@4037 | 40 | : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry)) { |
duke@435 | 41 | _current_class_index = 0; |
duke@435 | 42 | _current_class_entry = NULL; |
tschatzl@5862 | 43 | _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); |
duke@435 | 44 | }; |
duke@435 | 45 | |
duke@435 | 46 | |
zgu@3900 | 47 | Dictionary::Dictionary(int table_size, HashtableBucket<mtClass>* t, |
duke@435 | 48 | int number_of_entries) |
coleenp@4037 | 49 | : TwoOopHashtable<Klass*, mtClass>(table_size, sizeof(DictionaryEntry), t, number_of_entries) { |
duke@435 | 50 | _current_class_index = 0; |
duke@435 | 51 | _current_class_entry = NULL; |
tschatzl@5862 | 52 | _pd_cache_table = new ProtectionDomainCacheTable(defaultProtectionDomainCacheSize); |
duke@435 | 53 | }; |
duke@435 | 54 | |
tschatzl@5862 | 55 | ProtectionDomainCacheEntry* Dictionary::cache_get(oop protection_domain) { |
tschatzl@5862 | 56 | return _pd_cache_table->get(protection_domain); |
tschatzl@5862 | 57 | } |
duke@435 | 58 | |
coleenp@4037 | 59 | DictionaryEntry* Dictionary::new_entry(unsigned int hash, Klass* klass, |
coleenp@4037 | 60 | ClassLoaderData* loader_data) { |
coleenp@4037 | 61 | DictionaryEntry* entry = (DictionaryEntry*)Hashtable<Klass*, mtClass>::new_entry(hash, klass); |
coleenp@4037 | 62 | entry->set_loader_data(loader_data); |
duke@435 | 63 | entry->set_pd_set(NULL); |
coleenp@4037 | 64 | assert(klass->oop_is_instance(), "Must be"); |
duke@435 | 65 | return entry; |
duke@435 | 66 | } |
duke@435 | 67 | |
duke@435 | 68 | |
duke@435 | 69 | void Dictionary::free_entry(DictionaryEntry* entry) { |
duke@435 | 70 | // avoid recursion when deleting linked list |
duke@435 | 71 | while (entry->pd_set() != NULL) { |
duke@435 | 72 | ProtectionDomainEntry* to_delete = entry->pd_set(); |
duke@435 | 73 | entry->set_pd_set(to_delete->next()); |
duke@435 | 74 | delete to_delete; |
duke@435 | 75 | } |
coleenp@4037 | 76 | Hashtable<Klass*, mtClass>::free_entry(entry); |
duke@435 | 77 | } |
duke@435 | 78 | |
duke@435 | 79 | |
duke@435 | 80 | bool DictionaryEntry::contains_protection_domain(oop protection_domain) const { |
duke@435 | 81 | #ifdef ASSERT |
coleenp@4037 | 82 | if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) { |
duke@435 | 83 | // Ensure this doesn't show up in the pd_set (invariant) |
duke@435 | 84 | bool in_pd_set = false; |
duke@435 | 85 | for (ProtectionDomainEntry* current = _pd_set; |
duke@435 | 86 | current != NULL; |
duke@435 | 87 | current = current->next()) { |
duke@435 | 88 | if (current->protection_domain() == protection_domain) { |
duke@435 | 89 | in_pd_set = true; |
duke@435 | 90 | break; |
duke@435 | 91 | } |
duke@435 | 92 | } |
duke@435 | 93 | if (in_pd_set) { |
duke@435 | 94 | assert(false, "A klass's protection domain should not show up " |
duke@435 | 95 | "in its sys. dict. PD set"); |
duke@435 | 96 | } |
duke@435 | 97 | } |
duke@435 | 98 | #endif /* ASSERT */ |
duke@435 | 99 | |
coleenp@4037 | 100 | if (protection_domain == InstanceKlass::cast(klass())->protection_domain()) { |
duke@435 | 101 | // Succeeds trivially |
duke@435 | 102 | return true; |
duke@435 | 103 | } |
duke@435 | 104 | |
duke@435 | 105 | for (ProtectionDomainEntry* current = _pd_set; |
duke@435 | 106 | current != NULL; |
duke@435 | 107 | current = current->next()) { |
duke@435 | 108 | if (current->protection_domain() == protection_domain) return true; |
duke@435 | 109 | } |
duke@435 | 110 | return false; |
duke@435 | 111 | } |
duke@435 | 112 | |
duke@435 | 113 | |
tschatzl@5862 | 114 | void DictionaryEntry::add_protection_domain(Dictionary* dict, oop protection_domain) { |
duke@435 | 115 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 116 | if (!contains_protection_domain(protection_domain)) { |
tschatzl@5862 | 117 | ProtectionDomainCacheEntry* entry = dict->cache_get(protection_domain); |
duke@435 | 118 | ProtectionDomainEntry* new_head = |
tschatzl@5862 | 119 | new ProtectionDomainEntry(entry, _pd_set); |
duke@435 | 120 | // Warning: Preserve store ordering. The SystemDictionary is read |
duke@435 | 121 | // without locks. The new ProtectionDomainEntry must be |
duke@435 | 122 | // complete before other threads can be allowed to see it |
duke@435 | 123 | // via a store to _pd_set. |
duke@435 | 124 | OrderAccess::release_store_ptr(&_pd_set, new_head); |
duke@435 | 125 | } |
duke@435 | 126 | if (TraceProtectionDomainVerification && WizardMode) { |
duke@435 | 127 | print(); |
duke@435 | 128 | } |
duke@435 | 129 | } |
duke@435 | 130 | |
duke@435 | 131 | |
coleenp@4037 | 132 | bool Dictionary::do_unloading() { |
jcoomes@1844 | 133 | assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); |
duke@435 | 134 | bool class_was_unloaded = false; |
duke@435 | 135 | int index = 0; // Defined here for portability! Do not move |
duke@435 | 136 | |
duke@435 | 137 | // Remove unloadable entries and classes from system dictionary |
duke@435 | 138 | // The placeholder array has been handled in always_strong_oops_do. |
duke@435 | 139 | DictionaryEntry* probe = NULL; |
duke@435 | 140 | for (index = 0; index < table_size(); index++) { |
duke@435 | 141 | for (DictionaryEntry** p = bucket_addr(index); *p != NULL; ) { |
duke@435 | 142 | probe = *p; |
coleenp@4037 | 143 | Klass* e = probe->klass(); |
coleenp@4037 | 144 | ClassLoaderData* loader_data = probe->loader_data(); |
duke@435 | 145 | |
coleenp@4037 | 146 | InstanceKlass* ik = InstanceKlass::cast(e); |
duke@435 | 147 | |
duke@435 | 148 | // Non-unloadable classes were handled in always_strong_oops_do |
coleenp@4037 | 149 | if (!is_strongly_reachable(loader_data, e)) { |
duke@435 | 150 | // Entry was not visited in phase1 (negated test from phase1) |
coleenp@4037 | 151 | assert(!loader_data->is_the_null_class_loader_data(), "unloading entry with null class loader"); |
coleenp@4037 | 152 | ClassLoaderData* k_def_class_loader_data = ik->class_loader_data(); |
duke@435 | 153 | |
duke@435 | 154 | // Do we need to delete this system dictionary entry? |
duke@435 | 155 | bool purge_entry = false; |
duke@435 | 156 | |
duke@435 | 157 | // Do we need to delete this system dictionary entry? |
coleenp@4037 | 158 | if (loader_data->is_unloading()) { |
duke@435 | 159 | // If the loader is not live this entry should always be |
duke@435 | 160 | // removed (will never be looked up again). Note that this is |
duke@435 | 161 | // not the same as unloading the referred class. |
coleenp@4037 | 162 | if (k_def_class_loader_data == loader_data) { |
duke@435 | 163 | // This is the defining entry, so the referred class is about |
duke@435 | 164 | // to be unloaded. |
duke@435 | 165 | class_was_unloaded = true; |
duke@435 | 166 | } |
duke@435 | 167 | // Also remove this system dictionary entry. |
duke@435 | 168 | purge_entry = true; |
duke@435 | 169 | |
duke@435 | 170 | } else { |
duke@435 | 171 | // The loader in this entry is alive. If the klass is dead, |
coleenp@4037 | 172 | // (determined by checking the defining class loader) |
duke@435 | 173 | // the loader must be an initiating loader (rather than the |
duke@435 | 174 | // defining loader). Remove this entry. |
coleenp@4037 | 175 | if (k_def_class_loader_data->is_unloading()) { |
coleenp@4037 | 176 | // If we get here, the class_loader_data must not be the defining |
duke@435 | 177 | // loader, it must be an initiating one. |
coleenp@4037 | 178 | assert(k_def_class_loader_data != loader_data, |
duke@435 | 179 | "cannot have live defining loader and unreachable klass"); |
duke@435 | 180 | // Loader is live, but class and its defining loader are dead. |
duke@435 | 181 | // Remove the entry. The class is going away. |
duke@435 | 182 | purge_entry = true; |
duke@435 | 183 | } |
duke@435 | 184 | } |
duke@435 | 185 | |
duke@435 | 186 | if (purge_entry) { |
duke@435 | 187 | *p = probe->next(); |
duke@435 | 188 | if (probe == _current_class_entry) { |
duke@435 | 189 | _current_class_entry = NULL; |
duke@435 | 190 | } |
duke@435 | 191 | free_entry(probe); |
duke@435 | 192 | continue; |
duke@435 | 193 | } |
duke@435 | 194 | } |
duke@435 | 195 | p = probe->next_addr(); |
duke@435 | 196 | } |
duke@435 | 197 | } |
duke@435 | 198 | return class_was_unloaded; |
duke@435 | 199 | } |
duke@435 | 200 | |
duke@435 | 201 | |
coleenp@4037 | 202 | void Dictionary::always_strong_oops_do(OopClosure* blk) { |
tschatzl@5862 | 203 | // Follow all system classes and temporary placeholders in dictionary; only |
tschatzl@5862 | 204 | // protection domain oops contain references into the heap. In a first |
tschatzl@5862 | 205 | // pass over the system dictionary determine which need to be treated as |
tschatzl@5862 | 206 | // strongly reachable and mark them as such. |
duke@435 | 207 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 208 | for (DictionaryEntry *probe = bucket(index); |
duke@435 | 209 | probe != NULL; |
duke@435 | 210 | probe = probe->next()) { |
coleenp@4037 | 211 | Klass* e = probe->klass(); |
coleenp@4037 | 212 | ClassLoaderData* loader_data = probe->loader_data(); |
coleenp@4037 | 213 | if (is_strongly_reachable(loader_data, e)) { |
tschatzl@5862 | 214 | probe->set_strongly_reachable(); |
duke@435 | 215 | } |
duke@435 | 216 | } |
duke@435 | 217 | } |
tschatzl@5862 | 218 | // Then iterate over the protection domain cache to apply the closure on the |
tschatzl@5862 | 219 | // previously marked ones. |
tschatzl@5862 | 220 | _pd_cache_table->always_strong_oops_do(blk); |
duke@435 | 221 | } |
duke@435 | 222 | |
duke@435 | 223 | |
coleenp@4037 | 224 | void Dictionary::always_strong_classes_do(KlassClosure* closure) { |
coleenp@4037 | 225 | // Follow all system classes and temporary placeholders in dictionary |
duke@435 | 226 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 227 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 228 | probe != NULL; |
duke@435 | 229 | probe = probe->next()) { |
coleenp@4037 | 230 | Klass* e = probe->klass(); |
coleenp@4037 | 231 | ClassLoaderData* loader_data = probe->loader_data(); |
coleenp@4037 | 232 | if (is_strongly_reachable(loader_data, e)) { |
coleenp@4037 | 233 | closure->do_klass(e); |
coleenp@4037 | 234 | } |
coleenp@4037 | 235 | } |
coleenp@4037 | 236 | } |
coleenp@4037 | 237 | } |
coleenp@4037 | 238 | |
coleenp@4037 | 239 | |
coleenp@4037 | 240 | // Just the classes from defining class loaders |
coleenp@4037 | 241 | void Dictionary::classes_do(void f(Klass*)) { |
coleenp@4037 | 242 | for (int index = 0; index < table_size(); index++) { |
coleenp@4037 | 243 | for (DictionaryEntry* probe = bucket(index); |
coleenp@4037 | 244 | probe != NULL; |
coleenp@4037 | 245 | probe = probe->next()) { |
coleenp@4037 | 246 | Klass* k = probe->klass(); |
coleenp@4037 | 247 | if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { |
duke@435 | 248 | f(k); |
duke@435 | 249 | } |
duke@435 | 250 | } |
duke@435 | 251 | } |
duke@435 | 252 | } |
duke@435 | 253 | |
duke@435 | 254 | // Added for initialize_itable_for_klass to handle exceptions |
duke@435 | 255 | // Just the classes from defining class loaders |
coleenp@4037 | 256 | void Dictionary::classes_do(void f(Klass*, TRAPS), TRAPS) { |
duke@435 | 257 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 258 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 259 | probe != NULL; |
duke@435 | 260 | probe = probe->next()) { |
coleenp@4037 | 261 | Klass* k = probe->klass(); |
coleenp@4037 | 262 | if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { |
duke@435 | 263 | f(k, CHECK); |
duke@435 | 264 | } |
duke@435 | 265 | } |
duke@435 | 266 | } |
duke@435 | 267 | } |
duke@435 | 268 | |
duke@435 | 269 | // All classes, and their class loaders |
duke@435 | 270 | // Don't iterate over placeholders |
coleenp@4037 | 271 | void Dictionary::classes_do(void f(Klass*, ClassLoaderData*)) { |
duke@435 | 272 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 273 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 274 | probe != NULL; |
duke@435 | 275 | probe = probe->next()) { |
coleenp@4037 | 276 | Klass* k = probe->klass(); |
coleenp@4037 | 277 | f(k, probe->loader_data()); |
duke@435 | 278 | } |
duke@435 | 279 | } |
duke@435 | 280 | } |
duke@435 | 281 | |
duke@435 | 282 | void Dictionary::oops_do(OopClosure* f) { |
tschatzl@5862 | 283 | // Only the protection domain oops contain references into the heap. Iterate |
tschatzl@5862 | 284 | // over all of them. |
tschatzl@5862 | 285 | _pd_cache_table->oops_do(f); |
duke@435 | 286 | } |
duke@435 | 287 | |
coleenp@4037 | 288 | void Dictionary::methods_do(void f(Method*)) { |
duke@435 | 289 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 290 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 291 | probe != NULL; |
duke@435 | 292 | probe = probe->next()) { |
coleenp@4037 | 293 | Klass* k = probe->klass(); |
coleenp@4037 | 294 | if (probe->loader_data() == InstanceKlass::cast(k)->class_loader_data()) { |
duke@435 | 295 | // only take klass is we have the entry with the defining class loader |
coleenp@4037 | 296 | InstanceKlass::cast(k)->methods_do(f); |
duke@435 | 297 | } |
duke@435 | 298 | } |
duke@435 | 299 | } |
duke@435 | 300 | } |
duke@435 | 301 | |
tschatzl@5862 | 302 | void Dictionary::unlink(BoolObjectClosure* is_alive) { |
tschatzl@5862 | 303 | // Only the protection domain cache table may contain references to the heap |
tschatzl@5862 | 304 | // that need to be unlinked. |
tschatzl@5862 | 305 | _pd_cache_table->unlink(is_alive); |
tschatzl@5862 | 306 | } |
duke@435 | 307 | |
coleenp@4037 | 308 | Klass* Dictionary::try_get_next_class() { |
duke@435 | 309 | while (true) { |
duke@435 | 310 | if (_current_class_entry != NULL) { |
coleenp@4037 | 311 | Klass* k = _current_class_entry->klass(); |
duke@435 | 312 | _current_class_entry = _current_class_entry->next(); |
duke@435 | 313 | return k; |
duke@435 | 314 | } |
duke@435 | 315 | _current_class_index = (_current_class_index + 1) % table_size(); |
duke@435 | 316 | _current_class_entry = bucket(_current_class_index); |
duke@435 | 317 | } |
duke@435 | 318 | // never reached |
duke@435 | 319 | } |
duke@435 | 320 | |
duke@435 | 321 | // Add a loaded class to the system dictionary. |
duke@435 | 322 | // Readers of the SystemDictionary aren't always locked, so _buckets |
duke@435 | 323 | // is volatile. The store of the next field in the constructor is |
duke@435 | 324 | // also cast to volatile; we do this to ensure store order is maintained |
duke@435 | 325 | // by the compilers. |
duke@435 | 326 | |
coleenp@4037 | 327 | void Dictionary::add_klass(Symbol* class_name, ClassLoaderData* loader_data, |
duke@435 | 328 | KlassHandle obj) { |
duke@435 | 329 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 330 | assert(obj() != NULL, "adding NULL obj"); |
hseigel@4278 | 331 | assert(obj()->name() == class_name, "sanity check on name"); |
stefank@4667 | 332 | assert(loader_data != NULL, "Must be non-NULL"); |
duke@435 | 333 | |
coleenp@4037 | 334 | unsigned int hash = compute_hash(class_name, loader_data); |
duke@435 | 335 | int index = hash_to_index(hash); |
coleenp@4037 | 336 | DictionaryEntry* entry = new_entry(hash, obj(), loader_data); |
duke@435 | 337 | add_entry(index, entry); |
duke@435 | 338 | } |
duke@435 | 339 | |
duke@435 | 340 | |
duke@435 | 341 | // This routine does not lock the system dictionary. |
duke@435 | 342 | // |
duke@435 | 343 | // Since readers don't hold a lock, we must make sure that system |
duke@435 | 344 | // dictionary entries are only removed at a safepoint (when only one |
duke@435 | 345 | // thread is running), and are added to in a safe way (all links must |
duke@435 | 346 | // be updated in an MT-safe manner). |
duke@435 | 347 | // |
duke@435 | 348 | // Callers should be aware that an entry could be added just after |
duke@435 | 349 | // _buckets[index] is read here, so the caller will not see the new entry. |
duke@435 | 350 | DictionaryEntry* Dictionary::get_entry(int index, unsigned int hash, |
coleenp@2497 | 351 | Symbol* class_name, |
coleenp@4037 | 352 | ClassLoaderData* loader_data) { |
duke@435 | 353 | debug_only(_lookup_count++); |
duke@435 | 354 | for (DictionaryEntry* entry = bucket(index); |
duke@435 | 355 | entry != NULL; |
duke@435 | 356 | entry = entry->next()) { |
coleenp@4037 | 357 | if (entry->hash() == hash && entry->equals(class_name, loader_data)) { |
duke@435 | 358 | return entry; |
duke@435 | 359 | } |
duke@435 | 360 | debug_only(_lookup_length++); |
duke@435 | 361 | } |
duke@435 | 362 | return NULL; |
duke@435 | 363 | } |
duke@435 | 364 | |
duke@435 | 365 | |
coleenp@4037 | 366 | Klass* Dictionary::find(int index, unsigned int hash, Symbol* name, |
coleenp@4037 | 367 | ClassLoaderData* loader_data, Handle protection_domain, TRAPS) { |
coleenp@4037 | 368 | DictionaryEntry* entry = get_entry(index, hash, name, loader_data); |
duke@435 | 369 | if (entry != NULL && entry->is_valid_protection_domain(protection_domain)) { |
duke@435 | 370 | return entry->klass(); |
duke@435 | 371 | } else { |
duke@435 | 372 | return NULL; |
duke@435 | 373 | } |
duke@435 | 374 | } |
duke@435 | 375 | |
duke@435 | 376 | |
coleenp@4037 | 377 | Klass* Dictionary::find_class(int index, unsigned int hash, |
coleenp@4037 | 378 | Symbol* name, ClassLoaderData* loader_data) { |
duke@435 | 379 | assert_locked_or_safepoint(SystemDictionary_lock); |
coleenp@4037 | 380 | assert (index == index_for(name, loader_data), "incorrect index?"); |
duke@435 | 381 | |
coleenp@4037 | 382 | DictionaryEntry* entry = get_entry(index, hash, name, loader_data); |
coleenp@4037 | 383 | return (entry != NULL) ? entry->klass() : (Klass*)NULL; |
duke@435 | 384 | } |
duke@435 | 385 | |
duke@435 | 386 | |
duke@435 | 387 | // Variant of find_class for shared classes. No locking required, as |
duke@435 | 388 | // that table is static. |
duke@435 | 389 | |
coleenp@4037 | 390 | Klass* Dictionary::find_shared_class(int index, unsigned int hash, |
coleenp@2497 | 391 | Symbol* name) { |
coleenp@4037 | 392 | assert (index == index_for(name, NULL), "incorrect index?"); |
duke@435 | 393 | |
coleenp@4037 | 394 | DictionaryEntry* entry = get_entry(index, hash, name, NULL); |
coleenp@4037 | 395 | return (entry != NULL) ? entry->klass() : (Klass*)NULL; |
duke@435 | 396 | } |
duke@435 | 397 | |
duke@435 | 398 | |
duke@435 | 399 | void Dictionary::add_protection_domain(int index, unsigned int hash, |
duke@435 | 400 | instanceKlassHandle klass, |
coleenp@4037 | 401 | ClassLoaderData* loader_data, Handle protection_domain, |
duke@435 | 402 | TRAPS) { |
coleenp@2497 | 403 | Symbol* klass_name = klass->name(); |
coleenp@4037 | 404 | DictionaryEntry* entry = get_entry(index, hash, klass_name, loader_data); |
duke@435 | 405 | |
duke@435 | 406 | assert(entry != NULL,"entry must be present, we just created it"); |
duke@435 | 407 | assert(protection_domain() != NULL, |
duke@435 | 408 | "real protection domain should be present"); |
duke@435 | 409 | |
tschatzl@5862 | 410 | entry->add_protection_domain(this, protection_domain()); |
duke@435 | 411 | |
duke@435 | 412 | assert(entry->contains_protection_domain(protection_domain()), |
duke@435 | 413 | "now protection domain should be present"); |
duke@435 | 414 | } |
duke@435 | 415 | |
duke@435 | 416 | |
duke@435 | 417 | bool Dictionary::is_valid_protection_domain(int index, unsigned int hash, |
coleenp@2497 | 418 | Symbol* name, |
coleenp@4037 | 419 | ClassLoaderData* loader_data, |
duke@435 | 420 | Handle protection_domain) { |
coleenp@4037 | 421 | DictionaryEntry* entry = get_entry(index, hash, name, loader_data); |
duke@435 | 422 | return entry->is_valid_protection_domain(protection_domain); |
duke@435 | 423 | } |
duke@435 | 424 | |
duke@435 | 425 | |
duke@435 | 426 | void Dictionary::reorder_dictionary() { |
duke@435 | 427 | |
duke@435 | 428 | // Copy all the dictionary entries into a single master list. |
duke@435 | 429 | |
duke@435 | 430 | DictionaryEntry* master_list = NULL; |
duke@435 | 431 | for (int i = 0; i < table_size(); ++i) { |
duke@435 | 432 | DictionaryEntry* p = bucket(i); |
duke@435 | 433 | while (p != NULL) { |
duke@435 | 434 | DictionaryEntry* tmp; |
duke@435 | 435 | tmp = p->next(); |
duke@435 | 436 | p->set_next(master_list); |
duke@435 | 437 | master_list = p; |
duke@435 | 438 | p = tmp; |
duke@435 | 439 | } |
duke@435 | 440 | set_entry(i, NULL); |
duke@435 | 441 | } |
duke@435 | 442 | |
duke@435 | 443 | // Add the dictionary entries back to the list in the correct buckets. |
duke@435 | 444 | while (master_list != NULL) { |
duke@435 | 445 | DictionaryEntry* p = master_list; |
duke@435 | 446 | master_list = master_list->next(); |
duke@435 | 447 | p->set_next(NULL); |
coleenp@4037 | 448 | Symbol* class_name = InstanceKlass::cast((Klass*)(p->klass()))->name(); |
coleenp@4037 | 449 | // Since the null class loader data isn't copied to the CDS archive, |
coleenp@4037 | 450 | // compute the hash with NULL for loader data. |
coleenp@4037 | 451 | unsigned int hash = compute_hash(class_name, NULL); |
duke@435 | 452 | int index = hash_to_index(hash); |
duke@435 | 453 | p->set_hash(hash); |
coleenp@4037 | 454 | p->set_loader_data(NULL); // loader_data isn't copied to CDS |
duke@435 | 455 | p->set_next(bucket(index)); |
duke@435 | 456 | set_entry(index, p); |
duke@435 | 457 | } |
duke@435 | 458 | } |
duke@435 | 459 | |
tschatzl@5862 | 460 | ProtectionDomainCacheTable::ProtectionDomainCacheTable(int table_size) |
tschatzl@5862 | 461 | : Hashtable<oop, mtClass>(table_size, sizeof(ProtectionDomainCacheEntry)) |
tschatzl@5862 | 462 | { |
tschatzl@5862 | 463 | } |
tschatzl@5862 | 464 | |
tschatzl@5862 | 465 | void ProtectionDomainCacheTable::unlink(BoolObjectClosure* is_alive) { |
tschatzl@5862 | 466 | assert(SafepointSynchronize::is_at_safepoint(), "must be"); |
tschatzl@5862 | 467 | for (int i = 0; i < table_size(); ++i) { |
tschatzl@5862 | 468 | ProtectionDomainCacheEntry** p = bucket_addr(i); |
tschatzl@5862 | 469 | ProtectionDomainCacheEntry* entry = bucket(i); |
tschatzl@5862 | 470 | while (entry != NULL) { |
tschatzl@5862 | 471 | if (is_alive->do_object_b(entry->literal())) { |
tschatzl@5862 | 472 | p = entry->next_addr(); |
tschatzl@5862 | 473 | } else { |
tschatzl@5862 | 474 | *p = entry->next(); |
tschatzl@5862 | 475 | free_entry(entry); |
tschatzl@5862 | 476 | } |
tschatzl@5862 | 477 | entry = *p; |
tschatzl@5862 | 478 | } |
tschatzl@5862 | 479 | } |
tschatzl@5862 | 480 | } |
tschatzl@5862 | 481 | |
tschatzl@5862 | 482 | void ProtectionDomainCacheTable::oops_do(OopClosure* f) { |
tschatzl@5862 | 483 | for (int index = 0; index < table_size(); index++) { |
tschatzl@5862 | 484 | for (ProtectionDomainCacheEntry* probe = bucket(index); |
tschatzl@5862 | 485 | probe != NULL; |
tschatzl@5862 | 486 | probe = probe->next()) { |
tschatzl@5862 | 487 | probe->oops_do(f); |
tschatzl@5862 | 488 | } |
tschatzl@5862 | 489 | } |
tschatzl@5862 | 490 | } |
tschatzl@5862 | 491 | |
tschatzl@5862 | 492 | uint ProtectionDomainCacheTable::bucket_size() { |
tschatzl@5862 | 493 | return sizeof(ProtectionDomainCacheEntry); |
tschatzl@5862 | 494 | } |
tschatzl@5862 | 495 | |
tschatzl@5862 | 496 | #ifndef PRODUCT |
tschatzl@5862 | 497 | void ProtectionDomainCacheTable::print() { |
tschatzl@5862 | 498 | tty->print_cr("Protection domain cache table (table_size=%d, classes=%d)", |
tschatzl@5862 | 499 | table_size(), number_of_entries()); |
tschatzl@5862 | 500 | for (int index = 0; index < table_size(); index++) { |
tschatzl@5862 | 501 | for (ProtectionDomainCacheEntry* probe = bucket(index); |
tschatzl@5862 | 502 | probe != NULL; |
tschatzl@5862 | 503 | probe = probe->next()) { |
tschatzl@5862 | 504 | probe->print(); |
tschatzl@5862 | 505 | } |
tschatzl@5862 | 506 | } |
tschatzl@5862 | 507 | } |
tschatzl@5862 | 508 | |
tschatzl@5862 | 509 | void ProtectionDomainCacheEntry::print() { |
tschatzl@5862 | 510 | tty->print_cr("entry "PTR_FORMAT" value "PTR_FORMAT" strongly_reachable %d next "PTR_FORMAT, |
jcoomes@5865 | 511 | this, (void*)literal(), _strongly_reachable, next()); |
tschatzl@5862 | 512 | } |
tschatzl@5862 | 513 | #endif |
tschatzl@5862 | 514 | |
tschatzl@5862 | 515 | void ProtectionDomainCacheTable::verify() { |
tschatzl@5862 | 516 | int element_count = 0; |
tschatzl@5862 | 517 | for (int index = 0; index < table_size(); index++) { |
tschatzl@5862 | 518 | for (ProtectionDomainCacheEntry* probe = bucket(index); |
tschatzl@5862 | 519 | probe != NULL; |
tschatzl@5862 | 520 | probe = probe->next()) { |
tschatzl@5862 | 521 | probe->verify(); |
tschatzl@5862 | 522 | element_count++; |
tschatzl@5862 | 523 | } |
tschatzl@5862 | 524 | } |
tschatzl@5862 | 525 | guarantee(number_of_entries() == element_count, |
tschatzl@5862 | 526 | "Verify of protection domain cache table failed"); |
tschatzl@5862 | 527 | debug_only(verify_lookup_length((double)number_of_entries() / table_size())); |
tschatzl@5862 | 528 | } |
tschatzl@5862 | 529 | |
tschatzl@5862 | 530 | void ProtectionDomainCacheEntry::verify() { |
tschatzl@5862 | 531 | guarantee(literal()->is_oop(), "must be an oop"); |
tschatzl@5862 | 532 | } |
tschatzl@5862 | 533 | |
tschatzl@5862 | 534 | void ProtectionDomainCacheTable::always_strong_oops_do(OopClosure* f) { |
tschatzl@5862 | 535 | // the caller marked the protection domain cache entries that we need to apply |
tschatzl@5862 | 536 | // the closure on. Only process them. |
tschatzl@5862 | 537 | for (int index = 0; index < table_size(); index++) { |
tschatzl@5862 | 538 | for (ProtectionDomainCacheEntry* probe = bucket(index); |
tschatzl@5862 | 539 | probe != NULL; |
tschatzl@5862 | 540 | probe = probe->next()) { |
tschatzl@5862 | 541 | if (probe->is_strongly_reachable()) { |
tschatzl@5862 | 542 | probe->reset_strongly_reachable(); |
tschatzl@5862 | 543 | probe->oops_do(f); |
tschatzl@5862 | 544 | } |
tschatzl@5862 | 545 | } |
tschatzl@5862 | 546 | } |
tschatzl@5862 | 547 | } |
tschatzl@5862 | 548 | |
tschatzl@5862 | 549 | ProtectionDomainCacheEntry* ProtectionDomainCacheTable::get(oop protection_domain) { |
tschatzl@5862 | 550 | unsigned int hash = compute_hash(protection_domain); |
tschatzl@5862 | 551 | int index = hash_to_index(hash); |
tschatzl@5862 | 552 | |
tschatzl@5862 | 553 | ProtectionDomainCacheEntry* entry = find_entry(index, protection_domain); |
tschatzl@5862 | 554 | if (entry == NULL) { |
tschatzl@5862 | 555 | entry = add_entry(index, hash, protection_domain); |
tschatzl@5862 | 556 | } |
tschatzl@5862 | 557 | return entry; |
tschatzl@5862 | 558 | } |
tschatzl@5862 | 559 | |
tschatzl@5862 | 560 | ProtectionDomainCacheEntry* ProtectionDomainCacheTable::find_entry(int index, oop protection_domain) { |
tschatzl@5862 | 561 | for (ProtectionDomainCacheEntry* e = bucket(index); e != NULL; e = e->next()) { |
tschatzl@5862 | 562 | if (e->protection_domain() == protection_domain) { |
tschatzl@5862 | 563 | return e; |
tschatzl@5862 | 564 | } |
tschatzl@5862 | 565 | } |
tschatzl@5862 | 566 | |
tschatzl@5862 | 567 | return NULL; |
tschatzl@5862 | 568 | } |
tschatzl@5862 | 569 | |
tschatzl@5862 | 570 | ProtectionDomainCacheEntry* ProtectionDomainCacheTable::add_entry(int index, unsigned int hash, oop protection_domain) { |
tschatzl@5862 | 571 | assert_locked_or_safepoint(SystemDictionary_lock); |
tschatzl@5862 | 572 | assert(index == index_for(protection_domain), "incorrect index?"); |
tschatzl@5862 | 573 | assert(find_entry(index, protection_domain) == NULL, "no double entry"); |
tschatzl@5862 | 574 | |
tschatzl@5862 | 575 | ProtectionDomainCacheEntry* p = new_entry(hash, protection_domain); |
tschatzl@5862 | 576 | Hashtable<oop, mtClass>::add_entry(index, p); |
tschatzl@5862 | 577 | return p; |
tschatzl@5862 | 578 | } |
tschatzl@5862 | 579 | |
tschatzl@5862 | 580 | void ProtectionDomainCacheTable::free(ProtectionDomainCacheEntry* to_delete) { |
tschatzl@5862 | 581 | unsigned int hash = compute_hash(to_delete->protection_domain()); |
tschatzl@5862 | 582 | int index = hash_to_index(hash); |
tschatzl@5862 | 583 | |
tschatzl@5862 | 584 | ProtectionDomainCacheEntry** p = bucket_addr(index); |
tschatzl@5862 | 585 | ProtectionDomainCacheEntry* entry = bucket(index); |
tschatzl@5862 | 586 | while (true) { |
tschatzl@5862 | 587 | assert(entry != NULL, "sanity"); |
tschatzl@5862 | 588 | |
tschatzl@5862 | 589 | if (entry == to_delete) { |
tschatzl@5862 | 590 | *p = entry->next(); |
tschatzl@5862 | 591 | Hashtable<oop, mtClass>::free_entry(entry); |
tschatzl@5862 | 592 | break; |
tschatzl@5862 | 593 | } else { |
tschatzl@5862 | 594 | p = entry->next_addr(); |
tschatzl@5862 | 595 | entry = *p; |
tschatzl@5862 | 596 | } |
tschatzl@5862 | 597 | } |
tschatzl@5862 | 598 | } |
tschatzl@5862 | 599 | |
jrose@1145 | 600 | SymbolPropertyTable::SymbolPropertyTable(int table_size) |
zgu@3900 | 601 | : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry)) |
jrose@1145 | 602 | { |
jrose@1145 | 603 | } |
zgu@3900 | 604 | SymbolPropertyTable::SymbolPropertyTable(int table_size, HashtableBucket<mtSymbol>* t, |
jrose@1145 | 605 | int number_of_entries) |
zgu@3900 | 606 | : Hashtable<Symbol*, mtSymbol>(table_size, sizeof(SymbolPropertyEntry), t, number_of_entries) |
jrose@1145 | 607 | { |
jrose@1145 | 608 | } |
jrose@1145 | 609 | |
jrose@1145 | 610 | |
jrose@1145 | 611 | SymbolPropertyEntry* SymbolPropertyTable::find_entry(int index, unsigned int hash, |
coleenp@2497 | 612 | Symbol* sym, |
jrose@1862 | 613 | intptr_t sym_mode) { |
jrose@1862 | 614 | assert(index == index_for(sym, sym_mode), "incorrect index?"); |
jrose@1145 | 615 | for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
coleenp@2497 | 616 | if (p->hash() == hash && p->symbol() == sym && p->symbol_mode() == sym_mode) { |
jrose@1145 | 617 | return p; |
jrose@1145 | 618 | } |
jrose@1145 | 619 | } |
jrose@1145 | 620 | return NULL; |
jrose@1145 | 621 | } |
jrose@1145 | 622 | |
jrose@1145 | 623 | |
jrose@1145 | 624 | SymbolPropertyEntry* SymbolPropertyTable::add_entry(int index, unsigned int hash, |
coleenp@2497 | 625 | Symbol* sym, intptr_t sym_mode) { |
jrose@1145 | 626 | assert_locked_or_safepoint(SystemDictionary_lock); |
jrose@1862 | 627 | assert(index == index_for(sym, sym_mode), "incorrect index?"); |
jrose@1862 | 628 | assert(find_entry(index, hash, sym, sym_mode) == NULL, "no double entry"); |
jrose@1145 | 629 | |
coleenp@2497 | 630 | SymbolPropertyEntry* p = new_entry(hash, sym, sym_mode); |
zgu@3900 | 631 | Hashtable<Symbol*, mtSymbol>::add_entry(index, p); |
jrose@1145 | 632 | return p; |
jrose@1145 | 633 | } |
jrose@1145 | 634 | |
jrose@1145 | 635 | void SymbolPropertyTable::oops_do(OopClosure* f) { |
jrose@1145 | 636 | for (int index = 0; index < table_size(); index++) { |
jrose@1145 | 637 | for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
coleenp@4037 | 638 | if (p->method_type() != NULL) { |
coleenp@4037 | 639 | f->do_oop(p->method_type_addr()); |
jrose@1145 | 640 | } |
jrose@1145 | 641 | } |
jrose@1145 | 642 | } |
jrose@1145 | 643 | } |
jrose@1145 | 644 | |
coleenp@4037 | 645 | void SymbolPropertyTable::methods_do(void f(Method*)) { |
jrose@1145 | 646 | for (int index = 0; index < table_size(); index++) { |
jrose@1145 | 647 | for (SymbolPropertyEntry* p = bucket(index); p != NULL; p = p->next()) { |
coleenp@4037 | 648 | Method* prop = p->method(); |
coleenp@4037 | 649 | if (prop != NULL) { |
coleenp@4037 | 650 | f((Method*)prop); |
jrose@1145 | 651 | } |
jrose@1145 | 652 | } |
jrose@1145 | 653 | } |
jrose@1145 | 654 | } |
jrose@1145 | 655 | |
duke@435 | 656 | |
duke@435 | 657 | // ---------------------------------------------------------------------------- |
duke@435 | 658 | #ifndef PRODUCT |
duke@435 | 659 | |
duke@435 | 660 | void Dictionary::print() { |
duke@435 | 661 | ResourceMark rm; |
duke@435 | 662 | HandleMark hm; |
duke@435 | 663 | |
acorn@3491 | 664 | tty->print_cr("Java system dictionary (table_size=%d, classes=%d)", |
acorn@3491 | 665 | table_size(), number_of_entries()); |
duke@435 | 666 | tty->print_cr("^ indicates that initiating loader is different from " |
duke@435 | 667 | "defining loader"); |
duke@435 | 668 | |
duke@435 | 669 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 670 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 671 | probe != NULL; |
duke@435 | 672 | probe = probe->next()) { |
duke@435 | 673 | if (Verbose) tty->print("%4d: ", index); |
coleenp@4037 | 674 | Klass* e = probe->klass(); |
coleenp@4037 | 675 | ClassLoaderData* loader_data = probe->loader_data(); |
duke@435 | 676 | bool is_defining_class = |
coleenp@4037 | 677 | (loader_data == InstanceKlass::cast(e)->class_loader_data()); |
duke@435 | 678 | tty->print("%s%s", is_defining_class ? " " : "^", |
hseigel@4278 | 679 | e->external_name()); |
coleenp@4037 | 680 | |
duke@435 | 681 | tty->print(", loader "); |
coleenp@4037 | 682 | loader_data->print_value(); |
duke@435 | 683 | tty->cr(); |
duke@435 | 684 | } |
duke@435 | 685 | } |
tschatzl@5862 | 686 | tty->cr(); |
tschatzl@5862 | 687 | _pd_cache_table->print(); |
tschatzl@5862 | 688 | tty->cr(); |
duke@435 | 689 | } |
duke@435 | 690 | |
duke@435 | 691 | #endif |
duke@435 | 692 | |
duke@435 | 693 | void Dictionary::verify() { |
duke@435 | 694 | guarantee(number_of_entries() >= 0, "Verify of system dictionary failed"); |
coleenp@4037 | 695 | |
duke@435 | 696 | int element_count = 0; |
duke@435 | 697 | for (int index = 0; index < table_size(); index++) { |
duke@435 | 698 | for (DictionaryEntry* probe = bucket(index); |
duke@435 | 699 | probe != NULL; |
duke@435 | 700 | probe = probe->next()) { |
coleenp@4037 | 701 | Klass* e = probe->klass(); |
coleenp@4037 | 702 | ClassLoaderData* loader_data = probe->loader_data(); |
hseigel@4278 | 703 | guarantee(e->oop_is_instance(), |
duke@435 | 704 | "Verify of system dictionary failed"); |
duke@435 | 705 | // class loader must be present; a null class loader is the |
duke@435 | 706 | // boostrap loader |
coleenp@4037 | 707 | guarantee(loader_data != NULL || DumpSharedSpaces || |
coleenp@4304 | 708 | loader_data->class_loader() == NULL || |
coleenp@4037 | 709 | loader_data->class_loader()->is_instance(), |
duke@435 | 710 | "checking type of class_loader"); |
coleenp@6316 | 711 | e->verify(); |
duke@435 | 712 | probe->verify_protection_domain_set(); |
duke@435 | 713 | element_count++; |
duke@435 | 714 | } |
duke@435 | 715 | } |
duke@435 | 716 | guarantee(number_of_entries() == element_count, |
duke@435 | 717 | "Verify of system dictionary failed"); |
duke@435 | 718 | debug_only(verify_lookup_length((double)number_of_entries() / table_size())); |
tschatzl@5862 | 719 | |
tschatzl@5862 | 720 | _pd_cache_table->verify(); |
duke@435 | 721 | } |
coleenp@4037 | 722 |