1 /* nat/Thread.c - java/lang/Thread
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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 1206 2004-06-25 10:15:56Z twisti $
42 #include "threads/thread.h"
43 #include "toolbox/logging.h"
44 #include "java_lang_ThreadGroup.h"
45 #include "java_lang_Object.h" /* needed for java_lang_Thread.h */
46 #include "java_lang_Throwable.h" /* needed for java_lang_Thread.h */
47 #include "java_lang_VMThread.h"
48 #include "java_lang_Thread.h"
52 * Class: java/lang/Thread
53 * Method: countStackFrames
56 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
58 log_text("java_lang_VMThread_countStackFrames called");
64 * Class: java/lang/Thread
65 * Method: currentThread
66 * Signature: ()Ljava/lang/Thread;
68 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
73 log_text("java_lang_VMThread_currentThread called");
75 #if defined(USE_THREADS)
76 #if !defined(NATIVE_THREADS)
77 t = (java_lang_Thread *) currentThread;
83 log_text("java_lang_VMThread_currentThread: t->group=NULL");
84 /* ThreadGroup of currentThread is not initialized */
86 t->group = (java_lang_ThreadGroup *)
87 native_new_and_init(class_new(utf_new_char("java/lang/ThreadGroup")));
90 log_text("unable to create ThreadGroup");
93 return (java_lang_Thread *) t;
101 * Class: java/lang/Thread
102 * Method: nativeInterrupt
105 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
107 log_text("Java_java_lang_VMThread_interrupt0 called");
112 * Class: java/lang/Thread
116 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isAlive(JNIEnv *env, java_lang_VMThread *this)
119 log_text("java_lang_VMThread_isAlive called");
121 #if defined(USE_THREADS)
122 return aliveThread((thread *) this->thread);
129 * Class: java_lang_Thread
130 * Method: isInterrupted
133 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
135 log_text("Java_java_lang_VMThread_isInterrupted called");
141 * Class: java/lang/Thread
142 * Method: registerNatives
145 JNIEXPORT void JNICALL Java_java_lang_VMThread_registerNatives(JNIEnv *env, jclass clazz)
152 * Class: java/lang/Thread
156 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
159 log_text("java_lang_VMThread_resume0 called");
161 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
162 resumeThread((thread *) this->thread);
168 * Class: java/lang/Thread
169 * Method: setPriority0
172 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 par1)
175 log_text("java_lang_VMThread_setPriority0 called");
177 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
178 setPriorityThread((thread *) this->thread, par1);
184 * Class: java_lang_Thread
188 JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 nanos)
192 new_exception_message(string_java_lang_IllegalArgumentException,
193 "timeout value is negative");
198 if (nanos < 0 || nanos > 999999) {
200 new_exception_message(string_java_lang_IllegalArgumentException,
201 "nanosecond timeout value out of range");
206 #if defined(USE_THREADS)
207 sleepThread(millis, nanos);
213 * Class: java/lang/Thread
217 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 par1)
220 log_text("java_lang_VMThread_start called");
222 #if defined(USE_THREADS)
223 #if defined(__GNUC__)
224 #warning perhaps it would be better to always work with the vmthread structure in the thread code (jowenn)
226 if (this->thread->vmThread == 0)
227 this->thread->vmThread = this;
229 startThread((thread *) (this->thread));
235 * Class: java/lang/Thread
237 * Signature: (Ljava/lang/Object;)V
239 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *par1)
242 log_text ("java_lang_VMThread_stop0 called");
245 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
246 if (currentThread == (thread*)this->thread) {
250 exceptionptr = proto_java_lang_ThreadDeath;
255 /*CONTEXT((thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
256 resumeThread((thread*)this->thread);
263 * Class: java/lang/Thread
267 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
270 log_text("java_lang_VMThread_suspend0 called");
272 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
273 suspendThread((thread*)this->thread);
279 * Class: java/lang/Thread
283 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
286 log_text("java_lang_VMThread_yield called");
288 #if defined(USE_THREADS)
295 * Class: java_lang_Thread
296 * Method: interrupted
299 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
301 log_text("Java_java_lang_VMThread_interrupted");
308 * Class: java_lang_Thread
312 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeInit(JNIEnv *env, java_lang_VMThread *this, s8 par1)
316 log_text("There has been an exception, strange...");*/
318 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
319 initThread(this->thread);
321 this->thread->priority = 5;
326 * Class: java_lang_Thread
328 * Signature: (Ljava/lang/Object;)Z
330 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object *par1)
337 * These are local overrides for various environment variables in Emacs.
338 * Please do not remove this and leave it at the end of the file, where
339 * Emacs will automagically detect them.
340 * ---------------------------------------------------------------------
343 * indent-tabs-mode: t