Repository navigation
Conversation
…rm64/loongarch64/riscv64 Opt-in via DOTNET_ManagedAllocHelpers=1 (default off). Implements CORINFO_HELP_NEWSFAST, CORINFO_HELP_NEWARR_1_VC/_PTR and String.FastAllocateString in CoreLib (System.Runtime.CompilerServices.AllocHelpers). The fast path reads a cached ee_alloc_context* from a [ThreadStatic] (lazily initialized through an FCall), bumps alloc_ptr against combined_limit (so allocation sampling keeps working) and stores the MethodTable/length; misses fall back to the existing native slow helpers (RhpNew/RhpNewVariableSizeObject). Context: dotnet#138068 (native alloc helpers pay a TLSDESC call per allocation on linux arm64/la64/rv64) and dotnet#138032 (arm64 JIT'd code reaches libcoreclr helpers through jump stubs). Gating: the managed helpers are only installed on linux arm64/loongarch64/ riscv64 when CanJITOptimizeTLSAccess() is true (the JIT inlines the thread-static access, so the managed fast path has no TLS call), and only where the native fast helpers would be used (not with allocation tracking or logging; GCStress=alloc still selects the slow helpers). Everywhere else the native helpers are kept regardless of the config. Not compiled for WebAssembly. - VM: SetJitHelperToILImplementation switches a dynamic helper to an IL implementation at startup. - VM: IL helpers that are not eligible for tiering (AggressiveOptimization) are called directly once jitted (no indirection cell, and on arm64 a direct `bl` within the code heap instead of a jump stub). - JIT: methods of AllocHelpers marked [Intrinsic] are never made fully interruptible (JitStress/JitFullyInt/debuggable code), and their tail calls to the [NoInlining] slow paths are not modeled as GC-poll-free loops. The only GC safe points are then calls outside the alloc_ptr bump -> MethodTable store region; return-address hijack covers the rest. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Azure Pipelines: Successfully started running 5 pipeline(s). 10 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Compile the managed allocation helpers only for 64-bit targets: they are only enabled on linux arm64/loongarch64/riscv64, and the ee_alloc_context layout check does not hold on 32-bit. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Verify the managed AllocHelpers.EEAllocContext layout against the native ee_alloc_context with DEFINE_CLASS_U/DEFINE_FIELD_U in corelib.h (checked by CoreLibBinder::Check in debug/checked builds) instead of static_asserts. - Publish the thread's ee_alloc_context pointer in ThreadLocalData::pAllocContext (set in InitializeCurrentThreadsStaticData) and map AllocHelpers.t_allocContext onto it via TLSIndexType::DirectOnThreadLocalData, the same mechanism used for Thread.DirectOnThreadLocalData and ManagedThreadId. This removes the AllocHelpers_GetAllocContext FCall and the lazy initialization from the slow paths; a null pointer (thread not set up yet) falls back to the slow path. - Carve pAllocContext out of ExtendedDirectThreadLocalTLSData (48 -> 40 bytes) so sizeof(ThreadLocalData) and libcoreclr's TLS segment size are unchanged. Growing the TLS segment by 8 bytes pushed libcoreclr out of glibc's static TLS surplus on linux-arm64 (Ubuntu 26.04), making the TLSDESC resolver dynamic and silently disabling inlined thread-static access for all code. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…nto feature/managed-alloc-helpers
jkotas
reviewed
Nov 24, 2026
Move RuntimeThreadLocals (the thread's ee_alloc_context) from its own t_runtime_thread_locals thread local into ThreadLocalData (t_ThreadStatics), inside the region referenceable by TLSIndexType::DirectOnThreadLocalData. - The managed allocation helpers map AllocHelpers.t_allocContext onto the first field of the embedded ee_alloc_context and use its address, so the fast path is TLS base + constant with no pointer load. The pAllocContext pointer field is removed and ExtendedDirectThreadLocalTLSData is back to 48 bytes. - libcoreclr's TLS segment size is unchanged (the two thread locals are merged, not duplicated). Growing it can push libcoreclr out of glibc's static TLS surplus, which disables the JIT's inlined TLS access. - Native code reaches it through GetRuntimeThreadLocals(); the INLINE_GET_ALLOC_CONTEXT_BASE asm macros (unix amd64/arm64/loongarch64, Windows amd64/x86/arm64) now use t_ThreadStatics with OFFSETOF__ThreadLocalData__ee_alloc_context; arm/riscv64 call GetThreadEEAllocContext. Builds without FEATURE_MULTITHREADING (wasm) keep the t_runtime_thread_locals thread local. - Thread::m_pRuntimeThreadLocals now points into t_ThreadStatics, so the cDAC Thread/RuntimeThreadLocals data descriptors and contracts are unchanged. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 24, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prototype following the discussion in #138068: allocation fast paths (
NEWSFAST,NEWARR_1_VC/PTR,FastAllocateString) in C# (AllocHelpers.cs), installed as JIT helpers the same way asCastHelpers. Off by default (DOTNET_ManagedAllocHelpers=1), and only used on linux arm64/loongarch64/riscv64 whenCanJITOptimizeTLSAccess()is true, where the managed thread-static access avoids the TLSDESC call the native helpers pay and calls land without jump stubs (#138032). Needs #138068 (bti cresolver fix) on BTI-enabled glibc.The bump and MethodTable store must not be split by a GC: the JIT keeps
AllocHelpersintrinsics partially interruptible (also under JitStress/JitFullyInt), so the fast path has no safepoints.linux-arm64 (Apple M1, Docker), ns per allocation:
The alloc context now lives in
ThreadLocalData(moved out oft_runtime_thread_locals, so libcoreclr's TLS size is unchanged) and the managed fast path reads it with no pointer load. On M1 that is ~8% slower than the earlier version that loaded a cached pointer; the fast path starts withmrs tpidr_el0followed by two unfoldedadds, which still needs a look and a measurement on a Linux arm64 server. The native helpers read the new location with no change in speed. string(8) is slower, likely from theAllocHelpersConfigcheck in the ReadyToRun-compiledStringconstructor; routingFastAllocateStringdirectly (or keeping strings native) would avoid it.Open questions: the ALIGN8, finalizable and ReadyToRun (R2R) helper variants, and loongarch64/riscv64 and arm64 GCStress runs.
🤖 Generated with Claude Code