Skip to content

Use direct VM callbacks for interpreter-only CoreCLR builds - #137398

Merged
davidwrighton merged 3 commits into
dotnet:mainfrom
davidwrighton:RemoveJitInterfaceAbstractionOnInterpreterPlatforms
Nov 18, 2026
Merged

davidwrighton merged 3 commits into
dotnet:mainfrom
davidwrighton:RemoveJitInterfaceAbstractionOnInterpreterPlatforms

Conversation

@davidwrighton

Copy link
Copy Markdown
Member

Summary

Use direct interpreter-to-VM calls when FEATURE_INTERPRETER is enabled and FEATURE_DYNAMIC_CODE_COMPILED is disabled, including interpreter-only Wasm and Apple configurations. Preserve the existing virtual callback interfaces on JIT-capable builds.

  • Make the ICorStaticInfo / ICorDynamicInfo / ICorJitInfo callback hierarchy and its VM implementations nonvirtual in interpreter-only runtime builds.
  • Select concrete CInterpreterJitInfo handles for the interpreter compiler and runtime GC encoder, without forwarding stubs.
  • Preserve specialized VM dispatch for code publication and debug-info storage; pass existing interface default arguments explicitly at concrete call sites.
  • Scope the build integration to runtime consumers, retain virtual interfaces for tool encoders, and regenerate the callback declarations and JIT-EE GUID.
  • Add compile-time guards for nonpolymorphism in direct mode and polymorphism in the normal configuration.

ICorJitCompiler, ICorJitHost, and unrelated runtime virtual interfaces remain unchanged. The GC encoder slot descriptor is renamed to avoid a collision with the decoder when including the VM headers.

Related to the callback-overhead discussion in #6751; this PR does not attempt to close that broader issue.

Size measurements

Matching browser-wasm Release builds, based on d990730ba1ca5e163fa067ae40c4a2ff9114c9f2, with identical link flags:

corerun.wasm Before After Reduction
Raw 4,406,307 bytes 4,340,440 bytes 65,867 bytes (1.49%)
Brotli 1,318,484 bytes 1,303,398 bytes 15,086 bytes (1.14%)

Brotli 1.1.0, quality 11, window 22, generic mode; decompression round trips verified. Neither image contains custom/debug sections. The changed image has 168 fewer defined functions. A linker-map relink produces byte-identical Wasm and retains no CEEJitInfo functions.

These are binary-size measurements, not startup or compilation-throughput measurements.

Validation

Passed:

./build.sh clr+libs+host
bash src/coreclr/tools/Common/JitInterface/ThunkGenerator/gen.sh
src/coreclr/build-runtime.sh -x64 -debug -subdir directcalls \
  -component runtime -component hosts \
  -cmakeargs '-DFEATURE_INTERPRETER=1 -DFEATURE_DYNAMIC_CODE_COMPILED=0'
src/coreclr/build-runtime.sh -x64 -debug \
  -component runtime -component jit -component spmi -component hosts \
  -cmakeargs '-DFEATURE_INTERPRETER=1 -DFEATURE_DYNAMIC_CODE_COMPILED=1'
src/tests/build.sh -Dir JIT/CodeGenBringUpTests x64 Debug /p:LibrariesConfiguration=Debug
./build.sh -os browser -arch wasm -c Release -subset clr.runtime+clr.hosts
git diff --check

The four JIT.CodeGenBringUpTests_{d,do,r,ro}.dll runners each returned the expected exit code 100 on both the interpreter-only runtime and the JIT-capable runtime with DOTNET_InterpMode=3 (eight successful runner invocations). The final interpreter-only native build and all eight invocations were repeated before committing.

Native object relocations show direct calls to concrete VM metadata callbacks. Expanding the conditional qualifiers in the normal configuration reproduces the original callback interface and generated declarations exactly.

Not run locally: Apple/iOS/MacCatalyst/tvOS or WASI builds, Wasm managed test execution, dedicated async/calli/EH suites, or startup/compilation-throughput benchmarks. Apple validation requires an Apple host.

Note

This PR description and the code changes were generated with GitHub Copilot.

Select concrete interpreter callback types and remove callback virtual methods in interpreter-only runtime builds while preserving the virtual interfaces for JIT-capable builds and tools.

Co-authored-by: Copilot <[email protected]>

