datadog-ruby_core_source 3.4.2 → 3.4.3

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ccan/build_assert/build_assert.h +40 -0
  3. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ccan/check_type/check_type.h +63 -0
  4. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ccan/container_of/container_of.h +142 -0
  5. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ccan/list/list.h +791 -0
  6. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ccan/str/str.h +17 -0
  7. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/id.h +357 -0
  8. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/id_table.h +54 -0
  9. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/array.h +154 -0
  10. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/basic_operators.h +66 -0
  11. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/bignum.h +256 -0
  12. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/bits.h +647 -0
  13. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/box.h +83 -0
  14. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/class.h +806 -0
  15. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/cmdlineopt.h +64 -0
  16. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/compar.h +29 -0
  17. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/compile.h +34 -0
  18. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/compilers.h +107 -0
  19. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/complex.h +29 -0
  20. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/concurrent_set.h +21 -0
  21. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/cont.h +34 -0
  22. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/dir.h +16 -0
  23. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/enc.h +19 -0
  24. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/encoding.h +39 -0
  25. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/enum.h +18 -0
  26. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/enumerator.h +21 -0
  27. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/error.h +251 -0
  28. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/eval.h +43 -0
  29. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/file.h +38 -0
  30. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/fixnum.h +185 -0
  31. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/gc.h +360 -0
  32. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/hash.h +194 -0
  33. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/imemo.h +322 -0
  34. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/inits.h +51 -0
  35. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/io.h +163 -0
  36. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/load.h +20 -0
  37. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/loadpath.h +16 -0
  38. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/math.h +23 -0
  39. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/missing.h +19 -0
  40. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/numeric.h +323 -0
  41. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/object.h +63 -0
  42. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/parse.h +131 -0
  43. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/proc.h +30 -0
  44. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/process.h +124 -0
  45. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/ractor.h +10 -0
  46. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/random.h +17 -0
  47. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/range.h +40 -0
  48. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/rational.h +71 -0
  49. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/re.h +33 -0
  50. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/ruby_parser.h +102 -0
  51. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/sanitizers.h +346 -0
  52. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/serial.h +23 -0
  53. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/set_table.h +70 -0
  54. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/signal.h +25 -0
  55. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/st.h +11 -0
  56. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/static_assert.h +16 -0
  57. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/string.h +203 -0
  58. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/struct.h +160 -0
  59. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/symbol.h +46 -0
  60. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/thread.h +112 -0
  61. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/time.h +34 -0
  62. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/transcode.h +23 -0
  63. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/util.h +27 -0
  64. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/variable.h +74 -0
  65. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/vm.h +138 -0
  66. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal/warnings.h +16 -0
  67. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/internal.h +105 -0
  68. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/iseq.h +359 -0
  69. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/method.h +276 -0
  70. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/node.h +122 -0
  71. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/parser_st.h +162 -0
  72. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/parser_value.h +106 -0
  73. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/ast.h +8254 -0
  74. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/defines.h +260 -0
  75. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/diagnostic.h +458 -0
  76. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/encoding.h +283 -0
  77. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/extension.h +19 -0
  78. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/node.h +129 -0
  79. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/options.h +485 -0
  80. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/pack.h +163 -0
  81. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/parser.h +936 -0
  82. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/prettyprint.h +34 -0
  83. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/prism.h +408 -0
  84. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/regexp.h +43 -0
  85. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/static_literals.h +121 -0
  86. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_buffer.h +236 -0
  87. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_char.h +204 -0
  88. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_constant_pool.h +218 -0
  89. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_integer.h +130 -0
  90. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_list.h +103 -0
  91. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_memchr.h +29 -0
  92. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_newline_list.h +113 -0
  93. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_string.h +200 -0
  94. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_strncasecmp.h +32 -0
  95. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/util/pm_strpbrk.h +46 -0
  96. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism/version.h +29 -0
  97. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/prism_compile.h +106 -0
  98. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ractor_core.h +331 -0
  99. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ruby_assert.h +14 -0
  100. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/ruby_atomic.h +73 -0
  101. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/rubyparser.h +1393 -0
  102. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/shape.h +464 -0
  103. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/thread_none.h +21 -0
  104. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/thread_pthread.h +177 -0
  105. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/vm_core.h +2397 -0
  106. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/vm_debug.h +124 -0
  107. data/lib/datadog/ruby_core_source/ruby-4.0.0-preview3/vm_opts.h +67 -0
  108. data/lib/datadog/ruby_core_source/version.rb +1 -1
  109. metadata +108 -3
  110. data/CHANGELOG.datadog.md +0 -19
