43972
|
1 |
/*
|
52910
|
2 |
* Copyright (c) 2009, 2018, 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.lir;
|
|
26 |
|
|
27 |
import static org.graalvm.compiler.lir.LIRValueUtil.isVirtualStackSlot;
|
|
28 |
import static jdk.vm.ci.code.ValueUtil.asAllocatableValue;
|
|
29 |
import static jdk.vm.ci.code.ValueUtil.isConstantJavaValue;
|
|
30 |
import static jdk.vm.ci.code.ValueUtil.isIllegalJavaValue;
|
|
31 |
import static jdk.vm.ci.code.ValueUtil.isVirtualObject;
|
|
32 |
|
|
33 |
import java.util.Arrays;
|
|
34 |
import java.util.EnumSet;
|
|
35 |
|
|
36 |
import org.graalvm.compiler.lir.LIRInstruction.OperandFlag;
|
|
37 |
import org.graalvm.compiler.lir.LIRInstruction.OperandMode;
|
|
38 |
import org.graalvm.compiler.lir.framemap.FrameMap;
|
|
39 |
import org.graalvm.compiler.lir.util.IndexedValueMap;
|
|
40 |
|
|
41 |
import jdk.vm.ci.code.BytecodeFrame;
|
|
42 |
import jdk.vm.ci.code.DebugInfo;
|
|
43 |
import jdk.vm.ci.code.StackLockValue;
|
|
44 |
import jdk.vm.ci.code.VirtualObject;
|
|
45 |
import jdk.vm.ci.meta.AllocatableValue;
|
|
46 |
import jdk.vm.ci.meta.JavaValue;
|
|
47 |
import jdk.vm.ci.meta.Value;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* This class represents garbage collection and deoptimization information attached to a LIR
|
|
51 |
* instruction.
|
|
52 |
*/
|
|
53 |
public class LIRFrameState {
|
|
54 |
|
46344
|
55 |
public static final LIRFrameState NO_STATE = new LIRFrameState(null, null, null);
|
|
56 |
|
43972
|
57 |
public final BytecodeFrame topFrame;
|
|
58 |
private final VirtualObject[] virtualObjects;
|
|
59 |
public final LabelRef exceptionEdge;
|
|
60 |
protected DebugInfo debugInfo;
|
|
61 |
|
|
62 |
private IndexedValueMap liveBasePointers;
|
|
63 |
|
|
64 |
public LIRFrameState(BytecodeFrame topFrame, VirtualObject[] virtualObjects, LabelRef exceptionEdge) {
|
|
65 |
this.topFrame = topFrame;
|
|
66 |
this.virtualObjects = virtualObjects;
|
|
67 |
this.exceptionEdge = exceptionEdge;
|
|
68 |
}
|
|
69 |
|
|
70 |
public boolean hasDebugInfo() {
|
|
71 |
return debugInfo != null;
|
|
72 |
}
|
|
73 |
|
|
74 |
public DebugInfo debugInfo() {
|
|
75 |
assert debugInfo != null : "debug info not allocated yet";
|
|
76 |
return debugInfo;
|
|
77 |
}
|
|
78 |
|
|
79 |
/**
|
|
80 |
* Iterates the frame state and calls the {@link InstructionValueProcedure} for every variable.
|
|
81 |
*
|
|
82 |
* @param proc The procedure called for variables.
|
|
83 |
*/
|
|
84 |
public void forEachState(LIRInstruction inst, InstructionValueProcedure proc) {
|
|
85 |
for (BytecodeFrame cur = topFrame; cur != null; cur = cur.caller()) {
|
|
86 |
processValues(inst, cur.values, proc);
|
|
87 |
}
|
|
88 |
if (virtualObjects != null) {
|
|
89 |
for (VirtualObject obj : virtualObjects) {
|
|
90 |
processValues(inst, obj.getValues(), proc);
|
|
91 |
}
|
|
92 |
}
|
|
93 |
if (liveBasePointers != null) {
|
|
94 |
liveBasePointers.forEach(inst, OperandMode.ALIVE, STATE_FLAGS, proc);
|
|
95 |
}
|
|
96 |
}
|
|
97 |
|
|
98 |
/**
|
|
99 |
* Iterates the frame state and calls the {@link InstructionValueConsumer} for every variable.
|
|
100 |
*
|
|
101 |
* @param proc The procedure called for variables.
|
|
102 |
*/
|
|
103 |
public void visitEachState(LIRInstruction inst, InstructionValueConsumer proc) {
|
|
104 |
for (BytecodeFrame cur = topFrame; cur != null; cur = cur.caller()) {
|
|
105 |
visitValues(inst, cur.values, proc);
|
|
106 |
}
|
|
107 |
if (virtualObjects != null) {
|
|
108 |
for (VirtualObject obj : virtualObjects) {
|
|
109 |
visitValues(inst, obj.getValues(), proc);
|
|
110 |
}
|
|
111 |
}
|
|
112 |
if (liveBasePointers != null) {
|
|
113 |
liveBasePointers.visitEach(inst, OperandMode.ALIVE, STATE_FLAGS, proc);
|
|
114 |
}
|
|
115 |
}
|
|
116 |
|
|
117 |
/**
|
|
118 |
* We filter out constant and illegal values ourself before calling the procedure, so
|
|
119 |
* {@link OperandFlag#CONST} and {@link OperandFlag#ILLEGAL} need not be set.
|
|
120 |
*/
|
|
121 |
protected static final EnumSet<OperandFlag> STATE_FLAGS = EnumSet.of(OperandFlag.REG, OperandFlag.STACK);
|
|
122 |
|
|
123 |
protected void processValues(LIRInstruction inst, JavaValue[] values, InstructionValueProcedure proc) {
|
|
124 |
for (int i = 0; i < values.length; i++) {
|
|
125 |
JavaValue value = values[i];
|
|
126 |
if (isIllegalJavaValue(value)) {
|
|
127 |
continue;
|
|
128 |
}
|
|
129 |
if (value instanceof AllocatableValue) {
|
|
130 |
AllocatableValue allocatable = (AllocatableValue) value;
|
|
131 |
Value result = proc.doValue(inst, allocatable, OperandMode.ALIVE, STATE_FLAGS);
|
|
132 |
if (!allocatable.identityEquals(result)) {
|
|
133 |
values[i] = (JavaValue) result;
|
|
134 |
}
|
|
135 |
} else if (value instanceof StackLockValue) {
|
|
136 |
StackLockValue monitor = (StackLockValue) value;
|
|
137 |
JavaValue owner = monitor.getOwner();
|
|
138 |
if (owner instanceof AllocatableValue) {
|
|
139 |
monitor.setOwner((JavaValue) proc.doValue(inst, (AllocatableValue) owner, OperandMode.ALIVE, STATE_FLAGS));
|
|
140 |
}
|
|
141 |
Value slot = monitor.getSlot();
|
|
142 |
if (isVirtualStackSlot(slot)) {
|
|
143 |
monitor.setSlot(asAllocatableValue(proc.doValue(inst, slot, OperandMode.ALIVE, STATE_FLAGS)));
|
|
144 |
}
|
|
145 |
} else {
|
|
146 |
assert unprocessed(value);
|
|
147 |
}
|
|
148 |
}
|
|
149 |
}
|
|
150 |
|
|
151 |
protected void visitValues(LIRInstruction inst, JavaValue[] values, InstructionValueConsumer proc) {
|
|
152 |
for (int i = 0; i < values.length; i++) {
|
|
153 |
JavaValue value = values[i];
|
|
154 |
if (isIllegalJavaValue(value)) {
|
|
155 |
continue;
|
|
156 |
} else if (value instanceof AllocatableValue) {
|
|
157 |
proc.visitValue(inst, (AllocatableValue) value, OperandMode.ALIVE, STATE_FLAGS);
|
|
158 |
} else if (value instanceof StackLockValue) {
|
|
159 |
StackLockValue monitor = (StackLockValue) value;
|
|
160 |
JavaValue owner = monitor.getOwner();
|
|
161 |
if (owner instanceof AllocatableValue) {
|
|
162 |
proc.visitValue(inst, (AllocatableValue) owner, OperandMode.ALIVE, STATE_FLAGS);
|
|
163 |
}
|
|
164 |
Value slot = monitor.getSlot();
|
|
165 |
if (isVirtualStackSlot(slot)) {
|
|
166 |
proc.visitValue(inst, slot, OperandMode.ALIVE, STATE_FLAGS);
|
|
167 |
}
|
|
168 |
} else {
|
|
169 |
assert unprocessed(value);
|
|
170 |
}
|
|
171 |
}
|
|
172 |
}
|
|
173 |
|
|
174 |
private boolean unprocessed(JavaValue value) {
|
|
175 |
if (isIllegalJavaValue(value)) {
|
|
176 |
// Ignore dead local variables.
|
|
177 |
return true;
|
|
178 |
} else if (isConstantJavaValue(value)) {
|
|
179 |
// Ignore constants, the register allocator does not need to see them.
|
|
180 |
return true;
|
|
181 |
} else if (isVirtualObject(value)) {
|
|
182 |
assert Arrays.asList(virtualObjects).contains(value);
|
|
183 |
return true;
|
|
184 |
} else {
|
|
185 |
return false;
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
/**
|
|
190 |
* Called by the register allocator to initialize the frame state.
|
|
191 |
*
|
|
192 |
* @param frameMap The frame map.
|
|
193 |
* @param canHaveRegisters True if there can be any register map entries.
|
|
194 |
*/
|
|
195 |
public void initDebugInfo(FrameMap frameMap, boolean canHaveRegisters) {
|
|
196 |
debugInfo = new DebugInfo(topFrame, virtualObjects);
|
|
197 |
}
|
|
198 |
|
|
199 |
public IndexedValueMap getLiveBasePointers() {
|
|
200 |
return liveBasePointers;
|
|
201 |
}
|
|
202 |
|
|
203 |
public void setLiveBasePointers(IndexedValueMap liveBasePointers) {
|
|
204 |
this.liveBasePointers = liveBasePointers;
|
|
205 |
}
|
|
206 |
|
|
207 |
@Override
|
|
208 |
public String toString() {
|
|
209 |
return debugInfo != null ? debugInfo.toString() : topFrame != null ? topFrame.toString() : "<empty>";
|
|
210 |
}
|
|
211 |
}
|