1 /*
   2  * Copyright (c) 2016, 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 TestAllocObjectArrays
  27  * @summary Acceptance tests: collector can withstand allocation
  28  * @key gc
  29  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  30  *
  31  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  32  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  33  *      -XX:+ShenandoahDegeneratedGC -XX:+ShenandoahVerify
  34  *      TestAllocObjectArrays
  35  *
  36  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  37  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  38  *      -XX:-ShenandoahDegeneratedGC -XX:+ShenandoahVerify
  39  *      TestAllocObjectArrays
  40  *
  41  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  42  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  43  *      -XX:+ShenandoahDegeneratedGC
  44  *      TestAllocObjectArrays
  45  *
  46  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  47  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  48  *      -XX:-ShenandoahDegeneratedGC
  49  *      TestAllocObjectArrays
  50 
  51 /*
  52  * @test TestAllocObjectArrays
  53  * @summary Acceptance tests: collector can withstand allocation
  54  * @key gc
  55  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  56  *
  57  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  58  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  59  *      -XX:+ShenandoahOOMDuringEvacALot -XX:+ShenandoahVerify
  60  *      TestAllocObjectArrays
  61  *
  62  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  63  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  64  *      -XX:+ShenandoahAllocFailureALot -XX:+ShenandoahVerify
  65  *      TestAllocObjectArrays
  66  *
  67  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  68  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  69  *      -XX:+ShenandoahOOMDuringEvacALot
  70  *      TestAllocObjectArrays
  71  *
  72  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  73  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  74  *      -XX:+ShenandoahAllocFailureALot
  75  *      TestAllocObjectArrays
  76  *
  77  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  78  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  79  *      TestAllocObjectArrays
  80  *
  81  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  82  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  83  *      -XX:+ShenandoahVerify
  84  *      TestAllocObjectArrays
  85  *
  86  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  87  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  88  *      TestAllocObjectArrays
  89  *
  90  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  91  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  92  *      TestAllocObjectArrays
  93  *
  94  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  95  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  96  *      TestAllocObjectArrays
  97  *
  98  * @run main/othervm -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions -Xmx1g -Xms1g
  99  *      -XX:+UseShenandoahGC
 100  *      -XX:-UseTLAB -XX:+ShenandoahVerify
 101  *      TestAllocObjectArrays
 102  */
 103 
 104 import java.util.Random;
 105 
 106 public class TestAllocObjectArrays {
 107 
 108     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation
 109 
 110     static volatile Object sink;
 111 
 112     public static void main(String[] args) throws Exception {
 113         final int min = 0;
 114         final int max = 384 * 1024;
 115         long count = TARGET_MB * 1024 * 1024 / (16 + 4 * (min + (max - min) / 2));
 116 
 117         Random r = new Random();
 118         for (long c = 0; c < count; c++) {
 119             sink = new Object[min + r.nextInt(max - min)];
 120         }
 121     }
 122 
 123 }