* Removed all Id tags.
[cacao.git] / src / native / vm / java_lang_Thread.c
index b352b28b5590ead8c4fc0160c583c101bf39aadf..a823022f355be84757dc174346be60bc92b9dc0c 100644 (file)
@@ -22,8 +22,6 @@
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
-
 */
 
 
@@ -31,6 +29,7 @@
 #include "vm/types.h"
 
 #include "native/jni.h"
+#include "native/llni.h"
 #include "native/native.h"
 
 #include "native/include/java_lang_String.h"
 
 #if defined(ENABLE_JAVASE)
 # include "native/include/java_lang_ThreadGroup.h"
-# include "native/include/java_lang_VMThread.h"
+
+# if defined(WITH_CLASSPATH_GNU)
+#  include "native/include/java_lang_VMThread.h"
+# endif
 #endif
 
 #include "threads/lock-common.h"
@@ -105,7 +107,7 @@ void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
        threadobject *thread;
 
 #if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) this->vmThread->vmdata;
+       thread = (threadobject *) LLNI_field_direct(LLNI_field_direct(this, vmThread), vmdata);
 #elif defined(WITH_CLASSPATH_CLDC1_1)
        thread = (threadobject *) this->vm_thread;
 #endif
@@ -123,15 +125,39 @@ void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
 s4 _Jv_java_lang_Thread_isAlive(java_lang_Thread *this)
 {
 #if defined(ENABLE_THREADS)
-       threadobject *thread;
+       threadobject *t;
 
-#if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) this->vmThread->vmdata;
-#elif defined(WITH_CLASSPATH_CLDC1_1)
-       thread = (threadobject *) this->vm_thread;
-#endif
+# if defined(WITH_CLASSPATH_GNU)
+
+       t = (threadobject *) LLNI_field_direct(LLNI_field_direct(this, vmThread), vmdata);
+
+# elif defined(WITH_CLASSPATH_SUN)
+
+       /* XXX this is just a quick hack */
+
+       for (t = threads_list_first(); t != NULL; t = threads_list_next(t)) {
+               if (t->object == this)
+                       break;
+       }
+
+       /* The threadobject is null when a thread is created in Java. The
+          priority is set later during startup. */
+
+       if (t == NULL)
+               return 0;
+
+# elif defined(WITH_CLASSPATH_CLDC1_1)
+
+       t = (threadobject *) this->vm_thread;
+
+       if (t == NULL)
+               return 0;
+
+# else
+#  error unknown classpath configuration
+# endif
 
-       return threads_thread_is_alive(thread);
+       return threads_thread_is_alive(t);
 #else
        /* if threads are disabled, the only thread running is alive */
 
@@ -148,15 +174,24 @@ s4 _Jv_java_lang_Thread_isAlive(java_lang_Thread *this)
 s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
 {
 #if defined(ENABLE_THREADS)
-       threadobject *thread;
+       threadobject *t;
 
-#if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) this->vmThread->vmdata;
-#elif defined(WITH_CLASSPATH_CLDC1_1)
-       thread = (threadobject *) this->vm_thread;
-#endif
+# if defined(WITH_CLASSPATH_GNU)
+       t = (threadobject *) LLNI_field_direct(LLNI_field_direct(this, vmThread), vmdata);
+# elif defined(WITH_CLASSPATH_SUN)
+       /* XXX this is just a quick hack */
 
-       return threads_thread_has_been_interrupted(thread);
+       for (t = threads_list_first(); t != NULL; t = threads_list_next(t)) {
+               if (t->object == this)
+                       break;
+       }
+# elif defined(WITH_CLASSPATH_CLDC1_1)
+       t = (threadobject *) this->vm_thread;
+# else
+#  error unknown classpath configuration
+# endif
+
+       return threads_thread_has_been_interrupted(t);
 #else
        return 0;
 #endif
@@ -195,21 +230,36 @@ void _Jv_java_lang_Thread_resume(java_lang_Thread *this)
 void _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority)
 {
 #if defined(ENABLE_THREADS)
-       threadobject *thread;
+       threadobject *t;
 
-#if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) this->vmThread->vmdata;
-#elif defined(WITH_CLASSPATH_CLDC1_1)
-       thread = (threadobject *) this->vm_thread;
+# if defined(WITH_CLASSPATH_GNU)
+       t = (threadobject *) LLNI_field_direct(LLNI_field_direct(this, vmThread), vmdata);
+# elif defined(WITH_CLASSPATH_SUN)
+       /* XXX this is just a quick hack */
+
+       for (t = threads_list_first(); t != NULL; t = threads_list_next(t)) {
+               if (t->object == this)
+                       break;
+       }
 
        /* The threadobject is null when a thread is created in Java. The
           priority is set later during startup. */
 
-       if (thread == NULL)
+       if (t == NULL)
                return;
-#endif
+# elif defined(WITH_CLASSPATH_CLDC1_1)
+       t = (threadobject *) this->vm_thread;
+
+       /* The threadobject is null when a thread is created in Java. The
+          priority is set later during startup. */
+
+       if (t == NULL)
+               return;
+# else
+#  error unknown classpath configuration
+# endif
 
-       threads_set_thread_priority(thread->tid, priority);
+       threads_set_thread_priority(t->tid, priority);
 #endif
 }
 
@@ -247,13 +297,13 @@ java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
                log_text("t ptr is NULL\n");
 
 # if defined(ENABLE_JAVASE)
-       if (t->group == NULL) {
+       if (LLNI_field_direct(t, group) == NULL) {
                /* ThreadGroup of currentThread is not initialized */
 
-               t->group = (java_lang_ThreadGroup *)
+               LLNI_field_direct(t, group) = (java_lang_ThreadGroup *)
                        native_new_and_init(class_java_lang_ThreadGroup);
 
-               if (t->group == NULL)
+               if (LLNI_field_direct(t, group) == NULL)
                        log_text("unable to create ThreadGroup");
        }
 # endif
@@ -304,9 +354,9 @@ s4 _Jv_java_lang_Thread_interrupted(void)
 s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
 {
 #if defined(ENABLE_THREADS)
-       java_objectheader *o;
+       java_handle_t *o;
 
-       o = (java_objectheader *) obj;
+       o = (java_handle_t *) obj;
 
        if (o == NULL) {
                exceptions_throw_nullpointerexception();
@@ -328,12 +378,12 @@ s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
 java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
 {
 #if defined(ENABLE_THREADS)
-       threadobject      *thread;
-       utf               *u;
-       java_objectheader *o;
+       threadobject  *thread;
+       utf           *u;
+       java_handle_t *o;
 
 # if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) this->vmThread->vmdata;
+       thread = (threadobject *) LLNI_field_direct(LLNI_field_direct(this, vmThread), vmdata);
 # elif defined(WITH_CLASSPATH_CLDC1_1)
        thread = (threadobject *) this->vm_thread;
 # endif