1 /* src/threads/threads-common.c - machine independent thread functions
3 Copyright (C) 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: signal.c 7246 2007-01-29 18:49:05Z twisti $
34 #include "native/jni.h"
35 #include "native/include/java_lang_Object.h"
36 #include "native/include/java_lang_Thread.h"
38 #if defined(WITH_CLASSPATH_GNU)
39 # include "native/include/java_lang_VMThread.h"
42 #include "threads/threads-common.h"
44 #include "threads/native/threads.h"
46 #include "vm/builtin.h"
47 #include "vm/stringlocal.h"
49 #include "vm/jit/stacktrace.h"
51 #include "vmcore/class.h"
52 #include "vmcore/utf8.h"
55 /* threads_create_thread *******************************************************
57 Creates a thread object with the given name.
59 *******************************************************************************/
61 threadobject *threads_create_thread(utf *name)
65 #if defined(WITH_CLASSPATH_GNU)
66 java_lang_VMThread *vmt;
69 /* create the vm internal thread object */
71 thread = NEW(threadobject);
76 /* create the java thread object */
78 t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
83 #if defined(WITH_CLASSPATH_GNU)
84 vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread);
90 vmt->vmdata = (java_lang_Object *) thread;
93 #elif defined(WITH_CLASSPATH_CLDC1_1)
94 t->vm_thread = (java_lang_Object *) thread;
98 thread->flags = THREAD_FLAG_DAEMON;
100 /* set java.lang.Thread fields */
102 t->name = javastring_new(name);
103 #if defined(ENABLE_JAVASE)
106 t->priority = NORM_PRIORITY;
108 /* return the thread object */
114 /* threads_get_current_tid *****************************************************
116 Return the tid of the current thread.
121 *******************************************************************************/
123 ptrint threads_get_current_tid(void)
125 threadobject *thread;
127 thread = THREADOBJECT;
129 /* this may happen during bootstrap */
134 return (ptrint) thread->tid;
138 /* threads_dump ****************************************************************
140 Dumps info for all threads running in the JVM. This function is
141 called when SIGQUIT (<ctrl>-\) is sent to CACAO.
143 *******************************************************************************/
145 void threads_dump(void)
147 threadobject *thread;
151 thread = mainthreadobj;
153 /* XXX we should stop the world here */
155 printf("Full thread dump CACAO "VERSION":\n");
157 /* iterate over all started threads */
160 /* get thread object */
164 /* the thread may be currently in initalization, don't print it */
167 /* get thread name */
169 #if defined(ENABLE_JAVASE)
170 name = javastring_toutf(t->name, false);
171 #elif defined(ENABLE_JAVAME_CLDC1_1)
176 utf_display_printable_ascii(name);
179 if (thread->flags & THREAD_FLAG_DAEMON)
182 #if SIZEOF_VOID_P == 8
183 printf("prio=%d tid=0x%016lx\n", t->priority, (ptrint) thread->tid);
185 printf("prio=%d tid=0x%08lx\n", t->priority, (ptrint) thread->tid);
188 /* print trace of thread */
190 threads_print_stacktrace(thread);
193 thread = thread->next;
194 } while ((thread != NULL) && (thread != mainthreadobj));
198 /* threads_print_stacktrace ****************************************************
200 Print the current stacktrace of the given thread.
202 *******************************************************************************/
204 void threads_print_stacktrace(threadobject *thread)
207 stacktracebuffer *stb;
210 /* mark start of dump memory area */
212 dumpsize = dump_size();
214 /* create a stacktrace for the current thread */
216 #if defined(ENABLE_THREADS)
217 sfi = thread->_stackframeinfo;
219 sfi = _no_threads_stackframeinfo;
222 stb = stacktrace_create(sfi);
224 /* print stacktrace */
227 stacktrace_print_trace_from_buffer(stb);
229 puts("\t<<No stacktrace available>>");
233 dump_release(dumpsize);
238 * These are local overrides for various environment variables in Emacs.
239 * Please do not remove this and leave it at the end of the file, where
240 * Emacs will automagically detect them.
241 * ---------------------------------------------------------------------
244 * indent-tabs-mode: t
248 * vim:noexpandtab:sw=4:ts=4: