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 $
-
*/
#include "vm/types.h"
#include "native/jni.h"
+#include "native/llni.h"
#include "native/native.h"
-#if defined(ENABLE_JAVASE)
-# include "native/include/java_lang_ThreadGroup.h"
-# include "native/include/java_lang_VMThread.h"
-#endif
-
#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_THREADS)
-# include "threads/native/threads.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"
-/* XXX REMOVE ME only for vm_abort */
-#include "vm/vm.h"
-
/*
* Class: java/lang/Thread
void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
{
#if defined(ENABLE_THREADS)
- threads_start_javathread(this);
+ threads_thread_start(this);
#endif
}
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
}
+/*
+ * Class: java/lang/Thread
+ * Method: isAlive
+ * Signature: ()Z
+ */
+s4 _Jv_java_lang_Thread_isAlive(java_lang_Thread *this)
+{
+#if defined(ENABLE_THREADS)
+ threadobject *t;
+
+# 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(t);
+#else
+ /* if threads are disabled, the only thread running is alive */
+
+ return 1;
+#endif
+}
+
+
/*
* Class: java/lang/Thread
* Method: isInterrupted
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
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
}
#if defined(ENABLE_THREADS)
thread = THREADOBJECT;
- t = (java_lang_Thread *) thread->object;
+ t = thread->object;
if (t == NULL)
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
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();
*/
java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
{
- vm_abort("Java_java_lang_Thread_getState: IMPLEMENT ME!");
+#if defined(ENABLE_THREADS)
+ threadobject *thread;
+ utf *u;
+ java_handle_t *o;
+# if defined(WITH_CLASSPATH_GNU)
+ thread = (threadobject *) LLNI_field_direct(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
}