author | weijun |
Thu, 11 Dec 2014 15:23:02 +0800 | |
changeset 27957 | 24b4e6082f19 |
parent 27493 | 8a2a7d7c52a0 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
2 |
* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.management; |
|
27 |
||
28 |
import java.io.IOException; |
|
4156 | 29 |
import java.util.ArrayList; |
30 |
import java.util.List; |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
31 |
import javax.management.ObjectName; |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
32 |
|
2 | 33 |
import com.sun.management.HotSpotDiagnosticMXBean; |
34 |
import com.sun.management.VMOption; |
|
35 |
||
36 |
/** |
|
37 |
* Implementation of the diagnostic MBean for Hotspot VM. |
|
38 |
*/ |
|
39 |
public class HotSpotDiagnostic implements HotSpotDiagnosticMXBean { |
|
40 |
public HotSpotDiagnostic() { |
|
41 |
} |
|
42 |
||
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
43 |
@Override |
20826 | 44 |
public void dumpHeap(String outputFile, boolean live) throws IOException { |
45 |
SecurityManager security = System.getSecurityManager(); |
|
46 |
if (security != null) { |
|
47 |
security.checkWrite(outputFile); |
|
48 |
Util.checkControlAccess(); |
|
49 |
} |
|
50 |
||
51 |
dumpHeap0(outputFile, live); |
|
52 |
} |
|
53 |
||
54 |
private native void dumpHeap0(String outputFile, boolean live) throws IOException; |
|
2 | 55 |
|
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
56 |
@Override |
2 | 57 |
public List<VMOption> getDiagnosticOptions() { |
58 |
List<Flag> allFlags = Flag.getAllFlags(); |
|
11530
a9d059c15b80
7117570: Warnings in sun.mangement.* and its subpackages
mchung
parents:
11365
diff
changeset
|
59 |
List<VMOption> result = new ArrayList<>(); |
2 | 60 |
for (Flag flag : allFlags) { |
61 |
if (flag.isWriteable() && flag.isExternal()) { |
|
62 |
result.add(flag.getVMOption()); |
|
63 |
} |
|
64 |
} |
|
65 |
return result; |
|
66 |
} |
|
67 |
||
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
68 |
@Override |
2 | 69 |
public VMOption getVMOption(String name) { |
70 |
if (name == null) { |
|
71 |
throw new NullPointerException("name cannot be null"); |
|
72 |
} |
|
73 |
||
74 |
Flag f = Flag.getFlag(name); |
|
75 |
if (f == null) { |
|
76 |
throw new IllegalArgumentException("VM option \"" + |
|
77 |
name + "\" does not exist"); |
|
78 |
} |
|
79 |
return f.getVMOption(); |
|
80 |
} |
|
81 |
||
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
82 |
@Override |
2 | 83 |
public void setVMOption(String name, String value) { |
84 |
if (name == null) { |
|
85 |
throw new NullPointerException("name cannot be null"); |
|
86 |
} |
|
87 |
if (value == null) { |
|
88 |
throw new NullPointerException("value cannot be null"); |
|
89 |
} |
|
90 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
91 |
Util.checkControlAccess(); |
2 | 92 |
Flag flag = Flag.getFlag(name); |
93 |
if (flag == null) { |
|
94 |
throw new IllegalArgumentException("VM option \"" + |
|
95 |
name + "\" does not exist"); |
|
96 |
} |
|
97 |
if (!flag.isWriteable()){ |
|
98 |
throw new IllegalArgumentException("VM Option \"" + |
|
99 |
name + "\" is not writeable"); |
|
100 |
} |
|
101 |
||
102 |
// Check the type of the value |
|
103 |
Object v = flag.getValue(); |
|
104 |
if (v instanceof Long) { |
|
105 |
try { |
|
106 |
long l = Long.parseLong(value); |
|
107 |
Flag.setLongValue(name, l); |
|
108 |
} catch (NumberFormatException e) { |
|
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
109 |
throw new IllegalArgumentException("Invalid value:" + |
2 | 110 |
" VM Option \"" + name + "\"" + |
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
111 |
" expects numeric value", e); |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
112 |
} |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
113 |
} else if (v instanceof Double) { |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
114 |
try { |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
115 |
double d = Double.parseDouble(value); |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
116 |
Flag.setDoubleValue(name, d); |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
117 |
} catch (NumberFormatException e) { |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
118 |
throw new IllegalArgumentException("Invalid value:" + |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
119 |
" VM Option \"" + name + "\"" + |
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
120 |
" expects numeric value", e); |
2 | 121 |
} |
122 |
} else if (v instanceof Boolean) { |
|
123 |
if (!value.equalsIgnoreCase("true") && |
|
124 |
!value.equalsIgnoreCase("false")) { |
|
125 |
throw new IllegalArgumentException("Invalid value:" + |
|
126 |
" VM Option \"" + name + "\"" + |
|
127 |
" expects \"true\" or \"false\"."); |
|
128 |
} |
|
129 |
Flag.setBooleanValue(name, Boolean.parseBoolean(value)); |
|
130 |
} else if (v instanceof String) { |
|
131 |
Flag.setStringValue(name, value); |
|
132 |
} else { |
|
133 |
throw new IllegalArgumentException("VM Option \"" + |
|
134 |
name + "\" is of an unsupported type: " + |
|
135 |
v.getClass().getName()); |
|
136 |
} |
|
137 |
} |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
138 |
|
27493
8a2a7d7c52a0
8061616: HotspotDiagnosticMXBean.getVMOption() throws IllegalArgumentException for flags of type double
jbachorik
parents:
25859
diff
changeset
|
139 |
@Override |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
140 |
public ObjectName getObjectName() { |
4156 | 141 |
return Util.newObjectName("com.sun.management:type=HotSpotDiagnostic"); |
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
142 |
} |
2 | 143 |
} |