[kaffe] CVS kaffe (hkraemer): moved handling of thread interruption to jthread layer,

Kaffe CVS cvs-commits at kaffe.org
Sun Oct 31 06:41:34 PST 2004


PatchSet 5389 
Date: 2004/10/31 14:35:33
Author: hkraemer
Branch: HEAD
Tag: (none) 
Log:
moved handling of thread interruption to jthread layer,
some minor fixes

Members: 
	ChangeLog:1.2940->1.2941 
	include/errors.h:1.13->1.14 
	kaffe/kaffevm/stackTrace.c:1.38->1.39 
	kaffe/kaffevm/thread.c:1.79->1.80 
	kaffe/kaffevm/jni/jni.c:1.7->1.8 
	kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.123->1.124 
	kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.63->1.64 
	kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.10->1.11 
	kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.50->1.51 
	libraries/clib/native/Object.c:1.9->1.10 
	libraries/clib/native/Thread.c:1.18->1.19 
	libraries/javalib/java/lang/VMObject.java:1.1->1.2 
	libraries/javalib/java/lang/VMThread.java:1.1->1.2 
	libraries/javalib/kaffe/lang/ThreadStack.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2940 kaffe/ChangeLog:1.2941
--- kaffe/ChangeLog:1.2940	Sun Oct 31 13:36:22 2004
+++ kaffe/ChangeLog	Sun Oct 31 14:35:33 2004
@@ -1,3 +1,53 @@
+2004-10-31  Helmer Kraemer  <hkraemer at freenet.de>
+
+	Moved complete handling of thread interruption down to jthread layer:
+	
+	* kaffe/kaffevm/systems/unix-jthreads/jthread.h
+	(THREAD_FLAGS_INTERRUPTED_READ) removed
+	* kaffe/kaffevm/systems/unix-jthreads/jthread.c
+	(suspendOnQThread): don't clear interrupted flag
+	(jthread_interrupt): set interrupted flag if a thread interrupts
+	itself; only resume threads not waiting for a mutex
+
+	* kaffe/kaffevm/systems/unix-pthreads/lock-impl.c
+	(jcondvar_wait): don't mess around with interrupted flag, it's
+	set correctly by the interrupting thread
+	* kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
+	(jthread_interrupt): if thread is waiting for its semaphore, signal that
+	one instead of sending a signal
+	(jthread_is_interrupted, jthread_interrupted): add comments
+	(jthread_suspendall): lock thread's suspendLock before reading its
+	suspendState
+
+	* include/errors.h: added define for java.lang.InterruptedException
+	
+	* libraries/clib/native/Object.c, libraries/javalib/java/lang/VMObject.java
+	(nativeWait): removed
+	(wait): moved to native code
+
+	* libraries/clib/native/Thread.c, libraries/javalib/java/lang/VMThread.java
+	(nativeInterrupt, nativeIsInterrupted, nativeInterrupted): removed
+	(interrupt, isInterrupted, interrupted, sleep): moved to native code
+
+	Some other minor fixes:
+
+	* libraries/javalib/kaffe/lang/ThreadStack.java
+	(getCallersClassLoader): return AppClassLoader if there're no java methods
+	on the stack
+
+	* kaffe/kaffevm/jni/jni.c (tryClassForName): removed
+	(Kaffe_FindClass): simply call Class.forName and let ThreadStack find the
+	correct ClassLoader
+	
+	* libraries/javalib/Klasses.jar.bootstrap: regenerated
+	
+	* kaffe/kaffevm/stackTrace.c (getStackTraceElements): adapted to
+	changes of field names of java.lang.StackTraceElement
+	
+	* kaffe/kaffevm/thread.c (thread_malloc, thread_free,
+	thread_realloc): removed
+	Added debug messages and removed unused variables
+	
 2004-10-30  Dalibor Topic  <robilad at kaffe.org>
 
 	* libraries/javalib/gnu/xml/xpath/VariableReference.java,
