1 /* src/native/jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996-2005, 2006 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 Contact: cacao@cacaojvm.org
27 Authors: Rainhard Grafl
30 Changes: Joseph Wenninger
35 $Id: jni.c 4969 2006-05-29 09:41:02Z motse $
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/cacaodbg.h"
84 #if defined(ENABLE_THREADS)
85 # include "threads/native/threads.h"
88 #include "toolbox/logging.h"
89 #include "vm/builtin.h"
90 #include "vm/exceptions.h"
91 #include "vm/global.h"
92 #include "vm/initialize.h"
93 #include "vm/loader.h"
94 #include "vm/options.h"
95 #include "vm/resolve.h"
96 #include "vm/statistics.h"
97 #include "vm/stringlocal.h"
98 #include "vm/jit/asmpart.h"
99 #include "vm/jit/jit.h"
100 #include "vm/statistics.h"
104 /* global variables ***********************************************************/
106 /* global reference table *****************************************************/
108 /* hashsize must be power of 2 */
110 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
112 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
115 /* direct buffer stuff ********************************************************/
117 static classinfo *class_java_nio_Buffer;
118 static classinfo *class_java_nio_DirectByteBufferImpl;
119 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
120 #if SIZEOF_VOID_P == 8
121 static classinfo *class_gnu_classpath_Pointer64;
123 static classinfo *class_gnu_classpath_Pointer32;
126 static methodinfo *dbbirw_init;
129 /* local reference table ******************************************************/
131 #if !defined(ENABLE_THREADS)
132 localref_table *_no_threads_localref_table;
136 /* accessing instance fields macros *******************************************/
138 #define SET_FIELD(o,type,f,value) \
139 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
141 #define GET_FIELD(o,type,f) \
142 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
145 /* some forward declarations **************************************************/
147 jobject NewLocalRef(JNIEnv *env, jobject ref);
148 jint EnsureLocalCapacity(JNIEnv* env, jint capacity);
151 /* jni_init ********************************************************************
153 Initialize the JNI subsystem.
155 *******************************************************************************/
159 /* create global ref hashtable */
161 hashtable_global_ref = NEW(hashtable);
163 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
166 /* direct buffer stuff */
168 if (!(class_java_nio_Buffer =
169 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
170 !link_class(class_java_nio_Buffer))
173 if (!(class_java_nio_DirectByteBufferImpl =
174 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
175 !link_class(class_java_nio_DirectByteBufferImpl))
178 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
179 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
180 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
184 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
186 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
189 #if SIZEOF_VOID_P == 8
190 if (!(class_gnu_classpath_Pointer64 =
191 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
192 !link_class(class_gnu_classpath_Pointer64))
195 if (!(class_gnu_classpath_Pointer32 =
196 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
197 !link_class(class_gnu_classpath_Pointer32))
205 /* _Jv_jni_vmargs_from_objectarray *********************************************
209 *******************************************************************************/
211 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
214 java_objectarray *params)
216 java_objectheader *param;
218 typedesc *paramtypes;
224 paramcount = descr->paramcount;
225 paramtypes = descr->paramtypes;
227 /* if method is non-static fill first block and skip `this' pointer */
233 vmargs[0].type = TYPE_ADR;
234 vmargs[0].data.l = (u8) (ptrint) o;
241 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
242 switch (paramtypes->type) {
243 /* primitive types */
248 param = params->data[j];
253 /* internally used data type */
254 vmargs[i].type = paramtypes->type;
256 /* convert the value according to its declared type */
258 c = param->vftbl->class;
260 switch (paramtypes->decltype) {
261 case PRIMITIVETYPE_BOOLEAN:
262 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
263 value = (s8) ((java_lang_Boolean *) param)->value;
267 vmargs[i].data.l = value;
270 case PRIMITIVETYPE_BYTE:
271 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
272 value = (s8) ((java_lang_Byte *) param)->value;
276 vmargs[i].data.l = value;
279 case PRIMITIVETYPE_CHAR:
280 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
281 value = (s8) ((java_lang_Character *) param)->value;
285 vmargs[i].data.l = value;
288 case PRIMITIVETYPE_SHORT:
289 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
290 value = (s8) ((java_lang_Short *) param)->value;
291 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
292 value = (s8) ((java_lang_Byte *) param)->value;
296 vmargs[i].data.l = value;
299 case PRIMITIVETYPE_INT:
300 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
301 value = (s8) ((java_lang_Integer *) param)->value;
302 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
303 value = (s8) ((java_lang_Short *) param)->value;
304 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
305 value = (s8) ((java_lang_Byte *) param)->value;
309 vmargs[i].data.l = value;
312 case PRIMITIVETYPE_LONG:
313 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
314 value = (s8) ((java_lang_Long *) param)->value;
315 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
316 value = (s8) ((java_lang_Integer *) param)->value;
317 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
318 value = (s8) ((java_lang_Short *) param)->value;
319 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
320 value = (s8) ((java_lang_Byte *) param)->value;
324 vmargs[i].data.l = value;
327 case PRIMITIVETYPE_FLOAT:
328 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
329 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
334 case PRIMITIVETYPE_DOUBLE:
335 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
336 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
337 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
338 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
349 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
352 if (params->data[j] != 0) {
353 if (paramtypes->arraydim > 0) {
354 if (!builtin_arrayinstanceof(params->data[j], c))
358 if (!builtin_instanceof(params->data[j], c))
363 vmargs[i].type = TYPE_ADR;
364 vmargs[i].data.l = (u8) (ptrint) params->data[j];
373 /* *rettype = descr->returntype.decltype; */
378 exceptions_throw_illegalargumentexception();
383 /* _Jv_jni_CallObjectMethod ****************************************************
385 Internal function to call Java Object methods.
387 *******************************************************************************/
389 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
391 methodinfo *m, va_list ap)
394 java_objectheader *ro;
396 STATISTICS(jniinvokation());
399 exceptions_throw_nullpointerexception();
403 /* Class initialization is done by the JIT compiler. This is ok
404 since a static method always belongs to the declaring class. */
406 if (m->flags & ACC_STATIC) {
407 /* For static methods we reset the object. */
412 /* for convenience */
417 /* For instance methods we make a virtual function table lookup. */
419 resm = method_vftbl_lookup(vftbl, m);
422 STATISTICS(jnicallXmethodnvokation());
424 ro = vm_call_method_valist(resm, o, ap);
430 /* _Jv_jni_CallObjectMethodA ***************************************************
432 Internal function to call Java Object methods.
434 *******************************************************************************/
436 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
438 methodinfo *m, jvalue *args)
441 java_objectheader *ro;
443 STATISTICS(jniinvokation());
446 exceptions_throw_nullpointerexception();
450 /* Class initialization is done by the JIT compiler. This is ok
451 since a static method always belongs to the declaring class. */
453 if (m->flags & ACC_STATIC) {
454 /* For static methods we reset the object. */
459 /* for convenience */
464 /* For instance methods we make a virtual function table lookup. */
466 resm = method_vftbl_lookup(vftbl, m);
469 STATISTICS(jnicallXmethodnvokation());
471 ro = vm_call_method_jvalue(resm, o, args);
477 /* _Jv_jni_CallIntMethod *******************************************************
479 Internal function to call Java integer class methods (boolean,
480 byte, char, short, int).
482 *******************************************************************************/
484 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
485 methodinfo *m, va_list ap)
490 STATISTICS(jniinvokation());
493 exceptions_throw_nullpointerexception();
497 /* Class initialization is done by the JIT compiler. This is ok
498 since a static method always belongs to the declaring class. */
500 if (m->flags & ACC_STATIC) {
501 /* For static methods we reset the object. */
506 /* for convenience */
511 /* For instance methods we make a virtual function table lookup. */
513 resm = method_vftbl_lookup(vftbl, m);
516 STATISTICS(jnicallXmethodnvokation());
518 i = vm_call_method_int_valist(resm, o, ap);
524 /* _Jv_jni_CallIntMethodA ******************************************************
526 Internal function to call Java integer class methods (boolean,
527 byte, char, short, int).
529 *******************************************************************************/
531 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
532 methodinfo *m, jvalue *args)
537 STATISTICS(jniinvokation());
540 exceptions_throw_nullpointerexception();
544 /* Class initialization is done by the JIT compiler. This is ok
545 since a static method always belongs to the declaring class. */
547 if (m->flags & ACC_STATIC) {
548 /* For static methods we reset the object. */
553 /* for convenience */
558 /* For instance methods we make a virtual function table lookup. */
560 resm = method_vftbl_lookup(vftbl, m);
563 STATISTICS(jnicallXmethodnvokation());
565 i = vm_call_method_int_jvalue(resm, o, args);
571 /* _Jv_jni_CallLongMethod ******************************************************
573 Internal function to call Java long methods.
575 *******************************************************************************/
577 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
578 methodinfo *m, va_list ap)
583 STATISTICS(jniinvokation());
586 exceptions_throw_nullpointerexception();
590 /* Class initialization is done by the JIT compiler. This is ok
591 since a static method always belongs to the declaring class. */
593 if (m->flags & ACC_STATIC) {
594 /* For static methods we reset the object. */
599 /* for convenience */
604 /* For instance methods we make a virtual function table lookup. */
606 resm = method_vftbl_lookup(vftbl, m);
609 STATISTICS(jnicallXmethodnvokation());
611 l = vm_call_method_long_valist(resm, o, ap);
617 /* _Jv_jni_CallFloatMethod *****************************************************
619 Internal function to call Java float methods.
621 *******************************************************************************/
623 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
624 methodinfo *m, va_list ap)
629 /* Class initialization is done by the JIT compiler. This is ok
630 since a static method always belongs to the declaring class. */
632 if (m->flags & ACC_STATIC) {
633 /* For static methods we reset the object. */
638 /* for convenience */
643 /* For instance methods we make a virtual function table lookup. */
645 resm = method_vftbl_lookup(vftbl, m);
648 STATISTICS(jnicallXmethodnvokation());
650 f = vm_call_method_float_valist(resm, o, ap);
656 /* _Jv_jni_CallDoubleMethod ****************************************************
658 Internal function to call Java double methods.
660 *******************************************************************************/
662 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
663 methodinfo *m, va_list ap)
668 /* Class initialization is done by the JIT compiler. This is ok
669 since a static method always belongs to the declaring class. */
671 if (m->flags & ACC_STATIC) {
672 /* For static methods we reset the object. */
677 /* for convenience */
682 /* For instance methods we make a virtual function table lookup. */
684 resm = method_vftbl_lookup(vftbl, m);
687 d = vm_call_method_double_valist(resm, o, ap);
693 /* _Jv_jni_CallVoidMethod ******************************************************
695 Internal function to call Java void methods.
697 *******************************************************************************/
699 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
700 methodinfo *m, va_list ap)
705 exceptions_throw_nullpointerexception();
709 /* Class initialization is done by the JIT compiler. This is ok
710 since a static method always belongs to the declaring class. */
712 if (m->flags & ACC_STATIC) {
713 /* For static methods we reset the object. */
718 /* for convenience */
723 /* For instance methods we make a virtual function table lookup. */
725 resm = method_vftbl_lookup(vftbl, m);
728 STATISTICS(jnicallXmethodnvokation());
730 (void) vm_call_method_valist(resm, o, ap);
734 /* _Jv_jni_CallVoidMethodA *****************************************************
736 Internal function to call Java void methods.
738 *******************************************************************************/
740 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
741 methodinfo *m, jvalue *args)
746 exceptions_throw_nullpointerexception();
750 /* Class initialization is done by the JIT compiler. This is ok
751 since a static method always belongs to the declaring class. */
753 if (m->flags & ACC_STATIC) {
754 /* For static methods we reset the object. */
759 /* for convenience */
764 /* For instance methods we make a virtual function table lookup. */
766 resm = method_vftbl_lookup(vftbl, m);
769 STATISTICS(jnicallXmethodnvokation());
771 (void) vm_call_method_jvalue(resm, o, args);
775 /* _Jv_jni_invokeNative ********************************************************
777 Invoke a method on the given object with the given arguments.
779 For instance methods OBJ must be != NULL and the method is looked up
780 in the vftbl of the object.
782 For static methods, OBJ is ignored.
784 *******************************************************************************/
786 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
787 java_objectarray *params)
791 java_objectheader *ro;
796 exceptions_throw_nullpointerexception();
800 argcount = m->parseddesc->paramcount;
801 paramcount = argcount;
803 /* if method is non-static, remove the `this' pointer */
805 if (!(m->flags & ACC_STATIC))
808 /* For instance methods the object has to be an instance of the
809 class the method belongs to. For static methods the obj
810 parameter is ignored. */
812 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
814 new_exception_message(string_java_lang_IllegalArgumentException,
815 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
819 /* check if we got the right number of arguments */
821 if (((params == NULL) && (paramcount != 0)) ||
822 (params && (params->header.size != paramcount)))
825 new_exception(string_java_lang_IllegalArgumentException);
829 /* for instance methods we need an object */
831 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
833 new_exception_message(string_java_lang_NullPointerException,
834 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
838 /* for static methods, zero object to make subsequent code simpler */
839 if (m->flags & ACC_STATIC)
843 /* for instance methods we must do a vftbl lookup */
844 resm = method_vftbl_lookup(o->vftbl, m);
847 /* for static methods, just for convenience */
851 vmargs = MNEW(vm_arg, argcount);
853 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
856 switch (resm->parseddesc->returntype.decltype) {
858 (void) vm_call_method_vmarg(resm, argcount, vmargs);
863 case PRIMITIVETYPE_BOOLEAN: {
865 java_lang_Boolean *bo;
867 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
869 ro = builtin_new(class_java_lang_Boolean);
871 /* setting the value of the object direct */
873 bo = (java_lang_Boolean *) ro;
878 case PRIMITIVETYPE_BYTE: {
882 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
884 ro = builtin_new(class_java_lang_Byte);
886 /* setting the value of the object direct */
888 bo = (java_lang_Byte *) ro;
893 case PRIMITIVETYPE_CHAR: {
895 java_lang_Character *co;
897 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
899 ro = builtin_new(class_java_lang_Character);
901 /* setting the value of the object direct */
903 co = (java_lang_Character *) ro;
908 case PRIMITIVETYPE_SHORT: {
912 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
914 ro = builtin_new(class_java_lang_Short);
916 /* setting the value of the object direct */
918 so = (java_lang_Short *) ro;
923 case PRIMITIVETYPE_INT: {
925 java_lang_Integer *io;
927 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
929 ro = builtin_new(class_java_lang_Integer);
931 /* setting the value of the object direct */
933 io = (java_lang_Integer *) ro;
938 case PRIMITIVETYPE_LONG: {
942 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
944 ro = builtin_new(class_java_lang_Long);
946 /* setting the value of the object direct */
948 lo = (java_lang_Long *) ro;
953 case PRIMITIVETYPE_FLOAT: {
957 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
959 ro = builtin_new(class_java_lang_Float);
961 /* setting the value of the object direct */
963 fo = (java_lang_Float *) ro;
968 case PRIMITIVETYPE_DOUBLE: {
970 java_lang_Double *_do;
972 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
974 ro = builtin_new(class_java_lang_Double);
976 /* setting the value of the object direct */
978 _do = (java_lang_Double *) ro;
984 ro = vm_call_method_vmarg(resm, argcount, vmargs);
988 /* if this happens the exception has already been set by
989 fill_callblock_from_objectarray */
991 MFREE(vmargs, vm_arg, argcount);
996 MFREE(vmargs, vm_arg, argcount);
999 java_objectheader *cause;
1001 cause = *exceptionptr;
1003 /* clear exception pointer, we are calling JIT code again */
1005 *exceptionptr = NULL;
1008 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1009 (java_lang_Throwable *) cause);
1016 /* GetVersion ******************************************************************
1018 Returns the major version number in the higher 16 bits and the
1019 minor version number in the lower 16 bits.
1021 *******************************************************************************/
1023 jint GetVersion(JNIEnv *env)
1025 STATISTICS(jniinvokation());
1027 /* we support JNI 1.4 */
1029 return JNI_VERSION_1_4;
1033 /* Class Operations ***********************************************************/
1035 /* DefineClass *****************************************************************
1037 Loads a class from a buffer of raw class data. The buffer
1038 containing the raw class data is not referenced by the VM after the
1039 DefineClass call returns, and it may be discarded if desired.
1041 *******************************************************************************/
1043 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1044 const jbyte *buf, jsize bufLen)
1046 java_lang_ClassLoader *cl;
1047 java_lang_String *s;
1051 STATISTICS(jniinvokation());
1053 cl = (java_lang_ClassLoader *) loader;
1054 s = javastring_new_from_utf_string(name);
1055 ba = (java_bytearray *) buf;
1057 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1060 return (jclass) NewLocalRef(env, (jobject) c);
1064 /* FindClass *******************************************************************
1066 This function loads a locally-defined class. It searches the
1067 directories and zip files specified by the CLASSPATH environment
1068 variable for the class with the specified name.
1070 *******************************************************************************/
1072 jclass FindClass(JNIEnv *env, const char *name)
1078 STATISTICS(jniinvokation());
1080 u = utf_new_char_classname((char *) name);
1082 /* Check stacktrace for classloader, if one found use it,
1083 otherwise use the system classloader. */
1085 /* Quote from the JNI documentation:
1087 In the Java 2 Platform, FindClass locates the class loader
1088 associated with the current native method. If the native code
1089 belongs to a system class, no class loader will be
1090 involved. Otherwise, the proper class loader will be invoked to
1091 load and link the named class. When FindClass is called through
1092 the Invocation Interface, there is no current native method or
1093 its associated class loader. In that case, the result of
1094 ClassLoader.getBaseClassLoader is used." */
1096 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1097 /* these JITs support stacktraces, and so does the interpreter */
1099 cc = stacktrace_getCurrentClass();
1101 # if defined(ENABLE_INTRP)
1102 /* the interpreter supports stacktraces, even if the JIT does not */
1105 cc = stacktrace_getCurrentClass();
1111 /* if no Java method was found, use the system classloader */
1114 c = load_class_from_sysloader(u);
1116 c = load_class_from_classloader(u, cc->classloader);
1124 return (jclass) NewLocalRef(env, (jobject) c);
1128 /* GetSuperclass ***************************************************************
1130 If clazz represents any class other than the class Object, then
1131 this function returns the object that represents the superclass of
1132 the class specified by clazz.
1134 *******************************************************************************/
1136 jclass GetSuperclass(JNIEnv *env, jclass sub)
1140 STATISTICS(jniinvokation());
1142 c = ((classinfo *) sub)->super.cls;
1147 return (jclass) NewLocalRef(env, (jobject) c);
1151 /* IsAssignableFrom ************************************************************
1153 Determines whether an object of sub can be safely cast to sup.
1155 *******************************************************************************/
1157 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1159 STATISTICS(jniinvokation());
1161 return Java_java_lang_VMClass_isAssignableFrom(env,
1163 (java_lang_Class *) sup,
1164 (java_lang_Class *) sub);
1168 /* Throw ***********************************************************************
1170 Causes a java.lang.Throwable object to be thrown.
1172 *******************************************************************************/
1174 jint Throw(JNIEnv *env, jthrowable obj)
1176 STATISTICS(jniinvokation());
1178 *exceptionptr = (java_objectheader *) obj;
1184 /* ThrowNew ********************************************************************
1186 Constructs an exception object from the specified class with the
1187 message specified by message and causes that exception to be
1190 *******************************************************************************/
1192 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1195 java_lang_Throwable *o;
1196 java_lang_String *s;
1198 STATISTICS(jniinvokation());
1200 c = (classinfo *) clazz;
1201 s = (java_lang_String *) javastring_new_from_utf_string(msg);
1203 /* instantiate exception object */
1205 o = (java_lang_Throwable *) native_new_and_init_string(c, s);
1210 *exceptionptr = (java_objectheader *) o;
1216 /* ExceptionOccurred ***********************************************************
1218 Determines if an exception is being thrown. The exception stays
1219 being thrown until either the native code calls ExceptionClear(),
1220 or the Java code handles the exception.
1222 *******************************************************************************/
1224 jthrowable ExceptionOccurred(JNIEnv *env)
1226 java_objectheader *e;
1228 STATISTICS(jniinvokation());
1232 return NewLocalRef(env, (jthrowable) e);
1236 /* ExceptionDescribe ***********************************************************
1238 Prints an exception and a backtrace of the stack to a system
1239 error-reporting channel, such as stderr. This is a convenience
1240 routine provided for debugging.
1242 *******************************************************************************/
1244 void ExceptionDescribe(JNIEnv *env)
1246 java_objectheader *e;
1249 STATISTICS(jniinvokation());
1254 /* clear exception, because we are calling jit code again */
1256 *exceptionptr = NULL;
1258 /* get printStackTrace method from exception class */
1260 m = class_resolveclassmethod(e->vftbl->class,
1261 utf_printStackTrace,
1267 /* XXX what should we do? */
1270 /* print the stacktrace */
1272 (void) vm_call_method(m, e);
1277 /* ExceptionClear **************************************************************
1279 Clears any exception that is currently being thrown. If no
1280 exception is currently being thrown, this routine has no effect.
1282 *******************************************************************************/
1284 void ExceptionClear(JNIEnv *env)
1286 STATISTICS(jniinvokation());
1288 *exceptionptr = NULL;
1292 /* FatalError ******************************************************************
1294 Raises a fatal error and does not expect the VM to recover. This
1295 function does not return.
1297 *******************************************************************************/
1299 void FatalError(JNIEnv *env, const char *msg)
1301 STATISTICS(jniinvokation());
1303 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1307 /* PushLocalFrame **************************************************************
1309 Creates a new local reference frame, in which at least a given
1310 number of local references can be created.
1312 *******************************************************************************/
1314 jint PushLocalFrame(JNIEnv* env, jint capacity)
1317 localref_table *lrt;
1318 localref_table *nlrt;
1320 STATISTICS(jniinvokation());
1325 /* Allocate new local reference table on Java heap. Calculate the
1326 additional memory we have to allocate. */
1328 if (capacity > LOCALREFTABLE_CAPACITY)
1329 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1333 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1338 /* get current local reference table from thread */
1340 lrt = LOCALREFTABLE;
1342 /* Set up the new local reference table and add it to the local
1345 nlrt->capacity = capacity;
1347 nlrt->localframes = lrt->localframes + 1;
1350 /* store new local reference table in thread */
1352 LOCALREFTABLE = nlrt;
1358 /* PopLocalFrame ***************************************************************
1360 Pops off the current local reference frame, frees all the local
1361 references, and returns a local reference in the previous local
1362 reference frame for the given result object.
1364 *******************************************************************************/
1366 jobject PopLocalFrame(JNIEnv* env, jobject result)
1368 localref_table *lrt;
1369 localref_table *plrt;
1372 STATISTICS(jniinvokation());
1374 /* get current local reference table from thread */
1376 lrt = LOCALREFTABLE;
1378 localframes = lrt->localframes;
1380 /* Don't delete the top local frame, as this one is allocated in
1381 the native stub on the stack and is freed automagically on
1384 if (localframes == 1)
1385 return NewLocalRef(env, result);
1387 /* release all current local frames */
1389 for (; localframes >= 1; localframes--) {
1390 /* get previous frame */
1394 /* clear all reference entries */
1396 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1400 /* set new local references table */
1405 /* store new local reference table in thread */
1407 LOCALREFTABLE = lrt;
1409 /* add local reference and return the value */
1411 return NewLocalRef(env, result);
1415 /* DeleteLocalRef **************************************************************
1417 Deletes the local reference pointed to by localRef.
1419 *******************************************************************************/
1421 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1423 java_objectheader *o;
1424 localref_table *lrt;
1427 STATISTICS(jniinvokation());
1429 o = (java_objectheader *) localRef;
1431 /* get local reference table (thread specific) */
1433 lrt = LOCALREFTABLE;
1435 /* go through all local frames */
1437 for (; lrt != NULL; lrt = lrt->prev) {
1439 /* and try to remove the reference */
1441 for (i = 0; i < lrt->capacity; i++) {
1442 if (lrt->refs[i] == o) {
1443 lrt->refs[i] = NULL;
1451 /* this should not happen */
1453 /* if (opt_checkjni) */
1454 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1455 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1459 /* IsSameObject ****************************************************************
1461 Tests whether two references refer to the same Java object.
1463 *******************************************************************************/
1465 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1467 STATISTICS(jniinvokation());
1476 /* NewLocalRef *****************************************************************
1478 Creates a new local reference that refers to the same object as ref.
1480 *******************************************************************************/
1482 jobject NewLocalRef(JNIEnv *env, jobject ref)
1484 localref_table *lrt;
1487 STATISTICS(jniinvokation());
1492 /* get local reference table (thread specific) */
1494 lrt = LOCALREFTABLE;
1496 /* Check if we have space for the requested reference? No,
1497 allocate a new frame. This is actually not what the spec says,
1498 but for compatibility reasons... */
1500 if (lrt->used == lrt->capacity) {
1501 if (EnsureLocalCapacity(env, 16) != 0)
1504 /* get the new local reference table */
1506 lrt = LOCALREFTABLE;
1509 /* insert the reference */
1511 for (i = 0; i < lrt->capacity; i++) {
1512 if (lrt->refs[i] == NULL) {
1513 lrt->refs[i] = (java_objectheader *) ref;
1520 /* should not happen, just to be sure */
1524 /* keep compiler happy */
1530 /* EnsureLocalCapacity *********************************************************
1532 Ensures that at least a given number of local references can be
1533 created in the current thread
1535 *******************************************************************************/
1537 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1539 localref_table *lrt;
1541 log_text("JNI-Call: EnsureLocalCapacity");
1543 STATISTICS(jniinvokation());
1545 /* get local reference table (thread specific) */
1547 lrt = LOCALREFTABLE;
1549 /* check if capacity elements are available in the local references table */
1551 if ((lrt->used + capacity) > lrt->capacity)
1552 return PushLocalFrame(env, capacity);
1558 /* AllocObject *****************************************************************
1560 Allocates a new Java object without invoking any of the
1561 constructors for the object. Returns a reference to the object.
1563 *******************************************************************************/
1565 jobject AllocObject(JNIEnv *env, jclass clazz)
1568 java_objectheader *o;
1570 STATISTICS(jniinvokation());
1572 c = (classinfo *) clazz;
1574 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1576 new_exception_utfmessage(string_java_lang_InstantiationException,
1583 return NewLocalRef(env, o);
1587 /* NewObject *******************************************************************
1589 Programmers place all arguments that are to be passed to the
1590 constructor immediately following the methodID
1591 argument. NewObject() accepts these arguments and passes them to
1592 the Java method that the programmer wishes to invoke.
1594 *******************************************************************************/
1596 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1598 java_objectheader *o;
1602 STATISTICS(jniinvokation());
1604 m = (methodinfo *) methodID;
1608 o = builtin_new(clazz);
1613 /* call constructor */
1615 va_start(ap, methodID);
1616 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1619 return NewLocalRef(env, o);
1623 /* NewObjectV ******************************************************************
1625 Programmers place all arguments that are to be passed to the
1626 constructor in an args argument of type va_list that immediately
1627 follows the methodID argument. NewObjectV() accepts these
1628 arguments, and, in turn, passes them to the Java method that the
1629 programmer wishes to invoke.
1631 *******************************************************************************/
1633 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1635 java_objectheader *o;
1638 STATISTICS(jniinvokation());
1640 m = (methodinfo *) methodID;
1644 o = builtin_new(clazz);
1649 /* call constructor */
1651 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1653 return NewLocalRef(env, o);
1657 /* NewObjectA *****************************************************************
1659 Programmers place all arguments that are to be passed to the
1660 constructor in an args array of jvalues that immediately follows
1661 the methodID argument. NewObjectA() accepts the arguments in this
1662 array, and, in turn, passes them to the Java method that the
1663 programmer wishes to invoke.
1665 *******************************************************************************/
1667 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1669 java_objectheader *o;
1672 STATISTICS(jniinvokation());
1674 m = (methodinfo *) methodID;
1678 o = builtin_new(clazz);
1683 /* call constructor */
1685 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1687 return NewLocalRef(env, o);
1691 /* GetObjectClass **************************************************************
1693 Returns the class of an object.
1695 *******************************************************************************/
1697 jclass GetObjectClass(JNIEnv *env, jobject obj)
1699 java_objectheader *o;
1702 STATISTICS(jniinvokation());
1704 o = (java_objectheader *) obj;
1706 if ((o == NULL) || (o->vftbl == NULL))
1709 c = o->vftbl->class;
1711 return (jclass) NewLocalRef(env, (jobject) c);
1715 /* IsInstanceOf ****************************************************************
1717 Tests whether an object is an instance of a class.
1719 *******************************************************************************/
1721 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1723 STATISTICS(jniinvokation());
1725 return Java_java_lang_VMClass_isInstance(env,
1727 (java_lang_Class *) clazz,
1728 (java_lang_Object *) obj);
1732 /* Reflection Support *********************************************************/
1734 /* FromReflectedMethod *********************************************************
1736 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1737 object to a method ID.
1739 *******************************************************************************/
1741 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1747 STATISTICS(jniinvokation());
1752 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1753 java_lang_reflect_Method *rm;
1755 rm = (java_lang_reflect_Method *) method;
1756 c = (classinfo *) (rm->declaringClass);
1759 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1760 java_lang_reflect_Constructor *rc;
1762 rc = (java_lang_reflect_Constructor *) method;
1763 c = (classinfo *) (rc->clazz);
1769 mi = &(c->methods[slot]);
1771 return (jmethodID) mi;
1775 /* FromReflectedField **********************************************************
1777 Converts a java.lang.reflect.Field to a field ID.
1779 *******************************************************************************/
1781 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1783 java_lang_reflect_Field *rf;
1787 STATISTICS(jniinvokation());
1789 rf = (java_lang_reflect_Field *) field;
1794 c = (classinfo *) rf->declaringClass;
1796 f = &(c->fields[rf->slot]);
1798 return (jfieldID) f;
1802 /* ToReflectedMethod ***********************************************************
1804 Converts a method ID derived from cls to an instance of the
1805 java.lang.reflect.Method class or to an instance of the
1806 java.lang.reflect.Constructor class.
1808 *******************************************************************************/
1810 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1812 STATISTICS(jniinvokation());
1814 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1820 /* ToReflectedField ************************************************************
1822 Converts a field ID derived from cls to an instance of the
1823 java.lang.reflect.Field class.
1825 *******************************************************************************/
1827 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1830 STATISTICS(jniinvokation());
1832 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1838 /* Calling Instance Methods ***************************************************/
1840 /* GetMethodID *****************************************************************
1842 Returns the method ID for an instance (nonstatic) method of a class
1843 or interface. The method may be defined in one of the clazz's
1844 superclasses and inherited by clazz. The method is determined by
1845 its name and signature.
1847 GetMethodID() causes an uninitialized class to be initialized.
1849 *******************************************************************************/
1851 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1859 STATISTICS(jniinvokation());
1861 c = (classinfo *) clazz;
1866 if (!(c->state & CLASS_INITIALIZED))
1867 if (!initialize_class(c))
1870 /* try to get the method of the class or one of it's superclasses */
1872 uname = utf_new_char((char *) name);
1873 udesc = utf_new_char((char *) sig);
1875 m = class_resolvemethod(clazz, uname, udesc);
1877 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1878 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1883 return (jmethodID) m;
1887 /* JNI-functions for calling instance methods *********************************/
1889 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1891 java_objectheader *o;
1893 java_objectheader *ret;
1896 o = (java_objectheader *) obj;
1897 m = (methodinfo *) methodID;
1899 va_start(ap, methodID);
1900 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1903 return NewLocalRef(env, ret);
1907 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1909 java_objectheader *o;
1911 java_objectheader *ret;
1913 o = (java_objectheader *) obj;
1914 m = (methodinfo *) methodID;
1916 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1918 return NewLocalRef(env, ret);
1922 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1924 java_objectheader *o;
1926 java_objectheader *ret;
1928 o = (java_objectheader *) obj;
1929 m = (methodinfo *) methodID;
1931 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1933 return NewLocalRef(env, ret);
1937 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1939 java_objectheader *o;
1944 o = (java_objectheader *) obj;
1945 m = (methodinfo *) methodID;
1947 va_start(ap, methodID);
1948 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1955 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1957 java_objectheader *o;
1961 o = (java_objectheader *) obj;
1962 m = (methodinfo *) methodID;
1964 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1970 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1972 java_objectheader *o;
1976 o = (java_objectheader *) obj;
1977 m = (methodinfo *) methodID;
1979 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1985 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1987 java_objectheader *o;
1992 o = (java_objectheader *) obj;
1993 m = (methodinfo *) methodID;
1995 va_start(ap, methodID);
1996 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2003 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2005 java_objectheader *o;
2009 o = (java_objectheader *) obj;
2010 m = (methodinfo *) methodID;
2012 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2018 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2020 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2026 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2028 java_objectheader *o;
2033 o = (java_objectheader *) obj;
2034 m = (methodinfo *) methodID;
2036 va_start(ap, methodID);
2037 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2044 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2046 java_objectheader *o;
2050 o = (java_objectheader *) obj;
2051 m = (methodinfo *) methodID;
2053 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2059 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2061 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2067 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2069 java_objectheader *o;
2074 o = (java_objectheader *) obj;
2075 m = (methodinfo *) methodID;
2077 va_start(ap, methodID);
2078 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2085 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2087 java_objectheader *o;
2091 o = (java_objectheader *) obj;
2092 m = (methodinfo *) methodID;
2094 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2100 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2102 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2109 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2111 java_objectheader *o;
2116 o = (java_objectheader *) obj;
2117 m = (methodinfo *) methodID;
2119 va_start(ap, methodID);
2120 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2127 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2129 java_objectheader *o;
2133 o = (java_objectheader *) obj;
2134 m = (methodinfo *) methodID;
2136 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2142 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2144 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2151 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2153 java_objectheader *o;
2158 o = (java_objectheader *) obj;
2159 m = (methodinfo *) methodID;
2161 va_start(ap, methodID);
2162 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2169 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2171 java_objectheader *o;
2175 o = (java_objectheader *) obj;
2176 m = (methodinfo *) methodID;
2178 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2184 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2186 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2193 jfloat CallFloatMethod(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 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2211 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2213 java_objectheader *o;
2217 o = (java_objectheader *) obj;
2218 m = (methodinfo *) methodID;
2220 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2226 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2228 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2235 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2237 java_objectheader *o;
2242 o = (java_objectheader *) obj;
2243 m = (methodinfo *) methodID;
2245 va_start(ap, methodID);
2246 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2253 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2255 java_objectheader *o;
2259 o = (java_objectheader *) obj;
2260 m = (methodinfo *) methodID;
2262 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2268 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2270 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2277 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2279 java_objectheader *o;
2283 o = (java_objectheader *) obj;
2284 m = (methodinfo *) methodID;
2286 va_start(ap, methodID);
2287 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2292 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2294 java_objectheader *o;
2297 o = (java_objectheader *) obj;
2298 m = (methodinfo *) methodID;
2300 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2304 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2306 java_objectheader *o;
2309 o = (java_objectheader *) obj;
2310 m = (methodinfo *) methodID;
2312 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2317 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2319 java_objectheader *o;
2322 java_objectheader *r;
2325 o = (java_objectheader *) obj;
2326 c = (classinfo *) clazz;
2327 m = (methodinfo *) methodID;
2329 va_start(ap, methodID);
2330 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2333 return NewLocalRef(env, r);
2337 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2339 java_objectheader *o;
2342 java_objectheader *r;
2344 o = (java_objectheader *) obj;
2345 c = (classinfo *) clazz;
2346 m = (methodinfo *) methodID;
2348 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2350 return NewLocalRef(env, r);
2354 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2356 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2358 return NewLocalRef(env, NULL);
2363 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2365 java_objectheader *o;
2371 o = (java_objectheader *) obj;
2372 c = (classinfo *) clazz;
2373 m = (methodinfo *) methodID;
2375 va_start(ap, methodID);
2376 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2383 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2385 java_objectheader *o;
2390 o = (java_objectheader *) obj;
2391 c = (classinfo *) clazz;
2392 m = (methodinfo *) methodID;
2394 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2400 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2402 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2408 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2410 java_objectheader *o;
2416 o = (java_objectheader *) obj;
2417 c = (classinfo *) clazz;
2418 m = (methodinfo *) methodID;
2420 va_start(ap, methodID);
2421 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2428 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2430 java_objectheader *o;
2435 o = (java_objectheader *) obj;
2436 c = (classinfo *) clazz;
2437 m = (methodinfo *) methodID;
2439 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2445 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2447 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2454 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2456 java_objectheader *o;
2462 o = (java_objectheader *) obj;
2463 c = (classinfo *) clazz;
2464 m = (methodinfo *) methodID;
2466 va_start(ap, methodID);
2467 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2474 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2476 java_objectheader *o;
2481 o = (java_objectheader *) obj;
2482 c = (classinfo *) clazz;
2483 m = (methodinfo *) methodID;
2485 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2491 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2493 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2500 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2502 java_objectheader *o;
2508 o = (java_objectheader *) obj;
2509 c = (classinfo *) clazz;
2510 m = (methodinfo *) methodID;
2512 va_start(ap, methodID);
2513 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2520 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2522 java_objectheader *o;
2527 o = (java_objectheader *) obj;
2528 c = (classinfo *) clazz;
2529 m = (methodinfo *) methodID;
2531 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2537 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2539 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2546 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2548 java_objectheader *o;
2554 o = (java_objectheader *) obj;
2555 c = (classinfo *) clazz;
2556 m = (methodinfo *) methodID;
2558 va_start(ap, methodID);
2559 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2566 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2568 java_objectheader *o;
2573 o = (java_objectheader *) obj;
2574 c = (classinfo *) clazz;
2575 m = (methodinfo *) methodID;
2577 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2583 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2585 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2592 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2594 java_objectheader *o;
2600 o = (java_objectheader *) obj;
2601 c = (classinfo *) clazz;
2602 m = (methodinfo *) methodID;
2604 va_start(ap, methodID);
2605 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2612 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2614 java_objectheader *o;
2619 o = (java_objectheader *) obj;
2620 c = (classinfo *) clazz;
2621 m = (methodinfo *) methodID;
2623 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2629 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2631 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2638 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2640 java_objectheader *o;
2646 o = (java_objectheader *) obj;
2647 c = (classinfo *) clazz;
2648 m = (methodinfo *) methodID;
2650 va_start(ap, methodID);
2651 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2658 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2660 java_objectheader *o;
2665 o = (java_objectheader *) obj;
2666 c = (classinfo *) clazz;
2667 m = (methodinfo *) methodID;
2669 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2675 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2677 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2684 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2686 java_objectheader *o;
2692 o = (java_objectheader *) obj;
2693 c = (classinfo *) clazz;
2694 m = (methodinfo *) methodID;
2696 va_start(ap, methodID);
2697 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2704 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2706 java_objectheader *o;
2711 o = (java_objectheader *) obj;
2712 c = (classinfo *) clazz;
2713 m = (methodinfo *) methodID;
2715 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2721 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2723 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2730 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2732 java_objectheader *o;
2737 o = (java_objectheader *) obj;
2738 c = (classinfo *) clazz;
2739 m = (methodinfo *) methodID;
2741 va_start(ap, methodID);
2742 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2747 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2749 java_objectheader *o;
2753 o = (java_objectheader *) obj;
2754 c = (classinfo *) clazz;
2755 m = (methodinfo *) methodID;
2757 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2761 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2763 java_objectheader *o;
2767 o = (java_objectheader *) obj;
2768 c = (classinfo *) clazz;
2769 m = (methodinfo *) methodID;
2771 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2775 /* Accessing Fields of Objects ************************************************/
2777 /* GetFieldID ******************************************************************
2779 Returns the field ID for an instance (nonstatic) field of a
2780 class. The field is specified by its name and signature. The
2781 Get<type>Field and Set<type>Field families of accessor functions
2782 use field IDs to retrieve object fields.
2784 *******************************************************************************/
2786 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2793 STATISTICS(jniinvokation());
2795 uname = utf_new_char((char *) name);
2796 udesc = utf_new_char((char *) sig);
2798 f = class_findfield(clazz, uname, udesc);
2801 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2803 return (jfieldID) f;
2807 /* Get<type>Field Routines *****************************************************
2809 This family of accessor routines returns the value of an instance
2810 (nonstatic) field of an object. The field to access is specified by
2811 a field ID obtained by calling GetFieldID().
2813 *******************************************************************************/
2815 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2817 java_objectheader *o;
2819 STATISTICS(jniinvokation());
2821 o = GET_FIELD(obj, java_objectheader*, fieldID);
2823 return NewLocalRef(env, o);
2827 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2831 STATISTICS(jniinvokation());
2833 i = GET_FIELD(obj, s4, fieldID);
2835 return (jboolean) i;
2839 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2843 STATISTICS(jniinvokation());
2845 i = GET_FIELD(obj, s4, fieldID);
2851 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2855 STATISTICS(jniinvokation());
2857 i = GET_FIELD(obj, s4, fieldID);
2863 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2867 STATISTICS(jniinvokation());
2869 i = GET_FIELD(obj, s4, fieldID);
2875 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2877 java_objectheader *o;
2881 STATISTICS(jniinvokation());
2883 o = (java_objectheader *) obj;
2884 f = (fieldinfo *) fieldID;
2886 i = GET_FIELD(o, s4, f);
2892 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2896 STATISTICS(jniinvokation());
2898 l = GET_FIELD(obj, s8, fieldID);
2904 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2908 STATISTICS(jniinvokation());
2910 f = GET_FIELD(obj, float, fieldID);
2916 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2920 STATISTICS(jniinvokation());
2922 d = GET_FIELD(obj, double, fieldID);
2928 /* Set<type>Field Routines *****************************************************
2930 This family of accessor routines sets the value of an instance
2931 (nonstatic) field of an object. The field to access is specified by
2932 a field ID obtained by calling GetFieldID().
2934 *******************************************************************************/
2936 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2938 STATISTICS(jniinvokation());
2940 SET_FIELD(obj, java_objectheader*, fieldID, value);
2944 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2946 STATISTICS(jniinvokation());
2948 SET_FIELD(obj, s4, fieldID, value);
2952 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2954 STATISTICS(jniinvokation());
2956 SET_FIELD(obj, s4, fieldID, value);
2960 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2962 STATISTICS(jniinvokation());
2964 SET_FIELD(obj, s4, fieldID, value);
2968 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2970 STATISTICS(jniinvokation());
2972 SET_FIELD(obj, s4, fieldID, value);
2976 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2978 STATISTICS(jniinvokation());
2980 SET_FIELD(obj, s4, fieldID, value);
2984 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2986 STATISTICS(jniinvokation());
2988 SET_FIELD(obj, s8, fieldID, value);
2992 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
2994 STATISTICS(jniinvokation());
2996 SET_FIELD(obj, float, fieldID, value);
3000 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3002 STATISTICS(jniinvokation());
3004 SET_FIELD(obj, double, fieldID, value);
3008 /* Calling Static Methods *****************************************************/
3010 /* GetStaticMethodID ***********************************************************
3012 Returns the method ID for a static method of a class. The method is
3013 specified by its name and signature.
3015 GetStaticMethodID() causes an uninitialized class to be
3018 *******************************************************************************/
3020 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3028 STATISTICS(jniinvokation());
3030 c = (classinfo *) clazz;
3035 if (!(c->state & CLASS_INITIALIZED))
3036 if (!initialize_class(c))
3039 /* try to get the static method of the class */
3041 uname = utf_new_char((char *) name);
3042 udesc = utf_new_char((char *) sig);
3044 m = class_resolvemethod(c, uname, udesc);
3046 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3047 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3052 return (jmethodID) m;
3056 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3059 java_objectheader *o;
3062 m = (methodinfo *) methodID;
3064 va_start(ap, methodID);
3065 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3068 return NewLocalRef(env, o);
3072 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3075 java_objectheader *o;
3077 m = (methodinfo *) methodID;
3079 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3081 return NewLocalRef(env, o);
3085 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3088 java_objectheader *o;
3090 m = (methodinfo *) methodID;
3092 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3094 return NewLocalRef(env, o);
3098 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3104 m = (methodinfo *) methodID;
3106 va_start(ap, methodID);
3107 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3114 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3119 m = (methodinfo *) methodID;
3121 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3127 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3129 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3135 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3141 m = (methodinfo *) methodID;
3143 va_start(ap, methodID);
3144 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3151 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3156 m = (methodinfo *) methodID;
3158 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3164 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3166 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3172 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3178 m = (methodinfo *) methodID;
3180 va_start(ap, methodID);
3181 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3188 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3193 m = (methodinfo *) methodID;
3195 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3201 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3203 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3209 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3215 m = (methodinfo *) methodID;
3217 va_start(ap, methodID);
3218 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3225 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3230 m = (methodinfo *) methodID;
3232 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3238 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3240 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3246 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3252 m = (methodinfo *) methodID;
3254 va_start(ap, methodID);
3255 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3262 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3267 m = (methodinfo *) methodID;
3269 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3275 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3277 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3283 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3289 m = (methodinfo *) methodID;
3291 va_start(ap, methodID);
3292 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3299 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3305 m = (methodinfo *) methodID;
3307 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3313 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3315 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3322 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3328 m = (methodinfo *) methodID;
3330 va_start(ap, methodID);
3331 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3338 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3343 m = (methodinfo *) methodID;
3345 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3351 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3353 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3359 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3365 m = (methodinfo *) methodID;
3367 va_start(ap, methodID);
3368 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3375 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3380 m = (methodinfo *) methodID;
3382 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3388 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3390 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3396 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3401 m = (methodinfo *) methodID;
3403 va_start(ap, methodID);
3404 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3409 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3413 m = (methodinfo *) methodID;
3415 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3419 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3423 m = (methodinfo *) methodID;
3425 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3429 /* Accessing Static Fields ****************************************************/
3431 /* GetStaticFieldID ************************************************************
3433 Returns the field ID for a static field of a class. The field is
3434 specified by its name and signature. The GetStatic<type>Field and
3435 SetStatic<type>Field families of accessor functions use field IDs
3436 to retrieve static fields.
3438 *******************************************************************************/
3440 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3444 STATISTICS(jniinvokation());
3446 f = class_findfield(clazz,
3447 utf_new_char((char *) name),
3448 utf_new_char((char *) sig));
3451 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3453 return (jfieldID) f;
3457 /* GetStatic<type>Field ********************************************************
3459 This family of accessor routines returns the value of a static
3462 *******************************************************************************/
3464 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3469 STATISTICS(jniinvokation());
3471 c = (classinfo *) clazz;
3472 f = (fieldinfo *) fieldID;
3474 if (!(c->state & CLASS_INITIALIZED))
3475 if (!initialize_class(c))
3478 return NewLocalRef(env, f->value.a);
3482 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3487 STATISTICS(jniinvokation());
3489 c = (classinfo *) clazz;
3490 f = (fieldinfo *) fieldID;
3492 if (!(c->state & CLASS_INITIALIZED))
3493 if (!initialize_class(c))
3500 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3505 STATISTICS(jniinvokation());
3507 c = (classinfo *) clazz;
3508 f = (fieldinfo *) fieldID;
3510 if (!(c->state & CLASS_INITIALIZED))
3511 if (!initialize_class(c))
3518 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3523 STATISTICS(jniinvokation());
3525 c = (classinfo *) clazz;
3526 f = (fieldinfo *) fieldID;
3528 if (!(c->state & CLASS_INITIALIZED))
3529 if (!initialize_class(c))
3536 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3541 STATISTICS(jniinvokation());
3543 c = (classinfo *) clazz;
3544 f = (fieldinfo *) fieldID;
3546 if (!(c->state & CLASS_INITIALIZED))
3547 if (!initialize_class(c))
3554 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3559 STATISTICS(jniinvokation());
3561 c = (classinfo *) clazz;
3562 f = (fieldinfo *) fieldID;
3564 if (!(c->state & CLASS_INITIALIZED))
3565 if (!initialize_class(c))
3572 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3577 STATISTICS(jniinvokation());
3579 c = (classinfo *) clazz;
3580 f = (fieldinfo *) fieldID;
3582 if (!(c->state & CLASS_INITIALIZED))
3583 if (!initialize_class(c))
3590 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3595 STATISTICS(jniinvokation());
3597 c = (classinfo *) clazz;
3598 f = (fieldinfo *) fieldID;
3600 if (!(c->state & CLASS_INITIALIZED))
3601 if (!initialize_class(c))
3608 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3613 STATISTICS(jniinvokation());
3615 c = (classinfo *) clazz;
3616 f = (fieldinfo *) fieldID;
3618 if (!(c->state & CLASS_INITIALIZED))
3619 if (!initialize_class(c))
3626 /* SetStatic<type>Field *******************************************************
3628 This family of accessor routines sets the value of a static field
3631 *******************************************************************************/
3633 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3638 STATISTICS(jniinvokation());
3640 c = (classinfo *) clazz;
3641 f = (fieldinfo *) fieldID;
3643 if (!(c->state & CLASS_INITIALIZED))
3644 if (!initialize_class(c))
3651 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3656 STATISTICS(jniinvokation());
3658 c = (classinfo *) clazz;
3659 f = (fieldinfo *) fieldID;
3661 if (!(c->state & CLASS_INITIALIZED))
3662 if (!initialize_class(c))
3669 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3674 STATISTICS(jniinvokation());
3676 c = (classinfo *) clazz;
3677 f = (fieldinfo *) fieldID;
3679 if (!(c->state & CLASS_INITIALIZED))
3680 if (!initialize_class(c))
3687 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3692 STATISTICS(jniinvokation());
3694 c = (classinfo *) clazz;
3695 f = (fieldinfo *) fieldID;
3697 if (!(c->state & CLASS_INITIALIZED))
3698 if (!initialize_class(c))
3705 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3710 STATISTICS(jniinvokation());
3712 c = (classinfo *) clazz;
3713 f = (fieldinfo *) fieldID;
3715 if (!(c->state & CLASS_INITIALIZED))
3716 if (!initialize_class(c))
3723 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3728 STATISTICS(jniinvokation());
3730 c = (classinfo *) clazz;
3731 f = (fieldinfo *) fieldID;
3733 if (!(c->state & CLASS_INITIALIZED))
3734 if (!initialize_class(c))
3741 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3746 STATISTICS(jniinvokation());
3748 c = (classinfo *) clazz;
3749 f = (fieldinfo *) fieldID;
3751 if (!(c->state & CLASS_INITIALIZED))
3752 if (!initialize_class(c))
3759 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3764 STATISTICS(jniinvokation());
3766 c = (classinfo *) clazz;
3767 f = (fieldinfo *) fieldID;
3769 if (!(c->state & CLASS_INITIALIZED))
3770 if (!initialize_class(c))
3777 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3782 STATISTICS(jniinvokation());
3784 c = (classinfo *) clazz;
3785 f = (fieldinfo *) fieldID;
3787 if (!(c->state & CLASS_INITIALIZED))
3788 if (!initialize_class(c))
3795 /* String Operations **********************************************************/
3797 /* NewString *******************************************************************
3799 Create new java.lang.String object from an array of Unicode
3802 *******************************************************************************/
3804 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3806 java_lang_String *s;
3810 STATISTICS(jniinvokation());
3812 s = (java_lang_String *) builtin_new(class_java_lang_String);
3813 a = builtin_newarray_char(len);
3815 /* javastring or characterarray could not be created */
3820 for (i = 0; i < len; i++)
3821 a->data[i] = buf[i];
3827 return (jstring) NewLocalRef(env, (jobject) s);
3831 static jchar emptyStringJ[]={0,0};
3833 /* GetStringLength *************************************************************
3835 Returns the length (the count of Unicode characters) of a Java
3838 *******************************************************************************/
3840 jsize GetStringLength(JNIEnv *env, jstring str)
3842 return ((java_lang_String *) str)->count;
3846 /******************** convertes javastring to u2-array ****************************/
3848 u2 *javastring_tou2(jstring so)
3850 java_lang_String *s;
3855 STATISTICS(jniinvokation());
3857 s = (java_lang_String *) so;
3867 /* allocate memory */
3869 stringbuffer = MNEW(u2, s->count + 1);
3873 for (i = 0; i < s->count; i++)
3874 stringbuffer[i] = a->data[s->offset + i];
3876 /* terminate string */
3878 stringbuffer[i] = '\0';
3880 return stringbuffer;
3884 /* GetStringChars **************************************************************
3886 Returns a pointer to the array of Unicode characters of the
3887 string. This pointer is valid until ReleaseStringchars() is called.
3889 *******************************************************************************/
3891 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3895 STATISTICS(jniinvokation());
3897 jc = javastring_tou2(str);
3909 return emptyStringJ;
3913 /* ReleaseStringChars **********************************************************
3915 Informs the VM that the native code no longer needs access to
3916 chars. The chars argument is a pointer obtained from string using
3919 *******************************************************************************/
3921 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3923 STATISTICS(jniinvokation());
3925 if (chars == emptyStringJ)
3928 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3932 /* NewStringUTF ****************************************************************
3934 Constructs a new java.lang.String object from an array of UTF-8 characters.
3936 *******************************************************************************/
3938 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3940 java_lang_String *s;
3942 STATISTICS(jniinvokation());
3944 s = javastring_new(utf_new_char(bytes));
3946 return (jstring) NewLocalRef(env, (jobject) s);
3950 /****************** returns the utf8 length in bytes of a string *******************/
3952 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3954 java_lang_String *s = (java_lang_String*) string;
3956 STATISTICS(jniinvokation());
3958 return (jsize) u2_utflength(s->value->data, s->count);
3962 /* GetStringUTFChars ***********************************************************
3964 Returns a pointer to an array of UTF-8 characters of the
3965 string. This array is valid until it is released by
3966 ReleaseStringUTFChars().
3968 *******************************************************************************/
3970 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3974 STATISTICS(jniinvokation());
3982 u = javastring_toutf((java_lang_String *) string, false);
3991 /* ReleaseStringUTFChars *******************************************************
3993 Informs the VM that the native code no longer needs access to
3994 utf. The utf argument is a pointer derived from string using
3995 GetStringUTFChars().
3997 *******************************************************************************/
3999 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4001 STATISTICS(jniinvokation());
4003 /* XXX we don't release utf chars right now, perhaps that should be done
4004 later. Since there is always one reference the garbage collector will
4009 /* Array Operations ***********************************************************/
4011 /* GetArrayLength **************************************************************
4013 Returns the number of elements in the array.
4015 *******************************************************************************/
4017 jsize GetArrayLength(JNIEnv *env, jarray array)
4019 java_arrayheader *a;
4021 STATISTICS(jniinvokation());
4023 a = (java_arrayheader *) array;
4029 /* NewObjectArray **************************************************************
4031 Constructs a new array holding objects in class elementClass. All
4032 elements are initially set to initialElement.
4034 *******************************************************************************/
4036 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4038 java_objectarray *oa;
4041 STATISTICS(jniinvokation());
4044 exceptions_throw_negativearraysizeexception();
4048 oa = builtin_anewarray(length, elementClass);
4053 /* set all elements to initialElement */
4055 for (i = 0; i < length; i++)
4056 oa->data[i] = initialElement;
4058 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4062 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4064 java_objectarray *oa;
4067 STATISTICS(jniinvokation());
4069 oa = (java_objectarray *) array;
4071 if (index >= oa->header.size) {
4072 exceptions_throw_arrayindexoutofboundsexception();
4076 o = oa->data[index];
4078 return NewLocalRef(env, o);
4082 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4084 java_objectarray *oa;
4085 java_objectheader *o;
4087 STATISTICS(jniinvokation());
4089 oa = (java_objectarray *) array;
4090 o = (java_objectheader *) val;
4092 if (index >= oa->header.size) {
4093 exceptions_throw_arrayindexoutofboundsexception();
4097 /* check if the class of value is a subclass of the element class
4100 if (!builtin_canstore(oa, o)) {
4101 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4106 oa->data[index] = val;
4110 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4112 java_booleanarray *ba;
4114 STATISTICS(jniinvokation());
4117 exceptions_throw_negativearraysizeexception();
4121 ba = builtin_newarray_boolean(len);
4123 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4127 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4131 STATISTICS(jniinvokation());
4134 exceptions_throw_negativearraysizeexception();
4138 ba = builtin_newarray_byte(len);
4140 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4144 jcharArray NewCharArray(JNIEnv *env, jsize len)
4148 STATISTICS(jniinvokation());
4151 exceptions_throw_negativearraysizeexception();
4155 ca = builtin_newarray_char(len);
4157 return (jcharArray) NewLocalRef(env, (jobject) ca);
4161 jshortArray NewShortArray(JNIEnv *env, jsize len)
4163 java_shortarray *sa;
4165 STATISTICS(jniinvokation());
4168 exceptions_throw_negativearraysizeexception();
4172 sa = builtin_newarray_short(len);
4174 return (jshortArray) NewLocalRef(env, (jobject) sa);
4178 jintArray NewIntArray(JNIEnv *env, jsize len)
4182 STATISTICS(jniinvokation());
4185 exceptions_throw_negativearraysizeexception();
4189 ia = builtin_newarray_int(len);
4191 return (jintArray) NewLocalRef(env, (jobject) ia);
4195 jlongArray NewLongArray(JNIEnv *env, jsize len)
4199 STATISTICS(jniinvokation());
4202 exceptions_throw_negativearraysizeexception();
4206 la = builtin_newarray_long(len);
4208 return (jlongArray) NewLocalRef(env, (jobject) la);
4212 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4214 java_floatarray *fa;
4216 STATISTICS(jniinvokation());
4219 exceptions_throw_negativearraysizeexception();
4223 fa = builtin_newarray_float(len);
4225 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4229 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4231 java_doublearray *da;
4233 STATISTICS(jniinvokation());
4236 exceptions_throw_negativearraysizeexception();
4240 da = builtin_newarray_double(len);
4242 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4246 /* Get<PrimitiveType>ArrayElements *********************************************
4248 A family of functions that returns the body of the primitive array.
4250 *******************************************************************************/
4252 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4255 java_booleanarray *ba;
4257 STATISTICS(jniinvokation());
4259 ba = (java_booleanarray *) array;
4262 *isCopy = JNI_FALSE;
4268 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4272 STATISTICS(jniinvokation());
4274 ba = (java_bytearray *) array;
4277 *isCopy = JNI_FALSE;
4283 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4287 STATISTICS(jniinvokation());
4289 ca = (java_chararray *) array;
4292 *isCopy = JNI_FALSE;
4298 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4300 java_shortarray *sa;
4302 STATISTICS(jniinvokation());
4304 sa = (java_shortarray *) array;
4307 *isCopy = JNI_FALSE;
4313 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4317 STATISTICS(jniinvokation());
4319 ia = (java_intarray *) array;
4322 *isCopy = JNI_FALSE;
4328 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4332 STATISTICS(jniinvokation());
4334 la = (java_longarray *) array;
4337 *isCopy = JNI_FALSE;
4339 /* We cast this one to prevent a compiler warning on 64-bit
4340 systems since GNU Classpath typedef jlong to long long. */
4342 return (jlong *) la->data;
4346 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4348 java_floatarray *fa;
4350 STATISTICS(jniinvokation());
4352 fa = (java_floatarray *) array;
4355 *isCopy = JNI_FALSE;
4361 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4364 java_doublearray *da;
4366 STATISTICS(jniinvokation());
4368 da = (java_doublearray *) array;
4371 *isCopy = JNI_FALSE;
4377 /* Release<PrimitiveType>ArrayElements *****************************************
4379 A family of functions that informs the VM that the native code no
4380 longer needs access to elems. The elems argument is a pointer
4381 derived from array using the corresponding
4382 Get<PrimitiveType>ArrayElements() function. If necessary, this
4383 function copies back all changes made to elems to the original
4386 *******************************************************************************/
4388 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4389 jboolean *elems, jint mode)
4391 java_booleanarray *ba;
4393 STATISTICS(jniinvokation());
4395 ba = (java_booleanarray *) array;
4397 if (elems != ba->data) {
4400 MCOPY(ba->data, elems, u1, ba->header.size);
4403 MCOPY(ba->data, elems, u1, ba->header.size);
4404 /* XXX TWISTI how should it be freed? */
4407 /* XXX TWISTI how should it be freed? */
4414 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4419 STATISTICS(jniinvokation());
4421 ba = (java_bytearray *) array;
4423 if (elems != ba->data) {
4426 MCOPY(ba->data, elems, s1, ba->header.size);
4429 MCOPY(ba->data, elems, s1, ba->header.size);
4430 /* XXX TWISTI how should it be freed? */
4433 /* XXX TWISTI how should it be freed? */
4440 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4445 STATISTICS(jniinvokation());
4447 ca = (java_chararray *) array;
4449 if (elems != ca->data) {
4452 MCOPY(ca->data, elems, u2, ca->header.size);
4455 MCOPY(ca->data, elems, u2, ca->header.size);
4456 /* XXX TWISTI how should it be freed? */
4459 /* XXX TWISTI how should it be freed? */
4466 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4469 java_shortarray *sa;
4471 STATISTICS(jniinvokation());
4473 sa = (java_shortarray *) array;
4475 if (elems != sa->data) {
4478 MCOPY(sa->data, elems, s2, sa->header.size);
4481 MCOPY(sa->data, elems, s2, sa->header.size);
4482 /* XXX TWISTI how should it be freed? */
4485 /* XXX TWISTI how should it be freed? */
4492 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4497 STATISTICS(jniinvokation());
4499 ia = (java_intarray *) array;
4501 if (elems != ia->data) {
4504 MCOPY(ia->data, elems, s4, ia->header.size);
4507 MCOPY(ia->data, elems, s4, ia->header.size);
4508 /* XXX TWISTI how should it be freed? */
4511 /* XXX TWISTI how should it be freed? */
4518 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4523 STATISTICS(jniinvokation());
4525 la = (java_longarray *) array;
4527 /* We cast this one to prevent a compiler warning on 64-bit
4528 systems since GNU Classpath typedef jlong to long long. */
4530 if ((s8 *) elems != la->data) {
4533 MCOPY(la->data, elems, s8, la->header.size);
4536 MCOPY(la->data, elems, s8, la->header.size);
4537 /* XXX TWISTI how should it be freed? */
4540 /* XXX TWISTI how should it be freed? */
4547 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4550 java_floatarray *fa;
4552 STATISTICS(jniinvokation());
4554 fa = (java_floatarray *) array;
4556 if (elems != fa->data) {
4559 MCOPY(fa->data, elems, float, fa->header.size);
4562 MCOPY(fa->data, elems, float, fa->header.size);
4563 /* XXX TWISTI how should it be freed? */
4566 /* XXX TWISTI how should it be freed? */
4573 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4574 jdouble *elems, jint mode)
4576 java_doublearray *da;
4578 STATISTICS(jniinvokation());
4580 da = (java_doublearray *) array;
4582 if (elems != da->data) {
4585 MCOPY(da->data, elems, double, da->header.size);
4588 MCOPY(da->data, elems, double, da->header.size);
4589 /* XXX TWISTI how should it be freed? */
4592 /* XXX TWISTI how should it be freed? */
4599 /* Get<PrimitiveType>ArrayRegion **********************************************
4601 A family of functions that copies a region of a primitive array
4604 *******************************************************************************/
4606 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4607 jsize len, jboolean *buf)
4609 java_booleanarray *ba;
4611 STATISTICS(jniinvokation());
4613 ba = (java_booleanarray *) array;
4615 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4616 exceptions_throw_arrayindexoutofboundsexception();
4618 MCOPY(buf, &ba->data[start], u1, len);
4622 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4627 STATISTICS(jniinvokation());
4629 ba = (java_bytearray *) array;
4631 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4632 exceptions_throw_arrayindexoutofboundsexception();
4634 MCOPY(buf, &ba->data[start], s1, len);
4638 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4643 STATISTICS(jniinvokation());
4645 ca = (java_chararray *) array;
4647 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4648 exceptions_throw_arrayindexoutofboundsexception();
4650 MCOPY(buf, &ca->data[start], u2, len);
4654 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4655 jsize len, jshort *buf)
4657 java_shortarray *sa;
4659 STATISTICS(jniinvokation());
4661 sa = (java_shortarray *) array;
4663 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4664 exceptions_throw_arrayindexoutofboundsexception();
4666 MCOPY(buf, &sa->data[start], s2, len);
4670 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4675 STATISTICS(jniinvokation());
4677 ia = (java_intarray *) array;
4679 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4680 exceptions_throw_arrayindexoutofboundsexception();
4682 MCOPY(buf, &ia->data[start], s4, len);
4686 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4691 STATISTICS(jniinvokation());
4693 la = (java_longarray *) array;
4695 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4696 exceptions_throw_arrayindexoutofboundsexception();
4698 MCOPY(buf, &la->data[start], s8, len);
4702 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4703 jsize len, jfloat *buf)
4705 java_floatarray *fa;
4707 STATISTICS(jniinvokation());
4709 fa = (java_floatarray *) array;
4711 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4712 exceptions_throw_arrayindexoutofboundsexception();
4714 MCOPY(buf, &fa->data[start], float, len);
4718 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4719 jsize len, jdouble *buf)
4721 java_doublearray *da;
4723 STATISTICS(jniinvokation());
4725 da = (java_doublearray *) array;
4727 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4728 exceptions_throw_arrayindexoutofboundsexception();
4730 MCOPY(buf, &da->data[start], double, len);
4734 /* Set<PrimitiveType>ArrayRegion **********************************************
4736 A family of functions that copies back a region of a primitive
4737 array from a buffer.
4739 *******************************************************************************/
4741 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4742 jsize len, jboolean *buf)
4744 java_booleanarray *ba;
4746 STATISTICS(jniinvokation());
4748 ba = (java_booleanarray *) array;
4750 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4751 exceptions_throw_arrayindexoutofboundsexception();
4753 MCOPY(&ba->data[start], buf, u1, len);
4757 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4762 STATISTICS(jniinvokation());
4764 ba = (java_bytearray *) array;
4766 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4767 exceptions_throw_arrayindexoutofboundsexception();
4769 MCOPY(&ba->data[start], buf, s1, len);
4773 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4778 STATISTICS(jniinvokation());
4780 ca = (java_chararray *) array;
4782 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4783 exceptions_throw_arrayindexoutofboundsexception();
4785 MCOPY(&ca->data[start], buf, u2, len);
4789 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4790 jsize len, jshort *buf)
4792 java_shortarray *sa;
4794 STATISTICS(jniinvokation());
4796 sa = (java_shortarray *) array;
4798 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4799 exceptions_throw_arrayindexoutofboundsexception();
4801 MCOPY(&sa->data[start], buf, s2, len);
4805 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4810 STATISTICS(jniinvokation());
4812 ia = (java_intarray *) array;
4814 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4815 exceptions_throw_arrayindexoutofboundsexception();
4817 MCOPY(&ia->data[start], buf, s4, len);
4821 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4826 STATISTICS(jniinvokation());
4828 la = (java_longarray *) array;
4830 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4831 exceptions_throw_arrayindexoutofboundsexception();
4833 MCOPY(&la->data[start], buf, s8, len);
4837 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4838 jsize len, jfloat *buf)
4840 java_floatarray *fa;
4842 STATISTICS(jniinvokation());
4844 fa = (java_floatarray *) array;
4846 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4847 exceptions_throw_arrayindexoutofboundsexception();
4849 MCOPY(&fa->data[start], buf, float, len);
4853 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4854 jsize len, jdouble *buf)
4856 java_doublearray *da;
4858 STATISTICS(jniinvokation());
4860 da = (java_doublearray *) array;
4862 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4863 exceptions_throw_arrayindexoutofboundsexception();
4865 MCOPY(&da->data[start], buf, double, len);
4869 /* Registering Native Methods *************************************************/
4871 /* RegisterNatives *************************************************************
4873 Registers native methods with the class specified by the clazz
4874 argument. The methods parameter specifies an array of
4875 JNINativeMethod structures that contain the names, signatures, and
4876 function pointers of the native methods. The nMethods parameter
4877 specifies the number of native methods in the array.
4879 *******************************************************************************/
4881 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4884 STATISTICS(jniinvokation());
4886 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4892 /* UnregisterNatives ***********************************************************
4894 Unregisters native methods of a class. The class goes back to the
4895 state before it was linked or registered with its native method
4898 This function should not be used in normal native code. Instead, it
4899 provides special programs a way to reload and relink native
4902 *******************************************************************************/
4904 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4906 STATISTICS(jniinvokation());
4908 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4910 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4916 /* Monitor Operations *********************************************************/
4918 /* MonitorEnter ****************************************************************
4920 Enters the monitor associated with the underlying Java object
4923 *******************************************************************************/
4925 jint MonitorEnter(JNIEnv *env, jobject obj)
4927 STATISTICS(jniinvokation());
4930 exceptions_throw_nullpointerexception();
4934 #if defined(ENABLE_THREADS)
4935 builtin_monitorenter(obj);
4942 /* MonitorExit *****************************************************************
4944 The current thread must be the owner of the monitor associated with
4945 the underlying Java object referred to by obj. The thread
4946 decrements the counter indicating the number of times it has
4947 entered this monitor. If the value of the counter becomes zero, the
4948 current thread releases the monitor.
4950 *******************************************************************************/
4952 jint MonitorExit(JNIEnv *env, jobject obj)
4954 STATISTICS(jniinvokation());
4957 exceptions_throw_nullpointerexception();
4961 #if defined(ENABLE_THREADS)
4962 builtin_monitorexit(obj);
4969 /* JavaVM Interface ***********************************************************/
4971 /* GetJavaVM *******************************************************************
4973 Returns the Java VM interface (used in the Invocation API)
4974 associated with the current thread. The result is placed at the
4975 location pointed to by the second argument, vm.
4977 *******************************************************************************/
4979 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4981 STATISTICS(jniinvokation());
4983 *vm = (JavaVM *) _Jv_jvm;
4989 /* GetStringRegion *************************************************************
4991 Copies len number of Unicode characters beginning at offset start
4992 to the given buffer buf.
4994 Throws StringIndexOutOfBoundsException on index overflow.
4996 *******************************************************************************/
4998 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
5000 java_lang_String *s;
5003 STATISTICS(jniinvokation());
5005 s = (java_lang_String *) str;
5008 if ((start < 0) || (len < 0) || (start > s->count) ||
5009 (start + len > s->count)) {
5010 exceptions_throw_stringindexoutofboundsexception();
5014 MCOPY(buf, &ca->data[start], u2, len);
5018 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5020 STATISTICS(jniinvokation());
5022 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5026 /* GetPrimitiveArrayCritical ***************************************************
5028 Obtain a direct pointer to array elements.
5030 *******************************************************************************/
5032 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5037 ba = (java_bytearray *) array;
5039 /* do the same as Kaffe does */
5041 bp = GetByteArrayElements(env, ba, isCopy);
5047 /* ReleasePrimitiveArrayCritical ***********************************************
5049 No specific documentation.
5051 *******************************************************************************/
5053 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5056 STATISTICS(jniinvokation());
5058 /* do the same as Kaffe does */
5060 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5064 /* GetStringCritical ***********************************************************
5066 The semantics of these two functions are similar to the existing
5067 Get/ReleaseStringChars functions.
5069 *******************************************************************************/
5071 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5073 STATISTICS(jniinvokation());
5075 return GetStringChars(env, string, isCopy);
5079 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5081 STATISTICS(jniinvokation());
5083 ReleaseStringChars(env, string, cstring);
5087 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5089 STATISTICS(jniinvokation());
5091 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5097 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5099 STATISTICS(jniinvokation());
5101 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5105 /* NewGlobalRef ****************************************************************
5107 Creates a new global reference to the object referred to by the obj
5110 *******************************************************************************/
5112 jobject NewGlobalRef(JNIEnv* env, jobject obj)
5114 hashtable_global_ref_entry *gre;
5115 u4 key; /* hashkey */
5116 u4 slot; /* slot in hashtable */
5118 STATISTICS(jniinvokation());
5120 #if defined(ENABLE_THREADS)
5121 builtin_monitorenter(hashtable_global_ref->header);
5124 /* normally addresses are aligned to 4, 8 or 16 bytes */
5126 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5127 slot = key & (hashtable_global_ref->size - 1);
5128 gre = hashtable_global_ref->ptr[slot];
5130 /* search external hash chain for the entry */
5133 if (gre->o == obj) {
5134 /* global object found, increment the reference */
5138 #if defined(ENABLE_THREADS)
5139 builtin_monitorexit(hashtable_global_ref->header);
5145 gre = gre->hashlink; /* next element in external chain */
5148 /* global ref not found, create a new one */
5150 gre = NEW(hashtable_global_ref_entry);
5155 /* insert entry into hashtable */
5157 gre->hashlink = hashtable_global_ref->ptr[slot];
5159 hashtable_global_ref->ptr[slot] = gre;
5161 /* update number of hashtable-entries */
5163 hashtable_global_ref->entries++;
5165 #if defined(ENABLE_THREADS)
5166 builtin_monitorexit(hashtable_global_ref->header);
5173 /* DeleteGlobalRef *************************************************************
5175 Deletes the global reference pointed to by globalRef.
5177 *******************************************************************************/
5179 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5181 hashtable_global_ref_entry *gre;
5182 hashtable_global_ref_entry *prevgre;
5183 u4 key; /* hashkey */
5184 u4 slot; /* slot in hashtable */
5186 STATISTICS(jniinvokation());
5188 #if defined(ENABLE_THREADS)
5189 builtin_monitorenter(hashtable_global_ref->header);
5192 /* normally addresses are aligned to 4, 8 or 16 bytes */
5194 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5195 slot = key & (hashtable_global_ref->size - 1);
5196 gre = hashtable_global_ref->ptr[slot];
5198 /* initialize prevgre */
5202 /* search external hash chain for the entry */
5205 if (gre->o == globalRef) {
5206 /* global object found, decrement the reference count */
5210 /* if reference count is 0, remove the entry */
5212 if (gre->refs == 0) {
5213 /* special handling if it's the first in the chain */
5215 if (prevgre == NULL)
5216 hashtable_global_ref->ptr[slot] = gre->hashlink;
5218 prevgre->hashlink = gre->hashlink;
5220 FREE(gre, hashtable_global_ref_entry);
5223 #if defined(ENABLE_THREADS)
5224 builtin_monitorexit(hashtable_global_ref->header);
5230 prevgre = gre; /* save current pointer for removal */
5231 gre = gre->hashlink; /* next element in external chain */
5234 log_println("JNI-DeleteGlobalRef: global reference not found");
5236 #if defined(ENABLE_THREADS)
5237 builtin_monitorexit(hashtable_global_ref->header);
5242 /* ExceptionCheck **************************************************************
5244 Returns JNI_TRUE when there is a pending exception; otherwise,
5247 *******************************************************************************/
5249 jboolean ExceptionCheck(JNIEnv *env)
5251 STATISTICS(jniinvokation());
5253 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5257 /* New JNI 1.4 functions ******************************************************/
5259 /* NewDirectByteBuffer *********************************************************
5261 Allocates and returns a direct java.nio.ByteBuffer referring to the
5262 block of memory starting at the memory address address and
5263 extending capacity bytes.
5265 *******************************************************************************/
5267 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5269 java_objectheader *nbuf;
5270 #if SIZEOF_VOID_P == 8
5271 gnu_classpath_Pointer64 *paddress;
5273 gnu_classpath_Pointer32 *paddress;
5276 STATISTICS(jniinvokation());
5278 /* alocate a gnu.classpath.Pointer{32,64} object */
5280 #if SIZEOF_VOID_P == 8
5281 if (!(paddress = (gnu_classpath_Pointer64 *)
5282 builtin_new(class_gnu_classpath_Pointer64)))
5284 if (!(paddress = (gnu_classpath_Pointer32 *)
5285 builtin_new(class_gnu_classpath_Pointer32)))
5289 /* fill gnu.classpath.Pointer{32,64} with address */
5291 paddress->data = (ptrint) address;
5293 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5295 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5296 (jmethodID) dbbirw_init, NULL, paddress,
5297 (jint) capacity, (jint) capacity, (jint) 0);
5299 /* add local reference and return the value */
5301 return NewLocalRef(env, nbuf);
5305 /* GetDirectBufferAddress ******************************************************
5307 Fetches and returns the starting address of the memory region
5308 referenced by the given direct java.nio.Buffer.
5310 *******************************************************************************/
5312 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5314 java_nio_DirectByteBufferImpl *nbuf;
5315 #if SIZEOF_VOID_P == 8
5316 gnu_classpath_Pointer64 *address;
5318 gnu_classpath_Pointer32 *address;
5321 STATISTICS(jniinvokation());
5323 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5326 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5328 #if SIZEOF_VOID_P == 8
5329 address = (gnu_classpath_Pointer64 *) nbuf->address;
5331 address = (gnu_classpath_Pointer32 *) nbuf->address;
5334 return (void *) address->data;
5338 /* GetDirectBufferCapacity *****************************************************
5340 Fetches and returns the capacity in bytes of the memory region
5341 referenced by the given direct java.nio.Buffer.
5343 *******************************************************************************/
5345 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5347 java_nio_Buffer *nbuf;
5349 STATISTICS(jniinvokation());
5351 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5354 nbuf = (java_nio_Buffer *) buf;
5356 return (jlong) nbuf->cap;
5360 /* DestroyJavaVM ***************************************************************
5362 Unloads a Java VM and reclaims its resources. Only the main thread
5363 can unload the VM. The system waits until the main thread is only
5364 remaining user thread before it destroys the VM.
5366 *******************************************************************************/
5368 jint DestroyJavaVM(JavaVM *vm)
5372 STATISTICS(jniinvokation());
5374 status = vm_destroy(vm);
5380 /* AttachCurrentThread *********************************************************
5382 Attaches the current thread to a Java VM. Returns a JNI interface
5383 pointer in the JNIEnv argument.
5385 Trying to attach a thread that is already attached is a no-op.
5387 A native thread cannot be attached simultaneously to two Java VMs.
5389 When a thread is attached to the VM, the context class loader is
5390 the bootstrap loader.
5392 *******************************************************************************/
5394 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5396 STATISTICS(jniinvokation());
5398 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5400 #if !defined(HAVE___THREAD)
5401 /* cacao_thread_attach();*/
5403 #error "No idea how to implement that. Perhaps Stefan knows"
5412 jint DetachCurrentThread(JavaVM *vm)
5414 STATISTICS(jniinvokation());
5416 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5422 /* GetEnv **********************************************************************
5424 If the current thread is not attached to the VM, sets *env to NULL,
5425 and returns JNI_EDETACHED. If the specified version is not
5426 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5427 sets *env to the appropriate interface, and returns JNI_OK.
5429 *******************************************************************************/
5431 jint GetEnv(JavaVM *vm, void **env, jint version)
5433 STATISTICS(jniinvokation());
5435 #if defined(ENABLE_THREADS)
5436 if (threads_get_current_threadobject() == NULL) {
5439 return JNI_EDETACHED;
5443 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5444 (version == JNI_VERSION_1_4)) {
5450 #if defined(ENABLE_JVMTI)
5451 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5452 == JVMTI_VERSION_INTERFACE_JVMTI) {
5454 *env = (void *) jvmti_new_environment();
5463 return JNI_EVERSION;
5468 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5470 STATISTICS(jniinvokation());
5472 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5478 /* JNI invocation table *******************************************************/
5480 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5486 AttachCurrentThread,
5487 DetachCurrentThread,
5489 AttachCurrentThreadAsDaemon
5493 /* JNI function table *********************************************************/
5495 struct JNINativeInterface _Jv_JNINativeInterface = {
5504 FromReflectedMethod,
5525 EnsureLocalCapacity,
5568 CallNonvirtualObjectMethod,
5569 CallNonvirtualObjectMethodV,
5570 CallNonvirtualObjectMethodA,
5571 CallNonvirtualBooleanMethod,
5572 CallNonvirtualBooleanMethodV,
5573 CallNonvirtualBooleanMethodA,
5574 CallNonvirtualByteMethod,
5575 CallNonvirtualByteMethodV,
5576 CallNonvirtualByteMethodA,
5577 CallNonvirtualCharMethod,
5578 CallNonvirtualCharMethodV,
5579 CallNonvirtualCharMethodA,
5580 CallNonvirtualShortMethod,
5581 CallNonvirtualShortMethodV,
5582 CallNonvirtualShortMethodA,
5583 CallNonvirtualIntMethod,
5584 CallNonvirtualIntMethodV,
5585 CallNonvirtualIntMethodA,
5586 CallNonvirtualLongMethod,
5587 CallNonvirtualLongMethodV,
5588 CallNonvirtualLongMethodA,
5589 CallNonvirtualFloatMethod,
5590 CallNonvirtualFloatMethodV,
5591 CallNonvirtualFloatMethodA,
5592 CallNonvirtualDoubleMethod,
5593 CallNonvirtualDoubleMethodV,
5594 CallNonvirtualDoubleMethodA,
5595 CallNonvirtualVoidMethod,
5596 CallNonvirtualVoidMethodV,
5597 CallNonvirtualVoidMethodA,
5622 CallStaticObjectMethod,
5623 CallStaticObjectMethodV,
5624 CallStaticObjectMethodA,
5625 CallStaticBooleanMethod,
5626 CallStaticBooleanMethodV,
5627 CallStaticBooleanMethodA,
5628 CallStaticByteMethod,
5629 CallStaticByteMethodV,
5630 CallStaticByteMethodA,
5631 CallStaticCharMethod,
5632 CallStaticCharMethodV,
5633 CallStaticCharMethodA,
5634 CallStaticShortMethod,
5635 CallStaticShortMethodV,
5636 CallStaticShortMethodA,
5637 CallStaticIntMethod,
5638 CallStaticIntMethodV,
5639 CallStaticIntMethodA,
5640 CallStaticLongMethod,
5641 CallStaticLongMethodV,
5642 CallStaticLongMethodA,
5643 CallStaticFloatMethod,
5644 CallStaticFloatMethodV,
5645 CallStaticFloatMethodA,
5646 CallStaticDoubleMethod,
5647 CallStaticDoubleMethodV,
5648 CallStaticDoubleMethodA,
5649 CallStaticVoidMethod,
5650 CallStaticVoidMethodV,
5651 CallStaticVoidMethodA,
5655 GetStaticObjectField,
5656 GetStaticBooleanField,
5659 GetStaticShortField,
5662 GetStaticFloatField,
5663 GetStaticDoubleField,
5664 SetStaticObjectField,
5665 SetStaticBooleanField,
5668 SetStaticShortField,
5671 SetStaticFloatField,
5672 SetStaticDoubleField,
5682 ReleaseStringUTFChars,
5687 GetObjectArrayElement,
5688 SetObjectArrayElement,
5699 GetBooleanArrayElements,
5700 GetByteArrayElements,
5701 GetCharArrayElements,
5702 GetShortArrayElements,
5703 GetIntArrayElements,
5704 GetLongArrayElements,
5705 GetFloatArrayElements,
5706 GetDoubleArrayElements,
5708 ReleaseBooleanArrayElements,
5709 ReleaseByteArrayElements,
5710 ReleaseCharArrayElements,
5711 ReleaseShortArrayElements,
5712 ReleaseIntArrayElements,
5713 ReleaseLongArrayElements,
5714 ReleaseFloatArrayElements,
5715 ReleaseDoubleArrayElements,
5717 GetBooleanArrayRegion,
5720 GetShortArrayRegion,
5723 GetFloatArrayRegion,
5724 GetDoubleArrayRegion,
5725 SetBooleanArrayRegion,
5728 SetShortArrayRegion,
5731 SetFloatArrayRegion,
5732 SetDoubleArrayRegion,
5742 /* new JNI 1.2 functions */
5747 GetPrimitiveArrayCritical,
5748 ReleasePrimitiveArrayCritical,
5751 ReleaseStringCritical,
5754 DeleteWeakGlobalRef,
5758 /* new JNI 1.4 functions */
5760 NewDirectByteBuffer,
5761 GetDirectBufferAddress,
5762 GetDirectBufferCapacity
5766 /* Invocation API Functions ***************************************************/
5768 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5770 Returns a default configuration for the Java VM.
5772 *******************************************************************************/
5774 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5776 JavaVMInitArgs *_vm_args;
5778 _vm_args = (JavaVMInitArgs *) vm_args;
5780 /* GNU classpath currently supports JNI 1.2 */
5782 switch (_vm_args->version) {
5783 case JNI_VERSION_1_1:
5784 _vm_args->version = JNI_VERSION_1_1;
5787 case JNI_VERSION_1_2:
5788 case JNI_VERSION_1_4:
5789 _vm_args->ignoreUnrecognized = JNI_FALSE;
5790 _vm_args->options = NULL;
5791 _vm_args->nOptions = 0;
5802 /* JNI_GetCreatedJavaVMs *******************************************************
5804 Returns all Java VMs that have been created. Pointers to VMs are written in
5805 the buffer vmBuf in the order they are created. At most bufLen number of
5806 entries will be written. The total number of created VMs is returned in
5809 *******************************************************************************/
5811 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5813 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5819 /* JNI_CreateJavaVM ************************************************************
5821 Loads and initializes a Java VM. The current thread becomes the main thread.
5822 Sets the env argument to the JNI interface pointer of the main thread.
5824 *******************************************************************************/
5826 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5828 JavaVMInitArgs *_vm_args;
5831 localref_table *lrt;
5833 /* get the arguments for the new JVM */
5835 _vm_args = (JavaVMInitArgs *) vm_args;
5837 /* get the VM and Env tables (must be set before vm_create) */
5839 env = NEW(_Jv_JNIEnv);
5840 env->env = &_Jv_JNINativeInterface;
5842 /* XXX Set the global variable. Maybe we should do that differently. */
5846 /* create and fill a JavaVM structure */
5848 jvm = NEW(_Jv_JavaVM);
5849 jvm->functions = &_Jv_JNIInvokeInterface;
5851 /* XXX Set the global variable. Maybe we should do that differently. */
5852 /* XXX JVMTI Agents needs a JavaVM */
5856 /* actually create the JVM */
5858 if (!vm_create(_vm_args)) {
5859 /* release allocated memory */
5861 FREE(env, _Jv_JNIEnv);
5862 FREE(jvm, _Jv_JavaVM);
5867 /* setup the local ref table (must be created after vm_create) */
5869 lrt = GCNEW(localref_table);
5871 lrt->capacity = LOCALREFTABLE_CAPACITY;
5873 lrt->localframes = 1;
5874 lrt->prev = LOCALREFTABLE;
5876 /* clear the references array (memset is faster then a for-loop) */
5878 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5880 LOCALREFTABLE = lrt;
5882 /* now return the values */
5884 *p_vm = (JavaVM *) jvm;
5885 *p_env = (void *) env;
5892 * These are local overrides for various environment variables in Emacs.
5893 * Please do not remove this and leave it at the end of the file, where
5894 * Emacs will automagically detect them.
5895 * ---------------------------------------------------------------------
5898 * indent-tabs-mode: t
5902 * vim:noexpandtab:sw=4:ts=4: