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 7722 2007-04-16 15:57:21Z twisti $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #if defined(ENABLE_JAVASE)
43 # if defined(WITH_CLASSPATH_GNU)
44 # include "native/include/gnu_classpath_Pointer.h"
46 # if SIZEOF_VOID_P == 8
47 # include "native/include/gnu_classpath_Pointer64.h"
49 # include "native/include/gnu_classpath_Pointer32.h"
54 #include "native/include/java_lang_Object.h"
55 #include "native/include/java_lang_Byte.h"
56 #include "native/include/java_lang_Character.h"
57 #include "native/include/java_lang_Short.h"
58 #include "native/include/java_lang_Integer.h"
59 #include "native/include/java_lang_Boolean.h"
60 #include "native/include/java_lang_Long.h"
61 #include "native/include/java_lang_Float.h"
62 #include "native/include/java_lang_Double.h"
63 #include "native/include/java_lang_String.h"
64 #include "native/include/java_lang_Throwable.h"
66 #if defined(ENABLE_JAVASE)
67 # include "native/include/java_lang_ClassLoader.h"
69 # include "native/include/java_lang_reflect_Constructor.h"
70 # include "native/include/java_lang_reflect_Field.h"
71 # include "native/include/java_lang_reflect_Method.h"
73 # include "native/include/java_nio_Buffer.h"
74 # include "native/include/java_nio_DirectByteBufferImpl.h"
77 #if defined(ENABLE_JVMTI)
78 # include "native/jvmti/cacaodbg.h"
81 #include "native/vm/java_lang_Class.h"
83 #if defined(ENABLE_JAVASE)
84 # include "native/vm/java_lang_ClassLoader.h"
87 #if defined(ENABLE_THREADS)
88 # include "threads/native/lock.h"
89 # include "threads/native/threads.h"
91 # include "threads/none/lock.h"
92 # include "threads/none/threads.h"
95 #include "toolbox/logging.h"
97 #include "vm/builtin.h"
98 #include "vm/exceptions.h"
99 #include "vm/global.h"
100 #include "vm/initialize.h"
101 #include "vm/stringlocal.h"
104 #include "vm/jit/asmpart.h"
105 #include "vm/jit/jit.h"
106 #include "vm/jit/stacktrace.h"
108 #include "vmcore/loader.h"
109 #include "vmcore/options.h"
110 #include "vm/resolve.h"
111 #include "vmcore/statistics.h"
114 /* global variables ***********************************************************/
116 /* global reference table *****************************************************/
118 /* hashsize must be power of 2 */
120 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
122 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
125 /* direct buffer stuff ********************************************************/
127 #if defined(ENABLE_JAVASE)
128 static classinfo *class_java_nio_Buffer;
129 static classinfo *class_java_nio_DirectByteBufferImpl;
130 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
132 # if defined(WITH_CLASSPATH_GNU)
133 # if SIZEOF_VOID_P == 8
134 static classinfo *class_gnu_classpath_Pointer64;
136 static classinfo *class_gnu_classpath_Pointer32;
140 static methodinfo *dbbirw_init;
144 /* local reference table ******************************************************/
146 #if !defined(ENABLE_THREADS)
147 localref_table *_no_threads_localref_table;
151 /* accessing instance fields macros *******************************************/
153 #define SET_FIELD(o,type,f,value) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
156 #define GET_FIELD(o,type,f) \
157 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
160 /* some forward declarations **************************************************/
162 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
163 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
166 /* jni_init ********************************************************************
168 Initialize the JNI subsystem.
170 *******************************************************************************/
174 /* create global ref hashtable */
176 hashtable_global_ref = NEW(hashtable);
178 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
181 #if defined(ENABLE_JAVASE)
182 /* direct buffer stuff */
184 if (!(class_java_nio_Buffer =
185 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
186 !link_class(class_java_nio_Buffer))
189 if (!(class_java_nio_DirectByteBufferImpl =
190 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
191 !link_class(class_java_nio_DirectByteBufferImpl))
194 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
195 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
196 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
200 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
202 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
205 # if defined(WITH_CLASSPATH_GNU)
206 # if SIZEOF_VOID_P == 8
207 if (!(class_gnu_classpath_Pointer64 =
208 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
209 !link_class(class_gnu_classpath_Pointer64))
212 if (!(class_gnu_classpath_Pointer32 =
213 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
214 !link_class(class_gnu_classpath_Pointer32))
218 #endif /* defined(ENABLE_JAVASE) */
224 /* jni_init_localref_table *****************************************************
226 Initializes the local references table of the current thread.
228 *******************************************************************************/
230 bool jni_init_localref_table(void)
234 lrt = GCNEW(localref_table);
239 lrt->capacity = LOCALREFTABLE_CAPACITY;
241 lrt->localframes = 1;
242 lrt->prev = LOCALREFTABLE;
244 /* clear the references array (memset is faster then a for-loop) */
246 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
254 /* _Jv_jni_vmargs_from_objectarray *********************************************
258 *******************************************************************************/
260 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
263 java_objectarray *params)
265 java_objectheader *param;
267 typedesc *paramtypes;
273 paramcount = descr->paramcount;
274 paramtypes = descr->paramtypes;
276 /* if method is non-static fill first block and skip `this' pointer */
282 vmargs[0].type = TYPE_ADR;
283 vmargs[0].data.l = (u8) (ptrint) o;
290 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
291 switch (paramtypes->type) {
292 /* primitive types */
297 param = params->data[j];
302 /* internally used data type */
303 vmargs[i].type = paramtypes->type;
305 /* convert the value according to its declared type */
307 c = param->vftbl->class;
309 switch (paramtypes->decltype) {
310 case PRIMITIVETYPE_BOOLEAN:
311 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
312 value = (s8) ((java_lang_Boolean *) param)->value;
316 vmargs[i].data.l = value;
319 case PRIMITIVETYPE_BYTE:
320 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
321 value = (s8) ((java_lang_Byte *) param)->value;
325 vmargs[i].data.l = value;
328 case PRIMITIVETYPE_CHAR:
329 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
330 value = (s8) ((java_lang_Character *) param)->value;
334 vmargs[i].data.l = value;
337 case PRIMITIVETYPE_SHORT:
338 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
339 value = (s8) ((java_lang_Short *) param)->value;
340 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
341 value = (s8) ((java_lang_Byte *) param)->value;
345 vmargs[i].data.l = value;
348 case PRIMITIVETYPE_INT:
349 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
350 value = (s8) ((java_lang_Integer *) param)->value;
351 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
352 value = (s8) ((java_lang_Short *) param)->value;
353 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
354 value = (s8) ((java_lang_Byte *) param)->value;
358 vmargs[i].data.l = value;
361 case PRIMITIVETYPE_LONG:
362 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
363 value = (s8) ((java_lang_Long *) param)->value;
364 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
365 value = (s8) ((java_lang_Integer *) param)->value;
366 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
367 value = (s8) ((java_lang_Short *) param)->value;
368 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
369 value = (s8) ((java_lang_Byte *) param)->value;
373 vmargs[i].data.l = value;
376 case PRIMITIVETYPE_FLOAT:
377 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
378 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
383 case PRIMITIVETYPE_DOUBLE:
384 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
385 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
386 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
387 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
398 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
401 if (params->data[j] != 0) {
402 if (paramtypes->arraydim > 0) {
403 if (!builtin_arrayinstanceof(params->data[j], c))
407 if (!builtin_instanceof(params->data[j], c))
412 vmargs[i].type = TYPE_ADR;
413 vmargs[i].data.l = (u8) (ptrint) params->data[j];
422 /* *rettype = descr->returntype.decltype; */
427 exceptions_throw_illegalargumentexception();
432 /* _Jv_jni_CallObjectMethod ****************************************************
434 Internal function to call Java Object methods.
436 *******************************************************************************/
438 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
440 methodinfo *m, va_list ap)
443 java_objectheader *ro;
445 STATISTICS(jniinvokation());
448 exceptions_throw_nullpointerexception();
452 /* Class initialization is done by the JIT compiler. This is ok
453 since a static method always belongs to the declaring class. */
455 if (m->flags & ACC_STATIC) {
456 /* For static methods we reset the object. */
461 /* for convenience */
466 /* For instance methods we make a virtual function table lookup. */
468 resm = method_vftbl_lookup(vftbl, m);
471 STATISTICS(jnicallXmethodnvokation());
473 ro = vm_call_method_valist(resm, o, ap);
479 /* _Jv_jni_CallObjectMethodA ***************************************************
481 Internal function to call Java Object methods.
483 *******************************************************************************/
485 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
487 methodinfo *m, jvalue *args)
490 java_objectheader *ro;
492 STATISTICS(jniinvokation());
495 exceptions_throw_nullpointerexception();
499 /* Class initialization is done by the JIT compiler. This is ok
500 since a static method always belongs to the declaring class. */
502 if (m->flags & ACC_STATIC) {
503 /* For static methods we reset the object. */
508 /* for convenience */
513 /* For instance methods we make a virtual function table lookup. */
515 resm = method_vftbl_lookup(vftbl, m);
518 STATISTICS(jnicallXmethodnvokation());
520 ro = vm_call_method_jvalue(resm, o, args);
526 /* _Jv_jni_CallIntMethod *******************************************************
528 Internal function to call Java integer class methods (boolean,
529 byte, char, short, int).
531 *******************************************************************************/
533 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
534 methodinfo *m, va_list ap)
539 STATISTICS(jniinvokation());
542 exceptions_throw_nullpointerexception();
546 /* Class initialization is done by the JIT compiler. This is ok
547 since a static method always belongs to the declaring class. */
549 if (m->flags & ACC_STATIC) {
550 /* For static methods we reset the object. */
555 /* for convenience */
560 /* For instance methods we make a virtual function table lookup. */
562 resm = method_vftbl_lookup(vftbl, m);
565 STATISTICS(jnicallXmethodnvokation());
567 i = vm_call_method_int_valist(resm, o, ap);
573 /* _Jv_jni_CallIntMethodA ******************************************************
575 Internal function to call Java integer class methods (boolean,
576 byte, char, short, int).
578 *******************************************************************************/
580 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
581 methodinfo *m, jvalue *args)
586 STATISTICS(jniinvokation());
589 exceptions_throw_nullpointerexception();
593 /* Class initialization is done by the JIT compiler. This is ok
594 since a static method always belongs to the declaring class. */
596 if (m->flags & ACC_STATIC) {
597 /* For static methods we reset the object. */
602 /* for convenience */
607 /* For instance methods we make a virtual function table lookup. */
609 resm = method_vftbl_lookup(vftbl, m);
612 STATISTICS(jnicallXmethodnvokation());
614 i = vm_call_method_int_jvalue(resm, o, args);
620 /* _Jv_jni_CallLongMethod ******************************************************
622 Internal function to call Java long methods.
624 *******************************************************************************/
626 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
627 methodinfo *m, va_list ap)
632 STATISTICS(jniinvokation());
635 exceptions_throw_nullpointerexception();
639 /* Class initialization is done by the JIT compiler. This is ok
640 since a static method always belongs to the declaring class. */
642 if (m->flags & ACC_STATIC) {
643 /* For static methods we reset the object. */
648 /* for convenience */
653 /* For instance methods we make a virtual function table lookup. */
655 resm = method_vftbl_lookup(vftbl, m);
658 STATISTICS(jnicallXmethodnvokation());
660 l = vm_call_method_long_valist(resm, o, ap);
666 /* _Jv_jni_CallFloatMethod *****************************************************
668 Internal function to call Java float methods.
670 *******************************************************************************/
672 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
673 methodinfo *m, va_list ap)
678 /* Class initialization is done by the JIT compiler. This is ok
679 since a static method always belongs to the declaring class. */
681 if (m->flags & ACC_STATIC) {
682 /* For static methods we reset the object. */
687 /* for convenience */
692 /* For instance methods we make a virtual function table lookup. */
694 resm = method_vftbl_lookup(vftbl, m);
697 STATISTICS(jnicallXmethodnvokation());
699 f = vm_call_method_float_valist(resm, o, ap);
705 /* _Jv_jni_CallDoubleMethod ****************************************************
707 Internal function to call Java double methods.
709 *******************************************************************************/
711 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
712 methodinfo *m, va_list ap)
717 /* Class initialization is done by the JIT compiler. This is ok
718 since a static method always belongs to the declaring class. */
720 if (m->flags & ACC_STATIC) {
721 /* For static methods we reset the object. */
726 /* for convenience */
731 /* For instance methods we make a virtual function table lookup. */
733 resm = method_vftbl_lookup(vftbl, m);
736 d = vm_call_method_double_valist(resm, o, ap);
742 /* _Jv_jni_CallVoidMethod ******************************************************
744 Internal function to call Java void methods.
746 *******************************************************************************/
748 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
749 methodinfo *m, va_list ap)
754 exceptions_throw_nullpointerexception();
758 /* Class initialization is done by the JIT compiler. This is ok
759 since a static method always belongs to the declaring class. */
761 if (m->flags & ACC_STATIC) {
762 /* For static methods we reset the object. */
767 /* for convenience */
772 /* For instance methods we make a virtual function table lookup. */
774 resm = method_vftbl_lookup(vftbl, m);
777 STATISTICS(jnicallXmethodnvokation());
779 (void) vm_call_method_valist(resm, o, ap);
783 /* _Jv_jni_CallVoidMethodA *****************************************************
785 Internal function to call Java void methods.
787 *******************************************************************************/
789 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
790 methodinfo *m, jvalue *args)
795 exceptions_throw_nullpointerexception();
799 /* Class initialization is done by the JIT compiler. This is ok
800 since a static method always belongs to the declaring class. */
802 if (m->flags & ACC_STATIC) {
803 /* For static methods we reset the object. */
808 /* for convenience */
813 /* For instance methods we make a virtual function table lookup. */
815 resm = method_vftbl_lookup(vftbl, m);
818 STATISTICS(jnicallXmethodnvokation());
820 (void) vm_call_method_jvalue(resm, o, args);
824 /* _Jv_jni_invokeNative ********************************************************
826 Invoke a method on the given object with the given arguments.
828 For instance methods OBJ must be != NULL and the method is looked up
829 in the vftbl of the object.
831 For static methods, OBJ is ignored.
833 *******************************************************************************/
835 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
836 java_objectarray *params)
840 java_objectheader *ro;
843 java_objectheader *xptr;
846 exceptions_throw_nullpointerexception();
850 argcount = m->parseddesc->paramcount;
851 paramcount = argcount;
853 /* if method is non-static, remove the `this' pointer */
855 if (!(m->flags & ACC_STATIC))
858 /* For instance methods the object has to be an instance of the
859 class the method belongs to. For static methods the obj
860 parameter is ignored. */
862 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
863 exceptions_throw_illegalargumentexception();
867 /* check if we got the right number of arguments */
869 if (((params == NULL) && (paramcount != 0)) ||
870 (params && (params->header.size != paramcount)))
872 exceptions_throw_illegalargumentexception();
876 /* for instance methods we need an object */
878 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
879 /* XXX not sure if that is the correct exception */
880 exceptions_throw_nullpointerexception();
884 /* for static methods, zero object to make subsequent code simpler */
885 if (m->flags & ACC_STATIC)
889 /* for instance methods we must do a vftbl lookup */
890 resm = method_vftbl_lookup(o->vftbl, m);
893 /* for static methods, just for convenience */
897 vmargs = MNEW(vm_arg, argcount);
899 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
900 MFREE(vmargs, vm_arg, argcount);
904 switch (resm->parseddesc->returntype.decltype) {
906 (void) vm_call_method_vmarg(resm, argcount, vmargs);
911 case PRIMITIVETYPE_BOOLEAN: {
913 java_lang_Boolean *bo;
915 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
917 ro = builtin_new(class_java_lang_Boolean);
919 /* setting the value of the object direct */
921 bo = (java_lang_Boolean *) ro;
926 case PRIMITIVETYPE_BYTE: {
930 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
932 ro = builtin_new(class_java_lang_Byte);
934 /* setting the value of the object direct */
936 bo = (java_lang_Byte *) ro;
941 case PRIMITIVETYPE_CHAR: {
943 java_lang_Character *co;
945 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
947 ro = builtin_new(class_java_lang_Character);
949 /* setting the value of the object direct */
951 co = (java_lang_Character *) ro;
956 case PRIMITIVETYPE_SHORT: {
960 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
962 ro = builtin_new(class_java_lang_Short);
964 /* setting the value of the object direct */
966 so = (java_lang_Short *) ro;
971 case PRIMITIVETYPE_INT: {
973 java_lang_Integer *io;
975 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
977 ro = builtin_new(class_java_lang_Integer);
979 /* setting the value of the object direct */
981 io = (java_lang_Integer *) ro;
986 case PRIMITIVETYPE_LONG: {
990 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
992 ro = builtin_new(class_java_lang_Long);
994 /* setting the value of the object direct */
996 lo = (java_lang_Long *) ro;
1001 case PRIMITIVETYPE_FLOAT: {
1003 java_lang_Float *fo;
1005 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1007 ro = builtin_new(class_java_lang_Float);
1009 /* setting the value of the object direct */
1011 fo = (java_lang_Float *) ro;
1016 case PRIMITIVETYPE_DOUBLE: {
1018 java_lang_Double *_do;
1020 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1022 ro = builtin_new(class_java_lang_Double);
1024 /* setting the value of the object direct */
1026 _do = (java_lang_Double *) ro;
1032 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1036 /* if this happens the exception has already been set by
1037 fill_callblock_from_objectarray */
1039 MFREE(vmargs, vm_arg, argcount);
1044 MFREE(vmargs, vm_arg, argcount);
1046 xptr = exceptions_get_exception();
1049 /* clear exception pointer, we are calling JIT code again */
1051 exceptions_clear_exception();
1053 exceptions_throw_invocationtargetexception(xptr);
1060 /* GetVersion ******************************************************************
1062 Returns the major version number in the higher 16 bits and the
1063 minor version number in the lower 16 bits.
1065 *******************************************************************************/
1067 jint _Jv_JNI_GetVersion(JNIEnv *env)
1069 STATISTICS(jniinvokation());
1071 /* we support JNI 1.4 */
1073 return JNI_VERSION_1_4;
1077 /* Class Operations ***********************************************************/
1079 /* DefineClass *****************************************************************
1081 Loads a class from a buffer of raw class data. The buffer
1082 containing the raw class data is not referenced by the VM after the
1083 DefineClass call returns, and it may be discarded if desired.
1085 *******************************************************************************/
1087 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1088 const jbyte *buf, jsize bufLen)
1090 #if defined(ENABLE_JAVASE)
1091 java_lang_ClassLoader *cl;
1092 java_lang_String *s;
1096 STATISTICS(jniinvokation());
1098 cl = (java_lang_ClassLoader *) loader;
1099 s = (java_lang_String *) javastring_new_from_utf_string(name);
1100 ba = (java_bytearray *) buf;
1102 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1105 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1107 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1109 /* keep compiler happy */
1116 /* FindClass *******************************************************************
1118 This function loads a locally-defined class. It searches the
1119 directories and zip files specified by the CLASSPATH environment
1120 variable for the class with the specified name.
1122 *******************************************************************************/
1124 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1126 #if defined(ENABLE_JAVASE)
1131 STATISTICS(jniinvokation());
1133 u = utf_new_char_classname((char *) name);
1135 /* Check stacktrace for classloader, if one found use it,
1136 otherwise use the system classloader. */
1138 /* Quote from the JNI documentation:
1140 In the Java 2 Platform, FindClass locates the class loader
1141 associated with the current native method. If the native code
1142 belongs to a system class, no class loader will be
1143 involved. Otherwise, the proper class loader will be invoked to
1144 load and link the named class. When FindClass is called through
1145 the Invocation Interface, there is no current native method or
1146 its associated class loader. In that case, the result of
1147 ClassLoader.getBaseClassLoader is used." */
1149 cc = stacktrace_getCurrentClass();
1152 c = load_class_from_sysloader(u);
1154 c = load_class_from_classloader(u, cc->classloader);
1162 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1164 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1166 /* keep compiler happy */
1173 /* GetSuperclass ***************************************************************
1175 If clazz represents any class other than the class Object, then
1176 this function returns the object that represents the superclass of
1177 the class specified by clazz.
1179 *******************************************************************************/
1181 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1185 STATISTICS(jniinvokation());
1187 c = ((classinfo *) sub)->super.cls;
1192 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1196 /* IsAssignableFrom ************************************************************
1198 Determines whether an object of sub can be safely cast to sup.
1200 *******************************************************************************/
1202 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1204 java_lang_Class *csup;
1205 java_lang_Class *csub;
1207 csup = (java_lang_Class *) sup;
1208 csub = (java_lang_Class *) sub;
1210 STATISTICS(jniinvokation());
1212 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1216 /* Throw ***********************************************************************
1218 Causes a java.lang.Throwable object to be thrown.
1220 *******************************************************************************/
1222 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1224 java_objectheader *o;
1226 STATISTICS(jniinvokation());
1228 o = (java_objectheader *) obj;
1230 exceptions_set_exception(o);
1236 /* ThrowNew ********************************************************************
1238 Constructs an exception object from the specified class with the
1239 message specified by message and causes that exception to be
1242 *******************************************************************************/
1244 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1247 java_objectheader *o;
1248 java_objectheader *s;
1250 STATISTICS(jniinvokation());
1252 c = (classinfo *) clazz;
1253 s = javastring_new_from_utf_string(msg);
1255 /* instantiate exception object */
1257 o = native_new_and_init_string(c, s);
1262 exceptions_set_exception(o);
1268 /* ExceptionOccurred ***********************************************************
1270 Determines if an exception is being thrown. The exception stays
1271 being thrown until either the native code calls ExceptionClear(),
1272 or the Java code handles the exception.
1274 *******************************************************************************/
1276 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1278 java_objectheader *o;
1280 STATISTICS(jniinvokation());
1282 o = exceptions_get_exception();
1284 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1288 /* ExceptionDescribe ***********************************************************
1290 Prints an exception and a backtrace of the stack to a system
1291 error-reporting channel, such as stderr. This is a convenience
1292 routine provided for debugging.
1294 *******************************************************************************/
1296 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1298 java_objectheader *o;
1301 STATISTICS(jniinvokation());
1303 o = exceptions_get_exception();
1306 /* clear exception, because we are calling jit code again */
1308 exceptions_clear_exception();
1310 /* get printStackTrace method from exception class */
1312 m = class_resolveclassmethod(o->vftbl->class,
1313 utf_printStackTrace,
1319 /* XXX what should we do? */
1322 /* print the stacktrace */
1324 (void) vm_call_method(m, o);
1329 /* ExceptionClear **************************************************************
1331 Clears any exception that is currently being thrown. If no
1332 exception is currently being thrown, this routine has no effect.
1334 *******************************************************************************/
1336 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1338 STATISTICS(jniinvokation());
1340 exceptions_clear_exception();
1344 /* FatalError ******************************************************************
1346 Raises a fatal error and does not expect the VM to recover. This
1347 function does not return.
1349 *******************************************************************************/
1351 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1353 STATISTICS(jniinvokation());
1355 /* this seems to be the best way */
1361 /* PushLocalFrame **************************************************************
1363 Creates a new local reference frame, in which at least a given
1364 number of local references can be created.
1366 *******************************************************************************/
1368 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1371 localref_table *lrt;
1372 localref_table *nlrt;
1374 STATISTICS(jniinvokation());
1379 /* Allocate new local reference table on Java heap. Calculate the
1380 additional memory we have to allocate. */
1382 if (capacity > LOCALREFTABLE_CAPACITY)
1383 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1387 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1392 /* get current local reference table from thread */
1394 lrt = LOCALREFTABLE;
1396 /* Set up the new local reference table and add it to the local
1399 nlrt->capacity = capacity;
1401 nlrt->localframes = lrt->localframes + 1;
1404 /* store new local reference table in thread */
1406 LOCALREFTABLE = nlrt;
1412 /* PopLocalFrame ***************************************************************
1414 Pops off the current local reference frame, frees all the local
1415 references, and returns a local reference in the previous local
1416 reference frame for the given result object.
1418 *******************************************************************************/
1420 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1422 localref_table *lrt;
1423 localref_table *plrt;
1426 STATISTICS(jniinvokation());
1428 /* get current local reference table from thread */
1430 lrt = LOCALREFTABLE;
1432 localframes = lrt->localframes;
1434 /* Don't delete the top local frame, as this one is allocated in
1435 the native stub on the stack and is freed automagically on
1438 if (localframes == 1)
1439 return _Jv_JNI_NewLocalRef(env, result);
1441 /* release all current local frames */
1443 for (; localframes >= 1; localframes--) {
1444 /* get previous frame */
1448 /* clear all reference entries */
1450 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1454 /* set new local references table */
1459 /* store new local reference table in thread */
1461 LOCALREFTABLE = lrt;
1463 /* add local reference and return the value */
1465 return _Jv_JNI_NewLocalRef(env, result);
1469 /* DeleteLocalRef **************************************************************
1471 Deletes the local reference pointed to by localRef.
1473 *******************************************************************************/
1475 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1477 java_objectheader *o;
1478 localref_table *lrt;
1481 STATISTICS(jniinvokation());
1483 o = (java_objectheader *) localRef;
1485 /* get local reference table (thread specific) */
1487 lrt = LOCALREFTABLE;
1489 /* go through all local frames */
1491 for (; lrt != NULL; lrt = lrt->prev) {
1493 /* and try to remove the reference */
1495 for (i = 0; i < lrt->capacity; i++) {
1496 if (lrt->refs[i] == o) {
1497 lrt->refs[i] = NULL;
1505 /* this should not happen */
1507 /* if (opt_checkjni) */
1508 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1509 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1513 /* IsSameObject ****************************************************************
1515 Tests whether two references refer to the same Java object.
1517 *******************************************************************************/
1519 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1521 STATISTICS(jniinvokation());
1530 /* NewLocalRef *****************************************************************
1532 Creates a new local reference that refers to the same object as ref.
1534 *******************************************************************************/
1536 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1538 localref_table *lrt;
1541 STATISTICS(jniinvokation());
1546 /* get local reference table (thread specific) */
1548 lrt = LOCALREFTABLE;
1550 /* Check if we have space for the requested reference? No,
1551 allocate a new frame. This is actually not what the spec says,
1552 but for compatibility reasons... */
1554 if (lrt->used == lrt->capacity) {
1555 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1558 /* get the new local reference table */
1560 lrt = LOCALREFTABLE;
1563 /* insert the reference */
1565 for (i = 0; i < lrt->capacity; i++) {
1566 if (lrt->refs[i] == NULL) {
1567 lrt->refs[i] = (java_objectheader *) ref;
1574 /* should not happen, just to be sure */
1578 /* keep compiler happy */
1584 /* EnsureLocalCapacity *********************************************************
1586 Ensures that at least a given number of local references can be
1587 created in the current thread
1589 *******************************************************************************/
1591 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1593 localref_table *lrt;
1595 STATISTICS(jniinvokation());
1597 /* get local reference table (thread specific) */
1599 lrt = LOCALREFTABLE;
1601 /* check if capacity elements are available in the local references table */
1603 if ((lrt->used + capacity) > lrt->capacity)
1604 return _Jv_JNI_PushLocalFrame(env, capacity);
1610 /* AllocObject *****************************************************************
1612 Allocates a new Java object without invoking any of the
1613 constructors for the object. Returns a reference to the object.
1615 *******************************************************************************/
1617 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1620 java_objectheader *o;
1622 STATISTICS(jniinvokation());
1624 c = (classinfo *) clazz;
1626 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1627 exceptions_throw_instantiationexception(c);
1633 return _Jv_JNI_NewLocalRef(env, o);
1637 /* NewObject *******************************************************************
1639 Programmers place all arguments that are to be passed to the
1640 constructor immediately following the methodID
1641 argument. NewObject() accepts these arguments and passes them to
1642 the Java method that the programmer wishes to invoke.
1644 *******************************************************************************/
1646 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1648 java_objectheader *o;
1652 STATISTICS(jniinvokation());
1654 m = (methodinfo *) methodID;
1658 o = builtin_new(clazz);
1663 /* call constructor */
1665 va_start(ap, methodID);
1666 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1669 return _Jv_JNI_NewLocalRef(env, o);
1673 /* NewObjectV ******************************************************************
1675 Programmers place all arguments that are to be passed to the
1676 constructor in an args argument of type va_list that immediately
1677 follows the methodID argument. NewObjectV() accepts these
1678 arguments, and, in turn, passes them to the Java method that the
1679 programmer wishes to invoke.
1681 *******************************************************************************/
1683 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1686 java_objectheader *o;
1689 STATISTICS(jniinvokation());
1691 m = (methodinfo *) methodID;
1695 o = builtin_new(clazz);
1700 /* call constructor */
1702 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1704 return _Jv_JNI_NewLocalRef(env, o);
1708 /* NewObjectA *****************************************************************
1710 Programmers place all arguments that are to be passed to the
1711 constructor in an args array of jvalues that immediately follows
1712 the methodID argument. NewObjectA() accepts the arguments in this
1713 array, and, in turn, passes them to the Java method that the
1714 programmer wishes to invoke.
1716 *******************************************************************************/
1718 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1721 java_objectheader *o;
1724 STATISTICS(jniinvokation());
1726 m = (methodinfo *) methodID;
1730 o = builtin_new(clazz);
1735 /* call constructor */
1737 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1739 return _Jv_JNI_NewLocalRef(env, o);
1743 /* GetObjectClass **************************************************************
1745 Returns the class of an object.
1747 *******************************************************************************/
1749 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1751 java_objectheader *o;
1754 STATISTICS(jniinvokation());
1756 o = (java_objectheader *) obj;
1758 if ((o == NULL) || (o->vftbl == NULL))
1761 c = o->vftbl->class;
1763 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1767 /* IsInstanceOf ****************************************************************
1769 Tests whether an object is an instance of a class.
1771 *******************************************************************************/
1773 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1776 java_lang_Object *o;
1778 STATISTICS(jniinvokation());
1780 c = (java_lang_Class *) clazz;
1781 o = (java_lang_Object *) obj;
1783 return _Jv_java_lang_Class_isInstance(c, o);
1787 /* Reflection Support *********************************************************/
1789 /* FromReflectedMethod *********************************************************
1791 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1792 object to a method ID.
1794 *******************************************************************************/
1796 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1798 #if defined(ENABLE_JAVASE)
1803 STATISTICS(jniinvokation());
1808 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1809 java_lang_reflect_Method *rm;
1811 rm = (java_lang_reflect_Method *) method;
1812 c = (classinfo *) (rm->declaringClass);
1815 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1816 java_lang_reflect_Constructor *rc;
1818 rc = (java_lang_reflect_Constructor *) method;
1819 c = (classinfo *) (rc->clazz);
1825 mi = &(c->methods[slot]);
1827 return (jmethodID) mi;
1829 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1831 /* keep compiler happy */
1838 /* FromReflectedField **********************************************************
1840 Converts a java.lang.reflect.Field to a field ID.
1842 *******************************************************************************/
1844 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1846 #if defined(ENABLE_JAVASE)
1847 java_lang_reflect_Field *rf;
1851 STATISTICS(jniinvokation());
1853 rf = (java_lang_reflect_Field *) field;
1858 c = (classinfo *) rf->declaringClass;
1860 f = &(c->fields[rf->slot]);
1862 return (jfieldID) f;
1864 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1866 /* keep compiler happy */
1873 /* ToReflectedMethod ***********************************************************
1875 Converts a method ID derived from cls to an instance of the
1876 java.lang.reflect.Method class or to an instance of the
1877 java.lang.reflect.Constructor class.
1879 *******************************************************************************/
1881 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1884 STATISTICS(jniinvokation());
1886 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1892 /* ToReflectedField ************************************************************
1894 Converts a field ID derived from cls to an instance of the
1895 java.lang.reflect.Field class.
1897 *******************************************************************************/
1899 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1902 STATISTICS(jniinvokation());
1904 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1910 /* Calling Instance Methods ***************************************************/
1912 /* GetMethodID *****************************************************************
1914 Returns the method ID for an instance (nonstatic) method of a class
1915 or interface. The method may be defined in one of the clazz's
1916 superclasses and inherited by clazz. The method is determined by
1917 its name and signature.
1919 GetMethodID() causes an uninitialized class to be initialized.
1921 *******************************************************************************/
1923 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1931 STATISTICS(jniinvokation());
1933 c = (classinfo *) clazz;
1938 if (!(c->state & CLASS_INITIALIZED))
1939 if (!initialize_class(c))
1942 /* try to get the method of the class or one of it's superclasses */
1944 uname = utf_new_char((char *) name);
1945 udesc = utf_new_char((char *) sig);
1947 m = class_resolvemethod(clazz, uname, udesc);
1949 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1950 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1955 return (jmethodID) m;
1959 /* JNI-functions for calling instance methods *********************************/
1961 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1964 java_objectheader *o;
1966 java_objectheader *ret;
1969 o = (java_objectheader *) obj;
1970 m = (methodinfo *) methodID;
1972 va_start(ap, methodID);
1973 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1976 return _Jv_JNI_NewLocalRef(env, ret);
1980 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1983 java_objectheader *o;
1985 java_objectheader *ret;
1987 o = (java_objectheader *) obj;
1988 m = (methodinfo *) methodID;
1990 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1992 return _Jv_JNI_NewLocalRef(env, ret);
1996 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1999 java_objectheader *o;
2001 java_objectheader *ret;
2003 o = (java_objectheader *) obj;
2004 m = (methodinfo *) methodID;
2006 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2008 return _Jv_JNI_NewLocalRef(env, ret);
2012 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2015 java_objectheader *o;
2020 o = (java_objectheader *) obj;
2021 m = (methodinfo *) methodID;
2023 va_start(ap, methodID);
2024 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2031 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2032 jmethodID methodID, va_list args)
2034 java_objectheader *o;
2038 o = (java_objectheader *) obj;
2039 m = (methodinfo *) methodID;
2041 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2047 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2048 jmethodID methodID, jvalue *args)
2050 java_objectheader *o;
2054 o = (java_objectheader *) obj;
2055 m = (methodinfo *) methodID;
2057 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2063 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2065 java_objectheader *o;
2070 o = (java_objectheader *) obj;
2071 m = (methodinfo *) methodID;
2073 va_start(ap, methodID);
2074 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2082 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2085 java_objectheader *o;
2089 o = (java_objectheader *) obj;
2090 m = (methodinfo *) methodID;
2092 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2098 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2101 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2107 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2109 java_objectheader *o;
2114 o = (java_objectheader *) obj;
2115 m = (methodinfo *) methodID;
2117 va_start(ap, methodID);
2118 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2125 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2128 java_objectheader *o;
2132 o = (java_objectheader *) obj;
2133 m = (methodinfo *) methodID;
2135 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2141 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2144 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2150 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2153 java_objectheader *o;
2158 o = (java_objectheader *) obj;
2159 m = (methodinfo *) methodID;
2161 va_start(ap, methodID);
2162 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2169 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2172 java_objectheader *o;
2176 o = (java_objectheader *) obj;
2177 m = (methodinfo *) methodID;
2179 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2185 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2188 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2195 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2197 java_objectheader *o;
2202 o = (java_objectheader *) obj;
2203 m = (methodinfo *) methodID;
2205 va_start(ap, methodID);
2206 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2213 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2216 java_objectheader *o;
2220 o = (java_objectheader *) obj;
2221 m = (methodinfo *) methodID;
2223 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2229 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2232 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2239 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2241 java_objectheader *o;
2246 o = (java_objectheader *) obj;
2247 m = (methodinfo *) methodID;
2249 va_start(ap, methodID);
2250 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2257 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2260 java_objectheader *o;
2264 o = (java_objectheader *) obj;
2265 m = (methodinfo *) methodID;
2267 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2273 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2276 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2283 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2286 java_objectheader *o;
2291 o = (java_objectheader *) obj;
2292 m = (methodinfo *) methodID;
2294 va_start(ap, methodID);
2295 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2302 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2305 java_objectheader *o;
2309 o = (java_objectheader *) obj;
2310 m = (methodinfo *) methodID;
2312 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2318 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2321 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2328 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2331 java_objectheader *o;
2336 o = (java_objectheader *) obj;
2337 m = (methodinfo *) methodID;
2339 va_start(ap, methodID);
2340 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2347 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2350 java_objectheader *o;
2354 o = (java_objectheader *) obj;
2355 m = (methodinfo *) methodID;
2357 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2363 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2366 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2373 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2375 java_objectheader *o;
2379 o = (java_objectheader *) obj;
2380 m = (methodinfo *) methodID;
2382 va_start(ap, methodID);
2383 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2388 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2391 java_objectheader *o;
2394 o = (java_objectheader *) obj;
2395 m = (methodinfo *) methodID;
2397 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2401 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2404 java_objectheader *o;
2407 o = (java_objectheader *) obj;
2408 m = (methodinfo *) methodID;
2410 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2415 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2416 jclass clazz, jmethodID methodID,
2419 java_objectheader *o;
2422 java_objectheader *r;
2425 o = (java_objectheader *) obj;
2426 c = (classinfo *) clazz;
2427 m = (methodinfo *) methodID;
2429 va_start(ap, methodID);
2430 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2433 return _Jv_JNI_NewLocalRef(env, r);
2437 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2438 jclass clazz, jmethodID methodID,
2441 java_objectheader *o;
2444 java_objectheader *r;
2446 o = (java_objectheader *) obj;
2447 c = (classinfo *) clazz;
2448 m = (methodinfo *) methodID;
2450 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2452 return _Jv_JNI_NewLocalRef(env, r);
2456 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2457 jclass clazz, jmethodID methodID,
2460 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2462 return _Jv_JNI_NewLocalRef(env, NULL);
2467 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2468 jclass clazz, jmethodID methodID,
2471 java_objectheader *o;
2477 o = (java_objectheader *) obj;
2478 c = (classinfo *) clazz;
2479 m = (methodinfo *) methodID;
2481 va_start(ap, methodID);
2482 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2489 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2490 jclass clazz, jmethodID methodID,
2493 java_objectheader *o;
2498 o = (java_objectheader *) obj;
2499 c = (classinfo *) clazz;
2500 m = (methodinfo *) methodID;
2502 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2508 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2509 jclass clazz, jmethodID methodID,
2512 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2518 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2519 jmethodID methodID, ...)
2521 java_objectheader *o;
2527 o = (java_objectheader *) obj;
2528 c = (classinfo *) clazz;
2529 m = (methodinfo *) methodID;
2531 va_start(ap, methodID);
2532 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2539 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2540 jmethodID methodID, va_list args)
2542 java_objectheader *o;
2547 o = (java_objectheader *) obj;
2548 c = (classinfo *) clazz;
2549 m = (methodinfo *) methodID;
2551 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2557 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2558 jmethodID methodID, jvalue *args)
2560 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2567 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2568 jmethodID methodID, ...)
2570 java_objectheader *o;
2576 o = (java_objectheader *) obj;
2577 c = (classinfo *) clazz;
2578 m = (methodinfo *) methodID;
2580 va_start(ap, methodID);
2581 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2588 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2589 jmethodID methodID, va_list args)
2591 java_objectheader *o;
2596 o = (java_objectheader *) obj;
2597 c = (classinfo *) clazz;
2598 m = (methodinfo *) methodID;
2600 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2606 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2607 jmethodID methodID, jvalue *args)
2609 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2616 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2617 jclass clazz, jmethodID methodID, ...)
2619 java_objectheader *o;
2625 o = (java_objectheader *) obj;
2626 c = (classinfo *) clazz;
2627 m = (methodinfo *) methodID;
2629 va_start(ap, methodID);
2630 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2637 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2638 jclass clazz, jmethodID methodID,
2641 java_objectheader *o;
2646 o = (java_objectheader *) obj;
2647 c = (classinfo *) clazz;
2648 m = (methodinfo *) methodID;
2650 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2656 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2657 jclass clazz, jmethodID methodID,
2660 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2667 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2668 jmethodID methodID, ...)
2670 java_objectheader *o;
2676 o = (java_objectheader *) obj;
2677 c = (classinfo *) clazz;
2678 m = (methodinfo *) methodID;
2680 va_start(ap, methodID);
2681 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2688 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2689 jmethodID methodID, va_list args)
2691 java_objectheader *o;
2696 o = (java_objectheader *) obj;
2697 c = (classinfo *) clazz;
2698 m = (methodinfo *) methodID;
2700 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2706 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2707 jmethodID methodID, jvalue *args)
2709 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2716 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2717 jmethodID methodID, ...)
2719 java_objectheader *o;
2725 o = (java_objectheader *) obj;
2726 c = (classinfo *) clazz;
2727 m = (methodinfo *) methodID;
2729 va_start(ap, methodID);
2730 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2737 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2738 jmethodID methodID, va_list args)
2740 java_objectheader *o;
2745 o = (java_objectheader *) obj;
2746 c = (classinfo *) clazz;
2747 m = (methodinfo *) methodID;
2749 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2755 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2756 jmethodID methodID, jvalue *args)
2758 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2765 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2766 jclass clazz, jmethodID methodID, ...)
2768 java_objectheader *o;
2774 o = (java_objectheader *) obj;
2775 c = (classinfo *) clazz;
2776 m = (methodinfo *) methodID;
2778 va_start(ap, methodID);
2779 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2786 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2787 jclass clazz, jmethodID methodID,
2790 java_objectheader *o;
2795 o = (java_objectheader *) obj;
2796 c = (classinfo *) clazz;
2797 m = (methodinfo *) methodID;
2799 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2805 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2806 jclass clazz, jmethodID methodID,
2809 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2816 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2817 jclass clazz, jmethodID methodID,
2820 java_objectheader *o;
2826 o = (java_objectheader *) obj;
2827 c = (classinfo *) clazz;
2828 m = (methodinfo *) methodID;
2830 va_start(ap, methodID);
2831 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2838 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2839 jclass clazz, jmethodID methodID,
2842 java_objectheader *o;
2847 o = (java_objectheader *) obj;
2848 c = (classinfo *) clazz;
2849 m = (methodinfo *) methodID;
2851 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2857 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2858 jclass clazz, jmethodID methodID,
2861 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2868 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2869 jmethodID methodID, ...)
2871 java_objectheader *o;
2876 o = (java_objectheader *) obj;
2877 c = (classinfo *) clazz;
2878 m = (methodinfo *) methodID;
2880 va_start(ap, methodID);
2881 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2886 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2887 jmethodID methodID, va_list args)
2889 java_objectheader *o;
2893 o = (java_objectheader *) obj;
2894 c = (classinfo *) clazz;
2895 m = (methodinfo *) methodID;
2897 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2901 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2902 jmethodID methodID, jvalue * args)
2904 java_objectheader *o;
2908 o = (java_objectheader *) obj;
2909 c = (classinfo *) clazz;
2910 m = (methodinfo *) methodID;
2912 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2916 /* Accessing Fields of Objects ************************************************/
2918 /* GetFieldID ******************************************************************
2920 Returns the field ID for an instance (nonstatic) field of a
2921 class. The field is specified by its name and signature. The
2922 Get<type>Field and Set<type>Field families of accessor functions
2923 use field IDs to retrieve object fields.
2925 *******************************************************************************/
2927 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2935 STATISTICS(jniinvokation());
2937 c = (classinfo *) clazz;
2939 uname = utf_new_char((char *) name);
2940 udesc = utf_new_char((char *) sig);
2942 f = class_findfield(clazz, uname, udesc);
2945 exceptions_throw_nosuchfielderror(c, uname);
2947 return (jfieldID) f;
2951 /* Get<type>Field Routines *****************************************************
2953 This family of accessor routines returns the value of an instance
2954 (nonstatic) field of an object. The field to access is specified by
2955 a field ID obtained by calling GetFieldID().
2957 *******************************************************************************/
2959 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2961 java_objectheader *o;
2963 STATISTICS(jniinvokation());
2965 o = GET_FIELD(obj, java_objectheader*, fieldID);
2967 return _Jv_JNI_NewLocalRef(env, o);
2971 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2975 STATISTICS(jniinvokation());
2977 i = GET_FIELD(obj, s4, fieldID);
2979 return (jboolean) i;
2983 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2987 STATISTICS(jniinvokation());
2989 i = GET_FIELD(obj, s4, fieldID);
2995 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2999 STATISTICS(jniinvokation());
3001 i = GET_FIELD(obj, s4, fieldID);
3007 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3011 STATISTICS(jniinvokation());
3013 i = GET_FIELD(obj, s4, fieldID);
3019 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3021 java_objectheader *o;
3025 STATISTICS(jniinvokation());
3027 o = (java_objectheader *) obj;
3028 f = (fieldinfo *) fieldID;
3030 i = GET_FIELD(o, s4, f);
3036 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3040 STATISTICS(jniinvokation());
3042 l = GET_FIELD(obj, s8, fieldID);
3048 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3052 STATISTICS(jniinvokation());
3054 f = GET_FIELD(obj, float, fieldID);
3060 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3064 STATISTICS(jniinvokation());
3066 d = GET_FIELD(obj, double, fieldID);
3072 /* Set<type>Field Routines *****************************************************
3074 This family of accessor routines sets the value of an instance
3075 (nonstatic) field of an object. The field to access is specified by
3076 a field ID obtained by calling GetFieldID().
3078 *******************************************************************************/
3080 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3083 STATISTICS(jniinvokation());
3085 SET_FIELD(obj, java_objectheader*, fieldID, value);
3089 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3092 STATISTICS(jniinvokation());
3094 SET_FIELD(obj, s4, fieldID, value);
3098 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3101 STATISTICS(jniinvokation());
3103 SET_FIELD(obj, s4, fieldID, value);
3107 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3110 STATISTICS(jniinvokation());
3112 SET_FIELD(obj, s4, fieldID, value);
3116 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3119 STATISTICS(jniinvokation());
3121 SET_FIELD(obj, s4, fieldID, value);
3125 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3127 STATISTICS(jniinvokation());
3129 SET_FIELD(obj, s4, fieldID, value);
3133 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3136 STATISTICS(jniinvokation());
3138 SET_FIELD(obj, s8, fieldID, value);
3142 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3145 STATISTICS(jniinvokation());
3147 SET_FIELD(obj, float, fieldID, value);
3151 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3154 STATISTICS(jniinvokation());
3156 SET_FIELD(obj, double, fieldID, value);
3160 /* Calling Static Methods *****************************************************/
3162 /* GetStaticMethodID ***********************************************************
3164 Returns the method ID for a static method of a class. The method is
3165 specified by its name and signature.
3167 GetStaticMethodID() causes an uninitialized class to be
3170 *******************************************************************************/
3172 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3180 STATISTICS(jniinvokation());
3182 c = (classinfo *) clazz;
3187 if (!(c->state & CLASS_INITIALIZED))
3188 if (!initialize_class(c))
3191 /* try to get the static method of the class */
3193 uname = utf_new_char((char *) name);
3194 udesc = utf_new_char((char *) sig);
3196 m = class_resolvemethod(c, uname, udesc);
3198 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3199 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3204 return (jmethodID) m;
3208 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3209 jmethodID methodID, ...)
3212 java_objectheader *o;
3215 m = (methodinfo *) methodID;
3217 va_start(ap, methodID);
3218 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3221 return _Jv_JNI_NewLocalRef(env, o);
3225 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3226 jmethodID methodID, va_list args)
3229 java_objectheader *o;
3231 m = (methodinfo *) methodID;
3233 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3235 return _Jv_JNI_NewLocalRef(env, o);
3239 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3240 jmethodID methodID, jvalue *args)
3243 java_objectheader *o;
3245 m = (methodinfo *) methodID;
3247 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3249 return _Jv_JNI_NewLocalRef(env, o);
3253 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3254 jmethodID methodID, ...)
3260 m = (methodinfo *) methodID;
3262 va_start(ap, methodID);
3263 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3270 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3271 jmethodID methodID, va_list args)
3276 m = (methodinfo *) methodID;
3278 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3284 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3285 jmethodID methodID, jvalue *args)
3287 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3293 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3294 jmethodID methodID, ...)
3300 m = (methodinfo *) methodID;
3302 va_start(ap, methodID);
3303 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3310 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3311 jmethodID methodID, va_list args)
3316 m = (methodinfo *) methodID;
3318 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3324 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3325 jmethodID methodID, jvalue *args)
3327 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3333 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3334 jmethodID methodID, ...)
3340 m = (methodinfo *) methodID;
3342 va_start(ap, methodID);
3343 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3350 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3351 jmethodID methodID, va_list args)
3356 m = (methodinfo *) methodID;
3358 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3364 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3365 jmethodID methodID, jvalue *args)
3367 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3373 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3374 jmethodID methodID, ...)
3380 m = (methodinfo *) methodID;
3382 va_start(ap, methodID);
3383 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3390 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3391 jmethodID methodID, va_list args)
3396 m = (methodinfo *) methodID;
3398 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3404 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3405 jmethodID methodID, jvalue *args)
3407 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3413 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3420 m = (methodinfo *) methodID;
3422 va_start(ap, methodID);
3423 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3430 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3431 jmethodID methodID, va_list args)
3436 m = (methodinfo *) methodID;
3438 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3444 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3445 jmethodID methodID, jvalue *args)
3447 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3453 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3454 jmethodID methodID, ...)
3460 m = (methodinfo *) methodID;
3462 va_start(ap, methodID);
3463 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3470 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3471 jmethodID methodID, va_list args)
3476 m = (methodinfo *) methodID;
3478 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3484 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3485 jmethodID methodID, jvalue *args)
3487 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3494 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3495 jmethodID methodID, ...)
3501 m = (methodinfo *) methodID;
3503 va_start(ap, methodID);
3504 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3511 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3512 jmethodID methodID, va_list args)
3517 m = (methodinfo *) methodID;
3519 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3525 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3526 jmethodID methodID, jvalue *args)
3528 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3534 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3535 jmethodID methodID, ...)
3541 m = (methodinfo *) methodID;
3543 va_start(ap, methodID);
3544 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3551 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3552 jmethodID methodID, va_list args)
3557 m = (methodinfo *) methodID;
3559 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3565 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3566 jmethodID methodID, jvalue *args)
3568 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3574 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3575 jmethodID methodID, ...)
3580 m = (methodinfo *) methodID;
3582 va_start(ap, methodID);
3583 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3588 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3589 jmethodID methodID, va_list args)
3593 m = (methodinfo *) methodID;
3595 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3599 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3600 jmethodID methodID, jvalue * args)
3604 m = (methodinfo *) methodID;
3606 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3610 /* Accessing Static Fields ****************************************************/
3612 /* GetStaticFieldID ************************************************************
3614 Returns the field ID for a static field of a class. The field is
3615 specified by its name and signature. The GetStatic<type>Field and
3616 SetStatic<type>Field families of accessor functions use field IDs
3617 to retrieve static fields.
3619 *******************************************************************************/
3621 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3629 STATISTICS(jniinvokation());
3631 c = (classinfo *) clazz;
3633 uname = utf_new_char((char *) name);
3634 usig = utf_new_char((char *) sig);
3636 f = class_findfield(clazz, uname, usig);
3639 exceptions_throw_nosuchfielderror(c, uname);
3641 return (jfieldID) f;
3645 /* GetStatic<type>Field ********************************************************
3647 This family of accessor routines returns the value of a static
3650 *******************************************************************************/
3652 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3658 STATISTICS(jniinvokation());
3660 c = (classinfo *) clazz;
3661 f = (fieldinfo *) fieldID;
3663 if (!(c->state & CLASS_INITIALIZED))
3664 if (!initialize_class(c))
3667 return _Jv_JNI_NewLocalRef(env, f->value.a);
3671 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3677 STATISTICS(jniinvokation());
3679 c = (classinfo *) clazz;
3680 f = (fieldinfo *) fieldID;
3682 if (!(c->state & CLASS_INITIALIZED))
3683 if (!initialize_class(c))
3690 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3695 STATISTICS(jniinvokation());
3697 c = (classinfo *) clazz;
3698 f = (fieldinfo *) fieldID;
3700 if (!(c->state & CLASS_INITIALIZED))
3701 if (!initialize_class(c))
3708 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3713 STATISTICS(jniinvokation());
3715 c = (classinfo *) clazz;
3716 f = (fieldinfo *) fieldID;
3718 if (!(c->state & CLASS_INITIALIZED))
3719 if (!initialize_class(c))
3726 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3731 STATISTICS(jniinvokation());
3733 c = (classinfo *) clazz;
3734 f = (fieldinfo *) fieldID;
3736 if (!(c->state & CLASS_INITIALIZED))
3737 if (!initialize_class(c))
3744 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3749 STATISTICS(jniinvokation());
3751 c = (classinfo *) clazz;
3752 f = (fieldinfo *) fieldID;
3754 if (!(c->state & CLASS_INITIALIZED))
3755 if (!initialize_class(c))
3762 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3767 STATISTICS(jniinvokation());
3769 c = (classinfo *) clazz;
3770 f = (fieldinfo *) fieldID;
3772 if (!(c->state & CLASS_INITIALIZED))
3773 if (!initialize_class(c))
3780 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3785 STATISTICS(jniinvokation());
3787 c = (classinfo *) clazz;
3788 f = (fieldinfo *) fieldID;
3790 if (!(c->state & CLASS_INITIALIZED))
3791 if (!initialize_class(c))
3798 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3804 STATISTICS(jniinvokation());
3806 c = (classinfo *) clazz;
3807 f = (fieldinfo *) fieldID;
3809 if (!(c->state & CLASS_INITIALIZED))
3810 if (!initialize_class(c))
3817 /* SetStatic<type>Field *******************************************************
3819 This family of accessor routines sets the value of a static field
3822 *******************************************************************************/
3824 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3830 STATISTICS(jniinvokation());
3832 c = (classinfo *) clazz;
3833 f = (fieldinfo *) fieldID;
3835 if (!(c->state & CLASS_INITIALIZED))
3836 if (!initialize_class(c))
3843 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3849 STATISTICS(jniinvokation());
3851 c = (classinfo *) clazz;
3852 f = (fieldinfo *) fieldID;
3854 if (!(c->state & CLASS_INITIALIZED))
3855 if (!initialize_class(c))
3862 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3868 STATISTICS(jniinvokation());
3870 c = (classinfo *) clazz;
3871 f = (fieldinfo *) fieldID;
3873 if (!(c->state & CLASS_INITIALIZED))
3874 if (!initialize_class(c))
3881 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3887 STATISTICS(jniinvokation());
3889 c = (classinfo *) clazz;
3890 f = (fieldinfo *) fieldID;
3892 if (!(c->state & CLASS_INITIALIZED))
3893 if (!initialize_class(c))
3900 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3906 STATISTICS(jniinvokation());
3908 c = (classinfo *) clazz;
3909 f = (fieldinfo *) fieldID;
3911 if (!(c->state & CLASS_INITIALIZED))
3912 if (!initialize_class(c))
3919 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3925 STATISTICS(jniinvokation());
3927 c = (classinfo *) clazz;
3928 f = (fieldinfo *) fieldID;
3930 if (!(c->state & CLASS_INITIALIZED))
3931 if (!initialize_class(c))
3938 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3944 STATISTICS(jniinvokation());
3946 c = (classinfo *) clazz;
3947 f = (fieldinfo *) fieldID;
3949 if (!(c->state & CLASS_INITIALIZED))
3950 if (!initialize_class(c))
3957 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3963 STATISTICS(jniinvokation());
3965 c = (classinfo *) clazz;
3966 f = (fieldinfo *) fieldID;
3968 if (!(c->state & CLASS_INITIALIZED))
3969 if (!initialize_class(c))
3976 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3982 STATISTICS(jniinvokation());
3984 c = (classinfo *) clazz;
3985 f = (fieldinfo *) fieldID;
3987 if (!(c->state & CLASS_INITIALIZED))
3988 if (!initialize_class(c))
3995 /* String Operations **********************************************************/
3997 /* NewString *******************************************************************
3999 Create new java.lang.String object from an array of Unicode
4002 *******************************************************************************/
4004 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4006 java_lang_String *s;
4010 STATISTICS(jniinvokation());
4012 s = (java_lang_String *) builtin_new(class_java_lang_String);
4013 a = builtin_newarray_char(len);
4015 /* javastring or characterarray could not be created */
4016 if ((a == NULL) || (s == NULL))
4020 for (i = 0; i < len; i++)
4021 a->data[i] = buf[i];
4027 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4031 static jchar emptyStringJ[]={0,0};
4033 /* GetStringLength *************************************************************
4035 Returns the length (the count of Unicode characters) of a Java
4038 *******************************************************************************/
4040 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4042 return ((java_lang_String *) str)->count;
4046 /******************** convertes javastring to u2-array ****************************/
4048 u2 *javastring_tou2(jstring so)
4050 java_lang_String *s;
4055 STATISTICS(jniinvokation());
4057 s = (java_lang_String *) so;
4067 /* allocate memory */
4069 stringbuffer = MNEW(u2, s->count + 1);
4073 for (i = 0; i < s->count; i++)
4074 stringbuffer[i] = a->data[s->offset + i];
4076 /* terminate string */
4078 stringbuffer[i] = '\0';
4080 return stringbuffer;
4084 /* GetStringChars **************************************************************
4086 Returns a pointer to the array of Unicode characters of the
4087 string. This pointer is valid until ReleaseStringChars() is called.
4089 *******************************************************************************/
4091 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4095 STATISTICS(jniinvokation());
4097 jc = javastring_tou2(str);
4109 return emptyStringJ;
4113 /* ReleaseStringChars **********************************************************
4115 Informs the VM that the native code no longer needs access to
4116 chars. The chars argument is a pointer obtained from string using
4119 *******************************************************************************/
4121 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4123 STATISTICS(jniinvokation());
4125 if (chars == emptyStringJ)
4128 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4132 /* NewStringUTF ****************************************************************
4134 Constructs a new java.lang.String object from an array of UTF-8
4137 *******************************************************************************/
4139 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4141 java_lang_String *s;
4143 STATISTICS(jniinvokation());
4145 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4147 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4151 /****************** returns the utf8 length in bytes of a string *******************/
4153 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4155 java_lang_String *s = (java_lang_String*) string;
4157 STATISTICS(jniinvokation());
4159 return (jsize) u2_utflength(s->value->data, s->count);
4163 /* GetStringUTFChars ***********************************************************
4165 Returns a pointer to an array of UTF-8 characters of the
4166 string. This array is valid until it is released by
4167 ReleaseStringUTFChars().
4169 *******************************************************************************/
4171 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4176 STATISTICS(jniinvokation());
4184 u = javastring_toutf((java_objectheader *) string, false);
4193 /* ReleaseStringUTFChars *******************************************************
4195 Informs the VM that the native code no longer needs access to
4196 utf. The utf argument is a pointer derived from string using
4197 GetStringUTFChars().
4199 *******************************************************************************/
4201 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4203 STATISTICS(jniinvokation());
4205 /* XXX we don't release utf chars right now, perhaps that should be done
4206 later. Since there is always one reference the garbage collector will
4211 /* Array Operations ***********************************************************/
4213 /* GetArrayLength **************************************************************
4215 Returns the number of elements in the array.
4217 *******************************************************************************/
4219 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4221 java_arrayheader *a;
4223 STATISTICS(jniinvokation());
4225 a = (java_arrayheader *) array;
4231 /* NewObjectArray **************************************************************
4233 Constructs a new array holding objects in class elementClass. All
4234 elements are initially set to initialElement.
4236 *******************************************************************************/
4238 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4239 jclass elementClass, jobject initialElement)
4241 java_objectarray *oa;
4244 STATISTICS(jniinvokation());
4247 exceptions_throw_negativearraysizeexception();
4251 oa = builtin_anewarray(length, elementClass);
4256 /* set all elements to initialElement */
4258 for (i = 0; i < length; i++)
4259 oa->data[i] = initialElement;
4261 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4265 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4268 java_objectarray *oa;
4271 STATISTICS(jniinvokation());
4273 oa = (java_objectarray *) array;
4275 if (index >= oa->header.size) {
4276 exceptions_throw_arrayindexoutofboundsexception();
4280 o = oa->data[index];
4282 return _Jv_JNI_NewLocalRef(env, o);
4286 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4287 jsize index, jobject val)
4289 java_objectarray *oa;
4290 java_objectheader *o;
4292 STATISTICS(jniinvokation());
4294 oa = (java_objectarray *) array;
4295 o = (java_objectheader *) val;
4297 if (index >= oa->header.size) {
4298 exceptions_throw_arrayindexoutofboundsexception();
4302 /* check if the class of value is a subclass of the element class
4305 if (!builtin_canstore(oa, o))
4308 oa->data[index] = val;
4312 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4314 java_booleanarray *ba;
4316 STATISTICS(jniinvokation());
4319 exceptions_throw_negativearraysizeexception();
4323 ba = builtin_newarray_boolean(len);
4325 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4329 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4333 STATISTICS(jniinvokation());
4336 exceptions_throw_negativearraysizeexception();
4340 ba = builtin_newarray_byte(len);
4342 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4346 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4350 STATISTICS(jniinvokation());
4353 exceptions_throw_negativearraysizeexception();
4357 ca = builtin_newarray_char(len);
4359 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4363 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4365 java_shortarray *sa;
4367 STATISTICS(jniinvokation());
4370 exceptions_throw_negativearraysizeexception();
4374 sa = builtin_newarray_short(len);
4376 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4380 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4384 STATISTICS(jniinvokation());
4387 exceptions_throw_negativearraysizeexception();
4391 ia = builtin_newarray_int(len);
4393 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4397 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4401 STATISTICS(jniinvokation());
4404 exceptions_throw_negativearraysizeexception();
4408 la = builtin_newarray_long(len);
4410 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4414 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4416 java_floatarray *fa;
4418 STATISTICS(jniinvokation());
4421 exceptions_throw_negativearraysizeexception();
4425 fa = builtin_newarray_float(len);
4427 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4431 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4433 java_doublearray *da;
4435 STATISTICS(jniinvokation());
4438 exceptions_throw_negativearraysizeexception();
4442 da = builtin_newarray_double(len);
4444 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4448 /* Get<PrimitiveType>ArrayElements *********************************************
4450 A family of functions that returns the body of the primitive array.
4452 *******************************************************************************/
4454 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4457 java_booleanarray *ba;
4459 STATISTICS(jniinvokation());
4461 ba = (java_booleanarray *) array;
4464 *isCopy = JNI_FALSE;
4470 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4475 STATISTICS(jniinvokation());
4477 ba = (java_bytearray *) array;
4480 *isCopy = JNI_FALSE;
4486 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4491 STATISTICS(jniinvokation());
4493 ca = (java_chararray *) array;
4496 *isCopy = JNI_FALSE;
4502 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4505 java_shortarray *sa;
4507 STATISTICS(jniinvokation());
4509 sa = (java_shortarray *) array;
4512 *isCopy = JNI_FALSE;
4518 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4523 STATISTICS(jniinvokation());
4525 ia = (java_intarray *) array;
4528 *isCopy = JNI_FALSE;
4534 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4539 STATISTICS(jniinvokation());
4541 la = (java_longarray *) array;
4544 *isCopy = JNI_FALSE;
4546 /* We cast this one to prevent a compiler warning on 64-bit
4547 systems since GNU Classpath typedef jlong to long long. */
4549 return (jlong *) la->data;
4553 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4556 java_floatarray *fa;
4558 STATISTICS(jniinvokation());
4560 fa = (java_floatarray *) array;
4563 *isCopy = JNI_FALSE;
4569 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4572 java_doublearray *da;
4574 STATISTICS(jniinvokation());
4576 da = (java_doublearray *) array;
4579 *isCopy = JNI_FALSE;
4585 /* Release<PrimitiveType>ArrayElements *****************************************
4587 A family of functions that informs the VM that the native code no
4588 longer needs access to elems. The elems argument is a pointer
4589 derived from array using the corresponding
4590 Get<PrimitiveType>ArrayElements() function. If necessary, this
4591 function copies back all changes made to elems to the original
4594 *******************************************************************************/
4596 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4597 jboolean *elems, jint mode)
4599 java_booleanarray *ba;
4601 STATISTICS(jniinvokation());
4603 ba = (java_booleanarray *) array;
4605 if (elems != ba->data) {
4608 MCOPY(ba->data, elems, u1, ba->header.size);
4611 MCOPY(ba->data, elems, u1, ba->header.size);
4612 /* XXX TWISTI how should it be freed? */
4615 /* XXX TWISTI how should it be freed? */
4622 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4623 jbyte *elems, jint mode)
4627 STATISTICS(jniinvokation());
4629 ba = (java_bytearray *) array;
4631 if (elems != ba->data) {
4634 MCOPY(ba->data, elems, s1, ba->header.size);
4637 MCOPY(ba->data, elems, s1, ba->header.size);
4638 /* XXX TWISTI how should it be freed? */
4641 /* XXX TWISTI how should it be freed? */
4648 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4649 jchar *elems, jint mode)
4653 STATISTICS(jniinvokation());
4655 ca = (java_chararray *) array;
4657 if (elems != ca->data) {
4660 MCOPY(ca->data, elems, u2, ca->header.size);
4663 MCOPY(ca->data, elems, u2, ca->header.size);
4664 /* XXX TWISTI how should it be freed? */
4667 /* XXX TWISTI how should it be freed? */
4674 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4675 jshort *elems, jint mode)
4677 java_shortarray *sa;
4679 STATISTICS(jniinvokation());
4681 sa = (java_shortarray *) array;
4683 if (elems != sa->data) {
4686 MCOPY(sa->data, elems, s2, sa->header.size);
4689 MCOPY(sa->data, elems, s2, sa->header.size);
4690 /* XXX TWISTI how should it be freed? */
4693 /* XXX TWISTI how should it be freed? */
4700 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4705 STATISTICS(jniinvokation());
4707 ia = (java_intarray *) array;
4709 if (elems != ia->data) {
4712 MCOPY(ia->data, elems, s4, ia->header.size);
4715 MCOPY(ia->data, elems, s4, ia->header.size);
4716 /* XXX TWISTI how should it be freed? */
4719 /* XXX TWISTI how should it be freed? */
4726 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4727 jlong *elems, jint mode)
4731 STATISTICS(jniinvokation());
4733 la = (java_longarray *) array;
4735 /* We cast this one to prevent a compiler warning on 64-bit
4736 systems since GNU Classpath typedef jlong to long long. */
4738 if ((s8 *) elems != la->data) {
4741 MCOPY(la->data, elems, s8, la->header.size);
4744 MCOPY(la->data, elems, s8, la->header.size);
4745 /* XXX TWISTI how should it be freed? */
4748 /* XXX TWISTI how should it be freed? */
4755 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4756 jfloat *elems, jint mode)
4758 java_floatarray *fa;
4760 STATISTICS(jniinvokation());
4762 fa = (java_floatarray *) array;
4764 if (elems != fa->data) {
4767 MCOPY(fa->data, elems, float, fa->header.size);
4770 MCOPY(fa->data, elems, float, fa->header.size);
4771 /* XXX TWISTI how should it be freed? */
4774 /* XXX TWISTI how should it be freed? */
4781 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4782 jdouble *elems, jint mode)
4784 java_doublearray *da;
4786 STATISTICS(jniinvokation());
4788 da = (java_doublearray *) array;
4790 if (elems != da->data) {
4793 MCOPY(da->data, elems, double, da->header.size);
4796 MCOPY(da->data, elems, double, da->header.size);
4797 /* XXX TWISTI how should it be freed? */
4800 /* XXX TWISTI how should it be freed? */
4807 /* Get<PrimitiveType>ArrayRegion **********************************************
4809 A family of functions that copies a region of a primitive array
4812 *******************************************************************************/
4814 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4815 jsize start, jsize len, jboolean *buf)
4817 java_booleanarray *ba;
4819 STATISTICS(jniinvokation());
4821 ba = (java_booleanarray *) array;
4823 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4824 exceptions_throw_arrayindexoutofboundsexception();
4826 MCOPY(buf, &ba->data[start], u1, len);
4830 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4831 jsize len, jbyte *buf)
4835 STATISTICS(jniinvokation());
4837 ba = (java_bytearray *) array;
4839 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4840 exceptions_throw_arrayindexoutofboundsexception();
4842 MCOPY(buf, &ba->data[start], s1, len);
4846 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4847 jsize len, jchar *buf)
4851 STATISTICS(jniinvokation());
4853 ca = (java_chararray *) array;
4855 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4856 exceptions_throw_arrayindexoutofboundsexception();
4858 MCOPY(buf, &ca->data[start], u2, len);
4862 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4863 jsize len, jshort *buf)
4865 java_shortarray *sa;
4867 STATISTICS(jniinvokation());
4869 sa = (java_shortarray *) array;
4871 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4872 exceptions_throw_arrayindexoutofboundsexception();
4874 MCOPY(buf, &sa->data[start], s2, len);
4878 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4879 jsize len, jint *buf)
4883 STATISTICS(jniinvokation());
4885 ia = (java_intarray *) array;
4887 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4888 exceptions_throw_arrayindexoutofboundsexception();
4890 MCOPY(buf, &ia->data[start], s4, len);
4894 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4895 jsize len, jlong *buf)
4899 STATISTICS(jniinvokation());
4901 la = (java_longarray *) array;
4903 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4904 exceptions_throw_arrayindexoutofboundsexception();
4906 MCOPY(buf, &la->data[start], s8, len);
4910 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4911 jsize len, jfloat *buf)
4913 java_floatarray *fa;
4915 STATISTICS(jniinvokation());
4917 fa = (java_floatarray *) array;
4919 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4920 exceptions_throw_arrayindexoutofboundsexception();
4922 MCOPY(buf, &fa->data[start], float, len);
4926 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4927 jsize len, jdouble *buf)
4929 java_doublearray *da;
4931 STATISTICS(jniinvokation());
4933 da = (java_doublearray *) array;
4935 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4936 exceptions_throw_arrayindexoutofboundsexception();
4938 MCOPY(buf, &da->data[start], double, len);
4942 /* Set<PrimitiveType>ArrayRegion **********************************************
4944 A family of functions that copies back a region of a primitive
4945 array from a buffer.
4947 *******************************************************************************/
4949 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4950 jsize start, jsize len, jboolean *buf)
4952 java_booleanarray *ba;
4954 STATISTICS(jniinvokation());
4956 ba = (java_booleanarray *) array;
4958 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4959 exceptions_throw_arrayindexoutofboundsexception();
4961 MCOPY(&ba->data[start], buf, u1, len);
4965 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4966 jsize len, jbyte *buf)
4970 STATISTICS(jniinvokation());
4972 ba = (java_bytearray *) array;
4974 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4975 exceptions_throw_arrayindexoutofboundsexception();
4977 MCOPY(&ba->data[start], buf, s1, len);
4981 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4982 jsize len, jchar *buf)
4986 STATISTICS(jniinvokation());
4988 ca = (java_chararray *) array;
4990 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4991 exceptions_throw_arrayindexoutofboundsexception();
4993 MCOPY(&ca->data[start], buf, u2, len);
4997 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4998 jsize len, jshort *buf)
5000 java_shortarray *sa;
5002 STATISTICS(jniinvokation());
5004 sa = (java_shortarray *) array;
5006 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5007 exceptions_throw_arrayindexoutofboundsexception();
5009 MCOPY(&sa->data[start], buf, s2, len);
5013 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5014 jsize len, jint *buf)
5018 STATISTICS(jniinvokation());
5020 ia = (java_intarray *) array;
5022 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5023 exceptions_throw_arrayindexoutofboundsexception();
5025 MCOPY(&ia->data[start], buf, s4, len);
5029 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5030 jsize len, jlong *buf)
5034 STATISTICS(jniinvokation());
5036 la = (java_longarray *) array;
5038 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5039 exceptions_throw_arrayindexoutofboundsexception();
5041 MCOPY(&la->data[start], buf, s8, len);
5045 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5046 jsize len, jfloat *buf)
5048 java_floatarray *fa;
5050 STATISTICS(jniinvokation());
5052 fa = (java_floatarray *) array;
5054 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5055 exceptions_throw_arrayindexoutofboundsexception();
5057 MCOPY(&fa->data[start], buf, float, len);
5061 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5062 jsize len, jdouble *buf)
5064 java_doublearray *da;
5066 STATISTICS(jniinvokation());
5068 da = (java_doublearray *) array;
5070 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5071 exceptions_throw_arrayindexoutofboundsexception();
5073 MCOPY(&da->data[start], buf, double, len);
5077 /* Registering Native Methods *************************************************/
5079 /* RegisterNatives *************************************************************
5081 Registers native methods with the class specified by the clazz
5082 argument. The methods parameter specifies an array of
5083 JNINativeMethod structures that contain the names, signatures, and
5084 function pointers of the native methods. The nMethods parameter
5085 specifies the number of native methods in the array.
5087 *******************************************************************************/
5089 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5090 const JNINativeMethod *methods, jint nMethods)
5092 STATISTICS(jniinvokation());
5094 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5095 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5096 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5103 /* UnregisterNatives ***********************************************************
5105 Unregisters native methods of a class. The class goes back to the
5106 state before it was linked or registered with its native method
5109 This function should not be used in normal native code. Instead, it
5110 provides special programs a way to reload and relink native
5113 *******************************************************************************/
5115 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5117 STATISTICS(jniinvokation());
5119 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5121 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5127 /* Monitor Operations *********************************************************/
5129 /* MonitorEnter ****************************************************************
5131 Enters the monitor associated with the underlying Java object
5134 *******************************************************************************/
5136 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5138 STATISTICS(jniinvokation());
5141 exceptions_throw_nullpointerexception();
5145 LOCK_MONITOR_ENTER(obj);
5151 /* MonitorExit *****************************************************************
5153 The current thread must be the owner of the monitor associated with
5154 the underlying Java object referred to by obj. The thread
5155 decrements the counter indicating the number of times it has
5156 entered this monitor. If the value of the counter becomes zero, the
5157 current thread releases the monitor.
5159 *******************************************************************************/
5161 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5163 STATISTICS(jniinvokation());
5166 exceptions_throw_nullpointerexception();
5170 LOCK_MONITOR_EXIT(obj);
5176 /* JavaVM Interface ***********************************************************/
5178 /* GetJavaVM *******************************************************************
5180 Returns the Java VM interface (used in the Invocation API)
5181 associated with the current thread. The result is placed at the
5182 location pointed to by the second argument, vm.
5184 *******************************************************************************/
5186 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5188 STATISTICS(jniinvokation());
5190 *vm = (JavaVM *) _Jv_jvm;
5196 /* GetStringRegion *************************************************************
5198 Copies len number of Unicode characters beginning at offset start
5199 to the given buffer buf.
5201 Throws StringIndexOutOfBoundsException on index overflow.
5203 *******************************************************************************/
5205 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5208 java_lang_String *s;
5211 STATISTICS(jniinvokation());
5213 s = (java_lang_String *) str;
5216 if ((start < 0) || (len < 0) || (start > s->count) ||
5217 (start + len > s->count)) {
5218 exceptions_throw_stringindexoutofboundsexception();
5222 MCOPY(buf, &ca->data[start], u2, len);
5226 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5227 jsize len, char *buf)
5229 STATISTICS(jniinvokation());
5231 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5235 /* GetPrimitiveArrayCritical ***************************************************
5237 Obtain a direct pointer to array elements.
5239 *******************************************************************************/
5241 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5247 ba = (java_bytearray *) array;
5249 /* do the same as Kaffe does */
5251 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5257 /* ReleasePrimitiveArrayCritical ***********************************************
5259 No specific documentation.
5261 *******************************************************************************/
5263 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5264 void *carray, jint mode)
5266 STATISTICS(jniinvokation());
5268 /* do the same as Kaffe does */
5270 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5275 /* GetStringCritical ***********************************************************
5277 The semantics of these two functions are similar to the existing
5278 Get/ReleaseStringChars functions.
5280 *******************************************************************************/
5282 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5285 STATISTICS(jniinvokation());
5287 return _Jv_JNI_GetStringChars(env, string, isCopy);
5291 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5292 const jchar *cstring)
5294 STATISTICS(jniinvokation());
5296 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5300 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5302 STATISTICS(jniinvokation());
5304 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5310 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5312 STATISTICS(jniinvokation());
5314 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5318 /* NewGlobalRef ****************************************************************
5320 Creates a new global reference to the object referred to by the obj
5323 *******************************************************************************/
5325 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5327 hashtable_global_ref_entry *gre;
5328 u4 key; /* hashkey */
5329 u4 slot; /* slot in hashtable */
5331 STATISTICS(jniinvokation());
5333 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5335 /* normally addresses are aligned to 4, 8 or 16 bytes */
5337 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5338 slot = key & (hashtable_global_ref->size - 1);
5339 gre = hashtable_global_ref->ptr[slot];
5341 /* search external hash chain for the entry */
5344 if (gre->o == obj) {
5345 /* global object found, increment the reference */
5349 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5354 gre = gre->hashlink; /* next element in external chain */
5357 /* global ref not found, create a new one */
5359 gre = NEW(hashtable_global_ref_entry);
5364 /* insert entry into hashtable */
5366 gre->hashlink = hashtable_global_ref->ptr[slot];
5368 hashtable_global_ref->ptr[slot] = gre;
5370 /* update number of hashtable-entries */
5372 hashtable_global_ref->entries++;
5374 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5380 /* DeleteGlobalRef *************************************************************
5382 Deletes the global reference pointed to by globalRef.
5384 *******************************************************************************/
5386 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5388 hashtable_global_ref_entry *gre;
5389 hashtable_global_ref_entry *prevgre;
5390 u4 key; /* hashkey */
5391 u4 slot; /* slot in hashtable */
5393 STATISTICS(jniinvokation());
5395 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5397 /* normally addresses are aligned to 4, 8 or 16 bytes */
5399 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5400 slot = key & (hashtable_global_ref->size - 1);
5401 gre = hashtable_global_ref->ptr[slot];
5403 /* initialize prevgre */
5407 /* search external hash chain for the entry */
5410 if (gre->o == globalRef) {
5411 /* global object found, decrement the reference count */
5415 /* if reference count is 0, remove the entry */
5417 if (gre->refs == 0) {
5418 /* special handling if it's the first in the chain */
5420 if (prevgre == NULL)
5421 hashtable_global_ref->ptr[slot] = gre->hashlink;
5423 prevgre->hashlink = gre->hashlink;
5425 FREE(gre, hashtable_global_ref_entry);
5428 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5433 prevgre = gre; /* save current pointer for removal */
5434 gre = gre->hashlink; /* next element in external chain */
5437 log_println("JNI-DeleteGlobalRef: global reference not found");
5439 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5443 /* ExceptionCheck **************************************************************
5445 Returns JNI_TRUE when there is a pending exception; otherwise,
5448 *******************************************************************************/
5450 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5452 java_objectheader *o;
5454 STATISTICS(jniinvokation());
5456 o = exceptions_get_exception();
5458 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5462 /* New JNI 1.4 functions ******************************************************/
5464 /* NewDirectByteBuffer *********************************************************
5466 Allocates and returns a direct java.nio.ByteBuffer referring to the
5467 block of memory starting at the memory address address and
5468 extending capacity bytes.
5470 *******************************************************************************/
5472 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5474 #if defined(ENABLE_JAVASE)
5475 java_objectheader *nbuf;
5476 # if SIZEOF_VOID_P == 8
5477 gnu_classpath_Pointer64 *paddress;
5479 gnu_classpath_Pointer32 *paddress;
5482 STATISTICS(jniinvokation());
5484 /* alocate a gnu.classpath.Pointer{32,64} object */
5486 # if SIZEOF_VOID_P == 8
5487 if (!(paddress = (gnu_classpath_Pointer64 *)
5488 builtin_new(class_gnu_classpath_Pointer64)))
5490 if (!(paddress = (gnu_classpath_Pointer32 *)
5491 builtin_new(class_gnu_classpath_Pointer32)))
5495 /* fill gnu.classpath.Pointer{32,64} with address */
5497 paddress->data = (ptrint) address;
5499 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5501 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5502 (jmethodID) dbbirw_init, NULL, paddress,
5503 (jint) capacity, (jint) capacity, (jint) 0);
5505 /* add local reference and return the value */
5507 return _Jv_JNI_NewLocalRef(env, nbuf);
5509 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5511 /* keep compiler happy */
5518 /* GetDirectBufferAddress ******************************************************
5520 Fetches and returns the starting address of the memory region
5521 referenced by the given direct java.nio.Buffer.
5523 *******************************************************************************/
5525 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5527 #if defined(ENABLE_JAVASE)
5528 java_nio_DirectByteBufferImpl *nbuf;
5529 # if SIZEOF_VOID_P == 8
5530 gnu_classpath_Pointer64 *address;
5532 gnu_classpath_Pointer32 *address;
5535 STATISTICS(jniinvokation());
5537 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5540 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5542 # if SIZEOF_VOID_P == 8
5543 address = (gnu_classpath_Pointer64 *) nbuf->address;
5545 address = (gnu_classpath_Pointer32 *) nbuf->address;
5548 if (address == NULL)
5551 return (void *) address->data;
5553 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5555 /* keep compiler happy */
5562 /* GetDirectBufferCapacity *****************************************************
5564 Fetches and returns the capacity in bytes of the memory region
5565 referenced by the given direct java.nio.Buffer.
5567 *******************************************************************************/
5569 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5571 #if defined(ENABLE_JAVASE)
5572 java_nio_Buffer *nbuf;
5574 STATISTICS(jniinvokation());
5576 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5579 nbuf = (java_nio_Buffer *) buf;
5581 return (jlong) nbuf->cap;
5583 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5585 /* keep compiler happy */
5592 /* DestroyJavaVM ***************************************************************
5594 Unloads a Java VM and reclaims its resources. Only the main thread
5595 can unload the VM. The system waits until the main thread is only
5596 remaining user thread before it destroys the VM.
5598 *******************************************************************************/
5600 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5604 STATISTICS(jniinvokation());
5606 status = vm_destroy(vm);
5612 /* AttachCurrentThread *********************************************************
5614 Attaches the current thread to a Java VM. Returns a JNI interface
5615 pointer in the JNIEnv argument.
5617 Trying to attach a thread that is already attached is a no-op.
5619 A native thread cannot be attached simultaneously to two Java VMs.
5621 When a thread is attached to the VM, the context class loader is
5622 the bootstrap loader.
5624 *******************************************************************************/
5626 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5628 JavaVMAttachArgs *vm_aargs;
5630 #if defined(ENABLE_THREADS)
5631 if (threads_get_current_threadobject() == NULL) {
5632 vm_aargs = (JavaVMAttachArgs *) thr_args;
5634 if (vm_aargs != NULL) {
5635 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5636 (vm_aargs->version != JNI_VERSION_1_4))
5637 return JNI_EVERSION;
5640 if (!threads_attach_current_thread(vm_aargs, false))
5643 if (!jni_init_localref_table())
5654 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5656 STATISTICS(jniinvokation());
5658 return jni_attach_current_thread(p_env, thr_args, false);
5662 /* DetachCurrentThread *********************************************************
5664 Detaches the current thread from a Java VM. All Java monitors held
5665 by this thread are released. All Java threads waiting for this
5666 thread to die are notified.
5668 In JDK 1.1, the main thread cannot be detached from the VM. It must
5669 call DestroyJavaVM to unload the entire VM.
5671 In the JDK, the main thread can be detached from the VM.
5673 The main thread, which is the thread that created the Java VM,
5674 cannot be detached from the VM. Instead, the main thread must call
5675 JNI_DestroyJavaVM() to unload the entire VM.
5677 *******************************************************************************/
5679 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5681 #if defined(ENABLE_THREADS)
5682 threadobject *thread;
5684 STATISTICS(jniinvokation());
5686 thread = threads_get_current_threadobject();
5691 if (!threads_detach_thread(thread))
5699 /* GetEnv **********************************************************************
5701 If the current thread is not attached to the VM, sets *env to NULL,
5702 and returns JNI_EDETACHED. If the specified version is not
5703 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5704 sets *env to the appropriate interface, and returns JNI_OK.
5706 *******************************************************************************/
5708 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5710 STATISTICS(jniinvokation());
5712 #if defined(ENABLE_THREADS)
5713 if (threads_get_current_threadobject() == NULL) {
5716 return JNI_EDETACHED;
5720 /* check the JNI version */
5723 case JNI_VERSION_1_1:
5724 case JNI_VERSION_1_2:
5725 case JNI_VERSION_1_4:
5733 #if defined(ENABLE_JVMTI)
5734 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5735 == JVMTI_VERSION_INTERFACE_JVMTI) {
5737 *env = (void *) jvmti_new_environment();
5746 return JNI_EVERSION;
5750 /* AttachCurrentThreadAsDaemon *************************************************
5752 Same semantics as AttachCurrentThread, but the newly-created
5753 java.lang.Thread instance is a daemon.
5755 If the thread has already been attached via either
5756 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5757 simply sets the value pointed to by penv to the JNIEnv of the
5758 current thread. In this case neither AttachCurrentThread nor this
5759 routine have any effect on the daemon status of the thread.
5761 *******************************************************************************/
5763 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5765 STATISTICS(jniinvokation());
5767 return jni_attach_current_thread(penv, args, true);
5771 /* JNI invocation table *******************************************************/
5773 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5778 _Jv_JNI_DestroyJavaVM,
5779 _Jv_JNI_AttachCurrentThread,
5780 _Jv_JNI_DetachCurrentThread,
5782 _Jv_JNI_AttachCurrentThreadAsDaemon
5786 /* JNI function table *********************************************************/
5788 struct JNINativeInterface _Jv_JNINativeInterface = {
5795 _Jv_JNI_DefineClass,
5797 _Jv_JNI_FromReflectedMethod,
5798 _Jv_JNI_FromReflectedField,
5799 _Jv_JNI_ToReflectedMethod,
5800 _Jv_JNI_GetSuperclass,
5801 _Jv_JNI_IsAssignableFrom,
5802 _Jv_JNI_ToReflectedField,
5806 _Jv_JNI_ExceptionOccurred,
5807 _Jv_JNI_ExceptionDescribe,
5808 _Jv_JNI_ExceptionClear,
5810 _Jv_JNI_PushLocalFrame,
5811 _Jv_JNI_PopLocalFrame,
5813 _Jv_JNI_NewGlobalRef,
5814 _Jv_JNI_DeleteGlobalRef,
5815 _Jv_JNI_DeleteLocalRef,
5816 _Jv_JNI_IsSameObject,
5817 _Jv_JNI_NewLocalRef,
5818 _Jv_JNI_EnsureLocalCapacity,
5820 _Jv_JNI_AllocObject,
5825 _Jv_JNI_GetObjectClass,
5826 _Jv_JNI_IsInstanceOf,
5828 _Jv_JNI_GetMethodID,
5830 _Jv_JNI_CallObjectMethod,
5831 _Jv_JNI_CallObjectMethodV,
5832 _Jv_JNI_CallObjectMethodA,
5833 _Jv_JNI_CallBooleanMethod,
5834 _Jv_JNI_CallBooleanMethodV,
5835 _Jv_JNI_CallBooleanMethodA,
5836 _Jv_JNI_CallByteMethod,
5837 _Jv_JNI_CallByteMethodV,
5838 _Jv_JNI_CallByteMethodA,
5839 _Jv_JNI_CallCharMethod,
5840 _Jv_JNI_CallCharMethodV,
5841 _Jv_JNI_CallCharMethodA,
5842 _Jv_JNI_CallShortMethod,
5843 _Jv_JNI_CallShortMethodV,
5844 _Jv_JNI_CallShortMethodA,
5845 _Jv_JNI_CallIntMethod,
5846 _Jv_JNI_CallIntMethodV,
5847 _Jv_JNI_CallIntMethodA,
5848 _Jv_JNI_CallLongMethod,
5849 _Jv_JNI_CallLongMethodV,
5850 _Jv_JNI_CallLongMethodA,
5851 _Jv_JNI_CallFloatMethod,
5852 _Jv_JNI_CallFloatMethodV,
5853 _Jv_JNI_CallFloatMethodA,
5854 _Jv_JNI_CallDoubleMethod,
5855 _Jv_JNI_CallDoubleMethodV,
5856 _Jv_JNI_CallDoubleMethodA,
5857 _Jv_JNI_CallVoidMethod,
5858 _Jv_JNI_CallVoidMethodV,
5859 _Jv_JNI_CallVoidMethodA,
5861 _Jv_JNI_CallNonvirtualObjectMethod,
5862 _Jv_JNI_CallNonvirtualObjectMethodV,
5863 _Jv_JNI_CallNonvirtualObjectMethodA,
5864 _Jv_JNI_CallNonvirtualBooleanMethod,
5865 _Jv_JNI_CallNonvirtualBooleanMethodV,
5866 _Jv_JNI_CallNonvirtualBooleanMethodA,
5867 _Jv_JNI_CallNonvirtualByteMethod,
5868 _Jv_JNI_CallNonvirtualByteMethodV,
5869 _Jv_JNI_CallNonvirtualByteMethodA,
5870 _Jv_JNI_CallNonvirtualCharMethod,
5871 _Jv_JNI_CallNonvirtualCharMethodV,
5872 _Jv_JNI_CallNonvirtualCharMethodA,
5873 _Jv_JNI_CallNonvirtualShortMethod,
5874 _Jv_JNI_CallNonvirtualShortMethodV,
5875 _Jv_JNI_CallNonvirtualShortMethodA,
5876 _Jv_JNI_CallNonvirtualIntMethod,
5877 _Jv_JNI_CallNonvirtualIntMethodV,
5878 _Jv_JNI_CallNonvirtualIntMethodA,
5879 _Jv_JNI_CallNonvirtualLongMethod,
5880 _Jv_JNI_CallNonvirtualLongMethodV,
5881 _Jv_JNI_CallNonvirtualLongMethodA,
5882 _Jv_JNI_CallNonvirtualFloatMethod,
5883 _Jv_JNI_CallNonvirtualFloatMethodV,
5884 _Jv_JNI_CallNonvirtualFloatMethodA,
5885 _Jv_JNI_CallNonvirtualDoubleMethod,
5886 _Jv_JNI_CallNonvirtualDoubleMethodV,
5887 _Jv_JNI_CallNonvirtualDoubleMethodA,
5888 _Jv_JNI_CallNonvirtualVoidMethod,
5889 _Jv_JNI_CallNonvirtualVoidMethodV,
5890 _Jv_JNI_CallNonvirtualVoidMethodA,
5894 _Jv_JNI_GetObjectField,
5895 _Jv_JNI_GetBooleanField,
5896 _Jv_JNI_GetByteField,
5897 _Jv_JNI_GetCharField,
5898 _Jv_JNI_GetShortField,
5899 _Jv_JNI_GetIntField,
5900 _Jv_JNI_GetLongField,
5901 _Jv_JNI_GetFloatField,
5902 _Jv_JNI_GetDoubleField,
5903 _Jv_JNI_SetObjectField,
5904 _Jv_JNI_SetBooleanField,
5905 _Jv_JNI_SetByteField,
5906 _Jv_JNI_SetCharField,
5907 _Jv_JNI_SetShortField,
5908 _Jv_JNI_SetIntField,
5909 _Jv_JNI_SetLongField,
5910 _Jv_JNI_SetFloatField,
5911 _Jv_JNI_SetDoubleField,
5913 _Jv_JNI_GetStaticMethodID,
5915 _Jv_JNI_CallStaticObjectMethod,
5916 _Jv_JNI_CallStaticObjectMethodV,
5917 _Jv_JNI_CallStaticObjectMethodA,
5918 _Jv_JNI_CallStaticBooleanMethod,
5919 _Jv_JNI_CallStaticBooleanMethodV,
5920 _Jv_JNI_CallStaticBooleanMethodA,
5921 _Jv_JNI_CallStaticByteMethod,
5922 _Jv_JNI_CallStaticByteMethodV,
5923 _Jv_JNI_CallStaticByteMethodA,
5924 _Jv_JNI_CallStaticCharMethod,
5925 _Jv_JNI_CallStaticCharMethodV,
5926 _Jv_JNI_CallStaticCharMethodA,
5927 _Jv_JNI_CallStaticShortMethod,
5928 _Jv_JNI_CallStaticShortMethodV,
5929 _Jv_JNI_CallStaticShortMethodA,
5930 _Jv_JNI_CallStaticIntMethod,
5931 _Jv_JNI_CallStaticIntMethodV,
5932 _Jv_JNI_CallStaticIntMethodA,
5933 _Jv_JNI_CallStaticLongMethod,
5934 _Jv_JNI_CallStaticLongMethodV,
5935 _Jv_JNI_CallStaticLongMethodA,
5936 _Jv_JNI_CallStaticFloatMethod,
5937 _Jv_JNI_CallStaticFloatMethodV,
5938 _Jv_JNI_CallStaticFloatMethodA,
5939 _Jv_JNI_CallStaticDoubleMethod,
5940 _Jv_JNI_CallStaticDoubleMethodV,
5941 _Jv_JNI_CallStaticDoubleMethodA,
5942 _Jv_JNI_CallStaticVoidMethod,
5943 _Jv_JNI_CallStaticVoidMethodV,
5944 _Jv_JNI_CallStaticVoidMethodA,
5946 _Jv_JNI_GetStaticFieldID,
5948 _Jv_JNI_GetStaticObjectField,
5949 _Jv_JNI_GetStaticBooleanField,
5950 _Jv_JNI_GetStaticByteField,
5951 _Jv_JNI_GetStaticCharField,
5952 _Jv_JNI_GetStaticShortField,
5953 _Jv_JNI_GetStaticIntField,
5954 _Jv_JNI_GetStaticLongField,
5955 _Jv_JNI_GetStaticFloatField,
5956 _Jv_JNI_GetStaticDoubleField,
5957 _Jv_JNI_SetStaticObjectField,
5958 _Jv_JNI_SetStaticBooleanField,
5959 _Jv_JNI_SetStaticByteField,
5960 _Jv_JNI_SetStaticCharField,
5961 _Jv_JNI_SetStaticShortField,
5962 _Jv_JNI_SetStaticIntField,
5963 _Jv_JNI_SetStaticLongField,
5964 _Jv_JNI_SetStaticFloatField,
5965 _Jv_JNI_SetStaticDoubleField,
5968 _Jv_JNI_GetStringLength,
5969 _Jv_JNI_GetStringChars,
5970 _Jv_JNI_ReleaseStringChars,
5972 _Jv_JNI_NewStringUTF,
5973 _Jv_JNI_GetStringUTFLength,
5974 _Jv_JNI_GetStringUTFChars,
5975 _Jv_JNI_ReleaseStringUTFChars,
5977 _Jv_JNI_GetArrayLength,
5979 _Jv_JNI_NewObjectArray,
5980 _Jv_JNI_GetObjectArrayElement,
5981 _Jv_JNI_SetObjectArrayElement,
5983 _Jv_JNI_NewBooleanArray,
5984 _Jv_JNI_NewByteArray,
5985 _Jv_JNI_NewCharArray,
5986 _Jv_JNI_NewShortArray,
5987 _Jv_JNI_NewIntArray,
5988 _Jv_JNI_NewLongArray,
5989 _Jv_JNI_NewFloatArray,
5990 _Jv_JNI_NewDoubleArray,
5992 _Jv_JNI_GetBooleanArrayElements,
5993 _Jv_JNI_GetByteArrayElements,
5994 _Jv_JNI_GetCharArrayElements,
5995 _Jv_JNI_GetShortArrayElements,
5996 _Jv_JNI_GetIntArrayElements,
5997 _Jv_JNI_GetLongArrayElements,
5998 _Jv_JNI_GetFloatArrayElements,
5999 _Jv_JNI_GetDoubleArrayElements,
6001 _Jv_JNI_ReleaseBooleanArrayElements,
6002 _Jv_JNI_ReleaseByteArrayElements,
6003 _Jv_JNI_ReleaseCharArrayElements,
6004 _Jv_JNI_ReleaseShortArrayElements,
6005 _Jv_JNI_ReleaseIntArrayElements,
6006 _Jv_JNI_ReleaseLongArrayElements,
6007 _Jv_JNI_ReleaseFloatArrayElements,
6008 _Jv_JNI_ReleaseDoubleArrayElements,
6010 _Jv_JNI_GetBooleanArrayRegion,
6011 _Jv_JNI_GetByteArrayRegion,
6012 _Jv_JNI_GetCharArrayRegion,
6013 _Jv_JNI_GetShortArrayRegion,
6014 _Jv_JNI_GetIntArrayRegion,
6015 _Jv_JNI_GetLongArrayRegion,
6016 _Jv_JNI_GetFloatArrayRegion,
6017 _Jv_JNI_GetDoubleArrayRegion,
6018 _Jv_JNI_SetBooleanArrayRegion,
6019 _Jv_JNI_SetByteArrayRegion,
6020 _Jv_JNI_SetCharArrayRegion,
6021 _Jv_JNI_SetShortArrayRegion,
6022 _Jv_JNI_SetIntArrayRegion,
6023 _Jv_JNI_SetLongArrayRegion,
6024 _Jv_JNI_SetFloatArrayRegion,
6025 _Jv_JNI_SetDoubleArrayRegion,
6027 _Jv_JNI_RegisterNatives,
6028 _Jv_JNI_UnregisterNatives,
6030 _Jv_JNI_MonitorEnter,
6031 _Jv_JNI_MonitorExit,
6035 /* new JNI 1.2 functions */
6037 _Jv_JNI_GetStringRegion,
6038 _Jv_JNI_GetStringUTFRegion,
6040 _Jv_JNI_GetPrimitiveArrayCritical,
6041 _Jv_JNI_ReleasePrimitiveArrayCritical,
6043 _Jv_JNI_GetStringCritical,
6044 _Jv_JNI_ReleaseStringCritical,
6046 _Jv_JNI_NewWeakGlobalRef,
6047 _Jv_JNI_DeleteWeakGlobalRef,
6049 _Jv_JNI_ExceptionCheck,
6051 /* new JNI 1.4 functions */
6053 _Jv_JNI_NewDirectByteBuffer,
6054 _Jv_JNI_GetDirectBufferAddress,
6055 _Jv_JNI_GetDirectBufferCapacity
6059 /* Invocation API Functions ***************************************************/
6061 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6063 Returns a default configuration for the Java VM.
6065 *******************************************************************************/
6067 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6069 JavaVMInitArgs *_vm_args;
6071 _vm_args = (JavaVMInitArgs *) vm_args;
6073 /* GNU classpath currently supports JNI 1.2 */
6075 switch (_vm_args->version) {
6076 case JNI_VERSION_1_1:
6077 _vm_args->version = JNI_VERSION_1_1;
6080 case JNI_VERSION_1_2:
6081 case JNI_VERSION_1_4:
6082 _vm_args->ignoreUnrecognized = JNI_FALSE;
6083 _vm_args->options = NULL;
6084 _vm_args->nOptions = 0;
6095 /* JNI_GetCreatedJavaVMs *******************************************************
6097 Returns all Java VMs that have been created. Pointers to VMs are written in
6098 the buffer vmBuf in the order they are created. At most bufLen number of
6099 entries will be written. The total number of created VMs is returned in
6102 *******************************************************************************/
6104 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6106 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6112 /* JNI_CreateJavaVM ************************************************************
6114 Loads and initializes a Java VM. The current thread becomes the main thread.
6115 Sets the env argument to the JNI interface pointer of the main thread.
6117 *******************************************************************************/
6119 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6121 /* actually create the JVM */
6123 if (!vm_createjvm(p_vm, p_env, vm_args))
6131 * These are local overrides for various environment variables in Emacs.
6132 * Please do not remove this and leave it at the end of the file, where
6133 * Emacs will automagically detect them.
6134 * ---------------------------------------------------------------------
6137 * indent-tabs-mode: t
6141 * vim:noexpandtab:sw=4:ts=4: