author | iveresov |
Fri, 02 Feb 2018 17:28:17 -0800 | |
changeset 48861 | 47f19ff9903c |
parent 48172 | e26fc5201707 |
child 49451 | e06f9607f370 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
2 |
* Copyright (c) 2012, 2017, 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.hotspot.amd64; |
|
24 |
||
46344 | 25 |
import static jdk.vm.ci.amd64.AMD64.rbp; |
43972 | 26 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
27 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL; |
|
28 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL; |
|
29 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS; |
|
30 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL; |
|
47667 | 31 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE; |
32 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.RESOLVE; |
|
33 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.INITIALIZE; |
|
34 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.LOAD_COUNTERS; |
|
43972 | 35 |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.List; |
|
38 |
||
39 |
import org.graalvm.compiler.asm.amd64.AMD64Address.Scale; |
|
40 |
import org.graalvm.compiler.core.amd64.AMD64ArithmeticLIRGenerator; |
|
41 |
import org.graalvm.compiler.core.amd64.AMD64LIRGenerator; |
|
42 |
import org.graalvm.compiler.core.amd64.AMD64MoveFactoryBase.BackupSlotProvider; |
|
46344 | 43 |
import org.graalvm.compiler.core.common.CompressEncoding; |
43972 | 44 |
import org.graalvm.compiler.core.common.LIRKind; |
47667 | 45 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; |
43972 | 46 |
import org.graalvm.compiler.core.common.spi.ForeignCallLinkage; |
47 |
import org.graalvm.compiler.core.common.spi.LIRKindTool; |
|
46640 | 48 |
import org.graalvm.compiler.debug.DebugContext; |
43972 | 49 |
import org.graalvm.compiler.debug.GraalError; |
50 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
|
51 |
import org.graalvm.compiler.hotspot.HotSpotBackend; |
|
52 |
import org.graalvm.compiler.hotspot.HotSpotDebugInfoBuilder; |
|
53 |
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; |
|
54 |
import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult; |
|
55 |
import org.graalvm.compiler.hotspot.HotSpotLIRGenerator; |
|
56 |
import org.graalvm.compiler.hotspot.HotSpotLockStack; |
|
57 |
import org.graalvm.compiler.hotspot.debug.BenchmarkCounters; |
|
58 |
import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction; |
|
59 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
|
60 |
import org.graalvm.compiler.hotspot.stubs.Stub; |
|
61 |
import org.graalvm.compiler.lir.LIR; |
|
62 |
import org.graalvm.compiler.lir.LIRFrameState; |
|
63 |
import org.graalvm.compiler.lir.LIRInstruction; |
|
64 |
import org.graalvm.compiler.lir.LIRInstructionClass; |
|
65 |
import org.graalvm.compiler.lir.LabelRef; |
|
66 |
import org.graalvm.compiler.lir.StandardOp.NoOp; |
|
67 |
import org.graalvm.compiler.lir.SwitchStrategy; |
|
68 |
import org.graalvm.compiler.lir.Variable; |
|
69 |
import org.graalvm.compiler.lir.VirtualStackSlot; |
|
70 |
import org.graalvm.compiler.lir.amd64.AMD64AddressValue; |
|
71 |
import org.graalvm.compiler.lir.amd64.AMD64CCall; |
|
72 |
import org.graalvm.compiler.lir.amd64.AMD64ControlFlow.StrategySwitchOp; |
|
73 |
import org.graalvm.compiler.lir.amd64.AMD64FrameMapBuilder; |
|
74 |
import org.graalvm.compiler.lir.amd64.AMD64Move; |
|
75 |
import org.graalvm.compiler.lir.amd64.AMD64Move.MoveFromRegOp; |
|
76 |
import org.graalvm.compiler.lir.amd64.AMD64PrefetchOp; |
|
77 |
import org.graalvm.compiler.lir.amd64.AMD64ReadTimestampCounter; |
|
78 |
import org.graalvm.compiler.lir.amd64.AMD64RestoreRegistersOp; |
|
79 |
import org.graalvm.compiler.lir.amd64.AMD64SaveRegistersOp; |
|
80 |
import org.graalvm.compiler.lir.amd64.AMD64VZeroUpper; |
|
81 |
import org.graalvm.compiler.lir.asm.CompilationResultBuilder; |
|
82 |
import org.graalvm.compiler.lir.framemap.FrameMapBuilder; |
|
83 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult; |
|
46344 | 84 |
import org.graalvm.compiler.options.OptionValues; |
43972 | 85 |
|
86 |
import jdk.vm.ci.amd64.AMD64; |
|
87 |
import jdk.vm.ci.amd64.AMD64Kind; |
|
88 |
import jdk.vm.ci.code.CallingConvention; |
|
89 |
import jdk.vm.ci.code.Register; |
|
90 |
import jdk.vm.ci.code.RegisterConfig; |
|
91 |
import jdk.vm.ci.code.RegisterValue; |
|
92 |
import jdk.vm.ci.code.StackSlot; |
|
93 |
import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant; |
|
94 |
import jdk.vm.ci.hotspot.HotSpotObjectConstant; |
|
95 |
import jdk.vm.ci.meta.AllocatableValue; |
|
96 |
import jdk.vm.ci.meta.Constant; |
|
97 |
import jdk.vm.ci.meta.DeoptimizationAction; |
|
98 |
import jdk.vm.ci.meta.DeoptimizationReason; |
|
99 |
import jdk.vm.ci.meta.JavaConstant; |
|
100 |
import jdk.vm.ci.meta.JavaKind; |
|
101 |
import jdk.vm.ci.meta.PlatformKind; |
|
102 |
import jdk.vm.ci.meta.PrimitiveConstant; |
|
103 |
import jdk.vm.ci.meta.Value; |
|
104 |
||
105 |
/** |
|
106 |
* LIR generator specialized for AMD64 HotSpot. |
|
107 |
*/ |
|
108 |
public class AMD64HotSpotLIRGenerator extends AMD64LIRGenerator implements HotSpotLIRGenerator { |
|
109 |
||
110 |
final GraalHotSpotVMConfig config; |
|
111 |
private HotSpotDebugInfoBuilder debugInfoBuilder; |
|
112 |
||
113 |
protected AMD64HotSpotLIRGenerator(HotSpotProviders providers, GraalHotSpotVMConfig config, LIRGenerationResult lirGenRes) { |
|
114 |
this(providers, config, lirGenRes, new BackupSlotProvider(lirGenRes.getFrameMapBuilder())); |
|
115 |
} |
|
116 |
||
117 |
private AMD64HotSpotLIRGenerator(HotSpotProviders providers, GraalHotSpotVMConfig config, LIRGenerationResult lirGenRes, BackupSlotProvider backupSlotProvider) { |
|
47798 | 118 |
this(new AMD64HotSpotLIRKindTool(), new AMD64HotSpotArithmeticLIRGenerator(), new AMD64HotSpotMoveFactory(backupSlotProvider), providers, config, lirGenRes); |
43972 | 119 |
} |
120 |
||
121 |
protected AMD64HotSpotLIRGenerator(LIRKindTool lirKindTool, AMD64ArithmeticLIRGenerator arithmeticLIRGen, MoveFactory moveFactory, HotSpotProviders providers, GraalHotSpotVMConfig config, |
|
122 |
LIRGenerationResult lirGenRes) { |
|
123 |
super(lirKindTool, arithmeticLIRGen, moveFactory, providers, lirGenRes); |
|
124 |
assert config.basicLockSize == 8; |
|
125 |
this.config = config; |
|
126 |
} |
|
127 |
||
128 |
@Override |
|
129 |
public HotSpotProviders getProviders() { |
|
130 |
return (HotSpotProviders) super.getProviders(); |
|
131 |
} |
|
132 |
||
133 |
/** |
|
134 |
* Utility for emitting the instruction to save RBP. |
|
135 |
*/ |
|
136 |
class SaveRbp { |
|
137 |
||
138 |
final NoOp placeholder; |
|
139 |
||
140 |
/** |
|
141 |
* The slot reserved for saving RBP. |
|
142 |
*/ |
|
143 |
final StackSlot reservedSlot; |
|
144 |
||
145 |
SaveRbp(NoOp placeholder) { |
|
146 |
this.placeholder = placeholder; |
|
147 |
AMD64FrameMapBuilder frameMapBuilder = (AMD64FrameMapBuilder) getResult().getFrameMapBuilder(); |
|
148 |
this.reservedSlot = frameMapBuilder.allocateRBPSpillSlot(); |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* Replaces this operation with the appropriate move for saving rbp. |
|
153 |
* |
|
154 |
* @param useStack specifies if rbp must be saved to the stack |
|
155 |
*/ |
|
156 |
public AllocatableValue finalize(boolean useStack) { |
|
157 |
AllocatableValue dst; |
|
158 |
if (useStack) { |
|
159 |
dst = reservedSlot; |
|
160 |
} else { |
|
161 |
((AMD64FrameMapBuilder) getResult().getFrameMapBuilder()).freeRBPSpillSlot(); |
|
162 |
dst = newVariable(LIRKind.value(AMD64Kind.QWORD)); |
|
163 |
} |
|
164 |
||
165 |
placeholder.replace(getResult().getLIR(), new MoveFromRegOp(AMD64Kind.QWORD, dst, rbp.asValue(LIRKind.value(AMD64Kind.QWORD)))); |
|
166 |
return dst; |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
private SaveRbp saveRbp; |
|
171 |
||
172 |
protected void emitSaveRbp() { |
|
173 |
NoOp placeholder = new NoOp(getCurrentBlock(), getResult().getLIR().getLIRforBlock(getCurrentBlock()).size()); |
|
174 |
append(placeholder); |
|
175 |
saveRbp = new SaveRbp(placeholder); |
|
176 |
} |
|
177 |
||
178 |
protected SaveRbp getSaveRbp() { |
|
179 |
return saveRbp; |
|
180 |
} |
|
181 |
||
182 |
/** |
|
183 |
* Helper instruction to reserve a stack slot for the whole method. Note that the actual users |
|
184 |
* of the stack slot might be inserted after stack slot allocation. This dummy instruction |
|
185 |
* ensures that the stack slot is alive and gets a real stack slot assigned. |
|
186 |
*/ |
|
187 |
private static final class RescueSlotDummyOp extends LIRInstruction { |
|
188 |
public static final LIRInstructionClass<RescueSlotDummyOp> TYPE = LIRInstructionClass.create(RescueSlotDummyOp.class); |
|
189 |
||
190 |
@Alive({OperandFlag.STACK, OperandFlag.UNINITIALIZED}) private AllocatableValue slot; |
|
191 |
||
192 |
RescueSlotDummyOp(FrameMapBuilder frameMapBuilder, LIRKind kind) { |
|
193 |
super(TYPE); |
|
194 |
slot = frameMapBuilder.allocateSpillSlot(kind); |
|
195 |
} |
|
196 |
||
197 |
public AllocatableValue getSlot() { |
|
198 |
return slot; |
|
199 |
} |
|
200 |
||
201 |
@Override |
|
202 |
public void emitCode(CompilationResultBuilder crb) { |
|
203 |
} |
|
204 |
} |
|
205 |
||
206 |
private RescueSlotDummyOp rescueSlotOp; |
|
207 |
||
208 |
private AllocatableValue getOrInitRescueSlot() { |
|
209 |
RescueSlotDummyOp op = getOrInitRescueSlotOp(); |
|
210 |
return op.getSlot(); |
|
211 |
} |
|
212 |
||
213 |
private RescueSlotDummyOp getOrInitRescueSlotOp() { |
|
214 |
if (rescueSlotOp == null) { |
|
215 |
// create dummy instruction to keep the rescue slot alive |
|
216 |
rescueSlotOp = new RescueSlotDummyOp(getResult().getFrameMapBuilder(), getLIRKindTool().getWordKind()); |
|
217 |
} |
|
218 |
return rescueSlotOp; |
|
219 |
} |
|
220 |
||
221 |
/** |
|
222 |
* List of epilogue operations that need to restore RBP. |
|
223 |
*/ |
|
224 |
List<AMD64HotSpotRestoreRbpOp> epilogueOps = new ArrayList<>(2); |
|
225 |
||
226 |
@Override |
|
227 |
public <I extends LIRInstruction> I append(I op) { |
|
228 |
I ret = super.append(op); |
|
229 |
if (op instanceof AMD64HotSpotRestoreRbpOp) { |
|
230 |
epilogueOps.add((AMD64HotSpotRestoreRbpOp) op); |
|
231 |
} |
|
232 |
return ret; |
|
233 |
} |
|
234 |
||
235 |
@Override |
|
236 |
public VirtualStackSlot getLockSlot(int lockDepth) { |
|
237 |
return getLockStack().makeLockSlot(lockDepth); |
|
238 |
} |
|
239 |
||
240 |
private HotSpotLockStack getLockStack() { |
|
241 |
assert debugInfoBuilder != null && debugInfoBuilder.lockStack() != null; |
|
242 |
return debugInfoBuilder.lockStack(); |
|
243 |
} |
|
244 |
||
245 |
private Register findPollOnReturnScratchRegister() { |
|
246 |
RegisterConfig regConfig = getProviders().getCodeCache().getRegisterConfig(); |
|
247 |
for (Register r : regConfig.getAllocatableRegisters()) { |
|
248 |
if (!r.equals(regConfig.getReturnRegister(JavaKind.Long)) && !r.equals(AMD64.rbp)) { |
|
249 |
return r; |
|
250 |
} |
|
251 |
} |
|
252 |
throw GraalError.shouldNotReachHere(); |
|
253 |
} |
|
254 |
||
255 |
private Register pollOnReturnScratchRegister; |
|
256 |
||
257 |
@Override |
|
258 |
public void emitReturn(JavaKind kind, Value input) { |
|
259 |
AllocatableValue operand = Value.ILLEGAL; |
|
260 |
if (input != null) { |
|
261 |
operand = resultOperandFor(kind, input.getValueKind()); |
|
262 |
emitMove(operand, input); |
|
263 |
} |
|
264 |
if (pollOnReturnScratchRegister == null) { |
|
265 |
pollOnReturnScratchRegister = findPollOnReturnScratchRegister(); |
|
266 |
} |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47798
diff
changeset
|
267 |
Register thread = getProviders().getRegisters().getThreadRegister(); |
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47798
diff
changeset
|
268 |
append(new AMD64HotSpotReturnOp(operand, getStub() != null, thread, pollOnReturnScratchRegister, config)); |
43972 | 269 |
} |
270 |
||
271 |
@Override |
|
272 |
public boolean needOnlyOopMaps() { |
|
273 |
// Stubs only need oop maps |
|
274 |
return getResult().getStub() != null; |
|
275 |
} |
|
276 |
||
277 |
private LIRFrameState currentRuntimeCallInfo; |
|
278 |
||
279 |
@Override |
|
280 |
protected void emitForeignCallOp(ForeignCallLinkage linkage, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { |
|
281 |
currentRuntimeCallInfo = info; |
|
282 |
HotSpotForeignCallLinkage hsLinkage = (HotSpotForeignCallLinkage) linkage; |
|
283 |
AMD64 arch = (AMD64) target().arch; |
|
284 |
if (arch.getFeatures().contains(AMD64.CPUFeature.AVX) && hsLinkage.mayContainFP() && !hsLinkage.isCompiledStub()) { |
|
285 |
/* |
|
286 |
* If the target may contain FP ops, and it is not compiled by us, we may have an |
|
287 |
* AVX-SSE transition. |
|
288 |
* |
|
289 |
* We exclude the argument registers from the zeroing LIR instruction since it violates |
|
290 |
* the LIR semantics of @Temp that values must not be live. Note that the emitted |
|
291 |
* machine instruction actually zeros _all_ XMM registers which is fine since we know |
|
292 |
* that their upper half is not used. |
|
293 |
*/ |
|
294 |
append(new AMD64VZeroUpper(arguments)); |
|
295 |
} |
|
296 |
super.emitForeignCallOp(linkage, result, arguments, temps, info); |
|
297 |
} |
|
298 |
||
299 |
/** |
|
300 |
* @param savedRegisters the registers saved by this operation which may be subject to pruning |
|
301 |
* @param savedRegisterLocations the slots to which the registers are saved |
|
302 |
* @param supportsRemove determines if registers can be pruned |
|
303 |
*/ |
|
304 |
protected AMD64SaveRegistersOp emitSaveRegisters(Register[] savedRegisters, AllocatableValue[] savedRegisterLocations, boolean supportsRemove) { |
|
305 |
AMD64SaveRegistersOp save = new AMD64SaveRegistersOp(savedRegisters, savedRegisterLocations, supportsRemove); |
|
306 |
append(save); |
|
307 |
return save; |
|
308 |
} |
|
309 |
||
310 |
/** |
|
311 |
* Allocate a stack slot for saving a register. |
|
312 |
*/ |
|
313 |
protected VirtualStackSlot allocateSaveRegisterLocation(Register register) { |
|
314 |
PlatformKind kind = target().arch.getLargestStorableKind(register.getRegisterCategory()); |
|
315 |
if (kind.getVectorLength() > 1) { |
|
316 |
// we don't use vector registers, so there is no need to save them |
|
317 |
kind = AMD64Kind.DOUBLE; |
|
318 |
} |
|
319 |
return getResult().getFrameMapBuilder().allocateSpillSlot(LIRKind.value(kind)); |
|
320 |
} |
|
321 |
||
322 |
/** |
|
323 |
* Adds a node to the graph that saves all allocatable registers to the stack. |
|
324 |
* |
|
325 |
* @param supportsRemove determines if registers can be pruned |
|
326 |
* @return the register save node |
|
327 |
*/ |
|
328 |
private AMD64SaveRegistersOp emitSaveAllRegisters(Register[] savedRegisters, boolean supportsRemove) { |
|
329 |
AllocatableValue[] savedRegisterLocations = new AllocatableValue[savedRegisters.length]; |
|
330 |
for (int i = 0; i < savedRegisters.length; i++) { |
|
331 |
savedRegisterLocations[i] = allocateSaveRegisterLocation(savedRegisters[i]); |
|
332 |
} |
|
333 |
return emitSaveRegisters(savedRegisters, savedRegisterLocations, supportsRemove); |
|
334 |
} |
|
335 |
||
336 |
protected void emitRestoreRegisters(AMD64SaveRegistersOp save) { |
|
337 |
append(new AMD64RestoreRegistersOp(save.getSlots().clone(), save)); |
|
338 |
} |
|
339 |
||
340 |
/** |
|
341 |
* Gets the {@link Stub} this generator is generating code for or {@code null} if a stub is not |
|
342 |
* being generated. |
|
343 |
*/ |
|
344 |
public Stub getStub() { |
|
345 |
return getResult().getStub(); |
|
346 |
} |
|
347 |
||
348 |
@Override |
|
349 |
public HotSpotLIRGenerationResult getResult() { |
|
350 |
return ((HotSpotLIRGenerationResult) super.getResult()); |
|
351 |
} |
|
352 |
||
353 |
public void setDebugInfoBuilder(HotSpotDebugInfoBuilder debugInfoBuilder) { |
|
354 |
this.debugInfoBuilder = debugInfoBuilder; |
|
355 |
} |
|
356 |
||
357 |
@Override |
|
358 |
public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args) { |
|
359 |
HotSpotForeignCallLinkage hotspotLinkage = (HotSpotForeignCallLinkage) linkage; |
|
360 |
boolean destroysRegisters = hotspotLinkage.destroysRegisters(); |
|
361 |
||
362 |
AMD64SaveRegistersOp save = null; |
|
363 |
Stub stub = getStub(); |
|
364 |
if (destroysRegisters) { |
|
365 |
if (stub != null && stub.preservesRegisters()) { |
|
47798 | 366 |
Register[] savedRegisters = getRegisterConfig().getAllocatableRegisters().toArray(); |
43972 | 367 |
save = emitSaveAllRegisters(savedRegisters, true); |
368 |
} |
|
369 |
} |
|
370 |
||
371 |
Variable result; |
|
372 |
LIRFrameState debugInfo = null; |
|
373 |
if (hotspotLinkage.needsDebugInfo()) { |
|
374 |
debugInfo = state; |
|
375 |
assert debugInfo != null || stub != null; |
|
376 |
} |
|
377 |
||
378 |
if (hotspotLinkage.needsJavaFrameAnchor()) { |
|
379 |
Register thread = getProviders().getRegisters().getThreadRegister(); |
|
380 |
append(new AMD64HotSpotCRuntimeCallPrologueOp(config.threadLastJavaSpOffset(), thread)); |
|
381 |
result = super.emitForeignCall(hotspotLinkage, debugInfo, args); |
|
382 |
append(new AMD64HotSpotCRuntimeCallEpilogueOp(config.threadLastJavaSpOffset(), config.threadLastJavaFpOffset(), config.threadLastJavaPcOffset(), thread)); |
|
383 |
} else { |
|
384 |
result = super.emitForeignCall(hotspotLinkage, debugInfo, args); |
|
385 |
} |
|
386 |
||
387 |
if (destroysRegisters) { |
|
388 |
if (stub != null) { |
|
389 |
if (stub.preservesRegisters()) { |
|
390 |
HotSpotLIRGenerationResult generationResult = getResult(); |
|
46344 | 391 |
LIRFrameState key = currentRuntimeCallInfo; |
392 |
if (key == null) { |
|
393 |
key = LIRFrameState.NO_STATE; |
|
394 |
} |
|
395 |
assert !generationResult.getCalleeSaveInfo().containsKey(key); |
|
396 |
generationResult.getCalleeSaveInfo().put(key, save); |
|
43972 | 397 |
emitRestoreRegisters(save); |
398 |
} |
|
399 |
} |
|
400 |
} |
|
401 |
||
402 |
return result; |
|
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public Value emitLoadObjectAddress(Constant constant) { |
|
407 |
HotSpotObjectConstant objectConstant = (HotSpotObjectConstant) constant; |
|
46459 | 408 |
LIRKind kind = objectConstant.isCompressed() ? getLIRKindTool().getNarrowOopKind() : getLIRKindTool().getObjectKind(); |
43972 | 409 |
Variable result = newVariable(kind); |
410 |
append(new AMD64HotSpotLoadAddressOp(result, constant, HotSpotConstantLoadAction.RESOLVE)); |
|
411 |
return result; |
|
412 |
} |
|
413 |
||
414 |
@Override |
|
415 |
public Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { |
|
416 |
HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant; |
|
46459 | 417 |
LIRKind kind = metaspaceConstant.isCompressed() ? getLIRKindTool().getNarrowPointerKind() : getLIRKindTool().getWordKind(); |
43972 | 418 |
Variable result = newVariable(kind); |
419 |
append(new AMD64HotSpotLoadAddressOp(result, constant, action)); |
|
420 |
return result; |
|
421 |
} |
|
422 |
||
47667 | 423 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, Object[] notes, Constant[] constants, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { |
424 |
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(foreignCall); |
|
43972 | 425 |
append(new AMD64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); |
426 |
AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); |
|
427 |
return emitMove(result); |
|
428 |
} |
|
429 |
||
47667 | 430 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { |
431 |
Constant[] constants = new Constant[]{constant}; |
|
432 |
Object[] notes = new Object[]{action}; |
|
433 |
return emitConstantRetrieval(foreignCall, notes, constants, constantDescriptions, frameState); |
|
434 |
} |
|
435 |
||
436 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
437 |
AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; |
|
438 |
return emitConstantRetrieval(foreignCall, action, constant, constantDescriptions, frameState); |
|
439 |
} |
|
440 |
||
43972 | 441 |
@Override |
47667 | 442 |
public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
443 |
return emitConstantRetrieval(RESOLVE_STRING_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); |
|
444 |
} |
|
43972 | 445 |
|
47667 | 446 |
@Override |
447 |
public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
448 |
return emitConstantRetrieval(RESOLVE_KLASS_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); |
|
43972 | 449 |
} |
450 |
||
451 |
@Override |
|
452 |
public Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
47667 | 453 |
return emitConstantRetrieval(INITIALIZE_KLASS_BY_SYMBOL, INITIALIZE, constant, constantDescription, frameState); |
454 |
} |
|
455 |
||
456 |
@Override |
|
457 |
public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { |
|
458 |
AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)}; |
|
459 |
return emitConstantRetrieval(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, LOAD_COUNTERS, method, constantDescriptions, frameState); |
|
460 |
} |
|
461 |
||
462 |
@Override |
|
463 |
public Value emitResolveDynamicInvoke(Constant appendix, LIRFrameState frameState) { |
|
464 |
AllocatableValue[] constantDescriptions = new AllocatableValue[0]; |
|
465 |
return emitConstantRetrieval(RESOLVE_DYNAMIC_INVOKE, INITIALIZE, appendix, constantDescriptions, frameState); |
|
43972 | 466 |
} |
467 |
||
468 |
@Override |
|
469 |
public Value emitLoadConfigValue(int markId, LIRKind kind) { |
|
470 |
Variable result = newVariable(kind); |
|
471 |
append(new AMD64HotSpotLoadConfigValueOp(markId, result)); |
|
472 |
return result; |
|
473 |
} |
|
474 |
||
475 |
@Override |
|
476 |
public Value emitRandomSeed() { |
|
477 |
AMD64ReadTimestampCounter timestamp = new AMD64ReadTimestampCounter(); |
|
478 |
append(timestamp); |
|
479 |
return emitMove(timestamp.getLowResult()); |
|
480 |
} |
|
481 |
||
482 |
@Override |
|
483 |
public void emitTailcall(Value[] args, Value address) { |
|
484 |
append(new AMD64TailcallOp(args, address)); |
|
485 |
} |
|
486 |
||
487 |
@Override |
|
488 |
public void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args, int numberOfFloatingPointArguments) { |
|
489 |
Value[] argLocations = new Value[args.length]; |
|
490 |
getResult().getFrameMapBuilder().callsMethod(nativeCallingConvention); |
|
491 |
// TODO(mg): in case a native function uses floating point varargs, the ABI requires that |
|
492 |
// RAX contains the length of the varargs |
|
493 |
PrimitiveConstant intConst = JavaConstant.forInt(numberOfFloatingPointArguments); |
|
494 |
AllocatableValue numberOfFloatingPointArgumentsRegister = AMD64.rax.asValue(LIRKind.value(AMD64Kind.DWORD)); |
|
495 |
emitMoveConstant(numberOfFloatingPointArgumentsRegister, intConst); |
|
496 |
for (int i = 0; i < args.length; i++) { |
|
497 |
Value arg = args[i]; |
|
498 |
AllocatableValue loc = nativeCallingConvention.getArgument(i); |
|
499 |
emitMove(loc, arg); |
|
500 |
argLocations[i] = loc; |
|
501 |
} |
|
502 |
Value ptr = emitLoadConstant(LIRKind.value(AMD64Kind.QWORD), JavaConstant.forLong(address)); |
|
503 |
append(new AMD64CCall(nativeCallingConvention.getReturn(), ptr, numberOfFloatingPointArgumentsRegister, argLocations)); |
|
504 |
} |
|
505 |
||
506 |
@Override |
|
507 |
public void emitUnwind(Value exception) { |
|
508 |
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER); |
|
509 |
CallingConvention outgoingCc = linkage.getOutgoingCallingConvention(); |
|
510 |
assert outgoingCc.getArgumentCount() == 2; |
|
511 |
RegisterValue exceptionParameter = (RegisterValue) outgoingCc.getArgument(0); |
|
512 |
emitMove(exceptionParameter, exception); |
|
513 |
append(new AMD64HotSpotUnwindOp(exceptionParameter)); |
|
514 |
} |
|
515 |
||
516 |
private void moveDeoptValuesToThread(Value actionAndReason, Value speculation) { |
|
517 |
moveValueToThread(actionAndReason, config.pendingDeoptimizationOffset); |
|
518 |
moveValueToThread(speculation, config.pendingFailedSpeculationOffset); |
|
519 |
} |
|
520 |
||
521 |
private void moveValueToThread(Value v, int offset) { |
|
522 |
LIRKind wordKind = LIRKind.value(target().arch.getWordKind()); |
|
523 |
RegisterValue thread = getProviders().getRegisters().getThreadRegister().asValue(wordKind); |
|
524 |
AMD64AddressValue address = new AMD64AddressValue(wordKind, thread, offset); |
|
525 |
arithmeticLIRGen.emitStore(v.getValueKind(), address, v, null); |
|
526 |
} |
|
527 |
||
528 |
@Override |
|
529 |
public void emitDeoptimize(Value actionAndReason, Value speculation, LIRFrameState state) { |
|
530 |
moveDeoptValuesToThread(actionAndReason, speculation); |
|
531 |
append(new AMD64DeoptimizeOp(state)); |
|
532 |
} |
|
533 |
||
534 |
@Override |
|
535 |
public void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason) { |
|
536 |
Value actionAndReason = emitJavaConstant(getMetaAccess().encodeDeoptActionAndReason(action, reason, 0)); |
|
537 |
Value nullValue = emitConstant(LIRKind.reference(AMD64Kind.QWORD), JavaConstant.NULL_POINTER); |
|
538 |
moveDeoptValuesToThread(actionAndReason, nullValue); |
|
539 |
append(new AMD64HotSpotDeoptimizeCallerOp()); |
|
540 |
} |
|
541 |
||
542 |
@Override |
|
543 |
public void beforeRegisterAllocation() { |
|
544 |
super.beforeRegisterAllocation(); |
|
545 |
boolean hasDebugInfo = getResult().getLIR().hasDebugInfo(); |
|
546 |
AllocatableValue savedRbp = saveRbp.finalize(hasDebugInfo); |
|
547 |
if (hasDebugInfo) { |
|
548 |
getResult().setDeoptimizationRescueSlot(((AMD64FrameMapBuilder) getResult().getFrameMapBuilder()).allocateDeoptimizationRescueSlot()); |
|
549 |
} |
|
550 |
||
551 |
getResult().setMaxInterpreterFrameSize(debugInfoBuilder.maxInterpreterFrameSize()); |
|
552 |
||
553 |
for (AMD64HotSpotRestoreRbpOp op : epilogueOps) { |
|
554 |
op.setSavedRbp(savedRbp); |
|
555 |
} |
|
556 |
if (BenchmarkCounters.enabled) { |
|
557 |
// ensure that the rescue slot is available |
|
558 |
LIRInstruction op = getOrInitRescueSlotOp(); |
|
559 |
// insert dummy instruction into the start block |
|
560 |
LIR lir = getResult().getLIR(); |
|
46344 | 561 |
ArrayList<LIRInstruction> instructions = lir.getLIRforBlock(lir.getControlFlowGraph().getStartBlock()); |
43972 | 562 |
instructions.add(1, op); |
46640 | 563 |
lir.getDebug().dump(DebugContext.INFO_LEVEL, lir, "created rescue dummy op"); |
43972 | 564 |
} |
565 |
} |
|
566 |
||
567 |
@Override |
|
568 |
public Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull) { |
|
569 |
LIRKind inputKind = pointer.getValueKind(LIRKind.class); |
|
47798 | 570 |
LIRKindTool lirKindTool = getLIRKindTool(); |
571 |
assert inputKind.getPlatformKind() == lirKindTool.getObjectKind().getPlatformKind(); |
|
43972 | 572 |
if (inputKind.isReference(0)) { |
573 |
// oop |
|
47798 | 574 |
Variable result = newVariable(lirKindTool.getNarrowOopKind()); |
48861 | 575 |
append(new AMD64Move.CompressPointerOp(result, asAllocatable(pointer), getProviders().getRegisters().getHeapBaseRegister().asValue(), encoding, nonNull, getLIRKindTool())); |
43972 | 576 |
return result; |
577 |
} else { |
|
578 |
// metaspace pointer |
|
47798 | 579 |
Variable result = newVariable(lirKindTool.getNarrowPointerKind()); |
43972 | 580 |
AllocatableValue base = Value.ILLEGAL; |
46344 | 581 |
OptionValues options = getResult().getLIR().getOptions(); |
582 |
if (encoding.hasBase() || GeneratePIC.getValue(options)) { |
|
583 |
if (GeneratePIC.getValue(options)) { |
|
47798 | 584 |
Variable baseAddress = newVariable(lirKindTool.getWordKind()); |
43972 | 585 |
AMD64HotSpotMove.BaseMove move = new AMD64HotSpotMove.BaseMove(baseAddress, config); |
586 |
append(move); |
|
587 |
base = baseAddress; |
|
588 |
} else { |
|
47798 | 589 |
base = emitLoadConstant(lirKindTool.getWordKind(), JavaConstant.forLong(encoding.getBase())); |
43972 | 590 |
} |
591 |
} |
|
48861 | 592 |
append(new AMD64Move.CompressPointerOp(result, asAllocatable(pointer), base, encoding, nonNull, getLIRKindTool())); |
43972 | 593 |
return result; |
594 |
} |
|
595 |
} |
|
596 |
||
597 |
@Override |
|
598 |
public Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull) { |
|
599 |
LIRKind inputKind = pointer.getValueKind(LIRKind.class); |
|
47798 | 600 |
LIRKindTool lirKindTool = getLIRKindTool(); |
601 |
assert inputKind.getPlatformKind() == lirKindTool.getNarrowOopKind().getPlatformKind(); |
|
43972 | 602 |
if (inputKind.isReference(0)) { |
603 |
// oop |
|
47798 | 604 |
Variable result = newVariable(lirKindTool.getObjectKind()); |
48861 | 605 |
append(new AMD64Move.UncompressPointerOp(result, asAllocatable(pointer), getProviders().getRegisters().getHeapBaseRegister().asValue(), encoding, nonNull, lirKindTool)); |
43972 | 606 |
return result; |
607 |
} else { |
|
608 |
// metaspace pointer |
|
47798 | 609 |
LIRKind uncompressedKind = lirKindTool.getWordKind(); |
610 |
Variable result = newVariable(uncompressedKind); |
|
43972 | 611 |
AllocatableValue base = Value.ILLEGAL; |
46344 | 612 |
OptionValues options = getResult().getLIR().getOptions(); |
613 |
if (encoding.hasBase() || GeneratePIC.getValue(options)) { |
|
614 |
if (GeneratePIC.getValue(options)) { |
|
47798 | 615 |
Variable baseAddress = newVariable(uncompressedKind); |
43972 | 616 |
AMD64HotSpotMove.BaseMove move = new AMD64HotSpotMove.BaseMove(baseAddress, config); |
617 |
append(move); |
|
618 |
base = baseAddress; |
|
619 |
} else { |
|
47798 | 620 |
base = emitLoadConstant(uncompressedKind, JavaConstant.forLong(encoding.getBase())); |
43972 | 621 |
} |
622 |
} |
|
48861 | 623 |
append(new AMD64Move.UncompressPointerOp(result, asAllocatable(pointer), base, encoding, nonNull, lirKindTool)); |
43972 | 624 |
return result; |
625 |
} |
|
626 |
} |
|
627 |
||
628 |
@Override |
|
629 |
public void emitNullCheck(Value address, LIRFrameState state) { |
|
47798 | 630 |
if (address.getValueKind().getPlatformKind() == getLIRKindTool().getNarrowOopKind().getPlatformKind()) { |
43972 | 631 |
CompressEncoding encoding = config.getOopEncoding(); |
632 |
Value uncompressed; |
|
46344 | 633 |
if (encoding.getShift() <= 3) { |
43972 | 634 |
LIRKind wordKind = LIRKind.unknownReference(target().arch.getWordKind()); |
46344 | 635 |
uncompressed = new AMD64AddressValue(wordKind, getProviders().getRegisters().getHeapBaseRegister().asValue(wordKind), asAllocatable(address), Scale.fromInt(1 << encoding.getShift()), |
636 |
0); |
|
43972 | 637 |
} else { |
638 |
uncompressed = emitUncompress(address, encoding, false); |
|
639 |
} |
|
640 |
append(new AMD64Move.NullCheckOp(asAddressValue(uncompressed), state)); |
|
47798 | 641 |
return; |
43972 | 642 |
} |
47798 | 643 |
super.emitNullCheck(address, state); |
43972 | 644 |
} |
645 |
||
646 |
@Override |
|
647 |
public LIRInstruction createBenchmarkCounter(String name, String group, Value increment) { |
|
648 |
if (BenchmarkCounters.enabled) { |
|
649 |
return new AMD64HotSpotCounterOp(name, group, increment, getProviders().getRegisters(), config, getOrInitRescueSlot()); |
|
650 |
} |
|
651 |
throw GraalError.shouldNotReachHere("BenchmarkCounters are not enabled!"); |
|
652 |
} |
|
653 |
||
654 |
@Override |
|
655 |
public LIRInstruction createMultiBenchmarkCounter(String[] names, String[] groups, Value[] increments) { |
|
656 |
if (BenchmarkCounters.enabled) { |
|
657 |
return new AMD64HotSpotCounterOp(names, groups, increments, getProviders().getRegisters(), config, getOrInitRescueSlot()); |
|
658 |
} |
|
659 |
throw GraalError.shouldNotReachHere("BenchmarkCounters are not enabled!"); |
|
660 |
} |
|
661 |
||
662 |
@Override |
|
663 |
public void emitPrefetchAllocate(Value address) { |
|
664 |
append(new AMD64PrefetchOp(asAddressValue(address), config.allocatePrefetchInstr)); |
|
665 |
} |
|
666 |
||
667 |
@Override |
|
668 |
protected StrategySwitchOp createStrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Variable key, AllocatableValue temp) { |
|
669 |
return new AMD64HotSpotStrategySwitchOp(strategy, keyTargets, defaultTarget, key, temp); |
|
670 |
} |
|
671 |
} |