Skip to content

Separate GC WKS and SVR compilation units#126720

Open
janvorli wants to merge 2 commits intodotnet:mainfrom
janvorli:gc-separate-compilation
Open

Separate GC WKS and SVR compilation units#126720
janvorli wants to merge 2 commits intodotnet:mainfrom
janvorli:gc-separate-compilation

Conversation

@janvorli
Copy link
Copy Markdown
Member

@janvorli janvorli commented Apr 9, 2026

Move the GC sources away from the wrapper-file model that text-included gc.cpp and gcee.cpp under SERVER_GC and instead compile the shared sources directly as separate WKS and SVR objects.

This change introduces gcinternal.h as the shared compilation context for the gc.cpp split, converts the former tail-included GC implementation fragments into separately compiled translation units, and updates the GC, VM, NativeAOT, and GC sample build surfaces to consume the new object layout.

It also removes the gcsvr.cpp/gcwks.cpp and gceesvr.cpp/gceewks.cpp wrappers, compiles gcee.cpp through the same dual-build WKS/SVR source lists as gc.cpp, deduplicates the repeated WKS/SVR source lists in the relevant CMake files, and renames the shared GC header from gc_common.h to gcinternal.h to avoid confusion with gccommon.cpp.

During the split, cross-translation-unit declarations and inline helpers needed by multiple GC source files were moved into the shared header, while local-only inline helpers were moved back into their owning .cpp files to avoid keeping unnecessary bodies in the shared header.

I've made size comparison between the new clrgc.dll, clrgcexp.dll and coreclr.dll and the changes in the gc dlls were very minor, around ~1.5kB growth due to little different decisions of the linker / compiler w.r.t. cold / hot code. The coreclr even became ~1.5kB smaller.

Move the GC sources away from the wrapper-file model that text-included gc.cpp and gcee.cpp under SERVER_GC and instead compile the shared sources directly as separate WKS and SVR objects.

This change introduces gcinternal.h as the shared compilation context for the gc.cpp split, converts the former tail-included GC implementation fragments into separately compiled translation units, and updates the GC, VM, NativeAOT, and GC sample build surfaces to consume the new object layout.

It also removes the gcsvr.cpp/gcwks.cpp and gceesvr.cpp/gceewks.cpp wrappers, compiles gcee.cpp through the same dual-build WKS/SVR source lists as gc.cpp, deduplicates the repeated WKS/SVR source lists in the relevant CMake files, and renames the shared GC header from gc_common.h to gcinternal.h to avoid confusion with gccommon.cpp.

During the split, cross-translation-unit declarations and inline helpers needed by multiple GC source files were moved into the shared header, while local-only inline helpers were moved back into their owning .cpp files to avoid keeping unnecessary bodies in the shared header.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@janvorli janvorli added this to the 11.0.0 milestone Apr 9, 2026
@janvorli janvorli self-assigned this Apr 9, 2026
Copilot AI review requested due to automatic review settings April 9, 2026 16:53
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/gc
See info in area-owners.md if you want to be subscribed.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors CoreCLR GC build plumbing to stop using wrapper translation units (gcwks.cpp/gcsvr.cpp and gceewks.cpp/gceesvr.cpp) and instead compile the shared GC implementation sources directly into separate WKS/SVR object sets, using a new shared compilation-context header gcinternal.h.

Changes:

  • Introduces gcinternal.h and updates many GC .cpp files to include it and wrap code in WKS/SVR namespaces based on SERVER_GC.
  • Updates CoreCLR VM and standalone GC CMake build graphs to build GC sources as object libraries for WKS/SVR and consume them from coreclr/clrgc targets.
  • Updates NativeAOT runtime and the GC sample project build surfaces to consume the new GC source layout.

Reviewed changes

Copilot reviewed 31 out of 33 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coreclr/vm/wks/CMakeLists.txt Adds GC object files into cee_wks_core build inputs.
src/coreclr/vm/CMakeLists.txt Defines shared GC source list and builds vm_gc_wks/vm_gc_svr object libraries.
src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt Links vm_gc_wks/vm_gc_svr into coreclr and coreclr_static.
src/coreclr/nativeaot/Runtime/CMakeLists.txt Replaces wrapper sources with direct GC .cpp compilation for NativeAOT.
src/coreclr/gc/gcinternal.h New shared GC compilation-context header; centralizes includes and inlines.
src/coreclr/gc/*.cpp Switches individual GC implementation files to include gcinternal.h and wrap in WKS/SVR namespaces.
src/coreclr/gc/CMakeLists.txt Builds standalone GC (clrgc/clrgcexp) with WKS/SVR object libraries.
src/coreclr/gc/sample/* Updates GC sample to compile split GC .cpp files directly.

@mangod9
Copy link
Copy Markdown
Member

mangod9 commented Apr 9, 2026

what is the motivation for this change? Does it improve build times?

@janvorli
Copy link
Copy Markdown
Member Author

janvorli commented Apr 9, 2026

what is the motivation for this change? Does it improve build times?

It doesn't affect build time in any way. The main reason is code editing experience. The individual files into which the gc.cpp was split in my recent change didn't include the headers for symbols they use, so when editing one of those e.g. in VS code, it was showing a lot of red squiggles and code navigation didn't work well.

@janvorli janvorli requested review from VSadov and jkotas April 9, 2026 20:43
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