8204668: Cleanup management of the java.vm.info System property
authordholmes
Thu, 14 Jun 2018 02:01:31 -0400
changeset 50557 83e2deb73612
parent 50556 e5a40146791b
child 50558 d9936e986e4f
8204668: Cleanup management of the java.vm.info System property Reviewed-by: rehn, cjplummer
src/hotspot/share/classfile/vmSymbols.hpp
src/hotspot/share/runtime/arguments.cpp
src/hotspot/share/runtime/arguments.hpp
src/hotspot/share/runtime/thread.cpp
--- a/src/hotspot/share/classfile/vmSymbols.hpp	Thu Jun 14 07:26:27 2018 +0200
+++ b/src/hotspot/share/classfile/vmSymbols.hpp	Thu Jun 14 02:01:31 2018 -0400
@@ -374,7 +374,6 @@
   template(fillInStackTrace_name,                     "fillInStackTrace")                         \
   template(getCause_name,                             "getCause")                                 \
   template(initCause_name,                            "initCause")                                \
-  template(setProperty_name,                          "setProperty")                              \
   template(getProperty_name,                          "getProperty")                              \
   template(context_name,                              "context")                                  \
   template(contextClassLoader_name,                   "contextClassLoader")                       \
--- a/src/hotspot/share/runtime/arguments.cpp	Thu Jun 14 07:26:27 2018 +0200
+++ b/src/hotspot/share/runtime/arguments.cpp	Thu Jun 14 02:01:31 2018 -0400
@@ -116,6 +116,7 @@
 SystemProperty *Arguments::_java_home = NULL;
 SystemProperty *Arguments::_java_class_path = NULL;
 SystemProperty *Arguments::_jdk_boot_class_path_append = NULL;
+SystemProperty *Arguments::_vm_info = NULL;
 
 GrowableArray<ModulePatchPath*> *Arguments::_patch_mod_prefix = NULL;
 PathString *Arguments::_system_boot_class_path = NULL;
@@ -395,9 +396,11 @@
                                                            "Java Virtual Machine Specification",  false));
   PropertyList_add(&_system_properties, new SystemProperty("java.vm.version", VM_Version::vm_release(),  false));
   PropertyList_add(&_system_properties, new SystemProperty("java.vm.name", VM_Version::vm_name(),  false));
-  PropertyList_add(&_system_properties, new SystemProperty("java.vm.info", VM_Version::vm_info_string(),  true));
   PropertyList_add(&_system_properties, new SystemProperty("jdk.debug", VM_Version::jdk_debug_level(),  false));
 
+  // Initialize the vm.info now, but it will need updating after argument parsing.
+  _vm_info = new SystemProperty("java.vm.info", VM_Version::vm_info_string(), true);
+
   // Following are JVMTI agent writable properties.
   // Properties values are set to NULL and they are
   // os specific they are initialized in os::init_system_properties_values().
@@ -417,6 +420,7 @@
   PropertyList_add(&_system_properties, _java_home);
   PropertyList_add(&_system_properties, _java_class_path);
   PropertyList_add(&_system_properties, _jdk_boot_class_path_append);
+  PropertyList_add(&_system_properties, _vm_info);
 
   // Set OS specific system properties values
   os::init_system_properties_values();
@@ -4451,18 +4455,6 @@
   PropertyList_add(plist, k, v, writeable == WriteableProperty, internal == InternalProperty);
 }
 
-// Update existing property with new value.
-void Arguments::PropertyList_update_value(SystemProperty* plist, const char* k, const char* v) {
-  SystemProperty* prop;
-  for (prop = plist; prop != NULL; prop = prop->next()) {
-    if (strcmp(k, prop->key()) == 0) {
-        prop->set_value(v);
-        return;
-    }
-  }
-  assert(false, "invalid property");
-}
-
 // Copies src into buf, replacing "%%" with "%" and "%p" with pid
 // Returns true if all of the source pointed by src has been copied over to
 // the destination buffer pointed by buf. Otherwise, returns false.
--- a/src/hotspot/share/runtime/arguments.hpp	Thu Jun 14 07:26:27 2018 +0200
+++ b/src/hotspot/share/runtime/arguments.hpp	Thu Jun 14 02:01:31 2018 -0400
@@ -291,6 +291,7 @@
   static SystemProperty *_java_home;
   static SystemProperty *_java_class_path;
   static SystemProperty *_jdk_boot_class_path_append;
+  static SystemProperty *_vm_info;
 
   // --patch-module=module=<file>(<pathsep><file>)*
   // Each element contains the associated module name, path
@@ -643,6 +644,11 @@
   // Update/Initialize System properties after JDK version number is known
   static void init_version_specific_system_properties();
 
+  // Update VM info property - called after argument parsing
+  static void update_vm_info_property(const char* vm_info) {
+    _vm_info->set_value(vm_info);
+  }
+
   // Property List manipulation
   static void PropertyList_add(SystemProperty *element);
   static void PropertyList_add(SystemProperty** plist, SystemProperty *element);
@@ -651,7 +657,6 @@
   static void PropertyList_unique_add(SystemProperty** plist, const char* k, const char* v,
                                       PropertyAppendable append, PropertyWriteable writeable,
                                       PropertyInternal internal);
-  static void PropertyList_update_value(SystemProperty* plist, const char* k, const char* v);
   static const char* PropertyList_get_value(SystemProperty* plist, const char* key);
   static const char* PropertyList_get_readable_value(SystemProperty* plist, const char* key);
   static int  PropertyList_count(SystemProperty* pl);
--- a/src/hotspot/share/runtime/thread.cpp	Thu Jun 14 07:26:27 2018 +0200
+++ b/src/hotspot/share/runtime/thread.cpp	Thu Jun 14 02:01:31 2018 -0400
@@ -1127,35 +1127,6 @@
   }
 }
 
-static void reset_vm_info_property(TRAPS) {
-  // the vm info string
-  ResourceMark rm(THREAD);
-  const char *vm_info = VM_Version::vm_info_string();
-
-  // update the native system property first
-  Arguments::PropertyList_update_value(Arguments::system_properties(), "java.vm.info", vm_info);
-
-  // java.lang.System class
-  Klass* klass =  SystemDictionary::resolve_or_fail(vmSymbols::java_lang_System(), true, CHECK);
-
-  // setProperty arguments
-  Handle key_str    = java_lang_String::create_from_str("java.vm.info", CHECK);
-  Handle value_str  = java_lang_String::create_from_str(vm_info, CHECK);
-
-  // return value
-  JavaValue r(T_OBJECT);
-
-  // public static String setProperty(String key, String value);
-  JavaCalls::call_static(&r,
-                         klass,
-                         vmSymbols::setProperty_name(),
-                         vmSymbols::string_string_string_signature(),
-                         key_str,
-                         value_str,
-                         CHECK);
-}
-
-
 void JavaThread::allocate_threadObj(Handle thread_group, const char* thread_name,
                                     bool daemon, TRAPS) {
   assert(thread_group.not_null(), "thread group should be specified");
@@ -3771,6 +3742,14 @@
     VMThread::execute(&verify_op);
   }
 
+  // We need this to update the java.vm.info property in case any flags used
+  // to initially define it have been changed. This is needed for both CDS and
+  // AOT, since UseSharedSpaces and UseAOT may be changed after java.vm.info
+  // is initially computed. See Abstract_VM_Version::vm_info_string().
+  // This update must happen before we initialize the java classes, but
+  // after any initialization logic that might modify the flags.
+  Arguments::update_vm_info_property(VM_Version::vm_info_string());
+
   Thread* THREAD = Thread::current();
 
   // Always call even when there are not JVMTI environments yet, since environments
@@ -3782,12 +3761,6 @@
 
   initialize_java_lang_classes(main_thread, CHECK_JNI_ERR);
 
-  // We need this to update the java.vm.info property in case any flags used
-  // to initially define it have been changed. This is needed for both CDS and
-  // AOT, since UseSharedSpaces and UseAOT may be changed after java.vm.info
-  // is initially computed. See Abstract_VM_Version::vm_info_string().
-  reset_vm_info_property(CHECK_JNI_ERR);
-
   quicken_jni_functions();
 
   // No more stub generation allowed after that point.