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 8106 2007-06-19 22:50:17Z twisti $
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
40 #include "native/jni.h"
41 #include "native/native.h"
43 #if defined(ENABLE_JAVASE)
44 # if defined(WITH_CLASSPATH_GNU)
45 # include "native/include/gnu_classpath_Pointer.h"
47 # if SIZEOF_VOID_P == 8
48 # include "native/include/gnu_classpath_Pointer64.h"
50 # include "native/include/gnu_classpath_Pointer32.h"
55 #include "native/include/java_lang_Object.h"
56 #include "native/include/java_lang_Byte.h"
57 #include "native/include/java_lang_Character.h"
58 #include "native/include/java_lang_Short.h"
59 #include "native/include/java_lang_Integer.h"
60 #include "native/include/java_lang_Boolean.h"
61 #include "native/include/java_lang_Long.h"
62 #include "native/include/java_lang_Float.h"
63 #include "native/include/java_lang_Double.h"
64 #include "native/include/java_lang_String.h"
65 #include "native/include/java_lang_Throwable.h"
67 #if defined(ENABLE_JAVASE)
68 # include "native/include/java_lang_ClassLoader.h"
70 # include "native/include/java_lang_reflect_Constructor.h"
71 # include "native/include/java_lang_reflect_Field.h"
72 # include "native/include/java_lang_reflect_Method.h"
74 # include "native/include/java_nio_Buffer.h"
75 # include "native/include/java_nio_DirectByteBufferImpl.h"
78 #if defined(ENABLE_JVMTI)
79 # include "native/jvmti/cacaodbg.h"
82 #include "native/vm/java_lang_Class.h"
84 #if defined(ENABLE_JAVASE)
85 # include "native/vm/java_lang_ClassLoader.h"
88 #include "threads/lock-common.h"
89 #include "threads/threads-common.h"
91 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/resolve.h"
98 #include "vm/stringlocal.h"
101 #include "vm/jit/asmpart.h"
102 #include "vm/jit/jit.h"
103 #include "vm/jit/stacktrace.h"
105 #include "vmcore/loader.h"
106 #include "vmcore/options.h"
107 #include "vmcore/primitive.h"
108 #include "vmcore/statistics.h"
111 /* global variables ***********************************************************/
113 /* global reference table *****************************************************/
115 /* hashsize must be power of 2 */
117 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
119 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
122 /* direct buffer stuff ********************************************************/
124 #if defined(ENABLE_JAVASE)
125 static classinfo *class_java_nio_Buffer;
126 static classinfo *class_java_nio_DirectByteBufferImpl;
127 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
129 # if defined(WITH_CLASSPATH_GNU)
130 # if SIZEOF_VOID_P == 8
131 static classinfo *class_gnu_classpath_Pointer64;
133 static classinfo *class_gnu_classpath_Pointer32;
137 static methodinfo *dbbirw_init;
141 /* local reference table ******************************************************/
143 #if !defined(ENABLE_THREADS)
144 localref_table *_no_threads_localref_table;
148 /* accessing instance fields macros *******************************************/
150 #define SET_FIELD(o,type,f,value) \
151 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
153 #define GET_FIELD(o,type,f) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
157 /* some forward declarations **************************************************/
159 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
160 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
163 /* jni_init ********************************************************************
165 Initialize the JNI subsystem.
167 *******************************************************************************/
171 /* create global ref hashtable */
173 hashtable_global_ref = NEW(hashtable);
175 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
178 #if defined(ENABLE_JAVASE)
179 /* direct buffer stuff */
181 if (!(class_java_nio_Buffer =
182 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
183 !link_class(class_java_nio_Buffer))
186 if (!(class_java_nio_DirectByteBufferImpl =
187 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
188 !link_class(class_java_nio_DirectByteBufferImpl))
191 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
192 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
193 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
197 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
199 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
202 # if defined(WITH_CLASSPATH_GNU)
203 # if SIZEOF_VOID_P == 8
204 if (!(class_gnu_classpath_Pointer64 =
205 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
206 !link_class(class_gnu_classpath_Pointer64))
209 if (!(class_gnu_classpath_Pointer32 =
210 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
211 !link_class(class_gnu_classpath_Pointer32))
215 #endif /* defined(ENABLE_JAVASE) */
221 /* jni_init_localref_table *****************************************************
223 Initializes the local references table of the current thread.
225 *******************************************************************************/
227 bool jni_init_localref_table(void)
231 lrt = GCNEW(localref_table);
236 lrt->capacity = LOCALREFTABLE_CAPACITY;
238 lrt->localframes = 1;
239 lrt->prev = LOCALREFTABLE;
241 /* clear the references array (memset is faster then a for-loop) */
243 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
251 /* _Jv_jni_CallObjectMethod ****************************************************
253 Internal function to call Java Object methods.
255 *******************************************************************************/
257 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
259 methodinfo *m, va_list ap)
262 java_objectheader *ro;
264 STATISTICS(jniinvokation());
267 exceptions_throw_nullpointerexception();
271 /* Class initialization is done by the JIT compiler. This is ok
272 since a static method always belongs to the declaring class. */
274 if (m->flags & ACC_STATIC) {
275 /* For static methods we reset the object. */
280 /* for convenience */
285 /* For instance methods we make a virtual function table lookup. */
287 resm = method_vftbl_lookup(vftbl, m);
290 STATISTICS(jnicallXmethodnvokation());
292 ro = vm_call_method_valist(resm, o, ap);
298 /* _Jv_jni_CallObjectMethodA ***************************************************
300 Internal function to call Java Object methods.
302 *******************************************************************************/
304 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
306 methodinfo *m, jvalue *args)
309 java_objectheader *ro;
311 STATISTICS(jniinvokation());
314 exceptions_throw_nullpointerexception();
318 /* Class initialization is done by the JIT compiler. This is ok
319 since a static method always belongs to the declaring class. */
321 if (m->flags & ACC_STATIC) {
322 /* For static methods we reset the object. */
327 /* for convenience */
332 /* For instance methods we make a virtual function table lookup. */
334 resm = method_vftbl_lookup(vftbl, m);
337 STATISTICS(jnicallXmethodnvokation());
339 ro = vm_call_method_jvalue(resm, o, args);
345 /* _Jv_jni_CallIntMethod *******************************************************
347 Internal function to call Java integer class methods (boolean,
348 byte, char, short, int).
350 *******************************************************************************/
352 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
353 methodinfo *m, va_list ap)
358 STATISTICS(jniinvokation());
361 exceptions_throw_nullpointerexception();
365 /* Class initialization is done by the JIT compiler. This is ok
366 since a static method always belongs to the declaring class. */
368 if (m->flags & ACC_STATIC) {
369 /* For static methods we reset the object. */
374 /* for convenience */
379 /* For instance methods we make a virtual function table lookup. */
381 resm = method_vftbl_lookup(vftbl, m);
384 STATISTICS(jnicallXmethodnvokation());
386 i = vm_call_method_int_valist(resm, o, ap);
392 /* _Jv_jni_CallIntMethodA ******************************************************
394 Internal function to call Java integer class methods (boolean,
395 byte, char, short, int).
397 *******************************************************************************/
399 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
400 methodinfo *m, jvalue *args)
405 STATISTICS(jniinvokation());
408 exceptions_throw_nullpointerexception();
412 /* Class initialization is done by the JIT compiler. This is ok
413 since a static method always belongs to the declaring class. */
415 if (m->flags & ACC_STATIC) {
416 /* For static methods we reset the object. */
421 /* for convenience */
426 /* For instance methods we make a virtual function table lookup. */
428 resm = method_vftbl_lookup(vftbl, m);
431 STATISTICS(jnicallXmethodnvokation());
433 i = vm_call_method_int_jvalue(resm, o, args);
439 /* _Jv_jni_CallLongMethod ******************************************************
441 Internal function to call Java long methods.
443 *******************************************************************************/
445 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
446 methodinfo *m, va_list ap)
451 STATISTICS(jniinvokation());
454 exceptions_throw_nullpointerexception();
458 /* Class initialization is done by the JIT compiler. This is ok
459 since a static method always belongs to the declaring class. */
461 if (m->flags & ACC_STATIC) {
462 /* For static methods we reset the object. */
467 /* for convenience */
472 /* For instance methods we make a virtual function table lookup. */
474 resm = method_vftbl_lookup(vftbl, m);
477 STATISTICS(jnicallXmethodnvokation());
479 l = vm_call_method_long_valist(resm, o, ap);
485 /* _Jv_jni_CallLongMethodA *****************************************************
487 Internal function to call Java long methods.
489 *******************************************************************************/
491 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
492 methodinfo *m, jvalue *args)
497 STATISTICS(jniinvokation());
500 exceptions_throw_nullpointerexception();
504 /* Class initialization is done by the JIT compiler. This is ok
505 since a static method always belongs to the declaring class. */
507 if (m->flags & ACC_STATIC) {
508 /* For static methods we reset the object. */
513 /* for convenience */
518 /* For instance methods we make a virtual function table lookup. */
520 resm = method_vftbl_lookup(vftbl, m);
523 STATISTICS(jnicallXmethodnvokation());
525 l = vm_call_method_long_jvalue(resm, o, args);
531 /* _Jv_jni_CallFloatMethod *****************************************************
533 Internal function to call Java float methods.
535 *******************************************************************************/
537 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
538 methodinfo *m, va_list ap)
543 /* Class initialization is done by the JIT compiler. This is ok
544 since a static method always belongs to the declaring class. */
546 if (m->flags & ACC_STATIC) {
547 /* For static methods we reset the object. */
552 /* for convenience */
557 /* For instance methods we make a virtual function table lookup. */
559 resm = method_vftbl_lookup(vftbl, m);
562 STATISTICS(jnicallXmethodnvokation());
564 f = vm_call_method_float_valist(resm, o, ap);
570 /* _Jv_jni_CallFloatMethodA ****************************************************
572 Internal function to call Java float methods.
574 *******************************************************************************/
576 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
577 methodinfo *m, jvalue *args)
582 /* Class initialization is done by the JIT compiler. This is ok
583 since a static method always belongs to the declaring class. */
585 if (m->flags & ACC_STATIC) {
586 /* For static methods we reset the object. */
591 /* for convenience */
596 /* For instance methods we make a virtual function table lookup. */
598 resm = method_vftbl_lookup(vftbl, m);
601 STATISTICS(jnicallXmethodnvokation());
603 f = vm_call_method_float_jvalue(resm, o, args);
609 /* _Jv_jni_CallDoubleMethod ****************************************************
611 Internal function to call Java double methods.
613 *******************************************************************************/
615 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
616 methodinfo *m, va_list ap)
621 /* Class initialization is done by the JIT compiler. This is ok
622 since a static method always belongs to the declaring class. */
624 if (m->flags & ACC_STATIC) {
625 /* For static methods we reset the object. */
630 /* for convenience */
635 /* For instance methods we make a virtual function table lookup. */
637 resm = method_vftbl_lookup(vftbl, m);
640 d = vm_call_method_double_valist(resm, o, ap);
646 /* _Jv_jni_CallDoubleMethodA ***************************************************
648 Internal function to call Java double methods.
650 *******************************************************************************/
652 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
653 methodinfo *m, jvalue *args)
658 /* Class initialization is done by the JIT compiler. This is ok
659 since a static method always belongs to the declaring class. */
661 if (m->flags & ACC_STATIC) {
662 /* For static methods we reset the object. */
667 /* for convenience */
672 /* For instance methods we make a virtual function table lookup. */
674 resm = method_vftbl_lookup(vftbl, m);
677 d = vm_call_method_double_jvalue(resm, o, args);
683 /* _Jv_jni_CallVoidMethod ******************************************************
685 Internal function to call Java void methods.
687 *******************************************************************************/
689 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
690 methodinfo *m, va_list ap)
695 exceptions_throw_nullpointerexception();
699 /* Class initialization is done by the JIT compiler. This is ok
700 since a static method always belongs to the declaring class. */
702 if (m->flags & ACC_STATIC) {
703 /* For static methods we reset the object. */
708 /* for convenience */
713 /* For instance methods we make a virtual function table lookup. */
715 resm = method_vftbl_lookup(vftbl, m);
718 STATISTICS(jnicallXmethodnvokation());
720 (void) vm_call_method_valist(resm, o, ap);
724 /* _Jv_jni_CallVoidMethodA *****************************************************
726 Internal function to call Java void methods.
728 *******************************************************************************/
730 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
731 methodinfo *m, jvalue *args)
736 exceptions_throw_nullpointerexception();
740 /* Class initialization is done by the JIT compiler. This is ok
741 since a static method always belongs to the declaring class. */
743 if (m->flags & ACC_STATIC) {
744 /* For static methods we reset the object. */
749 /* for convenience */
754 /* For instance methods we make a virtual function table lookup. */
756 resm = method_vftbl_lookup(vftbl, m);
759 STATISTICS(jnicallXmethodnvokation());
761 (void) vm_call_method_jvalue(resm, o, args);
765 /* _Jv_jni_invokeNative ********************************************************
767 Invoke a method on the given object with the given arguments.
769 For instance methods OBJ must be != NULL and the method is looked up
770 in the vftbl of the object.
772 For static methods, OBJ is ignored.
774 *******************************************************************************/
776 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__)
777 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
778 java_objectarray *params)
782 java_objectheader *ro;
785 java_objectheader *xptr;
788 exceptions_throw_nullpointerexception();
792 argcount = m->parseddesc->paramcount;
793 paramcount = argcount;
795 /* if method is non-static, remove the `this' pointer */
797 if (!(m->flags & ACC_STATIC))
800 /* For instance methods the object has to be an instance of the
801 class the method belongs to. For static methods the obj
802 parameter is ignored. */
804 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
805 exceptions_throw_illegalargumentexception();
809 /* check if we got the right number of arguments */
811 if (((params == NULL) && (paramcount != 0)) ||
812 (params && (params->header.size != paramcount)))
814 exceptions_throw_illegalargumentexception();
818 /* for instance methods we need an object */
820 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
821 /* XXX not sure if that is the correct exception */
822 exceptions_throw_nullpointerexception();
826 /* for static methods, zero object to make subsequent code simpler */
827 if (m->flags & ACC_STATIC)
831 /* for instance methods we must do a vftbl lookup */
832 resm = method_vftbl_lookup(o->vftbl, m);
835 /* for static methods, just for convenience */
839 vmargs = MNEW(vm_arg, argcount);
841 if (!vm_vmargs_from_objectarray(resm, o, vmargs, params)) {
842 MFREE(vmargs, vm_arg, argcount);
846 switch (resm->parseddesc->returntype.decltype) {
848 (void) vm_call_method_vmarg(resm, argcount, vmargs);
853 case PRIMITIVETYPE_BOOLEAN: {
855 java_lang_Boolean *bo;
857 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
859 ro = builtin_new(class_java_lang_Boolean);
861 /* setting the value of the object direct */
863 bo = (java_lang_Boolean *) ro;
868 case PRIMITIVETYPE_BYTE: {
872 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
874 ro = builtin_new(class_java_lang_Byte);
876 /* setting the value of the object direct */
878 bo = (java_lang_Byte *) ro;
883 case PRIMITIVETYPE_CHAR: {
885 java_lang_Character *co;
887 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
889 ro = builtin_new(class_java_lang_Character);
891 /* setting the value of the object direct */
893 co = (java_lang_Character *) ro;
898 case PRIMITIVETYPE_SHORT: {
902 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
904 ro = builtin_new(class_java_lang_Short);
906 /* setting the value of the object direct */
908 so = (java_lang_Short *) ro;
913 case PRIMITIVETYPE_INT: {
915 java_lang_Integer *io;
917 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
919 ro = builtin_new(class_java_lang_Integer);
921 /* setting the value of the object direct */
923 io = (java_lang_Integer *) ro;
928 case PRIMITIVETYPE_LONG: {
932 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
934 ro = builtin_new(class_java_lang_Long);
936 /* setting the value of the object direct */
938 lo = (java_lang_Long *) ro;
943 case PRIMITIVETYPE_FLOAT: {
947 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
949 ro = builtin_new(class_java_lang_Float);
951 /* setting the value of the object direct */
953 fo = (java_lang_Float *) ro;
958 case PRIMITIVETYPE_DOUBLE: {
960 java_lang_Double *_do;
962 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
964 ro = builtin_new(class_java_lang_Double);
966 /* setting the value of the object direct */
968 _do = (java_lang_Double *) ro;
974 ro = vm_call_method_vmarg(resm, argcount, vmargs);
978 /* if this happens the exception has already been set by
979 fill_callblock_from_objectarray */
981 MFREE(vmargs, vm_arg, argcount);
986 MFREE(vmargs, vm_arg, argcount);
988 xptr = exceptions_get_exception();
991 /* clear exception pointer, we are calling JIT code again */
993 exceptions_clear_exception();
995 exceptions_throw_invocationtargetexception(xptr);
1001 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
1002 java_objectarray *params)
1005 java_objectheader *ro;
1008 java_objectheader *xptr;
1013 exceptions_throw_nullpointerexception();
1017 argcount = m->parseddesc->paramcount;
1018 paramcount = argcount;
1020 /* if method is non-static, remove the `this' pointer */
1022 if (!(m->flags & ACC_STATIC))
1025 /* For instance methods the object has to be an instance of the
1026 class the method belongs to. For static methods the obj
1027 parameter is ignored. */
1029 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
1030 exceptions_throw_illegalargumentexception();
1034 /* check if we got the right number of arguments */
1036 if (((params == NULL) && (paramcount != 0)) ||
1037 (params && (params->header.size != paramcount)))
1039 exceptions_throw_illegalargumentexception();
1043 /* for instance methods we need an object */
1045 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
1046 /* XXX not sure if that is the correct exception */
1047 exceptions_throw_nullpointerexception();
1051 /* for static methods, zero object to make subsequent code simpler */
1052 if (m->flags & ACC_STATIC)
1056 /* for instance methods we must do a vftbl lookup */
1057 resm = method_vftbl_lookup(o->vftbl, m);
1060 /* for static methods, just for convenience */
1064 /* mark start of dump memory area */
1066 dumpsize = dump_size();
1068 /* fill the argument array from a object-array */
1070 array = vm_array_from_objectarray(resm, o, params);
1072 if (array == NULL) {
1073 /* release dump area */
1075 dump_release(dumpsize);
1080 switch (resm->parseddesc->returntype.decltype) {
1082 (void) vm_call_array(resm, array);
1087 case PRIMITIVETYPE_BOOLEAN: {
1089 java_lang_Boolean *bo;
1091 i = vm_call_int_array(resm, array);
1093 ro = builtin_new(class_java_lang_Boolean);
1095 /* setting the value of the object direct */
1097 bo = (java_lang_Boolean *) ro;
1102 case PRIMITIVETYPE_BYTE: {
1106 i = vm_call_int_array(resm, array);
1108 ro = builtin_new(class_java_lang_Byte);
1110 /* setting the value of the object direct */
1112 bo = (java_lang_Byte *) ro;
1117 case PRIMITIVETYPE_CHAR: {
1119 java_lang_Character *co;
1121 i = vm_call_int_array(resm, array);
1123 ro = builtin_new(class_java_lang_Character);
1125 /* setting the value of the object direct */
1127 co = (java_lang_Character *) ro;
1132 case PRIMITIVETYPE_SHORT: {
1134 java_lang_Short *so;
1136 i = vm_call_int_array(resm, array);
1138 ro = builtin_new(class_java_lang_Short);
1140 /* setting the value of the object direct */
1142 so = (java_lang_Short *) ro;
1147 case PRIMITIVETYPE_INT: {
1149 java_lang_Integer *io;
1151 i = vm_call_int_array(resm, array);
1153 ro = builtin_new(class_java_lang_Integer);
1155 /* setting the value of the object direct */
1157 io = (java_lang_Integer *) ro;
1162 case PRIMITIVETYPE_LONG: {
1166 l = vm_call_long_array(resm, array);
1168 ro = builtin_new(class_java_lang_Long);
1170 /* setting the value of the object direct */
1172 lo = (java_lang_Long *) ro;
1177 case PRIMITIVETYPE_FLOAT: {
1179 java_lang_Float *fo;
1181 f = vm_call_float_array(resm, array);
1183 ro = builtin_new(class_java_lang_Float);
1185 /* setting the value of the object direct */
1187 fo = (java_lang_Float *) ro;
1192 case PRIMITIVETYPE_DOUBLE: {
1194 java_lang_Double *_do;
1196 d = vm_call_double_array(resm, array);
1198 ro = builtin_new(class_java_lang_Double);
1200 /* setting the value of the object direct */
1202 _do = (java_lang_Double *) ro;
1208 ro = vm_call_array(resm, array);
1212 /* if this happens the exception has already been set by
1213 fill_callblock_from_objectarray */
1215 /* release dump area */
1217 dump_release(dumpsize);
1222 xptr = exceptions_get_exception();
1225 /* clear exception pointer, we are calling JIT code again */
1227 exceptions_clear_exception();
1229 exceptions_throw_invocationtargetexception(xptr);
1232 /* release dump area */
1234 dump_release(dumpsize);
1241 /* GetVersion ******************************************************************
1243 Returns the major version number in the higher 16 bits and the
1244 minor version number in the lower 16 bits.
1246 *******************************************************************************/
1248 jint _Jv_JNI_GetVersion(JNIEnv *env)
1250 STATISTICS(jniinvokation());
1252 /* we support JNI 1.4 */
1254 return JNI_VERSION_1_4;
1258 /* Class Operations ***********************************************************/
1260 /* DefineClass *****************************************************************
1262 Loads a class from a buffer of raw class data. The buffer
1263 containing the raw class data is not referenced by the VM after the
1264 DefineClass call returns, and it may be discarded if desired.
1266 *******************************************************************************/
1268 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1269 const jbyte *buf, jsize bufLen)
1271 #if defined(ENABLE_JAVASE)
1272 java_lang_ClassLoader *cl;
1273 java_lang_String *s;
1277 STATISTICS(jniinvokation());
1279 cl = (java_lang_ClassLoader *) loader;
1280 s = (java_lang_String *) javastring_new_from_utf_string(name);
1281 ba = (java_bytearray *) buf;
1283 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1286 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1288 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1290 /* keep compiler happy */
1297 /* FindClass *******************************************************************
1299 This function loads a locally-defined class. It searches the
1300 directories and zip files specified by the CLASSPATH environment
1301 variable for the class with the specified name.
1303 *******************************************************************************/
1305 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1307 #if defined(ENABLE_JAVASE)
1312 STATISTICS(jniinvokation());
1314 u = utf_new_char_classname((char *) name);
1316 /* Check stacktrace for classloader, if one found use it,
1317 otherwise use the system classloader. */
1319 /* Quote from the JNI documentation:
1321 In the Java 2 Platform, FindClass locates the class loader
1322 associated with the current native method. If the native code
1323 belongs to a system class, no class loader will be
1324 involved. Otherwise, the proper class loader will be invoked to
1325 load and link the named class. When FindClass is called through
1326 the Invocation Interface, there is no current native method or
1327 its associated class loader. In that case, the result of
1328 ClassLoader.getBaseClassLoader is used." */
1330 cc = stacktrace_getCurrentClass();
1333 c = load_class_from_sysloader(u);
1335 c = load_class_from_classloader(u, cc->classloader);
1343 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1345 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1347 /* keep compiler happy */
1354 /* GetSuperclass ***************************************************************
1356 If clazz represents any class other than the class Object, then
1357 this function returns the object that represents the superclass of
1358 the class specified by clazz.
1360 *******************************************************************************/
1362 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1366 STATISTICS(jniinvokation());
1368 c = ((classinfo *) sub)->super.cls;
1373 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1377 /* IsAssignableFrom ************************************************************
1379 Determines whether an object of sub can be safely cast to sup.
1381 *******************************************************************************/
1383 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1385 java_lang_Class *csup;
1386 java_lang_Class *csub;
1388 csup = (java_lang_Class *) sup;
1389 csub = (java_lang_Class *) sub;
1391 STATISTICS(jniinvokation());
1393 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1397 /* Throw ***********************************************************************
1399 Causes a java.lang.Throwable object to be thrown.
1401 *******************************************************************************/
1403 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1405 java_objectheader *o;
1407 STATISTICS(jniinvokation());
1409 o = (java_objectheader *) obj;
1411 exceptions_set_exception(o);
1417 /* ThrowNew ********************************************************************
1419 Constructs an exception object from the specified class with the
1420 message specified by message and causes that exception to be
1423 *******************************************************************************/
1425 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1428 java_objectheader *o;
1429 java_objectheader *s;
1431 STATISTICS(jniinvokation());
1433 c = (classinfo *) clazz;
1434 s = javastring_new_from_utf_string(msg);
1436 /* instantiate exception object */
1438 o = native_new_and_init_string(c, s);
1443 exceptions_set_exception(o);
1449 /* ExceptionOccurred ***********************************************************
1451 Determines if an exception is being thrown. The exception stays
1452 being thrown until either the native code calls ExceptionClear(),
1453 or the Java code handles the exception.
1455 *******************************************************************************/
1457 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1459 java_objectheader *o;
1461 STATISTICS(jniinvokation());
1463 o = exceptions_get_exception();
1465 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1469 /* ExceptionDescribe ***********************************************************
1471 Prints an exception and a backtrace of the stack to a system
1472 error-reporting channel, such as stderr. This is a convenience
1473 routine provided for debugging.
1475 *******************************************************************************/
1477 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1479 java_objectheader *o;
1482 STATISTICS(jniinvokation());
1484 o = exceptions_get_exception();
1487 /* clear exception, because we are calling jit code again */
1489 exceptions_clear_exception();
1491 /* get printStackTrace method from exception class */
1493 m = class_resolveclassmethod(o->vftbl->class,
1494 utf_printStackTrace,
1500 /* XXX what should we do? */
1503 /* print the stacktrace */
1505 (void) vm_call_method(m, o);
1510 /* ExceptionClear **************************************************************
1512 Clears any exception that is currently being thrown. If no
1513 exception is currently being thrown, this routine has no effect.
1515 *******************************************************************************/
1517 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1519 STATISTICS(jniinvokation());
1521 exceptions_clear_exception();
1525 /* FatalError ******************************************************************
1527 Raises a fatal error and does not expect the VM to recover. This
1528 function does not return.
1530 *******************************************************************************/
1532 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1534 STATISTICS(jniinvokation());
1536 /* this seems to be the best way */
1538 vm_abort("JNI Fatal error: %s", msg);
1542 /* PushLocalFrame **************************************************************
1544 Creates a new local reference frame, in which at least a given
1545 number of local references can be created.
1547 *******************************************************************************/
1549 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1552 localref_table *lrt;
1553 localref_table *nlrt;
1555 STATISTICS(jniinvokation());
1560 /* Allocate new local reference table on Java heap. Calculate the
1561 additional memory we have to allocate. */
1563 if (capacity > LOCALREFTABLE_CAPACITY)
1564 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1568 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1573 /* get current local reference table from thread */
1575 lrt = LOCALREFTABLE;
1577 /* Set up the new local reference table and add it to the local
1580 nlrt->capacity = capacity;
1582 nlrt->localframes = lrt->localframes + 1;
1585 /* store new local reference table in thread */
1587 LOCALREFTABLE = nlrt;
1593 /* PopLocalFrame ***************************************************************
1595 Pops off the current local reference frame, frees all the local
1596 references, and returns a local reference in the previous local
1597 reference frame for the given result object.
1599 *******************************************************************************/
1601 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1603 localref_table *lrt;
1604 localref_table *plrt;
1607 STATISTICS(jniinvokation());
1609 /* get current local reference table from thread */
1611 lrt = LOCALREFTABLE;
1613 localframes = lrt->localframes;
1615 /* Don't delete the top local frame, as this one is allocated in
1616 the native stub on the stack and is freed automagically on
1619 if (localframes == 1)
1620 return _Jv_JNI_NewLocalRef(env, result);
1622 /* release all current local frames */
1624 for (; localframes >= 1; localframes--) {
1625 /* get previous frame */
1629 /* clear all reference entries */
1631 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1635 /* set new local references table */
1640 /* store new local reference table in thread */
1642 LOCALREFTABLE = lrt;
1644 /* add local reference and return the value */
1646 return _Jv_JNI_NewLocalRef(env, result);
1650 /* DeleteLocalRef **************************************************************
1652 Deletes the local reference pointed to by localRef.
1654 *******************************************************************************/
1656 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1658 java_objectheader *o;
1659 localref_table *lrt;
1662 STATISTICS(jniinvokation());
1664 o = (java_objectheader *) localRef;
1666 /* get local reference table (thread specific) */
1668 lrt = LOCALREFTABLE;
1670 /* go through all local frames */
1672 for (; lrt != NULL; lrt = lrt->prev) {
1674 /* and try to remove the reference */
1676 for (i = 0; i < lrt->capacity; i++) {
1677 if (lrt->refs[i] == o) {
1678 lrt->refs[i] = NULL;
1686 /* this should not happen */
1688 /* if (opt_checkjni) */
1689 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1690 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1694 /* IsSameObject ****************************************************************
1696 Tests whether two references refer to the same Java object.
1698 *******************************************************************************/
1700 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1702 STATISTICS(jniinvokation());
1711 /* NewLocalRef *****************************************************************
1713 Creates a new local reference that refers to the same object as ref.
1715 *******************************************************************************/
1717 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1719 localref_table *lrt;
1722 STATISTICS(jniinvokation());
1727 /* get local reference table (thread specific) */
1729 lrt = LOCALREFTABLE;
1731 /* Check if we have space for the requested reference? No,
1732 allocate a new frame. This is actually not what the spec says,
1733 but for compatibility reasons... */
1735 if (lrt->used == lrt->capacity) {
1736 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1739 /* get the new local reference table */
1741 lrt = LOCALREFTABLE;
1744 /* insert the reference */
1746 for (i = 0; i < lrt->capacity; i++) {
1747 if (lrt->refs[i] == NULL) {
1748 lrt->refs[i] = (java_objectheader *) ref;
1755 /* should not happen, just to be sure */
1759 /* keep compiler happy */
1765 /* EnsureLocalCapacity *********************************************************
1767 Ensures that at least a given number of local references can be
1768 created in the current thread
1770 *******************************************************************************/
1772 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1774 localref_table *lrt;
1776 STATISTICS(jniinvokation());
1778 /* get local reference table (thread specific) */
1780 lrt = LOCALREFTABLE;
1782 /* check if capacity elements are available in the local references table */
1784 if ((lrt->used + capacity) > lrt->capacity)
1785 return _Jv_JNI_PushLocalFrame(env, capacity);
1791 /* AllocObject *****************************************************************
1793 Allocates a new Java object without invoking any of the
1794 constructors for the object. Returns a reference to the object.
1796 *******************************************************************************/
1798 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1801 java_objectheader *o;
1803 STATISTICS(jniinvokation());
1805 c = (classinfo *) clazz;
1807 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1808 exceptions_throw_instantiationexception(c);
1814 return _Jv_JNI_NewLocalRef(env, o);
1818 /* NewObject *******************************************************************
1820 Programmers place all arguments that are to be passed to the
1821 constructor immediately following the methodID
1822 argument. NewObject() accepts these arguments and passes them to
1823 the Java method that the programmer wishes to invoke.
1825 *******************************************************************************/
1827 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1829 java_objectheader *o;
1833 STATISTICS(jniinvokation());
1835 m = (methodinfo *) methodID;
1839 o = builtin_new(clazz);
1844 /* call constructor */
1846 va_start(ap, methodID);
1847 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1850 return _Jv_JNI_NewLocalRef(env, o);
1854 /* NewObjectV ******************************************************************
1856 Programmers place all arguments that are to be passed to the
1857 constructor in an args argument of type va_list that immediately
1858 follows the methodID argument. NewObjectV() accepts these
1859 arguments, and, in turn, passes them to the Java method that the
1860 programmer wishes to invoke.
1862 *******************************************************************************/
1864 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1867 java_objectheader *o;
1870 STATISTICS(jniinvokation());
1872 m = (methodinfo *) methodID;
1876 o = builtin_new(clazz);
1881 /* call constructor */
1883 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1885 return _Jv_JNI_NewLocalRef(env, o);
1889 /* NewObjectA *****************************************************************
1891 Programmers place all arguments that are to be passed to the
1892 constructor in an args array of jvalues that immediately follows
1893 the methodID argument. NewObjectA() accepts the arguments in this
1894 array, and, in turn, passes them to the Java method that the
1895 programmer wishes to invoke.
1897 *******************************************************************************/
1899 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1902 java_objectheader *o;
1905 STATISTICS(jniinvokation());
1907 m = (methodinfo *) methodID;
1911 o = builtin_new(clazz);
1916 /* call constructor */
1918 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1920 return _Jv_JNI_NewLocalRef(env, o);
1924 /* GetObjectClass **************************************************************
1926 Returns the class of an object.
1928 *******************************************************************************/
1930 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1932 java_objectheader *o;
1935 STATISTICS(jniinvokation());
1937 o = (java_objectheader *) obj;
1939 if ((o == NULL) || (o->vftbl == NULL))
1942 c = o->vftbl->class;
1944 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1948 /* IsInstanceOf ****************************************************************
1950 Tests whether an object is an instance of a class.
1952 *******************************************************************************/
1954 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1957 java_lang_Object *o;
1959 STATISTICS(jniinvokation());
1961 c = (java_lang_Class *) clazz;
1962 o = (java_lang_Object *) obj;
1964 return _Jv_java_lang_Class_isInstance(c, o);
1968 /* Reflection Support *********************************************************/
1970 /* FromReflectedMethod *********************************************************
1972 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1973 object to a method ID.
1975 *******************************************************************************/
1977 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1979 #if defined(ENABLE_JAVASE)
1984 STATISTICS(jniinvokation());
1989 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1990 java_lang_reflect_Method *rm;
1992 rm = (java_lang_reflect_Method *) method;
1993 c = (classinfo *) (rm->declaringClass);
1996 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1997 java_lang_reflect_Constructor *rc;
1999 rc = (java_lang_reflect_Constructor *) method;
2000 c = (classinfo *) (rc->clazz);
2006 mi = &(c->methods[slot]);
2008 return (jmethodID) mi;
2010 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
2012 /* keep compiler happy */
2019 /* FromReflectedField **********************************************************
2021 Converts a java.lang.reflect.Field to a field ID.
2023 *******************************************************************************/
2025 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
2027 #if defined(ENABLE_JAVASE)
2028 java_lang_reflect_Field *rf;
2032 STATISTICS(jniinvokation());
2034 rf = (java_lang_reflect_Field *) field;
2039 c = (classinfo *) rf->declaringClass;
2041 f = &(c->fields[rf->slot]);
2043 return (jfieldID) f;
2045 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
2047 /* keep compiler happy */
2054 /* ToReflectedMethod ***********************************************************
2056 Converts a method ID derived from cls to an instance of the
2057 java.lang.reflect.Method class or to an instance of the
2058 java.lang.reflect.Constructor class.
2060 *******************************************************************************/
2062 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2065 STATISTICS(jniinvokation());
2067 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2073 /* ToReflectedField ************************************************************
2075 Converts a field ID derived from cls to an instance of the
2076 java.lang.reflect.Field class.
2078 *******************************************************************************/
2080 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2083 STATISTICS(jniinvokation());
2085 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2091 /* Calling Instance Methods ***************************************************/
2093 /* GetMethodID *****************************************************************
2095 Returns the method ID for an instance (nonstatic) method of a class
2096 or interface. The method may be defined in one of the clazz's
2097 superclasses and inherited by clazz. The method is determined by
2098 its name and signature.
2100 GetMethodID() causes an uninitialized class to be initialized.
2102 *******************************************************************************/
2104 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2112 STATISTICS(jniinvokation());
2114 c = (classinfo *) clazz;
2119 if (!(c->state & CLASS_INITIALIZED))
2120 if (!initialize_class(c))
2123 /* try to get the method of the class or one of it's superclasses */
2125 uname = utf_new_char((char *) name);
2126 udesc = utf_new_char((char *) sig);
2128 m = class_resolvemethod(clazz, uname, udesc);
2130 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2131 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2136 return (jmethodID) m;
2140 /* JNI-functions for calling instance methods *********************************/
2142 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2145 java_objectheader *o;
2147 java_objectheader *ret;
2150 o = (java_objectheader *) obj;
2151 m = (methodinfo *) methodID;
2153 va_start(ap, methodID);
2154 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2157 return _Jv_JNI_NewLocalRef(env, ret);
2161 jobject _Jv_JNI_CallObjectMethodV(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_CallObjectMethod(o, o->vftbl, m, args);
2173 return _Jv_JNI_NewLocalRef(env, ret);
2177 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2180 java_objectheader *o;
2182 java_objectheader *ret;
2184 o = (java_objectheader *) obj;
2185 m = (methodinfo *) methodID;
2187 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2189 return _Jv_JNI_NewLocalRef(env, ret);
2193 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2196 java_objectheader *o;
2201 o = (java_objectheader *) obj;
2202 m = (methodinfo *) methodID;
2204 va_start(ap, methodID);
2205 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2212 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2213 jmethodID methodID, va_list args)
2215 java_objectheader *o;
2219 o = (java_objectheader *) obj;
2220 m = (methodinfo *) methodID;
2222 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2228 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2229 jmethodID methodID, jvalue *args)
2231 java_objectheader *o;
2235 o = (java_objectheader *) obj;
2236 m = (methodinfo *) methodID;
2238 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2244 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2246 java_objectheader *o;
2251 o = (java_objectheader *) obj;
2252 m = (methodinfo *) methodID;
2254 va_start(ap, methodID);
2255 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2263 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2266 java_objectheader *o;
2270 o = (java_objectheader *) obj;
2271 m = (methodinfo *) methodID;
2273 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2279 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2282 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2288 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2290 java_objectheader *o;
2295 o = (java_objectheader *) obj;
2296 m = (methodinfo *) methodID;
2298 va_start(ap, methodID);
2299 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2306 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2309 java_objectheader *o;
2313 o = (java_objectheader *) obj;
2314 m = (methodinfo *) methodID;
2316 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2322 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2325 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2331 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2334 java_objectheader *o;
2339 o = (java_objectheader *) obj;
2340 m = (methodinfo *) methodID;
2342 va_start(ap, methodID);
2343 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2350 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2353 java_objectheader *o;
2357 o = (java_objectheader *) obj;
2358 m = (methodinfo *) methodID;
2360 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2366 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2369 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2376 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2378 java_objectheader *o;
2383 o = (java_objectheader *) obj;
2384 m = (methodinfo *) methodID;
2386 va_start(ap, methodID);
2387 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2394 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2397 java_objectheader *o;
2401 o = (java_objectheader *) obj;
2402 m = (methodinfo *) methodID;
2404 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2410 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2413 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2420 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2422 java_objectheader *o;
2427 o = (java_objectheader *) obj;
2428 m = (methodinfo *) methodID;
2430 va_start(ap, methodID);
2431 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2438 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2441 java_objectheader *o;
2445 o = (java_objectheader *) obj;
2446 m = (methodinfo *) methodID;
2448 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2454 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2457 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2464 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2467 java_objectheader *o;
2472 o = (java_objectheader *) obj;
2473 m = (methodinfo *) methodID;
2475 va_start(ap, methodID);
2476 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2483 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2486 java_objectheader *o;
2490 o = (java_objectheader *) obj;
2491 m = (methodinfo *) methodID;
2493 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2499 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2502 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2509 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2512 java_objectheader *o;
2517 o = (java_objectheader *) obj;
2518 m = (methodinfo *) methodID;
2520 va_start(ap, methodID);
2521 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2528 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2531 java_objectheader *o;
2535 o = (java_objectheader *) obj;
2536 m = (methodinfo *) methodID;
2538 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2544 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2547 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2554 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2556 java_objectheader *o;
2560 o = (java_objectheader *) obj;
2561 m = (methodinfo *) methodID;
2563 va_start(ap, methodID);
2564 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2569 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2572 java_objectheader *o;
2575 o = (java_objectheader *) obj;
2576 m = (methodinfo *) methodID;
2578 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2582 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2585 java_objectheader *o;
2588 o = (java_objectheader *) obj;
2589 m = (methodinfo *) methodID;
2591 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2596 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2597 jclass clazz, jmethodID methodID,
2600 java_objectheader *o;
2603 java_objectheader *r;
2606 o = (java_objectheader *) obj;
2607 c = (classinfo *) clazz;
2608 m = (methodinfo *) methodID;
2610 va_start(ap, methodID);
2611 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2614 return _Jv_JNI_NewLocalRef(env, r);
2618 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2619 jclass clazz, jmethodID methodID,
2622 java_objectheader *o;
2625 java_objectheader *r;
2627 o = (java_objectheader *) obj;
2628 c = (classinfo *) clazz;
2629 m = (methodinfo *) methodID;
2631 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2633 return _Jv_JNI_NewLocalRef(env, r);
2637 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2638 jclass clazz, jmethodID methodID,
2641 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2643 return _Jv_JNI_NewLocalRef(env, NULL);
2648 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2649 jclass clazz, jmethodID methodID,
2652 java_objectheader *o;
2658 o = (java_objectheader *) obj;
2659 c = (classinfo *) clazz;
2660 m = (methodinfo *) methodID;
2662 va_start(ap, methodID);
2663 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2670 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2671 jclass clazz, jmethodID methodID,
2674 java_objectheader *o;
2679 o = (java_objectheader *) obj;
2680 c = (classinfo *) clazz;
2681 m = (methodinfo *) methodID;
2683 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2689 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2690 jclass clazz, jmethodID methodID,
2693 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2699 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2700 jmethodID methodID, ...)
2702 java_objectheader *o;
2708 o = (java_objectheader *) obj;
2709 c = (classinfo *) clazz;
2710 m = (methodinfo *) methodID;
2712 va_start(ap, methodID);
2713 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2720 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2721 jmethodID methodID, va_list args)
2723 java_objectheader *o;
2728 o = (java_objectheader *) obj;
2729 c = (classinfo *) clazz;
2730 m = (methodinfo *) methodID;
2732 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2738 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2739 jmethodID methodID, jvalue *args)
2741 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2748 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2749 jmethodID methodID, ...)
2751 java_objectheader *o;
2757 o = (java_objectheader *) obj;
2758 c = (classinfo *) clazz;
2759 m = (methodinfo *) methodID;
2761 va_start(ap, methodID);
2762 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2769 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2770 jmethodID methodID, va_list args)
2772 java_objectheader *o;
2777 o = (java_objectheader *) obj;
2778 c = (classinfo *) clazz;
2779 m = (methodinfo *) methodID;
2781 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2787 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2788 jmethodID methodID, jvalue *args)
2790 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2797 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2798 jclass clazz, jmethodID methodID, ...)
2800 java_objectheader *o;
2806 o = (java_objectheader *) obj;
2807 c = (classinfo *) clazz;
2808 m = (methodinfo *) methodID;
2810 va_start(ap, methodID);
2811 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2818 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2819 jclass clazz, jmethodID methodID,
2822 java_objectheader *o;
2827 o = (java_objectheader *) obj;
2828 c = (classinfo *) clazz;
2829 m = (methodinfo *) methodID;
2831 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2837 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2838 jclass clazz, jmethodID methodID,
2841 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2848 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2849 jmethodID methodID, ...)
2851 java_objectheader *o;
2857 o = (java_objectheader *) obj;
2858 c = (classinfo *) clazz;
2859 m = (methodinfo *) methodID;
2861 va_start(ap, methodID);
2862 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2869 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2870 jmethodID methodID, va_list args)
2872 java_objectheader *o;
2877 o = (java_objectheader *) obj;
2878 c = (classinfo *) clazz;
2879 m = (methodinfo *) methodID;
2881 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2887 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2888 jmethodID methodID, jvalue *args)
2890 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2897 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2898 jmethodID methodID, ...)
2900 java_objectheader *o;
2906 o = (java_objectheader *) obj;
2907 c = (classinfo *) clazz;
2908 m = (methodinfo *) methodID;
2910 va_start(ap, methodID);
2911 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2918 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2919 jmethodID methodID, va_list args)
2921 java_objectheader *o;
2926 o = (java_objectheader *) obj;
2927 c = (classinfo *) clazz;
2928 m = (methodinfo *) methodID;
2930 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2936 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2937 jmethodID methodID, jvalue *args)
2939 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2946 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2947 jclass clazz, jmethodID methodID, ...)
2949 java_objectheader *o;
2955 o = (java_objectheader *) obj;
2956 c = (classinfo *) clazz;
2957 m = (methodinfo *) methodID;
2959 va_start(ap, methodID);
2960 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2967 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2968 jclass clazz, jmethodID methodID,
2971 java_objectheader *o;
2976 o = (java_objectheader *) obj;
2977 c = (classinfo *) clazz;
2978 m = (methodinfo *) methodID;
2980 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2986 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2987 jclass clazz, jmethodID methodID,
2990 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2997 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2998 jclass clazz, jmethodID methodID,
3001 java_objectheader *o;
3007 o = (java_objectheader *) obj;
3008 c = (classinfo *) clazz;
3009 m = (methodinfo *) methodID;
3011 va_start(ap, methodID);
3012 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
3019 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
3020 jclass clazz, jmethodID methodID,
3023 java_objectheader *o;
3028 o = (java_objectheader *) obj;
3029 c = (classinfo *) clazz;
3030 m = (methodinfo *) methodID;
3032 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
3038 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
3039 jclass clazz, jmethodID methodID,
3042 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
3049 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
3050 jmethodID methodID, ...)
3052 java_objectheader *o;
3057 o = (java_objectheader *) obj;
3058 c = (classinfo *) clazz;
3059 m = (methodinfo *) methodID;
3061 va_start(ap, methodID);
3062 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3067 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3068 jmethodID methodID, va_list args)
3070 java_objectheader *o;
3074 o = (java_objectheader *) obj;
3075 c = (classinfo *) clazz;
3076 m = (methodinfo *) methodID;
3078 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3082 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3083 jmethodID methodID, jvalue * args)
3085 java_objectheader *o;
3089 o = (java_objectheader *) obj;
3090 c = (classinfo *) clazz;
3091 m = (methodinfo *) methodID;
3093 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3097 /* Accessing Fields of Objects ************************************************/
3099 /* GetFieldID ******************************************************************
3101 Returns the field ID for an instance (nonstatic) field of a
3102 class. The field is specified by its name and signature. The
3103 Get<type>Field and Set<type>Field families of accessor functions
3104 use field IDs to retrieve object fields.
3106 *******************************************************************************/
3108 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3116 STATISTICS(jniinvokation());
3118 c = (classinfo *) clazz;
3120 uname = utf_new_char((char *) name);
3121 udesc = utf_new_char((char *) sig);
3123 f = class_findfield(clazz, uname, udesc);
3126 exceptions_throw_nosuchfielderror(c, uname);
3128 return (jfieldID) f;
3132 /* Get<type>Field Routines *****************************************************
3134 This family of accessor routines returns the value of an instance
3135 (nonstatic) field of an object. The field to access is specified by
3136 a field ID obtained by calling GetFieldID().
3138 *******************************************************************************/
3140 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3142 java_objectheader *o;
3144 STATISTICS(jniinvokation());
3146 o = GET_FIELD(obj, java_objectheader*, fieldID);
3148 return _Jv_JNI_NewLocalRef(env, o);
3152 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3156 STATISTICS(jniinvokation());
3158 i = GET_FIELD(obj, s4, fieldID);
3160 return (jboolean) i;
3164 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3168 STATISTICS(jniinvokation());
3170 i = GET_FIELD(obj, s4, fieldID);
3176 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3180 STATISTICS(jniinvokation());
3182 i = GET_FIELD(obj, s4, fieldID);
3188 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3192 STATISTICS(jniinvokation());
3194 i = GET_FIELD(obj, s4, fieldID);
3200 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3202 java_objectheader *o;
3206 STATISTICS(jniinvokation());
3208 o = (java_objectheader *) obj;
3209 f = (fieldinfo *) fieldID;
3211 i = GET_FIELD(o, s4, f);
3217 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3221 STATISTICS(jniinvokation());
3223 l = GET_FIELD(obj, s8, fieldID);
3229 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3233 STATISTICS(jniinvokation());
3235 f = GET_FIELD(obj, float, fieldID);
3241 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3245 STATISTICS(jniinvokation());
3247 d = GET_FIELD(obj, double, fieldID);
3253 /* Set<type>Field Routines *****************************************************
3255 This family of accessor routines sets the value of an instance
3256 (nonstatic) field of an object. The field to access is specified by
3257 a field ID obtained by calling GetFieldID().
3259 *******************************************************************************/
3261 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3264 STATISTICS(jniinvokation());
3266 SET_FIELD(obj, java_objectheader*, fieldID, value);
3270 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3273 STATISTICS(jniinvokation());
3275 SET_FIELD(obj, s4, fieldID, value);
3279 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3282 STATISTICS(jniinvokation());
3284 SET_FIELD(obj, s4, fieldID, value);
3288 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3291 STATISTICS(jniinvokation());
3293 SET_FIELD(obj, s4, fieldID, value);
3297 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3300 STATISTICS(jniinvokation());
3302 SET_FIELD(obj, s4, fieldID, value);
3306 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3308 STATISTICS(jniinvokation());
3310 SET_FIELD(obj, s4, fieldID, value);
3314 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3317 STATISTICS(jniinvokation());
3319 SET_FIELD(obj, s8, fieldID, value);
3323 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3326 STATISTICS(jniinvokation());
3328 SET_FIELD(obj, float, fieldID, value);
3332 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3335 STATISTICS(jniinvokation());
3337 SET_FIELD(obj, double, fieldID, value);
3341 /* Calling Static Methods *****************************************************/
3343 /* GetStaticMethodID ***********************************************************
3345 Returns the method ID for a static method of a class. The method is
3346 specified by its name and signature.
3348 GetStaticMethodID() causes an uninitialized class to be
3351 *******************************************************************************/
3353 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3361 STATISTICS(jniinvokation());
3363 c = (classinfo *) clazz;
3368 if (!(c->state & CLASS_INITIALIZED))
3369 if (!initialize_class(c))
3372 /* try to get the static method of the class */
3374 uname = utf_new_char((char *) name);
3375 udesc = utf_new_char((char *) sig);
3377 m = class_resolvemethod(c, uname, udesc);
3379 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3380 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3385 return (jmethodID) m;
3389 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3390 jmethodID methodID, ...)
3393 java_objectheader *o;
3396 m = (methodinfo *) methodID;
3398 va_start(ap, methodID);
3399 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3402 return _Jv_JNI_NewLocalRef(env, o);
3406 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3407 jmethodID methodID, va_list args)
3410 java_objectheader *o;
3412 m = (methodinfo *) methodID;
3414 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3416 return _Jv_JNI_NewLocalRef(env, o);
3420 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3421 jmethodID methodID, jvalue *args)
3424 java_objectheader *o;
3426 m = (methodinfo *) methodID;
3428 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3430 return _Jv_JNI_NewLocalRef(env, o);
3434 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3435 jmethodID methodID, ...)
3441 m = (methodinfo *) methodID;
3443 va_start(ap, methodID);
3444 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3451 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3452 jmethodID methodID, va_list args)
3457 m = (methodinfo *) methodID;
3459 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3465 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3466 jmethodID methodID, jvalue *args)
3471 m = (methodinfo *) methodID;
3473 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3479 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3480 jmethodID methodID, ...)
3486 m = (methodinfo *) methodID;
3488 va_start(ap, methodID);
3489 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3496 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3497 jmethodID methodID, va_list args)
3502 m = (methodinfo *) methodID;
3504 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3510 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3511 jmethodID methodID, jvalue *args)
3516 m = (methodinfo *) methodID;
3518 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3524 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3525 jmethodID methodID, ...)
3531 m = (methodinfo *) methodID;
3533 va_start(ap, methodID);
3534 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3541 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3542 jmethodID methodID, va_list args)
3547 m = (methodinfo *) methodID;
3549 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3555 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3556 jmethodID methodID, jvalue *args)
3561 m = (methodinfo *) methodID;
3563 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3569 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3570 jmethodID methodID, ...)
3576 m = (methodinfo *) methodID;
3578 va_start(ap, methodID);
3579 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3586 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3587 jmethodID methodID, va_list args)
3592 m = (methodinfo *) methodID;
3594 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3600 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3601 jmethodID methodID, jvalue *args)
3606 m = (methodinfo *) methodID;
3608 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3614 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3621 m = (methodinfo *) methodID;
3623 va_start(ap, methodID);
3624 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3631 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3632 jmethodID methodID, va_list args)
3637 m = (methodinfo *) methodID;
3639 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3645 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3646 jmethodID methodID, jvalue *args)
3651 m = (methodinfo *) methodID;
3653 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3659 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3660 jmethodID methodID, ...)
3666 m = (methodinfo *) methodID;
3668 va_start(ap, methodID);
3669 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3676 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3677 jmethodID methodID, va_list args)
3682 m = (methodinfo *) methodID;
3684 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3690 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3691 jmethodID methodID, jvalue *args)
3696 m = (methodinfo *) methodID;
3698 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3705 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3706 jmethodID methodID, ...)
3712 m = (methodinfo *) methodID;
3714 va_start(ap, methodID);
3715 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3722 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3723 jmethodID methodID, va_list args)
3728 m = (methodinfo *) methodID;
3730 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3736 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3737 jmethodID methodID, jvalue *args)
3742 m = (methodinfo *) methodID;
3744 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3750 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3751 jmethodID methodID, ...)
3757 m = (methodinfo *) methodID;
3759 va_start(ap, methodID);
3760 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3767 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3768 jmethodID methodID, va_list args)
3773 m = (methodinfo *) methodID;
3775 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3781 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3782 jmethodID methodID, jvalue *args)
3787 m = (methodinfo *) methodID;
3789 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3795 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3796 jmethodID methodID, ...)
3801 m = (methodinfo *) methodID;
3803 va_start(ap, methodID);
3804 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3809 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3810 jmethodID methodID, va_list args)
3814 m = (methodinfo *) methodID;
3816 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3820 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3821 jmethodID methodID, jvalue * args)
3825 m = (methodinfo *) methodID;
3827 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3831 /* Accessing Static Fields ****************************************************/
3833 /* GetStaticFieldID ************************************************************
3835 Returns the field ID for a static field of a class. The field is
3836 specified by its name and signature. The GetStatic<type>Field and
3837 SetStatic<type>Field families of accessor functions use field IDs
3838 to retrieve static fields.
3840 *******************************************************************************/
3842 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3850 STATISTICS(jniinvokation());
3852 c = (classinfo *) clazz;
3854 uname = utf_new_char((char *) name);
3855 usig = utf_new_char((char *) sig);
3857 f = class_findfield(clazz, uname, usig);
3860 exceptions_throw_nosuchfielderror(c, uname);
3862 return (jfieldID) f;
3866 /* GetStatic<type>Field ********************************************************
3868 This family of accessor routines returns the value of a static
3871 *******************************************************************************/
3873 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3879 STATISTICS(jniinvokation());
3881 c = (classinfo *) clazz;
3882 f = (fieldinfo *) fieldID;
3884 if (!(c->state & CLASS_INITIALIZED))
3885 if (!initialize_class(c))
3888 return _Jv_JNI_NewLocalRef(env, f->value.a);
3892 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3898 STATISTICS(jniinvokation());
3900 c = (classinfo *) clazz;
3901 f = (fieldinfo *) fieldID;
3903 if (!(c->state & CLASS_INITIALIZED))
3904 if (!initialize_class(c))
3911 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3916 STATISTICS(jniinvokation());
3918 c = (classinfo *) clazz;
3919 f = (fieldinfo *) fieldID;
3921 if (!(c->state & CLASS_INITIALIZED))
3922 if (!initialize_class(c))
3929 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3934 STATISTICS(jniinvokation());
3936 c = (classinfo *) clazz;
3937 f = (fieldinfo *) fieldID;
3939 if (!(c->state & CLASS_INITIALIZED))
3940 if (!initialize_class(c))
3947 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3952 STATISTICS(jniinvokation());
3954 c = (classinfo *) clazz;
3955 f = (fieldinfo *) fieldID;
3957 if (!(c->state & CLASS_INITIALIZED))
3958 if (!initialize_class(c))
3965 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3970 STATISTICS(jniinvokation());
3972 c = (classinfo *) clazz;
3973 f = (fieldinfo *) fieldID;
3975 if (!(c->state & CLASS_INITIALIZED))
3976 if (!initialize_class(c))
3983 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3988 STATISTICS(jniinvokation());
3990 c = (classinfo *) clazz;
3991 f = (fieldinfo *) fieldID;
3993 if (!(c->state & CLASS_INITIALIZED))
3994 if (!initialize_class(c))
4001 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4006 STATISTICS(jniinvokation());
4008 c = (classinfo *) clazz;
4009 f = (fieldinfo *) fieldID;
4011 if (!(c->state & CLASS_INITIALIZED))
4012 if (!initialize_class(c))
4019 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
4025 STATISTICS(jniinvokation());
4027 c = (classinfo *) clazz;
4028 f = (fieldinfo *) fieldID;
4030 if (!(c->state & CLASS_INITIALIZED))
4031 if (!initialize_class(c))
4038 /* SetStatic<type>Field *******************************************************
4040 This family of accessor routines sets the value of a static field
4043 *******************************************************************************/
4045 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4051 STATISTICS(jniinvokation());
4053 c = (classinfo *) clazz;
4054 f = (fieldinfo *) fieldID;
4056 if (!(c->state & CLASS_INITIALIZED))
4057 if (!initialize_class(c))
4064 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4070 STATISTICS(jniinvokation());
4072 c = (classinfo *) clazz;
4073 f = (fieldinfo *) fieldID;
4075 if (!(c->state & CLASS_INITIALIZED))
4076 if (!initialize_class(c))
4083 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4089 STATISTICS(jniinvokation());
4091 c = (classinfo *) clazz;
4092 f = (fieldinfo *) fieldID;
4094 if (!(c->state & CLASS_INITIALIZED))
4095 if (!initialize_class(c))
4102 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4108 STATISTICS(jniinvokation());
4110 c = (classinfo *) clazz;
4111 f = (fieldinfo *) fieldID;
4113 if (!(c->state & CLASS_INITIALIZED))
4114 if (!initialize_class(c))
4121 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4127 STATISTICS(jniinvokation());
4129 c = (classinfo *) clazz;
4130 f = (fieldinfo *) fieldID;
4132 if (!(c->state & CLASS_INITIALIZED))
4133 if (!initialize_class(c))
4140 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4146 STATISTICS(jniinvokation());
4148 c = (classinfo *) clazz;
4149 f = (fieldinfo *) fieldID;
4151 if (!(c->state & CLASS_INITIALIZED))
4152 if (!initialize_class(c))
4159 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4165 STATISTICS(jniinvokation());
4167 c = (classinfo *) clazz;
4168 f = (fieldinfo *) fieldID;
4170 if (!(c->state & CLASS_INITIALIZED))
4171 if (!initialize_class(c))
4178 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4184 STATISTICS(jniinvokation());
4186 c = (classinfo *) clazz;
4187 f = (fieldinfo *) fieldID;
4189 if (!(c->state & CLASS_INITIALIZED))
4190 if (!initialize_class(c))
4197 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4203 STATISTICS(jniinvokation());
4205 c = (classinfo *) clazz;
4206 f = (fieldinfo *) fieldID;
4208 if (!(c->state & CLASS_INITIALIZED))
4209 if (!initialize_class(c))
4216 /* String Operations **********************************************************/
4218 /* NewString *******************************************************************
4220 Create new java.lang.String object from an array of Unicode
4223 *******************************************************************************/
4225 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4227 java_lang_String *s;
4231 STATISTICS(jniinvokation());
4233 s = (java_lang_String *) builtin_new(class_java_lang_String);
4234 a = builtin_newarray_char(len);
4236 /* javastring or characterarray could not be created */
4237 if ((a == NULL) || (s == NULL))
4241 for (i = 0; i < len; i++)
4242 a->data[i] = buf[i];
4248 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4252 static jchar emptyStringJ[]={0,0};
4254 /* GetStringLength *************************************************************
4256 Returns the length (the count of Unicode characters) of a Java
4259 *******************************************************************************/
4261 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4263 return ((java_lang_String *) str)->count;
4267 /******************** convertes javastring to u2-array ****************************/
4269 u2 *javastring_tou2(jstring so)
4271 java_lang_String *s;
4276 STATISTICS(jniinvokation());
4278 s = (java_lang_String *) so;
4288 /* allocate memory */
4290 stringbuffer = MNEW(u2, s->count + 1);
4294 for (i = 0; i < s->count; i++)
4295 stringbuffer[i] = a->data[s->offset + i];
4297 /* terminate string */
4299 stringbuffer[i] = '\0';
4301 return stringbuffer;
4305 /* GetStringChars **************************************************************
4307 Returns a pointer to the array of Unicode characters of the
4308 string. This pointer is valid until ReleaseStringChars() is called.
4310 *******************************************************************************/
4312 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4316 STATISTICS(jniinvokation());
4318 jc = javastring_tou2(str);
4330 return emptyStringJ;
4334 /* ReleaseStringChars **********************************************************
4336 Informs the VM that the native code no longer needs access to
4337 chars. The chars argument is a pointer obtained from string using
4340 *******************************************************************************/
4342 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4344 STATISTICS(jniinvokation());
4346 if (chars == emptyStringJ)
4349 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4353 /* NewStringUTF ****************************************************************
4355 Constructs a new java.lang.String object from an array of UTF-8
4358 *******************************************************************************/
4360 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4362 java_lang_String *s;
4364 STATISTICS(jniinvokation());
4366 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4368 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4372 /****************** returns the utf8 length in bytes of a string *******************/
4374 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4376 java_lang_String *s = (java_lang_String*) string;
4378 STATISTICS(jniinvokation());
4380 return (jsize) u2_utflength(s->value->data, s->count);
4384 /* GetStringUTFChars ***********************************************************
4386 Returns a pointer to an array of UTF-8 characters of the
4387 string. This array is valid until it is released by
4388 ReleaseStringUTFChars().
4390 *******************************************************************************/
4392 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4397 STATISTICS(jniinvokation());
4405 u = javastring_toutf((java_objectheader *) string, false);
4414 /* ReleaseStringUTFChars *******************************************************
4416 Informs the VM that the native code no longer needs access to
4417 utf. The utf argument is a pointer derived from string using
4418 GetStringUTFChars().
4420 *******************************************************************************/
4422 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4424 STATISTICS(jniinvokation());
4426 /* XXX we don't release utf chars right now, perhaps that should be done
4427 later. Since there is always one reference the garbage collector will
4432 /* Array Operations ***********************************************************/
4434 /* GetArrayLength **************************************************************
4436 Returns the number of elements in the array.
4438 *******************************************************************************/
4440 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4442 java_arrayheader *a;
4444 STATISTICS(jniinvokation());
4446 a = (java_arrayheader *) array;
4452 /* NewObjectArray **************************************************************
4454 Constructs a new array holding objects in class elementClass. All
4455 elements are initially set to initialElement.
4457 *******************************************************************************/
4459 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4460 jclass elementClass, jobject initialElement)
4462 java_objectarray *oa;
4465 STATISTICS(jniinvokation());
4468 exceptions_throw_negativearraysizeexception();
4472 oa = builtin_anewarray(length, elementClass);
4477 /* set all elements to initialElement */
4479 for (i = 0; i < length; i++)
4480 oa->data[i] = initialElement;
4482 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4486 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4489 java_objectarray *oa;
4492 STATISTICS(jniinvokation());
4494 oa = (java_objectarray *) array;
4496 if (index >= oa->header.size) {
4497 exceptions_throw_arrayindexoutofboundsexception();
4501 o = oa->data[index];
4503 return _Jv_JNI_NewLocalRef(env, o);
4507 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4508 jsize index, jobject val)
4510 java_objectarray *oa;
4511 java_objectheader *o;
4513 STATISTICS(jniinvokation());
4515 oa = (java_objectarray *) array;
4516 o = (java_objectheader *) val;
4518 if (index >= oa->header.size) {
4519 exceptions_throw_arrayindexoutofboundsexception();
4523 /* check if the class of value is a subclass of the element class
4526 if (!builtin_canstore(oa, o))
4529 oa->data[index] = val;
4533 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4535 java_booleanarray *ba;
4537 STATISTICS(jniinvokation());
4540 exceptions_throw_negativearraysizeexception();
4544 ba = builtin_newarray_boolean(len);
4546 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4550 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4554 STATISTICS(jniinvokation());
4557 exceptions_throw_negativearraysizeexception();
4561 ba = builtin_newarray_byte(len);
4563 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4567 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4571 STATISTICS(jniinvokation());
4574 exceptions_throw_negativearraysizeexception();
4578 ca = builtin_newarray_char(len);
4580 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4584 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4586 java_shortarray *sa;
4588 STATISTICS(jniinvokation());
4591 exceptions_throw_negativearraysizeexception();
4595 sa = builtin_newarray_short(len);
4597 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4601 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4605 STATISTICS(jniinvokation());
4608 exceptions_throw_negativearraysizeexception();
4612 ia = builtin_newarray_int(len);
4614 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4618 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4622 STATISTICS(jniinvokation());
4625 exceptions_throw_negativearraysizeexception();
4629 la = builtin_newarray_long(len);
4631 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4635 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4637 java_floatarray *fa;
4639 STATISTICS(jniinvokation());
4642 exceptions_throw_negativearraysizeexception();
4646 fa = builtin_newarray_float(len);
4648 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4652 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4654 java_doublearray *da;
4656 STATISTICS(jniinvokation());
4659 exceptions_throw_negativearraysizeexception();
4663 da = builtin_newarray_double(len);
4665 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4669 /* Get<PrimitiveType>ArrayElements *********************************************
4671 A family of functions that returns the body of the primitive array.
4673 *******************************************************************************/
4675 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4678 java_booleanarray *ba;
4680 STATISTICS(jniinvokation());
4682 ba = (java_booleanarray *) array;
4685 *isCopy = JNI_FALSE;
4691 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4696 STATISTICS(jniinvokation());
4698 ba = (java_bytearray *) array;
4701 *isCopy = JNI_FALSE;
4707 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4712 STATISTICS(jniinvokation());
4714 ca = (java_chararray *) array;
4717 *isCopy = JNI_FALSE;
4723 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4726 java_shortarray *sa;
4728 STATISTICS(jniinvokation());
4730 sa = (java_shortarray *) array;
4733 *isCopy = JNI_FALSE;
4739 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4744 STATISTICS(jniinvokation());
4746 ia = (java_intarray *) array;
4749 *isCopy = JNI_FALSE;
4755 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4760 STATISTICS(jniinvokation());
4762 la = (java_longarray *) array;
4765 *isCopy = JNI_FALSE;
4767 /* We cast this one to prevent a compiler warning on 64-bit
4768 systems since GNU Classpath typedef jlong to long long. */
4770 return (jlong *) la->data;
4774 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4777 java_floatarray *fa;
4779 STATISTICS(jniinvokation());
4781 fa = (java_floatarray *) array;
4784 *isCopy = JNI_FALSE;
4790 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4793 java_doublearray *da;
4795 STATISTICS(jniinvokation());
4797 da = (java_doublearray *) array;
4800 *isCopy = JNI_FALSE;
4806 /* Release<PrimitiveType>ArrayElements *****************************************
4808 A family of functions that informs the VM that the native code no
4809 longer needs access to elems. The elems argument is a pointer
4810 derived from array using the corresponding
4811 Get<PrimitiveType>ArrayElements() function. If necessary, this
4812 function copies back all changes made to elems to the original
4815 *******************************************************************************/
4817 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4818 jboolean *elems, jint mode)
4820 java_booleanarray *ba;
4822 STATISTICS(jniinvokation());
4824 ba = (java_booleanarray *) array;
4826 if (elems != ba->data) {
4829 MCOPY(ba->data, elems, u1, ba->header.size);
4832 MCOPY(ba->data, elems, u1, ba->header.size);
4833 /* XXX TWISTI how should it be freed? */
4836 /* XXX TWISTI how should it be freed? */
4843 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4844 jbyte *elems, jint mode)
4848 STATISTICS(jniinvokation());
4850 ba = (java_bytearray *) array;
4852 if (elems != ba->data) {
4855 MCOPY(ba->data, elems, s1, ba->header.size);
4858 MCOPY(ba->data, elems, s1, ba->header.size);
4859 /* XXX TWISTI how should it be freed? */
4862 /* XXX TWISTI how should it be freed? */
4869 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4870 jchar *elems, jint mode)
4874 STATISTICS(jniinvokation());
4876 ca = (java_chararray *) array;
4878 if (elems != ca->data) {
4881 MCOPY(ca->data, elems, u2, ca->header.size);
4884 MCOPY(ca->data, elems, u2, ca->header.size);
4885 /* XXX TWISTI how should it be freed? */
4888 /* XXX TWISTI how should it be freed? */
4895 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4896 jshort *elems, jint mode)
4898 java_shortarray *sa;
4900 STATISTICS(jniinvokation());
4902 sa = (java_shortarray *) array;
4904 if (elems != sa->data) {
4907 MCOPY(sa->data, elems, s2, sa->header.size);
4910 MCOPY(sa->data, elems, s2, sa->header.size);
4911 /* XXX TWISTI how should it be freed? */
4914 /* XXX TWISTI how should it be freed? */
4921 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4926 STATISTICS(jniinvokation());
4928 ia = (java_intarray *) array;
4930 if (elems != ia->data) {
4933 MCOPY(ia->data, elems, s4, ia->header.size);
4936 MCOPY(ia->data, elems, s4, ia->header.size);
4937 /* XXX TWISTI how should it be freed? */
4940 /* XXX TWISTI how should it be freed? */
4947 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4948 jlong *elems, jint mode)
4952 STATISTICS(jniinvokation());
4954 la = (java_longarray *) array;
4956 /* We cast this one to prevent a compiler warning on 64-bit
4957 systems since GNU Classpath typedef jlong to long long. */
4959 if ((s8 *) elems != la->data) {
4962 MCOPY(la->data, elems, s8, la->header.size);
4965 MCOPY(la->data, elems, s8, la->header.size);
4966 /* XXX TWISTI how should it be freed? */
4969 /* XXX TWISTI how should it be freed? */
4976 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4977 jfloat *elems, jint mode)
4979 java_floatarray *fa;
4981 STATISTICS(jniinvokation());
4983 fa = (java_floatarray *) array;
4985 if (elems != fa->data) {
4988 MCOPY(fa->data, elems, float, fa->header.size);
4991 MCOPY(fa->data, elems, float, fa->header.size);
4992 /* XXX TWISTI how should it be freed? */
4995 /* XXX TWISTI how should it be freed? */
5002 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
5003 jdouble *elems, jint mode)
5005 java_doublearray *da;
5007 STATISTICS(jniinvokation());
5009 da = (java_doublearray *) array;
5011 if (elems != da->data) {
5014 MCOPY(da->data, elems, double, da->header.size);
5017 MCOPY(da->data, elems, double, da->header.size);
5018 /* XXX TWISTI how should it be freed? */
5021 /* XXX TWISTI how should it be freed? */
5028 /* Get<PrimitiveType>ArrayRegion **********************************************
5030 A family of functions that copies a region of a primitive array
5033 *******************************************************************************/
5035 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5036 jsize start, jsize len, jboolean *buf)
5038 java_booleanarray *ba;
5040 STATISTICS(jniinvokation());
5042 ba = (java_booleanarray *) array;
5044 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5045 exceptions_throw_arrayindexoutofboundsexception();
5047 MCOPY(buf, &ba->data[start], u1, len);
5051 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5052 jsize len, jbyte *buf)
5056 STATISTICS(jniinvokation());
5058 ba = (java_bytearray *) array;
5060 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5061 exceptions_throw_arrayindexoutofboundsexception();
5063 MCOPY(buf, &ba->data[start], s1, len);
5067 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5068 jsize len, jchar *buf)
5072 STATISTICS(jniinvokation());
5074 ca = (java_chararray *) array;
5076 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5077 exceptions_throw_arrayindexoutofboundsexception();
5079 MCOPY(buf, &ca->data[start], u2, len);
5083 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5084 jsize len, jshort *buf)
5086 java_shortarray *sa;
5088 STATISTICS(jniinvokation());
5090 sa = (java_shortarray *) array;
5092 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5093 exceptions_throw_arrayindexoutofboundsexception();
5095 MCOPY(buf, &sa->data[start], s2, len);
5099 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5100 jsize len, jint *buf)
5104 STATISTICS(jniinvokation());
5106 ia = (java_intarray *) array;
5108 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5109 exceptions_throw_arrayindexoutofboundsexception();
5111 MCOPY(buf, &ia->data[start], s4, len);
5115 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5116 jsize len, jlong *buf)
5120 STATISTICS(jniinvokation());
5122 la = (java_longarray *) array;
5124 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5125 exceptions_throw_arrayindexoutofboundsexception();
5127 MCOPY(buf, &la->data[start], s8, len);
5131 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5132 jsize len, jfloat *buf)
5134 java_floatarray *fa;
5136 STATISTICS(jniinvokation());
5138 fa = (java_floatarray *) array;
5140 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5141 exceptions_throw_arrayindexoutofboundsexception();
5143 MCOPY(buf, &fa->data[start], float, len);
5147 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5148 jsize len, jdouble *buf)
5150 java_doublearray *da;
5152 STATISTICS(jniinvokation());
5154 da = (java_doublearray *) array;
5156 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5157 exceptions_throw_arrayindexoutofboundsexception();
5159 MCOPY(buf, &da->data[start], double, len);
5163 /* Set<PrimitiveType>ArrayRegion **********************************************
5165 A family of functions that copies back a region of a primitive
5166 array from a buffer.
5168 *******************************************************************************/
5170 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5171 jsize start, jsize len, jboolean *buf)
5173 java_booleanarray *ba;
5175 STATISTICS(jniinvokation());
5177 ba = (java_booleanarray *) array;
5179 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5180 exceptions_throw_arrayindexoutofboundsexception();
5182 MCOPY(&ba->data[start], buf, u1, len);
5186 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5187 jsize len, jbyte *buf)
5191 STATISTICS(jniinvokation());
5193 ba = (java_bytearray *) array;
5195 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5196 exceptions_throw_arrayindexoutofboundsexception();
5198 MCOPY(&ba->data[start], buf, s1, len);
5202 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5203 jsize len, jchar *buf)
5207 STATISTICS(jniinvokation());
5209 ca = (java_chararray *) array;
5211 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5212 exceptions_throw_arrayindexoutofboundsexception();
5214 MCOPY(&ca->data[start], buf, u2, len);
5218 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5219 jsize len, jshort *buf)
5221 java_shortarray *sa;
5223 STATISTICS(jniinvokation());
5225 sa = (java_shortarray *) array;
5227 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5228 exceptions_throw_arrayindexoutofboundsexception();
5230 MCOPY(&sa->data[start], buf, s2, len);
5234 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5235 jsize len, jint *buf)
5239 STATISTICS(jniinvokation());
5241 ia = (java_intarray *) array;
5243 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5244 exceptions_throw_arrayindexoutofboundsexception();
5246 MCOPY(&ia->data[start], buf, s4, len);
5250 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5251 jsize len, jlong *buf)
5255 STATISTICS(jniinvokation());
5257 la = (java_longarray *) array;
5259 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5260 exceptions_throw_arrayindexoutofboundsexception();
5262 MCOPY(&la->data[start], buf, s8, len);
5266 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5267 jsize len, jfloat *buf)
5269 java_floatarray *fa;
5271 STATISTICS(jniinvokation());
5273 fa = (java_floatarray *) array;
5275 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5276 exceptions_throw_arrayindexoutofboundsexception();
5278 MCOPY(&fa->data[start], buf, float, len);
5282 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5283 jsize len, jdouble *buf)
5285 java_doublearray *da;
5287 STATISTICS(jniinvokation());
5289 da = (java_doublearray *) array;
5291 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5292 exceptions_throw_arrayindexoutofboundsexception();
5294 MCOPY(&da->data[start], buf, double, len);
5298 /* Registering Native Methods *************************************************/
5300 /* RegisterNatives *************************************************************
5302 Registers native methods with the class specified by the clazz
5303 argument. The methods parameter specifies an array of
5304 JNINativeMethod structures that contain the names, signatures, and
5305 function pointers of the native methods. The nMethods parameter
5306 specifies the number of native methods in the array.
5308 *******************************************************************************/
5310 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5311 const JNINativeMethod *methods, jint nMethods)
5313 STATISTICS(jniinvokation());
5315 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5316 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5317 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5324 /* UnregisterNatives ***********************************************************
5326 Unregisters native methods of a class. The class goes back to the
5327 state before it was linked or registered with its native method
5330 This function should not be used in normal native code. Instead, it
5331 provides special programs a way to reload and relink native
5334 *******************************************************************************/
5336 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5338 STATISTICS(jniinvokation());
5340 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5342 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5348 /* Monitor Operations *********************************************************/
5350 /* MonitorEnter ****************************************************************
5352 Enters the monitor associated with the underlying Java object
5355 *******************************************************************************/
5357 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5359 STATISTICS(jniinvokation());
5362 exceptions_throw_nullpointerexception();
5366 LOCK_MONITOR_ENTER(obj);
5372 /* MonitorExit *****************************************************************
5374 The current thread must be the owner of the monitor associated with
5375 the underlying Java object referred to by obj. The thread
5376 decrements the counter indicating the number of times it has
5377 entered this monitor. If the value of the counter becomes zero, the
5378 current thread releases the monitor.
5380 *******************************************************************************/
5382 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5384 STATISTICS(jniinvokation());
5387 exceptions_throw_nullpointerexception();
5391 LOCK_MONITOR_EXIT(obj);
5397 /* JavaVM Interface ***********************************************************/
5399 /* GetJavaVM *******************************************************************
5401 Returns the Java VM interface (used in the Invocation API)
5402 associated with the current thread. The result is placed at the
5403 location pointed to by the second argument, vm.
5405 *******************************************************************************/
5407 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5409 STATISTICS(jniinvokation());
5411 *vm = (JavaVM *) _Jv_jvm;
5417 /* GetStringRegion *************************************************************
5419 Copies len number of Unicode characters beginning at offset start
5420 to the given buffer buf.
5422 Throws StringIndexOutOfBoundsException on index overflow.
5424 *******************************************************************************/
5426 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5429 java_lang_String *s;
5432 STATISTICS(jniinvokation());
5434 s = (java_lang_String *) str;
5437 if ((start < 0) || (len < 0) || (start > s->count) ||
5438 (start + len > s->count)) {
5439 exceptions_throw_stringindexoutofboundsexception();
5443 MCOPY(buf, &ca->data[start], u2, len);
5447 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5448 jsize len, char *buf)
5450 STATISTICS(jniinvokation());
5452 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5456 /* GetPrimitiveArrayCritical ***************************************************
5458 Obtain a direct pointer to array elements.
5460 *******************************************************************************/
5462 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5468 ba = (java_bytearray *) array;
5470 /* do the same as Kaffe does */
5472 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5478 /* ReleasePrimitiveArrayCritical ***********************************************
5480 No specific documentation.
5482 *******************************************************************************/
5484 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5485 void *carray, jint mode)
5487 STATISTICS(jniinvokation());
5489 /* do the same as Kaffe does */
5491 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5496 /* GetStringCritical ***********************************************************
5498 The semantics of these two functions are similar to the existing
5499 Get/ReleaseStringChars functions.
5501 *******************************************************************************/
5503 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5506 STATISTICS(jniinvokation());
5508 return _Jv_JNI_GetStringChars(env, string, isCopy);
5512 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5513 const jchar *cstring)
5515 STATISTICS(jniinvokation());
5517 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5521 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5523 STATISTICS(jniinvokation());
5525 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5531 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5533 STATISTICS(jniinvokation());
5535 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5539 /* NewGlobalRef ****************************************************************
5541 Creates a new global reference to the object referred to by the obj
5544 *******************************************************************************/
5546 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5548 hashtable_global_ref_entry *gre;
5549 u4 key; /* hashkey */
5550 u4 slot; /* slot in hashtable */
5552 STATISTICS(jniinvokation());
5554 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5556 /* normally addresses are aligned to 4, 8 or 16 bytes */
5558 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5559 slot = key & (hashtable_global_ref->size - 1);
5560 gre = hashtable_global_ref->ptr[slot];
5562 /* search external hash chain for the entry */
5565 if (gre->o == obj) {
5566 /* global object found, increment the reference */
5570 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5575 gre = gre->hashlink; /* next element in external chain */
5578 /* global ref not found, create a new one */
5580 gre = NEW(hashtable_global_ref_entry);
5585 /* insert entry into hashtable */
5587 gre->hashlink = hashtable_global_ref->ptr[slot];
5589 hashtable_global_ref->ptr[slot] = gre;
5591 /* update number of hashtable-entries */
5593 hashtable_global_ref->entries++;
5595 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5601 /* DeleteGlobalRef *************************************************************
5603 Deletes the global reference pointed to by globalRef.
5605 *******************************************************************************/
5607 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5609 hashtable_global_ref_entry *gre;
5610 hashtable_global_ref_entry *prevgre;
5611 u4 key; /* hashkey */
5612 u4 slot; /* slot in hashtable */
5614 STATISTICS(jniinvokation());
5616 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5618 /* normally addresses are aligned to 4, 8 or 16 bytes */
5620 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5621 slot = key & (hashtable_global_ref->size - 1);
5622 gre = hashtable_global_ref->ptr[slot];
5624 /* initialize prevgre */
5628 /* search external hash chain for the entry */
5631 if (gre->o == globalRef) {
5632 /* global object found, decrement the reference count */
5636 /* if reference count is 0, remove the entry */
5638 if (gre->refs == 0) {
5639 /* special handling if it's the first in the chain */
5641 if (prevgre == NULL)
5642 hashtable_global_ref->ptr[slot] = gre->hashlink;
5644 prevgre->hashlink = gre->hashlink;
5646 FREE(gre, hashtable_global_ref_entry);
5649 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5654 prevgre = gre; /* save current pointer for removal */
5655 gre = gre->hashlink; /* next element in external chain */
5658 log_println("JNI-DeleteGlobalRef: global reference not found");
5660 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5664 /* ExceptionCheck **************************************************************
5666 Returns JNI_TRUE when there is a pending exception; otherwise,
5669 *******************************************************************************/
5671 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5673 java_objectheader *o;
5675 STATISTICS(jniinvokation());
5677 o = exceptions_get_exception();
5679 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5683 /* New JNI 1.4 functions ******************************************************/
5685 /* NewDirectByteBuffer *********************************************************
5687 Allocates and returns a direct java.nio.ByteBuffer referring to the
5688 block of memory starting at the memory address address and
5689 extending capacity bytes.
5691 *******************************************************************************/
5693 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5695 #if defined(ENABLE_JAVASE)
5696 java_objectheader *nbuf;
5697 # if SIZEOF_VOID_P == 8
5698 gnu_classpath_Pointer64 *paddress;
5700 gnu_classpath_Pointer32 *paddress;
5703 STATISTICS(jniinvokation());
5705 /* alocate a gnu.classpath.Pointer{32,64} object */
5707 # if SIZEOF_VOID_P == 8
5708 if (!(paddress = (gnu_classpath_Pointer64 *)
5709 builtin_new(class_gnu_classpath_Pointer64)))
5711 if (!(paddress = (gnu_classpath_Pointer32 *)
5712 builtin_new(class_gnu_classpath_Pointer32)))
5716 /* fill gnu.classpath.Pointer{32,64} with address */
5718 paddress->data = (ptrint) address;
5720 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5722 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5723 (jmethodID) dbbirw_init, NULL, paddress,
5724 (jint) capacity, (jint) capacity, (jint) 0);
5726 /* add local reference and return the value */
5728 return _Jv_JNI_NewLocalRef(env, nbuf);
5730 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5732 /* keep compiler happy */
5739 /* GetDirectBufferAddress ******************************************************
5741 Fetches and returns the starting address of the memory region
5742 referenced by the given direct java.nio.Buffer.
5744 *******************************************************************************/
5746 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5748 #if defined(ENABLE_JAVASE)
5749 java_nio_DirectByteBufferImpl *nbuf;
5750 # if SIZEOF_VOID_P == 8
5751 gnu_classpath_Pointer64 *address;
5753 gnu_classpath_Pointer32 *address;
5756 STATISTICS(jniinvokation());
5758 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5761 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5763 # if SIZEOF_VOID_P == 8
5764 address = (gnu_classpath_Pointer64 *) nbuf->address;
5766 address = (gnu_classpath_Pointer32 *) nbuf->address;
5769 if (address == NULL)
5772 return (void *) address->data;
5774 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5776 /* keep compiler happy */
5783 /* GetDirectBufferCapacity *****************************************************
5785 Fetches and returns the capacity in bytes of the memory region
5786 referenced by the given direct java.nio.Buffer.
5788 *******************************************************************************/
5790 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5792 #if defined(ENABLE_JAVASE)
5793 java_nio_Buffer *nbuf;
5795 STATISTICS(jniinvokation());
5797 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5800 nbuf = (java_nio_Buffer *) buf;
5802 return (jlong) nbuf->cap;
5804 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5806 /* keep compiler happy */
5813 /* DestroyJavaVM ***************************************************************
5815 Unloads a Java VM and reclaims its resources. Only the main thread
5816 can unload the VM. The system waits until the main thread is only
5817 remaining user thread before it destroys the VM.
5819 *******************************************************************************/
5821 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5825 STATISTICS(jniinvokation());
5827 status = vm_destroy(vm);
5833 /* AttachCurrentThread *********************************************************
5835 Attaches the current thread to a Java VM. Returns a JNI interface
5836 pointer in the JNIEnv argument.
5838 Trying to attach a thread that is already attached is a no-op.
5840 A native thread cannot be attached simultaneously to two Java VMs.
5842 When a thread is attached to the VM, the context class loader is
5843 the bootstrap loader.
5845 *******************************************************************************/
5847 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5849 JavaVMAttachArgs *vm_aargs;
5851 #if defined(ENABLE_THREADS)
5852 if (threads_get_current_threadobject() == NULL) {
5853 vm_aargs = (JavaVMAttachArgs *) thr_args;
5855 if (vm_aargs != NULL) {
5856 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5857 (vm_aargs->version != JNI_VERSION_1_4))
5858 return JNI_EVERSION;
5861 if (!threads_attach_current_thread(vm_aargs, false))
5864 if (!jni_init_localref_table())
5875 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5877 STATISTICS(jniinvokation());
5879 return jni_attach_current_thread(p_env, thr_args, false);
5883 /* DetachCurrentThread *********************************************************
5885 Detaches the current thread from a Java VM. All Java monitors held
5886 by this thread are released. All Java threads waiting for this
5887 thread to die are notified.
5889 In JDK 1.1, the main thread cannot be detached from the VM. It must
5890 call DestroyJavaVM to unload the entire VM.
5892 In the JDK, the main thread can be detached from the VM.
5894 The main thread, which is the thread that created the Java VM,
5895 cannot be detached from the VM. Instead, the main thread must call
5896 JNI_DestroyJavaVM() to unload the entire VM.
5898 *******************************************************************************/
5900 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5902 #if defined(ENABLE_THREADS)
5903 threadobject *thread;
5905 STATISTICS(jniinvokation());
5907 thread = threads_get_current_threadobject();
5912 if (!threads_detach_thread(thread))
5920 /* GetEnv **********************************************************************
5922 If the current thread is not attached to the VM, sets *env to NULL,
5923 and returns JNI_EDETACHED. If the specified version is not
5924 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5925 sets *env to the appropriate interface, and returns JNI_OK.
5927 *******************************************************************************/
5929 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5931 STATISTICS(jniinvokation());
5933 #if defined(ENABLE_THREADS)
5934 if (threads_get_current_threadobject() == NULL) {
5937 return JNI_EDETACHED;
5941 /* check the JNI version */
5944 case JNI_VERSION_1_1:
5945 case JNI_VERSION_1_2:
5946 case JNI_VERSION_1_4:
5954 #if defined(ENABLE_JVMTI)
5955 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5956 == JVMTI_VERSION_INTERFACE_JVMTI) {
5958 *env = (void *) jvmti_new_environment();
5967 return JNI_EVERSION;
5971 /* AttachCurrentThreadAsDaemon *************************************************
5973 Same semantics as AttachCurrentThread, but the newly-created
5974 java.lang.Thread instance is a daemon.
5976 If the thread has already been attached via either
5977 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5978 simply sets the value pointed to by penv to the JNIEnv of the
5979 current thread. In this case neither AttachCurrentThread nor this
5980 routine have any effect on the daemon status of the thread.
5982 *******************************************************************************/
5984 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5986 STATISTICS(jniinvokation());
5988 return jni_attach_current_thread(penv, args, true);
5992 /* JNI invocation table *******************************************************/
5994 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5999 _Jv_JNI_DestroyJavaVM,
6000 _Jv_JNI_AttachCurrentThread,
6001 _Jv_JNI_DetachCurrentThread,
6003 _Jv_JNI_AttachCurrentThreadAsDaemon
6007 /* JNI function table *********************************************************/
6009 struct JNINativeInterface _Jv_JNINativeInterface = {
6016 _Jv_JNI_DefineClass,
6018 _Jv_JNI_FromReflectedMethod,
6019 _Jv_JNI_FromReflectedField,
6020 _Jv_JNI_ToReflectedMethod,
6021 _Jv_JNI_GetSuperclass,
6022 _Jv_JNI_IsAssignableFrom,
6023 _Jv_JNI_ToReflectedField,
6027 _Jv_JNI_ExceptionOccurred,
6028 _Jv_JNI_ExceptionDescribe,
6029 _Jv_JNI_ExceptionClear,
6031 _Jv_JNI_PushLocalFrame,
6032 _Jv_JNI_PopLocalFrame,
6034 _Jv_JNI_NewGlobalRef,
6035 _Jv_JNI_DeleteGlobalRef,
6036 _Jv_JNI_DeleteLocalRef,
6037 _Jv_JNI_IsSameObject,
6038 _Jv_JNI_NewLocalRef,
6039 _Jv_JNI_EnsureLocalCapacity,
6041 _Jv_JNI_AllocObject,
6046 _Jv_JNI_GetObjectClass,
6047 _Jv_JNI_IsInstanceOf,
6049 _Jv_JNI_GetMethodID,
6051 _Jv_JNI_CallObjectMethod,
6052 _Jv_JNI_CallObjectMethodV,
6053 _Jv_JNI_CallObjectMethodA,
6054 _Jv_JNI_CallBooleanMethod,
6055 _Jv_JNI_CallBooleanMethodV,
6056 _Jv_JNI_CallBooleanMethodA,
6057 _Jv_JNI_CallByteMethod,
6058 _Jv_JNI_CallByteMethodV,
6059 _Jv_JNI_CallByteMethodA,
6060 _Jv_JNI_CallCharMethod,
6061 _Jv_JNI_CallCharMethodV,
6062 _Jv_JNI_CallCharMethodA,
6063 _Jv_JNI_CallShortMethod,
6064 _Jv_JNI_CallShortMethodV,
6065 _Jv_JNI_CallShortMethodA,
6066 _Jv_JNI_CallIntMethod,
6067 _Jv_JNI_CallIntMethodV,
6068 _Jv_JNI_CallIntMethodA,
6069 _Jv_JNI_CallLongMethod,
6070 _Jv_JNI_CallLongMethodV,
6071 _Jv_JNI_CallLongMethodA,
6072 _Jv_JNI_CallFloatMethod,
6073 _Jv_JNI_CallFloatMethodV,
6074 _Jv_JNI_CallFloatMethodA,
6075 _Jv_JNI_CallDoubleMethod,
6076 _Jv_JNI_CallDoubleMethodV,
6077 _Jv_JNI_CallDoubleMethodA,
6078 _Jv_JNI_CallVoidMethod,
6079 _Jv_JNI_CallVoidMethodV,
6080 _Jv_JNI_CallVoidMethodA,
6082 _Jv_JNI_CallNonvirtualObjectMethod,
6083 _Jv_JNI_CallNonvirtualObjectMethodV,
6084 _Jv_JNI_CallNonvirtualObjectMethodA,
6085 _Jv_JNI_CallNonvirtualBooleanMethod,
6086 _Jv_JNI_CallNonvirtualBooleanMethodV,
6087 _Jv_JNI_CallNonvirtualBooleanMethodA,
6088 _Jv_JNI_CallNonvirtualByteMethod,
6089 _Jv_JNI_CallNonvirtualByteMethodV,
6090 _Jv_JNI_CallNonvirtualByteMethodA,
6091 _Jv_JNI_CallNonvirtualCharMethod,
6092 _Jv_JNI_CallNonvirtualCharMethodV,
6093 _Jv_JNI_CallNonvirtualCharMethodA,
6094 _Jv_JNI_CallNonvirtualShortMethod,
6095 _Jv_JNI_CallNonvirtualShortMethodV,
6096 _Jv_JNI_CallNonvirtualShortMethodA,
6097 _Jv_JNI_CallNonvirtualIntMethod,
6098 _Jv_JNI_CallNonvirtualIntMethodV,
6099 _Jv_JNI_CallNonvirtualIntMethodA,
6100 _Jv_JNI_CallNonvirtualLongMethod,
6101 _Jv_JNI_CallNonvirtualLongMethodV,
6102 _Jv_JNI_CallNonvirtualLongMethodA,
6103 _Jv_JNI_CallNonvirtualFloatMethod,
6104 _Jv_JNI_CallNonvirtualFloatMethodV,
6105 _Jv_JNI_CallNonvirtualFloatMethodA,
6106 _Jv_JNI_CallNonvirtualDoubleMethod,
6107 _Jv_JNI_CallNonvirtualDoubleMethodV,
6108 _Jv_JNI_CallNonvirtualDoubleMethodA,
6109 _Jv_JNI_CallNonvirtualVoidMethod,
6110 _Jv_JNI_CallNonvirtualVoidMethodV,
6111 _Jv_JNI_CallNonvirtualVoidMethodA,
6115 _Jv_JNI_GetObjectField,
6116 _Jv_JNI_GetBooleanField,
6117 _Jv_JNI_GetByteField,
6118 _Jv_JNI_GetCharField,
6119 _Jv_JNI_GetShortField,
6120 _Jv_JNI_GetIntField,
6121 _Jv_JNI_GetLongField,
6122 _Jv_JNI_GetFloatField,
6123 _Jv_JNI_GetDoubleField,
6124 _Jv_JNI_SetObjectField,
6125 _Jv_JNI_SetBooleanField,
6126 _Jv_JNI_SetByteField,
6127 _Jv_JNI_SetCharField,
6128 _Jv_JNI_SetShortField,
6129 _Jv_JNI_SetIntField,
6130 _Jv_JNI_SetLongField,
6131 _Jv_JNI_SetFloatField,
6132 _Jv_JNI_SetDoubleField,
6134 _Jv_JNI_GetStaticMethodID,
6136 _Jv_JNI_CallStaticObjectMethod,
6137 _Jv_JNI_CallStaticObjectMethodV,
6138 _Jv_JNI_CallStaticObjectMethodA,
6139 _Jv_JNI_CallStaticBooleanMethod,
6140 _Jv_JNI_CallStaticBooleanMethodV,
6141 _Jv_JNI_CallStaticBooleanMethodA,
6142 _Jv_JNI_CallStaticByteMethod,
6143 _Jv_JNI_CallStaticByteMethodV,
6144 _Jv_JNI_CallStaticByteMethodA,
6145 _Jv_JNI_CallStaticCharMethod,
6146 _Jv_JNI_CallStaticCharMethodV,
6147 _Jv_JNI_CallStaticCharMethodA,
6148 _Jv_JNI_CallStaticShortMethod,
6149 _Jv_JNI_CallStaticShortMethodV,
6150 _Jv_JNI_CallStaticShortMethodA,
6151 _Jv_JNI_CallStaticIntMethod,
6152 _Jv_JNI_CallStaticIntMethodV,
6153 _Jv_JNI_CallStaticIntMethodA,
6154 _Jv_JNI_CallStaticLongMethod,
6155 _Jv_JNI_CallStaticLongMethodV,
6156 _Jv_JNI_CallStaticLongMethodA,
6157 _Jv_JNI_CallStaticFloatMethod,
6158 _Jv_JNI_CallStaticFloatMethodV,
6159 _Jv_JNI_CallStaticFloatMethodA,
6160 _Jv_JNI_CallStaticDoubleMethod,
6161 _Jv_JNI_CallStaticDoubleMethodV,
6162 _Jv_JNI_CallStaticDoubleMethodA,
6163 _Jv_JNI_CallStaticVoidMethod,
6164 _Jv_JNI_CallStaticVoidMethodV,
6165 _Jv_JNI_CallStaticVoidMethodA,
6167 _Jv_JNI_GetStaticFieldID,
6169 _Jv_JNI_GetStaticObjectField,
6170 _Jv_JNI_GetStaticBooleanField,
6171 _Jv_JNI_GetStaticByteField,
6172 _Jv_JNI_GetStaticCharField,
6173 _Jv_JNI_GetStaticShortField,
6174 _Jv_JNI_GetStaticIntField,
6175 _Jv_JNI_GetStaticLongField,
6176 _Jv_JNI_GetStaticFloatField,
6177 _Jv_JNI_GetStaticDoubleField,
6178 _Jv_JNI_SetStaticObjectField,
6179 _Jv_JNI_SetStaticBooleanField,
6180 _Jv_JNI_SetStaticByteField,
6181 _Jv_JNI_SetStaticCharField,
6182 _Jv_JNI_SetStaticShortField,
6183 _Jv_JNI_SetStaticIntField,
6184 _Jv_JNI_SetStaticLongField,
6185 _Jv_JNI_SetStaticFloatField,
6186 _Jv_JNI_SetStaticDoubleField,
6189 _Jv_JNI_GetStringLength,
6190 _Jv_JNI_GetStringChars,
6191 _Jv_JNI_ReleaseStringChars,
6193 _Jv_JNI_NewStringUTF,
6194 _Jv_JNI_GetStringUTFLength,
6195 _Jv_JNI_GetStringUTFChars,
6196 _Jv_JNI_ReleaseStringUTFChars,
6198 _Jv_JNI_GetArrayLength,
6200 _Jv_JNI_NewObjectArray,
6201 _Jv_JNI_GetObjectArrayElement,
6202 _Jv_JNI_SetObjectArrayElement,
6204 _Jv_JNI_NewBooleanArray,
6205 _Jv_JNI_NewByteArray,
6206 _Jv_JNI_NewCharArray,
6207 _Jv_JNI_NewShortArray,
6208 _Jv_JNI_NewIntArray,
6209 _Jv_JNI_NewLongArray,
6210 _Jv_JNI_NewFloatArray,
6211 _Jv_JNI_NewDoubleArray,
6213 _Jv_JNI_GetBooleanArrayElements,
6214 _Jv_JNI_GetByteArrayElements,
6215 _Jv_JNI_GetCharArrayElements,
6216 _Jv_JNI_GetShortArrayElements,
6217 _Jv_JNI_GetIntArrayElements,
6218 _Jv_JNI_GetLongArrayElements,
6219 _Jv_JNI_GetFloatArrayElements,
6220 _Jv_JNI_GetDoubleArrayElements,
6222 _Jv_JNI_ReleaseBooleanArrayElements,
6223 _Jv_JNI_ReleaseByteArrayElements,
6224 _Jv_JNI_ReleaseCharArrayElements,
6225 _Jv_JNI_ReleaseShortArrayElements,
6226 _Jv_JNI_ReleaseIntArrayElements,
6227 _Jv_JNI_ReleaseLongArrayElements,
6228 _Jv_JNI_ReleaseFloatArrayElements,
6229 _Jv_JNI_ReleaseDoubleArrayElements,
6231 _Jv_JNI_GetBooleanArrayRegion,
6232 _Jv_JNI_GetByteArrayRegion,
6233 _Jv_JNI_GetCharArrayRegion,
6234 _Jv_JNI_GetShortArrayRegion,
6235 _Jv_JNI_GetIntArrayRegion,
6236 _Jv_JNI_GetLongArrayRegion,
6237 _Jv_JNI_GetFloatArrayRegion,
6238 _Jv_JNI_GetDoubleArrayRegion,
6239 _Jv_JNI_SetBooleanArrayRegion,
6240 _Jv_JNI_SetByteArrayRegion,
6241 _Jv_JNI_SetCharArrayRegion,
6242 _Jv_JNI_SetShortArrayRegion,
6243 _Jv_JNI_SetIntArrayRegion,
6244 _Jv_JNI_SetLongArrayRegion,
6245 _Jv_JNI_SetFloatArrayRegion,
6246 _Jv_JNI_SetDoubleArrayRegion,
6248 _Jv_JNI_RegisterNatives,
6249 _Jv_JNI_UnregisterNatives,
6251 _Jv_JNI_MonitorEnter,
6252 _Jv_JNI_MonitorExit,
6256 /* new JNI 1.2 functions */
6258 _Jv_JNI_GetStringRegion,
6259 _Jv_JNI_GetStringUTFRegion,
6261 _Jv_JNI_GetPrimitiveArrayCritical,
6262 _Jv_JNI_ReleasePrimitiveArrayCritical,
6264 _Jv_JNI_GetStringCritical,
6265 _Jv_JNI_ReleaseStringCritical,
6267 _Jv_JNI_NewWeakGlobalRef,
6268 _Jv_JNI_DeleteWeakGlobalRef,
6270 _Jv_JNI_ExceptionCheck,
6272 /* new JNI 1.4 functions */
6274 _Jv_JNI_NewDirectByteBuffer,
6275 _Jv_JNI_GetDirectBufferAddress,
6276 _Jv_JNI_GetDirectBufferCapacity
6280 /* Invocation API Functions ***************************************************/
6282 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6284 Returns a default configuration for the Java VM.
6286 *******************************************************************************/
6288 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6290 JavaVMInitArgs *_vm_args;
6292 _vm_args = (JavaVMInitArgs *) vm_args;
6294 /* GNU classpath currently supports JNI 1.2 */
6296 switch (_vm_args->version) {
6297 case JNI_VERSION_1_1:
6298 _vm_args->version = JNI_VERSION_1_1;
6301 case JNI_VERSION_1_2:
6302 case JNI_VERSION_1_4:
6303 _vm_args->ignoreUnrecognized = JNI_FALSE;
6304 _vm_args->options = NULL;
6305 _vm_args->nOptions = 0;
6316 /* JNI_GetCreatedJavaVMs *******************************************************
6318 Returns all Java VMs that have been created. Pointers to VMs are written in
6319 the buffer vmBuf in the order they are created. At most bufLen number of
6320 entries will be written. The total number of created VMs is returned in
6323 *******************************************************************************/
6325 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6327 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6333 /* JNI_CreateJavaVM ************************************************************
6335 Loads and initializes a Java VM. The current thread becomes the main thread.
6336 Sets the env argument to the JNI interface pointer of the main thread.
6338 *******************************************************************************/
6340 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6342 /* actually create the JVM */
6344 if (!vm_createjvm(p_vm, p_env, vm_args))
6352 * These are local overrides for various environment variables in Emacs.
6353 * Please do not remove this and leave it at the end of the file, where
6354 * Emacs will automagically detect them.
6355 * ---------------------------------------------------------------------
6358 * indent-tabs-mode: t
6362 * vim:noexpandtab:sw=4:ts=4: