Skip to content

Commit 0971cda

Browse files
wksqinsoon
authored andcommitted
Split will_oom_on_acquire
1 parent 03dfc5a commit 0971cda

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

src/policy/space.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,17 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
6767
/// avoid arithmatic overflow. If we have to do computation in the allocation fastpath and
6868
/// overflow happens there, there is nothing we can do about it.
6969
/// Return a boolean to indicate if we will be out of memory, determined by the check.
70-
fn will_oom_on_acquire(&self, tls: VMThread, size: usize, allow_oom_call: bool) -> bool {
70+
fn will_oom_on_acquire(&self, size: usize) -> bool {
7171
let max_pages = self.get_gc_trigger().policy.get_max_heap_size_in_pages();
7272
let requested_pages = size >> LOG_BYTES_IN_PAGE;
73-
if requested_pages > max_pages {
73+
requested_pages > max_pages
74+
}
75+
76+
/// Check if the requested `size` is an obvious out-of-memory case using
77+
/// [`Self::will_oom_on_acquire`] and, if it is, call `Collection::out_of_memory`. Return the
78+
/// result of `will_oom_on_acquire`.
79+
fn handle_obvious_oom_request(&self, tls: VMThread, size: usize, allow_oom_call: bool) -> bool {
80+
if self.will_oom_on_acquire(size) {
7481
if allow_oom_call {
7582
VM::VMCollection::out_of_memory(
7683
tls,
@@ -90,7 +97,7 @@ pub trait Space<VM: VMBinding>: 'static + SFT + Sync + Downcast {
9097
);
9198

9299
debug_assert!(
93-
!self.will_oom_on_acquire(tls, pages << LOG_BYTES_IN_PAGE, !no_gc_on_fail),
100+
!self.will_oom_on_acquire(pages << LOG_BYTES_IN_PAGE),
94101
"The requested pages is larger than the max heap size. Is will_go_oom_on_acquire used before acquring memory?"
95102
);
96103

src/util/alloc/bumpallocator.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ impl<VM: VMBinding> BumpAllocator<VM> {
196196
) -> Address {
197197
if self
198198
.space
199-
.will_oom_on_acquire(self.tls, size, !self.get_context().is_no_gc_on_fail())
199+
.handle_obvious_oom_request(self.tls, size, !self.get_context().is_no_gc_on_fail())
200200
{
201201
return Address::ZERO;
202202
}

src/util/alloc/large_object_allocator.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ impl<VM: VMBinding> Allocator<VM> for LargeObjectAllocator<VM> {
4949
}
5050

5151
fn alloc_slow_once(&mut self, size: usize, align: usize, _offset: usize) -> Address {
52-
if self
53-
.space
54-
.will_oom_on_acquire(self.tls, size, !self.get_context().is_no_gc_on_fail())
55-
{
52+
if self.space.handle_obvious_oom_request(
53+
self.tls,
54+
size,
55+
!self.get_context().is_no_gc_on_fail(),
56+
) {
5657
return Address::ZERO;
5758
}
5859

0 commit comments

Comments
 (0)