Copilot-Session: 0450a1a5-696d-455f-8288-4924e23b62d7
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging @dotnet/jit-contrib for JIT-EE GUID update

@azure-pipelines

Copy link
Copy Markdown
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.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @BrzVlad, @janvorli
See info in area-owners.md if you want to be subscribed.

@davidwrighton
davidwrighton marked this pull request as ready for review November 12, 2026 17:53
@davidwrighton
davidwrighton requested review from jkoritzinsky and a balanced review from Copilot November 12, 2026 17:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The cross-target callback ABI and GC/debug/EH dispatch changes require runtime-owner review and platform-specific validation, with Apple/WASI builds, managed Wasm execution, and dedicated async/calli/EH suites absent from the reported checks.

No open issues 🎉

What changed in this PR

This PR enables direct interpreter-to-VM callbacks in interpreter-only CoreCLR builds while retaining virtual callbacks for JIT-capable builds and tool consumers. It targets reduced binary size without changing unrelated runtime interfaces.

Changes:

  • Make callback declarations conditionally nonvirtual and use concrete interpreter callback handles.
  • Preserve specialized code-publication and debug-info dispatch, with compile-time checks for both configurations.
  • Update build integration, generated declarations, and the JIT-EE GUID; rename GC encoder slot types to avoid a header collision.
File Description
src/​coreclr/​vm/​jitinterface.h Apply conditional virtual qualifiers to VM callbacks.
src/​coreclr/​vm/​jitinterface.cpp Select concrete dispatch and assert expected polymorphism.
src/​coreclr/​vm/​common.h Enable direct calls for interpreter-only runtime builds.
src/​coreclr/​tools/​Common/​JitInterface/​ThunkGenerator/​Program.cs Generate conditional override qualifiers.
src/​coreclr/​interpreter/​stackmap.h Use configuration-dependent callback handles.
src/​coreclr/​interpreter/​stackmap.cpp Adapt stack-map callbacks and include ordering.
src/​coreclr/​interpreter/​interpreter.h Include VM definitions in direct-call mode.
src/​coreclr/​interpreter/​inc/​interpretershared.h Select the concrete interpreter handle type.
src/​coreclr/​interpreter/​eeinterp.cpp Convert incoming callbacks to the concrete handle.
src/​coreclr/​interpreter/​compileropt.cpp Pass alignment callback defaults explicitly.
src/​coreclr/​interpreter/​compiler.cpp Adapt callback handles, arguments, and includes.
src/​coreclr/​interpreter/​CMakeLists.txt Configure direct-call dependencies and static linking.
src/​coreclr/​inc/​jiteeversionguid.h Refresh the JIT-EE interface identifier.
src/​coreclr/​inc/​icorjitinfoimpl_generated.h Regenerate conditional callback declarations.
src/​coreclr/​inc/​gcinfoencoder.h Select callback types and rename encoder slot descriptors.
src/​coreclr/​inc/​corjit.h Make JIT callback virtual qualifiers conditional.
src/​coreclr/​inc/​corinfo.h Define conditional qualifiers for metadata callbacks.
src/​coreclr/​gcinfo/​gcinfoencoder.cpp Adapt encoder callbacks and renamed slot types.
src/​coreclr/​gcinfo/​CMakeLists.txt Scope direct-call encoder integration to runtime builds.

Review effort: Balanced

@jkoritzinsky jkoritzinsky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One comment on the infra side of things.

The implementation looks good, but this is just as horrifying as it was when we talked about it before. Effective though, so LGTM!

Comment thread src/coreclr/vm/common.h Resolved
davidwrighton and others added 2 commits November 18, 2026 00:28
Compute FEATURE_INTERPRETER_DIRECT_CALLS in clrfeatures.cmake and define it
globally from clrdefinitions.cmake, instead of deriving it in vm/common.h and
separately defining it for the gcinfo and interpreter targets. JITs, the
cross-target gcinfo encoders, and SuperPMI keep the virtual ICorJitInfo
interface by opting out through the IGNORE_FEATURE_INTERPRETER_DIRECT_CALLS
target property.

Co-authored-by: Copilot <[email protected]>
@davidwrighton
davidwrighton merged commit c94cc27 into dotnet:main Nov 18, 2026
114 of 116 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants