aboutsummaryrefslogtreecommitdiffstats
path: root/iseq.c
Commit message (Collapse)AuthorAgeFilesLines
* Fixed misspellingsNobuyoshi Nakada2019-12-201-2/+2
| | | | Fixed misspellings reported at [Bug #16437], only in ruby and rubyspec.
* vm_core.h (iseq_unique_id): prefer uintptr_t instead of unsigned longYusuke Endoh2019-12-101-1/+1
| | | | It produced a warning about type cast in LLP64 (i.e., windows).
* vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointerYusuke Endoh2019-12-091-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | (This is the second try of 036bc1da6c6c9b0fa9b7f5968d897a9554dd770e.) If iseq is GC'ed, the pointer of iseq may be reused, which may hide a deprecation warning of keyword argument change. http://ci.rvm.jp/results/trunk-test1@phosphorus-docker/2474221 ``` 1) Failure: TestKeywordArguments#test_explicit_super_kwsplat [/tmp/ruby/v2/src/trunk-test1/test/ruby/test_keyword.rb:549]: --- expected +++ actual @@ -1 +1 @@ -/The keyword argument is passed as the last hash parameter.* for `m'/m +"" ``` This change ad-hocly adds iseq_unique_id for each iseq, and use it instead of iseq pointer. This covers the case where caller is GC'ed. Still, the case where callee is GC'ed, is not covered. But anyway, it is very rare that iseq is GC'ed. Even when it occurs, it just hides some warnings. It's no big deal.
* Revert "vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointer"Yusuke Endoh2019-12-091-3/+0
| | | | | | | | | This reverts commit 036bc1da6c6c9b0fa9b7f5968d897a9554dd770e. This caused a failure on iseq_binary mode. http://ci.rvm.jp/results/trunk-iseq_binary@silicon-docker/2474587 Numbering iseqs is not trivial due to dump/load.
* vm_args.c (rb_warn_check): Use iseq_unique_id instead of its pointerYusuke Endoh2019-12-091-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | If iseq is GC'ed, the pointer of iseq may be reused, which may hide a deprecation warning of keyword argument change. http://ci.rvm.jp/results/trunk-test1@phosphorus-docker/2474221 ``` 1) Failure: TestKeywordArguments#test_explicit_super_kwsplat [/tmp/ruby/v2/src/trunk-test1/test/ruby/test_keyword.rb:549]: --- expected +++ actual @@ -1 +1 @@ -/The keyword argument is passed as the last hash parameter.* for `m'/m +"" ``` This change ad-hocly adds iseq_unique_id for each iseq, and use it instead of iseq pointer. This covers the case where caller is GC'ed. Still, the case where callee is GC'ed, is not covered. But anyway, it is very rare that iseq is GC'ed. Even when it occurs, it just hides some warnings. It's no big deal.
* Introduce an "Inline IVAR cache" structAaron Patterson2019-12-051-0/+2
| | | | | | | | | This commit introduces an "inline ivar cache" struct. The reason we need this is so compaction can differentiate from an ivar cache and a regular inline cache. Regular inline caches contain references to `VALUE` and ivar caches just contain references to the ivar index. With this new struct we can easily update references for inline caches (but not inline var caches as they just contain an int)
* make functions static卜部昌平2019-11-191-2/+2
| | | | | | | These functions are used from within a compilation unit so we can make them static, for better binary size. This changeset reduces the size of generated ruby binary from 26,590,128 bytes to 26,584,472 bytes on my macihne.
* Clarify documentation for `InstructionSequence#compile`.Samuel Williams2019-11-191-2/+14
| | | | | | | | We incorrectly assumed that the `file` argument should be the file name and caused https://github.com/scoutapp/scout_apm_ruby/issues/307 because exception backtrace did not contain correct path. This documentation clarifies the role of the different arguments and provides extra examples.
* Warn on access/modify of $SAFE, and remove effects of modifying $SAFEJeremy Evans2019-11-181-10/+0
| | | | | | | | | | | | | | | | | This removes the security features added by $SAFE = 1, and warns for access or modification of $SAFE from Ruby-level, as well as warning when calling all public C functions related to $SAFE. This modifies some internal functions that took a safe level argument to no longer take the argument. rb_require_safe now warns, rb_require_string has been added as a version that takes a VALUE and does not warn. One public C function that still takes a safe level argument and that this doesn't warn for is rb_eval_cmd. We may want to consider adding an alternative method that does not take a safe level argument, and warn for rb_eval_cmd.
* delete unused functions卜部昌平2019-11-141-14/+0
| | | | | | | | | | | | Looking at the list of symbols inside of libruby-static.a, I found hundreds of functions that are defined, but used from nowhere. There can be reasons for each of them (e.g. some functions are specific to some platform, some are useful when debugging, etc). However it seems the functions deleted here exist for no reason. This changeset reduces the size of ruby binary from 26,671,456 bytes to 26,592,864 bytes on my machine.
* Avoid top-level search for nested constant reference from nil in defined?Dylan Thacker-Smith2019-11-131-6/+13
| | | | | | | | | | | | Fixes [Bug #16332] Constant access was changed to no longer allow top-level constant access through `nil`, but `defined?` wasn't changed at the same time to stay consistent. Use a separate defined type to distinguish between a constant referenced from the current lexical scope and one referenced from another namespace.
* Support RB_BUILTIN in ISeq#to_aTakashi Kokubun2019-11-091-0/+15
|
* builtin.h must be included *AFTER* vm_core.hNobuyoshi Nakada2019-11-081-1/+1
|
* support builtin features with Ruby and C.Koichi Sasada2019-11-081-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Support loading builtin features written in Ruby, which implement with C builtin functions. [Feature #16254] Several features: (1) Load .rb file at boottime with native binary. Now, prelude.rb is loaded at boottime. However, this file is contained into the interpreter as a text format and we need to compile it. This patch contains a feature to load from binary format. (2) __builtin_func() in Ruby call func() written in C. In Ruby file, we can write `__builtin_func()` like method call. However this is not a method call, but special syntax to call a function `func()` written in C. C functions should be defined in a file (same compile unit) which load this .rb file. Functions (`func` in above example) should be defined with (a) 1st parameter: rb_execution_context_t *ec (b) rest parameters (0 to 15). (c) VALUE return type. This is very similar requirements for functions used by rb_define_method(), however `rb_execution_context_t *ec` is new requirement. (3) automatic C code generation from .rb files. tool/mk_builtin_loader.rb creates a C code to load .rb files needed by miniruby and ruby command. This script is run by BASERUBY, so *.rb should be written in BASERUBY compatbile syntax. This script load a .rb file and find all of __builtin_ prefix method calls, and generate a part of C code to export functions. tool/mk_builtin_binary.rb creates a C code which contains binary compiled Ruby files needed by ruby command.
* Right size the compile option hashLourens Naudé2019-10-291-1/+1
|
* Pin labels during disassemblyAaron Patterson2019-10-281-4/+20
| | | | | | | 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.
* Combine call info and cache to speed up method invocationAlan Wu2019-10-241-27/+18
| | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* avoid overflow in integer multiplication卜部昌平2019-10-091-2/+5
| | | | | | | 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.
* iseq.c (rb_iseq_compile_on_base): RemovedYusuke Endoh2019-10-041-20/+7
| | | | | | | 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.
* iseq.c (rb_iseq_compile_with_option): dummy parent_iseq for the parserYusuke Endoh2019-10-041-1/+8
| | | | | | | | | | | | | | | | 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.
* Make parser_params have parent_iseq instead of base_blockYusuke Endoh2019-10-041-1/+1
| | | | | | | | | | | | 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.
* Adjusted spaces [ci skip]Nobuyoshi Nakada2019-09-271-2/+2
|
* Remove mark arrayAaron Patterson2019-09-261-4/+0
| | | | We don't use this array anymore so we can remove it
* Scan the ISEQ arena for markables and mark themAaron Patterson2019-09-261-0/+3
| | | | | This commit scans the ISEQ arena for objects that can be marked and marks them. This should make the mark array unnecessary.
* Introduce a secondary arenaAaron Patterson2019-09-261-3/+5
| | | | | | We'll scan the secondary arena during GC mark. So, we should only allocate "markable" instruction linked list nodes out of the secondary arena.
* Extract allocation and free functionsAaron Patterson2019-09-261-17/+30
| | | | Now we can allocate and free a secondary arena.
* Make Method/Proc#parameters handle **nil syntaxJeremy Evans2019-08-301-0/+6
| | | | Use a [:nokey] entry in this case.
* Constified local variable `translator`Nobuyoshi Nakada2019-08-301-12/+5
|
* Adjust indent [ci skip]Nobuyoshi Nakada2019-08-301-26/+26
|
* decouple compile.c usage of imemo_ifunc卜部昌平2019-08-271-4/+6
| | | | | | | 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.
* Update moved objects in original_iseqAlan Wu2019-08-191-0/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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]
* Make it as clear as possible that RubyVM is MRI-specific and only exists on ↵Benoit Daloze2019-08-191-2/+4
| | | | | | | | | | | | | 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
* Rename rb_gc_mark_no_pin -> rb_gc_mark_movableAaron Patterson2019-08-121-8/+8
| | | | | | 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.
* * expand tabs.git2019-08-131-1/+1
|
* Unpin default value objectsAaron Patterson2019-08-121-1/+1
| | | | | We're already updating the location of default values, so we may as well unpin them.
* Document that RubyVM::InstructionSequence methods are implementation and ↵Jeremy Evans2019-08-051-1/+3
| | | | | | version dependent Fixes [Bug #6785]
* check iseq is executableKoichi Sasada2019-07-231-28/+28
|
* Let memory sizes of the various IMEMO object types be reflected correctlyLourens Naudé2019-07-231-3/+3
| | | | | | [Feature #15805] Closes: https://github.com/ruby/ruby/pull/2140
* Use UNALIGNED_MEMBER_PTRNobuyoshi Nakada2019-05-311-5/+8
| | | | | | | | | | | * 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`.
* Fix Possible Control flow issues (DEADCODE)Kazuhiro NISHIYAMA2019-05-291-6/+2
| | | | | Coverity Scan says `Execution cannot reach this statement: "poison_object(v);"`, so do nothing when `ptr` is always 0 without address_sanitizer.
* prefix ASAN related inline functions asan_Urabe, Shyouhei2019-05-231-6/+6
| | | | requested by Ko1.
* Rename rb_gc_new_location to rb_gc_locationAaron Patterson2019-05-181-10/+10
| | | | | The function will return new or existing locations depending on whether or not the object actually moved, so give it a more appropriate name.
* iseq.c: removed unnecessary zero-fillsNobuyoshi Nakada2019-04-291-2/+3
|
* Lazy allocate the compile data catch table arrayLourens Naudé2019-04-251-1/+1
| | | | Closes: https://github.com/ruby/ruby/pull/2119
* * expand tabs.git2019-04-231-2/+2
|
* Symbols can move, so don't cache in static pointerAaron Patterson2019-04-221-7/+7
| | | | | | 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.
* Update MJIT referencestenderlove2019-04-201-0/+3
| | | | | | 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
* Add `GC.compact` again.tenderlove2019-04-201-18/+82
| | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting compaction for nowtenderlove2019-04-171-82/+18
| | | | | | 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
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-171-18/+82
| | | | | | | | | | | 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