Skip to content

Commit

Permalink
Merge branch 'dev/mmtk-overrides-default' into update/enable-2024-09-10
Browse files Browse the repository at this point in the history
  • Loading branch information
wks committed Sep 19, 2024
2 parents 29612e3 + f38ff71 commit 8e171bf
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 189 deletions.
9 changes: 9 additions & 0 deletions compile.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
#include "insns.inc"
#include "insns_info.inc"

// conditional compilation macros for MMTk
#include "internal/mmtk_macros.h"

#define FIXNUM_INC(n, i) ((n)+(INT2FIX(i)&~FIXNUM_FLAG))
#define FIXNUM_OR(n, i) ((n)|INT2FIX(i))

Expand Down Expand Up @@ -5420,7 +5423,13 @@ compile_massign_lhs(rb_iseq_t *iseq, LINK_ANCHOR *const pre, LINK_ANCHOR *const
ci = ci_flag_set(iseq, ci, VM_CALL_ARGS_SPLAT_MUT);
}
OPERAND_AT(iobj, 0) = (VALUE)ci;
WHEN_USING_MMTK2({
// iobj is not a heap object, so it is technically incorrect to use it as the
// argument to the write barrier.
rb_gc_writebarrier_remember((VALUE)iseq);
}, {
RB_OBJ_WRITTEN(iseq, Qundef, iobj);
});

/* Given: h[*a], h[*b, 1] = ary
* h[*a] uses splatarray false and does not set VM_CALL_ARGS_SPLAT_MUT,
Expand Down
31 changes: 31 additions & 0 deletions gc/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -6913,6 +6913,21 @@ void
rb_gc_impl_writebarrier(void *objspace_ptr, VALUE a, VALUE b)
{
#if USE_MMTK
// Define the MMTK_WB_ASSERT_VO macro in the compiler command line to enable the assertions.
// Whenever writing an object field using the write barrier, it will assert the source object
// and the new value are valid objects.
#ifdef MMTK_WB_ASSERT_VO
if (rb_mmtk_enabled_p()) {
if (!rb_mmtk_is_valid_objref(a)) {
rb_bug("a is not MMTk object: %p", (void*)a);
}
if (!SPECIAL_CONST_P(b)) {
if (!rb_mmtk_is_valid_objref(b)) {
rb_bug("b is not MMTk object: %p", (void*)b);
}
}
}
#endif
if (rb_mmtk_enabled_p() && rb_mmtk_use_barrier) {
mmtk_object_reference_write_post(GET_THREAD()->mutator, (MMTk_ObjectReference)a);
return;
Expand Down Expand Up @@ -6958,6 +6973,14 @@ void
rb_gc_impl_writebarrier_unprotect(void *objspace_ptr, VALUE obj)
{
#if USE_MMTK
// Define the MMTK_WB_ASSERT_VO macro in the compiler command line to enable the assertions.
#ifdef MMTK_WB_ASSERT_VO
if (rb_mmtk_enabled_p()) {
if (!rb_mmtk_is_valid_objref(obj)) {
rb_bug("Attempted to unprotect invalid objref: %p", (void*)obj);
}
}
#endif
if (rb_mmtk_enabled_p()) {
mmtk_register_wb_unprotected_object((MMTk_ObjectReference)obj);
return;
Expand Down Expand Up @@ -7013,6 +7036,14 @@ void
rb_gc_impl_writebarrier_remember(void *objspace_ptr, VALUE obj)
{
#if USE_MMTK
// Define the MMTK_WB_ASSERT_VO macro in the compiler command line to enable the assertions.
#ifdef MMTK_WB_ASSERT_VO
if (rb_mmtk_enabled_p()) {
if (!rb_mmtk_is_valid_objref(obj)) {
rb_bug("Attempt to remember invalid invalid objref: %p", (void*)obj);
}
}
#endif
if (rb_mmtk_enabled_p() && rb_mmtk_use_barrier) {
mmtk_object_reference_write_post(GET_THREAD()->mutator, (MMTk_ObjectReference)obj);
return;
Expand Down
4 changes: 4 additions & 0 deletions internal/mmtk_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@

#if USE_MMTK
#define IF_USE_MMTK(a) a
#define IF_NOT_USE_MMTK(a)
#define IF_USE_MMTK2(a, b) a
#define WHEN_USING_MMTK(a) if (rb_mmtk_enabled_p()) { a }
#define WHEN_NOT_USING_MMTK(a) if (!rb_mmtk_enabled_p()) { a }
#define WHEN_USING_MMTK2(a, b) if (rb_mmtk_enabled_p()) { a } else { b }
#else
#define IF_USE_MMTK(a)
#define IF_NOT_USE_MMTK(a) a
#define IF_USE_MMTK2(a, b) b
#define WHEN_USING_MMTK(a)
#define WHEN_NOT_USING_MMTK(a) a
#define WHEN_USING_MMTK2(a, b) b
#endif

Expand Down
2 changes: 2 additions & 0 deletions internal/mmtk_support.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ bool rb_mmtk_is_mmtk_worker(void);
bool rb_mmtk_is_mutator(void);
void rb_mmtk_assert_mmtk_worker(void);
void rb_mmtk_assert_mutator(void);
bool rb_mmtk_is_valid_objref(VALUE obj);


// Vanilla GC timing
void rb_mmtk_gc_probe(bool enter);
Expand Down
6 changes: 6 additions & 0 deletions mmtk_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,12 @@ rb_mmtk_panic_if_multiple_ractor(const char *msg)
}
}

bool
rb_mmtk_is_valid_objref(VALUE obj)
{
return obj != 0 && obj % sizeof(VALUE) == 0 && mmtk_is_mmtk_object((MMTk_Address)obj);
}

////////////////////////////////////////////////////////////////////////////////
// Vanilla GC timing
////////////////////////////////////////////////////////////////////////////////
Expand Down
Loading

0 comments on commit 8e171bf

Please sign in to comment.