-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Share allocation helpers between CoreCLR and NativeAOT #115339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The general shape LGTM. Thank you! |
This is now ready for some initial review pass. |
cc @tomeksowi can we run the RISC-V bot on this? |
Of course. It will take some time to fully build the NativeAOT testcases, so the results will come out later. |
…) >= size, fix few typos in comments
Smoke tests passed with 3ac08ee. freebsd-x64: https://github.com/am11/CrossRepoCITesting/actions/runs/15390897782 |
Thanks for testing! I run it locally before pushing it but this is more comprehensive check. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise!
|
||
[RuntimeImport(RuntimeLibrary, "RhpNewVariableSizeObject")] | ||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
internal static extern unsafe object RhpNewVariableSizeObject(MethodTable* pEEType, int length, uint flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of RhpNewVariableSizeObject
does not expect the extra flags
argument.
- On x86, it is going to result into stack imbalance
- On arm, we do not pass the flags through, so it is not going to allocate 8-byte aligned array when needed
I think we may want to replace the calls to this with calls to RhAllocateNewArray instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, probably worth re-running /azp run runtime-nativeaot-outerloop
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it to use RhAllocateNewArray
. Alternative was to change to (misnamed) RhpNewArrayFastAlign8
/ RhpNewVariableSizeObject
with no flags
parameter. Then again, it is a code path slated for a cleanup in the follow-up.
/azp run runtime-nativeaot-outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
@filipnavara any chance #116276 is exclusive to this PR? |
Cannot rule anything out but I don't see any connection. It's NativeAOT outerloop which is not run as often as other tests. (Will look at the Helix artifacts later to see if anything sticks out.) |
Found one hit on main: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1056334&view=ms.vss-test-web.build-test-results-tab&runId=28475296&resultId=119279&paneView=debug ![]() @jkotas, it can randomly fail for any test using merged test executor (not specific to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None of the NativeAOT outer loop failures look related.
Thank you - great work!
/ba-g unrelated infrastructure issue (failure to list devices) |
Thanks for the patience with reviewing this. |
Share assembly version of allocation helpers between CoreCLR and NativeAOT. This allows better code reuse and removes the last usage of helper method frames in the CoreCLR runtime, cleanup is expected to be done separetely.
The slow paths on CoreCLR differ from NativeAOT in few details. They don't expect the
GC_ALLOC_FINALIZE
,GC_ALLOC_ALIGN8
andGC_ALLOC_ALIGN8_BIAS
flags to be passed the correct values and if they are not present then they get inferred from the method table. This means that helpers likeRhpNewFinalizable
stay exclusive to NativeAOT and remain unused on CoreCLR. This is done intentionally so we can have a single slow path (RhpNew
for objects,RhpNewArray
for arrays) that can be assigned to any JIT helper. The slow path is used when allocation tracking is enabled or for other diagnostic options.CoreCLR stores the per-thread allocation context in separate TLS variable, while NativeAOT track it as part of the main per-thread information. We abstract it by introducing
INLINE_GET_ALLOC_CONTEXT
macro that returns the pointer toee_alloc_context
structure.FastAllocateString
helper in CoreCLR has a changed signature to take the string method table as the first parameter. This mimics the same idea as used by NativeAOT where we can use slow array allocation helper and fast string allocation helper interchangably.Platform specific notes:
INLINE_GET_ALLOC_CONTEXT
doing function call that trashes volatile registers.Contributes to #95695