Index: kaffe/include/errors.h
diff -u kaffe/include/errors.h:1.13 kaffe/include/errors.h:1.14
--- kaffe/include/errors.h:1.13	Tue Oct 12 17:00:10 2004
+++ kaffe/include/errors.h	Sun Oct 31 14:35:32 2004
@@ -107,6 +107,7 @@
 #define ThreadDeath NEW_LANG_EXCEPTION(ThreadDeath)
 #define StackOverflowError NEW_LANG_EXCEPTION(StackOverflowError)
 #define IllegalThreadStateException NEW_LANG_EXCEPTION(IllegalThreadStateException)
+#define InterruptedException NEW_LANG_EXCEPTION(InterruptedException)
 #define	InstantiationException(M) NEW_LANG_EXCEPTION_MESSAGE(InstantiationException, M)
 
 #if !defined(KAFFEH)
Index: kaffe/kaffe/kaffevm/stackTrace.c
diff -u kaffe/kaffe/kaffevm/stackTrace.c:1.38 kaffe/kaffe/kaffevm/stackTrace.c:1.39
--- kaffe/kaffe/kaffevm/stackTrace.c:1.38	Fri Oct 22 22:32:41 2004
+++ kaffe/kaffe/kaffevm/stackTrace.c	Sun Oct 31 14:35:32 2004
@@ -184,7 +184,7 @@
 					(CLASS_SOURCEFILE(meth->class));
 				unhand(element)->lineNumber
 					= getLineNumber(meth, stack[i].pc);
-				unhand(element)->className
+				unhand(element)->declaringClass
 					= utf8Const2JavaReplace
 					(meth->class->name, '/', '.');
 				unhand(element)->methodName
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.79 kaffe/kaffe/kaffevm/thread.c:1.80
--- kaffe/kaffe/kaffevm/thread.c:1.79	Wed Oct 27 16:12:03 2004
+++ kaffe/kaffe/kaffevm/thread.c	Sun Oct 31 14:35:32 2004
@@ -61,30 +61,6 @@
 static void firstStartThread(void*);
 static void runfinalizer(void);
 
-/*
- * How do I get memory?
- */
-static
-void *
-thread_malloc(size_t s)
-{
-	return gc_malloc(s, KGC_ALLOC_THREADCTX);
-}
-
-static
-void
-thread_free(void *p)
-{
-	gc_free(p);
-}
-
-static
-void *
-thread_realloc(void *p, size_t s)
-{
-	return gc_realloc(p, s, KGC_ALLOC_THREADCTX);
-}
-
 static void
 linkNativeAndJavaThread(jthread_t thread, Hjava_lang_VMThread *jlThread)
 {
@@ -169,7 +145,8 @@
 {
 	jthread_t nativeTid;
 	struct _errorInfo info;
-	int iLockRoot;
+
+DBG(VMTHREAD, dprintf ("%p starting thread %p (vmthread %p)\n\n", jthread_current(), unhand(tid)->thread, tid); )
 
 	/* Hold the start lock while the thread is created.
 	 * This lock prevents the new thread from running until we're
@@ -195,9 +172,11 @@
 void
 interruptThread(Hjava_lang_VMThread* tid)
 {
-	if ((jthread_t)unhand(tid)->jthreadID) {
-		jthread_interrupt((jthread_t)unhand(tid)->jthreadID);
-	}
+DBG(VMTHREAD, dprintf ("%p (%p) interrupting %p (%p)\n", jthread_current(),
+                       THREAD_DATA()->jlThread, unhand(tid)->jthreadID, tid); )
+	assert(unhand(tid)->jthreadID != NULL);
+
+	jthread_interrupt((jthread_t)unhand(tid)->jthreadID);
 }
 
 /*
@@ -293,7 +272,6 @@
 	void (*func)(void *);
 	void **pointer_args = (void **)arg;
 	void *argument;
-	int iLockRoot;
 	jthread_t calling_thread;
 
 	ksemInit(&THREAD_DATA()->sem);
@@ -333,7 +311,6 @@
   Hjava_lang_Thread* tid;
   Hjava_lang_VMThread *vmtid;
   jthread_t nativeTid;
-  int iLockRoot;
   Hjava_lang_String* name;
   void *specialArgument[3];
 
@@ -400,7 +377,6 @@
 	jthread_t cur;
 	JNIEnv *env;
 	jmethodID runmethod;
-	int iLockRoot;
 	jthread_t calling_thread = (jthread_t) arg;
 
 	cur = jthread_current();
@@ -429,7 +405,7 @@
 #endif
 
 DBG(VMTHREAD,	
-	dprintf("firstStartThread %p\n", tid);		
+	dprintf("%p (%p) firstStartThread\n", cur, tid);		
     )
 
 	/*
@@ -483,7 +459,7 @@
 exitThread(void)
 {
 DBG(VMTHREAD,	
-	dprintf("exitThread %p\n", getCurrentThread());		
+	dprintf("%p (%p) exitThread\n", jthread_current(), THREAD_DATA()->jlThread);
     )
 
 #if defined(ENABLE_JVMPI)
Index: kaffe/kaffe/kaffevm/jni/jni.c
diff -u kaffe/kaffe/kaffevm/jni/jni.c:1.7 kaffe/kaffe/kaffevm/jni/jni.c:1.8
--- kaffe/kaffe/kaffevm/jni/jni.c:1.7	Thu Aug 19 19:29:06 2004
+++ kaffe/kaffe/kaffevm/jni/jni.c	Sun Oct 31 14:35:37 2004
@@ -217,28 +217,11 @@
  */
 
 static jclass
-tryClassForName(jstring nameString)
-{
-	jvalue retval;
-
-	BEGIN_EXCEPTION_HANDLING(0);
-
-	/* Call Class.forName() */
-	retval = do_execute_java_class_method("java.lang.Class", NULL,
-	    "forName", "(Ljava/lang/String;)Ljava/lang/Class;", nameString);
-
-	END_EXCEPTION_HANDLING();
-
-	return retval.l;
-}
-
-static jclass
 Kaffe_FindClass(JNIEnv* env, const char* name)
 {
 	jstring nameString;
 	Utf8Const* utf8;
 	jobject retval;
-	jobject exc;
 
 	BEGIN_EXCEPTION_HANDLING(0);
 
@@ -248,42 +231,9 @@
 	utf8ConstRelease(utf8);
 	checkPtr(nameString);
 
-	retval = tryClassForName(nameString);
-
-	exc = thread_data->exceptObj;
-	if (exc != NULL)
-	{
-		if (soft_instanceof(javaLangClassNotFoundException, exc))
-		{
-			int iLockRoot;
-			static iStaticLock appLock = KAFFE_STATIC_LOCK_INITIALIZER;
-
-			thread_data->exceptObj = NULL;
-			if (appClassLoader == NULL)
-			{
-				lockStaticMutex(&appLock);
-				if (appClassLoader == NULL)
-					appClassLoader = do_execute_java_method(kaffeLangAppClassLoaderClass, "getSingleton", "()Ljava/lang/ClassLoader;", NULL, true).l;
-				unlockStaticMutex(&appLock);
-
-				if (thread_data->exceptObj != NULL)
-				{
-					fprintf(stderr,
-						"ERROR: The default user class loader "
-					       	APPCLASSLOADERCLASS " can not be loaded.\n"
-						"Aborting...\n");
-					ABORT();
-				}
-			}
-
-			
-			retval = do_execute_java_class_method("java.lang.Class", NULL,
-			    "forName", "(Ljava/lang/String;ZLjava/lang/ClassLoader;)Ljava/lang/Class;", nameString, true, appClassLoader).l;
-			ADD_REF(retval);
-		}
-	} else {
-		ADD_REF(retval);
-	}
+	retval = do_execute_java_class_method("java.lang.Class", NULL,
+		"forName", "(Ljava/lang/String;)Ljava/lang/Class;", nameString).l;
+	ADD_REF(retval);
 
 	END_EXCEPTION_HANDLING();
 	return (retval);
@@ -1040,7 +990,7 @@
 	MIN_HEAPSIZE,	/* Min heap size */
 	MAX_HEAPSIZE,	/* Max heap size */
 	/*	2,	*/	/* Verify mode ... verify remote by default */
-	0,              /* Verify mode ... noverify by default */
+	0,		/* Verify mode ... noverify by default */
 	".",		/* Classpath */
 	0,		/* Bootclasspath */
 	(void*)&vfprintf,/* Vprintf */
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.123 kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.124
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c:1.123	Wed Oct 20 16:47:14 2004
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.c	Sun Oct 31 14:35:37 2004
@@ -941,7 +941,6 @@
 				if (jtid == currentJThread) {
 					reschedule();
 					if (jtid->flags & THREAD_FLAGS_INTERRUPTED) {
-						jtid->flags &= ~(THREAD_FLAGS_INTERRUPTED|THREAD_FLAGS_INTERRUPTED_READ);
 						rc = true;
 					}
 				}
@@ -1470,11 +1469,14 @@
 {
 	intsDisable();
 
+	/* mark thread as interrupted */
+	jtid->flags |= THREAD_FLAGS_INTERRUPTED;
+
 	/* make sure we only resume suspended threads 
-	 * (and neither dead nor runnable threads)
+	 * (and neither dead nor runnable threads) that
+	 * are not trying to acquire a mutex.
 	 */
-	if (jtid != currentJThread && jtid->status == THREAD_SUSPENDED) {
-		jtid->flags |= THREAD_FLAGS_INTERRUPTED;
+	if ((jtid->status == THREAD_SUSPENDED) && !jthread_on_mutex(jtid)) {
 		resumeThread(jtid);
 	}
 	intsRestore();
@@ -2695,11 +2697,13 @@
 
 int jthread_interrupted(jthread_t jt)
 {
-	if (jt->flags & THREAD_FLAGS_INTERRUPTED_READ || !(jt->flags & THREAD_FLAGS_INTERRUPTED))
-		return 0;
+	if (jt->flags & THREAD_FLAGS_INTERRUPTED)
+	{
+		jt->flags &= ~THREAD_FLAGS_INTERRUPTED;
+		return 1;
+	}
 
-	jt->flags |= THREAD_FLAGS_INTERRUPTED_READ;
-	return 1;
+	return 0;
 }
 
 int jthread_on_mutex(jthread_t jt)
Index: kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h
diff -u kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.63 kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.64
--- kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h:1.63	Wed Oct 20 16:47:14 2004
+++ kaffe/kaffe/kaffevm/systems/unix-jthreads/jthread.h	Sun Oct 31 14:35:37 2004
@@ -86,7 +86,6 @@
 #define THREAD_FLAGS_INTERRUPTED	128
 #define THREAD_FLAGS_WAIT_MUTEX		256
 #define THREAD_FLAGS_WAIT_CONDVAR	512
-#define THREAD_FLAGS_INTERRUPTED_READ   1024
 
 /*
  * This is our internal structure representing the "native" threads.
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.10 kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.11
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c:1.10	Mon Sep 20 15:48:45 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/lock-impl.c	Sun Oct 31 14:35:38 2004
@@ -81,13 +81,17 @@
   int             status;
   struct timespec abst;
   struct timeval  now;
-  //CHECK_LOCK( cur,lk);
 
-  cur->interrupting = 0;
+  /*
+   * If a thread trying to get a heavy lock is interrupted, we may get here
+   * with the interrupted flag set (because the thread didn't get the heavy
+   * lock and has to wait again). Therefore, we must not clear the interrupted
+   * flag here.
+   */
 
   if ( timeout == NOTIMEOUT )
     {
-      /* we handle this as "wait forever"	*/
+      /* we handle this as "wait forever" */
       status = ThreadCondWait(cur, cv, mux);
     }
   else
@@ -116,7 +120,12 @@
 	}
     }
 
-  cur->interrupting = (status == EINTR);
-  
+  /*
+   * Since we interrupt a thread blocked on a condition variable by signaling that
+   * condition variable, we cannot set the interrupted flag based on the value of
+   * 'signal'. Therefore, we have to rely on the interrupting thread to set the
+   * flag.
+   */
+
   return (status == 0);
 }
Index: kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c
diff -u kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.50 kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.51
--- kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c:1.50	Fri Oct 22 21:51:36 2004
+++ kaffe/kaffe/kaffevm/systems/unix-pthreads/thread-impl.c	Sun Oct 31 14:35:38 2004
@@ -588,18 +588,46 @@
   return (nt);
 }
 
+/**
+ * Interrupt a thread.
+ * 
+ * If tid is currently blocked its interrupted flag is set
+ * and the blocking operation is canceled.
+ */
 void jthread_interrupt(jthread_t tid)
 {
+  pthread_mutex_lock(&tid->suspendLock);
+
   tid->interrupting = 1;
-  /* We need to send some signal to interrupt syscalls. */
-  pthread_kill(tid->tid, sigInterrupt);
+
+  if ((tid->blockState & (BS_CV|BS_CV_TO)) != 0)
+    {
+      pthread_cond_signal (&tid->data.sem.cv);
+    }
+  else if(tid->blockState == 0)
+    {
+      /* We need to send some signal to interrupt syscalls. */
+      pthread_kill(tid->tid, sigInterrupt);
+    }
+
+  pthread_mutex_unlock(&tid->suspendLock);
 }
 
+/**
+ * Peek at the interrupted flag of a thread.
+ *
+ * @return true iff jt was interrupted.
+ */
 int jthread_is_interrupted(jthread_t jt)
 {
   return jt->interrupting;
 }
 
+/**
+ * Read and clear the interrupted flag of a thread.
+ *
+ * @return true iff jt was interrupted.
+ */
 int jthread_interrupted(jthread_t jt)
 {
   int i = jt->interrupting;
@@ -1192,11 +1220,11 @@
 	   * signals handled by threads which are blocked on someting else
 	   * than the thread lock (which we soon release)
 	   */
+	  pthread_mutex_lock(&t->suspendLock);
 	  if ( (t != cur) && (t->suspendState == 0) && (t->active != 0) ) {
 		DBG( JTHREAD, dprintf("signal suspend: %p (susp: %d blk: %d)\n",
 				      t, t->suspendState, t->blockState))
 
-		pthread_mutex_lock(&t->suspendLock);
 		t->suspendState = SS_PENDING_SUSPEND;
 
 		if ((t->blockState & (BS_CV|BS_MUTEX|BS_CV_TO)) != 0)
@@ -1221,8 +1249,8 @@
 			sem_wait( &critSem);
 		      }
 		  }
-		pthread_mutex_unlock(&t->suspendLock);
 	  }
