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 7392 2007-02-23 20:15:31Z michi $
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_THREADS)
84 # include "threads/native/lock.h"
85 # include "threads/native/threads.h"
87 # include "threads/none/lock.h"
88 # include "threads/none/threads.h"
91 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/stringlocal.h"
100 #include "vm/jit/asmpart.h"
101 #include "vm/jit/jit.h"
102 #include "vm/jit/stacktrace.h"
104 #include "vmcore/loader.h"
105 #include "vmcore/options.h"
106 #include "vmcore/resolve.h"
107 #include "vmcore/statistics.h"
110 /* global variables ***********************************************************/
112 /* global reference table *****************************************************/
114 /* hashsize must be power of 2 */
116 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
118 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
121 /* direct buffer stuff ********************************************************/
123 #if defined(ENABLE_JAVASE)
124 static classinfo *class_java_nio_Buffer;
125 static classinfo *class_java_nio_DirectByteBufferImpl;
126 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
128 # if defined(WITH_CLASSPATH_GNU)
129 # if SIZEOF_VOID_P == 8
130 static classinfo *class_gnu_classpath_Pointer64;
132 static classinfo *class_gnu_classpath_Pointer32;
136 static methodinfo *dbbirw_init;
140 /* local reference table ******************************************************/
142 #if !defined(ENABLE_THREADS)
143 localref_table *_no_threads_localref_table;
147 /* accessing instance fields macros *******************************************/
149 #define SET_FIELD(o,type,f,value) \
150 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
152 #define GET_FIELD(o,type,f) \
153 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
156 /* some forward declarations **************************************************/
158 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
159 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
162 /* jni_init ********************************************************************
164 Initialize the JNI subsystem.
166 *******************************************************************************/
170 /* create global ref hashtable */
172 hashtable_global_ref = NEW(hashtable);
174 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
177 #if defined(ENABLE_JAVASE)
178 /* direct buffer stuff */
180 if (!(class_java_nio_Buffer =
181 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
182 !link_class(class_java_nio_Buffer))
185 if (!(class_java_nio_DirectByteBufferImpl =
186 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
187 !link_class(class_java_nio_DirectByteBufferImpl))
190 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
191 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
192 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
196 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
198 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
201 # if defined(WITH_CLASSPATH_GNU)
202 # if SIZEOF_VOID_P == 8
203 if (!(class_gnu_classpath_Pointer64 =
204 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
205 !link_class(class_gnu_classpath_Pointer64))
208 if (!(class_gnu_classpath_Pointer32 =
209 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
210 !link_class(class_gnu_classpath_Pointer32))
214 #endif /* defined(ENABLE_JAVASE) */
220 /* jni_init_localref_table *****************************************************
222 Initializes the local references table of the current thread.
224 *******************************************************************************/
226 bool jni_init_localref_table(void)
230 #if defined(ENABLE_GC_CACAO)
231 /* XXX this one will never get freed for the main thread;
232 call jni_free_localref_table() if you want to do it! */
233 lrt = NEW(localref_table);
235 lrt = GCNEW(localref_table);
241 lrt->capacity = LOCALREFTABLE_CAPACITY;
243 lrt->localframes = 1;
244 lrt->prev = LOCALREFTABLE;
246 /* clear the references array (memset is faster then a for-loop) */
248 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
256 /* jni_init_localref_table *****************************************************
258 Frees the local references table of the current thread.
260 *******************************************************************************/
262 bool jni_free_localref_table(void)
266 #if defined(ENABLE_GC_CACAO)
270 assert(lrt->prev == NULL);
272 FREE(lrt, localref_table);
274 LOCALREFTABLE = NULL;
281 /* _Jv_jni_vmargs_from_objectarray *********************************************
285 *******************************************************************************/
287 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
290 java_objectarray *params)
292 java_objectheader *param;
294 typedesc *paramtypes;
300 paramcount = descr->paramcount;
301 paramtypes = descr->paramtypes;
303 /* if method is non-static fill first block and skip `this' pointer */
309 vmargs[0].type = TYPE_ADR;
310 vmargs[0].data.l = (u8) (ptrint) o;
317 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
318 switch (paramtypes->type) {
319 /* primitive types */
324 param = params->data[j];
329 /* internally used data type */
330 vmargs[i].type = paramtypes->type;
332 /* convert the value according to its declared type */
334 c = param->vftbl->class;
336 switch (paramtypes->decltype) {
337 case PRIMITIVETYPE_BOOLEAN:
338 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
339 value = (s8) ((java_lang_Boolean *) param)->value;
343 vmargs[i].data.l = value;
346 case PRIMITIVETYPE_BYTE:
347 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
348 value = (s8) ((java_lang_Byte *) param)->value;
352 vmargs[i].data.l = value;
355 case PRIMITIVETYPE_CHAR:
356 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
357 value = (s8) ((java_lang_Character *) param)->value;
361 vmargs[i].data.l = value;
364 case PRIMITIVETYPE_SHORT:
365 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
366 value = (s8) ((java_lang_Short *) param)->value;
367 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
368 value = (s8) ((java_lang_Byte *) param)->value;
372 vmargs[i].data.l = value;
375 case PRIMITIVETYPE_INT:
376 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
377 value = (s8) ((java_lang_Integer *) param)->value;
378 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
379 value = (s8) ((java_lang_Short *) param)->value;
380 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
381 value = (s8) ((java_lang_Byte *) param)->value;
385 vmargs[i].data.l = value;
388 case PRIMITIVETYPE_LONG:
389 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
390 value = (s8) ((java_lang_Long *) param)->value;
391 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
392 value = (s8) ((java_lang_Integer *) param)->value;
393 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
394 value = (s8) ((java_lang_Short *) param)->value;
395 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
396 value = (s8) ((java_lang_Byte *) param)->value;
400 vmargs[i].data.l = value;
403 case PRIMITIVETYPE_FLOAT:
404 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
405 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
410 case PRIMITIVETYPE_DOUBLE:
411 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
412 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
413 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
414 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
425 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
428 if (params->data[j] != 0) {
429 if (paramtypes->arraydim > 0) {
430 if (!builtin_arrayinstanceof(params->data[j], c))
434 if (!builtin_instanceof(params->data[j], c))
439 vmargs[i].type = TYPE_ADR;
440 vmargs[i].data.l = (u8) (ptrint) params->data[j];
449 /* *rettype = descr->returntype.decltype; */
454 exceptions_throw_illegalargumentexception();
459 /* _Jv_jni_CallObjectMethod ****************************************************
461 Internal function to call Java Object methods.
463 *******************************************************************************/
465 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
467 methodinfo *m, va_list ap)
470 java_objectheader *ro;
472 STATISTICS(jniinvokation());
475 exceptions_throw_nullpointerexception();
479 /* Class initialization is done by the JIT compiler. This is ok
480 since a static method always belongs to the declaring class. */
482 if (m->flags & ACC_STATIC) {
483 /* For static methods we reset the object. */
488 /* for convenience */
493 /* For instance methods we make a virtual function table lookup. */
495 resm = method_vftbl_lookup(vftbl, m);
498 STATISTICS(jnicallXmethodnvokation());
500 ro = vm_call_method_valist(resm, o, ap);
506 /* _Jv_jni_CallObjectMethodA ***************************************************
508 Internal function to call Java Object methods.
510 *******************************************************************************/
512 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
514 methodinfo *m, jvalue *args)
517 java_objectheader *ro;
519 STATISTICS(jniinvokation());
522 exceptions_throw_nullpointerexception();
526 /* Class initialization is done by the JIT compiler. This is ok
527 since a static method always belongs to the declaring class. */
529 if (m->flags & ACC_STATIC) {
530 /* For static methods we reset the object. */
535 /* for convenience */
540 /* For instance methods we make a virtual function table lookup. */
542 resm = method_vftbl_lookup(vftbl, m);
545 STATISTICS(jnicallXmethodnvokation());
547 ro = vm_call_method_jvalue(resm, o, args);
553 /* _Jv_jni_CallIntMethod *******************************************************
555 Internal function to call Java integer class methods (boolean,
556 byte, char, short, int).
558 *******************************************************************************/
560 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
561 methodinfo *m, va_list ap)
566 STATISTICS(jniinvokation());
569 exceptions_throw_nullpointerexception();
573 /* Class initialization is done by the JIT compiler. This is ok
574 since a static method always belongs to the declaring class. */
576 if (m->flags & ACC_STATIC) {
577 /* For static methods we reset the object. */
582 /* for convenience */
587 /* For instance methods we make a virtual function table lookup. */
589 resm = method_vftbl_lookup(vftbl, m);
592 STATISTICS(jnicallXmethodnvokation());
594 i = vm_call_method_int_valist(resm, o, ap);
600 /* _Jv_jni_CallIntMethodA ******************************************************
602 Internal function to call Java integer class methods (boolean,
603 byte, char, short, int).
605 *******************************************************************************/
607 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
608 methodinfo *m, jvalue *args)
613 STATISTICS(jniinvokation());
616 exceptions_throw_nullpointerexception();
620 /* Class initialization is done by the JIT compiler. This is ok
621 since a static method always belongs to the declaring class. */
623 if (m->flags & ACC_STATIC) {
624 /* For static methods we reset the object. */
629 /* for convenience */
634 /* For instance methods we make a virtual function table lookup. */
636 resm = method_vftbl_lookup(vftbl, m);
639 STATISTICS(jnicallXmethodnvokation());
641 i = vm_call_method_int_jvalue(resm, o, args);
647 /* _Jv_jni_CallLongMethod ******************************************************
649 Internal function to call Java long methods.
651 *******************************************************************************/
653 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
654 methodinfo *m, va_list ap)
659 STATISTICS(jniinvokation());
662 exceptions_throw_nullpointerexception();
666 /* Class initialization is done by the JIT compiler. This is ok
667 since a static method always belongs to the declaring class. */
669 if (m->flags & ACC_STATIC) {
670 /* For static methods we reset the object. */
675 /* for convenience */
680 /* For instance methods we make a virtual function table lookup. */
682 resm = method_vftbl_lookup(vftbl, m);
685 STATISTICS(jnicallXmethodnvokation());
687 l = vm_call_method_long_valist(resm, o, ap);
693 /* _Jv_jni_CallFloatMethod *****************************************************
695 Internal function to call Java float methods.
697 *******************************************************************************/
699 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
700 methodinfo *m, va_list ap)
705 /* Class initialization is done by the JIT compiler. This is ok
706 since a static method always belongs to the declaring class. */
708 if (m->flags & ACC_STATIC) {
709 /* For static methods we reset the object. */
714 /* for convenience */
719 /* For instance methods we make a virtual function table lookup. */
721 resm = method_vftbl_lookup(vftbl, m);
724 STATISTICS(jnicallXmethodnvokation());
726 f = vm_call_method_float_valist(resm, o, ap);
732 /* _Jv_jni_CallDoubleMethod ****************************************************
734 Internal function to call Java double methods.
736 *******************************************************************************/
738 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
739 methodinfo *m, va_list ap)
744 /* Class initialization is done by the JIT compiler. This is ok
745 since a static method always belongs to the declaring class. */
747 if (m->flags & ACC_STATIC) {
748 /* For static methods we reset the object. */
753 /* for convenience */
758 /* For instance methods we make a virtual function table lookup. */
760 resm = method_vftbl_lookup(vftbl, m);
763 d = vm_call_method_double_valist(resm, o, ap);
769 /* _Jv_jni_CallVoidMethod ******************************************************
771 Internal function to call Java void methods.
773 *******************************************************************************/
775 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
776 methodinfo *m, va_list ap)
781 exceptions_throw_nullpointerexception();
785 /* Class initialization is done by the JIT compiler. This is ok
786 since a static method always belongs to the declaring class. */
788 if (m->flags & ACC_STATIC) {
789 /* For static methods we reset the object. */
794 /* for convenience */
799 /* For instance methods we make a virtual function table lookup. */
801 resm = method_vftbl_lookup(vftbl, m);
804 STATISTICS(jnicallXmethodnvokation());
806 (void) vm_call_method_valist(resm, o, ap);
810 /* _Jv_jni_CallVoidMethodA *****************************************************
812 Internal function to call Java void methods.
814 *******************************************************************************/
816 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
817 methodinfo *m, jvalue *args)
822 exceptions_throw_nullpointerexception();
826 /* Class initialization is done by the JIT compiler. This is ok
827 since a static method always belongs to the declaring class. */
829 if (m->flags & ACC_STATIC) {
830 /* For static methods we reset the object. */
835 /* for convenience */
840 /* For instance methods we make a virtual function table lookup. */
842 resm = method_vftbl_lookup(vftbl, m);
845 STATISTICS(jnicallXmethodnvokation());
847 (void) vm_call_method_jvalue(resm, o, args);
851 /* _Jv_jni_invokeNative ********************************************************
853 Invoke a method on the given object with the given arguments.
855 For instance methods OBJ must be != NULL and the method is looked up
856 in the vftbl of the object.
858 For static methods, OBJ is ignored.
860 *******************************************************************************/
862 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
863 java_objectarray *params)
867 java_objectheader *ro;
870 java_objectheader *xptr;
873 exceptions_throw_nullpointerexception();
877 argcount = m->parseddesc->paramcount;
878 paramcount = argcount;
880 /* if method is non-static, remove the `this' pointer */
882 if (!(m->flags & ACC_STATIC))
885 /* For instance methods the object has to be an instance of the
886 class the method belongs to. For static methods the obj
887 parameter is ignored. */
889 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
890 exceptions_throw_illegalargumentexception();
894 /* check if we got the right number of arguments */
896 if (((params == NULL) && (paramcount != 0)) ||
897 (params && (params->header.size != paramcount)))
899 exceptions_throw_illegalargumentexception();
903 /* for instance methods we need an object */
905 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
906 /* XXX not sure if that is the correct exception */
907 exceptions_throw_nullpointerexception();
911 /* for static methods, zero object to make subsequent code simpler */
912 if (m->flags & ACC_STATIC)
916 /* for instance methods we must do a vftbl lookup */
917 resm = method_vftbl_lookup(o->vftbl, m);
920 /* for static methods, just for convenience */
924 vmargs = MNEW(vm_arg, argcount);
926 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
929 switch (resm->parseddesc->returntype.decltype) {
931 (void) vm_call_method_vmarg(resm, argcount, vmargs);
936 case PRIMITIVETYPE_BOOLEAN: {
938 java_lang_Boolean *bo;
940 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
942 ro = builtin_new(class_java_lang_Boolean);
944 /* setting the value of the object direct */
946 bo = (java_lang_Boolean *) ro;
951 case PRIMITIVETYPE_BYTE: {
955 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
957 ro = builtin_new(class_java_lang_Byte);
959 /* setting the value of the object direct */
961 bo = (java_lang_Byte *) ro;
966 case PRIMITIVETYPE_CHAR: {
968 java_lang_Character *co;
970 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
972 ro = builtin_new(class_java_lang_Character);
974 /* setting the value of the object direct */
976 co = (java_lang_Character *) ro;
981 case PRIMITIVETYPE_SHORT: {
985 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
987 ro = builtin_new(class_java_lang_Short);
989 /* setting the value of the object direct */
991 so = (java_lang_Short *) ro;
996 case PRIMITIVETYPE_INT: {
998 java_lang_Integer *io;
1000 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1002 ro = builtin_new(class_java_lang_Integer);
1004 /* setting the value of the object direct */
1006 io = (java_lang_Integer *) ro;
1011 case PRIMITIVETYPE_LONG: {
1015 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1017 ro = builtin_new(class_java_lang_Long);
1019 /* setting the value of the object direct */
1021 lo = (java_lang_Long *) ro;
1026 case PRIMITIVETYPE_FLOAT: {
1028 java_lang_Float *fo;
1030 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1032 ro = builtin_new(class_java_lang_Float);
1034 /* setting the value of the object direct */
1036 fo = (java_lang_Float *) ro;
1041 case PRIMITIVETYPE_DOUBLE: {
1043 java_lang_Double *_do;
1045 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1047 ro = builtin_new(class_java_lang_Double);
1049 /* setting the value of the object direct */
1051 _do = (java_lang_Double *) ro;
1057 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1061 /* if this happens the exception has already been set by
1062 fill_callblock_from_objectarray */
1064 MFREE(vmargs, vm_arg, argcount);
1069 MFREE(vmargs, vm_arg, argcount);
1071 xptr = exceptions_get_exception();
1074 /* clear exception pointer, we are calling JIT code again */
1076 exceptions_clear_exception();
1078 exceptions_throw_invocationtargetexception(xptr);
1085 /* GetVersion ******************************************************************
1087 Returns the major version number in the higher 16 bits and the
1088 minor version number in the lower 16 bits.
1090 *******************************************************************************/
1092 jint _Jv_JNI_GetVersion(JNIEnv *env)
1094 STATISTICS(jniinvokation());
1096 /* we support JNI 1.4 */
1098 return JNI_VERSION_1_4;
1102 /* Class Operations ***********************************************************/
1104 /* DefineClass *****************************************************************
1106 Loads a class from a buffer of raw class data. The buffer
1107 containing the raw class data is not referenced by the VM after the
1108 DefineClass call returns, and it may be discarded if desired.
1110 *******************************************************************************/
1112 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1113 const jbyte *buf, jsize bufLen)
1115 #if defined(ENABLE_JAVASE)
1116 java_lang_ClassLoader *cl;
1117 java_lang_String *s;
1121 STATISTICS(jniinvokation());
1123 cl = (java_lang_ClassLoader *) loader;
1124 s = javastring_new_from_utf_string(name);
1125 ba = (java_bytearray *) buf;
1127 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(env, NULL, cl, s, ba,
1130 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1132 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1134 /* keep compiler happy */
1141 /* FindClass *******************************************************************
1143 This function loads a locally-defined class. It searches the
1144 directories and zip files specified by the CLASSPATH environment
1145 variable for the class with the specified name.
1147 *******************************************************************************/
1149 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1151 #if defined(ENABLE_JAVASE)
1156 STATISTICS(jniinvokation());
1158 u = utf_new_char_classname((char *) name);
1160 /* Check stacktrace for classloader, if one found use it,
1161 otherwise use the system classloader. */
1163 /* Quote from the JNI documentation:
1165 In the Java 2 Platform, FindClass locates the class loader
1166 associated with the current native method. If the native code
1167 belongs to a system class, no class loader will be
1168 involved. Otherwise, the proper class loader will be invoked to
1169 load and link the named class. When FindClass is called through
1170 the Invocation Interface, there is no current native method or
1171 its associated class loader. In that case, the result of
1172 ClassLoader.getBaseClassLoader is used." */
1174 cc = stacktrace_getCurrentClass();
1177 c = load_class_from_sysloader(u);
1179 c = load_class_from_classloader(u, cc->classloader);
1187 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1189 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1191 /* keep compiler happy */
1198 /* GetSuperclass ***************************************************************
1200 If clazz represents any class other than the class Object, then
1201 this function returns the object that represents the superclass of
1202 the class specified by clazz.
1204 *******************************************************************************/
1206 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1210 STATISTICS(jniinvokation());
1212 c = ((classinfo *) sub)->super.cls;
1217 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1221 /* IsAssignableFrom ************************************************************
1223 Determines whether an object of sub can be safely cast to sup.
1225 *******************************************************************************/
1227 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1229 java_lang_Class *csup;
1230 java_lang_Class *csub;
1232 csup = (java_lang_Class *) sup;
1233 csub = (java_lang_Class *) sub;
1235 STATISTICS(jniinvokation());
1237 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1241 /* Throw ***********************************************************************
1243 Causes a java.lang.Throwable object to be thrown.
1245 *******************************************************************************/
1247 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1249 java_objectheader *o;
1251 STATISTICS(jniinvokation());
1253 o = (java_objectheader *) obj;
1255 exceptions_set_exception(o);
1261 /* ThrowNew ********************************************************************
1263 Constructs an exception object from the specified class with the
1264 message specified by message and causes that exception to be
1267 *******************************************************************************/
1269 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1272 java_objectheader *o;
1273 java_objectheader *s;
1275 STATISTICS(jniinvokation());
1277 c = (classinfo *) clazz;
1278 s = javastring_new_from_utf_string(msg);
1280 /* instantiate exception object */
1282 o = native_new_and_init_string(c, s);
1287 exceptions_set_exception(o);
1293 /* ExceptionOccurred ***********************************************************
1295 Determines if an exception is being thrown. The exception stays
1296 being thrown until either the native code calls ExceptionClear(),
1297 or the Java code handles the exception.
1299 *******************************************************************************/
1301 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1303 java_objectheader *o;
1305 STATISTICS(jniinvokation());
1307 o = exceptions_get_exception();
1309 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1313 /* ExceptionDescribe ***********************************************************
1315 Prints an exception and a backtrace of the stack to a system
1316 error-reporting channel, such as stderr. This is a convenience
1317 routine provided for debugging.
1319 *******************************************************************************/
1321 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1323 java_objectheader *o;
1326 STATISTICS(jniinvokation());
1328 o = exceptions_get_exception();
1331 /* clear exception, because we are calling jit code again */
1333 exceptions_clear_exception();
1335 /* get printStackTrace method from exception class */
1337 m = class_resolveclassmethod(o->vftbl->class,
1338 utf_printStackTrace,
1344 /* XXX what should we do? */
1347 /* print the stacktrace */
1349 (void) vm_call_method(m, o);
1354 /* ExceptionClear **************************************************************
1356 Clears any exception that is currently being thrown. If no
1357 exception is currently being thrown, this routine has no effect.
1359 *******************************************************************************/
1361 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1363 STATISTICS(jniinvokation());
1365 exceptions_clear_exception();
1369 /* FatalError ******************************************************************
1371 Raises a fatal error and does not expect the VM to recover. This
1372 function does not return.
1374 *******************************************************************************/
1376 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1378 STATISTICS(jniinvokation());
1380 /* this seems to be the best way */
1386 /* PushLocalFrame **************************************************************
1388 Creates a new local reference frame, in which at least a given
1389 number of local references can be created.
1391 *******************************************************************************/
1393 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1396 localref_table *lrt;
1397 localref_table *nlrt;
1399 STATISTICS(jniinvokation());
1404 /* Allocate new local reference table on Java heap. Calculate the
1405 additional memory we have to allocate. */
1407 if (capacity > LOCALREFTABLE_CAPACITY)
1408 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1412 #if defined(ENABLE_GC_CACAO)
1413 nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1415 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1421 /* get current local reference table from thread */
1423 lrt = LOCALREFTABLE;
1425 /* Set up the new local reference table and add it to the local
1428 nlrt->capacity = capacity;
1430 nlrt->localframes = lrt->localframes + 1;
1433 /* store new local reference table in thread */
1435 LOCALREFTABLE = nlrt;
1441 /* PopLocalFrame ***************************************************************
1443 Pops off the current local reference frame, frees all the local
1444 references, and returns a local reference in the previous local
1445 reference frame for the given result object.
1447 *******************************************************************************/
1449 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1451 localref_table *lrt;
1452 localref_table *plrt;
1456 STATISTICS(jniinvokation());
1458 /* get current local reference table from thread */
1460 lrt = LOCALREFTABLE;
1462 localframes = lrt->localframes;
1464 /* Don't delete the top local frame, as this one is allocated in
1465 the native stub on the stack and is freed automagically on
1468 if (localframes == 1)
1469 return _Jv_JNI_NewLocalRef(env, result);
1471 /* release all current local frames */
1473 for (; localframes >= 1; localframes--) {
1474 /* get previous frame */
1478 /* clear all reference entries */
1480 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1484 #if defined(ENABLE_GC_CACAO)
1485 /* for the exact GC local reference tables are not on the heap,
1486 so we need to free them explicitly here. */
1488 if (lrt->capacity > LOCALREFTABLE_CAPACITY)
1489 additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
1493 MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1496 /* set new local references table */
1501 /* store new local reference table in thread */
1503 LOCALREFTABLE = lrt;
1505 /* add local reference and return the value */
1507 return _Jv_JNI_NewLocalRef(env, result);
1511 /* DeleteLocalRef **************************************************************
1513 Deletes the local reference pointed to by localRef.
1515 *******************************************************************************/
1517 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1519 java_objectheader *o;
1520 localref_table *lrt;
1523 STATISTICS(jniinvokation());
1525 o = (java_objectheader *) localRef;
1527 /* get local reference table (thread specific) */
1529 lrt = LOCALREFTABLE;
1531 /* go through all local frames */
1533 for (; lrt != NULL; lrt = lrt->prev) {
1535 /* and try to remove the reference */
1537 for (i = 0; i < lrt->capacity; i++) {
1538 if (lrt->refs[i] == o) {
1539 lrt->refs[i] = NULL;
1547 /* this should not happen */
1549 /* if (opt_checkjni) */
1550 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1551 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1555 /* IsSameObject ****************************************************************
1557 Tests whether two references refer to the same Java object.
1559 *******************************************************************************/
1561 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1563 STATISTICS(jniinvokation());
1572 /* NewLocalRef *****************************************************************
1574 Creates a new local reference that refers to the same object as ref.
1576 *******************************************************************************/
1578 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1580 localref_table *lrt;
1583 STATISTICS(jniinvokation());
1588 /* get local reference table (thread specific) */
1590 lrt = LOCALREFTABLE;
1592 /* Check if we have space for the requested reference? No,
1593 allocate a new frame. This is actually not what the spec says,
1594 but for compatibility reasons... */
1596 if (lrt->used == lrt->capacity) {
1597 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1600 /* get the new local reference table */
1602 lrt = LOCALREFTABLE;
1605 /* insert the reference */
1607 for (i = 0; i < lrt->capacity; i++) {
1608 if (lrt->refs[i] == NULL) {
1609 lrt->refs[i] = (java_objectheader *) ref;
1616 /* should not happen, just to be sure */
1620 /* keep compiler happy */
1626 /* EnsureLocalCapacity *********************************************************
1628 Ensures that at least a given number of local references can be
1629 created in the current thread
1631 *******************************************************************************/
1633 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1635 localref_table *lrt;
1637 STATISTICS(jniinvokation());
1639 /* get local reference table (thread specific) */
1641 lrt = LOCALREFTABLE;
1643 /* check if capacity elements are available in the local references table */
1645 if ((lrt->used + capacity) > lrt->capacity)
1646 return _Jv_JNI_PushLocalFrame(env, capacity);
1652 /* AllocObject *****************************************************************
1654 Allocates a new Java object without invoking any of the
1655 constructors for the object. Returns a reference to the object.
1657 *******************************************************************************/
1659 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1662 java_objectheader *o;
1664 STATISTICS(jniinvokation());
1666 c = (classinfo *) clazz;
1668 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1669 exceptions_throw_instantiationexception(c);
1675 return _Jv_JNI_NewLocalRef(env, o);
1679 /* NewObject *******************************************************************
1681 Programmers place all arguments that are to be passed to the
1682 constructor immediately following the methodID
1683 argument. NewObject() accepts these arguments and passes them to
1684 the Java method that the programmer wishes to invoke.
1686 *******************************************************************************/
1688 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1690 java_objectheader *o;
1694 STATISTICS(jniinvokation());
1696 m = (methodinfo *) methodID;
1700 o = builtin_new(clazz);
1705 /* call constructor */
1707 va_start(ap, methodID);
1708 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1711 return _Jv_JNI_NewLocalRef(env, o);
1715 /* NewObjectV ******************************************************************
1717 Programmers place all arguments that are to be passed to the
1718 constructor in an args argument of type va_list that immediately
1719 follows the methodID argument. NewObjectV() accepts these
1720 arguments, and, in turn, passes them to the Java method that the
1721 programmer wishes to invoke.
1723 *******************************************************************************/
1725 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1728 java_objectheader *o;
1731 STATISTICS(jniinvokation());
1733 m = (methodinfo *) methodID;
1737 o = builtin_new(clazz);
1742 /* call constructor */
1744 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1746 return _Jv_JNI_NewLocalRef(env, o);
1750 /* NewObjectA *****************************************************************
1752 Programmers place all arguments that are to be passed to the
1753 constructor in an args array of jvalues that immediately follows
1754 the methodID argument. NewObjectA() accepts the arguments in this
1755 array, and, in turn, passes them to the Java method that the
1756 programmer wishes to invoke.
1758 *******************************************************************************/
1760 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1763 java_objectheader *o;
1766 STATISTICS(jniinvokation());
1768 m = (methodinfo *) methodID;
1772 o = builtin_new(clazz);
1777 /* call constructor */
1779 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1781 return _Jv_JNI_NewLocalRef(env, o);
1785 /* GetObjectClass **************************************************************
1787 Returns the class of an object.
1789 *******************************************************************************/
1791 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1793 java_objectheader *o;
1796 STATISTICS(jniinvokation());
1798 o = (java_objectheader *) obj;
1800 if ((o == NULL) || (o->vftbl == NULL))
1803 c = o->vftbl->class;
1805 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1809 /* IsInstanceOf ****************************************************************
1811 Tests whether an object is an instance of a class.
1813 *******************************************************************************/
1815 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1818 java_lang_Object *o;
1820 STATISTICS(jniinvokation());
1822 c = (java_lang_Class *) clazz;
1823 o = (java_lang_Object *) obj;
1825 return _Jv_java_lang_Class_isInstance(c, o);
1829 /* Reflection Support *********************************************************/
1831 /* FromReflectedMethod *********************************************************
1833 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1834 object to a method ID.
1836 *******************************************************************************/
1838 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1840 #if defined(ENABLE_JAVASE)
1845 STATISTICS(jniinvokation());
1850 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1851 java_lang_reflect_Method *rm;
1853 rm = (java_lang_reflect_Method *) method;
1854 c = (classinfo *) (rm->declaringClass);
1857 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1858 java_lang_reflect_Constructor *rc;
1860 rc = (java_lang_reflect_Constructor *) method;
1861 c = (classinfo *) (rc->clazz);
1867 mi = &(c->methods[slot]);
1869 return (jmethodID) mi;
1871 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1873 /* keep compiler happy */
1880 /* FromReflectedField **********************************************************
1882 Converts a java.lang.reflect.Field to a field ID.
1884 *******************************************************************************/
1886 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1888 #if defined(ENABLE_JAVASE)
1889 java_lang_reflect_Field *rf;
1893 STATISTICS(jniinvokation());
1895 rf = (java_lang_reflect_Field *) field;
1900 c = (classinfo *) rf->declaringClass;
1902 f = &(c->fields[rf->slot]);
1904 return (jfieldID) f;
1906 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1908 /* keep compiler happy */
1915 /* ToReflectedMethod ***********************************************************
1917 Converts a method ID derived from cls to an instance of the
1918 java.lang.reflect.Method class or to an instance of the
1919 java.lang.reflect.Constructor class.
1921 *******************************************************************************/
1923 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1926 STATISTICS(jniinvokation());
1928 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1934 /* ToReflectedField ************************************************************
1936 Converts a field ID derived from cls to an instance of the
1937 java.lang.reflect.Field class.
1939 *******************************************************************************/
1941 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1944 STATISTICS(jniinvokation());
1946 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1952 /* Calling Instance Methods ***************************************************/
1954 /* GetMethodID *****************************************************************
1956 Returns the method ID for an instance (nonstatic) method of a class
1957 or interface. The method may be defined in one of the clazz's
1958 superclasses and inherited by clazz. The method is determined by
1959 its name and signature.
1961 GetMethodID() causes an uninitialized class to be initialized.
1963 *******************************************************************************/
1965 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1973 STATISTICS(jniinvokation());
1975 c = (classinfo *) clazz;
1980 if (!(c->state & CLASS_INITIALIZED))
1981 if (!initialize_class(c))
1984 /* try to get the method of the class or one of it's superclasses */
1986 uname = utf_new_char((char *) name);
1987 udesc = utf_new_char((char *) sig);
1989 m = class_resolvemethod(clazz, uname, udesc);
1991 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1992 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1997 return (jmethodID) m;
2001 /* JNI-functions for calling instance methods *********************************/
2003 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2006 java_objectheader *o;
2008 java_objectheader *ret;
2011 o = (java_objectheader *) obj;
2012 m = (methodinfo *) methodID;
2014 va_start(ap, methodID);
2015 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2018 return _Jv_JNI_NewLocalRef(env, ret);
2022 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2025 java_objectheader *o;
2027 java_objectheader *ret;
2029 o = (java_objectheader *) obj;
2030 m = (methodinfo *) methodID;
2032 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2034 return _Jv_JNI_NewLocalRef(env, ret);
2038 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2041 java_objectheader *o;
2043 java_objectheader *ret;
2045 o = (java_objectheader *) obj;
2046 m = (methodinfo *) methodID;
2048 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2050 return _Jv_JNI_NewLocalRef(env, ret);
2054 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2057 java_objectheader *o;
2062 o = (java_objectheader *) obj;
2063 m = (methodinfo *) methodID;
2065 va_start(ap, methodID);
2066 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2073 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2074 jmethodID methodID, va_list args)
2076 java_objectheader *o;
2080 o = (java_objectheader *) obj;
2081 m = (methodinfo *) methodID;
2083 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2089 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2090 jmethodID methodID, jvalue *args)
2092 java_objectheader *o;
2096 o = (java_objectheader *) obj;
2097 m = (methodinfo *) methodID;
2099 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2105 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2107 java_objectheader *o;
2112 o = (java_objectheader *) obj;
2113 m = (methodinfo *) methodID;
2115 va_start(ap, methodID);
2116 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2124 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2127 java_objectheader *o;
2131 o = (java_objectheader *) obj;
2132 m = (methodinfo *) methodID;
2134 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2140 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2143 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2149 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2151 java_objectheader *o;
2156 o = (java_objectheader *) obj;
2157 m = (methodinfo *) methodID;
2159 va_start(ap, methodID);
2160 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2167 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2170 java_objectheader *o;
2174 o = (java_objectheader *) obj;
2175 m = (methodinfo *) methodID;
2177 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2183 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2186 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2192 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2195 java_objectheader *o;
2200 o = (java_objectheader *) obj;
2201 m = (methodinfo *) methodID;
2203 va_start(ap, methodID);
2204 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2211 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2214 java_objectheader *o;
2218 o = (java_objectheader *) obj;
2219 m = (methodinfo *) methodID;
2221 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2227 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2230 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2237 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2239 java_objectheader *o;
2244 o = (java_objectheader *) obj;
2245 m = (methodinfo *) methodID;
2247 va_start(ap, methodID);
2248 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2255 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2258 java_objectheader *o;
2262 o = (java_objectheader *) obj;
2263 m = (methodinfo *) methodID;
2265 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2271 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2274 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2281 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2283 java_objectheader *o;
2288 o = (java_objectheader *) obj;
2289 m = (methodinfo *) methodID;
2291 va_start(ap, methodID);
2292 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2299 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2302 java_objectheader *o;
2306 o = (java_objectheader *) obj;
2307 m = (methodinfo *) methodID;
2309 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2315 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2318 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2325 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2328 java_objectheader *o;
2333 o = (java_objectheader *) obj;
2334 m = (methodinfo *) methodID;
2336 va_start(ap, methodID);
2337 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2344 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2347 java_objectheader *o;
2351 o = (java_objectheader *) obj;
2352 m = (methodinfo *) methodID;
2354 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2360 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2363 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2370 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2373 java_objectheader *o;
2378 o = (java_objectheader *) obj;
2379 m = (methodinfo *) methodID;
2381 va_start(ap, methodID);
2382 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2389 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2392 java_objectheader *o;
2396 o = (java_objectheader *) obj;
2397 m = (methodinfo *) methodID;
2399 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2405 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2408 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2415 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2417 java_objectheader *o;
2421 o = (java_objectheader *) obj;
2422 m = (methodinfo *) methodID;
2424 va_start(ap, methodID);
2425 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2430 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2433 java_objectheader *o;
2436 o = (java_objectheader *) obj;
2437 m = (methodinfo *) methodID;
2439 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2443 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2446 java_objectheader *o;
2449 o = (java_objectheader *) obj;
2450 m = (methodinfo *) methodID;
2452 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2457 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2458 jclass clazz, jmethodID methodID,
2461 java_objectheader *o;
2464 java_objectheader *r;
2467 o = (java_objectheader *) obj;
2468 c = (classinfo *) clazz;
2469 m = (methodinfo *) methodID;
2471 va_start(ap, methodID);
2472 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2475 return _Jv_JNI_NewLocalRef(env, r);
2479 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2480 jclass clazz, jmethodID methodID,
2483 java_objectheader *o;
2486 java_objectheader *r;
2488 o = (java_objectheader *) obj;
2489 c = (classinfo *) clazz;
2490 m = (methodinfo *) methodID;
2492 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2494 return _Jv_JNI_NewLocalRef(env, r);
2498 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2499 jclass clazz, jmethodID methodID,
2502 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2504 return _Jv_JNI_NewLocalRef(env, NULL);
2509 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2510 jclass clazz, jmethodID methodID,
2513 java_objectheader *o;
2519 o = (java_objectheader *) obj;
2520 c = (classinfo *) clazz;
2521 m = (methodinfo *) methodID;
2523 va_start(ap, methodID);
2524 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2531 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2532 jclass clazz, jmethodID methodID,
2535 java_objectheader *o;
2540 o = (java_objectheader *) obj;
2541 c = (classinfo *) clazz;
2542 m = (methodinfo *) methodID;
2544 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2550 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2551 jclass clazz, jmethodID methodID,
2554 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2560 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2561 jmethodID methodID, ...)
2563 java_objectheader *o;
2569 o = (java_objectheader *) obj;
2570 c = (classinfo *) clazz;
2571 m = (methodinfo *) methodID;
2573 va_start(ap, methodID);
2574 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2581 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2582 jmethodID methodID, va_list args)
2584 java_objectheader *o;
2589 o = (java_objectheader *) obj;
2590 c = (classinfo *) clazz;
2591 m = (methodinfo *) methodID;
2593 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2599 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2600 jmethodID methodID, jvalue *args)
2602 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2609 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2610 jmethodID methodID, ...)
2612 java_objectheader *o;
2618 o = (java_objectheader *) obj;
2619 c = (classinfo *) clazz;
2620 m = (methodinfo *) methodID;
2622 va_start(ap, methodID);
2623 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2630 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2631 jmethodID methodID, va_list args)
2633 java_objectheader *o;
2638 o = (java_objectheader *) obj;
2639 c = (classinfo *) clazz;
2640 m = (methodinfo *) methodID;
2642 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2648 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2649 jmethodID methodID, jvalue *args)
2651 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2658 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2659 jclass clazz, jmethodID methodID, ...)
2661 java_objectheader *o;
2667 o = (java_objectheader *) obj;
2668 c = (classinfo *) clazz;
2669 m = (methodinfo *) methodID;
2671 va_start(ap, methodID);
2672 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2679 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2680 jclass clazz, jmethodID methodID,
2683 java_objectheader *o;
2688 o = (java_objectheader *) obj;
2689 c = (classinfo *) clazz;
2690 m = (methodinfo *) methodID;
2692 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2698 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2699 jclass clazz, jmethodID methodID,
2702 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2709 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2710 jmethodID methodID, ...)
2712 java_objectheader *o;
2718 o = (java_objectheader *) obj;
2719 c = (classinfo *) clazz;
2720 m = (methodinfo *) methodID;
2722 va_start(ap, methodID);
2723 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2730 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2731 jmethodID methodID, va_list args)
2733 java_objectheader *o;
2738 o = (java_objectheader *) obj;
2739 c = (classinfo *) clazz;
2740 m = (methodinfo *) methodID;
2742 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2748 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2749 jmethodID methodID, jvalue *args)
2751 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2758 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2759 jmethodID methodID, ...)
2761 java_objectheader *o;
2767 o = (java_objectheader *) obj;
2768 c = (classinfo *) clazz;
2769 m = (methodinfo *) methodID;
2771 va_start(ap, methodID);
2772 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2779 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2780 jmethodID methodID, va_list args)
2782 java_objectheader *o;
2787 o = (java_objectheader *) obj;
2788 c = (classinfo *) clazz;
2789 m = (methodinfo *) methodID;
2791 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2797 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2798 jmethodID methodID, jvalue *args)
2800 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2807 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2808 jclass clazz, jmethodID methodID, ...)
2810 java_objectheader *o;
2816 o = (java_objectheader *) obj;
2817 c = (classinfo *) clazz;
2818 m = (methodinfo *) methodID;
2820 va_start(ap, methodID);
2821 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2828 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2829 jclass clazz, jmethodID methodID,
2832 java_objectheader *o;
2837 o = (java_objectheader *) obj;
2838 c = (classinfo *) clazz;
2839 m = (methodinfo *) methodID;
2841 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2847 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2848 jclass clazz, jmethodID methodID,
2851 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2858 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2859 jclass clazz, jmethodID methodID,
2862 java_objectheader *o;
2868 o = (java_objectheader *) obj;
2869 c = (classinfo *) clazz;
2870 m = (methodinfo *) methodID;
2872 va_start(ap, methodID);
2873 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2880 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2881 jclass clazz, jmethodID methodID,
2884 java_objectheader *o;
2889 o = (java_objectheader *) obj;
2890 c = (classinfo *) clazz;
2891 m = (methodinfo *) methodID;
2893 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2899 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2900 jclass clazz, jmethodID methodID,
2903 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2910 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2911 jmethodID methodID, ...)
2913 java_objectheader *o;
2918 o = (java_objectheader *) obj;
2919 c = (classinfo *) clazz;
2920 m = (methodinfo *) methodID;
2922 va_start(ap, methodID);
2923 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2928 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2929 jmethodID methodID, va_list args)
2931 java_objectheader *o;
2935 o = (java_objectheader *) obj;
2936 c = (classinfo *) clazz;
2937 m = (methodinfo *) methodID;
2939 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2943 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2944 jmethodID methodID, jvalue * args)
2946 java_objectheader *o;
2950 o = (java_objectheader *) obj;
2951 c = (classinfo *) clazz;
2952 m = (methodinfo *) methodID;
2954 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2958 /* Accessing Fields of Objects ************************************************/
2960 /* GetFieldID ******************************************************************
2962 Returns the field ID for an instance (nonstatic) field of a
2963 class. The field is specified by its name and signature. The
2964 Get<type>Field and Set<type>Field families of accessor functions
2965 use field IDs to retrieve object fields.
2967 *******************************************************************************/
2969 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2977 STATISTICS(jniinvokation());
2979 c = (classinfo *) clazz;
2981 uname = utf_new_char((char *) name);
2982 udesc = utf_new_char((char *) sig);
2984 f = class_findfield(clazz, uname, udesc);
2987 exceptions_throw_nosuchfielderror(c, uname);
2989 return (jfieldID) f;
2993 /* Get<type>Field Routines *****************************************************
2995 This family of accessor routines returns the value of an instance
2996 (nonstatic) field of an object. The field to access is specified by
2997 a field ID obtained by calling GetFieldID().
2999 *******************************************************************************/
3001 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3003 java_objectheader *o;
3005 STATISTICS(jniinvokation());
3007 o = GET_FIELD(obj, java_objectheader*, fieldID);
3009 return _Jv_JNI_NewLocalRef(env, o);
3013 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3017 STATISTICS(jniinvokation());
3019 i = GET_FIELD(obj, s4, fieldID);
3021 return (jboolean) i;
3025 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3029 STATISTICS(jniinvokation());
3031 i = GET_FIELD(obj, s4, fieldID);
3037 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3041 STATISTICS(jniinvokation());
3043 i = GET_FIELD(obj, s4, fieldID);
3049 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3053 STATISTICS(jniinvokation());
3055 i = GET_FIELD(obj, s4, fieldID);
3061 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3063 java_objectheader *o;
3067 STATISTICS(jniinvokation());
3069 o = (java_objectheader *) obj;
3070 f = (fieldinfo *) fieldID;
3072 i = GET_FIELD(o, s4, f);
3078 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3082 STATISTICS(jniinvokation());
3084 l = GET_FIELD(obj, s8, fieldID);
3090 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3094 STATISTICS(jniinvokation());
3096 f = GET_FIELD(obj, float, fieldID);
3102 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3106 STATISTICS(jniinvokation());
3108 d = GET_FIELD(obj, double, fieldID);
3114 /* Set<type>Field Routines *****************************************************
3116 This family of accessor routines sets the value of an instance
3117 (nonstatic) field of an object. The field to access is specified by
3118 a field ID obtained by calling GetFieldID().
3120 *******************************************************************************/
3122 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3125 STATISTICS(jniinvokation());
3127 SET_FIELD(obj, java_objectheader*, fieldID, value);
3131 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3134 STATISTICS(jniinvokation());
3136 SET_FIELD(obj, s4, fieldID, value);
3140 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3143 STATISTICS(jniinvokation());
3145 SET_FIELD(obj, s4, fieldID, value);
3149 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3152 STATISTICS(jniinvokation());
3154 SET_FIELD(obj, s4, fieldID, value);
3158 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3161 STATISTICS(jniinvokation());
3163 SET_FIELD(obj, s4, fieldID, value);
3167 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3169 STATISTICS(jniinvokation());
3171 SET_FIELD(obj, s4, fieldID, value);
3175 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3178 STATISTICS(jniinvokation());
3180 SET_FIELD(obj, s8, fieldID, value);
3184 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3187 STATISTICS(jniinvokation());
3189 SET_FIELD(obj, float, fieldID, value);
3193 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3196 STATISTICS(jniinvokation());
3198 SET_FIELD(obj, double, fieldID, value);
3202 /* Calling Static Methods *****************************************************/
3204 /* GetStaticMethodID ***********************************************************
3206 Returns the method ID for a static method of a class. The method is
3207 specified by its name and signature.
3209 GetStaticMethodID() causes an uninitialized class to be
3212 *******************************************************************************/
3214 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3222 STATISTICS(jniinvokation());
3224 c = (classinfo *) clazz;
3229 if (!(c->state & CLASS_INITIALIZED))
3230 if (!initialize_class(c))
3233 /* try to get the static method of the class */
3235 uname = utf_new_char((char *) name);
3236 udesc = utf_new_char((char *) sig);
3238 m = class_resolvemethod(c, uname, udesc);
3240 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3241 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3246 return (jmethodID) m;
3250 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3251 jmethodID methodID, ...)
3254 java_objectheader *o;
3257 m = (methodinfo *) methodID;
3259 va_start(ap, methodID);
3260 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3263 return _Jv_JNI_NewLocalRef(env, o);
3267 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3268 jmethodID methodID, va_list args)
3271 java_objectheader *o;
3273 m = (methodinfo *) methodID;
3275 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3277 return _Jv_JNI_NewLocalRef(env, o);
3281 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3282 jmethodID methodID, jvalue *args)
3285 java_objectheader *o;
3287 m = (methodinfo *) methodID;
3289 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3291 return _Jv_JNI_NewLocalRef(env, o);
3295 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3296 jmethodID methodID, ...)
3302 m = (methodinfo *) methodID;
3304 va_start(ap, methodID);
3305 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3312 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3313 jmethodID methodID, va_list args)
3318 m = (methodinfo *) methodID;
3320 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3326 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3327 jmethodID methodID, jvalue *args)
3329 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3335 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3336 jmethodID methodID, ...)
3342 m = (methodinfo *) methodID;
3344 va_start(ap, methodID);
3345 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3352 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3353 jmethodID methodID, va_list args)
3358 m = (methodinfo *) methodID;
3360 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3366 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3367 jmethodID methodID, jvalue *args)
3369 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3375 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3376 jmethodID methodID, ...)
3382 m = (methodinfo *) methodID;
3384 va_start(ap, methodID);
3385 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3392 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3393 jmethodID methodID, va_list args)
3398 m = (methodinfo *) methodID;
3400 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3406 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3407 jmethodID methodID, jvalue *args)
3409 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3415 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3416 jmethodID methodID, ...)
3422 m = (methodinfo *) methodID;
3424 va_start(ap, methodID);
3425 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3432 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3433 jmethodID methodID, va_list args)
3438 m = (methodinfo *) methodID;
3440 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3446 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3447 jmethodID methodID, jvalue *args)
3449 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3455 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3462 m = (methodinfo *) methodID;
3464 va_start(ap, methodID);
3465 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3472 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3473 jmethodID methodID, va_list args)
3478 m = (methodinfo *) methodID;
3480 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3486 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3487 jmethodID methodID, jvalue *args)
3489 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3495 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3496 jmethodID methodID, ...)
3502 m = (methodinfo *) methodID;
3504 va_start(ap, methodID);
3505 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3512 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3513 jmethodID methodID, va_list args)
3518 m = (methodinfo *) methodID;
3520 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3526 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3527 jmethodID methodID, jvalue *args)
3529 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3536 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3537 jmethodID methodID, ...)
3543 m = (methodinfo *) methodID;
3545 va_start(ap, methodID);
3546 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3553 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3554 jmethodID methodID, va_list args)
3559 m = (methodinfo *) methodID;
3561 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3567 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3568 jmethodID methodID, jvalue *args)
3570 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3576 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3577 jmethodID methodID, ...)
3583 m = (methodinfo *) methodID;
3585 va_start(ap, methodID);
3586 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3593 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3594 jmethodID methodID, va_list args)
3599 m = (methodinfo *) methodID;
3601 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3607 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3608 jmethodID methodID, jvalue *args)
3610 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3616 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3617 jmethodID methodID, ...)
3622 m = (methodinfo *) methodID;
3624 va_start(ap, methodID);
3625 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3630 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3631 jmethodID methodID, va_list args)
3635 m = (methodinfo *) methodID;
3637 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3641 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3642 jmethodID methodID, jvalue * args)
3646 m = (methodinfo *) methodID;
3648 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3652 /* Accessing Static Fields ****************************************************/
3654 /* GetStaticFieldID ************************************************************
3656 Returns the field ID for a static field of a class. The field is
3657 specified by its name and signature. The GetStatic<type>Field and
3658 SetStatic<type>Field families of accessor functions use field IDs
3659 to retrieve static fields.
3661 *******************************************************************************/
3663 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3671 STATISTICS(jniinvokation());
3673 c = (classinfo *) clazz;
3675 uname = utf_new_char((char *) name);
3676 usig = utf_new_char((char *) sig);
3678 f = class_findfield(clazz, uname, usig);
3681 exceptions_throw_nosuchfielderror(c, uname);
3683 return (jfieldID) f;
3687 /* GetStatic<type>Field ********************************************************
3689 This family of accessor routines returns the value of a static
3692 *******************************************************************************/
3694 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3700 STATISTICS(jniinvokation());
3702 c = (classinfo *) clazz;
3703 f = (fieldinfo *) fieldID;
3705 if (!(c->state & CLASS_INITIALIZED))
3706 if (!initialize_class(c))
3709 return _Jv_JNI_NewLocalRef(env, f->value.a);
3713 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3719 STATISTICS(jniinvokation());
3721 c = (classinfo *) clazz;
3722 f = (fieldinfo *) fieldID;
3724 if (!(c->state & CLASS_INITIALIZED))
3725 if (!initialize_class(c))
3732 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3737 STATISTICS(jniinvokation());
3739 c = (classinfo *) clazz;
3740 f = (fieldinfo *) fieldID;
3742 if (!(c->state & CLASS_INITIALIZED))
3743 if (!initialize_class(c))
3750 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3755 STATISTICS(jniinvokation());
3757 c = (classinfo *) clazz;
3758 f = (fieldinfo *) fieldID;
3760 if (!(c->state & CLASS_INITIALIZED))
3761 if (!initialize_class(c))
3768 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3773 STATISTICS(jniinvokation());
3775 c = (classinfo *) clazz;
3776 f = (fieldinfo *) fieldID;
3778 if (!(c->state & CLASS_INITIALIZED))
3779 if (!initialize_class(c))
3786 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3791 STATISTICS(jniinvokation());
3793 c = (classinfo *) clazz;
3794 f = (fieldinfo *) fieldID;
3796 if (!(c->state & CLASS_INITIALIZED))
3797 if (!initialize_class(c))
3804 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3809 STATISTICS(jniinvokation());
3811 c = (classinfo *) clazz;
3812 f = (fieldinfo *) fieldID;
3814 if (!(c->state & CLASS_INITIALIZED))
3815 if (!initialize_class(c))
3822 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3827 STATISTICS(jniinvokation());
3829 c = (classinfo *) clazz;
3830 f = (fieldinfo *) fieldID;
3832 if (!(c->state & CLASS_INITIALIZED))
3833 if (!initialize_class(c))
3840 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3846 STATISTICS(jniinvokation());
3848 c = (classinfo *) clazz;
3849 f = (fieldinfo *) fieldID;
3851 if (!(c->state & CLASS_INITIALIZED))
3852 if (!initialize_class(c))
3859 /* SetStatic<type>Field *******************************************************
3861 This family of accessor routines sets the value of a static field
3864 *******************************************************************************/
3866 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3872 STATISTICS(jniinvokation());
3874 c = (classinfo *) clazz;
3875 f = (fieldinfo *) fieldID;
3877 if (!(c->state & CLASS_INITIALIZED))
3878 if (!initialize_class(c))
3885 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3891 STATISTICS(jniinvokation());
3893 c = (classinfo *) clazz;
3894 f = (fieldinfo *) fieldID;
3896 if (!(c->state & CLASS_INITIALIZED))
3897 if (!initialize_class(c))
3904 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3910 STATISTICS(jniinvokation());
3912 c = (classinfo *) clazz;
3913 f = (fieldinfo *) fieldID;
3915 if (!(c->state & CLASS_INITIALIZED))
3916 if (!initialize_class(c))
3923 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3929 STATISTICS(jniinvokation());
3931 c = (classinfo *) clazz;
3932 f = (fieldinfo *) fieldID;
3934 if (!(c->state & CLASS_INITIALIZED))
3935 if (!initialize_class(c))
3942 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3948 STATISTICS(jniinvokation());
3950 c = (classinfo *) clazz;
3951 f = (fieldinfo *) fieldID;
3953 if (!(c->state & CLASS_INITIALIZED))
3954 if (!initialize_class(c))
3961 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3967 STATISTICS(jniinvokation());
3969 c = (classinfo *) clazz;
3970 f = (fieldinfo *) fieldID;
3972 if (!(c->state & CLASS_INITIALIZED))
3973 if (!initialize_class(c))
3980 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3986 STATISTICS(jniinvokation());
3988 c = (classinfo *) clazz;
3989 f = (fieldinfo *) fieldID;
3991 if (!(c->state & CLASS_INITIALIZED))
3992 if (!initialize_class(c))
3999 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4005 STATISTICS(jniinvokation());
4007 c = (classinfo *) clazz;
4008 f = (fieldinfo *) fieldID;
4010 if (!(c->state & CLASS_INITIALIZED))
4011 if (!initialize_class(c))
4018 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4024 STATISTICS(jniinvokation());
4026 c = (classinfo *) clazz;
4027 f = (fieldinfo *) fieldID;
4029 if (!(c->state & CLASS_INITIALIZED))
4030 if (!initialize_class(c))
4037 /* String Operations **********************************************************/
4039 /* NewString *******************************************************************
4041 Create new java.lang.String object from an array of Unicode
4044 *******************************************************************************/
4046 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4048 java_lang_String *s;
4052 STATISTICS(jniinvokation());
4054 s = (java_lang_String *) builtin_new(class_java_lang_String);
4055 a = builtin_newarray_char(len);
4057 /* javastring or characterarray could not be created */
4058 if ((a == NULL) || (s == NULL))
4062 for (i = 0; i < len; i++)
4063 a->data[i] = buf[i];
4069 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4073 static jchar emptyStringJ[]={0,0};
4075 /* GetStringLength *************************************************************
4077 Returns the length (the count of Unicode characters) of a Java
4080 *******************************************************************************/
4082 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4084 return ((java_lang_String *) str)->count;
4088 /******************** convertes javastring to u2-array ****************************/
4090 u2 *javastring_tou2(jstring so)
4092 java_lang_String *s;
4097 STATISTICS(jniinvokation());
4099 s = (java_lang_String *) so;
4109 /* allocate memory */
4111 stringbuffer = MNEW(u2, s->count + 1);
4115 for (i = 0; i < s->count; i++)
4116 stringbuffer[i] = a->data[s->offset + i];
4118 /* terminate string */
4120 stringbuffer[i] = '\0';
4122 return stringbuffer;
4126 /* GetStringChars **************************************************************
4128 Returns a pointer to the array of Unicode characters of the
4129 string. This pointer is valid until ReleaseStringchars() is called.
4131 *******************************************************************************/
4133 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4137 STATISTICS(jniinvokation());
4139 jc = javastring_tou2(str);
4151 return emptyStringJ;
4155 /* ReleaseStringChars **********************************************************
4157 Informs the VM that the native code no longer needs access to
4158 chars. The chars argument is a pointer obtained from string using
4161 *******************************************************************************/
4163 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4165 STATISTICS(jniinvokation());
4167 if (chars == emptyStringJ)
4170 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4174 /* NewStringUTF ****************************************************************
4176 Constructs a new java.lang.String object from an array of UTF-8 characters.
4178 *******************************************************************************/
4180 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4182 java_lang_String *s;
4184 STATISTICS(jniinvokation());
4186 s = javastring_safe_new_from_utf8(bytes);
4188 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4192 /****************** returns the utf8 length in bytes of a string *******************/
4194 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4196 java_lang_String *s = (java_lang_String*) string;
4198 STATISTICS(jniinvokation());
4200 return (jsize) u2_utflength(s->value->data, s->count);
4204 /* GetStringUTFChars ***********************************************************
4206 Returns a pointer to an array of UTF-8 characters of the
4207 string. This array is valid until it is released by
4208 ReleaseStringUTFChars().
4210 *******************************************************************************/
4212 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4217 STATISTICS(jniinvokation());
4225 u = javastring_toutf((java_lang_String *) string, false);
4234 /* ReleaseStringUTFChars *******************************************************
4236 Informs the VM that the native code no longer needs access to
4237 utf. The utf argument is a pointer derived from string using
4238 GetStringUTFChars().
4240 *******************************************************************************/
4242 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4244 STATISTICS(jniinvokation());
4246 /* XXX we don't release utf chars right now, perhaps that should be done
4247 later. Since there is always one reference the garbage collector will
4252 /* Array Operations ***********************************************************/
4254 /* GetArrayLength **************************************************************
4256 Returns the number of elements in the array.
4258 *******************************************************************************/
4260 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4262 java_arrayheader *a;
4264 STATISTICS(jniinvokation());
4266 a = (java_arrayheader *) array;
4272 /* NewObjectArray **************************************************************
4274 Constructs a new array holding objects in class elementClass. All
4275 elements are initially set to initialElement.
4277 *******************************************************************************/
4279 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4280 jclass elementClass, jobject initialElement)
4282 java_objectarray *oa;
4285 STATISTICS(jniinvokation());
4288 exceptions_throw_negativearraysizeexception();
4292 oa = builtin_anewarray(length, elementClass);
4297 /* set all elements to initialElement */
4299 for (i = 0; i < length; i++)
4300 oa->data[i] = initialElement;
4302 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4306 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4309 java_objectarray *oa;
4312 STATISTICS(jniinvokation());
4314 oa = (java_objectarray *) array;
4316 if (index >= oa->header.size) {
4317 exceptions_throw_arrayindexoutofboundsexception();
4321 o = oa->data[index];
4323 return _Jv_JNI_NewLocalRef(env, o);
4327 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4328 jsize index, jobject val)
4330 java_objectarray *oa;
4331 java_objectheader *o;
4333 STATISTICS(jniinvokation());
4335 oa = (java_objectarray *) array;
4336 o = (java_objectheader *) val;
4338 if (index >= oa->header.size) {
4339 exceptions_throw_arrayindexoutofboundsexception();
4343 /* check if the class of value is a subclass of the element class
4346 if (!builtin_canstore(oa, o)) {
4347 exceptions_throw_arraystoreexception();
4351 oa->data[index] = val;
4355 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4357 java_booleanarray *ba;
4359 STATISTICS(jniinvokation());
4362 exceptions_throw_negativearraysizeexception();
4366 ba = builtin_newarray_boolean(len);
4368 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4372 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4376 STATISTICS(jniinvokation());
4379 exceptions_throw_negativearraysizeexception();
4383 ba = builtin_newarray_byte(len);
4385 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4389 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4393 STATISTICS(jniinvokation());
4396 exceptions_throw_negativearraysizeexception();
4400 ca = builtin_newarray_char(len);
4402 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4406 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4408 java_shortarray *sa;
4410 STATISTICS(jniinvokation());
4413 exceptions_throw_negativearraysizeexception();
4417 sa = builtin_newarray_short(len);
4419 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4423 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4427 STATISTICS(jniinvokation());
4430 exceptions_throw_negativearraysizeexception();
4434 ia = builtin_newarray_int(len);
4436 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4440 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4444 STATISTICS(jniinvokation());
4447 exceptions_throw_negativearraysizeexception();
4451 la = builtin_newarray_long(len);
4453 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4457 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4459 java_floatarray *fa;
4461 STATISTICS(jniinvokation());
4464 exceptions_throw_negativearraysizeexception();
4468 fa = builtin_newarray_float(len);
4470 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4474 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4476 java_doublearray *da;
4478 STATISTICS(jniinvokation());
4481 exceptions_throw_negativearraysizeexception();
4485 da = builtin_newarray_double(len);
4487 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4491 /* Get<PrimitiveType>ArrayElements *********************************************
4493 A family of functions that returns the body of the primitive array.
4495 *******************************************************************************/
4497 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4500 java_booleanarray *ba;
4502 STATISTICS(jniinvokation());
4504 ba = (java_booleanarray *) array;
4507 *isCopy = JNI_FALSE;
4513 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4518 STATISTICS(jniinvokation());
4520 ba = (java_bytearray *) array;
4523 *isCopy = JNI_FALSE;
4529 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4534 STATISTICS(jniinvokation());
4536 ca = (java_chararray *) array;
4539 *isCopy = JNI_FALSE;
4545 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4548 java_shortarray *sa;
4550 STATISTICS(jniinvokation());
4552 sa = (java_shortarray *) array;
4555 *isCopy = JNI_FALSE;
4561 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4566 STATISTICS(jniinvokation());
4568 ia = (java_intarray *) array;
4571 *isCopy = JNI_FALSE;
4577 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4582 STATISTICS(jniinvokation());
4584 la = (java_longarray *) array;
4587 *isCopy = JNI_FALSE;
4589 /* We cast this one to prevent a compiler warning on 64-bit
4590 systems since GNU Classpath typedef jlong to long long. */
4592 return (jlong *) la->data;
4596 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4599 java_floatarray *fa;
4601 STATISTICS(jniinvokation());
4603 fa = (java_floatarray *) array;
4606 *isCopy = JNI_FALSE;
4612 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4615 java_doublearray *da;
4617 STATISTICS(jniinvokation());
4619 da = (java_doublearray *) array;
4622 *isCopy = JNI_FALSE;
4628 /* Release<PrimitiveType>ArrayElements *****************************************
4630 A family of functions that informs the VM that the native code no
4631 longer needs access to elems. The elems argument is a pointer
4632 derived from array using the corresponding
4633 Get<PrimitiveType>ArrayElements() function. If necessary, this
4634 function copies back all changes made to elems to the original
4637 *******************************************************************************/
4639 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4640 jboolean *elems, jint mode)
4642 java_booleanarray *ba;
4644 STATISTICS(jniinvokation());
4646 ba = (java_booleanarray *) array;
4648 if (elems != ba->data) {
4651 MCOPY(ba->data, elems, u1, ba->header.size);
4654 MCOPY(ba->data, elems, u1, ba->header.size);
4655 /* XXX TWISTI how should it be freed? */
4658 /* XXX TWISTI how should it be freed? */
4665 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4666 jbyte *elems, jint mode)
4670 STATISTICS(jniinvokation());
4672 ba = (java_bytearray *) array;
4674 if (elems != ba->data) {
4677 MCOPY(ba->data, elems, s1, ba->header.size);
4680 MCOPY(ba->data, elems, s1, ba->header.size);
4681 /* XXX TWISTI how should it be freed? */
4684 /* XXX TWISTI how should it be freed? */
4691 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4692 jchar *elems, jint mode)
4696 STATISTICS(jniinvokation());
4698 ca = (java_chararray *) array;
4700 if (elems != ca->data) {
4703 MCOPY(ca->data, elems, u2, ca->header.size);
4706 MCOPY(ca->data, elems, u2, ca->header.size);
4707 /* XXX TWISTI how should it be freed? */
4710 /* XXX TWISTI how should it be freed? */
4717 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4718 jshort *elems, jint mode)
4720 java_shortarray *sa;
4722 STATISTICS(jniinvokation());
4724 sa = (java_shortarray *) array;
4726 if (elems != sa->data) {
4729 MCOPY(sa->data, elems, s2, sa->header.size);
4732 MCOPY(sa->data, elems, s2, sa->header.size);
4733 /* XXX TWISTI how should it be freed? */
4736 /* XXX TWISTI how should it be freed? */
4743 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4748 STATISTICS(jniinvokation());
4750 ia = (java_intarray *) array;
4752 if (elems != ia->data) {
4755 MCOPY(ia->data, elems, s4, ia->header.size);
4758 MCOPY(ia->data, elems, s4, ia->header.size);
4759 /* XXX TWISTI how should it be freed? */
4762 /* XXX TWISTI how should it be freed? */
4769 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4770 jlong *elems, jint mode)
4774 STATISTICS(jniinvokation());
4776 la = (java_longarray *) array;
4778 /* We cast this one to prevent a compiler warning on 64-bit
4779 systems since GNU Classpath typedef jlong to long long. */
4781 if ((s8 *) elems != la->data) {
4784 MCOPY(la->data, elems, s8, la->header.size);
4787 MCOPY(la->data, elems, s8, la->header.size);
4788 /* XXX TWISTI how should it be freed? */
4791 /* XXX TWISTI how should it be freed? */
4798 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4799 jfloat *elems, jint mode)
4801 java_floatarray *fa;
4803 STATISTICS(jniinvokation());
4805 fa = (java_floatarray *) array;
4807 if (elems != fa->data) {
4810 MCOPY(fa->data, elems, float, fa->header.size);
4813 MCOPY(fa->data, elems, float, fa->header.size);
4814 /* XXX TWISTI how should it be freed? */
4817 /* XXX TWISTI how should it be freed? */
4824 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4825 jdouble *elems, jint mode)
4827 java_doublearray *da;
4829 STATISTICS(jniinvokation());
4831 da = (java_doublearray *) array;
4833 if (elems != da->data) {
4836 MCOPY(da->data, elems, double, da->header.size);
4839 MCOPY(da->data, elems, double, da->header.size);
4840 /* XXX TWISTI how should it be freed? */
4843 /* XXX TWISTI how should it be freed? */
4850 /* Get<PrimitiveType>ArrayRegion **********************************************
4852 A family of functions that copies a region of a primitive array
4855 *******************************************************************************/
4857 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4858 jsize start, jsize len, jboolean *buf)
4860 java_booleanarray *ba;
4862 STATISTICS(jniinvokation());
4864 ba = (java_booleanarray *) array;
4866 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4867 exceptions_throw_arrayindexoutofboundsexception();
4869 MCOPY(buf, &ba->data[start], u1, len);
4873 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4874 jsize len, jbyte *buf)
4878 STATISTICS(jniinvokation());
4880 ba = (java_bytearray *) array;
4882 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4883 exceptions_throw_arrayindexoutofboundsexception();
4885 MCOPY(buf, &ba->data[start], s1, len);
4889 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4890 jsize len, jchar *buf)
4894 STATISTICS(jniinvokation());
4896 ca = (java_chararray *) array;
4898 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4899 exceptions_throw_arrayindexoutofboundsexception();
4901 MCOPY(buf, &ca->data[start], u2, len);
4905 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4906 jsize len, jshort *buf)
4908 java_shortarray *sa;
4910 STATISTICS(jniinvokation());
4912 sa = (java_shortarray *) array;
4914 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4915 exceptions_throw_arrayindexoutofboundsexception();
4917 MCOPY(buf, &sa->data[start], s2, len);
4921 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4922 jsize len, jint *buf)
4926 STATISTICS(jniinvokation());
4928 ia = (java_intarray *) array;
4930 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4931 exceptions_throw_arrayindexoutofboundsexception();
4933 MCOPY(buf, &ia->data[start], s4, len);
4937 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4938 jsize len, jlong *buf)
4942 STATISTICS(jniinvokation());
4944 la = (java_longarray *) array;
4946 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4947 exceptions_throw_arrayindexoutofboundsexception();
4949 MCOPY(buf, &la->data[start], s8, len);
4953 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4954 jsize len, jfloat *buf)
4956 java_floatarray *fa;
4958 STATISTICS(jniinvokation());
4960 fa = (java_floatarray *) array;
4962 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4963 exceptions_throw_arrayindexoutofboundsexception();
4965 MCOPY(buf, &fa->data[start], float, len);
4969 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4970 jsize len, jdouble *buf)
4972 java_doublearray *da;
4974 STATISTICS(jniinvokation());
4976 da = (java_doublearray *) array;
4978 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4979 exceptions_throw_arrayindexoutofboundsexception();
4981 MCOPY(buf, &da->data[start], double, len);
4985 /* Set<PrimitiveType>ArrayRegion **********************************************
4987 A family of functions that copies back a region of a primitive
4988 array from a buffer.
4990 *******************************************************************************/
4992 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4993 jsize start, jsize len, jboolean *buf)
4995 java_booleanarray *ba;
4997 STATISTICS(jniinvokation());
4999 ba = (java_booleanarray *) array;
5001 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5002 exceptions_throw_arrayindexoutofboundsexception();
5004 MCOPY(&ba->data[start], buf, u1, len);
5008 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5009 jsize len, jbyte *buf)
5013 STATISTICS(jniinvokation());
5015 ba = (java_bytearray *) array;
5017 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5018 exceptions_throw_arrayindexoutofboundsexception();
5020 MCOPY(&ba->data[start], buf, s1, len);
5024 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5025 jsize len, jchar *buf)
5029 STATISTICS(jniinvokation());
5031 ca = (java_chararray *) array;
5033 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5034 exceptions_throw_arrayindexoutofboundsexception();
5036 MCOPY(&ca->data[start], buf, u2, len);
5040 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5041 jsize len, jshort *buf)
5043 java_shortarray *sa;
5045 STATISTICS(jniinvokation());
5047 sa = (java_shortarray *) array;
5049 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5050 exceptions_throw_arrayindexoutofboundsexception();
5052 MCOPY(&sa->data[start], buf, s2, len);
5056 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5057 jsize len, jint *buf)
5061 STATISTICS(jniinvokation());
5063 ia = (java_intarray *) array;
5065 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5066 exceptions_throw_arrayindexoutofboundsexception();
5068 MCOPY(&ia->data[start], buf, s4, len);
5072 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5073 jsize len, jlong *buf)
5077 STATISTICS(jniinvokation());
5079 la = (java_longarray *) array;
5081 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5082 exceptions_throw_arrayindexoutofboundsexception();
5084 MCOPY(&la->data[start], buf, s8, len);
5088 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5089 jsize len, jfloat *buf)
5091 java_floatarray *fa;
5093 STATISTICS(jniinvokation());
5095 fa = (java_floatarray *) array;
5097 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5098 exceptions_throw_arrayindexoutofboundsexception();
5100 MCOPY(&fa->data[start], buf, float, len);
5104 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5105 jsize len, jdouble *buf)
5107 java_doublearray *da;
5109 STATISTICS(jniinvokation());
5111 da = (java_doublearray *) array;
5113 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5114 exceptions_throw_arrayindexoutofboundsexception();
5116 MCOPY(&da->data[start], buf, double, len);
5120 /* Registering Native Methods *************************************************/
5122 /* RegisterNatives *************************************************************
5124 Registers native methods with the class specified by the clazz
5125 argument. The methods parameter specifies an array of
5126 JNINativeMethod structures that contain the names, signatures, and
5127 function pointers of the native methods. The nMethods parameter
5128 specifies the number of native methods in the array.
5130 *******************************************************************************/
5132 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5133 const JNINativeMethod *methods, jint nMethods)
5135 STATISTICS(jniinvokation());
5137 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5138 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5139 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5146 /* UnregisterNatives ***********************************************************
5148 Unregisters native methods of a class. The class goes back to the
5149 state before it was linked or registered with its native method
5152 This function should not be used in normal native code. Instead, it
5153 provides special programs a way to reload and relink native
5156 *******************************************************************************/
5158 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5160 STATISTICS(jniinvokation());
5162 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5164 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5170 /* Monitor Operations *********************************************************/
5172 /* MonitorEnter ****************************************************************
5174 Enters the monitor associated with the underlying Java object
5177 *******************************************************************************/
5179 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5181 STATISTICS(jniinvokation());
5184 exceptions_throw_nullpointerexception();
5188 LOCK_MONITOR_ENTER(obj);
5194 /* MonitorExit *****************************************************************
5196 The current thread must be the owner of the monitor associated with
5197 the underlying Java object referred to by obj. The thread
5198 decrements the counter indicating the number of times it has
5199 entered this monitor. If the value of the counter becomes zero, the
5200 current thread releases the monitor.
5202 *******************************************************************************/
5204 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5206 STATISTICS(jniinvokation());
5209 exceptions_throw_nullpointerexception();
5213 LOCK_MONITOR_EXIT(obj);
5219 /* JavaVM Interface ***********************************************************/
5221 /* GetJavaVM *******************************************************************
5223 Returns the Java VM interface (used in the Invocation API)
5224 associated with the current thread. The result is placed at the
5225 location pointed to by the second argument, vm.
5227 *******************************************************************************/
5229 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5231 STATISTICS(jniinvokation());
5233 *vm = (JavaVM *) _Jv_jvm;
5239 /* GetStringRegion *************************************************************
5241 Copies len number of Unicode characters beginning at offset start
5242 to the given buffer buf.
5244 Throws StringIndexOutOfBoundsException on index overflow.
5246 *******************************************************************************/
5248 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5251 java_lang_String *s;
5254 STATISTICS(jniinvokation());
5256 s = (java_lang_String *) str;
5259 if ((start < 0) || (len < 0) || (start > s->count) ||
5260 (start + len > s->count)) {
5261 exceptions_throw_stringindexoutofboundsexception();
5265 MCOPY(buf, &ca->data[start], u2, len);
5269 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5270 jsize len, char *buf)
5272 STATISTICS(jniinvokation());
5274 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5278 /* GetPrimitiveArrayCritical ***************************************************
5280 Obtain a direct pointer to array elements.
5282 *******************************************************************************/
5284 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5290 ba = (java_bytearray *) array;
5292 /* do the same as Kaffe does */
5294 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5300 /* ReleasePrimitiveArrayCritical ***********************************************
5302 No specific documentation.
5304 *******************************************************************************/
5306 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5307 void *carray, jint mode)
5309 STATISTICS(jniinvokation());
5311 /* do the same as Kaffe does */
5313 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5318 /* GetStringCritical ***********************************************************
5320 The semantics of these two functions are similar to the existing
5321 Get/ReleaseStringChars functions.
5323 *******************************************************************************/
5325 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5328 STATISTICS(jniinvokation());
5330 return _Jv_JNI_GetStringChars(env, string, isCopy);
5334 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5335 const jchar *cstring)
5337 STATISTICS(jniinvokation());
5339 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5343 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5345 STATISTICS(jniinvokation());
5347 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5353 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5355 STATISTICS(jniinvokation());
5357 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5361 /* NewGlobalRef ****************************************************************
5363 Creates a new global reference to the object referred to by the obj
5366 *******************************************************************************/
5368 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5370 hashtable_global_ref_entry *gre;
5371 u4 key; /* hashkey */
5372 u4 slot; /* slot in hashtable */
5374 STATISTICS(jniinvokation());
5376 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5378 /* normally addresses are aligned to 4, 8 or 16 bytes */
5380 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5381 slot = key & (hashtable_global_ref->size - 1);
5382 gre = hashtable_global_ref->ptr[slot];
5384 /* search external hash chain for the entry */
5387 if (gre->o == obj) {
5388 /* global object found, increment the reference */
5392 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5397 gre = gre->hashlink; /* next element in external chain */
5400 /* global ref not found, create a new one */
5402 gre = NEW(hashtable_global_ref_entry);
5407 /* insert entry into hashtable */
5409 gre->hashlink = hashtable_global_ref->ptr[slot];
5411 hashtable_global_ref->ptr[slot] = gre;
5413 /* update number of hashtable-entries */
5415 hashtable_global_ref->entries++;
5417 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5423 /* DeleteGlobalRef *************************************************************
5425 Deletes the global reference pointed to by globalRef.
5427 *******************************************************************************/
5429 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5431 hashtable_global_ref_entry *gre;
5432 hashtable_global_ref_entry *prevgre;
5433 u4 key; /* hashkey */
5434 u4 slot; /* slot in hashtable */
5436 STATISTICS(jniinvokation());
5438 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5440 /* normally addresses are aligned to 4, 8 or 16 bytes */
5442 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5443 slot = key & (hashtable_global_ref->size - 1);
5444 gre = hashtable_global_ref->ptr[slot];
5446 /* initialize prevgre */
5450 /* search external hash chain for the entry */
5453 if (gre->o == globalRef) {
5454 /* global object found, decrement the reference count */
5458 /* if reference count is 0, remove the entry */
5460 if (gre->refs == 0) {
5461 /* special handling if it's the first in the chain */
5463 if (prevgre == NULL)
5464 hashtable_global_ref->ptr[slot] = gre->hashlink;
5466 prevgre->hashlink = gre->hashlink;
5468 FREE(gre, hashtable_global_ref_entry);
5471 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5476 prevgre = gre; /* save current pointer for removal */
5477 gre = gre->hashlink; /* next element in external chain */
5480 log_println("JNI-DeleteGlobalRef: global reference not found");
5482 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5486 /* ExceptionCheck **************************************************************
5488 Returns JNI_TRUE when there is a pending exception; otherwise,
5491 *******************************************************************************/
5493 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5495 java_objectheader *o;
5497 STATISTICS(jniinvokation());
5499 o = exceptions_get_exception();
5501 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5505 /* New JNI 1.4 functions ******************************************************/
5507 /* NewDirectByteBuffer *********************************************************
5509 Allocates and returns a direct java.nio.ByteBuffer referring to the
5510 block of memory starting at the memory address address and
5511 extending capacity bytes.
5513 *******************************************************************************/
5515 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5517 #if defined(ENABLE_JAVASE)
5518 java_objectheader *nbuf;
5519 # if SIZEOF_VOID_P == 8
5520 gnu_classpath_Pointer64 *paddress;
5522 gnu_classpath_Pointer32 *paddress;
5525 STATISTICS(jniinvokation());
5527 /* alocate a gnu.classpath.Pointer{32,64} object */
5529 # if SIZEOF_VOID_P == 8
5530 if (!(paddress = (gnu_classpath_Pointer64 *)
5531 builtin_new(class_gnu_classpath_Pointer64)))
5533 if (!(paddress = (gnu_classpath_Pointer32 *)
5534 builtin_new(class_gnu_classpath_Pointer32)))
5538 /* fill gnu.classpath.Pointer{32,64} with address */
5540 paddress->data = (ptrint) address;
5542 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5544 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5545 (jmethodID) dbbirw_init, NULL, paddress,
5546 (jint) capacity, (jint) capacity, (jint) 0);
5548 /* add local reference and return the value */
5550 return _Jv_JNI_NewLocalRef(env, nbuf);
5552 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5554 /* keep compiler happy */
5561 /* GetDirectBufferAddress ******************************************************
5563 Fetches and returns the starting address of the memory region
5564 referenced by the given direct java.nio.Buffer.
5566 *******************************************************************************/
5568 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5570 #if defined(ENABLE_JAVASE)
5571 java_nio_DirectByteBufferImpl *nbuf;
5572 # if SIZEOF_VOID_P == 8
5573 gnu_classpath_Pointer64 *address;
5575 gnu_classpath_Pointer32 *address;
5578 STATISTICS(jniinvokation());
5580 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5583 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5585 # if SIZEOF_VOID_P == 8
5586 address = (gnu_classpath_Pointer64 *) nbuf->address;
5588 address = (gnu_classpath_Pointer32 *) nbuf->address;
5591 if (address == NULL)
5594 return (void *) address->data;
5596 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5598 /* keep compiler happy */
5605 /* GetDirectBufferCapacity *****************************************************
5607 Fetches and returns the capacity in bytes of the memory region
5608 referenced by the given direct java.nio.Buffer.
5610 *******************************************************************************/
5612 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5614 #if defined(ENABLE_JAVASE)
5615 java_nio_Buffer *nbuf;
5617 STATISTICS(jniinvokation());
5619 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5622 nbuf = (java_nio_Buffer *) buf;
5624 return (jlong) nbuf->cap;
5626 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5628 /* keep compiler happy */
5635 /* DestroyJavaVM ***************************************************************
5637 Unloads a Java VM and reclaims its resources. Only the main thread
5638 can unload the VM. The system waits until the main thread is only
5639 remaining user thread before it destroys the VM.
5641 *******************************************************************************/
5643 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5647 STATISTICS(jniinvokation());
5649 status = vm_destroy(vm);
5655 /* AttachCurrentThread *********************************************************
5657 Attaches the current thread to a Java VM. Returns a JNI interface
5658 pointer in the JNIEnv argument.
5660 Trying to attach a thread that is already attached is a no-op.
5662 A native thread cannot be attached simultaneously to two Java VMs.
5664 When a thread is attached to the VM, the context class loader is
5665 the bootstrap loader.
5667 *******************************************************************************/
5669 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5671 JavaVMAttachArgs *vm_aargs;
5673 #if defined(ENABLE_THREADS)
5674 if (threads_get_current_threadobject() == NULL) {
5675 vm_aargs = (JavaVMAttachArgs *) thr_args;
5677 if (vm_aargs != NULL) {
5678 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5679 (vm_aargs->version != JNI_VERSION_1_4))
5680 return JNI_EVERSION;
5683 if (!threads_attach_current_thread(vm_aargs, false))
5686 if (!jni_init_localref_table())
5697 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5699 STATISTICS(jniinvokation());
5701 return jni_attach_current_thread(p_env, thr_args, false);
5705 /* DetachCurrentThread *********************************************************
5707 Detaches the current thread from a Java VM. All Java monitors held
5708 by this thread are released. All Java threads waiting for this
5709 thread to die are notified.
5711 In JDK 1.1, the main thread cannot be detached from the VM. It must
5712 call DestroyJavaVM to unload the entire VM.
5714 In the JDK, the main thread can be detached from the VM.
5716 The main thread, which is the thread that created the Java VM,
5717 cannot be detached from the VM. Instead, the main thread must call
5718 JNI_DestroyJavaVM() to unload the entire VM.
5720 *******************************************************************************/
5722 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5724 #if defined(ENABLE_THREADS)
5725 threadobject *thread;
5727 STATISTICS(jniinvokation());
5729 thread = threads_get_current_threadobject();
5734 if (!jni_free_localref_table())
5737 if (!threads_detach_thread(thread))
5745 /* GetEnv **********************************************************************
5747 If the current thread is not attached to the VM, sets *env to NULL,
5748 and returns JNI_EDETACHED. If the specified version is not
5749 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5750 sets *env to the appropriate interface, and returns JNI_OK.
5752 *******************************************************************************/
5754 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5756 STATISTICS(jniinvokation());
5758 #if defined(ENABLE_THREADS)
5759 if (threads_get_current_threadobject() == NULL) {
5762 return JNI_EDETACHED;
5766 /* check the JNI version */
5769 case JNI_VERSION_1_1:
5770 case JNI_VERSION_1_2:
5771 case JNI_VERSION_1_4:
5779 #if defined(ENABLE_JVMTI)
5780 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5781 == JVMTI_VERSION_INTERFACE_JVMTI) {
5783 *env = (void *) jvmti_new_environment();
5792 return JNI_EVERSION;
5796 /* AttachCurrentThreadAsDaemon *************************************************
5798 Same semantics as AttachCurrentThread, but the newly-created
5799 java.lang.Thread instance is a daemon.
5801 If the thread has already been attached via either
5802 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5803 simply sets the value pointed to by penv to the JNIEnv of the
5804 current thread. In this case neither AttachCurrentThread nor this
5805 routine have any effect on the daemon status of the thread.
5807 *******************************************************************************/
5809 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5811 STATISTICS(jniinvokation());
5813 return jni_attach_current_thread(penv, args, true);
5817 /* JNI invocation table *******************************************************/
5819 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5824 _Jv_JNI_DestroyJavaVM,
5825 _Jv_JNI_AttachCurrentThread,
5826 _Jv_JNI_DetachCurrentThread,
5828 _Jv_JNI_AttachCurrentThreadAsDaemon
5832 /* JNI function table *********************************************************/
5834 struct JNINativeInterface _Jv_JNINativeInterface = {
5841 _Jv_JNI_DefineClass,
5843 _Jv_JNI_FromReflectedMethod,
5844 _Jv_JNI_FromReflectedField,
5845 _Jv_JNI_ToReflectedMethod,
5846 _Jv_JNI_GetSuperclass,
5847 _Jv_JNI_IsAssignableFrom,
5848 _Jv_JNI_ToReflectedField,
5852 _Jv_JNI_ExceptionOccurred,
5853 _Jv_JNI_ExceptionDescribe,
5854 _Jv_JNI_ExceptionClear,
5856 _Jv_JNI_PushLocalFrame,
5857 _Jv_JNI_PopLocalFrame,
5859 _Jv_JNI_NewGlobalRef,
5860 _Jv_JNI_DeleteGlobalRef,
5861 _Jv_JNI_DeleteLocalRef,
5862 _Jv_JNI_IsSameObject,
5863 _Jv_JNI_NewLocalRef,
5864 _Jv_JNI_EnsureLocalCapacity,
5866 _Jv_JNI_AllocObject,
5871 _Jv_JNI_GetObjectClass,
5872 _Jv_JNI_IsInstanceOf,
5874 _Jv_JNI_GetMethodID,
5876 _Jv_JNI_CallObjectMethod,
5877 _Jv_JNI_CallObjectMethodV,
5878 _Jv_JNI_CallObjectMethodA,
5879 _Jv_JNI_CallBooleanMethod,
5880 _Jv_JNI_CallBooleanMethodV,
5881 _Jv_JNI_CallBooleanMethodA,
5882 _Jv_JNI_CallByteMethod,
5883 _Jv_JNI_CallByteMethodV,
5884 _Jv_JNI_CallByteMethodA,
5885 _Jv_JNI_CallCharMethod,
5886 _Jv_JNI_CallCharMethodV,
5887 _Jv_JNI_CallCharMethodA,
5888 _Jv_JNI_CallShortMethod,
5889 _Jv_JNI_CallShortMethodV,
5890 _Jv_JNI_CallShortMethodA,
5891 _Jv_JNI_CallIntMethod,
5892 _Jv_JNI_CallIntMethodV,
5893 _Jv_JNI_CallIntMethodA,
5894 _Jv_JNI_CallLongMethod,
5895 _Jv_JNI_CallLongMethodV,
5896 _Jv_JNI_CallLongMethodA,
5897 _Jv_JNI_CallFloatMethod,
5898 _Jv_JNI_CallFloatMethodV,
5899 _Jv_JNI_CallFloatMethodA,
5900 _Jv_JNI_CallDoubleMethod,
5901 _Jv_JNI_CallDoubleMethodV,
5902 _Jv_JNI_CallDoubleMethodA,
5903 _Jv_JNI_CallVoidMethod,
5904 _Jv_JNI_CallVoidMethodV,
5905 _Jv_JNI_CallVoidMethodA,
5907 _Jv_JNI_CallNonvirtualObjectMethod,
5908 _Jv_JNI_CallNonvirtualObjectMethodV,
5909 _Jv_JNI_CallNonvirtualObjectMethodA,
5910 _Jv_JNI_CallNonvirtualBooleanMethod,
5911 _Jv_JNI_CallNonvirtualBooleanMethodV,
5912 _Jv_JNI_CallNonvirtualBooleanMethodA,
5913 _Jv_JNI_CallNonvirtualByteMethod,
5914 _Jv_JNI_CallNonvirtualByteMethodV,
5915 _Jv_JNI_CallNonvirtualByteMethodA,
5916 _Jv_JNI_CallNonvirtualCharMethod,
5917 _Jv_JNI_CallNonvirtualCharMethodV,
5918 _Jv_JNI_CallNonvirtualCharMethodA,
5919 _Jv_JNI_CallNonvirtualShortMethod,
5920 _Jv_JNI_CallNonvirtualShortMethodV,
5921 _Jv_JNI_CallNonvirtualShortMethodA,
5922 _Jv_JNI_CallNonvirtualIntMethod,
5923 _Jv_JNI_CallNonvirtualIntMethodV,
5924 _Jv_JNI_CallNonvirtualIntMethodA,
5925 _Jv_JNI_CallNonvirtualLongMethod,
5926 _Jv_JNI_CallNonvirtualLongMethodV,
5927 _Jv_JNI_CallNonvirtualLongMethodA,
5928 _Jv_JNI_CallNonvirtualFloatMethod,
5929 _Jv_JNI_CallNonvirtualFloatMethodV,
5930 _Jv_JNI_CallNonvirtualFloatMethodA,
5931 _Jv_JNI_CallNonvirtualDoubleMethod,
5932 _Jv_JNI_CallNonvirtualDoubleMethodV,
5933 _Jv_JNI_CallNonvirtualDoubleMethodA,
5934 _Jv_JNI_CallNonvirtualVoidMethod,
5935 _Jv_JNI_CallNonvirtualVoidMethodV,
5936 _Jv_JNI_CallNonvirtualVoidMethodA,
5940 _Jv_JNI_GetObjectField,
5941 _Jv_JNI_GetBooleanField,
5942 _Jv_JNI_GetByteField,
5943 _Jv_JNI_GetCharField,
5944 _Jv_JNI_GetShortField,
5945 _Jv_JNI_GetIntField,
5946 _Jv_JNI_GetLongField,
5947 _Jv_JNI_GetFloatField,
5948 _Jv_JNI_GetDoubleField,
5949 _Jv_JNI_SetObjectField,
5950 _Jv_JNI_SetBooleanField,
5951 _Jv_JNI_SetByteField,
5952 _Jv_JNI_SetCharField,
5953 _Jv_JNI_SetShortField,
5954 _Jv_JNI_SetIntField,
5955 _Jv_JNI_SetLongField,
5956 _Jv_JNI_SetFloatField,
5957 _Jv_JNI_SetDoubleField,
5959 _Jv_JNI_GetStaticMethodID,
5961 _Jv_JNI_CallStaticObjectMethod,
5962 _Jv_JNI_CallStaticObjectMethodV,
5963 _Jv_JNI_CallStaticObjectMethodA,
5964 _Jv_JNI_CallStaticBooleanMethod,
5965 _Jv_JNI_CallStaticBooleanMethodV,
5966 _Jv_JNI_CallStaticBooleanMethodA,
5967 _Jv_JNI_CallStaticByteMethod,
5968 _Jv_JNI_CallStaticByteMethodV,
5969 _Jv_JNI_CallStaticByteMethodA,
5970 _Jv_JNI_CallStaticCharMethod,
5971 _Jv_JNI_CallStaticCharMethodV,
5972 _Jv_JNI_CallStaticCharMethodA,
5973 _Jv_JNI_CallStaticShortMethod,
5974 _Jv_JNI_CallStaticShortMethodV,
5975 _Jv_JNI_CallStaticShortMethodA,
5976 _Jv_JNI_CallStaticIntMethod,
5977 _Jv_JNI_CallStaticIntMethodV,
5978 _Jv_JNI_CallStaticIntMethodA,
5979 _Jv_JNI_CallStaticLongMethod,
5980 _Jv_JNI_CallStaticLongMethodV,
5981 _Jv_JNI_CallStaticLongMethodA,
5982 _Jv_JNI_CallStaticFloatMethod,
5983 _Jv_JNI_CallStaticFloatMethodV,
5984 _Jv_JNI_CallStaticFloatMethodA,
5985 _Jv_JNI_CallStaticDoubleMethod,
5986 _Jv_JNI_CallStaticDoubleMethodV,
5987 _Jv_JNI_CallStaticDoubleMethodA,
5988 _Jv_JNI_CallStaticVoidMethod,
5989 _Jv_JNI_CallStaticVoidMethodV,
5990 _Jv_JNI_CallStaticVoidMethodA,
5992 _Jv_JNI_GetStaticFieldID,
5994 _Jv_JNI_GetStaticObjectField,
5995 _Jv_JNI_GetStaticBooleanField,
5996 _Jv_JNI_GetStaticByteField,
5997 _Jv_JNI_GetStaticCharField,
5998 _Jv_JNI_GetStaticShortField,
5999 _Jv_JNI_GetStaticIntField,
6000 _Jv_JNI_GetStaticLongField,
6001 _Jv_JNI_GetStaticFloatField,
6002 _Jv_JNI_GetStaticDoubleField,
6003 _Jv_JNI_SetStaticObjectField,
6004 _Jv_JNI_SetStaticBooleanField,
6005 _Jv_JNI_SetStaticByteField,
6006 _Jv_JNI_SetStaticCharField,
6007 _Jv_JNI_SetStaticShortField,
6008 _Jv_JNI_SetStaticIntField,
6009 _Jv_JNI_SetStaticLongField,
6010 _Jv_JNI_SetStaticFloatField,
6011 _Jv_JNI_SetStaticDoubleField,
6014 _Jv_JNI_GetStringLength,
6015 _Jv_JNI_GetStringChars,
6016 _Jv_JNI_ReleaseStringChars,
6018 _Jv_JNI_NewStringUTF,
6019 _Jv_JNI_GetStringUTFLength,
6020 _Jv_JNI_GetStringUTFChars,
6021 _Jv_JNI_ReleaseStringUTFChars,
6023 _Jv_JNI_GetArrayLength,
6025 _Jv_JNI_NewObjectArray,
6026 _Jv_JNI_GetObjectArrayElement,
6027 _Jv_JNI_SetObjectArrayElement,
6029 _Jv_JNI_NewBooleanArray,
6030 _Jv_JNI_NewByteArray,
6031 _Jv_JNI_NewCharArray,
6032 _Jv_JNI_NewShortArray,
6033 _Jv_JNI_NewIntArray,
6034 _Jv_JNI_NewLongArray,
6035 _Jv_JNI_NewFloatArray,
6036 _Jv_JNI_NewDoubleArray,
6038 _Jv_JNI_GetBooleanArrayElements,
6039 _Jv_JNI_GetByteArrayElements,
6040 _Jv_JNI_GetCharArrayElements,
6041 _Jv_JNI_GetShortArrayElements,
6042 _Jv_JNI_GetIntArrayElements,
6043 _Jv_JNI_GetLongArrayElements,
6044 _Jv_JNI_GetFloatArrayElements,
6045 _Jv_JNI_GetDoubleArrayElements,
6047 _Jv_JNI_ReleaseBooleanArrayElements,
6048 _Jv_JNI_ReleaseByteArrayElements,
6049 _Jv_JNI_ReleaseCharArrayElements,
6050 _Jv_JNI_ReleaseShortArrayElements,
6051 _Jv_JNI_ReleaseIntArrayElements,
6052 _Jv_JNI_ReleaseLongArrayElements,
6053 _Jv_JNI_ReleaseFloatArrayElements,
6054 _Jv_JNI_ReleaseDoubleArrayElements,
6056 _Jv_JNI_GetBooleanArrayRegion,
6057 _Jv_JNI_GetByteArrayRegion,
6058 _Jv_JNI_GetCharArrayRegion,
6059 _Jv_JNI_GetShortArrayRegion,
6060 _Jv_JNI_GetIntArrayRegion,
6061 _Jv_JNI_GetLongArrayRegion,
6062 _Jv_JNI_GetFloatArrayRegion,
6063 _Jv_JNI_GetDoubleArrayRegion,
6064 _Jv_JNI_SetBooleanArrayRegion,
6065 _Jv_JNI_SetByteArrayRegion,
6066 _Jv_JNI_SetCharArrayRegion,
6067 _Jv_JNI_SetShortArrayRegion,
6068 _Jv_JNI_SetIntArrayRegion,
6069 _Jv_JNI_SetLongArrayRegion,
6070 _Jv_JNI_SetFloatArrayRegion,
6071 _Jv_JNI_SetDoubleArrayRegion,
6073 _Jv_JNI_RegisterNatives,
6074 _Jv_JNI_UnregisterNatives,
6076 _Jv_JNI_MonitorEnter,
6077 _Jv_JNI_MonitorExit,
6081 /* new JNI 1.2 functions */
6083 _Jv_JNI_GetStringRegion,
6084 _Jv_JNI_GetStringUTFRegion,
6086 _Jv_JNI_GetPrimitiveArrayCritical,
6087 _Jv_JNI_ReleasePrimitiveArrayCritical,
6089 _Jv_JNI_GetStringCritical,
6090 _Jv_JNI_ReleaseStringCritical,
6092 _Jv_JNI_NewWeakGlobalRef,
6093 _Jv_JNI_DeleteWeakGlobalRef,
6095 _Jv_JNI_ExceptionCheck,
6097 /* new JNI 1.4 functions */
6099 _Jv_JNI_NewDirectByteBuffer,
6100 _Jv_JNI_GetDirectBufferAddress,
6101 _Jv_JNI_GetDirectBufferCapacity
6105 /* Invocation API Functions ***************************************************/
6107 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6109 Returns a default configuration for the Java VM.
6111 *******************************************************************************/
6113 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6115 JavaVMInitArgs *_vm_args;
6117 _vm_args = (JavaVMInitArgs *) vm_args;
6119 /* GNU classpath currently supports JNI 1.2 */
6121 switch (_vm_args->version) {
6122 case JNI_VERSION_1_1:
6123 _vm_args->version = JNI_VERSION_1_1;
6126 case JNI_VERSION_1_2:
6127 case JNI_VERSION_1_4:
6128 _vm_args->ignoreUnrecognized = JNI_FALSE;
6129 _vm_args->options = NULL;
6130 _vm_args->nOptions = 0;
6141 /* JNI_GetCreatedJavaVMs *******************************************************
6143 Returns all Java VMs that have been created. Pointers to VMs are written in
6144 the buffer vmBuf in the order they are created. At most bufLen number of
6145 entries will be written. The total number of created VMs is returned in
6148 *******************************************************************************/
6150 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6152 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6158 /* JNI_CreateJavaVM ************************************************************
6160 Loads and initializes a Java VM. The current thread becomes the main thread.
6161 Sets the env argument to the JNI interface pointer of the main thread.
6163 *******************************************************************************/
6165 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6167 /* actually create the JVM */
6169 if (!vm_createjvm(p_vm, p_env, vm_args))
6177 * These are local overrides for various environment variables in Emacs.
6178 * Please do not remove this and leave it at the end of the file, where
6179 * Emacs will automagically detect them.
6180 * ---------------------------------------------------------------------
6183 * indent-tabs-mode: t
6187 * vim:noexpandtab:sw=4:ts=4: