This commit is contained in:
Alan Bateman 2017-06-17 08:03:09 +01:00
commit a0a5208606
10 changed files with 4 additions and 272 deletions

View File

@ -188,7 +188,6 @@ JVM_Yield
JVM_AddModuleExports
JVM_AddModuleExportsToAll
JVM_AddModuleExportsToAllUnnamed
JVM_AddModulePackage
JVM_AddReadsModule
JVM_DefineModule
JVM_SetBootLoaderUnnamedModule

View File

@ -722,74 +722,6 @@ jobject Modules::get_module(Symbol* package_name, Handle h_loader, TRAPS) {
return NULL;
}
void Modules::add_module_package(jobject module, const char* package_name, TRAPS) {
ResourceMark rm(THREAD);
if (module == NULL) {
THROW_MSG(vmSymbols::java_lang_NullPointerException(),
"module is null");
}
if (package_name == NULL) {
THROW_MSG(vmSymbols::java_lang_NullPointerException(),
"package is null");
}
ModuleEntry* module_entry = get_module_entry(module, CHECK);
if (module_entry == NULL) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"module is invalid");
}
if (!module_entry->is_named()) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
"module cannot be an unnamed module");
}
if (!verify_package_name(package_name)) {
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
err_msg("Invalid package name: %s", package_name));
}
ClassLoaderData *loader_data = module_entry->loader_data();
// Only modules defined to either the boot or platform class loader, can define a "java/" package.
if (!loader_data->is_the_null_class_loader_data() &&
!loader_data->is_platform_class_loader_data() &&
(strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
(package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
const char* class_loader_name = SystemDictionary::loader_name(loader_data);
size_t pkg_len = strlen(package_name);
char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
strncpy(pkg_name, package_name, pkg_len);
StringUtils::replace_no_expand(pkg_name, "/", ".");
const char* msg_text1 = "Class loader (instance of): ";
const char* msg_text2 = " tried to define prohibited package name: ";
size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + pkg_len + 1;
char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, pkg_name);
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), message);
}
log_debug(module)("add_module_package(): Adding package %s to module %s",
package_name, module_entry->name()->as_C_string());
TempNewSymbol pkg_symbol = SymbolTable::new_symbol(package_name, CHECK);
PackageEntryTable* package_table = loader_data->packages();
assert(package_table != NULL, "Missing package_table");
PackageEntry* existing_pkg = NULL;
{
MutexLocker ml(Module_lock, THREAD);
// Check that the package does not exist in the class loader's package table.
existing_pkg = package_table->lookup_only(pkg_symbol);
if (existing_pkg == NULL) {
PackageEntry* pkg = package_table->locked_create_entry_or_null(pkg_symbol, module_entry);
assert(pkg != NULL, "Unable to create a module's package entry");
}
}
if (existing_pkg != NULL) {
throw_dup_pkg_exception(module_entry->name()->as_C_string(), existing_pkg, CHECK);
}
}
// Export package in module to all unnamed modules.
void Modules::add_module_exports_to_all_unnamed(jobject module, const char* package_name, TRAPS) {
if (module == NULL) {

View File

@ -113,14 +113,6 @@ public:
// Returns NULL if package is invalid or not defined by loader.
static jobject get_module(Symbol* package_name, Handle h_loader, TRAPS);
// This adds package to module.
// It throws IllegalArgumentException if:
// * Module is bad
// * Module is unnamed
// * Package is not syntactically correct
// * Package is already defined for module's class loader.
static void add_module_package(jobject module, const char* package, TRAPS);
// Marks the specified package as exported to all unnamed modules.
// If either module or package is null then NullPointerException is thrown.
// If module or package is bad, or module is unnamed, or package is not in

View File

@ -1039,11 +1039,6 @@ JVM_ENTRY (void, JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject so
Modules::add_reads_module(from_module, source_module, CHECK);
JVM_END
JVM_ENTRY (void, JVM_AddModulePackage(JNIEnv *env, jobject module, const char* package))
JVMWrapper("JVM_AddModulePackage");
Modules::add_module_package(module, package, CHECK);
JVM_END
// Reflection support //////////////////////////////////////////////////////////////////////////////
JVM_ENTRY(jstring, JVM_GetClassName(JNIEnv *env, jclass cls))

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 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
@ -466,14 +466,6 @@ JVM_AddModuleExportsToAll(JNIEnv *env, jobject from_module, const char* package)
JNIEXPORT void JNICALL
JVM_AddReadsModule(JNIEnv *env, jobject from_module, jobject source_module);
/*
* Add a package to a module.
* module: module that will contain the package
* package: package to add to the module
*/
JNIEXPORT void JNICALL
JVM_AddModulePackage(JNIEnv* env, jobject module, const char* package);
/*
* Reflection support functions
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 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
@ -1457,15 +1457,6 @@ WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jo
Modules::add_reads_module(from_module, source_module, CHECK);
WB_END
WB_ENTRY(void, WB_AddModulePackage(JNIEnv* env, jobject o, jclass module, 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));
}
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;
@ -1910,8 +1901,6 @@ static JNINativeMethod methods[] = {
(void*)&WB_AddModuleExports },
{CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
(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",

View File

@ -2937,8 +2937,8 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args, bool* patch_m
if (res != JNI_OK) {
return res;
}
} else if (match_option(option, "--permit-illegal-access")) {
if (!create_property("jdk.module.permitIllegalAccess", "true", ExternalProperty)) {
} else if (match_option(option, "--illegal-access=", &tail)) {
if (!create_property("jdk.module.illegalAccess", tail, ExternalProperty)) {
return JNI_ENOMEM;
}
// -agentlib and -agentpath

View File

@ -1,154 +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 ..
* @build sun.hotspot.WhiteBox
* @compile/module=java.base java/lang/ModuleHelper.java
* @run main ClassFileInstaller sun.hotspot.WhiteBox
* sun.hotspot.WhiteBox$WhiteBoxPermission
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI JVMAddModulePackage
*/
import static jdk.test.lib.Asserts.*;
import java.sql.Time;
public class JVMAddModulePackage {
public static void main(String args[]) throws Throwable {
MyClassLoader cl1 = new MyClassLoader();
MyClassLoader cl3 = new MyClassLoader();
Object module_one, module_two, module_three;
boolean result;
module_one = 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" });
module_two = ModuleHelper.ModuleObject("module_two", cl1, new String[] { "yourpackage" });
assertNotNull(module_two, "Module should not be null");
ModuleHelper.DefineModule(module_two, "9.0", "module_two/here", new String[] { "yourpackage" });
module_three = ModuleHelper.ModuleObject("module_three", cl3, new String[] { "apackage/num3" });
assertNotNull(module_three, "Module should not be null");
ModuleHelper.DefineModule(module_three, "9.0", "module_three/here", new String[] { "apackage/num3" });
// Simple call
ModuleHelper.AddModulePackage(module_one, "new_package");
// Add a package and export it
ModuleHelper.AddModulePackage(module_one, "apackage/num3");
ModuleHelper.AddModuleExportsToAll(module_one, "apackage/num3");
// Null module argument, expect an NPE
try {
ModuleHelper.AddModulePackage(null, "new_package");
throw new RuntimeException("Failed to get the expected NPE");
} catch(NullPointerException e) {
// Expected
}
// Bad module argument, expect an IAE
try {
ModuleHelper.AddModulePackage(cl1, "new_package");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
}
// Null package argument, expect an NPE
try {
ModuleHelper.AddModulePackage(module_one, null);
throw new RuntimeException("Failed to get the expected NPE");
} catch(NullPointerException e) {
// Expected
}
// Existing package, expect an ISE
try {
ModuleHelper.AddModulePackage(module_one, "yourpackage");
throw new RuntimeException("Failed to get the expected ISE");
} catch(IllegalStateException e) {
// Expected
}
// Invalid package name, expect an IAE
try {
ModuleHelper.AddModulePackage(module_one, "your.apackage");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
}
// Invalid package name, expect an IAE
try {
ModuleHelper.AddModulePackage(module_one, ";your/apackage");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
}
// Invalid package name, expect an IAE
try {
ModuleHelper.AddModulePackage(module_one, "7[743");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
}
// Empty package name, expect an IAE
try {
ModuleHelper.AddModulePackage(module_one, "");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
// Expected
}
// Add package named "java" to an module defined to a class loader other than the boot or platform loader.
try {
// module_one is defined to a MyClassLoader class loader.
ModuleHelper.AddModulePackage(module_one, "java/foo");
throw new RuntimeException("Failed to get the expected IAE");
} catch(IllegalArgumentException e) {
if (!e.getMessage().contains("prohibited package name")) {
throw new RuntimeException("Failed to get expected IAE message for prohibited package name: " + e.getMessage());
}
}
// Package "javabar" should be ok
ModuleHelper.AddModulePackage(module_one, "javabar");
// Package named "java" defined to the boot class loader, should be ok
Object module_javabase = module_one.getClass().getModule();
ModuleHelper.AddModulePackage(module_javabase, "java/foo");
// Package named "java" defined to the platform class loader, should be ok
// The module java.sql is defined to the platform class loader.
java.sql.Time jst = new java.sql.Time(45000); // milliseconds
Object module_javasql = jst.getClass().getModule();
ModuleHelper.AddModulePackage(module_javasql, "java/foo");
}
static class MyClassLoader extends ClassLoader { }
}

View File

@ -49,12 +49,6 @@ public class ModuleHelper {
java.lang.ModuleHelper.addReadsNoSync((Module)from, (Module)to);
}
public static void AddModulePackage(Object m, String pkg) throws Throwable {
WhiteBox wb = WhiteBox.getWhiteBox();
wb.AddModulePackage(m, pkg);
java.lang.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);

View File

@ -63,11 +63,4 @@ public final class ModuleHelper {
}
}
/**
* Adds a package to a module without notifying the VM.
*/
public static void addPackageNoSync(Module m, String pkg) {
m.implAddPackageNoSync(pkg);
}
}