Skip to content

Commit 4fc1b6f

Browse files
author
Max Charlamb
committed
remove GCCover contract and move API to CodeVersions
1 parent 22ed710 commit 4fc1b6f

File tree

22 files changed

+146
-260
lines changed

22 files changed

+146
-260
lines changed

docs/design/datacontracts/CodeVersions.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public virtual bool CodeVersionManagerSupportsMethod(TargetPointer methodDesc);
4040

4141
// Return the instruction pointer corresponding to the start of the given native code version
4242
public virtual TargetCodePointer GetNativeCode(NativeCodeVersionHandle codeVersionHandle);
43+
44+
// Gets the GCStressCodeCopy pointer if available, otherwise returns TargetPointer.Null
45+
public virtual TargetPointer GetGCStressCodeCopy(NativeCodeVersionHandle codeVersionHandle);
4346
```
4447
### Extension Methods
4548
```csharp
@@ -61,13 +64,15 @@ Data descriptors used:
6164
| NativeCodeVersionNode | NativeCode | indicates an explicit native code version node |
6265
| NativeCodeVersionNode | Flags | `NativeCodeVersionNodeFlags` flags, see below |
6366
| NativeCodeVersionNode | VersionId | Version ID corresponding to the parent IL code version |
67+
| NativeCodeVersionNode | GCCoverageInfo | GCStress debug info, if supported |
6468
| ILCodeVersioningState | FirstVersionNode | pointer to the first `ILCodeVersionNode` |
6569
| ILCodeVersioningState | ActiveVersionKind | an `ILCodeVersionKind` value indicating which fields of the active version are value |
6670
| ILCodeVersioningState | ActiveVersionNode | if the active version is explicit, the NativeCodeVersionNode for the active version |
6771
| ILCodeVersioningState | ActiveVersionModule | if the active version is synthetic or unknown, the pointer to the Module that defines the method |
6872
| ILCodeVersioningState | ActiveVersionMethodDef | if the active version is synthetic or unknown, the MethodDef token for the method |
6973
| ILCodeVersionNode | VersionId | Version ID of the node |
7074
| ILCodeVersionNode | Next | Pointer to the next `ILCodeVersionNode`|
75+
| GCCoverageInfo | SavedCode | Pointer to the GCCover saved code copy |
7176

7277
The flag indicates that the default version of the code for a method desc is active:
7378
```csharp
@@ -249,3 +254,11 @@ bool ICodeVersions.CodeVersionManagerSupportsMethod(TargetPointer methodDescAddr
249254
return true;
250255
}
251256
```
257+
258+
### Finding GCStress Code Copy
259+
```csharp
260+
public virtual TargetPointer GetGCStressCodeCopy(NativeCodeVersionHandle codeVersionHandle);
261+
```
262+
263+
1. If `codeVersionHandle` is synthetic, use the `IRuntimeTypeSystem` to find the GCStressCodeCopy.
264+
2. If `codeVersionHandle` is explicit, read the `NativeCodeVersionNode` for the `GCCoverageInfo` pointer. This value is nullable as it only exists in some builds. If the value doesn't exist or is a nullptr, return `TargetPointer.Null`. Otherwise return the `SavedCode` pointer from the `GCCoverageInfo` struct.

docs/design/datacontracts/RuntimeTypeSystem.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ partial interface IRuntimeTypeSystem : IContract
159159
// Get an instruction pointer that can be called to cause the MethodDesc to be executed
160160
public virtual TargetCodePointer GetNativeCode(MethodDescHandle methodDesc);
161161

