1 /* 2 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 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 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 24 /* 25 * @test TestExplicitGC 26 * @summary Test that Shenandoah reacts to explicit GC flags appropriately 27 * @key gc 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 "-XX:+UnlockExperimentalVMOptions", 65 "-XX:+UseShenandoahGC", 66 "-Xlog:gc", 67 TestExplicitGC.class.getName(), 68 "test"); 69 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 70 for (String p : full) { 71 output.shouldNotContain(p); 72 } 73 for (String p : concNormal) { 74 output.shouldContain(p); 75 } 76 } 77 78 { 79 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 80 "-XX:+UnlockExperimentalVMOptions", 81 "-XX:+UseShenandoahGC", 82 "-Xlog:gc", 83 "-XX:+DisableExplicitGC", 84 TestExplicitGC.class.getName(), 85 "test"); 86 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 87 for (String p : full) { 88 output.shouldNotContain(p); 89 } 90 for (String p : concNormal) { 91 output.shouldNotContain(p); 92 } 93 } 94 95 { 96 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 97 "-XX:+UnlockExperimentalVMOptions", 98 "-XX:+UseShenandoahGC", 99 "-Xlog:gc", 100 "-XX:+ExplicitGCInvokesConcurrent", 101 TestExplicitGC.class.getName(), 102 "test"); 103 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 104 for (String p : full) { 105 output.shouldNotContain(p); 106 } 107 for (String p : concNormal) { 108 output.shouldContain(p); 109 } 110 } 111 112 { 113 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 114 "-XX:+UnlockExperimentalVMOptions", 115 "-XX:+UseShenandoahGC", 116 "-Xlog:gc", 117 "-XX:-ExplicitGCInvokesConcurrent", 118 TestExplicitGC.class.getName(), 119 "test"); 120 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 121 for (String p : full) { 122 output.shouldContain(p); 123 } 124 for (String p : concNormal) { 125 output.shouldNotContain(p); 126 } 127 } 128 129 { 130 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 131 "-XX:+UnlockExperimentalVMOptions", 132 "-XX:+UseShenandoahGC", 133 "-Xlog:gc", 134 "-XX:+ExplicitGCInvokesConcurrent", 135 "-XX:ShenandoahGCMode=iu", 136 TestExplicitGC.class.getName(), 137 "test"); 138 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 139 for (String p : full) { 140 output.shouldNotContain(p); 141 } 142 for (String p : concNormal) { 143 output.shouldContain(p); 144 } 145 } 146 } 147 }