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