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

1455 Коммитов

Автор SHA1 Сообщение Дата
Jeremy Evans 5e33f2b0e4 Eliminate array allocation for f(*a, kw: 1)
In cases where the compiler can detect the hash is static, it would
use duphash for the hash part. As the hash is static, there is no need
to allocate an array.
2023-12-07 11:27:55 -08:00
Jeremy Evans 95615872e3 Eliminate array allocation for f(*a, **lvar, &lvar) and f(*a, **@iv, &@iv)
The compiler already eliminates the array allocation for
f(*a, &lvar) and f(*a, &@iv).  If that is safe, then eliminating
it for f(*a, **lvar) and f(*a, **@iv) as the last commit did is
as safe, and eliminating it for f(*a, **lvar, &lvar) and
f(*a, **@iv, &@iv) is also as safe.
2023-12-07 11:27:55 -08:00
Jeremy Evans 1731dd05a7 Eliminate array allocation for f(*a, **lvar) and f(*a, **@iv)
The compiler already eliminates the array allocation for
f(*a, &lvar) and f(*a, &@iv), and eliminating the array allocation
for keyword splat is as safe as eliminating it for block passes.
2023-12-07 11:27:55 -08:00
Jeremy Evans c70c1d2a95 Eliminate array allocation for f(1, *a, &lvar) and f(1, *a, &@iv)
Due to how the compiler works, while f(*a, &lvar) and f(*a, &@iv)
do not allocate an array, but f(1, *a, &lvar) and f(1, *a, &@iv)
do.  It's probably possible to fix this in the compiler, but
seems easiest to fix this in the peephole optimizer.

Eliminating this array allocation is as safe as the current
elimination of the array allocation for f(*a, &lvar) and
f(*a, &@iv).
2023-12-07 11:27:55 -08:00
Jeremy Evans 40a2afd08f Eliminate array allocation for f(1, *a)
Due to how the compiler works, while f(*a) does not allocate an
array f(1, *a) does.  This is possible to fix in the compiler, but
the change is much more complex.  This attempts to fix the issue
in a simpler way using the peephole optimizer.

