8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
authorjbachorik
Mon, 03 Nov 2014 11:19:54 +0100
changeset 27493 8a2a7d7c52a0
parent 27337 89b967c599ce
child 27494 22353a4c3b4e
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double Reviewed-by: mchung, sla
jdk/src/java.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java
jdk/src/java.management/share/classes/sun/management/Flag.java
jdk/src/java.management/share/classes/sun/management/HotSpotDiagnostic.java
jdk/src/java.management/share/native/include/jmm.h
jdk/src/java.management/share/native/libmanagement/Flag.c
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDoubleVMOption.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java
jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java
--- a/jdk/src/java.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/src/java.management/share/classes/com/sun/management/HotSpotDiagnosticMXBean.java	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -25,7 +25,6 @@
 
 package com.sun.management;
 
-import java.util.List;
 import java.lang.management.PlatformManagedObject;
 
 /**
@@ -109,7 +108,7 @@
      * @throws IllegalArgumentException if the VM option of the given name
      *                                     does not exist.
      * @throws IllegalArgumentException if the new value is invalid.
-     * @throws IllegalArgumentException if the VM option is not writeable.
+     * @throws IllegalArgumentException if the VM option is not writable.
      * @throws NullPointerException if name or value is <tt>null</tt>.
      *
      * @throws  java.lang.SecurityException
--- a/jdk/src/java.management/share/classes/sun/management/Flag.java	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/src/java.management/share/classes/sun/management/Flag.java	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -110,6 +110,7 @@
     // These set* methods are synchronized on the class object
     // to avoid multiple threads updating the same flag at the same time.
     static synchronized native void setLongValue(String name, long value);
+    static synchronized native void setDoubleValue(String name, double value);
     static synchronized native void setBooleanValue(String name, boolean value);
     static synchronized native void setStringValue(String name, String value);
 
--- a/jdk/src/java.management/share/classes/sun/management/HotSpotDiagnostic.java	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/src/java.management/share/classes/sun/management/HotSpotDiagnostic.java	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -40,6 +40,7 @@
     public HotSpotDiagnostic() {
     }
 
+    @Override
     public void dumpHeap(String outputFile, boolean live) throws IOException {
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
@@ -52,6 +53,7 @@
 
     private native void dumpHeap0(String outputFile, boolean live) throws IOException;
 
+    @Override
     public List<VMOption> getDiagnosticOptions() {
         List<Flag> allFlags = Flag.getAllFlags();
         List<VMOption> result = new ArrayList<>();
@@ -63,6 +65,7 @@
         return result;
     }
 
+    @Override
     public VMOption getVMOption(String name) {
         if (name == null) {
             throw new NullPointerException("name cannot be null");
@@ -76,6 +79,7 @@
         return f.getVMOption();
     }
 
+    @Override
     public void setVMOption(String name, String value) {
         if (name == null) {
             throw new NullPointerException("name cannot be null");
@@ -102,12 +106,18 @@
                 long l = Long.parseLong(value);
                 Flag.setLongValue(name, l);
             } catch (NumberFormatException e) {
-                IllegalArgumentException iae =
-                    new IllegalArgumentException("Invalid value:" +
+                throw new IllegalArgumentException("Invalid value:" +
                         " VM Option \"" + name + "\"" +
-                        " expects numeric value");
-                iae.initCause(e);
-                throw iae;
+                        " expects numeric value", e);
+            }
+        } else if (v instanceof Double) {
+            try {
+                double d = Double.parseDouble(value);
+                Flag.setDoubleValue(name, d);
+            } catch (NumberFormatException e) {
+                throw new IllegalArgumentException("Invalid value:" +
+                        " VM Option \"" + name + "\"" +
+                        " expects numeric value", e);
             }
         } else if (v instanceof Boolean) {
             if (!value.equalsIgnoreCase("true") &&
@@ -126,6 +136,7 @@
         }
     }
 
+    @Override
     public ObjectName getObjectName() {
         return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic");
     }
--- a/jdk/src/java.management/share/native/include/jmm.h	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/src/java.management/share/native/include/jmm.h	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -143,7 +143,8 @@
   JMM_VMGLOBAL_TYPE_UNKNOWN  = 0,
   JMM_VMGLOBAL_TYPE_JBOOLEAN = 1,
   JMM_VMGLOBAL_TYPE_JSTRING  = 2,
-  JMM_VMGLOBAL_TYPE_JLONG    = 3
+  JMM_VMGLOBAL_TYPE_JLONG    = 3,
+  JMM_VMGLOBAL_TYPE_JDOUBLE  = 4
 } jmmVMGlobalType;
 
 typedef enum {
--- a/jdk/src/java.management/share/native/libmanagement/Flag.c	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/src/java.management/share/native/libmanagement/Flag.c	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2014, 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
@@ -133,6 +133,10 @@
             valueObj = JNU_NewObjectByName(env, "java/lang/Long", "(J)V",
                                            globals[i].value.j);
             break;
+        case JMM_VMGLOBAL_TYPE_JDOUBLE:
+            valueObj = JNU_NewObjectByName(env, "java/lang/Double", "(D)V",
+                                           globals[i].value.d);
+            break;
         default:
             // ignore unsupported type
             continue;
@@ -202,6 +206,16 @@
 }
 
 JNIEXPORT void JNICALL
+Java_sun_management_Flag_setDoubleValue
+  (JNIEnv *env, jclass cls, jstring name, jdouble value)
+{
+   jvalue v;
+   v.d = value;
+
+   jmm_interface->SetVMGlobal(env, name, v);
+}
+
+JNIEXPORT void JNICALL
 Java_sun_management_Flag_setBooleanValue
   (JNIEnv *env, jclass cls, jstring name, jboolean value)
 {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetDoubleVMOption.java	Mon Nov 03 11:19:54 2014 +0100
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2014, 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     8061616
+ * @summary Basic Test for HotSpotDiagnosticMXBean.getVMOption() and double values
+ * @author  Jaroslav Bachorik
+ *
+ * @run main/othervm -XX:CompileThresholdScaling=0.14 GetDoubleVMOption
+ */
+
+import com.sun.management.HotSpotDiagnosticMXBean;
+import com.sun.management.VMOption;
+import java.lang.management.ManagementFactory;
+import java.util.List;
+import javax.management.MBeanServer;
+
+public class GetDoubleVMOption {
+    private static final String COMPILE_THRESHOLD_SCALING = "CompileThresholdScaling";
+    private static final String EXPECTED_VALUE = "0.14";
+    private static final String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
+        "com.sun.management:type=HotSpotDiagnostic";
+
+    public static void main(String[] args) throws Exception {
+        List<HotSpotDiagnosticMXBean> list =
+            ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class);
+        HotSpotDiagnosticMXBean mbean = list.get(0);
+        checkVMOption(mbean);
+
+        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
+        mbean = ManagementFactory.newPlatformMXBeanProxy(mbs,
+                    HOTSPOT_DIAGNOSTIC_MXBEAN_NAME,
+                    HotSpotDiagnosticMXBean.class);
+        checkVMOption(mbean);
+    }
+
+    private static void checkVMOption(HotSpotDiagnosticMXBean mbean) {
+        VMOption option = mbean.getVMOption(COMPILE_THRESHOLD_SCALING);
+        if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
+            throw new RuntimeException("Unexpected value: " +
+                option.getValue() + " expected: " + EXPECTED_VALUE);
+        }
+    }
+}
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/GetVMOption.java	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -32,16 +32,15 @@
 
 import com.sun.management.HotSpotDiagnosticMXBean;
 import com.sun.management.VMOption;