+	  pthread_mutex_unlock(&t->suspendLock);
 	}
 
 #else
Index: kaffe/libraries/clib/native/Object.c
diff -u kaffe/libraries/clib/native/Object.c:1.9 kaffe/libraries/clib/native/Object.c:1.10
--- kaffe/libraries/clib/native/Object.c:1.9	Thu Jul 29 14:24:54 2004
+++ kaffe/libraries/clib/native/Object.c	Sun Oct 31 14:35:32 2004
@@ -24,6 +24,7 @@
 #include "java_lang_VMObject.h"
 #include "thread.h"
 #include "jvmpi_kaffe.h"
+#include "debug.h"
 
 /*
  * Return class object for this object.
@@ -89,8 +90,19 @@
  * Wait for this object to be notified.
  */
 void
-java_lang_VMObject_nativeWait(struct Hjava_lang_Object* o, jlong timeout, UNUSED jint ns)
+java_lang_VMObject_wait(struct Hjava_lang_Object* o, jlong timeout, UNUSED jint ns)
 {
+  jthread_t cur = jthread_current();
+
+  if(jthread_interrupted(cur))
+    {
+      throwException(InterruptedException);
+    }
+
+DBG(VMTHREAD, dprintf ("%p (%p) waiting for %p, %d\n",
+			cur, jthread_get_data(cur)->jlThread,
+			o, timeout); )
+
 #if defined(ENABLE_JVMPI)
   if( JVMPI_EVENT_ISENABLED(JVMPI_EVENT_MONITOR_WAIT) )
     {
@@ -128,4 +140,9 @@
       jvmpiPostEvent(&ev);
     }
 #endif
+
+  if(jthread_interrupted(cur))
+    {
+      throwException(InterruptedException);
+    }
 }
