author | chegar |
Thu, 17 Oct 2019 20:53:35 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58678 | 9cf78a70fa4f |
parent 54328 | 37648a9c4a6a |
child 58679 | 9c3209ff7550 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
58678 | 2 |
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. |
50330 | 3 |
* Copyright (c) 2018, Red Hat Inc. All rights reserved. |
43972 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 |
* or visit www.oracle.com if you need additional information or have any |
|
22 |
* questions. |
|
23 |
*/ |
|
24 |
||
50858 | 25 |
|
26 |
||
43972 | 27 |
package org.graalvm.compiler.hotspot.aarch64; |
28 |
||
50330 | 29 |
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC; |
30 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.INITIALIZE_KLASS_BY_SYMBOL; |
|
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
31 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_DYNAMIC_INVOKE; |
50330 | 32 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_KLASS_BY_SYMBOL; |
33 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS; |
|
34 |
import static org.graalvm.compiler.hotspot.HotSpotBackend.RESOLVE_STRING_BY_SYMBOL; |
|
35 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.INITIALIZE; |
|
36 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.LOAD_COUNTERS; |
|
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
37 |
import static org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction.RESOLVE; |
43972 | 38 |
import static org.graalvm.compiler.lir.LIRValueUtil.asConstant; |
39 |
import static org.graalvm.compiler.lir.LIRValueUtil.isConstantValue; |
|
40 |
||
58678 | 41 |
import java.util.EnumSet; |
43972 | 42 |
import java.util.function.Function; |
43 |
||
44 |
import org.graalvm.compiler.asm.Label; |
|
45 |
import org.graalvm.compiler.asm.aarch64.AArch64Address.AddressingMode; |
|
48398 | 46 |
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.ConditionFlag; |
46640 | 47 |
import org.graalvm.compiler.asm.aarch64.AArch64Assembler.PrefetchMode; |
43972 | 48 |
import org.graalvm.compiler.core.aarch64.AArch64ArithmeticLIRGenerator; |
49 |
import org.graalvm.compiler.core.aarch64.AArch64LIRGenerator; |
|
46459 | 50 |
import org.graalvm.compiler.core.aarch64.AArch64LIRKindTool; |
46344 | 51 |
import org.graalvm.compiler.core.common.CompressEncoding; |
58678 | 52 |
import org.graalvm.compiler.core.common.GraalOptions; |
43972 | 53 |
import org.graalvm.compiler.core.common.LIRKind; |
54 |
import org.graalvm.compiler.core.common.calc.Condition; |
|
50330 | 55 |
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; |
43972 | 56 |
import org.graalvm.compiler.core.common.spi.ForeignCallLinkage; |
57 |
import org.graalvm.compiler.core.common.spi.LIRKindTool; |
|
58 |
import org.graalvm.compiler.debug.GraalError; |
|
46344 | 59 |
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig; |
43972 | 60 |
import org.graalvm.compiler.hotspot.HotSpotBackend; |
61 |
import org.graalvm.compiler.hotspot.HotSpotDebugInfoBuilder; |
|
62 |
import org.graalvm.compiler.hotspot.HotSpotForeignCallLinkage; |
|
63 |
import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult; |
|
64 |
import org.graalvm.compiler.hotspot.HotSpotLIRGenerator; |
|
65 |
import org.graalvm.compiler.hotspot.HotSpotLockStack; |
|
50330 | 66 |
import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction; |
43972 | 67 |
import org.graalvm.compiler.hotspot.meta.HotSpotProviders; |
68 |
import org.graalvm.compiler.hotspot.meta.HotSpotRegistersProvider; |
|
69 |
import org.graalvm.compiler.hotspot.stubs.Stub; |
|
70 |
import org.graalvm.compiler.lir.LIRFrameState; |
|
71 |
import org.graalvm.compiler.lir.LIRInstruction; |
|
72 |
import org.graalvm.compiler.lir.LabelRef; |
|
58678 | 73 |
import org.graalvm.compiler.lir.StandardOp.ZapRegistersOp; |
43972 | 74 |
import org.graalvm.compiler.lir.SwitchStrategy; |
75 |
import org.graalvm.compiler.lir.Variable; |
|
76 |
import org.graalvm.compiler.lir.VirtualStackSlot; |
|
77 |
import org.graalvm.compiler.lir.aarch64.AArch64AddressValue; |
|
46344 | 78 |
import org.graalvm.compiler.lir.aarch64.AArch64CCall; |
43972 | 79 |
import org.graalvm.compiler.lir.aarch64.AArch64Call; |
80 |
import org.graalvm.compiler.lir.aarch64.AArch64ControlFlow.StrategySwitchOp; |
|
81 |
import org.graalvm.compiler.lir.aarch64.AArch64FrameMapBuilder; |
|
46344 | 82 |
import org.graalvm.compiler.lir.aarch64.AArch64Move; |
43972 | 83 |
import org.graalvm.compiler.lir.aarch64.AArch64Move.StoreOp; |
84 |
import org.graalvm.compiler.lir.aarch64.AArch64PrefetchOp; |
|
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
85 |
import org.graalvm.compiler.lir.aarch64.AArch64RestoreRegistersOp; |
50330 | 86 |
import org.graalvm.compiler.lir.aarch64.AArch64SaveRegistersOp; |
43972 | 87 |
import org.graalvm.compiler.lir.gen.LIRGenerationResult; |
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
88 |
import org.graalvm.compiler.options.OptionValues; |
43972 | 89 |
|
90 |
import jdk.vm.ci.aarch64.AArch64; |
|
91 |
import jdk.vm.ci.aarch64.AArch64Kind; |
|
92 |
import jdk.vm.ci.code.CallingConvention; |
|
93 |
import jdk.vm.ci.code.Register; |
|
94 |
import jdk.vm.ci.code.RegisterValue; |
|
95 |
import jdk.vm.ci.code.StackSlot; |
|
96 |
import jdk.vm.ci.hotspot.HotSpotCompressedNullConstant; |
|
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
97 |
import jdk.vm.ci.hotspot.HotSpotMetaspaceConstant; |
43972 | 98 |
import jdk.vm.ci.hotspot.HotSpotObjectConstant; |
99 |
import jdk.vm.ci.meta.AllocatableValue; |
|
100 |
import jdk.vm.ci.meta.Constant; |
|
101 |
import jdk.vm.ci.meta.DeoptimizationAction; |
|
102 |
import jdk.vm.ci.meta.DeoptimizationReason; |
|
103 |
import jdk.vm.ci.meta.JavaConstant; |
|
104 |
import jdk.vm.ci.meta.JavaKind; |
|
105 |
import jdk.vm.ci.meta.PlatformKind; |
|
50858 | 106 |
import jdk.vm.ci.meta.SpeculationLog; |
43972 | 107 |
import jdk.vm.ci.meta.Value; |
108 |
||
109 |
/** |
|
110 |
* LIR generator specialized for AArch64 HotSpot. |
|
111 |
*/ |
|
112 |
public class AArch64HotSpotLIRGenerator extends AArch64LIRGenerator implements HotSpotLIRGenerator { |
|
113 |
||
114 |
final GraalHotSpotVMConfig config; |
|
115 |
private HotSpotDebugInfoBuilder debugInfoBuilder; |
|
116 |
||
117 |
protected AArch64HotSpotLIRGenerator(HotSpotProviders providers, GraalHotSpotVMConfig config, LIRGenerationResult lirGenRes) { |
|
54328 | 118 |
this(new AArch64LIRKindTool(), new AArch64ArithmeticLIRGenerator(null), new AArch64HotSpotMoveFactory(), providers, config, lirGenRes); |
43972 | 119 |
} |
120 |
||
121 |
protected AArch64HotSpotLIRGenerator(LIRKindTool lirKindTool, AArch64ArithmeticLIRGenerator arithmeticLIRGen, MoveFactory moveFactory, HotSpotProviders providers, GraalHotSpotVMConfig config, |
|
122 |
LIRGenerationResult lirGenRes) { |
|
123 |
super(lirKindTool, arithmeticLIRGen, moveFactory, providers, lirGenRes); |
|
124 |
this.config = config; |
|
125 |
} |
|
126 |
||
127 |
@Override |
|
128 |
public HotSpotProviders getProviders() { |
|
129 |
return (HotSpotProviders) super.getProviders(); |
|
130 |
} |
|
131 |
||
132 |
@Override |
|
133 |
public boolean needOnlyOopMaps() { |
|
134 |
// Stubs only need oop maps |
|
135 |
return getResult().getStub() != null; |
|
136 |
} |
|
137 |
||
50330 | 138 |
private LIRFrameState currentRuntimeCallInfo; |
43972 | 139 |
|
140 |
@Override |
|
141 |
protected void emitForeignCallOp(ForeignCallLinkage linkage, Value result, Value[] arguments, Value[] temps, LIRFrameState info) { |
|
142 |
currentRuntimeCallInfo = info; |
|
143 |
if (AArch64Call.isNearCall(linkage)) { |
|
144 |
append(new AArch64Call.DirectNearForeignCallOp(linkage, result, arguments, temps, info, label)); |
|
145 |
} else { |
|
146 |
append(new AArch64Call.DirectFarForeignCallOp(linkage, result, arguments, temps, info, label)); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
@Override |
|
151 |
public void emitTailcall(Value[] args, Value address) { |
|
152 |
throw GraalError.unimplemented(); |
|
153 |
} |
|
154 |
||
155 |
@Override |
|
46344 | 156 |
public void emitCCall(long address, CallingConvention nativeCallingConvention, Value[] args) { |
157 |
Value[] argLocations = new Value[args.length]; |
|
158 |
getResult().getFrameMapBuilder().callsMethod(nativeCallingConvention); |
|
159 |
for (int i = 0; i < args.length; i++) { |
|
160 |
Value arg = args[i]; |
|
161 |
AllocatableValue loc = nativeCallingConvention.getArgument(i); |
|
162 |
emitMove(loc, arg); |
|
163 |
argLocations[i] = loc; |
|
164 |
} |
|
165 |
Value ptr = emitLoadConstant(LIRKind.value(AArch64Kind.QWORD), JavaConstant.forLong(address)); |
|
166 |
append(new AArch64CCall(nativeCallingConvention.getReturn(), ptr, argLocations)); |
|
167 |
} |
|
168 |
||
50330 | 169 |
/** |
170 |
* @param savedRegisters the registers saved by this operation which may be subject to pruning |
|
171 |
* @param savedRegisterLocations the slots to which the registers are saved |
|
172 |
*/ |
|
58678 | 173 |
protected AArch64SaveRegistersOp emitSaveRegisters(Register[] savedRegisters, AllocatableValue[] savedRegisterLocations) { |
174 |
AArch64SaveRegistersOp save = new AArch64SaveRegistersOp(savedRegisters, savedRegisterLocations); |
|
50330 | 175 |
append(save); |
176 |
return save; |
|
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* Allocate a stack slot for saving a register. |
|
181 |
*/ |
|
182 |
protected VirtualStackSlot allocateSaveRegisterLocation(Register register) { |
|
183 |
PlatformKind kind = target().arch.getLargestStorableKind(register.getRegisterCategory()); |
|
184 |
if (kind.getVectorLength() > 1) { |
|
185 |
// we don't use vector registers, so there is no need to save them |
|
58678 | 186 |
kind = AArch64Kind.DOUBLE; |
50330 | 187 |
} |
188 |
return getResult().getFrameMapBuilder().allocateSpillSlot(LIRKind.value(kind)); |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* Adds a node to the graph that saves all allocatable registers to the stack. |
|
193 |
* |
|
194 |
* @return the register save node |
|
195 |
*/ |
|
58678 | 196 |
private AArch64SaveRegistersOp emitSaveAllRegisters(Register[] savedRegisters) { |
50330 | 197 |
AllocatableValue[] savedRegisterLocations = new AllocatableValue[savedRegisters.length]; |
198 |
for (int i = 0; i < savedRegisters.length; i++) { |
|
199 |
savedRegisterLocations[i] = allocateSaveRegisterLocation(savedRegisters[i]); |
|
200 |
} |
|
58678 | 201 |
return emitSaveRegisters(savedRegisters, savedRegisterLocations); |
50330 | 202 |
} |
203 |
||
204 |
protected void emitRestoreRegisters(AArch64SaveRegistersOp save) { |
|
205 |
append(new AArch64RestoreRegistersOp(save.getSlots().clone(), save)); |
|
43972 | 206 |
} |
207 |
||
208 |
@Override |
|
209 |
public VirtualStackSlot getLockSlot(int lockDepth) { |
|
210 |
return getLockStack().makeLockSlot(lockDepth); |
|
211 |
} |
|
212 |
||
213 |
private HotSpotLockStack getLockStack() { |
|
214 |
assert debugInfoBuilder != null && debugInfoBuilder.lockStack() != null; |
|
215 |
return debugInfoBuilder.lockStack(); |
|
216 |
} |
|
217 |
||
218 |
@Override |
|
219 |
public void emitCompareBranch(PlatformKind cmpKind, Value x, Value y, Condition cond, boolean unorderedIsTrue, LabelRef trueDestination, LabelRef falseDestination, |
|
220 |
double trueDestinationProbability) { |
|
221 |
Value localX = x; |
|
222 |
Value localY = y; |
|
223 |
if (localX instanceof HotSpotObjectConstant) { |
|
224 |
localX = load(localX); |
|
225 |
} |
|
226 |
if (localY instanceof HotSpotObjectConstant) { |
|
227 |
localY = load(localY); |
|
228 |
} |
|
229 |
super.emitCompareBranch(cmpKind, localX, localY, cond, unorderedIsTrue, trueDestination, falseDestination, trueDestinationProbability); |
|
230 |
} |
|
231 |
||
232 |
@Override |
|
233 |
protected boolean emitCompare(PlatformKind cmpKind, Value a, Value b, Condition condition, boolean unorderedIsTrue) { |
|
234 |
Value localA = a; |
|
235 |
Value localB = b; |
|
236 |
if (isConstantValue(a)) { |
|
237 |
Constant c = asConstant(a); |
|
238 |
if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(c)) { |
|
239 |
localA = AArch64.zr.asValue(LIRKind.value(AArch64Kind.DWORD)); |
|
240 |
} else if (c instanceof HotSpotObjectConstant) { |
|
241 |
localA = load(localA); |
|
242 |
} |
|
243 |
} |
|
244 |
if (isConstantValue(b)) { |
|
245 |
Constant c = asConstant(b); |
|
246 |
if (HotSpotCompressedNullConstant.COMPRESSED_NULL.equals(c)) { |
|
247 |
localB = AArch64.zr.asValue(LIRKind.value(AArch64Kind.DWORD)); |
|
248 |
} else if (c instanceof HotSpotObjectConstant) { |
|
249 |
localB = load(localB); |
|
250 |
} |
|
251 |
} |
|
252 |
return super.emitCompare(cmpKind, localA, localB, condition, unorderedIsTrue); |
|
253 |
} |
|
254 |
||
255 |
@Override |
|
256 |
public Value emitCompress(Value pointer, CompressEncoding encoding, boolean nonNull) { |
|
257 |
LIRKind inputKind = pointer.getValueKind(LIRKind.class); |
|
50330 | 258 |
LIRKindTool lirKindTool = getLIRKindTool(); |
43972 | 259 |
assert inputKind.getPlatformKind() == AArch64Kind.QWORD; |
260 |
if (inputKind.isReference(0)) { |
|
261 |
// oop |
|
48398 | 262 |
Variable result = newVariable(LIRKind.compressedReference(AArch64Kind.DWORD)); |
43972 | 263 |
append(new AArch64HotSpotMove.CompressPointer(result, asAllocatable(pointer), getProviders().getRegisters().getHeapBaseRegister().asValue(), encoding, nonNull)); |
264 |
return result; |
|
265 |
} else { |
|
266 |
// metaspace pointer |
|
267 |
Variable result = newVariable(LIRKind.value(AArch64Kind.DWORD)); |
|
268 |
AllocatableValue base = Value.ILLEGAL; |
|
50330 | 269 |
OptionValues options = getResult().getLIR().getOptions(); |
270 |
if (encoding.hasBase() || GeneratePIC.getValue(options)) { |
|
271 |
if (GeneratePIC.getValue(options)) { |
|
272 |
Variable baseAddress = newVariable(lirKindTool.getWordKind()); |
|
273 |
AArch64HotSpotMove.BaseMove move = new AArch64HotSpotMove.BaseMove(baseAddress, config); |
|
274 |
append(move); |
|
275 |
base = baseAddress; |
|
276 |
} else { |
|
277 |
base = emitLoadConstant(LIRKind.value(AArch64Kind.QWORD), JavaConstant.forLong(encoding.getBase())); |
|
278 |
} |
|
43972 | 279 |
} |
280 |
append(new AArch64HotSpotMove.CompressPointer(result, asAllocatable(pointer), base, encoding, nonNull)); |
|
281 |
return result; |
|
282 |
} |
|
283 |
} |
|
284 |
||
285 |
@Override |
|
286 |
public Value emitUncompress(Value pointer, CompressEncoding encoding, boolean nonNull) { |
|
287 |
LIRKind inputKind = pointer.getValueKind(LIRKind.class); |
|
288 |
assert inputKind.getPlatformKind() == AArch64Kind.DWORD; |
|
289 |
if (inputKind.isReference(0)) { |
|
290 |
// oop |
|
291 |
Variable result = newVariable(LIRKind.reference(AArch64Kind.QWORD)); |
|
292 |
append(new AArch64HotSpotMove.UncompressPointer(result, asAllocatable(pointer), getProviders().getRegisters().getHeapBaseRegister().asValue(), encoding, nonNull)); |
|
293 |
return result; |
|
294 |
} else { |
|
295 |
// metaspace pointer |
|
296 |
Variable result = newVariable(LIRKind.value(AArch64Kind.QWORD)); |
|
297 |
AllocatableValue base = Value.ILLEGAL; |
|
50330 | 298 |
OptionValues options = getResult().getLIR().getOptions(); |
299 |
if (encoding.hasBase() || GeneratePIC.getValue(options)) { |
|
300 |
if (GeneratePIC.getValue(options)) { |
|
301 |
Variable baseAddress = newVariable(LIRKind.value(AArch64Kind.QWORD)); |
|
302 |
AArch64HotSpotMove.BaseMove move = new AArch64HotSpotMove.BaseMove(baseAddress, config); |
|
303 |
append(move); |
|
304 |
base = baseAddress; |
|
305 |
} else { |
|
306 |
base = emitLoadConstant(LIRKind.value(AArch64Kind.QWORD), JavaConstant.forLong(encoding.getBase())); |
|
307 |
} |
|
43972 | 308 |
} |
309 |
append(new AArch64HotSpotMove.UncompressPointer(result, asAllocatable(pointer), base, encoding, nonNull)); |
|
310 |
return result; |
|
311 |
} |
|
312 |
} |
|
313 |
||
314 |
@Override |
|
46344 | 315 |
public void emitNullCheck(Value address, LIRFrameState state) { |
316 |
if (address.getValueKind().getPlatformKind() == AArch64Kind.DWORD) { |
|
317 |
CompressEncoding encoding = config.getOopEncoding(); |
|
318 |
Value uncompressed = emitUncompress(address, encoding, false); |
|
319 |
append(new AArch64Move.NullCheckOp(asAddressValue(uncompressed), state)); |
|
320 |
} else { |
|
321 |
super.emitNullCheck(address, state); |
|
322 |
} |
|
323 |
} |
|
324 |
||
325 |
@Override |
|
43972 | 326 |
public void emitPrefetchAllocate(Value address) { |
46640 | 327 |
append(new AArch64PrefetchOp(asAddressValue(address), PrefetchMode.PSTL1KEEP)); |
43972 | 328 |
} |
329 |
||
330 |
@Override |
|
331 |
public void beforeRegisterAllocation() { |
|
332 |
super.beforeRegisterAllocation(); |
|
333 |
boolean hasDebugInfo = getResult().getLIR().hasDebugInfo(); |
|
334 |
if (hasDebugInfo) { |
|
335 |
getResult().setDeoptimizationRescueSlot(((AArch64FrameMapBuilder) getResult().getFrameMapBuilder()).allocateDeoptimizationRescueSlot()); |
|
336 |
} |
|
337 |
||
338 |
getResult().setMaxInterpreterFrameSize(debugInfoBuilder.maxInterpreterFrameSize()); |
|
339 |
} |
|
340 |
||
341 |
private Label label; |
|
342 |
||
343 |
@Override |
|
344 |
public Variable emitForeignCall(ForeignCallLinkage linkage, LIRFrameState state, Value... args) { |
|
345 |
HotSpotForeignCallLinkage hotspotLinkage = (HotSpotForeignCallLinkage) linkage; |
|
50330 | 346 |
boolean destroysRegisters = hotspotLinkage.destroysRegisters(); |
347 |
||
348 |
AArch64SaveRegistersOp save = null; |
|
349 |
Stub stub = getStub(); |
|
58678 | 350 |
if (destroysRegisters && stub != null && stub.shouldSaveRegistersAroundCalls()) { |
351 |
Register[] savedRegisters = getRegisterConfig().getAllocatableRegisters().toArray(); |
|
352 |
save = emitSaveAllRegisters(savedRegisters); |
|
50330 | 353 |
} |
354 |
||
43972 | 355 |
Variable result; |
356 |
LIRFrameState debugInfo = null; |
|
357 |
if (hotspotLinkage.needsDebugInfo()) { |
|
358 |
debugInfo = state; |
|
359 |
assert debugInfo != null || getStub() != null; |
|
360 |
} |
|
361 |
||
50330 | 362 |
if (destroysRegisters || hotspotLinkage.needsJavaFrameAnchor()) { |
43972 | 363 |
HotSpotRegistersProvider registers = getProviders().getRegisters(); |
364 |
Register thread = registers.getThreadRegister(); |
|
365 |
Variable scratch = newVariable(LIRKind.value(target().arch.getWordKind())); |
|
366 |
||
367 |
// We need a label for the return address. |
|
368 |
label = new Label(); |
|
369 |
||
50330 | 370 |
append(new AArch64HotSpotCRuntimeCallPrologueOp(config.threadLastJavaSpOffset(), config.threadLastJavaPcOffset(), thread, scratch, label)); |
43972 | 371 |
result = super.emitForeignCall(hotspotLinkage, debugInfo, args); |
50330 | 372 |
append(new AArch64HotSpotCRuntimeCallEpilogueOp(config.threadLastJavaSpOffset(), config.threadLastJavaPcOffset(), thread, label)); |
43972 | 373 |
|
374 |
// Clear it out so it's not being reused later. |
|
375 |
label = null; |
|
376 |
} else { |
|
377 |
result = super.emitForeignCall(hotspotLinkage, debugInfo, args); |
|
378 |
} |
|
379 |
||
58678 | 380 |
if (save != null) { |
381 |
HotSpotLIRGenerationResult generationResult = getResult(); |
|
382 |
LIRFrameState key = currentRuntimeCallInfo; |
|
383 |
if (key == null) { |
|
384 |
key = LIRFrameState.NO_STATE; |
|
50330 | 385 |
} |
58678 | 386 |
assert !generationResult.getCalleeSaveInfo().containsKey(key); |
387 |
generationResult.getCalleeSaveInfo().put(key, save); |
|
388 |
emitRestoreRegisters(save); |
|
50330 | 389 |
} |
390 |
||
43972 | 391 |
return result; |
392 |
} |
|
393 |
||
394 |
@Override |
|
395 |
public void emitDeoptimizeCaller(DeoptimizationAction action, DeoptimizationReason reason) { |
|
396 |
Value actionAndReason = emitJavaConstant(getMetaAccess().encodeDeoptActionAndReason(action, reason, 0)); |
|
50858 | 397 |
Value speculation = emitJavaConstant(getMetaAccess().encodeSpeculation(SpeculationLog.NO_SPECULATION)); |
398 |
moveDeoptValuesToThread(actionAndReason, speculation); |
|
43972 | 399 |
append(new AArch64HotSpotDeoptimizeCallerOp(config)); |
400 |
} |
|
401 |
||
402 |
@Override |
|
403 |
public void emitDeoptimize(Value actionAndReason, Value failedSpeculation, LIRFrameState state) { |
|
404 |
moveDeoptValuesToThread(actionAndReason, failedSpeculation); |
|
405 |
append(new AArch64HotSpotDeoptimizeOp(state)); |
|
406 |
} |
|
407 |
||
408 |
private void moveDeoptValuesToThread(Value actionAndReason, Value speculation) { |
|
409 |
moveValueToThread(actionAndReason, config.pendingDeoptimizationOffset); |
|
410 |
moveValueToThread(speculation, config.pendingFailedSpeculationOffset); |
|
411 |
} |
|
412 |
||
413 |
private void moveValueToThread(Value value, int offset) { |
|
414 |
LIRKind wordKind = LIRKind.value(target().arch.getWordKind()); |
|
415 |
RegisterValue thread = getProviders().getRegisters().getThreadRegister().asValue(wordKind); |
|
416 |
final int transferSize = value.getValueKind().getPlatformKind().getSizeInBytes(); |
|
46536 | 417 |
AArch64AddressValue address = new AArch64AddressValue(value.getValueKind(), thread, Value.ILLEGAL, offset, transferSize, AddressingMode.IMMEDIATE_SCALED); |
43972 | 418 |
append(new StoreOp((AArch64Kind) value.getPlatformKind(), address, loadReg(value), null)); |
419 |
} |
|
420 |
||
421 |
@Override |
|
422 |
public void emitUnwind(Value exception) { |
|
423 |
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(HotSpotBackend.UNWIND_EXCEPTION_TO_CALLER); |
|
424 |
CallingConvention outgoingCc = linkage.getOutgoingCallingConvention(); |
|
425 |
assert outgoingCc.getArgumentCount() == 2; |
|
426 |
RegisterValue exceptionParameter = (RegisterValue) outgoingCc.getArgument(0); |
|
427 |
emitMove(exceptionParameter, exception); |
|
428 |
append(new AArch64HotSpotUnwindOp(config, exceptionParameter)); |
|
429 |
} |
|
430 |
||
431 |
@Override |
|
50330 | 432 |
public Value emitLoadObjectAddress(Constant constant) { |
433 |
HotSpotObjectConstant objectConstant = (HotSpotObjectConstant) constant; |
|
434 |
LIRKind kind = objectConstant.isCompressed() ? getLIRKindTool().getNarrowOopKind() : getLIRKindTool().getObjectKind(); |
|
435 |
Variable result = newVariable(kind); |
|
436 |
append(new AArch64HotSpotLoadAddressOp(result, constant, HotSpotConstantLoadAction.RESOLVE)); |
|
437 |
return result; |
|
438 |
} |
|
439 |
||
440 |
@Override |
|
441 |
public Value emitLoadMetaspaceAddress(Constant constant, HotSpotConstantLoadAction action) { |
|
442 |
HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) constant; |
|
443 |
LIRKind kind = metaspaceConstant.isCompressed() ? getLIRKindTool().getNarrowPointerKind() : getLIRKindTool().getWordKind(); |
|
444 |
Variable result = newVariable(kind); |
|
445 |
append(new AArch64HotSpotLoadAddressOp(result, constant, action)); |
|
446 |
return result; |
|
447 |
} |
|
448 |
||
449 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, Object[] notes, Constant[] constants, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { |
|
450 |
ForeignCallLinkage linkage = getForeignCalls().lookupForeignCall(foreignCall); |
|
451 |
append(new AArch64HotSpotConstantRetrievalOp(constants, constantDescriptions, frameState, linkage, notes)); |
|
452 |
AllocatableValue result = linkage.getOutgoingCallingConvention().getReturn(); |
|
453 |
return emitMove(result); |
|
454 |
} |
|
455 |
||
456 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, AllocatableValue[] constantDescriptions, LIRFrameState frameState) { |
|
457 |
Constant[] constants = new Constant[]{constant}; |
|
458 |
Object[] notes = new Object[]{action}; |
|
459 |
return emitConstantRetrieval(foreignCall, notes, constants, 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); |
|
466 |
} |
|
467 |
||
468 |
@Override |
|
469 |
public Value emitLoadConfigValue(int markId, LIRKind kind) { |
|
470 |
Variable result = newVariable(kind); |
|
471 |
append(new AArch64HotSpotLoadConfigValueOp(markId, result)); |
|
472 |
return result; |
|
473 |
} |
|
474 |
||
475 |
private Value emitConstantRetrieval(ForeignCallDescriptor foreignCall, HotSpotConstantLoadAction action, Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
476 |
AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(constantDescription)}; |
|
477 |
return emitConstantRetrieval(foreignCall, action, constant, constantDescriptions, frameState); |
|
478 |
} |
|
479 |
||
480 |
@Override |
|
481 |
public Value emitObjectConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
482 |
return emitConstantRetrieval(RESOLVE_STRING_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); |
|
483 |
} |
|
484 |
||
485 |
@Override |
|
486 |
public Value emitMetaspaceConstantRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
487 |
return emitConstantRetrieval(RESOLVE_KLASS_BY_SYMBOL, RESOLVE, constant, constantDescription, frameState); |
|
488 |
} |
|
489 |
||
490 |
@Override |
|
43972 | 491 |
public void emitReturn(JavaKind kind, Value input) { |
492 |
AllocatableValue operand = Value.ILLEGAL; |
|
493 |
if (input != null) { |
|
494 |
operand = resultOperandFor(kind, input.getValueKind()); |
|
495 |
emitMove(operand, input); |
|
496 |
} |
|
48172
e26fc5201707
8191437: AOT doesn't work easily after thread local handshakes
dlong
parents:
47216
diff
changeset
|
497 |
Register thread = getProviders().getRegisters().getThreadRegister(); |
51126
a25c48c0a1ab
8181855: [Graal] runtime/ReservedStack/ReservedStackTest.java triggers: assert(thread->deopt_mark() == __null) failed: no stack overflow from deopt blob/uncommon trap
dlong
parents:
50858
diff
changeset
|
498 |
append(new AArch64HotSpotReturnOp(operand, getStub() != null, config, thread, getResult().requiresReservedStackAccessCheck())); |
43972 | 499 |
} |
500 |
||
50330 | 501 |
@Override |
502 |
public Value emitKlassInitializationAndRetrieval(Constant constant, Value constantDescription, LIRFrameState frameState) { |
|
503 |
return emitConstantRetrieval(INITIALIZE_KLASS_BY_SYMBOL, INITIALIZE, constant, constantDescription, frameState); |
|
504 |
} |
|
505 |
||
506 |
@Override |
|
507 |
public Value emitResolveMethodAndLoadCounters(Constant method, Value klassHint, Value methodDescription, LIRFrameState frameState) { |
|
508 |
AllocatableValue[] constantDescriptions = new AllocatableValue[]{asAllocatable(klassHint), asAllocatable(methodDescription)}; |
|
509 |
return emitConstantRetrieval(RESOLVE_METHOD_BY_SYMBOL_AND_LOAD_COUNTERS, LOAD_COUNTERS, method, constantDescriptions, frameState); |
|
510 |
} |
|
511 |
||
43972 | 512 |
/** |
513 |
* Gets the {@link Stub} this generator is generating code for or {@code null} if a stub is not |
|
514 |
* being generated. |
|
515 |
*/ |
|
516 |
public Stub getStub() { |
|
517 |
return getResult().getStub(); |
|
518 |
} |
|
519 |
||
520 |
@Override |
|
521 |
public HotSpotLIRGenerationResult getResult() { |
|
522 |
return ((HotSpotLIRGenerationResult) super.getResult()); |
|
523 |
} |
|
524 |
||
525 |
@Override |
|
526 |
protected StrategySwitchOp createStrategySwitchOp(SwitchStrategy strategy, LabelRef[] keyTargets, LabelRef defaultTarget, Variable key, AllocatableValue scratchValue, |
|
527 |
Function<Condition, ConditionFlag> converter) { |
|
528 |
return new AArch64HotSpotStrategySwitchOp(strategy, keyTargets, defaultTarget, key, scratchValue, converter); |
|
529 |
} |
|
530 |
||
531 |
public void setDebugInfoBuilder(HotSpotDebugInfoBuilder debugInfoBuilder) { |
|
532 |
this.debugInfoBuilder = debugInfoBuilder; |
|
533 |
} |
|
534 |
||
535 |
@Override |
|
58678 | 536 |
public ZapRegistersOp createZapRegisters(Register[] zappedRegisters, JavaConstant[] zapValues) { |
43972 | 537 |
throw GraalError.unimplemented(); |
538 |
} |
|
539 |
||
540 |
@Override |
|
541 |
public LIRInstruction createZapArgumentSpace(StackSlot[] zappedStack, JavaConstant[] zapValues) { |
|
542 |
throw GraalError.unimplemented(); |
|
543 |
} |
|
58678 | 544 |
|
545 |
@Override |
|
546 |
public void emitZeroMemory(Value address, Value length, boolean isAligned) { |
|
547 |
int dczidValue = config.psrInfoDczidValue; |
|
548 |
EnumSet<AArch64.Flag> flags = ((AArch64) target().arch).getFlags(); |
|
549 |
||
550 |
// ARMv8-A architecture reference manual D12.2.35 Data Cache Zero ID register says: |
|
551 |
// * BS, bits [3:0] indicate log2 of the DC ZVA block size in (4-byte) words. |
|
552 |
// * DZP, bit [4] of indicates whether use of DC ZVA instruction is prohibited. |
|
553 |
int zvaLength = 4 << (dczidValue & 0xF); |
|
554 |
boolean isDcZvaProhibited = ((dczidValue & 0x10) != 0); |
|
555 |
||
556 |
// Use DC ZVA if it's not prohibited and AArch64 HotSpot flag UseBlockZeroing is on. |
|
557 |
boolean useDcZva = !isDcZvaProhibited && flags.contains(AArch64.Flag.UseBlockZeroing); |
|
558 |
||
559 |
// Set zva length negative (unknown at compile-time) for AOT compilation, since the value |
|
560 |
// could be different on different AArch64 CPU implementations. |
|
561 |
if (GraalOptions.ImmutableCode.getValue(getResult().getLIR().getOptions())) { |
|
562 |
useDcZva = false; |
|
563 |
} |
|
564 |
||
565 |
emitZeroMemory(address, length, isAligned, useDcZva, zvaLength); |
|
566 |
} |
|
43972 | 567 |
} |