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 4921 2006-05-15 14:24:36Z twisti $
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/jvmti.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_ascii(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)
1194 java_lang_Throwable *o;
1195 java_lang_String *s;
1197 STATISTICS(jniinvokation());
1199 s = (java_lang_String *) javastring_new_from_ascii(msg);
1201 /* instantiate exception object */
1203 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1209 *exceptionptr = (java_objectheader *) o;
1215 /* ExceptionOccurred ***********************************************************
1217 Determines if an exception is being thrown. The exception stays
1218 being thrown until either the native code calls ExceptionClear(),
1219 or the Java code handles the exception.
1221 *******************************************************************************/
1223 jthrowable ExceptionOccurred(JNIEnv *env)
1225 java_objectheader *e;
1227 STATISTICS(jniinvokation());
1231 return NewLocalRef(env, (jthrowable) e);
1235 /* ExceptionDescribe ***********************************************************
1237 Prints an exception and a backtrace of the stack to a system
1238 error-reporting channel, such as stderr. This is a convenience
1239 routine provided for debugging.
1241 *******************************************************************************/
1243 void ExceptionDescribe(JNIEnv *env)
1245 java_objectheader *e;
1248 STATISTICS(jniinvokation());
1253 /* clear exception, because we are calling jit code again */
1255 *exceptionptr = NULL;
1257 /* get printStackTrace method from exception class */
1259 m = class_resolveclassmethod(e->vftbl->class,
1260 utf_printStackTrace,
1266 /* XXX what should we do? */
1269 /* print the stacktrace */
1271 (void) vm_call_method(m, e);
1276 /* ExceptionClear **************************************************************
1278 Clears any exception that is currently being thrown. If no
1279 exception is currently being thrown, this routine has no effect.
1281 *******************************************************************************/
1283 void ExceptionClear(JNIEnv *env)
1285 STATISTICS(jniinvokation());
1287 *exceptionptr = NULL;
1291 /* FatalError ******************************************************************
1293 Raises a fatal error and does not expect the VM to recover. This
1294 function does not return.
1296 *******************************************************************************/
1298 void FatalError(JNIEnv *env, const char *msg)
1300 STATISTICS(jniinvokation());
1302 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1306 /* PushLocalFrame **************************************************************
1308 Creates a new local reference frame, in which at least a given
1309 number of local references can be created.
1311 *******************************************************************************/
1313 jint PushLocalFrame(JNIEnv* env, jint capacity)
1316 localref_table *lrt;
1317 localref_table *nlrt;
1319 STATISTICS(jniinvokation());
1324 /* Allocate new local reference table on Java heap. Calculate the
1325 additional memory we have to allocate. */
1327 if (capacity > LOCALREFTABLE_CAPACITY)
1328 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1332 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1337 /* get current local reference table from thread */
1339 lrt = LOCALREFTABLE;
1341 /* Set up the new local reference table and add it to the local
1344 nlrt->capacity = capacity;
1346 nlrt->localframes = lrt->localframes + 1;
1349 /* store new local reference table in thread */
1351 LOCALREFTABLE = nlrt;
1357 /* PopLocalFrame ***************************************************************
1359 Pops off the current local reference frame, frees all the local
1360 references, and returns a local reference in the previous local
1361 reference frame for the given result object.
1363 *******************************************************************************/
1365 jobject PopLocalFrame(JNIEnv* env, jobject result)
1367 localref_table *lrt;
1368 localref_table *plrt;
1371 STATISTICS(jniinvokation());
1373 /* get current local reference table from thread */
1375 lrt = LOCALREFTABLE;
1377 localframes = lrt->localframes;
1379 /* Don't delete the top local frame, as this one is allocated in
1380 the native stub on the stack and is freed automagically on
1383 if (localframes == 1)
1384 return NewLocalRef(env, result);
1386 /* release all current local frames */
1388 for (; localframes >= 1; localframes--) {
1389 /* get previous frame */
1393 /* clear all reference entries */
1395 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1399 /* set new local references table */
1404 /* store new local reference table in thread */
1406 LOCALREFTABLE = lrt;
1408 /* add local reference and return the value */
1410 return NewLocalRef(env, result);
1414 /* DeleteLocalRef **************************************************************
1416 Deletes the local reference pointed to by localRef.
1418 *******************************************************************************/
1420 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1422 java_objectheader *o;
1423 localref_table *lrt;
1426 STATISTICS(jniinvokation());
1428 o = (java_objectheader *) localRef;
1430 /* get local reference table (thread specific) */
1432 lrt = LOCALREFTABLE;
1434 /* go through all local frames */
1436 for (; lrt != NULL; lrt = lrt->prev) {
1438 /* and try to remove the reference */
1440 for (i = 0; i < lrt->capacity; i++) {
1441 if (lrt->refs[i] == o) {
1442 lrt->refs[i] = NULL;
1450 /* this should not happen */
1452 /* if (opt_checkjni) */
1453 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1454 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1458 /* IsSameObject ****************************************************************
1460 Tests whether two references refer to the same Java object.
1462 *******************************************************************************/
1464 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1466 STATISTICS(jniinvokation());
1475 /* NewLocalRef *****************************************************************
1477 Creates a new local reference that refers to the same object as ref.
1479 *******************************************************************************/
1481 jobject NewLocalRef(JNIEnv *env, jobject ref)
1483 localref_table *lrt;
1486 STATISTICS(jniinvokation());
1491 /* get local reference table (thread specific) */
1493 lrt = LOCALREFTABLE;
1495 /* Check if we have space for the requested reference? No,
1496 allocate a new frame. This is actually not what the spec says,
1497 but for compatibility reasons... */
1499 if (lrt->used == lrt->capacity) {
1500 if (EnsureLocalCapacity(env, 16) != 0)
1503 /* get the new local reference table */
1505 lrt = LOCALREFTABLE;
1508 /* insert the reference */
1510 for (i = 0; i < lrt->capacity; i++) {
1511 if (lrt->refs[i] == NULL) {
1512 lrt->refs[i] = (java_objectheader *) ref;
1519 /* should not happen, just to be sure */
1523 /* keep compiler happy */
1529 /* EnsureLocalCapacity *********************************************************
1531 Ensures that at least a given number of local references can be
1532 created in the current thread
1534 *******************************************************************************/
1536 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1538 localref_table *lrt;
1540 log_text("JNI-Call: EnsureLocalCapacity");
1542 STATISTICS(jniinvokation());
1544 /* get local reference table (thread specific) */
1546 lrt = LOCALREFTABLE;
1548 /* check if capacity elements are available in the local references table */
1550 if ((lrt->used + capacity) > lrt->capacity)
1551 return PushLocalFrame(env, capacity);
1557 /* AllocObject *****************************************************************
1559 Allocates a new Java object without invoking any of the
1560 constructors for the object. Returns a reference to the object.
1562 *******************************************************************************/
1564 jobject AllocObject(JNIEnv *env, jclass clazz)
1567 java_objectheader *o;
1569 STATISTICS(jniinvokation());
1571 c = (classinfo *) clazz;
1573 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1575 new_exception_utfmessage(string_java_lang_InstantiationException,
1582 return NewLocalRef(env, o);
1586 /* NewObject *******************************************************************
1588 Programmers place all arguments that are to be passed to the
1589 constructor immediately following the methodID
1590 argument. NewObject() accepts these arguments and passes them to
1591 the Java method that the programmer wishes to invoke.
1593 *******************************************************************************/
1595 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1597 java_objectheader *o;
1601 STATISTICS(jniinvokation());
1603 m = (methodinfo *) methodID;
1607 o = builtin_new(clazz);
1612 /* call constructor */
1614 va_start(ap, methodID);
1615 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1618 return NewLocalRef(env, o);
1622 /* NewObjectV ******************************************************************
1624 Programmers place all arguments that are to be passed to the
1625 constructor in an args argument of type va_list that immediately
1626 follows the methodID argument. NewObjectV() accepts these
1627 arguments, and, in turn, passes them to the Java method that the
1628 programmer wishes to invoke.
1630 *******************************************************************************/
1632 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1634 java_objectheader *o;
1637 STATISTICS(jniinvokation());
1639 m = (methodinfo *) methodID;
1643 o = builtin_new(clazz);
1648 /* call constructor */
1650 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1652 return NewLocalRef(env, o);
1656 /* NewObjectA *****************************************************************
1658 Programmers place all arguments that are to be passed to the
1659 constructor in an args array of jvalues that immediately follows
1660 the methodID argument. NewObjectA() accepts the arguments in this
1661 array, and, in turn, passes them to the Java method that the
1662 programmer wishes to invoke.
1664 *******************************************************************************/
1666 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1668 java_objectheader *o;
1671 STATISTICS(jniinvokation());
1673 m = (methodinfo *) methodID;
1677 o = builtin_new(clazz);
1682 /* call constructor */
1684 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1686 return NewLocalRef(env, o);
1690 /* GetObjectClass **************************************************************
1692 Returns the class of an object.
1694 *******************************************************************************/
1696 jclass GetObjectClass(JNIEnv *env, jobject obj)
1698 java_objectheader *o;
1701 STATISTICS(jniinvokation());
1703 o = (java_objectheader *) obj;
1705 if ((o == NULL) || (o->vftbl == NULL))
1708 c = o->vftbl->class;
1710 return (jclass) NewLocalRef(env, (jobject) c);
1714 /* IsInstanceOf ****************************************************************
1716 Tests whether an object is an instance of a class.
1718 *******************************************************************************/
1720 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1722 STATISTICS(jniinvokation());
1724 return Java_java_lang_VMClass_isInstance(env,
1726 (java_lang_Class *) clazz,
1727 (java_lang_Object *) obj);
1731 /* Reflection Support *********************************************************/
1733 /* FromReflectedMethod *********************************************************
1735 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1736 object to a method ID.
1738 *******************************************************************************/
1740 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1746 STATISTICS(jniinvokation());
1751 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1752 java_lang_reflect_Method *rm;
1754 rm = (java_lang_reflect_Method *) method;
1755 c = (classinfo *) (rm->declaringClass);
1758 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1759 java_lang_reflect_Constructor *rc;
1761 rc = (java_lang_reflect_Constructor *) method;
1762 c = (classinfo *) (rc->clazz);
1768 mi = &(c->methods[slot]);
1770 return (jmethodID) mi;
1774 /* FromReflectedField **********************************************************
1776 Converts a java.lang.reflect.Field to a field ID.
1778 *******************************************************************************/
1780 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1782 java_lang_reflect_Field *rf;
1786 STATISTICS(jniinvokation());
1788 rf = (java_lang_reflect_Field *) field;
1793 c = (classinfo *) rf->declaringClass;
1795 f = &(c->fields[rf->slot]);
1797 return (jfieldID) f;
1801 /* ToReflectedMethod ***********************************************************
1803 Converts a method ID derived from cls to an instance of the
1804 java.lang.reflect.Method class or to an instance of the
1805 java.lang.reflect.Constructor class.
1807 *******************************************************************************/
1809 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1811 STATISTICS(jniinvokation());
1813 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1819 /* ToReflectedField ************************************************************
1821 Converts a field ID derived from cls to an instance of the
1822 java.lang.reflect.Field class.
1824 *******************************************************************************/
1826 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1829 STATISTICS(jniinvokation());
1831 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1837 /* Calling Instance Methods ***************************************************/
1839 /* GetMethodID *****************************************************************
1841 Returns the method ID for an instance (nonstatic) method of a class
1842 or interface. The method may be defined in one of the clazz's
1843 superclasses and inherited by clazz. The method is determined by
1844 its name and signature.
1846 GetMethodID() causes an uninitialized class to be initialized.
1848 *******************************************************************************/
1850 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1858 STATISTICS(jniinvokation());
1860 c = (classinfo *) clazz;
1865 if (!(c->state & CLASS_INITIALIZED))
1866 if (!initialize_class(c))
1869 /* try to get the method of the class or one of it's superclasses */
1871 uname = utf_new_char((char *) name);
1872 udesc = utf_new_char((char *) sig);
1874 m = class_resolvemethod(clazz, uname, udesc);
1876 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1877 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1882 return (jmethodID) m;
1886 /* JNI-functions for calling instance methods *********************************/
1888 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1890 java_objectheader *o;
1892 java_objectheader *ret;
1895 o = (java_objectheader *) obj;
1896 m = (methodinfo *) methodID;
1898 va_start(ap, methodID);
1899 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1902 return NewLocalRef(env, ret);
1906 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1908 java_objectheader *o;
1910 java_objectheader *ret;
1912 o = (java_objectheader *) obj;
1913 m = (methodinfo *) methodID;
1915 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1917 return NewLocalRef(env, ret);
1921 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1923 java_objectheader *o;
1925 java_objectheader *ret;
1927 o = (java_objectheader *) obj;
1928 m = (methodinfo *) methodID;
1930 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1932 return NewLocalRef(env, ret);
1936 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1938 java_objectheader *o;
1943 o = (java_objectheader *) obj;
1944 m = (methodinfo *) methodID;
1946 va_start(ap, methodID);
1947 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1954 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1956 java_objectheader *o;
1960 o = (java_objectheader *) obj;
1961 m = (methodinfo *) methodID;
1963 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1969 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1971 java_objectheader *o;
1975 o = (java_objectheader *) obj;
1976 m = (methodinfo *) methodID;
1978 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1984 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1986 java_objectheader *o;
1991 o = (java_objectheader *) obj;
1992 m = (methodinfo *) methodID;
1994 va_start(ap, methodID);
1995 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2002 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2004 java_objectheader *o;
2008 o = (java_objectheader *) obj;
2009 m = (methodinfo *) methodID;
2011 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2017 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2019 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2025 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2027 java_objectheader *o;
2032 o = (java_objectheader *) obj;
2033 m = (methodinfo *) methodID;
2035 va_start(ap, methodID);
2036 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2043 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2045 java_objectheader *o;
2049 o = (java_objectheader *) obj;
2050 m = (methodinfo *) methodID;
2052 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2058 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2060 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2066 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2068 java_objectheader *o;
2073 o = (java_objectheader *) obj;
2074 m = (methodinfo *) methodID;
2076 va_start(ap, methodID);
2077 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2084 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2086 java_objectheader *o;
2090 o = (java_objectheader *) obj;
2091 m = (methodinfo *) methodID;
2093 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2099 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2101 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2108 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2110 java_objectheader *o;
2115 o = (java_objectheader *) obj;
2116 m = (methodinfo *) methodID;
2118 va_start(ap, methodID);
2119 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2126 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2128 java_objectheader *o;
2132 o = (java_objectheader *) obj;
2133 m = (methodinfo *) methodID;
2135 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2141 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2143 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2150 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2152 java_objectheader *o;
2157 o = (java_objectheader *) obj;
2158 m = (methodinfo *) methodID;
2160 va_start(ap, methodID);
2161 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2168 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2170 java_objectheader *o;
2174 o = (java_objectheader *) obj;
2175 m = (methodinfo *) methodID;
2177 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2183 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2185 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2192 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2194 java_objectheader *o;
2199 o = (java_objectheader *) obj;
2200 m = (methodinfo *) methodID;
2202 va_start(ap, methodID);
2203 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2210 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2212 java_objectheader *o;
2216 o = (java_objectheader *) obj;
2217 m = (methodinfo *) methodID;
2219 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2225 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2227 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2234 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2236 java_objectheader *o;
2241 o = (java_objectheader *) obj;
2242 m = (methodinfo *) methodID;
2244 va_start(ap, methodID);
2245 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2252 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2254 java_objectheader *o;
2258 o = (java_objectheader *) obj;
2259 m = (methodinfo *) methodID;
2261 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2267 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2269 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2276 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2278 java_objectheader *o;
2282 o = (java_objectheader *) obj;
2283 m = (methodinfo *) methodID;
2285 va_start(ap, methodID);
2286 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2291 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2293 java_objectheader *o;
2296 o = (java_objectheader *) obj;
2297 m = (methodinfo *) methodID;
2299 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2303 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2305 java_objectheader *o;
2308 o = (java_objectheader *) obj;
2309 m = (methodinfo *) methodID;
2311 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2316 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2318 java_objectheader *o;
2321 java_objectheader *r;
2324 o = (java_objectheader *) obj;
2325 c = (classinfo *) clazz;
2326 m = (methodinfo *) methodID;
2328 va_start(ap, methodID);
2329 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2332 return NewLocalRef(env, r);
2336 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2338 java_objectheader *o;
2341 java_objectheader *r;
2343 o = (java_objectheader *) obj;
2344 c = (classinfo *) clazz;
2345 m = (methodinfo *) methodID;
2347 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2349 return NewLocalRef(env, r);
2353 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2355 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2357 return NewLocalRef(env, NULL);
2362 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2364 java_objectheader *o;
2370 o = (java_objectheader *) obj;
2371 c = (classinfo *) clazz;
2372 m = (methodinfo *) methodID;
2374 va_start(ap, methodID);
2375 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2382 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2384 java_objectheader *o;
2389 o = (java_objectheader *) obj;
2390 c = (classinfo *) clazz;
2391 m = (methodinfo *) methodID;
2393 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2399 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2401 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2407 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2409 java_objectheader *o;
2415 o = (java_objectheader *) obj;
2416 c = (classinfo *) clazz;
2417 m = (methodinfo *) methodID;
2419 va_start(ap, methodID);
2420 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2427 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2429 java_objectheader *o;
2434 o = (java_objectheader *) obj;
2435 c = (classinfo *) clazz;
2436 m = (methodinfo *) methodID;
2438 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2444 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2446 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2453 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2455 java_objectheader *o;
2461 o = (java_objectheader *) obj;
2462 c = (classinfo *) clazz;
2463 m = (methodinfo *) methodID;
2465 va_start(ap, methodID);
2466 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2473 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2475 java_objectheader *o;
2480 o = (java_objectheader *) obj;
2481 c = (classinfo *) clazz;
2482 m = (methodinfo *) methodID;
2484 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2490 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2492 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2499 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2501 java_objectheader *o;
2507 o = (java_objectheader *) obj;
2508 c = (classinfo *) clazz;
2509 m = (methodinfo *) methodID;
2511 va_start(ap, methodID);
2512 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2519 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2521 java_objectheader *o;
2526 o = (java_objectheader *) obj;
2527 c = (classinfo *) clazz;
2528 m = (methodinfo *) methodID;
2530 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2536 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2538 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2545 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2547 java_objectheader *o;
2553 o = (java_objectheader *) obj;
2554 c = (classinfo *) clazz;
2555 m = (methodinfo *) methodID;
2557 va_start(ap, methodID);
2558 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2565 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2567 java_objectheader *o;
2572 o = (java_objectheader *) obj;
2573 c = (classinfo *) clazz;
2574 m = (methodinfo *) methodID;
2576 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2582 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2584 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2591 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2593 java_objectheader *o;
2599 o = (java_objectheader *) obj;
2600 c = (classinfo *) clazz;
2601 m = (methodinfo *) methodID;
2603 va_start(ap, methodID);
2604 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2611 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2613 java_objectheader *o;
2618 o = (java_objectheader *) obj;
2619 c = (classinfo *) clazz;
2620 m = (methodinfo *) methodID;
2622 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2628 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2630 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2637 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2639 java_objectheader *o;
2645 o = (java_objectheader *) obj;
2646 c = (classinfo *) clazz;
2647 m = (methodinfo *) methodID;
2649 va_start(ap, methodID);
2650 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2657 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2659 java_objectheader *o;
2664 o = (java_objectheader *) obj;
2665 c = (classinfo *) clazz;
2666 m = (methodinfo *) methodID;
2668 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2674 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2676 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2683 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2685 java_objectheader *o;
2691 o = (java_objectheader *) obj;
2692 c = (classinfo *) clazz;
2693 m = (methodinfo *) methodID;
2695 va_start(ap, methodID);
2696 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2703 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2705 java_objectheader *o;
2710 o = (java_objectheader *) obj;
2711 c = (classinfo *) clazz;
2712 m = (methodinfo *) methodID;
2714 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2720 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2722 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2729 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2731 java_objectheader *o;
2736 o = (java_objectheader *) obj;
2737 c = (classinfo *) clazz;
2738 m = (methodinfo *) methodID;
2740 va_start(ap, methodID);
2741 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2746 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2748 java_objectheader *o;
2752 o = (java_objectheader *) obj;
2753 c = (classinfo *) clazz;
2754 m = (methodinfo *) methodID;
2756 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2760 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2762 java_objectheader *o;
2766 o = (java_objectheader *) obj;
2767 c = (classinfo *) clazz;
2768 m = (methodinfo *) methodID;
2770 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2774 /* Accessing Fields of Objects ************************************************/
2776 /* GetFieldID ******************************************************************
2778 Returns the field ID for an instance (nonstatic) field of a
2779 class. The field is specified by its name and signature. The
2780 Get<type>Field and Set<type>Field families of accessor functions
2781 use field IDs to retrieve object fields.
2783 *******************************************************************************/
2785 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2792 STATISTICS(jniinvokation());
2794 uname = utf_new_char((char *) name);
2795 udesc = utf_new_char((char *) sig);
2797 f = class_findfield(clazz, uname, udesc);
2800 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2802 return (jfieldID) f;
2806 /* Get<type>Field Routines *****************************************************
2808 This family of accessor routines returns the value of an instance
2809 (nonstatic) field of an object. The field to access is specified by
2810 a field ID obtained by calling GetFieldID().
2812 *******************************************************************************/
2814 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2816 java_objectheader *o;
2818 STATISTICS(jniinvokation());
2820 o = GET_FIELD(obj, java_objectheader*, fieldID);
2822 return NewLocalRef(env, o);
2826 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2830 STATISTICS(jniinvokation());
2832 i = GET_FIELD(obj, s4, fieldID);
2834 return (jboolean) i;
2838 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2842 STATISTICS(jniinvokation());
2844 i = GET_FIELD(obj, s4, fieldID);
2850 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2854 STATISTICS(jniinvokation());
2856 i = GET_FIELD(obj, s4, fieldID);
2862 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2866 STATISTICS(jniinvokation());
2868 i = GET_FIELD(obj, s4, fieldID);
2874 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2876 java_objectheader *o;
2880 STATISTICS(jniinvokation());
2882 o = (java_objectheader *) obj;
2883 f = (fieldinfo *) fieldID;
2885 i = GET_FIELD(o, s4, f);
2891 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2895 STATISTICS(jniinvokation());
2897 l = GET_FIELD(obj, s8, fieldID);
2903 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2907 STATISTICS(jniinvokation());
2909 f = GET_FIELD(obj, float, fieldID);
2915 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2919 STATISTICS(jniinvokation());
2921 d = GET_FIELD(obj, double, fieldID);
2927 /* Set<type>Field Routines *****************************************************
2929 This family of accessor routines sets the value of an instance
2930 (nonstatic) field of an object. The field to access is specified by
2931 a field ID obtained by calling GetFieldID().
2933 *******************************************************************************/
2935 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2937 STATISTICS(jniinvokation());
2939 SET_FIELD(obj, java_objectheader*, fieldID, value);
2943 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2945 STATISTICS(jniinvokation());
2947 SET_FIELD(obj, s4, fieldID, value);
2951 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2953 STATISTICS(jniinvokation());
2955 SET_FIELD(obj, s4, fieldID, value);
2959 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2961 STATISTICS(jniinvokation());
2963 SET_FIELD(obj, s4, fieldID, value);
2967 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2969 STATISTICS(jniinvokation());
2971 SET_FIELD(obj, s4, fieldID, value);
2975 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2977 STATISTICS(jniinvokation());
2979 SET_FIELD(obj, s4, fieldID, value);
2983 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2985 STATISTICS(jniinvokation());
2987 SET_FIELD(obj, s8, fieldID, value);
2991 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
2993 STATISTICS(jniinvokation());
2995 SET_FIELD(obj, float, fieldID, value);
2999 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3001 STATISTICS(jniinvokation());
3003 SET_FIELD(obj, double, fieldID, value);
3007 /* Calling Static Methods *****************************************************/
3009 /* GetStaticMethodID ***********************************************************
3011 Returns the method ID for a static method of a class. The method is
3012 specified by its name and signature.
3014 GetStaticMethodID() causes an uninitialized class to be
3017 *******************************************************************************/
3019 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3027 STATISTICS(jniinvokation());
3029 c = (classinfo *) clazz;
3034 if (!(c->state & CLASS_INITIALIZED))
3035 if (!initialize_class(c))
3038 /* try to get the static method of the class */
3040 uname = utf_new_char((char *) name);
3041 udesc = utf_new_char((char *) sig);
3043 m = class_resolvemethod(c, uname, udesc);
3045 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3046 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3051 return (jmethodID) m;
3055 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3058 java_objectheader *o;
3061 m = (methodinfo *) methodID;
3063 va_start(ap, methodID);
3064 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3067 return NewLocalRef(env, o);
3071 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3074 java_objectheader *o;
3076 m = (methodinfo *) methodID;
3078 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3080 return NewLocalRef(env, o);
3084 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3087 java_objectheader *o;
3089 m = (methodinfo *) methodID;
3091 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3093 return NewLocalRef(env, o);
3097 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3103 m = (methodinfo *) methodID;
3105 va_start(ap, methodID);
3106 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3113 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3118 m = (methodinfo *) methodID;
3120 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3126 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3128 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3134 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3140 m = (methodinfo *) methodID;
3142 va_start(ap, methodID);
3143 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3150 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3155 m = (methodinfo *) methodID;
3157 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3163 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3165 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3171 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3177 m = (methodinfo *) methodID;
3179 va_start(ap, methodID);
3180 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3187 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3192 m = (methodinfo *) methodID;
3194 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3200 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3202 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3208 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3214 m = (methodinfo *) methodID;
3216 va_start(ap, methodID);
3217 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3224 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3229 m = (methodinfo *) methodID;
3231 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3237 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3239 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3245 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3251 m = (methodinfo *) methodID;
3253 va_start(ap, methodID);
3254 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3261 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3266 m = (methodinfo *) methodID;
3268 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3274 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3276 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3282 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3288 m = (methodinfo *) methodID;
3290 va_start(ap, methodID);
3291 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3298 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3304 m = (methodinfo *) methodID;
3306 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3312 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3314 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3321 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3327 m = (methodinfo *) methodID;
3329 va_start(ap, methodID);
3330 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3337 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3342 m = (methodinfo *) methodID;
3344 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3350 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3352 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3358 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3364 m = (methodinfo *) methodID;
3366 va_start(ap, methodID);
3367 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3374 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3379 m = (methodinfo *) methodID;
3381 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3387 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3389 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3395 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3400 m = (methodinfo *) methodID;
3402 va_start(ap, methodID);
3403 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3408 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3412 m = (methodinfo *) methodID;
3414 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3418 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3422 m = (methodinfo *) methodID;
3424 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3428 /* Accessing Static Fields ****************************************************/
3430 /* GetStaticFieldID ************************************************************
3432 Returns the field ID for a static field of a class. The field is
3433 specified by its name and signature. The GetStatic<type>Field and
3434 SetStatic<type>Field families of accessor functions use field IDs
3435 to retrieve static fields.
3437 *******************************************************************************/
3439 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3443 STATISTICS(jniinvokation());
3445 f = class_findfield(clazz,
3446 utf_new_char((char *) name),
3447 utf_new_char((char *) sig));
3450 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3452 return (jfieldID) f;
3456 /* GetStatic<type>Field ********************************************************
3458 This family of accessor routines returns the value of a static
3461 *******************************************************************************/
3463 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3468 STATISTICS(jniinvokation());
3470 c = (classinfo *) clazz;
3471 f = (fieldinfo *) fieldID;
3473 if (!(c->state & CLASS_INITIALIZED))
3474 if (!initialize_class(c))
3477 return NewLocalRef(env, f->value.a);
3481 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3486 STATISTICS(jniinvokation());
3488 c = (classinfo *) clazz;
3489 f = (fieldinfo *) fieldID;
3491 if (!(c->state & CLASS_INITIALIZED))
3492 if (!initialize_class(c))
3499 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3504 STATISTICS(jniinvokation());
3506 c = (classinfo *) clazz;
3507 f = (fieldinfo *) fieldID;
3509 if (!(c->state & CLASS_INITIALIZED))
3510 if (!initialize_class(c))
3517 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3522 STATISTICS(jniinvokation());
3524 c = (classinfo *) clazz;
3525 f = (fieldinfo *) fieldID;
3527 if (!(c->state & CLASS_INITIALIZED))
3528 if (!initialize_class(c))
3535 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3540 STATISTICS(jniinvokation());
3542 c = (classinfo *) clazz;
3543 f = (fieldinfo *) fieldID;
3545 if (!(c->state & CLASS_INITIALIZED))
3546 if (!initialize_class(c))
3553 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3558 STATISTICS(jniinvokation());
3560 c = (classinfo *) clazz;
3561 f = (fieldinfo *) fieldID;
3563 if (!(c->state & CLASS_INITIALIZED))
3564 if (!initialize_class(c))
3571 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3576 STATISTICS(jniinvokation());
3578 c = (classinfo *) clazz;
3579 f = (fieldinfo *) fieldID;
3581 if (!(c->state & CLASS_INITIALIZED))
3582 if (!initialize_class(c))
3589 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3594 STATISTICS(jniinvokation());
3596 c = (classinfo *) clazz;
3597 f = (fieldinfo *) fieldID;
3599 if (!(c->state & CLASS_INITIALIZED))
3600 if (!initialize_class(c))
3607 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3612 STATISTICS(jniinvokation());
3614 c = (classinfo *) clazz;
3615 f = (fieldinfo *) fieldID;
3617 if (!(c->state & CLASS_INITIALIZED))
3618 if (!initialize_class(c))
3625 /* SetStatic<type>Field *******************************************************
3627 This family of accessor routines sets the value of a static field
3630 *******************************************************************************/
3632 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3637 STATISTICS(jniinvokation());
3639 c = (classinfo *) clazz;
3640 f = (fieldinfo *) fieldID;
3642 if (!(c->state & CLASS_INITIALIZED))
3643 if (!initialize_class(c))
3650 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3655 STATISTICS(jniinvokation());
3657 c = (classinfo *) clazz;
3658 f = (fieldinfo *) fieldID;
3660 if (!(c->state & CLASS_INITIALIZED))
3661 if (!initialize_class(c))
3668 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3673 STATISTICS(jniinvokation());
3675 c = (classinfo *) clazz;
3676 f = (fieldinfo *) fieldID;
3678 if (!(c->state & CLASS_INITIALIZED))
3679 if (!initialize_class(c))
3686 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3691 STATISTICS(jniinvokation());
3693 c = (classinfo *) clazz;
3694 f = (fieldinfo *) fieldID;
3696 if (!(c->state & CLASS_INITIALIZED))
3697 if (!initialize_class(c))
3704 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3709 STATISTICS(jniinvokation());
3711 c = (classinfo *) clazz;
3712 f = (fieldinfo *) fieldID;
3714 if (!(c->state & CLASS_INITIALIZED))
3715 if (!initialize_class(c))
3722 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3727 STATISTICS(jniinvokation());
3729 c = (classinfo *) clazz;
3730 f = (fieldinfo *) fieldID;
3732 if (!(c->state & CLASS_INITIALIZED))
3733 if (!initialize_class(c))
3740 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3745 STATISTICS(jniinvokation());
3747 c = (classinfo *) clazz;
3748 f = (fieldinfo *) fieldID;
3750 if (!(c->state & CLASS_INITIALIZED))
3751 if (!initialize_class(c))
3758 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3763 STATISTICS(jniinvokation());
3765 c = (classinfo *) clazz;
3766 f = (fieldinfo *) fieldID;
3768 if (!(c->state & CLASS_INITIALIZED))
3769 if (!initialize_class(c))
3776 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3781 STATISTICS(jniinvokation());
3783 c = (classinfo *) clazz;
3784 f = (fieldinfo *) fieldID;
3786 if (!(c->state & CLASS_INITIALIZED))
3787 if (!initialize_class(c))
3794 /* String Operations **********************************************************/
3796 /* NewString *******************************************************************
3798 Create new java.lang.String object from an array of Unicode
3801 *******************************************************************************/
3803 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3805 java_lang_String *s;
3809 STATISTICS(jniinvokation());
3811 s = (java_lang_String *) builtin_new(class_java_lang_String);
3812 a = builtin_newarray_char(len);
3814 /* javastring or characterarray could not be created */
3819 for (i = 0; i < len; i++)
3820 a->data[i] = buf[i];
3826 return (jstring) NewLocalRef(env, (jobject) s);
3830 static jchar emptyStringJ[]={0,0};
3832 /* GetStringLength *************************************************************
3834 Returns the length (the count of Unicode characters) of a Java
3837 *******************************************************************************/
3839 jsize GetStringLength(JNIEnv *env, jstring str)
3841 return ((java_lang_String *) str)->count;
3845 /******************** convertes javastring to u2-array ****************************/
3847 u2 *javastring_tou2(jstring so)
3849 java_lang_String *s;
3854 STATISTICS(jniinvokation());
3856 s = (java_lang_String *) so;
3866 /* allocate memory */
3868 stringbuffer = MNEW(u2, s->count + 1);
3872 for (i = 0; i < s->count; i++)
3873 stringbuffer[i] = a->data[s->offset + i];
3875 /* terminate string */
3877 stringbuffer[i] = '\0';
3879 return stringbuffer;
3883 /* GetStringChars **************************************************************
3885 Returns a pointer to the array of Unicode characters of the
3886 string. This pointer is valid until ReleaseStringchars() is called.
3888 *******************************************************************************/
3890 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3894 STATISTICS(jniinvokation());
3896 jc = javastring_tou2(str);
3908 return emptyStringJ;
3912 /* ReleaseStringChars **********************************************************
3914 Informs the VM that the native code no longer needs access to
3915 chars. The chars argument is a pointer obtained from string using
3918 *******************************************************************************/
3920 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3922 STATISTICS(jniinvokation());
3924 if (chars == emptyStringJ)
3927 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3931 /* NewStringUTF ****************************************************************
3933 Constructs a new java.lang.String object from an array of UTF-8 characters.
3935 *******************************************************************************/
3937 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3939 java_lang_String *s;
3941 STATISTICS(jniinvokation());
3943 s = javastring_new(utf_new_char(bytes));
3945 return (jstring) NewLocalRef(env, (jobject) s);
3949 /****************** returns the utf8 length in bytes of a string *******************/
3951 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3953 java_lang_String *s = (java_lang_String*) string;
3955 STATISTICS(jniinvokation());
3957 return (jsize) u2_utflength(s->value->data, s->count);
3961 /* GetStringUTFChars ***********************************************************
3963 Returns a pointer to an array of UTF-8 characters of the
3964 string. This array is valid until it is released by
3965 ReleaseStringUTFChars().
3967 *******************************************************************************/
3969 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3973 STATISTICS(jniinvokation());
3981 u = javastring_toutf((java_lang_String *) string, false);
3990 /* ReleaseStringUTFChars *******************************************************
3992 Informs the VM that the native code no longer needs access to
3993 utf. The utf argument is a pointer derived from string using
3994 GetStringUTFChars().
3996 *******************************************************************************/
3998 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4000 STATISTICS(jniinvokation());
4002 /* XXX we don't release utf chars right now, perhaps that should be done
4003 later. Since there is always one reference the garbage collector will
4008 /* Array Operations ***********************************************************/
4010 /* GetArrayLength **************************************************************
4012 Returns the number of elements in the array.
4014 *******************************************************************************/
4016 jsize GetArrayLength(JNIEnv *env, jarray array)
4018 java_arrayheader *a;
4020 STATISTICS(jniinvokation());
4022 a = (java_arrayheader *) array;
4028 /* NewObjectArray **************************************************************
4030 Constructs a new array holding objects in class elementClass. All
4031 elements are initially set to initialElement.
4033 *******************************************************************************/
4035 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4037 java_objectarray *oa;
4040 STATISTICS(jniinvokation());
4043 exceptions_throw_negativearraysizeexception();
4047 oa = builtin_anewarray(length, elementClass);
4052 /* set all elements to initialElement */
4054 for (i = 0; i < length; i++)
4055 oa->data[i] = initialElement;
4057 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4061 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4063 java_objectarray *oa;
4066 STATISTICS(jniinvokation());
4068 oa = (java_objectarray *) array;
4070 if (index >= oa->header.size) {
4071 exceptions_throw_arrayindexoutofboundsexception();
4075 o = oa->data[index];
4077 return NewLocalRef(env, o);
4081 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4083 java_objectarray *oa;
4084 java_objectheader *o;
4086 STATISTICS(jniinvokation());
4088 oa = (java_objectarray *) array;
4089 o = (java_objectheader *) val;
4091 if (index >= oa->header.size) {
4092 exceptions_throw_arrayindexoutofboundsexception();
4096 /* check if the class of value is a subclass of the element class
4099 if (!builtin_canstore(oa, o)) {
4100 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4105 oa->data[index] = val;
4109 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4111 java_booleanarray *ba;
4113 STATISTICS(jniinvokation());
4116 exceptions_throw_negativearraysizeexception();
4120 ba = builtin_newarray_boolean(len);
4122 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4126 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4130 STATISTICS(jniinvokation());
4133 exceptions_throw_negativearraysizeexception();
4137 ba = builtin_newarray_byte(len);
4139 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4143 jcharArray NewCharArray(JNIEnv *env, jsize len)
4147 STATISTICS(jniinvokation());
4150 exceptions_throw_negativearraysizeexception();
4154 ca = builtin_newarray_char(len);
4156 return (jcharArray) NewLocalRef(env, (jobject) ca);
4160 jshortArray NewShortArray(JNIEnv *env, jsize len)
4162 java_shortarray *sa;
4164 STATISTICS(jniinvokation());
4167 exceptions_throw_negativearraysizeexception();
4171 sa = builtin_newarray_short(len);
4173 return (jshortArray) NewLocalRef(env, (jobject) sa);
4177 jintArray NewIntArray(JNIEnv *env, jsize len)
4181 STATISTICS(jniinvokation());
4184 exceptions_throw_negativearraysizeexception();
4188 ia = builtin_newarray_int(len);
4190 return (jintArray) NewLocalRef(env, (jobject) ia);
4194 jlongArray NewLongArray(JNIEnv *env, jsize len)
4198 STATISTICS(jniinvokation());
4201 exceptions_throw_negativearraysizeexception();
4205 la = builtin_newarray_long(len);
4207 return (jlongArray) NewLocalRef(env, (jobject) la);
4211 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4213 java_floatarray *fa;
4215 STATISTICS(jniinvokation());
4218 exceptions_throw_negativearraysizeexception();
4222 fa = builtin_newarray_float(len);
4224 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4228 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4230 java_doublearray *da;
4232 STATISTICS(jniinvokation());
4235 exceptions_throw_negativearraysizeexception();
4239 da = builtin_newarray_double(len);
4241 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4245 /* Get<PrimitiveType>ArrayElements *********************************************
4247 A family of functions that returns the body of the primitive array.
4249 *******************************************************************************/
4251 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4254 java_booleanarray *ba;
4256 STATISTICS(jniinvokation());
4258 ba = (java_booleanarray *) array;
4261 *isCopy = JNI_FALSE;
4267 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4271 STATISTICS(jniinvokation());
4273 ba = (java_bytearray *) array;
4276 *isCopy = JNI_FALSE;
4282 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4286 STATISTICS(jniinvokation());
4288 ca = (java_chararray *) array;
4291 *isCopy = JNI_FALSE;
4297 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4299 java_shortarray *sa;
4301 STATISTICS(jniinvokation());
4303 sa = (java_shortarray *) array;
4306 *isCopy = JNI_FALSE;
4312 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4316 STATISTICS(jniinvokation());
4318 ia = (java_intarray *) array;
4321 *isCopy = JNI_FALSE;
4327 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4331 STATISTICS(jniinvokation());
4333 la = (java_longarray *) array;
4336 *isCopy = JNI_FALSE;
4338 /* We cast this one to prevent a compiler warning on 64-bit
4339 systems since GNU Classpath typedef jlong to long long. */
4341 return (jlong *) la->data;
4345 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4347 java_floatarray *fa;
4349 STATISTICS(jniinvokation());
4351 fa = (java_floatarray *) array;
4354 *isCopy = JNI_FALSE;
4360 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4363 java_doublearray *da;
4365 STATISTICS(jniinvokation());
4367 da = (java_doublearray *) array;
4370 *isCopy = JNI_FALSE;
4376 /* Release<PrimitiveType>ArrayElements *****************************************
4378 A family of functions that informs the VM that the native code no
4379 longer needs access to elems. The elems argument is a pointer
4380 derived from array using the corresponding
4381 Get<PrimitiveType>ArrayElements() function. If necessary, this
4382 function copies back all changes made to elems to the original
4385 *******************************************************************************/
4387 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4388 jboolean *elems, jint mode)
4390 java_booleanarray *ba;
4392 STATISTICS(jniinvokation());
4394 ba = (java_booleanarray *) array;
4396 if (elems != ba->data) {
4399 MCOPY(ba->data, elems, u1, ba->header.size);
4402 MCOPY(ba->data, elems, u1, ba->header.size);
4403 /* XXX TWISTI how should it be freed? */
4406 /* XXX TWISTI how should it be freed? */
4413 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4418 STATISTICS(jniinvokation());
4420 ba = (java_bytearray *) array;
4422 if (elems != ba->data) {
4425 MCOPY(ba->data, elems, s1, ba->header.size);
4428 MCOPY(ba->data, elems, s1, ba->header.size);
4429 /* XXX TWISTI how should it be freed? */
4432 /* XXX TWISTI how should it be freed? */
4439 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4444 STATISTICS(jniinvokation());
4446 ca = (java_chararray *) array;
4448 if (elems != ca->data) {
4451 MCOPY(ca->data, elems, u2, ca->header.size);
4454 MCOPY(ca->data, elems, u2, ca->header.size);
4455 /* XXX TWISTI how should it be freed? */
4458 /* XXX TWISTI how should it be freed? */
4465 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4468 java_shortarray *sa;
4470 STATISTICS(jniinvokation());
4472 sa = (java_shortarray *) array;
4474 if (elems != sa->data) {
4477 MCOPY(sa->data, elems, s2, sa->header.size);
4480 MCOPY(sa->data, elems, s2, sa->header.size);
4481 /* XXX TWISTI how should it be freed? */
4484 /* XXX TWISTI how should it be freed? */
4491 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4496 STATISTICS(jniinvokation());
4498 ia = (java_intarray *) array;
4500 if (elems != ia->data) {
4503 MCOPY(ia->data, elems, s4, ia->header.size);
4506 MCOPY(ia->data, elems, s4, ia->header.size);
4507 /* XXX TWISTI how should it be freed? */
4510 /* XXX TWISTI how should it be freed? */
4517 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4522 STATISTICS(jniinvokation());
4524 la = (java_longarray *) array;
4526 /* We cast this one to prevent a compiler warning on 64-bit
4527 systems since GNU Classpath typedef jlong to long long. */
4529 if ((s8 *) elems != la->data) {
4532 MCOPY(la->data, elems, s8, la->header.size);
4535 MCOPY(la->data, elems, s8, la->header.size);
4536 /* XXX TWISTI how should it be freed? */
4539 /* XXX TWISTI how should it be freed? */
4546 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4549 java_floatarray *fa;
4551 STATISTICS(jniinvokation());
4553 fa = (java_floatarray *) array;
4555 if (elems != fa->data) {
4558 MCOPY(fa->data, elems, float, fa->header.size);
4561 MCOPY(fa->data, elems, float, fa->header.size);
4562 /* XXX TWISTI how should it be freed? */
4565 /* XXX TWISTI how should it be freed? */
4572 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4573 jdouble *elems, jint mode)
4575 java_doublearray *da;
4577 STATISTICS(jniinvokation());
4579 da = (java_doublearray *) array;
4581 if (elems != da->data) {
4584 MCOPY(da->data, elems, double, da->header.size);
4587 MCOPY(da->data, elems, double, da->header.size);
4588 /* XXX TWISTI how should it be freed? */
4591 /* XXX TWISTI how should it be freed? */
4598 /* Get<PrimitiveType>ArrayRegion **********************************************
4600 A family of functions that copies a region of a primitive array
4603 *******************************************************************************/
4605 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4606 jsize len, jboolean *buf)
4608 java_booleanarray *ba;
4610 STATISTICS(jniinvokation());
4612 ba = (java_booleanarray *) array;
4614 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4615 exceptions_throw_arrayindexoutofboundsexception();
4617 MCOPY(buf, &ba->data[start], u1, len);
4621 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4626 STATISTICS(jniinvokation());
4628 ba = (java_bytearray *) array;
4630 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4631 exceptions_throw_arrayindexoutofboundsexception();
4633 MCOPY(buf, &ba->data[start], s1, len);
4637 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4642 STATISTICS(jniinvokation());
4644 ca = (java_chararray *) array;
4646 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4647 exceptions_throw_arrayindexoutofboundsexception();
4649 MCOPY(buf, &ca->data[start], u2, len);
4653 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4654 jsize len, jshort *buf)
4656 java_shortarray *sa;
4658 STATISTICS(jniinvokation());
4660 sa = (java_shortarray *) array;
4662 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4663 exceptions_throw_arrayindexoutofboundsexception();
4665 MCOPY(buf, &sa->data[start], s2, len);
4669 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4674 STATISTICS(jniinvokation());
4676 ia = (java_intarray *) array;
4678 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4679 exceptions_throw_arrayindexoutofboundsexception();
4681 MCOPY(buf, &ia->data[start], s4, len);
4685 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4690 STATISTICS(jniinvokation());
4692 la = (java_longarray *) array;
4694 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4695 exceptions_throw_arrayindexoutofboundsexception();
4697 MCOPY(buf, &la->data[start], s8, len);
4701 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4702 jsize len, jfloat *buf)
4704 java_floatarray *fa;
4706 STATISTICS(jniinvokation());
4708 fa = (java_floatarray *) array;
4710 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4711 exceptions_throw_arrayindexoutofboundsexception();
4713 MCOPY(buf, &fa->data[start], float, len);
4717 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4718 jsize len, jdouble *buf)
4720 java_doublearray *da;
4722 STATISTICS(jniinvokation());
4724 da = (java_doublearray *) array;
4726 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4727 exceptions_throw_arrayindexoutofboundsexception();
4729 MCOPY(buf, &da->data[start], double, len);
4733 /* Set<PrimitiveType>ArrayRegion **********************************************
4735 A family of functions that copies back a region of a primitive
4736 array from a buffer.
4738 *******************************************************************************/
4740 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4741 jsize len, jboolean *buf)
4743 java_booleanarray *ba;
4745 STATISTICS(jniinvokation());
4747 ba = (java_booleanarray *) array;
4749 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4750 exceptions_throw_arrayindexoutofboundsexception();
4752 MCOPY(&ba->data[start], buf, u1, len);
4756 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4761 STATISTICS(jniinvokation());
4763 ba = (java_bytearray *) array;
4765 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4766 exceptions_throw_arrayindexoutofboundsexception();
4768 MCOPY(&ba->data[start], buf, s1, len);
4772 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4777 STATISTICS(jniinvokation());
4779 ca = (java_chararray *) array;
4781 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4782 exceptions_throw_arrayindexoutofboundsexception();
4784 MCOPY(&ca->data[start], buf, u2, len);
4788 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4789 jsize len, jshort *buf)
4791 java_shortarray *sa;
4793 STATISTICS(jniinvokation());
4795 sa = (java_shortarray *) array;
4797 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4798 exceptions_throw_arrayindexoutofboundsexception();
4800 MCOPY(&sa->data[start], buf, s2, len);
4804 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4809 STATISTICS(jniinvokation());
4811 ia = (java_intarray *) array;
4813 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4814 exceptions_throw_arrayindexoutofboundsexception();
4816 MCOPY(&ia->data[start], buf, s4, len);
4820 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4825 STATISTICS(jniinvokation());
4827 la = (java_longarray *) array;
4829 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4830 exceptions_throw_arrayindexoutofboundsexception();
4832 MCOPY(&la->data[start], buf, s8, len);
4836 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4837 jsize len, jfloat *buf)
4839 java_floatarray *fa;
4841 STATISTICS(jniinvokation());
4843 fa = (java_floatarray *) array;
4845 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4846 exceptions_throw_arrayindexoutofboundsexception();
4848 MCOPY(&fa->data[start], buf, float, len);
4852 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4853 jsize len, jdouble *buf)
4855 java_doublearray *da;
4857 STATISTICS(jniinvokation());
4859 da = (java_doublearray *) array;
4861 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4862 exceptions_throw_arrayindexoutofboundsexception();
4864 MCOPY(&da->data[start], buf, double, len);
4868 /* Registering Native Methods *************************************************/
4870 /* RegisterNatives *************************************************************
4872 Registers native methods with the class specified by the clazz
4873 argument. The methods parameter specifies an array of
4874 JNINativeMethod structures that contain the names, signatures, and
4875 function pointers of the native methods. The nMethods parameter
4876 specifies the number of native methods in the array.
4878 *******************************************************************************/
4880 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4883 STATISTICS(jniinvokation());
4885 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4891 /* UnregisterNatives ***********************************************************
4893 Unregisters native methods of a class. The class goes back to the
4894 state before it was linked or registered with its native method
4897 This function should not be used in normal native code. Instead, it
4898 provides special programs a way to reload and relink native
4901 *******************************************************************************/
4903 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4905 STATISTICS(jniinvokation());
4907 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4909 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4915 /* Monitor Operations *********************************************************/
4917 /* MonitorEnter ****************************************************************
4919 Enters the monitor associated with the underlying Java object
4922 *******************************************************************************/
4924 jint MonitorEnter(JNIEnv *env, jobject obj)
4926 STATISTICS(jniinvokation());
4929 exceptions_throw_nullpointerexception();
4933 #if defined(ENABLE_THREADS)
4934 builtin_monitorenter(obj);
4941 /* MonitorExit *****************************************************************
4943 The current thread must be the owner of the monitor associated with
4944 the underlying Java object referred to by obj. The thread
4945 decrements the counter indicating the number of times it has
4946 entered this monitor. If the value of the counter becomes zero, the
4947 current thread releases the monitor.
4949 *******************************************************************************/
4951 jint MonitorExit(JNIEnv *env, jobject obj)
4953 STATISTICS(jniinvokation());
4956 exceptions_throw_nullpointerexception();
4960 #if defined(ENABLE_THREADS)
4961 builtin_monitorexit(obj);
4968 /* JavaVM Interface ***********************************************************/
4970 /* GetJavaVM *******************************************************************
4972 Returns the Java VM interface (used in the Invocation API)
4973 associated with the current thread. The result is placed at the
4974 location pointed to by the second argument, vm.
4976 *******************************************************************************/
4978 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4980 STATISTICS(jniinvokation());
4982 *vm = (JavaVM *) _Jv_jvm;
4988 /* GetStringRegion *************************************************************
4990 Copies len number of Unicode characters beginning at offset start
4991 to the given buffer buf.
4993 Throws StringIndexOutOfBoundsException on index overflow.
4995 *******************************************************************************/
4997 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
4999 java_lang_String *s;
5002 STATISTICS(jniinvokation());
5004 s = (java_lang_String *) str;
5007 if ((start < 0) || (len < 0) || (start > s->count) ||
5008 (start + len > s->count)) {
5009 exceptions_throw_stringindexoutofboundsexception();
5013 MCOPY(buf, &ca->data[start], u2, len);
5017 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5019 STATISTICS(jniinvokation());
5021 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5025 /* GetPrimitiveArrayCritical ***************************************************
5027 Obtain a direct pointer to array elements.
5029 *******************************************************************************/
5031 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5036 ba = (java_bytearray *) array;
5038 /* do the same as Kaffe does */
5040 bp = GetByteArrayElements(env, ba, isCopy);
5046 /* ReleasePrimitiveArrayCritical ***********************************************
5048 No specific documentation.
5050 *******************************************************************************/
5052 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5055 STATISTICS(jniinvokation());
5057 /* do the same as Kaffe does */
5059 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5063 /* GetStringCritical ***********************************************************
5065 The semantics of these two functions are similar to the existing
5066 Get/ReleaseStringChars functions.
5068 *******************************************************************************/
5070 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5072 STATISTICS(jniinvokation());
5074 return GetStringChars(env, string, isCopy);
5078 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5080 STATISTICS(jniinvokation());
5082 ReleaseStringChars(env, string, cstring);
5086 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5088 STATISTICS(jniinvokation());
5090 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5096 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5098 STATISTICS(jniinvokation());
5100 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5104 /* NewGlobalRef ****************************************************************
5106 Creates a new global reference to the object referred to by the obj
5109 *******************************************************************************/
5111 jobject NewGlobalRef(JNIEnv* env, jobject obj)
5113 hashtable_global_ref_entry *gre;
5114 u4 key; /* hashkey */
5115 u4 slot; /* slot in hashtable */
5117 STATISTICS(jniinvokation());
5119 #if defined(ENABLE_THREADS)
5120 builtin_monitorenter(hashtable_global_ref->header);
5123 /* normally addresses are aligned to 4, 8 or 16 bytes */
5125 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5126 slot = key & (hashtable_global_ref->size - 1);
5127 gre = hashtable_global_ref->ptr[slot];
5129 /* search external hash chain for the entry */
5132 if (gre->o == obj) {
5133 /* global object found, increment the reference */
5137 #if defined(ENABLE_THREADS)
5138 builtin_monitorexit(hashtable_global_ref->header);
5144 gre = gre->hashlink; /* next element in external chain */
5147 /* global ref not found, create a new one */
5149 gre = NEW(hashtable_global_ref_entry);
5154 /* insert entry into hashtable */
5156 gre->hashlink = hashtable_global_ref->ptr[slot];
5158 hashtable_global_ref->ptr[slot] = gre;
5160 /* update number of hashtable-entries */
5162 hashtable_global_ref->entries++;
5164 #if defined(ENABLE_THREADS)
5165 builtin_monitorexit(hashtable_global_ref->header);
5172 /* DeleteGlobalRef *************************************************************
5174 Deletes the global reference pointed to by globalRef.
5176 *******************************************************************************/
5178 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5180 hashtable_global_ref_entry *gre;
5181 hashtable_global_ref_entry *prevgre;
5182 u4 key; /* hashkey */
5183 u4 slot; /* slot in hashtable */
5185 STATISTICS(jniinvokation());
5187 #if defined(ENABLE_THREADS)
5188 builtin_monitorenter(hashtable_global_ref->header);
5191 /* normally addresses are aligned to 4, 8 or 16 bytes */
5193 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5194 slot = key & (hashtable_global_ref->size - 1);
5195 gre = hashtable_global_ref->ptr[slot];
5197 /* initialize prevgre */
5201 /* search external hash chain for the entry */
5204 if (gre->o == globalRef) {
5205 /* global object found, decrement the reference count */
5209 /* if reference count is 0, remove the entry */
5211 if (gre->refs == 0) {
5212 /* special handling if it's the first in the chain */
5214 if (prevgre == NULL)
5215 hashtable_global_ref->ptr[slot] = gre->hashlink;
5217 prevgre->hashlink = gre->hashlink;
5219 FREE(gre, hashtable_global_ref_entry);
5222 #if defined(ENABLE_THREADS)
5223 builtin_monitorexit(hashtable_global_ref->header);
5229 prevgre = gre; /* save current pointer for removal */
5230 gre = gre->hashlink; /* next element in external chain */
5233 log_println("JNI-DeleteGlobalRef: global reference not found");
5235 #if defined(ENABLE_THREADS)
5236 builtin_monitorexit(hashtable_global_ref->header);
5241 /* ExceptionCheck **************************************************************
5243 Returns JNI_TRUE when there is a pending exception; otherwise,
5246 *******************************************************************************/
5248 jboolean ExceptionCheck(JNIEnv *env)
5250 STATISTICS(jniinvokation());
5252 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5256 /* New JNI 1.4 functions ******************************************************/
5258 /* NewDirectByteBuffer *********************************************************
5260 Allocates and returns a direct java.nio.ByteBuffer referring to the
5261 block of memory starting at the memory address address and
5262 extending capacity bytes.
5264 *******************************************************************************/
5266 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5268 java_objectheader *nbuf;
5269 #if SIZEOF_VOID_P == 8
5270 gnu_classpath_Pointer64 *paddress;
5272 gnu_classpath_Pointer32 *paddress;
5275 STATISTICS(jniinvokation());
5277 /* alocate a gnu.classpath.Pointer{32,64} object */
5279 #if SIZEOF_VOID_P == 8
5280 if (!(paddress = (gnu_classpath_Pointer64 *)
5281 builtin_new(class_gnu_classpath_Pointer64)))
5283 if (!(paddress = (gnu_classpath_Pointer32 *)
5284 builtin_new(class_gnu_classpath_Pointer32)))
5288 /* fill gnu.classpath.Pointer{32,64} with address */
5290 paddress->data = (ptrint) address;
5292 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5294 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5295 (jmethodID) dbbirw_init, NULL, paddress,
5296 (jint) capacity, (jint) capacity, (jint) 0);
5298 /* add local reference and return the value */
5300 return NewLocalRef(env, nbuf);
5304 /* GetDirectBufferAddress ******************************************************
5306 Fetches and returns the starting address of the memory region
5307 referenced by the given direct java.nio.Buffer.
5309 *******************************************************************************/
5311 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5313 java_nio_DirectByteBufferImpl *nbuf;
5314 #if SIZEOF_VOID_P == 8
5315 gnu_classpath_Pointer64 *address;
5317 gnu_classpath_Pointer32 *address;
5320 STATISTICS(jniinvokation());
5322 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5325 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5327 #if SIZEOF_VOID_P == 8
5328 address = (gnu_classpath_Pointer64 *) nbuf->address;
5330 address = (gnu_classpath_Pointer32 *) nbuf->address;
5333 return (void *) address->data;
5337 /* GetDirectBufferCapacity *****************************************************
5339 Fetches and returns the capacity in bytes of the memory region
5340 referenced by the given direct java.nio.Buffer.
5342 *******************************************************************************/
5344 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5346 java_nio_Buffer *nbuf;
5348 STATISTICS(jniinvokation());
5350 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5353 nbuf = (java_nio_Buffer *) buf;
5355 return (jlong) nbuf->cap;
5359 /* DestroyJavaVM ***************************************************************
5361 Unloads a Java VM and reclaims its resources. Only the main thread
5362 can unload the VM. The system waits until the main thread is only
5363 remaining user thread before it destroys the VM.
5365 *******************************************************************************/
5367 jint DestroyJavaVM(JavaVM *vm)
5371 STATISTICS(jniinvokation());
5373 status = vm_destroy(vm);
5379 /* AttachCurrentThread *********************************************************
5381 Attaches the current thread to a Java VM. Returns a JNI interface
5382 pointer in the JNIEnv argument.
5384 Trying to attach a thread that is already attached is a no-op.
5386 A native thread cannot be attached simultaneously to two Java VMs.
5388 When a thread is attached to the VM, the context class loader is
5389 the bootstrap loader.
5391 *******************************************************************************/
5393 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5395 STATISTICS(jniinvokation());
5397 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5399 #if !defined(HAVE___THREAD)
5400 /* cacao_thread_attach();*/
5402 #error "No idea how to implement that. Perhaps Stefan knows"
5411 jint DetachCurrentThread(JavaVM *vm)
5413 STATISTICS(jniinvokation());
5415 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5421 /* GetEnv **********************************************************************
5423 If the current thread is not attached to the VM, sets *env to NULL,
5424 and returns JNI_EDETACHED. If the specified version is not
5425 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5426 sets *env to the appropriate interface, and returns JNI_OK.
5428 *******************************************************************************/
5430 jint GetEnv(JavaVM *vm, void **env, jint version)
5432 STATISTICS(jniinvokation());
5434 #if defined(ENABLE_THREADS)
5435 if (threads_get_current_threadobject() == NULL) {
5438 return JNI_EDETACHED;
5442 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5443 (version == JNI_VERSION_1_4)) {
5449 #if defined(ENABLE_JVMTI)
5450 if (version == JVMTI_VERSION_1_0) {
5451 *env = (void *) new_jvmtienv();
5460 return JNI_EVERSION;
5465 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5467 STATISTICS(jniinvokation());
5469 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5475 /* JNI invocation table *******************************************************/
5477 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5483 AttachCurrentThread,
5484 DetachCurrentThread,
5486 AttachCurrentThreadAsDaemon
5490 /* JNI function table *********************************************************/
5492 struct JNINativeInterface _Jv_JNINativeInterface = {
5501 FromReflectedMethod,
5522 EnsureLocalCapacity,
5565 CallNonvirtualObjectMethod,
5566 CallNonvirtualObjectMethodV,
5567 CallNonvirtualObjectMethodA,
5568 CallNonvirtualBooleanMethod,
5569 CallNonvirtualBooleanMethodV,
5570 CallNonvirtualBooleanMethodA,
5571 CallNonvirtualByteMethod,
5572 CallNonvirtualByteMethodV,
5573 CallNonvirtualByteMethodA,
5574 CallNonvirtualCharMethod,
5575 CallNonvirtualCharMethodV,
5576 CallNonvirtualCharMethodA,
5577 CallNonvirtualShortMethod,
5578 CallNonvirtualShortMethodV,
5579 CallNonvirtualShortMethodA,
5580 CallNonvirtualIntMethod,
5581 CallNonvirtualIntMethodV,
5582 CallNonvirtualIntMethodA,
5583 CallNonvirtualLongMethod,
5584 CallNonvirtualLongMethodV,
5585 CallNonvirtualLongMethodA,
5586 CallNonvirtualFloatMethod,
5587 CallNonvirtualFloatMethodV,
5588 CallNonvirtualFloatMethodA,
5589 CallNonvirtualDoubleMethod,
5590 CallNonvirtualDoubleMethodV,
5591 CallNonvirtualDoubleMethodA,
5592 CallNonvirtualVoidMethod,
5593 CallNonvirtualVoidMethodV,
5594 CallNonvirtualVoidMethodA,
5619 CallStaticObjectMethod,
5620 CallStaticObjectMethodV,
5621 CallStaticObjectMethodA,
5622 CallStaticBooleanMethod,
5623 CallStaticBooleanMethodV,
5624 CallStaticBooleanMethodA,
5625 CallStaticByteMethod,
5626 CallStaticByteMethodV,
5627 CallStaticByteMethodA,
5628 CallStaticCharMethod,
5629 CallStaticCharMethodV,
5630 CallStaticCharMethodA,
5631 CallStaticShortMethod,
5632 CallStaticShortMethodV,
5633 CallStaticShortMethodA,
5634 CallStaticIntMethod,
5635 CallStaticIntMethodV,
5636 CallStaticIntMethodA,
5637 CallStaticLongMethod,
5638 CallStaticLongMethodV,
5639 CallStaticLongMethodA,
5640 CallStaticFloatMethod,
5641 CallStaticFloatMethodV,
5642 CallStaticFloatMethodA,
5643 CallStaticDoubleMethod,
5644 CallStaticDoubleMethodV,
5645 CallStaticDoubleMethodA,
5646 CallStaticVoidMethod,
5647 CallStaticVoidMethodV,
5648 CallStaticVoidMethodA,
5652 GetStaticObjectField,
5653 GetStaticBooleanField,
5656 GetStaticShortField,
5659 GetStaticFloatField,
5660 GetStaticDoubleField,
5661 SetStaticObjectField,
5662 SetStaticBooleanField,
5665 SetStaticShortField,
5668 SetStaticFloatField,
5669 SetStaticDoubleField,
5679 ReleaseStringUTFChars,
5684 GetObjectArrayElement,
5685 SetObjectArrayElement,
5696 GetBooleanArrayElements,
5697 GetByteArrayElements,
5698 GetCharArrayElements,
5699 GetShortArrayElements,
5700 GetIntArrayElements,
5701 GetLongArrayElements,
5702 GetFloatArrayElements,
5703 GetDoubleArrayElements,
5705 ReleaseBooleanArrayElements,
5706 ReleaseByteArrayElements,
5707 ReleaseCharArrayElements,
5708 ReleaseShortArrayElements,
5709 ReleaseIntArrayElements,
5710 ReleaseLongArrayElements,
5711 ReleaseFloatArrayElements,
5712 ReleaseDoubleArrayElements,
5714 GetBooleanArrayRegion,
5717 GetShortArrayRegion,
5720 GetFloatArrayRegion,
5721 GetDoubleArrayRegion,
5722 SetBooleanArrayRegion,
5725 SetShortArrayRegion,
5728 SetFloatArrayRegion,
5729 SetDoubleArrayRegion,
5739 /* new JNI 1.2 functions */
5744 GetPrimitiveArrayCritical,
5745 ReleasePrimitiveArrayCritical,
5748 ReleaseStringCritical,
5751 DeleteWeakGlobalRef,
5755 /* new JNI 1.4 functions */
5757 NewDirectByteBuffer,
5758 GetDirectBufferAddress,
5759 GetDirectBufferCapacity
5763 /* Invocation API Functions ***************************************************/
5765 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5767 Returns a default configuration for the Java VM.
5769 *******************************************************************************/
5771 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5773 JavaVMInitArgs *_vm_args;
5775 _vm_args = (JavaVMInitArgs *) vm_args;
5777 /* GNU classpath currently supports JNI 1.2 */
5779 switch (_vm_args->version) {
5780 case JNI_VERSION_1_1:
5781 _vm_args->version = JNI_VERSION_1_1;
5784 case JNI_VERSION_1_2:
5785 case JNI_VERSION_1_4:
5786 _vm_args->ignoreUnrecognized = JNI_FALSE;
5787 _vm_args->options = NULL;
5788 _vm_args->nOptions = 0;
5799 /* JNI_GetCreatedJavaVMs *******************************************************
5801 Returns all Java VMs that have been created. Pointers to VMs are written in
5802 the buffer vmBuf in the order they are created. At most bufLen number of
5803 entries will be written. The total number of created VMs is returned in
5806 *******************************************************************************/
5808 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5810 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5816 /* JNI_CreateJavaVM ************************************************************
5818 Loads and initializes a Java VM. The current thread becomes the main thread.
5819 Sets the env argument to the JNI interface pointer of the main thread.
5821 *******************************************************************************/
5823 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5825 JavaVMInitArgs *_vm_args;
5828 localref_table *lrt;
5830 /* get the arguments for the new JVM */
5832 _vm_args = (JavaVMInitArgs *) vm_args;
5834 /* get the VM and Env tables (must be set before vm_create) */
5836 env = NEW(_Jv_JNIEnv);
5837 env->env = &_Jv_JNINativeInterface;
5839 /* XXX Set the global variable. Maybe we should do that differently. */
5844 /* create and fill a JavaVM structure */
5846 jvm = NEW(_Jv_JavaVM);
5847 jvm->functions = &_Jv_JNIInvokeInterface;
5849 /* XXX Set the global variable. Maybe we should do that differently. */
5850 /* XXX JVMTI Agents needs a JavaVM */
5854 /* actually create the JVM */
5856 if (!vm_create(_vm_args))
5859 /* setup the local ref table (must be created after vm_create) */
5861 lrt = GCNEW(localref_table);
5863 lrt->capacity = LOCALREFTABLE_CAPACITY;
5865 lrt->localframes = 1;
5866 lrt->prev = LOCALREFTABLE;
5868 /* clear the references array (memset is faster then a for-loop) */
5870 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5872 LOCALREFTABLE = lrt;
5874 /* now return the values */
5876 *p_vm = (JavaVM *) jvm;
5877 *p_env = (void *) env;
5884 * These are local overrides for various environment variables in Emacs.
5885 * Please do not remove this and leave it at the end of the file, where
5886 * Emacs will automagically detect them.
5887 * ---------------------------------------------------------------------
5890 * indent-tabs-mode: t
5894 * vim:noexpandtab:sw=4:ts=4: