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 * @requires vm.gc.Shenandoah & !vm.graal.enabled 29 * @library /test/lib 30 * @modules java.base/jdk.internal.misc 31 * java.management 32 * @run driver TestExplicitGC 33 */ 34 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 public class TestExplicitGC { 39 40 enum Mode { 41 PRODUCT, 42 DIAGNOSTIC, 43 EXPERIMENTAL, 44 } 45 46 public static void main(String[] args) throws Exception { 47 if (args.length > 0) { 48 System.out.println("Calling System.gc()"); 49 System.gc(); 50 return; 51 } 52 53 String[] full = new String[] { 54 "Pause Full" 55 }; 56 57 String[] concNormal = new String[] { 58 "Pause Init Mark", 59 "Pause Final Mark", 60 }; 61 62 { 63 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 64 "-Xmx128m", 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 "-Xmx128m", 82 "-XX:+UnlockExperimentalVMOptions", 83 "-XX:+UseShenandoahGC", 84 "-Xlog:gc", 85 "-XX:+DisableExplicitGC", 86 TestExplicitGC.class.getName(), 87 "test"); 88 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 89 for (String p : full) { 90 output.shouldNotContain(p); 91 } 92 for (String p : concNormal) { 93 output.shouldNotContain(p); 94 } 95 } 96 97 { 98 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 99 "-Xmx128m", 100 "-XX:+UnlockExperimentalVMOptions", 101 "-XX:+UseShenandoahGC", 102 "-Xlog:gc", 103 "-XX:+ExplicitGCInvokesConcurrent", 104 TestExplicitGC.class.getName(), 105 "test"); 106 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 107 for (String p : full) { 108 output.shouldNotContain(p); 109 } 110 for (String p : concNormal) { 111 output.shouldContain(p); 112 } 113 } 114 115 { 116 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 117 "-Xmx128m", 118 "-XX:+UnlockExperimentalVMOptions", 119 "-XX:+UseShenandoahGC", 120 "-Xlog:gc", 121 "-XX:-ExplicitGCInvokesConcurrent", 122 TestExplicitGC.class.getName(), 123 "test"); 124 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 125 for (String p : full) { 126 output.shouldContain(p); 127 } 128 for (String p : concNormal) { 129 output.shouldNotContain(p); 130 } 131 } 132 133 { 134 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 135 "-Xmx128m", 136 "-XX:+UnlockExperimentalVMOptions", 137 "-XX:+UseShenandoahGC", 138 "-Xlog:gc", 139 "-XX:+ExplicitGCInvokesConcurrent", 140 "-XX:ShenandoahGCMode=iu", 141 TestExplicitGC.class.getName(), 142 "test"); 143 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 144 for (String p : full) { 145 output.shouldNotContain(p); 146 } 147 for (String p : concNormal) { 148 output.shouldContain(p); 149 } 150 } 151 } 152 }