8174823: Module system implementation refresh (3/2017)
authoralanb
Wed, 22 Mar 2017 16:26:09 +0000
changeset 44326 6c59cca7ff07
parent 44204 8490172c1777
child 44327 88f5f676e22b
8174823: Module system implementation refresh (3/2017) Reviewed-by: sspitsyn, dholmes, lfoltan, mchung
hotspot/src/share/vm/classfile/moduleEntry.hpp
hotspot/src/share/vm/classfile/modules.cpp
hotspot/src/share/vm/classfile/vmSymbols.hpp
hotspot/src/share/vm/oops/instanceKlass.cpp
hotspot/src/share/vm/runtime/arguments.cpp
hotspot/src/share/vm/runtime/java.cpp
hotspot/src/share/vm/runtime/java.hpp
hotspot/src/share/vm/runtime/thread.cpp
--- a/hotspot/src/share/vm/classfile/moduleEntry.hpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/classfile/moduleEntry.hpp	Wed Mar 22 16:26:09 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
+ * 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
@@ -36,8 +36,8 @@
 #include "utilities/ostream.hpp"
 
 #define UNNAMED_MODULE "Unnamed Module"
-#define JAVAPKG "java/"
-#define JAVAPKG_LEN 5
+#define JAVAPKG "java"
+#define JAVAPKG_LEN 4
 #define JAVA_BASE_NAME "java.base"
 
 class ModuleClosure;
--- a/hotspot/src/share/vm/classfile/modules.cpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/classfile/modules.cpp	Wed Mar 22 16:26:09 2017 +0000
@@ -325,7 +325,8 @@
     // Only modules defined to either the boot or platform class loader, can define a "java/" package.
     if (!h_loader.is_null() &&
         !SystemDictionary::is_platform_class_loader(h_loader) &&
-        strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0) {
+        (strncmp(package_name, JAVAPKG, JAVAPKG_LEN) == 0 &&
+          (package_name[JAVAPKG_LEN] == '/' || package_name[JAVAPKG_LEN] == '\0'))) {
       const char* class_loader_name = SystemDictionary::loader_name(h_loader());
       size_t pkg_len = strlen(package_name);
       char* pkg_name = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, pkg_len);
@@ -748,7 +749,8 @@
   // 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) {
+      (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);
--- a/hotspot/src/share/vm/classfile/vmSymbols.hpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/classfile/vmSymbols.hpp	Wed Mar 22 16:26:09 2017 +0000
@@ -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
@@ -561,6 +561,7 @@
   template(int_StringBuffer_signature,                "(I)Ljava/lang/StringBuffer;")                              \
   template(char_StringBuffer_signature,               "(C)Ljava/lang/StringBuffer;")                              \
   template(int_String_signature,                      "(I)Ljava/lang/String;")                                    \
+  template(boolean_boolean_int_signature,             "(ZZ)I")                                                    \
   template(codesource_permissioncollection_signature, "(Ljava/security/CodeSource;Ljava/security/PermissionCollection;)V") \
   /* signature symbols needed by intrinsics */                                                                    \
   VM_INTRINSICS_DO(VM_INTRINSIC_IGNORE, VM_SYMBOL_IGNORE, VM_SYMBOL_IGNORE, template, VM_ALIAS_IGNORE)            \
