* src/threads/native/threads.c: Rewritten such that threadobject
authortwisti <none@none>
Tue, 26 Dec 2006 19:56:58 +0000 (19:56 +0000)
committertwisti <none@none>
Tue, 26 Dec 2006 19:56:58 +0000 (19:56 +0000)
extends a java.lang.Thread object instead of java.lang.VMThread.
* src/threads/native/threads.h: Likewise.

* src/vm/finalizer.c (finalizer_vmthread): Renamed to thread_finalizer
and changed type to threadobject*.
(lock_finalizer_thread): Renamed to lock_thread_finalizer.
(finalizer_init): Changed variable names.
(finalizer_start_thread): Thread-code changes.

* src/vm/jit/optimizing/recompile.c (recompile_vmthread): Renamed to
thread_recompile and changed type to threadobject*.
(lock_recompile_thread): Renamed to lock_thread_recompile.
(recompile_init): Changed variable names.
(recompile_thread): Likewise.
(recompile_queue_method): Likewise.
(recompile_start_thread): Thread-code changes.

* src/vm/utf8.c (utf_addThread): Added.
* src/vm/utf8.h: Likewise.

* src/lib/vm/reference/java/lang/VMThread.java (create): Set vmThread
before calling start.

* src/native/vm/gnu/java_lang_VMThread.c: Call _Jv_java_lang_Thread
functions.

* src/native/vm/Makefile.am (libnativevm_la_SOURCES): Added
java_lang_Thread.[ch].
* src/native/vm/java_lang_Thread.c: New file.
* src/native/vm/java_lang_Thread.h: Likewise.

src/lib/vm/reference/java/lang/VMThread.java
src/native/vm/Makefile.am
src/native/vm/gnu/java_lang_VMThread.c
src/native/vm/java_lang_Thread.c [new file with mode: 0644]
src/native/vm/java_lang_Thread.h [new file with mode: 0644]
src/threads/native/threads.c
src/threads/native/threads.h
src/vm/finalizer.c
src/vm/jit/optimizing/recompile.c
src/vm/utf8.c
src/vm/utf8.h

index 2871beb92adfd0fde4100e15f78b058c93886a89..a511f3cf05691c657a5f6c92d620df11df3e3bae 100644 (file)
@@ -159,8 +159,8 @@ final class VMThread
     static void create(Thread thread, long stacksize)
     {
        VMThread vmThread = new VMThread(thread);
-       vmThread.start(stacksize);
        thread.vmThread = vmThread;
+       vmThread.start(stacksize);
     }
 
     /**
index ed5fdbca0a777b5a54d6142e02b1a9f678d5c143..11d68c701bc797d73d06ca05a728f21e48a6e8b7 100644 (file)
@@ -50,7 +50,9 @@ libnativevm_la_SOURCES = \
        java_lang_Class.c \
        java_lang_Class.h \
        java_lang_Object.c \
-       java_lang_Object.h
+       java_lang_Object.h \
+       java_lang_Thread.c \
+       java_lang_Thread.h
 
 libnativevm_la_LIBADD = \
        $(NATIVEVM_LIB)
index 6edcf394ce2cb117eacabb6986718a8845569244..97a2da00f59209ca385af5f3c8f5532dcde25e1f 100644 (file)
@@ -1,4 +1,4 @@
-/* src/native/vm/VMThread.c - java/lang/VMThread
+/* src/native/vm/gnu/java_lang_VMThread.c - java/lang/VMThread
 
    Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    Contact: cacao@cacaojvm.org
 
    Authors: Roman Obermaiser
-
-   Changes: Joseph Wenninger
+            Joseph Wenninger
             Christian Thalinger
 
-   $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
+   $Id: java_lang_VMThread.c 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
 #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"
+#include "native/vm/java_lang_Thread.h"
 
 #if defined(ENABLE_THREADS)
 # include "threads/native/threads.h"
 #endif
 
-#include "toolbox/logging.h"
-#include "vm/exceptions.h"
-#include "vm/options.h"
-
 
 /*
  * Class:     java/lang/VMThread
@@ -61,9 +57,7 @@
  */
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
 {
-    log_text("java_lang_VMThread_countStackFrames called");
-
-    return 0;
+    return _Jv_java_lang_Thread_countStackFrames(this->thread);
 }
 
 
@@ -74,13 +68,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 stacksize)
 {
-#if defined(ENABLE_THREADS)
-       this->thread->vmThread = this;
-
-       /* don't pass a function pointer (NULL) since we want Thread.run()V here */
-
-       threads_start_thread((java_lang_Thread *) this->thread, NULL);
-#endif
+       _Jv_java_lang_Thread_start(this->thread, stacksize);
 }
 
 
@@ -91,9 +79,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
 {
-#if defined(ENABLE_THREADS)
-       threads_thread_interrupt(this);
-#endif
+       _Jv_java_lang_Thread_interrupt(this->thread);
 }
 
 
@@ -104,9 +90,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_
  */
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
 {
-#if defined(ENABLE_THREADS)
-       return threads_thread_has_been_interrupted(this);
-#endif
+       return _Jv_java_lang_Thread_isInterrupted(this->thread);
 }
 
 
@@ -117,8 +101,7 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lan
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
 {
-#if defined(ENABLE_THREADS)
-#endif
+       _Jv_java_lang_Thread_suspend(this->thread);
 }
 
 
@@ -129,8 +112,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VM
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
 {
-#if defined(ENABLE_THREADS)
-#endif
+       _Jv_java_lang_Thread_resume(this->thread);
 }
 
 
@@ -141,10 +123,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMT
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
 {
-#if defined(ENABLE_THREADS)
-       threads_java_lang_Thread_set_priority((java_lang_Thread *) this->thread,
-                                                                                 priority);
-#endif
+       _Jv_java_lang_Thread_setPriority(this->thread, priority);
 }
 
 
@@ -155,8 +134,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, ja
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
 {
-#if defined(ENABLE_THREADS)
-#endif
+       _Jv_java_lang_Thread_stop(this->thread, t);
 }
 
 
@@ -167,31 +145,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang
  */
 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
 {
-       java_lang_Thread *t;
-
-#if defined(ENABLE_THREADS)
-       t = ((threadobject*) THREADOBJECT)->o.thread;
-
-       if (t == NULL)
-               log_text("t ptr is NULL\n");
-  
-       if (!t->group) {
-               /* ThreadGroup of currentThread is not initialized */
-
-               t->group = (java_lang_ThreadGroup *)
-                       native_new_and_init(class_java_lang_ThreadGroup);
-
-               if (t->group == NULL)
-                       log_text("unable to create ThreadGroup");
-       }
-#else
-       /* we just return a fake java.lang.Thread object, otherwise we get
-       NullPointerException's in GNU classpath */
-
-       t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
-#endif
-
-       return t;
+       return _Jv_java_lang_Thread_currentThread();
 }
 
 
@@ -202,9 +156,7 @@ JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
 {
-#if defined(ENABLE_THREADS)
-       threads_yield();
-#endif
+       _Jv_java_lang_Thread_yield();
 }
 
 
@@ -215,9 +167,7 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
  */
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
 {
-#if defined(ENABLE_THREADS)
-       return threads_check_if_interrupted_and_reset();
-#endif
+       return _Jv_java_lang_Thread_interrupted();
 }
 
 
@@ -228,9 +178,18 @@ JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass cla
  */
 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
 {
-#if defined(ENABLE_THREADS)
-       return lock_is_held_by_current_thread((java_objectheader *) o);
-#endif
+       return _Jv_java_lang_Thread_holdsLock(o);
+}
+
+
+/*
+ * Class:     java/lang/VMThread
+ * Method:    getState
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *this)
+{
+       return _Jv_java_lang_Thread_getState(this->thread);
 }
 
 
diff --git a/src/native/vm/java_lang_Thread.c b/src/native/vm/java_lang_Thread.c
new file mode 100644 (file)
index 0000000..0868db0
--- /dev/null
@@ -0,0 +1,283 @@
+/* src/native/vm/java_lang_Thread.c - java/lang/Thread functions
+
+   Copyright (C) 1996-2005, 2006 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.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Contact: cacao@cacaojvm.org
+
+   Authors: Roman Obermaiser
+            Joseph Wenninger
+            Christian Thalinger
+
+   $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
+
+*/
+
+
+#include "config.h"
+#include "vm/types.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_Thread.h"
+
+#if defined(ENABLE_THREADS)
+# include "threads/native/threads.h"
+#endif
+
+#include "toolbox/logging.h"
+#include "vm/options.h"
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    countStackFrames
+ * Signature: ()I
+ */
+s4 _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this)
+{
+    log_text("java_lang_Thread_countStackFrames called");
+
+    return 0;
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    start
+ * Signature: (J)V
+ */
+void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *thread;
+
+       thread = (threadobject *) this;
+
+       /* don't pass a function pointer (NULL) since we want Thread.run()V here */
+
+       threads_start_thread(thread, NULL);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    interrupt
+ * Signature: ()V
+ */
+void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *thread;
+
+       thread = (threadobject *) this;
+
+       threads_thread_interrupt(thread);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    isInterrupted
+ * Signature: ()Z
+ */
+s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *thread;
+
+       thread = (threadobject *) this;
+
+       return threads_thread_has_been_interrupted(thread);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    suspend
+ * Signature: ()V
+ */
+void _Jv_java_lang_Thread_suspend(java_lang_Thread *this)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    resume
+ * Signature: ()V
+ */
+void _Jv_java_lang_Thread_resume(java_lang_Thread *this)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    setPriority
+ * Signature: (I)V
+ */
+void _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority)
+{
+#if defined(ENABLE_THREADS)
+       threadobject *thread;
+
+       thread = (threadobject *) this;
+
+       threads_set_thread_priority(thread->tid, priority);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    stop
+ * Signature: (Ljava/lang/Object;)V
+ */
+void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t)
+{
+#if defined(ENABLE_THREADS)
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    currentThread
+ * Signature: ()Ljava/lang/Thread;
+ */
+java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
+{
+       threadobject     *thread;
+       java_lang_Thread *t;
+
+#if defined(ENABLE_THREADS)
+       thread = THREADOBJECT;
+
+       t = (java_lang_Thread *) thread;
+
+       if (t == NULL)
+               log_text("t ptr is NULL\n");
+  
+       if (t->group == NULL) {
+               /* ThreadGroup of currentThread is not initialized */
+
+               t->group = (java_lang_ThreadGroup *)
+                       native_new_and_init(class_java_lang_ThreadGroup);
+
+               if (t->group == NULL)
+                       log_text("unable to create ThreadGroup");
+       }
+#else
+       /* we just return a fake java.lang.Thread object, otherwise we get
+       NullPointerException's in GNU classpath */
+
+       t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+#endif
+
+       return t;
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    yield
+ * Signature: ()V
+ */
+void _Jv_java_lang_Thread_yield(void)
+{
+#if defined(ENABLE_THREADS)
+       threads_yield();
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    interrupted
+ * Signature: ()Z
+ */
+s4 _Jv_java_lang_Thread_interrupted(void)
+{
+#if defined(ENABLE_THREADS)
+       return threads_check_if_interrupted_and_reset();
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    holdsLock
+ * Signature: (Ljava/lang/Object;)Z
+ */
+s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
+{
+#if defined(ENABLE_THREADS)
+       java_objectheader *o;
+
+       o = (java_objectheader *) obj;
+
+       if (o == NULL) {
+               exceptions_throw_nullpointerexception();
+               return;
+       }
+
+       return lock_is_held_by_current_thread(o);
+#endif
+}
+
+
+/*
+ * Class:     java/lang/Thread
+ * Method:    getState
+ * Signature: ()Ljava/lang/String;
+ */
+java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
+{
+       vm_abort("Java_java_lang_Thread_getState: IMPLEMENT ME!");
+
+       return NULL;
+}
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
diff --git a/src/native/vm/java_lang_Thread.h b/src/native/vm/java_lang_Thread.h
new file mode 100644 (file)
index 0000000..95c1dab
--- /dev/null
@@ -0,0 +1,81 @@
+/* src/native/vm/java_lang_Thread.h - java/lang/Thread functions
+
+   Copyright (C) 2006 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.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
+
+   Contact: cacao@cacaojvm.org
+
+   Authors: Christian Thalinger
+
+   $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
+
+*/
+
+
+#ifndef _JV_JAVA_LANG_THREAD_H
+#define _JV_JAVA_LANG_THREAD_H
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "native/jni.h"
+#include "native/include/java_lang_String.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"
+
+#include "threads/native/threads.h"
+
+
+/* function prototypes ********************************************************/
+
+s4                _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this);
+void              _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize);
+void              _Jv_java_lang_Thread_interrupt(java_lang_Thread *this);
+s4                _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this);
+void              _Jv_java_lang_Thread_suspend(java_lang_Thread *this);
+void              _Jv_java_lang_Thread_resume(java_lang_Thread *this);
+void              _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority);
+void              _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t);
+java_lang_Thread *_Jv_java_lang_Thread_currentThread(void);
+void              _Jv_java_lang_Thread_yield(void);
+s4                _Jv_java_lang_Thread_interrupted(void);
+s4                _Jv_java_lang_Thread_holdsLock(java_lang_Object* o);
+java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this);
+
+#endif /* _JV_JAVA_LANG_THREAD_H */
+
+
+/*
+ * These are local overrides for various environment variables in Emacs.
+ * Please do not remove this and leave it at the end of the file, where
+ * Emacs will automagically detect them.
+ * ---------------------------------------------------------------------
+ * Local variables:
+ * mode: c
+ * indent-tabs-mode: t
+ * c-basic-offset: 4
+ * tab-width: 4
+ * End:
+ */
index b494545554ef40b628dbfba16fb2daa418bbcdca..daa171bf8be8f1996597765c516fdefd9b3696e2 100644 (file)
@@ -28,7 +28,7 @@
             Christian Thalinger
             Edwin Steiner
 
