Path: blob/master/test/hotspot/jtreg/compiler/oracle/CheckCompileCommandOption.java
41152 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 CheckCompileCommandOption25* @summary Checks parsing of -XX:CompileCommand=option26* @bug 8055286 8056964 8059847 806903527* @library /test/lib28* @modules java.base/jdk.internal.misc29* java.management30* @requires vm.flagless31* @requires vm.debug == true32* @run driver compiler.oracle.CheckCompileCommandOption33*/3435package compiler.oracle;3637import jdk.test.lib.process.OutputAnalyzer;38import jdk.test.lib.process.ProcessTools;3940import java.io.File;4142public class CheckCompileCommandOption {4344// Currently, two types of trailing options can be used with45// -XX:CompileCommand=option46//47// (1) CompileCommand=option,Klass::method,option48// (2) CompileCommand=option,Klass::method,type,option,value49//50// Type (1) is used to enable a boolean option for a method.51//52// Type (2) is used to support options with a value. Values can53// have the the following types: intx, uintx, bool, ccstr,54// ccstrlist, and double.5556private static final String[][] FILE_ARGUMENTS = {57{58"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command1.txt"),59"-version"60},61{62"-XX:CompileCommandFile=" + new File(System.getProperty("test.src", "."), "command2.txt"),63"-version"64}65};6667private static final String[][] FILE_EXPECTED_OUTPUT = {68{69"com/oracle/Test.test1 bool TestOptionBool = true",70"com/oracle/Test.test2 bool TestOptionBool = true",71"com/oracle/Test.test3 bool TestOptionBool = true",72"com/oracle/Test.test4 bool TestOptionBool = true",73"com/oracle/Test.test4 bool TestOptionBool2 = true",74"com/oracle/Test.test5 bool TestOptionBool = true",75"com/oracle/Test.test5 bool TestOptionBool2 = true",76"com/oracle/Test.test6(I) bool TestOptionBool = true",77"com/oracle/Test.test7(I) bool TestOptionBool = true",78"com/oracle/Test.test8(I) bool TestOptionBool = true",79"com/oracle/Test.test9(I) bool TestOptionBool = true",80"com/oracle/Test.test9(I) bool TestOptionBool2 = true",81"com/oracle/Test.test10(I) bool TestOptionBool = true",82"com/oracle/Test.test10(I) bool TestOptionBool2 = true"83},84{85"Test.test const char* TestOptionList = '_foo _bar'",86"Test.test const char* TestOptionStr = '_foo'",87"Test.test bool TestOptionBool = false",88"Test.test intx TestOptionInt = -1",89"Test.test uintx TestOptionUint = 1",90"Test.test bool TestOptionBool2 = true",91"Test.test double TestOptionDouble = 1.123000"92}93};9495private static final String[][] TYPE_1_ARGUMENTS = {96{97"-XX:CompileCommand=option,com/oracle/Test.test,TestOptionBool",98"-XX:CompileCommand=option,com/oracle/Test,test,TestOptionBool2",99"-XX:CompileCommand=option,com/oracle/Test.test2,TestOptionBool2,TestOptionBool",100"-version"101}102};103104private static final String[][] TYPE_1_EXPECTED_OUTPUTS = {105{106"com/oracle/Test.test bool TestOptionBool = true",107"com/oracle/Test.test bool TestOptionBool2 = true",108"com/oracle/Test.test2 bool TestOptionBool = true",109"com/oracle/Test.test2 bool TestOptionBool2 = true",110}111};112113private static final String[][] TYPE_2_ARGUMENTS = {114{115"-XX:CompileCommand=option,Test::test,ccstrlist,TestOptionList,_foo,_bar",116"-XX:CompileCommand=option,Test::test,ccstr,TestOptionStr,_foo",117"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false",118"-XX:CompileCommand=option,Test::test,intx,TestOptionInt,-1",119"-XX:CompileCommand=option,Test::test,uintx,TestOptionUint,1",120"-XX:CompileCommand=option,Test::test,TestOptionBool2",121"-XX:CompileCommand=option,Test::test,double,TestOptionDouble,1.123",122"-XX:CompileCommand=option,Test.test2,double,TestOptionDouble,1.123",123"-version"124}125};126127private static final String[][] TYPE_2_EXPECTED_OUTPUTS = {128{129"Test.test const char* TestOptionList = '_foo _bar'",130"Test.test const char* TestOptionStr = '_foo'",131"Test.test bool TestOptionBool = false",132"Test.test intx TestOptionInt = -1",133"Test.test uintx TestOptionUint = 1",134"Test.test bool TestOptionBool2 = true",135"Test.test double TestOptionDouble = 1.123000",136"Test.test2 double TestOptionDouble = 1.123000"137}138};139140private static final String[][] TYPE_3_ARGUMENTS = {141{142"-XX:CompileCommand=option,Test::test,bool,TestOptionBool,false,intx,TestOptionInt,-1,uintx,TestOptionUint,1,TestOptionBool2,double,TestOptionDouble,1.123",143"-version"144}145};146147private static final String[][] TYPE_3_EXPECTED_OUTPUTS = {148{149"Test.test bool TestOptionBool = false",150"Test.test intx TestOptionInt = -1",151"Test.test uintx TestOptionUint = 1",152"Test.test bool TestOptionBool2 = true",153"Test.test double TestOptionDouble = 1.123000"154}155};156157private static final String[][] TYPE_4_ARGUMENTS = {158{159"-XX:CompileCommand=TestOptionList,Test::test,_foo,_bar",160"-XX:CompileCommand=TestOptionStr,Test::test,_foo",161"-XX:CompileCommand=TestOptionBool,Test::test,false",162"-XX:CompileCommand=TestOptionInt,Test::test,-1",163"-XX:CompileCommand=TestOptionUint,Test::test,1",164"-XX:CompileCommand=TestOptionBool2,Test::test",165"-XX:CompileCommand=TestOptionDouble,Test::test,1.123",166"-XX:CompileCommand=TestOptionDouble,Test.test2,1.123",167"-version"168}169};170171private static final String[][] TYPE_4_EXPECTED_OUTPUTS = {172{173"CompileCommand: TestOptionList Test.test const char* TestOptionList = '_foo _bar'",174"CompileCommand: TestOptionStr Test.test const char* TestOptionStr = '_foo'",175"CompileCommand: TestOptionBool Test.test bool TestOptionBool = false",176"CompileCommand: TestOptionInt Test.test intx TestOptionInt = -1",177"CompileCommand: TestOptionUint Test.test uintx TestOptionUint = 1",178"CompileCommand: TestOptionBool2 Test.test bool TestOptionBool2 = true",179"CompileCommand: TestOptionDouble Test.test double TestOptionDouble = 1.123000",180"CompileCommand: TestOptionDouble Test.test2 double TestOptionDouble = 1.123000"181}182};183184private static final String[][] TYPE_4_INVALID_ARGUMENTS = {185{186"-XX:CompileCommand=InvalidOption,Test::test,_foo,_bar",187"-XX:CompileCommand=TestOptionInt,Test::test,_foo",188"-XX:CompileCommand=TestOptionBool,Test::test,1",189"-XX:CompileCommand=TestOptionDouble,Test::test,-1",190"-XX:CompileCommand=TestOptionUint,Test::test",191"-XX:CompileCommand=TestOptionBool2,Test::test,falsee",192"-XX:CompileCommand=TestOptionDouble,Test::test,true",193"-XX:CompileCommand=TestOptionDouble,Test.test2,1.f",194"-version"195}196};197198private static final String[][] TYPE_4_INVALID_OUTPUTS = {199{200"Unrecognized option 'InvalidOption'",201"Value cannot be read for option 'TestOptionInt' of type 'intx'",202"Value cannot be read for option 'TestOptionBool' of type 'bool'",203"Value cannot be read for option 'TestOptionDouble' of type 'double'",204"Option 'TestOptionUint' is not followed by a value",205"Value cannot be read for option 'TestOptionBool2' of type 'bool'",206"Value cannot be read for option 'TestOptionDouble' of type 'double'",207"Value cannot be read for option 'TestOptionDouble' of type 'double'"208}209};210211private static final String[][] TYPE_2_INVALID_ARGUMENTS = {212{213// bool flag name missing214"-XX:CompileCommand=option,Test::test,bool",215"-version"216},217{218// bool flag value missing219"-XX:CompileCommand=option,Test::test,bool,MyBoolOption",220"-version"221},222{223// wrong value for bool flag224"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,100",225"-version"226},227{228// intx flag name missing229"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx",230"-version"231},232{233// intx flag value missing234"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption",235"-version"236},237{238// wrong value for intx flag239"-XX:CompileCommand=option,Test::test,bool,MyBoolOption,false,intx,MyIntOption,true",240"-version"241},242{243// wrong value for flag double flag244"-XX:CompileCommand=option,Test::test,double,MyDoubleOption,1",245"-version"246}247};248249private static void verifyValidOption(String[] arguments, String[] expected_outputs) throws Exception {250ProcessBuilder pb;251OutputAnalyzer out;252253pb = ProcessTools.createJavaProcessBuilder(arguments);254out = new OutputAnalyzer(pb.start());255256for (String expected_output : expected_outputs) {257out.shouldContain(expected_output);258}259260out.shouldNotContain("CompileCommand: An error occurred during parsing");261out.shouldHaveExitValue(0);262}263264private static void verifyInvalidOption(String[] arguments) throws Exception {265ProcessBuilder pb;266OutputAnalyzer out;267268pb = ProcessTools.createJavaProcessBuilder(arguments);269out = new OutputAnalyzer(pb.start());270271out.shouldContain("CompileCommand: An error occurred during parsing");272out.shouldHaveExitValue(0);273}274275private static void verifyInvalidOption(String[] arguments, String[] expected_outputs) throws Exception {276ProcessBuilder pb;277OutputAnalyzer out;278279pb = ProcessTools.createJavaProcessBuilder(arguments);280out = new OutputAnalyzer(pb.start());281282for (String expected_output : expected_outputs) {283out.shouldContain(expected_output);284}285286out.shouldContain("CompileCommand: An error occurred during parsing");287out.shouldHaveExitValue(0);288289}290291292public static void main(String[] args) throws Exception {293294if (TYPE_1_ARGUMENTS.length != TYPE_1_EXPECTED_OUTPUTS.length) {295throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (1) options does not match.");296}297298if (TYPE_2_ARGUMENTS.length != TYPE_2_EXPECTED_OUTPUTS.length) {299throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (2) options does not match.");300}301302if (TYPE_3_ARGUMENTS.length != TYPE_3_EXPECTED_OUTPUTS.length) {303throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (3) options does not match.");304}305306if (TYPE_4_ARGUMENTS.length != TYPE_4_EXPECTED_OUTPUTS.length) {307throw new RuntimeException("Test is set up incorrectly: length of arguments and expected outputs for type (4) options does not match.");308}309310// Check if type (1) options are parsed correctly311for (int i = 0; i < TYPE_1_ARGUMENTS.length; i++) {312verifyValidOption(TYPE_1_ARGUMENTS[i], TYPE_1_EXPECTED_OUTPUTS[i]);313}314315// Check if type (2) options are parsed correctly316for (int i = 0; i < TYPE_2_ARGUMENTS.length; i++) {317verifyValidOption(TYPE_2_ARGUMENTS[i], TYPE_2_EXPECTED_OUTPUTS[i]);318}319320// Check if type (3) options are parsed correctly321for (int i = 0; i < TYPE_3_ARGUMENTS.length; i++) {322verifyValidOption(TYPE_3_ARGUMENTS[i], TYPE_3_EXPECTED_OUTPUTS[i]);323}324325// Check if type (4) options are parsed correctly326for (int i = 0; i < TYPE_4_ARGUMENTS.length; i++) {327verifyValidOption(TYPE_4_ARGUMENTS[i], TYPE_4_EXPECTED_OUTPUTS[i]);328}329330// Check if error is reported for invalid type (2) options331// (flags with type information specified)332for (String[] arguments: TYPE_2_INVALID_ARGUMENTS) {333verifyInvalidOption(arguments);334}335336// Check if error is reported for invalid type (2) options337// (flags with type information specified)338for (int i = 0; i < TYPE_4_INVALID_ARGUMENTS.length; i++) {339verifyInvalidOption(TYPE_4_INVALID_ARGUMENTS[i], TYPE_4_INVALID_OUTPUTS[i]);340}341342// Check if commands in command file are parsed correctly343for (int i = 0; i < FILE_ARGUMENTS.length; i++) {344verifyValidOption(FILE_ARGUMENTS[i], FILE_EXPECTED_OUTPUT[i]);345}346}347}348349350