-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch CoreCLR WeakReference to unified managed implementation (#77196)
* Delete managed CoreClr WR * all but com works * COM tests are passing * HandleTagBits const for NativeAot * Exclusive Set * fix * Use sign bit * Platforms not supporting COM can mask only one bit. * new approach * fix mono build * check for FEATURE_COMWRAPPERS too * stub NativeAOT support (NYI). * current * moved handle tags on the managed side to one location * Getter optimizations * Optimizations for Setter * accessibility of some members * ensure identity of the rehydrated RCW * make ComWeakRefToObject a QCall * delete unused pWeakReferenceOfTCanonMT and pWeakReferenceMT * byte-aligned * cleanup unreachable code * renamed WeakReferenceObject::m_Handle -> WeakReferenceObject::m_taggedHandle * Apply suggestions from code review Co-authored-by: Aaron Robinson <[email protected]> * some PR feedback * GetWeakHandle no longer cares about inlining. * turn ObjectToComWeakRef into a QCall * revert changes under coreclr\gc * added a note to eventually remove HNDTYPE_WEAK_NATIVE_COM * Update src/coreclr/gc/gcinterface.h Co-authored-by: Maoni Stephens <[email protected]> Co-authored-by: Aaron Robinson <[email protected]> Co-authored-by: Maoni Stephens <[email protected]>
- Loading branch information
1 parent
e0c9353
commit 7d2de49
Showing
38 changed files
with
540 additions
and
1,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/coreclr/System.Private.CoreLib/src/System/ComAwareWeakReference.CoreCLR.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
#if FEATURE_COMINTEROP || FEATURE_COMWRAPPERS | ||
namespace System | ||
{ | ||
internal sealed partial class ComAwareWeakReference | ||
{ | ||
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ComWeakRefToObject")] | ||
private static partial void ComWeakRefToObject(IntPtr pComWeakRef, long wrapperId, ObjectHandleOnStack retRcw); | ||
|
||
internal static object? ComWeakRefToObject(IntPtr pComWeakRef, long wrapperId) | ||
{ | ||
object? retRcw = null; | ||
ComWeakRefToObject(pComWeakRef, wrapperId, ObjectHandleOnStack.Create(ref retRcw)); | ||
return retRcw; | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
internal static unsafe bool PossiblyComObject(object target) | ||
{ | ||
// see: syncblk.h | ||
const int IS_HASHCODE_BIT_NUMBER = 26; | ||
const int BIT_SBLK_IS_HASHCODE = 1 << IS_HASHCODE_BIT_NUMBER; | ||
const int BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX = 0x08000000; | ||
|
||
fixed (byte* pRawData = &target.GetRawData()) | ||
{ | ||
// The header is 4 bytes before MT field on all architectures | ||
int header = *(int*)(pRawData - sizeof(IntPtr) - sizeof(int)); | ||
// common case: target does not have a syncblock, so there is no interop info | ||
return (header & (BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX | BIT_SBLK_IS_HASHCODE)) == BIT_SBLK_IS_HASH_OR_SYNCBLKINDEX; | ||
} | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.InternalCall)] | ||
internal static extern bool HasInteropInfo(object target); | ||
|
||
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ObjectToComWeakRef")] | ||
private static partial IntPtr ObjectToComWeakRef(ObjectHandleOnStack retRcw, out long wrapperId); | ||
|
||
internal static nint ObjectToComWeakRef(object target, out long wrapperId) | ||
{ | ||
if (HasInteropInfo(target)) | ||
{ | ||
return ObjectToComWeakRef(ObjectHandleOnStack.Create(ref target), out wrapperId); | ||
} | ||
|
||
wrapperId = 0; | ||
return IntPtr.Zero; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 0 additions & 52 deletions
52
src/coreclr/System.Private.CoreLib/src/System/WeakReference.CoreCLR.cs
This file was deleted.
Oops, something went wrong.
46 changes: 0 additions & 46 deletions
46
src/coreclr/System.Private.CoreLib/src/System/WeakReference.T.CoreCLR.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/coreclr/nativeaot/System.Private.CoreLib/src/System/ComAwareWeakReference.NativeAot.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System; | ||
|
||
#if FEATURE_COMINTEROP || FEATURE_COMWRAPPERS | ||
namespace System | ||
{ | ||
internal sealed partial class ComAwareWeakReference | ||
{ | ||
internal static object? ComWeakRefToObject(IntPtr pComWeakRef, long wrapperId) | ||
{ | ||
// NativeAOT support for COM WeakReference is NYI | ||
throw new NotImplementedException(); | ||
} | ||
|
||
internal static bool PossiblyComObject(object target) | ||
{ | ||
// NativeAOT support for COM WeakReference is NYI | ||
return false; | ||
} | ||
|
||
internal static IntPtr ObjectToComWeakRef(object target, out long wrapperId) | ||
{ | ||
// NativeAOT support for COM WeakReference is NYI | ||
wrapperId = 0; | ||
return 0; | ||
} | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.