1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* 25 * @test SieveObjects 26 * @summary Acceptance tests: collector can deal with retained objects 27 * 28 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:+ShenandoahVerify SieveObjects 29 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive -XX:+ShenandoahVerify SieveObjects 30 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive -XX:+ShenandoahVerify SieveObjects 31 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static -XX:+ShenandoahVerify SieveObjects 32 * 33 * @run main/othervm/timeout=240 -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:-UseTLAB -XX:+ShenandoahVerify SieveObjects 34 * 35 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g SieveObjects 36 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=passive SieveObjects 37 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=adaptive SieveObjects 38 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=static SieveObjects 39 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=compact SieveObjects 40 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive SieveObjects 41 * 42 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahOOMDuringEvacALot SieveObjects 43 * @run main/othervm -XX:+UseShenandoahGC -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g -XX:ShenandoahGCHeuristics=aggressive -XX:+ShenandoahAllocFailureALot SieveObjects 44 */ 45 46 import java.util.concurrent.ThreadLocalRandom; 47 48 public class SieveObjects { 49 50 static final int COUNT = 100_000_000; 51 static final int WINDOW = 1_000_000; 52 static final int PAYLOAD = 100; 53 54 static final MyObject[] arr = new MyObject[WINDOW]; 55 56 public static void main(String[] args) throws Exception { 57 int rIdx = 0; 58 for (int c = 0; c < COUNT; c++) { 59 MyObject v = arr[rIdx]; 60 if (v != null) { 61 if (v.x != rIdx) { 62 throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x); 63 } 64 if (ThreadLocalRandom.current().nextInt(1000) > 100) { 65 arr[rIdx] = null; 66 } 67 } else { 68 if (ThreadLocalRandom.current().nextInt(1000) > 500) { 69 arr[rIdx] = new MyObject(rIdx); 70 } 71 } 72 rIdx++; 73 if (rIdx >= WINDOW) { 74 rIdx = 0; 75 } 76 } 77 } 78 79 public static class MyObject { 80 public int x; 81 public byte[] payload; 82 public MyObject(int x) { 83 this.x = x; 84 this.payload = new byte[PAYLOAD]; 85 } 86 } 87 88 }