Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/test/hotspot/jtreg/gc/g1/TestG1TraceEagerReclaimHumongousObjects.java
64478 views
1
/*
2
* Copyright (c) 2014, 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
package gc.g1;
25
26
/*
27
* @test TestG1TraceEagerReclaimHumongousObjects
28
* @bug 8058801 8048179
29
* @summary Ensure that the output for a G1TraceEagerReclaimHumongousObjects
30
* includes the expected necessary messages.
31
* @requires vm.gc.G1
32
* @library /test/lib
33
* @modules java.base/jdk.internal.misc
34
* java.management
35
* @run driver gc.g1.TestG1TraceEagerReclaimHumongousObjects
36
*/
37
38
import jdk.test.lib.process.OutputAnalyzer;
39
import jdk.test.lib.process.ProcessTools;
40
import java.util.LinkedList;
41
42
public class TestG1TraceEagerReclaimHumongousObjects {
43
public static void main(String[] args) throws Exception {
44
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+UseG1GC",
45
"-Xms128M",
46
"-Xmx128M",
47
"-Xmn16M",
48
"-XX:G1HeapRegionSize=1M",
49
"-Xlog:gc+phases=trace,gc+humongous=trace",
50
"-XX:+UnlockExperimentalVMOptions",
51
GCWithHumongousObjectTest.class.getName());
52
53
OutputAnalyzer output = new OutputAnalyzer(pb.start());
54
55
System.out.println(output.getStdout());
56
// As G1ReclaimDeadHumongousObjectsAtYoungGC is set(default), below logs should be displayed.
57
output.shouldContain("Humongous Reclaim");
58
output.shouldContain("Humongous Total");
59
output.shouldContain("Humongous Candidate");
60
output.shouldContain("Humongous Reclaimed");
61
62
// As G1TraceReclaimDeadHumongousObjectsAtYoungGC is set and GCWithHumongousObjectTest has humongous objects,
63
// these logs should be displayed.
64
output.shouldContain("Humongous region");
65
output.shouldContain("Reclaimed humongous region");
66
output.shouldHaveExitValue(0);
67
}
68
69
static class GCWithHumongousObjectTest {
70
71
public static final int M = 1024*1024;
72
public static LinkedList<Object> garbageList = new LinkedList<Object>();
73
// A large object referenced by a static.
74
static int[] filler = new int[10 * M];
75
76
public static void genGarbage() {
77
for (int i = 0; i < 32*1024; i++) {
78
garbageList.add(new int[100]);
79
}
80
garbageList.clear();
81
}
82
83
public static void main(String[] args) {
84
85
int[] large = new int[M];
86
Object ref = large;
87
88
System.out.println("Creating garbage");
89
for (int i = 0; i < 100; i++) {
90
// A large object that will be reclaimed eagerly.
91
large = new int[6*M];
92
genGarbage();
93
// Make sure that the compiler cannot completely remove
94
// the allocation of the large object until here.
95
System.out.println(large);
96
}
97
98
// Keep the reference to the first object alive.
99
System.out.println(ref);
100
System.out.println("Done");
101
}
102
}
103
}
104
105