better reflection code
[cacao.git] / src / native / vm / VMThread.c
1 /* class: java/lang/Thread */
2
3 /*
4  * Class:     java/lang/Thread
5  * Method:    countStackFrames
6  * Signature: ()I
7  */
8 JNIEXPORT s4 JNICALL Java_java_lang_Thread_countStackFrames ( JNIEnv *env ,  struct java_lang_Thread* this)
9 {
10     log_text ("java_lang_Thread_countStackFrames called");
11     return 0;         /* not yet implemented */
12 }
13
14 /*
15  * Class:     java/lang/Thread
16  * Method:    currentThread
17  * Signature: ()Ljava/lang/Thread;
18  */
19 JNIEXPORT struct java_lang_Thread* JNICALL Java_java_lang_Thread_currentThread ( JNIEnv *env ,jclass clazz )
20 {
21   struct java_lang_Thread* t;
22
23   if (runverbose)
24     log_text ("java_lang_Thread_currentThread called");
25
26
27   #ifdef USE_THREADS
28
29          t = (struct java_lang_Thread*) currentThread; 
30   
31          if (!t->group) {
32                 log_text("java_lang_Thread_currentThread: t->group=NULL");
33                 /* ThreadGroup of currentThread is not initialized */
34
35                 t->group = (java_lang_ThreadGroup *) 
36                         native_new_and_init(loader_load(utf_new_char("java/lang/ThreadGroup")));
37
38                 if (t->group == 0) 
39                         log_text("unable to create ThreadGroup");
40         }
41
42         return (struct java_lang_Thread*) currentThread;
43   #else
44         return 0;       
45   #endif
46 }
47
48 /*
49  * Class:     java/lang/Thread
50  * Method:    nativeInterrupt
51  * Signature: ()V
52  */
53 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInterrupt ( JNIEnv *env ,  struct java_lang_Thread* this)
54 {
55   log_text("Java_java_lang_Thread_interrupt0  called");
56   /* not yet implemented */
57 }
58
59 /*
60  * Class:     java/lang/Thread
61  * Method:    isAlive
62  * Signature: ()Z
63  */
64 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isAlive ( JNIEnv *env ,  struct java_lang_Thread* this)
65 {
66     if (runverbose)
67         log_text ("java_lang_Thread_isAlive called");
68
69 #ifdef USE_THREADS
70     return aliveThread((thread*)this);
71 #else
72     return 0;
73 #endif
74 }
75
76
77
78 /*
79  * Class:     java_lang_Thread
80  * Method:    isInterrupted
81  * Signature: ()Z
82  */
83 JNIEXPORT s4 JNICALL Java_java_lang_Thread_isInterrupted (JNIEnv *env ,  struct java_lang_Thread* this )
84 {
85     log_text("Java_java_lang_Thread_isInterrupted  called");
86     return 0;                   /* not yet implemented */
87 }
88
89 /*
90  * Class:     java/lang/Thread
91  * Method:    registerNatives
92  * Signature: ()V
93  */
94 JNIEXPORT void JNICALL Java_java_lang_Thread_registerNatives ( JNIEnv *env ,jclass clazz )
95 {
96   /* empty */
97 }
98
99 /*
100  * Class:     java/lang/Thread
101  * Method:    resume0
102  * Signature: ()V
103  */
104 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeResume ( JNIEnv *env ,  struct java_lang_Thread* this)
105 {
106     if (runverbose)
107         log_text ("java_lang_Thread_resume0 called");
108
109 #ifdef USE_THREADS
110     resumeThread((thread*)this);
111 #endif
112 }
113
114 /*
115  * Class:     java/lang/Thread
116  * Method:    setPriority0
117  * Signature: (I)V
118  */
119 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSetPriority ( JNIEnv *env ,  struct java_lang_Thread* this, s4 par1)
120 {
121     if (runverbose) 
122         log_text ("java_lang_Thread_setPriority0 called");
123
124 #ifdef USE_THREADS
125     setPriorityThread((thread*)this, par1);
126 #endif
127 }
128
129
130 /*
131  * Class:     java_lang_Thread
132  * Method:    sleep
133  * Signature: (JI)V
134  */
135 JNIEXPORT void JNICALL Java_java_lang_Thread_sleep (JNIEnv *env , jclass clazz, s8 millis, s4 par2)
136 {
137     if (runverbose)
138         log_text ("java_lang_Thread_sleep called");
139
140 #ifdef USE_THREADS
141     sleepThread(millis);
142 #endif
143 }
144
145 /*
146  * Class:     java/lang/Thread
147  * Method:    start
148  * Signature: ()V
149  */
150 JNIEXPORT void JNICALL Java_java_lang_Thread_start ( JNIEnv *env ,  struct java_lang_Thread* this)
151 {
152   if (runverbose) 
153     log_text ("java_lang_Thread_start called");
154     /*printf("THREAD PRIORITY: %d\n",this->priority);*/
155
156   #ifdef USE_THREADS
157         startThread((thread*)this);
158   #endif
159 }
160
161 /*
162  * Class:     java/lang/Thread
163  * Method:    stop0
164  * Signature: (Ljava/lang/Object;)V
165  */
166 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeStop ( JNIEnv *env ,  struct java_lang_Thread* this, struct java_lang_Throwable* par1)
167 {
168   if (runverbose)
169     log_text ("java_lang_Thread_stop0 called");
170
171
172   #ifdef USE_THREADS
173         if (currentThread == (thread*)this)
174         {
175             log_text("killing");
176             killThread(0);
177             /*
178                 exceptionptr = proto_java_lang_ThreadDeath;
179                 return;
180             */
181         }
182         else
183         {
184                 CONTEXT((thread*)this).flags |= THREAD_FLAGS_KILLED;
185                 resumeThread((thread*)this);
186         }
187    #endif
188 }
189
190 /*
191  * Class:     java/lang/Thread
192  * Method:    suspend0
193  * Signature: ()V
194  */
195 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeSuspend ( JNIEnv *env ,  struct java_lang_Thread* this)
196 {
197   if (runverbose)
198     log_text ("java_lang_Thread_suspend0 called");
199
200   #ifdef USE_THREADS
201         suspendThread((thread*)this);
202   #endif
203
204 }
205
206 /*
207  * Class:     java/lang/Thread
208  * Method:    yield
209  * Signature: ()V
210  */
211 JNIEXPORT void JNICALL Java_java_lang_Thread_yield ( JNIEnv *env  ,jclass clazz)
212 {
213   if (runverbose)
214     log_text ("java_lang_Thread_yield called");
215   #ifdef USE_THREADS
216         yieldThread();
217   #endif
218 }
219
220 /*
221  * Class:     java_lang_Thread
222  * Method:    interrupted
223  * Signature: ()Z
224  */
225 JNIEXPORT s4 JNICALL Java_java_lang_Thread_interrupted (JNIEnv *env ,jclass clazz) {
226         log_text("Java_java_lang_Thread_interrupted");
227         return 0;
228 }
229 /*
230  * Class:     java_lang_Thread
231  * Method:    nativeInit
232  * Signature: (J)V
233  */
234 JNIEXPORT void JNICALL Java_java_lang_Thread_nativeInit (JNIEnv *env ,  struct java_lang_Thread* this , s8 par1) {
235         log_text("Thread_nativeInit");
236         if (exceptionptr) log_text("There has been an exception, strange...");
237         this->priority=5;
238 }
239
240 /*
241  * Class:     java_lang_Thread
242  * Method:    holdsLock
243  * Signature: (Ljava/lang/Object;)Z
244  */
245 JNIEXPORT s4 JNICALL Java_java_lang_Thread_holdsLock (JNIEnv *env , jclass clazz, struct java_lang_Object* par1)
246 {
247 }