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