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 TestSieveObjects
  27  * @summary Acceptance tests: collector can deal with retained objects
  28  * @key gc
  29  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  30  *
  31  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  32  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  33  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
  34  *      TestSieveObjects
  35  *
  36  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  37  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  38  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
  39  *      TestSieveObjects
  40  *
  41  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  42  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  43  *      -XX:+ShenandoahDegeneratedGC
  44  *      TestSieveObjects
  45  *
  46  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  47  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  48  *      -XX:-ShenandoahDegeneratedGC
  49  *      TestSieveObjects
  50  */
  51 
  52 /*
  53  * @test TestSieveObjects
  54  * @summary Acceptance tests: collector can deal with retained objects
  55  * @key gc
  56  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  57  *
  58  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  59  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  60  *      -XX:+ShenandoahOOMDuringEvacALot
  61  *      TestSieveObjects
  62  *
  63  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  64  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  65  *      -XX:+ShenandoahAllocFailureALot
  66  *      TestSieveObjects
  67  *
  68  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  69  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  70  *      TestSieveObjects
  71  *
  72  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  73  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  74  *      -XX:+ShenandoahVerify
  75  *      TestSieveObjects
  76  *
  77  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  78  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  79  *      TestSieveObjects
  80  *
  81  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  82  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  83  *      TestSieveObjects
  84  *
  85  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  86  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  87  *      TestSieveObjects
  88  *
  89  * @run main/othervm/timeout=240 -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  90  *      -XX:+UseShenandoahGC
  91  *      -XX:-UseTLAB -XX:+ShenandoahVerify
  92  *      TestSieveObjects
  93  */
  94 
  95 /*
  96  * @test TestSieveObjects
  97  * @summary Acceptance tests: collector can deal with retained objects
  98  * @key gc
  99  * @requires vm.gc.Shenandoah & !vm.graal.enabled
 100  *
 101  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 102  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
 103  *      -XX:+ShenandoahOOMDuringEvacALot
 104  *      TestSieveObjects
 105  *
 106  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 107  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
 108  *      -XX:+ShenandoahAllocFailureALot
 109  *      TestSieveObjects
 110  *
 111  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 112  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
 113  *      TestSieveObjects
 114  *
 115  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 116  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 117  *      -XX:+ShenandoahVerify
 118  *      TestSieveObjects
 119  *
 120  * @run main/othervm -Xmx1g -Xms1g -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 121  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
 122  *      TestSieveObjects
 123  */
 124 
 125 import java.util.concurrent.ThreadLocalRandom;
 126 
 127 public class TestSieveObjects {
 128 
 129     static final int COUNT = 100_000_000;
 130     static final int WINDOW = 1_000_000;
 131     static final int PAYLOAD = 100;
 132 
 133     static final MyObject[] arr = new MyObject[WINDOW];
 134 
 135     public static void main(String[] args) throws Exception {
 136         int rIdx = 0;
 137         for (int c = 0; c < COUNT; c++) {
 138             MyObject v = arr[rIdx];
 139             if (v != null) {
 140                 if (v.x != rIdx) {
 141                     throw new IllegalStateException("Illegal value at index " + rIdx + ": " + v.x);
 142                 }
 143                 if (ThreadLocalRandom.current().nextInt(1000) > 100) {
 144                     arr[rIdx] = null;
 145                 }
 146             } else {
 147                 if (ThreadLocalRandom.current().nextInt(1000) > 500) {
 148                     arr[rIdx] = new MyObject(rIdx);
 149                 }
 150             }
 151             rIdx++;
 152             if (rIdx >= WINDOW) {
 153                 rIdx = 0;
 154             }
 155         }
 156     }
 157 
 158     public static class MyObject {
 159         public int x;
 160         public byte[] payload;
 161 
 162         public MyObject(int x) {
 163             this.x = x;
 164             this.payload = new byte[PAYLOAD];
 165         }
 166     }
 167 
 168 }