comparison truffle/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/DirectCallNode.java @ 21951:9c8c0937da41

Moving all sources into truffle subdirectory
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 17 Jun 2015 10:58:08 +0200
parents graal/com.oracle.truffle.api/src/com/oracle/truffle/api/nodes/DirectCallNode.java@57f3498a51a4
children dc83cc1f94f2
comparison
equal deleted inserted replaced
21950:2a5011c7e641 21951:9c8c0937da41
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 call site
36 * sensitive AST duplication. Inlining inlines this call site into the call graph of the parent
37 * {@link CallTarget}. Call site sensitive AST duplication duplicates the {@link CallTarget} in an
38 * uninitialized state to collect call site sensitive 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 #cloneCallTarget()
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 * @deprecated we do not expose this information any longer. returns always false.
106 */
107 @SuppressWarnings("static-method")
108 @Deprecated
109 public final boolean isInlined() {
110 return false;
111 }
112
113 /**
114 * Returns <code>true</code> if the runtime system supports cloning and the {@link RootNode}
115 * returns <code>true</code> in {@link RootNode#isCloningAllowed()}.
116 *
117 * @return <code>true</code> if the target is allowed to be cloned.
118 */
119 public abstract boolean isCallTargetCloningAllowed();
120
121 /**
122 * Clones the {@link CallTarget} instance returned by {@link #getCallTarget()} in an
123 * uninitialized state for this {@link DirectCallNode}. This can be sensible to gather call site
124 * sensitive profiling information for this {@link DirectCallNode}. If
125 * {@link #isCallTargetCloningAllowed()} returns <code>false</code> this method has no effect
126 * and returns <code>false</code>.
127 */
128 public abstract boolean cloneCallTarget();
129
130 /**
131 * Returns <code>true</code> if the target of the {@link DirectCallNode} was cloned by the
132 * runtime system or by the guest language implementation.
133 *
134 * @return if the target was split
135 */
136 public final boolean isCallTargetCloned() {
137 return getClonedCallTarget() != null;
138 }
139
140 /**
141 * Returns the split {@link CallTarget} if this call site's {@link CallTarget} is cloned.
142 *
143 * @return the split {@link CallTarget}
144 */
145 public abstract CallTarget getClonedCallTarget();
146
147 /**
148 * Returns the used call target when {@link #call(VirtualFrame, Object[])} is invoked. If the
149 * {@link CallTarget} was split this method returns the {@link CallTarget} returned by
150 * {@link #getClonedCallTarget()}.
151 *
152 * @return the used {@link CallTarget} when node is called
153 */
154 public CallTarget getCurrentCallTarget() {
155 CallTarget split = getClonedCallTarget();
156 if (split != null) {
157 return split;
158 } else {
159 return getCallTarget();
160 }
161 }
162
163 /**
164 * Returns the {@link RootNode} associated with {@link CallTarget} returned by
165 * {@link #getCurrentCallTarget()}. If the stored {@link CallTarget} does not contain a
166 * {@link RootNode} this method returns <code>null</code>.
167 *
168 * @see #getCurrentCallTarget()
169 * @return the root node of the used call target
170 */
171 public final RootNode getCurrentRootNode() {
172 CallTarget target = getCurrentCallTarget();
173 if (target instanceof RootCallTarget) {
174 return ((RootCallTarget) target).getRootNode();
175 }
176 return null;
177 }
178
179 @Override
180 public String toString() {
181 return String.format("%s(target=%s)", getClass().getSimpleName(), getCurrentCallTarget());
182 }
183
184 public static DirectCallNode create(CallTarget target) {
185 return Truffle.getRuntime().createDirectCallNode(target);
186 }
187
188 }