[kaffe] A GC question

Guilhem Lavaux guilhem at kaffe.org
Sat Mar 18 23:40:56 PST 2006


Hi,

First, the GC is scanning all stacks including the native stacks looking
for references to "GC objects" which have been allocated using gcMalloc.
So the only point which poses problems is "obj = gcMalloc" at the moment
of the "=". In the facts it is not a problem because the thread is
suspended in two ways:
* the thread is calling itself some function and in that case we take
care of flushing the registers to the stack.
* the thread is suspended using a signal handler which causes also the
registers to be moved to the stack during all the time we are in the
signal handler.

So there must not be any problems here.

Regards,

Guilhem.


Ceyhun ÖZGÜN wrote:

> Hi,
> I have downloaded the sources and I was looking sources.
>
> I have a question in my mind about garbage collection.
>
> softcall_new(stack(0), class_object());
> #defined softcall_new(r, t)            (r)->v.taddr = soft_new(t)
> soft_new(Hjava_lang_Class* c)
> {
>     Hjava_lang_Object* obj;
>     errorInfo info;
>
>     if (c->state != CSTATE_COMPLETE && processClass(c,
> CSTATE_COMPLETE, &info) == false) {
>         goto bad;
>     }
>     obj = newObjectChecked(c, &info);
>     if (obj == 0) {
>         goto bad;
>     }
>
> DBG(NEWINSTR,
>     dprintf("New object of type %s (%d,%p)\n",
>         c->name->data, c->bfsize, obj); )
>
>     return (obj);
> bad:
>     throwError(&info);
>     return (0);
> }
>
>
> 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
>
> _________________________________________________________________
> Siz siz olun MSN'den hava durumunu ögrenmeden evden çikmayin!
> http://www.msn.com.tr/havadurumu/
>
>
> _______________________________________________
> kaffe mailing list
> kaffe at kaffe.org
> http://kaffe.org/cgi-bin/mailman/listinfo/kaffe






More information about the kaffe mailing list