-   $Id: threads.c 6171 2006-12-11 11:47:42Z twisti $
+   $Id: threads.c 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
@@ -214,7 +214,6 @@ static void threads_table_dump(FILE *file);
 threadobject *mainthreadobj;
 
 static methodinfo *method_thread_init;
-static methodinfo *method_threadgroup_add;
 
 /* the thread object of the current thread                                    */
 /* This is either a thread-local variable defined with __thread, or           */
@@ -338,27 +337,6 @@ void threads_sem_post(sem_t *sem)
 }
 
 
-/* threads_set_thread_priority *************************************************
-
-   Set the priority of the given thread.
-
-   IN:
-      tid..........thread id
-         priority.....priority to set
-
-******************************************************************************/
-
-static void threads_set_thread_priority(pthread_t tid, int priority)
-{
-       struct sched_param schedp;
-       int policy;
-
-       pthread_getschedparam(tid, &policy, &schedp);
-       schedp.sched_priority = priority;
-       pthread_setschedparam(tid, policy, &schedp);
-}
-
-
 /* compiler_lock ***************************************************************
 
    Enter the compiler lock.
@@ -621,12 +599,40 @@ static void threads_set_current_threadobject(threadobject *thread)
 }
 
 
+/* threads_init_threadobject **************************************************
+
+   Initialize implementation fields of a threadobject.
+
+   IN:
+      thread............the threadobject
+
+******************************************************************************/
+
+static void threads_init_threadobject(threadobject *thread)
+{
+       thread->tid = pthread_self();
+
+       thread->index = 0;
+
+       /* TODO destroy all those things */
+       pthread_mutex_init(&(thread->joinmutex), NULL);
+       pthread_cond_init(&(thread->joincond), NULL);
+
+       pthread_mutex_init(&(thread->waitmutex), NULL);
+       pthread_cond_init(&(thread->waitcond), NULL);
+
+       thread->interrupted = false;
+       thread->signaled = false;
+       thread->sleeping = false;
+}
+
+
 /* threads_get_current_threadobject ********************************************
 
    Return the threadobject of the current thread.
    
    RETURN VALUE:
-       the current threadobject * (an instance of java.lang.VMThread)
+       the current threadobject * (an instance of java.lang.Thread)
 
 *******************************************************************************/
 
@@ -689,9 +695,12 @@ void threads_preinit(void)
 bool threads_init(void)
 {
        java_lang_String      *threadname;
-       java_lang_Thread      *mainthread;
+       java_lang_VMThread    *vmt;
        java_lang_ThreadGroup *threadgroup;
        threadobject          *tempthread;
+       methodinfo            *m;
+       java_objectheader     *o;
+       java_lang_Thread      *t;
 
        tempthread = mainthreadobj;
 
@@ -703,7 +712,7 @@ bool threads_init(void)
           can keep the execution environment there. No Thread object must
           have been created at an earlier time. */
 
-       class_java_lang_VMThread->instancesize = sizeof(threadobject);
+       class_java_lang_Thread->instancesize = sizeof(threadobject);
 
        /* get methods we need in this file */
 
@@ -717,26 +726,16 @@ bool threads_init(void)
        if (method_thread_init == NULL)
                return false;
 
-       method_threadgroup_add =
-               class_resolveclassmethod(class_java_lang_ThreadGroup,
-                                                                utf_new_char("addThread"),
-                                                                utf_new_char("(Ljava/lang/Thread;)V"),
-                                                                class_java_lang_ThreadGroup,
-                                                                true);
-
-       if (method_threadgroup_add == NULL)
-               return false;
+       /* create a java.lang.Thread for the main thread */
 
-       /* create a VMThread */
-
-       mainthreadobj = (threadobject *) builtin_new(class_java_lang_VMThread);
+       mainthreadobj = (threadobject *) builtin_new(class_java_lang_Thread);
 
        if (mainthreadobj == NULL)
                return false;
 
        FREE(tempthread, threadobject);
 
-       threads_init_threadobject(&mainthreadobj->o);
+       threads_init_threadobject(mainthreadobj);
 
        threads_set_current_threadobject(mainthreadobj);
 
@@ -767,33 +766,48 @@ bool threads_init(void)
        threadgroup = (java_lang_ThreadGroup *)
                native_new_and_init(class_java_lang_ThreadGroup);
 
-       if (!threadgroup)
+       if (threadgroup == NULL)
                throw_exception_exit();
 
-       /* create a Thread */
+#if defined(WITH_CLASSPATH_GNU)
+       /* create a java.lang.VMThread for the main thread */
 
-       mainthread = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+       vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
 
-       if (mainthread == NULL)
+       if (vmt == NULL)
                throw_exception_exit();
 
-       mainthreadobj->o.thread = mainthread;
+       /* set the thread */
 
-       /* call Thread.<init>(Ljava/lang/VMThread;Ljava/lang/String;IZ)V */
+       t           = (java_lang_Thread *) mainthreadobj;
+       vmt->thread = t;
 
-       (void) vm_call_method(method_thread_init, (java_objectheader *) mainthread,
-                                                 mainthreadobj, threadname, NORM_PRIORITY, false);
+       /* call java.lang.Thread.<init>(Ljava/lang/VMThread;Ljava/lang/String;IZ)V */
+       o = (java_objectheader *) mainthreadobj;
+
+       (void) vm_call_method(method_thread_init, o, vmt, threadname, NORM_PRIORITY,
+                                                 false);
+#else
+#error IMPLEMENT ME!
+#endif
 
        if (*exceptionptr)
                return false;
 
-       mainthread->group = threadgroup;
+       mainthreadobj->o.group = threadgroup;
+
+       /* add main thread to java.lang.ThreadGroup */
 
-       /* add mainthread to ThreadGroup */
+       m = class_resolveclassmethod(class_java_lang_ThreadGroup,
+                                                                utf_addThread,
+                                                                utf_java_lang_Thread__V,
+                                                                class_java_lang_ThreadGroup,
+                                                                true);
+
+       o = (java_objectheader *) threadgroup;
+       t = (java_lang_Thread *) mainthreadobj;
 
-       (void) vm_call_method(method_threadgroup_add, 
-                                                 (java_objectheader *) threadgroup,
-                                                 mainthread);
+       (void) vm_call_method(m, o, t);
 
        if (*exceptionptr)
                return false;
@@ -937,35 +951,6 @@ static void threads_table_remove(threadobject *thread)
 #endif
 }
 
