author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58533 | 46b0b7fe255c |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
58299 | 2 |
* Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 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 |
*/ |
|
50858 | 23 |
|
24 |
||
43972 | 25 |
package org.graalvm.compiler.java; |
26 |
||
27 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP; |
|
28 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2; |
|
29 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2_X1; |
|
30 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP2_X2; |
|
31 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP_X1; |
|
32 |
import static org.graalvm.compiler.bytecode.Bytecodes.DUP_X2; |
|
33 |
import static org.graalvm.compiler.bytecode.Bytecodes.POP; |
|
34 |
import static org.graalvm.compiler.bytecode.Bytecodes.POP2; |
|
35 |
import static org.graalvm.compiler.bytecode.Bytecodes.SWAP; |
|
36 |
import static org.graalvm.compiler.debug.GraalError.shouldNotReachHere; |
|
37 |
import static org.graalvm.compiler.nodes.FrameState.TWO_SLOT_MARKER; |
|
58533 | 38 |
import static org.graalvm.compiler.nodes.util.GraphUtil.originalValue; |
43972 | 39 |
|
40 |
import java.util.ArrayList; |
|
41 |
import java.util.Arrays; |
|
42 |
import java.util.List; |
|
43 |
import java.util.function.Function; |
|
44 |
||
45 |
import org.graalvm.compiler.bytecode.Bytecode; |
|
46 |
import org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode; |
|
46344 | 47 |
import org.graalvm.compiler.core.common.PermanentBailoutException; |
43972 | 48 |
import org.graalvm.compiler.core.common.type.StampFactory; |
49 |
import org.graalvm.compiler.core.common.type.StampPair; |
|
46640 | 50 |
import org.graalvm.compiler.debug.DebugContext; |
54601 | 51 |
import org.graalvm.compiler.debug.GraalError; |
43972 | 52 |
import org.graalvm.compiler.graph.NodeSourcePosition; |
53 |
import org.graalvm.compiler.java.BciBlockMapping.BciBlock; |
|
54 |
import org.graalvm.compiler.nodeinfo.Verbosity; |
|
55 |
import org.graalvm.compiler.nodes.AbstractMergeNode; |
|
56 |
import org.graalvm.compiler.nodes.ConstantNode; |
|
57 |
import org.graalvm.compiler.nodes.FrameState; |
|
58 |
import org.graalvm.compiler.nodes.LoopBeginNode; |
|
59 |
import org.graalvm.compiler.nodes.LoopExitNode; |
|
48190 | 60 |
import org.graalvm.compiler.nodes.NodeView; |
43972 | 61 |
import org.graalvm.compiler.nodes.ParameterNode; |
62 |
import org.graalvm.compiler.nodes.PhiNode; |
|
63 |
import org.graalvm.compiler.nodes.ProxyNode; |
|
64 |
import org.graalvm.compiler.nodes.StateSplit; |
|
65 |
import org.graalvm.compiler.nodes.StructuredGraph; |
|
66 |
import org.graalvm.compiler.nodes.ValueNode; |
|
67 |
import org.graalvm.compiler.nodes.ValuePhiNode; |
|
68 |
import org.graalvm.compiler.nodes.calc.FloatingNode; |
|
69 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; |
|
70 |
import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderTool; |
|
71 |
import org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext.SideEffectsState; |
|
72 |
import org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin; |
|
73 |
import org.graalvm.compiler.nodes.java.MonitorIdNode; |
|
74 |
||
75 |
import jdk.vm.ci.code.BytecodeFrame; |
|
76 |
import jdk.vm.ci.meta.Assumptions; |
|
77 |
import jdk.vm.ci.meta.JavaKind; |
|
78 |
import jdk.vm.ci.meta.JavaType; |
|
79 |
import jdk.vm.ci.meta.ResolvedJavaMethod; |
|
80 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
81 |
import jdk.vm.ci.meta.Signature; |
|
82 |
||
83 |
public final class FrameStateBuilder implements SideEffectsState { |
|
84 |
||
85 |
private static final ValueNode[] EMPTY_ARRAY = new ValueNode[0]; |
|
86 |
private static final MonitorIdNode[] EMPTY_MONITOR_ARRAY = new MonitorIdNode[0]; |
|
87 |
||
88 |
private final BytecodeParser parser; |
|
89 |
private final GraphBuilderTool tool; |
|
90 |
private final Bytecode code; |
|
91 |
private int stackSize; |
|
92 |
protected final ValueNode[] locals; |
|
93 |
protected final ValueNode[] stack; |
|
94 |
private ValueNode[] lockedObjects; |
|
95 |
private boolean canVerifyKind; |
|
96 |
||
97 |
/** |
|
98 |
* @see BytecodeFrame#rethrowException |
|
99 |
*/ |
|
100 |
private boolean rethrowException; |
|
101 |
||
102 |
private MonitorIdNode[] monitorIds; |
|
103 |
private final StructuredGraph graph; |
|
46344 | 104 |
private final boolean clearNonLiveLocals; |
43972 | 105 |
private FrameState outerFrameState; |
46807 | 106 |
private NodeSourcePosition outerSourcePosition; |
43972 | 107 |
|
108 |
/** |
|
109 |
* The closest {@link StateSplit#hasSideEffect() side-effect} predecessors. There will be more |
|
110 |
* than one when the current block contains no side-effects but merging predecessor blocks do. |
|
111 |
*/ |
|
112 |
private List<StateSplit> sideEffects; |
|
113 |
||
114 |
/** |
|
115 |
* Creates a new frame state builder for the given method and the given target graph. |
|
116 |
* |
|
117 |
* @param method the method whose frame is simulated |
|
118 |
* @param graph the target graph of Graal nodes created by the builder |
|
119 |
*/ |
|
120 |
public FrameStateBuilder(GraphBuilderTool tool, ResolvedJavaMethod method, StructuredGraph graph) { |
|
54328 | 121 |
this(tool, new ResolvedJavaMethodBytecode(method), graph, false); |
43972 | 122 |
} |
123 |
||
124 |
/** |
|
125 |
* Creates a new frame state builder for the given code attribute, method and the given target |
|
54328 | 126 |
* graph. Additionally specifies if nonLiveLocals should be retained. |
43972 | 127 |
* |
128 |
* @param code the bytecode in which the frame exists |
|
129 |
* @param graph the target graph of Graal nodes created by the builder |
|
54328 | 130 |
* @param shouldRetainLocalVariables specifies if nonLiveLocals should be retained in state. |
43972 | 131 |
*/ |
54328 | 132 |
public FrameStateBuilder(GraphBuilderTool tool, Bytecode code, StructuredGraph graph, boolean shouldRetainLocalVariables) { |
43972 | 133 |
this.tool = tool; |
134 |
if (tool instanceof BytecodeParser) { |
|
135 |
this.parser = (BytecodeParser) tool; |
|
136 |
} else { |
|
137 |
this.parser = null; |
|
138 |
} |
|
139 |
this.code = code; |
|
140 |
this.locals = allocateArray(code.getMaxLocals()); |
|
141 |
this.stack = allocateArray(Math.max(1, code.getMaxStackSize())); |
|
142 |
this.lockedObjects = allocateArray(0); |
|
143 |
||
144 |
assert graph != null; |
|
145 |
||
146 |
this.monitorIds = EMPTY_MONITOR_ARRAY; |
|
147 |
this.graph = graph; |
|
55509 | 148 |
this.clearNonLiveLocals = !shouldRetainLocalVariables; |
43972 | 149 |
this.canVerifyKind = true; |
150 |
} |
|
151 |
||
152 |
public void disableKindVerification() { |
|
153 |
canVerifyKind = false; |
|
154 |
} |
|
155 |
||
156 |
public void initializeFromArgumentsArray(ValueNode[] arguments) { |
|
157 |
||
158 |
int javaIndex = 0; |
|
159 |
int index = 0; |
|
160 |
if (!getMethod().isStatic()) { |
|
161 |
// set the receiver |
|
162 |
locals[javaIndex] = arguments[index]; |
|
163 |
javaIndex = 1; |
|
164 |
index = 1; |
|
165 |
} |
|
166 |
Signature sig = getMethod().getSignature(); |
|
167 |
int max = sig.getParameterCount(false); |
|
168 |
for (int i = 0; i < max; i++) { |
|
169 |
JavaKind kind = sig.getParameterKind(i); |
|
170 |
locals[javaIndex] = arguments[index]; |
|
171 |
javaIndex++; |
|
172 |
if (kind.needsTwoSlots()) { |
|
173 |
locals[javaIndex] = TWO_SLOT_MARKER; |
|
174 |
javaIndex++; |
|
175 |
} |
|
176 |
index++; |
|
177 |
} |
|
178 |
} |
|
179 |
||
180 |
public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) { |
|
181 |
||
182 |
int javaIndex = 0; |
|
183 |
int index = 0; |
|
184 |
ResolvedJavaMethod method = getMethod(); |
|
185 |
ResolvedJavaType originalType = method.getDeclaringClass(); |
|
186 |
if (!method.isStatic()) { |
|
187 |
// add the receiver |
|
188 |
FloatingNode receiver = null; |
|
189 |
StampPair receiverStamp = null; |
|
190 |
if (plugins != null) { |
|
191 |
receiverStamp = plugins.getOverridingStamp(tool, originalType, true); |
|
192 |
} |
|
193 |
if (receiverStamp == null) { |
|
194 |
receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true); |
|
195 |
} |
|
196 |
||
197 |
if (plugins != null) { |
|
198 |
for (ParameterPlugin plugin : plugins.getParameterPlugins()) { |
|
199 |
receiver = plugin.interceptParameter(tool, index, receiverStamp); |
|
200 |
if (receiver != null) { |
|
201 |
break; |
|
202 |
} |
|
203 |
} |
|
204 |
} |
|
205 |
if (receiver == null) { |
|
206 |
receiver = new ParameterNode(javaIndex, receiverStamp); |
|
207 |
} |
|
208 |
||
47798 | 209 |
locals[javaIndex] = graph.addOrUniqueWithInputs(receiver); |
43972 | 210 |
javaIndex = 1; |
211 |
index = 1; |
|
212 |
} |
|
213 |
Signature sig = method.getSignature(); |
|
214 |
int max = sig.getParameterCount(false); |
|
215 |
ResolvedJavaType accessingClass = originalType; |
|
216 |
for (int i = 0; i < max; i++) { |
|
217 |
JavaType type = sig.getParameterType(i, accessingClass); |
|
218 |
if (eagerResolve) { |
|
219 |
type = type.resolve(accessingClass); |
|
220 |
} |
|
221 |
JavaKind kind = type.getJavaKind(); |
|
222 |
StampPair stamp = null; |
|
223 |
if (plugins != null) { |
|
224 |
stamp = plugins.getOverridingStamp(tool, type, false); |
|
225 |
} |
|
226 |
if (stamp == null) { |
|
50609 | 227 |
// GR-714: subword inputs cannot be trusted |
228 |
if (kind.getStackKind() != kind) { |
|
229 |
stamp = StampPair.createSingle(StampFactory.forKind(JavaKind.Int)); |
|
230 |
} else { |
|
231 |
stamp = StampFactory.forDeclaredType(assumptions, type, false); |
|
232 |
} |
|
43972 | 233 |
} |
234 |
||
235 |
FloatingNode param = null; |
|
236 |
if (plugins != null) { |
|
237 |
for (ParameterPlugin plugin : plugins.getParameterPlugins()) { |
|
238 |
param = plugin.interceptParameter(tool, index, stamp); |
|
239 |
if (param != null) { |
|
240 |
break; |
|
241 |
} |
|
242 |
} |
|
243 |
} |
|
244 |
if (param == null) { |
|
245 |
param = new ParameterNode(index, stamp); |
|
246 |
} |
|
247 |
||
47798 | 248 |
locals[javaIndex] = graph.addOrUniqueWithInputs(param); |
43972 | 249 |
javaIndex++; |
250 |
if (kind.needsTwoSlots()) { |
|
251 |
locals[javaIndex] = TWO_SLOT_MARKER; |
|
252 |
javaIndex++; |
|
253 |
} |
|
254 |
index++; |
|
255 |
} |
|
256 |
} |
|
257 |
||
258 |
private FrameStateBuilder(FrameStateBuilder other) { |
|
259 |
this.parser = other.parser; |
|
260 |
this.tool = other.tool; |
|
261 |
this.code = other.code; |
|
262 |
this.stackSize = other.stackSize; |
|
263 |
this.locals = other.locals.clone(); |
|
264 |
this.stack = other.stack.clone(); |
|
265 |
this.lockedObjects = other.lockedObjects.length == 0 ? other.lockedObjects : other.lockedObjects.clone(); |
|
266 |
this.rethrowException = other.rethrowException; |
|
267 |
this.canVerifyKind = other.canVerifyKind; |
|
268 |
||
269 |
assert locals.length == code.getMaxLocals(); |
|
270 |
assert stack.length == Math.max(1, code.getMaxStackSize()); |
|
271 |
||
272 |
assert other.graph != null; |
|
273 |
graph = other.graph; |
|
46344 | 274 |
clearNonLiveLocals = other.clearNonLiveLocals; |
43972 | 275 |
monitorIds = other.monitorIds.length == 0 ? other.monitorIds : other.monitorIds.clone(); |
276 |
||
277 |
assert lockedObjects.length == monitorIds.length; |
|
278 |
} |
|
279 |
||
280 |
private static ValueNode[] allocateArray(int length) { |
|
281 |
return length == 0 ? EMPTY_ARRAY : new ValueNode[length]; |
|
282 |
} |
|
283 |
||
284 |
public ResolvedJavaMethod getMethod() { |
|
285 |
return code.getMethod(); |
|
286 |
} |
|
287 |
||
288 |
@Override |
|
289 |
public String toString() { |
|
290 |
StringBuilder sb = new StringBuilder(); |
|
291 |
sb.append("[locals: ["); |
|
292 |
for (int i = 0; i < locals.length; i++) { |
|
293 |
sb.append(i == 0 ? "" : ",").append(locals[i] == null ? "_" : locals[i] == TWO_SLOT_MARKER ? "#" : locals[i].toString(Verbosity.Id)); |
|
294 |
} |
|
295 |
sb.append("] stack: ["); |
|
296 |
for (int i = 0; i < stackSize; i++) { |
|
297 |
sb.append(i == 0 ? "" : ",").append(stack[i] == null ? "_" : stack[i] == TWO_SLOT_MARKER ? "#" : stack[i].toString(Verbosity.Id)); |
|
298 |
} |
|
299 |
sb.append("] locks: ["); |
|
300 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
301 |
sb.append(i == 0 ? "" : ",").append(lockedObjects[i].toString(Verbosity.Id)).append(" / ").append(monitorIds[i].toString(Verbosity.Id)); |
|
302 |
} |
|
303 |
sb.append("]"); |
|
304 |
if (rethrowException) { |
|
305 |
sb.append(" rethrowException"); |
|
306 |
} |
|
307 |
sb.append("]"); |
|
308 |
return sb.toString(); |
|
309 |
} |
|
310 |
||
311 |
public FrameState create(int bci, StateSplit forStateSplit) { |
|
312 |
if (parser != null && parser.parsingIntrinsic()) { |
|
49451 | 313 |
NodeSourcePosition sourcePosition = parser.getGraph().trackNodeSourcePosition() ? createBytecodePosition(bci) : null; |
46509 | 314 |
return parser.intrinsicContext.createFrameState(parser.getGraph(), this, forStateSplit, sourcePosition); |
43972 | 315 |
} |
316 |
||
317 |
// Skip intrinsic frames |
|
318 |
return create(bci, parser != null ? parser.getNonIntrinsicAncestor() : null, false, null, null); |
|
319 |
} |
|
320 |
||
321 |
/** |
|
322 |
* @param pushedValues if non-null, values to {@link #push(JavaKind, ValueNode)} to the stack |
|
323 |
* before creating the {@link FrameState} |
|
324 |
*/ |
|
325 |
public FrameState create(int bci, BytecodeParser parent, boolean duringCall, JavaKind[] pushedSlotKinds, ValueNode[] pushedValues) { |
|
326 |
if (outerFrameState == null && parent != null) { |
|
327 |
assert !parent.parsingIntrinsic() : "must already have the next non-intrinsic ancestor"; |
|
328 |
outerFrameState = parent.getFrameStateBuilder().create(parent.bci(), parent.getNonIntrinsicAncestor(), true, null, null); |
|
329 |
} |
|
330 |
if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI && parent != null) { |
|
331 |
FrameState newFrameState = outerFrameState.duplicateModified(outerFrameState.bci, true, false, JavaKind.Void, new JavaKind[]{JavaKind.Object}, new ValueNode[]{stack[0]}); |
|
332 |
return newFrameState; |
|
333 |
} |
|
334 |
if (bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { |
|
335 |
throw shouldNotReachHere(); |
|
336 |
} |
|
337 |
||
338 |
if (pushedValues != null) { |
|
339 |
assert pushedSlotKinds.length == pushedValues.length; |
|
340 |
int stackSizeToRestore = stackSize; |
|
341 |
for (int i = 0; i < pushedValues.length; i++) { |
|
342 |
push(pushedSlotKinds[i], pushedValues[i]); |
|
343 |
} |
|
344 |
FrameState res = graph.add(new FrameState(outerFrameState, code, bci, locals, stack, stackSize, lockedObjects, Arrays.asList(monitorIds), rethrowException, duringCall)); |
|
345 |
stackSize = stackSizeToRestore; |
|
346 |
return res; |
|
347 |
} else { |
|
348 |
if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI) { |
|
349 |
assert outerFrameState == null; |
|
350 |
clearLocals(); |
|
351 |
} |
|
352 |
return graph.add(new FrameState(outerFrameState, code, bci, locals, stack, stackSize, lockedObjects, Arrays.asList(monitorIds), rethrowException, duringCall)); |
|
353 |
} |
|
354 |
} |
|
355 |
||
356 |
public NodeSourcePosition createBytecodePosition(int bci) { |
|
49451 | 357 |
BytecodeParser parent = parser.getParent(); |
358 |
NodeSourcePosition position = create(bci, parent); |
|
359 |
return position; |
|
46509 | 360 |
} |
361 |
||
49451 | 362 |
private NodeSourcePosition create(int bci, BytecodeParser parent) { |
46807 | 363 |
if (outerSourcePosition == null && parent != null) { |
49451 | 364 |
outerSourcePosition = parent.getFrameStateBuilder().createBytecodePosition(parent.bci()); |
43972 | 365 |
} |
366 |
if (bci == BytecodeFrame.AFTER_EXCEPTION_BCI && parent != null) { |
|
367 |
return FrameState.toSourcePosition(outerFrameState); |
|
368 |
} |
|
369 |
if (bci == BytecodeFrame.INVALID_FRAMESTATE_BCI) { |
|
370 |
throw shouldNotReachHere(); |
|
371 |
} |
|
52578 | 372 |
if (parser.intrinsicContext != null && (parent == null || parent.intrinsicContext != parser.intrinsicContext)) { |
373 |
// When parsing an intrinsic put in a substitution marker showing the original method as |
|
374 |
// the caller. This keeps the relationship between the method and the method |
|
375 |
// substitution clear in resulting NodeSourcePosition. |
|
376 |
NodeSourcePosition original = new NodeSourcePosition(outerSourcePosition, parser.intrinsicContext.getOriginalMethod(), -1); |
|
377 |
return NodeSourcePosition.substitution(original, code.getMethod(), bci); |
|
378 |
} else { |
|
379 |
return new NodeSourcePosition(outerSourcePosition, code.getMethod(), bci); |
|
380 |
} |
|
43972 | 381 |
} |
382 |
||
383 |
public FrameStateBuilder copy() { |
|
384 |
return new FrameStateBuilder(this); |
|
385 |
} |
|
386 |
||
58533 | 387 |
private String incompatibilityErrorMessage(String reason, FrameStateBuilder other) { |
388 |
return String.format("Frame states being merged are incompatible: %s%n This frame state: %s%nOther frame state: %s%nParser context: %s", reason, this, other, parser); |
|
389 |
} |
|
390 |
||
391 |
/** |
|
392 |
* Checks invariants that must hold when merging {@code other} into this frame state. |
|
393 |
* |
|
394 |
* @param other |
|
395 |
* @throws PermanentBailoutException if the frame states are incompatible with respect to their |
|
396 |
* locked objects. This indicates bytecode that has unstructured or unbalanced |
|
397 |
* locks. |
|
398 |
* @throws GraalError if the frame states are incompatible in terms of {@link #rethrowException} |
|
399 |
* or stack slots |
|
400 |
*/ |
|
401 |
public void checkCompatibleWith(FrameStateBuilder other) { |
|
43972 | 402 |
assert code.equals(other.code) && graph == other.graph && localsSize() == other.localsSize() : "Can only compare frame states of the same method"; |
403 |
assert lockedObjects.length == monitorIds.length && other.lockedObjects.length == other.monitorIds.length : "mismatch between lockedObjects and monitorIds"; |
|
404 |
||
54601 | 405 |
if (rethrowException != other.rethrowException) { |
58533 | 406 |
throw new GraalError(incompatibilityErrorMessage("mismatch in rethrowException flag", other)); |
54601 | 407 |
} |
408 |
||
43972 | 409 |
if (stackSize() != other.stackSize()) { |
58533 | 410 |
throw new GraalError(incompatibilityErrorMessage("mismatch in stack sizes", other)); |
43972 | 411 |
} |
412 |
for (int i = 0; i < stackSize(); i++) { |
|
413 |
ValueNode x = stack[i]; |
|
414 |
ValueNode y = other.stack[i]; |
|
415 |
assert x != null && y != null; |
|
416 |
if (x != y && (x == TWO_SLOT_MARKER || x.isDeleted() || y == TWO_SLOT_MARKER || y.isDeleted() || x.getStackKind() != y.getStackKind())) { |
|
58533 | 417 |
throw new GraalError(incompatibilityErrorMessage("mismatch in stack types", other)); |
43972 | 418 |
} |
419 |
} |
|
420 |
if (lockedObjects.length != other.lockedObjects.length) { |
|
58533 | 421 |
throw new PermanentBailoutException(incompatibilityErrorMessage("unbalanced monitors - locked objects do not match", other)); |
43972 | 422 |
} |
423 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
58533 | 424 |
if (originalValue(lockedObjects[i], false) != originalValue(other.lockedObjects[i], false)) { |
425 |
throw new PermanentBailoutException(incompatibilityErrorMessage("unbalanced monitors - locked objects do not match", other)); |
|
426 |
} |
|
427 |
if (monitorIds[i] != other.monitorIds[i]) { |
|
428 |
throw new PermanentBailoutException(incompatibilityErrorMessage("unbalanced monitors - monitors do not match", other)); |
|
43972 | 429 |
} |
430 |
} |
|
431 |
} |
|
432 |
||
433 |
public void merge(AbstractMergeNode block, FrameStateBuilder other) { |
|
58533 | 434 |
checkCompatibleWith(other); |
43972 | 435 |
|
436 |
for (int i = 0; i < localsSize(); i++) { |
|
437 |
locals[i] = merge(locals[i], other.locals[i], block); |
|
438 |
} |
|
439 |
for (int i = 0; i < stackSize(); i++) { |
|
440 |
stack[i] = merge(stack[i], other.stack[i], block); |
|
441 |
} |
|
442 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
443 |
lockedObjects[i] = merge(lockedObjects[i], other.lockedObjects[i], block); |
|
444 |
assert monitorIds[i] == other.monitorIds[i]; |
|
445 |
} |
|
446 |
||
447 |
if (sideEffects == null) { |
|
448 |
sideEffects = other.sideEffects; |
|
449 |
} else { |
|
450 |
if (other.sideEffects != null) { |
|
451 |
sideEffects.addAll(other.sideEffects); |
|
452 |
} |
|
453 |
} |
|
454 |
} |
|
455 |
||
456 |
private ValueNode merge(ValueNode currentValue, ValueNode otherValue, AbstractMergeNode block) { |
|
457 |
if (currentValue == null || currentValue.isDeleted()) { |
|
458 |
return null; |
|
459 |
} else if (block.isPhiAtMerge(currentValue)) { |
|
460 |
if (otherValue == null || otherValue == TWO_SLOT_MARKER || otherValue.isDeleted() || currentValue.getStackKind() != otherValue.getStackKind()) { |
|
461 |
// This phi must be dead anyway, add input of correct stack kind to keep the graph |
|
462 |
// invariants. |
|
463 |
((PhiNode) currentValue).addInput(ConstantNode.defaultForKind(currentValue.getStackKind(), graph)); |
|
464 |
} else { |
|
465 |
((PhiNode) currentValue).addInput(otherValue); |
|
466 |
} |
|
467 |
return currentValue; |
|
468 |
} else if (currentValue != otherValue) { |
|
469 |
if (currentValue == TWO_SLOT_MARKER || otherValue == TWO_SLOT_MARKER) { |
|
470 |
return null; |
|
471 |
} else if (otherValue == null || otherValue.isDeleted() || currentValue.getStackKind() != otherValue.getStackKind()) { |
|
472 |
return null; |
|
473 |
} |
|
474 |
assert !(block instanceof LoopBeginNode) : String.format("Phi functions for loop headers are create eagerly for changed locals and all stack slots: %s != %s", currentValue, otherValue); |
|
475 |
return createValuePhi(currentValue, otherValue, block); |
|
476 |
} else { |
|
477 |
return currentValue; |
|
478 |
} |
|
479 |
} |
|
480 |
||
481 |
private ValuePhiNode createValuePhi(ValueNode currentValue, ValueNode otherValue, AbstractMergeNode block) { |
|
48190 | 482 |
ValuePhiNode phi = graph.addWithoutUnique(new ValuePhiNode(currentValue.stamp(NodeView.DEFAULT).unrestricted(), block)); |
43972 | 483 |
for (int i = 0; i < block.phiPredecessorCount(); i++) { |
484 |
phi.addInput(currentValue); |
|
485 |
} |
|
486 |
phi.addInput(otherValue); |
|
487 |
assert phi.valueCount() == block.phiPredecessorCount() + 1; |
|
488 |
return phi; |
|
489 |
} |
|
490 |
||
491 |
public void inferPhiStamps(AbstractMergeNode block) { |
|
492 |
for (int i = 0; i < localsSize(); i++) { |
|
493 |
inferPhiStamp(block, locals[i]); |
|
494 |
} |
|
495 |
for (int i = 0; i < stackSize(); i++) { |
|
496 |
inferPhiStamp(block, stack[i]); |
|
497 |
} |
|
498 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
499 |
inferPhiStamp(block, lockedObjects[i]); |
|
500 |
} |
|
501 |
} |
|
502 |
||
503 |
private static void inferPhiStamp(AbstractMergeNode block, ValueNode node) { |
|
504 |
if (block.isPhiAtMerge(node)) { |
|
505 |
node.inferStamp(); |
|
506 |
} |
|
507 |
} |
|
508 |
||
509 |
public void insertLoopPhis(LocalLiveness liveness, int loopId, LoopBeginNode loopBegin, boolean forcePhis, boolean stampFromValueForForcedPhis) { |
|
510 |
for (int i = 0; i < localsSize(); i++) { |
|
511 |
boolean changedInLoop = liveness.localIsChangedInLoop(loopId, i); |
|
512 |
if (forcePhis || changedInLoop) { |
|
513 |
locals[i] = createLoopPhi(loopBegin, locals[i], stampFromValueForForcedPhis && !changedInLoop); |
|
514 |
} |
|
515 |
} |
|
516 |
for (int i = 0; i < stackSize(); i++) { |
|
517 |
stack[i] = createLoopPhi(loopBegin, stack[i], false); |
|
518 |
} |
|
519 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
520 |
lockedObjects[i] = createLoopPhi(loopBegin, lockedObjects[i], false); |
|
521 |
} |
|
522 |
} |
|
523 |
||
524 |
public void insertLoopProxies(LoopExitNode loopExit, FrameStateBuilder loopEntryState) { |
|
46640 | 525 |
DebugContext debug = graph.getDebug(); |
43972 | 526 |
for (int i = 0; i < localsSize(); i++) { |
527 |
ValueNode value = locals[i]; |
|
528 |
if (value != null && value != TWO_SLOT_MARKER && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { |
|
46640 | 529 |
debug.log(" inserting proxy for %s", value); |
43972 | 530 |
locals[i] = ProxyNode.forValue(value, loopExit, graph); |
531 |
} |
|
532 |
} |
|
533 |
for (int i = 0; i < stackSize(); i++) { |
|
534 |
ValueNode value = stack[i]; |
|
535 |
if (value != null && value != TWO_SLOT_MARKER && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { |
|
46640 | 536 |
debug.log(" inserting proxy for %s", value); |
43972 | 537 |
stack[i] = ProxyNode.forValue(value, loopExit, graph); |
538 |
} |
|
539 |
} |
|
540 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
541 |
ValueNode value = lockedObjects[i]; |
|
542 |
if (value != null && (!loopEntryState.contains(value) || loopExit.loopBegin().isPhiAtMerge(value))) { |
|
46640 | 543 |
debug.log(" inserting proxy for %s", value); |
43972 | 544 |
lockedObjects[i] = ProxyNode.forValue(value, loopExit, graph); |
545 |
} |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
public void insertProxies(Function<ValueNode, ValueNode> proxyFunction) { |
|
46640 | 550 |
DebugContext debug = graph.getDebug(); |
43972 | 551 |
for (int i = 0; i < localsSize(); i++) { |
552 |
ValueNode value = locals[i]; |
|
553 |
if (value != null && value != TWO_SLOT_MARKER) { |
|
46640 | 554 |
debug.log(" inserting proxy for %s", value); |
43972 | 555 |
locals[i] = proxyFunction.apply(value); |
556 |
} |
|
557 |
} |
|
558 |
for (int i = 0; i < stackSize(); i++) { |
|
559 |
ValueNode value = stack[i]; |
|
560 |
if (value != null && value != TWO_SLOT_MARKER) { |
|
46640 | 561 |
debug.log(" inserting proxy for %s", value); |
43972 | 562 |
stack[i] = proxyFunction.apply(value); |
563 |
} |
|
564 |
} |
|
565 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
566 |
ValueNode value = lockedObjects[i]; |
|
567 |
if (value != null) { |
|
46640 | 568 |
debug.log(" inserting proxy for %s", value); |
43972 | 569 |
lockedObjects[i] = proxyFunction.apply(value); |
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
private ValueNode createLoopPhi(AbstractMergeNode block, ValueNode value, boolean stampFromValue) { |
|
575 |
if (value == null || value == TWO_SLOT_MARKER) { |
|
576 |
return value; |
|
577 |
} |
|
578 |
assert !block.isPhiAtMerge(value) : "phi function for this block already created"; |
|
579 |
||
48190 | 580 |
ValuePhiNode phi = graph.addWithoutUnique(new ValuePhiNode(stampFromValue ? value.stamp(NodeView.DEFAULT) : value.stamp(NodeView.DEFAULT).unrestricted(), block)); |
43972 | 581 |
phi.addInput(value); |
582 |
return phi; |
|
583 |
} |
|
584 |
||
585 |
/** |
|
586 |
* Adds a locked monitor to this frame state. |
|
587 |
* |
|
588 |
* @param object the object whose monitor will be locked. |
|
589 |
*/ |
|
590 |
public void pushLock(ValueNode object, MonitorIdNode monitorId) { |
|
591 |
assert object.isAlive() && object.getStackKind() == JavaKind.Object : "unexpected value: " + object; |
|
592 |
lockedObjects = Arrays.copyOf(lockedObjects, lockedObjects.length + 1); |
|
593 |
monitorIds = Arrays.copyOf(monitorIds, monitorIds.length + 1); |
|
594 |
lockedObjects[lockedObjects.length - 1] = object; |
|
595 |
monitorIds[monitorIds.length - 1] = monitorId; |
|
596 |
assert lockedObjects.length == monitorIds.length; |
|
597 |
} |
|
598 |
||
599 |
/** |
|
600 |
* Removes a locked monitor from this frame state. |
|
601 |
* |
|
602 |
* @return the object whose monitor was removed from the locks list. |
|
603 |
*/ |
|
604 |
public ValueNode popLock() { |
|
605 |
try { |
|
606 |
return lockedObjects[lockedObjects.length - 1]; |
|
607 |
} finally { |
|
608 |
lockedObjects = lockedObjects.length == 1 ? EMPTY_ARRAY : Arrays.copyOf(lockedObjects, lockedObjects.length - 1); |
|
609 |
monitorIds = monitorIds.length == 1 ? EMPTY_MONITOR_ARRAY : Arrays.copyOf(monitorIds, monitorIds.length - 1); |
|
610 |
assert lockedObjects.length == monitorIds.length; |
|
611 |
} |
|
612 |
} |
|
613 |
||
614 |
public MonitorIdNode peekMonitorId() { |
|
615 |
return monitorIds[monitorIds.length - 1]; |
|
616 |
} |
|
617 |
||
618 |
/** |
|
619 |
* @return the current lock depth |
|
620 |
*/ |
|
621 |
public int lockDepth(boolean includeParents) { |
|
622 |
int depth = lockedObjects.length; |
|
623 |
assert depth == monitorIds.length; |
|
624 |
if (includeParents && parser.getParent() != null) { |
|
625 |
depth += parser.getParent().frameState.lockDepth(true); |
|
626 |
} |
|
627 |
return depth; |
|
628 |
} |
|
629 |
||
630 |
public boolean contains(ValueNode value) { |
|
631 |
for (int i = 0; i < localsSize(); i++) { |
|
632 |
if (locals[i] == value) { |
|
633 |
return true; |
|
634 |
} |
|
635 |
} |
|
636 |
for (int i = 0; i < stackSize(); i++) { |
|
637 |
if (stack[i] == value) { |
|
638 |
return true; |
|
639 |
} |
|
640 |
} |
|
641 |
assert lockedObjects.length == monitorIds.length; |
|
642 |
for (int i = 0; i < lockedObjects.length; i++) { |
|
643 |
if (lockedObjects[i] == value || monitorIds[i] == value) { |
|
644 |
return true; |
|
645 |
} |
|
646 |
} |
|
647 |
return false; |
|
648 |
} |
|
649 |
||
650 |
public void clearNonLiveLocals(BciBlock block, LocalLiveness liveness, boolean liveIn) { |
|
651 |
/* |
|
54328 | 652 |
* Non-live local clearing is mandatory for the entry block of an OSR compilation so that |
653 |
* dead object slots at the OSR entry are cleared. It's not sufficient to rely on PiNodes |
|
654 |
* with Kind.Illegal, because the conflicting branch might not have been parsed. |
|
43972 | 655 |
*/ |
54328 | 656 |
boolean isOSREntryBlock = graph.isOSR() && getMethod().equals(graph.method()) && graph.getEntryBCI() == block.startBci; |
657 |
if (!clearNonLiveLocals && !isOSREntryBlock) { |
|
43972 | 658 |
return; |
659 |
} |
|
660 |
if (liveIn) { |
|
661 |
for (int i = 0; i < locals.length; i++) { |
|
662 |
if (!liveness.localIsLiveIn(block, i)) { |
|
663 |
assert locals[i] != TWO_SLOT_MARKER || locals[i - 1] == null : "Clearing of second slot must have cleared the first slot too"; |
|
664 |
locals[i] = null; |
|
665 |
} |
|
666 |
} |
|
667 |
} else { |
|
668 |
for (int i = 0; i < locals.length; i++) { |
|
669 |
if (!liveness.localIsLiveOut(block, i)) { |
|
670 |
assert locals[i] != TWO_SLOT_MARKER || locals[i - 1] == null : "Clearing of second slot must have cleared the first slot too"; |
|
671 |
locals[i] = null; |
|
672 |
} |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
/** |
|
678 |
* Clears all local variables. |
|
679 |
*/ |
|
680 |
public void clearLocals() { |
|
681 |
for (int i = 0; i < locals.length; i++) { |
|
682 |
locals[i] = null; |
|
683 |
} |
|
684 |
} |
|
685 |
||
686 |
/** |
|
687 |
* @see BytecodeFrame#rethrowException |
|
688 |
*/ |
|
689 |
public boolean rethrowException() { |
|
690 |
return rethrowException; |
|
691 |
} |
|
692 |
||
693 |
/** |
|
694 |
* @see BytecodeFrame#rethrowException |
|
695 |
*/ |
|
696 |
public void setRethrowException(boolean b) { |
|
697 |
rethrowException = b; |
|
698 |
} |
|
699 |
||
700 |
/** |
|
701 |
* Returns the size of the local variables. |
|
702 |
* |
|
703 |
* @return the size of the local variables |
|
704 |
*/ |
|
705 |
public int localsSize() { |
|
706 |
return locals.length; |
|
707 |
} |
|
708 |
||
709 |
/** |
|
710 |
* Gets the current size (height) of the stack. |
|
711 |
*/ |
|
712 |
public int stackSize() { |
|
713 |
return stackSize; |
|
714 |
} |
|
715 |
||
716 |
private boolean verifyKind(JavaKind slotKind, ValueNode x) { |
|
717 |
assert x != null; |
|
718 |
assert x != TWO_SLOT_MARKER; |
|
719 |
assert slotKind.getSlotCount() > 0; |
|
720 |
||
721 |
if (canVerifyKind) { |
|
722 |
assert x.getStackKind() == slotKind.getStackKind(); |
|
723 |
} |
|
724 |
return true; |
|
725 |
} |
|
726 |
||
727 |
/** |
|
728 |
* Loads the local variable at the specified index, checking that the returned value is non-null |
|
729 |
* and that two-stack values are properly handled. |
|
730 |
* |
|
731 |
* @param i the index of the local variable to load |
|
732 |
* @param slotKind the kind of the local variable from the point of view of the bytecodes |
|
733 |
* @return the instruction that produced the specified local |
|
734 |
*/ |
|
735 |
public ValueNode loadLocal(int i, JavaKind slotKind) { |
|
736 |
ValueNode x = locals[i]; |
|
737 |
assert verifyKind(slotKind, x); |
|
738 |
assert slotKind.needsTwoSlots() ? locals[i + 1] == TWO_SLOT_MARKER : (i == locals.length - 1 || locals[i + 1] != TWO_SLOT_MARKER); |
|
739 |
return x; |
|
740 |
} |
|
741 |
||
742 |
/** |
|
743 |
* Stores a given local variable at the specified index. If the value occupies two slots, then |
|
744 |
* the next local variable index is also overwritten. |
|
745 |
* |
|
746 |
* @param i the index at which to store |
|
747 |
* @param slotKind the kind of the local variable from the point of view of the bytecodes |
|
748 |
* @param x the instruction which produces the value for the local |
|
749 |
*/ |
|
750 |
public void storeLocal(int i, JavaKind slotKind, ValueNode x) { |
|
751 |
assert verifyKind(slotKind, x); |
|
752 |
||
753 |
if (locals[i] == TWO_SLOT_MARKER) { |
|
754 |
/* Writing the second slot of a two-slot value invalidates the first slot. */ |
|
755 |
locals[i - 1] = null; |
|
756 |
} |
|
757 |
locals[i] = x; |
|
758 |
if (slotKind.needsTwoSlots()) { |
|
54914 | 759 |
if (i < locals.length - 2 && locals[i + 2] == TWO_SLOT_MARKER) { |
760 |
/* |
|
761 |
* Writing a two-slot marker to an index previously occupied by a two-slot value: |
|
762 |
* clear the old marker of the second slot. |
|
763 |
*/ |
|
764 |
locals[i + 2] = null; |
|
765 |
} |
|
43972 | 766 |
/* Writing a two-slot value: mark the second slot. */ |
767 |
locals[i + 1] = TWO_SLOT_MARKER; |
|
768 |
} else if (i < locals.length - 1 && locals[i + 1] == TWO_SLOT_MARKER) { |
|
769 |
/* |
|
770 |
* Writing a one-slot value to an index previously occupied by a two-slot value: clear |
|
771 |
* the old marker of the second slot. |
|
772 |
*/ |
|
773 |
locals[i + 1] = null; |
|
774 |
} |
|
775 |
} |
|
776 |
||
777 |
/** |
|
778 |
* Pushes an instruction onto the stack with the expected type. |
|
779 |
* |
|
780 |
* @param slotKind the kind of the stack element from the point of view of the bytecodes |
|
781 |
* @param x the instruction to push onto the stack |
|
782 |
*/ |
|
783 |
public void push(JavaKind slotKind, ValueNode x) { |
|
784 |
assert verifyKind(slotKind, x); |
|
785 |
||
786 |
xpush(x); |
|
787 |
if (slotKind.needsTwoSlots()) { |
|
788 |
xpush(TWO_SLOT_MARKER); |
|
789 |
} |
|
790 |
} |
|
791 |
||
792 |
public void pushReturn(JavaKind slotKind, ValueNode x) { |
|
793 |
if (slotKind != JavaKind.Void) { |
|
794 |
push(slotKind, x); |
|
795 |
} |
|
796 |
} |
|
797 |
||
798 |
/** |
|
799 |
* Pops an instruction off the stack with the expected type. |
|
800 |
* |
|
801 |
* @param slotKind the kind of the stack element from the point of view of the bytecodes |
|
802 |
* @return the instruction on the top of the stack |
|
803 |
*/ |
|
804 |
public ValueNode pop(JavaKind slotKind) { |
|
805 |
if (slotKind.needsTwoSlots()) { |
|
806 |
ValueNode s = xpop(); |
|
55619
3595fb8794c5
8221577: [Graal] Implement basic type consistency checks for Low level MH intrinsics
jcm
parents:
54914
diff
changeset
|
807 |
assert s == TWO_SLOT_MARKER : s; |
43972 | 808 |
} |
809 |
ValueNode x = xpop(); |
|
810 |
assert verifyKind(slotKind, x); |
|
811 |
return x; |
|
812 |
} |
|
813 |
||
814 |
private void xpush(ValueNode x) { |
|
815 |
assert x != null; |
|
816 |
stack[stackSize++] = x; |
|
817 |
} |
|
818 |
||
819 |
private ValueNode xpop() { |
|
820 |
ValueNode result = stack[--stackSize]; |
|
821 |
assert result != null; |
|
822 |
return result; |
|
823 |
} |
|
824 |
||
825 |
private ValueNode xpeek() { |
|
826 |
ValueNode result = stack[stackSize - 1]; |
|
827 |
assert result != null; |
|
828 |
return result; |
|
829 |
} |
|
830 |
||
54601 | 831 |
public ValueNode peekObject() { |
832 |
ValueNode x = xpeek(); |
|
833 |
assert verifyKind(JavaKind.Object, x); |
|
834 |
return x; |
|
835 |
} |
|
836 |
||
43972 | 837 |
/** |
838 |
* Pop the specified number of slots off of this stack and return them as an array of |
|
839 |
* instructions. |
|
840 |
* |
|
841 |
* @return an array containing the arguments off of the stack |
|
842 |
*/ |
|
843 |
public ValueNode[] popArguments(int argSize) { |
|
844 |
ValueNode[] result = allocateArray(argSize); |
|
845 |
for (int i = argSize - 1; i >= 0; i--) { |
|
846 |
ValueNode x = xpop(); |
|
847 |
if (x == TWO_SLOT_MARKER) { |
|
848 |
/* Ignore second slot of two-slot value. */ |
|
849 |
x = xpop(); |
|
850 |
} |
|
55619
3595fb8794c5
8221577: [Graal] Implement basic type consistency checks for Low level MH intrinsics
jcm
parents:
54914
diff
changeset
|
851 |
assert x != null && x != TWO_SLOT_MARKER : x; |
43972 | 852 |
result[i] = x; |
853 |
} |
|
854 |
return result; |
|
855 |
} |
|
856 |
||
857 |
/** |
|
858 |
* Clears all values on this stack. |
|
859 |
*/ |
|
860 |
public void clearStack() { |
|
861 |
stackSize = 0; |
|
862 |
} |
|
863 |
||
864 |
/** |
|
865 |
* Performs a raw stack operation as defined in the Java bytecode specification. |
|
866 |
* |
|
867 |
* @param opcode The Java bytecode. |
|
868 |
*/ |
|
869 |
public void stackOp(int opcode) { |
|
870 |
switch (opcode) { |
|
871 |
case POP: { |
|
872 |
ValueNode w1 = xpop(); |
|
873 |
assert w1 != TWO_SLOT_MARKER; |
|
874 |
break; |
|
875 |
} |
|
876 |
case POP2: { |
|
877 |
xpop(); |
|
878 |
ValueNode w2 = xpop(); |
|
879 |
assert w2 != TWO_SLOT_MARKER; |
|
880 |
break; |
|
881 |
} |
|
882 |
case DUP: { |
|
883 |
ValueNode w1 = xpeek(); |
|
884 |
assert w1 != TWO_SLOT_MARKER; |
|
885 |
xpush(w1); |
|
886 |
break; |
|
887 |
} |
|
888 |
case DUP_X1: { |
|
889 |
ValueNode w1 = xpop(); |
|
890 |
ValueNode w2 = xpop(); |
|
891 |
assert w1 != TWO_SLOT_MARKER; |
|
892 |
xpush(w1); |
|
893 |
xpush(w2); |
|
894 |
xpush(w1); |
|
895 |
break; |
|
896 |
} |
|
897 |
case DUP_X2: { |
|
898 |
ValueNode w1 = xpop(); |
|
899 |
ValueNode w2 = xpop(); |
|
900 |
ValueNode w3 = xpop(); |
|
901 |
assert w1 != TWO_SLOT_MARKER; |
|
902 |
xpush(w1); |
|
903 |
xpush(w3); |
|
904 |
xpush(w2); |
|
905 |
xpush(w1); |
|
906 |
break; |
|
907 |
} |
|
908 |
case DUP2: { |
|
909 |
ValueNode w1 = xpop(); |
|
910 |
ValueNode w2 = xpop(); |
|
911 |
xpush(w2); |
|
912 |
xpush(w1); |
|
913 |
xpush(w2); |
|
914 |
xpush(w1); |
|
915 |
break; |
|
916 |
} |
|
917 |
case DUP2_X1: { |
|
918 |
ValueNode w1 = xpop(); |
|
919 |
ValueNode w2 = xpop(); |
|
920 |
ValueNode w3 = xpop(); |
|
921 |
xpush(w2); |
|
922 |
xpush(w1); |
|
923 |
xpush(w3); |
|
924 |
xpush(w2); |
|
925 |
xpush(w1); |
|
926 |
break; |
|
927 |
} |
|
928 |
case DUP2_X2: { |
|
929 |
ValueNode w1 = xpop(); |
|
930 |
ValueNode w2 = xpop(); |
|
931 |
ValueNode w3 = xpop(); |
|
932 |
ValueNode w4 = xpop(); |
|
933 |
xpush(w2); |
|
934 |
xpush(w1); |
|
935 |
xpush(w4); |
|
936 |
xpush(w3); |
|
937 |
xpush(w2); |
|
938 |
xpush(w1); |
|
939 |
break; |
|
940 |
} |
|
941 |
case SWAP: { |
|
942 |
ValueNode w1 = xpop(); |
|
943 |
ValueNode w2 = xpop(); |
|
944 |
assert w1 != TWO_SLOT_MARKER; |
|
945 |
assert w2 != TWO_SLOT_MARKER; |
|
946 |
xpush(w1); |
|
947 |
xpush(w2); |
|
948 |
break; |
|
949 |
} |
|
950 |
default: |
|
951 |
throw shouldNotReachHere(); |
|
952 |
} |
|
953 |
} |
|
954 |
||
955 |
@Override |
|
956 |
public int hashCode() { |
|
957 |
int result = hashCode(locals, locals.length); |
|
958 |
result *= 13; |
|
959 |
result += hashCode(stack, this.stackSize); |
|
960 |
return result; |
|
961 |
} |
|
962 |
||
963 |
private static int hashCode(Object[] a, int length) { |
|
964 |
int result = 1; |
|
965 |
for (int i = 0; i < length; ++i) { |
|
966 |
Object element = a[i]; |
|
967 |
result = 31 * result + (element == null ? 0 : System.identityHashCode(element)); |
|
968 |
} |
|
969 |
return result; |
|
970 |
} |
|
971 |
||
972 |
private static boolean equals(ValueNode[] a, ValueNode[] b, int length) { |
|
973 |
for (int i = 0; i < length; ++i) { |
|
974 |
if (a[i] != b[i]) { |
|
975 |
return false; |
|
976 |
} |
|
977 |
} |
|
978 |
return true; |
|
979 |
} |
|
980 |
||
981 |
@Override |
|
982 |
public boolean equals(Object otherObject) { |
|
983 |
if (otherObject instanceof FrameStateBuilder) { |
|
984 |
FrameStateBuilder other = (FrameStateBuilder) otherObject; |
|
985 |
if (!other.code.equals(code)) { |
|
986 |
return false; |
|
987 |
} |
|
988 |
if (other.stackSize != stackSize) { |
|
989 |
return false; |
|
990 |
} |
|
991 |
if (other.parser != parser) { |
|
992 |
return false; |
|
993 |
} |
|
994 |
if (other.tool != tool) { |
|
995 |
return false; |
|
996 |
} |
|
997 |
if (other.rethrowException != rethrowException) { |
|
998 |
return false; |
|
999 |
} |
|
1000 |
if (other.graph != graph) { |
|
1001 |
return false; |
|
1002 |
} |
|
1003 |
if (other.locals.length != locals.length) { |
|
1004 |
return false; |
|
1005 |
} |
|
1006 |
return equals(other.locals, locals, locals.length) && equals(other.stack, stack, stackSize) && equals(other.lockedObjects, lockedObjects, lockedObjects.length) && |
|
1007 |
equals(other.monitorIds, monitorIds, monitorIds.length); |
|
1008 |
} |
|
1009 |
return false; |
|
1010 |
} |
|
1011 |
||
1012 |
@Override |
|
1013 |
public boolean isAfterSideEffect() { |
|
1014 |
return sideEffects != null; |
|
1015 |
} |
|
1016 |
||
1017 |
@Override |
|
1018 |
public Iterable<StateSplit> sideEffects() { |
|
1019 |
return sideEffects; |
|
1020 |
} |
|
1021 |
||
1022 |
@Override |
|
1023 |
public void addSideEffect(StateSplit sideEffect) { |
|
1024 |
assert sideEffect != null; |
|
1025 |
assert sideEffect.hasSideEffect(); |
|
1026 |
if (sideEffects == null) { |
|
1027 |
sideEffects = new ArrayList<>(4); |
|
1028 |
} |
|
1029 |
sideEffects.add(sideEffect); |
|
1030 |
} |
|
1031 |
} |