Skip to content

Commit 3e27334

Browse files
Demote re-registered nmethods (#336)
If an nmethod is in the mature roots and the nmethod is re-registered due to code patching, the nmethod will appear in both the nursery roots and the mature roots for one collection, causing some roots to be scanned twice. This PR removes an nmethod from the mature roots, when the nmethod is re-registered, so that the nmethod will only be present in the nursery.
1 parent 48128b8 commit 3e27334

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

mmtk/src/api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,13 @@ pub extern "C" fn mmtk_register_nmethod(nm: Address) {
512512
NMETHOD_SLOTS.with_borrow_mut(|slots| {
513513
if !slots.is_empty() {
514514
let mut roots = crate::NURSERY_CODE_CACHE_ROOTS.lock().unwrap();
515+
let mut mature_roots = crate::MATURE_CODE_CACHE_ROOTS.lock().unwrap();
516+
// The nmethod might already be in the mature roots, if we
517+
// are re-registering the nmethod due to code patching.
518+
// If the nmethod is already in the mature roots, we demote
519+
// the nmethod to the nursery roots, as the nmethod might
520+
// now refer to a young object.
521+
mature_roots.remove(&nm);
515522
roots.insert(nm, std::mem::take(slots));
516523
}
517524
});

0 commit comments

Comments
 (0)