Skip to content

Allow objects to span multiple contiguous blocks for bump allocator #1298

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 2 commits into from
Closed
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
19 changes: 17 additions & 2 deletions src/util/alloc/bumpallocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,29 @@ impl<VM: VMBinding> BumpAllocator<VM> {
acquired_start
);
if !stress_test {
self.set_limit(acquired_start, acquired_start + block_size);
// If the new block is contiguous to the previous one, we can let the
// allocation span multiple blocks. This reduces wasted space, specially in the
// single-threaded GC case.
let start = if self.bump_pointer.limit == acquired_start {
self.bump_pointer.cursor
} else {
acquired_start
};
self.set_limit(start, acquired_start + block_size);
self.alloc(size, align, offset)
} else {
// For a stress test, we artificially make the fastpath fail by
// manipulating the limit as below.
// The assumption here is that we use an address range such that
// cursor > block_size always.
self.set_limit(acquired_start, unsafe { Address::from_usize(block_size) });
let start = if self.bump_pointer.cursor + self.bump_pointer.limit.as_usize()
== acquired_start
{
self.bump_pointer.cursor
} else {
acquired_start
};
self.set_limit(start, unsafe { Address::from_usize(block_size) });
// Note that we have just acquired a new block so we know that we don't have to go
// through the entire allocation sequence again, we can directly call the slow path
// allocation.
Expand Down