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=240 -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
148  *      -XX:+UseShenandoahGC
149  *      -XX:-UseTLAB -XX:+ShenandoahVerify
150  *      TestSieveObjects
151  */
152 
153 import java.util.Random;
154 import jdk.test.lib.Utils;
155 
156 public class TestSieveObjects {
157 
158     static final int COUNT = 100_000_000;
159     static final int WINDOW = 1_000_000;
160     static final int PAYLOAD = 100;
161 
162     static final MyObject[] arr = new MyObject[WINDOW];
163 
164     public static void main(String[] args) throws Exception {
165         int rIdx = 0;
166         Random rng = Utils.getRandomInstance();
167         for (int c = 0; c < COUNT; c++) {
168             MyObject v = arr[rIdx];
169             if (v != null) {
170                 if (v.x != rIdx) {
171                     throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x);
172                 }
173                 if (rng.nextInt(1000) > 100) {
174                     arr[rIdx] = null;
175                 }
176             } else {
177                 if (rng.nextInt(1000) > 500) {
178                     arr[rIdx] = new MyObject(rIdx);
179                 }
180             }
181             rIdx++;
182             if (rIdx >= WINDOW) {
183                 rIdx = 0;
184             }
185         }
186     }
187 
188     public static class MyObject {
189         public int x;
190         public byte[] payload;
191 
192         public MyObject(int x) {
193             this.x = x;
194             this.payload = new byte[PAYLOAD];
195         }
196     }
197 
198 }