src/share/vm/classfile/systemDictionary.cpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7485
9fa3bf3043a2
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial