Skip to content

Commit 31a78a4

Browse files
authored
Deduplicate specs in SideMetadataSanity::get_all_specs (#1342)
For 32 bits chunked side metadata, we check the total size of side metadata per chunk to make sure it won't get too large. https://github.com/mmtk/mmtk-core/blob/1dc681561097688ac37382b1e23e56f2d160b7c7/src/util/metadata/side_metadata/sanity.rs#L112 However, the function `get_all_specs` collects all the side metadata specs from all the policies, and different policies may use the same local side metadata. This results in duplicate entries in the vec, and results in incorrect total size calculated based on the vec. This PR fixes this.
1 parent f177258 commit 31a78a4

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/util/metadata/side_metadata/sanity.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,10 @@ impl SideMetadataSanity {
232232
specs.append(&mut (*v).clone());
233233
}
234234
}
235-
236-
specs
235+
// Deduplicate the specs using a hashset
236+
std::collections::HashSet::<SideMetadataSpec>::from_iter(specs)
237+
.into_iter()
238+
.collect()
237239
}
238240

239241
/// Verifies that all local side metadata specs:
@@ -852,4 +854,34 @@ mod tests {
852854
assert!(verify_local_specs_size(&[spec_1, spec_1]).is_err());
853855
assert!(verify_local_specs_size(&[spec_1, spec_1, spec_1, spec_1, spec_1]).is_err());
854856
}
857+
858+
#[test]
859+
fn test_side_metadata_sanity_get_all_local_specs() {
860+
let spec_1 = SideMetadataSpec {
861+
name: "spec_1",
862+
is_global: false,
863+
offset: SideMetadataOffset::rel(0),
864+
log_num_of_bits: 0,
865+
log_bytes_in_region: 0,
866+
};
867+
868+
let mut sanity = SideMetadataSanity::new();
869+
sanity.verify_metadata_context(
870+
"policy1",
871+
&SideMetadataContext {
872+
global: vec![],
873+
local: vec![spec_1],
874+
},
875+
);
876+
sanity.verify_metadata_context(
877+
"policy2",
878+
&SideMetadataContext {
879+
global: vec![],
880+
local: vec![spec_1],
881+
},
882+
);
883+
884+
let local_specs = sanity.get_all_specs(false);
885+
assert_eq!(local_specs.len(), 1);
886+
}
855887
}

0 commit comments

Comments
 (0)