diff --git a/.github/scripts/ci-style.sh b/.github/scripts/ci-style.sh index ed5ddf3fc2..51b6a095bc 100755 --- a/.github/scripts/ci-style.sh +++ b/.github/scripts/ci-style.sh @@ -2,6 +2,8 @@ export RUSTFLAGS="-D warnings" +# --- Check main crate --- + # check base cargo clippy # check all features @@ -10,8 +12,6 @@ for_all_features "cargo clippy" for_all_features "cargo clippy --release" # check for tests for_all_features "cargo clippy --tests" -# check for dummyvm -cargo clippy --manifest-path=vmbindings/dummyvm/Cargo.toml # target-specific features if [[ $arch == "x86_64" && $os == "linux" ]]; then @@ -20,5 +20,14 @@ if [[ $arch == "x86_64" && $os == "linux" ]]; then cargo clippy --tests --features perf_counter fi -# check format -cargo fmt -- --check +# --- Check auxiliary crate --- + +style_check_auxiliary_crate() { + crate_path=$1 + + cargo clippy --manifest-path=$crate_path/Cargo.toml + cargo fmt --manifest-path=$crate_path/Cargo.toml -- --check +} + +style_check_auxiliary_crate macros +style_check_auxiliary_crate vmbindings/dummyvm diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 5a882796cf..53f6b544a6 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,17 +1,17 @@ extern crate proc_macro; -extern crate syn; extern crate proc_macro_error; extern crate quote; +extern crate syn; use proc_macro::TokenStream; -use proc_macro_error::proc_macro_error; -use syn::{parse_macro_input}; use proc_macro_error::abort_call_site; +use proc_macro_error::proc_macro_error; use quote::quote; +use syn::parse_macro_input; use syn::DeriveInput; -mod util; mod plan_trace_object_impl; +mod util; const DEBUG_MACRO_OUTPUT: bool = false; @@ -37,15 +37,22 @@ pub fn derive_plan_trace_object(input: TokenStream) -> TokenStream { let output = if let syn::Data::Struct(syn::DataStruct { fields: syn::Fields::Named(ref fields), .. - }) = input.data { + }) = input.data + { let spaces = util::get_fields_with_attribute(fields, "trace"); let post_scan_spaces = util::get_fields_with_attribute(fields, "post_scan"); let fallback = util::get_unique_field_with_attribute(fields, "fallback_trace"); - let trace_object_function = plan_trace_object_impl::generate_trace_object(&spaces, &fallback, &ty_generics); - let post_scan_object_function = plan_trace_object_impl::generate_post_scan_object(&post_scan_spaces, &fallback, &ty_generics); - let may_move_objects_function = plan_trace_object_impl::generate_may_move_objects(&spaces, &fallback, &ty_generics); - quote!{ + let trace_object_function = + plan_trace_object_impl::generate_trace_object(&spaces, &fallback, &ty_generics); + let post_scan_object_function = plan_trace_object_impl::generate_post_scan_object( + &post_scan_spaces, + &fallback, + &ty_generics, + ); + let may_move_objects_function = + plan_trace_object_impl::generate_may_move_objects(&spaces, &fallback, &ty_generics); + quote! { impl #impl_generics crate::plan::PlanTraceObject #ty_generics for #ident #ty_generics #where_clause { #trace_object_function diff --git a/macros/src/plan_trace_object_impl.rs b/macros/src/plan_trace_object_impl.rs index a427015301..5dd0b045dc 100644 --- a/macros/src/plan_trace_object_impl.rs +++ b/macros/src/plan_trace_object_impl.rs @@ -1,6 +1,6 @@ +use proc_macro2::TokenStream as TokenStream2; use quote::quote; use syn::{Field, TypeGenerics}; -use proc_macro2::TokenStream as TokenStream2; use crate::util; @@ -12,7 +12,7 @@ pub(crate) fn generate_trace_object<'a>( // Generate a check with early return for each space let space_field_handler = space_fields.iter().map(|f| { let f_ident = f.ident.as_ref().unwrap(); - let ref f_ty = f.ty; + let f_ty = &f.ty; // Figure out copy let trace_attr = util::get_field_attribute(f, "trace").unwrap(); @@ -42,7 +42,7 @@ pub(crate) fn generate_trace_object<'a>( // Generate a fallback to the parent plan let parent_field_delegator = if let Some(f) = parent_field { let f_ident = f.ident.as_ref().unwrap(); - let ref f_ty = f.ty; + let f_ty = &f.ty; quote! { <#f_ty as PlanTraceObject #ty_generics>::trace_object::(&self.#f_ident, __mmtk_queue, __mmtk_objref, __mmtk_worker) } @@ -70,7 +70,7 @@ pub(crate) fn generate_post_scan_object<'a>( ) -> TokenStream2 { let scan_field_handler = post_scan_object_fields.iter().map(|f| { let f_ident = f.ident.as_ref().unwrap(); - let ref f_ty = f.ty; + let f_ty = &f.ty; quote! { if self.#f_ident.in_space(__mmtk_objref) { @@ -84,7 +84,7 @@ pub(crate) fn generate_post_scan_object<'a>( // Generate a fallback to the parent plan let parent_field_delegator = if let Some(f) = parent_field { let f_ident = f.ident.as_ref().unwrap(); - let ref f_ty = f.ty; + let f_ty = &f.ty; quote! { <#f_ty as PlanTraceObject #ty_generics>::post_scan_object(&self.#f_ident, __mmtk_objref) } @@ -110,7 +110,7 @@ pub(crate) fn generate_may_move_objects<'a>( ) -> TokenStream2 { // If any space or the parent may move objects, the plan may move objects let space_handlers = space_fields.iter().map(|f| { - let ref f_ty = f.ty; + let f_ty = &f.ty; quote! { || <#f_ty as PolicyTraceObject #ty_generics>::may_move_objects::() @@ -118,7 +118,7 @@ pub(crate) fn generate_may_move_objects<'a>( }); let parent_handler = if let Some(p) = parent_field { - let ref p_ty = p.ty; + let p_ty = &p.ty; quote! { || <#p_ty as PlanTraceObject #ty_generics>::may_move_objects::() diff --git a/vmbindings/dummyvm/src/active_plan.rs b/vmbindings/dummyvm/src/active_plan.rs index 1985def213..782a2a8886 100644 --- a/vmbindings/dummyvm/src/active_plan.rs +++ b/vmbindings/dummyvm/src/active_plan.rs @@ -1,14 +1,14 @@ -use mmtk::Plan; -use mmtk::vm::ActivePlan; -use mmtk::util::opaque_pointer::*; -use mmtk::Mutator; use crate::DummyVM; use crate::SINGLETON; +use mmtk::util::opaque_pointer::*; +use mmtk::vm::ActivePlan; +use mmtk::Mutator; +use mmtk::Plan; -pub struct VMActivePlan<> {} +pub struct VMActivePlan {} impl ActivePlan for VMActivePlan { - fn global() -> &'static dyn Plan { + fn global() -> &'static dyn Plan { SINGLETON.get_plan() } diff --git a/vmbindings/dummyvm/src/api.rs b/vmbindings/dummyvm/src/api.rs index 2109c187d8..3a1b61971c 100644 --- a/vmbindings/dummyvm/src/api.rs +++ b/vmbindings/dummyvm/src/api.rs @@ -1,25 +1,31 @@ // All functions here are extern function. There is no point for marking them as unsafe. #![allow(clippy::not_unsafe_ptr_arg_deref)] +use crate::DummyVM; +use crate::BUILDER; +use crate::SINGLETON; use libc::c_char; -use std::sync::atomic::Ordering; -use std::ffi::CStr; use mmtk::memory_manager; -use mmtk::AllocationSemantics; -use mmtk::util::{ObjectReference, Address}; -use mmtk::util::opaque_pointer::*; use mmtk::scheduler::{GCController, GCWorker}; +use mmtk::util::opaque_pointer::*; +use mmtk::util::{Address, ObjectReference}; +use mmtk::AllocationSemantics; use mmtk::Mutator; -use crate::DummyVM; -use crate::SINGLETON; -use crate::BUILDER; +use std::ffi::CStr; +use std::sync::atomic::Ordering; #[no_mangle] pub extern "C" fn mmtk_init(heap_size: usize) { // set heap size first { let mut builder = BUILDER.lock().unwrap(); - let success = builder.options.gc_trigger.set(mmtk::util::options::GCTriggerSelector::FixedHeapSize(heap_size)); + let success = + builder + .options + .gc_trigger + .set(mmtk::util::options::GCTriggerSelector::FixedHeapSize( + heap_size, + )); assert!(success, "Failed to set heap size to {}", heap_size); } @@ -43,18 +49,37 @@ pub extern "C" fn mmtk_destroy_mutator(mutator: *mut Mutator) { } #[no_mangle] -pub extern "C" fn mmtk_alloc(mutator: *mut Mutator, size: usize, - align: usize, offset: usize, mut semantics: AllocationSemantics) -> Address { - if size >= SINGLETON.get_plan().constraints().max_non_los_default_alloc_bytes { +pub extern "C" fn mmtk_alloc( + mutator: *mut Mutator, + size: usize, + align: usize, + offset: usize, + mut semantics: AllocationSemantics, +) -> Address { + if size + >= SINGLETON + .get_plan() + .constraints() + .max_non_los_default_alloc_bytes + { semantics = AllocationSemantics::Los; } memory_manager::alloc::(unsafe { &mut *mutator }, size, align, offset, semantics) } #[no_mangle] -pub extern "C" fn mmtk_post_alloc(mutator: *mut Mutator, refer: ObjectReference, - bytes: usize, mut semantics: AllocationSemantics) { - if bytes >= SINGLETON.get_plan().constraints().max_non_los_default_alloc_bytes { +pub extern "C" fn mmtk_post_alloc( + mutator: *mut Mutator, + refer: ObjectReference, + bytes: usize, + mut semantics: AllocationSemantics, +) { + if bytes + >= SINGLETON + .get_plan() + .constraints() + .max_non_los_default_alloc_bytes + { semantics = AllocationSemantics::Los; } memory_manager::post_alloc::(unsafe { &mut *mutator }, refer, bytes, semantics) @@ -66,7 +91,10 @@ pub extern "C" fn mmtk_will_never_move(object: ObjectReference) -> bool { } #[no_mangle] -pub extern "C" fn mmtk_start_control_collector(tls: VMWorkerThread, controller: &'static mut GCController) { +pub extern "C" fn mmtk_start_control_collector( + tls: VMWorkerThread, + controller: &'static mut GCController, +) { memory_manager::start_control_collector(&SINGLETON, tls, controller); } @@ -106,7 +134,7 @@ pub extern "C" fn mmtk_total_bytes() -> usize { } #[no_mangle] -pub extern "C" fn mmtk_is_live_object(object: ObjectReference) -> bool{ +pub extern "C" fn mmtk_is_live_object(object: ObjectReference) -> bool { memory_manager::is_live_object(object) } @@ -166,7 +194,11 @@ pub extern "C" fn mmtk_process(name: *const c_char, value: *const c_char) -> boo let name_str: &CStr = unsafe { CStr::from_ptr(name) }; let value_str: &CStr = unsafe { CStr::from_ptr(value) }; let mut builder = BUILDER.lock().unwrap(); - memory_manager::process(&mut builder, name_str.to_str().unwrap(), value_str.to_str().unwrap()) + memory_manager::process( + &mut builder, + name_str.to_str().unwrap(), + value_str.to_str().unwrap(), + ) } #[no_mangle] @@ -201,7 +233,11 @@ pub extern "C" fn mmtk_calloc(num: usize, size: usize) -> Address { #[no_mangle] #[cfg(feature = "malloc_counted_size")] -pub extern "C" fn mmtk_realloc_with_old_size(addr: Address, size: usize, old_size: usize) -> Address { +pub extern "C" fn mmtk_realloc_with_old_size( + addr: Address, + size: usize, + old_size: usize, +) -> Address { memory_manager::realloc_with_old_size::(&SINGLETON, addr, size, old_size) } #[no_mangle] diff --git a/vmbindings/dummyvm/src/object_model.rs b/vmbindings/dummyvm/src/object_model.rs index ca90c7a8d1..c666b1e7b1 100644 --- a/vmbindings/dummyvm/src/object_model.rs +++ b/vmbindings/dummyvm/src/object_model.rs @@ -1,7 +1,7 @@ +use crate::DummyVM; use mmtk::util::copy::{CopySemantics, GCWorkerCopyContext}; use mmtk::util::{Address, ObjectReference}; use mmtk::vm::*; -use crate::DummyVM; pub struct VMObjectModel {} @@ -11,10 +11,13 @@ pub const OBJECT_REF_OFFSET: usize = 4; impl ObjectModel for VMObjectModel { const GLOBAL_LOG_BIT_SPEC: VMGlobalLogBitSpec = VMGlobalLogBitSpec::in_header(0); - const LOCAL_FORWARDING_POINTER_SPEC: VMLocalForwardingPointerSpec = VMLocalForwardingPointerSpec::in_header(0); - const LOCAL_FORWARDING_BITS_SPEC: VMLocalForwardingBitsSpec = VMLocalForwardingBitsSpec::in_header(0); + const LOCAL_FORWARDING_POINTER_SPEC: VMLocalForwardingPointerSpec = + VMLocalForwardingPointerSpec::in_header(0); + const LOCAL_FORWARDING_BITS_SPEC: VMLocalForwardingBitsSpec = + VMLocalForwardingBitsSpec::in_header(0); const LOCAL_MARK_BIT_SPEC: VMLocalMarkBitSpec = VMLocalMarkBitSpec::in_header(0); - const LOCAL_LOS_MARK_NURSERY_SPEC: VMLocalLOSMarkNurserySpec = VMLocalLOSMarkNurserySpec::in_header(0); + const LOCAL_LOS_MARK_NURSERY_SPEC: VMLocalLOSMarkNurserySpec = + VMLocalLOSMarkNurserySpec::in_header(0); const OBJECT_REF_OFFSET_LOWER_BOUND: isize = OBJECT_REF_OFFSET as isize; diff --git a/vmbindings/dummyvm/src/reference_glue.rs b/vmbindings/dummyvm/src/reference_glue.rs index f7a5b5f8a7..66e09c5e5a 100644 --- a/vmbindings/dummyvm/src/reference_glue.rs +++ b/vmbindings/dummyvm/src/reference_glue.rs @@ -1,7 +1,7 @@ -use mmtk::vm::ReferenceGlue; -use mmtk::util::ObjectReference; -use mmtk::util::opaque_pointer::VMWorkerThread; use crate::DummyVM; +use mmtk::util::opaque_pointer::VMWorkerThread; +use mmtk::util::ObjectReference; +use mmtk::vm::ReferenceGlue; pub struct VMReferenceGlue {} diff --git a/vmbindings/dummyvm/src/scanning.rs b/vmbindings/dummyvm/src/scanning.rs index 8698106664..960f9d642b 100644 --- a/vmbindings/dummyvm/src/scanning.rs +++ b/vmbindings/dummyvm/src/scanning.rs @@ -1,5 +1,5 @@ -use crate::DummyVM; use crate::edges::DummyVMEdge; +use crate::DummyVM; use mmtk::util::opaque_pointer::*; use mmtk::util::ObjectReference; use mmtk::vm::EdgeVisitor; diff --git a/vmbindings/dummyvm/src/tests/allocate_align_offset.rs b/vmbindings/dummyvm/src/tests/allocate_align_offset.rs index ad8b27fb5d..c68cac7378 100644 --- a/vmbindings/dummyvm/src/tests/allocate_align_offset.rs +++ b/vmbindings/dummyvm/src/tests/allocate_align_offset.rs @@ -1,11 +1,11 @@ // GITHUB-CI: MMTK_PLAN=all use crate::api; +use crate::tests::fixtures::{MutatorFixture, SerialFixture}; use crate::DummyVM; -use crate::tests::fixtures::{SerialFixture, MutatorFixture}; +use log::info; use mmtk::plan::AllocationSemantics; use mmtk::vm::VMBinding; -use log::info; lazy_static! { static ref MUTATOR: SerialFixture = SerialFixture::new(); @@ -21,7 +21,12 @@ pub fn allocate_alignment() { while align <= max { info!("Test allocation with alignment {}", align); let addr = api::mmtk_alloc(fixture.mutator, 8, align, 0, AllocationSemantics::Default); - assert!(addr.is_aligned_to(align), "Expected allocation alignment {}, returned address is {:?}", align, addr); + assert!( + addr.is_aligned_to(align), + "Expected allocation alignment {}, returned address is {:?}", + align, + addr + ); align *= 2; } }) @@ -36,9 +41,23 @@ pub fn allocate_offset() { info!("Allowed alignment between {} and {}", min, max); let mut align = min; while align <= max { - info!("Test allocation with alignment {} and offset {}", align, OFFSET); - let addr = api::mmtk_alloc(fixture.mutator, 8, align, OFFSET, AllocationSemantics::Default); - assert!((addr + OFFSET).is_aligned_to(align), "Expected allocation alignment {}, returned address is {:?}", align, addr); + info!( + "Test allocation with alignment {} and offset {}", + align, OFFSET + ); + let addr = api::mmtk_alloc( + fixture.mutator, + 8, + align, + OFFSET, + AllocationSemantics::Default, + ); + assert!( + (addr + OFFSET).is_aligned_to(align), + "Expected allocation alignment {}, returned address is {:?}", + align, + addr + ); align *= 2; } }) diff --git a/vmbindings/dummyvm/src/tests/barrier_slow_path_assertion.rs b/vmbindings/dummyvm/src/tests/barrier_slow_path_assertion.rs index 21162b2c08..f8394a48ab 100644 --- a/vmbindings/dummyvm/src/tests/barrier_slow_path_assertion.rs +++ b/vmbindings/dummyvm/src/tests/barrier_slow_path_assertion.rs @@ -4,12 +4,12 @@ // Run the test with any plan that uses object barrier, and we also need both VO bit and extreme assertions. use crate::object_model::OBJECT_REF_OFFSET; -use crate::{api::*, edges}; -use crate::tests::fixtures::MMTKSingleton; use crate::tests::fixtures::FixtureContent; +use crate::tests::fixtures::MMTKSingleton; +use crate::{api::*, edges}; use atomic::Atomic; use mmtk::util::{Address, ObjectReference}; -use mmtk::util::{VMThread, VMMutatorThread}; +use mmtk::util::{VMMutatorThread, VMThread}; use mmtk::vm::edge_shape::SimpleEdge; use mmtk::AllocationSemantics; @@ -35,8 +35,11 @@ fn test_assertion_barrier_invalid_ref() { let invalid_objref = ObjectReference::from_raw_address(objref.to_raw_address() + 8usize); unsafe { let mu = &mut *mutator; - mu.barrier - .object_reference_write_slow(invalid_objref, edges::DummyVMEdge::Simple(edge), objref); + mu.barrier.object_reference_write_slow( + invalid_objref, + edges::DummyVMEdge::Simple(edge), + objref, + ); } } diff --git a/vmbindings/dummyvm/src/tests/conservatism.rs b/vmbindings/dummyvm/src/tests/conservatism.rs index fd4313e2d4..b2ef84c1cf 100644 --- a/vmbindings/dummyvm/src/tests/conservatism.rs +++ b/vmbindings/dummyvm/src/tests/conservatism.rs @@ -13,7 +13,8 @@ lazy_static! { } fn basic_filter(addr: Address) -> bool { - !addr.is_zero() && addr.as_usize() % VO_BIT_REGION_SIZE == (OBJECT_REF_OFFSET % VO_BIT_REGION_SIZE) + !addr.is_zero() + && addr.as_usize() % VO_BIT_REGION_SIZE == (OBJECT_REF_OFFSET % VO_BIT_REGION_SIZE) } fn assert_filter_pass(addr: Address) { @@ -129,7 +130,12 @@ pub fn large_offsets_aligned() { SINGLE_OBJECT.with_fixture(|fixture| { for log_offset in 12usize..(usize::BITS as usize) { let offset = 1usize << log_offset; - let addr = match fixture.objref.to_raw_address().as_usize().checked_add(offset) { + let addr = match fixture + .objref + .to_raw_address() + .as_usize() + .checked_add(offset) + { Some(n) => unsafe { Address::from_usize(n) }, None => break, }; @@ -144,7 +150,12 @@ pub fn negative_offsets() { SINGLE_OBJECT.with_fixture(|fixture| { for log_offset in LOG_BITS_IN_WORD..(usize::BITS as usize) { let offset = 1usize << log_offset; - let addr = match fixture.objref.to_raw_address().as_usize().checked_sub(offset) { + let addr = match fixture + .objref + .to_raw_address() + .as_usize() + .checked_sub(offset) + { Some(0) => break, Some(n) => unsafe { Address::from_usize(n) }, None => break, diff --git a/vmbindings/dummyvm/src/tests/edges_test.rs b/vmbindings/dummyvm/src/tests/edges_test.rs index 8b15c28503..92c50dbbb4 100644 --- a/vmbindings/dummyvm/src/tests/edges_test.rs +++ b/vmbindings/dummyvm/src/tests/edges_test.rs @@ -57,7 +57,8 @@ mod only_64_bit { // Note: We cannot guarantee GC will allocate an object in the low address region. // So we make up addresses just for testing the bit operations of compressed OOP edges. let compressed1 = (COMPRESSABLE_ADDR1 >> 3) as u32; - let objref1 = ObjectReference::from_raw_address(unsafe { Address::from_usize(COMPRESSABLE_ADDR1) }); + let objref1 = + ObjectReference::from_raw_address(unsafe { Address::from_usize(COMPRESSABLE_ADDR1) }); let mut slot: Atomic = Atomic::new(compressed1); @@ -73,7 +74,8 @@ mod only_64_bit { // So we make up addresses just for testing the bit operations of compressed OOP edges. let compressed1 = (COMPRESSABLE_ADDR1 >> 3) as u32; let compressed2 = (COMPRESSABLE_ADDR2 >> 3) as u32; - let objref2 = ObjectReference::from_raw_address(unsafe { Address::from_usize(COMPRESSABLE_ADDR2) }); + let objref2 = + ObjectReference::from_raw_address(unsafe { Address::from_usize(COMPRESSABLE_ADDR2) }); let mut slot: Atomic = Atomic::new(compressed1); @@ -123,8 +125,10 @@ const TAG2: usize = 0b10; #[test] pub fn load_tagged() { FIXTURE.with_fixture(|fixture| { - let mut slot1: Atomic = Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG1); - let mut slot2: Atomic = Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG2); + let mut slot1: Atomic = + Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG1); + let mut slot2: Atomic = + Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG2); let edge1 = TaggedEdge::new(Address::from_ref(&mut slot1)); let edge2 = TaggedEdge::new(Address::from_ref(&mut slot2)); @@ -140,8 +144,10 @@ pub fn load_tagged() { #[test] pub fn store_tagged() { FIXTURE.with_fixture(|fixture| { - let mut slot1: Atomic = Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG1); - let mut slot2: Atomic = Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG2); + let mut slot1: Atomic = + Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG1); + let mut slot2: Atomic = + Atomic::new(fixture.objref1.to_raw_address().as_usize() | TAG2); let edge1 = TaggedEdge::new(Address::from_ref(&mut slot1)); let edge2 = TaggedEdge::new(Address::from_ref(&mut slot2)); diff --git a/vmbindings/dummyvm/src/tests/fixtures/mod.rs b/vmbindings/dummyvm/src/tests/fixtures/mod.rs index 2c11d4522d..3345509647 100644 --- a/vmbindings/dummyvm/src/tests/fixtures/mod.rs +++ b/vmbindings/dummyvm/src/tests/fixtures/mod.rs @@ -2,12 +2,12 @@ #![allow(dead_code)] use atomic_refcell::AtomicRefCell; -use std::sync::Once; use std::sync::Mutex; +use std::sync::Once; +use mmtk::util::{ObjectReference, VMMutatorThread, VMThread}; use mmtk::AllocationSemantics; use mmtk::MMTK; -use mmtk::util::{ObjectReference, VMThread, VMMutatorThread}; use crate::api::*; use crate::object_model::OBJECT_REF_OFFSET; @@ -17,7 +17,6 @@ pub trait FixtureContent { fn create() -> Self; } - pub struct Fixture { content: AtomicRefCell>>, once: Once, @@ -46,13 +45,13 @@ impl Fixture { /// SerialFixture ensures all `with_fixture()` calls will be executed serially. pub struct SerialFixture { - content: Mutex>> + content: Mutex>>, } impl SerialFixture { pub fn new() -> Self { Self { - content: Mutex::new(None) + content: Mutex::new(None), } } @@ -94,7 +93,7 @@ impl FixtureContent for SingleObject { } pub struct MMTKSingleton { - pub mmtk: &'static MMTK + pub mmtk: &'static MMTK, } impl FixtureContent for MMTKSingleton { diff --git a/vmbindings/dummyvm/src/tests/handle_mmap_conflict.rs b/vmbindings/dummyvm/src/tests/handle_mmap_conflict.rs index 95e4836291..5a702a37f0 100644 --- a/vmbindings/dummyvm/src/tests/handle_mmap_conflict.rs +++ b/vmbindings/dummyvm/src/tests/handle_mmap_conflict.rs @@ -1,11 +1,11 @@ -use mmtk::util::Address; -use mmtk::util::opaque_pointer::*; -use mmtk::util::memory; use crate::DummyVM; +use mmtk::util::memory; +use mmtk::util::opaque_pointer::*; +use mmtk::util::Address; #[test] pub fn test_handle_mmap_conflict() { - let start = unsafe { Address::from_usize(0x100_0000 )}; + let start = unsafe { Address::from_usize(0x100_0000) }; let one_megabyte = 1000000; let mmap1_res = memory::dzmmap_noreplace(start, one_megabyte, memory::MmapStrategy::Normal); assert!(mmap1_res.is_ok()); @@ -21,4 +21,4 @@ pub fn test_handle_mmap_conflict() { let err = panic_res.err().unwrap(); assert!(err.is::<&str>()); assert_eq!(err.downcast_ref::<&str>().unwrap(), &"Failed to mmap, the address is already mapped. Should MMTk quanrantine the address range first?"); -} \ No newline at end of file +} diff --git a/vmbindings/dummyvm/src/tests/handle_mmap_oom.rs b/vmbindings/dummyvm/src/tests/handle_mmap_oom.rs index 47b64fff31..043f621fea 100644 --- a/vmbindings/dummyvm/src/tests/handle_mmap_oom.rs +++ b/vmbindings/dummyvm/src/tests/handle_mmap_oom.rs @@ -1,7 +1,7 @@ -use mmtk::util::Address; -use mmtk::util::opaque_pointer::*; -use mmtk::util::memory; use crate::DummyVM; +use mmtk::util::memory; +use mmtk::util::opaque_pointer::*; +use mmtk::util::Address; #[cfg(target_pointer_width = "32")] const LARGE_SIZE: usize = 4_294_967_295; @@ -11,7 +11,7 @@ const LARGE_SIZE: usize = 1_000_000_000_000; #[test] pub fn test_handle_mmap_oom() { let panic_res = std::panic::catch_unwind(move || { - let start = unsafe { Address::from_usize(0x100_0000 )}; + let start = unsafe { Address::from_usize(0x100_0000) }; // mmap 1 terabyte memory - we expect this will fail due to out of memory. // If that's not the case, increase the size we mmap. let mmap_res = memory::dzmmap_noreplace(start, LARGE_SIZE, memory::MmapStrategy::Normal); @@ -23,5 +23,8 @@ pub fn test_handle_mmap_oom() { // The error should match the default implementation of Collection::out_of_memory() let err = panic_res.err().unwrap(); assert!(err.is::()); - assert_eq!(err.downcast_ref::().unwrap(), &"Out of memory with MmapOutOfMemory!"); + assert_eq!( + err.downcast_ref::().unwrap(), + &"Out of memory with MmapOutOfMemory!" + ); } diff --git a/vmbindings/dummyvm/src/tests/is_in_mmtk_spaces.rs b/vmbindings/dummyvm/src/tests/is_in_mmtk_spaces.rs index 2e69e120d6..7e14fb9bc9 100644 --- a/vmbindings/dummyvm/src/tests/is_in_mmtk_spaces.rs +++ b/vmbindings/dummyvm/src/tests/is_in_mmtk_spaces.rs @@ -1,7 +1,7 @@ // GITHUB-CI: MMTK_PLAN=all -use crate::tests::fixtures::{Fixture, SingleObject}; use crate::api::mmtk_is_in_mmtk_spaces as is_in_mmtk_spaces; +use crate::tests::fixtures::{Fixture, SingleObject}; use mmtk::util::*; lazy_static! { @@ -43,7 +43,12 @@ pub fn large_offsets_aligned() { SINGLE_OBJECT.with_fixture(|fixture| { for log_offset in 12usize..(usize::BITS as usize) { let offset = 1usize << log_offset; - let addr = match fixture.objref.to_raw_address().as_usize().checked_add(offset) { + let addr = match fixture + .objref + .to_raw_address() + .as_usize() + .checked_add(offset) + { Some(n) => unsafe { Address::from_usize(n) }, None => break, }; @@ -59,7 +64,12 @@ pub fn negative_offsets() { SINGLE_OBJECT.with_fixture(|fixture| { for log_offset in 1usize..(usize::BITS as usize) { let offset = 1usize << log_offset; - let addr = match fixture.objref.to_raw_address().as_usize().checked_sub(offset) { + let addr = match fixture + .objref + .to_raw_address() + .as_usize() + .checked_sub(offset) + { Some(n) => unsafe { Address::from_usize(n) }, None => break, }; diff --git a/vmbindings/dummyvm/src/tests/issue139.rs b/vmbindings/dummyvm/src/tests/issue139.rs index 7d073e731f..f62cab5ca1 100644 --- a/vmbindings/dummyvm/src/tests/issue139.rs +++ b/vmbindings/dummyvm/src/tests/issue139.rs @@ -4,7 +4,7 @@ use mmtk::AllocationSemantics; #[test] pub fn issue139_alloc_non_multiple_of_min_alignment() { - mmtk_init(200*1024*1024); + mmtk_init(200 * 1024 * 1024); let handle = mmtk_bind_mutator(VMMutatorThread(VMThread::UNINITIALIZED)); // Allocate 6 bytes with 8 bytes ailgnment required diff --git a/vmbindings/dummyvm/src/tests/malloc_counted.rs b/vmbindings/dummyvm/src/tests/malloc_counted.rs index 3f003fbecc..d5d8ef678a 100644 --- a/vmbindings/dummyvm/src/tests/malloc_counted.rs +++ b/vmbindings/dummyvm/src/tests/malloc_counted.rs @@ -1,7 +1,7 @@ // GITHUB-CI: FEATURES=malloc_counted_size -use crate::tests::fixtures::{SerialFixture, MMTKSingleton}; use crate::api::*; +use crate::tests::fixtures::{MMTKSingleton, SerialFixture}; lazy_static! { static ref MMTK_SINGLETON: SerialFixture = SerialFixture::new(); diff --git a/vmbindings/dummyvm/src/tests/malloc_ms.rs b/vmbindings/dummyvm/src/tests/malloc_ms.rs index 0eeb513163..db08f65bbb 100644 --- a/vmbindings/dummyvm/src/tests/malloc_ms.rs +++ b/vmbindings/dummyvm/src/tests/malloc_ms.rs @@ -1,5 +1,5 @@ -use mmtk::util::malloc::malloc_ms_util; use crate::DummyVM; +use mmtk::util::malloc::malloc_ms_util; #[test] fn test_malloc() { @@ -26,11 +26,15 @@ fn test_malloc() { assert!(malloc_ms_util::get_malloc_usable_size(address3, bool3) >= 16); assert!(malloc_ms_util::get_malloc_usable_size(address4, bool4) >= 32); - unsafe { malloc_ms_util::free(address1.to_mut_ptr()); } + unsafe { + malloc_ms_util::free(address1.to_mut_ptr()); + } #[cfg(feature = "malloc_hoard")] malloc_ms_util::offset_free(address2); #[cfg(not(feature = "malloc_hoard"))] - unsafe { malloc_ms_util::free(address2.to_mut_ptr()); } + unsafe { + malloc_ms_util::free(address2.to_mut_ptr()); + } malloc_ms_util::offset_free(address3); malloc_ms_util::offset_free(address4); } diff --git a/vmbindings/dummyvm/src/tests/mod.rs b/vmbindings/dummyvm/src/tests/mod.rs index 7f4974f430..c50105bb2d 100644 --- a/vmbindings/dummyvm/src/tests/mod.rs +++ b/vmbindings/dummyvm/src/tests/mod.rs @@ -4,23 +4,23 @@ // // One way to avoid re-initialization is to have only one #[test] per module. // There are also helpers for creating fixtures in `fixture/mod.rs`. -mod issue139; -mod handle_mmap_oom; -#[cfg(target_os = "linux")] -mod handle_mmap_conflict; mod allocate_align_offset; -mod allocate_without_initialize_collection; -mod allocate_with_initialize_collection; mod allocate_with_disable_collection; +mod allocate_with_initialize_collection; mod allocate_with_re_enable_collection; +mod allocate_without_initialize_collection; +mod barrier_slow_path_assertion; +#[cfg(feature = "is_mmtk_object")] +mod conservatism; +mod edges_test; +mod fixtures; +#[cfg(target_os = "linux")] +mod handle_mmap_conflict; +mod handle_mmap_oom; +mod is_in_mmtk_spaces; +mod issue139; #[cfg(not(feature = "malloc_counted_size"))] mod malloc_api; #[cfg(feature = "malloc_counted_size")] mod malloc_counted; mod malloc_ms; -#[cfg(feature = "is_mmtk_object")] -mod conservatism; -mod is_in_mmtk_spaces; -mod fixtures; -mod edges_test; -mod barrier_slow_path_assertion;