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 8074 2007-06-13 22:27: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__)
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)
1006 java_objectheader *ro;
1009 java_objectheader *xptr;
1014 exceptions_throw_nullpointerexception();
1018 argcount = m->parseddesc->paramcount;
1019 paramcount = argcount;
1021 /* if method is non-static, remove the `this' pointer */
1023 if (!(m->flags & ACC_STATIC))
1026 /* For instance methods the object has to be an instance of the
1027 class the method belongs to. For static methods the obj
1028 parameter is ignored. */
1030 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
1031 exceptions_throw_illegalargumentexception();
1035 /* check if we got the right number of arguments */
1037 if (((params == NULL) && (paramcount != 0)) ||
1038 (params && (params->header.size != paramcount)))
1040 exceptions_throw_illegalargumentexception();
1044 /* for instance methods we need an object */
1046 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
1047 /* XXX not sure if that is the correct exception */
1048 exceptions_throw_nullpointerexception();
1052 /* for static methods, zero object to make subsequent code simpler */
1053 if (m->flags & ACC_STATIC)
1057 /* for instance methods we must do a vftbl lookup */
1058 resm = method_vftbl_lookup(o->vftbl, m);
1061 /* for static methods, just for convenience */
1065 /* mark start of dump memory area */
1067 dumpsize = dump_size();
1069 /* fill the argument array from a object-array */
1071 array = vm_array_from_objectarray(resm, o, params);
1073 if (array == NULL) {
1074 /* release dump area */
1076 dump_release(dumpsize);
1081 switch (resm->parseddesc->returntype.decltype) {
1083 (void) vm_call_array(resm, array);
1088 case PRIMITIVETYPE_BOOLEAN: {
1090 java_lang_Boolean *bo;
1092 i = vm_call_int_array(resm, array);
1094 ro = builtin_new(class_java_lang_Boolean);
1096 /* setting the value of the object direct */
1098 bo = (java_lang_Boolean *) ro;
1103 case PRIMITIVETYPE_BYTE: {
1107 i = vm_call_int_array(resm, array);
1109 ro = builtin_new(class_java_lang_Byte);
1111 /* setting the value of the object direct */
1113 bo = (java_lang_Byte *) ro;
1118 case PRIMITIVETYPE_CHAR: {
1120 java_lang_Character *co;
1122 i = vm_call_int_array(resm, array);
1124 ro = builtin_new(class_java_lang_Character);
1126 /* setting the value of the object direct */
1128 co = (java_lang_Character *) ro;
1133 case PRIMITIVETYPE_SHORT: {
1135 java_lang_Short *so;
1137 i = vm_call_int_array(resm, array);
1139 ro = builtin_new(class_java_lang_Short);
1141 /* setting the value of the object direct */
1143 so = (java_lang_Short *) ro;
1148 case PRIMITIVETYPE_INT: {
1150 java_lang_Integer *io;
1152 i = vm_call_int_array(resm, array);
1154 ro = builtin_new(class_java_lang_Integer);
1156 /* setting the value of the object direct */
1158 io = (java_lang_Integer *) ro;
1163 case PRIMITIVETYPE_LONG: {
1167 l = vm_call_long_array(resm, array);
1169 ro = builtin_new(class_java_lang_Long);
1171 /* setting the value of the object direct */
1173 lo = (java_lang_Long *) ro;
1178 case PRIMITIVETYPE_FLOAT: {
1180 java_lang_Float *fo;
1182 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1184 ro = builtin_new(class_java_lang_Float);
1186 /* setting the value of the object direct */
1188 fo = (java_lang_Float *) ro;
1193 case PRIMITIVETYPE_DOUBLE: {
1195 java_lang_Double *_do;
1197 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1199 ro = builtin_new(class_java_lang_Double);
1201 /* setting the value of the object direct */
1203 _do = (java_lang_Double *) ro;
1209 ro = vm_call_array(resm, array);
1213 /* if this happens the exception has already been set by
1214 fill_callblock_from_objectarray */
1216 /* release dump area */
1218 dump_release(dumpsize);
1223 xptr = exceptions_get_exception();
1226 /* clear exception pointer, we are calling JIT code again */
1228 exceptions_clear_exception();
1230 exceptions_throw_invocationtargetexception(xptr);
1233 /* release dump area */
1235 dump_release(dumpsize);
1242 /* GetVersion ******************************************************************
1244 Returns the major version number in the higher 16 bits and the
1245 minor version number in the lower 16 bits.
1247 *******************************************************************************/
1249 jint _Jv_JNI_GetVersion(JNIEnv *env)
1251 STATISTICS(jniinvokation());
1253 /* we support JNI 1.4 */
1255 return JNI_VERSION_1_4;
1259 /* Class Operations ***********************************************************/
1261 /* DefineClass *****************************************************************
1263 Loads a class from a buffer of raw class data. The buffer
1264 containing the raw class data is not referenced by the VM after the
1265 DefineClass call returns, and it may be discarded if desired.
1267 *******************************************************************************/
1269 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1270 const jbyte *buf, jsize bufLen)
1272 #if defined(ENABLE_JAVASE)
1273 java_lang_ClassLoader *cl;
1274 java_lang_String *s;
1278 STATISTICS(jniinvokation());
1280 cl = (java_lang_ClassLoader *) loader;
1281 s = (java_lang_String *) javastring_new_from_utf_string(name);
1282 ba = (java_bytearray *) buf;
1284 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1287 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1289 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1291 /* keep compiler happy */
1298 /* FindClass *******************************************************************
1300 This function loads a locally-defined class. It searches the
1301 directories and zip files specified by the CLASSPATH environment
1302 variable for the class with the specified name.
1304 *******************************************************************************/
1306 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1308 #if defined(ENABLE_JAVASE)
1313 STATISTICS(jniinvokation());
1315 u = utf_new_char_classname((char *) name);
1317 /* Check stacktrace for classloader, if one found use it,
1318 otherwise use the system classloader. */
1320 /* Quote from the JNI documentation:
1322 In the Java 2 Platform, FindClass locates the class loader
1323 associated with the current native method. If the native code
1324 belongs to a system class, no class loader will be
1325 involved. Otherwise, the proper class loader will be invoked to
1326 load and link the named class. When FindClass is called through
1327 the Invocation Interface, there is no current native method or
1328 its associated class loader. In that case, the result of
1329 ClassLoader.getBaseClassLoader is used." */
1331 cc = stacktrace_getCurrentClass();
1334 c = load_class_from_sysloader(u);
1336 c = load_class_from_classloader(u, cc->classloader);
1344 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1346 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1348 /* keep compiler happy */
1355 /* GetSuperclass ***************************************************************
1357 If clazz represents any class other than the class Object, then
1358 this function returns the object that represents the superclass of
1359 the class specified by clazz.
1361 *******************************************************************************/
1363 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1367 STATISTICS(jniinvokation());
1369 c = ((classinfo *) sub)->super.cls;
1374 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1378 /* IsAssignableFrom ************************************************************
1380 Determines whether an object of sub can be safely cast to sup.
1382 *******************************************************************************/
1384 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1386 java_lang_Class *csup;
1387 java_lang_Class *csub;
1389 csup = (java_lang_Class *) sup;
1390 csub = (java_lang_Class *) sub;
1392 STATISTICS(jniinvokation());
1394 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1398 /* Throw ***********************************************************************
1400 Causes a java.lang.Throwable object to be thrown.
1402 *******************************************************************************/
1404 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1406 java_objectheader *o;
1408 STATISTICS(jniinvokation());
1410 o = (java_objectheader *) obj;
1412 exceptions_set_exception(o);
1418 /* ThrowNew ********************************************************************
1420 Constructs an exception object from the specified class with the
1421 message specified by message and causes that exception to be
1424 *******************************************************************************/
1426 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1429 java_objectheader *o;
1430 java_objectheader *s;
1432 STATISTICS(jniinvokation());
1434 c = (classinfo *) clazz;
1435 s = javastring_new_from_utf_string(msg);
1437 /* instantiate exception object */
1439 o = native_new_and_init_string(c, s);
1444 exceptions_set_exception(o);
1450 /* ExceptionOccurred ***********************************************************
1452 Determines if an exception is being thrown. The exception stays
1453 being thrown until either the native code calls ExceptionClear(),
1454 or the Java code handles the exception.
1456 *******************************************************************************/
1458 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1460 java_objectheader *o;
1462 STATISTICS(jniinvokation());
1464 o = exceptions_get_exception();
1466 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1470 /* ExceptionDescribe ***********************************************************
1472 Prints an exception and a backtrace of the stack to a system
1473 error-reporting channel, such as stderr. This is a convenience
1474 routine provided for debugging.
1476 *******************************************************************************/
1478 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1480 java_objectheader *o;
1483 STATISTICS(jniinvokation());
1485 o = exceptions_get_exception();
1488 /* clear exception, because we are calling jit code again */
1490 exceptions_clear_exception();
1492 /* get printStackTrace method from exception class */
1494 m = class_resolveclassmethod(o->vftbl->class,
1495 utf_printStackTrace,
1501 /* XXX what should we do? */
1504 /* print the stacktrace */
1506 (void) vm_call_method(m, o);
1511 /* ExceptionClear **************************************************************
1513 Clears any exception that is currently being thrown. If no
1514 exception is currently being thrown, this routine has no effect.
1516 *******************************************************************************/
1518 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1520 STATISTICS(jniinvokation());
1522 exceptions_clear_exception();
1526 /* FatalError ******************************************************************
1528 Raises a fatal error and does not expect the VM to recover. This
1529 function does not return.
1531 *******************************************************************************/
1533 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1535 STATISTICS(jniinvokation());
1537 /* this seems to be the best way */
1539 vm_abort("JNI Fatal error: %s", msg);
1543 /* PushLocalFrame **************************************************************
1545 Creates a new local reference frame, in which at least a given
1546 number of local references can be created.
1548 *******************************************************************************/
1550 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1553 localref_table *lrt;
1554 localref_table *nlrt;
1556 STATISTICS(jniinvokation());
1561 /* Allocate new local reference table on Java heap. Calculate the
1562 additional memory we have to allocate. */
1564 if (capacity > LOCALREFTABLE_CAPACITY)
1565 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1569 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1574 /* get current local reference table from thread */
1576 lrt = LOCALREFTABLE;
1578 /* Set up the new local reference table and add it to the local
1581 nlrt->capacity = capacity;
1583 nlrt->localframes = lrt->localframes + 1;
1586 /* store new local reference table in thread */
1588 LOCALREFTABLE = nlrt;
1594 /* PopLocalFrame ***************************************************************
1596 Pops off the current local reference frame, frees all the local
1597 references, and returns a local reference in the previous local
1598 reference frame for the given result object.
1600 *******************************************************************************/
1602 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1604 localref_table *lrt;
1605 localref_table *plrt;
1608 STATISTICS(jniinvokation());
1610 /* get current local reference table from thread */
1612 lrt = LOCALREFTABLE;
1614 localframes = lrt->localframes;
1616 /* Don't delete the top local frame, as this one is allocated in
1617 the native stub on the stack and is freed automagically on
1620 if (localframes == 1)
1621 return _Jv_JNI_NewLocalRef(env, result);
1623 /* release all current local frames */
1625 for (; localframes >= 1; localframes--) {
1626 /* get previous frame */
1630 /* clear all reference entries */
1632 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1636 /* set new local references table */
1641 /* store new local reference table in thread */
1643 LOCALREFTABLE = lrt;
1645 /* add local reference and return the value */
1647 return _Jv_JNI_NewLocalRef(env, result);
1651 /* DeleteLocalRef **************************************************************
1653 Deletes the local reference pointed to by localRef.
1655 *******************************************************************************/
1657 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1659 java_objectheader *o;
1660 localref_table *lrt;
1663 STATISTICS(jniinvokation());
1665 o = (java_objectheader *) localRef;
1667 /* get local reference table (thread specific) */
1669 lrt = LOCALREFTABLE;
1671 /* go through all local frames */
1673 for (; lrt != NULL; lrt = lrt->prev) {
1675 /* and try to remove the reference */
1677 for (i = 0; i < lrt->capacity; i++) {
1678 if (lrt->refs[i] == o) {
1679 lrt->refs[i] = NULL;
1687 /* this should not happen */
1689 /* if (opt_checkjni) */
1690 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1691 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1695 /* IsSameObject ****************************************************************
1697 Tests whether two references refer to the same Java object.
1699 *******************************************************************************/
1701 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1703 STATISTICS(jniinvokation());
1712 /* NewLocalRef *****************************************************************
1714 Creates a new local reference that refers to the same object as ref.
1716 *******************************************************************************/
1718 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1720 localref_table *lrt;
1723 STATISTICS(jniinvokation());
1728 /* get local reference table (thread specific) */
1730 lrt = LOCALREFTABLE;
1732 /* Check if we have space for the requested reference? No,
1733 allocate a new frame. This is actually not what the spec says,
1734 but for compatibility reasons... */
1736 if (lrt->used == lrt->capacity) {
1737 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1740 /* get the new local reference table */
1742 lrt = LOCALREFTABLE;
1745 /* insert the reference */
1747 for (i = 0; i < lrt->capacity; i++) {
1748 if (lrt->refs[i] == NULL) {
1749 lrt->refs[i] = (java_objectheader *) ref;
1756 /* should not happen, just to be sure */
1760 /* keep compiler happy */
1766 /* EnsureLocalCapacity *********************************************************
1768 Ensures that at least a given number of local references can be
1769 created in the current thread
1771 *******************************************************************************/
1773 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1775 localref_table *lrt;
1777 STATISTICS(jniinvokation());
1779 /* get local reference table (thread specific) */
1781 lrt = LOCALREFTABLE;
1783 /* check if capacity elements are available in the local references table */
1785 if ((lrt->used + capacity) > lrt->capacity)
1786 return _Jv_JNI_PushLocalFrame(env, capacity);
1792 /* AllocObject *****************************************************************
1794 Allocates a new Java object without invoking any of the
1795 constructors for the object. Returns a reference to the object.
1797 *******************************************************************************/
1799 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1802 java_objectheader *o;
1804 STATISTICS(jniinvokation());
1806 c = (classinfo *) clazz;
1808 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1809 exceptions_throw_instantiationexception(c);
1815 return _Jv_JNI_NewLocalRef(env, o);
1819 /* NewObject *******************************************************************
1821 Programmers place all arguments that are to be passed to the
1822 constructor immediately following the methodID
1823 argument. NewObject() accepts these arguments and passes them to
1824 the Java method that the programmer wishes to invoke.
1826 *******************************************************************************/
1828 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1830 java_objectheader *o;
1834 STATISTICS(jniinvokation());
1836 m = (methodinfo *) methodID;
1840 o = builtin_new(clazz);
1845 /* call constructor */
1847 va_start(ap, methodID);
1848 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1851 return _Jv_JNI_NewLocalRef(env, o);
1855 /* NewObjectV ******************************************************************
1857 Programmers place all arguments that are to be passed to the
1858 constructor in an args argument of type va_list that immediately
1859 follows the methodID argument. NewObjectV() accepts these
1860 arguments, and, in turn, passes them to the Java method that the
1861 programmer wishes to invoke.
1863 *******************************************************************************/
1865 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1868 java_objectheader *o;
1871 STATISTICS(jniinvokation());
1873 m = (methodinfo *) methodID;
1877 o = builtin_new(clazz);
1882 /* call constructor */
1884 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1886 return _Jv_JNI_NewLocalRef(env, o);
1890 /* NewObjectA *****************************************************************
1892 Programmers place all arguments that are to be passed to the
1893 constructor in an args array of jvalues that immediately follows
1894 the methodID argument. NewObjectA() accepts the arguments in this
1895 array, and, in turn, passes them to the Java method that the
1896 programmer wishes to invoke.
1898 *******************************************************************************/
1900 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1903 java_objectheader *o;
1906 STATISTICS(jniinvokation());
1908 m = (methodinfo *) methodID;
1912 o = builtin_new(clazz);
1917 /* call constructor */
1919 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1921 return _Jv_JNI_NewLocalRef(env, o);
1925 /* GetObjectClass **************************************************************
1927 Returns the class of an object.
1929 *******************************************************************************/
1931 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1933 java_objectheader *o;
1936 STATISTICS(jniinvokation());
1938 o = (java_objectheader *) obj;
1940 if ((o == NULL) || (o->vftbl == NULL))
1943 c = o->vftbl->class;
1945 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1949 /* IsInstanceOf ****************************************************************
1951 Tests whether an object is an instance of a class.
1953 *******************************************************************************/
1955 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1958 java_lang_Object *o;
1960 STATISTICS(jniinvokation());
1962 c = (java_lang_Class *) clazz;
1963 o = (java_lang_Object *) obj;
1965 return _Jv_java_lang_Class_isInstance(c, o);
1969 /* Reflection Support *********************************************************/
1971 /* FromReflectedMethod *********************************************************
1973 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1974 object to a method ID.
1976 *******************************************************************************/
1978 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1980 #if defined(ENABLE_JAVASE)
1985 STATISTICS(jniinvokation());
1990 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1991 java_lang_reflect_Method *rm;
1993 rm = (java_lang_reflect_Method *) method;
1994 c = (classinfo *) (rm->declaringClass);
1997 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1998 java_lang_reflect_Constructor *rc;
2000 rc = (java_lang_reflect_Constructor *) method;
2001 c = (classinfo *) (rc->clazz);
2007 mi = &(c->methods[slot]);
2009 return (jmethodID) mi;
2011 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
2013 /* keep compiler happy */
2020 /* FromReflectedField **********************************************************
2022 Converts a java.lang.reflect.Field to a field ID.
2024 *******************************************************************************/
2026 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
2028 #if defined(ENABLE_JAVASE)
2029 java_lang_reflect_Field *rf;
2033 STATISTICS(jniinvokation());
2035 rf = (java_lang_reflect_Field *) field;
2040 c = (classinfo *) rf->declaringClass;
2042 f = &(c->fields[rf->slot]);
2044 return (jfieldID) f;
2046 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
2048 /* keep compiler happy */
2055 /* ToReflectedMethod ***********************************************************
2057 Converts a method ID derived from cls to an instance of the
2058 java.lang.reflect.Method class or to an instance of the
2059 java.lang.reflect.Constructor class.
2061 *******************************************************************************/
2063 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2066 STATISTICS(jniinvokation());
2068 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2074 /* ToReflectedField ************************************************************
2076 Converts a field ID derived from cls to an instance of the
2077 java.lang.reflect.Field class.
2079 *******************************************************************************/
2081 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2084 STATISTICS(jniinvokation());
2086 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2092 /* Calling Instance Methods ***************************************************/
2094 /* GetMethodID *****************************************************************
2096 Returns the method ID for an instance (nonstatic) method of a class
2097 or interface. The method may be defined in one of the clazz's
2098 superclasses and inherited by clazz. The method is determined by
2099 its name and signature.
2101 GetMethodID() causes an uninitialized class to be initialized.
2103 *******************************************************************************/
2105 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2113 STATISTICS(jniinvokation());
2115 c = (classinfo *) clazz;
2120 if (!(c->state & CLASS_INITIALIZED))
2121 if (!initialize_class(c))
2124 /* try to get the method of the class or one of it's superclasses */
2126 uname = utf_new_char((char *) name);
2127 udesc = utf_new_char((char *) sig);
2129 m = class_resolvemethod(clazz, uname, udesc);
2131 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2132 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2137 return (jmethodID) m;
2141 /* JNI-functions for calling instance methods *********************************/
2143 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2146 java_objectheader *o;
2148 java_objectheader *ret;
2151 o = (java_objectheader *) obj;
2152 m = (methodinfo *) methodID;
2154 va_start(ap, methodID);
2155 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2158 return _Jv_JNI_NewLocalRef(env, ret);
2162 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2165 java_objectheader *o;
2167 java_objectheader *ret;
2169 o = (java_objectheader *) obj;
2170 m = (methodinfo *) methodID;
2172 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2174 return _Jv_JNI_NewLocalRef(env, ret);
2178 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2181 java_objectheader *o;
2183 java_objectheader *ret;
2185 o = (java_objectheader *) obj;
2186 m = (methodinfo *) methodID;
2188 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2190 return _Jv_JNI_NewLocalRef(env, ret);
2194 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2197 java_objectheader *o;
2202 o = (java_objectheader *) obj;
2203 m = (methodinfo *) methodID;
2205 va_start(ap, methodID);
2206 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2213 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2214 jmethodID methodID, va_list args)
2216 java_objectheader *o;
2220 o = (java_objectheader *) obj;
2221 m = (methodinfo *) methodID;
2223 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2229 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2230 jmethodID methodID, jvalue *args)
2232 java_objectheader *o;
2236 o = (java_objectheader *) obj;
2237 m = (methodinfo *) methodID;
2239 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2245 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2247 java_objectheader *o;
2252 o = (java_objectheader *) obj;
2253 m = (methodinfo *) methodID;
2255 va_start(ap, methodID);
2256 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2264 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2267 java_objectheader *o;
2271 o = (java_objectheader *) obj;
2272 m = (methodinfo *) methodID;
2274 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2280 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2283 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2289 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2291 java_objectheader *o;
2296 o = (java_objectheader *) obj;
2297 m = (methodinfo *) methodID;
2299 va_start(ap, methodID);
2300 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2307 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2310 java_objectheader *o;
2314 o = (java_objectheader *) obj;
2315 m = (methodinfo *) methodID;
2317 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2323 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2326 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2332 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2335 java_objectheader *o;
2340 o = (java_objectheader *) obj;
2341 m = (methodinfo *) methodID;
2343 va_start(ap, methodID);
2344 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2351 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2354 java_objectheader *o;
2358 o = (java_objectheader *) obj;
2359 m = (methodinfo *) methodID;
2361 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2367 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2370 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2377 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2379 java_objectheader *o;
2384 o = (java_objectheader *) obj;
2385 m = (methodinfo *) methodID;
2387 va_start(ap, methodID);
2388 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2395 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2398 java_objectheader *o;
2402 o = (java_objectheader *) obj;
2403 m = (methodinfo *) methodID;
2405 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2411 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2414 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2421 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2423 java_objectheader *o;
2428 o = (java_objectheader *) obj;
2429 m = (methodinfo *) methodID;
2431 va_start(ap, methodID);
2432 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2439 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2442 java_objectheader *o;
2446 o = (java_objectheader *) obj;
2447 m = (methodinfo *) methodID;
2449 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2455 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2458 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2465 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2468 java_objectheader *o;
2473 o = (java_objectheader *) obj;
2474 m = (methodinfo *) methodID;
2476 va_start(ap, methodID);
2477 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2484 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2487 java_objectheader *o;
2491 o = (java_objectheader *) obj;
2492 m = (methodinfo *) methodID;
2494 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2500 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2503 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2510 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2513 java_objectheader *o;
2518 o = (java_objectheader *) obj;
2519 m = (methodinfo *) methodID;
2521 va_start(ap, methodID);
2522 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2529 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2532 java_objectheader *o;
2536 o = (java_objectheader *) obj;
2537 m = (methodinfo *) methodID;
2539 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2545 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2548 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2555 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2557 java_objectheader *o;
2561 o = (java_objectheader *) obj;
2562 m = (methodinfo *) methodID;
2564 va_start(ap, methodID);
2565 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2570 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2573 java_objectheader *o;
2576 o = (java_objectheader *) obj;
2577 m = (methodinfo *) methodID;
2579 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2583 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2586 java_objectheader *o;
2589 o = (java_objectheader *) obj;
2590 m = (methodinfo *) methodID;
2592 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2597 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2598 jclass clazz, jmethodID methodID,
2601 java_objectheader *o;
2604 java_objectheader *r;
2607 o = (java_objectheader *) obj;
2608 c = (classinfo *) clazz;
2609 m = (methodinfo *) methodID;
2611 va_start(ap, methodID);
2612 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2615 return _Jv_JNI_NewLocalRef(env, r);
2619 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2620 jclass clazz, jmethodID methodID,
2623 java_objectheader *o;
2626 java_objectheader *r;
2628 o = (java_objectheader *) obj;
2629 c = (classinfo *) clazz;
2630 m = (methodinfo *) methodID;
2632 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2634 return _Jv_JNI_NewLocalRef(env, r);
2638 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2639 jclass clazz, jmethodID methodID,
2642 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2644 return _Jv_JNI_NewLocalRef(env, NULL);
2649 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2650 jclass clazz, jmethodID methodID,
2653 java_objectheader *o;
2659 o = (java_objectheader *) obj;
2660 c = (classinfo *) clazz;
2661 m = (methodinfo *) methodID;
2663 va_start(ap, methodID);
2664 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2671 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2672 jclass clazz, jmethodID methodID,
2675 java_objectheader *o;
2680 o = (java_objectheader *) obj;
2681 c = (classinfo *) clazz;
2682 m = (methodinfo *) methodID;
2684 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2690 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2691 jclass clazz, jmethodID methodID,
2694 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2700 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2701 jmethodID methodID, ...)
2703 java_objectheader *o;
2709 o = (java_objectheader *) obj;
2710 c = (classinfo *) clazz;
2711 m = (methodinfo *) methodID;
2713 va_start(ap, methodID);
2714 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2721 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2722 jmethodID methodID, va_list args)
2724 java_objectheader *o;
2729 o = (java_objectheader *) obj;
2730 c = (classinfo *) clazz;
2731 m = (methodinfo *) methodID;
2733 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2739 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2740 jmethodID methodID, jvalue *args)
2742 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2749 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2750 jmethodID methodID, ...)
2752 java_objectheader *o;
2758 o = (java_objectheader *) obj;
2759 c = (classinfo *) clazz;
2760 m = (methodinfo *) methodID;
2762 va_start(ap, methodID);
2763 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2770 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2771 jmethodID methodID, va_list args)
2773 java_objectheader *o;
2778 o = (java_objectheader *) obj;
2779 c = (classinfo *) clazz;
2780 m = (methodinfo *) methodID;
2782 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2788 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2789 jmethodID methodID, jvalue *args)
2791 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2798 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2799 jclass clazz, jmethodID methodID, ...)
2801 java_objectheader *o;
2807 o = (java_objectheader *) obj;
2808 c = (classinfo *) clazz;
2809 m = (methodinfo *) methodID;
2811 va_start(ap, methodID);
2812 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2819 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2820 jclass clazz, jmethodID methodID,
2823 java_objectheader *o;
2828 o = (java_objectheader *) obj;
2829 c = (classinfo *) clazz;
2830 m = (methodinfo *) methodID;
2832 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2838 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2839 jclass clazz, jmethodID methodID,
2842 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2849 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2850 jmethodID methodID, ...)
2852 java_objectheader *o;
2858 o = (java_objectheader *) obj;
2859 c = (classinfo *) clazz;
2860 m = (methodinfo *) methodID;
2862 va_start(ap, methodID);
2863 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2870 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2871 jmethodID methodID, va_list args)
2873 java_objectheader *o;
2878 o = (java_objectheader *) obj;
2879 c = (classinfo *) clazz;
2880 m = (methodinfo *) methodID;
2882 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2888 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2889 jmethodID methodID, jvalue *args)
2891 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2898 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2899 jmethodID methodID, ...)
2901 java_objectheader *o;
2907 o = (java_objectheader *) obj;
2908 c = (classinfo *) clazz;
2909 m = (methodinfo *) methodID;
2911 va_start(ap, methodID);
2912 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2919 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2920 jmethodID methodID, va_list args)
2922 java_objectheader *o;
2927 o = (java_objectheader *) obj;
2928 c = (classinfo *) clazz;
2929 m = (methodinfo *) methodID;
2931 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2937 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2938 jmethodID methodID, jvalue *args)
2940 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2947 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2948 jclass clazz, jmethodID methodID, ...)
2950 java_objectheader *o;
2956 o = (java_objectheader *) obj;
2957 c = (classinfo *) clazz;
2958 m = (methodinfo *) methodID;
2960 va_start(ap, methodID);
2961 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2968 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2969 jclass clazz, jmethodID methodID,
2972 java_objectheader *o;
2977 o = (java_objectheader *) obj;
2978 c = (classinfo *) clazz;
2979 m = (methodinfo *) methodID;
2981 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2987 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2988 jclass clazz, jmethodID methodID,
2991 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2998 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2999 jclass clazz, jmethodID methodID,
3002 java_objectheader *o;
3008 o = (java_objectheader *) obj;
3009 c = (classinfo *) clazz;
3010 m = (methodinfo *) methodID;
3012 va_start(ap, methodID);
3013 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
3020 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
3021 jclass clazz, jmethodID methodID,
3024 java_objectheader *o;
3029 o = (java_objectheader *) obj;
3030 c = (classinfo *) clazz;
3031 m = (methodinfo *) methodID;
3033 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
3039 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
3040 jclass clazz, jmethodID methodID,
3043 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
3050 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
3051 jmethodID methodID, ...)
3053 java_objectheader *o;
3058 o = (java_objectheader *) obj;
3059 c = (classinfo *) clazz;
3060 m = (methodinfo *) methodID;
3062 va_start(ap, methodID);
3063 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3068 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3069 jmethodID methodID, va_list args)
3071 java_objectheader *o;
3075 o = (java_objectheader *) obj;
3076 c = (classinfo *) clazz;
3077 m = (methodinfo *) methodID;
3079 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3083 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3084 jmethodID methodID, jvalue * args)
3086 java_objectheader *o;
3090 o = (java_objectheader *) obj;
3091 c = (classinfo *) clazz;
3092 m = (methodinfo *) methodID;
3094 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3098 /* Accessing Fields of Objects ************************************************/
3100 /* GetFieldID ******************************************************************
3102 Returns the field ID for an instance (nonstatic) field of a
3103 class. The field is specified by its name and signature. The
3104 Get<type>Field and Set<type>Field families of accessor functions
3105 use field IDs to retrieve object fields.
3107 *******************************************************************************/
3109 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3117 STATISTICS(jniinvokation());
3119 c = (classinfo *) clazz;
3121 uname = utf_new_char((char *) name);
3122 udesc = utf_new_char((char *) sig);
3124 f = class_findfield(clazz, uname, udesc);
3127 exceptions_throw_nosuchfielderror(c, uname);
3129 return (jfieldID) f;
3133 /* Get<type>Field Routines *****************************************************
3135 This family of accessor routines returns the value of an instance
3136 (nonstatic) field of an object. The field to access is specified by
3137 a field ID obtained by calling GetFieldID().
3139 *******************************************************************************/
3141 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3143 java_objectheader *o;
3145 STATISTICS(jniinvokation());
3147 o = GET_FIELD(obj, java_objectheader*, fieldID);
3149 return _Jv_JNI_NewLocalRef(env, o);
3153 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3157 STATISTICS(jniinvokation());
3159 i = GET_FIELD(obj, s4, fieldID);
3161 return (jboolean) i;
3165 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3169 STATISTICS(jniinvokation());
3171 i = GET_FIELD(obj, s4, fieldID);
3177 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3181 STATISTICS(jniinvokation());
3183 i = GET_FIELD(obj, s4, fieldID);
3189 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3193 STATISTICS(jniinvokation());
3195 i = GET_FIELD(obj, s4, fieldID);
3201 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3203 java_objectheader *o;
3207 STATISTICS(jniinvokation());
3209 o = (java_objectheader *) obj;
3210 f = (fieldinfo *) fieldID;
3212 i = GET_FIELD(o, s4, f);
3218 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3222 STATISTICS(jniinvokation());
3224 l = GET_FIELD(obj, s8, fieldID);
3230 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3234 STATISTICS(jniinvokation());
3236 f = GET_FIELD(obj, float, fieldID);
3242 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3246 STATISTICS(jniinvokation());
3248 d = GET_FIELD(obj, double, fieldID);
3254 /* Set<type>Field Routines *****************************************************
3256 This family of accessor routines sets the value of an instance
3257 (nonstatic) field of an object. The field to access is specified by
3258 a field ID obtained by calling GetFieldID().
3260 *******************************************************************************/
3262 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3265 STATISTICS(jniinvokation());
3267 SET_FIELD(obj, java_objectheader*, fieldID, value);
3271 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3274 STATISTICS(jniinvokation());
3276 SET_FIELD(obj, s4, fieldID, value);
3280 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3283 STATISTICS(jniinvokation());
3285 SET_FIELD(obj, s4, fieldID, value);
3289 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3292 STATISTICS(jniinvokation());
3294 SET_FIELD(obj, s4, fieldID, value);
3298 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3301 STATISTICS(jniinvokation());
3303 SET_FIELD(obj, s4, fieldID, value);
3307 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3309 STATISTICS(jniinvokation());
3311 SET_FIELD(obj, s4, fieldID, value);
3315 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3318 STATISTICS(jniinvokation());
3320 SET_FIELD(obj, s8, fieldID, value);
3324 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3327 STATISTICS(jniinvokation());
3329 SET_FIELD(obj, float, fieldID, value);
3333 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3336 STATISTICS(jniinvokation());
3338 SET_FIELD(obj, double, fieldID, value);
3342 /* Calling Static Methods *****************************************************/
3344 /* GetStaticMethodID ***********************************************************
3346 Returns the method ID for a static method of a class. The method is
3347 specified by its name and signature.
3349 GetStaticMethodID() causes an uninitialized class to be
3352 *******************************************************************************/
3354 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3362 STATISTICS(jniinvokation());
3364 c = (classinfo *) clazz;
3369 if (!(c->state & CLASS_INITIALIZED))
3370 if (!initialize_class(c))
3373 /* try to get the static method of the class */
3375 uname = utf_new_char((char *) name);
3376 udesc = utf_new_char((char *) sig);
3378 m = class_resolvemethod(c, uname, udesc);
3380 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3381 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3386 return (jmethodID) m;
3390 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3391 jmethodID methodID, ...)
3394 java_objectheader *o;
3397 m = (methodinfo *) methodID;
3399 va_start(ap, methodID);
3400 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3403 return _Jv_JNI_NewLocalRef(env, o);
3407 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3408 jmethodID methodID, va_list args)
3411 java_objectheader *o;
3413 m = (methodinfo *) methodID;
3415 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3417 return _Jv_JNI_NewLocalRef(env, o);
3421 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3422 jmethodID methodID, jvalue *args)
3425 java_objectheader *o;
3427 m = (methodinfo *) methodID;
3429 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3431 return _Jv_JNI_NewLocalRef(env, o);
3435 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3436 jmethodID methodID, ...)
3442 m = (methodinfo *) methodID;
3444 va_start(ap, methodID);
3445 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3452 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3453 jmethodID methodID, va_list args)
3458 m = (methodinfo *) methodID;
3460 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3466 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3467 jmethodID methodID, jvalue *args)
3472 m = (methodinfo *) methodID;
3474 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3480 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3481 jmethodID methodID, ...)
3487 m = (methodinfo *) methodID;
3489 va_start(ap, methodID);
3490 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3497 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3498 jmethodID methodID, va_list args)
3503 m = (methodinfo *) methodID;
3505 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3511 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3512 jmethodID methodID, jvalue *args)
3517 m = (methodinfo *) methodID;
3519 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3525 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3526 jmethodID methodID, ...)
3532 m = (methodinfo *) methodID;
3534 va_start(ap, methodID);
3535 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3542 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3543 jmethodID methodID, va_list args)
3548 m = (methodinfo *) methodID;
3550 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3556 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3557 jmethodID methodID, jvalue *args)
3562 m = (methodinfo *) methodID;
3564 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3570 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3571 jmethodID methodID, ...)
3577 m = (methodinfo *) methodID;
3579 va_start(ap, methodID);
3580 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3587 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3588 jmethodID methodID, va_list args)
3593 m = (methodinfo *) methodID;
3595 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3601 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3602 jmethodID methodID, jvalue *args)
3607 m = (methodinfo *) methodID;
3609 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3615 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3622 m = (methodinfo *) methodID;
3624 va_start(ap, methodID);
3625 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3632 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3633 jmethodID methodID, va_list args)
3638 m = (methodinfo *) methodID;
3640 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3646 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3647 jmethodID methodID, jvalue *args)
3652 m = (methodinfo *) methodID;
3654 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3660 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3661 jmethodID methodID, ...)
3667 m = (methodinfo *) methodID;
3669 va_start(ap, methodID);
3670 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3677 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3678 jmethodID methodID, va_list args)
3683 m = (methodinfo *) methodID;
3685 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3691 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3692 jmethodID methodID, jvalue *args)
3697 m = (methodinfo *) methodID;
3699 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3706 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3707 jmethodID methodID, ...)
3713 m = (methodinfo *) methodID;
3715 va_start(ap, methodID);
3716 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3723 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3724 jmethodID methodID, va_list args)
3729 m = (methodinfo *) methodID;
3731 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3737 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3738 jmethodID methodID, jvalue *args)
3743 m = (methodinfo *) methodID;
3745 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3751 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3752 jmethodID methodID, ...)
3758 m = (methodinfo *) methodID;
3760 va_start(ap, methodID);
3761 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3768 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3769 jmethodID methodID, va_list args)
3774 m = (methodinfo *) methodID;
3776 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3782 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3783 jmethodID methodID, jvalue *args)
3788 m = (methodinfo *) methodID;
3790 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3796 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3797 jmethodID methodID, ...)
3802 m = (methodinfo *) methodID;
3804 va_start(ap, methodID);
3805 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3810 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3811 jmethodID methodID, va_list args)
3815 m = (methodinfo *) methodID;
3817 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3821 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3822 jmethodID methodID, jvalue * args)
3826 m = (methodinfo *) methodID;
3828 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3832 /* Accessing Static Fields ****************************************************/
3834 /* GetStaticFieldID ************************************************************
3836 Returns the field ID for a static field of a class. The field is
3837 specified by its name and signature. The GetStatic<type>Field and
3838 SetStatic<type>Field families of accessor functions use field IDs
3839 to retrieve static fields.
3841 *******************************************************************************/
3843 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3851 STATISTICS(jniinvokation());
3853 c = (classinfo *) clazz;
3855 uname = utf_new_char((char *) name);
3856 usig = utf_new_char((char *) sig);
3858 f = class_findfield(clazz, uname, usig);
3861 exceptions_throw_nosuchfielderror(c, uname);
3863 return (jfieldID) f;
3867 /* GetStatic<type>Field ********************************************************
3869 This family of accessor routines returns the value of a static
3872 *******************************************************************************/
3874 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3880 STATISTICS(jniinvokation());
3882 c = (classinfo *) clazz;
3883 f = (fieldinfo *) fieldID;
3885 if (!(c->state & CLASS_INITIALIZED))
3886 if (!initialize_class(c))
3889 return _Jv_JNI_NewLocalRef(env, f->value.a);
3893 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3899 STATISTICS(jniinvokation());
3901 c = (classinfo *) clazz;
3902 f = (fieldinfo *) fieldID;
3904 if (!(c->state & CLASS_INITIALIZED))
3905 if (!initialize_class(c))
3912 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3917 STATISTICS(jniinvokation());
3919 c = (classinfo *) clazz;
3920 f = (fieldinfo *) fieldID;
3922 if (!(c->state & CLASS_INITIALIZED))
3923 if (!initialize_class(c))
3930 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3935 STATISTICS(jniinvokation());
3937 c = (classinfo *) clazz;
3938 f = (fieldinfo *) fieldID;
3940 if (!(c->state & CLASS_INITIALIZED))
3941 if (!initialize_class(c))
3948 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3953 STATISTICS(jniinvokation());
3955 c = (classinfo *) clazz;
3956 f = (fieldinfo *) fieldID;
3958 if (!(c->state & CLASS_INITIALIZED))
3959 if (!initialize_class(c))
3966 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3971 STATISTICS(jniinvokation());
3973 c = (classinfo *) clazz;
3974 f = (fieldinfo *) fieldID;
3976 if (!(c->state & CLASS_INITIALIZED))
3977 if (!initialize_class(c))
3984 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3989 STATISTICS(jniinvokation());
3991 c = (classinfo *) clazz;
3992 f = (fieldinfo *) fieldID;
3994 if (!(c->state & CLASS_INITIALIZED))
3995 if (!initialize_class(c))
4002 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4007 STATISTICS(jniinvokation());
4009 c = (classinfo *) clazz;
4010 f = (fieldinfo *) fieldID;
4012 if (!(c->state & CLASS_INITIALIZED))
4013 if (!initialize_class(c))
4020 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
4026 STATISTICS(jniinvokation());
4028 c = (classinfo *) clazz;
4029 f = (fieldinfo *) fieldID;
4031 if (!(c->state & CLASS_INITIALIZED))
4032 if (!initialize_class(c))
4039 /* SetStatic<type>Field *******************************************************
4041 This family of accessor routines sets the value of a static field
4044 *******************************************************************************/
4046 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4052 STATISTICS(jniinvokation());
4054 c = (classinfo *) clazz;
4055 f = (fieldinfo *) fieldID;
4057 if (!(c->state & CLASS_INITIALIZED))
4058 if (!initialize_class(c))
4065 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4071 STATISTICS(jniinvokation());
4073 c = (classinfo *) clazz;
4074 f = (fieldinfo *) fieldID;
4076 if (!(c->state & CLASS_INITIALIZED))
4077 if (!initialize_class(c))
4084 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4090 STATISTICS(jniinvokation());
4092 c = (classinfo *) clazz;
4093 f = (fieldinfo *) fieldID;
4095 if (!(c->state & CLASS_INITIALIZED))
4096 if (!initialize_class(c))
4103 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4109 STATISTICS(jniinvokation());
4111 c = (classinfo *) clazz;
4112 f = (fieldinfo *) fieldID;
4114 if (!(c->state & CLASS_INITIALIZED))
4115 if (!initialize_class(c))
4122 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4128 STATISTICS(jniinvokation());
4130 c = (classinfo *) clazz;
4131 f = (fieldinfo *) fieldID;
4133 if (!(c->state & CLASS_INITIALIZED))
4134 if (!initialize_class(c))
4141 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4147 STATISTICS(jniinvokation());
4149 c = (classinfo *) clazz;
4150 f = (fieldinfo *) fieldID;
4152 if (!(c->state & CLASS_INITIALIZED))
4153 if (!initialize_class(c))
4160 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4166 STATISTICS(jniinvokation());
4168 c = (classinfo *) clazz;
4169 f = (fieldinfo *) fieldID;
4171 if (!(c->state & CLASS_INITIALIZED))
4172 if (!initialize_class(c))
4179 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4185 STATISTICS(jniinvokation());
4187 c = (classinfo *) clazz;
4188 f = (fieldinfo *) fieldID;
4190 if (!(c->state & CLASS_INITIALIZED))
4191 if (!initialize_class(c))
4198 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4204 STATISTICS(jniinvokation());
4206 c = (classinfo *) clazz;
4207 f = (fieldinfo *) fieldID;
4209 if (!(c->state & CLASS_INITIALIZED))
4210 if (!initialize_class(c))
4217 /* String Operations **********************************************************/
4219 /* NewString *******************************************************************
4221 Create new java.lang.String object from an array of Unicode
4224 *******************************************************************************/
4226 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4228 java_lang_String *s;
4232 STATISTICS(jniinvokation());
4234 s = (java_lang_String *) builtin_new(class_java_lang_String);
4235 a = builtin_newarray_char(len);
4237 /* javastring or characterarray could not be created */
4238 if ((a == NULL) || (s == NULL))
4242 for (i = 0; i < len; i++)
4243 a->data[i] = buf[i];
4249 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4253 static jchar emptyStringJ[]={0,0};
4255 /* GetStringLength *************************************************************
4257 Returns the length (the count of Unicode characters) of a Java
4260 *******************************************************************************/
4262 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4264 return ((java_lang_String *) str)->count;
4268 /******************** convertes javastring to u2-array ****************************/
4270 u2 *javastring_tou2(jstring so)
4272 java_lang_String *s;
4277 STATISTICS(jniinvokation());
4279 s = (java_lang_String *) so;
4289 /* allocate memory */
4291 stringbuffer = MNEW(u2, s->count + 1);
4295 for (i = 0; i < s->count; i++)
4296 stringbuffer[i] = a->data[s->offset + i];
4298 /* terminate string */
4300 stringbuffer[i] = '\0';
4302 return stringbuffer;
4306 /* GetStringChars **************************************************************
4308 Returns a pointer to the array of Unicode characters of the
4309 string. This pointer is valid until ReleaseStringChars() is called.
4311 *******************************************************************************/
4313 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4317 STATISTICS(jniinvokation());
4319 jc = javastring_tou2(str);
4331 return emptyStringJ;
4335 /* ReleaseStringChars **********************************************************
4337 Informs the VM that the native code no longer needs access to
4338 chars. The chars argument is a pointer obtained from string using
4341 *******************************************************************************/
4343 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4345 STATISTICS(jniinvokation());
4347 if (chars == emptyStringJ)
4350 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4354 /* NewStringUTF ****************************************************************
4356 Constructs a new java.lang.String object from an array of UTF-8
4359 *******************************************************************************/
4361 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4363 java_lang_String *s;
4365 STATISTICS(jniinvokation());
4367 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4369 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4373 /****************** returns the utf8 length in bytes of a string *******************/
4375 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4377 java_lang_String *s = (java_lang_String*) string;
4379 STATISTICS(jniinvokation());
4381 return (jsize) u2_utflength(s->value->data, s->count);
4385 /* GetStringUTFChars ***********************************************************
4387 Returns a pointer to an array of UTF-8 characters of the
4388 string. This array is valid until it is released by
4389 ReleaseStringUTFChars().
4391 *******************************************************************************/
4393 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4398 STATISTICS(jniinvokation());
4406 u = javastring_toutf((java_objectheader *) string, false);
4415 /* ReleaseStringUTFChars *******************************************************
4417 Informs the VM that the native code no longer needs access to
4418 utf. The utf argument is a pointer derived from string using
4419 GetStringUTFChars().
4421 *******************************************************************************/
4423 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4425 STATISTICS(jniinvokation());
4427 /* XXX we don't release utf chars right now, perhaps that should be done
4428 later. Since there is always one reference the garbage collector will
4433 /* Array Operations ***********************************************************/
4435 /* GetArrayLength **************************************************************
4437 Returns the number of elements in the array.
4439 *******************************************************************************/
4441 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4443 java_arrayheader *a;
4445 STATISTICS(jniinvokation());
4447 a = (java_arrayheader *) array;
4453 /* NewObjectArray **************************************************************
4455 Constructs a new array holding objects in class elementClass. All
4456 elements are initially set to initialElement.
4458 *******************************************************************************/
4460 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4461 jclass elementClass, jobject initialElement)
4463 java_objectarray *oa;
4466 STATISTICS(jniinvokation());
4469 exceptions_throw_negativearraysizeexception();
4473 oa = builtin_anewarray(length, elementClass);
4478 /* set all elements to initialElement */
4480 for (i = 0; i < length; i++)
4481 oa->data[i] = initialElement;
4483 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4487 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4490 java_objectarray *oa;
4493 STATISTICS(jniinvokation());
4495 oa = (java_objectarray *) array;
4497 if (index >= oa->header.size) {
4498 exceptions_throw_arrayindexoutofboundsexception();
4502 o = oa->data[index];
4504 return _Jv_JNI_NewLocalRef(env, o);
4508 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4509 jsize index, jobject val)
4511 java_objectarray *oa;
4512 java_objectheader *o;
4514 STATISTICS(jniinvokation());
4516 oa = (java_objectarray *) array;
4517 o = (java_objectheader *) val;
4519 if (index >= oa->header.size) {
4520 exceptions_throw_arrayindexoutofboundsexception();
4524 /* check if the class of value is a subclass of the element class
4527 if (!builtin_canstore(oa, o))
4530 oa->data[index] = val;
4534 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4536 java_booleanarray *ba;
4538 STATISTICS(jniinvokation());
4541 exceptions_throw_negativearraysizeexception();
4545 ba = builtin_newarray_boolean(len);
4547 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4551 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4555 STATISTICS(jniinvokation());
4558 exceptions_throw_negativearraysizeexception();
4562 ba = builtin_newarray_byte(len);
4564 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4568 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4572 STATISTICS(jniinvokation());
4575 exceptions_throw_negativearraysizeexception();
4579 ca = builtin_newarray_char(len);
4581 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4585 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4587 java_shortarray *sa;
4589 STATISTICS(jniinvokation());
4592 exceptions_throw_negativearraysizeexception();
4596 sa = builtin_newarray_short(len);
4598 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4602 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4606 STATISTICS(jniinvokation());
4609 exceptions_throw_negativearraysizeexception();
4613 ia = builtin_newarray_int(len);
4615 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4619 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4623 STATISTICS(jniinvokation());
4626 exceptions_throw_negativearraysizeexception();
4630 la = builtin_newarray_long(len);
4632 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4636 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4638 java_floatarray *fa;
4640 STATISTICS(jniinvokation());
4643 exceptions_throw_negativearraysizeexception();
4647 fa = builtin_newarray_float(len);
4649 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4653 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4655 java_doublearray *da;
4657 STATISTICS(jniinvokation());
4660 exceptions_throw_negativearraysizeexception();
4664 da = builtin_newarray_double(len);
4666 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4670 /* Get<PrimitiveType>ArrayElements *********************************************
4672 A family of functions that returns the body of the primitive array.
4674 *******************************************************************************/
4676 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4679 java_booleanarray *ba;
4681 STATISTICS(jniinvokation());
4683 ba = (java_booleanarray *) array;
4686 *isCopy = JNI_FALSE;
4692 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4697 STATISTICS(jniinvokation());
4699 ba = (java_bytearray *) array;
4702 *isCopy = JNI_FALSE;
4708 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4713 STATISTICS(jniinvokation());
4715 ca = (java_chararray *) array;
4718 *isCopy = JNI_FALSE;
4724 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4727 java_shortarray *sa;
4729 STATISTICS(jniinvokation());
4731 sa = (java_shortarray *) array;
4734 *isCopy = JNI_FALSE;
4740 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4745 STATISTICS(jniinvokation());
4747 ia = (java_intarray *) array;
4750 *isCopy = JNI_FALSE;
4756 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4761 STATISTICS(jniinvokation());
4763 la = (java_longarray *) array;
4766 *isCopy = JNI_FALSE;
4768 /* We cast this one to prevent a compiler warning on 64-bit
4769 systems since GNU Classpath typedef jlong to long long. */
4771 return (jlong *) la->data;
4775 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4778 java_floatarray *fa;
4780 STATISTICS(jniinvokation());
4782 fa = (java_floatarray *) array;
4785 *isCopy = JNI_FALSE;
4791 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4794 java_doublearray *da;
4796 STATISTICS(jniinvokation());
4798 da = (java_doublearray *) array;
4801 *isCopy = JNI_FALSE;
4807 /* Release<PrimitiveType>ArrayElements *****************************************
4809 A family of functions that informs the VM that the native code no
4810 longer needs access to elems. The elems argument is a pointer
4811 derived from array using the corresponding
4812 Get<PrimitiveType>ArrayElements() function. If necessary, this
4813 function copies back all changes made to elems to the original
4816 *******************************************************************************/
4818 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4819 jboolean *elems, jint mode)
4821 java_booleanarray *ba;
4823 STATISTICS(jniinvokation());
4825 ba = (java_booleanarray *) array;
4827 if (elems != ba->data) {
4830 MCOPY(ba->data, elems, u1, ba->header.size);
4833 MCOPY(ba->data, elems, u1, ba->header.size);
4834 /* XXX TWISTI how should it be freed? */
4837 /* XXX TWISTI how should it be freed? */
4844 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4845 jbyte *elems, jint mode)
4849 STATISTICS(jniinvokation());
4851 ba = (java_bytearray *) array;
4853 if (elems != ba->data) {
4856 MCOPY(ba->data, elems, s1, ba->header.size);
4859 MCOPY(ba->data, elems, s1, ba->header.size);
4860 /* XXX TWISTI how should it be freed? */
4863 /* XXX TWISTI how should it be freed? */
4870 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4871 jchar *elems, jint mode)
4875 STATISTICS(jniinvokation());
4877 ca = (java_chararray *) array;
4879 if (elems != ca->data) {
4882 MCOPY(ca->data, elems, u2, ca->header.size);
4885 MCOPY(ca->data, elems, u2, ca->header.size);
4886 /* XXX TWISTI how should it be freed? */
4889 /* XXX TWISTI how should it be freed? */
4896 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4897 jshort *elems, jint mode)
4899 java_shortarray *sa;
4901 STATISTICS(jniinvokation());
4903 sa = (java_shortarray *) array;
4905 if (elems != sa->data) {
4908 MCOPY(sa->data, elems, s2, sa->header.size);
4911 MCOPY(sa->data, elems, s2, sa->header.size);
4912 /* XXX TWISTI how should it be freed? */
4915 /* XXX TWISTI how should it be freed? */
4922 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4927 STATISTICS(jniinvokation());
4929 ia = (java_intarray *) array;
4931 if (elems != ia->data) {
4934 MCOPY(ia->data, elems, s4, ia->header.size);
4937 MCOPY(ia->data, elems, s4, ia->header.size);
4938 /* XXX TWISTI how should it be freed? */
4941 /* XXX TWISTI how should it be freed? */
4948 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4949 jlong *elems, jint mode)
4953 STATISTICS(jniinvokation());
4955 la = (java_longarray *) array;
4957 /* We cast this one to prevent a compiler warning on 64-bit
4958 systems since GNU Classpath typedef jlong to long long. */
4960 if ((s8 *) elems != la->data) {
4963 MCOPY(la->data, elems, s8, la->header.size);
4966 MCOPY(la->data, elems, s8, la->header.size);
4967 /* XXX TWISTI how should it be freed? */
4970 /* XXX TWISTI how should it be freed? */
4977 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4978 jfloat *elems, jint mode)
4980 java_floatarray *fa;
4982 STATISTICS(jniinvokation());
4984 fa = (java_floatarray *) array;
4986 if (elems != fa->data) {
4989 MCOPY(fa->data, elems, float, fa->header.size);
4992 MCOPY(fa->data, elems, float, fa->header.size);
4993 /* XXX TWISTI how should it be freed? */
4996 /* XXX TWISTI how should it be freed? */
5003 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
5004 jdouble *elems, jint mode)
5006 java_doublearray *da;
5008 STATISTICS(jniinvokation());
5010 da = (java_doublearray *) array;
5012 if (elems != da->data) {
5015 MCOPY(da->data, elems, double, da->header.size);
5018 MCOPY(da->data, elems, double, da->header.size);
5019 /* XXX TWISTI how should it be freed? */
5022 /* XXX TWISTI how should it be freed? */
5029 /* Get<PrimitiveType>ArrayRegion **********************************************
5031 A family of functions that copies a region of a primitive array
5034 *******************************************************************************/
5036 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5037 jsize start, jsize len, jboolean *buf)
5039 java_booleanarray *ba;
5041 STATISTICS(jniinvokation());
5043 ba = (java_booleanarray *) array;
5045 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5046 exceptions_throw_arrayindexoutofboundsexception();
5048 MCOPY(buf, &ba->data[start], u1, len);
5052 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5053 jsize len, jbyte *buf)
5057 STATISTICS(jniinvokation());
5059 ba = (java_bytearray *) array;
5061 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5062 exceptions_throw_arrayindexoutofboundsexception();
5064 MCOPY(buf, &ba->data[start], s1, len);
5068 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5069 jsize len, jchar *buf)
5073 STATISTICS(jniinvokation());
5075 ca = (java_chararray *) array;
5077 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5078 exceptions_throw_arrayindexoutofboundsexception();
5080 MCOPY(buf, &ca->data[start], u2, len);
5084 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5085 jsize len, jshort *buf)
5087 java_shortarray *sa;
5089 STATISTICS(jniinvokation());
5091 sa = (java_shortarray *) array;
5093 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5094 exceptions_throw_arrayindexoutofboundsexception();
5096 MCOPY(buf, &sa->data[start], s2, len);
5100 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5101 jsize len, jint *buf)
5105 STATISTICS(jniinvokation());
5107 ia = (java_intarray *) array;
5109 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5110 exceptions_throw_arrayindexoutofboundsexception();
5112 MCOPY(buf, &ia->data[start], s4, len);
5116 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5117 jsize len, jlong *buf)
5121 STATISTICS(jniinvokation());
5123 la = (java_longarray *) array;
5125 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5126 exceptions_throw_arrayindexoutofboundsexception();
5128 MCOPY(buf, &la->data[start], s8, len);
5132 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5133 jsize len, jfloat *buf)
5135 java_floatarray *fa;
5137 STATISTICS(jniinvokation());
5139 fa = (java_floatarray *) array;
5141 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5142 exceptions_throw_arrayindexoutofboundsexception();
5144 MCOPY(buf, &fa->data[start], float, len);
5148 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5149 jsize len, jdouble *buf)
5151 java_doublearray *da;
5153 STATISTICS(jniinvokation());
5155 da = (java_doublearray *) array;
5157 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5158 exceptions_throw_arrayindexoutofboundsexception();
5160 MCOPY(buf, &da->data[start], double, len);
5164 /* Set<PrimitiveType>ArrayRegion **********************************************
5166 A family of functions that copies back a region of a primitive
5167 array from a buffer.
5169 *******************************************************************************/
5171 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5172 jsize start, jsize len, jboolean *buf)
5174 java_booleanarray *ba;
5176 STATISTICS(jniinvokation());
5178 ba = (java_booleanarray *) array;
5180 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5181 exceptions_throw_arrayindexoutofboundsexception();
5183 MCOPY(&ba->data[start], buf, u1, len);
5187 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5188 jsize len, jbyte *buf)
5192 STATISTICS(jniinvokation());
5194 ba = (java_bytearray *) array;
5196 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5197 exceptions_throw_arrayindexoutofboundsexception();
5199 MCOPY(&ba->data[start], buf, s1, len);
5203 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5204 jsize len, jchar *buf)
5208 STATISTICS(jniinvokation());
5210 ca = (java_chararray *) array;
5212 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5213 exceptions_throw_arrayindexoutofboundsexception();
5215 MCOPY(&ca->data[start], buf, u2, len);
5219 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5220 jsize len, jshort *buf)
5222 java_shortarray *sa;
5224 STATISTICS(jniinvokation());
5226 sa = (java_shortarray *) array;
5228 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5229 exceptions_throw_arrayindexoutofboundsexception();
5231 MCOPY(&sa->data[start], buf, s2, len);
5235 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5236 jsize len, jint *buf)
5240 STATISTICS(jniinvokation());
5242 ia = (java_intarray *) array;
5244 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5245 exceptions_throw_arrayindexoutofboundsexception();
5247 MCOPY(&ia->data[start], buf, s4, len);
5251 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5252 jsize len, jlong *buf)
5256 STATISTICS(jniinvokation());
5258 la = (java_longarray *) array;
5260 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5261 exceptions_throw_arrayindexoutofboundsexception();
5263 MCOPY(&la->data[start], buf, s8, len);
5267 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5268 jsize len, jfloat *buf)
5270 java_floatarray *fa;
5272 STATISTICS(jniinvokation());
5274 fa = (java_floatarray *) array;
5276 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5277 exceptions_throw_arrayindexoutofboundsexception();
5279 MCOPY(&fa->data[start], buf, float, len);
5283 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5284 jsize len, jdouble *buf)
5286 java_doublearray *da;
5288 STATISTICS(jniinvokation());
5290 da = (java_doublearray *) array;
5292 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5293 exceptions_throw_arrayindexoutofboundsexception();
5295 MCOPY(&da->data[start], buf, double, len);
5299 /* Registering Native Methods *************************************************/
5301 /* RegisterNatives *************************************************************
5303 Registers native methods with the class specified by the clazz
5304 argument. The methods parameter specifies an array of
5305 JNINativeMethod structures that contain the names, signatures, and
5306 function pointers of the native methods. The nMethods parameter
5307 specifies the number of native methods in the array.
5309 *******************************************************************************/
5311 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5312 const JNINativeMethod *methods, jint nMethods)
5314 STATISTICS(jniinvokation());
5316 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5317 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5318 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5325 /* UnregisterNatives ***********************************************************
5327 Unregisters native methods of a class. The class goes back to the
5328 state before it was linked or registered with its native method
5331 This function should not be used in normal native code. Instead, it
5332 provides special programs a way to reload and relink native
5335 *******************************************************************************/
5337 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5339 STATISTICS(jniinvokation());
5341 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5343 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5349 /* Monitor Operations *********************************************************/
5351 /* MonitorEnter ****************************************************************
5353 Enters the monitor associated with the underlying Java object
5356 *******************************************************************************/
5358 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5360 STATISTICS(jniinvokation());
5363 exceptions_throw_nullpointerexception();
5367 LOCK_MONITOR_ENTER(obj);
5373 /* MonitorExit *****************************************************************
5375 The current thread must be the owner of the monitor associated with
5376 the underlying Java object referred to by obj. The thread
5377 decrements the counter indicating the number of times it has
5378 entered this monitor. If the value of the counter becomes zero, the
5379 current thread releases the monitor.
5381 *******************************************************************************/
5383 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5385 STATISTICS(jniinvokation());
5388 exceptions_throw_nullpointerexception();
5392 LOCK_MONITOR_EXIT(obj);
5398 /* JavaVM Interface ***********************************************************/
5400 /* GetJavaVM *******************************************************************
5402 Returns the Java VM interface (used in the Invocation API)
5403 associated with the current thread. The result is placed at the
5404 location pointed to by the second argument, vm.
5406 *******************************************************************************/
5408 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5410 STATISTICS(jniinvokation());
5412 *vm = (JavaVM *) _Jv_jvm;
5418 /* GetStringRegion *************************************************************
5420 Copies len number of Unicode characters beginning at offset start
5421 to the given buffer buf.
5423 Throws StringIndexOutOfBoundsException on index overflow.
5425 *******************************************************************************/
5427 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5430 java_lang_String *s;
5433 STATISTICS(jniinvokation());
5435 s = (java_lang_String *) str;
5438 if ((start < 0) || (len < 0) || (start > s->count) ||
5439 (start + len > s->count)) {
5440 exceptions_throw_stringindexoutofboundsexception();
5444 MCOPY(buf, &ca->data[start], u2, len);
5448 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5449 jsize len, char *buf)
5451 STATISTICS(jniinvokation());
5453 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5457 /* GetPrimitiveArrayCritical ***************************************************
5459 Obtain a direct pointer to array elements.
5461 *******************************************************************************/
5463 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5469 ba = (java_bytearray *) array;
5471 /* do the same as Kaffe does */
5473 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5479 /* ReleasePrimitiveArrayCritical ***********************************************
5481 No specific documentation.
5483 *******************************************************************************/
5485 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5486 void *carray, jint mode)
5488 STATISTICS(jniinvokation());
5490 /* do the same as Kaffe does */
5492 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5497 /* GetStringCritical ***********************************************************
5499 The semantics of these two functions are similar to the existing
5500 Get/ReleaseStringChars functions.
5502 *******************************************************************************/
5504 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5507 STATISTICS(jniinvokation());
5509 return _Jv_JNI_GetStringChars(env, string, isCopy);
5513 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5514 const jchar *cstring)
5516 STATISTICS(jniinvokation());
5518 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5522 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5524 STATISTICS(jniinvokation());
5526 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5532 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5534 STATISTICS(jniinvokation());
5536 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5540 /* NewGlobalRef ****************************************************************
5542 Creates a new global reference to the object referred to by the obj
5545 *******************************************************************************/
5547 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5549 hashtable_global_ref_entry *gre;
5550 u4 key; /* hashkey */
5551 u4 slot; /* slot in hashtable */
5553 STATISTICS(jniinvokation());
5555 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5557 /* normally addresses are aligned to 4, 8 or 16 bytes */
5559 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5560 slot = key & (hashtable_global_ref->size - 1);
5561 gre = hashtable_global_ref->ptr[slot];
5563 /* search external hash chain for the entry */
5566 if (gre->o == obj) {
5567 /* global object found, increment the reference */
5571 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5576 gre = gre->hashlink; /* next element in external chain */
5579 /* global ref not found, create a new one */
5581 gre = NEW(hashtable_global_ref_entry);
5586 /* insert entry into hashtable */
5588 gre->hashlink = hashtable_global_ref->ptr[slot];
5590 hashtable_global_ref->ptr[slot] = gre;
5592 /* update number of hashtable-entries */
5594 hashtable_global_ref->entries++;
5596 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5602 /* DeleteGlobalRef *************************************************************
5604 Deletes the global reference pointed to by globalRef.
5606 *******************************************************************************/
5608 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5610 hashtable_global_ref_entry *gre;
5611 hashtable_global_ref_entry *prevgre;
5612 u4 key; /* hashkey */
5613 u4 slot; /* slot in hashtable */
5615 STATISTICS(jniinvokation());
5617 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5619 /* normally addresses are aligned to 4, 8 or 16 bytes */
5621 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5622 slot = key & (hashtable_global_ref->size - 1);
5623 gre = hashtable_global_ref->ptr[slot];
5625 /* initialize prevgre */
5629 /* search external hash chain for the entry */
5632 if (gre->o == globalRef) {
5633 /* global object found, decrement the reference count */
5637 /* if reference count is 0, remove the entry */
5639 if (gre->refs == 0) {
5640 /* special handling if it's the first in the chain */
5642 if (prevgre == NULL)
5643 hashtable_global_ref->ptr[slot] = gre->hashlink;
5645 prevgre->hashlink = gre->hashlink;
5647 FREE(gre, hashtable_global_ref_entry);
5650 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5655 prevgre = gre; /* save current pointer for removal */
5656 gre = gre->hashlink; /* next element in external chain */
5659 log_println("JNI-DeleteGlobalRef: global reference not found");
5661 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5665 /* ExceptionCheck **************************************************************
5667 Returns JNI_TRUE when there is a pending exception; otherwise,
5670 *******************************************************************************/
5672 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5674 java_objectheader *o;
5676 STATISTICS(jniinvokation());
5678 o = exceptions_get_exception();
5680 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5684 /* New JNI 1.4 functions ******************************************************/
5686 /* NewDirectByteBuffer *********************************************************
5688 Allocates and returns a direct java.nio.ByteBuffer referring to the
5689 block of memory starting at the memory address address and
5690 extending capacity bytes.
5692 *******************************************************************************/
5694 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5696 #if defined(ENABLE_JAVASE)
5697 java_objectheader *nbuf;
5698 # if SIZEOF_VOID_P == 8
5699 gnu_classpath_Pointer64 *paddress;
5701 gnu_classpath_Pointer32 *paddress;
5704 STATISTICS(jniinvokation());
5706 /* alocate a gnu.classpath.Pointer{32,64} object */
5708 # if SIZEOF_VOID_P == 8
5709 if (!(paddress = (gnu_classpath_Pointer64 *)
5710 builtin_new(class_gnu_classpath_Pointer64)))
5712 if (!(paddress = (gnu_classpath_Pointer32 *)
5713 builtin_new(class_gnu_classpath_Pointer32)))
5717 /* fill gnu.classpath.Pointer{32,64} with address */
5719 paddress->data = (ptrint) address;
5721 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5723 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5724 (jmethodID) dbbirw_init, NULL, paddress,
5725 (jint) capacity, (jint) capacity, (jint) 0);
5727 /* add local reference and return the value */
5729 return _Jv_JNI_NewLocalRef(env, nbuf);
5731 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5733 /* keep compiler happy */
5740 /* GetDirectBufferAddress ******************************************************
5742 Fetches and returns the starting address of the memory region
5743 referenced by the given direct java.nio.Buffer.
5745 *******************************************************************************/
5747 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5749 #if defined(ENABLE_JAVASE)
5750 java_nio_DirectByteBufferImpl *nbuf;
5751 # if SIZEOF_VOID_P == 8
5752 gnu_classpath_Pointer64 *address;
5754 gnu_classpath_Pointer32 *address;
5757 STATISTICS(jniinvokation());
5759 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5762 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5764 # if SIZEOF_VOID_P == 8
5765 address = (gnu_classpath_Pointer64 *) nbuf->address;
5767 address = (gnu_classpath_Pointer32 *) nbuf->address;
5770 if (address == NULL)
5773 return (void *) address->data;
5775 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5777 /* keep compiler happy */
5784 /* GetDirectBufferCapacity *****************************************************
5786 Fetches and returns the capacity in bytes of the memory region
5787 referenced by the given direct java.nio.Buffer.
5789 *******************************************************************************/
5791 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5793 #if defined(ENABLE_JAVASE)
5794 java_nio_Buffer *nbuf;
5796 STATISTICS(jniinvokation());
5798 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5801 nbuf = (java_nio_Buffer *) buf;
5803 return (jlong) nbuf->cap;
5805 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5807 /* keep compiler happy */
5814 /* DestroyJavaVM ***************************************************************
5816 Unloads a Java VM and reclaims its resources. Only the main thread
5817 can unload the VM. The system waits until the main thread is only
5818 remaining user thread before it destroys the VM.
5820 *******************************************************************************/
5822 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5826 STATISTICS(jniinvokation());
5828 status = vm_destroy(vm);
5834 /* AttachCurrentThread *********************************************************
5836 Attaches the current thread to a Java VM. Returns a JNI interface
5837 pointer in the JNIEnv argument.
5839 Trying to attach a thread that is already attached is a no-op.
5841 A native thread cannot be attached simultaneously to two Java VMs.
5843 When a thread is attached to the VM, the context class loader is
5844 the bootstrap loader.
5846 *******************************************************************************/
5848 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5850 JavaVMAttachArgs *vm_aargs;
5852 #if defined(ENABLE_THREADS)
5853 if (threads_get_current_threadobject() == NULL) {
5854 vm_aargs = (JavaVMAttachArgs *) thr_args;
5856 if (vm_aargs != NULL) {
5857 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5858 (vm_aargs->version != JNI_VERSION_1_4))
5859 return JNI_EVERSION;
5862 if (!threads_attach_current_thread(vm_aargs, false))
5865 if (!jni_init_localref_table())
5876 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5878 STATISTICS(jniinvokation());
5880 return jni_attach_current_thread(p_env, thr_args, false);
5884 /* DetachCurrentThread *********************************************************
5886 Detaches the current thread from a Java VM. All Java monitors held
5887 by this thread are released. All Java threads waiting for this
5888 thread to die are notified.
5890 In JDK 1.1, the main thread cannot be detached from the VM. It must
5891 call DestroyJavaVM to unload the entire VM.
5893 In the JDK, the main thread can be detached from the VM.
5895 The main thread, which is the thread that created the Java VM,
5896 cannot be detached from the VM. Instead, the main thread must call
5897 JNI_DestroyJavaVM() to unload the entire VM.
5899 *******************************************************************************/
5901 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5903 #if defined(ENABLE_THREADS)
5904 threadobject *thread;
5906 STATISTICS(jniinvokation());
5908 thread = threads_get_current_threadobject();
5913 if (!threads_detach_thread(thread))
5921 /* GetEnv **********************************************************************
5923 If the current thread is not attached to the VM, sets *env to NULL,
5924 and returns JNI_EDETACHED. If the specified version is not
5925 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5926 sets *env to the appropriate interface, and returns JNI_OK.
5928 *******************************************************************************/
5930 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5932 STATISTICS(jniinvokation());
5934 #if defined(ENABLE_THREADS)
5935 if (threads_get_current_threadobject() == NULL) {
5938 return JNI_EDETACHED;
5942 /* check the JNI version */
5945 case JNI_VERSION_1_1:
5946 case JNI_VERSION_1_2:
5947 case JNI_VERSION_1_4:
5955 #if defined(ENABLE_JVMTI)
5956 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5957 == JVMTI_VERSION_INTERFACE_JVMTI) {
5959 *env = (void *) jvmti_new_environment();
5968 return JNI_EVERSION;
5972 /* AttachCurrentThreadAsDaemon *************************************************
5974 Same semantics as AttachCurrentThread, but the newly-created
5975 java.lang.Thread instance is a daemon.
5977 If the thread has already been attached via either
5978 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5979 simply sets the value pointed to by penv to the JNIEnv of the
5980 current thread. In this case neither AttachCurrentThread nor this
5981 routine have any effect on the daemon status of the thread.
5983 *******************************************************************************/
5985 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5987 STATISTICS(jniinvokation());
5989 return jni_attach_current_thread(penv, args, true);
5993 /* JNI invocation table *******************************************************/
5995 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
6000 _Jv_JNI_DestroyJavaVM,
6001 _Jv_JNI_AttachCurrentThread,
6002 _Jv_JNI_DetachCurrentThread,
6004 _Jv_JNI_AttachCurrentThreadAsDaemon
6008 /* JNI function table *********************************************************/
6010 struct JNINativeInterface _Jv_JNINativeInterface = {
6017 _Jv_JNI_DefineClass,
6019 _Jv_JNI_FromReflectedMethod,
6020 _Jv_JNI_FromReflectedField,
6021 _Jv_JNI_ToReflectedMethod,
6022 _Jv_JNI_GetSuperclass,
6023 _Jv_JNI_IsAssignableFrom,
6024 _Jv_JNI_ToReflectedField,
6028 _Jv_JNI_ExceptionOccurred,
6029 _Jv_JNI_ExceptionDescribe,
6030 _Jv_JNI_ExceptionClear,
6032 _Jv_JNI_PushLocalFrame,
6033 _Jv_JNI_PopLocalFrame,
6035 _Jv_JNI_NewGlobalRef,
6036 _Jv_JNI_DeleteGlobalRef,
6037 _Jv_JNI_DeleteLocalRef,
6038 _Jv_JNI_IsSameObject,
6039 _Jv_JNI_NewLocalRef,
6040 _Jv_JNI_EnsureLocalCapacity,
6042 _Jv_JNI_AllocObject,
6047 _Jv_JNI_GetObjectClass,
6048 _Jv_JNI_IsInstanceOf,
6050 _Jv_JNI_GetMethodID,
6052 _Jv_JNI_CallObjectMethod,
6053 _Jv_JNI_CallObjectMethodV,
6054 _Jv_JNI_CallObjectMethodA,
6055 _Jv_JNI_CallBooleanMethod,
6056 _Jv_JNI_CallBooleanMethodV,
6057 _Jv_JNI_CallBooleanMethodA,
6058 _Jv_JNI_CallByteMethod,
6059 _Jv_JNI_CallByteMethodV,
6060 _Jv_JNI_CallByteMethodA,
6061 _Jv_JNI_CallCharMethod,
6062 _Jv_JNI_CallCharMethodV,
6063 _Jv_JNI_CallCharMethodA,
6064 _Jv_JNI_CallShortMethod,
6065 _Jv_JNI_CallShortMethodV,
6066 _Jv_JNI_CallShortMethodA,
6067 _Jv_JNI_CallIntMethod,
6068 _Jv_JNI_CallIntMethodV,
6069 _Jv_JNI_CallIntMethodA,
6070 _Jv_JNI_CallLongMethod,
6071 _Jv_JNI_CallLongMethodV,
6072 _Jv_JNI_CallLongMethodA,
6073 _Jv_JNI_CallFloatMethod,
6074 _Jv_JNI_CallFloatMethodV,
6075 _Jv_JNI_CallFloatMethodA,
6076 _Jv_JNI_CallDoubleMethod,
6077 _Jv_JNI_CallDoubleMethodV,
6078 _Jv_JNI_CallDoubleMethodA,
6079 _Jv_JNI_CallVoidMethod,
6080 _Jv_JNI_CallVoidMethodV,
6081 _Jv_JNI_CallVoidMethodA,
6083 _Jv_JNI_CallNonvirtualObjectMethod,
6084 _Jv_JNI_CallNonvirtualObjectMethodV,
6085 _Jv_JNI_CallNonvirtualObjectMethodA,
6086 _Jv_JNI_CallNonvirtualBooleanMethod,
6087 _Jv_JNI_CallNonvirtualBooleanMethodV,
6088 _Jv_JNI_CallNonvirtualBooleanMethodA,
6089 _Jv_JNI_CallNonvirtualByteMethod,
6090 _Jv_JNI_CallNonvirtualByteMethodV,
6091 _Jv_JNI_CallNonvirtualByteMethodA,
6092 _Jv_JNI_CallNonvirtualCharMethod,
6093 _Jv_JNI_CallNonvirtualCharMethodV,
6094 _Jv_JNI_CallNonvirtualCharMethodA,
6095 _Jv_JNI_CallNonvirtualShortMethod,
6096 _Jv_JNI_CallNonvirtualShortMethodV,
6097 _Jv_JNI_CallNonvirtualShortMethodA,
6098 _Jv_JNI_CallNonvirtualIntMethod,
6099 _Jv_JNI_CallNonvirtualIntMethodV,
6100 _Jv_JNI_CallNonvirtualIntMethodA,
6101 _Jv_JNI_CallNonvirtualLongMethod,
6102 _Jv_JNI_CallNonvirtualLongMethodV,
6103 _Jv_JNI_CallNonvirtualLongMethodA,
6104 _Jv_JNI_CallNonvirtualFloatMethod,
6105 _Jv_JNI_CallNonvirtualFloatMethodV,
6106 _Jv_JNI_CallNonvirtualFloatMethodA,
6107 _Jv_JNI_CallNonvirtualDoubleMethod,
6108 _Jv_JNI_CallNonvirtualDoubleMethodV,
6109 _Jv_JNI_CallNonvirtualDoubleMethodA,
6110 _Jv_JNI_CallNonvirtualVoidMethod,
6111 _Jv_JNI_CallNonvirtualVoidMethodV,
6112 _Jv_JNI_CallNonvirtualVoidMethodA,
6116 _Jv_JNI_GetObjectField,
6117 _Jv_JNI_GetBooleanField,
6118 _Jv_JNI_GetByteField,
6119 _Jv_JNI_GetCharField,
6120 _Jv_JNI_GetShortField,
6121 _Jv_JNI_GetIntField,
6122 _Jv_JNI_GetLongField,
6123 _Jv_JNI_GetFloatField,
6124 _Jv_JNI_GetDoubleField,
6125 _Jv_JNI_SetObjectField,
6126 _Jv_JNI_SetBooleanField,
6127 _Jv_JNI_SetByteField,
6128 _Jv_JNI_SetCharField,
6129 _Jv_JNI_SetShortField,
6130 _Jv_JNI_SetIntField,
6131 _Jv_JNI_SetLongField,
6132 _Jv_JNI_SetFloatField,
6133 _Jv_JNI_SetDoubleField,
6135 _Jv_JNI_GetStaticMethodID,
6137 _Jv_JNI_CallStaticObjectMethod,
6138 _Jv_JNI_CallStaticObjectMethodV,
6139 _Jv_JNI_CallStaticObjectMethodA,
6140 _Jv_JNI_CallStaticBooleanMethod,
6141 _Jv_JNI_CallStaticBooleanMethodV,
6142 _Jv_JNI_CallStaticBooleanMethodA,
6143 _Jv_JNI_CallStaticByteMethod,
6144 _Jv_JNI_CallStaticByteMethodV,
6145 _Jv_JNI_CallStaticByteMethodA,
6146 _Jv_JNI_CallStaticCharMethod,
6147 _Jv_JNI_CallStaticCharMethodV,
6148 _Jv_JNI_CallStaticCharMethodA,
6149 _Jv_JNI_CallStaticShortMethod,
6150 _Jv_JNI_CallStaticShortMethodV,
6151 _Jv_JNI_CallStaticShortMethodA,
6152 _Jv_JNI_CallStaticIntMethod,
6153 _Jv_JNI_CallStaticIntMethodV,
6154 _Jv_JNI_CallStaticIntMethodA,
6155 _Jv_JNI_CallStaticLongMethod,
6156 _Jv_JNI_CallStaticLongMethodV,
6157 _Jv_JNI_CallStaticLongMethodA,
6158 _Jv_JNI_CallStaticFloatMethod,
6159 _Jv_JNI_CallStaticFloatMethodV,
6160 _Jv_JNI_CallStaticFloatMethodA,
6161 _Jv_JNI_CallStaticDoubleMethod,
6162 _Jv_JNI_CallStaticDoubleMethodV,
6163 _Jv_JNI_CallStaticDoubleMethodA,
6164 _Jv_JNI_CallStaticVoidMethod,
6165 _Jv_JNI_CallStaticVoidMethodV,
6166 _Jv_JNI_CallStaticVoidMethodA,
6168 _Jv_JNI_GetStaticFieldID,
6170 _Jv_JNI_GetStaticObjectField,
6171 _Jv_JNI_GetStaticBooleanField,
6172 _Jv_JNI_GetStaticByteField,
6173 _Jv_JNI_GetStaticCharField,
6174 _Jv_JNI_GetStaticShortField,
6175 _Jv_JNI_GetStaticIntField,
6176 _Jv_JNI_GetStaticLongField,
6177 _Jv_JNI_GetStaticFloatField,
6178 _Jv_JNI_GetStaticDoubleField,
6179 _Jv_JNI_SetStaticObjectField,
6180 _Jv_JNI_SetStaticBooleanField,
6181 _Jv_JNI_SetStaticByteField,
6182 _Jv_JNI_SetStaticCharField,
6183 _Jv_JNI_SetStaticShortField,
6184 _Jv_JNI_SetStaticIntField,
6185 _Jv_JNI_SetStaticLongField,
6186 _Jv_JNI_SetStaticFloatField,
6187 _Jv_JNI_SetStaticDoubleField,
6190 _Jv_JNI_GetStringLength,
6191 _Jv_JNI_GetStringChars,
6192 _Jv_JNI_ReleaseStringChars,
6194 _Jv_JNI_NewStringUTF,
6195 _Jv_JNI_GetStringUTFLength,
6196 _Jv_JNI_GetStringUTFChars,
6197 _Jv_JNI_ReleaseStringUTFChars,
6199 _Jv_JNI_GetArrayLength,
6201 _Jv_JNI_NewObjectArray,
6202 _Jv_JNI_GetObjectArrayElement,
6203 _Jv_JNI_SetObjectArrayElement,
6205 _Jv_JNI_NewBooleanArray,
6206 _Jv_JNI_NewByteArray,
6207 _Jv_JNI_NewCharArray,
6208 _Jv_JNI_NewShortArray,
6209 _Jv_JNI_NewIntArray,
6210 _Jv_JNI_NewLongArray,
6211 _Jv_JNI_NewFloatArray,
6212 _Jv_JNI_NewDoubleArray,
6214 _Jv_JNI_GetBooleanArrayElements,
6215 _Jv_JNI_GetByteArrayElements,
6216 _Jv_JNI_GetCharArrayElements,
6217 _Jv_JNI_GetShortArrayElements,
6218 _Jv_JNI_GetIntArrayElements,
6219 _Jv_JNI_GetLongArrayElements,
6220 _Jv_JNI_GetFloatArrayElements,
6221 _Jv_JNI_GetDoubleArrayElements,
6223 _Jv_JNI_ReleaseBooleanArrayElements,
6224 _Jv_JNI_ReleaseByteArrayElements,
6225 _Jv_JNI_ReleaseCharArrayElements,
6226 _Jv_JNI_ReleaseShortArrayElements,
6227 _Jv_JNI_ReleaseIntArrayElements,
6228 _Jv_JNI_ReleaseLongArrayElements,
6229 _Jv_JNI_ReleaseFloatArrayElements,
6230 _Jv_JNI_ReleaseDoubleArrayElements,
6232 _Jv_JNI_GetBooleanArrayRegion,
6233 _Jv_JNI_GetByteArrayRegion,
6234 _Jv_JNI_GetCharArrayRegion,
6235 _Jv_JNI_GetShortArrayRegion,
6236 _Jv_JNI_GetIntArrayRegion,
6237 _Jv_JNI_GetLongArrayRegion,
6238 _Jv_JNI_GetFloatArrayRegion,
6239 _Jv_JNI_GetDoubleArrayRegion,
6240 _Jv_JNI_SetBooleanArrayRegion,
6241 _Jv_JNI_SetByteArrayRegion,
6242 _Jv_JNI_SetCharArrayRegion,
6243 _Jv_JNI_SetShortArrayRegion,
6244 _Jv_JNI_SetIntArrayRegion,
6245 _Jv_JNI_SetLongArrayRegion,
6246 _Jv_JNI_SetFloatArrayRegion,
6247 _Jv_JNI_SetDoubleArrayRegion,
6249 _Jv_JNI_RegisterNatives,
6250 _Jv_JNI_UnregisterNatives,
6252 _Jv_JNI_MonitorEnter,
6253 _Jv_JNI_MonitorExit,
6257 /* new JNI 1.2 functions */
6259 _Jv_JNI_GetStringRegion,
6260 _Jv_JNI_GetStringUTFRegion,
6262 _Jv_JNI_GetPrimitiveArrayCritical,
6263 _Jv_JNI_ReleasePrimitiveArrayCritical,
6265 _Jv_JNI_GetStringCritical,
6266 _Jv_JNI_ReleaseStringCritical,
6268 _Jv_JNI_NewWeakGlobalRef,
6269 _Jv_JNI_DeleteWeakGlobalRef,
6271 _Jv_JNI_ExceptionCheck,
6273 /* new JNI 1.4 functions */
6275 _Jv_JNI_NewDirectByteBuffer,
6276 _Jv_JNI_GetDirectBufferAddress,
6277 _Jv_JNI_GetDirectBufferCapacity
6281 /* Invocation API Functions ***************************************************/
6283 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6285 Returns a default configuration for the Java VM.
6287 *******************************************************************************/
6289 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6291 JavaVMInitArgs *_vm_args;
6293 _vm_args = (JavaVMInitArgs *) vm_args;
6295 /* GNU classpath currently supports JNI 1.2 */
6297 switch (_vm_args->version) {
6298 case JNI_VERSION_1_1:
6299 _vm_args->version = JNI_VERSION_1_1;
6302 case JNI_VERSION_1_2:
6303 case JNI_VERSION_1_4:
6304 _vm_args->ignoreUnrecognized = JNI_FALSE;
6305 _vm_args->options = NULL;
6306 _vm_args->nOptions = 0;
6317 /* JNI_GetCreatedJavaVMs *******************************************************
6319 Returns all Java VMs that have been created. Pointers to VMs are written in
6320 the buffer vmBuf in the order they are created. At most bufLen number of
6321 entries will be written. The total number of created VMs is returned in
6324 *******************************************************************************/
6326 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6328 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6334 /* JNI_CreateJavaVM ************************************************************
6336 Loads and initializes a Java VM. The current thread becomes the main thread.
6337 Sets the env argument to the JNI interface pointer of the main thread.
6339 *******************************************************************************/
6341 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6343 /* actually create the JVM */
6345 if (!vm_createjvm(p_vm, p_env, vm_args))
6353 * These are local overrides for various environment variables in Emacs.
6354 * Please do not remove this and leave it at the end of the file, where
6355 * Emacs will automagically detect them.
6356 * ---------------------------------------------------------------------
6359 * indent-tabs-mode: t
6363 * vim:noexpandtab:sw=4:ts=4: