aboutsummaryrefslogtreecommitdiffstats
path: root/vm.c
Commit message (Collapse)AuthorAgeFilesLines
* Convert keyword argument to required positional hash argument for Class#new, ↵Jeremy Evans2019-09-061-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Method#call, UnboundMethod#bind_call Also add keyword argument separation warnings for Class#new and Method#call. To allow for keyword argument to required positional hash converstion in cfuncs, add a vm frame flag indicating the cfunc was called with an empty keyword hash (which was removed before calling the cfunc). The cfunc can check this frame flag and add back an empty hash if it is passing its arguments to another Ruby method. Add rb_empty_keyword_given_p function for checking if called with an empty keyword hash, and rb_add_empty_keyword for adding back an empty hash to argv. All of this empty keyword argument support is only for 2.7. It will be removed in 3.0 as Ruby 3 will not convert empty keyword arguments to required positional hash arguments. Comment all of the relevent code to make it obvious this is expected to be removed. Add rb_funcallv_kw as an public C-API function, just like rb_funcallv but with a keyword flag. This is used by rb_obj_call_init (internals of Class#new). This also required expected call_type enum with CALL_FCALL_KW, similar to the recent addition of CALL_PUBLIC_KW. Add rb_vm_call_kw as a internal function, used by call_method_data (internals of Method#call and UnboundMethod#bind_call). Add tests for UnboundMethod#bind_call keyword handling.
* Add VM_NO_KEYWORDSJeremy Evans2019-09-051-4/+4
| | | | | I think this is easier to read than using literal 0 with comments in every case where it is used.
* Propagate kw_splat informationYusuke Endoh2019-09-051-25/+25
| | | | | | | The kw_splat flag is whether the original call passes keyword or not. Some types of methods (e.g., bmethod and sym_proc) drops the information. This change tries to propagate the flag to the final callee, as far as I can.
* Merge pull request #2422 from jeremyevans/rb_keyword_given_pJeremy Evans2019-09-031-0/+6
| | | Add rb_keyword_given_p to the C-API
* Allow ** syntax to be used for calling methods that do not accept keywordsJeremy Evans2019-08-301-5/+0
| | | | | | | | Treat the ** syntax as passing a copy of the hash as the last positional argument. If the hash being double splatted is empty, do not add a positional argument. Remove rb_no_keyword_hash, no longer needed.
* Separate keyword arguments from positional argumentsYusuke Endoh2019-08-301-10/+6
| | | | And, allow non-symbol keys as a keyword arugment
* drop-in type check for rb_define_singleton_method卜部昌平2019-08-291-2/+8
| | | | | | We can check the function pointer passed to rb_define_singleton_method like how we do so in rb_define_method. Doing so revealed many arity mismatches.
* drop-in type check for rb_define_method_id卜部昌平2019-08-291-3/+21
| | | | | | We can check the function pointer passed to rb_define_method_id like how we do so in rb_define_method. This method is relatively rarely used so there are less problems found than the other APIs.
* Make it as clear as possible that RubyVM is MRI-specific and only exists on ↵Benoit Daloze2019-08-191-5/+18
| | | | | | | | | | | | | 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-4/+4
| | | | | | 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.
* solve "duplicate :raise event" [Bug #15877]Koichi Sasada2019-08-081-2/+0
| | | | | | | Without this patch, "raise" event invoked twice when raise an exception in "load"ed script. This patch by danielwaterworth (Daniel Waterworth). [Bug #15877]
* Add *_clear methods to VM_COLLECT_USAGE_DETAILS APIGannon McGibbon2019-08-081-0/+53
| | | | | | | Add RubyVM::USAGE_ANALYSIS_INSN_CLEAR, RubyVM::USAGE_ANALYSIS_OPERAND_CLEAR, and RubyVM::USAGE_ANALYSIS_REGISTER_CLEAR to clear VM instruction hash constants. Closes: https://github.com/ruby/ruby/pull/2258
* Add *_start and *_running methods to VM_COLLECT_USAGE_DETAILS APIGannon McGibbon2019-08-081-3/+63
| | | | | | | | | | | Add RubyVM::USAGE_ANALYSIS_INSN_START, RubyVM::USAGE_ANALYSIS_OPERAND_START, and RubyVM::USAGE_ANALYSIS_REGISTER_START to begin collecting VM instructions. Add RubyVM::USAGE_ANALYSIS_INSN_RUNNING, RubyVM::USAGE_ANALYSIS_OPERAND_RUNNING, and RubyVM::USAGE_ANALYSIS_REGISTER_RUNNING to check if VM instructions are being collected. Closes: https://github.com/ruby/ruby/pull/2258
* Add a way to print debug counters without exitingAaron Patterson2019-08-071-0/+1
| | | | | | | | I am trying to study debug counters inside a Rails application. Accessing debug counters by killing the process is hard because child processes don't get the same TRAP as the parent, and Rails seems to intercept calls to `exit`. Adding this method lets me print the debug counters when I want (at the end of requests for example)
* Revert "Revert "Add a specialized instruction for `.nil?` calls""Yusuke Endoh2019-08-021-0/+1
| | | | | | This reverts commit a0980f2446c0db735b8ffeb37e241370c458a626. Retry for macOS Mojave.
* Revert "Add a specialized instruction for `.nil?` calls"Yusuke Endoh2019-08-021-1/+0
| | | | | | | | | | This reverts commit 9faef3113fb4331524b81ba73005ba13fa0ef6c6. It seemed to cause a failure on macOS Mojave, though I'm unsure how. https://rubyci.org/logs/rubyci.s3.amazonaws.com/osx1014/ruby-master/log/20190802T034503Z.fail.html.gz This tentative revert is to check if the issue is actually caused by the change or not.
* Make attr* methods define public methods if self in caller is not same as ↵Jeremy Evans2019-08-011-1/+1
| | | | | | | | | | | | receiver Previously, attr* methods could be private even if not in the private section of a class/module block. This uses the same approach that ruby started using for define_method in 1fc33199736f316dd71d0c551edbf514528ddde6. Fixes [Bug #4537]
* calc_lineno(): add assertions卜部昌平2019-08-011-1/+1
| | | | This function has a lot of assumptions. Should make them sure.
* Add a specialized instruction for `.nil?` callsAaron Patterson2019-07-311-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit adds a specialized instruction for called to `.nil?`. It is about 27% faster than master in the case where the object is nil or not nil. In the case where an object implements `nil?`, I think it may be slightly slower. Here is a benchmark: ```ruby require "benchmark/ips" class Niller def nil?; true; end end not_nil = Object.new xnil = nil niller = Niller.new Benchmark.ips do |x| x.report("nil?") { xnil.nil? } x.report("not nil") { not_nil.nil? } x.report("niller") { niller.nil? } end ``` On Ruby master: ``` [aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 429.195k i/100ms not nil 437.889k i/100ms niller 437.935k i/100ms Calculating ------------------------------------- nil? 20.166M (± 8.1%) i/s - 100.002M in 5.002794s not nil 20.046M (± 7.6%) i/s - 99.839M in 5.020086s niller 22.467M (± 6.1%) i/s - 112.111M in 5.013817s [aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 449.660k i/100ms not nil 433.836k i/100ms niller 443.073k i/100ms Calculating ------------------------------------- nil? 19.997M (± 8.8%) i/s - 99.375M in 5.020458s not nil 20.529M (± 7.0%) i/s - 102.385M in 5.020689s niller 21.796M (± 8.0%) i/s - 108.110M in 5.002300s [aaron@TC ~/g/ruby (master)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 402.119k i/100ms not nil 438.968k i/100ms niller 398.226k i/100ms Calculating ------------------------------------- nil? 20.050M (±12.2%) i/s - 98.519M in 5.008817s not nil 20.614M (± 8.0%) i/s - 102.280M in 5.004531s niller 22.223M (± 8.8%) i/s - 110.309M in 5.013106s ``` On this branch: ``` [aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 468.371k i/100ms not nil 456.517k i/100ms niller 454.981k i/100ms Calculating ------------------------------------- nil? 27.849M (± 7.8%) i/s - 138.169M in 5.001730s not nil 26.417M (± 8.7%) i/s - 131.020M in 5.011674s niller 21.561M (± 7.5%) i/s - 107.376M in 5.018113s [aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 477.259k i/100ms not nil 428.712k i/100ms niller 446.109k i/100ms Calculating ------------------------------------- nil? 28.071M (± 7.3%) i/s - 139.837M in 5.016590s not nil 25.789M (±12.9%) i/s - 126.470M in 5.011144s niller 20.002M (±12.2%) i/s - 98.144M in 5.001737s [aaron@TC ~/g/ruby (specialized-nilp)]$ ./ruby compil.rb Warming up -------------------------------------- nil? 467.676k i/100ms not nil 445.791k i/100ms niller 415.024k i/100ms Calculating ------------------------------------- nil? 26.907M (± 8.0%) i/s - 133.755M in 5.013915s not nil 25.319M (± 7.9%) i/s - 125.713M in 5.007758s niller 19.569M (±11.8%) i/s - 96.286M in 5.008533s ``` Co-Authored-By: Ashe Connor <kivikakk@github.com>
* Clarify Thread exception handling documentation [ci skip]Jeremy Evans2019-07-241-8/+19
| | | | | | From djellemah (John Anderson). Fixes [Bug #12252]
* In some situations, `vm_stack` can be NULL, but `cfp` is valid.Samuel Williams2019-07-191-4/+0
|
* Better usage of `rb_ec_clear_vm_stack` to maintain invariants.Samuel Williams2019-07-191-1/+1
|
* Improve ec assertions.Samuel Williams2019-07-191-9/+7
|
* Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams2019-07-191-1/+1
|
* Remove unused vm_stack recycling.Samuel Williams2019-07-181-36/+0
|
* MJIT Support for getblockparamproxyTakashi Kokubun2019-07-141-2/+1
|
* Document $LOAD_PATH.resolve_feature_path in globals.rdocBenoit Daloze2019-07-131-12/+0
| | | | | * RDoc does not seem to support documenting singleton object methods, and making $LOAD_PATH a class as a workaround is too weird.
* $LOAD_PATH.resolve_feature_pathNobuyoshi Nakada2019-07-111-4/+0
| | | | Moved from RubyVM. [Feature #15903]
* Ensure that vm_stack is cleared in `thread_cleanup_func_before_exec`.Samuel Williams2019-06-201-9/+25
| | | | | | | | If `vm_stack` is left dangling in a forked process, the gc attempts to scan it, but it is invalid and will cause a segfault. Therefore, we clear it before forking. In order to simplify this, `rb_ec_clear_vm_stack` was introduced.
* Revert failed attempt at fixing invalid usage of vm_stack.Samuel Williams2019-06-201-25/+9
|
* Don't clear cfp, it causes problems.Samuel Williams2019-06-201-1/+1
|
* Ensure `vm_stack` is cleared after fork.Samuel Williams2019-06-201-10/+26
|
* Don't try to dereference NULL cfp.Samuel Williams2019-06-201-1/+1
|
* Adjust indentNobuyoshi Nakada2019-06-191-4/+5
|
* Remove IA64 support.Samuel Williams2019-06-191-3/+0
|
* Use shared implementation of `rb_ec_initialize_vm_stack`.Samuel Williams2019-06-191-11/+17
|
* Basic assertions for thread initialization.Samuel Williams2019-06-191-0/+4
|
* Ensure execution context is cleared after thread is finished.Samuel Williams2019-06-191-3/+0
|
* Better handling of root fiber.Samuel Williams2019-06-191-1/+1
|
* Fix handling of vm_stack_size and avoid trying to deallocate it.Samuel Williams2019-06-191-7/+12
|
* Move vm stack init into thread.Samuel Williams2019-06-191-12/+11
|
* * expand tabs.git2019-06-121-16/+16
|
* Add compaction support for more types.Aaron Patterson2019-06-111-4/+47
| | | | | | | | This commit adds compaction support for: * Fibers * Continuations * Autoload Constants
* Make opt_aref instruction support Integer#[]Yusuke Endoh2019-06-011-1/+1
| | | | | | | | | | | | only when its receiver and the argument are both Integers. Since 6bedbf4625, Integer#[] has supported a range extraction. This means that Integer#[] now accepts multiple arguments, which made the method very slow unfortunately. This change fixes the performance issue by adding a special handling for its traditional use case: `num[idx]` where both `num` and `idx` are Integers.
* Use UNALIGNED_MEMBER_PTRNobuyoshi Nakada2019-05-311-5/+5
| | | | | | | | | | | * 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`.
* Keep vm->orig_progname aliveAlan Wu2019-05-311-0/+1
| | | | | | | | `vm->orig_progname` can be different from `vm->progname` when user code assigns to `$0`. While `vm->progname` is kept alive by the global table, nothing marked `vm->orig_progname`. [Bug #15887]
* Eagerly name modules and classesAlan Wu2019-05-221-3/+1
| | | | | | | | | | | | | | | | | | | | | | | * variable.c: make the hidden ivars `classpath` and `tmp_classpath` the source of truth for module and constant names. Assign to them when modules are bind to constants. * variable.c: remove references to module name cache, as what used to be the cache is now the source of truth. Remove rb_class_path_no_cache(). * variable.c: remove the hidden ivar `classid`. This existed for the purposes of module name search, which is now replaced. Also, remove the associated rb_name_class(). * class.c: use rb_set_class_path_string to set the name of Object during boot. Must use a fstring as this runs before rb_cString is initialized and creating a normal string leads to a VALUE without a class. * spec/ruby/core/module/name_spec.rb: add a few specs to specify what happens to Module#name across multiple operations. These specs pass without other code changes in this commit. [Feature #15765]
* Fixing function nameAaron Patterson2019-05-141-1/+1
| | | | | This function is used for marking / pinning vm stack values, so it should have "vm" in the function name to be more clear.
* Prevent rb_define_(class|module) classes from movingAaron Patterson2019-04-221-4/+6
| | | | | | | | | | | | Before this commit, classes and modules would be registered with the VM's `defined_module_hash`. The key was the ID of the class, but that meant that it was possible for hash collisions to occur. The compactor doesn't allow classes in the `defined_module_hash` to move, but if there is a conflict, then it's possible a class would be removed from the hash and not get pined. This commit changes the key / value of the hash just to be the class itself, thus preventing movement.
* Add `GC.compact` again.tenderlove2019-04-201-1/+30
| | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e