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 8245 2007-07-31 09:55:04Z michi $
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 # if defined(WITH_CLASSPATH_SUN)
69 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
72 # include "native/include/java_lang_ClassLoader.h"
74 # include "native/include/java_lang_reflect_Constructor.h"
75 # include "native/include/java_lang_reflect_Field.h"
76 # include "native/include/java_lang_reflect_Method.h"
78 # include "native/include/java_nio_Buffer.h"
80 # if defined(WITH_CLASSPATH_GNU)
81 # include "native/include/java_nio_DirectByteBufferImpl.h"
85 #if defined(ENABLE_JVMTI)
86 # include "native/jvmti/cacaodbg.h"
89 #include "native/vm/java_lang_Class.h"
91 #if defined(ENABLE_JAVASE)
92 # include "native/vm/java_lang_ClassLoader.h"
93 # include "native/vm/reflect.h"
96 #include "threads/lock-common.h"
97 #include "threads/threads-common.h"
99 #include "toolbox/logging.h"
101 #include "vm/builtin.h"
102 #include "vm/exceptions.h"
103 #include "vm/global.h"
104 #include "vm/initialize.h"
105 #include "vm/resolve.h"
106 #include "vm/stringlocal.h"
109 #include "vm/jit/asmpart.h"
110 #include "vm/jit/jit.h"
111 #include "vm/jit/stacktrace.h"
113 #include "vmcore/loader.h"
114 #include "vmcore/options.h"
115 #include "vmcore/primitive.h"
116 #include "vmcore/statistics.h"
119 /* debug **********************************************************************/
122 # define TRACEJNICALLS(format, ...) \
124 if (opt_TraceJNICalls) { \
125 log_println((format), __VA_ARGS__); \
129 # define TRACEJNICALLS(format, ...)
133 /* global variables ***********************************************************/
135 /* global reference table *****************************************************/
137 /* hashsize must be power of 2 */
139 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
141 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
144 /* direct buffer stuff ********************************************************/
146 #if defined(ENABLE_JAVASE)
147 static classinfo *class_java_nio_Buffer;
148 static classinfo *class_java_nio_DirectByteBufferImpl;
149 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
151 # if defined(WITH_CLASSPATH_GNU)
152 # if SIZEOF_VOID_P == 8
153 static classinfo *class_gnu_classpath_Pointer64;
155 static classinfo *class_gnu_classpath_Pointer32;
159 static methodinfo *dbbirw_init;
163 /* local reference table ******************************************************/
165 #if !defined(ENABLE_THREADS)
166 localref_table *_no_threads_localref_table;
170 /* accessing instance fields macros *******************************************/
172 #define SET_FIELD(o,type,f,value) \
173 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
175 #define GET_FIELD(o,type,f) \
176 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
179 /* some forward declarations **************************************************/
181 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
182 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
185 /* jni_init ********************************************************************
187 Initialize the JNI subsystem.
189 *******************************************************************************/
193 /* create global ref hashtable */
195 hashtable_global_ref = NEW(hashtable);
197 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
200 #if defined(ENABLE_JAVASE)
201 /* direct buffer stuff */
203 if (!(class_java_nio_Buffer =
204 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
205 !link_class(class_java_nio_Buffer))
208 # if defined(WITH_CLASSPATH_GNU)
209 if (!(class_java_nio_DirectByteBufferImpl =
210 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
211 !link_class(class_java_nio_DirectByteBufferImpl))
214 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
215 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
216 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
220 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
222 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
225 # if SIZEOF_VOID_P == 8
226 if (!(class_gnu_classpath_Pointer64 =
227 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
228 !link_class(class_gnu_classpath_Pointer64))
231 if (!(class_gnu_classpath_Pointer32 =
232 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
233 !link_class(class_gnu_classpath_Pointer32))
237 #endif /* defined(ENABLE_JAVASE) */
243 /* jni_init_localref_table *****************************************************
245 Initializes the local references table of the current thread.
247 *******************************************************************************/
249 bool jni_init_localref_table(void)
253 #if defined(ENABLE_GC_CACAO)
254 /* XXX this one will never get freed for the main thread;
255 call jni_free_localref_table() if you want to do it! */
256 lrt = NEW(localref_table);
258 lrt = GCNEW(localref_table);
264 lrt->capacity = LOCALREFTABLE_CAPACITY;
266 lrt->localframes = 1;
267 lrt->prev = LOCALREFTABLE;
269 /* clear the references array (memset is faster then a for-loop) */
271 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
279 /* jni_init_localref_table *****************************************************
281 Frees the local references table of the current thread.
283 *******************************************************************************/
285 bool jni_free_localref_table(void)
289 #if defined(ENABLE_GC_CACAO)
293 assert(lrt->prev == NULL);
295 FREE(lrt, localref_table);
297 LOCALREFTABLE = NULL;
304 /* _Jv_jni_CallObjectMethod ****************************************************
306 Internal function to call Java Object methods.
308 *******************************************************************************/
310 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
312 methodinfo *m, va_list ap)
315 java_objectheader *ro;
317 STATISTICS(jniinvokation());
320 exceptions_throw_nullpointerexception();
324 /* Class initialization is done by the JIT compiler. This is ok
325 since a static method always belongs to the declaring class. */
327 if (m->flags & ACC_STATIC) {
328 /* For static methods we reset the object. */
333 /* for convenience */
338 /* For instance methods we make a virtual function table lookup. */
340 resm = method_vftbl_lookup(vftbl, m);
343 STATISTICS(jnicallXmethodnvokation());
345 ro = vm_call_method_valist(resm, o, ap);
351 /* _Jv_jni_CallObjectMethodA ***************************************************
353 Internal function to call Java Object methods.
355 *******************************************************************************/
357 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
363 java_objectheader *ro;
365 STATISTICS(jniinvokation());
368 exceptions_throw_nullpointerexception();
372 /* Class initialization is done by the JIT compiler. This is ok
373 since a static method always belongs to the declaring class. */
375 if (m->flags & ACC_STATIC) {
376 /* For static methods we reset the object. */
381 /* for convenience */
386 /* For instance methods we make a virtual function table lookup. */
388 resm = method_vftbl_lookup(vftbl, m);
391 STATISTICS(jnicallXmethodnvokation());
393 ro = vm_call_method_jvalue(resm, o, args);
399 /* _Jv_jni_CallIntMethod *******************************************************
401 Internal function to call Java integer class methods (boolean,
402 byte, char, short, int).
404 *******************************************************************************/
406 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
407 methodinfo *m, va_list ap)
412 STATISTICS(jniinvokation());
415 exceptions_throw_nullpointerexception();
419 /* Class initialization is done by the JIT compiler. This is ok
420 since a static method always belongs to the declaring class. */
422 if (m->flags & ACC_STATIC) {
423 /* For static methods we reset the object. */
428 /* for convenience */
433 /* For instance methods we make a virtual function table lookup. */
435 resm = method_vftbl_lookup(vftbl, m);
438 STATISTICS(jnicallXmethodnvokation());
440 i = vm_call_method_int_valist(resm, o, ap);
446 /* _Jv_jni_CallIntMethodA ******************************************************
448 Internal function to call Java integer class methods (boolean,
449 byte, char, short, int).
451 *******************************************************************************/
453 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
454 methodinfo *m, const jvalue *args)
459 STATISTICS(jniinvokation());
462 exceptions_throw_nullpointerexception();
466 /* Class initialization is done by the JIT compiler. This is ok
467 since a static method always belongs to the declaring class. */
469 if (m->flags & ACC_STATIC) {
470 /* For static methods we reset the object. */
475 /* for convenience */
480 /* For instance methods we make a virtual function table lookup. */
482 resm = method_vftbl_lookup(vftbl, m);
485 STATISTICS(jnicallXmethodnvokation());
487 i = vm_call_method_int_jvalue(resm, o, args);
493 /* _Jv_jni_CallLongMethod ******************************************************
495 Internal function to call Java long methods.
497 *******************************************************************************/
499 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
500 methodinfo *m, va_list ap)
505 STATISTICS(jniinvokation());
508 exceptions_throw_nullpointerexception();
512 /* Class initialization is done by the JIT compiler. This is ok
513 since a static method always belongs to the declaring class. */
515 if (m->flags & ACC_STATIC) {
516 /* For static methods we reset the object. */
521 /* for convenience */
526 /* For instance methods we make a virtual function table lookup. */
528 resm = method_vftbl_lookup(vftbl, m);
531 STATISTICS(jnicallXmethodnvokation());
533 l = vm_call_method_long_valist(resm, o, ap);
539 /* _Jv_jni_CallLongMethodA *****************************************************
541 Internal function to call Java long methods.
543 *******************************************************************************/
545 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
546 methodinfo *m, const jvalue *args)
551 STATISTICS(jniinvokation());
554 exceptions_throw_nullpointerexception();
558 /* Class initialization is done by the JIT compiler. This is ok
559 since a static method always belongs to the declaring class. */
561 if (m->flags & ACC_STATIC) {
562 /* For static methods we reset the object. */
567 /* for convenience */
572 /* For instance methods we make a virtual function table lookup. */
574 resm = method_vftbl_lookup(vftbl, m);
577 STATISTICS(jnicallXmethodnvokation());
579 l = vm_call_method_long_jvalue(resm, o, args);
585 /* _Jv_jni_CallFloatMethod *****************************************************
587 Internal function to call Java float methods.
589 *******************************************************************************/
591 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
592 methodinfo *m, va_list ap)
597 /* Class initialization is done by the JIT compiler. This is ok
598 since a static method always belongs to the declaring class. */
600 if (m->flags & ACC_STATIC) {
601 /* For static methods we reset the object. */
606 /* for convenience */
611 /* For instance methods we make a virtual function table lookup. */
613 resm = method_vftbl_lookup(vftbl, m);
616 STATISTICS(jnicallXmethodnvokation());
618 f = vm_call_method_float_valist(resm, o, ap);
624 /* _Jv_jni_CallFloatMethodA ****************************************************
626 Internal function to call Java float methods.
628 *******************************************************************************/
630 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
631 methodinfo *m, const jvalue *args)
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 f = vm_call_method_float_jvalue(resm, o, args);
663 /* _Jv_jni_CallDoubleMethod ****************************************************
665 Internal function to call Java double methods.
667 *******************************************************************************/
669 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
670 methodinfo *m, va_list ap)
675 /* Class initialization is done by the JIT compiler. This is ok
676 since a static method always belongs to the declaring class. */
678 if (m->flags & ACC_STATIC) {
679 /* For static methods we reset the object. */
684 /* for convenience */
689 /* For instance methods we make a virtual function table lookup. */
691 resm = method_vftbl_lookup(vftbl, m);
694 d = vm_call_method_double_valist(resm, o, ap);
700 /* _Jv_jni_CallDoubleMethodA ***************************************************
702 Internal function to call Java double methods.
704 *******************************************************************************/
706 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
707 methodinfo *m, const jvalue *args)
712 /* Class initialization is done by the JIT compiler. This is ok
713 since a static method always belongs to the declaring class. */
715 if (m->flags & ACC_STATIC) {
716 /* For static methods we reset the object. */
721 /* for convenience */
726 /* For instance methods we make a virtual function table lookup. */
728 resm = method_vftbl_lookup(vftbl, m);
731 d = vm_call_method_double_jvalue(resm, o, args);
737 /* _Jv_jni_CallVoidMethod ******************************************************
739 Internal function to call Java void methods.
741 *******************************************************************************/
743 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
744 methodinfo *m, va_list ap)
749 exceptions_throw_nullpointerexception();
753 /* Class initialization is done by the JIT compiler. This is ok
754 since a static method always belongs to the declaring class. */
756 if (m->flags & ACC_STATIC) {
757 /* For static methods we reset the object. */
762 /* for convenience */
767 /* For instance methods we make a virtual function table lookup. */
769 resm = method_vftbl_lookup(vftbl, m);
772 STATISTICS(jnicallXmethodnvokation());
774 (void) vm_call_method_valist(resm, o, ap);
778 /* _Jv_jni_CallVoidMethodA *****************************************************
780 Internal function to call Java void methods.
782 *******************************************************************************/
784 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
785 methodinfo *m, const jvalue *args)
790 exceptions_throw_nullpointerexception();
794 /* Class initialization is done by the JIT compiler. This is ok
795 since a static method always belongs to the declaring class. */
797 if (m->flags & ACC_STATIC) {
798 /* For static methods we reset the object. */
803 /* for convenience */
808 /* For instance methods we make a virtual function table lookup. */
810 resm = method_vftbl_lookup(vftbl, m);
813 STATISTICS(jnicallXmethodnvokation());
815 (void) vm_call_method_jvalue(resm, o, args);
819 /* _Jv_jni_invokeNative ********************************************************
821 Invoke a method on the given object with the given arguments.
823 For instance methods OBJ must be != NULL and the method is looked up
824 in the vftbl of the object.
826 For static methods, OBJ is ignored.
828 *******************************************************************************/
830 #if !defined(__MIPS__) && !defined(__X86_64__) && !defined(__POWERPC64__) && !defined(__SPARC_64__) && !defined(__M68K__) && !defined(__ARM__) && !defined(__ALPHA__) && !defined(__I386__)
831 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
832 java_objectarray *params)
836 java_objectheader *ro;
839 java_objectheader *xptr;
842 exceptions_throw_nullpointerexception();
846 argcount = m->parseddesc->paramcount;
847 paramcount = argcount;
849 /* if method is non-static, remove the `this' pointer */
851 if (!(m->flags & ACC_STATIC))
854 /* For instance methods the object has to be an instance of the
855 class the method belongs to. For static methods the obj
856 parameter is ignored. */
858 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
859 exceptions_throw_illegalargumentexception();
863 /* check if we got the right number of arguments */
865 if (((params == NULL) && (paramcount != 0)) ||
866 (params && (params->header.size != paramcount)))
868 exceptions_throw_illegalargumentexception();
872 /* for instance methods we need an object */
874 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
875 /* XXX not sure if that is the correct exception */
876 exceptions_throw_nullpointerexception();
880 /* for static methods, zero object to make subsequent code simpler */
881 if (m->flags & ACC_STATIC)
885 /* for instance methods we must do a vftbl lookup */
886 resm = method_vftbl_lookup(o->vftbl, m);
889 /* for static methods, just for convenience */
893 vmargs = MNEW(vm_arg, argcount);
895 if (!vm_vmargs_from_objectarray(resm, o, vmargs, params)) {
896 MFREE(vmargs, vm_arg, argcount);
900 switch (resm->parseddesc->returntype.decltype) {
902 (void) vm_call_method_vmarg(resm, argcount, vmargs);
907 case PRIMITIVETYPE_BOOLEAN: {
909 java_lang_Boolean *bo;
911 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
913 ro = builtin_new(class_java_lang_Boolean);
915 /* setting the value of the object direct */
917 bo = (java_lang_Boolean *) ro;
922 case PRIMITIVETYPE_BYTE: {
926 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
928 ro = builtin_new(class_java_lang_Byte);
930 /* setting the value of the object direct */
932 bo = (java_lang_Byte *) ro;
937 case PRIMITIVETYPE_CHAR: {
939 java_lang_Character *co;
941 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
943 ro = builtin_new(class_java_lang_Character);
945 /* setting the value of the object direct */
947 co = (java_lang_Character *) ro;
952 case PRIMITIVETYPE_SHORT: {
956 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
958 ro = builtin_new(class_java_lang_Short);
960 /* setting the value of the object direct */
962 so = (java_lang_Short *) ro;
967 case PRIMITIVETYPE_INT: {
969 java_lang_Integer *io;
971 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
973 ro = builtin_new(class_java_lang_Integer);
975 /* setting the value of the object direct */
977 io = (java_lang_Integer *) ro;
982 case PRIMITIVETYPE_LONG: {
986 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
988 ro = builtin_new(class_java_lang_Long);
990 /* setting the value of the object direct */
992 lo = (java_lang_Long *) ro;
997 case PRIMITIVETYPE_FLOAT: {
1001 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1003 ro = builtin_new(class_java_lang_Float);
1005 /* setting the value of the object direct */
1007 fo = (java_lang_Float *) ro;
1012 case PRIMITIVETYPE_DOUBLE: {
1014 java_lang_Double *_do;
1016 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1018 ro = builtin_new(class_java_lang_Double);
1020 /* setting the value of the object direct */
1022 _do = (java_lang_Double *) ro;
1028 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1032 /* if this happens the exception has already been set by
1033 fill_callblock_from_objectarray */
1035 MFREE(vmargs, vm_arg, argcount);
1040 MFREE(vmargs, vm_arg, argcount);
1042 xptr = exceptions_get_exception();
1045 /* clear exception pointer, we are calling JIT code again */
1047 exceptions_clear_exception();
1049 exceptions_throw_invocationtargetexception(xptr);
1055 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
1056 java_objectarray *params)
1059 java_objectheader *ro;
1062 java_objectheader *xptr;
1067 exceptions_throw_nullpointerexception();
1071 argcount = m->parseddesc->paramcount;
1072 paramcount = argcount;
1074 /* if method is non-static, remove the `this' pointer */
1076 if (!(m->flags & ACC_STATIC))
1079 /* For instance methods the object has to be an instance of the
1080 class the method belongs to. For static methods the obj
1081 parameter is ignored. */
1083 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
1084 exceptions_throw_illegalargumentexception();
1088 /* check if we got the right number of arguments */
1090 if (((params == NULL) && (paramcount != 0)) ||
1091 (params && (params->header.size != paramcount)))
1093 exceptions_throw_illegalargumentexception();
1097 /* for instance methods we need an object */
1099 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
1100 /* XXX not sure if that is the correct exception */
1101 exceptions_throw_nullpointerexception();
1105 /* for static methods, zero object to make subsequent code simpler */
1106 if (m->flags & ACC_STATIC)
1110 /* for instance methods we must do a vftbl lookup */
1111 resm = method_vftbl_lookup(o->vftbl, m);
1114 /* for static methods, just for convenience */
1118 /* mark start of dump memory area */
1120 dumpsize = dump_size();
1122 /* Fill the argument array from a object-array. */
1124 array = vm_array_from_objectarray(resm, o, params);
1126 /* The array can be NULL if we don't have any arguments to pass
1127 and the architecture does not have any argument registers
1128 (e.g. i386). In that case we additionally check for an
1129 exception thrown. */
1131 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
1132 /* release dump area */
1134 dump_release(dumpsize);
1139 switch (resm->parseddesc->returntype.decltype) {
1141 (void) vm_call_array(resm, array);
1146 case PRIMITIVETYPE_BOOLEAN: {
1148 java_lang_Boolean *bo;
1150 i = vm_call_int_array(resm, array);
1152 ro = builtin_new(class_java_lang_Boolean);
1154 /* setting the value of the object direct */
1156 bo = (java_lang_Boolean *) ro;
1161 case PRIMITIVETYPE_BYTE: {
1165 i = vm_call_int_array(resm, array);
1167 ro = builtin_new(class_java_lang_Byte);
1169 /* setting the value of the object direct */
1171 bo = (java_lang_Byte *) ro;
1176 case PRIMITIVETYPE_CHAR: {
1178 java_lang_Character *co;
1180 i = vm_call_int_array(resm, array);
1182 ro = builtin_new(class_java_lang_Character);
1184 /* setting the value of the object direct */
1186 co = (java_lang_Character *) ro;
1191 case PRIMITIVETYPE_SHORT: {
1193 java_lang_Short *so;
1195 i = vm_call_int_array(resm, array);
1197 ro = builtin_new(class_java_lang_Short);
1199 /* setting the value of the object direct */
1201 so = (java_lang_Short *) ro;
1206 case PRIMITIVETYPE_INT: {
1208 java_lang_Integer *io;
1210 i = vm_call_int_array(resm, array);
1212 ro = builtin_new(class_java_lang_Integer);
1214 /* setting the value of the object direct */
1216 io = (java_lang_Integer *) ro;
1221 case PRIMITIVETYPE_LONG: {
1225 l = vm_call_long_array(resm, array);
1227 ro = builtin_new(class_java_lang_Long);
1229 /* setting the value of the object direct */
1231 lo = (java_lang_Long *) ro;
1236 case PRIMITIVETYPE_FLOAT: {
1238 java_lang_Float *fo;
1240 f = vm_call_float_array(resm, array);
1242 ro = builtin_new(class_java_lang_Float);
1244 /* setting the value of the object direct */
1246 fo = (java_lang_Float *) ro;
1251 case PRIMITIVETYPE_DOUBLE: {
1253 java_lang_Double *_do;
1255 d = vm_call_double_array(resm, array);
1257 ro = builtin_new(class_java_lang_Double);
1259 /* setting the value of the object direct */
1261 _do = (java_lang_Double *) ro;
1267 ro = vm_call_array(resm, array);
1271 /* if this happens the exception has already been set by
1272 fill_callblock_from_objectarray */
1274 /* release dump area */
1276 dump_release(dumpsize);
1281 xptr = exceptions_get_exception();
1284 /* clear exception pointer, we are calling JIT code again */
1286 exceptions_clear_exception();
1288 exceptions_throw_invocationtargetexception(xptr);
1291 /* release dump area */
1293 dump_release(dumpsize);
1300 /* GetVersion ******************************************************************
1302 Returns the major version number in the higher 16 bits and the
1303 minor version number in the lower 16 bits.
1305 *******************************************************************************/
1307 jint _Jv_JNI_GetVersion(JNIEnv *env)
1309 STATISTICS(jniinvokation());
1311 /* we support JNI 1.4 */
1313 return JNI_VERSION_1_4;
1317 /* Class Operations ***********************************************************/
1319 /* DefineClass *****************************************************************
1321 Loads a class from a buffer of raw class data. The buffer
1322 containing the raw class data is not referenced by the VM after the
1323 DefineClass call returns, and it may be discarded if desired.
1325 *******************************************************************************/
1327 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1328 const jbyte *buf, jsize bufLen)
1330 #if defined(ENABLE_JAVASE)
1332 java_objectheader *cl;
1335 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
1337 u = utf_new_char(name);
1338 cl = (java_objectheader *) loader;
1340 c = class_define(u, cl, bufLen, (const uint8_t *) buf);
1342 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1344 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1346 /* keep compiler happy */
1353 /* FindClass *******************************************************************
1355 This function loads a locally-defined class. It searches the
1356 directories and zip files specified by the CLASSPATH environment
1357 variable for the class with the specified name.
1359 *******************************************************************************/
1361 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1363 #if defined(ENABLE_JAVASE)
1368 STATISTICS(jniinvokation());
1370 u = utf_new_char_classname((char *) name);
1372 /* Check stacktrace for classloader, if one found use it,
1373 otherwise use the system classloader. */
1375 /* Quote from the JNI documentation:
1377 In the Java 2 Platform, FindClass locates the class loader
1378 associated with the current native method. If the native code
1379 belongs to a system class, no class loader will be
1380 involved. Otherwise, the proper class loader will be invoked to
1381 load and link the named class. When FindClass is called through
1382 the Invocation Interface, there is no current native method or
1383 its associated class loader. In that case, the result of
1384 ClassLoader.getBaseClassLoader is used." */
1386 cc = stacktrace_getCurrentClass();
1389 c = load_class_from_sysloader(u);
1391 c = load_class_from_classloader(u, cc->classloader);
1399 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1401 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1403 /* keep compiler happy */
1410 /* GetSuperclass ***************************************************************
1412 If clazz represents any class other than the class Object, then
1413 this function returns the object that represents the superclass of
1414 the class specified by clazz.
1416 *******************************************************************************/
1418 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1423 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1425 c = (classinfo *) sub;
1430 super = class_get_superclass(c);
1432 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1436 /* IsAssignableFrom ************************************************************
1438 Determines whether an object of sub can be safely cast to sup.
1440 *******************************************************************************/
1442 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1444 java_lang_Class *csup;
1445 java_lang_Class *csub;
1447 csup = (java_lang_Class *) sup;
1448 csub = (java_lang_Class *) sub;
1450 STATISTICS(jniinvokation());
1452 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1456 /* Throw ***********************************************************************
1458 Causes a java.lang.Throwable object to be thrown.
1460 *******************************************************************************/
1462 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1464 java_objectheader *o;
1466 STATISTICS(jniinvokation());
1468 o = (java_objectheader *) obj;
1470 exceptions_set_exception(o);
1476 /* ThrowNew ********************************************************************
1478 Constructs an exception object from the specified class with the
1479 message specified by message and causes that exception to be
1482 *******************************************************************************/
1484 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1487 java_objectheader *o;
1488 java_objectheader *s;
1490 STATISTICS(jniinvokation());
1492 c = (classinfo *) clazz;
1495 s = javastring_new_from_utf_string(msg);
1497 /* instantiate exception object */
1499 o = native_new_and_init_string(c, s);
1504 exceptions_set_exception(o);
1510 /* ExceptionOccurred ***********************************************************
1512 Determines if an exception is being thrown. The exception stays
1513 being thrown until either the native code calls ExceptionClear(),
1514 or the Java code handles the exception.
1516 *******************************************************************************/
1518 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1520 java_objectheader *o;
1522 STATISTICS(jniinvokation());
1524 o = exceptions_get_exception();
1526 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1530 /* ExceptionDescribe ***********************************************************
1532 Prints an exception and a backtrace of the stack to a system
1533 error-reporting channel, such as stderr. This is a convenience
1534 routine provided for debugging.
1536 *******************************************************************************/
1538 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1540 java_objectheader *o;
1543 STATISTICS(jniinvokation());
1545 o = exceptions_get_exception();
1548 /* clear exception, because we are calling jit code again */
1550 exceptions_clear_exception();
1552 /* get printStackTrace method from exception class */
1554 m = class_resolveclassmethod(o->vftbl->class,
1555 utf_printStackTrace,
1561 /* XXX what should we do? */
1564 /* print the stacktrace */
1566 (void) vm_call_method(m, o);
1571 /* ExceptionClear **************************************************************
1573 Clears any exception that is currently being thrown. If no
1574 exception is currently being thrown, this routine has no effect.
1576 *******************************************************************************/
1578 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1580 STATISTICS(jniinvokation());
1582 exceptions_clear_exception();
1586 /* FatalError ******************************************************************
1588 Raises a fatal error and does not expect the VM to recover. This
1589 function does not return.
1591 *******************************************************************************/
1593 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1595 STATISTICS(jniinvokation());
1597 /* this seems to be the best way */
1599 vm_abort("JNI Fatal error: %s", msg);
1603 /* PushLocalFrame **************************************************************
1605 Creates a new local reference frame, in which at least a given
1606 number of local references can be created.
1608 *******************************************************************************/
1610 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1613 localref_table *lrt;
1614 localref_table *nlrt;
1616 STATISTICS(jniinvokation());
1621 /* Allocate new local reference table on Java heap. Calculate the
1622 additional memory we have to allocate. */
1624 if (capacity > LOCALREFTABLE_CAPACITY)
1625 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1629 #if defined(ENABLE_GC_CACAO)
1630 nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1632 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1638 /* get current local reference table from thread */
1640 lrt = LOCALREFTABLE;
1642 /* Set up the new local reference table and add it to the local
1645 nlrt->capacity = capacity;
1647 nlrt->localframes = lrt->localframes + 1;
1650 /* store new local reference table in thread */
1652 LOCALREFTABLE = nlrt;
1658 /* PopLocalFrame ***************************************************************
1660 Pops off the current local reference frame, frees all the local
1661 references, and returns a local reference in the previous local
1662 reference frame for the given result object.
1664 *******************************************************************************/
1666 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1668 localref_table *lrt;
1669 localref_table *plrt;
1673 STATISTICS(jniinvokation());
1675 /* get current local reference table from thread */
1677 lrt = LOCALREFTABLE;
1679 localframes = lrt->localframes;
1681 /* Don't delete the top local frame, as this one is allocated in
1682 the native stub on the stack and is freed automagically on
1685 if (localframes == 1)
1686 return _Jv_JNI_NewLocalRef(env, result);
1688 /* release all current local frames */
1690 for (; localframes >= 1; localframes--) {
1691 /* get previous frame */
1695 /* clear all reference entries */
1697 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1701 #if defined(ENABLE_GC_CACAO)
1702 /* for the exact GC local reference tables are not on the heap,
1703 so we need to free them explicitly here. */
1705 if (lrt->capacity > LOCALREFTABLE_CAPACITY)
1706 additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
1710 MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1713 /* set new local references table */
1718 /* store new local reference table in thread */
1720 LOCALREFTABLE = lrt;
1722 /* add local reference and return the value */
1724 return _Jv_JNI_NewLocalRef(env, result);
1728 /* DeleteLocalRef **************************************************************
1730 Deletes the local reference pointed to by localRef.
1732 *******************************************************************************/
1734 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1736 java_objectheader *o;
1737 localref_table *lrt;
1740 STATISTICS(jniinvokation());
1742 o = (java_objectheader *) localRef;
1744 /* get local reference table (thread specific) */
1746 lrt = LOCALREFTABLE;
1748 /* go through all local frames */
1750 for (; lrt != NULL; lrt = lrt->prev) {
1752 /* and try to remove the reference */
1754 for (i = 0; i < lrt->capacity; i++) {
1755 if (lrt->refs[i] == o) {
1756 lrt->refs[i] = NULL;
1764 /* this should not happen */
1766 /* if (opt_checkjni) */
1767 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1768 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1772 /* IsSameObject ****************************************************************
1774 Tests whether two references refer to the same Java object.
1776 *******************************************************************************/
1778 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1780 STATISTICS(jniinvokation());
1789 /* NewLocalRef *****************************************************************
1791 Creates a new local reference that refers to the same object as ref.
1793 *******************************************************************************/
1795 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1797 localref_table *lrt;
1800 STATISTICS(jniinvokation());
1805 /* get local reference table (thread specific) */
1807 lrt = LOCALREFTABLE;
1809 /* Check if we have space for the requested reference? No,
1810 allocate a new frame. This is actually not what the spec says,
1811 but for compatibility reasons... */
1813 if (lrt->used == lrt->capacity) {
1814 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1817 /* get the new local reference table */
1819 lrt = LOCALREFTABLE;
1822 /* insert the reference */
1824 for (i = 0; i < lrt->capacity; i++) {
1825 if (lrt->refs[i] == NULL) {
1826 lrt->refs[i] = (java_objectheader *) ref;
1833 /* should not happen, just to be sure */
1837 /* keep compiler happy */
1843 /* EnsureLocalCapacity *********************************************************
1845 Ensures that at least a given number of local references can be
1846 created in the current thread
1848 *******************************************************************************/
1850 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1852 localref_table *lrt;
1854 STATISTICS(jniinvokation());
1856 /* get local reference table (thread specific) */
1858 lrt = LOCALREFTABLE;
1860 /* check if capacity elements are available in the local references table */
1862 if ((lrt->used + capacity) > lrt->capacity)
1863 return _Jv_JNI_PushLocalFrame(env, capacity);
1869 /* AllocObject *****************************************************************
1871 Allocates a new Java object without invoking any of the
1872 constructors for the object. Returns a reference to the object.
1874 *******************************************************************************/
1876 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1879 java_objectheader *o;
1881 STATISTICS(jniinvokation());
1883 c = (classinfo *) clazz;
1885 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1886 exceptions_throw_instantiationexception(c);
1892 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1896 /* NewObject *******************************************************************
1898 Programmers place all arguments that are to be passed to the
1899 constructor immediately following the methodID
1900 argument. NewObject() accepts these arguments and passes them to
1901 the Java method that the programmer wishes to invoke.
1903 *******************************************************************************/
1905 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1907 java_objectheader *o;
1912 STATISTICS(jniinvokation());
1914 c = (classinfo *) clazz;
1915 m = (methodinfo *) methodID;
1924 /* call constructor */
1926 va_start(ap, methodID);
1927 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1930 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1934 /* NewObjectV ******************************************************************
1936 Programmers place all arguments that are to be passed to the
1937 constructor in an args argument of type va_list that immediately
1938 follows the methodID argument. NewObjectV() accepts these
1939 arguments, and, in turn, passes them to the Java method that the
1940 programmer wishes to invoke.
1942 *******************************************************************************/
1944 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1947 java_objectheader *o;
1951 STATISTICS(jniinvokation());
1953 c = (classinfo *) clazz;
1954 m = (methodinfo *) methodID;
1963 /* call constructor */
1965 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1967 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1971 /* NewObjectA *****************************************************************
1973 Programmers place all arguments that are to be passed to the
1974 constructor in an args array of jvalues that immediately follows
1975 the methodID argument. NewObjectA() accepts the arguments in this
1976 array, and, in turn, passes them to the Java method that the
1977 programmer wishes to invoke.
1979 *******************************************************************************/
1981 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1984 java_objectheader *o;
1988 STATISTICS(jniinvokation());
1990 c = (classinfo *) clazz;
1991 m = (methodinfo *) methodID;
2000 /* call constructor */
2002 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2004 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2008 /* GetObjectClass **************************************************************
2010 Returns the class of an object.
2012 *******************************************************************************/
2014 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
2016 java_objectheader *o;
2019 STATISTICS(jniinvokation());
2021 o = (java_objectheader *) obj;
2023 if ((o == NULL) || (o->vftbl == NULL))
2026 c = o->vftbl->class;
2028 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
2032 /* IsInstanceOf ****************************************************************
2034 Tests whether an object is an instance of a class.
2036 *******************************************************************************/
2038 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
2041 java_lang_Object *o;
2043 STATISTICS(jniinvokation());
2045 c = (java_lang_Class *) clazz;
2046 o = (java_lang_Object *) obj;
2048 return _Jv_java_lang_Class_isInstance(c, o);
2052 /* Reflection Support *********************************************************/
2054 /* FromReflectedMethod *********************************************************
2056 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
2057 object to a method ID.
2059 *******************************************************************************/
2061 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
2063 #if defined(ENABLE_JAVASE)
2064 java_objectheader *o;
2069 STATISTICS(jniinvokation());
2071 o = (java_objectheader *) method;
2076 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
2077 java_lang_reflect_Method *rm;
2079 rm = (java_lang_reflect_Method *) method;
2080 c = (classinfo *) (rm->clazz);
2083 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
2084 java_lang_reflect_Constructor *rc;
2086 rc = (java_lang_reflect_Constructor *) method;
2087 c = (classinfo *) (rc->clazz);
2093 m = &(c->methods[slot]);
2095 return (jmethodID) m;
2097 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
2099 /* keep compiler happy */
2106 /* FromReflectedField **********************************************************
2108 Converts a java.lang.reflect.Field to a field ID.
2110 *******************************************************************************/
2112 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
2114 #if defined(ENABLE_JAVASE)
2115 java_lang_reflect_Field *rf;
2119 STATISTICS(jniinvokation());
2121 rf = (java_lang_reflect_Field *) field;
2126 c = (classinfo *) rf->clazz;
2127 f = &(c->fields[rf->slot]);
2129 return (jfieldID) f;
2131 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
2133 /* keep compiler happy */
2140 /* ToReflectedMethod ***********************************************************
2142 Converts a method ID derived from cls to an instance of the
2143 java.lang.reflect.Method class or to an instance of the
2144 java.lang.reflect.Constructor class.
2146 *******************************************************************************/
2148 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2151 #if defined(ENABLE_JAVASE)
2153 java_lang_reflect_Constructor *rc;
2154 java_lang_reflect_Method *rm;
2156 STATISTICS(jniinvokation());
2158 m = (methodinfo *) methodID;
2160 /* HotSpot does the same assert. */
2162 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
2164 if (m->name == utf_init) {
2165 rc = reflect_constructor_new(m);
2167 return (jobject) rc;
2170 rm = reflect_method_new(m);
2172 return (jobject) rm;
2175 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
2177 /* keep compiler happy */
2184 /* ToReflectedField ************************************************************
2186 Converts a field ID derived from cls to an instance of the
2187 java.lang.reflect.Field class.
2189 *******************************************************************************/
2191 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2194 STATISTICS(jniinvokation());
2196 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2202 /* Calling Instance Methods ***************************************************/
2204 /* GetMethodID *****************************************************************
2206 Returns the method ID for an instance (nonstatic) method of a class
2207 or interface. The method may be defined in one of the clazz's
2208 superclasses and inherited by clazz. The method is determined by
2209 its name and signature.
2211 GetMethodID() causes an uninitialized class to be initialized.
2213 *******************************************************************************/
2215 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2223 STATISTICS(jniinvokation());
2225 c = (classinfo *) clazz;
2230 if (!(c->state & CLASS_INITIALIZED))
2231 if (!initialize_class(c))
2234 /* try to get the method of the class or one of it's superclasses */
2236 uname = utf_new_char((char *) name);
2237 udesc = utf_new_char((char *) sig);
2239 m = class_resolvemethod(c, uname, udesc);
2241 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2242 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2247 return (jmethodID) m;
2251 /* JNI-functions for calling instance methods *********************************/
2253 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2256 java_objectheader *o;
2258 java_objectheader *ret;
2261 o = (java_objectheader *) obj;
2262 m = (methodinfo *) methodID;
2264 va_start(ap, methodID);
2265 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2268 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2272 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2275 java_objectheader *o;
2277 java_objectheader *ret;
2279 o = (java_objectheader *) obj;
2280 m = (methodinfo *) methodID;
2282 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2284 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2288 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2291 java_objectheader *o;
2293 java_objectheader *ret;
2295 o = (java_objectheader *) obj;
2296 m = (methodinfo *) methodID;
2298 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2300 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2304 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2307 java_objectheader *o;
2312 o = (java_objectheader *) obj;
2313 m = (methodinfo *) methodID;
2315 va_start(ap, methodID);
2316 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2323 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2324 jmethodID methodID, va_list args)
2326 java_objectheader *o;
2330 o = (java_objectheader *) obj;
2331 m = (methodinfo *) methodID;
2333 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2339 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2340 jmethodID methodID, const jvalue *args)
2342 java_objectheader *o;
2346 o = (java_objectheader *) obj;
2347 m = (methodinfo *) methodID;
2349 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2355 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2357 java_objectheader *o;
2362 o = (java_objectheader *) obj;
2363 m = (methodinfo *) methodID;
2365 va_start(ap, methodID);
2366 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2374 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2377 java_objectheader *o;
2381 o = (java_objectheader *) obj;
2382 m = (methodinfo *) methodID;
2384 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2390 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2393 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2399 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2401 java_objectheader *o;
2406 o = (java_objectheader *) obj;
2407 m = (methodinfo *) methodID;
2409 va_start(ap, methodID);
2410 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2417 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2420 java_objectheader *o;
2424 o = (java_objectheader *) obj;
2425 m = (methodinfo *) methodID;
2427 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2433 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2436 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2442 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2445 java_objectheader *o;
2450 o = (java_objectheader *) obj;
2451 m = (methodinfo *) methodID;
2453 va_start(ap, methodID);
2454 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2461 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2464 java_objectheader *o;
2468 o = (java_objectheader *) obj;
2469 m = (methodinfo *) methodID;
2471 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2477 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2480 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2487 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2489 java_objectheader *o;
2494 o = (java_objectheader *) obj;
2495 m = (methodinfo *) methodID;
2497 va_start(ap, methodID);
2498 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2505 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2508 java_objectheader *o;
2512 o = (java_objectheader *) obj;
2513 m = (methodinfo *) methodID;
2515 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2521 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2524 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2531 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2533 java_objectheader *o;
2538 o = (java_objectheader *) obj;
2539 m = (methodinfo *) methodID;
2541 va_start(ap, methodID);
2542 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2549 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2552 java_objectheader *o;
2556 o = (java_objectheader *) obj;
2557 m = (methodinfo *) methodID;
2559 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2565 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2568 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2575 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2578 java_objectheader *o;
2583 o = (java_objectheader *) obj;
2584 m = (methodinfo *) methodID;
2586 va_start(ap, methodID);
2587 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2594 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2597 java_objectheader *o;
2601 o = (java_objectheader *) obj;
2602 m = (methodinfo *) methodID;
2604 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2610 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2613 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2620 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2623 java_objectheader *o;
2628 o = (java_objectheader *) obj;
2629 m = (methodinfo *) methodID;
2631 va_start(ap, methodID);
2632 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2639 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2642 java_objectheader *o;
2646 o = (java_objectheader *) obj;
2647 m = (methodinfo *) methodID;
2649 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2655 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2658 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2665 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2667 java_objectheader *o;
2671 o = (java_objectheader *) obj;
2672 m = (methodinfo *) methodID;
2674 va_start(ap, methodID);
2675 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2680 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2683 java_objectheader *o;
2686 o = (java_objectheader *) obj;
2687 m = (methodinfo *) methodID;
2689 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2693 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2696 java_objectheader *o;
2699 o = (java_objectheader *) obj;
2700 m = (methodinfo *) methodID;
2702 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2707 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2708 jclass clazz, jmethodID methodID,
2711 java_objectheader *o;
2714 java_objectheader *r;
2717 o = (java_objectheader *) obj;
2718 c = (classinfo *) clazz;
2719 m = (methodinfo *) methodID;
2721 va_start(ap, methodID);
2722 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2725 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2729 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2730 jclass clazz, jmethodID methodID,
2733 java_objectheader *o;
2736 java_objectheader *r;
2738 o = (java_objectheader *) obj;
2739 c = (classinfo *) clazz;
2740 m = (methodinfo *) methodID;
2742 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2744 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2748 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2749 jclass clazz, jmethodID methodID,
2752 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2754 return _Jv_JNI_NewLocalRef(env, NULL);
2759 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2760 jclass clazz, jmethodID methodID,
2763 java_objectheader *o;
2769 o = (java_objectheader *) obj;
2770 c = (classinfo *) clazz;
2771 m = (methodinfo *) methodID;
2773 va_start(ap, methodID);
2774 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2781 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2782 jclass clazz, jmethodID methodID,
2785 java_objectheader *o;
2790 o = (java_objectheader *) obj;
2791 c = (classinfo *) clazz;
2792 m = (methodinfo *) methodID;
2794 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2800 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2801 jclass clazz, jmethodID methodID,
2804 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2810 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2811 jmethodID methodID, ...)
2813 java_objectheader *o;
2819 o = (java_objectheader *) obj;
2820 c = (classinfo *) clazz;
2821 m = (methodinfo *) methodID;
2823 va_start(ap, methodID);
2824 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2831 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2832 jmethodID methodID, va_list args)
2834 java_objectheader *o;
2839 o = (java_objectheader *) obj;
2840 c = (classinfo *) clazz;
2841 m = (methodinfo *) methodID;
2843 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2849 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2850 jmethodID methodID, const jvalue *args)
2852 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2859 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2860 jmethodID methodID, ...)
2862 java_objectheader *o;
2868 o = (java_objectheader *) obj;
2869 c = (classinfo *) clazz;
2870 m = (methodinfo *) methodID;
2872 va_start(ap, methodID);
2873 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2880 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2881 jmethodID methodID, va_list args)
2883 java_objectheader *o;
2888 o = (java_objectheader *) obj;
2889 c = (classinfo *) clazz;
2890 m = (methodinfo *) methodID;
2892 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2898 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2899 jmethodID methodID, const jvalue *args)
2901 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2908 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2909 jclass clazz, jmethodID methodID, ...)
2911 java_objectheader *o;
2917 o = (java_objectheader *) obj;
2918 c = (classinfo *) clazz;
2919 m = (methodinfo *) methodID;
2921 va_start(ap, methodID);
2922 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2929 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2930 jclass clazz, jmethodID methodID,
2933 java_objectheader *o;
2938 o = (java_objectheader *) obj;
2939 c = (classinfo *) clazz;
2940 m = (methodinfo *) methodID;
2942 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2948 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2949 jclass clazz, jmethodID methodID,
2952 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2959 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2960 jmethodID methodID, ...)
2962 java_objectheader *o;
2968 o = (java_objectheader *) obj;
2969 c = (classinfo *) clazz;
2970 m = (methodinfo *) methodID;
2972 va_start(ap, methodID);
2973 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2980 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2981 jmethodID methodID, va_list args)
2983 java_objectheader *o;
2988 o = (java_objectheader *) obj;
2989 c = (classinfo *) clazz;
2990 m = (methodinfo *) methodID;
2992 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2998 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2999 jmethodID methodID, const jvalue *args)
3001 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
3008 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
3009 jmethodID methodID, ...)
3011 java_objectheader *o;
3017 o = (java_objectheader *) obj;
3018 c = (classinfo *) clazz;
3019 m = (methodinfo *) methodID;
3021 va_start(ap, methodID);
3022 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
3029 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
3030 jmethodID methodID, va_list args)
3032 java_objectheader *o;
3037 o = (java_objectheader *) obj;
3038 c = (classinfo *) clazz;
3039 m = (methodinfo *) methodID;
3041 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
3047 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
3048 jmethodID methodID, const jvalue *args)
3050 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
3057 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
3058 jclass clazz, jmethodID methodID, ...)
3060 java_objectheader *o;
3066 o = (java_objectheader *) obj;
3067 c = (classinfo *) clazz;
3068 m = (methodinfo *) methodID;
3070 va_start(ap, methodID);
3071 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
3078 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
3079 jclass clazz, jmethodID methodID,
3082 java_objectheader *o;
3087 o = (java_objectheader *) obj;
3088 c = (classinfo *) clazz;
3089 m = (methodinfo *) methodID;
3091 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
3097 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
3098 jclass clazz, jmethodID methodID,
3101 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
3108 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
3109 jclass clazz, jmethodID methodID,
3112 java_objectheader *o;
3118 o = (java_objectheader *) obj;
3119 c = (classinfo *) clazz;
3120 m = (methodinfo *) methodID;
3122 va_start(ap, methodID);
3123 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
3130 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
3131 jclass clazz, jmethodID methodID,
3134 java_objectheader *o;
3139 o = (java_objectheader *) obj;
3140 c = (classinfo *) clazz;
3141 m = (methodinfo *) methodID;
3143 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
3149 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
3150 jclass clazz, jmethodID methodID,
3153 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
3160 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
3161 jmethodID methodID, ...)
3163 java_objectheader *o;
3168 o = (java_objectheader *) obj;
3169 c = (classinfo *) clazz;
3170 m = (methodinfo *) methodID;
3172 va_start(ap, methodID);
3173 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3178 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3179 jmethodID methodID, va_list args)
3181 java_objectheader *o;
3185 o = (java_objectheader *) obj;
3186 c = (classinfo *) clazz;
3187 m = (methodinfo *) methodID;
3189 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3193 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3194 jmethodID methodID, const jvalue * args)
3196 java_objectheader *o;
3200 o = (java_objectheader *) obj;
3201 c = (classinfo *) clazz;
3202 m = (methodinfo *) methodID;
3204 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3208 /* Accessing Fields of Objects ************************************************/
3210 /* GetFieldID ******************************************************************
3212 Returns the field ID for an instance (nonstatic) field of a
3213 class. The field is specified by its name and signature. The
3214 Get<type>Field and Set<type>Field families of accessor functions
3215 use field IDs to retrieve object fields.
3217 *******************************************************************************/
3219 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3227 STATISTICS(jniinvokation());
3229 c = (classinfo *) clazz;
3231 /* XXX NPE check? */
3233 uname = utf_new_char((char *) name);
3234 udesc = utf_new_char((char *) sig);
3236 f = class_findfield(c, uname, udesc);
3239 exceptions_throw_nosuchfielderror(c, uname);
3241 return (jfieldID) f;
3245 /* Get<type>Field Routines *****************************************************
3247 This family of accessor routines returns the value of an instance
3248 (nonstatic) field of an object. The field to access is specified by
3249 a field ID obtained by calling GetFieldID().
3251 *******************************************************************************/
3253 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3255 java_objectheader *o;
3257 STATISTICS(jniinvokation());
3259 o = GET_FIELD(obj, java_objectheader*, fieldID);
3261 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3265 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3269 STATISTICS(jniinvokation());
3271 i = GET_FIELD(obj, s4, fieldID);
3273 return (jboolean) i;
3277 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3281 STATISTICS(jniinvokation());
3283 i = GET_FIELD(obj, s4, fieldID);
3289 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3293 STATISTICS(jniinvokation());
3295 i = GET_FIELD(obj, s4, fieldID);
3301 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3305 STATISTICS(jniinvokation());
3307 i = GET_FIELD(obj, s4, fieldID);
3313 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3315 java_objectheader *o;
3319 STATISTICS(jniinvokation());
3321 o = (java_objectheader *) obj;
3322 f = (fieldinfo *) fieldID;
3324 i = GET_FIELD(o, s4, f);
3330 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3334 STATISTICS(jniinvokation());
3336 l = GET_FIELD(obj, s8, fieldID);
3342 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3346 STATISTICS(jniinvokation());
3348 f = GET_FIELD(obj, float, fieldID);
3354 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3358 STATISTICS(jniinvokation());
3360 d = GET_FIELD(obj, double, fieldID);
3366 /* Set<type>Field Routines *****************************************************
3368 This family of accessor routines sets the value of an instance
3369 (nonstatic) field of an object. The field to access is specified by
3370 a field ID obtained by calling GetFieldID().
3372 *******************************************************************************/
3374 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3377 STATISTICS(jniinvokation());
3379 SET_FIELD(obj, java_objectheader*, fieldID, value);
3383 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3386 STATISTICS(jniinvokation());
3388 SET_FIELD(obj, s4, fieldID, value);
3392 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3395 STATISTICS(jniinvokation());
3397 SET_FIELD(obj, s4, fieldID, value);
3401 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3404 STATISTICS(jniinvokation());
3406 SET_FIELD(obj, s4, fieldID, value);
3410 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3413 STATISTICS(jniinvokation());
3415 SET_FIELD(obj, s4, fieldID, value);
3419 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3421 STATISTICS(jniinvokation());
3423 SET_FIELD(obj, s4, fieldID, value);
3427 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3430 STATISTICS(jniinvokation());
3432 SET_FIELD(obj, s8, fieldID, value);
3436 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3439 STATISTICS(jniinvokation());
3441 SET_FIELD(obj, float, fieldID, value);
3445 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3448 STATISTICS(jniinvokation());
3450 SET_FIELD(obj, double, fieldID, value);
3454 /* Calling Static Methods *****************************************************/
3456 /* GetStaticMethodID ***********************************************************
3458 Returns the method ID for a static method of a class. The method is
3459 specified by its name and signature.
3461 GetStaticMethodID() causes an uninitialized class to be
3464 *******************************************************************************/
3466 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3474 STATISTICS(jniinvokation());
3476 c = (classinfo *) clazz;
3481 if (!(c->state & CLASS_INITIALIZED))
3482 if (!initialize_class(c))
3485 /* try to get the static method of the class */
3487 uname = utf_new_char((char *) name);
3488 udesc = utf_new_char((char *) sig);
3490 m = class_resolvemethod(c, uname, udesc);
3492 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3493 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3498 return (jmethodID) m;
3502 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3503 jmethodID methodID, ...)
3506 java_objectheader *o;
3509 m = (methodinfo *) methodID;
3511 va_start(ap, methodID);
3512 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3515 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3519 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3520 jmethodID methodID, va_list args)
3523 java_objectheader *o;
3525 m = (methodinfo *) methodID;
3527 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3529 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3533 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3534 jmethodID methodID, const jvalue *args)
3537 java_objectheader *o;
3539 m = (methodinfo *) methodID;
3541 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3543 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3547 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3548 jmethodID methodID, ...)
3554 m = (methodinfo *) methodID;
3556 va_start(ap, methodID);
3557 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3564 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3565 jmethodID methodID, va_list args)
3570 m = (methodinfo *) methodID;
3572 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3578 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3579 jmethodID methodID, const jvalue *args)
3584 m = (methodinfo *) methodID;
3586 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3592 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3593 jmethodID methodID, ...)
3599 m = (methodinfo *) methodID;
3601 va_start(ap, methodID);
3602 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3609 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3610 jmethodID methodID, va_list args)
3615 m = (methodinfo *) methodID;
3617 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3623 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3624 jmethodID methodID, const jvalue *args)
3629 m = (methodinfo *) methodID;
3631 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3637 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3638 jmethodID methodID, ...)
3644 m = (methodinfo *) methodID;
3646 va_start(ap, methodID);
3647 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3654 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3655 jmethodID methodID, va_list args)
3660 m = (methodinfo *) methodID;
3662 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3668 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3669 jmethodID methodID, const jvalue *args)
3674 m = (methodinfo *) methodID;
3676 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3682 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3683 jmethodID methodID, ...)
3689 m = (methodinfo *) methodID;
3691 va_start(ap, methodID);
3692 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3699 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3700 jmethodID methodID, va_list args)
3705 m = (methodinfo *) methodID;
3707 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3713 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3714 jmethodID methodID, const jvalue *args)
3719 m = (methodinfo *) methodID;
3721 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3727 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3734 m = (methodinfo *) methodID;
3736 va_start(ap, methodID);
3737 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3744 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3745 jmethodID methodID, va_list args)
3750 m = (methodinfo *) methodID;
3752 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3758 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3759 jmethodID methodID, const jvalue *args)
3764 m = (methodinfo *) methodID;
3766 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3772 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3773 jmethodID methodID, ...)
3779 m = (methodinfo *) methodID;
3781 va_start(ap, methodID);
3782 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3789 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3790 jmethodID methodID, va_list args)
3795 m = (methodinfo *) methodID;
3797 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3803 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3804 jmethodID methodID, const jvalue *args)
3809 m = (methodinfo *) methodID;
3811 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3818 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3819 jmethodID methodID, ...)
3825 m = (methodinfo *) methodID;
3827 va_start(ap, methodID);
3828 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3835 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3836 jmethodID methodID, va_list args)
3841 m = (methodinfo *) methodID;
3843 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3849 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3850 jmethodID methodID, const jvalue *args)
3855 m = (methodinfo *) methodID;
3857 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3863 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3864 jmethodID methodID, ...)
3870 m = (methodinfo *) methodID;
3872 va_start(ap, methodID);
3873 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3880 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3881 jmethodID methodID, va_list args)
3886 m = (methodinfo *) methodID;
3888 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3894 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3895 jmethodID methodID, const jvalue *args)
3900 m = (methodinfo *) methodID;
3902 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3908 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3909 jmethodID methodID, ...)
3914 m = (methodinfo *) methodID;
3916 va_start(ap, methodID);
3917 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3922 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3923 jmethodID methodID, va_list args)
3927 m = (methodinfo *) methodID;
3929 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3933 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3934 jmethodID methodID, const jvalue * args)
3938 m = (methodinfo *) methodID;
3940 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3944 /* Accessing Static Fields ****************************************************/
3946 /* GetStaticFieldID ************************************************************
3948 Returns the field ID for a static field of a class. The field is
3949 specified by its name and signature. The GetStatic<type>Field and
3950 SetStatic<type>Field families of accessor functions use field IDs
3951 to retrieve static fields.
3953 *******************************************************************************/
3955 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3963 STATISTICS(jniinvokation());
3965 c = (classinfo *) clazz;
3967 uname = utf_new_char((char *) name);
3968 usig = utf_new_char((char *) sig);
3970 f = class_findfield(c, uname, usig);
3973 exceptions_throw_nosuchfielderror(c, uname);
3975 return (jfieldID) f;
3979 /* GetStatic<type>Field ********************************************************
3981 This family of accessor routines returns the value of a static
3984 *******************************************************************************/
3986 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3992 STATISTICS(jniinvokation());
3994 c = (classinfo *) clazz;
3995 f = (fieldinfo *) fieldID;
3997 if (!(c->state & CLASS_INITIALIZED))
3998 if (!initialize_class(c))
4001 return _Jv_JNI_NewLocalRef(env, f->value.a);
4005 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
4011 STATISTICS(jniinvokation());
4013 c = (classinfo *) clazz;
4014 f = (fieldinfo *) fieldID;
4016 if (!(c->state & CLASS_INITIALIZED))
4017 if (!initialize_class(c))
4024 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4029 STATISTICS(jniinvokation());
4031 c = (classinfo *) clazz;
4032 f = (fieldinfo *) fieldID;
4034 if (!(c->state & CLASS_INITIALIZED))
4035 if (!initialize_class(c))
4042 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4047 STATISTICS(jniinvokation());
4049 c = (classinfo *) clazz;
4050 f = (fieldinfo *) fieldID;
4052 if (!(c->state & CLASS_INITIALIZED))
4053 if (!initialize_class(c))
4060 jshort _Jv_JNI_GetStaticShortField(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 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4083 STATISTICS(jniinvokation());
4085 c = (classinfo *) clazz;
4086 f = (fieldinfo *) fieldID;
4088 if (!(c->state & CLASS_INITIALIZED))
4089 if (!initialize_class(c))
4096 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4101 STATISTICS(jniinvokation());
4103 c = (classinfo *) clazz;
4104 f = (fieldinfo *) fieldID;
4106 if (!(c->state & CLASS_INITIALIZED))
4107 if (!initialize_class(c))
4114 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
4119 STATISTICS(jniinvokation());
4121 c = (classinfo *) clazz;
4122 f = (fieldinfo *) fieldID;
4124 if (!(c->state & CLASS_INITIALIZED))
4125 if (!initialize_class(c))
4132 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
4138 STATISTICS(jniinvokation());
4140 c = (classinfo *) clazz;
4141 f = (fieldinfo *) fieldID;
4143 if (!(c->state & CLASS_INITIALIZED))
4144 if (!initialize_class(c))
4151 /* SetStatic<type>Field *******************************************************
4153 This family of accessor routines sets the value of a static field
4156 *******************************************************************************/
4158 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4164 STATISTICS(jniinvokation());
4166 c = (classinfo *) clazz;
4167 f = (fieldinfo *) fieldID;
4169 if (!(c->state & CLASS_INITIALIZED))
4170 if (!initialize_class(c))
4177 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4183 STATISTICS(jniinvokation());
4185 c = (classinfo *) clazz;
4186 f = (fieldinfo *) fieldID;
4188 if (!(c->state & CLASS_INITIALIZED))
4189 if (!initialize_class(c))
4196 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4202 STATISTICS(jniinvokation());
4204 c = (classinfo *) clazz;
4205 f = (fieldinfo *) fieldID;
4207 if (!(c->state & CLASS_INITIALIZED))
4208 if (!initialize_class(c))
4215 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4221 STATISTICS(jniinvokation());
4223 c = (classinfo *) clazz;
4224 f = (fieldinfo *) fieldID;
4226 if (!(c->state & CLASS_INITIALIZED))
4227 if (!initialize_class(c))
4234 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4240 STATISTICS(jniinvokation());
4242 c = (classinfo *) clazz;
4243 f = (fieldinfo *) fieldID;
4245 if (!(c->state & CLASS_INITIALIZED))
4246 if (!initialize_class(c))
4253 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4259 STATISTICS(jniinvokation());
4261 c = (classinfo *) clazz;
4262 f = (fieldinfo *) fieldID;
4264 if (!(c->state & CLASS_INITIALIZED))
4265 if (!initialize_class(c))
4272 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4278 STATISTICS(jniinvokation());
4280 c = (classinfo *) clazz;
4281 f = (fieldinfo *) fieldID;
4283 if (!(c->state & CLASS_INITIALIZED))
4284 if (!initialize_class(c))
4291 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4297 STATISTICS(jniinvokation());
4299 c = (classinfo *) clazz;
4300 f = (fieldinfo *) fieldID;
4302 if (!(c->state & CLASS_INITIALIZED))
4303 if (!initialize_class(c))
4310 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4316 STATISTICS(jniinvokation());
4318 c = (classinfo *) clazz;
4319 f = (fieldinfo *) fieldID;
4321 if (!(c->state & CLASS_INITIALIZED))
4322 if (!initialize_class(c))
4329 /* String Operations **********************************************************/
4331 /* NewString *******************************************************************
4333 Create new java.lang.String object from an array of Unicode
4336 *******************************************************************************/
4338 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4340 java_lang_String *s;
4344 STATISTICS(jniinvokation());
4346 s = (java_lang_String *) builtin_new(class_java_lang_String);
4347 a = builtin_newarray_char(len);
4349 /* javastring or characterarray could not be created */
4350 if ((a == NULL) || (s == NULL))
4354 for (i = 0; i < len; i++)
4355 a->data[i] = buf[i];
4361 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4365 static jchar emptyStringJ[]={0,0};
4367 /* GetStringLength *************************************************************
4369 Returns the length (the count of Unicode characters) of a Java
4372 *******************************************************************************/
4374 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4376 java_lang_String *s;
4378 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
4380 s = (java_lang_String *) str;
4386 /******************** convertes javastring to u2-array ****************************/
4388 u2 *javastring_tou2(jstring so)
4390 java_lang_String *s;
4395 STATISTICS(jniinvokation());
4397 s = (java_lang_String *) so;
4407 /* allocate memory */
4409 stringbuffer = MNEW(u2, s->count + 1);
4413 for (i = 0; i < s->count; i++)
4414 stringbuffer[i] = a->data[s->offset + i];
4416 /* terminate string */
4418 stringbuffer[i] = '\0';
4420 return stringbuffer;
4424 /* GetStringChars **************************************************************
4426 Returns a pointer to the array of Unicode characters of the
4427 string. This pointer is valid until ReleaseStringChars() is called.
4429 *******************************************************************************/
4431 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4435 STATISTICS(jniinvokation());
4437 jc = javastring_tou2(str);
4449 return emptyStringJ;
4453 /* ReleaseStringChars **********************************************************
4455 Informs the VM that the native code no longer needs access to
4456 chars. The chars argument is a pointer obtained from string using
4459 *******************************************************************************/
4461 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4463 STATISTICS(jniinvokation());
4465 if (chars == emptyStringJ)
4468 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4472 /* NewStringUTF ****************************************************************
4474 Constructs a new java.lang.String object from an array of UTF-8
4477 *******************************************************************************/
4479 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4481 java_lang_String *s;
4483 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
4485 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4487 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4491 /****************** returns the utf8 length in bytes of a string *******************/
4493 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
4495 java_lang_String *s;
4498 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
4500 s = (java_lang_String *) string;
4502 length = u2_utflength(s->value->data, s->count);
4508 /* GetStringUTFChars ***********************************************************
4510 Returns a pointer to an array of UTF-8 characters of the
4511 string. This array is valid until it is released by
4512 ReleaseStringUTFChars().
4514 *******************************************************************************/
4516 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4521 STATISTICS(jniinvokation());
4529 u = javastring_toutf((java_objectheader *) string, false);
4538 /* ReleaseStringUTFChars *******************************************************
4540 Informs the VM that the native code no longer needs access to
4541 utf. The utf argument is a pointer derived from string using
4542 GetStringUTFChars().
4544 *******************************************************************************/
4546 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4548 STATISTICS(jniinvokation());
4550 /* XXX we don't release utf chars right now, perhaps that should be done
4551 later. Since there is always one reference the garbage collector will
4556 /* Array Operations ***********************************************************/
4558 /* GetArrayLength **************************************************************
4560 Returns the number of elements in the array.
4562 *******************************************************************************/
4564 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4566 java_arrayheader *a;
4568 STATISTICS(jniinvokation());
4570 a = (java_arrayheader *) array;
4576 /* NewObjectArray **************************************************************
4578 Constructs a new array holding objects in class elementClass. All
4579 elements are initially set to initialElement.
4581 *******************************************************************************/
4583 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4584 jclass elementClass, jobject initialElement)
4587 java_objectheader *o;
4588 java_objectarray *oa;
4591 STATISTICS(jniinvokation());
4593 c = (classinfo *) elementClass;
4594 o = (java_objectheader *) initialElement;
4597 exceptions_throw_negativearraysizeexception();
4601 oa = builtin_anewarray(length, c);
4606 /* set all elements to initialElement */
4608 for (i = 0; i < length; i++)
4611 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4615 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4618 java_objectarray *oa;
4619 java_objectheader *o;
4621 STATISTICS(jniinvokation());
4623 oa = (java_objectarray *) array;
4625 if (index >= oa->header.size) {
4626 exceptions_throw_arrayindexoutofboundsexception();
4630 o = oa->data[index];
4632 return _Jv_JNI_NewLocalRef(env, (jobject) o);
4636 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4637 jsize index, jobject val)
4639 java_objectarray *oa;
4640 java_objectheader *o;
4642 STATISTICS(jniinvokation());
4644 oa = (java_objectarray *) array;
4645 o = (java_objectheader *) val;
4647 if (index >= oa->header.size) {
4648 exceptions_throw_arrayindexoutofboundsexception();
4652 /* check if the class of value is a subclass of the element class
4655 if (!builtin_canstore(oa, o))
4658 oa->data[index] = o;
4662 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4664 java_booleanarray *ba;
4666 STATISTICS(jniinvokation());
4669 exceptions_throw_negativearraysizeexception();
4673 ba = builtin_newarray_boolean(len);
4675 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4679 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4683 STATISTICS(jniinvokation());
4686 exceptions_throw_negativearraysizeexception();
4690 ba = builtin_newarray_byte(len);
4692 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4696 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4700 STATISTICS(jniinvokation());
4703 exceptions_throw_negativearraysizeexception();
4707 ca = builtin_newarray_char(len);
4709 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4713 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4715 java_shortarray *sa;
4717 STATISTICS(jniinvokation());
4720 exceptions_throw_negativearraysizeexception();
4724 sa = builtin_newarray_short(len);
4726 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4730 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4734 STATISTICS(jniinvokation());
4737 exceptions_throw_negativearraysizeexception();
4741 ia = builtin_newarray_int(len);
4743 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4747 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4751 STATISTICS(jniinvokation());
4754 exceptions_throw_negativearraysizeexception();
4758 la = builtin_newarray_long(len);
4760 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4764 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4766 java_floatarray *fa;
4768 STATISTICS(jniinvokation());
4771 exceptions_throw_negativearraysizeexception();
4775 fa = builtin_newarray_float(len);
4777 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4781 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4783 java_doublearray *da;
4785 STATISTICS(jniinvokation());
4788 exceptions_throw_negativearraysizeexception();
4792 da = builtin_newarray_double(len);
4794 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4798 /* Get<PrimitiveType>ArrayElements *********************************************
4800 A family of functions that returns the body of the primitive array.
4802 *******************************************************************************/
4804 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4807 java_booleanarray *ba;
4809 STATISTICS(jniinvokation());
4811 ba = (java_booleanarray *) array;
4814 *isCopy = JNI_FALSE;
4820 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4825 STATISTICS(jniinvokation());
4827 ba = (java_bytearray *) array;
4830 *isCopy = JNI_FALSE;
4836 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4841 STATISTICS(jniinvokation());
4843 ca = (java_chararray *) array;
4846 *isCopy = JNI_FALSE;
4852 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4855 java_shortarray *sa;
4857 STATISTICS(jniinvokation());
4859 sa = (java_shortarray *) array;
4862 *isCopy = JNI_FALSE;
4868 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4873 STATISTICS(jniinvokation());
4875 ia = (java_intarray *) array;
4878 *isCopy = JNI_FALSE;
4884 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4889 STATISTICS(jniinvokation());
4891 la = (java_longarray *) array;
4894 *isCopy = JNI_FALSE;
4896 /* We cast this one to prevent a compiler warning on 64-bit
4897 systems since GNU Classpath typedef jlong to long long. */
4899 return (jlong *) la->data;
4903 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4906 java_floatarray *fa;
4908 STATISTICS(jniinvokation());
4910 fa = (java_floatarray *) array;
4913 *isCopy = JNI_FALSE;
4919 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4922 java_doublearray *da;
4924 STATISTICS(jniinvokation());
4926 da = (java_doublearray *) array;
4929 *isCopy = JNI_FALSE;
4935 /* Release<PrimitiveType>ArrayElements *****************************************
4937 A family of functions that informs the VM that the native code no
4938 longer needs access to elems. The elems argument is a pointer
4939 derived from array using the corresponding
4940 Get<PrimitiveType>ArrayElements() function. If necessary, this
4941 function copies back all changes made to elems to the original
4944 *******************************************************************************/
4946 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4947 jboolean *elems, jint mode)
4949 java_booleanarray *ba;
4951 STATISTICS(jniinvokation());
4953 ba = (java_booleanarray *) array;
4955 if (elems != ba->data) {
4958 MCOPY(ba->data, elems, u1, ba->header.size);
4961 MCOPY(ba->data, elems, u1, ba->header.size);
4962 /* XXX TWISTI how should it be freed? */
4965 /* XXX TWISTI how should it be freed? */
4972 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4973 jbyte *elems, jint mode)
4977 STATISTICS(jniinvokation());
4979 ba = (java_bytearray *) array;
4981 if (elems != ba->data) {
4984 MCOPY(ba->data, elems, s1, ba->header.size);
4987 MCOPY(ba->data, elems, s1, ba->header.size);
4988 /* XXX TWISTI how should it be freed? */
4991 /* XXX TWISTI how should it be freed? */
4998 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4999 jchar *elems, jint mode)
5003 STATISTICS(jniinvokation());
5005 ca = (java_chararray *) array;
5007 if (elems != ca->data) {
5010 MCOPY(ca->data, elems, u2, ca->header.size);
5013 MCOPY(ca->data, elems, u2, ca->header.size);
5014 /* XXX TWISTI how should it be freed? */
5017 /* XXX TWISTI how should it be freed? */
5024 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
5025 jshort *elems, jint mode)
5027 java_shortarray *sa;
5029 STATISTICS(jniinvokation());
5031 sa = (java_shortarray *) array;
5033 if (elems != sa->data) {
5036 MCOPY(sa->data, elems, s2, sa->header.size);
5039 MCOPY(sa->data, elems, s2, sa->header.size);
5040 /* XXX TWISTI how should it be freed? */
5043 /* XXX TWISTI how should it be freed? */
5050 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
5055 STATISTICS(jniinvokation());
5057 ia = (java_intarray *) array;
5059 if (elems != ia->data) {
5062 MCOPY(ia->data, elems, s4, ia->header.size);
5065 MCOPY(ia->data, elems, s4, ia->header.size);
5066 /* XXX TWISTI how should it be freed? */
5069 /* XXX TWISTI how should it be freed? */
5076 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
5077 jlong *elems, jint mode)
5081 STATISTICS(jniinvokation());
5083 la = (java_longarray *) array;
5085 /* We cast this one to prevent a compiler warning on 64-bit
5086 systems since GNU Classpath typedef jlong to long long. */
5088 if ((s8 *) elems != la->data) {
5091 MCOPY(la->data, elems, s8, la->header.size);
5094 MCOPY(la->data, elems, s8, la->header.size);
5095 /* XXX TWISTI how should it be freed? */
5098 /* XXX TWISTI how should it be freed? */
5105 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
5106 jfloat *elems, jint mode)
5108 java_floatarray *fa;
5110 STATISTICS(jniinvokation());
5112 fa = (java_floatarray *) array;
5114 if (elems != fa->data) {
5117 MCOPY(fa->data, elems, float, fa->header.size);
5120 MCOPY(fa->data, elems, float, fa->header.size);
5121 /* XXX TWISTI how should it be freed? */
5124 /* XXX TWISTI how should it be freed? */
5131 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
5132 jdouble *elems, jint mode)
5134 java_doublearray *da;
5136 STATISTICS(jniinvokation());
5138 da = (java_doublearray *) array;
5140 if (elems != da->data) {
5143 MCOPY(da->data, elems, double, da->header.size);
5146 MCOPY(da->data, elems, double, da->header.size);
5147 /* XXX TWISTI how should it be freed? */
5150 /* XXX TWISTI how should it be freed? */
5157 /* Get<PrimitiveType>ArrayRegion **********************************************
5159 A family of functions that copies a region of a primitive array
5162 *******************************************************************************/
5164 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5165 jsize start, jsize len, jboolean *buf)
5167 java_booleanarray *ba;
5169 STATISTICS(jniinvokation());
5171 ba = (java_booleanarray *) array;
5173 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5174 exceptions_throw_arrayindexoutofboundsexception();
5176 MCOPY(buf, &ba->data[start], u1, len);
5180 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5181 jsize len, jbyte *buf)
5185 STATISTICS(jniinvokation());
5187 ba = (java_bytearray *) array;
5189 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5190 exceptions_throw_arrayindexoutofboundsexception();
5192 MCOPY(buf, &ba->data[start], s1, len);
5196 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5197 jsize len, jchar *buf)
5201 STATISTICS(jniinvokation());
5203 ca = (java_chararray *) array;
5205 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5206 exceptions_throw_arrayindexoutofboundsexception();
5208 MCOPY(buf, &ca->data[start], u2, len);
5212 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5213 jsize len, jshort *buf)
5215 java_shortarray *sa;
5217 STATISTICS(jniinvokation());
5219 sa = (java_shortarray *) array;
5221 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5222 exceptions_throw_arrayindexoutofboundsexception();
5224 MCOPY(buf, &sa->data[start], s2, len);
5228 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5229 jsize len, jint *buf)
5233 STATISTICS(jniinvokation());
5235 ia = (java_intarray *) array;
5237 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5238 exceptions_throw_arrayindexoutofboundsexception();
5240 MCOPY(buf, &ia->data[start], s4, len);
5244 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5245 jsize len, jlong *buf)
5249 STATISTICS(jniinvokation());
5251 la = (java_longarray *) array;
5253 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5254 exceptions_throw_arrayindexoutofboundsexception();
5256 MCOPY(buf, &la->data[start], s8, len);
5260 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5261 jsize len, jfloat *buf)
5263 java_floatarray *fa;
5265 STATISTICS(jniinvokation());
5267 fa = (java_floatarray *) array;
5269 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5270 exceptions_throw_arrayindexoutofboundsexception();
5272 MCOPY(buf, &fa->data[start], float, len);
5276 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5277 jsize len, jdouble *buf)
5279 java_doublearray *da;
5281 STATISTICS(jniinvokation());
5283 da = (java_doublearray *) array;
5285 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5286 exceptions_throw_arrayindexoutofboundsexception();
5288 MCOPY(buf, &da->data[start], double, len);
5292 /* Set<PrimitiveType>ArrayRegion **********************************************
5294 A family of functions that copies back a region of a primitive
5295 array from a buffer.
5297 *******************************************************************************/
5299 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5300 jsize start, jsize len, const jboolean *buf)
5302 java_booleanarray *ba;
5304 STATISTICS(jniinvokation());
5306 ba = (java_booleanarray *) array;
5308 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5309 exceptions_throw_arrayindexoutofboundsexception();
5311 MCOPY(&ba->data[start], buf, u1, len);
5315 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5316 jsize len, const jbyte *buf)
5320 STATISTICS(jniinvokation());
5322 ba = (java_bytearray *) array;
5324 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5325 exceptions_throw_arrayindexoutofboundsexception();
5327 MCOPY(&ba->data[start], buf, s1, len);
5331 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5332 jsize len, const jchar *buf)
5336 STATISTICS(jniinvokation());
5338 ca = (java_chararray *) array;
5340 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5341 exceptions_throw_arrayindexoutofboundsexception();
5343 MCOPY(&ca->data[start], buf, u2, len);
5347 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5348 jsize len, const jshort *buf)
5350 java_shortarray *sa;
5352 STATISTICS(jniinvokation());
5354 sa = (java_shortarray *) array;
5356 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5357 exceptions_throw_arrayindexoutofboundsexception();
5359 MCOPY(&sa->data[start], buf, s2, len);
5363 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5364 jsize len, const jint *buf)
5368 STATISTICS(jniinvokation());
5370 ia = (java_intarray *) array;
5372 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5373 exceptions_throw_arrayindexoutofboundsexception();
5375 MCOPY(&ia->data[start], buf, s4, len);
5379 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5380 jsize len, const jlong *buf)
5384 STATISTICS(jniinvokation());
5386 la = (java_longarray *) array;
5388 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5389 exceptions_throw_arrayindexoutofboundsexception();
5391 MCOPY(&la->data[start], buf, s8, len);
5395 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5396 jsize len, const jfloat *buf)
5398 java_floatarray *fa;
5400 STATISTICS(jniinvokation());
5402 fa = (java_floatarray *) array;
5404 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5405 exceptions_throw_arrayindexoutofboundsexception();
5407 MCOPY(&fa->data[start], buf, float, len);
5411 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5412 jsize len, const jdouble *buf)
5414 java_doublearray *da;
5416 STATISTICS(jniinvokation());
5418 da = (java_doublearray *) array;
5420 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5421 exceptions_throw_arrayindexoutofboundsexception();
5423 MCOPY(&da->data[start], buf, double, len);
5427 /* Registering Native Methods *************************************************/
5429 /* RegisterNatives *************************************************************
5431 Registers native methods with the class specified by the clazz
5432 argument. The methods parameter specifies an array of
5433 JNINativeMethod structures that contain the names, signatures, and
5434 function pointers of the native methods. The nMethods parameter
5435 specifies the number of native methods in the array.
5437 *******************************************************************************/
5439 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5440 const JNINativeMethod *methods, jint nMethods)
5444 STATISTICS(jniinvokation());
5446 c = (classinfo *) clazz;
5448 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5449 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5452 native_method_register(c->name, methods, nMethods);
5458 /* UnregisterNatives ***********************************************************
5460 Unregisters native methods of a class. The class goes back to the
5461 state before it was linked or registered with its native method
5464 This function should not be used in normal native code. Instead, it
5465 provides special programs a way to reload and relink native
5468 *******************************************************************************/
5470 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5472 STATISTICS(jniinvokation());
5474 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5476 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5482 /* Monitor Operations *********************************************************/
5484 /* MonitorEnter ****************************************************************
5486 Enters the monitor associated with the underlying Java object
5489 *******************************************************************************/
5491 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5493 STATISTICS(jniinvokation());
5496 exceptions_throw_nullpointerexception();
5500 LOCK_MONITOR_ENTER(obj);
5506 /* MonitorExit *****************************************************************
5508 The current thread must be the owner of the monitor associated with
5509 the underlying Java object referred to by obj. The thread
5510 decrements the counter indicating the number of times it has
5511 entered this monitor. If the value of the counter becomes zero, the
5512 current thread releases the monitor.
5514 *******************************************************************************/
5516 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5518 STATISTICS(jniinvokation());
5521 exceptions_throw_nullpointerexception();
5525 LOCK_MONITOR_EXIT(obj);
5531 /* JavaVM Interface ***********************************************************/
5533 /* GetJavaVM *******************************************************************
5535 Returns the Java VM interface (used in the Invocation API)
5536 associated with the current thread. The result is placed at the
5537 location pointed to by the second argument, vm.
5539 *******************************************************************************/
5541 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5543 STATISTICS(jniinvokation());
5545 *vm = (JavaVM *) _Jv_jvm;
5551 /* GetStringRegion *************************************************************
5553 Copies len number of Unicode characters beginning at offset start
5554 to the given buffer buf.
5556 Throws StringIndexOutOfBoundsException on index overflow.
5558 *******************************************************************************/
5560 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5563 java_lang_String *s;
5566 STATISTICS(jniinvokation());
5568 s = (java_lang_String *) str;
5571 if ((start < 0) || (len < 0) || (start > s->count) ||
5572 (start + len > s->count)) {
5573 exceptions_throw_stringindexoutofboundsexception();
5577 MCOPY(buf, &ca->data[start], u2, len);
5581 /* GetStringUTFRegion **********************************************************
5583 Translates len number of Unicode characters beginning at offset
5584 start into UTF-8 format and place the result in the given buffer
5587 Throws StringIndexOutOfBoundsException on index overflow.
5589 *******************************************************************************/
5591 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5592 jsize len, char *buf)
5594 java_lang_String *s;
5598 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
5600 s = (java_lang_String *) str;
5603 if ((start < 0) || (len < 0) || (start > s->count) ||
5604 (start + len > s->count)) {
5605 exceptions_throw_stringindexoutofboundsexception();
5609 for (i = 0; i < len; i++)
5610 buf[i] = ca->data[s->offset + start + i];
5616 /* GetPrimitiveArrayCritical ***************************************************
5618 Obtain a direct pointer to array elements.
5620 *******************************************************************************/
5622 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5628 ba = (java_bytearray *) array;
5630 /* do the same as Kaffe does */
5632 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
5638 /* ReleasePrimitiveArrayCritical ***********************************************
5640 No specific documentation.
5642 *******************************************************************************/
5644 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5645 void *carray, jint mode)
5647 STATISTICS(jniinvokation());
5649 /* do the same as Kaffe does */
5651 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5656 /* GetStringCritical ***********************************************************
5658 The semantics of these two functions are similar to the existing
5659 Get/ReleaseStringChars functions.
5661 *******************************************************************************/
5663 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5666 STATISTICS(jniinvokation());
5668 return _Jv_JNI_GetStringChars(env, string, isCopy);
5672 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5673 const jchar *cstring)
5675 STATISTICS(jniinvokation());
5677 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5681 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5683 STATISTICS(jniinvokation());
5685 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5691 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5693 STATISTICS(jniinvokation());
5695 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5699 /* NewGlobalRef ****************************************************************
5701 Creates a new global reference to the object referred to by the obj
5704 *******************************************************************************/
5706 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5708 hashtable_global_ref_entry *gre;
5709 u4 key; /* hashkey */
5710 u4 slot; /* slot in hashtable */
5711 java_objectheader *o;
5713 STATISTICS(jniinvokation());
5715 o = (java_objectheader *) obj;
5717 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5719 /* normally addresses are aligned to 4, 8 or 16 bytes */
5721 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5722 slot = key & (hashtable_global_ref->size - 1);
5723 gre = hashtable_global_ref->ptr[slot];
5725 /* search external hash chain for the entry */
5729 /* global object found, increment the reference */
5733 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5738 gre = gre->hashlink; /* next element in external chain */
5741 /* global ref not found, create a new one */
5743 gre = NEW(hashtable_global_ref_entry);
5745 #if defined(ENABLE_GC_CACAO)
5746 /* register global ref with the GC */
5748 gc_reference_register(&(gre->o));
5754 /* insert entry into hashtable */
5756 gre->hashlink = hashtable_global_ref->ptr[slot];
5758 hashtable_global_ref->ptr[slot] = gre;
5760 /* update number of hashtable-entries */
5762 hashtable_global_ref->entries++;
5764 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5770 /* DeleteGlobalRef *************************************************************
5772 Deletes the global reference pointed to by globalRef.
5774 *******************************************************************************/
5776 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5778 hashtable_global_ref_entry *gre;
5779 hashtable_global_ref_entry *prevgre;
5780 u4 key; /* hashkey */
5781 u4 slot; /* slot in hashtable */
5782 java_objectheader *o;
5784 STATISTICS(jniinvokation());
5786 o = (java_objectheader *) globalRef;
5788 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5790 /* normally addresses are aligned to 4, 8 or 16 bytes */
5792 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5793 slot = key & (hashtable_global_ref->size - 1);
5794 gre = hashtable_global_ref->ptr[slot];
5796 /* initialize prevgre */
5800 /* search external hash chain for the entry */
5804 /* global object found, decrement the reference count */
5808 /* if reference count is 0, remove the entry */
5810 if (gre->refs == 0) {
5811 /* special handling if it's the first in the chain */
5813 if (prevgre == NULL)
5814 hashtable_global_ref->ptr[slot] = gre->hashlink;
5816 prevgre->hashlink = gre->hashlink;
5818 #if defined(ENABLE_GC_CACAO)
5819 /* unregister global ref with the GC */
5821 gc_reference_unregister(&(gre->o));
5824 FREE(gre, hashtable_global_ref_entry);
5827 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5832 prevgre = gre; /* save current pointer for removal */
5833 gre = gre->hashlink; /* next element in external chain */
5836 log_println("JNI-DeleteGlobalRef: global reference not found");
5838 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5842 /* ExceptionCheck **************************************************************
5844 Returns JNI_TRUE when there is a pending exception; otherwise,
5847 *******************************************************************************/
5849 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5851 java_objectheader *o;
5853 STATISTICS(jniinvokation());
5855 o = exceptions_get_exception();
5857 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5861 /* New JNI 1.4 functions ******************************************************/
5863 /* NewDirectByteBuffer *********************************************************
5865 Allocates and returns a direct java.nio.ByteBuffer referring to the
5866 block of memory starting at the memory address address and
5867 extending capacity bytes.
5869 *******************************************************************************/
5871 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5873 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5874 java_objectheader *nbuf;
5876 # if SIZEOF_VOID_P == 8
5877 gnu_classpath_Pointer64 *paddress;
5879 gnu_classpath_Pointer32 *paddress;
5882 STATISTICS(jniinvokation());
5884 /* alocate a gnu.classpath.Pointer{32,64} object */
5886 # if SIZEOF_VOID_P == 8
5887 if (!(paddress = (gnu_classpath_Pointer64 *)
5888 builtin_new(class_gnu_classpath_Pointer64)))
5890 if (!(paddress = (gnu_classpath_Pointer32 *)
5891 builtin_new(class_gnu_classpath_Pointer32)))
5895 /* fill gnu.classpath.Pointer{32,64} with address */
5897 paddress->data = (ptrint) address;
5899 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5901 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5902 (jmethodID) dbbirw_init, NULL, paddress,
5903 (jint) capacity, (jint) capacity, (jint) 0);
5905 /* add local reference and return the value */
5907 return _Jv_JNI_NewLocalRef(env, nbuf);
5909 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5911 /* keep compiler happy */
5918 /* GetDirectBufferAddress ******************************************************
5920 Fetches and returns the starting address of the memory region
5921 referenced by the given direct java.nio.Buffer.
5923 *******************************************************************************/
5925 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5927 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5928 java_nio_DirectByteBufferImpl *nbuf;
5929 # if SIZEOF_VOID_P == 8
5930 gnu_classpath_Pointer64 *address;
5932 gnu_classpath_Pointer32 *address;
5935 STATISTICS(jniinvokation());
5937 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5940 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5942 # if SIZEOF_VOID_P == 8
5943 address = (gnu_classpath_Pointer64 *) nbuf->address;
5945 address = (gnu_classpath_Pointer32 *) nbuf->address;
5948 if (address == NULL)
5951 return (void *) address->data;
5953 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5955 /* keep compiler happy */
5962 /* GetDirectBufferCapacity *****************************************************
5964 Fetches and returns the capacity in bytes of the memory region
5965 referenced by the given direct java.nio.Buffer.
5967 *******************************************************************************/
5969 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5971 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5972 java_objectheader *o;
5973 java_nio_Buffer *nbuf;
5975 STATISTICS(jniinvokation());
5977 o = (java_objectheader *) buf;
5979 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
5982 nbuf = (java_nio_Buffer *) o;
5984 return (jlong) nbuf->cap;
5986 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5988 /* keep compiler happy */
5995 /* DestroyJavaVM ***************************************************************
5997 Unloads a Java VM and reclaims its resources. Only the main thread
5998 can unload the VM. The system waits until the main thread is only
5999 remaining user thread before it destroys the VM.
6001 *******************************************************************************/
6003 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
6007 STATISTICS(jniinvokation());
6009 status = vm_destroy(vm);
6015 /* AttachCurrentThread *********************************************************
6017 Attaches the current thread to a Java VM. Returns a JNI interface
6018 pointer in the JNIEnv argument.
6020 Trying to attach a thread that is already attached is a no-op.
6022 A native thread cannot be attached simultaneously to two Java VMs.
6024 When a thread is attached to the VM, the context class loader is
6025 the bootstrap loader.
6027 *******************************************************************************/
6029 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
6031 JavaVMAttachArgs *vm_aargs;
6033 #if defined(ENABLE_THREADS)
6034 if (threads_get_current_threadobject() == NULL) {
6035 vm_aargs = (JavaVMAttachArgs *) thr_args;
6037 if (vm_aargs != NULL) {
6038 if ((vm_aargs->version != JNI_VERSION_1_2) &&
6039 (vm_aargs->version != JNI_VERSION_1_4))
6040 return JNI_EVERSION;
6043 if (!threads_attach_current_thread(vm_aargs, false))
6046 if (!jni_init_localref_table())
6057 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
6059 STATISTICS(jniinvokation());
6061 return jni_attach_current_thread(p_env, thr_args, false);
6065 /* DetachCurrentThread *********************************************************
6067 Detaches the current thread from a Java VM. All Java monitors held
6068 by this thread are released. All Java threads waiting for this
6069 thread to die are notified.
6071 In JDK 1.1, the main thread cannot be detached from the VM. It must
6072 call DestroyJavaVM to unload the entire VM.
6074 In the JDK, the main thread can be detached from the VM.
6076 The main thread, which is the thread that created the Java VM,
6077 cannot be detached from the VM. Instead, the main thread must call
6078 JNI_DestroyJavaVM() to unload the entire VM.
6080 *******************************************************************************/
6082 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
6084 #if defined(ENABLE_THREADS)
6085 threadobject *thread;
6087 STATISTICS(jniinvokation());
6089 thread = threads_get_current_threadobject();
6094 if (!jni_free_localref_table())
6097 if (!threads_detach_thread(thread))
6105 /* GetEnv **********************************************************************
6107 If the current thread is not attached to the VM, sets *env to NULL,
6108 and returns JNI_EDETACHED. If the specified version is not
6109 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
6110 sets *env to the appropriate interface, and returns JNI_OK.
6112 *******************************************************************************/
6114 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
6116 STATISTICS(jniinvokation());
6118 #if defined(ENABLE_THREADS)
6119 if (threads_get_current_threadobject() == NULL) {
6122 return JNI_EDETACHED;
6126 /* check the JNI version */
6129 case JNI_VERSION_1_1:
6130 case JNI_VERSION_1_2:
6131 case JNI_VERSION_1_4:
6139 #if defined(ENABLE_JVMTI)
6140 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
6141 == JVMTI_VERSION_INTERFACE_JVMTI) {
6143 *env = (void *) jvmti_new_environment();
6152 return JNI_EVERSION;
6156 /* AttachCurrentThreadAsDaemon *************************************************
6158 Same semantics as AttachCurrentThread, but the newly-created
6159 java.lang.Thread instance is a daemon.
6161 If the thread has already been attached via either
6162 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
6163 simply sets the value pointed to by penv to the JNIEnv of the
6164 current thread. In this case neither AttachCurrentThread nor this
6165 routine have any effect on the daemon status of the thread.
6167 *******************************************************************************/
6169 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
6171 STATISTICS(jniinvokation());
6173 return jni_attach_current_thread(penv, args, true);
6177 /* JNI invocation table *******************************************************/
6179 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
6184 _Jv_JNI_DestroyJavaVM,
6185 _Jv_JNI_AttachCurrentThread,
6186 _Jv_JNI_DetachCurrentThread,
6188 _Jv_JNI_AttachCurrentThreadAsDaemon
6192 /* JNI function table *********************************************************/
6194 struct JNINativeInterface_ _Jv_JNINativeInterface = {
6201 _Jv_JNI_DefineClass,
6203 _Jv_JNI_FromReflectedMethod,
6204 _Jv_JNI_FromReflectedField,
6205 _Jv_JNI_ToReflectedMethod,
6206 _Jv_JNI_GetSuperclass,
6207 _Jv_JNI_IsAssignableFrom,
6208 _Jv_JNI_ToReflectedField,
6212 _Jv_JNI_ExceptionOccurred,
6213 _Jv_JNI_ExceptionDescribe,
6214 _Jv_JNI_ExceptionClear,
6216 _Jv_JNI_PushLocalFrame,
6217 _Jv_JNI_PopLocalFrame,
6219 _Jv_JNI_NewGlobalRef,
6220 _Jv_JNI_DeleteGlobalRef,
6221 _Jv_JNI_DeleteLocalRef,
6222 _Jv_JNI_IsSameObject,
6223 _Jv_JNI_NewLocalRef,
6224 _Jv_JNI_EnsureLocalCapacity,
6226 _Jv_JNI_AllocObject,
6231 _Jv_JNI_GetObjectClass,
6232 _Jv_JNI_IsInstanceOf,
6234 _Jv_JNI_GetMethodID,
6236 _Jv_JNI_CallObjectMethod,
6237 _Jv_JNI_CallObjectMethodV,
6238 _Jv_JNI_CallObjectMethodA,
6239 _Jv_JNI_CallBooleanMethod,
6240 _Jv_JNI_CallBooleanMethodV,
6241 _Jv_JNI_CallBooleanMethodA,
6242 _Jv_JNI_CallByteMethod,
6243 _Jv_JNI_CallByteMethodV,
6244 _Jv_JNI_CallByteMethodA,
6245 _Jv_JNI_CallCharMethod,
6246 _Jv_JNI_CallCharMethodV,
6247 _Jv_JNI_CallCharMethodA,
6248 _Jv_JNI_CallShortMethod,
6249 _Jv_JNI_CallShortMethodV,
6250 _Jv_JNI_CallShortMethodA,
6251 _Jv_JNI_CallIntMethod,
6252 _Jv_JNI_CallIntMethodV,
6253 _Jv_JNI_CallIntMethodA,
6254 _Jv_JNI_CallLongMethod,
6255 _Jv_JNI_CallLongMethodV,
6256 _Jv_JNI_CallLongMethodA,
6257 _Jv_JNI_CallFloatMethod,
6258 _Jv_JNI_CallFloatMethodV,
6259 _Jv_JNI_CallFloatMethodA,
6260 _Jv_JNI_CallDoubleMethod,
6261 _Jv_JNI_CallDoubleMethodV,
6262 _Jv_JNI_CallDoubleMethodA,
6263 _Jv_JNI_CallVoidMethod,
6264 _Jv_JNI_CallVoidMethodV,
6265 _Jv_JNI_CallVoidMethodA,
6267 _Jv_JNI_CallNonvirtualObjectMethod,
6268 _Jv_JNI_CallNonvirtualObjectMethodV,
6269 _Jv_JNI_CallNonvirtualObjectMethodA,
6270 _Jv_JNI_CallNonvirtualBooleanMethod,
6271 _Jv_JNI_CallNonvirtualBooleanMethodV,
6272 _Jv_JNI_CallNonvirtualBooleanMethodA,
6273 _Jv_JNI_CallNonvirtualByteMethod,
6274 _Jv_JNI_CallNonvirtualByteMethodV,
6275 _Jv_JNI_CallNonvirtualByteMethodA,
6276 _Jv_JNI_CallNonvirtualCharMethod,
6277 _Jv_JNI_CallNonvirtualCharMethodV,
6278 _Jv_JNI_CallNonvirtualCharMethodA,
6279 _Jv_JNI_CallNonvirtualShortMethod,
6280 _Jv_JNI_CallNonvirtualShortMethodV,
6281 _Jv_JNI_CallNonvirtualShortMethodA,
6282 _Jv_JNI_CallNonvirtualIntMethod,
6283 _Jv_JNI_CallNonvirtualIntMethodV,
6284 _Jv_JNI_CallNonvirtualIntMethodA,
6285 _Jv_JNI_CallNonvirtualLongMethod,
6286 _Jv_JNI_CallNonvirtualLongMethodV,
6287 _Jv_JNI_CallNonvirtualLongMethodA,
6288 _Jv_JNI_CallNonvirtualFloatMethod,
6289 _Jv_JNI_CallNonvirtualFloatMethodV,
6290 _Jv_JNI_CallNonvirtualFloatMethodA,
6291 _Jv_JNI_CallNonvirtualDoubleMethod,
6292 _Jv_JNI_CallNonvirtualDoubleMethodV,
6293 _Jv_JNI_CallNonvirtualDoubleMethodA,
6294 _Jv_JNI_CallNonvirtualVoidMethod,
6295 _Jv_JNI_CallNonvirtualVoidMethodV,
6296 _Jv_JNI_CallNonvirtualVoidMethodA,
6300 _Jv_JNI_GetObjectField,
6301 _Jv_JNI_GetBooleanField,
6302 _Jv_JNI_GetByteField,
6303 _Jv_JNI_GetCharField,
6304 _Jv_JNI_GetShortField,
6305 _Jv_JNI_GetIntField,
6306 _Jv_JNI_GetLongField,
6307 _Jv_JNI_GetFloatField,
6308 _Jv_JNI_GetDoubleField,
6309 _Jv_JNI_SetObjectField,
6310 _Jv_JNI_SetBooleanField,
6311 _Jv_JNI_SetByteField,
6312 _Jv_JNI_SetCharField,
6313 _Jv_JNI_SetShortField,
6314 _Jv_JNI_SetIntField,
6315 _Jv_JNI_SetLongField,
6316 _Jv_JNI_SetFloatField,
6317 _Jv_JNI_SetDoubleField,
6319 _Jv_JNI_GetStaticMethodID,
6321 _Jv_JNI_CallStaticObjectMethod,
6322 _Jv_JNI_CallStaticObjectMethodV,
6323 _Jv_JNI_CallStaticObjectMethodA,
6324 _Jv_JNI_CallStaticBooleanMethod,
6325 _Jv_JNI_CallStaticBooleanMethodV,
6326 _Jv_JNI_CallStaticBooleanMethodA,
6327 _Jv_JNI_CallStaticByteMethod,
6328 _Jv_JNI_CallStaticByteMethodV,
6329 _Jv_JNI_CallStaticByteMethodA,
6330 _Jv_JNI_CallStaticCharMethod,
6331 _Jv_JNI_CallStaticCharMethodV,
6332 _Jv_JNI_CallStaticCharMethodA,
6333 _Jv_JNI_CallStaticShortMethod,
6334 _Jv_JNI_CallStaticShortMethodV,
6335 _Jv_JNI_CallStaticShortMethodA,
6336 _Jv_JNI_CallStaticIntMethod,
6337 _Jv_JNI_CallStaticIntMethodV,
6338 _Jv_JNI_CallStaticIntMethodA,
6339 _Jv_JNI_CallStaticLongMethod,
6340 _Jv_JNI_CallStaticLongMethodV,
6341 _Jv_JNI_CallStaticLongMethodA,
6342 _Jv_JNI_CallStaticFloatMethod,
6343 _Jv_JNI_CallStaticFloatMethodV,
6344 _Jv_JNI_CallStaticFloatMethodA,
6345 _Jv_JNI_CallStaticDoubleMethod,
6346 _Jv_JNI_CallStaticDoubleMethodV,
6347 _Jv_JNI_CallStaticDoubleMethodA,
6348 _Jv_JNI_CallStaticVoidMethod,
6349 _Jv_JNI_CallStaticVoidMethodV,
6350 _Jv_JNI_CallStaticVoidMethodA,
6352 _Jv_JNI_GetStaticFieldID,
6354 _Jv_JNI_GetStaticObjectField,
6355 _Jv_JNI_GetStaticBooleanField,
6356 _Jv_JNI_GetStaticByteField,
6357 _Jv_JNI_GetStaticCharField,
6358 _Jv_JNI_GetStaticShortField,
6359 _Jv_JNI_GetStaticIntField,
6360 _Jv_JNI_GetStaticLongField,
6361 _Jv_JNI_GetStaticFloatField,
6362 _Jv_JNI_GetStaticDoubleField,
6363 _Jv_JNI_SetStaticObjectField,
6364 _Jv_JNI_SetStaticBooleanField,
6365 _Jv_JNI_SetStaticByteField,
6366 _Jv_JNI_SetStaticCharField,
6367 _Jv_JNI_SetStaticShortField,
6368 _Jv_JNI_SetStaticIntField,
6369 _Jv_JNI_SetStaticLongField,
6370 _Jv_JNI_SetStaticFloatField,
6371 _Jv_JNI_SetStaticDoubleField,
6374 _Jv_JNI_GetStringLength,
6375 _Jv_JNI_GetStringChars,
6376 _Jv_JNI_ReleaseStringChars,
6378 _Jv_JNI_NewStringUTF,
6379 _Jv_JNI_GetStringUTFLength,
6380 _Jv_JNI_GetStringUTFChars,
6381 _Jv_JNI_ReleaseStringUTFChars,
6383 _Jv_JNI_GetArrayLength,
6385 _Jv_JNI_NewObjectArray,
6386 _Jv_JNI_GetObjectArrayElement,
6387 _Jv_JNI_SetObjectArrayElement,
6389 _Jv_JNI_NewBooleanArray,
6390 _Jv_JNI_NewByteArray,
6391 _Jv_JNI_NewCharArray,
6392 _Jv_JNI_NewShortArray,
6393 _Jv_JNI_NewIntArray,
6394 _Jv_JNI_NewLongArray,
6395 _Jv_JNI_NewFloatArray,
6396 _Jv_JNI_NewDoubleArray,
6398 _Jv_JNI_GetBooleanArrayElements,
6399 _Jv_JNI_GetByteArrayElements,
6400 _Jv_JNI_GetCharArrayElements,
6401 _Jv_JNI_GetShortArrayElements,
6402 _Jv_JNI_GetIntArrayElements,
6403 _Jv_JNI_GetLongArrayElements,
6404 _Jv_JNI_GetFloatArrayElements,
6405 _Jv_JNI_GetDoubleArrayElements,
6407 _Jv_JNI_ReleaseBooleanArrayElements,
6408 _Jv_JNI_ReleaseByteArrayElements,
6409 _Jv_JNI_ReleaseCharArrayElements,
6410 _Jv_JNI_ReleaseShortArrayElements,
6411 _Jv_JNI_ReleaseIntArrayElements,
6412 _Jv_JNI_ReleaseLongArrayElements,
6413 _Jv_JNI_ReleaseFloatArrayElements,
6414 _Jv_JNI_ReleaseDoubleArrayElements,
6416 _Jv_JNI_GetBooleanArrayRegion,
6417 _Jv_JNI_GetByteArrayRegion,
6418 _Jv_JNI_GetCharArrayRegion,
6419 _Jv_JNI_GetShortArrayRegion,
6420 _Jv_JNI_GetIntArrayRegion,
6421 _Jv_JNI_GetLongArrayRegion,
6422 _Jv_JNI_GetFloatArrayRegion,
6423 _Jv_JNI_GetDoubleArrayRegion,
6424 _Jv_JNI_SetBooleanArrayRegion,
6425 _Jv_JNI_SetByteArrayRegion,
6426 _Jv_JNI_SetCharArrayRegion,
6427 _Jv_JNI_SetShortArrayRegion,
6428 _Jv_JNI_SetIntArrayRegion,
6429 _Jv_JNI_SetLongArrayRegion,
6430 _Jv_JNI_SetFloatArrayRegion,
6431 _Jv_JNI_SetDoubleArrayRegion,
6433 _Jv_JNI_RegisterNatives,
6434 _Jv_JNI_UnregisterNatives,
6436 _Jv_JNI_MonitorEnter,
6437 _Jv_JNI_MonitorExit,
6441 /* new JNI 1.2 functions */
6443 _Jv_JNI_GetStringRegion,
6444 _Jv_JNI_GetStringUTFRegion,
6446 _Jv_JNI_GetPrimitiveArrayCritical,
6447 _Jv_JNI_ReleasePrimitiveArrayCritical,
6449 _Jv_JNI_GetStringCritical,
6450 _Jv_JNI_ReleaseStringCritical,
6452 _Jv_JNI_NewWeakGlobalRef,
6453 _Jv_JNI_DeleteWeakGlobalRef,
6455 _Jv_JNI_ExceptionCheck,
6457 /* new JNI 1.4 functions */
6459 _Jv_JNI_NewDirectByteBuffer,
6460 _Jv_JNI_GetDirectBufferAddress,
6461 _Jv_JNI_GetDirectBufferCapacity
6465 /* Invocation API Functions ***************************************************/
6467 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6469 Returns a default configuration for the Java VM.
6471 *******************************************************************************/
6473 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6475 JavaVMInitArgs *_vm_args;
6477 _vm_args = (JavaVMInitArgs *) vm_args;
6479 /* GNU classpath currently supports JNI 1.2 */
6481 switch (_vm_args->version) {
6482 case JNI_VERSION_1_1:
6483 _vm_args->version = JNI_VERSION_1_1;
6486 case JNI_VERSION_1_2:
6487 case JNI_VERSION_1_4:
6488 _vm_args->ignoreUnrecognized = JNI_FALSE;
6489 _vm_args->options = NULL;
6490 _vm_args->nOptions = 0;
6501 /* JNI_GetCreatedJavaVMs *******************************************************
6503 Returns all Java VMs that have been created. Pointers to VMs are written in
6504 the buffer vmBuf in the order they are created. At most bufLen number of
6505 entries will be written. The total number of created VMs is returned in
6508 *******************************************************************************/
6510 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6512 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
6517 /* We currently only support 1 VM running. */
6519 vmBuf[0] = (JavaVM *) _Jv_jvm;
6526 /* JNI_CreateJavaVM ************************************************************
6528 Loads and initializes a Java VM. The current thread becomes the main thread.
6529 Sets the env argument to the JNI interface pointer of the main thread.
6531 *******************************************************************************/
6533 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6535 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
6537 /* actually create the JVM */
6539 if (!vm_createjvm(p_vm, p_env, vm_args))
6547 * These are local overrides for various environment variables in Emacs.
6548 * Please do not remove this and leave it at the end of the file, where
6549 * Emacs will automagically detect them.
6550 * ---------------------------------------------------------------------
6553 * indent-tabs-mode: t
6557 * vim:noexpandtab:sw=4:ts=4: