Skip to content

Conversation

wks
Copy link
Collaborator

@wks wks commented Oct 10, 2025

We extract portions of that function into separate functions or lambda expressions in order to make the main decision tree logic terse.

We do not intend to change the logic of this function, but we fix some obvious bugs in this commit.

  • It is a runtime error if we need GC but GC is not initialized. We use panic! instead of assert!.
  • Now the value passed to on_pending_allocation always includes metadata size.

We extract portions of that function into separate functions or lambda
expressions in order to make the main decision tree logic terse.

We do not intend to change the logic of this function, but we fix some
obvious bugs in this commit.

-   It is a runtime error if we need GC but GC is not initialized.  We
    use `panic!` instead of `assert!`.
-   Now the value passed to `on_pending_allocation` always includes
    metadata size.
@wks wks mentioned this pull request Oct 10, 2025
@wks wks added the PR-extended-testing Run extended tests for the pull request label Oct 10, 2025
The closure doesn't return zero.
@wks wks requested a review from qinsoon October 13, 2025 02:00
if let Some(addr) = self.get_new_pages_and_initialize(pr, pages_reserved, pages, tls) {
addr
} else {
on_gc_required(true);
Copy link
Member

Choose a reason for hiding this comment

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

This is a bit confusing: GC is not required at this point, and on_gc_required will actually require GC.

Maybe you could just do something like below:

if let Some(addr) = self.get_new_pages_and_initialize(pr, pages_reserved, pages, tls) {
    addr
} else {
    if alloc_options.on_fail.allow_gc() {
        // We thought we had memory to allocate, but somehow failed the allocation. Will force a GC.
        let gc_performed = self.get_gc_trigger().poll(true, Some(self.as_space()));
        debug_assert!(gc_performed, "GC not performed when forced.");
    
        on_gc_required();   
    }    
    Address::ZERO
}


if should_poll && self.get_gc_trigger().poll(false, Some(self.as_space())) {
// Handle the case that GC is required.
let on_gc_required = |attempted_allocation_and_failed: bool| {
Copy link
Member

Choose a reason for hiding this comment

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

This can be extracted as a new method, like what you did with get_new_pages_and_initialize.

wks added 2 commits October 13, 2025 11:19
Make it consistent with the order variables are introduced.
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.

LGTM

@wks wks added this pull request to the merge queue Oct 13, 2025
Merged via the queue into mmtk:master with commit e845077 Oct 13, 2025
33 checks passed
@wks wks deleted the fix/reorganize-space-acquire2 branch October 13, 2025 06:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PR-extended-testing Run extended tests for the pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants