* src/native/vm/java_lang_Thread.c: Removed.
authorChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 5 Mar 2008 16:01:01 +0000 (17:01 +0100)
committerChristian Thalinger <twisti@complang.tuwien.ac.at>
Wed, 5 Mar 2008 16:01:01 +0000 (17:01 +0100)
* src/native/vm/java_lang_Thread.h: Likewise.

* src/native/vm/Makefile.am (libnativevm_la_SOURCES): Removed
java_lang_Thread.[ch].

* src/threads/threads-common.c (threads_get_current_object): New
function.
* src/threads/threads-common.h: Likewise.

* src/native/vm/cldc1.1/java_lang_Thread.c,
src/native/vm/gnu/java_lang_VMThread.c,
src/native/vm/sun/jvm.c: Implemented thread functions directly.

src/native/vm/Makefile.am
src/native/vm/cldc1.1/java_lang_Thread.c
src/native/vm/gnu/java_lang_VMThread.c
src/native/vm/java_lang_Thread.c [deleted file]
src/native/vm/java_lang_Thread.h [deleted file]
src/native/vm/sun/jvm.c
src/threads/threads-common.c
src/threads/threads-common.h

index b90a188aa00d8dd8ba80db1ab77f2e4308d7c2cd..b70b105772a1d8bc88825281f0751fd9932d4471 100644 (file)
@@ -81,8 +81,6 @@ libnativevm_la_SOURCES = \
        \
        java_lang_Class.c \
        java_lang_Class.h \
-       java_lang_Thread.c \
-       java_lang_Thread.h \
        $(JAVA_LANG_REFLECT_CONSTRUCTOR_SOURCES) \
        $(JAVA_LANG_REFLECT_METHOD_SOURCES) \
        $(SUN_MISC_UNSAFE_SOURCES)
index ec3ed489738da669a50ca9c80da6f09455fe5bb5..f61c1c1945b419ef3ff4af4997ee3776fad5c9b4 100644 (file)
@@ -1,9 +1,7 @@
 /* src/native/vm/cldc1.1/java_lang_Thread.c
 
-   Copyright (C) 2006, 2007 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
+   Copyright (C) 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
@@ -36,8 +34,6 @@
 
 #include "native/include/java_lang_Thread.h"
 
-#include "native/vm/java_lang_Thread.h"
-
 #include "threads/threads-common.h"
 
 #include "toolbox/logging.h"
@@ -86,7 +82,11 @@ void _Jv_java_lang_Thread_init(void)
  */
 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
 {
-       return _Jv_java_lang_Thread_currentThread();
+       java_lang_Thread *thread;
+
+       thread = (java_lang_Thread *) threads_get_current_object();
+
+       return thread;
 }
 
 
@@ -97,7 +97,19 @@ JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang_Thread *this, s4 oldPriority, s4 newPriority)
 {
-       _Jv_java_lang_Thread_setPriority(this, newPriority);
+#if defined(ENABLE_THREADS)
+       threadobject *t;
+
+       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;
+
+       threads_set_thread_priority(t->tid, newPriority);
+#endif
 }
 
 
@@ -108,7 +120,9 @@ JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, java_lang
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis)
 {
-       _Jv_java_lang_Thread_sleep(millis);
+#if defined(ENABLE_THREADS)
+       threads_sleep(millis, 0);
+#endif
 }
 
 
@@ -119,7 +133,9 @@ JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8
  */
 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, java_lang_Thread *this)
 {
-       _Jv_java_lang_Thread_start(this, 0);
+#if defined(ENABLE_THREADS)
+       threads_thread_start((java_handle_t *) this);
+#endif
 }
 
 
