* gc.c (finalizer_table, objspace->final.table):
Create finalizer_table at Init_heap(). Remove all null checks of finalizer_table. * gc.c (mark_tbl): skip if no table entries. * gc.c (slot_swee): remove useless need_call_final check. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5eced07cd7
commit
7b0d48c1fa
10
ChangeLog
10
ChangeLog
@ -1,3 +1,13 @@
|
|||||||
|
Sun Oct 31 23:27:09 2010 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* gc.c (finalizer_table, objspace->final.table):
|
||||||
|
Create finalizer_table at Init_heap().
|
||||||
|
Remove all null checks of finalizer_table.
|
||||||
|
|
||||||
|
* gc.c (mark_tbl): skip if no table entries.
|
||||||
|
|
||||||
|
* gc.c (slot_swee): remove useless need_call_final check.
|
||||||
|
|
||||||
Sun Oct 31 22:32:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Sun Oct 31 22:32:08 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* gc.c (rb_objspace_free): finalizers should be called separately
|
* gc.c (rb_objspace_free): finalizers should be called separately
|
||||||
|
33
gc.c
33
gc.c
@ -386,8 +386,6 @@ int *ruby_initial_gc_stress_ptr = &rb_objspace.gc_stress;
|
|||||||
#define global_List objspace->global_list
|
#define global_List objspace->global_list
|
||||||
#define ruby_gc_stress objspace->gc_stress
|
#define ruby_gc_stress objspace->gc_stress
|
||||||
|
|
||||||
#define need_call_final (finalizer_table && finalizer_table->num_entries)
|
|
||||||
|
|
||||||
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
|
static void rb_objspace_call_finalizer(rb_objspace_t *objspace);
|
||||||
|
|
||||||
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
#if defined(ENABLE_VM_OBJSPACE) && ENABLE_VM_OBJSPACE
|
||||||
@ -1005,6 +1003,7 @@ init_heap(rb_objspace_t *objspace)
|
|||||||
}
|
}
|
||||||
heaps_inc = 0;
|
heaps_inc = 0;
|
||||||
objspace->profile.invoke_time = getrusage_time();
|
objspace->profile.invoke_time = getrusage_time();
|
||||||
|
finalizer_table = st_init_numtable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1389,7 +1388,7 @@ static void
|
|||||||
mark_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
mark_tbl(rb_objspace_t *objspace, st_table *tbl, int lev)
|
||||||
{
|
{
|
||||||
struct mark_tbl_arg arg;
|
struct mark_tbl_arg arg;
|
||||||
if (!tbl) return;
|
if (!tbl || tbl->num_entries == 0) return;
|
||||||
arg.objspace = objspace;
|
arg.objspace = objspace;
|
||||||
arg.lev = lev;
|
arg.lev = lev;
|
||||||
st_foreach(tbl, mark_entry, (st_data_t)&arg);
|
st_foreach(tbl, mark_entry, (st_data_t)&arg);
|
||||||
@ -1956,7 +1955,7 @@ slot_sweep(rb_objspace_t *objspace, struct heaps_slot *sweep_slot)
|
|||||||
if (!(p->as.basic.flags & FL_MARK)) {
|
if (!(p->as.basic.flags & FL_MARK)) {
|
||||||
if (p->as.basic.flags &&
|
if (p->as.basic.flags &&
|
||||||
((deferred = obj_free(objspace, (VALUE)p)) ||
|
((deferred = obj_free(objspace, (VALUE)p)) ||
|
||||||
((FL_TEST(p, FL_FINALIZE)) && need_call_final))) {
|
(FL_TEST(p, FL_FINALIZE)))) {
|
||||||
if (!deferred) {
|
if (!deferred) {
|
||||||
p->as.free.flags = T_ZOMBIE;
|
p->as.free.flags = T_ZOMBIE;
|
||||||
RDATA(p)->dfree = 0;
|
RDATA(p)->dfree = 0;
|
||||||
@ -2397,10 +2396,7 @@ gc_marks(rb_objspace_t *objspace)
|
|||||||
|
|
||||||
th->vm->self ? rb_gc_mark(th->vm->self) : rb_vm_mark(th->vm);
|
th->vm->self ? rb_gc_mark(th->vm->self) : rb_vm_mark(th->vm);
|
||||||
|
|
||||||
if (finalizer_table) {
|
|
||||||
mark_tbl(objspace, finalizer_table, 0);
|
mark_tbl(objspace, finalizer_table, 0);
|
||||||
}
|
|
||||||
|
|
||||||
mark_current_machine_context(objspace, th);
|
mark_current_machine_context(objspace, th);
|
||||||
|
|
||||||
rb_gc_mark_symbols();
|
rb_gc_mark_symbols();
|
||||||
@ -2760,11 +2756,9 @@ static VALUE
|
|||||||
undefine_final(VALUE os, VALUE obj)
|
undefine_final(VALUE os, VALUE obj)
|
||||||
{
|
{
|
||||||
rb_objspace_t *objspace = &rb_objspace;
|
rb_objspace_t *objspace = &rb_objspace;
|
||||||
rb_check_frozen(obj);
|
|
||||||
if (finalizer_table) {
|
|
||||||
st_data_t data = obj;
|
st_data_t data = obj;
|
||||||
|
rb_check_frozen(obj);
|
||||||
st_delete(finalizer_table, &data, 0);
|
st_delete(finalizer_table, &data, 0);
|
||||||
}
|
|
||||||
FL_UNSET(obj, FL_FINALIZE);
|
FL_UNSET(obj, FL_FINALIZE);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
@ -2803,9 +2797,6 @@ define_final(int argc, VALUE *argv, VALUE os)
|
|||||||
block = rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
|
block = rb_ary_new3(2, INT2FIX(rb_safe_level()), block);
|
||||||
OBJ_FREEZE(block);
|
OBJ_FREEZE(block);
|
||||||
|
|
||||||
if (!finalizer_table) {
|
|
||||||
finalizer_table = st_init_numtable();
|
|
||||||
}
|
|
||||||
if (st_lookup(finalizer_table, obj, &data)) {
|
if (st_lookup(finalizer_table, obj, &data)) {
|
||||||
table = (VALUE)data;
|
table = (VALUE)data;
|
||||||
rb_ary_push(table, block);
|
rb_ary_push(table, block);
|
||||||
@ -2825,7 +2816,6 @@ rb_gc_copy_finalizer(VALUE dest, VALUE obj)
|
|||||||
VALUE table;
|
VALUE table;
|
||||||
st_data_t data;
|
st_data_t data;
|
||||||
|
|
||||||
if (!finalizer_table) return;
|
|
||||||
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
if (!FL_TEST(obj, FL_FINALIZE)) return;
|
||||||
if (st_lookup(finalizer_table, obj, &data)) {
|
if (st_lookup(finalizer_table, obj, &data)) {
|
||||||
table = (VALUE)data;
|
table = (VALUE)data;
|
||||||
@ -2885,8 +2875,7 @@ run_final(rb_objspace_t *objspace, VALUE obj)
|
|||||||
}
|
}
|
||||||
|
|
||||||
key = (st_data_t)obj;
|
key = (st_data_t)obj;
|
||||||
if (finalizer_table &&
|
if (st_delete(finalizer_table, &key, &table)) {
|
||||||
st_delete(finalizer_table, &key, &table)) {
|
|
||||||
run_finalizer(objspace, obj, objid, (VALUE)table);
|
run_finalizer(objspace, obj, objid, (VALUE)table);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2954,7 +2943,7 @@ rb_gc_call_finalizer_at_exit(void)
|
|||||||
rb_objspace_call_finalizer(&rb_objspace);
|
rb_objspace_call_finalizer(&rb_objspace);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
||||||
{
|
{
|
||||||
RVALUE *p, *pend;
|
RVALUE *p, *pend;
|
||||||
@ -2962,8 +2951,8 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
|||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
/* run finalizers */
|
/* run finalizers */
|
||||||
if (finalizer_table) {
|
|
||||||
gc_clear_mark_on_sweep_slots(objspace);
|
gc_clear_mark_on_sweep_slots(objspace);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
/* XXX: this loop will make no sense */
|
/* XXX: this loop will make no sense */
|
||||||
/* because mark will not be removed */
|
/* because mark will not be removed */
|
||||||
@ -2984,11 +2973,10 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
|||||||
xfree(curr);
|
xfree(curr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st_free_table(finalizer_table);
|
|
||||||
finalizer_table = 0;
|
|
||||||
}
|
|
||||||
/* finalizers are part of garbage collection */
|
/* finalizers are part of garbage collection */
|
||||||
during_gc++;
|
during_gc++;
|
||||||
|
|
||||||
/* run data object's finalizers */
|
/* run data object's finalizers */
|
||||||
for (i = 0; i < heaps_used; i++) {
|
for (i = 0; i < heaps_used; i++) {
|
||||||
p = objspace->heap.sorted[i].start; pend = objspace->heap.sorted[i].end;
|
p = objspace->heap.sorted[i].start; pend = objspace->heap.sorted[i].end;
|
||||||
@ -3023,6 +3011,9 @@ rb_objspace_call_finalizer(rb_objspace_t *objspace)
|
|||||||
if (final_list) {
|
if (final_list) {
|
||||||
finalize_list(objspace, final_list);
|
finalize_list(objspace, final_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
st_free_table(finalizer_table);
|
||||||
|
finalizer_table = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
Loading…
x
Reference in New Issue
Block a user