author | ohair |
Tue, 25 May 2010 15:58:33 -0700 | |
changeset 5506 | 202f599c92aa |
parent 715 | f16baef3a20e |
child 18801 | ff4643bb836d |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 2005, 2008, 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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
2 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6314913 |
|
27 |
* @summary Basic Test for HotSpotDiagnosticMXBean.setVMOption() |
|
28 |
* and getDiagnosticOptions(). |
|
29 |
* @author Mandy Chung |
|
30 |
* |
|
31 |
* @run main/othervm -XX:+PrintGCDetails SetVMOption |
|
32 |
*/ |
|
33 |
||
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
34 |
import java.lang.management.ManagementFactory; |
2 | 35 |
import java.util.*; |
36 |
import com.sun.management.HotSpotDiagnosticMXBean; |
|
37 |
import com.sun.management.VMOption; |
|
38 |
import com.sun.management.VMOption.Origin; |
|
39 |
import sun.misc.Version; |
|
40 |
||
41 |
public class SetVMOption { |
|
42 |
private static String PRINT_GC_DETAILS = "PrintGCDetails"; |
|
43 |
private static String EXPECTED_VALUE = "true"; |
|
44 |
private static String BAD_VALUE = "yes"; |
|
45 |
private static String NEW_VALUE = "false"; |
|
46 |
private static String MANAGEMENT_SERVER = "ManagementServer"; |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
47 |
private static HotSpotDiagnosticMXBean mbean; |
2 | 48 |
|
49 |
public static void main(String[] args) throws Exception { |
|
401
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
50 |
List<HotSpotDiagnosticMXBean> list = |
ef01e0dccd63
6610094: Add generic support for platform MXBeans of any type (also fixed 6681031)
mchung
parents:
2
diff
changeset
|
51 |
ManagementFactory.getPlatformMXBeans(HotSpotDiagnosticMXBean.class); |
2 | 52 |
|
53 |
// The following test is transitional only and should be removed |
|
54 |
// once build 52 is promoted. |
|
55 |
int build = Version.jvmBuildNumber(); |
|
56 |
if (build > 0 && build < 52) { |
|
57 |
// JVM support is integrated in build 52 |
|
58 |
// this test is skipped if running with VM earlier than 52 |
|
59 |
return; |
|
60 |
} |
|
61 |
||
62 |
VMOption option = findPrintGCDetailsOption(); |
|
63 |
if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) { |
|
64 |
throw new RuntimeException("Unexpected value: " + |
|
65 |
option.getValue() + " expected: " + EXPECTED_VALUE); |
|
66 |
} |
|
67 |
if (option.getOrigin() != Origin.VM_CREATION) { |
|
68 |
throw new RuntimeException("Unexpected origin: " + |
|
69 |
option.getOrigin() + " expected: VM_CREATION"); |
|
70 |
} |
|
71 |
if (!option.isWriteable()) { |
|
72 |
throw new RuntimeException("Expected " + PRINT_GC_DETAILS + |
|
73 |
" to be writeable"); |
|
74 |
} |
|
75 |
||
76 |
// set VM option to a new value |
|
77 |
mbean.setVMOption(PRINT_GC_DETAILS, NEW_VALUE); |
|
78 |
||
79 |
option = findPrintGCDetailsOption(); |
|
80 |
if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) { |
|
81 |
throw new RuntimeException("Unexpected value: " + |
|
82 |
option.getValue() + " expected: " + NEW_VALUE); |
|
83 |
} |
|
84 |
if (option.getOrigin() != Origin.MANAGEMENT) { |
|
85 |
throw new RuntimeException("Unexpected origin: " + |
|
86 |
option.getOrigin() + " expected: MANAGEMENT"); |
|
87 |
} |
|
88 |
VMOption o = mbean.getVMOption(PRINT_GC_DETAILS); |
|
89 |
if (!option.getValue().equals(o.getValue())) { |
|
90 |
throw new RuntimeException("Unmatched value: " + |
|
91 |
option.getValue() + " expected: " + o.getValue()); |
|
92 |
} |
|
93 |
if (!option.getValue().equals(o.getValue())) { |
|
94 |
throw new RuntimeException("Unmatched value: " + |
|
95 |
option.getValue() + " expected: " + o.getValue()); |
|
96 |
} |
|
97 |
if (option.getOrigin() != o.getOrigin()) { |
|
98 |
throw new RuntimeException("Unmatched origin: " + |
|
99 |
option.getOrigin() + " expected: " + o.getOrigin()); |
|
100 |
} |
|
101 |
if (option.isWriteable() != o.isWriteable()) { |
|
102 |
throw new RuntimeException("Unmatched writeable: " + |
|
103 |
option.isWriteable() + " expected: " + o.isWriteable()); |
|
104 |
} |
|
105 |
||
106 |
// check if ManagementServer is not writeable |
|
107 |
List<VMOption> options = mbean.getDiagnosticOptions(); |
|
108 |
VMOption mgmtServerOption = null; |
|
109 |
for (VMOption o1 : options) { |
|
110 |
if (o1.getName().equals(MANAGEMENT_SERVER)) { |
|
111 |
mgmtServerOption = o1; |
|
112 |
break; |
|
113 |
} |
|
114 |
} |
|
115 |
if (mgmtServerOption != null) { |
|
116 |
throw new RuntimeException(MANAGEMENT_SERVER + |
|
117 |
" is not expected to be writeable"); |
|
118 |
} |
|
119 |
mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER); |
|
120 |
if (mgmtServerOption == null) { |
|
121 |
throw new RuntimeException(MANAGEMENT_SERVER + |
|
122 |
" should exist."); |
|
123 |
} |
|
124 |
if (mgmtServerOption.getOrigin() != Origin.DEFAULT) { |
|
125 |
throw new RuntimeException(MANAGEMENT_SERVER + |
|
126 |
" should have the default value."); |
|
127 |
} |
|
128 |
if (mgmtServerOption.isWriteable()) { |
|
129 |
throw new RuntimeException(MANAGEMENT_SERVER + |
|
130 |
" is not expected to be writeable"); |
|
131 |
} |
|
132 |
} |
|
133 |
||
134 |
public static VMOption findPrintGCDetailsOption() { |
|
135 |
List<VMOption> options = mbean.getDiagnosticOptions(); |
|
136 |
VMOption gcDetails = null; |
|
137 |
for (VMOption o : options) { |
|
138 |
if (o.getName().equals(PRINT_GC_DETAILS)) { |
|
139 |
gcDetails = o; |
|
140 |
break; |
|
141 |
} |
|
142 |
} |
|
143 |
if (gcDetails == null) { |
|
144 |
throw new RuntimeException("VM option " + PRINT_GC_DETAILS + |
|
145 |
" not found"); |
|
146 |
} |
|
147 |
return gcDetails; |
|
148 |
} |
|
149 |
} |