From 52c1331763d8b9b8d6362987e6f8847b65ed7f57 Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 11 Oct 2013 18:27:18 +0000 Subject: [PATCH] * class.c, variable.c, gc.c (rb_class_tbl): removed. * vm.c, vm_core.h (rb_vm_add_root_module): added to register as a defined root module or class. This guard helps mark miss from defined classes/modules they are only refered from C's global variables in C-exts. Basically, it is extension's bug. Register to hash object VM has. Marking a hash objects allows generational GC supports. * gc.c (RGENGC_PRINT_TICK): disable (revert). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43263 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 14 ++++++++++++++ class.c | 10 +++++----- gc.c | 6 +----- variable.c | 5 ----- vm.c | 15 ++++++++++++++- vm_core.h | 2 ++ 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 943af618bc..193a6f9f95 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +Sat Oct 12 03:26:04 2013 Koichi Sasada + + * class.c, variable.c, gc.c (rb_class_tbl): removed. + + * vm.c, vm_core.h (rb_vm_add_root_module): added to register as a + defined root module or class. + This guard helps mark miss from defined classes/modules they are + only refered from C's global variables in C-exts. + Basically, it is extension's bug. + Register to hash object VM has. + Marking a hash objects allows generational GC supports. + + * gc.c (RGENGC_PRINT_TICK): disable (revert). + Sat Oct 12 03:24:49 2013 Koichi Sasada * vm_method.c (rb_gc_mark_unlinked_live_method_entries): diff --git a/class.c b/class.c index 2573bd916a..d2cdf74635 100644 --- a/class.c +++ b/class.c @@ -31,7 +31,9 @@ #include "internal.h" #include -extern st_table *rb_class_tbl; +int rb_vm_add_root_module(ID id, VALUE module); + + #define id_attached id__attached__ void @@ -517,12 +519,10 @@ make_singleton_class(VALUE obj) static VALUE boot_defclass(const char *name, VALUE super) { - extern st_table *rb_class_tbl; VALUE obj = rb_class_boot(super); ID id = rb_intern(name); rb_name_class(obj, id); - st_add_direct(rb_class_tbl, id, obj); rb_const_set((rb_cObject ? rb_cObject : obj), id, obj); return obj; } @@ -643,7 +643,7 @@ rb_define_class(const char *name, VALUE super) rb_warn("no super class for `%s', Object assumed", name); } klass = rb_define_class_id(id, super); - st_add_direct(rb_class_tbl, id, klass); + rb_vm_add_root_module(id, klass); rb_name_class(klass, id); rb_const_set(rb_cObject, id, klass); rb_class_inherited(super, klass); @@ -754,7 +754,7 @@ rb_define_module(const char *name) rb_raise(rb_eTypeError, "%s is not a module", rb_obj_classname(module)); } module = rb_define_module_id(id); - st_add_direct(rb_class_tbl, id, module); + rb_vm_add_root_module(id, module); rb_const_set(rb_cObject, id, module); return module; diff --git a/gc.c b/gc.c index 2d489ac679..77ab210923 100644 --- a/gc.c +++ b/gc.c @@ -535,7 +535,6 @@ VALUE *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress; int ruby_gc_debug_indent = 0; VALUE rb_mGC; -extern st_table *rb_class_tbl; int ruby_disable_gc_stress = 0; void rb_gcdebug_print_obj_condition(VALUE obj); @@ -3453,7 +3452,7 @@ gc_mark_stacked_objects(rb_objspace_t *objspace) shrink_stack_chunk_cache(mstack); } -#define RGENGC_PRINT_TICK 1 +#define RGENGC_PRINT_TICK 0 /* the following code is only for internal tuning. */ /* Source code to use RDTSC is quoted and modified from @@ -3597,9 +3596,6 @@ gc_marks_body(rb_objspace_t *objspace, int full_mark) MARK_CHECKPOINT; rb_gc_mark_global_tbl(); - MARK_CHECKPOINT; - mark_tbl(objspace, rb_class_tbl); - /* mark generic instance variables for special constants */ MARK_CHECKPOINT; rb_mark_generic_ivar_tbl(); diff --git a/variable.c b/variable.c index 3b3189bddc..fa4a769b33 100644 --- a/variable.c +++ b/variable.c @@ -21,14 +21,12 @@ #include "id.h" st_table *rb_global_tbl; -st_table *rb_class_tbl; static ID autoload, classpath, tmp_classpath, classid; void Init_var_tables(void) { rb_global_tbl = st_init_numtable(); - rb_class_tbl = st_init_numtable(); CONST_ID(autoload, "__autoload__"); /* __classpath__: fully qualified class path */ CONST_ID(classpath, "__classpath__"); @@ -135,9 +133,6 @@ find_class_path(VALUE klass, ID preferred) if (RCLASS_CONST_TBL(rb_cObject)) { st_foreach_safe(RCLASS_CONST_TBL(rb_cObject), fc_i, (st_data_t)&arg); } - if (arg.path == 0) { - st_foreach_safe(rb_class_tbl, fc_i, (st_data_t)&arg); - } if (arg.path) { st_data_t tmp = tmp_classpath; if (!RCLASS_IV_TBL(klass)) { diff --git a/vm.c b/vm.c index 0193b7b75a..287d1c311e 100644 --- a/vm.c +++ b/vm.c @@ -1611,6 +1611,7 @@ rb_vm_mark(void *ptr) RUBY_MARK_UNLESS_NULL(vm->loaded_features_snapshot); RUBY_MARK_UNLESS_NULL(vm->top_self); RUBY_MARK_UNLESS_NULL(vm->coverages); + RUBY_MARK_UNLESS_NULL(vm->defined_module_hash); rb_gc_mark_locations(vm->special_exceptions, vm->special_exceptions + ruby_special_error_count); if (vm->loading_table) { @@ -1634,6 +1635,17 @@ rb_vm_mark(void *ptr) RUBY_MARK_LEAVE("vm"); } + +int +rb_vm_add_root_module(ID id, VALUE module) +{ + rb_vm_t *vm = GET_VM(); + if (vm->defined_module_hash) { + rb_hash_aset(vm->defined_module_hash, ID2SYM(id), module); + } + return TRUE; +} + #define vm_free 0 int @@ -2619,8 +2631,9 @@ Init_top_self(void) rb_define_singleton_method(rb_vm_top_self(), "to_s", main_to_s, 0); rb_define_alias(rb_singleton_class(rb_vm_top_self()), "inspect", "to_s"); - /* initialize mark object array */ + /* initialize mark object array, hash */ vm->mark_object_ary = rb_ary_tmp_new(1); + vm->defined_module_hash = rb_hash_new(); } VALUE * diff --git a/vm_core.h b/vm_core.h index 8510e1688a..1af68a219f 100644 --- a/vm_core.h +++ b/vm_core.h @@ -400,6 +400,8 @@ typedef struct rb_vm_struct { struct unlinked_method_entry_list_entry *unlinked_method_entry_list; + VALUE defined_module_hash; + #if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE struct rb_objspace *objspace; #endif