hotspot/test/compiler/intrinsics/IntrinsicAvailableTest.java
author zmajo
Tue, 28 Jul 2015 19:20:42 +0200
changeset 31962 d05e0a4d1b43
child 34155 8d9e0cbf93a2
child 33730 30e064828045
permissions -rw-r--r--
8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics Summary: Add a new method, sun.hotspot.WhiteBox.isIntrinsicAvailable, that can be used to determine if an intrinsic is available. Reviewed-by: kvn, jrose
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
31962
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     1
/*
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     4
 *
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     8
 *
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    13
 * accompanied this code).
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    14
 *
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    18
 *
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    21
 * questions.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    22
 */
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    23
import java.lang.reflect.Executable;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    24
import java.util.concurrent.Callable;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    25
import java.util.Objects;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    26
/*
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    27
 * @test
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    28
 * @bug 8130832
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    29
 * @library /testlibrary /../../test/lib /compiler/whitebox /compiler/testlibrary
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    30
 * @build IntrinsicAvailableTest
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    31
 * @run main ClassFileInstaller sun.hotspot.WhiteBox
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    32
 *                              sun.hotspot.WhiteBox$WhiteBoxPermission
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    33
 * @run main/othervm -Xbootclasspath/a:.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    34
 *                   -XX:+UnlockDiagnosticVMOptions
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    35
 *                   -XX:+WhiteBoxAPI
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    36
 *                   -XX:+UseCRC32Intrinsics
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    37
 *                   IntrinsicAvailableTest
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    38
 * @run main/othervm -Xbootclasspath/a:.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    39
 *                   -XX:+UnlockDiagnosticVMOptions
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    40
 *                   -XX:+WhiteBoxAPI
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    41
 *                   -XX:-UseCRC32Intrinsics
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    42
 *                   IntrinsicAvailableTest
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    43
 */
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    44
public class IntrinsicAvailableTest extends CompilerWhiteBoxTest {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    45
    protected String VMName;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    46
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    47
    public IntrinsicAvailableTest(IntrinsicAvailableTestTestCase testCase) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    48
        super(testCase);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    49
        VMName = System.getProperty("java.vm.name");
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    50
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    51
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    52
    public static class IntrinsicAvailableTestTestCase implements TestCase {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    53
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    54
        public String name() {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    55
            return "IntrinsicAvailableTestTestCase";
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    56
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    57
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    58
        public Executable getExecutable() {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    59
            // Using a single method to test the
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    60
            // WhiteBox.isIntrinsicAvailable(Executable method, int compLevel)
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    61
            // call for the compilation level corresponding to both the C1 and C2
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    62
            // compiler keeps the current test simple.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    63
            //
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    64
            // The tested method is java.util.zip.CRC32.update(int, int) because
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    65
            // both C1 and C2 define an intrinsic for the method and
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    66
            // the UseCRC32Intrinsics flag can be used to enable/disable
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    67
            // intrinsification of the method in both product and fastdebug
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    68
            // builds.
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    69
            try {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    70
                return Class.forName("java.util.zip.CRC32").getDeclaredMethod("update", int.class, int.class);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    71
            } catch (NoSuchMethodException e) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    72
                throw new RuntimeException("Test bug, method unavailable. " + e);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    73
            } catch (ClassNotFoundException e) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    74
                throw new RuntimeException("Test bug, class unavailable. " + e);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    75
            }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    76
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    77
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    78
        public Callable<Integer> getCallable() {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    79
            return null;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    80
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    81
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    82
        public boolean isOsr() {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    83
            return false;
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    84
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    85
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    86
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    87
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    88
    protected void checkIntrinsicForCompilationLevel(Executable method, int compLevel) throws Exception {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    89
        boolean intrinsicEnabled = Boolean.valueOf(getVMOption("UseCRC32Intrinsics"));
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    90
        boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(method,
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    91
                                                                    compLevel);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    92
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    93
        String intrinsicEnabledMessage = intrinsicEnabled ? "enabled" : "disabled";
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    94
        String intrinsicAvailableMessage = intrinsicAvailable ? "available" : "not available";
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    95
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    96
        if (intrinsicEnabled == intrinsicAvailable) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    97
            System.out.println("Expected result: intrinsic for java.util.zip.CRC32.update() is " +
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    98
                               intrinsicEnabledMessage + " and intrinsic is " + intrinsicAvailableMessage +
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
    99
                               " at compilation level " + compLevel);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   100
        } else {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   101
            throw new RuntimeException("Unexpected result: intrinsic for java.util.zip.CRC32.update() is " +
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   102
                                       intrinsicEnabledMessage + " but intrinsic is " + intrinsicAvailableMessage +
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   103
                                       " at compilation level " + compLevel);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   104
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   105
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   106
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   107
    protected boolean isServerVM() {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   108
        return VMName.toLowerCase().contains("server");
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   109
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   110
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   111
    public void test() throws Exception {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   112
        Executable intrinsicMethod = testCase.getExecutable();
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   113
        if (isServerVM()) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   114
            if (TIERED_COMPILATION) {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   115
                checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   116
            }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   117
            checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_FULL_OPTIMIZATION);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   118
        } else {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   119
            checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   120
        }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   121
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   122
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   123
    public static void main(String args[]) throws Exception {
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   124
        new IntrinsicAvailableTest(new IntrinsicAvailableTestTestCase()).test();
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   125
    }
d05e0a4d1b43 8130832: Extend the WhiteBox API to provide information about the availability of compiler intrinsics
zmajo
parents:
diff changeset
   126
}