1 /* src/native/vm/java_lang_Thread.c - java/lang/Thread functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Roman Obermaiser
31 $Id: java_lang_VMThread.c 6213 2006-12-18 17:36:06Z twisti $
39 #include "native/jni.h"
40 #include "native/native.h"
41 #include "native/include/java_lang_ThreadGroup.h"
42 #include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
43 #include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
44 #include "native/include/java_lang_Thread.h"
46 #if defined(ENABLE_THREADS)
47 # include "threads/native/threads.h"
50 #include "toolbox/logging.h"
51 #include "vm/options.h"
55 * Class: java/lang/Thread
56 * Method: countStackFrames
59 s4 _Jv_java_lang_Thread_countStackFrames(java_lang_Thread *this)
61 log_text("java_lang_Thread_countStackFrames called");
68 * Class: java/lang/Thread
72 void _Jv_java_lang_Thread_start(java_lang_Thread *this, s8 stacksize)
74 #if defined(ENABLE_THREADS)
77 thread = (threadobject *) this;
79 /* don't pass a function pointer (NULL) since we want Thread.run()V here */
81 threads_start_thread(thread, NULL);
87 * Class: java/lang/Thread
91 void _Jv_java_lang_Thread_interrupt(java_lang_Thread *this)
93 #if defined(ENABLE_THREADS)
96 thread = (threadobject *) this;
98 threads_thread_interrupt(thread);
104 * Class: java/lang/Thread
105 * Method: isInterrupted
108 s4 _Jv_java_lang_Thread_isInterrupted(java_lang_Thread *this)
110 #if defined(ENABLE_THREADS)
111 threadobject *thread;
113 thread = (threadobject *) this;
115 return threads_thread_has_been_interrupted(thread);
121 * Class: java/lang/Thread
125 void _Jv_java_lang_Thread_suspend(java_lang_Thread *this)
127 #if defined(ENABLE_THREADS)
133 * Class: java/lang/Thread
137 void _Jv_java_lang_Thread_resume(java_lang_Thread *this)
139 #if defined(ENABLE_THREADS)
145 * Class: java/lang/Thread
146 * Method: setPriority
149 void _Jv_java_lang_Thread_setPriority(java_lang_Thread *this, s4 priority)
151 #if defined(ENABLE_THREADS)
152 threadobject *thread;
154 thread = (threadobject *) this;
156 threads_set_thread_priority(thread->tid, priority);
162 * Class: java/lang/Thread
164 * Signature: (Ljava/lang/Object;)V
166 void _Jv_java_lang_Thread_stop(java_lang_Thread *this, java_lang_Throwable *t)
168 #if defined(ENABLE_THREADS)
174 * Class: java/lang/Thread
175 * Method: currentThread
176 * Signature: ()Ljava/lang/Thread;
178 java_lang_Thread *_Jv_java_lang_Thread_currentThread(void)
180 threadobject *thread;
183 #if defined(ENABLE_THREADS)
184 thread = THREADOBJECT;
186 t = (java_lang_Thread *) thread;
189 log_text("t ptr is NULL\n");
191 if (t->group == NULL) {
192 /* ThreadGroup of currentThread is not initialized */
194 t->group = (java_lang_ThreadGroup *)
195 native_new_and_init(class_java_lang_ThreadGroup);
197 if (t->group == NULL)
198 log_text("unable to create ThreadGroup");
201 /* we just return a fake java.lang.Thread object, otherwise we get
202 NullPointerException's in GNU classpath */
204 t = (java_lang_Thread *) builtin_new(class_java_lang_Thread);
212 * Class: java/lang/Thread
216 void _Jv_java_lang_Thread_yield(void)
218 #if defined(ENABLE_THREADS)
225 * Class: java/lang/Thread
226 * Method: interrupted
229 s4 _Jv_java_lang_Thread_interrupted(void)
231 #if defined(ENABLE_THREADS)
232 return threads_check_if_interrupted_and_reset();
238 * Class: java/lang/Thread
240 * Signature: (Ljava/lang/Object;)Z
242 s4 _Jv_java_lang_Thread_holdsLock(java_lang_Object* obj)
244 #if defined(ENABLE_THREADS)
245 java_objectheader *o;
247 o = (java_objectheader *) obj;
250 exceptions_throw_nullpointerexception();
254 return lock_is_held_by_current_thread(o);
260 * Class: java/lang/Thread
262 * Signature: ()Ljava/lang/String;
264 java_lang_String *_Jv_java_lang_Thread_getState(java_lang_Thread *this)
266 vm_abort("Java_java_lang_Thread_getState: IMPLEMENT ME!");
273 * These are local overrides for various environment variables in Emacs.
274 * Please do not remove this and leave it at the end of the file, where
275 * Emacs will automagically detect them.
276 * ---------------------------------------------------------------------
279 * indent-tabs-mode: t