From be8504bd8a63962c84567990f0b84019f299166c Mon Sep 17 00:00:00 2001 From: Sean Gillespie Date: Wed, 5 Apr 2017 09:57:50 -0700 Subject: [Local GC] Move Weak Reference finalization out of the GC (#10676) * [Local GC] Move Weak Reference finalization out of the GC * Address two issues: 1) Use GetGCSafeMethodTable instead of GetMethodTable, so that the mark bit is correctly masked off the object's method table pointer, 2) Address code review feedback by re-inserting a missed call to GetCanonicalMethodTable and rename the new API to EagerFinalized to better illustrate its broader purpose. * Repair the GC sample --- src/vm/gcenv.ee.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/vm/gcenv.ee.cpp') diff --git a/src/vm/gcenv.ee.cpp b/src/vm/gcenv.ee.cpp index f3c139e66d..a652359c4f 100644 --- a/src/vm/gcenv.ee.cpp +++ b/src/vm/gcenv.ee.cpp @@ -29,6 +29,15 @@ #include "comcallablewrapper.h" #endif // FEATURE_COMINTEROP +// the method table for the WeakReference class +extern MethodTable* pWeakReferenceMT; + +// The canonical method table for WeakReference +extern MethodTable* pWeakReferenceOfTCanonMT; + +// Finalizes a weak reference directly. +extern void FinalizeWeakReference(Object* obj); + void GCToEEInterface::SuspendEE(SUSPEND_REASON reason) { WRAPPER_NO_CONTRACT; @@ -1359,3 +1368,16 @@ bool GCToEEInterface::ShouldFinalizeObjectForUnload(AppDomain* pDomain, Object* // to move them to a new app domain instead of finalizing them here. return true; } + +bool GCToEEInterface::EagerFinalized(Object* obj) +{ + MethodTable* pMT = obj->GetGCSafeMethodTable(); + if (pMT == pWeakReferenceMT || + pMT->GetCanonicalMethodTable() == pWeakReferenceOfTCanonMT) + { + FinalizeWeakReference(obj); + return true; + } + + return false; +} -- cgit v1.2.3