diff options
author | John Hawthorn <[email protected]> | 2024-11-27 23:32:56 -0800 |
---|---|---|
committer | John Hawthorn <[email protected]> | 2024-11-29 20:37:27 -0800 |
commit | a505cd32fb55aec0423c5b57d17ae31c076b44ab (patch) | |
tree | 04213b8ed8948c3f5efa22670fcc75aa5d0d2948 | |
parent | 660b995365f719fa59ed6f2809bb1527e6470d14 (diff) |
RUBY_DEBUG: Verify PC correctness every alloc
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/12204
-rw-r--r-- | gc.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -969,11 +969,25 @@ rb_gc_obj_slot_size(VALUE obj) return rb_gc_impl_obj_slot_size(obj); } +static inline void +gc_validate_pc(void) { +#if RUBY_DEBUG + rb_execution_context_t *ec = GET_EC(); + const rb_control_frame_t *cfp = ec->cfp; + if (cfp && VM_FRAME_RUBYFRAME_P(cfp) && cfp->pc) { + RUBY_ASSERT(cfp->pc >= ISEQ_BODY(cfp->iseq)->iseq_encoded); + RUBY_ASSERT(cfp->pc <= ISEQ_BODY(cfp->iseq)->iseq_encoded + ISEQ_BODY(cfp->iseq)->iseq_size); + } +#endif +} + static inline VALUE newobj_of(rb_ractor_t *cr, VALUE klass, VALUE flags, VALUE v1, VALUE v2, VALUE v3, bool wb_protected, size_t size) { VALUE obj = rb_gc_impl_new_obj(rb_gc_get_objspace(), cr->newobj_cache, klass, flags, v1, v2, v3, wb_protected, size); + gc_validate_pc(); + if (UNLIKELY(rb_gc_event_hook_required_p(RUBY_INTERNAL_EVENT_NEWOBJ))) { unsigned int lev; RB_VM_LOCK_ENTER_CR_LEV(cr, &lev); |