- exception stuff
[cacao.git] / src / native / vm / VMThread.c
1 /* nat/Thread.c - java/lang/Thread
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Roman Obermaiser
28
29    Changes: Joseph Wenninger
30
31    $Id: VMThread.c 1042 2004-04-26 17:12:47Z twisti $
32
33 */
34
35
36 #include "jni.h"
37 #include "builtin.h"
38 #include "types.h"
39 #include "native.h"
40 #include "loader.h"
41 #include "tables.h"
42 #include "threads/thread.h"
43 #include "toolbox/loging.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_Thread.h"
48
49
50 /*
51  * Class:     java/lang/Thread
52  * Method:    countStackFrames
53  * Signature: ()I
54  */
55 JNIEXPORT s4 JNICALL Java_java_lang_Thread_countStackFrames(JNIEnv *env, java_lang_Thread *this)
56 {
57     log_text("java_lang_Thread_countStackFrames called");
58
59     return 0;
60 }
61
62 /*
63  * Class:     java/lang/Thread
64  * Method:    currentThread
65  * Signature: ()Ljava/lang/Thread;
66  */
67 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
68 {
69         java_lang_Thread *t;
70
71         if (runverbose)
72                 log_text("java_lang_Thread_currentThread called");
73
74 #if defined(USE_THREADS)
75 #if !defined(NATIVE_THREADS)
76         t = (java_lang_Thread *) currentThread;
77 #else
78         t = THREADOBJECT;
79 #endif
80   
81         if (!t->group) {
82                 log_text("java_lang_Thread_currentThread: t->group=NULL");
83                 /* ThreadGroup of currentThread is not initialized */
84
85                 t->group = (java_lang_ThreadGroup *) 
86                         native_new_and_init(class_new(utf_new_char("java/lang/ThreadGroup")));
87
88                 if (t->group == 0) 
89                         log_text("unable to create ThreadGroup");
90         }
91
92         return (java_lang_Thread *) t;
93 #else
94         return 0;       
95 #endif
96 }
97
98
99 /*
100  * Class:     java/lang/Thread
101  * Method:    nativeInterrupt
102  * Signature: ()V
103  */
104 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInterrupt(JNIEnv *env, java_lang_Thread *this)
105 {
106         log_text("Java_java_lang_Thread_interrupt0 called");
107 }
108
109
110 /*
111  * Class:     java/lang/Thread
112  * Method:    isAlive
113  * Signature: ()Z
114  */
115 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, java_lang_Thread *this)
116 {
117         if (runverbose)
118                 log_text("java_lang_Thread_isAlive called");
119
120 #if defined(USE_THREADS)
121         return aliveThread((thread *) this);
122 #endif
123 }
124
125
126
127 /*
128  * Class:     java_lang_Thread
129  * Method:    isInterrupted
130  * Signature: ()Z
131  */
132 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isInterrupted(JNIEnv *env, java_lang_Thread *this)
133 {
134         log_text("Java_java_lang_Thread_isInterrupted  called");
135         return 0;
136 }
137
138
139 /*
140  * Class:     java/lang/Thread
141  * Method:    registerNatives
142  * Signature: ()V
143  */
144 JNIEXPORT void JNICALL Java_java_lang_Thread_registerNatives(JNIEnv *env, jclass clazz)
145 {
146         /* empty */
147 }
148
149
150 /*
151  * Class:     java/lang/Thread
152  * Method:    resume0
153  * Signature: ()V
154  */
155 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeResume(JNIEnv *env, java_lang_Thread *this)
156 {
157         if (runverbose)
158                 log_text("java_lang_Thread_resume0 called");
159
160 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
161         resumeThread((thread *) this);
162 #endif
163 }
164
165
166 /*
167  * Class:     java/lang/Thread
168  * Method:    setPriority0
169  * Signature: (I)V
170  */
171 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSetPriority(JNIEnv *env, java_lang_Thread *this, s4 par1)
172 {
173     if (runverbose) 
174                 log_text("java_lang_Thread_setPriority0 called");
175
176 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
177         setPriorityThread((thread *) this, par1);
178 #endif
179 }
180
181
182 /*
183  * Class:     java_lang_Thread
184  * Method:    sleep
185  * Signature: (JI)V
186  */
187 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 par2)
188 {
189         if (runverbose)
190                 log_text("java_lang_Thread_sleep called");
191
192 #if defined(USE_THREADS)
193         sleepThread(millis);
194 #endif
195 }
196
197
198 /*
199  * Class:     java/lang/Thread
200  * Method:    start
201  * Signature: ()V
202  */
203 JNIEXPORT void JNICALL Java_java_lang_Thread_start(JNIEnv *env, java_lang_Thread *this)
204 {
205         if (runverbose) 
206                 log_text("java_lang_Thread_start called");
207
208 #if defined(USE_THREADS)
209         startThread((thread*)this);
210 #endif
211 }
212
213
214 /*
215  * Class:     java/lang/Thread
216  * Method:    stop0
217  * Signature: (Ljava/lang/Object;)V
218  */
219 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeStop(JNIEnv *env, java_lang_Thread *this, java_lang_Throwable *par1)
220 {
221         if (runverbose)
222                 log_text ("java_lang_Thread_stop0 called");
223
224
225 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
226         if (currentThread == (thread*)this) {
227                 log_text("killing");
228                 killThread(0);
229                 /*
230                   exceptionptr = proto_java_lang_ThreadDeath;
231                   return;
232                 */
233
234         } else {
235                 CONTEXT((thread*)this).flags |= THREAD_FLAGS_KILLED;
236                 resumeThread((thread*)this);
237         }
238 #endif
239 }
240
241
242 /*
243  * Class:     java/lang/Thread
244  * Method:    suspend0
245  * Signature: ()V
246  */
247 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSuspend(JNIEnv *env, java_lang_Thread *this)
248 {
249         if (runverbose)
250                 log_text("java_lang_Thread_suspend0 called");
251
252 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
253         suspendThread((thread*)this);
254 #endif
255 }
256
257
258 /*
259  * Class:     java/lang/Thread
260  * Method:    yield
261  * Signature: ()V
262  */
263 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
264 {
265         if (runverbose)
266                 log_text("java_lang_Thread_yield called");
267
268 #if defined(USE_THREADS)
269         yieldThread();
270 #endif
271 }
272
273
274 /*
275  * Class:     java_lang_Thread
276  * Method:    interrupted
277  * Signature: ()Z
278  */
279 JNIEXPORT s4 JNICALL Java_java_lang_Thread_interrupted(JNIEnv *env, jclass clazz)
280 {
281         log_text("Java_java_lang_Thread_interrupted");
282
283         return 0;
284 }
285
286
287 /*
288  * Class:     java_lang_Thread
289  * Method:    nativeInit
290  * Signature: (J)V
291  */
292 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInit(JNIEnv *env, java_lang_Thread *this, s8 par1)
293 {
294 /*
295         if (*exceptionptr)
296                 log_text("There has been an exception, strange...");*/
297
298 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
299         initThread(this);
300 #endif
301         this->priority = 5;
302 }
303
304
305 /*
306  * Class:     java_lang_Thread
307  * Method:    holdsLock
308  * Signature: (Ljava/lang/Object;)Z
309  */
310 JNIEXPORT s4 JNICALL Java_java_lang_Thread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object *par1)
311 {
312         return 0;
313 }
314
315
316 /*
317  * These are local overrides for various environment variables in Emacs.
318  * Please do not remove this and leave it at the end of the file, where
319  * Emacs will automagically detect them.
320  * ---------------------------------------------------------------------
321  * Local variables:
322  * mode: c
323  * indent-tabs-mode: t
324  * c-basic-offset: 4
325  * tab-width: 4
326  * End:
327  */