hotspot/test/compiler/oracle/GetMethodOptionTest.java
author cjplummer
Thu, 29 Oct 2015 12:04:04 -0700
changeset 33730 30e064828045
parent 30604 b8d532cb6420
child 38152 80e5da81fb2c
permissions -rw-r--r--
8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests Summary: Use new external.lib.roots property in TEST.ROOT so /../../test/lib is not needed. Reviewed-by: mseledtsov, sla, iklam
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
/*
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
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
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    24
import java.lang.reflect.Executable;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    25
import java.util.function.BiFunction;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    26
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29476
diff changeset
    27
import jdk.test.lib.Asserts;
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    28
import sun.hotspot.WhiteBox;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    29
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    30
/*
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    31
 * @test
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    32
 * @bug 8074980
33730
30e064828045 8140189: [TESTBUG] Get rid of "@library /../../test/lib" in jtreg tests
cjplummer
parents: 30604
diff changeset
    33
 * @library /testlibrary /test/lib
30604
b8d532cb6420 8067013: Rename the com.oracle.java.testlibary package
ykantser
parents: 29476
diff changeset
    34
 * @build sun.hotspot.WhiteBox jdk.test.lib.Asserts GetMethodOptionTest
29476
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    35
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    36
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    37
 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    38
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,ccstrlist,MyListOption,_foo,_bar
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    39
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,ccstr,MyStrOption,_foo
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    40
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,bool,MyBoolOption,false
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    41
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,intx,MyIntxOption,-1
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    42
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,uintx,MyUintxOption,1
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    43
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,MyFlag
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    44
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,double,MyDoubleOption1,1.123
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    45
 *                   -XX:CompileCommand=option,GetMethodOptionTest.test,double,MyDoubleOption2,1.123
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    46
 *                   -XX:CompileCommand=option,GetMethodOptionTest::test,bool,MyBoolOptionX,false,intx,MyIntxOptionX,-1,uintx,MyUintxOptionX,1,MyFlagX,double,MyDoubleOptionX,1.123
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    47
 *                   GetMethodOptionTest
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    48
 */
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    49
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    50
public class GetMethodOptionTest {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    51
    private static final  WhiteBox WB = WhiteBox.getWhiteBox();
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    52
    public static void main(String[] args) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    53
        Executable test = getMethod("test");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    54
        Executable test2 = getMethod("test2");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    55
        BiFunction<Executable, String, Object> getter = WB::getMethodOption;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    56
        for (TestCase testCase : TestCase.values()) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    57
            Object expected = testCase.value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    58
            String name = testCase.name();
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    59
            Asserts.assertEQ(expected, getter.apply(test, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    60
                    testCase + ": universal getter returns wrong value");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    61
            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
    62
                    testCase + ": specific getter returns wrong value");
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    63
            Asserts.assertEQ(null, getter.apply(test2, name),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    64
                    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
    65
            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
    66
                    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
    67
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    68
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    69
    private static void test() { }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    70
    private static void test2() { }
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 enum TestCase {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    73
        MyListOption("_foo _bar", WB::getMethodStringOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    74
        MyStrOption("_foo", WB::getMethodStringOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    75
        MyBoolOption(false, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    76
        MyIntxOption(-1L, WB::getMethodIntxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    77
        MyUintxOption(1L, WB::getMethodUintxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    78
        MyFlag(true, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    79
        MyDoubleOption1(1.123d, WB::getMethodDoubleOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    80
        MyDoubleOption2(1.123d, WB::getMethodDoubleOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    81
        MyBoolOptionX(false, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    82
        MyIntxOptionX(-1L, WB::getMethodIntxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    83
        MyUintxOptionX(1L, WB::getMethodUintxOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    84
        MyFlagX(true, WB::getMethodBooleanOption),
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    85
        MyDoubleOptionX(1.123d, WB::getMethodDoubleOption);
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    86
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    87
        public final Object value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    88
        public final BiFunction<Executable, String, Object> getter;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    89
        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
    90
            this.value = value;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    91
            this.getter = getter;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    92
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    93
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    94
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    95
    private static Executable getMethod(String name) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    96
        Executable result;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    97
        try {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    98
            result = GetMethodOptionTest.class.getDeclaredMethod(name);
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
    99
        } catch (NoSuchMethodException | SecurityException e) {
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   100
            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
   101
        }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   102
        return result;
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   103
    }
7a8537835aec 8074980: add WhiteBox API to get a flag value for a method
iignatyev
parents:
diff changeset
   104
}