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 TestHeuristicsUnlock 26 * @summary Test that Shenandoah heuristics are unlocked properly 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 TestHeuristicsUnlock 33 */ 34 35 import jdk.test.lib.process.ProcessTools; 36 import jdk.test.lib.process.OutputAnalyzer; 37 38 public class TestHeuristicsUnlock { 39 40 enum Mode { 41 PRODUCT, 42 DIAGNOSTIC, 43 EXPERIMENTAL, 44 } 45 main(String[] args)46 public static void main(String[] args) throws Exception { 47 testWith("adaptive", Mode.PRODUCT); 48 testWith("static", Mode.PRODUCT); 49 testWith("compact", Mode.PRODUCT); 50 51 testWith("traversal", Mode.EXPERIMENTAL); 52 53 testWith("aggressive", Mode.DIAGNOSTIC); 54 testWith("passive", Mode.DIAGNOSTIC); 55 } 56 testWith(String h, Mode mode)57 private static void testWith(String h, Mode mode) throws Exception { 58 if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test 59 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 60 "-XX:-UnlockDiagnosticVMOptions", 61 "-XX:-UnlockExperimentalVMOptions", 62 "-XX:+UseShenandoahGC", 63 "-XX:ShenandoahGCHeuristics=" + h, 64 "-version" 65 ); 66 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 67 switch (mode) { 68 case PRODUCT: 69 output.shouldHaveExitValue(0); 70 break; 71 case DIAGNOSTIC: 72 case EXPERIMENTAL: 73 output.shouldNotHaveExitValue(0); 74 break; 75 } 76 } 77 78 if (false) { // When ShenandoahGC is experimental flag, this makes no sense to test 79 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 80 "-XX:+UnlockDiagnosticVMOptions", 81 "-XX:-UnlockExperimentalVMOptions", 82 "-XX:+UseShenandoahGC", 83 "-XX:ShenandoahGCHeuristics=" + h, 84 "-version" 85 ); 86 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 87 switch (mode) { 88 case PRODUCT: 89 case DIAGNOSTIC: 90 output.shouldHaveExitValue(0); 91 break; 92 case EXPERIMENTAL: 93 output.shouldNotHaveExitValue(0); 94 break; 95 } 96 } 97 98 { 99 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 100 "-XX:-UnlockDiagnosticVMOptions", 101 "-XX:+UnlockExperimentalVMOptions", 102 "-XX:+UseShenandoahGC", 103 "-XX:ShenandoahGCHeuristics=" + h, 104 "-version" 105 ); 106 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 107 switch (mode) { 108 case PRODUCT: 109 case EXPERIMENTAL: 110 output.shouldHaveExitValue(0); 111 break; 112 case DIAGNOSTIC: 113 output.shouldNotHaveExitValue(0); 114 break; 115 } 116 } 117 } 118 119 } 120