Skip to content

Commit 423d2a3

Browse files
Replace multi-loaderallocator hash implementation in MethodDescBackpatchInfo (dotnet#22285)
* GCHeapHash - Hashtable implementation for runtime use - Implementation written in C++ - Data storage in managed heap memory - Based on SHash design, but using managed memory CrossLoaderAllocatorHash - Hash for c++ Pointer to C++ pointer where the lifetimes are controlled by different loader allocators - Support for add/remove/visit all entries of 1 key/visit all entries/ remove all entries of 1 key - Supports holding data which is unmanaged, but data items themselves can be of any size (key/value are templated types) * Swap MethodDescBackpatchInfo to use the CrossLoaderAllocatorHash * The MethodDescBackpatchCrst needs to be around an allocation - Adjust the Crst so that it can safely be used around code which allocates - Required moving its use out from within the EESuspend logic used in rejit
1 parent 89e78f4 commit 423d2a3

23 files changed

+2576
-664
lines changed

src/System.Private.CoreLib/System.Private.CoreLib.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,9 @@
232232
<Compile Include="$(BclSourcesRoot)\System\Reflection\RuntimePropertyInfo.cs" />
233233
<Compile Include="$(BclSourcesRoot)\System\Resources\ManifestBasedResourceGroveler.CoreCLR.cs" />
234234
<Compile Include="$(BclSourcesRoot)\System\RtType.cs" />
235+
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\CrossLoaderAllocatorHashHelpers.cs" />
235236
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\DependentHandle.cs" />
237+
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\GCHeapHash.cs" />
236238
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\ICastableHelpers.cs" />
237239
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\jithelpers.cs" />
238240
<Compile Include="$(BclSourcesRoot)\System\Runtime\CompilerServices\RuntimeFeature.CoreCLR.cs" />
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
namespace System.Runtime.CompilerServices
9+
{
10+
/// <summary>
11+
/// Managed structure used by CrossLoaderAllocatorHeap to isolate per LoaderAllocator
12+
/// data.
13+
/// </summary>
14+
[StructLayout(LayoutKind.Sequential)]
15+
internal class LAHashDependentHashTracker
16+
{
17+
GCHandle _dependentHandle;
18+
IntPtr _loaderAllocator;
19+
20+
~LAHashDependentHashTracker()
21+
{
22+
if (_dependentHandle.IsAllocated)
23+
_dependentHandle.Free();
24+
}
25+
}
26+
27+
/// <summary>
28+
/// Managed structure used by CrossLoaderAllocatorHeap to hold a set of references
29+
/// to LAHashDependentHashTracker's
30+
/// </summary>
31+
[StructLayout(LayoutKind.Sequential)]
32+
internal class LAHashKeyToTrackers
33+
{
34+
object _trackerOrTrackerSet;
35+
object _laLocalKeyValueStore;
36+
}
37+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Runtime.InteropServices;
7+
8+
namespace System.Runtime.CompilerServices
9+
{
10+
/// <summary>
11+
/// Managed structure used by GCHeapHash in CLR to provide a hashtable manipulated
12+
/// by C++ runtime code which manages its memory in the GC heap.
13+
/// </summary>
14+
[StructLayout(LayoutKind.Sequential)]
15+
internal class GCHeapHash
16+
{
17+
Array _data;
18+
int _count;
19+
int _deletedCount;
20+
}
21+
}

src/inc/CrstTypes.def

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,8 @@ End
491491

492492
// Used to synchronize all rejit information stored in a given AppDomain.
493493
Crst ReJITDomainTable
494-
AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController MethodDescBackpatchInfoTracker
495-
AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex
494+
AcquiredBefore LoaderHeap SingleUseLock DeadlockDetection JumpStubCache DebuggerController FuncPtrStubs
495+
AcquiredAfter ReJITGlobalRequest ThreadStore GlobalStrLiteralMap SystemDomain DebuggerMutex MethodDescBackpatchInfoTracker
496496
End
497497

498498
// Used to synchronize all global requests (which may span multiple AppDomains) which add
@@ -701,5 +701,5 @@ Crst COMCallWrapper
701701
End
702702

703703
Crst MethodDescBackpatchInfoTracker
704-
AcquiredBefore FuncPtrStubs
704+
AcquiredBefore FuncPtrStubs ThreadStore SystemDomain
705705
End

0 commit comments

Comments
 (0)