Граф коммитов

97 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada 352a885a0f Thread specific storage APIs
This patch introduces thread specific storage APIs
for tools which use `rb_internal_thread_event_hook` APIs.

* `rb_internal_thread_specific_key_create()` to create a tool specific
  thread local storage key and allocate the storage if not available.
* `rb_internal_thread_specific_set()` sets a data to thread and tool
  specific storage.
* `rb_internal_thread_specific_get()` gets a data in thread and tool
  specific storage.

Note that `rb_internal_thread_specific_get|set(thread_val, key)`
can be called without GVL and safe for async signal and safe for
multi-threading (native threads). So you can call it in any internal
thread event hooks. Further more you can call it from other native
threads. Of course `thread_val` should be living while accessing the
data from this function.

Note that you should not forget to clean up the set data.
2023-12-08 13:16:19 +09:00
Peter Zhu 68869e9bd9 Revert "Revert "Remove SHAPE_CAPACITY_CHANGE shapes""
This reverts commit 5f3fb4f4e3.
2023-11-13 18:26:36 -05:00
Peter Zhu 5f3fb4f4e3 Revert "Remove SHAPE_CAPACITY_CHANGE shapes"
This reverts commit f6910a6112.

We're seeing crashes in the test suite of Shopify's core monolith after
this change.
2023-11-10 11:27:49 -05:00
Peter Zhu f6910a6112 Remove SHAPE_CAPACITY_CHANGE shapes
We don't need to create a shape to transition capacity as we can
transition the capacity when the capacity of the SHAPE_IVAR changes.
2023-11-09 09:25:02 -05:00
Jean Boussier d898e8d6f8 Refactor rb_shape_transition_shape_capa out
Right now the `rb_shape_get_next` shape caller need to
first check if there is capacity left, and if not call
`rb_shape_transition_shape_capa` before it can call `rb_shape_get_next`.

And on each of these it needs to checks if we got a TOO_COMPLEX
back.

All this logic is duplicated in the interpreter, YJIT and RJIT.

Instead we can have `rb_shape_get_next` do the capacity transition
when needed. The caller can compare the old and new shapes capacity
to know if resizing is needed. It also can check for TOO_COMPLEX
only once.
2023-11-08 11:02:55 +01:00
Peter Zhu 38ba040d8b Make every initial size pool shape a root shape
This commit makes every initial size pool shape a root shape and assigns
it a capacity of 0.
2023-11-02 13:42:11 -04:00
Aaron Patterson 84e4453436 Use a functional red-black tree for indexing the shapes
This is an experimental commit that uses a functional red-black tree to
create an index of the ancestor shapes.  It uses an Okasaki style
functional red black tree:

  https://www.cs.tufts.edu/comp/150FP/archive/chris-okasaki/redblack99.pdf

This tree is advantageous because:

* It offers O(n log n) insertions and O(n log n) lookups.
* It shares memory with previous "versions" of the tree

When we insert a node in the tree, only the parts of the tree that need
to be rebalanced are newly allocated.  Parts of the tree that don't need
to be rebalanced are not reallocated, so "new trees" are able to share
memory with old trees.  This is in contrast to a sorted set where we
would have to duplicate the set, and also resort the set on each
insertion.

I've added a new stat to RubyVM.stat so we can understand how the red
black tree increases.
2023-10-24 10:52:06 -07:00
Katherine Oelsner a7032b80af Revert "shape.h: Make attr_index_t uint8_t"
This reverts commit e3afc212ec.
2023-10-18 15:01:13 -07:00
Jean Boussier e3afc212ec shape.h: Make attr_index_t uint8_t
Given `SHAPE_MAX_NUM_IVS 80`, we transition to TOO_COMPLEX
way before we could overflow a 8bit counter.

This reduce the size of `rb_shape_t` from 32B to 24B.

If we decide to raise `SHAPE_MAX_NUM_IVS` we can always increase
that type again.
2023-10-11 08:33:09 +02:00
Jean Boussier 5cc44f48c5 Refactor rb_shape_transition_shape_capa to not accept capacity
This way the groth factor is encapsulated, which allows
rb_shape_transition_shape_capa to be smarter about ideal sizes.
2023-10-10 14:47:54 +02:00
HParker c74dc8b4af Use reference counting to avoid memory leak in kwargs
Tracks other callinfo that references the same kwargs and frees them when all references are cleared.

