Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/gc/arguments/TestNewRatioFlag.java
40942 views
1
/*
2
* Copyright (c) 2015, 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.arguments;
25
26
/*
27
* @test TestNewRatioFlag
28
* @bug 8025166
29
* @summary Verify that heap devided among generations according to NewRatio
30
* @requires vm.gc != "Z" & vm.gc != "Shenandoah"
31
* @library /test/lib
32
* @library /
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
* @run driver gc.arguments.TestNewRatioFlag
38
*/
39
40
import java.util.Arrays;
41
import java.util.Collections;
42
import java.util.LinkedList;
43
import jdk.test.lib.process.ProcessTools;
44
import jdk.test.lib.process.OutputAnalyzer;
45
import jdk.test.lib.Utils;
46
import sun.hotspot.WhiteBox;
47
48
public class TestNewRatioFlag {
49
50
public static final long M = 1024 * 1024;
51
public static final long HEAP_SIZE = 100 * M;
52
53
public static void main(String args[]) throws Exception {
54
LinkedList<String> options = new LinkedList<>(
55
Arrays.asList(Utils.getFilteredTestJavaOpts("(-XX:[^ ]*NewSize=[^ ]+)|(-Xm[ns][^ ]+)"))
56
);
57
58
testNewRatio(4, options);
59
testNewRatio(6, options);
60
testNewRatio(10, options);
61
testNewRatio(15, options);
62
testNewRatio(20, options);
63
}
64
65
/**
66
* Verify that actual size of young gen conforms specified NewRatio
67
*
68
* @param ratio value of NewRatio option
69
* @param options additional options for VM
70
*/
71
public static void testNewRatio(int ratio, LinkedList<String> options) throws Exception {
72
LinkedList<String> vmOptions = new LinkedList<>(options);
73
Collections.addAll(vmOptions,
74
"-Xbootclasspath/a:.",
75
"-XX:+UnlockDiagnosticVMOptions",
76
"-XX:+WhiteBoxAPI",
77
"-XX:GCLockerEdenExpansionPercent=0",
78
"-Xmx" + HEAP_SIZE,
79
"-Xms" + HEAP_SIZE,
80
"-XX:NewRatio=" + ratio,
81
"-XX:-UseLargePages",
82
NewRatioVerifier.class.getName(),
83
Integer.toString(ratio)
84
);
85
86
ProcessBuilder procBuilder = GCArguments.createJavaProcessBuilder(vmOptions);
87
OutputAnalyzer analyzer = new OutputAnalyzer(procBuilder.start());
88
analyzer.shouldHaveExitValue(0);
89
System.out.println(analyzer.getOutput());
90
}
91
92
public static class NewRatioVerifier {
93
94
static WhiteBox wb = WhiteBox.getWhiteBox();
95
96
public static void main(String args[]) {
97
if (args.length != 1) {
98
throw new IllegalArgumentException("Expected 1 arg: <expectedRatio>");
99
}
100
int expectedRatio = Integer.valueOf(args[0]);
101
switch (GCTypes.YoungGCType.getYoungGCType()) {
102
case DefNew:
103
verifyDefNewNewRatio(expectedRatio);
104
break;
105
case PSNew:
106
verifyPSNewRatio(expectedRatio);
107
break;
108
case G1:
109
verifyG1NewRatio(expectedRatio);
110
break;
111
default:
112
throw new RuntimeException("Unexpected young GC type");
113
}
114
}
115
116
/**
117
* Verify NewSize for DefNew and ParNew collectors.
118
*
119
* Compare expected NewSize calculated according to sizing policies used by DefNew
120
* with NewSize value reported by MemoryPoolMXBeans.
121
*/
122
public static void verifyDefNewNewRatio(int expectedRatio) {
123
long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
124
long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
125
long initOld = HeapRegionUsageTool.getOldUsage().getInit();
126
127
long newSize = initEden + 2 * initSurv;
128
129
long expectedNewSize = HeapRegionUsageTool.alignDown(initOld / expectedRatio,
130
wb.getHeapSpaceAlignment());
131
132
if (expectedNewSize != newSize) {
133
throw new RuntimeException("Expected young gen size is: " + expectedNewSize
134
+ ", but observed new size is: " + newSize);
135
}
136
}
137
138
/**
139
* Verify NewSize for PS collector.
140
* Expected NewSize calculated according to alignment policies used by PS
141
* and then compared with actual NewSize obtained from MemoryPoolMXBeans.
142
*/
143
public static void verifyPSNewRatio(int expectedRatio) {
144
long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
145
long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
146
long initOld = HeapRegionUsageTool.getOldUsage().getInit();
147
148
long newSize = initEden + 2 * initSurv;
149
150
long alignedDownNewSize = HeapRegionUsageTool.alignDown(initOld / expectedRatio,
151
wb.getHeapSpaceAlignment());
152
long expectedNewSize = HeapRegionUsageTool.alignUp(alignedDownNewSize,
153
wb.psVirtualSpaceAlignment());
154
155
if (expectedNewSize != newSize) {
156
throw new RuntimeException("Expected young gen size is: " + expectedNewSize
157
+ ", but observed new size is: " + newSize);
158
}
159
}
160
161
/**
162
* Verify NewSize for G1 GC.
163
* Amount of young regions calculated according to sizing policies used by G1
164
* and then compared with actual number of young regions derived from
165
* values reported by MemoryPoolMXBeans and region size.
166
*/
167
public static void verifyG1NewRatio(int expectedRatio) {
168
long initEden = HeapRegionUsageTool.getEdenUsage().getInit();
169
long initSurv = HeapRegionUsageTool.getSurvivorUsage().getInit();
170
long maxOld = HeapRegionUsageTool.getOldUsage().getMax();
171
172
int regionSize = wb.g1RegionSize();
173
int youngListLength = (int) ((initEden + initSurv) / regionSize);
174
int maxRegions = (int) (maxOld / regionSize);
175
int expectedYoungListLength = (int) (maxRegions / (double) (expectedRatio + 1));
176
177
if (youngListLength != expectedYoungListLength) {
178
throw new RuntimeException("Expected G1 young list length is: " + expectedYoungListLength
179
+ ", but observed young list length is: " + youngListLength);
180
}
181
}
182
}
183
}
184
185