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