summaryrefslogtreecommitdiff
path: root/iseq.c
AgeCommit message (Collapse)Author
2023-09-01Copy compile options from AST directly without intermediate HashNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8349
2023-09-01Copy `rb_compile_option_t` only if neededNobuyoshi Nakada
Use `COMPILE_OPTION_DEFAULT` if nothing to change. Notes: Merged: https://github.com/ruby/ruby/pull/8349
2023-09-01Use macro argument not the variable directlyNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8349
2023-08-30Update YARP APIs to handle uint8_tKevin Newton
2023-08-29Compile more YARP node types (#8322)Jemma Issroff
* Add several more node simple types to YARP's compiler: Nodes include: DefinedNode, EmbeddedStatementsNode, LocalVariableReadNode, LocalVariableWriteNode, MultiWriteNode, OptionalParameterNode, SplatNode, YieldNode * Add AssocSplatNode, RangeNode * Add RangeNode, other helpers for future nodes * Add ArrayNode, HashNode, static literal helpers * Add branch conditionals * Add IfNode, UnlessNode * Add ScopeNode * NEW_ISEQ and NEW_CHILD_ISEQ implemented for YARP * Add nodes that depend on ScopeNode * Addressed PR comments
2023-08-29[YARP] Compile basic types (#8311)Jemma Issroff
* 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 Notes: Merged-By: jemmaissroff
2023-08-28Add yarp/yarp_compiler.c (#8042)Jemma Issroff
* 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. Notes: Merged-By: jemmaissroff
2023-08-25Move SCRIPT_LINES__ away from parse.yNobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/8289
2023-08-01support `rescue` event for TracePointKoichi Sasada
fix [Feature #19572] Notes: Merged: https://github.com/ruby/ruby/pull/8150
2023-07-28`cc->cme` should not be marked.Ruby
cc is callcache. cc->klass (klass) should not be marked because if the klass is free'ed, the cc->klass will be cleared by `vm_cc_invalidate()`. cc->cme (cme) should not be marked because if cc is invalidated when cme is free'ed. - klass marks cme if klass uses cme. - caller classe's ccs->cme marks cc->cme. - if cc is invalidated (klass doesn't refer the cc), cc is invalidated by `vm_cc_invalidate()` and cc->cme is not be accessed. - On the multi-Ractors, cme will be collected with global GC so that it is safe if GC is not interleaving while accessing cc and cme. fix [Bug #19436] ```ruby 10_000.times{|i| # p i if (i%1_000) == 0 str = "x" * 1_000_000 def str.foo = nil eval "def call#{i}(s) = s.foo" send "call#{i}", str } ``` Without this patch: ``` real 1m5.639s user 0m6.637s sys 0m58.292s ``` and with this patch: ``` real 0m2.045s user 0m1.627s sys 0m0.164s ``` Notes: Merged: https://github.com/ruby/ruby/pull/8120
2023-07-27Clean up OPT_STACK_CACHING (#8132)Takashi Kokubun
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2023-06-30Don't check for null pointer in calls to freePeter Zhu
According to the C99 specification section 7.20.3.2 paragraph 2: > If ptr is a null pointer, no action occurs. So we do not need to check that the pointer is a null pointer. Notes: Merged: https://github.com/ruby/ruby/pull/8004
2023-06-17Replace parser & node compile_option from Hash to bit fieldyui-knk
This commit reduces dependency to CRuby object. Notes: Merged: https://github.com/ruby/ruby/pull/7950
2023-06-12[Feature #19719] Universal Parseryui-knk
Introduce Universal Parser mode for the parser. This commit includes these changes: * Introduce `UNIVERSAL_PARSER` macro. All of CRuby related functions are passed via `struct rb_parser_config_struct` when this macro is enabled. * Add CI task with 'cppflags=-DUNIVERSAL_PARSER' for ubuntu. Notes: Merged: https://github.com/ruby/ruby/pull/7927
2023-05-23Move `ruby_node_name` to node.c and rename prefix of the functionyui-knk
Notes: Merged: https://github.com/ruby/ruby/pull/7844
2023-04-11Move `catch_except_p` to `compile_data`eileencodes
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> Notes: Merged: https://github.com/ruby/ruby/pull/7652
2023-04-01Remove unused VM_CALL_BLOCKISEQ flagTakashi Kokubun
2023-03-23`vm_call_single_noarg_inline_builtin`Koichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/7486
2023-03-07Remove obsoleted functions in rjit.cTakashi Kokubun
2023-03-06s/mjit/rjit/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06s/MJIT/RJIT/Takashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7462
2023-03-06Stop exporting symbols for MJITTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7459
2023-03-05Store MJIT blocks on each ISEQTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7448
2023-03-05Invalidate everything on GC.compactTakashi Kokubun
Notes: Merged: https://github.com/ruby/ruby/pull/7448
2023-02-27Fix spelling (#7389)John Bampton
Notes: Merged-By: k0kubun <takashikkbn@gmail.com>
2023-02-09Merge gc.h and internal/gc.hMatt Valentine-House
[Feature #19425] Notes: Merged: https://github.com/ruby/ruby/pull/7273
2023-02-08Rename iseq_mark_and_update to iseq_mark_and_movePeter Zhu
The new name is more consistent.
2023-01-27Pass through `line_offset` argument correctly (but it was always 0). (#7177)Samuel Williams
Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-01-22Ensure main file has default coverage if required. (#7169)Samuel Williams
* Extract common code for coverage setup. Notes: Merged-By: ioquatix <samuel@codeotaku.com>
2023-01-20Make all of the references of iseq movablePeter Zhu
Notes: Merged: https://github.com/ruby/ruby/pull/7156
2023-01-19Combine code paths for marking ccPeter Zhu
This commit avoids a separate code path for marking and moving the callcache of the iseq. Notes: Merged: https://github.com/ruby/ruby/pull/7140
2023-01-19Add rb_gc_mark_and_move and implement on iseqPeter Zhu
This commit adds rb_gc_mark_and_move which takes a pointer to an object and marks it during marking phase and updates references during compaction. This allows for marking and reference updating to be combined into a single function, which reduces code duplication and prevents bugs if marking and reference updating goes out of sync. This commit also implements rb_gc_mark_and_move on iseq as an example. Notes: Merged: https://github.com/ruby/ruby/pull/7140
2023-01-19ci in iseq can only be object or nullPeter Zhu
It looks like rb_callinfo in iseq can only be either a Ruby object or null, since it cannot be allocated on the stack. Notes: Merged: https://github.com/ruby/ruby/pull/7147
2022-12-06Set max_iv_count (used for object shapes) based on inline cachesJemma Issroff
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> Notes: Merged: https://github.com/ruby/ruby/pull/6870
2022-12-04Fix crash when RGENGC_CHECK_MODE=2Peter Zhu
Commit dba61f4 fixes a crash when GC'ing a iseq that failed to compile. However, if we turn on RGENGC_CHECK_MODE then rb_iseq_memsize crashes since it cannot handle an iseq without is_entries.
2022-12-03return early if there is no is_entries bufferAaron Patterson
If there is a compilation error, is_entries may not be allocated, but ic_size could be greater than 0. If we don't have a buffer to iterate over, just return early. Otherwise GC could segv [Bug #19173] Notes: Merged: https://github.com/ruby/ruby/pull/6853
2022-12-02Use consistent style [ci skip]Nobuyoshi Nakada
2022-11-22Free the IV table after estimationAaron Patterson
We need to make sure the name table is freed otherwise we have a memory leak.
2022-11-22Increment max_iv_count on class based on number of set_iv in initialize (#6788)Jemma Issroff
We can loosely predict the number of ivar sets on a class based on the number of iv set instructions in the initialize method. This should give us a more accurate estimate to use for initial size pool allocation, which should in turn give us more cache hits. Notes: Merged-By: maximecb <maximecb@ruby-lang.org>
2022-11-16Using UNDEF_P macroS-H-GAMELINKS
Notes: Merged: https://github.com/ruby/ruby/pull/6721
2022-10-20push dummy frame for loading processKoichi Sasada
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 Notes: Merged: https://github.com/ruby/ruby/pull/6572
2022-10-11Revert "Revert "This commit implements the Object Shapes technique in CRuby.""Jemma Issroff
This reverts commit 9a6803c90b817f70389cae10d60b50ad752da48f.
2022-09-30Revert "This commit implements the Object Shapes technique in CRuby."Aaron Patterson
This reverts commit 68bc9e2e97d12f80df0d113e284864e225f771c2.
2022-09-29Add `eval: true/false` flag to `Coverage.setup`.Samuel Williams
2022-09-28This commit implements the Object Shapes technique in CRuby.Jemma Issroff
Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email>
2022-09-26Revert this until we can figure out WB issues or remove shapes from GCAaron Patterson
Revert "* expand tabs. [ci skip]" This reverts commit 830b5b5c351c5c6efa5ad461ae4ec5085e5f0275. Revert "This commit implements the Object Shapes technique in CRuby." This reverts commit 9ddfd2ca004d1952be79cf1b84c52c79a55978f4.
2022-09-26This commit implements the Object Shapes technique in CRuby.Jemma Issroff
Object Shapes is used for accessing instance variables and representing the "frozenness" of objects. Object instances have a "shape" and the shape represents some attributes of the object (currently which instance variables are set and the "frozenness"). Shapes form a tree data structure, and when a new instance variable is set on an object, that object "transitions" to a new shape in the shape tree. Each shape has an ID that is used for caching. The shape structure is independent of class, so objects of different types can have the same shape. For example: ```ruby class Foo def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end class Bar def initialize # Starts with shape id 0 @a = 1 # transitions to shape id 1 @b = 1 # transitions to shape id 2 end end foo = Foo.new # `foo` has shape id 2 bar = Bar.new # `bar` has shape id 2 ``` Both `foo` and `bar` instances have the same shape because they both set instance variables of the same name in the same order. This technique can help to improve inline cache hits as well as generate more efficient machine code in JIT compilers. This commit also adds some methods for debugging shapes on objects. See `RubyVM::Shape` for more details. For more context on Object Shapes, see [Feature: #18776] Co-Authored-By: Aaron Patterson <tenderlove@ruby-lang.org> Co-Authored-By: Eileen M. Uchitelle <eileencodes@gmail.com> Co-Authored-By: John Hawthorn <john@hawthorn.email> Notes: Merged: https://github.com/ruby/ruby/pull/6386
2022-09-26Rework vm_core to use `int first_lineno` struct member.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/6430
2022-09-26Rework `first_lineno` to be `int`.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/6430
2022-09-25Extract common code for coverage setup.Samuel Williams
Notes: Merged: https://github.com/ruby/ruby/pull/6425