Skip to content

[NativeAOT] Implement GCToEEInterface::EagerFinalized #75107

@VSadov

Description

@VSadov

WeakReference has a special codepath in GC to finalize eagerly, which avoids using finalizer queue. We could easily do that in NativeAOT as well, if we could tell if an instance is a WeakReference or WeakReference<T>

Weak references could be used in big quantities, so such optimization would be a noticeable improvement.

There is also a subtle correctness issue.
If, for example, a weakref getter runs concurrently with finalizer and the handle gets recycled for an object of a different type, it could result in a GC hole.
On the other hand eager finalization is run by GC when objects transition from Reachable to F-Reachable. There is no way for that to happen concurrently with getter, so handle recycling is not a problem.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions