43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2011, 2016, 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.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
package org.graalvm.compiler.nodes;
|
|
24 |
|
46509
|
25 |
import jdk.vm.ci.meta.JavaKind;
|
46551
|
26 |
|
43972
|
27 |
import org.graalvm.compiler.core.common.type.Stamp;
|
|
28 |
import org.graalvm.compiler.graph.Node;
|
|
29 |
import org.graalvm.compiler.graph.NodeClass;
|
|
30 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
31 |
import org.graalvm.compiler.nodeinfo.Verbosity;
|
|
32 |
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
|
|
33 |
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
|
|
34 |
import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
|
|
35 |
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
|
36 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
37 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
38 |
import org.graalvm.compiler.nodes.spi.UncheckedInterfaceProvider;
|
|
39 |
import org.graalvm.compiler.nodes.util.GraphUtil;
|
46551
|
40 |
import org.graalvm.word.LocationIdentity;
|
43972
|
41 |
|
46509
|
42 |
import java.util.Map;
|
|
43 |
|
|
44 |
import static org.graalvm.compiler.nodeinfo.InputType.Extension;
|
|
45 |
import static org.graalvm.compiler.nodeinfo.InputType.Memory;
|
|
46 |
import static org.graalvm.compiler.nodeinfo.InputType.State;
|
|
47 |
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
|
|
48 |
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN;
|
43972
|
49 |
|
|
50 |
@NodeInfo(nameTemplate = "Invoke!#{p#targetMethod/s}", allowedUsageTypes = {Memory}, cycles = CYCLES_UNKNOWN, size = SIZE_UNKNOWN)
|
|
51 |
public final class InvokeWithExceptionNode extends ControlSplitNode implements Invoke, MemoryCheckpoint.Single, LIRLowerable, UncheckedInterfaceProvider {
|
|
52 |
public static final NodeClass<InvokeWithExceptionNode> TYPE = NodeClass.create(InvokeWithExceptionNode.class);
|
|
53 |
|
|
54 |
private static final double EXCEPTION_PROBA = 1e-5;
|
|
55 |
|
|
56 |
@Successor AbstractBeginNode next;
|
|
57 |
@Successor AbstractBeginNode exceptionEdge;
|
|
58 |
@OptionalInput ValueNode classInit;
|
|
59 |
@Input(Extension) CallTargetNode callTarget;
|
|
60 |
@OptionalInput(State) FrameState stateDuring;
|
|
61 |
@OptionalInput(State) FrameState stateAfter;
|
|
62 |
protected final int bci;
|
|
63 |
protected boolean polymorphic;
|
|
64 |
protected boolean useForInlining;
|
|
65 |
protected double exceptionProbability;
|
|
66 |
|
|
67 |
public InvokeWithExceptionNode(CallTargetNode callTarget, AbstractBeginNode exceptionEdge, int bci) {
|
|
68 |
super(TYPE, callTarget.returnStamp().getTrustedStamp());
|
|
69 |
this.exceptionEdge = exceptionEdge;
|
|
70 |
this.bci = bci;
|
|
71 |
this.callTarget = callTarget;
|
|
72 |
this.polymorphic = false;
|
|
73 |
this.useForInlining = true;
|
|
74 |
this.exceptionProbability = EXCEPTION_PROBA;
|
|
75 |
}
|
|
76 |
|
49451
|
77 |
@Override
|
|
78 |
protected void afterClone(Node other) {
|
|
79 |
updateInliningLogAfterClone(other);
|
|
80 |
}
|
|
81 |
|
|
82 |
@Override
|
|
83 |
public FixedNode asFixedNode() {
|
|
84 |
return this;
|
|
85 |
}
|
|
86 |
|
43972
|
87 |
public AbstractBeginNode exceptionEdge() {
|
|
88 |
return exceptionEdge;
|
|
89 |
}
|
|
90 |
|
|
91 |
public void setExceptionEdge(AbstractBeginNode x) {
|
|
92 |
updatePredecessor(exceptionEdge, x);
|
|
93 |
exceptionEdge = x;
|
|
94 |
}
|
|
95 |
|
|
96 |
@Override
|
|
97 |
public AbstractBeginNode next() {
|
|
98 |
return next;
|
|
99 |
}
|
|
100 |
|
|
101 |
public void setNext(AbstractBeginNode x) {
|
|
102 |
updatePredecessor(next, x);
|
|
103 |
next = x;
|
|
104 |
}
|
|
105 |
|
|
106 |
@Override
|
|
107 |
public CallTargetNode callTarget() {
|
|
108 |
return callTarget;
|
|
109 |
}
|
|
110 |
|
|
111 |
void setCallTarget(CallTargetNode callTarget) {
|
|
112 |
updateUsages(this.callTarget, callTarget);
|
|
113 |
this.callTarget = callTarget;
|
|
114 |
}
|
|
115 |
|
|
116 |
public MethodCallTargetNode methodCallTarget() {
|
|
117 |
return (MethodCallTargetNode) callTarget;
|
|
118 |
}
|
|
119 |
|
|
120 |
@Override
|
|
121 |
public boolean isPolymorphic() {
|
|
122 |
return polymorphic;
|
|
123 |
}
|
|
124 |
|
|
125 |
@Override
|
|
126 |
public void setPolymorphic(boolean value) {
|
|
127 |
this.polymorphic = value;
|
|
128 |
}
|
|
129 |
|
|
130 |
@Override
|
|
131 |
public boolean useForInlining() {
|
|
132 |
return useForInlining;
|
|
133 |
}
|
|
134 |
|
|
135 |
@Override
|
|
136 |
public void setUseForInlining(boolean value) {
|
|
137 |
this.useForInlining = value;
|
|
138 |
}
|
|
139 |
|
|
140 |
@Override
|
|
141 |
public String toString(Verbosity verbosity) {
|
|
142 |
if (verbosity == Verbosity.Long) {
|
|
143 |
return super.toString(Verbosity.Short) + "(bci=" + bci() + ")";
|
|
144 |
} else if (verbosity == Verbosity.Name) {
|
|
145 |
return "Invoke#" + (callTarget == null ? "null" : callTarget().targetName());
|
|
146 |
} else {
|
|
147 |
return super.toString(verbosity);
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
@Override
|
|
152 |
public int bci() {
|
|
153 |
return bci;
|
|
154 |
}
|
|
155 |
|
|
156 |
@Override
|
|
157 |
public void setNext(FixedNode x) {
|
|
158 |
if (x != null) {
|
|
159 |
this.setNext(KillingBeginNode.begin(x, getLocationIdentity()));
|
|
160 |
} else {
|
|
161 |
this.setNext(null);
|
|
162 |
}
|
|
163 |
}
|
|
164 |
|
|
165 |
@Override
|
|
166 |
public void lower(LoweringTool tool) {
|
|
167 |
tool.getLowerer().lower(this, tool);
|
|
168 |
}
|
|
169 |
|
|
170 |
@Override
|
|
171 |
public void generate(NodeLIRBuilderTool gen) {
|
|
172 |
gen.emitInvoke(this);
|
|
173 |
}
|
|
174 |
|
|
175 |
@Override
|
|
176 |
public FrameState stateAfter() {
|
|
177 |
return stateAfter;
|
|
178 |
}
|
|
179 |
|
|
180 |
@Override
|
|
181 |
public void setStateAfter(FrameState stateAfter) {
|
|
182 |
updateUsages(this.stateAfter, stateAfter);
|
|
183 |
this.stateAfter = stateAfter;
|
|
184 |
}
|
|
185 |
|
|
186 |
@Override
|
|
187 |
public boolean hasSideEffect() {
|
|
188 |
return true;
|
|
189 |
}
|
|
190 |
|
|
191 |
@Override
|
|
192 |
public LocationIdentity getLocationIdentity() {
|
|
193 |
return LocationIdentity.any();
|
|
194 |
}
|
|
195 |
|
|
196 |
@Override
|
|
197 |
public Map<Object, Object> getDebugProperties(Map<Object, Object> map) {
|
|
198 |
Map<Object, Object> debugProperties = super.getDebugProperties(map);
|
|
199 |
if (callTarget != null) {
|
|
200 |
debugProperties.put("targetMethod", callTarget.targetName());
|
|
201 |
}
|
|
202 |
return debugProperties;
|
|
203 |
}
|
|
204 |
|
|
205 |
public void killExceptionEdge() {
|
|
206 |
AbstractBeginNode edge = exceptionEdge();
|
|
207 |
setExceptionEdge(null);
|
|
208 |
GraphUtil.killCFG(edge);
|
|
209 |
}
|
|
210 |
|
46509
|
211 |
public void replaceWithNewBci(int newBci) {
|
|
212 |
AbstractBeginNode nextNode = next();
|
|
213 |
AbstractBeginNode exceptionObject = exceptionEdge;
|
|
214 |
setExceptionEdge(null);
|
|
215 |
setNext(null);
|
|
216 |
InvokeWithExceptionNode repl = graph().add(new InvokeWithExceptionNode(callTarget(), exceptionObject, newBci));
|
|
217 |
repl.setStateAfter(stateAfter);
|
|
218 |
this.setStateAfter(null);
|
|
219 |
this.replaceAtPredecessor(repl);
|
|
220 |
repl.setNext(nextNode);
|
|
221 |
boolean removed = this.callTarget().removeUsage(this);
|
|
222 |
assert removed;
|
|
223 |
this.replaceAtUsages(repl);
|
|
224 |
this.markDeleted();
|
|
225 |
}
|
|
226 |
|
43972
|
227 |
@Override
|
|
228 |
public void intrinsify(Node node) {
|
|
229 |
assert !(node instanceof ValueNode) || (((ValueNode) node).getStackKind() == JavaKind.Void) == (getStackKind() == JavaKind.Void);
|
|
230 |
CallTargetNode call = callTarget;
|
|
231 |
FrameState state = stateAfter();
|
46509
|
232 |
if (exceptionEdge != null) {
|
|
233 |
killExceptionEdge();
|
|
234 |
}
|
43972
|
235 |
if (node instanceof StateSplit) {
|
|
236 |
StateSplit stateSplit = (StateSplit) node;
|
|
237 |
stateSplit.setStateAfter(state);
|
|
238 |
}
|
|
239 |
if (node instanceof ForeignCallNode) {
|
|
240 |
ForeignCallNode foreign = (ForeignCallNode) node;
|
|
241 |
foreign.setBci(bci());
|
|
242 |
}
|
|
243 |
if (node == null) {
|
|
244 |
assert getStackKind() == JavaKind.Void && hasNoUsages();
|
|
245 |
graph().removeSplit(this, next());
|
|
246 |
} else if (node instanceof ControlSinkNode) {
|
|
247 |
this.replaceAtPredecessor(node);
|
|
248 |
this.replaceAtUsages(null);
|
|
249 |
GraphUtil.killCFG(this);
|
|
250 |
return;
|
|
251 |
} else {
|
|
252 |
graph().replaceSplit(this, node, next());
|
|
253 |
}
|
|
254 |
GraphUtil.killWithUnusedFloatingInputs(call);
|
|
255 |
if (state.hasNoUsages()) {
|
|
256 |
GraphUtil.killWithUnusedFloatingInputs(state);
|
|
257 |
}
|
|
258 |
}
|
|
259 |
|
|
260 |
@Override
|
|
261 |
public double probability(AbstractBeginNode successor) {
|
|
262 |
return successor == next ? 1 - exceptionProbability : exceptionProbability;
|
|
263 |
}
|
|
264 |
|
|
265 |
@Override
|
|
266 |
public boolean canDeoptimize() {
|
|
267 |
return true;
|
|
268 |
}
|
|
269 |
|
|
270 |
@Override
|
|
271 |
public FrameState stateDuring() {
|
|
272 |
return stateDuring;
|
|
273 |
}
|
|
274 |
|
|
275 |
@Override
|
|
276 |
public void setStateDuring(FrameState stateDuring) {
|
|
277 |
updateUsages(this.stateDuring, stateDuring);
|
|
278 |
this.stateDuring = stateDuring;
|
|
279 |
}
|
|
280 |
|
|
281 |
@Override
|
|
282 |
public AbstractBeginNode getPrimarySuccessor() {
|
|
283 |
return this.next();
|
|
284 |
}
|
|
285 |
|
|
286 |
@Override
|
|
287 |
public Stamp uncheckedStamp() {
|
|
288 |
return this.callTarget.returnStamp().getUncheckedStamp();
|
|
289 |
}
|
|
290 |
|
|
291 |
@Override
|
|
292 |
public void setClassInit(ValueNode classInit) {
|
|
293 |
this.classInit = classInit;
|
|
294 |
updateUsages(null, classInit);
|
|
295 |
}
|
|
296 |
|
|
297 |
@Override
|
|
298 |
public ValueNode classInit() {
|
|
299 |
return classInit;
|
|
300 |
}
|
46344
|
301 |
|
|
302 |
@Override
|
|
303 |
public boolean setProbability(AbstractBeginNode successor, double value) {
|
|
304 |
// Cannot set probability for exception invokes.
|
|
305 |
return false;
|
|
306 |
}
|
|
307 |
|
|
308 |
@Override
|
|
309 |
public int getSuccessorCount() {
|
|
310 |
return 2;
|
|
311 |
}
|
46509
|
312 |
|
|
313 |
/**
|
|
314 |
* Replaces this InvokeWithExceptionNode with a normal InvokeNode. Kills the exception dispatch
|
|
315 |
* code.
|
|
316 |
*/
|
|
317 |
public InvokeNode replaceWithInvoke() {
|
|
318 |
InvokeNode invokeNode = graph().add(new InvokeNode(callTarget, bci));
|
|
319 |
AbstractBeginNode oldException = this.exceptionEdge;
|
|
320 |
graph().replaceSplitWithFixed(this, invokeNode, this.next());
|
|
321 |
GraphUtil.killCFG(oldException);
|
|
322 |
return invokeNode;
|
|
323 |
}
|
43972
|
324 |
}
|