Skip to content

Commit 74887a2

Browse files
peterzhu2118matzbot
authored andcommitted
[ruby/mmtk] Skip weak references that are special consts
If a reference marked weak becomes a special const, it will crash because it is not a GC handled object. We should skip special consts here. ruby/mmtk@870a79426b
1 parent 66bcb69 commit 74887a2

File tree

4 files changed

+15
-0
lines changed

4 files changed

+15
-0
lines changed

gc/mmtk/mmtk.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,14 @@ rb_mmtk_update_global_tables(int table)
342342
rb_gc_vm_weak_table_foreach(rb_mmtk_update_table_i, NULL, NULL, true, (enum rb_gc_vm_weak_tables)table);
343343
}
344344

345+
static bool
346+
rb_mmtk_special_const_p(MMTk_ObjectReference object)
347+
{
348+
VALUE obj = (VALUE)object;
349+
350+
return RB_SPECIAL_CONST_P(obj);
351+
}
352+
345353
// Bootup
346354
MMTk_RubyUpcalls ruby_upcalls = {
347355
rb_mmtk_init_gc_worker_thread,
@@ -360,6 +368,7 @@ MMTk_RubyUpcalls ruby_upcalls = {
360368
rb_mmtk_update_global_tables,
361369
rb_mmtk_global_tables_count,
362370
rb_mmtk_update_finalizer_table,
371+
rb_mmtk_special_const_p,
363372
};
364373

365374
// Use max 80% of the available memory by default for MMTk

gc/mmtk/mmtk.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ typedef struct MMTk_RubyUpcalls {
6868
void (*update_global_tables)(int tbl_idx);
6969
int (*global_tables_count)(void);
7070
void (*update_finalizer_table)(void);
71+
bool (*special_const_p)(MMTk_ObjectReference object);
7172
} MMTk_RubyUpcalls;
7273

7374
typedef struct MMTk_RawVecOfObjRef {

gc/mmtk/src/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ pub struct RubyUpcalls {
313313
pub update_global_tables: extern "C" fn(tbl_idx: c_int),
314314
pub global_tables_count: extern "C" fn() -> c_int,
315315
pub update_finalizer_table: extern "C" fn(),
316+
pub special_const_p: extern "C" fn(object: ObjectReference) -> bool,
316317
}
317318

318319
unsafe impl Sync for RubyUpcalls {}

gc/mmtk/src/weak_proc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ impl GCWork<Ruby> for ProcessWeakReferences {
134134
.expect("Mutators should not be holding the lock.");
135135

136136
for ptr_ptr in weak_references.iter_mut() {
137+
if (upcalls().special_const_p)(**ptr_ptr) {
138+
continue;
139+
}
140+
137141
if !(**ptr_ptr).is_reachable() {
138142
**ptr_ptr = crate::binding().weak_reference_dead_value;
139143
}

0 commit comments

Comments
 (0)