Skip to content

Commit f4f7233

Browse files
author
Stefan Anzinger
committed
[GR-9604] AArch64: Integrate AOT Implementation.
PullRequest: graal/1421
2 parents 3d06e2e + 4eb3879 commit f4f7233

File tree

16 files changed

+891
-67
lines changed

16 files changed

+891
-67
lines changed

compiler/src/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64Assembler.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2018, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -26,6 +27,7 @@
2627
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADD;
2728
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADDS;
2829
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADR;
30+
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ADRP;
2931
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.AND;
3032
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ANDS;
3133
import static org.graalvm.compiler.asm.aarch64.AArch64Assembler.Instruction.ASRV;
@@ -1346,16 +1348,14 @@ private void compareAndSwapInstruction(Instruction instr, Register rs, Register
13461348

13471349
/**
13481350
* Address of page: sign extends 21-bit offset, shifts if left by 12 and adds it to the value of
1349-
* the PC with its bottom 12-bits cleared, writing the result to dst.
1351+
* the PC with its bottom 12-bits cleared, writing the result to dst. No offset is emitted; the
1352+
* instruction will be patched later.
13501353
*
13511354
* @param dst general purpose register. May not be null, zero-register or stackpointer.
1352-
* @param imm Signed 33-bit offset with lower 12bits clear.
13531355
*/
1354-
// protected void adrp(Register dst, long imm) {
1355-
// assert (imm & NumUtil.getNbitNumberInt(12)) == 0 : "Lower 12-bit of immediate must be zero.";
1356-
// assert NumUtil.isSignedNbit(33, imm);
1357-
// addressCalculationInstruction(dst, (int) (imm >>> 12), Instruction.ADRP);
1358-
// }
1356+
public void adrp(Register dst) {
1357+
emitInt(ADRP.encoding | PcRelImmOp | rd(dst));
1358+
}
13591359

13601360
/**
13611361
* Adds a 21-bit signed offset to the program counter and writes the result to dst.
@@ -1367,6 +1367,13 @@ public void adr(Register dst, int imm21) {
13671367
emitInt(ADR.encoding | PcRelImmOp | rd(dst) | getPcRelativeImmEncoding(imm21));
13681368
}
13691369

1370+
/**
1371+
* Adds a 21-bit signed offset to the program counter and writes the result to dst.
1372+
*
1373+
* @param dst general purpose register. May not be null, zero-register or stackpointer.
1374+
* @param imm21 Signed 21-bit offset.
1375+
* @param pos the position in the code that the instruction is emitted.
1376+
*/
13701377
public void adr(Register dst, int imm21, int pos) {
13711378
emitInt(ADR.encoding | PcRelImmOp | rd(dst) | getPcRelativeImmEncoding(imm21), pos);
13721379
}

compiler/src/org.graalvm.compiler.asm.aarch64/src/org/graalvm/compiler/asm/aarch64/AArch64MacroAssembler.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import static jdk.vm.ci.aarch64.AArch64.sp;
3838
import static jdk.vm.ci.aarch64.AArch64.zr;
3939

40-
import org.graalvm.compiler.asm.AbstractAddress;
4140
import org.graalvm.compiler.asm.Label;
4241
import org.graalvm.compiler.core.common.NumUtil;
4342
import org.graalvm.compiler.debug.GraalError;
@@ -306,9 +305,10 @@ public void loadAddress(Register dst, AArch64Address address, int transferSize)
306305
case EXTENDED_REGISTER_OFFSET:
307306
add(64, dst, address.getBase(), address.getOffset(), address.getExtendType(), address.isScaled() ? shiftAmt : 0);
308307
break;
309-
case PC_LITERAL:
310-
super.adr(dst, address.getImmediateRaw());
308+
case PC_LITERAL: {
309+
addressOf(dst);
311310
break;
311+
}
312312
case BASE_REGISTER_ONLY:
313313
movx(dst, address.getBase());
314314
break;
@@ -1560,10 +1560,16 @@ public AArch64Address makeAddress(Register base, int displacement) {
15601560
}
15611561

15621562
@Override
1563-
public AbstractAddress getPlaceholder(int instructionStartPosition) {
1563+
public AArch64Address getPlaceholder(int instructionStartPosition) {
15641564
return AArch64Address.PLACEHOLDER;
15651565
}
15661566

1567+
public void addressOf(Register dst) {
1568+
// This will be fixed up later.
1569+
super.adrp(dst);
1570+
super.add(64, dst, dst, 0);
1571+
}
1572+
15671573
/**
15681574
* Loads an address into Register d.
15691575
*

compiler/src/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotBackend.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import static jdk.vm.ci.aarch64.AArch64.zr;
3030
import static jdk.vm.ci.code.ValueUtil.asRegister;
3131
import static jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig.fp;
32+
import static org.graalvm.compiler.core.common.GraalOptions.GeneratePIC;
3233
import static org.graalvm.compiler.core.common.GraalOptions.ZapStackOnMethodEntry;
3334

3435
import org.graalvm.collections.EconomicSet;
@@ -41,13 +42,15 @@
4142
import org.graalvm.compiler.code.CompilationResult;
4243
import org.graalvm.compiler.core.aarch64.AArch64NodeMatchRules;
4344
import org.graalvm.compiler.core.common.CompilationIdentifier;
45+
import org.graalvm.compiler.core.common.LIRKind;
4446
import org.graalvm.compiler.core.common.alloc.RegisterAllocationConfig;
4547
import org.graalvm.compiler.core.common.spi.ForeignCallLinkage;
4648
import org.graalvm.compiler.hotspot.GraalHotSpotVMConfig;
4749
import org.graalvm.compiler.hotspot.HotSpotDataBuilder;
4850
import org.graalvm.compiler.hotspot.HotSpotGraalRuntimeProvider;
4951
import org.graalvm.compiler.hotspot.HotSpotHostBackend;
5052
import org.graalvm.compiler.hotspot.HotSpotLIRGenerationResult;
53+
import org.graalvm.compiler.hotspot.meta.HotSpotConstantLoadAction;
5154
import org.graalvm.compiler.hotspot.meta.HotSpotForeignCallsProvider;
5255
import org.graalvm.compiler.hotspot.meta.HotSpotProviders;
5356
import org.graalvm.compiler.hotspot.stubs.Stub;
@@ -66,12 +69,15 @@
6669
import org.graalvm.compiler.nodes.StructuredGraph;
6770
import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool;
6871

72+
import jdk.vm.ci.aarch64.AArch64Kind;
6973
import jdk.vm.ci.code.CallingConvention;
7074
import jdk.vm.ci.code.Register;
7175
import jdk.vm.ci.code.RegisterConfig;
7276
import jdk.vm.ci.code.StackSlot;
7377
import jdk.vm.ci.hotspot.HotSpotCallingConventionType;
78+
import jdk.vm.ci.hotspot.HotSpotSentinelConstant;
7479
import jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig;
80+
import jdk.vm.ci.meta.JavaKind;
7581
import jdk.vm.ci.meta.JavaType;
7682
import jdk.vm.ci.meta.ResolvedJavaMethod;
7783

@@ -269,7 +275,7 @@ private void emitCodePrefix(CompilationResultBuilder crb, ResolvedJavaMethod ins
269275
Register klass = r10;
270276
if (config.useCompressedClassPointers) {
271277
masm.ldr(32, klass, klassAddress);
272-
AArch64HotSpotMove.decodeKlassPointer(masm, klass, klass, providers.getRegisters().getHeapBaseRegister(), config.getKlassEncoding());
278+
AArch64HotSpotMove.decodeKlassPointer(crb, masm, klass, klass, config.getKlassEncoding(), config);
273279
} else {
274280
masm.ldr(64, klass, klassAddress);
275281
}
@@ -285,6 +291,23 @@ private void emitCodePrefix(CompilationResultBuilder crb, ResolvedJavaMethod ins
285291
crb.recordMark(config.MARKID_OSR_ENTRY);
286292
masm.bind(verifiedStub);
287293
crb.recordMark(config.MARKID_VERIFIED_ENTRY);
294+
295+
if (GeneratePIC.getValue(crb.getOptions())) {
296+
// Check for method state
297+
HotSpotFrameContext frameContext = (HotSpotFrameContext) crb.frameContext;
298+
if (!frameContext.isStub) {
299+
crb.recordInlineDataInCodeWithNote(new HotSpotSentinelConstant(LIRKind.value(AArch64Kind.QWORD), JavaKind.Long), HotSpotConstantLoadAction.MAKE_NOT_ENTRANT);
300+
try (ScratchRegister sc = masm.getScratchRegister()) {
301+
Register scratch = sc.getRegister();
302+
masm.addressOf(scratch);
303+
masm.ldr(64, scratch, AArch64Address.createBaseRegisterOnlyAddress(scratch));
304+
Label noCall = new Label();
305+
masm.cbz(64, scratch, noCall);
306+
AArch64Call.directJmp(crb, masm, getForeignCalls().lookupForeignCall(WRONG_METHOD_HANDLER));
307+
masm.bind(noCall);
308+
}
309+
}
310+
}
288311
}
289312

290313
private static void emitCodeBody(CompilationResultBuilder crb, LIR lir, AArch64MacroAssembler masm) {
@@ -299,8 +322,10 @@ private static void emitCodeBody(CompilationResultBuilder crb, LIR lir, AArch64M
299322
* @see "http://mail.openjdk.java.net/pipermail/aarch64-port-dev/2013-September/000273.html"
300323
*/
301324
public static void emitInvalidatePlaceholder(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
302-
crb.blockComment("[nop for method invalidation]");
303-
masm.nop();
325+
if (!GeneratePIC.getValue(crb.getOptions())) {
326+
crb.blockComment("[nop for method invalidation]");
327+
masm.nop();
328+
}
304329
}
305330

306331
private void emitCodeSuffix(CompilationResultBuilder crb, AArch64MacroAssembler masm, FrameMap frameMap) {

compiler/src/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotBackendFactory.java

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2018, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -25,6 +26,10 @@
2526
import static jdk.vm.ci.aarch64.AArch64.sp;
2627
import static jdk.vm.ci.common.InitTimer.timer;
2728

29+
import jdk.vm.ci.code.Architecture;
30+
import jdk.vm.ci.code.Register;
31+
import jdk.vm.ci.code.RegisterConfig;
32+
import jdk.vm.ci.code.TargetDescription;
2833
import org.graalvm.compiler.api.replacements.SnippetReflectionProvider;
2934
import org.graalvm.compiler.bytecode.BytecodeProvider;
3035
import org.graalvm.compiler.core.aarch64.AArch64AddressLoweringByUse;
@@ -64,10 +69,6 @@
6469
import org.graalvm.compiler.word.WordTypes;
6570

6671
import jdk.vm.ci.aarch64.AArch64;
67-
import jdk.vm.ci.code.Architecture;
68-
import jdk.vm.ci.code.RegisterArray;
69-
import jdk.vm.ci.code.RegisterConfig;
70-
import jdk.vm.ci.code.TargetDescription;
7172
import jdk.vm.ci.common.InitTimer;
7273
import jdk.vm.ci.hotspot.HotSpotCodeCacheProvider;
7374
import jdk.vm.ci.hotspot.HotSpotConstantReflectionProvider;
@@ -77,6 +78,9 @@
7778
import jdk.vm.ci.meta.Value;
7879
import jdk.vm.ci.runtime.JVMCIBackend;
7980

81+
import java.util.ArrayList;
82+
import java.util.List;
83+
8084
@ServiceProvider(HotSpotBackendFactory.class)
8185
public class AArch64HotSpotBackendFactory implements HotSpotBackendFactory {
8286

@@ -200,12 +204,20 @@ protected HotSpotLoweringProvider createLowerer(HotSpotGraalRuntimeProvider runt
200204
}
201205

202206
protected static Value[] createNativeABICallerSaveRegisters(@SuppressWarnings("unused") GraalHotSpotVMConfig config, RegisterConfig regConfig) {
203-
AArch64HotSpotRegisterConfig conf = (AArch64HotSpotRegisterConfig) regConfig;
204-
RegisterArray callerSavedRegisters = conf.getCallerSaveRegisters();
205-
int size = callerSavedRegisters.size();
206-
Value[] nativeABICallerSaveRegisters = new Value[size];
207-
for (int i = 0; i < size; i++) {
208-
nativeABICallerSaveRegisters[i] = callerSavedRegisters.get(i).asValue();
207+
List<Register> callerSave = new ArrayList<>(regConfig.getAllocatableRegisters().asList());
208+
callerSave.remove(AArch64.r19);
209+
callerSave.remove(AArch64.r20);
210+
callerSave.remove(AArch64.r21);
211+
callerSave.remove(AArch64.r22);
212+
callerSave.remove(AArch64.r23);
213+
callerSave.remove(AArch64.r24);
214+
callerSave.remove(AArch64.r25);
215+
callerSave.remove(AArch64.r26);
216+
callerSave.remove(AArch64.r27);
217+
callerSave.remove(AArch64.r28);
218+
Value[] nativeABICallerSaveRegisters = new Value[callerSave.size()];
219+
for (int i = 0; i < callerSave.size(); i++) {
220+
nativeABICallerSaveRegisters[i] = callerSave.get(i).asValue();
209221
}
210222
return nativeABICallerSaveRegisters;
211223
}

compiler/src/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotCRuntimeCallEpilogueOp.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import static jdk.vm.ci.aarch64.AArch64.zr;
2626

27+
import org.graalvm.compiler.asm.Label;
2728
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
2829
import org.graalvm.compiler.lir.LIRInstructionClass;
2930
import org.graalvm.compiler.lir.Opcode;
@@ -37,20 +38,22 @@ public class AArch64HotSpotCRuntimeCallEpilogueOp extends AArch64LIRInstruction
3738
public static final LIRInstructionClass<AArch64HotSpotCRuntimeCallEpilogueOp> TYPE = LIRInstructionClass.create(AArch64HotSpotCRuntimeCallEpilogueOp.class);
3839

3940
private final int threadLastJavaSpOffset;
40-
private final int threadLastJavaFpOffset;
41+
private final int threadLastJavaPcOffset;
4142
private final Register thread;
43+
@SuppressWarnings("unused") private final Label label;
4244

43-
public AArch64HotSpotCRuntimeCallEpilogueOp(int threadLastJavaSpOffset, int threadLastJavaFpOffset, Register thread) {
45+
public AArch64HotSpotCRuntimeCallEpilogueOp(int threadLastJavaSpOffset, int threadLastJavaPcOffset, Register thread, Label label) {
4446
super(TYPE);
4547
this.threadLastJavaSpOffset = threadLastJavaSpOffset;
46-
this.threadLastJavaFpOffset = threadLastJavaFpOffset;
48+
this.threadLastJavaPcOffset = threadLastJavaPcOffset;
4749
this.thread = thread;
50+
this.label = label;
4851
}
4952

5053
@Override
5154
public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
5255
// Reset last Java frame:
5356
masm.str(64, zr, masm.makeAddress(thread, threadLastJavaSpOffset, 8));
54-
masm.str(64, zr, masm.makeAddress(thread, threadLastJavaFpOffset, 8));
57+
masm.str(64, zr, masm.makeAddress(thread, threadLastJavaPcOffset, 8));
5558
}
5659
}

compiler/src/org.graalvm.compiler.hotspot.aarch64/src/org/graalvm/compiler/hotspot/aarch64/AArch64HotSpotCRuntimeCallPrologueOp.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3+
* Copyright (c) 2018, Red Hat Inc. All rights reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
56
* This code is free software; you can redistribute it and/or modify it
@@ -25,7 +26,6 @@
2526
import static org.graalvm.compiler.lir.LIRInstruction.OperandFlag.REG;
2627
import static jdk.vm.ci.aarch64.AArch64.sp;
2728
import static jdk.vm.ci.code.ValueUtil.asRegister;
28-
import static jdk.vm.ci.hotspot.aarch64.AArch64HotSpotRegisterConfig.fp;
2929

3030
import org.graalvm.compiler.asm.Label;
3131
import org.graalvm.compiler.asm.aarch64.AArch64MacroAssembler;
@@ -43,16 +43,14 @@ public class AArch64HotSpotCRuntimeCallPrologueOp extends AArch64LIRInstruction
4343

4444
private final int threadLastJavaSpOffset;
4545
private final int threadLastJavaPcOffset;
46-
private final int threadLastJavaFpOffset;
4746
private final Register thread;
4847
@Temp({REG}) protected AllocatableValue scratch;
4948
private final Label label;
5049

51-
public AArch64HotSpotCRuntimeCallPrologueOp(int threadLastJavaSpOffset, int threadLastJavaPcOffset, int threadLastJavaFpOffset, Register thread, AllocatableValue scratch, Label label) {
50+
public AArch64HotSpotCRuntimeCallPrologueOp(int threadLastJavaSpOffset, int threadLastJavaPcOffset, Register thread, AllocatableValue scratch, Label label) {
5251
super(TYPE);
5352
this.threadLastJavaSpOffset = threadLastJavaSpOffset;
5453
this.threadLastJavaPcOffset = threadLastJavaPcOffset;
55-
this.threadLastJavaFpOffset = threadLastJavaFpOffset;
5654
this.thread = thread;
5755
this.scratch = scratch;
5856
this.label = label;
@@ -69,7 +67,5 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) {
6967
// Get the current PC. Use a label to patch the return address.
7068
masm.adr(scratchRegister, label);
7169
masm.str(64, scratchRegister, masm.makeAddress(thread, threadLastJavaPcOffset, 8));
72-
73-
masm.str(64, fp, masm.makeAddress(thread, threadLastJavaFpOffset, 8));
7470
}
7571
}

0 commit comments

Comments
 (0)