Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestG1SkipCompaction.java
40942 views
1
/*
2
* Copyright (c) 2021, Huawei Technologies Co. Ltd. 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 TestG1SkipCompaction
26
* @summary Test for JDK-8262068 Improve G1 Full GC by skipping compaction
27
* for regions with high survival ratio.
28
* @requires vm.gc.G1
29
* @library /test/lib
30
* @modules java.base/jdk.internal.misc
31
* java.management
32
* @run main/othervm -Xms256m -Xmx256m TestG1SkipCompaction
33
*/
34
import java.util.regex.Matcher;
35
import java.util.regex.Pattern;
36
37
import java.util.ArrayList;
38
import java.util.List;
39
40
import jdk.test.lib.Platform;
41
import jdk.test.lib.process.OutputAnalyzer;
42
import jdk.test.lib.process.ProcessTools;
43
44
public class TestG1SkipCompaction {
45
public static void runTest() throws Exception {
46
final String[] arguments = {
47
"-XX:+UseG1GC",
48
"-XX:MarkSweepDeadRatio=3",
49
"-Xmx8m",
50
"-Xms8M",
51
"-Xlog:gc+phases=trace",
52
"-XX:G1HeapRegionSize=1m",
53
GCTest.class.getName()
54
};
55
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(arguments);
56
OutputAnalyzer output = new OutputAnalyzer(pb.start());
57
System.out.println(output.getStdout());
58
59
String pattern = ".*skip compaction region.*";
60
Pattern r = Pattern.compile(pattern);
61
Matcher m = r.matcher(output.getStdout());
62
63
if (!m.find()) {
64
throw new RuntimeException("Could not find any not compacted regions in the logs");
65
}
66
}
67
68
public static void main(String[] args) throws Exception {
69
runTest();
70
}
71
72
static class GCTest {
73
public static List<char[]> memory;
74
public static void main(String[] args) throws Exception {
75
memory = new ArrayList<>();
76
try {
77
while (true) {
78
memory.add(new char[8 * 1024]);
79
System.gc();
80
}
81
} catch (OutOfMemoryError e) {
82
memory = null;
83
System.gc();
84
}
85
}
86
}
87
}
88
89
90