43972
|
1 |
/*
|
|
2 |
* Copyright (c) 2009, 2015, 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 |
|
46640
|
25 |
import org.graalvm.compiler.debug.DebugContext;
|
43972
|
26 |
import org.graalvm.compiler.graph.NodeClass;
|
|
27 |
import org.graalvm.compiler.lir.gen.LIRGeneratorTool;
|
|
28 |
import org.graalvm.compiler.nodeinfo.NodeInfo;
|
|
29 |
import org.graalvm.compiler.nodes.spi.LIRLowerable;
|
|
30 |
import org.graalvm.compiler.nodes.spi.Lowerable;
|
|
31 |
import org.graalvm.compiler.nodes.spi.LoweringTool;
|
|
32 |
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
|
|
33 |
|
|
34 |
import jdk.vm.ci.meta.DeoptimizationAction;
|
|
35 |
import jdk.vm.ci.meta.DeoptimizationReason;
|
|
36 |
import jdk.vm.ci.meta.JavaConstant;
|
|
37 |
import jdk.vm.ci.meta.JavaKind;
|
|
38 |
import jdk.vm.ci.meta.MetaAccessProvider;
|
|
39 |
import jdk.vm.ci.meta.Value;
|
|
40 |
|
|
41 |
@NodeInfo(shortName = "Deopt", nameTemplate = "Deopt {p#reason/s}")
|
48861
|
42 |
public final class DeoptimizeNode extends AbstractDeoptimizeNode implements Lowerable, LIRLowerable, StaticDeoptimizingNode {
|
43972
|
43 |
public static final int DEFAULT_DEBUG_ID = 0;
|
|
44 |
|
|
45 |
public static final NodeClass<DeoptimizeNode> TYPE = NodeClass.create(DeoptimizeNode.class);
|
|
46 |
protected final DeoptimizationAction action;
|
|
47 |
protected final DeoptimizationReason reason;
|
46344
|
48 |
protected int debugId;
|
43972
|
49 |
protected final JavaConstant speculation;
|
|
50 |
|
|
51 |
public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason) {
|
|
52 |
this(action, reason, DEFAULT_DEBUG_ID, JavaConstant.NULL_POINTER, null);
|
|
53 |
}
|
|
54 |
|
|
55 |
public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason, JavaConstant speculation) {
|
|
56 |
this(action, reason, DEFAULT_DEBUG_ID, speculation, null);
|
|
57 |
}
|
|
58 |
|
|
59 |
public DeoptimizeNode(DeoptimizationAction action, DeoptimizationReason reason, int debugId, JavaConstant speculation, FrameState stateBefore) {
|
|
60 |
super(TYPE, stateBefore);
|
|
61 |
assert action != null;
|
|
62 |
assert reason != null;
|
|
63 |
assert speculation.getJavaKind() == JavaKind.Object;
|
|
64 |
this.action = action;
|
|
65 |
this.reason = reason;
|
|
66 |
this.debugId = debugId;
|
|
67 |
this.speculation = speculation;
|
|
68 |
}
|
|
69 |
|
48861
|
70 |
@Override
|
|
71 |
public DeoptimizationAction getAction() {
|
43972
|
72 |
return action;
|
|
73 |
}
|
|
74 |
|
48861
|
75 |
@Override
|
|
76 |
public DeoptimizationReason getReason() {
|
43972
|
77 |
return reason;
|
|
78 |
}
|
|
79 |
|
|
80 |
@Override
|
|
81 |
public void lower(LoweringTool tool) {
|
|
82 |
tool.getLowerer().lower(this, tool);
|
|
83 |
}
|
|
84 |
|
|
85 |
@SuppressWarnings("deprecation")
|
|
86 |
public int getDebugId() {
|
|
87 |
int deoptDebugId = debugId;
|
46640
|
88 |
if (deoptDebugId == DEFAULT_DEBUG_ID) {
|
|
89 |
DebugContext debug = getDebug();
|
|
90 |
if ((debug.isDumpEnabledForMethod() || debug.isLogEnabledForMethod())) {
|
|
91 |
deoptDebugId = this.getId();
|
|
92 |
}
|
43972
|
93 |
}
|
|
94 |
return deoptDebugId;
|
|
95 |
}
|
|
96 |
|
46344
|
97 |
public void setDebugId(int debugId) {
|
|
98 |
assert debugId != DEFAULT_DEBUG_ID;
|
|
99 |
this.debugId = debugId;
|
|
100 |
}
|
|
101 |
|
43972
|
102 |
@Override
|
|
103 |
public void generate(NodeLIRBuilderTool gen) {
|
|
104 |
LIRGeneratorTool tool = gen.getLIRGeneratorTool();
|
|
105 |
Value actionAndReason = tool.emitJavaConstant(tool.getMetaAccess().encodeDeoptActionAndReason(action, reason, getDebugId()));
|
|
106 |
Value speculationValue = tool.emitJavaConstant(speculation);
|
|
107 |
gen.getLIRGeneratorTool().emitDeoptimize(actionAndReason, speculationValue, gen.state(this));
|
|
108 |
}
|
|
109 |
|
|
110 |
@Override
|
|
111 |
public ValueNode getActionAndReason(MetaAccessProvider metaAccess) {
|
|
112 |
return ConstantNode.forConstant(metaAccess.encodeDeoptActionAndReason(action, reason, getDebugId()), metaAccess, graph());
|
|
113 |
}
|
|
114 |
|
|
115 |
@Override
|
|
116 |
public ValueNode getSpeculation(MetaAccessProvider metaAccess) {
|
|
117 |
return ConstantNode.forConstant(speculation, metaAccess, graph());
|
|
118 |
}
|
|
119 |
|
48861
|
120 |
@Override
|
43972
|
121 |
public JavaConstant getSpeculation() {
|
|
122 |
return speculation;
|
|
123 |
}
|
|
124 |
|
|
125 |
@NodeIntrinsic
|
|
126 |
public static native void deopt(@ConstantNodeParameter DeoptimizationAction action, @ConstantNodeParameter DeoptimizationReason reason);
|
|
127 |
}
|