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
28 changes: 28 additions & 0 deletions mmtk/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ impl GCThreadTLS {
}
}

#[repr(C)]
#[derive(Clone)]
pub struct RawVecOfObjRef {
pub ptr: *mut ObjectReference,
pub len: usize,
pub capa: usize,
}

impl RawVecOfObjRef {
pub fn from_vec(vec: Vec<ObjectReference>) -> RawVecOfObjRef {
// Note: Vec::into_raw_parts is unstable. We implement it manually.
let mut vec = std::mem::ManuallyDrop::new(vec);
let (ptr, len, capa) = (vec.as_mut_ptr(), vec.len(), vec.capacity());

RawVecOfObjRef { ptr, len, capa }
}

pub unsafe fn into_vec(self) -> Vec<ObjectReference> {
Vec::from_raw_parts(self.ptr, self.len, self.capa)
}
}

impl Into<RawVecOfObjRef> for Vec<ObjectReference> {
fn into(self) -> RawVecOfObjRef {
RawVecOfObjRef::from_vec(self)
}
}

#[repr(C)]
#[derive(Clone)]
pub struct RubyUpcalls {
Expand Down
24 changes: 15 additions & 9 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::ffi::CStr;

use crate::abi;
use crate::abi::RawVecOfObjRef;
use crate::binding::RubyBinding;
use crate::mmtk;
use crate::Ruby;
Expand Down Expand Up @@ -208,16 +209,21 @@ pub extern "C" fn mmtk_last_heap_address() -> Address {
}

#[no_mangle]
pub extern "C" fn mmtk_register_finalizable(reff: ObjectReference) {
crate::binding()
.finalizer_processor
.register_finalizable(reff);
pub extern "C" fn mmtk_add_finalizer(reff: ObjectReference) {
memory_manager::add_finalizer(crate::mmtk(), reff)
}

#[no_mangle]
pub extern "C" fn mmtk_poll_finalizable(include_live: bool) -> ObjectReference {
crate::binding()
.finalizer_processor
.poll_finalizable(include_live)
.unwrap_or_else(|| unsafe { Address::zero().to_object_reference() })
pub extern "C" fn mmtk_get_finalized_object() -> ObjectReference {
memory_manager::get_finalized_object(crate::mmtk()).unwrap_or(ObjectReference::NULL)
}

#[no_mangle]
pub extern "C" fn mmtk_get_all_finalizers() -> RawVecOfObjRef {
memory_manager::get_all_finalizers(crate::mmtk()).into()
}

#[no_mangle]
pub extern "C" fn mmtk_free_raw_vec_of_obj_ref(raw_vec: RawVecOfObjRef) {
unsafe { raw_vec.into_vec() };
}
3 changes: 0 additions & 3 deletions mmtk/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ use std::sync::Mutex;
use mmtk::MMTK;

use crate::abi;
use crate::finalize;
use crate::Ruby;

pub struct RubyBinding {
pub mmtk: &'static MMTK<Ruby>,
pub upcalls: *const abi::RubyUpcalls,
pub finalizer_processor: finalize::FinalizerProcessor,
pub plan_name: Mutex<Option<CString>>,
}

Expand All @@ -22,7 +20,6 @@ impl RubyBinding {
Self {
mmtk,
upcalls,
finalizer_processor: finalize::FinalizerProcessor::new(),
plan_name: Mutex::new(None),
}
}
Expand Down
37 changes: 0 additions & 37 deletions mmtk/src/finalize.rs

This file was deleted.

1 change: 0 additions & 1 deletion mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pub mod active_plan;
pub mod api;
pub mod binding;
pub mod collection;
pub mod finalize;
pub mod object_model;
pub mod reference_glue;
pub mod scanning;
Expand Down
9 changes: 0 additions & 9 deletions mmtk/src/scanning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,6 @@ impl Scanning<Ruby> for VMScanning {
Self::collect_object_roots_in("scan_vm_specific_roots", gc_tls, &mut factory, || {
(upcalls().scan_vm_specific_roots)();
});
{
// FIXME: This is a workaround. Obviously it will keep all finalizable objects alive until program exits.
debug!("[scan_vm_specific_roots] Enqueueing candidates.");
let candidates = crate::binding()
.finalizer_processor
.with_candidates(|v| v.to_vec());
factory.create_process_node_roots_work(candidates);
debug!("[scan_vm_specific_roots] Finished Enqueueing candidates.");
}
}

fn supports_return_barrier() -> bool {
Expand Down