8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow"
authoriveresov
Tue, 15 Jan 2019 10:40:32 -0800
changeset 53309 314c5b5d9369
parent 53308 1884ecc20c38
child 53310 8ce4083fc831
8196568: [Graal] LongMulOverflowTest.java fails with "runTestOverflow() did not overflow" Summary: Temporarily cripple j.l.Math.*Exact() instrinsics to pass TCK Reviewed-by: kvn, dlong, never
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.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.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	Tue Dec 18 10:12:28 2018 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactExceptionTest.java	Tue Jan 15 10:40:32 2019 -0800
@@ -86,6 +86,46 @@
         }
     }
 
+    public void testIntegerExactOverflowWithoutUse1(int input) {
+        Math.addExact(intCounter, input);
+    }
+
+    public void testIntegerExactOverflowWithoutUse2(int input, boolean cond) {
+        if (cond) {
+            Math.addExact(intCounter, input);
+        } else {
+            intCounter = Math.addExact(intCounter, input);
+        }
+    }
+
+    @Test
+    public void testIntegerExactWithoutUse1() throws InvalidInstalledCodeException {
+        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse1");
+        InstalledCode code = getCode(method);
+
+        boolean gotException = false;
+        try {
+            code.executeVarargs(this, Integer.MAX_VALUE);
+        } catch (ArithmeticException e) {
+            gotException = true;
+        }
+        assertTrue(gotException);
+    }
+
+    @Test
+    public void testIntegerExactWithoutUse2() throws InvalidInstalledCodeException {
+        ResolvedJavaMethod method = getResolvedJavaMethod("testIntegerExactOverflowWithoutUse2");
+        InstalledCode code = getCode(method);
+
+        boolean gotException = false;
+        try {
+            code.executeVarargs(this, Integer.MAX_VALUE, true);
+        } catch (ArithmeticException e) {
+            gotException = true;
+        }
+        assertTrue(gotException);
+    }
+
     static long longCounter = 10;
 
     public void testLongExactOverflowSnippet(long input) {
@@ -138,4 +178,44 @@
             assertTrue(code.isValid());
         }
     }
+
+    public void testLongExactOverflowWithoutUse1(long input) {
+        Math.addExact(longCounter, input);
+    }
+
+    public void testLongExactOverflowWithoutUse2(long input, boolean cond) {
+        if (cond) {
+            Math.addExact(longCounter, input);
+        } else {
+            longCounter = Math.addExact(longCounter, input);
+        }
+    }
+
+    @Test
+    public void testLongExactWithoutUse1() throws InvalidInstalledCodeException {
+        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse1");
+        InstalledCode code = getCode(method);
+
+        boolean gotException = false;
+        try {
+            code.executeVarargs(this, Long.MAX_VALUE);
+        } catch (ArithmeticException e) {
+            gotException = true;
+        }
+        assertTrue(gotException);
+    }
+
+    @Test
+    public void testLongExactWithoutUse2() throws InvalidInstalledCodeException {
+        ResolvedJavaMethod method = getResolvedJavaMethod("testLongExactOverflowWithoutUse2");
+        InstalledCode code = getCode(method);
+
+        boolean gotException = false;
+        try {
+            code.executeVarargs(this, Long.MAX_VALUE, true);
+        } catch (ArithmeticException e) {
+            gotException = true;
+        }
+        assertTrue(gotException);
+    }
 }
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java	Tue Dec 18 10:12:28 2018 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements.test/src/org/graalvm/compiler/replacements/test/IntegerExactFoldTest.java	Tue Jan 15 10:40:32 2019 -0800
@@ -50,11 +50,13 @@
 import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticNode;
 import org.graalvm.compiler.replacements.nodes.arithmetic.IntegerExactArithmeticSplitNode;
 import org.junit.Assert;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 import org.junit.runners.Parameterized.Parameters;
 
+@Ignore
 @RunWith(Parameterized.class)
 public class IntegerExactFoldTest extends GraalCompilerTest {
     private final long lowerBoundA;
--- a/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Tue Dec 18 10:12:28 2018 +0100
+++ b/src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/StandardGraphBuilderPlugins.java	Tue Jan 15 10:40:32 2019 -0800
@@ -559,26 +559,19 @@
         }
     }
 
-    private static void createIntegerExactOperation(GraphBuilderContext b, JavaKind kind, ValueNode x, ValueNode y, IntegerExactOp op) {
-        if (b.needsExplicitException()) {
+    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));
+            return true;
+        } else {
             BytecodeExceptionKind exceptionKind = kind == JavaKind.Int ? BytecodeExceptionKind.INTEGER_EXACT_OVERFLOW : BytecodeExceptionKind.LONG_EXACT_OVERFLOW;
             AbstractBeginNode exceptionEdge = b.genExplicitExceptionEdge(exceptionKind);
-            IntegerExactArithmeticSplitNode split = b.addPush(kind, createIntegerExactSplit(x, y, exceptionEdge, op));
-            split.setNext(b.add(new BeginNode()));
-        } else {
-            SpeculationLog log = b.getGraph().getSpeculationLog();
-            if (log == null || (x.isConstant() && y.isConstant())) {
-                b.addPush(kind, createIntegerExactArithmeticNode(x, y, null, op));
-            } else {
-                SpeculationReason speculation = new IntegerExactOpSpeculation(b.getMethod(), op);
-                if (log.maySpeculate(speculation)) {
-                    b.addPush(kind, createIntegerExactArithmeticNode(x, y, speculation, op));
-                } else {
-                    BeginNode begin = b.add(new BeginNode());
-                    IntegerExactArithmeticNode node = (IntegerExactArithmeticNode) b.addPush(kind, createIntegerExactArithmeticNode(x, y, null, op));
-                    node.setAnchor(begin);
-                }
+            if (exceptionEdge != null) {
+                IntegerExactArithmeticSplitNode split = b.addPush(kind, createIntegerExactSplit(x, y, exceptionEdge, op));
+                split.setNext(b.add(new BeginNode()));
+                return true;
             }
+            return false;
         }
     }
 
@@ -592,8 +585,7 @@
                     @Override
                     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                         ConstantNode y = b.add(ConstantNode.forIntegerKind(kind, 1));
-                        createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_DECREMENT_EXACT);
-                        return true;
+                        return createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_DECREMENT_EXACT);
                     }
                 });
 
@@ -601,33 +593,29 @@
                     @Override
                     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                         ConstantNode y = b.add(ConstantNode.forIntegerKind(kind, 1));
-                        createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_INCREMENT_EXACT);
-                        return true;
+                        return createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_INCREMENT_EXACT);
                     }
                 });
 
                 r.register2("addExact", type, type, new InvocationPlugin() {
                     @Override
                     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
-                        createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_ADD_EXACT);
-                        return true;
+                        return createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_ADD_EXACT);
                     }
                 });
 
                 r.register2("subtractExact", type, type, new InvocationPlugin() {
                     @Override
                     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
-                        createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_SUBTRACT_EXACT);
-                        return true;
+                        return createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_SUBTRACT_EXACT);
                     }
                 });
 
                 r.register2("multiplyExact", type, type, new InvocationPlugin() {
                     @Override
                     public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
-                        createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_MULTIPLY_EXACT);
-                        return true;
-                    }
+                        return createIntegerExactOperation(b, kind, x, y, IntegerExactOp.INTEGER_MULTIPLY_EXACT);
+                     }
                 });
             }
         }