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 8069 2007-06-13 14:08:24Z twisti $
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
40 #include "native/jni.h"
41 #include "native/native.h"
43 #if defined(ENABLE_JAVASE)
44 # if defined(WITH_CLASSPATH_GNU)
45 # include "native/include/gnu_classpath_Pointer.h"
47 # if SIZEOF_VOID_P == 8
48 # include "native/include/gnu_classpath_Pointer64.h"
50 # include "native/include/gnu_classpath_Pointer32.h"
55 #include "native/include/java_lang_Object.h"
56 #include "native/include/java_lang_Byte.h"
57 #include "native/include/java_lang_Character.h"
58 #include "native/include/java_lang_Short.h"
59 #include "native/include/java_lang_Integer.h"
60 #include "native/include/java_lang_Boolean.h"
61 #include "native/include/java_lang_Long.h"
62 #include "native/include/java_lang_Float.h"
63 #include "native/include/java_lang_Double.h"
64 #include "native/include/java_lang_String.h"
65 #include "native/include/java_lang_Throwable.h"
67 #if defined(ENABLE_JAVASE)
68 # include "native/include/java_lang_ClassLoader.h"
70 # include "native/include/java_lang_reflect_Constructor.h"
71 # include "native/include/java_lang_reflect_Field.h"
72 # include "native/include/java_lang_reflect_Method.h"
74 # include "native/include/java_nio_Buffer.h"
75 # include "native/include/java_nio_DirectByteBufferImpl.h"
78 #if defined(ENABLE_JVMTI)
79 # include "native/jvmti/cacaodbg.h"
82 #include "native/vm/java_lang_Class.h"
84 #if defined(ENABLE_JAVASE)
85 # include "native/vm/java_lang_ClassLoader.h"
88 #include "threads/lock-common.h"
89 #include "threads/threads-common.h"
91 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/resolve.h"
98 #include "vm/stringlocal.h"
101 #include "vm/jit/asmpart.h"
102 #include "vm/jit/jit.h"
103 #include "vm/jit/stacktrace.h"
105 #include "vmcore/loader.h"
106 #include "vmcore/options.h"
107 #include "vmcore/primitive.h"
108 #include "vmcore/statistics.h"
111 /* global variables ***********************************************************/
113 /* global reference table *****************************************************/
115 /* hashsize must be power of 2 */
117 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
119 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
122 /* direct buffer stuff ********************************************************/
124 #if defined(ENABLE_JAVASE)
125 static classinfo *class_java_nio_Buffer;
126 static classinfo *class_java_nio_DirectByteBufferImpl;
127 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
129 # if defined(WITH_CLASSPATH_GNU)
130 # if SIZEOF_VOID_P == 8
131 static classinfo *class_gnu_classpath_Pointer64;
133 static classinfo *class_gnu_classpath_Pointer32;
137 static methodinfo *dbbirw_init;
141 /* local reference table ******************************************************/
143 #if !defined(ENABLE_THREADS)
144 localref_table *_no_threads_localref_table;
148 /* accessing instance fields macros *******************************************/
150 #define SET_FIELD(o,type,f,value) \
151 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
153 #define GET_FIELD(o,type,f) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
157 /* some forward declarations **************************************************/
159 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
160 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
163 /* jni_init ********************************************************************
165 Initialize the JNI subsystem.
167 *******************************************************************************/
171 /* create global ref hashtable */
173 hashtable_global_ref = NEW(hashtable);
175 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
178 #if defined(ENABLE_JAVASE)
179 /* direct buffer stuff */
181 if (!(class_java_nio_Buffer =
182 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
183 !link_class(class_java_nio_Buffer))
186 if (!(class_java_nio_DirectByteBufferImpl =
187 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
188 !link_class(class_java_nio_DirectByteBufferImpl))
191 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
192 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
193 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
197 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
199 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
202 # if defined(WITH_CLASSPATH_GNU)
203 # if SIZEOF_VOID_P == 8
204 if (!(class_gnu_classpath_Pointer64 =
205 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
206 !link_class(class_gnu_classpath_Pointer64))
209 if (!(class_gnu_classpath_Pointer32 =
210 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
211 !link_class(class_gnu_classpath_Pointer32))
215 #endif /* defined(ENABLE_JAVASE) */
221 /* jni_init_localref_table *****************************************************
223 Initializes the local references table of the current thread.
225 *******************************************************************************/
227 bool jni_init_localref_table(void)
231 lrt = GCNEW(localref_table);
236 lrt->capacity = LOCALREFTABLE_CAPACITY;
238 lrt->localframes = 1;
239 lrt->prev = LOCALREFTABLE;
241 /* clear the references array (memset is faster then a for-loop) */
243 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
251 /* _Jv_jni_vmargs_from_objectarray *********************************************
255 *******************************************************************************/
257 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
260 java_objectarray *params)
262 java_objectheader *param;
264 typedesc *paramtypes;
270 paramcount = descr->paramcount;
271 paramtypes = descr->paramtypes;
273 /* if method is non-static fill first block and skip `this' pointer */
279 vmargs[0].type = TYPE_ADR;
280 vmargs[0].data.l = (u8) (ptrint) o;
287 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
288 switch (paramtypes->type) {
289 /* primitive types */
294 param = params->data[j];
299 /* internally used data type */
300 vmargs[i].type = paramtypes->type;
302 /* convert the value according to its declared type */
304 c = param->vftbl->class;
306 switch (paramtypes->decltype) {
307 case PRIMITIVETYPE_BOOLEAN:
308 if (c == class_java_lang_Boolean)
309 value = (int64_t) ((java_lang_Boolean *) param)->value;
313 vmargs[i].data.l = value;
316 case PRIMITIVETYPE_BYTE:
317 if (c == class_java_lang_Byte)
318 value = (int64_t) ((java_lang_Byte *) param)->value;
322 vmargs[i].data.l = value;
325 case PRIMITIVETYPE_CHAR:
326 if (c == class_java_lang_Character)
327 value = (int64_t) ((java_lang_Character *) param)->value;
331 vmargs[i].data.l = value;
334 case PRIMITIVETYPE_SHORT:
335 if (c == class_java_lang_Short)
336 value = (int64_t) ((java_lang_Short *) param)->value;
337 else if (c == class_java_lang_Byte)
338 value = (int64_t) ((java_lang_Byte *) param)->value;
342 vmargs[i].data.l = value;
345 case PRIMITIVETYPE_INT:
346 if (c == class_java_lang_Integer)
347 value = (int64_t) ((java_lang_Integer *) param)->value;
348 else if (c == class_java_lang_Short)
349 value = (int64_t) ((java_lang_Short *) param)->value;
350 else if (c == class_java_lang_Byte)
351 value = (int64_t) ((java_lang_Byte *) param)->value;
355 vmargs[i].data.l = value;
358 case PRIMITIVETYPE_LONG:
359 if (c == class_java_lang_Long)
360 value = (int64_t) ((java_lang_Long *) param)->value;
361 else if (c == class_java_lang_Integer)
362 value = (int64_t) ((java_lang_Integer *) param)->value;
363 else if (c == class_java_lang_Short)
364 value = (int64_t) ((java_lang_Short *) param)->value;
365 else if (c == class_java_lang_Byte)
366 value = (int64_t) ((java_lang_Byte *) param)->value;
370 vmargs[i].data.l = value;
373 case PRIMITIVETYPE_FLOAT:
374 if (c == class_java_lang_Float)
375 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
380 case PRIMITIVETYPE_DOUBLE:
381 if (c == class_java_lang_Double)
382 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
383 else if (c == class_java_lang_Float)
384 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
395 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
398 if (params->data[j] != 0) {
399 if (paramtypes->arraydim > 0) {
400 if (!builtin_arrayinstanceof(params->data[j], c))
404 if (!builtin_instanceof(params->data[j], c))
409 vmargs[i].type = TYPE_ADR;
410 vmargs[i].data.l = (u8) (ptrint) params->data[j];
419 /* *rettype = descr->returntype.decltype; */
424 exceptions_throw_illegalargumentexception();
429 /* _Jv_jni_CallObjectMethod ****************************************************
431 Internal function to call Java Object methods.
433 *******************************************************************************/
435 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
437 methodinfo *m, va_list ap)
440 java_objectheader *ro;
442 STATISTICS(jniinvokation());
445 exceptions_throw_nullpointerexception();
449 /* Class initialization is done by the JIT compiler. This is ok
450 since a static method always belongs to the declaring class. */
452 if (m->flags & ACC_STATIC) {
453 /* For static methods we reset the object. */
458 /* for convenience */
463 /* For instance methods we make a virtual function table lookup. */
465 resm = method_vftbl_lookup(vftbl, m);
468 STATISTICS(jnicallXmethodnvokation());
470 ro = vm_call_method_valist(resm, o, ap);
476 /* _Jv_jni_CallObjectMethodA ***************************************************
478 Internal function to call Java Object methods.
480 *******************************************************************************/
482 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
484 methodinfo *m, jvalue *args)
487 java_objectheader *ro;
489 STATISTICS(jniinvokation());
492 exceptions_throw_nullpointerexception();
496 /* Class initialization is done by the JIT compiler. This is ok
497 since a static method always belongs to the declaring class. */
499 if (m->flags & ACC_STATIC) {
500 /* For static methods we reset the object. */
505 /* for convenience */
510 /* For instance methods we make a virtual function table lookup. */
512 resm = method_vftbl_lookup(vftbl, m);
515 STATISTICS(jnicallXmethodnvokation());
517 ro = vm_call_method_jvalue(resm, o, args);
523 /* _Jv_jni_CallIntMethod *******************************************************
525 Internal function to call Java integer class methods (boolean,
526 byte, char, short, int).
528 *******************************************************************************/
530 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
531 methodinfo *m, va_list ap)
536 STATISTICS(jniinvokation());
539 exceptions_throw_nullpointerexception();
543 /* Class initialization is done by the JIT compiler. This is ok
544 since a static method always belongs to the declaring class. */
546 if (m->flags & ACC_STATIC) {
547 /* For static methods we reset the object. */
552 /* for convenience */
557 /* For instance methods we make a virtual function table lookup. */
559 resm = method_vftbl_lookup(vftbl, m);
562 STATISTICS(jnicallXmethodnvokation());
564 i = vm_call_method_int_valist(resm, o, ap);
570 /* _Jv_jni_CallIntMethodA ******************************************************
572 Internal function to call Java integer class methods (boolean,
573 byte, char, short, int).
575 *******************************************************************************/
577 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
578 methodinfo *m, jvalue *args)
583 STATISTICS(jniinvokation());
586 exceptions_throw_nullpointerexception();
590 /* Class initialization is done by the JIT compiler. This is ok
591 since a static method always belongs to the declaring class. */
593 if (m->flags & ACC_STATIC) {
594 /* For static methods we reset the object. */
599 /* for convenience */
604 /* For instance methods we make a virtual function table lookup. */
606 resm = method_vftbl_lookup(vftbl, m);
609 STATISTICS(jnicallXmethodnvokation());
611 i = vm_call_method_int_jvalue(resm, o, args);
617 /* _Jv_jni_CallLongMethod ******************************************************
619 Internal function to call Java long methods.
621 *******************************************************************************/
623 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
624 methodinfo *m, va_list ap)
629 STATISTICS(jniinvokation());
632 exceptions_throw_nullpointerexception();
636 /* Class initialization is done by the JIT compiler. This is ok
637 since a static method always belongs to the declaring class. */
639 if (m->flags & ACC_STATIC) {
640 /* For static methods we reset the object. */
645 /* for convenience */
650 /* For instance methods we make a virtual function table lookup. */
652 resm = method_vftbl_lookup(vftbl, m);
655 STATISTICS(jnicallXmethodnvokation());
657 l = vm_call_method_long_valist(resm, o, ap);
663 /* _Jv_jni_CallLongMethodA *****************************************************
665 Internal function to call Java long methods.
667 *******************************************************************************/
669 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
670 methodinfo *m, jvalue *args)
675 STATISTICS(jniinvokation());
678 exceptions_throw_nullpointerexception();
682 /* Class initialization is done by the JIT compiler. This is ok
683 since a static method always belongs to the declaring class. */
685 if (m->flags & ACC_STATIC) {
686 /* For static methods we reset the object. */
691 /* for convenience */
696 /* For instance methods we make a virtual function table lookup. */
698 resm = method_vftbl_lookup(vftbl, m);
701 STATISTICS(jnicallXmethodnvokation());
703 l = vm_call_method_long_jvalue(resm, o, args);
709 /* _Jv_jni_CallFloatMethod *****************************************************
711 Internal function to call Java float methods.
713 *******************************************************************************/
715 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
716 methodinfo *m, va_list ap)
721 /* Class initialization is done by the JIT compiler. This is ok
722 since a static method always belongs to the declaring class. */
724 if (m->flags & ACC_STATIC) {
725 /* For static methods we reset the object. */
730 /* for convenience */
735 /* For instance methods we make a virtual function table lookup. */
737 resm = method_vftbl_lookup(vftbl, m);
740 STATISTICS(jnicallXmethodnvokation());
742 f = vm_call_method_float_valist(resm, o, ap);
748 /* _Jv_jni_CallFloatMethodA ****************************************************
750 Internal function to call Java float methods.
752 *******************************************************************************/
754 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
755 methodinfo *m, jvalue *args)
760 /* Class initialization is done by the JIT compiler. This is ok
761 since a static method always belongs to the declaring class. */
763 if (m->flags & ACC_STATIC) {
764 /* For static methods we reset the object. */
769 /* for convenience */
774 /* For instance methods we make a virtual function table lookup. */
776 resm = method_vftbl_lookup(vftbl, m);
779 STATISTICS(jnicallXmethodnvokation());
781 f = vm_call_method_float_jvalue(resm, o, args);
787 /* _Jv_jni_CallDoubleMethod ****************************************************
789 Internal function to call Java double methods.
791 *******************************************************************************/
793 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
794 methodinfo *m, va_list ap)
799 /* Class initialization is done by the JIT compiler. This is ok
800 since a static method always belongs to the declaring class. */
802 if (m->flags & ACC_STATIC) {
803 /* For static methods we reset the object. */
808 /* for convenience */
813 /* For instance methods we make a virtual function table lookup. */
815 resm = method_vftbl_lookup(vftbl, m);
818 d = vm_call_method_double_valist(resm, o, ap);
824 /* _Jv_jni_CallDoubleMethodA ***************************************************
826 Internal function to call Java double methods.
828 *******************************************************************************/
830 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
831 methodinfo *m, jvalue *args)
836 /* Class initialization is done by the JIT compiler. This is ok
837 since a static method always belongs to the declaring class. */
839 if (m->flags & ACC_STATIC) {
840 /* For static methods we reset the object. */
845 /* for convenience */
850 /* For instance methods we make a virtual function table lookup. */
852 resm = method_vftbl_lookup(vftbl, m);
855 d = vm_call_method_double_jvalue(resm, o, args);
861 /* _Jv_jni_CallVoidMethod ******************************************************
863 Internal function to call Java void methods.
865 *******************************************************************************/
867 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
868 methodinfo *m, va_list ap)
873 exceptions_throw_nullpointerexception();
877 /* Class initialization is done by the JIT compiler. This is ok
878 since a static method always belongs to the declaring class. */
880 if (m->flags & ACC_STATIC) {
881 /* For static methods we reset the object. */
886 /* for convenience */
891 /* For instance methods we make a virtual function table lookup. */
893 resm = method_vftbl_lookup(vftbl, m);
896 STATISTICS(jnicallXmethodnvokation());
898 (void) vm_call_method_valist(resm, o, ap);
902 /* _Jv_jni_CallVoidMethodA *****************************************************
904 Internal function to call Java void methods.
906 *******************************************************************************/
908 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
909 methodinfo *m, jvalue *args)
914 exceptions_throw_nullpointerexception();
918 /* Class initialization is done by the JIT compiler. This is ok
919 since a static method always belongs to the declaring class. */
921 if (m->flags & ACC_STATIC) {
922 /* For static methods we reset the object. */
927 /* for convenience */
932 /* For instance methods we make a virtual function table lookup. */
934 resm = method_vftbl_lookup(vftbl, m);
937 STATISTICS(jnicallXmethodnvokation());
939 (void) vm_call_method_jvalue(resm, o, args);
943 /* _Jv_jni_invokeNative ********************************************************
945 Invoke a method on the given object with the given arguments.
947 For instance methods OBJ must be != NULL and the method is looked up
948 in the vftbl of the object.
950 For static methods, OBJ is ignored.
952 *******************************************************************************/
954 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
955 java_objectarray *params)
959 java_objectheader *ro;
962 java_objectheader *xptr;
965 exceptions_throw_nullpointerexception();
969 argcount = m->parseddesc->paramcount;
970 paramcount = argcount;
972 /* if method is non-static, remove the `this' pointer */
974 if (!(m->flags & ACC_STATIC))
977 /* For instance methods the object has to be an instance of the
978 class the method belongs to. For static methods the obj
979 parameter is ignored. */
981 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
982 exceptions_throw_illegalargumentexception();
986 /* check if we got the right number of arguments */
988 if (((params == NULL) && (paramcount != 0)) ||
989 (params && (params->header.size != paramcount)))
991 exceptions_throw_illegalargumentexception();
995 /* for instance methods we need an object */
997 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
998 /* XXX not sure if that is the correct exception */
999 exceptions_throw_nullpointerexception();
1003 /* for static methods, zero object to make subsequent code simpler */
1004 if (m->flags & ACC_STATIC)
1008 /* for instance methods we must do a vftbl lookup */
1009 resm = method_vftbl_lookup(o->vftbl, m);
1012 /* for static methods, just for convenience */
1016 vmargs = MNEW(vm_arg, argcount);
1018 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
1019 MFREE(vmargs, vm_arg, argcount);
1023 switch (resm->parseddesc->returntype.decltype) {
1025 (void) vm_call_method_vmarg(resm, argcount, vmargs);
1030 case PRIMITIVETYPE_BOOLEAN: {
1032 java_lang_Boolean *bo;
1034 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1036 ro = builtin_new(class_java_lang_Boolean);
1038 /* setting the value of the object direct */
1040 bo = (java_lang_Boolean *) ro;
1045 case PRIMITIVETYPE_BYTE: {
1049 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1051 ro = builtin_new(class_java_lang_Byte);
1053 /* setting the value of the object direct */
1055 bo = (java_lang_Byte *) ro;
1060 case PRIMITIVETYPE_CHAR: {
1062 java_lang_Character *co;
1064 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1066 ro = builtin_new(class_java_lang_Character);
1068 /* setting the value of the object direct */
1070 co = (java_lang_Character *) ro;
1075 case PRIMITIVETYPE_SHORT: {
1077 java_lang_Short *so;
1079 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1081 ro = builtin_new(class_java_lang_Short);
1083 /* setting the value of the object direct */
1085 so = (java_lang_Short *) ro;
1090 case PRIMITIVETYPE_INT: {
1092 java_lang_Integer *io;
1094 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1096 ro = builtin_new(class_java_lang_Integer);
1098 /* setting the value of the object direct */
1100 io = (java_lang_Integer *) ro;
1105 case PRIMITIVETYPE_LONG: {
1109 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1111 ro = builtin_new(class_java_lang_Long);
1113 /* setting the value of the object direct */
1115 lo = (java_lang_Long *) ro;
1120 case PRIMITIVETYPE_FLOAT: {
1122 java_lang_Float *fo;
1124 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1126 ro = builtin_new(class_java_lang_Float);
1128 /* setting the value of the object direct */
1130 fo = (java_lang_Float *) ro;
1135 case PRIMITIVETYPE_DOUBLE: {
1137 java_lang_Double *_do;
1139 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1141 ro = builtin_new(class_java_lang_Double);
1143 /* setting the value of the object direct */
1145 _do = (java_lang_Double *) ro;
1151 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1155 /* if this happens the exception has already been set by
1156 fill_callblock_from_objectarray */
1158 MFREE(vmargs, vm_arg, argcount);
1163 MFREE(vmargs, vm_arg, argcount);
1165 xptr = exceptions_get_exception();
1168 /* clear exception pointer, we are calling JIT code again */
1170 exceptions_clear_exception();
1172 exceptions_throw_invocationtargetexception(xptr);
1179 /* GetVersion ******************************************************************
1181 Returns the major version number in the higher 16 bits and the
1182 minor version number in the lower 16 bits.
1184 *******************************************************************************/
1186 jint _Jv_JNI_GetVersion(JNIEnv *env)
1188 STATISTICS(jniinvokation());
1190 /* we support JNI 1.4 */
1192 return JNI_VERSION_1_4;
1196 /* Class Operations ***********************************************************/
1198 /* DefineClass *****************************************************************
1200 Loads a class from a buffer of raw class data. The buffer
1201 containing the raw class data is not referenced by the VM after the
1202 DefineClass call returns, and it may be discarded if desired.
1204 *******************************************************************************/
1206 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1207 const jbyte *buf, jsize bufLen)
1209 #if defined(ENABLE_JAVASE)
1210 java_lang_ClassLoader *cl;
1211 java_lang_String *s;
1215 STATISTICS(jniinvokation());
1217 cl = (java_lang_ClassLoader *) loader;
1218 s = (java_lang_String *) javastring_new_from_utf_string(name);
1219 ba = (java_bytearray *) buf;
1221 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1224 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1226 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1228 /* keep compiler happy */
1235 /* FindClass *******************************************************************
1237 This function loads a locally-defined class. It searches the
1238 directories and zip files specified by the CLASSPATH environment
1239 variable for the class with the specified name.
1241 *******************************************************************************/
1243 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1245 #if defined(ENABLE_JAVASE)
1250 STATISTICS(jniinvokation());
1252 u = utf_new_char_classname((char *) name);
1254 /* Check stacktrace for classloader, if one found use it,
1255 otherwise use the system classloader. */
1257 /* Quote from the JNI documentation:
1259 In the Java 2 Platform, FindClass locates the class loader
1260 associated with the current native method. If the native code
1261 belongs to a system class, no class loader will be
1262 involved. Otherwise, the proper class loader will be invoked to
1263 load and link the named class. When FindClass is called through
1264 the Invocation Interface, there is no current native method or
1265 its associated class loader. In that case, the result of
1266 ClassLoader.getBaseClassLoader is used." */
1268 cc = stacktrace_getCurrentClass();
1271 c = load_class_from_sysloader(u);
1273 c = load_class_from_classloader(u, cc->classloader);
1281 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1283 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1285 /* keep compiler happy */
1292 /* GetSuperclass ***************************************************************
1294 If clazz represents any class other than the class Object, then
1295 this function returns the object that represents the superclass of
1296 the class specified by clazz.
1298 *******************************************************************************/
1300 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1304 STATISTICS(jniinvokation());
1306 c = ((classinfo *) sub)->super.cls;
1311 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1315 /* IsAssignableFrom ************************************************************
1317 Determines whether an object of sub can be safely cast to sup.
1319 *******************************************************************************/
1321 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1323 java_lang_Class *csup;
1324 java_lang_Class *csub;
1326 csup = (java_lang_Class *) sup;
1327 csub = (java_lang_Class *) sub;
1329 STATISTICS(jniinvokation());
1331 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1335 /* Throw ***********************************************************************
1337 Causes a java.lang.Throwable object to be thrown.
1339 *******************************************************************************/
1341 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1343 java_objectheader *o;
1345 STATISTICS(jniinvokation());
1347 o = (java_objectheader *) obj;
1349 exceptions_set_exception(o);
1355 /* ThrowNew ********************************************************************
1357 Constructs an exception object from the specified class with the
1358 message specified by message and causes that exception to be
1361 *******************************************************************************/
1363 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1366 java_objectheader *o;
1367 java_objectheader *s;
1369 STATISTICS(jniinvokation());
1371 c = (classinfo *) clazz;
1372 s = javastring_new_from_utf_string(msg);
1374 /* instantiate exception object */
1376 o = native_new_and_init_string(c, s);
1381 exceptions_set_exception(o);
1387 /* ExceptionOccurred ***********************************************************
1389 Determines if an exception is being thrown. The exception stays
1390 being thrown until either the native code calls ExceptionClear(),
1391 or the Java code handles the exception.
1393 *******************************************************************************/
1395 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1397 java_objectheader *o;
1399 STATISTICS(jniinvokation());
1401 o = exceptions_get_exception();
1403 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1407 /* ExceptionDescribe ***********************************************************
1409 Prints an exception and a backtrace of the stack to a system
1410 error-reporting channel, such as stderr. This is a convenience
1411 routine provided for debugging.
1413 *******************************************************************************/
1415 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1417 java_objectheader *o;
1420 STATISTICS(jniinvokation());
1422 o = exceptions_get_exception();
1425 /* clear exception, because we are calling jit code again */
1427 exceptions_clear_exception();
1429 /* get printStackTrace method from exception class */
1431 m = class_resolveclassmethod(o->vftbl->class,
1432 utf_printStackTrace,
1438 /* XXX what should we do? */
1441 /* print the stacktrace */
1443 (void) vm_call_method(m, o);
1448 /* ExceptionClear **************************************************************
1450 Clears any exception that is currently being thrown. If no
1451 exception is currently being thrown, this routine has no effect.
1453 *******************************************************************************/
1455 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1457 STATISTICS(jniinvokation());
1459 exceptions_clear_exception();
1463 /* FatalError ******************************************************************
1465 Raises a fatal error and does not expect the VM to recover. This
1466 function does not return.
1468 *******************************************************************************/
1470 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1472 STATISTICS(jniinvokation());
1474 /* this seems to be the best way */
1476 vm_abort("JNI Fatal error: %s", msg);
1480 /* PushLocalFrame **************************************************************
1482 Creates a new local reference frame, in which at least a given
1483 number of local references can be created.
1485 *******************************************************************************/
1487 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1490 localref_table *lrt;
1491 localref_table *nlrt;
1493 STATISTICS(jniinvokation());
1498 /* Allocate new local reference table on Java heap. Calculate the
1499 additional memory we have to allocate. */
1501 if (capacity > LOCALREFTABLE_CAPACITY)
1502 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1506 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1511 /* get current local reference table from thread */
1513 lrt = LOCALREFTABLE;
1515 /* Set up the new local reference table and add it to the local
1518 nlrt->capacity = capacity;
1520 nlrt->localframes = lrt->localframes + 1;
1523 /* store new local reference table in thread */
1525 LOCALREFTABLE = nlrt;
1531 /* PopLocalFrame ***************************************************************
1533 Pops off the current local reference frame, frees all the local
1534 references, and returns a local reference in the previous local
1535 reference frame for the given result object.
1537 *******************************************************************************/
1539 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1541 localref_table *lrt;
1542 localref_table *plrt;
1545 STATISTICS(jniinvokation());
1547 /* get current local reference table from thread */
1549 lrt = LOCALREFTABLE;
1551 localframes = lrt->localframes;
1553 /* Don't delete the top local frame, as this one is allocated in
1554 the native stub on the stack and is freed automagically on
1557 if (localframes == 1)
1558 return _Jv_JNI_NewLocalRef(env, result);
1560 /* release all current local frames */
1562 for (; localframes >= 1; localframes--) {
1563 /* get previous frame */
1567 /* clear all reference entries */
1569 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1573 /* set new local references table */
1578 /* store new local reference table in thread */
1580 LOCALREFTABLE = lrt;
1582 /* add local reference and return the value */
1584 return _Jv_JNI_NewLocalRef(env, result);
1588 /* DeleteLocalRef **************************************************************
1590 Deletes the local reference pointed to by localRef.
1592 *******************************************************************************/
1594 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1596 java_objectheader *o;
1597 localref_table *lrt;
1600 STATISTICS(jniinvokation());
1602 o = (java_objectheader *) localRef;
1604 /* get local reference table (thread specific) */
1606 lrt = LOCALREFTABLE;
1608 /* go through all local frames */
1610 for (; lrt != NULL; lrt = lrt->prev) {
1612 /* and try to remove the reference */
1614 for (i = 0; i < lrt->capacity; i++) {
1615 if (lrt->refs[i] == o) {
1616 lrt->refs[i] = NULL;
1624 /* this should not happen */
1626 /* if (opt_checkjni) */
1627 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1628 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1632 /* IsSameObject ****************************************************************
1634 Tests whether two references refer to the same Java object.
1636 *******************************************************************************/
1638 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1640 STATISTICS(jniinvokation());
1649 /* NewLocalRef *****************************************************************
1651 Creates a new local reference that refers to the same object as ref.
1653 *******************************************************************************/
1655 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1657 localref_table *lrt;
1660 STATISTICS(jniinvokation());
1665 /* get local reference table (thread specific) */
1667 lrt = LOCALREFTABLE;
1669 /* Check if we have space for the requested reference? No,
1670 allocate a new frame. This is actually not what the spec says,
1671 but for compatibility reasons... */
1673 if (lrt->used == lrt->capacity) {
1674 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1677 /* get the new local reference table */
1679 lrt = LOCALREFTABLE;
1682 /* insert the reference */
1684 for (i = 0; i < lrt->capacity; i++) {
1685 if (lrt->refs[i] == NULL) {
1686 lrt->refs[i] = (java_objectheader *) ref;
1693 /* should not happen, just to be sure */
1697 /* keep compiler happy */
1703 /* EnsureLocalCapacity *********************************************************
1705 Ensures that at least a given number of local references can be
1706 created in the current thread
1708 *******************************************************************************/
1710 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1712 localref_table *lrt;
1714 STATISTICS(jniinvokation());
1716 /* get local reference table (thread specific) */
1718 lrt = LOCALREFTABLE;
1720 /* check if capacity elements are available in the local references table */
1722 if ((lrt->used + capacity) > lrt->capacity)
1723 return _Jv_JNI_PushLocalFrame(env, capacity);
1729 /* AllocObject *****************************************************************
1731 Allocates a new Java object without invoking any of the
1732 constructors for the object. Returns a reference to the object.
1734 *******************************************************************************/
1736 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1739 java_objectheader *o;
1741 STATISTICS(jniinvokation());
1743 c = (classinfo *) clazz;
1745 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1746 exceptions_throw_instantiationexception(c);
1752 return _Jv_JNI_NewLocalRef(env, o);
1756 /* NewObject *******************************************************************
1758 Programmers place all arguments that are to be passed to the
1759 constructor immediately following the methodID
1760 argument. NewObject() accepts these arguments and passes them to
1761 the Java method that the programmer wishes to invoke.
1763 *******************************************************************************/
1765 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1767 java_objectheader *o;
1771 STATISTICS(jniinvokation());
1773 m = (methodinfo *) methodID;
1777 o = builtin_new(clazz);
1782 /* call constructor */
1784 va_start(ap, methodID);
1785 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1788 return _Jv_JNI_NewLocalRef(env, o);
1792 /* NewObjectV ******************************************************************
1794 Programmers place all arguments that are to be passed to the
1795 constructor in an args argument of type va_list that immediately
1796 follows the methodID argument. NewObjectV() accepts these
1797 arguments, and, in turn, passes them to the Java method that the
1798 programmer wishes to invoke.
1800 *******************************************************************************/
1802 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1805 java_objectheader *o;
1808 STATISTICS(jniinvokation());
1810 m = (methodinfo *) methodID;
1814 o = builtin_new(clazz);
1819 /* call constructor */
1821 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1823 return _Jv_JNI_NewLocalRef(env, o);
1827 /* NewObjectA *****************************************************************
1829 Programmers place all arguments that are to be passed to the
1830 constructor in an args array of jvalues that immediately follows
1831 the methodID argument. NewObjectA() accepts the arguments in this
1832 array, and, in turn, passes them to the Java method that the
1833 programmer wishes to invoke.
1835 *******************************************************************************/
1837 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1840 java_objectheader *o;
1843 STATISTICS(jniinvokation());
1845 m = (methodinfo *) methodID;
1849 o = builtin_new(clazz);
1854 /* call constructor */
1856 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1858 return _Jv_JNI_NewLocalRef(env, o);
1862 /* GetObjectClass **************************************************************
1864 Returns the class of an object.
1866 *******************************************************************************/
1868 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1870 java_objectheader *o;
1873 STATISTICS(jniinvokation());
1875 o = (java_objectheader *) obj;
1877 if ((o == NULL) || (o->vftbl == NULL))
1880 c = o->vftbl->class;
1882 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1886 /* IsInstanceOf ****************************************************************
1888 Tests whether an object is an instance of a class.
1890 *******************************************************************************/
1892 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1895 java_lang_Object *o;
1897 STATISTICS(jniinvokation());
1899 c = (java_lang_Class *) clazz;
1900 o = (java_lang_Object *) obj;
1902 return _Jv_java_lang_Class_isInstance(c, o);
1906 /* Reflection Support *********************************************************/
1908 /* FromReflectedMethod *********************************************************
1910 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1911 object to a method ID.
1913 *******************************************************************************/
1915 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1917 #if defined(ENABLE_JAVASE)
1922 STATISTICS(jniinvokation());
1927 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1928 java_lang_reflect_Method *rm;
1930 rm = (java_lang_reflect_Method *) method;
1931 c = (classinfo *) (rm->declaringClass);
1934 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1935 java_lang_reflect_Constructor *rc;
1937 rc = (java_lang_reflect_Constructor *) method;
1938 c = (classinfo *) (rc->clazz);
1944 mi = &(c->methods[slot]);
1946 return (jmethodID) mi;
1948 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1950 /* keep compiler happy */
1957 /* FromReflectedField **********************************************************
1959 Converts a java.lang.reflect.Field to a field ID.
1961 *******************************************************************************/
1963 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1965 #if defined(ENABLE_JAVASE)
1966 java_lang_reflect_Field *rf;
1970 STATISTICS(jniinvokation());
1972 rf = (java_lang_reflect_Field *) field;
1977 c = (classinfo *) rf->declaringClass;
1979 f = &(c->fields[rf->slot]);
1981 return (jfieldID) f;
1983 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1985 /* keep compiler happy */
1992 /* ToReflectedMethod ***********************************************************
1994 Converts a method ID derived from cls to an instance of the
1995 java.lang.reflect.Method class or to an instance of the
1996 java.lang.reflect.Constructor class.
1998 *******************************************************************************/
2000 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2003 STATISTICS(jniinvokation());
2005 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2011 /* ToReflectedField ************************************************************
2013 Converts a field ID derived from cls to an instance of the
2014 java.lang.reflect.Field class.
2016 *******************************************************************************/
2018 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2021 STATISTICS(jniinvokation());
2023 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2029 /* Calling Instance Methods ***************************************************/
2031 /* GetMethodID *****************************************************************
2033 Returns the method ID for an instance (nonstatic) method of a class
2034 or interface. The method may be defined in one of the clazz's
2035 superclasses and inherited by clazz. The method is determined by
2036 its name and signature.
2038 GetMethodID() causes an uninitialized class to be initialized.
2040 *******************************************************************************/
2042 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2050 STATISTICS(jniinvokation());
2052 c = (classinfo *) clazz;
2057 if (!(c->state & CLASS_INITIALIZED))
2058 if (!initialize_class(c))
2061 /* try to get the method of the class or one of it's superclasses */
2063 uname = utf_new_char((char *) name);
2064 udesc = utf_new_char((char *) sig);
2066 m = class_resolvemethod(clazz, uname, udesc);
2068 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2069 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2074 return (jmethodID) m;
2078 /* JNI-functions for calling instance methods *********************************/
2080 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2083 java_objectheader *o;
2085 java_objectheader *ret;
2088 o = (java_objectheader *) obj;
2089 m = (methodinfo *) methodID;
2091 va_start(ap, methodID);
2092 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2095 return _Jv_JNI_NewLocalRef(env, ret);
2099 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2102 java_objectheader *o;
2104 java_objectheader *ret;
2106 o = (java_objectheader *) obj;
2107 m = (methodinfo *) methodID;
2109 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2111 return _Jv_JNI_NewLocalRef(env, ret);
2115 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2118 java_objectheader *o;
2120 java_objectheader *ret;
2122 o = (java_objectheader *) obj;
2123 m = (methodinfo *) methodID;
2125 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2127 return _Jv_JNI_NewLocalRef(env, ret);
2131 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2134 java_objectheader *o;
2139 o = (java_objectheader *) obj;
2140 m = (methodinfo *) methodID;
2142 va_start(ap, methodID);
2143 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2150 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2151 jmethodID methodID, va_list args)
2153 java_objectheader *o;
2157 o = (java_objectheader *) obj;
2158 m = (methodinfo *) methodID;
2160 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2166 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2167 jmethodID methodID, jvalue *args)
2169 java_objectheader *o;
2173 o = (java_objectheader *) obj;
2174 m = (methodinfo *) methodID;
2176 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2182 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2184 java_objectheader *o;
2189 o = (java_objectheader *) obj;
2190 m = (methodinfo *) methodID;
2192 va_start(ap, methodID);
2193 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2201 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2204 java_objectheader *o;
2208 o = (java_objectheader *) obj;
2209 m = (methodinfo *) methodID;
2211 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2217 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2220 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2226 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2228 java_objectheader *o;
2233 o = (java_objectheader *) obj;
2234 m = (methodinfo *) methodID;
2236 va_start(ap, methodID);
2237 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2244 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2247 java_objectheader *o;
2251 o = (java_objectheader *) obj;
2252 m = (methodinfo *) methodID;
2254 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2260 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2263 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2269 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2272 java_objectheader *o;
2277 o = (java_objectheader *) obj;
2278 m = (methodinfo *) methodID;
2280 va_start(ap, methodID);
2281 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2288 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2291 java_objectheader *o;
2295 o = (java_objectheader *) obj;
2296 m = (methodinfo *) methodID;
2298 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2304 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2307 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2314 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2316 java_objectheader *o;
2321 o = (java_objectheader *) obj;
2322 m = (methodinfo *) methodID;
2324 va_start(ap, methodID);
2325 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2332 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2335 java_objectheader *o;
2339 o = (java_objectheader *) obj;
2340 m = (methodinfo *) methodID;
2342 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2348 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2351 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2358 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2360 java_objectheader *o;
2365 o = (java_objectheader *) obj;
2366 m = (methodinfo *) methodID;
2368 va_start(ap, methodID);
2369 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2376 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2379 java_objectheader *o;
2383 o = (java_objectheader *) obj;
2384 m = (methodinfo *) methodID;
2386 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2392 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2395 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2402 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2405 java_objectheader *o;
2410 o = (java_objectheader *) obj;
2411 m = (methodinfo *) methodID;
2413 va_start(ap, methodID);
2414 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2421 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2424 java_objectheader *o;
2428 o = (java_objectheader *) obj;
2429 m = (methodinfo *) methodID;
2431 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2437 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2440 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2447 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2450 java_objectheader *o;
2455 o = (java_objectheader *) obj;
2456 m = (methodinfo *) methodID;
2458 va_start(ap, methodID);
2459 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2466 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2469 java_objectheader *o;
2473 o = (java_objectheader *) obj;
2474 m = (methodinfo *) methodID;
2476 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2482 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2485 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2492 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2494 java_objectheader *o;
2498 o = (java_objectheader *) obj;
2499 m = (methodinfo *) methodID;
2501 va_start(ap, methodID);
2502 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2507 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2510 java_objectheader *o;
2513 o = (java_objectheader *) obj;
2514 m = (methodinfo *) methodID;
2516 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2520 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2523 java_objectheader *o;
2526 o = (java_objectheader *) obj;
2527 m = (methodinfo *) methodID;
2529 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2534 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2535 jclass clazz, jmethodID methodID,
2538 java_objectheader *o;
2541 java_objectheader *r;
2544 o = (java_objectheader *) obj;
2545 c = (classinfo *) clazz;
2546 m = (methodinfo *) methodID;
2548 va_start(ap, methodID);
2549 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2552 return _Jv_JNI_NewLocalRef(env, r);
2556 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2557 jclass clazz, jmethodID methodID,
2560 java_objectheader *o;
2563 java_objectheader *r;
2565 o = (java_objectheader *) obj;
2566 c = (classinfo *) clazz;
2567 m = (methodinfo *) methodID;
2569 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2571 return _Jv_JNI_NewLocalRef(env, r);
2575 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2576 jclass clazz, jmethodID methodID,
2579 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2581 return _Jv_JNI_NewLocalRef(env, NULL);
2586 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2587 jclass clazz, jmethodID methodID,
2590 java_objectheader *o;
2596 o = (java_objectheader *) obj;
2597 c = (classinfo *) clazz;
2598 m = (methodinfo *) methodID;
2600 va_start(ap, methodID);
2601 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2608 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2609 jclass clazz, jmethodID methodID,
2612 java_objectheader *o;
2617 o = (java_objectheader *) obj;
2618 c = (classinfo *) clazz;
2619 m = (methodinfo *) methodID;
2621 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2627 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2628 jclass clazz, jmethodID methodID,
2631 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2637 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2638 jmethodID methodID, ...)
2640 java_objectheader *o;
2646 o = (java_objectheader *) obj;
2647 c = (classinfo *) clazz;
2648 m = (methodinfo *) methodID;
2650 va_start(ap, methodID);
2651 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2658 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2659 jmethodID methodID, va_list args)
2661 java_objectheader *o;
2666 o = (java_objectheader *) obj;
2667 c = (classinfo *) clazz;
2668 m = (methodinfo *) methodID;
2670 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2676 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2677 jmethodID methodID, jvalue *args)
2679 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2686 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2687 jmethodID methodID, ...)
2689 java_objectheader *o;
2695 o = (java_objectheader *) obj;
2696 c = (classinfo *) clazz;
2697 m = (methodinfo *) methodID;
2699 va_start(ap, methodID);
2700 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2707 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2708 jmethodID methodID, va_list args)
2710 java_objectheader *o;
2715 o = (java_objectheader *) obj;
2716 c = (classinfo *) clazz;
2717 m = (methodinfo *) methodID;
2719 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2725 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2726 jmethodID methodID, jvalue *args)
2728 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2735 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2736 jclass clazz, jmethodID methodID, ...)
2738 java_objectheader *o;
2744 o = (java_objectheader *) obj;
2745 c = (classinfo *) clazz;
2746 m = (methodinfo *) methodID;
2748 va_start(ap, methodID);
2749 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2756 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2757 jclass clazz, jmethodID methodID,
2760 java_objectheader *o;
2765 o = (java_objectheader *) obj;
2766 c = (classinfo *) clazz;
2767 m = (methodinfo *) methodID;
2769 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2775 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2776 jclass clazz, jmethodID methodID,
2779 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2786 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2787 jmethodID methodID, ...)
2789 java_objectheader *o;
2795 o = (java_objectheader *) obj;
2796 c = (classinfo *) clazz;
2797 m = (methodinfo *) methodID;
2799 va_start(ap, methodID);
2800 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2807 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2808 jmethodID methodID, va_list args)
2810 java_objectheader *o;
2815 o = (java_objectheader *) obj;
2816 c = (classinfo *) clazz;
2817 m = (methodinfo *) methodID;
2819 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2825 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2826 jmethodID methodID, jvalue *args)
2828 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2835 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2836 jmethodID methodID, ...)
2838 java_objectheader *o;
2844 o = (java_objectheader *) obj;
2845 c = (classinfo *) clazz;
2846 m = (methodinfo *) methodID;
2848 va_start(ap, methodID);
2849 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2856 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2857 jmethodID methodID, va_list args)
2859 java_objectheader *o;
2864 o = (java_objectheader *) obj;
2865 c = (classinfo *) clazz;
2866 m = (methodinfo *) methodID;
2868 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2874 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2875 jmethodID methodID, jvalue *args)
2877 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2884 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2885 jclass clazz, jmethodID methodID, ...)
2887 java_objectheader *o;
2893 o = (java_objectheader *) obj;
2894 c = (classinfo *) clazz;
2895 m = (methodinfo *) methodID;
2897 va_start(ap, methodID);
2898 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2905 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2906 jclass clazz, jmethodID methodID,
2909 java_objectheader *o;
2914 o = (java_objectheader *) obj;
2915 c = (classinfo *) clazz;
2916 m = (methodinfo *) methodID;
2918 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2924 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2925 jclass clazz, jmethodID methodID,
2928 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2935 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2936 jclass clazz, jmethodID methodID,
2939 java_objectheader *o;
2945 o = (java_objectheader *) obj;
2946 c = (classinfo *) clazz;
2947 m = (methodinfo *) methodID;
2949 va_start(ap, methodID);
2950 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2957 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2958 jclass clazz, jmethodID methodID,
2961 java_objectheader *o;
2966 o = (java_objectheader *) obj;
2967 c = (classinfo *) clazz;
2968 m = (methodinfo *) methodID;
2970 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2976 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2977 jclass clazz, jmethodID methodID,
2980 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2987 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2988 jmethodID methodID, ...)
2990 java_objectheader *o;
2995 o = (java_objectheader *) obj;
2996 c = (classinfo *) clazz;
2997 m = (methodinfo *) methodID;
2999 va_start(ap, methodID);
3000 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3005 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3006 jmethodID methodID, va_list args)
3008 java_objectheader *o;
3012 o = (java_objectheader *) obj;
3013 c = (classinfo *) clazz;
3014 m = (methodinfo *) methodID;
3016 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3020 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3021 jmethodID methodID, jvalue * args)
3023 java_objectheader *o;
3027 o = (java_objectheader *) obj;
3028 c = (classinfo *) clazz;
3029 m = (methodinfo *) methodID;
3031 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3035 /* Accessing Fields of Objects ************************************************/
3037 /* GetFieldID ******************************************************************
3039 Returns the field ID for an instance (nonstatic) field of a
3040 class. The field is specified by its name and signature. The
3041 Get<type>Field and Set<type>Field families of accessor functions
3042 use field IDs to retrieve object fields.
3044 *******************************************************************************/
3046 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3054 STATISTICS(jniinvokation());
3056 c = (classinfo *) clazz;
3058 uname = utf_new_char((char *) name);
3059 udesc = utf_new_char((char *) sig);
3061 f = class_findfield(clazz, uname, udesc);
3064 exceptions_throw_nosuchfielderror(c, uname);
3066 return (jfieldID) f;
3070 /* Get<type>Field Routines *****************************************************
3072 This family of accessor routines returns the value of an instance
3073 (nonstatic) field of an object. The field to access is specified by
3074 a field ID obtained by calling GetFieldID().
3076 *******************************************************************************/
3078 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3080 java_objectheader *o;
3082 STATISTICS(jniinvokation());
3084 o = GET_FIELD(obj, java_objectheader*, fieldID);
3086 return _Jv_JNI_NewLocalRef(env, o);
3090 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3094 STATISTICS(jniinvokation());
3096 i = GET_FIELD(obj, s4, fieldID);
3098 return (jboolean) i;
3102 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3106 STATISTICS(jniinvokation());
3108 i = GET_FIELD(obj, s4, fieldID);
3114 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3118 STATISTICS(jniinvokation());
3120 i = GET_FIELD(obj, s4, fieldID);
3126 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3130 STATISTICS(jniinvokation());
3132 i = GET_FIELD(obj, s4, fieldID);
3138 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3140 java_objectheader *o;
3144 STATISTICS(jniinvokation());
3146 o = (java_objectheader *) obj;
3147 f = (fieldinfo *) fieldID;
3149 i = GET_FIELD(o, s4, f);
3155 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3159 STATISTICS(jniinvokation());
3161 l = GET_FIELD(obj, s8, fieldID);
3167 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3171 STATISTICS(jniinvokation());
3173 f = GET_FIELD(obj, float, fieldID);
3179 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3183 STATISTICS(jniinvokation());
3185 d = GET_FIELD(obj, double, fieldID);
3191 /* Set<type>Field Routines *****************************************************
3193 This family of accessor routines sets the value of an instance
3194 (nonstatic) field of an object. The field to access is specified by
3195 a field ID obtained by calling GetFieldID().
3197 *******************************************************************************/
3199 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3202 STATISTICS(jniinvokation());
3204 SET_FIELD(obj, java_objectheader*, fieldID, value);
3208 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3211 STATISTICS(jniinvokation());
3213 SET_FIELD(obj, s4, fieldID, value);
3217 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3220 STATISTICS(jniinvokation());
3222 SET_FIELD(obj, s4, fieldID, value);
3226 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3229 STATISTICS(jniinvokation());
3231 SET_FIELD(obj, s4, fieldID, value);
3235 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3238 STATISTICS(jniinvokation());
3240 SET_FIELD(obj, s4, fieldID, value);
3244 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3246 STATISTICS(jniinvokation());
3248 SET_FIELD(obj, s4, fieldID, value);
3252 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3255 STATISTICS(jniinvokation());
3257 SET_FIELD(obj, s8, fieldID, value);
3261 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3264 STATISTICS(jniinvokation());
3266 SET_FIELD(obj, float, fieldID, value);
3270 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3273 STATISTICS(jniinvokation());
3275 SET_FIELD(obj, double, fieldID, value);
3279 /* Calling Static Methods *****************************************************/
3281 /* GetStaticMethodID ***********************************************************
3283 Returns the method ID for a static method of a class. The method is
3284 specified by its name and signature.
3286 GetStaticMethodID() causes an uninitialized class to be
3289 *******************************************************************************/
3291 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3299 STATISTICS(jniinvokation());
3301 c = (classinfo *) clazz;
3306 if (!(c->state & CLASS_INITIALIZED))
3307 if (!initialize_class(c))
3310 /* try to get the static method of the class */
3312 uname = utf_new_char((char *) name);
3313 udesc = utf_new_char((char *) sig);
3315 m = class_resolvemethod(c, uname, udesc);
3317 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3318 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3323 return (jmethodID) m;
3327 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3328 jmethodID methodID, ...)
3331 java_objectheader *o;
3334 m = (methodinfo *) methodID;
3336 va_start(ap, methodID);
3337 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3340 return _Jv_JNI_NewLocalRef(env, o);
3344 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3345 jmethodID methodID, va_list args)
3348 java_objectheader *o;
3350 m = (methodinfo *) methodID;
3352 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3354 return _Jv_JNI_NewLocalRef(env, o);
3358 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3359 jmethodID methodID, jvalue *args)
3362 java_objectheader *o;
3364 m = (methodinfo *) methodID;
3366 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3368 return _Jv_JNI_NewLocalRef(env, o);
3372 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3373 jmethodID methodID, ...)
3379 m = (methodinfo *) methodID;
3381 va_start(ap, methodID);
3382 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3389 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3390 jmethodID methodID, va_list args)
3395 m = (methodinfo *) methodID;
3397 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3403 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3404 jmethodID methodID, jvalue *args)
3409 m = (methodinfo *) methodID;
3411 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3417 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3418 jmethodID methodID, ...)
3424 m = (methodinfo *) methodID;
3426 va_start(ap, methodID);
3427 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3434 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3435 jmethodID methodID, va_list args)
3440 m = (methodinfo *) methodID;
3442 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3448 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3449 jmethodID methodID, jvalue *args)
3454 m = (methodinfo *) methodID;
3456 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3462 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3463 jmethodID methodID, ...)
3469 m = (methodinfo *) methodID;
3471 va_start(ap, methodID);
3472 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3479 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3480 jmethodID methodID, va_list args)
3485 m = (methodinfo *) methodID;
3487 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3493 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3494 jmethodID methodID, jvalue *args)
3499 m = (methodinfo *) methodID;
3501 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3507 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3508 jmethodID methodID, ...)
3514 m = (methodinfo *) methodID;
3516 va_start(ap, methodID);
3517 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3524 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3525 jmethodID methodID, va_list args)
3530 m = (methodinfo *) methodID;
3532 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3538 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3539 jmethodID methodID, jvalue *args)
3544 m = (methodinfo *) methodID;
3546 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3552 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3559 m = (methodinfo *) methodID;
3561 va_start(ap, methodID);
3562 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3569 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3570 jmethodID methodID, va_list args)
3575 m = (methodinfo *) methodID;
3577 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3583 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3584 jmethodID methodID, jvalue *args)
3589 m = (methodinfo *) methodID;
3591 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3597 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3598 jmethodID methodID, ...)
3604 m = (methodinfo *) methodID;
3606 va_start(ap, methodID);
3607 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3614 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3615 jmethodID methodID, va_list args)
3620 m = (methodinfo *) methodID;
3622 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3628 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3629 jmethodID methodID, jvalue *args)
3634 m = (methodinfo *) methodID;
3636 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3643 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3644 jmethodID methodID, ...)
3650 m = (methodinfo *) methodID;
3652 va_start(ap, methodID);
3653 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3660 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3661 jmethodID methodID, va_list args)
3666 m = (methodinfo *) methodID;
3668 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3674 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3675 jmethodID methodID, jvalue *args)
3680 m = (methodinfo *) methodID;
3682 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3688 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3689 jmethodID methodID, ...)
3695 m = (methodinfo *) methodID;
3697 va_start(ap, methodID);
3698 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3705 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3706 jmethodID methodID, va_list args)
3711 m = (methodinfo *) methodID;
3713 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3719 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3720 jmethodID methodID, jvalue *args)
3725 m = (methodinfo *) methodID;
3727 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3733 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3734 jmethodID methodID, ...)
3739 m = (methodinfo *) methodID;
3741 va_start(ap, methodID);
3742 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3747 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3748 jmethodID methodID, va_list args)
3752 m = (methodinfo *) methodID;
3754 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3758 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3759 jmethodID methodID, jvalue * args)
3763 m = (methodinfo *) methodID;
3765 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3769 /* Accessing Static Fields ****************************************************/
3771 /* GetStaticFieldID ************************************************************
3773 Returns the field ID for a static field of a class. The field is
3774 specified by its name and signature. The GetStatic<type>Field and
3775 SetStatic<type>Field families of accessor functions use field IDs
3776 to retrieve static fields.
3778 *******************************************************************************/
3780 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3788 STATISTICS(jniinvokation());
3790 c = (classinfo *) clazz;
3792 uname = utf_new_char((char *) name);
3793 usig = utf_new_char((char *) sig);
3795 f = class_findfield(clazz, uname, usig);
3798 exceptions_throw_nosuchfielderror(c, uname);
3800 return (jfieldID) f;
3804 /* GetStatic<type>Field ********************************************************
3806 This family of accessor routines returns the value of a static
3809 *******************************************************************************/
3811 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3817 STATISTICS(jniinvokation());
3819 c = (classinfo *) clazz;
3820 f = (fieldinfo *) fieldID;
3822 if (!(c->state & CLASS_INITIALIZED))
3823 if (!initialize_class(c))
3826 return _Jv_JNI_NewLocalRef(env, f->value.a);
3830 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3836 STATISTICS(jniinvokation());
3838 c = (classinfo *) clazz;
3839 f = (fieldinfo *) fieldID;
3841 if (!(c->state & CLASS_INITIALIZED))
3842 if (!initialize_class(c))
3849 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3854 STATISTICS(jniinvokation());
3856 c = (classinfo *) clazz;
3857 f = (fieldinfo *) fieldID;
3859 if (!(c->state & CLASS_INITIALIZED))
3860 if (!initialize_class(c))
3867 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3872 STATISTICS(jniinvokation());
3874 c = (classinfo *) clazz;
3875 f = (fieldinfo *) fieldID;
3877 if (!(c->state & CLASS_INITIALIZED))
3878 if (!initialize_class(c))
3885 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3890 STATISTICS(jniinvokation());
3892 c = (classinfo *) clazz;
3893 f = (fieldinfo *) fieldID;
3895 if (!(c->state & CLASS_INITIALIZED))
3896 if (!initialize_class(c))
3903 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3908 STATISTICS(jniinvokation());
3910 c = (classinfo *) clazz;
3911 f = (fieldinfo *) fieldID;
3913 if (!(c->state & CLASS_INITIALIZED))
3914 if (!initialize_class(c))
3921 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3926 STATISTICS(jniinvokation());
3928 c = (classinfo *) clazz;
3929 f = (fieldinfo *) fieldID;
3931 if (!(c->state & CLASS_INITIALIZED))
3932 if (!initialize_class(c))
3939 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3944 STATISTICS(jniinvokation());
3946 c = (classinfo *) clazz;
3947 f = (fieldinfo *) fieldID;
3949 if (!(c->state & CLASS_INITIALIZED))
3950 if (!initialize_class(c))
3957 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3963 STATISTICS(jniinvokation());
3965 c = (classinfo *) clazz;
3966 f = (fieldinfo *) fieldID;
3968 if (!(c->state & CLASS_INITIALIZED))
3969 if (!initialize_class(c))
3976 /* SetStatic<type>Field *******************************************************
3978 This family of accessor routines sets the value of a static field
3981 *******************************************************************************/
3983 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3989 STATISTICS(jniinvokation());
3991 c = (classinfo *) clazz;
3992 f = (fieldinfo *) fieldID;
3994 if (!(c->state & CLASS_INITIALIZED))
3995 if (!initialize_class(c))
4002 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4008 STATISTICS(jniinvokation());
4010 c = (classinfo *) clazz;
4011 f = (fieldinfo *) fieldID;
4013 if (!(c->state & CLASS_INITIALIZED))
4014 if (!initialize_class(c))
4021 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4027 STATISTICS(jniinvokation());
4029 c = (classinfo *) clazz;
4030 f = (fieldinfo *) fieldID;
4032 if (!(c->state & CLASS_INITIALIZED))
4033 if (!initialize_class(c))
4040 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4046 STATISTICS(jniinvokation());
4048 c = (classinfo *) clazz;
4049 f = (fieldinfo *) fieldID;
4051 if (!(c->state & CLASS_INITIALIZED))
4052 if (!initialize_class(c))
4059 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4065 STATISTICS(jniinvokation());
4067 c = (classinfo *) clazz;
4068 f = (fieldinfo *) fieldID;
4070 if (!(c->state & CLASS_INITIALIZED))
4071 if (!initialize_class(c))
4078 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4084 STATISTICS(jniinvokation());
4086 c = (classinfo *) clazz;
4087 f = (fieldinfo *) fieldID;
4089 if (!(c->state & CLASS_INITIALIZED))
4090 if (!initialize_class(c))
4097 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4103 STATISTICS(jniinvokation());
4105 c = (classinfo *) clazz;
4106 f = (fieldinfo *) fieldID;
4108 if (!(c->state & CLASS_INITIALIZED))
4109 if (!initialize_class(c))
4116 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4122 STATISTICS(jniinvokation());
4124 c = (classinfo *) clazz;
4125 f = (fieldinfo *) fieldID;
4127 if (!(c->state & CLASS_INITIALIZED))
4128 if (!initialize_class(c))
4135 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4141 STATISTICS(jniinvokation());
4143 c = (classinfo *) clazz;
4144 f = (fieldinfo *) fieldID;
4146 if (!(c->state & CLASS_INITIALIZED))
4147 if (!initialize_class(c))
4154 /* String Operations **********************************************************/
4156 /* NewString *******************************************************************
4158 Create new java.lang.String object from an array of Unicode
4161 *******************************************************************************/
4163 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4165 java_lang_String *s;
4169 STATISTICS(jniinvokation());
4171 s = (java_lang_String *) builtin_new(class_java_lang_String);
4172 a = builtin_newarray_char(len);
4174 /* javastring or characterarray could not be created */
4175 if ((a == NULL) || (s == NULL))
4179 for (i = 0; i < len; i++)
4180 a->data[i] = buf[i];
4186 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4190 static jchar emptyStringJ[]={0,0};
4192 /* GetStringLength *************************************************************
4194 Returns the length (the count of Unicode characters) of a Java
4197 *******************************************************************************/
4199 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4201 return ((java_lang_String *) str)->count;
4205 /******************** convertes javastring to u2-array ****************************/
4207 u2 *javastring_tou2(jstring so)
4209 java_lang_String *s;
4214 STATISTICS(jniinvokation());
4216 s = (java_lang_String *) so;
4226 /* allocate memory */
4228 stringbuffer = MNEW(u2, s->count + 1);
4232 for (i = 0; i < s->count; i++)
4233 stringbuffer[i] = a->data[s->offset + i];
4235 /* terminate string */
4237 stringbuffer[i] = '\0';
4239 return stringbuffer;
4243 /* GetStringChars **************************************************************
4245 Returns a pointer to the array of Unicode characters of the
4246 string. This pointer is valid until ReleaseStringChars() is called.
4248 *******************************************************************************/
4250 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4254 STATISTICS(jniinvokation());
4256 jc = javastring_tou2(str);
4268 return emptyStringJ;
4272 /* ReleaseStringChars **********************************************************
4274 Informs the VM that the native code no longer needs access to
4275 chars. The chars argument is a pointer obtained from string using
4278 *******************************************************************************/
4280 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4282 STATISTICS(jniinvokation());
4284 if (chars == emptyStringJ)
4287 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4291 /* NewStringUTF ****************************************************************
4293 Constructs a new java.lang.String object from an array of UTF-8
4296 *******************************************************************************/
4298 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4300 java_lang_String *s;
4302 STATISTICS(jniinvokation());
4304 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4306 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4310 /****************** returns the utf8 length in bytes of a string *******************/
4312 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4314 java_lang_String *s = (java_lang_String*) string;
4316 STATISTICS(jniinvokation());
4318 return (jsize) u2_utflength(s->value->data, s->count);
4322 /* GetStringUTFChars ***********************************************************
4324 Returns a pointer to an array of UTF-8 characters of the
4325 string. This array is valid until it is released by
4326 ReleaseStringUTFChars().
4328 *******************************************************************************/
4330 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4335 STATISTICS(jniinvokation());
4343 u = javastring_toutf((java_objectheader *) string, false);
4352 /* ReleaseStringUTFChars *******************************************************
4354 Informs the VM that the native code no longer needs access to
4355 utf. The utf argument is a pointer derived from string using
4356 GetStringUTFChars().
4358 *******************************************************************************/
4360 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4362 STATISTICS(jniinvokation());
4364 /* XXX we don't release utf chars right now, perhaps that should be done
4365 later. Since there is always one reference the garbage collector will
4370 /* Array Operations ***********************************************************/
4372 /* GetArrayLength **************************************************************
4374 Returns the number of elements in the array.
4376 *******************************************************************************/
4378 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4380 java_arrayheader *a;
4382 STATISTICS(jniinvokation());
4384 a = (java_arrayheader *) array;
4390 /* NewObjectArray **************************************************************
4392 Constructs a new array holding objects in class elementClass. All
4393 elements are initially set to initialElement.
4395 *******************************************************************************/
4397 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4398 jclass elementClass, jobject initialElement)
4400 java_objectarray *oa;
4403 STATISTICS(jniinvokation());
4406 exceptions_throw_negativearraysizeexception();
4410 oa = builtin_anewarray(length, elementClass);
4415 /* set all elements to initialElement */
4417 for (i = 0; i < length; i++)
4418 oa->data[i] = initialElement;
4420 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4424 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4427 java_objectarray *oa;
4430 STATISTICS(jniinvokation());
4432 oa = (java_objectarray *) array;
4434 if (index >= oa->header.size) {
4435 exceptions_throw_arrayindexoutofboundsexception();
4439 o = oa->data[index];
4441 return _Jv_JNI_NewLocalRef(env, o);
4445 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4446 jsize index, jobject val)
4448 java_objectarray *oa;
4449 java_objectheader *o;
4451 STATISTICS(jniinvokation());
4453 oa = (java_objectarray *) array;
4454 o = (java_objectheader *) val;
4456 if (index >= oa->header.size) {
4457 exceptions_throw_arrayindexoutofboundsexception();
4461 /* check if the class of value is a subclass of the element class
4464 if (!builtin_canstore(oa, o))
4467 oa->data[index] = val;
4471 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4473 java_booleanarray *ba;
4475 STATISTICS(jniinvokation());
4478 exceptions_throw_negativearraysizeexception();
4482 ba = builtin_newarray_boolean(len);
4484 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4488 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4492 STATISTICS(jniinvokation());
4495 exceptions_throw_negativearraysizeexception();
4499 ba = builtin_newarray_byte(len);
4501 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4505 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4509 STATISTICS(jniinvokation());
4512 exceptions_throw_negativearraysizeexception();
4516 ca = builtin_newarray_char(len);
4518 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4522 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4524 java_shortarray *sa;
4526 STATISTICS(jniinvokation());
4529 exceptions_throw_negativearraysizeexception();
4533 sa = builtin_newarray_short(len);
4535 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4539 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4543 STATISTICS(jniinvokation());
4546 exceptions_throw_negativearraysizeexception();
4550 ia = builtin_newarray_int(len);
4552 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4556 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4560 STATISTICS(jniinvokation());
4563 exceptions_throw_negativearraysizeexception();
4567 la = builtin_newarray_long(len);
4569 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4573 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4575 java_floatarray *fa;
4577 STATISTICS(jniinvokation());
4580 exceptions_throw_negativearraysizeexception();
4584 fa = builtin_newarray_float(len);
4586 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4590 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4592 java_doublearray *da;
4594 STATISTICS(jniinvokation());
4597 exceptions_throw_negativearraysizeexception();
4601 da = builtin_newarray_double(len);
4603 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4607 /* Get<PrimitiveType>ArrayElements *********************************************
4609 A family of functions that returns the body of the primitive array.
4611 *******************************************************************************/
4613 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4616 java_booleanarray *ba;
4618 STATISTICS(jniinvokation());
4620 ba = (java_booleanarray *) array;
4623 *isCopy = JNI_FALSE;
4629 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4634 STATISTICS(jniinvokation());
4636 ba = (java_bytearray *) array;
4639 *isCopy = JNI_FALSE;
4645 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4650 STATISTICS(jniinvokation());
4652 ca = (java_chararray *) array;
4655 *isCopy = JNI_FALSE;
4661 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4664 java_shortarray *sa;
4666 STATISTICS(jniinvokation());
4668 sa = (java_shortarray *) array;
4671 *isCopy = JNI_FALSE;
4677 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4682 STATISTICS(jniinvokation());
4684 ia = (java_intarray *) array;
4687 *isCopy = JNI_FALSE;
4693 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4698 STATISTICS(jniinvokation());
4700 la = (java_longarray *) array;
4703 *isCopy = JNI_FALSE;
4705 /* We cast this one to prevent a compiler warning on 64-bit
4706 systems since GNU Classpath typedef jlong to long long. */
4708 return (jlong *) la->data;
4712 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4715 java_floatarray *fa;
4717 STATISTICS(jniinvokation());
4719 fa = (java_floatarray *) array;
4722 *isCopy = JNI_FALSE;
4728 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4731 java_doublearray *da;
4733 STATISTICS(jniinvokation());
4735 da = (java_doublearray *) array;
4738 *isCopy = JNI_FALSE;
4744 /* Release<PrimitiveType>ArrayElements *****************************************
4746 A family of functions that informs the VM that the native code no
4747 longer needs access to elems. The elems argument is a pointer
4748 derived from array using the corresponding
4749 Get<PrimitiveType>ArrayElements() function. If necessary, this
4750 function copies back all changes made to elems to the original
4753 *******************************************************************************/
4755 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4756 jboolean *elems, jint mode)
4758 java_booleanarray *ba;
4760 STATISTICS(jniinvokation());
4762 ba = (java_booleanarray *) array;
4764 if (elems != ba->data) {
4767 MCOPY(ba->data, elems, u1, ba->header.size);
4770 MCOPY(ba->data, elems, u1, ba->header.size);
4771 /* XXX TWISTI how should it be freed? */
4774 /* XXX TWISTI how should it be freed? */
4781 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4782 jbyte *elems, jint mode)
4786 STATISTICS(jniinvokation());
4788 ba = (java_bytearray *) array;
4790 if (elems != ba->data) {
4793 MCOPY(ba->data, elems, s1, ba->header.size);
4796 MCOPY(ba->data, elems, s1, ba->header.size);
4797 /* XXX TWISTI how should it be freed? */
4800 /* XXX TWISTI how should it be freed? */
4807 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4808 jchar *elems, jint mode)
4812 STATISTICS(jniinvokation());
4814 ca = (java_chararray *) array;
4816 if (elems != ca->data) {
4819 MCOPY(ca->data, elems, u2, ca->header.size);
4822 MCOPY(ca->data, elems, u2, ca->header.size);
4823 /* XXX TWISTI how should it be freed? */
4826 /* XXX TWISTI how should it be freed? */
4833 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4834 jshort *elems, jint mode)
4836 java_shortarray *sa;
4838 STATISTICS(jniinvokation());
4840 sa = (java_shortarray *) array;
4842 if (elems != sa->data) {
4845 MCOPY(sa->data, elems, s2, sa->header.size);
4848 MCOPY(sa->data, elems, s2, sa->header.size);
4849 /* XXX TWISTI how should it be freed? */
4852 /* XXX TWISTI how should it be freed? */
4859 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4864 STATISTICS(jniinvokation());
4866 ia = (java_intarray *) array;
4868 if (elems != ia->data) {
4871 MCOPY(ia->data, elems, s4, ia->header.size);
4874 MCOPY(ia->data, elems, s4, ia->header.size);
4875 /* XXX TWISTI how should it be freed? */
4878 /* XXX TWISTI how should it be freed? */
4885 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4886 jlong *elems, jint mode)
4890 STATISTICS(jniinvokation());
4892 la = (java_longarray *) array;
4894 /* We cast this one to prevent a compiler warning on 64-bit
4895 systems since GNU Classpath typedef jlong to long long. */
4897 if ((s8 *) elems != la->data) {
4900 MCOPY(la->data, elems, s8, la->header.size);
4903 MCOPY(la->data, elems, s8, la->header.size);
4904 /* XXX TWISTI how should it be freed? */
4907 /* XXX TWISTI how should it be freed? */
4914 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4915 jfloat *elems, jint mode)
4917 java_floatarray *fa;
4919 STATISTICS(jniinvokation());
4921 fa = (java_floatarray *) array;
4923 if (elems != fa->data) {
4926 MCOPY(fa->data, elems, float, fa->header.size);
4929 MCOPY(fa->data, elems, float, fa->header.size);
4930 /* XXX TWISTI how should it be freed? */
4933 /* XXX TWISTI how should it be freed? */
4940 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4941 jdouble *elems, jint mode)
4943 java_doublearray *da;
4945 STATISTICS(jniinvokation());
4947 da = (java_doublearray *) array;
4949 if (elems != da->data) {
4952 MCOPY(da->data, elems, double, da->header.size);
4955 MCOPY(da->data, elems, double, da->header.size);
4956 /* XXX TWISTI how should it be freed? */
4959 /* XXX TWISTI how should it be freed? */
4966 /* Get<PrimitiveType>ArrayRegion **********************************************
4968 A family of functions that copies a region of a primitive array
4971 *******************************************************************************/
4973 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4974 jsize start, jsize len, jboolean *buf)
4976 java_booleanarray *ba;
4978 STATISTICS(jniinvokation());
4980 ba = (java_booleanarray *) array;
4982 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4983 exceptions_throw_arrayindexoutofboundsexception();
4985 MCOPY(buf, &ba->data[start], u1, len);
4989 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4990 jsize len, jbyte *buf)
4994 STATISTICS(jniinvokation());
4996 ba = (java_bytearray *) array;
4998 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4999 exceptions_throw_arrayindexoutofboundsexception();
5001 MCOPY(buf, &ba->data[start], s1, len);
5005 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5006 jsize len, jchar *buf)
5010 STATISTICS(jniinvokation());
5012 ca = (java_chararray *) array;
5014 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5015 exceptions_throw_arrayindexoutofboundsexception();
5017 MCOPY(buf, &ca->data[start], u2, len);
5021 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5022 jsize len, jshort *buf)
5024 java_shortarray *sa;
5026 STATISTICS(jniinvokation());
5028 sa = (java_shortarray *) array;
5030 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5031 exceptions_throw_arrayindexoutofboundsexception();
5033 MCOPY(buf, &sa->data[start], s2, len);
5037 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5038 jsize len, jint *buf)
5042 STATISTICS(jniinvokation());
5044 ia = (java_intarray *) array;
5046 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5047 exceptions_throw_arrayindexoutofboundsexception();
5049 MCOPY(buf, &ia->data[start], s4, len);
5053 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5054 jsize len, jlong *buf)
5058 STATISTICS(jniinvokation());
5060 la = (java_longarray *) array;
5062 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5063 exceptions_throw_arrayindexoutofboundsexception();
5065 MCOPY(buf, &la->data[start], s8, len);
5069 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5070 jsize len, jfloat *buf)
5072 java_floatarray *fa;
5074 STATISTICS(jniinvokation());
5076 fa = (java_floatarray *) array;
5078 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5079 exceptions_throw_arrayindexoutofboundsexception();
5081 MCOPY(buf, &fa->data[start], float, len);
5085 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5086 jsize len, jdouble *buf)
5088 java_doublearray *da;
5090 STATISTICS(jniinvokation());
5092 da = (java_doublearray *) array;
5094 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5095 exceptions_throw_arrayindexoutofboundsexception();
5097 MCOPY(buf, &da->data[start], double, len);
5101 /* Set<PrimitiveType>ArrayRegion **********************************************
5103 A family of functions that copies back a region of a primitive
5104 array from a buffer.
5106 *******************************************************************************/
5108 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5109 jsize start, jsize len, jboolean *buf)
5111 java_booleanarray *ba;
5113 STATISTICS(jniinvokation());
5115 ba = (java_booleanarray *) array;
5117 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5118 exceptions_throw_arrayindexoutofboundsexception();
5120 MCOPY(&ba->data[start], buf, u1, len);
5124 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5125 jsize len, jbyte *buf)
5129 STATISTICS(jniinvokation());
5131 ba = (java_bytearray *) array;
5133 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5134 exceptions_throw_arrayindexoutofboundsexception();
5136 MCOPY(&ba->data[start], buf, s1, len);
5140 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5141 jsize len, jchar *buf)
5145 STATISTICS(jniinvokation());
5147 ca = (java_chararray *) array;
5149 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5150 exceptions_throw_arrayindexoutofboundsexception();
5152 MCOPY(&ca->data[start], buf, u2, len);
5156 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5157 jsize len, jshort *buf)
5159 java_shortarray *sa;
5161 STATISTICS(jniinvokation());
5163 sa = (java_shortarray *) array;
5165 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5166 exceptions_throw_arrayindexoutofboundsexception();
5168 MCOPY(&sa->data[start], buf, s2, len);
5172 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5173 jsize len, jint *buf)
5177 STATISTICS(jniinvokation());
5179 ia = (java_intarray *) array;
5181 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5182 exceptions_throw_arrayindexoutofboundsexception();
5184 MCOPY(&ia->data[start], buf, s4, len);
5188 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5189 jsize len, jlong *buf)
5193 STATISTICS(jniinvokation());
5195 la = (java_longarray *) array;
5197 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5198 exceptions_throw_arrayindexoutofboundsexception();
5200 MCOPY(&la->data[start], buf, s8, len);
5204 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5205 jsize len, jfloat *buf)
5207 java_floatarray *fa;
5209 STATISTICS(jniinvokation());
5211 fa = (java_floatarray *) array;
5213 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5214 exceptions_throw_arrayindexoutofboundsexception();
5216 MCOPY(&fa->data[start], buf, float, len);
5220 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5221 jsize len, jdouble *buf)
5223 java_doublearray *da;
5225 STATISTICS(jniinvokation());
5227 da = (java_doublearray *) array;
5229 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5230 exceptions_throw_arrayindexoutofboundsexception();
5232 MCOPY(&da->data[start], buf, double, len);
5236 /* Registering Native Methods *************************************************/
5238 /* RegisterNatives *************************************************************
5240 Registers native methods with the class specified by the clazz
5241 argument. The methods parameter specifies an array of
5242 JNINativeMethod structures that contain the names, signatures, and
5243 function pointers of the native methods. The nMethods parameter
5244 specifies the number of native methods in the array.
5246 *******************************************************************************/
5248 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5249 const JNINativeMethod *methods, jint nMethods)
5251 STATISTICS(jniinvokation());
5253 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5254 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5255 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5262 /* UnregisterNatives ***********************************************************
5264 Unregisters native methods of a class. The class goes back to the
5265 state before it was linked or registered with its native method
5268 This function should not be used in normal native code. Instead, it
5269 provides special programs a way to reload and relink native
5272 *******************************************************************************/
5274 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5276 STATISTICS(jniinvokation());
5278 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5280 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5286 /* Monitor Operations *********************************************************/
5288 /* MonitorEnter ****************************************************************
5290 Enters the monitor associated with the underlying Java object
5293 *******************************************************************************/
5295 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5297 STATISTICS(jniinvokation());
5300 exceptions_throw_nullpointerexception();
5304 LOCK_MONITOR_ENTER(obj);
5310 /* MonitorExit *****************************************************************
5312 The current thread must be the owner of the monitor associated with
5313 the underlying Java object referred to by obj. The thread
5314 decrements the counter indicating the number of times it has
5315 entered this monitor. If the value of the counter becomes zero, the
5316 current thread releases the monitor.
5318 *******************************************************************************/
5320 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5322 STATISTICS(jniinvokation());
5325 exceptions_throw_nullpointerexception();
5329 LOCK_MONITOR_EXIT(obj);
5335 /* JavaVM Interface ***********************************************************/
5337 /* GetJavaVM *******************************************************************
5339 Returns the Java VM interface (used in the Invocation API)
5340 associated with the current thread. The result is placed at the
5341 location pointed to by the second argument, vm.
5343 *******************************************************************************/
5345 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5347 STATISTICS(jniinvokation());
5349 *vm = (JavaVM *) _Jv_jvm;
5355 /* GetStringRegion *************************************************************
5357 Copies len number of Unicode characters beginning at offset start
5358 to the given buffer buf.
5360 Throws StringIndexOutOfBoundsException on index overflow.
5362 *******************************************************************************/
5364 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5367 java_lang_String *s;
5370 STATISTICS(jniinvokation());
5372 s = (java_lang_String *) str;
5375 if ((start < 0) || (len < 0) || (start > s->count) ||
5376 (start + len > s->count)) {
5377 exceptions_throw_stringindexoutofboundsexception();
5381 MCOPY(buf, &ca->data[start], u2, len);
5385 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5386 jsize len, char *buf)
5388 STATISTICS(jniinvokation());
5390 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5394 /* GetPrimitiveArrayCritical ***************************************************
5396 Obtain a direct pointer to array elements.
5398 *******************************************************************************/
5400 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5406 ba = (java_bytearray *) array;
5408 /* do the same as Kaffe does */
5410 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5416 /* ReleasePrimitiveArrayCritical ***********************************************
5418 No specific documentation.
5420 *******************************************************************************/
5422 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5423 void *carray, jint mode)
5425 STATISTICS(jniinvokation());
5427 /* do the same as Kaffe does */
5429 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5434 /* GetStringCritical ***********************************************************
5436 The semantics of these two functions are similar to the existing
5437 Get/ReleaseStringChars functions.
5439 *******************************************************************************/
5441 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5444 STATISTICS(jniinvokation());
5446 return _Jv_JNI_GetStringChars(env, string, isCopy);
5450 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5451 const jchar *cstring)
5453 STATISTICS(jniinvokation());
5455 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5459 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5461 STATISTICS(jniinvokation());
5463 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5469 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5471 STATISTICS(jniinvokation());
5473 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5477 /* NewGlobalRef ****************************************************************
5479 Creates a new global reference to the object referred to by the obj
5482 *******************************************************************************/
5484 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5486 hashtable_global_ref_entry *gre;
5487 u4 key; /* hashkey */
5488 u4 slot; /* slot in hashtable */
5490 STATISTICS(jniinvokation());
5492 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5494 /* normally addresses are aligned to 4, 8 or 16 bytes */
5496 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5497 slot = key & (hashtable_global_ref->size - 1);
5498 gre = hashtable_global_ref->ptr[slot];
5500 /* search external hash chain for the entry */
5503 if (gre->o == obj) {
5504 /* global object found, increment the reference */
5508 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5513 gre = gre->hashlink; /* next element in external chain */
5516 /* global ref not found, create a new one */
5518 gre = NEW(hashtable_global_ref_entry);
5523 /* insert entry into hashtable */
5525 gre->hashlink = hashtable_global_ref->ptr[slot];
5527 hashtable_global_ref->ptr[slot] = gre;
5529 /* update number of hashtable-entries */
5531 hashtable_global_ref->entries++;
5533 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5539 /* DeleteGlobalRef *************************************************************
5541 Deletes the global reference pointed to by globalRef.
5543 *******************************************************************************/
5545 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5547 hashtable_global_ref_entry *gre;
5548 hashtable_global_ref_entry *prevgre;
5549 u4 key; /* hashkey */
5550 u4 slot; /* slot in hashtable */
5552 STATISTICS(jniinvokation());
5554 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5556 /* normally addresses are aligned to 4, 8 or 16 bytes */
5558 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5559 slot = key & (hashtable_global_ref->size - 1);
5560 gre = hashtable_global_ref->ptr[slot];
5562 /* initialize prevgre */
5566 /* search external hash chain for the entry */
5569 if (gre->o == globalRef) {
5570 /* global object found, decrement the reference count */
5574 /* if reference count is 0, remove the entry */
5576 if (gre->refs == 0) {
5577 /* special handling if it's the first in the chain */
5579 if (prevgre == NULL)
5580 hashtable_global_ref->ptr[slot] = gre->hashlink;
5582 prevgre->hashlink = gre->hashlink;
5584 FREE(gre, hashtable_global_ref_entry);
5587 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5592 prevgre = gre; /* save current pointer for removal */
5593 gre = gre->hashlink; /* next element in external chain */
5596 log_println("JNI-DeleteGlobalRef: global reference not found");
5598 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5602 /* ExceptionCheck **************************************************************
5604 Returns JNI_TRUE when there is a pending exception; otherwise,
5607 *******************************************************************************/
5609 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5611 java_objectheader *o;
5613 STATISTICS(jniinvokation());
5615 o = exceptions_get_exception();
5617 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5621 /* New JNI 1.4 functions ******************************************************/
5623 /* NewDirectByteBuffer *********************************************************
5625 Allocates and returns a direct java.nio.ByteBuffer referring to the
5626 block of memory starting at the memory address address and
5627 extending capacity bytes.
5629 *******************************************************************************/
5631 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5633 #if defined(ENABLE_JAVASE)
5634 java_objectheader *nbuf;
5635 # if SIZEOF_VOID_P == 8
5636 gnu_classpath_Pointer64 *paddress;
5638 gnu_classpath_Pointer32 *paddress;
5641 STATISTICS(jniinvokation());
5643 /* alocate a gnu.classpath.Pointer{32,64} object */
5645 # if SIZEOF_VOID_P == 8
5646 if (!(paddress = (gnu_classpath_Pointer64 *)
5647 builtin_new(class_gnu_classpath_Pointer64)))
5649 if (!(paddress = (gnu_classpath_Pointer32 *)
5650 builtin_new(class_gnu_classpath_Pointer32)))
5654 /* fill gnu.classpath.Pointer{32,64} with address */
5656 paddress->data = (ptrint) address;
5658 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5660 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5661 (jmethodID) dbbirw_init, NULL, paddress,
5662 (jint) capacity, (jint) capacity, (jint) 0);
5664 /* add local reference and return the value */
5666 return _Jv_JNI_NewLocalRef(env, nbuf);
5668 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5670 /* keep compiler happy */
5677 /* GetDirectBufferAddress ******************************************************
5679 Fetches and returns the starting address of the memory region
5680 referenced by the given direct java.nio.Buffer.
5682 *******************************************************************************/
5684 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5686 #if defined(ENABLE_JAVASE)
5687 java_nio_DirectByteBufferImpl *nbuf;
5688 # if SIZEOF_VOID_P == 8
5689 gnu_classpath_Pointer64 *address;
5691 gnu_classpath_Pointer32 *address;
5694 STATISTICS(jniinvokation());
5696 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5699 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5701 # if SIZEOF_VOID_P == 8
5702 address = (gnu_classpath_Pointer64 *) nbuf->address;
5704 address = (gnu_classpath_Pointer32 *) nbuf->address;
5707 if (address == NULL)
5710 return (void *) address->data;
5712 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5714 /* keep compiler happy */
5721 /* GetDirectBufferCapacity *****************************************************
5723 Fetches and returns the capacity in bytes of the memory region
5724 referenced by the given direct java.nio.Buffer.
5726 *******************************************************************************/
5728 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5730 #if defined(ENABLE_JAVASE)
5731 java_nio_Buffer *nbuf;
5733 STATISTICS(jniinvokation());
5735 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5738 nbuf = (java_nio_Buffer *) buf;
5740 return (jlong) nbuf->cap;
5742 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5744 /* keep compiler happy */
5751 /* DestroyJavaVM ***************************************************************
5753 Unloads a Java VM and reclaims its resources. Only the main thread
5754 can unload the VM. The system waits until the main thread is only
5755 remaining user thread before it destroys the VM.
5757 *******************************************************************************/
5759 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5763 STATISTICS(jniinvokation());
5765 status = vm_destroy(vm);
5771 /* AttachCurrentThread *********************************************************
5773 Attaches the current thread to a Java VM. Returns a JNI interface
5774 pointer in the JNIEnv argument.
5776 Trying to attach a thread that is already attached is a no-op.
5778 A native thread cannot be attached simultaneously to two Java VMs.
5780 When a thread is attached to the VM, the context class loader is
5781 the bootstrap loader.
5783 *******************************************************************************/
5785 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5787 JavaVMAttachArgs *vm_aargs;
5789 #if defined(ENABLE_THREADS)
5790 if (threads_get_current_threadobject() == NULL) {
5791 vm_aargs = (JavaVMAttachArgs *) thr_args;
5793 if (vm_aargs != NULL) {
5794 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5795 (vm_aargs->version != JNI_VERSION_1_4))
5796 return JNI_EVERSION;
5799 if (!threads_attach_current_thread(vm_aargs, false))
5802 if (!jni_init_localref_table())
5813 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5815 STATISTICS(jniinvokation());
5817 return jni_attach_current_thread(p_env, thr_args, false);
5821 /* DetachCurrentThread *********************************************************
5823 Detaches the current thread from a Java VM. All Java monitors held
5824 by this thread are released. All Java threads waiting for this
5825 thread to die are notified.
5827 In JDK 1.1, the main thread cannot be detached from the VM. It must
5828 call DestroyJavaVM to unload the entire VM.
5830 In the JDK, the main thread can be detached from the VM.
5832 The main thread, which is the thread that created the Java VM,
5833 cannot be detached from the VM. Instead, the main thread must call
5834 JNI_DestroyJavaVM() to unload the entire VM.
5836 *******************************************************************************/
5838 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5840 #if defined(ENABLE_THREADS)
5841 threadobject *thread;
5843 STATISTICS(jniinvokation());
5845 thread = threads_get_current_threadobject();
5850 if (!threads_detach_thread(thread))
5858 /* GetEnv **********************************************************************
5860 If the current thread is not attached to the VM, sets *env to NULL,
5861 and returns JNI_EDETACHED. If the specified version is not
5862 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5863 sets *env to the appropriate interface, and returns JNI_OK.
5865 *******************************************************************************/
5867 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5869 STATISTICS(jniinvokation());
5871 #if defined(ENABLE_THREADS)
5872 if (threads_get_current_threadobject() == NULL) {
5875 return JNI_EDETACHED;
5879 /* check the JNI version */
5882 case JNI_VERSION_1_1:
5883 case JNI_VERSION_1_2:
5884 case JNI_VERSION_1_4:
5892 #if defined(ENABLE_JVMTI)
5893 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5894 == JVMTI_VERSION_INTERFACE_JVMTI) {
5896 *env = (void *) jvmti_new_environment();
5905 return JNI_EVERSION;
5909 /* AttachCurrentThreadAsDaemon *************************************************
5911 Same semantics as AttachCurrentThread, but the newly-created
5912 java.lang.Thread instance is a daemon.
5914 If the thread has already been attached via either
5915 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5916 simply sets the value pointed to by penv to the JNIEnv of the
5917 current thread. In this case neither AttachCurrentThread nor this
5918 routine have any effect on the daemon status of the thread.
5920 *******************************************************************************/
5922 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5924 STATISTICS(jniinvokation());
5926 return jni_attach_current_thread(penv, args, true);
5930 /* JNI invocation table *******************************************************/
5932 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5937 _Jv_JNI_DestroyJavaVM,
5938 _Jv_JNI_AttachCurrentThread,
5939 _Jv_JNI_DetachCurrentThread,
5941 _Jv_JNI_AttachCurrentThreadAsDaemon
5945 /* JNI function table *********************************************************/
5947 struct JNINativeInterface _Jv_JNINativeInterface = {
5954 _Jv_JNI_DefineClass,
5956 _Jv_JNI_FromReflectedMethod,
5957 _Jv_JNI_FromReflectedField,
5958 _Jv_JNI_ToReflectedMethod,
5959 _Jv_JNI_GetSuperclass,
5960 _Jv_JNI_IsAssignableFrom,
5961 _Jv_JNI_ToReflectedField,
5965 _Jv_JNI_ExceptionOccurred,
5966 _Jv_JNI_ExceptionDescribe,
5967 _Jv_JNI_ExceptionClear,
5969 _Jv_JNI_PushLocalFrame,
5970 _Jv_JNI_PopLocalFrame,
5972 _Jv_JNI_NewGlobalRef,
5973 _Jv_JNI_DeleteGlobalRef,
5974 _Jv_JNI_DeleteLocalRef,
5975 _Jv_JNI_IsSameObject,
5976 _Jv_JNI_NewLocalRef,
5977 _Jv_JNI_EnsureLocalCapacity,
5979 _Jv_JNI_AllocObject,
5984 _Jv_JNI_GetObjectClass,
5985 _Jv_JNI_IsInstanceOf,
5987 _Jv_JNI_GetMethodID,
5989 _Jv_JNI_CallObjectMethod,
5990 _Jv_JNI_CallObjectMethodV,
5991 _Jv_JNI_CallObjectMethodA,
5992 _Jv_JNI_CallBooleanMethod,
5993 _Jv_JNI_CallBooleanMethodV,
5994 _Jv_JNI_CallBooleanMethodA,
5995 _Jv_JNI_CallByteMethod,
5996 _Jv_JNI_CallByteMethodV,
5997 _Jv_JNI_CallByteMethodA,
5998 _Jv_JNI_CallCharMethod,
5999 _Jv_JNI_CallCharMethodV,
6000 _Jv_JNI_CallCharMethodA,
6001 _Jv_JNI_CallShortMethod,
6002 _Jv_JNI_CallShortMethodV,
6003 _Jv_JNI_CallShortMethodA,
6004 _Jv_JNI_CallIntMethod,
6005 _Jv_JNI_CallIntMethodV,
6006 _Jv_JNI_CallIntMethodA,
6007 _Jv_JNI_CallLongMethod,
6008 _Jv_JNI_CallLongMethodV,
6009 _Jv_JNI_CallLongMethodA,
6010 _Jv_JNI_CallFloatMethod,
6011 _Jv_JNI_CallFloatMethodV,
6012 _Jv_JNI_CallFloatMethodA,
6013 _Jv_JNI_CallDoubleMethod,
6014 _Jv_JNI_CallDoubleMethodV,
6015 _Jv_JNI_CallDoubleMethodA,
6016 _Jv_JNI_CallVoidMethod,
6017 _Jv_JNI_CallVoidMethodV,
6018 _Jv_JNI_CallVoidMethodA,
6020 _Jv_JNI_CallNonvirtualObjectMethod,
6021 _Jv_JNI_CallNonvirtualObjectMethodV,
6022 _Jv_JNI_CallNonvirtualObjectMethodA,
6023 _Jv_JNI_CallNonvirtualBooleanMethod,
6024 _Jv_JNI_CallNonvirtualBooleanMethodV,
6025 _Jv_JNI_CallNonvirtualBooleanMethodA,
6026 _Jv_JNI_CallNonvirtualByteMethod,
6027 _Jv_JNI_CallNonvirtualByteMethodV,
6028 _Jv_JNI_CallNonvirtualByteMethodA,
6029 _Jv_JNI_CallNonvirtualCharMethod,
6030 _Jv_JNI_CallNonvirtualCharMethodV,
6031 _Jv_JNI_CallNonvirtualCharMethodA,
6032 _Jv_JNI_CallNonvirtualShortMethod,
6033 _Jv_JNI_CallNonvirtualShortMethodV,
6034 _Jv_JNI_CallNonvirtualShortMethodA,
6035 _Jv_JNI_CallNonvirtualIntMethod,
6036 _Jv_JNI_CallNonvirtualIntMethodV,
6037 _Jv_JNI_CallNonvirtualIntMethodA,
6038 _Jv_JNI_CallNonvirtualLongMethod,
6039 _Jv_JNI_CallNonvirtualLongMethodV,
6040 _Jv_JNI_CallNonvirtualLongMethodA,
6041 _Jv_JNI_CallNonvirtualFloatMethod,
6042 _Jv_JNI_CallNonvirtualFloatMethodV,
6043 _Jv_JNI_CallNonvirtualFloatMethodA,
6044 _Jv_JNI_CallNonvirtualDoubleMethod,
6045 _Jv_JNI_CallNonvirtualDoubleMethodV,
6046 _Jv_JNI_CallNonvirtualDoubleMethodA,
6047 _Jv_JNI_CallNonvirtualVoidMethod,
6048 _Jv_JNI_CallNonvirtualVoidMethodV,
6049 _Jv_JNI_CallNonvirtualVoidMethodA,
6053 _Jv_JNI_GetObjectField,
6054 _Jv_JNI_GetBooleanField,
6055 _Jv_JNI_GetByteField,
6056 _Jv_JNI_GetCharField,
6057 _Jv_JNI_GetShortField,
6058 _Jv_JNI_GetIntField,
6059 _Jv_JNI_GetLongField,
6060 _Jv_JNI_GetFloatField,
6061 _Jv_JNI_GetDoubleField,
6062 _Jv_JNI_SetObjectField,
6063 _Jv_JNI_SetBooleanField,
6064 _Jv_JNI_SetByteField,
6065 _Jv_JNI_SetCharField,
6066 _Jv_JNI_SetShortField,
6067 _Jv_JNI_SetIntField,
6068 _Jv_JNI_SetLongField,
6069 _Jv_JNI_SetFloatField,
6070 _Jv_JNI_SetDoubleField,
6072 _Jv_JNI_GetStaticMethodID,
6074 _Jv_JNI_CallStaticObjectMethod,
6075 _Jv_JNI_CallStaticObjectMethodV,
6076 _Jv_JNI_CallStaticObjectMethodA,
6077 _Jv_JNI_CallStaticBooleanMethod,
6078 _Jv_JNI_CallStaticBooleanMethodV,
6079 _Jv_JNI_CallStaticBooleanMethodA,
6080 _Jv_JNI_CallStaticByteMethod,
6081 _Jv_JNI_CallStaticByteMethodV,
6082 _Jv_JNI_CallStaticByteMethodA,
6083 _Jv_JNI_CallStaticCharMethod,
6084 _Jv_JNI_CallStaticCharMethodV,
6085 _Jv_JNI_CallStaticCharMethodA,
6086 _Jv_JNI_CallStaticShortMethod,
6087 _Jv_JNI_CallStaticShortMethodV,
6088 _Jv_JNI_CallStaticShortMethodA,
6089 _Jv_JNI_CallStaticIntMethod,
6090 _Jv_JNI_CallStaticIntMethodV,
6091 _Jv_JNI_CallStaticIntMethodA,
6092 _Jv_JNI_CallStaticLongMethod,
6093 _Jv_JNI_CallStaticLongMethodV,
6094 _Jv_JNI_CallStaticLongMethodA,
6095 _Jv_JNI_CallStaticFloatMethod,
6096 _Jv_JNI_CallStaticFloatMethodV,
6097 _Jv_JNI_CallStaticFloatMethodA,
6098 _Jv_JNI_CallStaticDoubleMethod,
6099 _Jv_JNI_CallStaticDoubleMethodV,
6100 _Jv_JNI_CallStaticDoubleMethodA,
6101 _Jv_JNI_CallStaticVoidMethod,
6102 _Jv_JNI_CallStaticVoidMethodV,
6103 _Jv_JNI_CallStaticVoidMethodA,
6105 _Jv_JNI_GetStaticFieldID,
6107 _Jv_JNI_GetStaticObjectField,
6108 _Jv_JNI_GetStaticBooleanField,
6109 _Jv_JNI_GetStaticByteField,
6110 _Jv_JNI_GetStaticCharField,
6111 _Jv_JNI_GetStaticShortField,
6112 _Jv_JNI_GetStaticIntField,
6113 _Jv_JNI_GetStaticLongField,
6114 _Jv_JNI_GetStaticFloatField,
6115 _Jv_JNI_GetStaticDoubleField,
6116 _Jv_JNI_SetStaticObjectField,
6117 _Jv_JNI_SetStaticBooleanField,
6118 _Jv_JNI_SetStaticByteField,
6119 _Jv_JNI_SetStaticCharField,
6120 _Jv_JNI_SetStaticShortField,
6121 _Jv_JNI_SetStaticIntField,
6122 _Jv_JNI_SetStaticLongField,
6123 _Jv_JNI_SetStaticFloatField,
6124 _Jv_JNI_SetStaticDoubleField,
6127 _Jv_JNI_GetStringLength,
6128 _Jv_JNI_GetStringChars,
6129 _Jv_JNI_ReleaseStringChars,
6131 _Jv_JNI_NewStringUTF,
6132 _Jv_JNI_GetStringUTFLength,
6133 _Jv_JNI_GetStringUTFChars,
6134 _Jv_JNI_ReleaseStringUTFChars,
6136 _Jv_JNI_GetArrayLength,
6138 _Jv_JNI_NewObjectArray,
6139 _Jv_JNI_GetObjectArrayElement,
6140 _Jv_JNI_SetObjectArrayElement,
6142 _Jv_JNI_NewBooleanArray,
6143 _Jv_JNI_NewByteArray,
6144 _Jv_JNI_NewCharArray,
6145 _Jv_JNI_NewShortArray,
6146 _Jv_JNI_NewIntArray,
6147 _Jv_JNI_NewLongArray,
6148 _Jv_JNI_NewFloatArray,
6149 _Jv_JNI_NewDoubleArray,
6151 _Jv_JNI_GetBooleanArrayElements,
6152 _Jv_JNI_GetByteArrayElements,
6153 _Jv_JNI_GetCharArrayElements,
6154 _Jv_JNI_GetShortArrayElements,
6155 _Jv_JNI_GetIntArrayElements,
6156 _Jv_JNI_GetLongArrayElements,
6157 _Jv_JNI_GetFloatArrayElements,
6158 _Jv_JNI_GetDoubleArrayElements,
6160 _Jv_JNI_ReleaseBooleanArrayElements,
6161 _Jv_JNI_ReleaseByteArrayElements,
6162 _Jv_JNI_ReleaseCharArrayElements,
6163 _Jv_JNI_ReleaseShortArrayElements,
6164 _Jv_JNI_ReleaseIntArrayElements,
6165 _Jv_JNI_ReleaseLongArrayElements,
6166 _Jv_JNI_ReleaseFloatArrayElements,
6167 _Jv_JNI_ReleaseDoubleArrayElements,
6169 _Jv_JNI_GetBooleanArrayRegion,
6170 _Jv_JNI_GetByteArrayRegion,
6171 _Jv_JNI_GetCharArrayRegion,
6172 _Jv_JNI_GetShortArrayRegion,
6173 _Jv_JNI_GetIntArrayRegion,
6174 _Jv_JNI_GetLongArrayRegion,
6175 _Jv_JNI_GetFloatArrayRegion,
6176 _Jv_JNI_GetDoubleArrayRegion,
6177 _Jv_JNI_SetBooleanArrayRegion,
6178 _Jv_JNI_SetByteArrayRegion,
6179 _Jv_JNI_SetCharArrayRegion,
6180 _Jv_JNI_SetShortArrayRegion,
6181 _Jv_JNI_SetIntArrayRegion,
6182 _Jv_JNI_SetLongArrayRegion,
6183 _Jv_JNI_SetFloatArrayRegion,
6184 _Jv_JNI_SetDoubleArrayRegion,
6186 _Jv_JNI_RegisterNatives,
6187 _Jv_JNI_UnregisterNatives,
6189 _Jv_JNI_MonitorEnter,
6190 _Jv_JNI_MonitorExit,
6194 /* new JNI 1.2 functions */
6196 _Jv_JNI_GetStringRegion,
6197 _Jv_JNI_GetStringUTFRegion,
6199 _Jv_JNI_GetPrimitiveArrayCritical,
6200 _Jv_JNI_ReleasePrimitiveArrayCritical,
6202 _Jv_JNI_GetStringCritical,
6203 _Jv_JNI_ReleaseStringCritical,
6205 _Jv_JNI_NewWeakGlobalRef,
6206 _Jv_JNI_DeleteWeakGlobalRef,
6208 _Jv_JNI_ExceptionCheck,
6210 /* new JNI 1.4 functions */
6212 _Jv_JNI_NewDirectByteBuffer,
6213 _Jv_JNI_GetDirectBufferAddress,
6214 _Jv_JNI_GetDirectBufferCapacity
6218 /* Invocation API Functions ***************************************************/
6220 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6222 Returns a default configuration for the Java VM.
6224 *******************************************************************************/
6226 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6228 JavaVMInitArgs *_vm_args;
6230 _vm_args = (JavaVMInitArgs *) vm_args;
6232 /* GNU classpath currently supports JNI 1.2 */
6234 switch (_vm_args->version) {
6235 case JNI_VERSION_1_1:
6236 _vm_args->version = JNI_VERSION_1_1;
6239 case JNI_VERSION_1_2:
6240 case JNI_VERSION_1_4:
6241 _vm_args->ignoreUnrecognized = JNI_FALSE;
6242 _vm_args->options = NULL;
6243 _vm_args->nOptions = 0;
6254 /* JNI_GetCreatedJavaVMs *******************************************************
6256 Returns all Java VMs that have been created. Pointers to VMs are written in
6257 the buffer vmBuf in the order they are created. At most bufLen number of
6258 entries will be written. The total number of created VMs is returned in
6261 *******************************************************************************/
6263 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6265 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6271 /* JNI_CreateJavaVM ************************************************************
6273 Loads and initializes a Java VM. The current thread becomes the main thread.
6274 Sets the env argument to the JNI interface pointer of the main thread.
6276 *******************************************************************************/
6278 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6280 /* actually create the JVM */
6282 if (!vm_createjvm(p_vm, p_env, vm_args))
6290 * These are local overrides for various environment variables in Emacs.
6291 * Please do not remove this and leave it at the end of the file, where
6292 * Emacs will automagically detect them.
6293 * ---------------------------------------------------------------------
6296 * indent-tabs-mode: t
6300 * vim:noexpandtab:sw=4:ts=4: