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

Why is ImmixAllocator reset twice? #959

Closed
wks opened this issue Sep 24, 2023 · 1 comment · Fixed by #964
Closed

Why is ImmixAllocator reset twice? #959

wks opened this issue Sep 24, 2023 · 1 comment · Fixed by #964

Comments

@wks
Copy link
Collaborator

wks commented Sep 24, 2023

In src/plan/immix/mutator.rs:

pub fn immix_mutator_prepare<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
    let immix_allocator = unsafe {
        mutator
            .allocators
            .get_allocator_mut(mutator.config.allocator_mapping[AllocationSemantics::Default])
    }
    .downcast_mut::<ImmixAllocator<VM>>()
    .unwrap();
    immix_allocator.reset();
}

pub fn immix_mutator_release<VM: VMBinding>(mutator: &mut Mutator<VM>, _tls: VMWorkerThread) {
    let immix_allocator = unsafe {
        mutator
            .allocators
            .get_allocator_mut(mutator.config.allocator_mapping[AllocationSemantics::Default])
    }
    .downcast_mut::<ImmixAllocator<VM>>()
    .unwrap();
    immix_allocator.reset();
}

The immix_allocator.reset() invocation does the following:

impl<VM: VMBinding> ImmixAllocator<VM> {
    pub fn reset(&mut self) {
        self.bump_pointer.reset(Address::ZERO, Address::ZERO);
        self.large_bump_pointer.reset(Address::ZERO, Address::ZERO);
        self.request_for_large = false;
        self.line = None;
    }
}

This method is idempotent, and we don't touch the allocators during GC. Why do we need to reset the ImmixAllocator in both prepare_func and release_func?

p.s. This behaviour exists in JikesRVM, and it has behaved like this ever since Immix was introduced into JikesRVM MMTk.

@wks
Copy link
Collaborator Author

wks commented Sep 24, 2023

One possible explanation is that it intended to reset ImmixCollector.copy (the counterpart of ImmixCopyContext::copy_allocator in Rust MMTk) during the PREPARE phase because it is used for evacuating objects. But it mistakenly reset the ImmixAllocator of the mutator, instead.

github-merge-queue bot pushed a commit that referenced this issue Sep 29, 2023
Some plans do nothing when preparing mutators. We add a boolean flag so
that we do not create the PrepareMutator work packets in the first
place.

We also remove the function that prepares Mutator for Immix. It is
unnecessary to reset the ImmixAllocator of a mutator when preparing
mutator because the mutator's ImmixAllocator is not used during GC. When
a GC worker defragments the heap and promotes young objects, it uses the
ImmixAllocator instances in ImmixCopyContext or ImmixHybridCopyContext.

Fixes: #959
@wks wks closed this as completed in #964 Sep 29, 2023
qinsoon added a commit to qinsoon/mmtk-core that referenced this issue Oct 3, 2023
Some plans do nothing when preparing mutators. We add a boolean flag so
that we do not create the PrepareMutator work packets in the first
place.

We also remove the function that prepares Mutator for Immix. It is
unnecessary to reset the ImmixAllocator of a mutator when preparing
mutator because the mutator's ImmixAllocator is not used during GC. When
a GC worker defragments the heap and promotes young objects, it uses the
ImmixAllocator instances in ImmixCopyContext or ImmixHybridCopyContext.

Fixes: mmtk#959
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant