aboutsummaryrefslogtreecommitdiff
path: root/tests/nbody-java/native_java_lang_Thread.c
blob: c2631b1c2f5c40c2c33f1bcf16f856be77a90855 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#include "xmlvm.h"
#include "java_lang_Thread.h"


//XMLVM_BEGIN_NATIVE_IMPLEMENTATION
#include <pthread.h>
#ifdef __OBJC__
#import <Foundation/NSAutoreleasePool.h>
#endif


void threadRunner(JAVA_OBJECT me)
{
    java_lang_Thread* thiz = me;
    XMLVM_JMP_BUF xmlvm_exception_env;
    JAVA_LONG nativeThreadId = (JAVA_LONG) pthread_self();
    
#ifdef __OBJC__
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
#endif
#ifdef XMLVM_ENABLE_STACK_TRACES
    createStackForNewThread(nativeThreadId);
#endif

    if (XMLVM_SETJMP(xmlvm_exception_env)) {
        // Technically, XMLVM_UNWIND_EXCEPTION() should be called, but
        // exceptions will not be used anymore and XMLVM_ENTER_METHOD() wasn't
        // called (excessive), so a compilation error would occur

        xmlvm_unhandled_exception();
    } else {
        thiz->fields.java_lang_Thread.xmlvmExceptionEnv_ = &xmlvm_exception_env;
        java_lang_Thread_run0___long(thiz, nativeThreadId);
    }

#ifdef XMLVM_ENABLE_STACK_TRACES
    destroyStackForExitingThread(nativeThreadId);
#endif
#ifdef __OBJC__
    [pool release];
#endif
}
//XMLVM_END_NATIVE_IMPLEMENTATION

void java_lang_Thread_initMainThread__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_initMainThread__]
    ((java_lang_Thread*)me)->fields.java_lang_Thread.xmlvmExceptionEnv_ = xmlvm_exception_env_main_thread;
    //XMLVM_END_NATIVE
}

JAVA_INT java_lang_Thread_activeCount__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_activeCount__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_checkAccess__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_checkAccess__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_INT java_lang_Thread_countStackFrames__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_countStackFrames__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_LONG java_lang_Thread_getCurrentThreadNativeId__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getCurrentThreadNativeId__]
    JAVA_LONG nativeThreadId = (JAVA_LONG)pthread_self();
    return nativeThreadId;
    //XMLVM_END_NATIVE
}

void java_lang_Thread_destroy__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_destroy__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_dumpStack__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_dumpStack__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_INT java_lang_Thread_enumerate___java_lang_Thread_1ARRAY(JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_enumerate___java_lang_Thread_1ARRAY]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_OBJECT java_lang_Thread_getAllStackTraces__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getAllStackTraces__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_OBJECT java_lang_Thread_getContextClassLoader__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getContextClassLoader__]
    XMLVMElem _r0;
    _r0.o = __NEW_org_xmlvm_runtime_XMLVMClassLoader();
    org_xmlvm_runtime_XMLVMClassLoader___INIT___(_r0.o);
    return _r0.o;
    //XMLVM_END_NATIVE
}

JAVA_OBJECT java_lang_Thread_getDefaultUncaughtExceptionHandler__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getDefaultUncaughtExceptionHandler__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_OBJECT java_lang_Thread_getStackTrace__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getStackTrace__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_OBJECT java_lang_Thread_getUncaughtExceptionHandler__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_getUncaughtExceptionHandler__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_join___long_int(JAVA_OBJECT me, JAVA_LONG n1, JAVA_INT n2)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_join___long_int]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_resume__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_resume__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_BOOLEAN java_lang_Thread_stackTracesEnabled__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_stackTracesEnabled__]
#ifdef XMLVM_ENABLE_STACK_TRACES
    return 1;
#else
    return 0;
#endif
    //XMLVM_END_NATIVE
}

void java_lang_Thread_setContextClassLoader___java_lang_ClassLoader(JAVA_OBJECT me, JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_setContextClassLoader___java_lang_ClassLoader]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_setDefaultUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_setDefaultUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_setPriority___int(JAVA_OBJECT me, JAVA_INT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_setPriority___int]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler(JAVA_OBJECT me, JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_start0__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_start0__]
    pthread_t pt;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    int rc = pthread_create(&pt, &attr, threadRunner, (void *)me);
    if (rc != 0) {
        printf("ERROR creating thread. Return code: %i", rc);
        exit(-1);
    }
    pthread_attr_destroy(&attr);
    //XMLVM_END_NATIVE
}

void java_lang_Thread_stop__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_stop__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_stop___java_lang_Throwable(JAVA_OBJECT me, JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_stop___java_lang_Throwable]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_suspend__(JAVA_OBJECT me)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_suspend__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

void java_lang_Thread_yield__()
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_yield__]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}

JAVA_BOOLEAN java_lang_Thread_holdsLock___java_lang_Object(JAVA_OBJECT n1)
{
    //XMLVM_BEGIN_NATIVE[java_lang_Thread_holdsLock___java_lang_Object]
    XMLVM_UNIMPLEMENTED_NATIVE_METHOD();
    //XMLVM_END_NATIVE
}


void xmlvm_init_native_java_lang_Thread()
{
    //XMLVM_BEGIN_NATIVE_IMPLEMENTATION_INIT
    //XMLVM_END_NATIVE_IMPLEMENTATION_INIT
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_checkAccess__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_checkAccess__] = 
        (VTABLE_PTR) java_lang_Thread_checkAccess__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_countStackFrames__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_countStackFrames__] = 
        (VTABLE_PTR) java_lang_Thread_countStackFrames__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_destroy__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_destroy__] = 
        (VTABLE_PTR) java_lang_Thread_destroy__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getContextClassLoader__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getContextClassLoader__] = 
        (VTABLE_PTR) java_lang_Thread_getContextClassLoader__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getStackTrace__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getStackTrace__] = 
        (VTABLE_PTR) java_lang_Thread_getStackTrace__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_getUncaughtExceptionHandler__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_getUncaughtExceptionHandler__] = 
        (VTABLE_PTR) java_lang_Thread_getUncaughtExceptionHandler__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_join___long_int
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_join___long_int] = 
        (VTABLE_PTR) java_lang_Thread_join___long_int;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_resume__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_resume__] = 
        (VTABLE_PTR) java_lang_Thread_resume__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setContextClassLoader___java_lang_ClassLoader
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setContextClassLoader___java_lang_ClassLoader] = 
        (VTABLE_PTR) java_lang_Thread_setContextClassLoader___java_lang_ClassLoader;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setPriority___int
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setPriority___int] = 
        (VTABLE_PTR) java_lang_Thread_setPriority___int;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler] = 
        (VTABLE_PTR) java_lang_Thread_setUncaughtExceptionHandler___java_lang_Thread_UncaughtExceptionHandler;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_start0__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_start0__] = 
        (VTABLE_PTR) java_lang_Thread_start0__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_stop__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_stop__] = 
        (VTABLE_PTR) java_lang_Thread_stop__;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_stop___java_lang_Throwable
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_stop___java_lang_Throwable] = 
        (VTABLE_PTR) java_lang_Thread_stop___java_lang_Throwable;
#endif
#ifdef XMLVM_VTABLE_IDX_java_lang_Thread_suspend__
    __TIB_java_lang_Thread.vtable[XMLVM_VTABLE_IDX_java_lang_Thread_suspend__] = 
        (VTABLE_PTR) java_lang_Thread_suspend__;
#endif
}