Skip to content

Commit

Permalink
Remove NULL ObjectReference
Browse files Browse the repository at this point in the history
  • Loading branch information
wks committed Apr 24, 2024
1 parent 5a2b91c commit 1bf6794
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
4 changes: 2 additions & 2 deletions mmtk/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ features = ["is_mmtk_object", "object_pinning"]

# Uncomment the following lines to use mmtk-core from the official repository.
git = "https://github.com/mmtk/mmtk-core.git"
rev = "5a01555b5aee984b634f81e9d137f1ae0410fd39"
rev = "6aa75cd72247d12b9568dc321c46feca6572a512"

# Uncomment the following line to use mmtk-core from a local repository.
#path = "../../mmtk-core"
# path = "../../mmtk-core"

[features]
default = []
Expand Down
7 changes: 3 additions & 4 deletions mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use mmtk::memory_manager;
use mmtk::memory_manager::mmtk_init;
use mmtk::util::alloc::AllocatorInfo;
use mmtk::util::alloc::AllocatorSelector;
use mmtk::util::apiutils::NullableObjectReference;
use mmtk::util::constants::MIN_OBJECT_SIZE;
use mmtk::util::options::GCTriggerSelector;
use mmtk::util::options::PlanSelector;
Expand Down Expand Up @@ -208,10 +209,8 @@ pub extern "C" fn mmtk_is_live_object(object: ObjectReference) -> bool {
}

#[no_mangle]
pub extern "C" fn mmtk_get_forwarded_object(object: ObjectReference) -> ObjectReference {
object
.get_forwarded_object::<Ruby>()
.unwrap_or(ObjectReference::NULL)
pub extern "C" fn mmtk_get_forwarded_object(object: ObjectReference) -> NullableObjectReference {
object.get_forwarded_object::<Ruby>().into()
}

#[no_mangle]
Expand Down
7 changes: 5 additions & 2 deletions mmtk/src/object_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ impl ObjectModel<Ruby> for VMObjectModel {
let from_start = from_acc.obj_start();
let object_size = from_acc.object_size();
let to_start = copy_context.alloc_copy(from, object_size, MIN_OBJ_ALIGN, 0, semantics);
debug_assert!(!to_start.is_zero());
let to_payload = to_start.add(OBJREF_OFFSET);
unsafe {
copy_nonoverlapping::<u8>(from_start.to_ptr(), to_start.to_mut_ptr(), object_size);
}
let to_obj = ObjectReference::from_raw_address(to_payload);
// unsafe: `to_payload`` cannot be zero because `alloc_copy`` never returns zero.
let to_obj = unsafe { ObjectReference::from_raw_address_unchecked(to_payload) };
copy_context.post_copy(to_obj, object_size, semantics);
trace!("Copied object from {} to {}", from, to_obj);

Expand Down Expand Up @@ -123,7 +125,8 @@ impl ObjectModel<Ruby> for VMObjectModel {
}

fn address_to_ref(addr: Address) -> ObjectReference {
ObjectReference::from_raw_address(addr)
debug_assert!(!addr.is_zero());
unsafe { ObjectReference::from_raw_address_unchecked(addr) }
}

fn get_size_when_copied(object: ObjectReference) -> usize {
Expand Down
6 changes: 5 additions & 1 deletion mmtk/src/reference_glue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct VMReferenceGlue {}
impl ReferenceGlue<Ruby> for VMReferenceGlue {
type FinalizableType = ObjectReference;

fn get_referent(_object: ObjectReference) -> ObjectReference {
fn get_referent(_object: ObjectReference) -> Option<ObjectReference> {
unimplemented!()
}

Expand All @@ -19,4 +19,8 @@ impl ReferenceGlue<Ruby> for VMReferenceGlue {
fn enqueue_references(_references: &[ObjectReference], _tls: VMWorkerThread) {
unimplemented!()
}

fn clear_referent(_new_reference: ObjectReference) {
unimplemented!()
}
}

0 comments on commit 1bf6794

Please sign in to comment.