[kaffe] race during thread creation and gc invocation
Helmer Krämer
hkraemer at freenet.de
Mon Dec 20 03:17:13 PST 2004
On Sat, 11 Dec 2004 21:50:54 +0100
Alexander Boettcher <ab764283 at os.inf.tu-dresden.de> wrote:
Hi Alexander,
> i have a race condition in thread.c found which (may) causes Kaffe to
> hang - for our L4 system it happens.
[skipping lame excuses for not responding earlier]
thanks for the detailed analysis :) I suspect that this may also be
the cause for some of the regression test failures on smp systems.
> So, jlThread can not be used in this form, a other pointer would be
> necessary in the threadData structure or the gc may not assume that
> jlThread is of type VMThread and has to handle it.
>
> What do you think ?
Probably the easiest way would be to simply skip uninitialized
threads in liveThreadWalker. To determine whether a thread is
properly initialized, we can (ab)use threadData.jniEnv and define
a thread as initialized iff threadData.jniEnv is not NULL. The
attached patch does exactly that and seems to work on my i386.
Could you probably give it a try?
Thanks,
Helmer
-------------- next part --------------
Index: kaffe/kaffevm/kaffe-gc/gc-refs.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/kaffe-gc/gc-refs.c,v
retrieving revision 1.7
diff -u -r1.7 gc-refs.c
--- kaffe/kaffevm/kaffe-gc/gc-refs.c 19 Dec 2004 06:41:29 -0000 1.7
+++ kaffe/kaffevm/kaffe-gc/gc-refs.c 20 Dec 2004 11:13:37 -0000
@@ -156,6 +156,12 @@
threadData *thread_data = KTHREAD(get_data)(tid);
Hjava_lang_VMThread *thread = (Hjava_lang_VMThread *)thread_data->jlThread;
+ /* if the gc is invoked while a new thread is being
+ * initialized, we better skip that thread.
+ */
+ if (!THREAD_DATA_INITIALIZED(thread_data))
+ return;
+
KGC_markObject(c, NULL, unhand(thread)->thread);
KGC_markObject(c, NULL, thread);
Index: kaffe/kaffevm/threadData.h
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/threadData.h,v
retrieving revision 1.4
diff -u -r1.4 threadData.h
--- kaffe/kaffevm/threadData.h 7 Jul 2004 16:05:13 -0000 1.4
+++ kaffe/kaffevm/threadData.h 20 Dec 2004 11:13:37 -0000
@@ -38,4 +38,6 @@
int needOnStack;
} threadData;
+#define THREAD_DATA_INITIALIZED(td) ((td)->jniEnv != NULL)
+
#endif
More information about the kaffe
mailing list