|
A GC question: msg#00030java.vm.sablevm.devel
Hi, I have downloaded the sources and I was looking sources. I have a question in my mind about garbage collection. case SVM_INSTRUCTION_NEW: { #ifndef NDEBUG if (env->vm->verbose_instructions == JNI_TRUE) { _svmf_printf (env, stderr, "T%d: [verbose instructions: executing @%p NEW]\n", env->thread.id, (void *) (pc - 1)); } #endif /* instruction body */ pc++; /* skip preparation address */ { _svmt_class_info *class_info = (pc++)->class_info; _svmt_object_instance *instance; /* skip stack map */ assert (stack_size >= pc->stack_gc_map->size); pc++; /* save state */ env->stack.current_frame->pc = pc; env->stack.current_frame->stack_size = stack_size; if (_svmm_new_object_instance (env, class_info, instance) != JNI_OK) { _svmm_goto_label (exception_handler); } stack[stack_size++].reference = instance; } In the source above it allocates an object and pushes it to the stack. My question is, what if the thread that allocated the object is preempted right after the allocation and before pushing it to the stack. And scheduler switches to an another thread and that thread needs garbage collection. The garbage collector searches the roots (stack and frames etc) for references and it can not find any references because obj reference it is not pushed on the stack yet. So collector collects the newly allocated object and obj pointer in first thread becomes a ghost pointer. And later first thread runs and uses an deallocated area, possibly an area that belongs to an another object. And this situation is very bad. I have a solution in my mind, but I think it is not the best solution. Marking the object as NOT_USED in allocation and clearing that mark first access (assigning to stack, a local var, or a field of class/object). I have looked at Sun JDK sources (1.3, 1.4) and I did not see any workaround for this. What do you think? Thanks for advance. Ceyhun ÖZGÜN _________________________________________________________________ Yagmura yakalanmamak için sadece semsiyenize degil, MSN hava durumuna güvenin! http://www.msn.com.tr/havadurumu/
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | about SableJIT, David Bélanger |
|---|---|
| Next by Date: | Re: A GC question, Etienne Gagnon |
| Previous by Thread: | about SableJIT, David Bélanger |
| Next by Thread: | Re: A GC question, Etienne Gagnon |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |