-
Couldn't load subscription status.
- Fork 78
Refactor Space::acquire #1401
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
Refactor Space::acquire #1401
Conversation
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.
The closure doesn't return zero.
src/policy/space.rs
Outdated
| if let Some(addr) = self.get_new_pages_and_initialize(pr, pages_reserved, pages, tls) { | ||
| addr | ||
| } else { | ||
| on_gc_required(true); |
There was a problem hiding this comment.
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
}
src/policy/space.rs
Outdated
|
|
||
| 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| { |
There was a problem hiding this comment.
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.
Make it consistent with the order variables are introduced.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.
panic!instead ofassert!.on_pending_allocationalways includes metadata size.