-import com.sun.management.VMOption.Origin;
 import java.lang.management.ManagementFactory;
 import java.util.List;
 import javax.management.MBeanServer;
 
 public class GetVMOption {
-    private static String PRINT_GC_DETAILS = "PrintGCDetails";
-    private static String EXPECTED_VALUE = "true";
-    private static String BAD_OPTION = "BadOption";
-    private static String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
+    private static final String PRINT_GC_DETAILS = "PrintGCDetails";
+    private static final String EXPECTED_VALUE = "true";
+    private static final String BAD_OPTION = "BadOption";
+    private static final String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =
         "com.sun.management:type=HotSpotDiagnostic";
 
     public static void main(String[] args) throws Exception {
--- a/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java	Thu Oct 30 17:48:10 2014 -0700
+++ b/jdk/test/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java	Mon Nov 03 11:19:54 2014 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2005, 2014, 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
@@ -39,11 +39,11 @@
 import com.sun.management.VMOption.Origin;
 
 public class SetVMOption {
-    private static String PRINT_GC_DETAILS = "PrintGCDetails";
-    private static String EXPECTED_VALUE = "true";
-    private static String BAD_VALUE = "yes";
-    private static String NEW_VALUE = "false";
-    private static String MANAGEMENT_SERVER = "ManagementServer";
+    private static final String PRINT_GC_DETAILS = "PrintGCDetails";
+    private static final String EXPECTED_VALUE = "true";
+    private static final String BAD_VALUE = "yes";
+    private static final String NEW_VALUE = "false";
+    private static final String MANAGEMENT_SERVER = "ManagementServer";
     private static HotSpotDiagnosticMXBean mbean;
 
     public static void main(String[] args) throws Exception {