src/share/vm/classfile/systemDictionary.cpp

Tue, 22 Mar 2011 13:36:33 -0700

author
jcoomes
date
Tue, 22 Mar 2011 13:36:33 -0700
changeset 2661
b099aaf51bf8
parent 2639
8033953d67ff
child 2698
38fea01eb669
permissions
-rw-r--r--

6962931: move interned strings out of the perm gen
Reviewed-by: never, coleenp, ysr, jwilhelm

duke@435 1 /*
jrose@2638 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #include "precompiled.hpp"
stefank@2314 26 #include "classfile/dictionary.hpp"
stefank@2314 27 #include "classfile/javaClasses.hpp"
stefank@2314 28 #include "classfile/loaderConstraints.hpp"
stefank@2314 29 #include "classfile/placeholders.hpp"
stefank@2314 30 #include "classfile/resolutionErrors.hpp"
stefank@2314 31 #include "classfile/systemDictionary.hpp"
stefank@2314 32 #include "classfile/vmSymbols.hpp"
stefank@2314 33 #include "interpreter/bytecodeStream.hpp"
stefank@2314 34 #include "interpreter/interpreter.hpp"
stefank@2314 35 #include "memory/gcLocker.hpp"
stefank@2314 36 #include "memory/oopFactory.hpp"
stefank@2314 37 #include "oops/instanceKlass.hpp"
stefank@2314 38 #include "oops/instanceRefKlass.hpp"
stefank@2314 39 #include "oops/klass.inline.hpp"
stefank@2314 40 #include "oops/methodDataOop.hpp"
stefank@2314 41 #include "oops/objArrayKlass.hpp"
stefank@2314 42 #include "oops/oop.inline.hpp"
stefank@2314 43 #include "oops/oop.inline2.hpp"
stefank@2314 44 #include "oops/typeArrayKlass.hpp"
stefank@2314 45 #include "prims/jvmtiEnvBase.hpp"
stefank@2314 46 #include "prims/methodHandles.hpp"
stefank@2314 47 #include "runtime/biasedLocking.hpp"
stefank@2314 48 #include "runtime/fieldType.hpp"
stefank@2314 49 #include "runtime/handles.inline.hpp"
stefank@2314 50 #include "runtime/java.hpp"
stefank@2314 51 #include "runtime/javaCalls.hpp"
stefank@2314 52 #include "runtime/mutexLocker.hpp"
stefank@2314 53 #include "runtime/signature.hpp"
stefank@2314 54 #include "services/classLoadingService.hpp"
stefank@2314 55 #include "services/threadService.hpp"
duke@435 56
duke@435 57
twisti@2258 58 Dictionary* SystemDictionary::_dictionary = NULL;
twisti@2258 59 PlaceholderTable* SystemDictionary::_placeholders = NULL;
twisti@2258 60 Dictionary* SystemDictionary::_shared_dictionary = NULL;
twisti@2258 61 LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
twisti@2258 62 ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
twisti@2258 63 SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
duke@435 64
duke@435 65
duke@435 66 int SystemDictionary::_number_of_modifications = 0;
duke@435 67
duke@435 68 oop SystemDictionary::_system_loader_lock_obj = NULL;
duke@435 69
jrose@567 70 klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
jrose@567 71 = { NULL /*, NULL...*/ };
duke@435 72
duke@435 73 klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
duke@435 74
duke@435 75 oop SystemDictionary::_java_system_loader = NULL;
duke@435 76
duke@435 77 bool SystemDictionary::_has_loadClassInternal = false;
duke@435 78 bool SystemDictionary::_has_checkPackageAccess = false;
duke@435 79
duke@435 80 // lazily initialized klass variables
duke@435 81 volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
duke@435 82
duke@435 83
duke@435 84 // ----------------------------------------------------------------------------
duke@435 85 // Java-level SystemLoader
duke@435 86
duke@435 87 oop SystemDictionary::java_system_loader() {
duke@435 88 return _java_system_loader;
duke@435 89 }
duke@435 90
duke@435 91 void SystemDictionary::compute_java_system_loader(TRAPS) {
never@1577 92 KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
duke@435 93 JavaValue result(T_OBJECT);
duke@435 94 JavaCalls::call_static(&result,
never@1577 95 KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
coleenp@2497 96 vmSymbols::getSystemClassLoader_name(),
coleenp@2497 97 vmSymbols::void_classloader_signature(),
duke@435 98 CHECK);
duke@435 99
duke@435 100 _java_system_loader = (oop)result.get_jobject();
duke@435 101 }
duke@435 102
duke@435 103
duke@435 104 // ----------------------------------------------------------------------------
duke@435 105 // debugging
duke@435 106
duke@435 107 #ifdef ASSERT
duke@435 108
duke@435 109 // return true if class_name contains no '.' (internal format is '/')
coleenp@2497 110 bool SystemDictionary::is_internal_format(Symbol* class_name) {
coleenp@2497 111 if (class_name != NULL) {
duke@435 112 ResourceMark rm;
duke@435 113 char* name = class_name->as_C_string();
duke@435 114 return strchr(name, '.') == NULL;
duke@435 115 } else {
duke@435 116 return true;
duke@435 117 }
duke@435 118 }
duke@435 119
duke@435 120 #endif
duke@435 121
duke@435 122 // ----------------------------------------------------------------------------
acorn@949 123 // Parallel class loading check
acorn@949 124
acorn@949 125 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
acorn@949 126 if (UnsyncloadClass || class_loader.is_null()) return true;
acorn@949 127 if (AlwaysLockClassLoader) return false;
acorn@949 128 return java_lang_Class::parallelCapable(class_loader());
acorn@949 129 }
acorn@949 130 // ----------------------------------------------------------------------------
acorn@1510 131 // ParallelDefineClass flag does not apply to bootclass loader
acorn@1510 132 bool SystemDictionary::is_parallelDefine(Handle class_loader) {
acorn@1510 133 if (class_loader.is_null()) return false;
acorn@1510 134 if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) {
acorn@1510 135 return true;
acorn@1510 136 }
acorn@1510 137 return false;
acorn@1510 138 }
acorn@1510 139 // ----------------------------------------------------------------------------
duke@435 140 // Resolving of classes
duke@435 141
duke@435 142 // Forwards to resolve_or_null
duke@435 143
coleenp@2497 144 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
duke@435 145 klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
duke@435 146 if (HAS_PENDING_EXCEPTION || klass == NULL) {
duke@435 147 KlassHandle k_h(THREAD, klass);
duke@435 148 // can return a null klass
duke@435 149 klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
duke@435 150 }
duke@435 151 return klass;
duke@435 152 }
duke@435 153
coleenp@2497 154 klassOop SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) {
duke@435 155 if (HAS_PENDING_EXCEPTION) {
duke@435 156 // If we have a pending exception we forward it to the caller, unless throw_error is true,
duke@435 157 // in which case we have to check whether the pending exception is a ClassNotFoundException,
duke@435 158 // and if so convert it to a NoClassDefFoundError
duke@435 159 // And chain the original ClassNotFoundException
never@1577 160 if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
duke@435 161 ResourceMark rm(THREAD);
duke@435 162 assert(klass_h() == NULL, "Should not have result with exception pending");
duke@435 163 Handle e(THREAD, PENDING_EXCEPTION);
duke@435 164 CLEAR_PENDING_EXCEPTION;
duke@435 165 THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
duke@435 166 } else {
duke@435 167 return NULL;
duke@435 168 }
duke@435 169 }
duke@435 170 // Class not found, throw appropriate error or exception depending on value of throw_error
duke@435 171 if (klass_h() == NULL) {
duke@435 172 ResourceMark rm(THREAD);
duke@435 173 if (throw_error) {
duke@435 174 THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
duke@435 175 } else {
duke@435 176 THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
duke@435 177 }
duke@435 178 }
duke@435 179 return (klassOop)klass_h();
duke@435 180 }
duke@435 181
duke@435 182
coleenp@2497 183 klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
duke@435 184 bool throw_error, TRAPS)
duke@435 185 {
duke@435 186 return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
duke@435 187 }
duke@435 188
duke@435 189
duke@435 190 // Forwards to resolve_instance_class_or_null
duke@435 191
coleenp@2497 192 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
duke@435 193 assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
coleenp@2497 194 if (FieldType::is_array(class_name)) {
duke@435 195 return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
coleenp@2497 196 } else if (FieldType::is_obj(class_name)) {
coleenp@2497 197 ResourceMark rm(THREAD);
coleenp@2497 198 // Ignore wrapping L and ;.
coleenp@2497 199 TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
coleenp@2497 200 class_name->utf8_length() - 2, CHECK_NULL);
coleenp@2497 201 return resolve_instance_class_or_null(name, class_loader, protection_domain, CHECK_NULL);
duke@435 202 } else {
duke@435 203 return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
duke@435 204 }
duke@435 205 }
duke@435 206
coleenp@2497 207 klassOop SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
duke@435 208 return resolve_or_null(class_name, Handle(), Handle(), THREAD);
duke@435 209 }
duke@435 210
duke@435 211 // Forwards to resolve_instance_class_or_null
duke@435 212
coleenp@2497 213 klassOop SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
duke@435 214 Handle class_loader,
duke@435 215 Handle protection_domain,
duke@435 216 TRAPS) {
coleenp@2497 217 assert(FieldType::is_array(class_name), "must be array");
duke@435 218 klassOop k = NULL;
coleenp@2497 219 FieldArrayInfo fd;
coleenp@2497 220 // dimension and object_key in FieldArrayInfo are assigned as a side-effect
coleenp@2497 221 // of this call
coleenp@2497 222 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
duke@435 223 if (t == T_OBJECT) {
duke@435 224 // naked oop "k" is OK here -- we assign back into it
coleenp@2497 225 k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
duke@435 226 class_loader,
duke@435 227 protection_domain,
duke@435 228 CHECK_NULL);
duke@435 229 if (k != NULL) {
coleenp@2497 230 k = Klass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
duke@435 231 }
duke@435 232 } else {
duke@435 233 k = Universe::typeArrayKlassObj(t);
coleenp@2497 234 k = typeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
duke@435 235 }
duke@435 236 return k;
duke@435 237 }
duke@435 238
duke@435 239
duke@435 240 // Must be called for any super-class or super-interface resolution
duke@435 241 // during class definition to allow class circularity checking
duke@435 242 // super-interface callers:
duke@435 243 // parse_interfaces - for defineClass & jvmtiRedefineClasses
duke@435 244 // super-class callers:
duke@435 245 // ClassFileParser - for defineClass & jvmtiRedefineClasses
duke@435 246 // load_shared_class - while loading a class from shared archive
acorn@949 247 // resolve_instance_class_or_null:
acorn@949 248 // via: handle_parallel_super_load
duke@435 249 // when resolving a class that has an existing placeholder with
duke@435 250 // a saved superclass [i.e. a defineClass is currently in progress]
duke@435 251 // if another thread is trying to resolve the class, it must do
duke@435 252 // super-class checks on its own thread to catch class circularity
duke@435 253 // This last call is critical in class circularity checking for cases
duke@435 254 // where classloading is delegated to different threads and the
duke@435 255 // classloader lock is released.
duke@435 256 // Take the case: Base->Super->Base
duke@435 257 // 1. If thread T1 tries to do a defineClass of class Base
duke@435 258 // resolve_super_or_fail creates placeholder: T1, Base (super Super)
duke@435 259 // 2. resolve_instance_class_or_null does not find SD or placeholder for Super
duke@435 260 // so it tries to load Super
duke@435 261 // 3. If we load the class internally, or user classloader uses same thread
duke@435 262 // loadClassFromxxx or defineClass via parseClassFile Super ...
duke@435 263 // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base)
duke@435 264 // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base
duke@435 265 // 3.4 calls resolve_super_or_fail Base
duke@435 266 // 3.5 finds T1,Base -> throws class circularity
duke@435 267 //OR 4. If T2 tries to resolve Super via defineClass Super ...
duke@435 268 // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base)
duke@435 269 // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super)
duke@435 270 // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2
duke@435 271 // 4.4 finds T2, Super -> throws class circularity
duke@435 272 // Must be called, even if superclass is null, since this is
duke@435 273 // where the placeholder entry is created which claims this
duke@435 274 // thread is loading this class/classloader.
coleenp@2497 275 klassOop SystemDictionary::resolve_super_or_fail(Symbol* child_name,
coleenp@2497 276 Symbol* class_name,
duke@435 277 Handle class_loader,
duke@435 278 Handle protection_domain,
duke@435 279 bool is_superclass,
duke@435 280 TRAPS) {
duke@435 281
jrose@567 282 // Try to get one of the well-known klasses.
jrose@567 283 // They are trusted, and do not participate in circularities.
jrose@567 284 if (LinkWellKnownClasses) {
coleenp@2497 285 klassOop k = find_well_known_klass(class_name);
jrose@567 286 if (k != NULL) {
jrose@567 287 return k;
jrose@567 288 }
jrose@567 289 }
jrose@567 290
duke@435 291 // Double-check, if child class is already loaded, just return super-class,interface
duke@435 292 // Don't add a placedholder if already loaded, i.e. already in system dictionary
duke@435 293 // Make sure there's a placeholder for the *child* before resolving.
duke@435 294 // Used as a claim that this thread is currently loading superclass/classloader
duke@435 295 // Used here for ClassCircularity checks and also for heap verification
duke@435 296 // (every instanceKlass in the heap needs to be in the system dictionary
duke@435 297 // or have a placeholder).
duke@435 298 // Must check ClassCircularity before checking if super class is already loaded
duke@435 299 //
duke@435 300 // We might not already have a placeholder if this child_name was
duke@435 301 // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass);
duke@435 302 // the name of the class might not be known until the stream is actually
duke@435 303 // parsed.
duke@435 304 // Bugs 4643874, 4715493
duke@435 305 // compute_hash can have a safepoint
duke@435 306
duke@435 307 unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader);
duke@435 308 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 309 unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader);
duke@435 310 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 311 // can't throw error holding a lock
duke@435 312 bool child_already_loaded = false;
duke@435 313 bool throw_circularity_error = false;
duke@435 314 {
duke@435 315 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 316 klassOop childk = find_class(d_index, d_hash, child_name, class_loader);
duke@435 317 klassOop quicksuperk;
duke@435 318 // to support // loading: if child done loading, just return superclass
duke@435 319 // if class_name, & class_loader don't match:
duke@435 320 // if initial define, SD update will give LinkageError
duke@435 321 // if redefine: compare_class_versions will give HIERARCHY_CHANGED
duke@435 322 // so we don't throw an exception here.
duke@435 323 // see: nsk redefclass014 & java.lang.instrument Instrument032
duke@435 324 if ((childk != NULL ) && (is_superclass) &&
duke@435 325 ((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) &&
duke@435 326
coleenp@2497 327 ((Klass::cast(quicksuperk)->name() == class_name) &&
duke@435 328 (Klass::cast(quicksuperk)->class_loader() == class_loader()))) {
duke@435 329 return quicksuperk;
duke@435 330 } else {
duke@435 331 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
duke@435 332 if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
duke@435 333 throw_circularity_error = true;
duke@435 334 }
acorn@949 335 }
acorn@949 336 if (!throw_circularity_error) {
duke@435 337 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
duke@435 338 }
duke@435 339 }
duke@435 340 if (throw_circularity_error) {
duke@435 341 ResourceMark rm(THREAD);
duke@435 342 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
duke@435 343 }
duke@435 344
duke@435 345 // java.lang.Object should have been found above
coleenp@2497 346 assert(class_name != NULL, "null super class for resolving");
duke@435 347 // Resolve the super class or interface, check results on return
duke@435 348 klassOop superk = NULL;
duke@435 349 superk = SystemDictionary::resolve_or_null(class_name,
duke@435 350 class_loader,
duke@435 351 protection_domain,
duke@435 352 THREAD);
duke@435 353
duke@435 354 KlassHandle superk_h(THREAD, superk);
duke@435 355
duke@435 356 // Note: clean up of placeholders currently in callers of
duke@435 357 // resolve_super_or_fail - either at update_dictionary time
duke@435 358 // or on error
duke@435 359 {
duke@435 360 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 361 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
duke@435 362 if (probe != NULL) {
duke@435 363 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER);
duke@435 364 }
duke@435 365 }
duke@435 366 if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
duke@435 367 // can null superk
duke@435 368 superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD));
duke@435 369 }
duke@435 370
duke@435 371 return superk_h();
duke@435 372 }
duke@435 373
duke@435 374 void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
duke@435 375 Handle class_loader,
duke@435 376 Handle protection_domain,
duke@435 377 TRAPS) {
duke@435 378 if(!has_checkPackageAccess()) return;
duke@435 379
duke@435 380 // Now we have to call back to java to check if the initating class has access
duke@435 381 JavaValue result(T_VOID);
duke@435 382 if (TraceProtectionDomainVerification) {
duke@435 383 // Print out trace information
duke@435 384 tty->print_cr("Checking package access");
duke@435 385 tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr();
duke@435 386 tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
duke@435 387 tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr();
duke@435 388 }
duke@435 389
duke@435 390 assert(class_loader() != NULL, "should not have non-null protection domain for null classloader");
duke@435 391
never@1577 392 KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass());
duke@435 393 JavaCalls::call_special(&result,
duke@435 394 class_loader,
duke@435 395 system_loader,
coleenp@2497 396 vmSymbols::checkPackageAccess_name(),
coleenp@2497 397 vmSymbols::class_protectiondomain_signature(),
duke@435 398 Handle(THREAD, klass->java_mirror()),
duke@435 399 protection_domain,
duke@435 400 THREAD);
duke@435 401
duke@435 402 if (TraceProtectionDomainVerification) {
duke@435 403 if (HAS_PENDING_EXCEPTION) {
duke@435 404 tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!");
duke@435 405 } else {
duke@435 406 tty->print_cr(" -> granted");
duke@435 407 }
duke@435 408 tty->cr();
duke@435 409 }
duke@435 410
duke@435 411 if (HAS_PENDING_EXCEPTION) return;
duke@435 412
duke@435 413 // If no exception has been thrown, we have validated the protection domain
duke@435 414 // Insert the protection domain of the initiating class into the set.
duke@435 415 {
duke@435 416 // We recalculate the entry here -- we've called out to java since
duke@435 417 // the last time it was calculated.
coleenp@2497 418 Symbol* kn = klass->name();
duke@435 419 unsigned int d_hash = dictionary()->compute_hash(kn, class_loader);
duke@435 420 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 421
duke@435 422 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 423 {
duke@435 424 // Note that we have an entry, and entries can be deleted only during GC,
duke@435 425 // so we cannot allow GC to occur while we're holding this entry.
duke@435 426
duke@435 427 // We're using a No_Safepoint_Verifier to catch any place where we
duke@435 428 // might potentially do a GC at all.
duke@435 429 // SystemDictionary::do_unloading() asserts that classes are only
duke@435 430 // unloaded at a safepoint.
duke@435 431 No_Safepoint_Verifier nosafepoint;
duke@435 432 dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader,
duke@435 433 protection_domain, THREAD);
duke@435 434 }
duke@435 435 }
duke@435 436 }
duke@435 437
duke@435 438 // We only get here if this thread finds that another thread
duke@435 439 // has already claimed the placeholder token for the current operation,
duke@435 440 // but that other thread either never owned or gave up the
duke@435 441 // object lock
duke@435 442 // Waits on SystemDictionary_lock to indicate placeholder table updated
duke@435 443 // On return, caller must recheck placeholder table state
duke@435 444 //
duke@435 445 // We only get here if
duke@435 446 // 1) custom classLoader, i.e. not bootstrap classloader
duke@435 447 // 2) UnsyncloadClass not set
duke@435 448 // 3) custom classLoader has broken the class loader objectLock
duke@435 449 // so another thread got here in parallel
duke@435 450 //
duke@435 451 // lockObject must be held.
duke@435 452 // Complicated dance due to lock ordering:
duke@435 453 // Must first release the classloader object lock to
duke@435 454 // allow initial definer to complete the class definition
duke@435 455 // and to avoid deadlock
duke@435 456 // Reclaim classloader lock object with same original recursion count
duke@435 457 // Must release SystemDictionary_lock after notify, since
duke@435 458 // class loader lock must be claimed before SystemDictionary_lock
duke@435 459 // to prevent deadlocks
duke@435 460 //
duke@435 461 // The notify allows applications that did an untimed wait() on
duke@435 462 // the classloader object lock to not hang.
duke@435 463 void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
duke@435 464 assert_lock_strong(SystemDictionary_lock);
duke@435 465
duke@435 466 bool calledholdinglock
duke@435 467 = ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
duke@435 468 assert(calledholdinglock,"must hold lock for notify");
acorn@949 469 assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
duke@435 470 ObjectSynchronizer::notifyall(lockObject, THREAD);
duke@435 471 intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
duke@435 472 SystemDictionary_lock->wait();
duke@435 473 SystemDictionary_lock->unlock();
duke@435 474 ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
duke@435 475 SystemDictionary_lock->lock();
duke@435 476 }
duke@435 477
duke@435 478 // If the class in is in the placeholder table, class loading is in progress
duke@435 479 // For cases where the application changes threads to load classes, it
duke@435 480 // is critical to ClassCircularity detection that we try loading
duke@435 481 // the superclass on the same thread internally, so we do parallel
duke@435 482 // super class loading here.
duke@435 483 // This also is critical in cases where the original thread gets stalled
duke@435 484 // even in non-circularity situations.
duke@435 485 // Note: only one thread can define the class, but multiple can resolve
duke@435 486 // Note: must call resolve_super_or_fail even if null super -
acorn@949 487 // to force placeholder entry creation for this class for circularity detection
duke@435 488 // Caller must check for pending exception
duke@435 489 // Returns non-null klassOop if other thread has completed load
duke@435 490 // and we are done,
duke@435 491 // If return null klassOop and no pending exception, the caller must load the class
duke@435 492 instanceKlassHandle SystemDictionary::handle_parallel_super_load(
coleenp@2497 493 Symbol* name, Symbol* superclassname, Handle class_loader,
duke@435 494 Handle protection_domain, Handle lockObject, TRAPS) {
duke@435 495
duke@435 496 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
duke@435 497 unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
duke@435 498 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 499 unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
duke@435 500 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 501
duke@435 502 // superk is not used, resolve_super called for circularity check only
duke@435 503 // This code is reached in two situations. One if this thread
duke@435 504 // is loading the same class twice (e.g. ClassCircularity, or
duke@435 505 // java.lang.instrument).
duke@435 506 // The second is if another thread started the resolve_super first
duke@435 507 // and has not yet finished.
duke@435 508 // In both cases the original caller will clean up the placeholder
duke@435 509 // entry on error.
duke@435 510 klassOop superk = SystemDictionary::resolve_super_or_fail(name,
duke@435 511 superclassname,
duke@435 512 class_loader,
duke@435 513 protection_domain,
duke@435 514 true,
duke@435 515 CHECK_(nh));
duke@435 516 // We don't redefine the class, so we just need to clean up if there
duke@435 517 // was not an error (don't want to modify any system dictionary
duke@435 518 // data structures).
duke@435 519 {
duke@435 520 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 521 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
duke@435 522 SystemDictionary_lock->notify_all();
duke@435 523 }
duke@435 524
acorn@949 525 // parallelCapable class loaders do NOT wait for parallel superclass loads to complete
acorn@949 526 // Serial class loaders and bootstrap classloader do wait for superclass loads
acorn@949 527 if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
duke@435 528 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 529 // Check if classloading completed while we were loading superclass or waiting
duke@435 530 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 531 if (check != NULL) {
duke@435 532 // Klass is already loaded, so just return it
duke@435 533 return(instanceKlassHandle(THREAD, check));
duke@435 534 } else {
duke@435 535 return nh;
duke@435 536 }
duke@435 537 }
duke@435 538
duke@435 539 // must loop to both handle other placeholder updates
duke@435 540 // and spurious notifications
duke@435 541 bool super_load_in_progress = true;
duke@435 542 PlaceholderEntry* placeholder;
duke@435 543 while (super_load_in_progress) {
duke@435 544 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 545 // Check if classloading completed while we were loading superclass or waiting
duke@435 546 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 547 if (check != NULL) {
duke@435 548 // Klass is already loaded, so just return it
duke@435 549 return(instanceKlassHandle(THREAD, check));
duke@435 550 } else {
duke@435 551 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
duke@435 552 if (placeholder && placeholder->super_load_in_progress() ){
duke@435 553 // Before UnsyncloadClass:
duke@435 554 // We only get here if the application has released the
duke@435 555 // classloader lock when another thread was in the middle of loading a
duke@435 556 // superclass/superinterface for this class, and now
duke@435 557 // this thread is also trying to load this class.
duke@435 558 // To minimize surprises, the first thread that started to
duke@435 559 // load a class should be the one to complete the loading
duke@435 560 // with the classfile it initially expected.
duke@435 561 // This logic has the current thread wait once it has done
duke@435 562 // all the superclass/superinterface loading it can, until
duke@435 563 // the original thread completes the class loading or fails
duke@435 564 // If it completes we will use the resulting instanceKlass
duke@435 565 // which we will find below in the systemDictionary.
duke@435 566 // We also get here for parallel bootstrap classloader
duke@435 567 if (class_loader.is_null()) {
duke@435 568 SystemDictionary_lock->wait();
duke@435 569 } else {
duke@435 570 double_lock_wait(lockObject, THREAD);
duke@435 571 }
duke@435 572 } else {
duke@435 573 // If not in SD and not in PH, other thread's load must have failed
duke@435 574 super_load_in_progress = false;
duke@435 575 }
duke@435 576 }
duke@435 577 }
duke@435 578 return (nh);
duke@435 579 }
duke@435 580
duke@435 581
coleenp@2497 582 klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) {
coleenp@2497 583 assert(name != NULL && !FieldType::is_array(name) &&
coleenp@2497 584 !FieldType::is_obj(name), "invalid class name");
duke@435 585
duke@435 586 // UseNewReflection
duke@435 587 // Fix for 4474172; see evaluation for more details
duke@435 588 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
duke@435 589
duke@435 590 // Do lookup to see if class already exist and the protection domain
duke@435 591 // has the right access
duke@435 592 unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
duke@435 593 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 594 klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader,
duke@435 595 protection_domain, THREAD);
duke@435 596 if (probe != NULL) return probe;
duke@435 597
duke@435 598
duke@435 599 // Non-bootstrap class loaders will call out to class loader and
duke@435 600 // define via jvm/jni_DefineClass which will acquire the
duke@435 601 // class loader object lock to protect against multiple threads
duke@435 602 // defining the class in parallel by accident.
duke@435 603 // This lock must be acquired here so the waiter will find
duke@435 604 // any successful result in the SystemDictionary and not attempt
duke@435 605 // the define
acorn@949 606 // ParallelCapable Classloaders and the bootstrap classloader,
duke@435 607 // or all classloaders with UnsyncloadClass do not acquire lock here
duke@435 608 bool DoObjectLock = true;
acorn@949 609 if (is_parallelCapable(class_loader)) {
duke@435 610 DoObjectLock = false;
duke@435 611 }
duke@435 612
duke@435 613 unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
duke@435 614 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 615
duke@435 616 // Class is not in SystemDictionary so we have to do loading.
duke@435 617 // Make sure we are synchronized on the class loader before we proceed
duke@435 618 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
duke@435 619 check_loader_lock_contention(lockObject, THREAD);
duke@435 620 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
duke@435 621
duke@435 622 // Check again (after locking) if class already exist in SystemDictionary
duke@435 623 bool class_has_been_loaded = false;
duke@435 624 bool super_load_in_progress = false;
duke@435 625 bool havesupername = false;
duke@435 626 instanceKlassHandle k;
duke@435 627 PlaceholderEntry* placeholder;
coleenp@2497 628 Symbol* superclassname = NULL;
duke@435 629
duke@435 630 {
duke@435 631 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 632 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 633 if (check != NULL) {
duke@435 634 // Klass is already loaded, so just return it
duke@435 635 class_has_been_loaded = true;
duke@435 636 k = instanceKlassHandle(THREAD, check);
duke@435 637 } else {
duke@435 638 placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
duke@435 639 if (placeholder && placeholder->super_load_in_progress()) {
duke@435 640 super_load_in_progress = true;
duke@435 641 if (placeholder->havesupername() == true) {
coleenp@2497 642 superclassname = placeholder->supername();
duke@435 643 havesupername = true;
duke@435 644 }
duke@435 645 }
duke@435 646 }
duke@435 647 }
duke@435 648
duke@435 649 // If the class in is in the placeholder table, class loading is in progress
duke@435 650 if (super_load_in_progress && havesupername==true) {
duke@435 651 k = SystemDictionary::handle_parallel_super_load(name, superclassname,
duke@435 652 class_loader, protection_domain, lockObject, THREAD);
duke@435 653 if (HAS_PENDING_EXCEPTION) {
duke@435 654 return NULL;
duke@435 655 }
duke@435 656 if (!k.is_null()) {
duke@435 657 class_has_been_loaded = true;
duke@435 658 }
duke@435 659 }
duke@435 660
duke@435 661 if (!class_has_been_loaded) {
duke@435 662
duke@435 663 // add placeholder entry to record loading instance class
duke@435 664 // Five cases:
duke@435 665 // All cases need to prevent modifying bootclasssearchpath
duke@435 666 // in parallel with a classload of same classname
acorn@949 667 // Redefineclasses uses existence of the placeholder for the duration
acorn@949 668 // of the class load to prevent concurrent redefinition of not completely
acorn@949 669 // defined classes.
duke@435 670 // case 1. traditional classloaders that rely on the classloader object lock
duke@435 671 // - no other need for LOAD_INSTANCE
duke@435 672 // case 2. traditional classloaders that break the classloader object lock
duke@435 673 // as a deadlock workaround. Detection of this case requires that
duke@435 674 // this check is done while holding the classloader object lock,
duke@435 675 // and that lock is still held when calling classloader's loadClass.
duke@435 676 // For these classloaders, we ensure that the first requestor
duke@435 677 // completes the load and other requestors wait for completion.
duke@435 678 // case 3. UnsyncloadClass - don't use objectLocker
duke@435 679 // With this flag, we allow parallel classloading of a
duke@435 680 // class/classloader pair
duke@435 681 // case4. Bootstrap classloader - don't own objectLocker
duke@435 682 // This classloader supports parallelism at the classloader level,
duke@435 683 // but only allows a single load of a class/classloader pair.
duke@435 684 // No performance benefit and no deadlock issues.
acorn@949 685 // case 5. parallelCapable user level classloaders - without objectLocker
acorn@949 686 // Allow parallel classloading of a class/classloader pair
duke@435 687 bool throw_circularity_error = false;
duke@435 688 {
duke@435 689 MutexLocker mu(SystemDictionary_lock, THREAD);
acorn@949 690 if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
duke@435 691 PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
duke@435 692 if (oldprobe) {
duke@435 693 // only need check_seen_thread once, not on each loop
duke@435 694 // 6341374 java/lang/Instrument with -Xcomp
duke@435 695 if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
duke@435 696 throw_circularity_error = true;
duke@435 697 } else {
duke@435 698 // case 1: traditional: should never see load_in_progress.
duke@435 699 while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
duke@435 700
duke@435 701 // case 4: bootstrap classloader: prevent futile classloading,
duke@435 702 // wait on first requestor
duke@435 703 if (class_loader.is_null()) {
duke@435 704 SystemDictionary_lock->wait();
duke@435 705 } else {
duke@435 706 // case 2: traditional with broken classloader lock. wait on first
duke@435 707 // requestor.
duke@435 708 double_lock_wait(lockObject, THREAD);
duke@435 709 }
duke@435 710 // Check if classloading completed while we were waiting
duke@435 711 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 712 if (check != NULL) {
duke@435 713 // Klass is already loaded, so just return it
duke@435 714 k = instanceKlassHandle(THREAD, check);
duke@435 715 class_has_been_loaded = true;
duke@435 716 }
duke@435 717 // check if other thread failed to load and cleaned up
duke@435 718 oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
duke@435 719 }
duke@435 720 }
duke@435 721 }
duke@435 722 }
duke@435 723 // All cases: add LOAD_INSTANCE
acorn@949 724 // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try
duke@435 725 // LOAD_INSTANCE in parallel
duke@435 726 // add placeholder entry even if error - callers will remove on error
acorn@949 727 if (!throw_circularity_error && !class_has_been_loaded) {
coleenp@2497 728 PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
duke@435 729 // For class loaders that do not acquire the classloader object lock,
duke@435 730 // if they did not catch another thread holding LOAD_INSTANCE,
duke@435 731 // need a check analogous to the acquire ObjectLocker/find_class
duke@435 732 // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
duke@435 733 // one final check if the load has already completed
acorn@949 734 // class loaders holding the ObjectLock shouldn't find the class here
duke@435 735 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 736 if (check != NULL) {
duke@435 737 // Klass is already loaded, so just return it
duke@435 738 k = instanceKlassHandle(THREAD, check);
duke@435 739 class_has_been_loaded = true;
duke@435 740 newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
acorn@949 741 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
acorn@949 742 SystemDictionary_lock->notify_all();
duke@435 743 }
duke@435 744 }
duke@435 745 }
duke@435 746 // must throw error outside of owning lock
duke@435 747 if (throw_circularity_error) {
duke@435 748 ResourceMark rm(THREAD);
duke@435 749 THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
duke@435 750 }
duke@435 751
duke@435 752 if (!class_has_been_loaded) {
duke@435 753
duke@435 754 // Do actual loading
duke@435 755 k = load_instance_class(name, class_loader, THREAD);
duke@435 756
acorn@1510 757 // For UnsyncloadClass only
duke@435 758 // If they got a linkageError, check if a parallel class load succeeded.
duke@435 759 // If it did, then for bytecode resolution the specification requires
duke@435 760 // that we return the same result we did for the other thread, i.e. the
duke@435 761 // successfully loaded instanceKlass
duke@435 762 // Should not get here for classloaders that support parallelism
acorn@1510 763 // with the new cleaner mechanism, even with AllowParallelDefineClass
acorn@949 764 // Bootstrap goes through here to allow for an extra guarantee check
duke@435 765 if (UnsyncloadClass || (class_loader.is_null())) {
duke@435 766 if (k.is_null() && HAS_PENDING_EXCEPTION
never@1577 767 && PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
duke@435 768 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 769 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 770 if (check != NULL) {
duke@435 771 // Klass is already loaded, so just use it
duke@435 772 k = instanceKlassHandle(THREAD, check);
duke@435 773 CLEAR_PENDING_EXCEPTION;
duke@435 774 guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
duke@435 775 }
duke@435 776 }
duke@435 777 }
duke@435 778
duke@435 779 // clean up placeholder entries for success or error
duke@435 780 // This cleans up LOAD_INSTANCE entries
duke@435 781 // It also cleans up LOAD_SUPER entries on errors from
duke@435 782 // calling load_instance_class
duke@435 783 {
duke@435 784 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 785 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
duke@435 786 if (probe != NULL) {
duke@435 787 probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
duke@435 788 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
duke@435 789 SystemDictionary_lock->notify_all();
duke@435 790 }
duke@435 791 }
duke@435 792
duke@435 793 // If everything was OK (no exceptions, no null return value), and
duke@435 794 // class_loader is NOT the defining loader, do a little more bookkeeping.
duke@435 795 if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
duke@435 796 k->class_loader() != class_loader()) {
duke@435 797
duke@435 798 check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
duke@435 799
duke@435 800 // Need to check for a PENDING_EXCEPTION again; check_constraints
duke@435 801 // can throw and doesn't use the CHECK macro.
duke@435 802 if (!HAS_PENDING_EXCEPTION) {
duke@435 803 { // Grabbing the Compile_lock prevents systemDictionary updates
duke@435 804 // during compilations.
duke@435 805 MutexLocker mu(Compile_lock, THREAD);
duke@435 806 update_dictionary(d_index, d_hash, p_index, p_hash,
duke@435 807 k, class_loader, THREAD);
duke@435 808 }
duke@435 809 if (JvmtiExport::should_post_class_load()) {
duke@435 810 Thread *thread = THREAD;
duke@435 811 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
duke@435 812 JvmtiExport::post_class_load((JavaThread *) thread, k());
duke@435 813 }
duke@435 814 }
duke@435 815 }
duke@435 816 if (HAS_PENDING_EXCEPTION || k.is_null()) {
duke@435 817 // On error, clean up placeholders
duke@435 818 {
duke@435 819 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 820 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
duke@435 821 SystemDictionary_lock->notify_all();
duke@435 822 }
duke@435 823 return NULL;
duke@435 824 }
duke@435 825 }
duke@435 826 }
duke@435 827
duke@435 828 #ifdef ASSERT
duke@435 829 {
duke@435 830 Handle loader (THREAD, k->class_loader());
duke@435 831 MutexLocker mu(SystemDictionary_lock, THREAD);
coleenp@2497 832 oop kk = find_class(name, loader);
duke@435 833 assert(kk == k(), "should be present in dictionary");
duke@435 834 }
duke@435 835 #endif
duke@435 836
duke@435 837 // return if the protection domain in NULL
duke@435 838 if (protection_domain() == NULL) return k();
duke@435 839
duke@435 840 // Check the protection domain has the right access
duke@435 841 {
duke@435 842 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 843 // Note that we have an entry, and entries can be deleted only during GC,
duke@435 844 // so we cannot allow GC to occur while we're holding this entry.
duke@435 845 // We're using a No_Safepoint_Verifier to catch any place where we
duke@435 846 // might potentially do a GC at all.
duke@435 847 // SystemDictionary::do_unloading() asserts that classes are only
duke@435 848 // unloaded at a safepoint.
duke@435 849 No_Safepoint_Verifier nosafepoint;
duke@435 850 if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
duke@435 851 class_loader,
duke@435 852 protection_domain)) {
duke@435 853 return k();
duke@435 854 }
duke@435 855 }
duke@435 856
duke@435 857 // Verify protection domain. If it fails an exception is thrown
duke@435 858 validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL)));
duke@435 859
duke@435 860 return k();
duke@435 861 }
duke@435 862
duke@435 863
duke@435 864 // This routine does not lock the system dictionary.
duke@435 865 //
duke@435 866 // Since readers don't hold a lock, we must make sure that system
duke@435 867 // dictionary entries are only removed at a safepoint (when only one
duke@435 868 // thread is running), and are added to in a safe way (all links must
duke@435 869 // be updated in an MT-safe manner).
duke@435 870 //
duke@435 871 // Callers should be aware that an entry could be added just after
duke@435 872 // _dictionary->bucket(index) is read here, so the caller will not see
duke@435 873 // the new entry.
duke@435 874
coleenp@2497 875 klassOop SystemDictionary::find(Symbol* class_name,
duke@435 876 Handle class_loader,
duke@435 877 Handle protection_domain,
duke@435 878 TRAPS) {
duke@435 879
kvn@991 880 // UseNewReflection
kvn@991 881 // The result of this call should be consistent with the result
kvn@991 882 // of the call to resolve_instance_class_or_null().
kvn@991 883 // See evaluation 6790209 and 4474172 for more details.
kvn@991 884 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
kvn@991 885
duke@435 886 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
duke@435 887 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 888
duke@435 889 {
duke@435 890 // Note that we have an entry, and entries can be deleted only during GC,
duke@435 891 // so we cannot allow GC to occur while we're holding this entry.
duke@435 892 // We're using a No_Safepoint_Verifier to catch any place where we
duke@435 893 // might potentially do a GC at all.
duke@435 894 // SystemDictionary::do_unloading() asserts that classes are only
duke@435 895 // unloaded at a safepoint.
duke@435 896 No_Safepoint_Verifier nosafepoint;
duke@435 897 return dictionary()->find(d_index, d_hash, class_name, class_loader,
duke@435 898 protection_domain, THREAD);
duke@435 899 }
duke@435 900 }
duke@435 901
duke@435 902
duke@435 903 // Look for a loaded instance or array klass by name. Do not do any loading.
duke@435 904 // return NULL in case of error.
coleenp@2497 905 klassOop SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
duke@435 906 Handle class_loader,
duke@435 907 Handle protection_domain,
duke@435 908 TRAPS) {
duke@435 909 klassOop k = NULL;
coleenp@2497 910 assert(class_name != NULL, "class name must be non NULL");
jrose@567 911
jrose@567 912 // Try to get one of the well-known klasses.
jrose@567 913 if (LinkWellKnownClasses) {
coleenp@2497 914 k = find_well_known_klass(class_name);
jrose@567 915 if (k != NULL) {
jrose@567 916 return k;
jrose@567 917 }
jrose@567 918 }
jrose@567 919
coleenp@2497 920 if (FieldType::is_array(class_name)) {
duke@435 921 // The name refers to an array. Parse the name.
coleenp@2497 922 // dimension and object_key in FieldArrayInfo are assigned as a
coleenp@2497 923 // side-effect of this call
coleenp@2497 924 FieldArrayInfo fd;
coleenp@2497 925 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
duke@435 926 if (t != T_OBJECT) {
duke@435 927 k = Universe::typeArrayKlassObj(t);
duke@435 928 } else {
coleenp@2497 929 k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
duke@435 930 }
duke@435 931 if (k != NULL) {
coleenp@2497 932 k = Klass::cast(k)->array_klass_or_null(fd.dimension());
duke@435 933 }
duke@435 934 } else {
duke@435 935 k = find(class_name, class_loader, protection_domain, THREAD);
duke@435 936 }
duke@435 937 return k;
duke@435 938 }
duke@435 939
jrose@567 940 // Quick range check for names of well-known classes:
coleenp@2497 941 static Symbol* wk_klass_name_limits[2] = {NULL, NULL};
jrose@567 942
jrose@567 943 #ifndef PRODUCT
jrose@567 944 static int find_wkk_calls, find_wkk_probes, find_wkk_wins;
jrose@567 945 // counts for "hello world": 3983, 1616, 1075
jrose@567 946 // => 60% hit after limit guard, 25% total win rate
jrose@567 947 #endif
jrose@567 948
coleenp@2497 949 klassOop SystemDictionary::find_well_known_klass(Symbol* class_name) {
jrose@567 950 // A bounds-check on class_name will quickly get a negative result.
jrose@567 951 NOT_PRODUCT(find_wkk_calls++);
jrose@567 952 if (class_name >= wk_klass_name_limits[0] &&
jrose@567 953 class_name <= wk_klass_name_limits[1]) {
jrose@567 954 NOT_PRODUCT(find_wkk_probes++);
jrose@567 955 vmSymbols::SID sid = vmSymbols::find_sid(class_name);
jrose@567 956 if (sid != vmSymbols::NO_SID) {
jrose@567 957 klassOop k = NULL;
jrose@567 958 switch (sid) {
jrose@567 959 #define WK_KLASS_CASE(name, symbol, ignore_option) \
jrose@567 960 case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \
jrose@567 961 k = WK_KLASS(name); break;
jrose@567 962 WK_KLASSES_DO(WK_KLASS_CASE)
jrose@567 963 #undef WK_KLASS_CASE
jrose@567 964 }
jrose@567 965 NOT_PRODUCT(if (k != NULL) find_wkk_wins++);
jrose@567 966 return k;
jrose@567 967 }
jrose@567 968 }
jrose@567 969 return NULL;
jrose@567 970 }
jrose@567 971
duke@435 972 // Note: this method is much like resolve_from_stream, but
duke@435 973 // updates no supplemental data structures.
duke@435 974 // TODO consolidate the two methods with a helper routine?
coleenp@2497 975 klassOop SystemDictionary::parse_stream(Symbol* class_name,
duke@435 976 Handle class_loader,
duke@435 977 Handle protection_domain,
duke@435 978 ClassFileStream* st,
jrose@866 979 KlassHandle host_klass,
jrose@866 980 GrowableArray<Handle>* cp_patches,
duke@435 981 TRAPS) {
coleenp@2497 982 TempNewSymbol parsed_name = NULL;
duke@435 983
duke@435 984 // Parse the stream. Note that we do this even though this klass might
duke@435 985 // already be present in the SystemDictionary, otherwise we would not
duke@435 986 // throw potential ClassFormatErrors.
duke@435 987 //
duke@435 988 // Note: "name" is updated.
duke@435 989 // Further note: a placeholder will be added for this class when
duke@435 990 // super classes are loaded (resolve_super_or_fail). We expect this
duke@435 991 // to be called for all classes but java.lang.Object; and we preload
duke@435 992 // java.lang.Object through resolve_or_fail, not this path.
duke@435 993
duke@435 994 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
duke@435 995 class_loader,
duke@435 996 protection_domain,
jrose@1145 997 host_klass,
jrose@1145 998 cp_patches,
duke@435 999 parsed_name,
acorn@1408 1000 true,
duke@435 1001 THREAD);
duke@435 1002
duke@435 1003 // We don't redefine the class, so we just need to clean up whether there
duke@435 1004 // was an error or not (don't want to modify any system dictionary
duke@435 1005 // data structures).
duke@435 1006 // Parsed name could be null if we threw an error before we got far
duke@435 1007 // enough along to parse it -- in that case, there is nothing to clean up.
coleenp@2497 1008 if (parsed_name != NULL) {
duke@435 1009 unsigned int p_hash = placeholders()->compute_hash(parsed_name,
duke@435 1010 class_loader);
duke@435 1011 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 1012 {
duke@435 1013 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 1014 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
duke@435 1015 SystemDictionary_lock->notify_all();
duke@435 1016 }
duke@435 1017 }
duke@435 1018
jrose@866 1019 if (host_klass.not_null() && k.not_null()) {
jrose@866 1020 assert(AnonymousClasses, "");
jrose@866 1021 // If it's anonymous, initialize it now, since nobody else will.
jrose@866 1022 k->set_host_klass(host_klass());
jrose@866 1023
jrose@866 1024 {
jrose@866 1025 MutexLocker mu_r(Compile_lock, THREAD);
jrose@866 1026
jrose@866 1027 // Add to class hierarchy, initialize vtables, and do possible
jrose@866 1028 // deoptimizations.
jrose@866 1029 add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
jrose@866 1030
jrose@866 1031 // But, do not add to system dictionary.
jrose@866 1032 }
jrose@866 1033
jrose@866 1034 k->eager_initialize(THREAD);
jrose@866 1035
jrose@866 1036 // notify jvmti
jrose@866 1037 if (JvmtiExport::should_post_class_load()) {
jrose@866 1038 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
jrose@866 1039 JvmtiExport::post_class_load((JavaThread *) THREAD, k());
jrose@866 1040 }
jrose@866 1041 }
jrose@866 1042
duke@435 1043 return k();
duke@435 1044 }
duke@435 1045
duke@435 1046 // Add a klass to the system from a stream (called by jni_DefineClass and
duke@435 1047 // JVM_DefineClass).
duke@435 1048 // Note: class_name can be NULL. In that case we do not know the name of
duke@435 1049 // the class until we have parsed the stream.
duke@435 1050
coleenp@2497 1051 klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
duke@435 1052 Handle class_loader,
duke@435 1053 Handle protection_domain,
duke@435 1054 ClassFileStream* st,
acorn@1408 1055 bool verify,
duke@435 1056 TRAPS) {
duke@435 1057
acorn@949 1058 // Classloaders that support parallelism, e.g. bootstrap classloader,
acorn@949 1059 // or all classloaders with UnsyncloadClass do not acquire lock here
acorn@949 1060 bool DoObjectLock = true;
acorn@949 1061 if (is_parallelCapable(class_loader)) {
acorn@949 1062 DoObjectLock = false;
acorn@949 1063 }
acorn@949 1064
acorn@949 1065 // Make sure we are synchronized on the class loader before we proceed
duke@435 1066 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
duke@435 1067 check_loader_lock_contention(lockObject, THREAD);
acorn@949 1068 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
duke@435 1069
coleenp@2497 1070 TempNewSymbol parsed_name = NULL;
duke@435 1071
duke@435 1072 // Parse the stream. Note that we do this even though this klass might
duke@435 1073 // already be present in the SystemDictionary, otherwise we would not
duke@435 1074 // throw potential ClassFormatErrors.
duke@435 1075 //
duke@435 1076 // Note: "name" is updated.
duke@435 1077 // Further note: a placeholder will be added for this class when
duke@435 1078 // super classes are loaded (resolve_super_or_fail). We expect this
duke@435 1079 // to be called for all classes but java.lang.Object; and we preload
duke@435 1080 // java.lang.Object through resolve_or_fail, not this path.
duke@435 1081
duke@435 1082 instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
duke@435 1083 class_loader,
duke@435 1084 protection_domain,
duke@435 1085 parsed_name,
acorn@1408 1086 verify,
duke@435 1087 THREAD);
duke@435 1088
duke@435 1089 const char* pkg = "java/";
duke@435 1090 if (!HAS_PENDING_EXCEPTION &&
duke@435 1091 !class_loader.is_null() &&
coleenp@2497 1092 parsed_name != NULL &&
duke@435 1093 !strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
duke@435 1094 // It is illegal to define classes in the "java." package from
duke@435 1095 // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
duke@435 1096 ResourceMark rm(THREAD);
duke@435 1097 char* name = parsed_name->as_C_string();
duke@435 1098 char* index = strrchr(name, '/');
duke@435 1099 *index = '\0'; // chop to just the package name
duke@435 1100 while ((index = strchr(name, '/')) != NULL) {
duke@435 1101 *index = '.'; // replace '/' with '.' in package name
duke@435 1102 }
duke@435 1103 const char* fmt = "Prohibited package name: %s";
duke@435 1104 size_t len = strlen(fmt) + strlen(name);
duke@435 1105 char* message = NEW_RESOURCE_ARRAY(char, len);
duke@435 1106 jio_snprintf(message, len, fmt, name);
duke@435 1107 Exceptions::_throw_msg(THREAD_AND_LOCATION,
duke@435 1108 vmSymbols::java_lang_SecurityException(), message);
duke@435 1109 }
duke@435 1110
duke@435 1111 if (!HAS_PENDING_EXCEPTION) {
coleenp@2497 1112 assert(parsed_name != NULL, "Sanity");
coleenp@2497 1113 assert(class_name == NULL || class_name == parsed_name, "name mismatch");
duke@435 1114 // Verification prevents us from creating names with dots in them, this
duke@435 1115 // asserts that that's the case.
duke@435 1116 assert(is_internal_format(parsed_name),
duke@435 1117 "external class name format used internally");
duke@435 1118
duke@435 1119 // Add class just loaded
acorn@949 1120 // If a class loader supports parallel classloading handle parallel define requests
acorn@949 1121 // find_or_define_instance_class may return a different instanceKlass
acorn@949 1122 if (is_parallelCapable(class_loader)) {
acorn@949 1123 k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
acorn@949 1124 } else {
acorn@949 1125 define_instance_class(k, THREAD);
acorn@949 1126 }
duke@435 1127 }
duke@435 1128
duke@435 1129 // If parsing the class file or define_instance_class failed, we
duke@435 1130 // need to remove the placeholder added on our behalf. But we
duke@435 1131 // must make sure parsed_name is valid first (it won't be if we had
duke@435 1132 // a format error before the class was parsed far enough to
duke@435 1133 // find the name).
coleenp@2497 1134 if (HAS_PENDING_EXCEPTION && parsed_name != NULL) {
duke@435 1135 unsigned int p_hash = placeholders()->compute_hash(parsed_name,
duke@435 1136 class_loader);
duke@435 1137 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 1138 {
duke@435 1139 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 1140 placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
duke@435 1141 SystemDictionary_lock->notify_all();
duke@435 1142 }
duke@435 1143 return NULL;
duke@435 1144 }
duke@435 1145
duke@435 1146 // Make sure that we didn't leave a place holder in the
duke@435 1147 // SystemDictionary; this is only done on success
duke@435 1148 debug_only( {
duke@435 1149 if (!HAS_PENDING_EXCEPTION) {
coleenp@2497 1150 assert(parsed_name != NULL, "parsed_name is still null?");
coleenp@2497 1151 Symbol* h_name = k->name();
duke@435 1152 Handle h_loader (THREAD, k->class_loader());
duke@435 1153
duke@435 1154 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 1155
coleenp@2497 1156 klassOop check = find_class(parsed_name, class_loader);
duke@435 1157 assert(check == k(), "should be present in the dictionary");
duke@435 1158
coleenp@2497 1159 klassOop check2 = find_class(h_name, h_loader);
duke@435 1160 assert(check == check2, "name inconsistancy in SystemDictionary");
duke@435 1161 }
duke@435 1162 } );
duke@435 1163
duke@435 1164 return k();
duke@435 1165 }
duke@435 1166
duke@435 1167
duke@435 1168 void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length,
duke@435 1169 int number_of_entries) {
duke@435 1170 assert(length == _nof_buckets * sizeof(HashtableBucket),
duke@435 1171 "bad shared dictionary size.");
duke@435 1172 _shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
duke@435 1173 }
duke@435 1174
duke@435 1175
duke@435 1176 // If there is a shared dictionary, then find the entry for the
duke@435 1177 // given shared system class, if any.
duke@435 1178
coleenp@2497 1179 klassOop SystemDictionary::find_shared_class(Symbol* class_name) {
duke@435 1180 if (shared_dictionary() != NULL) {
duke@435 1181 unsigned int d_hash = dictionary()->compute_hash(class_name, Handle());
duke@435 1182 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 1183 return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
duke@435 1184 } else {
duke@435 1185 return NULL;
duke@435 1186 }
duke@435 1187 }
duke@435 1188
duke@435 1189
duke@435 1190 // Load a class from the shared spaces (found through the shared system
duke@435 1191 // dictionary). Force the superclass and all interfaces to be loaded.
duke@435 1192 // Update the class definition to include sibling classes and no
duke@435 1193 // subclasses (yet). [Classes in the shared space are not part of the
duke@435 1194 // object hierarchy until loaded.]
duke@435 1195
duke@435 1196 instanceKlassHandle SystemDictionary::load_shared_class(
coleenp@2497 1197 Symbol* class_name, Handle class_loader, TRAPS) {
duke@435 1198 instanceKlassHandle ik (THREAD, find_shared_class(class_name));
duke@435 1199 return load_shared_class(ik, class_loader, THREAD);
duke@435 1200 }
duke@435 1201
duke@435 1202 // Note well! Changes to this method may affect oop access order
duke@435 1203 // in the shared archive. Please take care to not make changes that
duke@435 1204 // adversely affect cold start time by changing the oop access order
duke@435 1205 // that is specified in dump.cpp MarkAndMoveOrderedReadOnly and
duke@435 1206 // MarkAndMoveOrderedReadWrite closures.
duke@435 1207 instanceKlassHandle SystemDictionary::load_shared_class(
duke@435 1208 instanceKlassHandle ik, Handle class_loader, TRAPS) {
duke@435 1209 assert(class_loader.is_null(), "non-null classloader for shared class?");
duke@435 1210 if (ik.not_null()) {
duke@435 1211 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
coleenp@2497 1212 Symbol* class_name = ik->name();
duke@435 1213
duke@435 1214 // Found the class, now load the superclass and interfaces. If they
duke@435 1215 // are shared, add them to the main system dictionary and reset
duke@435 1216 // their hierarchy references (supers, subs, and interfaces).
duke@435 1217
duke@435 1218 if (ik->super() != NULL) {
coleenp@2497 1219 Symbol* cn = ik->super()->klass_part()->name();
duke@435 1220 resolve_super_or_fail(class_name, cn,
duke@435 1221 class_loader, Handle(), true, CHECK_(nh));
duke@435 1222 }
duke@435 1223
duke@435 1224 objArrayHandle interfaces (THREAD, ik->local_interfaces());
duke@435 1225 int num_interfaces = interfaces->length();
duke@435 1226 for (int index = 0; index < num_interfaces; index++) {
duke@435 1227 klassOop k = klassOop(interfaces->obj_at(index));
duke@435 1228
duke@435 1229 // Note: can not use instanceKlass::cast here because
duke@435 1230 // interfaces' instanceKlass's C++ vtbls haven't been
duke@435 1231 // reinitialized yet (they will be once the interface classes
duke@435 1232 // are loaded)
coleenp@2497 1233 Symbol* name = k->klass_part()->name();
duke@435 1234 resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh));
duke@435 1235 }
duke@435 1236
duke@435 1237 // Adjust methods to recover missing data. They need addresses for
duke@435 1238 // interpreter entry points and their default native method address
duke@435 1239 // must be reset.
duke@435 1240
duke@435 1241 // Updating methods must be done under a lock so multiple
duke@435 1242 // threads don't update these in parallel
duke@435 1243 // Shared classes are all currently loaded by the bootstrap
duke@435 1244 // classloader, so this will never cause a deadlock on
duke@435 1245 // a custom class loader lock.
duke@435 1246
duke@435 1247 {
duke@435 1248 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
duke@435 1249 check_loader_lock_contention(lockObject, THREAD);
duke@435 1250 ObjectLocker ol(lockObject, THREAD, true);
duke@435 1251
duke@435 1252 objArrayHandle methods (THREAD, ik->methods());
duke@435 1253 int num_methods = methods->length();
duke@435 1254 for (int index2 = 0; index2 < num_methods; ++index2) {
duke@435 1255 methodHandle m(THREAD, methodOop(methods->obj_at(index2)));
duke@435 1256 m()->link_method(m, CHECK_(nh));
duke@435 1257 }
duke@435 1258 }
duke@435 1259
duke@435 1260 if (TraceClassLoading) {
duke@435 1261 ResourceMark rm;
duke@435 1262 tty->print("[Loaded %s", ik->external_name());
duke@435 1263 tty->print(" from shared objects file");
duke@435 1264 tty->print_cr("]");
duke@435 1265 }
duke@435 1266 // notify a class loaded from shared object
duke@435 1267 ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()),
duke@435 1268 true /* shared class */);
duke@435 1269 }
duke@435 1270 return ik;
duke@435 1271 }
duke@435 1272
duke@435 1273 #ifdef KERNEL
duke@435 1274 // Some classes on the bootstrap class path haven't been installed on the
duke@435 1275 // system yet. Call the DownloadManager method to make them appear in the
duke@435 1276 // bootstrap class path and try again to load the named class.
duke@435 1277 // Note that with delegation class loaders all classes in another loader will
duke@435 1278 // first try to call this so it'd better be fast!!
duke@435 1279 static instanceKlassHandle download_and_retry_class_load(
coleenp@2497 1280 Symbol* class_name,
duke@435 1281 TRAPS) {
duke@435 1282
duke@435 1283 klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass();
duke@435 1284 instanceKlassHandle nk;
duke@435 1285
duke@435 1286 // If download manager class isn't loaded just return.
duke@435 1287 if (dlm == NULL) return nk;
duke@435 1288
duke@435 1289 { HandleMark hm(THREAD);
duke@435 1290 ResourceMark rm(THREAD);
duke@435 1291 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk));
duke@435 1292 Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk));
duke@435 1293
duke@435 1294 // return value
duke@435 1295 JavaValue result(T_OBJECT);
duke@435 1296
duke@435 1297 // Call the DownloadManager. We assume that it has a lock because
duke@435 1298 // multiple classes could be not found and downloaded at the same time.
duke@435 1299 // class sun.misc.DownloadManager;
duke@435 1300 // public static String getBootClassPathEntryForClass(String className);
duke@435 1301 JavaCalls::call_static(&result,
duke@435 1302 KlassHandle(THREAD, dlm),
coleenp@2497 1303 vmSymbols::getBootClassPathEntryForClass_name(),
coleenp@2497 1304 vmSymbols::string_string_signature(),
duke@435 1305 class_string,
duke@435 1306 CHECK_(nk));
duke@435 1307
duke@435 1308 // Get result.string and add to bootclasspath
duke@435 1309 assert(result.get_type() == T_OBJECT, "just checking");
duke@435 1310 oop obj = (oop) result.get_jobject();
duke@435 1311 if (obj == NULL) { return nk; }
duke@435 1312
coleenp@457 1313 Handle h_obj(THREAD, obj);
coleenp@457 1314 char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj,
coleenp@457 1315 CHECK_(nk));
duke@435 1316
duke@435 1317 // lock the loader
duke@435 1318 // we use this lock because JVMTI does.
duke@435 1319 Handle loader_lock(THREAD, SystemDictionary::system_loader_lock());
duke@435 1320
duke@435 1321 ObjectLocker ol(loader_lock, THREAD);
duke@435 1322 // add the file to the bootclasspath
duke@435 1323 ClassLoader::update_class_path_entry_list(new_class_name, true);
duke@435 1324 } // end HandleMark
duke@435 1325
duke@435 1326 if (TraceClassLoading) {
duke@435 1327 ClassLoader::print_bootclasspath();
duke@435 1328 }
duke@435 1329 return ClassLoader::load_classfile(class_name, CHECK_(nk));
duke@435 1330 }
duke@435 1331 #endif // KERNEL
duke@435 1332
duke@435 1333
coleenp@2497 1334 instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
duke@435 1335 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
duke@435 1336 if (class_loader.is_null()) {
mchung@1310 1337
duke@435 1338 // Search the shared system dictionary for classes preloaded into the
duke@435 1339 // shared spaces.
duke@435 1340 instanceKlassHandle k;
mchung@1310 1341 {
mchung@1310 1342 PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
mchung@1310 1343 k = load_shared_class(class_name, class_loader, THREAD);
mchung@1310 1344 }
duke@435 1345
duke@435 1346 if (k.is_null()) {
duke@435 1347 // Use VM class loader
mchung@1310 1348 PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
duke@435 1349 k = ClassLoader::load_classfile(class_name, CHECK_(nh));
duke@435 1350 }
duke@435 1351
duke@435 1352 #ifdef KERNEL
duke@435 1353 // If the VM class loader has failed to load the class, call the
duke@435 1354 // DownloadManager class to make it magically appear on the classpath
duke@435 1355 // and try again. This is only configured with the Kernel VM.
duke@435 1356 if (k.is_null()) {
duke@435 1357 k = download_and_retry_class_load(class_name, CHECK_(nh));
duke@435 1358 }
duke@435 1359 #endif // KERNEL
duke@435 1360
acorn@949 1361 // find_or_define_instance_class may return a different instanceKlass
duke@435 1362 if (!k.is_null()) {
duke@435 1363 k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
duke@435 1364 }
duke@435 1365 return k;
duke@435 1366 } else {
duke@435 1367 // Use user specified class loader to load class. Call loadClass operation on class_loader.
duke@435 1368 ResourceMark rm(THREAD);
duke@435 1369
mchung@1310 1370 assert(THREAD->is_Java_thread(), "must be a JavaThread");
mchung@1310 1371 JavaThread* jt = (JavaThread*) THREAD;
mchung@1310 1372
mchung@1310 1373 PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
mchung@1310 1374 ClassLoader::perf_app_classload_selftime(),
mchung@1310 1375 ClassLoader::perf_app_classload_count(),
mchung@1310 1376 jt->get_thread_stat()->perf_recursion_counts_addr(),
mchung@1310 1377 jt->get_thread_stat()->perf_timers_addr(),
mchung@1310 1378 PerfClassTraceTime::CLASS_LOAD);
mchung@1310 1379
duke@435 1380 Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh));
duke@435 1381 // Translate to external class name format, i.e., convert '/' chars to '.'
duke@435 1382 Handle string = java_lang_String::externalize_classname(s, CHECK_(nh));
duke@435 1383
duke@435 1384 JavaValue result(T_OBJECT);
duke@435 1385
never@1577 1386 KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass());
duke@435 1387
acorn@949 1388 // Call public unsynchronized loadClass(String) directly for all class loaders
acorn@949 1389 // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will
acorn@949 1390 // acquire a class-name based lock rather than the class loader object lock.
acorn@949 1391 // JDK < 7 already acquire the class loader lock in loadClass(String, boolean),
acorn@949 1392 // so the call to loadClassInternal() was not required.
acorn@949 1393 //
acorn@949 1394 // UnsyncloadClass flag means both call loadClass(String) and do
acorn@949 1395 // not acquire the class loader lock even for class loaders that are
acorn@949 1396 // not parallelCapable. This was a risky transitional
acorn@949 1397 // flag for diagnostic purposes only. It is risky to call
duke@435 1398 // custom class loaders without synchronization.
duke@435 1399 // WARNING If a custom class loader does NOT synchronizer findClass, or callers of
acorn@949 1400 // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field.
duke@435 1401 // Do NOT assume this will be supported in future releases.
acorn@949 1402 //
acorn@949 1403 // Added MustCallLoadClassInternal in case we discover in the field
acorn@949 1404 // a customer that counts on this call
acorn@949 1405 if (MustCallLoadClassInternal && has_loadClassInternal()) {
duke@435 1406 JavaCalls::call_special(&result,
duke@435 1407 class_loader,
duke@435 1408 spec_klass,
coleenp@2497 1409 vmSymbols::loadClassInternal_name(),
coleenp@2497 1410 vmSymbols::string_class_signature(),
duke@435 1411 string,
duke@435 1412 CHECK_(nh));
duke@435 1413 } else {
duke@435 1414 JavaCalls::call_virtual(&result,
duke@435 1415 class_loader,
duke@435 1416 spec_klass,
coleenp@2497 1417 vmSymbols::loadClass_name(),
coleenp@2497 1418 vmSymbols::string_class_signature(),
duke@435 1419 string,
duke@435 1420 CHECK_(nh));
duke@435 1421 }
duke@435 1422
duke@435 1423 assert(result.get_type() == T_OBJECT, "just checking");
duke@435 1424 oop obj = (oop) result.get_jobject();
duke@435 1425
duke@435 1426 // Primitive classes return null since forName() can not be
duke@435 1427 // used to obtain any of the Class objects representing primitives or void
duke@435 1428 if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
duke@435 1429 instanceKlassHandle k =
duke@435 1430 instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj));
duke@435 1431 // For user defined Java class loaders, check that the name returned is
duke@435 1432 // the same as that requested. This check is done for the bootstrap
duke@435 1433 // loader when parsing the class file.
coleenp@2497 1434 if (class_name == k->name()) {
duke@435 1435 return k;
duke@435 1436 }
duke@435 1437 }
duke@435 1438 // Class is not found or has the wrong name, return NULL
duke@435 1439 return nh;
duke@435 1440 }
duke@435 1441 }
duke@435 1442
duke@435 1443 void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
duke@435 1444
duke@435 1445 Handle class_loader_h(THREAD, k->class_loader());
duke@435 1446
acorn@949 1447 // for bootstrap and other parallel classloaders don't acquire lock,
acorn@949 1448 // use placeholder token
acorn@949 1449 // If a parallelCapable class loader calls define_instance_class instead of
acorn@949 1450 // find_or_define_instance_class to get here, we have a timing
acorn@949 1451 // hole with systemDictionary updates and check_constraints
acorn@949 1452 if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) {
duke@435 1453 assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD,
duke@435 1454 compute_loader_lock_object(class_loader_h, THREAD)),
duke@435 1455 "define called without lock");
duke@435 1456 }
duke@435 1457
duke@435 1458 // Check class-loading constraints. Throw exception if violation is detected.
duke@435 1459 // Grabs and releases SystemDictionary_lock
duke@435 1460 // The check_constraints/find_class call and update_dictionary sequence
duke@435 1461 // must be "atomic" for a specific class/classloader pair so we never
duke@435 1462 // define two different instanceKlasses for that class/classloader pair.
duke@435 1463 // Existing classloaders will call define_instance_class with the
duke@435 1464 // classloader lock held
duke@435 1465 // Parallel classloaders will call find_or_define_instance_class
duke@435 1466 // which will require a token to perform the define class
coleenp@2497 1467 Symbol* name_h = k->name();
duke@435 1468 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
duke@435 1469 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 1470 check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
duke@435 1471
duke@435 1472 // Register class just loaded with class loader (placed in Vector)
duke@435 1473 // Note we do this before updating the dictionary, as this can
duke@435 1474 // fail with an OutOfMemoryError (if it does, we will *not* put this
duke@435 1475 // class in the dictionary and will not update the class hierarchy).
duke@435 1476 if (k->class_loader() != NULL) {
duke@435 1477 methodHandle m(THREAD, Universe::loader_addClass_method());
duke@435 1478 JavaValue result(T_VOID);
duke@435 1479 JavaCallArguments args(class_loader_h);
duke@435 1480 args.push_oop(Handle(THREAD, k->java_mirror()));
duke@435 1481 JavaCalls::call(&result, m, &args, CHECK);
duke@435 1482 }
duke@435 1483
duke@435 1484 // Add the new class. We need recompile lock during update of CHA.
duke@435 1485 {
duke@435 1486 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h);
duke@435 1487 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 1488
duke@435 1489 MutexLocker mu_r(Compile_lock, THREAD);
duke@435 1490
duke@435 1491 // Add to class hierarchy, initialize vtables, and do possible
duke@435 1492 // deoptimizations.
duke@435 1493 add_to_hierarchy(k, CHECK); // No exception, but can block
duke@435 1494
duke@435 1495 // Add to systemDictionary - so other classes can see it.
duke@435 1496 // Grabs and releases SystemDictionary_lock
duke@435 1497 update_dictionary(d_index, d_hash, p_index, p_hash,
duke@435 1498 k, class_loader_h, THREAD);
duke@435 1499 }
duke@435 1500 k->eager_initialize(THREAD);
duke@435 1501
duke@435 1502 // notify jvmti
duke@435 1503 if (JvmtiExport::should_post_class_load()) {
duke@435 1504 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
duke@435 1505 JvmtiExport::post_class_load((JavaThread *) THREAD, k());
duke@435 1506
duke@435 1507 }
duke@435 1508 }
duke@435 1509
duke@435 1510 // Support parallel classloading
acorn@1510 1511 // All parallel class loaders, including bootstrap classloader
acorn@1510 1512 // lock a placeholder entry for this class/class_loader pair
acorn@1510 1513 // to allow parallel defines of different classes for this class loader
acorn@949 1514 // With AllowParallelDefine flag==true, in case they do not synchronize around
acorn@949 1515 // FindLoadedClass/DefineClass, calls, we check for parallel
duke@435 1516 // loading for them, wait if a defineClass is in progress
duke@435 1517 // and return the initial requestor's results
acorn@1510 1518 // This flag does not apply to the bootstrap classloader.
acorn@949 1519 // With AllowParallelDefine flag==false, call through to define_instance_class
acorn@949 1520 // which will throw LinkageError: duplicate class definition.
acorn@1510 1521 // False is the requested default.
duke@435 1522 // For better performance, the class loaders should synchronize
acorn@949 1523 // findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
duke@435 1524 // potentially waste time reading and parsing the bytestream.
duke@435 1525 // Note: VM callers should ensure consistency of k/class_name,class_loader
coleenp@2497 1526 instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
duke@435 1527
duke@435 1528 instanceKlassHandle nh = instanceKlassHandle(); // null Handle
coleenp@2497 1529 Symbol* name_h = k->name(); // passed in class_name may be null
duke@435 1530
acorn@950 1531 unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader);
duke@435 1532 int d_index = dictionary()->hash_to_index(d_hash);
duke@435 1533
duke@435 1534 // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
acorn@950 1535 unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader);
duke@435 1536 int p_index = placeholders()->hash_to_index(p_hash);
duke@435 1537 PlaceholderEntry* probe;
duke@435 1538
duke@435 1539 {
duke@435 1540 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 1541 // First check if class already defined
acorn@1510 1542 if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
acorn@1510 1543 klassOop check = find_class(d_index, d_hash, name_h, class_loader);
acorn@1510 1544 if (check != NULL) {
acorn@1510 1545 return(instanceKlassHandle(THREAD, check));
acorn@1510 1546 }
duke@435 1547 }
duke@435 1548
duke@435 1549 // Acquire define token for this class/classloader
coleenp@2497 1550 probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
acorn@949 1551 // Wait if another thread defining in parallel
acorn@949 1552 // All threads wait - even those that will throw duplicate class: otherwise
acorn@949 1553 // caller is surprised by LinkageError: duplicate, but findLoadedClass fails
acorn@949 1554 // if other thread has not finished updating dictionary
acorn@949 1555 while (probe->definer() != NULL) {
acorn@949 1556 SystemDictionary_lock->wait();
acorn@949 1557 }
acorn@949 1558 // Only special cases allow parallel defines and can use other thread's results
acorn@949 1559 // Other cases fall through, and may run into duplicate defines
acorn@949 1560 // caught by finding an entry in the SystemDictionary
acorn@1510 1561 if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) {
jrose@866 1562 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
acorn@950 1563 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
acorn@949 1564 SystemDictionary_lock->notify_all();
jrose@866 1565 #ifdef ASSERT
acorn@950 1566 klassOop check = find_class(d_index, d_hash, name_h, class_loader);
acorn@949 1567 assert(check != NULL, "definer missed recording success");
jrose@866 1568 #endif
acorn@949 1569 return(instanceKlassHandle(THREAD, probe->instanceKlass()));
acorn@949 1570 } else {
acorn@949 1571 // This thread will define the class (even if earlier thread tried and had an error)
duke@435 1572 probe->set_definer(THREAD);
duke@435 1573 }
duke@435 1574 }
duke@435 1575
duke@435 1576 define_instance_class(k, THREAD);
duke@435 1577
duke@435 1578 Handle linkage_exception = Handle(); // null handle
duke@435 1579
duke@435 1580 // definer must notify any waiting threads
duke@435 1581 {
duke@435 1582 MutexLocker mu(SystemDictionary_lock, THREAD);
acorn@950 1583 PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader);
duke@435 1584 assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
duke@435 1585 if (probe != NULL) {
duke@435 1586 if (HAS_PENDING_EXCEPTION) {
duke@435 1587 linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
duke@435 1588 CLEAR_PENDING_EXCEPTION;
duke@435 1589 } else {
duke@435 1590 probe->set_instanceKlass(k());
duke@435 1591 }
duke@435 1592 probe->set_definer(NULL);
duke@435 1593 probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
acorn@950 1594 placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
duke@435 1595 SystemDictionary_lock->notify_all();
duke@435 1596 }
duke@435 1597 }
duke@435 1598
duke@435 1599 // Can't throw exception while holding lock due to rank ordering
duke@435 1600 if (linkage_exception() != NULL) {
duke@435 1601 THROW_OOP_(linkage_exception(), nh); // throws exception and returns
duke@435 1602 }
duke@435 1603
duke@435 1604 return k;
duke@435 1605 }
duke@435 1606 Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
duke@435 1607 // If class_loader is NULL we synchronize on _system_loader_lock_obj
duke@435 1608 if (class_loader.is_null()) {
duke@435 1609 return Handle(THREAD, _system_loader_lock_obj);
duke@435 1610 } else {
duke@435 1611 return class_loader;
duke@435 1612 }
duke@435 1613 }
duke@435 1614
duke@435 1615 // This method is added to check how often we have to wait to grab loader
duke@435 1616 // lock. The results are being recorded in the performance counters defined in
duke@435 1617 // ClassLoader::_sync_systemLoaderLockContentionRate and
duke@435 1618 // ClassLoader::_sync_nonSystemLoaderLockConteionRate.
duke@435 1619 void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
duke@435 1620 if (!UsePerfData) {
duke@435 1621 return;
duke@435 1622 }
duke@435 1623
duke@435 1624 assert(!loader_lock.is_null(), "NULL lock object");
duke@435 1625
duke@435 1626 if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
duke@435 1627 == ObjectSynchronizer::owner_other) {
duke@435 1628 // contention will likely happen, so increment the corresponding
duke@435 1629 // contention counter.
duke@435 1630 if (loader_lock() == _system_loader_lock_obj) {
duke@435 1631 ClassLoader::sync_systemLoaderLockContentionRate()->inc();
duke@435 1632 } else {
duke@435 1633 ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
duke@435 1634 }
duke@435 1635 }
duke@435 1636 }
duke@435 1637
duke@435 1638 // ----------------------------------------------------------------------------
duke@435 1639 // Lookup
duke@435 1640
duke@435 1641 klassOop SystemDictionary::find_class(int index, unsigned int hash,
coleenp@2497 1642 Symbol* class_name,
duke@435 1643 Handle class_loader) {
duke@435 1644 assert_locked_or_safepoint(SystemDictionary_lock);
duke@435 1645 assert (index == dictionary()->index_for(class_name, class_loader),
duke@435 1646 "incorrect index?");
duke@435 1647
duke@435 1648 klassOop k = dictionary()->find_class(index, hash, class_name, class_loader);
duke@435 1649 return k;
duke@435 1650 }
duke@435 1651
duke@435 1652
duke@435 1653 // Basic find on classes in the midst of being loaded
coleenp@2497 1654 Symbol* SystemDictionary::find_placeholder(Symbol* class_name,
coleenp@2497 1655 Handle class_loader) {
duke@435 1656 assert_locked_or_safepoint(SystemDictionary_lock);
coleenp@2497 1657 unsigned int p_hash = placeholders()->compute_hash(class_name, class_loader);
coleenp@2497 1658 int p_index = placeholders()->hash_to_index(p_hash);
coleenp@2497 1659 return placeholders()->find_entry(p_index, p_hash, class_name, class_loader);
duke@435 1660 }
duke@435 1661
duke@435 1662
duke@435 1663 // Used for assertions and verification only
coleenp@2497 1664 klassOop SystemDictionary::find_class(Symbol* class_name, Handle class_loader) {
duke@435 1665 #ifndef ASSERT
duke@435 1666 guarantee(VerifyBeforeGC ||
duke@435 1667 VerifyDuringGC ||
duke@435 1668 VerifyBeforeExit ||
duke@435 1669 VerifyAfterGC, "too expensive");
duke@435 1670 #endif
duke@435 1671 assert_locked_or_safepoint(SystemDictionary_lock);
duke@435 1672
duke@435 1673 // First look in the loaded class array
duke@435 1674 unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
duke@435 1675 int d_index = dictionary()->hash_to_index(d_hash);
coleenp@2497 1676 return find_class(d_index, d_hash, class_name, class_loader);
duke@435 1677 }
duke@435 1678
duke@435 1679
duke@435 1680 // Get the next class in the diictionary.
duke@435 1681 klassOop SystemDictionary::try_get_next_class() {
duke@435 1682 return dictionary()->try_get_next_class();
duke@435 1683 }
duke@435 1684
duke@435 1685
duke@435 1686 // ----------------------------------------------------------------------------
duke@435 1687 // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock
duke@435 1688 // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in
duke@435 1689 // before a new class is used.
duke@435 1690
duke@435 1691 void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
duke@435 1692 assert(k.not_null(), "just checking");
never@2551 1693 assert_locked_or_safepoint(Compile_lock);
never@2551 1694
duke@435 1695 // Link into hierachy. Make sure the vtables are initialized before linking into
duke@435 1696 k->append_to_sibling_list(); // add to superklass/sibling list
duke@435 1697 k->process_interfaces(THREAD); // handle all "implements" declarations
duke@435 1698 k->set_init_state(instanceKlass::loaded);
duke@435 1699 // Now flush all code that depended on old class hierarchy.
duke@435 1700 // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97)
duke@435 1701 // Also, first reinitialize vtable because it may have gotten out of synch
duke@435 1702 // while the new class wasn't connected to the class hierarchy.
duke@435 1703 Universe::flush_dependents_on(k);
duke@435 1704 }
duke@435 1705
duke@435 1706
duke@435 1707 // ----------------------------------------------------------------------------
duke@435 1708 // GC support
duke@435 1709
duke@435 1710 // Following roots during mark-sweep is separated in two phases.
duke@435 1711 //
duke@435 1712 // The first phase follows preloaded classes and all other system
duke@435 1713 // classes, since these will never get unloaded anyway.
duke@435 1714 //
duke@435 1715 // The second phase removes (unloads) unreachable classes from the
duke@435 1716 // system dictionary and follows the remaining classes' contents.
duke@435 1717
duke@435 1718 void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
duke@435 1719 // Follow preloaded classes/mirrors and system loader object
duke@435 1720 blk->do_oop(&_java_system_loader);
duke@435 1721 preloaded_oops_do(blk);
duke@435 1722 always_strong_classes_do(blk);
duke@435 1723 }
duke@435 1724
duke@435 1725
duke@435 1726 void SystemDictionary::always_strong_classes_do(OopClosure* blk) {
duke@435 1727 // Follow all system classes and temporary placeholders in dictionary
duke@435 1728 dictionary()->always_strong_classes_do(blk);
duke@435 1729
duke@435 1730 // Placeholders. These are *always* strong roots, as they
duke@435 1731 // represent classes we're actively loading.
duke@435 1732 placeholders_do(blk);
duke@435 1733
jrose@1145 1734 // Visit extra methods
twisti@2258 1735 invoke_method_table()->oops_do(blk);
duke@435 1736 }
duke@435 1737
duke@435 1738
duke@435 1739 void SystemDictionary::placeholders_do(OopClosure* blk) {
duke@435 1740 placeholders()->oops_do(blk);
duke@435 1741 }
duke@435 1742
duke@435 1743
duke@435 1744 bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {
duke@435 1745 bool result = dictionary()->do_unloading(is_alive);
duke@435 1746 constraints()->purge_loader_constraints(is_alive);
duke@435 1747 resolution_errors()->purge_resolution_errors(is_alive);
duke@435 1748 return result;
duke@435 1749 }
duke@435 1750
duke@435 1751
duke@435 1752 // The mirrors are scanned by shared_oops_do() which is
duke@435 1753 // not called by oops_do(). In order to process oops in
duke@435 1754 // a necessary order, shared_oops_do() is call by
duke@435 1755 // Universe::oops_do().
duke@435 1756 void SystemDictionary::oops_do(OopClosure* f) {
duke@435 1757 // Adjust preloaded classes and system loader object
duke@435 1758 f->do_oop(&_java_system_loader);
duke@435 1759 preloaded_oops_do(f);
duke@435 1760
duke@435 1761 lazily_loaded_oops_do(f);
duke@435 1762
duke@435 1763 // Adjust dictionary
duke@435 1764 dictionary()->oops_do(f);
duke@435 1765
jrose@1145 1766 // Visit extra methods
twisti@2258 1767 invoke_method_table()->oops_do(f);
jrose@1145 1768
duke@435 1769 // Partially loaded classes
duke@435 1770 placeholders()->oops_do(f);
duke@435 1771
duke@435 1772 // Adjust constraint table
duke@435 1773 constraints()->oops_do(f);
duke@435 1774
duke@435 1775 // Adjust resolution error table
duke@435 1776 resolution_errors()->oops_do(f);
duke@435 1777 }
duke@435 1778
duke@435 1779
duke@435 1780 void SystemDictionary::preloaded_oops_do(OopClosure* f) {
jrose@567 1781 for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
jrose@567 1782 f->do_oop((oop*) &_well_known_klasses[k]);
jrose@567 1783 }
duke@435 1784
duke@435 1785 {
duke@435 1786 for (int i = 0; i < T_VOID+1; i++) {
duke@435 1787 if (_box_klasses[i] != NULL) {
duke@435 1788 assert(i >= T_BOOLEAN, "checking");
duke@435 1789 f->do_oop((oop*) &_box_klasses[i]);
duke@435 1790 }
duke@435 1791 }
duke@435 1792 }
duke@435 1793
duke@435 1794 // The basic type mirrors would have already been processed in
duke@435 1795 // Universe::oops_do(), via a call to shared_oops_do(), so should
duke@435 1796 // not be processed again.
duke@435 1797
duke@435 1798 f->do_oop((oop*) &_system_loader_lock_obj);
duke@435 1799 FilteredFieldsMap::klasses_oops_do(f);
duke@435 1800 }
duke@435 1801
duke@435 1802 void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) {
duke@435 1803 f->do_oop((oop*) &_abstract_ownable_synchronizer_klass);
duke@435 1804 }
duke@435 1805
duke@435 1806 // Just the classes from defining class loaders
duke@435 1807 // Don't iterate over placeholders
duke@435 1808 void SystemDictionary::classes_do(void f(klassOop)) {
duke@435 1809 dictionary()->classes_do(f);
duke@435 1810 }
duke@435 1811
duke@435 1812 // Added for initialize_itable_for_klass
duke@435 1813 // Just the classes from defining class loaders
duke@435 1814 // Don't iterate over placeholders
duke@435 1815 void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
duke@435 1816 dictionary()->classes_do(f, CHECK);
duke@435 1817 }
duke@435 1818
duke@435 1819 // All classes, and their class loaders
duke@435 1820 // Don't iterate over placeholders
duke@435 1821 void SystemDictionary::classes_do(void f(klassOop, oop)) {
duke@435 1822 dictionary()->classes_do(f);
duke@435 1823 }
duke@435 1824
duke@435 1825 // All classes, and their class loaders
duke@435 1826 // (added for helpers that use HandleMarks and ResourceMarks)
duke@435 1827 // Don't iterate over placeholders
duke@435 1828 void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
duke@435 1829 dictionary()->classes_do(f, CHECK);
duke@435 1830 }
duke@435 1831
coleenp@2497 1832 void SystemDictionary::placeholders_do(void f(Symbol*, oop)) {
duke@435 1833 placeholders()->entries_do(f);
duke@435 1834 }
duke@435 1835
duke@435 1836 void SystemDictionary::methods_do(void f(methodOop)) {
duke@435 1837 dictionary()->methods_do(f);
twisti@2258 1838 invoke_method_table()->methods_do(f);
duke@435 1839 }
duke@435 1840
duke@435 1841 // ----------------------------------------------------------------------------
duke@435 1842 // Lazily load klasses
duke@435 1843
duke@435 1844 void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
duke@435 1845 assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later");
duke@435 1846
duke@435 1847 // if multiple threads calling this function, only one thread will load
duke@435 1848 // the class. The other threads will find the loaded version once the
duke@435 1849 // class is loaded.
duke@435 1850 klassOop aos = _abstract_ownable_synchronizer_klass;
duke@435 1851 if (aos == NULL) {
coleenp@2497 1852 klassOop k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
duke@435 1853 // Force a fence to prevent any read before the write completes
duke@435 1854 OrderAccess::fence();
duke@435 1855 _abstract_ownable_synchronizer_klass = k;
duke@435 1856 }
duke@435 1857 }
duke@435 1858
duke@435 1859 // ----------------------------------------------------------------------------
duke@435 1860 // Initialization
duke@435 1861
duke@435 1862 void SystemDictionary::initialize(TRAPS) {
duke@435 1863 // Allocate arrays
duke@435 1864 assert(dictionary() == NULL,
duke@435 1865 "SystemDictionary should only be initialized once");
twisti@2258 1866 _dictionary = new Dictionary(_nof_buckets);
twisti@2258 1867 _placeholders = new PlaceholderTable(_nof_buckets);
duke@435 1868 _number_of_modifications = 0;
twisti@2258 1869 _loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
twisti@2258 1870 _resolution_errors = new ResolutionErrorTable(_resolution_error_size);
twisti@2258 1871 _invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
duke@435 1872
duke@435 1873 // Allocate private object used as system class loader lock
duke@435 1874 _system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK);
duke@435 1875 // Initialize basic classes
duke@435 1876 initialize_preloaded_classes(CHECK);
duke@435 1877 }
duke@435 1878
jrose@567 1879 // Compact table of directions on the initialization of klasses:
jrose@567 1880 static const short wk_init_info[] = {
jrose@567 1881 #define WK_KLASS_INIT_INFO(name, symbol, option) \
jrose@567 1882 ( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \
jrose@567 1883 << SystemDictionary::CEIL_LG_OPTION_LIMIT) \
jrose@567 1884 | (int)SystemDictionary::option ),
jrose@567 1885 WK_KLASSES_DO(WK_KLASS_INIT_INFO)
jrose@567 1886 #undef WK_KLASS_INIT_INFO
jrose@567 1887 0
jrose@567 1888 };
jrose@567 1889
jrose@2638 1890 Symbol* SystemDictionary::find_backup_symbol(Symbol* symbol,
jrose@2638 1891 const char* from_prefix,
jrose@2638 1892 const char* to_prefix) {
jrose@2638 1893 assert(AllowTransitionalJSR292, ""); // delete this subroutine
jrose@2638 1894 Symbol* backup_symbol = NULL;
jrose@2638 1895 size_t from_len = strlen(from_prefix);
jrose@2638 1896 if (strncmp((const char*) symbol->base(), from_prefix, from_len) != 0)
jrose@2638 1897 return NULL;
jrose@2638 1898 char buf[100];
jrose@2638 1899 size_t to_len = strlen(to_prefix);
jrose@2638 1900 size_t tail_len = symbol->utf8_length() - from_len;
jrose@2638 1901 size_t new_len = to_len + tail_len;
jrose@2638 1902 guarantee(new_len < sizeof(buf), "buf too small");
jrose@2638 1903 memcpy(buf, to_prefix, to_len);
jrose@2638 1904 memcpy(buf + to_len, symbol->base() + from_len, tail_len);
jrose@2638 1905 buf[new_len] = '\0';
jrose@2638 1906 vmSymbols::SID backup_sid = vmSymbols::find_sid(buf);
jrose@2638 1907 if (backup_sid != vmSymbols::NO_SID) {
jrose@2638 1908 backup_symbol = vmSymbols::symbol_at(backup_sid);
jrose@2638 1909 }
jrose@2638 1910 return backup_symbol;
jrose@2638 1911 }
jrose@2638 1912
jrose@2638 1913 Symbol* SystemDictionary::find_backup_class_name(Symbol* symbol) {
jrose@2638 1914 assert(AllowTransitionalJSR292, ""); // delete this subroutine
jrose@2638 1915 if (symbol == NULL) return NULL;
jrose@2638 1916 Symbol* backup_symbol = find_backup_symbol(symbol, "java/lang/invoke/", "java/dyn/"); // AllowTransitionalJSR292 ONLY
jrose@2638 1917 if (backup_symbol == NULL)
jrose@2638 1918 backup_symbol = find_backup_symbol(symbol, "java/dyn/", "sun/dyn/"); // AllowTransitionalJSR292 ONLY
jrose@2638 1919 return backup_symbol;
jrose@2638 1920 }
jrose@2638 1921
jrose@2638 1922 Symbol* SystemDictionary::find_backup_signature(Symbol* symbol) {
jrose@2638 1923 assert(AllowTransitionalJSR292, ""); // delete this subroutine
jrose@2638 1924 if (symbol == NULL) return NULL;
jrose@2638 1925 return find_backup_symbol(symbol, "Ljava/lang/invoke/", "Ljava/dyn/");
jrose@2638 1926 }
jrose@2638 1927
jrose@567 1928 bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) {
jrose@567 1929 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
jrose@567 1930 int info = wk_init_info[id - FIRST_WKID];
jrose@567 1931 int sid = (info >> CEIL_LG_OPTION_LIMIT);
coleenp@2497 1932 Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
jrose@567 1933 klassOop* klassp = &_well_known_klasses[id];
jrose@2638 1934 bool pre_load = (init_opt < SystemDictionary::Opt);
jrose@2638 1935 bool try_load = true;
jrose@567 1936 if (init_opt == SystemDictionary::Opt_Kernel) {
jrose@567 1937 #ifndef KERNEL
jrose@567 1938 try_load = false;
jrose@567 1939 #endif //KERNEL
jrose@567 1940 }
jrose@2638 1941 Symbol* backup_symbol = NULL; // symbol to try if the current symbol fails
jrose@2638 1942 if (init_opt == SystemDictionary::Pre_JSR292) {
jrose@2638 1943 if (!EnableMethodHandles) try_load = false; // do not bother to load such classes
jrose@2638 1944 if (AllowTransitionalJSR292) {
jrose@2638 1945 backup_symbol = find_backup_class_name(symbol);
jrose@2638 1946 if (try_load && PreferTransitionalJSR292) {
jrose@2638 1947 while (backup_symbol != NULL) {
jrose@2638 1948 (*klassp) = resolve_or_null(backup_symbol, CHECK_0); // try backup early
jrose@2638 1949 if (TraceMethodHandles) {
jrose@2638 1950 ResourceMark rm;
jrose@2638 1951 tty->print_cr("MethodHandles: try backup first for %s => %s (%s)",
jrose@2638 1952 symbol->as_C_string(), backup_symbol->as_C_string(),
jrose@2638 1953 ((*klassp) == NULL) ? "no such class" : "backup load succeeded");
jrose@2638 1954 }
jrose@2638 1955 if ((*klassp) != NULL) return true;
jrose@2638 1956 backup_symbol = find_backup_class_name(backup_symbol); // find next backup
jrose@2638 1957 }
jrose@2638 1958 }
jrose@2638 1959 }
jrose@2638 1960 }
jrose@2638 1961 if ((*klassp) != NULL) return true;
jrose@2638 1962 if (!try_load) return false;
jrose@2638 1963 while (symbol != NULL) {
jrose@2638 1964 bool must_load = (pre_load && (backup_symbol == NULL));
jrose@567 1965 if (must_load) {
jrose@567 1966 (*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
jrose@567 1967 } else {
jrose@567 1968 (*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass
jrose@567 1969 }
jrose@2638 1970 if ((*klassp) != NULL) return true;
jrose@2638 1971 // Go around again. Example of long backup sequence:
jrose@2638 1972 // java.lang.invoke.MemberName, java.dyn.MemberName, sun.dyn.MemberName, ONLY if AllowTransitionalJSR292
jrose@2638 1973 if (TraceMethodHandles && (backup_symbol != NULL)) {
jrose@2638 1974 ResourceMark rm;
jrose@2638 1975 tty->print_cr("MethodHandles: backup for %s => %s",
jrose@2638 1976 symbol->as_C_string(), backup_symbol->as_C_string());
jrose@2638 1977 }
jrose@2638 1978 symbol = backup_symbol;
jrose@2638 1979 if (AllowTransitionalJSR292)
jrose@2638 1980 backup_symbol = find_backup_class_name(symbol);
jrose@567 1981 }
jrose@2638 1982 return false;
jrose@567 1983 }
jrose@567 1984
jrose@567 1985 void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
jrose@567 1986 assert((int)start_id <= (int)limit_id, "IDs are out of order!");
jrose@567 1987 for (int id = (int)start_id; id < (int)limit_id; id++) {
jrose@567 1988 assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
jrose@567 1989 int info = wk_init_info[id - FIRST_WKID];
jrose@567 1990 int sid = (info >> CEIL_LG_OPTION_LIMIT);
jrose@567 1991 int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT));
jrose@567 1992
jrose@567 1993 initialize_wk_klass((WKID)id, opt, CHECK);
jrose@567 1994
jrose@567 1995 // Update limits, so find_well_known_klass can be very fast:
coleenp@2497 1996 Symbol* s = vmSymbols::symbol_at((vmSymbols::SID)sid);
jrose@567 1997 if (wk_klass_name_limits[1] == NULL) {
jrose@567 1998 wk_klass_name_limits[0] = wk_klass_name_limits[1] = s;
jrose@567 1999 } else if (wk_klass_name_limits[1] < s) {
jrose@567 2000 wk_klass_name_limits[1] = s;
jrose@567 2001 } else if (wk_klass_name_limits[0] > s) {
jrose@567 2002 wk_klass_name_limits[0] = s;
jrose@567 2003 }
jrose@567 2004 }
jrose@1145 2005
jrose@1145 2006 // move the starting value forward to the limit:
jrose@1145 2007 start_id = limit_id;
jrose@567 2008 }
jrose@567 2009
duke@435 2010
duke@435 2011 void SystemDictionary::initialize_preloaded_classes(TRAPS) {
never@1577 2012 assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once");
duke@435 2013 // Preload commonly used klasses
jrose@567 2014 WKID scan = FIRST_WKID;
jrose@567 2015 // first do Object, String, Class
never@1577 2016 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
jrose@567 2017
never@1577 2018 debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(Class_klass)));
jrose@567 2019
duke@435 2020 // Fixup mirrors for classes loaded before java.lang.Class.
duke@435 2021 // These calls iterate over the objects currently in the perm gen
duke@435 2022 // so calling them at this point is matters (not before when there
duke@435 2023 // are fewer objects and not later after there are more objects
duke@435 2024 // in the perm gen.
duke@435 2025 Universe::initialize_basic_type_mirrors(CHECK);
duke@435 2026 Universe::fixup_mirrors(CHECK);
duke@435 2027
jrose@567 2028 // do a bunch more:
never@1577 2029 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
duke@435 2030
duke@435 2031 // Preload ref klasses and set reference types
never@1577 2032 instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
never@1577 2033 instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
duke@435 2034
never@1577 2035 initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
never@1577 2036 instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
never@1577 2037 instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
never@1577 2038 instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
never@1577 2039 instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
duke@435 2040
jrose@1145 2041 WKID meth_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
jrose@1145 2042 WKID meth_group_end = WK_KLASS_ENUM_NAME(WrongMethodTypeException_klass);
jrose@1145 2043 initialize_wk_klasses_until(meth_group_start, scan, CHECK);
jrose@1145 2044 if (EnableMethodHandles) {
jrose@1474 2045 initialize_wk_klasses_through(meth_group_end, scan, CHECK);
jrose@1145 2046 }
jrose@1145 2047 if (_well_known_klasses[meth_group_start] == NULL) {
jrose@1145 2048 // Skip the rest of the method handle classes, if MethodHandle is not loaded.
jrose@1145 2049 scan = WKID(meth_group_end+1);
jrose@1145 2050 }
jrose@1161 2051 WKID indy_group_start = WK_KLASS_ENUM_NAME(Linkage_klass);
twisti@2343 2052 WKID indy_group_end = WK_KLASS_ENUM_NAME(CallSite_klass);
jrose@1161 2053 initialize_wk_klasses_until(indy_group_start, scan, CHECK);
jrose@1161 2054 if (EnableInvokeDynamic) {
jrose@1494 2055 initialize_wk_klasses_through(indy_group_end, scan, CHECK);
jrose@1161 2056 }
jrose@1161 2057 if (_well_known_klasses[indy_group_start] == NULL) {
jrose@1161 2058 // Skip the rest of the dynamic typing classes, if Linkage is not loaded.
jrose@1161 2059 scan = WKID(indy_group_end+1);
jrose@1161 2060 }
jrose@1145 2061
jrose@567 2062 initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
duke@435 2063
never@1577 2064 _box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
never@1577 2065 _box_klasses[T_CHAR] = WK_KLASS(Character_klass);
never@1577 2066 _box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
never@1577 2067 _box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
never@1577 2068 _box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
never@1577 2069 _box_klasses[T_SHORT] = WK_KLASS(Short_klass);
never@1577 2070 _box_klasses[T_INT] = WK_KLASS(Integer_klass);
never@1577 2071 _box_klasses[T_LONG] = WK_KLASS(Long_klass);
jrose@567 2072 //_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
jrose@567 2073 //_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
duke@435 2074
duke@435 2075 #ifdef KERNEL
jrose@567 2076 if (sun_jkernel_DownloadManager_klass() == NULL) {
duke@435 2077 warning("Cannot find sun/jkernel/DownloadManager");
duke@435 2078 }
duke@435 2079 #endif // KERNEL
acorn@949 2080
duke@435 2081 { // Compute whether we should use loadClass or loadClassInternal when loading classes.
never@1577 2082 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
duke@435 2083 _has_loadClassInternal = (method != NULL);
duke@435 2084 }
duke@435 2085 { // Compute whether we should use checkPackageAccess or NOT
never@1577 2086 methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
duke@435 2087 _has_checkPackageAccess = (method != NULL);
duke@435 2088 }
duke@435 2089 }
duke@435 2090
duke@435 2091 // Tells if a given klass is a box (wrapper class, such as java.lang.Integer).
duke@435 2092 // If so, returns the basic type it holds. If not, returns T_OBJECT.
duke@435 2093 BasicType SystemDictionary::box_klass_type(klassOop k) {
duke@435 2094 assert(k != NULL, "");
duke@435 2095 for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
duke@435 2096 if (_box_klasses[i] == k)
duke@435 2097 return (BasicType)i;
duke@435 2098 }
duke@435 2099 return T_OBJECT;
duke@435 2100 }
duke@435 2101
jrose@1100 2102 KlassHandle SystemDictionaryHandles::box_klass(BasicType t) {
jrose@1100 2103 if (t >= T_BOOLEAN && t <= T_VOID)
jrose@1100 2104 return KlassHandle(&SystemDictionary::_box_klasses[t], true);
jrose@1100 2105 else
jrose@1100 2106 return KlassHandle();
jrose@1100 2107 }
jrose@1100 2108
duke@435 2109 // Constraints on class loaders. The details of the algorithm can be
duke@435 2110 // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java
duke@435 2111 // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is
duke@435 2112 // that the system dictionary needs to maintain a set of contraints that
duke@435 2113 // must be satisfied by all classes in the dictionary.
duke@435 2114 // if defining is true, then LinkageError if already in systemDictionary
duke@435 2115 // if initiating loader, then ok if instanceKlass matches existing entry
duke@435 2116
duke@435 2117 void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
duke@435 2118 instanceKlassHandle k,
duke@435 2119 Handle class_loader, bool defining,
duke@435 2120 TRAPS) {
duke@435 2121 const char *linkage_error = NULL;
duke@435 2122 {
coleenp@2497 2123 Symbol* name = k->name();
duke@435 2124 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 2125
duke@435 2126 klassOop check = find_class(d_index, d_hash, name, class_loader);
duke@435 2127 if (check != (klassOop)NULL) {
duke@435 2128 // if different instanceKlass - duplicate class definition,
duke@435 2129 // else - ok, class loaded by a different thread in parallel,
duke@435 2130 // we should only have found it if it was done loading and ok to use
duke@435 2131 // system dictionary only holds instance classes, placeholders
duke@435 2132 // also holds array classes
duke@435 2133
duke@435 2134 assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
duke@435 2135 if ((defining == true) || (k() != check)) {
duke@435 2136 linkage_error = "loader (instance of %s): attempted duplicate class "
duke@435 2137 "definition for name: \"%s\"";
duke@435 2138 } else {
duke@435 2139 return;
duke@435 2140 }
duke@435 2141 }
duke@435 2142
duke@435 2143 #ifdef ASSERT
coleenp@2497 2144 Symbol* ph_check = find_placeholder(name, class_loader);
coleenp@2497 2145 assert(ph_check == NULL || ph_check == name, "invalid symbol");
duke@435 2146 #endif
duke@435 2147
duke@435 2148 if (linkage_error == NULL) {
duke@435 2149 if (constraints()->check_or_update(k, class_loader, name) == false) {
duke@435 2150 linkage_error = "loader constraint violation: loader (instance of %s)"
duke@435 2151 " previously initiated loading for a different type with name \"%s\"";
duke@435 2152 }
duke@435 2153 }
duke@435 2154 }
duke@435 2155
duke@435 2156 // Throw error now if needed (cannot throw while holding
duke@435 2157 // SystemDictionary_lock because of rank ordering)
duke@435 2158
duke@435 2159 if (linkage_error) {
duke@435 2160 ResourceMark rm(THREAD);
duke@435 2161 const char* class_loader_name = loader_name(class_loader());
duke@435 2162 char* type_name = k->name()->as_C_string();
duke@435 2163 size_t buflen = strlen(linkage_error) + strlen(class_loader_name) +
duke@435 2164 strlen(type_name);
duke@435 2165 char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
duke@435 2166 jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name);
duke@435 2167 THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
duke@435 2168 }
duke@435 2169 }
duke@435 2170
duke@435 2171
duke@435 2172 // Update system dictionary - done after check_constraint and add_to_hierachy
duke@435 2173 // have been called.
duke@435 2174 void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
duke@435 2175 int p_index, unsigned int p_hash,
duke@435 2176 instanceKlassHandle k,
duke@435 2177 Handle class_loader,
duke@435 2178 TRAPS) {
duke@435 2179 // Compile_lock prevents systemDictionary updates during compilations
duke@435 2180 assert_locked_or_safepoint(Compile_lock);
coleenp@2497 2181 Symbol* name = k->name();
duke@435 2182
duke@435 2183 {
duke@435 2184 MutexLocker mu1(SystemDictionary_lock, THREAD);
duke@435 2185
duke@435 2186 // See whether biased locking is enabled and if so set it for this
duke@435 2187 // klass.
duke@435 2188 // Note that this must be done past the last potential blocking
duke@435 2189 // point / safepoint. We enable biased locking lazily using a
duke@435 2190 // VM_Operation to iterate the SystemDictionary and installing the
duke@435 2191 // biasable mark word into each instanceKlass's prototype header.
duke@435 2192 // To avoid race conditions where we accidentally miss enabling the
duke@435 2193 // optimization for one class in the process of being added to the
duke@435 2194 // dictionary, we must not safepoint after the test of
duke@435 2195 // BiasedLocking::enabled().
duke@435 2196 if (UseBiasedLocking && BiasedLocking::enabled()) {
duke@435 2197 // Set biased locking bit for all loaded classes; it will be
duke@435 2198 // cleared if revocation occurs too often for this type
duke@435 2199 // NOTE that we must only do this when the class is initally
duke@435 2200 // defined, not each time it is referenced from a new class loader
duke@435 2201 if (k->class_loader() == class_loader()) {
duke@435 2202 k->set_prototype_header(markOopDesc::biased_locking_prototype());
duke@435 2203 }
duke@435 2204 }
duke@435 2205
duke@435 2206 // Check for a placeholder. If there, remove it and make a
duke@435 2207 // new system dictionary entry.
duke@435 2208 placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
duke@435 2209 klassOop sd_check = find_class(d_index, d_hash, name, class_loader);
duke@435 2210 if (sd_check == NULL) {
duke@435 2211 dictionary()->add_klass(name, class_loader, k);
duke@435 2212 notice_modification();
duke@435 2213 }
duke@435 2214 #ifdef ASSERT
duke@435 2215 sd_check = find_class(d_index, d_hash, name, class_loader);
duke@435 2216 assert (sd_check != NULL, "should have entry in system dictionary");
duke@435 2217 // Changed to allow PH to remain to complete class circularity checking
duke@435 2218 // while only one thread can define a class at one time, multiple
duke@435 2219 // classes can resolve the superclass for a class at one time,
duke@435 2220 // and the placeholder is used to track that
coleenp@2497 2221 // Symbol* ph_check = find_placeholder(name, class_loader);
duke@435 2222 // assert (ph_check == NULL, "should not have a placeholder entry");
duke@435 2223 #endif
duke@435 2224 SystemDictionary_lock->notify_all();
duke@435 2225 }
duke@435 2226 }
duke@435 2227
duke@435 2228
never@2551 2229 // Try to find a class name using the loader constraints. The
never@2551 2230 // loader constraints might know about a class that isn't fully loaded
never@2551 2231 // yet and these will be ignored.
duke@435 2232 klassOop SystemDictionary::find_constrained_instance_or_array_klass(
coleenp@2497 2233 Symbol* class_name, Handle class_loader, TRAPS) {
duke@435 2234
duke@435 2235 // First see if it has been loaded directly.
duke@435 2236 // Force the protection domain to be null. (This removes protection checks.)
duke@435 2237 Handle no_protection_domain;
duke@435 2238 klassOop klass = find_instance_or_array_klass(class_name, class_loader,
duke@435 2239 no_protection_domain, CHECK_NULL);
duke@435 2240 if (klass != NULL)
duke@435 2241 return klass;
duke@435 2242
duke@435 2243 // Now look to see if it has been loaded elsewhere, and is subject to
duke@435 2244 // a loader constraint that would require this loader to return the
duke@435 2245 // klass that is already loaded.
coleenp@2497 2246 if (FieldType::is_array(class_name)) {
acorn@1771 2247 // For array classes, their klassOops are not kept in the
acorn@1771 2248 // constraint table. The element klassOops are.
coleenp@2497 2249 FieldArrayInfo fd;
coleenp@2497 2250 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
duke@435 2251 if (t != T_OBJECT) {
duke@435 2252 klass = Universe::typeArrayKlassObj(t);
duke@435 2253 } else {
duke@435 2254 MutexLocker mu(SystemDictionary_lock, THREAD);
coleenp@2497 2255 klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
duke@435 2256 }
acorn@1771 2257 // If element class already loaded, allocate array klass
duke@435 2258 if (klass != NULL) {
coleenp@2497 2259 klass = Klass::cast(klass)->array_klass_or_null(fd.dimension());
duke@435 2260 }
duke@435 2261 } else {
duke@435 2262 MutexLocker mu(SystemDictionary_lock, THREAD);
duke@435 2263 // Non-array classes are easy: simply check the constraint table.
duke@435 2264 klass = constraints()->find_constrained_klass(class_name, class_loader);
duke@435 2265 }
duke@435 2266
duke@435 2267 return klass;
duke@435 2268 }
duke@435 2269
duke@435 2270
coleenp@2497 2271 bool SystemDictionary::add_loader_constraint(Symbol* class_name,
duke@435 2272 Handle class_loader1,
duke@435 2273 Handle class_loader2,
duke@435 2274 Thread* THREAD) {
coleenp@2497 2275 Symbol* constraint_name = NULL;
coleenp@2497 2276 if (!FieldType::is_array(class_name)) {
acorn@1771 2277 constraint_name = class_name;
acorn@1771 2278 } else {
acorn@1771 2279 // For array classes, their klassOops are not kept in the
acorn@1771 2280 // constraint table. The element classes are.
coleenp@2497 2281 FieldArrayInfo fd;
coleenp@2497 2282 BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
acorn@1771 2283 // primitive types always pass
acorn@1771 2284 if (t != T_OBJECT) {
acorn@1771 2285 return true;
acorn@1771 2286 } else {
coleenp@2497 2287 constraint_name = fd.object_key();
acorn@1771 2288 }
acorn@1771 2289 }
acorn@1771 2290 unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1);
duke@435 2291 int d_index1 = dictionary()->hash_to_index(d_hash1);
duke@435 2292
acorn@1771 2293 unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, class_loader2);
duke@435 2294 int d_index2 = dictionary()->hash_to_index(d_hash2);
acorn@1771 2295 {
acorn@1771 2296 MutexLocker mu_s(SystemDictionary_lock, THREAD);
duke@435 2297
acorn@1771 2298 // Better never do a GC while we're holding these oops
acorn@1771 2299 No_Safepoint_Verifier nosafepoint;
duke@435 2300
acorn@1771 2301 klassOop klass1 = find_class(d_index1, d_hash1, constraint_name, class_loader1);
acorn@1771 2302 klassOop klass2 = find_class(d_index2, d_hash2, constraint_name, class_loader2);
acorn@1771 2303 return constraints()->add_entry(constraint_name, klass1, class_loader1,
acorn@1771 2304 klass2, class_loader2);
duke@435 2305 }
duke@435 2306 }
duke@435 2307
duke@435 2308 // Add entry to resolution error table to record the error when the first
duke@435 2309 // attempt to resolve a reference to a class has failed.
coleenp@2497 2310 void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, Symbol* error) {
duke@435 2311 unsigned int hash = resolution_errors()->compute_hash(pool, which);
duke@435 2312 int index = resolution_errors()->hash_to_index(hash);
duke@435 2313 {
duke@435 2314 MutexLocker ml(SystemDictionary_lock, Thread::current());
duke@435 2315 resolution_errors()->add_entry(index, hash, pool, which, error);
duke@435 2316 }
duke@435 2317 }
duke@435 2318
duke@435 2319 // Lookup resolution error table. Returns error if found, otherwise NULL.
coleenp@2497 2320 Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) {
duke@435 2321 unsigned int hash = resolution_errors()->compute_hash(pool, which);
duke@435 2322 int index = resolution_errors()->hash_to_index(hash);
duke@435 2323 {
duke@435 2324 MutexLocker ml(SystemDictionary_lock, Thread::current());
duke@435 2325 ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
coleenp@2497 2326 return (entry != NULL) ? entry->error() : (Symbol*)NULL;
duke@435 2327 }
duke@435 2328 }
duke@435 2329
duke@435 2330
jrose@1100 2331 // Signature constraints ensure that callers and callees agree about
jrose@1100 2332 // the meaning of type names in their signatures. This routine is the
jrose@1100 2333 // intake for constraints. It collects them from several places:
jrose@1100 2334 //
jrose@1100 2335 // * LinkResolver::resolve_method (if check_access is true) requires
jrose@1100 2336 // that the resolving class (the caller) and the defining class of
jrose@1100 2337 // the resolved method (the callee) agree on each type in the
jrose@1100 2338 // method's signature.
jrose@1100 2339 //
jrose@1100 2340 // * LinkResolver::resolve_interface_method performs exactly the same
jrose@1100 2341 // checks.
jrose@1100 2342 //
jrose@1100 2343 // * LinkResolver::resolve_field requires that the constant pool
jrose@1100 2344 // attempting to link to a field agree with the field's defining
jrose@1100 2345 // class about the type of the field signature.
jrose@1100 2346 //
jrose@1100 2347 // * klassVtable::initialize_vtable requires that, when a class
jrose@1100 2348 // overrides a vtable entry allocated by a superclass, that the
jrose@1100 2349 // overriding method (i.e., the callee) agree with the superclass
jrose@1100 2350 // on each type in the method's signature.
jrose@1100 2351 //
jrose@1100 2352 // * klassItable::initialize_itable requires that, when a class fills
jrose@1100 2353 // in its itables, for each non-abstract method installed in an
jrose@1100 2354 // itable, the method (i.e., the callee) agree with the interface
jrose@1100 2355 // on each type in the method's signature.
jrose@1100 2356 //
jrose@1100 2357 // All those methods have a boolean (check_access, checkconstraints)
jrose@1100 2358 // which turns off the checks. This is used from specialized contexts
jrose@1100 2359 // such as bootstrapping, dumping, and debugging.
jrose@1100 2360 //
jrose@1100 2361 // No direct constraint is placed between the class and its
jrose@1100 2362 // supertypes. Constraints are only placed along linked relations
jrose@1100 2363 // between callers and callees. When a method overrides or implements
jrose@1100 2364 // an abstract method in a supertype (superclass or interface), the
jrose@1100 2365 // constraints are placed as if the supertype were the caller to the
jrose@1100 2366 // overriding method. (This works well, since callers to the
jrose@1100 2367 // supertype have already established agreement between themselves and
jrose@1100 2368 // the supertype.) As a result of all this, a class can disagree with
jrose@1100 2369 // its supertype about the meaning of a type name, as long as that
jrose@1100 2370 // class neither calls a relevant method of the supertype, nor is
jrose@1100 2371 // called (perhaps via an override) from the supertype.
jrose@1100 2372 //
jrose@1100 2373 //
jrose@1100 2374 // SystemDictionary::check_signature_loaders(sig, l1, l2)
jrose@1100 2375 //
duke@435 2376 // Make sure all class components (including arrays) in the given
duke@435 2377 // signature will be resolved to the same class in both loaders.
duke@435 2378 // Returns the name of the type that failed a loader constraint check, or
duke@435 2379 // NULL if no constraint failed. The returned C string needs cleaning up
jrose@1100 2380 // with a ResourceMark in the caller. No exception except OOME is thrown.
acorn@1771 2381 // Arrays are not added to the loader constraint table, their elements are.
coleenp@2497 2382 char* SystemDictionary::check_signature_loaders(Symbol* signature,
duke@435 2383 Handle loader1, Handle loader2,
duke@435 2384 bool is_method, TRAPS) {
duke@435 2385 // Nothing to do if loaders are the same.
duke@435 2386 if (loader1() == loader2()) {
duke@435 2387 return NULL;
duke@435 2388 }
duke@435 2389
coleenp@2497 2390 ResourceMark rm(THREAD);
duke@435 2391 SignatureStream sig_strm(signature, is_method);
duke@435 2392 while (!sig_strm.is_done()) {
duke@435 2393 if (sig_strm.is_object()) {
coleenp@2497 2394 Symbol* s = sig_strm.as_symbol(CHECK_NULL);
coleenp@2497 2395 Symbol* sig = s;
duke@435 2396 if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
coleenp@2497 2397 return sig->as_C_string();
duke@435 2398 }
duke@435 2399 }
duke@435 2400 sig_strm.next();
duke@435 2401 }
duke@435 2402 return NULL;
duke@435 2403 }
duke@435 2404
duke@435 2405
coleenp@2497 2406 methodOop SystemDictionary::find_method_handle_invoke(Symbol* name,
coleenp@2497 2407 Symbol* signature,
jrose@1863 2408 KlassHandle accessing_klass,
jrose@1145 2409 TRAPS) {
jrose@1145 2410 if (!EnableMethodHandles) return NULL;
coleenp@2497 2411 vmSymbols::SID name_id = vmSymbols::find_sid(name);
jrose@1862 2412 assert(name_id != vmSymbols::NO_SID, "must be a known name");
jrose@1862 2413 unsigned int hash = invoke_method_table()->compute_hash(signature, name_id);
jrose@1145 2414 int index = invoke_method_table()->hash_to_index(hash);
jrose@1862 2415 SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, name_id);
jrose@1863 2416 methodHandle non_cached_result;
jrose@1145 2417 if (spe == NULL || spe->property_oop() == NULL) {
jrose@1863 2418 spe = NULL;
jrose@1145 2419 // Must create lots of stuff here, but outside of the SystemDictionary lock.
twisti@1570 2420 if (THREAD->is_Compiler_thread())
twisti@1570 2421 return NULL; // do not attempt from within compiler
jrose@2148 2422 bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name));
jrose@2638 2423 if (AllowInvokeForInvokeGeneric && name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name))
jrose@2638 2424 for_invokeGeneric = true;
jrose@1863 2425 bool found_on_bcp = false;
coleenp@2497 2426 Handle mt = find_method_handle_type(signature, accessing_klass,
jrose@2148 2427 for_invokeGeneric,
jrose@2148 2428 found_on_bcp, CHECK_NULL);
jrose@1145 2429 KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass();
jrose@1862 2430 methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature,
jrose@1145 2431 mt, CHECK_NULL);
jrose@1145 2432 // Now grab the lock. We might have to throw away the new method,
jrose@1145 2433 // if a racing thread has managed to install one at the same time.
jrose@1863 2434 if (found_on_bcp) {
jrose@1145 2435 MutexLocker ml(SystemDictionary_lock, Thread::current());
jrose@1862 2436 spe = invoke_method_table()->find_entry(index, hash, signature, name_id);
jrose@1145 2437 if (spe == NULL)
jrose@1862 2438 spe = invoke_method_table()->add_entry(index, hash, signature, name_id);
jrose@1145 2439 if (spe->property_oop() == NULL)
jrose@1145 2440 spe->set_property_oop(m());
jrose@1863 2441 } else {
jrose@1863 2442 non_cached_result = m;
jrose@1145 2443 }
jrose@1145 2444 }
jrose@1863 2445 if (spe != NULL && spe->property_oop() != NULL) {
jrose@1863 2446 assert(spe->property_oop()->is_method(), "");
jrose@1863 2447 return (methodOop) spe->property_oop();
jrose@1863 2448 } else {
jrose@1863 2449 return non_cached_result();
jrose@1863 2450 }
jrose@1145 2451 }
jrose@1145 2452
jrose@2639 2453 // Ask Java code to find or construct a java.lang.invoke.MethodType for the given
jrose@1145 2454 // signature, as interpreted relative to the given class loader.
jrose@1145 2455 // Because of class loader constraints, all method handle usage must be
jrose@1145 2456 // consistent with this loader.
coleenp@2497 2457 Handle SystemDictionary::find_method_handle_type(Symbol* signature,
jrose@1863 2458 KlassHandle accessing_klass,
jrose@2148 2459 bool for_invokeGeneric,
jrose@1863 2460 bool& return_bcp_flag,
jrose@1862 2461 TRAPS) {
jrose@1863 2462 Handle class_loader, protection_domain;
jrose@1863 2463 bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader
jrose@1145 2464 Handle empty;
coleenp@2497 2465 int npts = ArgumentCount(signature).size();
never@1577 2466 objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
jrose@1145 2467 int arg = 0;
jrose@1145 2468 Handle rt; // the return type from the signature
coleenp@2497 2469 ResourceMark rm(THREAD);
coleenp@2497 2470 for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
jrose@1863 2471 oop mirror = NULL;
jrose@1863 2472 if (is_on_bcp) {
jrose@1863 2473 mirror = ss.as_java_mirror(class_loader, protection_domain,
jrose@1863 2474 SignatureStream::ReturnNull, CHECK_(empty));
jrose@1863 2475 if (mirror == NULL) {
jrose@1863 2476 // fall back from BCP to accessing_klass
jrose@1863 2477 if (accessing_klass.not_null()) {
jrose@1863 2478 class_loader = Handle(THREAD, instanceKlass::cast(accessing_klass())->class_loader());
jrose@1863 2479 protection_domain = Handle(THREAD, instanceKlass::cast(accessing_klass())->protection_domain());
jrose@1863 2480 }
jrose@1863 2481 is_on_bcp = false;
jrose@1863 2482 }
jrose@1863 2483 }
jrose@1863 2484 if (!is_on_bcp) {
jrose@1863 2485 // Resolve, throwing a real error if it doesn't work.
jrose@1863 2486 mirror = ss.as_java_mirror(class_loader, protection_domain,
jrose@1863 2487 SignatureStream::NCDFError, CHECK_(empty));
jrose@1145 2488 }
jrose@1145 2489 if (ss.at_return_type())
jrose@1145 2490 rt = Handle(THREAD, mirror);
jrose@1145 2491 else
jrose@1145 2492 pts->obj_at_put(arg++, mirror);
jrose@1863 2493 // Check accessibility.
jrose@1863 2494 if (ss.is_object() && accessing_klass.not_null()) {
jrose@1863 2495 klassOop sel_klass = java_lang_Class::as_klassOop(mirror);
jrose@1863 2496 // Emulate constantPoolOopDesc::verify_constant_pool_resolve.
jrose@1863 2497 if (Klass::cast(sel_klass)->oop_is_objArray())
jrose@1863 2498 sel_klass = objArrayKlass::cast(sel_klass)->bottom_klass();
jrose@1863 2499 if (Klass::cast(sel_klass)->oop_is_instance()) {
jrose@1863 2500 KlassHandle sel_kh(THREAD, sel_klass);
jrose@1863 2501 LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
jrose@1863 2502 }
jrose@1863 2503 }
jrose@1145 2504 }
jrose@1145 2505 assert(arg == npts, "");
jrose@1145 2506
jrose@2639 2507 // call java.lang.invoke.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType
jrose@1145 2508 JavaCallArguments args(Handle(THREAD, rt()));
jrose@1145 2509 args.push_oop(pts());
jrose@1145 2510 JavaValue result(T_OBJECT);
jrose@2639 2511 Symbol* findMethodHandleType_signature = vmSymbols::findMethodHandleType_signature();
jrose@2639 2512 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) {
jrose@2639 2513 findMethodHandleType_signature = vmSymbols::findMethodHandleType_TRANS_signature();
jrose@2639 2514 }
jrose@1145 2515 JavaCalls::call_static(&result,
jrose@1862 2516 SystemDictionary::MethodHandleNatives_klass(),
jrose@1862 2517 vmSymbols::findMethodHandleType_name(),
jrose@2639 2518 findMethodHandleType_signature,
jrose@1145 2519 &args, CHECK_(empty));
jrose@2148 2520 Handle method_type(THREAD, (oop) result.get_jobject());
jrose@2148 2521
jrose@2148 2522 if (for_invokeGeneric) {
jrose@2639 2523 // call java.lang.invoke.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void
jrose@2148 2524 JavaCallArguments args(Handle(THREAD, method_type()));
jrose@2148 2525 JavaValue no_result(T_VOID);
jrose@2639 2526 Symbol* notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_signature();
jrose@2639 2527 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) {
jrose@2639 2528 notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_TRANS_signature();
jrose@2639 2529 }
jrose@2148 2530 JavaCalls::call_static(&no_result,
jrose@2148 2531 SystemDictionary::MethodHandleNatives_klass(),
jrose@2148 2532 vmSymbols::notifyGenericMethodType_name(),
jrose@2639 2533 notifyGenericMethodType_signature,
jrose@2148 2534 &args, THREAD);
jrose@2148 2535 if (HAS_PENDING_EXCEPTION) {
jrose@2148 2536 // If the notification fails, just kill it.
jrose@2148 2537 CLEAR_PENDING_EXCEPTION;
jrose@2148 2538 }
jrose@2148 2539 }
jrose@1863 2540
jrose@1863 2541 // report back to the caller with the MethodType and the "on_bcp" flag
jrose@1863 2542 return_bcp_flag = is_on_bcp;
jrose@2148 2543 return method_type;
jrose@1145 2544 }
jrose@1145 2545
jrose@1957 2546 // Ask Java code to find or construct a method handle constant.
jrose@1957 2547 Handle SystemDictionary::link_method_handle_constant(KlassHandle caller,
jrose@1957 2548 int ref_kind, //e.g., JVM_REF_invokeVirtual
jrose@1957 2549 KlassHandle callee,
coleenp@2497 2550 Symbol* name_sym,
coleenp@2497 2551 Symbol* signature,
jrose@1957 2552 TRAPS) {
jrose@1957 2553 Handle empty;
coleenp@2497 2554 Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty));
jrose@1957 2555 Handle type;
jrose@1957 2556 if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
jrose@1957 2557 bool ignore_is_on_bcp = false;
jrose@2148 2558 type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty));
jrose@1957 2559 } else {
coleenp@2497 2560 ResourceMark rm(THREAD);
coleenp@2497 2561 SignatureStream ss(signature, false);
jrose@1957 2562 if (!ss.is_done()) {
jrose@1957 2563 oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
jrose@1957 2564 SignatureStream::NCDFError, CHECK_(empty));
jrose@1957 2565 type = Handle(THREAD, mirror);
jrose@1957 2566 ss.next();
jrose@1957 2567 if (!ss.is_done()) type = Handle(); // error!
jrose@1957 2568 }
jrose@1957 2569 }
jrose@1957 2570 if (type.is_null()) {
jrose@1957 2571 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad signature", empty);
jrose@1957 2572 }
jrose@1957 2573
jrose@2639 2574 // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
jrose@1957 2575 JavaCallArguments args;
jrose@1957 2576 args.push_oop(caller->java_mirror()); // the referring class
jrose@1957 2577 args.push_int(ref_kind);
jrose@1957 2578 args.push_oop(callee->java_mirror()); // the target class
jrose@1957 2579 args.push_oop(name());
jrose@1957 2580 args.push_oop(type());
jrose@1957 2581 JavaValue result(T_OBJECT);
jrose@2639 2582 Symbol* linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_signature();
jrose@2639 2583 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandle_klass()->name() == vmSymbols::java_dyn_MethodHandle()) {
jrose@2639 2584 linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_TRANS_signature();
jrose@2639 2585 }
jrose@1957 2586 JavaCalls::call_static(&result,
jrose@1957 2587 SystemDictionary::MethodHandleNatives_klass(),
jrose@1957 2588 vmSymbols::linkMethodHandleConstant_name(),
jrose@2639 2589 linkMethodHandleConstant_signature,
jrose@1957 2590 &args, CHECK_(empty));
jrose@1957 2591 return Handle(THREAD, (oop) result.get_jobject());
jrose@1957 2592 }
jrose@1145 2593
jrose@2639 2594 // Ask Java code to find or construct a java.lang.invoke.CallSite for the given
jrose@1161 2595 // name and signature, as interpreted relative to the given class loader.
jrose@1862 2596 Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method,
coleenp@2497 2597 Symbol* name,
jrose@1862 2598 methodHandle signature_invoker,
jrose@1862 2599 Handle info,
jrose@1862 2600 methodHandle caller_method,
jrose@1161 2601 int caller_bci,
jrose@1161 2602 TRAPS) {
jrose@1161 2603 Handle empty;
jrose@2015 2604 guarantee(bootstrap_method.not_null() &&
jrose@2639 2605 java_lang_invoke_MethodHandle::is_instance(bootstrap_method()),
jrose@2015 2606 "caller must supply a valid BSM");
jrose@2015 2607
jrose@1862 2608 Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty));
jrose@1862 2609 MethodHandles::init_MemberName(caller_mname(), caller_method());
jrose@1862 2610
jrose@2639 2611 // call java.lang.invoke.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos)
coleenp@2497 2612 oop name_str_oop = StringTable::intern(name, CHECK_(empty)); // not a handle!
jrose@1862 2613 JavaCallArguments args(Handle(THREAD, bootstrap_method()));
jrose@1161 2614 args.push_oop(name_str_oop);
jrose@1862 2615 args.push_oop(signature_invoker->method_handle_type());
jrose@1862 2616 args.push_oop(info());
jrose@1862 2617 args.push_oop(caller_mname());
jrose@1161 2618 args.push_int(caller_bci);
jrose@1161 2619 JavaValue result(T_OBJECT);
jrose@2638 2620 Symbol* makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_signature();
jrose@2638 2621 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::sun_dyn_MethodHandleNatives()) {
jrose@2638 2622 makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS_signature();
jrose@2638 2623 }
jrose@2639 2624 if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::java_dyn_MethodHandleNatives()) {
jrose@2639 2625 makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS2_signature();
jrose@2639 2626 }
jrose@1161 2627 JavaCalls::call_static(&result,
jrose@1862 2628 SystemDictionary::MethodHandleNatives_klass(),
jrose@1862 2629 vmSymbols::makeDynamicCallSite_name(),
jrose@2638 2630 makeDynamicCallSite_signature,
jrose@1161 2631 &args, CHECK_(empty));
jrose@1161 2632 oop call_site_oop = (oop) result.get_jobject();
jrose@1424 2633 assert(call_site_oop->is_oop()
jrose@2639 2634 /*&& java_lang_invoke_CallSite::is_instance(call_site_oop)*/, "must be sane");
jrose@1161 2635 if (TraceMethodHandles) {
jrose@1494 2636 #ifndef PRODUCT
jrose@1161 2637 tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop);
jrose@1161 2638 call_site_oop->print();
jrose@1161 2639 tty->cr();
jrose@1494 2640 #endif //PRODUCT
jrose@1161 2641 }
jrose@1161 2642 return call_site_oop;
jrose@1161 2643 }
jrose@1161 2644
jrose@2015 2645 Handle SystemDictionary::find_bootstrap_method(methodHandle caller_method, int caller_bci,
jrose@2268 2646 int cache_index,
jrose@2268 2647 Handle& argument_info_result,
jrose@2268 2648 TRAPS) {
jrose@1161 2649 Handle empty;
jrose@2015 2650
jrose@2015 2651 constantPoolHandle pool;
jrose@2015 2652 {
jrose@2015 2653 klassOop caller = caller_method->method_holder();
jrose@2015 2654 if (!Klass::cast(caller)->oop_is_instance()) return empty;
jrose@2015 2655 pool = constantPoolHandle(THREAD, instanceKlass::cast(caller)->constants());
jrose@2015 2656 }
jrose@2015 2657
jrose@2015 2658 int constant_pool_index = pool->cache()->entry_at(cache_index)->constant_pool_index();
jrose@2015 2659 constantTag tag = pool->tag_at(constant_pool_index);
jrose@2015 2660
jrose@2015 2661 if (tag.is_invoke_dynamic()) {
jrose@2268 2662 // JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments
jrose@2015 2663 // The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
jrose@2015 2664 int bsm_index = pool->invoke_dynamic_bootstrap_method_ref_index_at(constant_pool_index);
jrose@2015 2665 if (bsm_index != 0) {
jrose@2015 2666 int bsm_index_in_cache = pool->cache()->entry_at(cache_index)->bootstrap_method_index_in_cache();
jrose@2015 2667 DEBUG_ONLY(int bsm_index_2 = pool->cache()->entry_at(bsm_index_in_cache)->constant_pool_index());
jrose@2015 2668 assert(bsm_index == bsm_index_2, "BSM constant lifted to cache");
jrose@2015 2669 if (TraceMethodHandles) {
jrose@2015 2670 tty->print_cr("resolving bootstrap method for "PTR_FORMAT" at %d at cache[%d]CP[%d]...",
jrose@2015 2671 (intptr_t) caller_method(), caller_bci, cache_index, constant_pool_index);
jrose@2015 2672 }
jrose@2015 2673 oop bsm_oop = pool->resolve_cached_constant_at(bsm_index_in_cache, CHECK_(empty));
jrose@2015 2674 if (TraceMethodHandles) {
jrose@2015 2675 tty->print_cr("bootstrap method for "PTR_FORMAT" at %d retrieved as "PTR_FORMAT":",
jrose@2015 2676 (intptr_t) caller_method(), caller_bci, (intptr_t) bsm_oop);
jrose@2015 2677 }
jrose@2268 2678 assert(bsm_oop->is_oop(), "must be sane");
jrose@2268 2679 // caller must verify that it is of type MethodHandle
jrose@2268 2680 Handle bsm(THREAD, bsm_oop);
jrose@2268 2681 bsm_oop = NULL; // safety
jrose@2268 2682
jrose@2268 2683 // Extract the optional static arguments.
jrose@2268 2684 Handle argument_info; // either null, or one arg, or Object[]{arg...}
jrose@2268 2685 int argc = pool->invoke_dynamic_argument_count_at(constant_pool_index);
jrose@2268 2686 if (TraceInvokeDynamic) {
jrose@2268 2687 tty->print_cr("find_bootstrap_method: [%d/%d] CONSTANT_InvokeDynamic: %d[%d]",
jrose@2268 2688 constant_pool_index, cache_index, bsm_index, argc);
jrose@2268 2689 }
jrose@2268 2690 if (argc > 0) {
jrose@2268 2691 objArrayHandle arg_array;
jrose@2268 2692 if (argc > 1) {
jrose@2268 2693 objArrayOop arg_array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), argc, CHECK_(empty));
jrose@2268 2694 arg_array = objArrayHandle(THREAD, arg_array_oop);
jrose@2268 2695 argument_info = arg_array;
jrose@2268 2696 }
jrose@2268 2697 for (int arg_i = 0; arg_i < argc; arg_i++) {
jrose@2268 2698 int arg_index = pool->invoke_dynamic_argument_index_at(constant_pool_index, arg_i);
jrose@2268 2699 oop arg_oop = pool->resolve_possibly_cached_constant_at(arg_index, CHECK_(empty));
jrose@2268 2700 if (arg_array.is_null()) {
jrose@2268 2701 argument_info = Handle(THREAD, arg_oop);
jrose@2268 2702 } else {
jrose@2268 2703 arg_array->obj_at_put(arg_i, arg_oop);
jrose@2268 2704 }
jrose@2268 2705 }
jrose@2268 2706 }
jrose@2268 2707
jrose@2268 2708 argument_info_result = argument_info; // return argument_info to caller
jrose@2268 2709 return bsm;
jrose@2015 2710 }
jrose@2015 2711 // else null BSM; fall through
jrose@2015 2712 } else if (tag.is_name_and_type()) {
jrose@2015 2713 // JSR 292 EDR does not have JVM_CONSTANT_InvokeDynamic
jrose@2015 2714 // a bare name&type defaults its BSM to null, so fall through...
jrose@2015 2715 } else {
jrose@2015 2716 ShouldNotReachHere(); // verifier does not allow this
jrose@2015 2717 }
jrose@2015 2718
jrose@2015 2719 // Fall through to pick up the per-class bootstrap method.
jrose@2015 2720 // This mechanism may go away in the PFD.
jrose@2015 2721 assert(AllowTransitionalJSR292, "else the verifier should have stopped us already");
jrose@2268 2722 argument_info_result = empty; // return no argument_info to caller
jrose@2015 2723 oop bsm_oop = instanceKlass::cast(caller_method->method_holder())->bootstrap_method();
jrose@2015 2724 if (bsm_oop != NULL) {
jrose@1494 2725 if (TraceMethodHandles) {
jrose@2015 2726 tty->print_cr("bootstrap method for "PTR_FORMAT" registered as "PTR_FORMAT":",
jrose@2015 2727 (intptr_t) caller_method(), (intptr_t) bsm_oop);
jrose@1494 2728 }
jrose@2268 2729 assert(bsm_oop->is_oop(), "must be sane");
jrose@2015 2730 return Handle(THREAD, bsm_oop);
jrose@1161 2731 }
jrose@1161 2732
jrose@1862 2733 return empty;
jrose@1161 2734 }
jrose@1161 2735
duke@435 2736 // Since the identity hash code for symbols changes when the symbols are
duke@435 2737 // moved from the regular perm gen (hash in the mark word) to the shared
duke@435 2738 // spaces (hash is the address), the classes loaded into the dictionary
duke@435 2739 // may be in the wrong buckets.
duke@435 2740
duke@435 2741 void SystemDictionary::reorder_dictionary() {
duke@435 2742 dictionary()->reorder_dictionary();
duke@435 2743 }
duke@435 2744
duke@435 2745
duke@435 2746 void SystemDictionary::copy_buckets(char** top, char* end) {
duke@435 2747 dictionary()->copy_buckets(top, end);
duke@435 2748 }
duke@435 2749
duke@435 2750
duke@435 2751 void SystemDictionary::copy_table(char** top, char* end) {
duke@435 2752 dictionary()->copy_table(top, end);
duke@435 2753 }
duke@435 2754
duke@435 2755
duke@435 2756 void SystemDictionary::reverse() {
duke@435 2757 dictionary()->reverse();
duke@435 2758 }
duke@435 2759
duke@435 2760 int SystemDictionary::number_of_classes() {
duke@435 2761 return dictionary()->number_of_entries();
duke@435 2762 }
duke@435 2763
duke@435 2764
duke@435 2765 // ----------------------------------------------------------------------------
duke@435 2766 #ifndef PRODUCT
duke@435 2767
duke@435 2768 void SystemDictionary::print() {
duke@435 2769 dictionary()->print();
duke@435 2770
duke@435 2771 // Placeholders
duke@435 2772 GCMutexLocker mu(SystemDictionary_lock);
duke@435 2773 placeholders()->print();
duke@435 2774
duke@435 2775 // loader constraints - print under SD_lock
duke@435 2776 constraints()->print();
duke@435 2777 }
duke@435 2778
duke@435 2779 #endif
duke@435 2780
duke@435 2781 void SystemDictionary::verify() {
duke@435 2782 guarantee(dictionary() != NULL, "Verify of system dictionary failed");
duke@435 2783 guarantee(constraints() != NULL,
duke@435 2784 "Verify of loader constraints failed");
duke@435 2785 guarantee(dictionary()->number_of_entries() >= 0 &&
duke@435 2786 placeholders()->number_of_entries() >= 0,
duke@435 2787 "Verify of system dictionary failed");
duke@435 2788
duke@435 2789 // Verify dictionary
duke@435 2790 dictionary()->verify();
duke@435 2791
duke@435 2792 GCMutexLocker mu(SystemDictionary_lock);
duke@435 2793 placeholders()->verify();
duke@435 2794
duke@435 2795 // Verify constraint table
duke@435 2796 guarantee(constraints() != NULL, "Verify of loader constraints failed");
tonyp@1693 2797 constraints()->verify(dictionary(), placeholders());
duke@435 2798 }
duke@435 2799
duke@435 2800
duke@435 2801 void SystemDictionary::verify_obj_klass_present(Handle obj,
coleenp@2497 2802 Symbol* class_name,
duke@435 2803 Handle class_loader) {
duke@435 2804 GCMutexLocker mu(SystemDictionary_lock);
coleenp@2497 2805 Symbol* name;
coleenp@2497 2806
coleenp@2497 2807 klassOop probe = find_class(class_name, class_loader);
duke@435 2808 if (probe == NULL) {
duke@435 2809 probe = SystemDictionary::find_shared_class(class_name);
coleenp@2497 2810 if (probe == NULL) {
coleenp@2497 2811 name = find_placeholder(class_name, class_loader);
coleenp@2497 2812 }
duke@435 2813 }
coleenp@2497 2814 guarantee(probe != NULL || name != NULL,
coleenp@2497 2815 "Loaded klasses should be in SystemDictionary");
duke@435 2816 }
duke@435 2817
duke@435 2818 #ifndef PRODUCT
duke@435 2819
duke@435 2820 // statistics code
duke@435 2821 class ClassStatistics: AllStatic {
duke@435 2822 private:
duke@435 2823 static int nclasses; // number of classes
duke@435 2824 static int nmethods; // number of methods
duke@435 2825 static int nmethoddata; // number of methodData
duke@435 2826 static int class_size; // size of class objects in words
duke@435 2827 static int method_size; // size of method objects in words
duke@435 2828 static int debug_size; // size of debug info in methods
duke@435 2829 static int methoddata_size; // size of methodData objects in words
duke@435 2830
duke@435 2831 static void do_class(klassOop k) {
duke@435 2832 nclasses++;
duke@435 2833 class_size += k->size();
duke@435 2834 if (k->klass_part()->oop_is_instance()) {
duke@435 2835 instanceKlass* ik = (instanceKlass*)k->klass_part();
duke@435 2836 class_size += ik->methods()->size();
duke@435 2837 class_size += ik->constants()->size();
duke@435 2838 class_size += ik->local_interfaces()->size();
duke@435 2839 class_size += ik->transitive_interfaces()->size();
duke@435 2840 // We do not have to count implementors, since we only store one!
duke@435 2841 class_size += ik->fields()->size();
duke@435 2842 }
duke@435 2843 }
duke@435 2844
duke@435 2845 static void do_method(methodOop m) {
duke@435 2846 nmethods++;
duke@435 2847 method_size += m->size();
duke@435 2848 // class loader uses same objArray for empty vectors, so don't count these
duke@435 2849 if (m->exception_table()->length() != 0) method_size += m->exception_table()->size();
duke@435 2850 if (m->has_stackmap_table()) {
duke@435 2851 method_size += m->stackmap_data()->size();
duke@435 2852 }
duke@435 2853
duke@435 2854 methodDataOop mdo = m->method_data();
duke@435 2855 if (mdo != NULL) {
duke@435 2856 nmethoddata++;
duke@435 2857 methoddata_size += mdo->size();
duke@435 2858 }
duke@435 2859 }
duke@435 2860
duke@435 2861 public:
duke@435 2862 static void print() {
duke@435 2863 SystemDictionary::classes_do(do_class);
duke@435 2864 SystemDictionary::methods_do(do_method);
duke@435 2865 tty->print_cr("Class statistics:");
duke@435 2866 tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize);
duke@435 2867 tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods,
duke@435 2868 (method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize);
duke@435 2869 tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize);
duke@435 2870 }
duke@435 2871 };
duke@435 2872
duke@435 2873
duke@435 2874 int ClassStatistics::nclasses = 0;
duke@435 2875 int ClassStatistics::nmethods = 0;
duke@435 2876 int ClassStatistics::nmethoddata = 0;
duke@435 2877 int ClassStatistics::class_size = 0;
duke@435 2878 int ClassStatistics::method_size = 0;
duke@435 2879 int ClassStatistics::debug_size = 0;
duke@435 2880 int ClassStatistics::methoddata_size = 0;
duke@435 2881
duke@435 2882 void SystemDictionary::print_class_statistics() {
duke@435 2883 ResourceMark rm;
duke@435 2884 ClassStatistics::print();
duke@435 2885 }
duke@435 2886
duke@435 2887
duke@435 2888 class MethodStatistics: AllStatic {
duke@435 2889 public:
duke@435 2890 enum {
duke@435 2891 max_parameter_size = 10
duke@435 2892 };
duke@435 2893 private:
duke@435 2894
duke@435 2895 static int _number_of_methods;
duke@435 2896 static int _number_of_final_methods;
duke@435 2897 static int _number_of_static_methods;
duke@435 2898 static int _number_of_native_methods;
duke@435 2899 static int _number_of_synchronized_methods;
duke@435 2900 static int _number_of_profiled_methods;
duke@435 2901 static int _number_of_bytecodes;
duke@435 2902 static int _parameter_size_profile[max_parameter_size];
duke@435 2903 static int _bytecodes_profile[Bytecodes::number_of_java_codes];
duke@435 2904
duke@435 2905 static void initialize() {
duke@435 2906 _number_of_methods = 0;
duke@435 2907 _number_of_final_methods = 0;
duke@435 2908 _number_of_static_methods = 0;
duke@435 2909 _number_of_native_methods = 0;
duke@435 2910 _number_of_synchronized_methods = 0;
duke@435 2911 _number_of_profiled_methods = 0;
duke@435 2912 _number_of_bytecodes = 0;
duke@435 2913 for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0;
duke@435 2914 for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0;
duke@435 2915 };
duke@435 2916
duke@435 2917 static void do_method(methodOop m) {
duke@435 2918 _number_of_methods++;
duke@435 2919 // collect flag info
duke@435 2920 if (m->is_final() ) _number_of_final_methods++;
duke@435 2921 if (m->is_static() ) _number_of_static_methods++;
duke@435 2922 if (m->is_native() ) _number_of_native_methods++;
duke@435 2923 if (m->is_synchronized()) _number_of_synchronized_methods++;
duke@435 2924 if (m->method_data() != NULL) _number_of_profiled_methods++;
duke@435 2925 // collect parameter size info (add one for receiver, if any)
duke@435 2926 _parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++;
duke@435 2927 // collect bytecodes info
duke@435 2928 {
duke@435 2929 Thread *thread = Thread::current();
duke@435 2930 HandleMark hm(thread);
duke@435 2931 BytecodeStream s(methodHandle(thread, m));
duke@435 2932 Bytecodes::Code c;
duke@435 2933 while ((c = s.next()) >= 0) {
duke@435 2934 _number_of_bytecodes++;
duke@435 2935 _bytecodes_profile[c]++;
duke@435 2936 }
duke@435 2937 }
duke@435 2938 }
duke@435 2939
duke@435 2940 public:
duke@435 2941 static void print() {
duke@435 2942 initialize();
duke@435 2943 SystemDictionary::methods_do(do_method);
duke@435 2944 // generate output
duke@435 2945 tty->cr();
duke@435 2946 tty->print_cr("Method statistics (static):");
duke@435 2947 // flag distribution
duke@435 2948 tty->cr();
duke@435 2949 tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods);
duke@435 2950 tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods);
duke@435 2951 tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods);
duke@435 2952 tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods);
duke@435 2953 tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods);
duke@435 2954 // parameter size profile
duke@435 2955 tty->cr();
duke@435 2956 { int tot = 0;
duke@435 2957 int avg = 0;
duke@435 2958 for (int i = 0; i < max_parameter_size; i++) {
duke@435 2959 int n = _parameter_size_profile[i];
duke@435 2960 tot += n;
duke@435 2961 avg += n*i;
duke@435 2962 tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods);
duke@435 2963 }
duke@435 2964 assert(tot == _number_of_methods, "should be the same");
duke@435 2965 tty->print_cr(" %6d methods 100.0%%", _number_of_methods);
duke@435 2966 tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods);
duke@435 2967 }
duke@435 2968 // bytecodes profile
duke@435 2969 tty->cr();
duke@435 2970 { int tot = 0;
duke@435 2971 for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
duke@435 2972 if (Bytecodes::is_defined(i)) {
duke@435 2973 Bytecodes::Code c = Bytecodes::cast(i);
duke@435 2974 int n = _bytecodes_profile[c];
duke@435 2975 tot += n;
duke@435 2976 tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c));
duke@435 2977 }
duke@435 2978 }
duke@435 2979 assert(tot == _number_of_bytecodes, "should be the same");
duke@435 2980 tty->print_cr("%9d 100.000%%", _number_of_bytecodes);
duke@435 2981 }
duke@435 2982 tty->cr();
duke@435 2983 }
duke@435 2984 };
duke@435 2985
duke@435 2986 int MethodStatistics::_number_of_methods;
duke@435 2987 int MethodStatistics::_number_of_final_methods;
duke@435 2988 int MethodStatistics::_number_of_static_methods;
duke@435 2989 int MethodStatistics::_number_of_native_methods;
duke@435 2990 int MethodStatistics::_number_of_synchronized_methods;
duke@435 2991 int MethodStatistics::_number_of_profiled_methods;
duke@435 2992 int MethodStatistics::_number_of_bytecodes;
duke@435 2993 int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size];
duke@435 2994 int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes];
duke@435 2995
duke@435 2996
duke@435 2997 void SystemDictionary::print_method_statistics() {
duke@435 2998 MethodStatistics::print();
duke@435 2999 }
duke@435 3000
duke@435 3001 #endif // PRODUCT

mercurial