debase-ruby_core_source 4.0.1 → 4.1.0.preview1

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 (200) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/addr2line.h +22 -0
  4. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/builtin.h +127 -0
  5. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/build_assert/build_assert.h +40 -0
  6. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/check_type/check_type.h +63 -0
  7. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/container_of/container_of.h +142 -0
  8. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/list/list.h +791 -0
  9. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ccan/str/str.h +17 -0
  10. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/constant.h +53 -0
  11. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/darray.h +295 -0
  12. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/debug_counter.h +428 -0
  13. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/dln.h +33 -0
  14. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/encindex.h +70 -0
  15. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/eval_intern.h +356 -0
  16. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/hrtime.h +237 -0
  17. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/id.h +365 -0
  18. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/id_table.h +74 -0
  19. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/insns.inc +315 -0
  20. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/insns_info.inc +11637 -0
  21. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/array.h +158 -0
  22. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/basic_operators.h +67 -0
  23. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/bignum.h +249 -0
  24. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/bits.h +647 -0
  25. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/box.h +103 -0
  26. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/class.h +797 -0
  27. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/cmdlineopt.h +64 -0
  28. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compar.h +30 -0
  29. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compile.h +34 -0
  30. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/compilers.h +104 -0
  31. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/complex.h +29 -0
  32. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/concurrent_set.h +21 -0
  33. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/cont.h +33 -0
  34. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/coverage.h +51 -0
  35. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/dir.h +16 -0
  36. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enc.h +19 -0
  37. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/encoding.h +40 -0
  38. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enum.h +18 -0
  39. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/enumerator.h +21 -0
  40. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/error.h +287 -0
  41. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/eval.h +43 -0
  42. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/file.h +40 -0
  43. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/fixnum.h +185 -0
  44. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/gc.h +411 -0
  45. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/hash.h +220 -0
  46. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/imemo.h +302 -0
  47. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/inits.h +54 -0
  48. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/io.h +167 -0
  49. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/io_buffer.h +36 -0
  50. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/jit.h +23 -0
  51. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/load.h +20 -0
  52. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/loadpath.h +16 -0
  53. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/marshal.h +17 -0
  54. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/math.h +23 -0
  55. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/missing.h +19 -0
  56. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/numeric.h +326 -0
  57. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/object.h +88 -0
  58. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/objspace.h +24 -0
  59. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/parse.h +131 -0
  60. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/proc.h +34 -0
  61. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/process.h +124 -0
  62. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/ractor.h +9 -0
  63. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/random.h +17 -0
  64. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/range.h +46 -0
  65. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/rational.h +92 -0
  66. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/re.h +87 -0
  67. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/ruby_parser.h +109 -0
  68. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/sanitizers.h +346 -0
  69. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/scheduler.h +7 -0
  70. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/serial.h +23 -0
  71. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/set.h +20 -0
  72. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/set_table.h +77 -0
  73. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/signal.h +25 -0
  74. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/simd.h +18 -0
  75. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/st.h +32 -0
  76. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/static_assert.h +16 -0
  77. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/string.h +240 -0
  78. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/struct.h +120 -0
  79. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/symbol.h +46 -0
  80. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/thread.h +108 -0
  81. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/time.h +34 -0
  82. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/transcode.h +23 -0
  83. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/util.h +27 -0
  84. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/variable.h +81 -0
  85. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/vm.h +144 -0
  86. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/vm_map.h +95 -0
  87. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal/warnings.h +16 -0
  88. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/internal.h +106 -0
  89. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/iseq.h +439 -0
  90. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/known_errors.inc +1419 -0
  91. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/method.h +279 -0
  92. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/node.h +122 -0
  93. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/node_name.inc +224 -0
  94. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/optinsn.inc +128 -0
  95. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/optunifs.inc +41 -0
  96. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parse.h +246 -0
  97. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_bits.h +647 -0
  98. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_node.h +32 -0
  99. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_st.h +161 -0
  100. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/parser_value.h +116 -0
  101. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/arena.h +37 -0
  102. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/ast.h +10371 -0
  103. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/buffer.h +52 -0
  104. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/comments.h +43 -0
  105. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/accel.h +19 -0
  106. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/align.h +36 -0
  107. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/assume.h +25 -0
  108. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/exported.h +24 -0
  109. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/fallthrough.h +22 -0
  110. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/filesystem.h +32 -0
  111. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/flex_array.h +19 -0
  112. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/force_inline.h +21 -0
  113. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/format.h +25 -0
  114. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/inline.h +17 -0
  115. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nodiscard.h +22 -0
  116. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/nonnull.h +18 -0
  117. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/compiler/unused.h +18 -0
  118. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/constant_pool.h +81 -0
  119. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/diagnostic.h +93 -0
  120. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/errors_format.h +53 -0
  121. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/excludes.h +29 -0
  122. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/extension.h +19 -0
  123. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/integer.h +41 -0
  124. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/allocator.h +68 -0
  125. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/allocator_debug.h +88 -0
  126. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/arena.h +108 -0
  127. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/bit.h +42 -0
  128. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/buffer.h +91 -0
  129. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/char.h +139 -0
  130. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/comments.h +20 -0
  131. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/constant_pool.h +152 -0
  132. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/diagnostic.h +389 -0
  133. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/encoding.h +242 -0
  134. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/integer.h +68 -0
  135. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/isinf.h +16 -0
  136. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/line_offset_list.h +34 -0
  137. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/list.h +62 -0
  138. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/magic_comments.h +23 -0
  139. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/memchr.h +15 -0
  140. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/node.h +32 -0
  141. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/options.h +224 -0
  142. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/parser.h +971 -0
  143. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/regexp.h +42 -0
  144. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/serialize.h +39 -0
  145. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/source.h +72 -0
  146. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/static_literals.h +100 -0
  147. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/stringy.h +35 -0
  148. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/strncasecmp.h +18 -0
  149. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/strpbrk.h +33 -0
  150. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/internal/tokens.h +11 -0
  151. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/json.h +32 -0
  152. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/line_offset_list.h +61 -0
  153. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/magic_comments.h +35 -0
  154. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/node.h +94 -0
  155. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/options.h +335 -0
  156. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/parser.h +348 -0
  157. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/prettyprint.h +31 -0
  158. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/prism.h +131 -0
  159. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/serialize.h +115 -0
  160. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/source.h +155 -0
  161. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/stream.h +28 -0
  162. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/string_query.h +63 -0
  163. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/stringy.h +72 -0
  164. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism/version.h +38 -0
  165. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism_compile.h +204 -0
  166. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/prism_xallocator.h +6 -0
  167. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/probes_helper.h +42 -0
  168. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ractor_core.h +421 -0
  169. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regenc.h +261 -0
  170. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regint.h +983 -0
  171. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/regparse.h +371 -0
  172. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/revision.h +5 -0
  173. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ruby_assert.h +14 -0
  174. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/ruby_atomic.h +115 -0
  175. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/rubyparser.h +1389 -0
  176. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/shape.h +733 -0
  177. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/siphash.h +48 -0
  178. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/symbol.h +116 -0
  179. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_none.h +25 -0
  180. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_pthread.h +63 -0
  181. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_sched.h +271 -0
  182. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/thread_win32.h +48 -0
  183. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/timev.h +58 -0
  184. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/transcode_data.h +138 -0
  185. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/variable.h +26 -0
  186. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/version.h +69 -0
  187. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm.inc +6457 -0
  188. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_call_iseq_optimized.inc +244 -0
  189. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_callinfo.h +688 -0
  190. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_core.h +2509 -0
  191. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_debug.h +124 -0
  192. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_exec.h +202 -0
  193. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_insnhelper.h +280 -0
  194. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_opts.h +65 -0
  195. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vm_sync.h +160 -0
  196. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/vmtc.inc +302 -0
  197. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/yjit.h +87 -0
  198. data/lib/debase/ruby_core_source/ruby-4.1.0-preview1/zjit.h +221 -0
  199. data/lib/debase/ruby_core_source/version.rb +1 -1
  200. metadata +2930 -2724
