Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/IntrinsicDisabledTest.java
41149 views
/*1* Copyright (c) 2015, 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 813865126*27* @requires !vm.graal.enabled28* @modules java.base/jdk.internal.misc29* @library /test/lib /30*31* @build sun.hotspot.WhiteBox32* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox33* @run main/othervm -Xbootclasspath/a:.34* -XX:+UnlockDiagnosticVMOptions35* -XX:+WhiteBoxAPI36* -XX:DisableIntrinsic=_putCharVolatile,_putInt37* -XX:DisableIntrinsic=_putIntVolatile38* -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putChar,ccstrlist,DisableIntrinsic,_getCharVolatile,_getInt39* -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putCharVolatile,ccstrlist,DisableIntrinsic,_getIntVolatile40* compiler.intrinsics.IntrinsicDisabledTest41* @run main/othervm -Xbootclasspath/a:.42* -XX:+UnlockDiagnosticVMOptions43* -XX:+WhiteBoxAPI44* -XX:ControlIntrinsic=-_putCharVolatile,-_putInt45* -XX:ControlIntrinsic=-_putIntVolatile46* -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putChar,-_getCharVolatile,-_getInt47* -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,-_getIntVolatile48* compiler.intrinsics.IntrinsicDisabledTest49* @run main/othervm -Xbootclasspath/a:.50* -XX:+UnlockDiagnosticVMOptions51* -XX:+WhiteBoxAPI52* -XX:ControlIntrinsic=+_putIntVolatile,+_putCharVolatile,+_putInt53* -XX:DisableIntrinsic=_putCharVolatile,_putInt54* -XX:DisableIntrinsic=_putIntVolatile55* -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putChar,+_getCharVolatile,+_getInt56* -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,+_getIntVolatile57* -XX:CompileCommand=DisableIntrinsic,jdk.internal.misc.Unsafe::putChar,_getCharVolatile,_getInt58* -XX:CompileCommand=DisableIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,_getIntVolatile59* compiler.intrinsics.IntrinsicDisabledTest60*/6162package compiler.intrinsics;6364import jdk.test.lib.Platform;65import sun.hotspot.WhiteBox;66import compiler.whitebox.CompilerWhiteBoxTest;6768import java.lang.reflect.Executable;69import java.util.Objects;7071public class IntrinsicDisabledTest {7273private static final WhiteBox wb = WhiteBox.getWhiteBox();7475/* Determine if tiered compilation is enabled. */76private static final boolean TIERED_COMPILATION = wb.getBooleanVMFlag("TieredCompilation");7778private static final int TIERED_STOP_AT_LEVEL = wb.getIntxVMFlag("TieredStopAtLevel").intValue();7980/* This test uses several methods from jdk.internal.misc.Unsafe. The method81* getMethod() returns a different Executable for each different82* combination of its input parameters. There are eight possible83* combinations, getMethod can return an Executable representing84* the following methods: putChar, putCharVolatile, getChar,85* getCharVolatile, putInt, putIntVolatile, getInt,86* getIntVolatile. These methods were selected because they can87* be intrinsified by both the C1 and the C2 compiler.88*/89static Executable getMethod(boolean isChar, boolean isPut, boolean isVolatile) throws RuntimeException {90Executable aMethod;91String methodTypeName = isChar ? "Char" : "Int";9293try {94Class aClass = Class.forName("jdk.internal.misc.Unsafe");95if (isPut) {96aMethod = aClass.getDeclaredMethod("put" + methodTypeName + (isVolatile ? "Volatile" : ""),97Object.class,98long.class,99isChar ? char.class : int.class);100} else {101aMethod = aClass.getDeclaredMethod("get" + methodTypeName + (isVolatile ? "Volatile" : ""),102Object.class,103long.class);104}105} catch (NoSuchMethodException e) {106throw new RuntimeException("Test bug, method is unavailable. " + e);107} catch (ClassNotFoundException e) {108throw new RuntimeException("Test bug, class is unavailable. " + e);109}110111return aMethod;112}113114public static void test(int compLevel) {115116Executable putChar = getMethod(true, /*isPut =*/ true, /*isVolatile = */ false);117Executable getChar = getMethod(true, /*isPut =*/ false, /*isVolatile = */ false);118Executable putCharVolatile = getMethod(true, /*isPut =*/ true, /*isVolatile = */ true);119Executable getCharVolatile = getMethod(true, /*isPut =*/ false, /*isVolatile = */ true);120Executable putInt = getMethod(false, /*isPut =*/ true, /*isVolatile = */ false);121Executable getInt = getMethod(false, /*isPut =*/ false, /*isVolatile = */ false);122Executable putIntVolatile = getMethod(false, /*isPut =*/ true, /*isVolatile = */ true);123Executable getIntVolatile = getMethod(false, /*isPut =*/ false, /*isVolatile = */ true);124125/* Test if globally disabling intrinsics works. */126if (!wb.isIntrinsicAvailable(putChar, compLevel)) {127throw new RuntimeException("Intrinsic for [" + putChar.toGenericString() +128"] is not available globally although it should be.");129}130131if (wb.isIntrinsicAvailable(putCharVolatile, compLevel)) {132throw new RuntimeException("Intrinsic for [" + putCharVolatile.toGenericString() +133"] is available globally although it should not be.");134}135136if (wb.isIntrinsicAvailable(putInt, compLevel)) {137throw new RuntimeException("Intrinsic for [" + putInt.toGenericString() +138"] is available globally although it should not be.");139}140141if (wb.isIntrinsicAvailable(putIntVolatile, compLevel)) {142throw new RuntimeException("Intrinsic for [" + putIntVolatile.toGenericString() +143"] is available globally although it should not be.");144}145146/* Test if disabling intrinsics on a per-method level147* works. The method for which intrinsics are148* disabled (the compilation context) is putChar. */149if (!wb.isIntrinsicAvailable(getChar, putChar, compLevel)) {150throw new RuntimeException("Intrinsic for [" + getChar.toGenericString() +151"] is not available for intrinsification in [" +152putChar.toGenericString() + "] although it should be.");153}154155if (wb.isIntrinsicAvailable(getCharVolatile, putChar, compLevel)) {156throw new RuntimeException("Intrinsic for [" + getCharVolatile.toGenericString() +157"] is available for intrinsification in [" +158putChar.toGenericString() + "] although it should not be.");159}160161if (wb.isIntrinsicAvailable(getInt, putChar, compLevel)) {162throw new RuntimeException("Intrinsic for [" + getInt.toGenericString() +163"] is available for intrinsification in [" +164putChar.toGenericString() + "] although it should not be.");165}166167if (wb.isIntrinsicAvailable(getIntVolatile, putCharVolatile, compLevel)) {168throw new RuntimeException("Intrinsic for [" + getIntVolatile.toGenericString() +169"] is available for intrinsification in [" +170putCharVolatile.toGenericString() + "] although it should not be.");171}172173/* Test if disabling intrinsics on a per-method level174* leaves those intrinsics enabled globally. */175if (!wb.isIntrinsicAvailable(getCharVolatile, compLevel)) {176throw new RuntimeException("Intrinsic for [" + getCharVolatile.toGenericString() +177"] is not available globally although it should be.");178}179180if (!wb.isIntrinsicAvailable(getInt, compLevel)) {181throw new RuntimeException("Intrinsic for [" + getInt.toGenericString() +182"] is not available globally although it should be.");183}184185186if (!wb.isIntrinsicAvailable(getIntVolatile, compLevel)) {187throw new RuntimeException("Intrinsic for [" + getIntVolatile.toGenericString() +188"] is not available globally although it should be.");189}190191/* Test if disabling an intrinsic globally disables it on a192* per-method level as well. */193if (!wb.isIntrinsicAvailable(putChar, getChar, compLevel)) {194throw new RuntimeException("Intrinsic for [" + putChar.toGenericString() +195"] is not available for intrinsification in [" +196getChar.toGenericString() + "] although it should be.");197}198199if (wb.isIntrinsicAvailable(putCharVolatile, getChar, compLevel)) {200throw new RuntimeException("Intrinsic for [" + putCharVolatile.toGenericString() +201"] is available for intrinsification in [" +202getChar.toGenericString() + "] although it should not be.");203}204205if (wb.isIntrinsicAvailable(putInt, getChar, compLevel)) {206throw new RuntimeException("Intrinsic for [" + putInt.toGenericString() +207"] is available for intrinsification in [" +208getChar.toGenericString() + "] although it should not be.");209}210211if (wb.isIntrinsicAvailable(putIntVolatile, getChar, compLevel)) {212throw new RuntimeException("Intrinsic for [" + putIntVolatile.toGenericString() +213"] is available for intrinsification in [" +214getChar.toGenericString() + "] although it should not be.");215}216}217218public static void main(String args[]) {219if (Platform.isServer() && !Platform.isEmulatedClient() &&220(TIERED_STOP_AT_LEVEL == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION)) {221if (TIERED_COMPILATION) {222test(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);223}224test(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);225} else {226test(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);227}228}229}230231232