Index: kaffe/libraries/clib/native/Thread.c
diff -u kaffe/libraries/clib/native/Thread.c:1.18 kaffe/libraries/clib/native/Thread.c:1.19
--- kaffe/libraries/clib/native/Thread.c:1.18	Thu Jul 29 14:24:54 2004
+++ kaffe/libraries/clib/native/Thread.c	Sun Oct 31 14:35:32 2004
@@ -20,6 +20,7 @@
 #include "locks.h"
 #include "support.h"
 #include "jthread.h"
+#include "debug.h"
 
 struct Hjava_lang_Thread*
 java_lang_VMThread_currentThread(void)
@@ -55,7 +56,7 @@
 }
 
 void
-java_lang_VMThread_nativeInterrupt(struct Hjava_lang_VMThread* this)
+java_lang_VMThread_interrupt(struct Hjava_lang_VMThread* this)
 {
   interruptThread(this);
 }
@@ -66,12 +67,46 @@
   finalizeThread(this);
 }
 
-jboolean java_lang_VMThread_nativeInterrupted(void)
+jboolean java_lang_VMThread_interrupted(void)
 {
   return jthread_interrupted(jthread_current());
 }
 
-jboolean java_lang_VMThread_nativeIsInterrupted(Hjava_lang_VMThread *this)
+jboolean java_lang_VMThread_isInterrupted(Hjava_lang_VMThread *this)
 {
   return jthread_is_interrupted((jthread_t)unhand(this)->jthreadID);
+}
+
+
+void java_lang_VMThread_sleep(jlong timeout, UNUSED jint ns)
+{
+  jthread_t	cur = jthread_current();
+
+  if(jthread_interrupted(cur))
+    {
+      throwException(InterruptedException);
+    }
+
+DBG(VMTHREAD, dprintf ("%p (%p) sleeping for %d\n", cur,
+			jthread_get_data(cur)->jlThread, timeout); )
+
+  /*
+   * Using the semaphore of this thread for sleeping is safe, since
+   * there are only two reasons for another thread to invoke ksemPut
+   * on this semaphore:
+   *
+   *     - it releases a lock this thread is waiting for, or
+   *     - it has to signal this thread that it has been started.
+   *
+   * None of these apply here (we're neither waiting for a lock nor
+   * starting a new thread). Since the jthread implementation has to
+   * be able to interrupt a thread waiting for its semaphore anyway,
+   * this thread can still be interrupted.
+   */
+  ksemGet(&jthread_get_data(cur)->sem, timeout);
+
+  if(jthread_interrupted(cur))
+    {
+      throwException(InterruptedException);
+    }
 }