-/* threads_init_threadobject **************************************************
-
-   Initialize implementation fields of a java.lang.VMThread.
-
-   IN:
-      t............the java.lang.VMThread
-
-******************************************************************************/
-
-void threads_init_threadobject(java_lang_VMThread *t)
-{
-       threadobject *thread = (threadobject*) t;
-
-       thread->tid = pthread_self();
-
-       thread->index = 0;
-
-       /* TODO destroy all those things */
-       pthread_mutex_init(&(thread->joinmutex), NULL);
-       pthread_cond_init(&(thread->joincond), NULL);
-
-       pthread_mutex_init(&(thread->waitmutex), NULL);
-       pthread_cond_init(&(thread->waitcond), NULL);
-
-       thread->interrupted = false;
-       thread->signaled = false;
-       thread->sleeping = false;
-}
-
 
 /* threads_startup_thread ******************************************************
 
@@ -988,12 +973,17 @@ void threads_init_threadobject(java_lang_VMThread *t)
 
 static void *threads_startup_thread(void *t)
 {
-       startupinfo  *startup;
-       threadobject *thread;
-       sem_t        *psem;
-       threadobject *tnext;
-       methodinfo   *method;
-       functionptr   function;
+       startupinfo        *startup;
+       threadobject       *thread;
+#if defined(WITH_CLASSPATH_GNU)
+       java_lang_VMThread *vmt;
+#endif
+       sem_t              *psem;
+       threadobject       *tnext;
+       classinfo          *c;
+       methodinfo         *m;
+       java_objectheader  *o;
+       functionptr         function;
 
 #if defined(ENABLE_INTRP)
        u1 *intrp_thread_stack;
@@ -1054,7 +1044,7 @@ static void *threads_startup_thread(void *t)
 
        /* set our priority */
 
-       threads_set_thread_priority(thread->tid, thread->o.thread->priority);
+       threads_set_thread_priority(thread->tid, thread->o.priority);
 
 #if defined(ENABLE_INTRP)
        /* set interpreter stack */
@@ -1077,13 +1067,19 @@ static void *threads_startup_thread(void *t)
 
                thread->flags |= THREAD_FLAG_JAVA;
 
-               method = class_resolveclassmethod(thread->o.header.vftbl->class,
-                                                                                 utf_run,
-                                                                                 utf_void__void,
-                                                                                 thread->o.header.vftbl->class,
-                                                                                 true);
+#if defined(WITH_CLASSPATH_GNU)
+               /* We need to start the run method of
+                  java.lang.VMThread. Since this is a final class, we can use
+                  the class object directly. */
+
+               c   = class_java_lang_VMThread;
+#elif defined(WITH_CLASSPATH_CLDC1_1)
+               c   = thread->o.header.vftbl->class;
+#endif
 
-               if (method == NULL)
+               m = class_resolveclassmethod(c, utf_run, utf_void__void, c, true);
+
+               if (m == NULL)
                        throw_exception();
 
                /* set ThreadMXBean variables */
@@ -1096,7 +1092,17 @@ static void *threads_startup_thread(void *t)
                        _Jv_jvm->java_lang_management_ThreadMXBean_PeakThreadCount =
                                _Jv_jvm->java_lang_management_ThreadMXBean_ThreadCount;
 
-               (void) vm_call_method(method, (java_objectheader *) thread);
+#if defined(WITH_CLASSPATH_GNU)
+               /* we need to start the run method of java.lang.VMThread */
+
+               vmt = (java_lang_VMThread *) thread->o.vmThread;
+               o   = (java_objectheader *) vmt;
+
+#elif defined(WITH_CLASSPATH_CLDC1_1)
+               o   = (java_objectheader *) thread;
+#endif
+
+               (void) vm_call_method(m, o);
        }
        else {
                /* this is an internal thread */
@@ -1140,21 +1146,18 @@ static void *threads_startup_thread(void *t)
    Start a thread in the JVM.
 
    IN:
-      t............the java.lang.Thread object
+      thread.......the thread object
          function.....function to run in the new thread. NULL means that the
                       "run" method of the object `t` should be called
 
 ******************************************************************************/
 
-void threads_start_thread(java_lang_Thread *t, functionptr function)
+void threads_start_thread(threadobject *thread, functionptr function)
 {
        sem_t          sem;
        sem_t          sem_first;
        pthread_attr_t attr;
        startupinfo    startup;
-       threadobject  *thread;
-
-       thread = (threadobject *) t->vmThread;
 
        /* fill startupinfo structure passed by pthread_create to
         * threads_startup_thread */
@@ -1179,7 +1182,7 @@ void threads_start_thread(java_lang_Thread *t, functionptr function)
 
        /* create the thread */
 
-       if (pthread_create(&thread->tid, &attr, threads_startup_thread, &startup))
+       if (pthread_create(&(thread->tid), &attr, threads_startup_thread, &startup))
                vm_abort("pthread_create failed: %s", strerror(errno));
 
        /* signal that pthread_create has returned, so thread->tid is valid */
@@ -1197,6 +1200,27 @@ void threads_start_thread(java_lang_Thread *t, functionptr function)
 }
 
 
+/* threads_set_thread_priority *************************************************
+
+   Set the priority of the given thread.
+
+   IN:
+      tid..........thread id
+         priority.....priority to set
+
+******************************************************************************/
+
+void threads_set_thread_priority(pthread_t tid, int priority)
+{
+       struct sched_param schedp;
+       int policy;
+
+       pthread_getschedparam(tid, &policy, &schedp);
+       schedp.sched_priority = priority;
+       pthread_setschedparam(tid, policy, &schedp);
+}
+
+
 /* threads_attach_current_thread ***********************************************
 
    Attaches the current thread to the VM.  Used in JNI.
@@ -1206,20 +1230,26 @@ void threads_start_thread(java_lang_Thread *t, functionptr function)
 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
 {
        threadobject          *thread;
-       java_lang_Thread      *t;
+       java_lang_VMThread    *vmt;
        utf                   *u;
        java_lang_String      *s;
        java_lang_ThreadGroup *group;
+       methodinfo            *m;
        java_objectheader     *o;
+       java_lang_Thread      *t;
 
-       /* create a java.lang.VMThread object */
+       /* create a java.lang.Thread object */
 
-       thread = (threadobject *) builtin_new(class_java_lang_VMThread);
+       thread = (threadobject *) builtin_new(class_java_lang_Thread);
 
        if (thread == NULL)
                return false;
 
-       threads_init_threadobject(&thread->o);
+       /* cast for convenience */
+
+       t = (java_lang_Thread *) thread;
+
+       threads_init_threadobject(thread);
        threads_set_current_threadobject(thread);
        lock_init_execution_env(thread);
 
@@ -1249,14 +1279,18 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
        }
 #endif
 
