changeset 8054:c651edf2ab08

Add support for jdk.boot.class.path.append property
author hseigel
date Thu, 12 Mar 2015 19:55:07 -0400
parents 4c251362419a
children 651cd13f8cc2
files src/share/vm/classfile/classLoader.cpp src/share/vm/runtime/arguments.cpp src/share/vm/runtime/arguments.hpp src/share/vm/runtime/statSampler.cpp test/runtime/BootClassAppendProp/BootClassPathAppendProp.java
diffstat 5 files changed, 96 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classLoader.cpp	Mon Mar 09 09:39:52 2015 -0400
+++ b/src/share/vm/classfile/classLoader.cpp	Thu Mar 12 19:55:07 2015 -0400
@@ -722,7 +722,7 @@
     EXCEPTION_MARK;
     ResourceMark rm(THREAD);
     mark_append_entry = (mark_append_entry ||
-                         (bootstrap_search && (start == Arguments::bootclasspath_a_index())));
+      (bootstrap_search && (start == Arguments::bootclassloader_append_index())));
 
     char* path = NEW_RESOURCE_ARRAY(char, end - start + 1);
     strncpy(path, &class_path[start], end - start);
--- a/src/share/vm/runtime/arguments.cpp	Mon Mar 09 09:39:52 2015 -0400
+++ b/src/share/vm/runtime/arguments.cpp	Thu Mar 12 19:55:07 2015 -0400
@@ -87,7 +87,7 @@
 int    Arguments::_sun_java_launcher_pid        = -1;
 bool   Arguments::_sun_java_launcher_is_altjvm  = false;
 const char*  Arguments::_override_dir           = NULL;
-int    Arguments::_bootclasspath_a_index        = -1;
+int    Arguments::_bootclassloader_append_index = -1;
 
 // These parameters are reset in method parse_vm_init_args(JavaVMInitArgs*)
 bool   Arguments::_AlwaysCompileLoopMethods     = AlwaysCompileLoopMethods;
@@ -110,6 +110,7 @@
 SystemProperty *Arguments::_java_home = NULL;
 SystemProperty *Arguments::_java_class_path = NULL;
 SystemProperty *Arguments::_sun_boot_class_path = NULL;
+SystemProperty *Arguments::_jdk_boot_class_path_append = NULL;
 
 char* Arguments::_ext_dirs = NULL;
 
@@ -201,6 +202,7 @@
   _java_library_path = new SystemProperty("java.library.path", NULL,  true);
   _java_home =  new SystemProperty("java.home", NULL,  true);
   _sun_boot_class_path = new SystemProperty("sun.boot.class.path", NULL,  true);
+  _jdk_boot_class_path_append = new SystemProperty("jdk.boot.class.path.append", NULL, true);
 
   _java_class_path = new SystemProperty("java.class.path", "",  true);
 
@@ -209,8 +211,11 @@
   PropertyList_add(&_system_properties, _java_library_path);
   PropertyList_add(&_system_properties, _java_home);
   PropertyList_add(&_system_properties, _java_class_path);
+  // Delete the next line to set property sun.boot.class.path to NULL.
   PropertyList_add(&_system_properties, _sun_boot_class_path);
 
+  PropertyList_add(&_system_properties, _jdk_boot_class_path_append);
+
   // Set OS specific system properties values
   os::init_system_properties_values();
 }
@@ -461,7 +466,7 @@
   for (i = 0; i < _scp_nitems; ++i) {
     if (i == _scp_suffix) {
       // Record index of boot loader's append path.
-      Arguments::set_bootclasspath_a_index((int)total_len);
+      Arguments::set_bootclassloader_append_index((int)total_len);
     }
     if (_items[i] != NULL) {
       lengths[i] = strlen(_items[i]);
@@ -3349,6 +3354,18 @@
   return JNI_OK;
 }
 
+// Set property jdk.boot.class.path.append to the contents of the bootclasspath
+// that follows either the jimage file or exploded module directories.  The
+// property will contain -Xbootclasspath/a and/or jvmti appended additions.
+void Arguments::set_jdkbootclasspath_append() {
+  char *sysclasspath = get_sysclasspath();
+  assert(sysclasspath != NULL, "NULL sysclasspath");
+  int bcp_a_idx = bootclassloader_append_index();
+  if (bcp_a_idx != -1 && bcp_a_idx < (int)strlen(sysclasspath)) {
+    _jdk_boot_class_path_append->set_value(sysclasspath + bcp_a_idx);
+  }
+}
+
 // Remove all empty paths from the app classpath (if IgnoreEmptyClassPaths is enabled)
 //
 // This is necessary because some apps like to specify classpath like -cp foo.jar:${XYZ}:bar.jar
@@ -3483,7 +3500,7 @@
     // At this point in sysclasspath processing anything
     // added would be considered in the boot loader's append path.
     // Record this index, including +1 for the file separator character.
-    Arguments::set_bootclasspath_a_index(((int)strlen(Arguments::get_sysclasspath()))+1);
+    Arguments::set_bootclassloader_append_index(((int)strlen(Arguments::get_sysclasspath()))+1);
   }
 
   // This must be done after all arguments have been processed.
