debase-ruby_core_source 0.10.12 → 0.10.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (116) hide show
  1. checksums.yaml +4 -4
  2. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/addr2line.h +20 -0
  3. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/builtin.h +83 -0
  4. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
  5. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/check_type/check_type.h +63 -0
  6. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/container_of/container_of.h +142 -0
  7. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/list/list.h +788 -0
  8. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ccan/str/str.h +16 -0
  9. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/constant.h +55 -0
  10. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/darray.h +198 -0
  11. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/debug_counter.h +467 -0
  12. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/dln.h +31 -0
  13. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/encindex.h +70 -0
  14. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/eval_intern.h +304 -0
  15. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/gc.h +142 -0
  16. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/hrtime.h +168 -0
  17. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/id.h +293 -0
  18. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/id_table.h +36 -0
  19. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/insns.inc +247 -0
  20. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/insns_info.inc +8978 -0
  21. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/array.h +113 -0
  22. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/bignum.h +246 -0
  23. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/bits.h +565 -0
  24. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/class.h +188 -0
  25. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compar.h +49 -0
  26. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compile.h +35 -0
  27. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/compilers.h +107 -0
  28. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/complex.h +29 -0
  29. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/cont.h +24 -0
  30. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/dir.h +16 -0
  31. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enc.h +19 -0
  32. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/encoding.h +30 -0
  33. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enum.h +18 -0
  34. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/enumerator.h +21 -0
  35. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/error.h +191 -0
  36. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/eval.h +32 -0
  37. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/file.h +38 -0
  38. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/fixnum.h +184 -0
  39. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/gc.h +175 -0
  40. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/hash.h +243 -0
  41. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/imemo.h +243 -0
  42. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/inits.h +50 -0
  43. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/io.h +38 -0
  44. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/load.h +18 -0
  45. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/loadpath.h +16 -0
  46. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/math.h +23 -0
  47. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/missing.h +18 -0
  48. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/numeric.h +271 -0
  49. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/object.h +83 -0
  50. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/parse.h +23 -0
  51. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/proc.h +32 -0
  52. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/process.h +137 -0
  53. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/random.h +16 -0
  54. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/range.h +40 -0
  55. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/rational.h +72 -0
  56. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/re.h +30 -0
  57. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/sanitizers.h +190 -0
  58. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/serial.h +23 -0
  59. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/signal.h +21 -0
  60. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/static_assert.h +16 -0
  61. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/string.h +141 -0
  62. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/struct.h +153 -0
  63. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/symbol.h +40 -0
  64. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/thread.h +53 -0
  65. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/time.h +34 -0
  66. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/transcode.h +20 -0
  67. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/util.h +27 -0
  68. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/variable.h +83 -0
  69. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/vm.h +132 -0
  70. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal/warnings.h +16 -0
  71. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/internal.h +109 -0
  72. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/iseq.h +320 -0
  73. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/known_errors.inc +791 -0
  74. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/method.h +245 -0
  75. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/mjit.h +231 -0
  76. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/mjit_compile.inc +8265 -0
  77. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/node.h +499 -0
  78. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/node_name.inc +210 -0
  79. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/opt_sc.inc +107 -0
  80. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/optinsn.inc +128 -0
  81. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/optunifs.inc +43 -0
  82. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/parse.h +214 -0
  83. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/probes_helper.h +44 -0
  84. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ractor_core.h +346 -0
  85. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regenc.h +254 -0
  86. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regint.h +942 -0
  87. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/regparse.h +370 -0
  88. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/revision.h +2 -0
  89. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ruby_assert.h +14 -0
  90. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/ruby_atomic.h +23 -0
  91. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/siphash.h +48 -0
  92. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/symbol.h +119 -0
  93. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/thread_pthread.h +115 -0
  94. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/thread_win32.h +61 -0
  95. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/timev.h +57 -0
  96. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/transcode_data.h +138 -0
  97. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/transient_heap.h +65 -0
  98. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/variable.h +21 -0
  99. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/version.h +88 -0
  100. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm.inc +5415 -0
  101. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_call_iseq_optimized.inc +244 -0
  102. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_callinfo.h +454 -0
  103. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_core.h +2103 -0
  104. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_debug.h +119 -0
  105. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_exec.h +197 -0
  106. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_insnhelper.h +265 -0
  107. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_opts.h +73 -0
  108. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vm_sync.h +137 -0
  109. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/vmtc.inc +241 -0
  110. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit.h +63 -0
  111. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_asm.h +392 -0
  112. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_codegen.h +19 -0
  113. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_core.h +302 -0
  114. data/lib/debase/ruby_core_source/ruby-3.1.0-preview1/yjit_iface.h +38 -0
  115. data/lib/debase/ruby_core_source/version.rb +1 -1
  116. metadata +116 -3
