Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/IntrinsicAvailableTest.java
41152 views
/*1* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 813083226* @modules java.base/jdk.internal.misc27* @library /test/lib /28*29* @build sun.hotspot.WhiteBox30* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox31* @run main/othervm -Xbootclasspath/a:.32* -XX:+UnlockDiagnosticVMOptions33* -XX:+WhiteBoxAPI34* -XX:+UseCRC32Intrinsics35* compiler.intrinsics.IntrinsicAvailableTest36* @run main/othervm -Xbootclasspath/a:.37* -XX:+UnlockDiagnosticVMOptions38* -XX:+WhiteBoxAPI39* -XX:-UseCRC32Intrinsics40* compiler.intrinsics.IntrinsicAvailableTest41* @run main/othervm -Xbootclasspath/a:.42* -XX:+UnlockDiagnosticVMOptions43* -XX:+WhiteBoxAPI44* -XX:ControlIntrinsic=+_updateCRC3245* -XX:-UseCRC32Intrinsics46* compiler.intrinsics.IntrinsicAvailableTest47* @run main/othervm -Xbootclasspath/a:.48* -XX:+UnlockDiagnosticVMOptions49* -XX:+WhiteBoxAPI50* -XX:ControlIntrinsic=-_updateCRC3251* -XX:+UseCRC32Intrinsics52* compiler.intrinsics.IntrinsicAvailableTest53*54* @run main/othervm -Xbootclasspath/a:.55* -XX:+UnlockDiagnosticVMOptions56* -XX:+WhiteBoxAPI57* -XX:ControlIntrinsic=+_updateCRC3258* -XX:+UseCRC32Intrinsics59* compiler.intrinsics.IntrinsicAvailableTest60*/616263package compiler.intrinsics;6465import compiler.whitebox.CompilerWhiteBoxTest;66import jdk.test.lib.Platform;6768import java.lang.reflect.Executable;69import java.util.concurrent.Callable;7071public class IntrinsicAvailableTest extends CompilerWhiteBoxTest {7273public IntrinsicAvailableTest(IntrinsicAvailableTestTestCase testCase) {74super(testCase);75}7677public static class IntrinsicAvailableTestTestCase implements TestCase {7879public String name() {80return "IntrinsicAvailableTestTestCase";81}8283public Executable getExecutable() {84// Using a single method to test the85// WhiteBox.isIntrinsicAvailable(Executable method, int compLevel)86// call for the compilation level corresponding to both the C1 and C287// compiler keeps the current test simple.88//89// The tested method is java.util.zip.CRC32.update(int, int) because90// both C1 and C2 define an intrinsic for the method and91// the UseCRC32Intrinsics flag can be used to enable/disable92// intrinsification of the method in both product and fastdebug93// builds.94try {95return Class.forName("java.util.zip.CRC32").getDeclaredMethod("update", int.class, int.class);96} catch (NoSuchMethodException e) {97throw new RuntimeException("Test bug, method unavailable. " + e);98} catch (ClassNotFoundException e) {99throw new RuntimeException("Test bug, class unavailable. " + e);100}101}102103public Callable<Integer> getCallable() {104return null;105}106107public boolean isOsr() {108return false;109}110111}112113protected void checkIntrinsicForCompilationLevel(Executable method, int compLevel) throws Exception {114boolean intrinsicEnabled = true;115String controlIntrinsic = getVMOption("ControlIntrinsic", "");116117if (controlIntrinsic.contains("+_updateCRC32")) {118intrinsicEnabled = true;119} else if (controlIntrinsic.contains("-_updateCRC32")) {120intrinsicEnabled = false;121}122123intrinsicEnabled &= Boolean.valueOf(getVMOption("UseCRC32Intrinsics"));124125boolean intrinsicAvailable = WHITE_BOX.isIntrinsicAvailable(method,126compLevel);127128String intrinsicEnabledMessage = intrinsicEnabled ? "enabled" : "disabled";129String intrinsicAvailableMessage = intrinsicAvailable ? "available" : "not available";130131if (intrinsicEnabled == intrinsicAvailable) {132System.out.println("Expected result: intrinsic for java.util.zip.CRC32.update() is " +133intrinsicEnabledMessage + " and intrinsic is " + intrinsicAvailableMessage +134" at compilation level " + compLevel);135} else {136throw new RuntimeException("Unexpected result: intrinsic for java.util.zip.CRC32.update() is " +137intrinsicEnabledMessage + " but intrinsic is " + intrinsicAvailableMessage +138" at compilation level " + compLevel);139}140}141142public void test() throws Exception {143Executable intrinsicMethod = testCase.getExecutable();144if (Platform.isServer() && !Platform.isEmulatedClient() && (TIERED_STOP_AT_LEVEL == COMP_LEVEL_FULL_OPTIMIZATION)) {145if (TIERED_COMPILATION) {146checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);147}148// Dont bother check JVMCI compiler - returns false on all intrinsics.149if (!Boolean.valueOf(getVMOption("UseJVMCICompiler"))) {150checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_FULL_OPTIMIZATION);151}152} else {153checkIntrinsicForCompilationLevel(intrinsicMethod, COMP_LEVEL_SIMPLE);154}155}156157public static void main(String args[]) throws Exception {158new IntrinsicAvailableTest(new IntrinsicAvailableTestTestCase()).test();159}160}161162163