src/share/vm/classfile/dictionary.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6680
78bbf4d43a14
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial