Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4a22982

Browse files
Rahul Kumarjkotas
authored andcommitted
Add platform (x64 & arm64) specific optimized jit helpers for statics access (#10912)
1 parent 402cea7 commit 4a22982

File tree

8 files changed

+267
-1
lines changed

8 files changed

+267
-1
lines changed

src/vm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,7 @@ if(CLR_CMAKE_TARGET_ARCH_AMD64)
317317
${ARCH_SOURCES_DIR}/JitHelpers_FastWriteBarriers.asm
318318
${ARCH_SOURCES_DIR}/JitHelpers_InlineGetAppDomain.asm
319319
${ARCH_SOURCES_DIR}/JitHelpers_InlineGetThread.asm
320+
${ARCH_SOURCES_DIR}/JitHelpers_SingleAppDomain.asm
320321
${ARCH_SOURCES_DIR}/JitHelpers_Slow.asm
321322
${ARCH_SOURCES_DIR}/PInvokeStubs.asm
322323
${ARCH_SOURCES_DIR}/RedirectedHandledJITCase.asm
@@ -363,6 +364,7 @@ else(WIN32)
363364
${ARCH_SOURCES_DIR}/getstate.S
364365
${ARCH_SOURCES_DIR}/jithelpers_fast.S
365366
${ARCH_SOURCES_DIR}/jithelpers_fastwritebarriers.S
367+
${ARCH_SOURCES_DIR}/jithelpers_singleappdomain.S
366368
${ARCH_SOURCES_DIR}/jithelpers_slow.S
367369
${ARCH_SOURCES_DIR}/pinvokestubs.S
368370
${ARCH_SOURCES_DIR}/theprestubamd64.S
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
; Licensed to the .NET Foundation under one or more agreements.
2+
; The .NET Foundation licenses this file to you under the MIT license.
3+
; See the LICENSE file in the project root for more information.
4+
5+
; ==++==
6+
;
7+
8+
;
9+
; ==--==
10+
; ***********************************************************************
11+
; File: JitHelpers_SingleAppDomain.asm
12+
;
13+
; Notes: JIT Static access helpers when coreclr host specifies single
14+
; appdomain flag
15+
; ***********************************************************************
16+
17+
include AsmMacros.inc
18+
include asmconstants.inc
19+
20+
; Min amount of stack space that a nested function should allocate.
21+
MIN_SIZE equ 28h
22+
23+
extern JIT_GetSharedNonGCStaticBase_Helper:proc
24+
extern JIT_GetSharedGCStaticBase_Helper:proc
25+
26+
LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain, _TEXT
27+
; If class is not initialized, bail to C++ helper
28+
test byte ptr [rcx + OFFSETOF__DomainLocalModule__m_pDataBlob + rdx], 1
29+
jz CallHelper
30+
mov rax, rcx
31+
REPRET
32+
33+
align 16
34+
CallHelper:
35+
; Tail call JIT_GetSharedNonGCStaticBase_Helper
36+
jmp JIT_GetSharedNonGCStaticBase_Helper
37+
LEAF_END JIT_GetSharedNonGCStaticBase_SingleAppDomain, _TEXT
38+
39+
LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain, _TEXT
40+
mov rax, rcx
41+
ret
42+
LEAF_END JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain, _TEXT
43+
44+
LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT
45+
; If class is not initialized, bail to C++ helper
46+
test byte ptr [rcx + OFFSETOF__DomainLocalModule__m_pDataBlob + rdx], 1
47+
jz CallHelper
48+
49+
mov rax, [rcx + OFFSETOF__DomainLocalModule__m_pGCStatics]
50+
REPRET
51+
52+
align 16
53+
CallHelper:
54+
; Tail call Jit_GetSharedGCStaticBase_Helper
55+
jmp JIT_GetSharedGCStaticBase_Helper
56+
LEAF_END JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT
57+
58+
LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain, _TEXT
59+
mov rax, [rcx + OFFSETOF__DomainLocalModule__m_pGCStatics]
60+
ret
61+
LEAF_END JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain, _TEXT
62+
63+
end
64+
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
.intel_syntax noprefix
6+
#include "unixasmmacros.inc"
7+
#include "asmconstants.h"
8+
9+
//
10+
// JIT Static access helpers when coreclr host specifies single
11+
// appdomain flag
12+
//
13+
14+
LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain, _TEXT
15+
// If class is not initialized, bail to C++ helper
16+
test byte ptr [rdi + OFFSETOF__DomainLocalModule__m_pDataBlob + rsi], 1
17+
jz CallHelper
18+
mov rax, rdi
19+
rep ret
20+
21+
.balign 16
22+
CallHelper:
23+
// Tail call JIT_GetSharedNonGCStaticBase_Helper
24+
jmp C_FUNC(JIT_GetSharedNonGCStaticBase_Helper)
25+
LEAF_END_MARKED JIT_GetSharedNonGCStaticBase_SingleAppDomain, _TEXT
26+
27+
LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain, _TEXT
28+
mov rax, rdi
29+
ret
30+
LEAF_END JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain, _TEXT
31+
32+
LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT
33+
// If class is not initialized, bail to C++ helper
34+
test byte ptr [rdi + OFFSETOF__DomainLocalModule__m_pDataBlob + rsi], 1
35+
jz CallHelper1
36+
37+
mov rax, [rdi + OFFSETOF__DomainLocalModule__m_pGCStatics]
38+
rep ret
39+
40+
.balign 16
41+
CallHelper1:
42+
// Tail call Jit_GetSharedGCStaticBase_Helper
43+
jmp C_FUNC(JIT_GetSharedGCStaticBase_Helper)
44+
LEAF_END JIT_GetSharedGCStaticBase_SingleAppDomain, _TEXT
45+
46+
LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain, _TEXT
47+
mov rax, [rdi + OFFSETOF__DomainLocalModule__m_pGCStatics]
48+
ret
49+
LEAF_END JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain, _TEXT

src/vm/arm64/asmconstants.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,11 @@ ASMCONSTANTS_C_ASSERT(ResolveCacheElem__target == offsetof(ResolveCacheElem, tar
167167
ASMCONSTANTS_C_ASSERT(ResolveCacheElem__pNext == offsetof(ResolveCacheElem, pNext));
168168
#endif // CROSSGEN_COMPILE
169169

170+
#define DomainLocalModule__m_pDataBlob 0x30
171+
#define DomainLocalModule__m_pGCStatics 0x20
172+
ASMCONSTANTS_C_ASSERT(DomainLocalModule__m_pDataBlob == offsetof(DomainLocalModule, m_pDataBlob));
173+
ASMCONSTANTS_C_ASSERT(DomainLocalModule__m_pGCStatics == offsetof(DomainLocalModule, m_pGCStatics));
174+
175+
170176
#undef ASMCONSTANTS_RUNTIME_ASSERT
171177
#undef ASMCONSTANTS_C_ASSERT

src/vm/arm64/asmhelpers.S

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,3 +1212,60 @@ NESTED_END StubDispatchFixupStub, _TEXT
12121212
fmov d0, x1
12131213
LEAF_END
12141214
#endif
1215+
1216+
//
1217+
// JIT Static access helpers when coreclr host specifies single appdomain flag
1218+
//
1219+
1220+
// ------------------------------------------------------------------
1221+
// void* JIT_GetSharedNonGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1222+
1223+
LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain
1224+
// If class is not initialized, bail to C++ helper
1225+
add x2, x0, #DomainLocalModule__m_pDataBlob
1226+
ldrb w2, [x2, w1]
1227+
tst w2, #1
1228+
beq LOCAL_LABEL(CallHelper)
1229+
1230+
ret lr
1231+
1232+
LOCAL_LABEL(CallHelper):
1233+
// Tail call JIT_GetSharedNonGCStaticBase_Helper
1234+
b C_FUNC(JIT_GetSharedNonGCStaticBase_Helper)
1235+
LEAF_END
1236+
1237+
1238+
// ------------------------------------------------------------------
1239+
// void* JIT_GetSharedNonGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1240+
1241+
LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain
1242+
ret lr
1243+
LEAF_END
1244+
1245+
1246+
// ------------------------------------------------------------------
1247+
// void* JIT_GetSharedGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1248+
1249+
LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain
1250+
// If class is not initialized, bail to C++ helper
1251+
add x2, x0, #DomainLocalModule__m_pDataBlob
1252+
ldrb w2, [x2, w1]
1253+
tst w2, #1
1254+
beq LOCAL_LABEL(CallHelper)
1255+
1256+
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
1257+
ret lr
1258+
1259+
LOCAL_LABEL(CallHelper):
1260+
// Tail call Jit_GetSharedGCStaticBase_Helper
1261+
b C_FUNC(JIT_GetSharedGCStaticBase_Helper)
1262+
LEAF_END
1263+
1264+
1265+
// ------------------------------------------------------------------
1266+
// void* JIT_GetSharedGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1267+
1268+
LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain
1269+
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
1270+
ret lr
1271+
LEAF_END

src/vm/arm64/asmhelpers.asm

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
IMPORT $g_GCShadowEnd
5353
#endif // WRITE_BARRIER_CHECK
5454

55+
IMPORT JIT_GetSharedNonGCStaticBase_Helper
56+
IMPORT JIT_GetSharedGCStaticBase_Helper
57+
5558
TEXTAREA
5659

5760
;; LPVOID __stdcall GetCurrentIP(void);
@@ -1326,5 +1329,62 @@ Fail
13261329
LEAF_END
13271330
#endif
13281331

1332+
;
1333+
; JIT Static access helpers when coreclr host specifies single appdomain flag
1334+
;
1335+
1336+
; ------------------------------------------------------------------
1337+
; void* JIT_GetSharedNonGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1338+
1339+
LEAF_ENTRY JIT_GetSharedNonGCStaticBase_SingleAppDomain
1340+
; If class is not initialized, bail to C++ helper
1341+
add x2, x0, #DomainLocalModule__m_pDataBlob
1342+
ldrb w2, [x2, w1]
1343+
tst w2, #1
1344+
beq CallHelper1
1345+
1346+
ret lr
1347+
1348+
CallHelper1
1349+
; Tail call JIT_GetSharedNonGCStaticBase_Helper
1350+
b JIT_GetSharedNonGCStaticBase_Helper
1351+
LEAF_END
1352+
1353+
1354+
; ------------------------------------------------------------------
1355+
; void* JIT_GetSharedNonGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1356+
1357+
LEAF_ENTRY JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain
1358+
ret lr
1359+
LEAF_END
1360+
1361+
1362+
; ------------------------------------------------------------------
1363+
; void* JIT_GetSharedGCStaticBase(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1364+
1365+
LEAF_ENTRY JIT_GetSharedGCStaticBase_SingleAppDomain
1366+
; If class is not initialized, bail to C++ helper
1367+
add x2, x0, #DomainLocalModule__m_pDataBlob
1368+
ldrb w2, [x2, w1]
1369+
tst w2, #1
1370+
beq CallHelper2
1371+
1372+
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
1373+
ret lr
1374+
1375+
CallHelper2
1376+
; Tail call Jit_GetSharedGCStaticBase_Helper
1377+
b JIT_GetSharedGCStaticBase_Helper
1378+
LEAF_END
1379+
1380+
1381+
; ------------------------------------------------------------------
1382+
; void* JIT_GetSharedGCStaticBaseNoCtor(SIZE_T moduleDomainID, DWORD dwClassDomainID)
1383+
1384+
LEAF_ENTRY JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain
1385+
ldr x0, [x0, #DomainLocalModule__m_pGCStatics]
1386+
ret lr
1387+
LEAF_END
1388+
13291389
; Must be at very end of file
13301390
END

src/vm/arm64/stubs.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515
#include "virtualcallstub.h"
1616
#include "jitinterface.h"
1717

18+
EXTERN_C void JIT_GetSharedNonGCStaticBase_SingleAppDomain();
19+
EXTERN_C void JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain();
20+
EXTERN_C void JIT_GetSharedGCStaticBase_SingleAppDomain();
21+
EXTERN_C void JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain();
22+
1823
#ifndef DACCESS_COMPILE
1924
//-----------------------------------------------------------------------
2025
// InstructionFormat for B.cond
@@ -1078,10 +1083,18 @@ void JIT_TailCall()
10781083
_ASSERTE(!"ARM64:NYI");
10791084
}
10801085

1086+
#if !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
10811087
void InitJITHelpers1()
10821088
{
1083-
return;
1089+
if(IsSingleAppDomain())
1090+
{
1091+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE, JIT_GetSharedGCStaticBase_SingleAppDomain);
1092+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, JIT_GetSharedNonGCStaticBase_SingleAppDomain);
1093+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE_NOCTOR, JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain);
1094+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR,JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain);
1095+
}
10841096
}
1097+
#endif // !defined(DACCESS_COMPILE) && !defined(CROSSGEN_COMPILE)
10851098

