From 7dab12e3f03e61927cf1558c6490303f58220fbe Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Thu, 26 Sep 2024 19:57:04 -0700 Subject: [PATCH 1/2] Fix statics issue with barriers --- src/coreclr/vm/arm64/asmhelpers.S | 6 ++++-- src/coreclr/vm/arm64/asmhelpers.asm | 6 ++++-- src/coreclr/vm/methodtable.h | 8 ++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/coreclr/vm/arm64/asmhelpers.S b/src/coreclr/vm/arm64/asmhelpers.S index 723bb4b384113..ac51662c82db4 100644 --- a/src/coreclr/vm/arm64/asmhelpers.S +++ b/src/coreclr/vm/arm64/asmhelpers.S @@ -653,7 +653,8 @@ DynamicHelper DynamicHelperFrameFlags_ObjectArg | DynamicHelperFrameFlags_Object LEAF_ENTRY JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper - ldr x1, [x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics] + add x1, x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics + ldar x1, [x1] tbnz x1, #0, LOCAL_LABEL(JIT_GetDynamicNonGCStaticBase_SingleAppDomain_CallHelper) mov x0, x1 ret lr @@ -668,7 +669,8 @@ LEAF_END JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT LEAF_ENTRY JIT_GetDynamicGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper - ldr x1, [x0, #OFFSETOF__DynamicStaticsInfo__m_pGCStatics] + add x1, x0, #OFFSETOF__DynamicStaticsInfo__m_pGCStatics + ldar x1, [x1] tbnz x1, #0, LOCAL_LABEL(JIT_GetDynamicGCStaticBase_SingleAppDomain_CallHelper) mov x0, x1 ret lr diff --git a/src/coreclr/vm/arm64/asmhelpers.asm b/src/coreclr/vm/arm64/asmhelpers.asm index fd66033e898f5..153c7a3dbe9b5 100644 --- a/src/coreclr/vm/arm64/asmhelpers.asm +++ b/src/coreclr/vm/arm64/asmhelpers.asm @@ -1012,7 +1012,8 @@ Fail LEAF_ENTRY JIT_GetDynamicNonGCStaticBase_SingleAppDomain ; If class is not initialized, bail to C++ helper - ldr x1, [x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics] + add x1, x0, #OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics + ldar x1, [x1] tbnz x1, #0, CallHelper1 mov x0, x1 ret lr @@ -1026,7 +1027,8 @@ CallHelper1 LEAF_ENTRY JIT_GetDynamicGCStaticBase_SingleAppDomain ; If class is not initialized, bail to C++ helper - ldr x1, [x0, #OFFSETOF__DynamicStaticsInfo__m_pGCStatics] + add x1, x0, #OFFSETOF__DynamicStaticsInfo__m_pGCStatics + ldar x1, [x1] tbnz x1, #0, CallHelper2 mov x0, x1 ret lr diff --git a/src/coreclr/vm/methodtable.h b/src/coreclr/vm/methodtable.h index 6c454cf4ac149..e1dce807d381f 100644 --- a/src/coreclr/vm/methodtable.h +++ b/src/coreclr/vm/methodtable.h @@ -603,12 +603,12 @@ struct DynamicStaticsInfo TADDR m_pGCStatics; // Always access through helper methods to properly handle the ISCLASSNOTINITED bit TADDR m_pNonGCStatics; // Always access through helper methods to properly handle the ISCLASSNOTINITED bit PTR_MethodTable m_pMethodTable; - PTR_OBJECTREF GetGCStaticsPointer() { TADDR staticsVal = VolatileLoadWithoutBarrier(&m_pGCStatics); return dac_cast(staticsVal & STATICSPOINTERMASK); } - PTR_BYTE GetNonGCStaticsPointer() { TADDR staticsVal = VolatileLoadWithoutBarrier(&m_pNonGCStatics); return dac_cast(staticsVal & STATICSPOINTERMASK); } + PTR_OBJECTREF GetGCStaticsPointer() { TADDR staticsVal = VolatileLoad(&m_pGCStatics); return dac_cast(staticsVal & STATICSPOINTERMASK); } + PTR_BYTE GetNonGCStaticsPointer() { TADDR staticsVal = VolatileLoad(&m_pNonGCStatics); return dac_cast(staticsVal & STATICSPOINTERMASK); } PTR_OBJECTREF GetGCStaticsPointerAssumeIsInited() { TADDR staticsVal = m_pGCStatics; _ASSERTE(staticsVal != 0); _ASSERTE((staticsVal & (ISCLASSNOTINITEDMASK)) == 0); return dac_cast(staticsVal); } PTR_BYTE GetNonGCStaticsPointerAssumeIsInited() { TADDR staticsVal = m_pNonGCStatics; _ASSERTE(staticsVal != 0); _ASSERTE((staticsVal & (ISCLASSNOTINITEDMASK)) == 0); return dac_cast(staticsVal); } - bool GetIsInitedAndGCStaticsPointerIfInited(PTR_OBJECTREF *ptrResult) { TADDR staticsVal = VolatileLoadWithoutBarrier(&m_pGCStatics); *ptrResult = dac_cast(staticsVal); return !(staticsVal & ISCLASSNOTINITED); } - bool GetIsInitedAndNonGCStaticsPointerIfInited(PTR_BYTE *ptrResult) { TADDR staticsVal = VolatileLoadWithoutBarrier(&m_pNonGCStatics); *ptrResult = dac_cast(staticsVal); return !(staticsVal & ISCLASSNOTINITED); } + bool GetIsInitedAndGCStaticsPointerIfInited(PTR_OBJECTREF *ptrResult) { TADDR staticsVal = VolatileLoad(&m_pGCStatics); *ptrResult = dac_cast(staticsVal); return !(staticsVal & ISCLASSNOTINITED); } + bool GetIsInitedAndNonGCStaticsPointerIfInited(PTR_BYTE *ptrResult) { TADDR staticsVal = VolatileLoad(&m_pNonGCStatics); *ptrResult = dac_cast(staticsVal); return !(staticsVal & ISCLASSNOTINITED); } // This function sets the pointer portion of a statics pointer. It returns false if the statics value was already set. bool InterlockedUpdateStaticsPointer(bool isGC, TADDR newVal, bool isClassInitedByUpdatingStaticPointer) From a9cf91a6f205fa0e72df5e8ed951151dc172a4d6 Mon Sep 17 00:00:00 2001 From: David Wrighton Date: Fri, 27 Sep 2024 09:04:40 -0700 Subject: [PATCH 2/2] Add barriers for RiscV and Loongson --- src/coreclr/vm/loongarch64/asmhelpers.S | 2 ++ src/coreclr/vm/riscv64/asmhelpers.S | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/coreclr/vm/loongarch64/asmhelpers.S b/src/coreclr/vm/loongarch64/asmhelpers.S index 2350e55a639f3..7edded0c031e3 100644 --- a/src/coreclr/vm/loongarch64/asmhelpers.S +++ b/src/coreclr/vm/loongarch64/asmhelpers.S @@ -937,6 +937,7 @@ LEAF_END setFPReturn, _TEXT LEAF_ENTRY JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper ld.d $a1, $a0, OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics + dbar 0 bnez $a1, LOCAL_LABEL(JIT_GetDynamicNonGCStaticBase_SingleAppDomain_CallHelper) ori $a0, $a1, 0 jirl $r0, $ra, 0 @@ -952,6 +953,7 @@ LEAF_END JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT LEAF_ENTRY JIT_GetDynamicGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper ld.d $a1, $a0, OFFSETOF__DynamicStaticsInfo__m_pGCStatics + dbar 0 bnez $a1, LOCAL_LABEL(JIT_GetDynamicGCStaticBase_SingleAppDomain_CallHelper) ori $a0, $a1, 0 jirl $r0, $ra, 0 diff --git a/src/coreclr/vm/riscv64/asmhelpers.S b/src/coreclr/vm/riscv64/asmhelpers.S index 977d0354e4e80..577f92f211014 100644 --- a/src/coreclr/vm/riscv64/asmhelpers.S +++ b/src/coreclr/vm/riscv64/asmhelpers.S @@ -806,6 +806,7 @@ LEAF_END setFPReturn, _TEXT LEAF_ENTRY JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper ld a1, OFFSETOF__DynamicStaticsInfo__m_pNonGCStatics(a0) + fence r,rw bnez a1, LOCAL_LABEL(JIT_GetDynamicNonGCStaticBase_SingleAppDomain_CallHelper) mv a0, a1 ret @@ -822,6 +823,7 @@ LEAF_END JIT_GetDynamicNonGCStaticBase_SingleAppDomain, _TEXT LEAF_ENTRY JIT_GetDynamicGCStaticBase_SingleAppDomain, _TEXT // If class is not initialized, bail to C++ helper ld a1, OFFSETOF__DynamicStaticsInfo__m_pGCStatics(a0) + fence r,rw bnez a1, LOCAL_LABEL(JIT_GetDynamicGCStaticBase_SingleAppDomain_CallHelper) mv a0, a1 ret