Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/com/sun/management/HotSpotDiagnosticMXBean/SetVMOption.java
41153 views
1
/*
2
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved.
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
*
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.
22
*/
23
24
/*
25
* @test
26
* @bug 6314913
27
* @summary Basic Test for HotSpotDiagnosticMXBean.setVMOption()
28
* and getDiagnosticOptions().
29
* @author Mandy Chung
30
* @author Jaroslav Bachorik
31
*
32
* @library /test/lib
33
* @run main/othervm -XX:+HeapDumpOnOutOfMemoryError SetVMOption
34
*/
35
36
import java.lang.management.ManagementFactory;
37
import java.util.*;
38
import com.sun.management.HotSpotDiagnosticMXBean;
39
import com.sun.management.VMOption;
40
import com.sun.management.VMOption.Origin;
41
import jdk.test.lib.Platform;
42
43
public class SetVMOption {
44
private static final String HEAP_DUMP_ON_OOM = "HeapDumpOnOutOfMemoryError";
45
private static final String EXPECTED_VALUE = "true";
46
private static final String BAD_VALUE = "yes";
47
private static final String NEW_VALUE = "false";
48
private static final String MANAGEMENT_SERVER = "ManagementServer";
49
private static HotSpotDiagnosticMXBean mbean;
50
51
public static void main(String[] args) throws Exception {
52
mbean =
53
ManagementFactory.getPlatformMXBean(HotSpotDiagnosticMXBean.class);
54
55
VMOption option = findHeapDumpOnOomOption();
56
if (!option.getValue().equalsIgnoreCase(EXPECTED_VALUE)) {
57
throw new RuntimeException("Unexpected value: " +
58
option.getValue() + " expected: " + EXPECTED_VALUE);
59
}
60
if (option.getOrigin() != Origin.VM_CREATION) {
61
throw new RuntimeException("Unexpected origin: " +
62
option.getOrigin() + " expected: VM_CREATION");
63
}
64
if (!option.isWriteable()) {
65
throw new RuntimeException("Expected " + HEAP_DUMP_ON_OOM +
66
" to be writeable");
67
}
68
69
// set VM option to a new value
70
mbean.setVMOption(HEAP_DUMP_ON_OOM, NEW_VALUE);
71
72
option = findHeapDumpOnOomOption();
73
if (!option.getValue().equalsIgnoreCase(NEW_VALUE)) {
74
throw new RuntimeException("Unexpected value: " +
75
option.getValue() + " expected: " + NEW_VALUE);
76
}
77
if (option.getOrigin() != Origin.MANAGEMENT) {
78
throw new RuntimeException("Unexpected origin: " +
79
option.getOrigin() + " expected: MANAGEMENT");
80
}
81
VMOption o = mbean.getVMOption(HEAP_DUMP_ON_OOM);
82
if (!option.getValue().equals(o.getValue())) {
83
throw new RuntimeException("Unmatched value: " +
84
option.getValue() + " expected: " + o.getValue());
85
}
86
if (!option.getValue().equals(o.getValue())) {
87
throw new RuntimeException("Unmatched value: " +
88
option.getValue() + " expected: " + o.getValue());
89
}
90
if (option.getOrigin() != o.getOrigin()) {
91
throw new RuntimeException("Unmatched origin: " +
92
option.getOrigin() + " expected: " + o.getOrigin());
93
}
94
if (option.isWriteable() != o.isWriteable()) {
95
throw new RuntimeException("Unmatched writeable: " +
96
option.isWriteable() + " expected: " + o.isWriteable());
97
}
98
99
100
// Today we don't have any manageable flags of the string type in the product build,
101
// so we can only test DummyManageableStringFlag in the debug build.
102
if (Platform.isDebugBuild()) {
103
String optionName = "DummyManageableStringFlag";
104
String toValue = "DummyManageableStringFlag_Is_Set_To_Hello";
105
106
mbean.setVMOption(optionName, toValue);
107
108
VMOption stringOption = findOption(optionName);
109
Object newValue = stringOption.getValue();
110
if (!toValue.equals(newValue)) {
111
throw new RuntimeException("Unmatched value: " +
112
newValue + " expected: " + toValue);
113
}
114
}
115
116
// check if ManagementServer is not writeable
117
List<VMOption> options = mbean.getDiagnosticOptions();
118
VMOption mgmtServerOption = null;
119
for (VMOption o1 : options) {
120
if (o1.getName().equals(MANAGEMENT_SERVER)) {
121
mgmtServerOption = o1;
122
break;
123
}
124
}
125
if (mgmtServerOption != null) {
126
throw new RuntimeException(MANAGEMENT_SERVER +
127
" is not expected to be writeable");
128
}
129
mgmtServerOption = mbean.getVMOption(MANAGEMENT_SERVER);
130
if (mgmtServerOption == null) {
131
throw new RuntimeException(MANAGEMENT_SERVER +
132
" should exist.");
133
}
134
if (mgmtServerOption.getOrigin() != Origin.DEFAULT) {
135
throw new RuntimeException(MANAGEMENT_SERVER +
136
" should have the default value.");
137
}
138
if (mgmtServerOption.isWriteable()) {
139
throw new RuntimeException(MANAGEMENT_SERVER +
140
" is not expected to be writeable");
141
}
142
}
143
144
public static VMOption findHeapDumpOnOomOption() {
145
return findOption(HEAP_DUMP_ON_OOM);
146
}
147
148
private static VMOption findOption(String optionName) {
149
List<VMOption> options = mbean.getDiagnosticOptions();
150
VMOption found = null;
151
for (VMOption o : options) {
152
if (o.getName().equals(optionName)) {
153
found = o;
154
break;
155
}
156
}
157
if (found == null) {
158
throw new RuntimeException("VM option " + optionName +
159
" not found");
160
}
161
return found;
162
}
163
}
164
165