test/hotspot/jtreg/gc/arguments/TestParallelGCThreads.java
author jcbeyler
Mon, 13 Aug 2018 09:19:21 -0700
changeset 51396 38ec0cea438e
parent 47216 71c04702a3d5
child 53523 4c5184c56dc2
permissions -rw-r--r--
8061467: Add UseLargePages to TestNUMAPageSize Summary: Add flag to test for all architectures to be tested Reviewed-by: phh, pliden, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
     1
/*
41705
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     2
 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     4
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     7
 * published by the Free Software Foundation.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     8
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    13
 * accompanied this code).
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    14
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    18
 *
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    21
 * questions.
332239c052cc 8165687: Fix license and copyright headers in jd9 under hotspot/test
stsmirno
parents: 40631
diff changeset
    22
 */
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    23
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    24
/*
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    25
 * @test TestParallelGCThreads
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    26
 * @key gc
31330
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    27
 * @bug 8059527 8081382
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    28
 * @summary Tests argument processing for ParallelGCThreads
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    29
 * @library /test/lib
36851
03e2f4d0a421 8153737: Unsupported Module
chegar
parents: 31330
diff changeset
    30
 * @modules java.base/jdk.internal.misc
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 26939
diff changeset
    31
 *          java.management
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    32
 * @run driver TestParallelGCThreads
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    33
 */
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    34
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    35
import jdk.test.lib.Asserts;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 36851
diff changeset
    37
import jdk.test.lib.process.ProcessTools;
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    38
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    39
public class TestParallelGCThreads {
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    40
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    41
  public static void main(String args[]) throws Exception {
31330
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    42
    testFlags();
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    43
    testDefaultValue();
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    44
  }
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    45
31330
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    46
  private static final String flagName = "ParallelGCThreads";
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    47
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    48
  // uint ParallelGCThreads = 23 {product}
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    49
  private static final String printFlagsFinalPattern = " *uint *" + flagName + " *:?= *(\\d+) *\\{product\\} *";
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    50
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    51
  public static void testDefaultValue()  throws Exception {
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    52
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    53
      "-XX:+UnlockExperimentalVMOptions", "-XX:+PrintFlagsFinal", "-version");
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    54
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    55
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    56
    String value = output.firstMatch(printFlagsFinalPattern, 1);
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    57
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    58
    try {
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    59
      Asserts.assertNotNull(value, "Couldn't find uint flag " + flagName);
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    60
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    61
      Long longValue = new Long(value);
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    62
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    63
      // Sanity check that we got a non-zero value.
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    64
      Asserts.assertNotEquals(longValue, "0");
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    65
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    66
      output.shouldHaveExitValue(0);
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    67
    } catch (Exception e) {
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    68
      System.err.println(output.getOutput());
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    69
      throw e;
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    70
    }
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    71
  }
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    72
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    73
  public static void testFlags() throws Exception {
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    74
    // For each parallel collector (G1, Parallel, ParNew/CMS)
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    75
    for (String gc : new String[] {"G1", "Parallel", "ConcMarkSweep"}) {
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    76
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    77
      // Make sure the VM does not allow ParallelGCThreads set to 0
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    78
      String[] flags = new String[] {"-XX:+Use" + gc + "GC", "-XX:ParallelGCThreads=0", "-XX:+PrintFlagsFinal", "-version"};
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    79
      ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    80
      OutputAnalyzer output = new OutputAnalyzer(pb.start());
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    81
      output.shouldHaveExitValue(1);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    82
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    83
      // Do some basic testing to ensure the flag updates the count
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    84
      for (long i = 1; i <= 3; i++) {
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    85
        flags = new String[] {"-XX:+Use" + gc + "GC", "-XX:ParallelGCThreads=" + i, "-XX:+PrintFlagsFinal", "-version"};
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    86
        long count = getParallelGCThreadCount(flags);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    87
        Asserts.assertEQ(count, i, "Specifying ParallelGCThreads=" + i + " for " + gc + "GC does not set the thread count properly!");
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    88
      }
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    89
    }
31330
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    90
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    91
    // 4294967295 == (unsigned int) -1
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    92
    // So setting ParallelGCThreads=4294967295 should give back 4294967295
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    93
    // and setting ParallelGCThreads=4294967296 should give back 0. (SerialGC is ok with ParallelGCThreads=0)
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    94
    for (long i = 4294967295L; i <= 4294967296L; i++) {
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    95
      String[] flags = new String[] {"-XX:+UseSerialGC", "-XX:ParallelGCThreads=" + i, "-XX:+PrintFlagsFinal", "-version"};
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    96
      long count = getParallelGCThreadCount(flags);
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    97
      Asserts.assertEQ(count, i % 4294967296L, "Specifying ParallelGCThreads=" + i + " does not set the thread count properly!");
77061bb01b18 8081382: Make flags ParallelGCThreads and ConcGCThreads of type uint
david
parents: 30604
diff changeset
    98
    }
26939
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
    99
  }
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   100
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   101
  public static long getParallelGCThreadCount(String flags[]) throws Exception {
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   102
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   103
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   104
    output.shouldHaveExitValue(0);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   105
    String stdout = output.getStdout();
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   106
    return FlagsValue.getFlagLongValue("ParallelGCThreads", stdout);
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   107
  }
93633340028d 8059527: Disallow ParallelGCThreads=0 for G1
mlarsson
parents:
diff changeset
   108
}