annotate graal/com.oracle.truffle.api.dsl/src/com/oracle/truffle/api/dsl/internal/SpecializationNode.java @ 19289:62c43fcf5be2

Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
author Christian Humer <christian.humer@gmail.com>
date Tue, 03 Feb 2015 15:07:07 +0100
parents 92880b0f7fed
children f4792a544170
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
1 /*
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
4 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
10 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
15 * accompanied this code).
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
16 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
20 *
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
23 * questions.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
24 */
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
25 package com.oracle.truffle.api.dsl.internal;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
26
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
27 import java.lang.reflect.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
28 import java.util.concurrent.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
29
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
30 import com.oracle.truffle.api.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
31 import com.oracle.truffle.api.dsl.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
32 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent0;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
33 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
34 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
35 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent3;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
36 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEvent4;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
37 import com.oracle.truffle.api.dsl.internal.RewriteEvent.RewriteEventN;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
38 import com.oracle.truffle.api.frame.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
39 import com.oracle.truffle.api.nodes.*;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
40 import com.oracle.truffle.api.nodes.NodeUtil.NodeClass;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
41 import com.oracle.truffle.api.nodes.NodeUtil.NodeField;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
42
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
43 /**
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
44 * Internal implementation dependent base class for generated specialized nodes.
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
45 */
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
46 @SuppressWarnings("unused")
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
47 @NodeInfo(cost = NodeCost.NONE)
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
48 public abstract class SpecializationNode extends Node {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
49
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
50 @Child protected SpecializationNode next;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
51
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
52 private final int index;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
53
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
54 public SpecializationNode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
55 this(-1);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
56 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
57
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
58 public SpecializationNode(int index) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
59 this.index = index;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
60 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
61
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
62 @Override
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
63 public final NodeCost getCost() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
64 return NodeCost.NONE;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
65 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
66
19281
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
67 public void reset() {
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
68 SpecializationNode start = findStart();
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
69 SpecializationNode end = findEnd();
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
70 if (start != end) {
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
71 start.replace(end, "reset specialization");
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
72 }
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
73 }
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
74
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
75 public static Node updateRoot(Node node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
76 updateRootImpl(((SpecializedNode) node).getSpecializationNode(), node);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
77 return node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
78 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
79
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
80 private static void updateRootImpl(SpecializationNode start, Node node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
81 NodeField[] fields = NodeClass.get(start.getClass()).getFields();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
82 for (int i = fields.length - 1; i >= 0; i--) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
83 NodeField f = fields[i];
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
84 if (f.getName().equals("root")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
85 f.putObject(start, node);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
86 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
87 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
88 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
89 if (start.next != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
90 updateRootImpl(start.next, node);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
91 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
92 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
93
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
94 protected final SpecializationNode polymorphicMerge(SpecializationNode newNode) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
95 SpecializationNode merged = next.merge(newNode);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
96 if (merged == newNode && !isSame(newNode) && count() <= 2) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
97 return removeSame(new RewriteEvent0(findRoot(), "merged polymorphic to monomorphic"));
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
98 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
99 return merged;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
100 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
101
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
102 public final NodeCost getNodeCost() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
103 switch (count()) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
104 case 0:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
105 case 1:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
106 return NodeCost.UNINITIALIZED;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
107 case 2:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
108 return NodeCost.MONOMORPHIC;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
109 default:
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
110 return NodeCost.POLYMORPHIC;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
111 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
112 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
113
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
114 protected abstract Node[] getSuppliedChildren();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
115
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
116 protected SpecializationNode merge(SpecializationNode newNode) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
117 if (this.isSame(newNode)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
118 return this;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
119 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
120 return next != null ? next.merge(newNode) : newNode;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
121 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
122
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
123 protected SpecializationNode mergeNoSame(SpecializationNode newNode) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
124 return next != null ? next.merge(newNode) : newNode;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
125 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
126
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
127 protected final int countSame(SpecializationNode node) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
128 return findStart().countSameImpl(node);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
129 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
130
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
131 private int countSameImpl(SpecializationNode node) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
132 if (next != null) {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
133 return next.countSameImpl(node) + (isSame(node) ? 1 : 0);
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
134 } else {
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
135 return 0;
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
136 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
137 }
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
138
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
139 @Override
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
140 public final boolean equals(Object obj) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
141 if (obj instanceof SpecializationNode) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
142 return ((SpecializationNode) obj).isSame(this);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
143 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
144 return super.equals(obj);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
145 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
146
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
147 @Override
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
148 public final int hashCode() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
149 return index;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
150 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
151
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
152 protected boolean isSame(SpecializationNode other) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
153 return getClass() == other.getClass();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
154 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
155
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
156 private int count() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
157 return next != null ? next.count() + 1 : 1;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
158 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
159
19281
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
160 private SpecializationNode findEnd() {
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
161 SpecializationNode node = this;
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
162 while (node.next != null) {
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
163 node = node.next;
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
164 }
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
165 return node;
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
166 }
92880b0f7fed Truffle-DSL: add internal API support to reset the specialization chain.
Christian Humer <christian.humer@gmail.com>
parents: 18802
diff changeset
167
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
168 protected final SpecializationNode removeSame(final CharSequence reason) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
169 return atomic(new Callable<SpecializationNode>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
170 public SpecializationNode call() throws Exception {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
171 return removeImpl(SpecializationNode.this, reason);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
172 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
173 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
174 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
175
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
176 /** Find the topmost of the specialization chain. */
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
177 private SpecializationNode findStart() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
178 SpecializationNode node = this;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
179 Node parent = this.getParent();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
180 while (parent instanceof SpecializationNode) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
181 SpecializationNode parentCast = ((SpecializationNode) parent);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
182 if (parentCast.next != node) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
183 break;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
184 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
185 node = parentCast;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
186 parent = node.getParent();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
187 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
188 return node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
189 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
190
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
191 private Node findRoot() {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
192 return findStart().getParent();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
193 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
194
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
195 private SpecializationNode removeImpl(SpecializationNode toRemove, CharSequence reason) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
196 SpecializationNode start = findStart();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
197 SpecializationNode current = start;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
198 while (current != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
199 if (current.isSame(toRemove)) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
200 current.replace(current.next, reason);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
201 if (current == start) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
202 start = start.next;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
203 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
204 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
205 current = current.next;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
206 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
207 return findEnd().findStart();
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
208 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
209
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
210 public Object acceptAndExecute(Frame frame) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
211 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
212 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
213
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
214 public Object acceptAndExecute(Frame frame, Object o1) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
215 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
216 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
217
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
218 public Object acceptAndExecute(Frame frame, Object o1, Object o2) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
219 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
220 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
221
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
222 public Object acceptAndExecute(Frame frame, Object o1, Object o2, Object o3) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
223 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
224 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
225
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
226 public Object acceptAndExecute(Frame frame, Object o1, Object o2, Object o3, Object o4) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
227 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
228 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
229
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
230 public Object acceptAndExecute(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
231 throw new UnsupportedOperationException();
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
232 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
233
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
234 public Object acceptAndExecute(Frame frame, Object... args) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
235 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
236 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
237
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
238 protected SpecializationNode createFallback() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
239 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
240 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
241
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
242 protected SpecializationNode createPolymorphic() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
243 return null;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
244 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
245
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
246 protected SpecializationNode createNext(Frame frame) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
247 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
248 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
249
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
250 protected SpecializationNode createNext(Frame frame, Object o1) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
251 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
252 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
253
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
254 protected SpecializationNode createNext(Frame frame, Object o1, Object o2) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
255 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
256 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
257
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
258 protected SpecializationNode createNext(Frame frame, Object o1, Object o2, Object o3) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
259 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
260 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
261
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
262 protected SpecializationNode createNext(Frame frame, Object o1, Object o2, Object o3, Object o4) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
263 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
264 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
265
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
266 protected SpecializationNode createNext(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
267 throw new UnsupportedOperationException();
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
268 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
269
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
270 protected SpecializationNode createNext(Frame frame, Object... args) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
271 throw new UnsupportedOperationException();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
272 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
273
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
274 protected final Object uninitialized(Frame frame) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
275 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
276 SpecializationNode nextSpecialization = createNext(frame);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
277 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
278 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
279 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
280 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
281 return unsupported(frame);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
282 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
283 return insertSpecialization(nextSpecialization, new RewriteEvent0(findRoot(), "inserted new specialization")).acceptAndExecute(frame);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
284 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
285
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
286 protected final Object uninitialized(Frame frame, Object o1) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
287 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
288 SpecializationNode nextSpecialization = createNext(frame, o1);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
289 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
290 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
291 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
292 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
293 return unsupported(frame, o1);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
294 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
295 return insertSpecialization(nextSpecialization, new RewriteEvent1(findRoot(), "inserted new specialization", o1)).acceptAndExecute(frame, o1);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
296 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
297
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
298 protected final Object uninitialized(Frame frame, Object o1, Object o2) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
299 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
300 SpecializationNode nextSpecialization = createNext(frame, o1, o2);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
301 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
302 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
303 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
304 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
305 return unsupported(frame, o1, o2);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
306 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
307 return insertSpecialization(nextSpecialization, new RewriteEvent2(findRoot(), "inserted new specialization", o1, o2)).acceptAndExecute(frame, o1, o2);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
308 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
309
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
310 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
311 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
312 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
313 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
314 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
315 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
316 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
317 return unsupported(frame, o1, o2, o3);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
318 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
319 return insertSpecialization(nextSpecialization, new RewriteEvent3(findRoot(), "inserted new specialization", o1, o2, o3)).acceptAndExecute(frame, o1, o2, o3);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
320 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
321
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
322 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
323 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
324 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
325 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
326 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
327 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
328 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
329 return unsupported(frame, o1, o2, o3, o4);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
330 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
331 return insertSpecialization(nextSpecialization, new RewriteEvent4(findRoot(), "inserts new specialization", o1, o2, o3, o4)).acceptAndExecute(frame, o1, o2, o3, o4);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
332 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
333
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
334 protected final Object uninitialized(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
335 CompilerDirectives.transferToInterpreterAndInvalidate();
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
336 SpecializationNode nextSpecialization = createNext(frame, o1, o2, o3, o4, o5);
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
337 if (nextSpecialization == null) {
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
338 nextSpecialization = createFallback();
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
339 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
340 if (nextSpecialization == null) {
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
341 unsupported(frame, o1, o2, o3, o4, o5);
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
342 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
343 return insertSpecialization(nextSpecialization, new RewriteEventN(findRoot(), "inserts new specialization", o1, o2, o3, o4, o5)).acceptAndExecute(frame, o1, o2, o3, o4, o5);
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
344 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
345
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
346 protected final Object uninitialized(Frame frame, Object... args) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
347 CompilerDirectives.transferToInterpreterAndInvalidate();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
348 SpecializationNode nextSpecialization = createNext(frame, args);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
349 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
350 nextSpecialization = createFallback();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
351 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
352 if (nextSpecialization == null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
353 unsupported(frame, args);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
354 }
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
355 return insertSpecialization(nextSpecialization, new RewriteEventN(findRoot(), "inserts new specialization", args)).acceptAndExecute(frame, args);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
356 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
357
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
358 private boolean needsPolymorphic() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
359 return findStart().count() == 2;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
360 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
361
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
362 protected final Object remove(String reason, Frame frame) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
363 return removeSame(new RewriteEvent0(findRoot(), reason)).acceptAndExecute(frame);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
364 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
365
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
366 protected final Object remove(String reason, Frame frame, Object o1) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
367 return removeSame(new RewriteEvent1(findRoot(), reason, o1)).acceptAndExecute(frame, o1);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
368 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
369
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
370 protected final Object remove(String reason, Frame frame, Object o1, Object o2) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
371 return removeSame(new RewriteEvent2(findRoot(), reason, o1, o2)).acceptAndExecute(frame, o1, o2);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
372 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
373
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
374 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
375 return removeSame(new RewriteEvent3(findRoot(), reason, o1, o2, o3)).acceptAndExecute(frame, o1, o2, o3);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
376 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
377
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
378 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
379 return removeSame(new RewriteEvent4(findRoot(), reason, o1, o2, o3, o4)).acceptAndExecute(frame, o1, o2, o3, o4);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
380 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
381
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
382 protected final Object remove(String reason, Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
383 return removeSame(new RewriteEventN(findRoot(), reason, o1, o2, o3, o4, o5)).acceptAndExecute(frame, o1, o2, o3, o4, o5);
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
384 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
385
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
386 protected final Object remove(String reason, Frame frame, Object... args) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
387 return removeSame(new RewriteEventN(findRoot(), reason, args)).acceptAndExecute(frame, args);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
388 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
389
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
390 protected Object unsupported(Frame frame) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
391 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren());
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
392 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
393
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
394 protected Object unsupported(Frame frame, Object o1) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
395 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), o1);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
396 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
397
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
398 protected Object unsupported(Frame frame, Object o1, Object o2) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
399 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), o1, o2);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
400 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
401
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
402 protected Object unsupported(Frame frame, Object o1, Object o2, Object o3) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
403 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), o1, o2, o3);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
404 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
405
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
406 protected Object unsupported(Frame frame, Object o1, Object o2, Object o3, Object o4) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
407 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), o1, o2, o3, o4);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
408 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
409
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
410 protected Object unsupported(Frame frame, Object o1, Object o2, Object o3, Object o4, Object o5) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
411 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), o1, o2, o3, o4, o5);
18802
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
412 }
71e372cae32e Truffle-DSL: increase maximum number of acceptAndExecute arguments to 5.
Christian Humer <christian.humer@gmail.com>
parents: 18776
diff changeset
413
18776
c0fb70634640 Truffle-DSL: support for frame types Frame, MaterializedFrame. Added validation for frame type consistency. Some refactorings along the way.
Christian Humer <christian.humer@gmail.com>
parents: 18766
diff changeset
414 protected Object unsupported(Frame frame, Object... args) {
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
415 throw new UnsupportedSpecializationException(findRoot(), getSuppliedChildren(), args);
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
416 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
417
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
418 private SpecializationNode insertSpecialization(final SpecializationNode generated, final CharSequence message) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
419 return atomic(new Callable<SpecializationNode>() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
420 public SpecializationNode call() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
421 return insert(generated, message);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
422 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
423 });
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
424 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
425
18766
a720bf2e2f43 Truffle-DSL: checkstyle fixes.
Christian Humer <christian.humer@gmail.com>
parents: 18761
diff changeset
426 private SpecializationNode insert(final SpecializationNode generated, CharSequence message) {
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
427 SpecializationNode start = findStart();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
428 if (start == this) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
429 // fast path for first insert
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
430 return insertBefore(this, generated, message);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
431 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
432 return slowSortedInsert(start, generated, message);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
433 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
434 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
435
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
436 private static <T> SpecializationNode slowSortedInsert(SpecializationNode start, final SpecializationNode generated, final CharSequence message) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
437 final SpecializationNode merged = start.merge(generated);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
438 if (merged == generated) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
439 // new node
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
440 if (start.count() == 2) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
441 insertBefore(start, start.createPolymorphic(), "insert polymorphic");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
442 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
443 SpecializationNode insertBefore = findInsertBeforeNode(generated.index, start);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
444 return insertBefore(insertBefore, generated, message);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
445 } else {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
446 // existing node
19289
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
447 merged.replace(merged, new RewriteEvent0(merged.findRoot(), "merged specialization"));
62c43fcf5be2 Truffle-DSL: implement @Cached and fixes for the new guard expression syntax.
Christian Humer <christian.humer@gmail.com>
parents: 19281
diff changeset
448 return start;
18761
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
449 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
450 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
451
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
452 private static SpecializationNode findInsertBeforeNode(int generatedIndex, SpecializationNode start) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
453 SpecializationNode current = start;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
454 while (current != null && current.index < generatedIndex) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
455 current = current.next;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
456 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
457 return current;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
458 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
459
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
460 private static <T> SpecializationNode insertBefore(SpecializationNode node, SpecializationNode insertBefore, CharSequence message) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
461 insertBefore.next = node;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
462 return node.replace(insertBefore, message);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
463 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
464
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
465 @Override
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
466 public final String toString() {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
467 Class<?> clazz = getClass();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
468 StringBuilder b = new StringBuilder();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
469 b.append(clazz.getSimpleName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
470
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
471 appendFields(b, clazz);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
472 if (next != null) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
473 b.append(" -> ").append(next.toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
474 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
475 return b.toString();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
476 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
477
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
478 private void appendFields(StringBuilder b, Class<?> clazz) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
479 Field[] fields = clazz.getDeclaredFields();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
480 if (fields.length == 0) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
481 return;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
482 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
483 b.append("(");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
484 for (Field field : fields) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
485 if (Modifier.isStatic(field.getModifiers())) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
486 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
487 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
488 String name = field.getName();
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
489 if (name.equals("root")) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
490 continue;
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
491 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
492 b.append(field.getName());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
493 try {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
494 field.setAccessible(true);
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
495 b.append(field.get(this));
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
496 } catch (IllegalArgumentException e) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
497 b.append(e.toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
498 } catch (IllegalAccessException e) {
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
499 b.append(e.toString());
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
500 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
501 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
502 b.append(")");
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
503 }
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
504
a665483c3881 Truffle-DSL: new node layout implementation.
Christian Humer <christian.humer@gmail.com>
parents:
diff changeset
505 }