1 /* src/native/vm/java_lang_Thread.c - java/lang/Thread functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, 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., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
33 #include "native/jni.h"
34 #include "native/native.h"
36 #include "native/include/java_lang_String.h"
37 #include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
38 #include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
39 #include "native/include/java_lang_Thread.h"
41 #if defined(ENABLE_JAVASE)
42 # include "native/include/java_lang_ThreadGroup.h"
43 # include "native/include/java_lang_VMThread.h"
46 #include "threads/threads-common.h"
48 #include "toolbox/logging.h"
50 #include "vm/builtin.h"
51 #include "vm/exceptions.h"
52 #include "vm/stringlocal.h"
54 #include "vmcore/options.h"
58 * Class: java/lang/Thread
59 * Method: countStackFrames
62 s4 _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this)
64 log_text("java_lang_Thread_countStackFrames called");
71 * Class: java/lang/Thread
75 void _Jv_java_lang_Thread_sleep(s8 millis)
77 #if defined(ENABLE_THREADS)
78 threads_sleep(millis, 0);
84 * Class: java/lang/Thread
88 void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
90 #if defined(ENABLE_THREADS)
91 threads_start_javathread(this);
97 * Class: java/lang/Thread
101 void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
103 #if defined(ENABLE_THREADS)
104 threadobject *thread;
106 #if defined(WITH_CLASSPATH_GNU)
107 thread = (threadobject *) this->vmThread->vmdata;
108 #elif defined(WITH_CLASSPATH_CLDC1_1)
109 thread = (threadobject *) this->vm_thread;
112 threads_thread_interrupt(thread);
118 * Class: java/lang/Thread
122 s4 _Jv_java_lang_Thread_isAlive(java_lang_Thread *this)
124 #if defined(ENABLE_THREADS)
125 threadobject *thread;
127 #if defined(WITH_CLASSPATH_GNU)
128 thread = (threadobject *) this->vmThread->vmdata;
129 #elif defined(WITH_CLASSPATH_CLDC1_1)
130 thread = (threadobject *) this->vm_thread;
133 return threads_thread_is_alive(thread);
135 /* if threads are disabled, the only thread running is alive */
143 * Class: java/lang/Thread
144 * Method: isInterrupted
147 s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
149 #if defined(ENABLE_THREADS)
150 threadobject *thread;
152 #if defined(WITH_CLASSPATH_GNU)
153 thread = (threadobject *) this->vmThread->vmdata;
154 #elif defined(WITH_CLASSPATH_CLDC1_1)
155 thread = (threadobject *) this->vm_thread;
158 return threads_thread_has_been_interrupted(thread);
166 * Class: java/lang/Thread
170 void _Jv_java_lang_Thread_suspend(java_lang_Thread *this)
172 #if defined(ENABLE_THREADS)
178 * Class: java/lang/Thread
182 void _Jv_java_lang_Thread_resume(java_lang_Thread *this)
184 #if defined(ENABLE_THREADS)
190 * Class: java/lang/Thread
191 * Method: setPriority
194 void _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority)
196 #if defined(ENABLE_THREADS)
197 threadobject *thread;
199 #if defined(WITH_CLASSPATH_GNU)
200 thread = (threadobject *) this->vmThread->vmdata;
201 #elif defined(WITH_CLASSPATH_CLDC1_1)
202 thread = (threadobject *) this->vm_thread;
204 /* The threadobject is null when a thread is created in Java. The
205 priority is set later during startup. */
211 threads_set_thread_priority(thread->tid, priority);
217 * Class: java/lang/Thread
219 * Signature: (Ljava/lang/Object;)V
221 void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t)
223 #if defined(ENABLE_THREADS)
229 * Class: java/lang/Thread
230 * Method: currentThread
231 * Signature: ()Ljava/lang/Thread;
233 java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
235 #if defined(ENABLE_THREADS)
236 threadobject *thread;
240 #if defined(ENABLE_THREADS)
241 thread = THREADOBJECT;
246 log_text("t ptr is NULL\n");
248 # if defined(ENABLE_JAVASE)
249 if (t->group == NULL) {
250 /* ThreadGroup of currentThread is not initialized */
252 t->group = (java_lang_ThreadGroup *)
253 native_new_and_init(class_java_lang_ThreadGroup);
255 if (t->group == NULL)
256 log_text("unable to create ThreadGroup");
260 /* we just return a fake java.lang.Thread object, otherwise we get
261 NullPointerException's in GNU classpath */
263 t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
271 * Class: java/lang/Thread
275 void _Jv_java_lang_Thread_yield(void)
277 #if defined(ENABLE_THREADS)
284 * Class: java/lang/Thread
285 * Method: interrupted
288 s4 _Jv_java_lang_Thread_interrupted(void)
290 #if defined(ENABLE_THREADS)
291 return threads_check_if_interrupted_and_reset();
299 * Class: java/lang/Thread
301 * Signature: (Ljava/lang/Object;)Z
303 s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
305 #if defined(ENABLE_THREADS)
306 java_objectheader *o;
308 o = (java_objectheader *) obj;
311 exceptions_throw_nullpointerexception();
315 return lock_is_held_by_current_thread(o);
323 * Class: java/lang/Thread
325 * Signature: ()Ljava/lang/String;
327 java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
329 #if defined(ENABLE_THREADS)
330 threadobject *thread;
332 java_objectheader *o;
334 # if defined(WITH_CLASSPATH_GNU)
335 thread = (threadobject *) this->vmThread->vmdata;
336 # elif defined(WITH_CLASSPATH_CLDC1_1)
337 thread = (threadobject *) this->vm_thread;
340 u = threads_thread_get_state(thread);
341 o = javastring_new(u);
343 return (java_lang_String *) o;
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