Skip to content
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

Move the thread alloc context off of Thread in CoreCLR #103055

Merged
merged 20 commits into from
Jun 17, 2024

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented Jun 5, 2024

Fixes #99661

This PR also removes the x64-specific inline-assembly helpers for a few scenarios as we now get identical or near-identical codegen with MSVC for our release builds.

@jkoritzinsky jkoritzinsky added NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it area-VM-coreclr labels Jun 5, 2024
Copy link
Contributor

Tagging subscribers to this area: @mangod9
See info in area-owners.md if you want to be subscribed.

…es to enable MSVC to optimize dynamic TLS initialization away. Clean up comments. Fix NativeAOT emulated TLS
…ave nearly identical assembly as the (raw hcall impl) portable helpers in jithelpers.cpp. Use those instead.

Leave JIT_Box's assembly helper as we can't get quite as good of codegen with a portable helper today (and we don't even have one at the moment)
…up when a thread dies, as the TLS memory will be released
…minate (which does all the same cleanup as DetachThread, but in a scenario where we can actually clean up the object as well).
@jkoritzinsky jkoritzinsky removed NO-MERGE The PR is not ready for merge yet (see discussion for detailed reasons) NO-REVIEW Experimental/testing PR, do NOT review it labels Jun 14, 2024
@jkoritzinsky jkoritzinsky requested review from jkotas and davidwrighton and removed request for MichalStrehovsky June 14, 2024 03:43
src/coreclr/vm/threads.cpp Outdated Show resolved Hide resolved
@jkoritzinsky jkoritzinsky changed the title Move the thread alloc context off of Thread in CoreCLR and NativeAOT Move the thread alloc context off of Thread in CoreCLR Jun 14, 2024
@jkoritzinsky jkoritzinsky requested a review from jkotas June 14, 2024 18:53
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

src/coreclr/debug/daccess/request.cpp Outdated Show resolved Hide resolved
src/coreclr/debug/daccess/request.cpp Outdated Show resolved Hide resolved
src/coreclr/vm/amd64/AsmMacros.inc Show resolved Hide resolved
extern CopyValueClassUnchecked:proc
extern JIT_Box:proc

; HCIMPL2(Object*, JIT_Box, CORINFO_CLASS_HANDLE type, void* unboxedData)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to get rid of this asm implementation and replace it with the portable C++ one. (It can be done in separate change.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was having trouble getting the exact same assembly out of this one with a C++ implementation, so I didn't want to do it in this PR. I'll move it over in another PR and we can review the assembly differences there.

Copy link
Member

@jkotas jkotas Jun 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The box helper is not super perf critical. The JIT will inline it for all cases that matter. I think it would be fine to have something close enough - anything that does not raise HELPER_METHOD_FRAME on a hot path should be ok.

src/coreclr/vm/gcheaputilities.h Show resolved Hide resolved
src/coreclr/vm/jithelpers.cpp Show resolved Hide resolved
src/coreclr/vm/jithelpers.cpp Show resolved Hide resolved
#ifdef _MSC_VER
EXTERN_C __declspec(selectany) __declspec(thread) gc_alloc_context t_thread_alloc_context;
#else
EXTERN_C __thread gc_alloc_context t_thread_alloc_context;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was about to see what it would take to move m_fPreemptiveGCDisabled and m_pFrame to be on this same plan (inline thread static - to save an indirection in PInvoke transitions). It would help to have all these key inline thread statics together, similar to how it is done in naot. Can we turn this into a structure like ThreadBuffer and make gc_alloc_context to be the first field in it? We can then move more into that structure.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can do that. Would you like me to do it in this PR or in a follow-up?

I'd prefer to do it in a follow-up when I mess with the box helper as there won't be any assembly changes I need to make then (as the thread-specific alloc-context won't be referenced in any hand-written CoreCLR assembly helpers at that point)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine with me.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid unnecessary extra indirection in allocation helpers
2 participants