summaryrefslogtreecommitdiff
path: root/method.h
AgeCommit message (Collapse)Author
2013-06-14* class.c, include/ruby/ruby.h: add write barriers for T_CLASS,ko1
T_MODULE, T_ICLASS. * constant.h: constify rb_const_entry_t::value and file to detect assignment. * variable.c, internal.h (rb_st_insert_id_and_value, rb_st_copy): added. update table with write barrier. * method.h: constify some variables to detect assignment. * object.c (init_copy): add WBs. * variable.c: ditto. * vm_method.c (rb_add_method): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-05-13vm_method.c: rb_method_entry_atnobu
* vm_method.c (rb_method_entry_at): return the method entry for id at klass, without ancestors. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40683 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2013-02-06vm_method.c: show respond_to locationnobu
* proc.c (rb_method_entry_location, rb_{mod,obj}_method_location): new functions to obtain source location of method definition. * vm_method.c (rb_obj_respond_to): show the location of old style respond_to? method. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39089 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-17* method.h: remove `VM_METHOD_TYPE_CFUNC_FRAMELESS' method type.ko1
This method type is for optimized CFUNC such as Fixnum#+ and so on. This feature is half-baked and no way to use them. [Background] Now, VM has opt_plus instructions to optimize `+' methods for some Classes (such as Fixnum, Float (flonum)). We call this type of instructions as `specialized instructions'. This simple technique improve simple program dramatically. However, we can make specialized instructions for only several types (classes) and selectors (method names) because a large instruction will be slow. In other words, this technique has no extensibility. To overcome this problem, VM_METHOD_TYPE_CFUNC_FRAMELESS was introduced (r37198). This type is a variant of CFUNC, but called their functiions directly without building a method frame. Any CFUNC method can be defined as frameless methods if a method is not needed to make method frame. Frameless methods are faster as specialized instructions (a bit slower, but no need to care). No problem described at http://charlie.bz/blog/why-do-singleton-methods-make-ruby-slow because this technique doesn't see class, but see method body itself. Alias is also no problem. [Problem] However, we can't set frameless method type for polymorphic methods such as Array#[]. Necessity for method frame depends on which parameter type. For example, Fixnum#+ needs method frame if coerce is needed. Current VM_METHOD_TYPE_CFUNC_FRAMELESS is not flexible and need more tuning to introduce it. Expected behavior of frameless method type may be: result = optimized_cfunc(params); /* call optimized cfunc */ if (result == Qundef) { result = normal_cfunc(); } This is why I say this feature is half-baked. We need to learn primitive method in Smalltalk more. (I heard this name at RubyConf Taiwan this month. Thanks!) [Conclusion] Nobody may use this feature and there is no compatibility issue. This feature goes to next minor (2.1?). * proc.c (rb_method_entry_arity): ditto. * vm_eval.c, vm_insnhelper.c, vm_method.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38431 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-13* method.h (END_OF_ENUMERATION): placeholder to put last comma.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38353 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-13* method.h: remove "VM_METHOD_TYPE__MAX" from rb_method_type_t.ko1
rb_method_type_t is not a number and "_MAX" causes misunderstanding. * proc.c (rb_method_entry_arity): ditto. * vm_eval.c (vm_call0_body): ditto. * vm_insnhelper.c (vm_call_method): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38349 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-12method.h: NOEX_SAFE_SHIFT_OFFSETnobu
* method.h (rb_method_flag_t): name a magic number for NOEX_SAFE and NOEX_WITH as NOEX_SAFE_SHIFT_OFFSET. * method.h (rb_method_type_t, method_optimized_type): C89 forbids a comma after the last element in enum. * proc.c (rb_method_entry_arity), vm_eval.c (vm_call0_body), vm_insnhelper.c (vm_call_method): add VM_METHOD_TYPE__MAX case. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38340 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-09* vm_insnhelper.c (vm_call_opt_send): Kernel#send should not useshugo
refinements. * proc.c (mnew): Kernel#method, Kernel#public_method, Module#instance_method, and Module#public_instance_method should not use refinements. * vm_method.c (rb_method_boundp): Kernel#respond_to? should not use refinements. * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38279 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-12-06* revised r37993 to avoid SEGV/ILL in tests. In r37993, a methodshugo
entry with VM_METHOD_TYPE_REFINED holds only the original method definition, so ci->me is set to a method entry allocated in the stack, and it causes SEGV/ILL. In this commit, a method entry with VM_METHOD_TYPE_REFINED holds the whole original method entry. Furthermore, rb_thread_mark() is changed to mark cfp->klass to avoid GC for iclasses created by copy_refinement_iclass(). * vm_method.c (rb_method_entry_make): add a method entry with VM_METHOD_TYPE_REFINED to the class refined by the refinement if the target module is a refinement. When a method entry with VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with the same name is searched in refinements. If such a method is found, the method is invoked. Otherwise, the original method in the refined class (rb_method_definition_t::body.orig_me) is invoked. This change is made to simplify the normal method lookup and to improve the performance of normal method calls. * vm_method.c (EXPR1, search_method, rb_method_entry), vm_eval.c (rb_call0, rb_search_method_entry): do not use refinements for method lookup. * vm_insnhelper.c (vm_call_method): search methods in refinements if ci->me is VM_METHOD_TYPE_REFINED. If the method is called by super (i.e., ci->call == vm_call_super_method), skip the same method entry as the current method to avoid infinite call of the same method. * class.c (include_modules_at): add a refined method entry for each method defined in a module included in a refinement. * class.c (rb_prepend_module): set an empty table to RCLASS_M_TBL(klass) to add refined method entries, because refinements should have priority over prepended modules. * proc.c (mnew): use rb_method_entry_with_refinements() to get a refined method. * vm.c (rb_thread_mark): mark cfp->klass for iclasses created by copy_refinement_iclass(). * vm.c (Init_VM), cont.c (fiber_init): initialize th->cfp->klass. * test/ruby/test_refinement.rb (test_inline_method_cache): do not skip the test because it should pass successfully. * test/ruby/test_refinement.rb (test_redefine_refined_method): new test for the case a refined method is redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38236 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-30* revert r37993 to avoid SEGV in tests.shugo
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38022 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-29* vm_method.c (rb_method_entry_make): add a method entry withshugo
VM_METHOD_TYPE_REFINED to the class refined by the refinement if the target module is a refinement. When a method entry with VM_METHOD_TYPE_UNDEF is invoked by vm_call_method(), a method with the same name is searched in refinements. If such a method is found, the method is invoked. Otherwise, the original method in the refined class (rb_method_definition_t::body.orig_def) is invoked. This change is made to simplify the normal method lookup and to improve the performance of normal method calls. * vm_method.c (EXPR1, search_method, rb_method_entry), vm_eval.c (rb_call0, rb_search_method_entry): do not use refinements for method lookup. * vm_insnhelper.c (vm_call_method): search methods in refinements if ci->me is VM_METHOD_TYPE_REFINED. If the method is called by super (i.e., ci->call == vm_call_super_method), skip the same method entry as the current method to avoid infinite call of the same method. * class.c (include_modules_at): add a refined method entry for each method defined in a module included in a refinement. * class.c (rb_prepend_module): set an empty table to RCLASS_M_TBL(klass) to add refined method entries, because refinements should have priority over prepended modules. * proc.c (mnew): use rb_method_entry_with_refinements() to get a refined method. * test/ruby/test_refinement.rb (test_inline_method_cache): do not skip the test because it should pass successfully. * test/ruby/test_refinement.rb (test_redefine_refined_method): new test for the case a refined method is redefined. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37993 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-11-13* vm_insnhelper.c (vm_call_cfunc_with_frame): don't use ci afterko1
EXEC_EVENT_HOOK because ci can be overridden. * vm_eval.c: ditto. * method.h: change invoker's parameters types. * vm_method.c (call_cfunc_invoker_func): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37647 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-25* include/ruby/ruby.h, class.c: remove (revert)ko1
`rb_add_method_cfunc_frameless()' API. This API is not mature to become an offical API. For example, we can not use this API with `rb_define_private_method()'. * method.h, vm_method.c (rb_add_method_cfunc_frameless): removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37320 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-23* vm_core.h, vm_insnhelper.c, vm_eval.c (OPT_CALL_CFUNC_WITHOUT_FRAME):ko1
add a new otpimization and its macro `OPT_CALL_CFUNC_WITHOUT_FRAME'. This optimization makes all cfunc method calls `frameless', which is fster than ordinal cfunc method call. If `frame' is needed (for example, it calls another method with `rb_funcall()'), then build a frame. In other words, this optimization delays frame building. However, to delay the frame building, we need additional overheads: (1) Store the last call information. (2) Check the delayed frame buidling before the frame is needed. (3) Overhead to build a delayed frame. rb_thread_t::passed_ci is storage of delayed cfunc call information. (1) is lightweight because it is only 1 assignment to `passed_ci'. To achieve (2), we modify GET_THREAD() to check `passed_ci' every time. It causes 10% overhead on my envrionment. This optimization only works for cfunc methods which do not need their `frame'. After evaluation on my environment, this optimization does not effective every time. Because of this evaluation results, this optimization is disabled at default. * vm_insnhelper.c, vm.c: add VM_PROFILE* macros to measure behaviour of VM internals. I will extend this feature. * vm_method.c, method.h: change parameters of the `invoker' function. Receive `func' pointer as the first parameter. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37293 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-19* method.h (rb_method_cfunc_t::invoker): add new field (func ptr)ko1
`invoker'. `invoker' function invoke cfunc body (rb_method_cfunc_t::func). `invoker' is set at method definition timing. With this change, the big `switch' (branch) in `call_cfunc()' is no longer needed. However, the performance benefit is only a bit. * vm_core.h (rb_call_info_t::aux::func): add a new field to store cfunc body function pointer. * vm_method.c (call_cfunc_invoker_func): add a new function which returns a suitable invoke function. * vm_method.c (setup_method_cfunc_struct): added. * vm_method.c (rb_add_method): fix to set `invoker'. * vm_eval.c (vm_call0_body): catch up above changes. * vm_insnhelper.c (call_cfunc): removed. * vm_insnhelper.c (vm_call_cfunc): fix to call cfunc body with `invoker' function. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37268 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-18* class.c (rb_define_frameless_method): rename fromko1
rb_define_method_fast(). Defined method with this C API does not make a method frame. It is bit lightweight than ordinal C functions. Now only 0 or 1 argc are permitted. * method.h (VM_METHOD_TYPE_CFUNC_FRAMELESS): rename macro name from VM_METHOD_TYPE_CFUNC_FAST. * vm_insnhelper.c, vm_method.c: rename related functions. * proc.c (rb_method_entry_arity): catch up above changes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-16* method.h(rb_method_definition_struct): remove a comma after the last elementnagachika
of enum. fix for r37198. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37226 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-15* method.h: introduce new method type VM_METHOD_TYPE_CFUNC_FAST.ko1
This method is similar to VM_METHOD_TYPE_CFUNC methods, but called cfunc without building new frame (does not push new control frame). If error is occured in cfunc, the backtrace only shows caller frame and upper. This kind of methods can be added by rb_define_method_fast(). This feature is similar to specialized instructions (opt_plus, etc), but more flexible (but a bit slower). * class.c (rb_define_method_fast): added. Maybe it will be renamed soon. * vm_insnhelper.c (vm_call_method): support method type VM_METHOD_TYPE_CFUNC_FAST. * proc.c (rb_method_entry_arity): catch up new method type. * vm_method.c (rb_add_method_cfunc_fast): added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37198 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-10-08* eval.c, gc.c, iseq.c, node.h, vm_insnhelper.c, vm_insnhelper.h,shugo
vm_method.c: rename omod and overlaid modules to refinements. * eval.c (hidden_identity_hash_new): renamed from identity_hash_new. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37117 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-02* eval.c (rb_mod_using): new method Module#using. [experimental]shugo
* eval.c (rb_mod_refine): new method Module#refine. [experimental] * eval.c (f_using): new method Kernel#using. [experimental] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36596 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-08-02* class.c, insns.def, method.h, proc.c, vm.c, vm_core.h, vm_eval.c,shugo
vm_insnhelper.c, vm_insnhelper.h, vm_method.c: add klass to rb_control_frame_t to implement super correctly. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36595 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-06-25Revert r31873 Module#mixnobu
* class.c (rb_mix_module): revert Module#mix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36216 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2012-02-21* proc.c (method_hash, proc_hash): Fix {Unbound}Method#hashmarcandre
[Bug #6048]. Isolate hash computation for proc * internal.h: Declaration for above * vm_method.c (rb_method_definition_hash): Computation for hash part of a method definition * method.h: Declaration for above * test/ruby/test_method.rb: Test for above git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34715 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-06-18* method.h, internal.h iseq.h: declare internal functions.akr
* compile.c, eval.c, iseq.c, object.c, parse.y, proc.c, process.c, thread.c, vm.c, vm_eval.c, vm_insnhelper.c, vm_method.c: don't declare internal functions. Note that rb_method_entry_eq() is defined in vm_method.c but there was a declaration in proc.c with different const-ness. Now it is declared in method.h with same const-ness to the definition. * object.c (rb_mod_module_exec): don't declare functions declared in include/ruby/intern.h. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-05-31* class.c (rb_mix_module): implement Module#mix.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2011-01-19* method.h: parenthesize macro arguments.akr
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30606 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-10-26* class.c, constant.h, gc.c, method.h, object.c, variable.c,mame
vm_insnhelper.c: use struct rb_constant_entry_t as entry of RCLASS_CONST_TBL. RCLASS_CONST_TBL has contained VALUE of constant directly. Now instead rb_const_entry_t is contained in RCLASS_CONST_TBL, rb_const_entry_t is managed by malloc, and have not only the value itself but also visibility flag. This is another preparation for private constant (see [ruby-dev:39685][ruby-core:32698]). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-05* vm_method.c (rb_unlink_method_entry, rb_sweep_method_entry):ko1
added. Unlinked method entries are collected to vm->unlinked_method_entry_list. On the GC timing, mark all method entries which are on all living threads. Only non-marked method entries are collected. This hack prevents releasing living method entry. [Performance Consideration] Since this Method Entry GC (MEGC) doesn't occuer frequently, MEGC will not be a performance bottleneck. However, to traverse living method entries, every control frame push needs to clear cfp->me field. This will be a performance issue (because pushing control frame is occurred frequently). Bug #2777 [ruby-dev:40457] * cont.c (fiber_init): init cfp->me. * gc.c (garbage_collect): kick rb_sweep_method_entry(). * method.h (rb_method_entry_t): add a mark field. * vm.c (invoke_block_from_c): set passed me. * vm.c (rb_thread_mark): mark cfp->me. * vm_core.h (rb_thread_t): add a field passed_me. * vm_core.h (rb_vm_t): add a field unlinked_method_entry_list. * vm_insnhelper.c (vm_push_frame): clear cfp->me at all times. * vm_insnhelper.c (vm_call_bmethod): pass me. * bootstraptest/test_method.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27634 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-04* gc.c (rb_mark_method_entry): renamed.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-04* method.h (rb_gc_mark_method_entry): fixed typo.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-05-04* method.h, vm_method.c: rename some internal functions related toko1
rb_method_entry_t. rb_add_method_me() -> rb_method_entry_set(). rb_get_method_entry() -> rb_method_entry_without_cache(). rb_gc_mark_method_entry() -> rb_mark_method_entry(). * class.c, proc.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27620 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2010-03-22* proc.c (rb_method_location): return attr's location if it is setup.wanabe
[Feature #2084] * NEWS: follow above. * vm_method.c (rb_add_method): save attr's location. * gc.c (mark_method_entry): mark attr's location. * method.h (rb_method_definition_t): add member to save attr's location. * vm_eval.c (vm_call0): follow above. * vm_insnhelper.c (vm_call_method): ditto. * vm_method.c (rb_method_definition_eq): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-04* vm_method.c (basic_obj_respond_to): should not callmatz
#respond_to_missing? for not implemented methods. [ruby-core:25909] * vm_method.c (rb_method_boundp): returns exceptional value 2 for not-implemented methods when called from #respond_to? (specifies by new contant NOEX_RESPONDS). * method.h (enum): new constant NOEX_RESPONDS added. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-10-02* method.h (rb_method_type_t): remove a comma at end ofnaruse
enumerator list. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25192 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-09-28git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@25129 ↵matz
b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-08-29* vm_eval.c (rb_call0): gets rid of checking method cache twice.yugui
* method.h (rb_get_method_entry): added a prototype of the function. (rb_method_entry_without_cache): more friendly name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-08-28* method.h (rb_method_definition_t): split from rb_method_entry_tnobu
to deal aliases. [ruby-dev:39165] * proc.c (struct METHOD): contains rb_method_entry_t copy. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24691 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-08-26* method.c (rb_method_entry_t): body.proc should be marked.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24664 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-22 * method.h : Commas at end of enum list not allowed as of C89shyouhei
* vm_method.c (rb_add_method): avoid C++ comment * vm_insnhelper.c (vm_call_cfunc): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-16* method.h: properties.nobu
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24138 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2009-07-15* method.h, vm_core.h: add rb_method_entry_t. Remove nodes aroundko1
method management. This change affect some VM control stack structure. * vm.c, vm_insnhelper.c, vm_method.c, vm_eval.c: ditto. and make some refactoring. * insns.def, class.c, eval.c, proc.c, vm_dump.c : ditto. * vm_core.h, compile.c (iseq_specialized_instruction): remove VM_CALL_SEND_BIT. use another optimization tech for Kernel#send. * node.h: remove unused node types. * ext/objspace/objspace.c (count_nodes): ditto. * gc.c: add mark/free functions for method entry. * include/ruby/intern.h: remove decl of rb_define_notimplement_method_id(). nobody can use it because noex is not opend. * iseq.c (iseq_mark): fix to check ic_method is available. * iseq.c (rb_iseq_disasm): fix to use rb_method_get_iseq(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24128 b2dd03c8-39d4-4d8f-98ff-823fe69b080e