8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
Reviewed-by: mchung, sla
This commit is contained in:
parent
b23c39c07b
commit
cd4e0a44d5
jdk
src/java.management/share
classes
native
test/com/sun/management/HotSpotDiagnosticMXBean
@ -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 @@ public interface HotSpotDiagnosticMXBean extends PlatformManagedObject {
|
||||
* @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
|
||||
|
@ -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 @@ class Flag {
|
||||
// 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);
|
||||
|
||||
|
@ -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 class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
public HotSpotDiagnostic() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dumpHeap(String outputFile, boolean live) throws IOException {
|
||||
SecurityManager security = System.getSecurityManager();
|
||||
if (security != null) {
|
||||
@ -52,6 +53,7 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
|
||||
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 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VMOption getVMOption(String name) {
|
||||
if (name == null) {
|
||||
throw new NullPointerException("name cannot be null");
|
||||
@ -76,6 +79,7 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
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 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
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 @@ public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ObjectName getObjectName() {
|
||||
return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic");
|
||||
}
|
||||
|
@ -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 @@ typedef enum {
|
||||
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 {
|
||||
|
@ -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 @@ Java_sun_management_Flag_getFlags
|
||||
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;
|
||||
@ -201,6 +205,16 @@ Java_sun_management_Flag_setLongValue
|
||||
jmm_interface->SetVMGlobal(env, name, v);
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
@ -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;
|
||||
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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user