summaryrefslogtreecommitdiff
path: root/method.h
AgeCommit message (Collapse)Author
2019-10-03* expand tabs. [ci skip]git
Tabs were expanded because previously the file did not have any tab indentation. Please update your editor config, and use misc/expand_tabs.rb in the pre-commit hook.
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 add rb_method_entry_from_template卜部昌平
Tired of rb_method_entry_create(..., rb_method_definition_create( ..., &(rb_method_foo_t) {...})) maneuver. Provide a function that does the thing to reduce copy&paste. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor delete rb_method_entry_copy卜部昌平
The deleted function was to destructively overwrite existing method entries, which is now considered to be a bad idea. Delete it, and assign a newly created method entry instead. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor constify most of rb_method_definition_t卜部昌平
Most (if not all) of the fields of rb_method_definition_t are never meant to be modified once after they are stored. Marking them const makes it possible for compilers to warn on unintended modifications. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-09-30refactor delete METHOD_ENTRY_COMPLEMENTED flag卜部昌平
Because rb_method_definition_t tracks its own complemented_count, we no longer have to check it in rb_method_entry_t side. Notes: Merged: https://github.com/ruby/ruby/pull/2486
2019-07-23Stop packing rb_method_definition_tNobuyoshi Nakada
By using `BITFIELD`, `type` field should not be forced to align.
2019-05-31STATIC_ASSERT for VM_METHOD_TYPE_MINIMUM_BITSNobuyoshi Nakada
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-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-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-05`rb_add_method` is void function.ko1
* method.h (rb_add_method): make it void function because nobody use a return value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-02-22change `cfunc->invoker` type for opt.ko1
* vm_insnhelper.c: change `call_cfunc_*` parameters order and specify a function type for the passed func ptr. This fix reduce the number of asm instructions, such as: # before this patch 0000000000000110 <call_cfunc_0>: 110: 48 89 fa mov %rdi,%rdx 113: 31 c0 xor %eax,%eax 115: 48 89 f7 mov %rsi,%rdi 118: ff e2 jmpq *%rdx 11a: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1) # after this patch 0000000000000110 <call_cfunc_0>: 110: ff e1 jmpq *%rcx However, this kind of instruction reduction doesn't affect any performance because of great CPU architectures :p git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67122 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2019-01-28Add refinements support to method/instance_method.nobu
[Fix GH-2034] From: manga_osyo <manga.osyo@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-18Enable refinements on symbol-proc in ruby-level methodsnobu
* vm_args.c (refine_sym_proc_call): resolve refinements when the proc is invoked, instead of resolving at making the proc, to enable refinements on symbol-proc in ruby-level methods * vm.c (vm_cref_dup): clear cached symbol-procs when duplicating. [Bug #15114] [Fix GH-2039] From: manga_osyo <manga.osyo@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04Revert "Symbol refinements"mrkn
Due to assertion failures when VM_CHECK_MODE >= 2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66182 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-04Symbol refinementsmrkn
* vm_args.c (refine_sym_proc_call): enalbe accidentally disabled refinements in Symbol#to_proc. [Bug #15114] From: osyo (manga osyo) <manga.osyo@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66181 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03Revert "Symbol refinements"nobu
Due to assertion failures when VM_CHECK_MODE >= 2. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66155 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03Symbol refinementsnobu
* vm_args.c (refine_sym_proc_call): enalbe accidentally disabled refinements in Symbol#to_proc. [Bug #15114] From: osyo (manga osyo) <manga.osyo@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66151 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03Revert "Symbol refinements [Bug #15114]"nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-12-03Symbol refinements [Bug #15114]nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-11-26Support targetting TracePoint [Feature #15289]ko1
* vm_trace.c (rb_tracepoint_enable_for_target): support targetting TracePoint. [Feature #15289] Tragetting TracePoint is only enabled on specified method, proc and so on, example: `tp.enable(target: code)`. `code` should be consisted of InstructionSeuqnece (iseq) (RubyVM::InstructionSeuqnece.of(code) should not return nil) If code is a tree of iseq, TracePoint is enabled on all of iseqs in a tree. Enabled tragetting TracePoints can not enabled again with and without target. * vm_core.h (rb_iseq_t): introduce `rb_iseq_t::local_hooks` to store local hooks. `rb_iseq_t::aux::trace_events` is renamed to `global_trace_events` to contrast with `local_hooks`. * vm_core.h (rb_hook_list_t): add `rb_hook_list_t::running` to represent how many Threads/Fibers are used this list. If this field is 0, nobody using this hooks and we can delete it. This is why we can remove code from cont.c. * vm_core.h (rb_vm_t): because of above change, we can eliminate `rb_vm_t::trace_running` field. Also renamed from `rb_vm_t::event_hooks` to `global_hooks`. * vm_core.h, vm.c (ruby_vm_event_enabled_global_flags): renamed from `ruby_vm_event_enabled_flags. * vm_core.h, vm.c (ruby_vm_event_local_num): added to count enabled targetting TracePoints. * vm_core.h, vm_trace.c (rb_exec_event_hooks): accepts hook list. * vm_core.h (rb_vm_global_hooks): added for convinience. * method.h (rb_method_bmethod_t): added to maintain Proc and `rb_hook_list_t` for bmethod (defined by define_method). * prelude.rb (TracePoint#enable): extracet a keyword parameter (because it is easy than writing in C). It calls `TracePoint#__enable` internal method written in C. * vm_insnhelper.c (vm_trace): check also iseq->local_hooks. * vm.c (invoke_bmethod): check def->body.bmethod.hooks. * vm.c (hook_before_rewind): check iseq->local_hooks and def->body.bmethod.hooks before rewind by exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66003 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-08-22Avoid compiler depend errorkazu
ref r64492 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-06-03Add TracePoint#parametersmame
It can be used to get the parameters' information of method and block. There was no way to get block parameters. It was possible but ineffective to get method parameters via Method object: `tp.defined_class.method(tp.method_id).parameters` TracePoint#parameters allows us to get the information easily. [Feature #14694] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@63562 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-28method.h: VM_METHOD_TYPE_MINIMUM_BITSnobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-28method.h: BITFIELD in rb_method_definition_tnobu
* method.h (rb_method_definition_struct): use BITFIELD for rb_method_type_t. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-27internal.h: add BITFIELD macro to aid C99 usersnormal
I plan to use this macro to pack other enums in the VM. * internal.h: add BITFIELD macro * method.h: use BITFIELD for rb_method_visibility_t [ruby-core:85074] [Misc #14395] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-07Speedup `block.call` [Feature #14330]ko1
* insns.def (getblockparamproxy): introduce new instruction to return the `rb_block_param_proxy` object if possible. This object responds to `call` method and invoke given block (completely similar to `yield`). * method.h (OPTIMIZED_METHOD_TYPE_BLOCK_CALL): add new optimized call type which is for `rb_block_param_proxy.cal`. * vm_insnhelper.c (vm_call_method_each_type): ditto. * vm_insnhelper.c (vm_call_opt_block_call): ditto. * vm_core.h (BOP_CALL, PROC_REDEFINED_OP_FLAG): add check for `Proc#call` redefinition. * compile.c (iseq_compile_each0): compile to use new insn `getblockparamproxy` for method call. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-01-02bit-fields other than int is a C99ismshyouhei
To be precise C90 says "A bit-field may have type int, unsigned int, or signed int". It is clear that char or enum are NG. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61554 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05vm_core.h (rb_iseq_locatoin_t): add a field `code_range`mame
This change makes each ISeq keep NODE's code range. This information is needed for method coverage. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61025 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-05Revamp method coverage to support define_methodmame
Traditionally, method coverage measurement was implemented by inserting `trace2` instruction to the head of method iseq. So, it just measured methods defined by `def` keyword. This commit drastically changes the measuring mechanism of method coverage; at `RUBY_EVENT_CALL`, it keeps a hash from rb_method_entry_t* to runs (i.e., it counts the runs per method entry), and at `Coverage.result`, it creates the result hash by enumerating all `rb_method_entry_t*` objects (by `ObjectSpace.each_object`). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16make a func static.ko1
* vm_method.c (rb_resolve_refined_method_callable): make it static. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60808 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-11-16remove unused function.ko1
* vm_method.c (rb_method_entry_with_refinements): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60801 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-21Add doxygen commentssonots
* include/ruby/ruby.h (enum ruby_value_type): add doxygen comments * internal.h (enum imemo_type, struct vm_svar): add doxygen comments * method.h (rb_method_type_t, rb_method_iseq_t): add doxygen comments git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60285 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-10-06proc.c: super_method of included methodnobu
* proc.c (method_super_method): search the next super method along the included ancestor chain. [ruby-core:83114] [Bug #13973] * vm_method.c (rb_callable_method_entry_without_refinements): return the defined class. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60127 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-17Revert r59612nobu
* method.h (rb_method_definition_t): rb_method_type_t should be unsigned as it needs 5bits at least for signed extension. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59616 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-08-17method.h: enum rb_method_definition_t::typenobu
* method.h (rb_method_definition_t): define type as an enum for debugging. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59612 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-19specify unsigned (fix r58784).ko1
* method.h (rb_method_definition_t#type): specify unsigned explicitly. Some compilers (includes VC) returns negative value. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58788 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-05-19method.h: pack rb_method_definition_t structnormal
We only have 12 method types, so 4 bits is enough for rb_method_type_t. Size reductions: - x86-64 48 => 40 bytes - x86 28 => 24 bytes * method.h (enum method_optimized_type): split out for CPP (struct rb_method_definition struct): pack on unaligned systems (rb_method_definition_t): split typedef to help ctags [ruby-core:81236] [Feature #13494] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-11-05* eval.c, method.h, proc.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c:ktsj
TracePoint#method_id should return method_id, not callee_id. [ruby-core:77241] [Feature #12747] * test/ruby/test_settracefunc.rb: change accordingly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-18* method.h: introduce the folliwing field and macros.ko1
* rb_method_definition_t::complemented_count to count shared method entries because of complemented method entries and separate from alias_count. Shared `def' only by complemented method entries should not prevent method re-definition warning. * METHOD_ENTRY_COMPLEMENTED(me) to represent complemented method entry. * METHOD_ENTRY_COMPLEMENTED_SET(me) to check it as complemented me. * vm_insnhelper.c (aliased_callable_method_entry): should also check me->def->complemented_count. * vm_method.c (method_definition_addref_complement): add to count complemented method entries number. * vm_method.c (rb_method_definition_release): release `def' iff alias_count == 0 and complemented_count == 0. * test/ruby/test_module.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52636 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17revert r52614, r52615, r52617 because they cause serious errorsko1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17* method.h (METHOD_ENTRY_COMPLEMENTED(_SET)): introduced to recognizeko1
complemented method entries or not. There are some cases that callabe method entries do not have defined_class. * vm_method.c (rb_method_entry_complement_defined_class): use METHOD_ENTRY_COMPLEMENTED_SET(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-17* method.h: introduce rb_method_definition_t::complemented_count.ko1
* vm_method.c (method_definition_addref_complement): introduced. def->alias_count is used to decide warn or do not warn at method redefinition. Complented methods should not prevent redefiniton warnings. * vm_method.c (rb_method_definition_release): release def iff alias_count == 0 && complemented_count == 0. * test/ruby/test_module.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52614 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-13* method.h: constify rb_cref_t::scope_visi;ko1
* eval_intern.h (CREF_SCOPE_VISI_COPY): catch up this fix. * vm_method.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52561 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-08method.h: suppress warningsnobu
* method.h (METHOD_ENTRY_{VISI,BASIC,FLAGS}_SET): suppress shift-op-parentheses warnings. [Fix GH-1082] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2015-11-04* method.h: fix typo. Patch by @davydovantonhsbt
[fix GH-1076][ci skip] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52444 b2dd03c8-39d4-4d8f-98ff-823fe69b080e