[kaffe] Exit code when an exception was uncaught
Guilhem Lavaux
guilhem at kaffe.org
Sat Feb 26 07:47:23 PST 2005
Hi Daniel,
Thanks for the report. I don't know how I've managed to pass my test
previously however I have now a patch for this which fix the behaviour
of JNI_DestroyJavaVM (and consequently fix the problem you reported).
However this patch is only for unix-pthreads at the moment. I'll write
something for unix-jthreads asap and commit it.
Cheers,
Guilhem.
Daniel Bonniot wrote:
> Guilhem Lavaux wrote:
>
>> Hi Daniel,
>>
>> I had a few minutes free and checked it in the CVS. Now whenever there
>> is an uncaught exception happened kaffe-bin will return with 1 instead
>> of 0.
>>
>> Cheers,
>>
>> Guilhem.
>
>
> Guilhem, thanks a lot for looking into this. However, I tried with the
> latest Debian package, which includes your change, and it does not seem
> to make any difference in this case. Here is the testcase, and
> transcript while running with JDK and kaffe.
>
> $ cat Field.java
> class Field {
> public static void main(String[] args)
> {
> throw new Error();
> }
> }
> $ javac Field.java
> $ java Field && echo OOOOPS
> Exception in thread "main" java.lang.Error
> at Field.main(Field.java:4)
> $ kaffe Field && echo OOOOPS
> java.lang.Error
> at Field.main (Field.java:4)
> OOOOPS
> $ kaffe -fullversion
> ...
> ChangeLog head : 2005-02-15 Guilhem Lavaux <guilhem at kaffe.org>
>
>
> Cheers,
>
> Daniel
>
> PS: I checked, and unless I made a mistake, it did not look like it was
> the kaffe shell script losing the exit code.
>
> _______________________________________________
> kaffe mailing list
> kaffe at kaffe.org
> http://kaffe.org/cgi-bin/mailman/listinfo/kaffe
>
-------------- next part --------------
Index: kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c,v
retrieving revision 1.73
diff -u -r1.73 thread-impl.c
--- kaffe/kaffevm/systems/unix-pthreads/thread-impl.c 20 Feb 2005 00:55:48 -0000 1.73
+++ kaffe/kaffevm/systems/unix-pthreads/thread-impl.c 26 Feb 2005 15:51:34 -0000
@@ -1004,9 +1004,10 @@
*/
}
-/*
+/**
* Function to be called (by threads.c firstStartThread) when the thread leaves
- * the user thread function
+ * the user thread function. If the calling thread is the main thread then it
+ * suspend the thread until all other threads has exited.
*/
void
jthread_exit ( void )
@@ -1044,7 +1045,9 @@
}
for ( t=activeThreads; t != NULL; t = t->next ){
- if ( t != cur ) {
+ /* We must not kill the current thread and the main thread
+ */
+ if ( t != cur && t != firstThread) {
/* Mark the thread as to be killed. */
t->status = THREAD_KILL;
/* Send an interrupt event to the remote thread.
@@ -1066,27 +1069,32 @@
#endif
if ( (cur != firstThread) && (firstThread->active == 0) ) {
- /* if the firstThread has already been frozen, it's not in the cache list */
- pthread_cancel( firstThread->tid);
+ /* if the firstThread has already been frozen,
+ * it's not in the cache list. We must wake it up because
+ * this thread is the last one alive and it is exiting. */
repsem_post (&firstThread->sem);
}
- unprotectThreadList(cur);
- pthread_exit( NULL);
+ /* This is not the main thread so we may kill it. */
+ if (cur != firstThread)
+ {
+ unprotectThreadList(cur);
+ pthread_exit( NULL);
- /* we shouldn't get here, this is a last safeguard */
- EXIT(0);
+ /* we shouldn't get here, this is a last safeguard */
+ EXIT(0);
+ }
}
unprotectThreadList(cur);
}
- if ( cur == firstThread ) {
- /*
- * We don't cache this one, but we have to remove it from the active list. Note
- * that the firstThread always has to be the last entry in the activeThreads list
- * (we just add new entries at the head)
- */
- protectThreadList(cur);
+ /*
+ * We don't cache this one, but we have to remove it from the active list. Note
+ * that the firstThread always has to be the last entry in the activeThreads list
+ * (we just add new entries at the head)
+ */
+ protectThreadList(cur);
+ if ( cur == firstThread && nonDaemons != 0) {
/* if we would be the head, we would have been the last, too (and already exited) */
assert( cur != activeThreads);
@@ -1097,22 +1105,15 @@
unprotectThreadList(cur);
- /*
- * Put us into a permanent freeze to avoid shut down of the whole process (it's
- * not clear if this is common pthread behavior or just a implementation
- * linux-threads "feature")
+ /* Put the main thread in a frozen state waiting for the other
+ * real threads to terminate. The main thread gets the control back
+ * after that.
*/
repsem_wait( &cur->sem);
-
- /* We put here a safe-guard in case the pthread_cancel has not managed
- * to do its job and that repsem_wait awakes.
- */
- pthread_exit(NULL);
}
- else {
+ else if (cur != firstThread) {
/* flag that we soon will get a new cache entry (would be annoying to
* create a new thread in the meantime) */
- protectThreadList(cur);
pendingExits++;
unprotectThreadList(cur);
}
More information about the kaffe
mailing list