Skip to content

Commit d673663

Browse files
committed
Various fixes to get tests passing
Move portions of ComWrappers.NativeAot.cs that aren't run during GC into ComWrappers.Common.cs Convert CoreCLR to use the managed ComWrappers implementation wherever possible (everywhere except for during GC) Move wrapper ID to be a CoreCLR-only concept (as it's only needed for diagnostics support)
1 parent 5266e7d commit d673663

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3354
-5516
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
<Compile Include="src\System\RuntimeType.BoxCache.cs" />
243243
<Compile Include="src\System\RuntimeType.CreateUninitializedCache.CoreCLR.cs" />
244244
<Compile Include="src\System\RuntimeType.GenericCache.cs" />
245+
<Compile Include="src\System\Runtime\InteropServices\TrackerObjectManager.CoreCLR.cs" />
245246
</ItemGroup>
246247
<ItemGroup Condition="'$(FeatureComWrappers)' == 'true'">
247248
<Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\ComWrappers.cs" />

src/coreclr/System.Private.CoreLib/src/System/ComAwareWeakReference.CoreCLR.cs

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,19 @@ namespace System
1010
internal sealed partial class ComAwareWeakReference
1111
{
1212
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ComWeakRefToObject")]
13-
private static partial void ComWeakRefToObject(IntPtr pComWeakRef, long wrapperId, ObjectHandleOnStack retRcw);
13+
private static partial void ComWeakRefToObject(IntPtr pComWeakRef, ObjectHandleOnStack retRcw);
1414

15-
internal static object? ComWeakRefToObject(IntPtr pComWeakRef, long wrapperId)
15+
internal static object? ComWeakRefToObject(IntPtr pComWeakRef, object? context)
1616
{
17-
object? retRcw = null;
18-
ComWeakRefToObject(pComWeakRef, wrapperId, ObjectHandleOnStack.Create(ref retRcw));
19-
return retRcw;
17+
if (context is null)
18+
{
19+
// This wrapper was not created by ComWrappers, so we try to rehydrate using built-in COM.
20+
object? retRcw = null;
21+
ComWeakRefToObject(pComWeakRef, ObjectHandleOnStack.Create(ref retRcw));
22+
return retRcw;
23+
}
24+
25+
return ComWeakRefToComWrappersObject(pComWeakRef, context);
2026
}
2127

2228
[MethodImpl(MethodImplOptions.AggressiveInlining)]
@@ -40,17 +46,24 @@ internal static unsafe bool PossiblyComObject(object target)
4046
internal static extern bool HasInteropInfo(object target);
4147

4248
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ObjectToComWeakRef")]
43-
private static partial IntPtr ObjectToComWeakRef(ObjectHandleOnStack retRcw, out long wrapperId);
49+
private static partial IntPtr ObjectToComWeakRef(ObjectHandleOnStack retRcw);
4450

45-
internal static nint ObjectToComWeakRef(object target, out long wrapperId)
51+
internal static nint ObjectToComWeakRef(object target, out object? context)
4652
{
47-
if (HasInteropInfo(target))
53+
if (!HasInteropInfo(target))
54+
{
55+
context = null;
56+
return IntPtr.Zero;
57+
}
58+
59+
if (target is __ComObject)
4860
{
49-
return ObjectToComWeakRef(ObjectHandleOnStack.Create(ref target), out wrapperId);
61+
// This object is using built-in COM, so use built-in COM to create the weak reference.
62+
context = null;
63+
return ObjectToComWeakRef(ObjectHandleOnStack.Create(ref target));
5064
}
5165

52-
wrapperId = 0;
53-
return IntPtr.Zero;
66+
return ComWrappersObjectToComWeakRef(target, out context);
5467
}
5568
}
5669
}

src/coreclr/System.Private.CoreLib/src/System/GC.CoreCLR.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ internal enum GC_ALLOC_FLAGS
106106
private static partial long GetTotalMemory();
107107

108108
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "GCInterface_Collect")]
109-
private static partial void _Collect(int generation, int mode);
109+
private static partial void _Collect(int generation, int mode, [MarshalAs(UnmanagedType.U1)] bool lowMemoryPressure);
110110

111111
[MethodImpl(MethodImplOptions.InternalCall)]
112112
private static extern int GetMaxGeneration();
@@ -174,7 +174,7 @@ public static void Collect(int generation)
174174
public static void Collect()
175175
{
176176
// -1 says to GC all generations.
177-
_Collect(-1, (int)InternalGCCollectionMode.Blocking);
177+
_Collect(-1, (int)InternalGCCollectionMode.Blocking, lowMemoryPressure: false);
178178
}
179179

180180
public static void Collect(int generation, GCCollectionMode mode)
@@ -189,6 +189,11 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking)
189189
}
190190

191191
public static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting)
192+
{
193+
Collect(generation, mode, blocking, compacting, lowMemoryPressure: false);
194+
}
195+
196+
internal static void Collect(int generation, GCCollectionMode mode, bool blocking, bool compacting, bool lowMemoryPressure)
192197
{
193198
ArgumentOutOfRangeException.ThrowIfNegative(generation);
194199

@@ -197,7 +202,6 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking,
197202
throw new ArgumentOutOfRangeException(nameof(mode), SR.ArgumentOutOfRange_Enum);
198203
}
199204

200-
201205
int iInternalModes = 0;
202206

203207
if (mode == GCCollectionMode.Optimized)
@@ -222,7 +226,9 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking,
222226
}
223227

224228
if (compacting)
229+
{
225230
iInternalModes |= (int)InternalGCCollectionMode.Compacting;
231+
}
226232

227233
if (blocking)
228234
{
@@ -233,7 +239,7 @@ public static void Collect(int generation, GCCollectionMode mode, bool blocking,
233239
iInternalModes |= (int)InternalGCCollectionMode.NonBlocking;
234240
}
235241

236-
_Collect(generation, iInternalModes);
242+
_Collect(generation, (int)iInternalModes, lowMemoryPressure);
237243
}
238244

239245
public static int CollectionCount(int generation)

0 commit comments

Comments
 (0)