debase-ruby_core_source 3.2.0 → 3.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +5 -0
  4. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/addr2line.h +20 -0
  5. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/builtin.h +117 -0
  6. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ccan/build_assert/build_assert.h +40 -0
  7. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ccan/check_type/check_type.h +63 -0
  8. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ccan/container_of/container_of.h +142 -0
  9. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ccan/list/list.h +789 -0
  10. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ccan/str/str.h +17 -0
  11. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/constant.h +53 -0
  12. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/darray.h +179 -0
  13. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/debug_counter.h +426 -0
  14. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/dln.h +31 -0
  15. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/encindex.h +70 -0
  16. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/eval_intern.h +339 -0
  17. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/hrtime.h +227 -0
  18. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/id.h +299 -0
  19. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/id_table.h +39 -0
  20. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/insns.inc +249 -0
  21. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/insns_info.inc +9159 -0
  22. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/array.h +162 -0
  23. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/basic_operators.h +63 -0
  24. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/bignum.h +244 -0
  25. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/bits.h +564 -0
  26. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/class.h +221 -0
  27. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/cmdlineopt.h +61 -0
  28. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/compar.h +29 -0
  29. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/compile.h +35 -0
  30. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/compilers.h +107 -0
  31. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/complex.h +29 -0
  32. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/cont.h +32 -0
  33. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/dir.h +16 -0
  34. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/enc.h +19 -0
  35. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/encoding.h +32 -0
  36. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/enum.h +18 -0
  37. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/enumerator.h +21 -0
  38. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/error.h +191 -0
  39. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/eval.h +32 -0
  40. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/file.h +38 -0
  41. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/fixnum.h +184 -0
  42. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/gc.h +333 -0
  43. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/hash.h +216 -0
  44. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/imemo.h +241 -0
  45. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/inits.h +50 -0
  46. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/io.h +38 -0
  47. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/load.h +18 -0
  48. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/loadpath.h +16 -0
  49. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/math.h +23 -0
  50. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/missing.h +18 -0
  51. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/numeric.h +273 -0
  52. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/object.h +59 -0
  53. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/parse.h +25 -0
  54. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/proc.h +30 -0
  55. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/process.h +138 -0
  56. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/ractor.h +6 -0
  57. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/random.h +16 -0
  58. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/range.h +40 -0
  59. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/rational.h +71 -0
  60. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/re.h +28 -0
  61. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/sanitizers.h +186 -0
  62. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/serial.h +23 -0
  63. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/signal.h +21 -0
  64. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/static_assert.h +16 -0
  65. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/string.h +145 -0
  66. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/struct.h +152 -0
  67. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/symbol.h +42 -0
  68. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/thread.h +61 -0
  69. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/time.h +34 -0
  70. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/transcode.h +20 -0
  71. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/util.h +27 -0
  72. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/variable.h +88 -0
  73. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/vm.h +124 -0
  74. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal/warnings.h +16 -0
  75. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/internal.h +112 -0
  76. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/iseq.h +334 -0
  77. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/known_errors.inc +791 -0
  78. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/method.h +254 -0
  79. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/node.h +514 -0
  80. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/node_name.inc +210 -0
  81. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/opt_sc.inc +109 -0
  82. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/optinsn.inc +128 -0
  83. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/optunifs.inc +43 -0
  84. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/parse.h +230 -0
  85. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/probes_helper.h +42 -0
  86. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ractor_core.h +387 -0
  87. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/regenc.h +254 -0
  88. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/regint.h +996 -0
  89. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/regparse.h +370 -0
  90. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/revision.h +5 -0
  91. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/rjit.h +103 -0
  92. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/rjit_c.h +165 -0
  93. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ruby_assert.h +14 -0
  94. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/ruby_atomic.h +23 -0
  95. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/shape.h +232 -0
  96. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/siphash.h +48 -0
  97. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/symbol.h +119 -0
  98. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/thread_none.h +20 -0
  99. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/thread_pthread.h +128 -0
  100. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/thread_win32.h +63 -0
  101. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/timev.h +58 -0
  102. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/transcode_data.h +138 -0
  103. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/transient_heap.h +65 -0
  104. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/variable.h +30 -0
  105. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/version.h +65 -0
  106. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm.inc +5497 -0
  107. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_call_iseq_optimized.inc +244 -0
  108. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_callinfo.h +574 -0
  109. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_core.h +2107 -0
  110. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_debug.h +122 -0
  111. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_exec.h +198 -0
  112. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_insnhelper.h +274 -0
  113. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_opts.h +72 -0
  114. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vm_sync.h +137 -0
  115. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/vmtc.inc +243 -0
  116. data/lib/debase/ruby_core_source/ruby-3.3.0-preview1/yjit.h +72 -0
  117. data/lib/debase/ruby_core_source/version.rb +1 -1
  118. metadata +116 -3