@@ -0,0 +1,245 @@
1
+ #ifndef RUBY_METHOD_H
2
+ #define RUBY_METHOD_H 1
3
+ /**********************************************************************
4
+
5
+ method.h -
6
+
7
+ $Author$
8
+ created at: Wed Jul 15 20:02:33 2009
9
+
10
+ Copyright (C) 2009 Koichi Sasada
11
+
12
+ **********************************************************************/
13
+
14
+ #include "internal.h"
15
+ #include "internal/imemo.h"
16
+ #include "internal/compilers.h"
17
+ #include "internal/static_assert.h"
18
+
19
+ #ifndef END_OF_ENUMERATION
20
+ # if defined(__GNUC__) &&! defined(__STRICT_ANSI__)
21
+ # define END_OF_ENUMERATION(key)
22
+ # else
23
+ # define END_OF_ENUMERATION(key) END_OF_##key##_PLACEHOLDER = 0
24
+ # endif
25
+ #endif
26
+
27
+ /* cref */
28
+
29
+ typedef enum {
30
+ METHOD_VISI_UNDEF = 0x00,
31
+ METHOD_VISI_PUBLIC = 0x01,
32
+ METHOD_VISI_PRIVATE = 0x02,
33
+ METHOD_VISI_PROTECTED = 0x03,
34
+
35
+ METHOD_VISI_MASK = 0x03
36
+ } rb_method_visibility_t;
37
+
38
+ typedef struct rb_scope_visi_struct {
39
+ BITFIELD(rb_method_visibility_t, method_visi, 3);
40
+ unsigned int module_func : 1;
41
+ } rb_scope_visibility_t;
42
+
43
+ /*! CREF (Class REFerence) */
44
+ typedef struct rb_cref_struct {
45
+ VALUE flags;
46
+ VALUE refinements;
47
+ VALUE klass;
48
+ struct rb_cref_struct * next;
49
+ const rb_scope_visibility_t scope_visi;
50
+ } rb_cref_t;
51
+
52
+ /* method data type */
53
+
54
+ typedef struct rb_method_entry_struct {
55
+ VALUE flags;
56
+ VALUE defined_class;
57
+ struct rb_method_definition_struct * const def;
58
+ ID called_id;
59
+ VALUE owner;
60
+ } rb_method_entry_t;
61
+
62
+ typedef struct rb_callable_method_entry_struct { /* same fields with rb_method_entry_t */
63
+ VALUE flags;
64
+ const VALUE defined_class;
65
+ struct rb_method_definition_struct * const def;
66
+ ID called_id;
67
+ const VALUE owner;
68
+ } rb_callable_method_entry_t;
69
+
70
+ #define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0))
71
+ #define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2))
72
+ #define METHOD_ENTRY_COMPLEMENTED(me) ((me)->flags & IMEMO_FL_USER3)
73
+ #define METHOD_ENTRY_COMPLEMENTED_SET(me) ((me)->flags |= IMEMO_FL_USER3)
74
+ #define METHOD_ENTRY_CACHED(me) ((me)->flags & IMEMO_FL_USER4)
75
+ #define METHOD_ENTRY_CACHED_SET(me) ((me)->flags |= IMEMO_FL_USER4)
76
+ #define METHOD_ENTRY_INVALIDATED(me) ((me)->flags & IMEMO_FL_USER5)
77
+ #define METHOD_ENTRY_INVALIDATED_SET(me) ((me)->flags |= IMEMO_FL_USER5)
78
+ #define METHOD_ENTRY_CACHEABLE(me) !(METHOD_ENTRY_VISI(me) == METHOD_VISI_PROTECTED)
79
+
80
+ static inline void
81
+ METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi)
82
+ {
83
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
84
+ me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << (IMEMO_FL_USHIFT+0));
85
+ }
86
+ static inline void
87
+ METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, unsigned int basic)
88
+ {
89
+ VM_ASSERT(basic <= 1);
90
+ me->flags = (me->flags & ~(IMEMO_FL_USER2 )) | (basic << (IMEMO_FL_USHIFT+2));
91
+ }
92
+ static inline void
93
+ METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, unsigned int basic)
94
+ {
95
+ VM_ASSERT((int)visi >= 0 && visi <= 3);
96
+ VM_ASSERT(basic <= 1);
97
+ me->flags =
98
+ (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
99
+ ((visi << (IMEMO_FL_USHIFT+0)) | (basic << (IMEMO_FL_USHIFT+2)));
100
+ }
101
+ static inline void
102
+ METHOD_ENTRY_FLAGS_COPY(rb_method_entry_t *dst, const rb_method_entry_t *src)
103
+ {
104
+ dst->flags =
105
+ (dst->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2)) |
106
+ (src->flags & (IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2));
107
+ }
108
+
109
+ typedef enum {
110
+ VM_METHOD_TYPE_ISEQ, /*!< Ruby method */
111
+ VM_METHOD_TYPE_CFUNC, /*!< C method */
112
+ VM_METHOD_TYPE_ATTRSET, /*!< attr_writer or attr_accessor */
113
+ VM_METHOD_TYPE_IVAR, /*!< attr_reader or attr_accessor */
114
+ VM_METHOD_TYPE_BMETHOD,
115
+ VM_METHOD_TYPE_ZSUPER,
116
+ VM_METHOD_TYPE_ALIAS,
117
+ VM_METHOD_TYPE_UNDEF,
118
+ VM_METHOD_TYPE_NOTIMPLEMENTED,
119
+ VM_METHOD_TYPE_OPTIMIZED, /*!< Kernel#send, Proc#call, etc */
120
+ VM_METHOD_TYPE_MISSING, /*!< wrapper for method_missing(id) */
121
+ VM_METHOD_TYPE_REFINED, /*!< refinement */
122
+
123
+ END_OF_ENUMERATION(VM_METHOD_TYPE)
124
+ } rb_method_type_t;
125
+ #define VM_METHOD_TYPE_MINIMUM_BITS 4
126
+ STATIC_ASSERT(VM_METHOD_TYPE_MINIMUM_BITS,
127
+ VM_METHOD_TYPE_REFINED <= (1<<VM_METHOD_TYPE_MINIMUM_BITS));
128
+
129
+ #ifndef rb_iseq_t
130
+ typedef struct rb_iseq_struct rb_iseq_t;
131
+ #define rb_iseq_t rb_iseq_t
132
+ #endif
133
+
134
+ typedef struct rb_method_iseq_struct {
135
+ rb_iseq_t * iseqptr; /*!< iseq pointer, should be separated from iseqval */
136
+ rb_cref_t * cref; /*!< class reference, should be marked */
137
+ } rb_method_iseq_t; /* check rb_add_method_iseq() when modify the fields */
138
+
139
+ typedef struct rb_method_cfunc_struct {
140
+ VALUE (*func)(ANYARGS);
141
+ VALUE (*invoker)(VALUE recv, int argc, const VALUE *argv, VALUE (*func)(ANYARGS));
142
+ int argc;
143
+ } rb_method_cfunc_t;
144
+
145
+ typedef struct rb_method_attr_struct {
146
+ ID id;
147
+ VALUE location; /* should be marked */
148
+ } rb_method_attr_t;
149
+
150
+ typedef struct rb_method_alias_struct {
151
+ struct rb_method_entry_struct * original_me; /* original_me->klass is original owner */
152
+ } rb_method_alias_t;
153
+
154
+ typedef struct rb_method_refined_struct {
155
+ struct rb_method_entry_struct * orig_me;
156
+ VALUE owner;
157
+ } rb_method_refined_t;
158
+
159
+ typedef struct rb_method_bmethod_struct {
160
+ VALUE proc; /* should be marked */
161
+ struct rb_hook_list_struct *hooks;
162
+ VALUE defined_ractor;
163
+ } rb_method_bmethod_t;
164
+
165
+ enum method_optimized_type {
166
+ OPTIMIZED_METHOD_TYPE_SEND,
167
+ OPTIMIZED_METHOD_TYPE_CALL,
168
+ OPTIMIZED_METHOD_TYPE_BLOCK_CALL,
169
+ OPTIMIZED_METHOD_TYPE__MAX
170
+ };
171
+
172
+ struct rb_method_definition_struct {
173
+ BITFIELD(rb_method_type_t, type, VM_METHOD_TYPE_MINIMUM_BITS);
174
+ int alias_count : 28;
175
+ int complemented_count : 28;
176
+
177
+ union {
178
+ rb_method_iseq_t iseq;
179
+ rb_method_cfunc_t cfunc;
180
+ rb_method_attr_t attr;
181
+ rb_method_alias_t alias;
182
+ rb_method_refined_t refined;
183
+ rb_method_bmethod_t bmethod;
184
+
185
+ enum method_optimized_type optimize_type;
186
+ } body;
187
+
188
+ ID original_id;
189
+ uintptr_t method_serial;
190
+ };
191
+
192
+ struct rb_id_table;
193
+
194
+ typedef struct rb_method_definition_struct rb_method_definition_t;
195
+ STATIC_ASSERT(sizeof_method_def, offsetof(rb_method_definition_t, body)==8);
196
+
197
+ #define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
198
+ #define UNDEFINED_REFINED_METHOD_P(def) \
199
+ ((def)->type == VM_METHOD_TYPE_REFINED && \
200
+ UNDEFINED_METHOD_ENTRY_P((def)->body.refined.orig_me))
201
+
202
+ void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_visibility_t visi);
203
+ void rb_add_method_iseq(VALUE klass, ID mid, const rb_iseq_t *iseq, rb_cref_t *cref, rb_method_visibility_t visi);
204
+ void rb_add_refined_method_entry(VALUE refined_class, ID mid);
205
+ void rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi);
206
+
207
+ rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_visibility_t noex);
208
+ rb_method_entry_t *rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, const rb_method_definition_t *def);
209
+
210
+ const rb_method_entry_t *rb_method_entry_at(VALUE obj, ID id);
211
+
212
+ const rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
213
+ const rb_method_entry_t *rb_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
214
+ const rb_method_entry_t *rb_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
215
+ const rb_method_entry_t *rb_resolve_refined_method(VALUE refinements, const rb_method_entry_t *me);
216
+ RUBY_SYMBOL_EXPORT_BEGIN
217
+ const rb_method_entry_t *rb_resolve_me_location(const rb_method_entry_t *, VALUE[5]);
218
+ RUBY_SYMBOL_EXPORT_END
219
+
220
+ const rb_callable_method_entry_t *rb_callable_method_entry(VALUE klass, ID id);
221
+ const rb_callable_method_entry_t *rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class);
222
+ const rb_callable_method_entry_t *rb_callable_method_entry_without_refinements(VALUE klass, ID id, VALUE *defined_class);
223
+
224
+ int rb_method_entry_arity(const rb_method_entry_t *me);
225
+ int rb_method_entry_eq(const rb_method_entry_t *m1, const rb_method_entry_t *m2);
226
+ st_index_t rb_hash_method_entry(st_index_t hash, const rb_method_entry_t *me);
227
+
228
+ VALUE rb_method_entry_location(const rb_method_entry_t *me);
229
+
230
+ void rb_free_method_entry(const rb_method_entry_t *me);
231
+
232
+ const rb_method_entry_t *rb_method_entry_clone(const rb_method_entry_t *me);
233
+ const rb_callable_method_entry_t *rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class);
234
+ void rb_method_entry_copy(rb_method_entry_t *dst, const rb_method_entry_t *src);
235
+
236
+ void rb_method_table_insert(VALUE klass, struct rb_id_table *table, ID method_id, const rb_method_entry_t *me);
237
+
238
+ void rb_scope_visibility_set(rb_method_visibility_t);
239
+
240
+ VALUE rb_unnamed_parameters(int arity);
241
+
242
+ void rb_clear_method_cache(VALUE klass_or_module, ID mid);
243
+ void rb_clear_method_cache_all(void);
244
+
245
+ #endif /* RUBY_METHOD_H */
@@ -0,0 +1,231 @@
1
+ #ifndef RUBY_MJIT_H
2
+ #define RUBY_MJIT_H 1
3
+ /**********************************************************************
4
+
5
+ mjit.h - Interface to MRI method JIT compiler for Ruby's main thread
6
+
7
+ Copyright (C) 2017 Vladimir Makarov <vmakarov@redhat.com>.
8
+
9
+ **********************************************************************/
10
+
11
+ #include "ruby/internal/config.h" // defines USE_MJIT
12
+ #include "ruby/internal/stdbool.h"
13
+ #include "vm_core.h"
14
+
15
+ # if USE_MJIT
16
+
17
+ #include "debug_counter.h"
18
+ #include "ruby.h"
19
+ #include "vm_core.h"
20
+ #include "yjit.h"
21
+
22
+ // Special address values of a function generated from the
23
+ // corresponding iseq by MJIT:
24
+ enum rb_mjit_iseq_func {
25
+ // ISEQ has never been enqueued to unit_queue yet
26
+ NOT_ADDED_JIT_ISEQ_FUNC = 0,
27
+ // ISEQ is already queued for the machine code generation but the
28
+ // code is not ready yet for the execution
29
+ NOT_READY_JIT_ISEQ_FUNC = 1,
30
+ // ISEQ included not compilable insn, some internal assertion failed
31
+ // or the unit is unloaded
32
+ NOT_COMPILED_JIT_ISEQ_FUNC = 2,
33
+ // End mark
34
+ LAST_JIT_ISEQ_FUNC = 3
35
+ };
36
+
37
+ // MJIT options which can be defined on the MRI command line.
38
+ struct mjit_options {
39
+ // Converted from "jit" feature flag to tell the enablement
40
+ // information to ruby_show_version().
41
+ char on;
42
+ // Save temporary files after MRI finish. The temporary files
43
+ // include the pre-compiled header, C code file generated for ISEQ,
44
+ // and the corresponding object file.
45
+ char save_temps;
46
+ // Print MJIT warnings to stderr.
47
+ char warnings;
48
+ // Disable compiler optimization and add debug symbols. It can be
49
+ // very slow.
50
+ char debug;
51
+ // Add arbitrary cflags.
52
+ char* debug_flags;
53
+ // If not 0, all ISeqs are synchronously compiled. For testing.
54
+ unsigned int wait;
55
+ // Number of calls to trigger JIT compilation. For testing.
56
+ unsigned int min_calls;
57
+ // Force printing info about MJIT work of level VERBOSE or
58
+ // less. 0=silence, 1=medium, 2=verbose.
59
+ int verbose;
60
+ // Maximal permitted number of iseq JIT codes in a MJIT memory
61
+ // cache.
62
+ int max_cache_size;
63
+ };
64
+
65
+ // State of optimization switches
66
+ struct rb_mjit_compile_info {
67
+ // Disable getinstancevariable/setinstancevariable optimizations based on inline cache (T_OBJECT)
68
+ bool disable_ivar_cache;
69
+ // Disable getinstancevariable/setinstancevariable optimizations based on inline cache (FL_EXIVAR)
70
+ bool disable_exivar_cache;
71
+ // Disable send/opt_send_without_block optimizations based on inline cache
72
+ bool disable_send_cache;
73
+ // Disable method inlining
74
+ bool disable_inlining;
75
+ // Disable opt_getinlinecache inlining
76
+ bool disable_const_cache;
77
+ };
78
+
79
+ typedef VALUE (*mjit_func_t)(rb_execution_context_t *, rb_control_frame_t *);
80
+
81
+ RUBY_SYMBOL_EXPORT_BEGIN
82
+ RUBY_EXTERN struct mjit_options mjit_opts;
83
+ RUBY_EXTERN bool mjit_call_p;
84
+
85
+ extern void rb_mjit_add_iseq_to_process(const rb_iseq_t *iseq);
86
+ extern VALUE rb_mjit_wait_call(rb_execution_context_t *ec, struct rb_iseq_constant_body *body);
87
+ extern struct rb_mjit_compile_info* rb_mjit_iseq_compile_info(const struct rb_iseq_constant_body *body);
88
+ extern void rb_mjit_recompile_send(const rb_iseq_t *iseq);
89
+ extern void rb_mjit_recompile_ivar(const rb_iseq_t *iseq);
90
+ extern void rb_mjit_recompile_exivar(const rb_iseq_t *iseq);
91
+ extern void rb_mjit_recompile_inlining(const rb_iseq_t *iseq);
92
+ extern void rb_mjit_recompile_const(const rb_iseq_t *iseq);
93
+ RUBY_SYMBOL_EXPORT_END
94
+
95
+ extern void mjit_cancel_all(const char *reason);
96
+ extern bool mjit_compile(FILE *f, const rb_iseq_t *iseq, const char *funcname, int id);
97
+ extern void mjit_init(const struct mjit_options *opts);
98
+ extern void mjit_gc_start_hook(void);
99
+ extern void mjit_gc_exit_hook(void);
100
+ extern void mjit_free_iseq(const rb_iseq_t *iseq);
101
+ extern void mjit_update_references(const rb_iseq_t *iseq);
102
+ extern void mjit_mark(void);
103
+ extern struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec);
104
+ extern void mjit_cont_free(struct mjit_cont *cont);
105
+ extern void mjit_mark_cc_entries(const struct rb_iseq_constant_body *const body);
106
+
107
+ # ifdef MJIT_HEADER
108
+ NOINLINE(static COLDFUNC VALUE mjit_exec_slowpath(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_iseq_constant_body *body));
109
+ # else
110
+ static inline VALUE mjit_exec_slowpath(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_iseq_constant_body *body);
111
+ # endif
112
+ static VALUE
113
+ mjit_exec_slowpath(rb_execution_context_t *ec, const rb_iseq_t *iseq, struct rb_iseq_constant_body *body)
114
+ {
115
+ uintptr_t func_i = (uintptr_t)(body->jit_func);
116
+ ASSUME(func_i <= LAST_JIT_ISEQ_FUNC);
117
+ switch ((enum rb_mjit_iseq_func)func_i) {
118
+ case NOT_ADDED_JIT_ISEQ_FUNC:
119
+ RB_DEBUG_COUNTER_INC(mjit_exec_not_added);
120
+ if (body->total_calls == mjit_opts.min_calls) {
121
+ rb_mjit_add_iseq_to_process(iseq);
122
+ if (UNLIKELY(mjit_opts.wait)) {
123
+ return rb_mjit_wait_call(ec, body);
124
+ }
125
+ }
126
+ break;
127
+ case NOT_READY_JIT_ISEQ_FUNC:
128
+ RB_DEBUG_COUNTER_INC(mjit_exec_not_ready);
129
+ break;
130
+ case NOT_COMPILED_JIT_ISEQ_FUNC:
131
+ RB_DEBUG_COUNTER_INC(mjit_exec_not_compiled);
132
+ break;
133
+ default: // to avoid warning with LAST_JIT_ISEQ_FUNC
134
+ break;
135
+ }
136
+ return Qundef;
137
+ }
138
+
139
+ // Try to execute the current iseq in ec. Use JIT code if it is ready.
140
+ // If it is not, add ISEQ to the compilation queue and return Qundef for MJIT.
141
+ // YJIT compiles on the thread running the iseq.
142
+ static inline VALUE
143
+ mjit_exec(rb_execution_context_t *ec)
144
+ {
145
+ const rb_iseq_t *iseq = ec->cfp->iseq;
146
+ struct rb_iseq_constant_body *body = iseq->body;
147
+ bool yjit_enabled = false;
148
+ #ifndef MJIT_HEADER
149
+ // Don't want to compile with YJIT or use code generated by YJIT
150
+ // when running inside code generated by MJIT.
151
+ yjit_enabled = rb_yjit_enabled_p();
152
+ #endif
153
+
154
+ if (mjit_call_p || yjit_enabled) {
155
+ body->total_calls++;
156
+ }
157
+
158
+ #ifndef MJIT_HEADER
159
+ if (yjit_enabled && !mjit_call_p && body->total_calls == rb_yjit_call_threshold()) {
160
+ // If we couldn't generate any code for this iseq, then return
161
+ // Qundef so the interpreter will handle the call.
162
+ if (!rb_yjit_compile_iseq(iseq, ec)) {
163
+ return Qundef;
164
+ }
165
+ }
166
+ #endif
167
+
168
+ if (!(mjit_call_p || yjit_enabled))
169
+ return Qundef;
170
+
171
+ RB_DEBUG_COUNTER_INC(mjit_exec);
172
+
173
+ mjit_func_t func = body->jit_func;
174
+
175
+ // YJIT tried compiling this function once before and couldn't do
176
+ // it, so return Qundef so the interpreter handles it.
177
+ if (yjit_enabled && func == 0) {
178
+ return Qundef;
179
+ }
180
+
181
+ if (UNLIKELY((uintptr_t)func <= LAST_JIT_ISEQ_FUNC)) {
182
+ # ifdef MJIT_HEADER
183
+ RB_DEBUG_COUNTER_INC(mjit_frame_JT2VM);
184
+ # else
185
+ RB_DEBUG_COUNTER_INC(mjit_frame_VM2VM);
186
+ # endif
187
+ return mjit_exec_slowpath(ec, iseq, body);
188
+ }
189
+
190
+ # ifdef MJIT_HEADER
191
+ RB_DEBUG_COUNTER_INC(mjit_frame_JT2JT);
192
+ # else
193
+ RB_DEBUG_COUNTER_INC(mjit_frame_VM2JT);
194
+ # endif
195
+ RB_DEBUG_COUNTER_INC(mjit_exec_call_func);
196
+ // Under SystemV x64 calling convention
197
+ // ec -> RDI
198
+ // cfp -> RSI
199
+ return func(ec, ec->cfp);
200
+ }
201
+
202
+ void mjit_child_after_fork(void);
203
+
204
+ # ifdef MJIT_HEADER
205
+ #define mjit_enabled true
206
+ # else // MJIT_HEADER
207
+ extern bool mjit_enabled;
208
+ # endif // MJIT_HEADER
209
+ VALUE mjit_pause(bool wait_p);
210
+ VALUE mjit_resume(void);
211
+ void mjit_finish(bool close_handle_p);
212
+
213
+ # else // USE_MJIT
214
+
215
+ static inline void mjit_cancel_all(const char *reason){}
216
+ static inline struct mjit_cont *mjit_cont_new(rb_execution_context_t *ec){return NULL;}
217
+ static inline void mjit_cont_free(struct mjit_cont *cont){}
218
+ static inline void mjit_gc_start_hook(void){}
219
+ static inline void mjit_gc_exit_hook(void){}
220
+ static inline void mjit_free_iseq(const rb_iseq_t *iseq){}
221
+ static inline void mjit_mark(void){}
222
+ static inline VALUE mjit_exec(rb_execution_context_t *ec) { return Qundef; /* unreachable */ }
223
+ static inline void mjit_child_after_fork(void){}
224
+
225
+ #define mjit_enabled false
226
+ static inline VALUE mjit_pause(bool wait_p){ return Qnil; } // unreachable
227
+ static inline VALUE mjit_resume(void){ return Qnil; } // unreachable
228
+ static inline void mjit_finish(bool close_handle_p){}
229
+
230
+ # endif // USE_MJIT
231
+ #endif // RUBY_MJIT_H