changeset 12394:df3af5e007ad

Merge.
author Christian Humer <christian.humer@gmail.com>
date Wed, 09 Oct 2013 15:33:36 +0200
parents 7cce548b0b60 (diff) dfaac94659aa (current diff)
children 8e8347ecabbc
files graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/debug/SurvivingCounterNode.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Canonicalizable.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/CanonicalizerTool.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/Simplifiable.java graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/spi/SimplifierTool.java graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/PhiStampPhase.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/CustomTypeCheckMacroNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/CustomTypeCheckNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/TypeCastMacroNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/TypeCastNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeCustomizationMacroNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/nodes/typesystem/UnsafeCustomizationNode.java graal/com.oracle.graal.truffle/src/com/oracle/graal/truffle/phases/ReplaceLoadFinalPhase.java
diffstat 16 files changed, 1937 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.api.dsl.test/src/com/oracle/truffle/api/dsl/test/ImplicitCastTest.java	Wed Oct 09 15:33:36 2013 +0200
@@ -26,6 +26,8 @@
 
 import com.oracle.truffle.api.dsl.*;
 import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast0NodeFactory;
+import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast1NodeFactory;
+import com.oracle.truffle.api.dsl.test.ImplicitCastTestFactory.ImplicitCast2NodeFactory;
 import com.oracle.truffle.api.dsl.test.NodeContainerTest.Str;
 import com.oracle.truffle.api.dsl.test.TypeSystemTest.TestRootNode;
 import com.oracle.truffle.api.dsl.test.TypeSystemTest.ValueNode;
@@ -55,12 +57,12 @@
         public abstract Object executeEvaluated(VirtualFrame frame, Object value2);
 
         @Specialization(order = 1)
-        public String op1(String value) throws RuntimeException {
+        public String op1(String value) {
             return value;
         }
 
         @Specialization(order = 2)
-        public boolean op1(boolean value) throws RuntimeException {
+        public boolean op1(boolean value) {
             return value;
         }
 
@@ -77,8 +79,81 @@
         Assert.assertEquals(true, root.getNode().executeEvaluated(null, true));
     }
 
-    // TODO assert implicit casts only in one direction
+    @TypeSystemReference(ImplicitCast0Types.class)
+    @NodeChild(value = "operand", type = ImplicitCast1Node.class)
+    // TODO temporary workaround
+    @PolymorphicLimit(1)
+    abstract static class ImplicitCast1Node extends ValueNode {
+
+        public abstract Object executeEvaluated(VirtualFrame frame, Object operand);
+
+        @Specialization(order = 0)
+        public String op0(String value) {
+            return value;
+        }
+
+        @Specialization(order = 1, rewriteOn = RuntimeException.class)
+        public boolean op1(@SuppressWarnings("unused") boolean value) throws RuntimeException {
+            throw new RuntimeException();
+        }
+
+        @Specialization(order = 2)
+        public boolean op2(boolean value) {
+            return value;
+        }
+
+    }
+
+    @Test
+    public void testImplicitCast1() {
+        ImplicitCast1Node node = ImplicitCast1NodeFactory.create(null);
+        TestRootNode<ImplicitCast1Node> root = new TestRootNode<>(node);
+        Assert.assertEquals("2", root.getNode().executeEvaluated(null, "2"));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1));
+        Assert.assertEquals("1", root.getNode().executeEvaluated(null, "1"));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, true));
+    }
 
