8241815: Unnecessary calls to SystemDictionaryShared::define_shared_package

Avoid calling ClassLoaders.definePackage during loading of shared classes originated from the module image since java.lang.Package for named modules are automatically defined.

Reviewed-by: mchung, lfoltan
This commit is contained in:
Calvin Cheung 2020-04-28 00:09:53 +00:00
parent 03f8e6ccd8
commit 18c43241fb
4 changed files with 6 additions and 63 deletions

View File

@ -480,37 +480,6 @@ void SystemDictionaryShared::define_shared_package(Symbol* class_name,
}
}
// Define Package for shared app/platform classes from named module
void SystemDictionaryShared::define_shared_package(Symbol* class_name,
Handle class_loader,
ModuleEntry* mod_entry,
TRAPS) {
assert(mod_entry != NULL, "module_entry should not be NULL");
Handle module_handle(THREAD, mod_entry->module());
Handle pkg_name = get_package_name(class_name, CHECK);
assert(pkg_name.not_null(), "Package should not be null for class in named module");
Klass* classLoader_klass;
if (SystemDictionary::is_system_class_loader(class_loader())) {
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_AppClassLoader_klass();
} else {
assert(SystemDictionary::is_platform_class_loader(class_loader()), "unexpected classloader");
classLoader_klass = SystemDictionary::jdk_internal_loader_ClassLoaders_PlatformClassLoader_klass();
}
JavaValue result(T_OBJECT);
JavaCallArguments args(2);
args.set_receiver(class_loader);
args.push_oop(pkg_name);
args.push_oop(module_handle);
JavaCalls::call_virtual(&result, classLoader_klass,
vmSymbols::definePackage_name(),
vmSymbols::definePackage_signature(),
&args,
CHECK);
}
// Get the ProtectionDomain associated with the CodeSource from the classloader.
Handle SystemDictionaryShared::get_protection_domain_from_classloader(Handle class_loader,
Handle url, TRAPS) {
@ -599,11 +568,11 @@ Handle SystemDictionaryShared::init_security_info(Handle class_loader, InstanceK
// For shared app/platform classes originated from the run-time image:
// The ProtectionDomains are cached in the corresponding ModuleEntries
// for fast access by the VM.
if (pkg_entry != NULL) {
ModuleEntry* mod_entry = pkg_entry->module();
pd = get_shared_protection_domain(class_loader, mod_entry, THREAD);
define_shared_package(class_name, class_loader, mod_entry, CHECK_(pd));
}
// all packages from module image are already created during VM bootstrap in
// Modules::define_module().
assert(pkg_entry != NULL, "archived class in module image cannot be from unnamed package");
ModuleEntry* mod_entry = pkg_entry->module();
pd = get_shared_protection_domain(class_loader, mod_entry, THREAD);
} else {
// For shared app/platform classes originated from JAR files on the class path:
// Each of the 3 SystemDictionaryShared::_shared_xxx arrays has the same length

View File

@ -167,10 +167,6 @@ private:
Handle manifest,
Handle url,
TRAPS);
static void define_shared_package(Symbol* class_name,
Handle class_loader,
ModuleEntry* mod_entry,
TRAPS);
static Handle get_shared_jar_manifest(int shared_path_index, TRAPS);
static Handle get_shared_jar_url(int shared_path_index, TRAPS);

View File

@ -436,8 +436,6 @@
template(input_stream_signature, "Ljava/io/InputStream;") \
template(print_stream_signature, "Ljava/io/PrintStream;") \
template(security_manager_signature, "Ljava/lang/SecurityManager;") \
template(definePackage_name, "definePackage") \
template(definePackage_signature, "(Ljava/lang/String;Ljava/lang/Module;)Ljava/lang/Package;") \
template(defineOrCheckPackage_name, "defineOrCheckPackage") \
template(defineOrCheckPackage_signature, "(Ljava/lang/String;Ljava/util/jar/Manifest;Ljava/net/URL;)Ljava/lang/Package;") \
template(fileToEncodedURL_name, "fileToEncodedURL") \

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 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
@ -132,16 +132,6 @@ public class ClassLoaders {
PlatformClassLoader(BootClassLoader parent) {
super("platform", parent, null);
}
/**
* Called by the VM to support define package for AppCDS.
*
* Shared classes are returned in ClassLoader::findLoadedClass
* that bypass the defineClass call.
*/
private Package definePackage(String pn, Module module) {
return JLA.definePackage(this, pn, module);
}
}
/**
@ -194,16 +184,6 @@ public class ClassLoaders {
ucp.addFile(path);
}
/**
* Called by the VM to support define package for AppCDS
*
* Shared classes are returned in ClassLoader::findLoadedClass
* that bypass the defineClass call.
*/
private Package definePackage(String pn, Module module) {
return JLA.definePackage(this, pn, module);
}
/**
* Called by the VM to support define package for AppCDS
*/