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 #if defined(ENABLE_JAVASE)
37 # include "native/include/java_lang_ThreadGroup.h"
40 #include "native/include/java_lang_String.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_Thread.h"
45 #if defined(ENABLE_THREADS)
46 # include "threads/native/threads.h"
49 #include "toolbox/logging.h"
51 #include "vm/builtin.h"
52 #include "vm/exceptions.h"
54 #include "vmcore/options.h"
56 /* XXX REMOVE ME only for vm_abort */
61 * Class: java/lang/Thread
62 * Method: countStackFrames
65 s4 _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this)
67 log_text("java_lang_Thread_countStackFrames called");
74 * Class: java/lang/Thread
78 void _Jv_java_lang_Thread_sleep(s8 millis)
80 #if defined(ENABLE_THREADS)
81 threads_sleep(millis, 0);
87 * Class: java/lang/Thread
91 void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
93 #if defined(ENABLE_THREADS)
96 thread = (threadobject *) this;
98 /* don't pass a function pointer (NULL) since we want Thread.run()V here */
100 threads_start_thread(thread, NULL);
106 * Class: java/lang/Thread
110 void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
112 #if defined(ENABLE_THREADS)
113 threadobject *thread;
115 thread = (threadobject *) this;
117 threads_thread_interrupt(thread);
123 * Class: java/lang/Thread
124 * Method: isInterrupted
127 s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
129 #if defined(ENABLE_THREADS)
130 threadobject *thread;
132 thread = (threadobject *) this;
134 return threads_thread_has_been_interrupted(thread);
142 * Class: java/lang/Thread
146 void _Jv_java_lang_Thread_suspend(java_lang_Thread *this)
148 #if defined(ENABLE_THREADS)
154 * Class: java/lang/Thread
158 void _Jv_java_lang_Thread_resume(java_lang_Thread *this)
160 #if defined(ENABLE_THREADS)
166 * Class: java/lang/Thread
167 * Method: setPriority
170 void _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority)
172 #if defined(ENABLE_THREADS)
173 threadobject *thread;
175 thread = (threadobject *) this;
177 threads_set_thread_priority(thread->tid, priority);
183 * Class: java/lang/Thread
185 * Signature: (Ljava/lang/Object;)V
187 void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t)
189 #if defined(ENABLE_THREADS)
195 * Class: java/lang/Thread
196 * Method: currentThread
197 * Signature: ()Ljava/lang/Thread;
199 java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
201 #if defined(ENABLE_THREADS)
202 threadobject *thread;
206 #if defined(ENABLE_THREADS)
207 thread = THREADOBJECT;
209 t = (java_lang_Thread *) thread;
212 log_text("t ptr is NULL\n");
214 # if defined(ENABLE_JAVASE)
215 if (t->group == NULL) {
216 /* ThreadGroup of currentThread is not initialized */
218 t->group = (java_lang_ThreadGroup *)
219 native_new_and_init(class_java_lang_ThreadGroup);
221 if (t->group == NULL)
222 log_text("unable to create ThreadGroup");
226 /* we just return a fake java.lang.Thread object, otherwise we get
227 NullPointerException's in GNU classpath */
229 t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
237 * Class: java/lang/Thread
241 void _Jv_java_lang_Thread_yield(void)
243 #if defined(ENABLE_THREADS)
250 * Class: java/lang/Thread
251 * Method: interrupted
254 s4 _Jv_java_lang_Thread_interrupted(void)
256 #if defined(ENABLE_THREADS)
257 return threads_check_if_interrupted_and_reset();
265 * Class: java/lang/Thread
267 * Signature: (Ljava/lang/Object;)Z
269 s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
271 #if defined(ENABLE_THREADS)
272 java_objectheader *o;
274 o = (java_objectheader *) obj;
277 exceptions_throw_nullpointerexception();
281 return lock_is_held_by_current_thread(o);
289 * Class: java/lang/Thread
291 * Signature: ()Ljava/lang/String;
293 java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
295 vm_abort("Java_java_lang_Thread_getState: IMPLEMENT ME!");
302 * These are local overrides for various environment variables in Emacs.
303 * Please do not remove this and leave it at the end of the file, where
304 * Emacs will automagically detect them.
305 * ---------------------------------------------------------------------
308 * indent-tabs-mode: t