Skip to content

Commit

Permalink
[cdac] GetMethodDescData for jitted methods (#109187)
Browse files Browse the repository at this point in the history
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 <arobins@microsoft.com>

* 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 <elfung@microsoft.com>
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
  • Loading branch information
3 people authored Nov 1, 2024
1 parent 251ef76 commit 65d6ef6
Show file tree
Hide file tree
Showing 40 changed files with 1,721 additions and 207 deletions.
8 changes: 8 additions & 0 deletions docs/design/datacontracts/CodeVersions.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ NativeCodeVersionHandle ICodeVersions.GetNativeCodeVersionForIP(TargetCodePointe

NativeCodeVersionHandle GetSpecificNativeCodeVersion(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 = target.Contracts.RuntimeTypeSystem.GetMethodDescVersioningState(md);
if (methodDescVersioningStateAddress == TargetPointer.Null)
{
Expand Down
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;
}
```
Loading

0 comments on commit 65d6ef6

Please sign in to comment.