-       /* create a java.lang.Thread object */
+#if defined(WITH_CLASSPATH_GNU)
+       /* create a java.lang.VMThread object */
 
-       t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+       vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
 
-       if (t == NULL)
+       if (vmt == NULL)
                return false;
 
-       thread->o.thread = t;
+       /* set the thread */
+
+       vmt->thread = t;
+#endif
 
        if (vm_aargs != NULL) {
                u     = utf_new_char(vm_aargs->name);
@@ -1264,26 +1298,37 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
        }
        else {
                u     = utf_null;
-               group = mainthreadobj->o.thread->group;
+               group = mainthreadobj->o.group;
        }
 
        s = javastring_new(u);
 
-       o = (java_objectheader *) t;
+       o = (java_objectheader *) thread;
 
-       (void) vm_call_method(method_thread_init, o, thread, s, NORM_PRIORITY,
+#if defined(WITH_CLASSPATH_GNU)
+       (void) vm_call_method(method_thread_init, o, vmt, s, NORM_PRIORITY,
                                                  isdaemon);
+#else
+#endif
 
        if (*exceptionptr)
                return false;
 
        /* store the thread group in the object */
 
-       t->group = group;
+       thread->o.group = group;
+
+       /* add thread to given thread-group */
+
+       m = class_resolveclassmethod(group->header.vftbl->class,
+                                                                utf_addThread,
+                                                                utf_java_lang_Thread__V,
+                                                                class_java_lang_ThreadGroup,
+                                                                true);
 
        o = (java_objectheader *) group;
 
-       (void) vm_call_method(method_threadgroup_add, o, t);
+       (void) vm_call_method(m, o, t);
 
        if (*exceptionptr)
                return false;
@@ -1300,10 +1345,10 @@ bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon)
 
 bool threads_detach_thread(threadobject *thread)
 {
-       java_lang_Thread      *t;
        java_lang_ThreadGroup *group;
        methodinfo            *m;
        java_objectheader     *o;
+       java_lang_Thread      *t;
 
        /* Allow lock record pools to be used by other threads. They
           cannot be deleted so we'd better not waste them. */
@@ -1316,8 +1361,7 @@ bool threads_detach_thread(threadobject *thread)
 
        /* remove thread from the thread group */
 
-       t     = thread->o.thread;
-       group = t->group;
+       group = thread->o.group;
 
        /* XXX TWISTI: should all threads be in a ThreadGroup? */
 
@@ -1332,6 +1376,7 @@ bool threads_detach_thread(threadobject *thread)
                        return false;
 
                o = (java_objectheader *) group;
+               t = (java_lang_Thread *) thread;
 
                (void) vm_call_method(m, o, t);
 
@@ -1353,13 +1398,13 @@ bool threads_detach_thread(threadobject *thread)
 
        /* reset thread id (lock on joinmutex? TWISTI) */
 
-       pthread_mutex_lock(&thread->joinmutex);
+       pthread_mutex_lock(&(thread->joinmutex));
        thread->tid = 0;
-       pthread_mutex_unlock(&thread->joinmutex);
+       pthread_mutex_unlock(&(thread->joinmutex));
 
        /* tell everyone that a thread has finished */
 
-       pthread_cond_broadcast(&thread->joincond);
+       pthread_cond_broadcast(&(thread->joincond));
 
        return true;
 }
