Skip to content
Permalink
Browse files
8262227: Change SystemDictionary::find() to return an InstanceKlass*.
Reviewed-by: iklam, dholmes, coleenp
  • Loading branch information
Harold Seigel committed Feb 25, 2021
1 parent 35c0a69 commit 29c603f9dc1d3f86260ed3d3c1b8ef23111ba4b4
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 84 deletions.
@@ -112,8 +112,7 @@ Klass* AOTCodeHeap::lookup_klass(const char* name, int len, const Method* method
log_debug(aot, class, resolve)("Probe failed for AOT class %s", name);
return NULL;
}
Klass* k = SystemDictionary::find_instance_or_array_klass(sym, loader, protection_domain, thread);
assert(!thread->has_pending_exception(), "should not throw");
Klass* k = SystemDictionary::find_instance_or_array_klass(sym, loader, protection_domain);

if (k != NULL) {
log_info(aot, class, resolve)("%s %s (lookup)", caller->method_holder()->external_name(), k->external_name());
@@ -304,10 +304,10 @@ ciInstance* ciEnv::get_or_create_exception(jobject& handle, Symbol* name) {
VM_ENTRY_MARK;
if (handle == NULL) {
// Cf. universe.cpp, creation of Universe::_null_ptr_exception_instance.
Klass* k = SystemDictionary::find(name, Handle(), Handle(), THREAD);
InstanceKlass* ik = SystemDictionary::find_instance_klass(name, Handle(), Handle());
jobject objh = NULL;
if (!HAS_PENDING_EXCEPTION && k != NULL) {
oop obj = InstanceKlass::cast(k)->allocate_instance(THREAD);
if (ik != NULL) {
oop obj = ik->allocate_instance(THREAD);
if (!HAS_PENDING_EXCEPTION)
objh = JNIHandles::make_global(Handle(THREAD, obj));
}
@@ -448,8 +448,7 @@ ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader,
CHECK_AND_CLEAR_(fail_type));
} else {
kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain,
CHECK_AND_CLEAR_(fail_type));
kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
}
found_klass = kls;
}
@@ -899,16 +899,15 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
// _dictionary->bucket(index) is read here, so the caller will not see
// the new entry.

