From 4bbcc219ecc64d657b07947aa2a33ee15bf8924e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Inf=C3=BChr?= Date: Fri, 5 Jan 2024 12:10:06 +0100 Subject: [PATCH] swiper: remove forward_full method in swiper.rs --- dora-runtime/src/gc/root.rs | 4 ++-- dora-runtime/src/gc/swiper.rs | 21 --------------------- dora-runtime/src/gc/swiper/full.rs | 18 +++++++++++++----- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/dora-runtime/src/gc/root.rs b/dora-runtime/src/gc/root.rs index 8b4349380..b26e76c6d 100644 --- a/dora-runtime/src/gc/root.rs +++ b/dora-runtime/src/gc/root.rs @@ -223,9 +223,9 @@ where lazy_compilation_stub::iterate_roots(vm, frame.fp, ¶ms, is_variadic, return_type, callback) } -pub fn iterate_weak_roots(vm: &VM, object_updater: F) +pub fn iterate_weak_roots(vm: &VM, mut object_updater: F) where - F: Fn(Address) -> Option
, + F: FnMut(Address) -> Option
, { let mut finalizers = vm.gc.finalizers.lock(); let mut deleted = false; diff --git a/dora-runtime/src/gc/swiper.rs b/dora-runtime/src/gc/swiper.rs index a1ab31368..ab96c09e0 100644 --- a/dora-runtime/src/gc/swiper.rs +++ b/dora-runtime/src/gc/swiper.rs @@ -622,27 +622,6 @@ pub trait CommonOldGen { fn committed_size(&self) -> usize; } -fn forward_full(object: Address, heap: Region, perm: Region) -> Option
{ - if heap.contains(object) { - let obj = object.to_obj(); - - if obj.header().is_marked() { - let vtblptr = obj.header().vtblptr(); - - if let VtblptrWordKind::Fwdptr(new_address) = vtblptr { - Some(new_address) - } else { - Some(object) - } - } else { - None - } - } else { - debug_assert!(perm.contains(object)); - Some(object) - } -} - fn forward_minor(object: Address, young: Region) -> Option
{ if young.contains(object) { let obj = object.to_obj(); diff --git a/dora-runtime/src/gc/swiper/full.rs b/dora-runtime/src/gc/swiper/full.rs index dc397efc4..65385db44 100644 --- a/dora-runtime/src/gc/swiper/full.rs +++ b/dora-runtime/src/gc/swiper/full.rs @@ -10,7 +10,7 @@ use crate::gc::swiper::crossing::CrossingMap; use crate::gc::swiper::large::LargeSpace; use crate::gc::swiper::old::{OldGen, OldGenProtected, Page}; use crate::gc::swiper::young::YoungGen; -use crate::gc::swiper::{forward_full, walk_region, INITIAL_METADATA_OLD}; +use crate::gc::swiper::{walk_region, INITIAL_METADATA_OLD}; use crate::gc::{fill_region_with, iterate_strong_roots, iterate_weak_roots, marking, Slot}; use crate::gc::{Address, GcReason, Region}; use crate::object::{Obj, VtblptrWordKind}; @@ -228,7 +228,7 @@ impl<'a> FullCollector<'a> { }); iterate_weak_roots(self.vm, |object_address| { - forward_full(object_address, self.heap, self.readonly_space.total()) + self.forward_object(object_address).or(Some(object_address)) }); self.large_space.remove_objects(|object_start| { @@ -384,16 +384,24 @@ impl<'a> FullCollector<'a> { return; } + if let Some(forwarded) = self.forward_object(object_address) { + debug_assert!(self.heap.contains(forwarded)); + slot.set(forwarded); + } + } + + fn forward_object(&mut self, object_address: Address) -> Option
{ if self.heap.contains(object_address) { let object = object_address.to_obj(); let vtblptr = object.header().vtblptr(); if let VtblptrWordKind::Fwdptr(address) = vtblptr { - debug_assert!(self.heap.contains(address)); - slot.set(address); + Some(address) + } else { + None } } else { - debug_assert!(self.readonly_space.contains(object_address)); + None } }