Skip to content

Commit

Permalink
Remove NULL ObjectReference (#62)
Browse files Browse the repository at this point in the history
Parent PR: mmtk/mmtk-core#1064

---------

Co-authored-by: mmtkgc-bot <mmtkgc.bot@gmail.com>
  • Loading branch information
wks and mmtkgc-bot authored Apr 27, 2024
1 parent 5a2b91c commit eacde09
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
8 changes: 4 additions & 4 deletions mmtk/Cargo.lock

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

6 changes: 3 additions & 3 deletions mmtk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ edition = "2021"
# Metadata for the Ruby repository
[package.metadata.ci-repos.ruby]
repo = "mmtk/ruby" # This is used by actions/checkout, so the format is "owner/repo", not URL.
rev = "f63ea9a7ab846f8c1e0fab3ea61cdd1b364a661c"
rev = "2a566599cdb83134df4c64a4991b26e2a96dc24a"

[lib]
name = "mmtk_ruby"
Expand All @@ -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 = "a02803b4104519ff2289234101a2dd8ceedd1bc7"

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

[features]
default = []
Expand Down
2 changes: 2 additions & 0 deletions mmtk/cbindgen.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ typedef rb_thread_t* MMTk_VMMutatorThread;
typedef struct MMTk_GCThreadTLS* MMTk_VMWorkerThread;
typedef void* MMTk_Address;
typedef void* MMTk_ObjectReference;
typedef void* MMTk_NullableObjectReference;
typedef uint32_t MMTk_AllocationSemantics;
"""

Expand All @@ -34,6 +35,7 @@ typedef uint32_t MMTk_AllocationSemantics;
"VMWorkerThread" = "MMTk_VMWorkerThread"
"Address" = "MMTk_Address"
"ObjectReference" = "MMTk_ObjectReference"
"NullableObjectReference" = "MMTk_NullableObjectReference"
"RawVecOfObjRef" = "MMTk_RawVecOfObjRef"
"AllocationSemantics" = "MMTk_AllocationSemantics"
"GC_THREAD_KIND_CONTROLLER" = "MMTK_GC_THREAD_KIND_CONTROLLER"
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::api_util::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 eacde09

Please sign in to comment.