Index: kaffe/libraries/javalib/java/lang/VMObject.java
diff -u kaffe/libraries/javalib/java/lang/VMObject.java:1.1 kaffe/libraries/javalib/java/lang/VMObject.java:1.2
--- kaffe/libraries/javalib/java/lang/VMObject.java:1.1	Thu Jul 29 14:42:28 2004
+++ kaffe/libraries/javalib/java/lang/VMObject.java	Sun Oct 31 14:35:37 2004
@@ -91,23 +91,6 @@
    *         lock on the Object
    * @throws InterruptedException if some other Thread interrupts this Thread
    */
-  static void wait(Object o, long ms, int ns)
-    throws IllegalMonitorStateException, InterruptedException
-  {
-    Thread current = Thread.currentThread();
-    VMThread vmt = current.vmThread;
-    
-    if (current.interrupted())
-      throw new InterruptedException();
-    
-    vmt.holder = o;
-    nativeWait(o, ms, ns);
-    vmt.holder = null;
-    
-    if (current.interrupted())
-      throw new InterruptedException();
-  }
-
-  static native void nativeWait(Object o, long ms, int ns)
-      throws IllegalMonitorStateException, InterruptedException;
+  static native void wait(Object o, long ms, int ns)
+    throws IllegalMonitorStateException, InterruptedException;
 }
