Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ mimalloc-sys = { version = "0.1.6", optional = true }
mmtk-macros = { version = "0.18.0", path = "macros/" }
num_cpus = "1.8"
num-traits = "0.2"
pfm = { version = "0.1.0-beta.1", optional = true }
pfm = { version = "0.1.0-beta.3", optional = true }
regex = "1.7.0"
spin = "0.9.5"
static_assertions = "1.1.0"
Expand Down
4 changes: 2 additions & 2 deletions docs/header/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ extern void mmtk_disable_collection();
extern void* mmtk_alloc(MMTk_Mutator mutator,
size_t size,
size_t align,
ssize_t offset,
size_t offset,
int allocator);

// Slowpath allocation for an object
extern void* mmtk_alloc_slow(MMTk_Mutator mutator,
size_t size,
size_t align,
ssize_t offset,
size_t offset,
int allocator);

// Perform post-allocation hooks or actions such as initializing object metadata
Expand Down
6 changes: 3 additions & 3 deletions examples/reference_bump_allocator.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extern MMTk_Mutator bind_mutator(void *tls) {
return NULL;
}

extern void* align_allocation(void* region, size_t align, ssize_t offset) {
extern void* align_allocation(void* region, size_t align, size_t offset) {
ssize_t region_signed = (ssize_t) region;

ssize_t mask = (ssize_t) (align - 1);
Expand All @@ -42,7 +42,7 @@ extern void* align_allocation(void* region, size_t align, ssize_t offset) {
}

extern void* alloc(MMTk_Mutator mutator, size_t size,
size_t align, ssize_t offset, int allocator) {
size_t align, size_t offset, int allocator) {

void* result = align_allocation(IMMORTAL_SPACE.heap_cursor, align, offset);
void* new_cursor = (void*)((size_t) result + size);
Expand All @@ -54,7 +54,7 @@ extern void* alloc(MMTk_Mutator mutator, size_t size,
}

extern void* alloc_slow(MMTk_Mutator mutator, size_t size,
size_t align, ssize_t offset, int allocator) {
size_t align, size_t offset, int allocator) {

perror("Not implemented\n");
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion src/memory_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub fn alloc<VM: VMBinding>(
mutator: &mut Mutator<VM>,
size: usize,
align: usize,
offset: isize,
offset: usize,
semantics: AllocationSemantics,
) -> Address {
// MMTk has assumptions about minimal object size.
Expand Down
4 changes: 2 additions & 2 deletions src/plan/mutator_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl<VM: VMBinding> MutatorContext<VM> for Mutator<VM> {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
allocator: AllocationSemantics,
) -> Address {
unsafe {
Expand Down Expand Up @@ -161,7 +161,7 @@ pub trait MutatorContext<VM: VMBinding>: Send + 'static {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
allocator: AllocationSemantics,
) -> Address;
fn post_alloc(&mut self, refer: ObjectReference, bytes: usize, allocator: AllocationSemantics);
Expand Down
2 changes: 1 addition & 1 deletion src/policy/copy_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub trait PolicyCopyContext: 'static + Send {
original: ObjectReference,
bytes: usize,
align: usize,
offset: isize,
offset: usize,
) -> Address;
fn post_copy(&mut self, _obj: ObjectReference, _bytes: usize) {}
}
2 changes: 1 addition & 1 deletion src/policy/copyspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl<VM: VMBinding> PolicyCopyContext for CopySpaceCopyContext<VM> {
_original: ObjectReference,
bytes: usize,
align: usize,
offset: isize,
offset: usize,
) -> Address {
self.copy_allocator.alloc(bytes, align, offset)
}
Expand Down
4 changes: 2 additions & 2 deletions src/policy/immix/immixspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ impl<VM: VMBinding> PolicyCopyContext for ImmixCopyContext<VM> {
_original: ObjectReference,
bytes: usize,
align: usize,
offset: isize,
offset: usize,
) -> Address {
self.allocator.alloc(bytes, align, offset)
}
Expand Down Expand Up @@ -949,7 +949,7 @@ impl<VM: VMBinding> PolicyCopyContext for ImmixHybridCopyContext<VM> {
_original: ObjectReference,
bytes: usize,
align: usize,
offset: isize,
offset: usize,
) -> Address {
if self.get_space().in_defrag() {
self.defrag_allocator.alloc(bytes, align, offset)
Expand Down
2 changes: 1 addition & 1 deletion src/policy/marksweepspace/malloc_ms/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<VM: VMBinding> MallocSpace<VM> {
}
}

pub fn alloc(&self, tls: VMThread, size: usize, align: usize, offset: isize) -> Address {
pub fn alloc(&self, tls: VMThread, size: usize, align: usize, offset: usize) -> Address {
// TODO: Should refactor this and Space.acquire()
if self.get_gc_trigger().poll(false, Some(self)) {
assert!(VM::VMActivePlan::is_mutator(tls), "Polling in GC worker");
Expand Down
21 changes: 10 additions & 11 deletions src/util/alloc/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,23 @@ pub enum AllocationError {
pub fn align_allocation_no_fill<VM: VMBinding>(
region: Address,
alignment: usize,
offset: isize,
offset: usize,
) -> Address {
align_allocation_inner::<VM>(region, alignment, offset, VM::MIN_ALIGNMENT, false)
}

pub fn align_allocation<VM: VMBinding>(
region: Address,
alignment: usize,
offset: isize,
offset: usize,
) -> Address {
align_allocation_inner::<VM>(region, alignment, offset, VM::MIN_ALIGNMENT, true)
}

pub fn align_allocation_inner<VM: VMBinding>(
region: Address,
alignment: usize,
offset: isize,
offset: usize,
known_alignment: usize,
fillalignmentgap: bool,
) -> Address {
Expand All @@ -51,10 +51,9 @@ pub fn align_allocation_inner<VM: VMBinding>(
}
debug_assert!(!(fillalignmentgap && region.is_zero()));
debug_assert!(alignment <= VM::MAX_ALIGNMENT);
debug_assert!(offset >= 0);
debug_assert!(region.is_aligned_to(VM::ALLOC_END_ALIGNMENT));
debug_assert!((alignment & (VM::MIN_ALIGNMENT - 1)) == 0);
debug_assert!((offset & (VM::MIN_ALIGNMENT - 1) as isize) == 0);
debug_assert!((offset & (VM::MIN_ALIGNMENT - 1)) == 0);

// No alignment ever required.
if alignment <= known_alignment || VM::MAX_ALIGNMENT <= VM::MIN_ALIGNMENT {
Expand All @@ -64,7 +63,7 @@ pub fn align_allocation_inner<VM: VMBinding>(
// May require an alignment
let region_isize = region.as_usize() as isize;
let mask = (alignment - 1) as isize; // fromIntSignExtend
let neg_off = -offset; // fromIntSignExtend
let neg_off: isize = -(offset as isize); // fromIntSignExtend

// TODO: Consider using neg_off.wrapping_sub_unsigned(region.as_usize()), and we can remove region_isize.
// This requires Rust 1.66.0+.
Expand Down Expand Up @@ -164,7 +163,7 @@ pub trait Allocator<VM: VMBinding>: Downcast {
/// * `size`: the allocation size in bytes.
/// * `align`: the required alignment in bytes.
/// * `offset` the required offset in bytes.
fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address;
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address;

/// Slowpath allocation attempt. This function is explicitly not inlined for performance
/// considerations.
Expand All @@ -174,7 +173,7 @@ pub trait Allocator<VM: VMBinding>: Downcast {
/// * `align`: the required alignment in bytes.
/// * `offset` the required offset in bytes.
#[inline(never)]
fn alloc_slow(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow(&mut self, size: usize, align: usize, offset: usize) -> Address {
self.alloc_slow_inline(size, align, offset)
}

Expand All @@ -194,7 +193,7 @@ pub trait Allocator<VM: VMBinding>: Downcast {
/// * `size`: the allocation size in bytes.
/// * `align`: the required alignment in bytes.
/// * `offset` the required offset in bytes.
fn alloc_slow_inline(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow_inline(&mut self, size: usize, align: usize, offset: usize) -> Address {
let tls = self.get_tls();
let plan = self.get_plan().base();
let is_mutator = VM::VMActivePlan::is_mutator(tls);
Expand Down Expand Up @@ -317,7 +316,7 @@ pub trait Allocator<VM: VMBinding>: Downcast {
/// * `size`: the allocation size in bytes.
/// * `align`: the required alignment in bytes.
/// * `offset` the required offset in bytes.
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: isize) -> Address;
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: usize) -> Address;

/// Single slowpath allocation attempt for stress test. When the stress factor is set (e.g. to
/// N), we would expect for every N bytes allocated, we will trigger a stress GC. However, for
Expand Down Expand Up @@ -351,7 +350,7 @@ pub trait Allocator<VM: VMBinding>: Downcast {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
need_poll: bool,
) -> Address {
// If an allocator does thread local allocation but does not override this method to
Expand Down
8 changes: 4 additions & 4 deletions src/util/alloc/bumpallocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<VM: VMBinding> Allocator<VM> for BumpAllocator<VM> {
BLOCK_SIZE
}

fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
trace!("alloc");
let result = align_allocation_no_fill::<VM>(self.cursor, align, offset);
let new_cursor = result + size;
Expand All @@ -83,7 +83,7 @@ impl<VM: VMBinding> Allocator<VM> for BumpAllocator<VM> {
}
}

fn alloc_slow_once(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: usize) -> Address {
trace!("alloc_slow");
self.acquire_block(size, align, offset, false)
}
Expand All @@ -100,7 +100,7 @@ impl<VM: VMBinding> Allocator<VM> for BumpAllocator<VM> {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
need_poll: bool,
) -> Address {
if need_poll {
Expand Down Expand Up @@ -155,7 +155,7 @@ impl<VM: VMBinding> BumpAllocator<VM> {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
stress_test: bool,
) -> Address {
let block_size = (size + BLOCK_MASK) & (!BLOCK_MASK);
Expand Down
6 changes: 3 additions & 3 deletions src/util/alloc/free_list_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<VM: VMBinding> Allocator<VM> for FreeListAllocator<VM> {
}

// Find a block with free space and allocate to it
fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
debug_assert!(
size <= MAX_BIN_SIZE,
"Alloc request for {} bytes is too big.",
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<VM: VMBinding> Allocator<VM> for FreeListAllocator<VM> {
self.alloc_slow(size, align, offset)
}

fn alloc_slow_once(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: usize) -> Address {
// Try get a block from the space
if let Some(block) = self.acquire_global_block(size, align, false) {
let addr = self.block_alloc(block);
Expand All @@ -101,7 +101,7 @@ impl<VM: VMBinding> Allocator<VM> for FreeListAllocator<VM> {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
need_poll: bool,
) -> Address {
trace!("allow slow precise stress s={}", size);
Expand Down
16 changes: 8 additions & 8 deletions src/util/alloc/immix_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<VM: VMBinding> Allocator<VM> for ImmixAllocator<VM> {
crate::policy::immix::block::Block::BYTES
}

fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
debug_assert!(
size <= crate::policy::immix::MAX_IMMIX_OBJECT_SIZE,
"Trying to allocate a {} bytes object, which is larger than MAX_IMMIX_OBJECT_SIZE {}",
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<VM: VMBinding> Allocator<VM> for ImmixAllocator<VM> {
}

/// Acquire a clean block from ImmixSpace for allocation.
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow_once(&mut self, size: usize, align: usize, offset: usize) -> Address {
trace!("{:?}: alloc_slow_once", self.tls);
self.acquire_clean_block(size, align, offset)
}
Expand All @@ -117,7 +117,7 @@ impl<VM: VMBinding> Allocator<VM> for ImmixAllocator<VM> {
&mut self,
size: usize,
align: usize,
offset: isize,
offset: usize,
need_poll: bool,
) -> Address {
trace!("{:?}: alloc_slow_once_precise_stress", self.tls);
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
}

/// Large-object (larger than a line) bump allocation.
fn overflow_alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn overflow_alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
trace!("{:?}: overflow_alloc", self.tls);
let start = align_allocation_no_fill::<VM>(self.large_cursor, align, offset);
let end = start + size;
Expand All @@ -212,7 +212,7 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
}

/// Bump allocate small objects into recyclable lines (i.e. holes).
fn alloc_slow_hot(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc_slow_hot(&mut self, size: usize, align: usize, offset: usize) -> Address {
trace!("{:?}: alloc_slow_hot", self.tls);
if self.acquire_recyclable_lines(size, align, offset) {
// If stress test is active, then we need to go to the slow path instead of directly
Expand All @@ -238,7 +238,7 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
}

/// Search for recyclable lines.
fn acquire_recyclable_lines(&mut self, size: usize, align: usize, offset: isize) -> bool {
fn acquire_recyclable_lines(&mut self, size: usize, align: usize, offset: usize) -> bool {
while self.line.is_some() || self.acquire_recyclable_block() {
let line = self.line.unwrap();
if let Some((start_line, end_line)) = self.immix_space().get_next_available_lines(line)
Expand Down Expand Up @@ -289,7 +289,7 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
}

// Get a clean block from ImmixSpace.
fn acquire_clean_block(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn acquire_clean_block(&mut self, size: usize, align: usize, offset: usize) -> Address {
match self.immix_space().get_clean_block(self.tls, self.copy) {
None => Address::ZERO,
Some(block) => {
Expand All @@ -314,7 +314,7 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
/// Return whether the TLAB has been exhausted and we need to acquire a new block. Assumes that
/// the buffer limits have been restored using [`ImmixAllocator::restore_limit_for_stress`].
/// Note that this function may implicitly change the limits of the allocator.
fn require_new_block(&mut self, size: usize, align: usize, offset: isize) -> bool {
fn require_new_block(&mut self, size: usize, align: usize, offset: usize) -> bool {
let result = align_allocation_no_fill::<VM>(self.cursor, align, offset);
let new_cursor = result + size;
let insufficient_space = new_cursor > self.limit;
Expand Down
4 changes: 2 additions & 2 deletions src/util/alloc/large_object_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<VM: VMBinding> Allocator<VM> for LargeObjectAllocator<VM> {
false
}

fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
let cell: Address = self.alloc_slow(size, align, offset);
// We may get a null ptr from alloc due to the VM being OOM
if !cell.is_zero() {
Expand All @@ -44,7 +44,7 @@ impl<VM: VMBinding> Allocator<VM> for LargeObjectAllocator<VM> {
}
}

fn alloc_slow_once(&mut self, size: usize, align: usize, _offset: isize) -> Address {
fn alloc_slow_once(&mut self, size: usize, align: usize, _offset: usize) -> Address {
let header = 0; // HashSet is used instead of DoublyLinkedList
let maxbytes = allocator::get_maximum_aligned_size::<VM>(size + header, align);
let pages = crate::util::conversions::bytes_to_pages_up(maxbytes);
Expand Down
6 changes: 2 additions & 4 deletions src/util/alloc/malloc_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<VM: VMBinding> Allocator<VM> for MallocAllocator<VM> {
self.plan
}

fn alloc(&mut self, size: usize, align: usize, offset: isize) -> Address {
fn alloc(&mut self, size: usize, align: usize, offset: usize) -> Address {
self.alloc_slow(size, align, offset)
}

Expand All @@ -37,9 +37,7 @@ impl<VM: VMBinding> Allocator<VM> for MallocAllocator<VM> {
false
}

fn alloc_slow_once(&mut self, size: usize, align: usize, offset: isize) -> Address {
assert!(offset >= 0);

fn alloc_slow_once(&mut self, size: usize, align: usize, offset: usize) -> Address {
self.space.alloc(self.tls, size, align, offset)
}
}
Expand Down
Loading