aboutsummaryrefslogtreecommitdiffstats
path: root/method.h
Commit message (Collapse)AuthorAgeFilesLines
* per-method serial number卜部昌平2019-12-181-0/+1
| | | | | | | | | | | | | | | | | Methods and their definitions can be allocated/deallocated on-the-fly. One pathological situation is when a method is deallocated then another one is allocated immediately after that. Address of those old/new method entries/definitions can be the same then, depending on underlying malloc/free implementation. So pointer comparison is insufficient. We have to check the contents. To do so we introduce def->method_serial, which is an integer unique to that specific method definition. PS: Note that method_serial being uintptr_t rather than rb_serial_t is intentional. This is because rb_serial_t can be bigger than a pointer on a 32bit system (rb_serial_t is at least 64bit). In order to preserve old packing of struct rb_call_cache, rb_serial_t is inappropriate.
* make functions static卜部昌平2019-11-191-1/+0
| | | | | | | 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.
* delete unused functions卜部昌平2019-11-141-3/+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.
* * expand tabs. [ci skip]git2019-10-031-7/+7
| | | | | 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.
* Revert https://github.com/ruby/ruby/pull/2486卜部昌平2019-10-031-29/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 ```
* refactor constify most of rb_method_entry_t卜部昌平2019-09-301-36/+7
| | | | | | | | | | | 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.
* refactor add rb_method_entry_from_template卜部昌平2019-09-301-3/+2
| | | | | | 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.
* refactor delete rb_method_entry_copy卜部昌平2019-09-301-1/+2
| | | | | | 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.
* refactor constify most of rb_method_definition_t卜部昌平2019-09-301-20/+20
| | | | | | 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.
* refactor delete METHOD_ENTRY_COMPLEMENTED flag卜部昌平2019-09-301-2/+0
| | | | | Because rb_method_definition_t tracks its own complemented_count, we no longer have to check it in rb_method_entry_t side.
* Stop packing rb_method_definition_tNobuyoshi Nakada2019-07-231-2/+3
| | | | By using `BITFIELD`, `type` field should not be forced to align.
* STATIC_ASSERT for VM_METHOD_TYPE_MINIMUM_BITSNobuyoshi Nakada2019-05-311-1/+2
|
* Add `GC.compact` again.tenderlove2019-04-201-12/+12
| | | | | | 🙏 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Reverting compaction for nowtenderlove2019-04-171-12/+12
| | | | | | 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-12/+12
| | | | | | | | | | | 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
* Reverting all commits from r67479 to r67496 because of CI failureskazu2019-04-101-12/+12
| | | | | | | | 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
* Adding `GC.compact` and compacting GC support.tenderlove2019-04-091-12/+12
| | | | | | | | | | | 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
* `rb_add_method` is void function.ko12019-04-051-1/+1
| | | | | | | | * 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
* change `cfunc->invoker` type for opt.ko12019-02-221-1/+1
| | | | | | | | | | | | | | | | | | | | | | | * 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
* Add refinements support to method/instance_method.nobu2019-01-281-0/+1
| | | | | | | | [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
* Enable refinements on symbol-proc in ruby-level methodsnobu2018-12-181-0/+1
| | | | | | | | | | | | | | * 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
* Revert "Symbol refinements"mrkn2018-12-041-1/+0
| | | | | | 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
* Symbol refinementsmrkn2018-12-041-0/+1
| | | | | | | | | * 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
* Revert "Symbol refinements"nobu2018-12-031-1/+0
| | | | | | 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
* Symbol refinementsnobu2018-12-031-0/+1
| | | | | | | | | * 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
* Revert "Symbol refinements [Bug #15114]"nobu2018-12-031-1/+0
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66150 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Symbol refinements [Bug #15114]nobu2018-12-031-0/+1
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66149 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Support targetting TracePoint [Feature #15289]ko12018-11-261-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* Avoid compiler depend errorkazu2018-08-221-2/+2
| | | | | | ref r64492 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64503 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Add TracePoint#parametersmame2018-06-031-0/+2
| | | | | | | | | | | 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
* method.h: VM_METHOD_TYPE_MINIMUM_BITSnobu2018-01-281-1/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62080 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* method.h: BITFIELD in rb_method_definition_tnobu2018-01-281-1/+1
| | | | | | | * 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
* internal.h: add BITFIELD macro to aid C99 usersnormal2018-01-271-7/+1
| | | | | | | | | | 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
* Speedup `block.call` [Feature #14330]ko12018-01-071-0/+1
| | | | | | | | | | | | | | | | | | | | | | * 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
* bit-fields other than int is a C99ismshyouhei2018-01-021-1/+7
| | | | | | | 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
* vm_core.h (rb_iseq_locatoin_t): add a field `code_range`mame2017-12-051-1/+1
| | | | | | | 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
* Revamp method coverage to support define_methodmame2017-12-051-0/+3
| | | | | | | | | | | | | | 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
* make a func static.ko12017-11-161-1/+0
| | | | | | | * 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
* remove unused function.ko12017-11-161-1/+0
| | | | | | | * 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
* Add doxygen commentssonots2017-10-211-9/+10
| | | | | | | | * 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
* proc.c: super_method of included methodnobu2017-10-061-4/+4
| | | | | | | | | | * 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
* Revert r59612nobu2017-08-171-1/+1
| | | | | | | * 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
* method.h: enum rb_method_definition_t::typenobu2017-08-171-1/+1
| | | | | | | * 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
* specify unsigned (fix r58784).ko12017-05-191-1/+1
| | | | | | | | * 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
* method.h: pack rb_method_definition_t structnormal2017-05-191-11/+14
| | | | | | | | | | | | | | | | | 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
* * eval.c, method.h, proc.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c:ktsj2016-11-051-1/+1
| | | | | | | | | 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
* * method.h: introduce the folliwing field and macros.ko12015-11-181-2/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | * 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
* revert r52614, r52615, r52617 because they cause serious errorsko12015-11-171-5/+2
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52619 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* * method.h (METHOD_ENTRY_COMPLEMENTED(_SET)): introduced to recognizeko12015-11-171-0/+2
| | | | | | | | | | | | | 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
* * method.h: introduce rb_method_definition_t::complemented_count.ko12015-11-171-2/+3
| | | | | | | | | | | | | | | | | | * 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