8172307: Remove ununsed JVM API JVM_GetModuleByPackageName()
authorhseigel
Wed, 01 Mar 2017 07:59:20 -0500
changeset 46296 15ba6edb7910
parent 46295 6092ca55b77b
child 46299 ebd21762a028
8172307: Remove ununsed JVM API JVM_GetModuleByPackageName() Summary: Remove get_module_by_package_name() etc., and unneeded test. Reviewed-by: sspitsyn, gtriantafill
hotspot/src/share/vm/classfile/modules.cpp
hotspot/src/share/vm/classfile/modules.hpp
hotspot/src/share/vm/prims/whitebox.cpp
hotspot/test/runtime/modules/JVMGetModuleByPkgName.java
hotspot/test/runtime/modules/ModuleHelper.java
--- a/hotspot/src/share/vm/classfile/modules.cpp	Mon Oct 24 14:51:16 2016 +0200
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Wed Mar 01 07:59:20 2017 -0500
@@ -649,39 +649,6 @@
   return JNIHandles::make_local(THREAD, module);
 }
 
-
-jobject Modules::get_module_by_package_name(jobject loader, const char* package_name, TRAPS) {
-  ResourceMark rm(THREAD);
-  assert(ModuleEntryTable::javabase_defined(),
-         "Attempt to call get_module_from_pkg before " JAVA_BASE_NAME " is defined");
-
-  if (package_name == NULL) {
-    THROW_MSG_(vmSymbols::java_lang_NullPointerException(),
-               "package is null", JNI_FALSE);
-  }
-
-  Handle h_loader (THREAD, JNIHandles::resolve(loader));
-  // Check that loader is a subclass of java.lang.ClassLoader.
-  if (loader != NULL && !java_lang_ClassLoader::is_subclass(h_loader->klass())) {
-    THROW_MSG_(vmSymbols::java_lang_IllegalArgumentException(),
-               "Class loader is not a subclass of java.lang.ClassLoader", JNI_FALSE);
-  }
-
-  if (strlen(package_name) == 0) {
-    // Return the unnamed module
-    ModuleEntryTable* module_table = get_module_entry_table(h_loader, CHECK_NULL);
-    if (NULL == module_table) return NULL;
-    const ModuleEntry* const unnamed_module = module_table->unnamed_module();
-    return JNIHandles::make_local(THREAD, JNIHandles::resolve(unnamed_module->module()));
-
-  } else {
-    TempNewSymbol package_sym = SymbolTable::new_symbol(package_name, CHECK_NULL);
-    return get_module(package_sym, h_loader, CHECK_NULL);
-  }
-  return NULL;
-}
-
-
 jobject Modules::get_named_module(Handle h_loader, const char* package_name, TRAPS) {
   assert(ModuleEntryTable::javabase_defined(),
          "Attempt to call get_named_module before " JAVA_BASE_NAME " is defined");
--- a/hotspot/src/share/vm/classfile/modules.hpp	Mon Oct 24 14:51:16 2016 +0200
+++ b/hotspot/src/share/vm/classfile/modules.hpp	Wed Mar 01 07:59:20 2017 -0500
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+* Copyright (c) 2017, 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
@@ -105,7 +105,6 @@
   // NullPointerException is thrown if package is null.
   // IllegalArgumentException is thrown if loader is neither null nor a subtype of
   // java/lang/ClassLoader.
-  static jobject get_module_by_package_name(jobject loader, const char* package, TRAPS);
   static jobject get_named_module(Handle h_loader, const char* package, TRAPS);
 
   // If package is defined by loader, return the
--- a/hotspot/src/share/vm/prims/whitebox.cpp	Mon Oct 24 14:51:16 2016 +0200
+++ b/hotspot/src/share/vm/prims/whitebox.cpp	Wed Mar 01 07:59:20 2017 -0500
@@ -1466,15 +1466,6 @@
   Modules::add_module_package(module, package_name, CHECK);
 WB_END
 
-WB_ENTRY(jobject, WB_GetModuleByPackageName(JNIEnv* env, jobject o, jobject loader, jstring package))
-  ResourceMark rm(THREAD);
-  char* package_name = NULL;
-  if (package != NULL) {
-      package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
-  }
-  return Modules::get_module_by_package_name(loader, package_name, THREAD);
-WB_END
-
 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
   if (inc < 0) {
     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
@@ -1912,8 +1903,6 @@
                                                       (void*)&WB_AddReadsModule },
   {CC"AddModulePackage",   CC"(Ljava/lang/Object;Ljava/lang/String;)V",
                                                       (void*)&WB_AddModulePackage },
-  {CC"GetModuleByPackageName", CC"(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;",
-                                                      (void*)&WB_GetModuleByPackageName },
   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
--- a/hotspot/test/runtime/modules/JVMGetModuleByPkgName.java	Mon Oct 24 14:51:16 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-/*
- * Copyright (c) 2016, 2017, 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
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation.
- *
- * This code is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
- * or visit www.oracle.com if you need additional information or have any
- * questions.
- */
-
-/*
- * @test
- * @modules java.base/jdk.internal.misc
- * @library /test/lib ..
- * @compile p2/c2.java
- * @build sun.hotspot.WhiteBox
- * @compile/module=java.base java/lang/reflect/ModuleHelper.java
- * @run main ClassFileInstaller sun.hotspot.WhiteBox
- *                              sun.hotspot.WhiteBox$WhiteBoxPermission
- * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMGetModuleByPkgName
- */
-
-import static jdk.test.lib.Asserts.*;
-import java.lang.ClassLoader;
-import java.lang.reflect.Module;
-
-public class JVMGetModuleByPkgName {
-
-    public static void main(String args[]) throws Throwable {
-
-        Module javaBase = ModuleHelper.GetModuleByPackageName(null, "java/lang");
-        if (!javaBase.getName().equals("java.base")) {
-            throw new RuntimeException(
-                "Failed to get module java.base for package java/lang");
-        }
-
-        if (ModuleHelper.GetModuleByPackageName(null, "bad.package.name") != null) {
-            throw new RuntimeException("Failed to get null for bad.package.name");
-        }
-
-        ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
-        if (ModuleHelper.GetModuleByPackageName(systemLoader, "java/lang") != null) {
-            throw new RuntimeException(
-                "Failed to get null for systemClassLoader and java/lang");
-        }
-
-        try {
-            ModuleHelper.GetModuleByPackageName(systemLoader, null);
-            throw new RuntimeException(
-                "Failed to throw NullPointerException for null package name");
-        } catch(NullPointerException e) {
-             // Expected
-        }
-
-        Module unnamedModule = ModuleHelper.GetModuleByPackageName(systemLoader, "");
-        if (unnamedModule.isNamed()) {
-            throw new RuntimeException(
-                "Unexpected named module returned for unnamed package");
-        }
-
-        p2.c2 obj = new p2.c2();
-        unnamedModule = ModuleHelper.GetModuleByPackageName(systemLoader, "p2");
-        if (unnamedModule.isNamed()) {
-            throw new RuntimeException(
-                "Unexpected named module returned for package p2 in unnamed module");
-        }
-
-        MyClassLoader cl1 = new MyClassLoader();
-        Module module_one = (Module)ModuleHelper.ModuleObject("module_one", cl1, new String[] { "mypackage" });
-        assertNotNull(module_one, "Module should not be null");
-        ModuleHelper.DefineModule(module_one, "9.0", "module_one/here", new String[] { "mypackage" });
-        if (ModuleHelper.GetModuleByPackageName(cl1, "mypackage") != module_one) {
-            throw new RuntimeException("Wrong module returned for cl1 mypackage");
-        }
-    }
-
-    static class MyClassLoader extends ClassLoader { }
-}
--- a/hotspot/test/runtime/modules/ModuleHelper.java	Mon Oct 24 14:51:16 2016 +0200
+++ b/hotspot/test/runtime/modules/ModuleHelper.java	Wed Mar 01 07:59:20 2017 -0500
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2015, 2017, 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
@@ -56,11 +56,6 @@
         java.lang.reflect.ModuleHelper.addPackageNoSync((Module)m, pkg);
     }
 
-    public static Module GetModuleByPackageName(Object ldr, String pkg) throws Throwable {
-        WhiteBox wb = WhiteBox.getWhiteBox();
-        return (Module)wb.GetModuleByPackageName(ldr, pkg);
-    }
-
     public static void AddModuleExportsToAllUnnamed(Object m, String pkg) throws Throwable {
         WhiteBox wb = WhiteBox.getWhiteBox();
         wb.AddModuleExportsToAllUnnamed(m, pkg);