1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. 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 25 /* 26 * @test TestExplicitGC 27 * @summary Test that Shenandoah reacts to explicit GC flags appropriately 28 * @key gc 29 * @requires vm.gc.Shenandoah & !vm.graal.enabled 30 * @library /test/lib 31 * @modules java.base/jdk.internal.misc 32 * java.management 33 * @run driver TestExplicitGC 34 */ 35 36 import jdk.test.lib.process.ProcessTools; 37 import jdk.test.lib.process.OutputAnalyzer; 38 39 public class TestExplicitGC { 40 41 enum Mode { 42 PRODUCT, 43 DIAGNOSTIC, 44 EXPERIMENTAL, 45 } 46 47 public static void main(String[] args) throws Exception { 48 if (args.length > 0) { 49 System.out.println("Calling System.gc()"); 50 System.gc(); 51 return; 52 } 53 54 String[] full = new String[] { 55 "Pause Full" 56 }; 57 58 String[] concNormal = new String[] { 59 "Pause Init Mark", 60 "Pause Final Mark", 61 }; 62 63 { 64 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 65 "-XX:+UnlockExperimentalVMOptions", 66 "-XX:+UseShenandoahGC", 67 "-Xlog:gc", 68 TestExplicitGC.class.getName(), 69 "test"); 70 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 71 for (String p : full) { 72 output.shouldNotContain(p); 73 } 74 for (String p : concNormal) { 75 output.shouldContain(p); 76 } 77 } 78 79 { 80 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 81 "-XX:+UnlockExperimentalVMOptions", 82 "-XX:+UseShenandoahGC", 83 "-Xlog:gc", 84 "-XX:+DisableExplicitGC", 85 TestExplicitGC.class.getName(), 86 "test"); 87 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 88 for (String p : full) { 89 output.shouldNotContain(p); 90 } 91 for (String p : concNormal) { 92 output.shouldNotContain(p); 93 } 94 } 95 96 { 97 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 98 "-XX:+UnlockExperimentalVMOptions", 99 "-XX:+UseShenandoahGC", 100 "-Xlog:gc", 101 "-XX:+ExplicitGCInvokesConcurrent", 102 TestExplicitGC.class.getName(), 103 "test"); 104 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 105 for (String p : full) { 106 output.shouldNotContain(p); 107 } 108 for (String p : concNormal) { 109 output.shouldContain(p); 110 } 111 } 112 113 { 114 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 115 "-XX:+UnlockExperimentalVMOptions", 116 "-XX:+UseShenandoahGC", 117 "-Xlog:gc", 118 "-XX:-ExplicitGCInvokesConcurrent", 119 TestExplicitGC.class.getName(), 120 "test"); 121 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 122 for (String p : full) { 123 output.shouldContain(p); 124 } 125 for (String p : concNormal) { 126 output.shouldNotContain(p); 127 } 128 } 129 } 130 }