jdk

Форк
0
/
IntrinsicDisabledTest.java 
230 строк · 11.8 Кб
1
/*
2
 * Copyright (c) 2015, 2022, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/*
25
 * @test
26
 * @bug 8138651
27
 *
28
 * @requires !vm.graal.enabled
29
 * @modules java.base/jdk.internal.misc
30
 * @library /test/lib /
31
 *
32
 * @build jdk.test.whitebox.WhiteBox
33
 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
34
 * @run main/othervm -Xbootclasspath/a:.
35
 *                   -XX:+UnlockDiagnosticVMOptions
36
 *                   -XX:+WhiteBoxAPI
37
 *                   -XX:DisableIntrinsic=_putCharVolatile,_putInt
38
 *                   -XX:DisableIntrinsic=_putIntVolatile
39
 *                   -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putChar,ccstrlist,DisableIntrinsic,_getCharVolatile,_getInt
40
 *                   -XX:CompileCommand=option,jdk.internal.misc.Unsafe::putCharVolatile,ccstrlist,DisableIntrinsic,_getIntVolatile
41
 *                   compiler.intrinsics.IntrinsicDisabledTest
42
 * @run main/othervm -Xbootclasspath/a:.
43
 *                   -XX:+UnlockDiagnosticVMOptions
44
 *                   -XX:+WhiteBoxAPI
45
 *                   -XX:ControlIntrinsic=-_putCharVolatile,-_putInt
46
 *                   -XX:ControlIntrinsic=-_putIntVolatile
47
 *                   -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putChar,-_getCharVolatile,-_getInt
48
 *                   -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,-_getIntVolatile
49
 *                   compiler.intrinsics.IntrinsicDisabledTest
50
 * @run main/othervm -Xbootclasspath/a:.
51
 *                   -XX:+UnlockDiagnosticVMOptions
52
 *                   -XX:+WhiteBoxAPI
53
 *                   -XX:ControlIntrinsic=+_putIntVolatile,+_putCharVolatile,+_putInt
54
 *                   -XX:DisableIntrinsic=_putCharVolatile,_putInt
55
 *                   -XX:DisableIntrinsic=_putIntVolatile
56
 *                   -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putChar,+_getCharVolatile,+_getInt
57
 *                   -XX:CompileCommand=ControlIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,+_getIntVolatile
58
 *                   -XX:CompileCommand=DisableIntrinsic,jdk.internal.misc.Unsafe::putChar,_getCharVolatile,_getInt
59
 *                   -XX:CompileCommand=DisableIntrinsic,jdk.internal.misc.Unsafe::putCharVolatile,_getIntVolatile
60
 *                   compiler.intrinsics.IntrinsicDisabledTest
61
*/
62

63
package compiler.intrinsics;
64

65
import jdk.test.lib.Platform;
66
import jdk.test.whitebox.WhiteBox;
67
import compiler.whitebox.CompilerWhiteBoxTest;
68

69
import java.lang.reflect.Executable;
70
import java.util.Objects;
71

