Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/tools/jhsdb/heapconfig/JMapHeapConfigTest.java
41153 views
1
/*
2
* Copyright (c) 2015, 2020, 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
import java.io.IOException;
25
import java.math.BigDecimal;
26
import java.util.ArrayList;
27
import java.util.Collections;
28
import java.util.HashMap;
29
import java.util.List;
30
import java.util.Map;
31
32
import jdk.test.lib.apps.LingeredApp;
33
import jdk.test.lib.SA.SATestUtils;
34
import jdk.test.lib.Utils;
35
36
/**
37
* @test
38
* @bug 8042397
39
* @summary Unit test for jmap utility test heap configuration reader
40
*
41
* @requires vm.hasSA
42
* @library /test/lib
43
* @modules java.management
44
* jdk.hotspot.agent/sun.jvm.hotspot
45
*
46
* @build JMapHeapConfigTest TmtoolTestScenario
47
* @run main JMapHeapConfigTest
48
*/
49
public class JMapHeapConfigTest {
50
51
static final String expectedJMapValues[] = {
52
"MinHeapFreeRatio",
53
"MaxHeapFreeRatio",
54
"MaxHeapSize",
55
"NewSize",
56
"OldSize",
57
"NewRatio",
58
"SurvivorRatio",
59
"MetaspaceSize",
60
"CompressedClassSpaceSize",
61
"G1HeapRegionSize"};
62
63
// Test can't deal with negative jlongs:
64
// ignoring MaxMetaspaceSize
65
// ignoring MaxNewSize
66
67
static final String desiredMaxHeapSize = "-Xmx128m";
68
69
private static Map<String, String> parseJMapOutput(List<String> jmapOutput) {
70
Map<String, String> heapConfigMap = new HashMap<String, String>();
71
boolean shouldParse = false;
72
73
for (String line : jmapOutput) {
74
line = line.trim();
75
76
if (line.startsWith("Heap Configuration:")) {
77
shouldParse = true;
78
continue;
79
}
80
81
if (line.startsWith("Heap Usage:")) {
82
shouldParse = false;
83
continue;
84
}
85
86
if (shouldParse && !line.equals("")) {
87
String[] lv = line.split("\\s+");
88
try {
89
heapConfigMap.put(lv[0], lv[2]);
90
} catch (ArrayIndexOutOfBoundsException ex) {
91
// Ignore mailformed lines
92
}
93
}
94
}
95
return heapConfigMap;
96
}
97
98
// Compare stored values
99
private static void compareValues(Map<String, String> parsedJMapOutput, Map<String, String> parsedVmOutput) {
100
for (String key : expectedJMapValues) {
101
try {
102
String jmapVal = parsedJMapOutput.get(key);
103
if (jmapVal == null) {
104
throw new RuntimeException("Key '" + key + "' doesn't exists in jmap output");
105
}
106
107
String vmVal = parsedVmOutput.get(key);
108
if (vmVal == null) {
109
throw new RuntimeException("Key '" + key + "' doesn't exists in vm output");
110
}
111
112
if (new BigDecimal(jmapVal).compareTo(new BigDecimal(vmVal)) != 0) {
113
throw new RuntimeException(String.format("Key %s doesn't match %s vs %s", key, vmVal, jmapVal));
114
}
115
} catch (NumberFormatException ex) {
116
throw new RuntimeException("Unexpected key '" + key + "' value", ex);
117
}
118
}
119
}
120
121
public static void main(String[] args) throws Exception {
122
System.out.println("Starting JMapHeapConfigTest");
123
SATestUtils.skipIfCannotAttach(); // throws SkippedException if attach not expected to work.
124
125
if (!LingeredApp.isLastModifiedWorking()) {
126
// Exact behaviour of the test depends to operating system and the test nature,
127
// so just print the warning and continue
128
System.err.println("Warning! Last modified time doesn't work.");
129
}
130
131
boolean mx_found = false;
132
String[] jvmOptions = Utils.getTestJavaOpts();
133
for (String option : jvmOptions) {
134
if (option.startsWith("-Xmx")) {
135
System.out.println("INFO: maximum heap size set by JTREG as " + option);
136
mx_found = true;
137
break;
138
}
139
}
140
141
// Forward vm options to LingeredApp
142
ArrayList<String> cmd = new ArrayList();
143
Collections.addAll(cmd, Utils.getTestJavaOpts());
144
if (!mx_found) {
145
cmd.add(desiredMaxHeapSize);
146
System.out.println("INFO: maximum heap size set explicitly as " + desiredMaxHeapSize);
147
}
148
cmd.add("-XX:+PrintFlagsFinal");
149
150
TmtoolTestScenario tmt = TmtoolTestScenario.create("jmap", "--heap");
151
int exitcode = tmt.launch(cmd.toArray(new String[0]));
152
if (exitcode != 0) {
153
throw new RuntimeException("Test FAILED jmap exits with non zero exit code " + exitcode);
154
}
155
156
Map<String,String> parsedJmapOutput = parseJMapOutput(tmt.getToolOutput());
157
Map<String,String> parsedVMOutput = tmt.parseFlagsFinal();
158
159
compareValues(parsedJmapOutput, parsedVMOutput);
160
161
// If test fails it throws RuntimeException
162
System.out.println("Test PASSED");
163
}
164
}
165
166