Eliminating this array allocation is safe, since just as in the
f(*a) case, nothing else on the caller side can modify the array.
2023-12-07 11:27:55 -08:00
Peter Zhu d1691617d6 Pin instruction storage
The operands in each instruction needs to be pinned because if
auto-compaction runs in iseq_set_sequence, then the objects could exist
on the generated_iseq buffer, which would not be reference updated which
can lead to T_MOVED (and subsequently T_NONE) objects on the iseq.
2023-12-02 09:06:03 -05:00
Nobuyoshi Nakada a607d62d8c [Bug #20033] Dynamic regexp should not assign captures 2023-12-02 03:57:41 +09:00
Peter Zhu 6ebcf25de2 GC guard catch_table_ary in iseq_set_exception_table
The function iseq_set_exception_table allocates memory which can cause
a GC compaction to run. Since catch_table_ary is not on the stack, it
can be moved, which would make tptr incorrect.
2023-11-29 12:30:12 -05:00
Nobuyoshi Nakada 7fe7b7bc5a
Fix portability of bignum in ISeq Binary Format
- Unless `sizeof(BDIGIT) == 4`, (8-byte integer not available), the
  size to be loaded was wrong.
- Since `BDIGIT`s are dumped as raw binary, the loaded byte order was
  inverted unless little-endian.
2023-11-26 11:42:02 +09:00
Jean Boussier 0aafd040c3 Embed ibf_dump objects 2023-11-21 17:41:27 +01:00
Jean Boussier b4f551686b Get rid of useless dsize functions
If we always return 0, we might as well not define
the function at all.
2023-11-21 15:15:03 +01:00
Jean Boussier 05028f4d55 compile.c: make pinned_list embedable
This saves some malloc churn for small pin lists.
2023-11-20 17:27:32 +01:00
Nobuyoshi Nakada 2a442121d1
Stabilize outer variable list
Sort outer variables by names to make dumped binary data stable.
2023-11-11 16:58:14 +09:00
Nobuyoshi Nakada e2ef85b109 Finer granularity IBF dependendency
It depends on only `VALUE` definition.  Check for endianness and word
size instead of the platform name.
2023-11-09 16:01:01 +09:00
Nobuyoshi Nakada 61bb5c0572 Use `uint32_t` instead of `unsigned int` for the exact size 2023-11-09 16:01:01 +09:00
Matt Valentine-House 8ef7f27321 [PRISM] CompileEnsureNode 2023-11-07 14:03:57 +00:00
Jemma Issroff f6ba87ca88 [PRISM] Implement compilation for MultiWriteNodes, fix MultiTargetNodes
Compilation now works for MultiWriteNodes and MultiTargetNodes, with
nesting on MultiWrites. See the tests added in this commit for example
behavior.
2023-11-06 10:39:07 -03:00
Matt Valentine-House 9249b8622b Move constant indexing into rb_translate_prism 2023-10-30 19:44:42 +00:00
Matt Valentine-House 5dfba84cff [Prism] Compile ForNode
Fixes ruby/prism#1648
2023-10-30 19:44:42 +00:00
Nobuyoshi Nakada 13c9cbe09e
Embed `rb_args_info` in `rb_node_args_t` 2023-10-30 00:19:43 +09:00
Jemma Issroff b5f6e2a7c4 [PRISM] ScopeNode doesn't need void * anymore 2023-10-25 18:18:35 -03:00
Jemma Issroff 8f71a5c530 [PRISM] Move scope_node itself to CRuby, create prism_compile.h 2023-10-25 18:18:35 -03:00
yui-knk 08e25985d1 Expand OP_ASGN1 nd_args to nd_index and nd_rvalue
ARGSCAT has been used for nd_args to hold index and rvalue,
because there was limitation on the number of members for Node.
We can easily change structure of node now, let's expand it.
2023-10-20 07:56:20 +09:00
Nobuyoshi Nakada c2d4c92a98
Extract a local variable 2023-10-19 17:28:41 +09:00
Jemma Issroff 10c5063704 Address PR comments 2023-10-18 17:16:11 -07:00
Jemma Issroff ba3a99acaf Remove pm_compile_context_t, move the context onto ScopeNode
We changed ScopeNodes to point to their parent (previous) ScopeNodes.
Accordingly, we can remove pm_compile_context_t, and store all
necessary context in ScopeNodes, allowing us to access locals from
outer scopes.
2023-10-18 17:16:11 -07:00
Alan Wu d2b0c9da2e
YJIT: Add a live ISeq counter
It's an estimator for application size and could be used as a
compilation heuristic later.

Co-authored-by: Maxime Chevalier-Boisvert <maxime.chevalierboisvert@shopify.com>
Co-authored-by: Takashi Kokubun <takashikkbn@gmail.com>
2023-10-18 23:46:35 +00:00
Nobuyoshi Nakada 8e6a251138
Remove unnecessary and misleading casts 2023-10-18 18:52:05 +09:00
Nobuyoshi Nakada 380c25f89f
Adjust indent [ci skip] 2023-10-11 19:42:07 +09:00
yui-knk f9fe7aeef4 Extract NODE_FL_NEWLINE access to macro 2023-10-11 19:22:34 +09:00
yui-knk 8c2a493233 Fix cast node type 2023-10-09 19:08:23 +09:00
yui-knk fbd534679f Correctly casting node for accessing nd_value and nd_vid in compile.c 2023-10-07 17:54:35 +09:00
yui-knk 5c779dc45d Remove not used fields from MATCH3 2023-10-06 15:32:33 +09:00
Nobuyoshi Nakada a5cc6341c0
Remove `NODE_VALUES`
This node type was added for the multi-value experiment back in 2004.
The feature itself was removed after a few years, but this is its
remnant.
2023-10-06 03:39:58 +09:00
yui-knk 45350a0460 Correctly casting node for accessing COLON node nd_mid in compile.c 2023-10-05 13:19:09 +09:00
Yuichiro Kaneko 1ed6fd8997 Check the result of get_nd_recv before node type check for safety
Co-authored-by: Nobuyoshi Nakada <nobu@ruby-lang.org>
2023-10-02 09:41:45 +09:00
yui-knk b1131851e0 Correctly casting node for accessing nd_recv, nd_mid and nd_args in compile.c 2023-10-02 09:41:45 +09: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
yui-knk 08239fd6af Use rb_node_args_t and rb_node_args_aux_t instead of NODE 2023-10-01 19:38:03 +09:00
yui-knk cecd1de2eb Use rb_node_opt_arg_t and rb_node_kw_arg_t instead of NODE 2023-10-01 09:19:42 +09:00
yui-knk d293d9e191 Expand pattern_info struct into ARYPTN Node and FNDPTN Node 2023-09-30 13:11:32 +09:00
yui-knk 129d006852 Remove not used fields from argument nodes 2023-09-30 12:29:29 +09:00
yui-knk 37a783a30c Merge RNode_OP_ASGN2 and RNode_OP_ASGN22 2023-09-29 08:36:39 +09:00
Kevin Newton a213d21448 Move CRuby-specific prism files to top level 2023-09-28 09:44:16 -04:00
yui-knk 74c6781153 Change RNode structure from union to struct
All kind of AST nodes use same struct RNode, which has u1, u2, u3 union members
for holding different kind of data.
This has two problems.

1. Low flexibility of data structure

Some nodes, for example NODE_TRUE, don’t use u1, u2, u3. On the other hand,
NODE_OP_ASGN2 needs more than three union members. However they use same
structure definition, need to allocate three union members for NODE_TRUE and
need to separate NODE_OP_ASGN2 into another node.
This change removes the restriction so make it possible to
change data structure by each node type.

2. No compile time check for union member access

It’s developer’s responsibility for using correct member for each node type when it’s union.
This change clarifies which node has which type of fields and enables compile time check.

This commit also changes node_buffer_elem_struct buf management to handle
different size data with alignment.
2023-09-28 11:58:10 +09:00
Kevin Newton 175ac32c62 Use new constant pool layout for prism 2023-09-27 15:41:05 -04:00
Kevin Newton 3d0a46796b Rename YARP symbols to prism 2023-09-27 13:57:38 -04:00
Aaron Patterson f08cac066e Don't call malloc with 0
It seems not-uncommon for methods to have no IV, ISE, or ICVARC caches.
Calling malloc with 0 will actually allocate something, so if there
aren't any caches (`ISEQ_IS_SIZE(body) == 0`), then we can avoid
allocating memory by not calling malloc.  If there are no caches, then
theoretically nobody should be reading from the buffer anyway.

This saves about 1MB on Lobsters benchmark.
2023-09-14 16:15:53 -07:00
Nobuyoshi Nakada 6e64d43704 [Bug #19862] Skip compiled result of never reachable expression 2023-09-13 08:30:37 +09:00
yui-knk b5914a72a9 Refactor to use same logic with other assignment nodes 2023-09-10 19:45:33 +09:00
Peter Zhu b3b57f70cc Fix missing write barrier in iseq instruction list
There's a missing write barrier for operands in the iseq instruction
list, which can cause crashes.

It can be reproduced when Ruby is compiled with `-DRUBY_DEBUG_ENV=1`.
Using the following command:

```
RUBY_GC_HEAP_OLDOBJECT_LIMIT_FACTOR=0 RUBY_DEBUG=gc_stress ruby -w --disable=gems -Itool/lib -W0 test.rb
```

The following script crashes:

```
require "test/unit"
```
2023-09-06 11:18:50 -04:00
Yusuke Endoh 4f4c1170bc Revert "Don't reset line coverage for evaled code. (#8330)"
This reverts commit 7e0f5df2f9.

https://bugs.ruby-lang.org/issues/19857#note-7
2023-09-04 19:52:08 +09:00
Samuel Williams 7e0f5df2f9
Don't reset line coverage for evaled code. (#8330)
* Add failing test.
2023-09-04 13:31:25 +12:00
Kevin Newton 49dff732e8
Update YARP APIs to handle uint8_t 2023-08-30 14:41:39 -04:00
Jemma Issroff 535045ab3b
[YARP] Compile basic types (#8311)
* Add a compile_context arg to yp_compile_node

The compile_context will allow us to pass around the parser, and
the constants and lookup table (to be used in future commits).

* Compile yp_program_node_t and yp_statements_node_t

Add the compilation for program and statements node so that we can
successfully compile an empty program with YARP.

* Helper functions for parsing numbers, strings, and symbols

* Compile basic numeric / boolean node types in YARP

* Compile StringNode and SymbolNodes in YARP

* Compile several basic node types in YARP

* Added error return for missing node
2023-08-29 09:27:00 -07:00
Jemma Issroff 3b815ed7da
Add yarp/yarp_compiler.c (#8042)
* Add yarp/yarp_compiler.c as stencil for compiling YARP

This commit adds yarp/yarp_compiler.c, and changes the sync script
to ensure that yarp/yarp_compiler.c will not get overwritten

* [Misc #119772] Create and expose RubyVM::InstructionSequence.compile_yarp

This commit creates the stencil for a compile_yarp function, which
we will continue to fill out. It allows us to check the output
of compiled YARP code against compiled code without using YARP.
2023-08-28 13:55:58 -07:00
yui-knk 00054de6b5 Remove nd_entry from NODE_GASGN and NODE_GVAR
After a0f12a0258 NODE_GASGN and
NODE_GVAR hold same value on both nd_vid and nd_entry.
This commit stops setting value to nd_entry and makes to use only
nd_vid.
2023-08-23 07:59:54 +09:00
Takashi Kokubun e210b899dc
Move the PC regardless of the leaf flag (#8232)
Co-authored-by: Alan Wu <alansi.xingwu@shopify.com>
2023-08-16 20:28:33 -07:00
Koichi Sasada d68c01fd31 support `rescue` event for TracePoint
fix [Feature #19572]
2023-08-01 22:46:17 +09:00
Takashi Kokubun 38be9a9b72
Clean up OPT_STACK_CACHING (#8132) 2023-07-27 17:27:05 -07:00
Peter Zhu 3223181284 Remove RARRAY_CONST_PTR_TRANSIENT
RARRAY_CONST_PTR now does the same things as RARRAY_CONST_PTR_TRANSIENT.
2023-07-13 14:48:14 -04:00
Nobuyoshi Nakada 0d0841ad4c
Compile code for lazy ISeq loding always 2023-06-30 23:59:05 +09:00
yui-knk 19c62b400d Replace parser & node compile_option from Hash to bit field
This commit reduces dependency to CRuby object.
2023-06-17 16:41:08 +09:00
yui-knk 5f65e8c5d5 Rename `rb_node_name` to the original name
98637d421d changes the name of
the function. However this function is exported as global,
then change the name to origin one for keeping compatibility.
2023-05-24 20:54:48 +09:00
yui-knk 98637d421d Move `ruby_node_name` to node.c and rename prefix of the function 2023-05-23 18:05:35 +09:00
Nobuyoshi Nakada c7bacf84f0 [Bug #19611] Remove never-reachable branch in logical expression 2023-04-27 14:52:22 +09:00
Nobuyoshi Nakada 8023da746c
Adjust indent [ci skip] 2023-04-19 09:23:28 +09:00
git 21082eac50 * expand tabs. [ci skip]
Please consider using misc/expand_tabs.rb as a pre-commit hook.
2023-04-19 00:16:36 +00:00
Aaron Patterson c5fc1ce975 Emit special instruction for array literal + .(hash|min|max)
This commit introduces a new instruction `opt_newarray_send` which is
used when there is an array literal followed by either the `hash`,
`min`, or `max` method.

```
[a, b, c].hash
```

Will emit an `opt_newarray_send` instruction.  This instruction falls
back to a method call if the "interested" method has been monkey
patched.

Here are some examples of the instructions generated:

```
$ ./miniruby --dump=insns -e '[@a, @b].max'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 getinstancevariable                    :@a, <is:0>               (   1)[Li]
0003 getinstancevariable                    :@b, <is:1>
0006 opt_newarray_send                      2, :max
0009 leave
$ ./miniruby --dump=insns -e '[@a, @b].min'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,12)> (catch: FALSE)
0000 getinstancevariable                    :@a, <is:0>               (   1)[Li]
0003 getinstancevariable                    :@b, <is:1>
0006 opt_newarray_send                      2, :min
0009 leave
$ ./miniruby --dump=insns -e '[@a, @b].hash'
== disasm: #<ISeq:<main>@-e:1 (1,0)-(1,13)> (catch: FALSE)
0000 getinstancevariable                    :@a, <is:0>               (   1)[Li]
0003 getinstancevariable                    :@b, <is:1>
0006 opt_newarray_send                      2, :hash
0009 leave
```

[Feature #18897] [ruby-core:109147]

Co-authored-by: John Hawthorn <jhawthorn@github.com>
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
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
Koichi Sasada e5a5e43c36 should not restore builtin_inline_index
`builtin_inline_index` is restored because THEN clause on
`Primitive.mandatory_only?` was compiled twice.

However, f29c9d6d36 skips to compile THEN clause so we don't
need to restore `builtin_inline_index`.
2023-03-23 14:03:12 +09:00
Koichi Sasada f29c9d6d36 compile branch body if needed
```ruby
if true
  THEN
else
  ELSE
end
```

On this case, ELSE is not needed so that only compile THEN part.
2023-03-17 09:50:41 +09:00
Koichi Sasada 6462c1a042 `Hash#dup` for kwsplat arguments
On `f(*a, **kw)` method calls, a rest keyword parameter is identically
same Hash object is passed and it should make `#dup`ed Hahs.

fix https://bugs.ruby-lang.org/issues/19526
2023-03-15 18:05:13 +09:00
Takashi Kokubun 70ba310212
YJIT: Introduce no_gc attribute (#7511) 2023-03-14 15:38:58 -07:00
Takashi Kokubun 94da5f7c36 Rename builtin attr :inline to :leaf 2023-03-11 14:25:12 -08:00
Takashi Kokubun 0c0c88d383 Support multiple attributes with Primitive.attr! 2023-03-11 14:19:46 -08:00
Koichi Sasada 262254dc7d rename `defined_ivar` to `definedivar`
because non-opt instructions should contain `_` char.
2023-03-10 00:37:11 +09:00
Ole Friis Østergaard 1a3f8e1c9f Add defined_ivar instruction
This is a variation of the `defined` instruction, for use when we
are checking for an instance variable. Splitting this out as a
separate instruction lets us skip some checks, and it also allows
us to use an instance variable cache, letting shape analysis
speed up the operation further.
2023-03-08 09:34:31 -08:00
Nobuyoshi Nakada 5889cbd7de Constify function tables 2023-03-08 13:59:21 +09:00
Takashi Kokubun 233ddfac54 Stop exporting symbols for MJIT 2023-03-06 21:59:23 -08:00
Koichi Sasada e87d088291 Change bytecode of `f(*a, **kw)`
`f(*a, **kw)` is compiled to `f([*a, kw])` but it makes an dummy
array, so change it to pass two arguments `a` and `kw` with calling
flags.

```
ruby 3.2.0 (2022-12-29 revision a7d467a792) [x86_64-linux]
Calculating -------------------------------------
               foo()     15.354M (± 4.2%) i/s -     77.295M in   5.043650s
              dele()     13.439M (± 3.9%) i/s -     67.109M in   5.001974s
             dele(*)      6.265M (± 4.5%) i/s -     31.730M in   5.075649s
            dele(*a)      6.286M (± 3.3%) i/s -     31.719M in   5.051516s
      dele(*a, **kw)      1.926M (± 4.5%) i/s -      9.753M in   5.076487s
         dele(*, **)      1.927M (± 4.2%) i/s -      9.710M in   5.048224s
           dele(...)      5.871M (± 3.9%) i/s -     29.471M in   5.028023s
         forwardable      4.969M (± 4.1%) i/s -     25.233M in   5.087498s

ruby 3.3.0dev (2023-01-13T01:28:00Z master 7e8802fa5b) [x86_64-linux]
Calculating -------------------------------------
               foo()     16.354M (± 4.7%) i/s -     81.799M in   5.014561s
              dele()     14.256M (± 3.5%) i/s -     71.656M in   5.032883s
             dele(*)      6.701M (± 3.8%) i/s -     33.948M in   5.074938s
            dele(*a)      6.681M (± 3.3%) i/s -     33.578M in   5.031720s
      dele(*a, **kw)      4.200M (± 4.4%) i/s -     21.258M in   5.072583s
         dele(*, **)      4.197M (± 5.3%) i/s -     21.322M in   5.096684s
           dele(...)      6.039M (± 6.8%) i/s -     30.355M in   5.052662s
         forwardable      4.788M (± 3.2%) i/s -     24.033M in   5.024875s
```
2023-03-06 15:03:06 +09:00
John Bampton 2f7270c681
Fix spelling (#7389) 2023-02-27 09:56:06 -08:00
Peter Zhu 3e09822407 Fix incorrect line numbers in GC hook
If the previous instruction is not a leaf instruction, then the PC was
incremented before the instruction was ran (meaning the currently
executing instruction is actually the previous instruction), so we
should not increment the PC otherwise we will calculate the source
line for the next instruction.

This bug can be reproduced in the following script:

```
require "objspace"

ObjectSpace.trace_object_allocations_start
a =

  1.0 / 0.0
p [ObjectSpace.allocation_sourceline(a), ObjectSpace.allocation_sourcefile(a)]
```

Which outputs: [4, "test.rb"]

This is incorrect because the object was allocated on line 10 and not
line 4. The behaviour is correct when we use a leaf instruction (e.g.
if we replaced `1.0 / 0.0` with `"hello"`), then the output is:
[10, "test.rb"].

[Bug #19456]
2023-02-24 14:10:09 -05:00
Nobuyoshi Nakada cb40432c74
Use `ERROR_ARGS_AT` 2023-02-21 18:40:03 +09:00
Jean Boussier 0459eaec95 compile.c: eliminate getinstancevariable -> pop sequences
This case wasn't eliminated before because `getinstancevariable`
could emit a warning, but that's no longer the case since Ruby
3.0.
2023-02-20 19:04:04 +01:00
Nobuyoshi Nakada 2490b2e121 Add utility macros `DECIMAL_SIZE_OF` and `DECIMAL_SIZE_OF_BYTES` 2023-02-14 15:18:21 +09:00
Alan Wu 86de48e9f6 Remove ibf_dumper's WB_PROTECTED status
It doesn't have the right write barriers in place. For example, there is

    rb_mark_set(dump->global_buffer.obj_table);

in the mark function, but there is no corresponding write barrier when
adding to the table in the
`ibf_dump_object() -> ibf_table_find_or_insert() -> st_insert()` code path.

To insert write barrier correctly, we need to store the T_STRUCT VALUE
inside `struct ibf_dump`. Instead of doing that, let's just demote it
to WB unproected for correctness. These dumper object are ephemeral so
there is not a huge benefit for having them WB protected.

Users of the bootsnap gem ran into crashes due to this issue:
https://github.com/Shopify/bootsnap/issues/436

Fixes [Bug #19419]
2023-02-13 11:42:58 -05:00
Matt Valentine-House 72aba64fff Merge gc.h and internal/gc.h
[Feature #19425]
2023-02-09 10:32:29 -05:00
Peter Zhu 861d70e383 Rename iseq_mark_and_update to iseq_mark_and_move
The new name is more consistent.
2023-02-08 12:43:25 -05:00
Peter Zhu 056e7a0154 Make all of the references of iseq movable 2023-01-20 08:51:39 -05:00
Stan Lo df6b72b8ff Avoid checking interrupt when loading iseq
The interrupt check will unintentionally release the VM lock when loading an iseq.
And this will cause issues with the `debug` gem's
[`ObjectSpace.each_iseq` method](0fcfc28aca/ext/debug/iseq_collector.c (L61-L67)),
which wraps iseqs with a wrapper and exposes their internal states when they're actually not ready to be used.

And when that happens, errors like this would occur and kill the `debug` gem's thread:

```
 DEBUGGER: ReaderThreadError: uninitialized InstructionSequence
┃ DEBUGGER: Disconnected.
┃ ["/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:247:in `absolute_path'",
┃  "/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:247:in `block in iterate_iseq'",
┃  "/opt/rubies/ruby-3.2.0/lib/ruby/gems/3.2.0/gems/debug-1.7.1/lib/debug/breakpoint.rb:246:in `each_iseq'",
...
```

A way to reproduce the issue is to satisfy these conditions at the same time:

1. `debug` gem calling `ObjectSpace.each_iseq` (e.g. [activating a `LineBreakpoint`](0fcfc28aca/lib/debug/breakpoint.rb (L246))).
2. A large amount of iseq being loaded from another thread (possibly through the `bootsnap` gem).
3. 1 and 2 iterating through the same iseq(s) at the same time.

Because this issue requires external dependencies and a rather complicated timing setup to reproduce, I wasn't able to write a test case for it.
But here's some pseudo code to help reproduce it:

```rb
require "debug/session"

Thread.new do
  100.times do
    ObjectSpace.each_iseq do |iseq|
      iseq.absolute_path
    end
  end
end

sleep 0.1

load_a_bunch_of_iseq
possibly_through_bootsnap
```

[Bug #19348]

Co-authored-by: Peter Zhu <peter@peterzhu.ca>
2023-01-17 08:01:19 -05:00
Shugo Maeda 2581de112c Disallow mixed usage of ... and */**
[Feature #19134]
2022-12-15 18:56:24 +09:00
Jemma Issroff 40a9964b89 Set max_iv_count (used for object shapes) based on inline caches
With this change, we're storing the iv name on an inline cache on
setinstancevariable instructions. This allows us to check the inline
cache to count instance variables set in initialize and give us an
estimate of iv capacity for an object.

For the purpose of estimating the number of instance variables required
for an object, we're assuming that all initialize methods will call
`super`.

This change allows us to estimate the number of instance variables
required without disassembling instruction sequences.

Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org>
2022-12-06 13:43:42 -08:00
yui-knk 8be62f06c8 Remove ruby2_keywords related to args forwarding
This was introduced by b609bdeb53
to suppress warnings. However these warngins were deleted by
beae6cbf0f. Therefore these codes
are not needed anymore.
2022-11-29 15:39:56 +09:00
S-H-GAMELINKS 1f4f6c9832 Using UNDEF_P macro 2022-11-16 18:58:33 +09:00
Yusuke Endoh 4a7d6c2852 Fix false LocalJumpError when branch coverage is enabled
`throw TAG_BREAK` instruction makes a jump only if the continuation of
catch of TAG_BREAK exactly matches the instruction immediately following
the "send" instruction that is currently being executed. Otherwise, it
seems to determine break from proc-closure.

Branch coverage may insert some recording instructions after "send"
instruction, which broke the conditions for TAG_BREAK to work properly.

This change forces to set the continuation of catch of TAG_BREAK
immediately after "send" (or "invokesuper") instruction.

[Bug #18991]
2022-11-08 14:37:08 +09:00
Koichi Sasada e35c528d72 push dummy frame for loading process
This patch pushes dummy frames when loading code for the
profiling purpose.

The following methods push a dummy frame:
* `Kernel#require`
* `Kernel#load`
* `RubyVM::InstructionSequence.compile_file`
* `RubyVM::InstructionSequence.load_from_binary`

https://bugs.ruby-lang.org/issues/18559
2022-10-20 17:38:28 +09:00
Jemma Issroff ad63b668e2
Revert "Revert "This commit implements the Object Shapes technique in CRuby.""
This reverts commit 9a6803c90b.
2022-10-11 08:40:56 -07:00
Aaron Patterson 9a6803c90b
Revert "This commit implements the Object Shapes technique in CRuby."
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-30 16:01:50 -07:00