From 77cda9cec59f5fa903cedc1369c6cd581c159803 Mon Sep 17 00:00:00 2001 From: iignatyev Date: Tue, 31 Dec 2013 19:26:57 +0400 Subject: 8028587: New tests development for intrisics for basic operators - add, neg, inc, dec, sub, mul Reviewed-by: twisti Contributed-by: anton.ivanov@oracle.com --- .../mathexact/sanity/AddExactIntTest.java | 45 ++++++ .../mathexact/sanity/AddExactLongTest.java | 45 ++++++ .../mathexact/sanity/DecrementExactIntTest.java | 45 ++++++ .../mathexact/sanity/DecrementExactLongTest.java | 45 ++++++ .../mathexact/sanity/IncrementExactIntTest.java | 45 ++++++ .../mathexact/sanity/IncrementExactLongTest.java | 45 ++++++ .../intrinsics/mathexact/sanity/IntrinsicBase.java | 155 +++++++++++++++++++++ .../intrinsics/mathexact/sanity/MathIntrinsic.java | 155 +++++++++++++++++++++ .../mathexact/sanity/MultiplyExactIntTest.java | 45 ++++++ .../mathexact/sanity/MultiplyExactLongTest.java | 45 ++++++ .../mathexact/sanity/NegateExactIntTest.java | 45 ++++++ .../mathexact/sanity/NegateExactLongTest.java | 45 ++++++ .../mathexact/sanity/SubtractExactIntTest.java | 46 ++++++ .../mathexact/sanity/SubtractExactLongTest.java | 45 ++++++ .../intrinsics/mathexact/sanity/Verifier.java | 71 ++++++++++ 15 files changed, 922 insertions(+) create mode 100644 test/compiler/intrinsics/mathexact/sanity/AddExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/AddExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/DecrementExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/DecrementExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/IncrementExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/IncrementExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/MathIntrinsic.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/MultiplyExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/MultiplyExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/NegateExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/NegateExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/SubtractExactIntTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/SubtractExactLongTest.java create mode 100644 test/compiler/intrinsics/mathexact/sanity/Verifier.java (limited to 'test/compiler/intrinsics/mathexact/sanity') diff --git a/test/compiler/intrinsics/mathexact/sanity/AddExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/AddExactIntTest.java new file mode 100644 index 000000000..c55f847d2 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/AddExactIntTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build AddExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics AddExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics AddExactIntTest + * @run main Verifier hs_neg.log hs.log + */ + +public class AddExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Add).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/AddExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/AddExactLongTest.java new file mode 100644 index 000000000..4823f073f --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/AddExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build AddExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics AddExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics AddExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class AddExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Add).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/DecrementExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/DecrementExactIntTest.java new file mode 100644 index 000000000..0b97ab86a --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/DecrementExactIntTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build DecrementExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics DecrementExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics DecrementExactIntTest + * @run main Verifier hs_neg.log hs.log + */ + +public class DecrementExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Decrement).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/DecrementExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/DecrementExactLongTest.java new file mode 100644 index 000000000..f2429aa91 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/DecrementExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build DecrementExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics DecrementExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics DecrementExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class DecrementExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Decrement).test(); + } +} \ No newline at end of file diff --git a/test/compiler/intrinsics/mathexact/sanity/IncrementExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/IncrementExactIntTest.java new file mode 100644 index 000000000..714f4e2e0 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/IncrementExactIntTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build IncrementExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics IncrementExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics IncrementExactIntTest + * @run main Verifier hs_neg.log hs.log + */ + +public class IncrementExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Increment).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/IncrementExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/IncrementExactLongTest.java new file mode 100644 index 000000000..19511c499 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/IncrementExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build IncrementExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics IncrementExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics IncrementExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class IncrementExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Increment).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java b/test/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java new file mode 100644 index 000000000..cecd6ce2d --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/IntrinsicBase.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import com.oracle.java.testlibrary.Platform; + +import java.io.FileOutputStream; +import java.lang.reflect.Executable; +import java.util.Properties; + +public abstract class IntrinsicBase extends CompilerWhiteBoxTest { + protected String javaVmName; + protected String useMathExactIntrinsics; + + protected IntrinsicBase(TestCase testCase) { + super(testCase); + javaVmName = System.getProperty("java.vm.name"); + useMathExactIntrinsics = getVMOption("UseMathExactIntrinsics"); + } + + @Override + protected void test() throws Exception { + //java.lang.Math should be loaded to allow a compilation of the methods that use Math's method + System.out.println("class java.lang.Math should be loaded. Proof: " + Math.class); + printEnvironmentInfo(); + + int expectedIntrinsicCount = 0; + + switch (MODE) { + case "compiled mode": + case "mixed mode": + if (isServerVM()) { + if (TIERED_COMPILATION) { + int max_level = TIERED_STOP_AT_LEVEL; + expectedIntrinsicCount = (max_level == COMP_LEVEL_MAX) ? 1 : 0; + for (int i = CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE; i <= max_level; ++i) { + deoptimize(); + compileAtLevel(i); + } + } else { + expectedIntrinsicCount = 1; + deoptimize(); + compileAtLevel(CompilerWhiteBoxTest.COMP_LEVEL_MAX); + } + } else { + deoptimize(); + compileAtLevel(CompilerWhiteBoxTest.COMP_LEVEL_SIMPLE); + } + + if (!isIntrinsicSupported()) { + expectedIntrinsicCount = 0; + } + break; + case "interpreted mode": //test is not applicable in this mode; + System.err.println("Warning: This test is not applicable in mode: " + MODE); + break; + default: + throw new RuntimeException("Test bug, unknown VM mode: " + MODE); + } + + System.out.println("Expected intrinsic count is " + expectedIntrinsicCount + " name " + getIntrinsicId()); + + final FileOutputStream out = new FileOutputStream(getVMOption("LogFile") + ".verify.properties"); + Properties expectedProps = new Properties(); + expectedProps.setProperty("intrinsic.name", getIntrinsicId()); + expectedProps.setProperty("intrinsic.expectedCount", String.valueOf(expectedIntrinsicCount)); + expectedProps.store(out, null); + + out.close(); + } + + protected void printEnvironmentInfo() { + System.out.println("java.vm.name=" + javaVmName); + System.out.println("os.arch=" + Platform.getOsArch()); + System.out.println("java.vm.info=" + MODE); + System.out.println("useMathExactIntrinsics=" + useMathExactIntrinsics); + } + + protected void compileAtLevel(int level) { + WHITE_BOX.enqueueMethodForCompilation(method, level); + waitBackgroundCompilation(); + checkCompilation(method, level); + } + + protected void checkCompilation(Executable executable, int level) { + if (!WHITE_BOX.isMethodCompiled(executable)) { + throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but not compiled"); + } + final int compilationLevel = WHITE_BOX.getMethodCompilationLevel(executable); + if (compilationLevel != level) { + if (!(TIERED_COMPILATION && level == COMP_LEVEL_FULL_PROFILE && compilationLevel == COMP_LEVEL_LIMITED_PROFILE)) { //possible case + throw new RuntimeException("Test bug, expected compilation (level): " + level + ", but level: " + compilationLevel); + } + } + } + + protected abstract boolean isIntrinsicSupported(); + + protected abstract String getIntrinsicId(); + + protected boolean isServerVM() { + return javaVmName.toLowerCase().contains("server"); + } + + static class IntTest extends IntrinsicBase { + protected IntTest(MathIntrinsic.IntIntrinsic testCase) { + super(testCase); + } + + @Override + protected boolean isIntrinsicSupported() { + return isServerVM() && Boolean.valueOf(useMathExactIntrinsics) && (Platform.isX86() || Platform.isX64()); + } + + @Override + protected String getIntrinsicId() { + return "_" + testCase.name().toLowerCase() + "ExactI"; + } + } + + static class LongTest extends IntrinsicBase { + protected LongTest(MathIntrinsic.LongIntrinsic testCase) { + super(testCase); + } + + @Override + protected boolean isIntrinsicSupported() { + return isServerVM() && Boolean.valueOf(useMathExactIntrinsics) && Platform.isX64(); + } + + @Override + protected String getIntrinsicId() { + return "_" + testCase.name().toLowerCase() + "ExactL"; + } + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/MathIntrinsic.java b/test/compiler/intrinsics/mathexact/sanity/MathIntrinsic.java new file mode 100644 index 000000000..99039f9a7 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/MathIntrinsic.java @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.lang.reflect.Executable; +import java.util.concurrent.Callable; + +public class MathIntrinsic { + + enum IntIntrinsic implements CompilerWhiteBoxTest.TestCase { + Add { + @Override + Object execMathMethod() { + return intR = Math.addExact(int1, int2); + } + }, + Subtract { + @Override + Object execMathMethod() { + return intR = Math.subtractExact(int1, int2); + } + }, + Multiply { + @Override + Object execMathMethod() { + return intR = Math.multiplyExact(int1, int2); + } + }, + Increment { + @Override + Object execMathMethod() { + return intR = Math.incrementExact(int1); + } + }, + Decrement { + @Override + Object execMathMethod() { + return intR = Math.decrementExact(int1); + } + }, + Negate { + @Override + Object execMathMethod() { + return intR = Math.negateExact(int1); + } + }; + protected int int1; + protected int int2; + protected int intR; + + abstract Object execMathMethod(); + + @Override + public Executable getExecutable() { + try { + return getClass().getDeclaredMethod("execMathMethod"); + } catch (NoSuchMethodException e) { + throw new RuntimeException("Test bug, no such method: " + e); + } + } + + @Override + public Callable getCallable() { + return null; + } + + @Override + public boolean isOsr() { + return false; + } + + } + + enum LongIntrinsic implements CompilerWhiteBoxTest.TestCase { + Add { + @Override + Object execMathMethod() { + return longR = Math.addExact(long1, long2); + } + }, + Subtract { + @Override + Object execMathMethod() { + return longR = Math.subtractExact(long1, long2); + } + }, + Multiply { + @Override + Object execMathMethod() { + return longR = Math.multiplyExact(long1, long2); + } + }, + Increment { + @Override + Object execMathMethod() { + return longR = Math.incrementExact(long1); + } + }, + Decrement { + @Override + Object execMathMethod() { + return longR = Math.decrementExact(long1); + } + }, + Negate { + @Override + Object execMathMethod() { + return longR = Math.negateExact(long1); + } + }; + protected long long1; + protected long long2; + protected long longR; + + abstract Object execMathMethod(); + + @Override + public Executable getExecutable() { + try { + return getClass().getDeclaredMethod("execMathMethod"); + } catch (NoSuchMethodException e) { + throw new RuntimeException("Test bug, no such method: " + e); + } + } + + @Override + public Callable getCallable() { + return null; + } + + @Override + public boolean isOsr() { + return false; + } + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/MultiplyExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/MultiplyExactIntTest.java new file mode 100644 index 000000000..bd4335001 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/MultiplyExactIntTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build MultiplyExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics MultiplyExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics MultiplyExactIntTest + * @run main Verifier hs_neg.log hs.log + */ + +public class MultiplyExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Multiply).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/MultiplyExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/MultiplyExactLongTest.java new file mode 100644 index 000000000..70651107d --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/MultiplyExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build MultiplyExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics MultiplyExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics MultiplyExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class MultiplyExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Multiply).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/NegateExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/NegateExactIntTest.java new file mode 100644 index 000000000..579c2907e --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/NegateExactIntTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build NegateExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics NegateExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics NegateExactIntTest + * @run main Verifier hs_neg.log hs.log + */ + +public class NegateExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Negate).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/NegateExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/NegateExactLongTest.java new file mode 100644 index 000000000..6f114f632 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/NegateExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build NegateExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics NegateExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics NegateExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class NegateExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Negate).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/SubtractExactIntTest.java b/test/compiler/intrinsics/mathexact/sanity/SubtractExactIntTest.java new file mode 100644 index 000000000..d1eaf3919 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/SubtractExactIntTest.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build SubtractExactIntTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics SubtractExactIntTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics SubtractExactIntTest + * @run main Verifier hs_neg.log hs.log + + */ + +public class SubtractExactIntTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.IntTest(MathIntrinsic.IntIntrinsic.Subtract).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/SubtractExactLongTest.java b/test/compiler/intrinsics/mathexact/sanity/SubtractExactLongTest.java new file mode 100644 index 000000000..fbe8eb1e1 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/SubtractExactLongTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @library /testlibrary /testlibrary/whitebox /compiler/whitebox + * @build SubtractExactLongTest + * @run main ClassFileInstaller sun.hotspot.WhiteBox + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs_neg.log -XX:-UseMathExactIntrinsics SubtractExactLongTest + * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:+UnlockExperimentalVMOptions + * -XX:+IgnoreUnrecognizedVMOptions -XX:+WhiteBoxAPI -XX:+LogCompilation + * -XX:CompileCommand=compileonly,MathIntrinsic*::execMathMethod + * -XX:LogFile=hs.log -XX:+UseMathExactIntrinsics SubtractExactLongTest + * @run main Verifier hs_neg.log hs.log + */ + +public class SubtractExactLongTest { + + public static void main(String[] args) throws Exception { + new IntrinsicBase.LongTest(MathIntrinsic.LongIntrinsic.Subtract).test(); + } +} diff --git a/test/compiler/intrinsics/mathexact/sanity/Verifier.java b/test/compiler/intrinsics/mathexact/sanity/Verifier.java new file mode 100644 index 000000000..7b26d64c6 --- /dev/null +++ b/test/compiler/intrinsics/mathexact/sanity/Verifier.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import java.io.BufferedReader; +import java.io.FileReader; +import java.util.Properties; + +public class Verifier { + + public static void main(String[] args) throws Exception { + if (args.length == 0) + throw new RuntimeException("Test bug, nothing to verify"); + for (String hsLogFile : args) { + verify(hsLogFile); + } + } + + private static void verify(String hsLogFile) throws Exception { + System.out.println("Verifying " + hsLogFile); + + final Properties expectedProperties = new Properties(); + final FileReader reader = new FileReader(hsLogFile + ".verify.properties"); + expectedProperties.load(reader); + reader.close(); + + int fullMatchCnt = 0; + int suspectCnt = 0; + final String intrinsicId = expectedProperties.getProperty("intrinsic.name"); + final String prefix = "