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 8060 2007-06-10 20:00:40Z twisti $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #if defined(ENABLE_JAVASE)
43 # if defined(WITH_CLASSPATH_GNU)
44 # include "native/include/gnu_classpath_Pointer.h"
46 # if SIZEOF_VOID_P == 8
47 # include "native/include/gnu_classpath_Pointer64.h"
49 # include "native/include/gnu_classpath_Pointer32.h"
54 #include "native/include/java_lang_Object.h"
55 #include "native/include/java_lang_Byte.h"
56 #include "native/include/java_lang_Character.h"
57 #include "native/include/java_lang_Short.h"
58 #include "native/include/java_lang_Integer.h"
59 #include "native/include/java_lang_Boolean.h"
60 #include "native/include/java_lang_Long.h"
61 #include "native/include/java_lang_Float.h"
62 #include "native/include/java_lang_Double.h"
63 #include "native/include/java_lang_String.h"
64 #include "native/include/java_lang_Throwable.h"
66 #if defined(ENABLE_JAVASE)
67 # include "native/include/java_lang_ClassLoader.h"
69 # include "native/include/java_lang_reflect_Constructor.h"
70 # include "native/include/java_lang_reflect_Field.h"
71 # include "native/include/java_lang_reflect_Method.h"
73 # include "native/include/java_nio_Buffer.h"
74 # include "native/include/java_nio_DirectByteBufferImpl.h"
77 #if defined(ENABLE_JVMTI)
78 # include "native/jvmti/cacaodbg.h"
81 #include "native/vm/java_lang_Class.h"
83 #if defined(ENABLE_JAVASE)
84 # include "native/vm/java_lang_ClassLoader.h"
87 #include "threads/lock-common.h"
88 #include "threads/threads-common.h"
90 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/resolve.h"
97 #include "vm/stringlocal.h"
100 #include "vm/jit/asmpart.h"
101 #include "vm/jit/jit.h"
102 #include "vm/jit/stacktrace.h"
104 #include "vmcore/loader.h"
105 #include "vmcore/options.h"
106 #include "vmcore/primitive.h"
107 #include "vmcore/statistics.h"
110 /* global variables ***********************************************************/
112 /* global reference table *****************************************************/
114 /* hashsize must be power of 2 */
116 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
118 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
121 /* direct buffer stuff ********************************************************/
123 #if defined(ENABLE_JAVASE)
124 static classinfo *class_java_nio_Buffer;
125 static classinfo *class_java_nio_DirectByteBufferImpl;
126 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
128 # if defined(WITH_CLASSPATH_GNU)
129 # if SIZEOF_VOID_P == 8
130 static classinfo *class_gnu_classpath_Pointer64;
132 static classinfo *class_gnu_classpath_Pointer32;
136 static methodinfo *dbbirw_init;
140 /* local reference table ******************************************************/
142 #if !defined(ENABLE_THREADS)
143 localref_table *_no_threads_localref_table;
147 /* accessing instance fields macros *******************************************/
149 #define SET_FIELD(o,type,f,value) \
150 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
152 #define GET_FIELD(o,type,f) \
153 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
156 /* some forward declarations **************************************************/
158 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
159 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
162 /* jni_init ********************************************************************
164 Initialize the JNI subsystem.
166 *******************************************************************************/
170 /* create global ref hashtable */
172 hashtable_global_ref = NEW(hashtable);
174 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
177 #if defined(ENABLE_JAVASE)
178 /* direct buffer stuff */
180 if (!(class_java_nio_Buffer =
181 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
182 !link_class(class_java_nio_Buffer))
185 if (!(class_java_nio_DirectByteBufferImpl =
186 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
187 !link_class(class_java_nio_DirectByteBufferImpl))
190 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
191 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
192 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
196 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
198 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
201 # if defined(WITH_CLASSPATH_GNU)
202 # if SIZEOF_VOID_P == 8
203 if (!(class_gnu_classpath_Pointer64 =
204 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
205 !link_class(class_gnu_classpath_Pointer64))
208 if (!(class_gnu_classpath_Pointer32 =
209 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
210 !link_class(class_gnu_classpath_Pointer32))
214 #endif /* defined(ENABLE_JAVASE) */
220 /* jni_init_localref_table *****************************************************
222 Initializes the local references table of the current thread.
224 *******************************************************************************/
226 bool jni_init_localref_table(void)
230 lrt = GCNEW(localref_table);
235 lrt->capacity = LOCALREFTABLE_CAPACITY;
237 lrt->localframes = 1;
238 lrt->prev = LOCALREFTABLE;
240 /* clear the references array (memset is faster then a for-loop) */
242 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
250 /* _Jv_jni_vmargs_from_objectarray *********************************************
254 *******************************************************************************/
256 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
259 java_objectarray *params)
261 java_objectheader *param;
263 typedesc *paramtypes;
269 paramcount = descr->paramcount;
270 paramtypes = descr->paramtypes;
272 /* if method is non-static fill first block and skip `this' pointer */
278 vmargs[0].type = TYPE_ADR;
279 vmargs[0].data.l = (u8) (ptrint) o;
286 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
287 switch (paramtypes->type) {
288 /* primitive types */
293 param = params->data[j];
298 /* internally used data type */
299 vmargs[i].type = paramtypes->type;
301 /* convert the value according to its declared type */
303 c = param->vftbl->class;
305 switch (paramtypes->decltype) {
306 case PRIMITIVETYPE_BOOLEAN:
307 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
308 value = (s8) ((java_lang_Boolean *) param)->value;
312 vmargs[i].data.l = value;
315 case PRIMITIVETYPE_BYTE:
316 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
317 value = (s8) ((java_lang_Byte *) param)->value;
321 vmargs[i].data.l = value;
324 case PRIMITIVETYPE_CHAR:
325 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
326 value = (s8) ((java_lang_Character *) param)->value;
330 vmargs[i].data.l = value;
333 case PRIMITIVETYPE_SHORT:
334 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
335 value = (s8) ((java_lang_Short *) param)->value;
336 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
337 value = (s8) ((java_lang_Byte *) param)->value;
341 vmargs[i].data.l = value;
344 case PRIMITIVETYPE_INT:
345 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
346 value = (s8) ((java_lang_Integer *) param)->value;
347 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
348 value = (s8) ((java_lang_Short *) param)->value;
349 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
350 value = (s8) ((java_lang_Byte *) param)->value;
354 vmargs[i].data.l = value;
357 case PRIMITIVETYPE_LONG:
358 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
359 value = (s8) ((java_lang_Long *) param)->value;
360 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
361 value = (s8) ((java_lang_Integer *) param)->value;
362 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
363 value = (s8) ((java_lang_Short *) param)->value;
364 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
365 value = (s8) ((java_lang_Byte *) param)->value;
369 vmargs[i].data.l = value;
372 case PRIMITIVETYPE_FLOAT:
373 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
374 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
379 case PRIMITIVETYPE_DOUBLE:
380 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
381 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
382 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
383 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
394 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
397 if (params->data[j] != 0) {
398 if (paramtypes->arraydim > 0) {
399 if (!builtin_arrayinstanceof(params->data[j], c))
403 if (!builtin_instanceof(params->data[j], c))
408 vmargs[i].type = TYPE_ADR;
409 vmargs[i].data.l = (u8) (ptrint) params->data[j];
418 /* *rettype = descr->returntype.decltype; */
423 exceptions_throw_illegalargumentexception();
428 /* _Jv_jni_CallObjectMethod ****************************************************
430 Internal function to call Java Object methods.
432 *******************************************************************************/
434 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
436 methodinfo *m, va_list ap)
439 java_objectheader *ro;
441 STATISTICS(jniinvokation());
444 exceptions_throw_nullpointerexception();
448 /* Class initialization is done by the JIT compiler. This is ok
449 since a static method always belongs to the declaring class. */
451 if (m->flags & ACC_STATIC) {
452 /* For static methods we reset the object. */
457 /* for convenience */
462 /* For instance methods we make a virtual function table lookup. */
464 resm = method_vftbl_lookup(vftbl, m);
467 STATISTICS(jnicallXmethodnvokation());
469 ro = vm_call_method_valist(resm, o, ap);
475 /* _Jv_jni_CallObjectMethodA ***************************************************
477 Internal function to call Java Object methods.
479 *******************************************************************************/
481 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
483 methodinfo *m, jvalue *args)
486 java_objectheader *ro;
488 STATISTICS(jniinvokation());
491 exceptions_throw_nullpointerexception();
495 /* Class initialization is done by the JIT compiler. This is ok
496 since a static method always belongs to the declaring class. */
498 if (m->flags & ACC_STATIC) {
499 /* For static methods we reset the object. */
504 /* for convenience */
509 /* For instance methods we make a virtual function table lookup. */
511 resm = method_vftbl_lookup(vftbl, m);
514 STATISTICS(jnicallXmethodnvokation());
516 ro = vm_call_method_jvalue(resm, o, args);
522 /* _Jv_jni_CallIntMethod *******************************************************
524 Internal function to call Java integer class methods (boolean,
525 byte, char, short, int).
527 *******************************************************************************/
529 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
530 methodinfo *m, va_list ap)
535 STATISTICS(jniinvokation());
538 exceptions_throw_nullpointerexception();
542 /* Class initialization is done by the JIT compiler. This is ok
543 since a static method always belongs to the declaring class. */
545 if (m->flags & ACC_STATIC) {
546 /* For static methods we reset the object. */
551 /* for convenience */
556 /* For instance methods we make a virtual function table lookup. */
558 resm = method_vftbl_lookup(vftbl, m);
561 STATISTICS(jnicallXmethodnvokation());
563 i = vm_call_method_int_valist(resm, o, ap);
569 /* _Jv_jni_CallIntMethodA ******************************************************
571 Internal function to call Java integer class methods (boolean,
572 byte, char, short, int).
574 *******************************************************************************/
576 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
577 methodinfo *m, jvalue *args)
582 STATISTICS(jniinvokation());
585 exceptions_throw_nullpointerexception();
589 /* Class initialization is done by the JIT compiler. This is ok
590 since a static method always belongs to the declaring class. */
592 if (m->flags & ACC_STATIC) {
593 /* For static methods we reset the object. */
598 /* for convenience */
603 /* For instance methods we make a virtual function table lookup. */
605 resm = method_vftbl_lookup(vftbl, m);
608 STATISTICS(jnicallXmethodnvokation());
610 i = vm_call_method_int_jvalue(resm, o, args);
616 /* _Jv_jni_CallLongMethod ******************************************************
618 Internal function to call Java long methods.
620 *******************************************************************************/
622 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
623 methodinfo *m, va_list ap)
628 STATISTICS(jniinvokation());
631 exceptions_throw_nullpointerexception();
635 /* Class initialization is done by the JIT compiler. This is ok
636 since a static method always belongs to the declaring class. */
638 if (m->flags & ACC_STATIC) {
639 /* For static methods we reset the object. */
644 /* for convenience */
649 /* For instance methods we make a virtual function table lookup. */
651 resm = method_vftbl_lookup(vftbl, m);
654 STATISTICS(jnicallXmethodnvokation());
656 l = vm_call_method_long_valist(resm, o, ap);
662 /* _Jv_jni_CallLongMethodA *****************************************************
664 Internal function to call Java long methods.
666 *******************************************************************************/
668 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
669 methodinfo *m, jvalue *args)
674 STATISTICS(jniinvokation());
677 exceptions_throw_nullpointerexception();
681 /* Class initialization is done by the JIT compiler. This is ok
682 since a static method always belongs to the declaring class. */
684 if (m->flags & ACC_STATIC) {
685 /* For static methods we reset the object. */
690 /* for convenience */
695 /* For instance methods we make a virtual function table lookup. */
697 resm = method_vftbl_lookup(vftbl, m);
700 STATISTICS(jnicallXmethodnvokation());
702 l = vm_call_method_long_jvalue(resm, o, args);
708 /* _Jv_jni_CallFloatMethod *****************************************************
710 Internal function to call Java float methods.
712 *******************************************************************************/
714 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
715 methodinfo *m, va_list ap)
720 /* Class initialization is done by the JIT compiler. This is ok
721 since a static method always belongs to the declaring class. */
723 if (m->flags & ACC_STATIC) {
724 /* For static methods we reset the object. */
729 /* for convenience */
734 /* For instance methods we make a virtual function table lookup. */
736 resm = method_vftbl_lookup(vftbl, m);
739 STATISTICS(jnicallXmethodnvokation());
741 f = vm_call_method_float_valist(resm, o, ap);
747 /* _Jv_jni_CallFloatMethodA ****************************************************
749 Internal function to call Java float methods.
751 *******************************************************************************/
753 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
754 methodinfo *m, jvalue *args)
759 /* Class initialization is done by the JIT compiler. This is ok
760 since a static method always belongs to the declaring class. */
762 if (m->flags & ACC_STATIC) {
763 /* For static methods we reset the object. */
768 /* for convenience */
773 /* For instance methods we make a virtual function table lookup. */
775 resm = method_vftbl_lookup(vftbl, m);
778 STATISTICS(jnicallXmethodnvokation());
780 f = vm_call_method_float_jvalue(resm, o, args);
786 /* _Jv_jni_CallDoubleMethod ****************************************************
788 Internal function to call Java double methods.
790 *******************************************************************************/
792 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
793 methodinfo *m, va_list ap)
798 /* Class initialization is done by the JIT compiler. This is ok
799 since a static method always belongs to the declaring class. */
801 if (m->flags & ACC_STATIC) {
802 /* For static methods we reset the object. */
807 /* for convenience */
812 /* For instance methods we make a virtual function table lookup. */
814 resm = method_vftbl_lookup(vftbl, m);
817 d = vm_call_method_double_valist(resm, o, ap);
823 /* _Jv_jni_CallDoubleMethodA ***************************************************
825 Internal function to call Java double methods.
827 *******************************************************************************/
829 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
830 methodinfo *m, jvalue *args)
835 /* Class initialization is done by the JIT compiler. This is ok
836 since a static method always belongs to the declaring class. */
838 if (m->flags & ACC_STATIC) {
839 /* For static methods we reset the object. */
844 /* for convenience */
849 /* For instance methods we make a virtual function table lookup. */
851 resm = method_vftbl_lookup(vftbl, m);
854 d = vm_call_method_double_jvalue(resm, o, args);
860 /* _Jv_jni_CallVoidMethod ******************************************************
862 Internal function to call Java void methods.
864 *******************************************************************************/
866 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
867 methodinfo *m, va_list ap)
872 exceptions_throw_nullpointerexception();
876 /* Class initialization is done by the JIT compiler. This is ok
877 since a static method always belongs to the declaring class. */
879 if (m->flags & ACC_STATIC) {
880 /* For static methods we reset the object. */
885 /* for convenience */
890 /* For instance methods we make a virtual function table lookup. */
892 resm = method_vftbl_lookup(vftbl, m);
895 STATISTICS(jnicallXmethodnvokation());
897 (void) vm_call_method_valist(resm, o, ap);
901 /* _Jv_jni_CallVoidMethodA *****************************************************
903 Internal function to call Java void methods.
905 *******************************************************************************/
907 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
908 methodinfo *m, jvalue *args)
913 exceptions_throw_nullpointerexception();
917 /* Class initialization is done by the JIT compiler. This is ok
918 since a static method always belongs to the declaring class. */
920 if (m->flags & ACC_STATIC) {
921 /* For static methods we reset the object. */
926 /* for convenience */
931 /* For instance methods we make a virtual function table lookup. */
933 resm = method_vftbl_lookup(vftbl, m);
936 STATISTICS(jnicallXmethodnvokation());
938 (void) vm_call_method_jvalue(resm, o, args);
942 /* _Jv_jni_invokeNative ********************************************************
944 Invoke a method on the given object with the given arguments.
946 For instance methods OBJ must be != NULL and the method is looked up
947 in the vftbl of the object.
949 For static methods, OBJ is ignored.
951 *******************************************************************************/
953 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
954 java_objectarray *params)
958 java_objectheader *ro;
961 java_objectheader *xptr;
964 exceptions_throw_nullpointerexception();
968 argcount = m->parseddesc->paramcount;
969 paramcount = argcount;
971 /* if method is non-static, remove the `this' pointer */
973 if (!(m->flags & ACC_STATIC))
976 /* For instance methods the object has to be an instance of the
977 class the method belongs to. For static methods the obj
978 parameter is ignored. */
980 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
981 exceptions_throw_illegalargumentexception();
985 /* check if we got the right number of arguments */
987 if (((params == NULL) && (paramcount != 0)) ||
988 (params && (params->header.size != paramcount)))
990 exceptions_throw_illegalargumentexception();
994 /* for instance methods we need an object */
996 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
997 /* XXX not sure if that is the correct exception */
998 exceptions_throw_nullpointerexception();
1002 /* for static methods, zero object to make subsequent code simpler */
1003 if (m->flags & ACC_STATIC)
1007 /* for instance methods we must do a vftbl lookup */
1008 resm = method_vftbl_lookup(o->vftbl, m);
1011 /* for static methods, just for convenience */
1015 vmargs = MNEW(vm_arg, argcount);
1017 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
1018 MFREE(vmargs, vm_arg, argcount);
1022 switch (resm->parseddesc->returntype.decltype) {
1024 (void) vm_call_method_vmarg(resm, argcount, vmargs);
1029 case PRIMITIVETYPE_BOOLEAN: {
1031 java_lang_Boolean *bo;
1033 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1035 ro = builtin_new(class_java_lang_Boolean);
1037 /* setting the value of the object direct */
1039 bo = (java_lang_Boolean *) ro;
1044 case PRIMITIVETYPE_BYTE: {
1048 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1050 ro = builtin_new(class_java_lang_Byte);
1052 /* setting the value of the object direct */
1054 bo = (java_lang_Byte *) ro;
1059 case PRIMITIVETYPE_CHAR: {
1061 java_lang_Character *co;
1063 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1065 ro = builtin_new(class_java_lang_Character);
1067 /* setting the value of the object direct */
1069 co = (java_lang_Character *) ro;
1074 case PRIMITIVETYPE_SHORT: {
1076 java_lang_Short *so;
1078 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1080 ro = builtin_new(class_java_lang_Short);
1082 /* setting the value of the object direct */
1084 so = (java_lang_Short *) ro;
1089 case PRIMITIVETYPE_INT: {
1091 java_lang_Integer *io;
1093 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1095 ro = builtin_new(class_java_lang_Integer);
1097 /* setting the value of the object direct */
1099 io = (java_lang_Integer *) ro;
1104 case PRIMITIVETYPE_LONG: {
1108 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1110 ro = builtin_new(class_java_lang_Long);
1112 /* setting the value of the object direct */
1114 lo = (java_lang_Long *) ro;
1119 case PRIMITIVETYPE_FLOAT: {
1121 java_lang_Float *fo;
1123 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1125 ro = builtin_new(class_java_lang_Float);
1127 /* setting the value of the object direct */
1129 fo = (java_lang_Float *) ro;
1134 case PRIMITIVETYPE_DOUBLE: {
1136 java_lang_Double *_do;
1138 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1140 ro = builtin_new(class_java_lang_Double);
1142 /* setting the value of the object direct */
1144 _do = (java_lang_Double *) ro;
1150 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1154 /* if this happens the exception has already been set by
1155 fill_callblock_from_objectarray */
1157 MFREE(vmargs, vm_arg, argcount);
1162 MFREE(vmargs, vm_arg, argcount);
1164 xptr = exceptions_get_exception();
1167 /* clear exception pointer, we are calling JIT code again */
1169 exceptions_clear_exception();
1171 exceptions_throw_invocationtargetexception(xptr);
1178 /* GetVersion ******************************************************************
1180 Returns the major version number in the higher 16 bits and the
1181 minor version number in the lower 16 bits.
1183 *******************************************************************************/
1185 jint _Jv_JNI_GetVersion(JNIEnv *env)
1187 STATISTICS(jniinvokation());
1189 /* we support JNI 1.4 */
1191 return JNI_VERSION_1_4;
1195 /* Class Operations ***********************************************************/
1197 /* DefineClass *****************************************************************
1199 Loads a class from a buffer of raw class data. The buffer
1200 containing the raw class data is not referenced by the VM after the
1201 DefineClass call returns, and it may be discarded if desired.
1203 *******************************************************************************/
1205 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1206 const jbyte *buf, jsize bufLen)
1208 #if defined(ENABLE_JAVASE)
1209 java_lang_ClassLoader *cl;
1210 java_lang_String *s;
1214 STATISTICS(jniinvokation());
1216 cl = (java_lang_ClassLoader *) loader;
1217 s = (java_lang_String *) javastring_new_from_utf_string(name);
1218 ba = (java_bytearray *) buf;
1220 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1223 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1225 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1227 /* keep compiler happy */
1234 /* FindClass *******************************************************************
1236 This function loads a locally-defined class. It searches the
1237 directories and zip files specified by the CLASSPATH environment
1238 variable for the class with the specified name.
1240 *******************************************************************************/
1242 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1244 #if defined(ENABLE_JAVASE)
1249 STATISTICS(jniinvokation());
1251 u = utf_new_char_classname((char *) name);
1253 /* Check stacktrace for classloader, if one found use it,
1254 otherwise use the system classloader. */
1256 /* Quote from the JNI documentation:
1258 In the Java 2 Platform, FindClass locates the class loader
1259 associated with the current native method. If the native code
1260 belongs to a system class, no class loader will be
1261 involved. Otherwise, the proper class loader will be invoked to
1262 load and link the named class. When FindClass is called through
1263 the Invocation Interface, there is no current native method or
1264 its associated class loader. In that case, the result of
1265 ClassLoader.getBaseClassLoader is used." */
1267 cc = stacktrace_getCurrentClass();
1270 c = load_class_from_sysloader(u);
1272 c = load_class_from_classloader(u, cc->classloader);
1280 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1282 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1284 /* keep compiler happy */
1291 /* GetSuperclass ***************************************************************
1293 If clazz represents any class other than the class Object, then
1294 this function returns the object that represents the superclass of
1295 the class specified by clazz.
1297 *******************************************************************************/
1299 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1303 STATISTICS(jniinvokation());
1305 c = ((classinfo *) sub)->super.cls;
1310 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1314 /* IsAssignableFrom ************************************************************
1316 Determines whether an object of sub can be safely cast to sup.
1318 *******************************************************************************/
1320 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1322 java_lang_Class *csup;
1323 java_lang_Class *csub;
1325 csup = (java_lang_Class *) sup;
1326 csub = (java_lang_Class *) sub;
1328 STATISTICS(jniinvokation());
1330 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1334 /* Throw ***********************************************************************
1336 Causes a java.lang.Throwable object to be thrown.
1338 *******************************************************************************/
1340 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1342 java_objectheader *o;
1344 STATISTICS(jniinvokation());
1346 o = (java_objectheader *) obj;
1348 exceptions_set_exception(o);
1354 /* ThrowNew ********************************************************************
1356 Constructs an exception object from the specified class with the
1357 message specified by message and causes that exception to be
1360 *******************************************************************************/
1362 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1365 java_objectheader *o;
1366 java_objectheader *s;
1368 STATISTICS(jniinvokation());
1370 c = (classinfo *) clazz;
1371 s = javastring_new_from_utf_string(msg);
1373 /* instantiate exception object */
1375 o = native_new_and_init_string(c, s);
1380 exceptions_set_exception(o);
1386 /* ExceptionOccurred ***********************************************************
1388 Determines if an exception is being thrown. The exception stays
1389 being thrown until either the native code calls ExceptionClear(),
1390 or the Java code handles the exception.
1392 *******************************************************************************/
1394 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1396 java_objectheader *o;
1398 STATISTICS(jniinvokation());
1400 o = exceptions_get_exception();
1402 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1406 /* ExceptionDescribe ***********************************************************
1408 Prints an exception and a backtrace of the stack to a system
1409 error-reporting channel, such as stderr. This is a convenience
1410 routine provided for debugging.
1412 *******************************************************************************/
1414 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1416 java_objectheader *o;
1419 STATISTICS(jniinvokation());
1421 o = exceptions_get_exception();
1424 /* clear exception, because we are calling jit code again */
1426 exceptions_clear_exception();
1428 /* get printStackTrace method from exception class */
1430 m = class_resolveclassmethod(o->vftbl->class,
1431 utf_printStackTrace,
1437 /* XXX what should we do? */
1440 /* print the stacktrace */
1442 (void) vm_call_method(m, o);
1447 /* ExceptionClear **************************************************************
1449 Clears any exception that is currently being thrown. If no
1450 exception is currently being thrown, this routine has no effect.
1452 *******************************************************************************/
1454 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1456 STATISTICS(jniinvokation());
1458 exceptions_clear_exception();
1462 /* FatalError ******************************************************************
1464 Raises a fatal error and does not expect the VM to recover. This
1465 function does not return.
1467 *******************************************************************************/
1469 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1471 STATISTICS(jniinvokation());
1473 /* this seems to be the best way */
1475 vm_abort("JNI Fatal error: %s", msg);
1479 /* PushLocalFrame **************************************************************
1481 Creates a new local reference frame, in which at least a given
1482 number of local references can be created.
1484 *******************************************************************************/
1486 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1489 localref_table *lrt;
1490 localref_table *nlrt;
1492 STATISTICS(jniinvokation());
1497 /* Allocate new local reference table on Java heap. Calculate the
1498 additional memory we have to allocate. */
1500 if (capacity > LOCALREFTABLE_CAPACITY)
1501 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1505 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1510 /* get current local reference table from thread */
1512 lrt = LOCALREFTABLE;
1514 /* Set up the new local reference table and add it to the local
1517 nlrt->capacity = capacity;
1519 nlrt->localframes = lrt->localframes + 1;
1522 /* store new local reference table in thread */
1524 LOCALREFTABLE = nlrt;
1530 /* PopLocalFrame ***************************************************************
1532 Pops off the current local reference frame, frees all the local
1533 references, and returns a local reference in the previous local
1534 reference frame for the given result object.
1536 *******************************************************************************/
1538 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1540 localref_table *lrt;
1541 localref_table *plrt;
1544 STATISTICS(jniinvokation());
1546 /* get current local reference table from thread */
1548 lrt = LOCALREFTABLE;
1550 localframes = lrt->localframes;
1552 /* Don't delete the top local frame, as this one is allocated in
1553 the native stub on the stack and is freed automagically on
1556 if (localframes == 1)
1557 return _Jv_JNI_NewLocalRef(env, result);
1559 /* release all current local frames */
1561 for (; localframes >= 1; localframes--) {
1562 /* get previous frame */
1566 /* clear all reference entries */
1568 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1572 /* set new local references table */
1577 /* store new local reference table in thread */
1579 LOCALREFTABLE = lrt;
1581 /* add local reference and return the value */
1583 return _Jv_JNI_NewLocalRef(env, result);
1587 /* DeleteLocalRef **************************************************************
1589 Deletes the local reference pointed to by localRef.
1591 *******************************************************************************/
1593 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1595 java_objectheader *o;
1596 localref_table *lrt;
1599 STATISTICS(jniinvokation());
1601 o = (java_objectheader *) localRef;
1603 /* get local reference table (thread specific) */
1605 lrt = LOCALREFTABLE;
1607 /* go through all local frames */
1609 for (; lrt != NULL; lrt = lrt->prev) {
1611 /* and try to remove the reference */
1613 for (i = 0; i < lrt->capacity; i++) {
1614 if (lrt->refs[i] == o) {
1615 lrt->refs[i] = NULL;
1623 /* this should not happen */
1625 /* if (opt_checkjni) */
1626 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1627 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1631 /* IsSameObject ****************************************************************
1633 Tests whether two references refer to the same Java object.
1635 *******************************************************************************/
1637 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1639 STATISTICS(jniinvokation());
1648 /* NewLocalRef *****************************************************************
1650 Creates a new local reference that refers to the same object as ref.
1652 *******************************************************************************/
1654 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1656 localref_table *lrt;
1659 STATISTICS(jniinvokation());
1664 /* get local reference table (thread specific) */
1666 lrt = LOCALREFTABLE;
1668 /* Check if we have space for the requested reference? No,
1669 allocate a new frame. This is actually not what the spec says,
1670 but for compatibility reasons... */
1672 if (lrt->used == lrt->capacity) {
1673 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1676 /* get the new local reference table */
1678 lrt = LOCALREFTABLE;
1681 /* insert the reference */
1683 for (i = 0; i < lrt->capacity; i++) {
1684 if (lrt->refs[i] == NULL) {
1685 lrt->refs[i] = (java_objectheader *) ref;
1692 /* should not happen, just to be sure */
1696 /* keep compiler happy */
1702 /* EnsureLocalCapacity *********************************************************
1704 Ensures that at least a given number of local references can be
1705 created in the current thread
1707 *******************************************************************************/
1709 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1711 localref_table *lrt;
1713 STATISTICS(jniinvokation());
1715 /* get local reference table (thread specific) */
1717 lrt = LOCALREFTABLE;
1719 /* check if capacity elements are available in the local references table */
1721 if ((lrt->used + capacity) > lrt->capacity)
1722 return _Jv_JNI_PushLocalFrame(env, capacity);
1728 /* AllocObject *****************************************************************
1730 Allocates a new Java object without invoking any of the
1731 constructors for the object. Returns a reference to the object.
1733 *******************************************************************************/
1735 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1738 java_objectheader *o;
1740 STATISTICS(jniinvokation());
1742 c = (classinfo *) clazz;
1744 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1745 exceptions_throw_instantiationexception(c);
1751 return _Jv_JNI_NewLocalRef(env, o);
1755 /* NewObject *******************************************************************
1757 Programmers place all arguments that are to be passed to the
1758 constructor immediately following the methodID
1759 argument. NewObject() accepts these arguments and passes them to
1760 the Java method that the programmer wishes to invoke.
1762 *******************************************************************************/
1764 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1766 java_objectheader *o;
1770 STATISTICS(jniinvokation());
1772 m = (methodinfo *) methodID;
1776 o = builtin_new(clazz);
1781 /* call constructor */
1783 va_start(ap, methodID);
1784 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1787 return _Jv_JNI_NewLocalRef(env, o);
1791 /* NewObjectV ******************************************************************
1793 Programmers place all arguments that are to be passed to the
1794 constructor in an args argument of type va_list that immediately
1795 follows the methodID argument. NewObjectV() accepts these
1796 arguments, and, in turn, passes them to the Java method that the
1797 programmer wishes to invoke.
1799 *******************************************************************************/
1801 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1804 java_objectheader *o;
1807 STATISTICS(jniinvokation());
1809 m = (methodinfo *) methodID;
1813 o = builtin_new(clazz);
1818 /* call constructor */
1820 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1822 return _Jv_JNI_NewLocalRef(env, o);
1826 /* NewObjectA *****************************************************************
1828 Programmers place all arguments that are to be passed to the
1829 constructor in an args array of jvalues that immediately follows
1830 the methodID argument. NewObjectA() accepts the arguments in this
1831 array, and, in turn, passes them to the Java method that the
1832 programmer wishes to invoke.
1834 *******************************************************************************/
1836 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1839 java_objectheader *o;
1842 STATISTICS(jniinvokation());
1844 m = (methodinfo *) methodID;
1848 o = builtin_new(clazz);
1853 /* call constructor */
1855 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1857 return _Jv_JNI_NewLocalRef(env, o);
1861 /* GetObjectClass **************************************************************
1863 Returns the class of an object.
1865 *******************************************************************************/
1867 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1869 java_objectheader *o;
1872 STATISTICS(jniinvokation());
1874 o = (java_objectheader *) obj;
1876 if ((o == NULL) || (o->vftbl == NULL))
1879 c = o->vftbl->class;
1881 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1885 /* IsInstanceOf ****************************************************************
1887 Tests whether an object is an instance of a class.
1889 *******************************************************************************/
1891 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1894 java_lang_Object *o;
1896 STATISTICS(jniinvokation());
1898 c = (java_lang_Class *) clazz;
1899 o = (java_lang_Object *) obj;
1901 return _Jv_java_lang_Class_isInstance(c, o);
1905 /* Reflection Support *********************************************************/
1907 /* FromReflectedMethod *********************************************************
1909 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1910 object to a method ID.
1912 *******************************************************************************/
1914 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1916 #if defined(ENABLE_JAVASE)
1921 STATISTICS(jniinvokation());
1926 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1927 java_lang_reflect_Method *rm;
1929 rm = (java_lang_reflect_Method *) method;
1930 c = (classinfo *) (rm->declaringClass);
1933 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1934 java_lang_reflect_Constructor *rc;
1936 rc = (java_lang_reflect_Constructor *) method;
1937 c = (classinfo *) (rc->clazz);
1943 mi = &(c->methods[slot]);
1945 return (jmethodID) mi;
1947 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1949 /* keep compiler happy */
1956 /* FromReflectedField **********************************************************
1958 Converts a java.lang.reflect.Field to a field ID.
1960 *******************************************************************************/
1962 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1964 #if defined(ENABLE_JAVASE)
1965 java_lang_reflect_Field *rf;
1969 STATISTICS(jniinvokation());
1971 rf = (java_lang_reflect_Field *) field;
1976 c = (classinfo *) rf->declaringClass;
1978 f = &(c->fields[rf->slot]);
1980 return (jfieldID) f;
1982 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1984 /* keep compiler happy */
1991 /* ToReflectedMethod ***********************************************************
1993 Converts a method ID derived from cls to an instance of the
1994 java.lang.reflect.Method class or to an instance of the
1995 java.lang.reflect.Constructor class.
1997 *******************************************************************************/
1999 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2002 STATISTICS(jniinvokation());
2004 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2010 /* ToReflectedField ************************************************************
2012 Converts a field ID derived from cls to an instance of the
2013 java.lang.reflect.Field class.
2015 *******************************************************************************/
2017 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2020 STATISTICS(jniinvokation());
2022 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2028 /* Calling Instance Methods ***************************************************/
2030 /* GetMethodID *****************************************************************
2032 Returns the method ID for an instance (nonstatic) method of a class
2033 or interface. The method may be defined in one of the clazz's
2034 superclasses and inherited by clazz. The method is determined by
2035 its name and signature.
2037 GetMethodID() causes an uninitialized class to be initialized.
2039 *******************************************************************************/
2041 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2049 STATISTICS(jniinvokation());
2051 c = (classinfo *) clazz;
2056 if (!(c->state & CLASS_INITIALIZED))
2057 if (!initialize_class(c))
2060 /* try to get the method of the class or one of it's superclasses */
2062 uname = utf_new_char((char *) name);
2063 udesc = utf_new_char((char *) sig);
2065 m = class_resolvemethod(clazz, uname, udesc);
2067 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2068 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2073 return (jmethodID) m;
2077 /* JNI-functions for calling instance methods *********************************/
2079 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2082 java_objectheader *o;
2084 java_objectheader *ret;
2087 o = (java_objectheader *) obj;
2088 m = (methodinfo *) methodID;
2090 va_start(ap, methodID);
2091 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2094 return _Jv_JNI_NewLocalRef(env, ret);
2098 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2101 java_objectheader *o;
2103 java_objectheader *ret;
2105 o = (java_objectheader *) obj;
2106 m = (methodinfo *) methodID;
2108 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2110 return _Jv_JNI_NewLocalRef(env, ret);
2114 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2117 java_objectheader *o;
2119 java_objectheader *ret;
2121 o = (java_objectheader *) obj;
2122 m = (methodinfo *) methodID;
2124 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2126 return _Jv_JNI_NewLocalRef(env, ret);
2130 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2133 java_objectheader *o;
2138 o = (java_objectheader *) obj;
2139 m = (methodinfo *) methodID;
2141 va_start(ap, methodID);
2142 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2149 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2150 jmethodID methodID, va_list args)
2152 java_objectheader *o;
2156 o = (java_objectheader *) obj;
2157 m = (methodinfo *) methodID;
2159 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2165 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2166 jmethodID methodID, jvalue *args)
2168 java_objectheader *o;
2172 o = (java_objectheader *) obj;
2173 m = (methodinfo *) methodID;
2175 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2181 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2183 java_objectheader *o;
2188 o = (java_objectheader *) obj;
2189 m = (methodinfo *) methodID;
2191 va_start(ap, methodID);
2192 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2200 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2203 java_objectheader *o;
2207 o = (java_objectheader *) obj;
2208 m = (methodinfo *) methodID;
2210 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2216 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2219 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2225 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2227 java_objectheader *o;
2232 o = (java_objectheader *) obj;
2233 m = (methodinfo *) methodID;
2235 va_start(ap, methodID);
2236 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2243 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2246 java_objectheader *o;
2250 o = (java_objectheader *) obj;
2251 m = (methodinfo *) methodID;
2253 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2259 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2262 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2268 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2271 java_objectheader *o;
2276 o = (java_objectheader *) obj;
2277 m = (methodinfo *) methodID;
2279 va_start(ap, methodID);
2280 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2287 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2290 java_objectheader *o;
2294 o = (java_objectheader *) obj;
2295 m = (methodinfo *) methodID;
2297 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2303 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2306 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2313 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2315 java_objectheader *o;
2320 o = (java_objectheader *) obj;
2321 m = (methodinfo *) methodID;
2323 va_start(ap, methodID);
2324 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2331 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2334 java_objectheader *o;
2338 o = (java_objectheader *) obj;
2339 m = (methodinfo *) methodID;
2341 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2347 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2350 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2357 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2359 java_objectheader *o;
2364 o = (java_objectheader *) obj;
2365 m = (methodinfo *) methodID;
2367 va_start(ap, methodID);
2368 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2375 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2378 java_objectheader *o;
2382 o = (java_objectheader *) obj;
2383 m = (methodinfo *) methodID;
2385 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2391 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2394 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2401 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2404 java_objectheader *o;
2409 o = (java_objectheader *) obj;
2410 m = (methodinfo *) methodID;
2412 va_start(ap, methodID);
2413 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2420 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2423 java_objectheader *o;
2427 o = (java_objectheader *) obj;
2428 m = (methodinfo *) methodID;
2430 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2436 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2439 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2446 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2449 java_objectheader *o;
2454 o = (java_objectheader *) obj;
2455 m = (methodinfo *) methodID;
2457 va_start(ap, methodID);
2458 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2465 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2468 java_objectheader *o;
2472 o = (java_objectheader *) obj;
2473 m = (methodinfo *) methodID;
2475 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2481 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2484 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2491 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2493 java_objectheader *o;
2497 o = (java_objectheader *) obj;
2498 m = (methodinfo *) methodID;
2500 va_start(ap, methodID);
2501 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2506 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2509 java_objectheader *o;
2512 o = (java_objectheader *) obj;
2513 m = (methodinfo *) methodID;
2515 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2519 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2522 java_objectheader *o;
2525 o = (java_objectheader *) obj;
2526 m = (methodinfo *) methodID;
2528 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2533 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2534 jclass clazz, jmethodID methodID,
2537 java_objectheader *o;
2540 java_objectheader *r;
2543 o = (java_objectheader *) obj;
2544 c = (classinfo *) clazz;
2545 m = (methodinfo *) methodID;
2547 va_start(ap, methodID);
2548 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2551 return _Jv_JNI_NewLocalRef(env, r);
2555 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2556 jclass clazz, jmethodID methodID,
2559 java_objectheader *o;
2562 java_objectheader *r;
2564 o = (java_objectheader *) obj;
2565 c = (classinfo *) clazz;
2566 m = (methodinfo *) methodID;
2568 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2570 return _Jv_JNI_NewLocalRef(env, r);
2574 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2575 jclass clazz, jmethodID methodID,
2578 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2580 return _Jv_JNI_NewLocalRef(env, NULL);
2585 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2586 jclass clazz, jmethodID methodID,
2589 java_objectheader *o;
2595 o = (java_objectheader *) obj;
2596 c = (classinfo *) clazz;
2597 m = (methodinfo *) methodID;
2599 va_start(ap, methodID);
2600 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2607 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2608 jclass clazz, jmethodID methodID,
2611 java_objectheader *o;
2616 o = (java_objectheader *) obj;
2617 c = (classinfo *) clazz;
2618 m = (methodinfo *) methodID;
2620 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2626 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2627 jclass clazz, jmethodID methodID,
2630 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2636 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2637 jmethodID methodID, ...)
2639 java_objectheader *o;
2645 o = (java_objectheader *) obj;
2646 c = (classinfo *) clazz;
2647 m = (methodinfo *) methodID;
2649 va_start(ap, methodID);
2650 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2657 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2658 jmethodID methodID, va_list args)
2660 java_objectheader *o;
2665 o = (java_objectheader *) obj;
2666 c = (classinfo *) clazz;
2667 m = (methodinfo *) methodID;
2669 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2675 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2676 jmethodID methodID, jvalue *args)
2678 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2685 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2686 jmethodID methodID, ...)
2688 java_objectheader *o;
2694 o = (java_objectheader *) obj;
2695 c = (classinfo *) clazz;
2696 m = (methodinfo *) methodID;
2698 va_start(ap, methodID);
2699 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2706 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2707 jmethodID methodID, va_list args)
2709 java_objectheader *o;
2714 o = (java_objectheader *) obj;
2715 c = (classinfo *) clazz;
2716 m = (methodinfo *) methodID;
2718 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2724 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2725 jmethodID methodID, jvalue *args)
2727 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2734 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2735 jclass clazz, jmethodID methodID, ...)
2737 java_objectheader *o;
2743 o = (java_objectheader *) obj;
2744 c = (classinfo *) clazz;
2745 m = (methodinfo *) methodID;
2747 va_start(ap, methodID);
2748 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2755 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2756 jclass clazz, jmethodID methodID,
2759 java_objectheader *o;
2764 o = (java_objectheader *) obj;
2765 c = (classinfo *) clazz;
2766 m = (methodinfo *) methodID;
2768 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2774 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2775 jclass clazz, jmethodID methodID,
2778 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2785 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2786 jmethodID methodID, ...)
2788 java_objectheader *o;
2794 o = (java_objectheader *) obj;
2795 c = (classinfo *) clazz;
2796 m = (methodinfo *) methodID;
2798 va_start(ap, methodID);
2799 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2806 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2807 jmethodID methodID, va_list args)
2809 java_objectheader *o;
2814 o = (java_objectheader *) obj;
2815 c = (classinfo *) clazz;
2816 m = (methodinfo *) methodID;
2818 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2824 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2825 jmethodID methodID, jvalue *args)
2827 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2834 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2835 jmethodID methodID, ...)
2837 java_objectheader *o;
2843 o = (java_objectheader *) obj;
2844 c = (classinfo *) clazz;
2845 m = (methodinfo *) methodID;
2847 va_start(ap, methodID);
2848 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2855 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2856 jmethodID methodID, va_list args)
2858 java_objectheader *o;
2863 o = (java_objectheader *) obj;
2864 c = (classinfo *) clazz;
2865 m = (methodinfo *) methodID;
2867 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2873 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2874 jmethodID methodID, jvalue *args)
2876 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2883 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2884 jclass clazz, jmethodID methodID, ...)
2886 java_objectheader *o;
2892 o = (java_objectheader *) obj;
2893 c = (classinfo *) clazz;
2894 m = (methodinfo *) methodID;
2896 va_start(ap, methodID);
2897 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2904 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2905 jclass clazz, jmethodID methodID,
2908 java_objectheader *o;
2913 o = (java_objectheader *) obj;
2914 c = (classinfo *) clazz;
2915 m = (methodinfo *) methodID;
2917 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2923 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2924 jclass clazz, jmethodID methodID,
2927 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2934 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2935 jclass clazz, jmethodID methodID,
2938 java_objectheader *o;
2944 o = (java_objectheader *) obj;
2945 c = (classinfo *) clazz;
2946 m = (methodinfo *) methodID;
2948 va_start(ap, methodID);
2949 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2956 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2957 jclass clazz, jmethodID methodID,
2960 java_objectheader *o;
2965 o = (java_objectheader *) obj;
2966 c = (classinfo *) clazz;
2967 m = (methodinfo *) methodID;
2969 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2975 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2976 jclass clazz, jmethodID methodID,
2979 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2986 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2987 jmethodID methodID, ...)
2989 java_objectheader *o;
2994 o = (java_objectheader *) obj;
2995 c = (classinfo *) clazz;
2996 m = (methodinfo *) methodID;
2998 va_start(ap, methodID);
2999 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3004 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3005 jmethodID methodID, va_list args)
3007 java_objectheader *o;
3011 o = (java_objectheader *) obj;
3012 c = (classinfo *) clazz;
3013 m = (methodinfo *) methodID;
3015 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3019 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3020 jmethodID methodID, jvalue * args)
3022 java_objectheader *o;
3026 o = (java_objectheader *) obj;
3027 c = (classinfo *) clazz;
3028 m = (methodinfo *) methodID;
3030 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3034 /* Accessing Fields of Objects ************************************************/
3036 /* GetFieldID ******************************************************************
3038 Returns the field ID for an instance (nonstatic) field of a
3039 class. The field is specified by its name and signature. The
3040 Get<type>Field and Set<type>Field families of accessor functions
3041 use field IDs to retrieve object fields.
3043 *******************************************************************************/
3045 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3053 STATISTICS(jniinvokation());
3055 c = (classinfo *) clazz;
3057 uname = utf_new_char((char *) name);
3058 udesc = utf_new_char((char *) sig);
3060 f = class_findfield(clazz, uname, udesc);
3063 exceptions_throw_nosuchfielderror(c, uname);
3065 return (jfieldID) f;
3069 /* Get<type>Field Routines *****************************************************
3071 This family of accessor routines returns the value of an instance
3072 (nonstatic) field of an object. The field to access is specified by
3073 a field ID obtained by calling GetFieldID().
3075 *******************************************************************************/
3077 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3079 java_objectheader *o;
3081 STATISTICS(jniinvokation());
3083 o = GET_FIELD(obj, java_objectheader*, fieldID);
3085 return _Jv_JNI_NewLocalRef(env, o);
3089 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3093 STATISTICS(jniinvokation());
3095 i = GET_FIELD(obj, s4, fieldID);
3097 return (jboolean) i;
3101 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3105 STATISTICS(jniinvokation());
3107 i = GET_FIELD(obj, s4, fieldID);
3113 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3117 STATISTICS(jniinvokation());
3119 i = GET_FIELD(obj, s4, fieldID);
3125 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3129 STATISTICS(jniinvokation());
3131 i = GET_FIELD(obj, s4, fieldID);
3137 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3139 java_objectheader *o;
3143 STATISTICS(jniinvokation());
3145 o = (java_objectheader *) obj;
3146 f = (fieldinfo *) fieldID;
3148 i = GET_FIELD(o, s4, f);
3154 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3158 STATISTICS(jniinvokation());
3160 l = GET_FIELD(obj, s8, fieldID);
3166 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3170 STATISTICS(jniinvokation());
3172 f = GET_FIELD(obj, float, fieldID);
3178 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3182 STATISTICS(jniinvokation());
3184 d = GET_FIELD(obj, double, fieldID);
3190 /* Set<type>Field Routines *****************************************************
3192 This family of accessor routines sets the value of an instance
3193 (nonstatic) field of an object. The field to access is specified by
3194 a field ID obtained by calling GetFieldID().
3196 *******************************************************************************/
3198 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3201 STATISTICS(jniinvokation());
3203 SET_FIELD(obj, java_objectheader*, fieldID, value);
3207 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3210 STATISTICS(jniinvokation());
3212 SET_FIELD(obj, s4, fieldID, value);
3216 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3219 STATISTICS(jniinvokation());
3221 SET_FIELD(obj, s4, fieldID, value);
3225 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3228 STATISTICS(jniinvokation());
3230 SET_FIELD(obj, s4, fieldID, value);
3234 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3237 STATISTICS(jniinvokation());
3239 SET_FIELD(obj, s4, fieldID, value);
3243 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3245 STATISTICS(jniinvokation());
3247 SET_FIELD(obj, s4, fieldID, value);
3251 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3254 STATISTICS(jniinvokation());
3256 SET_FIELD(obj, s8, fieldID, value);
3260 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3263 STATISTICS(jniinvokation());
3265 SET_FIELD(obj, float, fieldID, value);
3269 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3272 STATISTICS(jniinvokation());
3274 SET_FIELD(obj, double, fieldID, value);
3278 /* Calling Static Methods *****************************************************/
3280 /* GetStaticMethodID ***********************************************************
3282 Returns the method ID for a static method of a class. The method is
3283 specified by its name and signature.
3285 GetStaticMethodID() causes an uninitialized class to be
3288 *******************************************************************************/
3290 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3298 STATISTICS(jniinvokation());
3300 c = (classinfo *) clazz;
3305 if (!(c->state & CLASS_INITIALIZED))
3306 if (!initialize_class(c))
3309 /* try to get the static method of the class */
3311 uname = utf_new_char((char *) name);
3312 udesc = utf_new_char((char *) sig);
3314 m = class_resolvemethod(c, uname, udesc);
3316 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3317 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3322 return (jmethodID) m;
3326 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3327 jmethodID methodID, ...)
3330 java_objectheader *o;
3333 m = (methodinfo *) methodID;
3335 va_start(ap, methodID);
3336 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3339 return _Jv_JNI_NewLocalRef(env, o);
3343 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3344 jmethodID methodID, va_list args)
3347 java_objectheader *o;
3349 m = (methodinfo *) methodID;
3351 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3353 return _Jv_JNI_NewLocalRef(env, o);
3357 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3358 jmethodID methodID, jvalue *args)
3361 java_objectheader *o;
3363 m = (methodinfo *) methodID;
3365 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3367 return _Jv_JNI_NewLocalRef(env, o);
3371 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3372 jmethodID methodID, ...)
3378 m = (methodinfo *) methodID;
3380 va_start(ap, methodID);
3381 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3388 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3389 jmethodID methodID, va_list args)
3394 m = (methodinfo *) methodID;
3396 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3402 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3403 jmethodID methodID, jvalue *args)
3408 m = (methodinfo *) methodID;
3410 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3416 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3417 jmethodID methodID, ...)
3423 m = (methodinfo *) methodID;
3425 va_start(ap, methodID);
3426 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3433 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3434 jmethodID methodID, va_list args)
3439 m = (methodinfo *) methodID;
3441 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3447 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3448 jmethodID methodID, jvalue *args)
3453 m = (methodinfo *) methodID;
3455 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3461 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3462 jmethodID methodID, ...)
3468 m = (methodinfo *) methodID;
3470 va_start(ap, methodID);
3471 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3478 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3479 jmethodID methodID, va_list args)
3484 m = (methodinfo *) methodID;
3486 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3492 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3493 jmethodID methodID, jvalue *args)
3498 m = (methodinfo *) methodID;
3500 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3506 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3507 jmethodID methodID, ...)
3513 m = (methodinfo *) methodID;
3515 va_start(ap, methodID);
3516 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3523 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3524 jmethodID methodID, va_list args)
3529 m = (methodinfo *) methodID;
3531 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3537 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3538 jmethodID methodID, jvalue *args)
3543 m = (methodinfo *) methodID;
3545 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3551 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3558 m = (methodinfo *) methodID;
3560 va_start(ap, methodID);
3561 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3568 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3569 jmethodID methodID, va_list args)
3574 m = (methodinfo *) methodID;
3576 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3582 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3583 jmethodID methodID, jvalue *args)
3588 m = (methodinfo *) methodID;
3590 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3596 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3597 jmethodID methodID, ...)
3603 m = (methodinfo *) methodID;
3605 va_start(ap, methodID);
3606 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3613 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3614 jmethodID methodID, va_list args)
3619 m = (methodinfo *) methodID;
3621 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3627 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3628 jmethodID methodID, jvalue *args)
3633 m = (methodinfo *) methodID;
3635 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3642 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3643 jmethodID methodID, ...)
3649 m = (methodinfo *) methodID;
3651 va_start(ap, methodID);
3652 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3659 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3660 jmethodID methodID, va_list args)
3665 m = (methodinfo *) methodID;
3667 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3673 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3674 jmethodID methodID, jvalue *args)
3679 m = (methodinfo *) methodID;
3681 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3687 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3688 jmethodID methodID, ...)
3694 m = (methodinfo *) methodID;
3696 va_start(ap, methodID);
3697 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3704 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3705 jmethodID methodID, va_list args)
3710 m = (methodinfo *) methodID;
3712 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3718 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3719 jmethodID methodID, jvalue *args)
3724 m = (methodinfo *) methodID;
3726 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3732 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3733 jmethodID methodID, ...)
3738 m = (methodinfo *) methodID;
3740 va_start(ap, methodID);
3741 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3746 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3747 jmethodID methodID, va_list args)
3751 m = (methodinfo *) methodID;
3753 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3757 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3758 jmethodID methodID, jvalue * args)
3762 m = (methodinfo *) methodID;
3764 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3768 /* Accessing Static Fields ****************************************************/
3770 /* GetStaticFieldID ************************************************************
3772 Returns the field ID for a static field of a class. The field is
3773 specified by its name and signature. The GetStatic<type>Field and
3774 SetStatic<type>Field families of accessor functions use field IDs
3775 to retrieve static fields.
3777 *******************************************************************************/
3779 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3787 STATISTICS(jniinvokation());
3789 c = (classinfo *) clazz;
3791 uname = utf_new_char((char *) name);
3792 usig = utf_new_char((char *) sig);
3794 f = class_findfield(clazz, uname, usig);
3797 exceptions_throw_nosuchfielderror(c, uname);
3799 return (jfieldID) f;
3803 /* GetStatic<type>Field ********************************************************
3805 This family of accessor routines returns the value of a static
3808 *******************************************************************************/
3810 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3816 STATISTICS(jniinvokation());
3818 c = (classinfo *) clazz;
3819 f = (fieldinfo *) fieldID;
3821 if (!(c->state & CLASS_INITIALIZED))
3822 if (!initialize_class(c))
3825 return _Jv_JNI_NewLocalRef(env, f->value.a);
3829 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3835 STATISTICS(jniinvokation());
3837 c = (classinfo *) clazz;
3838 f = (fieldinfo *) fieldID;
3840 if (!(c->state & CLASS_INITIALIZED))
3841 if (!initialize_class(c))
3848 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3853 STATISTICS(jniinvokation());
3855 c = (classinfo *) clazz;
3856 f = (fieldinfo *) fieldID;
3858 if (!(c->state & CLASS_INITIALIZED))
3859 if (!initialize_class(c))
3866 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3871 STATISTICS(jniinvokation());
3873 c = (classinfo *) clazz;
3874 f = (fieldinfo *) fieldID;
3876 if (!(c->state & CLASS_INITIALIZED))
3877 if (!initialize_class(c))
3884 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3889 STATISTICS(jniinvokation());
3891 c = (classinfo *) clazz;
3892 f = (fieldinfo *) fieldID;
3894 if (!(c->state & CLASS_INITIALIZED))
3895 if (!initialize_class(c))
3902 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3907 STATISTICS(jniinvokation());
3909 c = (classinfo *) clazz;
3910 f = (fieldinfo *) fieldID;
3912 if (!(c->state & CLASS_INITIALIZED))
3913 if (!initialize_class(c))
3920 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3925 STATISTICS(jniinvokation());
3927 c = (classinfo *) clazz;
3928 f = (fieldinfo *) fieldID;
3930 if (!(c->state & CLASS_INITIALIZED))
3931 if (!initialize_class(c))
3938 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3943 STATISTICS(jniinvokation());
3945 c = (classinfo *) clazz;
3946 f = (fieldinfo *) fieldID;
3948 if (!(c->state & CLASS_INITIALIZED))
3949 if (!initialize_class(c))
3956 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3962 STATISTICS(jniinvokation());
3964 c = (classinfo *) clazz;
3965 f = (fieldinfo *) fieldID;
3967 if (!(c->state & CLASS_INITIALIZED))
3968 if (!initialize_class(c))
3975 /* SetStatic<type>Field *******************************************************
3977 This family of accessor routines sets the value of a static field
3980 *******************************************************************************/
3982 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3988 STATISTICS(jniinvokation());
3990 c = (classinfo *) clazz;
3991 f = (fieldinfo *) fieldID;
3993 if (!(c->state & CLASS_INITIALIZED))
3994 if (!initialize_class(c))
4001 void _Jv_JNI_SetStaticBooleanField(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 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4026 STATISTICS(jniinvokation());
4028 c = (classinfo *) clazz;
4029 f = (fieldinfo *) fieldID;
4031 if (!(c->state & CLASS_INITIALIZED))
4032 if (!initialize_class(c))
4039 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4045 STATISTICS(jniinvokation());
4047 c = (classinfo *) clazz;
4048 f = (fieldinfo *) fieldID;
4050 if (!(c->state & CLASS_INITIALIZED))
4051 if (!initialize_class(c))
4058 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4064 STATISTICS(jniinvokation());
4066 c = (classinfo *) clazz;
4067 f = (fieldinfo *) fieldID;
4069 if (!(c->state & CLASS_INITIALIZED))
4070 if (!initialize_class(c))
4077 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4083 STATISTICS(jniinvokation());
4085 c = (classinfo *) clazz;
4086 f = (fieldinfo *) fieldID;
4088 if (!(c->state & CLASS_INITIALIZED))
4089 if (!initialize_class(c))
4096 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4102 STATISTICS(jniinvokation());
4104 c = (classinfo *) clazz;
4105 f = (fieldinfo *) fieldID;
4107 if (!(c->state & CLASS_INITIALIZED))
4108 if (!initialize_class(c))
4115 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4121 STATISTICS(jniinvokation());
4123 c = (classinfo *) clazz;
4124 f = (fieldinfo *) fieldID;
4126 if (!(c->state & CLASS_INITIALIZED))
4127 if (!initialize_class(c))
4134 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4140 STATISTICS(jniinvokation());
4142 c = (classinfo *) clazz;
4143 f = (fieldinfo *) fieldID;
4145 if (!(c->state & CLASS_INITIALIZED))
4146 if (!initialize_class(c))
4153 /* String Operations **********************************************************/
4155 /* NewString *******************************************************************
4157 Create new java.lang.String object from an array of Unicode
4160 *******************************************************************************/
4162 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4164 java_lang_String *s;
4168 STATISTICS(jniinvokation());
4170 s = (java_lang_String *) builtin_new(class_java_lang_String);
4171 a = builtin_newarray_char(len);
4173 /* javastring or characterarray could not be created */
4174 if ((a == NULL) || (s == NULL))
4178 for (i = 0; i < len; i++)
4179 a->data[i] = buf[i];
4185 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4189 static jchar emptyStringJ[]={0,0};
4191 /* GetStringLength *************************************************************
4193 Returns the length (the count of Unicode characters) of a Java
4196 *******************************************************************************/
4198 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4200 return ((java_lang_String *) str)->count;
4204 /******************** convertes javastring to u2-array ****************************/
4206 u2 *javastring_tou2(jstring so)
4208 java_lang_String *s;
4213 STATISTICS(jniinvokation());
4215 s = (java_lang_String *) so;
4225 /* allocate memory */
4227 stringbuffer = MNEW(u2, s->count + 1);
4231 for (i = 0; i < s->count; i++)
4232 stringbuffer[i] = a->data[s->offset + i];
4234 /* terminate string */
4236 stringbuffer[i] = '\0';
4238 return stringbuffer;
4242 /* GetStringChars **************************************************************
4244 Returns a pointer to the array of Unicode characters of the
4245 string. This pointer is valid until ReleaseStringChars() is called.
4247 *******************************************************************************/
4249 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4253 STATISTICS(jniinvokation());
4255 jc = javastring_tou2(str);
4267 return emptyStringJ;
4271 /* ReleaseStringChars **********************************************************
4273 Informs the VM that the native code no longer needs access to
4274 chars. The chars argument is a pointer obtained from string using
4277 *******************************************************************************/
4279 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4281 STATISTICS(jniinvokation());
4283 if (chars == emptyStringJ)
4286 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4290 /* NewStringUTF ****************************************************************
4292 Constructs a new java.lang.String object from an array of UTF-8
4295 *******************************************************************************/
4297 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4299 java_lang_String *s;
4301 STATISTICS(jniinvokation());
4303 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4305 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4309 /****************** returns the utf8 length in bytes of a string *******************/
4311 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4313 java_lang_String *s = (java_lang_String*) string;
4315 STATISTICS(jniinvokation());
4317 return (jsize) u2_utflength(s->value->data, s->count);
4321 /* GetStringUTFChars ***********************************************************
4323 Returns a pointer to an array of UTF-8 characters of the
4324 string. This array is valid until it is released by
4325 ReleaseStringUTFChars().
4327 *******************************************************************************/
4329 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4334 STATISTICS(jniinvokation());
4342 u = javastring_toutf((java_objectheader *) string, false);
4351 /* ReleaseStringUTFChars *******************************************************
4353 Informs the VM that the native code no longer needs access to
4354 utf. The utf argument is a pointer derived from string using
4355 GetStringUTFChars().
4357 *******************************************************************************/
4359 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4361 STATISTICS(jniinvokation());
4363 /* XXX we don't release utf chars right now, perhaps that should be done
4364 later. Since there is always one reference the garbage collector will
4369 /* Array Operations ***********************************************************/
4371 /* GetArrayLength **************************************************************
4373 Returns the number of elements in the array.
4375 *******************************************************************************/
4377 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4379 java_arrayheader *a;
4381 STATISTICS(jniinvokation());
4383 a = (java_arrayheader *) array;
4389 /* NewObjectArray **************************************************************
4391 Constructs a new array holding objects in class elementClass. All
4392 elements are initially set to initialElement.
4394 *******************************************************************************/
4396 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4397 jclass elementClass, jobject initialElement)
4399 java_objectarray *oa;
4402 STATISTICS(jniinvokation());
4405 exceptions_throw_negativearraysizeexception();
4409 oa = builtin_anewarray(length, elementClass);
4414 /* set all elements to initialElement */
4416 for (i = 0; i < length; i++)
4417 oa->data[i] = initialElement;
4419 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4423 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4426 java_objectarray *oa;
4429 STATISTICS(jniinvokation());
4431 oa = (java_objectarray *) array;
4433 if (index >= oa->header.size) {
4434 exceptions_throw_arrayindexoutofboundsexception();
4438 o = oa->data[index];
4440 return _Jv_JNI_NewLocalRef(env, o);
4444 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4445 jsize index, jobject val)
4447 java_objectarray *oa;
4448 java_objectheader *o;
4450 STATISTICS(jniinvokation());
4452 oa = (java_objectarray *) array;
4453 o = (java_objectheader *) val;
4455 if (index >= oa->header.size) {
4456 exceptions_throw_arrayindexoutofboundsexception();
4460 /* check if the class of value is a subclass of the element class
4463 if (!builtin_canstore(oa, o))
4466 oa->data[index] = val;
4470 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4472 java_booleanarray *ba;
4474 STATISTICS(jniinvokation());
4477 exceptions_throw_negativearraysizeexception();
4481 ba = builtin_newarray_boolean(len);
4483 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4487 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4491 STATISTICS(jniinvokation());
4494 exceptions_throw_negativearraysizeexception();
4498 ba = builtin_newarray_byte(len);
4500 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4504 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4508 STATISTICS(jniinvokation());
4511 exceptions_throw_negativearraysizeexception();
4515 ca = builtin_newarray_char(len);
4517 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4521 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4523 java_shortarray *sa;
4525 STATISTICS(jniinvokation());
4528 exceptions_throw_negativearraysizeexception();
4532 sa = builtin_newarray_short(len);
4534 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4538 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4542 STATISTICS(jniinvokation());
4545 exceptions_throw_negativearraysizeexception();
4549 ia = builtin_newarray_int(len);
4551 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4555 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4559 STATISTICS(jniinvokation());
4562 exceptions_throw_negativearraysizeexception();
4566 la = builtin_newarray_long(len);
4568 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4572 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4574 java_floatarray *fa;
4576 STATISTICS(jniinvokation());
4579 exceptions_throw_negativearraysizeexception();
4583 fa = builtin_newarray_float(len);
4585 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4589 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4591 java_doublearray *da;
4593 STATISTICS(jniinvokation());
4596 exceptions_throw_negativearraysizeexception();
4600 da = builtin_newarray_double(len);
4602 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4606 /* Get<PrimitiveType>ArrayElements *********************************************
4608 A family of functions that returns the body of the primitive array.
4610 *******************************************************************************/
4612 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4615 java_booleanarray *ba;
4617 STATISTICS(jniinvokation());
4619 ba = (java_booleanarray *) array;
4622 *isCopy = JNI_FALSE;
4628 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4633 STATISTICS(jniinvokation());
4635 ba = (java_bytearray *) array;
4638 *isCopy = JNI_FALSE;
4644 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4649 STATISTICS(jniinvokation());
4651 ca = (java_chararray *) array;
4654 *isCopy = JNI_FALSE;
4660 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4663 java_shortarray *sa;
4665 STATISTICS(jniinvokation());
4667 sa = (java_shortarray *) array;
4670 *isCopy = JNI_FALSE;
4676 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4681 STATISTICS(jniinvokation());
4683 ia = (java_intarray *) array;
4686 *isCopy = JNI_FALSE;
4692 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4697 STATISTICS(jniinvokation());
4699 la = (java_longarray *) array;
4702 *isCopy = JNI_FALSE;
4704 /* We cast this one to prevent a compiler warning on 64-bit
4705 systems since GNU Classpath typedef jlong to long long. */
4707 return (jlong *) la->data;
4711 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4714 java_floatarray *fa;
4716 STATISTICS(jniinvokation());
4718 fa = (java_floatarray *) array;
4721 *isCopy = JNI_FALSE;
4727 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4730 java_doublearray *da;
4732 STATISTICS(jniinvokation());
4734 da = (java_doublearray *) array;
4737 *isCopy = JNI_FALSE;
4743 /* Release<PrimitiveType>ArrayElements *****************************************
4745 A family of functions that informs the VM that the native code no
4746 longer needs access to elems. The elems argument is a pointer
4747 derived from array using the corresponding
4748 Get<PrimitiveType>ArrayElements() function. If necessary, this
4749 function copies back all changes made to elems to the original
4752 *******************************************************************************/
4754 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4755 jboolean *elems, jint mode)
4757 java_booleanarray *ba;
4759 STATISTICS(jniinvokation());
4761 ba = (java_booleanarray *) array;
4763 if (elems != ba->data) {
4766 MCOPY(ba->data, elems, u1, ba->header.size);
4769 MCOPY(ba->data, elems, u1, ba->header.size);
4770 /* XXX TWISTI how should it be freed? */
4773 /* XXX TWISTI how should it be freed? */
4780 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4781 jbyte *elems, jint mode)
4785 STATISTICS(jniinvokation());
4787 ba = (java_bytearray *) array;
4789 if (elems != ba->data) {
4792 MCOPY(ba->data, elems, s1, ba->header.size);
4795 MCOPY(ba->data, elems, s1, ba->header.size);
4796 /* XXX TWISTI how should it be freed? */
4799 /* XXX TWISTI how should it be freed? */
4806 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4807 jchar *elems, jint mode)
4811 STATISTICS(jniinvokation());
4813 ca = (java_chararray *) array;
4815 if (elems != ca->data) {
4818 MCOPY(ca->data, elems, u2, ca->header.size);
4821 MCOPY(ca->data, elems, u2, ca->header.size);
4822 /* XXX TWISTI how should it be freed? */
4825 /* XXX TWISTI how should it be freed? */
4832 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4833 jshort *elems, jint mode)
4835 java_shortarray *sa;
4837 STATISTICS(jniinvokation());
4839 sa = (java_shortarray *) array;
4841 if (elems != sa->data) {
4844 MCOPY(sa->data, elems, s2, sa->header.size);
4847 MCOPY(sa->data, elems, s2, sa->header.size);
4848 /* XXX TWISTI how should it be freed? */
4851 /* XXX TWISTI how should it be freed? */
4858 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4863 STATISTICS(jniinvokation());
4865 ia = (java_intarray *) array;
4867 if (elems != ia->data) {
4870 MCOPY(ia->data, elems, s4, ia->header.size);
4873 MCOPY(ia->data, elems, s4, ia->header.size);
4874 /* XXX TWISTI how should it be freed? */
4877 /* XXX TWISTI how should it be freed? */
4884 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4885 jlong *elems, jint mode)
4889 STATISTICS(jniinvokation());
4891 la = (java_longarray *) array;
4893 /* We cast this one to prevent a compiler warning on 64-bit
4894 systems since GNU Classpath typedef jlong to long long. */
4896 if ((s8 *) elems != la->data) {
4899 MCOPY(la->data, elems, s8, la->header.size);
4902 MCOPY(la->data, elems, s8, la->header.size);
4903 /* XXX TWISTI how should it be freed? */
4906 /* XXX TWISTI how should it be freed? */
4913 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4914 jfloat *elems, jint mode)
4916 java_floatarray *fa;
4918 STATISTICS(jniinvokation());
4920 fa = (java_floatarray *) array;
4922 if (elems != fa->data) {
4925 MCOPY(fa->data, elems, float, fa->header.size);
4928 MCOPY(fa->data, elems, float, fa->header.size);
4929 /* XXX TWISTI how should it be freed? */
4932 /* XXX TWISTI how should it be freed? */
4939 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4940 jdouble *elems, jint mode)
4942 java_doublearray *da;
4944 STATISTICS(jniinvokation());
4946 da = (java_doublearray *) array;
4948 if (elems != da->data) {
4951 MCOPY(da->data, elems, double, da->header.size);
4954 MCOPY(da->data, elems, double, da->header.size);
4955 /* XXX TWISTI how should it be freed? */
4958 /* XXX TWISTI how should it be freed? */
4965 /* Get<PrimitiveType>ArrayRegion **********************************************
4967 A family of functions that copies a region of a primitive array
4970 *******************************************************************************/
4972 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4973 jsize start, jsize len, jboolean *buf)
4975 java_booleanarray *ba;
4977 STATISTICS(jniinvokation());
4979 ba = (java_booleanarray *) array;
4981 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4982 exceptions_throw_arrayindexoutofboundsexception();
4984 MCOPY(buf, &ba->data[start], u1, len);
4988 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4989 jsize len, jbyte *buf)
4993 STATISTICS(jniinvokation());
4995 ba = (java_bytearray *) array;
4997 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4998 exceptions_throw_arrayindexoutofboundsexception();
5000 MCOPY(buf, &ba->data[start], s1, len);
5004 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5005 jsize len, jchar *buf)
5009 STATISTICS(jniinvokation());
5011 ca = (java_chararray *) array;
5013 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5014 exceptions_throw_arrayindexoutofboundsexception();
5016 MCOPY(buf, &ca->data[start], u2, len);
5020 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5021 jsize len, jshort *buf)
5023 java_shortarray *sa;
5025 STATISTICS(jniinvokation());
5027 sa = (java_shortarray *) array;
5029 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5030 exceptions_throw_arrayindexoutofboundsexception();
5032 MCOPY(buf, &sa->data[start], s2, len);
5036 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5037 jsize len, jint *buf)
5041 STATISTICS(jniinvokation());
5043 ia = (java_intarray *) array;
5045 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5046 exceptions_throw_arrayindexoutofboundsexception();
5048 MCOPY(buf, &ia->data[start], s4, len);
5052 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5053 jsize len, jlong *buf)
5057 STATISTICS(jniinvokation());
5059 la = (java_longarray *) array;
5061 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5062 exceptions_throw_arrayindexoutofboundsexception();
5064 MCOPY(buf, &la->data[start], s8, len);
5068 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5069 jsize len, jfloat *buf)
5071 java_floatarray *fa;
5073 STATISTICS(jniinvokation());
5075 fa = (java_floatarray *) array;
5077 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5078 exceptions_throw_arrayindexoutofboundsexception();
5080 MCOPY(buf, &fa->data[start], float, len);
5084 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5085 jsize len, jdouble *buf)
5087 java_doublearray *da;
5089 STATISTICS(jniinvokation());
5091 da = (java_doublearray *) array;
5093 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5094 exceptions_throw_arrayindexoutofboundsexception();
5096 MCOPY(buf, &da->data[start], double, len);
5100 /* Set<PrimitiveType>ArrayRegion **********************************************
5102 A family of functions that copies back a region of a primitive
5103 array from a buffer.
5105 *******************************************************************************/
5107 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5108 jsize start, jsize len, jboolean *buf)
5110 java_booleanarray *ba;
5112 STATISTICS(jniinvokation());
5114 ba = (java_booleanarray *) array;
5116 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5117 exceptions_throw_arrayindexoutofboundsexception();
5119 MCOPY(&ba->data[start], buf, u1, len);
5123 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5124 jsize len, jbyte *buf)
5128 STATISTICS(jniinvokation());
5130 ba = (java_bytearray *) array;
5132 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5133 exceptions_throw_arrayindexoutofboundsexception();
5135 MCOPY(&ba->data[start], buf, s1, len);
5139 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5140 jsize len, jchar *buf)
5144 STATISTICS(jniinvokation());
5146 ca = (java_chararray *) array;
5148 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5149 exceptions_throw_arrayindexoutofboundsexception();
5151 MCOPY(&ca->data[start], buf, u2, len);
5155 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5156 jsize len, jshort *buf)
5158 java_shortarray *sa;
5160 STATISTICS(jniinvokation());
5162 sa = (java_shortarray *) array;
5164 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5165 exceptions_throw_arrayindexoutofboundsexception();
5167 MCOPY(&sa->data[start], buf, s2, len);
5171 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5172 jsize len, jint *buf)
5176 STATISTICS(jniinvokation());
5178 ia = (java_intarray *) array;
5180 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5181 exceptions_throw_arrayindexoutofboundsexception();
5183 MCOPY(&ia->data[start], buf, s4, len);
5187 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5188 jsize len, jlong *buf)
5192 STATISTICS(jniinvokation());
5194 la = (java_longarray *) array;
5196 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5197 exceptions_throw_arrayindexoutofboundsexception();
5199 MCOPY(&la->data[start], buf, s8, len);
5203 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5204 jsize len, jfloat *buf)
5206 java_floatarray *fa;
5208 STATISTICS(jniinvokation());
5210 fa = (java_floatarray *) array;
5212 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5213 exceptions_throw_arrayindexoutofboundsexception();
5215 MCOPY(&fa->data[start], buf, float, len);
5219 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5220 jsize len, jdouble *buf)
5222 java_doublearray *da;
5224 STATISTICS(jniinvokation());
5226 da = (java_doublearray *) array;
5228 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5229 exceptions_throw_arrayindexoutofboundsexception();
5231 MCOPY(&da->data[start], buf, double, len);
5235 /* Registering Native Methods *************************************************/
5237 /* RegisterNatives *************************************************************
5239 Registers native methods with the class specified by the clazz
5240 argument. The methods parameter specifies an array of
5241 JNINativeMethod structures that contain the names, signatures, and
5242 function pointers of the native methods. The nMethods parameter
5243 specifies the number of native methods in the array.
5245 *******************************************************************************/
5247 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5248 const JNINativeMethod *methods, jint nMethods)
5250 STATISTICS(jniinvokation());
5252 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5253 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5254 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5261 /* UnregisterNatives ***********************************************************
5263 Unregisters native methods of a class. The class goes back to the
5264 state before it was linked or registered with its native method
5267 This function should not be used in normal native code. Instead, it
5268 provides special programs a way to reload and relink native
5271 *******************************************************************************/
5273 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5275 STATISTICS(jniinvokation());
5277 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5279 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5285 /* Monitor Operations *********************************************************/
5287 /* MonitorEnter ****************************************************************
5289 Enters the monitor associated with the underlying Java object
5292 *******************************************************************************/
5294 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5296 STATISTICS(jniinvokation());
5299 exceptions_throw_nullpointerexception();
5303 LOCK_MONITOR_ENTER(obj);
5309 /* MonitorExit *****************************************************************
5311 The current thread must be the owner of the monitor associated with
5312 the underlying Java object referred to by obj. The thread
5313 decrements the counter indicating the number of times it has
5314 entered this monitor. If the value of the counter becomes zero, the
5315 current thread releases the monitor.
5317 *******************************************************************************/
5319 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5321 STATISTICS(jniinvokation());
5324 exceptions_throw_nullpointerexception();
5328 LOCK_MONITOR_EXIT(obj);
5334 /* JavaVM Interface ***********************************************************/
5336 /* GetJavaVM *******************************************************************
5338 Returns the Java VM interface (used in the Invocation API)
5339 associated with the current thread. The result is placed at the
5340 location pointed to by the second argument, vm.
5342 *******************************************************************************/
5344 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5346 STATISTICS(jniinvokation());
5348 *vm = (JavaVM *) _Jv_jvm;
5354 /* GetStringRegion *************************************************************
5356 Copies len number of Unicode characters beginning at offset start
5357 to the given buffer buf.
5359 Throws StringIndexOutOfBoundsException on index overflow.
5361 *******************************************************************************/
5363 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5366 java_lang_String *s;
5369 STATISTICS(jniinvokation());
5371 s = (java_lang_String *) str;
5374 if ((start < 0) || (len < 0) || (start > s->count) ||
5375 (start + len > s->count)) {
5376 exceptions_throw_stringindexoutofboundsexception();
5380 MCOPY(buf, &ca->data[start], u2, len);
5384 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5385 jsize len, char *buf)
5387 STATISTICS(jniinvokation());
5389 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5393 /* GetPrimitiveArrayCritical ***************************************************
5395 Obtain a direct pointer to array elements.
5397 *******************************************************************************/
5399 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5405 ba = (java_bytearray *) array;
5407 /* do the same as Kaffe does */
5409 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5415 /* ReleasePrimitiveArrayCritical ***********************************************
5417 No specific documentation.
5419 *******************************************************************************/
5421 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5422 void *carray, jint mode)
5424 STATISTICS(jniinvokation());
5426 /* do the same as Kaffe does */
5428 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5433 /* GetStringCritical ***********************************************************
5435 The semantics of these two functions are similar to the existing
5436 Get/ReleaseStringChars functions.
5438 *******************************************************************************/
5440 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5443 STATISTICS(jniinvokation());
5445 return _Jv_JNI_GetStringChars(env, string, isCopy);
5449 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5450 const jchar *cstring)
5452 STATISTICS(jniinvokation());
5454 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5458 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5460 STATISTICS(jniinvokation());
5462 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5468 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5470 STATISTICS(jniinvokation());
5472 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5476 /* NewGlobalRef ****************************************************************
5478 Creates a new global reference to the object referred to by the obj
5481 *******************************************************************************/
5483 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5485 hashtable_global_ref_entry *gre;
5486 u4 key; /* hashkey */
5487 u4 slot; /* slot in hashtable */
5489 STATISTICS(jniinvokation());
5491 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5493 /* normally addresses are aligned to 4, 8 or 16 bytes */
5495 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5496 slot = key & (hashtable_global_ref->size - 1);
5497 gre = hashtable_global_ref->ptr[slot];
5499 /* search external hash chain for the entry */
5502 if (gre->o == obj) {
5503 /* global object found, increment the reference */
5507 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5512 gre = gre->hashlink; /* next element in external chain */
5515 /* global ref not found, create a new one */
5517 gre = NEW(hashtable_global_ref_entry);
5522 /* insert entry into hashtable */
5524 gre->hashlink = hashtable_global_ref->ptr[slot];
5526 hashtable_global_ref->ptr[slot] = gre;
5528 /* update number of hashtable-entries */
5530 hashtable_global_ref->entries++;
5532 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5538 /* DeleteGlobalRef *************************************************************
5540 Deletes the global reference pointed to by globalRef.
5542 *******************************************************************************/
5544 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5546 hashtable_global_ref_entry *gre;
5547 hashtable_global_ref_entry *prevgre;
5548 u4 key; /* hashkey */
5549 u4 slot; /* slot in hashtable */
5551 STATISTICS(jniinvokation());
5553 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5555 /* normally addresses are aligned to 4, 8 or 16 bytes */
5557 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5558 slot = key & (hashtable_global_ref->size - 1);
5559 gre = hashtable_global_ref->ptr[slot];
5561 /* initialize prevgre */
5565 /* search external hash chain for the entry */
5568 if (gre->o == globalRef) {
5569 /* global object found, decrement the reference count */
5573 /* if reference count is 0, remove the entry */
5575 if (gre->refs == 0) {
5576 /* special handling if it's the first in the chain */
5578 if (prevgre == NULL)
5579 hashtable_global_ref->ptr[slot] = gre->hashlink;
5581 prevgre->hashlink = gre->hashlink;
5583 FREE(gre, hashtable_global_ref_entry);
5586 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5591 prevgre = gre; /* save current pointer for removal */
5592 gre = gre->hashlink; /* next element in external chain */
5595 log_println("JNI-DeleteGlobalRef: global reference not found");
5597 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5601 /* ExceptionCheck **************************************************************
5603 Returns JNI_TRUE when there is a pending exception; otherwise,
5606 *******************************************************************************/
5608 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5610 java_objectheader *o;
5612 STATISTICS(jniinvokation());
5614 o = exceptions_get_exception();
5616 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5620 /* New JNI 1.4 functions ******************************************************/
5622 /* NewDirectByteBuffer *********************************************************
5624 Allocates and returns a direct java.nio.ByteBuffer referring to the
5625 block of memory starting at the memory address address and
5626 extending capacity bytes.
5628 *******************************************************************************/
5630 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5632 #if defined(ENABLE_JAVASE)
5633 java_objectheader *nbuf;
5634 # if SIZEOF_VOID_P == 8
5635 gnu_classpath_Pointer64 *paddress;
5637 gnu_classpath_Pointer32 *paddress;
5640 STATISTICS(jniinvokation());
5642 /* alocate a gnu.classpath.Pointer{32,64} object */
5644 # if SIZEOF_VOID_P == 8
5645 if (!(paddress = (gnu_classpath_Pointer64 *)
5646 builtin_new(class_gnu_classpath_Pointer64)))
5648 if (!(paddress = (gnu_classpath_Pointer32 *)
5649 builtin_new(class_gnu_classpath_Pointer32)))
5653 /* fill gnu.classpath.Pointer{32,64} with address */
5655 paddress->data = (ptrint) address;
5657 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5659 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5660 (jmethodID) dbbirw_init, NULL, paddress,
5661 (jint) capacity, (jint) capacity, (jint) 0);
5663 /* add local reference and return the value */
5665 return _Jv_JNI_NewLocalRef(env, nbuf);
5667 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5669 /* keep compiler happy */
5676 /* GetDirectBufferAddress ******************************************************
5678 Fetches and returns the starting address of the memory region
5679 referenced by the given direct java.nio.Buffer.
5681 *******************************************************************************/
5683 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5685 #if defined(ENABLE_JAVASE)
5686 java_nio_DirectByteBufferImpl *nbuf;
5687 # if SIZEOF_VOID_P == 8
5688 gnu_classpath_Pointer64 *address;
5690 gnu_classpath_Pointer32 *address;
5693 STATISTICS(jniinvokation());
5695 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5698 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5700 # if SIZEOF_VOID_P == 8
5701 address = (gnu_classpath_Pointer64 *) nbuf->address;
5703 address = (gnu_classpath_Pointer32 *) nbuf->address;
5706 if (address == NULL)
5709 return (void *) address->data;
5711 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5713 /* keep compiler happy */
5720 /* GetDirectBufferCapacity *****************************************************
5722 Fetches and returns the capacity in bytes of the memory region
5723 referenced by the given direct java.nio.Buffer.
5725 *******************************************************************************/
5727 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5729 #if defined(ENABLE_JAVASE)
5730 java_nio_Buffer *nbuf;
5732 STATISTICS(jniinvokation());
5734 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5737 nbuf = (java_nio_Buffer *) buf;
5739 return (jlong) nbuf->cap;
5741 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5743 /* keep compiler happy */
5750 /* DestroyJavaVM ***************************************************************
5752 Unloads a Java VM and reclaims its resources. Only the main thread
5753 can unload the VM. The system waits until the main thread is only
5754 remaining user thread before it destroys the VM.
5756 *******************************************************************************/
5758 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5762 STATISTICS(jniinvokation());
5764 status = vm_destroy(vm);
5770 /* AttachCurrentThread *********************************************************
5772 Attaches the current thread to a Java VM. Returns a JNI interface
5773 pointer in the JNIEnv argument.
5775 Trying to attach a thread that is already attached is a no-op.
5777 A native thread cannot be attached simultaneously to two Java VMs.
5779 When a thread is attached to the VM, the context class loader is
5780 the bootstrap loader.
5782 *******************************************************************************/
5784 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5786 JavaVMAttachArgs *vm_aargs;
5788 #if defined(ENABLE_THREADS)
5789 if (threads_get_current_threadobject() == NULL) {
5790 vm_aargs = (JavaVMAttachArgs *) thr_args;
5792 if (vm_aargs != NULL) {
5793 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5794 (vm_aargs->version != JNI_VERSION_1_4))
5795 return JNI_EVERSION;
5798 if (!threads_attach_current_thread(vm_aargs, false))
5801 if (!jni_init_localref_table())
5812 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5814 STATISTICS(jniinvokation());
5816 return jni_attach_current_thread(p_env, thr_args, false);
5820 /* DetachCurrentThread *********************************************************
5822 Detaches the current thread from a Java VM. All Java monitors held
5823 by this thread are released. All Java threads waiting for this
5824 thread to die are notified.
5826 In JDK 1.1, the main thread cannot be detached from the VM. It must
5827 call DestroyJavaVM to unload the entire VM.
5829 In the JDK, the main thread can be detached from the VM.
5831 The main thread, which is the thread that created the Java VM,
5832 cannot be detached from the VM. Instead, the main thread must call
5833 JNI_DestroyJavaVM() to unload the entire VM.
5835 *******************************************************************************/
5837 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5839 #if defined(ENABLE_THREADS)
5840 threadobject *thread;
5842 STATISTICS(jniinvokation());
5844 thread = threads_get_current_threadobject();
5849 if (!threads_detach_thread(thread))
5857 /* GetEnv **********************************************************************
5859 If the current thread is not attached to the VM, sets *env to NULL,
5860 and returns JNI_EDETACHED. If the specified version is not
5861 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5862 sets *env to the appropriate interface, and returns JNI_OK.
5864 *******************************************************************************/
5866 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5868 STATISTICS(jniinvokation());
5870 #if defined(ENABLE_THREADS)
5871 if (threads_get_current_threadobject() == NULL) {
5874 return JNI_EDETACHED;
5878 /* check the JNI version */
5881 case JNI_VERSION_1_1:
5882 case JNI_VERSION_1_2:
5883 case JNI_VERSION_1_4:
5891 #if defined(ENABLE_JVMTI)
5892 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5893 == JVMTI_VERSION_INTERFACE_JVMTI) {
5895 *env = (void *) jvmti_new_environment();
5904 return JNI_EVERSION;
5908 /* AttachCurrentThreadAsDaemon *************************************************
5910 Same semantics as AttachCurrentThread, but the newly-created
5911 java.lang.Thread instance is a daemon.
5913 If the thread has already been attached via either
5914 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5915 simply sets the value pointed to by penv to the JNIEnv of the
5916 current thread. In this case neither AttachCurrentThread nor this
5917 routine have any effect on the daemon status of the thread.
5919 *******************************************************************************/
5921 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5923 STATISTICS(jniinvokation());
5925 return jni_attach_current_thread(penv, args, true);
5929 /* JNI invocation table *******************************************************/
5931 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5936 _Jv_JNI_DestroyJavaVM,
5937 _Jv_JNI_AttachCurrentThread,
5938 _Jv_JNI_DetachCurrentThread,
5940 _Jv_JNI_AttachCurrentThreadAsDaemon
5944 /* JNI function table *********************************************************/
5946 struct JNINativeInterface _Jv_JNINativeInterface = {
5953 _Jv_JNI_DefineClass,
5955 _Jv_JNI_FromReflectedMethod,
5956 _Jv_JNI_FromReflectedField,
5957 _Jv_JNI_ToReflectedMethod,
5958 _Jv_JNI_GetSuperclass,
5959 _Jv_JNI_IsAssignableFrom,
5960 _Jv_JNI_ToReflectedField,
5964 _Jv_JNI_ExceptionOccurred,
5965 _Jv_JNI_ExceptionDescribe,
5966 _Jv_JNI_ExceptionClear,
5968 _Jv_JNI_PushLocalFrame,
5969 _Jv_JNI_PopLocalFrame,
5971 _Jv_JNI_NewGlobalRef,
5972 _Jv_JNI_DeleteGlobalRef,
5973 _Jv_JNI_DeleteLocalRef,
5974 _Jv_JNI_IsSameObject,
5975 _Jv_JNI_NewLocalRef,
5976 _Jv_JNI_EnsureLocalCapacity,
5978 _Jv_JNI_AllocObject,
5983 _Jv_JNI_GetObjectClass,
5984 _Jv_JNI_IsInstanceOf,
5986 _Jv_JNI_GetMethodID,
5988 _Jv_JNI_CallObjectMethod,
5989 _Jv_JNI_CallObjectMethodV,
5990 _Jv_JNI_CallObjectMethodA,
5991 _Jv_JNI_CallBooleanMethod,
5992 _Jv_JNI_CallBooleanMethodV,
5993 _Jv_JNI_CallBooleanMethodA,
5994 _Jv_JNI_CallByteMethod,
5995 _Jv_JNI_CallByteMethodV,
5996 _Jv_JNI_CallByteMethodA,
5997 _Jv_JNI_CallCharMethod,
5998 _Jv_JNI_CallCharMethodV,
5999 _Jv_JNI_CallCharMethodA,
6000 _Jv_JNI_CallShortMethod,
6001 _Jv_JNI_CallShortMethodV,
6002 _Jv_JNI_CallShortMethodA,
6003 _Jv_JNI_CallIntMethod,
6004 _Jv_JNI_CallIntMethodV,
6005 _Jv_JNI_CallIntMethodA,
6006 _Jv_JNI_CallLongMethod,
6007 _Jv_JNI_CallLongMethodV,
6008 _Jv_JNI_CallLongMethodA,
6009 _Jv_JNI_CallFloatMethod,
6010 _Jv_JNI_CallFloatMethodV,
6011 _Jv_JNI_CallFloatMethodA,
6012 _Jv_JNI_CallDoubleMethod,
6013 _Jv_JNI_CallDoubleMethodV,
6014 _Jv_JNI_CallDoubleMethodA,
6015 _Jv_JNI_CallVoidMethod,
6016 _Jv_JNI_CallVoidMethodV,
6017 _Jv_JNI_CallVoidMethodA,
6019 _Jv_JNI_CallNonvirtualObjectMethod,
6020 _Jv_JNI_CallNonvirtualObjectMethodV,
6021 _Jv_JNI_CallNonvirtualObjectMethodA,
6022 _Jv_JNI_CallNonvirtualBooleanMethod,
6023 _Jv_JNI_CallNonvirtualBooleanMethodV,
6024 _Jv_JNI_CallNonvirtualBooleanMethodA,
6025 _Jv_JNI_CallNonvirtualByteMethod,
6026 _Jv_JNI_CallNonvirtualByteMethodV,
6027 _Jv_JNI_CallNonvirtualByteMethodA,
6028 _Jv_JNI_CallNonvirtualCharMethod,
6029 _Jv_JNI_CallNonvirtualCharMethodV,
6030 _Jv_JNI_CallNonvirtualCharMethodA,
6031 _Jv_JNI_CallNonvirtualShortMethod,
6032 _Jv_JNI_CallNonvirtualShortMethodV,
6033 _Jv_JNI_CallNonvirtualShortMethodA,
6034 _Jv_JNI_CallNonvirtualIntMethod,
6035 _Jv_JNI_CallNonvirtualIntMethodV,
6036 _Jv_JNI_CallNonvirtualIntMethodA,
6037 _Jv_JNI_CallNonvirtualLongMethod,
6038 _Jv_JNI_CallNonvirtualLongMethodV,
6039 _Jv_JNI_CallNonvirtualLongMethodA,
6040 _Jv_JNI_CallNonvirtualFloatMethod,
6041 _Jv_JNI_CallNonvirtualFloatMethodV,
6042 _Jv_JNI_CallNonvirtualFloatMethodA,
6043 _Jv_JNI_CallNonvirtualDoubleMethod,
6044 _Jv_JNI_CallNonvirtualDoubleMethodV,
6045 _Jv_JNI_CallNonvirtualDoubleMethodA,
6046 _Jv_JNI_CallNonvirtualVoidMethod,
6047 _Jv_JNI_CallNonvirtualVoidMethodV,
6048 _Jv_JNI_CallNonvirtualVoidMethodA,
6052 _Jv_JNI_GetObjectField,
6053 _Jv_JNI_GetBooleanField,
6054 _Jv_JNI_GetByteField,
6055 _Jv_JNI_GetCharField,
6056 _Jv_JNI_GetShortField,
6057 _Jv_JNI_GetIntField,
6058 _Jv_JNI_GetLongField,
6059 _Jv_JNI_GetFloatField,
6060 _Jv_JNI_GetDoubleField,
6061 _Jv_JNI_SetObjectField,
6062 _Jv_JNI_SetBooleanField,
6063 _Jv_JNI_SetByteField,
6064 _Jv_JNI_SetCharField,
6065 _Jv_JNI_SetShortField,
6066 _Jv_JNI_SetIntField,
6067 _Jv_JNI_SetLongField,
6068 _Jv_JNI_SetFloatField,
6069 _Jv_JNI_SetDoubleField,
6071 _Jv_JNI_GetStaticMethodID,
6073 _Jv_JNI_CallStaticObjectMethod,
6074 _Jv_JNI_CallStaticObjectMethodV,
6075 _Jv_JNI_CallStaticObjectMethodA,
6076 _Jv_JNI_CallStaticBooleanMethod,
6077 _Jv_JNI_CallStaticBooleanMethodV,
6078 _Jv_JNI_CallStaticBooleanMethodA,
6079 _Jv_JNI_CallStaticByteMethod,
6080 _Jv_JNI_CallStaticByteMethodV,
6081 _Jv_JNI_CallStaticByteMethodA,
6082 _Jv_JNI_CallStaticCharMethod,
6083 _Jv_JNI_CallStaticCharMethodV,
6084 _Jv_JNI_CallStaticCharMethodA,
6085 _Jv_JNI_CallStaticShortMethod,
6086 _Jv_JNI_CallStaticShortMethodV,
6087 _Jv_JNI_CallStaticShortMethodA,
6088 _Jv_JNI_CallStaticIntMethod,
6089 _Jv_JNI_CallStaticIntMethodV,
6090 _Jv_JNI_CallStaticIntMethodA,
6091 _Jv_JNI_CallStaticLongMethod,
6092 _Jv_JNI_CallStaticLongMethodV,
6093 _Jv_JNI_CallStaticLongMethodA,
6094 _Jv_JNI_CallStaticFloatMethod,
6095 _Jv_JNI_CallStaticFloatMethodV,
6096 _Jv_JNI_CallStaticFloatMethodA,
6097 _Jv_JNI_CallStaticDoubleMethod,
6098 _Jv_JNI_CallStaticDoubleMethodV,
6099 _Jv_JNI_CallStaticDoubleMethodA,
6100 _Jv_JNI_CallStaticVoidMethod,
6101 _Jv_JNI_CallStaticVoidMethodV,
6102 _Jv_JNI_CallStaticVoidMethodA,
6104 _Jv_JNI_GetStaticFieldID,
6106 _Jv_JNI_GetStaticObjectField,
6107 _Jv_JNI_GetStaticBooleanField,
6108 _Jv_JNI_GetStaticByteField,
6109 _Jv_JNI_GetStaticCharField,
6110 _Jv_JNI_GetStaticShortField,
6111 _Jv_JNI_GetStaticIntField,
6112 _Jv_JNI_GetStaticLongField,
6113 _Jv_JNI_GetStaticFloatField,
6114 _Jv_JNI_GetStaticDoubleField,
6115 _Jv_JNI_SetStaticObjectField,
6116 _Jv_JNI_SetStaticBooleanField,
6117 _Jv_JNI_SetStaticByteField,
6118 _Jv_JNI_SetStaticCharField,
6119 _Jv_JNI_SetStaticShortField,
6120 _Jv_JNI_SetStaticIntField,
6121 _Jv_JNI_SetStaticLongField,
6122 _Jv_JNI_SetStaticFloatField,
6123 _Jv_JNI_SetStaticDoubleField,
6126 _Jv_JNI_GetStringLength,
6127 _Jv_JNI_GetStringChars,
6128 _Jv_JNI_ReleaseStringChars,
6130 _Jv_JNI_NewStringUTF,
6131 _Jv_JNI_GetStringUTFLength,
6132 _Jv_JNI_GetStringUTFChars,
6133 _Jv_JNI_ReleaseStringUTFChars,
6135 _Jv_JNI_GetArrayLength,
6137 _Jv_JNI_NewObjectArray,
6138 _Jv_JNI_GetObjectArrayElement,
6139 _Jv_JNI_SetObjectArrayElement,
6141 _Jv_JNI_NewBooleanArray,
6142 _Jv_JNI_NewByteArray,
6143 _Jv_JNI_NewCharArray,
6144 _Jv_JNI_NewShortArray,
6145 _Jv_JNI_NewIntArray,
6146 _Jv_JNI_NewLongArray,
6147 _Jv_JNI_NewFloatArray,
6148 _Jv_JNI_NewDoubleArray,
6150 _Jv_JNI_GetBooleanArrayElements,
6151 _Jv_JNI_GetByteArrayElements,
6152 _Jv_JNI_GetCharArrayElements,
6153 _Jv_JNI_GetShortArrayElements,
6154 _Jv_JNI_GetIntArrayElements,
6155 _Jv_JNI_GetLongArrayElements,
6156 _Jv_JNI_GetFloatArrayElements,
6157 _Jv_JNI_GetDoubleArrayElements,
6159 _Jv_JNI_ReleaseBooleanArrayElements,
6160 _Jv_JNI_ReleaseByteArrayElements,
6161 _Jv_JNI_ReleaseCharArrayElements,
6162 _Jv_JNI_ReleaseShortArrayElements,
6163 _Jv_JNI_ReleaseIntArrayElements,
6164 _Jv_JNI_ReleaseLongArrayElements,
6165 _Jv_JNI_ReleaseFloatArrayElements,
6166 _Jv_JNI_ReleaseDoubleArrayElements,
6168 _Jv_JNI_GetBooleanArrayRegion,
6169 _Jv_JNI_GetByteArrayRegion,
6170 _Jv_JNI_GetCharArrayRegion,
6171 _Jv_JNI_GetShortArrayRegion,
6172 _Jv_JNI_GetIntArrayRegion,
6173 _Jv_JNI_GetLongArrayRegion,
6174 _Jv_JNI_GetFloatArrayRegion,
6175 _Jv_JNI_GetDoubleArrayRegion,
6176 _Jv_JNI_SetBooleanArrayRegion,
6177 _Jv_JNI_SetByteArrayRegion,
6178 _Jv_JNI_SetCharArrayRegion,
6179 _Jv_JNI_SetShortArrayRegion,
6180 _Jv_JNI_SetIntArrayRegion,
6181 _Jv_JNI_SetLongArrayRegion,
6182 _Jv_JNI_SetFloatArrayRegion,
6183 _Jv_JNI_SetDoubleArrayRegion,
6185 _Jv_JNI_RegisterNatives,
6186 _Jv_JNI_UnregisterNatives,
6188 _Jv_JNI_MonitorEnter,
6189 _Jv_JNI_MonitorExit,
6193 /* new JNI 1.2 functions */
6195 _Jv_JNI_GetStringRegion,
6196 _Jv_JNI_GetStringUTFRegion,
6198 _Jv_JNI_GetPrimitiveArrayCritical,
6199 _Jv_JNI_ReleasePrimitiveArrayCritical,
6201 _Jv_JNI_GetStringCritical,
6202 _Jv_JNI_ReleaseStringCritical,
6204 _Jv_JNI_NewWeakGlobalRef,
6205 _Jv_JNI_DeleteWeakGlobalRef,
6207 _Jv_JNI_ExceptionCheck,
6209 /* new JNI 1.4 functions */
6211 _Jv_JNI_NewDirectByteBuffer,
6212 _Jv_JNI_GetDirectBufferAddress,
6213 _Jv_JNI_GetDirectBufferCapacity
6217 /* Invocation API Functions ***************************************************/
6219 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6221 Returns a default configuration for the Java VM.
6223 *******************************************************************************/
6225 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6227 JavaVMInitArgs *_vm_args;
6229 _vm_args = (JavaVMInitArgs *) vm_args;
6231 /* GNU classpath currently supports JNI 1.2 */
6233 switch (_vm_args->version) {
6234 case JNI_VERSION_1_1:
6235 _vm_args->version = JNI_VERSION_1_1;
6238 case JNI_VERSION_1_2:
6239 case JNI_VERSION_1_4:
6240 _vm_args->ignoreUnrecognized = JNI_FALSE;
6241 _vm_args->options = NULL;
6242 _vm_args->nOptions = 0;
6253 /* JNI_GetCreatedJavaVMs *******************************************************
6255 Returns all Java VMs that have been created. Pointers to VMs are written in
6256 the buffer vmBuf in the order they are created. At most bufLen number of
6257 entries will be written. The total number of created VMs is returned in
6260 *******************************************************************************/
6262 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6264 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6270 /* JNI_CreateJavaVM ************************************************************
6272 Loads and initializes a Java VM. The current thread becomes the main thread.
6273 Sets the env argument to the JNI interface pointer of the main thread.
6275 *******************************************************************************/
6277 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6279 /* actually create the JVM */
6281 if (!vm_createjvm(p_vm, p_env, vm_args))
6289 * These are local overrides for various environment variables in Emacs.
6290 * Please do not remove this and leave it at the end of the file, where
6291 * Emacs will automagically detect them.
6292 * ---------------------------------------------------------------------
6295 * indent-tabs-mode: t
6299 * vim:noexpandtab:sw=4:ts=4: