Skip to content
Merged
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
7 changes: 7 additions & 0 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,13 @@ pub extern "C" fn mmtk_register_nmethod(nm: Address) {
NMETHOD_SLOTS.with_borrow_mut(|slots| {
if !slots.is_empty() {
let mut roots = crate::NURSERY_CODE_CACHE_ROOTS.lock().unwrap();
let mut mature_roots = crate::MATURE_CODE_CACHE_ROOTS.lock().unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Holding two locks at the same time is prone to dead-locking, especially when ScanCodeCacheRoots::do_work acquires the two locks in the opposite order. One way to fix it is putting the two hash maps under the same lock. I refactored this part of code locally when trying to address the "fix relocation" thing, but haven't merged it yet because it is somewhat unrelated to the "fix relocation" itself. I'll make another pull request later for the refactoring.

// The nmethod might already be in the mature roots, if we
// are re-registering the nmethod due to code patching.
// If the nmethod is already in the mature roots, we demote
// the nmethod to the nursery roots, as the nmethod might
// now refer to a young object.
mature_roots.remove(&nm);
roots.insert(nm, std::mem::take(slots));
}
});
Expand Down
Loading