72
public class IntrinsicDisabledTest {
73

74
    private static final WhiteBox wb = WhiteBox.getWhiteBox();
75

76
    /* Determine if tiered compilation is enabled. */
77
    private static final boolean TIERED_COMPILATION = wb.getBooleanVMFlag("TieredCompilation");
78

79
    private static final int TIERED_STOP_AT_LEVEL = wb.getIntxVMFlag("TieredStopAtLevel").intValue();
80

81
    /* This test uses several methods from jdk.internal.misc.Unsafe. The method
82
     * getMethod() returns a different Executable for each different
83
     * combination of its input parameters. There are eight possible
84
     * combinations, getMethod can return an Executable representing
85
     * the following methods: putChar, putCharVolatile, getChar,
86
     * getCharVolatile, putInt, putIntVolatile, getInt,
87
     * getIntVolatile. These methods were selected because they can
88
     * be intrinsified by both the C1 and the C2 compiler.
89
     */
90
    static Executable getMethod(boolean isChar, boolean isPut, boolean isVolatile) throws RuntimeException {
91
        Executable aMethod;
92
        String methodTypeName = isChar ? "Char" : "Int";
93

94
        try {
95
            Class aClass = Class.forName("jdk.internal.misc.Unsafe");
96
            if (isPut) {
97
                aMethod = aClass.getDeclaredMethod("put" + methodTypeName + (isVolatile ? "Volatile" : ""),
98
                                                   Object.class,
99
                                                   long.class,
100
                                                   isChar ? char.class : int.class);
101
            } else {
102
                aMethod = aClass.getDeclaredMethod("get" + methodTypeName + (isVolatile ? "Volatile" : ""),
103
                                                   Object.class,
104
                                                   long.class);
105
            }
106
        } catch (NoSuchMethodException e) {
107
            throw new RuntimeException("Test bug, method is unavailable. " + e);
108
        } catch (ClassNotFoundException e) {
109
            throw new RuntimeException("Test bug, class is unavailable. " + e);
110
        }
111

112
        return aMethod;
113
    }
114

115
    public static void test(int compLevel) {
116

117
        Executable putChar = getMethod(true, /*isPut =*/ true, /*isVolatile = */ false);
118
        Executable getChar = getMethod(true, /*isPut =*/ false, /*isVolatile = */ false);
119
        Executable putCharVolatile = getMethod(true, /*isPut =*/ true, /*isVolatile = */ true);
120
        Executable getCharVolatile = getMethod(true, /*isPut =*/ false, /*isVolatile = */ true);
121
        Executable putInt = getMethod(false, /*isPut =*/ true, /*isVolatile = */ false);
122
        Executable getInt = getMethod(false, /*isPut =*/ false, /*isVolatile = */ false);
123
        Executable putIntVolatile = getMethod(false, /*isPut =*/ true, /*isVolatile = */ true);
124
        Executable getIntVolatile = getMethod(false, /*isPut =*/ false, /*isVolatile = */ true);
125

126
        /* Test if globally disabling intrinsics works. */
127
        if (!wb.isIntrinsicAvailable(putChar, compLevel)) {
128
            throw new RuntimeException("Intrinsic for [" + putChar.toGenericString() +
129
                                       "] is not available globally although it should be.");
130
        }
131

132
        if (wb.isIntrinsicAvailable(putCharVolatile, compLevel)) {
133
            throw new RuntimeException("Intrinsic for [" + putCharVolatile.toGenericString() +
134
                                       "] is available globally although it should not be.");
135
        }
136

137
        if (wb.isIntrinsicAvailable(putInt, compLevel)) {
138
            throw new RuntimeException("Intrinsic for [" + putInt.toGenericString() +
139
                                       "] is available globally although it should not be.");
140
        }
141

142
        if (wb.isIntrinsicAvailable(putIntVolatile, compLevel)) {
143
            throw new RuntimeException("Intrinsic for [" + putIntVolatile.toGenericString() +
144
                                       "] is available globally although it should not be.");
145
        }
146

147
        /* Test if disabling intrinsics on a per-method level
148
         * works. The method for which intrinsics are
149
         * disabled (the compilation context) is putChar. */
150
        if (!wb.isIntrinsicAvailable(getChar, putChar, compLevel)) {
151
            throw new RuntimeException("Intrinsic for [" + getChar.toGenericString() +
152
                                       "] is not available for intrinsification in [" +
153
                                       putChar.toGenericString() + "] although it should be.");
154
        }
155

156
        if (wb.isIntrinsicAvailable(getCharVolatile, putChar, compLevel)) {
157
            throw new RuntimeException("Intrinsic for [" + getCharVolatile.toGenericString() +
158
                                       "] is available for intrinsification in [" +
159
                                       putChar.toGenericString() + "] although it should not be.");
160
        }
161

162
        if (wb.isIntrinsicAvailable(getInt, putChar, compLevel)) {
163
            throw new RuntimeException("Intrinsic for [" + getInt.toGenericString() +
164
                                       "] is available for intrinsification in [" +
165
                                       putChar.toGenericString() + "] although it should not be.");
166
        }
167

168
        if (wb.isIntrinsicAvailable(getIntVolatile, putCharVolatile, compLevel)) {
169
            throw new RuntimeException("Intrinsic for [" + getIntVolatile.toGenericString() +
170
                                       "] is available for intrinsification in [" +
171
                                       putCharVolatile.toGenericString() + "] although it should not be.");
172
        }
173

174
        /* Test if disabling intrinsics on a per-method level
175
         * leaves those intrinsics enabled globally. */
176
        if (!wb.isIntrinsicAvailable(getCharVolatile, compLevel)) {
177
            throw new RuntimeException("Intrinsic for [" + getCharVolatile.toGenericString() +
178
                                       "] is not available globally although it should be.");
179
        }
180

181
        if (!wb.isIntrinsicAvailable(getInt, compLevel)) {
182
            throw new RuntimeException("Intrinsic for [" + getInt.toGenericString() +
183
                                       "] is not available globally although it should be.");
184
        }
185

186

187
        if (!wb.isIntrinsicAvailable(getIntVolatile, compLevel)) {
188
            throw new RuntimeException("Intrinsic for [" + getIntVolatile.toGenericString() +
189
                                       "] is not available globally although it should be.");
190
        }
191

192
        /* Test if disabling an intrinsic globally disables it on a
193
         * per-method level as well. */
194
        if (!wb.isIntrinsicAvailable(putChar, getChar, compLevel)) {
195
            throw new RuntimeException("Intrinsic for [" + putChar.toGenericString() +
196
                                       "] is not available for intrinsification in [" +
197
                                       getChar.toGenericString() + "] although it should be.");
198
        }
199

200
        if (wb.isIntrinsicAvailable(putCharVolatile, getChar, compLevel)) {
201
            throw new RuntimeException("Intrinsic for [" + putCharVolatile.toGenericString() +
202
                                       "] is available for intrinsification in [" +
203
                                       getChar.toGenericString() + "] although it should not be.");
204
        }
205

206
        if (wb.isIntrinsicAvailable(putInt, getChar, compLevel)) {
207
            throw new RuntimeException("Intrinsic for [" + putInt.toGenericString() +
208
                                       "] is available for intrinsification in [" +
209
                                       getChar.toGenericString() + "] although it should not be.");
210
        }
211

212
        if (wb.isIntrinsicAvailable(putIntVolatile, getChar, compLevel)) {
213
            throw new RuntimeException("Intrinsic for [" + putIntVolatile.toGenericString() +
214
                                       "] is available for intrinsification in [" +
215
                                       getChar.toGenericString() + "] although it should not be.");
216
        }
217
    }
218

219
    public static void main(String args[]) {
220
        if (Platform.isServer() && !Platform.isEmulatedClient() &&
221
                                   (TIERED_STOP_AT_LEVEL == CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION)) {
222
            if (TIERED_COMPILATION) {
223
                test(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
224
            }
225
            test(CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
226
        } else {
227
            test(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE);
228
        }
229
    }
230
}
231

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.