Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4915573
Share allocation helpers between CoreCLR and NativeAOT
filipnavara May 4, 2025
c5add6c
Remove unused OFFSETOF__String__m_Length
filipnavara May 15, 2025
3b6496b
Minor cleanup
filipnavara May 15, 2025
ea19aca
Apply suggestions from code review
filipnavara May 16, 2025
4410d5a
Fix INLINE_GET_ALLOC_CONTEXT macros for loongarch64
filipnavara May 16, 2025
63cc0aa
Fix arm64 build
filipnavara May 17, 2025
41b36d0
Don't save (FP) arguments in PUSH_COOP_PINVOKE_FRAME when they are no…
filipnavara May 26, 2025
dba2a0a
Micro-optimize multiplication on Intel CPUs
filipnavara May 26, 2025
7165763
Improve ARM Align8/Misalign helpers
filipnavara May 26, 2025
393e958
Remove FEATURE_DOUBLE_ALIGNMENT_HINT helpers
filipnavara May 26, 2025
7cb358b
Wire up CORINFO_HELP_NEWARR_1_ALIGN8 on CoreCLR
filipnavara May 26, 2025
8bbdcc0
Remove dead code
filipnavara May 26, 2025
d2f30b1
Specify function alignment on x64
filipnavara May 26, 2025
03937ee
Remove FEATURE_READYTORUN guards around DynamicHelperFrame
filipnavara May 27, 2025
e887720
Avoid saving argument registers in PUSH_COOP_PINVOKE_FRAME on 64-bit …
filipnavara May 27, 2025
f9f76f9
Fix PUSH/POP_COOP_PINVOKE_FRAME on x86 and adjust the usage to match …
filipnavara May 27, 2025
b162ce2
Update PUSH_COOP_PINVOKE_FRAME/POP_COOP_PINVOKE_FRAME on ARM32
filipnavara May 27, 2025
553e498
Fix unwinding information for PUSH_COOP_PINVOKE_FRAME/POP_COOP_PINVOK…
filipnavara May 27, 2025
d2b8377
Fix PUSH_COOP_PINVOKE_FRAME for linux-x64/osx-x64
filipnavara May 27, 2025
0a9dda2
Fix ARM stack alignment
filipnavara May 27, 2025
bfda608
Update src/coreclr/pal/inc/unixasmmacrosarm.inc
filipnavara May 27, 2025
ad9723b
Change NativeAOT MD array allocation to go through slow helper
filipnavara May 29, 2025
e9bc1d1
Revert unnecessary changes
filipnavara May 29, 2025
7e60b77
Change calling convention for RhpGcAlloc/RhpGcAllocMaybeFrozen/RhExce…
filipnavara May 29, 2025
95e83c0
Use SZARRAY_BASE_SIZE for RhpNewArrayFast/RhpNewObjectArrayFast
filipnavara May 29, 2025
15c9486
Split RhNewArray into RhNewArray (fast SZ array helper) / RhNewVariab…
filipnavara May 29, 2025
9099a3f
Remove ASM_LARGE_OBJECT_SIZE usage from RhpNewObjectArrayFast, update…
filipnavara May 30, 2025
8be5c58
Fix comment
filipnavara May 30, 2025
24c5ccd
Bail out on overflows in RhpNewFast* on 32-bit platforms
filipnavara May 30, 2025
55ab84a
Use LEAF_ENTRY/NESTED_ENTRY consistently
filipnavara Jun 1, 2025
1d0e9db
Rename RhpNewArray to RhpNewVariableSizeObject, fix RhpNewObjectArray…
filipnavara Jun 1, 2025
77d88e0
Apply suggestions from code review
filipnavara Jun 1, 2025
203615b
Revert one of the last changes
filipnavara Jun 1, 2025
eda90c9
Update fast alloc pattern on arm64 to use (combined_limit - alloc_ptr…
filipnavara Jun 2, 2025
893a8d6
Update fast alloc pattern on x64 to use (combined_limit - alloc_ptr) …
filipnavara Jun 2, 2025
0260d54
Post-rebase fix
filipnavara Jun 2, 2025
523bedf
INLINE_GET_ALLOC_CONTEXT -> INLINE_GET_ALLOC_CONTEXT_BASE + OFFSETOF_…
filipnavara Jun 2, 2025
d6ae57d
Fix typo
filipnavara Jun 2, 2025
679d691
Fix win-x64 NEW_ARRAY_FAST
filipnavara Jun 2, 2025
39e5b6f
Update fast alloc pattern on rv64/la64 to use (combined_limit - alloc…
filipnavara Jun 2, 2025
3ac08ee
Update fast alloc pattern on arm32 to use (combined_limit - alloc_ptr…
filipnavara Jun 2, 2025
29b6879
Fix cut & paste error in arm32 NEW_ARRAY_FAST
filipnavara Jun 2, 2025
1288dd6
Address PR feedback
filipnavara Jun 3, 2025
3362c7c
Replace incorrect import of RhpNewVariableSizeObject with RhAllocateN…
filipnavara Jun 3, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ internal static unsafe string StrCns(uint rid, IntPtr scopeHandle)
}

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern string FastAllocateString(int length);
internal static extern unsafe string FastAllocateString(MethodTable *pMT, int length);

[DebuggerHidden]
internal static unsafe string FastAllocateString(int length)
{
return FastAllocateString(TypeHandle.TypeHandleOf<string>().AsMethodTable(), length);
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "String_Intern")]
private static partial void Intern(StringHandleOnStack src);
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,6 @@ namespace ETW
static VOID SendMethodDetailsEvent(MethodDesc *pMethodDesc);
static VOID SendNonDuplicateMethodDetailsEvent(MethodDesc* pMethodDesc, MethodDescSet* set);
static VOID StubInitialized(ULONGLONG ullHelperStartAddress, LPCWSTR pHelperName);
static VOID StubsInitialized(PVOID *pHelperStartAddress, PVOID *pHelperNames, LONG ulNoOfHelpers);
static VOID MethodRestored(MethodDesc * pMethodDesc);
static VOID MethodTableRestored(MethodTable * pMethodTable);
static VOID DynamicMethodDestroyed(MethodDesc *pMethodDesc);
Expand All @@ -972,7 +971,6 @@ namespace ETW
static VOID MethodJitting(MethodDesc *pMethodDesc, COR_ILMETHOD_DECODER* methodDecoder, SString *namespaceOrClassName, SString *methodName, SString *methodSignature);
static VOID MethodJitted(MethodDesc *pMethodDesc, SString *namespaceOrClassName, SString *methodName, SString *methodSignature, PCODE pNativeCodeStartAddress, PrepareCodeConfig *pConfig);
static VOID StubInitialized(ULONGLONG ullHelperStartAddress, LPCWSTR pHelperName) {};
static VOID StubsInitialized(PVOID *pHelperStartAddress, PVOID *pHelperNames, LONG ulNoOfHelpers) {};
static VOID MethodRestored(MethodDesc * pMethodDesc) {};
static VOID MethodTableRestored(MethodTable * pMethodTable) {};
static VOID DynamicMethodDestroyed(MethodDesc *pMethodDesc) {};
Expand Down
31 changes: 15 additions & 16 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
#define FEATURE_USE_HELPERS_FOR_32BIT_INT_DIV
#endif

// pfnHelper is set to NULL if it is a stubbed helper.
// It will be set in InitJITHelpers1
// pfnHelper is set to NULL if it is an unused helper.

JITHELPER(CORINFO_HELP_UNDEF, NULL, METHOD__NIL)

Expand Down Expand Up @@ -100,20 +99,20 @@
JITHELPER(CORINFO_HELP_DBLREM, JIT_DblRem, METHOD__NIL)

// Allocating a new object
JITHELPER(CORINFO_HELP_NEWFAST, JIT_New, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWFAST_MAYBEFROZEN, JIT_NewMaybeFrozen,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST, JIT_New, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_FINALIZE, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_New, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_VC, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_FINALIZE, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR_RARE, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
JITHELPER(CORINFO_HELP_NEWARR_1_DIRECT, JIT_NewArr1,METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWARR_1_MAYBEFROZEN, JIT_NewArr1MaybeFrozen,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_VC, JIT_NewArr1,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_ALIGN8, JIT_NewArr1,METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWFAST, RhpNew, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWFAST_MAYBEFROZEN, RhpNewMaybeFrozen, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST, RhpNew, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_FINALIZE, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8, RhpNew, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_VC, RhpNew, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_FINALIZE, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR_RARE, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
JITHELPER(CORINFO_HELP_NEWARR_1_DIRECT, RhpNewVariableSizeObject, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWARR_1_MAYBEFROZEN, RhpNewArrayMaybeFrozen, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_OBJ, RhpNewVariableSizeObject, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_VC, RhpNewVariableSizeObject, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_ALIGN8, RhpNewVariableSizeObject, METHOD__NIL)

DYNAMICJITHELPER(CORINFO_HELP_STRCNS, NULL, METHOD__STRING__STRCNS)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<StepFilter xmlns="http://schemas.microsoft.com/vstudio/debugger/natstepfilter/2010">
<Function>
<Name>RhpNewFast|RhpNewFinalizable|RhpNewFastAlign8|RhpNewFastMisalign|RhpNewFinalizableAlign8|RhpNewArray|RhpNewArrayAlign8</Name>
<Name>RhpNewFast|RhpNewFinalizable|RhpNewFastAlign8|RhpNewFastMisalign|RhpNewFinalizableAlign8|RhpNewArrayFast|RhpNewArrayFastAlign8</Name>
<Action>NoStepInto</Action>
</Function>
</StepFilter>
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,9 @@ internal static int RhEndNoGCRegion()
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe object RhpNewFinalizable(MethodTable* pEEType);

[RuntimeImport(RuntimeLibrary, "RhpNewArray")]
[RuntimeImport(RuntimeLibrary, "RhpNewArrayFast")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe object RhpNewArray(MethodTable* pEEType, int length);
internal static extern unsafe object RhpNewArrayFast(MethodTable* pEEType, int length);

#if FEATURE_64BIT_ALIGNMENT
[RuntimeImport(RuntimeLibrary, "RhpNewFastAlign8")]
Expand All @@ -141,9 +141,9 @@ internal static int RhEndNoGCRegion()
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe object RhpNewFinalizableAlign8(MethodTable* pEEType);

[RuntimeImport(RuntimeLibrary, "RhpNewArrayAlign8")]
[RuntimeImport(RuntimeLibrary, "RhpNewArrayFastAlign8")]
[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern unsafe object RhpNewArrayAlign8(MethodTable* pEEType, int length);
internal static extern unsafe object RhpNewArrayFastAlign8(MethodTable* pEEType, int length);

[RuntimeImport(RuntimeLibrary, "RhpNewFastMisalign")]
[MethodImpl(MethodImplOptions.InternalCall)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,44 @@ public static unsafe object RhNewObject(MethodTable* pEEType)

[RuntimeExport("RhNewArray")]
public static unsafe object RhNewArray(MethodTable* pEEType, int length)
{
Debug.Assert(pEEType->IsSzArray);

#if FEATURE_64BIT_ALIGNMENT
MethodTable* pEEElementType = pEEType->RelatedParameterType;
if (pEEElementType->IsValueType && pEEElementType->RequiresAlign8)
{
return InternalCalls.RhpNewArrayFastAlign8(pEEType, length);
}
else
#endif // FEATURE_64BIT_ALIGNMENT
{
return InternalCalls.RhpNewArrayFast(pEEType, length);
}
}

[RuntimeExport("RhNewVariableSizeObject")]
public static unsafe object RhNewVariableSizeObject(MethodTable* pEEType, int length)
{
Debug.Assert(pEEType->IsArray || pEEType->IsString);

object array;
#if FEATURE_64BIT_ALIGNMENT
MethodTable* pEEElementType = pEEType->RelatedParameterType;
if (pEEElementType->IsValueType && pEEElementType->RequiresAlign8)
{
return InternalCalls.RhpNewArrayAlign8(pEEType, length);
RuntimeImports.RhAllocateNewArray(pEEType, (uint)length, (uint)GC_ALLOC_FLAGS.GC_ALLOC_ALIGN8, &array);
}
else
#endif // FEATURE_64BIT_ALIGNMENT
{
return InternalCalls.RhpNewArray(pEEType, length);
RuntimeImports.RhAllocateNewArray(pEEType, (uint)length, (uint)GC_ALLOC_FLAGS.GC_ALLOC_NO_FLAGS, &array);
}

if (array == null)
throw new OutOfMemoryException();

return array;
}

public static unsafe object RhBox(MethodTable* pEEType, ref byte data)
Expand Down Expand Up @@ -380,10 +404,10 @@ internal static unsafe IntPtr RhGetRuntimeHelperForType(MethodTable* pEEType, Ru
#if FEATURE_64BIT_ALIGNMENT
MethodTable* pEEElementType = pEEType->RelatedParameterType;
if (pEEElementType->IsValueType && pEEElementType->RequiresAlign8)
return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArrayAlign8;
return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArrayFastAlign8;
#endif // FEATURE_64BIT_ALIGNMENT

return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArray;
return (IntPtr)(delegate*<MethodTable*, int, object>)&InternalCalls.RhpNewArrayFast;

default:
Debug.Fail("Unknown RuntimeHelperKind");
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/nativeaot/Runtime/AsmOffsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ASM_OFFSET( 4, 8, String, m_Length)
ASM_OFFSET( 8, C, String, m_FirstChar)
ASM_CONST( 2, 2, STRING_COMPONENT_SIZE)
ASM_CONST( E, 16, STRING_BASE_SIZE)
ASM_CONST( C, 18, SZARRAY_BASE_SIZE)
ASM_CONST( C, 18, MIN_OBJECT_SIZE)
ASM_CONST(3FFFFFDF,3FFFFFDF,MAX_STRING_LENGTH)


Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ if (CLR_CMAKE_TARGET_ARCH_AMD64)
endif (CLR_CMAKE_TARGET_ARCH_AMD64)

list(APPEND RUNTIME_SOURCES_ARCH_ASM
${ARCH_SOURCES_DIR}/AllocFast.${ASM_SUFFIX}
${RUNTIME_DIR}/${ARCH_SOURCES_DIR}/AllocFast.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/ExceptionHandling.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/GcProbe.${ASM_SUFFIX}
${ARCH_SOURCES_DIR}/MiscStubs.${ASM_SUFFIX}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/nativeaot/Runtime/GCHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ static Object* GcAllocInternal(MethodTable* pEEType, uint32_t uFlags, uintptr_t
// numElements - number of array elements
// pTransitionFrame- transition frame to make stack crawlable
// Returns a pointer to the object allocated or NULL on failure.
EXTERN_C void* F_CALL_CONV RhpGcAlloc(MethodTable* pEEType, uint32_t uFlags, uintptr_t numElements, PInvokeTransitionFrame* pTransitionFrame)
EXTERN_C void* RhpGcAlloc(MethodTable* pEEType, uint32_t uFlags, uintptr_t numElements, PInvokeTransitionFrame* pTransitionFrame)
{
Thread* pThread = ThreadStore::GetCurrentThread();

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/nativeaot/Runtime/ObjectLayout.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ static uintptr_t const STRING_COMPONENT_SIZE = StringConstants::ComponentSize;
//-------------------------------------------------------------------------------------------------
static uintptr_t const STRING_BASE_SIZE = StringConstants::BaseSize;

//-------------------------------------------------------------------------------------------------
static uintptr_t const SZARRAY_BASE_SIZE = MIN_OBJECT_SIZE;

//-------------------------------------------------------------------------------------------------
static uintptr_t const MAX_STRING_LENGTH = 0x3FFFFFDF;

Expand Down
12 changes: 8 additions & 4 deletions src/coreclr/nativeaot/Runtime/amd64/AsmMacros.inc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ PUSH_COOP_PINVOKE_FRAME macro trashReg

;; allocate scratch space and any required alignment
alloc_stack 28h

END_PROLOGUE
endm

;;
Expand All @@ -322,6 +324,10 @@ POP_COOP_PINVOKE_FRAME macro
pop r10 ; discard caller RSP
endm

INLINE_GET_ALLOC_CONTEXT_BASE macro destReg, trashReg
INLINE_GET_TLS_VAR destReg, trashReg, tls_CurrentThread
endm

; - TAILCALL_RAX: ("jmp rax") should be used for tailcalls, this emits an instruction
; sequence which is recognized by the unwinder as a valid epilogue terminator
TAILJMP_RAX TEXTEQU <DB 048h, 0FFh, 0E0h>
Expand All @@ -335,10 +341,8 @@ TSF_DoNotTriggerGc equ 10h
;;
;; Rename fields of nested structs
;;
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_eeAllocContext + OFFSETOF__ee_alloc_context__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__Thread__m_eeAllocContext__combined_limit equ OFFSETOF__Thread__m_eeAllocContext + OFFSETOF__ee_alloc_context__combined_limit


OFFSETOF__ee_alloc_context__alloc_ptr equ OFFSETOF__ee_alloc_context__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__ee_alloc_context equ OFFSETOF__Thread__m_eeAllocContext

;; GC type flags
GC_ALLOC_FINALIZE equ 1
Expand Down
11 changes: 8 additions & 3 deletions src/coreclr/nativeaot/Runtime/arm64/AsmMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ STATUS_REDHAWK_THREAD_ABORT equ 0x43
;;
;; Rename fields of nested structs
;;
OFFSETOF__Thread__m_alloc_context__alloc_ptr equ OFFSETOF__Thread__m_eeAllocContext + OFFSETOF__ee_alloc_context__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__Thread__m_eeAllocContext__combined_limit equ OFFSETOF__Thread__m_eeAllocContext + OFFSETOF__ee_alloc_context__combined_limit
OFFSETOF__ee_alloc_context__alloc_ptr equ OFFSETOF__ee_alloc_context__m_rgbAllocContextBuffer + OFFSETOF__gc_alloc_context__alloc_ptr
OFFSETOF__ee_alloc_context equ OFFSETOF__Thread__m_eeAllocContext

;;
;; IMPORTS
Expand Down Expand Up @@ -220,7 +220,6 @@ TrashRegister32Bit SETS "w":CC:("$TrashRegister32Bit":RIGHT:((:LEN:TrashRegister
INLINE_GET_TLS_VAR $destReg, $trashReg, tls_CurrentThread
MEND


MACRO
INLINE_THREAD_UNHIJACK $threadReg, $trashReg1, $trashReg2
;;
Expand All @@ -236,6 +235,12 @@ TrashRegister32Bit SETS "w":CC:("$TrashRegister32Bit":RIGHT:((:LEN:TrashRegister
0
MEND

MACRO
INLINE_GET_ALLOC_CONTEXT_BASE $destReg, $trashReg

INLINE_GET_TLS_VAR $destReg, $trashReg, tls_CurrentThread
MEND

;; ---------------------------------------------------------------------------- -
;;
;; Macro to add a memory barrier. Equal to __sync_synchronize().
Expand Down
4 changes: 0 additions & 4 deletions src/coreclr/nativeaot/Runtime/i386/AllocFast.S

This file was deleted.

Loading
Loading