Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unique object enqueuing option #1255

Merged
merged 3 commits into from
Jan 9, 2025
Merged

Unique object enqueuing option #1255

merged 3 commits into from
Jan 9, 2025

Conversation

wks
Copy link
Collaborator

@wks wks commented Jan 7, 2025

Added a constant VMBinding::UNIQUE_OBJECT_ENQUEUING. When set to true, MMTk will guarantee that each object is enqueued at most once in each GC. This can be useful for VMs that piggyback on object scanning to visit objects during GC.

Implementation-wise, the mark bit is set atomically when VMBinding::UNIQUE_OBJECT_ENQUEUING is true. This PR only affects the native MarkSweep space. Other spaces already do this atomically.

Fixes: #1254

Added a constant `VMBinding::UNIQUE_OBJECT_ENQUEUING`.  When set to
true, MMTk will guarantee that each object is enqueued at most once in
each GC.  This can be useful for VMs that piggyback on object scanning
to visit objects during GC.

Implementation-wise, the mark bit is set atomically when
`VMBinding::UNIQUE_OBJECT_ENQUEUING` is true.  This PR only affects the
native MarkSweep space.  Other spaces already do this atomically.

Fixes: mmtk#1254
@wks
Copy link
Collaborator Author

wks commented Jan 7, 2025

This PR intends to fix the immediate problem of MarkSweep enqueuing objects multiple times, which may crash the Ruby binding when there are multiple GC workers and the plan is MarkSweep.

I observed that MarkSweepSpace and ImmixSpace do object marking completely differently, and there are code fragments related to marking scattered in ImmixSpace, impl VMLocalMarkBitSpec and impl MarkState. We should do a larger scale refactoring to make all spaces use the MarkState struct. I plan to do it later because it may need more careful performance evaluation.

@k-sareen
Copy link
Collaborator

k-sareen commented Jan 7, 2025

Re: MarkState refactoring. Yeah I've done it in my branch, but you have to be careful since you can't use it for LOS. LOS mark bits are 2-bits per page not 1-bit per valid object. You could probably just cherry-pick the commit from here: k-sareen@c31c80e

@wks
Copy link
Collaborator Author

wks commented Jan 9, 2025

The "Public API Check" failed. This PR introduces a new API pub const mmtk::vm::VMBinding::UNIQUE_OBJECT_ENQUEUING: bool, but it has a default value false so it won't break existing bindings.

@wks wks marked this pull request as ready for review January 9, 2025 03:44
Copy link
Member

@qinsoon qinsoon left a comment

Choose a reason for hiding this comment

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

Just a minor suggestion. Otherwise it looks good to me.

src/vm/mod.rs Outdated
/// override this if they need. For example, some VMs piggyback on object-scanning to visit
/// objects during a GC, but may have data race if multiple GC workers visit the same object at
/// the same time. Such VMs can set this constant to `true` to workaround this problem.
const UNIQUE_OBJECT_ENQUEUING: bool = false;
Copy link
Member

Choose a reason for hiding this comment

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

We can move this to the Scanning trait. It seems only relevant for scanning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I moved it to the Scanning trait.

@wks wks enabled auto-merge January 9, 2025 06:05
@k-sareen
Copy link
Collaborator

k-sareen commented Jan 9, 2025

Should update may_trace_duplicate_edges to be equal to the constant for MS

@wks wks added this pull request to the merge queue Jan 9, 2025
@wks
Copy link
Collaborator Author

wks commented Jan 9, 2025

Should update may_trace_duplicate_edges to be equal to the constant for MS

It's a bit hard for the current implementation because PlanConstraint is not parameterized with <VM: VMBinding>, but the feature is controlled by Scanning::UNIQUE_OBJECT_ENQUEUING.

Merged via the queue into mmtk:master with commit 68bf1b6 Jan 9, 2025
31 of 33 checks passed
@wks wks deleted the fix/native-ms-marking branch January 9, 2025 07:41
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.

Native MarkSweep is not marking objects atomically.
3 participants