Path: blob/master/test/hotspot/jtreg/compiler/codecache/cli/TestSegmentedCodeCacheOption.java
41152 views
/*1* Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 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 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 801577426* @summary Verify SegmentedCodeCache option's processing27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* java.compiler30* java.management31* jdk.internal.jvmstat/sun.jvmstat.monitor32*33* @run driver compiler.codecache.cli.TestSegmentedCodeCacheOption34*/3536package compiler.codecache.cli;3738import compiler.codecache.cli.common.CodeCacheOptions;39import jdk.test.lib.process.ExitCode;40import jdk.test.lib.Platform;41import jdk.test.lib.cli.CommandLineOptionTest;42import sun.hotspot.code.BlobType;4344public class TestSegmentedCodeCacheOption {45private static final String INT_MODE = "-Xint";46private static final String TIERED_COMPILATION = "TieredCompilation";47private static final String SEGMENTED_CODE_CACHE = "SegmentedCodeCache";48private static final String USE_SEGMENTED_CODE_CACHE49= CommandLineOptionTest.prepareBooleanFlag(SEGMENTED_CODE_CACHE,50true);51private static final long THRESHOLD_CC_SIZE_VALUE52= CodeCacheOptions.mB(240);53private static final long BELOW_THRESHOLD_CC_SIZE54= THRESHOLD_CC_SIZE_VALUE - CodeCacheOptions.mB(1);55private static final String[] UNEXPECTED_MESSAGES = new String[] {56".*" + SEGMENTED_CODE_CACHE + ".*"57};585960private static enum TestCase {61JVM_STARTUP {62@Override63public void run() throws Throwable {64// There should be no errors when we're trying to enable SCC ...65String testCaseWarningMessage = "JVM output should not contain "66+ "any warnings related to " + SEGMENTED_CODE_CACHE;67String testCaseExitCodeMessage = "JVM should start without any "68+ "issues with " + USE_SEGMENTED_CODE_CACHE;6970CommandLineOptionTest.verifySameJVMStartup(71/* expectedMessages */ null, UNEXPECTED_MESSAGES,72testCaseExitCodeMessage, testCaseWarningMessage,73ExitCode.OK, USE_SEGMENTED_CODE_CACHE);74// ... and when we're trying to enable it w/o TieredCompilation75testCaseExitCodeMessage = "Disabled tiered compilation should "76+ "not cause startup failure w/ "77+ USE_SEGMENTED_CODE_CACHE;7879CommandLineOptionTest.verifySameJVMStartup(80/* expectedMessages */ null, UNEXPECTED_MESSAGES,81testCaseExitCodeMessage, testCaseWarningMessage,82ExitCode.OK, USE_SEGMENTED_CODE_CACHE,83CommandLineOptionTest.prepareBooleanFlag(84TIERED_COMPILATION, false));85// ... and even w/ Xint.86testCaseExitCodeMessage = "It should be possible to use "87+ USE_SEGMENTED_CODE_CACHE + " in interpreted mode "88+ "without any errors.";8990CommandLineOptionTest.verifyJVMStartup(91/* expected messages */ null, UNEXPECTED_MESSAGES,92testCaseExitCodeMessage, testCaseWarningMessage,93ExitCode.OK, false, INT_MODE, USE_SEGMENTED_CODE_CACHE);94}95},96OPTION_VALUES_GENERIC {97@Override98public void run() throws Throwable {99// SCC is disabled w/o TieredCompilation by default100String errorMessage = SEGMENTED_CODE_CACHE101+ " should be disabled by default when tiered "102+ "compilation is disabled";103104CommandLineOptionTest.verifyOptionValueForSameVM(105SEGMENTED_CODE_CACHE, "false", errorMessage,106CommandLineOptionTest.prepareBooleanFlag(107TIERED_COMPILATION, false));108// SCC is disabled by default when ReservedCodeCacheSize is too109// small110errorMessage = String.format("%s should be disabled bu default "111+ "when %s value is too small.", SEGMENTED_CODE_CACHE,112BlobType.All.sizeOptionName);113114CommandLineOptionTest.verifyOptionValueForSameVM(115SEGMENTED_CODE_CACHE, "false", errorMessage,116CommandLineOptionTest.prepareNumericFlag(117BlobType.All.sizeOptionName,118BELOW_THRESHOLD_CC_SIZE));119// SCC could be explicitly enabled w/ Xint120errorMessage = String.format("It should be possible to "121+ "explicitly enable %s in interpreted mode.",122SEGMENTED_CODE_CACHE);123124CommandLineOptionTest.verifyOptionValue(SEGMENTED_CODE_CACHE,125"true", errorMessage, false, INT_MODE,126USE_SEGMENTED_CODE_CACHE);127// SCC could be explicitly enabled w/o TieredCompilation and w/128// small ReservedCodeCacheSize value129errorMessage = String.format("It should be possible to "130+ "explicitly enable %s with small %s and "131+ "disabled tiered comp.", SEGMENTED_CODE_CACHE,132BlobType.All.sizeOptionName);133134CommandLineOptionTest.verifyOptionValueForSameVM(135SEGMENTED_CODE_CACHE, "true", errorMessage,136CommandLineOptionTest.prepareBooleanFlag(137TIERED_COMPILATION, false),138CommandLineOptionTest.prepareNumericFlag(139BlobType.All.sizeOptionName,140BELOW_THRESHOLD_CC_SIZE),141USE_SEGMENTED_CODE_CACHE);142}143},144OPTION_VALUES_SERVER_SPECIFIC {145@Override146public boolean isApplicable() {147return Platform.isServer() && Platform.isTieredSupported();148}149150@Override151public void run() throws Throwable {152// SCC is enabled by default when TieredCompilation is on and153// ReservedCodeCacheSize is large enough154String errorMessage = String.format("Large enough %s and "155+ "enabled tiered compilation should enable %s "156+ "by default.", BlobType.All.sizeOptionName,157SEGMENTED_CODE_CACHE);158159CommandLineOptionTest.verifyOptionValueForSameVM(160SEGMENTED_CODE_CACHE, "true", errorMessage,161CommandLineOptionTest.prepareNumericFlag(162BlobType.All.sizeOptionName,163THRESHOLD_CC_SIZE_VALUE),164CommandLineOptionTest.prepareBooleanFlag(165TIERED_COMPILATION, true));166}167};168169TestCase() {170}171172public boolean isApplicable() {173return true;174}175176public abstract void run() throws Throwable;177}178179public static void main(String args[]) throws Throwable {180for (TestCase testCase : TestCase.values()) {181if (testCase.isApplicable()) {182System.out.println("Running test case: " + testCase.name());183testCase.run();184} else {185System.out.println("Test case skipped: " + testCase.name());186}187}188}189}190191192