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
11 changes: 10 additions & 1 deletion gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ struct objspace {
uintptr_t vo_bit_log_region_size;
uintptr_t vo_bit_base_addr;
size_t max_non_los_default_alloc_bytes;
bool write_barrier_required;
};

#define OBJ_FREE_BUF_CAPACITY 128
Expand Down Expand Up @@ -619,6 +620,7 @@ rb_gc_impl_objspace_init(void *objspace_ptr)
objspace->vo_bit_log_region_size = mmtk_get_vo_bit_log_region_size();
objspace->vo_bit_base_addr = mmtk_get_vo_bit_base_addr();
objspace->max_non_los_default_alloc_bytes = mmtk_max_non_los_default_alloc_bytes();
objspace->write_barrier_required = mmtk_plan_has_write_barrier();
}

void
Expand Down Expand Up @@ -1235,7 +1237,7 @@ rb_gc_impl_location(void *objspace_ptr, VALUE obj)
void
rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
{
struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache();
struct objspace *objspace = objspace_ptr;

if (SPECIAL_CONST_P(b)) return;

Expand All @@ -1254,6 +1256,9 @@ rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
MMTK_ASSERT(BUILTIN_TYPE(a) != T_NONE);
MMTK_ASSERT(BUILTIN_TYPE(b) != T_NONE);

if (!objspace->write_barrier_required) return;

struct MMTk_ractor_cache *cache = rb_gc_get_ractor_newobj_cache();
mmtk_object_reference_write_post(cache->mutator, (MMTk_ObjectReference)a);
}

Expand All @@ -1272,6 +1277,10 @@ rb_gc_impl_obj_became_shareable(void *objspace_ptr, VALUE obj)
void
rb_gc_impl_writebarrier_remember(void *objspace_ptr, VALUE obj)
{
struct objspace *objspace = objspace_ptr;

if (!objspace->write_barrier_required) return;

if (!ruby_native_thread_p()) {
/* Called from an MMTk GC worker thread (via gc_ref_update_object's
* re-embedding path during reference updating). There is no mutator
Expand Down
2 changes: 2 additions & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ bool mmtk_gc_enabled_p(void);

size_t mmtk_max_non_los_default_alloc_bytes(void);

bool mmtk_plan_has_write_barrier(void);

MMTk_Address mmtk_alloc(MMTk_Mutator *mutator,
size_t size,
size_t align,
Expand Down
6 changes: 6 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ use mmtk::MMTKBuilder;
use mmtk::Mutator;
use mmtk::memory_manager;
use mmtk::memory_manager::mmtk_init;
use mmtk::plan::BarrierSelector;
use mmtk::util::Address;
use mmtk::util::ObjectReference;
use mmtk::util::VMMutatorThread;
Expand Down Expand Up @@ -348,6 +349,11 @@ pub extern "C" fn mmtk_max_non_los_default_alloc_bytes() -> usize {
.max_non_los_default_alloc_bytes
}

#[unsafe(no_mangle)]
pub extern "C" fn mmtk_plan_has_write_barrier() -> bool {
mmtk().get_plan().constraints().barrier != BarrierSelector::NoBarrier
}

#[unsafe(no_mangle)]
pub unsafe extern "C" fn mmtk_alloc(
mutator: *mut RubyMutator,
Expand Down
Loading