IntrinsicAvailableTest.java revision 11833:1cbffa2beba6
11558Srgrimes/*
21558Srgrimes * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
31558Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
41558Srgrimes *
51558Srgrimes * This code is free software; you can redistribute it and/or modify it
61558Srgrimes * under the terms of the GNU General Public License version 2 only, as
71558Srgrimes * published by the Free Software Foundation.
81558Srgrimes *
91558Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT
101558Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
111558Srgrimes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
121558Srgrimes * version 2 for more details (a copy is included in the LICENSE file that
131558Srgrimes * accompanied this code).
141558Srgrimes *
151558Srgrimes * You should have received a copy of the GNU General Public License version
161558Srgrimes * 2 along with this work; if not, write to the Free Software Foundation,
171558Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
181558Srgrimes *
191558Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
201558Srgrimes * or visit www.oracle.com if you need additional information or have any
211558Srgrimes * questions.
221558Srgrimes */
231558Srgrimes
241558Srgrimes/*
251558Srgrimes * @test
261558Srgrimes * @bug 8130832
271558Srgrimes * @modules java.base/jdk.internal.misc
281558Srgrimes * @library /test/lib /
291558Srgrimes *
301558Srgrimes * @build sun.hotspot.WhiteBox
311558Srgrimes * @run driver ClassFileInstaller sun.hotspot.WhiteBox
321558Srgrimes *                                sun.hotspot.WhiteBox$WhiteBoxPermission
331558Srgrimes * @run main/othervm -Xbootclasspath/a:.
3437417Scharnier *                   -XX:+UnlockDiagnosticVMOptions
351558Srgrimes *                   -XX:+WhiteBoxAPI
361558Srgrimes *                   -XX:+UseCRC32Intrinsics
371558Srgrimes *                   compiler.intrinsics.IntrinsicAvailableTest
381558Srgrimes * @run main/othervm -Xbootclasspath/a:.
391558Srgrimes *                   -XX:+UnlockDiagnosticVMOptions
4037417Scharnier *                   -XX:+WhiteBoxAPI
411558Srgrimes *                   -XX:-UseCRC32Intrinsics
4237417Scharnier *                   compiler.intrinsics.IntrinsicAvailableTest
4337417Scharnier */
4450476Speter
451558Srgrimes
461558Srgrimespackage compiler.intrinsics;
471558Srgrimes
4827837Sdavidnimport compiler.whitebox.CompilerWhiteBoxTest;
4919227Sphkimport jdk.test.lib.Platform;
501558Srgrimes
511558Srgrimesimport java.lang.reflect.Executable;
5228344Sdavidnimport java.util.concurrent.Callable;
53101271Smux
541558Srgrimespublic class IntrinsicAvailableTest extends CompilerWhiteBoxTest {
551558Srgrimes
561558Srgrimes    public IntrinsicAvailableTest(IntrinsicAvailableTestTestCase testCase) {
571558Srgrimes        super(testCase);
58166484Simp    }
5927186Sache
6069793Sobrien    public static class IntrinsicAvailableTestTestCase implements TestCase {
611558Srgrimes
621558Srgrimes        public String name() {
631558Srgrimes            return "IntrinsicAvailableTestTestCase";
641558Srgrimes        }
651558Srgrimes
661558Srgrimes        public Executable getExecutable() {
671558Srgrimes            // Using a single method to test the
681558Srgrimes            // WhiteBox.isIntrinsicAvailable(Executable method, int compLevel)
692323Snate            // call for the compilation level corresponding to both the C1 and C2
7026594Scharnier            // compiler keeps the current test simple.
711558Srgrimes            //
721558Srgrimes            // The tested method is java.util.zip.CRC32.update(int, int) because
731558Srgrimes            // both C1 and C2 define an intrinsic for the method and
741558Srgrimes            // the UseCRC32Intrinsics flag can be used to enable/disable
751558Srgrimes            // intrinsification of the method in both product and fastdebug
761558Srgrimes            // builds.
771558Srgrimes            try {
7821865Sdavidn                return Class.forName("java.util.zip.CRC32").getDeclaredMethod("update", int.class, int.class);
7921865Sdavidn            } catch (NoSuchMethodException e) {
8021865Sdavidn                throw new RuntimeException("Test bug, method unavailable. " + e);
8121865Sdavidn            } catch (ClassNotFoundException e) {
821558Srgrimes                throw new RuntimeException("Test bug, class unavailable. " + e);
831558Srgrimes            }
841558Srgrimes        }
851558Srgrimes
861558Srgrimes        public Callable<Integer> getCallable() {
871558Srgrimes            return null;
881558Srgrimes        }
89173785Sobrien
901558Srgrimes        public boolean isOsr() {
911558Srgrimes            return false;
921558Srgrimes        }
93173785Sobrien
94173785Sobrien    }
95173785Sobrien
96173785Sobrien    protected void checkIntrinsicForCompilationLevel(Executable method, int compLevel) throws Exception {
971558Srgrimes        boolean intrinsicEnabled = Boolean.valueOf(getVMOption("UseCRC32Intrinsics"));
9892838Simp        boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(method,
9992838Simp                                                                    compLevel);
1001558Srgrimes
10192838Simp        String intrinsicEnabledMessage = intrinsicEnabled ? "enabled" : "disabled";
10292838Simp        String intrinsicAvailableMessage = intrinsicAvailable ? "available" : "not available";
10392838Simp
10492838Simp        if (intrinsicEnabled == intrinsicAvailable) {
10592838Simp            System.out.println("Expected result: intrinsic for java.util.zip.CRC32.update() is " +
10692838Simp                               intrinsicEnabledMessage + " and intrinsic is " + intrinsicAvailableMessage +
107140070Sdelphij                               " at compilation level " + compLevel);
1081558Srgrimes        } else {
1091558Srgrimes            throw new RuntimeException("Unexpected result: intrinsic for java.util.zip.CRC32.update() is " +
1101558Srgrimes                                       intrinsicEnabledMessage + " but intrinsic is " + intrinsicAvailableMessage +
1111558Srgrimes                                       " at compilation level " + compLevel);
1121558Srgrimes        }
1131558Srgrimes    }
11492838Simp
11592838Simp    public void test() throws Exception {
1161558Srgrimes        Executable intrinsicMethod = testCase.getExecutable();
11792838Simp        if (Platform.isServer() && (TIERED_STOP_AT_LEVEL == COMP_LEVEL_FULL_OPTIMIZATION)) {
11892838Simp            if (TIERED_COMPILATION) {
11992838Simp                checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
12092838Simp            }
12192838Simp            // Dont bother check JVMCI compiler - returns false on all intrinsics.
12292838Simp            if (!Boolean.valueOf(getVMOption("UseJVMCICompiler"))) {
12392838Simp                checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_FULL_OPTIMIZATION);
1241558Srgrimes            }
125166484Simp        } else {
126166484Simp            checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);
1271558Srgrimes        }
12811910Sphk    }
12911910Sphk
13011910Sphk    public static void main(String args[]) throws Exception {
1312327Sjkh        new IntrinsicAvailableTest(new IntrinsicAvailableTestTestCase()).test();
13247962Sru    }
1331558Srgrimes}
13419227Sphk