test/hotspot/jtreg/compiler/oracle/GetMethodOptionTest.java
author iignatyev
Mon, 18 Feb 2019 09:31:07 -0800
changeset 53791 bec6c8739833
parent 47216 71c04702a3d5
permissions -rw-r--r--
8219157: vm/mlvm/mixed/stress/java/findDeadlock should be problem-listed only on mac Reviewed-by: thartmann
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     1
/*
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     4
 *
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     7
 * published by the Free Software Foundation.
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     8
 *
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    13
 * accompanied this code).
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    14
 *
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    18
 *
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    21
 * questions.
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    22
 */
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    23
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    24
/*
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    25
 * @test
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    26
 * @bug 8074980
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    27
 * @library /test/lib
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    28
 * @modules java.base/jdk.internal.misc
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40059
diff changeset
    29
 * @build sun.hotspot.WhiteBox
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    30
 * @run driver ClassFileInstaller sun.hotspot.WhiteBox
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    31
 *                                sun.hotspot.WhiteBox$WhiteBoxPermission
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    32
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    33
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,ccstrlist,MyListOption,_foo,_bar
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    34
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,ccstr,MyStrOption,_foo
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    35
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,bool,MyBoolOption,false
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    36
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,intx,MyIntxOption,-1
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    37
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,uintx,MyUintxOption,1
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    38
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,MyFlag
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    39
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,double,MyDoubleOption1,1.123
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    40
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,double,MyDoubleOption2,1.123
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    41
 *                   -XX:CompileCommand=option,compiler.oracle.GetMethodOptionTest::test,bool,MyBoolOptionX,false,intx,MyIntxOptionX,-1,uintx,MyUintxOptionX,1,MyFlagX,double,MyDoubleOptionX,1.123
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    42
 *                   compiler.oracle.GetMethodOptionTest
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    43
 */
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    44
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    45
package compiler.oracle;
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    46
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29476
diff changeset
    47
import jdk.test.lib.Asserts;
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    48
import sun.hotspot.WhiteBox;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    49
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    50
import java.lang.reflect.Executable;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 38152
diff changeset
    51
import java.util.function.BiFunction;
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    52
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    53
public class GetMethodOptionTest {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    54
    private static final  WhiteBox WB = WhiteBox.getWhiteBox();
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    55
    public static void main(String[] args) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    56
        Executable test = getMethod("test");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    57
        Executable test2 = getMethod("test2");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    58
        BiFunction<Executable, String, Object> getter = WB::getMethodOption;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    59
        for (TestCase testCase : TestCase.values()) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    60
            Object expected = testCase.value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    61
            String name = testCase.name();
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    62
            Asserts.assertEQ(expected, getter.apply(test, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    63
                    testCase + ": universal getter returns wrong value");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    64
            Asserts.assertEQ(expected, testCase.getter.apply(test, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    65
                    testCase + ": specific getter returns wrong value");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    66
            Asserts.assertEQ(null, getter.apply(test2, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    67
                    testCase + ": universal getter returns value for unused method");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    68
            Asserts.assertEQ(null, testCase.getter.apply(test2, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    69
                    testCase + ": type specific getter returns value for unused method");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    70
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    71
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    72
    private static void test() { }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    73
    private static void test2() { }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    74
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    75
    private static enum TestCase {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    76
        MyListOption("_foo _bar", WB::getMethodStringOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    77
        MyStrOption("_foo", WB::getMethodStringOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    78
        MyBoolOption(false, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    79
        MyIntxOption(-1L, WB::getMethodIntxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    80
        MyUintxOption(1L, WB::getMethodUintxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    81
        MyFlag(true, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    82
        MyDoubleOption1(1.123d, WB::getMethodDoubleOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    83
        MyDoubleOption2(1.123d, WB::getMethodDoubleOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    84
        MyBoolOptionX(false, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    85
        MyIntxOptionX(-1L, WB::getMethodIntxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    86
        MyUintxOptionX(1L, WB::getMethodUintxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    87
        MyFlagX(true, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    88
        MyDoubleOptionX(1.123d, WB::getMethodDoubleOption);
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    89
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    90
        public final Object value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    91
        public final BiFunction<Executable, String, Object> getter;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    92
        private TestCase(Object value, BiFunction<Executable, String, Object> getter) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    93
            this.value = value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    94
            this.getter = getter;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    95
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    96
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    97
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    98
    private static Executable getMethod(String name) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    99
        Executable result;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   100
        try {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   101
            result = GetMethodOptionTest.class.getDeclaredMethod(name);
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   102
        } catch (NoSuchMethodException | SecurityException e) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   103
            throw new Error("TESTBUG : can't get method " + name, e);
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   104
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   105
        return result;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   106
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   107
}