Path: blob/master/test/hotspot/jtreg/compiler/codecache/CheckSegmentedCodeCache.java
41149 views
/*1* Copyright (c) 2014, 2021, 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* @test CheckSegmentedCodeCache25* @bug 801577426* @summary Checks VM options related to the segmented code cache27* @library /test/lib28* @requires vm.flagless29*30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions33* -XX:+WhiteBoxAPI34* compiler.codecache.CheckSegmentedCodeCache35*/3637package compiler.codecache;3839import jdk.test.lib.process.OutputAnalyzer;40import jdk.test.lib.Platform;41import jdk.test.lib.process.ProcessTools;42import sun.hotspot.WhiteBox;4344public class CheckSegmentedCodeCache {45private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();46// Code heap names47private static final String NON_METHOD = "CodeHeap 'non-nmethods'";48private static final String PROFILED = "CodeHeap 'profiled nmethods'";49private static final String NON_PROFILED = "CodeHeap 'non-profiled nmethods'";5051private static void verifySegmentedCodeCache(ProcessBuilder pb, boolean enabled) throws Exception {52OutputAnalyzer out = new OutputAnalyzer(pb.start());53out.shouldHaveExitValue(0);54if (enabled) {55try {56// Non-nmethod code heap should be always available with the segmented code cache57out.shouldContain(NON_METHOD);58} catch (RuntimeException e) {59// Check if TieredCompilation is disabled (in a client VM)60if (!out.getOutput().contains("-XX:+TieredCompilation not supported in this VM")) {61// Code cache is not segmented62throw new RuntimeException("No code cache segmentation.");63}64}65} else {66out.shouldNotContain(NON_METHOD);67}68}6970private static void verifyCodeHeapNotExists(ProcessBuilder pb, String... heapNames) throws Exception {71OutputAnalyzer out = new OutputAnalyzer(pb.start());72out.shouldHaveExitValue(0);73for (String name : heapNames) {74out.shouldNotContain(name);75}76}7778private static void failsWith(ProcessBuilder pb, String message) throws Exception {79OutputAnalyzer out = new OutputAnalyzer(pb.start());80out.shouldContain(message);81out.shouldHaveExitValue(1);82}8384/**85* Check the result of segmented code cache related VM options.86*/87public static void main(String[] args) throws Exception {88ProcessBuilder pb;8990// Disabled with ReservedCodeCacheSize < 240MB91pb = ProcessTools.createJavaProcessBuilder("-XX:ReservedCodeCacheSize=239m",92"-XX:+PrintCodeCache",93"-version");94verifySegmentedCodeCache(pb, false);9596// Disabled without TieredCompilation97pb = ProcessTools.createJavaProcessBuilder("-XX:-TieredCompilation",98"-XX:+PrintCodeCache",99"-version");100verifySegmentedCodeCache(pb, false);101102// Enabled with TieredCompilation and ReservedCodeCacheSize >= 240MB103pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",104"-XX:ReservedCodeCacheSize=240m",105"-XX:+PrintCodeCache",106"-version");107verifySegmentedCodeCache(pb, true);108pb = ProcessTools.createJavaProcessBuilder("-XX:+TieredCompilation",109"-XX:ReservedCodeCacheSize=400m",110"-XX:+PrintCodeCache",111"-version");112verifySegmentedCodeCache(pb, true);113114// Always enabled if SegmentedCodeCache is set115pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",116"-XX:-TieredCompilation",117"-XX:ReservedCodeCacheSize=239m",118"-XX:+PrintCodeCache",119"-version");120verifySegmentedCodeCache(pb, true);121122// The profiled and non-profiled code heaps should not be available in123// interpreter-only mode124pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",125"-Xint",126"-XX:+PrintCodeCache",127"-version");128verifyCodeHeapNotExists(pb, PROFILED, NON_PROFILED);129130// If we stop compilation at CompLevel_none or CompLevel_simple we131// don't need a profiled code heap.132pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",133"-XX:TieredStopAtLevel=0",134"-XX:+PrintCodeCache",135"-version");136verifyCodeHeapNotExists(pb, PROFILED);137pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",138"-XX:TieredStopAtLevel=1",139"-XX:+PrintCodeCache",140"-version");141verifyCodeHeapNotExists(pb, PROFILED);142143// Fails with too small non-nmethod code heap size144pb = ProcessTools.createJavaProcessBuilder("-XX:NonNMethodCodeHeapSize=100K",145"-version");146failsWith(pb, "Invalid NonNMethodCodeHeapSize");147148// Fails if code heap sizes do not add up149pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",150"-XX:ReservedCodeCacheSize=10M",151"-XX:NonNMethodCodeHeapSize=5M",152"-XX:ProfiledCodeHeapSize=5M",153"-XX:NonProfiledCodeHeapSize=5M",154"-version");155failsWith(pb, "Invalid code heap sizes");156157// Fails if not enough space for VM internal code158long minUseSpace = WHITE_BOX.getUintxVMFlag("CodeCacheMinimumUseSpace");159// minimum size: CodeCacheMinimumUseSpace DEBUG_ONLY(* 3)160long minSize = (Platform.isDebugBuild() ? 3 : 1) * minUseSpace;161pb = ProcessTools.createJavaProcessBuilder("-XX:+SegmentedCodeCache",162"-XX:ReservedCodeCacheSize=" + minSize,163"-XX:InitialCodeCacheSize=100K",164"-version");165failsWith(pb, "Not enough space in non-nmethod code heap to run VM");166}167}168169170