mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
3636f8c0f5
commit
f5b15f0e3f
4 changed files with 81 additions and 25 deletions
25
ChangeLog
25
ChangeLog
|
@ -1,3 +1,28 @@
|
||||||
|
Tue Oct 22 14:53:11 2013 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
|
* 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.
|
||||||
|
|
||||||
Tue Oct 22 12:11:16 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Oct 22 12:11:16 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* configure.in: check if the given CFLAGS and LDFLAGS are working, and
|
* configure.in: check if the given CFLAGS and LDFLAGS are working, and
|
||||||
|
|
4
gc.c
4
gc.c
|
@ -1821,7 +1821,9 @@ rb_gc_finalize_deferred(void)
|
||||||
static void
|
static void
|
||||||
gc_finalize_deferred_register()
|
gc_finalize_deferred_register()
|
||||||
{
|
{
|
||||||
rb_postponed_job_register_one(0, gc_finalize_deferred, 0);
|
if (rb_postponed_job_register_one(0, gc_finalize_deferred, 0) == 0) {
|
||||||
|
rb_bug("gc_finalize_deferred_register: can't register finalizer.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct force_finalize_list {
|
struct force_finalize_list {
|
||||||
|
|
8
thread.c
8
thread.c
|
@ -1956,6 +1956,10 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
|
||||||
postponed_job_interrupt = interrupt & POSTPONED_JOB_INTERRUPT_MASK;
|
postponed_job_interrupt = interrupt & POSTPONED_JOB_INTERRUPT_MASK;
|
||||||
trap_interrupt = interrupt & TRAP_INTERRUPT_MASK;
|
trap_interrupt = interrupt & TRAP_INTERRUPT_MASK;
|
||||||
|
|
||||||
|
if (postponed_job_interrupt) {
|
||||||
|
rb_postponed_job_flush(th->vm);
|
||||||
|
}
|
||||||
|
|
||||||
/* signal handling */
|
/* signal handling */
|
||||||
if (trap_interrupt && (th == th->vm->main_thread)) {
|
if (trap_interrupt && (th == th->vm->main_thread)) {
|
||||||
enum rb_thread_status prev_status = th->status;
|
enum rb_thread_status prev_status = th->status;
|
||||||
|
@ -2004,10 +2008,6 @@ rb_threadptr_execute_interrupts(rb_thread_t *th, int blocking_timing)
|
||||||
rb_thread_schedule_limits(limits_us);
|
rb_thread_schedule_limits(limits_us);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (postponed_job_interrupt) {
|
|
||||||
rb_postponed_job_flush(th->vm);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
69
vm_trace.c
69
vm_trace.c
|
@ -1385,7 +1385,8 @@ typedef struct rb_postponed_job_struct {
|
||||||
void *data;
|
void *data;
|
||||||
} rb_postponed_job_t;
|
} rb_postponed_job_t;
|
||||||
|
|
||||||
#define MAX_POSTPONED_JOB 1024
|
#define MAX_POSTPONED_JOB 1000
|
||||||
|
#define MAX_POSTPONED_JOB_SPECIAL_ADDITION 24
|
||||||
|
|
||||||
static void
|
static void
|
||||||
Init_postponed_job(void)
|
Init_postponed_job(void)
|
||||||
|
@ -1395,22 +1396,25 @@ Init_postponed_job(void)
|
||||||
vm->postponed_job_index = 0;
|
vm->postponed_job_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* return 0 if job buffer is full */
|
enum postponed_job_register_result {
|
||||||
int
|
PJRR_SUCESS = 0,
|
||||||
rb_postponed_job_register(unsigned int flags, rb_postponed_job_func_t func, void *data)
|
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;
|
rb_postponed_job_t *pjob;
|
||||||
|
|
||||||
while (1) {
|
if (expected_index >= max) return PJRR_FULL; /* failed */
|
||||||
int index = vm->postponed_job_index;
|
|
||||||
if (index >= MAX_POSTPONED_JOB) return 0; /* failed */
|
|
||||||
|
|
||||||
if (ATOMIC_CAS(vm->postponed_job_index, index, index+1) == index) {
|
if (ATOMIC_CAS(vm->postponed_job_index, expected_index, expected_index+1) == expected_index) {
|
||||||
pjob = &vm->postponed_job_buffer[index];
|
pjob = &vm->postponed_job_buffer[expected_index];
|
||||||
break;
|
}
|
||||||
}
|
else {
|
||||||
|
return PJRR_INTERRUPTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
pjob->flags = flags;
|
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);
|
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
|
int
|
||||||
rb_postponed_job_register_one(unsigned int flags, rb_postponed_job_func_t func, void *data)
|
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;
|
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 */
|
begin:
|
||||||
for (i=0; i<vm->postponed_job_index; i++) {
|
index = vm->postponed_job_index;
|
||||||
|
for (i=0; i<index; i++) {
|
||||||
pjob = &vm->postponed_job_buffer[i];
|
pjob = &vm->postponed_job_buffer[i];
|
||||||
if (pjob->func == func) {
|
if (pjob->func == func) {
|
||||||
|
RUBY_VM_SET_POSTPONED_JOB_INTERRUPT(th);
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
switch (postponed_job_register(th, vm, flags, func, data, MAX_POSTPONED_JOB + MAX_POSTPONED_JOB_SPECIAL_ADDITION, index)) {
|
||||||
return rb_postponed_job_register(flags, func, data);
|
case PJRR_SUCESS : return 1;
|
||||||
|
case PJRR_FULL : return 0;
|
||||||
|
case PJRR_INTERRUPTED: goto begin;
|
||||||
|
default: rb_bug("unreachable\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue