1 /*
  2  * Copyright (c) 2016, 2018, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 /*
 27  * @test id=passive
 28  * @summary Acceptance tests: collector can withstand allocation
 29  * @key randomness
 30  * @requires vm.gc.Shenandoah
 31  * @library /test/lib
 32  *
 33  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 34  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 35  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 36  *      TestAllocObjectArrays
 37  *
 38  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 39  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 40  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 41  *      TestAllocObjectArrays
 42  *
 43  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 44  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 45  *      -XX:+ShenandoahDegeneratedGC
 46  *      TestAllocObjectArrays
 47  *
 48  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 49  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 50  *      -XX:-ShenandoahDegeneratedGC
 51  *      TestAllocObjectArrays
 52  */
 53 
 54 /*
 55  * @test id=aggressive
 56  * @summary Acceptance tests: collector can withstand allocation
 57  * @key randomness
 58  * @requires vm.gc.Shenandoah
 59  * @library /test/lib
 60  *
 61  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 62  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 63  *      -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify
 64  *      TestAllocObjectArrays
 65  *
 66  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 67  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 68  *      -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify
 69  *      TestAllocObjectArrays
 70  *
 71  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 72  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 73  *      -XX:+ShenandoahOOMDuringEvacALot
 74  *      TestAllocObjectArrays
 75  *
 76  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 77  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 78  *      -XX:+ShenandoahAllocFailureALot
 79  *      TestAllocObjectArrays
 80  *
 81  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 82  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 83  *      TestAllocObjectArrays
 84  */
 85 
 86 /*
 87  * @test id=adaptive
 88  * @summary Acceptance tests: collector can withstand allocation
 89  * @key randomness
 90  * @requires vm.gc.Shenandoah
 91  * @library /test/lib
 92  *
 93  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 94  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 95  *      -XX:+ShenandoahVerify
 96  *      TestAllocObjectArrays
 97  *
 98  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
 99  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
100  *      TestAllocObjectArrays
101  */
102 
103 /*
104  * @test id=generational
105  * @summary Acceptance tests: collector can withstand allocation
106  * @key randomness
107  * @requires vm.gc.Shenandoah
108  * @library /test/lib
109  *
110  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
111  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
112  *      -XX:+ShenandoahVerify
113  *      TestAllocObjectArrays
114  *
115  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
116  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
117  *      TestAllocObjectArrays
118  *
119  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
120  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
121  *      -XX:+ShenandoahOOMDuringEvacALot
122  *      -XX:+ShenandoahVerify
123  *      TestAllocObjectArrays
124  *
125  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
126  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
127  *      -XX:+ShenandoahAllocFailureALot
128  *      -XX:+ShenandoahVerify
129  *      TestAllocObjectArrays
130  */
131 
132 /*
133  * @test id=static
134  * @summary Acceptance tests: collector can withstand allocation
135  * @key randomness
136  * @requires vm.gc.Shenandoah
137  * @library /test/lib
138  *
139  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
140  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
141  *      TestAllocObjectArrays
142  */
143 
144 /*
145  * @test id=compact
146  * @summary Acceptance tests: collector can withstand allocation
147  * @key randomness
148  * @requires vm.gc.Shenandoah
149  * @library /test/lib
150  *
151  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
152  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
153  *      TestAllocObjectArrays
154  */
155 
156 /*
157  * @test id=no-tlab
158  * @summary Acceptance tests: collector can withstand allocation
159  * @key randomness
160  * @requires vm.gc.Shenandoah
161  * @library /test/lib
162  *
163  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
164  *      -XX:+UseShenandoahGC
165  *      -XX:-UseTLAB -XX:+ShenandoahVerify
166  *      TestAllocObjectArrays
167  *
168  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
169  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
170  *      -XX:-UseTLAB -XX:+ShenandoahVerify
171  *      TestAllocObjectArrays
172  */
173 
174 /*
175  * @test id=iu-aggressive
176  * @summary Acceptance tests: collector can withstand allocation
177  * @key randomness
178  * @requires vm.gc.Shenandoah
179  * @library /test/lib
180  *
181  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
182  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
183  *      -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify
184  *      TestAllocObjectArrays
185  *
186  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
187  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
188  *      -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify
189  *      TestAllocObjectArrays
190  *
191  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
192  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
193  *      -XX:+ShenandoahOOMDuringEvacALot
194  *      TestAllocObjectArrays
195  *
196  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
197  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
198  *      -XX:+ShenandoahAllocFailureALot
199  *      TestAllocObjectArrays
200  *
201  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
202  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
203  *      TestAllocObjectArrays
204  */
205 
206 /*
207  * @test id=iu
208  * @summary Acceptance tests: collector can withstand allocation
209  * @key randomness
210  * @requires vm.gc.Shenandoah
211  * @library /test/lib
212  *
213  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
214  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
215  *      -XX:+ShenandoahVerify
216  *      TestAllocObjectArrays
217  *
218  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
219  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
220  *      TestAllocObjectArrays
221  */
222 
223 import java.util.Random;
224 import jdk.test.lib.Utils;
225 
226 public class TestAllocObjectArrays {
227 
228     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation
229 
230     static volatile Object sink;
231 
232     public static void main(String[] args) throws Exception {
233         final int min = 0;
234         final int max = 384 * 1024;
235         long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
236 
237         Random r = Utils.getRandomInstance();
238         for (long c = 0; c < count; c++) {
239             sink = new Object[min + r.nextInt(max - min)];
240         }
241     }
242 
243 }