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 4892 2006-05-06 18:29:55Z motse $
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/jvmti.h"
84 #if defined(USE_THREADS)
85 # if defined(NATIVE_THREADS)
86 # include "threads/native/threads.h"
88 # include "threads/green/threads.h"
92 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/loader.h"
98 #include "vm/options.h"
99 #include "vm/resolve.h"
100 #include "vm/statistics.h"
101 #include "vm/stringlocal.h"
102 #include "vm/jit/asmpart.h"
103 #include "vm/jit/jit.h"
104 #include "vm/statistics.h"
108 /* global variables ***********************************************************/
110 /* global reference table *****************************************************/
112 static java_objectheader **global_ref_table;
114 /* jmethodID and jclass caching variables for NewGlobalRef and DeleteGlobalRef*/
115 static classinfo *ihmclass = NULL;
116 static methodinfo *putmid = NULL;
117 static methodinfo *getmid = NULL;
118 static methodinfo *removemid = NULL;
121 /* direct buffer stuff ********************************************************/
123 static classinfo *class_java_nio_Buffer;
124 static classinfo *class_java_nio_DirectByteBufferImpl;
125 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
126 #if SIZEOF_VOID_P == 8
127 static classinfo *class_gnu_classpath_Pointer64;
129 static classinfo *class_gnu_classpath_Pointer32;
132 static methodinfo *dbbirw_init;
135 /* local reference table ******************************************************/
137 #if !defined(USE_THREADS)
138 localref_table *_no_threads_localref_table;
142 /* accessing instance fields macros *******************************************/
144 #define SET_FIELD(o,type,f,value) \
145 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
147 #define GET_FIELD(o,type,f) \
148 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
151 /* some forward declarations **************************************************/
153 jobject NewLocalRef(JNIEnv *env, jobject ref);
154 jint EnsureLocalCapacity(JNIEnv* env, jint capacity);
157 /* jni_init ********************************************************************
159 Initialize the JNI subsystem.
161 *******************************************************************************/
165 /* initalize global reference table */
168 load_class_bootstrap(utf_new_char("java/util/IdentityHashMap"))))
171 global_ref_table = GCNEW(jobject);
173 if (!(*global_ref_table = native_new_and_init(ihmclass)))
176 if (!(getmid = class_resolvemethod(ihmclass, utf_get,
177 utf_java_lang_Object__java_lang_Object)))
180 if (!(putmid = class_resolvemethod(ihmclass, utf_put,
181 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))))
185 class_resolvemethod(ihmclass, utf_remove,
186 utf_java_lang_Object__java_lang_Object)))
190 /* direct buffer stuff */
192 if (!(class_java_nio_Buffer =
193 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
194 !link_class(class_java_nio_Buffer))
197 if (!(class_java_nio_DirectByteBufferImpl =
198 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
199 !link_class(class_java_nio_DirectByteBufferImpl))
202 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
203 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
204 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
208 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
210 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
213 #if SIZEOF_VOID_P == 8
214 if (!(class_gnu_classpath_Pointer64 =
215 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
216 !link_class(class_gnu_classpath_Pointer64))
219 if (!(class_gnu_classpath_Pointer32 =
220 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
221 !link_class(class_gnu_classpath_Pointer32))
229 /* _Jv_jni_vmargs_from_objectarray *********************************************
233 *******************************************************************************/
235 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
238 java_objectarray *params)
240 java_objectheader *param;
242 typedesc *paramtypes;
248 paramcount = descr->paramcount;
249 paramtypes = descr->paramtypes;
251 /* if method is non-static fill first block and skip `this' pointer */
257 vmargs[0].type = TYPE_ADR;
258 vmargs[0].data.l = (u8) (ptrint) o;
265 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
266 switch (paramtypes->type) {
267 /* primitive types */
272 param = params->data[j];
277 /* internally used data type */
278 vmargs[i].type = paramtypes->type;
280 /* convert the value according to its declared type */
282 c = param->vftbl->class;
284 switch (paramtypes->decltype) {
285 case PRIMITIVETYPE_BOOLEAN:
286 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
287 value = (s8) ((java_lang_Boolean *) param)->value;
291 vmargs[i].data.l = value;
294 case PRIMITIVETYPE_BYTE:
295 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
296 value = (s8) ((java_lang_Byte *) param)->value;
300 vmargs[i].data.l = value;
303 case PRIMITIVETYPE_CHAR:
304 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
305 value = (s8) ((java_lang_Character *) param)->value;
309 vmargs[i].data.l = value;
312 case PRIMITIVETYPE_SHORT:
313 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
314 value = (s8) ((java_lang_Short *) param)->value;
315 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
316 value = (s8) ((java_lang_Byte *) param)->value;
320 vmargs[i].data.l = value;
323 case PRIMITIVETYPE_INT:
324 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
325 value = (s8) ((java_lang_Integer *) param)->value;
326 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
327 value = (s8) ((java_lang_Short *) param)->value;
328 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
329 value = (s8) ((java_lang_Byte *) param)->value;
333 vmargs[i].data.l = value;
336 case PRIMITIVETYPE_LONG:
337 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
338 value = (s8) ((java_lang_Long *) param)->value;
339 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
340 value = (s8) ((java_lang_Integer *) param)->value;
341 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
342 value = (s8) ((java_lang_Short *) param)->value;
343 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
344 value = (s8) ((java_lang_Byte *) param)->value;
348 vmargs[i].data.l = value;
351 case PRIMITIVETYPE_FLOAT:
352 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
353 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
358 case PRIMITIVETYPE_DOUBLE:
359 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
360 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
361 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
362 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
373 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
376 if (params->data[j] != 0) {
377 if (paramtypes->arraydim > 0) {
378 if (!builtin_arrayinstanceof(params->data[j], c))
382 if (!builtin_instanceof(params->data[j], c))
387 vmargs[i].type = TYPE_ADR;
388 vmargs[i].data.l = (u8) (ptrint) params->data[j];
397 /* *rettype = descr->returntype.decltype; */
402 exceptions_throw_illegalargumentexception();
407 /* _Jv_jni_CallObjectMethod ****************************************************
409 Internal function to call Java Object methods.
411 *******************************************************************************/
413 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
415 methodinfo *m, va_list ap)
418 java_objectheader *ro;
420 STATISTICS(jniinvokation());
423 exceptions_throw_nullpointerexception();
427 /* Class initialization is done by the JIT compiler. This is ok
428 since a static method always belongs to the declaring class. */
430 if (m->flags & ACC_STATIC) {
431 /* For static methods we reset the object. */
436 /* for convenience */
441 /* For instance methods we make a virtual function table lookup. */
443 resm = method_vftbl_lookup(vftbl, m);
446 STATISTICS(jnicallXmethodnvokation());
448 ro = vm_call_method_valist(resm, o, ap);
454 /* _Jv_jni_CallObjectMethodA ***************************************************
456 Internal function to call Java Object methods.
458 *******************************************************************************/
460 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
462 methodinfo *m, jvalue *args)
465 java_objectheader *ro;
467 STATISTICS(jniinvokation());
470 exceptions_throw_nullpointerexception();
474 /* Class initialization is done by the JIT compiler. This is ok
475 since a static method always belongs to the declaring class. */
477 if (m->flags & ACC_STATIC) {
478 /* For static methods we reset the object. */
483 /* for convenience */
488 /* For instance methods we make a virtual function table lookup. */
490 resm = method_vftbl_lookup(vftbl, m);
493 STATISTICS(jnicallXmethodnvokation());
495 ro = vm_call_method_jvalue(resm, o, args);
501 /* _Jv_jni_CallIntMethod *******************************************************
503 Internal function to call Java integer class methods (boolean,
504 byte, char, short, int).
506 *******************************************************************************/
508 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
509 methodinfo *m, va_list ap)
514 STATISTICS(jniinvokation());
517 exceptions_throw_nullpointerexception();
521 /* Class initialization is done by the JIT compiler. This is ok
522 since a static method always belongs to the declaring class. */
524 if (m->flags & ACC_STATIC) {
525 /* For static methods we reset the object. */
530 /* for convenience */
535 /* For instance methods we make a virtual function table lookup. */
537 resm = method_vftbl_lookup(vftbl, m);
540 STATISTICS(jnicallXmethodnvokation());
542 i = vm_call_method_int_valist(resm, o, ap);
548 /* _Jv_jni_CallIntMethodA ******************************************************
550 Internal function to call Java integer class methods (boolean,
551 byte, char, short, int).
553 *******************************************************************************/
555 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
556 methodinfo *m, jvalue *args)
561 STATISTICS(jniinvokation());
564 exceptions_throw_nullpointerexception();
568 /* Class initialization is done by the JIT compiler. This is ok
569 since a static method always belongs to the declaring class. */
571 if (m->flags & ACC_STATIC) {
572 /* For static methods we reset the object. */
577 /* for convenience */
582 /* For instance methods we make a virtual function table lookup. */
584 resm = method_vftbl_lookup(vftbl, m);
587 STATISTICS(jnicallXmethodnvokation());
589 i = vm_call_method_int_jvalue(resm, o, args);
595 /* _Jv_jni_CallLongMethod ******************************************************
597 Internal function to call Java long methods.
599 *******************************************************************************/
601 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
602 methodinfo *m, va_list ap)
607 STATISTICS(jniinvokation());
610 exceptions_throw_nullpointerexception();
614 /* Class initialization is done by the JIT compiler. This is ok
615 since a static method always belongs to the declaring class. */
617 if (m->flags & ACC_STATIC) {
618 /* For static methods we reset the object. */
623 /* for convenience */
628 /* For instance methods we make a virtual function table lookup. */
630 resm = method_vftbl_lookup(vftbl, m);
633 STATISTICS(jnicallXmethodnvokation());
635 l = vm_call_method_long_valist(resm, o, ap);
641 /* _Jv_jni_CallFloatMethod *****************************************************
643 Internal function to call Java float methods.
645 *******************************************************************************/
647 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
648 methodinfo *m, va_list ap)
653 /* Class initialization is done by the JIT compiler. This is ok
654 since a static method always belongs to the declaring class. */
656 if (m->flags & ACC_STATIC) {
657 /* For static methods we reset the object. */
662 /* for convenience */
667 /* For instance methods we make a virtual function table lookup. */
669 resm = method_vftbl_lookup(vftbl, m);
672 STATISTICS(jnicallXmethodnvokation());
674 f = vm_call_method_float_valist(resm, o, ap);
680 /* _Jv_jni_CallDoubleMethod ****************************************************
682 Internal function to call Java double methods.
684 *******************************************************************************/
686 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
687 methodinfo *m, va_list ap)
692 /* Class initialization is done by the JIT compiler. This is ok
693 since a static method always belongs to the declaring class. */
695 if (m->flags & ACC_STATIC) {
696 /* For static methods we reset the object. */
701 /* for convenience */
706 /* For instance methods we make a virtual function table lookup. */
708 resm = method_vftbl_lookup(vftbl, m);
711 d = vm_call_method_double_valist(resm, o, ap);
717 /* _Jv_jni_CallVoidMethod ******************************************************
719 Internal function to call Java void methods.
721 *******************************************************************************/
723 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
724 methodinfo *m, va_list ap)
729 exceptions_throw_nullpointerexception();
733 /* Class initialization is done by the JIT compiler. This is ok
734 since a static method always belongs to the declaring class. */
736 if (m->flags & ACC_STATIC) {
737 /* For static methods we reset the object. */
742 /* for convenience */
747 /* For instance methods we make a virtual function table lookup. */
749 resm = method_vftbl_lookup(vftbl, m);
752 STATISTICS(jnicallXmethodnvokation());
754 (void) vm_call_method_valist(resm, o, ap);
758 /* _Jv_jni_CallVoidMethodA *****************************************************
760 Internal function to call Java void methods.
762 *******************************************************************************/
764 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
765 methodinfo *m, jvalue *args)
770 exceptions_throw_nullpointerexception();
774 /* Class initialization is done by the JIT compiler. This is ok
775 since a static method always belongs to the declaring class. */
777 if (m->flags & ACC_STATIC) {
778 /* For static methods we reset the object. */
783 /* for convenience */
788 /* For instance methods we make a virtual function table lookup. */
790 resm = method_vftbl_lookup(vftbl, m);
793 STATISTICS(jnicallXmethodnvokation());
795 (void) vm_call_method_jvalue(resm, o, args);
799 /* _Jv_jni_invokeNative ********************************************************
801 Invoke a method on the given object with the given arguments.
803 For instance methods OBJ must be != NULL and the method is looked up
804 in the vftbl of the object.
806 For static methods, OBJ is ignored.
808 *******************************************************************************/
810 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
811 java_objectarray *params)
815 java_objectheader *ro;
820 exceptions_throw_nullpointerexception();
824 argcount = m->parseddesc->paramcount;
825 paramcount = argcount;
827 /* if method is non-static, remove the `this' pointer */
829 if (!(m->flags & ACC_STATIC))
832 /* For instance methods the object has to be an instance of the
833 class the method belongs to. For static methods the obj
834 parameter is ignored. */
836 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
838 new_exception_message(string_java_lang_IllegalArgumentException,
839 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
843 /* check if we got the right number of arguments */
845 if (((params == NULL) && (paramcount != 0)) ||
846 (params && (params->header.size != paramcount)))
849 new_exception(string_java_lang_IllegalArgumentException);
853 /* for instance methods we need an object */
855 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
857 new_exception_message(string_java_lang_NullPointerException,
858 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
862 /* for static methods, zero object to make subsequent code simpler */
863 if (m->flags & ACC_STATIC)
867 /* for instance methods we must do a vftbl lookup */
868 resm = method_vftbl_lookup(o->vftbl, m);
871 /* for static methods, just for convenience */
875 vmargs = MNEW(vm_arg, argcount);
877 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
880 switch (resm->parseddesc->returntype.decltype) {
882 (void) vm_call_method_vmarg(resm, argcount, vmargs);
887 case PRIMITIVETYPE_BOOLEAN: {
889 java_lang_Boolean *bo;
891 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
893 ro = builtin_new(class_java_lang_Boolean);
895 /* setting the value of the object direct */
897 bo = (java_lang_Boolean *) ro;
902 case PRIMITIVETYPE_BYTE: {
906 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
908 ro = builtin_new(class_java_lang_Byte);
910 /* setting the value of the object direct */
912 bo = (java_lang_Byte *) ro;
917 case PRIMITIVETYPE_CHAR: {
919 java_lang_Character *co;
921 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
923 ro = builtin_new(class_java_lang_Character);
925 /* setting the value of the object direct */
927 co = (java_lang_Character *) ro;
932 case PRIMITIVETYPE_SHORT: {
936 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
938 ro = builtin_new(class_java_lang_Short);
940 /* setting the value of the object direct */
942 so = (java_lang_Short *) ro;
947 case PRIMITIVETYPE_INT: {
949 java_lang_Integer *io;
951 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
953 ro = builtin_new(class_java_lang_Integer);
955 /* setting the value of the object direct */
957 io = (java_lang_Integer *) ro;
962 case PRIMITIVETYPE_LONG: {
966 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
968 ro = builtin_new(class_java_lang_Long);
970 /* setting the value of the object direct */
972 lo = (java_lang_Long *) ro;
977 case PRIMITIVETYPE_FLOAT: {
981 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
983 ro = builtin_new(class_java_lang_Float);
985 /* setting the value of the object direct */
987 fo = (java_lang_Float *) ro;
992 case PRIMITIVETYPE_DOUBLE: {
994 java_lang_Double *_do;
996 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
998 ro = builtin_new(class_java_lang_Double);
1000 /* setting the value of the object direct */
1002 _do = (java_lang_Double *) ro;
1008 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1012 /* if this happens the exception has already been set by
1013 fill_callblock_from_objectarray */
1015 MFREE(vmargs, vm_arg, argcount);
1020 MFREE(vmargs, vm_arg, argcount);
1022 if (*exceptionptr) {
1023 java_objectheader *cause;
1025 cause = *exceptionptr;
1027 /* clear exception pointer, we are calling JIT code again */
1029 *exceptionptr = NULL;
1032 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1033 (java_lang_Throwable *) cause);
1040 /* GetVersion ******************************************************************
1042 Returns the major version number in the higher 16 bits and the
1043 minor version number in the lower 16 bits.
1045 *******************************************************************************/
1047 jint GetVersion(JNIEnv *env)
1049 STATISTICS(jniinvokation());
1051 /* we support JNI 1.4 */
1053 return JNI_VERSION_1_4;
1057 /* Class Operations ***********************************************************/
1059 /* DefineClass *****************************************************************
1061 Loads a class from a buffer of raw class data. The buffer
1062 containing the raw class data is not referenced by the VM after the
1063 DefineClass call returns, and it may be discarded if desired.
1065 *******************************************************************************/
1067 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1068 const jbyte *buf, jsize bufLen)
1070 java_lang_ClassLoader *cl;
1071 java_lang_String *s;
1075 STATISTICS(jniinvokation());
1077 cl = (java_lang_ClassLoader *) loader;
1078 s = javastring_new_from_ascii(name);
1079 ba = (java_bytearray *) buf;
1081 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1084 return (jclass) NewLocalRef(env, (jobject) c);
1088 /* FindClass *******************************************************************
1090 This function loads a locally-defined class. It searches the
1091 directories and zip files specified by the CLASSPATH environment
1092 variable for the class with the specified name.
1094 *******************************************************************************/
1096 jclass FindClass(JNIEnv *env, const char *name)
1102 STATISTICS(jniinvokation());
1104 u = utf_new_char_classname((char *) name);
1106 /* Check stacktrace for classloader, if one found use it,
1107 otherwise use the system classloader. */
1109 /* Quote from the JNI documentation:
1111 In the Java 2 Platform, FindClass locates the class loader
1112 associated with the current native method. If the native code
1113 belongs to a system class, no class loader will be
1114 involved. Otherwise, the proper class loader will be invoked to
1115 load and link the named class. When FindClass is called through
1116 the Invocation Interface, there is no current native method or
1117 its associated class loader. In that case, the result of
1118 ClassLoader.getBaseClassLoader is used." */
1120 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1121 /* these JITs support stacktraces, and so does the interpreter */
1123 cc = stacktrace_getCurrentClass();
1125 # if defined(ENABLE_INTRP)
1126 /* the interpreter supports stacktraces, even if the JIT does not */
1129 cc = stacktrace_getCurrentClass();
1135 /* if no Java method was found, use the system classloader */
1138 c = load_class_from_sysloader(u);
1140 c = load_class_from_classloader(u, cc->classloader);
1148 return (jclass) NewLocalRef(env, (jobject) c);
1152 /* GetSuperclass ***************************************************************
1154 If clazz represents any class other than the class Object, then
1155 this function returns the object that represents the superclass of
1156 the class specified by clazz.
1158 *******************************************************************************/
1160 jclass GetSuperclass(JNIEnv *env, jclass sub)
1164 STATISTICS(jniinvokation());
1166 c = ((classinfo *) sub)->super.cls;
1171 return (jclass) NewLocalRef(env, (jobject) c);
1175 /* IsAssignableFrom ************************************************************
1177 Determines whether an object of sub can be safely cast to sup.
1179 *******************************************************************************/
1181 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1183 STATISTICS(jniinvokation());
1185 return Java_java_lang_VMClass_isAssignableFrom(env,
1187 (java_lang_Class *) sup,
1188 (java_lang_Class *) sub);
1192 /* Throw ***********************************************************************
1194 Causes a java.lang.Throwable object to be thrown.
1196 *******************************************************************************/
1198 jint Throw(JNIEnv *env, jthrowable obj)
1200 STATISTICS(jniinvokation());
1202 *exceptionptr = (java_objectheader *) obj;
1208 /* ThrowNew ********************************************************************
1210 Constructs an exception object from the specified class with the
1211 message specified by message and causes that exception to be
1214 *******************************************************************************/
1216 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1218 java_lang_Throwable *o;
1219 java_lang_String *s;
1221 STATISTICS(jniinvokation());
1223 s = (java_lang_String *) javastring_new_from_ascii(msg);
1225 /* instantiate exception object */
1227 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1233 *exceptionptr = (java_objectheader *) o;
1239 /* ExceptionOccurred ***********************************************************
1241 Determines if an exception is being thrown. The exception stays
1242 being thrown until either the native code calls ExceptionClear(),
1243 or the Java code handles the exception.
1245 *******************************************************************************/
1247 jthrowable ExceptionOccurred(JNIEnv *env)
1249 java_objectheader *e;
1251 STATISTICS(jniinvokation());
1255 return NewLocalRef(env, (jthrowable) e);
1259 /* ExceptionDescribe ***********************************************************
1261 Prints an exception and a backtrace of the stack to a system
1262 error-reporting channel, such as stderr. This is a convenience
1263 routine provided for debugging.
1265 *******************************************************************************/
1267 void ExceptionDescribe(JNIEnv *env)
1269 java_objectheader *e;
1272 STATISTICS(jniinvokation());
1277 /* clear exception, because we are calling jit code again */
1279 *exceptionptr = NULL;
1281 /* get printStackTrace method from exception class */
1283 m = class_resolveclassmethod(e->vftbl->class,
1284 utf_printStackTrace,
1290 /* XXX what should we do? */
1293 /* print the stacktrace */
1295 (void) vm_call_method(m, e);
1300 /* ExceptionClear **************************************************************
1302 Clears any exception that is currently being thrown. If no
1303 exception is currently being thrown, this routine has no effect.
1305 *******************************************************************************/
1307 void ExceptionClear(JNIEnv *env)
1309 STATISTICS(jniinvokation());
1311 *exceptionptr = NULL;
1315 /* FatalError ******************************************************************
1317 Raises a fatal error and does not expect the VM to recover. This
1318 function does not return.
1320 *******************************************************************************/
1322 void FatalError(JNIEnv *env, const char *msg)
1324 STATISTICS(jniinvokation());
1326 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1330 /* PushLocalFrame **************************************************************
1332 Creates a new local reference frame, in which at least a given
1333 number of local references can be created.
1335 *******************************************************************************/
1337 jint PushLocalFrame(JNIEnv* env, jint capacity)
1340 localref_table *lrt;
1341 localref_table *nlrt;
1343 STATISTICS(jniinvokation());
1348 /* Allocate new local reference table on Java heap. Calculate the
1349 additional memory we have to allocate. */
1351 if (capacity > LOCALREFTABLE_CAPACITY)
1352 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1356 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1361 /* get current local reference table from thread */
1363 lrt = LOCALREFTABLE;
1365 /* Set up the new local reference table and add it to the local
1368 nlrt->capacity = capacity;
1370 nlrt->localframes = lrt->localframes + 1;
1373 /* store new local reference table in thread */
1375 LOCALREFTABLE = nlrt;
1381 /* PopLocalFrame ***************************************************************
1383 Pops off the current local reference frame, frees all the local
1384 references, and returns a local reference in the previous local
1385 reference frame for the given result object.
1387 *******************************************************************************/
1389 jobject PopLocalFrame(JNIEnv* env, jobject result)
1391 localref_table *lrt;
1392 localref_table *plrt;
1395 STATISTICS(jniinvokation());
1397 /* get current local reference table from thread */
1399 lrt = LOCALREFTABLE;
1401 localframes = lrt->localframes;
1403 /* Don't delete the top local frame, as this one is allocated in
1404 the native stub on the stack and is freed automagically on
1407 if (localframes == 1)
1408 return NewLocalRef(env, result);
1410 /* release all current local frames */
1412 for (; localframes >= 1; localframes--) {
1413 /* get previous frame */
1417 /* clear all reference entries */
1419 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1423 /* set new local references table */
1428 /* store new local reference table in thread */
1430 LOCALREFTABLE = lrt;
1432 /* add local reference and return the value */
1434 return NewLocalRef(env, result);
1438 /* DeleteLocalRef **************************************************************
1440 Deletes the local reference pointed to by localRef.
1442 *******************************************************************************/
1444 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1446 java_objectheader *o;
1447 localref_table *lrt;
1450 STATISTICS(jniinvokation());
1452 o = (java_objectheader *) localRef;
1454 /* get local reference table (thread specific) */
1456 lrt = LOCALREFTABLE;
1458 /* go through all local frames */
1460 for (; lrt != NULL; lrt = lrt->prev) {
1462 /* and try to remove the reference */
1464 for (i = 0; i < lrt->capacity; i++) {
1465 if (lrt->refs[i] == o) {
1466 lrt->refs[i] = NULL;
1474 /* this should not happen */
1476 /* if (opt_checkjni) */
1477 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1478 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1482 /* IsSameObject ****************************************************************
1484 Tests whether two references refer to the same Java object.
1486 *******************************************************************************/
1488 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1490 STATISTICS(jniinvokation());
1499 /* NewLocalRef *****************************************************************
1501 Creates a new local reference that refers to the same object as ref.
1503 *******************************************************************************/
1505 jobject NewLocalRef(JNIEnv *env, jobject ref)
1507 localref_table *lrt;
1510 STATISTICS(jniinvokation());
1515 /* get local reference table (thread specific) */
1517 lrt = LOCALREFTABLE;
1519 /* Check if we have space for the requested reference? No,
1520 allocate a new frame. This is actually not what the spec says,
1521 but for compatibility reasons... */
1523 if (lrt->used == lrt->capacity) {
1524 if (EnsureLocalCapacity(env, 16) != 0)
1527 /* get the new local reference table */
1529 lrt = LOCALREFTABLE;
1532 /* insert the reference */
1534 for (i = 0; i < lrt->capacity; i++) {
1535 if (lrt->refs[i] == NULL) {
1536 lrt->refs[i] = (java_objectheader *) ref;
1543 /* should not happen, just to be sure */
1547 /* keep compiler happy */
1553 /* EnsureLocalCapacity *********************************************************
1555 Ensures that at least a given number of local references can be
1556 created in the current thread
1558 *******************************************************************************/
1560 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1562 localref_table *lrt;
1564 log_text("JNI-Call: EnsureLocalCapacity");
1566 STATISTICS(jniinvokation());
1568 /* get local reference table (thread specific) */
1570 lrt = LOCALREFTABLE;
1572 /* check if capacity elements are available in the local references table */
1574 if ((lrt->used + capacity) > lrt->capacity)
1575 return PushLocalFrame(env, capacity);
1581 /* AllocObject *****************************************************************
1583 Allocates a new Java object without invoking any of the
1584 constructors for the object. Returns a reference to the object.
1586 *******************************************************************************/
1588 jobject AllocObject(JNIEnv *env, jclass clazz)
1591 java_objectheader *o;
1593 STATISTICS(jniinvokation());
1595 c = (classinfo *) clazz;
1597 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1599 new_exception_utfmessage(string_java_lang_InstantiationException,
1606 return NewLocalRef(env, o);
1610 /* NewObject *******************************************************************
1612 Programmers place all arguments that are to be passed to the
1613 constructor immediately following the methodID
1614 argument. NewObject() accepts these arguments and passes them to
1615 the Java method that the programmer wishes to invoke.
1617 *******************************************************************************/
1619 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1621 java_objectheader *o;
1625 STATISTICS(jniinvokation());
1627 m = (methodinfo *) methodID;
1631 o = builtin_new(clazz);
1636 /* call constructor */
1638 va_start(ap, methodID);
1639 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1642 return NewLocalRef(env, o);
1646 /* NewObjectV ******************************************************************
1648 Programmers place all arguments that are to be passed to the
1649 constructor in an args argument of type va_list that immediately
1650 follows the methodID argument. NewObjectV() accepts these
1651 arguments, and, in turn, passes them to the Java method that the
1652 programmer wishes to invoke.
1654 *******************************************************************************/
1656 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1658 java_objectheader *o;
1661 STATISTICS(jniinvokation());
1663 m = (methodinfo *) methodID;
1667 o = builtin_new(clazz);
1672 /* call constructor */
1674 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1676 return NewLocalRef(env, o);
1680 /* NewObjectA *****************************************************************
1682 Programmers place all arguments that are to be passed to the
1683 constructor in an args array of jvalues that immediately follows
1684 the methodID argument. NewObjectA() accepts the arguments in this
1685 array, and, in turn, passes them to the Java method that the
1686 programmer wishes to invoke.
1688 *******************************************************************************/
1690 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1692 java_objectheader *o;
1695 STATISTICS(jniinvokation());
1697 m = (methodinfo *) methodID;
1701 o = builtin_new(clazz);
1706 /* call constructor */
1708 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1710 return NewLocalRef(env, o);
1714 /* GetObjectClass **************************************************************
1716 Returns the class of an object.
1718 *******************************************************************************/
1720 jclass GetObjectClass(JNIEnv *env, jobject obj)
1722 java_objectheader *o;
1725 STATISTICS(jniinvokation());
1727 o = (java_objectheader *) obj;
1729 if ((o == NULL) || (o->vftbl == NULL))
1732 c = o->vftbl->class;
1734 return (jclass) NewLocalRef(env, (jobject) c);
1738 /* IsInstanceOf ****************************************************************
1740 Tests whether an object is an instance of a class.
1742 *******************************************************************************/
1744 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1746 STATISTICS(jniinvokation());
1748 return Java_java_lang_VMClass_isInstance(env,
1750 (java_lang_Class *) clazz,
1751 (java_lang_Object *) obj);
1755 /* Reflection Support *********************************************************/
1757 /* FromReflectedMethod *********************************************************
1759 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1760 object to a method ID.
1762 *******************************************************************************/
1764 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1770 STATISTICS(jniinvokation());
1775 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1776 java_lang_reflect_Method *rm;
1778 rm = (java_lang_reflect_Method *) method;
1779 c = (classinfo *) (rm->declaringClass);
1782 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1783 java_lang_reflect_Constructor *rc;
1785 rc = (java_lang_reflect_Constructor *) method;
1786 c = (classinfo *) (rc->clazz);
1792 mi = &(c->methods[slot]);
1794 return (jmethodID) mi;
1798 /* FromReflectedField **********************************************************
1800 Converts a java.lang.reflect.Field to a field ID.
1802 *******************************************************************************/
1804 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1806 java_lang_reflect_Field *rf;
1810 STATISTICS(jniinvokation());
1812 rf = (java_lang_reflect_Field *) field;
1817 c = (classinfo *) rf->declaringClass;
1819 f = &(c->fields[rf->slot]);
1821 return (jfieldID) f;
1825 /* ToReflectedMethod ***********************************************************
1827 Converts a method ID derived from cls to an instance of the
1828 java.lang.reflect.Method class or to an instance of the
1829 java.lang.reflect.Constructor class.
1831 *******************************************************************************/
1833 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1835 STATISTICS(jniinvokation());
1837 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1843 /* ToReflectedField ************************************************************
1845 Converts a field ID derived from cls to an instance of the
1846 java.lang.reflect.Field class.
1848 *******************************************************************************/
1850 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1853 STATISTICS(jniinvokation());
1855 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1861 /* Calling Instance Methods ***************************************************/
1863 /* GetMethodID *****************************************************************
1865 Returns the method ID for an instance (nonstatic) method of a class
1866 or interface. The method may be defined in one of the clazz's
1867 superclasses and inherited by clazz. The method is determined by
1868 its name and signature.
1870 GetMethodID() causes an uninitialized class to be initialized.
1872 *******************************************************************************/
1874 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1882 STATISTICS(jniinvokation());
1884 c = (classinfo *) clazz;
1889 if (!(c->state & CLASS_INITIALIZED))
1890 if (!initialize_class(c))
1893 /* try to get the method of the class or one of it's superclasses */
1895 uname = utf_new_char((char *) name);
1896 udesc = utf_new_char((char *) sig);
1898 m = class_resolvemethod(clazz, uname, udesc);
1900 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1901 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1906 return (jmethodID) m;
1910 /* JNI-functions for calling instance methods *********************************/
1912 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1914 java_objectheader *o;
1916 java_objectheader *ret;
1919 o = (java_objectheader *) obj;
1920 m = (methodinfo *) methodID;
1922 va_start(ap, methodID);
1923 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1926 return NewLocalRef(env, ret);
1930 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1932 java_objectheader *o;
1934 java_objectheader *ret;
1936 o = (java_objectheader *) obj;
1937 m = (methodinfo *) methodID;
1939 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1941 return NewLocalRef(env, ret);
1945 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1947 java_objectheader *o;
1949 java_objectheader *ret;
1951 o = (java_objectheader *) obj;
1952 m = (methodinfo *) methodID;
1954 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1956 return NewLocalRef(env, ret);
1960 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1962 java_objectheader *o;
1967 o = (java_objectheader *) obj;
1968 m = (methodinfo *) methodID;
1970 va_start(ap, methodID);
1971 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1978 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1980 java_objectheader *o;
1984 o = (java_objectheader *) obj;
1985 m = (methodinfo *) methodID;
1987 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1993 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1995 java_objectheader *o;
1999 o = (java_objectheader *) obj;
2000 m = (methodinfo *) methodID;
2002 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2008 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2010 java_objectheader *o;
2015 o = (java_objectheader *) obj;
2016 m = (methodinfo *) methodID;
2018 va_start(ap, methodID);
2019 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2026 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2028 java_objectheader *o;
2032 o = (java_objectheader *) obj;
2033 m = (methodinfo *) methodID;
2035 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2041 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2043 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2049 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2051 java_objectheader *o;
2056 o = (java_objectheader *) obj;
2057 m = (methodinfo *) methodID;
2059 va_start(ap, methodID);
2060 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2067 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2069 java_objectheader *o;
2073 o = (java_objectheader *) obj;
2074 m = (methodinfo *) methodID;
2076 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2082 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2084 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2090 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2092 java_objectheader *o;
2097 o = (java_objectheader *) obj;
2098 m = (methodinfo *) methodID;
2100 va_start(ap, methodID);
2101 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2108 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2110 java_objectheader *o;
2114 o = (java_objectheader *) obj;
2115 m = (methodinfo *) methodID;
2117 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2123 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2125 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2132 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2134 java_objectheader *o;
2139 o = (java_objectheader *) obj;
2140 m = (methodinfo *) methodID;
2142 va_start(ap, methodID);
2143 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2150 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2152 java_objectheader *o;
2156 o = (java_objectheader *) obj;
2157 m = (methodinfo *) methodID;
2159 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2165 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2167 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2174 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2176 java_objectheader *o;
2181 o = (java_objectheader *) obj;
2182 m = (methodinfo *) methodID;
2184 va_start(ap, methodID);
2185 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2192 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2194 java_objectheader *o;
2198 o = (java_objectheader *) obj;
2199 m = (methodinfo *) methodID;
2201 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2207 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2209 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2216 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2218 java_objectheader *o;
2223 o = (java_objectheader *) obj;
2224 m = (methodinfo *) methodID;
2226 va_start(ap, methodID);
2227 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2234 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2236 java_objectheader *o;
2240 o = (java_objectheader *) obj;
2241 m = (methodinfo *) methodID;
2243 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2249 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2251 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2258 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2260 java_objectheader *o;
2265 o = (java_objectheader *) obj;
2266 m = (methodinfo *) methodID;
2268 va_start(ap, methodID);
2269 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2276 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2278 java_objectheader *o;
2282 o = (java_objectheader *) obj;
2283 m = (methodinfo *) methodID;
2285 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2291 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2293 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2300 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2302 java_objectheader *o;
2306 o = (java_objectheader *) obj;
2307 m = (methodinfo *) methodID;
2309 va_start(ap, methodID);
2310 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2315 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2317 java_objectheader *o;
2320 o = (java_objectheader *) obj;
2321 m = (methodinfo *) methodID;
2323 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2327 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2329 java_objectheader *o;
2332 o = (java_objectheader *) obj;
2333 m = (methodinfo *) methodID;
2335 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2340 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2342 java_objectheader *o;
2345 java_objectheader *r;
2348 o = (java_objectheader *) obj;
2349 c = (classinfo *) clazz;
2350 m = (methodinfo *) methodID;
2352 va_start(ap, methodID);
2353 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2356 return NewLocalRef(env, r);
2360 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2362 java_objectheader *o;
2365 java_objectheader *r;
2367 o = (java_objectheader *) obj;
2368 c = (classinfo *) clazz;
2369 m = (methodinfo *) methodID;
2371 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2373 return NewLocalRef(env, r);
2377 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2379 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2381 return NewLocalRef(env, NULL);
2386 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2388 java_objectheader *o;
2394 o = (java_objectheader *) obj;
2395 c = (classinfo *) clazz;
2396 m = (methodinfo *) methodID;
2398 va_start(ap, methodID);
2399 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2406 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2408 java_objectheader *o;
2413 o = (java_objectheader *) obj;
2414 c = (classinfo *) clazz;
2415 m = (methodinfo *) methodID;
2417 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2423 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2425 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2431 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2433 java_objectheader *o;
2439 o = (java_objectheader *) obj;
2440 c = (classinfo *) clazz;
2441 m = (methodinfo *) methodID;
2443 va_start(ap, methodID);
2444 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2451 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2453 java_objectheader *o;
2458 o = (java_objectheader *) obj;
2459 c = (classinfo *) clazz;
2460 m = (methodinfo *) methodID;
2462 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2468 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2470 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2477 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2479 java_objectheader *o;
2485 o = (java_objectheader *) obj;
2486 c = (classinfo *) clazz;
2487 m = (methodinfo *) methodID;
2489 va_start(ap, methodID);
2490 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2497 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2499 java_objectheader *o;
2504 o = (java_objectheader *) obj;
2505 c = (classinfo *) clazz;
2506 m = (methodinfo *) methodID;
2508 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2514 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2516 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2523 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2525 java_objectheader *o;
2531 o = (java_objectheader *) obj;
2532 c = (classinfo *) clazz;
2533 m = (methodinfo *) methodID;
2535 va_start(ap, methodID);
2536 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2543 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2545 java_objectheader *o;
2550 o = (java_objectheader *) obj;
2551 c = (classinfo *) clazz;
2552 m = (methodinfo *) methodID;
2554 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2560 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2562 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2569 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2571 java_objectheader *o;
2577 o = (java_objectheader *) obj;
2578 c = (classinfo *) clazz;
2579 m = (methodinfo *) methodID;
2581 va_start(ap, methodID);
2582 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2589 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2591 java_objectheader *o;
2596 o = (java_objectheader *) obj;
2597 c = (classinfo *) clazz;
2598 m = (methodinfo *) methodID;
2600 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2606 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2608 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2615 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2617 java_objectheader *o;
2623 o = (java_objectheader *) obj;
2624 c = (classinfo *) clazz;
2625 m = (methodinfo *) methodID;
2627 va_start(ap, methodID);
2628 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2635 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2637 java_objectheader *o;
2642 o = (java_objectheader *) obj;
2643 c = (classinfo *) clazz;
2644 m = (methodinfo *) methodID;
2646 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2652 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2654 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2661 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2663 java_objectheader *o;
2669 o = (java_objectheader *) obj;
2670 c = (classinfo *) clazz;
2671 m = (methodinfo *) methodID;
2673 va_start(ap, methodID);
2674 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2681 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2683 java_objectheader *o;
2688 o = (java_objectheader *) obj;
2689 c = (classinfo *) clazz;
2690 m = (methodinfo *) methodID;
2692 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2698 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2700 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2707 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2709 java_objectheader *o;
2715 o = (java_objectheader *) obj;
2716 c = (classinfo *) clazz;
2717 m = (methodinfo *) methodID;
2719 va_start(ap, methodID);
2720 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2727 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2729 java_objectheader *o;
2734 o = (java_objectheader *) obj;
2735 c = (classinfo *) clazz;
2736 m = (methodinfo *) methodID;
2738 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2744 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2746 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2753 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2755 java_objectheader *o;
2760 o = (java_objectheader *) obj;
2761 c = (classinfo *) clazz;
2762 m = (methodinfo *) methodID;
2764 va_start(ap, methodID);
2765 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2770 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2772 java_objectheader *o;
2776 o = (java_objectheader *) obj;
2777 c = (classinfo *) clazz;
2778 m = (methodinfo *) methodID;
2780 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2784 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2786 java_objectheader *o;
2790 o = (java_objectheader *) obj;
2791 c = (classinfo *) clazz;
2792 m = (methodinfo *) methodID;
2794 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2798 /* Accessing Fields of Objects ************************************************/
2800 /* GetFieldID ******************************************************************
2802 Returns the field ID for an instance (nonstatic) field of a
2803 class. The field is specified by its name and signature. The
2804 Get<type>Field and Set<type>Field families of accessor functions
2805 use field IDs to retrieve object fields.
2807 *******************************************************************************/
2809 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2816 STATISTICS(jniinvokation());
2818 uname = utf_new_char((char *) name);
2819 udesc = utf_new_char((char *) sig);
2821 f = class_findfield(clazz, uname, udesc);
2824 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2826 return (jfieldID) f;
2830 /* Get<type>Field Routines *****************************************************
2832 This family of accessor routines returns the value of an instance
2833 (nonstatic) field of an object. The field to access is specified by
2834 a field ID obtained by calling GetFieldID().
2836 *******************************************************************************/
2838 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2840 java_objectheader *o;
2842 STATISTICS(jniinvokation());
2844 o = GET_FIELD(obj, java_objectheader*, fieldID);
2846 return NewLocalRef(env, o);
2850 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2854 STATISTICS(jniinvokation());
2856 i = GET_FIELD(obj, s4, fieldID);
2858 return (jboolean) i;
2862 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2866 STATISTICS(jniinvokation());
2868 i = GET_FIELD(obj, s4, fieldID);
2874 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2878 STATISTICS(jniinvokation());
2880 i = GET_FIELD(obj, s4, fieldID);
2886 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2890 STATISTICS(jniinvokation());
2892 i = GET_FIELD(obj, s4, fieldID);
2898 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2900 java_objectheader *o;
2904 STATISTICS(jniinvokation());
2906 o = (java_objectheader *) obj;
2907 f = (fieldinfo *) fieldID;
2909 i = GET_FIELD(o, s4, f);
2915 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2919 STATISTICS(jniinvokation());
2921 l = GET_FIELD(obj, s8, fieldID);
2927 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2931 STATISTICS(jniinvokation());
2933 f = GET_FIELD(obj, float, fieldID);
2939 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2943 STATISTICS(jniinvokation());
2945 d = GET_FIELD(obj, double, fieldID);
2951 /* Set<type>Field Routines *****************************************************
2953 This family of accessor routines sets the value of an instance
2954 (nonstatic) field of an object. The field to access is specified by
2955 a field ID obtained by calling GetFieldID().
2957 *******************************************************************************/
2959 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2961 STATISTICS(jniinvokation());
2963 SET_FIELD(obj, java_objectheader*, fieldID, value);
2967 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2969 STATISTICS(jniinvokation());
2971 SET_FIELD(obj, s4, fieldID, value);
2975 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2977 STATISTICS(jniinvokation());
2979 SET_FIELD(obj, s4, fieldID, value);
2983 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2985 STATISTICS(jniinvokation());
2987 SET_FIELD(obj, s4, fieldID, value);
2991 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2993 STATISTICS(jniinvokation());
2995 SET_FIELD(obj, s4, fieldID, value);
2999 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3001 STATISTICS(jniinvokation());
3003 SET_FIELD(obj, s4, fieldID, value);
3007 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
3009 STATISTICS(jniinvokation());
3011 SET_FIELD(obj, s8, fieldID, value);
3015 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
3017 STATISTICS(jniinvokation());
3019 SET_FIELD(obj, float, fieldID, value);
3023 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3025 STATISTICS(jniinvokation());
3027 SET_FIELD(obj, double, fieldID, value);
3031 /* Calling Static Methods *****************************************************/
3033 /* GetStaticMethodID ***********************************************************
3035 Returns the method ID for a static method of a class. The method is
3036 specified by its name and signature.
3038 GetStaticMethodID() causes an uninitialized class to be
3041 *******************************************************************************/
3043 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3051 STATISTICS(jniinvokation());
3053 c = (classinfo *) clazz;
3058 if (!(c->state & CLASS_INITIALIZED))
3059 if (!initialize_class(c))
3062 /* try to get the static method of the class */
3064 uname = utf_new_char((char *) name);
3065 udesc = utf_new_char((char *) sig);
3067 m = class_resolvemethod(c, uname, udesc);
3069 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3070 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3075 return (jmethodID) m;
3079 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3082 java_objectheader *o;
3085 m = (methodinfo *) methodID;
3087 va_start(ap, methodID);
3088 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3091 return NewLocalRef(env, o);
3095 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3098 java_objectheader *o;
3100 m = (methodinfo *) methodID;
3102 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3104 return NewLocalRef(env, o);
3108 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3111 java_objectheader *o;
3113 m = (methodinfo *) methodID;
3115 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3117 return NewLocalRef(env, o);
3121 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3127 m = (methodinfo *) methodID;
3129 va_start(ap, methodID);
3130 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3137 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3142 m = (methodinfo *) methodID;
3144 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3150 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3152 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3158 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3164 m = (methodinfo *) methodID;
3166 va_start(ap, methodID);
3167 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3174 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3179 m = (methodinfo *) methodID;
3181 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3187 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3189 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3195 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3201 m = (methodinfo *) methodID;
3203 va_start(ap, methodID);
3204 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3211 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3216 m = (methodinfo *) methodID;
3218 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3224 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3226 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3232 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3238 m = (methodinfo *) methodID;
3240 va_start(ap, methodID);
3241 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3248 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3253 m = (methodinfo *) methodID;
3255 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3261 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3263 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3269 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3275 m = (methodinfo *) methodID;
3277 va_start(ap, methodID);
3278 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3285 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3290 m = (methodinfo *) methodID;
3292 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3298 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3300 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3306 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3312 m = (methodinfo *) methodID;
3314 va_start(ap, methodID);
3315 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3322 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3328 m = (methodinfo *) methodID;
3330 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3336 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3338 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3345 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3351 m = (methodinfo *) methodID;
3353 va_start(ap, methodID);
3354 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3361 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3366 m = (methodinfo *) methodID;
3368 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3374 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3376 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3382 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3388 m = (methodinfo *) methodID;
3390 va_start(ap, methodID);
3391 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3398 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3403 m = (methodinfo *) methodID;
3405 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3411 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3413 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3419 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3424 m = (methodinfo *) methodID;
3426 va_start(ap, methodID);
3427 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3432 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3436 m = (methodinfo *) methodID;
3438 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3442 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3446 m = (methodinfo *) methodID;
3448 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3452 /* Accessing Static Fields ****************************************************/
3454 /* GetStaticFieldID ************************************************************
3456 Returns the field ID for a static field of a class. The field is
3457 specified by its name and signature. The GetStatic<type>Field and
3458 SetStatic<type>Field families of accessor functions use field IDs
3459 to retrieve static fields.
3461 *******************************************************************************/
3463 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3467 STATISTICS(jniinvokation());
3469 f = class_findfield(clazz,
3470 utf_new_char((char *) name),
3471 utf_new_char((char *) sig));
3474 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3476 return (jfieldID) f;
3480 /* GetStatic<type>Field ********************************************************
3482 This family of accessor routines returns the value of a static
3485 *******************************************************************************/
3487 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3492 STATISTICS(jniinvokation());
3494 c = (classinfo *) clazz;
3495 f = (fieldinfo *) fieldID;
3497 if (!(c->state & CLASS_INITIALIZED))
3498 if (!initialize_class(c))
3501 return NewLocalRef(env, f->value.a);
3505 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3510 STATISTICS(jniinvokation());
3512 c = (classinfo *) clazz;
3513 f = (fieldinfo *) fieldID;
3515 if (!(c->state & CLASS_INITIALIZED))
3516 if (!initialize_class(c))
3523 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3528 STATISTICS(jniinvokation());
3530 c = (classinfo *) clazz;
3531 f = (fieldinfo *) fieldID;
3533 if (!(c->state & CLASS_INITIALIZED))
3534 if (!initialize_class(c))
3541 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3546 STATISTICS(jniinvokation());
3548 c = (classinfo *) clazz;
3549 f = (fieldinfo *) fieldID;
3551 if (!(c->state & CLASS_INITIALIZED))
3552 if (!initialize_class(c))
3559 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3564 STATISTICS(jniinvokation());
3566 c = (classinfo *) clazz;
3567 f = (fieldinfo *) fieldID;
3569 if (!(c->state & CLASS_INITIALIZED))
3570 if (!initialize_class(c))
3577 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3582 STATISTICS(jniinvokation());
3584 c = (classinfo *) clazz;
3585 f = (fieldinfo *) fieldID;
3587 if (!(c->state & CLASS_INITIALIZED))
3588 if (!initialize_class(c))
3595 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3600 STATISTICS(jniinvokation());
3602 c = (classinfo *) clazz;
3603 f = (fieldinfo *) fieldID;
3605 if (!(c->state & CLASS_INITIALIZED))
3606 if (!initialize_class(c))
3613 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3618 STATISTICS(jniinvokation());
3620 c = (classinfo *) clazz;
3621 f = (fieldinfo *) fieldID;
3623 if (!(c->state & CLASS_INITIALIZED))
3624 if (!initialize_class(c))
3631 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3636 STATISTICS(jniinvokation());
3638 c = (classinfo *) clazz;
3639 f = (fieldinfo *) fieldID;
3641 if (!(c->state & CLASS_INITIALIZED))
3642 if (!initialize_class(c))
3649 /* SetStatic<type>Field *******************************************************
3651 This family of accessor routines sets the value of a static field
3654 *******************************************************************************/
3656 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3661 STATISTICS(jniinvokation());
3663 c = (classinfo *) clazz;
3664 f = (fieldinfo *) fieldID;
3666 if (!(c->state & CLASS_INITIALIZED))
3667 if (!initialize_class(c))
3674 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3679 STATISTICS(jniinvokation());
3681 c = (classinfo *) clazz;
3682 f = (fieldinfo *) fieldID;
3684 if (!(c->state & CLASS_INITIALIZED))
3685 if (!initialize_class(c))
3692 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3697 STATISTICS(jniinvokation());
3699 c = (classinfo *) clazz;
3700 f = (fieldinfo *) fieldID;
3702 if (!(c->state & CLASS_INITIALIZED))
3703 if (!initialize_class(c))
3710 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3715 STATISTICS(jniinvokation());
3717 c = (classinfo *) clazz;
3718 f = (fieldinfo *) fieldID;
3720 if (!(c->state & CLASS_INITIALIZED))
3721 if (!initialize_class(c))
3728 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3733 STATISTICS(jniinvokation());
3735 c = (classinfo *) clazz;
3736 f = (fieldinfo *) fieldID;
3738 if (!(c->state & CLASS_INITIALIZED))
3739 if (!initialize_class(c))
3746 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3751 STATISTICS(jniinvokation());
3753 c = (classinfo *) clazz;
3754 f = (fieldinfo *) fieldID;
3756 if (!(c->state & CLASS_INITIALIZED))
3757 if (!initialize_class(c))
3764 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3769 STATISTICS(jniinvokation());
3771 c = (classinfo *) clazz;
3772 f = (fieldinfo *) fieldID;
3774 if (!(c->state & CLASS_INITIALIZED))
3775 if (!initialize_class(c))
3782 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3787 STATISTICS(jniinvokation());
3789 c = (classinfo *) clazz;
3790 f = (fieldinfo *) fieldID;
3792 if (!(c->state & CLASS_INITIALIZED))
3793 if (!initialize_class(c))
3800 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3805 STATISTICS(jniinvokation());
3807 c = (classinfo *) clazz;
3808 f = (fieldinfo *) fieldID;
3810 if (!(c->state & CLASS_INITIALIZED))
3811 if (!initialize_class(c))
3818 /* String Operations **********************************************************/
3820 /* NewString *******************************************************************
3822 Create new java.lang.String object from an array of Unicode
3825 *******************************************************************************/
3827 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3829 java_lang_String *s;
3833 STATISTICS(jniinvokation());
3835 s = (java_lang_String *) builtin_new(class_java_lang_String);
3836 a = builtin_newarray_char(len);
3838 /* javastring or characterarray could not be created */
3843 for (i = 0; i < len; i++)
3844 a->data[i] = buf[i];
3850 return (jstring) NewLocalRef(env, (jobject) s);
3854 static jchar emptyStringJ[]={0,0};
3856 /* GetStringLength *************************************************************
3858 Returns the length (the count of Unicode characters) of a Java
3861 *******************************************************************************/
3863 jsize GetStringLength(JNIEnv *env, jstring str)
3865 return ((java_lang_String *) str)->count;
3869 /******************** convertes javastring to u2-array ****************************/
3871 u2 *javastring_tou2(jstring so)
3873 java_lang_String *s;
3878 STATISTICS(jniinvokation());
3880 s = (java_lang_String *) so;
3890 /* allocate memory */
3892 stringbuffer = MNEW(u2, s->count + 1);
3896 for (i = 0; i < s->count; i++)
3897 stringbuffer[i] = a->data[s->offset + i];
3899 /* terminate string */
3901 stringbuffer[i] = '\0';
3903 return stringbuffer;
3907 /* GetStringChars **************************************************************
3909 Returns a pointer to the array of Unicode characters of the
3910 string. This pointer is valid until ReleaseStringchars() is called.
3912 *******************************************************************************/
3914 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3918 STATISTICS(jniinvokation());
3920 jc = javastring_tou2(str);
3932 return emptyStringJ;
3936 /* ReleaseStringChars **********************************************************
3938 Informs the VM that the native code no longer needs access to
3939 chars. The chars argument is a pointer obtained from string using
3942 *******************************************************************************/
3944 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3946 STATISTICS(jniinvokation());
3948 if (chars == emptyStringJ)
3951 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3955 /* NewStringUTF ****************************************************************
3957 Constructs a new java.lang.String object from an array of UTF-8 characters.
3959 *******************************************************************************/
3961 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3963 java_lang_String *s;
3965 STATISTICS(jniinvokation());
3967 s = javastring_new(utf_new_char(bytes));
3969 return (jstring) NewLocalRef(env, (jobject) s);
3973 /****************** returns the utf8 length in bytes of a string *******************/
3975 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3977 java_lang_String *s = (java_lang_String*) string;
3979 STATISTICS(jniinvokation());
3981 return (jsize) u2_utflength(s->value->data, s->count);
3985 /* GetStringUTFChars ***********************************************************
3987 Returns a pointer to an array of UTF-8 characters of the
3988 string. This array is valid until it is released by
3989 ReleaseStringUTFChars().
3991 *******************************************************************************/
3993 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3997 STATISTICS(jniinvokation());
4005 u = javastring_toutf((java_lang_String *) string, false);
4014 /* ReleaseStringUTFChars *******************************************************
4016 Informs the VM that the native code no longer needs access to
4017 utf. The utf argument is a pointer derived from string using
4018 GetStringUTFChars().
4020 *******************************************************************************/
4022 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4024 STATISTICS(jniinvokation());
4026 /* XXX we don't release utf chars right now, perhaps that should be done
4027 later. Since there is always one reference the garbage collector will
4032 /* Array Operations ***********************************************************/
4034 /* GetArrayLength **************************************************************
4036 Returns the number of elements in the array.
4038 *******************************************************************************/
4040 jsize GetArrayLength(JNIEnv *env, jarray array)
4042 java_arrayheader *a;
4044 STATISTICS(jniinvokation());
4046 a = (java_arrayheader *) array;
4052 /* NewObjectArray **************************************************************
4054 Constructs a new array holding objects in class elementClass. All
4055 elements are initially set to initialElement.
4057 *******************************************************************************/
4059 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4061 java_objectarray *oa;
4064 STATISTICS(jniinvokation());
4067 exceptions_throw_negativearraysizeexception();
4071 oa = builtin_anewarray(length, elementClass);
4076 /* set all elements to initialElement */
4078 for (i = 0; i < length; i++)
4079 oa->data[i] = initialElement;
4081 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4085 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4087 java_objectarray *oa;
4090 STATISTICS(jniinvokation());
4092 oa = (java_objectarray *) array;
4094 if (index >= oa->header.size) {
4095 exceptions_throw_arrayindexoutofboundsexception();
4099 o = oa->data[index];
4101 return NewLocalRef(env, o);
4105 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4107 java_objectarray *oa;
4108 java_objectheader *o;
4110 STATISTICS(jniinvokation());
4112 oa = (java_objectarray *) array;
4113 o = (java_objectheader *) val;
4115 if (index >= oa->header.size) {
4116 exceptions_throw_arrayindexoutofboundsexception();
4120 /* check if the class of value is a subclass of the element class
4123 if (!builtin_canstore(oa, o)) {
4124 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4129 oa->data[index] = val;
4133 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4135 java_booleanarray *ba;
4137 STATISTICS(jniinvokation());
4140 exceptions_throw_negativearraysizeexception();
4144 ba = builtin_newarray_boolean(len);
4146 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4150 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4154 STATISTICS(jniinvokation());
4157 exceptions_throw_negativearraysizeexception();
4161 ba = builtin_newarray_byte(len);
4163 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4167 jcharArray NewCharArray(JNIEnv *env, jsize len)
4171 STATISTICS(jniinvokation());
4174 exceptions_throw_negativearraysizeexception();
4178 ca = builtin_newarray_char(len);
4180 return (jcharArray) NewLocalRef(env, (jobject) ca);
4184 jshortArray NewShortArray(JNIEnv *env, jsize len)
4186 java_shortarray *sa;
4188 STATISTICS(jniinvokation());
4191 exceptions_throw_negativearraysizeexception();
4195 sa = builtin_newarray_short(len);
4197 return (jshortArray) NewLocalRef(env, (jobject) sa);
4201 jintArray NewIntArray(JNIEnv *env, jsize len)
4205 STATISTICS(jniinvokation());
4208 exceptions_throw_negativearraysizeexception();
4212 ia = builtin_newarray_int(len);
4214 return (jintArray) NewLocalRef(env, (jobject) ia);
4218 jlongArray NewLongArray(JNIEnv *env, jsize len)
4222 STATISTICS(jniinvokation());
4225 exceptions_throw_negativearraysizeexception();
4229 la = builtin_newarray_long(len);
4231 return (jlongArray) NewLocalRef(env, (jobject) la);
4235 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4237 java_floatarray *fa;
4239 STATISTICS(jniinvokation());
4242 exceptions_throw_negativearraysizeexception();
4246 fa = builtin_newarray_float(len);
4248 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4252 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4254 java_doublearray *da;
4256 STATISTICS(jniinvokation());
4259 exceptions_throw_negativearraysizeexception();
4263 da = builtin_newarray_double(len);
4265 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4269 /* Get<PrimitiveType>ArrayElements *********************************************
4271 A family of functions that returns the body of the primitive array.
4273 *******************************************************************************/
4275 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4278 java_booleanarray *ba;
4280 STATISTICS(jniinvokation());
4282 ba = (java_booleanarray *) array;
4285 *isCopy = JNI_FALSE;
4291 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4295 STATISTICS(jniinvokation());
4297 ba = (java_bytearray *) array;
4300 *isCopy = JNI_FALSE;
4306 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4310 STATISTICS(jniinvokation());
4312 ca = (java_chararray *) array;
4315 *isCopy = JNI_FALSE;
4321 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4323 java_shortarray *sa;
4325 STATISTICS(jniinvokation());
4327 sa = (java_shortarray *) array;
4330 *isCopy = JNI_FALSE;
4336 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4340 STATISTICS(jniinvokation());
4342 ia = (java_intarray *) array;
4345 *isCopy = JNI_FALSE;
4351 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4355 STATISTICS(jniinvokation());
4357 la = (java_longarray *) array;
4360 *isCopy = JNI_FALSE;
4362 /* We cast this one to prevent a compiler warning on 64-bit
4363 systems since GNU Classpath typedef jlong to long long. */
4365 return (jlong *) la->data;
4369 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4371 java_floatarray *fa;
4373 STATISTICS(jniinvokation());
4375 fa = (java_floatarray *) array;
4378 *isCopy = JNI_FALSE;
4384 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4387 java_doublearray *da;
4389 STATISTICS(jniinvokation());
4391 da = (java_doublearray *) array;
4394 *isCopy = JNI_FALSE;
4400 /* Release<PrimitiveType>ArrayElements *****************************************
4402 A family of functions that informs the VM that the native code no
4403 longer needs access to elems. The elems argument is a pointer
4404 derived from array using the corresponding
4405 Get<PrimitiveType>ArrayElements() function. If necessary, this
4406 function copies back all changes made to elems to the original
4409 *******************************************************************************/
4411 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4412 jboolean *elems, jint mode)
4414 java_booleanarray *ba;
4416 STATISTICS(jniinvokation());
4418 ba = (java_booleanarray *) array;
4420 if (elems != ba->data) {
4423 MCOPY(ba->data, elems, u1, ba->header.size);
4426 MCOPY(ba->data, elems, u1, ba->header.size);
4427 /* XXX TWISTI how should it be freed? */
4430 /* XXX TWISTI how should it be freed? */
4437 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4442 STATISTICS(jniinvokation());
4444 ba = (java_bytearray *) array;
4446 if (elems != ba->data) {
4449 MCOPY(ba->data, elems, s1, ba->header.size);
4452 MCOPY(ba->data, elems, s1, ba->header.size);
4453 /* XXX TWISTI how should it be freed? */
4456 /* XXX TWISTI how should it be freed? */
4463 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4468 STATISTICS(jniinvokation());
4470 ca = (java_chararray *) array;
4472 if (elems != ca->data) {
4475 MCOPY(ca->data, elems, u2, ca->header.size);
4478 MCOPY(ca->data, elems, u2, ca->header.size);
4479 /* XXX TWISTI how should it be freed? */
4482 /* XXX TWISTI how should it be freed? */
4489 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4492 java_shortarray *sa;
4494 STATISTICS(jniinvokation());
4496 sa = (java_shortarray *) array;
4498 if (elems != sa->data) {
4501 MCOPY(sa->data, elems, s2, sa->header.size);
4504 MCOPY(sa->data, elems, s2, sa->header.size);
4505 /* XXX TWISTI how should it be freed? */
4508 /* XXX TWISTI how should it be freed? */
4515 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4520 STATISTICS(jniinvokation());
4522 ia = (java_intarray *) array;
4524 if (elems != ia->data) {
4527 MCOPY(ia->data, elems, s4, ia->header.size);
4530 MCOPY(ia->data, elems, s4, ia->header.size);
4531 /* XXX TWISTI how should it be freed? */
4534 /* XXX TWISTI how should it be freed? */
4541 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4546 STATISTICS(jniinvokation());
4548 la = (java_longarray *) array;
4550 /* We cast this one to prevent a compiler warning on 64-bit
4551 systems since GNU Classpath typedef jlong to long long. */
4553 if ((s8 *) elems != la->data) {
4556 MCOPY(la->data, elems, s8, la->header.size);
4559 MCOPY(la->data, elems, s8, la->header.size);
4560 /* XXX TWISTI how should it be freed? */
4563 /* XXX TWISTI how should it be freed? */
4570 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4573 java_floatarray *fa;
4575 STATISTICS(jniinvokation());
4577 fa = (java_floatarray *) array;
4579 if (elems != fa->data) {
4582 MCOPY(fa->data, elems, float, fa->header.size);
4585 MCOPY(fa->data, elems, float, fa->header.size);
4586 /* XXX TWISTI how should it be freed? */
4589 /* XXX TWISTI how should it be freed? */
4596 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4597 jdouble *elems, jint mode)
4599 java_doublearray *da;
4601 STATISTICS(jniinvokation());
4603 da = (java_doublearray *) array;
4605 if (elems != da->data) {
4608 MCOPY(da->data, elems, double, da->header.size);
4611 MCOPY(da->data, elems, double, da->header.size);
4612 /* XXX TWISTI how should it be freed? */
4615 /* XXX TWISTI how should it be freed? */
4622 /* Get<PrimitiveType>ArrayRegion **********************************************
4624 A family of functions that copies a region of a primitive array
4627 *******************************************************************************/
4629 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4630 jsize len, jboolean *buf)
4632 java_booleanarray *ba;
4634 STATISTICS(jniinvokation());
4636 ba = (java_booleanarray *) array;
4638 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4639 exceptions_throw_arrayindexoutofboundsexception();
4641 MCOPY(buf, &ba->data[start], u1, len);
4645 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4650 STATISTICS(jniinvokation());
4652 ba = (java_bytearray *) array;
4654 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4655 exceptions_throw_arrayindexoutofboundsexception();
4657 MCOPY(buf, &ba->data[start], s1, len);
4661 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4666 STATISTICS(jniinvokation());
4668 ca = (java_chararray *) array;
4670 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4671 exceptions_throw_arrayindexoutofboundsexception();
4673 MCOPY(buf, &ca->data[start], u2, len);
4677 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4678 jsize len, jshort *buf)
4680 java_shortarray *sa;
4682 STATISTICS(jniinvokation());
4684 sa = (java_shortarray *) array;
4686 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4687 exceptions_throw_arrayindexoutofboundsexception();
4689 MCOPY(buf, &sa->data[start], s2, len);
4693 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4698 STATISTICS(jniinvokation());
4700 ia = (java_intarray *) array;
4702 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4703 exceptions_throw_arrayindexoutofboundsexception();
4705 MCOPY(buf, &ia->data[start], s4, len);
4709 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4714 STATISTICS(jniinvokation());
4716 la = (java_longarray *) array;
4718 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4719 exceptions_throw_arrayindexoutofboundsexception();
4721 MCOPY(buf, &la->data[start], s8, len);
4725 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4726 jsize len, jfloat *buf)
4728 java_floatarray *fa;
4730 STATISTICS(jniinvokation());
4732 fa = (java_floatarray *) array;
4734 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4735 exceptions_throw_arrayindexoutofboundsexception();
4737 MCOPY(buf, &fa->data[start], float, len);
4741 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4742 jsize len, jdouble *buf)
4744 java_doublearray *da;
4746 STATISTICS(jniinvokation());
4748 da = (java_doublearray *) array;
4750 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4751 exceptions_throw_arrayindexoutofboundsexception();
4753 MCOPY(buf, &da->data[start], double, len);
4757 /* Set<PrimitiveType>ArrayRegion **********************************************
4759 A family of functions that copies back a region of a primitive
4760 array from a buffer.
4762 *******************************************************************************/
4764 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4765 jsize len, jboolean *buf)
4767 java_booleanarray *ba;
4769 STATISTICS(jniinvokation());
4771 ba = (java_booleanarray *) array;
4773 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4774 exceptions_throw_arrayindexoutofboundsexception();
4776 MCOPY(&ba->data[start], buf, u1, len);
4780 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4785 STATISTICS(jniinvokation());
4787 ba = (java_bytearray *) array;
4789 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4790 exceptions_throw_arrayindexoutofboundsexception();
4792 MCOPY(&ba->data[start], buf, s1, len);
4796 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4801 STATISTICS(jniinvokation());
4803 ca = (java_chararray *) array;
4805 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4806 exceptions_throw_arrayindexoutofboundsexception();
4808 MCOPY(&ca->data[start], buf, u2, len);
4812 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4813 jsize len, jshort *buf)
4815 java_shortarray *sa;
4817 STATISTICS(jniinvokation());
4819 sa = (java_shortarray *) array;
4821 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4822 exceptions_throw_arrayindexoutofboundsexception();
4824 MCOPY(&sa->data[start], buf, s2, len);
4828 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4833 STATISTICS(jniinvokation());
4835 ia = (java_intarray *) array;
4837 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4838 exceptions_throw_arrayindexoutofboundsexception();
4840 MCOPY(&ia->data[start], buf, s4, len);
4844 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4849 STATISTICS(jniinvokation());
4851 la = (java_longarray *) array;
4853 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4854 exceptions_throw_arrayindexoutofboundsexception();
4856 MCOPY(&la->data[start], buf, s8, len);
4860 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4861 jsize len, jfloat *buf)
4863 java_floatarray *fa;
4865 STATISTICS(jniinvokation());
4867 fa = (java_floatarray *) array;
4869 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4870 exceptions_throw_arrayindexoutofboundsexception();
4872 MCOPY(&fa->data[start], buf, float, len);
4876 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4877 jsize len, jdouble *buf)
4879 java_doublearray *da;
4881 STATISTICS(jniinvokation());
4883 da = (java_doublearray *) array;
4885 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4886 exceptions_throw_arrayindexoutofboundsexception();
4888 MCOPY(&da->data[start], buf, double, len);
4892 /* Registering Native Methods *************************************************/
4894 /* RegisterNatives *************************************************************
4896 Registers native methods with the class specified by the clazz
4897 argument. The methods parameter specifies an array of
4898 JNINativeMethod structures that contain the names, signatures, and
4899 function pointers of the native methods. The nMethods parameter
4900 specifies the number of native methods in the array.
4902 *******************************************************************************/
4904 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4907 STATISTICS(jniinvokation());
4909 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4915 /* UnregisterNatives ***********************************************************
4917 Unregisters native methods of a class. The class goes back to the
4918 state before it was linked or registered with its native method
4921 This function should not be used in normal native code. Instead, it
4922 provides special programs a way to reload and relink native
4925 *******************************************************************************/
4927 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4929 STATISTICS(jniinvokation());
4931 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4933 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4939 /* Monitor Operations *********************************************************/
4941 /* MonitorEnter ****************************************************************
4943 Enters the monitor associated with the underlying Java object
4946 *******************************************************************************/
4948 jint MonitorEnter(JNIEnv *env, jobject obj)
4950 STATISTICS(jniinvokation());
4953 exceptions_throw_nullpointerexception();
4957 #if defined(USE_THREADS)
4958 builtin_monitorenter(obj);
4965 /* MonitorExit *****************************************************************
4967 The current thread must be the owner of the monitor associated with
4968 the underlying Java object referred to by obj. The thread
4969 decrements the counter indicating the number of times it has
4970 entered this monitor. If the value of the counter becomes zero, the
4971 current thread releases the monitor.
4973 *******************************************************************************/
4975 jint MonitorExit(JNIEnv *env, jobject obj)
4977 STATISTICS(jniinvokation());
4980 exceptions_throw_nullpointerexception();
4984 #if defined(USE_THREADS)
4985 builtin_monitorexit(obj);
4992 /* JavaVM Interface ***********************************************************/
4994 /* GetJavaVM *******************************************************************
4996 Returns the Java VM interface (used in the Invocation API)
4997 associated with the current thread. The result is placed at the
4998 location pointed to by the second argument, vm.
5000 *******************************************************************************/
5002 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
5004 STATISTICS(jniinvokation());
5006 *vm = (JavaVM *) _Jv_jvm;
5012 /* GetStringRegion *************************************************************
5014 Copies len number of Unicode characters beginning at offset start
5015 to the given buffer buf.
5017 Throws StringIndexOutOfBoundsException on index overflow.
5019 *******************************************************************************/
5021 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
5023 java_lang_String *s;
5026 STATISTICS(jniinvokation());
5028 s = (java_lang_String *) str;
5031 if ((start < 0) || (len < 0) || (start > s->count) ||
5032 (start + len > s->count)) {
5033 exceptions_throw_stringindexoutofboundsexception();
5037 MCOPY(buf, &ca->data[start], u2, len);
5041 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5043 STATISTICS(jniinvokation());
5045 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5049 /* GetPrimitiveArrayCritical ***************************************************
5051 Obtain a direct pointer to array elements.
5053 *******************************************************************************/
5055 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5060 ba = (java_bytearray *) array;
5062 /* do the same as Kaffe does */
5064 bp = GetByteArrayElements(env, ba, isCopy);
5070 /* ReleasePrimitiveArrayCritical ***********************************************
5072 No specific documentation.
5074 *******************************************************************************/
5076 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5079 STATISTICS(jniinvokation());
5081 /* do the same as Kaffe does */
5083 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5087 /* GetStringCritical ***********************************************************
5089 The semantics of these two functions are similar to the existing
5090 Get/ReleaseStringChars functions.
5092 *******************************************************************************/
5094 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5096 STATISTICS(jniinvokation());
5098 return GetStringChars(env, string, isCopy);
5102 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5104 STATISTICS(jniinvokation());
5106 ReleaseStringChars(env, string, cstring);
5110 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5112 STATISTICS(jniinvokation());
5114 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5120 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5122 STATISTICS(jniinvokation());
5124 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5128 /* NewGlobalRef ****************************************************************
5130 Creates a new global reference to the object referred to by the obj
5133 *******************************************************************************/
5135 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
5137 java_objectheader *o;
5138 java_lang_Integer *refcount;
5139 java_objectheader *newval;
5141 STATISTICS(jniinvokation());
5143 #if defined(USE_THREADS)
5144 builtin_monitorenter(*global_ref_table);
5147 o = vm_call_method(getmid, *global_ref_table, lobj);
5149 refcount = (java_lang_Integer *) o;
5151 if (refcount == NULL) {
5152 newval = native_new_and_init_int(class_java_lang_Integer, 1);
5154 if (newval == NULL) {
5155 #if defined(USE_THREADS)
5156 builtin_monitorexit(*global_ref_table);
5161 (void) vm_call_method(putmid, *global_ref_table, lobj, newval);
5164 /* we can access the object itself, as we are in a
5165 synchronized section */
5170 #if defined(USE_THREADS)
5171 builtin_monitorexit(*global_ref_table);
5178 /* DeleteGlobalRef *************************************************************
5180 Deletes the global reference pointed to by globalRef.
5182 *******************************************************************************/
5184 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5186 java_objectheader *o;
5187 java_lang_Integer *refcount;
5190 STATISTICS(jniinvokation());
5192 #if defined(USE_THREADS)
5193 builtin_monitorenter(*global_ref_table);
5196 o = vm_call_method(getmid, *global_ref_table, globalRef);
5198 refcount = (java_lang_Integer *) o;
5200 if (refcount == NULL) {
5201 log_text("JNI-DeleteGlobalRef: unable to find global reference");
5205 /* we can access the object itself, as we are in a synchronized
5208 val = refcount->value - 1;
5211 (void) vm_call_method(removemid, *global_ref_table, refcount);
5214 /* we do not create a new object, but set the new value into
5217 refcount->value = val;
5220 #if defined(USE_THREADS)
5221 builtin_monitorexit(*global_ref_table);
5226 /* ExceptionCheck **************************************************************
5228 Returns JNI_TRUE when there is a pending exception; otherwise,
5231 *******************************************************************************/
5233 jboolean ExceptionCheck(JNIEnv *env)
5235 STATISTICS(jniinvokation());
5237 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5241 /* New JNI 1.4 functions ******************************************************/
5243 /* NewDirectByteBuffer *********************************************************
5245 Allocates and returns a direct java.nio.ByteBuffer referring to the
5246 block of memory starting at the memory address address and
5247 extending capacity bytes.
5249 *******************************************************************************/
5251 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5253 java_objectheader *nbuf;
5254 #if SIZEOF_VOID_P == 8
5255 gnu_classpath_Pointer64 *paddress;
5257 gnu_classpath_Pointer32 *paddress;
5260 STATISTICS(jniinvokation());
5262 /* alocate a gnu.classpath.Pointer{32,64} object */
5264 #if SIZEOF_VOID_P == 8
5265 if (!(paddress = (gnu_classpath_Pointer64 *)
5266 builtin_new(class_gnu_classpath_Pointer64)))
5268 if (!(paddress = (gnu_classpath_Pointer32 *)
5269 builtin_new(class_gnu_classpath_Pointer32)))
5273 /* fill gnu.classpath.Pointer{32,64} with address */
5275 paddress->data = (ptrint) address;
5277 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5279 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5280 (jmethodID) dbbirw_init, NULL, paddress,
5281 (jint) capacity, (jint) capacity, (jint) 0);
5283 /* add local reference and return the value */
5285 return NewLocalRef(env, nbuf);
5289 /* GetDirectBufferAddress ******************************************************
5291 Fetches and returns the starting address of the memory region
5292 referenced by the given direct java.nio.Buffer.
5294 *******************************************************************************/
5296 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5298 java_nio_DirectByteBufferImpl *nbuf;
5299 #if SIZEOF_VOID_P == 8
5300 gnu_classpath_Pointer64 *address;
5302 gnu_classpath_Pointer32 *address;
5305 STATISTICS(jniinvokation());
5307 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5310 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5312 #if SIZEOF_VOID_P == 8
5313 address = (gnu_classpath_Pointer64 *) nbuf->address;
5315 address = (gnu_classpath_Pointer32 *) nbuf->address;
5318 return (void *) address->data;
5322 /* GetDirectBufferCapacity *****************************************************
5324 Fetches and returns the capacity in bytes of the memory region
5325 referenced by the given direct java.nio.Buffer.
5327 *******************************************************************************/
5329 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5331 java_nio_Buffer *nbuf;
5333 STATISTICS(jniinvokation());
5335 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5338 nbuf = (java_nio_Buffer *) buf;
5340 return (jlong) nbuf->cap;
5344 /* DestroyJavaVM ***************************************************************
5346 Unloads a Java VM and reclaims its resources. Only the main thread
5347 can unload the VM. The system waits until the main thread is only
5348 remaining user thread before it destroys the VM.
5350 *******************************************************************************/
5352 jint DestroyJavaVM(JavaVM *vm)
5356 STATISTICS(jniinvokation());
5358 status = vm_destroy(vm);
5364 /* AttachCurrentThread *********************************************************
5366 Attaches the current thread to a Java VM. Returns a JNI interface
5367 pointer in the JNIEnv argument.
5369 Trying to attach a thread that is already attached is a no-op.
5371 A native thread cannot be attached simultaneously to two Java VMs.
5373 When a thread is attached to the VM, the context class loader is
5374 the bootstrap loader.
5376 *******************************************************************************/
5378 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5380 STATISTICS(jniinvokation());
5382 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5384 #if !defined(HAVE___THREAD)
5385 /* cacao_thread_attach();*/
5387 #error "No idea how to implement that. Perhaps Stefan knows"
5396 jint DetachCurrentThread(JavaVM *vm)
5398 STATISTICS(jniinvokation());
5400 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5406 /* GetEnv **********************************************************************
5408 If the current thread is not attached to the VM, sets *env to NULL,
5409 and returns JNI_EDETACHED. If the specified version is not
5410 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5411 sets *env to the appropriate interface, and returns JNI_OK.
5413 *******************************************************************************/
5415 jint GetEnv(JavaVM *vm, void **env, jint version)
5417 STATISTICS(jniinvokation());
5419 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
5420 if (thread_getself() == NULL) {
5423 return JNI_EDETACHED;
5427 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5428 (version == JNI_VERSION_1_4)) {
5434 #if defined(ENABLE_JVMTI)
5435 if (version == JVMTI_VERSION_1_0) {
5436 *env = (void *) new_jvmtienv();
5445 return JNI_EVERSION;
5450 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5452 STATISTICS(jniinvokation());
5454 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5460 /* JNI invocation table *******************************************************/
5462 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5468 AttachCurrentThread,
5469 DetachCurrentThread,
5471 AttachCurrentThreadAsDaemon
5475 /* JNI function table *********************************************************/
5477 struct JNINativeInterface _Jv_JNINativeInterface = {
5486 FromReflectedMethod,
5507 EnsureLocalCapacity,
5550 CallNonvirtualObjectMethod,
5551 CallNonvirtualObjectMethodV,
5552 CallNonvirtualObjectMethodA,
5553 CallNonvirtualBooleanMethod,
5554 CallNonvirtualBooleanMethodV,
5555 CallNonvirtualBooleanMethodA,
5556 CallNonvirtualByteMethod,
5557 CallNonvirtualByteMethodV,
5558 CallNonvirtualByteMethodA,
5559 CallNonvirtualCharMethod,
5560 CallNonvirtualCharMethodV,
5561 CallNonvirtualCharMethodA,
5562 CallNonvirtualShortMethod,
5563 CallNonvirtualShortMethodV,
5564 CallNonvirtualShortMethodA,
5565 CallNonvirtualIntMethod,
5566 CallNonvirtualIntMethodV,
5567 CallNonvirtualIntMethodA,
5568 CallNonvirtualLongMethod,
5569 CallNonvirtualLongMethodV,
5570 CallNonvirtualLongMethodA,
5571 CallNonvirtualFloatMethod,
5572 CallNonvirtualFloatMethodV,
5573 CallNonvirtualFloatMethodA,
5574 CallNonvirtualDoubleMethod,
5575 CallNonvirtualDoubleMethodV,
5576 CallNonvirtualDoubleMethodA,
5577 CallNonvirtualVoidMethod,
5578 CallNonvirtualVoidMethodV,
5579 CallNonvirtualVoidMethodA,
5604 CallStaticObjectMethod,
5605 CallStaticObjectMethodV,
5606 CallStaticObjectMethodA,
5607 CallStaticBooleanMethod,
5608 CallStaticBooleanMethodV,
5609 CallStaticBooleanMethodA,
5610 CallStaticByteMethod,
5611 CallStaticByteMethodV,
5612 CallStaticByteMethodA,
5613 CallStaticCharMethod,
5614 CallStaticCharMethodV,
5615 CallStaticCharMethodA,
5616 CallStaticShortMethod,
5617 CallStaticShortMethodV,
5618 CallStaticShortMethodA,
5619 CallStaticIntMethod,
5620 CallStaticIntMethodV,
5621 CallStaticIntMethodA,
5622 CallStaticLongMethod,
5623 CallStaticLongMethodV,
5624 CallStaticLongMethodA,
5625 CallStaticFloatMethod,
5626 CallStaticFloatMethodV,
5627 CallStaticFloatMethodA,
5628 CallStaticDoubleMethod,
5629 CallStaticDoubleMethodV,
5630 CallStaticDoubleMethodA,
5631 CallStaticVoidMethod,
5632 CallStaticVoidMethodV,
5633 CallStaticVoidMethodA,
5637 GetStaticObjectField,
5638 GetStaticBooleanField,
5641 GetStaticShortField,
5644 GetStaticFloatField,
5645 GetStaticDoubleField,
5646 SetStaticObjectField,
5647 SetStaticBooleanField,
5650 SetStaticShortField,
5653 SetStaticFloatField,
5654 SetStaticDoubleField,
5664 ReleaseStringUTFChars,
5669 GetObjectArrayElement,
5670 SetObjectArrayElement,
5681 GetBooleanArrayElements,
5682 GetByteArrayElements,
5683 GetCharArrayElements,
5684 GetShortArrayElements,
5685 GetIntArrayElements,
5686 GetLongArrayElements,
5687 GetFloatArrayElements,
5688 GetDoubleArrayElements,
5690 ReleaseBooleanArrayElements,
5691 ReleaseByteArrayElements,
5692 ReleaseCharArrayElements,
5693 ReleaseShortArrayElements,
5694 ReleaseIntArrayElements,
5695 ReleaseLongArrayElements,
5696 ReleaseFloatArrayElements,
5697 ReleaseDoubleArrayElements,
5699 GetBooleanArrayRegion,
5702 GetShortArrayRegion,
5705 GetFloatArrayRegion,
5706 GetDoubleArrayRegion,
5707 SetBooleanArrayRegion,
5710 SetShortArrayRegion,
5713 SetFloatArrayRegion,
5714 SetDoubleArrayRegion,
5724 /* new JNI 1.2 functions */
5729 GetPrimitiveArrayCritical,
5730 ReleasePrimitiveArrayCritical,
5733 ReleaseStringCritical,
5736 DeleteWeakGlobalRef,
5740 /* new JNI 1.4 functions */
5742 NewDirectByteBuffer,
5743 GetDirectBufferAddress,
5744 GetDirectBufferCapacity
5748 /* Invocation API Functions ***************************************************/
5750 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5752 Returns a default configuration for the Java VM.
5754 *******************************************************************************/
5756 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5758 JavaVMInitArgs *_vm_args;
5760 _vm_args = (JavaVMInitArgs *) vm_args;
5762 /* GNU classpath currently supports JNI 1.2 */
5764 switch (_vm_args->version) {
5765 case JNI_VERSION_1_1:
5766 _vm_args->version = JNI_VERSION_1_1;
5769 case JNI_VERSION_1_2:
5770 case JNI_VERSION_1_4:
5771 _vm_args->ignoreUnrecognized = JNI_FALSE;
5772 _vm_args->options = NULL;
5773 _vm_args->nOptions = 0;
5784 /* JNI_GetCreatedJavaVMs *******************************************************
5786 Returns all Java VMs that have been created. Pointers to VMs are written in
5787 the buffer vmBuf in the order they are created. At most bufLen number of
5788 entries will be written. The total number of created VMs is returned in
5791 *******************************************************************************/
5793 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5795 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5801 /* JNI_CreateJavaVM ************************************************************
5803 Loads and initializes a Java VM. The current thread becomes the main thread.
5804 Sets the env argument to the JNI interface pointer of the main thread.
5806 *******************************************************************************/
5808 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5810 JavaVMInitArgs *_vm_args;
5813 localref_table *lrt;
5815 /* get the arguments for the new JVM */
5817 _vm_args = (JavaVMInitArgs *) vm_args;
5819 /* get the VM and Env tables (must be set before vm_create) */
5821 env = NEW(_Jv_JNIEnv);
5822 env->env = &_Jv_JNINativeInterface;
5824 /* XXX Set the global variable. Maybe we should do that differently. */
5829 /* create and fill a JavaVM structure */
5831 jvm = NEW(_Jv_JavaVM);
5832 jvm->functions = &_Jv_JNIInvokeInterface;
5834 /* XXX Set the global variable. Maybe we should do that differently. */
5835 /* XXX JVMTI Agents needs a JavaVM */
5839 /* actually create the JVM */
5841 if (!vm_create(_vm_args))
5844 /* setup the local ref table (must be created after vm_create) */
5846 lrt = GCNEW(localref_table);
5848 lrt->capacity = LOCALREFTABLE_CAPACITY;
5850 lrt->localframes = 1;
5851 lrt->prev = LOCALREFTABLE;
5853 /* clear the references array (memset is faster then a for-loop) */
5855 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5857 LOCALREFTABLE = lrt;
5859 /* now return the values */
5861 *p_vm = (JavaVM *) jvm;
5862 *p_env = (void *) env;
5869 * These are local overrides for various environment variables in Emacs.
5870 * Please do not remove this and leave it at the end of the file, where
5871 * Emacs will automagically detect them.
5872 * ---------------------------------------------------------------------
5875 * indent-tabs-mode: t
5879 * vim:noexpandtab:sw=4:ts=4: