src/share/vm/classfile/dictionary.cpp

Thu, 14 Jun 2018 09:15:08 -0700

author
kevinw
date
Thu, 14 Jun 2018 09:15:08 -0700
changeset 9327
f96fcd9e1e1b
parent 8497
50e62b688ddc
child 9448
73d689add964
child 9530
9fce84e6f51a
permissions
-rw-r--r--

8081202: Hotspot compile warning: "Invalid suffix on literal; C++11 requires a space between literal and identifier"
Summary: Need to add a space between macro identifier and string literal
Reviewed-by: bpittore, stefank, dholmes, kbarrett

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

mercurial