From ebb4a67845559f4663dcff8f730dfa2cf0a9e647 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Fri, 16 Aug 2024 15:47:20 -0400 Subject: [PATCH] placeholder ExecutionManager contract; updates to RTS and Loader --- docs/design/datacontracts/ExecutionManager.md | 2 + docs/design/datacontracts/Loader.md | 9 ++++ .../design/datacontracts/RuntimeTypeSystem.md | 41 +++++++++++++++++-- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/docs/design/datacontracts/ExecutionManager.md b/docs/design/datacontracts/ExecutionManager.md index ec5faa399273f..276dfa6cb11ae 100644 --- a/docs/design/datacontracts/ExecutionManager.md +++ b/docs/design/datacontracts/ExecutionManager.md @@ -50,6 +50,8 @@ Contracts used: ```csharp ``` +**TODO** Methods + ### NibbleMap **TODO** diff --git a/docs/design/datacontracts/Loader.md b/docs/design/datacontracts/Loader.md index d0fe390b5ad39..be9a563bb1f56 100644 --- a/docs/design/datacontracts/Loader.md +++ b/docs/design/datacontracts/Loader.md @@ -38,6 +38,9 @@ TargetPointer GetLoaderAllocator(ModuleHandle handle); TargetPointer GetThunkHeap(ModuleHandle handle); TargetPointer GetILBase(ModuleHandle handle); ModuleLookupTables GetLookupTables(ModuleHandle handle); +TargetPointer GetModuleLookupMapElement(TargetPointer table, uint rid, out TargetNUInt flags); +bool IsCollectibleLoaderAllocator(ModuleHandle handle); + ``` ## Version 1 @@ -58,6 +61,10 @@ Data descriptors used: | `Module` | `TypeDefToMethodTableMap` | Mapping table | | `Module` | `TypeRefToMethodTableMap` | Mapping table | | `ModuleLookupMap` | `TableData` | Start of the mapping table's data | +| `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 +| `LoaderAllocator` | `IsCollectible` | Flag indicating if this is loader allocator may be collected ``` csharp ModuleHandle GetModuleHandle(TargetPointer modulePointer) @@ -110,3 +117,5 @@ ModuleLookupTables GetLookupTables(ModuleHandle handle) Module::MethodDefToILCodeVersioningState */)); } ``` + +**TODO* pseudocode for IsCollectibleLoaderAllocator and LookupTableMap element lookup diff --git a/docs/design/datacontracts/RuntimeTypeSystem.md b/docs/design/datacontracts/RuntimeTypeSystem.md index 3e6fefa079073..d7098c141c02e 100644 --- a/docs/design/datacontracts/RuntimeTypeSystem.md +++ b/docs/design/datacontracts/RuntimeTypeSystem.md @@ -137,6 +137,31 @@ partial interface IRuntimeTypeSystem : IContract // Return true if a MethodDesc represents an IL Stub dynamically generated by the runtime // A IL Stub method is also a StoredSigMethodDesc, and a NoMetadataMethod public virtual bool IsILStub(MethodDescHandle methodDesc); + + // Return true if a MethodDesc is in a collectible module + public virtual bool IsCollectibleMethod(MethodDescHandle methodDesc); + + // Return true if a MethodDesc is in a module that supports Edit-And-Continue + public virtual bool InEnCEnabledModule(MethodDescHandle methodDesc); + + // Return true if a MethodDesc supports mulitiple code versions + public virtual bool IsVersionable(MethodDescHandle methodDesc); + + // 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); + } ``` @@ -605,6 +630,7 @@ The version 1 `MethodDesc` APIs depend on the `MethodDescAlignment` global and t | `MethodDescAlignment` | `MethodDescChunk` trailing data is allocated in multiples of this constant. The size (in bytes) of each `MethodDesc` (or subclass) instance is a multiple of this constant. | | `MethodDescTokenRemainderBitCount` | Number of bits in the token remainder in `MethodDesc` | +**TODO** MethodDesc code pointers additions In the runtime a `MethodDesc` implicitly belongs to a single `MethodDescChunk` and some common data is shared between method descriptors that belong to the same chunk. A single method table will typically have multiple chunks. There are subkinds of MethodDescs at runtime of varying sizes (but the sizes must be mutliples of `MethodDescAlignment`) and each chunk contains method descriptors of the same size. @@ -629,6 +655,15 @@ We depend on the following data descriptors: | `StoredSigMethodDesc` | `ExtendedFlags` | Flags field for the `StoredSigMethodDesc` | | `DynamicMethodDesc` | `MethodName` | Pointer to Null-terminated UTF8 string describing the Method desc | +**TODO** MethodDesc code pointers additions + +The contract depends on the following other contracts + +| Contract | +| --- | +| Loader | +| ReJIT | +| CodeVersions | And the following enumeration definitions @@ -708,9 +743,9 @@ And the various apis are implemented with the following algorithms public uint GetMethodToken(MethodDescHandle methodDescHandle) { MethodDesc methodDesc = _methodDescs[methodDescHandle.Address]; - + TargetPointer methodDescChunk = // Using ChunkIndex from methodDesc, compute the wrapping MethodDescChunk - + ushort Flags3AndTokenRemainder = // Read Flags3AndTokenRemainder field from MethodDesc contract using address methodDescHandle.Address ushort FlagsAndTokenRange = // Read FlagsAndTokenRange field from MethodDescChunk contract using address methodDescChunk @@ -819,4 +854,4 @@ And the various apis are implemented with the following algorithms return ((DynamicMethodDescExtendedFlags)ExtendedFlags).HasFlag(DynamicMethodDescExtendedFlags.IsILStub); } ``` -**TODO(cdac)** +**TODO(cdac)** additional code pointers methods on MethodDesc