author | emcmanus |
Wed, 21 Oct 2009 17:33:18 +0200 | |
changeset 4156 | acaa49a2768a |
parent 1226 | eba24d3b9c0c |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
715 | 2 |
* Copyright 2005-2008 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
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 |
||
43 |
public native void dumpHeap(String outputFile, boolean live) throws IOException; |
|
44 |
||
45 |
public List<VMOption> getDiagnosticOptions() { |
|
46 |
List<Flag> allFlags = Flag.getAllFlags(); |
|
47 |
List<VMOption> result = new ArrayList<VMOption>(); |
|
48 |
for (Flag flag : allFlags) { |
|
49 |
if (flag.isWriteable() && flag.isExternal()) { |
|
50 |
result.add(flag.getVMOption()); |
|
51 |
} |
|
52 |
} |
|
53 |
return result; |
|
54 |
} |
|
55 |
||
56 |
public VMOption getVMOption(String name) { |
|
57 |
if (name == null) { |
|
58 |
throw new NullPointerException("name cannot be null"); |
|
59 |
} |
|
60 |
||
61 |
Flag f = Flag.getFlag(name); |
|
62 |
if (f == null) { |
|
63 |
throw new IllegalArgumentException("VM option \"" + |
|
64 |
name + "\" does not exist"); |
|
65 |
} |
|
66 |
return f.getVMOption(); |
|
67 |
} |
|
68 |
||
69 |
public void setVMOption(String name, String value) { |
|
70 |
if (name == null) { |
|
71 |
throw new NullPointerException("name cannot be null"); |
|
72 |
} |
|
73 |
if (value == null) { |
|
74 |
throw new NullPointerException("value cannot be null"); |
|
75 |
} |
|
76 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
77 |
Util.checkControlAccess(); |
2 | 78 |
Flag flag = Flag.getFlag(name); |
79 |
if (flag == null) { |
|
80 |
throw new IllegalArgumentException("VM option \"" + |
|
81 |
name + "\" does not exist"); |
|
82 |
} |
|
83 |
if (!flag.isWriteable()){ |
|
84 |
throw new IllegalArgumentException("VM Option \"" + |
|
85 |
name + "\" is not writeable"); |
|
86 |
} |
|
87 |
||
88 |
// Check the type of the value |
|
89 |
Object v = flag.getValue(); |
|
90 |
if (v instanceof Long) { |
|
91 |
try { |
|
92 |
long l = Long.parseLong(value); |
|
93 |
Flag.setLongValue(name, l); |
|
94 |
} catch (NumberFormatException e) { |
|
95 |
IllegalArgumentException iae = |
|
96 |
new IllegalArgumentException("Invalid value:" + |
|
97 |
" VM Option \"" + name + "\"" + |
|
98 |
" expects numeric value"); |
|
99 |
iae.initCause(e); |
|
100 |
throw iae; |
|
101 |
} |
|
102 |
} else if (v instanceof Boolean) { |
|
103 |
if (!value.equalsIgnoreCase("true") && |
|
104 |
!value.equalsIgnoreCase("false")) { |
|
105 |
throw new IllegalArgumentException("Invalid value:" + |
|
106 |
" VM Option \"" + name + "\"" + |
|
107 |
" expects \"true\" or \"false\"."); |
|
108 |
} |
|
109 |
Flag.setBooleanValue(name, Boolean.parseBoolean(value)); |
|
110 |
} else if (v instanceof String) { |
|
111 |
Flag.setStringValue(name, value); |
|
112 |
} else { |
|
113 |
throw new IllegalArgumentException("VM Option \"" + |
|
114 |
name + "\" is of an unsupported type: " + |
|
115 |
v.getClass().getName()); |
|
116 |
} |
|
117 |
} |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
118 |
|
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
119 |
public ObjectName getObjectName() { |
4156 | 120 |
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
|
121 |
} |
2 | 122 |
} |