162-
// Gets the GCCoverageInfo pointer if available, otherwise returns TargetPointer.Null
163-
public virtual TargetPointer GetGCCoverageInfo(MethodDescHandle methodDesc);
162+
// Gets the GCStressCodeCopy pointer if available, otherwise returns TargetPointer.Null
163+
public virtual TargetPointer GetGCStressCodeCopy(MethodDescHandle methodDesc);
164164
}
165165
```
166166

@@ -640,6 +640,7 @@ We depend on the following data descriptors:
640640
| `MethodDesc` | `Slot` | The method's slot |
641641
| `MethodDesc` | `Flags` | The method's flags |
642642
| `MethodDesc` | `Flags3AndTokenRemainder` | More flags for the method, and the low bits of the method's token's RID |
643+
| `MethodDesc` | `GCCoverageInfo` | The method's GCCover debug info, if supported |
643644
| `MethodDescCodeData` | `VersioningState` | The IL versioning state associated with a method descriptor
644645
| `MethodDescChunk` | `MethodTable` | The method table set of methods belongs to |
645646
| `MethodDescChunk` | `Next` | The next chunk of methods |
@@ -656,6 +657,7 @@ We depend on the following data descriptors:
656657
| `StoredSigMethodDesc` | `cSig` | Count of bytes in the metadata signature |
657658
| `StoredSigMethodDesc` | `ExtendedFlags` | Flags field for the `StoredSigMethodDesc` |
658659
| `DynamicMethodDesc` | `MethodName` | Pointer to Null-terminated UTF8 string describing the Method desc |
660+
| `GCCoverageInfo` | `SavedCode` | Pointer to the GCCover saved code copy |
659661

660662

661663
The contract depends on the following other contracts

src/coreclr/debug/runtimeinfo/contracts.jsonc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"EcmaMetadata" : 1,
1515
"Exception": 1,
1616
"ExecutionManager": 2,
17-
"GCCover": 1,
1817
"Loader": 1,
1918
"Object": 1,
2019
"PlatformMetadata": 1,

src/coreclr/debug/runtimeinfo/datadescriptor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ CDAC_TYPE_FIELD(MethodDesc, /*uint16*/, Flags3AndTokenRemainder, cdac_data<Metho
332332
CDAC_TYPE_FIELD(MethodDesc, /*uint8*/, EntryPointFlags, cdac_data<MethodDesc>::EntryPointFlags)
333333
CDAC_TYPE_FIELD(MethodDesc, /*pointer*/, CodeData, cdac_data<MethodDesc>::CodeData)
334334
#ifdef HAVE_GCCOVER
335-
CDAC_TYPE_FIELD(MethodDesc, /*pointer*/, GCCoverageInfo, cdac_data<MethodDesc>::GCCoverageInfo)
335+
CDAC_TYPE_FIELD(MethodDesc, /*pointer*/, GCCoverageInfo, MethodDesc::m_GcCover)
336336
#endif // HAVE_GCCOVER
337337
CDAC_TYPE_END(MethodDesc)
338338

src/coreclr/vm/method.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,9 +1910,6 @@ template<> struct cdac_data<MethodDesc>
19101910
static constexpr size_t Flags3AndTokenRemainder = offsetof(MethodDesc, m_wFlags3AndTokenRemainder);
19111911
static constexpr size_t EntryPointFlags = offsetof(MethodDesc, m_bFlags4);
19121912
static constexpr size_t CodeData = offsetof(MethodDesc, m_codeData);
1913-
#ifdef HAVE_GCCOVER
1914-
static constexpr size_t GCCoverageInfo = offsetof(MethodDesc, m_GcCover);
1915-
#endif // HAVE_GCCOVER
19161913
};
19171914

19181915
#ifndef DACCESS_COMPILE

src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Abstractions/ContractRegistry.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,4 @@ internal abstract class ContractRegistry
5959
/// Gets an instance of the ReJIT contract for the target.
6060
/// </summary>
6161
public abstract IReJIT ReJIT { get; }
62-
/// <summary>
63-
/// Gets an instance of the GCCover contract for the target.
64-
/// </summary>
65-
public abstract IGCCover GCCover { get; }
6662
}

src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/ICodeVersions.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ internal interface ICodeVersions : IContract
2222

2323
public virtual TargetCodePointer GetNativeCode(NativeCodeVersionHandle codeVersionHandle) => throw new NotImplementedException();
2424

25+
public virtual TargetPointer GetGCStressCodeCopy(NativeCodeVersionHandle codeVersionHandle) => throw new NotImplementedException();
26+
2527
public virtual bool CodeVersionManagerSupportsMethod(TargetPointer methodDesc) => throw new NotImplementedException();
2628
}
2729

src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IGCCover.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Abstractions/Contracts/IRuntimeTypeSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ internal interface IRuntimeTypeSystem : IContract
166166

167167
public virtual TargetPointer GetAddressOfNativeCodeSlot(MethodDescHandle methodDesc) => throw new NotImplementedException();
168168

169-
public virtual TargetPointer GetGCCoverageInfo(MethodDescHandle methodDesc) => throw new NotImplementedException();
169+
public virtual TargetPointer GetGCStressCodeCopy(MethodDescHandle methodDesc) => throw new NotImplementedException();
170170
#endregion MethodDesc inspection APIs
171171
}
172172

src/native/managed/cdacreader/Microsoft.Diagnostics.DataContractReader.Contracts/Contracts/CodeVersions_1.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,30 @@ NativeCodeVersionHandle ICodeVersions.GetActiveNativeCodeVersionForILCodeVersion
187187
return (ilVersionId == codeVersion.ILVersionId)
188188
&& ((NativeCodeVersionNodeFlags)codeVersion.Flags).HasFlag(NativeCodeVersionNodeFlags.IsActiveChild);
189189
});
190+
}
191+
192+
TargetPointer ICodeVersions.GetGCStressCodeCopy(NativeCodeVersionHandle codeVersionHandle)
193+
{
194+
Debug.Assert(codeVersionHandle.Valid);
190195

196+
if (!codeVersionHandle.IsExplicit)
197+
{
198+
// NativeCodeVersion::GetGCCoverageInfo
199+
IRuntimeTypeSystem rts = _target.Contracts.RuntimeTypeSystem;
200+
MethodDescHandle md = rts.GetMethodDescHandle(codeVersionHandle.MethodDescAddress);
201+
return rts.GetGCStressCodeCopy(md);
202+
}
203+
else
204+
{
205+
// NativeCodeVersionNode::GetGCCoverageInfo
206+
NativeCodeVersionNode codeVersionNode = AsNode(codeVersionHandle);
207+
if (codeVersionNode.GCCoverageInfo is TargetPointer gcCoverageInfoAddr)
208+
{
209+
Target.TypeInfo gcCoverageInfoType = _target.GetTypeInfo(DataType.GCCoverageInfo);
210+
return gcCoverageInfoAddr + (ulong)gcCoverageInfoType.Fields["SavedCode"].Offset;
211+
}
212+
return TargetPointer.Null;
213+
}
191214
}
192215

193216
[Flags]

0 commit comments

Comments
 (0)