1 /* 2 * Copyright (c) 2015, 2020, Oracle and/or its affiliates. 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 package gc.g1.mixedgc; 25 26 import java.util.ArrayList; 27 import java.util.Collections; 28 import java.util.List; 29 30 import gc.testlibrary.g1.MixedGCProvoker; 31 import jdk.test.lib.process.OutputAnalyzer; 32 import jdk.test.lib.process.ProcessTools; 33 34 /* 35 * @test TestLogging 36 * @summary Check that a mixed GC is reflected in the gc logs 37 * @requires vm.gc.G1 38 * @requires vm.opt.MaxGCPauseMillis == "null" 39 * @library /test/lib / 40 * @modules java.base/jdk.internal.misc 41 * @modules java.management 42 * @build sun.hotspot.WhiteBox 43 * @run driver ClassFileInstaller sun.hotspot.WhiteBox 44 * @run driver gc.g1.mixedgc.TestLogging 45 */ 46 47 /** 48 * Test spawns MixedGCProvoker in a separate VM and expects to find a message 49 * telling that a mixed gc has happened 50 */ 51 public class TestLogging { 52 private static final String[] COMMON_OPTIONS = new String[]{ 53 "-Xbootclasspath/a:.", "-XX:+UseG1GC", 54 "-XX:+UnlockExperimentalVMOptions", 55 "-XX:+UnlockDiagnosticVMOptions", 56 "-XX:+WhiteBoxAPI", 57 "-Xms10M", "-Xmx10M", "-XX:NewSize=2M", "-XX:MaxNewSize=2M", 58 "-XX:+AlwaysTenure", // surviving promote objects immediately 59 "-XX:InitiatingHeapOccupancyPercent=100", // set initial CMC threshold and disable adaptive IHOP 60 "-XX:-G1UseAdaptiveIHOP", // to avoid additional concurrent cycles caused by ergonomics 61 "-XX:G1MixedGCCountTarget=4", 62 "-XX:MaxGCPauseMillis=30000", // to have enough time 63 "-XX:G1HeapRegionSize=1m", "-XX:G1HeapWastePercent=0", 64 "-XX:G1MixedGCLiveThresholdPercent=100"}; 65 main(String args[])66 public static void main(String args[]) throws Exception { 67 // Test turns logging on by giving -Xlog:gc flag 68 test("-Xlog:gc,gc+heap=debug"); 69 // Test turns logging on by giving -Xlog:gc=debug flag 70 test("-Xlog:gc=debug,gc+heap=debug"); 71 } 72 test(String vmFlag)73 private static void test(String vmFlag) throws Exception { 74 System.out.println(String.format("%s: running with %s flag", TestLogging.class.getSimpleName(), vmFlag)); 75 OutputAnalyzer output = spawnMixedGCProvoker(vmFlag); 76 System.out.println(output.getStdout()); 77 output.shouldHaveExitValue(0); 78 output.shouldContain("Pause Young (Mixed)"); 79 } 80 81 /** 82 * Method spawns MixedGCProvoker with addition flags set 83 * 84 * @parameter extraFlags -flags to be added to the common options set 85 */ spawnMixedGCProvoker(String... extraFlags)86 private static OutputAnalyzer spawnMixedGCProvoker(String... extraFlags) 87 throws Exception { 88 List<String> testOpts = new ArrayList<>(); 89 Collections.addAll(testOpts, COMMON_OPTIONS); 90 Collections.addAll(testOpts, extraFlags); 91 testOpts.add(RunMixedGC.class.getName()); 92 System.out.println(testOpts); 93 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(testOpts); 94 return new OutputAnalyzer(pb.start()); 95 } 96 } 97 98 class RunMixedGC { main(String[] args)99 public static void main(String[] args) { 100 final int MB = 1024 * 1024; 101 MixedGCProvoker.allocateAndProvokeMixedGC(MB); 102 } 103 } 104 105