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 2195 2005-04-03 16:53:16Z edwin $
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/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");
74 * Class: java/lang/VMThread
75 * Method: currentThread
76 * Signature: ()Ljava/lang/Thread;
78 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
81 classinfo *threadgroupclass;
84 log_text("java_lang_VMThread_currentThread called");
86 #if defined(USE_THREADS)
87 #if !defined(NATIVE_THREADS)
88 t = (java_lang_Thread *) currentThread;
90 t = ((threadobject*) THREADOBJECT)->o.thread;
93 log_text("java_lang_VMThread_currentThread 111");
94 if ((runverbose) && (t == NULL))
95 log_text("t ptr is NULL\n");
96 if (t == NULL) printf("t ptr is NULL\n"); fflush(stdout);
99 /* ThreadGroup of currentThread is not initialized */
101 log_text("java_lang_VMThread_currentThread 222");
103 if (!load_class_bootstrap(utf_new_char("java/lang/ThreadGroup"),&threadgroupclass))
106 t->group = (java_lang_ThreadGroup *) native_new_and_init(threadgroupclass);
109 log_text("java_lang_VMThread_currentThread 333");
111 log_text("unable to create ThreadGroup");
113 log_text("java_lang_VMThread_currentThread 444");
116 log_text("java_lang_VMThread_currentThread 555");
126 * Class: java/lang/VMThread
130 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
132 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
133 interruptThread(this);
135 log_text("Java_java_lang_VMThread_interrupt called");
141 * Class: java/lang/VMThread
145 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isAlive(JNIEnv *env, java_lang_VMThread *this)
148 log_text("java_lang_VMThread_isAlive called");
150 #if defined(USE_THREADS)
151 #if !defined(NATIVE_THREADS)
152 return aliveThread((thread *) this->thread);
154 /* This method is implemented in classpath. */
155 throw_cacao_exception_exit(string_java_lang_InternalError, "aliveThread");
159 /* keep compiler happy */
167 * Class: java/lang/VMThread
168 * Method: isInterrupted
171 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
173 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
174 return isInterruptedThread(this);
176 log_text("Java_java_lang_VMThread_isInterrupted called");
183 * Class: java/lang/VMThread
184 * Method: registerNatives
187 JNIEXPORT void JNICALL Java_java_lang_VMThread_registerNatives(JNIEnv *env, jclass clazz)
194 * Class: java/lang/VMThread
198 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
201 log_text("java_lang_VMThread_resume0 called");
203 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
204 resumeThread((thread *) this->thread);
210 * Class: java/lang/VMThread
211 * Method: nativeSetPriority
214 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, s4 par1)
217 log_text("java_lang_VMThread_nativeSetPriority called");
219 #if defined(USE_THREADS)
220 setPriorityThread((thread *) this->thread, par1);
226 * Class: java/lang/VMThread
230 JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, s8 millis, s4 nanos)
232 #if defined(USE_THREADS)
233 sleepThread(millis, nanos);
239 * Class: java/lang/VMThread
243 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, s8 par1)
246 log_text("java_lang_VMThread_start called");
248 #if defined(USE_THREADS)
249 this->thread->vmThread = this;
250 startThread((thread *) this->thread);
256 * Class: java/lang/VMThread
258 * Signature: (Ljava/lang/Object;)V
260 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *par1)
263 log_text ("java_lang_VMThread_nativeStop called");
266 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
267 if (currentThread == (thread*)this->thread) {
271 exceptionptr = proto_java_lang_ThreadDeath;
276 /*CONTEXT((thread*)this)*/ this->flags |= THREAD_FLAGS_KILLED;
277 resumeThread((thread*)this->thread);
284 * Class: java/lang/VMThread
288 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
291 log_text("java_lang_VMThread_suspend called");
293 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
294 suspendThread((thread*)this->thread);
300 * Class: java/lang/VMThread
304 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
307 log_text("java_lang_VMThread_yield called");
309 #if defined(USE_THREADS)
316 * Class: java/lang/VMThread
317 * Method: interrupted
320 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
322 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
323 return interruptedThread();
325 log_text("Java_java_lang_VMThread_interrupted");
332 * Class: java/lang/VMThread
336 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeInit(JNIEnv *env, java_lang_VMThread *this, s8 par1)
338 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
345 * Class: java/lang/VMThread
347 * Signature: (Ljava/lang/Object;)Z
349 JNIEXPORT s4 JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
351 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
352 return threadHoldsLock((threadobject*) THREADOBJECT,
353 (java_objectheader *) o);
355 /* I don't know how to find out [stefan] */
362 * These are local overrides for various environment variables in Emacs.
363 * Please do not remove this and leave it at the end of the file, where
364 * Emacs will automagically detect them.
365 * ---------------------------------------------------------------------
368 * indent-tabs-mode: t