1 
2 #include "xmlvm.h"
3 #include "java_lang_Thread.h"
4 
5 
6 //XMLVM_BEGIN_NATIVE_IMPLEMENTATION
7 #include <pthread.h>
8 #ifdef __OBJC__
9 #import <Foundation/NSAutoreleasePool.h>
10 #endif
11 
12 
threadRunner(JAVA_OBJECT me)13 void threadRunner(JAVA_OBJECT me)
14 {
15     java_lang_Thread* thiz = me;
16     XMLVM_JMP_BUF xmlvm_exception_env;
17     JAVA_LONG nativeThreadId = (JAVA_LONG) pthread_self();
18 
19 #ifdef __OBJC__
20     NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
21 #endif
22 #ifdef XMLVM_ENABLE_STACK_TRACES
23     createStackForNewThread(nativeThreadId);
24 #endif
25 
26     if (XMLVM_SETJMP(xmlvm_exception_env)) {
27         // Technically, XMLVM_UNWIND_EXCEPTION() should be called, but
28         // exceptions will not be used anymore and XMLVM_ENTER_METHOD() wasn't
29         // called (excessive), so a compilation error would occur
30 
31         xmlvm_unhandled_exception();
32     } else {
33         thiz->fields.java_lang_Thread.xmlvmExceptionEnv_ = &xmlvm_exception_env;
34         java_lang_Thread_run0___long(thiz, nativeThreadId);
35     }
36 
37 #ifdef XMLVM_ENABLE_STACK_TRACES
38     destroyStackForExitingThread(nativeThreadId);
39 #endif
40 #ifdef __OBJC__
41     [pool release];
42 #endif
43 }
44 //XMLVM_END_NATIVE_IMPLEMENTATION
45 
java_lang_Thread_initMainThread__(JAVA_OBJECT me)46 void java_lang_Thread_initMainThread__(JAVA_OBJECT me)
47 {
48     //XMLVM_BEGIN_NATIVE[java_lang_Thread_initMainThread__]
49     ((java_lang_Thread*)me)->fields.java_lang_Thread.xmlvmExceptionEnv_ = xmlvm_exception_env_main_thread;
50     //XMLVM_END_NATIVE
51 }
52 
java_lang_Thread_activeCount__()53 JAVA_INT java_lang_Thread_activeCount__()
54 {
55     //XMLVM_BEGIN_NATIVE[java_lang_Thread_activeCount__]
56     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
57     //XMLVM_END_NATIVE
58 }
59 
java_lang_Thread_checkAccess__(JAVA_OBJECT me)60 void java_lang_Thread_checkAccess__(JAVA_OBJECT me)
61 {
62     //XMLVM_BEGIN_NATIVE[java_lang_Thread_checkAccess__]
63     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
64     //XMLVM_END_NATIVE
65 }
66 
java_lang_Thread_countStackFrames__(JAVA_OBJECT me)67 JAVA_INT java_lang_Thread_countStackFrames__(JAVA_OBJECT me)
68 {
69     //XMLVM_BEGIN_NATIVE[java_lang_Thread_countStackFrames__]
70     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
71     //XMLVM_END_NATIVE
72 }
73 
java_lang_Thread_getCurrentThreadNativeId__()74 JAVA_LONG java_lang_Thread_getCurrentThreadNativeId__()
75 {
76     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getCurrentThreadNativeId__]
77     JAVA_LONG nativeThreadId = (JAVA_LONG)pthread_self();
78     return nativeThreadId;
79     //XMLVM_END_NATIVE
80 }
81 
java_lang_Thread_destroy__(JAVA_OBJECT me)82 void java_lang_Thread_destroy__(JAVA_OBJECT me)
83 {
84     //XMLVM_BEGIN_NATIVE[java_lang_Thread_destroy__]
85     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
86     //XMLVM_END_NATIVE
87 }
88 
java_lang_Thread_dumpStack__()89 void java_lang_Thread_dumpStack__()
90 {
91     //XMLVM_BEGIN_NATIVE[java_lang_Thread_dumpStack__]
92     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
93     //XMLVM_END_NATIVE
94 }
95 
java_lang_Thread_enumerate___java_lang_Thread_1ARRAY(JAVA_OBJECT n1)96 JAVA_INT java_lang_Thread_enumerate___java_lang_Thread_1ARRAY(JAVA_OBJECT n1)
97 {
98     //XMLVM_BEGIN_NATIVE[java_lang_Thread_enumerate___java_lang_Thread_1ARRAY]
99     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
100     //XMLVM_END_NATIVE
101 }
102 
java_lang_Thread_getAllStackTraces__()103 JAVA_OBJECT java_lang_Thread_getAllStackTraces__()
104 {
105     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getAllStackTraces__]
106     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
107     //XMLVM_END_NATIVE
108 }
109 
java_lang_Thread_getContextClassLoader__(JAVA_OBJECT me)110 JAVA_OBJECT java_lang_Thread_getContextClassLoader__(JAVA_OBJECT me)
111 {
112     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getContextClassLoader__]
113     XMLVMElem _r0;
114     _r0.o = __NEW_org_xmlvm_runtime_XMLVMClassLoader();
115     org_xmlvm_runtime_XMLVMClassLoader___INIT___(_r0.o);
116     return _r0.o;
117     //XMLVM_END_NATIVE
118 }
119 
java_lang_Thread_getDefaultUncaughtExceptionHandler__()120 JAVA_OBJECT java_lang_Thread_getDefaultUncaughtExceptionHandler__()
121 {
122     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getDefaultUncaughtExceptionHandler__]
123     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
124     //XMLVM_END_NATIVE
125 }
126 
java_lang_Thread_getStackTrace__(JAVA_OBJECT me)127 JAVA_OBJECT java_lang_Thread_getStackTrace__(JAVA_OBJECT me)
128 {
129     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getStackTrace__]
130     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
131     //XMLVM_END_NATIVE
132 }
133 
java_lang_Thread_getUncaughtExceptionHandler__(JAVA_OBJECT me)134 JAVA_OBJECT java_lang_Thread_getUncaughtExceptionHandler__(JAVA_OBJECT me)
135 {
136     //XMLVM_BEGIN_NATIVE[java_lang_Thread_getUncaughtExceptionHandler__]
137     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
138     //XMLVM_END_NATIVE
139 }
140 
java_lang_Thread_join___long_int(JAVA_OBJECT me,JAVA_LONG n1,JAVA_INT n2)141 void java_lang_Thread_join___long_int(JAVA_OBJECT me, JAVA_LONG n1, JAVA_INT n2)
142 {
143     //XMLVM_BEGIN_NATIVE[java_lang_Thread_join___long_int]
144     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
145     //XMLVM_END_NATIVE
146 }
147 
java_lang_Thread_resume__(JAVA_OBJECT me)148 void java_lang_Thread_resume__(JAVA_OBJECT me)
149 {
150     //XMLVM_BEGIN_NATIVE[java_lang_Thread_resume__]
151     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
152     //XMLVM_END_NATIVE
153 }
154 
java_lang_Thread_stackTracesEnabled__()155 JAVA_BOOLEAN java_lang_Thread_stackTracesEnabled__()
156 {
157     //XMLVM_BEGIN_NATIVE[java_lang_Thread_stackTracesEnabled__]
158 #ifdef XMLVM_ENABLE_STACK_TRACES
159     return 1;
160 #else
161     return 0;
162 #endif
163     //XMLVM_END_NATIVE
164 }
165 
java_lang_Thread_setContextClassLoader___java_lang_ClassLoader(JAVA_OBJECT me,JAVA_OBJECT n1)166 void java_lang_Thread_setContextClassLoader___java_lang_ClassLoader(JAVA_OBJECT me, JAVA_OBJECT n1)
167 {
168     //XMLVM_BEGIN_NATIVE[java_lang_Thread_setContextClassLoader___java_lang_ClassLoader]
169     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
170     //XMLVM_END_NATIVE
171 }
172 
java_lang_Thread_setDefaultUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT n1)173 void java_lang_Thread_setDefaultUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT n1)
174 {
175     //XMLVM_BEGIN_NATIVE[java_lang_Thread_setDefaultUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler]
176     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
177     //XMLVM_END_NATIVE
178 }
179 
java_lang_Thread_setPriority___int(JAVA_OBJECT me,JAVA_INT n1)180 void java_lang_Thread_setPriority___int(JAVA_OBJECT me, JAVA_INT n1)
181 {
182     //XMLVM_BEGIN_NATIVE[java_lang_Thread_setPriority___int]
183     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
184     //XMLVM_END_NATIVE
185 }
186 
java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT me,JAVA_OBJECT n1)187 void java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT me, JAVA_OBJECT n1)
188 {
189     //XMLVM_BEGIN_NATIVE[java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler]
190     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
191     //XMLVM_END_NATIVE
192 }
193 
java_lang_Thread_start0__(JAVA_OBJECT me)194 void java_lang_Thread_start0__(JAVA_OBJECT me)
195 {
196     //XMLVM_BEGIN_NATIVE[java_lang_Thread_start0__]
197     pthread_t pt;
198     pthread_attr_t attr;
199     pthread_attr_init(&attr);
200     pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
201     int rc = pthread_create(&pt, &attr, threadRunner, (void *)me);
202     if (rc != 0) {
203         printf("ERROR creating thread. Return code: %i", rc);
204         exit(-1);
205     }
206     pthread_attr_destroy(&attr);
207     //XMLVM_END_NATIVE
208 }
209 
java_lang_Thread_stop__(JAVA_OBJECT me)210 void java_lang_Thread_stop__(JAVA_OBJECT me)
211 {
212     //XMLVM_BEGIN_NATIVE[java_lang_Thread_stop__]
213     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
214     //XMLVM_END_NATIVE
215 }
216 
java_lang_Thread_stop___java_lang_Throwable(JAVA_OBJECT me,JAVA_OBJECT n1)217 void java_lang_Thread_stop___java_lang_Throwable(JAVA_OBJECT me, JAVA_OBJECT n1)
218 {
219     //XMLVM_BEGIN_NATIVE[java_lang_Thread_stop___java_lang_Throwable]
220     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
221     //XMLVM_END_NATIVE
222 }
223 
java_lang_Thread_suspend__(JAVA_OBJECT me)224 void java_lang_Thread_suspend__(JAVA_OBJECT me)
225 {
226     //XMLVM_BEGIN_NATIVE[java_lang_Thread_suspend__]
227     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
228     //XMLVM_END_NATIVE
229 }
230 
java_lang_Thread_yield__()231 void java_lang_Thread_yield__()
232 {
233     //XMLVM_BEGIN_NATIVE[java_lang_Thread_yield__]
234     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
235     //XMLVM_END_NATIVE
236 }
237 
java_lang_Thread_holdsLock___java_lang_Object(JAVA_OBJECT n1)238 JAVA_BOOLEAN java_lang_Thread_holdsLock___java_lang_Object(JAVA_OBJECT n1)
239 {
240     //XMLVM_BEGIN_NATIVE[java_lang_Thread_holdsLock___java_lang_Object]
241     XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
242     //XMLVM_END_NATIVE
243 }
244 
245 
xmlvm_init_native_java_lang_Thread()246 void xmlvm_init_native_java_lang_Thread()
247 {
248     //XMLVM_BEGIN_NATIVE_IMPLEMENTATION_INIT
249     //XMLVM_END_NATIVE_IMPLEMENTATION_INIT
250 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_checkAccess__
251     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_checkAccess__] =
252         (VTABLE_PTR) java_lang_Thread_checkAccess__;
253 #endif
254 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_countStackFrames__
255     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_countStackFrames__] =
256         (VTABLE_PTR) java_lang_Thread_countStackFrames__;
257 #endif
258 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_destroy__
259     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_destroy__] =
260         (VTABLE_PTR) java_lang_Thread_destroy__;
261 #endif
262 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getContextClassLoader__
263     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getContextClassLoader__] =
264         (VTABLE_PTR) java_lang_Thread_getContextClassLoader__;
265 #endif
266 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getStackTrace__
267     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getStackTrace__] =
268         (VTABLE_PTR) java_lang_Thread_getStackTrace__;
269 #endif
270 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getUncaughtExceptionHandler__
271     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getUncaughtExceptionHandler__] =
272         (VTABLE_PTR) java_lang_Thread_getUncaughtExceptionHandler__;
273 #endif
274 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_join___long_int
275     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_join___long_int] =
276         (VTABLE_PTR) java_lang_Thread_join___long_int;
277 #endif
278 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_resume__
279     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_resume__] =
280         (VTABLE_PTR) java_lang_Thread_resume__;
281 #endif
282 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setContextClassLoader___java_lang_ClassLoader
283     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setContextClassLoader___java_lang_ClassLoader] =
284         (VTABLE_PTR) java_lang_Thread_setContextClassLoader___java_lang_ClassLoader;
285 #endif
286 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setPriority___int
287     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setPriority___int] =
288         (VTABLE_PTR) java_lang_Thread_setPriority___int;
289 #endif
290 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler
291     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler] =
292         (VTABLE_PTR) java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler;
293 #endif
294 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_start0__
295     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_start0__] =
296         (VTABLE_PTR) java_lang_Thread_start0__;
297 #endif
298 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_stop__
299     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_stop__] =
300         (VTABLE_PTR) java_lang_Thread_stop__;
301 #endif
302 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_stop___java_lang_Throwable
303     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_stop___java_lang_Throwable] =
304         (VTABLE_PTR) java_lang_Thread_stop___java_lang_Throwable;
305 #endif
306 #ifdef XMLVM_VTABLE_IDX_java_lang_Thread_suspend__
307     __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_suspend__] =
308         (VTABLE_PTR) java_lang_Thread_suspend__;
309 #endif
310 }
311