1 /* src/native/vm/gnuclasspath/java_lang_VMThread.c
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 */
37 #include "native/include/java_lang_VMThread.h"
38 #include "native/include/java_lang_String.h"
39 #include "native/include/java_lang_Thread.h"
41 #include "threads/lock-common.h"
42 #include "threads/thread.hpp"
44 #include "vm/exceptions.h"
45 #include "vm/stringlocal.h"
47 #include "vmcore/utf8.h"
50 /* native methods implemented by this file ************************************/
52 static JNINativeMethod methods[] = {
53 { "countStackFrames", "()I", (void *) (intptr_t) &Java_java_lang_VMThread_countStackFrames },
54 { "start", "(J)V", (void *) (intptr_t) &Java_java_lang_VMThread_start },
55 { "interrupt", "()V", (void *) (intptr_t) &Java_java_lang_VMThread_interrupt },
56 { "isInterrupted", "()Z", (void *) (intptr_t) &Java_java_lang_VMThread_isInterrupted },
57 { "suspend", "()V", (void *) (intptr_t) &Java_java_lang_VMThread_suspend },
58 { "resume", "()V", (void *) (intptr_t) &Java_java_lang_VMThread_resume },
59 { "nativeSetPriority", "(I)V", (void *) (intptr_t) &Java_java_lang_VMThread_nativeSetPriority },
60 { "nativeStop", "(Ljava/lang/Throwable;)V", (void *) (intptr_t) &Java_java_lang_VMThread_nativeStop },
61 { "currentThread", "()Ljava/lang/Thread;", (void *) (intptr_t) &Java_java_lang_VMThread_currentThread },
62 { "yield", "()V", (void *) (intptr_t) &Java_java_lang_VMThread_yield },
63 { "interrupted", "()Z", (void *) (intptr_t) &Java_java_lang_VMThread_interrupted },
64 { "holdsLock", "(Ljava/lang/Object;)Z", (void *) (intptr_t) &Java_java_lang_VMThread_holdsLock },
65 { "getState", "()Ljava/lang/String;", (void *) (intptr_t) &Java_java_lang_VMThread_getState },
69 /* _Jv_java_lang_VMThread_init *************************************************
71 Register native functions.
73 *******************************************************************************/
75 void _Jv_java_lang_VMThread_init(void)
79 u = utf_new_char("java/lang/VMThread");
81 native_method_register(u, methods, NATIVE_METHODS_COUNT);
86 * Class: java/lang/VMThread
87 * Method: countStackFrames
90 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_countStackFrames(JNIEnv *env, java_lang_VMThread *this)
92 log_println("Java_java_lang_VMThread_countStackFrames: Deprecated. Not implemented.");
99 * Class: java/lang/VMThread
103 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, int64_t stacksize)
105 java_lang_Thread *thread;
107 LLNI_field_get_ref(this, thread, thread);
109 #if defined(ENABLE_THREADS)
110 threads_thread_start((java_handle_t *) thread);
116 * Class: java/lang/VMThread
120 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
122 #if defined(ENABLE_THREADS)
126 h = (java_handle_t *) this;
127 t = thread_get_thread(h);
129 threads_thread_interrupt(t);
135 * Class: java/lang/VMThread
136 * Method: isInterrupted
139 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
141 #if defined(ENABLE_THREADS)
145 h = (java_handle_t *) this;
146 t = thread_get_thread(h);
148 return thread_is_interrupted(t);
156 * Class: java/lang/VMThread
160 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
162 #if defined(ENABLE_THREADS)
163 log_println("Java_java_lang_VMThread_suspend: Deprecated. Not implemented.");
169 * Class: java/lang/VMThread
173 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
175 #if defined(ENABLE_THREADS)
176 log_println("Java_java_lang_VMThread_resume: Deprecated. Not implemented.");
182 * Class: java/lang/VMThread
183 * Method: nativeSetPriority
186 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, int32_t priority)
188 #if defined(ENABLE_THREADS)
192 h = (java_handle_t *) this;
193 t = thread_get_thread(h);
195 threads_set_thread_priority(t->tid, priority);
201 * Class: java/lang/VMThread
203 * Signature: (Ljava/lang/Throwable;)V
205 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
207 #if defined(ENABLE_THREADS)
208 log_println("Java_java_lang_VMThread_nativeStop: Deprecated. Not implemented.");
214 * Class: java/lang/VMThread
215 * Method: currentThread
216 * Signature: ()Ljava/lang/Thread;
218 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
220 java_lang_Thread *to;
222 to = (java_lang_Thread *) thread_get_current_object();
229 * Class: java/lang/VMThread
233 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
235 #if defined(ENABLE_THREADS)
242 * Class: java/lang/VMThread
243 * Method: interrupted
246 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
248 #if defined(ENABLE_THREADS)
252 t = thread_get_current();
254 interrupted = thread_is_interrupted(t);
257 thread_set_interrupted(t, false);
267 * Class: java/lang/VMThread
269 * Signature: (Ljava/lang/Object;)Z
271 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
273 #if defined(ENABLE_THREADS)
276 h = (java_handle_t *) o;
279 exceptions_throw_nullpointerexception();
283 return lock_is_held_by_current_thread(h);
291 * Class: java/lang/VMThread
293 * Signature: ()Ljava/lang/String;
295 JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *this)
297 #if defined(ENABLE_THREADS)
304 h = (java_handle_t *) this;
305 t = thread_get_thread(h);
307 state = cacaothread_get_state(t);
310 case THREAD_STATE_NEW:
311 u = utf_new_char("NEW");
313 case THREAD_STATE_RUNNABLE:
314 u = utf_new_char("RUNNABLE");
316 case THREAD_STATE_BLOCKED:
317 u = utf_new_char("BLOCKED");
319 case THREAD_STATE_WAITING:
320 u = utf_new_char("WAITING");
322 case THREAD_STATE_TIMED_WAITING:
323 u = utf_new_char("TIMED_WAITING");
325 case THREAD_STATE_TERMINATED:
326 u = utf_new_char("TERMINATED");
329 vm_abort("Java_java_lang_VMThread_getState: unknown thread state %d", state);
331 /* Keep compiler happy. */
336 o = javastring_new(u);
338 return (java_lang_String *) o;
346 * These are local overrides for various environment variables in Emacs.
347 * Please do not remove this and leave it at the end of the file, where
348 * Emacs will automagically detect them.
349 * ---------------------------------------------------------------------
352 * indent-tabs-mode: t