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