1 /* src/native/vm/gnu/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.h"
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 java_lang_Thread *thread;
94 LLNI_field_get_ref(this, thread, thread);
96 log_println("Java_java_lang_VMThread_countStackFrames: IMPLEMENT ME!");
103 * Class: java/lang/VMThread
107 JNIEXPORT void JNICALL Java_java_lang_VMThread_start(JNIEnv *env, java_lang_VMThread *this, int64_t stacksize)
109 java_lang_Thread *thread;
111 LLNI_field_get_ref(this, thread, thread);
113 #if defined(ENABLE_THREADS)
114 threads_thread_start((java_handle_t *) thread);
120 * Class: java/lang/VMThread
124 JNIEXPORT void JNICALL Java_java_lang_VMThread_interrupt(JNIEnv *env, java_lang_VMThread *this)
126 #if defined(ENABLE_THREADS)
130 h = (java_handle_t *) this;
131 t = thread_get_thread(h);
133 threads_thread_interrupt(t);
139 * Class: java/lang/VMThread
140 * Method: isInterrupted
143 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_isInterrupted(JNIEnv *env, java_lang_VMThread *this)
145 #if defined(ENABLE_THREADS)
149 h = (java_handle_t *) this;
150 t = thread_get_thread(h);
152 return thread_is_interrupted(t);
160 * Class: java/lang/VMThread
164 JNIEXPORT void JNICALL Java_java_lang_VMThread_suspend(JNIEnv *env, java_lang_VMThread *this)
166 #if defined(ENABLE_THREADS)
167 /* TODO Should we implement this or is it obsolete? */
173 * Class: java/lang/VMThread
177 JNIEXPORT void JNICALL Java_java_lang_VMThread_resume(JNIEnv *env, java_lang_VMThread *this)
179 #if defined(ENABLE_THREADS)
180 /* TODO Should we implement this or is it obsolete? */
186 * Class: java/lang/VMThread
187 * Method: nativeSetPriority
190 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeSetPriority(JNIEnv *env, java_lang_VMThread *this, int32_t priority)
192 #if defined(ENABLE_THREADS)
196 h = (java_handle_t *) this;
197 t = thread_get_thread(h);
199 threads_set_thread_priority(t->tid, priority);
205 * Class: java/lang/VMThread
207 * Signature: (Ljava/lang/Throwable;)V
209 JNIEXPORT void JNICALL Java_java_lang_VMThread_nativeStop(JNIEnv *env, java_lang_VMThread *this, java_lang_Throwable *t)
211 #if defined(ENABLE_THREADS)
212 /* TODO Should we implement this or is it obsolete? */
218 * Class: java/lang/VMThread
219 * Method: currentThread
220 * Signature: ()Ljava/lang/Thread;
222 JNIEXPORT java_lang_Thread* JNICALL Java_java_lang_VMThread_currentThread(JNIEnv *env, jclass clazz)
224 java_lang_Thread *to;
226 to = (java_lang_Thread *) thread_get_current_object();
233 * Class: java/lang/VMThread
237 JNIEXPORT void JNICALL Java_java_lang_VMThread_yield(JNIEnv *env, jclass clazz)
239 #if defined(ENABLE_THREADS)
246 * Class: java/lang/VMThread
247 * Method: interrupted
250 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_interrupted(JNIEnv *env, jclass clazz)
252 #if defined(ENABLE_THREADS)
256 t = thread_get_current();
258 interrupted = thread_is_interrupted(t);
261 thread_set_interrupted(t, false);
271 * Class: java/lang/VMThread
273 * Signature: (Ljava/lang/Object;)Z
275 JNIEXPORT int32_t JNICALL Java_java_lang_VMThread_holdsLock(JNIEnv *env, jclass clazz, java_lang_Object* o)
277 #if defined(ENABLE_THREADS)
280 h = (java_handle_t *) o;
283 exceptions_throw_nullpointerexception();
287 return lock_is_held_by_current_thread(h);
295 * Class: java/lang/VMThread
297 * Signature: ()Ljava/lang/String;
299 JNIEXPORT java_lang_String* JNICALL Java_java_lang_VMThread_getState(JNIEnv *env, java_lang_VMThread *this)
301 #if defined(ENABLE_THREADS)
308 h = (java_handle_t *) this;
309 t = thread_get_thread(h);
311 state = cacaothread_get_state(t);
314 case THREAD_STATE_NEW:
315 u = utf_new_char("NEW");
317 case THREAD_STATE_RUNNABLE:
318 u = utf_new_char("RUNNABLE");
320 case THREAD_STATE_BLOCKED:
321 u = utf_new_char("BLOCKED");
323 case THREAD_STATE_WAITING:
324 u = utf_new_char("WAITING");
326 case THREAD_STATE_TIMED_WAITING:
327 u = utf_new_char("TIMED_WAITING");
329 case THREAD_STATE_TERMINATED:
330 u = utf_new_char("TERMINATED");
333 vm_abort("Java_java_lang_VMThread_getState: unknown thread state %d", state);
335 /* Keep compiler happy. */
340 o = javastring_new(u);
342 return (java_lang_String *) o;
350 * These are local overrides for various environment variables in Emacs.
351 * Please do not remove this and leave it at the end of the file, where
352 * Emacs will automagically detect them.
353 * ---------------------------------------------------------------------
356 * indent-tabs-mode: t