diff options
author | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-22 06:24:54 +0000 |
---|---|---|
committer | ko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-10-22 06:24:54 +0000 |
commit | f5b15f0e3f6d3f3b3467059802e24c8de0d9d361 (patch) | |
tree | 714c98acc6dabd7d4b0959744ae4eac36c325c82 /vm_trace.c | |
parent | 3636f8c0f56ddf15e26e28e7a38e748588fad976 (diff) | |
download | ruby-f5b15f0e3f6d3f3b3467059802e24c8de0d9d361.tar.gz |
* vm_trace.c: exterminate Zombies.
There is a bug that T_ZOMBIE objects are not collected.
Because there is a pass to miss finalizer postponed job
with multi-threading. This patch solve this issue.
* vm_trace.c (rb_postponed_job_register_one): set
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th) if another same job
is registered.
There is a possibility to remain a postponed job without
interrupt flag.
* vm_trace.c (rb_postponed_job_register_one): check interrupt
carefully.
* vm_trace.c (rb_postponed_job_register_one): use additional space
to avoid buffer full.
* gc.c (gc_finalize_deferred_register): check failure.
* thread.c (rb_threadptr_execute_interrupts): check
`postponed_job_interrupt' immediately. There is a possibility
to miss this flag.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43383 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'vm_trace.c')
-rw-r--r-- | vm_trace.c | 69 |
1 files changed, 49 insertions, 20 deletions
diff --git a/vm_trace.c b/vm_trace.c index 0e09c7e310..2371846580 100644 --- a/vm_trace.c +++ b/vm_trace.c @@ -1385,7 +1385,8 @@ typedef struct rb_postponed_job_struct { void *data; } rb_postponed_job_t; -#define MAX_POSTPONED_JOB 1024 +#define MAX_POSTPONED_JOB 1000 +#define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24 static void Init_postponed_job(void) @@ -1395,22 +1396,25 @@ Init_postponed_job(void) vm->postponed_job_index = 0; } -/* return 0 if job buffer is full */ -int -rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) +enum postponed_job_register_result { + PJRR_SUCESS = 0, + PJRR_FULL = 1, + PJRR_INTERRUPTED = 2 +}; + +static enum postponed_job_register_result +postponed_job_register(rb_thread_t *th, rb_vm_t *vm, + unsigned int flags, rb_postponed_job_func_t func, void *data, int max, int expected_index) { - rb_thread_t *th = GET_THREAD(); - rb_vm_t *vm = th->vm; rb_postponed_job_t *pjob; - while (1) { - int index = vm->postponed_job_index; - if (index >= MAX_POSTPONED_JOB) return 0; /* failed */ + if (expected_index >= max) return PJRR_FULL; /* failed */ - if (ATOMIC_CAS(vm->postponed_job_index, index, index+1) == index) { - pjob = &vm->postponed_job_buffer[index]; - break; - } + if (ATOMIC_CAS(vm->postponed_job_index, expected_index, expected_index+1) == expected_index) { + pjob = &vm->postponed_job_buffer[expected_index]; + } + else { + return PJRR_INTERRUPTED; } pjob->flags = flags; @@ -1420,25 +1424,50 @@ rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th); - return 1; + return PJRR_SUCESS; +} + + +/* return 0 if job buffer is full */ +int +rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data) +{ + rb_thread_t *th = GET_THREAD(); + rb_vm_t *vm = th->vm; + + begin: + switch (postponed_job_register(th, vm, flags, func, data, MAX_POSTPONED_JOB, vm->postponed_job_index)) { + case PJRR_SUCESS : return 1; + case PJRR_FULL : return 0; + case PJRR_INTERRUPTED: goto begin; + default: rb_bug("unreachable\n"); + } } +/* return 0 if job buffer is full */ int rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data) { - rb_vm_t *vm = GET_VM(); + rb_thread_t *th = GET_THREAD(); + rb_vm_t *vm = th->vm; rb_postponed_job_t *pjob; - int i; + int i, index; - /* TODO: this check is not signal safe, but I believe this is not critical prbolem */ - for (i=0; i<vm->postponed_job_index; i++) { + begin: + index = vm->postponed_job_index; + for (i=0; i<index; i++) { pjob = &vm->postponed_job_buffer[i]; if (pjob->func == func) { + RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th); return 2; } } - - return rb_postponed_job_register(flags, func, data); + switch (postponed_job_register(th, vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) { + case PJRR_SUCESS : return 1; + case PJRR_FULL : return 0; + case PJRR_INTERRUPTED: goto begin; + default: rb_bug("unreachable\n"); + } } void |