Path: blob/master/test/hotspot/jtreg/compiler/jvmci/compilerToVM/GetFlagValueTest.java
41153 views
/*1* Copyright (c) 2015, 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* @test25* @bug 817391226* @requires vm.jvmci27* @library / /test/lib28* @library ../common/patches29* @modules jdk.internal.vm.ci/jdk.vm.ci.hotspot:+open30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32* @build jdk.internal.vm.ci/jdk.vm.ci.hotspot.CompilerToVMHelper33* @run main/othervm -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI34* -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xbootclasspath/a:.35* compiler.jvmci.compilerToVM.GetFlagValueTest36*/3738package compiler.jvmci.compilerToVM;3940import jdk.test.lib.Asserts;41import jdk.vm.ci.hotspot.CompilerToVMHelper;42import jdk.test.lib.process.OutputAnalyzer;43import jdk.test.lib.process.ProcessTools;44import java.math.BigInteger;45import java.util.Arrays;46import java.util.regex.Pattern;47import java.util.regex.Matcher;48import sun.hotspot.WhiteBox;4950public class GetFlagValueTest {51public static void main(String[] args) throws Exception {52try {53CompilerToVMHelper.getFlagValue(null);54Asserts.fail("Expected NullPointerException when calling getFlagValue(null)");55} catch (NullPointerException e) {56// expected57}5859Object missing = CompilerToVMHelper.getFlagValue("this is surely not a flag");60Asserts.assertEquals(CompilerToVMHelper.CTVM, missing);6162ProcessBuilder pb;63OutputAnalyzer out;6465pb = ProcessTools.createJavaProcessBuilder(66"-XX:+UnlockExperimentalVMOptions",67"-XX:+EnableJVMCI",68"-XX:+PrintFlagsFinal",69"-version");70out = new OutputAnalyzer(pb.start());7172out.shouldHaveExitValue(0);73String[] lines = out.getStdout().split("\\r?\\n");74Asserts.assertTrue(lines.length > 1, "Expected output from -XX:+PrintFlagsFinal");7576final WhiteBox wb = WhiteBox.getWhiteBox();7778// Line example: ccstr PrintIdealGraphAddress = 127.0.0.1 {C2 notproduct} {default}79Pattern flagLine = Pattern.compile("(\\w+)\\s+(\\w+)\\s+:?= (?:(.+))\\{[^}]+\\}\\s+\\{[^}]+\\}");80for (String line : lines) {81if (line.indexOf('=') != -1) {82line = line.trim();83Matcher m = flagLine.matcher(line);84Asserts.assertTrue(m.matches(), "Unexpected line in -XX:+PrintFlagsFinal output: " + line);85String type = m.group(1);86String name = m.group(2);87String expect = m.group(3).trim();88Object value = CompilerToVMHelper.getFlagValue(name);89Object wbValue = wb.getVMFlag(name);90Asserts.assertEquals(value, wbValue, "Value of flag " + name);91}92}93}94}959697