@@ -1378,8 +1423,9 @@ bool threads_detach_thread(threadobject *thread)
 static threadobject *threads_find_non_daemon_thread(threadobject *thread)
 {
        while (thread != mainthreadobj) {
-               if (!thread->o.thread->daemon)
+               if (!thread->o.daemon)
                        return thread;
+
                thread = thread->prev;
        }
 
@@ -1400,15 +1446,14 @@ void threads_join_all_threads(void)
        pthread_mutex_lock(&threadlistlock);
 
        while ((thread = threads_find_non_daemon_thread(mainthreadobj->prev)) != NULL) {
-
-               pthread_mutex_lock(&thread->joinmutex);
+               pthread_mutex_lock(&(thread->joinmutex));
 
                pthread_mutex_unlock(&threadlistlock);
 
                while (thread->tid)
-                       pthread_cond_wait(&thread->joincond, &thread->joinmutex);
+                       pthread_cond_wait(&(thread->joincond), &(thread->joinmutex));
 
-               pthread_mutex_unlock(&thread->joinmutex);
+               pthread_mutex_unlock(&(thread->joinmutex));
 
                pthread_mutex_lock(&threadlistlock);
        }
@@ -1489,48 +1534,49 @@ static bool threads_current_time_is_earlier_than(const struct timespec *tv)
 
 *******************************************************************************/
 
-static bool threads_wait_with_timeout(threadobject *t,
+static bool threads_wait_with_timeout(threadobject *thread,
                                                                          struct timespec *wakeupTime)
 {
        bool wasinterrupted;
 
        /* acquire the waitmutex */
 
-       pthread_mutex_lock(&t->waitmutex);
+       pthread_mutex_lock(&thread->waitmutex);
 
        /* mark us as sleeping */
 
-       t->sleeping = true;
+       thread->sleeping = true;
 
        /* wait on waitcond */
 
        if (wakeupTime->tv_sec || wakeupTime->tv_nsec) {
                /* with timeout */
-               while (!t->interrupted && !t->signaled
+               while (!thread->interrupted && !thread->signaled
                           && threads_current_time_is_earlier_than(wakeupTime))
                {
-                       pthread_cond_timedwait(&t->waitcond, &t->waitmutex, wakeupTime);
+                       pthread_cond_timedwait(&thread->waitcond, &thread->waitmutex,
+                                                                  wakeupTime);
                }
        }
        else {
                /* no timeout */
-               while (!t->interrupted && !t->signaled)
-                       pthread_cond_wait(&t->waitcond, &t->waitmutex);
+               while (!thread->interrupted && !thread->signaled)
+                       pthread_cond_wait(&thread->waitcond, &thread->waitmutex);
        }
 
        /* check if we were interrupted */
 
-       wasinterrupted = t->interrupted;
+       wasinterrupted = thread->interrupted;
 
        /* reset all flags */
 
-       t->interrupted = false;
-       t->signaled = false;
-       t->sleeping = false;
+       thread->interrupted = false;
+       thread->signaled    = false;
+       thread->sleeping    = false;
 
        /* release the waitmutex */
 
-       pthread_mutex_unlock(&t->waitmutex);
+       pthread_mutex_unlock(&thread->waitmutex);
 
        return wasinterrupted;
 }
@@ -1552,8 +1598,7 @@ static bool threads_wait_with_timeout(threadobject *t,
 
 *******************************************************************************/
 
-bool threads_wait_with_timeout_relative(threadobject *t,
-                                                                               s8 millis,
+bool threads_wait_with_timeout_relative(threadobject *thread, s8 millis,
                                                                                s4 nanos)
 {
        struct timespec wakeupTime;
@@ -1564,7 +1609,7 @@ bool threads_wait_with_timeout_relative(threadobject *t,
 
        /* wait */
 
-       return threads_wait_with_timeout(t, &wakeupTime);
+       return threads_wait_with_timeout(thread, &wakeupTime);
 }
 
 
@@ -1612,27 +1657,23 @@ static void threads_calc_absolute_time(struct timespec *tm, s8 millis, s4 nanos)
 
 *******************************************************************************/
 
-void threads_thread_interrupt(java_lang_VMThread *thread)
+void threads_thread_interrupt(threadobject *thread)
 {
-       threadobject *t;
-
-       t = (threadobject *) thread;
-
        /* Signal the thread a "waitcond" and tell it that it has been
           interrupted. */
 
-       pthread_mutex_lock(&t->waitmutex);
+       pthread_mutex_lock(&thread->waitmutex);
 
        /* Interrupt blocking system call using a signal. */
 
-       pthread_kill(t->tid, SIGHUP);
+       pthread_kill(thread->tid, SIGHUP);
 
-       if (t->sleeping)
-               pthread_cond_signal(&t->waitcond);
+       if (thread->sleeping)
+               pthread_cond_signal(&thread->waitcond);
 
-       t->interrupted = true;
+       thread->interrupted = true;
 
-       pthread_mutex_unlock(&t->waitmutex);
+       pthread_mutex_unlock(&thread->waitmutex);
 }
 
 
@@ -1648,20 +1689,24 @@ void threads_thread_interrupt(java_lang_VMThread *thread)
 
 bool threads_check_if_interrupted_and_reset(void)
 {
-       threadobject *t;
+       threadobject *thread;
        bool intr;
 
-       t = (threadobject*) THREADOBJECT;
+       thread = THREADOBJECT;
 
-       intr = t->interrupted;
+       /* get interrupted flag */
 
-       t->interrupted = false;
+       intr = thread->interrupted;
+
+       /* reset interrupted flag */
+
+       thread->interrupted = false;
 
        return intr;
 }
 
 
-/* threads_thread_has_been_interrupted *********************************************************
+/* threads_thread_has_been_interrupted *****************************************
 
    Check if the given thread has been interrupted
 
@@ -1673,13 +1718,9 @@ bool threads_check_if_interrupted_and_reset(void)
 
 *******************************************************************************/
 
-bool threads_thread_has_been_interrupted(java_lang_VMThread *thread)
+bool threads_thread_has_been_interrupted(threadobject *thread)
 {
-       threadobject *t;
-
-       t = (threadobject*) thread;
-
-       return t->interrupted;
+       return thread->interrupted;
 }
 
 
@@ -1691,15 +1732,15 @@ bool threads_thread_has_been_interrupted(java_lang_VMThread *thread)
 
 void threads_sleep(s8 millis, s4 nanos)
 {
-       threadobject       *t;
-       struct timespec    wakeupTime;
-       bool               wasinterrupted;
+       threadobject    *thread;
+       struct timespec  wakeupTime;
+       bool             wasinterrupted;
 
-       t = (threadobject *) THREADOBJECT;
+       thread = THREADOBJECT;
 
        threads_calc_absolute_time(&wakeupTime, millis, nanos);
 
-       wasinterrupted = threads_wait_with_timeout(t, &wakeupTime);
+       wasinterrupted = threads_wait_with_timeout(thread, &wakeupTime);
 
        if (wasinterrupted)
                *exceptionptr = new_exception(string_java_lang_InterruptedException);
@@ -1718,26 +1759,6 @@ void threads_yield(void)
 }
 
 
-/* threads_java_lang_Thread_set_priority ***************************************
-
-   Set the priority for the given java.lang.Thread.
-
-   IN:
-      t............the java.lang.Thread
-         priority.....the priority
-
-*******************************************************************************/
-
-void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority)
-{
-       threadobject *thread;
-
-       thread = (threadobject*) t->vmThread;
-
-       threads_set_thread_priority(thread->tid, priority);
-}
-
-
 /* threads_dump ****************************************************************
 
    Dumps info for all threads running in the JVM. This function is
@@ -1747,10 +1768,9 @@ void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority)
 
 void threads_dump(void)
 {
-       threadobject       *thread;
-       java_lang_VMThread *vmt;
-       java_lang_Thread   *t;
-       utf                *name;
+       threadobject     *thread;
+       java_lang_Thread *t;
+       utf              *name;
 
        thread = mainthreadobj;
 
@@ -1761,10 +1781,9 @@ void threads_dump(void)
        /* iterate over all started threads */
 
        do {
-               /* get thread objects */
+               /* get thread object */
 
-               vmt = &thread->o;
-               t   = vmt->thread;
+               t = (java_lang_Thread *) thread;
 
                /* the thread may be currently in initalization, don't print it */
 
index 0a9a3e3b48bc9a9ec97fa27de8337c682f76f5a9..023fc7050f156ef79f8dcd6b7c22be80f58b8b28 100644 (file)
    Contact: cacao@cacaojvm.org
 
    Authors: Stefan Ring
-                       Edwin Steiner
+            Edwin Steiner
+            Christian Thalinger
 
-   Changes: Christian Thalinger
-
-   $Id: threads.h 5870 2006-10-30 12:27:59Z twisti $
+   $Id: threads.h 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
@@ -53,9 +52,7 @@ typedef struct threads_table_t       threads_table_t;
 
 #include "mm/memory.h"
 #include "native/jni.h"
-#include "native/include/java_lang_Object.h" /* required by java/lang/VMThread*/
 #include "native/include/java_lang_Thread.h"
-#include "native/include/java_lang_VMThread.h"
 #include "vm/global.h"
 
 #include "threads/native/lock.h"
@@ -98,7 +95,7 @@ extern __thread threadobject *threads_current_threadobject;
 
 #define THREADSPECIFIC
 #define THREADOBJECT \
-       ((threadobject *)pthread_getspecific(threads_current_threadobject_key))
+       ((threadobject *) pthread_getspecific(threads_current_threadobject_key))
 
 extern pthread_key_t threads_current_threadobject_key;
 
@@ -133,7 +130,7 @@ struct threads_table_t {
 
 /* threadobject ****************************************************************
 
-   Every java.lang.VMThread object is actually an instance of this
+   Every java.lang.Thread object is actually an instance of this
    structure.
 
 *******************************************************************************/
@@ -143,7 +140,7 @@ struct threads_table_t {
 
 
 struct threadobject {
-       java_lang_VMThread    o;            /* the java.lang.VMThread object      */
+       java_lang_Thread      o;            /* the java.lang.Thread object        */
 
        lock_execution_env_t  ee;           /* data for the lock implementation   */
 
@@ -202,9 +199,9 @@ threadobject *threads_get_current_threadobject(void);
 void threads_preinit(void);
 bool threads_init(void);
 
-void threads_init_threadobject(java_lang_VMThread *);
+void threads_start_thread(threadobject *thread, functionptr function);
 
-void threads_start_thread(java_lang_Thread *t, functionptr function);
+void threads_set_thread_priority(pthread_t tid, int priority);
 
 bool threads_attach_current_thread(JavaVMAttachArgs *vm_aargs, bool isdaemon);
 bool threads_detach_thread(threadobject *thread);
@@ -216,11 +213,9 @@ void threads_yield(void);
 
 bool threads_wait_with_timeout_relative(threadobject *t, s8 millis, s4 nanos);
 
-void threads_thread_interrupt(java_lang_VMThread *);
+void threads_thread_interrupt(threadobject *thread);
 bool threads_check_if_interrupted_and_reset(void);
-bool threads_thread_has_been_interrupted(java_lang_VMThread *);
-
-void threads_java_lang_Thread_set_priority(java_lang_Thread *t, s4 priority);
+bool threads_thread_has_been_interrupted(threadobject *thread);
 
 void threads_cast_stopworld(void);
 void threads_cast_startworld(void);
index e0e69d02c0297e5ef6d67f51dc15a2c63ae81f83..175b05cbc8a5b0733808b05b610935fdf205b17f 100644 (file)
@@ -26,9 +26,7 @@
 
    Authors: Christian Thalinger
 
-   Changes:
-
-   $Id: finalizer.c 5123 2006-07-12 21:45:34Z twisti $
+   $Id: finalizer.c 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
@@ -60,8 +58,8 @@
 /* global variables ***********************************************************/
 
 #if defined(ENABLE_THREADS)
-static java_lang_VMThread *finalizer_vmthread;
-static java_objectheader *lock_finalizer_thread;
+static threadobject      *thread_finalizer;
+static java_objectheader *lock_thread_finalizer;
 #endif
 
 
@@ -74,9 +72,9 @@ static java_objectheader *lock_finalizer_thread;
 bool finalizer_init(void)
 {
 #if defined(ENABLE_THREADS)
-       lock_finalizer_thread = NEW(java_objectheader);
+       lock_thread_finalizer = NEW(java_objectheader);
 
-       lock_init_object_lock(lock_finalizer_thread);
+       lock_init_object_lock(lock_thread_finalizer);
 #endif
 
        /* everything's ok */
@@ -99,15 +97,15 @@ static void finalizer_thread(void)
        while (true) {
                /* get the lock on the finalizer lock object, so we can call wait */
 
-               lock_monitor_enter(lock_finalizer_thread);
+               lock_monitor_enter(lock_thread_finalizer);
 
                /* wait forever (0, 0) on that object till we are signaled */
        
-               lock_wait_for_object(lock_finalizer_thread, 0, 0);
+               lock_wait_for_object(lock_thread_finalizer, 0, 0);
 
                /* leave the lock */
 
-               lock_monitor_exit(lock_finalizer_thread);
+               lock_monitor_exit(lock_thread_finalizer);
 
                /* and call the finalizers */
 
@@ -126,28 +124,32 @@ static void finalizer_thread(void)
 #if defined(ENABLE_THREADS)
 bool finalizer_start_thread(void)
 {
-       java_lang_Thread *t;
+#if defined(WITH_CLASSPATH_GNU)
+       java_lang_VMThread *vmt;
+#endif
 
        /* create the finalizer object */
 
-       finalizer_vmthread =
-               (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
+       thread_finalizer = (threadobject *) builtin_new(class_java_lang_Thread);
 
-       if (!finalizer_vmthread)
+       if (thread_finalizer == NULL)
                return false;
 
-       t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+#if defined(WITH_CLASSPATH_GNU)
+       vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
 
-       t->vmThread = finalizer_vmthread;
-       t->name     = javastring_new_from_ascii("Finalizer");
-       t->daemon   = true;
-       t->priority = 5;
+       vmt->thread = (java_lang_Thread *) thread_finalizer;
+
+       thread_finalizer->o.vmThread = vmt;
+#endif
 
-       finalizer_vmthread->thread = t;
+       thread_finalizer->o.name     = javastring_new_from_ascii("Finalizer");
+       thread_finalizer->o.daemon   = true;
+       thread_finalizer->o.priority = 5;
 
        /* actually start the finalizer thread */
 
-       threads_start_thread(t, finalizer_thread);
+       threads_start_thread(thread_finalizer, finalizer_thread);
 
        /* everything's ok */
 
@@ -168,15 +170,15 @@ void finalizer_notify(void)
 #if defined(ENABLE_THREADS)
        /* get the lock on the finalizer lock object, so we can call wait */
 
-       lock_monitor_enter(lock_finalizer_thread);
+       lock_monitor_enter(lock_thread_finalizer);
 
        /* signal the finalizer thread */
        
-       lock_notify_object(lock_finalizer_thread);
+       lock_notify_object(lock_thread_finalizer);
 
        /* leave the lock */
 
-       lock_monitor_exit(lock_finalizer_thread);
+       lock_monitor_exit(lock_thread_finalizer);
 #else
        /* if we don't have threads, just run the finalizers */
 
index 5ada79b8b9cf128cc2fe74458ed030fd96fc5da8..87e04ad13a231865dec06b07ac4bd895ae02e191 100644 (file)
@@ -26,8 +26,6 @@
 
    Authors: Christian Thalinger
 
-   Changes:
-
    $Id: cacao.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
@@ -60,9 +58,9 @@
 
 /* global variables ***********************************************************/
 
-static java_lang_VMThread *recompile_vmthread;
-static java_objectheader *lock_recompile_thread;
-static list *list_recompile_methods;
+static threadobject      *thread_recompile;
+static java_objectheader *lock_thread_recompile;
+static list              *list_recompile_methods;
 
 
 /* recompile_init **************************************************************
@@ -75,9 +73,9 @@ bool recompile_init(void)
 {
        /* initialize the recompile lock object */
 
-       lock_recompile_thread = NEW(java_objectheader);
+       lock_thread_recompile = NEW(java_objectheader);
 
-       lock_init_object_lock(lock_recompile_thread);
+       lock_init_object_lock(lock_thread_recompile);
 
        /* create method list */
 
@@ -172,15 +170,15 @@ static void recompile_thread(void)
        while (true) {
                /* get the lock on the recompile lock object, so we can call wait */
 
-               lock_monitor_enter(lock_recompile_thread);
+               lock_monitor_enter(lock_thread_recompile);
 
                /* wait forever (0, 0) on that object till we are signaled */
        
-               lock_wait_for_object(lock_recompile_thread, 0, 0);
+               lock_wait_for_object(lock_thread_recompile, 0, 0);
 
                /* leave the lock */
 
-               lock_monitor_exit(lock_recompile_thread);
+               lock_monitor_exit(lock_thread_recompile);
 
                /* get the next method and recompile it */
 
@@ -218,28 +216,32 @@ static void recompile_thread(void)
 
 bool recompile_start_thread(void)
 {
-       java_lang_Thread *t;
+#if defined(WITH_CLASSPATH_GNU)
+       java_lang_VMThread *vmt;
+#endif
 
        /* create the profile object */
 
-       recompile_vmthread =
-               (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
+       thread_recompile = (threadobject *) builtin_new(class_java_lang_Thread);
 
-       if (recompile_vmthread == NULL)
+       if (thread_recompile == NULL)
                return false;
 
-       t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
+#if defined(WITH_CLASSPATH_GNU)
+       vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
 
-       t->vmThread = recompile_vmthread;
-       t->name     = javastring_new_from_ascii("Recompiler");
-       t->daemon   = true;
-       t->priority = 5;
+       vmt->thread = (java_lang_Thread *) thread_recompile;
+
+       thread_recompile->o.vmThread = vmt;
+#endif
 
-       recompile_vmthread->thread = t;
+       thread_recompile->o.name     = javastring_new_from_ascii("Recompiler");
+       thread_recompile->o.daemon   = true;
+       thread_recompile->o.priority = 5;
 
        /* actually start the recompilation thread */
 
-       threads_start_thread(t, recompile_thread);
+       threads_start_thread(thread_recompile, recompile_thread);
 
        /* everything's ok */
 
@@ -269,15 +271,15 @@ void recompile_queue_method(methodinfo *m)
 
        /* get the lock on the recompile lock object, so we can call notify */
 
-       lock_monitor_enter(lock_recompile_thread);
+       lock_monitor_enter(lock_thread_recompile);
 
        /* signal the recompiler thread */
        
-       lock_notify_object(lock_recompile_thread);
+       lock_notify_object(lock_thread_recompile);
 
        /* leave the lock */
 
-       lock_monitor_exit(lock_recompile_thread);
+       lock_monitor_exit(lock_thread_recompile);
 }
 
 
index 63a26a8b63cf60fa12334cc035c7c06027a6003c..76837ed3d9308068a8b9530989031eb56d2ef645 100644 (file)
@@ -30,7 +30,7 @@
             Christian Thalinger
             Edwin Steiner
 
-   $Id: utf8.c 6216 2006-12-18 18:21:37Z twisti $
+   $Id: utf8.c 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
@@ -136,6 +136,7 @@ utf *utf_run;                           /* run                                */
 
 utf *utf_add;
 utf *utf_remove;
+utf *utf_addThread;
 utf *utf_removeThread;
 utf *utf_put;
 utf *utf_get;
@@ -289,6 +290,7 @@ bool utf8_init(void)
 
        utf_add                        = utf_new_char("add");
        utf_remove                     = utf_new_char("remove");
+       utf_addThread                  = utf_new_char("addThread");
        utf_removeThread               = utf_new_char("removeThread");
        utf_put                        = utf_new_char("put");
        utf_get                        = utf_new_char("get");
index acc5c14d2b347bfe19ef04da6ecce8dfbb8e9253..c4b11e4c319f7ac0f8014a77c8a517808cd68f1d 100644 (file)
@@ -27,7 +27,7 @@
    Authors: Christian Thalinger
             Edwin Steiner
 
-   $Id: utf8.h 6216 2006-12-18 18:21:37Z twisti $
+   $Id: utf8.h 6228 2006-12-26 19:56:58Z twisti $
 
 */
 
@@ -129,6 +129,7 @@ extern utf *utf_run;
 
 extern utf *utf_add;
 extern utf *utf_remove;
+extern utf *utf_addThread;
 extern utf *utf_removeThread;
 extern utf *utf_put;
 extern utf *utf_get;