-
Notifications
You must be signed in to change notification settings - Fork 5.4k
[NativeAOT] Add cDAC data descriptor infrastructure #126972
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
max-charlamb
wants to merge
8
commits into
main
Choose a base branch
from
dev/max-charlamb/managed-type-descriptors
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de1cecb
[NativeAOT] Add cDAC data descriptor infrastructure
max-charlamb f226bc3
[NativeAOT] Add managed type sub-descriptor for cDAC
max-charlamb 52a7ae1
Address PR review feedback
max-charlamb c237caf
Enable cdac-build-tool for NativeAOT builds
max-charlamb 11fb743
Address round 2 review feedback
max-charlamb 0d15346
Move ThreadStore pointer to static member matching CoreCLR
max-charlamb 13b9320
Move datadescriptor after eventpipe in CMake ordering
max-charlamb 656e2c7
Use SKIP_TRACING_DEFINITIONS for datadescriptor build
max-charlamb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
46 changes: 46 additions & 0 deletions
46
src/coreclr/nativeaot/Runtime/datadescriptor/CMakeLists.txt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| set(CMAKE_INCLUDE_CURRENT_DIR OFF) | ||
|
|
||
| # cDAC contract descriptor for NativeAOT | ||
| # | ||
| # This uses the shared datadescriptor infrastructure from | ||
| # src/coreclr/debug/datadescriptor-shared/ to generate a | ||
| # DotNetRuntimeContractDescriptor symbol in the NativeAOT runtime. | ||
| # | ||
| # Include directories and compile definitions are inherited from the parent | ||
| # Runtime/CMakeLists.txt directory scope. The interface targets below only | ||
| # need to add the datadescriptor-specific include path. | ||
|
|
||
| include(${CLR_DIR}/clrdatadescriptors.cmake) | ||
|
|
||
| add_library(nativeaot_descriptor_interface INTERFACE) | ||
| target_include_directories(nativeaot_descriptor_interface INTERFACE | ||
| ${CMAKE_CURRENT_SOURCE_DIR}) | ||
| target_compile_definitions(nativeaot_descriptor_interface INTERFACE SKIP_TRACING_DEFINITIONS) | ||
| generate_data_descriptors( | ||
| LIBRARY_NAME nativeaot_cdac_contract_descriptor | ||
| CONTRACT_NAME "DotNetRuntimeContractDescriptor" | ||
| INTERFACE_TARGET nativeaot_descriptor_interface | ||
| EXPORT_VISIBLE) | ||
|
|
||
| # GC contract descriptors (workstation + server). | ||
| # The GC has its own data descriptor exposed as a sub-descriptor via gc_descriptor in GcDacVars. | ||
| set(GC_DESCRIPTOR_DIR "${CLR_DIR}/gc/datadescriptor") | ||
|
|
||
| add_library(nativeaot_gc_wks_descriptor_interface INTERFACE) | ||
| target_include_directories(nativeaot_gc_wks_descriptor_interface INTERFACE | ||
| ${GC_DESCRIPTOR_DIR} | ||
| ${GC_DIR}) | ||
| generate_data_descriptors( | ||
|
max-charlamb marked this conversation as resolved.
|
||
| LIBRARY_NAME nativeaot_gc_wks_descriptor | ||
| CONTRACT_NAME "GCContractDescriptorWKS" | ||
| INTERFACE_TARGET nativeaot_gc_wks_descriptor_interface) | ||
|
|
||
| add_library(nativeaot_gc_svr_descriptor_interface INTERFACE) | ||
| target_include_directories(nativeaot_gc_svr_descriptor_interface INTERFACE | ||
| ${GC_DESCRIPTOR_DIR} | ||
| ${GC_DIR}) | ||
| target_compile_definitions(nativeaot_gc_svr_descriptor_interface INTERFACE -DSERVER_GC) | ||
|
max-charlamb marked this conversation as resolved.
|
||
| generate_data_descriptors( | ||
| LIBRARY_NAME nativeaot_gc_svr_descriptor | ||
| CONTRACT_NAME "GCContractDescriptorSVR" | ||
| INTERFACE_TARGET nativeaot_gc_svr_descriptor_interface) | ||
36 changes: 36 additions & 0 deletions
36
src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.h
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // This header provides the includes needed for datadescriptor.inc to use | ||
| // offsetof() on NativeAOT runtime data structures. | ||
| // | ||
| // Note: Some NativeAOT types have private members that offsetof() cannot access | ||
| // from this compilation unit. For those types, we use known offset constants | ||
| // validated at build time by AsmOffsetsVerify.cpp and DebugHeader.cpp static_asserts. | ||
|
|
||
| #include "common.h" | ||
| #include "gcenv.h" | ||
| #include "gcheaputilities.h" | ||
| #include "gcinterface.dac.h" | ||
| #include "rhassert.h" | ||
| #include "TargetPtrs.h" | ||
| #include "PalLimitedContext.h" | ||
| #include "Pal.h" | ||
| #include "holder.h" | ||
| #include "RuntimeInstance.h" | ||
| #include "regdisplay.h" | ||
| #include "StackFrameIterator.h" | ||
| #include "thread.h" | ||
| #include "threadstore.h" | ||
|
|
||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
|
|
||
| GPTR_DECL(MethodTable, g_pFreeObjectEEType); | ||
|
|
||
| // ILC emits a ContractDescriptor named "DotNetManagedContractDescriptor" with | ||
| // managed type layouts. We take its address so datadescriptor.inc can reference | ||
| // it as a sub-descriptor via CDAC_GLOBAL_SUB_DESCRIPTOR. | ||
| struct ContractDescriptor; | ||
| extern "C" ContractDescriptor DotNetManagedContractDescriptor; | ||
| static const void* g_pManagedContractDescriptor = &DotNetManagedContractDescriptor; |
137 changes: 137 additions & 0 deletions
137
src/coreclr/nativeaot/Runtime/datadescriptor/datadescriptor.inc
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // | ||
| // No include guards. This file is included multiple times. | ||
| // | ||
| // NativeAOT data descriptor declarations for the cDAC contract system. | ||
| // This file defines the types, fields, and globals that diagnostic tools | ||
| // need to inspect NativeAOT runtime state. | ||
| // | ||
| // When modifying this file (adding/removing types, fields, or globals), you must also: | ||
| // 1. Update the corresponding contract doc in docs/design/datacontracts/<contract>.md | ||
| // 2. Update the managed data class in src/native/managed/cdac/.../Data/<Type>.cs | ||
| // 3. Update the contract implementation in src/native/managed/cdac/.../Contracts/<Contract>.cs | ||
| // 4. Update the mock descriptors and tests in src/native/managed/cdac/tests/. | ||
|
|
||
| CDAC_BASELINE("empty") | ||
| CDAC_TYPES_BEGIN() | ||
|
|
||
| // ======================== | ||
| // Thread and ThreadStore | ||
| // ======================== | ||
|
|
||
| CDAC_TYPE_BEGIN(Thread) | ||
| CDAC_TYPE_INDETERMINATE(Thread) | ||
| CDAC_TYPE_FIELD(Thread, T_UINT64, OSId, offsetof(RuntimeThreadLocals, m_threadId)) | ||
| CDAC_TYPE_FIELD(Thread, T_UINT32, State, offsetof(RuntimeThreadLocals, m_ThreadStateFlags)) | ||
| CDAC_TYPE_FIELD(Thread, T_POINTER, LinkNext, offsetof(RuntimeThreadLocals, m_pNext)) | ||
| CDAC_TYPE_FIELD(Thread, T_POINTER, ExceptionTracker, offsetof(RuntimeThreadLocals, m_pExInfoStackHead)) | ||
| CDAC_TYPE_FIELD(Thread, T_POINTER, CachedStackBase, offsetof(RuntimeThreadLocals, m_pStackHigh)) | ||
| CDAC_TYPE_FIELD(Thread, T_POINTER, CachedStackLimit, offsetof(RuntimeThreadLocals, m_pStackLow)) | ||
| CDAC_TYPE_FIELD(Thread, TYPE(RuntimeThreadLocals), RuntimeThreadLocals, offsetof(RuntimeThreadLocals, m_eeAllocContext)) | ||
| CDAC_TYPE_FIELD(Thread, T_POINTER, TransitionFrame, offsetof(RuntimeThreadLocals, m_pTransitionFrame)) | ||
| CDAC_TYPE_END(Thread) | ||
|
|
||
| CDAC_TYPE_BEGIN(ThreadStore) | ||
| CDAC_TYPE_INDETERMINATE(ThreadStore) | ||
| CDAC_TYPE_FIELD(ThreadStore, T_POINTER, FirstThreadLink, cdac_data<ThreadStore>::FirstThreadLink) | ||
| CDAC_TYPE_END(ThreadStore) | ||
|
|
||
| CDAC_TYPE_BEGIN(RuntimeThreadLocals) | ||
| CDAC_TYPE_INDETERMINATE(RuntimeThreadLocals) | ||
| CDAC_TYPE_FIELD(RuntimeThreadLocals, TYPE(EEAllocContext), AllocContext, offsetof(RuntimeThreadLocals, m_eeAllocContext)) | ||
| CDAC_TYPE_END(RuntimeThreadLocals) | ||
|
|
||
| // ======================== | ||
| // Allocation Context | ||
| // ======================== | ||
|
|
||
| CDAC_TYPE_BEGIN(EEAllocContext) | ||
| CDAC_TYPE_INDETERMINATE(EEAllocContext) | ||
| CDAC_TYPE_FIELD(EEAllocContext, TYPE(GCAllocContext), GCAllocationContext, offsetof(ee_alloc_context, m_rgbAllocContextBuffer)) | ||
| CDAC_TYPE_END(EEAllocContext) | ||
|
|
||
| CDAC_TYPE_BEGIN(GCAllocContext) | ||
| CDAC_TYPE_INDETERMINATE(GCAllocContext) | ||
| CDAC_TYPE_FIELD(GCAllocContext, T_POINTER, Pointer, offsetof(gc_alloc_context, alloc_ptr)) | ||
| CDAC_TYPE_FIELD(GCAllocContext, T_POINTER, Limit, offsetof(gc_alloc_context, alloc_limit)) | ||
| CDAC_TYPE_FIELD(GCAllocContext, T_INT64, AllocBytes, offsetof(gc_alloc_context, alloc_bytes)) | ||
| CDAC_TYPE_FIELD(GCAllocContext, T_INT64, AllocBytesLoh, offsetof(gc_alloc_context, alloc_bytes_uoh)) | ||
| CDAC_TYPE_END(GCAllocContext) | ||
|
|
||
| // ======================== | ||
| // MethodTable (EEType) | ||
| // ======================== | ||
|
|
||
| CDAC_TYPE_BEGIN(MethodTable) | ||
| CDAC_TYPE_INDETERMINATE(MethodTable) | ||
| CDAC_TYPE_FIELD(MethodTable, T_UINT32, Flags, cdac_data<MethodTable>::Flags) | ||
| CDAC_TYPE_FIELD(MethodTable, T_UINT32, BaseSize, cdac_data<MethodTable>::BaseSize) | ||
| CDAC_TYPE_FIELD(MethodTable, T_POINTER, RelatedType, cdac_data<MethodTable>::RelatedType) | ||
| CDAC_TYPE_FIELD(MethodTable, T_UINT16, NumVtableSlots, cdac_data<MethodTable>::NumVtableSlots) | ||
| CDAC_TYPE_FIELD(MethodTable, T_UINT16, NumInterfaces, cdac_data<MethodTable>::NumInterfaces) | ||
| CDAC_TYPE_FIELD(MethodTable, T_UINT32, HashCode, cdac_data<MethodTable>::HashCode) | ||
| CDAC_TYPE_FIELD(MethodTable, T_POINTER, VTable, cdac_data<MethodTable>::VTable) | ||
| CDAC_TYPE_END(MethodTable) | ||
|
|
||
| // ======================== | ||
| // Exception Info | ||
| // ======================== | ||
|
|
||
| CDAC_TYPE_BEGIN(ExInfo) | ||
| CDAC_TYPE_INDETERMINATE(ExInfo) | ||
| CDAC_TYPE_FIELD(ExInfo, T_POINTER, PreviousNestedInfo, offsetof(ExInfo, m_pPrevExInfo)) | ||
| CDAC_TYPE_FIELD(ExInfo, T_POINTER, ThrownObject, offsetof(ExInfo, m_exception)) | ||
| CDAC_TYPE_END(ExInfo) | ||
|
|
||
| CDAC_TYPES_END() | ||
|
|
||
| // ======================== | ||
| // Globals | ||
| // ======================== | ||
|
|
||
| CDAC_GLOBALS_BEGIN() | ||
|
|
||
| CDAC_GLOBAL_POINTER(ThreadStore, &ThreadStore::s_pThreadStore) | ||
|
|
||
| CDAC_GLOBAL_POINTER(FreeObjectMethodTable, &g_pFreeObjectEEType) | ||
|
|
||
| CDAC_GLOBAL_POINTER(GCLowestAddress, &g_lowest_address) | ||
| CDAC_GLOBAL_POINTER(GCHighestAddress, &g_highest_address) | ||
|
|
||
| // NativeAOT MethodTable flag constants (accessed via cdac_data friend) | ||
| CDAC_GLOBAL(MethodTableEETypeKindMask, uint32, cdac_data<MethodTable>::EETypeKindMask) | ||
| CDAC_GLOBAL(MethodTableHasComponentSizeFlag, uint32, cdac_data<MethodTable>::HasComponentSizeFlag) | ||
| CDAC_GLOBAL(MethodTableHasFinalizerFlag, uint32, cdac_data<MethodTable>::HasFinalizerFlag) | ||
| CDAC_GLOBAL(MethodTableHasPointersFlag, uint32, cdac_data<MethodTable>::HasPointersFlag) | ||
| CDAC_GLOBAL(MethodTableIsGenericFlag, uint32, cdac_data<MethodTable>::IsGenericFlag) | ||
| CDAC_GLOBAL(MethodTableElementTypeMask, uint32, cdac_data<MethodTable>::ElementTypeMask) | ||
| CDAC_GLOBAL(MethodTableElementTypeShift, uint32, cdac_data<MethodTable>::ElementTypeShift) | ||
|
|
||
| // Thread state flag constants | ||
| CDAC_GLOBAL(ThreadStateFlagAttached, uint32, 0x00000001) | ||
| CDAC_GLOBAL(ThreadStateFlagDetached, uint32, 0x00000002) | ||
|
|
||
| // Object contract globals | ||
| #ifdef TARGET_64BIT | ||
| CDAC_GLOBAL(ObjectToMethodTableUnmask, uint8, 7) | ||
| #else | ||
| CDAC_GLOBAL(ObjectToMethodTableUnmask, uint8, 3) | ||
| #endif | ||
|
|
||
| // Contracts: declare which contracts this runtime supports | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add stresslog here as well (without the module table). It can use the same contract version as CoreCLR. |
||
| CDAC_GLOBAL_CONTRACT(Thread, 1001) | ||
| CDAC_GLOBAL_CONTRACT(Exception, 1) | ||
| CDAC_GLOBAL_CONTRACT(RuntimeTypeSystem, 1001) | ||
|
|
||
| // Managed type sub-descriptor: ILC emits a ContractDescriptor with managed type layouts | ||
| // that the cDAC reader merges as a sub-descriptor. This provides field offsets for managed | ||
| // types (e.g., ConditionalWeakTable internals, IdDispenser) that are not exposed through | ||
| // native C++ data descriptors. | ||
| CDAC_GLOBAL_SUB_DESCRIPTOR(ManagedTypes, &g_pManagedContractDescriptor) | ||
|
|
||
|
max-charlamb marked this conversation as resolved.
|
||
| // GC sub-descriptor: the GC populates gc_descriptor during GC_Initialize. | ||
| // It is important for subdescriptor pointers to be the last pointers. | ||
| CDAC_GLOBAL_SUB_DESCRIPTOR(GC, &(g_gc_dac_vars.gc_descriptor)) | ||
|
|
||
| CDAC_GLOBALS_END() | ||
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
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
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
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
15 changes: 15 additions & 0 deletions
15
...ativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/CdacFieldAttribute.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Runtime.CompilerServices | ||
| { | ||
| /// <summary> | ||
| /// When applied to an instance field of a type annotated with <see cref="CdacTypeAttribute"/>, | ||
| /// indicates that ILC should include this field in the managed cDAC data descriptor. | ||
| /// The field's actual declared name is used in the descriptor. | ||
| /// </summary> | ||
| [AttributeUsage(AttributeTargets.Field, Inherited = false)] | ||
| internal sealed class CdacFieldAttribute : Attribute | ||
| { | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
...nativeaot/System.Private.CoreLib/src/System/Runtime/CompilerServices/CdacTypeAttribute.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace System.Runtime.CompilerServices | ||
| { | ||
| /// <summary> | ||
| /// When applied to a type, indicates that ILC should include its field layout in the | ||
| /// managed cDAC data descriptor. The cDAC reader merges this information as a | ||
| /// sub-descriptor so diagnostic tools can inspect managed type instances without | ||
| /// runtime metadata (critical for NativeAOT where metadata may be stripped). | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// Fields to include must be individually annotated with <see cref="CdacFieldAttribute"/>. | ||
| /// The type and field names used in the descriptor match the actual managed names. | ||
| /// </remarks> | ||
| [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, Inherited = false)] | ||
| internal sealed class CdacTypeAttribute : Attribute | ||
| { | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the relationship between
DotNetRuntimeDebugHeaderandDotNetRuntimeContractDescriptor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DotNetRuntimeDebugHeaderexport exposes a set of offsets that the current NativeAOT SOS uses to implement some commands ad-hoc.The
DotNetRuntimeContractDescriptoris the cDAC contract blob, similar to CoreCLR builds. Once the cDAC NAOT infrastructure is in place and working, the legacyDotNetRuntimeDebugHeaderexport and blob will be removed.