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