--- a/hotspot/src/share/vm/oops/instanceKlass.cpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/oops/instanceKlass.cpp	Wed Mar 22 16:26:09 2017 +0000
@@ -2456,22 +2456,24 @@
 void InstanceKlass::check_prohibited_package(Symbol* class_name,
                                              Handle class_loader,
                                              TRAPS) {
-  ResourceMark rm(THREAD);
   if (!class_loader.is_null() &&
       !SystemDictionary::is_platform_class_loader(class_loader) &&
-      class_name != NULL &&
-      strncmp(class_name->as_C_string(), JAVAPKG, JAVAPKG_LEN) == 0) {
-    TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
-    assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
-    char* name = pkg_name->as_C_string();
-    const char* class_loader_name = SystemDictionary::loader_name(class_loader());
-    StringUtils::replace_no_expand(name, "/", ".");
-    const char* msg_text1 = "Class loader (instance of): ";
-    const char* msg_text2 = " tried to load prohibited package name: ";
-    size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 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, name);
-    THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
+      class_name != NULL) {
+    ResourceMark rm(THREAD);
+    char* name = class_name->as_C_string();
+    if (strncmp(name, JAVAPKG, JAVAPKG_LEN) == 0 && name[JAVAPKG_LEN] == '/') {
+      TempNewSymbol pkg_name = InstanceKlass::package_from_name(class_name, CHECK);
+      assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
+      name = pkg_name->as_C_string();
+      const char* class_loader_name = SystemDictionary::loader_name(class_loader());
+      StringUtils::replace_no_expand(name, "/", ".");
+      const char* msg_text1 = "Class loader (instance of): ";
+      const char* msg_text2 = " tried to load prohibited package name: ";
+      size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 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, name);
+      THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
+    }
   }
   return;
 }
--- a/hotspot/src/share/vm/runtime/arguments.cpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.cpp	Wed Mar 22 16:26:09 2017 +0000
@@ -2932,6 +2932,10 @@
       if (res != JNI_OK) {
         return res;
       }
+    } else if (match_option(option, "--permit-illegal-access")) {
+      if (!create_property("jdk.module.permitIllegalAccess", "true", ExternalProperty)) {
+        return JNI_ENOMEM;
+      }
     // -agentlib and -agentpath
     } else if (match_option(option, "-agentlib:", &tail) ||
           (is_absolute_path = match_option(option, "-agentpath:", &tail))) {
--- a/hotspot/src/share/vm/runtime/java.cpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/runtime/java.cpp	Wed Mar 22 16:26:09 2017 +0000
@@ -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
@@ -621,6 +621,13 @@
   }
 }
 
+void vm_exit_during_initialization() {
+  vm_notify_during_shutdown(NULL, NULL);
+
+  // Failure during initialization, we don't want to dump core
+  vm_abort(false);
+}
+
 void vm_exit_during_initialization(Handle exception) {
   tty->print_cr("Error occurred during initialization of VM");
   // If there are exceptions on this thread it must be cleared
--- a/hotspot/src/share/vm/runtime/java.hpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/runtime/java.hpp	Wed Mar 22 16:26:09 2017 +0000
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2015, 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
@@ -45,6 +45,7 @@
 extern void notify_vm_shutdown();
 
 // VM exit if error occurs during initialization of VM
+extern void vm_exit_during_initialization();
 extern void vm_exit_during_initialization(Handle exception);
 extern void vm_exit_during_initialization(Symbol* exception_name, const char* message);
 extern void vm_exit_during_initialization(const char* error, const char* message = NULL);
--- a/hotspot/src/share/vm/runtime/thread.cpp	Thu Mar 16 16:34:34 2017 +0000
+++ b/hotspot/src/share/vm/runtime/thread.cpp	Wed Mar 22 16:26:09 2017 +0000
@@ -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
@@ -3409,9 +3409,16 @@
   Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
   instanceKlassHandle klass (THREAD, k);
 
-  JavaValue result(T_VOID);
+  JavaValue result(T_INT);
+  JavaCallArguments args;
+  args.push_int(DisplayVMOutputToStderr);
+  args.push_int(log_is_enabled(Debug, init)); // print stack trace if exception thrown
   JavaCalls::call_static(&result, klass, vmSymbols::initPhase2_name(),
-                                         vmSymbols::void_method_signature(), CHECK);
+                                         vmSymbols::boolean_boolean_int_signature(), &args, CHECK);
+  if (result.get_jint() != JNI_OK) {
+    vm_exit_during_initialization(); // no message or exception
+  }
+
   universe_post_module_init();
 }