Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/serviceability/dcmd/compiler/CodeCacheTest.java
41153 views
1
/*
2
* Copyright (c) 2014, 2017, 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 CodeCacheTest
26
* @bug 8054889
27
* @library /test/lib
28
* @modules java.base/jdk.internal.misc
29
* java.compiler
30
* java.management
31
* jdk.internal.jvmstat/sun.jvmstat.monitor
32
* @run testng/othervm -XX:+SegmentedCodeCache CodeCacheTest
33
* @run testng/othervm -XX:-SegmentedCodeCache CodeCacheTest
34
* @run testng/othervm -Xint -XX:+SegmentedCodeCache CodeCacheTest
35
* @summary Test of diagnostic command Compiler.codecache
36
*/
37
38
import org.testng.annotations.Test;
39
import org.testng.Assert;
40
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.dcmd.CommandExecutor;
43
import jdk.test.lib.dcmd.JMXExecutor;
44
45
import java.util.Iterator;
46
import java.util.regex.Matcher;
47
import java.util.regex.Pattern;
48
49
public class CodeCacheTest {
50
51
/**
52
* This test calls Jcmd (diagnostic command tool) Compiler.codecache and then parses the output,
53
* making sure that all numbers look ok
54
*
55
*
56
* Expected output without code cache segmentation:
57
*
58
* CodeCache: size=245760Kb used=4680Kb max_used=4680Kb free=241079Kb
59
* bounds [0x00007f5bd9000000, 0x00007f5bd94a0000, 0x00007f5be8000000]
60
* total_blobs=575 nmethods=69 adapters=423
61
* compilation: enabled
62
*
63
* Expected output with code cache segmentation (number of segments may change):
64
*
65
* CodeHeap 'non-nmethods': size=5696Kb used=2236Kb max_used=2238Kb free=3459Kb
66
* bounds [0x00007fa0f0ffe000, 0x00007fa0f126e000, 0x00007fa0f158e000]
67
* CodeHeap 'profiled nmethods': size=120036Kb used=8Kb max_used=8Kb free=120027Kb
68
* bounds [0x00007fa0f158e000, 0x00007fa0f17fe000, 0x00007fa0f8ac7000]
69
* CodeHeap 'non-profiled nmethods': size=120036Kb used=2Kb max_used=2Kb free=120034Kb
70
* bounds [0x00007fa0f8ac7000, 0x00007fa0f8d37000, 0x00007fa100000000]
71
* total_blobs=486 nmethods=8 adapters=399
72
* compilation: enabled
73
*/
74
75
static Pattern line1 = Pattern.compile("(CodeCache|CodeHeap.*): size=(\\p{Digit}*)Kb used=(\\p{Digit}*)Kb max_used=(\\p{Digit}*)Kb free=(\\p{Digit}*)Kb");
76
static Pattern line2 = Pattern.compile(" bounds \\[0x(\\p{XDigit}*), 0x(\\p{XDigit}*), 0x(\\p{XDigit}*)\\]");
77
static Pattern line3 = Pattern.compile(" total_blobs=(\\p{Digit}*) nmethods=(\\p{Digit}*) adapters=(\\p{Digit}*)");
78
static Pattern line4 = Pattern.compile(" compilation: (.*)");
79
80
private static boolean getFlagBool(String flag, String where) {
81
Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where);
82
if (!m.find()) {
83
Assert.fail("Could not find value for flag " + flag + " in output string");
84
}
85
return m.group(1).equals("true");
86
}
87
88
private static int getFlagInt(String flag, String where) {
89
Matcher m = Pattern.compile(flag + "\\s+:?=\\s+\\d+").matcher(where);
90
if (!m.find()) {
91
Assert.fail("Could not find value for flag " + flag + " in output string");
92
}
93
String match = m.group();
94
return Integer.parseInt(match.substring(match.lastIndexOf(" ") + 1, match.length()));
95
}
96
97
public void run(CommandExecutor executor) {
98
// Get number of code cache segments
99
int segmentsCount = 0;
100
String flags = executor.execute("VM.flags -all").getOutput();
101
if (!getFlagBool("SegmentedCodeCache", flags) || !getFlagBool("UseCompiler", flags)) {
102
// No segmentation
103
segmentsCount = 1;
104
} else if (getFlagBool("TieredCompilation", flags) && getFlagInt("TieredStopAtLevel", flags) > 1) {
105
// Tiered compilation: use all segments
106
segmentsCount = 3;
107
} else {
108
// No TieredCompilation: only non-nmethod and non-profiled segment
109
segmentsCount = 2;
110
}
111
112
// Get output from dcmd (diagnostic command)
113
OutputAnalyzer output = executor.execute("Compiler.codecache");
114
Iterator<String> lines = output.asLines().iterator();
115
116
// Validate code cache segments
117
String line;
118
Matcher m;
119
int matchedCount = 0;
120
while (true) {
121
// Validate first line
122
line = lines.next();
123
m = line1.matcher(line);
124
if (m.matches()) {
125
for (int i = 2; i <= 5; i++) {
126
int val = Integer.parseInt(m.group(i));
127
if (val < 0) {
128
Assert.fail("Failed parsing dcmd codecache output");
129
}
130
}
131
} else {
132
break;
133
}
134
135
// Validate second line
136
line = lines.next();
137
m = line2.matcher(line);
138
if (m.matches()) {
139
String start = m.group(1);
140
String mark = m.group(2);
141
String top = m.group(3);
142
143
// Lexical compare of hex numbers to check that they look sane.
144
if (start.compareTo(mark) > 1) {
145
Assert.fail("Failed parsing dcmd codecache output");
146
}
147
if (mark.compareTo(top) > 1) {
148
Assert.fail("Failed parsing dcmd codecache output");
149
}
150
} else {
151
Assert.fail("Regexp 2 failed to match line: " + line);
152
}
153
++matchedCount;
154
}
155
// Because of CodeCacheExtensions, we could match more than expected
156
if (matchedCount < segmentsCount) {
157
Assert.fail("Fewer segments matched (" + matchedCount + ") than expected (" + segmentsCount + ")");
158
}
159
160
// Validate third line
161
m = line3.matcher(line);
162
if (m.matches()) {
163
int blobs = Integer.parseInt(m.group(1));
164
if (blobs <= 0) {
165
Assert.fail("Failed parsing dcmd codecache output");
166
}
167
int nmethods = Integer.parseInt(m.group(2));
168
if (nmethods < 0) {
169
Assert.fail("Failed parsing dcmd codecache output");
170
}
171
int adapters = Integer.parseInt(m.group(3));
172
if (adapters <= 0) {
173
Assert.fail("Failed parsing dcmd codecache output");
174
}
175
if (blobs < (nmethods + adapters)) {
176
Assert.fail("Failed parsing dcmd codecache output");
177
}
178
} else {
179
Assert.fail("Regexp 3 failed to match line: " + line);
180
}
181
182
// Validate fourth line
183
line = lines.next();
184
m = line4.matcher(line);
185
if (!m.matches()) {
186
Assert.fail("Regexp 4 failed to match line: " + line);
187
}
188
}
189
190
@Test
191
public void jmx() {
192
run(new JMXExecutor());
193
}
194
}
195
196