37
37
import java .util .Collections ;
38
38
39
39
import jdk .test .lib .Asserts ;
40
+ import jdk .test .lib .Platform ;
40
41
import jdk .test .lib .process .OutputAnalyzer ;
41
42
import jdk .test .lib .process .ProcessTools ;
42
43
import sun .hotspot .WhiteBox ;
@@ -52,6 +53,9 @@ public static void main(String args[]) throws Exception {
52
53
testAllExplicitlyEnabled ();
53
54
testFullAndRemark ();
54
55
testConcurrentMark ();
56
+ if (Platform .isDebugBuild ()) {
57
+ testYoungEvacFail ();
58
+ }
55
59
testBadVerificationType ();
56
60
}
57
61
@@ -115,13 +119,33 @@ private static void testConcurrentMark() throws Exception {
115
119
verifyCollection ("Pause Full" , false , false , false , output .getStdout ());
116
120
}
117
121
122
+ private static void testYoungEvacFail () throws Exception {
123
+ OutputAnalyzer output ;
124
+ output = testWithVerificationType (new String [] {"young-evac-fail" },
125
+ new String [] {"-XX:+G1EvacuationFailureALot" ,
126
+ "-XX:G1EvacuationFailureALotCount=100" ,
127
+ "-XX:G1EvacuationFailureALotInterval=1" ,
128
+ "-XX:+UnlockDiagnosticVMOptions" ,
129
+ "-XX:-G1AllowPreventiveGC" });
130
+ output .shouldHaveExitValue (0 );
131
+
132
+ verifyCollection ("Pause Young (Normal)" , false , false , true , output .getStdout ());
133
+ verifyCollection ("Pause Young (Concurrent Start)" , false , false , true , output .getStdout ());
134
+ verifyCollection ("Pause Young (Mixed)" , false , false , true , output .getStdout ());
135
+ verifyCollection ("Pause Young (Prepare Mixed)" , false , false , true , output .getStdout ());
136
+ verifyCollection ("Pause Remark" , false , false , false , output .getStdout ());
137
+ verifyCollection ("Pause Cleanup" , false , false , false , output .getStdout ());
138
+ verifyCollection ("Pause Full" , false , false , false , output .getStdout ());
139
+ }
140
+
141
+
118
142
private static void testBadVerificationType () throws Exception {
119
143
OutputAnalyzer output ;
120
144
// Test bad type
121
145
output = testWithVerificationType (new String [] {"old" });
122
146
output .shouldHaveExitValue (0 );
123
147
124
- output .shouldMatch ("VerifyGCType: '.*' is unknown. Available types are: young-normal, concurrent-start, mixed, remark, cleanup and full" );
148
+ output .shouldMatch ("VerifyGCType: '.*' is unknown. Available types are: young-normal, young-evac-fail, concurrent-start, mixed, remark, cleanup and full" );
125
149
verifyCollection ("Pause Young (Normal)" , true , false , true , output .getStdout ());
126
150
verifyCollection ("Pause Young (Concurrent Start)" , true , false , true , output .getStdout ());
127
151
verifyCollection ("Pause Young (Mixed)" , true , false , true , output .getStdout ());
@@ -131,7 +155,7 @@ private static void testBadVerificationType() throws Exception {
131
155
verifyCollection ("Pause Full" , true , true , true , output .getStdout ());
132
156
}
133
157
134
- private static OutputAnalyzer testWithVerificationType (String [] types ) throws Exception {
158
+ private static OutputAnalyzer testWithVerificationType (String [] types , String ... extraOpts ) throws Exception {
135
159
ArrayList <String > basicOpts = new ArrayList <>();
136
160
Collections .addAll (basicOpts , new String [] {
137
161
"-Xbootclasspath/a:." ,
@@ -151,10 +175,13 @@ private static OutputAnalyzer testWithVerificationType(String[] types) throws Ex
151
175
basicOpts .add ("-XX:VerifyGCType=" +verifyType );
152
176
}
153
177
178
+ Collections .addAll (basicOpts , extraOpts );
179
+
154
180
basicOpts .add (TriggerGCs .class .getName ());
155
181
156
182
ProcessBuilder procBuilder = ProcessTools .createJavaProcessBuilder (basicOpts );
157
183
OutputAnalyzer analyzer = new OutputAnalyzer (procBuilder .start ());
184
+
158
185
return analyzer ;
159
186
}
160
187
@@ -228,6 +255,9 @@ static CollectionInfo parseFirst(String name, String data) {
228
255
}
229
256
230
257
public static class TriggerGCs {
258
+
259
+ // This class triggers GCs; we need to make sure that in all of the young gcs
260
+ // at least some objects survive so that evacuation failure can happen.
231
261
public static void main (String args []) throws Exception {
232
262
WhiteBox wb = WhiteBox .getWhiteBox ();
233
263
// Allocate some memory that can be turned into garbage.
@@ -241,16 +271,24 @@ public static void main(String args[]) throws Exception {
241
271
// Memory have been promoted to old by full GC. Free
242
272
// some memory to be reclaimed by concurrent cycle.
243
273
partialFree (used );
274
+
275
+ used = alloc1M ();
244
276
wb .g1StartConcMarkCycle (); // concurrent-start, remark and cleanup
277
+ partialFree (used );
245
278
246
279
// Sleep to make sure concurrent cycle is done
247
280
while (wb .g1InConcurrentMark ()) {
248
281
Thread .sleep (1000 );
249
282
}
250
283
251
284
// Trigger two young GCs, first will be young-prepare-mixed, second will be mixed.
285
+ used = alloc1M ();
252
286
wb .youngGC (); // young-prepare-mixed
287
+ partialFree (used );
288
+
289
+ used = alloc1M ();
253
290
wb .youngGC (); // mixed
291
+ partialFree (used );
254
292
}
255
293
256
294
private static Object [] alloc1M () {
0 commit comments