mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8264126: Remove TRAPS/THREAD parameter for class loading functions
Reviewed-by: ccheung, iklam, dholmes
This commit is contained in:
parent
f3eed05236
commit
507b690f88
11 changed files with 54 additions and 58 deletions
|
@ -405,7 +405,7 @@ ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
|
|||
ciSymbol* name,
|
||||
bool require_local) {
|
||||
ASSERT_IN_VM;
|
||||
EXCEPTION_CONTEXT;
|
||||
Thread* current = Thread::current();
|
||||
|
||||
// Now we need to check the SystemDictionary
|
||||
Symbol* sym = name->get_symbol();
|
||||
|
@ -425,11 +425,11 @@ ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
|
|||
return unloaded_klass;
|
||||
}
|
||||
|
||||
Handle loader(THREAD, (oop)NULL);
|
||||
Handle domain(THREAD, (oop)NULL);
|
||||
Handle loader;
|
||||
Handle domain;
|
||||
if (accessing_klass != NULL) {
|
||||
loader = Handle(THREAD, accessing_klass->loader());
|
||||
domain = Handle(THREAD, accessing_klass->protection_domain());
|
||||
loader = Handle(current, accessing_klass->loader());
|
||||
domain = Handle(current, accessing_klass->protection_domain());
|
||||
}
|
||||
|
||||
// setup up the proper type to return on OOM
|
||||
|
@ -442,10 +442,10 @@ ciKlass* ciEnv::get_klass_by_name_impl(ciKlass* accessing_klass,
|
|||
Klass* found_klass;
|
||||
{
|
||||
ttyUnlocker ttyul; // release tty lock to avoid ordering problems
|
||||
MutexLocker ml(Compile_lock);
|
||||
MutexLocker ml(current, Compile_lock);
|
||||
Klass* kls;
|
||||
if (!require_local) {
|
||||
kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, THREAD);
|
||||
kls = SystemDictionary::find_constrained_instance_or_array_klass(current, sym, loader);
|
||||
} else {
|
||||
kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 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
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
// SystemDictionary::check_signature_loaders(Symbol* signature,
|
||||
// Klass* klass_being_linked,
|
||||
// Handle loader1, Handle loader2,
|
||||
// bool is_method, TRAPS)
|
||||
// bool is_method)
|
||||
|
||||
InstanceKlass* find_constrained_klass(Symbol* name, Handle loader);
|
||||
|
||||
|
|
|
@ -1049,7 +1049,7 @@ InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
|
|||
bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
|
||||
InstanceKlass* ik,
|
||||
PackageEntry* pkg_entry,
|
||||
Handle class_loader, TRAPS) {
|
||||
Handle class_loader) {
|
||||
assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
|
||||
"Cannot use sharing if java.base is patched");
|
||||
|
||||
|
@ -1081,17 +1081,17 @@ bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
|
|||
if (MetaspaceShared::use_optimized_module_handling()) {
|
||||
// Class visibility has not changed between dump time and run time, so a class
|
||||
// that was visible (and thus archived) during dump time is always visible during runtime.
|
||||
assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD),
|
||||
assert(SystemDictionary::is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader),
|
||||
"visibility cannot change between dump time and runtime");
|
||||
return true;
|
||||
}
|
||||
return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader, THREAD);
|
||||
return is_shared_class_visible_impl(class_name, ik, pkg_entry, class_loader);
|
||||
}
|
||||
|
||||
bool SystemDictionary::is_shared_class_visible_impl(Symbol* class_name,
|
||||
InstanceKlass* ik,
|
||||
PackageEntry* pkg_entry,
|
||||
Handle class_loader, TRAPS) {
|
||||
Handle class_loader) {
|
||||
int scp_index = ik->shared_classpath_index();
|
||||
assert(!ik->is_shared_unregistered_class(), "this function should be called for built-in classes only");
|
||||
assert(scp_index >= 0, "must be");
|
||||
|
@ -1231,9 +1231,7 @@ InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
|
|||
assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
|
||||
Symbol* class_name = ik->name();
|
||||
|
||||
bool visible = is_shared_class_visible(
|
||||
class_name, ik, pkg_entry, class_loader, CHECK_NULL);
|
||||
if (!visible) {
|
||||
if (!is_shared_class_visible(class_name, ik, pkg_entry, class_loader)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -1818,7 +1816,7 @@ void SystemDictionary::update_dictionary(unsigned int hash,
|
|||
// loader constraints might know about a class that isn't fully loaded
|
||||
// yet and these will be ignored.
|
||||
Klass* SystemDictionary::find_constrained_instance_or_array_klass(
|
||||
Symbol* class_name, Handle class_loader, Thread* THREAD) {
|
||||
Thread* current, Symbol* class_name, Handle class_loader) {
|
||||
|
||||
// First see if it has been loaded directly.
|
||||
// Force the protection domain to be null. (This removes protection checks.)
|
||||
|
@ -1840,7 +1838,7 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
|
|||
if (t != T_OBJECT) {
|
||||
klass = Universe::typeArrayKlassObj(t);
|
||||
} else {
|
||||
MutexLocker mu(THREAD, SystemDictionary_lock);
|
||||
MutexLocker mu(current, SystemDictionary_lock);
|
||||
klass = constraints()->find_constrained_klass(ss.as_symbol(), class_loader);
|
||||
}
|
||||
// If element class already loaded, allocate array klass
|
||||
|
@ -1848,7 +1846,7 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
|
|||
klass = klass->array_klass_or_null(ndims);
|
||||
}
|
||||
} else {
|
||||
MutexLocker mu(THREAD, SystemDictionary_lock);
|
||||
MutexLocker mu(current, SystemDictionary_lock);
|
||||
// Non-array classes are easy: simply check the constraint table.
|
||||
klass = constraints()->find_constrained_klass(class_name, class_loader);
|
||||
}
|
||||
|
@ -1859,8 +1857,7 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
|
|||
bool SystemDictionary::add_loader_constraint(Symbol* class_name,
|
||||
Klass* klass_being_linked,
|
||||
Handle class_loader1,
|
||||
Handle class_loader2,
|
||||
Thread* THREAD) {
|
||||
Handle class_loader2) {
|
||||
ClassLoaderData* loader_data1 = class_loader_data(class_loader1);
|
||||
ClassLoaderData* loader_data2 = class_loader_data(class_loader2);
|
||||
|
||||
|
@ -1890,7 +1887,7 @@ bool SystemDictionary::add_loader_constraint(Symbol* class_name,
|
|||
unsigned int name_hash2 = dictionary2->compute_hash(constraint_name);
|
||||
|
||||
{
|
||||
MutexLocker mu_s(THREAD, SystemDictionary_lock);
|
||||
MutexLocker mu_s(SystemDictionary_lock);
|
||||
InstanceKlass* klass1 = dictionary1->find_class(name_hash1, constraint_name);
|
||||
InstanceKlass* klass2 = dictionary2->find_class(name_hash2, constraint_name);
|
||||
bool result = constraints()->add_entry(constraint_name, klass1, class_loader1,
|
||||
|
@ -1900,7 +1897,7 @@ bool SystemDictionary::add_loader_constraint(Symbol* class_name,
|
|||
!klass_being_linked->is_shared()) {
|
||||
SystemDictionaryShared::record_linking_constraint(constraint_name,
|
||||
InstanceKlass::cast(klass_being_linked),
|
||||
class_loader1, class_loader2, THREAD);
|
||||
class_loader1, class_loader2);
|
||||
}
|
||||
#endif // INCLUDE_CDS
|
||||
if (Signature::is_array(class_name)) {
|
||||
|
@ -2038,9 +2035,9 @@ const char* SystemDictionary::find_nest_host_error(const constantPoolHandle& poo
|
|||
// NULL if no constraint failed. No exception except OOME is thrown.
|
||||
// Arrays are not added to the loader constraint table, their elements are.
|
||||
Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
|
||||
Klass* klass_being_linked,
|
||||
Handle loader1, Handle loader2,
|
||||
bool is_method, TRAPS) {
|
||||
Klass* klass_being_linked,
|
||||
Handle loader1, Handle loader2,
|
||||
bool is_method) {
|
||||
// Nothing to do if loaders are the same.
|
||||
if (loader1() == loader2()) {
|
||||
return NULL;
|
||||
|
@ -2052,7 +2049,7 @@ Symbol* SystemDictionary::check_signature_loaders(Symbol* signature,
|
|||
// Note: In the future, if template-like types can take
|
||||
// arguments, we will want to recognize them and dig out class
|
||||
// names hiding inside the argument lists.
|
||||
if (!add_loader_constraint(sig, klass_being_linked, loader1, loader2, THREAD)) {
|
||||
if (!add_loader_constraint(sig, klass_being_linked, loader1, loader2)) {
|
||||
return sig;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,9 +169,9 @@ class SystemDictionary : AllStatic {
|
|||
// satisfied, and it is safe for classes in the given class loader
|
||||
// to manipulate strongly-typed values of the found class, subject
|
||||
// to local linkage and access checks.
|
||||
static Klass* find_constrained_instance_or_array_klass(Symbol* class_name,
|
||||
Handle class_loader,
|
||||
Thread* THREAD);
|
||||
static Klass* find_constrained_instance_or_array_klass(Thread* current,
|
||||
Symbol* class_name,
|
||||
Handle class_loader);
|
||||
|
||||
static void classes_do(MetaspaceClosure* it);
|
||||
// Iterate over all methods in all klasses
|
||||
|
@ -218,7 +218,7 @@ public:
|
|||
|
||||
public:
|
||||
static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
|
||||
Handle loader1, Handle loader2, bool is_method, TRAPS);
|
||||
Handle loader1, Handle loader2, bool is_method);
|
||||
|
||||
// JSR 292
|
||||
// find a java.lang.invoke.MethodHandle.invoke* method for a given signature
|
||||
|
@ -350,11 +350,11 @@ private:
|
|||
|
||||
static bool is_shared_class_visible(Symbol* class_name, InstanceKlass* ik,
|
||||
PackageEntry* pkg_entry,
|
||||
Handle class_loader, TRAPS);
|
||||
Handle class_loader);
|
||||
static bool is_shared_class_visible_impl(Symbol* class_name,
|
||||
InstanceKlass* ik,
|
||||
PackageEntry* pkg_entry,
|
||||
Handle class_loader, TRAPS);
|
||||
Handle class_loader);
|
||||
static bool check_shared_class_super_type(InstanceKlass* klass, InstanceKlass* super,
|
||||
Handle class_loader, Handle protection_domain,
|
||||
bool is_superclass, TRAPS);
|
||||
|
@ -366,7 +366,7 @@ protected:
|
|||
// Used by SystemDictionaryShared
|
||||
|
||||
static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
|
||||
Handle loader2, TRAPS);
|
||||
Handle loader2);
|
||||
static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld);
|
||||
static InstanceKlass* load_shared_lambda_proxy_class(InstanceKlass* ik,
|
||||
Handle class_loader,
|
||||
|
|
|
@ -1823,7 +1823,7 @@ void SystemDictionaryShared::check_verification_constraints(InstanceKlass* klass
|
|||
// InstanceKlass::link_class(), so that these can be checked quickly
|
||||
// at runtime without laying out the vtable/itables.
|
||||
void SystemDictionaryShared::record_linking_constraint(Symbol* name, InstanceKlass* klass,
|
||||
Handle loader1, Handle loader2, TRAPS) {
|
||||
Handle loader1, Handle loader2) {
|
||||
// A linking constraint check is executed when:
|
||||
// - klass extends or implements type S
|
||||
// - klass overrides method S.M(...) with X.M
|
||||
|
@ -1861,13 +1861,14 @@ void SystemDictionaryShared::record_linking_constraint(Symbol* name, InstanceKla
|
|||
return;
|
||||
}
|
||||
|
||||
if (THREAD->is_VM_thread()) {
|
||||
assert(DynamicDumpSharedSpaces, "must be");
|
||||
if (DynamicDumpSharedSpaces && Thread::current()->is_VM_thread()) {
|
||||
// We are re-laying out the vtable/itables of the *copy* of
|
||||
// a class during the final stage of dynamic dumping. The
|
||||
// linking constraints for this class has already been recorded.
|
||||
return;
|
||||
}
|
||||
assert(!Thread::current()->is_VM_thread(), "must be");
|
||||
|
||||
Arguments::assert_is_dumping_archive();
|
||||
DumpTimeSharedClassInfo* info = find_or_allocate_info_for(klass);
|
||||
if (info != NULL) {
|
||||
|
@ -1877,7 +1878,7 @@ void SystemDictionaryShared::record_linking_constraint(Symbol* name, InstanceKla
|
|||
|
||||
// returns true IFF there's no need to re-initialize the i/v-tables for klass for
|
||||
// the purpose of checking class loader constraints.
|
||||
bool SystemDictionaryShared::check_linking_constraints(InstanceKlass* klass, TRAPS) {
|
||||
bool SystemDictionaryShared::check_linking_constraints(Thread* current, InstanceKlass* klass) {
|
||||
assert(!DumpSharedSpaces && UseSharedSpaces, "called at run time with CDS enabled only");
|
||||
LogTarget(Info, class, loader, constraints) log;
|
||||
if (klass->is_shared_boot_class()) {
|
||||
|
@ -1888,20 +1889,20 @@ bool SystemDictionaryShared::check_linking_constraints(InstanceKlass* klass, TRA
|
|||
RunTimeSharedClassInfo* info = RunTimeSharedClassInfo::get_for(klass);
|
||||
assert(info != NULL, "Sanity");
|
||||
if (info->_num_loader_constraints > 0) {
|
||||
HandleMark hm(THREAD);
|
||||
HandleMark hm(current);
|
||||
for (int i = 0; i < info->_num_loader_constraints; i++) {
|
||||
RunTimeSharedClassInfo::RTLoaderConstraint* lc = info->loader_constraint_at(i);
|
||||
Symbol* name = lc->constraint_name();
|
||||
Handle loader1(THREAD, get_class_loader_by(lc->_loader_type1));
|
||||
Handle loader2(THREAD, get_class_loader_by(lc->_loader_type2));
|
||||
Handle loader1(current, get_class_loader_by(lc->_loader_type1));
|
||||
Handle loader2(current, get_class_loader_by(lc->_loader_type2));
|
||||
if (log.is_enabled()) {
|
||||
ResourceMark rm(THREAD);
|
||||
ResourceMark rm(current);
|
||||
log.print("[CDS add loader constraint for class %s symbol %s loader[0] %s loader[1] %s",
|
||||
klass->external_name(), name->as_C_string(),
|
||||
ClassLoaderData::class_loader_data(loader1())->loader_name_and_id(),
|
||||
ClassLoaderData::class_loader_data(loader2())->loader_name_and_id());
|
||||
}
|
||||
if (!SystemDictionary::add_loader_constraint(name, klass, loader1, loader2, THREAD)) {
|
||||
if (!SystemDictionary::add_loader_constraint(name, klass, loader1, loader2)) {
|
||||
// Loader constraint violation has been found. The caller
|
||||
// will re-layout the vtable/itables to produce the correct
|
||||
// exception.
|
||||
|
@ -1918,7 +1919,7 @@ bool SystemDictionaryShared::check_linking_constraints(InstanceKlass* klass, TRA
|
|||
}
|
||||
}
|
||||
if (log.is_enabled()) {
|
||||
ResourceMark rm(THREAD);
|
||||
ResourceMark rm(current);
|
||||
log.print("[CDS has not recorded loader constraint for class %s]", klass->external_name());
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -297,9 +297,9 @@ public:
|
|||
static InstanceKlass* get_shared_nest_host(InstanceKlass* lambda_ik) NOT_CDS_RETURN_(NULL);
|
||||
static InstanceKlass* prepare_shared_lambda_proxy_class(InstanceKlass* lambda_ik,
|
||||
InstanceKlass* caller_ik, TRAPS) NOT_CDS_RETURN_(NULL);
|
||||
static bool check_linking_constraints(InstanceKlass* klass, TRAPS) NOT_CDS_RETURN_(false);
|
||||
static bool check_linking_constraints(Thread* current, InstanceKlass* klass) NOT_CDS_RETURN_(false);
|
||||
static void record_linking_constraint(Symbol* name, InstanceKlass* klass,
|
||||
Handle loader1, Handle loader2, TRAPS) NOT_CDS_RETURN;
|
||||
Handle loader1, Handle loader2) NOT_CDS_RETURN;
|
||||
static bool is_builtin(InstanceKlass* k) {
|
||||
return (k->shared_classpath_index() != UNREGISTERED_INDEX);
|
||||
}
|
||||
|
|
|
@ -675,7 +675,7 @@ void LinkResolver::check_method_loader_constraints(const LinkInfo& link_info,
|
|||
SystemDictionary::check_signature_loaders(link_info.signature(),
|
||||
/*klass_being_linked*/ NULL, // We are not linking class
|
||||
current_loader,
|
||||
resolved_loader, true, CHECK);
|
||||
resolved_loader, true);
|
||||
if (failed_type_symbol != NULL) {
|
||||
Klass* current_class = link_info.current_klass();
|
||||
ClassLoaderData* current_loader_data = current_class->class_loader_data();
|
||||
|
@ -712,8 +712,7 @@ void LinkResolver::check_field_loader_constraints(Symbol* field, Symbol* sig,
|
|||
SystemDictionary::check_signature_loaders(sig,
|
||||
/*klass_being_linked*/ NULL, // We are not linking class
|
||||
ref_loader, sel_loader,
|
||||
false,
|
||||
CHECK);
|
||||
false);
|
||||
if (failed_type_symbol != NULL) {
|
||||
stringStream ss;
|
||||
const char* failed_type_name = failed_type_symbol->as_klass_external_name();
|
||||
|
|
|
@ -1255,8 +1255,8 @@ Klass* JVMCIRuntime::get_klass_by_name_impl(Klass*& accessing_klass,
|
|||
return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local);
|
||||
}
|
||||
|
||||
Handle loader(THREAD, (oop)NULL);
|
||||
Handle domain(THREAD, (oop)NULL);
|
||||
Handle loader;
|
||||
Handle domain;
|
||||
if (accessing_klass != NULL) {
|
||||
loader = Handle(THREAD, accessing_klass->class_loader());
|
||||
domain = Handle(THREAD, accessing_klass->protection_domain());
|
||||
|
@ -1265,9 +1265,9 @@ Klass* JVMCIRuntime::get_klass_by_name_impl(Klass*& accessing_klass,
|
|||
Klass* found_klass;
|
||||
{
|
||||
ttyUnlocker ttyul; // release tty lock to avoid ordering problems
|
||||
MutexLocker ml(Compile_lock);
|
||||
MutexLocker ml(THREAD, Compile_lock);
|
||||
if (!require_local) {
|
||||
found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, THREAD);
|
||||
found_klass = SystemDictionary::find_constrained_instance_or_array_klass(THREAD, sym, loader);
|
||||
} else {
|
||||
found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain);
|
||||
}
|
||||
|
|
|
@ -984,7 +984,7 @@ bool InstanceKlass::link_class_impl(TRAPS) {
|
|||
// 1) the class is loaded by custom class loader or
|
||||
// 2) the class is loaded by built-in class loader but failed to add archived loader constraints
|
||||
bool need_init_table = true;
|
||||
if (is_shared() && SystemDictionaryShared::check_linking_constraints(this, THREAD)) {
|
||||
if (is_shared() && SystemDictionaryShared::check_linking_constraints(THREAD, this)) {
|
||||
need_init_table = false;
|
||||
}
|
||||
if (need_init_table) {
|
||||
|
|
|
@ -525,7 +525,7 @@ bool klassVtable::update_inherited_vtable(const methodHandle& target_method,
|
|||
Symbol* failed_type_symbol =
|
||||
SystemDictionary::check_signature_loaders(signature, _klass,
|
||||
target_loader, super_loader,
|
||||
true, CHECK_(false));
|
||||
true);
|
||||
if (failed_type_symbol != NULL) {
|
||||
stringStream ss;
|
||||
ss.print("loader constraint violation for class %s: when selecting "
|
||||
|
@ -1269,7 +1269,7 @@ void klassItable::initialize_itable_for_interface(int method_table_offset, Insta
|
|||
_klass,
|
||||
method_holder_loader,
|
||||
interface_loader,
|
||||
true, CHECK);
|
||||
true);
|
||||
if (failed_type_symbol != NULL) {
|
||||
stringStream ss;
|
||||
ss.print("loader constraint violation in interface itable"
|
||||
|
|
|
@ -320,8 +320,7 @@ Klass* ObjArrayKlass::array_klass_impl(bool or_null, int n, TRAPS) {
|
|||
if (higher_dimension_acquire() == NULL) {
|
||||
if (or_null) return NULL;
|
||||
|
||||
ResourceMark rm;
|
||||
JavaThread *jt = THREAD->as_Java_thread();
|
||||
ResourceMark rm(THREAD);
|
||||
{
|
||||
// Ensure atomic creation of higher dimensions
|
||||
MutexLocker mu(THREAD, MultiArray_lock);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue