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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
|
/*
* mono-jni.c: native methods required by the mono JNI implementation.
*
*
*/
#include <jni.h>
#include <gmodule.h>
#include <mono/metadata/object.h>
#include <mono/metadata/appdomain.h>
#include <string.h>
#include <stdarg.h>
/*
* PROTOTYPES
*/
void * native_load_native_library (char *filename);
int native_lookup_symbol (GModule *module, char *symbol_name, gpointer *symbol);
void mono_jni_jnienv_init (
void *makelocalref_func,
void *unwrap_func,
void *makeglobalref_func,
void *deleteref_func,
void *getfieldcookie_func,
void *getmethodcookie_func,
void *setfieldvalue_func,
void *getfieldvalue_func,
void *getclassfromobject_func,
void *exceptioncheck_func,
void *getpendingexception_func,
void *setpendingexception_func,
void *invokemethod_func,
void *getmethodarglist_func,
void *findclass_func,
void *getjnienv_func,
void *allocobject_func);
void* mono_jni_get_func_table (void);
void mono_jni_set_jnifunc (int index, void *func);
jint JNICALL GetJavaVM (JNIEnv *env, JavaVM **vm);
void *
native_load_native_library (char *filename)
{
return g_module_open (filename, 0);
}
int
native_lookup_symbol (GModule *module, char *symbol_name, gpointer *symbol)
{
gboolean res = g_module_symbol (module, symbol_name, symbol);
return res;
}
typedef struct MonoJniFunctions {
int (*MakeLocalRef) (JNIEnv *env, void *obj);
void * (*UnwrapRef) (JNIEnv *env, void *ref);
int (*MakeGlobalRef) (void *obj);
void (*DeleteRef) (JNIEnv *env, void *ref);
int (*GetFieldCookie) (void *klass, void *name, void *sig, gboolean is_static);
int (*GetMethodCookie) (void *klass, void *name, void *sig, gboolean is_static);
void (*SetFieldValue) (void *cookie, void *obj, void *val);
void * (*GetFieldValue) (void *cookie, void *obj);
void * (*GetClassFromObject) (void *obj);
jboolean (*ExceptionCheck) (JNIEnv *env);
void * (*GetPendingException) (JNIEnv *env);
void (*SetPendingException) (JNIEnv *env, void *obj);
void * (*InvokeMethod) (JNIEnv *env, void *cookie, void *obj, void *args, int virtual);
void * (*GetMethodArgList) (void *cookie);
void * (*FindClass) (void *name);
void * (*GetJniEnv) (void);
void * (*AllocObject) (void *klass);
} MonoJniFunctions;
static MonoJniFunctions jniFuncs;
void
mono_jni_jnienv_init (
void *makelocalref_func,
void *unwrap_func,
void *makeglobalref_func,
void *deleteref_func,
void *getfieldcookie_func,
void *getmethodcookie_func,
void *setfieldvalue_func,
void *getfieldvalue_func,
void *getclassfromobject_func,
void *exceptioncheck_func,
void *getpendingexception_func,
void *setpendingexception_func,
void *invokemethod_func,
void *getmethodarglist_func,
void *findclass_func,
void *getjnienv_func,
void *allocobject_func)
{
jniFuncs.MakeLocalRef = makelocalref_func;
jniFuncs.UnwrapRef = unwrap_func;
jniFuncs.MakeGlobalRef = makeglobalref_func;
jniFuncs.DeleteRef = deleteref_func;
jniFuncs.GetFieldCookie = getfieldcookie_func;
jniFuncs.GetMethodCookie = getmethodcookie_func;
jniFuncs.SetFieldValue = setfieldvalue_func;
jniFuncs.GetFieldValue = getfieldvalue_func;
jniFuncs.GetClassFromObject = getclassfromobject_func;
jniFuncs.ExceptionCheck = exceptioncheck_func;
jniFuncs.GetPendingException = getpendingexception_func;
jniFuncs.SetPendingException = setpendingexception_func;
jniFuncs.InvokeMethod = invokemethod_func;
jniFuncs.GetMethodArgList = getmethodarglist_func;
jniFuncs.FindClass = findclass_func;
jniFuncs.GetJniEnv = getjnienv_func;
jniFuncs.AllocObject = allocobject_func;
}
static void *jni_func_table[256];
static void ***jni_ptr = NULL;
static void *vm_func_table[64];
static void ***vm_ptr = NULL;
void*
mono_jni_get_func_table (void)
{
if (!jni_ptr) {
jni_ptr = (void***)&jni_func_table;
}
return jni_ptr;
}
void
mono_jni_set_jnifunc (int index, void *func)
{
jni_func_table [index] = func;
}
static MonoString *
StringFromUTF8 (const char* psz)
{
/* TODO: */
return mono_string_new (mono_domain_get (), psz);
#if 0
/* Sun's modified UTF8 encoding is not compatible with System::Text::Encoding::UTF8, so */
/* we need to roll our own */
int len, res_len, i;
int *res;
len = strlen (psz);
res = g_malloc (len * sizeof (int));
res_len = 0;
for (i = 0; i < len; i++) {
int c = (unsigned char)*psz++;
int char2, char3;
switch (c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
/* 0xxxxxxx */
break;
case 12: case 13:
/* 110x xxxx 10xx xxxx */
char2 = *psz++;
i++;
c = (((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
char2 = *psz++;
char3 = *psz++;
i++;
i++;
c = (((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0));
break;
}
res [res_len ++] = c;
}
return mono_string_new_utf16 (mono_domain_get (), res, res_len);
#endif
}
/***************************************************************************/
/* JNI FUNCTIONS */
/***************************************************************************/
static jint JNICALL GetVersion (JNIEnv *env) { printf ("JNI Function GetVersion is not implemented.\n"); g_assert_not_reached (); return 0; }
static jclass JNICALL DefineClass (JNIEnv *env, const char *name, jobject loader, const jbyte *buf, jsize len) { printf ("JNI Function DefineClass is not implemented.\n"); g_assert_not_reached (); return 0; }
static jclass JNICALL FindClass (JNIEnv *env, const char *name)
{
return (jclass)(jniFuncs.MakeLocalRef (env, jniFuncs.FindClass (StringFromUTF8(name))));
}
static jmethodID JNICALL FromReflectedMethod (JNIEnv *env, jobject method) { printf ("JNI Function FromReflectedMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jfieldID JNICALL FromReflectedField (JNIEnv *env, jobject field) { printf ("JNI Function FromReflectedField is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL ToReflectedMethod (JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic) { printf ("JNI Function ToReflectedMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jclass JNICALL GetSuperclass (JNIEnv *env, jclass sub) { printf ("JNI Function GetSuperclass is not implemented.\n"); g_assert_not_reached (); return 0; }
static jboolean JNICALL IsAssignableFrom (JNIEnv *env, jclass sub, jclass sup) { printf ("JNI Function IsAssignableFrom is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL ToReflectedField (JNIEnv *env, jclass cls, jfieldID fieldID, jboolean isStatic) { printf ("JNI Function ToReflectedField is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL Throw (JNIEnv *env, jthrowable obj) { printf ("JNI Function Throw is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL ThrowNew (JNIEnv *env, jclass clazz, const char *msg) { printf ("JNI Function ThrowNew is not implemented.\n"); g_assert_not_reached (); return 0; }
static jthrowable JNICALL ExceptionOccurred (JNIEnv *env)
{
return (jthrowable)jniFuncs.MakeLocalRef (env, jniFuncs.GetPendingException (env));
}
static void JNICALL ExceptionDescribe (JNIEnv *env) { printf ("JNI Function ExceptionDescribe is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL ExceptionClear (JNIEnv *env) { printf ("JNI Function ExceptionClear is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL FatalError (JNIEnv *env, const char *msg) { printf ("JNI Function FatalError is not implemented.\n"); g_assert_not_reached (); }
static jint JNICALL PushLocalFrame (JNIEnv *env, jint capacity) { printf ("JNI Function PushLocalFrame is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL PopLocalFrame (JNIEnv *env, jobject result) { printf ("JNI Function PopLocalFrame is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL NewGlobalRef (JNIEnv *env, jobject lobj)
{
return (jobject)jniFuncs.MakeGlobalRef (jniFuncs.UnwrapRef (env, lobj));
}
static void JNICALL DeleteGlobalRef (JNIEnv *env, jobject gref)
{
jniFuncs.DeleteRef (env, gref);
}
static void JNICALL DeleteLocalRef (JNIEnv *env, jobject obj)
{
jniFuncs.DeleteRef (env, obj);
}
static jboolean JNICALL IsSameObject (JNIEnv *env, jobject obj1, jobject obj2) { printf ("JNI Function IsSameObject is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL NewLocalRef (JNIEnv *env, jobject ref) { printf ("JNI Function NewLocalRef is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL EnsureLocalCapacity (JNIEnv *env, jint capacity) { printf ("JNI Function EnsureLocalCapacity is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL AllocObject (JNIEnv *env, jclass clazz) { printf ("JNI Function EnsureLocalCapacity is not implemented.\n"); g_assert_not_reached (); return 0; }
static jclass JNICALL GetObjectClass (JNIEnv *env, jobject obj)
{
g_assert (obj);
return (jclass)jniFuncs.MakeLocalRef (env, jniFuncs.GetClassFromObject (jniFuncs.UnwrapRef (env, obj)));
}
static jboolean JNICALL IsInstanceOf (JNIEnv *env, jobject obj, jclass clazz) { printf ("JNI Function IsInstanceOf is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL CallObjectMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args) { printf ("JNI Function CallObjectMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
#define BOXED_VALUE(obj) ((char*)(obj) + sizeof (MonoObject))
static MonoObject *
box_Boolean (jboolean val)
{
return mono_value_box (mono_domain_get (), mono_get_boolean_class (), &val);
}
static MonoObject *
box_Byte (jbyte val)
{
/* Sbyte ! */
return mono_value_box (mono_domain_get (), mono_get_sbyte_class (), &val);
}
static MonoObject *
box_Char (jchar val)
{
return mono_value_box (mono_domain_get (), mono_get_char_class (), &val);
}
static MonoObject *
box_Short (jshort val)
{
return mono_value_box (mono_domain_get (), mono_get_int16_class (), &val);
}
static MonoObject *
box_Int (jint val)
{
return mono_value_box (mono_domain_get (), mono_get_int32_class (), &val);
}
static MonoObject *
box_Long (jlong val)
{
return mono_value_box (mono_domain_get (), mono_get_int64_class (), &val);
}
static MonoObject *
box_Float (jfloat val)
{
return mono_value_box (mono_domain_get (), mono_get_single_class (), &val);
}
static MonoObject *
box_Double (jdouble val)
{
return mono_value_box (mono_domain_get (), mono_get_double_class (), &val);
}
static int
GetMethodArgs (jmethodID methodID, char* sig)
{
char *res;
res = jniFuncs.GetMethodArgList (methodID);
strcpy (sig, res);
return strlen (sig);
}
static MonoObject*
InvokeHelper (JNIEnv *env, jobject object, jmethodID methodID, jvalue* args)
{
char sig[257];
int argc, i;
MonoObject **argarray;
MonoArray *args2;
/* assert(!pLocalRefs->PendingException); */
g_assert(methodID);
argc = GetMethodArgs(methodID, sig);
argarray = g_new (MonoObject*, argc);
for(i = 0; i < argc; i++)
{
switch(sig[i])
{
case 'Z': {
jboolean val = args[i].z != JNI_FALSE;
argarray[i] = box_Boolean (val);
break;
}
case 'B':
argarray[i] = box_Byte (args[i].b);
break;
case 'C':
argarray[i] = box_Char (args[i].c);
break;
case 'S':
argarray[i] = box_Short (args[i].s);
break;
case 'I':
argarray[i] = box_Int (args[i].i);
break;
case 'J':
argarray[i] = box_Long (args[i].j);
break;
case 'F':
argarray[i] = box_Float (args[i].f);
break;
case 'D':
argarray[i] = box_Double (args[i].d);
break;
case 'L':
argarray[i] = jniFuncs.UnwrapRef (env, args[i].l);
break;
}
}
args2 = mono_array_new (mono_domain_get (), mono_get_object_class (), argc);
for (i = 0; i < argc; ++i)
mono_array_set (args2, MonoObject*, i, argarray [i]);
return jniFuncs.InvokeMethod (env, methodID, jniFuncs.UnwrapRef (env, object), args2, FALSE);
}
#define METHOD_IMPL_MANAGED(Type,type,cpptype) \
static type JNICALL Call##Type##MethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue* args)\
{\
MonoObject* ret = InvokeHelper(env, obj, methodID, args);\
if(ret) return *(type*)BOXED_VALUE(ret);\
return 0;\
}
#define METHOD_IMPL(Type,type) \
static type JNICALL Call##Type##MethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)\
{\
char sig[257];\
int i;\
int argc = GetMethodArgs(methodID, sig);\
jvalue* argarray = (jvalue*)alloca(argc * sizeof(jvalue));\
for(i = 0; i < argc; i++)\
{\
switch(sig[i])\
{\
case 'Z':\
case 'B':\
case 'S':\
case 'C':\
case 'I':\
argarray[i].i = va_arg(args, int);\
break;\
case 'J':\
argarray[i].j = va_arg(args, gint64);\
break;\
case 'L':\
argarray[i].l = va_arg(args, jobject);\
break;\
case 'D':\
argarray[i].d = va_arg(args, double);\
break;\
case 'F':\
argarray[i].f = (float)va_arg(args, double);\
break;\
}\
}\
return Call##Type##MethodA(env, obj, methodID, argarray);\
}\
static type Call##Type##Method(JNIEnv *env, jobject obj, jmethodID methodID, ...) \
{\
va_list args;\
type ret;\
va_start(args, methodID);\
ret = Call##Type##MethodV(env, obj, methodID, args);\
va_end(args);\
return ret;\
}\
static type JNICALL CallNonvirtual##Type##Method (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...) \
{\
printf ("JNI Function CallNonvirtual" #Type "Method is not implemented.\n"); g_assert_not_reached ();\
return 0;\
}\
static type JNICALL CallNonvirtual##Type##MethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args) \
{\
printf ("JNI Function CallNonvirtual" #Type "MethodV is not implemented.\n"); g_assert_not_reached ();\
return 0;\
}\
static type JNICALL CallNonvirtual##Type##MethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args) \
{\
printf ("JNI Function CallNonvirtual" #Type "MethodA is not implemented.\n"); g_assert_not_reached ();\
return 0;\
}
METHOD_IMPL_MANAGED(Boolean,jboolean,gboolean)
METHOD_IMPL_MANAGED(Byte,jbyte,gchar)
METHOD_IMPL_MANAGED(Char,jchar,gunichar2)
METHOD_IMPL_MANAGED(Short,jshort,gint16)
METHOD_IMPL_MANAGED(Int,jint,gint32)
METHOD_IMPL_MANAGED(Long,jlong,gint64)
METHOD_IMPL_MANAGED(Float,jfloat,float)
METHOD_IMPL_MANAGED(Double,jdouble,double)
METHOD_IMPL(Object,jobject)
METHOD_IMPL(Boolean,jboolean)
METHOD_IMPL(Byte,jbyte)
METHOD_IMPL(Char,jchar)
METHOD_IMPL(Short,jshort)
METHOD_IMPL(Int,jint)
METHOD_IMPL(Long,jlong)
METHOD_IMPL(Float,jfloat)
METHOD_IMPL(Double,jdouble)
/* TODO: These should be put into the macros above... */
static void JNICALL CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args) {
InvokeHelper(env, obj, methodID, args);
}
static void JNICALL CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args) {
char sig[257];
int argc, i;
jvalue* argarray;
argc = GetMethodArgs(methodID, sig);
argarray = (jvalue*)alloca(argc * sizeof(jvalue));
for(i = 0; i < argc; i++)
{
switch(sig[i])
{
case 'Z':
case 'B':
case 'S':
case 'C':
case 'I':
argarray[i].i = va_arg(args, int);
break;
case 'J':
argarray[i].j = va_arg(args, gint64);
break;
case 'L':
argarray[i].l = va_arg(args, jobject);
break;
case 'D':
argarray[i].d = va_arg(args, double);
break;
case 'F':
argarray[i].f = (float)va_arg(args, double);
break;
}
}
CallVoidMethodA(env, obj, methodID, argarray);
}
static void JNICALL CallVoidMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...) {
va_list args;
va_start(args, methodID);
CallVoidMethodV(env, obj, methodID, args);
va_end(args);
}
static void JNICALL CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallNonvirtualVoidMethod is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallNonvirtualVoidMethodV is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args) { printf ("JNI Function CallNonvirtualVoidMethodA is not implemented.\n"); g_assert_not_reached (); }
static jfieldID FindFieldID(JNIEnv *env, jclass cls, const char* name, const char* sig, gboolean isstatic)
{
return (jfieldID)jniFuncs.GetFieldCookie (jniFuncs.UnwrapRef (env, cls), StringFromUTF8 (name), StringFromUTF8 (sig), isstatic);
}
static jmethodID FindMethodID(JNIEnv *env, jclass cls, const char* name, const char* sig, gboolean isstatic)
{
return (jmethodID)jniFuncs.GetMethodCookie (
jniFuncs.UnwrapRef (env, cls), StringFromUTF8(name), StringFromUTF8(sig), isstatic);
}
static jmethodID JNICALL GetMethodID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
{
return FindMethodID (env, clazz, name, sig, FALSE);
}
static jfieldID JNICALL GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
{
return FindFieldID (env, clazz, name, sig, FALSE);
}
static jfieldID JNICALL GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
{
return FindFieldID (env, clazz, name, sig, TRUE);
}
static jmethodID JNICALL GetStaticMethodID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
{
return FindMethodID (env, clazz, name, sig, TRUE);
}
#define GET_SET_FIELD(Type,type,cpptype) \
static void JNICALL Set##Type##Field(JNIEnv *env, jobject obj, jfieldID fieldID, type val)\
{\
jniFuncs.SetFieldValue (fieldID, jniFuncs.UnwrapRef (env, obj), \
box_##Type (val));\
}\
static type JNICALL Get##Type##Field(JNIEnv *env, jobject obj, jfieldID fieldID)\
{\
return *(cpptype*)BOXED_VALUE(jniFuncs.GetFieldValue (fieldID, jniFuncs.UnwrapRef (env, obj)));\
}\
static void JNICALL SetStatic##Type##Field (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)\
{\
jniFuncs.SetFieldValue (fieldID, NULL, \
box_##Type (value));\
}\
static type JNICALL GetStatic##Type##Field(JNIEnv *env, jclass clazz, jfieldID fieldID)\
{\
return *(cpptype*)BOXED_VALUE(jniFuncs.GetFieldValue (fieldID, NULL));\
}\
/* return *(cpptype*)BOXED_VALUE (jniFuncs.GetFieldValue (fieldID, jniFuncs.UnwrapRef (obj))); */
GET_SET_FIELD(Boolean,jboolean,gboolean)
GET_SET_FIELD(Byte,jbyte, gchar)
GET_SET_FIELD(Char,jchar, gunichar2)
GET_SET_FIELD(Short,jshort,gshort)
GET_SET_FIELD(Int,jint,int)
GET_SET_FIELD(Long,jlong, gint64)
GET_SET_FIELD(Float,jfloat,float)
GET_SET_FIELD(Double,jdouble,double)
static jobject JNICALL GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
{
return (jobject)(jniFuncs.MakeLocalRef (env, jniFuncs.GetFieldValue (fieldID, jniFuncs.UnwrapRef (env, obj))));
}
static void JNICALL SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
{
jniFuncs.SetFieldValue (fieldID, jniFuncs.UnwrapRef (env, obj), jniFuncs.UnwrapRef (env, val));
}
static jobject JNICALL GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
{
return (jobject)(jniFuncs.MakeLocalRef (env, jniFuncs.GetFieldValue (fieldID, NULL)));
}
static void JNICALL SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
{
jniFuncs.SetFieldValue (fieldID, NULL, jniFuncs.UnwrapRef (env, value));
}
static jobject JNICALL CallStaticObjectMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticObjectMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL CallStaticObjectMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticObjectMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jobject JNICALL CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticObjectMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jboolean JNICALL CallStaticBooleanMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticBooleanMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jboolean JNICALL CallStaticBooleanMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticBooleanMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jboolean JNICALL CallStaticBooleanMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticBooleanMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jbyte JNICALL CallStaticByteMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticByteMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jbyte JNICALL CallStaticByteMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticByteMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jbyte JNICALL CallStaticByteMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticByteMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jchar JNICALL CallStaticCharMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticCharMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jchar JNICALL CallStaticCharMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticCharMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jchar JNICALL CallStaticCharMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticCharMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jshort JNICALL CallStaticShortMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticShortMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jshort JNICALL CallStaticShortMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticShortMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jshort JNICALL CallStaticShortMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticShortMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL CallStaticIntMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticIntMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL CallStaticIntMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticIntMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL CallStaticIntMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticIntMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jlong JNICALL CallStaticLongMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticLongMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jlong JNICALL CallStaticLongMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticLongMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jlong JNICALL CallStaticLongMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticLongMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jfloat JNICALL CallStaticFloatMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticFloatMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jfloat JNICALL CallStaticFloatMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticFloatMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jfloat JNICALL CallStaticFloatMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticFloatMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static jdouble JNICALL CallStaticDoubleMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...) { printf ("JNI Function CallStaticDoubleMethod is not implemented.\n"); g_assert_not_reached (); return 0; }
static jdouble JNICALL CallStaticDoubleMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticDoubleMethodV is not implemented.\n"); g_assert_not_reached (); return 0; }
static jdouble JNICALL CallStaticDoubleMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args) { printf ("JNI Function CallStaticDoubleMethodA is not implemented.\n"); g_assert_not_reached (); return 0; }
static void JNICALL CallStaticVoidMethod (JNIEnv *env, jclass cls, jmethodID methodID, ...) { printf ("JNI Function CallStaticVoidMethod is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL CallStaticVoidMethodV (JNIEnv *env, jclass cls, jmethodID methodID, va_list args) { printf ("JNI Function CallStaticVoidMethodV is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL CallStaticVoidMethodA (JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args) { printf ("JNI Function CallStaticVoidMethodA is not implemented.\n"); g_assert_not_reached (); }
static jstring JNICALL NewString (JNIEnv *env, const jchar *unicode, jsize len) { printf ("JNI Function NewString is not implemented.\n"); g_assert_not_reached (); return 0; }
static jsize JNICALL GetStringLength (JNIEnv *env, jstring str) { printf ("JNI Function GetStringLength is not implemented.\n"); g_assert_not_reached (); return 0; }
static const jchar *JNICALL GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy) { printf ("JNI Function GetStringChars is not implemented.\n"); g_assert_not_reached (); return 0; }
static void JNICALL ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars) { printf ("JNI Function ReleaseStringChars is not implemented.\n"); g_assert_not_reached (); }
static jstring JNICALL NewStringUTF (JNIEnv *env, const char *utf)
{
return (jstring)jniFuncs.MakeLocalRef (env, StringFromUTF8 (utf));
}
static jsize JNICALL GetStringUTFLength (JNIEnv *env, jstring str) { printf ("JNI Function GetStringUTFLength is not implemented.\n"); g_assert_not_reached (); return 0; }
static const char* JNICALL GetStringUTFChars (JNIEnv *env, jstring str, jboolean *isCopy)
{
MonoString *s;
char *buf;
int i, j, e;
s = jniFuncs.UnwrapRef (env, str);
buf = g_malloc (mono_string_length (s) * 3 + 1);
j = 0;
for(i = 0, e = mono_string_length (s); i < e; i++)
{
jchar ch = mono_string_chars (s)[i];
if ((ch != 0) && (ch <=0x7f))
{
buf[j++] = (char)ch;
}
else if (ch <= 0x7FF)
{
/* 11 bits or less. */
unsigned char high_five = ch >> 6;
unsigned char low_six = ch & 0x3F;
buf[j++] = high_five | 0xC0; /* 110xxxxx */
buf[j++] = low_six | 0x80; /* 10xxxxxx */
}
else
{
/* possibly full 16 bits. */
char high_four = ch >> 12;
char mid_six = (ch >> 6) & 0x3F;
char low_six = ch & 0x3f;
buf[j++] = high_four | 0xE0; /* 1110xxxx */
buf[j++] = mid_six | 0x80; /* 10xxxxxx */
buf[j++] = low_six | 0x80; /* 10xxxxxx*/
}
}
buf[j] = 0;
if(isCopy)
{
*isCopy = JNI_TRUE;
}
return buf;
}
static void JNICALL ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
{
g_free ((char*)chars);
}
static jsize JNICALL GetArrayLength (JNIEnv *env, jarray array)
{
MonoArray *arr = jniFuncs.UnwrapRef (env, array);
return mono_array_length (arr);
}
static jobject JNICALL GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index) { printf ("JNI Function GetObjectArrayElement is not implemented.\n"); g_assert_not_reached (); return 0; }
static void JNICALL SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobject val) { printf ("JNI Function SetObjectArrayElement is not implemented.\n"); g_assert_not_reached (); }
static int new_java_array (JNIEnv *env, MonoClass *eclass, jsize len)
{
return jniFuncs.MakeLocalRef (env, mono_array_new (mono_domain_get (), eclass, len));
}
static jobjectArray JNICALL NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init) { printf ("JNI Function NewObjectArray is not implemented.\n"); g_assert_not_reached (); return 0; }
static jbooleanArray JNICALL NewBooleanArray (JNIEnv *env, jsize len)
{
return (jbooleanArray)new_java_array (env, mono_get_boolean_class (), len);
}
static jbyteArray JNICALL NewByteArray (JNIEnv *env, jsize len)
{
return (jbyteArray)new_java_array (env, mono_get_sbyte_class (), len);
}
static jcharArray JNICALL NewCharArray (JNIEnv *env, jsize len)
{
return (jcharArray)new_java_array (env, mono_get_char_class (), len);
}
static jshortArray JNICALL NewShortArray (JNIEnv *env, jsize len)
{
return (jshortArray)new_java_array (env, mono_get_int16_class (), len);
}
static jintArray JNICALL NewIntArray (JNIEnv *env, jsize len)
{
return (jintArray)new_java_array (env, mono_get_int32_class (), len);
}
static jlongArray JNICALL NewLongArray (JNIEnv *env, jsize len)
{
return (jlongArray)new_java_array (env, mono_get_int64_class (), len);
}
static jfloatArray JNICALL NewFloatArray (JNIEnv *env, jsize len)
{
return (jfloatArray)new_java_array (env, mono_get_single_class (), len);
}
static jdoubleArray JNICALL NewDoubleArray (JNIEnv *env, jsize len)
{
return (jdoubleArray)new_java_array (env, mono_get_double_class (), len);
}
/* Original version with copy */
#if 0
#define GET_SET_ARRAY_ELEMENTS(Type,type,cpptype) \
static type* JNICALL Get##Type##ArrayElements(JNIEnv *env, type##Array array, jboolean *isCopy)\
{\
int i; \
MonoArray *obj; \
type *res; \
\
obj = jniFuncs.UnwrapRef ((void*)array); \
res = g_new (type, mono_array_length (obj) + 1); \
for (i = 0; i < mono_array_length (obj); ++i) { \
res [i] = mono_array_get (obj, cpptype, i); \
} \
\
if (isCopy) \
*isCopy = JNI_TRUE; \
return res; \
} \
\
static void JNICALL Release##Type##ArrayElements(JNIEnv *env, type##Array array, type *elems, jint mode)\
{\
int i; \
MonoArray *obj; \
type *res; \
\
obj = jniFuncs.UnwrapRef ((void*)array); \
if(mode == 0)\
{\
for (i = 0; i < mono_array_length (obj); ++i) \
mono_array_get (obj, cpptype, i) = elems [i]; \
g_free (elems); \
}\
else if(mode == JNI_COMMIT)\
{\
for (i = 0; i < mono_array_length (obj); ++i) \
mono_array_get (obj, cpptype, i) = elems [i]; \
}\
else if(mode == JNI_ABORT)\
{\
g_free (elems);\
}\
}
#endif
/*
* Fast version with no copy. Works because the mono garbage collector is
* non-copying.
*/
#define GET_SET_ARRAY_ELEMENTS(Type,type,cpptype) \
static type* JNICALL Get##Type##ArrayElements(JNIEnv *env, type##Array array, jboolean *isCopy)\
{\
MonoArray *obj; \
\
obj = jniFuncs.UnwrapRef (env, (void*)array); \
if (isCopy) \
*isCopy = JNI_FALSE;\
return (type*)mono_array_addr (obj, cpptype, 0); \
} \
\
static void JNICALL Release##Type##ArrayElements(JNIEnv *env, type##Array array, type *elems, jint mode)\
{\
return; \
} \
static void JNICALL Get##Type##ArrayRegion (JNIEnv *env, type##Array array, jsize start, jsize l, type *buf) \
{\
MonoArray *obj; \
obj = jniFuncs.UnwrapRef (env, (void*)array); \
memcpy (buf, mono_array_addr (obj, sizeof (type), start), (sizeof (type) * l)); \
} \
static void JNICALL Set##Type##ArrayRegion (JNIEnv *env, type##Array array, jsize start, jsize l, type *buf) \
{ \
MonoArray *obj; \
obj = jniFuncs.UnwrapRef (env, (void*)array); \
memcpy (mono_array_addr (obj, sizeof (type), start), buf, (sizeof (type) * l)); \
}
GET_SET_ARRAY_ELEMENTS(Boolean,jboolean,gboolean)
GET_SET_ARRAY_ELEMENTS(Byte,jbyte,gchar)
GET_SET_ARRAY_ELEMENTS(Char,jchar,gunichar2)
GET_SET_ARRAY_ELEMENTS(Short,jshort,short)
GET_SET_ARRAY_ELEMENTS(Int,jint,int)
GET_SET_ARRAY_ELEMENTS(Long,jlong,glong)
GET_SET_ARRAY_ELEMENTS(Float,jfloat,float)
GET_SET_ARRAY_ELEMENTS(Double,jdouble,double)
static void * JNICALL GetPrimitiveArrayCritical (JNIEnv *env, jarray array, jboolean *isCopy) {
MonoArray *obj;
obj = jniFuncs.UnwrapRef (env, (void*)array);
if (isCopy)
*isCopy = JNI_FALSE;
return mono_array_addr (obj, void*, 0);
}
static void JNICALL ReleasePrimitiveArrayCritical (JNIEnv *env, jarray array, void *carray, jint mode) {
}
static const jchar * JNICALL GetStringCritical (JNIEnv *env, jstring string, jboolean *isCopy) {
MonoString *obj;
obj = jniFuncs.UnwrapRef (env, (void*)string);
if (isCopy)
*isCopy = JNI_FALSE;
return mono_string_chars (obj);
}
static void JNICALL ReleaseStringCritical (JNIEnv *env, jstring string, const jchar *cstring)
{
}
static jobject JNICALL NewObjectA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
{
return (jobject)jniFuncs.MakeLocalRef (env, InvokeHelper (env, NULL, methodID, args));
}
static jobject JNICALL NewObjectV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
{
char sig[257];
int i;
jvalue *argarray;
int argc;
argc = GetMethodArgs(methodID, sig);
argarray = (jvalue*)alloca(argc * sizeof(jvalue));
for(i = 0; i < argc; i++)
{
switch(sig[i])
{
case 'Z':
case 'B':
case 'S':
case 'C':
case 'I':
argarray[i].i = va_arg(args, int);
break;
case 'J':
argarray[i].j = va_arg(args, gint64);
break;
case 'L':
argarray[i].l = va_arg(args, jobject);
break;
case 'D':
argarray[i].d = va_arg(args, double);
break;
case 'F':
argarray[i].f = (float)va_arg(args, double);
break;
}
}
return NewObjectA (env, clazz, methodID, argarray);
}
static jobject JNICALL NewObject (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
{
va_list args;
jobject o;
va_start(args, methodID);
o = NewObjectV(env, clazz, methodID, args);
va_end(args);
return o;
}
static jint JNICALL RegisterNatives (JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint nMethods) { printf ("JNI Function RegisterNatives is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL UnregisterNatives (JNIEnv *env, jclass clazz) { printf ("JNI Function UnregisterNatives is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL MonitorEnter (JNIEnv *env, jobject obj) { printf ("JNI Function MonitorEnter is not implemented.\n"); g_assert_not_reached (); return 0; }
static jint JNICALL MonitorExit (JNIEnv *env, jobject obj) { printf ("JNI Function MonitorExit is not implemented.\n"); g_assert_not_reached (); return 0; }
jint JNICALL GetJavaVM (JNIEnv *env, JavaVM **vm)
{
if (!vm_ptr)
vm_ptr = (void***)&vm_func_table;
*vm = (JavaVM*)&vm_ptr;
return JNI_OK;
}
static void JNICALL GetStringRegion (JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf) { printf ("JNI Function GetStringRegion is not implemented.\n"); g_assert_not_reached (); }
static void JNICALL GetStringUTFRegion (JNIEnv *env, jstring str, jsize start, jsize len, char *buf) { printf ("JNI Function GetStringUTFRegion is not implemented.\n"); g_assert_not_reached (); }
static jweak JNICALL NewWeakGlobalRef (JNIEnv *env, jobject obj) { printf ("JNI Function NewWeakGlobalRef is not implemented.\n"); g_assert_not_reached (); return 0; }
static void JNICALL DeleteWeakGlobalRef (JNIEnv *env, jweak ref) { printf ("JNI Function DeleteWeakGlobalRef is not implemented.\n"); g_assert_not_reached (); }
static jboolean JNICALL ExceptionCheck (JNIEnv *env) {
return jniFuncs.ExceptionCheck (env);
}
static jobject JNICALL NewDirectByteBuffer (JNIEnv* env, void* address, jlong capacity) { printf ("JNI Function NewDirectByteBuffer is not implemented.\n"); g_assert_not_reached (); return 0; }
static void* JNICALL GetDirectBufferAddress (JNIEnv* env, jobject buf) { printf ("JNI Function GetDirectBufferAddress is not implemented.\n"); g_assert_not_reached (); return 0; }
static jlong JNICALL GetDirectBufferCapacity (JNIEnv* env, jobject buf) { printf ("JNI Function GetDirectBufferCapacity is not implemented.\n"); g_assert_not_reached (); return 0; }
/***************************************************************************/
/* VM FUNCTIONS */
/***************************************************************************/
static jint DestroyJavaVM (void *vm)
{
g_assert_not_reached ();
return 0;
}
static jint AttachCurrentThread (void *vm, void **penv, void *args)
{
g_assert_not_reached ();
return 0;
}
static jint DetachCurrentThread (void *vm)
{
g_assert_not_reached ();
return 0;
}
static jint GetEnv (void *vm, void **penv, jint version)
{
void *env = jniFuncs.GetJniEnv ();
if (env) {
*penv = env;
return JNI_OK;
}
else {
*penv = NULL;
return JNI_EDETACHED;
}
}
static jint AttachCurrentThreadAsDaemon (void *vm, void **penv, void *args)
{
g_assert_not_reached ();
return 0;
}
/*****************************************************************************/
static void *jni_func_table[256] = {
NULL,
NULL,
NULL,
NULL,
(void*)&GetVersion,
(void*)&DefineClass,
(void*)&FindClass,
(void*)&FromReflectedMethod,
(void*)&FromReflectedField,
(void*)&ToReflectedMethod,
(void*)&GetSuperclass,
(void*)&IsAssignableFrom,
(void*)&ToReflectedField,
(void*)&Throw,
(void*)&ThrowNew,
(void*)&ExceptionOccurred,
(void*)&ExceptionDescribe,
(void*)&ExceptionClear,
(void*)&FatalError,
(void*)&PushLocalFrame,
(void*)&PopLocalFrame,
(void*)&NewGlobalRef,
(void*)&DeleteGlobalRef,
(void*)&DeleteLocalRef,
(void*)&IsSameObject,
(void*)&NewLocalRef,
(void*)&EnsureLocalCapacity,
(void*)&AllocObject,
(void*)&NewObject,
(void*)&NewObjectV,
(void*)&NewObjectA,
(void*)&GetObjectClass,
(void*)&IsInstanceOf,
(void*)&GetMethodID,
(void*)&CallObjectMethod,
(void*)&CallObjectMethodV,
(void*)&CallObjectMethodA,
(void*)&CallBooleanMethod,
(void*)&CallBooleanMethodV,
(void*)&CallBooleanMethodA,
(void*)&CallByteMethod,
(void*)&CallByteMethodV,
(void*)&CallByteMethodA,
(void*)&CallCharMethod,
(void*)&CallCharMethodV,
(void*)&CallCharMethodA,
(void*)&CallShortMethod,
(void*)&CallShortMethodV,
(void*)&CallShortMethodA,
(void*)&CallIntMethod,
(void*)&CallIntMethodV,
(void*)&CallIntMethodA,
(void*)&CallLongMethod,
(void*)&CallLongMethodV,
(void*)&CallLongMethodA,
(void*)&CallFloatMethod,
(void*)&CallFloatMethodV,
(void*)&CallFloatMethodA,
(void*)&CallDoubleMethod,
(void*)&CallDoubleMethodV,
(void*)&CallDoubleMethodA,
(void*)&CallVoidMethod,
(void*)&CallVoidMethodV,
(void*)&CallVoidMethodA,
(void*)&CallNonvirtualObjectMethod,
(void*)&CallNonvirtualObjectMethodV,
(void*)&CallNonvirtualObjectMethodA,
(void*)&CallNonvirtualBooleanMethod,
(void*)&CallNonvirtualBooleanMethodV,
(void*)&CallNonvirtualBooleanMethodA,
(void*)&CallNonvirtualByteMethod,
(void*)&CallNonvirtualByteMethodV,
(void*)&CallNonvirtualByteMethodA,
(void*)&CallNonvirtualCharMethod,
(void*)&CallNonvirtualCharMethodV,
(void*)&CallNonvirtualCharMethodA,
(void*)&CallNonvirtualShortMethod,
(void*)&CallNonvirtualShortMethodV,
(void*)&CallNonvirtualShortMethodA,
(void*)&CallNonvirtualIntMethod,
(void*)&CallNonvirtualIntMethodV,
(void*)&CallNonvirtualIntMethodA,
(void*)&CallNonvirtualLongMethod,
(void*)&CallNonvirtualLongMethodV,
(void*)&CallNonvirtualLongMethodA,
(void*)&CallNonvirtualFloatMethod,
(void*)&CallNonvirtualFloatMethodV,
(void*)&CallNonvirtualFloatMethodA,
(void*)&CallNonvirtualDoubleMethod,
(void*)&CallNonvirtualDoubleMethodV,
(void*)&CallNonvirtualDoubleMethodA,
(void*)&CallNonvirtualVoidMethod,
(void*)&CallNonvirtualVoidMethodV,
(void*)&CallNonvirtualVoidMethodA,
(void*)&GetFieldID,
(void*)&GetObjectField,
(void*)&GetBooleanField,
(void*)&GetByteField,
(void*)&GetCharField,
(void*)&GetShortField,
(void*)&GetIntField,
(void*)&GetLongField,
(void*)&GetFloatField,
(void*)&GetDoubleField,
(void*)&SetObjectField,
(void*)&SetBooleanField,
(void*)&SetByteField,
(void*)&SetCharField,
(void*)&SetShortField,
(void*)&SetIntField,
(void*)&SetLongField,
(void*)&SetFloatField,
(void*)&SetDoubleField,
(void*)&GetStaticMethodID,
(void*)&CallStaticObjectMethod,
(void*)&CallStaticObjectMethodV,
(void*)&CallStaticObjectMethodA,
(void*)&CallStaticBooleanMethod,
(void*)&CallStaticBooleanMethodV,
(void*)&CallStaticBooleanMethodA,
(void*)&CallStaticByteMethod,
(void*)&CallStaticByteMethodV,
(void*)&CallStaticByteMethodA,
(void*)&CallStaticCharMethod,
(void*)&CallStaticCharMethodV,
(void*)&CallStaticCharMethodA,
(void*)&CallStaticShortMethod,
(void*)&CallStaticShortMethodV,
(void*)&CallStaticShortMethodA,
(void*)&CallStaticIntMethod,
(void*)&CallStaticIntMethodV,
(void*)&CallStaticIntMethodA,
(void*)&CallStaticLongMethod,
(void*)&CallStaticLongMethodV,
(void*)&CallStaticLongMethodA,
(void*)&CallStaticFloatMethod,
(void*)&CallStaticFloatMethodV,
(void*)&CallStaticFloatMethodA,
(void*)&CallStaticDoubleMethod,
(void*)&CallStaticDoubleMethodV,
(void*)&CallStaticDoubleMethodA,
(void*)&CallStaticVoidMethod,
(void*)&CallStaticVoidMethodV,
(void*)&CallStaticVoidMethodA,
(void*)&GetStaticFieldID,
(void*)&GetStaticObjectField,
(void*)&GetStaticBooleanField,
(void*)&GetStaticByteField,
(void*)&GetStaticCharField,
(void*)&GetStaticShortField,
(void*)&GetStaticIntField,
(void*)&GetStaticLongField,
(void*)&GetStaticFloatField,
(void*)&GetStaticDoubleField,
(void*)&SetStaticObjectField,
(void*)&SetStaticBooleanField,
(void*)&SetStaticByteField,
(void*)&SetStaticCharField,
(void*)&SetStaticShortField,
(void*)&SetStaticIntField,
(void*)&SetStaticLongField,
(void*)&SetStaticFloatField,
(void*)&SetStaticDoubleField,
(void*)&NewString,
(void*)&GetStringLength,
(void*)&GetStringChars,
(void*)&ReleaseStringChars,
(void*)&NewStringUTF,
(void*)&GetStringUTFLength,
(void*)&GetStringUTFChars,
(void*)&ReleaseStringUTFChars,
(void*)&GetArrayLength,
(void*)&NewObjectArray,
(void*)&GetObjectArrayElement,
(void*)&SetObjectArrayElement,
(void*)&NewBooleanArray,
(void*)&NewByteArray,
(void*)&NewCharArray,
(void*)&NewShortArray,
(void*)&NewIntArray,
(void*)&NewLongArray,
(void*)&NewFloatArray,
(void*)&NewDoubleArray,
(void*)&GetBooleanArrayElements,
(void*)&GetByteArrayElements,
(void*)&GetCharArrayElements,
(void*)&GetShortArrayElements,
(void*)&GetIntArrayElements,
(void*)&GetLongArrayElements,
(void*)&GetFloatArrayElements,
(void*)&GetDoubleArrayElements,
(void*)&ReleaseBooleanArrayElements,
(void*)&ReleaseByteArrayElements,
(void*)&ReleaseCharArrayElements,
(void*)&ReleaseShortArrayElements,
(void*)&ReleaseIntArrayElements,
(void*)&ReleaseLongArrayElements,
(void*)&ReleaseFloatArrayElements,
(void*)&ReleaseDoubleArrayElements,
(void*)&GetBooleanArrayRegion,
(void*)&GetByteArrayRegion,
(void*)&GetCharArrayRegion,
(void*)&GetShortArrayRegion,
(void*)&GetIntArrayRegion,
(void*)&GetLongArrayRegion,
(void*)&GetFloatArrayRegion,
(void*)&GetDoubleArrayRegion,
(void*)&SetBooleanArrayRegion,
(void*)&SetByteArrayRegion,
(void*)&SetCharArrayRegion,
(void*)&SetShortArrayRegion,
(void*)&SetIntArrayRegion,
(void*)&SetLongArrayRegion,
(void*)&SetFloatArrayRegion,
(void*)&SetDoubleArrayRegion,
(void*)&RegisterNatives,
(void*)&UnregisterNatives,
(void*)&MonitorEnter,
(void*)&MonitorExit,
(void*)&GetJavaVM,
(void*)&GetStringRegion,
(void*)&GetStringUTFRegion,
(void*)&GetPrimitiveArrayCritical,
(void*)&ReleasePrimitiveArrayCritical,
(void*)&GetStringCritical,
(void*)&ReleaseStringCritical,
(void*)&NewWeakGlobalRef,
(void*)&DeleteWeakGlobalRef,
(void*)&ExceptionCheck,
(void*)&NewDirectByteBuffer,
(void*)&GetDirectBufferAddress,
(void*)&GetDirectBufferCapacity
};
static void *vm_func_table[64] = {
NULL,
NULL,
NULL,
(void*)&DestroyJavaVM,
(void*)&AttachCurrentThread,
(void*)&DetachCurrentThread,
(void*)&GetEnv,
(void*)&AttachCurrentThreadAsDaemon
};
|