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
7 changes: 7 additions & 0 deletions gc/mmtk/mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ rb_mmtk_special_const_p(MMTk_ObjectReference object)
return RB_SPECIAL_CONST_P(obj);
}

static void
rb_mmtk_mutator_thread_panic_handler(void)
{
rb_bug("Ruby mutator thread panicked");
}

// Bootup
MMTk_RubyUpcalls ruby_upcalls = {
rb_mmtk_init_gc_worker_thread,
Expand All @@ -374,6 +380,7 @@ MMTk_RubyUpcalls ruby_upcalls = {
rb_mmtk_global_tables_count,
rb_mmtk_update_finalizer_table,
rb_mmtk_special_const_p,
rb_mmtk_mutator_thread_panic_handler,
};

// Use max 80% of the available memory by default for MMTk
Expand Down
1 change: 1 addition & 0 deletions gc/mmtk/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ typedef struct MMTk_RubyUpcalls {
int (*global_tables_count)(void);
void (*update_finalizer_table)(void);
bool (*special_const_p)(MMTk_ObjectReference object);
void (*mutator_thread_panic_handler)(void);
} MMTk_RubyUpcalls;

typedef struct MMTk_RawVecOfObjRef {
Expand Down
1 change: 1 addition & 0 deletions gc/mmtk/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ pub struct RubyUpcalls {
pub global_tables_count: extern "C" fn() -> c_int,
pub update_finalizer_table: extern "C" fn(),
pub special_const_p: extern "C" fn(object: ObjectReference) -> bool,
pub mutator_thread_panic_handler: extern "C" fn(),
}

unsafe impl Sync for RubyUpcalls {}
Expand Down
4 changes: 4 additions & 0 deletions gc/mmtk/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ pub unsafe extern "C" fn mmtk_init_binding(
upcalls: *const RubyUpcalls,
weak_reference_dead_value: ObjectReference,
) {
crate::MUTATOR_THREAD_PANIC_HANDLER
.set((unsafe { (*upcalls).clone() }).mutator_thread_panic_handler)
.unwrap_or_else(|_| panic!("MUTATOR_THREAD_PANIC_HANDLER is already initialized"));

crate::set_panic_hook();

let builder = unsafe { Box::from_raw(builder) };
Expand Down
8 changes: 8 additions & 0 deletions gc/mmtk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ impl VMBinding for Ruby {
type VMMemorySlice = RubyMemorySlice;
}

/// The callback for mutator thread panic handler (which calls rb_bug to output
/// debugging information such as the Ruby backtrace and memory maps).
/// This is set before BINDING is set because mmtk_init could panic.
pub static MUTATOR_THREAD_PANIC_HANDLER: OnceCell<extern "C" fn()> = OnceCell::new();

/// The singleton object for the Ruby binding itself.
pub static BINDING: OnceCell<RubyBinding> = OnceCell::new();

Expand Down Expand Up @@ -132,6 +137,9 @@ pub(crate) fn set_panic_hook() {
handle_gc_thread_panic(panic_info);
} else {
old_hook(panic_info);
(crate::MUTATOR_THREAD_PANIC_HANDLER
.get()
.expect("MUTATOR_THREAD_PANIC_HANDLER is not set"))();
}
}));
}
Expand Down