index 49aa253ae6bb8e51fe6400887ae29cfaea2aef68..230c18ddb2e7bf458189d52df5781b49d3641bf8 100644 (file)
@@ -1,9 +1,7 @@
 /* src/native/vm/gnu/java_lang_VMThread.c
 
-   Copyright (C) 1996-2005, 2006, 2007 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
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 #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_String.h"
 #include "native/include/java_lang_Thread.h"
 
-#include "native/include/java_lang_VMThread.h"
-
-#include "native/vm/java_lang_Thread.h"
-
+#include "threads/lock-common.h"
 #include "threads/threads-common.h"
 
+#include "vm/exceptions.h"
+#include "vm/stringlocal.h"
+
 #include "vmcore/utf8.h"
 
 
@@ -94,7 +93,9 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env,
 
        LLNI_field_get_ref(this, thread, thread);
 
-       return _Jv_java_lang_Thread_countStackFrames(thread);
+    log_println("Java_java_lang_VMThread_countStackFrames: IMPLEMENT ME!");
+
+    return 0;
 }
 
 
@@ -109,7 +110,9 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMTh
 
        LLNI_field_get_ref(this, thread, thread);
 
-       _Jv_java_lang_Thread_start(thread, stacksize);
+#if defined(ENABLE_THREADS)
+       threads_thread_start((java_handle_t *) thread);
+#endif
 }
 
 
@@ -142,11 +145,18 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_
  */
 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
 {
+#if defined(ENABLE_THREADS)
        java_lang_Thread *thread;
+       threadobject     *t;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       return _Jv_java_lang_Thread_isInterrupted(thread);
+       t = (threadobject *) LLNI_field_direct(thread, vmThread)->vmdata;
+
+       return threads_thread_has_been_interrupted(t);
+#else
+       return 0;
+#endif
 }
 
 
@@ -157,11 +167,13 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, jav
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
 {
+#if defined(ENABLE_THREADS)
        java_lang_Thread *thread;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       _Jv_java_lang_Thread_suspend(thread);
+       /* TODO Should we implement this or is it obsolete? */
+#endif
 }
 
 
@@ -172,11 +184,13 @@ 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)
        java_lang_Thread *thread;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       _Jv_java_lang_Thread_resume(thread);
+       /* TODO Should we implement this or is it obsolete? */
+#endif
 }
 
 
@@ -187,11 +201,16 @@ 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, int32_t priority)
 {
+#if defined(ENABLE_THREADS)
        java_lang_Thread *thread;
+       threadobject     *t;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       _Jv_java_lang_Thread_setPriority(thread, priority);
+       t = (threadobject *) LLNI_field_direct(thread, vmThread)->vmdata;
+
+       threads_set_thread_priority(t->tid, priority);
+#endif
 }
 
 
@@ -202,11 +221,13 @@ 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)
        java_lang_Thread *thread;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       _Jv_java_lang_Thread_stop(thread, t);
+       /* TODO Should we implement this or is it obsolete? */
+#endif
 }
 
 
@@ -217,7 +238,11 @@ 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)
 {
-       return _Jv_java_lang_Thread_currentThread();
+       java_lang_Thread *thread;
+
+       thread = (java_lang_Thread *) threads_get_current_object();
+
+       return thread;
 }
 
 
@@ -228,7 +253,9 @@ JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv
  */
 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
 {
-       _Jv_java_lang_Thread_yield();
+#if defined(ENABLE_THREADS)
+       threads_yield();
+#endif
 }
 
 
@@ -239,7 +266,11 @@ JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
  */
 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
 {
-       return _Jv_java_lang_Thread_interrupted();
+#if defined(ENABLE_THREADS)
+       return threads_check_if_interrupted_and_reset();
+#else
+       return 0;
+#endif
 }
 
 
@@ -250,7 +281,20 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclas
  */
 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
 {
-       return _Jv_java_lang_Thread_holdsLock(o);
+#if defined(ENABLE_THREADS)
+       java_handle_t *h;
+
+       h = (java_handle_t *) o;
+
+       if (h == NULL) {
+               exceptions_throw_nullpointerexception();
+               return 0;
+       }
+
+       return lock_is_held_by_current_thread(h);
+#else
+       return 0;
+#endif
 }
 
 
@@ -261,11 +305,23 @@ JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass
  */
 JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *this)
 {
+#if defined(ENABLE_THREADS)
        java_lang_Thread *thread;
+       threadobject     *t;
+       utf              *u;
+       java_handle_t    *o;
 
        LLNI_field_get_ref(this, thread, thread);
 
-       return _Jv_java_lang_Thread_getState(thread);
+       t = (threadobject *) LLNI_field_direct(thread, vmThread)->vmdata;
+
+       u = threads_thread_get_state(t);
+       o = javastring_new(u);
+
+       return (java_lang_String *) o;
+#else
+       return NULL;
+#endif
 }
 
 
