mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
833cade2dc
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
103 lines
2.9 KiB
C
103 lines
2.9 KiB
C
/**********************************************************************
|
|
|
|
method.h -
|
|
|
|
$Author$
|
|
created at: Wed Jul 15 20:02:33 2009
|
|
|
|
Copyright (C) 2009 Koichi Sasada
|
|
|
|
**********************************************************************/
|
|
#ifndef METHOD_H
|
|
#define METHOD_H
|
|
|
|
typedef enum {
|
|
NOEX_PUBLIC = 0x00,
|
|
NOEX_NOSUPER = 0x01,
|
|
NOEX_PRIVATE = 0x02,
|
|
NOEX_PROTECTED = 0x04,
|
|
NOEX_MASK = 0x06,
|
|
NOEX_BASIC = 0x08,
|
|
NOEX_UNDEF = NOEX_NOSUPER,
|
|
NOEX_MODFUNC = 0x12,
|
|
NOEX_SUPER = 0x20,
|
|
NOEX_VCALL = 0x40,
|
|
NOEX_RESPONDS = 0x80
|
|
} rb_method_flag_t;
|
|
|
|
#define NOEX_SAFE(n) ((int)((n) >> 8) & 0x0F)
|
|
#define NOEX_WITH(n, s) ((s << 8) | (n) | (ruby_running ? 0 : NOEX_BASIC))
|
|
#define NOEX_WITH_SAFE(n) NOEX_WITH(n, rb_safe_level())
|
|
|
|
/* method data type */
|
|
|
|
typedef enum {
|
|
VM_METHOD_TYPE_ISEQ,
|
|
VM_METHOD_TYPE_CFUNC,
|
|
VM_METHOD_TYPE_ATTRSET,
|
|
VM_METHOD_TYPE_IVAR,
|
|
VM_METHOD_TYPE_BMETHOD,
|
|
VM_METHOD_TYPE_ZSUPER,
|
|
VM_METHOD_TYPE_UNDEF,
|
|
VM_METHOD_TYPE_NOTIMPLEMENTED,
|
|
VM_METHOD_TYPE_OPTIMIZED, /* Kernel#send, Proc#call, etc */
|
|
VM_METHOD_TYPE_MISSING /* wrapper for method_missing(id) */
|
|
} rb_method_type_t;
|
|
|
|
typedef struct rb_method_cfunc_struct {
|
|
VALUE (*func)(ANYARGS);
|
|
int argc;
|
|
} rb_method_cfunc_t;
|
|
|
|
typedef struct rb_method_attr_struct {
|
|
ID id;
|
|
VALUE location;
|
|
} rb_method_attr_t;
|
|
|
|
typedef struct rb_iseq_struct rb_iseq_t;
|
|
|
|
typedef struct rb_method_definition_struct {
|
|
rb_method_type_t type; /* method type */
|
|
ID original_id;
|
|
union {
|
|
rb_iseq_t *iseq; /* should be mark */
|
|
rb_method_cfunc_t cfunc;
|
|
rb_method_attr_t attr;
|
|
VALUE proc; /* should be mark */
|
|
enum method_optimized_type {
|
|
OPTIMIZED_METHOD_TYPE_SEND,
|
|
OPTIMIZED_METHOD_TYPE_CALL
|
|
} optimize_type;
|
|
} body;
|
|
int alias_count;
|
|
} rb_method_definition_t;
|
|
|
|
typedef struct rb_method_entry_struct {
|
|
rb_method_flag_t flag;
|
|
char mark;
|
|
rb_method_definition_t *def;
|
|
ID called_id;
|
|
VALUE klass; /* should be mark */
|
|
} rb_method_entry_t;
|
|
|
|
struct unlinked_method_entry_list_entry {
|
|
struct unlinked_method_entry_list_entry *next;
|
|
rb_method_entry_t *me;
|
|
};
|
|
|
|
#define UNDEFINED_METHOD_ENTRY_P(me) (!(me) || !(me)->def || (me)->def->type == VM_METHOD_TYPE_UNDEF)
|
|
|
|
void rb_add_method_cfunc(VALUE klass, ID mid, VALUE (*func)(ANYARGS), int argc, rb_method_flag_t noex);
|
|
rb_method_entry_t *rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex);
|
|
rb_method_entry_t *rb_method_entry(VALUE klass, ID id);
|
|
|
|
rb_method_entry_t *rb_method_entry_get_without_cache(VALUE klass, ID id);
|
|
rb_method_entry_t *rb_method_entry_set(VALUE klass, ID mid, const rb_method_entry_t *, rb_method_flag_t noex);
|
|
|
|
int rb_method_entry_arity(const rb_method_entry_t *me);
|
|
|
|
void rb_mark_method_entry(const rb_method_entry_t *me);
|
|
void rb_free_method_entry(rb_method_entry_t *me);
|
|
void rb_sweep_method_entry(void *vm);
|
|
|
|
#endif /* METHOD_H */
|