changeset 59023:b92b43bbcce3

8241815: Unnecessary calls to SystemDictionaryShared::define_shared_package Summary: 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
author ccheung
date Tue, 28 Apr 2020 00:09:53 +0000
parents aa0217568f78
children feec7e7df3e9
files src/hotspot/share/classfile/systemDictionaryShared.cpp src/hotspot/share/classfile/systemDictionaryShared.hpp src/hotspot/share/classfile/vmSymbols.hpp src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java
diffstat 4 files changed, 6 insertions(+), 63 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/classfile/systemDictionaryShared.cpp	Mon Apr 27 14:23:15 2020 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.cpp	Tue Apr 28 00:09:53 2020 +0000
@@ -480,37 +480,6 @@
   }
 }
 
-// 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 @@
       // 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
--- a/src/hotspot/share/classfile/systemDictionaryShared.hpp	Mon Apr 27 14:23:15 2020 -0700
+++ b/src/hotspot/share/classfile/systemDictionaryShared.hpp	Tue Apr 28 00:09:53 2020 +0000
@@ -167,10 +167,6 @@
                                     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);
--- a/src/hotspot/share/classfile/vmSymbols.hpp	Mon Apr 27 14:23:15 2020 -0700
+++ b/src/hotspot/share/classfile/vmSymbols.hpp	Tue Apr 28 00:09:53 2020 +0000
@@ -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")                         \
--- a/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Mon Apr 27 14:23:15 2020 -0700
+++ b/src/java.base/share/classes/jdk/internal/loader/ClassLoaders.java	Tue Apr 28 00:09:53 2020 +0000
@@ -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 @@
         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);
-        }
     }
 
     /**
@@ -196,16 +186,6 @@
 
         /**
          * 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
          */
         protected Package defineOrCheckPackage(String pn, Manifest man, URL url) {
             return super.defineOrCheckPackage(pn, man, url);