Make ICorProfiler support optional via FEATURE_CORPROFILER#126487
Make ICorProfiler support optional via FEATURE_CORPROFILER#126487AaronRobinsonMSFT merged 6 commits intodotnet:mainfrom
Conversation
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>
|
Tagging subscribers to this area: @agocke |
There was a problem hiding this comment.
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_CORPROFILERand gatePROFILING_SUPPORTED,PROFILING_SUPPORTED_DATA, andFEATURE_PROFAPI_ATTACH_DETACHon 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. |
|
Looks good from cDAC perspective. |
noahfalk
left a comment
There was a problem hiding this comment.
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.
…iptors and JIT interface
src/native/managed/cdac/Microsoft.Diagnostics.DataContractReader.Contracts/Data/Thread.cs
Show resolved
Hide resolved
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>
…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>
…_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>
- 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>
Note
This PR description was AI/Copilot-generated.
Summary
Introduce
FEATURE_CORPROFILERas a build-level toggle that controls whetherPROFILING_SUPPORTED,PROFILING_SUPPORTED_DATA, andFEATURE_PROFAPI_ATTACH_DETACHare defined. On WASM,FEATURE_CORPROFILERis set to 0, disabling ICorProfiler support which is not meaningful on that target.Changes
Build system
clrfeatures.cmake: DefineFEATURE_CORPROFILER=1by default, set to 0 forCLR_CMAKE_TARGET_ARCH_WASM.clrdefinitions.cmake: GatePROFILING_SUPPORTED,PROFILING_SUPPORTED_DATA, andFEATURE_PROFAPI_ATTACH_DETACHonFEATURE_CORPROFILER. PreviouslyFEATURE_PROFAPI_ATTACH_DETACHwas unconditionally defined — this is now correctly co-located.clr.featuredefines.props: SetProfilingSupportedBuild=falsefor WASM targets.VM code (
#ifdef PROFILING_SUPPORTEDguards)Added guards around profiling-specific code paths in:
asynccontinuations.cpp— class unload notificationsceeload.cpp— profiler type/attribute count fieldscomdependenthandle.cpp/marshalnative.cpp— GC handle profiler slow-path checksexceptionhandling.cpp— profiler exception notificationsgcenv.ee.cpp— finalizable object profiler callbackjitinterface.cpp—CORProfilerTrackTransitions()check (preservingIsILStub()unconditionally for debugger support)prestub.cpp/readytoruninfo.cpp— profiler transition/image checksruntimehandles.cpp— dynamic method unload notificationsthreads.cpp/threads.h— profiler filter context and callback state fieldseetoprofinterfaceimpl.h— entire header guardedcDAC (data contract)
datadescriptor.inc: Conditionally emitProfControlBlocktype,ProfilerFilterContextthread field,ProfilerControlBlockglobal pointer, andReJITcontract under#ifdef PROFILING_SUPPORTED.Thread.cs: UseTryGetValueforProfilerFilterContext(matching existingTEBpattern) to handle the field being absent on non-profiling targets.