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