Skip to content

Commit

Permalink
swiper: fix phase recording
Browse files Browse the repository at this point in the history
  • Loading branch information
dinfuehr committed Jan 7, 2024
1 parent 5c8ebb5 commit 23dd35a
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 130 deletions.
14 changes: 0 additions & 14 deletions dora-runtime/src/gc/sweep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,10 @@ struct MarkSweep<'a> {

impl<'a> MarkSweep<'a> {
fn collect(&mut self) {
let dev_verbose = self.vm.flags.gc_dev_verbose;

if dev_verbose {
println!("Sweep GC: Phase 1 (marking)");
}

self.mark();
self.iterate_weak_refs();

if dev_verbose {
println!("Sweep GC: Phase 2 (sweep)");
}

self.sweep();

if dev_verbose {
println!("Sweep GC: Stop");
}
}

fn mark(&mut self) {
Expand Down
58 changes: 8 additions & 50 deletions dora-runtime/src/gc/swiper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,7 @@ impl Swiper {
rootset: &[Slot],
threads: &[Arc<DoraThread>],
) {
self.verify(
vm,
VerifierPhase::PreMinor,
CollectionKind::Minor,
"pre-minor",
&rootset,
);
self.verify(vm, VerifierPhase::PreMinor, CollectionKind::Minor, &rootset);

{
let mut pool = self.threadpool.lock();
Expand Down Expand Up @@ -282,7 +276,6 @@ impl Swiper {
vm,
VerifierPhase::PostMinor,
CollectionKind::Minor,
"post-minor",
&rootset,
);
}
Expand All @@ -294,13 +287,7 @@ impl Swiper {
threads: &[Arc<DoraThread>],
rootset: &[Slot],
) {
self.verify(
vm,
VerifierPhase::PreFull,
CollectionKind::Full,
"pre-full",
&rootset,
);
self.verify(vm, VerifierPhase::PreFull, CollectionKind::Full, &rootset);

{
let mut collector = FullCollector::new(
Expand All @@ -326,28 +313,11 @@ impl Swiper {
}
}

self.verify(
vm,
VerifierPhase::PostFull,
CollectionKind::Full,
"post-full",
&rootset,
);
self.verify(vm, VerifierPhase::PostFull, CollectionKind::Full, &rootset);
}

fn verify(
&self,
vm: &VM,
phase: VerifierPhase,
_kind: CollectionKind,
name: &str,
rootset: &[Slot],
) {
fn verify(&self, vm: &VM, phase: VerifierPhase, _kind: CollectionKind, rootset: &[Slot]) {
if vm.flags.gc_verify {
if vm.flags.gc_dev_verbose {
println!("GC: Verify {}", name);
}

let readonly_space = &vm.gc.readonly_space;

let mut verifier = Verifier::new(
Expand All @@ -363,10 +333,6 @@ impl Swiper {
phase,
);
verifier.verify();

if vm.flags.gc_dev_verbose {
println!("GC: Verify {} finished", name);
}
}
}

Expand Down Expand Up @@ -467,19 +433,12 @@ impl Collector for Swiper {
);
println!("GC stats: full-total={}", config.full_total_all());
println!("GC stats: full-marking={}", config.full_marking_all());
println!(
"GC stats: full-compute-forward={}",
config.full_compute_forward_all()
);
println!("GC stats: full-sweep={}", config.full_sweep_all());
println!(
"GC stats: full-update-refs={}",
config.full_update_refs_all()
);
println!("GC stats: full-relocate={}", config.full_relocate_all());
println!(
"GC stats: full-reset-cards={}",
config.full_reset_cards_all()
);
println!("GC stats: full-evacuate={}", config.full_relocate_all());
println!("");
println!(
"GC stats: minor-collections={:.1}",
Expand Down Expand Up @@ -511,10 +470,9 @@ impl Collector for Swiper {
println!("\nFull:");

println!("\tMarking:\t{}", config.full_marking());
println!("\tCompute Fwd:\t{}", config.full_compute_forward());
println!("\tSweep:\t\t{}", config.full_sweep());
println!("\tUpdate Refs:\t{}", config.full_update_refs());
println!("\tRelocate:\t{}", config.full_relocate());
println!("\tReset Cards:\t{}", config.full_reset_cards());
println!("\tEvacuate:\t{}", config.full_relocate());
println!("\tTotal:\t\t{}", config.full_total());

println!("");
Expand Down
13 changes: 2 additions & 11 deletions dora-runtime/src/gc/swiper/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ impl HeapController {
AllNumbers(self.full_phases.iter().map(|x| x.marking).collect())
}

pub fn full_compute_forward(&self) -> Numbers {
pub fn full_sweep(&self) -> Numbers {
let values: Vec<_> = self.full_phases.iter().map(|x| x.sweep).collect();
calculate_numbers(&values)
}

pub fn full_compute_forward_all(&self) -> AllNumbers {
pub fn full_sweep_all(&self) -> AllNumbers {
AllNumbers(self.full_phases.iter().map(|x| x.sweep).collect())
}

Expand All @@ -273,15 +273,6 @@ impl HeapController {
AllNumbers(self.full_phases.iter().map(|x| x.evacuate).collect())
}

pub fn full_reset_cards(&self) -> Numbers {
let values: Vec<_> = self.full_phases.iter().map(|x| x.reset_cards).collect();
calculate_numbers(&values)
}

pub fn full_reset_cards_all(&self) -> AllNumbers {
AllNumbers(self.full_phases.iter().map(|x| x.reset_cards).collect())
}

pub fn full_total(&self) -> Numbers {
let values: Vec<_> = self.full_phases.iter().map(|x| x.total).collect();
calculate_numbers(&values)
Expand Down
66 changes: 28 additions & 38 deletions dora-runtime/src/gc/swiper/full.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::sync::Arc;
use std::time::Instant;

use parking_lot::MutexGuard;

Expand All @@ -16,7 +17,6 @@ use crate::gc::{Address, GcReason, Region};
use crate::object::{Obj, VtblptrWordKind};
use crate::stdlib;
use crate::threads::DoraThread;
use crate::timer::Timer;
use crate::vm::{Trap, VM};

pub struct FullCollector<'a> {
Expand Down Expand Up @@ -93,25 +93,9 @@ impl<'a> FullCollector<'a> {
}

pub fn collect(&mut self) {
let dev_verbose = self.vm.flags.gc_dev_verbose;
let stats = self.vm.flags.gc_stats;

let mut timer = Timer::new(stats);

if dev_verbose {
println!("Full GC: Start");
}

self.mark_live();

if stats {
let duration = timer.stop();
self.phases.marking = duration;
}

if dev_verbose {
println!("Full GC: Phase 1 (marking)");
}
self.phases.marking = measure(self.vm, || {
self.mark_live();
});

if self.vm.flags.gc_verify {
verify_marking(
Expand All @@ -121,28 +105,19 @@ impl<'a> FullCollector<'a> {
self.large_space,
self.heap,
);

if stats {
timer.stop();
}

if dev_verbose {
println!("Full GC: Phase 1b (verify marking)");
}
}

self.sweep();
self.evacuate();
self.update_references();
self.phases.sweep = measure(self.vm, || {
self.sweep();
});

if stats {
let duration = timer.stop();
self.phases.reset_cards = duration;
}
self.phases.evacuate = measure(self.vm, || {
self.evacuate();
});

if dev_verbose {
println!("Full GC: Phase 5 (reset cards)");
}
self.phases.update_refs = measure(self.vm, || {
self.update_references();
});

self.young.reset_after_full_gc(self.vm);
}
Expand Down Expand Up @@ -403,3 +378,18 @@ fn verify_marking_object(obj_address: Address, heap: Region) {
});
}
}

fn measure<F>(vm: &VM, fct: F) -> f32
where
F: FnOnce(),
{
if vm.flags.gc_stats {
let start = Instant::now();
fct();
let duration = start.elapsed();
duration.as_secs_f32() * 1000f32
} else {
fct();
0.0f32
}
}
10 changes: 0 additions & 10 deletions dora-runtime/src/gc/swiper/minor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,8 @@ impl<'a> MinorCollector<'a> {
let to_committed = self.young.to_committed();
self.young_alloc = Some(YoungAlloc::new(to_committed));

let dev_verbose = self.vm.flags.gc_dev_verbose;

if dev_verbose {
println!("Minor GC: Worker threads started");
}

self.run_threads();

if dev_verbose {
println!("Minor GC: Worker threads finished");
}

self.iterate_weak_refs();

let young_alloc = std::mem::replace(&mut self.young_alloc, None).expect("missing value");
Expand Down
1 change: 0 additions & 1 deletion dora-runtime/src/vm/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ pub struct Flags {
pub gc_stress_in_lazy_compile: bool,
pub gc_stats: bool,
pub gc_verbose: bool,
pub gc_dev_verbose: bool,
pub gc_verify: bool,
pub gc_worker: usize,
pub gc_young_size: Option<MemSize>,
Expand Down
6 changes: 0 additions & 6 deletions dora/src/driver/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ Options:
--gc-stress-minor Minor collection at every allocation.
--gc-stats Print GC statistics.
--gc-verbose Verbose GC.
--gc-dev-verbose Verbose GC for developers.
--gc-verify Verify heap before and after collections.
--gc-worker=<num> Number of GC worker threads.
--gc=<name> Switch GC. Possible values: zero, copy, swiper (default).
Expand Down Expand Up @@ -84,7 +83,6 @@ pub struct Args {
pub gc_stress_minor: bool,
pub gc_stats: bool,
pub gc_verbose: bool,
pub gc_dev_verbose: bool,
pub gc_verify: bool,
pub gc_worker: usize,
gc_young_size: Option<MemSize>,
Expand Down Expand Up @@ -134,7 +132,6 @@ impl Default for Args {
gc_stress_minor: false,
gc_stats: false,
gc_verbose: false,
gc_dev_verbose: false,
gc_verify: false,
gc_worker: 0,
gc_young_size: None,
Expand Down Expand Up @@ -249,8 +246,6 @@ pub fn parse_arguments() -> Result<Args, String> {
args.gc_stats = true;
} else if arg == "--gc-verbose" {
args.gc_verbose = true;
} else if arg == "--gc-dev-verbose" {
args.gc_dev_verbose = true;
} else if arg == "--gc-verify" {
args.gc_verify = true;
} else if arg.starts_with("--gc-worker=") {
Expand Down Expand Up @@ -411,7 +406,6 @@ pub fn create_vm_args(args: &Args) -> VmArgs {
gc_stress_minor: args.gc_stress_minor,
gc_stats: args.gc_stats,
gc_verbose: args.gc_verbose,
gc_dev_verbose: args.gc_dev_verbose,
gc_verify: args.gc_verify,
gc_worker: args.gc_worker,
gc_young_size: args.gc_young_size,
Expand Down

0 comments on commit 23dd35a

Please sign in to comment.