--- /dev/null 2015-07-15 11:37:42.295537975 +0200 +++ new/test/compiler/intrinsics/IntrinsicAvailableTest.java 2015-07-21 17:08:33.141850362 +0200 @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +import java.lang.reflect.Executable; +import java.util.concurrent.Callable; +import java.util.Objects; +/* + * @test + * @bug 8130832 + * @library /testlibrary /../../test/lib /compiler/whitebox /compiler/testlibrary + * @build IntrinsicAvailableTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * sun.hotspot.WhiteBox$WhiteBoxPermission + * @run main/othervm -Xbootclasspath/a:. + * -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI + * -XX:+UseCRC32Intrinsics + * IntrinsicAvailableTest + * @run main/othervm -Xbootclasspath/a:. + * -XX:+UnlockDiagnosticVMOptions + * -XX:+WhiteBoxAPI + * -XX:-UseCRC32Intrinsics + * IntrinsicAvailableTest + */ +public class IntrinsicAvailableTest extends CompilerWhiteBoxTest { + protected String VMName; + + public IntrinsicAvailableTest(IntrinsicAvailableTestTestCase testCase) { + super(testCase); + VMName = System.getProperty("java.vm.name"); + } + + public static class IntrinsicAvailableTestTestCase implements TestCase { + + public String name() { + return "IntrinsicAvailableTestTestCase"; + } + + public Executable getExecutable() { + // Using a single method to test the + // WhiteBox.isIntrinsicAvailableForMethod(Executable method, int compLevel) + // call for the compilation level corresponding to both the C1 and C2 + // compiler keeps the current test simple. + // + // The tested method is java.util.zip.CRC32.update(int, int) because + // both C1 and C2 define an intrinsic for the method and + // the UseCRC32Intrinsics flag can be used to enable/disable + // intrinsification of the method in both product and fastdebug + // builds. + try { + return Class.forName("java.util.zip.CRC32").getDeclaredMethod("update", int.class, int.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException("Test bug, method unavailable. " + e); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Test bug, class unavailable. " + e); + } + } + + public Callable getCallable() { + return null; + } + + public boolean isOsr() { + return false; + } + + } + + protected void checkIntrinsicForCompilationLevel(Executable method, int compLevel) throws Exception { + boolean intrinsicEnabled = Boolean.valueOf(getVMOption("UseCRC32Intrinsics")); + boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailableForMethod(method, + compLevel); + + String intrinsicEnabledMessage = intrinsicEnabled ? "enabled" : "disabled"; + String intrinsicAvailableMessage = intrinsicAvailable ? "available" : "not available"; + + if (intrinsicEnabled == intrinsicAvailable) { + System.out.println("Expected result: intrinsic for java.util.zip.CRC32.update() is " + + intrinsicEnabledMessage + " and intrinsic is " + intrinsicAvailableMessage + + " at compilation level " + compLevel); + } else { + throw new RuntimeException("Unexpected result: intrinsic for java.util.zip.CRC32.update() is " + + intrinsicEnabledMessage + " but intrinsic is " + intrinsicAvailableMessage + + " at compilation level " + compLevel); + } + } + + protected boolean isServerVM() { + return VMName.toLowerCase().contains("server"); + } + + public void test() throws Exception { + Executable intrinsicMethod = testCase.getExecutable(); + if (isServerVM()) { + if (TIERED_COMPILATION) { + checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE); + } + checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_FULL_OPTIMIZATION); + } else { + checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE); + } + } + + public static void main(String args[]) throws Exception { + new IntrinsicAvailableTest(new IntrinsicAvailableTestTestCase()).test(); + } +}