# HG changeset patch # User Andreas Woess # Date 1426867723 -3600 # Node ID cd59085cf0d89c25f84bcae8611dc140f3db39b3 # Parent a0971187a38aaec4c82ad0283b0d56df564d9424 Truffle: remove Node#onAdopt() hook diff -r a0971187a38a -r cd59085cf0d8 CHANGELOG.md --- a/CHANGELOG.md Fri Mar 20 15:59:35 2015 +0100 +++ b/CHANGELOG.md Fri Mar 20 17:08:43 2015 +0100 @@ -17,6 +17,8 @@ * Instrumentation: AST "probing" is now safe and implemented by Node.probe(); language implementors need only implement Node.isInstrumentable() and Node.createWrapperNode(). * Instrumentation: A new framework defines a category of simple "instrumentation tools" that can be created, configured, and installed, after which they autonomously collect execution data of some kind. * Instrumentation: A new example "instrumentation tool" is a language-agnostic collector of code coverage information (CoverageTracker); there are two other examples. +* Removed unsafe compiler directives; use `sun.misc.Unsafe` instead. +* Removed `Node#onAdopt()`. ### Truffle-DSL * Implemented a new generated code layout that reduces the code size. diff -r a0971187a38a -r cd59085cf0d8 graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/OnAdoptTest.java --- a/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/OnAdoptTest.java Fri Mar 20 15:59:35 2015 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2014, 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.truffle.api.test; - -import org.junit.*; - -import com.oracle.truffle.api.*; -import com.oracle.truffle.api.frame.*; -import com.oracle.truffle.api.nodes.*; - -/** - *

Inserting Extra Nodes into the AST Transparently

- * - *

- * The {@link Node} class provides a callback that is invoked whenever a node is adopted in an AST - * by insertion or replacement. Node classes can override the {@code onAdopt()} method to run extra - * functionality upon adoption. - *

- * - *

- * This test demonstrates how node instances of a specific class can be automatically wrapped in - * extra nodes when they are inserted into the AST. - *

- */ -public class OnAdoptTest { - - static class Root extends RootNode { - - @Child private Base child1; - @Child private Base child2; - - public Root(Base child1, Base child2) { - super(null); - this.child1 = child1; - this.child2 = child2; - } - - @Override - public Object execute(VirtualFrame frame) { - return child1.executeInt(frame) + child2.executeInt(frame); - } - - } - - abstract static class Base extends Node { - public abstract int executeInt(VirtualFrame frame); - } - - static class Wrapper extends Base { - - @Child private Base wrappee; - - public Wrapper(Base wrappee) { - this.wrappee = wrappee; - } - - @Override - public int executeInt(VirtualFrame frame) { - return 1 + wrappee.executeInt(frame); - } - - } - - abstract static class GenBase extends Base { - - private final int k; - - public GenBase(int k) { - this.k = k; - } - - @Override - public int executeInt(VirtualFrame frame) { - return k; - } - - } - - static class Gen extends GenBase { - public Gen(int k) { - super(k); - } - } - - static class GenWrapped extends GenBase { - - public GenWrapped(int k) { - super(k); - } - - @Override - protected void onAdopt() { - Wrapper w = new Wrapper(this); - this.replace(w); - } - - } - - @Test - public void testOnInsert() { - TruffleRuntime runtime = Truffle.getRuntime(); - Base b1 = new Gen(11); - Base b2 = new GenWrapped(11); - Root r = new Root(b1, b2); - CallTarget ct = runtime.createCallTarget(r); - Object result = ct.call(); - Assert.assertEquals(23, result); - } - -} diff -r a0971187a38a -r cd59085cf0d8 graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Fri Mar 20 15:59:35 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/Node.java Fri Mar 20 17:08:43 2015 +0100 @@ -176,15 +176,11 @@ if (newChild == this) { throw new IllegalStateException("The parent of a node can never be the node itself."); } - boolean isInserted = newChild.parent == null; newChild.parent = this; if (TruffleOptions.TraceASTJSON) { JSONHelper.dumpNewChild(this, newChild); } newChild.adoptHelper(); - if (isInserted) { - newChild.onAdopt(); - } } private void adoptHelper() { @@ -201,12 +197,8 @@ if (newChild == this) { throw new IllegalStateException("The parent of a node can never be the node itself."); } - boolean isInserted = newChild.parent == null; newChild.parent = this; newChild.adoptUnadoptedHelper(); - if (isInserted) { - newChild.onAdopt(); - } } private void adoptUnadoptedHelper() { @@ -329,16 +321,6 @@ } /** - * Subclasses of {@link Node} can implement this method to execute extra functionality when a - * node is effectively inserted into the AST. The {@code onAdopt} callback is called after the - * node has been effectively inserted, and it is guaranteed to be called only once for any given - * node. - */ - protected void onAdopt() { - // empty default - } - - /** * Invokes the {@link NodeVisitor#visit(Node)} method for this node and recursively also for all * child nodes. *