Skip to content

Commit

Permalink
Pin dynamic symbol in rb_sym2id
Browse files Browse the repository at this point in the history
A dynamic symbol with an associated ID is implicitly pinned in Ruby.  We
also pin it with MMTk's API when using MMTk.
  • Loading branch information
wks committed Nov 24, 2023
1 parent 338511d commit d21a30a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
6 changes: 6 additions & 0 deletions internal/mmtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,4 +197,10 @@ void mmtk_gc_poll(MMTk_VMMutatorThread tls);

size_t mmtk_get_immix_bump_ptr_offset(void);

bool mmtk_pin_object(MMTk_ObjectReference object);

bool mmtk_unpin_object(MMTk_ObjectReference object);

bool mmtk_is_pinned(MMTk_ObjectReference object);

#endif /* MMTK_H */
14 changes: 14 additions & 0 deletions symbol.c
Original file line number Diff line number Diff line change
Expand Up @@ -910,11 +910,25 @@ rb_sym2id(VALUE sym)
RSYMBOL(sym)->id = id |= num;
/* make it permanent object */

#if USE_MMTK
if (rb_mmtk_enabled_p()) {
// Symbols with associated ID are implicitly pinned (see gc_is_moveable_obj).
// When using MMTk, we need to inform MMTk not to move the object.
mmtk_pin_object((MMTk_ObjectReference)sym);
}
#endif

set_id_entry(symbols, rb_id_to_serial(num), fstr, sym);
rb_hash_delete_entry(symbols->dsymbol_fstr_hash, fstr);
}
}
GLOBAL_SYMBOLS_LEAVE();
#if USE_MMTK && RUBY_DEBUG
if (rb_mmtk_enabled_p()) {
// Assert that all dynamic symbols returned from this function are pinned.
RUBY_ASSERT(mmtk_is_pinned((MMTk_ObjectReference)sym));
}
#endif
}
else {
rb_raise(rb_eTypeError, "wrong argument type %s (expected Symbol)",
Expand Down

0 comments on commit d21a30a

Please sign in to comment.