1 /* src/native/vm/cldc1.1/java_lang_Thread.cpp
3 Copyright (C) 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.hpp"
31 #include "native/native.hpp"
33 #if defined(ENABLE_JNI_HEADERS)
34 # include "native/include/java_lang_Thread.h"
37 #include "threads/thread.hpp"
38 #include "threads/threadlist.hpp"
40 #include "toolbox/logging.hpp"
42 #include "vm/jit/builtin.hpp"
43 #include "vm/javaobjects.hpp"
46 // Native functions are exported as C functions.
50 * Class: java/lang/Thread
51 * Method: currentThread
52 * Signature: ()Ljava/lang/Thread;
54 JNIEXPORT jobject JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
56 return (jobject) thread_get_current_object();
61 * Class: java/lang/Thread
62 * Method: setPriority0
65 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, jobject _this, jint oldPriority, jint newPriority)
67 #if defined(ENABLE_THREADS)
68 java_lang_Thread jlt(_this);
69 threadobject* t = jlt.get_vm_thread();
71 // The threadobject is null when a thread is created in Java. The
72 // priority is set later during startup.
76 threads_set_thread_priority(t->tid, newPriority);
82 * Class: java/lang/Thread
86 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, jlong millis)
88 #if defined(ENABLE_THREADS)
89 threads_sleep(millis, 0);
95 * Class: java/lang/Thread
99 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, jobject _this)
101 #if defined(ENABLE_THREADS)
102 java_lang_Thread jlt(_this);
103 threads_thread_start(jlt.get_handle());
109 * Class: java/lang/Thread
113 JNIEXPORT jboolean JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, jobject _this)
115 #if defined(ENABLE_THREADS)
116 java_lang_Thread jlt(_this);
117 threadobject* t = jlt.get_vm_thread();
122 bool result = threads_thread_is_alive(t);
126 // If threads are disabled, the only thread running is alive.
133 * Class: java/lang/Thread
134 * Method: activeCount
137 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
139 #if defined(ENABLE_THREADS)
140 return ThreadList::get_number_of_non_daemon_threads();
148 * Class: java/lang/Thread
152 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, jobject _this)
154 #if defined(ENABLE_THREADS)
155 java_lang_Thread jlt(_this);
156 threadobject* t = jlt.get_vm_thread();
157 threads_thread_interrupt(t);
163 * Class: java/lang/Thread
164 * Method: internalExit
167 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, jobject _this)
174 * Class: java/lang/Thread
178 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
180 #if defined(ENABLE_THREADS)
188 /* native methods implemented by this file ************************************/
190 static JNINativeMethod methods[] = {
191 { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
192 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
193 { (char*) "sleep", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_Thread_sleep },
194 { (char*) "start0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_start0 },
195 { (char*) "isAlive", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Thread_isAlive },
196 { (char*) "activeCount", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_Thread_activeCount },
197 { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
198 { (char*) "interrupt0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0 },
200 { (char*) "internalExit", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_internalExit },
202 { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_yield },
206 /* _Jv_java_lang_Thread_init ***************************************************
208 Register native functions.
210 *******************************************************************************/
212 void _Jv_java_lang_Thread_init(void)
214 utf* u = utf_new_char("java/lang/Thread");
216 NativeMethods& nm = VM::get_current()->get_nativemethods();
217 nm.register_methods(u, methods, NATIVE_METHODS_COUNT);
222 * These are local overrides for various environment variables in Emacs.
223 * Please do not remove this and leave it at the end of the file, where
224 * Emacs will automagically detect them.
225 * ---------------------------------------------------------------------
228 * indent-tabs-mode: t
232 * vim:noexpandtab:sw=4:ts=4: