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 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 String[] concTraversal = new String[] { 63 "Pause Init Traversal", 64 "Pause Final Traversal", 65 }; 66 67 { 68 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 69 "-XX:+UnlockExperimentalVMOptions", 70 "-XX:+UseShenandoahGC", 71 "-Xlog:gc", 72 TestExplicitGC.class.getName(), 73 "test"); 74 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 75 for (String p : full) { 76 output.shouldNotContain(p); 77 } 78 for (String p : concNormal) { 79 output.shouldContain(p); 80 } 81 for (String p : concTraversal) { 82 output.shouldNotContain(p); 83 } 84 } 85 86 { 87 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 88 "-XX:+UnlockExperimentalVMOptions", 89 "-XX:+UseShenandoahGC", 90 "-Xlog:gc", 91 "-XX:+DisableExplicitGC", 92 TestExplicitGC.class.getName(), 93 "test"); 94 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 95 for (String p : full) { 96 output.shouldNotContain(p); 97 } 98 for (String p : concNormal) { 99 output.shouldNotContain(p); 100 } 101 for (String p : concTraversal) { 102 output.shouldNotContain(p); 103 } 104 } 105 106 { 107 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 108 "-XX:+UnlockExperimentalVMOptions", 109 "-XX:+UseShenandoahGC", 110 "-Xlog:gc", 111 "-XX:+ExplicitGCInvokesConcurrent", 112 TestExplicitGC.class.getName(), 113 "test"); 114 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 115 for (String p : full) { 116 output.shouldNotContain(p); 117 } 118 for (String p : concNormal) { 119 output.shouldContain(p); 120 } 121 for (String p : concTraversal) { 122 output.shouldNotContain(p); 123 } 124 } 125 126 { 127 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 128 "-XX:+UnlockExperimentalVMOptions", 129 "-XX:+UseShenandoahGC", 130 "-Xlog:gc", 131 "-XX:+ExplicitGCInvokesConcurrent", 132 "-XX:ShenandoahGCHeuristics=traversal", 133 TestExplicitGC.class.getName(), 134 "test"); 135 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 136 for (String p : full) { 137 output.shouldNotContain(p); 138 } 139 for (String p : concNormal) { 140 output.shouldNotContain(p); 141 } 142 for (String p : concTraversal) { 143 output.shouldContain(p); 144 } 145 } 146 147 { 148 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 149 "-XX:+UnlockExperimentalVMOptions", 150 "-XX:+UseShenandoahGC", 151 "-Xlog:gc", 152 "-XX:-ExplicitGCInvokesConcurrent", 153 TestExplicitGC.class.getName(), 154 "test"); 155 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 156 for (String p : full) { 157 output.shouldContain(p); 158 } 159 for (String p : concNormal) { 160 output.shouldNotContain(p); 161 } 162 for (String p : concTraversal) { 163 output.shouldNotContain(p); 164 } 165 } 166 } 167 }