Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/TestCheckIndex.java
41152 views
/*1* Copyright (c) 2020, Red Hat, Inc. 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 825515026* @summary Add utility methods to check long indexes and ranges27* @requires vm.compiler2.enabled28* @requires vm.compMode != "Xcomp"29* @library /test/lib /30* @build sun.hotspot.WhiteBox31* @run driver jdk.test.lib.helpers.ClassFileInstaller sun.hotspot.WhiteBox32*33* @run main/othervm -ea -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -XX:-BackgroundCompilation TestCheckIndex34*35*/3637import java.util.Objects;38import sun.hotspot.WhiteBox;39import java.lang.reflect.Method;40import compiler.whitebox.CompilerWhiteBoxTest;4142public class TestCheckIndex {43private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();4445public static void main(String[] args) throws NoSuchMethodException {46Objects.checkIndex(0, 10); // Load class47Method m1 = TestCheckIndex.class.getDeclaredMethod("test1", int.class, int.class);48Method m2 = TestCheckIndex.class.getDeclaredMethod("test2", long.class, long.class);49Method m3 = TestCheckIndex.class.getDeclaredMethod("test3", int.class, int.class);50Method m4 = TestCheckIndex.class.getDeclaredMethod("test4", long.class, long.class);51assert m1 != null && m2 != null && m3 != null && m4 != null;52WHITE_BOX.enqueueMethodForCompilation(m1, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);53if (!WHITE_BOX.isMethodCompiled(m1)) {54throw new RuntimeException("should be compiled");55}56WHITE_BOX.enqueueMethodForCompilation(m2, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);57if (!WHITE_BOX.isMethodCompiled(m2)) {58throw new RuntimeException("should be compiled");59}60WHITE_BOX.enqueueMethodForCompilation(m3, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);61if (!WHITE_BOX.isMethodCompiled(m3)) {62throw new RuntimeException("should be compiled");63}64WHITE_BOX.enqueueMethodForCompilation(m4, CompilerWhiteBoxTest.COMP_LEVEL_FULL_OPTIMIZATION);65if (!WHITE_BOX.isMethodCompiled(m4)) {66throw new RuntimeException("should be compiled");67}6869if (test1(0, 10) != 0) {70throw new RuntimeException("incorrect result");71}72if (!WHITE_BOX.isMethodCompiled(m1)) {73throw new RuntimeException("should still be compiled");74}75if (test2(0, 10) != 0) {76throw new RuntimeException("incorrect result");77}78if (!WHITE_BOX.isMethodCompiled(m2)) {79throw new RuntimeException("should still be compiled");80}8182try {83test1(0, -10);84throw new RuntimeException("exception not thrown");85} catch (IndexOutOfBoundsException ioobe) {86}87if (WHITE_BOX.isMethodCompiled(m1)) {88throw new RuntimeException("should have deoptimized");89}90try {91test2(0, -10);92throw new RuntimeException("exception not thrown");93} catch (IndexOutOfBoundsException ioobe) {94}95if (WHITE_BOX.isMethodCompiled(m2)) {96throw new RuntimeException("should have deoptimized");97}9899try {100test3(42, 10);101throw new RuntimeException("exception not thrown");102} catch (IndexOutOfBoundsException ioobe) {103}104if (WHITE_BOX.isMethodCompiled(m3)) {105throw new RuntimeException("should have deoptimized");106}107try {108test4(42, 10);109throw new RuntimeException("exception not thrown");110} catch (IndexOutOfBoundsException ioobe) {111}112if (WHITE_BOX.isMethodCompiled(m4)) {113throw new RuntimeException("should have deoptimized");114}115}116117static int test1(int index, int length) {118return Objects.checkIndex(index, length);119}120121static long test2(long index, long length) {122return Objects.checkIndex(index, length);123}124125static int test3(int index, int length) {126return Objects.checkIndex(index, length);127}128129static long test4(long index, long length) {130return Objects.checkIndex(index, length);131}132}133134135