Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java
41149 views
1
/*
2
* Copyright (c) 2014, 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 CheckSegmentedCodeCache
26
* @bug 8015774
27
* @summary Checks VM options related to the segmented code cache
28
* @library /test/lib
29
* @requires vm.flagless
30
*
31
* @build sun.hotspot.WhiteBox
32
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
33
* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions
34
* -XX:+WhiteBoxAPI
35
* compiler.codecache.CheckSegmentedCodeCache
36
*/
37
38
package compiler.codecache;
39
40
import jdk.test.lib.process.OutputAnalyzer;
41
import jdk.test.lib.Platform;
42
import jdk.test.lib.process.ProcessTools;
43
import sun.hotspot.WhiteBox;
44
45
public class CheckSegmentedCodeCache {
46
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
47
// Code heap names
48
private static final String NON_METHOD = "CodeHeap 'non-nmethods'";
49
private static final String PROFILED = "CodeHeap 'profiled nmethods'";
50
private static final String NON_PROFILED = "CodeHeap 'non-profiled nmethods'";
51
52
private static void verifySegmentedCodeCache(ProcessBuilder pb, boolean enabled) throws Exception {
53
OutputAnalyzer out = new OutputAnalyzer(pb.start());
54
out.shouldHaveExitValue(0);
55
if (enabled) {
56
try {
57
// Non-nmethod code heap should be always available with the segmented code cache
58
out.shouldContain(NON_METHOD);
59
} catch (RuntimeException e) {
60
// Check if TieredCompilation is disabled (in a client VM)
61
if (!out.getOutput().contains("-XX:+TieredCompilation not supported in this VM")) {
62
// Code cache is not segmented
63
throw new RuntimeException("No code cache segmentation.");
64
}
65
}
66
} else {
67
out.shouldNotContain(NON_METHOD);
68
}
69
}
70
71
private static void verifyCodeHeapNotExists(ProcessBuilder pb, String... heapNames) throws Exception {
72
OutputAnalyzer out = new OutputAnalyzer(pb.start());
73
out.shouldHaveExitValue(0);
74
for (String name : heapNames) {
75
out.shouldNotContain(name);
76
}
77
}
78
79
private static void failsWith(ProcessBuilder pb, String message) throws Exception {
80
OutputAnalyzer out = new OutputAnalyzer(pb.start());
81
out.shouldContain(message);
82
out.shouldHaveExitValue(1);
83
}
84
85
/**
86
* Check the result of segmented code cache related VM options.
87
*/
88
public static void main(String[] args) throws Exception {
89
ProcessBuilder pb;
90
91
// Disabled with ReservedCodeCacheSize < 240MB
92
pb = ProcessTools.createJavaProcessBuilder("-XX:ReservedCodeCacheSize=239m",
93
"-XX:+PrintCodeCache",
94
"-version");
95
verifySegmentedCodeCache(pb, false);
96
97
// Disabled without TieredCompilation
98
pb = ProcessTools.createJavaProcessBuilder("-XX:-TieredCompilation",
99
"-XX:+PrintCodeCache",
100
"-version");
101
verifySegmentedCodeCache(pb, false);
102
103
// Enabled with TieredCompilation and ReservedCodeCacheSize >= 240MB
104
pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
105
"-XX:ReservedCodeCacheSize=240m",
106
"-XX:+PrintCodeCache",
107
"-version");
108
verifySegmentedCodeCache(pb, true);
109
pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",
110
"-XX:ReservedCodeCacheSize=400m",
111
"-XX:+PrintCodeCache",
112
"-version");
113
verifySegmentedCodeCache(pb, true);
114
115
// Always enabled if SegmentedCodeCache is set
116
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
117
"-XX:-TieredCompilation",
118
"-XX:ReservedCodeCacheSize=239m",
119
"-XX:+PrintCodeCache",
120
"-version");
121
verifySegmentedCodeCache(pb, true);
122
123
// The profiled and non-profiled code heaps should not be available in
124
// interpreter-only mode
125
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
126
"-Xint",
127
"-XX:+PrintCodeCache",
128
"-version");
129
verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);
130
131
// If we stop compilation at CompLevel_none or CompLevel_simple we
132
// don't need a profiled code heap.
133
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
134
"-XX:TieredStopAtLevel=0",
135
"-XX:+PrintCodeCache",
136
"-version");
137
verifyCodeHeapNotExists(pb, PROFILED);
138
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
139
"-XX:TieredStopAtLevel=1",
140
"-XX:+PrintCodeCache",
141
"-version");
142
verifyCodeHeapNotExists(pb, PROFILED);
143
144
// Fails with too small non-nmethod code heap size
145
pb = ProcessTools.createJavaProcessBuilder("-XX:NonNMethodCodeHeapSize=100K",
146
"-version");
147
failsWith(pb, "Invalid NonNMethodCodeHeapSize");
148
149
// Fails if code heap sizes do not add up
150
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
151
"-XX:ReservedCodeCacheSize=10M",
152
"-XX:NonNMethodCodeHeapSize=5M",
153
"-XX:ProfiledCodeHeapSize=5M",
154
"-XX:NonProfiledCodeHeapSize=5M",
155
"-version");
156
failsWith(pb, "Invalid code heap sizes");
157
158
// Fails if not enough space for VM internal code
159
long minUseSpace = WHITE_BOX.getUintxVMFlag("CodeCacheMinimumUseSpace");
160
// minimum size: CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)
161
long minSize = (Platform.isDebugBuild() ? 3 : 1) * minUseSpace;
162
pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",
163
"-XX:ReservedCodeCacheSize=" + minSize,
164
"-XX:InitialCodeCacheSize=100K",
165
"-version");
166
failsWith(pb, "Not enough space in non-nmethod code heap to run VM");
167
}
168
}
169
170