Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/g1/TestHumongousConcurrentStartUndo.java
40942 views
1
/*
2
* Copyright (c) 2020, 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 TestHumongousConcurrentStartUndo
28
* @summary Tests an alternating sequence of Concurrent Mark and Concurrent Undo
29
* cycles.
30
* reclaim heap occupancy falls below the IHOP value.
31
* @requires vm.gc.G1
32
* @library /test/lib /testlibrary /
33
* @modules java.base/jdk.internal.misc
34
* java.management
35
* @build sun.hotspot.WhiteBox
36
* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox
37
* sun.hotspot.WhiteBox$WhiteBoxPermission
38
* @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.
39
* gc.g1.TestHumongousConcurrentStartUndo
40
*/
41
42
import gc.testlibrary.Helpers;
43
44
import sun.hotspot.WhiteBox;
45
import jdk.test.lib.process.OutputAnalyzer;
46
import jdk.test.lib.process.ProcessTools;
47
48
import java.lang.ref.Reference;
49
50
public class TestHumongousConcurrentStartUndo {
51
// Heap sizes < 224 MB are increased to 224 MB if vm_page_size == 64K to
52
// fulfill alignment constraints.
53
private static final int HeapSize = 224; // MB
54
private static final int HeapRegionSize = 1; // MB
55
private static final int InitiatingHeapOccupancyPercent = 50; // %
56
private static final int YoungSize = HeapSize / 8;
57
58
public static void main(String[] args) throws Exception {
59
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
60
"-Xbootclasspath/a:.",
61
"-XX:+UseG1GC",
62
"-Xms" + HeapSize + "m",
63
"-Xmx" + HeapSize + "m",
64
"-Xmn" + YoungSize + "m",
65
"-XX:G1HeapRegionSize=" + HeapRegionSize + "m",
66
"-XX:InitiatingHeapOccupancyPercent=" + InitiatingHeapOccupancyPercent,
67
"-XX:-G1UseAdaptiveIHOP",
68
"-XX:+UnlockDiagnosticVMOptions",
69
"-XX:+WhiteBoxAPI",
70
"-Xlog:gc*",
71
EdenObjectAllocatorWithHumongousAllocation.class.getName());
72
73
OutputAnalyzer output = new OutputAnalyzer(pb.start());
74
output.shouldContain("Pause Young (Concurrent Start) (G1 Humongous Allocation)");
75
output.shouldContain("Concurrent Undo Cycle");
76
output.shouldContain("Concurrent Mark Cycle");
77
output.shouldHaveExitValue(0);
78
System.out.println(output.getStdout());
79
}
80
81
static class EdenObjectAllocatorWithHumongousAllocation {
82
private static final WhiteBox WB = WhiteBox.getWhiteBox();
83
84
private static final int M = 1024 * 1024;
85
// Make humongous object size 75% of region size
86
private static final int HumongousObjectSize =
87
(int)(HeapRegionSize * M * 0.75);
88
// Number of objects to allocate to go above IHOP
89
private static final int NumHumongousObjectAllocations =
90
(int)(((HeapSize - YoungSize) * 80 / 100.0) / HeapRegionSize);
91
92
93
private static void allocateHumongous(int num, Object[] holder) {
94
for (int i = 0; i < num; i++) {
95
if (i % 10 == 0) {
96
System.out.println("Allocating humongous object " + i + "/" + num +
97
" of size " + HumongousObjectSize + " bytes");
98
}
99
holder[i % holder.length] = new byte[HumongousObjectSize];
100
}
101
}
102
103
private static void runConcurrentUndoCycle() {
104
// Start from an "empty" heap.
105
WB.fullGC();
106
// The queue only holds one element, so only one humongous object
107
// will be reachable and the concurrent operation should be undone.
108
allocateHumongous(NumHumongousObjectAllocations, new Object[1]);
109
Helpers.waitTillCMCFinished(WB, 1);
110
}
111
112
private static void runConcurrentMarkCycle() {
113
Object[] a = new Object[NumHumongousObjectAllocations];
114
// Start from an "empty" heap.
115
WB.fullGC();
116
// Try to trigger a concurrent mark cycle. Block concurrent operation
117
// while we are allocating more humongous objects than the IHOP threshold.
118
// After releasing control, trigger the full cycle.
119
try {
120
System.out.println("Acquire CM control");
121
WB.concurrentGCAcquireControl();
122
allocateHumongous(NumHumongousObjectAllocations, a);
123
} finally {
124
System.out.println("Release CM control");
125
WB.concurrentGCReleaseControl();
126
}
127
// At this point we kept NumHumongousObjectAllocations humongous objects live
128
// in "a" which is larger than the IHOP threshold. Another dummy humongous
129
// allocation must trigger a concurrent cycle that is not an Undo Cycle.
130
allocateHumongous(1, new Object[1]);
131
Helpers.waitTillCMCFinished(WB, 1);
132
133
Reference.reachabilityFence(a);
134
}
135
136
public static void main(String [] args) throws Exception {
137
for (int iterate = 0; iterate < 3; iterate++) {
138
runConcurrentUndoCycle();
139
runConcurrentMarkCycle();
140
}
141
}
142
}
143
}
144
145
146