summaryrefslogtreecommitdiff
path: root/vm.c
AgeCommit message (Collapse)Author
2019-12-05fix parameterKoichi Sasada
2019-11-18Deprecate taint/trust and related methods, and make the methods no-opsJeremy Evans
This removes the related tests, and puts the related specs behind version guards. This affects all code in lib, including some libraries that may want to support older versions of Ruby. Notes: Merged: https://github.com/ruby/ruby/pull/2476
2019-11-08support builtin features with Ruby and C.Koichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/2655
2019-11-06Remove duplicate codeAaron Patterson
These functions are the same, so remove one. Co-authored-by: John Hawthorn <john@hawthorn.email>
2019-10-29Right size the vm_default_params hashLourens Naudé
Notes: Merged: https://github.com/ruby/ruby/pull/2592
2019-10-03Revert https://github.com/ruby/ruby/pull/2486卜部昌平
This reverts commits: 10d6a3aca7 8ba48c1b85 fba8627dc1 dd883de5ba 6c6a25feca 167e6b48f1 7cb96d41a5 3207979278 595b3c4fdd 1521f7cf89 c11c5e69ac cf33608203 3632a812c0 f56506be0d 86427a3219 . The reason for the revert is that we observe ABA problem around inline method cache. When a cache misshits, we search for a method entry. And if the entry is identical to what was cached before, we reuse the cache. But the commits we are reverting here introduced situations where a method entry is freed, then the identical memory region is used for another method entry. An inline method cache cannot detect that ABA. Here is a code that reproduce such situation: ```ruby require 'prime' class << Integer alias org_sqrt sqrt def sqrt(n) raise end GC.stress = true Prime.each(7*37){} rescue nil # <- Here we populate CC class << Object.new; end # These adjacent remove-then-alias maneuver # frees a method entry, then immediately # reuses it for another. remove_method :sqrt alias sqrt org_sqrt end Prime.each(7*37).to_a # <- SEGV ```
2019-09-30refactor constify most of rb_method_entry_t卜部昌平
Now that we have eliminated most destructive operations over the rb_method_entry_t / rb_callable_method_entry_t, let's make them mostly immutabe and mark them const. One exception is rb_export_method(), which destructively modifies visibilities of method entries. I have left that operation as is because I suspect that destructiveness is the nature of that function. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor delete vm_cref_dump卜部昌平
No longer used. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-29Remove VM_NO_KEYWORDS, replace with RB_NO_KEYWORDSJeremy Evans
VM_NO_KEYWORDS was introduced first in vm_core.h, but it is best to only use a single definition for this.
2019-09-26Fix more keyword separation issuesJeremy Evans
This fixes instance_exec and similar methods. It also fixes Enumerator::Yielder#yield, rb_yield_block, and a couple of cases with Proc#{<<,>>}. This support requires the addition of rb_yield_values_kw, similar to rb_yield_values2, for passing the keyword flag. Unlike earlier attempts at this, this does not modify the rb_block_call_func type or add a separate function type. The functions of type rb_block_call_func are called by Ruby with a separate VM frame, and we can get the keyword flag information from the VM frame flags, so it doesn't need to be passed as a function argument. These changes require the following VM functions accept a keyword flag: * vm_yield_with_cref * vm_yield * vm_yield_with_block Notes: Merged: https://github.com/ruby/ruby/pull/2493
2019-09-24suppress meddlesome clang10 warrning卜部昌平
It says: vm.c:2519:34: warning: expression does not compute the number of elements in this array; element type is 'const struct __jmp_buf_tag', not 'VALUE' (aka 'unsigned long') [-Wsizeof-array-div] sizeof(ec->machine.regs) / sizeof(VALUE)); ~~~~~~~~~~~~~~~~ ^ vm.c:2519:34: note: place parentheses around the 'sizeof(VALUE)' expression to silence this warning
2019-09-24refactor delete unused variable卜部昌平
cadfaacb2533d47d52dbb5dbefe724d7bf11112e missed it.
2019-09-23Lazy init thread local storageLourens Naudé
Notes: Merged: https://github.com/ruby/ruby/pull/2295
2019-09-06Convert keyword argument to required positional hash argument for Class#new, ↵Jeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2432
2019-09-05Add VM_NO_KEYWORDSJeremy Evans
I think this is easier to read than using literal 0 with comments in every case where it is used.
2019-09-05Propagate kw_splat informationYusuke Endoh
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.
2019-09-03Merge pull request #2422 from jeremyevans/rb_keyword_given_pJeremy Evans
Add rb_keyword_given_p to the C-API Notes: Merged-By: jeremyevans <code@jeremyevans.net>
2019-08-30Allow ** syntax to be used for calling methods that do not accept keywordsJeremy Evans
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. Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-30Separate keyword arguments from positional argumentsYusuke Endoh
And, allow non-symbol keys as a keyword arugment Notes: Merged: https://github.com/ruby/ruby/pull/2395
2019-08-29drop-in type check for rb_define_singleton_method卜部昌平
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.
2019-08-29drop-in type check for rb_define_method_id卜部昌平
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.
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-08solve "duplicate :raise event" [Bug #15877]Koichi Sasada
Without this patch, "raise" event invoked twice when raise an exception in "load"ed script. This patch by danielwaterworth (Daniel Waterworth). [Bug #15877]
2019-08-08Add *_clear methods to VM_COLLECT_USAGE_DETAILS APIGannon McGibbon
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
2019-08-08Add *_start and *_running methods to VM_COLLECT_USAGE_DETAILS APIGannon McGibbon
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
2019-08-07Add a way to print debug counters without exitingAaron Patterson
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)
2019-08-02Revert "Revert "Add a specialized instruction for `.nil?` calls""Yusuke Endoh
This reverts commit a0980f2446c0db735b8ffeb37e241370c458a626. Retry for macOS Mojave.
2019-08-02Revert "Add a specialized instruction for `.nil?` calls"Yusuke Endoh
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.
2019-08-01Make attr* methods define public methods if self in caller is not same as ↵Jeremy Evans
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]
2019-08-01calc_lineno(): add assertions卜部昌平
This function has a lot of assumptions. Should make them sure.
2019-07-31Add a specialized instruction for `.nil?` callsAaron Patterson
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>
2019-07-24Clarify Thread exception handling documentation [ci skip]Jeremy Evans
From djellemah (John Anderson). Fixes [Bug #12252]
2019-07-19In some situations, `vm_stack` can be NULL, but `cfp` is valid.Samuel Williams
2019-07-19Better usage of `rb_ec_clear_vm_stack` to maintain invariants.Samuel Williams
2019-07-19Improve ec assertions.Samuel Williams
2019-07-19Remove `rb_vm_push_frame` as it is no longer used.Samuel Williams
2019-07-18Remove unused vm_stack recycling.Samuel Williams
2019-07-14MJIT Support for getblockparamproxyTakashi Kokubun
2019-07-13Document $LOAD_PATH.resolve_feature_path in globals.rdocBenoit Daloze
* RDoc does not seem to support documenting singleton object methods, and making $LOAD_PATH a class as a workaround is too weird.
2019-07-11$LOAD_PATH.resolve_feature_pathNobuyoshi Nakada
Moved from RubyVM. [Feature #15903]
2019-06-20Ensure that vm_stack is cleared in `thread_cleanup_func_before_exec`.Samuel Williams
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.
2019-06-20Revert failed attempt at fixing invalid usage of vm_stack.Samuel Williams
2019-06-20Don't clear cfp, it causes problems.Samuel Williams
2019-06-20Ensure `vm_stack` is cleared after fork.Samuel Williams
2019-06-20Don't try to dereference NULL cfp.Samuel Williams
2019-06-19Adjust indentNobuyoshi Nakada
2019-06-19Remove IA64 support.Samuel Williams
2019-06-19Use shared implementation of `rb_ec_initialize_vm_stack`.Samuel Williams
2019-06-19Basic assertions for thread initialization.Samuel Williams