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 * @library /testlibrary 29 * 30 * @run driver TestExplicitGC 31 */ 32 33 import com.oracle.java.testlibrary.*; 34 35 public class TestExplicitGC { 36 37 enum Mode { 38 PRODUCT, 39 DIAGNOSTIC, 40 EXPERIMENTAL, 41 } 42 43 public static void main(String[] args) throws Exception { 44 if (args.length > 0) { 45 System.out.println("Calling System.gc()"); 46 System.gc(); 47 return; 48 } 49 50 String[] full = new String[] { 51 "Pause Full" 52 }; 53 54 String[] concNormal = new String[] { 55 "Pause Init Mark", 56 "Pause Final Mark", 57 }; 58 59 String[] concTraversal = new String[] { 60 "Pause Init Traversal", 61 "Pause Final Traversal", 62 }; 63 64 { 65 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 66 "-XX:+UnlockExperimentalVMOptions", 67 "-XX:+UseShenandoahGC", 68 "-verbose:gc", 69 TestExplicitGC.class.getName(), 70 "test"); 71 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 72 for (String p : full) { 73 output.shouldNotContain(p); 74 } 75 for (String p : concNormal) { 76 output.shouldContain(p); 77 } 78 for (String p : concTraversal) { 79 output.shouldNotContain(p); 80 } 81 } 82 83 { 84 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 85 "-XX:+UnlockExperimentalVMOptions", 86 "-XX:+UseShenandoahGC", 87 "-verbose:gc", 88 "-XX:+DisableExplicitGC", 89 TestExplicitGC.class.getName(), 90 "test"); 91 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 92 for (String p : full) { 93 output.shouldNotContain(p); 94 } 95 for (String p : concNormal) { 96 output.shouldNotContain(p); 97 } 98 for (String p : concTraversal) { 99 output.shouldNotContain(p); 100 } 101 } 102 103 { 104 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 105 "-XX:+UnlockExperimentalVMOptions", 106 "-XX:+UseShenandoahGC", 107 "-verbose:gc", 108 "-XX:+ExplicitGCInvokesConcurrent", 109 TestExplicitGC.class.getName(), 110 "test"); 111 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 112 for (String p : full) { 113 output.shouldNotContain(p); 114 } 115 for (String p : concNormal) { 116 output.shouldContain(p); 117 } 118 for (String p : concTraversal) { 119 output.shouldNotContain(p); 120 } 121 } 122 123 { 124 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 125 "-XX:+UnlockExperimentalVMOptions", 126 "-XX:+UseShenandoahGC", 127 "-verbose:gc", 128 "-XX:+ExplicitGCInvokesConcurrent", 129 "-XX:ShenandoahGCMode=traversal", 130 TestExplicitGC.class.getName(), 131 "test"); 132 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 133 for (String p : full) { 134 output.shouldNotContain(p); 135 } 136 for (String p : concNormal) { 137 output.shouldNotContain(p); 138 } 139 for (String p : concTraversal) { 140 output.shouldContain(p); 141 } 142 } 143 144 { 145 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 146 "-XX:+UnlockExperimentalVMOptions", 147 "-XX:+UseShenandoahGC", 148 "-verbose:gc", 149 "-XX:-ExplicitGCInvokesConcurrent", 150 TestExplicitGC.class.getName(), 151 "test"); 152 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 153 for (String p : full) { 154 output.shouldContain(p); 155 } 156 for (String p : concNormal) { 157 output.shouldNotContain(p); 158 } 159 for (String p : concTraversal) { 160 output.shouldNotContain(p); 161 } 162 } 163 } 164 }