Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion docs/design/datacontracts/CodeVersions.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ public virtual TargetPointer GetIL(ILCodeVersionHandle ilCodeVersionHandle);

// Determines whether an IL code version has default IL
public virtual bool HasDefaultIL(ILCodeVersionHandle ilCodeVersionHandle);

// Gets the optimization tier for a native code version
public virtual OptimizationTier GetOptimizationTier(NativeCodeVersionHandle codeVersionHandle);
```

### Extension Methods
```csharp
// Return a handle to the active version of the native code for a given method descriptor
Expand All @@ -73,6 +77,7 @@ Data descriptors used:
| NativeCodeVersionNode | Flags | `NativeCodeVersionNodeFlags` flags, see below |
| NativeCodeVersionNode | VersionId | Version ID corresponding to the parent IL code version |
| NativeCodeVersionNode | GCCoverageInfo | GCStress debug info, if supported |
| NativeCodeVersionNode | OptimizationTier | The optimization tier of this native code version |
Comment thread
barosiak marked this conversation as resolved.
| ILCodeVersioningState | FirstVersionNode | pointer to the first `ILCodeVersionNode` |
| ILCodeVersioningState | ActiveVersionKind | an `ILCodeVersionKind` value indicating which fields of the active version are value |
| ILCodeVersioningState | ActiveVersionNode | if the active version is explicit, the NativeCodeVersionNode for the active version |
Expand Down Expand Up @@ -390,4 +395,4 @@ bool ICodeVersions.HasDefaultIL(ILCodeVersionHandle ilCodeVersionHandle)
{
return ilCodeVersionHandle.IsExplicit ? AsNode(ilCodeVersionHandle).ILAddress == TargetPointer.Null : true;
}
```
```
1 change: 1 addition & 0 deletions docs/design/datacontracts/Loader.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ IEnumerable<TargetPointer> GetInstantiatedMethods(ModuleHandle handle);

