Skip to content
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

[cdac] GetMethodDescData for jitted methods #109187

Merged
merged 295 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
295 commits
Select commit Hold shift + click to select a range
04f41f6
remove instance field initialization from PrecodeMachineDescriptor
lambdageek Aug 15, 2024
abf9df0
suggestion from code review make m_IsCollectible a const BYTE
lambdageek Aug 15, 2024
71dee34
fixup
lambdageek Aug 15, 2024
2fbc89e
Revert "fixup"
lambdageek Aug 15, 2024
2e3b938
Revert "suggestion from code review make m_IsCollectible a const BYTE"
lambdageek Aug 15, 2024
1776abe
move PrecodeStubs to a separate contract
lambdageek Aug 15, 2024
099b5fa
ExecutionManager contract
lambdageek Aug 15, 2024
50046b8
rename contract NativeCodePointers => CodeVersions
lambdageek Aug 15, 2024
e2d637b
ReJIT contract
lambdageek Aug 15, 2024
7724fa8
formatting, comments and whitespace
lambdageek Aug 16, 2024
a53b3ae
cleanup
lambdageek Aug 16, 2024
124ee6a
"NDirect" -> "PInvoke" in descriptor and contracts
lambdageek Aug 16, 2024
fb1676b
WIP: contract writeups
lambdageek Aug 16, 2024
f1d757e
fix build
lambdageek Aug 16, 2024
f1d7be8
placeholder ExecutionManager contract
lambdageek Aug 16, 2024
ebb4a67
placeholder ExecutionManager contract; updates to RTS and Loader
lambdageek Aug 16, 2024
aac3faf
refactor ExecutionManager
lambdageek Aug 19, 2024
ef51f0e
remove dead method from contract
lambdageek Aug 22, 2024
92764a2
fix typo
lambdageek Aug 22, 2024
4e1a620
Merge remote-tracking branch 'origin/main' into cdac-nativecodeptr
lambdageek Aug 22, 2024
037c349
Apply suggestions from code review
lambdageek Aug 23, 2024
25d8343
Add PrecodeStubs contract writeup
lambdageek Aug 23, 2024
ac0165a
Merge remote-tracking branch 'origin/main' into cdac-nativecodeptr
lambdageek Sep 10, 2024
8f5e98b
Merge remote-tracking branch 'origin/main' into cdac-nativecodeptr
lambdageek Sep 12, 2024
81fe51b
checkpoint: Abstractions
lambdageek Sep 11, 2024
c376c4c
checkpoint begin moving contracts to Abstractions
lambdageek Sep 11, 2024
9c3f010
rationalize IContractFactory
lambdageek Sep 11, 2024
7ec2f79
move IObject contract
lambdageek Sep 11, 2024
efaff82
fixup interfaces
lambdageek Sep 11, 2024
c8b5c3f
move IRuntimeTypeSystem contract
lambdageek Sep 11, 2024
e69d73c
move IException contract
lambdageek Sep 11, 2024
6861830
move ILoader contract
lambdageek Sep 11, 2024
14a7ac6
move IEcmaMetadata contract
lambdageek Sep 11, 2024
1caf9de
move IDacStreams
lambdageek Sep 11, 2024
79d6834
move IThread contract
lambdageek Sep 11, 2024
e9fd58b
move IExecutionManager, IPrecodeStubs, IReJIT contracts
lambdageek Sep 11, 2024
bcb9eac
simplify IContractFactory; make factories into classes
lambdageek Sep 11, 2024
f2844ae
rewrite all contract impls in terms of ITarget
lambdageek Sep 11, 2024
a36919b
copy some docstrings
lambdageek Sep 11, 2024
8f5fcb6
remove downcasts ITarget -> Target
lambdageek Sep 12, 2024
69f134a
make TypeInfo and FieldInfo readonly
lambdageek Sep 12, 2024
9aec4dd
move contracts and data to a Contracts assembly
lambdageek Sep 12, 2024
dd75ae8
make IContractFactory.CreateContract non-static
lambdageek Sep 12, 2024
222c2db
Add a TestPlaceholderTarget : ITarget
lambdageek Sep 13, 2024
089dfe2
[cdac] break up cdacreader into 4 separate assemblies
lambdageek Sep 11, 2024
c283b13
rename the contract factories using libraries naming convention
lambdageek Sep 24, 2024
cc3a4f1
removed unused usings
lambdageek Sep 24, 2024
4a5cd7a
fixup mock
lambdageek Sep 24, 2024
18e9d00
document all ITarget members
lambdageek Sep 24, 2024
ba9d83a
rename Registry -> ContractRegistry
lambdageek Sep 24, 2024
1f72377
Merge branch 'cdac-abstractions2' into cdac-abstractions
lambdageek Sep 24, 2024
1b8acd8
fixup merge
lambdageek Sep 24, 2024
a64c70b
one more merge fixup
lambdageek Sep 24, 2024
87d026a
change ITarget -> AbstractTarget
lambdageek Sep 25, 2024
0f2130d
change IContractRegistry -> AbstractContractRegistry
lambdageek Sep 25, 2024
9b937bc
rename Target -> ContractDescriptorTarget; AbstractTarget -> Target
lambdageek Sep 25, 2024
fd83148
fixup: rename the .cs file too
lambdageek Sep 25, 2024
6a45fba
Add ReadTargetPointerFromSpan to abstract Target
lambdageek Sep 25, 2024
bd64632
change SOSDacImpl to depend on the abstract Target
lambdageek Sep 25, 2024
ff762e0
Remove a few move concrete Target dependencies
lambdageek Sep 25, 2024
76e919f
Merge branch 'cdac-abstractions2' into cdac-abstractions
lambdageek Sep 25, 2024
7832178
fixup merge. ITarget -> Target
lambdageek Sep 25, 2024
aa9ec24
fixup merge
lambdageek Sep 25, 2024
75dfc46
rename ContractRegistry -> CachingContractRegistry; AbstractContractR…
lambdageek Sep 25, 2024
15ef960
revert unnecesasry change
lambdageek Sep 25, 2024
e2cfbe3
Merge branch 'cdac-abstractions2' into cdac-abstractions
lambdageek Sep 25, 2024
0877fa6
fixup merge
lambdageek Sep 25, 2024
1ad195b
fixup filenames and namespaces
lambdageek Sep 26, 2024
14b9470
make MockMemorySpace.ReadContext a class
lambdageek Sep 24, 2024
a2d666e
remove uses of fixed in tests
lambdageek Sep 24, 2024
863db76
make the MockMemorySpace.Builder a normal class
lambdageek Sep 24, 2024
2a7bd2e
make MockMemorySpace.ReadContext private
lambdageek Sep 24, 2024
58c4a1d
begin hiding ContractDescriptorFill
lambdageek Sep 24, 2024
588a4a3
fixup rebase
lambdageek Sep 25, 2024
0724708
cleanup boilerplate: call FillDescriptor automatically
lambdageek Sep 25, 2024
9394b73
start removing json and pointer data boilerplate
lambdageek Sep 25, 2024
77713e5
Don't fill the pointer data when there isn't any
lambdageek Sep 25, 2024
ad2a60d
remove test boilerplate
lambdageek Sep 26, 2024
607298d
remove unused MockMemorySpace.Builder functions
lambdageek Sep 26, 2024
11cdf6f
fixup rebase
lambdageek Sep 26, 2024
aae5ef4
remove unneeded stackalloc
lambdageek Sep 26, 2024
f56a3e9
describe test addresses
lambdageek Sep 26, 2024
1da90cc
Merge remote-tracking branch 'origin/main' into cdac-abstractions2
lambdageek Sep 26, 2024
1a84559
Merge branch 'cdac-bettertest' into cdac-abstractions2
lambdageek Sep 26, 2024
89132cc
Merge branch 'cdac-abstractions2' into cdac-abstractions
lambdageek Sep 26, 2024
f0700c2
Merge remote-tracking branch 'origin/main' into cdac-abstractions2
lambdageek Sep 26, 2024
bb35661
fixup merge
lambdageek Sep 27, 2024
4990111
WIP: nibble map testing
lambdageek Sep 27, 2024
32d956b
Merge remote-tracking branch 'origin/main' into cdac-abstractions2
lambdageek Sep 27, 2024
6f3ad9d
Merge branch 'cdac-abstractions2' into cdac-abstractions
lambdageek Sep 27, 2024
0666342
fixup NibbleMapTests typo
lambdageek Sep 27, 2024
a301ac1
rename HeapList -> CodeHeapListNode in data descriptor
lambdageek Sep 27, 2024
16445f5
MockMemorySpace: simplify ReaderContext
lambdageek Sep 27, 2024
f8fd300
move NibbleMap to ExecutionManagerHelpers namespace
lambdageek Sep 27, 2024
b493562
Add a NibbleMap test
lambdageek Sep 27, 2024
7584fcf
checkpoint: there's something wrong in the nibble map lookup
lambdageek Sep 27, 2024
99a9bee
[testing] display Target values in hex in debugger views
lambdageek Sep 30, 2024
2f4c032
NibbleMap: fix bug and add test
lambdageek Sep 30, 2024
52504e9
[cdac] Implement NibbleMap lookup and tests
lambdageek Sep 30, 2024
43fb677
remove fixed fixme
lambdageek Sep 30, 2024
dc3c1a4
remove one more TODO
lambdageek Sep 30, 2024
8b5d966
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Sep 30, 2024
c774d52
remove fixed fixme
lambdageek Sep 30, 2024
3789c26
remove one more TODO
lambdageek Sep 30, 2024
77edfc4
brief nibble map summary
lambdageek Sep 30, 2024
e04bdb0
Merge branch 'cdac-nibblemap-standalone' into cdac-abstractions
lambdageek Sep 30, 2024
7187a60
move RangeSectionLookupAlgorithm to a separate file
lambdageek Sep 30, 2024
14c5821
make a testable RangeSectionLookupAlgorithm.FindFragmentInternal
lambdageek Sep 30, 2024
2620440
spelling
lambdageek Oct 1, 2024
ed2f959
add placeholder RangeSectionLookupAlgorithmTest
lambdageek Oct 1, 2024
fdb22e0
checkpoint: lookup tests are working
lambdageek Oct 2, 2024
b1ad9ab
FIXME: RangeSection.Find
lambdageek Oct 2, 2024
fb93441
fix: HeapList got renamed to CodeHeapListNode
lambdageek Oct 2, 2024
333c334
fix lookup in RangeSection.Find
lambdageek Oct 2, 2024
25242ca
feed some random inputs to TestLookupOne
lambdageek Oct 3, 2024
b2a5cbc
add a Cursor to clean up RangeSectionLookupAlgorithm
lambdageek Oct 3, 2024
bef5946
use cursors for the test
lambdageek Oct 3, 2024
98dc4d1
wip: start hiding ExMgrPtr
lambdageek Oct 3, 2024
008856b
refactor RangeSectionMap
lambdageek Oct 3, 2024
32cc381
more refactoring
lambdageek Oct 3, 2024
0d302e2
exhaustively test RangeSectionMap.EffectiveBitsForLevel
lambdageek Oct 3, 2024
17d6369
on second thought, no random tests
lambdageek Oct 3, 2024
824e476
Merge remote-tracking branch 'lambdageek/cdac-nibblemap-standalone' i…
lambdageek Oct 4, 2024
bdd5c7b
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 4, 2024
3d4d553
add RangeSectionMap docs
lambdageek Oct 4, 2024
4ba95d1
remove duplicated files
lambdageek Oct 4, 2024
593316c
Add some very basic ExecutionManager tests that return null
lambdageek Oct 4, 2024
3101d6c
NibbleMap: remove unused _codeHeaderSize field
lambdageek Oct 4, 2024
5828f67
cleanup NibbleMap and tests
lambdageek Oct 4, 2024
cf5fa67
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 7, 2024
f3c0504
NibbleMap: use a struct for MapUnit
lambdageek Oct 7, 2024
9637185
NibbleMap: use types
lambdageek Oct 7, 2024
e200b7a
Clarify termination condition; clean up docs
lambdageek Oct 7, 2024
199f7e6
fix dodgy math in example
lambdageek Oct 7, 2024
7f261ec
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 8, 2024
093c8d9
fixup RangeSectionMapTests
lambdageek Oct 8, 2024
aa1deb9
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 9, 2024
d9d47ff
use better cdac_data friends
lambdageek Oct 8, 2024
bc8b551
one more friend
lambdageek Oct 8, 2024
29e58ea
fix typos
lambdageek Oct 8, 2024
c7d04e4
markdown cleanup
lambdageek Oct 8, 2024
006ccbc
document the ExecutionManager methods
lambdageek Oct 9, 2024
d6d3433
cache EECodeInfo based on given code pointer, not start of the method
lambdageek Oct 9, 2024
1143509
WIP: execution manager RangeSectionFragment test
lambdageek Oct 9, 2024
ea06c24
Make TestPlaceholderTarget data cache more useful; make TestRegistry …
lambdageek Oct 10, 2024
1cf0e07
WIP: execution manager tests (still failing)
lambdageek Oct 10, 2024
15a2959
bugfix: stubCodeBlockLast is uint8
lambdageek Oct 10, 2024
184a7c8
checkpoint: unit test is working
lambdageek Oct 10, 2024
b7f2c2b
add a simple bump allocator to MockMemorySpace
lambdageek Oct 11, 2024
ecf6ca4
Add a field layout algorithm to TargetTestHelpers
lambdageek Oct 11, 2024
78c8a14
use allocators a bit more
lambdageek Oct 11, 2024
c57e08e
move all the test builders to a separate class
lambdageek Oct 14, 2024
89eb612
cleanup test infra
lambdageek Oct 14, 2024
6befac2
remove a few more magic constants
lambdageek Oct 14, 2024
73d7c1e
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 16, 2024
659366c
add legacy DAC comparison for GetMethodDescData
lambdageek Oct 16, 2024
2680380
EECodeInfo -> CodeBlock
lambdageek Oct 16, 2024
2bc1b3a
EffectiveBitsForLevel -> GetIndexForLevel
lambdageek Oct 16, 2024
da5940f
EECodeInfo->CodeBlock followup
lambdageek Oct 16, 2024
aa672e5
add documentation to managed contract impl
lambdageek Oct 16, 2024
3d52a08
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 17, 2024
ac1bb9f
[cdac] Add a CodeVersions contract
lambdageek Oct 16, 2024
28d9aa1
tighter cdac_data friends
lambdageek Oct 17, 2024
70f4746
remove unused DataType values
lambdageek Oct 17, 2024
0dbf69d
move ecma metadata helpers to their own class
lambdageek Oct 17, 2024
b59fdb1
tighter cdac_data friends
lambdageek Oct 17, 2024
786912d
move ecma metadata helpers to their own class
lambdageek Oct 17, 2024
7386408
fixup EcmaMetadataUtils renaming
lambdageek Oct 17, 2024
ed6b345
WIP: CodeVersionsTests
lambdageek Oct 17, 2024
66a86c0
WIP: TestGetNativeCodeVersionOneVersionVersionable
lambdageek Oct 17, 2024
76a349e
implement GetNativeCode for a NativeCodeVersionNode handle
lambdageek Oct 18, 2024
2e4d142
checkpoint: TestGetNativeCodeVersionOneVersionVersionable passes
lambdageek Oct 18, 2024
814173f
Add TestGetActiveNativeCodeVersionDefaultCase
lambdageek Oct 18, 2024
5dfba68
don't add ILCodeVersioningState::Next field yet
lambdageek Oct 18, 2024
e01fd5d
describe Loader::GetModuleLookupMapElement contract
lambdageek Oct 18, 2024
a95b3ed
remove unused member
lambdageek Oct 18, 2024
b9ad92c
update contract markdown
lambdageek Oct 18, 2024
ab383ea
simplify flags handling a bit
lambdageek Oct 18, 2024
7d29912
add TODOs for RuntimeTypeSystem additions
lambdageek Oct 18, 2024
56e540a
implement GetNativeCode for a NativeCodeVersionNode handle
lambdageek Oct 18, 2024
2a6e68c
don't add ILCodeVersioningState::Next field yet
lambdageek Oct 18, 2024
dd921ac
describe Loader::GetModuleLookupMapElement contract
lambdageek Oct 18, 2024
b7e9bf0
update contract markdown
lambdageek Oct 18, 2024
bdf45b1
simplify flags handling a bit
lambdageek Oct 18, 2024
52010ff
add TODOs for RuntimeTypeSystem additions
lambdageek Oct 18, 2024
19aa553
Merge branch 'cdac-code-versions' into cdac-abstractions
lambdageek Oct 18, 2024
c8f3e08
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 18, 2024
8ba56d9
[cdac] PrecodeStubs contract
lambdageek Oct 18, 2024
cecb380
WIP: start adding PrecodeStubs test infrastructure
lambdageek Oct 18, 2024
f56ae2b
Merge remote-tracking branch 'origin/main' into cdac-precode-stubs
lambdageek Oct 18, 2024
35b2d56
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 19, 2024
6594d2c
cleanup whitespace
lambdageek Oct 19, 2024
f0d1caa
checkpoint: stub precode test passing
lambdageek Oct 21, 2024
093d837
set the "thumb" bit
lambdageek Oct 21, 2024
0cf7619
cleanup thumb bit
lambdageek Oct 21, 2024
fd0c294
Merge branch 'cdac-precode-stubs' into cdac-abstractions
lambdageek Oct 21, 2024
d8b9495
get collectible flag for module from Assembly instead of LoaderAllocator
lambdageek Oct 21, 2024
9e981dc
remove whitespace changes
lambdageek Oct 21, 2024
53b5163
add a CDacMetadata struct
lambdageek Oct 21, 2024
9bee984
permute PrecodeMachineDescriptor fields for better packability
lambdageek Oct 21, 2024
fd70d6a
reader for CDacMetadata contract
lambdageek Oct 21, 2024
24e1260
RuntimeTypeSystem cdacMetadata bits
lambdageek Oct 21, 2024
dacf410
add a CDacMetadata struct
lambdageek Oct 21, 2024
0adec75
permute PrecodeMachineDescriptor fields for better packability
lambdageek Oct 21, 2024
312a2b9
reader for CDacMetadata contract
lambdageek Oct 21, 2024
0cd8b8b
WIP: code pointer flags
lambdageek Oct 21, 2024
6a97f53
checkpoint tests with CDacMetadata
lambdageek Oct 22, 2024
8b9bbe8
WIP: code pointer flags
lambdageek Oct 21, 2024
27953ad
checkpoint tests with CDacMetadata
lambdageek Oct 22, 2024
2ed9445
Use CodePointerFlags in RuntimeTypeSystem
lambdageek Oct 22, 2024
441db40
fix a couple TODOs
lambdageek Oct 22, 2024
c4edad8
implement MethodDesc GetLoaderModule
lambdageek Oct 22, 2024
56b2b5f
implement MethodTable GetLoaderModule
lambdageek Oct 22, 2024
ed3ab8a
fixup GetSpecificNativeCodeVersion
lambdageek Oct 22, 2024
446995a
bigfix: CodeBlock start address in EEJitManager
lambdageek Oct 22, 2024
a1f3199
Apply suggestions from code review
lambdageek Oct 22, 2024
a78cbe4
rename CDacMetadata -> PlatformMetadata
lambdageek Oct 23, 2024
561ef30
add a define for Loongarch64 stub precode shift
lambdageek Oct 23, 2024
2522e23
conditionally define fields for precode absent precode types
lambdageek Oct 23, 2024
9dedc96
clarify how stub and pinvoke precodes work
lambdageek Oct 23, 2024
a6670c6
Merge branch 'cdac-precode-stubs' into cdac-abstractions
lambdageek Oct 23, 2024
19c3daa
add MethodTable.AuxiliaryData field to test typeinfo
lambdageek Oct 23, 2024
5e3d561
remove fixme
lambdageek Oct 24, 2024
876e46a
implement vtable indirections
lambdageek Oct 24, 2024
f1a3977
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 24, 2024
a4e4461
remove duplicate file after merge
lambdageek Oct 24, 2024
04b0506
fixup: GetVtableIndirections
lambdageek Oct 24, 2024
b99d94a
fix GCC build
lambdageek Oct 24, 2024
d562f96
remove unused usings
lambdageek Oct 24, 2024
1d12dd7
update TODOs
lambdageek Oct 24, 2024
2c9d0fc
remove more bad merge artifacts
lambdageek Oct 24, 2024
b93b4d2
rename some vestigial CDacMetadata references
lambdageek Oct 24, 2024
9740125
fix typo in name of private method
lambdageek Oct 24, 2024
4ccdc5f
Merge remote-tracking branch 'origin/main' into cdac-abstractions
lambdageek Oct 30, 2024
b7afbf0
WIP: MethodDesc tests
lambdageek Oct 25, 2024
babbe44
checkpoint GetMethodToken test passes
lambdageek Oct 28, 2024
a6bce83
fixup merge
lambdageek Oct 30, 2024
c74390f
move MethodValidation to a separate class
lambdageek Oct 30, 2024
292101b
move COR_PRF_MONITOR into ReJIT_1
lambdageek Oct 30, 2024
ab16aa8
Update src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs
lambdageek Oct 30, 2024
caee264
assert the expected slot number
lambdageek Oct 30, 2024
564c7e4
Exercise a few more easy properties of MethodDesc
lambdageek Oct 30, 2024
a54db74
whitespace
lambdageek Oct 31, 2024
bdc6479
remove TypeHandleFromAddress from contract
lambdageek Oct 31, 2024
0867c68
clean up MethodClassification -> size lookups
lambdageek Oct 31, 2024
f0603e3
document RuntimeTypeSystem contract additions
lambdageek Oct 31, 2024
4ff2f72
update the CodeVersions contract to match implementation
lambdageek Oct 31, 2024
3d342f6
remove some TODO comments
lambdageek Oct 31, 2024
3bacf70
fix build
lambdageek Oct 31, 2024
9f8adeb
add sizes for method desc subclasses
lambdageek Oct 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/design/datacontracts/Loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ TargetPointer GetThunkHeap(ModuleHandle handle);
TargetPointer GetILBase(ModuleHandle handle);
ModuleLookupTables GetLookupTables(ModuleHandle handle);
TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out TargetNUInt flags);
bool IsCollectible(ModuleHandle handle);
```

## Version 1
Expand All @@ -64,6 +65,7 @@ Data descriptors used:
| `ModuleLookupMap` | `SupportedFlagsMask` | Mask for flag bits on lookup map entries |
| `ModuleLookupMap` | `Count` | Number of TargetPointer sized entries in this section of the map |
| `ModuleLookupMap` | `Next` | Pointer to next ModuleLookupMap segment for this map
| `Assembly` | `IsCollectible` | Flag indicating if this is module may be collected

``` csharp
ModuleHandle GetModuleHandle(TargetPointer modulePointer)
Expand Down Expand Up @@ -151,3 +153,12 @@ TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out Tar
return TargetPointer.Null;
}
```

```csharp
bool ILoader.IsCollectible(ModuleHandle handle)
{
TargetPointer assembly = _target.ReadPointer(handle.Address + /*Module::Assembly*/);
byte isCollectible = _target.Read<byte>(assembly + /* Assembly::IsCollectible*/);
return isCollectible != 0;
}
```
43 changes: 43 additions & 0 deletions docs/design/datacontracts/ReJIT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Contract ReJIT

This contract encapsulates support for [ReJIT](../features/code-versioning.md) in the runtime.

## APIs of contract

```csharp
bool IsEnabled();
```

## Version 1

Data descriptors used:
| Data Descriptor Name | Field | Meaning |
| --- | --- | --- |
| ProfControlBlock | GlobalEventMask | an `ICorProfiler` `COR_PRF_MONITOR` value |

Global variables used:
| Global Name | Type | Purpose |
| --- | --- | --- |
|ProfilerControlBlock | TargetPointer | pointer to the `ProfControlBlock` |

Contracts used:
| Contract Name |
| --- |

```csharp
// see src/coreclr/inc/corprof.idl
[Flags]
private enum COR_PRF_MONITOR
{
COR_PRF_ENABLE_REJIT = 0x00040000,
}