Index: kaffe/libraries/javalib/java/lang/VMThread.java
diff -u kaffe/libraries/javalib/java/lang/VMThread.java:1.1 kaffe/libraries/javalib/java/lang/VMThread.java:1.2
--- kaffe/libraries/javalib/java/lang/VMThread.java:1.1	Thu Jul 29 14:42:28 2004
+++ kaffe/libraries/javalib/java/lang/VMThread.java	Sun Oct 31 14:35:37 2004
@@ -91,21 +91,6 @@
     private Ptr jthreadID;
 
     /**
-     * Kaffe Specific: Object instance to fall asleep.
-     */
-    private Object sleeper;
-
-    /**
-     * Kaffe Specific: Object which is holding the thread.
-     */
-    Object holder;
-    
-    /**
-     * Kaffe Specific: Thread is being interrupted.
-     */ 
-    private boolean interrupting;
-    
-    /**
      * Private constructor, create VMThreads with the static create method.
      *
      * @param thread The Thread object that was just created.
@@ -325,23 +310,7 @@
     /**
      * Interrupt this thread.
      */
-    void interrupt()
-    {
-      interrupting = true;
-      Object h = holder;
-      if (h != null)
-	{
-	  holder = null;
-	  synchronized(h)
-	    {
-	      h.notify();
-	    }
-	}
-      else
-	nativeInterrupt();
-    }
-
-    private native void nativeInterrupt();
+    native void interrupt();
 
     /**
      * Determine whether this Thread has been interrupted, but leave
@@ -349,12 +318,7 @@
      *
      * @return whether the Thread has been interrupted
      */
-    boolean isInterrupted()
-    {
-      return interrupting || nativeIsInterrupted();
-    }
-
-    private native boolean nativeIsInterrupted();
+    native boolean isInterrupted();
 
     /**
      * Suspend this Thread.  It will not come back, ever, unless it is resumed.
@@ -396,7 +360,7 @@
      *
      * @return the currently executing Thread
      */
-    native static Thread currentThread();
+    static native Thread currentThread();
 
     /**
      * Yield to another thread. The Thread will not lose any locks it holds
@@ -424,18 +388,7 @@
      *         <i>interrupted status</i> will be cleared
      * @throws IllegalArgumentException if ns is invalid
      */
-    static void sleep(long ms, int ns) throws InterruptedException
-    {
-      VMThread curr = currentThread().vmThread;
-	
-      if (curr.sleeper == null)
-	curr.sleeper = new Object();
-	
-      synchronized (curr.sleeper)
-	{
-	  curr.sleeper.wait(ms, ns);
-	}
-    }
+    static native void sleep(long ms, int ns) throws InterruptedException;
 
     /**
      * Determine whether the current Thread has been interrupted, and clear
@@ -443,16 +396,7 @@
      *
      * @return whether the current Thread has been interrupted
      */
-    static boolean interrupted()
-    {
-      VMThread vmt = Thread.currentThread().vmThread;
-      boolean i = nativeInterrupted() || vmt.interrupting;
-
-      vmt.interrupting = false;
-      return i;
-    }
-
-    static native boolean nativeInterrupted();
+    static native boolean interrupted();
 
     /**
      * Kaffe Specific: finalize thread
Index: kaffe/libraries/javalib/kaffe/lang/ThreadStack.java
diff -u kaffe/libraries/javalib/kaffe/lang/ThreadStack.java:1.2 kaffe/libraries/javalib/kaffe/lang/ThreadStack.java:1.3
--- kaffe/libraries/javalib/kaffe/lang/ThreadStack.java:1.2	Sat Jun 28 18:06:41 2003
+++ kaffe/libraries/javalib/kaffe/lang/ThreadStack.java	Sun Oct 31 14:35:31 2004
@@ -80,10 +80,11 @@
 		/*
 		 * if this is already the last class on the stack, we're done
 		 * this should only happen in the very beginning when main.c
-		 * calls FindClass and thus forName outside a java class.
+		 * calls FindClass and thus forName outside a java class, so
+		 * we return the AppClassLoader in this case.
 		 */
 		if (frameIdx == classStack.length) {
-			return javaPrimordial ? PrimordialClassLoader.getSingleton() : null;
+			return AppClassLoader.getSingleton();
 		}
 
 		/*




More information about the kaffe mailing list