bool IsProbeExtensionResultValid(ModuleHandle handle);
ModuleFlags GetFlags(ModuleHandle handle);
bool IsReadyToRun(ModuleHandle handle);
bool TryGetSimpleName(ModuleHandle handle, out string simpleName);
string GetPath(ModuleHandle handle);
string GetFileName(ModuleHandle handle);
Expand Down
35 changes: 34 additions & 1 deletion docs/design/datacontracts/RuntimeTypeSystem.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,19 @@ public enum ArrayFunctionType
}
```

```csharp
public enum OptimizationTier
{
OptimizationTierUnknown,
OptimizationTier0,
OptimizationTier1,
OptimizationTier1OSR,
OptimizationTierOptimized,
OptimizationTier0Instrumented,
OptimizationTier1Instrumented,
}
```
Comment thread
max-charlamb marked this conversation as resolved.

```csharp
partial interface IRuntimeTypeSystem : IContract
{
Expand Down Expand Up @@ -196,6 +209,12 @@ partial interface IRuntimeTypeSystem : IContract
// Gets the GCStressCodeCopy pointer if available, otherwise returns TargetPointer.Null
public virtual TargetPointer GetGCStressCodeCopy(MethodDescHandle methodDesc);

// Gets the optimization tier stored on the MethodDesc's code data
public virtual OptimizationTier GetMethodDescOptimizationTier(MethodDescHandle methodDesc);

// Returns true if the method is eligible for tiered compilation
public virtual bool IsEligibleForTieredCompilation(MethodDescHandle methodDesc);

}
```

Expand Down Expand Up @@ -424,6 +443,20 @@ The contract additionally depends on these data descriptors
| `GenericsDictInfo` | `NumDicts` | Number of instantiation dictionaries, including inherited ones, in this `GenericsDictInfo` |
| `GenericsDictInfo` | `NumTypeArgs` | Number of type arguments in the type or method instantiation described by this `GenericsDictInfo` |

The value of the `NativeCodeVersionNode::OptimizationTier` field is one of:
```csharp
private enum OptimizationTier_1 : uint
{
OptimizationTier0 = 0,
OptimizationTier1 = 1,
OptimizationTier1OSR = 2,
OptimizationTierOptimized = 3,
OptimizationTier0Instrumented = 4,
OptimizationTier1Instrumented = 5,
OptimizationTierUnknown = 0xFFFFFFFF
}
```

Comment thread
barosiak marked this conversation as resolved.
Contracts used:
| Contract Name |
| --- |
Expand Down Expand Up @@ -1798,4 +1831,4 @@ void GetCoreLibFieldDescAndDef(string @namespace, string typeName, string fieldN
MetadataReader mdReader = _target.Contracts.EcmaMetadata.GetMetadata(moduleHandle)!;
fieldDef = mdReader.GetFieldDefinition(fieldHandle);
}
```
```
6 changes: 1 addition & 5 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,13 +1279,9 @@ HRESULT ClrDataAccess::GetTieredVersions(
break;
}
}
else if (pMD->IsJitOptimizationDisabled())
{
nativeCodeAddrs[count].OptimizationTier = DacpTieredVersionData::OptimizationTier_MinOptJitted;
}
else
{
nativeCodeAddrs[count].OptimizationTier = DacpTieredVersionData::OptimizationTier_Optimized;
nativeCodeAddrs[count].OptimizationTier = DacpTieredVersionData::OptimizationTier_Unknown;
}
Comment thread
barosiak marked this conversation as resolved.

++count;
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/codeversion.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,9 @@ struct cdac_data<NativeCodeVersionNode>
#ifdef HAVE_GCCOVER
static constexpr size_t GCCoverageInfo = offsetof(NativeCodeVersionNode, m_gcCover);
#endif // HAVE_GCCOVER
#ifdef FEATURE_TIERED_COMPILATION
static constexpr size_t OptimizationTier = offsetof(NativeCodeVersionNode, m_optTier);
#endif // FEATURE_TIERED_COMPILATION
};

class NativeCodeVersionCollection
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/vm/datadescriptor/datadescriptor.inc
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ CDAC_TYPE_INDETERMINATE(MethodDescCodeData)
CDAC_TYPE_FIELD(MethodDescCodeData, /*CodePointer*/, TemporaryEntryPoint, offsetof(MethodDescCodeData,TemporaryEntryPoint))
#ifdef FEATURE_CODE_VERSIONING
CDAC_TYPE_FIELD(MethodDescCodeData, /*pointer*/, VersioningState, offsetof(MethodDescCodeData,VersioningState))
CDAC_TYPE_FIELD(MethodDescCodeData, /*uint32*/, OptimizationTier, offsetof(MethodDescCodeData,OptimizationTier))
#endif // FEATURE_CODE_VERSIONING
CDAC_TYPE_END(MethodDescCodeData)

Expand Down Expand Up @@ -885,6 +886,9 @@ CDAC_TYPE_FIELD(NativeCodeVersionNode, /*nuint*/, ILVersionId, cdac_data<NativeC
#ifdef HAVE_GCCOVER
CDAC_TYPE_FIELD(NativeCodeVersionNode, /*pointer*/, GCCoverageInfo, cdac_data<NativeCodeVersionNode>::GCCoverageInfo)
#endif // HAVE_GCCOVER
#ifdef FEATURE_TIERED_COMPILATION
CDAC_TYPE_FIELD(NativeCodeVersionNode, /*uint32*/, OptimizationTier, cdac_data<NativeCodeVersionNode>::OptimizationTier)
#endif // FEATURE_TIERED_COMPILATION
CDAC_TYPE_END(NativeCodeVersionNode)

CDAC_TYPE_BEGIN(ILCodeVersionNode)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/eeconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class EEConfig
bool TieredCompilation_UseCallCountingStubs() const { LIMITED_METHOD_CONTRACT; return fTieredCompilation_UseCallCountingStubs; }
DWORD TieredCompilation_DeleteCallCountingStubsAfter() const { LIMITED_METHOD_CONTRACT; return tieredCompilation_DeleteCallCountingStubsAfter; }
#endif // FEATURE_TIERED_COMPILATION
DWORD TieredCompilation_DefaultTier() const
DWORD TieredCompilation_DefaultTier() const
{
LIMITED_METHOD_CONTRACT;
return tieredCompilation_DefaultTier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public interface ICodeVersions : IContract

public virtual TargetPointer GetIL(ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException();
public virtual bool HasDefaultIL(ILCodeVersionHandle ilCodeVersionHandle) => throw new NotImplementedException();
public virtual OptimizationTier GetOptimizationTier(NativeCodeVersionHandle codeVersionHandle) => throw new NotImplementedException();
}

public readonly struct ILCodeVersionHandle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public interface ILoader : IContract

bool IsProbeExtensionResultValid(ModuleHandle handle) => throw new NotImplementedException();
ModuleFlags GetFlags(ModuleHandle handle) => throw new NotImplementedException();
bool IsReadyToRun(ModuleHandle handle) => throw new NotImplementedException();
bool TryGetSimpleName(ModuleHandle handle, out string simpleName) => throw new NotImplementedException();
string GetPath(ModuleHandle handle) => throw new NotImplementedException();
string GetFileName(ModuleHandle handle) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public enum ArrayFunctionType
Constructor = 3
}

public enum OptimizationTier : uint
{
OptimizationTierUnknown,
OptimizationTier0,
OptimizationTier1,
OptimizationTier1OSR,
OptimizationTierOptimized,
OptimizationTier0Instrumented,
OptimizationTier1Instrumented,
}


public interface IRuntimeTypeSystem : IContract
{
static string IContract.Name => nameof(RuntimeTypeSystem);
Expand Down Expand Up @@ -207,6 +219,9 @@ public interface IRuntimeTypeSystem : IContract
TargetPointer GetAddressOfNativeCodeSlot(MethodDescHandle methodDesc) => throw new NotImplementedException();

TargetPointer GetGCStressCodeCopy(MethodDescHandle methodDesc) => throw new NotImplementedException();

OptimizationTier GetMethodDescOptimizationTier(MethodDescHandle methodDescHandle) => throw new NotImplementedException();
bool IsEligibleForTieredCompilation(MethodDescHandle methodDescHandle) => throw new NotImplementedException();
#endregion MethodDesc inspection APIs
#region FieldDesc inspection APIs
TargetPointer GetMTOfEnclosingClass(TargetPointer fieldDescPointer) => throw new NotImplementedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,4 +413,25 @@ bool ICodeVersions.HasDefaultIL(ILCodeVersionHandle iLCodeVersionHandle)
{
return iLCodeVersionHandle.IsExplicit ? AsNode(iLCodeVersionHandle).ILAddress == TargetPointer.Null : true;
}

OptimizationTier ICodeVersions.GetOptimizationTier(NativeCodeVersionHandle codeVersionHandle)
{
if (!codeVersionHandle.Valid)
{
throw new ArgumentException("Invalid NativeCodeVersionHandle");
}

if (codeVersionHandle.IsExplicit)
{
NativeCodeVersionNode nativeCodeVersionNode = _target.ProcessedData.GetOrAdd<NativeCodeVersionNode>(codeVersionHandle.CodeVersionNodeAddress);
return RuntimeTypeSystem_1.GetOptimizationTier(nativeCodeVersionNode.OptimizationTier);
}
else
{
IRuntimeTypeSystem rtsContract = _target.Contracts.RuntimeTypeSystem;
MethodDescHandle methodDescHandle = rtsContract.GetMethodDescHandle(codeVersionHandle.MethodDescAddress);
OptimizationTier optimizationTier = rtsContract.GetMethodDescOptimizationTier(methodDescHandle);
return optimizationTier;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ ModuleFlags ILoader.GetFlags(ModuleHandle handle)
return GetFlags(module);
}

bool ILoader.IsReadyToRun(ModuleHandle handle)
{
Data.Module module = _target.ProcessedData.GetOrAdd<Data.Module>(handle.Address);
return module.ReadyToRunInfo != TargetPointer.Null;
}

bool ILoader.TryGetSimpleName(ModuleHandle handle, out string simpleName)
{
simpleName = string.Empty;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,17 @@ public ulong SizeOfChunk

}

private enum OptimizationTier_1 : uint
{
OptimizationTier0,
OptimizationTier1,
OptimizationTier1OSR,
OptimizationTierOptimized,
OptimizationTier0Instrumented,
OptimizationTier1Instrumented,
OptimizationTierUnknown = 0xFFFFFFFF
}

private sealed class InstantiatedMethodDesc : IData<InstantiatedMethodDesc>
{
public static InstantiatedMethodDesc Create(Target target, TargetPointer address) => new InstantiatedMethodDesc(target, address);
Expand Down Expand Up @@ -1645,6 +1656,37 @@ TargetPointer IRuntimeTypeSystem.GetGCStressCodeCopy(MethodDescHandle methodDesc
return TargetPointer.Null;
}

internal static OptimizationTier GetOptimizationTier(uint? optimizationTier)
{
return (OptimizationTier_1?)optimizationTier switch
{
OptimizationTier_1.OptimizationTier0 => OptimizationTier.OptimizationTier0,
OptimizationTier_1.OptimizationTier1 => OptimizationTier.OptimizationTier1,
OptimizationTier_1.OptimizationTier1OSR => OptimizationTier.OptimizationTier1OSR,
OptimizationTier_1.OptimizationTierOptimized => OptimizationTier.OptimizationTierOptimized,
OptimizationTier_1.OptimizationTier0Instrumented => OptimizationTier.OptimizationTier0Instrumented,
OptimizationTier_1.OptimizationTier1Instrumented => OptimizationTier.OptimizationTier1Instrumented,
_ => OptimizationTier.OptimizationTierUnknown,
};
}

OptimizationTier IRuntimeTypeSystem.GetMethodDescOptimizationTier(MethodDescHandle methodDescHandle)
{
MethodDesc methodDesc = _methodDescs[methodDescHandle.Address];
TargetPointer codeDataAddress = methodDesc.CodeData;
if (codeDataAddress == TargetPointer.Null)
return OptimizationTier.OptimizationTierUnknown;

Data.MethodDescCodeData codeData = _target.ProcessedData.GetOrAdd<Data.MethodDescCodeData>(codeDataAddress);
return GetOptimizationTier(codeData.OptimizationTier);
}

bool IRuntimeTypeSystem.IsEligibleForTieredCompilation(MethodDescHandle methodDescHandle)
{
MethodDesc methodDesc = _methodDescs[methodDescHandle.Address];
return methodDesc.IsEligibleForTieredCompilation;
}

private sealed class NonValidatedMethodTableQueries : MethodValidation.IMethodTableQueries
{
private readonly RuntimeTypeSystem_1 _rts;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public MethodDescCodeData(Target target, TargetPointer address)

TemporaryEntryPoint = target.ReadCodePointer(address + (ulong)type.Fields[nameof(TemporaryEntryPoint)].Offset);
VersioningState = target.ReadPointer(address + (ulong)type.Fields[nameof(VersioningState)].Offset);
OptimizationTier = target.Read<uint>(address + (ulong)type.Fields[nameof(OptimizationTier)].Offset);
Comment thread
barosiak marked this conversation as resolved.
}
Comment thread
max-charlamb marked this conversation as resolved.

public TargetCodePointer TemporaryEntryPoint { get; set; }
public TargetPointer VersioningState { get; set; }
public uint OptimizationTier { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public NativeCodeVersionNode(Target target, TargetPointer address)
{
GCCoverageInfo = target.ReadPointer(address + (ulong)type.Fields[nameof(GCCoverageInfo)].Offset);
}
OptimizationTier = target.Read<uint>(address + (ulong)type.Fields[nameof(OptimizationTier)].Offset);
Comment thread
barosiak marked this conversation as resolved.
}

public TargetPointer Next { get; init; }
Expand All @@ -31,4 +32,5 @@ public NativeCodeVersionNode(Target target, TargetPointer address)
public TargetNUInt ILVersionId { get; init; }

public TargetPointer? GCCoverageInfo { get; init; }
public uint OptimizationTier { get; init; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -959,12 +959,37 @@ public unsafe partial interface ISOSDacInterface4
int GetClrNotification([In, Out, MarshalUsing(CountElementName = nameof(count))] ClrDataAddress[] arguments, int count, int* pNeeded);
};

public struct DacpTieredVersionData
{
public enum OptimizationTier
{
Unknown = 0,
MinOptJitted = 1,
Optimized = 2,
QuickJitted = 3,
OptimizedTier1 = 4,
ReadyToRun = 5,
OptimizedTier1OSR = 6,
QuickJittedInstrumented = 7,
OptimizedTier1Instrumented = 8,
}

public ClrDataAddress nativeCodeAddr;
public OptimizationTier optimizationTier;
public ClrDataAddress nativeCodeVersionNodePtr;
}

[GeneratedComInterface]
[Guid("127d6abe-6c86-4e48-8e7b-220781c58101")]
public unsafe partial interface ISOSDacInterface5
{
[PreserveSig]
int GetTieredVersions(ClrDataAddress methodDesc, int rejitId, /*struct DacpTieredVersionData*/void* nativeCodeAddrs, int cNativeCodeAddrs, int* pcNativeCodeAddrs);
int GetTieredVersions(
ClrDataAddress methodDesc,
int rejitId,
[In, Out, MarshalUsing(CountElementName = nameof(cNativeCodeAddrs))] DacpTieredVersionData[]? nativeCodeAddrs,
int cNativeCodeAddrs,
int* pcNativeCodeAddrs);
};

public struct DacpMethodTableCollectibleData
Expand Down
Loading