comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/DirectCallNode.java @ 15093:5634b199c4da

Truffle: API-change: renamed CallNode to DirectCallNode and added IndirectCallNode.
author Christian Humer <christian.humer@gmail.com>
date Mon, 14 Apr 2014 20:32:25 +0200
parents graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/CallNode.java@07e7aae05983
children 40d0022115ee
comparison
equal deleted inserted replaced
15092:c73ce0dd3583 15093:5634b199c4da
1 /*
2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 package com.oracle.truffle.api.nodes;
26
27 import com.oracle.truffle.api.*;
28 import com.oracle.truffle.api.frame.*;
29
30 /**
31 * Represents a direct call to a {@link CallTarget}. Direct calls are calls for which the
32 * {@link CallTarget} remains the same for each consecutive call. This part of the Truffle API
33 * enables the runtime system to perform additional optimizations on direct calls.
34 *
35 * Optimizations that can be applied to a {@link DirectCallNode} are inlining and splitting.
36 * Inlining inlines this call site into the call graph of the parent {@link CallTarget}. Splitting
37 * duplicates the {@link CallTarget} using {@link RootNode#split()} to collect call site sensitive
38 * profiling information.
39 *
40 * Please note: This class is not intended to be subclassed by guest language implementations.
41 *
42 * @see IndirectCallNode for calls with a non-constant target
43 * @see TruffleRuntime#createDirectCallNode(CallTarget)
44 * @see #forceInlining()
45 * @see #split()
46 */
47 public abstract class DirectCallNode extends Node {
48
49 protected final CallTarget callTarget;
50
51 protected DirectCallNode(CallTarget callTarget) {
52 this.callTarget = callTarget;
53 }
54
55 /**
56 * Calls the inner {@link CallTarget} returned by {@link #getCurrentCallTarget()}.
57 *
58 * @param arguments the arguments that should be passed to the callee
59 * @return the return result of the call
60 */
61 public abstract Object call(VirtualFrame frame, Object[] arguments);
62
63 /**
64 * Returns the originally supplied {@link CallTarget} when this call node was created. Please
65 * note that the returned {@link CallTarget} is not necessarily the {@link CallTarget} that is
66 * called. For that use {@link #getCurrentCallTarget()} instead.
67 *
68 * @return the {@link CallTarget} provided.
69 */
70 public CallTarget getCallTarget() {
71 return callTarget;
72 }
73
74 /**
75 * Returns <code>true</code> if the underlying runtime system supports inlining for the
76 * {@link CallTarget} in this {@link DirectCallNode}.
77 *
78 * @return true if inlining is supported.
79 */
80 public abstract boolean isInlinable();
81
82 /**
83 * Returns <code>true</code> if the {@link CallTarget} is forced to be inlined. A
84 * {@link DirectCallNode} can either be inlined manually by invoking {@link #forceInlining()} or
85 * by the runtime system which may at any point decide to inline.
86 *
87 * @return true if this method was inlined else false.
88 */
89 public abstract boolean isInliningForced();
90
91 /**
92 * Enforces the runtime system to inline the {@link CallTarget} at this call site. If the
93 * runtime system does not support inlining or it is already inlined this method has no effect.
94 * The runtime system may decide to not inline calls which were forced to inline.
95 */
96 public abstract void forceInlining();
97
98 /**
99 * Returns true if the runtime system has decided to inline this call-site. If the
100 * {@link DirectCallNode} was forced to inline then this does not necessarily mean that the
101 * {@link DirectCallNode} is really going to be inlined. This depends on whether or not the
102 * runtime system supports inlining. The runtime system may also decide to not inline calls
103 * which were forced to inline.
104 */
105 public abstract boolean isInlined();
106
107 /**
108 * Returns <code>true</code> if this {@link DirectCallNode} can be split. A
109 * {@link DirectCallNode} can only be split if the runtime system supports splitting and if the
110 * {@link RootNode} contained the {@link CallTarget} returns <code>true</code> for
111 * {@link RootNode#isSplittable()}.
112 *
113 * @return <code>true</code> if the target can be split
114 */
115 public abstract boolean isSplittable();
116
117 /**
118 * Enforces the runtime system to split the {@link CallTarget}. If the {@link DirectCallNode} is
119 * not splittable this methods has no effect.
120 */
121 public abstract boolean split();
122
123 /**
124 * Returns <code>true</code> if the target of the {@link DirectCallNode} was split.
125 *
126 * @return if the target was split
127 */
128 public final boolean isSplit() {
129 return getSplitCallTarget() != null;
130 }
131
132 /**
133 * Returns the split {@link CallTarget} if this method is split.
134 *
135 * @return the split {@link CallTarget}
136 */
137 public abstract CallTarget getSplitCallTarget();
138
139 /**
140 * Returns the used call target when {@link #call(VirtualFrame, Object[])} is invoked. If the
141 * {@link CallTarget} was split this method returns the {@link CallTarget} returned by
142 * {@link #getSplitCallTarget()}.
143 *
144 * @return the used {@link CallTarget} when node is called
145 */
146 public CallTarget getCurrentCallTarget() {
147 CallTarget split = getSplitCallTarget();
148 if (split != null) {
149 return split;
150 } else {
151 return getCallTarget();
152 }
153 }
154
155 /**
156 * Returns the {@link RootNode} associated with {@link CallTarget} returned by
157 * {@link #getCurrentCallTarget()}. If the stored {@link CallTarget} does not contain a
158 * {@link RootNode} this method returns <code>null</code>.
159 *
160 * @see #getCurrentCallTarget()
161 * @return the root node of the used call target
162 */
163 public final RootNode getCurrentRootNode() {
164 CallTarget target = getCurrentCallTarget();
165 if (target instanceof RootCallTarget) {
166 return ((RootCallTarget) target).getRootNode();
167 }
168 return null;
169 }
170 }