diff --git a/src/native/vm/java_lang_Thread.c b/src/native/vm/java_lang_Thread.c
deleted file mode 100644 (file)
index b6a6c7c..0000000
+++ /dev/null
@@ -1,349 +0,0 @@
-/* src/native/vm/java_lang_Thread.c - java/lang/Thread functions
-
-   Copyright (C) 1996-2005, 2006, 2007 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.
-
-*/
-
-
-#include "config.h"
-#include "vm/types.h"
-
-#include "native/jni.h"
-#include "native/llni.h"
-#include "native/native.h"
-
-#include "native/include/java_lang_String.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_JAVASE)
-# include "native/include/java_lang_ThreadGroup.h"
-
-# if defined(WITH_CLASSPATH_GNU)
-#  include "native/include/java_lang_VMThread.h"
-# endif
-#endif
-
-#include "threads/lock-common.h"
-#include "threads/threads-common.h"
-
-#include "toolbox/logging.h"
-
-#include "vm/builtin.h"
-#include "vm/exceptions.h"
-#include "vm/stringlocal.h"
-
-#include "vmcore/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:    sleep
- * Signature: (J)V
- */
-void _Jv_java_lang_Thread_sleep(s8 millis)
-{
-#if defined(ENABLE_THREADS)
-       threads_sleep(millis, 0);
-#endif
-}
-
-
-/*
- * 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)
-       threads_thread_start((java_handle_t *) this);
-#endif
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    isInterrupted
- * Signature: ()Z
- */
-s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
-{
-#if defined(ENABLE_THREADS)
-       threadobject *t;
-
-# if defined(WITH_CLASSPATH_GNU)
-       t = (threadobject *) 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;
-       }
-# 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
-}
-
-
-/*
- * 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 *t;
-
-# if defined(WITH_CLASSPATH_GNU)
-       t = (threadobject *) 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;
-# 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(t->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)
-{
-#if defined(ENABLE_THREADS)
-       threadobject          *thread;
-#endif
-       java_lang_Thread      *t;
-#if defined(ENABLE_JAVASE)
-       java_lang_ThreadGroup *group;
-#endif
-
-#if defined(ENABLE_THREADS)
-       thread = THREADOBJECT;
-
-       t = (java_lang_Thread *) threads_thread_get_object(thread);
-
-       if (t == NULL)
-               log_text("t ptr is NULL\n");
-
-# if defined(ENABLE_JAVASE)
-       LLNI_field_get_ref(t, group, group);
-
-       if (group == NULL) {
-               /* ThreadGroup of currentThread is not initialized */
-
-               group = (java_lang_ThreadGroup *)
-                       native_new_and_init(class_java_lang_ThreadGroup);
-
-               if (group == NULL)
-                       log_text("unable to create ThreadGroup");
-
-               LLNI_field_set_ref(t, group, group);
-       }
-# endif
-#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();
-#else
-       return 0;
-#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_handle_t *o;
-
-       o = (java_handle_t *) obj;
-
-       if (o == NULL) {
-               exceptions_throw_nullpointerexception();
-               return 0;
-       }
-
-       return lock_is_held_by_current_thread(o);
-#else
-       return 0;
-#endif
-}
-
-
-/*
- * Class:     java/lang/Thread
- * Method:    getState
- * Signature: ()Ljava/lang/String;
- */
-java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
-{
-#if defined(ENABLE_THREADS)
-       threadobject  *thread;
-       utf           *u;
-       java_handle_t *o;
-
-# if defined(WITH_CLASSPATH_GNU)
-       thread = (threadobject *) LLNI_field_direct(this, vmThread)->vmdata;
-# elif defined(WITH_CLASSPATH_CLDC1_1)
-       thread = (threadobject *) this->vm_thread;
-# endif
-
-       u = threads_thread_get_state(thread);
-       o = javastring_new(u);
-
-       return (java_lang_String *) o;
-#else
-       return NULL;
-#endif
-}
-
-
-/*
- * 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
deleted file mode 100644 (file)
index e29e8b6..0000000
+++ /dev/null
@@ -1,79 +0,0 @@
-/* src/native/vm/java_lang_Thread.h - java/lang/Thread functions
-
-   Copyright (C) 2006, 2007 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.
-
-*/
-
-
-#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_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_JAVASE)
-# include "native/include/java_lang_ThreadGroup.h"
-#endif
-
-#if defined(WITH_CLASSPATH_GNU)
-# include "native/include/java_lang_VMThread.h"
-#endif
-
-
-/* function prototypes ********************************************************/
-
-s4                _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this);
-void              _Jv_java_lang_Thread_sleep(s8 millis);
-void              _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize);
-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 a1f3b1d2e2989f595fad5c35b557233155458cb3..19bd2594a23b41a307b0902c99b4f1609eae7055 100644 (file)
@@ -63,7 +63,6 @@
 #endif
 
 #include "native/vm/java_lang_Class.h"