--- a/src/share/vm/runtime/arguments.hpp	Mon Mar 09 09:39:52 2015 -0400
+++ b/src/share/vm/runtime/arguments.hpp	Thu Mar 12 19:55:07 2015 -0400
@@ -259,6 +259,7 @@
   static SystemProperty *_java_home;
   static SystemProperty *_java_class_path;
   static SystemProperty *_sun_boot_class_path;
+  static SystemProperty *_jdk_boot_class_path_append;
 
   // temporary: to emit warning if the default ext dirs are not empty.
   // remove this variable when the warning is no longer needed.
@@ -315,7 +316,7 @@
   // Capture the index location of -Xbootclasspath\a within sysclasspath.
   // Used when setting up the bootstrap search path in order to
   // mark the boot loader's append path observability boundary.
-  static int _bootclasspath_a_index;
+  static int _bootclassloader_append_index;
 
   // -Xoverride flag
   static const char* _override_dir;
@@ -544,8 +545,12 @@
   static void  set_min_heap_size(uintx v)   { _min_heap_size = v;  }
 
   // -Xbootclasspath/a
-  static int  bootclasspath_a_index()              { return _bootclasspath_a_index; }
-  static void set_bootclasspath_a_index(int value) { _bootclasspath_a_index = value; }
+  static int  bootclassloader_append_index() {
+    return _bootclassloader_append_index;
+  }
+  static void set_bootclassloader_append_index(int value) {
+    _bootclassloader_append_index = value;
+  }
 
   // -Xoverride
   static const char* override_dir()         { return _override_dir; }
@@ -610,8 +615,15 @@
   static void set_java_home(char *value) { _java_home->set_value(value); }
   static void set_library_path(char *value) { _java_library_path->set_value(value); }
   static void set_ext_dirs(char *value)     { _ext_dirs = os::strdup_check_oom(value); }
-  static void set_sysclasspath(char *value) { _sun_boot_class_path->set_value(value); }
-  static void append_sysclasspath(const char *value) { _sun_boot_class_path->append_value(value); }
+  static void set_jdkbootclasspath_append();
+  static void set_sysclasspath(char *value) {
+    _sun_boot_class_path->set_value(value);
+    set_jdkbootclasspath_append();
+  }
+  static void append_sysclasspath(const char *value) {
+    _sun_boot_class_path->append_value(value);
+    set_jdkbootclasspath_append();
+  }
 
   static char* get_java_home() { return _java_home->value(); }
   static char* get_dll_dir() { return _sun_boot_library_path->value(); }
--- a/src/share/vm/runtime/statSampler.cpp	Mon Mar 09 09:39:52 2015 -0400
+++ b/src/share/vm/runtime/statSampler.cpp	Thu Mar 12 19:55:07 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2015, 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
@@ -237,7 +237,6 @@
 
 // unstable interface, unsupported counters
 static const char* property_counters_uu[] = {
-  "sun.boot.class.path",
   "sun.boot.library.path",
   NULL
 };
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/runtime/BootClassAppendProp/BootClassPathAppendProp.java	Thu Mar 12 19:55:07 2015 -0400
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+import java.io.File;
+
+/*
+ * @test
+ * @build BootClassPathAppendProp
+ * @run main/othervm -Xbootclasspath/a:/usr/lib -showversion -Xbootclasspath/a:/i/dont/exist BootClassPathAppendProp set
+ * @run main/othervm -Xoverride:/not/here -Xbootclasspath/a:/i/may/exist BootClassPathAppendProp override
+ * @run main/othervm BootClassPathAppendProp empty
+ */
+
+// Test that property jdk.boot.class.path.append contains only the bootclasspath
+// info following the .jimage file.
+public class BootClassPathAppendProp {
+
+    public static void test_prop(String expected_val) {
+        String propVal = System.getProperty("jdk.boot.class.path.append");
+        if (!propVal.equals(expected_val)) {
+            throw new RuntimeException(
+                 "Bad jdk.boot.class.path.append property value: " + propVal);
+        }
+    }
+
+    public static void main(String[] args) {
+        if (args[0].equals("set")) {
+            test_prop("/usr/lib" + File.pathSeparator + "/i/dont/exist");
+        } else if (args[0].equals("override")) {
+            test_prop("/i/may/exist");
+        } else if (args[0].equals("empty")) {
+            test_prop("");
+        } else {
+            throw new RuntimeException("Unexpected arg to main: " + args[0]);
+        }
+    }
+}