1 /* src/native/vm/VMThread.c - java/lang/VMThread
3 Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4 R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5 C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6 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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
27 Authors: Roman Obermaiser
29 Changes: Joseph Wenninger
32 $Id: VMThread.c 3575 2005-11-05 16:26:56Z twisti $
40 #include "native/jni.h"
41 #include "native/native.h"
42 #include "native/include/java_lang_ThreadGroup.h"
43 #include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
44 #include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
45 #include "native/include/java_lang_VMThread.h"
46 #include "native/include/java_lang_Thread.h"
48 #if defined(USE_THREADS)
49 # if defined(NATIVE_THREADS)
50 # include "threads/native/threads.h"
52 # include "threads/green/threads.h"
56 #include "toolbox/logging.h"
57 #include "vm/exceptions.h"
58 #include "vm/options.h"
62 * Class: java/lang/VMThread
63 * Method: countStackFrames
66 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
68 log_text("java_lang_VMThread_countStackFrames called");
75 * Class: java/lang/VMThread
79 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 stacksize)
81 #if defined(USE_THREADS)
82 this->thread->vmThread = this;
84 /* don't pass a function pointer (NULL) since we want Thread.run()V here */
86 threads_start_thread((thread *) this->thread, NULL);
92 * Class: java/lang/VMThread
96 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
98 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
99 interruptThread(this);
101 log_text("Java_java_lang_VMThread_interrupt called");
107 * Class: java/lang/VMThread
108 * Method: isInterrupted
111 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
113 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
114 return isInterruptedThread(this);
116 log_text("Java_java_lang_VMThread_isInterrupted called");
123 * Class: java/lang/VMThread
127 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
130 log_text("java_lang_VMThread_suspend called");
132 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
133 suspendThread((thread *) this->thread);
139 * Class: java/lang/VMThread
143 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
146 log_text("java_lang_VMThread_resume0 called");
148 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
149 resumeThread((thread *) this->thread);
155 * Class: java/lang/VMThread
156 * Method: nativeSetPriority
159 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 priority)
162 log_text("java_lang_VMThread_nativeSetPriority called");
164 #if defined(USE_THREADS)
165 setPriorityThread((thread *) this->thread, priority);
171 * Class: java/lang/VMThread
173 * Signature: (Ljava/lang/Object;)V
175 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
178 log_text ("java_lang_VMThread_nativeStop called");
180 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
181 if (currentThread == (thread *) this->thread) {
185 exceptionptr = proto_java_lang_ThreadDeath;
190 /*CONTEXT((thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
191 resumeThread((thread *) this->thread);
198 * Class: java/lang/VMThread
199 * Method: currentThread
200 * Signature: ()Ljava/lang/Thread;
202 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
206 #if defined(USE_THREADS)
207 #if defined(NATIVE_THREADS)
208 t = ((threadobject*) THREADOBJECT)->o.thread;
210 t = (java_lang_Thread *) currentThread;
214 log_text("t ptr is NULL\n");
217 /* ThreadGroup of currentThread is not initialized */
219 t->group = (java_lang_ThreadGroup *)
220 native_new_and_init(class_java_lang_ThreadGroup);
222 if (t->group == NULL)
223 log_text("unable to create ThreadGroup");
226 /* we just return a fake java.lang.Thread object, otherwise we get
227 NullPointerException's in GNU classpath */
229 t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
237 * Class: java/lang/VMThread
241 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
244 log_text("java_lang_VMThread_yield called");
246 #if defined(USE_THREADS)
253 * Class: java/lang/VMThread
254 * Method: interrupted
257 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
259 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
260 return interruptedThread();
262 log_text("Java_java_lang_VMThread_interrupted");
269 * Class: java/lang/VMThread
271 * Signature: (Ljava/lang/Object;)Z
273 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
275 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
276 return threadHoldsLock((threadobject*) THREADOBJECT,
277 (java_objectheader *) o);
279 /* I don't know how to find out [stefan] */
286 * These are local overrides for various environment variables in Emacs.
287 * Please do not remove this and leave it at the end of the file, where
288 * Emacs will automagically detect them.
289 * ---------------------------------------------------------------------
292 * indent-tabs-mode: t