Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,14 @@ internal static unsafe bool ObjectHasComponentSize(object obj)
return GetMethodTable(obj)->HasComponentSize;
}

// Returns true iff the type of the object declares a finalizer.
// Callers are required to keep obj alive
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe bool ObjectHasFinalizer(object obj)
{
return GetMethodTable(obj)->HasFinalizer;
}

/// <summary>
/// Boxes a given value using an input <see cref="MethodTable"/> to determine its type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,14 @@ internal static unsafe bool ObjectHasComponentSize(object obj)
return GetMethodTable(obj)->HasComponentSize;
}

// Returns true iff the type of the object declares a finalizer.
// Callers are required to keep obj alive
[MethodImpl(MethodImplOptions.AggressiveInlining)]
internal static unsafe bool ObjectHasFinalizer(object obj)
{
return GetMethodTable(obj)->IsFinalizable;
}

public static void PrepareMethod(RuntimeMethodHandle method)
{
if (method.Value == IntPtr.Zero)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ internal static void DetachNonPromotedObjects()
ReferenceTrackerNativeObjectWrapper? nativeObjectWrapper = Unsafe.As<ReferenceTrackerNativeObjectWrapper>(weakNativeObjectWrapperHandle.Target);
if (nativeObjectWrapper != null &&
nativeObjectWrapper.TrackerObject != IntPtr.Zero &&
!RuntimeImports.RhIsPromoted(nativeObjectWrapper.ProxyHandle.Target))
nativeObjectWrapper.ProxyHandle.TryGetTarget(out object? proxyTarget) &&
!RuntimeImports.RhIsPromoted(proxyTarget))
{
// Notify the wrapper it was not promoted and is being collected.
BeforeWrapperFinalized(nativeObjectWrapper.TrackerObject);
Expand All @@ -205,9 +206,9 @@ internal static unsafe class FindReferenceTargetsCallback
internal ref struct Instance
{
private readonly IntPtr _vtable; // First field is IUnknown based vtable.
public GCHandle RootObject;
public WeakGCHandle<object> RootObject;

public Instance(GCHandle handle)
public Instance(WeakGCHandle<object> handle)
{
_vtable = (IntPtr)Unsafe.AsPointer(in FindReferenceTargetsCallback.Vftbl);
RootObject = handle;
Expand Down Expand Up @@ -240,7 +241,7 @@ private static unsafe int IFindReferenceTargetsCallback_FoundTrackerTarget(IntPt
return HResults.E_POINTER;
}

object sourceObject = ((FindReferenceTargetsCallback.Instance*)pThis)->RootObject.Target!;
_ = ((FindReferenceTargetsCallback.Instance*)pThis)->RootObject.TryGetTarget(out object? sourceObject);

if (!TryGetObject(referenceTrackerTarget, out object? targetObject))
{
Expand Down
Loading
Loading