Klass* SystemDictionary::find(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
InstanceKlass* SystemDictionary::find_instance_klass(Symbol* class_name,
Handle class_loader,
Handle protection_domain) {

// 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()));
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader());
oop class_loader_oop = java_lang_ClassLoader::non_reflection_class_loader(class_loader());
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data_or_null(class_loader_oop);

if (loader_data == NULL) {
// If the ClassLoaderData has not been setup,
@@ -918,16 +917,14 @@ Klass* SystemDictionary::find(Symbol* class_name,

Dictionary* dictionary = loader_data->dictionary();
unsigned int name_hash = dictionary->compute_hash(class_name);
return dictionary->find(name_hash, class_name,
protection_domain);
return dictionary->find(name_hash, class_name, protection_domain);
}

// Look for a loaded instance or array klass by name. Do not do any loading.
// return NULL in case of error.
Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS) {
Handle protection_domain) {
Klass* k = NULL;
assert(class_name != NULL, "class name must be non NULL");

@@ -941,13 +938,13 @@ Klass* SystemDictionary::find_instance_or_array_klass(Symbol* class_name,
if (t != T_OBJECT) {
k = Universe::typeArrayKlassObj(t);
} else {
k = SystemDictionary::find(ss.as_symbol(), class_loader, protection_domain, THREAD);
k = SystemDictionary::find_instance_klass(ss.as_symbol(), class_loader, protection_domain);
}
if (k != NULL) {
k = k->array_klass_or_null(ndims);
}
} else {
k = find(class_name, class_loader, protection_domain, THREAD);
k = find_instance_klass(class_name, class_loader, protection_domain);
}
return k;
}
@@ -1219,7 +1216,7 @@ bool SystemDictionary::check_shared_class_super_type(InstanceKlass* klass, Insta
if (!super_type->is_shared_unregistered_class() && super_type->class_loader_data() != NULL) {
// Check if the super class is loaded by the current class_loader
Symbol* name = super_type->name();
Klass* check = find(name, class_loader, protection_domain, CHECK_0);
InstanceKlass* check = find_instance_klass(name, class_loader, protection_domain);
if (check == super_type) {
return true;
}
@@ -1897,7 +1894,7 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
// Force the protection domain to be null. (This removes protection checks.)
Handle no_protection_domain;
Klass* klass = find_instance_or_array_klass(class_name, class_loader,
no_protection_domain, CHECK_NULL);
no_protection_domain);
if (klass != NULL)
return klass;

@@ -139,15 +139,14 @@ class SystemDictionary : AllStatic {
TRAPS);

// Lookup an already loaded class. If not found NULL is returned.
static Klass* find(Symbol* class_name, Handle class_loader, Handle protection_domain, TRAPS);
static InstanceKlass* find_instance_klass(Symbol* class_name, Handle class_loader, Handle protection_domain);

// Lookup an already loaded instance or array class.
// Do not make any queries to class loaders; consult only the cache.
// If not found NULL is returned.
static Klass* find_instance_or_array_klass(Symbol* class_name,
Handle class_loader,
Handle protection_domain,
TRAPS);
Handle protection_domain);

// Lookup an instance or array class that has already been loaded
// either into the given class loader, or else into another class
@@ -1513,7 +1513,7 @@ static bool is_retransforming(const InstanceKlass* ik, TRAPS) {
assert(name != NULL, "invariant");
Handle class_loader(THREAD, ik->class_loader());
Handle protection_domain(THREAD, ik->protection_domain());
return SystemDictionary::find(name, class_loader, protection_domain, THREAD) != NULL;
return SystemDictionary::find_instance_klass(name, class_loader, protection_domain) != NULL;
}

// target for JFR_ON_KLASS_CREATION hook
@@ -547,24 +547,27 @@ C2V_VMENTRY_NULL(jobject, lookupType, (JNIEnv* env, jobject, jstring jname, jcla
// This is a name from a signature. Strip off the trimmings.
// Call recursive to keep scope of strippedsym.
TempNewSymbol strippedsym = Signature::strip_envelope(class_name);
resolved_klass = SystemDictionary::find(strippedsym, class_loader, protection_domain, CHECK_NULL);
resolved_klass = SystemDictionary::find_instance_klass(strippedsym,
class_loader,
protection_domain);
} else if (Signature::is_array(class_name)) {
SignatureStream ss(class_name, false);
int ndim = ss.skip_array_prefix();
if (ss.type() == T_OBJECT) {
Symbol* strippedsym = ss.as_symbol();
resolved_klass = SystemDictionary::find(strippedsym,
class_loader,
protection_domain,
CHECK_NULL);
resolved_klass = SystemDictionary::find_instance_klass(strippedsym,
class_loader,
protection_domain);
if (!resolved_klass.is_null()) {
resolved_klass = resolved_klass->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = TypeArrayKlass::cast(Universe::typeArrayKlassObj(ss.type()))->array_klass(ndim, CHECK_NULL);
}
} else {
resolved_klass = SystemDictionary::find(class_name, class_loader, protection_domain, CHECK_NULL);
resolved_klass = SystemDictionary::find_instance_klass(class_name,
class_loader,
protection_domain);
}
}
JVMCIObject result = JVMCIENV->get_jvmci_type(resolved_klass, JVMCI_CHECK_NULL);
@@ -1162,7 +1162,7 @@ Klass* JVMCIRuntime::get_klass_by_name_impl(Klass*& accessing_klass,
if (!require_local) {
found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL);
} else {
found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL);
found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
}
}

