Skip to content

Commit 65d6ef6

Browse files
lambdageekelinor-fungAaronRobinsonMSFT
authored
[cdac] GetMethodDescData for jitted methods (#109187)
This is enough for `!PrintException` without R2R methods on the stack There's also a `ReJIT` contract here which just checks whether rejit is enabled. Most of the complexity is in validating MethodDescs Contributes to #99302 Contributes to #108553 --- * ReJIT contract * document the ExecutionManager methods * cache EECodeInfo based on given code pointer, not start of the method The EECodeInfo includes the relative offset (given ip - start of method) so it's not ok to share for different code pointers into the same method * add legacy DAC comparison for GetMethodDescData * add documentation to managed contract impl * add TODOs for RuntimeTypeSystem additions * update contract markdown * get collectible flag for module from Assembly instead of LoaderAllocator * Use CodePointerFlags in RuntimeTypeSystem * implement MethodDesc GetLoaderModule via the loader module attached to a chunk * implement MethodTable GetLoaderModule * add MethodTable.AuxiliaryData field to test typeinfo * implement vtable indirections * fixup: GetVtableIndirections - add MethodTable size to data descriptor * rename some vestigial CDacMetadata references * WIP: MethodDesc tests * checkpoint GetMethodToken test passes * move MethodValidation to a separate class also move method flags out of the RuntimeTypeSystem_1 contract for the cases where the method validation needs to call back to type validation, go via the contract * move COR_PRF_MONITOR into ReJIT_1 it's an implementation detail * Update src/native/managed/cdacreader/src/Legacy/SOSDacImpl.cs Co-authored-by: Aaron Robinson <[email protected]> * assert the expected slot number * Exercise a few more easy properties of MethodDesc * remove TypeHandleFromAddress from contract we just use GetTypeHandle now * clean up MethodClassification -> size lookups * document RuntimeTypeSystem contract additions * update the CodeVersions contract to match implementation * remove some TODO comments * add sizes for method desc subclasses the "additional pointers" logic in RuntimeTypeSystem_1 depends on the sizes --------- Co-authored-by: Elinor Fung <[email protected]> Co-authored-by: Aaron Robinson <[email protected]>
1 parent 251ef76 commit 65d6ef6

40 files changed

+1721
-207
lines changed

docs/design/datacontracts/CodeVersions.md

+8
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ NativeCodeVersionHandle ICodeVersions.GetNativeCodeVersionForIP(TargetCodePointe
113113

114114
NativeCodeVersionHandle GetSpecificNativeCodeVersion(MethodDescHandle md, TargetCodePointer startAddress)
115115
{
116+
// "Initial" stage of NativeCodeVersionIterator::Next() with a null m_ilCodeFilter
117+
TargetCodePointer firstNativeCode = rts.GetNativeCode(md);
118+
if (firstNativeCode == startAddress)
119+
{
120+
NativeCodeVersionHandle first = new NativeCodeVersionHandle(md.Address, TargetPointer.Null);
121+
return first;
122+
}
123+
// ImplicitCodeVersion stage of NativeCodeVersionIterator::Next()
116124
TargetPointer methodDescVersioningStateAddress = target.Contracts.RuntimeTypeSystem.GetMethodDescVersioningState(md);
117125
if (methodDescVersioningStateAddress == TargetPointer.Null)
118126
{

docs/design/datacontracts/Loader.md

+11
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ TargetPointer GetThunkHeap(ModuleHandle handle);
4040
TargetPointer GetILBase(ModuleHandle handle);
4141
ModuleLookupTables GetLookupTables(ModuleHandle handle);
4242
TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out TargetNUInt flags);
43+
bool IsCollectible(ModuleHandle handle);
4344
```
4445

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

6870
``` csharp
6971
ModuleHandle GetModuleHandle(TargetPointer modulePointer)
@@ -151,3 +153,12 @@ TargetPointer GetModuleLookupMapElement(TargetPointer table, uint token, out Tar
151153
return TargetPointer.Null;
152154
}
153155
```
156+
157+
```csharp
158+
bool ILoader.IsCollectible(ModuleHandle handle)
159+
{
160+
TargetPointer assembly = _target.ReadPointer(handle.Address + /*Module::Assembly*/);
161+
byte isCollectible = _target.Read<byte>(assembly + /* Assembly::IsCollectible*/);
162+
return isCollectible != 0;
163+
}
164+
```

docs/design/datacontracts/ReJIT.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Contract ReJIT
2+
3+
This contract encapsulates support for [ReJIT](../features/code-versioning.md) in the runtime.
4+
5+
## APIs of contract
6+
7+
```csharp
8+
bool IsEnabled();
9+
```
10+
11+
## Version 1
12+
13+
Data descriptors used:
14+
| Data Descriptor Name | Field | Meaning |
15+
| --- | --- | --- |
16+
| ProfControlBlock | GlobalEventMask | an `ICorProfiler` `COR_PRF_MONITOR` value |
17+
18+
Global variables used:
19+
| Global Name | Type | Purpose |
20+
| --- | --- | --- |
21+
|ProfilerControlBlock | TargetPointer | pointer to the `ProfControlBlock` |
22+
23+
Contracts used:
24+
| Contract Name |
25+
| --- |
26+
27+
```csharp
28+
// see src/coreclr/inc/corprof.idl
29+
[Flags]
30+
private enum COR_PRF_MONITOR
31+
{
32+
COR_PRF_ENABLE_REJIT = 0x00040000,
33+
}
34+
35+
bool IsEnabled()
36+
{
37+
TargetPointer address = target.ReadGlobalPointer("ProfilerControlBlock");
38+
ulong globalEventMask = target.Read<ulong>(address + /* ProfControlBlock::GlobalEventMask offset*/);
39+
bool profEnabledReJIT = (GlobalEventMask & (ulong)COR_PRF_MONITOR.COR_PRF_ENABLE_REJIT) != 0;
40+
bool clrConfigEnabledReJit = /* host process does not have environment variable DOTNET_ProfAPI_ReJitOnAttach set to 0 */;
41+
return profEnabledReJIT || clrConfigEnabledReJIT;
42+
}
43+
```

0 commit comments

Comments
 (0)