Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
- $Id: signal.c 7246 2007-01-29 18:49:05Z twisti $
+ $Id: threads-common.c 7805 2007-04-25 11:47:15Z twisti $
*/
#include "config.h"
-#include "vm/types.h"
+#include <assert.h>
+
+#include "vm/types.h"
#include "native/jni.h"
+
#include "native/include/java_lang_Object.h"
+#include "native/include/java_lang_String.h"
#include "native/include/java_lang_Thread.h"
#if defined(WITH_CLASSPATH_GNU)
#include "vm/jit/stacktrace.h"
#include "vmcore/class.h"
+
+#if defined(ENABLE_STATISTICS)
+# include "vmcore/options.h"
+# include "vmcore/statistics.h"
+#endif
+
#include "vmcore/utf8.h"
/* create the vm internal thread object */
+#if defined(ENABLE_GC_BOEHM)
+ thread = GCNEW_UNCOLLECTABLE(threadobject, 1);
+#else
thread = NEW(threadobject);
+#endif
if (thread == NULL)
return NULL;
/* set java.lang.Thread fields */
- t->name = javastring_new(name);
+ t->name = (java_lang_String *) javastring_new(name);
#if defined(ENABLE_JAVASE)
t->daemon = true;
#endif
}
+/* threads_start_javathread ***************************************************
+
+ Start a thread in the JVM. Only the java thread object exists so far.
+
+ IN:
+ object.....the java thread object java.lang.Thread
+
+******************************************************************************/
+
+void threads_start_javathread(java_lang_Thread *object)
+{
+ threadobject *thread;
+
+ /* create the vm internal threadobject */
+
+#if defined(ENABLE_GC_BOEHM)
+ thread = GCNEW_UNCOLLECTABLE(threadobject, 1);
+#else
+ thread = NEW(threadobject);
+#endif
+
+#if defined(ENABLE_STATISTICS)
+ if (opt_stat)
+ size_threadobject += sizeof(threadobject);
+#endif
+
+ /* link the two objects together */
+
+ thread->object = object;
+
+#if defined(ENABLE_JAVASE)
+ /* is this a daemon thread? */
+
+ if (object->daemon == true)
+ thread->flags |= THREAD_FLAG_DAEMON;
+#endif
+
+#if defined(WITH_CLASSPATH_GNU)
+ assert(object->vmThread);
+ assert(object->vmThread->vmdata == NULL);
+
+ object->vmThread->vmdata = (java_lang_Object *) thread;
+#elif defined(WITH_CLASSPATH_CLDC1_1)
+ object->vm_thread = (java_lang_Object *) thread;
+#endif
+
+ /* Actually start the thread. Don't pass a function pointer
+ (NULL) since we want Thread.run()V here. */
+
+ threads_start_thread(thread, NULL);
+}
+
+
/* threads_get_current_tid *****************************************************
Return the tid of the current thread.
java_lang_Thread *t;
utf *name;
- thread = mainthreadobj;
-
/* XXX we should stop the world here */
printf("Full thread dump CACAO "VERSION":\n");
/* iterate over all started threads */
+ thread = mainthreadobj;
+
do {
/* get thread object */
/* get thread name */
#if defined(ENABLE_JAVASE)
- name = javastring_toutf(t->name, false);
+ name = javastring_toutf((java_objectheader *) t->name, false);
#elif defined(ENABLE_JAVAME_CLDC1_1)
name = t->name;
#endif
printf(" prio=%d", t->priority);
#if SIZEOF_VOID_P == 8
- printf(" tid=0x%016lx", (ptrint) thread->tid);
+ printf(" tid=0x%016lx (%ld)",
+ (ptrint) thread->tid, (ptrint) thread->tid);
#else
- printf(" tid=0x%08lx", (ptrint) thread->tid);
+ printf(" tid=0x%08lx (%ld)",
+ (ptrint) thread->tid, (ptrint) thread->tid);
#endif
/* print thread state */
/* print trace of thread */
- threads_print_stacktrace(thread);
+ threads_thread_print_stacktrace(thread);
}
thread = thread->next;
}
-/* threads_print_stacktrace ****************************************************
+/* threads_thread_print_stacktrace *********************************************
- Print the current stacktrace of the given thread.
+ Print the current stacktrace of the current thread.
*******************************************************************************/
-void threads_print_stacktrace(threadobject *thread)
+void threads_thread_print_stacktrace(threadobject *thread)
{
stackframeinfo *sfi;
stacktracebuffer *stb;
}
+/* threads_print_stacktrace ****************************************************
+
+ Print the current stacktrace of the current thread.
+
+*******************************************************************************/
+
+void threads_print_stacktrace(void)
+{
+ threadobject *thread;
+
+ thread = THREADOBJECT;
+
+ threads_thread_print_stacktrace(thread);
+}
+
+
/*
* 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