10861099
EXTERN_C void __stdcall ProfileEnterNaked(UINT_PTR clientData)
10871100
{

src/vm/jitinterfacegen.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ extern "C" void* JIT_GetSharedNonGCStaticBaseNoCtor_Slow(SIZE_T moduleDomainID,
6161
extern "C" void* JIT_GetSharedGCStaticBase_Slow(SIZE_T moduleDomainID, DWORD dwModuleClassID);
6262
extern "C" void* JIT_GetSharedGCStaticBaseNoCtor_Slow(SIZE_T moduleDomainID, DWORD dwModuleClassID);
6363

64+
extern "C" void* JIT_GetSharedNonGCStaticBase_SingleAppDomain(SIZE_T moduleDomainID, DWORD dwModuleClassID);
65+
extern "C" void* JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain(SIZE_T moduleDomainID, DWORD dwModuleClassID);
66+
extern "C" void* JIT_GetSharedGCStaticBase_SingleAppDomain(SIZE_T moduleDomainID, DWORD dwModuleClassID);
67+
extern "C" void* JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain(SIZE_T moduleDomainID, DWORD dwModuleClassID);
68+
6469
#ifdef _TARGET_AMD64_
6570
extern WriteBarrierManager g_WriteBarrierManager;
6671
#endif // _TARGET_AMD64_
@@ -283,7 +288,17 @@ void InitJITHelpers1()
283288
SetJitHelperFunction(CORINFO_HELP_MON_ENTER_STATIC, JIT_MonEnterStatic_Slow);
284289
SetJitHelperFunction(CORINFO_HELP_MON_EXIT_STATIC, JIT_MonExitStatic_Slow);
285290
}
291+
#endif
286292

293+
if(IsSingleAppDomain())
294+
{
295+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE, JIT_GetSharedGCStaticBase_SingleAppDomain);
296+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE, JIT_GetSharedNonGCStaticBase_SingleAppDomain);
297+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE_NOCTOR, JIT_GetSharedGCStaticBaseNoCtor_SingleAppDomain);
298+
SetJitHelperFunction(CORINFO_HELP_GETSHARED_NONGCSTATIC_BASE_NOCTOR,JIT_GetSharedNonGCStaticBaseNoCtor_SingleAppDomain);
299+
}
300+
#ifndef FEATURE_IMPLICIT_TLS
301+
else
287302
if (gAppDomainTLSIndex >= TLS_MINIMUM_AVAILABLE)
288303
{
289304
SetJitHelperFunction(CORINFO_HELP_GETSHARED_GCSTATIC_BASE, JIT_GetSharedGCStaticBase_Slow);

0 commit comments

Comments
 (0)