changeset 21204:4a5df5570b7f

Truffle: make ReplaceObserver return a boolean in order to consume replace events. It can be useful for nodes to consume all replace events if they are always executed behind a @TruffleBoundary.
author Christian Humer <christian.humer@gmail.com>
date Mon, 04 May 2015 11:24:13 +0200
parents 9f45587ad8f5
children f34ae5c01864
files graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedOSRLoopNode.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ReplaceObserver.java graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java
diffstat 4 files changed, 17 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Wed Apr 29 17:16:53 2015 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedCallTarget.java	Mon May 04 11:24:13 2015 +0200
@@ -458,7 +458,7 @@
     }
 
     @Override
-    public void nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
+    public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
         CompilerAsserts.neverPartOfCompilation();
         if (isValid()) {
             invalidate(newNode, reason);
@@ -470,6 +470,7 @@
         if (cancelInstalledTask(newNode, reason)) {
             compilationProfile.reportInvalidated();
         }
+        return false;
     }
 
     public void accept(NodeVisitor visitor, boolean includeInlinedNodes) {
--- a/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedOSRLoopNode.java	Wed Apr 29 17:16:53 2015 +0200
+++ b/graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/OptimizedOSRLoopNode.java	Mon May 04 11:24:13 2015 +0200
@@ -157,8 +157,9 @@
         }
     }
 
-    public void nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
+    public boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason) {
         invalidate(newNode, reason);
+        return false;
     }
 
     private void invalidate(Object source, CharSequence reason) {
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ReplaceObserver.java	Wed Apr 29 17:16:53 2015 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ReplaceObserver.java	Mon May 04 11:24:13 2015 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 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
@@ -31,5 +31,10 @@
  */
 public interface ReplaceObserver {
 
-    void nodeReplaced(Node oldNode, Node newNode, CharSequence reason);
+    /**
+     * Returns <code>true</code> if the event is consumed and no parent nodes should be notified by
+     * for replaces. Returns <code>false</code> if the parent {@link Node} or {@link CallTarget}
+     * should get notified.
+     */
+    boolean nodeReplaced(Node oldNode, Node newNode, CharSequence reason);
 }
--- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Wed Apr 29 17:16:53 2015 +0200
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java	Mon May 04 11:24:13 2015 +0200
@@ -299,14 +299,18 @@
     private void reportReplace(Node oldNode, Node newNode, CharSequence reason) {
         Node node = this;
         while (node != null) {
+            boolean consumed = false;
             if (node instanceof ReplaceObserver) {
-                ((ReplaceObserver) node).nodeReplaced(oldNode, newNode, reason);
+                consumed = ((ReplaceObserver) node).nodeReplaced(oldNode, newNode, reason);
             } else if (node instanceof RootNode) {
                 CallTarget target = ((RootNode) node).getCallTarget();
                 if (target instanceof ReplaceObserver) {
-                    ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason);
+                    consumed = ((ReplaceObserver) target).nodeReplaced(oldNode, newNode, reason);
                 }
             }
+            if (consumed) {
+                break;
+            }
             node = node.getParent();
         }
         if (TruffleOptions.TraceRewrites) {