1 /* src/native/vm/gnuclasspath/java_lang_VMThread.cpp
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "native/jni.h"
31 #include "native/llni.h"
32 #include "native/native.h"
34 #include "native/include/java_lang_ThreadGroup.h"
35 #include "native/include/java_lang_Object.h" /* java_lang_Thread.h */
36 #include "native/include/java_lang_Throwable.h" /* java_lang_Thread.h */
40 #include "native/include/java_lang_VMThread.h"
43 #include "native/include/java_lang_String.h"
44 #include "native/include/java_lang_Thread.h"
46 #include "threads/lock-common.h"
47 #include "threads/thread.hpp"
49 #include "vm/exceptions.hpp"
50 #include "vm/string.hpp"
52 #include "vmcore/utf8.h"
55 // Native functions are exported as C functions.
59 * Class: java/lang/VMThread
60 * Method: countStackFrames
63 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *_this)
65 log_println("Java_java_lang_VMThread_countStackFrames: Deprecated. Not implemented.");
72 * Class: java/lang/VMThread
76 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *_this, int64_t stacksize)
78 java_lang_Thread *thread;
80 LLNI_field_get_ref(_this, thread, thread);
82 #if defined(ENABLE_THREADS)
83 threads_thread_start((java_handle_t *) thread);
89 * Class: java/lang/VMThread
93 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *_this)
95 #if defined(ENABLE_THREADS)
99 h = (java_handle_t *) _this;
100 t = thread_get_thread(h);
102 threads_thread_interrupt(t);
108 * Class: java/lang/VMThread
109 * Method: isInterrupted
112 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *_this)
114 #if defined(ENABLE_THREADS)
118 h = (java_handle_t *) _this;
119 t = thread_get_thread(h);
121 return thread_is_interrupted(t);
129 * Class: java/lang/VMThread
133 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *_this)
135 #if defined(ENABLE_THREADS)
136 log_println("Java_java_lang_VMThread_suspend: Deprecated. Not implemented.");
142 * Class: java/lang/VMThread
146 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *_this)
148 #if defined(ENABLE_THREADS)
149 log_println("Java_java_lang_VMThread_resume: Deprecated. Not implemented.");
155 * Class: java/lang/VMThread
156 * Method: nativeSetPriority
159 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *_this, int32_t priority)
161 #if defined(ENABLE_THREADS)
165 h = (java_handle_t *) _this;
166 t = thread_get_thread(h);
168 threads_set_thread_priority(t->tid, priority);
174 * Class: java/lang/VMThread
176 * Signature: (Ljava/lang/Throwable;)V
178 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *_this, java_lang_Throwable *t)
180 #if defined(ENABLE_THREADS)
181 log_println("Java_java_lang_VMThread_nativeStop: Deprecated. Not implemented.");
187 * Class: java/lang/VMThread
188 * Method: currentThread
189 * Signature: ()Ljava/lang/Thread;
191 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
193 java_lang_Thread *to;
195 to = (java_lang_Thread *) thread_get_current_object();
202 * Class: java/lang/VMThread
206 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
208 #if defined(ENABLE_THREADS)
215 * Class: java/lang/VMThread
219 JNIEXPORT void JNICALL Java_java_lang_VMThread_sleep(JNIEnv *env, jclass clazz, int64_t ms, int32_t ns)
221 #if defined(ENABLE_THREADS)
222 threads_sleep(ms, ns);
228 * Class: java/lang/VMThread
229 * Method: interrupted
232 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
234 #if defined(ENABLE_THREADS)
238 t = thread_get_current();
240 interrupted = thread_is_interrupted(t);
243 thread_set_interrupted(t, false);
253 * Class: java/lang/VMThread
255 * Signature: (Ljava/lang/Object;)Z
257 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
259 #if defined(ENABLE_THREADS)
262 h = (java_handle_t *) o;
265 exceptions_throw_nullpointerexception();
269 return lock_is_held_by_current_thread(h);
277 * Class: java/lang/VMThread
279 * Signature: ()Ljava/lang/String;
281 JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *_this)
283 #if defined(ENABLE_THREADS)
290 h = (java_handle_t *) _this;
291 t = thread_get_thread(h);
293 state = cacaothread_get_state(t);
296 case THREAD_STATE_NEW:
297 u = utf_new_char("NEW");
299 case THREAD_STATE_RUNNABLE:
300 u = utf_new_char("RUNNABLE");
302 case THREAD_STATE_BLOCKED:
303 u = utf_new_char("BLOCKED");
305 case THREAD_STATE_WAITING:
306 u = utf_new_char("WAITING");
308 case THREAD_STATE_TIMED_WAITING:
309 u = utf_new_char("TIMED_WAITING");
311 case THREAD_STATE_TERMINATED:
312 u = utf_new_char("TERMINATED");
315 vm_abort("Java_java_lang_VMThread_getState: unknown thread state %d", state);
317 /* Keep compiler happy. */
322 o = javastring_new(u);
324 return (java_lang_String *) o;
333 /* native methods implemented by this file ************************************/
335 static JNINativeMethod methods[] = {
336 { (char*) "countStackFrames", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_VMThread_countStackFrames },
337 { (char*) "start", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_VMThread_start },
338 { (char*) "interrupt", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_interrupt },
339 { (char*) "isInterrupted", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_VMThread_isInterrupted },
340 { (char*) "suspend", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_suspend },
341 { (char*) "resume", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_resume },
342 { (char*) "nativeSetPriority", (char*) "(I)V", (void*) (uintptr_t) &Java_java_lang_VMThread_nativeSetPriority },
343 { (char*) "nativeStop", (char*) "(Ljava/lang/Throwable;)V", (void*) (uintptr_t) &Java_java_lang_VMThread_nativeStop },
344 { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_VMThread_currentThread },
345 { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_VMThread_yield },
346 { (char*) "sleep", (char*) "(JI)V", (void*) (uintptr_t) &Java_java_lang_VMThread_sleep },
347 { (char*) "interrupted", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_VMThread_interrupted },
348 { (char*) "holdsLock", (char*) "(Ljava/lang/Object;)Z", (void*) (uintptr_t) &Java_java_lang_VMThread_holdsLock },
349 { (char*) "getState", (char*) "()Ljava/lang/String;", (void*) (uintptr_t) &Java_java_lang_VMThread_getState },
353 /* _Jv_java_lang_VMThread_init *************************************************
355 Register native functions.
357 *******************************************************************************/
361 void _Jv_java_lang_VMThread_init(void)
365 u = utf_new_char("java/lang/VMThread");
367 native_method_register(u, methods, NATIVE_METHODS_COUNT);
373 * These are local overrides for various environment variables in Emacs.
374 * Please do not remove this and leave it at the end of the file, where
375 * Emacs will automagically detect them.
376 * ---------------------------------------------------------------------
379 * indent-tabs-mode: t