Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/gc/g1/TestMixedGCLiveThreshold.java
64479 views
1
/*
2
* Copyright (c) 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
package gc.g1;
25
26
/*
27
* @test id=0percent
28
* @summary Test G1MixedGCLiveThresholdPercent=0. Fill up a region to at least 33 percent,
29
* the region should not be selected for mixed GC cycle.
30
* @requires vm.gc.G1
31
* @library /test/lib
32
* @build sun.hotspot.WhiteBox
33
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
34
* @run driver gc.g1.TestMixedGCLiveThreshold 0 false
35
*/
36
37
/*
38
* @test id=25percent
39
* @summary Test G1MixedGCLiveThresholdPercent=25. Fill up a region to at least 33 percent,
40
* the region should not be selected for mixed GC cycle.
41
* @requires vm.gc.G1
42
* @library /test/lib
43
* @build sun.hotspot.WhiteBox
44
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
45
* @run driver gc.g1.TestMixedGCLiveThreshold 25 false
46
*/
47
48
/*
49
* @test id=100percent
50
* @summary Test G1MixedGCLiveThresholdPercent=100. Fill up a region to at least 33 percent,
51
* the region should be selected for mixed GC cycle.
52
* @requires vm.gc.G1
53
* @library /test/lib
54
* @build sun.hotspot.WhiteBox
55
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
56
* @run driver gc.g1.TestMixedGCLiveThreshold 100 true
57
*/
58
59
import java.util.ArrayList;
60
import java.util.Collections;
61
import java.util.regex.Pattern;
62
import java.util.regex.Matcher;
63
64
import jdk.test.lib.process.OutputAnalyzer;
65
import jdk.test.lib.process.ProcessTools;
66
import jdk.test.lib.Asserts;
67
import sun.hotspot.WhiteBox;
68
69
public class TestMixedGCLiveThreshold {
70
private static final String pattern = "Remembered Set Tracking update regions total ([0-9]+), selected ([0-9]+)$";
71
72
public static void main(String[] args) throws Exception {
73
int liveThresholdPercent = Integer.parseInt(args[0]);
74
boolean expectRebuild = Boolean.parseBoolean(args[1]);
75
testMixedGCLiveThresholdPercent(liveThresholdPercent, expectRebuild);
76
}
77
78
private static void testMixedGCLiveThresholdPercent(int liveThresholdPercent, boolean expectedRebuild) throws Exception {
79
OutputAnalyzer output = testWithMixedGCLiveThresholdPercent(liveThresholdPercent);
80
81
boolean regionsSelected = regionsSelectedForRebuild(output.getStdout());
82
83
Asserts.assertEquals(regionsSelected, expectedRebuild,
84
(expectedRebuild ?
85
"No Regions selected for rebuild. G1MixedGCLiveThresholdPercent=" + liveThresholdPercent +
86
" at least one region should be selected" :
87
"Regions selected for rebuild. G1MixedGCLiveThresholdPercent=" + liveThresholdPercent +
88
" no regions should be selected")
89
);
90
output.shouldHaveExitValue(0);
91
output.reportDiagnosticSummary();
92
}
93
94
private static OutputAnalyzer testWithMixedGCLiveThresholdPercent(int percent) throws Exception {
95
ArrayList<String> basicOpts = new ArrayList<>();
96
Collections.addAll(basicOpts, new String[] {
97
"-Xbootclasspath/a:.",
98
"-XX:+UseG1GC",
99
"-XX:+UnlockDiagnosticVMOptions",
100
"-XX:+UnlockExperimentalVMOptions",
101
"-XX:+WhiteBoxAPI",
102
// Parallel full gc can distribute live objects into different regions.
103
"-XX:ParallelGCThreads=1",
104
"-Xlog:gc+remset+tracking=trace",
105
"-Xms10M",
106
"-Xmx10M"});
107
108
basicOpts.add("-XX:G1MixedGCLiveThresholdPercent=" + percent);
109
110
basicOpts.add(GCTest.class.getName());
111
112
ProcessBuilder procBuilder = ProcessTools.createJavaProcessBuilder(basicOpts);
113
OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
114
return analyzer;
115
}
116
117
private static boolean regionsSelectedForRebuild(String output) throws Exception {
118
Matcher m = Pattern.compile(pattern, Pattern.MULTILINE).matcher(output);
119
120
if (!m.find()) {
121
throw new Exception("Could not find correct output for Remembered Set Tracking in stdout," +
122
" should match the pattern \"" + pattern + "\", but stdout is \n" + output);
123
}
124
return Integer.parseInt(m.group(2)) > 0;
125
}
126
127
public static class GCTest {
128
public static void main(String args[]) throws Exception {
129
WhiteBox wb = WhiteBox.getWhiteBox();
130
// Allocate some memory less than region size.
131
Object used = allocate();
132
133
// Trigger the full GC using the WhiteBox API.
134
wb.fullGC(); // full
135
136
// Memory objects have been promoted to old by full GC.
137
// Concurrent cycle may select regions for rebuilding
138
wb.g1StartConcMarkCycle(); // concurrent-start, remark and cleanup
139
140
// Sleep to make sure concurrent cycle is done
141
while (wb.g1InConcurrentMark()) {
142
Thread.sleep(1000);
143
}
144
System.out.println(used);
145
}
146
147
private static Object allocate() {
148
final int objectSize = WhiteBox.getWhiteBox().g1RegionSize() / 3;
149
Object ret = new byte[objectSize];
150
return ret;
151
}
152
}
153
}
154
155