1 /*
   2  * Copyright (c) 2017, 2020, 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 TestGCThreadGroups
  27  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
  28  * @key gc
  29  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  30  *
  31  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  32  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=passive
  33  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  34  *      -Dtarget=1000
  35  *      TestGCThreadGroups
  36  */
  37 
  38 /**
  39  * @test TestGCThreadGroups
  40  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
  41  * @key gc
  42  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  43  *
  44  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  45  *      -XX:+UseShenandoahGC
  46  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  47  *      -Dtarget=1000
  48  *      TestGCThreadGroups
  49  *
  50  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  51  *      -XX:+UseShenandoahGC
  52  *      -XX:-UseDynamicNumberOfGCThreads
  53  *      -Dtarget=1000
  54  *      TestGCThreadGroups
  55  *
  56  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  57  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=adaptive
  58  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  59  *      -Dtarget=1000
  60  *      TestGCThreadGroups
  61  *
  62  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  63  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=static
  64  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  65  *      -Dtarget=1000
  66  *      TestGCThreadGroups
  67  *
  68  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  69  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=compact
  70  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  71  *      -Dtarget=100
  72  *      TestGCThreadGroups
  73  *
  74  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  75  *      -XX:+UseShenandoahGC -XX:ShenandoahGCHeuristics=aggressive
  76  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  77  *      -Dtarget=100
  78  *      TestGCThreadGroups
  79  */
  80 
  81 /**
  82  * @test TestGCThreadGroups
  83  * @summary Test Shenandoah GC uses concurrent/parallel threads correctly
  84  * @key gc
  85  * @requires vm.gc.Shenandoah & !vm.graal.enabled
  86  *
  87  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  88  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu
  89  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  90  *      -Dtarget=1000
  91  *      TestGCThreadGroups
  92  *
  93  * @run main/othervm -Xmx16m -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions
  94  *      -XX:+UseShenandoahGC -XX:ShenandoahGCMode=iu -XX:ShenandoahGCHeuristics=aggressive
  95  *      -XX:ConcGCThreads=2 -XX:ParallelGCThreads=4
  96  *      -Dtarget=1000
  97  *      TestGCThreadGroups
  98 */
  99 
 100 public class TestGCThreadGroups {
 101 
 102     static final long TARGET_MB = Long.getLong("target", 10_000); // 10 Gb allocation, around 1K cycles to handle
 103     static final long STRIDE = 100_000;
 104 
 105     static volatile Object sink;
 106 
 107     public static void main(String[] args) throws Exception {
 108         long count = TARGET_MB * 1024 * 1024 / 16;
 109         for (long c = 0; c < count; c += STRIDE) {
 110             for (long s = 0; s < STRIDE; s++) {
 111                 sink = new Object();
 112             }
 113             Thread.sleep(1);
 114         }
 115     }
 116 
 117 }