8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed
authoriveresov
Wed, 23 Jan 2019 16:57:01 -0800
changeset 53495 b693b0d2053d
parent 53494 8fd43dacaef7
child 53496 7ba8ce465804
8217678: [AOT] jck Math/IncrementExact and Math/DecrementExact tests fail when test classes are AOTed Reviewed-by: kvn
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java
src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java	Wed Jan 23 16:36:45 2019 -0800
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java	Wed Jan 23 16:57:01 2019 -0800
@@ -98,6 +98,10 @@
         }
     }
 
+    public void testIntegerExactOverflowWithoutUse3() {
+        Math.addExact(Integer.MAX_VALUE, 1);
+    }
+
     @Test
     public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException {
         ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1");
@@ -126,6 +130,20 @@
         assertTrue(gotException);
     }
 
+    @Test
+    public void testIntegerExactWithoutUse3() throws InvalidInstalledCodeException {
+        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse3");
+        InstalledCode code = getCode(method);
+
+        boolean gotException = false;
+        try {
+            code.executeVarargs(this);
+        } catch (ArithmeticException e) {
+            gotException = true;
+        }
+        assertTrue(gotException);
+    }
+
     static long longCounter = 10;
 
     public void testLongExactOverflowSnippet(long input) {
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Wed Jan 23 16:36:45 2019 -0800
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Wed Jan 23 16:57:01 2019 -0800
@@ -560,19 +560,14 @@
     }
 
     private static boolean createIntegerExactOperation(GraphBuilderContext b, JavaKind kind, ValueNode x, ValueNode y, IntegerExactOp op) {
-        if (x.isConstant() && y.isConstant()) {
-            b.addPush(kind, createIntegerExactArithmeticNode(x, y, null, op));
+        BytecodeExceptionKind exceptionKind = kind == JavaKind.Int ? BytecodeExceptionKind.INTEGER_EXACT_OVERFLOW : BytecodeExceptionKind.LONG_EXACT_OVERFLOW;
+        AbstractBeginNode exceptionEdge = b.genExplicitExceptionEdge(exceptionKind);
+        if (exceptionEdge != null) {
+            IntegerExactArithmeticSplitNode split = b.addPush(kind, createIntegerExactSplit(x, y, exceptionEdge, op));
+            split.setNext(b.add(new BeginNode()));
             return true;
-        } else {
-            BytecodeExceptionKind exceptionKind = kind == JavaKind.Int ? BytecodeExceptionKind.INTEGER_EXACT_OVERFLOW : BytecodeExceptionKind.LONG_EXACT_OVERFLOW;
-            AbstractBeginNode exceptionEdge = b.genExplicitExceptionEdge(exceptionKind);
-            if (exceptionEdge != null) {
-                IntegerExactArithmeticSplitNode split = b.addPush(kind, createIntegerExactSplit(x, y, exceptionEdge, op));
-                split.setNext(b.add(new BeginNode()));
-                return true;
-            }
-            return false;
         }
+        return false;
     }
 
     private static void registerMathPlugins(InvocationPlugins plugins, boolean allowDeoptimization) {