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 TestGCThreadGroups
  26  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
  27  * @key gc
  28  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  29  *
  30  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  31  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  32  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  33  *      -Dtarget=1000
  34  *      TestGCThreadGroups
  35  *
  36  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  37  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  38  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
  39  *      -Dtarget=1000
  40  *      TestGCThreadGroups
  41  */
  42 
  43 /**
  44  * @test TestGCThreadGroups
  45  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
  46  * @key gc
  47  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  48  *
  49  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  50  *      -XX:+UseShenandoahGC
  51  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  52  *      -Dtarget=1000
  53  *      TestGCThreadGroups
  54  *
  55  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  56  *      -XX:+UseShenandoahGC
  57  *      -XX:-UseDynamicNumberOfGCThreads
  58  *      -Dtarget=1000
  59  *      TestGCThreadGroups
  60  *
  61  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  62  *      -XX:+UseShenandoahGC
  63  *      -XX:+ForceDynamicNumberOfGCThreads
  64  *      -Dtarget=1000
  65  *      TestGCThreadGroups
  66  *
  67  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  68  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  69  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  70  *      -Dtarget=1000
  71  *      TestGCThreadGroups
  72  *
  73  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  74  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  75  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
  76  *      -Dtarget=1000
  77  *      TestGCThreadGroups
  78  *
  79  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  80  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  81  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  82  *      -Dtarget=1000
  83  *      TestGCThreadGroups
  84  *
  85  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  86  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  87  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
  88  *      -Dtarget=1000
  89  *      TestGCThreadGroups
  90  *
  91  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  92  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  93  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  94  *      -Dtarget=100
  95  *      TestGCThreadGroups
  96  *
  97  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  98  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  99  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
 100  *      -Dtarget=100
 101  *      TestGCThreadGroups
 102  *
 103  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 104  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 105  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
 106  *      -Dtarget=100
 107  *      TestGCThreadGroups
 108  *
 109  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 110  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
 111  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
 112  *      -Dtarget=100
 113  *      TestGCThreadGroups
 114  */
 115 
 116 /**
 117  * @test TestGCThreadGroups
 118  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
 119  * @key gc
 120  * @requires vm.gc.Shenandoah & !vm.graal.enabled
 121  *
 122  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 123  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal
 124  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
 125  *      -Dtarget=1000
 126  *      TestGCThreadGroups
 127  *
 128  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 129  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal -XX:ShenandoahGCHeuristics=aggressive
 130  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
 131  *      -Dtarget=1000
 132  *      TestGCThreadGroups
 133  *
 134  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 135  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal
 136  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
 137  *      -Dtarget=1000
 138  *      TestGCThreadGroups
 139  *
 140  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
 141  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=traversal -XX:ShenandoahGCHeuristics=aggressive
 142  *      -XX:ConcGCThreads=4 -XX:ParallelGCThreads=2
 143  *      -Dtarget=1000
 144  *      TestGCThreadGroups
 145 */
 146 
 147 public class TestGCThreadGroups {
 148 
 149     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation, around 1K cycles to handle
 150     static final long STRIDE = 100_000;
 151 
 152     static volatile Object sink;
 153 
 154     public static void main(String[] args) throws Exception {
 155         long count = TARGET_MB * 1024 * 1024 / 16;
 156         for (long c = 0; c < count; c += STRIDE) {
 157             for (long s = 0; s < STRIDE; s++) {
 158                 sink = new Object();
 159             }
 160             Thread.sleep(1);
 161         }
 162     }
 163 
 164 }