Skip to content

WIP: Add RefScanPolicy to object-scanning methods of Scanning#1437

Draft
wks wants to merge 11 commits intommtk:masterfrom
wks:feature/weakref-scan-api
Draft

WIP: Add RefScanPolicy to object-scanning methods of Scanning#1437
wks wants to merge 11 commits intommtk:masterfrom
wks:feature/weakref-scan-api

Conversation

@wks
Copy link
Collaborator

@wks wks commented Dec 17, 2025

We add a RefScanPolicy type parameter in object-scanning functions (scan_object and scan_object_and_trace_edges) in the Scanning trait. It tells the VM binding whether it should visit strong and/or weak reference fields using the callback argument, and whether it should "discover" weak references in VM-specific ways if the VM chooses to do so.

This PR is intended to pave a path for porting the OpenJDK-style reference processing from the lxr branch and eventually supporting LXR.

We also made some minor changes to the object-scanning functions.

  • The tls parameter of support_slot_enqueuing, scan_object and scan_object_and_trace_edges is now VMThread instead of VMWorkerThread. This allows mutator threads to scan objects in write barriers without a workaround.
  • The SlotVisitor and ObjectTracer type parameters are replaced with implicit impl types. Because object-scanning functions now take an explicit RefScanPolicy type parameter, we make SlotVisitor and ObjectTracer implicit to avoid the unnecessary _ like in scan_object::<_, ref_scan_policy::Closure>.

TODO:

  • Check what's missing by comparing with the lxr branch.
  • Fix bindings.
  • Decide whether we should add a RefScanPolicy implementation for barriers. We just use ref_scan_poilcy::StrongOnly for the SATB barrier.

Fixes: #1376
Fixes: #1375

wks added 11 commits December 17, 2025 19:54
The VM binding only needs to know the `RefScanPolicy` trait but not its
implementations.
"StrongClosure" and "StrongOnly" are too similar.
This makes the type parameter implicit and make it unnecessary to write
`<_, Closure>`.
Otherwise `Closure` may be ambiguous.  This also makes it looks like the
`EnumName::Variant` style.
We change the `tls` from `VMWorkerThread` to `VMThread` because mutator
threads can also scan objects in write barriers.
wks added a commit to wks/mmtk-openjdk that referenced this pull request Feb 3, 2026
mmtk-core introduced `RefScanPolicy` in object-scanning functions.  We
selectively visit strong and/or weak references according to the
`RefScanPolicy`.

Related PR: mmtk/mmtk-core#1437
@wks
Copy link
Collaborator Author

wks commented Feb 3, 2026

binding-refs
OPENJDK21_BINDING_REPO=wks/mmtk-openjdk
OPENJDK21_BINDING_REF=feature/weakref-scan-api

@wks wks mentioned this pull request Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Communicate intention for weak references when scanning objects New object-scanning API for barriers

1 participant