Skip to content

Move prepare/release/end_of_gc to trait Space #1315

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

Closed
wants to merge 1 commit into from

Conversation

qinsoon
Copy link
Member

@qinsoon qinsoon commented May 9, 2025

No description provided.

@qinsoon qinsoon marked this pull request as ready for review May 9, 2025 03:15
@qinsoon qinsoon requested a review from wks May 9, 2025 03:15
Copy link
Collaborator

@wks wks left a comment

Choose a reason for hiding this comment

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

After a second thought, I think it is not a good idea to "unify" the prepare, release and end_of_gc methods into the Space trait.

The obvious problem is the arg argument in prepare. Actually each space expects a specific arg type. Specifically, CopySpace expects a bool, while ImmixSpace expects a StatsForDefrag. Making it a Option<Box<dyn std::any::Any>> simply makes it dynamically types, and errors when passing the argument cannot be detected until run time. On the contrary, when using existing way, the Plan knows the concrete types of its spaces, and calls the prepare methods of each space differently, providing exactly what type of argument required. And that's type-checked by the Rust compiler.

The purpose of this PR is to support the polymorphic non-moving space (#1308). The prepare method is still called differently depending on the concrete space type.

In my refactoring I made a trait NonMovingSpace and its prepare_nonmoving_space takes only a full_heap parameter (passed to major_gc in prepare of some spaces). I admit that it is not general, either. It only works coincidentally because full_heap happens to be the union of all arguments of ImmortalSpace, MarkSweepSpace and ImmixSpace.


// Prepare defrag info
if self.is_defrag_enabled() {
let plan_stats = arg.unwrap().downcast::<StatsForDefrag>().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means ImmixSpace is expecting a StatesForDefrag argument.

@@ -138,6 +139,39 @@ impl<VM: VMBinding> Space<VM> for CopySpace<VM> {
fn enumerate_objects(&self, enumerator: &mut dyn ObjectEnumerator) {
object_enum::enumerate_blocks_from_monotonic_page_resource(enumerator, &self.pr);
}

fn prepare(&mut self, _major_gc: bool, arg: Option<Box<dyn Any>>) {
let is_from_space = arg.unwrap().downcast::<bool>().unwrap();
Copy link
Collaborator

Choose a reason for hiding this comment

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

This means CopySpace expects a bool

@qinsoon
Copy link
Member Author

qinsoon commented May 9, 2025

After a second thought, I think it is not a good idea to "unify" the prepare, release and end_of_gc methods into the Space trait.

I am okay with closing this PR. That means we understand that most spaces have prepare/release/end_of_gc, but we allow those functions to have different signatures, and we do not intend to call those functions in a unified way.

@qinsoon
Copy link
Member Author

qinsoon commented May 9, 2025

See the discussion in this PR and in #1316. We do not want to do this change for now.

@qinsoon qinsoon closed this May 9, 2025
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.

2 participants