ruby-changes:38742
From: ko1 <ko1@a...>
Date: Thu, 11 Jun 2015 08:55:40 +0900 (JST)
Subject: [ruby-changes:38742] ko1:r50823 (trunk): * method.h: embed rb_method_entry_t::attr::flags (5 bits) into
ko1 2015-06-11 08:55:33 +0900 (Thu, 11 Jun 2015) New Revision: 50823 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50823 Log: * method.h: embed rb_method_entry_t::attr::flags (5 bits) into rb_method_entry_t::flags to make one word spare space. Add some macros to access these flags. * vm_method.c: use these macros. * internal.h: define IMEMO_FL_USHIFT and IMEMO_FL_USER[0-4] for T_IMEMO local flags. Modified files: trunk/ChangeLog trunk/internal.h trunk/method.h trunk/vm_method.c Index: method.h =================================================================== --- method.h (revision 50822) +++ method.h (revision 50823) @@ -47,24 +47,44 @@ typedef struct rb_cref_struct { https://github.com/ruby/ruby/blob/trunk/method.h#L47 typedef struct rb_method_entry_struct { VALUE flags; - - union { - struct { - rb_method_visibility_t visi: 3; - unsigned int safe: 3; - unsigned int basic: 1; - } flags; - VALUE v; /* it should be VALUE size */ - } attr; - + VALUE dummy; struct rb_method_definition_struct * const def; ID called_id; const VALUE klass; /* should be marked */ } rb_method_entry_t; -#define METHOD_ENTRY_VISI(me) (me)->attr.flags.visi -#define METHOD_ENTRY_BASIC(me) (me)->attr.flags.basic -#define METHOD_ENTRY_SAFE(me) (me)->attr.flags.safe +#define METHOD_ENTRY_VISI(me) (rb_method_visibility_t)(((me)->flags & (IMEMO_FL_USER0 | IMEMO_FL_USER1)) >> (IMEMO_FL_USHIFT+0)) +#define METHOD_ENTRY_BASIC(me) (int) (((me)->flags & (IMEMO_FL_USER2 )) >> (IMEMO_FL_USHIFT+2)) +#define METHOD_ENTRY_SAFE(me) (int) (((me)->flags & (IMEMO_FL_USER3 | IMEMO_FL_USER4)) >> (IMEMO_FL_USHIFT+3)) + +static inline void +METHOD_ENTRY_VISI_SET(rb_method_entry_t *me, rb_method_visibility_t visi) +{ + VM_ASSERT(visi <= 3); + me->flags = (me->flags & ~(IMEMO_FL_USER0 | IMEMO_FL_USER1)) | (visi << IMEMO_FL_USHIFT+0); +} +static inline void +METHOD_ENTRY_BASIC_SET(rb_method_entry_t *me, int basic) +{ + VM_ASSERT(basic <= 1); + me->flags = me->flags | (basic << (IMEMO_FL_USHIFT+2)); +} +static inline void +METHOD_ENTRY_SAFE_SET(rb_method_entry_t *me, int safe) +{ + VM_ASSERT(safe <= 3); + me->flags = (me->flags & ~(IMEMO_FL_USER3 | IMEMO_FL_USER4)) | (safe << IMEMO_FL_USHIFT+3); +} +static inline void +METHOD_ENTRY_FLAGS_SET(rb_method_entry_t *me, rb_method_visibility_t visi, int basic, int safe) +{ + VM_ASSERT(visi <= 3); + VM_ASSERT(basic <= 1); + VM_ASSERT(safe <= 3); + me->flags = + (me->flags & ~(IMEMO_FL_USER0|IMEMO_FL_USER1|IMEMO_FL_USER2|IMEMO_FL_USER3|IMEMO_FL_USER4)) | + ((visi << IMEMO_FL_USHIFT+0) | (basic << (IMEMO_FL_USHIFT+2)) | (safe << IMEMO_FL_USHIFT+3)); +} typedef enum { VM_METHOD_TYPE_ISEQ, Index: ChangeLog =================================================================== --- ChangeLog (revision 50822) +++ ChangeLog (revision 50823) @@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Jun 11 08:52:01 2015 Koichi Sasada <ko1@a...> + + * method.h: embed rb_method_entry_t::attr::flags (5 bits) into + rb_method_entry_t::flags to make one word spare space. + + Add some macros to access these flags. + + * vm_method.c: use these macros. + + * internal.h: define IMEMO_FL_USHIFT and IMEMO_FL_USER[0-4] + for T_IMEMO local flags. + Thu Jun 11 08:27:06 2015 Koichi Sasada <ko1@a...> * vm.c: use VM_ASSERT instead of assert(). Index: vm_method.c =================================================================== --- vm_method.c (revision 50822) +++ vm_method.c (revision 50823) @@ -335,9 +335,7 @@ rb_method_entry_t * https://github.com/ruby/ruby/blob/trunk/vm_method.c#L335 rb_method_entry_create(ID called_id, VALUE klass, rb_method_visibility_t visi, rb_method_definition_t *def) { rb_method_entry_t *me = (rb_method_entry_t *)rb_imemo_new(imemo_ment, (VALUE)NULL, (VALUE)called_id, (VALUE)klass, 0); - METHOD_ENTRY_VISI(me) = visi; - METHOD_ENTRY_BASIC(me) = ruby_running ? FALSE : TRUE; - METHOD_ENTRY_SAFE(me) = rb_safe_level(); + METHOD_ENTRY_FLAGS_SET(me, visi, ruby_running ? FALSE : TRUE, rb_safe_level()); rb_method_definition_reset(me, def); VM_ASSERT(def != NULL); @@ -373,7 +371,7 @@ make_method_entry_refined(rb_method_entr https://github.com/ruby/ruby/blob/trunk/vm_method.c#L371 new_def = rb_method_definition_create(VM_METHOD_TYPE_REFINED, me->called_id, rb_method_entry_clone(me)); rb_method_definition_reset(me, new_def); - METHOD_ENTRY_VISI(me) = METHOD_VISI_PUBLIC; + METHOD_ENTRY_VISI_SET(me, METHOD_VISI_PUBLIC); } void @@ -561,7 +559,7 @@ method_entry_set(VALUE klass, ID mid, co https://github.com/ruby/ruby/blob/trunk/vm_method.c#L559 { rb_method_definition_t *def = rb_method_definition_addref(me->def); rb_method_entry_t *newme = rb_method_entry_make(klass, mid, me->def->type, def, visi, defined_class); - METHOD_ENTRY_SAFE(newme) = METHOD_ENTRY_SAFE(me); + METHOD_ENTRY_SAFE_SET(newme, METHOD_ENTRY_SAFE(me)); method_added(klass, mid); return newme; } @@ -877,10 +875,10 @@ rb_export_method(VALUE klass, ID name, r https://github.com/ruby/ruby/blob/trunk/vm_method.c#L875 rb_vm_check_redefinition_opt_method(me, klass); if (klass == defined_class || RCLASS_ORIGIN(klass) == defined_class) { - METHOD_ENTRY_VISI(me) = visi; + METHOD_ENTRY_VISI_SET(me, visi); if (me->def->type == VM_METHOD_TYPE_REFINED && me->def->body.refined.orig_me) { - METHOD_ENTRY_VISI((rb_method_entry_t *)me->def->body.refined.orig_me) = visi; + METHOD_ENTRY_VISI_SET((rb_method_entry_t *)me->def->body.refined.orig_me, visi); } rb_clear_method_cache_by_class(klass); } @@ -1403,7 +1401,7 @@ rb_alias(VALUE klass, ID alias_name, ID https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1401 RB_OBJ_WRITE(alias_me, &alias_me->klass, defined_class); alias_me->def->original_id = orig_me->called_id; *(ID *)&alias_me->def->body.alias.original_me->called_id = alias_name; - METHOD_ENTRY_SAFE(alias_me) = METHOD_ENTRY_SAFE(orig_me); + METHOD_ENTRY_SAFE_SET(alias_me, METHOD_ENTRY_SAFE(orig_me)); } else { method_entry_set(target_klass, alias_name, orig_me, visi, defined_class); Index: internal.h =================================================================== --- internal.h (revision 50822) +++ internal.h (revision 50823) @@ -545,6 +545,14 @@ imemo_type(VALUE imemo) https://github.com/ruby/ruby/blob/trunk/internal.h#L545 return (RBASIC(imemo)->flags >> FL_USHIFT) & imemo_mask; } +/* FL_USER0 to FL_USER2 is for type */ +#define IMEMO_FL_USHIFT (FL_USHIFT + 3) +#define IMEMO_FL_USER0 FL_USER3 +#define IMEMO_FL_USER1 FL_USER4 +#define IMEMO_FL_USER2 FL_USER5 +#define IMEMO_FL_USER3 FL_USER6 +#define IMEMO_FL_USER4 FL_USER7 + /* CREF in method.h */ /* SVAR */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/