@@ -0,0 +1,464 @@
1
+ #ifndef RUBY_SHAPE_H
2
+ #define RUBY_SHAPE_H
3
+
4
+ #include "internal/gc.h"
5
+
6
+ typedef uint16_t attr_index_t;
7
+ typedef uint32_t shape_id_t;
8
+ #define SHAPE_ID_NUM_BITS 32
9
+ #define SHAPE_ID_OFFSET_NUM_BITS 19
10
+
11
+ STATIC_ASSERT(shape_id_num_bits, SHAPE_ID_NUM_BITS == sizeof(shape_id_t) * CHAR_BIT);
12
+
13
+ #define SHAPE_BUFFER_SIZE (1 << SHAPE_ID_OFFSET_NUM_BITS)
14
+ #define SHAPE_ID_OFFSET_MASK (SHAPE_BUFFER_SIZE - 1)
15
+
16
+ #define SHAPE_ID_HEAP_INDEX_BITS 3
17
+ #define SHAPE_ID_HEAP_INDEX_MAX ((1 << SHAPE_ID_HEAP_INDEX_BITS) - 1)
18
+
19
+ #define SHAPE_ID_FL_USHIFT (SHAPE_ID_OFFSET_NUM_BITS + SHAPE_ID_HEAP_INDEX_BITS)
20
+ #define SHAPE_ID_HEAP_INDEX_OFFSET SHAPE_ID_FL_USHIFT
21
+
22
+ // shape_id_t bits:
23
+ // 0-18 SHAPE_ID_OFFSET_MASK
24
+ // index in rb_shape_tree.shape_list. Allow to access `rb_shape_t *`.
25
+ // 19-21 SHAPE_ID_HEAP_INDEX_MASK
26
+ // index in rb_shape_tree.capacities. Allow to access slot size.
27
+ // Always 0 except for T_OBJECT.
28
+ // 22 SHAPE_ID_FL_FROZEN
29
+ // Whether the object is frozen or not.
30
+ // 23 SHAPE_ID_FL_HAS_OBJECT_ID
31
+ // Whether the object has an `SHAPE_OBJ_ID` transition.
32
+ // 24 SHAPE_ID_FL_TOO_COMPLEX
33
+ // The object is backed by a `st_table`.
34
+
35
+ enum shape_id_fl_type {
36
+ #define RBIMPL_SHAPE_ID_FL(n) (1<<(SHAPE_ID_FL_USHIFT+n))
37
+
38
+ SHAPE_ID_HEAP_INDEX_MASK = RBIMPL_SHAPE_ID_FL(0) | RBIMPL_SHAPE_ID_FL(1) | RBIMPL_SHAPE_ID_FL(2),
39
+
40
+ SHAPE_ID_FL_FROZEN = RBIMPL_SHAPE_ID_FL(3),
41
+ SHAPE_ID_FL_HAS_OBJECT_ID = RBIMPL_SHAPE_ID_FL(4),
42
+ SHAPE_ID_FL_TOO_COMPLEX = RBIMPL_SHAPE_ID_FL(5),
43
+
44
+ SHAPE_ID_FL_NON_CANONICAL_MASK = SHAPE_ID_FL_FROZEN | SHAPE_ID_FL_HAS_OBJECT_ID,
45
+ SHAPE_ID_FLAGS_MASK = SHAPE_ID_HEAP_INDEX_MASK | SHAPE_ID_FL_NON_CANONICAL_MASK | SHAPE_ID_FL_TOO_COMPLEX,
46
+
47
+ #undef RBIMPL_SHAPE_ID_FL
48
+ };
49
+
50
+ // This mask allows to check if a shape_id contains any ivar.
51
+ // It relies on ROOT_SHAPE_WITH_OBJ_ID==1.
52
+ enum shape_id_mask {
53
+ SHAPE_ID_HAS_IVAR_MASK = SHAPE_ID_FL_TOO_COMPLEX | (SHAPE_ID_OFFSET_MASK - 1),
54
+ };
55
+
56
+ // The interpreter doesn't care about frozen status or slot size when reading ivars.
57
+ // So we normalize shape_id by clearing these bits to improve cache hits.
58
+ // JITs however might care about it.
59
+ #define SHAPE_ID_READ_ONLY_MASK (~(SHAPE_ID_FL_FROZEN | SHAPE_ID_HEAP_INDEX_MASK))
60
+
61
+ typedef uint32_t redblack_id_t;
62
+
63
+ #define SHAPE_MAX_FIELDS (attr_index_t)(-1)
64
+ #define SHAPE_FLAG_SHIFT ((SIZEOF_VALUE * CHAR_BIT) - SHAPE_ID_NUM_BITS)
65
+ #define SHAPE_FLAG_MASK (((VALUE)-1) >> SHAPE_ID_NUM_BITS)
66
+
67
+ #define SHAPE_MAX_VARIATIONS 8
68
+
69
+ #define INVALID_SHAPE_ID ((shape_id_t)-1)
70
+ #define ATTR_INDEX_NOT_SET ((attr_index_t)-1)
71
+
72
+ #define ROOT_SHAPE_ID 0x0
73
+ #define ROOT_SHAPE_WITH_OBJ_ID 0x1
74
+ #define ROOT_TOO_COMPLEX_SHAPE_ID (ROOT_SHAPE_ID | SHAPE_ID_FL_TOO_COMPLEX)
75
+ #define ROOT_TOO_COMPLEX_WITH_OBJ_ID (ROOT_SHAPE_WITH_OBJ_ID | SHAPE_ID_FL_TOO_COMPLEX | SHAPE_ID_FL_HAS_OBJECT_ID)
76
+
77
+ typedef struct redblack_node redblack_node_t;
78
+
79
+ struct rb_shape {
80
+ VALUE edges; // id_table from ID (ivar) to next shape
81
+ ID edge_name; // ID (ivar) for transition from parent to rb_shape
82
+ redblack_node_t *ancestor_index;
83
+ shape_id_t parent_id;
84
+ attr_index_t next_field_index; // Fields are either ivars or internal properties like `object_id`
85
+ attr_index_t capacity; // Total capacity of the object with this shape
86
+ uint8_t type;
87
+ };
88
+
89
+ typedef struct rb_shape rb_shape_t;
90
+
91
+ struct redblack_node {
92
+ ID key;
93
+ rb_shape_t *value;
94
+ redblack_id_t l;
95
+ redblack_id_t r;
96
+ };
97
+
98
+ enum shape_type {
99
+ SHAPE_ROOT,
100
+ SHAPE_IVAR,
101
+ SHAPE_OBJ_ID,
102
+ };
103
+
104
+ enum shape_flags {
105
+ SHAPE_FL_FROZEN = 1 << 0,
106
+ SHAPE_FL_HAS_OBJECT_ID = 1 << 1,
107
+ SHAPE_FL_TOO_COMPLEX = 1 << 2,
108
+
109
+ SHAPE_FL_NON_CANONICAL_MASK = SHAPE_FL_FROZEN | SHAPE_FL_HAS_OBJECT_ID,
110
+ };
111
+
112
+ typedef struct {
113
+ /* object shapes */
114
+ rb_shape_t *shape_list;
115
+ rb_shape_t *root_shape;
116
+ const attr_index_t *capacities;
117
+ rb_atomic_t next_shape_id;
118
+
119
+ redblack_node_t *shape_cache;
120
+ unsigned int cache_size;
121
+ } rb_shape_tree_t;
122
+
123
+ RUBY_SYMBOL_EXPORT_BEGIN
124
+ RUBY_EXTERN rb_shape_tree_t rb_shape_tree;
125
+ RUBY_SYMBOL_EXPORT_END
126
+
127
+ static inline shape_id_t
128
+ rb_shapes_count(void)
129
+ {
130
+ return (shape_id_t)RUBY_ATOMIC_LOAD(rb_shape_tree.next_shape_id);
131
+ }
132
+
133
+ union rb_attr_index_cache {
134
+ uint64_t pack;
135
+ struct {
136
+ shape_id_t shape_id;
137
+ attr_index_t index;
138
+ } unpack;
139
+ };
140
+
141
+ static inline shape_id_t
142
+ RBASIC_SHAPE_ID(VALUE obj)
143
+ {
144
+ RUBY_ASSERT(!RB_SPECIAL_CONST_P(obj));
145
+ RUBY_ASSERT(!RB_TYPE_P(obj, T_IMEMO) || IMEMO_TYPE_P(obj, imemo_fields));
146
+ #if RBASIC_SHAPE_ID_FIELD
147
+ return (shape_id_t)((RBASIC(obj)->shape_id));
148
+ #else
149
+ return (shape_id_t)((RBASIC(obj)->flags) >> SHAPE_FLAG_SHIFT);
150
+ #endif
151
+ }
152
+
153
+ // Same as RBASIC_SHAPE_ID but with flags that have no impact
154
+ // on reads removed. e.g. Remove FL_FROZEN.
155
+ static inline shape_id_t
156
+ RBASIC_SHAPE_ID_FOR_READ(VALUE obj)
157
+ {
158
+ return RBASIC_SHAPE_ID(obj) & SHAPE_ID_READ_ONLY_MASK;
159
+ }
160
+
161
+ #if RUBY_DEBUG
162
+ bool rb_shape_verify_consistency(VALUE obj, shape_id_t shape_id);
163
+ #endif
164
+
165
+ static inline void
166
+ RBASIC_SET_SHAPE_ID_NO_CHECKS(VALUE obj, shape_id_t shape_id)
167
+ {
168
+ #if RBASIC_SHAPE_ID_FIELD
169
+ RBASIC(obj)->shape_id = (VALUE)shape_id;
170
+ #else
171
+ // Object shapes are occupying top bits
172
+ RBASIC(obj)->flags &= SHAPE_FLAG_MASK;
173
+ RBASIC(obj)->flags |= ((VALUE)(shape_id) << SHAPE_FLAG_SHIFT);
174
+ #endif
175
+ }
176
+
177
+ static inline void
178
+ RBASIC_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
179
+ {
180
+ RUBY_ASSERT(!RB_SPECIAL_CONST_P(obj));
181
+ RUBY_ASSERT(!RB_TYPE_P(obj, T_IMEMO) || IMEMO_TYPE_P(obj, imemo_fields));
182
+
183
+ RBASIC_SET_SHAPE_ID_NO_CHECKS(obj, shape_id);
184
+
185
+ RUBY_ASSERT(rb_shape_verify_consistency(obj, shape_id));
186
+ }
187
+
188
+ void rb_set_boxed_class_shape_id(VALUE obj, shape_id_t shape_id);
189
+
190
+ static inline void
191
+ RB_SET_SHAPE_ID(VALUE obj, shape_id_t shape_id)
192
+ {
193
+ switch (BUILTIN_TYPE(obj)) {
194
+ case T_CLASS:
195
+ case T_MODULE:
196
+ rb_set_boxed_class_shape_id(obj, shape_id);
197
+ break;
198
+ default:
199
+ RBASIC_SET_SHAPE_ID(obj, shape_id);
200
+ break;
201
+ }
202
+ }
203
+
204
+ static inline rb_shape_t *
205
+ RSHAPE(shape_id_t shape_id)
206
+ {
207
+ uint32_t offset = (shape_id & SHAPE_ID_OFFSET_MASK);
208
+ RUBY_ASSERT(offset != INVALID_SHAPE_ID);
209
+
210
+ return &rb_shape_tree.shape_list[offset];
211
+ }
212
+
213
+ int32_t rb_shape_id_offset(void);
214
+
215
+ RUBY_FUNC_EXPORTED shape_id_t rb_obj_shape_id(VALUE obj);
216
+ shape_id_t rb_shape_get_next_iv_shape(shape_id_t shape_id, ID id);
217
+ bool rb_shape_get_iv_index(shape_id_t shape_id, ID id, attr_index_t *value);
218
+ bool rb_shape_get_iv_index_with_hint(shape_id_t shape_id, ID id, attr_index_t *value, shape_id_t *shape_id_hint);
219
+ bool rb_shape_find_ivar(shape_id_t shape_id, ID id, shape_id_t *ivar_shape);
220
+
221
+ typedef int rb_shape_foreach_transition_callback(shape_id_t shape_id, void *data);
222
+ bool rb_shape_foreach_field(shape_id_t shape_id, rb_shape_foreach_transition_callback func, void *data);
223
+
224
+ shape_id_t rb_shape_transition_frozen(VALUE obj);
225
+ shape_id_t rb_shape_transition_complex(VALUE obj);
226
+ shape_id_t rb_shape_transition_remove_ivar(VALUE obj, ID id, shape_id_t *removed_shape_id);
227
+ shape_id_t rb_shape_transition_add_ivar(VALUE obj, ID id);
228
+ shape_id_t rb_shape_transition_add_ivar_no_warnings(VALUE klass, shape_id_t original_shape_id, ID id);
229
+ shape_id_t rb_shape_transition_object_id(VALUE obj);
230
+ shape_id_t rb_shape_transition_heap(VALUE obj, size_t heap_index);
231
+ shape_id_t rb_shape_object_id(shape_id_t original_shape_id);
232
+
233
+ void rb_shape_free_all(void);
234
+
235
+ shape_id_t rb_shape_rebuild(shape_id_t initial_shape_id, shape_id_t dest_shape_id);
236
+ void rb_shape_copy_fields(VALUE dest, VALUE *dest_buf, shape_id_t dest_shape_id, VALUE *src_buf, shape_id_t src_shape_id);
237
+ void rb_shape_copy_complex_ivars(VALUE dest, VALUE obj, shape_id_t src_shape_id, st_table *fields_table);
238
+
239
+ static inline bool
240
+ rb_shape_too_complex_p(shape_id_t shape_id)
241
+ {
242
+ return shape_id & SHAPE_ID_FL_TOO_COMPLEX;
243
+ }
244
+
245
+ static inline bool
246
+ rb_shape_obj_too_complex_p(VALUE obj)
247
+ {
248
+ return !RB_SPECIAL_CONST_P(obj) && rb_shape_too_complex_p(RBASIC_SHAPE_ID(obj));
249
+ }
250
+
251
+ static inline bool
252
+ rb_shape_has_object_id(shape_id_t shape_id)
253
+ {
254
+ return shape_id & SHAPE_ID_FL_HAS_OBJECT_ID;
255
+ }
256
+
257
+ static inline bool
258
+ rb_shape_canonical_p(shape_id_t shape_id)
259
+ {
260
+ return !(shape_id & SHAPE_ID_FL_NON_CANONICAL_MASK);
261
+ }
262
+
263
+ static inline uint8_t
264
+ rb_shape_heap_index(shape_id_t shape_id)
265
+ {
266
+ return (uint8_t)((shape_id & SHAPE_ID_HEAP_INDEX_MASK) >> SHAPE_ID_HEAP_INDEX_OFFSET);
267
+ }
268
+
269
+ static inline shape_id_t
270
+ rb_shape_root(size_t heap_id)
271
+ {
272
+ shape_id_t heap_index = (shape_id_t)(heap_id + 1);
273
+ shape_id_t heap_flags = heap_index << SHAPE_ID_HEAP_INDEX_OFFSET;
274
+
275
+ RUBY_ASSERT((heap_flags & SHAPE_ID_HEAP_INDEX_MASK) == heap_flags);
276
+ RUBY_ASSERT(rb_shape_heap_index(heap_flags) == heap_index);
277
+
278
+ return ROOT_SHAPE_ID | heap_flags;
279
+ }
280
+
281
+ static inline shape_id_t
282
+ RSHAPE_PARENT_RAW_ID(shape_id_t shape_id)
283
+ {
284
+ return RSHAPE(shape_id)->parent_id;
285
+ }
286
+
287
+ static inline bool
288
+ RSHAPE_DIRECT_CHILD_P(shape_id_t parent_id, shape_id_t child_id)
289
+ {
290
+ return (parent_id & SHAPE_ID_FLAGS_MASK) == (child_id & SHAPE_ID_FLAGS_MASK) &&
291
+ RSHAPE(child_id)->parent_id == (parent_id & SHAPE_ID_OFFSET_MASK);
292
+ }
293
+
294
+ static inline enum shape_type
295
+ RSHAPE_TYPE(shape_id_t shape_id)
296
+ {
297
+ return RSHAPE(shape_id)->type;
298
+ }
299
+
300
+ static inline bool
301
+ RSHAPE_TYPE_P(shape_id_t shape_id, enum shape_type type)
302
+ {
303
+ return RSHAPE_TYPE(shape_id) == type;
304
+ }
305
+
306
+ static inline attr_index_t
307
+ RSHAPE_EMBEDDED_CAPACITY(shape_id_t shape_id)
308
+ {
309
+ uint8_t heap_index = rb_shape_heap_index(shape_id);
310
+ if (heap_index) {
311
+ return rb_shape_tree.capacities[heap_index - 1];
312
+ }
313
+ return 0;
314
+ }
315
+
316
+ static inline attr_index_t
317
+ RSHAPE_CAPACITY(shape_id_t shape_id)
318
+ {
319
+ attr_index_t embedded_capacity = RSHAPE_EMBEDDED_CAPACITY(shape_id);
320
+
321
+ if (embedded_capacity > RSHAPE(shape_id)->capacity) {
322
+ return embedded_capacity;
323
+ }
324
+ else {
325
+ return RSHAPE(shape_id)->capacity;
326
+ }
327
+ }
328
+
329
+ static inline attr_index_t
330
+ RSHAPE_LEN(shape_id_t shape_id)
331
+ {
332
+ return RSHAPE(shape_id)->next_field_index;
333
+ }
334
+
335
+ static inline attr_index_t
336
+ RSHAPE_INDEX(shape_id_t shape_id)
337
+ {
338
+ RUBY_ASSERT(RSHAPE_LEN(shape_id) > 0);
339
+ return RSHAPE_LEN(shape_id) - 1;
340
+ }
341
+
342
+ static inline ID
343
+ RSHAPE_EDGE_NAME(shape_id_t shape_id)
344
+ {
345
+ return RSHAPE(shape_id)->edge_name;
346
+ }
347
+
348
+ static inline uint32_t
349
+ ROBJECT_FIELDS_CAPACITY(VALUE obj)
350
+ {
351
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
352
+ // Asking for capacity doesn't make sense when the object is using
353
+ // a hash table for storing instance variables
354
+ RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));
355
+ return RSHAPE_CAPACITY(RBASIC_SHAPE_ID(obj));
356
+ }
357
+
358
+ static inline st_table *
359
+ ROBJECT_FIELDS_HASH(VALUE obj)
360
+ {
361
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
362
+ RUBY_ASSERT(rb_shape_obj_too_complex_p(obj));
363
+ RUBY_ASSERT(FL_TEST_RAW(obj, ROBJECT_HEAP));
364
+
365
+ return (st_table *)ROBJECT(obj)->as.heap.fields;
366
+ }
367
+
368
+ static inline void
369
+ ROBJECT_SET_FIELDS_HASH(VALUE obj, const st_table *tbl)
370
+ {
371
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
372
+ RUBY_ASSERT(rb_shape_obj_too_complex_p(obj));
373
+ RUBY_ASSERT(FL_TEST_RAW(obj, ROBJECT_HEAP));
374
+
375
+ ROBJECT(obj)->as.heap.fields = (VALUE *)tbl;
376
+ }
377
+
378
+ static inline uint32_t
379
+ ROBJECT_FIELDS_COUNT_COMPLEX(VALUE obj)
380
+ {
381
+ return (uint32_t)rb_st_table_size(ROBJECT_FIELDS_HASH(obj));
382
+ }
383
+
384
+ static inline uint32_t
385
+ ROBJECT_FIELDS_COUNT_NOT_COMPLEX(VALUE obj)
386
+ {
387
+ RBIMPL_ASSERT_TYPE(obj, RUBY_T_OBJECT);
388
+ RUBY_ASSERT(!rb_shape_obj_too_complex_p(obj));
389
+ return RSHAPE(RBASIC_SHAPE_ID(obj))->next_field_index;
390
+ }
391
+
392
+ static inline uint32_t
393
+ ROBJECT_FIELDS_COUNT(VALUE obj)
394
+ {
395
+ if (rb_shape_obj_too_complex_p(obj)) {
396
+ return ROBJECT_FIELDS_COUNT_COMPLEX(obj);
397
+ }
398
+ else {
399
+ return ROBJECT_FIELDS_COUNT_NOT_COMPLEX(obj);
400
+ }
401
+ }
402
+
403
+ static inline uint32_t
404
+ RBASIC_FIELDS_COUNT(VALUE obj)
405
+ {
406
+ return RSHAPE(RBASIC_SHAPE_ID(obj))->next_field_index;
407
+ }
408
+
409
+ static inline bool
410
+ rb_shape_obj_has_id(VALUE obj)
411
+ {
412
+ return rb_shape_has_object_id(RBASIC_SHAPE_ID(obj));
413
+ }
414
+
415
+ static inline bool
416
+ rb_shape_has_ivars(shape_id_t shape_id)
417
+ {
418
+ return shape_id & SHAPE_ID_HAS_IVAR_MASK;
419
+ }
420
+
421
+ static inline bool
422
+ rb_shape_obj_has_ivars(VALUE obj)
423
+ {
424
+ return rb_shape_has_ivars(RBASIC_SHAPE_ID(obj));
425
+ }
426
+
427
+ static inline bool
428
+ rb_shape_has_fields(shape_id_t shape_id)
429
+ {
430
+ return shape_id & (SHAPE_ID_OFFSET_MASK | SHAPE_ID_FL_TOO_COMPLEX);
431
+ }
432
+
433
+ static inline bool
434
+ rb_shape_obj_has_fields(VALUE obj)
435
+ {
436
+ return rb_shape_has_fields(RBASIC_SHAPE_ID(obj));
437
+ }
438
+
439
+ static inline bool
440
+ rb_obj_gen_fields_p(VALUE obj)
441
+ {
442
+ switch (TYPE(obj)) {
443
+ case T_NONE:
444
+ case T_OBJECT:
445
+ case T_CLASS:
446
+ case T_MODULE:
447
+ case T_IMEMO:
448
+ return false;
449
+ default:
450
+ break;
451
+ }
452
+ return rb_shape_obj_has_fields(obj);
453
+ }
454
+
455
+ // For ext/objspace
456
+ RUBY_SYMBOL_EXPORT_BEGIN
457
+ typedef void each_shape_callback(shape_id_t shape_id, void *data);
458
+ void rb_shape_each_shape_id(each_shape_callback callback, void *data);
459
+ size_t rb_shape_memsize(shape_id_t shape);
460
+ size_t rb_shape_edges_count(shape_id_t shape_id);
461
+ size_t rb_shape_depth(shape_id_t shape_id);
462
+ RUBY_SYMBOL_EXPORT_END
463
+
464
+ #endif
@@ -0,0 +1,21 @@
1
+ #ifndef RUBY_THREAD_NONE_H
2
+ #define RUBY_THREAD_NONE_H
3
+
4
+ #define RB_NATIVETHREAD_LOCK_INIT (void)(0)
5
+ #define RB_NATIVETHREAD_COND_INIT (void)(0)
6
+
7
+ // no-thread impl doesn't use TLS but define this to avoid using tls key
8
+ // based implementation in vm.c
9
+ #define RB_THREAD_LOCAL_SPECIFIER
10
+
11
+ struct rb_native_thread {
12
+ void *thread_id; // NULL
13
+ };
14
+
15
+ struct rb_thread_sched_item {};
16
+ struct rb_thread_sched {};
17
+
18
+ RUBY_EXTERN struct rb_execution_context_struct *ruby_current_ec;
19
+ NOINLINE(struct rb_execution_context_struct *rb_current_ec_noinline(void)); // for assertions
20
+
21
+ #endif /* RUBY_THREAD_NONE_H */
@@ -0,0 +1,177 @@
1
+ #ifndef RUBY_THREAD_PTHREAD_H
2
+ #define RUBY_THREAD_PTHREAD_H
3
+ /**********************************************************************
4
+
5
+ thread_pthread.h -
6
+
7
+ $Author$
8
+
9
+ Copyright (C) 2004-2007 Koichi Sasada
10
+
11
+ **********************************************************************/
12
+
13
+ #ifdef HAVE_PTHREAD_NP_H
14
+ #include <pthread_np.h>
15
+ #endif
16
+
17
+ #define RB_NATIVETHREAD_LOCK_INIT PTHREAD_MUTEX_INITIALIZER
18
+ #define RB_NATIVETHREAD_COND_INIT PTHREAD_COND_INITIALIZER
19
+
20
+ // TLS can not be accessed across .so on arm64 and perhaps ppc64le too.
21
+ #if defined(__arm64__) || defined(__aarch64__) || defined(__powerpc64__)
22
+ # define RB_THREAD_CURRENT_EC_NOINLINE
23
+ #endif
24
+
25
+ // this data should be protected by timer_th.waiting_lock
26
+ struct rb_thread_sched_waiting {
27
+ enum thread_sched_waiting_flag {
28
+ thread_sched_waiting_none = 0x00,
29
+ thread_sched_waiting_timeout = 0x01,
30
+ thread_sched_waiting_io_read = 0x02,
31
+ thread_sched_waiting_io_write = 0x08,
32
+ thread_sched_waiting_io_force = 0x40, // ignore readable
33
+ } flags;
34
+
35
+ struct {
36
+ // should be compat with hrtime.h
37
+ #ifdef MY_RUBY_BUILD_MAY_TIME_TRAVEL
38
+ int128_t timeout;
39
+ #else
40
+ uint64_t timeout;
41
+ #endif
42
+ uint32_t event_serial;
43
+ int fd; // -1 for timeout only
44
+ int result;
45
+ } data;
46
+
47
+ // connected to timer_th.waiting
48
+ struct ccan_list_node node;
49
+ };
50
+
51
+ // per-Thread scheduler helper data
52
+ struct rb_thread_sched_item {
53
+ struct {
54
+ struct ccan_list_node ubf;
55
+
56
+ // connected to ractor->threads.sched.reqdyq
57
+ // locked by ractor->threads.sched.lock
58
+ struct ccan_list_node readyq;
59
+
60
+ // connected to vm->ractor.sched.timeslice_threads
61
+ // locked by vm->ractor.sched.lock
62
+ struct ccan_list_node timeslice_threads;
63
+
64
+ // connected to vm->ractor.sched.running_threads
65
+ // locked by vm->ractor.sched.lock
66
+ struct ccan_list_node running_threads;
67
+
68
+ // connected to vm->ractor.sched.zombie_threads
69
+ struct ccan_list_node zombie_threads;
70
+ } node;
71
+
72
+ struct rb_thread_sched_waiting waiting_reason;
73
+ uint32_t event_serial;
74
+
75
+ bool finished;
76
+ bool malloc_stack;
77
+ void *context_stack;
78
+ struct coroutine_context *context;
79
+ };
80
+
81
+ struct rb_native_thread {
82
+ rb_atomic_t serial;
83
+ struct rb_vm_struct *vm;
84
+
85
+ rb_nativethread_id_t thread_id;
86
+
87
+ #ifdef RB_THREAD_T_HAS_NATIVE_ID
88
+ int tid;
89
+ #endif
90
+
91
+ struct rb_thread_struct *running_thread;
92
+
93
+ // to control native thread
94
+ #if defined(__GLIBC__) || defined(__FreeBSD__)
95
+ union
96
+ #else
97
+ /*
98
+ * assume the platform condvars are badly implemented and have a
99
+ * "memory" of which mutex they're associated with
100
+ */
101
+ struct
102
+ #endif
103
+ {
104
+ rb_nativethread_cond_t intr; /* th->interrupt_lock */
105
+ rb_nativethread_cond_t readyq; /* use sched->lock */
106
+ } cond;
107
+
108
+ #ifdef USE_SIGALTSTACK
109
+ void *altstack;
110
+ #endif
111
+
112
+ struct coroutine_context *nt_context;
113
+ int dedicated;
114
+
115
+ size_t machine_stack_maxsize;
116
+ };
117
+
118
+ #undef except
119
+ #undef try
120
+ #undef leave
121
+ #undef finally
122
+
123
+ // per-Ractor
124
+ struct rb_thread_sched {
125
+ rb_nativethread_lock_t lock_;
126
+ #if VM_CHECK_MODE
127
+ struct rb_thread_struct *lock_owner;
128
+ #endif
129
+ struct rb_thread_struct *running; // running thread or NULL
130
+ bool is_running;
131
+ bool is_running_timeslice;
132
+ bool enable_mn_threads;
133
+
134
+ struct ccan_list_head readyq;
135
+ int readyq_cnt;
136
+ // ractor scheduling
137
+ struct ccan_list_node grq_node;
138
+ };
139
+
140
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
141
+ NOINLINE(void rb_current_ec_set(struct rb_execution_context_struct *));
142
+
143
+ # ifdef RB_THREAD_CURRENT_EC_NOINLINE
144
+ NOINLINE(struct rb_execution_context_struct *rb_current_ec(void));
145
+ # else
146
+ RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER struct rb_execution_context_struct *ruby_current_ec;
147
+
148
+ // for RUBY_DEBUG_LOG()
149
+ RUBY_EXTERN RB_THREAD_LOCAL_SPECIFIER rb_atomic_t ruby_nt_serial;
150
+ #define RUBY_NT_SERIAL 1
151
+ # endif
152
+ #else
153
+ typedef pthread_key_t native_tls_key_t;
154
+
155
+ static inline void *
156
+ native_tls_get(native_tls_key_t key)
157
+ {
158
+ // return value should be checked by caller
159
+ return pthread_getspecific(key);
160
+ }
161
+
162
+ static inline void
163
+ native_tls_set(native_tls_key_t key, void *ptr)
164
+ {
165
+ if (UNLIKELY(pthread_setspecific(key, ptr) != 0)) {
166
+ rb_bug("pthread_setspecific error");
167
+ }
168
+ }
169
+
170
+ RUBY_EXTERN native_tls_key_t ruby_current_ec_key;
171
+ #endif
172
+
173
+ struct rb_ractor_struct;
174
+ void rb_ractor_sched_wait(struct rb_execution_context_struct *ec, struct rb_ractor_struct *cr, rb_unblock_function_t *ubf, void *ptr);
175
+ void rb_ractor_sched_wakeup(struct rb_ractor_struct *r, struct rb_thread_struct *th);
176
+
177
+ #endif /* RUBY_THREAD_PTHREAD_H */