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