use hashset for conservative root set
This commit is contained in:
parent
d84b1968d5
commit
66829edd74
1 changed files with 25 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
||||||
use std::{
|
use std::{
|
||||||
|
collections::HashSet,
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
marker::PhantomData,
|
marker::PhantomData,
|
||||||
ops::{Deref, DerefMut},
|
ops::{Deref, DerefMut},
|
||||||
|
@ -13,7 +14,7 @@ use mmtk::{
|
||||||
use crate::{object_model::object::VMKitObject, options::OPTIONS, VirtualMachine};
|
use crate::{object_model::object::VMKitObject, options::OPTIONS, VirtualMachine};
|
||||||
|
|
||||||
pub struct ConservativeRoots {
|
pub struct ConservativeRoots {
|
||||||
pub roots: Vec<ObjectReference>,
|
pub roots: HashSet<ObjectReference>,
|
||||||
pub internal_pointer_limit: usize,
|
pub internal_pointer_limit: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +30,13 @@ impl ConservativeRoots {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self
|
||||||
|
.roots
|
||||||
|
.contains(unsafe { &ObjectReference::from_raw_address_unchecked(pointer) })
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let Some(start) = mmtk::memory_manager::find_object_from_internal_pointer(
|
let Some(start) = mmtk::memory_manager::find_object_from_internal_pointer(
|
||||||
pointer,
|
pointer,
|
||||||
self.internal_pointer_limit,
|
self.internal_pointer_limit,
|
||||||
|
@ -36,7 +44,7 @@ impl ConservativeRoots {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
self.roots.push(start);
|
self.roots.insert(start);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Add all pointers in the span to the roots.
|
/// Add all pointers in the span to the roots.
|
||||||
|
@ -58,13 +66,15 @@ impl ConservativeRoots {
|
||||||
|
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
roots: Vec::new(),
|
roots: HashSet::new(),
|
||||||
internal_pointer_limit: OPTIONS.interior_pointer_max_bytes,
|
internal_pointer_limit: OPTIONS.interior_pointer_max_bytes,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_to_factory<SL: Slot>(&mut self, factory: &mut impl RootsWorkFactory<SL>) {
|
pub fn add_to_factory<SL: Slot>(&mut self, factory: &mut impl RootsWorkFactory<SL>) {
|
||||||
factory.create_process_pinning_roots_work(std::mem::take(&mut self.roots));
|
factory.create_process_tpinning_roots_work(std::mem::take(
|
||||||
|
&mut self.roots.clone().into_iter().collect(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +101,10 @@ impl<T, VM: VirtualMachine> InternalPointer<T, VM> {
|
||||||
.is_some(),
|
.is_some(),
|
||||||
"Internal pointer is not in the heap"
|
"Internal pointer is not in the heap"
|
||||||
);
|
);
|
||||||
assert!(VM::CONSERVATIVE_TRACING, "Internal pointers are not supported without VM::CONSERVATIVE_TRACING set to true");
|
assert!(
|
||||||
|
VM::CONSERVATIVE_TRACING,
|
||||||
|
"Internal pointers are not supported without VM::CONSERVATIVE_TRACING set to true"
|
||||||
|
);
|
||||||
Self {
|
Self {
|
||||||
address,
|
address,
|
||||||
_marker: std::marker::PhantomData,
|
_marker: std::marker::PhantomData,
|
||||||
|
@ -108,7 +121,12 @@ impl<T, VM: VirtualMachine> InternalPointer<T, VM> {
|
||||||
///
|
///
|
||||||
/// Panics if the pointer is not in the heap.
|
/// Panics if the pointer is not in the heap.
|
||||||
pub fn object(&self) -> VMKitObject {
|
pub fn object(&self) -> VMKitObject {
|
||||||
mmtk::memory_manager::find_object_from_internal_pointer(self.address, OPTIONS.interior_pointer_max_bytes).unwrap().into()
|
mmtk::memory_manager::find_object_from_internal_pointer(
|
||||||
|
self.address,
|
||||||
|
OPTIONS.interior_pointer_max_bytes,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return offset from the object start.
|
/// Return offset from the object start.
|
||||||
|
|
Loading…
Add table
Reference in a new issue