-/* nat/Thread.c - java/lang/Thread
+/* native/vm/VMThread.c - java/lang/VMThread
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Changes: Joseph Wenninger
- $Id: VMThread.c 1173 2004-06-16 14:56:18Z jowenn $
+ $Id: VMThread.c 2195 2005-04-03 16:53:16Z edwin $
*/
-#include "jni.h"
-#include "builtin.h"
+#include "config.h"
#include "types.h"
-#include "native.h"
-#include "loader.h"
-#include "tables.h"
-#include "threads/thread.h"
+#include "native/jni.h"
+#include "native/native.h"
+#include "native/include/java_lang_ThreadGroup.h"
+#include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
+#include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
+#include "native/include/java_lang_VMThread.h"
+#include "native/include/java_lang_Thread.h"
+
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+# include "threads/native/threads.h"
+# else
+# include "threads/green/threads.h"
+# endif
+#endif
+
#include "toolbox/logging.h"
-#include "java_lang_ThreadGroup.h"
-#include "java_lang_Object.h" /* needed for java_lang_Thread.h */
-#include "java_lang_Throwable.h" /* needed for java_lang_Thread.h */
-#include "java_lang_VMThread.h"
-#include "java_lang_Thread.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/options.h"
+#include "vm/tables.h"
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: countStackFrames
* Signature: ()I
*/
}
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: currentThread
* Signature: ()Ljava/lang/Thread;
*/
JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
{
java_lang_Thread *t;
+ classinfo *threadgroupclass;
if (runverbose)
log_text("java_lang_VMThread_currentThread called");
#if !defined(NATIVE_THREADS)
t = (java_lang_Thread *) currentThread;
#else
- t = THREADOBJECT;
+ t = ((threadobject*) THREADOBJECT)->o.thread;
#endif
+ if (runverbose)
+ log_text("java_lang_VMThread_currentThread 111");
+ if ((runverbose) && (t == NULL))
+ log_text("t ptr is NULL\n");
+if (t == NULL) printf("t ptr is NULL\n"); fflush(stdout);
if (!t->group) {
- log_text("java_lang_VMThread_currentThread: t->group=NULL");
/* ThreadGroup of currentThread is not initialized */
+ if (runverbose)
+ log_text("java_lang_VMThread_currentThread 222");
+
+ if (!load_class_bootstrap(utf_new_char("java/lang/ThreadGroup"),&threadgroupclass))
+ return NULL;
- t->group = (java_lang_ThreadGroup *)
- native_new_and_init(class_new(utf_new_char("java/lang/ThreadGroup")));
+ t->group = (java_lang_ThreadGroup *) native_new_and_init(threadgroupclass);
+ if (runverbose)
+ log_text("java_lang_VMThread_currentThread 333");
if (t->group == 0)
log_text("unable to create ThreadGroup");
+ if (runverbose)
+ log_text("java_lang_VMThread_currentThread 444");
}
+ if (runverbose)
+ log_text("java_lang_VMThread_currentThread 555");
- return (java_lang_Thread *) t;
+ return t;
#else
return 0;
#endif
/*
- * Class: java/lang/Thread
- * Method: nativeInterrupt
+ * Class: java/lang/VMThread
+ * Method: interrupt
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
{
- log_text("Java_java_lang_VMThread_interrupt0 called");
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ interruptThread(this);
+#else
+ log_text("Java_java_lang_VMThread_interrupt called");
+#endif
}
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: isAlive
* Signature: ()Z
*/
log_text("java_lang_VMThread_isAlive called");
#if defined(USE_THREADS)
+#if !defined(NATIVE_THREADS)
return aliveThread((thread *) this->thread);
+#else
+ /* This method is implemented in classpath. */
+ throw_cacao_exception_exit(string_java_lang_InternalError, "aliveThread");
+#endif
#endif
+
+ /* keep compiler happy */
+
+ return 0;
}
/*
- * Class: java_lang_Thread
+ * Class: java/lang/VMThread
* Method: isInterrupted
* Signature: ()Z
*/
JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ return isInterruptedThread(this);
+#else
log_text("Java_java_lang_VMThread_isInterrupted called");
return 0;
+#endif
}
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: registerNatives
* Signature: ()V
*/
/*
- * Class: java/lang/Thread
- * Method: resume0
+ * Class: java/lang/VMThread
+ * Method: resume
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
/*
- * Class: java/lang/Thread
- * Method: setPriority0
+ * Class: java/lang/VMThread
+ * Method: nativeSetPriority
* Signature: (I)V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 par1)
{
if (runverbose)
- log_text("java_lang_VMThread_setPriority0 called");
+ log_text("java_lang_VMThread_nativeSetPriority called");
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
+#if defined(USE_THREADS)
setPriorityThread((thread *) this->thread, par1);
#endif
}
/*
- * Class: java_lang_Thread
+ * Class: java/lang/VMThread
* Method: sleep
* Signature: (JI)V
*/
-JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 par2)
+JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 nanos)
{
- if (runverbose)
- log_text("java_lang_VMThread_sleep called");
-
#if defined(USE_THREADS)
- sleepThread(millis);
+ sleepThread(millis, nanos);
#endif
}
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: start
* Signature: ()V
*/
log_text("java_lang_VMThread_start called");
#if defined(USE_THREADS)
-#warning perhaps it would be better to always work with the vmthread structure in the thread code (jowenn)
- if (this->thread->vmThread==0)
- this->thread->vmThread=this;
- startThread((thread*)(this->thread));
+ this->thread->vmThread = this;
+ startThread((thread *) this->thread);
#endif
}
/*
- * Class: java/lang/Thread
- * Method: stop0
+ * Class: java/lang/VMThread
+ * Method: nativeStop
* Signature: (Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *par1)
{
if (runverbose)
- log_text ("java_lang_VMThread_stop0 called");
+ log_text ("java_lang_VMThread_nativeStop called");
#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
/*
- * Class: java/lang/Thread
- * Method: suspend0
+ * Class: java/lang/VMThread
+ * Method: suspend
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
{
if (runverbose)
- log_text("java_lang_VMThread_suspend0 called");
+ log_text("java_lang_VMThread_suspend called");
#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
suspendThread((thread*)this->thread);
/*
- * Class: java/lang/Thread
+ * Class: java/lang/VMThread
* Method: yield
* Signature: ()V
*/
/*
- * Class: java_lang_Thread
+ * Class: java/lang/VMThread
* Method: interrupted
* Signature: ()Z
*/
JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ return interruptedThread();
+#else
log_text("Java_java_lang_VMThread_interrupted");
-
return 0;
+#endif
}
/*
- * Class: java_lang_Thread
+ * Class: java/lang/VMThread
* Method: nativeInit
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeInit(JNIEnv *env, java_lang_VMThread *this, s8 par1)
{
-/*
- if (*exceptionptr)
- log_text("There has been an exception, strange...");*/
-
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- initThread(this->thread);
+ initThread(this);
#endif
- this->thread->priority = 5;
}
/*
- * Class: java_lang_Thread
+ * Class: java/lang/VMThread
* Method: holdsLock
* Signature: (Ljava/lang/Object;)Z
*/
-JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object *par1)
+JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ return threadHoldsLock((threadobject*) THREADOBJECT,
+ (java_objectheader *) o);
+#else
+ /* I don't know how to find out [stefan] */
return 0;
+#endif
}