Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/mathexact/AddExactIRepeatTest.java
41153 views
/*1* Copyright (c) 2013, 2020, 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*/2223/*24* @test25* @key randomness26* @bug 802565727* @summary Test repeating addExact28* @library /test/lib /29* @modules java.base/jdk.internal.misc30* java.management31*32* @run main compiler.intrinsics.mathexact.AddExactIRepeatTest33*/3435package compiler.intrinsics.mathexact;3637import jdk.test.lib.Utils;3839import java.util.Random;4041public class AddExactIRepeatTest {42public static void main(String[] args) {43runTest(new Verify.AddExactI());44}4546public static int nonExact(int x, int y, Verify.BinaryMethod method) {47int result = method.unchecked(x, y);48result += method.unchecked(x, y);49result += method.unchecked(x, y);50result += method.unchecked(x, y);51return result;52}5354public static void runTest(Verify.BinaryMethod method) {55Random rnd = Utils.getRandomInstance();56for (int i = 0; i < 50000; ++i) {57int x = Integer.MAX_VALUE - 10;58int y = Integer.MAX_VALUE - 10 + rnd.nextInt(5);5960int c = rnd.nextInt() / 2;61int d = rnd.nextInt() / 2;6263int a = catchingExact(x, y, method);6465if (a != 36) {66throw new RuntimeException("a != 36 : " + a);67}6869int b = nonExact(c, d, method);70int n = exact(c, d, method);717273if (n != b) {74throw new RuntimeException("n != b : " + n + " != " + b);75}76}77}7879public static int exact(int x, int y, Verify.BinaryMethod method) {80int result = 0;81result += method.checkMethod(x, y);82result += method.checkMethod(x, y);83result += method.checkMethod(x, y);84result += method.checkMethod(x, y);85return result;86}8788public static int catchingExact(int x, int y, Verify.BinaryMethod method) {89int result = 0;90try {91result += 5;92result = method.checkMethod(x, y);93} catch (ArithmeticException e) {94result += 1;95}96try {97result += 6;9899result += method.checkMethod(x, y);100} catch (ArithmeticException e) {101result += 2;102}103try {104result += 7;105result += method.checkMethod(x, y);106} catch (ArithmeticException e) {107result += 3;108}109try {110result += 8;111result += method.checkMethod(x, y);112} catch (ArithmeticException e) {113result += 4;114}115return result;116}117}118119120