@@ -0,0 +1,204 @@
1
+ #include "prism/prism.h"
2
+ #include "ruby/encoding.h"
3
+
4
+ /**
5
+ * the getlocal and setlocal instructions require two parameters. level is how
6
+ * many hops up the iseq stack one needs to go before finding the correct local
7
+ * table. The index is the index in that table where our variable is.
8
+ *
9
+ * Because these are always calculated and used together, we'll bind them
10
+ * together as a tuple.
11
+ */
12
+ typedef struct pm_local_index_struct {
13
+ int index, level;
14
+ } pm_local_index_t;
15
+
16
+ // A declaration for the struct that lives in compile.c.
17
+ struct iseq_link_anchor;
18
+ struct rb_code_location_struct;
19
+
20
+ /**
21
+ * A direct-indexed lookup table mapping constant IDs to local variable indices.
22
+ * Regular constant IDs (1..constants_size) index directly. Special forwarding
23
+ * parameter IDs (idMULT|FLAG, etc.) are mapped to 4 extra slots at the end.
24
+ *
25
+ * All lookups are O(1) — a single array dereference.
26
+ * The table is arena-allocated for child scopes (no explicit free needed).
27
+ */
28
+ typedef struct {
29
+ /** Array of local indices, indexed by constant_id. -1 means not present. */
30
+ int *values;
31
+
32
+ /** Total number of slots (constants_size + PM_INDEX_LOOKUP_SPECIALS). */
33
+ int capacity;
34
+
35
+ /** Whether the values array is heap-allocated and needs explicit free. */
36
+ bool owned;
37
+ } pm_index_lookup_table_t;
38
+
39
+ /** Number of extra slots for special forwarding parameter IDs. */
40
+ #define PM_INDEX_LOOKUP_SPECIALS 4
41
+
42
+ /** Slot offsets for special forwarding parameters (relative to constants_size). */
43
+ #define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t) (1 << 31))
44
+ #define PM_INDEX_LOOKUP_SPECIAL_MULT 0
45
+ #define PM_INDEX_LOOKUP_SPECIAL_POW 1
46
+ #define PM_INDEX_LOOKUP_SPECIAL_AND 2
47
+ #define PM_INDEX_LOOKUP_SPECIAL_DOT3 3
48
+
49
+ /**
50
+ * Special constant IDs for forwarding parameters. These use bit 31 to
51
+ * distinguish them from regular prism constant pool IDs. The lower bits
52
+ * encode which special slot (0-3) they map to in the lookup table.
53
+ */
54
+ #define PM_CONSTANT_MULT ((pm_constant_id_t) (PM_SPECIAL_CONSTANT_FLAG | PM_INDEX_LOOKUP_SPECIAL_MULT))
55
+ #define PM_CONSTANT_POW ((pm_constant_id_t) (PM_SPECIAL_CONSTANT_FLAG | PM_INDEX_LOOKUP_SPECIAL_POW))
56
+ #define PM_CONSTANT_AND ((pm_constant_id_t) (PM_SPECIAL_CONSTANT_FLAG | PM_INDEX_LOOKUP_SPECIAL_AND))
57
+ #define PM_CONSTANT_DOT3 ((pm_constant_id_t) (PM_SPECIAL_CONSTANT_FLAG | PM_INDEX_LOOKUP_SPECIAL_DOT3))
58
+
59
+ static inline int
60
+ pm_index_lookup_table_index(const pm_index_lookup_table_t *table, pm_constant_id_t key)
61
+ {
62
+ if (LIKELY(!(key & PM_SPECIAL_CONSTANT_FLAG))) {
63
+ return (int) key - 1;
64
+ }
65
+ return table->capacity - PM_INDEX_LOOKUP_SPECIALS + (int)(key & ~PM_SPECIAL_CONSTANT_FLAG);
66
+ }
67
+
68
+ static inline void
69
+ pm_index_lookup_table_insert(pm_index_lookup_table_t *table, pm_constant_id_t key, int value)
70
+ {
71
+ int idx = pm_index_lookup_table_index(table, key);
72
+ RUBY_ASSERT(idx >= 0 && idx < table->capacity);
73
+ table->values[idx] = value;
74
+ }
75
+
76
+ static inline int
77
+ pm_index_lookup_table_lookup(const pm_index_lookup_table_t *table, pm_constant_id_t key, int *value)
78
+ {
79
+ int idx = pm_index_lookup_table_index(table, key);
80
+ RUBY_ASSERT(idx >= 0 && idx < table->capacity);
81
+ if (table->values[idx] == -1) return 0;
82
+ *value = table->values[idx];
83
+ return 1;
84
+ }
85
+
86
+ static inline void
87
+ pm_index_lookup_table_init_heap(pm_index_lookup_table_t *table, int constants_size)
88
+ {
89
+ int cap = constants_size + PM_INDEX_LOOKUP_SPECIALS;
90
+ table->values = (int *) ruby_xmalloc(cap * sizeof(int));
91
+ memset(table->values, -1, cap * sizeof(int));
92
+ table->capacity = cap;
93
+ table->owned = true;
94
+ }
95
+
96
+ // ScopeNodes are helper nodes, and will never be part of the AST. We manually
97
+ // declare them here to avoid generating them.
98
+ typedef struct pm_scope_node {
99
+ pm_node_t base;
100
+ struct pm_scope_node *previous;
101
+ pm_node_t *ast_node;
102
+ pm_node_t *parameters;
103
+ pm_node_t *body;
104
+ pm_constant_id_list_t locals;
105
+
106
+ const pm_parser_t *parser;
107
+
108
+ /** The source hash of the parsed source, propagated to every iseq. */
109
+ uint64_t source_hash;
110
+ const pm_options_t *options;
111
+ const pm_line_offset_list_t *line_offsets;
112
+ int32_t start_line;
113
+ rb_encoding *encoding;
114
+
115
+ /**
116
+ * This is a pointer to the list of script lines for the ISEQs that will be
117
+ * associated with this scope node. It is only set if
118
+ * RubyVM.keep_script_lines is true. If it is set, it will be set to a
119
+ * pointer to an array that is always stack allocated (so no GC marking is
120
+ * needed by this struct). If it is not set, it will be NULL. It is
121
+ * inherited by all child scopes.
122
+ */
123
+ VALUE *script_lines;
124
+
125
+ /**
126
+ * This is the encoding of the actual filepath object that will be used when
127
+ * a __FILE__ node is compiled or when the path has to be set on a syntax
128
+ * error.
129
+ */
130
+ rb_encoding *filepath_encoding;
131
+
132
+ // The size of the local table on the iseq which includes locals and hidden
133
+ // variables.
134
+ int local_table_for_iseq_size;
135
+
136
+ ID *constants;
137
+
138
+ /**
139
+ * A flat lookup table mapping constant IDs (or special IDs) to local
140
+ * variable indices. When allocated from the compile data arena (child
141
+ * scopes), no explicit free is needed. When heap-allocated (top-level
142
+ * scope in pm_parse_process), owned is set to true so destroy can free it.
143
+ */
144
+ pm_index_lookup_table_t index_lookup_table;
145
+
146
+ // The current coverage setting, passed down through the various scopes.
147
+ int coverage_enabled;
148
+
149
+ /**
150
+ * This will only be set on the top-level scope node. It will contain all of
151
+ * the instructions pertaining to BEGIN{} nodes.
152
+ */
153
+ struct iseq_link_anchor *pre_execution_anchor;
154
+
155
+ /**
156
+ * Cached line hint for line offset list lookups. Since the compiler walks
157
+ * the AST roughly in source order, consecutive lookups tend to be for
158
+ * nearby byte offsets. This avoids repeated binary searches.
159
+ */
160
+ size_t last_line;
161
+ } pm_scope_node_t;
162
+
163
+ void pm_scope_node_init(const pm_node_t *node, pm_scope_node_t *scope, pm_scope_node_t *previous);
164
+ void pm_scope_node_destroy(pm_scope_node_t *scope_node);
165
+
166
+ typedef struct {
167
+ /** The arena allocator for AST-lifetime memory. */
168
+ pm_arena_t *arena;
169
+
170
+ /** The parser that will do the actual parsing. */
171
+ pm_parser_t *parser;
172
+
173
+ /** The options that will be passed to the parser. */
174
+ pm_options_t *options;
175
+
176
+ /** The source backing the parse (file, string, or stream). */
177
+ pm_source_t *source;
178
+
179
+ /** The resulting scope node that will hold the generated AST. */
180
+ pm_scope_node_t node;
181
+
182
+ /** Whether or not this parse result has performed its parsing yet. */
183
+ bool parsed;
184
+ } pm_parse_result_t;
185
+
186
+ void pm_parse_result_init(pm_parse_result_t *result);
187
+ VALUE pm_load_file(pm_parse_result_t *result, VALUE filepath, bool load_error);
188
+ VALUE pm_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
189
+ VALUE pm_load_parse_file(pm_parse_result_t *result, VALUE filepath, VALUE *script_lines);
190
+ VALUE pm_parse_string(pm_parse_result_t *result, VALUE source, VALUE filepath, VALUE *script_lines);
191
+ VALUE pm_parse_stdin(pm_parse_result_t *result);
192
+ void pm_options_version_for_current_ruby_set(pm_options_t *options);
193
+ void pm_parse_result_free(pm_parse_result_t *result);
194
+ bool pm_node_source_location(VALUE source, VALUE filepath, int start_line,
195
+ int node_id, struct rb_code_location_struct *location);
196
+
197
+ rb_iseq_t *pm_iseq_new(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, enum rb_iseq_type, int *error_state);
198
+ rb_iseq_t *pm_iseq_new_top(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, const rb_iseq_t *parent, int *error_state);
199
+ rb_iseq_t *pm_iseq_new_main(pm_scope_node_t *node, VALUE path, VALUE realpath, const rb_iseq_t *parent, int opt, int *error_state);
200
+ rb_iseq_t *pm_iseq_new_eval(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, int *error_state);
201
+ rb_iseq_t *pm_iseq_new_with_opt(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type, const rb_compile_option_t *option, int *error_state);
202
+ rb_iseq_t *pm_iseq_build(pm_scope_node_t *node, VALUE name, VALUE path, VALUE realpath, int first_lineno, const rb_iseq_t *parent, int isolated_depth, enum rb_iseq_type, const rb_compile_option_t *option);
203
+
204
+ VALUE pm_iseq_compile_node(rb_iseq_t *iseq, pm_scope_node_t *node);
@@ -0,0 +1,6 @@
1
+ #ifndef PRISM_XALLOCATOR_H
2
+ #define PRISM_XALLOCATOR_H
3
+
4
+ #include "ruby/internal/xmalloc.h"
5
+
6
+ #endif /* PRISM_XALLOCATOR_H */
@@ -0,0 +1,42 @@
1
+ #ifndef RUBY_PROBES_HELPER_H
2
+ #define RUBY_PROBES_HELPER_H
3
+
4
+ #include "ruby/ruby.h"
5
+
6
+ struct ruby_dtrace_method_hook_args {
7
+ const char *classname;
8
+ const char *methodname;
9
+ const char *filename;
10
+ int line_no;
11
+ volatile VALUE klass;
12
+ volatile VALUE name;
13
+ };
14
+
15
+ NOINLINE(int rb_dtrace_setup(rb_execution_context_t *, VALUE, ID, struct ruby_dtrace_method_hook_args *));
16
+
17
+ #define RUBY_DTRACE_METHOD_HOOK(name, ec, klazz, id) \
18
+ do { \
19
+ if (UNLIKELY(RUBY_DTRACE_##name##_ENABLED())) { \
20
+ struct ruby_dtrace_method_hook_args args; \
21
+ if (rb_dtrace_setup(ec, klazz, id, &args)) { \
22
+ RUBY_DTRACE_##name(args.classname, \
23
+ args.methodname, \
24
+ args.filename, \
25
+ args.line_no); \
26
+ } \
27
+ } \
28
+ } while (0)
29
+
30
+ #define RUBY_DTRACE_METHOD_ENTRY_HOOK(ec, klass, id) \
31
+ RUBY_DTRACE_METHOD_HOOK(METHOD_ENTRY, ec, klass, id)
32
+
33
+ #define RUBY_DTRACE_METHOD_RETURN_HOOK(ec, klass, id) \
34
+ RUBY_DTRACE_METHOD_HOOK(METHOD_RETURN, ec, klass, id)
35
+
36
+ #define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(ec, klass, id) \
37
+ RUBY_DTRACE_METHOD_HOOK(CMETHOD_ENTRY, ec, klass, id)
38
+
39
+ #define RUBY_DTRACE_CMETHOD_RETURN_HOOK(ec, klass, id) \
40
+ RUBY_DTRACE_METHOD_HOOK(CMETHOD_RETURN, ec, klass, id)
41
+
42
+ #endif /* RUBY_PROBES_HELPER_H */
@@ -0,0 +1,421 @@
1
+ #ifndef RUBY_RACTOR_CORE_H
2
+ #define RUBY_RACTOR_CORE_H
3
+ #include "internal/gc.h"
4
+ #include "internal/sanitizers.h"
5
+ #include "ruby/ruby.h"
6
+ #include "ruby/ractor.h"
7
+ #include "vm_core.h"
8
+ #include "id_table.h"
9
+ #include "vm_debug.h"
10
+ #include "hrtime.h"
11
+
12
+ #ifndef RACTOR_CHECK_MODE
13
+ #define RACTOR_CHECK_MODE (VM_CHECK_MODE || RUBY_DEBUG) && (SIZEOF_UINT64_T == SIZEOF_VALUE)
14
+ #endif
15
+
16
+ /* Record the registration-time VALUE in each rb_gc_register_address entry so the
17
+ * verifier can distinguish a transitioned cross-Ractor store from conservative
18
+ * garbage. Debug and ASAN builds only; production keeps one-word entries. */
19
+ #ifndef RB_GC_REGISTERED_ADDR_CHECK
20
+ # if RUBY_DEBUG || defined(RUBY_ASAN_ENABLED)
21
+ # define RB_GC_REGISTERED_ADDR_CHECK 1
22
+ # else
23
+ # define RB_GC_REGISTERED_ADDR_CHECK 0
24
+ # endif
25
+ #endif
26
+
27
+ // experimental flag because it is not sure it is the common pattern
28
+ #define RUBY_TYPED_FROZEN_SHAREABLE_NO_REC RUBY_FL_FINALIZE
29
+
30
+ /* An in-flight move payload, serialized off-heap (defined in ractor.c). */
31
+ struct rb_ractor_courier;
32
+
33
+ struct rb_ractor_sync {
34
+ // ractor lock
35
+ rb_nativethread_lock_t lock;
36
+
37
+ #if RACTOR_CHECK_MODE > 0
38
+ VALUE locked_by;
39
+ #endif
40
+
41
+ // incoming messages
42
+ struct ractor_queue *recv_queue;
43
+
44
+ // waiting threads for receiving
45
+ struct ccan_list_head waiters;
46
+
47
+ // ports
48
+ VALUE default_port_value;
49
+ struct st_table *ports;
50
+ size_t next_port_id;
51
+
52
+ /* The baskets this Ractor holds that are on no queue: one it is building to send,
53
+ * and one it has taken off a queue and is materializing. A queued basket is rooted
54
+ * by its queue instead. Only the owner touches this list. */
55
+ struct ccan_list_head off_queue_baskets;
56
+
57
+ // monitors
58
+ struct ccan_list_head monitors;
59
+
60
+ // value
61
+ rb_ractor_t *successor;
62
+ VALUE legacy;
63
+ bool legacy_exc;
64
+ bool legacy_taken; /* Ractor#value already returned the value */
65
+ };
66
+
67
+ struct ractor_basket;
68
+
69
+ // created
70
+ // | ready to run
71
+ // ====================== inserted to vm->ractor
72
+ // v
73
+ // blocking <---+ all threads are blocking
74
+ // | |
75
+ // v |
76
+ // running -----+
77
+ // | all threads are terminated.
78
+ // ====================== removed from vm->ractor
79
+ // v
80
+ // terminated
81
+ //
82
+ // status is protected by VM lock (global state)
83
+ enum ractor_status {
84
+ ractor_created,
85
+ ractor_running,
86
+ ractor_blocking,
87
+ ractor_terminated,
88
+ };
89
+
90
+ struct rb_ractor_registered_addr {
91
+ VALUE *addr;
92
+ #if RB_GC_REGISTERED_ADDR_CHECK
93
+ /* A raw provenance snapshot for verification only. Never mark or dereference it. */
94
+ VALUE initial_value;
95
+ #endif
96
+ };
97
+
98
+ struct rb_ractor_struct {
99
+ struct rb_ractor_pub pub;
100
+ struct rb_ractor_sync sync;
101
+
102
+ /* rb_gc_register_mark_object pins, per Ractor: the owner marks them (live via
103
+ * rb_ractor_mark_local_roots, unmerged zombie via the zombie scan) and a merge moves
104
+ * them to the survivor. Raw malloc, so a merge during sweep cannot re-enter GC. */
105
+ VALUE *registered_marks;
106
+ size_t registered_marks_cnt, registered_marks_capa;
107
+
108
+ struct rb_ractor_registered_addr *registered_addrs;
109
+ size_t registered_addrs_cnt, registered_addrs_capa;
110
+ bool registered_addrs_listed;
111
+
112
+ /* traversal-API mark redirect (NULL outside a traversal). Per Ractor so a
113
+ * concurrent traversal on another Ractor is never observed. A modular GC's
114
+ * Ractor-less marking worker threads read vm->gc.mark_func_data instead. */
115
+ struct gc_mark_func_data_struct *mark_func_data;
116
+
117
+ // thread management
118
+ struct {
119
+ struct ccan_list_head set;
120
+ unsigned int cnt;
121
+ unsigned int blocking_cnt;
122
+ unsigned int sleeper;
123
+ struct rb_thread_sched sched;
124
+ rb_execution_context_t *running_ec;
125
+ rb_thread_t *main;
126
+ // MN termination epilogue: keeps the dying thread marked (like a set
127
+ // member) between leaving the living set and its last use
128
+ rb_thread_t *dying_th;
129
+
130
+ // `main` is in rb_thread_terminate_all(), waiting for the others to go
131
+ bool terminating;
132
+ } threads;
133
+
134
+ /* Postponed jobs targeted at this Ractor
135
+ * (rb_postponed_job_trigger_for_ractor): bits index the VM-wide
136
+ * preregistration table; any of this Ractor's threads drains them
137
+ * in rb_postponed_job_flush. */
138
+ rb_atomic_t postponed_job_triggered_bits;
139
+
140
+ VALUE thgroup_default;
141
+
142
+ VALUE name;
143
+ VALUE loc;
144
+
145
+ enum ractor_status status_;
146
+
147
+ struct ccan_list_node vmlr_node;
148
+ bool in_terminated_set; /* vmlr_node is on vm->ractor.terminated_set */
149
+ /* The final self collection ran (ractor_postmortem_collect): from then on
150
+ * rb_ractor_mark_local_roots roots only the join value and the registered_marks
151
+ * pins, so the dying thread's own scaffolding can be collected. */
152
+ bool postmortem;
153
+
154
+ // ractor local data
155
+
156
+ rb_serial_t next_ec_serial;
157
+
158
+ st_table *local_storage;
159
+ struct rb_id_table *idkey_local_storage;
160
+ VALUE local_storage_store_lock;
161
+
162
+ /* 0 until first use: rb_ractor_stdin and friends build them lazily, with plain
163
+ * stores (rooted via ractor_mark_unshareable_parts; a write barrier on the
164
+ * shareable wrapper would shref-pin them). */
165
+ VALUE r_stdin;
166
+ VALUE r_stdout;
167
+ VALUE r_stderr;
168
+ VALUE verbose;
169
+ VALUE debug;
170
+
171
+ bool malloc_gc_disabled;
172
+ bool main_ractor;
173
+ void *newobj_cache;
174
+
175
+ /* This Ractor's objspace. The main Ractor receives the boot objspace from
176
+ * rb_gc_init_objspaces; a non-main Ractor shares the main one until it gets its
177
+ * own (while this is NULL). */
178
+ void *objspace;
179
+
180
+ /* A child Ractor's objspace is populated (Thread/Fiber wrappers) before it joins
181
+ * vm->ractor.set, so a whole-VM walk would miss it. Park it here from wrapper
182
+ * allocation until vm_insert_ractor clears it (under the VM lock) so the global GC
183
+ * still enumerates it. */
184
+ void *creating_child_objspace;
185
+
186
+ }; // rb_ractor_t is defined in vm_core.h
187
+
188
+ /* Mark the GC roots held in Ractor r's C structs (from the root scan in gc.c). */
189
+ void rb_ractor_mark_local_roots(rb_ractor_t *r);
190
+ void rb_ractor_mark_terminated_join_value(rb_ractor_t *r);
191
+ void rb_ractor_reap_dead_ports(rb_ractor_t *r);
192
+
193
+ /* Move src's registered_marks to dst and leave src empty (on join or when an orphan
194
+ * is absorbed). An absorb can run during a GC sweep, so the implementation uses raw
195
+ * realloc (ractor.c). */
196
+ void rb_ractor_absorb_registered_marks(rb_ractor_t *dst, rb_ractor_t *src);
197
+
198
+ void rb_ractor_absorb_registered_addrs_without_gc(rb_ractor_t *dst, rb_ractor_t *src);
199
+
200
+ enum ractor_wakeup_status {
201
+ wakeup_none,
202
+ wakeup_by_send,
203
+ wakeup_by_interrupt,
204
+ wakeup_by_close,
205
+ };
206
+
207
+ struct ractor_waiter {
208
+ enum ractor_wakeup_status wakeup_status;
209
+ rb_thread_t *th;
210
+ struct ccan_list_node node;
211
+ rb_atomic_t event_serial;
212
+
213
+ // absolute deadline for this wait, NULL when there is no timeout
214
+ const rb_hrtime_t *end;
215
+ };
216
+
217
+ static inline VALUE
218
+ rb_ractor_self(const rb_ractor_t *r)
219
+ {
220
+ return r->pub.self;
221
+ }
222
+
223
+ rb_ractor_t *rb_ractor_main_alloc(void);
224
+ void rb_ractor_main_setup(rb_vm_t *vm, rb_ractor_t *main_ractor, rb_thread_t *main_thread);
225
+ void rb_ractor_atexit(rb_execution_context_t *ec, VALUE result);
226
+ void rb_ractor_atexit_exception(rb_execution_context_t *ec);
227
+ void rb_ractor_teardown(rb_execution_context_t *ec);
228
+ void rb_ractor_receive_parameters(rb_execution_context_t *ec, rb_ractor_t *g, int len, VALUE *ptr);
229
+ void rb_ractor_send_parameters(rb_execution_context_t *ec, rb_ractor_t *g, VALUE args);
230
+ void rb_ractor_setup_default_port(rb_ractor_t *r);
231
+
232
+ VALUE rb_thread_create_ractor(rb_ractor_t *g, VALUE args, VALUE proc); // defined in thread.c
233
+
234
+ int rb_ractor_living_thread_num(const rb_ractor_t *);
235
+ VALUE rb_ractor_thread_list(void);
236
+ bool rb_ractor_p(VALUE rv);
237
+
238
+ void rb_ractor_living_threads_init(rb_ractor_t *r);
239
+ void rb_ractor_living_threads_insert(rb_ractor_t *r, rb_thread_t *th);
240
+ void rb_ractor_living_threads_remove(rb_ractor_t *r, rb_thread_t *th);
241
+
242
+ /* The structs the final self collection swept while the dying thread still stood on
243
+ * them; that thread frees them at its very last step (rb_ractor_postmortem_free). */
244
+ struct rb_ractor_postmortem_frees {
245
+ struct rb_thread_struct *th;
246
+ struct rb_fiber_struct *fiber;
247
+ };
248
+ void rb_ractor_postmortem(rb_thread_t *th, struct rb_ractor_postmortem_frees *pf);
249
+ void rb_ractor_postmortem_free(const struct rb_ractor_postmortem_frees *pf);
250
+ void rb_ractor_cancel_creation(rb_ractor_t *r, rb_thread_t *th);
251
+ void rb_ractor_blocking_threads_inc(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
252
+ void rb_ractor_blocking_threads_dec(rb_ractor_t *r, const char *file, int line); // TODO: file, line only for RUBY_DEBUG_LOG
253
+
254
+ void rb_ractor_vm_barrier_interrupt_running_thread(rb_ractor_t *r);
255
+ void rb_ractor_terminate_interrupt_main_thread(rb_ractor_t *r);
256
+ void rb_ractor_terminate_all(void);
257
+ bool rb_ractor_main_p_(void);
258
+ void rb_ractor_atfork(rb_vm_t *vm, rb_thread_t *th);
259
+ void rb_ractor_terminate_atfork(rb_vm_t *vm, rb_ractor_t *th);
260
+ VALUE rb_ractor_require(VALUE feature, bool silent);
261
+ VALUE rb_ractor_autoload_load(VALUE space, ID id);
262
+
263
+ VALUE rb_ractor_ensure_shareable(VALUE obj, VALUE name);
264
+ st_table *rb_ractor_targeted_hooks(rb_ractor_t *cr);
265
+
266
+ RUBY_SYMBOL_EXPORT_BEGIN
267
+ void rb_ractor_finish_marking(bool full_mark);
268
+
269
+ bool rb_ractor_shareable_p_continue(VALUE obj);
270
+
271
+ // THIS FUNCTION SHOULD NOT CALL WHILE INCREMENTAL MARKING!!
272
+ // This function is for T_DATA::free_func
273
+ void rb_ractor_local_storage_delkey(rb_ractor_local_key_t key);
274
+
275
+ RUBY_SYMBOL_EXPORT_END
276
+
277
+ static inline bool
278
+ rb_ractor_main_p(void)
279
+ {
280
+ if (ruby_single_main_ractor) {
281
+ return true;
282
+ }
283
+ else {
284
+ return rb_ractor_main_p_();
285
+ }
286
+ }
287
+
288
+ static inline bool
289
+ rb_ractor_status_p(rb_ractor_t *r, enum ractor_status status)
290
+ {
291
+ return r->status_ == status;
292
+ }
293
+
294
+ static inline void
295
+ rb_ractor_sleeper_threads_inc(rb_ractor_t *r)
296
+ {
297
+ r->threads.sleeper++;
298
+ }
299
+
300
+ static inline void
301
+ rb_ractor_sleeper_threads_dec(rb_ractor_t *r)
302
+ {
303
+ r->threads.sleeper--;
304
+ }
305
+
306
+ static inline void
307
+ rb_ractor_sleeper_threads_clear(rb_ractor_t *r)
308
+ {
309
+ r->threads.sleeper = 0;
310
+ }
311
+
312
+ static inline int
313
+ rb_ractor_sleeper_thread_num(rb_ractor_t *r)
314
+ {
315
+ return r->threads.sleeper;
316
+ }
317
+
318
+ static inline void
319
+ rb_ractor_thread_switch(rb_ractor_t *cr, rb_thread_t *th, bool always_reset)
320
+ {
321
+ RUBY_DEBUG_LOG("th:%d->%u%s",
322
+ cr->threads.running_ec ? (int)rb_th_serial(cr->threads.running_ec->thread_ptr) : -1,
323
+ rb_th_serial(th), cr->threads.running_ec == th->ec ? " (same)" : "");
324
+
325
+ if (cr->threads.running_ec != th->ec || always_reset) {
326
+ th->running_time_us = 0;
327
+ }
328
+
329
+ if (cr->threads.running_ec != th->ec) {
330
+ if (0) {
331
+ ruby_debug_printf("rb_ractor_thread_switch ec:%p->%p\n",
332
+ (void *)cr->threads.running_ec, (void *)th->ec);
333
+ }
334
+ }
335
+ else {
336
+ return;
337
+ }
338
+
339
+ cr->threads.running_ec = th->ec;
340
+
341
+ VM_ASSERT(cr == GET_RACTOR());
342
+ }
343
+
344
+ #define rb_ractor_set_current_ec(cr, ec) rb_ractor_set_current_ec_(cr, ec, __FILE__, __LINE__)
345
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
346
+ void rb_current_ec_set(rb_execution_context_t *ec);
347
+ #endif
348
+
349
+ static inline void
350
+ rb_ractor_set_current_ec_(rb_ractor_t *cr, rb_execution_context_t *ec, const char *file, int line)
351
+ {
352
+ #ifdef RB_THREAD_LOCAL_SPECIFIER
353
+ rb_current_ec_set(ec);
354
+ #else
355
+ native_tls_set(ruby_current_ec_key, ec);
356
+ #endif
357
+ RUBY_DEBUG_LOG2(file, line, "ec:%p->%p", (void *)cr->threads.running_ec, (void *)ec);
358
+ VM_ASSERT(ec == NULL || cr->threads.running_ec != ec);
359
+ cr->threads.running_ec = ec;
360
+ }
361
+
362
+ void rb_vm_ractor_blocking_cnt_inc(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
363
+ void rb_vm_ractor_blocking_cnt_dec(rb_vm_t *vm, rb_ractor_t *cr, const char *file, int line);
364
+
365
+ static inline rb_serial_t
366
+ rb_ractor_id(const rb_ractor_t *r)
367
+ {
368
+ return r->pub.id;
369
+ }
370
+
371
+ static inline void
372
+ rb_ractor_targeted_hooks_incr(rb_ractor_t *cr)
373
+ {
374
+ cr->pub.targeted_hooks_cnt++;
375
+ }
376
+
377
+ static inline void
378
+ rb_ractor_targeted_hooks_decr(rb_ractor_t *cr)
379
+ {
380
+ RUBY_ASSERT(cr->pub.targeted_hooks_cnt > 0);
381
+ cr->pub.targeted_hooks_cnt--;
382
+ }
383
+
384
+ static inline unsigned int
385
+ rb_ractor_targeted_hooks_cnt(rb_ractor_t *cr)
386
+ {
387
+ return cr->pub.targeted_hooks_cnt;
388
+ }
389
+
390
+ #if RACTOR_CHECK_MODE > 0
391
+
392
+ extern bool rb_ractor_ignore_belonging_flag;
393
+
394
+ /* An object's owning Ractor is decided by the objspace its page belongs to
395
+ * (rb_gc_obj_foreign_p). Putting an unshareable object on the VM stack of anyone
396
+ * but its owner is a containment violation. */
397
+ static inline VALUE
398
+ rb_ractor_confirm_belonging(VALUE obj)
399
+ {
400
+ if (rb_ractor_ignore_belonging_flag) return obj;
401
+ if (SPECIAL_CONST_P(obj) || RB_OBJ_SHAREABLE_P(obj)) return obj;
402
+
403
+ if (UNLIKELY(rb_gc_obj_foreign_p(obj))) {
404
+ rp(obj);
405
+ rb_bug("rb_ractor_confirm_belonging: unshareable object of another Ractor's objspace");
406
+ }
407
+ return obj;
408
+ }
409
+
410
+ static inline void
411
+ rb_ractor_ignore_belonging(bool flag)
412
+ {
413
+ rb_ractor_ignore_belonging_flag = flag;
414
+ }
415
+
416
+ #else
417
+ #define rb_ractor_confirm_belonging(obj) obj
418
+ #define rb_ractor_ignore_belonging(flag) (0)
419
+ #endif
420
+
421
+ #endif /* RUBY_RACTOR_CORE_H */