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