/* src/threads/threads-common.c - machine independent thread functions Copyright (C) 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. $Id: signal.c 7246 2007-01-29 18:49:05Z twisti $ */ #include "config.h" #include "vm/types.h" #include "native/jni.h" #include "native/include/java_lang_Object.h" #include "native/include/java_lang_Thread.h" #if defined(WITH_CLASSPATH_GNU) # include "native/include/java_lang_VMThread.h" #endif #include "threads/threads-common.h" #include "threads/native/threads.h" #include "vm/builtin.h" #include "vm/stringlocal.h" #include "vm/jit/stacktrace.h" #include "vmcore/class.h" #include "vmcore/utf8.h" /* threads_create_thread ******************************************************* Creates a thread object with the given name. *******************************************************************************/ threadobject *threads_create_thread(utf *name) { threadobject *thread; java_lang_Thread *t; #if defined(WITH_CLASSPATH_GNU) java_lang_VMThread *vmt; #endif /* create the vm internal thread object */ thread = NEW(threadobject); if (thread == NULL) return NULL; /* create the java thread object */ t = (java_lang_Thread *) builtin_new(class_java_lang_Thread); if (t == NULL) return NULL; #if defined(WITH_CLASSPATH_GNU) vmt = (java_lang_VMThread *) builtin_new(class_java_lang_VMThread); if (vmt == NULL) return NULL; vmt->thread = t; vmt->vmdata = (java_lang_Object *) thread; t->vmThread = vmt; #elif defined(WITH_CLASSPATH_CLDC1_1) t->vm_thread = (java_lang_Object *) thread; #endif thread->object = t; thread->flags = THREAD_FLAG_DAEMON; /* set java.lang.Thread fields */ t->name = javastring_new(name); #if defined(ENABLE_JAVASE) t->daemon = true; #endif t->priority = NORM_PRIORITY; /* return the thread object */ return thread; } /* threads_get_current_tid ***************************************************** Return the tid of the current thread. RETURN VALUE: the current tid *******************************************************************************/ ptrint threads_get_current_tid(void) { threadobject *thread; thread = THREADOBJECT; /* this may happen during bootstrap */ if (thread == NULL) return 0; return (ptrint) thread->tid; } /* threads_dump **************************************************************** Dumps info for all threads running in the JVM. This function is called when SIGQUIT (-\) is sent to CACAO. *******************************************************************************/ void threads_dump(void) { threadobject *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 */ do { /* get thread object */ t = thread->object; /* the thread may be currently in initalization, don't print it */ if (t != NULL) { /* get thread name */ #if defined(ENABLE_JAVASE) name = javastring_toutf(t->name, false); #elif defined(ENABLE_JAVAME_CLDC1_1) name = t->name; #endif printf("\n\""); utf_display_printable_ascii(name); printf("\" "); if (thread->flags & THREAD_FLAG_DAEMON) printf("daemon "); #if SIZEOF_VOID_P == 8 printf("prio=%d tid=0x%016lx\n", t->priority, (ptrint) thread->tid); #else printf("prio=%d tid=0x%08lx\n", t->priority, (ptrint) thread->tid); #endif /* print trace of thread */ threads_print_stacktrace(thread); } thread = thread->next; } while ((thread != NULL) && (thread != mainthreadobj)); } /* threads_print_stacktrace **************************************************** Print the current stacktrace of the given thread. *******************************************************************************/ void threads_print_stacktrace(threadobject *thread) { stackframeinfo *sfi; stacktracebuffer *stb; s4 dumpsize; /* mark start of dump memory area */ dumpsize = dump_size(); /* create a stacktrace for the current thread */ #if defined(ENABLE_THREADS) sfi = thread->_stackframeinfo; #else sfi = _no_threads_stackframeinfo; #endif stb = stacktrace_create(sfi); /* print stacktrace */ if (stb != NULL) stacktrace_print_trace_from_buffer(stb); else { puts("\t<>"); fflush(stdout); } dump_release(dumpsize); } /* * 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: * vim:noexpandtab:sw=4:ts=4: */