-#include "native/vm/java_lang_Thread.h"
 #include "native/vm/java_lang_reflect_Constructor.h"
 #include "native/vm/java_lang_reflect_Method.h"
 #include "native/vm/reflect.h"
@@ -2345,9 +2344,13 @@ void JVM_Sleep(JNIEnv* env, jclass threadClass, jlong millis)
 
 jobject JVM_CurrentThread(JNIEnv* env, jclass threadClass)
 {
+       java_object_t *o;
+
        TRACEJVMCALLSVERBOSE(("JVM_CurrentThread(env=%p, threadClass=%p)", env, threadClass));
 
-       return (jobject) _Jv_java_lang_Thread_currentThread();
+       o = threads_get_current_object();
+
+       return (jobject) o;
 }
 
 
index 8b00e663b94a4b6f6347fe3c800ee9e93758d45a..b8bc7046b866670c33fcb05fe69bb4eb40b39cce 100644 (file)
@@ -533,6 +533,62 @@ ptrint threads_get_current_tid(void)
 }
 
 
+/* threads_get_current_object **************************************************
+
+   Return the Java object of the current thread.
+   
+   RETURN VALUE:
+       the Java object
+
+*******************************************************************************/
+
+#include "native/include/java_lang_ThreadGroup.h"
+
+java_object_t *threads_get_current_object(void)
+{
+#if defined(ENABLE_THREADS)
+       threadobject  *t;
+# if defined(ENABLE_JAVASE)
+       java_lang_ThreadGroup *group;
+# endif
+#endif
+       java_lang_Thread *o;
+
+#if defined(ENABLE_THREADS)
+       t = THREADOBJECT;
+       o = threads_thread_get_object(t);
+
+# if defined(ENABLE_JAVASE)
+       /* TODO Do we really need this code?  Or should we check, when we
+          create the threads, that all of them have a group? */
+       /* TWISTI No, we don't need this code!  We need to allocate a
+          ThreadGroup before we initialize the main thread. */
+
+       LLNI_field_get_ref(o, group, group);
+
+       if (group == NULL) {
+               /* ThreadGroup of currentThread is not initialized */
+
+               group = (java_lang_ThreadGroup *)
+                       native_new_and_init(class_java_lang_ThreadGroup);
+
+               if (group == NULL)
+                       vm_abort("unable to create ThreadGroup");
+
+               LLNI_field_set_ref(o, group, group);
+       }
+# endif
+#else
+       /* We just return a fake java.lang.Thread object, otherwise we get
+          NullPointerException's in GNU Classpath. */
+
+       o = builtin_new(class_java_lang_Thread);
+#endif
+
+       return o;
+}
+
+
 /* threads_thread_state_runnable ***********************************************
 
    Set the current state of the given thread to THREAD_STATE_RUNNABLE.
index 4d0ce24e8a30b0835e2bee68ea12c72b022d8bb0..97ab88e1a33a5b29c291ef47266a7ec8a6051da1 100644 (file)
@@ -124,6 +124,7 @@ void          threads_thread_start(java_handle_t *object);
 void          threads_thread_print_info(threadobject *t);
 
 ptrint        threads_get_current_tid(void);
+java_object_t *threads_get_current_object(void);
 
 void          threads_thread_state_runnable(threadobject *t);
 void          threads_thread_state_waiting(threadobject *t);