2
* Copyright (c) 2020, Red Hat, Inc. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
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
34
* @run main/othervm -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation TestCheckIndex
38
import java.util.Objects;
39
import jdk.test.whitebox.WhiteBox;
40
import java.lang.reflect.Method;
41
import compiler.whitebox.CompilerWhiteBoxTest;
43
public class TestCheckIndex {
44
private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
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");
57
WHITE_BOX.enqueueMethodForCompilation(m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
58
if (!WHITE_BOX.isMethodCompiled(m2)) {
59
throw new RuntimeException("should be compiled");
61
WHITE_BOX.enqueueMethodForCompilation(m3, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
62
if (!WHITE_BOX.isMethodCompiled(m3)) {
63
throw new RuntimeException("should be compiled");
65
WHITE_BOX.enqueueMethodForCompilation(m4, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);
66
if (!WHITE_BOX.isMethodCompiled(m4)) {
67
throw new RuntimeException("should be compiled");
70
if (test1(0, 10) != 0) {
71
throw new RuntimeException("incorrect result");
73
if (!WHITE_BOX.isMethodCompiled(m1)) {
74
throw new RuntimeException("should still be compiled");
76
if (test2(0, 10) != 0) {
77
throw new RuntimeException("incorrect result");
79
if (!WHITE_BOX.isMethodCompiled(m2)) {
80
throw new RuntimeException("should still be compiled");
85
throw new RuntimeException("exception not thrown");
86
} catch (IndexOutOfBoundsException ioobe) {
88
if (WHITE_BOX.isMethodCompiled(m1)) {
89
throw new RuntimeException("should have deoptimized");
93
throw new RuntimeException("exception not thrown");
94
} catch (IndexOutOfBoundsException ioobe) {
96
if (WHITE_BOX.isMethodCompiled(m2)) {
97
throw new RuntimeException("should have deoptimized");
102
throw new RuntimeException("exception not thrown");
103
} catch (IndexOutOfBoundsException ioobe) {
105
if (WHITE_BOX.isMethodCompiled(m3)) {
106
throw new RuntimeException("should have deoptimized");
110
throw new RuntimeException("exception not thrown");
111
} catch (IndexOutOfBoundsException ioobe) {
113
if (WHITE_BOX.isMethodCompiled(m4)) {
114
throw new RuntimeException("should have deoptimized");
118
static int test1(int index, int length) {
119
return Objects.checkIndex(index, length);
122
static long test2(long index, long length) {
123
return Objects.checkIndex(index, length);
126
static int test3(int index, int length) {
127
return Objects.checkIndex(index, length);
130
static long test4(long index, long length) {
131
return Objects.checkIndex(index, length);