Skip to content

Commit

Permalink
Merge branch 'master' into fix/to_object_address
Browse files Browse the repository at this point in the history
  • Loading branch information
k-sareen authored Oct 25, 2023
2 parents 8503b6a + 59ff055 commit b2b2675
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 31 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ jobs:
base_repo: mmtk/mmtk-jikesrvm
ref: ${{ needs.binding-refs.outputs.jikesrvm_binding_ref }}
core_commit: ${{ needs.get-merged-pr.outputs.commit }}
update_lockfile: cargo build --features nogc --target i686-unknown-linux-gnu
# `cargo generate-lockfile` will update other dependencies. We avoid using it for the bindings.
# But we do not have a good option for JikesRVM. The Rust project in JikesRVM needs some source files
# that are generated during its build process. Unless we want to do a full build for JikesRVM, we cannot
# use `cargo build`. So use `cargo generate-lockfile` instead.
update_lockfile: cargo generate-lockfile
secrets: inherit

check-merge-v8-pr:
Expand Down
18 changes: 7 additions & 11 deletions src/util/alloc/bumpallocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct BumpAllocator<VM: VMBinding> {

/// A common fast-path bump-pointer allocator shared across different allocator implementations
/// that use bump-pointer allocation.
/// A `BumpPointer` is always initialized with cursor = 0, limit = 0, so the first allocation
/// always fails the check of `cursor + size < limit` and goes to the slowpath. A binding
/// can also take advantage of this design to zero-initialize the a bump pointer.
#[repr(C)]
#[derive(Copy, Clone)]
pub struct BumpPointer {
Expand All @@ -34,24 +37,17 @@ pub struct BumpPointer {
}

impl BumpPointer {
pub const fn new(start: Address, end: Address) -> Self {
BumpPointer {
cursor: start,
limit: end,
}
}

pub fn reset(&mut self, start: Address, end: Address) {
self.cursor = start;
self.limit = end;
}
}

impl std::default::Default for BumpPointer {
/// Defaults to 0,0. In this case, the first
/// allocation would naturally fail the check
/// `cursor + size < limit`, and go to the slowpath.
fn default() -> Self {
// Defaults to 0,0. In this case, the first
// allocation would naturally fail the check
// `cursor + size < limit`, and go to the slowpath.
BumpPointer {
cursor: Address::ZERO,
limit: Address::ZERO,
Expand Down Expand Up @@ -180,7 +176,7 @@ impl<VM: VMBinding> BumpAllocator<VM> {
) -> Self {
BumpAllocator {
tls,
bump_pointer: unsafe { BumpPointer::new(Address::zero(), Address::zero()) },
bump_pointer: BumpPointer::default(),
space,
context,
}
Expand Down
4 changes: 2 additions & 2 deletions src/util/alloc/immix_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ impl<VM: VMBinding> ImmixAllocator<VM> {
tls,
space: space.unwrap().downcast_ref::<ImmixSpace<VM>>().unwrap(),
context,
bump_pointer: BumpPointer::new(Address::ZERO, Address::ZERO),
bump_pointer: BumpPointer::default(),
hot: false,
copy,
large_bump_pointer: BumpPointer::new(Address::ZERO, Address::ZERO),
large_bump_pointer: BumpPointer::default(),
request_for_large: false,
line: None,
}
Expand Down
8 changes: 5 additions & 3 deletions src/vm/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,25 @@ pub enum GCThreadContext<VM: VMBinding> {
/// VM-specific methods for garbage collection.
pub trait Collection<VM: VMBinding> {
/// Stop all the mutator threads. MMTk calls this method when it requires all the mutator to yield for a GC.
/// This method is called by a single thread in MMTk (the GC controller).
/// This method should not return until all the threads are yielded.
/// The actual thread synchronization mechanism is up to the VM, and MMTk does not make assumptions on that.
/// MMTk provides a callback function and expects the binding to use the callback for each mutator when it
/// is ready for stack scanning. Usually a stack can be scanned as soon as the thread stops in the yieldpoint.
///
/// Arguments:
/// * `tls`: The thread pointer for the GC controller/coordinator.
/// * `tls`: The thread pointer for the GC worker.
/// * `mutator_visitor`: A callback. Call it with a mutator as argument to notify MMTk that the mutator is ready to be scanned.
fn stop_all_mutators<F>(tls: VMWorkerThread, mutator_visitor: F)
where
F: FnMut(&'static mut Mutator<VM>);

/// Resume all the mutator threads, the opposite of the above. When a GC is finished, MMTk calls this method.
///
/// This method may not be called by the same GC thread that called `stop_all_mutators`.
///
/// Arguments:
/// * `tls`: The thread pointer for the GC controller/coordinator.
/// * `tls`: The thread pointer for the GC worker. Currently it is the tls of the embedded `GCWorker` instance
/// of the coordinator thread, but it is subject to change, and should not be depended on.
fn resume_mutators(tls: VMWorkerThread);

/// Block the current thread for GC. This is called when an allocation request cannot be fulfilled and a GC
Expand Down
18 changes: 4 additions & 14 deletions vmbindings/dummyvm/src/tests/doc_mutator_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,9 @@ pub fn embed_fastpath_struct() {

// Bind an MMTk mutator
let mutator = mmtk::memory_manager::bind_mutator(&fixture.mmtk, tls_opaque_pointer);
// Create a fastpath BumpPointer
let default_bump_pointer = {
// First find the allocator
let selector = mmtk::memory_manager::get_allocator_mapping(
&fixture.mmtk,
AllocationSemantics::Default,
);
let default_allocator = unsafe {
mutator.allocator_impl::<mmtk::util::alloc::BumpAllocator<DummyVM>>(selector)
};
// Copy the bump pointer struct
default_allocator.bump_pointer
};
// Create a fastpath BumpPointer with default(). The BumpPointer from default() will guarantee to fail on the first allocation
// so the allocation goes to the slowpath and we will get an allocation buffer from MMTk.
let default_bump_pointer = BumpPointer::default();
// Store the fastpath BumpPointer along with the mutator
let mut storage = MutatorInTLS {
default_bump_pointer,
Expand Down Expand Up @@ -119,7 +109,7 @@ pub fn embed_fastpath_struct() {
default_allocator.bump_pointer = storage.default_bump_pointer;
// Do slow path allocation with MMTk
let addr = default_allocator.alloc_slow(size, 8, 0);
// Copy bump pointer values to the fastpath BumpPointer
// Copy bump pointer values to the fastpath BumpPointer so we will have an allocation buffer.
storage.default_bump_pointer = default_allocator.bump_pointer;
addr
}
Expand Down

0 comments on commit b2b2675

Please sign in to comment.