[bug #19906]

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-10-01 10:55:19 -04:00
Adam Hess 8b236e0c66 [Bug #19896]
fix memory leak in vm_method

This introduces a unified reference_count to clarify who is referencing a method.
This also allows us to treat the refinement method as the def owner since it counts itself as a reference

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-09-22 09:44:58 -04:00
Takashi Kokubun cd8d20cd1f
YJIT: Compile exception handlers (#8171)
Co-authored-by: Maxime Chevalier-Boisvert <maximechevalierb@gmail.com>
2023-08-08 16:06:22 -07:00
Alan Wu f302e725e1
Remove __bp__ and speed-up bmethod calls (#8060)
Remove rb_control_frame_t::__bp__ and optimize bmethod calls

This commit removes the __bp__ field from rb_control_frame_t. It was
introduced to help MJIT, but since MJIT was replaced by RJIT, we can use
vm_base_ptr() to compute it from the SP of the previous control frame
instead. Removing the field avoids needing to set it up when pushing new
frames.

Simply removing __bp__ would cause crashes since RJIT and YJIT used a
slightly different stack layout for bmethod calls than the interpreter.
At the moment of the call, the two layouts looked as follows:

                   ┌────────────┐    ┌────────────┐
                   │ frame_base │    │ frame_base │
                   ├────────────┤    ├────────────┤
                   │    ...     │    │    ...     │
                   ├────────────┤    ├────────────┤
                   │    args    │    │    args    │
                   ├────────────┤    └────────────┘<─prev_frame_sp
                   │  receiver  │
    prev_frame_sp─>└────────────┘
                     RJIT & YJIT      interpreter

Essentially, vm_base_ptr() needs to compute the address to frame_base
given prev_frame_sp in the diagrams. The presence of the receiver
created an off-by-one situation.

Make the interpreter use the layout the JITs use for iseq-to-iseq
bmethod calls. Doing so removes unnecessary argument shifting and
vm_exec_core() re-entry from the interpreter, yielding a speed
improvement visible through `benchmark/vm_defined_method.yml`:

     patched:   7578743.1 i/s
      master:   4796596.3 i/s - 1.58x  slower

C-to-iseq bmethod calls now store one more VALUE than before, but that
should have negligible impact on overall performance.

Note that re-entering vm_exec_core() used to be necessary for firing
TracePoint events, but that's no longer the case since
9121e57a5f.

Closes ruby/ruby#6428
2023-07-17 13:57:58 -04:00
Aaron Patterson 7ce6bcaf8b Expose rb_hash_resurrect
This is for implementing the `duphash` instruction
2023-06-23 11:46:21 -07:00
Peter Zhu 7577c101ed
Unify length field for embedded and heap strings (#7908)
* Unify length field for embedded and heap strings

The length field is of the same type and position in RString for both
embedded and heap allocated strings, so we can unify it.

* Remove RSTRING_EMBED_LEN
2023-06-06 10:19:20 -04:00
Aaron Patterson bdffcd6df3 Update RJIT to support newarray_send
This also adds max / hash support
2023-04-18 17:16:22 -07:00
eileencodes ce99e50ede Move `catch_except_p` to `compile_data`
The `catch_except_p` flag is used for communicating between parent and
child iseq's that a throw instruction was emitted. So for example if a
child iseq has a throw in it and the parent wants to catch the throw, we
use this flag to communicate to the parent iseq that a throw instruction
was emitted.

This flag is only useful at compile time, it only impacts the
compilation process so it seems to be fine to move it from the iseq body
to the compile_data struct.

Co-authored-by: Aaron Patterson <tenderlove@ruby-lang.org>
2023-04-11 10:47:58 -07:00
Aaron Patterson a9bfb64153 Expose rb_sym_to_proc via RJIT
This is needed for getblockparamproxy
2023-04-07 09:49:15 -07:00
Peter Zhu 1da2e7fca3
[Feature #19579] Remove !USE_RVARGC code (#7655)
Remove !USE_RVARGC code

[Feature #19579]

The Variable Width Allocation feature was turned on by default in Ruby
3.2. Since then, we haven't received bug reports or backports to the
non-Variable Width Allocation code paths, so we assume that nobody is
using it. We also don't plan on maintaining the non-Variable Width
Allocation code, so we are going to remove it.
2023-04-04 17:30:06 -04:00
Takashi Kokubun 19506650ef RJIT: Add --rjit-verify-ctx option 2023-04-04 00:35:29 -07:00
Takashi Kokubun d546f8c518 RJIT: Store type information in Context 2023-04-02 22:32:16 -07:00
Takashi Kokubun 6002b12611 RJIT: Support entry with different PCs 2023-04-02 15:27:40 -07:00
Takashi Kokubun 4fc336127e RJIT: Support has_opt ISEQs 2023-04-02 14:47:23 -07:00
Takashi Kokubun 66f8efc342 RJIT: Simplify cfunc implementation 2023-04-02 13:58:39 -07:00
Takashi Kokubun bf7587748d RJIT: Simplify invokesuper implementation 2023-04-02 11:42:16 -07:00
Takashi Kokubun 5cc644b147 RJIT: Group blockarg exit reasons 2023-04-02 11:01:23 -07:00
Takashi Kokubun cd1cd8030c RJIT: Support splat args 2023-04-02 10:55:03 -07:00
Takashi Kokubun 62188c8584 RJIT: Update exit reasons 2023-04-02 10:27:17 -07:00
Takashi Kokubun 1b475fcd10 Remove an unneeded function copy 2023-04-01 23:09:05 -07:00
Takashi Kokubun a077b7e36b RJIT: Support rest args 2023-04-01 23:00:36 -07:00
Takashi Kokubun bf2617b8a6 RJIT: Fix has_rest exit conditions 2023-04-01 21:47:28 -07:00
Takashi Kokubun 249fe18e8f RJIT: Remove unused counters 2023-04-01 17:24:45 -07:00
Takashi Kokubun 0973b93e49 RJIT: Start moving away from VM-like ISEQ handling 2023-04-01 16:56:05 -07:00
Takashi Kokubun 3352e76441 RJIT: Implement leaf builtin call 2023-03-26 19:25:17 -07:00
Takashi Kokubun dc270fc632 RJIT: Implement attr_writer 2023-03-26 18:02:25 -07:00
Takashi Kokubun ddb77dd11e RJIT: Put a guard for splat w/ var-arg cfunc 2023-03-25 22:14:07 -07:00
Takashi Kokubun 9bc2dbd33c RJIT: Support optional params on splat 2023-03-25 01:17:05 -07:00
Takashi Kokubun 85a55d3e75 RJIT: Remove send_iseq_complex_splat exit 2023-03-25 00:59:47 -07:00
Takashi Kokubun 1dd65f7c55 RJIT: Initial support of splat 2023-03-25 00:31:11 -07:00
Koichi Sasada c9fd81b860 `vm_call_single_noarg_inline_builtin`
If the iseq only contains `opt_invokebuiltin_delegate_leave` insn and
the builtin-function (bf) is inline-able, the caller doesn't need to
build a method frame.

`vm_call_single_noarg_inline_builtin` is fast path for such cases.
2023-03-23 14:03:12 +09:00
Takashi Kokubun cb45809454 RJIT: Update binding 2023-03-21 22:28:39 -07:00
Takashi Kokubun 38946209a7 RJIT: Split has_rest_or_post exit reasons 2023-03-21 22:01:55 -07:00
Takashi Kokubun c44367265d RJIT: Fix invokesuper 2023-03-21 00:10:14 -07:00
Takashi Kokubun 70ea58bd5b RJIT: Break up RJIT send_iseq_complex exit reasons 2023-03-19 23:58:14 -07:00
Takashi Kokubun 59b86da82c RJIT: Implement ifunc invokeblock 2023-03-19 23:32:07 -07:00
Takashi Kokubun e3dc25acae RJIT: Fix ISeq invokeblock 2023-03-19 21:52:25 -07:00
Takashi Kokubun 2d8ecfcc9a RJIT: Implement invokeblock with ISeq 2023-03-19 20:56:37 -07:00
Takashi Kokubun 83ad1cac81 RJIT: Optimize Kernel#respond_to? 2023-03-19 14:04:58 -07:00
Takashi Kokubun cd5a8d0160 RJIT: Optimize String#+@ 2023-03-19 13:36:26 -07:00