bool IsEnabled()
{
TargetPointer address = target.ReadGlobalPointer("ProfilerControlBlock");
ulong globalEventMask = target.Read<ulong>(address + /* ProfControlBlock::GlobalEventMask offset*/);
bool profEnabledReJIT = (GlobalEventMask & (ulong)COR_PRF_MONITOR.COR_PRF_ENABLE_REJIT) != 0;
bool clrConfigEnabledReJit = /* host process does not have environment variable DOTNET_ProfAPI_ReJitOnAttach set to 0 */;
return profEnabledReJIT || clrConfigEnabledReJIT;
}
```
9 changes: 9 additions & 0 deletions docs/design/datacontracts/RuntimeTypeSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,15 @@ partial interface IRuntimeTypeSystem : IContract
// Return a pointer to the IL versioning state of the MethodDesc
public virtual TargetPointer GetMethodDescVersioningState(MethodDescHandle methodDesc);

// Return the MethodTable slot number of the MethodDesc
public virtual ushort GetSlotNumber(MethodDescHandle methodDesc);

// Return true if the MethodDesc has space associated with it for storing a pointer to a code block
public virtual bool HasNativeCodeSlot(MethodDescHandle methodDesc);

// Return the address of the space that stores a pointer to a code block associated with the MethodDesc
public virtual TargetPointer GetAddressOfNativeCodeSlot(MethodDescHandle methodDesc);

// Get an instruction pointer that can be called to cause the MethodDesc to be executed
public virtual TargetCodePointer GetNativeCode(MethodDescHandle methodDesc);

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/debug/runtimeinfo/contracts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"Object": 1,
"PlatformMetadata": 1,
"PrecodeStubs": 1,
"ReJIT": 1,
"RuntimeTypeSystem": 1,
"Thread": 1
}
31 changes: 29 additions & 2 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,10 +244,17 @@ CDAC_TYPE_FIELD(ModuleLookupMap, /*uint32*/, Count, offsetof(LookupMapBase, dwCo
CDAC_TYPE_FIELD(ModuleLookupMap, /*nuint*/, SupportedFlagsMask, offsetof(LookupMapBase, supportedFlags))
CDAC_TYPE_END(ModuleLookupMap)

CDAC_TYPE_BEGIN(Assembly)
CDAC_TYPE_INDETERMINATE(Assembly)
#ifdef FEATURE_COLLECTIBLE_TYPES
CDAC_TYPE_FIELD(Assembly, /*uint8*/, IsCollectible, cdac_data<Assembly>::IsCollectible)
#endif
CDAC_TYPE_END(Assembly)

// RuntimeTypeSystem

CDAC_TYPE_BEGIN(MethodTable)
CDAC_TYPE_INDETERMINATE(MethodTable)
CDAC_TYPE_SIZE(sizeof(MethodTable))
CDAC_TYPE_FIELD(MethodTable, /*uint32*/, MTFlags, cdac_data<MethodTable>::MTFlags)
CDAC_TYPE_FIELD(MethodTable, /*uint32*/, BaseSize, cdac_data<MethodTable>::BaseSize)
CDAC_TYPE_FIELD(MethodTable, /*uint32*/, MTFlags2, cdac_data<MethodTable>::MTFlags2)
Expand All @@ -257,8 +264,14 @@ CDAC_TYPE_FIELD(MethodTable, /*pointer*/, ParentMethodTable, cdac_data<MethodTab
CDAC_TYPE_FIELD(MethodTable, /*uint16*/, NumInterfaces, cdac_data<MethodTable>::NumInterfaces)
CDAC_TYPE_FIELD(MethodTable, /*uint16*/, NumVirtuals, cdac_data<MethodTable>::NumVirtuals)
CDAC_TYPE_FIELD(MethodTable, /*pointer*/, PerInstInfo, cdac_data<MethodTable>::PerInstInfo)
CDAC_TYPE_FIELD(MethodTable, /*pointer*/, AuxiliaryData, cdac_data<MethodTable>::AuxiliaryData)
CDAC_TYPE_END(MethodTable)

CDAC_TYPE_BEGIN(MethodTableAuxiliaryData)
CDAC_TYPE_INDETERMINATE(MethodTableAuxiliaryData)
CDAC_TYPE_FIELD(MethodTableAuxiliaryData, /*pointer*/, LoaderModule, offsetof(MethodTableAuxiliaryData, m_pLoaderModule))
CDAC_TYPE_END(MethodTableAuxiliaryData)

CDAC_TYPE_BEGIN(EEClass)
CDAC_TYPE_INDETERMINATE(EEClass)
CDAC_TYPE_FIELD(EEClass, /*pointer*/, MethodTable, cdac_data<EEClass>::MethodTable)
Expand Down Expand Up @@ -309,11 +322,13 @@ CDAC_TYPE_FIELD(DynamicMetadata, /*inline byte array*/, Data, cdac_data<DynamicM
CDAC_TYPE_END(DynamicMetadata)

CDAC_TYPE_BEGIN(MethodDesc)
CDAC_TYPE_INDETERMINATE(MethodDesc)
CDAC_TYPE_SIZE(sizeof(MethodDesc))
CDAC_TYPE_FIELD(MethodDesc, /*uint8*/, ChunkIndex, cdac_data<MethodDesc>::ChunkIndex)
CDAC_TYPE_FIELD(MethodDesc, /*uint16*/, Slot, cdac_data<MethodDesc>::Slot)
CDAC_TYPE_FIELD(MethodDesc, /*uint16*/, Flags, cdac_data<MethodDesc>::Flags)
CDAC_TYPE_FIELD(MethodDesc, /*uint16*/, Flags3AndTokenRemainder, cdac_data<MethodDesc>::Flags3AndTokenRemainder)
CDAC_TYPE_FIELD(MethodDesc, /*uint8*/, EntryPointFlags, cdac_data<MethodDesc>::EntryPointFlags)
CDAC_TYPE_FIELD(MethodDesc, /*pointer*/, CodeData, cdac_data<MethodDesc>::CodeData)
CDAC_TYPE_END(MethodDesc)

CDAC_TYPE_BEGIN(MethodDescChunk)
Expand Down Expand Up @@ -348,6 +363,12 @@ CDAC_TYPE_BEGIN(CodePointer)
CDAC_TYPE_SIZE(sizeof(PCODE))
CDAC_TYPE_END(CodePointer)

CDAC_TYPE_BEGIN(MethodDescCodeData)
CDAC_TYPE_INDETERMINATE(MethodDescCodeData)
CDAC_TYPE_FIELD(MethodDescCodeData, /*CodePointer*/, TemporaryEntryPoint, offsetof(MethodDescCodeData,TemporaryEntryPoint))
CDAC_TYPE_FIELD(MethodDescCodeData, /*pointer*/, VersioningState, offsetof(MethodDescCodeData,VersioningState))
CDAC_TYPE_END(MethodDescCodeData)

CDAC_TYPE_BEGIN(MethodDescVersioningState)
CDAC_TYPE_INDETERMINATE(MethodDescVersioningState)
CDAC_TYPE_FIELD(MethodDescVersioningState, /*pointer*/, NativeCodeVersionNode, cdac_data<MethodDescVersioningState>::NativeCodeVersionNode)
Expand Down Expand Up @@ -441,6 +462,11 @@ CDAC_TYPE_FIELD(NativeCodeVersionNode, /*pointer*/, Next, cdac_data<NativeCodeVe
CDAC_TYPE_FIELD(NativeCodeVersionNode, /*pointer*/, MethodDesc, cdac_data<NativeCodeVersionNode>::MethodDesc)
CDAC_TYPE_FIELD(NativeCodeVersionNode, /*pointer*/, NativeCode, cdac_data<NativeCodeVersionNode>::NativeCode)
CDAC_TYPE_END(NativeCodeVersionNode)

CDAC_TYPE_BEGIN(ProfControlBlock)
CDAC_TYPE_FIELD(ProfControlBlock, /*uint64*/, GlobalEventMask, offsetof(ProfControlBlock, globalEventMask))
CDAC_TYPE_END(ProfControlBlock)

CDAC_TYPES_END()

CDAC_GLOBALS_BEGIN()
Expand Down Expand Up @@ -482,6 +508,7 @@ CDAC_GLOBAL_POINTER(MiniMetaDataBuffAddress, &::g_MiniMetaDataBuffAddress)
CDAC_GLOBAL_POINTER(MiniMetaDataBuffMaxSize, &::g_MiniMetaDataBuffMaxSize)
CDAC_GLOBAL_POINTER(ExecutionManagerCodeRangeMapAddress, cdac_data<ExecutionManager>::CodeRangeMapAddress)
CDAC_GLOBAL_POINTER(PlatformMetadata, &::g_cdacPlatformMetadata)
CDAC_GLOBAL_POINTER(ProfilerControlBlock, &::g_profControlBlock)
CDAC_GLOBALS_END()

#undef CDAC_BASELINE
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ Assembly::Assembly(PEAssembly* pPEAssembly, LoaderAllocator *pLoaderAllocator)
#endif
, m_pLoaderAllocator{pLoaderAllocator}
#ifdef FEATURE_COLLECTIBLE_TYPES
, m_isCollectible{pLoaderAllocator->IsCollectible() != FALSE}
, m_isCollectible{static_cast<BYTE>(pLoaderAllocator->IsCollectible() != FALSE ? 1 : 0)}
#endif
, m_isDynamic(false)
, m_isLoading{true}
Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/vm/assembly.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ class Assembly

PTR_LoaderAllocator m_pLoaderAllocator;
#ifdef FEATURE_COLLECTIBLE_TYPES
bool m_isCollectible;
BYTE m_isCollectible;
#endif // FEATURE_COLLECTIBLE_TYPES
bool m_isDynamic;

Expand All @@ -536,6 +536,16 @@ class Assembly
LOADERHANDLE m_hExposedObject;

DomainAssembly* m_NextAssemblyInSameALC;

friend struct ::cdac_data<Assembly>;
};

template<>
struct cdac_data<Assembly>
{
#ifdef FEATURE_COLLECTIBLE_TYPES
static constexpr size_t IsCollectible = offsetof(Assembly, m_isCollectible);
#endif
};

#ifndef DACCESS_COMPILE
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/method.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1914,6 +1914,8 @@ template<> struct cdac_data<MethodDesc>
static constexpr size_t Slot = offsetof(MethodDesc, m_wSlotNumber);
static constexpr size_t Flags = offsetof(MethodDesc, m_wFlags);
static constexpr size_t Flags3AndTokenRemainder = offsetof(MethodDesc, m_wFlags3AndTokenRemainder);
static constexpr size_t EntryPointFlags = offsetof(MethodDesc, m_bFlags4);
static constexpr size_t CodeData = offsetof(MethodDesc, m_codeData);
};

#ifndef DACCESS_COMPILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,8 @@ internal abstract class ContractRegistry
/// Gets an instance of the PrecodeStubs contract for the target.
/// </summary>
public abstract IPrecodeStubs PrecodeStubs { get; }
/// <summary>
/// Gets an instance of the ReJIT contract for the target.
/// </summary>
public abstract IReJIT ReJIT { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ internal interface ILoader : IContract
public virtual ModuleLookupTables GetLookupTables(ModuleHandle handle) => throw new NotImplementedException();

public virtual TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out TargetNUInt flags) => throw new NotImplementedException();
public virtual bool IsCollectible(ModuleHandle handle) => throw new NotImplementedException();
}

internal readonly struct Loader : ILoader
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

namespace Microsoft.Diagnostics.DataContractReader.Contracts;

internal interface IReJIT : IContract
{
static string IContract.Name { get; } = nameof(ReJIT);
bool IsEnabled() => throw new NotImplementedException();
}

internal readonly struct ReJIT : IReJIT
{

}
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ internal interface IRuntimeTypeSystem : IContract

public virtual TargetCodePointer GetNativeCode(MethodDescHandle methodDesc) => throw new NotImplementedException();

public virtual ushort GetSlotNumber(MethodDescHandle methodDesc) => throw new NotImplementedException();

public virtual bool HasNativeCodeSlot(MethodDescHandle methodDesc) => throw new NotImplementedException();

public virtual TargetPointer GetAddressOfNativeCodeSlot(MethodDescHandle methodDesc) => throw new NotImplementedException();
#endregion MethodDesc inspection APIs
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public enum DataType
RuntimeThreadLocals,
Module,
ModuleLookupMap,
Assembly,
MethodTable,
EEClass,
ArrayClass,
Expand All @@ -44,6 +45,7 @@ public enum DataType
String,
MethodDesc,
MethodDescChunk,
MethodDescCodeData,
PlatformMetadata,
PrecodeMachineDescriptor,
StubPrecodeData,
Expand All @@ -63,4 +65,5 @@ public enum DataType
MethodDescVersioningState,
ILCodeVersioningState,
NativeCodeVersionNode,
ProfControlBlock,
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ internal static class Globals
internal const string ExecutionManagerCodeRangeMapAddress = nameof(ExecutionManagerCodeRangeMapAddress);
internal const string StubCodeBlockLast = nameof(StubCodeBlockLast);
internal const string PlatformMetadata = nameof(PlatformMetadata);
internal const string ProfilerControlBlock = nameof(ProfilerControlBlock);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ internal enum MethodDescVersioningStateFlags : byte

private NativeCodeVersionHandle GetSpecificNativeCodeVersion(IRuntimeTypeSystem rts, MethodDescHandle md, TargetCodePointer startAddress)
{
// initial stage of NativeCodeVersionIterator::Next() with a null m_ilCodeFilter
TargetCodePointer firstNativeCode = rts.GetNativeCode(md);
if (firstNativeCode == startAddress)
{
NativeCodeVersionHandle first = new NativeCodeVersionHandle(md.Address, TargetPointer.Null);
return first;
}
// ImplicitCodeVersion stage of NativeCodeVersionIterator::Next()
TargetPointer methodDescVersioningStateAddress = rts.GetMethodDescVersioningState(md);
if (methodDescVersioningStateAddress == TargetPointer.Null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

Expand Down Expand Up @@ -42,7 +41,7 @@ public override bool GetMethodInfo(RangeSection rangeSection, TargetCodePointer
}
TargetPointer codeHeaderAddress = Target.ReadPointer(codeHeaderIndirect);
Data.RealCodeHeader realCodeHeader = Target.ProcessedData.GetOrAdd<Data.RealCodeHeader>(codeHeaderAddress);
info = new CodeBlock(jittedCodeAddress, codeHeaderOffset, relativeOffset, realCodeHeader, rangeSection.Data!.JitManager);
info = new CodeBlock(start.Value, codeHeaderOffset, relativeOffset, realCodeHeader, rangeSection.Data!.JitManager);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,12 @@ TargetPointer ILoader.GetModuleLookupMapElement(TargetPointer table, uint token,
} while (table != TargetPointer.Null);
return TargetPointer.Null;
}

bool ILoader.IsCollectible(ModuleHandle handle)
{
Data.Module module = _target.ProcessedData.GetOrAdd<Data.Module>(handle.Address);
TargetPointer assembly = module.Assembly;
Data.Assembly la = _target.ProcessedData.GetOrAdd<Data.Assembly>(assembly);
return la.IsCollectible != 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ internal override TargetPointer GetMethodDesc(Target target, Data.PrecodeMachine
}
}

internal sealed class ThisPtrRetBufPrecode : ValidPrecode // FIXME: is this a StubPrecode?
internal sealed class ThisPtrRetBufPrecode : ValidPrecode
{
internal ThisPtrRetBufPrecode(TargetPointer instrPointer) : base(instrPointer, KnownPrecodeType.ThisPtrRetBuf) { }

Expand Down
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.

using System;

namespace Microsoft.Diagnostics.DataContractReader.Contracts;

internal sealed class ReJITFactory : IContractFactory<IReJIT>
{
IReJIT IContractFactory<IReJIT>.CreateContract(Target target, int version)
{
TargetPointer profControlBlockAddress = target.ReadGlobalPointer(Constants.Globals.ProfilerControlBlock);
Data.ProfControlBlock profControlBlock = target.ProcessedData.GetOrAdd<Data.ProfControlBlock>(profControlBlockAddress);
return version switch
{
1 => new ReJIT_1(target, profControlBlock),
_ => default(ReJIT),
};
}
}
Loading
Loading