Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/ergonomics/TestDynamicNumberOfGCThreads.java
32284 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test TestDynamicNumberOfGCThreads25* @bug 801746226* @summary Ensure that UseDynamicNumberOfGCThreads runs27* @requires vm.gc=="null"28* @key gc29* @library /testlibrary30*/3132import com.oracle.java.testlibrary.ProcessTools;33import com.oracle.java.testlibrary.OutputAnalyzer;3435public class TestDynamicNumberOfGCThreads {36public static void main(String[] args) throws Exception {3738testDynamicNumberOfGCThreads("UseConcMarkSweepGC");3940testDynamicNumberOfGCThreads("UseG1GC");4142testDynamicNumberOfGCThreads("UseParallelGC");43}4445private static void verifyDynamicNumberOfGCThreads(OutputAnalyzer output) {46output.shouldHaveExitValue(0); // test should run succesfully47output.shouldContain("new_active_workers");48}4950private static void testDynamicNumberOfGCThreads(String gcFlag) throws Exception {51// UseDynamicNumberOfGCThreads and TraceDynamicGCThreads enabled52String[] baseArgs = {"-XX:+" + gcFlag, "-Xmx10M", "-XX:+PrintGCDetails", "-XX:+UseDynamicNumberOfGCThreads", "-XX:+TraceDynamicGCThreads", GCTest.class.getName()};5354// Base test with gc and +UseDynamicNumberOfGCThreads:55ProcessBuilder pb_enabled = ProcessTools.createJavaProcessBuilder(baseArgs);56verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start()));5758// Ensure it also works on uniprocessors or if user specifies -XX:ParallelGCThreads=1:59String[] extraArgs = {"-XX:+UnlockDiagnosticVMOptions", "-XX:+ForceDynamicNumberOfGCThreads", "-XX:ParallelGCThreads=1"};60String[] finalArgs = new String[baseArgs.length + extraArgs.length];61System.arraycopy(extraArgs, 0, finalArgs, 0, extraArgs.length);62System.arraycopy(baseArgs, 0, finalArgs, extraArgs.length, baseArgs.length);63pb_enabled = ProcessTools.createJavaProcessBuilder(finalArgs);64verifyDynamicNumberOfGCThreads(new OutputAnalyzer(pb_enabled.start()));65}6667static class GCTest {68private static byte[] garbage;69public static void main(String [] args) {70System.out.println("Creating garbage");71// create 128MB of garbage. This should result in at least one GC72for (int i = 0; i < 1024; i++) {73garbage = new byte[128 * 1024];74}75System.out.println("Done");76}77}78}798081