Path: blob/master/test/hotspot/jtreg/compiler/codecache/cli/common/CodeCacheCLITestCase.java
41154 views
/*1* Copyright (c) 2014, 2015, 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*/22package compiler.codecache.cli.common;2324import jdk.test.lib.Platform;25import jdk.test.lib.cli.CommandLineOptionTest;26import sun.hotspot.code.BlobType;2728import java.util.Collections;29import java.util.EnumSet;30import java.util.LinkedList;31import java.util.List;32import java.util.function.Function;3334/**35* Code cache related command line option test case consisting of description36* of code heaps used during test case run and additional options that should37* be passed to JVM and runner aimed to perform actual testing based on the38* description.39*/40public class CodeCacheCLITestCase {41private static final Function<CodeCacheOptions, Boolean> ONLY_SEGMENTED42= options -> options.segmented;43private static final Function<CodeCacheOptions, Boolean> SEGMENTED_SERVER44= ONLY_SEGMENTED.andThen(isSegmented -> isSegmented45&& Platform.isServer() && Platform.isTieredSupported());46private static final String USE_INT_MODE = "-Xint";47private static final String SEGMENTED_CODE_CACHE = "SegmentedCodeCache";48private static final String TIERED_COMPILATION = "TieredCompilation";49private static final String TIERED_STOP_AT = "TieredStopAtLevel";5051private final Description description;52private final Runner runner;5354public CodeCacheCLITestCase(Description description, Runner runner) {55this.description = description;56this.runner = runner;57}5859public final void run(CodeCacheOptions options) throws Throwable {60if (description.isApplicable(options)) {61runner.run(description, options);62}63}6465public enum CommonDescriptions {66/**67* Verifies that in interpreted mode PrintCodeCache output contains68* only NonNMethod code heap.69*/70INT_MODE(ONLY_SEGMENTED, EnumSet.of(BlobType.NonNMethod), USE_INT_MODE),71/**72* Verifies that with disabled SegmentedCodeCache PrintCodeCache output73* contains only CodeCache's entry.74*/75NON_SEGMENTED(options -> !options.segmented, EnumSet.of(BlobType.All),76CommandLineOptionTest.prepareBooleanFlag(SEGMENTED_CODE_CACHE,77false)),78/**79* Verifies that with disabled tiered compilation and enabled segmented80* code cache PrintCodeCache output does not contain information about81* profiled-nmethods heap and non-segmented CodeCache.82*/83NON_TIERED(ONLY_SEGMENTED,84EnumSet.of(BlobType.NonNMethod, BlobType.MethodNonProfiled),85CommandLineOptionTest.prepareBooleanFlag(TIERED_COMPILATION,86false)),87/**88* Verifies that with TieredStopAtLevel=0 PrintCodeCache output will89* contain information about non-nmethods and non-profiled nmethods90* heaps only.91*/92TIERED_LEVEL_0(SEGMENTED_SERVER,93EnumSet.of(BlobType.NonNMethod, BlobType.MethodNonProfiled),94CommandLineOptionTest.prepareBooleanFlag(TIERED_COMPILATION,95true),96CommandLineOptionTest.prepareNumericFlag(TIERED_STOP_AT, 0)),97/**98* Verifies that with TieredStopAtLevel=1 PrintCodeCache output will99* contain information about non-nmethods and non-profiled nmethods100* heaps only.101*/102TIERED_LEVEL_1(SEGMENTED_SERVER,103EnumSet.of(BlobType.NonNMethod, BlobType.MethodNonProfiled),104CommandLineOptionTest.prepareBooleanFlag(TIERED_COMPILATION,105true),106CommandLineOptionTest.prepareNumericFlag(TIERED_STOP_AT, 1)),107/**108* Verifies that with TieredStopAtLevel=4 PrintCodeCache output will109* contain information about all three code heaps.110*/111TIERED_LEVEL_4(SEGMENTED_SERVER,112EnumSet.complementOf(EnumSet.of(BlobType.All)),113CommandLineOptionTest.prepareBooleanFlag(TIERED_COMPILATION,114true),115CommandLineOptionTest.prepareNumericFlag(TIERED_STOP_AT, 4));116117CommonDescriptions(Function<CodeCacheOptions, Boolean> predicate,118EnumSet<BlobType> involvedCodeHeaps,119String... additionalOptions) {120this.description = new Description(predicate,121involvedCodeHeaps, additionalOptions);122}123124125public final Description description;126}127128public static class Description {129public final EnumSet<BlobType> involvedCodeHeaps;130private final String[] testCaseSpecificOptions;131private final Function<CodeCacheOptions, Boolean> predicate;132133public Description(Function<CodeCacheOptions, Boolean> predicate,134EnumSet<BlobType> involvedCodeHeaps,135String... testCaseSpecificOptions) {136this.involvedCodeHeaps = involvedCodeHeaps;137this.testCaseSpecificOptions = testCaseSpecificOptions;138this.predicate = predicate;139}140141public boolean isApplicable(CodeCacheOptions options) {142return predicate.apply(options);143}144145public CodeCacheOptions expectedValues(CodeCacheOptions options) {146return options.mapOptions(involvedCodeHeaps);147}148149public String[] getTestOptions(CodeCacheOptions codeCacheOptions,150String... additionalOptions) {151List<String> options = new LinkedList<>();152Collections.addAll(options, testCaseSpecificOptions);153Collections.addAll(options, additionalOptions);154return codeCacheOptions.prepareOptions(155options.toArray(new String[options.size()]));156}157}158159public static interface Runner {160public void run(Description testCaseDescription,161CodeCacheOptions options) throws Throwable;162}163}164165166167