Ruby 4.0.10p0 (2026-11-19 revision a704b7cd95a42cc0cf5f307137bf3aac0285b915)
vm_callinfo.h
1#ifndef RUBY_VM_CALLINFO_H /*-*-C-*-vi:se ft=c:*/
2#define RUBY_VM_CALLINFO_H
10
11#include "debug_counter.h"
12#include "internal/class.h"
13#include "shape.h"
14
15enum vm_call_flag_bits {
16 VM_CALL_ARGS_SPLAT_bit, // m(*args)
17 VM_CALL_ARGS_BLOCKARG_bit, // m(&block)
18 VM_CALL_FCALL_bit, // m(args) # receiver is self
19 VM_CALL_VCALL_bit, // m # method call that looks like a local variable
20 VM_CALL_ARGS_SIMPLE_bit, // !(ci->flag & (SPLAT|BLOCKARG|KWARG|KW_SPLAT|FORWARDING)) && !has_block_iseq
21 VM_CALL_KWARG_bit, // has kwarg
22 VM_CALL_KW_SPLAT_bit, // m(**opts)
23 VM_CALL_TAILCALL_bit, // located at tail position
24 VM_CALL_SUPER_bit, // super
25 VM_CALL_ZSUPER_bit, // zsuper
26 VM_CALL_OPT_SEND_bit, // internal flag
27 VM_CALL_KW_SPLAT_MUT_bit, // kw splat hash can be modified (to avoid allocating a new one)
28 VM_CALL_ARGS_SPLAT_MUT_bit, // args splat can be modified (to avoid allocating a new one)
29 VM_CALL_FORWARDING_bit, // m(...)
30 VM_CALL_IGNORE_REFINEMENTS_bit, // internal flag: ignore the caller's refinements (initialize call of opt_new)
31 VM_CALL__END
32};
33
34#define VM_CALL_ARGS_SPLAT (0x01 << VM_CALL_ARGS_SPLAT_bit)
35#define VM_CALL_ARGS_BLOCKARG (0x01 << VM_CALL_ARGS_BLOCKARG_bit)
36#define VM_CALL_FCALL (0x01 << VM_CALL_FCALL_bit)
37#define VM_CALL_VCALL (0x01 << VM_CALL_VCALL_bit)
38#define VM_CALL_ARGS_SIMPLE (0x01 << VM_CALL_ARGS_SIMPLE_bit)
39#define VM_CALL_KWARG (0x01 << VM_CALL_KWARG_bit)
40#define VM_CALL_KW_SPLAT (0x01 << VM_CALL_KW_SPLAT_bit)
41#define VM_CALL_TAILCALL (0x01 << VM_CALL_TAILCALL_bit)
42#define VM_CALL_SUPER (0x01 << VM_CALL_SUPER_bit)
43#define VM_CALL_ZSUPER (0x01 << VM_CALL_ZSUPER_bit)
44#define VM_CALL_OPT_SEND (0x01 << VM_CALL_OPT_SEND_bit)
45#define VM_CALL_KW_SPLAT_MUT (0x01 << VM_CALL_KW_SPLAT_MUT_bit)
46#define VM_CALL_ARGS_SPLAT_MUT (0x01 << VM_CALL_ARGS_SPLAT_MUT_bit)
47#define VM_CALL_FORWARDING (0x01 << VM_CALL_FORWARDING_bit)
48#define VM_CALL_IGNORE_REFINEMENTS (0x01 << VM_CALL_IGNORE_REFINEMENTS_bit)
49
51 int keyword_len;
52 rb_atomic_t references;
53 VALUE keywords[];
54};
55
56static inline size_t
57rb_callinfo_kwarg_bytes(int keyword_len)
58{
59 return rb_size_mul_add_or_raise(
60 keyword_len,
61 sizeof(VALUE),
62 sizeof(struct rb_callinfo_kwarg),
64}
65
66static inline void
67rb_callinfo_kwarg_retain(struct rb_callinfo_kwarg *kwarg)
68{
69 if (kwarg) RUBY_ATOMIC_INC(kwarg->references);
70}
71
72static inline void
73rb_callinfo_kwarg_release(struct rb_callinfo_kwarg *kwarg)
74{
75 if (kwarg && RUBY_ATOMIC_FETCH_SUB(kwarg->references, 1) == 1) {
76 ruby_sized_xfree(kwarg, rb_callinfo_kwarg_bytes(kwarg->keyword_len));
77 }
78}
79
80// imemo_callinfo
82 VALUE flags;
83 const struct rb_callinfo_kwarg *kwarg;
84 VALUE mid;
85 VALUE flag;
86 VALUE argc;
87};
88
89#if !defined(USE_EMBED_CI) || (USE_EMBED_CI+0)
90#undef USE_EMBED_CI
91#define USE_EMBED_CI 1
92#else
93#undef USE_EMBED_CI
94#define USE_EMBED_CI 0
95#endif
96
97#if SIZEOF_VALUE == 8
98#define CI_EMBED_TAG_bits 1
99#define CI_EMBED_ARGC_bits 15
100#define CI_EMBED_FLAG_bits 16
101#define CI_EMBED_ID_bits 32
102#elif SIZEOF_VALUE == 4
103#define CI_EMBED_TAG_bits 1
104#define CI_EMBED_ARGC_bits 3
105#define CI_EMBED_FLAG_bits 13
106#define CI_EMBED_ID_bits 15
107#endif
108
109#if (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits + CI_EMBED_FLAG_bits + CI_EMBED_ID_bits) != (SIZEOF_VALUE * 8)
110#error
111#endif
112
113#define CI_EMBED_FLAG 0x01
114#define CI_EMBED_ARGC_SHFT (CI_EMBED_TAG_bits)
115#define CI_EMBED_ARGC_MASK ((((VALUE)1)<<CI_EMBED_ARGC_bits) - 1)
116#define CI_EMBED_FLAG_SHFT (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits)
117#define CI_EMBED_FLAG_MASK ((((VALUE)1)<<CI_EMBED_FLAG_bits) - 1)
118#define CI_EMBED_ID_SHFT (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits + CI_EMBED_FLAG_bits)
119#define CI_EMBED_ID_MASK ((((VALUE)1)<<CI_EMBED_ID_bits) - 1)
120
121static inline bool
122vm_ci_packed_p(const struct rb_callinfo *ci)
123{
124 if (!USE_EMBED_CI) {
125 return 0;
126 }
127 if (LIKELY(((VALUE)ci) & 0x01)) {
128 return 1;
129 }
130 else {
131 VM_ASSERT(IMEMO_TYPE_P(ci, imemo_callinfo));
132 return 0;
133 }
134}
135
136static inline bool
137vm_ci_p(const struct rb_callinfo *ci)
138{
139 if (vm_ci_packed_p(ci) || IMEMO_TYPE_P(ci, imemo_callinfo)) {
140 return 1;
141 }
142 else {
143 return 0;
144 }
145}
146
147static inline ID
148vm_ci_mid(const struct rb_callinfo *ci)
149{
150 if (vm_ci_packed_p(ci)) {
151 return (((VALUE)ci) >> CI_EMBED_ID_SHFT) & CI_EMBED_ID_MASK;
152 }
153 else {
154 return (ID)ci->mid;
155 }
156}
157
158static inline unsigned int
159vm_ci_flag(const struct rb_callinfo *ci)
160{
161 if (vm_ci_packed_p(ci)) {
162 return (unsigned int)((((VALUE)ci) >> CI_EMBED_FLAG_SHFT) & CI_EMBED_FLAG_MASK);
163 }
164 else {
165 return (unsigned int)ci->flag;
166 }
167}
168
169static inline unsigned int
170vm_ci_argc(const struct rb_callinfo *ci)
171{
172 if (vm_ci_packed_p(ci)) {
173 return (unsigned int)((((VALUE)ci) >> CI_EMBED_ARGC_SHFT) & CI_EMBED_ARGC_MASK);
174 }
175 else {
176 return (unsigned int)ci->argc;
177 }
178}
179
180static inline const struct rb_callinfo_kwarg *
181vm_ci_kwarg(const struct rb_callinfo *ci)
182{
183 if (vm_ci_packed_p(ci)) {
184 return NULL;
185 }
186 else {
187 return ci->kwarg;
188 }
189}
190
191static inline void
192vm_ci_dump(const struct rb_callinfo *ci)
193{
194 if (vm_ci_packed_p(ci)) {
195 ruby_debug_printf("packed_ci ID:%s flag:%x argc:%u\n",
196 rb_id2name(vm_ci_mid(ci)), vm_ci_flag(ci), vm_ci_argc(ci));
197 }
198 else {
199 rp(ci);
200 }
201}
202
203#define vm_ci_new(mid, flag, argc, kwarg) vm_ci_new_(mid, flag, argc, kwarg, __FILE__, __LINE__)
204#define vm_ci_new_runtime(mid, flag, argc, kwarg) vm_ci_new_runtime_(mid, flag, argc, kwarg, __FILE__, __LINE__)
205
206/* This is passed to STATIC_ASSERT. Cannot be an inline function. */
207#define VM_CI_EMBEDDABLE_P(mid, flag, argc, kwarg) \
208 (((mid ) & ~CI_EMBED_ID_MASK) ? false : \
209 ((flag) & ~CI_EMBED_FLAG_MASK) ? false : \
210 ((argc) & ~CI_EMBED_ARGC_MASK) ? false : \
211 (kwarg) ? false : true)
212
213#define vm_ci_new_id(mid, flag, argc, must_zero) \
214 ((const struct rb_callinfo *) \
215 ((((VALUE)(mid )) << CI_EMBED_ID_SHFT) | \
216 (((VALUE)(flag)) << CI_EMBED_FLAG_SHFT) | \
217 (((VALUE)(argc)) << CI_EMBED_ARGC_SHFT) | \
218 RUBY_FIXNUM_FLAG))
219
220// vm_method.c
221const struct rb_callinfo *rb_vm_ci_lookup(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg);
222void rb_vm_ci_free(const struct rb_callinfo *);
223
224static inline const struct rb_callinfo *
225vm_ci_new_(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg, const char *file, int line)
226{
227 if (USE_EMBED_CI && VM_CI_EMBEDDABLE_P(mid, flag, argc, kwarg)) {
228 RB_DEBUG_COUNTER_INC(ci_packed);
229 return vm_ci_new_id(mid, flag, argc, kwarg);
230 }
231
232 const bool debug = 0;
233 if (debug) ruby_debug_printf("%s:%d ", file, line);
234
235 const struct rb_callinfo *ci = rb_vm_ci_lookup(mid, flag, argc, kwarg);
236
237 if (debug) rp(ci);
238 if (kwarg) {
239 RB_DEBUG_COUNTER_INC(ci_kw);
240 }
241 else {
242 RB_DEBUG_COUNTER_INC(ci_nokw);
243 }
244
245 VM_ASSERT(vm_ci_flag(ci) == flag);
246 VM_ASSERT(vm_ci_argc(ci) == argc);
247
248 return ci;
249}
250
251
252static inline const struct rb_callinfo *
253vm_ci_new_runtime_(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg, const char *file, int line)
254{
255 RB_DEBUG_COUNTER_INC(ci_runtime);
256 return vm_ci_new_(mid, flag, argc, kwarg, file, line);
257}
258
259#define VM_CALLINFO_NOT_UNDER_GC IMEMO_FL_USER0
260
261static inline bool
262vm_ci_markable(const struct rb_callinfo *ci)
263{
264 if (! ci) {
265 return false; /* or true? This is Qfalse... */
266 }
267 else if (vm_ci_packed_p(ci)) {
268 return true;
269 }
270 else {
271 VM_ASSERT(IMEMO_TYPE_P(ci, imemo_callinfo));
272 return ! FL_ANY_RAW((VALUE)ci, VM_CALLINFO_NOT_UNDER_GC);
273 }
274}
275
276#define VM_CI_ON_STACK(mid_, flags_, argc_, kwarg_) \
277 (struct rb_callinfo) { \
278 .flags = T_IMEMO | \
279 (imemo_callinfo << FL_USHIFT) | \
280 VM_CALLINFO_NOT_UNDER_GC, \
281 .mid = mid_, \
282 .flag = flags_, \
283 .argc = argc_, \
284 .kwarg = kwarg_, \
285 }
286
287typedef VALUE (*vm_call_handler)(
289 struct rb_control_frame_struct *cfp,
290 struct rb_calling_info *calling);
291
292// imemo_callcache
293
295 const VALUE flags;
296
297 /* inline cache: key */
298 const VALUE klass; // Weak reference. When klass is collected, `cc->klass = Qundef`.
299
300 /* inline cache: values */
301 const struct rb_callable_method_entry_struct * const cme_;
302 const vm_call_handler call_;
303
304 union {
305 struct {
306 uint64_t value; // Shape ID in former half, index in latter half
307 } attr;
308 const enum method_missing_reason method_missing_reason; /* used by method_missing */
309 VALUE v;
310 const struct rb_builtin_function *bf;
311 } aux_;
312};
313
314/* VM_CALLCACHE_IVAR used for IVAR/ATTRSET/STRUCT_AREF/STRUCT_ASET methods */
315#define VM_CALLCACHE_IVAR IMEMO_FL_USER0
316#define VM_CALLCACHE_BF IMEMO_FL_USER1
317#define VM_CALLCACHE_SUPER IMEMO_FL_USER2
318#define VM_CALLCACHE_REFINEMENT IMEMO_FL_USER3
319#define VM_CALLCACHE_UNMARKABLE IMEMO_FL_USER4
320#define VM_CALLCACHE_ON_STACK IMEMO_FL_USER5
321#define VM_CALLCACHE_INVALID_SUPER IMEMO_FL_USER6
322
323enum vm_cc_type {
324 cc_type_normal, // chained from ccs
325 cc_type_super,
326 cc_type_refinement,
327};
328
329extern const struct rb_callcache *rb_vm_empty_cc(void);
330extern const struct rb_callcache *rb_vm_empty_cc_for_super(void);
331
332#define vm_cc_empty() rb_vm_empty_cc()
333
334static inline void vm_cc_attr_index_set(const struct rb_callcache *cc, attr_index_t index, shape_id_t dest_shape_id);
335
336static inline void
337vm_cc_attr_index_initialize(const struct rb_callcache *cc, shape_id_t shape_id)
338{
339 vm_cc_attr_index_set(cc, (attr_index_t)-1, shape_id);
340}
341
342static inline VALUE
343cc_check_class(VALUE klass)
344{
345 VM_ASSERT(klass == Qundef || RB_TYPE_P(klass, T_CLASS) || RB_TYPE_P(klass, T_ICLASS));
346 return klass;
347}
348
349VALUE rb_vm_cc_table_create(size_t capa);
350VALUE rb_vm_cc_table_dup(VALUE old_table);
351void rb_vm_cc_table_delete(VALUE table, ID mid);
352
353static inline const struct rb_callcache *
354vm_cc_new(VALUE klass,
355 const struct rb_callable_method_entry_struct *cme,
356 vm_call_handler call,
357 enum vm_cc_type type)
358{
359 cc_check_class(klass);
360 struct rb_callcache *cc = SHAREABLE_IMEMO_NEW(struct rb_callcache, imemo_callcache, klass);
361 *((struct rb_callable_method_entry_struct **)&cc->cme_) = (struct rb_callable_method_entry_struct *)cme;
362 *((vm_call_handler *)&cc->call_) = call;
363
364 switch (type) {
365 case cc_type_normal:
366 break;
367 case cc_type_super:
368 *(VALUE *)&cc->flags |= VM_CALLCACHE_SUPER;
369 break;
370 case cc_type_refinement:
371 *(VALUE *)&cc->flags |= VM_CALLCACHE_REFINEMENT;
372 rb_vm_insert_cc_refinement(cc);
373 break;
374 }
375
376 if (cme) {
377 if (cme->def->type == VM_METHOD_TYPE_ATTRSET || cme->def->type == VM_METHOD_TYPE_IVAR) {
378 vm_cc_attr_index_initialize(cc, INVALID_SHAPE_ID);
379 }
380 }
381 else {
382 *(VALUE *)&cc->flags |= VM_CALLCACHE_INVALID_SUPER;
383 }
384
385 RB_DEBUG_COUNTER_INC(cc_new);
386 return cc;
387}
388
389static inline bool
390vm_cc_super_p(const struct rb_callcache *cc)
391{
392 return (cc->flags & VM_CALLCACHE_SUPER) != 0;
393}
394
395static inline bool
396vm_cc_refinement_p(const struct rb_callcache *cc)
397{
398 return (cc->flags & VM_CALLCACHE_REFINEMENT) != 0;
399}
400
401#define VM_CC_ON_STACK(clazz, call, aux, cme) \
402 (struct rb_callcache) { \
403 .flags = T_IMEMO | \
404 (imemo_callcache << FL_USHIFT) | \
405 VM_CALLCACHE_UNMARKABLE | \
406 VM_CALLCACHE_ON_STACK, \
407 .klass = cc_check_class(clazz), \
408 .cme_ = cme, \
409 .call_ = call, \
410 .aux_ = aux, \
411 }
412
413static inline bool
414vm_cc_class_check(const struct rb_callcache *cc, VALUE klass)
415{
416 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
417 VM_ASSERT(cc_check_class(cc->klass));
418 return cc->klass == klass;
419}
420
421static inline int
422vm_cc_markable(const struct rb_callcache *cc)
423{
424 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
425 return FL_TEST_RAW((VALUE)cc, VM_CALLCACHE_UNMARKABLE) == 0;
426}
427
428static inline bool
429vm_cc_invalid_super(const struct rb_callcache *cc)
430{
431 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
432 // Set when calling super and there is no superclass.
433 return FL_TEST_RAW((VALUE)cc, VM_CALLCACHE_INVALID_SUPER);
434}
435
436static inline bool
437vm_cc_valid(const struct rb_callcache *cc)
438{
439 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
440 VM_ASSERT(cc_check_class(cc->klass));
441
442 return !UNDEF_P(cc->klass);
443}
444
445static inline const struct rb_callable_method_entry_struct *
446vm_cc_cme(const struct rb_callcache *cc)
447{
448 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
449 VM_ASSERT(cc->klass != Qundef || !vm_cc_markable(cc) || vm_cc_invalid_super(cc));
450 VM_ASSERT(cc_check_class(cc->klass));
451 VM_ASSERT(cc->call_ == NULL || // not initialized yet
452 !vm_cc_markable(cc) ||
453 vm_cc_invalid_super(cc) ||
454 cc->cme_ != NULL);
455
456 return cc->cme_;
457}
458
459static inline vm_call_handler
460vm_cc_call(const struct rb_callcache *cc)
461{
462 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
463 VM_ASSERT(cc->call_ != NULL);
464 VM_ASSERT(cc->klass != Qundef || !vm_cc_markable(cc) || vm_cc_invalid_super(cc));
465 VM_ASSERT(cc_check_class(cc->klass));
466 return cc->call_;
467}
468
469static inline void
470vm_unpack_shape_and_index(const uint64_t cache_value, shape_id_t *shape_id, attr_index_t *index)
471{
472 union rb_attr_index_cache cache = {
473 .pack = cache_value,
474 };
475 *shape_id = cache.unpack.shape_id;
476 *index = cache.unpack.index - 1;
477}
478
479static inline void
480vm_cc_atomic_shape_and_index(const struct rb_callcache *cc, shape_id_t *shape_id, attr_index_t *index)
481{
482 vm_unpack_shape_and_index(ATOMIC_U64_LOAD_RELAXED(cc->aux_.attr.value), shape_id, index);
483}
484
485static inline void
486vm_ic_atomic_shape_and_index(const struct iseq_inline_iv_cache_entry *ic, shape_id_t *shape_id, attr_index_t *index)
487{
488 vm_unpack_shape_and_index(ATOMIC_U64_LOAD_RELAXED(ic->value), shape_id, index);
489}
490
491static inline unsigned int
492vm_cc_cmethod_missing_reason(const struct rb_callcache *cc)
493{
494 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
495 return cc->aux_.method_missing_reason;
496}
497
498static inline bool
499vm_cc_invalidated_p(const struct rb_callcache *cc)
500{
501 if (vm_cc_valid(cc) && !METHOD_ENTRY_INVALIDATED(vm_cc_cme(cc))) {
502 return false;
503 }
504 else {
505 return true;
506 }
507}
508
509/* callcache: mutate */
510
511static inline void
512vm_cc_call_set(const struct rb_callcache *cc, vm_call_handler call)
513{
514 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
515 VM_ASSERT(cc != vm_cc_empty());
516 *(vm_call_handler *)&cc->call_ = call;
517}
518
519static inline void
520set_vm_cc_ivar(const struct rb_callcache *cc)
521{
522 *(VALUE *)&cc->flags |= VM_CALLCACHE_IVAR;
523}
524
525static inline uint64_t
526vm_pack_shape_and_index(shape_id_t shape_id, attr_index_t index)
527{
528 union rb_attr_index_cache cache = {
529 .unpack = {
530 .shape_id = shape_id,
531 .index = index + 1,
532 }
533 };
534 return cache.pack;
535}
536
537static inline void
538vm_cc_attr_index_set(const struct rb_callcache *cc, attr_index_t index, shape_id_t dest_shape_id)
539{
540 uint64_t *attr_value = (uint64_t *)&cc->aux_.attr.value;
541 if (!vm_cc_markable(cc)) {
542 *attr_value = vm_pack_shape_and_index(INVALID_SHAPE_ID, ATTR_INDEX_NOT_SET);
543 return;
544 }
545 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
546 VM_ASSERT(cc != vm_cc_empty());
547 *attr_value = vm_pack_shape_and_index(dest_shape_id, index);
548 set_vm_cc_ivar(cc);
549}
550
551static inline bool
552vm_cc_ivar_p(const struct rb_callcache *cc)
553{
554 return (cc->flags & VM_CALLCACHE_IVAR) != 0;
555}
556
557static inline void
558vm_ic_attr_index_set(const rb_iseq_t *iseq, struct iseq_inline_iv_cache_entry *ic, attr_index_t index, shape_id_t dest_shape_id)
559{
560 ATOMIC_U64_SET_RELAXED(ic->value, vm_pack_shape_and_index(dest_shape_id, index));
561}
562
563static inline void
564vm_ic_attr_index_initialize(struct iseq_inline_iv_cache_entry *ic, shape_id_t shape_id)
565{
566 ATOMIC_U64_SET_RELAXED(ic->value, vm_pack_shape_and_index(shape_id, ATTR_INDEX_NOT_SET));
567}
568
569static inline void
570vm_cc_method_missing_reason_set(const struct rb_callcache *cc, enum method_missing_reason reason)
571{
572 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
573 VM_ASSERT(cc != vm_cc_empty());
574 *(enum method_missing_reason *)&cc->aux_.method_missing_reason = reason;
575}
576
577static inline void
578vm_cc_bf_set(const struct rb_callcache *cc, const struct rb_builtin_function *bf)
579{
580 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
581 VM_ASSERT(cc != vm_cc_empty());
582 *(const struct rb_builtin_function **)&cc->aux_.bf = bf;
583 *(VALUE *)&cc->flags |= VM_CALLCACHE_BF;
584}
585
586static inline bool
587vm_cc_bf_p(const struct rb_callcache *cc)
588{
589 return (cc->flags & VM_CALLCACHE_BF) != 0;
590}
591
592static inline void
593vm_cc_invalidate(const struct rb_callcache *cc)
594{
595 VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
596 VM_ASSERT(cc != vm_cc_empty());
597 // TODO: rb_multi_ractor_p() is a workaround to stabilize CI
598 VM_ASSERT(cc->klass != Qundef || rb_multi_ractor_p()); // should be enable
599
600 *(VALUE *)&cc->klass = Qundef;
601 RB_DEBUG_COUNTER_INC(cc_ent_invalidate);
602}
603
604/* calldata */
605
607 const struct rb_callinfo *ci;
608 const struct rb_callcache *cc;
609};
610
612#if VM_CHECK_MODE > 0
613 VALUE debug_sig;
614#endif
615 int capa;
616 int len;
617 const struct rb_callable_method_entry_struct *cme;
619 const struct rb_callcache *cc;
620 unsigned int argc;
621 unsigned short flag;
622 unsigned short kw_len;
623 } entries[FLEX_ARY_LEN];
624};
625
626/* entries[].flag is an unsigned short, so every VM_CALL flag bit must fit in 16 bits. */
627STATIC_ASSERT(cc_entries_flag_fits_in_short, VM_CALL__END <= 16);
628
629/* entries[].kw_len is an unsigned short, so a call site cannot carry, nor a method
630 declare, more keyword arguments than this. Enforced at compile time. */
631#define VM_CALL_KW_LEN_MAX UINT16_MAX
632
633static inline size_t
634vm_ccs_alloc_size(size_t capa)
635{
636 return offsetof(struct rb_class_cc_entries, entries) + (sizeof(struct rb_class_cc_entries_entry) * capa);
637}
638
639#if VM_CHECK_MODE > 0
640
641const rb_callable_method_entry_t *rb_vm_lookup_overloaded_cme(const rb_callable_method_entry_t *cme);
642void rb_vm_dump_overloaded_cme_table(void);
643
644static inline bool
645vm_ccs_p(const struct rb_class_cc_entries *ccs)
646{
647 return ccs->debug_sig == ~(VALUE)ccs;
648}
649
650static inline bool
651vm_cc_check_cme(const struct rb_callcache *cc, const rb_callable_method_entry_t *cme)
652{
653 bool valid;
654 RB_VM_LOCKING_NO_BARRIER() {
655 valid = vm_cc_cme(cc) == cme ||
656 (cme->def->iseq_overload && vm_cc_cme(cc) == rb_vm_lookup_overloaded_cme(cme));
657 }
658 if (valid) {
659 return true;
660 }
661#if 1
662 // debug print
663
664 fprintf(stderr, "iseq_overload:%d, cme:%p (def:%p), cm_cc_cme(cc):%p (def:%p)\n",
665 (int)cme->def->iseq_overload,
666 cme, cme->def,
667 vm_cc_cme(cc), vm_cc_cme(cc)->def);
668 rp(cme);
669 rp(vm_cc_cme(cc));
670 rp(rb_vm_lookup_overloaded_cme(cme));
671#endif
672 return false;
673}
674
675#endif
676
677#endif /* RUBY_VM_CALLINFO_H */
#define RUBY_ATOMIC_INC(var)
Atomically increments the value pointed by var.
Definition atomic.h:214
std::atomic< unsigned > rb_atomic_t
Type that is eligible for atomic operations.
Definition atomic.h:69
#define RUBY_ATOMIC_FETCH_SUB(var, val)
Atomically replaces the value pointed by var with the result of subtraction of val to the old value o...
Definition atomic.h:129
#define Qundef
Old name of RUBY_Qundef.
#define T_ICLASS
Old name of RUBY_T_ICLASS.
Definition value_type.h:66
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:131
#define FL_ANY_RAW
Old name of RB_FL_ANY_RAW.
Definition fl_type.h:125
#define T_CLASS
Old name of RUBY_T_CLASS.
Definition value_type.h:58
VALUE rb_eRuntimeError
RuntimeError exception.
Definition error.c:1429
int capa
Designed capacity of the buffer.
Definition io.h:11
VALUE type(ANYARGS)
ANYARGS-ed function type.
Definition vm_core.h:288
Definition method.h:63
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40