1 /* 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
31 $Id: VMThread.c 1735 2004-12-07 14:33:27Z twisti $
38 #include "native/jni.h"
39 #include "native/native.h"
40 #include "native/include/java_lang_ThreadGroup.h"
41 #include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
42 #include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
43 #include "native/include/java_lang_VMThread.h"
44 #include "native/include/java_lang_Thread.h"
46 #if defined(USE_THREADS)
47 # if defined(NATIVE_THREADS)
48 # include "threads/native/threads.h"
50 # include "threads/green/threads.h"
54 #include "toolbox/logging.h"
55 #include "vm/builtin.h"
56 #include "vm/exceptions.h"
57 #include "vm/options.h"
58 #include "vm/tables.h"
62 * Class: java/lang/Thread
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");
74 * Class: java/lang/Thread
75 * Method: currentThread
76 * Signature: ()Ljava/lang/Thread;
78 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
83 log_text("java_lang_VMThread_currentThread called");
85 #if defined(USE_THREADS)
86 #if !defined(NATIVE_THREADS)
87 t = (java_lang_Thread *) currentThread;
89 t = ((threadobject*) THREADOBJECT)->o.thread;
93 log_text("java_lang_VMThread_currentThread: t->group=NULL");
94 /* ThreadGroup of currentThread is not initialized */
96 t->group = (java_lang_ThreadGroup *)
97 native_new_and_init(class_new(utf_new_char("java/lang/ThreadGroup")));
100 log_text("unable to create ThreadGroup");
111 * Class: java/lang/Thread
112 * Method: nativeInterrupt
115 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
117 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
118 interruptThread(this);
120 log_text("Java_java_lang_VMThread_interrupt0 called");
126 * Class: java/lang/Thread
130 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isAlive(JNIEnv *env, java_lang_VMThread *this)
133 log_text("java_lang_VMThread_isAlive called");
135 #if defined(USE_THREADS)
136 #if !defined(NATIVE_THREADS)
137 return aliveThread((thread *) this->thread);
139 /* This method is implemented in classpath. */
140 throw_cacao_exception_exit(string_java_lang_InternalError, "aliveThread");
144 /* keep compiler happy */
152 * Class: java_lang_Thread
153 * Method: isInterrupted
156 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
158 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
159 return isInterruptedThread(this);
161 log_text("Java_java_lang_VMThread_isInterrupted called");
168 * Class: java/lang/Thread
169 * Method: registerNatives
172 JNIEXPORT void JNICALL Java_java_lang_VMThread_registerNatives(JNIEnv *env, jclass clazz)
179 * Class: java/lang/Thread
183 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
186 log_text("java_lang_VMThread_resume0 called");
188 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
189 resumeThread((thread *) this->thread);
195 * Class: java/lang/Thread
196 * Method: setPriority0
199 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 par1)
202 log_text("java_lang_VMThread_setPriority0 called");
204 #if defined(USE_THREADS)
205 setPriorityThread((thread *) this->thread, par1);
211 * Class: java_lang_Thread
215 JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 nanos)
217 #if defined(USE_THREADS)
218 sleepThread(millis, nanos);
224 * Class: java/lang/Thread
228 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 par1)
231 log_text("java_lang_VMThread_start called");
233 #if defined(USE_THREADS)
234 this->thread->vmThread = this;
235 startThread((thread *) this->thread);
241 * Class: java/lang/Thread
243 * Signature: (Ljava/lang/Object;)V
245 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *par1)
248 log_text ("java_lang_VMThread_stop0 called");
251 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
252 if (currentThread == (thread*)this->thread) {
256 exceptionptr = proto_java_lang_ThreadDeath;
261 /*CONTEXT((thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
262 resumeThread((thread*)this->thread);
269 * Class: java/lang/Thread
273 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
276 log_text("java_lang_VMThread_suspend0 called");
278 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
279 suspendThread((thread*)this->thread);
285 * Class: java/lang/Thread
289 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
292 log_text("java_lang_VMThread_yield called");
294 #if defined(USE_THREADS)
301 * Class: java_lang_Thread
302 * Method: interrupted
305 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
307 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
308 return interruptedThread();
310 log_text("Java_java_lang_VMThread_interrupted");
317 * Class: java_lang_Thread
321 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeInit(JNIEnv *env, java_lang_VMThread *this, s8 par1)
325 log_text("There has been an exception, strange...");*/
327 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
334 * Class: java/lang/VMThread
336 * Signature: (Ljava/lang/Object;)Z
338 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
340 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
341 return threadHoldsLock((threadobject*) THREADOBJECT,
342 (java_objectheader *) o);
344 /* I don't know how to find out [stefan] */
351 * These are local overrides for various environment variables in Emacs.
352 * Please do not remove this and leave it at the end of the file, where
353 * Emacs will automagically detect them.
354 * ---------------------------------------------------------------------
357 * indent-tabs-mode: t