1 /* src/native/jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 Contact: cacao@cacaojvm.org
27 Authors: Rainhard Grafl
30 Changes: Joseph Wenninger
35 $Id: jni.c 4552 2006-03-04 17:15:44Z twisti $
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/jvmti.h"
84 #if defined(USE_THREADS)
85 # if defined(NATIVE_THREADS)
86 # include "threads/native/threads.h"
88 # include "threads/green/threads.h"
92 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/loader.h"
98 #include "vm/options.h"
99 #include "vm/resolve.h"
100 #include "vm/statistics.h"
101 #include "vm/stringlocal.h"
102 #include "vm/jit/asmpart.h"
103 #include "vm/jit/jit.h"
104 #include "vm/statistics.h"
108 /* pointers to VM and the environment needed by GetJavaVM and GetEnv */
110 static JavaVM ptr_jvm = (JavaVM) &JNI_JavaVMTable;
111 void *ptr_env = (void*) &JNI_JNIEnvTable;
114 /* global variables ***********************************************************/
116 /* global reference table *****************************************************/
118 static java_objectheader **global_ref_table;
120 /* jmethodID and jclass caching variables for NewGlobalRef and DeleteGlobalRef*/
121 static classinfo *ihmclass = NULL;
122 static methodinfo *putmid = NULL;
123 static methodinfo *getmid = NULL;
124 static methodinfo *removemid = NULL;
127 /* direct buffer stuff ********************************************************/
129 static classinfo *class_java_nio_Buffer;
130 static classinfo *class_java_nio_DirectByteBufferImpl;
131 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
132 #if SIZEOF_VOID_P == 8
133 static classinfo *class_gnu_classpath_Pointer64;
135 static classinfo *class_gnu_classpath_Pointer32;
138 static methodinfo *dbbirw_init;
141 /* local reference table ******************************************************/
143 #if !defined(USE_THREADS)
144 localref_table *_no_threads_localref_table;
148 /* accessing instance fields macros *******************************************/
150 #define SET_FIELD(o,type,f,value) \
151 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
153 #define GET_FIELD(o,type,f) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
157 /* some forward declarations **************************************************/
159 jobject NewLocalRef(JNIEnv *env, jobject ref);
162 /* jni_init ********************************************************************
164 Initialize the JNI subsystem.
166 *******************************************************************************/
170 /* initalize global reference table */
173 load_class_bootstrap(utf_new_char("java/util/IdentityHashMap"))))
176 global_ref_table = GCNEW(jobject);
178 if (!(*global_ref_table = native_new_and_init(ihmclass)))
181 if (!(getmid = class_resolvemethod(ihmclass, utf_get,
182 utf_java_lang_Object__java_lang_Object)))
185 if (!(putmid = class_resolvemethod(ihmclass, utf_put,
186 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))))
190 class_resolvemethod(ihmclass, utf_remove,
191 utf_java_lang_Object__java_lang_Object)))
195 /* direct buffer stuff */
197 if (!(class_java_nio_Buffer =
198 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
199 !link_class(class_java_nio_Buffer))
202 if (!(class_java_nio_DirectByteBufferImpl =
203 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
204 !link_class(class_java_nio_DirectByteBufferImpl))
207 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
208 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
209 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
213 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
215 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
218 #if SIZEOF_VOID_P == 8
219 if (!(class_gnu_classpath_Pointer64 =
220 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
221 !link_class(class_gnu_classpath_Pointer64))
224 if (!(class_gnu_classpath_Pointer32 =
225 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
226 !link_class(class_gnu_classpath_Pointer32))
234 /* _Jv_jni_fill_vmargs_from_vargs **********************************************
238 *******************************************************************************/
240 static void _Jv_jni_vmargs_from_vargs(java_objectheader *o, methoddesc *descr,
241 vm_arg *vmargs, va_list ap)
243 typedesc *paramtypes;
246 paramtypes = descr->paramtypes;
248 /* if method is non-static fill first block and skip `this' pointer */
253 /* the `this' pointer */
254 vmargs[0].type = TYPE_ADR;
255 vmargs[0].data = (u8) (ptrint) o;
261 for (; i < descr->paramcount; i++, paramtypes++) {
262 switch (paramtypes->decltype) {
263 /* primitive types */
264 case PRIMITIVETYPE_BYTE:
265 case PRIMITIVETYPE_CHAR:
266 case PRIMITIVETYPE_SHORT:
267 case PRIMITIVETYPE_BOOLEAN:
268 case PRIMITIVETYPE_INT:
269 vmargs[i].type = TYPE_INT;
270 vmargs[i].data = (s8) va_arg(ap, s4);
273 case PRIMITIVETYPE_LONG:
274 vmargs[i].type = TYPE_LNG;
275 vmargs[i].data = (s8) va_arg(ap, s8);
278 case PRIMITIVETYPE_FLOAT:
279 vmargs[i].type = TYPE_FLT;
280 #if defined(__ALPHA__)
281 /* this keeps the assembler function much simpler */
283 *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
285 *((jfloat *) (&vmargs[i].data)) = (jfloat) va_arg(ap, jdouble);
289 case PRIMITIVETYPE_DOUBLE:
290 vmargs[i].type = TYPE_DBL;
291 *((jdouble *) (&vmargs[i].data)) = (jdouble) va_arg(ap, jdouble);
295 vmargs[i].type = TYPE_ADR;
296 vmargs[i].data = (u8) (ptrint) va_arg(ap, void*);
303 /* _Jv_jni_vmargs_from_objectarray *********************************************
307 *******************************************************************************/
309 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
312 java_objectarray *params)
314 java_objectheader *param;
316 typedesc *paramtypes;
321 paramcount = descr->paramcount;
322 paramtypes = descr->paramtypes;
324 /* if method is non-static fill first block and skip `this' pointer */
330 vmargs[0].type = TYPE_ADR;
331 vmargs[0].data = (u8) (ptrint) o;
338 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
339 switch (paramtypes->type) {
340 /* primitive types */
345 param = params->data[j];
350 /* internally used data type */
351 vmargs[i].type = paramtypes->type;
353 /* convert the value according to its declared type */
355 c = param->vftbl->class;
357 switch (paramtypes->decltype) {
358 case PRIMITIVETYPE_BOOLEAN:
359 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
360 vmargs[i].data = (s8) ((java_lang_Boolean *) param)->value;
365 case PRIMITIVETYPE_BYTE:
366 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
367 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
372 case PRIMITIVETYPE_CHAR:
373 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
374 vmargs[i].data = (s8) ((java_lang_Character *) param)->value;
379 case PRIMITIVETYPE_SHORT:
380 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
381 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
382 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
383 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
388 case PRIMITIVETYPE_INT:
389 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
390 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
391 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
392 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
393 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
394 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
399 case PRIMITIVETYPE_LONG:
400 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
401 vmargs[i].data = (s8) ((java_lang_Long *) param)->value;
402 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
403 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
404 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
405 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
406 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
407 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
412 case PRIMITIVETYPE_FLOAT:
413 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
414 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
419 case PRIMITIVETYPE_DOUBLE:
420 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
421 *((jdouble *) (&vmargs[i].data)) = (jdouble) ((java_lang_Double *) param)->value;
422 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
423 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
434 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
437 if (params->data[j] != 0) {
438 if (paramtypes->arraydim > 0) {
439 if (!builtin_arrayinstanceof(params->data[j], c))
443 if (!builtin_instanceof(params->data[j], c))
447 vmargs[i].type = TYPE_ADR;
448 vmargs[i].data = (u8) (ptrint) params->data[j];
457 /* *rettype = descr->returntype.decltype; */
462 exceptions_throw_illegalargumentexception();
467 /* _Jv_jni_vmargs_from_objectarray *********************************************
471 *******************************************************************************/
473 static void _Jv_jni_vmargs_from_args(java_objectheader *o, methoddesc *descr,
474 vm_arg *vmargs, jvalue *args)
476 typedesc *paramtypes;
480 paramtypes = descr->paramtypes;
482 /* if method is non-static fill first block and skip `this' pointer */
487 /* the `this' pointer */
488 vmargs[0].type = TYPE_ADR;
489 vmargs[0].data = (u8) (ptrint) o;
495 for (j = 0; i < descr->paramcount; i++, j++, paramtypes++) {
496 switch (paramtypes->decltype) {
497 /* primitive types */
498 case PRIMITIVETYPE_BOOLEAN:
499 case PRIMITIVETYPE_BYTE:
500 case PRIMITIVETYPE_CHAR:
501 case PRIMITIVETYPE_SHORT:
502 case PRIMITIVETYPE_INT:
503 vmargs[i].type = TYPE_INT;
504 vmargs[i].data = (s8) args[j].i;
507 case PRIMITIVETYPE_LONG:
508 vmargs[i].type = TYPE_LNG;
509 vmargs[i].data = (s8) args[j].j;
512 case PRIMITIVETYPE_FLOAT:
513 vmargs[i].type = TYPE_FLT;
514 #if defined(__ALPHA__)
515 /* this keeps the assembler function much simpler */
517 *((jdouble *) (&vmargs[i].data)) = (jdouble) args[j].f;
519 *((jfloat *) (&vmargs[i].data)) = args[j].f;
523 case PRIMITIVETYPE_DOUBLE:
524 vmargs[i].type = TYPE_DBL;
525 *((jdouble *) (&vmargs[i].data)) = args[j].d;
529 vmargs[i].type = TYPE_ADR;
530 vmargs[i].data = (u8) (ptrint) args[j].l;
537 /* _Jv_jni_CallObjectMethod ****************************************************
539 Internal function to call Java Object methods.
541 *******************************************************************************/
543 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
545 methodinfo *m, va_list ap)
550 java_objectheader *ret;
553 STATISTICS(jniinvokation());
556 exceptions_throw_nullpointerexception();
560 /* Class initialization is done by the JIT compiler. This is ok
561 since a static method always belongs to the declaring class. */
563 if (m->flags & ACC_STATIC) {
564 /* For static methods we reset the object. */
569 /* for convenience */
574 /* For instance methods we make a virtual function table lookup. */
576 resm = method_vftbl_lookup(vftbl, m);
579 /* mark start of dump memory area */
581 dumpsize = dump_size();
583 paramcount = resm->parseddesc->paramcount;
585 vmargs = DMNEW(vm_arg, paramcount);
587 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
589 STATISTICS(jnicallXmethodnvokation());
591 ret = vm_call_method(resm, paramcount, vmargs);
593 /* release dump area */
595 dump_release(dumpsize);
601 /* _Jv_jni_CallIntMethod *******************************************************
603 Internal function to call Java integer class methods (boolean,
604 byte, char, short, int).
606 *******************************************************************************/
608 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
609 methodinfo *m, va_list ap, s4 type)
617 STATISTICS(jniinvokation());
620 exceptions_throw_nullpointerexception();
624 /* Class initialization is done by the JIT compiler. This is ok
625 since a static method always belongs to the declaring class. */
627 if (m->flags & ACC_STATIC) {
628 /* For static methods we reset the object. */
633 /* for convenience */
638 /* For instance methods we make a virtual function table lookup. */
640 resm = method_vftbl_lookup(vftbl, m);
643 /* mark start of dump memory area */
645 dumpsize = dump_size();
647 paramcount = resm->parseddesc->paramcount;
649 vmargs = DMNEW(vm_arg, paramcount);
651 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
653 STATISTICS(jnicallXmethodnvokation());
655 ret = vm_call_method_int(resm, paramcount, vmargs);
657 /* release dump area */
659 dump_release(dumpsize);
665 /* _Jv_jni_CallLongMethod ******************************************************
667 Internal function to call Java long methods.
669 *******************************************************************************/
671 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
672 methodinfo *m, va_list ap)
680 STATISTICS(jniinvokation());
683 exceptions_throw_nullpointerexception();
687 /* Class initialization is done by the JIT compiler. This is ok
688 since a static method always belongs to the declaring class. */
690 if (m->flags & ACC_STATIC) {
691 /* For static methods we reset the object. */
696 /* for convenience */
701 /* For instance methods we make a virtual function table lookup. */
703 resm = method_vftbl_lookup(vftbl, m);
706 /* mark start of dump memory area */
708 dumpsize = dump_size();
710 paramcount = resm->parseddesc->paramcount;
712 vmargs = DMNEW(vm_arg, paramcount);
714 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
716 STATISTICS(jnicallXmethodnvokation());
718 ret = vm_call_method_long(resm, paramcount, vmargs);
720 /* release dump area */
722 dump_release(dumpsize);
728 /* _Jv_jni_CallFloatMethod *****************************************************
730 Internal function to call Java float methods.
732 *******************************************************************************/
734 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
735 methodinfo *m, va_list ap)
743 /* Class initialization is done by the JIT compiler. This is ok
744 since a static method always belongs to the declaring class. */
746 if (m->flags & ACC_STATIC) {
747 /* For static methods we reset the object. */
752 /* for convenience */
757 /* For instance methods we make a virtual function table lookup. */
759 resm = method_vftbl_lookup(vftbl, m);
762 /* mark start of dump memory area */
764 dumpsize = dump_size();
766 paramcount = resm->parseddesc->paramcount;
768 vmargs = DMNEW(vm_arg, paramcount);
770 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
772 STATISTICS(jnicallXmethodnvokation());
774 ret = vm_call_method_float(resm, paramcount, vmargs);
776 /* release dump area */
778 dump_release(dumpsize);
784 /* _Jv_jni_CallDoubleMethod ****************************************************
786 Internal function to call Java double methods.
788 *******************************************************************************/
790 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
791 methodinfo *m, va_list ap)
799 /* Class initialization is done by the JIT compiler. This is ok
800 since a static method always belongs to the declaring class. */
802 if (m->flags & ACC_STATIC) {
803 /* For static methods we reset the object. */
808 /* for convenience */
813 /* For instance methods we make a virtual function table lookup. */
815 resm = method_vftbl_lookup(vftbl, m);
818 /* mark start of dump memory area */
820 dumpsize = dump_size();
822 paramcount = resm->parseddesc->paramcount;
824 vmargs = DMNEW(vm_arg, paramcount);
826 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
828 STATISTICS(jnicallXmethodnvokation());
830 ret = vm_call_method_double(resm, paramcount, vmargs);
832 /* release dump area */
834 dump_release(dumpsize);
840 /* _Jv_jni_CallVoidMethod ******************************************************
842 Internal function to call Java void methods.
844 *******************************************************************************/
846 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
847 methodinfo *m, va_list ap)
855 exceptions_throw_nullpointerexception();
859 /* Class initialization is done by the JIT compiler. This is ok
860 since a static method always belongs to the declaring class. */
862 if (m->flags & ACC_STATIC) {
863 /* For static methods we reset the object. */
868 /* for convenience */
873 /* For instance methods we make a virtual function table lookup. */
875 resm = method_vftbl_lookup(vftbl, m);
878 /* mark start of dump memory area */
880 dumpsize = dump_size();
882 paramcount = resm->parseddesc->paramcount;
884 vmargs = DMNEW(vm_arg, paramcount);
886 _Jv_jni_vmargs_from_vargs(o, resm->parseddesc, vmargs, ap);
888 STATISTICS(jnicallXmethodnvokation());
890 (void) vm_call_method(resm, paramcount, vmargs);
892 /* release dump area */
894 dump_release(dumpsize);
898 /* _Jv_jni_CallVoidMethodA *****************************************************
900 Internal function to call Java void methods.
902 *******************************************************************************/
904 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
905 methodinfo *m, jvalue *args)
913 exceptions_throw_nullpointerexception();
917 /* Class initialization is done by the JIT compiler. This is ok
918 since a static method always belongs to the declaring class. */
920 if (m->flags & ACC_STATIC) {
921 /* For static methods we reset the object. */
926 /* for convenience */
931 /* For instance methods we make a virtual function table lookup. */
933 resm = method_vftbl_lookup(vftbl, m);
936 /* mark start of dump memory area */
938 dumpsize = dump_size();
940 paramcount = resm->parseddesc->paramcount;
942 vmargs = DMNEW(vm_arg, paramcount);
944 _Jv_jni_vmargs_from_args(o, resm->parseddesc, vmargs, args);
946 STATISTICS(jnicallXmethodnvokation());
948 (void) vm_call_method(resm, paramcount, vmargs);
950 /* release dump area */
952 dump_release(dumpsize);
956 /* _Jv_jni_invokeNative ********************************************************
958 Invoke a method on the given object with the given arguments.
960 For instance methods OBJ must be != NULL and the method is looked up
961 in the vftbl of the object.
963 For static methods, OBJ is ignored.
965 *******************************************************************************/
967 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
968 java_objectarray *params)
972 java_objectheader *ro;
977 exceptions_throw_nullpointerexception();
981 argcount = m->parseddesc->paramcount;
982 paramcount = argcount;
984 /* if method is non-static, remove the `this' pointer */
986 if (!(m->flags & ACC_STATIC))
989 /* For instance methods the object has to be an instance of the
990 class the method belongs to. For static methods the obj
991 parameter is ignored. */
993 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
995 new_exception_message(string_java_lang_IllegalArgumentException,
996 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
1000 /* check if we got the right number of arguments */
1002 if (((params == NULL) && (paramcount != 0)) ||
1003 (params && (params->header.size != paramcount)))
1006 new_exception(string_java_lang_IllegalArgumentException);
1010 /* for instance methods we need an object */
1012 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
1014 new_exception_message(string_java_lang_NullPointerException,
1015 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
1019 /* for static methods, zero object to make subsequent code simpler */
1020 if (m->flags & ACC_STATIC)
1024 /* for instance methods we must do a vftbl lookup */
1025 resm = method_vftbl_lookup(o->vftbl, m);
1028 /* for static methods, just for convenience */
1032 vmargs = MNEW(vm_arg, argcount);
1034 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
1037 switch (resm->parseddesc->returntype.decltype) {
1039 (void) vm_call_method(resm, argcount, vmargs);
1044 case PRIMITIVETYPE_BOOLEAN: {
1046 java_lang_Boolean *bo;
1048 i = vm_call_method_int(resm, argcount, vmargs);
1050 ro = builtin_new(class_java_lang_Boolean);
1052 /* setting the value of the object direct */
1054 bo = (java_lang_Boolean *) ro;
1059 case PRIMITIVETYPE_BYTE: {
1063 i = vm_call_method_int(resm, argcount, vmargs);
1065 ro = builtin_new(class_java_lang_Byte);
1067 /* setting the value of the object direct */
1069 bo = (java_lang_Byte *) ro;
1074 case PRIMITIVETYPE_CHAR: {
1076 java_lang_Character *co;
1078 i = vm_call_method_int(resm, argcount, vmargs);
1080 ro = builtin_new(class_java_lang_Character);
1082 /* setting the value of the object direct */
1084 co = (java_lang_Character *) ro;
1089 case PRIMITIVETYPE_SHORT: {
1091 java_lang_Short *so;
1093 i = vm_call_method_int(resm, argcount, vmargs);
1095 ro = builtin_new(class_java_lang_Short);
1097 /* setting the value of the object direct */
1099 so = (java_lang_Short *) ro;
1104 case PRIMITIVETYPE_INT: {
1106 java_lang_Integer *io;
1108 i = vm_call_method_int(resm, argcount, vmargs);
1110 ro = builtin_new(class_java_lang_Integer);
1112 /* setting the value of the object direct */
1114 io = (java_lang_Integer *) ro;
1119 case PRIMITIVETYPE_LONG: {
1123 l = vm_call_method_long(resm, argcount, vmargs);
1125 ro = builtin_new(class_java_lang_Long);
1127 /* setting the value of the object direct */
1129 lo = (java_lang_Long *) ro;
1134 case PRIMITIVETYPE_FLOAT: {
1136 java_lang_Float *fo;
1138 f = vm_call_method_float(resm, argcount, vmargs);
1140 ro = builtin_new(class_java_lang_Float);
1142 /* setting the value of the object direct */
1144 fo = (java_lang_Float *) ro;
1149 case PRIMITIVETYPE_DOUBLE: {
1151 java_lang_Double *_do;
1153 d = vm_call_method_double(resm, argcount, vmargs);
1155 ro = builtin_new(class_java_lang_Double);
1157 /* setting the value of the object direct */
1159 _do = (java_lang_Double *) ro;
1165 ro = vm_call_method(resm, argcount, vmargs);
1169 /* if this happens the exception has already been set by
1170 fill_callblock_from_objectarray */
1172 MFREE(vmargs, vm_arg, argcount);
1177 MFREE(vmargs, vm_arg, argcount);
1179 if (*exceptionptr) {
1180 java_objectheader *cause;
1182 cause = *exceptionptr;
1184 /* clear exception pointer, we are calling JIT code again */
1186 *exceptionptr = NULL;
1189 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1190 (java_lang_Throwable *) cause);
1197 /* GetVersion ******************************************************************
1199 Returns the major version number in the higher 16 bits and the
1200 minor version number in the lower 16 bits.
1202 *******************************************************************************/
1204 jint GetVersion(JNIEnv *env)
1206 STATISTICS(jniinvokation());
1208 /* we support JNI 1.4 */
1210 return JNI_VERSION_1_4;
1214 /* Class Operations ***********************************************************/
1216 /* DefineClass *****************************************************************
1218 Loads a class from a buffer of raw class data. The buffer
1219 containing the raw class data is not referenced by the VM after the
1220 DefineClass call returns, and it may be discarded if desired.
1222 *******************************************************************************/
1224 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1225 const jbyte *buf, jsize bufLen)
1227 java_lang_ClassLoader *cl;
1228 java_lang_String *s;
1232 STATISTICS(jniinvokation());
1234 cl = (java_lang_ClassLoader *) loader;
1235 s = javastring_new_char(name);
1236 ba = (java_bytearray *) buf;
1238 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1241 return (jclass) NewLocalRef(env, (jobject) c);
1245 /* FindClass *******************************************************************
1247 This function loads a locally-defined class. It searches the
1248 directories and zip files specified by the CLASSPATH environment
1249 variable for the class with the specified name.
1251 *******************************************************************************/
1253 jclass FindClass(JNIEnv *env, const char *name)
1259 STATISTICS(jniinvokation());
1261 u = utf_new_char_classname((char *) name);
1263 /* Check stacktrace for classloader, if one found use it,
1264 otherwise use the system classloader. */
1266 /* Quote from the JNI documentation:
1268 In the Java 2 Platform, FindClass locates the class loader
1269 associated with the current native method. If the native code
1270 belongs to a system class, no class loader will be
1271 involved. Otherwise, the proper class loader will be invoked to
1272 load and link the named class. When FindClass is called through
1273 the Invocation Interface, there is no current native method or
1274 its associated class loader. In that case, the result of
1275 ClassLoader.getBaseClassLoader is used." */
1277 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1278 /* these JITs support stacktraces, and so does the interpreter */
1280 cc = stacktrace_getCurrentClass();
1282 # if defined(ENABLE_INTRP)
1283 /* the interpreter supports stacktraces, even if the JIT does not */
1286 cc = stacktrace_getCurrentClass();
1292 /* if no Java method was found, use the system classloader */
1295 c = load_class_from_sysloader(u);
1297 c = load_class_from_classloader(u, cc->classloader);
1305 return (jclass) NewLocalRef(env, (jobject) c);
1309 /* GetSuperclass ***************************************************************
1311 If clazz represents any class other than the class Object, then
1312 this function returns the object that represents the superclass of
1313 the class specified by clazz.
1315 *******************************************************************************/
1317 jclass GetSuperclass(JNIEnv *env, jclass sub)
1321 STATISTICS(jniinvokation());
1323 c = ((classinfo *) sub)->super.cls;
1328 return (jclass) NewLocalRef(env, (jobject) c);
1332 /* IsAssignableFrom ************************************************************
1334 Determines whether an object of sub can be safely cast to sup.
1336 *******************************************************************************/
1338 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1340 STATISTICS(jniinvokation());
1342 return Java_java_lang_VMClass_isAssignableFrom(env,
1344 (java_lang_Class *) sup,
1345 (java_lang_Class *) sub);
1349 /* Throw ***********************************************************************
1351 Causes a java.lang.Throwable object to be thrown.
1353 *******************************************************************************/
1355 jint Throw(JNIEnv *env, jthrowable obj)
1357 STATISTICS(jniinvokation());
1359 *exceptionptr = (java_objectheader *) obj;
1365 /* ThrowNew ********************************************************************
1367 Constructs an exception object from the specified class with the
1368 message specified by message and causes that exception to be
1371 *******************************************************************************/
1373 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1375 java_lang_Throwable *o;
1376 java_lang_String *s;
1378 STATISTICS(jniinvokation());
1380 s = (java_lang_String *) javastring_new_char(msg);
1382 /* instantiate exception object */
1384 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1390 *exceptionptr = (java_objectheader *) o;
1396 /* ExceptionOccurred ***********************************************************
1398 Determines if an exception is being thrown. The exception stays
1399 being thrown until either the native code calls ExceptionClear(),
1400 or the Java code handles the exception.
1402 *******************************************************************************/
1404 jthrowable ExceptionOccurred(JNIEnv *env)
1406 java_objectheader *e;
1408 STATISTICS(jniinvokation());
1412 return NewLocalRef(env, (jthrowable) e);
1416 /* ExceptionDescribe ***********************************************************
1418 Prints an exception and a backtrace of the stack to a system
1419 error-reporting channel, such as stderr. This is a convenience
1420 routine provided for debugging.
1422 *******************************************************************************/
1424 void ExceptionDescribe(JNIEnv *env)
1426 java_objectheader *e;
1429 STATISTICS(jniinvokation());
1434 /* clear exception, because we are calling jit code again */
1436 *exceptionptr = NULL;
1438 /* get printStackTrace method from exception class */
1440 m = class_resolveclassmethod(e->vftbl->class,
1441 utf_printStackTrace,
1447 /* XXX what should we do? */
1450 /* print the stacktrace */
1452 (void) vm_call_method_intern(m, e, NULL, NULL, NULL);
1457 /* ExceptionClear **************************************************************
1459 Clears any exception that is currently being thrown. If no
1460 exception is currently being thrown, this routine has no effect.
1462 *******************************************************************************/
1464 void ExceptionClear(JNIEnv *env)
1466 STATISTICS(jniinvokation());
1468 *exceptionptr = NULL;
1472 /* FatalError ******************************************************************
1474 Raises a fatal error and does not expect the VM to recover. This
1475 function does not return.
1477 *******************************************************************************/
1479 void FatalError(JNIEnv *env, const char *msg)
1481 STATISTICS(jniinvokation());
1483 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1487 /* PushLocalFrame **************************************************************
1489 Creates a new local reference frame, in which at least a given
1490 number of local references can be created.
1492 *******************************************************************************/
1494 jint PushLocalFrame(JNIEnv* env, jint capacity)
1496 STATISTICS(jniinvokation());
1498 log_text("JNI-Call: PushLocalFrame: IMPLEMENT ME!");
1505 /* PopLocalFrame ***************************************************************
1507 Pops off the current local reference frame, frees all the local
1508 references, and returns a local reference in the previous local
1509 reference frame for the given result object.
1511 *******************************************************************************/
1513 jobject PopLocalFrame(JNIEnv* env, jobject result)
1515 STATISTICS(jniinvokation());
1517 log_text("JNI-Call: PopLocalFrame: IMPLEMENT ME!");
1521 /* add local reference and return the value */
1523 return NewLocalRef(env, NULL);
1527 /* DeleteLocalRef **************************************************************
1529 Deletes the local reference pointed to by localRef.
1531 *******************************************************************************/
1533 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1535 java_objectheader *o;
1536 localref_table *lrt;
1539 STATISTICS(jniinvokation());
1541 o = (java_objectheader *) localRef;
1543 /* get local reference table (thread specific) */
1545 lrt = LOCALREFTABLE;
1547 /* remove the reference */
1549 for (i = 0; i < lrt->capacity; i++) {
1550 if (lrt->refs[i] == o) {
1551 lrt->refs[i] = NULL;
1558 /* this should not happen */
1560 /* if (opt_checkjni) */
1561 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1562 log_text("JNI-DeleteLocalRef: Bad global or local ref passed to JNI");
1566 /* IsSameObject ****************************************************************
1568 Tests whether two references refer to the same Java object.
1570 *******************************************************************************/
1572 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1574 STATISTICS(jniinvokation());
1583 /* NewLocalRef *****************************************************************
1585 Creates a new local reference that refers to the same object as ref.
1587 *******************************************************************************/
1589 jobject NewLocalRef(JNIEnv *env, jobject ref)
1591 localref_table *lrt;
1594 STATISTICS(jniinvokation());
1599 /* get local reference table (thread specific) */
1601 lrt = LOCALREFTABLE;
1603 /* check if we have space for the requested reference */
1605 if (lrt->used == lrt->capacity) {
1606 /* throw_cacao_exception_exit(string_java_lang_InternalError, */
1607 /* "Too many local references"); */
1608 fprintf(stderr, "Too many local references");
1612 /* insert the reference */
1614 for (i = 0; i < lrt->capacity; i++) {
1615 if (lrt->refs[i] == NULL) {
1616 lrt->refs[i] = (java_objectheader *) ref;
1623 /* should not happen, just to be sure */
1627 /* keep compiler happy */
1633 /* EnsureLocalCapacity *********************************************************
1635 Ensures that at least a given number of local references can be
1636 created in the current thread
1638 *******************************************************************************/
1640 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1642 localref_table *lrt;
1644 STATISTICS(jniinvokation());
1646 /* get local reference table (thread specific) */
1648 lrt = LOCALREFTABLE;
1650 /* check if capacity elements are available in the local references table */
1652 if ((lrt->used + capacity) > lrt->capacity) {
1653 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
1661 /* AllocObject *****************************************************************
1663 Allocates a new Java object without invoking any of the
1664 constructors for the object. Returns a reference to the object.
1666 *******************************************************************************/
1668 jobject AllocObject(JNIEnv *env, jclass clazz)
1671 java_objectheader *o;
1673 STATISTICS(jniinvokation());
1675 c = (classinfo *) clazz;
1677 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1679 new_exception_utfmessage(string_java_lang_InstantiationException,
1686 return NewLocalRef(env, o);
1690 /* NewObject *******************************************************************
1692 Programmers place all arguments that are to be passed to the
1693 constructor immediately following the methodID
1694 argument. NewObject() accepts these arguments and passes them to
1695 the Java method that the programmer wishes to invoke.
1697 *******************************************************************************/
1699 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1701 java_objectheader *o;
1705 STATISTICS(jniinvokation());
1707 m = (methodinfo *) methodID;
1711 o = builtin_new(clazz);
1716 /* call constructor */
1718 va_start(ap, methodID);
1719 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1722 return NewLocalRef(env, o);
1726 /* NewObjectV ******************************************************************
1728 Programmers place all arguments that are to be passed to the
1729 constructor in an args argument of type va_list that immediately
1730 follows the methodID argument. NewObjectV() accepts these
1731 arguments, and, in turn, passes them to the Java method that the
1732 programmer wishes to invoke.
1734 *******************************************************************************/
1736 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1738 java_objectheader *o;
1741 STATISTICS(jniinvokation());
1743 m = (methodinfo *) methodID;
1747 o = builtin_new(clazz);
1752 /* call constructor */
1754 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1756 return NewLocalRef(env, o);
1760 /* NewObjectA *****************************************************************
1762 Programmers place all arguments that are to be passed to the
1763 constructor in an args array of jvalues that immediately follows
1764 the methodID argument. NewObjectA() accepts the arguments in this
1765 array, and, in turn, passes them to the Java method that the
1766 programmer wishes to invoke.
1768 *******************************************************************************/
1770 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1772 java_objectheader *o;
1775 STATISTICS(jniinvokation());
1777 m = (methodinfo *) methodID;
1781 o = builtin_new(clazz);
1786 /* call constructor */
1788 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1790 return NewLocalRef(env, o);
1794 /* GetObjectClass **************************************************************
1796 Returns the class of an object.
1798 *******************************************************************************/
1800 jclass GetObjectClass(JNIEnv *env, jobject obj)
1802 java_objectheader *o;
1805 STATISTICS(jniinvokation());
1807 o = (java_objectheader *) obj;
1809 if ((o == NULL) || (o->vftbl == NULL))
1812 c = o->vftbl->class;
1814 return (jclass) NewLocalRef(env, (jobject) c);
1818 /* IsInstanceOf ****************************************************************
1820 Tests whether an object is an instance of a class.
1822 *******************************************************************************/
1824 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1826 STATISTICS(jniinvokation());
1828 return Java_java_lang_VMClass_isInstance(env,
1830 (java_lang_Class *) clazz,
1831 (java_lang_Object *) obj);
1835 /* Reflection Support *********************************************************/
1837 /* FromReflectedMethod *********************************************************
1839 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1840 object to a method ID.
1842 *******************************************************************************/
1844 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1850 STATISTICS(jniinvokation());
1855 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1856 java_lang_reflect_Method *rm;
1858 rm = (java_lang_reflect_Method *) method;
1859 c = (classinfo *) (rm->declaringClass);
1862 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1863 java_lang_reflect_Constructor *rc;
1865 rc = (java_lang_reflect_Constructor *) method;
1866 c = (classinfo *) (rc->clazz);
1872 mi = &(c->methods[slot]);
1874 return (jmethodID) mi;
1878 /* FromReflectedField **********************************************************
1880 Converts a java.lang.reflect.Field to a field ID.
1882 *******************************************************************************/
1884 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1886 java_lang_reflect_Field *rf;
1890 STATISTICS(jniinvokation());
1892 rf = (java_lang_reflect_Field *) field;
1897 c = (classinfo *) rf->declaringClass;
1899 f = &(c->fields[rf->slot]);
1901 return (jfieldID) f;
1905 /* ToReflectedMethod ***********************************************************
1907 Converts a method ID derived from cls to an instance of the
1908 java.lang.reflect.Method class or to an instance of the
1909 java.lang.reflect.Constructor class.
1911 *******************************************************************************/
1913 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1915 STATISTICS(jniinvokation());
1917 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1923 /* ToReflectedField ************************************************************
1925 Converts a field ID derived from cls to an instance of the
1926 java.lang.reflect.Field class.
1928 *******************************************************************************/
1930 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1933 STATISTICS(jniinvokation());
1935 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1941 /* Calling Instance Methods ***************************************************/
1943 /* GetMethodID *****************************************************************
1945 Returns the method ID for an instance (nonstatic) method of a class
1946 or interface. The method may be defined in one of the clazz's
1947 superclasses and inherited by clazz. The method is determined by
1948 its name and signature.
1950 GetMethodID() causes an uninitialized class to be initialized.
1952 *******************************************************************************/
1954 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1962 STATISTICS(jniinvokation());
1964 c = (classinfo *) clazz;
1969 if (!(c->state & CLASS_INITIALIZED))
1970 if (!initialize_class(c))
1973 /* try to get the method of the class or one of it's superclasses */
1975 uname = utf_new_char((char *) name);
1976 udesc = utf_new_char((char *) sig);
1978 m = class_resolvemethod(clazz, uname, udesc);
1980 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1981 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1986 return (jmethodID) m;
1990 /* JNI-functions for calling instance methods *********************************/
1992 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1994 java_objectheader *o;
1996 java_objectheader *ret;
1999 o = (java_objectheader *) obj;
2000 m = (methodinfo *) methodID;
2002 va_start(ap, methodID);
2003 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2006 return NewLocalRef(env, ret);
2010 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2012 java_objectheader *o;
2014 java_objectheader *ret;
2016 o = (java_objectheader *) obj;
2017 m = (methodinfo *) methodID;
2019 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2021 return NewLocalRef(env, ret);
2025 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
2027 log_text("JNI-Call: CallObjectMethodA: IMPLEMENT ME!");
2029 return NewLocalRef(env, NULL);
2033 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2035 java_objectheader *o;
2040 o = (java_objectheader *) obj;
2041 m = (methodinfo *) methodID;
2043 va_start(ap, methodID);
2044 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap, PRIMITIVETYPE_BOOLEAN);
2051 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2053 java_objectheader *o;
2057 o = (java_objectheader *) obj;
2058 m = (methodinfo *) methodID;
2060 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args, PRIMITIVETYPE_BOOLEAN);
2066 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
2068 log_text("JNI-Call: CallBooleanMethodA");
2074 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2076 java_objectheader *o;
2081 o = (java_objectheader *) obj;
2082 m = (methodinfo *) methodID;
2084 va_start(ap, methodID);
2085 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap, PRIMITIVETYPE_BYTE);
2092 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2094 java_objectheader *o;
2098 o = (java_objectheader *) obj;
2099 m = (methodinfo *) methodID;
2101 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args, PRIMITIVETYPE_BYTE);
2107 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2109 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2115 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2117 java_objectheader *o;
2122 o = (java_objectheader *) obj;
2123 m = (methodinfo *) methodID;
2125 va_start(ap, methodID);
2126 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap, PRIMITIVETYPE_CHAR);
2133 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2135 java_objectheader *o;
2139 o = (java_objectheader *) obj;
2140 m = (methodinfo *) methodID;
2142 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args, PRIMITIVETYPE_CHAR);
2148 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2150 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2156 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2158 java_objectheader *o;
2163 o = (java_objectheader *) obj;
2164 m = (methodinfo *) methodID;
2166 va_start(ap, methodID);
2167 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap, PRIMITIVETYPE_SHORT);
2174 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2176 java_objectheader *o;
2180 o = (java_objectheader *) obj;
2181 m = (methodinfo *) methodID;
2183 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args, PRIMITIVETYPE_SHORT);
2189 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2191 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2198 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2200 java_objectheader *o;
2205 o = (java_objectheader *) obj;
2206 m = (methodinfo *) methodID;
2208 va_start(ap, methodID);
2209 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap, PRIMITIVETYPE_INT);
2216 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2218 java_objectheader *o;
2222 o = (java_objectheader *) obj;
2223 m = (methodinfo *) methodID;
2225 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args, PRIMITIVETYPE_INT);
2231 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2233 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2240 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2242 java_objectheader *o;
2247 o = (java_objectheader *) obj;
2248 m = (methodinfo *) methodID;
2250 va_start(ap, methodID);
2251 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2258 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2260 java_objectheader *o;
2264 o = (java_objectheader *) obj;
2265 m = (methodinfo *) methodID;
2267 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2273 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2275 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2282 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2284 java_objectheader *o;
2289 o = (java_objectheader *) obj;
2290 m = (methodinfo *) methodID;
2292 va_start(ap, methodID);
2293 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2300 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2302 java_objectheader *o;
2306 o = (java_objectheader *) obj;
2307 m = (methodinfo *) methodID;
2309 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2315 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2317 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2324 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2326 java_objectheader *o;
2331 o = (java_objectheader *) obj;
2332 m = (methodinfo *) methodID;
2334 va_start(ap, methodID);
2335 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2342 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2344 java_objectheader *o;
2348 o = (java_objectheader *) obj;
2349 m = (methodinfo *) methodID;
2351 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2357 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2359 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2366 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2368 java_objectheader *o;
2372 o = (java_objectheader *) obj;
2373 m = (methodinfo *) methodID;
2375 va_start(ap, methodID);
2376 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2381 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2383 java_objectheader *o;
2386 o = (java_objectheader *) obj;
2387 m = (methodinfo *) methodID;
2389 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2393 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2395 java_objectheader *o;
2398 o = (java_objectheader *) obj;
2399 m = (methodinfo *) methodID;
2401 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2406 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2408 java_objectheader *o;
2411 java_objectheader *r;
2414 o = (java_objectheader *) obj;
2415 c = (classinfo *) clazz;
2416 m = (methodinfo *) methodID;
2418 va_start(ap, methodID);
2419 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2422 return NewLocalRef(env, r);
2426 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2428 java_objectheader *o;
2431 java_objectheader *r;
2433 o = (java_objectheader *) obj;
2434 c = (classinfo *) clazz;
2435 m = (methodinfo *) methodID;
2437 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2439 return NewLocalRef(env, r);
2443 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2445 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2447 return NewLocalRef(env, NULL);
2452 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2454 java_objectheader *o;
2460 o = (java_objectheader *) obj;
2461 c = (classinfo *) clazz;
2462 m = (methodinfo *) methodID;
2464 va_start(ap, methodID);
2465 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap, PRIMITIVETYPE_BOOLEAN);
2472 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2474 java_objectheader *o;
2479 o = (java_objectheader *) obj;
2480 c = (classinfo *) clazz;
2481 m = (methodinfo *) methodID;
2483 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args, PRIMITIVETYPE_BOOLEAN);
2489 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2491 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2497 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2499 java_objectheader *o;
2505 o = (java_objectheader *) obj;
2506 c = (classinfo *) clazz;
2507 m = (methodinfo *) methodID;
2509 va_start(ap, methodID);
2510 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap, PRIMITIVETYPE_BYTE);
2517 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2519 java_objectheader *o;
2524 o = (java_objectheader *) obj;
2525 c = (classinfo *) clazz;
2526 m = (methodinfo *) methodID;
2528 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args, PRIMITIVETYPE_BYTE);
2534 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2536 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2543 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2545 java_objectheader *o;
2551 o = (java_objectheader *) obj;
2552 c = (classinfo *) clazz;
2553 m = (methodinfo *) methodID;
2555 va_start(ap, methodID);
2556 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap, PRIMITIVETYPE_CHAR);
2563 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2565 java_objectheader *o;
2570 o = (java_objectheader *) obj;
2571 c = (classinfo *) clazz;
2572 m = (methodinfo *) methodID;
2574 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args, PRIMITIVETYPE_CHAR);
2580 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2582 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2589 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2591 java_objectheader *o;
2597 o = (java_objectheader *) obj;
2598 c = (classinfo *) clazz;
2599 m = (methodinfo *) methodID;
2601 va_start(ap, methodID);
2602 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap, PRIMITIVETYPE_SHORT);
2609 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2611 java_objectheader *o;
2616 o = (java_objectheader *) obj;
2617 c = (classinfo *) clazz;
2618 m = (methodinfo *) methodID;
2620 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args, PRIMITIVETYPE_SHORT);
2626 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2628 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2635 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2637 java_objectheader *o;
2643 o = (java_objectheader *) obj;
2644 c = (classinfo *) clazz;
2645 m = (methodinfo *) methodID;
2647 va_start(ap, methodID);
2648 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap, PRIMITIVETYPE_INT);
2655 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2657 java_objectheader *o;
2662 o = (java_objectheader *) obj;
2663 c = (classinfo *) clazz;
2664 m = (methodinfo *) methodID;
2666 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args, PRIMITIVETYPE_INT);
2672 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2674 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2681 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2683 java_objectheader *o;
2689 o = (java_objectheader *) obj;
2690 c = (classinfo *) clazz;
2691 m = (methodinfo *) methodID;
2693 va_start(ap, methodID);
2694 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2701 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2703 java_objectheader *o;
2708 o = (java_objectheader *) obj;
2709 c = (classinfo *) clazz;
2710 m = (methodinfo *) methodID;
2712 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2718 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2720 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2727 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2729 java_objectheader *o;
2735 o = (java_objectheader *) obj;
2736 c = (classinfo *) clazz;
2737 m = (methodinfo *) methodID;
2739 va_start(ap, methodID);
2740 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2747 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2749 java_objectheader *o;
2754 o = (java_objectheader *) obj;
2755 c = (classinfo *) clazz;
2756 m = (methodinfo *) methodID;
2758 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2764 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2766 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2773 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2775 java_objectheader *o;
2781 o = (java_objectheader *) obj;
2782 c = (classinfo *) clazz;
2783 m = (methodinfo *) methodID;
2785 va_start(ap, methodID);
2786 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2793 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2795 java_objectheader *o;
2800 o = (java_objectheader *) obj;
2801 c = (classinfo *) clazz;
2802 m = (methodinfo *) methodID;
2804 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2810 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2812 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2819 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2821 java_objectheader *o;
2826 o = (java_objectheader *) obj;
2827 c = (classinfo *) clazz;
2828 m = (methodinfo *) methodID;
2830 va_start(ap, methodID);
2831 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2836 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2838 java_objectheader *o;
2842 o = (java_objectheader *) obj;
2843 c = (classinfo *) clazz;
2844 m = (methodinfo *) methodID;
2846 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2850 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2852 java_objectheader *o;
2856 o = (java_objectheader *) obj;
2857 c = (classinfo *) clazz;
2858 m = (methodinfo *) methodID;
2860 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2864 /* Accessing Fields of Objects ************************************************/
2866 /* GetFieldID ******************************************************************
2868 Returns the field ID for an instance (nonstatic) field of a
2869 class. The field is specified by its name and signature. The
2870 Get<type>Field and Set<type>Field families of accessor functions
2871 use field IDs to retrieve object fields.
2873 *******************************************************************************/
2875 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2882 STATISTICS(jniinvokation());
2884 uname = utf_new_char((char *) name);
2885 udesc = utf_new_char((char *) sig);
2887 f = class_findfield(clazz, uname, udesc);
2890 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2892 return (jfieldID) f;
2896 /* Get<type>Field Routines *****************************************************
2898 This family of accessor routines returns the value of an instance
2899 (nonstatic) field of an object. The field to access is specified by
2900 a field ID obtained by calling GetFieldID().
2902 *******************************************************************************/
2904 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2906 java_objectheader *o;
2908 STATISTICS(jniinvokation());
2910 o = GET_FIELD(obj, java_objectheader*, fieldID);
2912 return NewLocalRef(env, o);
2916 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2920 STATISTICS(jniinvokation());
2922 i = GET_FIELD(obj, s4, fieldID);
2924 return (jboolean) i;
2928 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2932 STATISTICS(jniinvokation());
2934 i = GET_FIELD(obj, s4, fieldID);
2940 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2944 STATISTICS(jniinvokation());
2946 i = GET_FIELD(obj, s4, fieldID);
2952 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2956 STATISTICS(jniinvokation());
2958 i = GET_FIELD(obj, s4, fieldID);
2964 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2966 java_objectheader *o;
2970 STATISTICS(jniinvokation());
2972 o = (java_objectheader *) obj;
2973 f = (fieldinfo *) fieldID;
2975 i = GET_FIELD(o, s4, f);
2981 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2985 STATISTICS(jniinvokation());
2987 l = GET_FIELD(obj, s8, fieldID);
2993 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2997 STATISTICS(jniinvokation());
2999 f = GET_FIELD(obj, float, fieldID);
3005 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3009 STATISTICS(jniinvokation());
3011 d = GET_FIELD(obj, double, fieldID);
3017 /* Set<type>Field Routines *****************************************************
3019 This family of accessor routines sets the value of an instance
3020 (nonstatic) field of an object. The field to access is specified by
3021 a field ID obtained by calling GetFieldID().
3023 *******************************************************************************/
3025 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
3027 STATISTICS(jniinvokation());
3029 SET_FIELD(obj, java_objectheader*, fieldID, value);
3033 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
3035 STATISTICS(jniinvokation());
3037 SET_FIELD(obj, s4, fieldID, value);
3041 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
3043 STATISTICS(jniinvokation());
3045 SET_FIELD(obj, s4, fieldID, value);
3049 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
3051 STATISTICS(jniinvokation());
3053 SET_FIELD(obj, s4, fieldID, value);
3057 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
3059 STATISTICS(jniinvokation());
3061 SET_FIELD(obj, s4, fieldID, value);
3065 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3067 STATISTICS(jniinvokation());
3069 SET_FIELD(obj, s4, fieldID, value);
3073 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
3075 STATISTICS(jniinvokation());
3077 SET_FIELD(obj, s8, fieldID, value);
3081 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
3083 STATISTICS(jniinvokation());
3085 SET_FIELD(obj, float, fieldID, value);
3089 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3091 STATISTICS(jniinvokation());
3093 SET_FIELD(obj, double, fieldID, value);
3097 /* Calling Static Methods *****************************************************/
3099 /* GetStaticMethodID ***********************************************************
3101 Returns the method ID for a static method of a class. The method is
3102 specified by its name and signature.
3104 GetStaticMethodID() causes an uninitialized class to be
3107 *******************************************************************************/
3109 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3117 STATISTICS(jniinvokation());
3119 c = (classinfo *) clazz;
3124 if (!(c->state & CLASS_INITIALIZED))
3125 if (!initialize_class(c))
3128 /* try to get the static method of the class */
3130 uname = utf_new_char((char *) name);
3131 udesc = utf_new_char((char *) sig);
3133 m = class_resolvemethod(c, uname, udesc);
3135 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3136 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3141 return (jmethodID) m;
3145 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3148 java_objectheader *o;
3151 m = (methodinfo *) methodID;
3153 va_start(ap, methodID);
3154 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3157 return NewLocalRef(env, o);
3161 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3164 java_objectheader *o;
3166 m = (methodinfo *) methodID;
3168 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3170 return NewLocalRef(env, o);
3174 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3176 log_text("JNI-Call: CallStaticObjectMethodA: IMPLEMENT ME!");
3178 return NewLocalRef(env, NULL);
3182 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3188 m = (methodinfo *) methodID;
3190 va_start(ap, methodID);
3191 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap, PRIMITIVETYPE_BOOLEAN);
3198 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3203 m = (methodinfo *) methodID;
3205 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args, PRIMITIVETYPE_BOOLEAN);
3211 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3213 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3219 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3225 m = (methodinfo *) methodID;
3227 va_start(ap, methodID);
3228 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap, PRIMITIVETYPE_BYTE);
3235 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3240 m = (methodinfo *) methodID;
3242 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args, PRIMITIVETYPE_BYTE);
3248 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3250 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3256 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3262 m = (methodinfo *) methodID;
3264 va_start(ap, methodID);
3265 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap, PRIMITIVETYPE_CHAR);
3272 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3277 m = (methodinfo *) methodID;
3279 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args, PRIMITIVETYPE_CHAR);
3285 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3287 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3293 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3299 m = (methodinfo *) methodID;
3301 va_start(ap, methodID);
3302 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap, PRIMITIVETYPE_SHORT);
3309 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3314 m = (methodinfo *) methodID;
3316 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args, PRIMITIVETYPE_SHORT);
3322 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3324 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3330 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3336 m = (methodinfo *) methodID;
3338 va_start(ap, methodID);
3339 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap, PRIMITIVETYPE_INT);
3346 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3351 m = (methodinfo *) methodID;
3353 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args, PRIMITIVETYPE_INT);
3359 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3361 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3367 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3373 m = (methodinfo *) methodID;
3375 va_start(ap, methodID);
3376 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3383 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3389 m = (methodinfo *) methodID;
3391 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3397 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3399 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3406 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3412 m = (methodinfo *) methodID;
3414 va_start(ap, methodID);
3415 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3422 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3427 m = (methodinfo *) methodID;
3429 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3435 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3437 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3443 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3449 m = (methodinfo *) methodID;
3451 va_start(ap, methodID);
3452 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3459 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3464 m = (methodinfo *) methodID;
3466 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3472 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3474 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3480 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3485 m = (methodinfo *) methodID;
3487 va_start(ap, methodID);
3488 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3493 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3497 m = (methodinfo *) methodID;
3499 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3503 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3507 m = (methodinfo *) methodID;
3509 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3513 /* Accessing Static Fields ****************************************************/
3515 /* GetStaticFieldID ************************************************************
3517 Returns the field ID for a static field of a class. The field is
3518 specified by its name and signature. The GetStatic<type>Field and
3519 SetStatic<type>Field families of accessor functions use field IDs
3520 to retrieve static fields.
3522 *******************************************************************************/
3524 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3528 STATISTICS(jniinvokation());
3530 f = class_findfield(clazz,
3531 utf_new_char((char *) name),
3532 utf_new_char((char *) sig));
3535 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3537 return (jfieldID) f;
3541 /* GetStatic<type>Field ********************************************************
3543 This family of accessor routines returns the value of a static
3546 *******************************************************************************/
3548 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3553 STATISTICS(jniinvokation());
3555 c = (classinfo *) clazz;
3556 f = (fieldinfo *) fieldID;
3558 if (!(c->state & CLASS_INITIALIZED))
3559 if (!initialize_class(c))
3562 return NewLocalRef(env, f->value.a);
3566 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3571 STATISTICS(jniinvokation());
3573 c = (classinfo *) clazz;
3574 f = (fieldinfo *) fieldID;
3576 if (!(c->state & CLASS_INITIALIZED))
3577 if (!initialize_class(c))
3584 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3589 STATISTICS(jniinvokation());
3591 c = (classinfo *) clazz;
3592 f = (fieldinfo *) fieldID;
3594 if (!(c->state & CLASS_INITIALIZED))
3595 if (!initialize_class(c))
3602 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3607 STATISTICS(jniinvokation());
3609 c = (classinfo *) clazz;
3610 f = (fieldinfo *) fieldID;
3612 if (!(c->state & CLASS_INITIALIZED))
3613 if (!initialize_class(c))
3620 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3625 STATISTICS(jniinvokation());
3627 c = (classinfo *) clazz;
3628 f = (fieldinfo *) fieldID;
3630 if (!(c->state & CLASS_INITIALIZED))
3631 if (!initialize_class(c))
3638 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3643 STATISTICS(jniinvokation());
3645 c = (classinfo *) clazz;
3646 f = (fieldinfo *) fieldID;
3648 if (!(c->state & CLASS_INITIALIZED))
3649 if (!initialize_class(c))
3656 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3661 STATISTICS(jniinvokation());
3663 c = (classinfo *) clazz;
3664 f = (fieldinfo *) fieldID;
3666 if (!(c->state & CLASS_INITIALIZED))
3667 if (!initialize_class(c))
3674 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3679 STATISTICS(jniinvokation());
3681 c = (classinfo *) clazz;
3682 f = (fieldinfo *) fieldID;
3684 if (!(c->state & CLASS_INITIALIZED))
3685 if (!initialize_class(c))
3692 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3697 STATISTICS(jniinvokation());
3699 c = (classinfo *) clazz;
3700 f = (fieldinfo *) fieldID;
3702 if (!(c->state & CLASS_INITIALIZED))
3703 if (!initialize_class(c))
3710 /* SetStatic<type>Field *******************************************************
3712 This family of accessor routines sets the value of a static field
3715 *******************************************************************************/
3717 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3722 STATISTICS(jniinvokation());
3724 c = (classinfo *) clazz;
3725 f = (fieldinfo *) fieldID;
3727 if (!(c->state & CLASS_INITIALIZED))
3728 if (!initialize_class(c))
3735 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3740 STATISTICS(jniinvokation());
3742 c = (classinfo *) clazz;
3743 f = (fieldinfo *) fieldID;
3745 if (!(c->state & CLASS_INITIALIZED))
3746 if (!initialize_class(c))
3753 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3758 STATISTICS(jniinvokation());
3760 c = (classinfo *) clazz;
3761 f = (fieldinfo *) fieldID;
3763 if (!(c->state & CLASS_INITIALIZED))
3764 if (!initialize_class(c))
3771 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3776 STATISTICS(jniinvokation());
3778 c = (classinfo *) clazz;
3779 f = (fieldinfo *) fieldID;
3781 if (!(c->state & CLASS_INITIALIZED))
3782 if (!initialize_class(c))
3789 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3794 STATISTICS(jniinvokation());
3796 c = (classinfo *) clazz;
3797 f = (fieldinfo *) fieldID;
3799 if (!(c->state & CLASS_INITIALIZED))
3800 if (!initialize_class(c))
3807 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3812 STATISTICS(jniinvokation());
3814 c = (classinfo *) clazz;
3815 f = (fieldinfo *) fieldID;
3817 if (!(c->state & CLASS_INITIALIZED))
3818 if (!initialize_class(c))
3825 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3830 STATISTICS(jniinvokation());
3832 c = (classinfo *) clazz;
3833 f = (fieldinfo *) fieldID;
3835 if (!(c->state & CLASS_INITIALIZED))
3836 if (!initialize_class(c))
3843 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3848 STATISTICS(jniinvokation());
3850 c = (classinfo *) clazz;
3851 f = (fieldinfo *) fieldID;
3853 if (!(c->state & CLASS_INITIALIZED))
3854 if (!initialize_class(c))
3861 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3866 STATISTICS(jniinvokation());
3868 c = (classinfo *) clazz;
3869 f = (fieldinfo *) fieldID;
3871 if (!(c->state & CLASS_INITIALIZED))
3872 if (!initialize_class(c))
3879 /* String Operations **********************************************************/
3881 /* NewString *******************************************************************
3883 Create new java.lang.String object from an array of Unicode
3886 *******************************************************************************/
3888 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3890 java_lang_String *s;
3894 STATISTICS(jniinvokation());
3896 s = (java_lang_String *) builtin_new(class_java_lang_String);
3897 a = builtin_newarray_char(len);
3899 /* javastring or characterarray could not be created */
3904 for (i = 0; i < len; i++)
3905 a->data[i] = buf[i];
3911 return (jstring) NewLocalRef(env, (jobject) s);
3915 static jchar emptyStringJ[]={0,0};
3917 /* GetStringLength *************************************************************
3919 Returns the length (the count of Unicode characters) of a Java
3922 *******************************************************************************/
3924 jsize GetStringLength(JNIEnv *env, jstring str)
3926 return ((java_lang_String *) str)->count;
3930 /******************** convertes javastring to u2-array ****************************/
3932 u2 *javastring_tou2(jstring so)
3934 java_lang_String *s;
3939 STATISTICS(jniinvokation());
3941 s = (java_lang_String *) so;
3951 /* allocate memory */
3953 stringbuffer = MNEW(u2, s->count + 1);
3957 for (i = 0; i < s->count; i++)
3958 stringbuffer[i] = a->data[s->offset + i];
3960 /* terminate string */
3962 stringbuffer[i] = '\0';
3964 return stringbuffer;
3968 /* GetStringChars **************************************************************
3970 Returns a pointer to the array of Unicode characters of the
3971 string. This pointer is valid until ReleaseStringchars() is called.
3973 *******************************************************************************/
3975 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3979 STATISTICS(jniinvokation());
3981 jc = javastring_tou2(str);
3993 return emptyStringJ;
3997 /* ReleaseStringChars **********************************************************
3999 Informs the VM that the native code no longer needs access to
4000 chars. The chars argument is a pointer obtained from string using
4003 *******************************************************************************/
4005 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4007 STATISTICS(jniinvokation());
4009 if (chars == emptyStringJ)
4012 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4016 /* NewStringUTF ****************************************************************
4018 Constructs a new java.lang.String object from an array of UTF-8 characters.
4020 *******************************************************************************/
4022 jstring NewStringUTF(JNIEnv *env, const char *bytes)
4024 java_lang_String *s;
4026 STATISTICS(jniinvokation());
4028 s = javastring_new(utf_new_char(bytes));
4030 return (jstring) NewLocalRef(env, (jobject) s);
4034 /****************** returns the utf8 length in bytes of a string *******************/
4036 jsize GetStringUTFLength (JNIEnv *env, jstring string)
4038 java_lang_String *s = (java_lang_String*) string;
4040 STATISTICS(jniinvokation());
4042 return (jsize) u2_utflength(s->value->data, s->count);
4046 /* GetStringUTFChars ***********************************************************
4048 Returns a pointer to an array of UTF-8 characters of the
4049 string. This array is valid until it is released by
4050 ReleaseStringUTFChars().
4052 *******************************************************************************/
4054 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
4058 STATISTICS(jniinvokation());
4066 u = javastring_toutf((java_lang_String *) string, false);
4075 /* ReleaseStringUTFChars *******************************************************
4077 Informs the VM that the native code no longer needs access to
4078 utf. The utf argument is a pointer derived from string using
4079 GetStringUTFChars().
4081 *******************************************************************************/
4083 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4085 STATISTICS(jniinvokation());
4087 /* XXX we don't release utf chars right now, perhaps that should be done
4088 later. Since there is always one reference the garbage collector will
4093 /* Array Operations ***********************************************************/
4095 /* GetArrayLength **************************************************************
4097 Returns the number of elements in the array.
4099 *******************************************************************************/
4101 jsize GetArrayLength(JNIEnv *env, jarray array)
4103 java_arrayheader *a;
4105 STATISTICS(jniinvokation());
4107 a = (java_arrayheader *) array;
4113 /* NewObjectArray **************************************************************
4115 Constructs a new array holding objects in class elementClass. All
4116 elements are initially set to initialElement.
4118 *******************************************************************************/
4120 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4122 java_objectarray *oa;
4125 STATISTICS(jniinvokation());
4128 exceptions_throw_negativearraysizeexception();
4132 oa = builtin_anewarray(length, elementClass);
4137 /* set all elements to initialElement */
4139 for (i = 0; i < length; i++)
4140 oa->data[i] = initialElement;
4142 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4146 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4148 java_objectarray *oa;
4151 STATISTICS(jniinvokation());
4153 oa = (java_objectarray *) array;
4155 if (index >= oa->header.size) {
4156 exceptions_throw_arrayindexoutofboundsexception();
4160 o = oa->data[index];
4162 return NewLocalRef(env, o);
4166 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4168 java_objectarray *oa;
4169 java_objectheader *o;
4171 STATISTICS(jniinvokation());
4173 oa = (java_objectarray *) array;
4174 o = (java_objectheader *) val;
4176 if (index >= oa->header.size) {
4177 exceptions_throw_arrayindexoutofboundsexception();
4181 /* check if the class of value is a subclass of the element class
4184 if (!builtin_canstore(oa, o)) {
4185 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4190 oa->data[index] = val;
4194 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4196 java_booleanarray *ba;
4198 STATISTICS(jniinvokation());
4201 exceptions_throw_negativearraysizeexception();
4205 ba = builtin_newarray_boolean(len);
4207 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4211 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4215 STATISTICS(jniinvokation());
4218 exceptions_throw_negativearraysizeexception();
4222 ba = builtin_newarray_byte(len);
4224 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4228 jcharArray NewCharArray(JNIEnv *env, jsize len)
4232 STATISTICS(jniinvokation());
4235 exceptions_throw_negativearraysizeexception();
4239 ca = builtin_newarray_char(len);
4241 return (jcharArray) NewLocalRef(env, (jobject) ca);
4245 jshortArray NewShortArray(JNIEnv *env, jsize len)
4247 java_shortarray *sa;
4249 STATISTICS(jniinvokation());
4252 exceptions_throw_negativearraysizeexception();
4256 sa = builtin_newarray_short(len);
4258 return (jshortArray) NewLocalRef(env, (jobject) sa);
4262 jintArray NewIntArray(JNIEnv *env, jsize len)
4266 STATISTICS(jniinvokation());
4269 exceptions_throw_negativearraysizeexception();
4273 ia = builtin_newarray_int(len);
4275 return (jintArray) NewLocalRef(env, (jobject) ia);
4279 jlongArray NewLongArray(JNIEnv *env, jsize len)
4283 STATISTICS(jniinvokation());
4286 exceptions_throw_negativearraysizeexception();
4290 la = builtin_newarray_long(len);
4292 return (jlongArray) NewLocalRef(env, (jobject) la);
4296 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4298 java_floatarray *fa;
4300 STATISTICS(jniinvokation());
4303 exceptions_throw_negativearraysizeexception();
4307 fa = builtin_newarray_float(len);
4309 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4313 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4315 java_doublearray *da;
4317 STATISTICS(jniinvokation());
4320 exceptions_throw_negativearraysizeexception();
4324 da = builtin_newarray_double(len);
4326 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4330 /* Get<PrimitiveType>ArrayElements *********************************************
4332 A family of functions that returns the body of the primitive array.
4334 *******************************************************************************/
4336 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4339 java_booleanarray *ba;
4341 STATISTICS(jniinvokation());
4343 ba = (java_booleanarray *) array;
4346 *isCopy = JNI_FALSE;
4352 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4356 STATISTICS(jniinvokation());
4358 ba = (java_bytearray *) array;
4361 *isCopy = JNI_FALSE;
4367 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4371 STATISTICS(jniinvokation());
4373 ca = (java_chararray *) array;
4376 *isCopy = JNI_FALSE;
4382 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4384 java_shortarray *sa;
4386 STATISTICS(jniinvokation());
4388 sa = (java_shortarray *) array;
4391 *isCopy = JNI_FALSE;
4397 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4401 STATISTICS(jniinvokation());
4403 ia = (java_intarray *) array;
4406 *isCopy = JNI_FALSE;
4412 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4416 STATISTICS(jniinvokation());
4418 la = (java_longarray *) array;
4421 *isCopy = JNI_FALSE;
4423 /* We cast this one to prevent a compiler warning on 64-bit
4424 systems since GNU Classpath typedef jlong to long long. */
4426 return (jlong *) la->data;
4430 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4432 java_floatarray *fa;
4434 STATISTICS(jniinvokation());
4436 fa = (java_floatarray *) array;
4439 *isCopy = JNI_FALSE;
4445 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4448 java_doublearray *da;
4450 STATISTICS(jniinvokation());
4452 da = (java_doublearray *) array;
4455 *isCopy = JNI_FALSE;
4461 /* Release<PrimitiveType>ArrayElements *****************************************
4463 A family of functions that informs the VM that the native code no
4464 longer needs access to elems. The elems argument is a pointer
4465 derived from array using the corresponding
4466 Get<PrimitiveType>ArrayElements() function. If necessary, this
4467 function copies back all changes made to elems to the original
4470 *******************************************************************************/
4472 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4473 jboolean *elems, jint mode)
4475 java_booleanarray *ba;
4477 STATISTICS(jniinvokation());
4479 ba = (java_booleanarray *) array;
4481 if (elems != ba->data) {
4484 MCOPY(ba->data, elems, u1, ba->header.size);
4487 MCOPY(ba->data, elems, u1, ba->header.size);
4488 /* XXX TWISTI how should it be freed? */
4491 /* XXX TWISTI how should it be freed? */
4498 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4503 STATISTICS(jniinvokation());
4505 ba = (java_bytearray *) array;
4507 if (elems != ba->data) {
4510 MCOPY(ba->data, elems, s1, ba->header.size);
4513 MCOPY(ba->data, elems, s1, ba->header.size);
4514 /* XXX TWISTI how should it be freed? */
4517 /* XXX TWISTI how should it be freed? */
4524 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4529 STATISTICS(jniinvokation());
4531 ca = (java_chararray *) array;
4533 if (elems != ca->data) {
4536 MCOPY(ca->data, elems, u2, ca->header.size);
4539 MCOPY(ca->data, elems, u2, ca->header.size);
4540 /* XXX TWISTI how should it be freed? */
4543 /* XXX TWISTI how should it be freed? */
4550 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4553 java_shortarray *sa;
4555 STATISTICS(jniinvokation());
4557 sa = (java_shortarray *) array;
4559 if (elems != sa->data) {
4562 MCOPY(sa->data, elems, s2, sa->header.size);
4565 MCOPY(sa->data, elems, s2, sa->header.size);
4566 /* XXX TWISTI how should it be freed? */
4569 /* XXX TWISTI how should it be freed? */
4576 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4581 STATISTICS(jniinvokation());
4583 ia = (java_intarray *) array;
4585 if (elems != ia->data) {
4588 MCOPY(ia->data, elems, s4, ia->header.size);
4591 MCOPY(ia->data, elems, s4, ia->header.size);
4592 /* XXX TWISTI how should it be freed? */
4595 /* XXX TWISTI how should it be freed? */
4602 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4607 STATISTICS(jniinvokation());
4609 la = (java_longarray *) array;
4611 /* We cast this one to prevent a compiler warning on 64-bit
4612 systems since GNU Classpath typedef jlong to long long. */
4614 if ((s8 *) elems != la->data) {
4617 MCOPY(la->data, elems, s8, la->header.size);
4620 MCOPY(la->data, elems, s8, la->header.size);
4621 /* XXX TWISTI how should it be freed? */
4624 /* XXX TWISTI how should it be freed? */
4631 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4634 java_floatarray *fa;
4636 STATISTICS(jniinvokation());
4638 fa = (java_floatarray *) array;
4640 if (elems != fa->data) {
4643 MCOPY(fa->data, elems, float, fa->header.size);
4646 MCOPY(fa->data, elems, float, fa->header.size);
4647 /* XXX TWISTI how should it be freed? */
4650 /* XXX TWISTI how should it be freed? */
4657 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4658 jdouble *elems, jint mode)
4660 java_doublearray *da;
4662 STATISTICS(jniinvokation());
4664 da = (java_doublearray *) array;
4666 if (elems != da->data) {
4669 MCOPY(da->data, elems, double, da->header.size);
4672 MCOPY(da->data, elems, double, da->header.size);
4673 /* XXX TWISTI how should it be freed? */
4676 /* XXX TWISTI how should it be freed? */
4683 /* Get<PrimitiveType>ArrayRegion **********************************************
4685 A family of functions that copies a region of a primitive array
4688 *******************************************************************************/
4690 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4691 jsize len, jboolean *buf)
4693 java_booleanarray *ba;
4695 STATISTICS(jniinvokation());
4697 ba = (java_booleanarray *) array;
4699 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4700 exceptions_throw_arrayindexoutofboundsexception();
4702 MCOPY(buf, &ba->data[start], u1, len);
4706 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4711 STATISTICS(jniinvokation());
4713 ba = (java_bytearray *) array;
4715 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4716 exceptions_throw_arrayindexoutofboundsexception();
4718 MCOPY(buf, &ba->data[start], s1, len);
4722 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4727 STATISTICS(jniinvokation());
4729 ca = (java_chararray *) array;
4731 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4732 exceptions_throw_arrayindexoutofboundsexception();
4734 MCOPY(buf, &ca->data[start], u2, len);
4738 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4739 jsize len, jshort *buf)
4741 java_shortarray *sa;
4743 STATISTICS(jniinvokation());
4745 sa = (java_shortarray *) array;
4747 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4748 exceptions_throw_arrayindexoutofboundsexception();
4750 MCOPY(buf, &sa->data[start], s2, len);
4754 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4759 STATISTICS(jniinvokation());
4761 ia = (java_intarray *) array;
4763 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4764 exceptions_throw_arrayindexoutofboundsexception();
4766 MCOPY(buf, &ia->data[start], s4, len);
4770 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4775 STATISTICS(jniinvokation());
4777 la = (java_longarray *) array;
4779 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4780 exceptions_throw_arrayindexoutofboundsexception();
4782 MCOPY(buf, &la->data[start], s8, len);
4786 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4787 jsize len, jfloat *buf)
4789 java_floatarray *fa;
4791 STATISTICS(jniinvokation());
4793 fa = (java_floatarray *) array;
4795 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4796 exceptions_throw_arrayindexoutofboundsexception();
4798 MCOPY(buf, &fa->data[start], float, len);
4802 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4803 jsize len, jdouble *buf)
4805 java_doublearray *da;
4807 STATISTICS(jniinvokation());
4809 da = (java_doublearray *) array;
4811 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4812 exceptions_throw_arrayindexoutofboundsexception();
4814 MCOPY(buf, &da->data[start], double, len);
4818 /* Set<PrimitiveType>ArrayRegion **********************************************
4820 A family of functions that copies back a region of a primitive
4821 array from a buffer.
4823 *******************************************************************************/
4825 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4826 jsize len, jboolean *buf)
4828 java_booleanarray *ba;
4830 STATISTICS(jniinvokation());
4832 ba = (java_booleanarray *) array;
4834 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4835 exceptions_throw_arrayindexoutofboundsexception();
4837 MCOPY(&ba->data[start], buf, u1, len);
4841 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4846 STATISTICS(jniinvokation());
4848 ba = (java_bytearray *) array;
4850 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4851 exceptions_throw_arrayindexoutofboundsexception();
4853 MCOPY(&ba->data[start], buf, s1, len);
4857 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4862 STATISTICS(jniinvokation());
4864 ca = (java_chararray *) array;
4866 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4867 exceptions_throw_arrayindexoutofboundsexception();
4869 MCOPY(&ca->data[start], buf, u2, len);
4873 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4874 jsize len, jshort *buf)
4876 java_shortarray *sa;
4878 STATISTICS(jniinvokation());
4880 sa = (java_shortarray *) array;
4882 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4883 exceptions_throw_arrayindexoutofboundsexception();
4885 MCOPY(&sa->data[start], buf, s2, len);
4889 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4894 STATISTICS(jniinvokation());
4896 ia = (java_intarray *) array;
4898 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4899 exceptions_throw_arrayindexoutofboundsexception();
4901 MCOPY(&ia->data[start], buf, s4, len);
4905 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4910 STATISTICS(jniinvokation());
4912 la = (java_longarray *) array;
4914 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4915 exceptions_throw_arrayindexoutofboundsexception();
4917 MCOPY(&la->data[start], buf, s8, len);
4921 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4922 jsize len, jfloat *buf)
4924 java_floatarray *fa;
4926 STATISTICS(jniinvokation());
4928 fa = (java_floatarray *) array;
4930 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4931 exceptions_throw_arrayindexoutofboundsexception();
4933 MCOPY(&fa->data[start], buf, float, len);
4937 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4938 jsize len, jdouble *buf)
4940 java_doublearray *da;
4942 STATISTICS(jniinvokation());
4944 da = (java_doublearray *) array;
4946 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4947 exceptions_throw_arrayindexoutofboundsexception();
4949 MCOPY(&da->data[start], buf, double, len);
4953 /* Registering Native Methods *************************************************/
4955 /* RegisterNatives *************************************************************
4957 Registers native methods with the class specified by the clazz
4958 argument. The methods parameter specifies an array of
4959 JNINativeMethod structures that contain the names, signatures, and
4960 function pointers of the native methods. The nMethods parameter
4961 specifies the number of native methods in the array.
4963 *******************************************************************************/
4965 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4968 STATISTICS(jniinvokation());
4970 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4976 /* UnregisterNatives ***********************************************************
4978 Unregisters native methods of a class. The class goes back to the
4979 state before it was linked or registered with its native method
4982 This function should not be used in normal native code. Instead, it
4983 provides special programs a way to reload and relink native
4986 *******************************************************************************/
4988 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4990 STATISTICS(jniinvokation());
4992 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4994 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5000 /* Monitor Operations *********************************************************/
5002 /* MonitorEnter ****************************************************************
5004 Enters the monitor associated with the underlying Java object
5007 *******************************************************************************/
5009 jint MonitorEnter(JNIEnv *env, jobject obj)
5011 STATISTICS(jniinvokation());
5014 exceptions_throw_nullpointerexception();
5018 #if defined(USE_THREADS)
5019 builtin_monitorenter(obj);
5026 /* MonitorExit *****************************************************************
5028 The current thread must be the owner of the monitor associated with
5029 the underlying Java object referred to by obj. The thread
5030 decrements the counter indicating the number of times it has
5031 entered this monitor. If the value of the counter becomes zero, the
5032 current thread releases the monitor.
5034 *******************************************************************************/
5036 jint MonitorExit(JNIEnv *env, jobject obj)
5038 STATISTICS(jniinvokation());
5041 exceptions_throw_nullpointerexception();
5045 #if defined(USE_THREADS)
5046 builtin_monitorexit(obj);
5053 /* JavaVM Interface ***********************************************************/
5055 /* GetJavaVM *******************************************************************
5057 Returns the Java VM interface (used in the Invocation API)
5058 associated with the current thread. The result is placed at the
5059 location pointed to by the second argument, vm.
5061 *******************************************************************************/
5063 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
5065 STATISTICS(jniinvokation());
5073 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
5075 STATISTICS(jniinvokation());
5077 log_text("JNI-Call: GetStringRegion: IMPLEMENT ME!");
5081 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5083 STATISTICS(jniinvokation());
5085 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5089 /* GetPrimitiveArrayCritical ***************************************************
5091 Obtain a direct pointer to array elements.
5093 *******************************************************************************/
5095 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5100 ba = (java_bytearray *) array;
5102 /* do the same as Kaffe does */
5104 bp = GetByteArrayElements(env, ba, isCopy);
5110 /* ReleasePrimitiveArrayCritical ***********************************************
5112 No specific documentation.
5114 *******************************************************************************/
5116 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5119 STATISTICS(jniinvokation());
5121 /* do the same as Kaffe does */
5123 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5127 /* GetStringCritical ***********************************************************
5129 The semantics of these two functions are similar to the existing
5130 Get/ReleaseStringChars functions.
5132 *******************************************************************************/
5134 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5136 STATISTICS(jniinvokation());
5138 return GetStringChars(env, string, isCopy);
5142 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5144 STATISTICS(jniinvokation());
5146 ReleaseStringChars(env, string, cstring);
5150 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5152 STATISTICS(jniinvokation());
5154 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5160 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5162 STATISTICS(jniinvokation());
5164 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5168 /* NewGlobalRef ****************************************************************
5170 Creates a new global reference to the object referred to by the obj
5173 *******************************************************************************/
5175 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
5177 java_objectheader *o;
5178 java_lang_Integer *refcount;
5179 java_objectheader *newval;
5181 STATISTICS(jniinvokation());
5183 #if defined(USE_THREADS)
5184 builtin_monitorenter(*global_ref_table);
5187 o = vm_call_method_intern(getmid, *global_ref_table, lobj, NULL, NULL);
5189 refcount = (java_lang_Integer *) o;
5191 if (refcount == NULL) {
5192 newval = native_new_and_init_int(class_java_lang_Integer, 1);
5194 if (newval == NULL) {
5195 #if defined(USE_THREADS)
5196 builtin_monitorexit(*global_ref_table);
5201 (void) vm_call_method_intern(putmid, *global_ref_table, lobj, newval,
5205 /* we can access the object itself, as we are in a
5206 synchronized section */
5211 #if defined(USE_THREADS)
5212 builtin_monitorexit(*global_ref_table);
5219 /* DeleteGlobalRef *************************************************************
5221 Deletes the global reference pointed to by globalRef.
5223 *******************************************************************************/
5225 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5227 java_objectheader *o;
5228 java_lang_Integer *refcount;
5231 STATISTICS(jniinvokation());
5233 #if defined(USE_THREADS)
5234 builtin_monitorenter(*global_ref_table);
5237 o = vm_call_method_intern(getmid, *global_ref_table, globalRef, NULL, NULL);
5239 refcount = (java_lang_Integer *) o;
5241 if (refcount == NULL) {
5242 log_text("JNI-DeleteGlobalRef: unable to find global reference");
5246 /* we can access the object itself, as we are in a synchronized
5249 val = refcount->value - 1;
5252 (void) vm_call_method_intern(removemid, *global_ref_table, refcount,
5256 /* we do not create a new object, but set the new value into
5259 refcount->value = val;
5262 #if defined(USE_THREADS)
5263 builtin_monitorexit(*global_ref_table);
5268 /* ExceptionCheck **************************************************************
5270 Returns JNI_TRUE when there is a pending exception; otherwise,
5273 *******************************************************************************/
5275 jboolean ExceptionCheck(JNIEnv *env)
5277 STATISTICS(jniinvokation());
5279 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5283 /* New JNI 1.4 functions ******************************************************/
5285 /* NewDirectByteBuffer *********************************************************
5287 Allocates and returns a direct java.nio.ByteBuffer referring to the
5288 block of memory starting at the memory address address and
5289 extending capacity bytes.
5291 *******************************************************************************/
5293 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5295 java_objectheader *nbuf;
5296 #if SIZEOF_VOID_P == 8
5297 gnu_classpath_Pointer64 *paddress;
5299 gnu_classpath_Pointer32 *paddress;
5302 STATISTICS(jniinvokation());
5304 /* alocate a gnu.classpath.Pointer{32,64} object */
5306 #if SIZEOF_VOID_P == 8
5307 if (!(paddress = (gnu_classpath_Pointer64 *)
5308 builtin_new(class_gnu_classpath_Pointer64)))
5310 if (!(paddress = (gnu_classpath_Pointer32 *)
5311 builtin_new(class_gnu_classpath_Pointer32)))
5315 /* fill gnu.classpath.Pointer{32,64} with address */
5317 paddress->data = (ptrint) address;
5319 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5321 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5322 (jmethodID) dbbirw_init, NULL, paddress,
5323 (jint) capacity, (jint) capacity, (jint) 0);
5325 /* add local reference and return the value */
5327 return NewLocalRef(env, nbuf);
5331 /* GetDirectBufferAddress ******************************************************
5333 Fetches and returns the starting address of the memory region
5334 referenced by the given direct java.nio.Buffer.
5336 *******************************************************************************/
5338 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5340 java_nio_DirectByteBufferImpl *nbuf;
5341 #if SIZEOF_VOID_P == 8
5342 gnu_classpath_Pointer64 *address;
5344 gnu_classpath_Pointer32 *address;
5347 STATISTICS(jniinvokation());
5349 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5352 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5354 #if SIZEOF_VOID_P == 8
5355 address = (gnu_classpath_Pointer64 *) nbuf->address;
5357 address = (gnu_classpath_Pointer32 *) nbuf->address;
5360 return (void *) address->data;
5364 /* GetDirectBufferCapacity *****************************************************
5366 Fetches and returns the capacity in bytes of the memory region
5367 referenced by the given direct java.nio.Buffer.
5369 *******************************************************************************/
5371 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5373 java_nio_Buffer *nbuf;
5375 STATISTICS(jniinvokation());
5377 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5380 nbuf = (java_nio_Buffer *) buf;
5382 return (jlong) nbuf->cap;
5386 /* DestroyJavaVM ***************************************************************
5388 Unloads a Java VM and reclaims its resources. Only the main thread
5389 can unload the VM. The system waits until the main thread is only
5390 remaining user thread before it destroys the VM.
5392 *******************************************************************************/
5394 jint DestroyJavaVM(JavaVM *vm)
5398 STATISTICS(jniinvokation());
5400 status = vm_destroy(vm);
5406 /* AttachCurrentThread *********************************************************
5408 Attaches the current thread to a Java VM. Returns a JNI interface
5409 pointer in the JNIEnv argument.
5411 Trying to attach a thread that is already attached is a no-op.
5413 A native thread cannot be attached simultaneously to two Java VMs.
5415 When a thread is attached to the VM, the context class loader is
5416 the bootstrap loader.
5418 *******************************************************************************/
5420 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5422 STATISTICS(jniinvokation());
5424 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5426 #if !defined(HAVE___THREAD)
5427 /* cacao_thread_attach();*/
5429 #error "No idea how to implement that. Perhaps Stefan knows"
5438 jint DetachCurrentThread(JavaVM *vm)
5440 STATISTICS(jniinvokation());
5442 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5448 /* GetEnv **********************************************************************
5450 If the current thread is not attached to the VM, sets *env to NULL,
5451 and returns JNI_EDETACHED. If the specified version is not
5452 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5453 sets *env to the appropriate interface, and returns JNI_OK.
5455 *******************************************************************************/
5457 jint GetEnv(JavaVM *vm, void **env, jint version)
5459 STATISTICS(jniinvokation());
5461 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
5462 if (thread_getself() == NULL) {
5465 return JNI_EDETACHED;
5469 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5470 (version == JNI_VERSION_1_4)) {
5476 #if defined(ENABLE_JVMTI)
5477 if (version == JVMTI_VERSION_1_0) {
5478 *env = (void *) new_jvmtienv();
5487 return JNI_EVERSION;
5492 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5494 STATISTICS(jniinvokation());
5496 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5502 /* JNI invocation table *******************************************************/
5504 const struct JNIInvokeInterface JNI_JavaVMTable = {
5510 AttachCurrentThread,
5511 DetachCurrentThread,
5513 AttachCurrentThreadAsDaemon
5517 /* JNI function table *********************************************************/
5519 struct JNINativeInterface JNI_JNIEnvTable = {
5528 FromReflectedMethod,
5549 EnsureLocalCapacity,
5592 CallNonvirtualObjectMethod,
5593 CallNonvirtualObjectMethodV,
5594 CallNonvirtualObjectMethodA,
5595 CallNonvirtualBooleanMethod,
5596 CallNonvirtualBooleanMethodV,
5597 CallNonvirtualBooleanMethodA,
5598 CallNonvirtualByteMethod,
5599 CallNonvirtualByteMethodV,
5600 CallNonvirtualByteMethodA,
5601 CallNonvirtualCharMethod,
5602 CallNonvirtualCharMethodV,
5603 CallNonvirtualCharMethodA,
5604 CallNonvirtualShortMethod,
5605 CallNonvirtualShortMethodV,
5606 CallNonvirtualShortMethodA,
5607 CallNonvirtualIntMethod,
5608 CallNonvirtualIntMethodV,
5609 CallNonvirtualIntMethodA,
5610 CallNonvirtualLongMethod,
5611 CallNonvirtualLongMethodV,
5612 CallNonvirtualLongMethodA,
5613 CallNonvirtualFloatMethod,
5614 CallNonvirtualFloatMethodV,
5615 CallNonvirtualFloatMethodA,
5616 CallNonvirtualDoubleMethod,
5617 CallNonvirtualDoubleMethodV,
5618 CallNonvirtualDoubleMethodA,
5619 CallNonvirtualVoidMethod,
5620 CallNonvirtualVoidMethodV,
5621 CallNonvirtualVoidMethodA,
5646 CallStaticObjectMethod,
5647 CallStaticObjectMethodV,
5648 CallStaticObjectMethodA,
5649 CallStaticBooleanMethod,
5650 CallStaticBooleanMethodV,
5651 CallStaticBooleanMethodA,
5652 CallStaticByteMethod,
5653 CallStaticByteMethodV,
5654 CallStaticByteMethodA,
5655 CallStaticCharMethod,
5656 CallStaticCharMethodV,
5657 CallStaticCharMethodA,
5658 CallStaticShortMethod,
5659 CallStaticShortMethodV,
5660 CallStaticShortMethodA,
5661 CallStaticIntMethod,
5662 CallStaticIntMethodV,
5663 CallStaticIntMethodA,
5664 CallStaticLongMethod,
5665 CallStaticLongMethodV,
5666 CallStaticLongMethodA,
5667 CallStaticFloatMethod,
5668 CallStaticFloatMethodV,
5669 CallStaticFloatMethodA,
5670 CallStaticDoubleMethod,
5671 CallStaticDoubleMethodV,
5672 CallStaticDoubleMethodA,
5673 CallStaticVoidMethod,
5674 CallStaticVoidMethodV,
5675 CallStaticVoidMethodA,
5679 GetStaticObjectField,
5680 GetStaticBooleanField,
5683 GetStaticShortField,
5686 GetStaticFloatField,
5687 GetStaticDoubleField,
5688 SetStaticObjectField,
5689 SetStaticBooleanField,
5692 SetStaticShortField,
5695 SetStaticFloatField,
5696 SetStaticDoubleField,
5706 ReleaseStringUTFChars,
5711 GetObjectArrayElement,
5712 SetObjectArrayElement,
5723 GetBooleanArrayElements,
5724 GetByteArrayElements,
5725 GetCharArrayElements,
5726 GetShortArrayElements,
5727 GetIntArrayElements,
5728 GetLongArrayElements,
5729 GetFloatArrayElements,
5730 GetDoubleArrayElements,
5732 ReleaseBooleanArrayElements,
5733 ReleaseByteArrayElements,
5734 ReleaseCharArrayElements,
5735 ReleaseShortArrayElements,
5736 ReleaseIntArrayElements,
5737 ReleaseLongArrayElements,
5738 ReleaseFloatArrayElements,
5739 ReleaseDoubleArrayElements,
5741 GetBooleanArrayRegion,
5744 GetShortArrayRegion,
5747 GetFloatArrayRegion,
5748 GetDoubleArrayRegion,
5749 SetBooleanArrayRegion,
5752 SetShortArrayRegion,
5755 SetFloatArrayRegion,
5756 SetDoubleArrayRegion,
5766 /* new JNI 1.2 functions */
5771 GetPrimitiveArrayCritical,
5772 ReleasePrimitiveArrayCritical,
5775 ReleaseStringCritical,
5778 DeleteWeakGlobalRef,
5782 /* new JNI 1.4 functions */
5784 NewDirectByteBuffer,
5785 GetDirectBufferAddress,
5786 GetDirectBufferCapacity
5790 /* Invocation API Functions ***************************************************/
5792 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5794 Returns a default configuration for the Java VM.
5796 *******************************************************************************/
5798 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5800 JavaVMInitArgs *_vm_args;
5802 _vm_args = (JavaVMInitArgs *) vm_args;
5804 /* GNU classpath currently supports JNI 1.2 */
5806 switch (_vm_args->version) {
5807 case JNI_VERSION_1_1:
5808 _vm_args->version = JNI_VERSION_1_1;
5811 case JNI_VERSION_1_2:
5812 case JNI_VERSION_1_4:
5813 _vm_args->ignoreUnrecognized = JNI_FALSE;
5814 _vm_args->options = NULL;
5815 _vm_args->nOptions = 0;
5826 /* JNI_GetCreatedJavaVMs *******************************************************
5828 Returns all Java VMs that have been created. Pointers to VMs are written in
5829 the buffer vmBuf in the order they are created. At most bufLen number of
5830 entries will be written. The total number of created VMs is returned in
5833 *******************************************************************************/
5835 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5837 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5843 /* JNI_CreateJavaVM ************************************************************
5845 Loads and initializes a Java VM. The current thread becomes the main thread.
5846 Sets the env argument to the JNI interface pointer of the main thread.
5848 *******************************************************************************/
5850 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5852 JavaVMInitArgs *_vm_args;
5854 localref_table *lrt;
5856 /* get the arguments for the new JVM */
5858 _vm_args = (JavaVMInitArgs *) vm_args;
5860 /* get the VM and Env tables (must be set before vm_create) */
5862 env = NEW(_Jv_JNIEnv);
5864 env->env = &JNI_JNIEnvTable;
5866 *p_vm = (JavaVM *) &JNI_JavaVMTable;
5867 *p_env = (void *) env;
5869 /* XXX Set the global env variable. Maybe we should do that differently. */
5873 /* actually create the JVM */
5875 if (!vm_create(_vm_args))
5878 /* setup the local ref table (must be created after vm_create) */
5880 lrt = GCNEW(localref_table);
5882 lrt->capacity = LOCALREFTABLE_CAPACITY;
5884 lrt->localframes = 1;
5885 lrt->prev = LOCALREFTABLE;
5887 /* clear the references array (memset is faster then a for-loop) */
5889 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5891 LOCALREFTABLE = lrt;
5898 * These are local overrides for various environment variables in Emacs.
5899 * Please do not remove this and leave it at the end of the file, where
5900 * Emacs will automagically detect them.
5901 * ---------------------------------------------------------------------
5904 * indent-tabs-mode: t
5908 * vim:noexpandtab:sw=4:ts=4: