8203329: JDWP/JDI VM information string is incorrect
authorcjplummer
Thu, 07 Jun 2018 19:01:18 -0700
changeset 50456 cb75455ada5a
parent 50455 2b73cce96dce
child 50457 538dd69b60c0
8203329: JDWP/JDI VM information string is incorrect Summary: make sure the native java.vm.info property also gets updated when the java version is. Reviewed-by: sspitsyn, dholmes
src/hotspot/share/runtime/arguments.cpp
src/hotspot/share/runtime/arguments.hpp
src/hotspot/share/runtime/thread.cpp
test/hotspot/jtreg/serviceability/jvmti/GetSystemProperty/JvmtiGetSystemPropertyTest.java
test/hotspot/jtreg/serviceability/jvmti/GetSystemProperty/libJvmtiGetSystemPropertyTest.c
--- a/src/hotspot/share/runtime/arguments.cpp	Thu Jun 07 17:38:34 2018 -0700
+++ b/src/hotspot/share/runtime/arguments.cpp	Thu Jun 07 19:01:18 2018 -0700
@@ -4447,6 +4447,18 @@
   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 07 17:38:34 2018 -0700
+++ b/src/hotspot/share/runtime/arguments.hpp	Thu Jun 07 19:01:18 2018 -0700
@@ -651,6 +651,7 @@
   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 07 17:38:34 2018 -0700
+++ b/src/hotspot/share/runtime/thread.cpp	Thu Jun 07 19:01:18 2018 -0700
@@ -1132,6 +1132,9 @@
   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);
 
@@ -3779,9 +3782,10 @@
 
   initialize_java_lang_classes(main_thread, CHECK_JNI_ERR);
 
-  // We need this for ClassDataSharing - the initial vm.info property is set
-  // with the default value of CDS "sharing" which may be reset through
-  // command line options.
+  // 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();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/jvmti/GetSystemProperty/JvmtiGetSystemPropertyTest.java	Thu Jun 07 19:01:18 2018 -0700
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2018, 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
+ * @bug 8203329
+ * @summary Verifies the JVMTI GetSystemProperty API returns the updated java.vm.info value
+ * @library /test/lib
+ * @run main/othervm/native -agentlib:JvmtiGetSystemPropertyTest JvmtiGetSystemPropertyTest
+ *
+ */
+
+public class JvmtiGetSystemPropertyTest {
+    private static native String getSystemProperty();
+
+    public static void main(String[] args) throws Exception {
+        String vm_info = System.getProperty("java.vm.info");
+        String vm_info_jvmti = getSystemProperty();
+        System.out.println("java.vm.info from java:  " + vm_info);
+        System.out.println("java.vm.info from jvmti: " + vm_info_jvmti);
+        if (!vm_info.equals(vm_info_jvmti)) {
+            throw new RuntimeException("java.vm.info poperties not equal: \"" +
+                                       vm_info + "\" != \"" + vm_info_jvmti + "\"");
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/hotspot/jtreg/serviceability/jvmti/GetSystemProperty/libJvmtiGetSystemPropertyTest.c	Thu Jun 07 19:01:18 2018 -0700
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2018, 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.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <jvmti.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+static jvmtiEnv *jvmti = NULL;
+
+JNIEXPORT jint JNICALL Agent_OnLoad(JavaVM *jvm, char *options, void *reserved) {
+  int err = (*jvm)->GetEnv(jvm, (void**) &jvmti, JVMTI_VERSION_9);
+  if (err != JNI_OK) {
+    return JNI_ERR;
+  }
+  return JNI_OK;
+}
+
+JNIEXPORT jstring JNICALL
+Java_JvmtiGetSystemPropertyTest_getSystemProperty(JNIEnv *env, jclass cls) {
+  jvmtiError err;
+  char* prop_value;
+
+  err = (*jvmti)->GetSystemProperty(jvmti, "java.vm.info", &prop_value);
+  if (err != JVMTI_ERROR_NONE) {
+    return NULL;
+  }
+
+  return (*env)->NewStringUTF(env, prop_value);
+}
+
+#ifdef __cplusplus
+}
+#endif