1 /* 2 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. 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 import jdk.test.lib.ExitCode; 24 import jdk.test.lib.Platform; 25 import jdk.test.lib.cli.CommandLineOptionTest; 26 import common.CodeCacheOptions; 27 import sun.hotspot.code.BlobType; 28 29 /** 30 * @test 31 * @bug 8015774 32 * @summary Verify SegmentedCodeCache option's processing 33 * @library /testlibrary /test/lib 34 * @modules java.base/sun.misc 35 * java.compiler 36 * java.management 37 * jdk.jvmstat/sun.jvmstat.monitor 38 * @build TestSegmentedCodeCacheOption jdk.test.lib.* 39 * @run main TestSegmentedCodeCacheOption 40 */ 41 public class TestSegmentedCodeCacheOption { 42 private static final String INT_MODE = "-Xint"; 43 private static final String TIERED_COMPILATION = "TieredCompilation"; 44 private static final String SEGMENTED_CODE_CACHE = "SegmentedCodeCache"; 45 private static final String USE_SEGMENTED_CODE_CACHE 46 = CommandLineOptionTest.prepareBooleanFlag(SEGMENTED_CODE_CACHE, 47 true); 48 private static final long THRESHOLD_CC_SIZE_VALUE 49 = CodeCacheOptions.mB(240); 50 private static final long BELOW_THRESHOLD_CC_SIZE 51 = THRESHOLD_CC_SIZE_VALUE - CodeCacheOptions.mB(1); 52 private static final String[] UNEXPECTED_MESSAGES = new String[] { 53 ".*" + SEGMENTED_CODE_CACHE + ".*" 54 }; 55 56 57 private static enum TestCase { 58 JVM_STARTUP { 59 @Override 60 public void run() throws Throwable { 61 // There should be no errors when we're trying to enable SCC ... 62 String testCaseWarningMessage = "JVM output should not contain " 63 + "any warnings related to " + SEGMENTED_CODE_CACHE; 64 String testCaseExitCodeMessage = "JVM should start without any " 65 + "issues with " + USE_SEGMENTED_CODE_CACHE; 66 67 CommandLineOptionTest.verifySameJVMStartup( 68 /* expectedMessages */ null, UNEXPECTED_MESSAGES, 69 testCaseExitCodeMessage, testCaseWarningMessage, 70 ExitCode.OK, USE_SEGMENTED_CODE_CACHE); 71 // ... and when we're trying to enable it w/o TieredCompilation 72 testCaseExitCodeMessage = "Disabled tiered compilation should " 73 + "not cause startup failure w/ " 74 + USE_SEGMENTED_CODE_CACHE; 75 76 CommandLineOptionTest.verifySameJVMStartup( 77 /* expectedMessages */ null, UNEXPECTED_MESSAGES, 78 testCaseExitCodeMessage, testCaseWarningMessage, 79 ExitCode.OK, USE_SEGMENTED_CODE_CACHE, 80 CommandLineOptionTest.prepareBooleanFlag( 81 TIERED_COMPILATION, false)); 82 // ... and even w/ Xint. 83 testCaseExitCodeMessage = "It should be possible to use " 84 + USE_SEGMENTED_CODE_CACHE + " in interpreted mode " 85 + "without any errors."; 86 87 CommandLineOptionTest.verifyJVMStartup( 88 /* expected messages */ null, UNEXPECTED_MESSAGES, 89 testCaseExitCodeMessage, testCaseWarningMessage, 90 ExitCode.OK, false, INT_MODE, USE_SEGMENTED_CODE_CACHE); 91 } 92 }, 93 OPTION_VALUES_GENERIC { 94 @Override 95 public void run() throws Throwable { 96 // SCC is disabled w/o TieredCompilation by default 97 String errorMessage = SEGMENTED_CODE_CACHE 98 + " should be disabled by default when tiered " 99 + "compilation is disabled"; 100 101 CommandLineOptionTest.verifyOptionValueForSameVM( 102 SEGMENTED_CODE_CACHE, "false", errorMessage, 103 CommandLineOptionTest.prepareBooleanFlag( 104 TIERED_COMPILATION, false)); 105 // SCC is disabled by default when ReservedCodeCacheSize is too 106 // small 107 errorMessage = String.format("%s should be disabled bu default " 108 + "when %s value is too small.", SEGMENTED_CODE_CACHE, 109 BlobType.All.sizeOptionName); 110 111 CommandLineOptionTest.verifyOptionValueForSameVM( 112 SEGMENTED_CODE_CACHE, "false", errorMessage, 113 CommandLineOptionTest.prepareNumericFlag( 114 BlobType.All.sizeOptionName, 115 BELOW_THRESHOLD_CC_SIZE)); 116 // SCC could be explicitly enabled w/ Xint 117 errorMessage = String.format("It should be possible to " 118 + "explicitly enable %s in interpreted mode.", 119 SEGMENTED_CODE_CACHE); 120 121 CommandLineOptionTest.verifyOptionValue(SEGMENTED_CODE_CACHE, 122 "true", errorMessage, false, INT_MODE, 123 USE_SEGMENTED_CODE_CACHE); 124 // SCC could be explicitly enabled w/o TieredCompilation and w/ 125 // small ReservedCodeCacheSize value 126 errorMessage = String.format("It should be possible to " 127 + "explicitly enable %s with small %s and " 128 + "disabled tiered comp.", SEGMENTED_CODE_CACHE, 129 BlobType.All.sizeOptionName); 130 131 CommandLineOptionTest.verifyOptionValueForSameVM( 132 SEGMENTED_CODE_CACHE, "true", errorMessage, 133 CommandLineOptionTest.prepareBooleanFlag( 134 TIERED_COMPILATION, false), 135 CommandLineOptionTest.prepareNumericFlag( 136 BlobType.All.sizeOptionName, 137 BELOW_THRESHOLD_CC_SIZE), 138 USE_SEGMENTED_CODE_CACHE); 139 } 140 }, 141 OPTION_VALUES_SERVER_SPECIFIC { 142 @Override 143 public boolean isApplicable() { 144 return Platform.isServer() && Platform.isTieredSupported(); 145 } 146 147 @Override 148 public void run() throws Throwable { 149 // SCC is enabled by default when TieredCompilation is on and 150 // ReservedCodeCacheSize is large enough 151 String errorMessage = String.format("Large enough %s and " 152 + "enabled tiered compilation should enable %s " 153 + "by default.", BlobType.All.sizeOptionName, 154 SEGMENTED_CODE_CACHE); 155 156 CommandLineOptionTest.verifyOptionValueForSameVM( 157 SEGMENTED_CODE_CACHE, "true", errorMessage, 158 CommandLineOptionTest.prepareNumericFlag( 159 BlobType.All.sizeOptionName, 160 THRESHOLD_CC_SIZE_VALUE), 161 CommandLineOptionTest.prepareBooleanFlag( 162 TIERED_COMPILATION, true)); 163 } 164 }; 165 166 TestCase() { 167 } 168 169 public boolean isApplicable() { 170 return true; 171 } 172 173 public abstract void run() throws Throwable; 174 } 175 176 public static void main(String args[]) throws Throwable { 177 for (TestCase testCase : TestCase.values()) { 178 if (testCase.isApplicable()) { 179 System.out.println("Running test case: " + testCase.name()); 180 testCase.run(); 181 } else { 182 System.out.println("Test case skipped: " + testCase.name()); 183 } 184 } 185 } 186 }