summaryrefslogtreecommitdiff
path: root/iseq.c
AgeCommit message (Collapse)Author
2019-10-28Pin labels during disassemblyAaron Patterson
We need to ensure that labels are pinned while disassembling. If the compactor runs during disassembly, references to these labels could go bad, so this commit just ensures that the labels can't move until we're done. Notes: Merged: https://github.com/ruby/ruby/pull/2625
2019-10-24Combine call info and cache to speed up method invocationAlan Wu
To perform a regular method call, the VM needs two structs, `rb_call_info` and `rb_call_cache`. At the moment, we allocate these two structures in separate buffers. In the worst case, the CPU needs to read 4 cache lines to complete a method call. Putting the two structures together reduces the maximum number of cache line reads to 2. Combining the structures also saves 8 bytes per call site as the current layout uses separate two pointers for the call info and the call cache. This saves about 2 MiB on Discourse. This change improves the Optcarrot benchmark at least 3%. For more details, see attached bugs.ruby-lang.org ticket. Complications: - A new instruction attribute `comptime_sp_inc` is introduced to calculate SP increase at compile time without using call caches. At compile time, a `TS_CALLDATA` operand points to a call info struct, but at runtime, the same operand points to a call data struct. Instruction that explicitly define `sp_inc` also need to define `comptime_sp_inc`. - MJIT code for copying call cache becomes slightly more complicated. - This changes the bytecode format, which might break existing tools. [Misc #16258] Notes: Merged: https://github.com/ruby/ruby/pull/2564
2019-10-09avoid overflow in integer multiplication卜部昌平
This changeset basically replaces `ruby_xmalloc(x * y)` into `ruby_xmalloc2(x, y)`. Some convenient functions are also provided for instance `rb_xmalloc_mul_add(x, y, z)` which allocates x * y + z byes. Notes: Merged: https://github.com/ruby/ruby/pull/2540
2019-10-04iseq.c (rb_iseq_compile_on_base): RemovedYusuke Endoh
ko1 cannot remember why he introduced the function. And it is not used. After it is removed, the argument "base_block" of rb_iseq_compile_with_option is always zero.
2019-10-04iseq.c (rb_iseq_compile_with_option): dummy parent_iseq for the parserYusuke Endoh
The parsing of `RubyVM::InstructionSequence.compile` does not support an outer scope currently. So it specified NULL as parent_iseq for the parser. However, it resulted in the following false-positive warning. ``` RubyVM::InstructionSequence.compile(<<END) o = Object.new o #=> <compiled>:2: warning: possibly useless use of a variable in void context END ``` This change specifies a dummy empty parent_iseq instead of NULL, which suppresses the false positive.
2019-10-04Make parser_params have parent_iseq instead of base_blockYusuke Endoh
The parser needs to determine whether a local varaiable is defined or not in outer scope. For the sake, "base_block" field has kept the outer block. However, the whole block was actually unneeded; the parser used only base_block->iseq. So, this change lets parser_params have the iseq directly, instead of the whole block. Notes: Merged: https://github.com/ruby/ruby/pull/2519
2019-09-27Adjusted spaces [ci skip]Nobuyoshi Nakada
2019-09-26Remove mark arrayAaron Patterson
We don't use this array anymore so we can remove it
2019-09-26Scan the ISEQ arena for markables and mark themAaron Patterson
This commit scans the ISEQ arena for objects that can be marked and marks them. This should make the mark array unnecessary.
2019-09-26Introduce a secondary arenaAaron Patterson
We'll scan the secondary arena during GC mark. So, we should only allocate "markable" instruction linked list nodes out of the secondary arena.
2019-09-26Extract allocation and free functionsAaron Patterson
Now we can allocate and free a secondary arena.
2019-08-30Make Method/Proc#parameters handle **nil syntaxJeremy Evans
Use a [:nokey] entry in this case. Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-30Constified local variable `translator`Nobuyoshi Nakada
2019-08-30Adjust indent [ci skip]Nobuyoshi Nakada
2019-08-27decouple compile.c usage of imemo_ifunc卜部昌平
After 5e86b005c0f2ef30df2f9906c7e2f3abefe286a2, I now think ANYARGS is dangerous and should be extinct. This commit deletes ANYARGS from struct vm_ifunc, but in doing so we also have to decouple the usage of this struct in compile.c, which (I think) is an abuse of ANYARGS.
2019-08-19Update moved objects in original_iseqAlan Wu
Without doing this, enabling a TracePoint on a method could lead to use of moved objects. This was found by running `env RUBY_ISEQ_DUMP_DEBUG=to_binary make test-all`, which sets orignal_iseq then runs the compaction tests and the tracepoint tests. Please excuse the lack of tests. I was not able to figure out how to reliably trigger a move on a specific iseq imemo to make a good regression test. To manually confirm the problem and this fix, you can run: ``` env RUBY_ISEQ_DUMP_DEBUG=to_binary make test-all \ TESTOPTS="test/ruby/test_gc_compact.rb \ test/gdbm/test_gdbm.rb \ test/ruby/test_settracefunc.rb" ``` Or the following script: ```ruby tp = TracePoint.new(:line) {} 1.times do # put it in a block to not keep these objects alive objects = 10_000.times.map { Object.new } objects.hash end 1.times do # this allocation pattern can realistically happen in an app # at load time beek = 10_000.times.map do eval(<<-RUBY) def foo a + b 1.times { 4 + 234234 } nil + 234 end RUBY Object.new Object.new end beek.hash end tp.enable(target: self.:foo) { 234 } # allocate original iseq GC.verify_compaction_references(toward: :empty) GC.compact tp.enable(target: self.:foo) { 234234 } # crash ``` [Bug #16098] Notes: Merged: https://github.com/ruby/ruby/pull/2391
2019-08-19Make it as clear as possible that RubyVM is MRI-specific and only exists on ↵Benoit Daloze
MRI (#2113) [ci skip] * Make it clear as possible that RubyVM is MRI-specific and only exists on MRI * See [Bug #15743]. * Use "CRuby VM" instead of "Ruby VM" for clarity. * Use YARV rather than "CRuby VM" for documenting RubyVM::InstructionSequence * Avoid introducing a new "CRuby VM" term in documentation
2019-08-12Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson
Renaming this function. "No pin" leaks some implementation details. We just want users to know that if they mark this object, the reference may move and they'll need to update the reference accordingly.
2019-08-13* expand tabs.git
2019-08-12Unpin default value objectsAaron Patterson
We're already updating the location of default values, so we may as well unpin them.
2019-08-05Document that RubyVM::InstructionSequence methods are implementation and ↵Jeremy Evans
version dependent Fixes [Bug #6785]
2019-07-23check iseq is executableKoichi Sasada
2019-07-23Let memory sizes of the various IMEMO object types be reflected correctlyLourens Naudé
[Feature #15805] Closes: https://github.com/ruby/ruby/pull/2140
2019-05-31Use UNALIGNED_MEMBER_PTRNobuyoshi Nakada
* internal.h (UNALIGNED_MEMBER_ACCESS, UNALIGNED_MEMBER_PTR): moved from eval_intern.h. * compile.c iseq.c, vm.c: use UNALIGNED_MEMBER_PTR for `entries` in `struct iseq_catch_table`. * vm_eval.c, vm_insnhelper.c: use UNALIGNED_MEMBER_PTR for `body` in `rb_method_definition_t`.
2019-05-29Fix Possible Control flow issues (DEADCODE)Kazuhiro NISHIYAMA
Coverity Scan says `Execution cannot reach this statement: "poison_object(v);"`, so do nothing when `ptr` is always 0 without address_sanitizer.
2019-05-23prefix ASAN related inline functions asan_Urabe, Shyouhei
requested by Ko1.
2019-05-18Rename rb_gc_new_location to rb_gc_locationAaron Patterson
The function will return new or existing locations depending on whether or not the object actually moved, so give it a more appropriate name.
2019-04-29iseq.c: removed unnecessary zero-fillsNobuyoshi Nakada
2019-04-25Lazy allocate the compile data catch table arrayLourens Naudé
Closes: https://github.com/ruby/ruby/pull/2119
2019-04-23* expand tabs.git
2019-04-22Symbols can move, so don't cache in static pointerAaron Patterson
This changes the static pointers to use IDs then look up the symbols with the ID. Symbols can move, so we don't want to keep static references to them.
2019-04-20Update MJIT referencestenderlove
ISeq can move, so we need to tell MJIT where the new location is. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67624 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-20Add `GC.compact` again.tenderlove
🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17Reverting compaction for nowtenderlove
For some reason symbols (or classes) are being overridden in trunk git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67598 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-17Adding `GC.compact` and compacting GC support.tenderlove
This commit adds the new method `GC.compact` and compacting GC support. Please see this issue for caveats: https://bugs.ruby-lang.org/issues/15626 [Feature #15626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67576 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-11Share the exception local ID tablenobu
[Fix GH-2115] From: Lourens Naudé <lourens@bearmetal.eu> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67511 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10Reverting all commits from r67479 to r67496 because of CI failureskazu
Because hard to specify commits related to r67479 only. So please commit again. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67499 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-10Adjusted stylesnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-09Adding `GC.compact` and compacting GC support.tenderlove
This commit adds the new method `GC.compact` and compacting GC support. Please see this issue for caveats: https://bugs.ruby-lang.org/issues/15626 [Feature #15626] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-01* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67406 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-04-01unpoison / poison objects while walking the heaptenderlove
This fixes some ASAN errors git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-09Fix styles [ci skip]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-23iseq.c: avoid Null pointer dereferencek0kubun
detected by coverity scan git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66500 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-20iseq.c: resurrect literal hash operandsnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Return same ISeq object for one src.ko1
* iseq.c: before this patch, RubyVM::InstructionSequence.of(src) (ISeq in short) returns different ISeq (wrapper) objects point to one ISeq internal object. This patch changes this behavior to cache created ISeq (wrapper) objects and return same ISeq object for an internal ISeq object. * iseq.h (ISEQ_EXECUTABLE_P): introduced to check executable ISeq objects. * iseq.h (ISEQ_COMPILE_DATA_ALLOC): reordr setting flag line to avoid ISEQ_USE_COMPILE_DATA but compiled_data == NULL case. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::wrapper` and `rb_iseq_t::aux::exec`. Move `rb_iseq_t::local_hooks` to `rb_iseq_t::aux::exec::local_hooks`. * test/ruby/test_iseq.rb: add ISeq.of() tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66246 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-06Prefer rb_check_arity when 0 or 1 argumentsnobu
Especially over checking argc then calling rb_scan_args just to raise an ArgumentError. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66238 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27Add rb_typeddata_is_instance_ofnobu
Similar to rb_typeddata_is_kind_of, except for that inherited type is not an instance. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66019 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27fix for ISeq.of(method).ko1
* iseq.c (iseqw_s_of): `rb_method_iseq(method)` can return NULL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66017 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-27* expand tabs.svn
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e