Skip to content
Permalink
Browse files

8178349: Cache builtin class loader constraints to avoid re-initializ…

…ing itable/vtable for shared classes

Record loader constraints for built-in class which is loaded by app loader or platform loader in shared archive in dump time.  When the class loaded from shared archive at runtime, directly check loader constraints using the saved info so avoid lengthy relayout i/v-table at class link stage.

Reviewed-by: iklam, ccheung
  • Loading branch information
yminqi committed May 1, 2020
1 parent eaf3306 commit 832272da71fa7a067a11a3f736037b25a7da7fa8
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2020, 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
@@ -61,6 +61,7 @@ class LoaderConstraintTable : public Hashtable<InstanceKlass*, mtClass> {

// Note: The main entry point for this module is via SystemDictionary.
// SystemDictionary::check_signature_loaders(Symbol* signature,
// Klass* klass_being_linked,
// Handle loader1, Handle loader2,
// bool is_method, TRAPS)

@@ -2297,8 +2297,8 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
return klass;
}


bool SystemDictionary::add_loader_constraint(Symbol* class_name,
Klass* klass_being_linked,
Handle class_loader1,
Handle class_loader2,
Thread* THREAD) {
@@ -2336,6 +2336,12 @@ bool SystemDictionary::add_loader_constraint(Symbol* class_name,
InstanceKlass* klass2 = find_class(d_hash2, constraint_name, dictionary2);
bool result = constraints()->add_entry(constraint_name, klass1, class_loader1,
klass2, class_loader2);
if (Arguments::is_dumping_archive() && klass_being_linked != NULL &&
!klass_being_linked->is_shared()) {
SystemDictionaryShared::record_linking_constraint(constraint_name,
InstanceKlass::cast(klass_being_linked),
class_loader1, class_loader2, THREAD);
}
if (Signature::is_array(class_name)) {
constraint_name->decrement_refcount();
}
@@ -2457,14 +2463,15 @@ const char* SystemDictionary::find_nest_host_error(const constantPoolHandle& poo
// called (perhaps via an override) from the supertype.
//
//
// SystemDictionary::check_signature_loaders(sig, l1, l2)
// SystemDictionary::check_signature_loaders(sig, klass_being_linked, l1, l2)
//
// Make sure all class components (including arrays) in the given
// signature will be resolved to the same class in both loaders.
// Returns the name of the type that failed a loader constraint check, or
// NULL if no constraint failed. 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) {
// Nothing to do if loaders are the same.
@@ -2478,15 +2485,14 @@ 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, loader1, loader2, THREAD)) {
if (!add_loader_constraint(sig, klass_being_linked, loader1, loader2, THREAD)) {
return sig;
}
}
}
return NULL;
}


Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
Symbol* signature,
TRAPS) {
@@ -494,10 +494,10 @@ class SystemDictionary : AllStatic {
// Note: java_lang_Class::primitive_type is the inverse of java_mirror

// Check class loader constraints
static bool add_loader_constraint(Symbol* name, Handle loader1,
static bool add_loader_constraint(Symbol* name, Klass* klass_being_linked, Handle loader1,
Handle loader2, TRAPS);
static Symbol* check_signature_loaders(Symbol* signature, Handle loader1,
Handle loader2, bool is_method, TRAPS);
static Symbol* check_signature_loaders(Symbol* signature, Klass* klass_being_linked,
Handle loader1, Handle loader2, bool is_method, TRAPS);

// JSR 292
// find a java.lang.invoke.MethodHandle.invoke* method for a given signature
@@ -656,7 +656,12 @@ class SystemDictionary : AllStatic {
public:
static bool is_system_class_loader(oop class_loader);
static bool is_platform_class_loader(oop class_loader);

static bool is_boot_class_loader(oop class_loader) { return class_loader == NULL; }
static bool is_builtin_class_loader(oop class_loader) {
return is_boot_class_loader(class_loader) ||
is_platform_class_loader(class_loader) ||
is_system_class_loader(class_loader);
}
// Returns TRUE if the method is a non-public member of class java.lang.Object.
static bool is_nonpublic_Object_method(Method* m) {
assert(m != NULL, "Unexpected NULL Method*");

0 comments on commit 832272d

Please sign in to comment.