Skip to content

Commit

Permalink
Implement rb_gc_impl_copy_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterzhu2118 committed Oct 9, 2024
1 parent 184cff6 commit f4cb3c2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions gc/mmtk.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// clang -I.. -L mmtk/target/debug -lmmtk_ruby -undefined dynamic_lookup -g -O3 -dynamiclib -o ../build/libgc.mmtk.dylib mmtk.c

#include <pthread.h>
#include <stdbool.h>

Expand Down Expand Up @@ -1247,7 +1245,16 @@ rb_gc_impl_garbage_object_p(void *objspace_ptr, VALUE obj)
}

void rb_gc_impl_set_event_hook(void *objspace_ptr, const rb_event_flag_t event) { }
void rb_gc_impl_copy_attributes(void *objspace_ptr, VALUE dest, VALUE obj) { }

void
rb_gc_impl_copy_attributes(void *objspace_ptr, VALUE dest, VALUE obj)
{
if (mmtk_object_wb_unprotected_p((MMTk_ObjectReference)obj)) {
rb_gc_impl_writebarrier_unprotect(objspace_ptr, dest);
}

rb_gc_impl_copy_finalizer(objspace_ptr, dest, obj);
}

// GC Identification

Expand Down
2 changes: 2 additions & 0 deletions gc/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ void mmtk_object_reference_write_post(MMTk_Mutator *mutator, MMTk_ObjectReferenc

void mmtk_register_wb_unprotected_object(MMTk_ObjectReference object);

bool mmtk_object_wb_unprotected_p(MMTk_ObjectReference object);

void mmtk_enumerate_objects(void (*callback)(MMTk_ObjectReference, void*), void *data);

struct MMTk_RawVecOfObjRef mmtk_get_all_obj_free_candidates(void);
Expand Down
5 changes: 5 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ pub extern "C" fn mmtk_register_wb_unprotected_object(object: ObjectReference) {
crate::binding().register_wb_unprotected_object(object)
}

#[no_mangle]
pub extern "C" fn mmtk_object_wb_unprotected_p(object: ObjectReference) -> bool {
crate::binding().object_wb_unprotected_p(object)
}

// =============== Heap walking ===============

#[no_mangle]
Expand Down
2 changes: 1 addition & 1 deletion gc/mmtk/src/binding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl RubyBinding {
objects.insert(object);
}

pub fn is_object_wb_unprotected(&self, object: ObjectReference) -> bool {
pub fn object_wb_unprotected_p(&self, object: ObjectReference) -> bool {
let objects = self.wb_unprotected_objects.lock().unwrap();
objects.contains(&object)
}
Expand Down

0 comments on commit f4cb3c2

Please sign in to comment.