2007-12-01 00:00:00 +00:00
|
|
|
/*
|
2011-03-11 22:33:47 -08:00
|
|
|
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
2007-12-01 00:00:00 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
|
|
*
|
|
|
|
* This code is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 only, as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* version 2 for more details (a copy is included in the LICENSE file that
|
|
|
|
* accompanied this code).
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License version
|
|
|
|
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
2010-05-27 19:08:38 -07:00
|
|
|
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
|
|
* or visit www.oracle.com if you need additional information or have any
|
|
|
|
* questions.
|
2007-12-01 00:00:00 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-23 13:22:55 -08:00
|
|
|
#include "precompiled.hpp"
|
|
|
|
#include "classfile/dictionary.hpp"
|
|
|
|
#include "classfile/javaClasses.hpp"
|
|
|
|
#include "classfile/loaderConstraints.hpp"
|
|
|
|
#include "classfile/placeholders.hpp"
|
|
|
|
#include "classfile/resolutionErrors.hpp"
|
|
|
|
#include "classfile/systemDictionary.hpp"
|
|
|
|
#include "classfile/vmSymbols.hpp"
|
|
|
|
#include "interpreter/bytecodeStream.hpp"
|
|
|
|
#include "interpreter/interpreter.hpp"
|
|
|
|
#include "memory/gcLocker.hpp"
|
|
|
|
#include "memory/oopFactory.hpp"
|
|
|
|
#include "oops/instanceKlass.hpp"
|
|
|
|
#include "oops/instanceRefKlass.hpp"
|
|
|
|
#include "oops/klass.inline.hpp"
|
|
|
|
#include "oops/methodDataOop.hpp"
|
|
|
|
#include "oops/objArrayKlass.hpp"
|
|
|
|
#include "oops/oop.inline.hpp"
|
|
|
|
#include "oops/oop.inline2.hpp"
|
|
|
|
#include "oops/typeArrayKlass.hpp"
|
|
|
|
#include "prims/jvmtiEnvBase.hpp"
|
|
|
|
#include "prims/methodHandles.hpp"
|
|
|
|
#include "runtime/biasedLocking.hpp"
|
|
|
|
#include "runtime/fieldType.hpp"
|
|
|
|
#include "runtime/handles.inline.hpp"
|
|
|
|
#include "runtime/java.hpp"
|
|
|
|
#include "runtime/javaCalls.hpp"
|
|
|
|
#include "runtime/mutexLocker.hpp"
|
|
|
|
#include "runtime/signature.hpp"
|
|
|
|
#include "services/classLoadingService.hpp"
|
|
|
|
#include "services/threadService.hpp"
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
2010-10-19 02:52:57 -07:00
|
|
|
Dictionary* SystemDictionary::_dictionary = NULL;
|
|
|
|
PlaceholderTable* SystemDictionary::_placeholders = NULL;
|
|
|
|
Dictionary* SystemDictionary::_shared_dictionary = NULL;
|
|
|
|
LoaderConstraintTable* SystemDictionary::_loader_constraints = NULL;
|
|
|
|
ResolutionErrorTable* SystemDictionary::_resolution_errors = NULL;
|
|
|
|
SymbolPropertyTable* SystemDictionary::_invoke_method_table = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
int SystemDictionary::_number_of_modifications = 0;
|
|
|
|
|
|
|
|
oop SystemDictionary::_system_loader_lock_obj = NULL;
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
klassOop SystemDictionary::_well_known_klasses[SystemDictionary::WKID_LIMIT]
|
|
|
|
= { NULL /*, NULL...*/ };
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
klassOop SystemDictionary::_box_klasses[T_VOID+1] = { NULL /*, NULL...*/ };
|
|
|
|
|
|
|
|
oop SystemDictionary::_java_system_loader = NULL;
|
|
|
|
|
|
|
|
bool SystemDictionary::_has_loadClassInternal = false;
|
|
|
|
bool SystemDictionary::_has_checkPackageAccess = false;
|
|
|
|
|
|
|
|
// lazily initialized klass variables
|
|
|
|
volatile klassOop SystemDictionary::_abstract_ownable_synchronizer_klass = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Java-level SystemLoader
|
|
|
|
|
|
|
|
oop SystemDictionary::java_system_loader() {
|
|
|
|
return _java_system_loader;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::compute_java_system_loader(TRAPS) {
|
2010-01-06 14:22:39 -08:00
|
|
|
KlassHandle system_klass(THREAD, WK_KLASS(ClassLoader_klass));
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
JavaCalls::call_static(&result,
|
2010-01-06 14:22:39 -08:00
|
|
|
KlassHandle(THREAD, WK_KLASS(ClassLoader_klass)),
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::getSystemClassLoader_name(),
|
|
|
|
vmSymbols::void_classloader_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
CHECK);
|
|
|
|
|
|
|
|
_java_system_loader = (oop)result.get_jobject();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// debugging
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
|
|
|
|
// return true if class_name contains no '.' (internal format is '/')
|
2011-01-27 16:11:27 -08:00
|
|
|
bool SystemDictionary::is_internal_format(Symbol* class_name) {
|
|
|
|
if (class_name != NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
ResourceMark rm;
|
|
|
|
char* name = class_name->as_C_string();
|
|
|
|
return strchr(name, '.') == NULL;
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Parallel class loading check
|
|
|
|
|
|
|
|
bool SystemDictionary::is_parallelCapable(Handle class_loader) {
|
|
|
|
if (UnsyncloadClass || class_loader.is_null()) return true;
|
|
|
|
if (AlwaysLockClassLoader) return false;
|
|
|
|
return java_lang_Class::parallelCapable(class_loader());
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2009-11-11 15:49:38 -05:00
|
|
|
// ParallelDefineClass flag does not apply to bootclass loader
|
|
|
|
bool SystemDictionary::is_parallelDefine(Handle class_loader) {
|
|
|
|
if (class_loader.is_null()) return false;
|
|
|
|
if (AllowParallelDefineClass && java_lang_Class::parallelCapable(class_loader())) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// ----------------------------------------------------------------------------
|
2007-12-01 00:00:00 +00:00
|
|
|
// Resolving of classes
|
|
|
|
|
|
|
|
// Forwards to resolve_or_null
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_or_fail(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
klassOop klass = resolve_or_null(class_name, class_loader, protection_domain, THREAD);
|
|
|
|
if (HAS_PENDING_EXCEPTION || klass == NULL) {
|
|
|
|
KlassHandle k_h(THREAD, klass);
|
|
|
|
// can return a null klass
|
|
|
|
klass = handle_resolution_exception(class_name, class_loader, protection_domain, throw_error, k_h, THREAD);
|
|
|
|
}
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::handle_resolution_exception(Symbol* class_name, Handle class_loader, Handle protection_domain, bool throw_error, KlassHandle klass_h, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
// 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
|
2010-01-06 14:22:39 -08:00
|
|
|
if (throw_error && PENDING_EXCEPTION->is_a(SystemDictionary::ClassNotFoundException_klass())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
assert(klass_h() == NULL, "Should not have result with exception pending");
|
|
|
|
Handle e(THREAD, PENDING_EXCEPTION);
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
|
|
|
THROW_MSG_CAUSE_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string(), e);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Class not found, throw appropriate error or exception depending on value of throw_error
|
|
|
|
if (klass_h() == NULL) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
if (throw_error) {
|
|
|
|
THROW_MSG_0(vmSymbols::java_lang_NoClassDefFoundError(), class_name->as_C_string());
|
|
|
|
} else {
|
|
|
|
THROW_MSG_0(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (klassOop)klass_h();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_or_fail(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
bool throw_error, TRAPS)
|
|
|
|
{
|
|
|
|
return resolve_or_fail(class_name, Handle(), Handle(), throw_error, THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Forwards to resolve_instance_class_or_null
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_or_null(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(!THREAD->is_Compiler_thread(), "Can not load classes with the Compiler thread");
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return resolve_array_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
|
2011-01-27 16:11:27 -08:00
|
|
|
} else if (FieldType::is_obj(class_name)) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
// Ignore wrapping L and ;.
|
|
|
|
TempNewSymbol name = SymbolTable::new_symbol(class_name->as_C_string() + 1,
|
|
|
|
class_name->utf8_length() - 2, CHECK_NULL);
|
|
|
|
return resolve_instance_class_or_null(name, class_loader, protection_domain, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
} else {
|
|
|
|
return resolve_instance_class_or_null(class_name, class_loader, protection_domain, CHECK_NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_or_null(Symbol* class_name, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return resolve_or_null(class_name, Handle(), Handle(), THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Forwards to resolve_instance_class_or_null
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_array_class_or_null(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(FieldType::is_array(class_name), "must be array");
|
2007-12-01 00:00:00 +00:00
|
|
|
klassOop k = NULL;
|
2011-01-27 16:11:27 -08:00
|
|
|
FieldArrayInfo fd;
|
|
|
|
// dimension and object_key in FieldArrayInfo are assigned as a side-effect
|
|
|
|
// of this call
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t == T_OBJECT) {
|
|
|
|
// naked oop "k" is OK here -- we assign back into it
|
2011-01-27 16:11:27 -08:00
|
|
|
k = SystemDictionary::resolve_instance_class_or_null(fd.object_key(),
|
2007-12-01 00:00:00 +00:00
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
CHECK_NULL);
|
|
|
|
if (k != NULL) {
|
2011-01-27 16:11:27 -08:00
|
|
|
k = Klass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
k = Universe::typeArrayKlassObj(t);
|
2011-01-27 16:11:27 -08:00
|
|
|
k = typeArrayKlass::cast(k)->array_klass(fd.dimension(), CHECK_NULL);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// super-class callers:
|
|
|
|
// ClassFileParser - for defineClass & jvmtiRedefineClasses
|
|
|
|
// load_shared_class - while loading a class from shared archive
|
2009-01-05 13:44:03 -05:00
|
|
|
// resolve_instance_class_or_null:
|
|
|
|
// via: handle_parallel_super_load
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
|
|
|
// thread is loading this class/classloader.
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_super_or_fail(Symbol* child_name,
|
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
bool is_superclass,
|
|
|
|
TRAPS) {
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// Try to get one of the well-known klasses.
|
|
|
|
// They are trusted, and do not participate in circularities.
|
|
|
|
if (LinkWellKnownClasses) {
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop k = find_well_known_klass(class_name);
|
2008-04-29 19:45:22 -07:00
|
|
|
if (k != NULL) {
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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 as a claim that this thread is currently loading superclass/classloader
|
|
|
|
// 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
|
|
|
|
// parsed.
|
|
|
|
// Bugs 4643874, 4715493
|
|
|
|
// compute_hash can have a safepoint
|
|
|
|
|
|
|
|
unsigned int d_hash = dictionary()->compute_hash(child_name, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(child_name, class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
// can't throw error holding a lock
|
|
|
|
bool child_already_loaded = false;
|
|
|
|
bool throw_circularity_error = false;
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
klassOop childk = find_class(d_index, d_hash, child_name, class_loader);
|
|
|
|
klassOop quicksuperk;
|
|
|
|
// 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
|
|
|
|
if ((childk != NULL ) && (is_superclass) &&
|
|
|
|
((quicksuperk = instanceKlass::cast(childk)->super()) != NULL) &&
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
((Klass::cast(quicksuperk)->name() == class_name) &&
|
2007-12-01 00:00:00 +00:00
|
|
|
(Klass::cast(quicksuperk)->class_loader() == class_loader()))) {
|
|
|
|
return quicksuperk;
|
|
|
|
} else {
|
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
|
|
|
|
if (probe && probe->check_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER)) {
|
|
|
|
throw_circularity_error = true;
|
|
|
|
}
|
2009-01-05 13:44:03 -05:00
|
|
|
}
|
|
|
|
if (!throw_circularity_error) {
|
2007-12-01 00:00:00 +00:00
|
|
|
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, child_name, class_loader, PlaceholderTable::LOAD_SUPER, class_name, THREAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (throw_circularity_error) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), child_name->as_C_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
// java.lang.Object should have been found above
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(class_name != NULL, "null super class for resolving");
|
2007-12-01 00:00:00 +00:00
|
|
|
// Resolve the super class or interface, check results on return
|
|
|
|
klassOop superk = NULL;
|
|
|
|
superk = SystemDictionary::resolve_or_null(class_name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
THREAD);
|
|
|
|
|
|
|
|
KlassHandle superk_h(THREAD, superk);
|
|
|
|
|
|
|
|
// Note: clean up of placeholders currently in callers of
|
|
|
|
// resolve_super_or_fail - either at update_dictionary time
|
|
|
|
// or on error
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, child_name, class_loader);
|
|
|
|
if (probe != NULL) {
|
|
|
|
probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_SUPER);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HAS_PENDING_EXCEPTION || superk_h() == NULL) {
|
|
|
|
// can null superk
|
|
|
|
superk_h = KlassHandle(THREAD, handle_resolution_exception(class_name, class_loader, protection_domain, true, superk_h, THREAD));
|
|
|
|
}
|
|
|
|
|
|
|
|
return superk_h();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::validate_protection_domain(instanceKlassHandle klass,
|
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
|
|
|
if(!has_checkPackageAccess()) return;
|
|
|
|
|
|
|
|
// Now we have to call back to java to check if the initating class has access
|
|
|
|
JavaValue result(T_VOID);
|
|
|
|
if (TraceProtectionDomainVerification) {
|
|
|
|
// Print out trace information
|
|
|
|
tty->print_cr("Checking package access");
|
|
|
|
tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr();
|
|
|
|
tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr();
|
|
|
|
tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr();
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(class_loader() != NULL, "should not have non-null protection domain for null classloader");
|
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass());
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaCalls::call_special(&result,
|
|
|
|
class_loader,
|
|
|
|
system_loader,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::checkPackageAccess_name(),
|
|
|
|
vmSymbols::class_protectiondomain_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle(THREAD, klass->java_mirror()),
|
|
|
|
protection_domain,
|
|
|
|
THREAD);
|
|
|
|
|
|
|
|
if (TraceProtectionDomainVerification) {
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!");
|
|
|
|
} else {
|
|
|
|
tty->print_cr(" -> granted");
|
|
|
|
}
|
|
|
|
tty->cr();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (HAS_PENDING_EXCEPTION) return;
|
|
|
|
|
|
|
|
// 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.
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* kn = klass->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int d_hash = dictionary()->compute_hash(kn, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
No_Safepoint_Verifier nosafepoint;
|
|
|
|
dictionary()->add_protection_domain(d_index, d_hash, klass, class_loader,
|
|
|
|
protection_domain, THREAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// object lock
|
|
|
|
// Waits on SystemDictionary_lock to indicate placeholder table updated
|
|
|
|
// On return, caller must recheck placeholder table state
|
|
|
|
//
|
|
|
|
// We only get here if
|
|
|
|
// 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
|
|
|
|
// and to avoid deadlock
|
|
|
|
// 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
|
|
|
|
// to prevent deadlocks
|
|
|
|
//
|
|
|
|
// The notify allows applications that did an untimed wait() on
|
|
|
|
// the classloader object lock to not hang.
|
|
|
|
void SystemDictionary::double_lock_wait(Handle lockObject, TRAPS) {
|
|
|
|
assert_lock_strong(SystemDictionary_lock);
|
|
|
|
|
|
|
|
bool calledholdinglock
|
|
|
|
= ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD, lockObject);
|
|
|
|
assert(calledholdinglock,"must hold lock for notify");
|
2009-01-05 13:44:03 -05:00
|
|
|
assert((!(lockObject() == _system_loader_lock_obj) && !is_parallelCapable(lockObject)), "unexpected double_lock_wait");
|
2007-12-01 00:00:00 +00:00
|
|
|
ObjectSynchronizer::notifyall(lockObject, THREAD);
|
|
|
|
intptr_t recursions = ObjectSynchronizer::complete_exit(lockObject, THREAD);
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
SystemDictionary_lock->unlock();
|
|
|
|
ObjectSynchronizer::reenter(lockObject, recursions, THREAD);
|
|
|
|
SystemDictionary_lock->lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 -
|
2009-01-05 13:44:03 -05:00
|
|
|
// to force placeholder entry creation for this class for circularity detection
|
2007-12-01 00:00:00 +00:00
|
|
|
// Caller must check for pending exception
|
|
|
|
// Returns non-null klassOop if other thread has completed load
|
|
|
|
// and we are done,
|
|
|
|
// If return null klassOop and no pending exception, the caller must load the class
|
|
|
|
instanceKlassHandle SystemDictionary::handle_parallel_super_load(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name, Symbol* superclassname, Handle class_loader,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle protection_domain, Handle lockObject, TRAPS) {
|
|
|
|
|
|
|
|
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
|
|
|
|
unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// entry on error.
|
|
|
|
klassOop superk = SystemDictionary::resolve_super_or_fail(name,
|
|
|
|
superclassname,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
true,
|
|
|
|
CHECK_(nh));
|
|
|
|
// 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
|
|
|
|
// data structures).
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// parallelCapable class loaders do NOT wait for parallel superclass loads to complete
|
|
|
|
// Serial class loaders and bootstrap classloader do wait for superclass loads
|
|
|
|
if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Check if classloading completed while we were loading superclass or waiting
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
|
|
|
return(instanceKlassHandle(THREAD, check));
|
|
|
|
} else {
|
|
|
|
return nh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// must loop to both handle other placeholder updates
|
|
|
|
// and spurious notifications
|
|
|
|
bool super_load_in_progress = true;
|
|
|
|
PlaceholderEntry* placeholder;
|
|
|
|
while (super_load_in_progress) {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Check if classloading completed while we were loading superclass or waiting
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
|
|
|
return(instanceKlassHandle(THREAD, check));
|
|
|
|
} else {
|
|
|
|
placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
|
|
|
|
if (placeholder && placeholder->super_load_in_progress() ){
|
|
|
|
// Before UnsyncloadClass:
|
|
|
|
// We only get here if the application has released the
|
|
|
|
// classloader lock when another thread was in the middle of loading a
|
|
|
|
// superclass/superinterface for this class, and now
|
|
|
|
// 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
|
|
|
|
// all the superclass/superinterface loading it can, until
|
|
|
|
// 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 (class_loader.is_null()) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
} else {
|
|
|
|
double_lock_wait(lockObject, THREAD);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// If not in SD and not in PH, other thread's load must have failed
|
|
|
|
super_load_in_progress = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (nh);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_instance_class_or_null(Symbol* name, Handle class_loader, Handle protection_domain, TRAPS) {
|
|
|
|
assert(name != NULL && !FieldType::is_array(name) &&
|
|
|
|
!FieldType::is_obj(name), "invalid class name");
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// UseNewReflection
|
|
|
|
// Fix for 4474172; see evaluation for more details
|
|
|
|
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
|
|
|
|
|
|
|
|
// Do lookup to see if class already exist and the protection domain
|
|
|
|
// has the right access
|
|
|
|
unsigned int d_hash = dictionary()->compute_hash(name, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
klassOop probe = dictionary()->find(d_index, d_hash, name, class_loader,
|
|
|
|
protection_domain, THREAD);
|
|
|
|
if (probe != NULL) return probe;
|
|
|
|
|
|
|
|
|
|
|
|
// Non-bootstrap class loaders will call out to class loader and
|
|
|
|
// define via jvm/jni_DefineClass which will acquire the
|
|
|
|
// 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
|
|
|
|
// the define
|
2009-01-05 13:44:03 -05:00
|
|
|
// ParallelCapable Classloaders and the bootstrap classloader,
|
2007-12-01 00:00:00 +00:00
|
|
|
// or all classloaders with UnsyncloadClass do not acquire lock here
|
|
|
|
bool DoObjectLock = true;
|
2009-01-05 13:44:03 -05:00
|
|
|
if (is_parallelCapable(class_loader)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
DoObjectLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name, class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
// Class is not in SystemDictionary so we have to do loading.
|
|
|
|
// Make sure we are synchronized on the class loader before we proceed
|
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
|
|
|
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
|
|
|
|
|
|
|
|
// Check again (after locking) if class already exist in SystemDictionary
|
|
|
|
bool class_has_been_loaded = false;
|
|
|
|
bool super_load_in_progress = false;
|
|
|
|
bool havesupername = false;
|
|
|
|
instanceKlassHandle k;
|
|
|
|
PlaceholderEntry* placeholder;
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* superclassname = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
|
|
|
class_has_been_loaded = true;
|
|
|
|
k = instanceKlassHandle(THREAD, check);
|
|
|
|
} else {
|
|
|
|
placeholder = placeholders()->get_entry(p_index, p_hash, name, class_loader);
|
|
|
|
if (placeholder && placeholder->super_load_in_progress()) {
|
|
|
|
super_load_in_progress = true;
|
|
|
|
if (placeholder->havesupername() == true) {
|
2011-01-27 16:11:27 -08:00
|
|
|
superclassname = placeholder->supername();
|
2007-12-01 00:00:00 +00:00
|
|
|
havesupername = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the class in is in the placeholder table, class loading is in progress
|
|
|
|
if (super_load_in_progress && havesupername==true) {
|
|
|
|
k = SystemDictionary::handle_parallel_super_load(name, superclassname,
|
|
|
|
class_loader, protection_domain, lockObject, THREAD);
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (!k.is_null()) {
|
|
|
|
class_has_been_loaded = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_has_been_loaded) {
|
|
|
|
|
|
|
|
// add placeholder entry to record loading instance class
|
|
|
|
// Five cases:
|
|
|
|
// All cases need to prevent modifying bootclasssearchpath
|
|
|
|
// in parallel with a classload of same classname
|
2009-01-05 13:44:03 -05:00
|
|
|
// Redefineclasses uses existence of the placeholder for the duration
|
|
|
|
// of the class load to prevent concurrent redefinition of not completely
|
|
|
|
// defined classes.
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
|
|
|
// class/classloader pair
|
|
|
|
// case4. Bootstrap classloader - don't own objectLocker
|
|
|
|
// This classloader supports parallelism at the classloader level,
|
|
|
|
// but only allows a single load of a class/classloader pair.
|
|
|
|
// No performance benefit and no deadlock issues.
|
2009-01-05 13:44:03 -05:00
|
|
|
// case 5. parallelCapable user level classloaders - without objectLocker
|
|
|
|
// Allow parallel classloading of a class/classloader pair
|
2007-12-01 00:00:00 +00:00
|
|
|
bool throw_circularity_error = false;
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
|
|
|
|
if (oldprobe) {
|
|
|
|
// only need check_seen_thread once, not on each loop
|
|
|
|
// 6341374 java/lang/Instrument with -Xcomp
|
|
|
|
if (oldprobe->check_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE)) {
|
|
|
|
throw_circularity_error = true;
|
|
|
|
} else {
|
|
|
|
// case 1: traditional: should never see load_in_progress.
|
|
|
|
while (!class_has_been_loaded && oldprobe && oldprobe->instance_load_in_progress()) {
|
|
|
|
|
|
|
|
// case 4: bootstrap classloader: prevent futile classloading,
|
|
|
|
// wait on first requestor
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
} else {
|
|
|
|
// case 2: traditional with broken classloader lock. wait on first
|
|
|
|
// requestor.
|
|
|
|
double_lock_wait(lockObject, THREAD);
|
|
|
|
}
|
|
|
|
// Check if classloading completed while we were waiting
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
|
|
|
k = instanceKlassHandle(THREAD, check);
|
|
|
|
class_has_been_loaded = true;
|
|
|
|
}
|
|
|
|
// check if other thread failed to load and cleaned up
|
|
|
|
oldprobe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// All cases: add LOAD_INSTANCE
|
2009-01-05 13:44:03 -05:00
|
|
|
// case 3: UnsyncloadClass || case 5: parallelCapable: allow competing threads to try
|
2007-12-01 00:00:00 +00:00
|
|
|
// LOAD_INSTANCE in parallel
|
|
|
|
// add placeholder entry even if error - callers will remove on error
|
2009-01-05 13:44:03 -05:00
|
|
|
if (!throw_circularity_error && !class_has_been_loaded) {
|
2011-01-27 16:11:27 -08:00
|
|
|
PlaceholderEntry* newprobe = placeholders()->find_and_add(p_index, p_hash, name, class_loader, PlaceholderTable::LOAD_INSTANCE, NULL, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
// For class loaders that do not acquire the classloader object lock,
|
|
|
|
// if they did not catch another thread holding LOAD_INSTANCE,
|
|
|
|
// need a check analogous to the acquire ObjectLocker/find_class
|
|
|
|
// i.e. now that we hold the LOAD_INSTANCE token on loading this class/CL
|
|
|
|
// one final check if the load has already completed
|
2009-01-05 13:44:03 -05:00
|
|
|
// class loaders holding the ObjectLock shouldn't find the class here
|
2007-12-01 00:00:00 +00:00
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just return it
|
|
|
|
k = instanceKlassHandle(THREAD, check);
|
|
|
|
class_has_been_loaded = true;
|
|
|
|
newprobe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
|
2009-01-05 13:44:03 -05:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// must throw error outside of owning lock
|
|
|
|
if (throw_circularity_error) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
THROW_MSG_0(vmSymbols::java_lang_ClassCircularityError(), name->as_C_string());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!class_has_been_loaded) {
|
|
|
|
|
|
|
|
// Do actual loading
|
|
|
|
k = load_instance_class(name, class_loader, THREAD);
|
|
|
|
|
2009-11-11 15:49:38 -05:00
|
|
|
// For UnsyncloadClass only
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
2009-11-11 15:49:38 -05:00
|
|
|
// with the new cleaner mechanism, even with AllowParallelDefineClass
|
2009-01-05 13:44:03 -05:00
|
|
|
// Bootstrap goes through here to allow for an extra guarantee check
|
2007-12-01 00:00:00 +00:00
|
|
|
if (UnsyncloadClass || (class_loader.is_null())) {
|
|
|
|
if (k.is_null() && HAS_PENDING_EXCEPTION
|
2010-01-06 14:22:39 -08:00
|
|
|
&& PENDING_EXCEPTION->is_a(SystemDictionary::LinkageError_klass())) {
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
// Klass is already loaded, so just use it
|
|
|
|
k = instanceKlassHandle(THREAD, check);
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
|
|
|
guarantee((!class_loader.is_null()), "dup definition for bootstrap loader?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name, class_loader);
|
|
|
|
if (probe != NULL) {
|
|
|
|
probe->remove_seen_thread(THREAD, PlaceholderTable::LOAD_INSTANCE);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If everything was OK (no exceptions, no null return value), and
|
|
|
|
// class_loader is NOT the defining loader, do a little more bookkeeping.
|
|
|
|
if (!HAS_PENDING_EXCEPTION && !k.is_null() &&
|
|
|
|
k->class_loader() != class_loader()) {
|
|
|
|
|
|
|
|
check_constraints(d_index, d_hash, k, class_loader, false, THREAD);
|
|
|
|
|
|
|
|
// Need to check for a PENDING_EXCEPTION again; check_constraints
|
|
|
|
// can throw and doesn't use the CHECK macro.
|
|
|
|
if (!HAS_PENDING_EXCEPTION) {
|
|
|
|
{ // Grabbing the Compile_lock prevents systemDictionary updates
|
|
|
|
// during compilations.
|
|
|
|
MutexLocker mu(Compile_lock, THREAD);
|
|
|
|
update_dictionary(d_index, d_hash, p_index, p_hash,
|
|
|
|
k, class_loader, THREAD);
|
|
|
|
}
|
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
Thread *thread = THREAD;
|
|
|
|
assert(thread->is_Java_thread(), "thread->is_Java_thread()");
|
|
|
|
JvmtiExport::post_class_load((JavaThread *) thread, k());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (HAS_PENDING_EXCEPTION || k.is_null()) {
|
|
|
|
// On error, clean up placeholders
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
|
|
|
{
|
|
|
|
Handle loader (THREAD, k->class_loader());
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2011-01-27 16:11:27 -08:00
|
|
|
oop kk = find_class(name, loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(kk == k(), "should be present in dictionary");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// return if the protection domain in NULL
|
|
|
|
if (protection_domain() == NULL) return k();
|
|
|
|
|
|
|
|
// Check the protection domain has the right access
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// 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.
|
|
|
|
No_Safepoint_Verifier nosafepoint;
|
|
|
|
if (dictionary()->is_valid_protection_domain(d_index, d_hash, name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain)) {
|
|
|
|
return k();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify protection domain. If it fails an exception is thrown
|
|
|
|
validate_protection_domain(k, class_loader, protection_domain, CHECK_(klassOop(NULL)));
|
|
|
|
|
|
|
|
return k();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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 new entry.
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::find(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
|
|
|
|
2009-01-16 11:23:10 -08:00
|
|
|
// UseNewReflection
|
|
|
|
// 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.
|
|
|
|
class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
|
|
|
|
{
|
|
|
|
// 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.
|
|
|
|
No_Safepoint_Verifier nosafepoint;
|
|
|
|
return dictionary()->find(d_index, d_hash, class_name, class_loader,
|
|
|
|
protection_domain, THREAD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Look for a loaded instance or array klass by name. Do not do any loading.
|
|
|
|
// return NULL in case of error.
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
TRAPS) {
|
|
|
|
klassOop k = NULL;
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(class_name != NULL, "class name must be non NULL");
|
2008-04-29 19:45:22 -07:00
|
|
|
|
|
|
|
// Try to get one of the well-known klasses.
|
|
|
|
if (LinkWellKnownClasses) {
|
2011-01-27 16:11:27 -08:00
|
|
|
k = find_well_known_klass(class_name);
|
2008-04-29 19:45:22 -07:00
|
|
|
if (k != NULL) {
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
// The name refers to an array. Parse the name.
|
2011-01-27 16:11:27 -08:00
|
|
|
// dimension and object_key in FieldArrayInfo are assigned as a
|
|
|
|
// side-effect of this call
|
|
|
|
FieldArrayInfo fd;
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t != T_OBJECT) {
|
|
|
|
k = Universe::typeArrayKlassObj(t);
|
|
|
|
} else {
|
2011-01-27 16:11:27 -08:00
|
|
|
k = SystemDictionary::find(fd.object_key(), class_loader, protection_domain, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
if (k != NULL) {
|
2011-01-27 16:11:27 -08:00
|
|
|
k = Klass::cast(k)->array_klass_or_null(fd.dimension());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
k = find(class_name, class_loader, protection_domain, THREAD);
|
|
|
|
}
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// Quick range check for names of well-known classes:
|
2011-01-27 16:11:27 -08:00
|
|
|
static Symbol* wk_klass_name_limits[2] = {NULL, NULL};
|
2008-04-29 19:45:22 -07:00
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
static int find_wkk_calls, find_wkk_probes, find_wkk_wins;
|
|
|
|
// counts for "hello world": 3983, 1616, 1075
|
|
|
|
// => 60% hit after limit guard, 25% total win rate
|
|
|
|
#endif
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::find_well_known_klass(Symbol* class_name) {
|
2008-04-29 19:45:22 -07:00
|
|
|
// A bounds-check on class_name will quickly get a negative result.
|
|
|
|
NOT_PRODUCT(find_wkk_calls++);
|
|
|
|
if (class_name >= wk_klass_name_limits[0] &&
|
|
|
|
class_name <= wk_klass_name_limits[1]) {
|
|
|
|
NOT_PRODUCT(find_wkk_probes++);
|
|
|
|
vmSymbols::SID sid = vmSymbols::find_sid(class_name);
|
|
|
|
if (sid != vmSymbols::NO_SID) {
|
|
|
|
klassOop k = NULL;
|
|
|
|
switch (sid) {
|
|
|
|
#define WK_KLASS_CASE(name, symbol, ignore_option) \
|
|
|
|
case vmSymbols::VM_SYMBOL_ENUM_NAME(symbol): \
|
|
|
|
k = WK_KLASS(name); break;
|
|
|
|
WK_KLASSES_DO(WK_KLASS_CASE)
|
|
|
|
#undef WK_KLASS_CASE
|
|
|
|
}
|
|
|
|
NOT_PRODUCT(if (k != NULL) find_wkk_wins++);
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Note: this method is much like resolve_from_stream, but
|
|
|
|
// updates no supplemental data structures.
|
|
|
|
// TODO consolidate the two methods with a helper routine?
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::parse_stream(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
ClassFileStream* st,
|
2008-11-12 22:33:26 -08:00
|
|
|
KlassHandle host_klass,
|
|
|
|
GrowableArray<Handle>* cp_patches,
|
2007-12-01 00:00:00 +00:00
|
|
|
TRAPS) {
|
2011-01-27 16:11:27 -08:00
|
|
|
TempNewSymbol parsed_name = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
2009-04-08 10:56:49 -07:00
|
|
|
host_klass,
|
|
|
|
cp_patches,
|
2007-12-01 00:00:00 +00:00
|
|
|
parsed_name,
|
2009-09-04 12:53:02 -04:00
|
|
|
true,
|
2007-12-01 00:00:00 +00:00
|
|
|
THREAD);
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// data structures).
|
|
|
|
// 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.
|
2011-01-27 16:11:27 -08:00
|
|
|
if (parsed_name != NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(parsed_name,
|
|
|
|
class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-12 22:33:26 -08:00
|
|
|
if (host_klass.not_null() && k.not_null()) {
|
2011-03-31 02:31:57 -07:00
|
|
|
assert(EnableInvokeDynamic, "");
|
2008-11-12 22:33:26 -08:00
|
|
|
// If it's anonymous, initialize it now, since nobody else will.
|
|
|
|
k->set_host_klass(host_klass());
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu_r(Compile_lock, THREAD);
|
|
|
|
|
|
|
|
// Add to class hierarchy, initialize vtables, and do possible
|
|
|
|
// deoptimizations.
|
|
|
|
add_to_hierarchy(k, CHECK_NULL); // No exception, but can block
|
|
|
|
|
|
|
|
// But, do not add to system dictionary.
|
|
|
|
}
|
|
|
|
|
|
|
|
k->eager_initialize(THREAD);
|
|
|
|
|
|
|
|
// notify jvmti
|
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
|
|
|
|
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
return k();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a klass to the system from a stream (called by jni_DefineClass and
|
|
|
|
// JVM_DefineClass).
|
|
|
|
// Note: class_name can be NULL. In that case we do not know the name of
|
|
|
|
// the class until we have parsed the stream.
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::resolve_from_stream(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader,
|
|
|
|
Handle protection_domain,
|
|
|
|
ClassFileStream* st,
|
2009-09-04 12:53:02 -04:00
|
|
|
bool verify,
|
2007-12-01 00:00:00 +00:00
|
|
|
TRAPS) {
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// Classloaders that support parallelism, e.g. bootstrap classloader,
|
|
|
|
// or all classloaders with UnsyncloadClass do not acquire lock here
|
|
|
|
bool DoObjectLock = true;
|
|
|
|
if (is_parallelCapable(class_loader)) {
|
|
|
|
DoObjectLock = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we are synchronized on the class loader before we proceed
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
TempNewSymbol parsed_name = NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
instanceKlassHandle k = ClassFileParser(st).parseClassFile(class_name,
|
|
|
|
class_loader,
|
|
|
|
protection_domain,
|
|
|
|
parsed_name,
|
2009-09-04 12:53:02 -04:00
|
|
|
verify,
|
2007-12-01 00:00:00 +00:00
|
|
|
THREAD);
|
|
|
|
|
|
|
|
const char* pkg = "java/";
|
|
|
|
if (!HAS_PENDING_EXCEPTION &&
|
|
|
|
!class_loader.is_null() &&
|
2011-01-27 16:11:27 -08:00
|
|
|
parsed_name != NULL &&
|
2007-12-01 00:00:00 +00:00
|
|
|
!strncmp((const char*)parsed_name->bytes(), pkg, strlen(pkg))) {
|
|
|
|
// It is illegal to define classes in the "java." package from
|
|
|
|
// JVM_DefineClass or jni_DefineClass unless you're the bootclassloader
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
char* name = parsed_name->as_C_string();
|
|
|
|
char* index = strrchr(name, '/');
|
|
|
|
*index = '\0'; // chop to just the package name
|
|
|
|
while ((index = strchr(name, '/')) != NULL) {
|
|
|
|
*index = '.'; // replace '/' with '.' in package name
|
|
|
|
}
|
|
|
|
const char* fmt = "Prohibited package name: %s";
|
|
|
|
size_t len = strlen(fmt) + strlen(name);
|
|
|
|
char* message = NEW_RESOURCE_ARRAY(char, len);
|
|
|
|
jio_snprintf(message, len, fmt, name);
|
|
|
|
Exceptions::_throw_msg(THREAD_AND_LOCATION,
|
|
|
|
vmSymbols::java_lang_SecurityException(), message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!HAS_PENDING_EXCEPTION) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(parsed_name != NULL, "Sanity");
|
|
|
|
assert(class_name == NULL || class_name == parsed_name, "name mismatch");
|
2007-12-01 00:00:00 +00:00
|
|
|
// Verification prevents us from creating names with dots in them, this
|
|
|
|
// asserts that that's the case.
|
|
|
|
assert(is_internal_format(parsed_name),
|
|
|
|
"external class name format used internally");
|
|
|
|
|
|
|
|
// Add class just loaded
|
2009-01-05 13:44:03 -05:00
|
|
|
// If a class loader supports parallel classloading handle parallel define requests
|
|
|
|
// find_or_define_instance_class may return a different instanceKlass
|
|
|
|
if (is_parallelCapable(class_loader)) {
|
|
|
|
k = find_or_define_instance_class(class_name, class_loader, k, THREAD);
|
|
|
|
} else {
|
|
|
|
define_instance_class(k, THREAD);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// find the name).
|
2011-01-27 16:11:27 -08:00
|
|
|
if (HAS_PENDING_EXCEPTION && parsed_name != NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(parsed_name,
|
|
|
|
class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, parsed_name, class_loader, THREAD);
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that we didn't leave a place holder in the
|
|
|
|
// SystemDictionary; this is only done on success
|
|
|
|
debug_only( {
|
|
|
|
if (!HAS_PENDING_EXCEPTION) {
|
2011-01-27 16:11:27 -08:00
|
|
|
assert(parsed_name != NULL, "parsed_name is still null?");
|
|
|
|
Symbol* h_name = k->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle h_loader (THREAD, k->class_loader());
|
|
|
|
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop check = find_class(parsed_name, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(check == k(), "should be present in the dictionary");
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop check2 = find_class(h_name, h_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(check == check2, "name inconsistancy in SystemDictionary");
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
|
|
|
|
return k();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::set_shared_dictionary(HashtableBucket* t, int length,
|
|
|
|
int number_of_entries) {
|
|
|
|
assert(length == _nof_buckets * sizeof(HashtableBucket),
|
|
|
|
"bad shared dictionary size.");
|
|
|
|
_shared_dictionary = new Dictionary(_nof_buckets, t, number_of_entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// If there is a shared dictionary, then find the entry for the
|
|
|
|
// given shared system class, if any.
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::find_shared_class(Symbol* class_name) {
|
2007-12-01 00:00:00 +00:00
|
|
|
if (shared_dictionary() != NULL) {
|
|
|
|
unsigned int d_hash = dictionary()->compute_hash(class_name, Handle());
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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.]
|
|
|
|
|
|
|
|
instanceKlassHandle SystemDictionary::load_shared_class(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name, Handle class_loader, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
instanceKlassHandle ik (THREAD, find_shared_class(class_name));
|
|
|
|
return load_shared_class(ik, class_loader, THREAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
instanceKlassHandle SystemDictionary::load_shared_class(
|
|
|
|
instanceKlassHandle ik, Handle class_loader, TRAPS) {
|
|
|
|
assert(class_loader.is_null(), "non-null classloader for shared class?");
|
|
|
|
if (ik.not_null()) {
|
|
|
|
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name = ik->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// 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).
|
|
|
|
|
|
|
|
if (ik->super() != NULL) {
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* cn = ik->super()->klass_part()->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
resolve_super_or_fail(class_name, cn,
|
|
|
|
class_loader, Handle(), true, CHECK_(nh));
|
|
|
|
}
|
|
|
|
|
|
|
|
objArrayHandle interfaces (THREAD, ik->local_interfaces());
|
|
|
|
int num_interfaces = interfaces->length();
|
|
|
|
for (int index = 0; index < num_interfaces; index++) {
|
|
|
|
klassOop k = klassOop(interfaces->obj_at(index));
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// are loaded)
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name = k->klass_part()->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
resolve_super_or_fail(class_name, name, class_loader, Handle(), false, CHECK_(nh));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adjust methods to recover missing data. They need addresses for
|
|
|
|
// interpreter entry points and their default native method address
|
|
|
|
// must be reset.
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
{
|
|
|
|
Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
|
|
|
|
check_loader_lock_contention(lockObject, THREAD);
|
|
|
|
ObjectLocker ol(lockObject, THREAD, true);
|
|
|
|
|
|
|
|
objArrayHandle methods (THREAD, ik->methods());
|
|
|
|
int num_methods = methods->length();
|
|
|
|
for (int index2 = 0; index2 < num_methods; ++index2) {
|
|
|
|
methodHandle m(THREAD, methodOop(methods->obj_at(index2)));
|
|
|
|
m()->link_method(m, CHECK_(nh));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TraceClassLoading) {
|
|
|
|
ResourceMark rm;
|
|
|
|
tty->print("[Loaded %s", ik->external_name());
|
|
|
|
tty->print(" from shared objects file");
|
|
|
|
tty->print_cr("]");
|
|
|
|
}
|
|
|
|
// notify a class loaded from shared object
|
|
|
|
ClassLoadingService::notify_class_loaded(instanceKlass::cast(ik()),
|
|
|
|
true /* shared class */);
|
|
|
|
}
|
|
|
|
return ik;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KERNEL
|
|
|
|
// Some classes on the bootstrap class path haven't been installed on the
|
|
|
|
// system yet. Call the DownloadManager method to make them appear in the
|
|
|
|
// bootstrap class path and try again to load the named class.
|
|
|
|
// Note that with delegation class loaders all classes in another loader will
|
|
|
|
// first try to call this so it'd better be fast!!
|
|
|
|
static instanceKlassHandle download_and_retry_class_load(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
TRAPS) {
|
|
|
|
|
|
|
|
klassOop dlm = SystemDictionary::sun_jkernel_DownloadManager_klass();
|
|
|
|
instanceKlassHandle nk;
|
|
|
|
|
|
|
|
// If download manager class isn't loaded just return.
|
|
|
|
if (dlm == NULL) return nk;
|
|
|
|
|
|
|
|
{ HandleMark hm(THREAD);
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nk));
|
|
|
|
Handle class_string = java_lang_String::externalize_classname(s, CHECK_(nk));
|
|
|
|
|
|
|
|
// return value
|
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
|
|
|
|
// Call the DownloadManager. We assume that it has a lock because
|
|
|
|
// multiple classes could be not found and downloaded at the same time.
|
|
|
|
// class sun.misc.DownloadManager;
|
|
|
|
// public static String getBootClassPathEntryForClass(String className);
|
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
KlassHandle(THREAD, dlm),
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::getBootClassPathEntryForClass_name(),
|
|
|
|
vmSymbols::string_string_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
class_string,
|
|
|
|
CHECK_(nk));
|
|
|
|
|
|
|
|
// Get result.string and add to bootclasspath
|
|
|
|
assert(result.get_type() == T_OBJECT, "just checking");
|
|
|
|
oop obj = (oop) result.get_jobject();
|
|
|
|
if (obj == NULL) { return nk; }
|
|
|
|
|
2008-01-17 13:38:17 -08:00
|
|
|
Handle h_obj(THREAD, obj);
|
|
|
|
char* new_class_name = java_lang_String::as_platform_dependent_str(h_obj,
|
|
|
|
CHECK_(nk));
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// lock the loader
|
|
|
|
// we use this lock because JVMTI does.
|
|
|
|
Handle loader_lock(THREAD, SystemDictionary::system_loader_lock());
|
|
|
|
|
|
|
|
ObjectLocker ol(loader_lock, THREAD);
|
|
|
|
// add the file to the bootclasspath
|
|
|
|
ClassLoader::update_class_path_entry_list(new_class_name, true);
|
|
|
|
} // end HandleMark
|
|
|
|
|
|
|
|
if (TraceClassLoading) {
|
|
|
|
ClassLoader::print_bootclasspath();
|
|
|
|
}
|
|
|
|
return ClassLoader::load_classfile(class_name, CHECK_(nk));
|
|
|
|
}
|
|
|
|
#endif // KERNEL
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
instanceKlassHandle SystemDictionary::load_instance_class(Symbol* class_name, Handle class_loader, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
|
|
|
|
if (class_loader.is_null()) {
|
2009-07-10 11:10:00 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Search the shared system dictionary for classes preloaded into the
|
|
|
|
// shared spaces.
|
|
|
|
instanceKlassHandle k;
|
2009-07-10 11:10:00 -07:00
|
|
|
{
|
|
|
|
PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
|
|
|
|
k = load_shared_class(class_name, class_loader, THREAD);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
if (k.is_null()) {
|
|
|
|
// Use VM class loader
|
2009-07-10 11:10:00 -07:00
|
|
|
PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
|
2007-12-01 00:00:00 +00:00
|
|
|
k = ClassLoader::load_classfile(class_name, CHECK_(nh));
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef KERNEL
|
|
|
|
// If the VM class loader has failed to load the class, call the
|
|
|
|
// DownloadManager class to make it magically appear on the classpath
|
|
|
|
// and try again. This is only configured with the Kernel VM.
|
|
|
|
if (k.is_null()) {
|
|
|
|
k = download_and_retry_class_load(class_name, CHECK_(nh));
|
|
|
|
}
|
|
|
|
#endif // KERNEL
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// find_or_define_instance_class may return a different instanceKlass
|
2007-12-01 00:00:00 +00:00
|
|
|
if (!k.is_null()) {
|
|
|
|
k = find_or_define_instance_class(class_name, class_loader, k, CHECK_(nh));
|
|
|
|
}
|
|
|
|
return k;
|
|
|
|
} else {
|
|
|
|
// Use user specified class loader to load class. Call loadClass operation on class_loader.
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
|
2009-07-10 11:10:00 -07:00
|
|
|
assert(THREAD->is_Java_thread(), "must be a JavaThread");
|
|
|
|
JavaThread* jt = (JavaThread*) THREAD;
|
|
|
|
|
|
|
|
PerfClassTraceTime vmtimer(ClassLoader::perf_app_classload_time(),
|
|
|
|
ClassLoader::perf_app_classload_selftime(),
|
|
|
|
ClassLoader::perf_app_classload_count(),
|
|
|
|
jt->get_thread_stat()->perf_recursion_counts_addr(),
|
|
|
|
jt->get_thread_stat()->perf_timers_addr(),
|
|
|
|
PerfClassTraceTime::CLASS_LOAD);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle s = java_lang_String::create_from_symbol(class_name, CHECK_(nh));
|
|
|
|
// Translate to external class name format, i.e., convert '/' chars to '.'
|
|
|
|
Handle string = java_lang_String::externalize_classname(s, CHECK_(nh));
|
|
|
|
|
|
|
|
JavaValue result(T_OBJECT);
|
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
KlassHandle spec_klass (THREAD, SystemDictionary::ClassLoader_klass());
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// 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
|
2007-12-01 00:00:00 +00:00
|
|
|
// custom class loaders without synchronization.
|
|
|
|
// WARNING If a custom class loader does NOT synchronizer findClass, or callers of
|
2009-01-05 13:44:03 -05:00
|
|
|
// findClass, the UnsyncloadClass flag risks unexpected timing bugs in the field.
|
2007-12-01 00:00:00 +00:00
|
|
|
// Do NOT assume this will be supported in future releases.
|
2009-01-05 13:44:03 -05:00
|
|
|
//
|
|
|
|
// Added MustCallLoadClassInternal in case we discover in the field
|
|
|
|
// a customer that counts on this call
|
|
|
|
if (MustCallLoadClassInternal && has_loadClassInternal()) {
|
2007-12-01 00:00:00 +00:00
|
|
|
JavaCalls::call_special(&result,
|
|
|
|
class_loader,
|
|
|
|
spec_klass,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::loadClassInternal_name(),
|
|
|
|
vmSymbols::string_class_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
string,
|
|
|
|
CHECK_(nh));
|
|
|
|
} else {
|
|
|
|
JavaCalls::call_virtual(&result,
|
|
|
|
class_loader,
|
|
|
|
spec_klass,
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::loadClass_name(),
|
|
|
|
vmSymbols::string_class_signature(),
|
2007-12-01 00:00:00 +00:00
|
|
|
string,
|
|
|
|
CHECK_(nh));
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(result.get_type() == T_OBJECT, "just checking");
|
|
|
|
oop obj = (oop) result.get_jobject();
|
|
|
|
|
|
|
|
// Primitive classes return null since forName() can not be
|
|
|
|
// used to obtain any of the Class objects representing primitives or void
|
|
|
|
if ((obj != NULL) && !(java_lang_Class::is_primitive(obj))) {
|
|
|
|
instanceKlassHandle k =
|
|
|
|
instanceKlassHandle(THREAD, java_lang_Class::as_klassOop(obj));
|
|
|
|
// 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.
|
2011-01-27 16:11:27 -08:00
|
|
|
if (class_name == k->name()) {
|
2007-12-01 00:00:00 +00:00
|
|
|
return k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Class is not found or has the wrong name, return NULL
|
|
|
|
return nh;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::define_instance_class(instanceKlassHandle k, TRAPS) {
|
|
|
|
|
|
|
|
Handle class_loader_h(THREAD, k->class_loader());
|
|
|
|
|
2009-01-05 13:44:03 -05:00
|
|
|
// for bootstrap and other parallel classloaders don't acquire lock,
|
|
|
|
// use placeholder token
|
|
|
|
// 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
|
|
|
|
if (!class_loader_h.is_null() && !is_parallelCapable(class_loader_h)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(ObjectSynchronizer::current_thread_holds_lock((JavaThread*)THREAD,
|
|
|
|
compute_loader_lock_object(class_loader_h, THREAD)),
|
|
|
|
"define called without lock");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check class-loading constraints. Throw exception if violation is detected.
|
|
|
|
// Grabs and releases SystemDictionary_lock
|
|
|
|
// The check_constraints/find_class call and update_dictionary sequence
|
|
|
|
// must be "atomic" for a specific class/classloader pair so we never
|
|
|
|
// define two different instanceKlasses for that class/classloader pair.
|
|
|
|
// Existing classloaders will call define_instance_class with the
|
|
|
|
// classloader lock held
|
|
|
|
// Parallel classloaders will call find_or_define_instance_class
|
|
|
|
// which will require a token to perform the define class
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name_h = k->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader_h);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
check_constraints(d_index, d_hash, k, class_loader_h, true, CHECK);
|
|
|
|
|
|
|
|
// 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).
|
|
|
|
if (k->class_loader() != NULL) {
|
|
|
|
methodHandle m(THREAD, Universe::loader_addClass_method());
|
|
|
|
JavaValue result(T_VOID);
|
|
|
|
JavaCallArguments args(class_loader_h);
|
|
|
|
args.push_oop(Handle(THREAD, k->java_mirror()));
|
|
|
|
JavaCalls::call(&result, m, &args, CHECK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add the new class. We need recompile lock during update of CHA.
|
|
|
|
{
|
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader_h);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
|
|
|
|
MutexLocker mu_r(Compile_lock, THREAD);
|
|
|
|
|
|
|
|
// Add to class hierarchy, initialize vtables, and do possible
|
|
|
|
// deoptimizations.
|
|
|
|
add_to_hierarchy(k, CHECK); // No exception, but can block
|
|
|
|
|
|
|
|
// Add to systemDictionary - so other classes can see it.
|
|
|
|
// Grabs and releases SystemDictionary_lock
|
|
|
|
update_dictionary(d_index, d_hash, p_index, p_hash,
|
|
|
|
k, class_loader_h, THREAD);
|
|
|
|
}
|
|
|
|
k->eager_initialize(THREAD);
|
|
|
|
|
|
|
|
// notify jvmti
|
|
|
|
if (JvmtiExport::should_post_class_load()) {
|
|
|
|
assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
|
|
|
|
JvmtiExport::post_class_load((JavaThread *) THREAD, k());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Support parallel classloading
|
2009-11-11 15:49:38 -05:00
|
|
|
// All parallel class loaders, including bootstrap classloader
|
|
|
|
// lock a placeholder entry for this class/class_loader pair
|
|
|
|
// to allow parallel defines of different classes for this class loader
|
2009-01-05 13:44:03 -05:00
|
|
|
// With AllowParallelDefine flag==true, in case they do not synchronize around
|
|
|
|
// FindLoadedClass/DefineClass, calls, we check for parallel
|
2007-12-01 00:00:00 +00:00
|
|
|
// loading for them, wait if a defineClass is in progress
|
|
|
|
// and return the initial requestor's results
|
2009-11-11 15:49:38 -05:00
|
|
|
// This flag does not apply to the bootstrap classloader.
|
2009-01-05 13:44:03 -05:00
|
|
|
// With AllowParallelDefine flag==false, call through to define_instance_class
|
|
|
|
// which will throw LinkageError: duplicate class definition.
|
2009-11-11 15:49:38 -05:00
|
|
|
// False is the requested default.
|
2007-12-01 00:00:00 +00:00
|
|
|
// For better performance, the class loaders should synchronize
|
2009-01-05 13:44:03 -05:00
|
|
|
// findClass(), i.e. FindLoadedClass/DefineClassIfAbsent or they
|
2007-12-01 00:00:00 +00:00
|
|
|
// potentially waste time reading and parsing the bytestream.
|
|
|
|
// Note: VM callers should ensure consistency of k/class_name,class_loader
|
2011-01-27 16:11:27 -08:00
|
|
|
instanceKlassHandle SystemDictionary::find_or_define_instance_class(Symbol* class_name, Handle class_loader, instanceKlassHandle k, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
instanceKlassHandle nh = instanceKlassHandle(); // null Handle
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name_h = k->name(); // passed in class_name may be null
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2009-01-08 16:27:28 -05:00
|
|
|
unsigned int d_hash = dictionary()->compute_hash(name_h, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
|
|
|
|
|
|
|
// Hold SD lock around find_class and placeholder creation for DEFINE_CLASS
|
2009-01-08 16:27:28 -05:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(name_h, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
PlaceholderEntry* probe;
|
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// First check if class already defined
|
2009-11-11 15:49:38 -05:00
|
|
|
if (UnsyncloadClass || (is_parallelDefine(class_loader))) {
|
|
|
|
klassOop check = find_class(d_index, d_hash, name_h, class_loader);
|
|
|
|
if (check != NULL) {
|
|
|
|
return(instanceKlassHandle(THREAD, check));
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Acquire define token for this class/classloader
|
2011-01-27 16:11:27 -08:00
|
|
|
probe = placeholders()->find_and_add(p_index, p_hash, name_h, class_loader, PlaceholderTable::DEFINE_CLASS, NULL, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
// 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
|
|
|
|
while (probe->definer() != NULL) {
|
|
|
|
SystemDictionary_lock->wait();
|
|
|
|
}
|
|
|
|
// 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
|
2009-11-11 15:49:38 -05:00
|
|
|
if ((UnsyncloadClass || is_parallelDefine(class_loader)) && (probe->instanceKlass() != NULL)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
|
2009-01-08 16:27:28 -05:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
|
2009-01-05 13:44:03 -05:00
|
|
|
SystemDictionary_lock->notify_all();
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef ASSERT
|
2009-01-08 16:27:28 -05:00
|
|
|
klassOop check = find_class(d_index, d_hash, name_h, class_loader);
|
2009-01-05 13:44:03 -05:00
|
|
|
assert(check != NULL, "definer missed recording success");
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
2009-01-05 13:44:03 -05:00
|
|
|
return(instanceKlassHandle(THREAD, probe->instanceKlass()));
|
|
|
|
} else {
|
|
|
|
// This thread will define the class (even if earlier thread tried and had an error)
|
|
|
|
probe->set_definer(THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
define_instance_class(k, THREAD);
|
|
|
|
|
|
|
|
Handle linkage_exception = Handle(); // null handle
|
|
|
|
|
|
|
|
// definer must notify any waiting threads
|
|
|
|
{
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2009-01-08 16:27:28 -05:00
|
|
|
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
|
|
|
|
if (probe != NULL) {
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
linkage_exception = Handle(THREAD,PENDING_EXCEPTION);
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
|
|
|
} else {
|
|
|
|
probe->set_instanceKlass(k());
|
|
|
|
}
|
|
|
|
probe->set_definer(NULL);
|
|
|
|
probe->remove_seen_thread(THREAD, PlaceholderTable::DEFINE_CLASS);
|
2009-01-08 16:27:28 -05:00
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name_h, class_loader, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Can't throw exception while holding lock due to rank ordering
|
|
|
|
if (linkage_exception() != NULL) {
|
|
|
|
THROW_OOP_(linkage_exception(), nh); // throws exception and returns
|
|
|
|
}
|
|
|
|
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
Handle SystemDictionary::compute_loader_lock_object(Handle class_loader, TRAPS) {
|
|
|
|
// If class_loader is NULL we synchronize on _system_loader_lock_obj
|
|
|
|
if (class_loader.is_null()) {
|
|
|
|
return Handle(THREAD, _system_loader_lock_obj);
|
|
|
|
} else {
|
|
|
|
return class_loader;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
void SystemDictionary::check_loader_lock_contention(Handle loader_lock, TRAPS) {
|
|
|
|
if (!UsePerfData) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(!loader_lock.is_null(), "NULL lock object");
|
|
|
|
|
|
|
|
if (ObjectSynchronizer::query_lock_ownership((JavaThread*)THREAD, loader_lock)
|
|
|
|
== ObjectSynchronizer::owner_other) {
|
|
|
|
// contention will likely happen, so increment the corresponding
|
|
|
|
// contention counter.
|
|
|
|
if (loader_lock() == _system_loader_lock_obj) {
|
|
|
|
ClassLoader::sync_systemLoaderLockContentionRate()->inc();
|
|
|
|
} else {
|
|
|
|
ClassLoader::sync_nonSystemLoaderLockContentionRate()->inc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Lookup
|
|
|
|
|
|
|
|
klassOop SystemDictionary::find_class(int index, unsigned int hash,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader) {
|
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
assert (index == dictionary()->index_for(class_name, class_loader),
|
|
|
|
"incorrect index?");
|
|
|
|
|
|
|
|
klassOop k = dictionary()->find_class(index, hash, class_name, class_loader);
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Basic find on classes in the midst of being loaded
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* SystemDictionary::find_placeholder(Symbol* class_name,
|
|
|
|
Handle class_loader) {
|
2007-12-01 00:00:00 +00:00
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
2011-01-27 16:11:27 -08:00
|
|
|
unsigned int p_hash = placeholders()->compute_hash(class_name, class_loader);
|
|
|
|
int p_index = placeholders()->hash_to_index(p_hash);
|
|
|
|
return placeholders()->find_entry(p_index, p_hash, class_name, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Used for assertions and verification only
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop SystemDictionary::find_class(Symbol* class_name, Handle class_loader) {
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifndef ASSERT
|
|
|
|
guarantee(VerifyBeforeGC ||
|
|
|
|
VerifyDuringGC ||
|
|
|
|
VerifyBeforeExit ||
|
|
|
|
VerifyAfterGC, "too expensive");
|
|
|
|
#endif
|
|
|
|
assert_locked_or_safepoint(SystemDictionary_lock);
|
|
|
|
|
|
|
|
// First look in the loaded class array
|
|
|
|
unsigned int d_hash = dictionary()->compute_hash(class_name, class_loader);
|
|
|
|
int d_index = dictionary()->hash_to_index(d_hash);
|
2011-01-27 16:11:27 -08:00
|
|
|
return find_class(d_index, d_hash, class_name, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Get the next class in the diictionary.
|
|
|
|
klassOop SystemDictionary::try_get_next_class() {
|
|
|
|
return dictionary()->try_get_next_class();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
void SystemDictionary::add_to_hierarchy(instanceKlassHandle k, TRAPS) {
|
|
|
|
assert(k.not_null(), "just checking");
|
2011-01-31 17:48:21 -08:00
|
|
|
assert_locked_or_safepoint(Compile_lock);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Link into hierachy. Make sure the vtables are initialized before linking into
|
|
|
|
k->append_to_sibling_list(); // add to superklass/sibling list
|
|
|
|
k->process_interfaces(THREAD); // handle all "implements" declarations
|
|
|
|
k->set_init_state(instanceKlass::loaded);
|
|
|
|
// 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.
|
|
|
|
Universe::flush_dependents_on(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// GC support
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
void SystemDictionary::always_strong_oops_do(OopClosure* blk) {
|
|
|
|
// Follow preloaded classes/mirrors and system loader object
|
|
|
|
blk->do_oop(&_java_system_loader);
|
|
|
|
preloaded_oops_do(blk);
|
|
|
|
always_strong_classes_do(blk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::always_strong_classes_do(OopClosure* blk) {
|
|
|
|
// Follow all system classes and temporary placeholders in dictionary
|
|
|
|
dictionary()->always_strong_classes_do(blk);
|
|
|
|
|
|
|
|
// Placeholders. These are *always* strong roots, as they
|
|
|
|
// represent classes we're actively loading.
|
|
|
|
placeholders_do(blk);
|
|
|
|
|
2009-04-08 10:56:49 -07:00
|
|
|
// Visit extra methods
|
2010-10-19 02:52:57 -07:00
|
|
|
invoke_method_table()->oops_do(blk);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::placeholders_do(OopClosure* blk) {
|
|
|
|
placeholders()->oops_do(blk);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SystemDictionary::do_unloading(BoolObjectClosure* is_alive) {
|
|
|
|
bool result = dictionary()->do_unloading(is_alive);
|
|
|
|
constraints()->purge_loader_constraints(is_alive);
|
|
|
|
resolution_errors()->purge_resolution_errors(is_alive);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
// Universe::oops_do().
|
|
|
|
void SystemDictionary::oops_do(OopClosure* f) {
|
|
|
|
// Adjust preloaded classes and system loader object
|
|
|
|
f->do_oop(&_java_system_loader);
|
|
|
|
preloaded_oops_do(f);
|
|
|
|
|
|
|
|
lazily_loaded_oops_do(f);
|
|
|
|
|
|
|
|
// Adjust dictionary
|
|
|
|
dictionary()->oops_do(f);
|
|
|
|
|
2009-04-08 10:56:49 -07:00
|
|
|
// Visit extra methods
|
2010-10-19 02:52:57 -07:00
|
|
|
invoke_method_table()->oops_do(f);
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// Partially loaded classes
|
|
|
|
placeholders()->oops_do(f);
|
|
|
|
|
|
|
|
// Adjust constraint table
|
|
|
|
constraints()->oops_do(f);
|
|
|
|
|
|
|
|
// Adjust resolution error table
|
|
|
|
resolution_errors()->oops_do(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::preloaded_oops_do(OopClosure* f) {
|
2008-04-29 19:45:22 -07:00
|
|
|
for (int k = (int)FIRST_WKID; k < (int)WKID_LIMIT; k++) {
|
|
|
|
f->do_oop((oop*) &_well_known_klasses[k]);
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < T_VOID+1; i++) {
|
|
|
|
if (_box_klasses[i] != NULL) {
|
|
|
|
assert(i >= T_BOOLEAN, "checking");
|
|
|
|
f->do_oop((oop*) &_box_klasses[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.
|
|
|
|
|
|
|
|
f->do_oop((oop*) &_system_loader_lock_obj);
|
|
|
|
FilteredFieldsMap::klasses_oops_do(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::lazily_loaded_oops_do(OopClosure* f) {
|
|
|
|
f->do_oop((oop*) &_abstract_ownable_synchronizer_klass);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Just the classes from defining class loaders
|
|
|
|
// Don't iterate over placeholders
|
|
|
|
void SystemDictionary::classes_do(void f(klassOop)) {
|
|
|
|
dictionary()->classes_do(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Added for initialize_itable_for_klass
|
|
|
|
// Just the classes from defining class loaders
|
|
|
|
// Don't iterate over placeholders
|
|
|
|
void SystemDictionary::classes_do(void f(klassOop, TRAPS), TRAPS) {
|
|
|
|
dictionary()->classes_do(f, CHECK);
|
|
|
|
}
|
|
|
|
|
|
|
|
// All classes, and their class loaders
|
|
|
|
// Don't iterate over placeholders
|
|
|
|
void SystemDictionary::classes_do(void f(klassOop, oop)) {
|
|
|
|
dictionary()->classes_do(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
// All classes, and their class loaders
|
|
|
|
// (added for helpers that use HandleMarks and ResourceMarks)
|
|
|
|
// Don't iterate over placeholders
|
|
|
|
void SystemDictionary::classes_do(void f(klassOop, oop, TRAPS), TRAPS) {
|
|
|
|
dictionary()->classes_do(f, CHECK);
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
void SystemDictionary::placeholders_do(void f(Symbol*, oop)) {
|
2007-12-01 00:00:00 +00:00
|
|
|
placeholders()->entries_do(f);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::methods_do(void f(methodOop)) {
|
|
|
|
dictionary()->methods_do(f);
|
2010-10-19 02:52:57 -07:00
|
|
|
invoke_method_table()->methods_do(f);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Lazily load klasses
|
|
|
|
|
|
|
|
void SystemDictionary::load_abstract_ownable_synchronizer_klass(TRAPS) {
|
|
|
|
assert(JDK_Version::is_gte_jdk16x_version(), "Must be JDK 1.6 or later");
|
|
|
|
|
|
|
|
// if multiple threads calling this function, only one thread will load
|
|
|
|
// the class. The other threads will find the loaded version once the
|
|
|
|
// class is loaded.
|
|
|
|
klassOop aos = _abstract_ownable_synchronizer_klass;
|
|
|
|
if (aos == NULL) {
|
2011-01-27 16:11:27 -08:00
|
|
|
klassOop k = resolve_or_fail(vmSymbols::java_util_concurrent_locks_AbstractOwnableSynchronizer(), true, CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
// Force a fence to prevent any read before the write completes
|
|
|
|
OrderAccess::fence();
|
|
|
|
_abstract_ownable_synchronizer_klass = k;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// Initialization
|
|
|
|
|
|
|
|
void SystemDictionary::initialize(TRAPS) {
|
|
|
|
// Allocate arrays
|
|
|
|
assert(dictionary() == NULL,
|
|
|
|
"SystemDictionary should only be initialized once");
|
2010-10-19 02:52:57 -07:00
|
|
|
_dictionary = new Dictionary(_nof_buckets);
|
|
|
|
_placeholders = new PlaceholderTable(_nof_buckets);
|
2007-12-01 00:00:00 +00:00
|
|
|
_number_of_modifications = 0;
|
2010-10-19 02:52:57 -07:00
|
|
|
_loader_constraints = new LoaderConstraintTable(_loader_constraint_size);
|
|
|
|
_resolution_errors = new ResolutionErrorTable(_resolution_error_size);
|
|
|
|
_invoke_method_table = new SymbolPropertyTable(_invoke_method_size);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Allocate private object used as system class loader lock
|
|
|
|
_system_loader_lock_obj = oopFactory::new_system_objArray(0, CHECK);
|
|
|
|
// Initialize basic classes
|
|
|
|
initialize_preloaded_classes(CHECK);
|
|
|
|
}
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// Compact table of directions on the initialization of klasses:
|
|
|
|
static const short wk_init_info[] = {
|
|
|
|
#define WK_KLASS_INIT_INFO(name, symbol, option) \
|
|
|
|
( ((int)vmSymbols::VM_SYMBOL_ENUM_NAME(symbol) \
|
|
|
|
<< SystemDictionary::CEIL_LG_OPTION_LIMIT) \
|
|
|
|
| (int)SystemDictionary::option ),
|
|
|
|
WK_KLASSES_DO(WK_KLASS_INIT_INFO)
|
|
|
|
#undef WK_KLASS_INIT_INFO
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2011-03-11 22:33:47 -08:00
|
|
|
Symbol* SystemDictionary::find_backup_symbol(Symbol* symbol,
|
|
|
|
const char* from_prefix,
|
|
|
|
const char* to_prefix) {
|
|
|
|
assert(AllowTransitionalJSR292, ""); // delete this subroutine
|
|
|
|
Symbol* backup_symbol = NULL;
|
|
|
|
size_t from_len = strlen(from_prefix);
|
|
|
|
if (strncmp((const char*) symbol->base(), from_prefix, from_len) != 0)
|
|
|
|
return NULL;
|
|
|
|
char buf[100];
|
|
|
|
size_t to_len = strlen(to_prefix);
|
|
|
|
size_t tail_len = symbol->utf8_length() - from_len;
|
|
|
|
size_t new_len = to_len + tail_len;
|
|
|
|
guarantee(new_len < sizeof(buf), "buf too small");
|
|
|
|
memcpy(buf, to_prefix, to_len);
|
|
|
|
memcpy(buf + to_len, symbol->base() + from_len, tail_len);
|
|
|
|
buf[new_len] = '\0';
|
|
|
|
vmSymbols::SID backup_sid = vmSymbols::find_sid(buf);
|
|
|
|
if (backup_sid != vmSymbols::NO_SID) {
|
|
|
|
backup_symbol = vmSymbols::symbol_at(backup_sid);
|
|
|
|
}
|
|
|
|
return backup_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol* SystemDictionary::find_backup_class_name(Symbol* symbol) {
|
|
|
|
assert(AllowTransitionalJSR292, ""); // delete this subroutine
|
|
|
|
if (symbol == NULL) return NULL;
|
|
|
|
Symbol* backup_symbol = find_backup_symbol(symbol, "java/lang/invoke/", "java/dyn/"); // AllowTransitionalJSR292 ONLY
|
|
|
|
if (backup_symbol == NULL)
|
|
|
|
backup_symbol = find_backup_symbol(symbol, "java/dyn/", "sun/dyn/"); // AllowTransitionalJSR292 ONLY
|
|
|
|
return backup_symbol;
|
|
|
|
}
|
|
|
|
|
|
|
|
Symbol* SystemDictionary::find_backup_signature(Symbol* symbol) {
|
|
|
|
assert(AllowTransitionalJSR292, ""); // delete this subroutine
|
|
|
|
if (symbol == NULL) return NULL;
|
|
|
|
return find_backup_symbol(symbol, "Ljava/lang/invoke/", "Ljava/dyn/");
|
|
|
|
}
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
bool SystemDictionary::initialize_wk_klass(WKID id, int init_opt, TRAPS) {
|
|
|
|
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|
|
|
|
int info = wk_init_info[id - FIRST_WKID];
|
|
|
|
int sid = (info >> CEIL_LG_OPTION_LIMIT);
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* symbol = vmSymbols::symbol_at((vmSymbols::SID)sid);
|
2008-04-29 19:45:22 -07:00
|
|
|
klassOop* klassp = &_well_known_klasses[id];
|
2011-03-11 22:33:47 -08:00
|
|
|
bool pre_load = (init_opt < SystemDictionary::Opt);
|
|
|
|
bool try_load = true;
|
2008-04-29 19:45:22 -07:00
|
|
|
if (init_opt == SystemDictionary::Opt_Kernel) {
|
|
|
|
#ifndef KERNEL
|
|
|
|
try_load = false;
|
|
|
|
#endif //KERNEL
|
|
|
|
}
|
2011-03-11 22:33:47 -08:00
|
|
|
Symbol* backup_symbol = NULL; // symbol to try if the current symbol fails
|
|
|
|
if (init_opt == SystemDictionary::Pre_JSR292) {
|
2011-03-31 02:31:57 -07:00
|
|
|
if (!EnableInvokeDynamic) try_load = false; // do not bother to load such classes
|
2011-03-11 22:33:47 -08:00
|
|
|
if (AllowTransitionalJSR292) {
|
|
|
|
backup_symbol = find_backup_class_name(symbol);
|
|
|
|
if (try_load && PreferTransitionalJSR292) {
|
|
|
|
while (backup_symbol != NULL) {
|
|
|
|
(*klassp) = resolve_or_null(backup_symbol, CHECK_0); // try backup early
|
|
|
|
if (TraceMethodHandles) {
|
|
|
|
ResourceMark rm;
|
|
|
|
tty->print_cr("MethodHandles: try backup first for %s => %s (%s)",
|
|
|
|
symbol->as_C_string(), backup_symbol->as_C_string(),
|
|
|
|
((*klassp) == NULL) ? "no such class" : "backup load succeeded");
|
|
|
|
}
|
|
|
|
if ((*klassp) != NULL) return true;
|
|
|
|
backup_symbol = find_backup_class_name(backup_symbol); // find next backup
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if ((*klassp) != NULL) return true;
|
|
|
|
if (!try_load) return false;
|
|
|
|
while (symbol != NULL) {
|
|
|
|
bool must_load = (pre_load && (backup_symbol == NULL));
|
2008-04-29 19:45:22 -07:00
|
|
|
if (must_load) {
|
|
|
|
(*klassp) = resolve_or_fail(symbol, true, CHECK_0); // load required class
|
|
|
|
} else {
|
|
|
|
(*klassp) = resolve_or_null(symbol, CHECK_0); // load optional klass
|
|
|
|
}
|
2011-03-11 22:33:47 -08:00
|
|
|
if ((*klassp) != NULL) return true;
|
|
|
|
// Go around again. Example of long backup sequence:
|
|
|
|
// java.lang.invoke.MemberName, java.dyn.MemberName, sun.dyn.MemberName, ONLY if AllowTransitionalJSR292
|
|
|
|
if (TraceMethodHandles && (backup_symbol != NULL)) {
|
|
|
|
ResourceMark rm;
|
|
|
|
tty->print_cr("MethodHandles: backup for %s => %s",
|
|
|
|
symbol->as_C_string(), backup_symbol->as_C_string());
|
|
|
|
}
|
|
|
|
symbol = backup_symbol;
|
|
|
|
if (AllowTransitionalJSR292)
|
|
|
|
backup_symbol = find_backup_class_name(symbol);
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
2011-03-11 22:33:47 -08:00
|
|
|
return false;
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void SystemDictionary::initialize_wk_klasses_until(WKID limit_id, WKID &start_id, TRAPS) {
|
|
|
|
assert((int)start_id <= (int)limit_id, "IDs are out of order!");
|
|
|
|
for (int id = (int)start_id; id < (int)limit_id; id++) {
|
|
|
|
assert(id >= (int)FIRST_WKID && id < (int)WKID_LIMIT, "oob");
|
|
|
|
int info = wk_init_info[id - FIRST_WKID];
|
|
|
|
int sid = (info >> CEIL_LG_OPTION_LIMIT);
|
|
|
|
int opt = (info & right_n_bits(CEIL_LG_OPTION_LIMIT));
|
|
|
|
|
|
|
|
initialize_wk_klass((WKID)id, opt, CHECK);
|
|
|
|
|
|
|
|
// Update limits, so find_well_known_klass can be very fast:
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* s = vmSymbols::symbol_at((vmSymbols::SID)sid);
|
2008-04-29 19:45:22 -07:00
|
|
|
if (wk_klass_name_limits[1] == NULL) {
|
|
|
|
wk_klass_name_limits[0] = wk_klass_name_limits[1] = s;
|
|
|
|
} else if (wk_klass_name_limits[1] < s) {
|
|
|
|
wk_klass_name_limits[1] = s;
|
|
|
|
} else if (wk_klass_name_limits[0] > s) {
|
|
|
|
wk_klass_name_limits[0] = s;
|
|
|
|
}
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
|
|
|
// move the starting value forward to the limit:
|
|
|
|
start_id = limit_id;
|
2008-04-29 19:45:22 -07:00
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
void SystemDictionary::initialize_preloaded_classes(TRAPS) {
|
2010-01-06 14:22:39 -08:00
|
|
|
assert(WK_KLASS(Object_klass) == NULL, "preloaded classes should only be initialized once");
|
2007-12-01 00:00:00 +00:00
|
|
|
// Preload commonly used klasses
|
2008-04-29 19:45:22 -07:00
|
|
|
WKID scan = FIRST_WKID;
|
|
|
|
// first do Object, String, Class
|
2010-01-06 14:22:39 -08:00
|
|
|
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Class_klass), scan, CHECK);
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
debug_only(instanceKlass::verify_class_klass_nonstatic_oop_maps(WK_KLASS(Class_klass)));
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
|
|
|
// in the perm gen.
|
|
|
|
Universe::initialize_basic_type_mirrors(CHECK);
|
|
|
|
Universe::fixup_mirrors(CHECK);
|
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
// do a bunch more:
|
2010-01-06 14:22:39 -08:00
|
|
|
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(Reference_klass), scan, CHECK);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// Preload ref klasses and set reference types
|
2010-01-06 14:22:39 -08:00
|
|
|
instanceKlass::cast(WK_KLASS(Reference_klass))->set_reference_type(REF_OTHER);
|
|
|
|
instanceRefKlass::update_nonstatic_oop_maps(WK_KLASS(Reference_klass));
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
initialize_wk_klasses_through(WK_KLASS_ENUM_NAME(PhantomReference_klass), scan, CHECK);
|
|
|
|
instanceKlass::cast(WK_KLASS(SoftReference_klass))->set_reference_type(REF_SOFT);
|
|
|
|
instanceKlass::cast(WK_KLASS(WeakReference_klass))->set_reference_type(REF_WEAK);
|
|
|
|
instanceKlass::cast(WK_KLASS(FinalReference_klass))->set_reference_type(REF_FINAL);
|
|
|
|
instanceKlass::cast(WK_KLASS(PhantomReference_klass))->set_reference_type(REF_PHANTOM);
|
2008-04-29 19:45:22 -07:00
|
|
|
|
2011-03-31 02:31:57 -07:00
|
|
|
// JSR 292 classes
|
|
|
|
WKID jsr292_group_start = WK_KLASS_ENUM_NAME(MethodHandle_klass);
|
|
|
|
WKID jsr292_group_end = WK_KLASS_ENUM_NAME(CallSite_klass);
|
|
|
|
initialize_wk_klasses_until(jsr292_group_start, scan, CHECK);
|
2009-04-21 23:21:04 -07:00
|
|
|
if (EnableInvokeDynamic) {
|
2011-03-31 02:31:57 -07:00
|
|
|
initialize_wk_klasses_through(jsr292_group_end, scan, CHECK);
|
|
|
|
} else {
|
|
|
|
// Skip the JSR 292 classes, if not enabled.
|
|
|
|
scan = WKID(jsr292_group_end + 1);
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2008-04-29 19:45:22 -07:00
|
|
|
initialize_wk_klasses_until(WKID_LIMIT, scan, CHECK);
|
|
|
|
|
2010-01-06 14:22:39 -08:00
|
|
|
_box_klasses[T_BOOLEAN] = WK_KLASS(Boolean_klass);
|
|
|
|
_box_klasses[T_CHAR] = WK_KLASS(Character_klass);
|
|
|
|
_box_klasses[T_FLOAT] = WK_KLASS(Float_klass);
|
|
|
|
_box_klasses[T_DOUBLE] = WK_KLASS(Double_klass);
|
|
|
|
_box_klasses[T_BYTE] = WK_KLASS(Byte_klass);
|
|
|
|
_box_klasses[T_SHORT] = WK_KLASS(Short_klass);
|
|
|
|
_box_klasses[T_INT] = WK_KLASS(Integer_klass);
|
|
|
|
_box_klasses[T_LONG] = WK_KLASS(Long_klass);
|
2008-04-29 19:45:22 -07:00
|
|
|
//_box_klasses[T_OBJECT] = WK_KLASS(object_klass);
|
|
|
|
//_box_klasses[T_ARRAY] = WK_KLASS(object_klass);
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
#ifdef KERNEL
|
2008-04-29 19:45:22 -07:00
|
|
|
if (sun_jkernel_DownloadManager_klass() == NULL) {
|
2007-12-01 00:00:00 +00:00
|
|
|
warning("Cannot find sun/jkernel/DownloadManager");
|
|
|
|
}
|
|
|
|
#endif // KERNEL
|
2009-01-05 13:44:03 -05:00
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
{ // Compute whether we should use loadClass or loadClassInternal when loading classes.
|
2010-01-06 14:22:39 -08:00
|
|
|
methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::loadClassInternal_name(), vmSymbols::string_class_signature());
|
2007-12-01 00:00:00 +00:00
|
|
|
_has_loadClassInternal = (method != NULL);
|
|
|
|
}
|
|
|
|
{ // Compute whether we should use checkPackageAccess or NOT
|
2010-01-06 14:22:39 -08:00
|
|
|
methodOop method = instanceKlass::cast(ClassLoader_klass())->find_method(vmSymbols::checkPackageAccess_name(), vmSymbols::class_protectiondomain_signature());
|
2007-12-01 00:00:00 +00:00
|
|
|
_has_checkPackageAccess = (method != NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
BasicType SystemDictionary::box_klass_type(klassOop k) {
|
|
|
|
assert(k != NULL, "");
|
|
|
|
for (int i = T_BOOLEAN; i < T_VOID+1; i++) {
|
|
|
|
if (_box_klasses[i] == k)
|
|
|
|
return (BasicType)i;
|
|
|
|
}
|
|
|
|
return T_OBJECT;
|
|
|
|
}
|
|
|
|
|
2009-03-20 23:19:36 -07:00
|
|
|
KlassHandle SystemDictionaryHandles::box_klass(BasicType t) {
|
|
|
|
if (t >= T_BOOLEAN && t <= T_VOID)
|
|
|
|
return KlassHandle(&SystemDictionary::_box_klasses[t], true);
|
|
|
|
else
|
|
|
|
return KlassHandle();
|
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
void SystemDictionary::check_constraints(int d_index, unsigned int d_hash,
|
|
|
|
instanceKlassHandle k,
|
|
|
|
Handle class_loader, bool defining,
|
|
|
|
TRAPS) {
|
|
|
|
const char *linkage_error = NULL;
|
|
|
|
{
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name = k->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
|
|
|
|
klassOop check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (check != (klassOop)NULL) {
|
|
|
|
// 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
|
|
|
|
|
|
|
|
assert(check->klass_part()->oop_is_instance(), "noninstance in systemdictionary");
|
|
|
|
if ((defining == true) || (k() != check)) {
|
|
|
|
linkage_error = "loader (instance of %s): attempted duplicate class "
|
|
|
|
"definition for name: \"%s\"";
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ASSERT
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* ph_check = find_placeholder(name, class_loader);
|
|
|
|
assert(ph_check == NULL || ph_check == name, "invalid symbol");
|
2007-12-01 00:00:00 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (linkage_error == NULL) {
|
|
|
|
if (constraints()->check_or_update(k, class_loader, name) == false) {
|
|
|
|
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)
|
|
|
|
|
|
|
|
if (linkage_error) {
|
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
const char* class_loader_name = loader_name(class_loader());
|
|
|
|
char* type_name = k->name()->as_C_string();
|
|
|
|
size_t buflen = strlen(linkage_error) + strlen(class_loader_name) +
|
|
|
|
strlen(type_name);
|
|
|
|
char* buf = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, buflen);
|
|
|
|
jio_snprintf(buf, buflen, linkage_error, class_loader_name, type_name);
|
|
|
|
THROW_MSG(vmSymbols::java_lang_LinkageError(), buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Update system dictionary - done after check_constraint and add_to_hierachy
|
|
|
|
// have been called.
|
|
|
|
void SystemDictionary::update_dictionary(int d_index, unsigned int d_hash,
|
|
|
|
int p_index, unsigned int p_hash,
|
|
|
|
instanceKlassHandle k,
|
|
|
|
Handle class_loader,
|
|
|
|
TRAPS) {
|
|
|
|
// Compile_lock prevents systemDictionary updates during compilations
|
|
|
|
assert_locked_or_safepoint(Compile_lock);
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name = k->name();
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
MutexLocker mu1(SystemDictionary_lock, THREAD);
|
|
|
|
|
|
|
|
// See whether biased locking is enabled and if so set it for this
|
|
|
|
// klass.
|
|
|
|
// 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().
|
|
|
|
if (UseBiasedLocking && 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
|
|
|
|
if (k->class_loader() == class_loader()) {
|
|
|
|
k->set_prototype_header(markOopDesc::biased_locking_prototype());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for a placeholder. If there, remove it and make a
|
|
|
|
// new system dictionary entry.
|
|
|
|
placeholders()->find_and_remove(p_index, p_hash, name, class_loader, THREAD);
|
|
|
|
klassOop sd_check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
if (sd_check == NULL) {
|
|
|
|
dictionary()->add_klass(name, class_loader, k);
|
|
|
|
notice_modification();
|
|
|
|
}
|
|
|
|
#ifdef ASSERT
|
|
|
|
sd_check = find_class(d_index, d_hash, name, class_loader);
|
|
|
|
assert (sd_check != NULL, "should have entry in system dictionary");
|
|
|
|
// 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
|
2011-01-27 16:11:27 -08:00
|
|
|
// Symbol* ph_check = find_placeholder(name, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
// assert (ph_check == NULL, "should not have a placeholder entry");
|
|
|
|
#endif
|
|
|
|
SystemDictionary_lock->notify_all();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-31 17:48:21 -08:00
|
|
|
// 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.
|
2007-12-01 00:00:00 +00:00
|
|
|
klassOop SystemDictionary::find_constrained_instance_or_array_klass(
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name, Handle class_loader, TRAPS) {
|
2007-12-01 00:00:00 +00:00
|
|
|
|
|
|
|
// First see if it has been loaded directly.
|
|
|
|
// Force the protection domain to be null. (This removes protection checks.)
|
|
|
|
Handle no_protection_domain;
|
|
|
|
klassOop klass = find_instance_or_array_klass(class_name, class_loader,
|
|
|
|
no_protection_domain, CHECK_NULL);
|
|
|
|
if (klass != NULL)
|
|
|
|
return klass;
|
|
|
|
|
|
|
|
// 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.
|
2011-01-27 16:11:27 -08:00
|
|
|
if (FieldType::is_array(class_name)) {
|
2010-01-19 16:03:09 -05:00
|
|
|
// For array classes, their klassOops are not kept in the
|
|
|
|
// constraint table. The element klassOops are.
|
2011-01-27 16:11:27 -08:00
|
|
|
FieldArrayInfo fd;
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(NULL));
|
2007-12-01 00:00:00 +00:00
|
|
|
if (t != T_OBJECT) {
|
|
|
|
klass = Universe::typeArrayKlassObj(t);
|
|
|
|
} else {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
2011-01-27 16:11:27 -08:00
|
|
|
klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2010-01-19 16:03:09 -05:00
|
|
|
// If element class already loaded, allocate array klass
|
2007-12-01 00:00:00 +00:00
|
|
|
if (klass != NULL) {
|
2011-01-27 16:11:27 -08:00
|
|
|
klass = Klass::cast(klass)->array_klass_or_null(fd.dimension());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MutexLocker mu(SystemDictionary_lock, THREAD);
|
|
|
|
// Non-array classes are easy: simply check the constraint table.
|
|
|
|
klass = constraints()->find_constrained_klass(class_name, class_loader);
|
|
|
|
}
|
|
|
|
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
bool SystemDictionary::add_loader_constraint(Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader1,
|
|
|
|
Handle class_loader2,
|
|
|
|
Thread* THREAD) {
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* constraint_name = NULL;
|
|
|
|
if (!FieldType::is_array(class_name)) {
|
2010-01-19 16:03:09 -05:00
|
|
|
constraint_name = class_name;
|
|
|
|
} else {
|
|
|
|
// For array classes, their klassOops are not kept in the
|
|
|
|
// constraint table. The element classes are.
|
2011-01-27 16:11:27 -08:00
|
|
|
FieldArrayInfo fd;
|
|
|
|
BasicType t = FieldType::get_array_info(class_name, fd, CHECK_(false));
|
2010-01-19 16:03:09 -05:00
|
|
|
// primitive types always pass
|
|
|
|
if (t != T_OBJECT) {
|
|
|
|
return true;
|
|
|
|
} else {
|
2011-01-27 16:11:27 -08:00
|
|
|
constraint_name = fd.object_key();
|
2010-01-19 16:03:09 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
unsigned int d_hash1 = dictionary()->compute_hash(constraint_name, class_loader1);
|
2007-12-01 00:00:00 +00:00
|
|
|
int d_index1 = dictionary()->hash_to_index(d_hash1);
|
|
|
|
|
2010-01-19 16:03:09 -05:00
|
|
|
unsigned int d_hash2 = dictionary()->compute_hash(constraint_name, class_loader2);
|
2007-12-01 00:00:00 +00:00
|
|
|
int d_index2 = dictionary()->hash_to_index(d_hash2);
|
|
|
|
{
|
2010-01-19 16:03:09 -05:00
|
|
|
MutexLocker mu_s(SystemDictionary_lock, THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-01-19 16:03:09 -05:00
|
|
|
// Better never do a GC while we're holding these oops
|
|
|
|
No_Safepoint_Verifier nosafepoint;
|
2007-12-01 00:00:00 +00:00
|
|
|
|
2010-01-19 16:03:09 -05:00
|
|
|
klassOop klass1 = find_class(d_index1, d_hash1, constraint_name, class_loader1);
|
|
|
|
klassOop klass2 = find_class(d_index2, d_hash2, constraint_name, class_loader2);
|
|
|
|
return constraints()->add_entry(constraint_name, klass1, class_loader1,
|
|
|
|
klass2, class_loader2);
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add entry to resolution error table to record the error when the first
|
|
|
|
// attempt to resolve a reference to a class has failed.
|
2011-01-27 16:11:27 -08:00
|
|
|
void SystemDictionary::add_resolution_error(constantPoolHandle pool, int which, Symbol* error) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int hash = resolution_errors()->compute_hash(pool, which);
|
|
|
|
int index = resolution_errors()->hash_to_index(hash);
|
|
|
|
{
|
|
|
|
MutexLocker ml(SystemDictionary_lock, Thread::current());
|
|
|
|
resolution_errors()->add_entry(index, hash, pool, which, error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lookup resolution error table. Returns error if found, otherwise NULL.
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* SystemDictionary::find_resolution_error(constantPoolHandle pool, int which) {
|
2007-12-01 00:00:00 +00:00
|
|
|
unsigned int hash = resolution_errors()->compute_hash(pool, which);
|
|
|
|
int index = resolution_errors()->hash_to_index(hash);
|
|
|
|
{
|
|
|
|
MutexLocker ml(SystemDictionary_lock, Thread::current());
|
|
|
|
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
|
2011-01-27 16:11:27 -08:00
|
|
|
return (entry != NULL) ? entry->error() : (Symbol*)NULL;
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-20 23:19:36 -07:00
|
|
|
// 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
|
|
|
|
// method's signature.
|
|
|
|
//
|
|
|
|
// * LinkResolver::resolve_interface_method performs exactly the same
|
|
|
|
// checks.
|
|
|
|
//
|
|
|
|
// * 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)
|
|
|
|
//
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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
|
2009-03-20 23:19:36 -07:00
|
|
|
// with a ResourceMark in the caller. No exception except OOME is thrown.
|
2010-01-19 16:03:09 -05:00
|
|
|
// Arrays are not added to the loader constraint table, their elements are.
|
2011-01-27 16:11:27 -08:00
|
|
|
char* SystemDictionary::check_signature_loaders(Symbol* signature,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle loader1, Handle loader2,
|
|
|
|
bool is_method, TRAPS) {
|
|
|
|
// Nothing to do if loaders are the same.
|
|
|
|
if (loader1() == loader2()) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
ResourceMark rm(THREAD);
|
2007-12-01 00:00:00 +00:00
|
|
|
SignatureStream sig_strm(signature, is_method);
|
|
|
|
while (!sig_strm.is_done()) {
|
|
|
|
if (sig_strm.is_object()) {
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* s = sig_strm.as_symbol(CHECK_NULL);
|
|
|
|
Symbol* sig = s;
|
2007-12-01 00:00:00 +00:00
|
|
|
if (!add_loader_constraint(sig, loader1, loader2, THREAD)) {
|
2011-01-27 16:11:27 -08:00
|
|
|
return sig->as_C_string();
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
sig_strm.next();
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-01-27 16:11:27 -08:00
|
|
|
methodOop SystemDictionary::find_method_handle_invoke(Symbol* name,
|
|
|
|
Symbol* signature,
|
2010-05-01 21:57:35 -07:00
|
|
|
KlassHandle accessing_klass,
|
2009-04-08 10:56:49 -07:00
|
|
|
TRAPS) {
|
2011-03-31 02:31:57 -07:00
|
|
|
if (!EnableInvokeDynamic) return NULL;
|
2011-01-27 16:11:27 -08:00
|
|
|
vmSymbols::SID name_id = vmSymbols::find_sid(name);
|
2010-05-01 02:42:18 -07:00
|
|
|
assert(name_id != vmSymbols::NO_SID, "must be a known name");
|
|
|
|
unsigned int hash = invoke_method_table()->compute_hash(signature, name_id);
|
2009-04-08 10:56:49 -07:00
|
|
|
int index = invoke_method_table()->hash_to_index(hash);
|
2010-05-01 02:42:18 -07:00
|
|
|
SymbolPropertyEntry* spe = invoke_method_table()->find_entry(index, hash, signature, name_id);
|
2010-05-01 21:57:35 -07:00
|
|
|
methodHandle non_cached_result;
|
2009-04-08 10:56:49 -07:00
|
|
|
if (spe == NULL || spe->property_oop() == NULL) {
|
2010-05-01 21:57:35 -07:00
|
|
|
spe = NULL;
|
2009-04-08 10:56:49 -07:00
|
|
|
// Must create lots of stuff here, but outside of the SystemDictionary lock.
|
2010-01-04 18:38:08 +01:00
|
|
|
if (THREAD->is_Compiler_thread())
|
|
|
|
return NULL; // do not attempt from within compiler
|
2010-09-13 23:24:30 -07:00
|
|
|
bool for_invokeGeneric = (name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invokeGeneric_name));
|
2011-03-11 22:33:47 -08:00
|
|
|
if (AllowInvokeForInvokeGeneric && name_id == vmSymbols::VM_SYMBOL_ENUM_NAME(invoke_name))
|
|
|
|
for_invokeGeneric = true;
|
2010-05-01 21:57:35 -07:00
|
|
|
bool found_on_bcp = false;
|
2011-01-27 16:11:27 -08:00
|
|
|
Handle mt = find_method_handle_type(signature, accessing_klass,
|
2010-09-13 23:24:30 -07:00
|
|
|
for_invokeGeneric,
|
|
|
|
found_on_bcp, CHECK_NULL);
|
2009-04-08 10:56:49 -07:00
|
|
|
KlassHandle mh_klass = SystemDictionaryHandles::MethodHandle_klass();
|
2010-05-01 02:42:18 -07:00
|
|
|
methodHandle m = methodOopDesc::make_invoke_method(mh_klass, name, signature,
|
2009-04-08 10:56:49 -07:00
|
|
|
mt, CHECK_NULL);
|
|
|
|
// 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.
|
2010-05-01 21:57:35 -07:00
|
|
|
if (found_on_bcp) {
|
2009-04-08 10:56:49 -07:00
|
|
|
MutexLocker ml(SystemDictionary_lock, Thread::current());
|
2010-05-01 02:42:18 -07:00
|
|
|
spe = invoke_method_table()->find_entry(index, hash, signature, name_id);
|
2009-04-08 10:56:49 -07:00
|
|
|
if (spe == NULL)
|
2010-05-01 02:42:18 -07:00
|
|
|
spe = invoke_method_table()->add_entry(index, hash, signature, name_id);
|
2009-04-08 10:56:49 -07:00
|
|
|
if (spe->property_oop() == NULL)
|
|
|
|
spe->set_property_oop(m());
|
2010-05-01 21:57:35 -07:00
|
|
|
} else {
|
|
|
|
non_cached_result = m;
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
}
|
2010-05-01 21:57:35 -07:00
|
|
|
if (spe != NULL && spe->property_oop() != NULL) {
|
|
|
|
assert(spe->property_oop()->is_method(), "");
|
|
|
|
return (methodOop) spe->property_oop();
|
|
|
|
} else {
|
|
|
|
return non_cached_result();
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// Ask Java code to find or construct a java.lang.invoke.MethodType for the given
|
2009-04-08 10:56:49 -07:00
|
|
|
// signature, as interpreted relative to the given class loader.
|
|
|
|
// Because of class loader constraints, all method handle usage must be
|
|
|
|
// consistent with this loader.
|
2011-01-27 16:11:27 -08:00
|
|
|
Handle SystemDictionary::find_method_handle_type(Symbol* signature,
|
2010-05-01 21:57:35 -07:00
|
|
|
KlassHandle accessing_klass,
|
2010-09-13 23:24:30 -07:00
|
|
|
bool for_invokeGeneric,
|
2010-05-01 21:57:35 -07:00
|
|
|
bool& return_bcp_flag,
|
2010-05-01 02:42:18 -07:00
|
|
|
TRAPS) {
|
2010-05-01 21:57:35 -07:00
|
|
|
Handle class_loader, protection_domain;
|
|
|
|
bool is_on_bcp = true; // keep this true as long as we can materialize from the boot classloader
|
2009-04-08 10:56:49 -07:00
|
|
|
Handle empty;
|
2011-01-27 16:11:27 -08:00
|
|
|
int npts = ArgumentCount(signature).size();
|
2010-01-06 14:22:39 -08:00
|
|
|
objArrayHandle pts = oopFactory::new_objArray(SystemDictionary::Class_klass(), npts, CHECK_(empty));
|
2009-04-08 10:56:49 -07:00
|
|
|
int arg = 0;
|
|
|
|
Handle rt; // the return type from the signature
|
2011-01-27 16:11:27 -08:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
for (SignatureStream ss(signature); !ss.is_done(); ss.next()) {
|
2010-05-01 21:57:35 -07:00
|
|
|
oop mirror = NULL;
|
|
|
|
if (is_on_bcp) {
|
|
|
|
mirror = ss.as_java_mirror(class_loader, protection_domain,
|
|
|
|
SignatureStream::ReturnNull, CHECK_(empty));
|
|
|
|
if (mirror == NULL) {
|
|
|
|
// fall back from BCP to accessing_klass
|
|
|
|
if (accessing_klass.not_null()) {
|
|
|
|
class_loader = Handle(THREAD, instanceKlass::cast(accessing_klass())->class_loader());
|
|
|
|
protection_domain = Handle(THREAD, instanceKlass::cast(accessing_klass())->protection_domain());
|
|
|
|
}
|
|
|
|
is_on_bcp = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!is_on_bcp) {
|
|
|
|
// Resolve, throwing a real error if it doesn't work.
|
|
|
|
mirror = ss.as_java_mirror(class_loader, protection_domain,
|
|
|
|
SignatureStream::NCDFError, CHECK_(empty));
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
if (ss.at_return_type())
|
|
|
|
rt = Handle(THREAD, mirror);
|
|
|
|
else
|
|
|
|
pts->obj_at_put(arg++, mirror);
|
2010-05-01 21:57:35 -07:00
|
|
|
// Check accessibility.
|
|
|
|
if (ss.is_object() && accessing_klass.not_null()) {
|
|
|
|
klassOop sel_klass = java_lang_Class::as_klassOop(mirror);
|
|
|
|
// Emulate constantPoolOopDesc::verify_constant_pool_resolve.
|
|
|
|
if (Klass::cast(sel_klass)->oop_is_objArray())
|
|
|
|
sel_klass = objArrayKlass::cast(sel_klass)->bottom_klass();
|
|
|
|
if (Klass::cast(sel_klass)->oop_is_instance()) {
|
|
|
|
KlassHandle sel_kh(THREAD, sel_klass);
|
|
|
|
LinkResolver::check_klass_accessability(accessing_klass, sel_kh, CHECK_(empty));
|
|
|
|
}
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
assert(arg == npts, "");
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::findMethodType(Class rt, Class[] pts) -> MethodType
|
2009-04-08 10:56:49 -07:00
|
|
|
JavaCallArguments args(Handle(THREAD, rt()));
|
|
|
|
args.push_oop(pts());
|
|
|
|
JavaValue result(T_OBJECT);
|
2011-03-11 22:34:57 -08:00
|
|
|
Symbol* findMethodHandleType_signature = vmSymbols::findMethodHandleType_signature();
|
|
|
|
if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) {
|
|
|
|
findMethodHandleType_signature = vmSymbols::findMethodHandleType_TRANS_signature();
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
JavaCalls::call_static(&result,
|
2010-05-01 02:42:18 -07:00
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::findMethodHandleType_name(),
|
2011-03-11 22:34:57 -08:00
|
|
|
findMethodHandleType_signature,
|
2009-04-08 10:56:49 -07:00
|
|
|
&args, CHECK_(empty));
|
2010-09-13 23:24:30 -07:00
|
|
|
Handle method_type(THREAD, (oop) result.get_jobject());
|
|
|
|
|
|
|
|
if (for_invokeGeneric) {
|
2011-03-11 22:34:57 -08:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::notifyGenericMethodType(MethodType) -> void
|
2010-09-13 23:24:30 -07:00
|
|
|
JavaCallArguments args(Handle(THREAD, method_type()));
|
|
|
|
JavaValue no_result(T_VOID);
|
2011-03-11 22:34:57 -08:00
|
|
|
Symbol* notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_signature();
|
|
|
|
if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodType_klass()->name() == vmSymbols::java_dyn_MethodType()) {
|
|
|
|
notifyGenericMethodType_signature = vmSymbols::notifyGenericMethodType_TRANS_signature();
|
|
|
|
}
|
2010-09-13 23:24:30 -07:00
|
|
|
JavaCalls::call_static(&no_result,
|
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::notifyGenericMethodType_name(),
|
2011-03-11 22:34:57 -08:00
|
|
|
notifyGenericMethodType_signature,
|
2010-09-13 23:24:30 -07:00
|
|
|
&args, THREAD);
|
|
|
|
if (HAS_PENDING_EXCEPTION) {
|
|
|
|
// If the notification fails, just kill it.
|
|
|
|
CLEAR_PENDING_EXCEPTION;
|
|
|
|
}
|
|
|
|
}
|
2010-05-01 21:57:35 -07:00
|
|
|
|
|
|
|
// report back to the caller with the MethodType and the "on_bcp" flag
|
|
|
|
return_bcp_flag = is_on_bcp;
|
2010-09-13 23:24:30 -07:00
|
|
|
return method_type;
|
2009-04-08 10:56:49 -07:00
|
|
|
}
|
|
|
|
|
2010-06-09 18:50:45 -07:00
|
|
|
// Ask Java code to find or construct a method handle constant.
|
|
|
|
Handle SystemDictionary::link_method_handle_constant(KlassHandle caller,
|
|
|
|
int ref_kind, //e.g., JVM_REF_invokeVirtual
|
|
|
|
KlassHandle callee,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name_sym,
|
|
|
|
Symbol* signature,
|
2010-06-09 18:50:45 -07:00
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
2011-01-27 16:11:27 -08:00
|
|
|
Handle name = java_lang_String::create_from_symbol(name_sym, CHECK_(empty));
|
2010-06-09 18:50:45 -07:00
|
|
|
Handle type;
|
|
|
|
if (signature->utf8_length() > 0 && signature->byte_at(0) == '(') {
|
|
|
|
bool ignore_is_on_bcp = false;
|
2010-09-13 23:24:30 -07:00
|
|
|
type = find_method_handle_type(signature, caller, false, ignore_is_on_bcp, CHECK_(empty));
|
2010-06-09 18:50:45 -07:00
|
|
|
} else {
|
2011-01-27 16:11:27 -08:00
|
|
|
ResourceMark rm(THREAD);
|
|
|
|
SignatureStream ss(signature, false);
|
2010-06-09 18:50:45 -07:00
|
|
|
if (!ss.is_done()) {
|
|
|
|
oop mirror = ss.as_java_mirror(caller->class_loader(), caller->protection_domain(),
|
|
|
|
SignatureStream::NCDFError, CHECK_(empty));
|
|
|
|
type = Handle(THREAD, mirror);
|
|
|
|
ss.next();
|
|
|
|
if (!ss.is_done()) type = Handle(); // error!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type.is_null()) {
|
|
|
|
THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad signature", empty);
|
|
|
|
}
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::linkMethodHandleConstant(Class caller, int refKind, Class callee, String name, Object type) -> MethodHandle
|
2010-06-09 18:50:45 -07:00
|
|
|
JavaCallArguments args;
|
|
|
|
args.push_oop(caller->java_mirror()); // the referring class
|
|
|
|
args.push_int(ref_kind);
|
|
|
|
args.push_oop(callee->java_mirror()); // the target class
|
|
|
|
args.push_oop(name());
|
|
|
|
args.push_oop(type());
|
|
|
|
JavaValue result(T_OBJECT);
|
2011-03-11 22:34:57 -08:00
|
|
|
Symbol* linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_signature();
|
|
|
|
if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandle_klass()->name() == vmSymbols::java_dyn_MethodHandle()) {
|
|
|
|
linkMethodHandleConstant_signature = vmSymbols::linkMethodHandleConstant_TRANS_signature();
|
|
|
|
}
|
2010-06-09 18:50:45 -07:00
|
|
|
JavaCalls::call_static(&result,
|
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::linkMethodHandleConstant_name(),
|
2011-03-11 22:34:57 -08:00
|
|
|
linkMethodHandleConstant_signature,
|
2010-06-09 18:50:45 -07:00
|
|
|
&args, CHECK_(empty));
|
|
|
|
return Handle(THREAD, (oop) result.get_jobject());
|
|
|
|
}
|
2009-04-08 10:56:49 -07:00
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// Ask Java code to find or construct a java.lang.invoke.CallSite for the given
|
2009-04-21 23:21:04 -07:00
|
|
|
// name and signature, as interpreted relative to the given class loader.
|
2010-05-01 02:42:18 -07:00
|
|
|
Handle SystemDictionary::make_dynamic_call_site(Handle bootstrap_method,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name,
|
2010-05-01 02:42:18 -07:00
|
|
|
methodHandle signature_invoker,
|
|
|
|
Handle info,
|
|
|
|
methodHandle caller_method,
|
|
|
|
int caller_bci,
|
2009-04-21 23:21:04 -07:00
|
|
|
TRAPS) {
|
|
|
|
Handle empty;
|
2010-07-15 18:40:45 -07:00
|
|
|
guarantee(bootstrap_method.not_null() &&
|
2011-03-11 22:34:57 -08:00
|
|
|
java_lang_invoke_MethodHandle::is_instance(bootstrap_method()),
|
2010-07-15 18:40:45 -07:00
|
|
|
"caller must supply a valid BSM");
|
|
|
|
|
2010-05-01 02:42:18 -07:00
|
|
|
Handle caller_mname = MethodHandles::new_MemberName(CHECK_(empty));
|
|
|
|
MethodHandles::init_MemberName(caller_mname(), caller_method());
|
|
|
|
|
2011-03-11 22:34:57 -08:00
|
|
|
// call java.lang.invoke.MethodHandleNatives::makeDynamicCallSite(bootm, name, mtype, info, caller_mname, caller_pos)
|
2011-01-27 16:11:27 -08:00
|
|
|
oop name_str_oop = StringTable::intern(name, CHECK_(empty)); // not a handle!
|
2010-05-01 02:42:18 -07:00
|
|
|
JavaCallArguments args(Handle(THREAD, bootstrap_method()));
|
2009-04-21 23:21:04 -07:00
|
|
|
args.push_oop(name_str_oop);
|
2010-05-01 02:42:18 -07:00
|
|
|
args.push_oop(signature_invoker->method_handle_type());
|
|
|
|
args.push_oop(info());
|
|
|
|
args.push_oop(caller_mname());
|
2009-04-21 23:21:04 -07:00
|
|
|
args.push_int(caller_bci);
|
|
|
|
JavaValue result(T_OBJECT);
|
2011-03-11 22:33:47 -08:00
|
|
|
Symbol* makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_signature();
|
|
|
|
if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::sun_dyn_MethodHandleNatives()) {
|
|
|
|
makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS_signature();
|
|
|
|
}
|
2011-03-11 22:34:57 -08:00
|
|
|
if (AllowTransitionalJSR292 && SystemDictionaryHandles::MethodHandleNatives_klass()->name() == vmSymbols::java_dyn_MethodHandleNatives()) {
|
|
|
|
makeDynamicCallSite_signature = vmSymbols::makeDynamicCallSite_TRANS2_signature();
|
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
JavaCalls::call_static(&result,
|
2010-05-01 02:42:18 -07:00
|
|
|
SystemDictionary::MethodHandleNatives_klass(),
|
|
|
|
vmSymbols::makeDynamicCallSite_name(),
|
2011-03-11 22:33:47 -08:00
|
|
|
makeDynamicCallSite_signature,
|
2009-04-21 23:21:04 -07:00
|
|
|
&args, CHECK_(empty));
|
|
|
|
oop call_site_oop = (oop) result.get_jobject();
|
2009-09-15 21:53:47 -07:00
|
|
|
assert(call_site_oop->is_oop()
|
2011-03-11 22:34:57 -08:00
|
|
|
/*&& java_lang_invoke_CallSite::is_instance(call_site_oop)*/, "must be sane");
|
2009-04-21 23:21:04 -07:00
|
|
|
if (TraceMethodHandles) {
|
2009-10-30 16:22:59 -07:00
|
|
|
#ifndef PRODUCT
|
2009-04-21 23:21:04 -07:00
|
|
|
tty->print_cr("Linked invokedynamic bci=%d site="INTPTR_FORMAT":", caller_bci, call_site_oop);
|
|
|
|
call_site_oop->print();
|
|
|
|
tty->cr();
|
2009-10-30 16:22:59 -07:00
|
|
|
#endif //PRODUCT
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
return call_site_oop;
|
|
|
|
}
|
|
|
|
|
2010-07-15 18:40:45 -07:00
|
|
|
Handle SystemDictionary::find_bootstrap_method(methodHandle caller_method, int caller_bci,
|
2010-10-30 13:08:23 -07:00
|
|
|
int cache_index,
|
|
|
|
Handle& argument_info_result,
|
|
|
|
TRAPS) {
|
2009-04-21 23:21:04 -07:00
|
|
|
Handle empty;
|
|
|
|
|
2010-07-15 18:40:45 -07:00
|
|
|
constantPoolHandle pool;
|
|
|
|
{
|
|
|
|
klassOop caller = caller_method->method_holder();
|
|
|
|
if (!Klass::cast(caller)->oop_is_instance()) return empty;
|
|
|
|
pool = constantPoolHandle(THREAD, instanceKlass::cast(caller)->constants());
|
|
|
|
}
|
|
|
|
|
|
|
|
int constant_pool_index = pool->cache()->entry_at(cache_index)->constant_pool_index();
|
|
|
|
constantTag tag = pool->tag_at(constant_pool_index);
|
|
|
|
|
|
|
|
if (tag.is_invoke_dynamic()) {
|
2010-10-30 13:08:23 -07:00
|
|
|
// JVM_CONSTANT_InvokeDynamic is an ordered pair of [bootm, name&type], plus optional arguments
|
2010-07-15 18:40:45 -07:00
|
|
|
// The bootm, being a JVM_CONSTANT_MethodHandle, has its own cache entry.
|
|
|
|
int bsm_index = pool->invoke_dynamic_bootstrap_method_ref_index_at(constant_pool_index);
|
|
|
|
if (bsm_index != 0) {
|
|
|
|
int bsm_index_in_cache = pool->cache()->entry_at(cache_index)->bootstrap_method_index_in_cache();
|
|
|
|
DEBUG_ONLY(int bsm_index_2 = pool->cache()->entry_at(bsm_index_in_cache)->constant_pool_index());
|
|
|
|
assert(bsm_index == bsm_index_2, "BSM constant lifted to cache");
|
|
|
|
if (TraceMethodHandles) {
|
|
|
|
tty->print_cr("resolving bootstrap method for "PTR_FORMAT" at %d at cache[%d]CP[%d]...",
|
|
|
|
(intptr_t) caller_method(), caller_bci, cache_index, constant_pool_index);
|
|
|
|
}
|
|
|
|
oop bsm_oop = pool->resolve_cached_constant_at(bsm_index_in_cache, CHECK_(empty));
|
|
|
|
if (TraceMethodHandles) {
|
|
|
|
tty->print_cr("bootstrap method for "PTR_FORMAT" at %d retrieved as "PTR_FORMAT":",
|
|
|
|
(intptr_t) caller_method(), caller_bci, (intptr_t) bsm_oop);
|
|
|
|
}
|
2010-10-30 13:08:23 -07:00
|
|
|
assert(bsm_oop->is_oop(), "must be sane");
|
|
|
|
// caller must verify that it is of type MethodHandle
|
|
|
|
Handle bsm(THREAD, bsm_oop);
|
|
|
|
bsm_oop = NULL; // safety
|
|
|
|
|
|
|
|
// Extract the optional static arguments.
|
|
|
|
Handle argument_info; // either null, or one arg, or Object[]{arg...}
|
|
|
|
int argc = pool->invoke_dynamic_argument_count_at(constant_pool_index);
|
|
|
|
if (TraceInvokeDynamic) {
|
|
|
|
tty->print_cr("find_bootstrap_method: [%d/%d] CONSTANT_InvokeDynamic: %d[%d]",
|
|
|
|
constant_pool_index, cache_index, bsm_index, argc);
|
|
|
|
}
|
|
|
|
if (argc > 0) {
|
|
|
|
objArrayHandle arg_array;
|
|
|
|
if (argc > 1) {
|
|
|
|
objArrayOop arg_array_oop = oopFactory::new_objArray(SystemDictionary::Object_klass(), argc, CHECK_(empty));
|
|
|
|
arg_array = objArrayHandle(THREAD, arg_array_oop);
|
|
|
|
argument_info = arg_array;
|
|
|
|
}
|
|
|
|
for (int arg_i = 0; arg_i < argc; arg_i++) {
|
|
|
|
int arg_index = pool->invoke_dynamic_argument_index_at(constant_pool_index, arg_i);
|
|
|
|
oop arg_oop = pool->resolve_possibly_cached_constant_at(arg_index, CHECK_(empty));
|
|
|
|
if (arg_array.is_null()) {
|
|
|
|
argument_info = Handle(THREAD, arg_oop);
|
|
|
|
} else {
|
|
|
|
arg_array->obj_at_put(arg_i, arg_oop);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
argument_info_result = argument_info; // return argument_info to caller
|
|
|
|
return bsm;
|
2010-07-15 18:40:45 -07:00
|
|
|
}
|
|
|
|
// else null BSM; fall through
|
|
|
|
} else if (tag.is_name_and_type()) {
|
|
|
|
// JSR 292 EDR does not have JVM_CONSTANT_InvokeDynamic
|
|
|
|
// a bare name&type defaults its BSM to null, so fall through...
|
|
|
|
} else {
|
|
|
|
ShouldNotReachHere(); // verifier does not allow this
|
|
|
|
}
|
2009-04-21 23:21:04 -07:00
|
|
|
|
2010-07-15 18:40:45 -07:00
|
|
|
// Fall through to pick up the per-class bootstrap method.
|
|
|
|
// This mechanism may go away in the PFD.
|
|
|
|
assert(AllowTransitionalJSR292, "else the verifier should have stopped us already");
|
2010-10-30 13:08:23 -07:00
|
|
|
argument_info_result = empty; // return no argument_info to caller
|
2010-07-15 18:40:45 -07:00
|
|
|
oop bsm_oop = instanceKlass::cast(caller_method->method_holder())->bootstrap_method();
|
|
|
|
if (bsm_oop != NULL) {
|
2009-10-30 16:22:59 -07:00
|
|
|
if (TraceMethodHandles) {
|
2010-07-15 18:40:45 -07:00
|
|
|
tty->print_cr("bootstrap method for "PTR_FORMAT" registered as "PTR_FORMAT":",
|
|
|
|
(intptr_t) caller_method(), (intptr_t) bsm_oop);
|
2009-10-30 16:22:59 -07:00
|
|
|
}
|
2010-10-30 13:08:23 -07:00
|
|
|
assert(bsm_oop->is_oop(), "must be sane");
|
2010-07-15 18:40:45 -07:00
|
|
|
return Handle(THREAD, bsm_oop);
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
2010-05-01 02:42:18 -07:00
|
|
|
return empty;
|
2009-04-21 23:21:04 -07:00
|
|
|
}
|
|
|
|
|
2007-12-01 00:00:00 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
void SystemDictionary::reorder_dictionary() {
|
|
|
|
dictionary()->reorder_dictionary();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::copy_buckets(char** top, char* end) {
|
|
|
|
dictionary()->copy_buckets(top, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::copy_table(char** top, char* end) {
|
|
|
|
dictionary()->copy_table(top, end);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::reverse() {
|
|
|
|
dictionary()->reverse();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SystemDictionary::number_of_classes() {
|
|
|
|
return dictionary()->number_of_entries();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
#ifndef PRODUCT
|
|
|
|
|
|
|
|
void SystemDictionary::print() {
|
|
|
|
dictionary()->print();
|
|
|
|
|
|
|
|
// Placeholders
|
|
|
|
GCMutexLocker mu(SystemDictionary_lock);
|
|
|
|
placeholders()->print();
|
|
|
|
|
|
|
|
// loader constraints - print under SD_lock
|
|
|
|
constraints()->print();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void SystemDictionary::verify() {
|
|
|
|
guarantee(dictionary() != NULL, "Verify of system dictionary failed");
|
|
|
|
guarantee(constraints() != NULL,
|
|
|
|
"Verify of loader constraints failed");
|
|
|
|
guarantee(dictionary()->number_of_entries() >= 0 &&
|
|
|
|
placeholders()->number_of_entries() >= 0,
|
|
|
|
"Verify of system dictionary failed");
|
|
|
|
|
|
|
|
// Verify dictionary
|
|
|
|
dictionary()->verify();
|
|
|
|
|
|
|
|
GCMutexLocker mu(SystemDictionary_lock);
|
|
|
|
placeholders()->verify();
|
|
|
|
|
|
|
|
// Verify constraint table
|
|
|
|
guarantee(constraints() != NULL, "Verify of loader constraints failed");
|
2010-02-05 11:05:50 -05:00
|
|
|
constraints()->verify(dictionary(), placeholders());
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::verify_obj_klass_present(Handle obj,
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* class_name,
|
2007-12-01 00:00:00 +00:00
|
|
|
Handle class_loader) {
|
|
|
|
GCMutexLocker mu(SystemDictionary_lock);
|
2011-01-27 16:11:27 -08:00
|
|
|
Symbol* name;
|
|
|
|
|
|
|
|
klassOop probe = find_class(class_name, class_loader);
|
2007-12-01 00:00:00 +00:00
|
|
|
if (probe == NULL) {
|
|
|
|
probe = SystemDictionary::find_shared_class(class_name);
|
2011-01-27 16:11:27 -08:00
|
|
|
if (probe == NULL) {
|
|
|
|
name = find_placeholder(class_name, class_loader);
|
|
|
|
}
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
2011-01-27 16:11:27 -08:00
|
|
|
guarantee(probe != NULL || name != NULL,
|
|
|
|
"Loaded klasses should be in SystemDictionary");
|
2007-12-01 00:00:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef PRODUCT
|
|
|
|
|
|
|
|
// statistics code
|
|
|
|
class ClassStatistics: AllStatic {
|
|
|
|
private:
|
|
|
|
static int nclasses; // number of classes
|
|
|
|
static int nmethods; // number of methods
|
|
|
|
static int nmethoddata; // number of methodData
|
|
|
|
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
|
|
|
|
static int methoddata_size; // size of methodData objects in words
|
|
|
|
|
|
|
|
static void do_class(klassOop k) {
|
|
|
|
nclasses++;
|
|
|
|
class_size += k->size();
|
|
|
|
if (k->klass_part()->oop_is_instance()) {
|
|
|
|
instanceKlass* ik = (instanceKlass*)k->klass_part();
|
|
|
|
class_size += ik->methods()->size();
|
|
|
|
class_size += ik->constants()->size();
|
|
|
|
class_size += ik->local_interfaces()->size();
|
|
|
|
class_size += ik->transitive_interfaces()->size();
|
|
|
|
// We do not have to count implementors, since we only store one!
|
|
|
|
class_size += ik->fields()->size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void do_method(methodOop m) {
|
|
|
|
nmethods++;
|
|
|
|
method_size += m->size();
|
|
|
|
// class loader uses same objArray for empty vectors, so don't count these
|
|
|
|
if (m->exception_table()->length() != 0) method_size += m->exception_table()->size();
|
|
|
|
if (m->has_stackmap_table()) {
|
|
|
|
method_size += m->stackmap_data()->size();
|
|
|
|
}
|
|
|
|
|
|
|
|
methodDataOop mdo = m->method_data();
|
|
|
|
if (mdo != NULL) {
|
|
|
|
nmethoddata++;
|
|
|
|
methoddata_size += mdo->size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void print() {
|
|
|
|
SystemDictionary::classes_do(do_class);
|
|
|
|
SystemDictionary::methods_do(do_method);
|
|
|
|
tty->print_cr("Class statistics:");
|
|
|
|
tty->print_cr("%d classes (%d bytes)", nclasses, class_size * oopSize);
|
|
|
|
tty->print_cr("%d methods (%d bytes = %d base + %d debug info)", nmethods,
|
|
|
|
(method_size + debug_size) * oopSize, method_size * oopSize, debug_size * oopSize);
|
|
|
|
tty->print_cr("%d methoddata (%d bytes)", nmethoddata, methoddata_size * oopSize);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int ClassStatistics::nclasses = 0;
|
|
|
|
int ClassStatistics::nmethods = 0;
|
|
|
|
int ClassStatistics::nmethoddata = 0;
|
|
|
|
int ClassStatistics::class_size = 0;
|
|
|
|
int ClassStatistics::method_size = 0;
|
|
|
|
int ClassStatistics::debug_size = 0;
|
|
|
|
int ClassStatistics::methoddata_size = 0;
|
|
|
|
|
|
|
|
void SystemDictionary::print_class_statistics() {
|
|
|
|
ResourceMark rm;
|
|
|
|
ClassStatistics::print();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MethodStatistics: AllStatic {
|
|
|
|
public:
|
|
|
|
enum {
|
|
|
|
max_parameter_size = 10
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
|
|
|
|
static int _number_of_methods;
|
|
|
|
static int _number_of_final_methods;
|
|
|
|
static int _number_of_static_methods;
|
|
|
|
static int _number_of_native_methods;
|
|
|
|
static int _number_of_synchronized_methods;
|
|
|
|
static int _number_of_profiled_methods;
|
|
|
|
static int _number_of_bytecodes;
|
|
|
|
static int _parameter_size_profile[max_parameter_size];
|
|
|
|
static int _bytecodes_profile[Bytecodes::number_of_java_codes];
|
|
|
|
|
|
|
|
static void initialize() {
|
|
|
|
_number_of_methods = 0;
|
|
|
|
_number_of_final_methods = 0;
|
|
|
|
_number_of_static_methods = 0;
|
|
|
|
_number_of_native_methods = 0;
|
|
|
|
_number_of_synchronized_methods = 0;
|
|
|
|
_number_of_profiled_methods = 0;
|
|
|
|
_number_of_bytecodes = 0;
|
|
|
|
for (int i = 0; i < max_parameter_size ; i++) _parameter_size_profile[i] = 0;
|
|
|
|
for (int j = 0; j < Bytecodes::number_of_java_codes; j++) _bytecodes_profile [j] = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void do_method(methodOop m) {
|
|
|
|
_number_of_methods++;
|
|
|
|
// collect flag info
|
|
|
|
if (m->is_final() ) _number_of_final_methods++;
|
|
|
|
if (m->is_static() ) _number_of_static_methods++;
|
|
|
|
if (m->is_native() ) _number_of_native_methods++;
|
|
|
|
if (m->is_synchronized()) _number_of_synchronized_methods++;
|
|
|
|
if (m->method_data() != NULL) _number_of_profiled_methods++;
|
|
|
|
// collect parameter size info (add one for receiver, if any)
|
|
|
|
_parameter_size_profile[MIN2(m->size_of_parameters() + (m->is_static() ? 0 : 1), max_parameter_size - 1)]++;
|
|
|
|
// collect bytecodes info
|
|
|
|
{
|
|
|
|
Thread *thread = Thread::current();
|
|
|
|
HandleMark hm(thread);
|
|
|
|
BytecodeStream s(methodHandle(thread, m));
|
|
|
|
Bytecodes::Code c;
|
|
|
|
while ((c = s.next()) >= 0) {
|
|
|
|
_number_of_bytecodes++;
|
|
|
|
_bytecodes_profile[c]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
|
|
|
static void print() {
|
|
|
|
initialize();
|
|
|
|
SystemDictionary::methods_do(do_method);
|
|
|
|
// generate output
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("Method statistics (static):");
|
|
|
|
// flag distribution
|
|
|
|
tty->cr();
|
|
|
|
tty->print_cr("%6d final methods %6.1f%%", _number_of_final_methods , _number_of_final_methods * 100.0F / _number_of_methods);
|
|
|
|
tty->print_cr("%6d static methods %6.1f%%", _number_of_static_methods , _number_of_static_methods * 100.0F / _number_of_methods);
|
|
|
|
tty->print_cr("%6d native methods %6.1f%%", _number_of_native_methods , _number_of_native_methods * 100.0F / _number_of_methods);
|
|
|
|
tty->print_cr("%6d synchronized methods %6.1f%%", _number_of_synchronized_methods, _number_of_synchronized_methods * 100.0F / _number_of_methods);
|
|
|
|
tty->print_cr("%6d profiled methods %6.1f%%", _number_of_profiled_methods, _number_of_profiled_methods * 100.0F / _number_of_methods);
|
|
|
|
// parameter size profile
|
|
|
|
tty->cr();
|
|
|
|
{ int tot = 0;
|
|
|
|
int avg = 0;
|
|
|
|
for (int i = 0; i < max_parameter_size; i++) {
|
|
|
|
int n = _parameter_size_profile[i];
|
|
|
|
tot += n;
|
|
|
|
avg += n*i;
|
|
|
|
tty->print_cr("parameter size = %1d: %6d methods %5.1f%%", i, n, n * 100.0F / _number_of_methods);
|
|
|
|
}
|
|
|
|
assert(tot == _number_of_methods, "should be the same");
|
|
|
|
tty->print_cr(" %6d methods 100.0%%", _number_of_methods);
|
|
|
|
tty->print_cr("(average parameter size = %3.1f including receiver, if any)", (float)avg / _number_of_methods);
|
|
|
|
}
|
|
|
|
// bytecodes profile
|
|
|
|
tty->cr();
|
|
|
|
{ int tot = 0;
|
|
|
|
for (int i = 0; i < Bytecodes::number_of_java_codes; i++) {
|
|
|
|
if (Bytecodes::is_defined(i)) {
|
|
|
|
Bytecodes::Code c = Bytecodes::cast(i);
|
|
|
|
int n = _bytecodes_profile[c];
|
|
|
|
tot += n;
|
|
|
|
tty->print_cr("%9d %7.3f%% %s", n, n * 100.0F / _number_of_bytecodes, Bytecodes::name(c));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert(tot == _number_of_bytecodes, "should be the same");
|
|
|
|
tty->print_cr("%9d 100.000%%", _number_of_bytecodes);
|
|
|
|
}
|
|
|
|
tty->cr();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int MethodStatistics::_number_of_methods;
|
|
|
|
int MethodStatistics::_number_of_final_methods;
|
|
|
|
int MethodStatistics::_number_of_static_methods;
|
|
|
|
int MethodStatistics::_number_of_native_methods;
|
|
|
|
int MethodStatistics::_number_of_synchronized_methods;
|
|
|
|
int MethodStatistics::_number_of_profiled_methods;
|
|
|
|
int MethodStatistics::_number_of_bytecodes;
|
|
|
|
int MethodStatistics::_parameter_size_profile[MethodStatistics::max_parameter_size];
|
|
|
|
int MethodStatistics::_bytecodes_profile[Bytecodes::number_of_java_codes];
|
|
|
|
|
|
|
|
|
|
|
|
void SystemDictionary::print_method_statistics() {
|
|
|
|
MethodStatistics::print();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // PRODUCT
|