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.
static void create(Thread thread, long stacksize)
{
VMThread vmThread = new VMThread(thread);
- vmThread.start(stacksize);
thread.vmThread = vmThread;
+ vmThread.start(stacksize);
}
/**
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)
-/* 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
*/
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);
}
*/
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);
}
*/
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);
}
*/
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);
}
*/
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);
}
*/
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);
}
*/
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);
}
*/
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);
}
*/
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();
}
*/
JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
{
-#if defined(ENABLE_THREADS)
- threads_yield();
-#endif
+ _Jv_java_lang_Thread_yield();
}
*/
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();
}
*/
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);
}
--- /dev/null
+/* 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:
+ */
--- /dev/null
+/* 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:
+ */
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 $
*/
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 */
}
-/* 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.
}
+/* 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)
*******************************************************************************/
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;
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 */
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);
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;
#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 ******************************************************
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;
/* 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 */
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 */
_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 */
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 */
/* 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 */
}
+/* 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.
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);
}
#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);
}
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;
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. */
/* 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? */
return false;
o = (java_objectheader *) group;
+ t = (java_lang_Thread *) thread;
(void) vm_call_method(m, o, t);
/* 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;
}
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;
}
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);
}
*******************************************************************************/
-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;
}
*******************************************************************************/
-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;
/* wait */
- return threads_wait_with_timeout(t, &wakeupTime);
+ return threads_wait_with_timeout(thread, &wakeupTime);
}
*******************************************************************************/
-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);
}
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
*******************************************************************************/
-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;
}
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);
}
-/* 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
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;
/* 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 */
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 $
*/
#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"
#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;
/* threadobject ****************************************************************
- Every java.lang.VMThread object is actually an instance of this
+ Every java.lang.Thread object is actually an instance of this
structure.
*******************************************************************************/
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 */
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);
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);
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 $
*/
/* 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
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 */
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 */
#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 */
#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 */
Authors: Christian Thalinger
- Changes:
-
$Id: cacao.c 4357 2006-01-22 23:33:38Z twisti $
*/
/* 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 **************************************************************
{
/* 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 */
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 */
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 */
/* 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);
}
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 $
*/
utf *utf_add;
utf *utf_remove;
+utf *utf_addThread;
utf *utf_removeThread;
utf *utf_put;
utf *utf_get;
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");
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 $
*/
extern utf *utf_add;
extern utf *utf_remove;
+extern utf *utf_addThread;
extern utf *utf_removeThread;
extern utf *utf_put;
extern utf *utf_get;