jdk

Форк
0
/
TestCheckIndex.java 
133 строки · 5.1 Кб
1
/*
2
 * Copyright (c) 2020, Red Hat, Inc. 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 8255150
27
 * @summary Add utility methods to check long indexes and ranges
28
 * @requires vm.compiler2.enabled
29
 * @requires vm.compMode != "Xcomp"
30
 * @library /test/lib /
31
 * @build jdk.test.whitebox.WhiteBox
32
 * @run driver jdk.test.lib.helpers.ClassFileInstaller jdk.test.whitebox.WhiteBox
33
 *
34
 * @run main/othervm -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation TestCheckIndex
35
 *
36
 */
37

38
import java.util.Objects;
39
import jdk.test.whitebox.WhiteBox;
40
import java.lang.reflect.Method;
41
import compiler.whitebox.CompilerWhiteBoxTest;
42

43
public class TestCheckIndex {
44
    private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
45

46
    public static void main(String[] args) throws NoSuchMethodException {
47
        Objects.checkIndex(0, 10); // Load class
48
        Method m1 = TestCheckIndex.class.getDeclaredMethod("test1", int.class, int.class);
49
        Method m2 = TestCheckIndex.class.getDeclaredMethod("test2", long.class, long.class);
50
        Method m3 = TestCheckIndex.class.getDeclaredMethod("test3", int.class, int.class);
51
        Method m4 = TestCheckIndex.class.getDeclaredMethod("test4", long.class, long.class);
52
        assert m1 != null && m2 != null && m3 != null && m4 != null;
53
        WHITE_BOX.enqueueMethodForCompilation(m1, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
54
        if (!WHITE_BOX.isMethodCompiled(m1)) {
55
            throw new RuntimeException("should be compiled");
56
        }
57
        WHITE_BOX.enqueueMethodForCompilation(m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
58
        if (!WHITE_BOX.isMethodCompiled(m2)) {
59
            throw new RuntimeException("should be compiled");
60
        }
61
        WHITE_BOX.enqueueMethodForCompilation(m3, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
62
        if (!WHITE_BOX.isMethodCompiled(m3)) {
63
            throw new RuntimeException("should be compiled");
64
        }
65
        WHITE_BOX.enqueueMethodForCompilation(m4, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
66
        if (!WHITE_BOX.isMethodCompiled(m4)) {
67
            throw new RuntimeException("should be compiled");
68
        }
69

70
        if (test1(0, 10) != 0) {
71
            throw new RuntimeException("incorrect result");
72
        }
73
        if (!WHITE_BOX.isMethodCompiled(m1)) {
74
            throw new RuntimeException("should still be compiled");
75
        }
76
        if (test2(0, 10) != 0) {
77
            throw new RuntimeException("incorrect result");
78
        }
79
        if (!WHITE_BOX.isMethodCompiled(m2)) {
80
            throw new RuntimeException("should still be compiled");
81
        }
82

83
        try {
84
            test1(0, -10);
85
            throw new RuntimeException("exception not thrown");
86
        } catch (IndexOutOfBoundsException ioobe) {
87
        }
88
        if (WHITE_BOX.isMethodCompiled(m1)) {
89
            throw new RuntimeException("should have deoptimized");
90
        }
91
        try {
92
            test2(0, -10);
93
            throw new RuntimeException("exception not thrown");
94
        } catch (IndexOutOfBoundsException ioobe) {
95
        }
96
        if (WHITE_BOX.isMethodCompiled(m2)) {
97
            throw new RuntimeException("should have deoptimized");
98
        }
99

100
        try {
101
            test3(42, 10);
102
            throw new RuntimeException("exception not thrown");
103
        } catch (IndexOutOfBoundsException ioobe) {
104
        }
105
        if (WHITE_BOX.isMethodCompiled(m3)) {
106
            throw new RuntimeException("should have deoptimized");
107
        }
108
        try {
109
            test4(42, 10);
110
            throw new RuntimeException("exception not thrown");
111
        } catch (IndexOutOfBoundsException ioobe) {
112
        }
113
        if (WHITE_BOX.isMethodCompiled(m4)) {
114
            throw new RuntimeException("should have deoptimized");
115
        }
116
    }
117

118
    static int test1(int index, int length) {
119
        return Objects.checkIndex(index, length);
120
    }
121

122
    static long test2(long index, long length) {
123
        return Objects.checkIndex(index, length);
124
    }
125

126
    static int test3(int index, int length) {
127
        return Objects.checkIndex(index, length);
128
    }
129

130
    static long test4(long index, long length) {
131
        return Objects.checkIndex(index, length);
132
    }
133
}
134

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

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

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

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