@@ -0,0 +1,574 @@
1
+ #ifndef RUBY_VM_CALLINFO_H /*-*-C-*-vi:se ft=c:*/
2
+ #define RUBY_VM_CALLINFO_H
3
+ /**
4
+ * @author Ruby developers <ruby-core@ruby-lang.org>
5
+ * @copyright This file is a part of the programming language Ruby.
6
+ * Permission is hereby granted, to either redistribute and/or
7
+ * modify this file, provided that the conditions mentioned in the
8
+ * file COPYING are met. Consult the file for details.
9
+ */
10
+
11
+ #include "debug_counter.h"
12
+ #include "internal/class.h"
13
+ #include "shape.h"
14
+
15
+ enum 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)) && blockiseq == NULL && ci->kw_arg == NULL
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__END
29
+ };
30
+
31
+ #define VM_CALL_ARGS_SPLAT (0x01 << VM_CALL_ARGS_SPLAT_bit)
32
+ #define VM_CALL_ARGS_BLOCKARG (0x01 << VM_CALL_ARGS_BLOCKARG_bit)
33
+ #define VM_CALL_FCALL (0x01 << VM_CALL_FCALL_bit)
34
+ #define VM_CALL_VCALL (0x01 << VM_CALL_VCALL_bit)
35
+ #define VM_CALL_ARGS_SIMPLE (0x01 << VM_CALL_ARGS_SIMPLE_bit)
36
+ #define VM_CALL_KWARG (0x01 << VM_CALL_KWARG_bit)
37
+ #define VM_CALL_KW_SPLAT (0x01 << VM_CALL_KW_SPLAT_bit)
38
+ #define VM_CALL_TAILCALL (0x01 << VM_CALL_TAILCALL_bit)
39
+ #define VM_CALL_SUPER (0x01 << VM_CALL_SUPER_bit)
40
+ #define VM_CALL_ZSUPER (0x01 << VM_CALL_ZSUPER_bit)
41
+ #define VM_CALL_OPT_SEND (0x01 << VM_CALL_OPT_SEND_bit)
42
+ #define VM_CALL_KW_SPLAT_MUT (0x01 << VM_CALL_KW_SPLAT_MUT_bit)
43
+
44
+ struct rb_callinfo_kwarg {
45
+ int keyword_len;
46
+ VALUE keywords[];
47
+ };
48
+
49
+ static inline size_t
50
+ rb_callinfo_kwarg_bytes(int keyword_len)
51
+ {
52
+ return rb_size_mul_add_or_raise(
53
+ keyword_len,
54
+ sizeof(VALUE),
55
+ sizeof(struct rb_callinfo_kwarg),
56
+ rb_eRuntimeError);
57
+ }
58
+
59
+ // imemo_callinfo
60
+ struct rb_callinfo {
61
+ VALUE flags;
62
+ const struct rb_callinfo_kwarg *kwarg;
63
+ VALUE mid;
64
+ VALUE flag;
65
+ VALUE argc;
66
+ };
67
+
68
+ #ifndef USE_EMBED_CI
69
+ #define USE_EMBED_CI 1
70
+ #endif
71
+
72
+ #if SIZEOF_VALUE == 8
73
+ #define CI_EMBED_TAG_bits 1
74
+ #define CI_EMBED_ARGC_bits 15
75
+ #define CI_EMBED_FLAG_bits 16
76
+ #define CI_EMBED_ID_bits 32
77
+ #elif SIZEOF_VALUE == 4
78
+ #define CI_EMBED_TAG_bits 1
79
+ #define CI_EMBED_ARGC_bits 3
80
+ #define CI_EMBED_FLAG_bits 13
81
+ #define CI_EMBED_ID_bits 15
82
+ #endif
83
+
84
+ #if (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits + CI_EMBED_FLAG_bits + CI_EMBED_ID_bits) != (SIZEOF_VALUE * 8)
85
+ #error
86
+ #endif
87
+
88
+ #define CI_EMBED_FLAG 0x01
89
+ #define CI_EMBED_ARGC_SHFT (CI_EMBED_TAG_bits)
90
+ #define CI_EMBED_ARGC_MASK ((((VALUE)1)<<CI_EMBED_ARGC_bits) - 1)
91
+ #define CI_EMBED_FLAG_SHFT (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits)
92
+ #define CI_EMBED_FLAG_MASK ((((VALUE)1)<<CI_EMBED_FLAG_bits) - 1)
93
+ #define CI_EMBED_ID_SHFT (CI_EMBED_TAG_bits + CI_EMBED_ARGC_bits + CI_EMBED_FLAG_bits)
94
+ #define CI_EMBED_ID_MASK ((((VALUE)1)<<CI_EMBED_ID_bits) - 1)
95
+
96
+ static inline bool
97
+ vm_ci_packed_p(const struct rb_callinfo *ci)
98
+ {
99
+ #if USE_EMBED_CI
100
+ if (LIKELY(((VALUE)ci) & 0x01)) {
101
+ return 1;
102
+ }
103
+ else {
104
+ VM_ASSERT(IMEMO_TYPE_P(ci, imemo_callinfo));
105
+ return 0;
106
+ }
107
+ #else
108
+ return 0;
109
+ #endif
110
+ }
111
+
112
+ static inline bool
113
+ vm_ci_p(const struct rb_callinfo *ci)
114
+ {
115
+ if (vm_ci_packed_p(ci) || IMEMO_TYPE_P(ci, imemo_callinfo)) {
116
+ return 1;
117
+ }
118
+ else {
119
+ return 0;
120
+ }
121
+ }
122
+
123
+ static inline ID
124
+ vm_ci_mid(const struct rb_callinfo *ci)
125
+ {
126
+ if (vm_ci_packed_p(ci)) {
127
+ return (((VALUE)ci) >> CI_EMBED_ID_SHFT) & CI_EMBED_ID_MASK;
128
+ }
129
+ else {
130
+ return (ID)ci->mid;
131
+ }
132
+ }
133
+
134
+ static inline unsigned int
135
+ vm_ci_flag(const struct rb_callinfo *ci)
136
+ {
137
+ if (vm_ci_packed_p(ci)) {
138
+ return (unsigned int)((((VALUE)ci) >> CI_EMBED_FLAG_SHFT) & CI_EMBED_FLAG_MASK);
139
+ }
140
+ else {
141
+ return (unsigned int)ci->flag;
142
+ }
143
+ }
144
+
145
+ static inline unsigned int
146
+ vm_ci_argc(const struct rb_callinfo *ci)
147
+ {
148
+ if (vm_ci_packed_p(ci)) {
149
+ return (unsigned int)((((VALUE)ci) >> CI_EMBED_ARGC_SHFT) & CI_EMBED_ARGC_MASK);
150
+ }
151
+ else {
152
+ return (unsigned int)ci->argc;
153
+ }
154
+ }
155
+
156
+ static inline const struct rb_callinfo_kwarg *
157
+ vm_ci_kwarg(const struct rb_callinfo *ci)
158
+ {
159
+ if (vm_ci_packed_p(ci)) {
160
+ return NULL;
161
+ }
162
+ else {
163
+ return ci->kwarg;
164
+ }
165
+ }
166
+
167
+ static inline void
168
+ vm_ci_dump(const struct rb_callinfo *ci)
169
+ {
170
+ if (vm_ci_packed_p(ci)) {
171
+ ruby_debug_printf("packed_ci ID:%s flag:%x argc:%u\n",
172
+ rb_id2name(vm_ci_mid(ci)), vm_ci_flag(ci), vm_ci_argc(ci));
173
+ }
174
+ else {
175
+ rp(ci);
176
+ }
177
+ }
178
+
179
+ #define vm_ci_new(mid, flag, argc, kwarg) vm_ci_new_(mid, flag, argc, kwarg, __FILE__, __LINE__)
180
+ #define vm_ci_new_runtime(mid, flag, argc, kwarg) vm_ci_new_runtime_(mid, flag, argc, kwarg, __FILE__, __LINE__)
181
+
182
+ /* This is passed to STATIC_ASSERT. Cannot be an inline function. */
183
+ #define VM_CI_EMBEDDABLE_P(mid, flag, argc, kwarg) \
184
+ (((mid ) & ~CI_EMBED_ID_MASK) ? false : \
185
+ ((flag) & ~CI_EMBED_FLAG_MASK) ? false : \
186
+ ((argc) & ~CI_EMBED_ARGC_MASK) ? false : \
187
+ (kwarg) ? false : true)
188
+
189
+ #define vm_ci_new_id(mid, flag, argc, must_zero) \
190
+ ((const struct rb_callinfo *) \
191
+ ((((VALUE)(mid )) << CI_EMBED_ID_SHFT) | \
192
+ (((VALUE)(flag)) << CI_EMBED_FLAG_SHFT) | \
193
+ (((VALUE)(argc)) << CI_EMBED_ARGC_SHFT) | \
194
+ RUBY_FIXNUM_FLAG))
195
+
196
+ static inline const struct rb_callinfo *
197
+ vm_ci_new_(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg, const char *file, int line)
198
+ {
199
+ #if USE_EMBED_CI
200
+ if (VM_CI_EMBEDDABLE_P(mid, flag, argc, kwarg)) {
201
+ RB_DEBUG_COUNTER_INC(ci_packed);
202
+ return vm_ci_new_id(mid, flag, argc, kwarg);
203
+ }
204
+ #endif
205
+
206
+ const bool debug = 0;
207
+ if (debug) ruby_debug_printf("%s:%d ", file, line);
208
+
209
+ // TODO: dedup
210
+ const struct rb_callinfo *ci = (const struct rb_callinfo *)
211
+ rb_imemo_new(imemo_callinfo,
212
+ (VALUE)mid,
213
+ (VALUE)flag,
214
+ (VALUE)argc,
215
+ (VALUE)kwarg);
216
+ if (debug) rp(ci);
217
+ if (kwarg) {
218
+ RB_DEBUG_COUNTER_INC(ci_kw);
219
+ }
220
+ else {
221
+ RB_DEBUG_COUNTER_INC(ci_nokw);
222
+ }
223
+
224
+ VM_ASSERT(vm_ci_flag(ci) == flag);
225
+ VM_ASSERT(vm_ci_argc(ci) == argc);
226
+
227
+ return ci;
228
+ }
229
+
230
+
231
+ static inline const struct rb_callinfo *
232
+ vm_ci_new_runtime_(ID mid, unsigned int flag, unsigned int argc, const struct rb_callinfo_kwarg *kwarg, const char *file, int line)
233
+ {
234
+ RB_DEBUG_COUNTER_INC(ci_runtime);
235
+ return vm_ci_new_(mid, flag, argc, kwarg, file, line);
236
+ }
237
+
238
+ #define VM_CALLINFO_NOT_UNDER_GC IMEMO_FL_USER0
239
+
240
+ static inline bool
241
+ vm_ci_markable(const struct rb_callinfo *ci)
242
+ {
243
+ if (! ci) {
244
+ return false; /* or true? This is Qfalse... */
245
+ }
246
+ else if (vm_ci_packed_p(ci)) {
247
+ return true;
248
+ }
249
+ else {
250
+ VM_ASSERT(IMEMO_TYPE_P(ci, imemo_callinfo));
251
+ return ! FL_ANY_RAW((VALUE)ci, VM_CALLINFO_NOT_UNDER_GC);
252
+ }
253
+ }
254
+
255
+ #define VM_CI_ON_STACK(mid_, flags_, argc_, kwarg_) \
256
+ (struct rb_callinfo) { \
257
+ .flags = T_IMEMO | \
258
+ (imemo_callinfo << FL_USHIFT) | \
259
+ VM_CALLINFO_NOT_UNDER_GC, \
260
+ .mid = mid_, \
261
+ .flag = flags_, \
262
+ .argc = argc_, \
263
+ .kwarg = kwarg_, \
264
+ }
265
+
266
+ typedef VALUE (*vm_call_handler)(
267
+ struct rb_execution_context_struct *ec,
268
+ struct rb_control_frame_struct *cfp,
269
+ struct rb_calling_info *calling);
270
+
271
+ // imemo_callcache
272
+
273
+ struct rb_callcache {
274
+ const VALUE flags;
275
+
276
+ /* inline cache: key */
277
+ const VALUE klass; // should not mark it because klass can not be free'd
278
+ // because of this marking. When klass is collected,
279
+ // cc will be cleared (cc->klass = 0) at vm_ccs_free().
280
+
281
+ /* inline cache: values */
282
+ const struct rb_callable_method_entry_struct * const cme_;
283
+ const vm_call_handler call_;
284
+
285
+ union {
286
+ struct {
287
+ uintptr_t value; // Shape ID in upper bits, index in lower bits
288
+ } attr;
289
+ const enum method_missing_reason method_missing_reason; /* used by method_missing */
290
+ VALUE v;
291
+ const struct rb_builtin_function *bf;
292
+ } aux_;
293
+ };
294
+
295
+ #define VM_CALLCACHE_UNMARKABLE FL_FREEZE
296
+ #define VM_CALLCACHE_ON_STACK FL_EXIVAR
297
+
298
+ extern const struct rb_callcache *rb_vm_empty_cc(void);
299
+ extern const struct rb_callcache *rb_vm_empty_cc_for_super(void);
300
+
301
+ #define vm_cc_empty() rb_vm_empty_cc()
302
+
303
+ static inline void vm_cc_attr_index_set(const struct rb_callcache *cc, attr_index_t index, shape_id_t dest_shape_id);
304
+
305
+ static inline void
306
+ vm_cc_attr_index_initialize(const struct rb_callcache *cc, shape_id_t shape_id)
307
+ {
308
+ vm_cc_attr_index_set(cc, (attr_index_t)-1, shape_id);
309
+ }
310
+
311
+ static inline const struct rb_callcache *
312
+ vm_cc_new(VALUE klass,
313
+ const struct rb_callable_method_entry_struct *cme,
314
+ vm_call_handler call)
315
+ {
316
+ const struct rb_callcache *cc = (const struct rb_callcache *)rb_imemo_new(imemo_callcache, (VALUE)cme, (VALUE)call, 0, klass);
317
+ vm_cc_attr_index_initialize(cc, INVALID_SHAPE_ID);
318
+ RB_DEBUG_COUNTER_INC(cc_new);
319
+ return cc;
320
+ }
321
+
322
+ #define VM_CC_ON_STACK(clazz, call, aux, cme) \
323
+ (struct rb_callcache) { \
324
+ .flags = T_IMEMO | \
325
+ (imemo_callcache << FL_USHIFT) | \
326
+ VM_CALLCACHE_UNMARKABLE | \
327
+ VM_CALLCACHE_ON_STACK, \
328
+ .klass = clazz, \
329
+ .cme_ = cme, \
330
+ .call_ = call, \
331
+ .aux_ = aux, \
332
+ }
333
+
334
+ static inline bool
335
+ vm_cc_class_check(const struct rb_callcache *cc, VALUE klass)
336
+ {
337
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
338
+ VM_ASSERT(cc->klass == 0 ||
339
+ RB_TYPE_P(cc->klass, T_CLASS) || RB_TYPE_P(cc->klass, T_ICLASS));
340
+ return cc->klass == klass;
341
+ }
342
+
343
+ static inline int
344
+ vm_cc_markable(const struct rb_callcache *cc)
345
+ {
346
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
347
+ return FL_TEST_RAW((VALUE)cc, VM_CALLCACHE_UNMARKABLE) == 0;
348
+ }
349
+
350
+ static inline const struct rb_callable_method_entry_struct *
351
+ vm_cc_cme(const struct rb_callcache *cc)
352
+ {
353
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
354
+ VM_ASSERT(cc->call_ == NULL || // not initialized yet
355
+ !vm_cc_markable(cc) ||
356
+ cc->cme_ != NULL);
357
+
358
+ return cc->cme_;
359
+ }
360
+
361
+ static inline vm_call_handler
362
+ vm_cc_call(const struct rb_callcache *cc)
363
+ {
364
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
365
+ VM_ASSERT(cc->call_ != NULL);
366
+ return cc->call_;
367
+ }
368
+
369
+ static inline attr_index_t
370
+ vm_cc_attr_index(const struct rb_callcache *cc)
371
+ {
372
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
373
+ return (attr_index_t)((cc->aux_.attr.value & SHAPE_FLAG_MASK) - 1);
374
+ }
375
+
376
+ static inline shape_id_t
377
+ vm_cc_attr_index_dest_shape_id(const struct rb_callcache *cc)
378
+ {
379
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
380
+
381
+ return cc->aux_.attr.value >> SHAPE_FLAG_SHIFT;
382
+ }
383
+
384
+ static inline void
385
+ vm_cc_atomic_shape_and_index(const struct rb_callcache *cc, shape_id_t * shape_id, attr_index_t * index)
386
+ {
387
+ uintptr_t cache_value = cc->aux_.attr.value; // Atomically read 64 bits
388
+ *shape_id = (shape_id_t)(cache_value >> SHAPE_FLAG_SHIFT);
389
+ *index = (attr_index_t)(cache_value & SHAPE_FLAG_MASK) - 1;
390
+ return;
391
+ }
392
+
393
+ static inline void
394
+ vm_ic_atomic_shape_and_index(const struct iseq_inline_iv_cache_entry *ic, shape_id_t * shape_id, attr_index_t * index)
395
+ {
396
+ uintptr_t cache_value = ic->value; // Atomically read 64 bits
397
+ *shape_id = (shape_id_t)(cache_value >> SHAPE_FLAG_SHIFT);
398
+ *index = (attr_index_t)(cache_value & SHAPE_FLAG_MASK) - 1;
399
+ return;
400
+ }
401
+
402
+ static inline shape_id_t
403
+ vm_ic_attr_index_dest_shape_id(const struct iseq_inline_iv_cache_entry *ic)
404
+ {
405
+ return (shape_id_t)(ic->value >> SHAPE_FLAG_SHIFT);
406
+ }
407
+
408
+ static inline unsigned int
409
+ vm_cc_cmethod_missing_reason(const struct rb_callcache *cc)
410
+ {
411
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
412
+ return cc->aux_.method_missing_reason;
413
+ }
414
+
415
+ static inline bool
416
+ vm_cc_invalidated_p(const struct rb_callcache *cc)
417
+ {
418
+ if (cc->klass && !METHOD_ENTRY_INVALIDATED(vm_cc_cme(cc))) {
419
+ return false;
420
+ }
421
+ else {
422
+ return true;
423
+ }
424
+ }
425
+
426
+ // For RJIT. cc_cme is supposed to have inlined `vm_cc_cme(cc)`.
427
+ static inline bool
428
+ vm_cc_valid_p(const struct rb_callcache *cc, const rb_callable_method_entry_t *cc_cme, VALUE klass)
429
+ {
430
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
431
+ if (cc->klass == klass && !METHOD_ENTRY_INVALIDATED(cc_cme)) {
432
+ return 1;
433
+ }
434
+ else {
435
+ return 0;
436
+ }
437
+ }
438
+
439
+ /* callcache: mutate */
440
+
441
+ #define VM_CALLCACH_IVAR IMEMO_FL_USER0
442
+ #define VM_CALLCACH_BF IMEMO_FL_USER1
443
+
444
+ static inline void
445
+ vm_cc_call_set(const struct rb_callcache *cc, vm_call_handler call)
446
+ {
447
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
448
+ VM_ASSERT(cc != vm_cc_empty());
449
+ *(vm_call_handler *)&cc->call_ = call;
450
+ }
451
+
452
+ static inline void
453
+ vm_cc_attr_index_set(const struct rb_callcache *cc, attr_index_t index, shape_id_t dest_shape_id)
454
+ {
455
+ uintptr_t *attr_value = (uintptr_t *)&cc->aux_.attr.value;
456
+ if (!vm_cc_markable(cc)) {
457
+ *attr_value = (uintptr_t)INVALID_SHAPE_ID << SHAPE_FLAG_SHIFT;
458
+ return;
459
+ }
460
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
461
+ VM_ASSERT(cc != vm_cc_empty());
462
+ *attr_value = (attr_index_t)(index + 1) | ((uintptr_t)(dest_shape_id) << SHAPE_FLAG_SHIFT);
463
+ *(VALUE *)&cc->flags |= VM_CALLCACH_IVAR;
464
+ }
465
+
466
+ static inline bool
467
+ vm_cc_ivar_p(const struct rb_callcache *cc)
468
+ {
469
+ return (cc->flags & VM_CALLCACH_IVAR) != 0;
470
+ }
471
+
472
+ static inline void
473
+ vm_ic_attr_index_set(const rb_iseq_t *iseq, const struct iseq_inline_iv_cache_entry *ic, attr_index_t index, shape_id_t dest_shape_id)
474
+ {
475
+ *(uintptr_t *)&ic->value = ((uintptr_t)dest_shape_id << SHAPE_FLAG_SHIFT) | (attr_index_t)(index + 1);
476
+ }
477
+
478
+ static inline void
479
+ vm_ic_attr_index_initialize(const struct iseq_inline_iv_cache_entry *ic, shape_id_t shape_id)
480
+ {
481
+ *(uintptr_t *)&ic->value = (uintptr_t)shape_id << SHAPE_FLAG_SHIFT;
482
+ }
483
+
484
+ static inline void
485
+ vm_cc_method_missing_reason_set(const struct rb_callcache *cc, enum method_missing_reason reason)
486
+ {
487
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
488
+ VM_ASSERT(cc != vm_cc_empty());
489
+ *(enum method_missing_reason *)&cc->aux_.method_missing_reason = reason;
490
+ }
491
+
492
+ static inline void
493
+ vm_cc_bf_set(const struct rb_callcache *cc, const struct rb_builtin_function *bf)
494
+ {
495
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
496
+ VM_ASSERT(cc != vm_cc_empty());
497
+ *(const struct rb_builtin_function **)&cc->aux_.bf = bf;
498
+ *(VALUE *)&cc->flags |= VM_CALLCACH_BF;
499
+ }
500
+
501
+ static inline bool
502
+ vm_cc_bf_p(const struct rb_callcache *cc)
503
+ {
504
+ return (cc->flags & VM_CALLCACH_BF) != 0;
505
+ }
506
+
507
+ static inline void
508
+ vm_cc_invalidate(const struct rb_callcache *cc)
509
+ {
510
+ VM_ASSERT(IMEMO_TYPE_P(cc, imemo_callcache));
511
+ VM_ASSERT(cc != vm_cc_empty());
512
+ VM_ASSERT(cc->klass != 0); // should be enable
513
+
514
+ *(VALUE *)&cc->klass = 0;
515
+ RB_DEBUG_COUNTER_INC(cc_ent_invalidate);
516
+ }
517
+
518
+ /* calldata */
519
+
520
+ struct rb_call_data {
521
+ const struct rb_callinfo *ci;
522
+ const struct rb_callcache *cc;
523
+ };
524
+
525
+ struct rb_class_cc_entries {
526
+ #if VM_CHECK_MODE > 0
527
+ VALUE debug_sig;
528
+ #endif
529
+ int capa;
530
+ int len;
531
+ const struct rb_callable_method_entry_struct *cme;
532
+ struct rb_class_cc_entries_entry {
533
+ const struct rb_callinfo *ci;
534
+ const struct rb_callcache *cc;
535
+ } *entries;
536
+ };
537
+
538
+ #if VM_CHECK_MODE > 0
539
+
540
+ const rb_callable_method_entry_t *rb_vm_lookup_overloaded_cme(const rb_callable_method_entry_t *cme);
541
+ void rb_vm_dump_overloaded_cme_table(void);
542
+
543
+ static inline bool
544
+ vm_ccs_p(const struct rb_class_cc_entries *ccs)
545
+ {
546
+ return ccs->debug_sig == ~(VALUE)ccs;
547
+ }
548
+
549
+ static inline bool
550
+ vm_cc_check_cme(const struct rb_callcache *cc, const rb_callable_method_entry_t *cme)
551
+ {
552
+ if (vm_cc_cme(cc) == cme ||
553
+ (cme->def->iseq_overload && vm_cc_cme(cc) == rb_vm_lookup_overloaded_cme(cme))) {
554
+ return true;
555
+ }
556
+ else {
557
+ #if 1
558
+ // debug print
559
+
560
+ fprintf(stderr, "iseq_overload:%d\n", (int)cme->def->iseq_overload);
561
+ rp(cme);
562
+ rp(vm_cc_cme(cc));
563
+ rb_vm_lookup_overloaded_cme(cme);
564
+ #endif
565
+ return false;
566
+ }
567
+ }
568
+
569
+ #endif
570
+
571
+ // gc.c
572
+ void rb_vm_ccs_free(struct rb_class_cc_entries *ccs);
573
+
574
+ #endif /* RUBY_VM_CALLINFO_H */