2929import static jdk .vm .ci .hotspot .HotSpotCallingConventionType .JavaCall ;
3030import static jdk .vm .ci .meta .JavaKind .Object ;
3131
32+ import java .util .List ;
33+
3234import jdk .graal .compiler .asm .Label ;
3335import jdk .graal .compiler .asm .aarch64 .AArch64Address ;
3436import jdk .graal .compiler .asm .aarch64 .AArch64MacroAssembler ;
35- import jdk .graal .compiler .asm .aarch64 .AArch64MacroAssembler .ScratchRegister ;
3637import jdk .graal .compiler .core .common .CompressEncoding ;
3738import jdk .graal .compiler .core .common .spi .ForeignCallLinkage ;
39+ import jdk .graal .compiler .debug .GraalError ;
3840import jdk .graal .compiler .hotspot .GraalHotSpotVMConfig ;
3941import jdk .graal .compiler .hotspot .HotSpotGraalRuntime ;
4042import jdk .graal .compiler .hotspot .aarch64 .AArch64HotSpotBackend ;
4951import jdk .graal .compiler .truffle .TruffleCompilerConfiguration ;
5052import jdk .graal .compiler .truffle .hotspot .TruffleCallBoundaryInstrumentationFactory ;
5153import jdk .graal .compiler .truffle .hotspot .TruffleEntryPointDecorator ;
54+ import jdk .vm .ci .aarch64 .AArch64 ;
5255import jdk .vm .ci .code .Register ;
5356
5457@ ServiceProvider (TruffleCallBoundaryInstrumentationFactory .class )
@@ -69,46 +72,51 @@ public void emitEntryPoint(CompilationResultBuilder crb, boolean beforeFrameSetu
6972 AArch64MacroAssembler masm = (AArch64MacroAssembler ) crb .asm ;
7073 AArch64HotSpotBackend .emitInvalidatePlaceholder (crb , masm );
7174
72- try (ScratchRegister scratch = masm .getScratchRegister ()) {
73- Register thisRegister = crb .getCodeCache ().getRegisterConfig ().getCallingConventionRegisters (JavaCall , Object ).get (0 );
74- Register spillRegister = scratch .getRegister ();
75- Label doProlog = new Label ();
76- if (config .useCompressedOops ) {
77- CompressEncoding encoding = config .getOopEncoding ();
78- AArch64Address address = AArch64Address .createImmediateAddress (32 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , thisRegister , installedCodeOffset );
79- masm .ldr (32 , spillRegister , address );
80- Register base = encoding .hasBase () ? registers .getHeapBaseRegister () : null ;
81- AArch64HotSpotMove .UncompressPointer .emitUncompressCode (masm , spillRegister , spillRegister , base , encoding , true );
82- if (config .gc == HotSpotGraalRuntime .HotSpotGC .Shenandoah ) {
83- Register thread = registers .getThreadRegister ();
84- ForeignCallLinkage callTarget = crb .getForeignCalls ().lookupForeignCall (SHENANDOAH_LOAD_BARRIER );
85- AArch64HotSpotShenandoahLoadRefBarrierOp .emitCode (config , crb , masm , null , thread , spillRegister , spillRegister , address , callTarget ,
86- ShenandoahLoadRefBarrierNode .ReferenceStrength .STRONG , false );
87- }
88- } else {
89- AArch64Address address = AArch64Address .createImmediateAddress (64 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , thisRegister , installedCodeOffset );
90- masm .ldr (64 , spillRegister , address );
91- if (config .gc == HotSpotGraalRuntime .HotSpotGC .Z ) {
92- ForeignCallLinkage callTarget = crb .getForeignCalls ().lookupForeignCall (Z_LOAD_BARRIER );
93- AArch64HotSpotZBarrierSetLIRGenerator .emitLoadBarrier (crb , masm , config , spillRegister , callTarget , address , null , false , false );
94- }
95- if (config .gc == HotSpotGraalRuntime .HotSpotGC .Shenandoah ) {
96- Register thread = registers .getThreadRegister ();
97- ForeignCallLinkage callTarget = crb .getForeignCalls ().lookupForeignCall (SHENANDOAH_LOAD_BARRIER );
98- AArch64HotSpotShenandoahLoadRefBarrierOp .emitCode (config , crb , masm , null , thread , spillRegister , spillRegister , address , callTarget ,
99- ShenandoahLoadRefBarrierNode .ReferenceStrength .STRONG , false );
100- }
101- }
102- masm .ldr (64 , spillRegister , AArch64Address .createImmediateAddress (64 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , spillRegister , entryPointOffset ));
103- masm .cbz (64 , spillRegister , doProlog );
104- if (!beforeFrameSetup ) {
105- // Must tear down the frame before jumping
106- ((AArch64HotSpotBackend .HotSpotFrameContext ) crb .frameContext ).leave (crb );
107- }
108- masm .jmp (spillRegister );
109- masm .nop ();
110- masm .bind (doProlog );
75+ List <Register > callRegisters = crb .getCodeCache ().getRegisterConfig ().getCallingConventionRegisters (JavaCall , Object );
76+ Register thisRegister = callRegisters .get (0 );
77+ /**
78+ * This path is complicated by the need for barriers which might have complex
79+ * implementations. In particular they may already be using the scratch registers so
80+ * choose other registers as temporaries. Since this is at the method entry and
81+ * non-argument registers should be freely available so use those instead.
82+ */
83+ Register spillRegister = AArch64 .r11 ;
84+ assert !callRegisters .contains (spillRegister ) : spillRegister + " " + callRegisters ;
85+ Label doProlog = new Label ();
86+ AArch64Address address ;
87+ if (config .useCompressedOops ) {
88+ CompressEncoding encoding = config .getOopEncoding ();
89+ address = AArch64Address .createImmediateAddress (32 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , thisRegister , installedCodeOffset );
90+ masm .ldr (32 , spillRegister , address );
91+ Register base = encoding .hasBase () ? registers .getHeapBaseRegister () : null ;
92+ AArch64HotSpotMove .UncompressPointer .emitUncompressCode (masm , spillRegister , spillRegister , base , encoding , true );
93+ } else {
94+ address = AArch64Address .createImmediateAddress (64 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , thisRegister , installedCodeOffset );
95+ masm .ldr (64 , spillRegister , address );
96+ }
97+ if (config .gc == HotSpotGraalRuntime .HotSpotGC .Z ) {
98+ GraalError .guarantee (!config .useCompressedOops , "only uncompressed oops" );
99+ ForeignCallLinkage callTarget = crb .getForeignCalls ().lookupForeignCall (Z_LOAD_BARRIER );
100+ AArch64HotSpotZBarrierSetLIRGenerator .emitLoadBarrier (crb , masm , config , spillRegister , callTarget , address , null , false , false );
101+ }
102+ if (config .gc == HotSpotGraalRuntime .HotSpotGC .Shenandoah ) {
103+ Register objectRegister = AArch64 .r12 ;
104+ assert !callRegisters .contains (objectRegister ) : objectRegister + " " + callRegisters ;
105+ Register thread = registers .getThreadRegister ();
106+ ForeignCallLinkage callTarget = crb .getForeignCalls ().lookupForeignCall (SHENANDOAH_LOAD_BARRIER );
107+ AArch64HotSpotShenandoahLoadRefBarrierOp .emitCode (config , crb , masm , null , thread , objectRegister , spillRegister , address , callTarget ,
108+ ShenandoahLoadRefBarrierNode .ReferenceStrength .STRONG , false );
109+ masm .mov (64 , spillRegister , objectRegister );
110+ }
111+ masm .ldr (64 , spillRegister , AArch64Address .createImmediateAddress (64 , AArch64Address .AddressingMode .IMMEDIATE_UNSIGNED_SCALED , spillRegister , entryPointOffset ));
112+ masm .cbz (64 , spillRegister , doProlog );
113+ if (!beforeFrameSetup ) {
114+ // Must tear down the frame before jumping
115+ crb .frameContext .leave (crb );
111116 }
117+ masm .jmp (spillRegister );
118+ masm .nop ();
119+ masm .bind (doProlog );
112120 }
113121 };
114122 }
0 commit comments