Path: blob/master/test/hotspot/jtreg/compiler/oracle/GetMethodOptionTest.java
41152 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 807498026* @library /test/lib27* @modules java.base/jdk.internal.misc28* @build sun.hotspot.WhiteBox29* @requires vm.debug == true30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI32* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,ccstrlist,TestOptionList,_foo,_bar33* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,ccstr,TestOptionStr,_foo34* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,bool,TestOptionBool,false35* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,intx,TestOptionInt,-136* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,uintx,TestOptionUint,137* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,TestOptionBool238* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,double,TestOptionDouble,1.12339* compiler.oracle.GetMethodOptionTest40*41* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI42* -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,bool,TestOptionBool,false,intx,TestOptionInt,-1,uintx,TestOptionUint,1,bool,TestOptionBool2,true,ccstr,TestOptionStr,_foo,double,TestOptionDouble,1.123,ccstrlist,TestOptionList,_foo,_bar43* compiler.oracle.GetMethodOptionTest44*45* @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI46* -XX:CompileCommand=TestOptionList,compiler.oracle.GetMethodOptionTest::test,_foo,_bar47* -XX:CompileCommand=TestOptionStr,compiler.oracle.GetMethodOptionTest::test,_foo48* -XX:CompileCommand=TestOptionBool,compiler.oracle.GetMethodOptionTest::test,false49-XX:CompileCommand=TestOptionBool2,compiler.oracle.GetMethodOptionTest::test50* -XX:CompileCommand=TestOptionInt,compiler.oracle.GetMethodOptionTest::test,-151* -XX:CompileCommand=TestOptionUint,compiler.oracle.GetMethodOptionTest::test,152* -XX:CompileCommand=TestOptionDouble,compiler.oracle.GetMethodOptionTest::test,1.12353* compiler.oracle.GetMethodOptionTest54*/5556package compiler.oracle;5758import jdk.test.lib.Asserts;59import sun.hotspot.WhiteBox;6061import java.lang.reflect.Executable;62import java.util.function.BiFunction;6364public class GetMethodOptionTest {65private static final WhiteBox WB = WhiteBox.getWhiteBox();66public static void main(String[] args) {67Executable test = getMethod("test");68Executable test2 = getMethod("test2");69BiFunction<Executable, String, Object> getter = WB::getMethodOption;70for (TestCase testCase : TestCase.values()) {71Object expected = testCase.value;72String name = testCase.name();73Asserts.assertEQ(expected, getter.apply(test, name),74testCase + ": universal getter returns wrong value");75Asserts.assertEQ(expected, testCase.getter.apply(test, name),76testCase + ": specific getter returns wrong value");77Asserts.assertEQ(null, getter.apply(test2, name),78testCase + ": universal getter returns value for unused method");79Asserts.assertEQ(null, testCase.getter.apply(test2, name),80testCase + ": type specific getter returns value for unused method");81}82}83private static void test() { }84private static void test2() { }8586private static enum TestCase {87TestOptionBool(false, WB::getMethodBooleanOption),88TestOptionStr("_foo", WB::getMethodStringOption),89TestOptionInt(-1L, WB::getMethodIntxOption),90TestOptionUint(1L, WB::getMethodUintxOption),91TestOptionBool2(true, WB::getMethodBooleanOption),92TestOptionDouble(1.123d, WB::getMethodDoubleOption),93TestOptionList("_foo _bar", WB::getMethodStringOption);9495public final Object value;96public final BiFunction<Executable, String, Object> getter;97private TestCase(Object value, BiFunction<Executable, String, Object> getter) {98this.value = value;99this.getter = getter;100}101}102103private static Executable getMethod(String name) {104Executable result;105try {106result = GetMethodOptionTest.class.getDeclaredMethod(name);107} catch (NoSuchMethodException | SecurityException e) {108throw new Error("TESTBUG : can't get method " + name, e);109}110return result;111}112}113114115