Fri, 27 Feb 2009 13:27:09 -0800
6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never
duke@435 | 1 | /* |
xdono@631 | 2 | * Copyright 1997-2008 Sun Microsystems, Inc. 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 | * |
duke@435 | 19 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
duke@435 | 20 | * CA 95054 USA or visit www.sun.com if you need additional information or |
duke@435 | 21 | * have any questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
duke@435 | 25 | # include "incls/_precompiled.incl" |
duke@435 | 26 | # include "incls/_systemDictionary.cpp.incl" |
duke@435 | 27 | |
duke@435 | 28 | |
duke@435 | 29 | Dictionary* SystemDictionary::_dictionary = NULL; |
duke@435 | 30 | PlaceholderTable* SystemDictionary::_placeholders = NULL; |
duke@435 | 31 | Dictionary* SystemDictionary::_shared_dictionary = NULL; |
duke@435 | 32 | LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL; |
duke@435 | 33 | ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL; |
duke@435 | 34 | |
duke@435 | 35 | |
duke@435 | 36 | int SystemDictionary::_number_of_modifications = 0; |
duke@435 | 37 | |
duke@435 | 38 | oop SystemDictionary::_system_loader_lock_obj = NULL; |
duke@435 | 39 | |
jrose@567 | 40 | klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT] |
jrose@567 | 41 | = { NULL /*, NULL...*/ }; |
duke@435 | 42 | |
duke@435 | 43 | klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ }; |
duke@435 | 44 | |
duke@435 | 45 | oop SystemDictionary::_java_system_loader = NULL; |
duke@435 | 46 | |
duke@435 | 47 | bool SystemDictionary::_has_loadClassInternal = false; |
duke@435 | 48 | bool SystemDictionary::_has_checkPackageAccess = false; |
duke@435 | 49 | |
duke@435 | 50 | // lazily initialized klass variables |
duke@435 | 51 | volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL; |
duke@435 | 52 | |
duke@435 | 53 | |
duke@435 | 54 | // ---------------------------------------------------------------------------- |
duke@435 | 55 | // Java-level SystemLoader |
duke@435 | 56 | |
duke@435 | 57 | oop SystemDictionary::java_system_loader() { |
duke@435 | 58 | return _java_system_loader; |
duke@435 | 59 | } |
duke@435 | 60 | |
duke@435 | 61 | void SystemDictionary::compute_java_system_loader(TRAPS) { |
jrose@567 | 62 | KlassHandle system_klass(THREAD, WK_KLASS(classloader_klass)); |
duke@435 | 63 | JavaValue result(T_OBJECT); |
duke@435 | 64 | JavaCalls::call_static(&result, |
jrose@567 | 65 | KlassHandle(THREAD, WK_KLASS(classloader_klass)), |
duke@435 | 66 | vmSymbolHandles::getSystemClassLoader_name(), |
duke@435 | 67 | vmSymbolHandles::void_classloader_signature(), |
duke@435 | 68 | CHECK); |
duke@435 | 69 | |
duke@435 | 70 | _java_system_loader = (oop)result.get_jobject(); |
duke@435 | 71 | } |
duke@435 | 72 | |
duke@435 | 73 | |
duke@435 | 74 | // ---------------------------------------------------------------------------- |
duke@435 | 75 | // debugging |
duke@435 | 76 | |
duke@435 | 77 | #ifdef ASSERT |
duke@435 | 78 | |
duke@435 | 79 | // return true if class_name contains no '.' (internal format is '/') |
duke@435 | 80 | bool SystemDictionary::is_internal_format(symbolHandle class_name) { |
duke@435 | 81 | if (class_name.not_null()) { |
duke@435 | 82 | ResourceMark rm; |
duke@435 | 83 | char* name = class_name->as_C_string(); |
duke@435 | 84 | return strchr(name, '.') == NULL; |
duke@435 | 85 | } else { |
duke@435 | 86 | return true; |
duke@435 | 87 | } |
duke@435 | 88 | } |
duke@435 | 89 | |
duke@435 | 90 | #endif |
duke@435 | 91 | |
duke@435 | 92 | // ---------------------------------------------------------------------------- |
acorn@949 | 93 | // Parallel class loading check |
acorn@949 | 94 | |
acorn@949 | 95 | bool SystemDictionary::is_parallelCapable(Handle class_loader) { |
acorn@949 | 96 | if (UnsyncloadClass || class_loader.is_null()) return true; |
acorn@949 | 97 | if (AlwaysLockClassLoader) return false; |
acorn@949 | 98 | return java_lang_Class::parallelCapable(class_loader()); |
acorn@949 | 99 | } |
acorn@949 | 100 | // ---------------------------------------------------------------------------- |
duke@435 | 101 | // Resolving of classes |
duke@435 | 102 | |
duke@435 | 103 | // Forwards to resolve_or_null |
duke@435 | 104 | |
duke@435 | 105 | klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) { |
duke@435 | 106 | klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD); |
duke@435 | 107 | if (HAS_PENDING_EXCEPTION || klass == NULL) { |
duke@435 | 108 | KlassHandle k_h(THREAD, klass); |
duke@435 | 109 | // can return a null klass |
duke@435 | 110 | klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD); |
duke@435 | 111 | } |
duke@435 | 112 | return klass; |
duke@435 | 113 | } |
duke@435 | 114 | |
duke@435 | 115 | klassOop SystemDictionary::handle_resolution_exception(symbolHandle class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) { |
duke@435 | 116 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 117 | // If we have a pending exception we forward it to the caller, unless throw_error is true, |
duke@435 | 118 | // in which case we have to check whether the pending exception is a ClassNotFoundException, |
duke@435 | 119 | // and if so convert it to a NoClassDefFoundError |
duke@435 | 120 | // And chain the original ClassNotFoundException |
duke@435 | 121 | if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::classNotFoundException_klass())) { |
duke@435 | 122 | ResourceMark rm(THREAD); |
duke@435 | 123 | assert(klass_h() == NULL, "Should not have result with exception pending"); |
duke@435 | 124 | Handle e(THREAD, PENDING_EXCEPTION); |
duke@435 | 125 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 126 | THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e); |
duke@435 | 127 | } else { |
duke@435 | 128 | return NULL; |
duke@435 | 129 | } |
duke@435 | 130 | } |
duke@435 | 131 | // Class not found, throw appropriate error or exception depending on value of throw_error |
duke@435 | 132 | if (klass_h() == NULL) { |
duke@435 | 133 | ResourceMark rm(THREAD); |
duke@435 | 134 | if (throw_error) { |
duke@435 | 135 | THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string()); |
duke@435 | 136 | } else { |
duke@435 | 137 | THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string()); |
duke@435 | 138 | } |
duke@435 | 139 | } |
duke@435 | 140 | return (klassOop)klass_h(); |
duke@435 | 141 | } |
duke@435 | 142 | |
duke@435 | 143 | |
duke@435 | 144 | klassOop SystemDictionary::resolve_or_fail(symbolHandle class_name, |
duke@435 | 145 | bool throw_error, TRAPS) |
duke@435 | 146 | { |
duke@435 | 147 | return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD); |
duke@435 | 148 | } |
duke@435 | 149 | |
duke@435 | 150 | |
duke@435 | 151 | // Forwards to resolve_instance_class_or_null |
duke@435 | 152 | |
duke@435 | 153 | klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { |
duke@435 | 154 | assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread"); |
duke@435 | 155 | if (FieldType::is_array(class_name())) { |
duke@435 | 156 | return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
duke@435 | 157 | } else { |
duke@435 | 158 | return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL); |
duke@435 | 159 | } |
duke@435 | 160 | } |
duke@435 | 161 | |
duke@435 | 162 | klassOop SystemDictionary::resolve_or_null(symbolHandle class_name, TRAPS) { |
duke@435 | 163 | return resolve_or_null(class_name, Handle(), Handle(), THREAD); |
duke@435 | 164 | } |
duke@435 | 165 | |
duke@435 | 166 | // Forwards to resolve_instance_class_or_null |
duke@435 | 167 | |
duke@435 | 168 | klassOop SystemDictionary::resolve_array_class_or_null(symbolHandle class_name, |
duke@435 | 169 | Handle class_loader, |
duke@435 | 170 | Handle protection_domain, |
duke@435 | 171 | TRAPS) { |
duke@435 | 172 | assert(FieldType::is_array(class_name()), "must be array"); |
duke@435 | 173 | jint dimension; |
duke@435 | 174 | symbolOop object_key; |
duke@435 | 175 | klassOop k = NULL; |
duke@435 | 176 | // dimension and object_key are assigned as a side-effect of this call |
duke@435 | 177 | BasicType t = FieldType::get_array_info(class_name(), |
duke@435 | 178 | &dimension, |
duke@435 | 179 | &object_key, |
duke@435 | 180 | CHECK_NULL); |
duke@435 | 181 | |
duke@435 | 182 | if (t == T_OBJECT) { |
duke@435 | 183 | symbolHandle h_key(THREAD, object_key); |
duke@435 | 184 | // naked oop "k" is OK here -- we assign back into it |
duke@435 | 185 | k = SystemDictionary::resolve_instance_class_or_null(h_key, |
duke@435 | 186 | class_loader, |
duke@435 | 187 | protection_domain, |
duke@435 | 188 | CHECK_NULL); |
duke@435 | 189 | if (k != NULL) { |
duke@435 | 190 | k = Klass::cast(k)->array_klass(dimension, CHECK_NULL); |
duke@435 | 191 | } |
duke@435 | 192 | } else { |
duke@435 | 193 | k = Universe::typeArrayKlassObj(t); |
duke@435 | 194 | k = typeArrayKlass::cast(k)->array_klass(dimension, CHECK_NULL); |
duke@435 | 195 | } |
duke@435 | 196 | return k; |
duke@435 | 197 | } |
duke@435 | 198 | |
duke@435 | 199 | |
duke@435 | 200 | // Must be called for any super-class or super-interface resolution |
duke@435 | 201 | // during class definition to allow class circularity checking |
duke@435 | 202 | // super-interface callers: |
duke@435 | 203 | // parse_interfaces - for defineClass & jvmtiRedefineClasses |
duke@435 | 204 | // super-class callers: |
duke@435 | 205 | // ClassFileParser - for defineClass & jvmtiRedefineClasses |
duke@435 | 206 | // load_shared_class - while loading a class from shared archive |
acorn@949 | 207 | // resolve_instance_class_or_null: |
acorn@949 | 208 | // via: handle_parallel_super_load |
duke@435 | 209 | // when resolving a class that has an existing placeholder with |
duke@435 | 210 | // a saved superclass [i.e. a defineClass is currently in progress] |
duke@435 | 211 | // if another thread is trying to resolve the class, it must do |
duke@435 | 212 | // super-class checks on its own thread to catch class circularity |
duke@435 | 213 | // This last call is critical in class circularity checking for cases |
duke@435 | 214 | // where classloading is delegated to different threads and the |
duke@435 | 215 | // classloader lock is released. |
duke@435 | 216 | // Take the case: Base->Super->Base |
duke@435 | 217 | // 1. If thread T1 tries to do a defineClass of class Base |
duke@435 | 218 | // resolve_super_or_fail creates placeholder: T1, Base (super Super) |
duke@435 | 219 | // 2. resolve_instance_class_or_null does not find SD or placeholder for Super |
duke@435 | 220 | // so it tries to load Super |
duke@435 | 221 | // 3. If we load the class internally, or user classloader uses same thread |
duke@435 | 222 | // loadClassFromxxx or defineClass via parseClassFile Super ... |
duke@435 | 223 | // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base) |
duke@435 | 224 | // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base |
duke@435 | 225 | // 3.4 calls resolve_super_or_fail Base |
duke@435 | 226 | // 3.5 finds T1,Base -> throws class circularity |
duke@435 | 227 | //OR 4. If T2 tries to resolve Super via defineClass Super ... |
duke@435 | 228 | // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base) |
duke@435 | 229 | // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super) |
duke@435 | 230 | // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 |
duke@435 | 231 | // 4.4 finds T2, Super -> throws class circularity |
duke@435 | 232 | // Must be called, even if superclass is null, since this is |
duke@435 | 233 | // where the placeholder entry is created which claims this |
duke@435 | 234 | // thread is loading this class/classloader. |
duke@435 | 235 | klassOop SystemDictionary::resolve_super_or_fail(symbolHandle child_name, |
duke@435 | 236 | symbolHandle class_name, |
duke@435 | 237 | Handle class_loader, |
duke@435 | 238 | Handle protection_domain, |
duke@435 | 239 | bool is_superclass, |
duke@435 | 240 | TRAPS) { |
duke@435 | 241 | |
jrose@567 | 242 | // Try to get one of the well-known klasses. |
jrose@567 | 243 | // They are trusted, and do not participate in circularities. |
jrose@567 | 244 | if (LinkWellKnownClasses) { |
jrose@567 | 245 | klassOop k = find_well_known_klass(class_name()); |
jrose@567 | 246 | if (k != NULL) { |
jrose@567 | 247 | return k; |
jrose@567 | 248 | } |
jrose@567 | 249 | } |
jrose@567 | 250 | |
duke@435 | 251 | // Double-check, if child class is already loaded, just return super-class,interface |
duke@435 | 252 | // Don't add a placedholder if already loaded, i.e. already in system dictionary |
duke@435 | 253 | // Make sure there's a placeholder for the *child* before resolving. |
duke@435 | 254 | // Used as a claim that this thread is currently loading superclass/classloader |
duke@435 | 255 | // Used here for ClassCircularity checks and also for heap verification |
duke@435 | 256 | // (every instanceKlass in the heap needs to be in the system dictionary |
duke@435 | 257 | // or have a placeholder). |
duke@435 | 258 | // Must check ClassCircularity before checking if super class is already loaded |
duke@435 | 259 | // |
duke@435 | 260 | // We might not already have a placeholder if this child_name was |
duke@435 | 261 | // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); |
duke@435 | 262 | // the name of the class might not be known until the stream is actually |
duke@435 | 263 | // parsed. |
duke@435 | 264 | // Bugs 4643874, 4715493 |
duke@435 | 265 | // compute_hash can have a safepoint |
duke@435 | 266 | |
duke@435 | 267 | unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader); |
duke@435 | 268 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 269 | unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader); |
duke@435 | 270 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 271 | // can't throw error holding a lock |
duke@435 | 272 | bool child_already_loaded = false; |
duke@435 | 273 | bool throw_circularity_error = false; |
duke@435 | 274 | { |
duke@435 | 275 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 276 | klassOop childk = find_class(d_index, d_hash, child_name, class_loader); |
duke@435 | 277 | klassOop quicksuperk; |
duke@435 | 278 | // to support // loading: if child done loading, just return superclass |
duke@435 | 279 | // if class_name, & class_loader don't match: |
duke@435 | 280 | // if initial define, SD update will give LinkageError |
duke@435 | 281 | // if redefine: compare_class_versions will give HIERARCHY_CHANGED |
duke@435 | 282 | // so we don't throw an exception here. |
duke@435 | 283 | // see: nsk redefclass014 & java.lang.instrument Instrument032 |
duke@435 | 284 | if ((childk != NULL ) && (is_superclass) && |
duke@435 | 285 | ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) && |
duke@435 | 286 | |
duke@435 | 287 | ((Klass::cast(quicksuperk)->name() == class_name()) && |
duke@435 | 288 | (Klass::cast(quicksuperk)->class_loader() == class_loader()))) { |
duke@435 | 289 | return quicksuperk; |
duke@435 | 290 | } else { |
duke@435 | 291 | PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); |
duke@435 | 292 | if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) { |
duke@435 | 293 | throw_circularity_error = true; |
duke@435 | 294 | } |
acorn@949 | 295 | } |
acorn@949 | 296 | if (!throw_circularity_error) { |
duke@435 | 297 | PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD); |
duke@435 | 298 | } |
duke@435 | 299 | } |
duke@435 | 300 | if (throw_circularity_error) { |
duke@435 | 301 | ResourceMark rm(THREAD); |
duke@435 | 302 | THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string()); |
duke@435 | 303 | } |
duke@435 | 304 | |
duke@435 | 305 | // java.lang.Object should have been found above |
duke@435 | 306 | assert(class_name() != NULL, "null super class for resolving"); |
duke@435 | 307 | // Resolve the super class or interface, check results on return |
duke@435 | 308 | klassOop superk = NULL; |
duke@435 | 309 | superk = SystemDictionary::resolve_or_null(class_name, |
duke@435 | 310 | class_loader, |
duke@435 | 311 | protection_domain, |
duke@435 | 312 | THREAD); |
duke@435 | 313 | |
duke@435 | 314 | KlassHandle superk_h(THREAD, superk); |
duke@435 | 315 | |
duke@435 | 316 | // Note: clean up of placeholders currently in callers of |
duke@435 | 317 | // resolve_super_or_fail - either at update_dictionary time |
duke@435 | 318 | // or on error |
duke@435 | 319 | { |
duke@435 | 320 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 321 | PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader); |
duke@435 | 322 | if (probe != NULL) { |
duke@435 | 323 | probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER); |
duke@435 | 324 | } |
duke@435 | 325 | } |
duke@435 | 326 | if (HAS_PENDING_EXCEPTION || superk_h() == NULL) { |
duke@435 | 327 | // can null superk |
duke@435 | 328 | superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD)); |
duke@435 | 329 | } |
duke@435 | 330 | |
duke@435 | 331 | return superk_h(); |
duke@435 | 332 | } |
duke@435 | 333 | |
duke@435 | 334 | void SystemDictionary::validate_protection_domain(instanceKlassHandle klass, |
duke@435 | 335 | Handle class_loader, |
duke@435 | 336 | Handle protection_domain, |
duke@435 | 337 | TRAPS) { |
duke@435 | 338 | if(!has_checkPackageAccess()) return; |
duke@435 | 339 | |
duke@435 | 340 | // Now we have to call back to java to check if the initating class has access |
duke@435 | 341 | JavaValue result(T_VOID); |
duke@435 | 342 | if (TraceProtectionDomainVerification) { |
duke@435 | 343 | // Print out trace information |
duke@435 | 344 | tty->print_cr("Checking package access"); |
duke@435 | 345 | tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); |
duke@435 | 346 | tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); |
duke@435 | 347 | tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); |
duke@435 | 348 | } |
duke@435 | 349 | |
duke@435 | 350 | assert(class_loader() != NULL, "should not have non-null protection domain for null classloader"); |
duke@435 | 351 | |
duke@435 | 352 | KlassHandle system_loader(THREAD, SystemDictionary::classloader_klass()); |
duke@435 | 353 | JavaCalls::call_special(&result, |
duke@435 | 354 | class_loader, |
duke@435 | 355 | system_loader, |
duke@435 | 356 | vmSymbolHandles::checkPackageAccess_name(), |
duke@435 | 357 | vmSymbolHandles::class_protectiondomain_signature(), |
duke@435 | 358 | Handle(THREAD, klass->java_mirror()), |
duke@435 | 359 | protection_domain, |
duke@435 | 360 | THREAD); |
duke@435 | 361 | |
duke@435 | 362 | if (TraceProtectionDomainVerification) { |
duke@435 | 363 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 364 | tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!"); |
duke@435 | 365 | } else { |
duke@435 | 366 | tty->print_cr(" -> granted"); |
duke@435 | 367 | } |
duke@435 | 368 | tty->cr(); |
duke@435 | 369 | } |
duke@435 | 370 | |
duke@435 | 371 | if (HAS_PENDING_EXCEPTION) return; |
duke@435 | 372 | |
duke@435 | 373 | // If no exception has been thrown, we have validated the protection domain |
duke@435 | 374 | // Insert the protection domain of the initiating class into the set. |
duke@435 | 375 | { |
duke@435 | 376 | // We recalculate the entry here -- we've called out to java since |
duke@435 | 377 | // the last time it was calculated. |
duke@435 | 378 | symbolHandle kn(THREAD, klass->name()); |
duke@435 | 379 | unsigned int d_hash = dictionary()->compute_hash(kn, class_loader); |
duke@435 | 380 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 381 | |
duke@435 | 382 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 383 | { |
duke@435 | 384 | // Note that we have an entry, and entries can be deleted only during GC, |
duke@435 | 385 | // so we cannot allow GC to occur while we're holding this entry. |
duke@435 | 386 | |
duke@435 | 387 | // We're using a No_Safepoint_Verifier to catch any place where we |
duke@435 | 388 | // might potentially do a GC at all. |
duke@435 | 389 | // SystemDictionary::do_unloading() asserts that classes are only |
duke@435 | 390 | // unloaded at a safepoint. |
duke@435 | 391 | No_Safepoint_Verifier nosafepoint; |
duke@435 | 392 | dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader, |
duke@435 | 393 | protection_domain, THREAD); |
duke@435 | 394 | } |
duke@435 | 395 | } |
duke@435 | 396 | } |
duke@435 | 397 | |
duke@435 | 398 | // We only get here if this thread finds that another thread |
duke@435 | 399 | // has already claimed the placeholder token for the current operation, |
duke@435 | 400 | // but that other thread either never owned or gave up the |
duke@435 | 401 | // object lock |
duke@435 | 402 | // Waits on SystemDictionary_lock to indicate placeholder table updated |
duke@435 | 403 | // On return, caller must recheck placeholder table state |
duke@435 | 404 | // |
duke@435 | 405 | // We only get here if |
duke@435 | 406 | // 1) custom classLoader, i.e. not bootstrap classloader |
duke@435 | 407 | // 2) UnsyncloadClass not set |
duke@435 | 408 | // 3) custom classLoader has broken the class loader objectLock |
duke@435 | 409 | // so another thread got here in parallel |
duke@435 | 410 | // |
duke@435 | 411 | // lockObject must be held. |
duke@435 | 412 | // Complicated dance due to lock ordering: |
duke@435 | 413 | // Must first release the classloader object lock to |
duke@435 | 414 | // allow initial definer to complete the class definition |
duke@435 | 415 | // and to avoid deadlock |
duke@435 | 416 | // Reclaim classloader lock object with same original recursion count |
duke@435 | 417 | // Must release SystemDictionary_lock after notify, since |
duke@435 | 418 | // class loader lock must be claimed before SystemDictionary_lock |
duke@435 | 419 | // to prevent deadlocks |
duke@435 | 420 | // |
duke@435 | 421 | // The notify allows applications that did an untimed wait() on |
duke@435 | 422 | // the classloader object lock to not hang. |
duke@435 | 423 | void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) { |
duke@435 | 424 | assert_lock_strong(SystemDictionary_lock); |
duke@435 | 425 | |
duke@435 | 426 | bool calledholdinglock |
duke@435 | 427 | = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject); |
duke@435 | 428 | assert(calledholdinglock,"must hold lock for notify"); |
acorn@949 | 429 | assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait"); |
duke@435 | 430 | ObjectSynchronizer::notifyall(lockObject, THREAD); |
duke@435 | 431 | intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD); |
duke@435 | 432 | SystemDictionary_lock->wait(); |
duke@435 | 433 | SystemDictionary_lock->unlock(); |
duke@435 | 434 | ObjectSynchronizer::reenter(lockObject, recursions, THREAD); |
duke@435 | 435 | SystemDictionary_lock->lock(); |
duke@435 | 436 | } |
duke@435 | 437 | |
duke@435 | 438 | // If the class in is in the placeholder table, class loading is in progress |
duke@435 | 439 | // For cases where the application changes threads to load classes, it |
duke@435 | 440 | // is critical to ClassCircularity detection that we try loading |
duke@435 | 441 | // the superclass on the same thread internally, so we do parallel |
duke@435 | 442 | // super class loading here. |
duke@435 | 443 | // This also is critical in cases where the original thread gets stalled |
duke@435 | 444 | // even in non-circularity situations. |
duke@435 | 445 | // Note: only one thread can define the class, but multiple can resolve |
duke@435 | 446 | // Note: must call resolve_super_or_fail even if null super - |
acorn@949 | 447 | // to force placeholder entry creation for this class for circularity detection |
duke@435 | 448 | // Caller must check for pending exception |
duke@435 | 449 | // Returns non-null klassOop if other thread has completed load |
duke@435 | 450 | // and we are done, |
duke@435 | 451 | // If return null klassOop and no pending exception, the caller must load the class |
duke@435 | 452 | instanceKlassHandle SystemDictionary::handle_parallel_super_load( |
duke@435 | 453 | symbolHandle name, symbolHandle superclassname, Handle class_loader, |
duke@435 | 454 | Handle protection_domain, Handle lockObject, TRAPS) { |
duke@435 | 455 | |
duke@435 | 456 | instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
duke@435 | 457 | unsigned int d_hash = dictionary()->compute_hash(name, class_loader); |
duke@435 | 458 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 459 | unsigned int p_hash = placeholders()->compute_hash(name, class_loader); |
duke@435 | 460 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 461 | |
duke@435 | 462 | // superk is not used, resolve_super called for circularity check only |
duke@435 | 463 | // This code is reached in two situations. One if this thread |
duke@435 | 464 | // is loading the same class twice (e.g. ClassCircularity, or |
duke@435 | 465 | // java.lang.instrument). |
duke@435 | 466 | // The second is if another thread started the resolve_super first |
duke@435 | 467 | // and has not yet finished. |
duke@435 | 468 | // In both cases the original caller will clean up the placeholder |
duke@435 | 469 | // entry on error. |
duke@435 | 470 | klassOop superk = SystemDictionary::resolve_super_or_fail(name, |
duke@435 | 471 | superclassname, |
duke@435 | 472 | class_loader, |
duke@435 | 473 | protection_domain, |
duke@435 | 474 | true, |
duke@435 | 475 | CHECK_(nh)); |
duke@435 | 476 | // We don't redefine the class, so we just need to clean up if there |
duke@435 | 477 | // was not an error (don't want to modify any system dictionary |
duke@435 | 478 | // data structures). |
duke@435 | 479 | { |
duke@435 | 480 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 481 | placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
duke@435 | 482 | SystemDictionary_lock->notify_all(); |
duke@435 | 483 | } |
duke@435 | 484 | |
acorn@949 | 485 | // parallelCapable class loaders do NOT wait for parallel superclass loads to complete |
acorn@949 | 486 | // Serial class loaders and bootstrap classloader do wait for superclass loads |
acorn@949 | 487 | if (!class_loader.is_null() && is_parallelCapable(class_loader)) { |
duke@435 | 488 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 489 | // Check if classloading completed while we were loading superclass or waiting |
duke@435 | 490 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 491 | if (check != NULL) { |
duke@435 | 492 | // Klass is already loaded, so just return it |
duke@435 | 493 | return(instanceKlassHandle(THREAD, check)); |
duke@435 | 494 | } else { |
duke@435 | 495 | return nh; |
duke@435 | 496 | } |
duke@435 | 497 | } |
duke@435 | 498 | |
duke@435 | 499 | // must loop to both handle other placeholder updates |
duke@435 | 500 | // and spurious notifications |
duke@435 | 501 | bool super_load_in_progress = true; |
duke@435 | 502 | PlaceholderEntry* placeholder; |
duke@435 | 503 | while (super_load_in_progress) { |
duke@435 | 504 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 505 | // Check if classloading completed while we were loading superclass or waiting |
duke@435 | 506 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 507 | if (check != NULL) { |
duke@435 | 508 | // Klass is already loaded, so just return it |
duke@435 | 509 | return(instanceKlassHandle(THREAD, check)); |
duke@435 | 510 | } else { |
duke@435 | 511 | placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
duke@435 | 512 | if (placeholder && placeholder->super_load_in_progress() ){ |
duke@435 | 513 | // Before UnsyncloadClass: |
duke@435 | 514 | // We only get here if the application has released the |
duke@435 | 515 | // classloader lock when another thread was in the middle of loading a |
duke@435 | 516 | // superclass/superinterface for this class, and now |
duke@435 | 517 | // this thread is also trying to load this class. |
duke@435 | 518 | // To minimize surprises, the first thread that started to |
duke@435 | 519 | // load a class should be the one to complete the loading |
duke@435 | 520 | // with the classfile it initially expected. |
duke@435 | 521 | // This logic has the current thread wait once it has done |
duke@435 | 522 | // all the superclass/superinterface loading it can, until |
duke@435 | 523 | // the original thread completes the class loading or fails |
duke@435 | 524 | // If it completes we will use the resulting instanceKlass |
duke@435 | 525 | // which we will find below in the systemDictionary. |
duke@435 | 526 | // We also get here for parallel bootstrap classloader |
duke@435 | 527 | if (class_loader.is_null()) { |
duke@435 | 528 | SystemDictionary_lock->wait(); |
duke@435 | 529 | } else { |
duke@435 | 530 | double_lock_wait(lockObject, THREAD); |
duke@435 | 531 | } |
duke@435 | 532 | } else { |
duke@435 | 533 | // If not in SD and not in PH, other thread's load must have failed |
duke@435 | 534 | super_load_in_progress = false; |
duke@435 | 535 | } |
duke@435 | 536 | } |
duke@435 | 537 | } |
duke@435 | 538 | return (nh); |
duke@435 | 539 | } |
duke@435 | 540 | |
duke@435 | 541 | |
duke@435 | 542 | klassOop SystemDictionary::resolve_instance_class_or_null(symbolHandle class_name, Handle class_loader, Handle protection_domain, TRAPS) { |
duke@435 | 543 | assert(class_name.not_null() && !FieldType::is_array(class_name()), "invalid class name"); |
duke@435 | 544 | // First check to see if we should remove wrapping L and ; |
duke@435 | 545 | symbolHandle name; |
duke@435 | 546 | if (FieldType::is_obj(class_name())) { |
duke@435 | 547 | ResourceMark rm(THREAD); |
duke@435 | 548 | // Ignore wrapping L and ;. |
duke@435 | 549 | name = oopFactory::new_symbol_handle(class_name()->as_C_string() + 1, class_name()->utf8_length() - 2, CHECK_NULL); |
duke@435 | 550 | } else { |
duke@435 | 551 | name = class_name; |
duke@435 | 552 | } |
duke@435 | 553 | |
duke@435 | 554 | // UseNewReflection |
duke@435 | 555 | // Fix for 4474172; see evaluation for more details |
duke@435 | 556 | class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
duke@435 | 557 | |
duke@435 | 558 | // Do lookup to see if class already exist and the protection domain |
duke@435 | 559 | // has the right access |
duke@435 | 560 | unsigned int d_hash = dictionary()->compute_hash(name, class_loader); |
duke@435 | 561 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 562 | klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader, |
duke@435 | 563 | protection_domain, THREAD); |
duke@435 | 564 | if (probe != NULL) return probe; |
duke@435 | 565 | |
duke@435 | 566 | |
duke@435 | 567 | // Non-bootstrap class loaders will call out to class loader and |
duke@435 | 568 | // define via jvm/jni_DefineClass which will acquire the |
duke@435 | 569 | // class loader object lock to protect against multiple threads |
duke@435 | 570 | // defining the class in parallel by accident. |
duke@435 | 571 | // This lock must be acquired here so the waiter will find |
duke@435 | 572 | // any successful result in the SystemDictionary and not attempt |
duke@435 | 573 | // the define |
acorn@949 | 574 | // ParallelCapable Classloaders and the bootstrap classloader, |
duke@435 | 575 | // or all classloaders with UnsyncloadClass do not acquire lock here |
duke@435 | 576 | bool DoObjectLock = true; |
acorn@949 | 577 | if (is_parallelCapable(class_loader)) { |
duke@435 | 578 | DoObjectLock = false; |
duke@435 | 579 | } |
duke@435 | 580 | |
duke@435 | 581 | unsigned int p_hash = placeholders()->compute_hash(name, class_loader); |
duke@435 | 582 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 583 | |
duke@435 | 584 | // Class is not in SystemDictionary so we have to do loading. |
duke@435 | 585 | // Make sure we are synchronized on the class loader before we proceed |
duke@435 | 586 | Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
duke@435 | 587 | check_loader_lock_contention(lockObject, THREAD); |
duke@435 | 588 | ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
duke@435 | 589 | |
duke@435 | 590 | // Check again (after locking) if class already exist in SystemDictionary |
duke@435 | 591 | bool class_has_been_loaded = false; |
duke@435 | 592 | bool super_load_in_progress = false; |
duke@435 | 593 | bool havesupername = false; |
duke@435 | 594 | instanceKlassHandle k; |
duke@435 | 595 | PlaceholderEntry* placeholder; |
duke@435 | 596 | symbolHandle superclassname; |
duke@435 | 597 | |
duke@435 | 598 | { |
duke@435 | 599 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 600 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 601 | if (check != NULL) { |
duke@435 | 602 | // Klass is already loaded, so just return it |
duke@435 | 603 | class_has_been_loaded = true; |
duke@435 | 604 | k = instanceKlassHandle(THREAD, check); |
duke@435 | 605 | } else { |
duke@435 | 606 | placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
duke@435 | 607 | if (placeholder && placeholder->super_load_in_progress()) { |
duke@435 | 608 | super_load_in_progress = true; |
duke@435 | 609 | if (placeholder->havesupername() == true) { |
duke@435 | 610 | superclassname = symbolHandle(THREAD, placeholder->supername()); |
duke@435 | 611 | havesupername = true; |
duke@435 | 612 | } |
duke@435 | 613 | } |
duke@435 | 614 | } |
duke@435 | 615 | } |
duke@435 | 616 | |
duke@435 | 617 | // If the class in is in the placeholder table, class loading is in progress |
duke@435 | 618 | if (super_load_in_progress && havesupername==true) { |
duke@435 | 619 | k = SystemDictionary::handle_parallel_super_load(name, superclassname, |
duke@435 | 620 | class_loader, protection_domain, lockObject, THREAD); |
duke@435 | 621 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 622 | return NULL; |
duke@435 | 623 | } |
duke@435 | 624 | if (!k.is_null()) { |
duke@435 | 625 | class_has_been_loaded = true; |
duke@435 | 626 | } |
duke@435 | 627 | } |
duke@435 | 628 | |
duke@435 | 629 | if (!class_has_been_loaded) { |
duke@435 | 630 | |
duke@435 | 631 | // add placeholder entry to record loading instance class |
duke@435 | 632 | // Five cases: |
duke@435 | 633 | // All cases need to prevent modifying bootclasssearchpath |
duke@435 | 634 | // in parallel with a classload of same classname |
acorn@949 | 635 | // Redefineclasses uses existence of the placeholder for the duration |
acorn@949 | 636 | // of the class load to prevent concurrent redefinition of not completely |
acorn@949 | 637 | // defined classes. |
duke@435 | 638 | // case 1. traditional classloaders that rely on the classloader object lock |
duke@435 | 639 | // - no other need for LOAD_INSTANCE |
duke@435 | 640 | // case 2. traditional classloaders that break the classloader object lock |
duke@435 | 641 | // as a deadlock workaround. Detection of this case requires that |
duke@435 | 642 | // this check is done while holding the classloader object lock, |
duke@435 | 643 | // and that lock is still held when calling classloader's loadClass. |
duke@435 | 644 | // For these classloaders, we ensure that the first requestor |
duke@435 | 645 | // completes the load and other requestors wait for completion. |
duke@435 | 646 | // case 3. UnsyncloadClass - don't use objectLocker |
duke@435 | 647 | // With this flag, we allow parallel classloading of a |
duke@435 | 648 | // class/classloader pair |
duke@435 | 649 | // case4. Bootstrap classloader - don't own objectLocker |
duke@435 | 650 | // This classloader supports parallelism at the classloader level, |
duke@435 | 651 | // but only allows a single load of a class/classloader pair. |
duke@435 | 652 | // No performance benefit and no deadlock issues. |
acorn@949 | 653 | // case 5. parallelCapable user level classloaders - without objectLocker |
acorn@949 | 654 | // Allow parallel classloading of a class/classloader pair |
duke@435 | 655 | symbolHandle nullsymbolHandle; |
duke@435 | 656 | bool throw_circularity_error = false; |
duke@435 | 657 | { |
duke@435 | 658 | MutexLocker mu(SystemDictionary_lock, THREAD); |
acorn@949 | 659 | if (class_loader.is_null() || !is_parallelCapable(class_loader)) { |
duke@435 | 660 | PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
duke@435 | 661 | if (oldprobe) { |
duke@435 | 662 | // only need check_seen_thread once, not on each loop |
duke@435 | 663 | // 6341374 java/lang/Instrument with -Xcomp |
duke@435 | 664 | if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) { |
duke@435 | 665 | throw_circularity_error = true; |
duke@435 | 666 | } else { |
duke@435 | 667 | // case 1: traditional: should never see load_in_progress. |
duke@435 | 668 | while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) { |
duke@435 | 669 | |
duke@435 | 670 | // case 4: bootstrap classloader: prevent futile classloading, |
duke@435 | 671 | // wait on first requestor |
duke@435 | 672 | if (class_loader.is_null()) { |
duke@435 | 673 | SystemDictionary_lock->wait(); |
duke@435 | 674 | } else { |
duke@435 | 675 | // case 2: traditional with broken classloader lock. wait on first |
duke@435 | 676 | // requestor. |
duke@435 | 677 | double_lock_wait(lockObject, THREAD); |
duke@435 | 678 | } |
duke@435 | 679 | // Check if classloading completed while we were waiting |
duke@435 | 680 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 681 | if (check != NULL) { |
duke@435 | 682 | // Klass is already loaded, so just return it |
duke@435 | 683 | k = instanceKlassHandle(THREAD, check); |
duke@435 | 684 | class_has_been_loaded = true; |
duke@435 | 685 | } |
duke@435 | 686 | // check if other thread failed to load and cleaned up |
duke@435 | 687 | oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
duke@435 | 688 | } |
duke@435 | 689 | } |
duke@435 | 690 | } |
duke@435 | 691 | } |
duke@435 | 692 | // All cases: add LOAD_INSTANCE |
acorn@949 | 693 | // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try |
duke@435 | 694 | // LOAD_INSTANCE in parallel |
duke@435 | 695 | // add placeholder entry even if error - callers will remove on error |
acorn@949 | 696 | if (!throw_circularity_error && !class_has_been_loaded) { |
duke@435 | 697 | PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, nullsymbolHandle, THREAD); |
duke@435 | 698 | // For class loaders that do not acquire the classloader object lock, |
duke@435 | 699 | // if they did not catch another thread holding LOAD_INSTANCE, |
duke@435 | 700 | // need a check analogous to the acquire ObjectLocker/find_class |
duke@435 | 701 | // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL |
duke@435 | 702 | // one final check if the load has already completed |
acorn@949 | 703 | // class loaders holding the ObjectLock shouldn't find the class here |
duke@435 | 704 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 705 | if (check != NULL) { |
duke@435 | 706 | // Klass is already loaded, so just return it |
duke@435 | 707 | k = instanceKlassHandle(THREAD, check); |
duke@435 | 708 | class_has_been_loaded = true; |
duke@435 | 709 | newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); |
acorn@949 | 710 | placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
acorn@949 | 711 | SystemDictionary_lock->notify_all(); |
duke@435 | 712 | } |
duke@435 | 713 | } |
duke@435 | 714 | } |
duke@435 | 715 | // must throw error outside of owning lock |
duke@435 | 716 | if (throw_circularity_error) { |
duke@435 | 717 | ResourceMark rm(THREAD); |
duke@435 | 718 | THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string()); |
duke@435 | 719 | } |
duke@435 | 720 | |
duke@435 | 721 | if (!class_has_been_loaded) { |
duke@435 | 722 | |
duke@435 | 723 | // Do actual loading |
duke@435 | 724 | k = load_instance_class(name, class_loader, THREAD); |
duke@435 | 725 | |
acorn@949 | 726 | // For UnsyncloadClass and AllowParallelDefineClass only: |
duke@435 | 727 | // If they got a linkageError, check if a parallel class load succeeded. |
duke@435 | 728 | // If it did, then for bytecode resolution the specification requires |
duke@435 | 729 | // that we return the same result we did for the other thread, i.e. the |
duke@435 | 730 | // successfully loaded instanceKlass |
duke@435 | 731 | // Should not get here for classloaders that support parallelism |
acorn@949 | 732 | // with the new cleaner mechanism |
acorn@949 | 733 | // Bootstrap goes through here to allow for an extra guarantee check |
duke@435 | 734 | if (UnsyncloadClass || (class_loader.is_null())) { |
duke@435 | 735 | if (k.is_null() && HAS_PENDING_EXCEPTION |
duke@435 | 736 | && PENDING_EXCEPTION->is_a(SystemDictionary::linkageError_klass())) { |
duke@435 | 737 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 738 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 739 | if (check != NULL) { |
duke@435 | 740 | // Klass is already loaded, so just use it |
duke@435 | 741 | k = instanceKlassHandle(THREAD, check); |
duke@435 | 742 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 743 | guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?"); |
duke@435 | 744 | } |
duke@435 | 745 | } |
duke@435 | 746 | } |
duke@435 | 747 | |
duke@435 | 748 | // clean up placeholder entries for success or error |
duke@435 | 749 | // This cleans up LOAD_INSTANCE entries |
duke@435 | 750 | // It also cleans up LOAD_SUPER entries on errors from |
duke@435 | 751 | // calling load_instance_class |
duke@435 | 752 | { |
duke@435 | 753 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 754 | PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader); |
duke@435 | 755 | if (probe != NULL) { |
duke@435 | 756 | probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE); |
duke@435 | 757 | placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
duke@435 | 758 | SystemDictionary_lock->notify_all(); |
duke@435 | 759 | } |
duke@435 | 760 | } |
duke@435 | 761 | |
duke@435 | 762 | // If everything was OK (no exceptions, no null return value), and |
duke@435 | 763 | // class_loader is NOT the defining loader, do a little more bookkeeping. |
duke@435 | 764 | if (!HAS_PENDING_EXCEPTION && !k.is_null() && |
duke@435 | 765 | k->class_loader() != class_loader()) { |
duke@435 | 766 | |
duke@435 | 767 | check_constraints(d_index, d_hash, k, class_loader, false, THREAD); |
duke@435 | 768 | |
duke@435 | 769 | // Need to check for a PENDING_EXCEPTION again; check_constraints |
duke@435 | 770 | // can throw and doesn't use the CHECK macro. |
duke@435 | 771 | if (!HAS_PENDING_EXCEPTION) { |
duke@435 | 772 | { // Grabbing the Compile_lock prevents systemDictionary updates |
duke@435 | 773 | // during compilations. |
duke@435 | 774 | MutexLocker mu(Compile_lock, THREAD); |
duke@435 | 775 | update_dictionary(d_index, d_hash, p_index, p_hash, |
duke@435 | 776 | k, class_loader, THREAD); |
duke@435 | 777 | } |
duke@435 | 778 | if (JvmtiExport::should_post_class_load()) { |
duke@435 | 779 | Thread *thread = THREAD; |
duke@435 | 780 | assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
duke@435 | 781 | JvmtiExport::post_class_load((JavaThread *) thread, k()); |
duke@435 | 782 | } |
duke@435 | 783 | } |
duke@435 | 784 | } |
duke@435 | 785 | if (HAS_PENDING_EXCEPTION || k.is_null()) { |
duke@435 | 786 | // On error, clean up placeholders |
duke@435 | 787 | { |
duke@435 | 788 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 789 | placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
duke@435 | 790 | SystemDictionary_lock->notify_all(); |
duke@435 | 791 | } |
duke@435 | 792 | return NULL; |
duke@435 | 793 | } |
duke@435 | 794 | } |
duke@435 | 795 | } |
duke@435 | 796 | |
duke@435 | 797 | #ifdef ASSERT |
duke@435 | 798 | { |
duke@435 | 799 | Handle loader (THREAD, k->class_loader()); |
duke@435 | 800 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 801 | oop kk = find_class_or_placeholder(name, loader); |
duke@435 | 802 | assert(kk == k(), "should be present in dictionary"); |
duke@435 | 803 | } |
duke@435 | 804 | #endif |
duke@435 | 805 | |
duke@435 | 806 | // return if the protection domain in NULL |
duke@435 | 807 | if (protection_domain() == NULL) return k(); |
duke@435 | 808 | |
duke@435 | 809 | // Check the protection domain has the right access |
duke@435 | 810 | { |
duke@435 | 811 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 812 | // Note that we have an entry, and entries can be deleted only during GC, |
duke@435 | 813 | // so we cannot allow GC to occur while we're holding this entry. |
duke@435 | 814 | // We're using a No_Safepoint_Verifier to catch any place where we |
duke@435 | 815 | // might potentially do a GC at all. |
duke@435 | 816 | // SystemDictionary::do_unloading() asserts that classes are only |
duke@435 | 817 | // unloaded at a safepoint. |
duke@435 | 818 | No_Safepoint_Verifier nosafepoint; |
duke@435 | 819 | if (dictionary()->is_valid_protection_domain(d_index, d_hash, name, |
duke@435 | 820 | class_loader, |
duke@435 | 821 | protection_domain)) { |
duke@435 | 822 | return k(); |
duke@435 | 823 | } |
duke@435 | 824 | } |
duke@435 | 825 | |
duke@435 | 826 | // Verify protection domain. If it fails an exception is thrown |
duke@435 | 827 | validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL))); |
duke@435 | 828 | |
duke@435 | 829 | return k(); |
duke@435 | 830 | } |
duke@435 | 831 | |
duke@435 | 832 | |
duke@435 | 833 | // This routine does not lock the system dictionary. |
duke@435 | 834 | // |
duke@435 | 835 | // Since readers don't hold a lock, we must make sure that system |
duke@435 | 836 | // dictionary entries are only removed at a safepoint (when only one |
duke@435 | 837 | // thread is running), and are added to in a safe way (all links must |
duke@435 | 838 | // be updated in an MT-safe manner). |
duke@435 | 839 | // |
duke@435 | 840 | // Callers should be aware that an entry could be added just after |
duke@435 | 841 | // _dictionary->bucket(index) is read here, so the caller will not see |
duke@435 | 842 | // the new entry. |
duke@435 | 843 | |
duke@435 | 844 | klassOop SystemDictionary::find(symbolHandle class_name, |
duke@435 | 845 | Handle class_loader, |
duke@435 | 846 | Handle protection_domain, |
duke@435 | 847 | TRAPS) { |
duke@435 | 848 | |
kvn@991 | 849 | // UseNewReflection |
kvn@991 | 850 | // The result of this call should be consistent with the result |
kvn@991 | 851 | // of the call to resolve_instance_class_or_null(). |
kvn@991 | 852 | // See evaluation 6790209 and 4474172 for more details. |
kvn@991 | 853 | class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader())); |
kvn@991 | 854 | |
duke@435 | 855 | unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); |
duke@435 | 856 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 857 | |
duke@435 | 858 | { |
duke@435 | 859 | // Note that we have an entry, and entries can be deleted only during GC, |
duke@435 | 860 | // so we cannot allow GC to occur while we're holding this entry. |
duke@435 | 861 | // We're using a No_Safepoint_Verifier to catch any place where we |
duke@435 | 862 | // might potentially do a GC at all. |
duke@435 | 863 | // SystemDictionary::do_unloading() asserts that classes are only |
duke@435 | 864 | // unloaded at a safepoint. |
duke@435 | 865 | No_Safepoint_Verifier nosafepoint; |
duke@435 | 866 | return dictionary()->find(d_index, d_hash, class_name, class_loader, |
duke@435 | 867 | protection_domain, THREAD); |
duke@435 | 868 | } |
duke@435 | 869 | } |
duke@435 | 870 | |
duke@435 | 871 | |
duke@435 | 872 | // Look for a loaded instance or array klass by name. Do not do any loading. |
duke@435 | 873 | // return NULL in case of error. |
duke@435 | 874 | klassOop SystemDictionary::find_instance_or_array_klass(symbolHandle class_name, |
duke@435 | 875 | Handle class_loader, |
duke@435 | 876 | Handle protection_domain, |
duke@435 | 877 | TRAPS) { |
duke@435 | 878 | klassOop k = NULL; |
duke@435 | 879 | assert(class_name() != NULL, "class name must be non NULL"); |
jrose@567 | 880 | |
jrose@567 | 881 | // Try to get one of the well-known klasses. |
jrose@567 | 882 | if (LinkWellKnownClasses) { |
jrose@567 | 883 | k = find_well_known_klass(class_name()); |
jrose@567 | 884 | if (k != NULL) { |
jrose@567 | 885 | return k; |
jrose@567 | 886 | } |
jrose@567 | 887 | } |
jrose@567 | 888 | |
duke@435 | 889 | if (FieldType::is_array(class_name())) { |
duke@435 | 890 | // The name refers to an array. Parse the name. |
duke@435 | 891 | jint dimension; |
duke@435 | 892 | symbolOop object_key; |
duke@435 | 893 | |
duke@435 | 894 | // dimension and object_key are assigned as a side-effect of this call |
duke@435 | 895 | BasicType t = FieldType::get_array_info(class_name(), &dimension, |
duke@435 | 896 | &object_key, CHECK_(NULL)); |
duke@435 | 897 | if (t != T_OBJECT) { |
duke@435 | 898 | k = Universe::typeArrayKlassObj(t); |
duke@435 | 899 | } else { |
duke@435 | 900 | symbolHandle h_key(THREAD, object_key); |
duke@435 | 901 | k = SystemDictionary::find(h_key, class_loader, protection_domain, THREAD); |
duke@435 | 902 | } |
duke@435 | 903 | if (k != NULL) { |
duke@435 | 904 | k = Klass::cast(k)->array_klass_or_null(dimension); |
duke@435 | 905 | } |
duke@435 | 906 | } else { |
duke@435 | 907 | k = find(class_name, class_loader, protection_domain, THREAD); |
duke@435 | 908 | } |
duke@435 | 909 | return k; |
duke@435 | 910 | } |
duke@435 | 911 | |
jrose@567 | 912 | // Quick range check for names of well-known classes: |
jrose@567 | 913 | static symbolOop wk_klass_name_limits[2] = {NULL, NULL}; |
jrose@567 | 914 | |
jrose@567 | 915 | #ifndef PRODUCT |
jrose@567 | 916 | static int find_wkk_calls, find_wkk_probes, find_wkk_wins; |
jrose@567 | 917 | // counts for "hello world": 3983, 1616, 1075 |
jrose@567 | 918 | // => 60% hit after limit guard, 25% total win rate |
jrose@567 | 919 | #endif |
jrose@567 | 920 | |
jrose@567 | 921 | klassOop SystemDictionary::find_well_known_klass(symbolOop class_name) { |
jrose@567 | 922 | // A bounds-check on class_name will quickly get a negative result. |
jrose@567 | 923 | NOT_PRODUCT(find_wkk_calls++); |
jrose@567 | 924 | if (class_name >= wk_klass_name_limits[0] && |
jrose@567 | 925 | class_name <= wk_klass_name_limits[1]) { |
jrose@567 | 926 | NOT_PRODUCT(find_wkk_probes++); |
jrose@567 | 927 | vmSymbols::SID sid = vmSymbols::find_sid(class_name); |
jrose@567 | 928 | if (sid != vmSymbols::NO_SID) { |
jrose@567 | 929 | klassOop k = NULL; |
jrose@567 | 930 | switch (sid) { |
jrose@567 | 931 | #define WK_KLASS_CASE(name, symbol, ignore_option) \ |
jrose@567 | 932 | case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \ |
jrose@567 | 933 | k = WK_KLASS(name); break; |
jrose@567 | 934 | WK_KLASSES_DO(WK_KLASS_CASE) |
jrose@567 | 935 | #undef WK_KLASS_CASE |
jrose@567 | 936 | } |
jrose@567 | 937 | NOT_PRODUCT(if (k != NULL) find_wkk_wins++); |
jrose@567 | 938 | return k; |
jrose@567 | 939 | } |
jrose@567 | 940 | } |
jrose@567 | 941 | return NULL; |
jrose@567 | 942 | } |
jrose@567 | 943 | |
duke@435 | 944 | // Note: this method is much like resolve_from_stream, but |
duke@435 | 945 | // updates no supplemental data structures. |
duke@435 | 946 | // TODO consolidate the two methods with a helper routine? |
duke@435 | 947 | klassOop SystemDictionary::parse_stream(symbolHandle class_name, |
duke@435 | 948 | Handle class_loader, |
duke@435 | 949 | Handle protection_domain, |
duke@435 | 950 | ClassFileStream* st, |
jrose@866 | 951 | KlassHandle host_klass, |
jrose@866 | 952 | GrowableArray<Handle>* cp_patches, |
duke@435 | 953 | TRAPS) { |
duke@435 | 954 | symbolHandle parsed_name; |
duke@435 | 955 | |
duke@435 | 956 | // Parse the stream. Note that we do this even though this klass might |
duke@435 | 957 | // already be present in the SystemDictionary, otherwise we would not |
duke@435 | 958 | // throw potential ClassFormatErrors. |
duke@435 | 959 | // |
duke@435 | 960 | // Note: "name" is updated. |
duke@435 | 961 | // Further note: a placeholder will be added for this class when |
duke@435 | 962 | // super classes are loaded (resolve_super_or_fail). We expect this |
duke@435 | 963 | // to be called for all classes but java.lang.Object; and we preload |
duke@435 | 964 | // java.lang.Object through resolve_or_fail, not this path. |
duke@435 | 965 | |
duke@435 | 966 | instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
duke@435 | 967 | class_loader, |
duke@435 | 968 | protection_domain, |
duke@435 | 969 | parsed_name, |
duke@435 | 970 | THREAD); |
duke@435 | 971 | |
acorn@949 | 972 | |
duke@435 | 973 | // We don't redefine the class, so we just need to clean up whether there |
duke@435 | 974 | // was an error or not (don't want to modify any system dictionary |
duke@435 | 975 | // data structures). |
duke@435 | 976 | // Parsed name could be null if we threw an error before we got far |
duke@435 | 977 | // enough along to parse it -- in that case, there is nothing to clean up. |
duke@435 | 978 | if (!parsed_name.is_null()) { |
duke@435 | 979 | unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
duke@435 | 980 | class_loader); |
duke@435 | 981 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 982 | { |
duke@435 | 983 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 984 | placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); |
duke@435 | 985 | SystemDictionary_lock->notify_all(); |
duke@435 | 986 | } |
duke@435 | 987 | } |
duke@435 | 988 | |
jrose@866 | 989 | if (host_klass.not_null() && k.not_null()) { |
jrose@866 | 990 | assert(AnonymousClasses, ""); |
jrose@866 | 991 | // If it's anonymous, initialize it now, since nobody else will. |
jrose@866 | 992 | k->set_host_klass(host_klass()); |
jrose@866 | 993 | |
jrose@866 | 994 | { |
jrose@866 | 995 | MutexLocker mu_r(Compile_lock, THREAD); |
jrose@866 | 996 | |
jrose@866 | 997 | // Add to class hierarchy, initialize vtables, and do possible |
jrose@866 | 998 | // deoptimizations. |
jrose@866 | 999 | add_to_hierarchy(k, CHECK_NULL); // No exception, but can block |
jrose@866 | 1000 | |
jrose@866 | 1001 | // But, do not add to system dictionary. |
jrose@866 | 1002 | } |
jrose@866 | 1003 | |
jrose@866 | 1004 | k->eager_initialize(THREAD); |
jrose@866 | 1005 | |
jrose@866 | 1006 | // notify jvmti |
jrose@866 | 1007 | if (JvmtiExport::should_post_class_load()) { |
jrose@866 | 1008 | assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
jrose@866 | 1009 | JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
jrose@866 | 1010 | } |
jrose@866 | 1011 | } |
jrose@866 | 1012 | |
duke@435 | 1013 | return k(); |
duke@435 | 1014 | } |
duke@435 | 1015 | |
duke@435 | 1016 | // Add a klass to the system from a stream (called by jni_DefineClass and |
duke@435 | 1017 | // JVM_DefineClass). |
duke@435 | 1018 | // Note: class_name can be NULL. In that case we do not know the name of |
duke@435 | 1019 | // the class until we have parsed the stream. |
duke@435 | 1020 | |
duke@435 | 1021 | klassOop SystemDictionary::resolve_from_stream(symbolHandle class_name, |
duke@435 | 1022 | Handle class_loader, |
duke@435 | 1023 | Handle protection_domain, |
duke@435 | 1024 | ClassFileStream* st, |
duke@435 | 1025 | TRAPS) { |
duke@435 | 1026 | |
acorn@949 | 1027 | // Classloaders that support parallelism, e.g. bootstrap classloader, |
acorn@949 | 1028 | // or all classloaders with UnsyncloadClass do not acquire lock here |
acorn@949 | 1029 | bool DoObjectLock = true; |
acorn@949 | 1030 | if (is_parallelCapable(class_loader)) { |
acorn@949 | 1031 | DoObjectLock = false; |
acorn@949 | 1032 | } |
acorn@949 | 1033 | |
acorn@949 | 1034 | // Make sure we are synchronized on the class loader before we proceed |
duke@435 | 1035 | Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
duke@435 | 1036 | check_loader_lock_contention(lockObject, THREAD); |
acorn@949 | 1037 | ObjectLocker ol(lockObject, THREAD, DoObjectLock); |
duke@435 | 1038 | |
duke@435 | 1039 | symbolHandle parsed_name; |
duke@435 | 1040 | |
duke@435 | 1041 | // Parse the stream. Note that we do this even though this klass might |
duke@435 | 1042 | // already be present in the SystemDictionary, otherwise we would not |
duke@435 | 1043 | // throw potential ClassFormatErrors. |
duke@435 | 1044 | // |
duke@435 | 1045 | // Note: "name" is updated. |
duke@435 | 1046 | // Further note: a placeholder will be added for this class when |
duke@435 | 1047 | // super classes are loaded (resolve_super_or_fail). We expect this |
duke@435 | 1048 | // to be called for all classes but java.lang.Object; and we preload |
duke@435 | 1049 | // java.lang.Object through resolve_or_fail, not this path. |
duke@435 | 1050 | |
duke@435 | 1051 | instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name, |
duke@435 | 1052 | class_loader, |
duke@435 | 1053 | protection_domain, |
duke@435 | 1054 | parsed_name, |
duke@435 | 1055 | THREAD); |
duke@435 | 1056 | |
duke@435 | 1057 | const char* pkg = "java/"; |
duke@435 | 1058 | if (!HAS_PENDING_EXCEPTION && |
duke@435 | 1059 | !class_loader.is_null() && |
duke@435 | 1060 | !parsed_name.is_null() && |
duke@435 | 1061 | !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) { |
duke@435 | 1062 | // It is illegal to define classes in the "java." package from |
duke@435 | 1063 | // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader |
duke@435 | 1064 | ResourceMark rm(THREAD); |
duke@435 | 1065 | char* name = parsed_name->as_C_string(); |
duke@435 | 1066 | char* index = strrchr(name, '/'); |
duke@435 | 1067 | *index = '\0'; // chop to just the package name |
duke@435 | 1068 | while ((index = strchr(name, '/')) != NULL) { |
duke@435 | 1069 | *index = '.'; // replace '/' with '.' in package name |
duke@435 | 1070 | } |
duke@435 | 1071 | const char* fmt = "Prohibited package name: %s"; |
duke@435 | 1072 | size_t len = strlen(fmt) + strlen(name); |
duke@435 | 1073 | char* message = NEW_RESOURCE_ARRAY(char, len); |
duke@435 | 1074 | jio_snprintf(message, len, fmt, name); |
duke@435 | 1075 | Exceptions::_throw_msg(THREAD_AND_LOCATION, |
duke@435 | 1076 | vmSymbols::java_lang_SecurityException(), message); |
duke@435 | 1077 | } |
duke@435 | 1078 | |
duke@435 | 1079 | if (!HAS_PENDING_EXCEPTION) { |
duke@435 | 1080 | assert(!parsed_name.is_null(), "Sanity"); |
duke@435 | 1081 | assert(class_name.is_null() || class_name() == parsed_name(), |
duke@435 | 1082 | "name mismatch"); |
duke@435 | 1083 | // Verification prevents us from creating names with dots in them, this |
duke@435 | 1084 | // asserts that that's the case. |
duke@435 | 1085 | assert(is_internal_format(parsed_name), |
duke@435 | 1086 | "external class name format used internally"); |
duke@435 | 1087 | |
duke@435 | 1088 | // Add class just loaded |
acorn@949 | 1089 | // If a class loader supports parallel classloading handle parallel define requests |
acorn@949 | 1090 | // find_or_define_instance_class may return a different instanceKlass |
acorn@949 | 1091 | if (is_parallelCapable(class_loader)) { |
acorn@949 | 1092 | k = find_or_define_instance_class(class_name, class_loader, k, THREAD); |
acorn@949 | 1093 | } else { |
acorn@949 | 1094 | define_instance_class(k, THREAD); |
acorn@949 | 1095 | } |
duke@435 | 1096 | } |
duke@435 | 1097 | |
duke@435 | 1098 | // If parsing the class file or define_instance_class failed, we |
duke@435 | 1099 | // need to remove the placeholder added on our behalf. But we |
duke@435 | 1100 | // must make sure parsed_name is valid first (it won't be if we had |
duke@435 | 1101 | // a format error before the class was parsed far enough to |
duke@435 | 1102 | // find the name). |
duke@435 | 1103 | if (HAS_PENDING_EXCEPTION && !parsed_name.is_null()) { |
duke@435 | 1104 | unsigned int p_hash = placeholders()->compute_hash(parsed_name, |
duke@435 | 1105 | class_loader); |
duke@435 | 1106 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 1107 | { |
duke@435 | 1108 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 1109 | placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD); |
duke@435 | 1110 | SystemDictionary_lock->notify_all(); |
duke@435 | 1111 | } |
duke@435 | 1112 | return NULL; |
duke@435 | 1113 | } |
duke@435 | 1114 | |
duke@435 | 1115 | // Make sure that we didn't leave a place holder in the |
duke@435 | 1116 | // SystemDictionary; this is only done on success |
duke@435 | 1117 | debug_only( { |
duke@435 | 1118 | if (!HAS_PENDING_EXCEPTION) { |
duke@435 | 1119 | assert(!parsed_name.is_null(), "parsed_name is still null?"); |
duke@435 | 1120 | symbolHandle h_name (THREAD, k->name()); |
duke@435 | 1121 | Handle h_loader (THREAD, k->class_loader()); |
duke@435 | 1122 | |
duke@435 | 1123 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 1124 | |
duke@435 | 1125 | oop check = find_class_or_placeholder(parsed_name, class_loader); |
duke@435 | 1126 | assert(check == k(), "should be present in the dictionary"); |
duke@435 | 1127 | |
duke@435 | 1128 | oop check2 = find_class_or_placeholder(h_name, h_loader); |
duke@435 | 1129 | assert(check == check2, "name inconsistancy in SystemDictionary"); |
duke@435 | 1130 | } |
duke@435 | 1131 | } ); |
duke@435 | 1132 | |
duke@435 | 1133 | return k(); |
duke@435 | 1134 | } |
duke@435 | 1135 | |
duke@435 | 1136 | |
duke@435 | 1137 | void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length, |
duke@435 | 1138 | int number_of_entries) { |
duke@435 | 1139 | assert(length == _nof_buckets * sizeof(HashtableBucket), |
duke@435 | 1140 | "bad shared dictionary size."); |
duke@435 | 1141 | _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries); |
duke@435 | 1142 | } |
duke@435 | 1143 | |
duke@435 | 1144 | |
duke@435 | 1145 | // If there is a shared dictionary, then find the entry for the |
duke@435 | 1146 | // given shared system class, if any. |
duke@435 | 1147 | |
duke@435 | 1148 | klassOop SystemDictionary::find_shared_class(symbolHandle class_name) { |
duke@435 | 1149 | if (shared_dictionary() != NULL) { |
duke@435 | 1150 | unsigned int d_hash = dictionary()->compute_hash(class_name, Handle()); |
duke@435 | 1151 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 1152 | return shared_dictionary()->find_shared_class(d_index, d_hash, class_name); |
duke@435 | 1153 | } else { |
duke@435 | 1154 | return NULL; |
duke@435 | 1155 | } |
duke@435 | 1156 | } |
duke@435 | 1157 | |
duke@435 | 1158 | |
duke@435 | 1159 | // Load a class from the shared spaces (found through the shared system |
duke@435 | 1160 | // dictionary). Force the superclass and all interfaces to be loaded. |
duke@435 | 1161 | // Update the class definition to include sibling classes and no |
duke@435 | 1162 | // subclasses (yet). [Classes in the shared space are not part of the |
duke@435 | 1163 | // object hierarchy until loaded.] |
duke@435 | 1164 | |
duke@435 | 1165 | instanceKlassHandle SystemDictionary::load_shared_class( |
duke@435 | 1166 | symbolHandle class_name, Handle class_loader, TRAPS) { |
duke@435 | 1167 | instanceKlassHandle ik (THREAD, find_shared_class(class_name)); |
duke@435 | 1168 | return load_shared_class(ik, class_loader, THREAD); |
duke@435 | 1169 | } |
duke@435 | 1170 | |
duke@435 | 1171 | // Note well! Changes to this method may affect oop access order |
duke@435 | 1172 | // in the shared archive. Please take care to not make changes that |
duke@435 | 1173 | // adversely affect cold start time by changing the oop access order |
duke@435 | 1174 | // that is specified in dump.cpp MarkAndMoveOrderedReadOnly and |
duke@435 | 1175 | // MarkAndMoveOrderedReadWrite closures. |
duke@435 | 1176 | instanceKlassHandle SystemDictionary::load_shared_class( |
duke@435 | 1177 | instanceKlassHandle ik, Handle class_loader, TRAPS) { |
duke@435 | 1178 | assert(class_loader.is_null(), "non-null classloader for shared class?"); |
duke@435 | 1179 | if (ik.not_null()) { |
duke@435 | 1180 | instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
duke@435 | 1181 | symbolHandle class_name(THREAD, ik->name()); |
duke@435 | 1182 | |
duke@435 | 1183 | // Found the class, now load the superclass and interfaces. If they |
duke@435 | 1184 | // are shared, add them to the main system dictionary and reset |
duke@435 | 1185 | // their hierarchy references (supers, subs, and interfaces). |
duke@435 | 1186 | |
duke@435 | 1187 | if (ik->super() != NULL) { |
duke@435 | 1188 | symbolHandle cn(THREAD, ik->super()->klass_part()->name()); |
duke@435 | 1189 | resolve_super_or_fail(class_name, cn, |
duke@435 | 1190 | class_loader, Handle(), true, CHECK_(nh)); |
duke@435 | 1191 | } |
duke@435 | 1192 | |
duke@435 | 1193 | objArrayHandle interfaces (THREAD, ik->local_interfaces()); |
duke@435 | 1194 | int num_interfaces = interfaces->length(); |
duke@435 | 1195 | for (int index = 0; index < num_interfaces; index++) { |
duke@435 | 1196 | klassOop k = klassOop(interfaces->obj_at(index)); |
duke@435 | 1197 | |
duke@435 | 1198 | // Note: can not use instanceKlass::cast here because |
duke@435 | 1199 | // interfaces' instanceKlass's C++ vtbls haven't been |
duke@435 | 1200 | // reinitialized yet (they will be once the interface classes |
duke@435 | 1201 | // are loaded) |
duke@435 | 1202 | symbolHandle name (THREAD, k->klass_part()->name()); |
duke@435 | 1203 | resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh)); |
duke@435 | 1204 | } |
duke@435 | 1205 | |
duke@435 | 1206 | // Adjust methods to recover missing data. They need addresses for |
duke@435 | 1207 | // interpreter entry points and their default native method address |
duke@435 | 1208 | // must be reset. |
duke@435 | 1209 | |
duke@435 | 1210 | // Updating methods must be done under a lock so multiple |
duke@435 | 1211 | // threads don't update these in parallel |
duke@435 | 1212 | // Shared classes are all currently loaded by the bootstrap |
duke@435 | 1213 | // classloader, so this will never cause a deadlock on |
duke@435 | 1214 | // a custom class loader lock. |
duke@435 | 1215 | |
duke@435 | 1216 | { |
duke@435 | 1217 | Handle lockObject = compute_loader_lock_object(class_loader, THREAD); |
duke@435 | 1218 | check_loader_lock_contention(lockObject, THREAD); |
duke@435 | 1219 | ObjectLocker ol(lockObject, THREAD, true); |
duke@435 | 1220 | |
duke@435 | 1221 | objArrayHandle methods (THREAD, ik->methods()); |
duke@435 | 1222 | int num_methods = methods->length(); |
duke@435 | 1223 | for (int index2 = 0; index2 < num_methods; ++index2) { |
duke@435 | 1224 | methodHandle m(THREAD, methodOop(methods->obj_at(index2))); |
duke@435 | 1225 | m()->link_method(m, CHECK_(nh)); |
duke@435 | 1226 | } |
duke@435 | 1227 | } |
duke@435 | 1228 | |
duke@435 | 1229 | if (TraceClassLoading) { |
duke@435 | 1230 | ResourceMark rm; |
duke@435 | 1231 | tty->print("[Loaded %s", ik->external_name()); |
duke@435 | 1232 | tty->print(" from shared objects file"); |
duke@435 | 1233 | tty->print_cr("]"); |
duke@435 | 1234 | } |
duke@435 | 1235 | // notify a class loaded from shared object |
duke@435 | 1236 | ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()), |
duke@435 | 1237 | true /* shared class */); |
duke@435 | 1238 | } |
duke@435 | 1239 | return ik; |
duke@435 | 1240 | } |
duke@435 | 1241 | |
duke@435 | 1242 | #ifdef KERNEL |
duke@435 | 1243 | // Some classes on the bootstrap class path haven't been installed on the |
duke@435 | 1244 | // system yet. Call the DownloadManager method to make them appear in the |
duke@435 | 1245 | // bootstrap class path and try again to load the named class. |
duke@435 | 1246 | // Note that with delegation class loaders all classes in another loader will |
duke@435 | 1247 | // first try to call this so it'd better be fast!! |
duke@435 | 1248 | static instanceKlassHandle download_and_retry_class_load( |
duke@435 | 1249 | symbolHandle class_name, |
duke@435 | 1250 | TRAPS) { |
duke@435 | 1251 | |
duke@435 | 1252 | klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass(); |
duke@435 | 1253 | instanceKlassHandle nk; |
duke@435 | 1254 | |
duke@435 | 1255 | // If download manager class isn't loaded just return. |
duke@435 | 1256 | if (dlm == NULL) return nk; |
duke@435 | 1257 | |
duke@435 | 1258 | { HandleMark hm(THREAD); |
duke@435 | 1259 | ResourceMark rm(THREAD); |
duke@435 | 1260 | Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk)); |
duke@435 | 1261 | Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk)); |
duke@435 | 1262 | |
duke@435 | 1263 | // return value |
duke@435 | 1264 | JavaValue result(T_OBJECT); |
duke@435 | 1265 | |
duke@435 | 1266 | // Call the DownloadManager. We assume that it has a lock because |
duke@435 | 1267 | // multiple classes could be not found and downloaded at the same time. |
duke@435 | 1268 | // class sun.misc.DownloadManager; |
duke@435 | 1269 | // public static String getBootClassPathEntryForClass(String className); |
duke@435 | 1270 | JavaCalls::call_static(&result, |
duke@435 | 1271 | KlassHandle(THREAD, dlm), |
duke@435 | 1272 | vmSymbolHandles::getBootClassPathEntryForClass_name(), |
duke@435 | 1273 | vmSymbolHandles::string_string_signature(), |
duke@435 | 1274 | class_string, |
duke@435 | 1275 | CHECK_(nk)); |
duke@435 | 1276 | |
duke@435 | 1277 | // Get result.string and add to bootclasspath |
duke@435 | 1278 | assert(result.get_type() == T_OBJECT, "just checking"); |
duke@435 | 1279 | oop obj = (oop) result.get_jobject(); |
duke@435 | 1280 | if (obj == NULL) { return nk; } |
duke@435 | 1281 | |
coleenp@457 | 1282 | Handle h_obj(THREAD, obj); |
coleenp@457 | 1283 | char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj, |
coleenp@457 | 1284 | CHECK_(nk)); |
duke@435 | 1285 | |
duke@435 | 1286 | // lock the loader |
duke@435 | 1287 | // we use this lock because JVMTI does. |
duke@435 | 1288 | Handle loader_lock(THREAD, SystemDictionary::system_loader_lock()); |
duke@435 | 1289 | |
duke@435 | 1290 | ObjectLocker ol(loader_lock, THREAD); |
duke@435 | 1291 | // add the file to the bootclasspath |
duke@435 | 1292 | ClassLoader::update_class_path_entry_list(new_class_name, true); |
duke@435 | 1293 | } // end HandleMark |
duke@435 | 1294 | |
duke@435 | 1295 | if (TraceClassLoading) { |
duke@435 | 1296 | ClassLoader::print_bootclasspath(); |
duke@435 | 1297 | } |
duke@435 | 1298 | return ClassLoader::load_classfile(class_name, CHECK_(nk)); |
duke@435 | 1299 | } |
duke@435 | 1300 | #endif // KERNEL |
duke@435 | 1301 | |
duke@435 | 1302 | |
duke@435 | 1303 | instanceKlassHandle SystemDictionary::load_instance_class(symbolHandle class_name, Handle class_loader, TRAPS) { |
duke@435 | 1304 | instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
duke@435 | 1305 | if (class_loader.is_null()) { |
duke@435 | 1306 | // Search the shared system dictionary for classes preloaded into the |
duke@435 | 1307 | // shared spaces. |
duke@435 | 1308 | instanceKlassHandle k; |
duke@435 | 1309 | k = load_shared_class(class_name, class_loader, THREAD); |
duke@435 | 1310 | |
duke@435 | 1311 | if (k.is_null()) { |
duke@435 | 1312 | // Use VM class loader |
duke@435 | 1313 | k = ClassLoader::load_classfile(class_name, CHECK_(nh)); |
duke@435 | 1314 | } |
duke@435 | 1315 | |
duke@435 | 1316 | #ifdef KERNEL |
duke@435 | 1317 | // If the VM class loader has failed to load the class, call the |
duke@435 | 1318 | // DownloadManager class to make it magically appear on the classpath |
duke@435 | 1319 | // and try again. This is only configured with the Kernel VM. |
duke@435 | 1320 | if (k.is_null()) { |
duke@435 | 1321 | k = download_and_retry_class_load(class_name, CHECK_(nh)); |
duke@435 | 1322 | } |
duke@435 | 1323 | #endif // KERNEL |
duke@435 | 1324 | |
acorn@949 | 1325 | // find_or_define_instance_class may return a different instanceKlass |
duke@435 | 1326 | if (!k.is_null()) { |
duke@435 | 1327 | k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh)); |
duke@435 | 1328 | } |
duke@435 | 1329 | return k; |
duke@435 | 1330 | } else { |
duke@435 | 1331 | // Use user specified class loader to load class. Call loadClass operation on class_loader. |
duke@435 | 1332 | ResourceMark rm(THREAD); |
duke@435 | 1333 | |
duke@435 | 1334 | Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh)); |
duke@435 | 1335 | // Translate to external class name format, i.e., convert '/' chars to '.' |
duke@435 | 1336 | Handle string = java_lang_String::externalize_classname(s, CHECK_(nh)); |
duke@435 | 1337 | |
duke@435 | 1338 | JavaValue result(T_OBJECT); |
duke@435 | 1339 | |
duke@435 | 1340 | KlassHandle spec_klass (THREAD, SystemDictionary::classloader_klass()); |
duke@435 | 1341 | |
acorn@949 | 1342 | // Call public unsynchronized loadClass(String) directly for all class loaders |
acorn@949 | 1343 | // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will |
acorn@949 | 1344 | // acquire a class-name based lock rather than the class loader object lock. |
acorn@949 | 1345 | // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), |
acorn@949 | 1346 | // so the call to loadClassInternal() was not required. |
acorn@949 | 1347 | // |
acorn@949 | 1348 | // UnsyncloadClass flag means both call loadClass(String) and do |
acorn@949 | 1349 | // not acquire the class loader lock even for class loaders that are |
acorn@949 | 1350 | // not parallelCapable. This was a risky transitional |
acorn@949 | 1351 | // flag for diagnostic purposes only. It is risky to call |
duke@435 | 1352 | // custom class loaders without synchronization. |
duke@435 | 1353 | // WARNING If a custom class loader does NOT synchronizer findClass, or callers of |
acorn@949 | 1354 | // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field. |
duke@435 | 1355 | // Do NOT assume this will be supported in future releases. |
acorn@949 | 1356 | // |
acorn@949 | 1357 | // Added MustCallLoadClassInternal in case we discover in the field |
acorn@949 | 1358 | // a customer that counts on this call |
acorn@949 | 1359 | if (MustCallLoadClassInternal && has_loadClassInternal()) { |
duke@435 | 1360 | JavaCalls::call_special(&result, |
duke@435 | 1361 | class_loader, |
duke@435 | 1362 | spec_klass, |
duke@435 | 1363 | vmSymbolHandles::loadClassInternal_name(), |
duke@435 | 1364 | vmSymbolHandles::string_class_signature(), |
duke@435 | 1365 | string, |
duke@435 | 1366 | CHECK_(nh)); |
duke@435 | 1367 | } else { |
duke@435 | 1368 | JavaCalls::call_virtual(&result, |
duke@435 | 1369 | class_loader, |
duke@435 | 1370 | spec_klass, |
duke@435 | 1371 | vmSymbolHandles::loadClass_name(), |
duke@435 | 1372 | vmSymbolHandles::string_class_signature(), |
duke@435 | 1373 | string, |
duke@435 | 1374 | CHECK_(nh)); |
duke@435 | 1375 | } |
duke@435 | 1376 | |
duke@435 | 1377 | assert(result.get_type() == T_OBJECT, "just checking"); |
duke@435 | 1378 | oop obj = (oop) result.get_jobject(); |
duke@435 | 1379 | |
duke@435 | 1380 | // Primitive classes return null since forName() can not be |
duke@435 | 1381 | // used to obtain any of the Class objects representing primitives or void |
duke@435 | 1382 | if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) { |
duke@435 | 1383 | instanceKlassHandle k = |
duke@435 | 1384 | instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj)); |
duke@435 | 1385 | // For user defined Java class loaders, check that the name returned is |
duke@435 | 1386 | // the same as that requested. This check is done for the bootstrap |
duke@435 | 1387 | // loader when parsing the class file. |
duke@435 | 1388 | if (class_name() == k->name()) { |
duke@435 | 1389 | return k; |
duke@435 | 1390 | } |
duke@435 | 1391 | } |
duke@435 | 1392 | // Class is not found or has the wrong name, return NULL |
duke@435 | 1393 | return nh; |
duke@435 | 1394 | } |
duke@435 | 1395 | } |
duke@435 | 1396 | |
duke@435 | 1397 | void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) { |
duke@435 | 1398 | |
duke@435 | 1399 | Handle class_loader_h(THREAD, k->class_loader()); |
duke@435 | 1400 | |
acorn@949 | 1401 | // for bootstrap and other parallel classloaders don't acquire lock, |
acorn@949 | 1402 | // use placeholder token |
acorn@949 | 1403 | // If a parallelCapable class loader calls define_instance_class instead of |
acorn@949 | 1404 | // find_or_define_instance_class to get here, we have a timing |
acorn@949 | 1405 | // hole with systemDictionary updates and check_constraints |
acorn@949 | 1406 | if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) { |
duke@435 | 1407 | assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, |
duke@435 | 1408 | compute_loader_lock_object(class_loader_h, THREAD)), |
duke@435 | 1409 | "define called without lock"); |
duke@435 | 1410 | } |
duke@435 | 1411 | |
duke@435 | 1412 | // Check class-loading constraints. Throw exception if violation is detected. |
duke@435 | 1413 | // Grabs and releases SystemDictionary_lock |
duke@435 | 1414 | // The check_constraints/find_class call and update_dictionary sequence |
duke@435 | 1415 | // must be "atomic" for a specific class/classloader pair so we never |
duke@435 | 1416 | // define two different instanceKlasses for that class/classloader pair. |
duke@435 | 1417 | // Existing classloaders will call define_instance_class with the |
duke@435 | 1418 | // classloader lock held |
duke@435 | 1419 | // Parallel classloaders will call find_or_define_instance_class |
duke@435 | 1420 | // which will require a token to perform the define class |
duke@435 | 1421 | symbolHandle name_h(THREAD, k->name()); |
duke@435 | 1422 | unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h); |
duke@435 | 1423 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 1424 | check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK); |
duke@435 | 1425 | |
duke@435 | 1426 | // Register class just loaded with class loader (placed in Vector) |
duke@435 | 1427 | // Note we do this before updating the dictionary, as this can |
duke@435 | 1428 | // fail with an OutOfMemoryError (if it does, we will *not* put this |
duke@435 | 1429 | // class in the dictionary and will not update the class hierarchy). |
duke@435 | 1430 | if (k->class_loader() != NULL) { |
duke@435 | 1431 | methodHandle m(THREAD, Universe::loader_addClass_method()); |
duke@435 | 1432 | JavaValue result(T_VOID); |
duke@435 | 1433 | JavaCallArguments args(class_loader_h); |
duke@435 | 1434 | args.push_oop(Handle(THREAD, k->java_mirror())); |
duke@435 | 1435 | JavaCalls::call(&result, m, &args, CHECK); |
duke@435 | 1436 | } |
duke@435 | 1437 | |
duke@435 | 1438 | // Add the new class. We need recompile lock during update of CHA. |
duke@435 | 1439 | { |
duke@435 | 1440 | unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h); |
duke@435 | 1441 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 1442 | |
duke@435 | 1443 | MutexLocker mu_r(Compile_lock, THREAD); |
duke@435 | 1444 | |
duke@435 | 1445 | // Add to class hierarchy, initialize vtables, and do possible |
duke@435 | 1446 | // deoptimizations. |
duke@435 | 1447 | add_to_hierarchy(k, CHECK); // No exception, but can block |
duke@435 | 1448 | |
duke@435 | 1449 | // Add to systemDictionary - so other classes can see it. |
duke@435 | 1450 | // Grabs and releases SystemDictionary_lock |
duke@435 | 1451 | update_dictionary(d_index, d_hash, p_index, p_hash, |
duke@435 | 1452 | k, class_loader_h, THREAD); |
duke@435 | 1453 | } |
duke@435 | 1454 | k->eager_initialize(THREAD); |
duke@435 | 1455 | |
duke@435 | 1456 | // notify jvmti |
duke@435 | 1457 | if (JvmtiExport::should_post_class_load()) { |
duke@435 | 1458 | assert(THREAD->is_Java_thread(), "thread->is_Java_thread()"); |
duke@435 | 1459 | JvmtiExport::post_class_load((JavaThread *) THREAD, k()); |
duke@435 | 1460 | |
duke@435 | 1461 | } |
duke@435 | 1462 | } |
duke@435 | 1463 | |
duke@435 | 1464 | // Support parallel classloading |
duke@435 | 1465 | // Initial implementation for bootstrap classloader |
duke@435 | 1466 | // For custom class loaders that support parallel classloading, |
acorn@949 | 1467 | // With AllowParallelDefine flag==true, in case they do not synchronize around |
acorn@949 | 1468 | // FindLoadedClass/DefineClass, calls, we check for parallel |
duke@435 | 1469 | // loading for them, wait if a defineClass is in progress |
duke@435 | 1470 | // and return the initial requestor's results |
acorn@949 | 1471 | // With AllowParallelDefine flag==false, call through to define_instance_class |
acorn@949 | 1472 | // which will throw LinkageError: duplicate class definition. |
duke@435 | 1473 | // For better performance, the class loaders should synchronize |
acorn@949 | 1474 | // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they |
duke@435 | 1475 | // potentially waste time reading and parsing the bytestream. |
duke@435 | 1476 | // Note: VM callers should ensure consistency of k/class_name,class_loader |
duke@435 | 1477 | instanceKlassHandle SystemDictionary::find_or_define_instance_class(symbolHandle class_name, Handle class_loader, instanceKlassHandle k, TRAPS) { |
duke@435 | 1478 | |
duke@435 | 1479 | instanceKlassHandle nh = instanceKlassHandle(); // null Handle |
acorn@950 | 1480 | symbolHandle name_h(THREAD, k->name()); // passed in class_name may be null |
duke@435 | 1481 | |
acorn@950 | 1482 | unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader); |
duke@435 | 1483 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 1484 | |
duke@435 | 1485 | // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS |
acorn@950 | 1486 | unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader); |
duke@435 | 1487 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 1488 | PlaceholderEntry* probe; |
duke@435 | 1489 | |
duke@435 | 1490 | { |
duke@435 | 1491 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 1492 | // First check if class already defined |
acorn@950 | 1493 | klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
duke@435 | 1494 | if (check != NULL) { |
duke@435 | 1495 | return(instanceKlassHandle(THREAD, check)); |
duke@435 | 1496 | } |
duke@435 | 1497 | |
duke@435 | 1498 | // Acquire define token for this class/classloader |
duke@435 | 1499 | symbolHandle nullsymbolHandle; |
acorn@950 | 1500 | probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, nullsymbolHandle, THREAD); |
acorn@949 | 1501 | // Wait if another thread defining in parallel |
acorn@949 | 1502 | // All threads wait - even those that will throw duplicate class: otherwise |
acorn@949 | 1503 | // caller is surprised by LinkageError: duplicate, but findLoadedClass fails |
acorn@949 | 1504 | // if other thread has not finished updating dictionary |
acorn@949 | 1505 | while (probe->definer() != NULL) { |
acorn@949 | 1506 | SystemDictionary_lock->wait(); |
acorn@949 | 1507 | } |
acorn@949 | 1508 | // Only special cases allow parallel defines and can use other thread's results |
acorn@949 | 1509 | // Other cases fall through, and may run into duplicate defines |
acorn@949 | 1510 | // caught by finding an entry in the SystemDictionary |
acorn@949 | 1511 | if ((UnsyncloadClass || AllowParallelDefineClass) && (probe->instanceKlass() != NULL)) { |
jrose@866 | 1512 | probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
acorn@950 | 1513 | placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
acorn@949 | 1514 | SystemDictionary_lock->notify_all(); |
jrose@866 | 1515 | #ifdef ASSERT |
acorn@950 | 1516 | klassOop check = find_class(d_index, d_hash, name_h, class_loader); |
acorn@949 | 1517 | assert(check != NULL, "definer missed recording success"); |
jrose@866 | 1518 | #endif |
acorn@949 | 1519 | return(instanceKlassHandle(THREAD, probe->instanceKlass())); |
acorn@949 | 1520 | } else { |
acorn@949 | 1521 | // This thread will define the class (even if earlier thread tried and had an error) |
duke@435 | 1522 | probe->set_definer(THREAD); |
duke@435 | 1523 | } |
duke@435 | 1524 | } |
duke@435 | 1525 | |
duke@435 | 1526 | define_instance_class(k, THREAD); |
duke@435 | 1527 | |
duke@435 | 1528 | Handle linkage_exception = Handle(); // null handle |
duke@435 | 1529 | |
duke@435 | 1530 | // definer must notify any waiting threads |
duke@435 | 1531 | { |
duke@435 | 1532 | MutexLocker mu(SystemDictionary_lock, THREAD); |
acorn@950 | 1533 | PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader); |
duke@435 | 1534 | assert(probe != NULL, "DEFINE_CLASS placeholder lost?"); |
duke@435 | 1535 | if (probe != NULL) { |
duke@435 | 1536 | if (HAS_PENDING_EXCEPTION) { |
duke@435 | 1537 | linkage_exception = Handle(THREAD,PENDING_EXCEPTION); |
duke@435 | 1538 | CLEAR_PENDING_EXCEPTION; |
duke@435 | 1539 | } else { |
duke@435 | 1540 | probe->set_instanceKlass(k()); |
duke@435 | 1541 | } |
duke@435 | 1542 | probe->set_definer(NULL); |
duke@435 | 1543 | probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS); |
acorn@950 | 1544 | placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD); |
duke@435 | 1545 | SystemDictionary_lock->notify_all(); |
duke@435 | 1546 | } |
duke@435 | 1547 | } |
duke@435 | 1548 | |
duke@435 | 1549 | // Can't throw exception while holding lock due to rank ordering |
duke@435 | 1550 | if (linkage_exception() != NULL) { |
duke@435 | 1551 | THROW_OOP_(linkage_exception(), nh); // throws exception and returns |
duke@435 | 1552 | } |
duke@435 | 1553 | |
duke@435 | 1554 | return k; |
duke@435 | 1555 | } |
duke@435 | 1556 | Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) { |
duke@435 | 1557 | // If class_loader is NULL we synchronize on _system_loader_lock_obj |
duke@435 | 1558 | if (class_loader.is_null()) { |
duke@435 | 1559 | return Handle(THREAD, _system_loader_lock_obj); |
duke@435 | 1560 | } else { |
duke@435 | 1561 | return class_loader; |
duke@435 | 1562 | } |
duke@435 | 1563 | } |
duke@435 | 1564 | |
duke@435 | 1565 | // This method is added to check how often we have to wait to grab loader |
duke@435 | 1566 | // lock. The results are being recorded in the performance counters defined in |
duke@435 | 1567 | // ClassLoader::_sync_systemLoaderLockContentionRate and |
duke@435 | 1568 | // ClassLoader::_sync_nonSystemLoaderLockConteionRate. |
duke@435 | 1569 | void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) { |
duke@435 | 1570 | if (!UsePerfData) { |
duke@435 | 1571 | return; |
duke@435 | 1572 | } |
duke@435 | 1573 | |
duke@435 | 1574 | assert(!loader_lock.is_null(), "NULL lock object"); |
duke@435 | 1575 | |
duke@435 | 1576 | if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock) |
duke@435 | 1577 | == ObjectSynchronizer::owner_other) { |
duke@435 | 1578 | // contention will likely happen, so increment the corresponding |
duke@435 | 1579 | // contention counter. |
duke@435 | 1580 | if (loader_lock() == _system_loader_lock_obj) { |
duke@435 | 1581 | ClassLoader::sync_systemLoaderLockContentionRate()->inc(); |
duke@435 | 1582 | } else { |
duke@435 | 1583 | ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc(); |
duke@435 | 1584 | } |
duke@435 | 1585 | } |
duke@435 | 1586 | } |
duke@435 | 1587 | |
duke@435 | 1588 | // ---------------------------------------------------------------------------- |
duke@435 | 1589 | // Lookup |
duke@435 | 1590 | |
duke@435 | 1591 | klassOop SystemDictionary::find_class(int index, unsigned int hash, |
duke@435 | 1592 | symbolHandle class_name, |
duke@435 | 1593 | Handle class_loader) { |
duke@435 | 1594 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 1595 | assert (index == dictionary()->index_for(class_name, class_loader), |
duke@435 | 1596 | "incorrect index?"); |
duke@435 | 1597 | |
duke@435 | 1598 | klassOop k = dictionary()->find_class(index, hash, class_name, class_loader); |
duke@435 | 1599 | return k; |
duke@435 | 1600 | } |
duke@435 | 1601 | |
duke@435 | 1602 | |
duke@435 | 1603 | // Basic find on classes in the midst of being loaded |
duke@435 | 1604 | symbolOop SystemDictionary::find_placeholder(int index, unsigned int hash, |
duke@435 | 1605 | symbolHandle class_name, |
duke@435 | 1606 | Handle class_loader) { |
duke@435 | 1607 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 1608 | |
duke@435 | 1609 | return placeholders()->find_entry(index, hash, class_name, class_loader); |
duke@435 | 1610 | } |
duke@435 | 1611 | |
duke@435 | 1612 | |
duke@435 | 1613 | // Used for assertions and verification only |
duke@435 | 1614 | oop SystemDictionary::find_class_or_placeholder(symbolHandle class_name, |
duke@435 | 1615 | Handle class_loader) { |
duke@435 | 1616 | #ifndef ASSERT |
duke@435 | 1617 | guarantee(VerifyBeforeGC || |
duke@435 | 1618 | VerifyDuringGC || |
duke@435 | 1619 | VerifyBeforeExit || |
duke@435 | 1620 | VerifyAfterGC, "too expensive"); |
duke@435 | 1621 | #endif |
duke@435 | 1622 | assert_locked_or_safepoint(SystemDictionary_lock); |
duke@435 | 1623 | symbolOop class_name_ = class_name(); |
duke@435 | 1624 | oop class_loader_ = class_loader(); |
duke@435 | 1625 | |
duke@435 | 1626 | // First look in the loaded class array |
duke@435 | 1627 | unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader); |
duke@435 | 1628 | int d_index = dictionary()->hash_to_index(d_hash); |
duke@435 | 1629 | oop lookup = find_class(d_index, d_hash, class_name, class_loader); |
duke@435 | 1630 | |
duke@435 | 1631 | if (lookup == NULL) { |
duke@435 | 1632 | // Next try the placeholders |
duke@435 | 1633 | unsigned int p_hash = placeholders()->compute_hash(class_name,class_loader); |
duke@435 | 1634 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 1635 | lookup = find_placeholder(p_index, p_hash, class_name, class_loader); |
duke@435 | 1636 | } |
duke@435 | 1637 | |
duke@435 | 1638 | return lookup; |
duke@435 | 1639 | } |
duke@435 | 1640 | |
duke@435 | 1641 | |
duke@435 | 1642 | // Get the next class in the diictionary. |
duke@435 | 1643 | klassOop SystemDictionary::try_get_next_class() { |
duke@435 | 1644 | return dictionary()->try_get_next_class(); |
duke@435 | 1645 | } |
duke@435 | 1646 | |
duke@435 | 1647 | |
duke@435 | 1648 | // ---------------------------------------------------------------------------- |
duke@435 | 1649 | // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock |
duke@435 | 1650 | // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in |
duke@435 | 1651 | // before a new class is used. |
duke@435 | 1652 | |
duke@435 | 1653 | void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) { |
duke@435 | 1654 | assert(k.not_null(), "just checking"); |
duke@435 | 1655 | // Link into hierachy. Make sure the vtables are initialized before linking into |
duke@435 | 1656 | k->append_to_sibling_list(); // add to superklass/sibling list |
duke@435 | 1657 | k->process_interfaces(THREAD); // handle all "implements" declarations |
duke@435 | 1658 | k->set_init_state(instanceKlass::loaded); |
duke@435 | 1659 | // Now flush all code that depended on old class hierarchy. |
duke@435 | 1660 | // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) |
duke@435 | 1661 | // Also, first reinitialize vtable because it may have gotten out of synch |
duke@435 | 1662 | // while the new class wasn't connected to the class hierarchy. |
duke@435 | 1663 | Universe::flush_dependents_on(k); |
duke@435 | 1664 | } |
duke@435 | 1665 | |
duke@435 | 1666 | |
duke@435 | 1667 | // ---------------------------------------------------------------------------- |
duke@435 | 1668 | // GC support |
duke@435 | 1669 | |
duke@435 | 1670 | // Following roots during mark-sweep is separated in two phases. |
duke@435 | 1671 | // |
duke@435 | 1672 | // The first phase follows preloaded classes and all other system |
duke@435 | 1673 | // classes, since these will never get unloaded anyway. |
duke@435 | 1674 | // |
duke@435 | 1675 | // The second phase removes (unloads) unreachable classes from the |
duke@435 | 1676 | // system dictionary and follows the remaining classes' contents. |
duke@435 | 1677 | |
duke@435 | 1678 | void SystemDictionary::always_strong_oops_do(OopClosure* blk) { |
duke@435 | 1679 | // Follow preloaded classes/mirrors and system loader object |
duke@435 | 1680 | blk->do_oop(&_java_system_loader); |
duke@435 | 1681 | preloaded_oops_do(blk); |
duke@435 | 1682 | always_strong_classes_do(blk); |
duke@435 | 1683 | } |
duke@435 | 1684 | |
duke@435 | 1685 | |
duke@435 | 1686 | void SystemDictionary::always_strong_classes_do(OopClosure* blk) { |
duke@435 | 1687 | // Follow all system classes and temporary placeholders in dictionary |
duke@435 | 1688 | dictionary()->always_strong_classes_do(blk); |
duke@435 | 1689 | |
duke@435 | 1690 | // Placeholders. These are *always* strong roots, as they |
duke@435 | 1691 | // represent classes we're actively loading. |
duke@435 | 1692 | placeholders_do(blk); |
duke@435 | 1693 | |
duke@435 | 1694 | // Loader constraints. We must keep the symbolOop used in the name alive. |
duke@435 | 1695 | constraints()->always_strong_classes_do(blk); |
duke@435 | 1696 | |
duke@435 | 1697 | // Resolution errors keep the symbolOop for the error alive |
duke@435 | 1698 | resolution_errors()->always_strong_classes_do(blk); |
duke@435 | 1699 | } |
duke@435 | 1700 | |
duke@435 | 1701 | |
duke@435 | 1702 | void SystemDictionary::placeholders_do(OopClosure* blk) { |
duke@435 | 1703 | placeholders()->oops_do(blk); |
duke@435 | 1704 | } |
duke@435 | 1705 | |
duke@435 | 1706 | |
duke@435 | 1707 | bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) { |
duke@435 | 1708 | bool result = dictionary()->do_unloading(is_alive); |
duke@435 | 1709 | constraints()->purge_loader_constraints(is_alive); |
duke@435 | 1710 | resolution_errors()->purge_resolution_errors(is_alive); |
duke@435 | 1711 | return result; |
duke@435 | 1712 | } |
duke@435 | 1713 | |
duke@435 | 1714 | |
duke@435 | 1715 | // The mirrors are scanned by shared_oops_do() which is |
duke@435 | 1716 | // not called by oops_do(). In order to process oops in |
duke@435 | 1717 | // a necessary order, shared_oops_do() is call by |
duke@435 | 1718 | // Universe::oops_do(). |
duke@435 | 1719 | void SystemDictionary::oops_do(OopClosure* f) { |
duke@435 | 1720 | // Adjust preloaded classes and system loader object |
duke@435 | 1721 | f->do_oop(&_java_system_loader); |
duke@435 | 1722 | preloaded_oops_do(f); |
duke@435 | 1723 | |
duke@435 | 1724 | lazily_loaded_oops_do(f); |
duke@435 | 1725 | |
duke@435 | 1726 | // Adjust dictionary |
duke@435 | 1727 | dictionary()->oops_do(f); |
duke@435 | 1728 | |
duke@435 | 1729 | // Partially loaded classes |
duke@435 | 1730 | placeholders()->oops_do(f); |
duke@435 | 1731 | |
duke@435 | 1732 | // Adjust constraint table |
duke@435 | 1733 | constraints()->oops_do(f); |
duke@435 | 1734 | |
duke@435 | 1735 | // Adjust resolution error table |
duke@435 | 1736 | resolution_errors()->oops_do(f); |
duke@435 | 1737 | } |
duke@435 | 1738 | |
duke@435 | 1739 | |
duke@435 | 1740 | void SystemDictionary::preloaded_oops_do(OopClosure* f) { |
jrose@567 | 1741 | f->do_oop((oop*) &wk_klass_name_limits[0]); |
jrose@567 | 1742 | f->do_oop((oop*) &wk_klass_name_limits[1]); |
duke@435 | 1743 | |
jrose@567 | 1744 | for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) { |
jrose@567 | 1745 | f->do_oop((oop*) &_well_known_klasses[k]); |
jrose@567 | 1746 | } |
duke@435 | 1747 | |
duke@435 | 1748 | { |
duke@435 | 1749 | for (int i = 0; i < T_VOID+1; i++) { |
duke@435 | 1750 | if (_box_klasses[i] != NULL) { |
duke@435 | 1751 | assert(i >= T_BOOLEAN, "checking"); |
duke@435 | 1752 | f->do_oop((oop*) &_box_klasses[i]); |
duke@435 | 1753 | } |
duke@435 | 1754 | } |
duke@435 | 1755 | } |
duke@435 | 1756 | |
duke@435 | 1757 | // The basic type mirrors would have already been processed in |
duke@435 | 1758 | // Universe::oops_do(), via a call to shared_oops_do(), so should |
duke@435 | 1759 | // not be processed again. |
duke@435 | 1760 | |
duke@435 | 1761 | f->do_oop((oop*) &_system_loader_lock_obj); |
duke@435 | 1762 | FilteredFieldsMap::klasses_oops_do(f); |
duke@435 | 1763 | } |
duke@435 | 1764 | |
duke@435 | 1765 | void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) { |
duke@435 | 1766 | f->do_oop((oop*) &_abstract_ownable_synchronizer_klass); |
duke@435 | 1767 | } |
duke@435 | 1768 | |
duke@435 | 1769 | // Just the classes from defining class loaders |
duke@435 | 1770 | // Don't iterate over placeholders |
duke@435 | 1771 | void SystemDictionary::classes_do(void f(klassOop)) { |
duke@435 | 1772 | dictionary()->classes_do(f); |
duke@435 | 1773 | } |
duke@435 | 1774 | |
duke@435 | 1775 | // Added for initialize_itable_for_klass |
duke@435 | 1776 | // Just the classes from defining class loaders |
duke@435 | 1777 | // Don't iterate over placeholders |
duke@435 | 1778 | void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) { |
duke@435 | 1779 | dictionary()->classes_do(f, CHECK); |
duke@435 | 1780 | } |
duke@435 | 1781 | |
duke@435 | 1782 | // All classes, and their class loaders |
duke@435 | 1783 | // Don't iterate over placeholders |
duke@435 | 1784 | void SystemDictionary::classes_do(void f(klassOop, oop)) { |
duke@435 | 1785 | dictionary()->classes_do(f); |
duke@435 | 1786 | } |
duke@435 | 1787 | |
duke@435 | 1788 | // All classes, and their class loaders |
duke@435 | 1789 | // (added for helpers that use HandleMarks and ResourceMarks) |
duke@435 | 1790 | // Don't iterate over placeholders |
duke@435 | 1791 | void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) { |
duke@435 | 1792 | dictionary()->classes_do(f, CHECK); |
duke@435 | 1793 | } |
duke@435 | 1794 | |
duke@435 | 1795 | void SystemDictionary::placeholders_do(void f(symbolOop, oop)) { |
duke@435 | 1796 | placeholders()->entries_do(f); |
duke@435 | 1797 | } |
duke@435 | 1798 | |
duke@435 | 1799 | void SystemDictionary::methods_do(void f(methodOop)) { |
duke@435 | 1800 | dictionary()->methods_do(f); |
duke@435 | 1801 | } |
duke@435 | 1802 | |
duke@435 | 1803 | // ---------------------------------------------------------------------------- |
duke@435 | 1804 | // Lazily load klasses |
duke@435 | 1805 | |
duke@435 | 1806 | void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) { |
duke@435 | 1807 | assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later"); |
duke@435 | 1808 | |
duke@435 | 1809 | // if multiple threads calling this function, only one thread will load |
duke@435 | 1810 | // the class. The other threads will find the loaded version once the |
duke@435 | 1811 | // class is loaded. |
duke@435 | 1812 | klassOop aos = _abstract_ownable_synchronizer_klass; |
duke@435 | 1813 | if (aos == NULL) { |
duke@435 | 1814 | klassOop k = resolve_or_fail(vmSymbolHandles::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK); |
duke@435 | 1815 | // Force a fence to prevent any read before the write completes |
duke@435 | 1816 | OrderAccess::fence(); |
duke@435 | 1817 | _abstract_ownable_synchronizer_klass = k; |
duke@435 | 1818 | } |
duke@435 | 1819 | } |
duke@435 | 1820 | |
duke@435 | 1821 | // ---------------------------------------------------------------------------- |
duke@435 | 1822 | // Initialization |
duke@435 | 1823 | |
duke@435 | 1824 | void SystemDictionary::initialize(TRAPS) { |
duke@435 | 1825 | // Allocate arrays |
duke@435 | 1826 | assert(dictionary() == NULL, |
duke@435 | 1827 | "SystemDictionary should only be initialized once"); |
duke@435 | 1828 | _dictionary = new Dictionary(_nof_buckets); |
duke@435 | 1829 | _placeholders = new PlaceholderTable(_nof_buckets); |
duke@435 | 1830 | _number_of_modifications = 0; |
duke@435 | 1831 | _loader_constraints = new LoaderConstraintTable(_loader_constraint_size); |
duke@435 | 1832 | _resolution_errors = new ResolutionErrorTable(_resolution_error_size); |
duke@435 | 1833 | |
duke@435 | 1834 | // Allocate private object used as system class loader lock |
duke@435 | 1835 | _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK); |
duke@435 | 1836 | // Initialize basic classes |
duke@435 | 1837 | initialize_preloaded_classes(CHECK); |
duke@435 | 1838 | } |
duke@435 | 1839 | |
jrose@567 | 1840 | // Compact table of directions on the initialization of klasses: |
jrose@567 | 1841 | static const short wk_init_info[] = { |
jrose@567 | 1842 | #define WK_KLASS_INIT_INFO(name, symbol, option) \ |
jrose@567 | 1843 | ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \ |
jrose@567 | 1844 | << SystemDictionary::CEIL_LG_OPTION_LIMIT) \ |
jrose@567 | 1845 | | (int)SystemDictionary::option ), |
jrose@567 | 1846 | WK_KLASSES_DO(WK_KLASS_INIT_INFO) |
jrose@567 | 1847 | #undef WK_KLASS_INIT_INFO |
jrose@567 | 1848 | 0 |
jrose@567 | 1849 | }; |
jrose@567 | 1850 | |
jrose@567 | 1851 | bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) { |
jrose@567 | 1852 | assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
jrose@567 | 1853 | int info = wk_init_info[id - FIRST_WKID]; |
jrose@567 | 1854 | int sid = (info >> CEIL_LG_OPTION_LIMIT); |
jrose@567 | 1855 | symbolHandle symbol = vmSymbolHandles::symbol_handle_at((vmSymbols::SID)sid); |
jrose@567 | 1856 | klassOop* klassp = &_well_known_klasses[id]; |
jrose@567 | 1857 | bool must_load = (init_opt < SystemDictionary::Opt); |
jrose@567 | 1858 | bool try_load = true; |
jrose@567 | 1859 | if (init_opt == SystemDictionary::Opt_Kernel) { |
jrose@567 | 1860 | #ifndef KERNEL |
jrose@567 | 1861 | try_load = false; |
jrose@567 | 1862 | #endif //KERNEL |
jrose@567 | 1863 | } |
jrose@567 | 1864 | if ((*klassp) == NULL && try_load) { |
jrose@567 | 1865 | if (must_load) { |
jrose@567 | 1866 | (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class |
jrose@567 | 1867 | } else { |
jrose@567 | 1868 | (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass |
jrose@567 | 1869 | } |
jrose@567 | 1870 | } |
jrose@567 | 1871 | return ((*klassp) != NULL); |
jrose@567 | 1872 | } |
jrose@567 | 1873 | |
jrose@567 | 1874 | void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) { |
jrose@567 | 1875 | assert((int)start_id <= (int)limit_id, "IDs are out of order!"); |
jrose@567 | 1876 | for (int id = (int)start_id; id < (int)limit_id; id++) { |
jrose@567 | 1877 | assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob"); |
jrose@567 | 1878 | int info = wk_init_info[id - FIRST_WKID]; |
jrose@567 | 1879 | int sid = (info >> CEIL_LG_OPTION_LIMIT); |
jrose@567 | 1880 | int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT)); |
jrose@567 | 1881 | |
jrose@567 | 1882 | initialize_wk_klass((WKID)id, opt, CHECK); |
jrose@567 | 1883 | |
jrose@567 | 1884 | // Update limits, so find_well_known_klass can be very fast: |
jrose@567 | 1885 | symbolOop s = vmSymbols::symbol_at((vmSymbols::SID)sid); |
jrose@567 | 1886 | if (wk_klass_name_limits[1] == NULL) { |
jrose@567 | 1887 | wk_klass_name_limits[0] = wk_klass_name_limits[1] = s; |
jrose@567 | 1888 | } else if (wk_klass_name_limits[1] < s) { |
jrose@567 | 1889 | wk_klass_name_limits[1] = s; |
jrose@567 | 1890 | } else if (wk_klass_name_limits[0] > s) { |
jrose@567 | 1891 | wk_klass_name_limits[0] = s; |
jrose@567 | 1892 | } |
jrose@567 | 1893 | } |
jrose@567 | 1894 | } |
jrose@567 | 1895 | |
duke@435 | 1896 | |
duke@435 | 1897 | void SystemDictionary::initialize_preloaded_classes(TRAPS) { |
jrose@567 | 1898 | assert(WK_KLASS(object_klass) == NULL, "preloaded classes should only be initialized once"); |
duke@435 | 1899 | // Preload commonly used klasses |
jrose@567 | 1900 | WKID scan = FIRST_WKID; |
jrose@567 | 1901 | // first do Object, String, Class |
jrose@567 | 1902 | initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(class_klass), scan, CHECK); |
jrose@567 | 1903 | |
jrose@567 | 1904 | debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(class_klass))); |
jrose@567 | 1905 | |
duke@435 | 1906 | // Fixup mirrors for classes loaded before java.lang.Class. |
duke@435 | 1907 | // These calls iterate over the objects currently in the perm gen |
duke@435 | 1908 | // so calling them at this point is matters (not before when there |
duke@435 | 1909 | // are fewer objects and not later after there are more objects |
duke@435 | 1910 | // in the perm gen. |
duke@435 | 1911 | Universe::initialize_basic_type_mirrors(CHECK); |
duke@435 | 1912 | Universe::fixup_mirrors(CHECK); |
duke@435 | 1913 | |
jrose@567 | 1914 | // do a bunch more: |
jrose@567 | 1915 | initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(reference_klass), scan, CHECK); |
duke@435 | 1916 | |
duke@435 | 1917 | // Preload ref klasses and set reference types |
jrose@567 | 1918 | instanceKlass::cast(WK_KLASS(reference_klass))->set_reference_type(REF_OTHER); |
jrose@567 | 1919 | instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(reference_klass)); |
duke@435 | 1920 | |
jrose@567 | 1921 | initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(phantom_reference_klass), scan, CHECK); |
jrose@567 | 1922 | instanceKlass::cast(WK_KLASS(soft_reference_klass))->set_reference_type(REF_SOFT); |
jrose@567 | 1923 | instanceKlass::cast(WK_KLASS(weak_reference_klass))->set_reference_type(REF_WEAK); |
jrose@567 | 1924 | instanceKlass::cast(WK_KLASS(final_reference_klass))->set_reference_type(REF_FINAL); |
jrose@567 | 1925 | instanceKlass::cast(WK_KLASS(phantom_reference_klass))->set_reference_type(REF_PHANTOM); |
duke@435 | 1926 | |
jrose@567 | 1927 | initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK); |
duke@435 | 1928 | |
jrose@567 | 1929 | _box_klasses[T_BOOLEAN] = WK_KLASS(boolean_klass); |
jrose@567 | 1930 | _box_klasses[T_CHAR] = WK_KLASS(char_klass); |
jrose@567 | 1931 | _box_klasses[T_FLOAT] = WK_KLASS(float_klass); |
jrose@567 | 1932 | _box_klasses[T_DOUBLE] = WK_KLASS(double_klass); |
jrose@567 | 1933 | _box_klasses[T_BYTE] = WK_KLASS(byte_klass); |
jrose@567 | 1934 | _box_klasses[T_SHORT] = WK_KLASS(short_klass); |
jrose@567 | 1935 | _box_klasses[T_INT] = WK_KLASS(int_klass); |
jrose@567 | 1936 | _box_klasses[T_LONG] = WK_KLASS(long_klass); |
jrose@567 | 1937 | //_box_klasses[T_OBJECT] = WK_KLASS(object_klass); |
jrose@567 | 1938 | //_box_klasses[T_ARRAY] = WK_KLASS(object_klass); |
duke@435 | 1939 | |
duke@435 | 1940 | #ifdef KERNEL |
jrose@567 | 1941 | if (sun_jkernel_DownloadManager_klass() == NULL) { |
duke@435 | 1942 | warning("Cannot find sun/jkernel/DownloadManager"); |
duke@435 | 1943 | } |
duke@435 | 1944 | #endif // KERNEL |
acorn@949 | 1945 | |
duke@435 | 1946 | { // Compute whether we should use loadClass or loadClassInternal when loading classes. |
duke@435 | 1947 | methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature()); |
duke@435 | 1948 | _has_loadClassInternal = (method != NULL); |
duke@435 | 1949 | } |
duke@435 | 1950 | { // Compute whether we should use checkPackageAccess or NOT |
duke@435 | 1951 | methodOop method = instanceKlass::cast(classloader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature()); |
duke@435 | 1952 | _has_checkPackageAccess = (method != NULL); |
duke@435 | 1953 | } |
duke@435 | 1954 | } |
duke@435 | 1955 | |
duke@435 | 1956 | // Tells if a given klass is a box (wrapper class, such as java.lang.Integer). |
duke@435 | 1957 | // If so, returns the basic type it holds. If not, returns T_OBJECT. |
duke@435 | 1958 | BasicType SystemDictionary::box_klass_type(klassOop k) { |
duke@435 | 1959 | assert(k != NULL, ""); |
duke@435 | 1960 | for (int i = T_BOOLEAN; i < T_VOID+1; i++) { |
duke@435 | 1961 | if (_box_klasses[i] == k) |
duke@435 | 1962 | return (BasicType)i; |
duke@435 | 1963 | } |
duke@435 | 1964 | return T_OBJECT; |
duke@435 | 1965 | } |
duke@435 | 1966 | |
duke@435 | 1967 | // Constraints on class loaders. The details of the algorithm can be |
duke@435 | 1968 | // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java |
duke@435 | 1969 | // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is |
duke@435 | 1970 | // that the system dictionary needs to maintain a set of contraints that |
duke@435 | 1971 | // must be satisfied by all classes in the dictionary. |
duke@435 | 1972 | // if defining is true, then LinkageError if already in systemDictionary |
duke@435 | 1973 | // if initiating loader, then ok if instanceKlass matches existing entry |
duke@435 | 1974 | |
duke@435 | 1975 | void SystemDictionary::check_constraints(int d_index, unsigned int d_hash, |
duke@435 | 1976 | instanceKlassHandle k, |
duke@435 | 1977 | Handle class_loader, bool defining, |
duke@435 | 1978 | TRAPS) { |
duke@435 | 1979 | const char *linkage_error = NULL; |
duke@435 | 1980 | { |
duke@435 | 1981 | symbolHandle name (THREAD, k->name()); |
duke@435 | 1982 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 1983 | |
duke@435 | 1984 | klassOop check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 1985 | if (check != (klassOop)NULL) { |
duke@435 | 1986 | // if different instanceKlass - duplicate class definition, |
duke@435 | 1987 | // else - ok, class loaded by a different thread in parallel, |
duke@435 | 1988 | // we should only have found it if it was done loading and ok to use |
duke@435 | 1989 | // system dictionary only holds instance classes, placeholders |
duke@435 | 1990 | // also holds array classes |
duke@435 | 1991 | |
duke@435 | 1992 | assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary"); |
duke@435 | 1993 | if ((defining == true) || (k() != check)) { |
duke@435 | 1994 | linkage_error = "loader (instance of %s): attempted duplicate class " |
duke@435 | 1995 | "definition for name: \"%s\""; |
duke@435 | 1996 | } else { |
duke@435 | 1997 | return; |
duke@435 | 1998 | } |
duke@435 | 1999 | } |
duke@435 | 2000 | |
duke@435 | 2001 | #ifdef ASSERT |
duke@435 | 2002 | unsigned int p_hash = placeholders()->compute_hash(name, class_loader); |
duke@435 | 2003 | int p_index = placeholders()->hash_to_index(p_hash); |
duke@435 | 2004 | symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); |
duke@435 | 2005 | assert(ph_check == NULL || ph_check == name(), "invalid symbol"); |
duke@435 | 2006 | #endif |
duke@435 | 2007 | |
duke@435 | 2008 | if (linkage_error == NULL) { |
duke@435 | 2009 | if (constraints()->check_or_update(k, class_loader, name) == false) { |
duke@435 | 2010 | linkage_error = "loader constraint violation: loader (instance of %s)" |
duke@435 | 2011 | " previously initiated loading for a different type with name \"%s\""; |
duke@435 | 2012 | } |
duke@435 | 2013 | } |
duke@435 | 2014 | } |
duke@435 | 2015 | |
duke@435 | 2016 | // Throw error now if needed (cannot throw while holding |
duke@435 | 2017 | // SystemDictionary_lock because of rank ordering) |
duke@435 | 2018 | |
duke@435 | 2019 | if (linkage_error) { |
duke@435 | 2020 | ResourceMark rm(THREAD); |
duke@435 | 2021 | const char* class_loader_name = loader_name(class_loader()); |
duke@435 | 2022 | char* type_name = k->name()->as_C_string(); |
duke@435 | 2023 | size_t buflen = strlen(linkage_error) + strlen(class_loader_name) + |
duke@435 | 2024 | strlen(type_name); |
duke@435 | 2025 | char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen); |
duke@435 | 2026 | jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name); |
duke@435 | 2027 | THROW_MSG(vmSymbols::java_lang_LinkageError(), buf); |
duke@435 | 2028 | } |
duke@435 | 2029 | } |
duke@435 | 2030 | |
duke@435 | 2031 | |
duke@435 | 2032 | // Update system dictionary - done after check_constraint and add_to_hierachy |
duke@435 | 2033 | // have been called. |
duke@435 | 2034 | void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash, |
duke@435 | 2035 | int p_index, unsigned int p_hash, |
duke@435 | 2036 | instanceKlassHandle k, |
duke@435 | 2037 | Handle class_loader, |
duke@435 | 2038 | TRAPS) { |
duke@435 | 2039 | // Compile_lock prevents systemDictionary updates during compilations |
duke@435 | 2040 | assert_locked_or_safepoint(Compile_lock); |
duke@435 | 2041 | symbolHandle name (THREAD, k->name()); |
duke@435 | 2042 | |
duke@435 | 2043 | { |
duke@435 | 2044 | MutexLocker mu1(SystemDictionary_lock, THREAD); |
duke@435 | 2045 | |
duke@435 | 2046 | // See whether biased locking is enabled and if so set it for this |
duke@435 | 2047 | // klass. |
duke@435 | 2048 | // Note that this must be done past the last potential blocking |
duke@435 | 2049 | // point / safepoint. We enable biased locking lazily using a |
duke@435 | 2050 | // VM_Operation to iterate the SystemDictionary and installing the |
duke@435 | 2051 | // biasable mark word into each instanceKlass's prototype header. |
duke@435 | 2052 | // To avoid race conditions where we accidentally miss enabling the |
duke@435 | 2053 | // optimization for one class in the process of being added to the |
duke@435 | 2054 | // dictionary, we must not safepoint after the test of |
duke@435 | 2055 | // BiasedLocking::enabled(). |
duke@435 | 2056 | if (UseBiasedLocking && BiasedLocking::enabled()) { |
duke@435 | 2057 | // Set biased locking bit for all loaded classes; it will be |
duke@435 | 2058 | // cleared if revocation occurs too often for this type |
duke@435 | 2059 | // NOTE that we must only do this when the class is initally |
duke@435 | 2060 | // defined, not each time it is referenced from a new class loader |
duke@435 | 2061 | if (k->class_loader() == class_loader()) { |
duke@435 | 2062 | k->set_prototype_header(markOopDesc::biased_locking_prototype()); |
duke@435 | 2063 | } |
duke@435 | 2064 | } |
duke@435 | 2065 | |
duke@435 | 2066 | // Check for a placeholder. If there, remove it and make a |
duke@435 | 2067 | // new system dictionary entry. |
duke@435 | 2068 | placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD); |
duke@435 | 2069 | klassOop sd_check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 2070 | if (sd_check == NULL) { |
duke@435 | 2071 | dictionary()->add_klass(name, class_loader, k); |
duke@435 | 2072 | notice_modification(); |
duke@435 | 2073 | } |
duke@435 | 2074 | #ifdef ASSERT |
duke@435 | 2075 | sd_check = find_class(d_index, d_hash, name, class_loader); |
duke@435 | 2076 | assert (sd_check != NULL, "should have entry in system dictionary"); |
duke@435 | 2077 | // Changed to allow PH to remain to complete class circularity checking |
duke@435 | 2078 | // while only one thread can define a class at one time, multiple |
duke@435 | 2079 | // classes can resolve the superclass for a class at one time, |
duke@435 | 2080 | // and the placeholder is used to track that |
duke@435 | 2081 | // symbolOop ph_check = find_placeholder(p_index, p_hash, name, class_loader); |
duke@435 | 2082 | // assert (ph_check == NULL, "should not have a placeholder entry"); |
duke@435 | 2083 | #endif |
duke@435 | 2084 | SystemDictionary_lock->notify_all(); |
duke@435 | 2085 | } |
duke@435 | 2086 | } |
duke@435 | 2087 | |
duke@435 | 2088 | |
duke@435 | 2089 | klassOop SystemDictionary::find_constrained_instance_or_array_klass( |
duke@435 | 2090 | symbolHandle class_name, Handle class_loader, TRAPS) { |
duke@435 | 2091 | |
duke@435 | 2092 | // First see if it has been loaded directly. |
duke@435 | 2093 | // Force the protection domain to be null. (This removes protection checks.) |
duke@435 | 2094 | Handle no_protection_domain; |
duke@435 | 2095 | klassOop klass = find_instance_or_array_klass(class_name, class_loader, |
duke@435 | 2096 | no_protection_domain, CHECK_NULL); |
duke@435 | 2097 | if (klass != NULL) |
duke@435 | 2098 | return klass; |
duke@435 | 2099 | |
duke@435 | 2100 | // Now look to see if it has been loaded elsewhere, and is subject to |
duke@435 | 2101 | // a loader constraint that would require this loader to return the |
duke@435 | 2102 | // klass that is already loaded. |
duke@435 | 2103 | if (FieldType::is_array(class_name())) { |
duke@435 | 2104 | // Array classes are hard because their klassOops are not kept in the |
duke@435 | 2105 | // constraint table. The array klass may be constrained, but the elem class |
duke@435 | 2106 | // may not be. |
duke@435 | 2107 | jint dimension; |
duke@435 | 2108 | symbolOop object_key; |
duke@435 | 2109 | BasicType t = FieldType::get_array_info(class_name(), &dimension, |
duke@435 | 2110 | &object_key, CHECK_(NULL)); |
duke@435 | 2111 | if (t != T_OBJECT) { |
duke@435 | 2112 | klass = Universe::typeArrayKlassObj(t); |
duke@435 | 2113 | } else { |
duke@435 | 2114 | symbolHandle elem_name(THREAD, object_key); |
duke@435 | 2115 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 2116 | klass = constraints()->find_constrained_elem_klass(class_name, elem_name, class_loader, THREAD); |
duke@435 | 2117 | } |
duke@435 | 2118 | if (klass != NULL) { |
duke@435 | 2119 | klass = Klass::cast(klass)->array_klass_or_null(dimension); |
duke@435 | 2120 | } |
duke@435 | 2121 | } else { |
duke@435 | 2122 | MutexLocker mu(SystemDictionary_lock, THREAD); |
duke@435 | 2123 | // Non-array classes are easy: simply check the constraint table. |
duke@435 | 2124 | klass = constraints()->find_constrained_klass(class_name, class_loader); |
duke@435 | 2125 | } |
duke@435 | 2126 | |
duke@435 | 2127 | return klass; |
duke@435 | 2128 | } |
duke@435 | 2129 | |
duke@435 | 2130 | |
duke@435 | 2131 | bool SystemDictionary::add_loader_constraint(symbolHandle class_name, |
duke@435 | 2132 | Handle class_loader1, |
duke@435 | 2133 | Handle class_loader2, |
duke@435 | 2134 | Thread* THREAD) { |
duke@435 | 2135 | unsigned int d_hash1 = dictionary()->compute_hash(class_name, class_loader1); |
duke@435 | 2136 | int d_index1 = dictionary()->hash_to_index(d_hash1); |
duke@435 | 2137 | |
duke@435 | 2138 | unsigned int d_hash2 = dictionary()->compute_hash(class_name, class_loader2); |
duke@435 | 2139 | int d_index2 = dictionary()->hash_to_index(d_hash2); |
duke@435 | 2140 | |
duke@435 | 2141 | { |
duke@435 | 2142 | MutexLocker mu_s(SystemDictionary_lock, THREAD); |
duke@435 | 2143 | |
duke@435 | 2144 | // Better never do a GC while we're holding these oops |
duke@435 | 2145 | No_Safepoint_Verifier nosafepoint; |
duke@435 | 2146 | |
duke@435 | 2147 | klassOop klass1 = find_class(d_index1, d_hash1, class_name, class_loader1); |
duke@435 | 2148 | klassOop klass2 = find_class(d_index2, d_hash2, class_name, class_loader2); |
duke@435 | 2149 | return constraints()->add_entry(class_name, klass1, class_loader1, |
duke@435 | 2150 | klass2, class_loader2); |
duke@435 | 2151 | } |
duke@435 | 2152 | } |
duke@435 | 2153 | |
duke@435 | 2154 | // Add entry to resolution error table to record the error when the first |
duke@435 | 2155 | // attempt to resolve a reference to a class has failed. |
duke@435 | 2156 | void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, symbolHandle error) { |
duke@435 | 2157 | unsigned int hash = resolution_errors()->compute_hash(pool, which); |
duke@435 | 2158 | int index = resolution_errors()->hash_to_index(hash); |
duke@435 | 2159 | { |
duke@435 | 2160 | MutexLocker ml(SystemDictionary_lock, Thread::current()); |
duke@435 | 2161 | resolution_errors()->add_entry(index, hash, pool, which, error); |
duke@435 | 2162 | } |
duke@435 | 2163 | } |
duke@435 | 2164 | |
duke@435 | 2165 | // Lookup resolution error table. Returns error if found, otherwise NULL. |
duke@435 | 2166 | symbolOop SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) { |
duke@435 | 2167 | unsigned int hash = resolution_errors()->compute_hash(pool, which); |
duke@435 | 2168 | int index = resolution_errors()->hash_to_index(hash); |
duke@435 | 2169 | { |
duke@435 | 2170 | MutexLocker ml(SystemDictionary_lock, Thread::current()); |
duke@435 | 2171 | ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which); |
duke@435 | 2172 | return (entry != NULL) ? entry->error() : (symbolOop)NULL; |
duke@435 | 2173 | } |
duke@435 | 2174 | } |
duke@435 | 2175 | |
duke@435 | 2176 | |
duke@435 | 2177 | // Make sure all class components (including arrays) in the given |
duke@435 | 2178 | // signature will be resolved to the same class in both loaders. |
duke@435 | 2179 | // Returns the name of the type that failed a loader constraint check, or |
duke@435 | 2180 | // NULL if no constraint failed. The returned C string needs cleaning up |
duke@435 | 2181 | // with a ResourceMark in the caller |
duke@435 | 2182 | char* SystemDictionary::check_signature_loaders(symbolHandle signature, |
duke@435 | 2183 | Handle loader1, Handle loader2, |
duke@435 | 2184 | bool is_method, TRAPS) { |
duke@435 | 2185 | // Nothing to do if loaders are the same. |
duke@435 | 2186 | if (loader1() == loader2()) { |
duke@435 | 2187 | return NULL; |
duke@435 | 2188 | } |
duke@435 | 2189 | |
duke@435 | 2190 | SignatureStream sig_strm(signature, is_method); |
duke@435 | 2191 | while (!sig_strm.is_done()) { |
duke@435 | 2192 | if (sig_strm.is_object()) { |
duke@435 | 2193 | symbolOop s = sig_strm.as_symbol(CHECK_NULL); |
duke@435 | 2194 | symbolHandle sig (THREAD, s); |
duke@435 | 2195 | if (!add_loader_constraint(sig, loader1, loader2, THREAD)) { |
duke@435 | 2196 | return sig()->as_C_string(); |
duke@435 | 2197 | } |
duke@435 | 2198 | } |
duke@435 | 2199 | sig_strm.next(); |
duke@435 | 2200 | } |
duke@435 | 2201 | return NULL; |
duke@435 | 2202 | } |
duke@435 | 2203 | |
duke@435 | 2204 | |
duke@435 | 2205 | // Since the identity hash code for symbols changes when the symbols are |
duke@435 | 2206 | // moved from the regular perm gen (hash in the mark word) to the shared |
duke@435 | 2207 | // spaces (hash is the address), the classes loaded into the dictionary |
duke@435 | 2208 | // may be in the wrong buckets. |
duke@435 | 2209 | |
duke@435 | 2210 | void SystemDictionary::reorder_dictionary() { |
duke@435 | 2211 | dictionary()->reorder_dictionary(); |
duke@435 | 2212 | } |
duke@435 | 2213 | |
duke@435 | 2214 | |
duke@435 | 2215 | void SystemDictionary::copy_buckets(char** top, char* end) { |
duke@435 | 2216 | dictionary()->copy_buckets(top, end); |
duke@435 | 2217 | } |
duke@435 | 2218 | |
duke@435 | 2219 | |
duke@435 | 2220 | void SystemDictionary::copy_table(char** top, char* end) { |
duke@435 | 2221 | dictionary()->copy_table(top, end); |
duke@435 | 2222 | } |
duke@435 | 2223 | |
duke@435 | 2224 | |
duke@435 | 2225 | void SystemDictionary::reverse() { |
duke@435 | 2226 | dictionary()->reverse(); |
duke@435 | 2227 | } |
duke@435 | 2228 | |
duke@435 | 2229 | int SystemDictionary::number_of_classes() { |
duke@435 | 2230 | return dictionary()->number_of_entries(); |
duke@435 | 2231 | } |
duke@435 | 2232 | |
duke@435 | 2233 | |
duke@435 | 2234 | // ---------------------------------------------------------------------------- |
duke@435 | 2235 | #ifndef PRODUCT |
duke@435 | 2236 | |
duke@435 | 2237 | void SystemDictionary::print() { |
duke@435 | 2238 | dictionary()->print(); |
duke@435 | 2239 | |
duke@435 | 2240 | // Placeholders |
duke@435 | 2241 | GCMutexLocker mu(SystemDictionary_lock); |
duke@435 | 2242 | placeholders()->print(); |
duke@435 | 2243 | |
duke@435 | 2244 | // loader constraints - print under SD_lock |
duke@435 | 2245 | constraints()->print(); |
duke@435 | 2246 | } |
duke@435 | 2247 | |
duke@435 | 2248 | #endif |
duke@435 | 2249 | |
duke@435 | 2250 | void SystemDictionary::verify() { |
duke@435 | 2251 | guarantee(dictionary() != NULL, "Verify of system dictionary failed"); |
duke@435 | 2252 | guarantee(constraints() != NULL, |
duke@435 | 2253 | "Verify of loader constraints failed"); |
duke@435 | 2254 | guarantee(dictionary()->number_of_entries() >= 0 && |
duke@435 | 2255 | placeholders()->number_of_entries() >= 0, |
duke@435 | 2256 | "Verify of system dictionary failed"); |
duke@435 | 2257 | |
duke@435 | 2258 | // Verify dictionary |
duke@435 | 2259 | dictionary()->verify(); |
duke@435 | 2260 | |
duke@435 | 2261 | GCMutexLocker mu(SystemDictionary_lock); |
duke@435 | 2262 | placeholders()->verify(); |
duke@435 | 2263 | |
duke@435 | 2264 | // Verify constraint table |
duke@435 | 2265 | guarantee(constraints() != NULL, "Verify of loader constraints failed"); |
duke@435 | 2266 | constraints()->verify(dictionary()); |
duke@435 | 2267 | } |
duke@435 | 2268 | |
duke@435 | 2269 | |
duke@435 | 2270 | void SystemDictionary::verify_obj_klass_present(Handle obj, |
duke@435 | 2271 | symbolHandle class_name, |
duke@435 | 2272 | Handle class_loader) { |
duke@435 | 2273 | GCMutexLocker mu(SystemDictionary_lock); |
duke@435 | 2274 | oop probe = find_class_or_placeholder(class_name, class_loader); |
duke@435 | 2275 | if (probe == NULL) { |
duke@435 | 2276 | probe = SystemDictionary::find_shared_class(class_name); |
duke@435 | 2277 | } |
duke@435 | 2278 | guarantee(probe != NULL && |
duke@435 | 2279 | (!probe->is_klass() || probe == obj()), |
duke@435 | 2280 | "Loaded klasses should be in SystemDictionary"); |
duke@435 | 2281 | } |
duke@435 | 2282 | |
duke@435 | 2283 | #ifndef PRODUCT |
duke@435 | 2284 | |
duke@435 | 2285 | // statistics code |
duke@435 | 2286 | class ClassStatistics: AllStatic { |
duke@435 | 2287 | private: |
duke@435 | 2288 | static int nclasses; // number of classes |
duke@435 | 2289 | static int nmethods; // number of methods |
duke@435 | 2290 | static int nmethoddata; // number of methodData |
duke@435 | 2291 | static int class_size; // size of class objects in words |
duke@435 | 2292 | static int method_size; // size of method objects in words |
duke@435 | 2293 | static int debug_size; // size of debug info in methods |
duke@435 | 2294 | static int methoddata_size; // size of methodData objects in words |
duke@435 | 2295 | |
duke@435 | 2296 | static void do_class(klassOop k) { |
duke@435 | 2297 | nclasses++; |
duke@435 | 2298 | class_size += k->size(); |
duke@435 | 2299 | if (k->klass_part()->oop_is_instance()) { |
duke@435 | 2300 | instanceKlass* ik = (instanceKlass*)k->klass_part(); |
duke@435 | 2301 | class_size += ik->methods()->size(); |
duke@435 | 2302 | class_size += ik->constants()->size(); |
duke@435 | 2303 | class_size += ik->local_interfaces()->size(); |
duke@435 | 2304 | class_size += ik->transitive_interfaces()->size(); |
duke@435 | 2305 | // We do not have to count implementors, since we only store one! |
duke@435 | 2306 | class_size += ik->fields()->size(); |
duke@435 | 2307 | } |
duke@435 | 2308 | } |
duke@435 | 2309 | |
duke@435 | 2310 | static void do_method(methodOop m) { |
duke@435 | 2311 | nmethods++; |
duke@435 | 2312 | method_size += m->size(); |
duke@435 | 2313 | // class loader uses same objArray for empty vectors, so don't count these |
duke@435 | 2314 | if (m->exception_table()->length() != 0) method_size += m->exception_table()->size(); |
duke@435 | 2315 | if (m->has_stackmap_table()) { |
duke@435 | 2316 | method_size += m->stackmap_data()->size(); |
duke@435 | 2317 | } |
duke@435 | 2318 | |
duke@435 | 2319 | methodDataOop mdo = m->method_data(); |
duke@435 | 2320 | if (mdo != NULL) { |
duke@435 | 2321 | nmethoddata++; |
duke@435 | 2322 | methoddata_size += mdo->size(); |
duke@435 | 2323 | } |
duke@435 | 2324 | } |
duke@435 | 2325 | |
duke@435 | 2326 | public: |
duke@435 | 2327 | static void print() { |
duke@435 | 2328 | SystemDictionary::classes_do(do_class); |
duke@435 | 2329 | SystemDictionary::methods_do(do_method); |
duke@435 | 2330 | tty->print_cr("Class statistics:"); |
duke@435 | 2331 | tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize); |
duke@435 | 2332 | tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods, |
duke@435 | 2333 | (method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize); |
duke@435 | 2334 | tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize); |
duke@435 | 2335 | } |
duke@435 | 2336 | }; |
duke@435 | 2337 | |
duke@435 | 2338 | |
duke@435 | 2339 | int ClassStatistics::nclasses = 0; |
duke@435 | 2340 | int ClassStatistics::nmethods = 0; |
duke@435 | 2341 | int ClassStatistics::nmethoddata = 0; |
duke@435 | 2342 | int ClassStatistics::class_size = 0; |
duke@435 | 2343 | int ClassStatistics::method_size = 0; |
duke@435 | 2344 | int ClassStatistics::debug_size = 0; |
duke@435 | 2345 | int ClassStatistics::methoddata_size = 0; |
duke@435 | 2346 | |
duke@435 | 2347 | void SystemDictionary::print_class_statistics() { |
duke@435 | 2348 | ResourceMark rm; |
duke@435 | 2349 | ClassStatistics::print(); |
duke@435 | 2350 | } |
duke@435 | 2351 | |
duke@435 | 2352 | |
duke@435 | 2353 | class MethodStatistics: AllStatic { |
duke@435 | 2354 | public: |
duke@435 | 2355 | enum { |
duke@435 | 2356 | max_parameter_size = 10 |
duke@435 | 2357 | }; |
duke@435 | 2358 | private: |
duke@435 | 2359 | |
duke@435 | 2360 | static int _number_of_methods; |
duke@435 | 2361 | static int _number_of_final_methods; |
duke@435 | 2362 | static int _number_of_static_methods; |
duke@435 | 2363 | static int _number_of_native_methods; |
duke@435 | 2364 | static int _number_of_synchronized_methods; |
duke@435 | 2365 | static int _number_of_profiled_methods; |
duke@435 | 2366 | static int _number_of_bytecodes; |
duke@435 | 2367 | static int _parameter_size_profile[max_parameter_size]; |
duke@435 | 2368 | static int _bytecodes_profile[Bytecodes::number_of_java_codes]; |
duke@435 | 2369 | |
duke@435 | 2370 | static void initialize() { |
duke@435 | 2371 | _number_of_methods = 0; |
duke@435 | 2372 | _number_of_final_methods = 0; |
duke@435 | 2373 | _number_of_static_methods = 0; |
duke@435 | 2374 | _number_of_native_methods = 0; |
duke@435 | 2375 | _number_of_synchronized_methods = 0; |
duke@435 | 2376 | _number_of_profiled_methods = 0; |
duke@435 | 2377 | _number_of_bytecodes = 0; |
duke@435 | 2378 | for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0; |
duke@435 | 2379 | for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0; |
duke@435 | 2380 | }; |
duke@435 | 2381 | |
duke@435 | 2382 | static void do_method(methodOop m) { |
duke@435 | 2383 | _number_of_methods++; |
duke@435 | 2384 | // collect flag info |
duke@435 | 2385 | if (m->is_final() ) _number_of_final_methods++; |
duke@435 | 2386 | if (m->is_static() ) _number_of_static_methods++; |
duke@435 | 2387 | if (m->is_native() ) _number_of_native_methods++; |
duke@435 | 2388 | if (m->is_synchronized()) _number_of_synchronized_methods++; |
duke@435 | 2389 | if (m->method_data() != NULL) _number_of_profiled_methods++; |
duke@435 | 2390 | // collect parameter size info (add one for receiver, if any) |
duke@435 | 2391 | _parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++; |
duke@435 | 2392 | // collect bytecodes info |
duke@435 | 2393 | { |
duke@435 | 2394 | Thread *thread = Thread::current(); |
duke@435 | 2395 | HandleMark hm(thread); |
duke@435 | 2396 | BytecodeStream s(methodHandle(thread, m)); |
duke@435 | 2397 | Bytecodes::Code c; |
duke@435 | 2398 | while ((c = s.next()) >= 0) { |
duke@435 | 2399 | _number_of_bytecodes++; |
duke@435 | 2400 | _bytecodes_profile[c]++; |
duke@435 | 2401 | } |
duke@435 | 2402 | } |
duke@435 | 2403 | } |
duke@435 | 2404 | |
duke@435 | 2405 | public: |
duke@435 | 2406 | static void print() { |
duke@435 | 2407 | initialize(); |
duke@435 | 2408 | SystemDictionary::methods_do(do_method); |
duke@435 | 2409 | // generate output |
duke@435 | 2410 | tty->cr(); |
duke@435 | 2411 | tty->print_cr("Method statistics (static):"); |
duke@435 | 2412 | // flag distribution |
duke@435 | 2413 | tty->cr(); |
duke@435 | 2414 | tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods); |
duke@435 | 2415 | tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods); |
duke@435 | 2416 | tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods); |
duke@435 | 2417 | tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods); |
duke@435 | 2418 | tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods); |
duke@435 | 2419 | // parameter size profile |
duke@435 | 2420 | tty->cr(); |
duke@435 | 2421 | { int tot = 0; |
duke@435 | 2422 | int avg = 0; |
duke@435 | 2423 | for (int i = 0; i < max_parameter_size; i++) { |
duke@435 | 2424 | int n = _parameter_size_profile[i]; |
duke@435 | 2425 | tot += n; |
duke@435 | 2426 | avg += n*i; |
duke@435 | 2427 | tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods); |
duke@435 | 2428 | } |
duke@435 | 2429 | assert(tot == _number_of_methods, "should be the same"); |
duke@435 | 2430 | tty->print_cr(" %6d methods 100.0%%", _number_of_methods); |
duke@435 | 2431 | tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods); |
duke@435 | 2432 | } |
duke@435 | 2433 | // bytecodes profile |
duke@435 | 2434 | tty->cr(); |
duke@435 | 2435 | { int tot = 0; |
duke@435 | 2436 | for (int i = 0; i < Bytecodes::number_of_java_codes; i++) { |
duke@435 | 2437 | if (Bytecodes::is_defined(i)) { |
duke@435 | 2438 | Bytecodes::Code c = Bytecodes::cast(i); |
duke@435 | 2439 | int n = _bytecodes_profile[c]; |
duke@435 | 2440 | tot += n; |
duke@435 | 2441 | tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c)); |
duke@435 | 2442 | } |
duke@435 | 2443 | } |
duke@435 | 2444 | assert(tot == _number_of_bytecodes, "should be the same"); |
duke@435 | 2445 | tty->print_cr("%9d 100.000%%", _number_of_bytecodes); |
duke@435 | 2446 | } |
duke@435 | 2447 | tty->cr(); |
duke@435 | 2448 | } |
duke@435 | 2449 | }; |
duke@435 | 2450 | |
duke@435 | 2451 | int MethodStatistics::_number_of_methods; |
duke@435 | 2452 | int MethodStatistics::_number_of_final_methods; |
duke@435 | 2453 | int MethodStatistics::_number_of_static_methods; |
duke@435 | 2454 | int MethodStatistics::_number_of_native_methods; |
duke@435 | 2455 | int MethodStatistics::_number_of_synchronized_methods; |
duke@435 | 2456 | int MethodStatistics::_number_of_profiled_methods; |
duke@435 | 2457 | int MethodStatistics::_number_of_bytecodes; |
duke@435 | 2458 | int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size]; |
duke@435 | 2459 | int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes]; |
duke@435 | 2460 | |
duke@435 | 2461 | |
duke@435 | 2462 | void SystemDictionary::print_method_statistics() { |
duke@435 | 2463 | MethodStatistics::print(); |
duke@435 | 2464 | } |
duke@435 | 2465 | |
duke@435 | 2466 | #endif // PRODUCT |