Path: blob/master/test/hotspot/jtreg/gc/shenandoah/TestPeriodicGC.java
40942 views
/*1* Copyright (c) 2017, 2020, Red Hat, Inc. 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*22*/2324/*25* @test TestPeriodicGC26* @summary Test that periodic GC is working27* @requires vm.gc.Shenandoah28* @library /test/lib29* @run driver TestPeriodicGC30*/3132import java.util.*;3334import jdk.test.lib.Asserts;35import jdk.test.lib.process.ProcessTools;36import jdk.test.lib.process.OutputAnalyzer;3738public class TestPeriodicGC {3940public static void testWith(String msg, boolean periodic, String... args) throws Exception {41String[] cmds = Arrays.copyOf(args, args.length + 2);42cmds[args.length] = TestPeriodicGC.class.getName();43cmds[args.length + 1] = "test";44ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(cmds);4546OutputAnalyzer output = new OutputAnalyzer(pb.start());47output.shouldHaveExitValue(0);48if (periodic && !output.getOutput().contains("Trigger: Time since last GC")) {49throw new AssertionError(msg + ": Should have periodic GC in logs");50}51if (!periodic && output.getOutput().contains("Trigger: Time since last GC")) {52throw new AssertionError(msg + ": Should not have periodic GC in logs");53}54}5556public static void main(String[] args) throws Exception {57if (args.length > 0 && args[0].equals("test")) {58Thread.sleep(5000); // stay idle59return;60}6162String[] enabled = new String[] {63"adaptive",64"compact",65"static",66};6768for (String h : enabled) {69testWith("Zero interval with " + h,70false,71"-Xlog:gc",72"-XX:+UnlockDiagnosticVMOptions",73"-XX:+UnlockExperimentalVMOptions",74"-XX:+UseShenandoahGC",75"-XX:ShenandoahGCHeuristics=" + h,76"-XX:ShenandoahGuaranteedGCInterval=0"77);7879testWith("Short interval with " + h,80true,81"-Xlog:gc",82"-XX:+UnlockDiagnosticVMOptions",83"-XX:+UnlockExperimentalVMOptions",84"-XX:+UseShenandoahGC",85"-XX:ShenandoahGCHeuristics=" + h,86"-XX:ShenandoahGuaranteedGCInterval=1000"87);8889testWith("Long interval with " + h,90false,91"-Xlog:gc",92"-XX:+UnlockDiagnosticVMOptions",93"-XX:+UnlockExperimentalVMOptions",94"-XX:+UseShenandoahGC",95"-XX:ShenandoahGCHeuristics=" + h,96"-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long97);98}99100testWith("Zero interval with iu mode",101false,102"-Xlog:gc",103"-XX:+UnlockDiagnosticVMOptions",104"-XX:+UnlockExperimentalVMOptions",105"-XX:+UseShenandoahGC",106"-XX:ShenandoahGCMode=iu",107"-XX:ShenandoahGuaranteedGCInterval=0"108);109110testWith("Short interval with iu mode",111true,112"-Xlog:gc",113"-XX:+UnlockDiagnosticVMOptions",114"-XX:+UnlockExperimentalVMOptions",115"-XX:+UseShenandoahGC",116"-XX:ShenandoahGCMode=iu",117"-XX:ShenandoahGuaranteedGCInterval=1000"118);119120testWith("Long interval with iu mode",121false,122"-Xlog:gc",123"-XX:+UnlockDiagnosticVMOptions",124"-XX:+UnlockExperimentalVMOptions",125"-XX:+UseShenandoahGC",126"-XX:ShenandoahGCMode=iu",127"-XX:ShenandoahGuaranteedGCInterval=100000" // deliberately too long128);129130testWith("Short interval with aggressive",131false,132"-Xlog:gc",133"-XX:+UnlockDiagnosticVMOptions",134"-XX:+UnlockExperimentalVMOptions",135"-XX:+UseShenandoahGC",136"-XX:ShenandoahGCHeuristics=aggressive",137"-XX:ShenandoahGuaranteedGCInterval=1000"138);139140testWith("Zero interval with passive",141false,142"-Xlog:gc",143"-XX:+UnlockDiagnosticVMOptions",144"-XX:+UnlockExperimentalVMOptions",145"-XX:+UseShenandoahGC",146"-XX:ShenandoahGCMode=passive",147"-XX:ShenandoahGuaranteedGCInterval=0"148);149150testWith("Short interval with passive",151false,152"-Xlog:gc",153"-XX:+UnlockDiagnosticVMOptions",154"-XX:+UnlockExperimentalVMOptions",155"-XX:+UseShenandoahGC",156"-XX:ShenandoahGCMode=passive",157"-XX:ShenandoahGuaranteedGCInterval=1000"158);159}160161}162163164