Skip to content

Make ICorProfiler support optional via FEATURE_CORPROFILER#126487

Merged
AaronRobinsonMSFT merged 6 commits intodotnet:mainfrom
AaronRobinsonMSFT:feature/corprofiler-toggle
Apr 3, 2026
Merged

Make ICorProfiler support optional via FEATURE_CORPROFILER#126487
AaronRobinsonMSFT merged 6 commits intodotnet:mainfrom
AaronRobinsonMSFT:feature/corprofiler-toggle

Conversation

@AaronRobinsonMSFT
Copy link
Copy Markdown
Member

Note

This PR description was AI/Copilot-generated.

Summary

Introduce FEATURE_CORPROFILER as a build-level toggle that controls whether PROFILING_SUPPORTED, PROFILING_SUPPORTED_DATA, and FEATURE_PROFAPI_ATTACH_DETACH are defined. On WASM, FEATURE_CORPROFILER is set to 0, disabling ICorProfiler support which is not meaningful on that target.

Changes

Build system

  • clrfeatures.cmake: Define FEATURE_CORPROFILER=1 by default, set to 0 for CLR_CMAKE_TARGET_ARCH_WASM.
  • clrdefinitions.cmake: Gate PROFILING_SUPPORTED, PROFILING_SUPPORTED_DATA, and FEATURE_PROFAPI_ATTACH_DETACH on FEATURE_CORPROFILER. Previously FEATURE_PROFAPI_ATTACH_DETACH was unconditionally defined — this is now correctly co-located.
  • clr.featuredefines.props: Set ProfilingSupportedBuild=false for WASM targets.

