[kaffe] A GC question

Ceyhun ÖZGÜN ceyhun_ozgun at hotmail.com
Sat Mar 18 04:22:17 PST 2006


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/





More information about the kaffe mailing list