Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/gc/shenandoah/TestPeriodicGC.java
32284 views
/*1* Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation.6*7* This code is distributed in the hope that it will be useful, but WITHOUT8* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or9* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License10* version 2 for more details (a copy is included in the LICENSE file that11* accompanied this code).12*13* You should have received a copy of the GNU General Public License version14* 2 along with this work; if not, write to the Free Software Foundation,15* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.16*17* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA18* or visit www.oracle.com if you need additional information or have any19* questions.20*21*/2223/*24* @test TestPeriodicGC25* @summary Test that periodic GC is working26* @key gc27* @library /testlibrary28*29* @run driver TestPeriodicGC30*/3132import java.util.*;3334import com.oracle.java.testlibrary.*;3536public class TestPeriodicGC {3738public static void testWith(String msg, boolean periodic, String... args) throws Exception {39String[] cmds = Arrays.copyOf(args, args.length + 2);40cmds[args.length] = TestPeriodicGC.class.getName();41cmds[args.length + 1] = "test";42ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);4344OutputAnalyzer output = new OutputAnalyzer(pb.start());45output.shouldHaveExitValue(0);46if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) {47throw new AssertionError(msg + ": Should have periodic GC in logs");48}49if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) {50throw new AssertionError(msg + ": Should not have periodic GC in logs");51}52}5354public static void main(String[] args) throws Exception {55if (args.length > 0 && args[0].equals("test")) {56Thread.sleep(5000); // stay idle57return;58}5960String[] enabled = new String[] {61"adaptive",62"compact",63"static"64};6566for (String h : enabled) {67testWith("Zero interval with " + h,68false,69"-verbose:gc",70"-XX:+UnlockDiagnosticVMOptions",71"-XX:+UnlockExperimentalVMOptions",72"-XX:+UseShenandoahGC",73"-XX:ShenandoahGCHeuristics=" + h,74"-XX:ShenandoahGuaranteedGCInterval=0"75);7677testWith("Short interval with " + h,78true,79"-verbose:gc",80"-XX:+UnlockDiagnosticVMOptions",81"-XX:+UnlockExperimentalVMOptions",82"-XX:+UseShenandoahGC",83"-XX:ShenandoahGCHeuristics=" + h,84"-XX:ShenandoahGuaranteedGCInterval=1000"85);8687testWith("Long interval with " + h,88false,89"-verbose:gc",90"-XX:+UnlockDiagnosticVMOptions",91"-XX:+UnlockExperimentalVMOptions",92"-XX:+UseShenandoahGC",93"-XX:ShenandoahGCHeuristics=" + h,94"-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long95);96}9798testWith("Zero interval with iu mode",99false,100"-verbose:gc",101"-XX:+UnlockDiagnosticVMOptions",102"-XX:+UnlockExperimentalVMOptions",103"-XX:+UseShenandoahGC",104"-XX:ShenandoahGCMode=iu",105"-XX:ShenandoahGuaranteedGCInterval=0"106);107108testWith("Short interval with iu mode",109true,110"-verbose:gc",111"-XX:+UnlockDiagnosticVMOptions",112"-XX:+UnlockExperimentalVMOptions",113"-XX:+UseShenandoahGC",114"-XX:ShenandoahGCMode=iu",115"-XX:ShenandoahGuaranteedGCInterval=1000"116);117118testWith("Long interval with iu mode",119false,120"-verbose:gc",121"-XX:+UnlockDiagnosticVMOptions",122"-XX:+UnlockExperimentalVMOptions",123"-XX:+UseShenandoahGC",124"-XX:ShenandoahGCMode=iu",125"-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long126);127128testWith("Short interval with aggressive",129false,130"-verbose:gc",131"-XX:+UnlockDiagnosticVMOptions",132"-XX:+UnlockExperimentalVMOptions",133"-XX:+UseShenandoahGC",134"-XX:ShenandoahGCHeuristics=aggressive",135"-XX:ShenandoahGuaranteedGCInterval=1000"136);137138testWith("Zero interval with passive",139false,140"-verbose:gc",141"-XX:+UnlockDiagnosticVMOptions",142"-XX:+UnlockExperimentalVMOptions",143"-XX:+UseShenandoahGC",144"-XX:ShenandoahGCMode=passive",145"-XX:ShenandoahGuaranteedGCInterval=0"146);147148testWith("Short interval with passive",149false,150"-verbose:gc",151"-XX:+UnlockDiagnosticVMOptions",152"-XX:+UnlockExperimentalVMOptions",153"-XX:+UseShenandoahGC",154"-XX:ShenandoahGCMode=passive",155"-XX:ShenandoahGuaranteedGCInterval=1000"156);157}158159}160161162