VM code (#ifdef PROFILING_SUPPORTED guards)

Added guards around profiling-specific code paths in:

  • asynccontinuations.cpp — class unload notifications
  • ceeload.cpp — profiler type/attribute count fields
  • comdependenthandle.cpp / marshalnative.cpp — GC handle profiler slow-path checks
  • exceptionhandling.cpp — profiler exception notifications
  • gcenv.ee.cpp — finalizable object profiler callback
  • jitinterface.cppCORProfilerTrackTransitions() check (preserving IsILStub() unconditionally for debugger support)
  • prestub.cpp / readytoruninfo.cpp — profiler transition/image checks
  • runtimehandles.cpp — dynamic method unload notifications
  • threads.cpp / threads.h — profiler filter context and callback state fields
  • eetoprofinterfaceimpl.h — entire header guarded

cDAC (data contract)

  • datadescriptor.inc: Conditionally emit ProfControlBlock type, ProfilerFilterContext thread field, ProfilerControlBlock global pointer, and ReJIT contract under #ifdef PROFILING_SUPPORTED.
  • Thread.cs: Use TryGetValue for ProfilerFilterContext (matching existing TEB pattern) to handle the field being absent on non-profiling targets.

Introduce FEATURE_CORPROFILER as a build-level toggle that controls
whether PROFILING_SUPPORTED, PROFILING_SUPPORTED_DATA, and
FEATURE_PROFAPI_ATTACH_DETACH are defined. On WASM, FEATURE_CORPROFILER
is set to 0, disabling ICorProfiler support which is not meaningful on
that target.

Add #ifdef PROFILING_SUPPORTED guards around profiling-specific code
paths in the VM (async continuations, ceeload, dependent handles,
exception handling, GC env, JIT interface, marshaling, prestub,
ReadyToRun, runtime handles, and thread management).

Update the cDAC data descriptor to conditionally emit ProfControlBlock,
ProfilerControlBlock global pointer, ProfilerFilterContext thread field,
and the ReJIT contract. Update the managed cDAC Thread reader to handle
the optional ProfilerFilterContext field gracefully using TryGetValue.

Preserve the IsILStub() check for CORJIT_FLAG_TRACK_TRANSITIONS outside
the profiling guard since it serves debugger functionality independent
of profiling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@AaronRobinsonMSFT AaronRobinsonMSFT added this to the 11.0.0 milestone Apr 2, 2026
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

Introduce a new build-time feature switch (FEATURE_CORPROFILER) to make ICorProfiler support optional (disabled on WASM), and tighten #ifdef PROFILING_SUPPORTED* guards so profiling-specific code and cDAC metadata are only emitted when profiling is enabled.

Changes:

  • Add FEATURE_CORPROFILER and gate PROFILING_SUPPORTED, PROFILING_SUPPORTED_DATA, and FEATURE_PROFAPI_ATTACH_DETACH on it (with WASM disabling profiling).
  • Wrap profiling-only VM behavior (callbacks, transition checks, counters/fields) in #ifdef PROFILING_SUPPORTED (or related) guards to allow non-profiling builds.
  • Make cDAC contracts resilient to missing profiling fields/globals (e.g., Thread.ProfilerFilterContext) by conditionally emitting metadata and reading fields opportunistically.

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs Treat ProfilerFilterContext as optional using TryGetValue and default to null when absent.
src/coreclr/vm/threads.h Gate profiler-only thread fields/methods and conditionally expose cDAC offset for ProfilerFilterContext.
src/coreclr/vm/threads.cpp Initialize profiler-related thread state only when profiling is supported.
src/coreclr/vm/runtimehandles.cpp Guard dynamic method unload profiler callback behind PROFILING_SUPPORTED.
src/coreclr/vm/readytoruninfo.cpp Guard profiler-driven R2R disabling checks behind PROFILING_SUPPORTED.
src/coreclr/vm/prestub.cpp Guard CORProfilerTrackTransitions() check behind PROFILING_SUPPORTED.
src/coreclr/vm/marshalnative.cpp Guard GCHandle slow-path profiler checks behind PROFILING_SUPPORTED.
src/coreclr/vm/jitinterface.cpp Preserve debugger IsILStub() behavior while guarding profiler transition checks.
src/coreclr/vm/gcenv.ee.cpp Guard finalizable object profiler callback behind PROFILING_SUPPORTED.
src/coreclr/vm/exceptionhandling.cpp Guard exception-related profiler callbacks behind PROFILING_SUPPORTED and clean up whitespace.
src/coreclr/vm/eetoprofinterfaceimpl.h Guard the header contents behind PROFILING_SUPPORTED / PROFILING_SUPPORTED_DATA.
src/coreclr/vm/datadescriptor/datadescriptor.inc Conditionally emit profiling-related cDAC types/fields/globals/contracts.
src/coreclr/vm/comdependenthandle.cpp Guard dependent handle slow-path profiler checks behind PROFILING_SUPPORTED.
src/coreclr/vm/ceeload.cpp Guard profiler type/attribute count initialization behind PROFILING_SUPPORTED_DATA.
src/coreclr/vm/asynccontinuations.cpp Guard class unload notifications behind PROFILING_SUPPORTED.
src/coreclr/inc/dacvars.h Expose g_profControlBlock to DAC when profiling and/or code versioning is enabled.
src/coreclr/clrfeatures.cmake Define FEATURE_CORPROFILER default and disable it for WASM.
src/coreclr/clrdefinitions.cmake Gate profiling-related compile definitions on FEATURE_CORPROFILER.
src/coreclr/clr.featuredefines.props Disable ProfilingSupportedBuild for WASM builds.

@max-charlamb
Copy link
Copy Markdown
Member

Looks good from cDAC perspective.

Copy link
Copy Markdown
Member

@noahfalk noahfalk left a comment

Choose a reason for hiding this comment

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

LGTM - agree with Jan that we should try to avoid that "|| FEATURE_CODE_VERSIONING". If the CODE_VERSIONING has profiler dependencies I'd try to snip them off within the code versioning impl instead of including the global profiler control block.

Copilot AI review requested due to automatic review settings April 2, 2026 22:36
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

Copilot reviewed 18 out of 18 changed files in this pull request and generated 2 comments.

@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) April 3, 2026 04:48
Copilot AI review requested due to automatic review settings April 3, 2026 18:14
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

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

Add a unit test that builds a Thread type descriptor without the
ProfilerFilterContext field and verifies the reader gracefully returns
TargetPointer.Null. This covers the TryGetValue fallback path in
Data.Thread for non-profiling targets (e.g., WASM).

The MockDescriptors.Thread class now accepts a hasProfilingSupport
parameter to control whether ProfilerFilterContext is included in the
type descriptor.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@AaronRobinsonMSFT AaronRobinsonMSFT merged commit 4b43fd3 into dotnet:main Apr 3, 2026
120 checks passed
@github-project-automation github-project-automation bot moved this to Done in AppModel Apr 3, 2026
@AaronRobinsonMSFT AaronRobinsonMSFT deleted the feature/corprofiler-toggle branch April 4, 2026 02:52
radekdoulik pushed a commit to radekdoulik/runtime that referenced this pull request Apr 9, 2026
…6487)

