struct AllocationOptionsHolder {
alloc_options: RefCell<AllocationOptions>,
}Expand description
A wrapper for AllocatorContext to hold a AllocationOptions that can be modified by the
same mutator thread.
All Allocator instances in Allocators share one AllocationOptions instance, and it will
only be accessed by the mutator (via Mutator::allocators) or the GC worker (via
GCWorker::copy) that owns it. Rust doesn’t like multiple mutable references pointing to a
shared data structure. We cannot use [atomic::Atomic] because AllocationOptions has
multiple fields. We wrap it in a RefCell to make it internally mutable.
Note: The allocation option is called every time Allocator::alloc_with_options is called.
Because API functions should only be called on allocation slow paths, we believe that RefCell
should be good enough for performance. If this is too slow, we may consider UnsafeCell. If
that’s still too slow, we should consider changing the API to make the allocation options a
persistent per-mutator value, and allow the VM binding set its value via a new API function.
Fields§
§alloc_options: RefCell<AllocationOptions>Implementations§
source§impl AllocationOptionsHolder
impl AllocationOptionsHolder
pub fn new(alloc_options: AllocationOptions) -> Self
pub fn set_alloc_options(&self, options: AllocationOptions)
pub fn clear_alloc_options(&self)
pub fn get_alloc_options(&self) -> AllocationOptions
Trait Implementations§
impl Sync for AllocationOptionsHolder
Strictly speaking, AllocationOptionsHolder isn’t Sync. Two threads cannot set or clear the
same AllocationOptionsHolder at the same time. However, both Mutator and GCWorker are
Send, and both of which own Allocators and require its field Arc<AllocationContext> to be
Send, which requires AllocationContext to be Sync, which requires
AllocationOptionsHolder to be Sync. (Note that Arc<T> can be cloned and given to another
thread, and Rust expects T to be Sync, too. But we never share AllocationContext between
threads, but only between multiple Allocator instances within the same Allocators instance.
Rust can’t figure this out.)
Auto Trait Implementations§
impl !Freeze for AllocationOptionsHolder
impl !RefUnwindSafe for AllocationOptionsHolder
impl Send for AllocationOptionsHolder
impl Unpin for AllocationOptionsHolder
impl UnwindSafe for AllocationOptionsHolder
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more