]> gitweb.factorcode.org Git - factor.git/blob - unmaintained/jni/jni-internals.factor
tools.test: Make the flag public. Finish porting tester changes to fuzzer.
[factor.git] / unmaintained / jni / jni-internals.factor
1 ! Copyright (C) 2006 Chris Double.
2 ! See http://factorcode.org/license.txt for BSD license.
3 IN: jni-internals
4 USING: kernel alien arrays sequences ;
5
6 LIBRARY: jvm
7
8 TYPEDEF: int jint
9 TYPEDEF: uchar jboolean
10 TYPEDEF: void* JNIEnv
11
12 C-STRUCT: jdk-init-args
13         { "jint" "version" }
14         { "void*" "properties" }
15         { "jint" "check-source" }
16         { "jint" "native-stack-size" }
17         { "jint" "java-stack-size" }
18         { "jint" "min-heap-size" }
19         { "jint" "max-heap-size" }
20         { "jint" "verify-mode" }
21         { "char*" "classpath" }
22         { "void*" "vprintf" }
23         { "void*" "exit" }
24         { "void*" "abort" }
25         { "jint" "enable-class-gc" }
26         { "jint" "enable-verbose-gc" }
27         { "jint" "disable-async-gc" }
28         { "jint" "verbose" }
29         { "jboolean" "debugging" }
30         { "jint" "debug-port" } ;
31
32 C-STRUCT: JNIInvokeInterface
33         { "void*" "reserved0" }
34         { "void*" "reserved1" }
35         { "void*" "reserved2" }
36         { "void*" "DestroyJavaVM" }
37         { "void*" "AttachCurrentThread" }
38         { "void*" "DetachCurrentThread" }
39         { "void*" "GetEnv" }
40         { "void*" "AttachCurrentThreadAsDaemon" } ;
41
42 C-STRUCT: JavaVM
43         { "JNIInvokeInterface*" "functions" } ;
44
45 C-STRUCT: JNINativeInterface
46     { "void*" "reserved0" }
47     { "void*" "reserved1" }
48     { "void*" "reserved2" }
49     { "void*" "reserved3" }
50     { "void*" "GetVersion" }
51     { "void*" "DefineClass" }
52     { "void*" "FindClass" }
53     { "void*" "FromReflectedMethod" }
54     { "void*" "FromReflectedField" }
55     { "void*" "ToReflectedMethod" }
56     { "void*" "GetSuperclass" }
57     { "void*" "IsAssignableFrom" }
58     { "void*" "ToReflectedField" }
59     { "void*" "Throw" }
60     { "void*" "ThrowNew" }
61     { "void*" "ExceptionOccurred" }
62     { "void*" "ExceptionDescribe" }
63     { "void*" "ExceptionClear" }
64     { "void*" "FatalError" }
65     { "void*" "PushLocalFrame" }
66     { "void*" "PopLocalFrame" }
67     { "void*" "NewGlobalRef" }
68     { "void*" "DeleteGlobalRef" }
69     { "void*" "DeleteLocalRef" }
70     { "void*" "IsSameObject" }
71     { "void*" "NewLocalRef" }
72     { "void*" "EnsureLocalCapacity" }
73     { "void*" "AllocObject" }
74     { "void*" "NewObject" }
75     { "void*" "NewObjectV" }
76     { "void*" "NewObjectA" }
77     { "void*" "GetObjectClass" }
78     { "void*" "IsInstanceOf" }
79     { "void*" "GetMethodID" }
80     { "void*" "CallObjectMethod" }
81     { "void*" "CallObjectMethodV" }
82     { "void*" "CallObjectMethodA" }
83     { "void*" "CallBooleanMethod" }
84     { "void*" "CallBooleanMethodV" }
85     { "void*" "CallBooleanMethodA" }
86     { "void*" "CallByteMethod" }
87     { "void*" "CallByteMethodV" }
88     { "void*" "CallByteMethodA" }
89     { "void*" "CallCharMethod" }
90     { "void*" "CallCharMethodV" }
91     { "void*" "CallCharMethodA" }
92     { "void*" "CallShortMethod" }
93     { "void*" "CallShortMethodV" }
94     { "void*" "CallShortMethodA" }
95     { "void*" "CallIntMethod" }
96     { "void*" "CallIntMethodV" }
97     { "void*" "CallIntMethodA" }
98     { "void*" "CallLongMethod" }
99     { "void*" "CallLongMethodV" }
100     { "void*" "CallLongMethodA" }
101     { "void*" "CallFloatMethod" }
102     { "void*" "CallFloatMethodV" }
103     { "void*" "CallFloatMethodA" }
104     { "void*" "CallDoubleMethod" }
105     { "void*" "CallDoubleMethodV" }
106     { "void*" "CallDoubleMethodA" }
107     { "void*" "CallVoidMethod" }
108     { "void*" "CallVoidMethodV" }
109     { "void*" "CallVoidMethodA" }
110     { "void*" "CallNonvirtualObjectMethod" }
111     { "void*" "CallNonvirtualObjectMethodV" }
112     { "void*" "CallNonvirtualObjectMethodA" }
113     { "void*" "CallNonvirtualBooleanMethod" }
114     { "void*" "CallNonvirtualBooleanMethodV" }
115     { "void*" "CallNonvirtualBooleanMethodA" }
116     { "void*" "CallNonvirtualByteMethod" }
117     { "void*" "CallNonvirtualByteMethodV" }
118     { "void*" "CallNonvirtualByteMethodA" }
119     { "void*" "CallNonvirtualCharMethod" }
120     { "void*" "CallNonvirtualCharMethodV" }
121     { "void*" "CallNonvirtualCharMethodA" }
122     { "void*" "CallNonvirtualShortMethod" }
123     { "void*" "CallNonvirtualShortMethodV" }
124     { "void*" "CallNonvirtualShortMethodA" }
125     { "void*" "CallNonvirtualIntMethod" }
126     { "void*" "CallNonvirtualIntMethodV" }
127     { "void*" "CallNonvirtualIntMethodA" }
128     { "void*" "CallNonvirtualLongMethod" }
129     { "void*" "CallNonvirtualLongMethodV" }
130     { "void*" "CallNonvirtualLongMethodA" }
131     { "void*" "CallNonvirtualFloatMethod" }
132     { "void*" "CallNonvirtualFloatMethodV" }
133     { "void*" "CallNonvirtualFloatMethodA" }
134     { "void*" "CallNonvirtualDoubleMethod" }
135     { "void*" "CallNonvirtualDoubleMethodV" }
136     { "void*" "CallNonvirtualDoubleMethodA" }
137     { "void*" "CallNonvirtualVoidMethod" }
138     { "void*" "CallNonvirtualVoidMethodV" }
139     { "void*" "CallNonvirtualVoidMethodA" }
140     { "void*" "GetFieldID" }
141     { "void*" "GetObjectField" }
142     { "void*" "GetBooleanField" }
143     { "void*" "GetByteField" }
144     { "void*" "GetCharField" }
145     { "void*" "GetShortField" }
146     { "void*" "GetIntField" }
147     { "void*" "GetLongField" }
148     { "void*" "GetFloatField" }
149     { "void*" "GetDoubleField" }
150     { "void*" "SetObjectField" }
151     { "void*" "SetBooleanField" }
152     { "void*" "SetByteField" }
153     { "void*" "SetCharField" }
154     { "void*" "SetShortField" }
155     { "void*" "SetIntField" }
156     { "void*" "SetLongField" }
157     { "void*" "SetFloatField" }
158     { "void*" "SetDoubleField" }
159     { "void*" "GetStaticMethodID" }
160     { "void*" "CallStaticObjectMethod" }
161     { "void*" "CallStaticObjectMethodV" }
162     { "void*" "CallStaticObjectMethodA" }
163     { "void*" "CallStaticBooleanMethod" }
164     { "void*" "CallStaticBooleanMethodV" }
165     { "void*" "CallStaticBooleanMethodA" }
166     { "void*" "CallStaticByteMethod" }
167     { "void*" "CallStaticByteMethodV" }
168     { "void*" "CallStaticByteMethodA" }
169     { "void*" "CallStaticCharMethod" }
170     { "void*" "CallStaticCharMethodV" }
171     { "void*" "CallStaticCharMethodA" }
172     { "void*" "CallStaticShortMethod" }
173     { "void*" "CallStaticShortMethodV" }
174     { "void*" "CallStaticShortMethodA" }
175     { "void*" "CallStaticIntMethod" }
176     { "void*" "CallStaticIntMethodV" }
177     { "void*" "CallStaticIntMethodA" }
178     { "void*" "CallStaticLongMethod" }
179     { "void*" "CallStaticLongMethodV" }
180     { "void*" "CallStaticLongMethodA" }
181     { "void*" "CallStaticFloatMethod" }
182     { "void*" "CallStaticFloatMethodV" }
183     { "void*" "CallStaticFloatMethodA" }
184     { "void*" "CallStaticDoubleMethod" }
185     { "void*" "CallStaticDoubleMethodV" }
186     { "void*" "CallStaticDoubleMethodA" }
187     { "void*" "CallStaticVoidMethod" }
188     { "void*" "CallStaticVoidMethodV" }
189     { "void*" "CallStaticVoidMethodA" }
190     { "void*" "GetStaticFieldID" }
191     { "void*" "GetStaticObjectField" }
192     { "void*" "GetStaticBooleanField" }
193     { "void*" "GetStaticByteField" }
194     { "void*" "GetStaticCharField" }
195     { "void*" "GetStaticShortField" }
196     { "void*" "GetStaticIntField" }
197     { "void*" "GetStaticLongField" }
198     { "void*" "GetStaticFloatField" }
199     { "void*" "GetStaticDoubleField" }
200     { "void*" "SetStaticObjectField" }
201     { "void*" "SetStaticBooleanField" }
202     { "void*" "SetStaticByteField" }
203     { "void*" "SetStaticCharField" }
204     { "void*" "SetStaticShortField" }
205     { "void*" "SetStaticIntField" }
206     { "void*" "SetStaticLongField" }
207     { "void*" "SetStaticFloatField" }
208     { "void*" "SetStaticDoubleField" }
209     { "void*" "NewString" }
210     { "void*" "GetStringLength" }
211     { "void*" "GetStringChars" }
212     { "void*" "ReleaseStringChars" }
213     { "void*" "NewStringUTF" }
214     { "void*" "GetStringUTFLength" }
215     { "void*" "GetStringUTFChars" }
216     { "void*" "ReleaseStringUTFChars" }
217     { "void*" "GetArrayLength" }
218     { "void*" "NewObjectArray" }
219     { "void*" "GetObjectArrayElement" }
220     { "void*" "SetObjectArrayElement" }
221     { "void*" "NewBooleanArray" }
222     { "void*" "NewByteArray" }
223     { "void*" "NewCharArray" }
224     { "void*" "NewShortArray" }
225     { "void*" "NewIntArray" }
226     { "void*" "NewLongArray" }
227     { "void*" "NewFloatArray" }
228     { "void*" "NewDoubleArray" }
229     { "void*" "GetBooleanArrayElements" }
230     { "void*" "GetByteArrayElements" }
231     { "void*" "GetCharArrayElements" }
232     { "void*" "GetShortArrayElements" }
233     { "void*" "GetIntArrayElements" }
234     { "void*" "GetLongArrayElements" }
235     { "void*" "GetFloatArrayElements" }
236     { "void*" "GetDoubleArrayElements" }
237     { "void*" "ReleaseBooleanArrayElements" }
238     { "void*" "ReleaseByteArrayElements" }
239     { "void*" "ReleaseCharArrayElements" }
240     { "void*" "ReleaseShortArrayElements" }
241     { "void*" "ReleaseIntArrayElements" }
242     { "void*" "ReleaseLongArrayElements" }
243     { "void*" "ReleaseFloatArrayElements" }
244     { "void*" "ReleaseDoubleArrayElements" }
245     { "void*" "GetBooleanArrayRegion" }
246     { "void*" "GetByteArrayRegion" }
247     { "void*" "GetCharArrayRegion" }
248     { "void*" "GetShortArrayRegion" }
249     { "void*" "GetIntArrayRegion" }
250     { "void*" "GetLongArrayRegion" }
251     { "void*" "GetFloatArrayRegion" }
252     { "void*" "GetDoubleArrayRegion" }
253     { "void*" "SetBooleanArrayRegion" }
254     { "void*" "SetByteArrayRegion" }
255     { "void*" "SetCharArrayRegion" }
256     { "void*" "SetShortArrayRegion" }
257     { "void*" "SetIntArrayRegion" }
258     { "void*" "SetLongArrayRegion" }
259     { "void*" "SetFloatArrayRegion" }
260     { "void*" "SetDoubleArrayRegion" }
261     { "void*" "RegisterNatives" }
262     { "void*" "UnregisterNatives" }
263     { "void*" "MonitorEnter" }
264     { "void*" "MonitorExit" }
265     { "void*" "GetJavaVM" }
266     { "void*" "GetStringRegion" }
267     { "void*" "GetStringUTFRegion" }
268     { "void*" "GetPrimitiveArrayCritical" }
269     { "void*" "ReleasePrimitiveArrayCritical" }
270     { "void*" "GetStringCritical" }
271     { "void*" "ReleaseStringCritical" }
272     { "void*" "NewWeakGlobalRef" }
273     { "void*" "DeleteWeakGlobalRef" }
274     { "void*" "ExceptionCheck" }
275     { "void*" "NewDirectByteBuffer" }
276     { "void*" "GetDirectBufferAddress" }
277     { "void*" "GetDirectBufferCapacity" } ;
278
279 C-STRUCT: JNIEnv
280         { "JNINativeInterface*" "functions" } ;
281
282 FUNCTION: jint JNI_GetDefaultJavaVMInitArgs ( jdk-init-args* args ) ;
283 FUNCTION: jint JNI_CreateJavaVM ( void** pvm, void** penv, void* args ) ;
284
285 : <jdk-init-args> ( -- jdk-init-args )
286   "jdk-init-args" <c-object>  0x00010004 over set-jdk-init-args-version ;
287
288 : jni1 ( -- init-args int )
289   <jdk-init-args> dup JNI_GetDefaultJavaVMInitArgs ;
290
291 : jni2 ( -- vm env int )
292   f <void*> f <void*> [
293     jni1 drop JNI_CreateJavaVM
294   ] 2keep rot dup 0 = [
295     >r >r 0 swap void*-nth r> 0 swap void*-nth r> 
296   ] when ;
297
298 : (destroy-java-vm) 
299   "int" { "void*" } cdecl alien-indirect ;
300
301 : (attach-current-thread) 
302   "int" { "void*" "void*" "void*" } cdecl alien-indirect ;
303
304 : (detach-current-thread) 
305   "int" { "void*" } cdecl alien-indirect ;
306
307 : (get-env) 
308   "int" { "void*" "void*" "int" } cdecl alien-indirect ;
309
310 : (attach-current-thread-as-daemon) 
311   "int" { "void*" "void*" "void*" } cdecl alien-indirect ;
312
313 : destroy-java-vm ( javavm -- int )
314   dup JavaVM-functions JNIInvokeInterface-DestroyJavaVM (destroy-java-vm) ;
315
316 : (get-version) 
317   "jint" { "JNIEnv*" } cdecl alien-indirect ;
318
319 : get-version ( jnienv -- int )
320   dup JNIEnv-functions JNINativeInterface-GetVersion (get-version) ;
321   
322 : (find-class) 
323   "void*" { "JNINativeInterface*" "char*" } cdecl alien-indirect ;
324
325 : find-class ( name jnienv -- int )
326   dup swapd JNIEnv-functions JNINativeInterface-FindClass (find-class) ;
327
328 : (get-static-field-id) 
329   "void*" { "JNINativeInterface*" "void*" "char*" "char*" } cdecl alien-indirect ;
330
331 : get-static-field-id ( class name sig jnienv -- int )
332   dup >r >r 3array r> swap first3 r> JNIEnv-functions JNINativeInterface-GetStaticFieldID (get-static-field-id) ;
333
334 : (get-static-object-field) 
335   "void*" { "JNINativeInterface*" "void*" "void*" } cdecl alien-indirect ;
336
337 : get-static-object-field ( class id jnienv -- int )
338   dup >r >r 2array r> swap first2 r> JNIEnv-functions JNINativeInterface-GetStaticObjectField (get-static-object-field) ;
339
340 : (get-method-id) 
341   "void*" { "JNINativeInterface*" "void*" "char*" "char*" } cdecl alien-indirect ;
342
343 : get-method-id ( class name sig jnienv -- int )
344   dup >r >r 3array r> swap first3 r> JNIEnv-functions JNINativeInterface-GetMethodID (get-method-id) ;
345
346 : (new-string) 
347   "void*" { "JNINativeInterface*" "char*" "int" } cdecl alien-indirect ;
348
349 : new-string ( str jnienv -- str )
350   dup >r >r dup length 2array r> swap first2 r> JNIEnv-functions JNINativeInterface-NewString (new-string) ;
351
352 : (call1) 
353   "void" { "JNINativeInterface*" "void*" "void*" "int" } cdecl alien-indirect ;
354
355 : call1 ( obj method-id jstr jnienv -- )
356   dup >r >r 3array r> swap first3 r> JNIEnv-functions JNINativeInterface-CallObjectMethod (call1) ;
357