changeset 19738:2bad5984e4fe

Evaluate neverPartOfCompilation assertion only after partial escape analysis and conditional elimination. Create explicit SourceStackTrace exception. Add neverPartOfCompilation unit test.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 09 Mar 2015 21:07:38 +0100
parents de35dd773272
children 17229e8fad57
files graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/SourceStackTrace.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/NeverPartOfCompilationTestNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java
diffstat 6 files changed, 134 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/SourceStackTrace.java	Mon Mar 09 21:07:38 2015 +0100
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2015, 2015, 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.
+ */
+package com.oracle.graal.api.code;
+
+/**
+ * Class representing a exception with a stack trace of the currently processed position in the
+ * compiled Java program instead of the stack trace of the compiler. The exception of the compiler
+ * is saved as the cause of this exception.
+ */
+public abstract class SourceStackTrace extends BailoutException {
+    private static final long serialVersionUID = 2144811793442316776L;
+
+    public static SourceStackTrace create(Throwable cause, String format, StackTraceElement[] elements) {
+        return new SourceStackTrace(cause, format) {
+
+            private static final long serialVersionUID = 6279381376051787907L;
+
+            @Override
+            public final synchronized Throwable fillInStackTrace() {
+                assert elements != null;
+                setStackTrace(elements);
+                return this;
+            }
+        };
+    }
+
+    private SourceStackTrace(Throwable cause, String format) {
+        super(cause, format);
+    }
+}
--- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Mon Mar 09 18:11:19 2015 +0100
+++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/util/GraphUtil.java	Mon Mar 09 21:07:38 2015 +0100
@@ -298,36 +298,7 @@
      * @return the exception
      */
     public static BailoutException createBailoutException(String message, Throwable cause, StackTraceElement[] elements) {
-        @SuppressWarnings("serial")
-        BailoutException exception = new BailoutException(cause, message) {
-
-            @Override
-            public final synchronized Throwable fillInStackTrace() {
-                setStackTrace(elements);
-                return this;
-            }
-        };
-        return exception;
-    }
-
-    /**
-     * Creates a runtime exception with the given stack trace elements and message.
-     *
-     * @param message the message of the exception
-     * @param elements the stack trace elements
-     * @return the exception
-     */
-    public static RuntimeException createRuntimeException(String message, Throwable cause, StackTraceElement[] elements) {
-        @SuppressWarnings("serial")
-        RuntimeException exception = new RuntimeException(message, cause) {
-
-            @Override
-            public final synchronized Throwable fillInStackTrace() {
-                setStackTrace(elements);
-                return this;
-            }
-        };
-        return exception;
+        return SourceStackTrace.create(cause, message, elements);
     }
 
     /**
--- a/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java	Mon Mar 09 18:11:19 2015 +0100
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/SimplePartialEvaluationTest.java	Mon Mar 09 21:07:38 2015 +0100
@@ -24,6 +24,7 @@
 
 import org.junit.*;
 
+import com.oracle.graal.api.code.*;
 import com.oracle.graal.truffle.test.nodes.*;
 import com.oracle.truffle.api.frame.*;
 
@@ -48,10 +49,29 @@
     }
 
     @Test
+    public void neverPartOfCompilationTest() {
+        FrameDescriptor fd = new FrameDescriptor();
+        AbstractTestNode firstTree = new NeverPartOfCompilationTestNode(new ConstantTestNode(1), 2);
+        assertPartialEvalEquals("constant42", new RootTestNode(fd, "neverPartOfCompilationTest", firstTree));
+
+        AbstractTestNode secondTree = new NeverPartOfCompilationTestNode(new ConstantTestNode(1), 1);
+        try {
+            assertPartialEvalEquals("constant42", new RootTestNode(fd, "neverPartOfCompilationTest", secondTree));
+            Assert.fail("Expected verification error!");
+        } catch (SourceStackTrace t) {
+            // Expected verification error occurred.
+            StackTraceElement[] trace = t.getStackTrace();
+            Assert.assertEquals("com.oracle.truffle.api.nodes.RootNode.getFrameDescriptor(RootNode.java)", trace[0].toString());
+            String secondString = trace[1].toString();
+            Assert.assertEquals("com.oracle.graal.truffle.OptimizedCallTarget.callRoot(OptimizedCallTarget.java:" /* "259)" */, secondString.substring(0, secondString.length() - 4));
+        }
+    }
+
+    @Test
     public void nestedLoopExplosion() {
         FrameDescriptor fd = new FrameDescriptor();
         AbstractTestNode result = new AddTestNode(new NestedExplodedLoopTestNode(5), new ConstantTestNode(17));
-        assertPartialEvalEquals("constant42", new RootTestNode(fd, "addConstants", result));
+        assertPartialEvalEquals("constant42", new RootTestNode(fd, "nestedLoopExplosion", result));
     }
 
     @Test
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.truffle.test/src/com/oracle/graal/truffle/test/nodes/NeverPartOfCompilationTestNode.java	Mon Mar 09 21:07:38 2015 +0100
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+package com.oracle.graal.truffle.test.nodes;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.frame.*;
+
+public class NeverPartOfCompilationTestNode extends AbstractTestNode {
+
+    @Child private AbstractTestNode left;
+    private final int value;
+
+    private static class ValueContainer {
+        int value;
+    }
+
+    public NeverPartOfCompilationTestNode(AbstractTestNode left, int value) {
+        this.left = left;
+        this.value = value;
+    }
+
+    @Override
+    public int execute(VirtualFrame frame) {
+        ValueContainer v = new ValueContainer();
+        v.value = value;
+        if (v.value == left.execute(frame)) {
+            CompilerAsserts.neverPartOfCompilation();
+        }
+        return 42;
+    }
+}
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java	Mon Mar 09 18:11:19 2015 +0100
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/substitutions/TruffleGraphBuilderPlugins.java	Mon Mar 09 21:07:38 2015 +0100
@@ -41,6 +41,7 @@
 import com.oracle.graal.truffle.*;
 import com.oracle.graal.truffle.nodes.*;
 import com.oracle.graal.truffle.nodes.arithmetic.*;
+import com.oracle.graal.truffle.nodes.asserts.*;
 import com.oracle.graal.truffle.nodes.frame.*;
 import com.oracle.graal.truffle.unsafe.*;
 import com.oracle.truffle.api.*;
@@ -214,6 +215,16 @@
                 }
             }
         });
+        r.register1("neverPartOfCompilation", String.class, new InvocationPlugin() {
+            public boolean apply(GraphBuilderContext builder, ValueNode message) {
+                if (message.isConstant()) {
+                    String messageString = message.asConstant().toValueString();
+                    builder.append(new NeverPartOfCompilationNode(messageString));
+                    return true;
+                }
+                throw builder.bailout("message for never part of compilation is non-constant");
+            }
+        });
     }
 
     public static void registerOptimizedCallTargetPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java	Mon Mar 09 18:11:19 2015 +0100
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/CompilerAsserts.java	Mon Mar 09 21:07:38 2015 +0100
@@ -51,7 +51,6 @@
      * @param message text associated with the bailout exception
      */
     public static void neverPartOfCompilation(String message) {
-        CompilerDirectives.bailout(message);
     }
 
     /**