-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR introduces `MockVM`, a type that implements `VMBinding` and allows users to control the behavior of each method for testing. This PR also moves all the tests in the current `DummyVM` to `MockVM`, and removes the current `DummyVM`. This PR closes #99. Note that the current `MockVM` implementation does not allow changing constants or associated types in `VMBinding` -- I would suggest we create another issue to track this problem. Changes: * Introduce `MockVM`, and write all the current `DummyVM` tests with `MockVM`. * Remove `DummyVM`, and remove `./examples` which uses `DummyVM`. * Change CI scripts to run tests with `MockVM`. * Remove `pub` visibility for some modules. Those modules were exposed so we can test them from `DummyVM`. As now `MockVM` is a part of the main crate, we can test private items. We no longer need `pub` for those modules.
- Loading branch information
Showing
89 changed files
with
3,198 additions
and
2,856 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
use criterion::Criterion; | ||
|
||
use mmtk::memory_manager; | ||
use mmtk::util::test_util::fixtures::*; | ||
use mmtk::AllocationSemantics; | ||
|
||
pub fn bench(c: &mut Criterion) { | ||
// Disable GC so we won't trigger GC | ||
let mut fixture = MutatorFixture::create_with_heapsize(1 << 30); | ||
memory_manager::disable_collection(fixture.mmtk()); | ||
c.bench_function("alloc", |b| { | ||
b.iter(|| { | ||
let _addr = | ||
memory_manager::alloc(&mut fixture.mutator, 8, 8, 0, AllocationSemantics::Default); | ||
}) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use criterion::criterion_group; | ||
use criterion::criterion_main; | ||
use criterion::Criterion; | ||
|
||
// As we can only initialize one MMTk instance, we have to run each benchmark in a separate process. | ||
// So we only register one benchmark to criterion ('bench_main'), and based on the env var MMTK_BENCH, | ||
// we pick the right benchmark to run. | ||
|
||
// The benchmark can be executed with the following command. The feature `mock_test` is required, as the tests use MockVM. | ||
// MMTK_BENCH=alloc cargo bench --features mock_test | ||
// MMTK_BENCH=sft cargo bench --features mock_test | ||
|
||
// [Yi] I am not sure if these benchmarks are helpful any more after the MockVM refactoring. MockVM is really slow, as it | ||
// is accessed with a lock, and it dispatches every call to function pointers in a struct. These tests may use MockVM, | ||
// so they become slower as well. And the slowdown | ||
// from MockVM may hide the actual performance difference when we change the functions that are benchmarked. | ||
// We may want to improve the MockVM implementation so we can skip dispatching for benchmarking, or introduce another MockVM | ||
// implementation for benchmarking. | ||
// However, I will just keep these benchmarks here. If we find it not useful, and we do not plan to improve MockVM, we can delete | ||
// them. | ||
|
||
mod alloc; | ||
mod sft; | ||
|
||
fn bench_main(c: &mut Criterion) { | ||
match std::env::var("MMTK_BENCH") { | ||
Ok(bench) => match bench.as_str() { | ||
"alloc" => alloc::bench(c), | ||
"sft" => sft::bench(c), | ||
_ => panic!("Unknown benchmark {:?}", bench), | ||
}, | ||
Err(_) => panic!("Need to name a benchmark by the env var MMTK_BENCH"), | ||
} | ||
} | ||
|
||
criterion_group!(benches, bench_main); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use criterion::black_box; | ||
use criterion::Criterion; | ||
|
||
use mmtk::memory_manager; | ||
use mmtk::util::test_util::fixtures::*; | ||
use mmtk::util::test_util::mock_vm::*; | ||
use mmtk::vm::ObjectModel; | ||
use mmtk::vm::VMBinding; | ||
use mmtk::AllocationSemantics; | ||
|
||
pub fn bench(c: &mut Criterion) { | ||
let mut fixture = MutatorFixture::create(); | ||
let addr = memory_manager::alloc(&mut fixture.mutator, 8, 8, 0, AllocationSemantics::Default); | ||
let obj = <MockVM as VMBinding>::VMObjectModel::address_to_ref(addr); | ||
|
||
c.bench_function("sft read", |b| { | ||
b.iter(|| memory_manager::is_in_mmtk_spaces::<MockVM>(black_box(obj))) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.