[前][次][番号順一覧][スレッド一覧]

ruby-changes:26380

From: ko1 <ko1@a...>
Date: Tue, 18 Dec 2012 07:07:04 +0900 (JST)
Subject: [ruby-changes:26380] ko1:r38431 (trunk): * method.h: remove `VM_METHOD_TYPE_CFUNC_FRAMELESS' method type.

ko1	2012-12-18 07:04:12 +0900 (Tue, 18 Dec 2012)

  New Revision: 38431

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38431

  Log:
    * method.h: remove `VM_METHOD_TYPE_CFUNC_FRAMELESS' method type.
      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.

  Modified files:
    trunk/ChangeLog
    trunk/method.h
    trunk/proc.c
    trunk/vm_eval.c
    trunk/vm_insnhelper.c
    trunk/vm_method.c

Index: method.h
===================================================================
--- method.h	(revision 38430)
+++ method.h	(revision 38431)
@@ -53,7 +53,6 @@ typedef enum { https://github.com/ruby/ruby/blob/trunk/method.h#L53
     VM_METHOD_TYPE_NOTIMPLEMENTED,
     VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
     VM_METHOD_TYPE_MISSING,   /* wrapper for method_missing(id) */
-    VM_METHOD_TYPE_CFUNC_FRAMELESS,
     VM_METHOD_TYPE_REFINED,
 
     END_OF_ENUMERATION(VM_METHOD_TYPE)
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 38430)
+++ ChangeLog	(revision 38431)
@@ -1,3 +1,47 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 18 06:36:12 2012  Koichi Sasada  <ko1@a...>
+
+	* method.h: remove `VM_METHOD_TYPE_CFUNC_FRAMELESS' method type.
+	  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.
+
 Tue Dec 18 04:58:22 2012  Koichi Sasada  <ko1@a...>
 
 	* vm_trace.c (fill_id_and_klass): TracePoint#defined_class returns
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 38430)
+++ vm_eval.c	(revision 38431)
@@ -219,12 +219,6 @@ vm_call0_body(rb_thread_t* th, rb_call_i https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L219
 	    rb_bug("vm_call0: unsupported optimized method type (%d)", ci->me->def->body.optimize_type);
 	}
 	break;
-      case VM_METHOD_TYPE_CFUNC_FRAMELESS:
-	{
-	    /* TODO: can optimize it */
-	    const rb_method_cfunc_t *cfunc = &ci->me->def->body.cfunc;
-	    return cfunc->invoker(cfunc->func, ci->recv, ci->argc, argv);
-	}
       case VM_METHOD_TYPE_UNDEF:
 	break;
     }
Index: proc.c
===================================================================
--- proc.c	(revision 38430)
+++ proc.c	(revision 38431)
@@ -1651,7 +1651,6 @@ rb_method_entry_arity(const rb_method_en https://github.com/ruby/ruby/blob/trunk/proc.c#L1651
     const rb_method_definition_t *def = me->def;
     if (!def) return 0;
     switch (def->type) {
-      case VM_METHOD_TYPE_CFUNC_FRAMELESS:
       case VM_METHOD_TYPE_CFUNC:
 	if (def->body.cfunc.argc < 0)
 	    return -1;
Index: vm_method.c
===================================================================
--- vm_method.c	(revision 38430)
+++ vm_method.c	(revision 38431)
@@ -420,7 +420,6 @@ rb_add_method(VALUE klass, ID mid, rb_me https://github.com/ruby/ruby/blob/trunk/vm_method.c#L420
 	def->body.iseq = (rb_iseq_t *)opts;
 	break;
       case VM_METHOD_TYPE_CFUNC:
-      case VM_METHOD_TYPE_CFUNC_FRAMELESS:
 	{
 	    rb_method_cfunc_t *cfunc = (rb_method_cfunc_t *)opts;
 	    setup_method_cfunc_struct(&def->body.cfunc, cfunc->func, cfunc->argc);
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 38430)
+++ vm_insnhelper.c	(revision 38431)
@@ -1620,21 +1620,6 @@ vm_call_opt_call(rb_thread_t *th, rb_con https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1620
 }
 
 static VALUE
-vm_call_cfunc_frameless_unary(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
-{
-    cfp->sp -= 1;
-    return (*ci->me->def->body.cfunc.func)(ci->recv);
-}
-
-static VALUE
-vm_call_cfunc_frameless_binary(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
-{
-    VALUE obj = *cfp->sp;
-    cfp->sp -= 2;
-    return (*ci->me->def->body.cfunc.func)(ci->recv, obj);
-}
-
-static VALUE
 vm_call_method_missing(rb_thread_t *th, rb_control_frame_t *reg_cfp, rb_call_info_t *ci)
 {
     VALUE *argv = STACK_ADDR_FROM_TOP(ci->argc);
@@ -1748,20 +1733,6 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1733
 		}
 		break;
 	      }
-	      case VM_METHOD_TYPE_CFUNC_FRAMELESS:
-		switch (ci->me->def->body.cfunc.argc) {
-		  case 0:
-		    rb_check_arity(ci->argc, 0, 0);
-		    CI_SET_FASTPATH(ci, vm_call_cfunc_frameless_unary, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT));
-		    return vm_call_cfunc_frameless_unary(th, cfp, ci);
-		  case 1:
-		    rb_check_arity(ci->argc, 0, 1);
-		    CI_SET_FASTPATH(ci, vm_call_cfunc_frameless_binary, enable_fastpath && !(ci->flag & VM_CALL_ARGS_SPLAT));
-		    return vm_call_cfunc_frameless_binary(th, cfp, ci);
-		  default:
-		    rb_bug("vm_call_method: unsupported cfunc_fast argc (%d)", ci->me->def->body.cfunc.argc);
-		}
-		break;
 	      case VM_METHOD_TYPE_UNDEF:
 		break;
 	      case VM_METHOD_TYPE_REFINED:{

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]