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