Path: blob/master/test/hotspot/jtreg/compiler/loopopts/TestDivZeroCheckControl.java
41149 views
/*1* Copyright (c) 2019, 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*22*/2324/*25* @test26* @bug 822949627* @summary Verify that zero check is executed before division/modulo operation.28* @requires vm.compiler2.enabled29* @run main/othervm -Xbatch -XX:LoopUnrollLimit=030* -XX:CompileCommand=dontinline,compiler.loopopts.TestDivZeroCheckControl::test*31* compiler.loopopts.TestDivZeroCheckControl32*/3334/*35* @test36* @summary Verify that zero check is executed before division/modulo operation.37* @requires vm.graal.enabled38* @run main/othervm -Xbatch39* -XX:CompileCommand=dontinline,compiler.loopopts.TestDivZeroCheckControl::test*40* compiler.loopopts.TestDivZeroCheckControl41*/4243package compiler.loopopts;4445public class TestDivZeroCheckControl {4647public static int test1(int div, int array[]) {48int res = 0;49for (int i = 0; i < 256; i++) {50int j = 0;51do {52array[i] = i;53try {54res = 1 % div;55} catch (ArithmeticException ex) { }56} while (++j < 9);57}58return res;59}6061// Same as test1 but with division instead of modulo62public static int test2(int div, int array[]) {63int res = 0;64for (int i = 0; i < 256; i++) {65int j = 0;66do {67array[i] = i;68try {69res = 1 / div;70} catch (ArithmeticException ex) { }71} while (++j < 9);72}73return res;74}7576// Same as test1 but with long77public static long test3(long div, int array[]) {78long res = 0;79for (int i = 0; i < 256; i++) {80int j = 0;81do {82array[i] = i;83try {84res = 1L % div;85} catch (ArithmeticException ex) { }86} while (++j < 9);87}88return res;89}9091// Same as test2 but with long92public static long test4(long div, int array[]) {93long res = 0;94for (int i = 0; i < 256; i++) {95int j = 0;96do {97array[i] = i;98try {99res = 1L / div;100} catch (ArithmeticException ex) { }101} while (++j < 9);102}103return res;104}105106public static void main(String[] args) {107int array[] = new int[256];108for (int i = 0; i < 50_000; ++i) {109test1(0, array);110test2(0, array);111test3(0, array);112test4(0, array);113}114}115}116117118