1 /*
  2  * Copyright (c) 2017, 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 deal with retained objects
 29  * @key randomness
 30  * @requires vm.gc.Shenandoah
 31  * @library /test/lib
 32  *
 33  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 34  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 35  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 36  *      TestSieveObjects
 37  *
 38  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 39  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 40  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
 41  *      TestSieveObjects
 42  *
 43  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 44  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 45  *      -XX:+ShenandoahDegeneratedGC
 46  *      TestSieveObjects
 47  *
 48  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 49  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
 50  *      -XX:-ShenandoahDegeneratedGC
 51  *      TestSieveObjects
 52  */
 53 
 54 /*
 55  * @test id=aggressive
 56  * @summary Acceptance tests: collector can deal with retained objects
 57  * @key randomness
 58  * @requires vm.gc.Shenandoah
 59  * @library /test/lib
 60  *
 61  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 62  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 63  *      -XX:+ShenandoahOOMDuringEvacALot
 64  *      TestSieveObjects
 65  *
 66  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 67  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 68  *      -XX:+ShenandoahAllocFailureALot
 69  *      TestSieveObjects
 70  *
 71  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 72  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 73  *      TestSieveObjects
 74  */
 75 
 76 /*
 77  * @test id=adaptive
 78  * @summary Acceptance tests: collector can deal with retained objects
 79  * @key randomness
 80  * @requires vm.gc.Shenandoah
 81  * @library /test/lib
 82  *
 83  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 84  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 85  *      -XX:+ShenandoahVerify
 86  *      TestSieveObjects
 87  *
 88  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 89  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
 90  *      TestSieveObjects
 91  *
 92  */
 93 
 94 /*
 95  * @test id=generational
 96  * @summary Acceptance tests: collector can deal with retained objects
 97  * @key randomness
 98  * @requires vm.gc.Shenandoah
 99  * @library /test/lib
100  *
101  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
102  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
103  *      -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify
104  *      TestSieveObjects
105  *
106  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
107  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
108  *      -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify
109  *      TestSieveObjects
110  *
111  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
112  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive -XX:ShenandoahGCMode=generational
113  *      TestSieveObjects
114  */
115 
116 /*
117  * @test id=static
118  * @summary Acceptance tests: collector can deal with retained objects
119  * @key randomness
120  * @requires vm.gc.Shenandoah
121  * @library /test/lib
122  *
123  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
124  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
125  *      TestSieveObjects
126  */
127 
128 /*
129  * @test id=compact
130  * @summary Acceptance tests: collector can deal with retained objects
131  * @key randomness
132  * @requires vm.gc.Shenandoah
133  * @library /test/lib
134  *
135  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
136  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
137  *      TestSieveObjects
138  */
139 
140 /*
141  * @test id=no-tlab
142  * @summary Acceptance tests: collector can deal with retained objects
143  * @key randomness
144  * @requires vm.gc.Shenandoah
145  * @library /test/lib
146  *
147  * @run main/othervm/timeout=300 -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
148  *      -XX:+UseShenandoahGC
149  *      -XX:-UseTLAB -XX:+ShenandoahVerify
150  *      TestSieveObjects
151  */
152 
153 /*
154  * @test id=iu-aggressive
155  * @summary Acceptance tests: collector can deal with retained objects
156  * @key randomness
157  * @requires vm.gc.Shenandoah
158  * @library /test/lib
159  *
160  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
161  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
162  *      -XX:+ShenandoahOOMDuringEvacALot
163  *      TestSieveObjects
164  *
165  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
166  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
167  *      -XX:+ShenandoahAllocFailureALot
168  *      TestSieveObjects
169  *
170  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
171  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
172  *      TestSieveObjects
173  */
174 
175 /*
176  * @test id=iu
177  * @summary Acceptance tests: collector can deal with retained objects
178  * @key randomness
179  * @requires vm.gc.Shenandoah
180  * @library /test/lib
181  *
182  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
183  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
184  *      -XX:+ShenandoahVerify
185  *      TestSieveObjects
186  *
187  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
188  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
189  *      TestSieveObjects
190  */
191 
192 import java.util.Random;
193 import jdk.test.lib.Utils;
194 
195 public class TestSieveObjects {
196 
197     static final int COUNT = 100_000_000;
198     static final int WINDOW = 1_000_000;
199     static final int PAYLOAD = 100;
200 
201     static final MyObject[] arr = new MyObject[WINDOW];
202 
203     public static void main(String[] args) throws Exception {
204         int rIdx = 0;
205         Random rng = Utils.getRandomInstance();
206         for (int c = 0; c < COUNT; c++) {
207             MyObject v = arr[rIdx];
208             if (v != null) {
209                 if (v.x != rIdx) {
210                     throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x);
211                 }
212                 if (rng.nextInt(1000) > 100) {
213                     arr[rIdx] = null;
214                 }
215             } else {
216                 if (rng.nextInt(1000) > 500) {
217                     arr[rIdx] = new MyObject(rIdx);
218                 }
219             }
220             rIdx++;
221             if (rIdx >= WINDOW) {
222                 rIdx = 0;
223             }
224         }
225     }
226 
227     public static class MyObject {
228         public int x;
229         public byte[] payload;
230 
231         public MyObject(int x) {
232             this.x = x;
233             this.payload = new byte[PAYLOAD];
234         }
235     }
236 
237 }