CACAO
java_lang_Thread.cpp
Go to the documentation of this file.
1 /* src/native/vm/cldc1.1/java_lang_Thread.cpp
2 
3  Copyright (C) 1996-2013
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 
26 #include "config.h"
27 
28 #include <stdint.h>
29 
30 #include "native/jni.hpp"
31 #include "native/native.hpp"
32 
33 #if defined(ENABLE_JNI_HEADERS)
34 # include "native/include/java_lang_Thread.h"
35 #endif
36 
37 #include "threads/thread.hpp"
38 #include "threads/threadlist.hpp"
39 
40 #include "toolbox/logging.hpp"
41 
42 #include "vm/jit/builtin.hpp"
43 #include "vm/javaobjects.hpp"
44 
45 
46 // Native functions are exported as C functions.
47 extern "C" {
48 
49 /*
50  * Class: java/lang/Thread
51  * Method: currentThread
52  * Signature: ()Ljava/lang/Thread;
53  */
55 {
57 }
58 
59 
60 /*
61  * Class: java/lang/Thread
62  * Method: setPriority0
63  * Signature: (II)V
64  */
65 JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, jobject _this, jint oldPriority, jint newPriority)
66 {
67  java_lang_Thread jlt(_this);
68  threadobject *t = jlt.get_vm_thread();
69 
70  // The threadobject is null when a thread is created in Java. The
71  // priority is set later during startup.
72  if (t == NULL)
73  return;
74 
75  threads_set_thread_priority(t, newPriority);
76 }
77 
78 
79 /*
80  * Class: java/lang/Thread
81  * Method: sleep
82  * Signature: (J)V
83  */
84 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, jlong millis)
85 {
86  threads_sleep(millis, 0);
87 }
88 
89 
90 /*
91  * Class: java/lang/Thread
92  * Method: start0
93  * Signature: ()V
94  */
95 JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, jobject _this)
96 {
97  java_lang_Thread jlt(_this);
99 }
100 
101 
102 /*
103  * Class: java/lang/Thread
104  * Method: isAlive
105  * Signature: ()Z
106  */
107 JNIEXPORT jboolean JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, jobject _this)
108 {
109  java_lang_Thread jlt(_this);
110  threadobject *t = jlt.get_vm_thread();
111 
112  if (t == NULL)
113  return 0;
114 
115  return threads_thread_is_alive(t);
116 }
117 
118 
119 /*
120  * Class: java/lang/Thread
121  * Method: activeCount
122  * Signature: ()I
123  */
124 JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
125 {
127 }
128 
129 
130 /*
131  * Class: java/lang/Thread
132  * Method: interrupt0
133  * Signature: ()V
134  */
135 JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, jobject _this)
136 {
137  java_lang_Thread jlt(_this);
138  threadobject *t = jlt.get_vm_thread();
139 
141 }
142 
143 #if 0
144 /*
145  * Class: java/lang/Thread
146  * Method: internalExit
147  * Signature: ()V
148  */
149 JNIEXPORT void JNICALL Java_java_lang_Thread_internalExit(JNIEnv *env, jobject _this)
150 {
151 }
152 #endif
153 
154 
155 /*
156  * Class: java/lang/Thread
157  * Method: yield
158  * Signature: ()V
159  */
160 JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
161 {
162  threads_yield();
163 }
164 
165 } // extern "C"
166 
167 
168 /* native methods implemented by this file ************************************/
169 
170 static JNINativeMethod methods[] = {
171  { (char*) "currentThread", (char*) "()Ljava/lang/Thread;", (void*) (uintptr_t) &Java_java_lang_Thread_currentThread },
172  { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
173  { (char*) "sleep", (char*) "(J)V", (void*) (uintptr_t) &Java_java_lang_Thread_sleep },
174  { (char*) "start0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_start0 },
175  { (char*) "isAlive", (char*) "()Z", (void*) (uintptr_t) &Java_java_lang_Thread_isAlive },
176  { (char*) "activeCount", (char*) "()I", (void*) (uintptr_t) &Java_java_lang_Thread_activeCount },
177  { (char*) "setPriority0", (char*) "(II)V", (void*) (uintptr_t) &Java_java_lang_Thread_setPriority0 },
178  { (char*) "interrupt0", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_interrupt0 },
179 #if 0
180  { (char*) "internalExit", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_internalExit },
181 #endif
182  { (char*) "yield", (char*) "()V", (void*) (uintptr_t) &Java_java_lang_Thread_yield },
183 };
184 
185 
186 /* _Jv_java_lang_Thread_init ***************************************************
187 
188  Register native functions.
189 
190 *******************************************************************************/
191 
193 {
194  Utf8String u = Utf8String::from_utf8("java/lang/Thread");
195 
198 }
199 
200 
201 /*
202  * These are local overrides for various environment variables in Emacs.
203  * Please do not remove this and leave it at the end of the file, where
204  * Emacs will automagically detect them.
205  * ---------------------------------------------------------------------
206  * Local variables:
207  * mode: c++
208  * indent-tabs-mode: t
209  * c-basic-offset: 4
210  * tab-width: 4
211  * End:
212  * vim:noexpandtab:sw=4:ts=4:
213  */
static JNINativeMethod methods[]
virtual java_handle_t * get_handle() const
void threads_thread_interrupt(threadobject *t)
Table containing all native methods registered with the VM.
Definition: native.hpp:132
NativeMethods & get_nativemethods()
Definition: vm.hpp:128
void register_methods(Utf8String classname, const JNINativeMethod *methods, size_t count)
Register native methods with the VM.
Definition: native.cpp:242
_Jv_JNIEnv JNIEnv
Definition: jni.hpp:112
#define NATIVE_METHODS_COUNT
Definition: native.hpp:45
static java_handle_t * thread_get_current_object(void)
Definition: thread.hpp:226
JNIEXPORT jobject JNICALL Java_java_lang_Thread_currentThread(JNIEnv *env, jclass clazz)
JNIEXPORT void JNICALL Java_java_lang_Thread_sleep(JNIEnv *env, jclass clazz, jlong millis)
JNIEXPORT void JNICALL Java_java_lang_Thread_yield(JNIEnv *env, jclass clazz)
int32_t get_number_of_non_daemon_threads()
Return the number of non-daemon threads.
Definition: threadlist.cpp:195
void threads_set_thread_priority(threadobject *t, int priority)
Definition: thread-none.cpp:77
void threads_thread_start(java_handle_t *object)
Definition: thread.cpp:445
static ThreadList * get()
Provides access to singleton.
Definition: threadlist.hpp:62
JNIEXPORT void JNICALL Java_java_lang_Thread_start0(JNIEnv *env, jobject _this)
JNIEXPORT s4 JNICALL Java_java_lang_Thread_activeCount(JNIEnv *env, jclass clazz)
static Utf8String from_utf8(const char *, size_t)
Definition: utf8.cpp:335
JNIEXPORT jboolean JNICALL Java_java_lang_Thread_isAlive(JNIEnv *env, jobject _this)
int32_t s4
Definition: types.hpp:45
JNIEXPORT void JNICALL Java_java_lang_Thread_setPriority0(JNIEnv *env, jobject _this, jint oldPriority, jint newPriority)
bool threads_thread_is_alive(threadobject *t)
Definition: thread.cpp:886
JNIEXPORT void JNICALL Java_java_lang_Thread_interrupt0(JNIEnv *env, jobject _this)
void _Jv_java_lang_Thread_init(void)
GNU Classpath java/lang/Thread.
void threads_sleep(int64_t millis, int32_t nanos)
void threads_yield(void)
static VM * get_current()
Definition: vm.hpp:99