-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch CoreCLR WeakReference to unified managed implementation #77196
Merged
Merged
Changes from 28 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
4b6a696
Delete managed CoreClr WR
VSadov 079818b
all but com works
VSadov 1dafd25
COM tests are passing
VSadov 30636bc
HandleTagBits const for NativeAot
VSadov 5876f7b
Exclusive Set
VSadov 9d7636c
fix
VSadov 109e7a6
Use sign bit
VSadov 628f8c3
Platforms not supporting COM can mask only one bit.
VSadov 9ad5897
new approach
VSadov bf57457
fix mono build
VSadov a917cff
check for FEATURE_COMWRAPPERS too
VSadov d42dca3
stub NativeAOT support (NYI).
VSadov b089f32
current
VSadov 333ae9f
moved handle tags on the managed side to one location
VSadov 99f299e
Getter optimizations
VSadov a119ad6
Optimizations for Setter
VSadov 3f1de5a
accessibility of some members
VSadov c4624ec
ensure identity of the rehydrated RCW
VSadov 92787ab
make ComWeakRefToObject a QCall
VSadov 22b7507
delete unused pWeakReferenceOfTCanonMT and pWeakReferenceMT
VSadov 87055ed
byte-aligned
VSadov 1a89e73
cleanup unreachable code
VSadov e709dfb
renamed WeakReferenceObject::m_Handle -> WeakReferenceObject::m_tagge…
VSadov e51f50c
Apply suggestions from code review
VSadov 06d66e3
some PR feedback
VSadov 9bbbdb5
GetWeakHandle no longer cares about inlining.
VSadov 90dd2bb
turn ObjectToComWeakRef into a QCall
VSadov ea7c3ee
revert changes under coreclr\gc
VSadov a5a8a98
added a note to eventually remove HNDTYPE_WEAK_NATIVE_COM
VSadov 230a3e6
Update src/coreclr/gc/gcinterface.h
VSadov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean that SOS no longer has insight into weak references?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regular weak references did not change from the introspection point of view.
The thing that changed is that there is no need to special case native COM weak handles, since they no longer exist. The implementation uses regular managed objects now and they will be reachable in SOS walks like any other managed object.