@@ -582,7 +582,7 @@ Klass* ConstantPool::klass_at_if_loaded(const constantPoolHandle& this_cp, int w
oop protection_domain = this_cp->pool_holder()->protection_domain();
Handle h_prot (thread, protection_domain);
Handle h_loader (thread, loader);
Klass* k = SystemDictionary::find(name, h_loader, h_prot, thread);
Klass* k = SystemDictionary::find_instance_klass(name, h_loader, h_prot);

// Avoid constant pool verification at a safepoint, which takes the Module_lock.
if (k != NULL && !SafepointSynchronize::is_at_safepoint()) {
@@ -891,7 +891,7 @@ bool Method::is_klass_loaded_by_klass_index(int klass_index) const {
Symbol* klass_name = constants()->klass_name_at(klass_index);
Handle loader(thread, method_holder()->class_loader());
Handle prot (thread, method_holder()->protection_domain());
return SystemDictionary::find(klass_name, loader, prot, thread) != NULL;
return SystemDictionary::find_instance_klass(klass_name, loader, prot) != NULL;
} else {
return true;
}
@@ -1070,8 +1070,7 @@ JVM_ENTRY(jclass, JVM_FindLoadedClass(JNIEnv *env, jobject loader, jstring name)
Handle h_loader(THREAD, JNIHandles::resolve(loader));
Klass* k = SystemDictionary::find_instance_or_array_klass(klass_name,
h_loader,
Handle(),
CHECK_NULL);
Handle());
#if INCLUDE_CDS
if (k == NULL) {
// If the class is not already loaded, try to see if it's in the shared
@@ -903,12 +903,11 @@ Deoptimization::DeoptAction Deoptimization::_unloaded_action
template<typename CacheType>
class BoxCacheBase : public CHeapObj<mtCompiler> {
protected:
static InstanceKlass* find_cache_klass(Symbol* klass_name, TRAPS) {
static InstanceKlass* find_cache_klass(Symbol* klass_name) {
ResourceMark rm;
char* klass_name_str = klass_name->as_C_string();
Klass* k = SystemDictionary::find(klass_name, Handle(), Handle(), THREAD);
guarantee(k != NULL, "%s must be loaded", klass_name_str);
InstanceKlass* ik = InstanceKlass::cast(k);
InstanceKlass* ik = SystemDictionary::find_instance_klass(klass_name, Handle(), Handle());
guarantee(ik != NULL, "%s must be loaded", klass_name_str);
guarantee(ik->is_initialized(), "%s must be initialized", klass_name_str);
CacheType::compute_offsets(ik);
return ik;
@@ -922,7 +921,7 @@ template<typename PrimitiveType, typename CacheType, typename BoxType> class Box
protected:
static BoxCache<PrimitiveType, CacheType, BoxType> *_singleton;
BoxCache(Thread* thread) {
InstanceKlass* ik = BoxCacheBase<CacheType>::find_cache_klass(CacheType::symbol(), thread);
InstanceKlass* ik = BoxCacheBase<CacheType>::find_cache_klass(CacheType::symbol());
objArrayOop cache = CacheType::cache(ik);
assert(cache->length() > 0, "Empty cache");
_low = BoxType::value(cache->obj_at(0));
@@ -978,7 +977,7 @@ class BooleanBoxCache : public BoxCacheBase<java_lang_Boolean> {
protected:
static BooleanBoxCache *_singleton;
BooleanBoxCache(Thread *thread) {
InstanceKlass* ik = find_cache_klass(java_lang_Boolean::symbol(), thread);
InstanceKlass* ik = find_cache_klass(java_lang_Boolean::symbol());
_true_cache = JNIHandles::make_global(Handle(thread, java_lang_Boolean::get_TRUE(ik)));
_false_cache = JNIHandles::make_global(Handle(thread, java_lang_Boolean::get_FALSE(ik)));
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -393,7 +393,7 @@ Klass* SignatureStream::as_klass(Handle class_loader, Handle protection_domain,
} else if (failure_mode == CachedOrNull) {
NoSafepointVerifier nsv; // no loading, now, we mean it!
assert(!HAS_PENDING_EXCEPTION, "");
k = SystemDictionary::find(name, class_loader, protection_domain, CHECK_NULL);
k = SystemDictionary::find_instance_klass(name, class_loader, protection_domain);
// SD::find does not trigger loading, so there should be no throws
// Still, bad things can happen, so we CHECK_NULL and ask callers
// to do likewise.

0 comments on commit 29c603f

Please sign in to comment.