Implement callcache using declare weak references

This commit is contained in:
Peter Zhu 2025-12-06 19:26:48 -05:00
parent a7ef2a9b0c
commit ade779b1e1
Notes: git 2025-12-25 14:19:00 +00:00
3 changed files with 13 additions and 1 deletions

11
gc.c
View File

@ -1209,6 +1209,17 @@ rb_gc_handle_weak_references(VALUE obj)
rb_bug("rb_gc_handle_weak_references: unknown T_DATA");
}
break;
case T_IMEMO: {
GC_ASSERT(imemo_type(obj) == imemo_callcache);
struct rb_callcache *cc = (struct rb_callcache *)obj;
if (!rb_gc_handle_weak_references_alive_p(cc->klass)) {
vm_cc_invalidate(cc);
}
break;
}
default:
rb_bug("rb_gc_handle_weak_references: type not supported\n");
}

View File

@ -372,7 +372,6 @@ rb_imemo_mark_and_move(VALUE obj, bool reference_updating)
RUBY_ASSERT(RB_TYPE_P(cc->klass, T_CLASS) || RB_TYPE_P(cc->klass, T_ICLASS));
RUBY_ASSERT(IMEMO_TYPE_P((VALUE)cc->cme_, imemo_ment));
rb_gc_mark_weak((VALUE *)&cc->klass);
if ((vm_cc_super_p(cc) || vm_cc_refinement_p(cc))) {
rb_gc_mark_movable((VALUE)cc->cme_);
}

View File

@ -342,6 +342,8 @@ vm_cc_new(VALUE klass,
{
cc_check_class(klass);
struct rb_callcache *cc = SHAREABLE_IMEMO_NEW(struct rb_callcache, imemo_callcache, klass);
rb_gc_declare_weak_references((VALUE)cc);
*((struct rb_callable_method_entry_struct **)&cc->cme_) = (struct rb_callable_method_entry_struct *)cme;
*((vm_call_handler *)&cc->call_) = call;