[kaffe] patch for mauve thread tests
Timothy Stack
stack@cs.utah.edu
Thu, 17 Oct 2002 10:34:55 -0600
hi,
The most recent mauve has some thread tests that kaffe fails, the
following patch should fix the following problems:
The "started" field wasn't being set for the main thread
The "group" field wasn't being cleared after the thread died.
The setPriority() method should throw an IllegalArgumentException
if the parameter is outside the range [MIN_PRIORITY, MAX_PRIORITY],
and not the ThreadGroup's max priority. If the parameter was
greater than the group's max priority it should be set the priority
to the group's maximum.
Unfortunately, kjc is causing the other failures. Specifically, the
code it generates for the first part of the daemon test:
Thread current = Thread.currentThread();
boolean status = current.isDaemon();
boolean illegal_exception = false;
try
{
current.setDaemon(!status);
}
catch (IllegalThreadStateException itse)
{
illegal_exception = true;
}
Looks like this:
.method public test(Lgnu/testlet/TestHarness;)V
.limit stack 3
.limit locals 9
.line 48
invokestatic java/lang/Thread/currentThread()Ljava/lang/Thread;
astore 4
.line 50
aload 4
invokevirtual java/lang/Thread/isDaemon()Z
istore 5
.line 51
iconst_0
istore 6
.line 54
.catch java/lang/IllegalThreadStateException from Label1 to Label2 using
Label3
Label1:
aload 4
iload 5
iconst_1
ixor
invokevirtual java/lang/Thread/setDaemon(Z)V
Label2:
goto Label4
.line 56
Label3:
astore 5
.line 58
iconst_1
istore 6
.line 60
Label4:
aload_1
aload 4
invokevirtual java/lang/Thread/isDaemon()Z
iload 5
if_icmpeq Label5
iconst_0
goto Label6
Label5:
Notice how slot five is used to store result of the first isDaemon(),
however, the exception handler will store the exception in slot five.
Oh, for a real verifier.
tim stack
Index: kaffe/kaffevm/thread.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/thread.c,v
retrieving revision 1.45
diff -u -r1.45 thread.c
--- kaffe/kaffevm/thread.c 3 Oct 2002 07:11:24 -0000 1.45
+++ kaffe/kaffevm/thread.c 17 Oct 2002 16:21:21 -0000
@@ -239,6 +239,7 @@
unhand(tid)->interrupting = 0;
unhand(tid)->target = 0;
unhand(tid)->group = standardGroup;
+
unhand(tid)->started = 1;
initThreadLock(tid);
Index: libraries/javalib/java/lang/Thread.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/lang/Thread.java,v
retrieving revision 1.38
diff -u -r1.38 Thread.java
--- libraries/javalib/java/lang/Thread.java 3 Jul 2002 22:33:14 -0000 1.38
+++ libraries/javalib/java/lang/Thread.java 17 Oct 2002 16:21:22 -0000
@@ -194,12 +194,16 @@
*/
/* Not private for now so GCJ won't optimize it away */
void finish() {
+
ThreadGroup tg;
+
synchronized(this) {
dying = true;
notifyAll(); // in case somebody is joining on us
+
tg = this.group;
+
this.group = null;
}
-
if (group != null) {
-
group.remove(this);
+
if (tg != null) {
+
tg.remove(this);
}
Application.removeResource(this);
}
@@ -332,7 +336,7 @@
}
public final synchronized void setDaemon(boolean on) {
-
if (started && !dying) {
+
if (started) {
throw new IllegalThreadStateException("Active Thread");
}
daemon = on;
@@ -345,8 +349,11 @@
public final void setPriority(int newPriority) {
checkAccess();
-
if (newPriority < MIN_PRIORITY || newPriority > group.getMaxPriority()) {
-
throw new IllegalArgumentException();
+
if (newPriority < MIN_PRIORITY || newPriority > MAX_PRIORITY) {
+
throw new IllegalArgumentException("Priority: " + newPriority);
+
}
+
if (newPriority > this.group.getMaxPriority()) {
+
newPriority = this.group.getMaxPriority();
}
setPriority0(newPriority);
}