Skip to content

Commit a4401ce

Browse files
committed
Allow VM to query if the current GC moves objects.
1 parent 698a737 commit a4401ce

File tree

10 files changed

+49
-0
lines changed

10 files changed

+49
-0
lines changed

src/plan/generational/copying/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ impl<VM: VMBinding> Plan for GenCopy<VM> {
127127
self.gen.get_used_pages() + self.tospace().reserved_pages()
128128
}
129129

130+
fn current_gc_may_move_object(&self) -> bool {
131+
true
132+
}
133+
130134
/// Return the number of pages available for allocation. Assuming all future allocations goes to nursery.
131135
fn get_available_pages(&self) -> usize {
132136
// super.get_available_pages() / 2 to reserve pages for copying

src/plan/generational/immix/global.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,14 @@ impl<VM: VMBinding> Plan for GenImmix<VM> {
151151
.set_next_gc_full_heap(CommonGenPlan::should_next_gc_be_full_heap(self));
152152
}
153153

154+
fn current_gc_may_move_object(&self) -> bool {
155+
if self.is_current_gc_nursery() {
156+
true
157+
} else {
158+
self.immix_space.in_defrag()
159+
}
160+
}
161+
154162
fn get_collection_reserved_pages(&self) -> usize {
155163
self.gen.get_collection_reserved_pages() + self.immix_space.defrag_headroom_pages()
156164
}

src/plan/global.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ pub trait Plan: 'static + HasSpaces + Sync + Downcast {
299299
true
300300
}
301301

302+
/// Return whether the current GC may move any object. The VM binding can make use of this
303+
/// information and choose to or not to update some data structures that record the addresses
304+
/// of objects.
305+
fn current_gc_may_move_object(&self) -> bool;
306+
302307
/// An object is firstly reached by a sanity GC. So the object is reachable
303308
/// in the current GC, and all the GC work has been done for the object (such as
304309
/// tracing and releasing). A plan can implement this to

src/plan/immix/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ impl<VM: VMBinding> Plan for Immix<VM> {
9797
.store(self.immix_space.release(true), Ordering::Relaxed);
9898
}
9999

100+
fn current_gc_may_move_object(&self) -> bool {
101+
self.immix_space.in_defrag()
102+
}
103+
100104
fn get_collection_reserved_pages(&self) -> usize {
101105
self.immix_space.defrag_headroom_pages()
102106
}

src/plan/markcompact/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,10 @@ impl<VM: VMBinding> Plan for MarkCompact<VM> {
171171
fn get_collection_reserved_pages(&self) -> usize {
172172
0
173173
}
174+
175+
fn current_gc_may_move_object(&self) -> bool {
176+
true
177+
}
174178
}
175179

176180
impl<VM: VMBinding> MarkCompact<VM> {

src/plan/marksweep/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ impl<VM: VMBinding> Plan for MarkSweep<VM> {
7373
self.base().collection_required(self, space_full)
7474
}
7575

76+
fn current_gc_may_move_object(&self) -> bool {
77+
false
78+
}
79+
7680
fn get_used_pages(&self) -> usize {
7781
self.common.get_used_pages() + self.ms.reserved_pages()
7882
}

src/plan/nogc/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ impl<VM: VMBinding> Plan for NoGC<VM> {
7474
unreachable!("GC triggered in nogc")
7575
}
7676

77+
fn current_gc_may_move_object(&self) -> bool {
78+
false
79+
}
80+
7781
fn get_used_pages(&self) -> usize {
7882
self.nogc_space.reserved_pages()
7983
+ self.immortal.reserved_pages()

src/plan/pageprotect/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ impl<VM: VMBinding> Plan for PageProtect<VM> {
6262
self.base().collection_required(self, space_full)
6363
}
6464

65+
fn current_gc_may_move_object(&self) -> bool {
66+
false
67+
}
68+
6569
fn get_used_pages(&self) -> usize {
6670
self.space.reserved_pages() + self.common.get_used_pages()
6771
}

src/plan/semispace/global.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ impl<VM: VMBinding> Plan for SemiSpace<VM> {
100100
self.base().collection_required(self, space_full)
101101
}
102102

103+
fn current_gc_may_move_object(&self) -> bool {
104+
true
105+
}
106+
103107
fn get_collection_reserved_pages(&self) -> usize {
104108
self.tospace().reserved_pages()
105109
}

src/plan/sticky/immix/global.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ impl<VM: VMBinding> Plan for StickyImmix<VM> {
158158
self.gc_full_heap.load(Ordering::Relaxed) && self.immix.last_collection_was_exhaustive()
159159
}
160160

161+
fn current_gc_may_move_object(&self) -> bool {
162+
if self.is_current_gc_nursery() {
163+
!cfg!(feature = "sticky_immix_non_moving_nursery")
164+
} else {
165+
return self.get_immix_space().in_defrag();
166+
}
167+
}
168+
161169
fn get_collection_reserved_pages(&self) -> usize {
162170
self.immix.get_collection_reserved_pages()
163171
}

0 commit comments

Comments
 (0)