## Summary

Introduce `FEATURE_CORPROFILER` as a build-level toggle that controls
whether `PROFILING_SUPPORTED`, `PROFILING_SUPPORTED_DATA`, and
`FEATURE_PROFAPI_ATTACH_DETACH` are defined. On WASM,
`FEATURE_CORPROFILER` is set to 0, disabling ICorProfiler support which
is not meaningful on that target.

## Changes

### Build system
- **`clrfeatures.cmake`**: Define `FEATURE_CORPROFILER=1` by default,
set to 0 for `CLR_CMAKE_TARGET_ARCH_WASM`.
- **`clrdefinitions.cmake`**: Gate `PROFILING_SUPPORTED`,
`PROFILING_SUPPORTED_DATA`, and `FEATURE_PROFAPI_ATTACH_DETACH` on
`FEATURE_CORPROFILER`. Previously `FEATURE_PROFAPI_ATTACH_DETACH` was
unconditionally defined — this is now correctly co-located.
- **`clr.featuredefines.props`**: Set `ProfilingSupportedBuild=false`
for WASM targets.

### VM code (`#ifdef PROFILING_SUPPORTED` guards)
Added guards around profiling-specific code paths in:
- `asynccontinuations.cpp` — class unload notifications
- `ceeload.cpp` — profiler type/attribute count fields
- `comdependenthandle.cpp` / `marshalnative.cpp` — GC handle profiler
slow-path checks
- `exceptionhandling.cpp` — profiler exception notifications
- `gcenv.ee.cpp` — finalizable object profiler callback
- `jitinterface.cpp` — `CORProfilerTrackTransitions()` check (preserving
`IsILStub()` unconditionally for debugger support)
- `prestub.cpp` / `readytoruninfo.cpp` — profiler transition/image
checks
- `runtimehandles.cpp` — dynamic method unload notifications
- `threads.cpp` / `threads.h` — profiler filter context and callback
state fields
- `eetoprofinterfaceimpl.h` — entire header guarded

### cDAC (data contract)
- `datadescriptor.inc`: Conditionally emit `ProfControlBlock` type,
`ProfilerFilterContext` thread field, `ProfilerControlBlock` global
pointer, and `ReJIT` contract under `#ifdef PROFILING_SUPPORTED`.
- `Thread.cs`: Use `TryGetValue` for `ProfilerFilterContext` (matching
existing `TEB` pattern) to handle the field being absent on
non-profiling targets.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
steveisok added a commit to steveisok/runtime that referenced this pull request Apr 9, 2026
…_CORPROFILER

PR dotnet#126487 disabled FEATURE_CORPROFILER for tvOS, which removes profiler
fields from the Thread struct (m_pProfilerFilterContext,
m_profilerCallbackState, m_dwProfilerEvacuationCounters). This shifts
m_pInterpThreadContext to a lower offset, but asmconstants.h was not
updated to account for the missing 144 bytes of profiler data.

Add PROFILING_SUPPORTED/PROFILING_SUPPORTED_DATA conditionals to select
the correct offset (0x228 for Release, 0xa90 for Debug) when profiling
is disabled.

Fixes internal unified-build failures on tvOS legs (tvOS_Shortstack_arm64,
tvOSSimulator_Shortstack_x64, tvOSSimulator_Shortstack_arm64) on main.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
kotlarmilos added a commit to kotlarmilos/runtime that referenced this pull request Apr 10, 2026
- Widen the preprocessor guard on m_dwTypeCount, m_dwExportedTypeCount,
  and m_dwCustomAttributeCount from PROFILING_SUPPORTED_DATA to
  PROFILING_SUPPORTED_DATA || FEATURE_METADATA_UPDATER in both ceeload.h
  (declaration) and ceeload.cpp (initialization). PR dotnet#126487 made these
  fields conditional on PROFILING_SUPPORTED_DATA, but
  UpdateNewlyAddedTypes() is guarded by PROFILING_SUPPORTED ||
  FEATURE_METADATA_UPDATER. When profiling is disabled (e.g., Apple
  mobile platforms with FEATURE_CORPROFILER off), the function compiles
  but the fields do not exist, causing build failures.

- Restore ios_arm64 (device) platform for the three iOS smoke test jobs
  in runtime.yml (Mono AOT, NativeAOT, CoreCLR), replacing the
  iossimulator_arm64 workaround from PR dotnet#126406.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants