1 /* src/native/jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: jni.c 8056 2007-06-10 14:49:57Z michi $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #if defined(ENABLE_JAVASE)
43 # if defined(WITH_CLASSPATH_GNU)
44 # include "native/include/gnu_classpath_Pointer.h"
46 # if SIZEOF_VOID_P == 8
47 # include "native/include/gnu_classpath_Pointer64.h"
49 # include "native/include/gnu_classpath_Pointer32.h"
54 #include "native/include/java_lang_Object.h"
55 #include "native/include/java_lang_Byte.h"
56 #include "native/include/java_lang_Character.h"
57 #include "native/include/java_lang_Short.h"
58 #include "native/include/java_lang_Integer.h"
59 #include "native/include/java_lang_Boolean.h"
60 #include "native/include/java_lang_Long.h"
61 #include "native/include/java_lang_Float.h"
62 #include "native/include/java_lang_Double.h"
63 #include "native/include/java_lang_String.h"
64 #include "native/include/java_lang_Throwable.h"
66 #if defined(ENABLE_JAVASE)
67 # include "native/include/java_lang_ClassLoader.h"
69 # include "native/include/java_lang_reflect_Constructor.h"
70 # include "native/include/java_lang_reflect_Field.h"
71 # include "native/include/java_lang_reflect_Method.h"
73 # include "native/include/java_nio_Buffer.h"
74 # include "native/include/java_nio_DirectByteBufferImpl.h"
77 #if defined(ENABLE_JVMTI)
78 # include "native/jvmti/cacaodbg.h"
81 #include "native/vm/java_lang_Class.h"
83 #if defined(ENABLE_JAVASE)
84 # include "native/vm/java_lang_ClassLoader.h"
87 #include "threads/lock-common.h"
88 #include "threads/threads-common.h"
90 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/stringlocal.h"
99 #include "vm/jit/asmpart.h"
100 #include "vm/jit/jit.h"
101 #include "vm/jit/stacktrace.h"
103 #include "vmcore/loader.h"
104 #include "vmcore/options.h"
105 #include "vm/resolve.h"
106 #include "vmcore/statistics.h"
109 /* global variables ***********************************************************/
111 /* global reference table *****************************************************/
113 /* hashsize must be power of 2 */
115 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
117 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
120 /* direct buffer stuff ********************************************************/
122 #if defined(ENABLE_JAVASE)
123 static classinfo *class_java_nio_Buffer;
124 static classinfo *class_java_nio_DirectByteBufferImpl;
125 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
127 # if defined(WITH_CLASSPATH_GNU)
128 # if SIZEOF_VOID_P == 8
129 static classinfo *class_gnu_classpath_Pointer64;
131 static classinfo *class_gnu_classpath_Pointer32;
135 static methodinfo *dbbirw_init;
139 /* local reference table ******************************************************/
141 #if !defined(ENABLE_THREADS)
142 localref_table *_no_threads_localref_table;
146 /* accessing instance fields macros *******************************************/
148 #define SET_FIELD(o,type,f,value) \
149 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
151 #define GET_FIELD(o,type,f) \
152 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
155 /* some forward declarations **************************************************/
157 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
158 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
161 /* jni_init ********************************************************************
163 Initialize the JNI subsystem.
165 *******************************************************************************/
169 /* create global ref hashtable */
171 hashtable_global_ref = NEW(hashtable);
173 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
176 #if defined(ENABLE_JAVASE)
177 /* direct buffer stuff */
179 if (!(class_java_nio_Buffer =
180 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
181 !link_class(class_java_nio_Buffer))
184 if (!(class_java_nio_DirectByteBufferImpl =
185 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
186 !link_class(class_java_nio_DirectByteBufferImpl))
189 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
190 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
191 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
195 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
197 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
200 # if defined(WITH_CLASSPATH_GNU)
201 # if SIZEOF_VOID_P == 8
202 if (!(class_gnu_classpath_Pointer64 =
203 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
204 !link_class(class_gnu_classpath_Pointer64))
207 if (!(class_gnu_classpath_Pointer32 =
208 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
209 !link_class(class_gnu_classpath_Pointer32))
213 #endif /* defined(ENABLE_JAVASE) */
219 /* jni_init_localref_table *****************************************************
221 Initializes the local references table of the current thread.
223 *******************************************************************************/
225 bool jni_init_localref_table(void)
229 #if defined(ENABLE_GC_CACAO)
230 /* XXX this one will never get freed for the main thread;
231 call jni_free_localref_table() if you want to do it! */
232 lrt = NEW(localref_table);
234 lrt = GCNEW(localref_table);
240 lrt->capacity = LOCALREFTABLE_CAPACITY;
242 lrt->localframes = 1;
243 lrt->prev = LOCALREFTABLE;
245 /* clear the references array (memset is faster then a for-loop) */
247 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
255 /* jni_init_localref_table *****************************************************
257 Frees the local references table of the current thread.
259 *******************************************************************************/
261 bool jni_free_localref_table(void)
265 #if defined(ENABLE_GC_CACAO)
269 assert(lrt->prev == NULL);
271 FREE(lrt, localref_table);
273 LOCALREFTABLE = NULL;
280 /* _Jv_jni_vmargs_from_objectarray *********************************************
284 *******************************************************************************/
286 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
289 java_objectarray *params)
291 java_objectheader *param;
293 typedesc *paramtypes;
299 paramcount = descr->paramcount;
300 paramtypes = descr->paramtypes;
302 /* if method is non-static fill first block and skip `this' pointer */
308 vmargs[0].type = TYPE_ADR;
309 vmargs[0].data.l = (u8) (ptrint) o;
316 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
317 switch (paramtypes->type) {
318 /* primitive types */
323 param = params->data[j];
328 /* internally used data type */
329 vmargs[i].type = paramtypes->type;
331 /* convert the value according to its declared type */
333 c = param->vftbl->class;
335 switch (paramtypes->decltype) {
336 case PRIMITIVETYPE_BOOLEAN:
337 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
338 value = (s8) ((java_lang_Boolean *) param)->value;
342 vmargs[i].data.l = value;
345 case PRIMITIVETYPE_BYTE:
346 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
347 value = (s8) ((java_lang_Byte *) param)->value;
351 vmargs[i].data.l = value;
354 case PRIMITIVETYPE_CHAR:
355 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
356 value = (s8) ((java_lang_Character *) param)->value;
360 vmargs[i].data.l = value;
363 case PRIMITIVETYPE_SHORT:
364 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
365 value = (s8) ((java_lang_Short *) param)->value;
366 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
367 value = (s8) ((java_lang_Byte *) param)->value;
371 vmargs[i].data.l = value;
374 case PRIMITIVETYPE_INT:
375 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
376 value = (s8) ((java_lang_Integer *) param)->value;
377 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
378 value = (s8) ((java_lang_Short *) param)->value;
379 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
380 value = (s8) ((java_lang_Byte *) param)->value;
384 vmargs[i].data.l = value;
387 case PRIMITIVETYPE_LONG:
388 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
389 value = (s8) ((java_lang_Long *) param)->value;
390 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
391 value = (s8) ((java_lang_Integer *) param)->value;
392 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
393 value = (s8) ((java_lang_Short *) param)->value;
394 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
395 value = (s8) ((java_lang_Byte *) param)->value;
399 vmargs[i].data.l = value;
402 case PRIMITIVETYPE_FLOAT:
403 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
404 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
409 case PRIMITIVETYPE_DOUBLE:
410 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
411 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
412 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
413 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
424 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
427 if (params->data[j] != 0) {
428 if (paramtypes->arraydim > 0) {
429 if (!builtin_arrayinstanceof(params->data[j], c))
433 if (!builtin_instanceof(params->data[j], c))
438 vmargs[i].type = TYPE_ADR;
439 vmargs[i].data.l = (u8) (ptrint) params->data[j];
448 /* *rettype = descr->returntype.decltype; */
453 exceptions_throw_illegalargumentexception();
458 /* _Jv_jni_CallObjectMethod ****************************************************
460 Internal function to call Java Object methods.
462 *******************************************************************************/
464 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
466 methodinfo *m, va_list ap)
469 java_objectheader *ro;
471 STATISTICS(jniinvokation());
474 exceptions_throw_nullpointerexception();
478 /* Class initialization is done by the JIT compiler. This is ok
479 since a static method always belongs to the declaring class. */
481 if (m->flags & ACC_STATIC) {
482 /* For static methods we reset the object. */
487 /* for convenience */
492 /* For instance methods we make a virtual function table lookup. */
494 resm = method_vftbl_lookup(vftbl, m);
497 STATISTICS(jnicallXmethodnvokation());
499 ro = vm_call_method_valist(resm, o, ap);
505 /* _Jv_jni_CallObjectMethodA ***************************************************
507 Internal function to call Java Object methods.
509 *******************************************************************************/
511 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
513 methodinfo *m, jvalue *args)
516 java_objectheader *ro;
518 STATISTICS(jniinvokation());
521 exceptions_throw_nullpointerexception();
525 /* Class initialization is done by the JIT compiler. This is ok
526 since a static method always belongs to the declaring class. */
528 if (m->flags & ACC_STATIC) {
529 /* For static methods we reset the object. */
534 /* for convenience */
539 /* For instance methods we make a virtual function table lookup. */
541 resm = method_vftbl_lookup(vftbl, m);
544 STATISTICS(jnicallXmethodnvokation());
546 ro = vm_call_method_jvalue(resm, o, args);
552 /* _Jv_jni_CallIntMethod *******************************************************
554 Internal function to call Java integer class methods (boolean,
555 byte, char, short, int).
557 *******************************************************************************/
559 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
560 methodinfo *m, va_list ap)
565 STATISTICS(jniinvokation());
568 exceptions_throw_nullpointerexception();
572 /* Class initialization is done by the JIT compiler. This is ok
573 since a static method always belongs to the declaring class. */
575 if (m->flags & ACC_STATIC) {
576 /* For static methods we reset the object. */
581 /* for convenience */
586 /* For instance methods we make a virtual function table lookup. */
588 resm = method_vftbl_lookup(vftbl, m);
591 STATISTICS(jnicallXmethodnvokation());
593 i = vm_call_method_int_valist(resm, o, ap);
599 /* _Jv_jni_CallIntMethodA ******************************************************
601 Internal function to call Java integer class methods (boolean,
602 byte, char, short, int).
604 *******************************************************************************/
606 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
607 methodinfo *m, jvalue *args)
612 STATISTICS(jniinvokation());
615 exceptions_throw_nullpointerexception();
619 /* Class initialization is done by the JIT compiler. This is ok
620 since a static method always belongs to the declaring class. */
622 if (m->flags & ACC_STATIC) {
623 /* For static methods we reset the object. */
628 /* for convenience */
633 /* For instance methods we make a virtual function table lookup. */
635 resm = method_vftbl_lookup(vftbl, m);
638 STATISTICS(jnicallXmethodnvokation());
640 i = vm_call_method_int_jvalue(resm, o, args);
646 /* _Jv_jni_CallLongMethod ******************************************************
648 Internal function to call Java long methods.
650 *******************************************************************************/
652 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
653 methodinfo *m, va_list ap)
658 STATISTICS(jniinvokation());
661 exceptions_throw_nullpointerexception();
665 /* Class initialization is done by the JIT compiler. This is ok
666 since a static method always belongs to the declaring class. */
668 if (m->flags & ACC_STATIC) {
669 /* For static methods we reset the object. */
674 /* for convenience */
679 /* For instance methods we make a virtual function table lookup. */
681 resm = method_vftbl_lookup(vftbl, m);
684 STATISTICS(jnicallXmethodnvokation());
686 l = vm_call_method_long_valist(resm, o, ap);
692 /* _Jv_jni_CallLongMethodA *****************************************************
694 Internal function to call Java long methods.
696 *******************************************************************************/
698 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
699 methodinfo *m, jvalue *args)
704 STATISTICS(jniinvokation());
707 exceptions_throw_nullpointerexception();
711 /* Class initialization is done by the JIT compiler. This is ok
712 since a static method always belongs to the declaring class. */
714 if (m->flags & ACC_STATIC) {
715 /* For static methods we reset the object. */
720 /* for convenience */
725 /* For instance methods we make a virtual function table lookup. */
727 resm = method_vftbl_lookup(vftbl, m);
730 STATISTICS(jnicallXmethodnvokation());
732 l = vm_call_method_long_jvalue(resm, o, args);
738 /* _Jv_jni_CallFloatMethod *****************************************************
740 Internal function to call Java float methods.
742 *******************************************************************************/
744 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
745 methodinfo *m, va_list ap)
750 /* Class initialization is done by the JIT compiler. This is ok
751 since a static method always belongs to the declaring class. */
753 if (m->flags & ACC_STATIC) {
754 /* For static methods we reset the object. */
759 /* for convenience */
764 /* For instance methods we make a virtual function table lookup. */
766 resm = method_vftbl_lookup(vftbl, m);
769 STATISTICS(jnicallXmethodnvokation());
771 f = vm_call_method_float_valist(resm, o, ap);
777 /* _Jv_jni_CallFloatMethodA ****************************************************
779 Internal function to call Java float methods.
781 *******************************************************************************/
783 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
784 methodinfo *m, jvalue *args)
789 /* Class initialization is done by the JIT compiler. This is ok
790 since a static method always belongs to the declaring class. */
792 if (m->flags & ACC_STATIC) {
793 /* For static methods we reset the object. */
798 /* for convenience */
803 /* For instance methods we make a virtual function table lookup. */
805 resm = method_vftbl_lookup(vftbl, m);
808 STATISTICS(jnicallXmethodnvokation());
810 f = vm_call_method_float_jvalue(resm, o, args);
816 /* _Jv_jni_CallDoubleMethod ****************************************************
818 Internal function to call Java double methods.
820 *******************************************************************************/
822 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
823 methodinfo *m, va_list ap)
828 /* Class initialization is done by the JIT compiler. This is ok
829 since a static method always belongs to the declaring class. */
831 if (m->flags & ACC_STATIC) {
832 /* For static methods we reset the object. */
837 /* for convenience */
842 /* For instance methods we make a virtual function table lookup. */
844 resm = method_vftbl_lookup(vftbl, m);
847 d = vm_call_method_double_valist(resm, o, ap);
853 /* _Jv_jni_CallDoubleMethodA ***************************************************
855 Internal function to call Java double methods.
857 *******************************************************************************/
859 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
860 methodinfo *m, jvalue *args)
865 /* Class initialization is done by the JIT compiler. This is ok
866 since a static method always belongs to the declaring class. */
868 if (m->flags & ACC_STATIC) {
869 /* For static methods we reset the object. */
874 /* for convenience */
879 /* For instance methods we make a virtual function table lookup. */
881 resm = method_vftbl_lookup(vftbl, m);
884 d = vm_call_method_double_jvalue(resm, o, args);
890 /* _Jv_jni_CallVoidMethod ******************************************************
892 Internal function to call Java void methods.
894 *******************************************************************************/
896 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
897 methodinfo *m, va_list ap)
902 exceptions_throw_nullpointerexception();
906 /* Class initialization is done by the JIT compiler. This is ok
907 since a static method always belongs to the declaring class. */
909 if (m->flags & ACC_STATIC) {
910 /* For static methods we reset the object. */
915 /* for convenience */
920 /* For instance methods we make a virtual function table lookup. */
922 resm = method_vftbl_lookup(vftbl, m);
925 STATISTICS(jnicallXmethodnvokation());
927 (void) vm_call_method_valist(resm, o, ap);
931 /* _Jv_jni_CallVoidMethodA *****************************************************
933 Internal function to call Java void methods.
935 *******************************************************************************/
937 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
938 methodinfo *m, jvalue *args)
943 exceptions_throw_nullpointerexception();
947 /* Class initialization is done by the JIT compiler. This is ok
948 since a static method always belongs to the declaring class. */
950 if (m->flags & ACC_STATIC) {
951 /* For static methods we reset the object. */
956 /* for convenience */
961 /* For instance methods we make a virtual function table lookup. */
963 resm = method_vftbl_lookup(vftbl, m);
966 STATISTICS(jnicallXmethodnvokation());
968 (void) vm_call_method_jvalue(resm, o, args);
972 /* _Jv_jni_invokeNative ********************************************************
974 Invoke a method on the given object with the given arguments.
976 For instance methods OBJ must be != NULL and the method is looked up
977 in the vftbl of the object.
979 For static methods, OBJ is ignored.
981 *******************************************************************************/
983 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
984 java_objectarray *params)
988 java_objectheader *ro;
991 java_objectheader *xptr;
994 exceptions_throw_nullpointerexception();
998 argcount = m->parseddesc->paramcount;
999 paramcount = argcount;
1001 /* if method is non-static, remove the `this' pointer */
1003 if (!(m->flags & ACC_STATIC))
1006 /* For instance methods the object has to be an instance of the
1007 class the method belongs to. For static methods the obj
1008 parameter is ignored. */
1010 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
1011 exceptions_throw_illegalargumentexception();
1015 /* check if we got the right number of arguments */
1017 if (((params == NULL) && (paramcount != 0)) ||
1018 (params && (params->header.size != paramcount)))
1020 exceptions_throw_illegalargumentexception();
1024 /* for instance methods we need an object */
1026 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
1027 /* XXX not sure if that is the correct exception */
1028 exceptions_throw_nullpointerexception();
1032 /* for static methods, zero object to make subsequent code simpler */
1033 if (m->flags & ACC_STATIC)
1037 /* for instance methods we must do a vftbl lookup */
1038 resm = method_vftbl_lookup(o->vftbl, m);
1041 /* for static methods, just for convenience */
1045 vmargs = MNEW(vm_arg, argcount);
1047 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
1048 MFREE(vmargs, vm_arg, argcount);
1052 switch (resm->parseddesc->returntype.decltype) {
1054 (void) vm_call_method_vmarg(resm, argcount, vmargs);
1059 case PRIMITIVETYPE_BOOLEAN: {
1061 java_lang_Boolean *bo;
1063 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1065 ro = builtin_new(class_java_lang_Boolean);
1067 /* setting the value of the object direct */
1069 bo = (java_lang_Boolean *) ro;
1074 case PRIMITIVETYPE_BYTE: {
1078 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1080 ro = builtin_new(class_java_lang_Byte);
1082 /* setting the value of the object direct */
1084 bo = (java_lang_Byte *) ro;
1089 case PRIMITIVETYPE_CHAR: {
1091 java_lang_Character *co;
1093 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1095 ro = builtin_new(class_java_lang_Character);
1097 /* setting the value of the object direct */
1099 co = (java_lang_Character *) ro;
1104 case PRIMITIVETYPE_SHORT: {
1106 java_lang_Short *so;
1108 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1110 ro = builtin_new(class_java_lang_Short);
1112 /* setting the value of the object direct */
1114 so = (java_lang_Short *) ro;
1119 case PRIMITIVETYPE_INT: {
1121 java_lang_Integer *io;
1123 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1125 ro = builtin_new(class_java_lang_Integer);
1127 /* setting the value of the object direct */
1129 io = (java_lang_Integer *) ro;
1134 case PRIMITIVETYPE_LONG: {
1138 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1140 ro = builtin_new(class_java_lang_Long);
1142 /* setting the value of the object direct */
1144 lo = (java_lang_Long *) ro;
1149 case PRIMITIVETYPE_FLOAT: {
1151 java_lang_Float *fo;
1153 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1155 ro = builtin_new(class_java_lang_Float);
1157 /* setting the value of the object direct */
1159 fo = (java_lang_Float *) ro;
1164 case PRIMITIVETYPE_DOUBLE: {
1166 java_lang_Double *_do;
1168 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1170 ro = builtin_new(class_java_lang_Double);
1172 /* setting the value of the object direct */
1174 _do = (java_lang_Double *) ro;
1180 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1184 /* if this happens the exception has already been set by
1185 fill_callblock_from_objectarray */
1187 MFREE(vmargs, vm_arg, argcount);
1192 MFREE(vmargs, vm_arg, argcount);
1194 xptr = exceptions_get_exception();
1197 /* clear exception pointer, we are calling JIT code again */
1199 exceptions_clear_exception();
1201 exceptions_throw_invocationtargetexception(xptr);
1208 /* GetVersion ******************************************************************
1210 Returns the major version number in the higher 16 bits and the
1211 minor version number in the lower 16 bits.
1213 *******************************************************************************/
1215 jint _Jv_JNI_GetVersion(JNIEnv *env)
1217 STATISTICS(jniinvokation());
1219 /* we support JNI 1.4 */
1221 return JNI_VERSION_1_4;
1225 /* Class Operations ***********************************************************/
1227 /* DefineClass *****************************************************************
1229 Loads a class from a buffer of raw class data. The buffer
1230 containing the raw class data is not referenced by the VM after the
1231 DefineClass call returns, and it may be discarded if desired.
1233 *******************************************************************************/
1235 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1236 const jbyte *buf, jsize bufLen)
1238 #if defined(ENABLE_JAVASE)
1239 java_lang_ClassLoader *cl;
1240 java_lang_String *s;
1244 STATISTICS(jniinvokation());
1246 cl = (java_lang_ClassLoader *) loader;
1247 s = (java_lang_String *) javastring_new_from_utf_string(name);
1248 ba = (java_bytearray *) buf;
1250 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1253 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1255 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1257 /* keep compiler happy */
1264 /* FindClass *******************************************************************
1266 This function loads a locally-defined class. It searches the
1267 directories and zip files specified by the CLASSPATH environment
1268 variable for the class with the specified name.
1270 *******************************************************************************/
1272 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1274 #if defined(ENABLE_JAVASE)
1279 STATISTICS(jniinvokation());
1281 u = utf_new_char_classname((char *) name);
1283 /* Check stacktrace for classloader, if one found use it,
1284 otherwise use the system classloader. */
1286 /* Quote from the JNI documentation:
1288 In the Java 2 Platform, FindClass locates the class loader
1289 associated with the current native method. If the native code
1290 belongs to a system class, no class loader will be
1291 involved. Otherwise, the proper class loader will be invoked to
1292 load and link the named class. When FindClass is called through
1293 the Invocation Interface, there is no current native method or
1294 its associated class loader. In that case, the result of
1295 ClassLoader.getBaseClassLoader is used." */
1297 cc = stacktrace_getCurrentClass();
1300 c = load_class_from_sysloader(u);
1302 c = load_class_from_classloader(u, cc->classloader);
1310 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1312 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1314 /* keep compiler happy */
1321 /* GetSuperclass ***************************************************************
1323 If clazz represents any class other than the class Object, then
1324 this function returns the object that represents the superclass of
1325 the class specified by clazz.
1327 *******************************************************************************/
1329 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1333 STATISTICS(jniinvokation());
1335 c = ((classinfo *) sub)->super.cls;
1340 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1344 /* IsAssignableFrom ************************************************************
1346 Determines whether an object of sub can be safely cast to sup.
1348 *******************************************************************************/
1350 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1352 java_lang_Class *csup;
1353 java_lang_Class *csub;
1355 csup = (java_lang_Class *) sup;
1356 csub = (java_lang_Class *) sub;
1358 STATISTICS(jniinvokation());
1360 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1364 /* Throw ***********************************************************************
1366 Causes a java.lang.Throwable object to be thrown.
1368 *******************************************************************************/
1370 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1372 java_objectheader *o;
1374 STATISTICS(jniinvokation());
1376 o = (java_objectheader *) obj;
1378 exceptions_set_exception(o);
1384 /* ThrowNew ********************************************************************
1386 Constructs an exception object from the specified class with the
1387 message specified by message and causes that exception to be
1390 *******************************************************************************/
1392 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1395 java_objectheader *o;
1396 java_objectheader *s;
1398 STATISTICS(jniinvokation());
1400 c = (classinfo *) clazz;
1401 s = javastring_new_from_utf_string(msg);
1403 /* instantiate exception object */
1405 o = native_new_and_init_string(c, s);
1410 exceptions_set_exception(o);
1416 /* ExceptionOccurred ***********************************************************
1418 Determines if an exception is being thrown. The exception stays
1419 being thrown until either the native code calls ExceptionClear(),
1420 or the Java code handles the exception.
1422 *******************************************************************************/
1424 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1426 java_objectheader *o;
1428 STATISTICS(jniinvokation());
1430 o = exceptions_get_exception();
1432 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1436 /* ExceptionDescribe ***********************************************************
1438 Prints an exception and a backtrace of the stack to a system
1439 error-reporting channel, such as stderr. This is a convenience
1440 routine provided for debugging.
1442 *******************************************************************************/
1444 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1446 java_objectheader *o;
1449 STATISTICS(jniinvokation());
1451 o = exceptions_get_exception();
1454 /* clear exception, because we are calling jit code again */
1456 exceptions_clear_exception();
1458 /* get printStackTrace method from exception class */
1460 m = class_resolveclassmethod(o->vftbl->class,
1461 utf_printStackTrace,
1467 /* XXX what should we do? */
1470 /* print the stacktrace */
1472 (void) vm_call_method(m, o);
1477 /* ExceptionClear **************************************************************
1479 Clears any exception that is currently being thrown. If no
1480 exception is currently being thrown, this routine has no effect.
1482 *******************************************************************************/
1484 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1486 STATISTICS(jniinvokation());
1488 exceptions_clear_exception();
1492 /* FatalError ******************************************************************
1494 Raises a fatal error and does not expect the VM to recover. This
1495 function does not return.
1497 *******************************************************************************/
1499 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1501 STATISTICS(jniinvokation());
1503 /* this seems to be the best way */
1505 vm_abort("JNI Fatal error: %s", msg);
1509 /* PushLocalFrame **************************************************************
1511 Creates a new local reference frame, in which at least a given
1512 number of local references can be created.
1514 *******************************************************************************/
1516 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1519 localref_table *lrt;
1520 localref_table *nlrt;
1522 STATISTICS(jniinvokation());
1527 /* Allocate new local reference table on Java heap. Calculate the
1528 additional memory we have to allocate. */
1530 if (capacity > LOCALREFTABLE_CAPACITY)
1531 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1535 #if defined(ENABLE_GC_CACAO)
1536 nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1538 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1544 /* get current local reference table from thread */
1546 lrt = LOCALREFTABLE;
1548 /* Set up the new local reference table and add it to the local
1551 nlrt->capacity = capacity;
1553 nlrt->localframes = lrt->localframes + 1;
1556 /* store new local reference table in thread */
1558 LOCALREFTABLE = nlrt;
1564 /* PopLocalFrame ***************************************************************
1566 Pops off the current local reference frame, frees all the local
1567 references, and returns a local reference in the previous local
1568 reference frame for the given result object.
1570 *******************************************************************************/
1572 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1574 localref_table *lrt;
1575 localref_table *plrt;
1579 STATISTICS(jniinvokation());
1581 /* get current local reference table from thread */
1583 lrt = LOCALREFTABLE;
1585 localframes = lrt->localframes;
1587 /* Don't delete the top local frame, as this one is allocated in
1588 the native stub on the stack and is freed automagically on
1591 if (localframes == 1)
1592 return _Jv_JNI_NewLocalRef(env, result);
1594 /* release all current local frames */
1596 for (; localframes >= 1; localframes--) {
1597 /* get previous frame */
1601 /* clear all reference entries */
1603 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1607 #if defined(ENABLE_GC_CACAO)
1608 /* for the exact GC local reference tables are not on the heap,
1609 so we need to free them explicitly here. */
1611 if (lrt->capacity > LOCALREFTABLE_CAPACITY)
1612 additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
1616 MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1619 /* set new local references table */
1624 /* store new local reference table in thread */
1626 LOCALREFTABLE = lrt;
1628 /* add local reference and return the value */
1630 return _Jv_JNI_NewLocalRef(env, result);
1634 /* DeleteLocalRef **************************************************************
1636 Deletes the local reference pointed to by localRef.
1638 *******************************************************************************/
1640 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1642 java_objectheader *o;
1643 localref_table *lrt;
1646 STATISTICS(jniinvokation());
1648 o = (java_objectheader *) localRef;
1650 /* get local reference table (thread specific) */
1652 lrt = LOCALREFTABLE;
1654 /* go through all local frames */
1656 for (; lrt != NULL; lrt = lrt->prev) {
1658 /* and try to remove the reference */
1660 for (i = 0; i < lrt->capacity; i++) {
1661 if (lrt->refs[i] == o) {
1662 lrt->refs[i] = NULL;
1670 /* this should not happen */
1672 /* if (opt_checkjni) */
1673 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1674 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1678 /* IsSameObject ****************************************************************
1680 Tests whether two references refer to the same Java object.
1682 *******************************************************************************/
1684 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1686 STATISTICS(jniinvokation());
1695 /* NewLocalRef *****************************************************************
1697 Creates a new local reference that refers to the same object as ref.
1699 *******************************************************************************/
1701 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1703 localref_table *lrt;
1706 STATISTICS(jniinvokation());
1711 /* get local reference table (thread specific) */
1713 lrt = LOCALREFTABLE;
1715 /* Check if we have space for the requested reference? No,
1716 allocate a new frame. This is actually not what the spec says,
1717 but for compatibility reasons... */
1719 if (lrt->used == lrt->capacity) {
1720 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1723 /* get the new local reference table */
1725 lrt = LOCALREFTABLE;
1728 /* insert the reference */
1730 for (i = 0; i < lrt->capacity; i++) {
1731 if (lrt->refs[i] == NULL) {
1732 lrt->refs[i] = (java_objectheader *) ref;
1739 /* should not happen, just to be sure */
1743 /* keep compiler happy */
1749 /* EnsureLocalCapacity *********************************************************
1751 Ensures that at least a given number of local references can be
1752 created in the current thread
1754 *******************************************************************************/
1756 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1758 localref_table *lrt;
1760 STATISTICS(jniinvokation());
1762 /* get local reference table (thread specific) */
1764 lrt = LOCALREFTABLE;
1766 /* check if capacity elements are available in the local references table */
1768 if ((lrt->used + capacity) > lrt->capacity)
1769 return _Jv_JNI_PushLocalFrame(env, capacity);
1775 /* AllocObject *****************************************************************
1777 Allocates a new Java object without invoking any of the
1778 constructors for the object. Returns a reference to the object.
1780 *******************************************************************************/
1782 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1785 java_objectheader *o;
1787 STATISTICS(jniinvokation());
1789 c = (classinfo *) clazz;
1791 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1792 exceptions_throw_instantiationexception(c);
1798 return _Jv_JNI_NewLocalRef(env, o);
1802 /* NewObject *******************************************************************
1804 Programmers place all arguments that are to be passed to the
1805 constructor immediately following the methodID
1806 argument. NewObject() accepts these arguments and passes them to
1807 the Java method that the programmer wishes to invoke.
1809 *******************************************************************************/
1811 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1813 java_objectheader *o;
1817 STATISTICS(jniinvokation());
1819 m = (methodinfo *) methodID;
1823 o = builtin_new(clazz);
1828 /* call constructor */
1830 va_start(ap, methodID);
1831 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1834 return _Jv_JNI_NewLocalRef(env, o);
1838 /* NewObjectV ******************************************************************
1840 Programmers place all arguments that are to be passed to the
1841 constructor in an args argument of type va_list that immediately
1842 follows the methodID argument. NewObjectV() accepts these
1843 arguments, and, in turn, passes them to the Java method that the
1844 programmer wishes to invoke.
1846 *******************************************************************************/
1848 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1851 java_objectheader *o;
1854 STATISTICS(jniinvokation());
1856 m = (methodinfo *) methodID;
1860 o = builtin_new(clazz);
1865 /* call constructor */
1867 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1869 return _Jv_JNI_NewLocalRef(env, o);
1873 /* NewObjectA *****************************************************************
1875 Programmers place all arguments that are to be passed to the
1876 constructor in an args array of jvalues that immediately follows
1877 the methodID argument. NewObjectA() accepts the arguments in this
1878 array, and, in turn, passes them to the Java method that the
1879 programmer wishes to invoke.
1881 *******************************************************************************/
1883 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1886 java_objectheader *o;
1889 STATISTICS(jniinvokation());
1891 m = (methodinfo *) methodID;
1895 o = builtin_new(clazz);
1900 /* call constructor */
1902 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1904 return _Jv_JNI_NewLocalRef(env, o);
1908 /* GetObjectClass **************************************************************
1910 Returns the class of an object.
1912 *******************************************************************************/
1914 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1916 java_objectheader *o;
1919 STATISTICS(jniinvokation());
1921 o = (java_objectheader *) obj;
1923 if ((o == NULL) || (o->vftbl == NULL))
1926 c = o->vftbl->class;
1928 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1932 /* IsInstanceOf ****************************************************************
1934 Tests whether an object is an instance of a class.
1936 *******************************************************************************/
1938 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1941 java_lang_Object *o;
1943 STATISTICS(jniinvokation());
1945 c = (java_lang_Class *) clazz;
1946 o = (java_lang_Object *) obj;
1948 return _Jv_java_lang_Class_isInstance(c, o);
1952 /* Reflection Support *********************************************************/
1954 /* FromReflectedMethod *********************************************************
1956 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1957 object to a method ID.
1959 *******************************************************************************/
1961 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1963 #if defined(ENABLE_JAVASE)
1968 STATISTICS(jniinvokation());
1973 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1974 java_lang_reflect_Method *rm;
1976 rm = (java_lang_reflect_Method *) method;
1977 c = (classinfo *) (rm->declaringClass);
1980 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1981 java_lang_reflect_Constructor *rc;
1983 rc = (java_lang_reflect_Constructor *) method;
1984 c = (classinfo *) (rc->clazz);
1990 mi = &(c->methods[slot]);
1992 return (jmethodID) mi;
1994 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1996 /* keep compiler happy */
2003 /* FromReflectedField **********************************************************
2005 Converts a java.lang.reflect.Field to a field ID.
2007 *******************************************************************************/
2009 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
2011 #if defined(ENABLE_JAVASE)
2012 java_lang_reflect_Field *rf;
2016 STATISTICS(jniinvokation());
2018 rf = (java_lang_reflect_Field *) field;
2023 c = (classinfo *) rf->declaringClass;
2025 f = &(c->fields[rf->slot]);
2027 return (jfieldID) f;
2029 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
2031 /* keep compiler happy */
2038 /* ToReflectedMethod ***********************************************************
2040 Converts a method ID derived from cls to an instance of the
2041 java.lang.reflect.Method class or to an instance of the
2042 java.lang.reflect.Constructor class.
2044 *******************************************************************************/
2046 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2049 STATISTICS(jniinvokation());
2051 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2057 /* ToReflectedField ************************************************************
2059 Converts a field ID derived from cls to an instance of the
2060 java.lang.reflect.Field class.
2062 *******************************************************************************/
2064 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2067 STATISTICS(jniinvokation());
2069 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2075 /* Calling Instance Methods ***************************************************/
2077 /* GetMethodID *****************************************************************
2079 Returns the method ID for an instance (nonstatic) method of a class
2080 or interface. The method may be defined in one of the clazz's
2081 superclasses and inherited by clazz. The method is determined by
2082 its name and signature.
2084 GetMethodID() causes an uninitialized class to be initialized.
2086 *******************************************************************************/
2088 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2096 STATISTICS(jniinvokation());
2098 c = (classinfo *) clazz;
2103 if (!(c->state & CLASS_INITIALIZED))
2104 if (!initialize_class(c))
2107 /* try to get the method of the class or one of it's superclasses */
2109 uname = utf_new_char((char *) name);
2110 udesc = utf_new_char((char *) sig);
2112 m = class_resolvemethod(clazz, uname, udesc);
2114 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2115 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2120 return (jmethodID) m;
2124 /* JNI-functions for calling instance methods *********************************/
2126 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2129 java_objectheader *o;
2131 java_objectheader *ret;
2134 o = (java_objectheader *) obj;
2135 m = (methodinfo *) methodID;
2137 va_start(ap, methodID);
2138 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2141 return _Jv_JNI_NewLocalRef(env, ret);
2145 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2148 java_objectheader *o;
2150 java_objectheader *ret;
2152 o = (java_objectheader *) obj;
2153 m = (methodinfo *) methodID;
2155 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2157 return _Jv_JNI_NewLocalRef(env, ret);
2161 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2164 java_objectheader *o;
2166 java_objectheader *ret;
2168 o = (java_objectheader *) obj;
2169 m = (methodinfo *) methodID;
2171 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2173 return _Jv_JNI_NewLocalRef(env, ret);
2177 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2180 java_objectheader *o;
2185 o = (java_objectheader *) obj;
2186 m = (methodinfo *) methodID;
2188 va_start(ap, methodID);
2189 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2196 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2197 jmethodID methodID, va_list args)
2199 java_objectheader *o;
2203 o = (java_objectheader *) obj;
2204 m = (methodinfo *) methodID;
2206 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2212 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2213 jmethodID methodID, jvalue *args)
2215 java_objectheader *o;
2219 o = (java_objectheader *) obj;
2220 m = (methodinfo *) methodID;
2222 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2228 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2230 java_objectheader *o;
2235 o = (java_objectheader *) obj;
2236 m = (methodinfo *) methodID;
2238 va_start(ap, methodID);
2239 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2247 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2250 java_objectheader *o;
2254 o = (java_objectheader *) obj;
2255 m = (methodinfo *) methodID;
2257 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2263 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2266 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2272 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2274 java_objectheader *o;
2279 o = (java_objectheader *) obj;
2280 m = (methodinfo *) methodID;
2282 va_start(ap, methodID);
2283 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2290 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2293 java_objectheader *o;
2297 o = (java_objectheader *) obj;
2298 m = (methodinfo *) methodID;
2300 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2306 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2309 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2315 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2318 java_objectheader *o;
2323 o = (java_objectheader *) obj;
2324 m = (methodinfo *) methodID;
2326 va_start(ap, methodID);
2327 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2334 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2337 java_objectheader *o;
2341 o = (java_objectheader *) obj;
2342 m = (methodinfo *) methodID;
2344 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2350 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2353 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2360 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2362 java_objectheader *o;
2367 o = (java_objectheader *) obj;
2368 m = (methodinfo *) methodID;
2370 va_start(ap, methodID);
2371 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2378 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2381 java_objectheader *o;
2385 o = (java_objectheader *) obj;
2386 m = (methodinfo *) methodID;
2388 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2394 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2397 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2404 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2406 java_objectheader *o;
2411 o = (java_objectheader *) obj;
2412 m = (methodinfo *) methodID;
2414 va_start(ap, methodID);
2415 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2422 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2425 java_objectheader *o;
2429 o = (java_objectheader *) obj;
2430 m = (methodinfo *) methodID;
2432 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2438 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2441 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2448 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2451 java_objectheader *o;
2456 o = (java_objectheader *) obj;
2457 m = (methodinfo *) methodID;
2459 va_start(ap, methodID);
2460 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2467 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2470 java_objectheader *o;
2474 o = (java_objectheader *) obj;
2475 m = (methodinfo *) methodID;
2477 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2483 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2486 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2493 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2496 java_objectheader *o;
2501 o = (java_objectheader *) obj;
2502 m = (methodinfo *) methodID;
2504 va_start(ap, methodID);
2505 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2512 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2515 java_objectheader *o;
2519 o = (java_objectheader *) obj;
2520 m = (methodinfo *) methodID;
2522 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2528 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2531 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2538 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2540 java_objectheader *o;
2544 o = (java_objectheader *) obj;
2545 m = (methodinfo *) methodID;
2547 va_start(ap, methodID);
2548 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2553 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2556 java_objectheader *o;
2559 o = (java_objectheader *) obj;
2560 m = (methodinfo *) methodID;
2562 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2566 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2569 java_objectheader *o;
2572 o = (java_objectheader *) obj;
2573 m = (methodinfo *) methodID;
2575 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2580 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2581 jclass clazz, jmethodID methodID,
2584 java_objectheader *o;
2587 java_objectheader *r;
2590 o = (java_objectheader *) obj;
2591 c = (classinfo *) clazz;
2592 m = (methodinfo *) methodID;
2594 va_start(ap, methodID);
2595 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2598 return _Jv_JNI_NewLocalRef(env, r);
2602 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2603 jclass clazz, jmethodID methodID,
2606 java_objectheader *o;
2609 java_objectheader *r;
2611 o = (java_objectheader *) obj;
2612 c = (classinfo *) clazz;
2613 m = (methodinfo *) methodID;
2615 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2617 return _Jv_JNI_NewLocalRef(env, r);
2621 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2622 jclass clazz, jmethodID methodID,
2625 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2627 return _Jv_JNI_NewLocalRef(env, NULL);
2632 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2633 jclass clazz, jmethodID methodID,
2636 java_objectheader *o;
2642 o = (java_objectheader *) obj;
2643 c = (classinfo *) clazz;
2644 m = (methodinfo *) methodID;
2646 va_start(ap, methodID);
2647 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2654 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2655 jclass clazz, jmethodID methodID,
2658 java_objectheader *o;
2663 o = (java_objectheader *) obj;
2664 c = (classinfo *) clazz;
2665 m = (methodinfo *) methodID;
2667 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2673 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2674 jclass clazz, jmethodID methodID,
2677 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2683 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2684 jmethodID methodID, ...)
2686 java_objectheader *o;
2692 o = (java_objectheader *) obj;
2693 c = (classinfo *) clazz;
2694 m = (methodinfo *) methodID;
2696 va_start(ap, methodID);
2697 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2704 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2705 jmethodID methodID, va_list args)
2707 java_objectheader *o;
2712 o = (java_objectheader *) obj;
2713 c = (classinfo *) clazz;
2714 m = (methodinfo *) methodID;
2716 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2722 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2723 jmethodID methodID, jvalue *args)
2725 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2732 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2733 jmethodID methodID, ...)
2735 java_objectheader *o;
2741 o = (java_objectheader *) obj;
2742 c = (classinfo *) clazz;
2743 m = (methodinfo *) methodID;
2745 va_start(ap, methodID);
2746 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2753 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2754 jmethodID methodID, va_list args)
2756 java_objectheader *o;
2761 o = (java_objectheader *) obj;
2762 c = (classinfo *) clazz;
2763 m = (methodinfo *) methodID;
2765 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2771 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2772 jmethodID methodID, jvalue *args)
2774 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2781 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2782 jclass clazz, jmethodID methodID, ...)
2784 java_objectheader *o;
2790 o = (java_objectheader *) obj;
2791 c = (classinfo *) clazz;
2792 m = (methodinfo *) methodID;
2794 va_start(ap, methodID);
2795 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2802 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2803 jclass clazz, jmethodID methodID,
2806 java_objectheader *o;
2811 o = (java_objectheader *) obj;
2812 c = (classinfo *) clazz;
2813 m = (methodinfo *) methodID;
2815 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2821 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2822 jclass clazz, jmethodID methodID,
2825 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2832 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2833 jmethodID methodID, ...)
2835 java_objectheader *o;
2841 o = (java_objectheader *) obj;
2842 c = (classinfo *) clazz;
2843 m = (methodinfo *) methodID;
2845 va_start(ap, methodID);
2846 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2853 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2854 jmethodID methodID, va_list args)
2856 java_objectheader *o;
2861 o = (java_objectheader *) obj;
2862 c = (classinfo *) clazz;
2863 m = (methodinfo *) methodID;
2865 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2871 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2872 jmethodID methodID, jvalue *args)
2874 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2881 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2882 jmethodID methodID, ...)
2884 java_objectheader *o;
2890 o = (java_objectheader *) obj;
2891 c = (classinfo *) clazz;
2892 m = (methodinfo *) methodID;
2894 va_start(ap, methodID);
2895 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2902 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2903 jmethodID methodID, va_list args)
2905 java_objectheader *o;
2910 o = (java_objectheader *) obj;
2911 c = (classinfo *) clazz;
2912 m = (methodinfo *) methodID;
2914 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2920 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2921 jmethodID methodID, jvalue *args)
2923 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2930 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2931 jclass clazz, jmethodID methodID, ...)
2933 java_objectheader *o;
2939 o = (java_objectheader *) obj;
2940 c = (classinfo *) clazz;
2941 m = (methodinfo *) methodID;
2943 va_start(ap, methodID);
2944 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2951 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2952 jclass clazz, jmethodID methodID,
2955 java_objectheader *o;
2960 o = (java_objectheader *) obj;
2961 c = (classinfo *) clazz;
2962 m = (methodinfo *) methodID;
2964 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2970 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2971 jclass clazz, jmethodID methodID,
2974 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2981 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2982 jclass clazz, jmethodID methodID,
2985 java_objectheader *o;
2991 o = (java_objectheader *) obj;
2992 c = (classinfo *) clazz;
2993 m = (methodinfo *) methodID;
2995 va_start(ap, methodID);
2996 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
3003 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
3004 jclass clazz, jmethodID methodID,
3007 java_objectheader *o;
3012 o = (java_objectheader *) obj;
3013 c = (classinfo *) clazz;
3014 m = (methodinfo *) methodID;
3016 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
3022 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
3023 jclass clazz, jmethodID methodID,
3026 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
3033 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
3034 jmethodID methodID, ...)
3036 java_objectheader *o;
3041 o = (java_objectheader *) obj;
3042 c = (classinfo *) clazz;
3043 m = (methodinfo *) methodID;
3045 va_start(ap, methodID);
3046 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3051 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3052 jmethodID methodID, va_list args)
3054 java_objectheader *o;
3058 o = (java_objectheader *) obj;
3059 c = (classinfo *) clazz;
3060 m = (methodinfo *) methodID;
3062 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3066 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3067 jmethodID methodID, jvalue * args)
3069 java_objectheader *o;
3073 o = (java_objectheader *) obj;
3074 c = (classinfo *) clazz;
3075 m = (methodinfo *) methodID;
3077 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3081 /* Accessing Fields of Objects ************************************************/
3083 /* GetFieldID ******************************************************************
3085 Returns the field ID for an instance (nonstatic) field of a
3086 class. The field is specified by its name and signature. The
3087 Get<type>Field and Set<type>Field families of accessor functions
3088 use field IDs to retrieve object fields.
3090 *******************************************************************************/
3092 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3100 STATISTICS(jniinvokation());
3102 c = (classinfo *) clazz;
3104 uname = utf_new_char((char *) name);
3105 udesc = utf_new_char((char *) sig);
3107 f = class_findfield(clazz, uname, udesc);
3110 exceptions_throw_nosuchfielderror(c, uname);
3112 return (jfieldID) f;
3116 /* Get<type>Field Routines *****************************************************
3118 This family of accessor routines returns the value of an instance
3119 (nonstatic) field of an object. The field to access is specified by
3120 a field ID obtained by calling GetFieldID().
3122 *******************************************************************************/
3124 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3126 java_objectheader *o;
3128 STATISTICS(jniinvokation());
3130 o = GET_FIELD(obj, java_objectheader*, fieldID);
3132 return _Jv_JNI_NewLocalRef(env, o);
3136 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3140 STATISTICS(jniinvokation());
3142 i = GET_FIELD(obj, s4, fieldID);
3144 return (jboolean) i;
3148 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3152 STATISTICS(jniinvokation());
3154 i = GET_FIELD(obj, s4, fieldID);
3160 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3164 STATISTICS(jniinvokation());
3166 i = GET_FIELD(obj, s4, fieldID);
3172 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3176 STATISTICS(jniinvokation());
3178 i = GET_FIELD(obj, s4, fieldID);
3184 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3186 java_objectheader *o;
3190 STATISTICS(jniinvokation());
3192 o = (java_objectheader *) obj;
3193 f = (fieldinfo *) fieldID;
3195 i = GET_FIELD(o, s4, f);
3201 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3205 STATISTICS(jniinvokation());
3207 l = GET_FIELD(obj, s8, fieldID);
3213 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3217 STATISTICS(jniinvokation());
3219 f = GET_FIELD(obj, float, fieldID);
3225 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3229 STATISTICS(jniinvokation());
3231 d = GET_FIELD(obj, double, fieldID);
3237 /* Set<type>Field Routines *****************************************************
3239 This family of accessor routines sets the value of an instance
3240 (nonstatic) field of an object. The field to access is specified by
3241 a field ID obtained by calling GetFieldID().
3243 *******************************************************************************/
3245 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3248 STATISTICS(jniinvokation());
3250 SET_FIELD(obj, java_objectheader*, fieldID, value);
3254 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3257 STATISTICS(jniinvokation());
3259 SET_FIELD(obj, s4, fieldID, value);
3263 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3266 STATISTICS(jniinvokation());
3268 SET_FIELD(obj, s4, fieldID, value);
3272 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3275 STATISTICS(jniinvokation());
3277 SET_FIELD(obj, s4, fieldID, value);
3281 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3284 STATISTICS(jniinvokation());
3286 SET_FIELD(obj, s4, fieldID, value);
3290 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3292 STATISTICS(jniinvokation());
3294 SET_FIELD(obj, s4, fieldID, value);
3298 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3301 STATISTICS(jniinvokation());
3303 SET_FIELD(obj, s8, fieldID, value);
3307 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3310 STATISTICS(jniinvokation());
3312 SET_FIELD(obj, float, fieldID, value);
3316 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3319 STATISTICS(jniinvokation());
3321 SET_FIELD(obj, double, fieldID, value);
3325 /* Calling Static Methods *****************************************************/
3327 /* GetStaticMethodID ***********************************************************
3329 Returns the method ID for a static method of a class. The method is
3330 specified by its name and signature.
3332 GetStaticMethodID() causes an uninitialized class to be
3335 *******************************************************************************/
3337 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3345 STATISTICS(jniinvokation());
3347 c = (classinfo *) clazz;
3352 if (!(c->state & CLASS_INITIALIZED))
3353 if (!initialize_class(c))
3356 /* try to get the static method of the class */
3358 uname = utf_new_char((char *) name);
3359 udesc = utf_new_char((char *) sig);
3361 m = class_resolvemethod(c, uname, udesc);
3363 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3364 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3369 return (jmethodID) m;
3373 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3374 jmethodID methodID, ...)
3377 java_objectheader *o;
3380 m = (methodinfo *) methodID;
3382 va_start(ap, methodID);
3383 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3386 return _Jv_JNI_NewLocalRef(env, o);
3390 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3391 jmethodID methodID, va_list args)
3394 java_objectheader *o;
3396 m = (methodinfo *) methodID;
3398 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3400 return _Jv_JNI_NewLocalRef(env, o);
3404 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3405 jmethodID methodID, jvalue *args)
3408 java_objectheader *o;
3410 m = (methodinfo *) methodID;
3412 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3414 return _Jv_JNI_NewLocalRef(env, o);
3418 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3419 jmethodID methodID, ...)
3425 m = (methodinfo *) methodID;
3427 va_start(ap, methodID);
3428 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3435 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3436 jmethodID methodID, va_list args)
3441 m = (methodinfo *) methodID;
3443 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3449 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3450 jmethodID methodID, jvalue *args)
3455 m = (methodinfo *) methodID;
3457 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3463 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3464 jmethodID methodID, ...)
3470 m = (methodinfo *) methodID;
3472 va_start(ap, methodID);
3473 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3480 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3481 jmethodID methodID, va_list args)
3486 m = (methodinfo *) methodID;
3488 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3494 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3495 jmethodID methodID, jvalue *args)
3500 m = (methodinfo *) methodID;
3502 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3508 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3509 jmethodID methodID, ...)
3515 m = (methodinfo *) methodID;
3517 va_start(ap, methodID);
3518 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3525 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3526 jmethodID methodID, va_list args)
3531 m = (methodinfo *) methodID;
3533 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3539 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3540 jmethodID methodID, jvalue *args)
3545 m = (methodinfo *) methodID;
3547 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3553 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3554 jmethodID methodID, ...)
3560 m = (methodinfo *) methodID;
3562 va_start(ap, methodID);
3563 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3570 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3571 jmethodID methodID, va_list args)
3576 m = (methodinfo *) methodID;
3578 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3584 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3585 jmethodID methodID, jvalue *args)
3590 m = (methodinfo *) methodID;
3592 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3598 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3605 m = (methodinfo *) methodID;
3607 va_start(ap, methodID);
3608 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3615 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3616 jmethodID methodID, va_list args)
3621 m = (methodinfo *) methodID;
3623 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3629 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3630 jmethodID methodID, jvalue *args)
3635 m = (methodinfo *) methodID;
3637 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3643 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3644 jmethodID methodID, ...)
3650 m = (methodinfo *) methodID;
3652 va_start(ap, methodID);
3653 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3660 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3661 jmethodID methodID, va_list args)
3666 m = (methodinfo *) methodID;
3668 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3674 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3675 jmethodID methodID, jvalue *args)
3680 m = (methodinfo *) methodID;
3682 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3689 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3690 jmethodID methodID, ...)
3696 m = (methodinfo *) methodID;
3698 va_start(ap, methodID);
3699 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3706 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3707 jmethodID methodID, va_list args)
3712 m = (methodinfo *) methodID;
3714 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3720 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3721 jmethodID methodID, jvalue *args)
3726 m = (methodinfo *) methodID;
3728 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3734 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3735 jmethodID methodID, ...)
3741 m = (methodinfo *) methodID;
3743 va_start(ap, methodID);
3744 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3751 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3752 jmethodID methodID, va_list args)
3757 m = (methodinfo *) methodID;
3759 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3765 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3766 jmethodID methodID, jvalue *args)
3771 m = (methodinfo *) methodID;
3773 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3779 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3780 jmethodID methodID, ...)
3785 m = (methodinfo *) methodID;
3787 va_start(ap, methodID);
3788 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3793 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3794 jmethodID methodID, va_list args)
3798 m = (methodinfo *) methodID;
3800 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3804 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3805 jmethodID methodID, jvalue * args)
3809 m = (methodinfo *) methodID;
3811 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3815 /* Accessing Static Fields ****************************************************/
3817 /* GetStaticFieldID ************************************************************
3819 Returns the field ID for a static field of a class. The field is
3820 specified by its name and signature. The GetStatic<type>Field and
3821 SetStatic<type>Field families of accessor functions use field IDs
3822 to retrieve static fields.
3824 *******************************************************************************/
3826 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3834 STATISTICS(jniinvokation());
3836 c = (classinfo *) clazz;
3838 uname = utf_new_char((char *) name);
3839 usig = utf_new_char((char *) sig);
3841 f = class_findfield(clazz, uname, usig);
3844 exceptions_throw_nosuchfielderror(c, uname);
3846 return (jfieldID) f;
3850 /* GetStatic<type>Field ********************************************************
3852 This family of accessor routines returns the value of a static
3855 *******************************************************************************/
3857 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3863 STATISTICS(jniinvokation());
3865 c = (classinfo *) clazz;
3866 f = (fieldinfo *) fieldID;
3868 if (!(c->state & CLASS_INITIALIZED))
3869 if (!initialize_class(c))
3872 return _Jv_JNI_NewLocalRef(env, f->value.a);
3876 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3882 STATISTICS(jniinvokation());
3884 c = (classinfo *) clazz;
3885 f = (fieldinfo *) fieldID;
3887 if (!(c->state & CLASS_INITIALIZED))
3888 if (!initialize_class(c))
3895 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3900 STATISTICS(jniinvokation());
3902 c = (classinfo *) clazz;
3903 f = (fieldinfo *) fieldID;
3905 if (!(c->state & CLASS_INITIALIZED))
3906 if (!initialize_class(c))
3913 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3918 STATISTICS(jniinvokation());
3920 c = (classinfo *) clazz;
3921 f = (fieldinfo *) fieldID;
3923 if (!(c->state & CLASS_INITIALIZED))
3924 if (!initialize_class(c))
3931 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3936 STATISTICS(jniinvokation());
3938 c = (classinfo *) clazz;
3939 f = (fieldinfo *) fieldID;
3941 if (!(c->state & CLASS_INITIALIZED))
3942 if (!initialize_class(c))
3949 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3954 STATISTICS(jniinvokation());
3956 c = (classinfo *) clazz;
3957 f = (fieldinfo *) fieldID;
3959 if (!(c->state & CLASS_INITIALIZED))
3960 if (!initialize_class(c))
3967 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3972 STATISTICS(jniinvokation());
3974 c = (classinfo *) clazz;
3975 f = (fieldinfo *) fieldID;
3977 if (!(c->state & CLASS_INITIALIZED))
3978 if (!initialize_class(c))
3985 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3990 STATISTICS(jniinvokation());
3992 c = (classinfo *) clazz;
3993 f = (fieldinfo *) fieldID;
3995 if (!(c->state & CLASS_INITIALIZED))
3996 if (!initialize_class(c))
4003 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
4009 STATISTICS(jniinvokation());
4011 c = (classinfo *) clazz;
4012 f = (fieldinfo *) fieldID;
4014 if (!(c->state & CLASS_INITIALIZED))
4015 if (!initialize_class(c))
4022 /* SetStatic<type>Field *******************************************************
4024 This family of accessor routines sets the value of a static field
4027 *******************************************************************************/
4029 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4035 STATISTICS(jniinvokation());
4037 c = (classinfo *) clazz;
4038 f = (fieldinfo *) fieldID;
4040 if (!(c->state & CLASS_INITIALIZED))
4041 if (!initialize_class(c))
4048 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4054 STATISTICS(jniinvokation());
4056 c = (classinfo *) clazz;
4057 f = (fieldinfo *) fieldID;
4059 if (!(c->state & CLASS_INITIALIZED))
4060 if (!initialize_class(c))
4067 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4073 STATISTICS(jniinvokation());
4075 c = (classinfo *) clazz;
4076 f = (fieldinfo *) fieldID;
4078 if (!(c->state & CLASS_INITIALIZED))
4079 if (!initialize_class(c))
4086 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4092 STATISTICS(jniinvokation());
4094 c = (classinfo *) clazz;
4095 f = (fieldinfo *) fieldID;
4097 if (!(c->state & CLASS_INITIALIZED))
4098 if (!initialize_class(c))
4105 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4111 STATISTICS(jniinvokation());
4113 c = (classinfo *) clazz;
4114 f = (fieldinfo *) fieldID;
4116 if (!(c->state & CLASS_INITIALIZED))
4117 if (!initialize_class(c))
4124 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4130 STATISTICS(jniinvokation());
4132 c = (classinfo *) clazz;
4133 f = (fieldinfo *) fieldID;
4135 if (!(c->state & CLASS_INITIALIZED))
4136 if (!initialize_class(c))
4143 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4149 STATISTICS(jniinvokation());
4151 c = (classinfo *) clazz;
4152 f = (fieldinfo *) fieldID;
4154 if (!(c->state & CLASS_INITIALIZED))
4155 if (!initialize_class(c))
4162 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4168 STATISTICS(jniinvokation());
4170 c = (classinfo *) clazz;
4171 f = (fieldinfo *) fieldID;
4173 if (!(c->state & CLASS_INITIALIZED))
4174 if (!initialize_class(c))
4181 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4187 STATISTICS(jniinvokation());
4189 c = (classinfo *) clazz;
4190 f = (fieldinfo *) fieldID;
4192 if (!(c->state & CLASS_INITIALIZED))
4193 if (!initialize_class(c))
4200 /* String Operations **********************************************************/
4202 /* NewString *******************************************************************
4204 Create new java.lang.String object from an array of Unicode
4207 *******************************************************************************/
4209 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4211 java_lang_String *s;
4215 STATISTICS(jniinvokation());
4217 s = (java_lang_String *) builtin_new(class_java_lang_String);
4218 a = builtin_newarray_char(len);
4220 /* javastring or characterarray could not be created */
4221 if ((a == NULL) || (s == NULL))
4225 for (i = 0; i < len; i++)
4226 a->data[i] = buf[i];
4232 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4236 static jchar emptyStringJ[]={0,0};
4238 /* GetStringLength *************************************************************
4240 Returns the length (the count of Unicode characters) of a Java
4243 *******************************************************************************/
4245 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4247 return ((java_lang_String *) str)->count;
4251 /******************** convertes javastring to u2-array ****************************/
4253 u2 *javastring_tou2(jstring so)
4255 java_lang_String *s;
4260 STATISTICS(jniinvokation());
4262 s = (java_lang_String *) so;
4272 /* allocate memory */
4274 stringbuffer = MNEW(u2, s->count + 1);
4278 for (i = 0; i < s->count; i++)
4279 stringbuffer[i] = a->data[s->offset + i];
4281 /* terminate string */
4283 stringbuffer[i] = '\0';
4285 return stringbuffer;
4289 /* GetStringChars **************************************************************
4291 Returns a pointer to the array of Unicode characters of the
4292 string. This pointer is valid until ReleaseStringChars() is called.
4294 *******************************************************************************/
4296 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4300 STATISTICS(jniinvokation());
4302 jc = javastring_tou2(str);
4314 return emptyStringJ;
4318 /* ReleaseStringChars **********************************************************
4320 Informs the VM that the native code no longer needs access to
4321 chars. The chars argument is a pointer obtained from string using
4324 *******************************************************************************/
4326 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4328 STATISTICS(jniinvokation());
4330 if (chars == emptyStringJ)
4333 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4337 /* NewStringUTF ****************************************************************
4339 Constructs a new java.lang.String object from an array of UTF-8
4342 *******************************************************************************/
4344 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4346 java_lang_String *s;
4348 STATISTICS(jniinvokation());
4350 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4352 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4356 /****************** returns the utf8 length in bytes of a string *******************/
4358 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4360 java_lang_String *s = (java_lang_String*) string;
4362 STATISTICS(jniinvokation());
4364 return (jsize) u2_utflength(s->value->data, s->count);
4368 /* GetStringUTFChars ***********************************************************
4370 Returns a pointer to an array of UTF-8 characters of the
4371 string. This array is valid until it is released by
4372 ReleaseStringUTFChars().
4374 *******************************************************************************/
4376 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4381 STATISTICS(jniinvokation());
4389 u = javastring_toutf((java_objectheader *) string, false);
4398 /* ReleaseStringUTFChars *******************************************************
4400 Informs the VM that the native code no longer needs access to
4401 utf. The utf argument is a pointer derived from string using
4402 GetStringUTFChars().
4404 *******************************************************************************/
4406 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4408 STATISTICS(jniinvokation());
4410 /* XXX we don't release utf chars right now, perhaps that should be done
4411 later. Since there is always one reference the garbage collector will
4416 /* Array Operations ***********************************************************/
4418 /* GetArrayLength **************************************************************
4420 Returns the number of elements in the array.
4422 *******************************************************************************/
4424 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4426 java_arrayheader *a;
4428 STATISTICS(jniinvokation());
4430 a = (java_arrayheader *) array;
4436 /* NewObjectArray **************************************************************
4438 Constructs a new array holding objects in class elementClass. All
4439 elements are initially set to initialElement.
4441 *******************************************************************************/
4443 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4444 jclass elementClass, jobject initialElement)
4446 java_objectarray *oa;
4449 STATISTICS(jniinvokation());
4452 exceptions_throw_negativearraysizeexception();
4456 oa = builtin_anewarray(length, elementClass);
4461 /* set all elements to initialElement */
4463 for (i = 0; i < length; i++)
4464 oa->data[i] = initialElement;
4466 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4470 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4473 java_objectarray *oa;
4476 STATISTICS(jniinvokation());
4478 oa = (java_objectarray *) array;
4480 if (index >= oa->header.size) {
4481 exceptions_throw_arrayindexoutofboundsexception();
4485 o = oa->data[index];
4487 return _Jv_JNI_NewLocalRef(env, o);
4491 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4492 jsize index, jobject val)
4494 java_objectarray *oa;
4495 java_objectheader *o;
4497 STATISTICS(jniinvokation());
4499 oa = (java_objectarray *) array;
4500 o = (java_objectheader *) val;
4502 if (index >= oa->header.size) {
4503 exceptions_throw_arrayindexoutofboundsexception();
4507 /* check if the class of value is a subclass of the element class
4510 if (!builtin_canstore(oa, o))
4513 oa->data[index] = val;
4517 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4519 java_booleanarray *ba;
4521 STATISTICS(jniinvokation());
4524 exceptions_throw_negativearraysizeexception();
4528 ba = builtin_newarray_boolean(len);
4530 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4534 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4538 STATISTICS(jniinvokation());
4541 exceptions_throw_negativearraysizeexception();
4545 ba = builtin_newarray_byte(len);
4547 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4551 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4555 STATISTICS(jniinvokation());
4558 exceptions_throw_negativearraysizeexception();
4562 ca = builtin_newarray_char(len);
4564 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4568 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4570 java_shortarray *sa;
4572 STATISTICS(jniinvokation());
4575 exceptions_throw_negativearraysizeexception();
4579 sa = builtin_newarray_short(len);
4581 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4585 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4589 STATISTICS(jniinvokation());
4592 exceptions_throw_negativearraysizeexception();
4596 ia = builtin_newarray_int(len);
4598 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4602 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4606 STATISTICS(jniinvokation());
4609 exceptions_throw_negativearraysizeexception();
4613 la = builtin_newarray_long(len);
4615 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4619 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4621 java_floatarray *fa;
4623 STATISTICS(jniinvokation());
4626 exceptions_throw_negativearraysizeexception();
4630 fa = builtin_newarray_float(len);
4632 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4636 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4638 java_doublearray *da;
4640 STATISTICS(jniinvokation());
4643 exceptions_throw_negativearraysizeexception();
4647 da = builtin_newarray_double(len);
4649 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4653 /* Get<PrimitiveType>ArrayElements *********************************************
4655 A family of functions that returns the body of the primitive array.
4657 *******************************************************************************/
4659 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4662 java_booleanarray *ba;
4664 STATISTICS(jniinvokation());
4666 ba = (java_booleanarray *) array;
4669 *isCopy = JNI_FALSE;
4675 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4680 STATISTICS(jniinvokation());
4682 ba = (java_bytearray *) array;
4685 *isCopy = JNI_FALSE;
4691 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4696 STATISTICS(jniinvokation());
4698 ca = (java_chararray *) array;
4701 *isCopy = JNI_FALSE;
4707 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4710 java_shortarray *sa;
4712 STATISTICS(jniinvokation());
4714 sa = (java_shortarray *) array;
4717 *isCopy = JNI_FALSE;
4723 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4728 STATISTICS(jniinvokation());
4730 ia = (java_intarray *) array;
4733 *isCopy = JNI_FALSE;
4739 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4744 STATISTICS(jniinvokation());
4746 la = (java_longarray *) array;
4749 *isCopy = JNI_FALSE;
4751 /* We cast this one to prevent a compiler warning on 64-bit
4752 systems since GNU Classpath typedef jlong to long long. */
4754 return (jlong *) la->data;
4758 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4761 java_floatarray *fa;
4763 STATISTICS(jniinvokation());
4765 fa = (java_floatarray *) array;
4768 *isCopy = JNI_FALSE;
4774 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4777 java_doublearray *da;
4779 STATISTICS(jniinvokation());
4781 da = (java_doublearray *) array;
4784 *isCopy = JNI_FALSE;
4790 /* Release<PrimitiveType>ArrayElements *****************************************
4792 A family of functions that informs the VM that the native code no
4793 longer needs access to elems. The elems argument is a pointer
4794 derived from array using the corresponding
4795 Get<PrimitiveType>ArrayElements() function. If necessary, this
4796 function copies back all changes made to elems to the original
4799 *******************************************************************************/
4801 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4802 jboolean *elems, jint mode)
4804 java_booleanarray *ba;
4806 STATISTICS(jniinvokation());
4808 ba = (java_booleanarray *) array;
4810 if (elems != ba->data) {
4813 MCOPY(ba->data, elems, u1, ba->header.size);
4816 MCOPY(ba->data, elems, u1, ba->header.size);
4817 /* XXX TWISTI how should it be freed? */
4820 /* XXX TWISTI how should it be freed? */
4827 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4828 jbyte *elems, jint mode)
4832 STATISTICS(jniinvokation());
4834 ba = (java_bytearray *) array;
4836 if (elems != ba->data) {
4839 MCOPY(ba->data, elems, s1, ba->header.size);
4842 MCOPY(ba->data, elems, s1, ba->header.size);
4843 /* XXX TWISTI how should it be freed? */
4846 /* XXX TWISTI how should it be freed? */
4853 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4854 jchar *elems, jint mode)
4858 STATISTICS(jniinvokation());
4860 ca = (java_chararray *) array;
4862 if (elems != ca->data) {
4865 MCOPY(ca->data, elems, u2, ca->header.size);
4868 MCOPY(ca->data, elems, u2, ca->header.size);
4869 /* XXX TWISTI how should it be freed? */
4872 /* XXX TWISTI how should it be freed? */
4879 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4880 jshort *elems, jint mode)
4882 java_shortarray *sa;
4884 STATISTICS(jniinvokation());
4886 sa = (java_shortarray *) array;
4888 if (elems != sa->data) {
4891 MCOPY(sa->data, elems, s2, sa->header.size);
4894 MCOPY(sa->data, elems, s2, sa->header.size);
4895 /* XXX TWISTI how should it be freed? */
4898 /* XXX TWISTI how should it be freed? */
4905 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4910 STATISTICS(jniinvokation());
4912 ia = (java_intarray *) array;
4914 if (elems != ia->data) {
4917 MCOPY(ia->data, elems, s4, ia->header.size);
4920 MCOPY(ia->data, elems, s4, ia->header.size);
4921 /* XXX TWISTI how should it be freed? */
4924 /* XXX TWISTI how should it be freed? */
4931 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4932 jlong *elems, jint mode)
4936 STATISTICS(jniinvokation());
4938 la = (java_longarray *) array;
4940 /* We cast this one to prevent a compiler warning on 64-bit
4941 systems since GNU Classpath typedef jlong to long long. */
4943 if ((s8 *) elems != la->data) {
4946 MCOPY(la->data, elems, s8, la->header.size);
4949 MCOPY(la->data, elems, s8, la->header.size);
4950 /* XXX TWISTI how should it be freed? */
4953 /* XXX TWISTI how should it be freed? */
4960 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4961 jfloat *elems, jint mode)
4963 java_floatarray *fa;
4965 STATISTICS(jniinvokation());
4967 fa = (java_floatarray *) array;
4969 if (elems != fa->data) {
4972 MCOPY(fa->data, elems, float, fa->header.size);
4975 MCOPY(fa->data, elems, float, fa->header.size);
4976 /* XXX TWISTI how should it be freed? */
4979 /* XXX TWISTI how should it be freed? */
4986 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4987 jdouble *elems, jint mode)
4989 java_doublearray *da;
4991 STATISTICS(jniinvokation());
4993 da = (java_doublearray *) array;
4995 if (elems != da->data) {
4998 MCOPY(da->data, elems, double, da->header.size);
5001 MCOPY(da->data, elems, double, da->header.size);
5002 /* XXX TWISTI how should it be freed? */
5005 /* XXX TWISTI how should it be freed? */
5012 /* Get<PrimitiveType>ArrayRegion **********************************************
5014 A family of functions that copies a region of a primitive array
5017 *******************************************************************************/
5019 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5020 jsize start, jsize len, jboolean *buf)
5022 java_booleanarray *ba;
5024 STATISTICS(jniinvokation());
5026 ba = (java_booleanarray *) array;
5028 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5029 exceptions_throw_arrayindexoutofboundsexception();
5031 MCOPY(buf, &ba->data[start], u1, len);
5035 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5036 jsize len, jbyte *buf)
5040 STATISTICS(jniinvokation());
5042 ba = (java_bytearray *) array;
5044 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5045 exceptions_throw_arrayindexoutofboundsexception();
5047 MCOPY(buf, &ba->data[start], s1, len);
5051 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5052 jsize len, jchar *buf)
5056 STATISTICS(jniinvokation());
5058 ca = (java_chararray *) array;
5060 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5061 exceptions_throw_arrayindexoutofboundsexception();
5063 MCOPY(buf, &ca->data[start], u2, len);
5067 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5068 jsize len, jshort *buf)
5070 java_shortarray *sa;
5072 STATISTICS(jniinvokation());
5074 sa = (java_shortarray *) array;
5076 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5077 exceptions_throw_arrayindexoutofboundsexception();
5079 MCOPY(buf, &sa->data[start], s2, len);
5083 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5084 jsize len, jint *buf)
5088 STATISTICS(jniinvokation());
5090 ia = (java_intarray *) array;
5092 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5093 exceptions_throw_arrayindexoutofboundsexception();
5095 MCOPY(buf, &ia->data[start], s4, len);
5099 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5100 jsize len, jlong *buf)
5104 STATISTICS(jniinvokation());
5106 la = (java_longarray *) array;
5108 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5109 exceptions_throw_arrayindexoutofboundsexception();
5111 MCOPY(buf, &la->data[start], s8, len);
5115 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5116 jsize len, jfloat *buf)
5118 java_floatarray *fa;
5120 STATISTICS(jniinvokation());
5122 fa = (java_floatarray *) array;
5124 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5125 exceptions_throw_arrayindexoutofboundsexception();
5127 MCOPY(buf, &fa->data[start], float, len);
5131 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5132 jsize len, jdouble *buf)
5134 java_doublearray *da;
5136 STATISTICS(jniinvokation());
5138 da = (java_doublearray *) array;
5140 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5141 exceptions_throw_arrayindexoutofboundsexception();
5143 MCOPY(buf, &da->data[start], double, len);
5147 /* Set<PrimitiveType>ArrayRegion **********************************************
5149 A family of functions that copies back a region of a primitive
5150 array from a buffer.
5152 *******************************************************************************/
5154 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5155 jsize start, jsize len, jboolean *buf)
5157 java_booleanarray *ba;
5159 STATISTICS(jniinvokation());
5161 ba = (java_booleanarray *) array;
5163 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5164 exceptions_throw_arrayindexoutofboundsexception();
5166 MCOPY(&ba->data[start], buf, u1, len);
5170 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5171 jsize len, jbyte *buf)
5175 STATISTICS(jniinvokation());
5177 ba = (java_bytearray *) array;
5179 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5180 exceptions_throw_arrayindexoutofboundsexception();
5182 MCOPY(&ba->data[start], buf, s1, len);
5186 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5187 jsize len, jchar *buf)
5191 STATISTICS(jniinvokation());
5193 ca = (java_chararray *) array;
5195 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5196 exceptions_throw_arrayindexoutofboundsexception();
5198 MCOPY(&ca->data[start], buf, u2, len);
5202 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5203 jsize len, jshort *buf)
5205 java_shortarray *sa;
5207 STATISTICS(jniinvokation());
5209 sa = (java_shortarray *) array;
5211 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5212 exceptions_throw_arrayindexoutofboundsexception();
5214 MCOPY(&sa->data[start], buf, s2, len);
5218 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5219 jsize len, jint *buf)
5223 STATISTICS(jniinvokation());
5225 ia = (java_intarray *) array;
5227 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5228 exceptions_throw_arrayindexoutofboundsexception();
5230 MCOPY(&ia->data[start], buf, s4, len);
5234 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5235 jsize len, jlong *buf)
5239 STATISTICS(jniinvokation());
5241 la = (java_longarray *) array;
5243 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5244 exceptions_throw_arrayindexoutofboundsexception();
5246 MCOPY(&la->data[start], buf, s8, len);
5250 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5251 jsize len, jfloat *buf)
5253 java_floatarray *fa;
5255 STATISTICS(jniinvokation());
5257 fa = (java_floatarray *) array;
5259 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5260 exceptions_throw_arrayindexoutofboundsexception();
5262 MCOPY(&fa->data[start], buf, float, len);
5266 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5267 jsize len, jdouble *buf)
5269 java_doublearray *da;
5271 STATISTICS(jniinvokation());
5273 da = (java_doublearray *) array;
5275 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5276 exceptions_throw_arrayindexoutofboundsexception();
5278 MCOPY(&da->data[start], buf, double, len);
5282 /* Registering Native Methods *************************************************/
5284 /* RegisterNatives *************************************************************
5286 Registers native methods with the class specified by the clazz
5287 argument. The methods parameter specifies an array of
5288 JNINativeMethod structures that contain the names, signatures, and
5289 function pointers of the native methods. The nMethods parameter
5290 specifies the number of native methods in the array.
5292 *******************************************************************************/
5294 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5295 const JNINativeMethod *methods, jint nMethods)
5297 STATISTICS(jniinvokation());
5299 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5300 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5301 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5308 /* UnregisterNatives ***********************************************************
5310 Unregisters native methods of a class. The class goes back to the
5311 state before it was linked or registered with its native method
5314 This function should not be used in normal native code. Instead, it
5315 provides special programs a way to reload and relink native
5318 *******************************************************************************/
5320 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5322 STATISTICS(jniinvokation());
5324 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5326 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5332 /* Monitor Operations *********************************************************/
5334 /* MonitorEnter ****************************************************************
5336 Enters the monitor associated with the underlying Java object
5339 *******************************************************************************/
5341 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5343 STATISTICS(jniinvokation());
5346 exceptions_throw_nullpointerexception();
5350 LOCK_MONITOR_ENTER(obj);
5356 /* MonitorExit *****************************************************************
5358 The current thread must be the owner of the monitor associated with
5359 the underlying Java object referred to by obj. The thread
5360 decrements the counter indicating the number of times it has
5361 entered this monitor. If the value of the counter becomes zero, the
5362 current thread releases the monitor.
5364 *******************************************************************************/
5366 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5368 STATISTICS(jniinvokation());
5371 exceptions_throw_nullpointerexception();
5375 LOCK_MONITOR_EXIT(obj);
5381 /* JavaVM Interface ***********************************************************/
5383 /* GetJavaVM *******************************************************************
5385 Returns the Java VM interface (used in the Invocation API)
5386 associated with the current thread. The result is placed at the
5387 location pointed to by the second argument, vm.
5389 *******************************************************************************/
5391 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5393 STATISTICS(jniinvokation());
5395 *vm = (JavaVM *) _Jv_jvm;
5401 /* GetStringRegion *************************************************************
5403 Copies len number of Unicode characters beginning at offset start
5404 to the given buffer buf.
5406 Throws StringIndexOutOfBoundsException on index overflow.
5408 *******************************************************************************/
5410 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5413 java_lang_String *s;
5416 STATISTICS(jniinvokation());
5418 s = (java_lang_String *) str;
5421 if ((start < 0) || (len < 0) || (start > s->count) ||
5422 (start + len > s->count)) {
5423 exceptions_throw_stringindexoutofboundsexception();
5427 MCOPY(buf, &ca->data[start], u2, len);
5431 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5432 jsize len, char *buf)
5434 STATISTICS(jniinvokation());
5436 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5440 /* GetPrimitiveArrayCritical ***************************************************
5442 Obtain a direct pointer to array elements.
5444 *******************************************************************************/
5446 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5452 ba = (java_bytearray *) array;
5454 /* do the same as Kaffe does */
5456 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5462 /* ReleasePrimitiveArrayCritical ***********************************************
5464 No specific documentation.
5466 *******************************************************************************/
5468 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5469 void *carray, jint mode)
5471 STATISTICS(jniinvokation());
5473 /* do the same as Kaffe does */
5475 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5480 /* GetStringCritical ***********************************************************
5482 The semantics of these two functions are similar to the existing
5483 Get/ReleaseStringChars functions.
5485 *******************************************************************************/
5487 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5490 STATISTICS(jniinvokation());
5492 return _Jv_JNI_GetStringChars(env, string, isCopy);
5496 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5497 const jchar *cstring)
5499 STATISTICS(jniinvokation());
5501 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5505 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5507 STATISTICS(jniinvokation());
5509 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5515 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5517 STATISTICS(jniinvokation());
5519 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5523 /* NewGlobalRef ****************************************************************
5525 Creates a new global reference to the object referred to by the obj
5528 *******************************************************************************/
5530 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5532 hashtable_global_ref_entry *gre;
5533 u4 key; /* hashkey */
5534 u4 slot; /* slot in hashtable */
5536 STATISTICS(jniinvokation());
5538 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5540 /* normally addresses are aligned to 4, 8 or 16 bytes */
5542 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5543 slot = key & (hashtable_global_ref->size - 1);
5544 gre = hashtable_global_ref->ptr[slot];
5546 /* search external hash chain for the entry */
5549 if (gre->o == obj) {
5550 /* global object found, increment the reference */
5554 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5559 gre = gre->hashlink; /* next element in external chain */
5562 /* global ref not found, create a new one */
5564 gre = NEW(hashtable_global_ref_entry);
5566 #if defined(ENABLE_GC_CACAO)
5567 /* register global ref with the GC */
5569 gc_reference_register(&(gre->o));
5575 /* insert entry into hashtable */
5577 gre->hashlink = hashtable_global_ref->ptr[slot];
5579 hashtable_global_ref->ptr[slot] = gre;
5581 /* update number of hashtable-entries */
5583 hashtable_global_ref->entries++;
5585 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5591 /* DeleteGlobalRef *************************************************************
5593 Deletes the global reference pointed to by globalRef.
5595 *******************************************************************************/
5597 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5599 hashtable_global_ref_entry *gre;
5600 hashtable_global_ref_entry *prevgre;
5601 u4 key; /* hashkey */
5602 u4 slot; /* slot in hashtable */
5604 STATISTICS(jniinvokation());
5606 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5608 /* normally addresses are aligned to 4, 8 or 16 bytes */
5610 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5611 slot = key & (hashtable_global_ref->size - 1);
5612 gre = hashtable_global_ref->ptr[slot];
5614 /* initialize prevgre */
5618 /* search external hash chain for the entry */
5621 if (gre->o == globalRef) {
5622 /* global object found, decrement the reference count */
5626 /* if reference count is 0, remove the entry */
5628 if (gre->refs == 0) {
5629 /* special handling if it's the first in the chain */
5631 if (prevgre == NULL)
5632 hashtable_global_ref->ptr[slot] = gre->hashlink;
5634 prevgre->hashlink = gre->hashlink;
5636 #if defined(ENABLE_GC_CACAO)
5637 /* unregister global ref with the GC */
5639 gc_reference_unregister(&(gre->o));
5642 FREE(gre, hashtable_global_ref_entry);
5645 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5650 prevgre = gre; /* save current pointer for removal */
5651 gre = gre->hashlink; /* next element in external chain */
5654 log_println("JNI-DeleteGlobalRef: global reference not found");
5656 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5660 /* ExceptionCheck **************************************************************
5662 Returns JNI_TRUE when there is a pending exception; otherwise,
5665 *******************************************************************************/
5667 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5669 java_objectheader *o;
5671 STATISTICS(jniinvokation());
5673 o = exceptions_get_exception();
5675 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5679 /* New JNI 1.4 functions ******************************************************/
5681 /* NewDirectByteBuffer *********************************************************
5683 Allocates and returns a direct java.nio.ByteBuffer referring to the
5684 block of memory starting at the memory address address and
5685 extending capacity bytes.
5687 *******************************************************************************/
5689 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5691 #if defined(ENABLE_JAVASE)
5692 java_objectheader *nbuf;
5693 # if SIZEOF_VOID_P == 8
5694 gnu_classpath_Pointer64 *paddress;
5696 gnu_classpath_Pointer32 *paddress;
5699 STATISTICS(jniinvokation());
5701 /* alocate a gnu.classpath.Pointer{32,64} object */
5703 # if SIZEOF_VOID_P == 8
5704 if (!(paddress = (gnu_classpath_Pointer64 *)
5705 builtin_new(class_gnu_classpath_Pointer64)))
5707 if (!(paddress = (gnu_classpath_Pointer32 *)
5708 builtin_new(class_gnu_classpath_Pointer32)))
5712 /* fill gnu.classpath.Pointer{32,64} with address */
5714 paddress->data = (ptrint) address;
5716 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5718 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5719 (jmethodID) dbbirw_init, NULL, paddress,
5720 (jint) capacity, (jint) capacity, (jint) 0);
5722 /* add local reference and return the value */
5724 return _Jv_JNI_NewLocalRef(env, nbuf);
5726 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5728 /* keep compiler happy */
5735 /* GetDirectBufferAddress ******************************************************
5737 Fetches and returns the starting address of the memory region
5738 referenced by the given direct java.nio.Buffer.
5740 *******************************************************************************/
5742 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5744 #if defined(ENABLE_JAVASE)
5745 java_nio_DirectByteBufferImpl *nbuf;
5746 # if SIZEOF_VOID_P == 8
5747 gnu_classpath_Pointer64 *address;
5749 gnu_classpath_Pointer32 *address;
5752 STATISTICS(jniinvokation());
5754 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5757 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5759 # if SIZEOF_VOID_P == 8
5760 address = (gnu_classpath_Pointer64 *) nbuf->address;
5762 address = (gnu_classpath_Pointer32 *) nbuf->address;
5765 if (address == NULL)
5768 return (void *) address->data;
5770 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5772 /* keep compiler happy */
5779 /* GetDirectBufferCapacity *****************************************************
5781 Fetches and returns the capacity in bytes of the memory region
5782 referenced by the given direct java.nio.Buffer.
5784 *******************************************************************************/
5786 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5788 #if defined(ENABLE_JAVASE)
5789 java_nio_Buffer *nbuf;
5791 STATISTICS(jniinvokation());
5793 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5796 nbuf = (java_nio_Buffer *) buf;
5798 return (jlong) nbuf->cap;
5800 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5802 /* keep compiler happy */
5809 /* DestroyJavaVM ***************************************************************
5811 Unloads a Java VM and reclaims its resources. Only the main thread
5812 can unload the VM. The system waits until the main thread is only
5813 remaining user thread before it destroys the VM.
5815 *******************************************************************************/
5817 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5821 STATISTICS(jniinvokation());
5823 status = vm_destroy(vm);
5829 /* AttachCurrentThread *********************************************************
5831 Attaches the current thread to a Java VM. Returns a JNI interface
5832 pointer in the JNIEnv argument.
5834 Trying to attach a thread that is already attached is a no-op.
5836 A native thread cannot be attached simultaneously to two Java VMs.
5838 When a thread is attached to the VM, the context class loader is
5839 the bootstrap loader.
5841 *******************************************************************************/
5843 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5845 JavaVMAttachArgs *vm_aargs;
5847 #if defined(ENABLE_THREADS)
5848 if (threads_get_current_threadobject() == NULL) {
5849 vm_aargs = (JavaVMAttachArgs *) thr_args;
5851 if (vm_aargs != NULL) {
5852 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5853 (vm_aargs->version != JNI_VERSION_1_4))
5854 return JNI_EVERSION;
5857 if (!threads_attach_current_thread(vm_aargs, false))
5860 if (!jni_init_localref_table())
5871 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5873 STATISTICS(jniinvokation());
5875 return jni_attach_current_thread(p_env, thr_args, false);
5879 /* DetachCurrentThread *********************************************************
5881 Detaches the current thread from a Java VM. All Java monitors held
5882 by this thread are released. All Java threads waiting for this
5883 thread to die are notified.
5885 In JDK 1.1, the main thread cannot be detached from the VM. It must
5886 call DestroyJavaVM to unload the entire VM.
5888 In the JDK, the main thread can be detached from the VM.
5890 The main thread, which is the thread that created the Java VM,
5891 cannot be detached from the VM. Instead, the main thread must call
5892 JNI_DestroyJavaVM() to unload the entire VM.
5894 *******************************************************************************/
5896 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5898 #if defined(ENABLE_THREADS)
5899 threadobject *thread;
5901 STATISTICS(jniinvokation());
5903 thread = threads_get_current_threadobject();
5908 if (!jni_free_localref_table())
5911 if (!threads_detach_thread(thread))
5919 /* GetEnv **********************************************************************
5921 If the current thread is not attached to the VM, sets *env to NULL,
5922 and returns JNI_EDETACHED. If the specified version is not
5923 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5924 sets *env to the appropriate interface, and returns JNI_OK.
5926 *******************************************************************************/
5928 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5930 STATISTICS(jniinvokation());
5932 #if defined(ENABLE_THREADS)
5933 if (threads_get_current_threadobject() == NULL) {
5936 return JNI_EDETACHED;
5940 /* check the JNI version */
5943 case JNI_VERSION_1_1:
5944 case JNI_VERSION_1_2:
5945 case JNI_VERSION_1_4:
5953 #if defined(ENABLE_JVMTI)
5954 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5955 == JVMTI_VERSION_INTERFACE_JVMTI) {
5957 *env = (void *) jvmti_new_environment();
5966 return JNI_EVERSION;
5970 /* AttachCurrentThreadAsDaemon *************************************************
5972 Same semantics as AttachCurrentThread, but the newly-created
5973 java.lang.Thread instance is a daemon.
5975 If the thread has already been attached via either
5976 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5977 simply sets the value pointed to by penv to the JNIEnv of the
5978 current thread. In this case neither AttachCurrentThread nor this
5979 routine have any effect on the daemon status of the thread.
5981 *******************************************************************************/
5983 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5985 STATISTICS(jniinvokation());
5987 return jni_attach_current_thread(penv, args, true);
5991 /* JNI invocation table *******************************************************/
5993 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5998 _Jv_JNI_DestroyJavaVM,
5999 _Jv_JNI_AttachCurrentThread,
6000 _Jv_JNI_DetachCurrentThread,
6002 _Jv_JNI_AttachCurrentThreadAsDaemon
6006 /* JNI function table *********************************************************/
6008 struct JNINativeInterface _Jv_JNINativeInterface = {
6015 _Jv_JNI_DefineClass,
6017 _Jv_JNI_FromReflectedMethod,
6018 _Jv_JNI_FromReflectedField,
6019 _Jv_JNI_ToReflectedMethod,
6020 _Jv_JNI_GetSuperclass,
6021 _Jv_JNI_IsAssignableFrom,
6022 _Jv_JNI_ToReflectedField,
6026 _Jv_JNI_ExceptionOccurred,
6027 _Jv_JNI_ExceptionDescribe,
6028 _Jv_JNI_ExceptionClear,
6030 _Jv_JNI_PushLocalFrame,
6031 _Jv_JNI_PopLocalFrame,
6033 _Jv_JNI_NewGlobalRef,
6034 _Jv_JNI_DeleteGlobalRef,
6035 _Jv_JNI_DeleteLocalRef,
6036 _Jv_JNI_IsSameObject,
6037 _Jv_JNI_NewLocalRef,
6038 _Jv_JNI_EnsureLocalCapacity,
6040 _Jv_JNI_AllocObject,
6045 _Jv_JNI_GetObjectClass,
6046 _Jv_JNI_IsInstanceOf,
6048 _Jv_JNI_GetMethodID,
6050 _Jv_JNI_CallObjectMethod,
6051 _Jv_JNI_CallObjectMethodV,
6052 _Jv_JNI_CallObjectMethodA,
6053 _Jv_JNI_CallBooleanMethod,
6054 _Jv_JNI_CallBooleanMethodV,
6055 _Jv_JNI_CallBooleanMethodA,
6056 _Jv_JNI_CallByteMethod,
6057 _Jv_JNI_CallByteMethodV,
6058 _Jv_JNI_CallByteMethodA,
6059 _Jv_JNI_CallCharMethod,
6060 _Jv_JNI_CallCharMethodV,
6061 _Jv_JNI_CallCharMethodA,
6062 _Jv_JNI_CallShortMethod,
6063 _Jv_JNI_CallShortMethodV,
6064 _Jv_JNI_CallShortMethodA,
6065 _Jv_JNI_CallIntMethod,
6066 _Jv_JNI_CallIntMethodV,
6067 _Jv_JNI_CallIntMethodA,
6068 _Jv_JNI_CallLongMethod,
6069 _Jv_JNI_CallLongMethodV,
6070 _Jv_JNI_CallLongMethodA,
6071 _Jv_JNI_CallFloatMethod,
6072 _Jv_JNI_CallFloatMethodV,
6073 _Jv_JNI_CallFloatMethodA,
6074 _Jv_JNI_CallDoubleMethod,
6075 _Jv_JNI_CallDoubleMethodV,
6076 _Jv_JNI_CallDoubleMethodA,
6077 _Jv_JNI_CallVoidMethod,
6078 _Jv_JNI_CallVoidMethodV,
6079 _Jv_JNI_CallVoidMethodA,
6081 _Jv_JNI_CallNonvirtualObjectMethod,
6082 _Jv_JNI_CallNonvirtualObjectMethodV,
6083 _Jv_JNI_CallNonvirtualObjectMethodA,
6084 _Jv_JNI_CallNonvirtualBooleanMethod,
6085 _Jv_JNI_CallNonvirtualBooleanMethodV,
6086 _Jv_JNI_CallNonvirtualBooleanMethodA,
6087 _Jv_JNI_CallNonvirtualByteMethod,
6088 _Jv_JNI_CallNonvirtualByteMethodV,
6089 _Jv_JNI_CallNonvirtualByteMethodA,
6090 _Jv_JNI_CallNonvirtualCharMethod,
6091 _Jv_JNI_CallNonvirtualCharMethodV,
6092 _Jv_JNI_CallNonvirtualCharMethodA,
6093 _Jv_JNI_CallNonvirtualShortMethod,
6094 _Jv_JNI_CallNonvirtualShortMethodV,
6095 _Jv_JNI_CallNonvirtualShortMethodA,
6096 _Jv_JNI_CallNonvirtualIntMethod,
6097 _Jv_JNI_CallNonvirtualIntMethodV,
6098 _Jv_JNI_CallNonvirtualIntMethodA,
6099 _Jv_JNI_CallNonvirtualLongMethod,
6100 _Jv_JNI_CallNonvirtualLongMethodV,
6101 _Jv_JNI_CallNonvirtualLongMethodA,
6102 _Jv_JNI_CallNonvirtualFloatMethod,
6103 _Jv_JNI_CallNonvirtualFloatMethodV,
6104 _Jv_JNI_CallNonvirtualFloatMethodA,
6105 _Jv_JNI_CallNonvirtualDoubleMethod,
6106 _Jv_JNI_CallNonvirtualDoubleMethodV,
6107 _Jv_JNI_CallNonvirtualDoubleMethodA,
6108 _Jv_JNI_CallNonvirtualVoidMethod,
6109 _Jv_JNI_CallNonvirtualVoidMethodV,
6110 _Jv_JNI_CallNonvirtualVoidMethodA,
6114 _Jv_JNI_GetObjectField,
6115 _Jv_JNI_GetBooleanField,
6116 _Jv_JNI_GetByteField,
6117 _Jv_JNI_GetCharField,
6118 _Jv_JNI_GetShortField,
6119 _Jv_JNI_GetIntField,
6120 _Jv_JNI_GetLongField,
6121 _Jv_JNI_GetFloatField,
6122 _Jv_JNI_GetDoubleField,
6123 _Jv_JNI_SetObjectField,
6124 _Jv_JNI_SetBooleanField,
6125 _Jv_JNI_SetByteField,
6126 _Jv_JNI_SetCharField,
6127 _Jv_JNI_SetShortField,
6128 _Jv_JNI_SetIntField,
6129 _Jv_JNI_SetLongField,
6130 _Jv_JNI_SetFloatField,
6131 _Jv_JNI_SetDoubleField,
6133 _Jv_JNI_GetStaticMethodID,
6135 _Jv_JNI_CallStaticObjectMethod,
6136 _Jv_JNI_CallStaticObjectMethodV,
6137 _Jv_JNI_CallStaticObjectMethodA,
6138 _Jv_JNI_CallStaticBooleanMethod,
6139 _Jv_JNI_CallStaticBooleanMethodV,
6140 _Jv_JNI_CallStaticBooleanMethodA,
6141 _Jv_JNI_CallStaticByteMethod,
6142 _Jv_JNI_CallStaticByteMethodV,
6143 _Jv_JNI_CallStaticByteMethodA,
6144 _Jv_JNI_CallStaticCharMethod,
6145 _Jv_JNI_CallStaticCharMethodV,
6146 _Jv_JNI_CallStaticCharMethodA,
6147 _Jv_JNI_CallStaticShortMethod,
6148 _Jv_JNI_CallStaticShortMethodV,
6149 _Jv_JNI_CallStaticShortMethodA,
6150 _Jv_JNI_CallStaticIntMethod,
6151 _Jv_JNI_CallStaticIntMethodV,
6152 _Jv_JNI_CallStaticIntMethodA,
6153 _Jv_JNI_CallStaticLongMethod,
6154 _Jv_JNI_CallStaticLongMethodV,
6155 _Jv_JNI_CallStaticLongMethodA,
6156 _Jv_JNI_CallStaticFloatMethod,
6157 _Jv_JNI_CallStaticFloatMethodV,
6158 _Jv_JNI_CallStaticFloatMethodA,
6159 _Jv_JNI_CallStaticDoubleMethod,
6160 _Jv_JNI_CallStaticDoubleMethodV,
6161 _Jv_JNI_CallStaticDoubleMethodA,
6162 _Jv_JNI_CallStaticVoidMethod,
6163 _Jv_JNI_CallStaticVoidMethodV,
6164 _Jv_JNI_CallStaticVoidMethodA,
6166 _Jv_JNI_GetStaticFieldID,
6168 _Jv_JNI_GetStaticObjectField,
6169 _Jv_JNI_GetStaticBooleanField,
6170 _Jv_JNI_GetStaticByteField,
6171 _Jv_JNI_GetStaticCharField,
6172 _Jv_JNI_GetStaticShortField,
6173 _Jv_JNI_GetStaticIntField,
6174 _Jv_JNI_GetStaticLongField,
6175 _Jv_JNI_GetStaticFloatField,
6176 _Jv_JNI_GetStaticDoubleField,
6177 _Jv_JNI_SetStaticObjectField,
6178 _Jv_JNI_SetStaticBooleanField,
6179 _Jv_JNI_SetStaticByteField,
6180 _Jv_JNI_SetStaticCharField,
6181 _Jv_JNI_SetStaticShortField,
6182 _Jv_JNI_SetStaticIntField,
6183 _Jv_JNI_SetStaticLongField,
6184 _Jv_JNI_SetStaticFloatField,
6185 _Jv_JNI_SetStaticDoubleField,
6188 _Jv_JNI_GetStringLength,
6189 _Jv_JNI_GetStringChars,
6190 _Jv_JNI_ReleaseStringChars,
6192 _Jv_JNI_NewStringUTF,
6193 _Jv_JNI_GetStringUTFLength,
6194 _Jv_JNI_GetStringUTFChars,
6195 _Jv_JNI_ReleaseStringUTFChars,
6197 _Jv_JNI_GetArrayLength,
6199 _Jv_JNI_NewObjectArray,
6200 _Jv_JNI_GetObjectArrayElement,
6201 _Jv_JNI_SetObjectArrayElement,
6203 _Jv_JNI_NewBooleanArray,
6204 _Jv_JNI_NewByteArray,
6205 _Jv_JNI_NewCharArray,
6206 _Jv_JNI_NewShortArray,
6207 _Jv_JNI_NewIntArray,
6208 _Jv_JNI_NewLongArray,
6209 _Jv_JNI_NewFloatArray,
6210 _Jv_JNI_NewDoubleArray,
6212 _Jv_JNI_GetBooleanArrayElements,
6213 _Jv_JNI_GetByteArrayElements,
6214 _Jv_JNI_GetCharArrayElements,
6215 _Jv_JNI_GetShortArrayElements,
6216 _Jv_JNI_GetIntArrayElements,
6217 _Jv_JNI_GetLongArrayElements,
6218 _Jv_JNI_GetFloatArrayElements,
6219 _Jv_JNI_GetDoubleArrayElements,
6221 _Jv_JNI_ReleaseBooleanArrayElements,
6222 _Jv_JNI_ReleaseByteArrayElements,
6223 _Jv_JNI_ReleaseCharArrayElements,
6224 _Jv_JNI_ReleaseShortArrayElements,
6225 _Jv_JNI_ReleaseIntArrayElements,
6226 _Jv_JNI_ReleaseLongArrayElements,
6227 _Jv_JNI_ReleaseFloatArrayElements,
6228 _Jv_JNI_ReleaseDoubleArrayElements,
6230 _Jv_JNI_GetBooleanArrayRegion,
6231 _Jv_JNI_GetByteArrayRegion,
6232 _Jv_JNI_GetCharArrayRegion,
6233 _Jv_JNI_GetShortArrayRegion,
6234 _Jv_JNI_GetIntArrayRegion,
6235 _Jv_JNI_GetLongArrayRegion,
6236 _Jv_JNI_GetFloatArrayRegion,
6237 _Jv_JNI_GetDoubleArrayRegion,
6238 _Jv_JNI_SetBooleanArrayRegion,
6239 _Jv_JNI_SetByteArrayRegion,
6240 _Jv_JNI_SetCharArrayRegion,
6241 _Jv_JNI_SetShortArrayRegion,
6242 _Jv_JNI_SetIntArrayRegion,
6243 _Jv_JNI_SetLongArrayRegion,
6244 _Jv_JNI_SetFloatArrayRegion,
6245 _Jv_JNI_SetDoubleArrayRegion,
6247 _Jv_JNI_RegisterNatives,
6248 _Jv_JNI_UnregisterNatives,
6250 _Jv_JNI_MonitorEnter,
6251 _Jv_JNI_MonitorExit,
6255 /* new JNI 1.2 functions */
6257 _Jv_JNI_GetStringRegion,
6258 _Jv_JNI_GetStringUTFRegion,
6260 _Jv_JNI_GetPrimitiveArrayCritical,
6261 _Jv_JNI_ReleasePrimitiveArrayCritical,
6263 _Jv_JNI_GetStringCritical,
6264 _Jv_JNI_ReleaseStringCritical,
6266 _Jv_JNI_NewWeakGlobalRef,
6267 _Jv_JNI_DeleteWeakGlobalRef,
6269 _Jv_JNI_ExceptionCheck,
6271 /* new JNI 1.4 functions */
6273 _Jv_JNI_NewDirectByteBuffer,
6274 _Jv_JNI_GetDirectBufferAddress,
6275 _Jv_JNI_GetDirectBufferCapacity
6279 /* Invocation API Functions ***************************************************/
6281 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6283 Returns a default configuration for the Java VM.
6285 *******************************************************************************/
6287 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6289 JavaVMInitArgs *_vm_args;
6291 _vm_args = (JavaVMInitArgs *) vm_args;
6293 /* GNU classpath currently supports JNI 1.2 */
6295 switch (_vm_args->version) {
6296 case JNI_VERSION_1_1:
6297 _vm_args->version = JNI_VERSION_1_1;
6300 case JNI_VERSION_1_2:
6301 case JNI_VERSION_1_4:
6302 _vm_args->ignoreUnrecognized = JNI_FALSE;
6303 _vm_args->options = NULL;
6304 _vm_args->nOptions = 0;
6315 /* JNI_GetCreatedJavaVMs *******************************************************
6317 Returns all Java VMs that have been created. Pointers to VMs are written in
6318 the buffer vmBuf in the order they are created. At most bufLen number of
6319 entries will be written. The total number of created VMs is returned in
6322 *******************************************************************************/
6324 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6326 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6332 /* JNI_CreateJavaVM ************************************************************
6334 Loads and initializes a Java VM. The current thread becomes the main thread.
6335 Sets the env argument to the JNI interface pointer of the main thread.
6337 *******************************************************************************/
6339 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6341 /* actually create the JVM */
6343 if (!vm_createjvm(p_vm, p_env, vm_args))
6351 * These are local overrides for various environment variables in Emacs.
6352 * Please do not remove this and leave it at the end of the file, where
6353 * Emacs will automagically detect them.
6354 * ---------------------------------------------------------------------
6357 * indent-tabs-mode: t
6361 * vim:noexpandtab:sw=4:ts=4: