Skip to content

Commit

Permalink
swiper: properly track size of old generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 6, 2024
1 parent 1ace459 commit de1538b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dora-runtime/src/gc/swiper/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,12 @@ pub fn stop(
std::usize::MAX
};

let min_semi_size = young.allocated_size();

let rest = config.max_heap_size - config.old_size;
let target_young_size = rest / 2;
let target_young_size = min(target_young_size, max_young_size);
let target_young_size = max(target_young_size, 2 * PAGE_SIZE);
let target_young_size = max(target_young_size, 2 * min_semi_size);
let young_size = align_page_down(target_young_size / 2) * 2;

if old_size + young_size > config.max_heap_size {
Expand Down
2 changes: 2 additions & 0 deletions dora-runtime/src/gc/swiper/old.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ impl OldGenProtected {
if let Some(page) = self.allocate_page(vm) {
self.pages.push(page);
self.pages.sort();
self.size += PAGE_SIZE;

self.top = page.object_area_start();
self.current_limit = page.object_area_end();
Expand All @@ -210,6 +211,7 @@ impl OldGenProtected {
.position(|&p| p == page)
.expect("missing page");
self.pages.swap_remove(idx);
self.size -= PAGE_SIZE;
os::discard(page.start(), page.size());
}

Expand Down
6 changes: 6 additions & 0 deletions dora-runtime/src/gc/swiper/young.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ impl YoungGen {
self.current_size.store(size, Ordering::Relaxed);
}

pub fn allocated_size(&self) -> usize {
let protected = self.alloc.protected.lock();
let to_committed = self.to_committed();
protected.current_limit.offset_from(to_committed.start())
}

pub fn protect_from(&self) {
if cfg!(debug_assertions) || self.protect {
let from_space = self.from_committed();
Expand Down
5 changes: 3 additions & 2 deletions dora-runtime/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -672,10 +672,11 @@ where
let cls = vm.class_instances.idx(clsid);
let vtable = cls.vtable.read();
let vtable: &VTable = vtable.as_ref().unwrap();
let mut handle: Ref<Str> = ptr.into();
let handle: Ref<Str> = ptr.into();
handle
.header_mut()
.header()
.set_vtblptr(Address::from_ptr(vtable as *const VTable));
handle.header().set_metadata_raw(0);

handle
}
Expand Down

0 comments on commit de1538b

Please sign in to comment.