-    // test example that covers the most cases
+    @TypeSystemReference(ImplicitCast0Types.class)
+    @NodeChildren({@NodeChild(value = "operand0", type = ImplicitCast2Node.class), @NodeChild(value = "operand1", type = ImplicitCast2Node.class, executeWith = "operand0")})
+    // TODO temporary workaround
+    @PolymorphicLimit(1)
+    abstract static class ImplicitCast2Node extends ValueNode {
+
+        @Specialization(order = 0)
+        public String op0(String v0, String v1) {
+            return v0 + v1;
+        }
+
+        @SuppressWarnings("unused")
+        @Specialization(order = 1, rewriteOn = RuntimeException.class)
+        public boolean op1(boolean v0, boolean v1) throws RuntimeException {
+            throw new RuntimeException();
+        }
+
+        @Specialization(order = 2)
+        public boolean op2(boolean v0, boolean v1) {
+            return v0 && v1;
+        }
+
+        public abstract Object executeEvaluated(VirtualFrame frame, Object v1);
+
+        public abstract Object executeEvaluated(VirtualFrame frame, Object v1, Object v2);
+
+        public abstract Object executeEvaluated(VirtualFrame frame, boolean v1, boolean v2);
+
+    }
+
+    @Test
+    public void testImplicitCast2() {
+        ImplicitCast2Node node = ImplicitCast2NodeFactory.create(null, null);
+        TestRootNode<ImplicitCast2Node> root = new TestRootNode<>(node);
+        Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2"));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1));
+        Assert.assertEquals("42", root.getNode().executeEvaluated(null, "4", "2"));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, 1, 1));
+        Assert.assertEquals(true, root.getNode().executeEvaluated(null, true, true));
+    }
 
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/PostOrderDeserializerTest.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2012, 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.nodes.serial;
+
+import java.nio.*;
+import java.util.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.api.nodes.serial.*;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.EmptyNode;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithArray;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithFields;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithOneChild;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithThreeChilds;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithTwoArray;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithTwoChilds;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.StringNode;
+
+public class PostOrderDeserializerTest {
+
+    private PostOrderDeserializer d;
+    private TestSerializerConstantPool cp;
+
+    @Before
+    public void setUp() {
+        cp = new TestSerializerConstantPool();
+        d = new PostOrderDeserializer(cp);
+    }
+
+    @After
+    public void tearDown() {
+        d = null;
+        cp = null;
+    }
+
+    private Node deserialize(byte[] bytes) {
+        return d.deserialize(bytes, Node.class);
+    }
+
+    @Test
+    public void testNull() {
+        createCP();
+        Node ast = deserialize(createBytes(VariableLengthIntBuffer.NULL));
+        Assert.assertNull(ast);
+    }
+
+    @Test
+    public void testSingleNode() {
+        createCP(EmptyNode.class);
+        Node expectedAst = new EmptyNode();
+        Node ast = deserialize(createBytes(0));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testThreeChilds() {
+        createCP(EmptyNode.class, NodeWithThreeChilds.class);
+        Node expectedAst = new NodeWithThreeChilds(new EmptyNode(), null, new EmptyNode());
+        Node ast = deserialize(createBytes(0, VariableLengthIntBuffer.NULL, 0, 1));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testFields() {
+        createCP(NodeWithFields.class, "test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE,
+                        (int) Character.MIN_VALUE, (int) Character.MAX_VALUE, (int) Short.MIN_VALUE, (int) Short.MAX_VALUE, (int) Byte.MIN_VALUE, (int) Byte.MAX_VALUE, 1);
+        NodeWithFields expectedAst = new NodeWithFields("test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE,
+                        Double.MAX_VALUE, Character.MIN_VALUE, Character.MAX_VALUE, Short.MIN_VALUE, Short.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE, Boolean.TRUE, Boolean.FALSE);
+        Node ast = deserialize(createBytes(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 10));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testFieldsNull() {
+        createCP(NodeWithFields.class, "test", 0, 0L, 0.0F, 0.0D);
+        NodeWithFields expectedAst = new NodeWithFields("test", 0, null, 0L, null, 0f, null, 0d, null, (char) 0, null, (short) 0, null, (byte) 0, null, false, null);
+        int nil = VariableLengthIntBuffer.NULL;
+        Node ast = deserialize(createBytes(0, 1, 2, nil, 3, nil, 4, nil, 5, nil, 2, nil, 2, nil, 2, nil, 2, nil));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testNullChilds() {
+        createCP(Node[].class, NodeWithArray.class);
+        Node expectedAst = new NodeWithArray(null);
+        Node ast = deserialize(createBytes(0, VariableLengthIntBuffer.NULL, 1));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testNChilds() {
+        Node expectedAst = new NodeWithArray(new Node[]{new EmptyNode(), new NodeWithArray(new Node[]{new EmptyNode(), new EmptyNode(), new EmptyNode()}), new EmptyNode(), new EmptyNode()});
+        createCP(Node[].class, 4, EmptyNode.class, 3, NodeWithArray.class);
+        Node ast = deserialize(createBytes(0, 1, 2, 0, 3, 2, 2, 2, 4, 2, 2, 4));
+
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void test2xNChilds() {
+        Node expectedAst = new NodeWithTwoArray(new Node[]{new StringNode("a0"), new StringNode("a1")}, new Node[]{new StringNode("b0"), new StringNode("b1"), new StringNode("b2")});
+        createCP(Node[].class, 2, StringNode.class, "a0", "a1", 3, "b0", "b1", "b2", NodeWithTwoArray.class);
+        Node ast = deserialize(createBytes(0, 1, 2, 3, 2, 4, 0, 5, 2, 6, 2, 7, 2, 8, 9));
+
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testBug0() {
+        Node expectedAst = new NodeWithArray(new Node[]{new NodeWithOneChild(new EmptyNode())});
+
+        createCP(Node[].class, 1, EmptyNode.class, NodeWithOneChild.class, NodeWithArray.class);
+        Node ast = deserialize(createBytes(0, 1, 2, 3, 4));
+        assertAST(expectedAst, ast);
+    }
+
+    @Test
+    public void testBug1() {
+        Node expectedAst = new NodeWithArray(new Node[]{new NodeWithTwoChilds(new EmptyNode(), new EmptyNode())});
+
+        createCP(Node[].class, 1, EmptyNode.class, NodeWithTwoChilds.class, NodeWithArray.class);
+        Node ast = deserialize(createBytes(0, 1, 2, 2, 3, 4));
+        assertAST(expectedAst, ast);
+    }
+
+    private static void assertAST(Node expectedAst, Node actualAst) {
+        if (expectedAst == null) {
+            Assert.assertNull(actualAst);
+            return;
+        }
+
+        Assert.assertNotNull(actualAst);
+        // fields are asserted using the corresponding equals implementation
+        Assert.assertEquals(expectedAst, actualAst);
+
+        Iterable<Node> expectedChildIterator = expectedAst.getChildren();
+        Iterator<Node> actualChildIterator = actualAst.getChildren().iterator();
+        for (Node node : expectedChildIterator) {
+            Assert.assertTrue(actualChildIterator.hasNext());
+            assertAST(node, actualChildIterator.next());
+        }
+        Assert.assertFalse(actualChildIterator.hasNext());
+    }
+
+    private static byte[] createBytes(int... refs) {
+        VariableLengthIntBuffer buf = new VariableLengthIntBuffer(ByteBuffer.allocate(512));
+        for (int i = 0; i < refs.length; i++) {
+            buf.put(refs[i]);
+        }
+        return buf.getBytes();
+    }
+
+    private void createCP(Object... cpData) {
+        for (int i = 0; i < cpData.length; i++) {
+            Object object = cpData[i];
+
+            cp.putObject(object.getClass(), object);
+
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/PostOrderSerializerTest.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2012, 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.nodes.serial;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.api.nodes.serial.*;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.EmptyNode;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithArray;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithFields;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithThreeChilds;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.NodeWithTwoArray;
+import com.oracle.truffle.api.test.nodes.serial.TestNodes.StringNode;
+
+public class PostOrderSerializerTest {
+
+    private PostOrderSerializer s;
+    private TestSerializerConstantPool cp;
+
+    @Before
+    public void setUp() {
+        cp = new TestSerializerConstantPool();
+        s = new PostOrderSerializer(cp);
+    }
+
+    @After
+    public void tearDown() {
+        cp = null;
+        s = null;
+    }
+
+    @Test
+    public void testNull() {
+        Node ast = null;
+        assertBytes(s.serialize(ast), VariableLengthIntBuffer.NULL);
+        assertCP();
+    }
+
+    @Test
+    public void testSingleEmptyNode() {
+        Node ast = new EmptyNode();
+        assertBytes(s.serialize(ast), 0);
+        assertCP(EmptyNode.class);
+    }
+
+    @Test
+    public void testThreeChilds() {
+        Node ast = new NodeWithThreeChilds(new EmptyNode(), null, new EmptyNode());
+        assertBytes(s.serialize(ast), 0, VariableLengthIntBuffer.NULL, 0, 1);
+        assertCP(EmptyNode.class, NodeWithThreeChilds.class);
+    }
+
+    @Test
+    public void testFields() {
+        NodeWithFields ast = new NodeWithFields("test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE,
+                        Character.MIN_VALUE, Character.MAX_VALUE, Short.MIN_VALUE, Short.MAX_VALUE, Byte.MIN_VALUE, Byte.MAX_VALUE, Boolean.TRUE, Boolean.FALSE);
+        assertBytes(s.serialize(ast), 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 10);
+        assertCP(NodeWithFields.class, "test", Integer.MIN_VALUE, Integer.MAX_VALUE, Long.MIN_VALUE, Long.MAX_VALUE, Float.MIN_VALUE, Float.MAX_VALUE, Double.MIN_VALUE, Double.MAX_VALUE,
+                        (int) Character.MIN_VALUE, (int) Character.MAX_VALUE, (int) Short.MIN_VALUE, (int) Short.MAX_VALUE, (int) Byte.MIN_VALUE, (int) Byte.MAX_VALUE, 1);
+    }
+
+    @Test
+    public void testFieldsNull() {
+        NodeWithFields ast = new NodeWithFields("test", 0, null, 0L, null, 0f, null, 0d, null, (char) 0, null, (short) 0, null, (byte) 0, null, false, null);
+        int nil = VariableLengthIntBuffer.NULL;
+        assertBytes(s.serialize(ast), 0, 1, 2, nil, 3, nil, 4, nil, 5, nil, 2, nil, 2, nil, 2, nil, 2, nil);
+        assertCP(NodeWithFields.class, "test", 0, 0L, 0.0F, 0.0D);
+    }
+
+    @Test
+    public void testNChilds() {
+        Node ast = new NodeWithArray(new Node[]{new EmptyNode(), new NodeWithArray(new Node[]{new EmptyNode(), new EmptyNode(), new EmptyNode()}), new EmptyNode(), new EmptyNode()});
+        assertBytes(s.serialize(ast), 0, 1, 2, 0, 3, 2, 2, 2, 4, 2, 2, 4);
+        assertCP(Node[].class, 4, EmptyNode.class, 3, NodeWithArray.class);
+    }
+
+    @Test
+    public void testNullChilds() {
+        Node ast = new NodeWithArray(null);
+        assertBytes(s.serialize(ast), 0, VariableLengthIntBuffer.NULL, 1);
+        assertCP(Node[].class, NodeWithArray.class);
+    }
+
+    @Test
+    public void test2xNChilds() {
+        Node ast = new NodeWithTwoArray(new Node[]{new StringNode("a0"), new StringNode("a1")}, new Node[]{new StringNode("b0"), new StringNode("b1"), new StringNode("b2")});
+        assertBytes(s.serialize(ast), 0, 1, 2, 3, 2, 4, 0, 5, 2, 6, 2, 7, 2, 8, 9);
+        assertCP(Node[].class, 2, StringNode.class, "a0", "a1", 3, "b0", "b1", "b2", NodeWithTwoArray.class);
+    }
+
+    private static void assertBytes(byte[] actualBytes, int... expectedIndexes) {
+        VariableLengthIntBuffer buf = new VariableLengthIntBuffer(actualBytes);
+        for (int i = 0; i < expectedIndexes.length; i++) {
+            Assert.assertTrue("Unexpected EOF " + i, buf.hasRemaining());
+            Assert.assertEquals("Index at pos " + i + ".", expectedIndexes[i], buf.get());
+        }
+        Assert.assertFalse(buf.hasRemaining());
+    }
+
+    private void assertCP(Object... object) {
+        for (int i = 0; i < object.length; i++) {
+            Object cpvalue = object[i];
+            Assert.assertNotNull("CP at index " + i, cpvalue);
+            Assert.assertEquals("CP at index " + i, cpvalue, cp.getObject(cpvalue.getClass(), i));
+        }
+        Assert.assertEquals(object.length, cp.getIndex());
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/TestNodes.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2012, 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.nodes.serial;
+
+import java.util.*;
+
+import com.oracle.truffle.api.nodes.*;
+
+final class TestNodes {
+
+    private TestNodes() {
+    }
+
+    static class StringNode extends Node {
+
+        private final String name;
+
+        public StringNode(String name) {
+            this.name = name;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(name);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            } else if (obj.getClass() != getClass()) {
+                return false;
+            } else if ((((Node) obj).getParent() != null) && !((Node) obj).getParent().equals(getParent())) {
+                return false;
+            } else if (!Objects.equals(name, ((StringNode) obj).name)) {
+                return false;
+            }
+            return true;
+        }
+    }
+
+    static class EmptyNode extends Node {
+
+        @Override
+        public int hashCode() {
+            return super.hashCode();
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (obj == null) {
+                return false;
+            } else if (obj.getClass() != getClass()) {
+                return false;
+            } else if ((((Node) obj).getParent() != null) && !((Node) obj).getParent().equals(getParent())) {
+                return false;
+            }
+            return true;
+        }
+    }
+
+    static class NodeWithOneChild extends EmptyNode {
+
+        @Child Node child;
+
+        public NodeWithOneChild(Node child) {
+            this.child = adoptChild(child);
+        }
+
+    }
+
+    static class NodeWithTwoChilds extends EmptyNode {
+
+        @Child Node child1;
+        @Child Node child2;
+
+        public NodeWithTwoChilds(Node child1, Node child2) {
+            this.child1 = adoptChild(child1);
+            this.child2 = adoptChild(child2);
+        }
+
+    }
+
+    static class NodeWithThreeChilds extends EmptyNode {
+
+        @Child Node child1;
+        @Child Node child2;
+        @Child Node child3;
+
+        public NodeWithThreeChilds(Node child1, Node child2, Node child3) {
+            this.child1 = adoptChild(child1);
+            this.child2 = adoptChild(child2);
+            this.child3 = adoptChild(child3);
+        }
+
+    }
+
+    static class NodeWithArray extends EmptyNode {
+
+        @Children private final Node[] childNodes;
+
+        NodeWithArray(Node[] children) {
+            this.childNodes = adoptChildren(children);
+        }
+
+        Node[] getChildNodes() {
+            return childNodes;
+        }
+    }
+
+    static class NodeWithTwoArray extends EmptyNode {
+
+        @Children private final Node[] childNodes1;
+        @Children private final Node[] childNodes2;
+
+        NodeWithTwoArray(Node[] childs1, Node[] childs2) {
+            this.childNodes1 = adoptChildren(childs1);
+            this.childNodes2 = adoptChildren(childs2);
+        }
+
+        Node[] getChildNodes1() {
+            return childNodes1;
+        }
+
+        Node[] getChildNodes2() {
+            return childNodes2;
+        }
+    }
+
+    static class NodeWithFields extends EmptyNode {
+
+        String stringField;
+        int integerField;
+        Integer integerObjectField;
+        long longField;
+        Long longObjectField;
+        float floatField;
+        Float floatObjectField;
+        double doubleField;
+        Double doubleObjectField;
+        char charField;
+        Character charObjectField;
+        short shortField;
+        Short shortObjecField;
+        byte byteField;
+        Byte byteObjectField;
+        boolean booleanField;
+        Boolean booleanObjectfield;
+
+        public NodeWithFields(String stringField, int integerField, Integer integerObjectField, long longField, Long longObjectField, float floatField, Float floatObjectField, double doubleField,
+                        Double doubleObjectField, char charField, Character charObjectField, short shortField, Short shortObjecField, byte byteField, Byte byteObjectField, boolean booleanField,
+                        Boolean booleanObjectfield) {
+            this.stringField = stringField;
+            this.integerField = integerField;
+            this.integerObjectField = integerObjectField;
+            this.longField = longField;
+            this.longObjectField = longObjectField;
+            this.floatField = floatField;
+            this.floatObjectField = floatObjectField;
+            this.doubleField = doubleField;
+            this.doubleObjectField = doubleObjectField;
+            this.charField = charField;
+            this.charObjectField = charObjectField;
+            this.shortField = shortField;
+            this.shortObjecField = shortObjecField;
+            this.byteField = byteField;
+            this.byteObjectField = byteObjectField;
+            this.booleanField = booleanField;
+            this.booleanObjectfield = booleanObjectfield;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(stringField, integerField, integerObjectField, longField, longObjectField, floatField, floatObjectField, doubleField, doubleObjectField, charField, charObjectField,
+                            shortField, shortObjecField, byteField, byteObjectField, booleanField, booleanObjectfield);
+        }
+
+        @Override
+        public boolean equals(Object obj) {
+            if (this == obj) {
+                return true;
+            }
+            if (obj.getClass() != getClass()) {
+                return false;
+            }
+            NodeWithFields o = (NodeWithFields) obj;
+            return Objects.deepEquals(fieldArray(), o.fieldArray());
+        }
+
+        private Object[] fieldArray() {
+            return array(stringField, integerField, integerObjectField, longField, longObjectField, floatField, floatObjectField, doubleField, doubleObjectField, charField, charObjectField,
+                            shortField, shortObjecField, byteField, byteObjectField, booleanField, booleanObjectfield);
+        }
+
+        private static Object[] array(Object... values) {
+            return values;
+        }
+
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/TestSerializerConstantPool.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2012, 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.nodes.serial;
+
+import java.util.*;
+
+import com.oracle.truffle.api.nodes.serial.*;
+
+class TestSerializerConstantPool implements SerializerConstantPool {
+
+    private final Map<Integer, Object> int2object = new HashMap<>();
+    private final Map<Object, Integer> object2int = new HashMap<>();
+
+    private int index;
+
+    public void setIndex(int index) {
+        this.index = index;
+    }
+
+    public int getIndex() {
+        return index;
+    }
+
+    @Override
+    public double getDouble(int cpi) {
+        return (Double) int2object.get(cpi);
+    }
+
+    @Override
+    public float getFloat(int cpi) {
+        return (Float) int2object.get(cpi);
+    }
+
+    @Override
+    public Object getObject(Class<?> clazz, int cpi) throws UnsupportedConstantPoolTypeException {
+        return int2object.get(cpi);
+    }
+
+    @Override
+    public int putDouble(double value) {
+        return put(value);
+    }
+
+    public int putFloat(float value) {
+        return put(value);
+    }
+
+    public int putObject(java.lang.Class<?> clazz, Object value) throws UnsupportedConstantPoolTypeException {
+        return put(value);
+    }
+
+    @Override
+    public int putClass(Class<?> clazz) {
+        return put(clazz);
+    }
+
+    private int put(Object o) {
+        Integer currentIndex = object2int.get(o);
+        if (currentIndex == null) {
+            int2object.put(index, o);
+            object2int.put(o, index);
+            return index++;
+        } else {
+            return currentIndex;
+        }
+    }
+
+    @Override
+    public Class<?> getClass(int idx) {
+        return (Class<?>) int2object.get(idx);
+    }
+
+    @Override
+    public int putInt(int constant) {
+        return put(constant);
+    }
+
+    @Override
+    public int getInt(int idx) {
+        return (Integer) int2object.get(idx);
+    }
+
+    @Override
+    public long getLong(int idx) {
+        return (Long) int2object.get(idx);
+    }
+
+    @Override
+    public int putLong(long value) {
+        return put(value);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/nodes/serial/VariableLengthIntBufferTest.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,124 @@
+/*
+ * Copyright (c) 2012, 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.nodes.serial;
+
+import java.nio.*;
+
+import org.junit.*;
+
+import com.oracle.truffle.api.nodes.serial.*;
+
+public class VariableLengthIntBufferTest {
+
+    private VariableLengthIntBuffer buf;
+
+    @Before
+    public void setUp() {
+        buf = new VariableLengthIntBuffer(ByteBuffer.allocate(512));
+    }
+
+    @After
+    public void tearDown() {
+        buf = null;
+    }
+
+    @Test
+    public void testPutNull() {
+        buf.put(VariableLengthIntBuffer.NULL);
+        assertBytes(0xFF);
+    }
+
+    @Test
+    public void testPutByteCornerCase0() {
+        buf.put(0x00); // 0
+        assertBytes(0x00);
+    }
+
+    @Test
+    public void testPutByteCornerCase1() {
+        buf.put(0x7F); // 127
+        assertBytes(0x7F);
+    }
+
+    @Test
+    public void testPutByteCornerCase2() {
+        buf.put(0x3FFF_FFFF);
+        assertBytes(0xBF, 0xFF, 0xFF, 0xFF);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testPutByteCornerCase3() {
+        buf.put(0x4000_0000); // out of encodeable
+    }
+
+    @Test
+    public void testGetNull() {
+        create(0xFF);
+        assertGet(VariableLengthIntBuffer.NULL);
+    }
+
+    @Test
+    public void testGetCornerCase0() {
+        create(0x00);
+        assertGet(0x00);
+    }
+
+    @Test
+    public void testGetCornerCase1() {
+        create(0x7F);
+        assertGet(0x7F);
+    }
+
+    @Test
+    public void testGetCornerCase2() {
+        create(0xBF, 0xFF, 0xFF, 0xFF);
+        assertGet(0x3FFF_FFFF);
+    }
+
+    @Test(expected = AssertionError.class)
+    public void testGetCornerCase3() {
+        create(0xFF, 0xFF, 0xFF, 0xFF);
+        assertGet(0x0);
+    }
+
+    private void create(int... bytes) {
+        byte[] convBytes = new byte[bytes.length];
+        for (int i = 0; i < bytes.length; i++) {
+            convBytes[i] = (byte) bytes[i];
+        }
+        buf = new VariableLengthIntBuffer(convBytes);
+    }
+
+    private void assertGet(int expected) {
+        Assert.assertEquals(expected, buf.get());
+    }
+
+    private void assertBytes(int... expectedBytes) {
+        byte[] actualBytes = buf.getBytes();
+        Assert.assertEquals(expectedBytes.length, actualBytes.length);
+        for (int i = 0; i < expectedBytes.length; i++) {
+            Assert.assertTrue(actualBytes[i] == (byte) expectedBytes[i]);
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/PostOrderDeserializer.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,366 @@
+/*
+ * Copyright (c) 2012, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.nodes.serial;
+
+import java.lang.reflect.*;
+import java.util.*;
+
+import sun.misc.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.api.nodes.NodeUtil.*;
+
+/**
+ * Experimental API. May change without notice.
+ */
+public final class PostOrderDeserializer {
+
+    private static final Unsafe unsafe = loadUnsafe();
+
+    private final SerializerConstantPool cp;
+
+    private final HierarchicalStack stack = new HierarchicalStack();
+
+    /**
+     * Constructs a new serializer using a custom {@link SerializerConstantPool} implementation. For
+     * the {@link SerializerConstantPool} implementation at least the following methods must be
+     * implemented:
+     * <ul>
+     * <li>{@link SerializerConstantPool#getInt(int)}</li>
+     * <li>{@link SerializerConstantPool#getClass(int)}</li>
+     * </ul>
+     */
+    public PostOrderDeserializer(SerializerConstantPool cp) {
+        this.cp = cp;
+    }
+
+    /**
+     * Deserializes the byte stream and returns the deserialized Truffle AST node.
+     * 
+     * @param bytes the trimmed byte array containing the serialized data
+     * @param expectedType the expected root node type. Throws an exception if the root node is not
+     *            assignable from this type.
+     * @return the deserialized Truffle AST represented by the root Node.
+     * 
+     * @throws UnsupportedConstantPoolTypeException thrown if a type is encountered that is not
+     *             supported by the constant pool implementation.
+     */
+    @SuppressWarnings("unchecked")
+    public <T extends Node> T deserialize(byte[] bytes, Class<T> expectedType) throws UnsupportedConstantPoolTypeException {
+        VariableLengthIntBuffer buffer = new VariableLengthIntBuffer(bytes);
+
+        while (buffer.hasRemaining()) {
+            int classCPI = buffer.get();
+            if (classCPI == VariableLengthIntBuffer.NULL) {
+                pushNode(null);
+            } else {
+                Class<?> clazz = cp.getClass(classCPI);
+                if (clazz.isArray()) {
+                    int lengthCPI = buffer.get();
+                    if (lengthCPI == VariableLengthIntBuffer.NULL) {
+                        pushArray(null);
+                    } else {
+                        pushArray((Node[]) Array.newInstance(clazz.getComponentType(), cp.getInt(lengthCPI)));
+                    }
+                } else {
+                    pushNode(invokeDeserialize(buffer, clazz.asSubclass(Node.class)));
+                }
+            }
+        }
+        T returnNode = (T) popNode(null, expectedType);
+
+        assert stack.dynamicStack.isEmpty();
+
+        return returnNode;
+    }
+
+    private void pushNode(Node node) {
+        stack.push(node);
+    }
+
+    private void pushArray(Node[] array) {
+        stack.pushStack(array);
+    }
+
+    private Node[] popArray(Node parent, Class<?> expectedType) {
+        Node[] array = (Node[]) stack.popStack();
+        if (array != null) {
+            assertType(array, expectedType);
+            for (int i = 0; i < array.length; i++) {
+                updateParent(parent, array[i]);
+            }
+        }
+        return array;
+    }
+
+    private Node popNode(Node parent, Class<?> expectedType) {
+        Object o = stack.pop();
+        assertType(o, expectedType);
+        updateParent(parent, (Node) o);
+        return (Node) o;
+    }
+
+    private static void assertType(Object o, Class<?> expectedType) {
+        if (o != null && !expectedType.isAssignableFrom(o.getClass())) {
+            throw new AssertionError("Expected element type '" + expectedType.getName() + "' but was '" + o.getClass().getName() + "'.");
+        }
+    }
+
+    private Node invokeDeserialize(VariableLengthIntBuffer buffer, Class<? extends Node> nodeClass) throws UnsupportedConstantPoolTypeException {
+        if (nodeClass == null) {
+            return null;
+        }
+
+        Object object;
+        try {
+            object = unsafe.allocateInstance(nodeClass);
+        } catch (InstantiationException e) {
+            throw new RuntimeException("Unable to allocate truffle node " + nodeClass, e);
+        }
+        if (!(object instanceof Node)) {
+            throw new RuntimeException("Class is not a truffle node " + nodeClass);
+        }
+
+        Node node = (Node) object;
+
+        NodeField[] nodeFields = NodeClass.get(nodeClass).getFields();
+        deserializeChildrenFields(node, nodeFields);
+        deserializeChildFields(node, nodeFields);
+        deserializeDataFields(buffer, node, nodeFields);
+
+        return node;
+    }
+
+    private void deserializeDataFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException {
+        for (int i = 0; i < nodeFields.length; i++) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.DATA) {
+                Class<?> fieldClass = field.getType();
+                long offset = field.getOffset();
+
+                // source sections are not serialized
+                // TODO add support for source sections
+                if (field.getType().isAssignableFrom(SourceSection.class)) {
+                    continue;
+                }
+
+                int cpi = buffer.get();
+                if (cpi == VariableLengthIntBuffer.NULL) {
+                    if (fieldClass == int.class) {
+                        unsafe.putInt(nodeInstance, offset, 0);
+                    } else if (fieldClass == long.class) {
+                        unsafe.putLong(nodeInstance, offset, 0L);
+                    } else if (fieldClass == float.class) {
+                        unsafe.putFloat(nodeInstance, offset, 0.0F);
+                    } else if (fieldClass == double.class) {
+                        unsafe.putDouble(nodeInstance, offset, 0.0D);
+                    } else if (fieldClass == byte.class) {
+                        unsafe.putByte(nodeInstance, offset, (byte) 0);
+                    } else if (fieldClass == short.class) {
+                        unsafe.putShort(nodeInstance, offset, (short) 0);
+                    } else if (fieldClass == char.class) {
+                        unsafe.putChar(nodeInstance, offset, (char) 0);
+                    } else if (fieldClass == boolean.class) {
+                        unsafe.putBoolean(nodeInstance, offset, false);
+                    } else {
+                        unsafe.putObject(nodeInstance, offset, null);
+                    }
+                } else {
+                    if (fieldClass == int.class) {
+                        unsafe.putInt(nodeInstance, offset, cp.getInt(cpi));
+                    } else if (fieldClass == long.class) {
+                        unsafe.putLong(nodeInstance, offset, cp.getLong(cpi));
+                    } else if (fieldClass == float.class) {
+                        unsafe.putFloat(nodeInstance, offset, cp.getFloat(cpi));
+                    } else if (fieldClass == double.class) {
+                        unsafe.putDouble(nodeInstance, offset, cp.getDouble(cpi));
+                    } else if (fieldClass == byte.class) {
+                        unsafe.putByte(nodeInstance, offset, (byte) cp.getInt(cpi));
+                    } else if (fieldClass == short.class) {
+                        unsafe.putShort(nodeInstance, offset, (short) cp.getInt(cpi));
+                    } else if (fieldClass == char.class) {
+                        unsafe.putChar(nodeInstance, offset, (char) cp.getInt(cpi));
+                    } else if (fieldClass == boolean.class) {
+                        unsafe.putBoolean(nodeInstance, offset, cp.getInt(cpi) == 1 ? true : false);
+                    } else if (fieldClass == Integer.class) {
+                        unsafe.putObject(nodeInstance, offset, cp.getInt(cpi));
+                    } else if (fieldClass == Long.class) {
+                        unsafe.putObject(nodeInstance, offset, cp.getLong(cpi));
+                    } else if (fieldClass == Float.class) {
+                        unsafe.putObject(nodeInstance, offset, cp.getFloat(cpi));
+                    } else if (fieldClass == Double.class) {
+                        unsafe.putObject(nodeInstance, offset, cp.getDouble(cpi));
+                    } else if (fieldClass == Byte.class) {
+                        unsafe.putObject(nodeInstance, offset, (byte) cp.getInt(cpi));
+                    } else if (fieldClass == Short.class) {
+                        unsafe.putObject(nodeInstance, offset, (short) cp.getInt(cpi));
+                    } else if (fieldClass == Character.class) {
+                        unsafe.putObject(nodeInstance, offset, (char) cp.getInt(cpi));
+                    } else if (fieldClass == Boolean.class) {
+                        unsafe.putObject(nodeInstance, offset, cp.getInt(cpi) == 1 ? Boolean.TRUE : Boolean.FALSE);
+                    } else {
+                        unsafe.putObject(nodeInstance, offset, cp.getObject(fieldClass, cpi));
+                    }
+                }
+            }
+        }
+    }
+
+    private void deserializeChildFields(Node parent, NodeField[] nodeFields) {
+        for (int i = nodeFields.length - 1; i >= 0; i--) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.CHILD) {
+                unsafe.putObject(parent, field.getOffset(), popNode(parent, field.getType()));
+            }
+        }
+    }
+
+    private void deserializeChildrenFields(Node parent, NodeField[] nodeFields) {
+        for (int i = nodeFields.length - 1; i >= 0; i--) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.CHILDREN) {
+                unsafe.putObject(parent, field.getOffset(), popArray(parent, field.getType()));
+            }
+        }
+    }
+
+    private static Node updateParent(Node parent, Node child) {
+        if (child != null) {
+            long parentOffset = NodeClass.get(child.getClass()).getParentOffset();
+            unsafe.putObject(child, parentOffset, parent);
+        }
+        return child;
+    }
+
+    private static Unsafe loadUnsafe() {
+        try {
+            return Unsafe.getUnsafe();
+        } catch (SecurityException e) {
+        }
+        try {
+            Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe");
+            theUnsafeInstance.setAccessible(true);
+            return (Unsafe) theUnsafeInstance.get(Unsafe.class);
+        } catch (Exception e) {
+            throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e);
+        }
+    }
+
+    private static class HierarchicalStack {
+
+        private static final Object NULL_STACK = new Object();
+
+        private final List<Object> dynamicStack = new ArrayList<>();
+
+        void pushStack(Object[] array) {
+            if (array == null) {
+                dynamicStack.add(NULL_STACK);
+            } else {
+                dynamicStack.add(new FixedSizeNodeStack(array));
+            }
+        }
+
+        private FixedSizeNodeStack getTosStack() {
+            if (dynamicStack.isEmpty()) {
+                return null;
+            }
+            Object peekTos = dynamicStack.get(dynamicStack.size() - 1);
+            if (peekTos != null && peekTos.getClass() == FixedSizeNodeStack.class) {
+                return (FixedSizeNodeStack) peekTos;
+            }
+            return null;
+        }
+
+        Object[] popStack() {
+            Object tos = dynamicStack.remove(dynamicStack.size() - 1);
+            if (tos == NULL_STACK) {
+                return null;
+            }
+            return ((FixedSizeNodeStack) tos).getArray();
+        }
+
+        void push(Object o) {
+            FixedSizeNodeStack tosStack = getTosStack();
+            if (tosStack != null && !tosStack.isFull()) {
+                tosStack.push(o);
+            } else {
+                dynamicStack.add(o);
+            }
+        }
+
+        Object pop() {
+            FixedSizeNodeStack tosStack = getTosStack();
+            Object value;
+            if (tosStack != null) {
+                assert !tosStack.isEmpty();
+                value = tosStack.pop();
+            } else {
+                value = dynamicStack.remove(dynamicStack.size() - 1);
+            }
+            assert value != NULL_STACK;
+            return value;
+        }
+
+    }
+
+    private static class FixedSizeNodeStack {
+
+        private final Object[] array;
+
+        private int tos;
+
+        FixedSizeNodeStack(Object[] array) {
+            this.array = array;
+        }
+
+        boolean isFull() {
+            return tos == array.length;
+        }
+
+        boolean isEmpty() {
+            return tos == 0;
+        }
+
+        private void push(Object node) {
+            if (tos >= array.length) {
+                throw new ArrayIndexOutOfBoundsException();
+            }
+            unsafe.putObject(array, Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * (long) (tos++), node);
+        }
+
+        private Object pop() {
+            if (tos <= 0) {
+                throw new ArrayIndexOutOfBoundsException();
+            }
+            return unsafe.getObject(array, Unsafe.ARRAY_OBJECT_BASE_OFFSET + Unsafe.ARRAY_OBJECT_INDEX_SCALE * (long) (--tos));
+        }
+
+        private Object[] getArray() {
+            return array;
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/PostOrderSerializer.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,199 @@
+/*
+ * Copyright (c) 2012, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.nodes.serial;
+
+import java.lang.reflect.*;
+import java.nio.*;
+
+import sun.misc.*;
+
+import com.oracle.truffle.api.*;
+import com.oracle.truffle.api.nodes.*;
+import com.oracle.truffle.api.nodes.NodeUtil.NodeClass;
+import com.oracle.truffle.api.nodes.NodeUtil.NodeField;
+import com.oracle.truffle.api.nodes.NodeUtil.NodeFieldKind;
+
+/**
+ * Experimental API. May change without notice.
+ */
+public final class PostOrderSerializer {
+
+    private static final Unsafe unsafe = loadUnsafe();
+
+    private final SerializerConstantPool cp;
+
+    /**
+     * Constructs a new deserializer using a custom {@link SerializerConstantPool} implementation.
+     * For the {@link SerializerConstantPool} implementation at least the following methods must be
+     * implemented:
+     * <ul>
+     * <li>{@link SerializerConstantPool#putInt(int)}</li>
+     * <li>{@link SerializerConstantPool#putClass(Class)}</li>
+     * </ul>
+     */
+    public PostOrderSerializer(SerializerConstantPool cp) {
+        this.cp = cp;
+    }
+
+    /**
+     * Serializes the node AST and returns the serialized data as byte array.
+     * 
+     * @param node the root node that represents the Truffle AST that should be serialized.
+     * @return a trimmed byte array that contains the serialized data.
+     * 
+     * @throws UnsupportedConstantPoolTypeException thrown if a type is encountered that is not
+     *             supported by the constant pool implementation.
+     */
+    public byte[] serialize(Node node) throws UnsupportedConstantPoolTypeException {
+        VariableLengthIntBuffer buffer = new VariableLengthIntBuffer(ByteBuffer.allocate(512));
+        serialize(buffer, node);
+        return buffer.getBytes();
+    }
+
+    private void serialize(VariableLengthIntBuffer buffer, Node node) throws UnsupportedConstantPoolTypeException {
+        if (node == null) {
+            buffer.put(VariableLengthIntBuffer.NULL);
+            return;
+        }
+        Class<? extends Node> nodeClass = node.getClass();
+
+        NodeField[] nodeFields = NodeClass.get(nodeClass).getFields();
+        serializeChildFields(buffer, node, nodeFields);
+        serializeChildrenFields(buffer, node, nodeFields);
+        buffer.put(cp.putClass(node.getClass()));
+        serializeDataFields(buffer, node, nodeFields);
+    }
+
+    private void serializeDataFields(VariableLengthIntBuffer buffer, Node node, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException {
+        for (int i = 0; i < nodeFields.length; i++) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.DATA) {
+                Class<?> fieldClass = field.getType();
+                long offset = field.getOffset();
+                int cpi;
+
+                if (field.getType().isAssignableFrom(SourceSection.class)) {
+                    continue;
+                }
+
+                if (fieldClass == int.class) {
+                    cpi = cp.putInt(unsafe.getInt(node, offset));
+                } else if (fieldClass == long.class) {
+                    cpi = cp.putLong(unsafe.getLong(node, offset));
+                } else if (fieldClass == float.class) {
+                    cpi = cp.putFloat(unsafe.getFloat(node, offset));
+                } else if (fieldClass == double.class) {
+                    cpi = cp.putDouble(unsafe.getDouble(node, offset));
+                } else if (fieldClass == byte.class) {
+                    cpi = cp.putInt(unsafe.getByte(node, offset));
+                } else if (fieldClass == short.class) {
+                    cpi = cp.putInt(unsafe.getShort(node, offset));
+                } else if (fieldClass == char.class) {
+                    cpi = cp.putInt(unsafe.getChar(node, offset));
+                } else if (fieldClass == boolean.class) {
+                    cpi = cp.putInt(unsafe.getBoolean(node, offset) ? 1 : 0);
+                } else {
+                    Object value = unsafe.getObject(node, offset);
+                    if (value == null) {
+                        cpi = VariableLengthIntBuffer.NULL;
+                    } else if (fieldClass == Integer.class) {
+                        cpi = cp.putInt((Integer) value);
+                    } else if (fieldClass == Long.class) {
+                        cpi = cp.putLong((Long) value);
+                    } else if (fieldClass == Float.class) {
+                        cpi = cp.putFloat((Float) value);
+                    } else if (fieldClass == Double.class) {
+                        cpi = cp.putDouble((Double) value);
+                    } else if (fieldClass == Byte.class) {
+                        cpi = cp.putInt((Byte) value);
+                    } else if (fieldClass == Short.class) {
+                        cpi = cp.putInt((Short) value);
+                    } else if (fieldClass == Character.class) {
+                        cpi = cp.putInt((Character) value);
+                    } else if (fieldClass == Boolean.class) {
+                        cpi = cp.putInt((Boolean) value ? 1 : 0);
+                    } else {
+                        cpi = cp.putObject(fieldClass, value);
+                    }
+                }
+
+                buffer.put(cpi);
+            }
+        }
+    }
+
+    private void serializeChildrenFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException {
+        for (int i = 0; i < nodeFields.length; i++) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.CHILDREN) {
+                Object childArrayObject = unsafe.getObject(nodeInstance, field.getOffset());
+                if (childArrayObject != null && !(childArrayObject instanceof Node[])) {
+                    throw new AssertionError("Node children must be instanceof Node[]");
+                }
+
+                buffer.put(cp.putClass(field.getType()));
+
+                Node[] childArray = (Node[]) childArrayObject;
+                if (childArray == null) {
+                    buffer.put(VariableLengthIntBuffer.NULL);
+                } else {
+                    buffer.put(cp.putInt(childArray.length));
+
+                    for (int j = 0; j < childArray.length; j++) {
+                        serialize(buffer, childArray[j]);
+                    }
+                }
+            }
+        }
+    }
+
+    private void serializeChildFields(VariableLengthIntBuffer buffer, Node nodeInstance, NodeField[] nodeFields) throws UnsupportedConstantPoolTypeException {
+        for (int i = 0; i < nodeFields.length; i++) {
+            NodeField field = nodeFields[i];
+            if (field.getKind() == NodeFieldKind.CHILD) {
+                Object childObject = unsafe.getObject(nodeInstance, field.getOffset());
+                if (childObject != null && !(childObject instanceof Node)) {
+                    throw new AssertionError("Node children must be instanceof Node");
+                }
+                serialize(buffer, (Node) childObject);
+            }
+        }
+    }
+
+    private static Unsafe loadUnsafe() {
+        try {
+            return Unsafe.getUnsafe();
+        } catch (SecurityException e) {
+        }
+        try {
+            Field theUnsafeInstance = Unsafe.class.getDeclaredField("theUnsafe");
+            theUnsafeInstance.setAccessible(true);
+            return (Unsafe) theUnsafeInstance.get(Unsafe.class);
+        } catch (Exception e) {
+            throw new RuntimeException("exception while trying to get Unsafe.theUnsafe via reflection:", e);
+        }
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/SerializerConstantPool.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,152 @@
+/*
+ * Copyright (c) 2012, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.nodes.serial;
+
+/**
+ * Experimental API. May change without notice. This interface is used as bridge between the
+ * {@link PostOrderDeserializer}, {@link PostOrderSerializer} and underlying constant pool
+ * implementation. A constant pool stores a value and returns an identifying index, with which the
+ * object can later be returned from the pool again. All methods of this class are optional and may
+ * throw a {@link UnsupportedOperationException}.
+ */
+public interface SerializerConstantPool {
+
+    /**
+     * Returns the constant pool index of a value that is not a java native type, a java
+     * native-wrapper class or a {@link Class} instance. The implementor should support all
+     * additional types that are necessary to serialize a truffle AST for a specific truffle
+     * implementation. If a type is not supported by this constant pool implementation a
+     * {@link UnsupportedConstantPoolTypeException} should be thrown.
+     * 
+     * @param clazz the {@link Class} of the value
+     * @param value the value to be stored. Must be at least a subclass of the given clazz.
+     * @return the constant pool index
+     * @throws UnsupportedConstantPoolTypeException if a type is not supported for persistence in
+     *             the constant pool.
+     */
+    int putObject(Class<?> clazz, Object value) throws UnsupportedConstantPoolTypeException;
+
+    /**
+     * Stores a value in the constant pool that is not a java native type, a java native-wrapper
+     * class or a {@link Class} instance. The implementor should support all additional types that
+     * are necessary to serialize a truffle AST for a specific truffle implementation. If a type is
+     * not supported by this constant pool implementation a
+     * {@link UnsupportedConstantPoolTypeException} should be thrown.
+     * 
+     * @param clazz the {@link Class} of the value in the constant pool.
+     * @param cpi the previously returned index
+     * @return the value stored inside the constant pool
+     * @throws UnsupportedConstantPoolTypeException if a type is not supported for persistence in
+     *             the constant pool.
+     * @throws IllegalArgumentException if the provided cpi is not a valid constant pool index.
+     */
+    Object getObject(Class<?> clazz, int cpi) throws UnsupportedConstantPoolTypeException;
+
+    /**
+     * Stores a Class instance in the constant pool and returns the constant pool index.
+     * 
+     * @param value the class to store
+     * @return the new or existing constant pool index of the Class
+     */
+    int putClass(Class<?> value);
+
+    /**
+     * Returns the {@link Class} instance to the given constant pool index.
+     * 
+     * @param cpi the constant pool index
+     * @return stored value
+     * @throws IllegalArgumentException if the constant pool indes is invalid.
+     */
+    Class<?> getClass(int cpi);
+
+    /**
+     * Stores an int value in the constant pool and returns the constant pool index.
+     * 
+     * @param value the value to store
+     * @return the new or existing constant pool index of the value
+     */
+    int putInt(int value);
+
+    /**
+     * Returns the stored int value to the given constant pool index from the constant pool.
+     * 
+     * @param cpi the constant pool index
+     * @return stored value
+     * @throws IllegalArgumentException if the constant pool index is invalid.
+     */
+    int getInt(int cpi);
+
+    /**
+     * Stores a long value in the constant pool and returns the constant pool index.
+     * 
+     * @param value the value to store
+     * @return the new or existing constant pool index of the value
+     */
+    int putLong(long value);
+
+    /**
+     * Returns the stored long value to the given constant pool index from the constant pool.
+     * 
+     * @param cpi the constant pool index
+     * @return the stored value
+     * @throws IllegalArgumentException if the constant pool index is invalid.
+     */
+    long getLong(int cpi);
+
+    /**
+     * Stores a double value in the constant pool and returns the constant pool index.
+     * 
+     * @param value the value to store
+     * @return the new or existing constant pool index of the value
+     */
+    int putDouble(double value);
+
+    /**
+     * Returns the stored double value to the given constant pool index from the constant pool.
+     * 
+     * @param cpi the constant pool index
+     * @return the stored value
+     * @throws IllegalArgumentException if the constant pool index is invalid.
+     */
+    double getDouble(int cpi);
+
+    /**
+     * Stores a float value in the constant pool and returns the constant pool index.
+     * 
+     * @param value the value to store
+     * @return the new or existing constant pool index of the value
+     */
+    int putFloat(float value);
+
+    /**
+     * Returns the stored float value to the given constant pool index from the constant pool.
+     * 
+     * @param cpi the constant pool index
+     * @return the stored value
+     * @throws IllegalArgumentException if the constant pool index is invalid.
+     */
+    float getFloat(int cpi);
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/UnsupportedConstantPoolTypeException.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,50 @@
+/*
+ * Copyright (c) 2012, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.nodes.serial;
+
+/**
+ * Experimental API. May change without notice.
+ */
+public class UnsupportedConstantPoolTypeException extends RuntimeException {
+
+    private static final long serialVersionUID = 1L;
+
+    public UnsupportedConstantPoolTypeException() {
+        super();
+    }
+
+    public UnsupportedConstantPoolTypeException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public UnsupportedConstantPoolTypeException(String message) {
+        super(message);
+    }
+
+    public UnsupportedConstantPoolTypeException(Throwable cause) {
+        super(cause);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/serial/VariableLengthIntBuffer.java	Wed Oct 09 15:33:36 2013 +0200
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2012, 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.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.nodes.serial;
+
+import java.nio.*;
+
+/**
+ * Experimental API. May change without notice. Simple variable length unsigned int buffer backed by
+ * a byte buffer.
+ */
+public class VariableLengthIntBuffer {
+
+    public static final int NULL = -1;
+
+    private ByteBuffer buffer;
+
+    public VariableLengthIntBuffer(ByteBuffer buffer) {
+        this.buffer = buffer;
+    }
+
+    public VariableLengthIntBuffer(byte[] array) {
+        buffer = ByteBuffer.wrap(array);
+    }
+
+    /**
+     * Returns the backing byte buffer.
+     */
+    public ByteBuffer getBuffer() {
+        return buffer;
+    }
+
+    public byte[] getBytes() {
+        int pos = buffer.position();
+        byte[] bytes = new byte[buffer.position()];
+        buffer.rewind();
+        buffer.get(bytes);
+        buffer.position(pos);
+        return bytes;
+    }
+
+    public int get() {
+        byte peekByte = buffer.get(buffer.position());
+        if ((peekByte & 0x80) == 0) {
+            // single byte encoding with prefix 0 (range 127)
+            return buffer.get(); // no bit to be masked
+        } else {
+            if (peekByte == (byte) 0xFF) {
+                buffer.get(); // skip one byte
+                return NULL;
+            }
+            int result = buffer.getInt() & 0x7FFF_FFFF; // first bit masked out
+            assert (result & 0x4000_0000) == 0;
+            return result;
+        }
+    }
+
+    public void put(int i) {
+        ensureCapacity();
+        if (i == NULL) {
+            buffer.put((byte) 0xFF);
+        } else if ((i & 0xFFFF_FF80) == 0) { // 7 bits data
+            buffer.put((byte) i);
+        } else if ((i & 0xC000_0000) == 0) { // 32 bits data
+            buffer.putInt(i | 0x8000_0000); // append leading 1
+        } else {
+            throw new IllegalArgumentException("Integer out of encodeable " + i);
+        }
+    }
+
+    private void ensureCapacity() {
+        if (buffer.position() + 4 > buffer.capacity()) {
+            ByteBuffer newBuffer = ByteBuffer.allocate(buffer.capacity() * 2);
+
+            int pos = buffer.position();
+            buffer.rewind();
+            newBuffer.put(buffer);
+            newBuffer.position(pos);
+
+            buffer = newBuffer;
+        }
+    }
+
+    public boolean hasRemaining() {
+        return buffer.hasRemaining();
+    }
+
+}
--- a/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.dsl.processor/src/com/oracle/truffle/dsl/processor/node/NodeCodeGenerator.java	Wed Oct 09 15:33:36 2013 +0200
@@ -953,6 +953,10 @@
                     }
                 }
 
+                for (CodeExecutableElement method : createImplicitChildrenAccessors()) {
+                    clazz.add(method);
+                }
+
                 clazz.add(createGenericExecuteAndSpecialize(node, rootGroup));
                 clazz.add(createInfoMessage(node));
             }
@@ -962,6 +966,51 @@
             }
         }
 
+        private List<CodeExecutableElement> createImplicitChildrenAccessors() {
+            NodeData node = getModel().getNode();
+            List<CodeExecutableElement> methods = new ArrayList<>();
+            Map<NodeChildData, Set<TypeData>> expectTypes = new HashMap<>();
+            for (ExecutableTypeData executableType : node.getExecutableTypes()) {
+                for (int i = 0; i < executableType.getEvaluatedCount(); i++) {
+                    ActualParameter parameter = executableType.getSignatureParameter(i);
+                    NodeChildData child = node.findChild(parameter.getSpecification().getName());
+                    Set<TypeData> types = expectTypes.get(child);
+                    if (types == null) {
+                        types = new TreeSet<>();
+                        expectTypes.put(child, types);
+                    }
+                    types.add(parameter.getTypeSystemType());
+                }
+            }
+
+            Map<NodeChildData, Set<TypeData>> visitedMap = new HashMap<>();
+            for (SpecializationData spec : node.getSpecializations()) {
+                for (ActualParameter param : spec.getParameters()) {
+                    if (!param.getSpecification().isSignature()) {
+                        continue;
+                    }
+                    NodeChildData child = node.findChild(param.getSpecification().getName());
+                    Set<TypeData> visitedTypeData = visitedMap.get(child);
+                    if (visitedTypeData == null) {
+                        visitedTypeData = new TreeSet<>();
+                        visitedMap.put(child, visitedTypeData);
+                    }
+                    if (visitedTypeData.contains(param.getTypeSystemType())) {
+                        continue;
+                    }
+                    visitedTypeData.add(param.getTypeSystemType());
+
+                    Set<TypeData> expect = expectTypes.get(child);
+                    if (expect == null) {
+                        expect = Collections.emptySet();
+                    }
+
+                    methods.addAll(createExecuteChilds(param, expect));
+                }
+            }
+            return methods;
+        }
+
         private CodeTree truffleBooleanOption(CodeTreeBuilder parent, String name) {
             CodeTreeBuilder builder = parent.create();
             builder.staticReference(getContext().getTruffleTypes().getTruffleOptions(), name);
@@ -1946,37 +1995,130 @@
                         ActualParameter unexpectedParameter) {
             CodeTreeBuilder builder = parent.create();
 
-            TypeData type = param.getTypeSystemType();
-            List<TypeData> targetTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(type);
-
-            if (targetTypes.size() > 1) {
-                boolean elseIf = false;
-                int index = 0;
-                for (TypeData typeData : targetTypes) {
-                    if (index < targetTypes.size() - 1) {
-                        elseIf = builder.startIf(elseIf);
-                        builder.string(typeName(param)).string(" == ").typeLiteral(typeData.getPrimitiveType());
-                        builder.end();
-                        builder.startBlock();
-                    } else {
-                        builder.startElseBlock();
+            ActualParameter sourceParameter = sourceExecutable.findParameter(param.getLocalName());
+
+            String childExecuteName = createExecuteChildMethodName(param, sourceParameter != null);
+            if (childExecuteName != null) {
+                builder.string(valueName(param));
+                builder.string(" = ");
+                builder.startCall(childExecuteName);
+
+                for (ActualParameter parameters : sourceExecutable.getParameters()) {
+                    if (parameters.getSpecification().isSignature()) {
+                        continue;
                     }
-
-                    ExecutableTypeData implictExecutableTypeData = child.getNodeData().findExecutableType(typeData, targetExecutable.getEvaluatedCount());
-                    ImplicitCastData cast = child.getNodeData().getTypeSystem().lookupCast(typeData, param.getTypeSystemType());
-                    CodeTree execute = createExecuteExpression(parent, child, sourceExecutable, implictExecutableTypeData, param, unexpectedParameter, cast);
-                    builder.statement(execute);
-                    builder.end();
-                    index++;
+                    builder.string(parameters.getLocalName());
+                }
+
+                if (sourceParameter != null) {
+                    builder.string(valueNameEvaluated(sourceParameter));
                 }
+
+                builder.string(typeName(param));
+
+                builder.end();
             } else {
-                builder.tree(createExecuteExpression(parent, child, sourceExecutable, targetExecutable, param, unexpectedParameter, null));
+                List<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
+                TypeData expectType = sourceParameter != null ? sourceParameter.getTypeSystemType() : null;
+                if (sourceTypes.size() > 1) {
+                    builder.tree(createExecuteExpressions(parent, param, expectType));
+                } else {
+                    builder.tree(createExecuteExpression(parent, child, expectType, targetExecutable, param, unexpectedParameter, null));
+                }
             }
             return builder.getRoot();
         }
 
-        private CodeTree createExecuteExpression(CodeTreeBuilder parent, NodeChildData child, ExecutableTypeData sourceExecutable, ExecutableTypeData targetExecutable,
-                        ActualParameter targetParameter, ActualParameter unexpectedParameter, ImplicitCastData cast) {
+        private String createExecuteChildMethodName(ActualParameter param, boolean expect) {
+            NodeChildData child = getModel().getNode().findChild(param.getSpecification().getName());
+            if (child.getExecuteWith().size() > 0) {
+                return null;
+            }
+            List<TypeData> sourceTypes = child.getNodeData().getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
+            if (sourceTypes.size() <= 1) {
+                return null;
+            }
+            String prefix = expect ? "expect" : "execute";
+            return prefix + Utils.firstLetterUpperCase(child.getName()) + Utils.firstLetterUpperCase(Utils.getSimpleName(param.getType())) + param.getIndex();
+        }
+
+        private List<CodeExecutableElement> createExecuteChilds(ActualParameter param, Set<TypeData> expectTypes) {
+            CodeExecutableElement executeMethod = createExecuteChild(param, null);
+            if (executeMethod == null) {
+                return Collections.emptyList();
+            }
+            List<CodeExecutableElement> childs = new ArrayList<>();
+            childs.add(executeMethod);
+
+            for (TypeData expectType : expectTypes) {
+                CodeExecutableElement method = createExecuteChild(param, expectType);
+                if (method != null) {
+                    childs.add(method);
+                }
+            }
+            return childs;
+        }
+
+        private CodeExecutableElement createExecuteChild(ActualParameter param, TypeData expectType) {
+            String childExecuteName = createExecuteChildMethodName(param, expectType != null);
+            if (childExecuteName == null) {
+                return null;
+            }
+
+            CodeExecutableElement method = new CodeExecutableElement(modifiers(PROTECTED, expectType != null ? STATIC : FINAL), param.getType(), childExecuteName);
+            method.getThrownTypes().add(getContext().getTruffleTypes().getUnexpectedValueException());
+            method.addParameter(new CodeVariableElement(getContext().getTruffleTypes().getFrame(), "frameValue"));
+            if (expectType != null) {
+                method.addParameter(new CodeVariableElement(expectType.getPrimitiveType(), valueNameEvaluated(param)));
+            }
+            method.addParameter(new CodeVariableElement(getContext().getType(Class.class), typeName(param)));
+
+            CodeTreeBuilder builder = method.createBuilder();
+            builder.declaration(param.getType(), valueName(param));
+            builder.tree(createExecuteExpressions(builder, param, expectType));
+            builder.startReturn().string(valueName(param)).end();
+
+            return method;
+        }
+
+        private CodeTree createExecuteExpressions(CodeTreeBuilder parent, ActualParameter param, TypeData expectType) {
+            CodeTreeBuilder builder = parent.create();
+            NodeData node = getModel().getNode();
+            NodeChildData child = node.findChild(param.getSpecification().getName());
+            List<TypeData> sourceTypes = node.getTypeSystem().lookupSourceTypes(param.getTypeSystemType());
+            boolean elseIf = false;
+            int index = 0;
+            for (TypeData sourceType : sourceTypes) {
+                if (index < sourceTypes.size() - 1) {
+                    elseIf = builder.startIf(elseIf);
+                    builder.string(typeName(param)).string(" == ").typeLiteral(sourceType.getPrimitiveType());
+                    builder.end();
+                    builder.startBlock();
+                } else {
+                    builder.startElseBlock();
+                }
+
+                ExecutableTypeData implictExecutableTypeData = child.getNodeData().findExecutableType(sourceType, child.getExecuteWith().size());
+                if (implictExecutableTypeData == null) {
+                    /*
+                     * For children with executeWith.size() > 0 an executable type may not exist so
+                     * use the generic executable type which is guaranteed to exist. An expect call
+                     * is inserted automatically by #createExecuteExpression.
+                     */
+                    implictExecutableTypeData = child.getNodeData().findExecutableType(node.getTypeSystem().getGenericTypeData(), child.getExecuteWith().size());
+                }
+
+                ImplicitCastData cast = child.getNodeData().getTypeSystem().lookupCast(sourceType, param.getTypeSystemType());
+                CodeTree execute = createExecuteExpression(builder, child, expectType, implictExecutableTypeData, param, null, cast);
+                builder.statement(execute);
+                builder.end();
+                index++;
+            }
+            return builder.getRoot();
+        }
+
+        private CodeTree createExecuteExpression(CodeTreeBuilder parent, NodeChildData child, TypeData expectType, ExecutableTypeData targetExecutable, ActualParameter targetParameter,
+                        ActualParameter unexpectedParameter, ImplicitCastData cast) {
             CodeTreeBuilder builder = parent.create();
             builder.string(valueName(targetParameter));
             builder.string(" = ");
@@ -1984,17 +2126,21 @@
                 startCallTypeSystemMethod(getContext(), builder, child.getNodeData(), cast.getMethodName());
             }
 
-            if (targetExecutable.getType().needsCastTo(context, targetParameter.getTypeSystemType()) && cast == null) {
-                startCallTypeSystemMethod(getContext(), builder, child.getNodeData(), TypeSystemCodeGenerator.expectTypeMethodName(targetParameter.getTypeSystemType()));
+            TypeData expectTarget = targetParameter.getTypeSystemType();
+            if (cast != null) {
+                expectTarget = cast.getSourceType();
+            }
+
+            if (targetExecutable.getType().needsCastTo(context, expectTarget)) {
+                startCallTypeSystemMethod(getContext(), builder, child.getNodeData(), TypeSystemCodeGenerator.expectTypeMethodName(expectTarget));
             }
 
             NodeData node = getModel().getNode();
-            ActualParameter sourceParameter = sourceExecutable.findParameter(targetParameter.getLocalName());
-            if (sourceParameter == null) {
+            if (expectType == null) {
                 builder.tree(createExecuteChildExpression(builder, child, targetParameter, targetExecutable, unexpectedParameter));
             } else {
                 CodeTree var = CodeTreeBuilder.singleString(valueNameEvaluated(targetParameter));
-                builder.tree(createExpectExecutableType(node, sourceParameter.getTypeSystemType(), targetExecutable, var));
+                builder.tree(createExpectExecutableType(node, expectType, targetExecutable, var));
             }
 
             if (targetExecutable.getType().needsCastTo(context, targetParameter.getTypeSystemType())) {
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/NodeFactory.java	Wed Oct 09 15:33:36 2013 +0200
@@ -63,7 +63,7 @@
     }
 
     public TypedNode createStringLiteral(String value) {
-        return StringLiteralNodeFactory.create(value);
+        return new StringLiteralNode(value);
     }
 
     public StatementNode createAssignment(String name, TypedNode right) {
@@ -112,9 +112,9 @@
 
     public TypedNode createNumericLiteral(String value) {
         try {
-            return IntegerLiteralNodeFactory.create(Integer.parseInt(value));
+            return new IntegerLiteralNode(Integer.parseInt(value));
         } catch (NumberFormatException ex) {
-            return BigIntegerLiteralNodeFactory.create(new BigInteger(value));
+            return new BigIntegerLiteralNode(new BigInteger(value));
         }
     }
 
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/BigIntegerLiteralNode.java	Wed Oct 09 15:33:36 2013 +0200
@@ -24,9 +24,10 @@
 
 import java.math.*;
 
-import com.oracle.truffle.api.dsl.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.nodes.*;
 
-public abstract class BigIntegerLiteralNode extends TypedNode {
+public final class BigIntegerLiteralNode extends TypedNode {
 
     private final BigInteger value;
 
@@ -34,8 +35,14 @@
         this.value = value;
     }
 
-    @Specialization
-    public BigInteger doBigInteger() {
+    @Override
+    public BigInteger executeBigInteger(VirtualFrame frame) throws UnexpectedResultException {
         return value;
     }
+
+    @Override
+    public Object executeGeneric(VirtualFrame frame) {
+        return value;
+    }
+
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/IntegerLiteralNode.java	Wed Oct 09 15:33:36 2013 +0200
@@ -22,9 +22,10 @@
  */
 package com.oracle.truffle.sl.nodes;
 
-import com.oracle.truffle.api.dsl.*;
+import com.oracle.truffle.api.frame.*;
+import com.oracle.truffle.api.nodes.*;
 
-public abstract class IntegerLiteralNode extends TypedNode {
+public final class IntegerLiteralNode extends TypedNode {
 
     private final int value;
 
@@ -32,8 +33,13 @@
         this.value = value;
     }
 
-    @Specialization
-    protected int doInteger() {
-        return this.value;
+    @Override
+    public int executeInteger(VirtualFrame frame) throws UnexpectedResultException {
+        return value;
+    }
+
+    @Override
+    public Object executeGeneric(VirtualFrame frame) {
+        return value;
     }
 }
--- a/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java	Tue Oct 08 21:47:46 2013 +0200
+++ b/graal/com.oracle.truffle.sl/src/com/oracle/truffle/sl/nodes/StringLiteralNode.java	Wed Oct 09 15:33:36 2013 +0200
@@ -22,9 +22,9 @@
  */
 package com.oracle.truffle.sl.nodes;
 
-import com.oracle.truffle.api.dsl.*;
+import com.oracle.truffle.api.frame.*;
 
-public abstract class StringLiteralNode extends TypedNode {
+public final class StringLiteralNode extends TypedNode {
 
     private final String value;
 
@@ -32,8 +32,14 @@
         this.value = value;
     }
 
-    @Specialization
-    protected String doString() {
+    @Override
+    public String executeString(VirtualFrame frame) {
         return value;
     }
+
+    @Override
+    public Object executeGeneric(VirtualFrame frame) {
+        return value;
+    }
+
 }