Path: blob/master/test/hotspot/jtreg/compiler/intrinsics/mathexact/sanity/MathIntrinsic.java
41159 views
/*1* Copyright (c) 2013, 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*/2223package compiler.intrinsics.mathexact.sanity;2425import compiler.whitebox.CompilerWhiteBoxTest;2627import java.lang.reflect.Executable;28import java.util.concurrent.Callable;2930public class MathIntrinsic {3132enum IntIntrinsic implements CompilerWhiteBoxTest.TestCase {33Add {34@Override35Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {36return Class.forName("java.lang.Math").getDeclaredMethod("addExact", int.class, int.class);37}3839@Override40Object execMathMethod() {41return intR = Math.addExact(int1, int2);42}43},44Subtract {45@Override46Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {47return Class.forName("java.lang.Math").getDeclaredMethod("subtractExact", int.class, int.class);48}4950@Override51Object execMathMethod() {52return intR = Math.subtractExact(int1, int2);53}54},55Multiply {56@Override57Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {58return Class.forName("java.lang.Math").getDeclaredMethod("multiplyExact", int.class, int.class);59}6061@Override62Object execMathMethod() {63return intR = Math.multiplyExact(int1, int2);64}65},66Increment {67@Override68Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {69return Class.forName("java.lang.Math").getDeclaredMethod("incrementExact", int.class);70}7172@Override73Object execMathMethod() {74return intR = Math.incrementExact(int1);75}76},77Decrement {78@Override79Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {80return Class.forName("java.lang.Math").getDeclaredMethod("decrementExact", int.class);81}8283@Override84Object execMathMethod() {85return intR = Math.decrementExact(int1);86}87},88Negate {89@Override90Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {91return Class.forName("java.lang.Math").getDeclaredMethod("negateExact", int.class);92}9394@Override95Object execMathMethod() {96return intR = Math.negateExact(int1);97}98};99100protected int int1;101protected int int2;102protected int intR;103104abstract Executable testMethod() throws NoSuchMethodException, ClassNotFoundException;105abstract Object execMathMethod();106107public Executable getTestMethod() {108try {109return testMethod();110} catch (NoSuchMethodException e) {111throw new RuntimeException("Test bug, no such method: " + e);112} catch (ClassNotFoundException e) {113throw new RuntimeException("Test bug, no such class: " + e);114}115}116117@Override118public Executable getExecutable() {119try {120return getClass().getDeclaredMethod("execMathMethod");121} catch (NoSuchMethodException e) {122throw new RuntimeException("Test bug, no such method: " + e);123}124}125126@Override127public Callable<Integer> getCallable() {128return null;129}130131@Override132public boolean isOsr() {133return false;134}135136}137138enum LongIntrinsic implements CompilerWhiteBoxTest.TestCase {139Add {140@Override141Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {142return Class.forName("java.lang.Math").getDeclaredMethod("addExact", long.class, long.class);143}144145@Override146Object execMathMethod() {147return longR = Math.addExact(long1, long2);148}149},150Subtract {151@Override152Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {153return Class.forName("java.lang.Math").getDeclaredMethod("subtractExact", long.class, long.class);154}155156@Override157Object execMathMethod() {158return longR = Math.subtractExact(long1, long2);159}160},161Multiply {162@Override163Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {164return Class.forName("java.lang.Math").getDeclaredMethod("multiplyExact", long.class, long.class);165}166167@Override168Object execMathMethod() {169return longR = Math.multiplyExact(long1, long2);170}171},172Increment {173@Override174Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {175return Class.forName("java.lang.Math").getDeclaredMethod("incrementExact", long.class);176}177178@Override179Object execMathMethod() {180return longR = Math.incrementExact(long1);181}182},183Decrement {184@Override185Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {186return Class.forName("java.lang.Math").getDeclaredMethod("decrementExact", long.class);187}188189@Override190Object execMathMethod() {191return longR = Math.decrementExact(long1);192}193},194Negate {195@Override196Executable testMethod() throws NoSuchMethodException, ClassNotFoundException {197return Class.forName("java.lang.Math").getDeclaredMethod("negateExact", long.class);198}199200@Override201Object execMathMethod() {202return longR = Math.negateExact(long1);203}204};205protected long long1;206protected long long2;207protected long longR;208209abstract Executable testMethod() throws NoSuchMethodException, ClassNotFoundException;210abstract Object execMathMethod();211212public Executable getTestMethod() {213try {214return testMethod();215} catch (NoSuchMethodException e) {216throw new RuntimeException("Test bug, no such method: " + e);217} catch (ClassNotFoundException e) {218throw new RuntimeException("Test bug, no such class: " + e);219}220}221222@Override223public Executable getExecutable() {224try {225return getClass().getDeclaredMethod("execMathMethod");226} catch (NoSuchMethodException e) {227throw new RuntimeException("Test bug, no such method: " + e);228}229}230231@Override232public Callable<Integer> getCallable() {233return null;234}235236@Override237public boolean isOsr() {238return false;239}240}241}242243244