286N/A * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 286N/A * This code is free software; you can redistribute it and/or modify it 286N/A * under the terms of the GNU General Public License version 2 only, as 286N/A * published by the Free Software Foundation. 286N/A * This code is distributed in the hope that it will be useful, but WITHOUT 286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 286N/A * version 2 for more details (a copy is included in the LICENSE file that 286N/A * accompanied this code). 286N/A * You should have received a copy of the GNU General Public License version 286N/A * 2 along with this work; if not, write to the Free Software Foundation, 286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 286N/A// lazily initialized klass variables 286N/A// ---------------------------------------------------------------------------- 286N/A// Java-level SystemLoader 286N/A// ---------------------------------------------------------------------------- // return true if class_name contains no '.' (internal format is '/') // ---------------------------------------------------------------------------- // Parallel class loading check // ---------------------------------------------------------------------------- // ParallelDefineClass flag does not apply to bootclass loader // ---------------------------------------------------------------------------- // Forwards to resolve_or_null // can return a null klass // If we have a pending exception we forward it to the caller, unless throw_error is true, // in which case we have to check whether the pending exception is a ClassNotFoundException, // and if so convert it to a NoClassDefFoundError // And chain the original ClassNotFoundException // Class not found, throw appropriate error or exception depending on value of throw_error // Forwards to resolve_instance_class_or_null err_msg(
"can not load classes with compiler thread: class=%s, classloader=%s",
// Ignore wrapping L and ;. // Forwards to resolve_instance_class_or_null // dimension and object_key in FieldArrayInfo are assigned as a side-effect // naked oop "k" is OK here -- we assign back into it // Must be called for any super-class or super-interface resolution // during class definition to allow class circularity checking // super-interface callers: // parse_interfaces - for defineClass & jvmtiRedefineClasses // ClassFileParser - for defineClass & jvmtiRedefineClasses // load_shared_class - while loading a class from shared archive // resolve_instance_class_or_null: // via: handle_parallel_super_load // when resolving a class that has an existing placeholder with // a saved superclass [i.e. a defineClass is currently in progress] // if another thread is trying to resolve the class, it must do // super-class checks on its own thread to catch class circularity // This last call is critical in class circularity checking for cases // where classloading is delegated to different threads and the // classloader lock is released. // Take the case: Base->Super->Base // 1. If thread T1 tries to do a defineClass of class Base // resolve_super_or_fail creates placeholder: T1, Base (super Super) // 2. resolve_instance_class_or_null does not find SD or placeholder for Super // so it tries to load Super // 3. If we load the class internally, or user classloader uses same thread // loadClassFromxxx or defineClass via parseClassFile Super ... // 3.1 resolve_super_or_fail creates placeholder: T1, Super (super Base) // 3.3 resolve_instance_class_or_null Base, finds placeholder for Base // 3.4 calls resolve_super_or_fail Base // 3.5 finds T1,Base -> throws class circularity //OR 4. If T2 tries to resolve Super via defineClass Super ... // 4.1 resolve_super_or_fail creates placeholder: T2, Super (super Base) // 4.2 resolve_instance_class_or_null Base, finds placeholder for Base (super Super) // 4.3 calls resolve_super_or_fail Super in parallel on own thread T2 // 4.4 finds T2, Super -> throws class circularity // Must be called, even if superclass is null, since this is // where the placeholder entry is created which claims this // Double-check, if child class is already loaded, just return super-class,interface // Don't add a placedholder if already loaded, i.e. already in system dictionary // Make sure there's a placeholder for the *child* before resolving. // Used here for ClassCircularity checks and also for heap verification // (every instanceKlass in the heap needs to be in the system dictionary // or have a placeholder). // Must check ClassCircularity before checking if super class is already loaded // We might not already have a placeholder if this child_name was // first seen via resolve_from_stream (jni_DefineClass or JVM_DefineClass); // the name of the class might not be known until the stream is actually // compute_hash can have a safepoint // can't throw error holding a lock // to support // loading: if child done loading, just return superclass // if class_name, & class_loader don't match: // if initial define, SD update will give LinkageError // if redefine: compare_class_versions will give HIERARCHY_CHANGED // so we don't throw an exception here. // see: nsk redefclass014 & java.lang.instrument Instrument032 // java.lang.Object should have been found above // Resolve the super class or interface, check results on return // Note: clean up of placeholders currently in callers of // resolve_super_or_fail - either at update_dictionary time // Now we have to call back to java to check if the initating class has access // Print out trace information // If no exception has been thrown, we have validated the protection domain // Insert the protection domain of the initiating class into the set. // We recalculate the entry here -- we've called out to java since // the last time it was calculated. // Note that we have an entry, and entries can be deleted only during GC, // so we cannot allow GC to occur while we're holding this entry. // We're using a No_Safepoint_Verifier to catch any place where we // might potentially do a GC at all. // SystemDictionary::do_unloading() asserts that classes are only // unloaded at a safepoint. // We only get here if this thread finds that another thread // has already claimed the placeholder token for the current operation, // but that other thread either never owned or gave up the // Waits on SystemDictionary_lock to indicate placeholder table updated // On return, caller must recheck placeholder table state // 1) custom classLoader, i.e. not bootstrap classloader // 2) UnsyncloadClass not set // 3) custom classLoader has broken the class loader objectLock // so another thread got here in parallel // lockObject must be held. // Complicated dance due to lock ordering: // Must first release the classloader object lock to // allow initial definer to complete the class definition // Reclaim classloader lock object with same original recursion count // Must release SystemDictionary_lock after notify, since // class loader lock must be claimed before SystemDictionary_lock // The notify allows applications that did an untimed wait() on // the classloader object lock to not hang. // If the class in is in the placeholder table, class loading is in progress // For cases where the application changes threads to load classes, it // is critical to ClassCircularity detection that we try loading // the superclass on the same thread internally, so we do parallel // super class loading here. // This also is critical in cases where the original thread gets stalled // even in non-circularity situations. // Note: only one thread can define the class, but multiple can resolve // Note: must call resolve_super_or_fail even if null super - // to force placeholder entry creation for this class for circularity detection // Caller must check for pending exception // Returns non-null klassOop if other thread has completed load // If return null klassOop and no pending exception, the caller must load the class // superk is not used, resolve_super called for circularity check only // This code is reached in two situations. One if this thread // is loading the same class twice (e.g. ClassCircularity, or // java.lang.instrument). // The second is if another thread started the resolve_super first // and has not yet finished. // In both cases the original caller will clean up the placeholder // We don't redefine the class, so we just need to clean up if there // was not an error (don't want to modify any system dictionary // parallelCapable class loaders do NOT wait for parallel superclass loads to complete // Serial class loaders and bootstrap classloader do wait for superclass loads // Check if classloading completed while we were loading superclass or waiting // Klass is already loaded, so just return it // must loop to both handle other placeholder updates // and spurious notifications // Check if classloading completed while we were loading superclass or waiting // Klass is already loaded, so just return it // Before UnsyncloadClass: // We only get here if the application has released the // classloader lock when another thread was in the middle of loading a // this thread is also trying to load this class. // To minimize surprises, the first thread that started to // load a class should be the one to complete the loading // with the classfile it initially expected. // This logic has the current thread wait once it has done // the original thread completes the class loading or fails // If it completes we will use the resulting instanceKlass // which we will find below in the systemDictionary. // We also get here for parallel bootstrap classloader // If not in SD and not in PH, other thread's load must have failed // Fix for 4474172; see evaluation for more details // Do lookup to see if class already exist and the protection domain // Non-bootstrap class loaders will call out to class loader and // class loader object lock to protect against multiple threads // defining the class in parallel by accident. // This lock must be acquired here so the waiter will find // any successful result in the SystemDictionary and not attempt // ParallelCapable Classloaders and the bootstrap classloader, // or all classloaders with UnsyncloadClass do not acquire lock here // Class is not in SystemDictionary so we have to do loading. // Make sure we are synchronized on the class loader before we proceed // Check again (after locking) if class already exist in SystemDictionary // Klass is already loaded, so just return it // If the class in is in the placeholder table, class loading is in progress // add placeholder entry to record loading instance class // All cases need to prevent modifying bootclasssearchpath // in parallel with a classload of same classname // Redefineclasses uses existence of the placeholder for the duration // of the class load to prevent concurrent redefinition of not completely // case 1. traditional classloaders that rely on the classloader object lock // - no other need for LOAD_INSTANCE // case 2. traditional classloaders that break the classloader object lock // as a deadlock workaround. Detection of this case requires that // this check is done while holding the classloader object lock, // and that lock is still held when calling classloader's loadClass. // For these classloaders, we ensure that the first requestor // completes the load and other requestors wait for completion. // case 3. UnsyncloadClass - don't use objectLocker // With this flag, we allow parallel classloading of a // case4. Bootstrap classloader - don't own objectLocker // This classloader supports parallelism at the classloader level, // No performance benefit and no deadlock issues. // case 5. parallelCapable user level classloaders - without objectLocker // only need check_seen_thread once, not on each loop // case 1: traditional: should never see load_in_progress. // case 4: bootstrap classloader: prevent futile classloading, // wait on first requestor // case 2: traditional with broken classloader lock. wait on first // Check if classloading completed while we were waiting // Klass is already loaded, so just return it // check if other thread failed to load and cleaned up // All cases: add LOAD_INSTANCE // case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try // LOAD_INSTANCE in parallel // add placeholder entry even if error - callers will remove on error // For class loaders that do not acquire the classloader object lock, // if they did not catch another thread holding LOAD_INSTANCE, // i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL // one final check if the load has already completed // class loaders holding the ObjectLock shouldn't find the class here // Klass is already loaded, so just return it // must throw error outside of owning lock // For UnsyncloadClass only // If they got a linkageError, check if a parallel class load succeeded. // If it did, then for bytecode resolution the specification requires // that we return the same result we did for the other thread, i.e. the // successfully loaded instanceKlass // Should not get here for classloaders that support parallelism // with the new cleaner mechanism, even with AllowParallelDefineClass // Bootstrap goes through here to allow for an extra guarantee check // Klass is already loaded, so just use it // clean up placeholder entries for success or error // This cleans up LOAD_INSTANCE entries // It also cleans up LOAD_SUPER entries on errors from // calling load_instance_class // If everything was OK (no exceptions, no null return value), and // class_loader is NOT the defining loader, do a little more bookkeeping. // Need to check for a PENDING_EXCEPTION again; check_constraints // can throw and doesn't use the CHECK macro. {
// Grabbing the Compile_lock prevents systemDictionary updates // On error, clean up placeholders assert(
kk == k(),
"should be present in dictionary");
// return if the protection domain in NULL // Check the protection domain has the right access // Note that we have an entry, and entries can be deleted only during GC, // so we cannot allow GC to occur while we're holding this entry. // We're using a No_Safepoint_Verifier to catch any place where we // might potentially do a GC at all. // SystemDictionary::do_unloading() asserts that classes are only // unloaded at a safepoint. // Verify protection domain. If it fails an exception is thrown // This routine does not lock the system dictionary. // Since readers don't hold a lock, we must make sure that system // dictionary entries are only removed at a safepoint (when only one // thread is running), and are added to in a safe way (all links must // be updated in an MT-safe manner). // Callers should be aware that an entry could be added just after // _dictionary->bucket(index) is read here, so the caller will not see // The result of this call should be consistent with the result // of the call to resolve_instance_class_or_null(). // See evaluation 6790209 and 4474172 for more details. // Note that we have an entry, and entries can be deleted only during GC, // so we cannot allow GC to occur while we're holding this entry. // We're using a No_Safepoint_Verifier to catch any place where we // might potentially do a GC at all. // SystemDictionary::do_unloading() asserts that classes are only // unloaded at a safepoint. // Look for a loaded instance or array klass by name. Do not do any loading. // return NULL in case of error. // The name refers to an array. Parse the name. // dimension and object_key in FieldArrayInfo are assigned as a // side-effect of this call // Note: this method is much like resolve_from_stream, but // updates no supplemental data structures. // TODO consolidate the two methods with a helper routine? // Parse the stream. Note that we do this even though this klass might // already be present in the SystemDictionary, otherwise we would not // throw potential ClassFormatErrors. // Note: "name" is updated. // Further note: a placeholder will be added for this class when // super classes are loaded (resolve_super_or_fail). We expect this // to be called for all classes but java.lang.Object; and we preload // java.lang.Object through resolve_or_fail, not this path. // We don't redefine the class, so we just need to clean up whether there // was an error or not (don't want to modify any system dictionary // Parsed name could be null if we threw an error before we got far // enough along to parse it -- in that case, there is nothing to clean up. // If it's anonymous, initialize it now, since nobody else will. // Add to class hierarchy, initialize vtables, and do possible // But, do not add to system dictionary. // Add a klass to the system from a stream (called by jni_DefineClass and // Note: class_name can be NULL. In that case we do not know the name of // the class until we have parsed the stream. // Classloaders that support parallelism, e.g. bootstrap classloader, // or all classloaders with UnsyncloadClass do not acquire lock here // Make sure we are synchronized on the class loader before we proceed // Parse the stream. Note that we do this even though this klass might // already be present in the SystemDictionary, otherwise we would not // throw potential ClassFormatErrors. // Note: "name" is updated. // Further note: a placeholder will be added for this class when // super classes are loaded (resolve_super_or_fail). We expect this // to be called for all classes but java.lang.Object; and we preload // java.lang.Object through resolve_or_fail, not this path. const char*
pkg =
"java/";
// It is illegal to define classes in the "java." package from // JVM_DefineClass or jni_DefineClass unless you're the bootclassloader *
index =
'\0';
// chop to just the package name *
index =
'.';
// replace '/' with '.' in package name const char*
fmt =
"Prohibited package name: %s";
// Verification prevents us from creating names with dots in them, this // asserts that that's the case. "external class name format used internally");
// If a class loader supports parallel classloading handle parallel define requests // find_or_define_instance_class may return a different instanceKlass // If parsing the class file or define_instance_class failed, we // need to remove the placeholder added on our behalf. But we // must make sure parsed_name is valid first (it won't be if we had // a format error before the class was parsed far enough to // Make sure that we didn't leave a place holder in the // SystemDictionary; this is only done on success assert(
check == k(),
"should be present in the dictionary");
"bad shared dictionary size.");
// If there is a shared dictionary, then find the entry for the // given shared system class, if any. // Load a class from the shared spaces (found through the shared system // dictionary). Force the superclass and all interfaces to be loaded. // Update the class definition to include sibling classes and no // subclasses (yet). [Classes in the shared space are not part of the // object hierarchy until loaded.] // Note well! Changes to this method may affect oop access order // in the shared archive. Please take care to not make changes that // adversely affect cold start time by changing the oop access order // that is specified in dump.cpp MarkAndMoveOrderedReadOnly and // MarkAndMoveOrderedReadWrite closures. // Found the class, now load the superclass and interfaces. If they // are shared, add them to the main system dictionary and reset // their hierarchy references (supers, subs, and interfaces). // Note: can not use instanceKlass::cast here because // interfaces' instanceKlass's C++ vtbls haven't been // reinitialized yet (they will be once the interface classes // Adjust methods to recover missing data. They need addresses for // interpreter entry points and their default native method address // Updating methods must be done under a lock so multiple // threads don't update these in parallel // Shared classes are all currently loaded by the bootstrap // classloader, so this will never cause a deadlock on // a custom class loader lock. // Reinitialize vtable because RedefineClasses may have changed some // entries in this vtable for super classes so the CDS vtable might // point to old or obsolete entries. RedefineClasses doesn't fix up // vtables in the shared system dictionary, only the main one. // It also redefines the itable too so fix that too. tty->
print(
" from shared objects file");
// notify a class loaded from shared object true /* shared class */);
// Search the shared system dictionary for classes preloaded into the // find_or_define_instance_class may return a different instanceKlass // Use user specified class loader to load class. Call loadClass operation on class_loader. // Translate to external class name format, i.e., convert '/' chars to '.' // Call public unsynchronized loadClass(String) directly for all class loaders // for parallelCapable class loaders. JDK >=7, loadClass(String, boolean) will // acquire a class-name based lock rather than the class loader object lock. // JDK < 7 already acquire the class loader lock in loadClass(String, boolean), // so the call to loadClassInternal() was not required. // UnsyncloadClass flag means both call loadClass(String) and do // not acquire the class loader lock even for class loaders that are // not parallelCapable. This was a risky transitional // flag for diagnostic purposes only. It is risky to call // custom class loaders without synchronization. // WARNING If a custom class loader does NOT synchronizer findClass, or callers of // findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field. // Do NOT assume this will be supported in future releases. // Added MustCallLoadClassInternal in case we discover in the field // a customer that counts on this call // Primitive classes return null since forName() can not be // used to obtain any of the Class objects representing primitives or void // For user defined Java class loaders, check that the name returned is // the same as that requested. This check is done for the bootstrap // loader when parsing the class file. // Class is not found or has the wrong name, return NULL // for bootstrap and other parallel classloaders don't acquire lock, // If a parallelCapable class loader calls define_instance_class instead of // find_or_define_instance_class to get here, we have a timing // hole with systemDictionary updates and check_constraints "define called without lock");
// Check class-loading constraints. Throw exception if violation is detected. // Grabs and releases SystemDictionary_lock // Existing classloaders will call define_instance_class with the // Parallel classloaders will call find_or_define_instance_class // which will require a token to perform the define class // Register class just loaded with class loader (placed in Vector) // Note we do this before updating the dictionary, as this can // fail with an OutOfMemoryError (if it does, we will *not* put this // class in the dictionary and will not update the class hierarchy). // Add the new class. We need recompile lock during update of CHA. // Add to class hierarchy, initialize vtables, and do possible // Add to systemDictionary - so other classes can see it. // Grabs and releases SystemDictionary_lock // Support parallel classloading // All parallel class loaders, including bootstrap classloader // to allow parallel defines of different classes for this class loader // With AllowParallelDefine flag==true, in case they do not synchronize around // loading for them, wait if a defineClass is in progress // and return the initial requestor's results // This flag does not apply to the bootstrap classloader. // With AllowParallelDefine flag==false, call through to define_instance_class // which will throw LinkageError: duplicate class definition. // False is the requested default. // For better performance, the class loaders should synchronize // potentially waste time reading and parsing the bytestream. // Note: VM callers should ensure consistency of k/class_name,class_loader // Hold SD lock around find_class and placeholder creation for DEFINE_CLASS // First check if class already defined // Wait if another thread defining in parallel // All threads wait - even those that will throw duplicate class: otherwise // caller is surprised by LinkageError: duplicate, but findLoadedClass fails // if other thread has not finished updating dictionary // Only special cases allow parallel defines and can use other thread's results // Other cases fall through, and may run into duplicate defines // caught by finding an entry in the SystemDictionary // This thread will define the class (even if earlier thread tried and had an error) // definer must notify any waiting threads // Can't throw exception while holding lock due to rank ordering // If class_loader is NULL we synchronize on _system_loader_lock_obj // This method is added to check how often we have to wait to grab loader // lock. The results are being recorded in the performance counters defined in // ClassLoader::_sync_systemLoaderLockContentionRate and // ClassLoader::_sync_nonSystemLoaderLockConteionRate. // contention will likely happen, so increment the corresponding // ---------------------------------------------------------------------------- // Basic find on classes in the midst of being loaded // Used for assertions and verification only // First look in the loaded class array // Get the next class in the diictionary. // ---------------------------------------------------------------------------- // Update hierachy. This is done before the new klass has been added to the SystemDictionary. The Recompile_lock // is held, to ensure that the compiler is not using the class hierachy, and that deoptimization will kick in // before a new class is used. // Link into hierachy. Make sure the vtables are initialized before linking into // Now flush all code that depended on old class hierarchy. // Note: must be done *after* linking k into the hierarchy (was bug 12/9/97) // Also, first reinitialize vtable because it may have gotten out of synch // while the new class wasn't connected to the class hierarchy. // ---------------------------------------------------------------------------- // Following roots during mark-sweep is separated in two phases. // The first phase follows preloaded classes and all other system // classes, since these will never get unloaded anyway. // The second phase removes (unloads) unreachable classes from the // system dictionary and follows the remaining classes' contents. // Follow all system classes and temporary placeholders in dictionary // Placeholders. These are *always* strong roots, as they // represent classes we're actively loading. // Calculate a "good" systemdictionary size based // on predicted or current loaded classes count // The mirrors are scanned by shared_oops_do() which is // not called by oops_do(). In order to process oops in // a necessary order, shared_oops_do() is call by // Adjust preloaded classes and system loader object // Partially loaded classes // Adjust constraint table // Adjust resolution error table for (
int i = 0; i <
T_VOID+
1; i++) {
// The basic type mirrors would have already been processed in // Universe::oops_do(), via a call to shared_oops_do(), so should // not be processed again. // Just the classes from defining class loaders // Don't iterate over placeholders // Added for initialize_itable_for_klass // Just the classes from defining class loaders // Don't iterate over placeholders // All classes, and their class loaders // Don't iterate over placeholders // All classes, and their class loaders // (added for helpers that use HandleMarks and ResourceMarks) // Don't iterate over placeholders // ---------------------------------------------------------------------------- // if multiple threads calling this function, only one thread will load // the class. The other threads will find the loaded version once the // Force a fence to prevent any read before the write completes // ---------------------------------------------------------------------------- "SystemDictionary should only be initialized once");
// Allocate private object used as system class loader lock // Initialize basic classes // Compact table of directions on the initialization of klasses: // move the starting value forward to the limit: // Preload commonly used klasses // first do Object, String, Class // Calculate offsets for String and Class classes since they are loaded and // can be used after this point. // Fixup mirrors for classes loaded before java.lang.Class. // These calls iterate over the objects currently in the perm gen // so calling them at this point is matters (not before when there // are fewer objects and not later after there are more objects // Preload ref klasses and set reference types // Skip the JSR 292 classes, if not enabled. //_box_klasses[T_OBJECT] = WK_KLASS(object_klass); //_box_klasses[T_ARRAY] = WK_KLASS(object_klass); {
// Compute whether we should use loadClass or loadClassInternal when loading classes. {
// Compute whether we should use checkPackageAccess or NOT// Tells if a given klass is a box (wrapper class, such as java.lang.Integer). // If so, returns the basic type it holds. If not, returns T_OBJECT. // Constraints on class loaders. The details of the algorithm can be // found in the OOPSLA'98 paper "Dynamic Class Loading in the Java // Virtual Machine" by Sheng Liang and Gilad Bracha. The basic idea is // that the system dictionary needs to maintain a set of contraints that // must be satisfied by all classes in the dictionary. // if defining is true, then LinkageError if already in systemDictionary // if initiating loader, then ok if instanceKlass matches existing entry // if different instanceKlass - duplicate class definition, // else - ok, class loaded by a different thread in parallel, // we should only have found it if it was done loading and ok to use // system dictionary only holds instance classes, placeholders // also holds array classes linkage_error =
"loader (instance of %s): attempted duplicate class " "definition for name: \"%s\"";
linkage_error =
"loader constraint violation: loader (instance of %s)" " previously initiated loading for a different type with name \"%s\"";
// Throw error now if needed (cannot throw while holding // SystemDictionary_lock because of rank ordering) // Update system dictionary - done after check_constraint and add_to_hierachy // Compile_lock prevents systemDictionary updates during compilations // See whether biased locking is enabled and if so set it for this // Note that this must be done past the last potential blocking // point / safepoint. We enable biased locking lazily using a // VM_Operation to iterate the SystemDictionary and installing the // biasable mark word into each instanceKlass's prototype header. // To avoid race conditions where we accidentally miss enabling the // optimization for one class in the process of being added to the // dictionary, we must not safepoint after the test of // BiasedLocking::enabled(). // Set biased locking bit for all loaded classes; it will be // cleared if revocation occurs too often for this type // NOTE that we must only do this when the class is initally // defined, not each time it is referenced from a new class loader // Check for a placeholder. If there, remove it and make a // new system dictionary entry. // Changed to allow PH to remain to complete class circularity checking // while only one thread can define a class at one time, multiple // classes can resolve the superclass for a class at one time, // and the placeholder is used to track that // Symbol* ph_check = find_placeholder(name, class_loader); // assert (ph_check == NULL, "should not have a placeholder entry"); // Try to find a class name using the loader constraints. The // loader constraints might know about a class that isn't fully loaded // yet and these will be ignored. // First see if it has been loaded directly. // Force the protection domain to be null. (This removes protection checks.) // Now look to see if it has been loaded elsewhere, and is subject to // a loader constraint that would require this loader to return the // klass that is already loaded. // For array classes, their klassOops are not kept in the // constraint table. The element klassOops are. // If element class already loaded, allocate array klass // Non-array classes are easy: simply check the constraint table. // For array classes, their klassOops are not kept in the // constraint table. The element classes are. // primitive types always pass // Better never do a GC while we're holding these oops // Add entry to resolution error table to record the error when the first // attempt to resolve a reference to a class has failed. // Lookup resolution error table. Returns error if found, otherwise NULL. // Signature constraints ensure that callers and callees agree about // the meaning of type names in their signatures. This routine is the // intake for constraints. It collects them from several places: // * LinkResolver::resolve_method (if check_access is true) requires // that the resolving class (the caller) and the defining class of // the resolved method (the callee) agree on each type in the // * LinkResolver::resolve_interface_method performs exactly the same // * LinkResolver::resolve_field requires that the constant pool // attempting to link to a field agree with the field's defining // class about the type of the field signature. // * klassVtable::initialize_vtable requires that, when a class // overrides a vtable entry allocated by a superclass, that the // overriding method (i.e., the callee) agree with the superclass // on each type in the method's signature. // * klassItable::initialize_itable requires that, when a class fills // in its itables, for each non-abstract method installed in an // itable, the method (i.e., the callee) agree with the interface // on each type in the method's signature. // All those methods have a boolean (check_access, checkconstraints) // which turns off the checks. This is used from specialized contexts // such as bootstrapping, dumping, and debugging. // No direct constraint is placed between the class and its // supertypes. Constraints are only placed along linked relations // between callers and callees. When a method overrides or implements // an abstract method in a supertype (superclass or interface), the // constraints are placed as if the supertype were the caller to the // overriding method. (This works well, since callers to the // supertype have already established agreement between themselves and // the supertype.) As a result of all this, a class can disagree with // its supertype about the meaning of a type name, as long as that // class neither calls a relevant method of the supertype, nor is // called (perhaps via an override) from the supertype. // SystemDictionary::check_signature_loaders(sig, l1, l2) // Make sure all class components (including arrays) in the given // signature will be resolved to the same class in both loaders. // Returns the name of the type that failed a loader constraint check, or // NULL if no constraint failed. The returned C string needs cleaning up // with a ResourceMark in the caller. No exception except OOME is thrown. // Arrays are not added to the loader constraint table, their elements are. // Nothing to do if loaders are the same. // Must create lots of stuff here, but outside of the SystemDictionary lock. // Now grab the lock. We might have to throw away the new method, // if a racing thread has managed to install one at the same time. // Helper for unpacking the return value from linkMethod and linkCallSite. if (
false) {
// FIXME: Decide if the Java upcall should resolve signatures. // call java.lang.invoke.MethodHandleNatives::linkMethod(... String, MethodType) -> MemberName // Ask Java code to find or construct a java.lang.invoke.MethodType for the given // signature, as interpreted relative to the given class loader. // Because of class loader constraints, all method handle usage must be // consistent with this loader. warning(
"SystemDictionary::find_method_handle_type called from compiler thread");
// FIXME return Handle();
// do not attempt from within compiler, unless it was cached bool is_on_bcp =
true;
// keep this true as long as we can materialize from the boot classloader Handle rt;
// the return type from the signature // Note: class_loader & protection_domain are both null at this point. // fall back from BCP to accessing_klass // Resolve, throwing a real error if it doesn't work. // Emulate constantPoolOopDesc::verify_constant_pool_resolve. // call java.lang.invoke.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType // We can cache this MethodType inside the JVM. // report back to the caller with the MethodType // Ask Java code to find or construct a method handle constant. int ref_kind,
//e.g., JVM_REF_invokeVirtual // call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle // Ask Java code to find or construct a java.lang.invoke.CallSite for the given // name and signature, as interpreted relative to the given class loader. for (
int i =
1; i <
len; i++)
"caller must supply a valid BSM");
// call java.lang.invoke.MethodHandleNatives::linkCallSite(caller, bsm, name, mtype, info, &appendix) // Since the identity hash code for symbols changes when the symbols are // moved from the regular perm gen (hash in the mark word) to the shared // spaces (hash is the address), the classes loaded into the dictionary // may be in the wrong buckets. // ---------------------------------------------------------------------------- // loader constraints - print under SD_lock "Verify of loader constraints failed");
"Verify of system dictionary failed");
// Verify constraint table "Loaded klasses should be in SystemDictionary");
// utility function for posting class load event #
endif /* INCLUDE_TRACE */#
endif /* INCLUDE_TRACE */ // post class unload event #
endif /* INCLUDE_TRACE */ static int nclasses;
// number of classes static int nmethods;
// number of methods static int class_size;
// size of class objects in words static int method_size;
// size of method objects in words static int debug_size;
// size of debug info in methods // We do not have to count implementors, since we only store one! // class loader uses same objArray for empty vectors, so don't count these // collect parameter size info (add one for receiver, if any) // collect bytecodes info while ((c = s.
next()) >= 0) {
// parameter size profile