diff --git a/vm.c b/vm.c index 2899433182..ef1bf0facb 100644 --- a/vm.c +++ b/vm.c @@ -2806,6 +2806,11 @@ rb_execution_context_update(const rb_execution_context_t *ec) cfp->block_code = (void *)rb_gc_location((VALUE)cfp->block_code); if (!VM_ENV_LOCAL_P(ep)) { + const VALUE *prev_ep = VM_ENV_PREV_EP(ep); + if (VM_ENV_FLAGS(prev_ep, VM_ENV_FLAG_ESCAPED)) { + VM_FORCE_WRITE(&prev_ep[VM_ENV_DATA_INDEX_ENV], rb_gc_location(prev_ep[VM_ENV_DATA_INDEX_ENV])); + } + if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED)) { VM_FORCE_WRITE(&ep[VM_ENV_DATA_INDEX_ENV], rb_gc_location(ep[VM_ENV_DATA_INDEX_ENV])); VM_FORCE_WRITE(&ep[VM_ENV_DATA_INDEX_ME_CREF], rb_gc_location(ep[VM_ENV_DATA_INDEX_ME_CREF])); @@ -2846,6 +2851,11 @@ rb_execution_context_mark(const rb_execution_context_t *ec) rb_gc_mark_movable((VALUE)cfp->block_code); if (!VM_ENV_LOCAL_P(ep)) { + const VALUE *prev_ep = VM_ENV_PREV_EP(ep); + if (VM_ENV_FLAGS(prev_ep, VM_ENV_FLAG_ESCAPED)) { + rb_gc_mark_movable(prev_ep[VM_ENV_DATA_INDEX_ENV]); + } + if (VM_ENV_FLAGS(ep, VM_ENV_FLAG_ESCAPED)) { rb_gc_mark_movable(ep[VM_ENV_DATA_INDEX_ENV]); rb_gc_mark(ep[VM_ENV_DATA_INDEX_ME_CREF]);