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 4573 2006-03-08 09:44:22Z twisti $
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/jvmti.h"
84 #if defined(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;
247 paramcount = descr->paramcount;
248 paramtypes = descr->paramtypes;
250 /* if method is non-static fill first block and skip `this' pointer */
256 vmargs[0].type = TYPE_ADR;
257 vmargs[0].data = (u8) (ptrint) o;
264 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
265 switch (paramtypes->type) {
266 /* primitive types */
271 param = params->data[j];
276 /* internally used data type */
277 vmargs[i].type = paramtypes->type;
279 /* convert the value according to its declared type */
281 c = param->vftbl->class;
283 switch (paramtypes->decltype) {
284 case PRIMITIVETYPE_BOOLEAN:
285 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
286 vmargs[i].data = (s8) ((java_lang_Boolean *) param)->value;
291 case PRIMITIVETYPE_BYTE:
292 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
293 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
298 case PRIMITIVETYPE_CHAR:
299 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
300 vmargs[i].data = (s8) ((java_lang_Character *) param)->value;
305 case PRIMITIVETYPE_SHORT:
306 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
307 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
308 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
309 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
314 case PRIMITIVETYPE_INT:
315 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
316 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
317 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
318 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
319 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
320 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
325 case PRIMITIVETYPE_LONG:
326 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
327 vmargs[i].data = (s8) ((java_lang_Long *) param)->value;
328 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
329 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
330 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
331 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
332 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
333 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
338 case PRIMITIVETYPE_FLOAT:
339 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
340 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
345 case PRIMITIVETYPE_DOUBLE:
346 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
347 *((jdouble *) (&vmargs[i].data)) = (jdouble) ((java_lang_Double *) param)->value;
348 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
349 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
360 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
363 if (params->data[j] != 0) {
364 if (paramtypes->arraydim > 0) {
365 if (!builtin_arrayinstanceof(params->data[j], c))
369 if (!builtin_instanceof(params->data[j], c))
373 vmargs[i].type = TYPE_ADR;
374 vmargs[i].data = (u8) (ptrint) params->data[j];
383 /* *rettype = descr->returntype.decltype; */
388 exceptions_throw_illegalargumentexception();
393 /* _Jv_jni_CallObjectMethod ****************************************************
395 Internal function to call Java Object methods.
397 *******************************************************************************/
399 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
401 methodinfo *m, va_list ap)
404 java_objectheader *ro;
406 STATISTICS(jniinvokation());
409 exceptions_throw_nullpointerexception();
413 /* Class initialization is done by the JIT compiler. This is ok
414 since a static method always belongs to the declaring class. */
416 if (m->flags & ACC_STATIC) {
417 /* For static methods we reset the object. */
422 /* for convenience */
427 /* For instance methods we make a virtual function table lookup. */
429 resm = method_vftbl_lookup(vftbl, m);
432 STATISTICS(jnicallXmethodnvokation());
434 ro = vm_call_method_valist(resm, o, ap);
440 /* _Jv_jni_CallObjectMethodA ***************************************************
442 Internal function to call Java Object methods.
444 *******************************************************************************/
446 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
448 methodinfo *m, jvalue *args)
451 java_objectheader *ro;
453 STATISTICS(jniinvokation());
456 exceptions_throw_nullpointerexception();
460 /* Class initialization is done by the JIT compiler. This is ok
461 since a static method always belongs to the declaring class. */
463 if (m->flags & ACC_STATIC) {
464 /* For static methods we reset the object. */
469 /* for convenience */
474 /* For instance methods we make a virtual function table lookup. */
476 resm = method_vftbl_lookup(vftbl, m);
479 STATISTICS(jnicallXmethodnvokation());
481 ro = vm_call_method_jvalue(resm, o, args);
487 /* _Jv_jni_CallIntMethod *******************************************************
489 Internal function to call Java integer class methods (boolean,
490 byte, char, short, int).
492 *******************************************************************************/
494 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
495 methodinfo *m, va_list ap)
500 STATISTICS(jniinvokation());
503 exceptions_throw_nullpointerexception();
507 /* Class initialization is done by the JIT compiler. This is ok
508 since a static method always belongs to the declaring class. */
510 if (m->flags & ACC_STATIC) {
511 /* For static methods we reset the object. */
516 /* for convenience */
521 /* For instance methods we make a virtual function table lookup. */
523 resm = method_vftbl_lookup(vftbl, m);
526 STATISTICS(jnicallXmethodnvokation());
528 i = vm_call_method_int_valist(resm, o, ap);
534 /* _Jv_jni_CallIntMethodA ******************************************************
536 Internal function to call Java integer class methods (boolean,
537 byte, char, short, int).
539 *******************************************************************************/
541 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
542 methodinfo *m, jvalue *args)
547 STATISTICS(jniinvokation());
550 exceptions_throw_nullpointerexception();
554 /* Class initialization is done by the JIT compiler. This is ok
555 since a static method always belongs to the declaring class. */
557 if (m->flags & ACC_STATIC) {
558 /* For static methods we reset the object. */
563 /* for convenience */
568 /* For instance methods we make a virtual function table lookup. */
570 resm = method_vftbl_lookup(vftbl, m);
573 STATISTICS(jnicallXmethodnvokation());
575 i = vm_call_method_int_jvalue(resm, o, args);
581 /* _Jv_jni_CallLongMethod ******************************************************
583 Internal function to call Java long methods.
585 *******************************************************************************/
587 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
588 methodinfo *m, va_list ap)
593 STATISTICS(jniinvokation());
596 exceptions_throw_nullpointerexception();
600 /* Class initialization is done by the JIT compiler. This is ok
601 since a static method always belongs to the declaring class. */
603 if (m->flags & ACC_STATIC) {
604 /* For static methods we reset the object. */
609 /* for convenience */
614 /* For instance methods we make a virtual function table lookup. */
616 resm = method_vftbl_lookup(vftbl, m);
619 STATISTICS(jnicallXmethodnvokation());
621 l = vm_call_method_long_valist(resm, o, ap);
627 /* _Jv_jni_CallFloatMethod *****************************************************
629 Internal function to call Java float methods.
631 *******************************************************************************/
633 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
634 methodinfo *m, va_list ap)
639 /* Class initialization is done by the JIT compiler. This is ok
640 since a static method always belongs to the declaring class. */
642 if (m->flags & ACC_STATIC) {
643 /* For static methods we reset the object. */
648 /* for convenience */
653 /* For instance methods we make a virtual function table lookup. */
655 resm = method_vftbl_lookup(vftbl, m);
658 STATISTICS(jnicallXmethodnvokation());
660 f = vm_call_method_float_valist(resm, o, ap);
666 /* _Jv_jni_CallDoubleMethod ****************************************************
668 Internal function to call Java double methods.
670 *******************************************************************************/
672 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
673 methodinfo *m, va_list ap)
678 /* Class initialization is done by the JIT compiler. This is ok
679 since a static method always belongs to the declaring class. */
681 if (m->flags & ACC_STATIC) {
682 /* For static methods we reset the object. */
687 /* for convenience */
692 /* For instance methods we make a virtual function table lookup. */
694 resm = method_vftbl_lookup(vftbl, m);
697 d = vm_call_method_double_valist(resm, o, ap);
703 /* _Jv_jni_CallVoidMethod ******************************************************
705 Internal function to call Java void methods.
707 *******************************************************************************/
709 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
710 methodinfo *m, va_list ap)
715 exceptions_throw_nullpointerexception();
719 /* Class initialization is done by the JIT compiler. This is ok
720 since a static method always belongs to the declaring class. */
722 if (m->flags & ACC_STATIC) {
723 /* For static methods we reset the object. */
728 /* for convenience */
733 /* For instance methods we make a virtual function table lookup. */
735 resm = method_vftbl_lookup(vftbl, m);
738 STATISTICS(jnicallXmethodnvokation());
740 (void) vm_call_method_valist(resm, o, ap);
744 /* _Jv_jni_CallVoidMethodA *****************************************************
746 Internal function to call Java void methods.
748 *******************************************************************************/
750 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
751 methodinfo *m, jvalue *args)
756 exceptions_throw_nullpointerexception();
760 /* Class initialization is done by the JIT compiler. This is ok
761 since a static method always belongs to the declaring class. */
763 if (m->flags & ACC_STATIC) {
764 /* For static methods we reset the object. */
769 /* for convenience */
774 /* For instance methods we make a virtual function table lookup. */
776 resm = method_vftbl_lookup(vftbl, m);
779 STATISTICS(jnicallXmethodnvokation());
781 (void) vm_call_method_jvalue(resm, o, args);
785 /* _Jv_jni_invokeNative ********************************************************
787 Invoke a method on the given object with the given arguments.
789 For instance methods OBJ must be != NULL and the method is looked up
790 in the vftbl of the object.
792 For static methods, OBJ is ignored.
794 *******************************************************************************/
796 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
797 java_objectarray *params)
801 java_objectheader *ro;
806 exceptions_throw_nullpointerexception();
810 argcount = m->parseddesc->paramcount;
811 paramcount = argcount;
813 /* if method is non-static, remove the `this' pointer */
815 if (!(m->flags & ACC_STATIC))
818 /* For instance methods the object has to be an instance of the
819 class the method belongs to. For static methods the obj
820 parameter is ignored. */
822 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
824 new_exception_message(string_java_lang_IllegalArgumentException,
825 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
829 /* check if we got the right number of arguments */
831 if (((params == NULL) && (paramcount != 0)) ||
832 (params && (params->header.size != paramcount)))
835 new_exception(string_java_lang_IllegalArgumentException);
839 /* for instance methods we need an object */
841 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
843 new_exception_message(string_java_lang_NullPointerException,
844 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
848 /* for static methods, zero object to make subsequent code simpler */
849 if (m->flags & ACC_STATIC)
853 /* for instance methods we must do a vftbl lookup */
854 resm = method_vftbl_lookup(o->vftbl, m);
857 /* for static methods, just for convenience */
861 vmargs = MNEW(vm_arg, argcount);
863 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
866 switch (resm->parseddesc->returntype.decltype) {
868 (void) vm_call_method_vmarg(resm, argcount, vmargs);
873 case PRIMITIVETYPE_BOOLEAN: {
875 java_lang_Boolean *bo;
877 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
879 ro = builtin_new(class_java_lang_Boolean);
881 /* setting the value of the object direct */
883 bo = (java_lang_Boolean *) ro;
888 case PRIMITIVETYPE_BYTE: {
892 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
894 ro = builtin_new(class_java_lang_Byte);
896 /* setting the value of the object direct */
898 bo = (java_lang_Byte *) ro;
903 case PRIMITIVETYPE_CHAR: {
905 java_lang_Character *co;
907 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
909 ro = builtin_new(class_java_lang_Character);
911 /* setting the value of the object direct */
913 co = (java_lang_Character *) ro;
918 case PRIMITIVETYPE_SHORT: {
922 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
924 ro = builtin_new(class_java_lang_Short);
926 /* setting the value of the object direct */
928 so = (java_lang_Short *) ro;
933 case PRIMITIVETYPE_INT: {
935 java_lang_Integer *io;
937 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
939 ro = builtin_new(class_java_lang_Integer);
941 /* setting the value of the object direct */
943 io = (java_lang_Integer *) ro;
948 case PRIMITIVETYPE_LONG: {
952 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
954 ro = builtin_new(class_java_lang_Long);
956 /* setting the value of the object direct */
958 lo = (java_lang_Long *) ro;
963 case PRIMITIVETYPE_FLOAT: {
967 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
969 ro = builtin_new(class_java_lang_Float);
971 /* setting the value of the object direct */
973 fo = (java_lang_Float *) ro;
978 case PRIMITIVETYPE_DOUBLE: {
980 java_lang_Double *_do;
982 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
984 ro = builtin_new(class_java_lang_Double);
986 /* setting the value of the object direct */
988 _do = (java_lang_Double *) ro;
994 ro = vm_call_method_vmarg(resm, argcount, vmargs);
998 /* if this happens the exception has already been set by
999 fill_callblock_from_objectarray */
1001 MFREE(vmargs, vm_arg, argcount);
1006 MFREE(vmargs, vm_arg, argcount);
1008 if (*exceptionptr) {
1009 java_objectheader *cause;
1011 cause = *exceptionptr;
1013 /* clear exception pointer, we are calling JIT code again */
1015 *exceptionptr = NULL;
1018 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1019 (java_lang_Throwable *) cause);
1026 /* GetVersion ******************************************************************
1028 Returns the major version number in the higher 16 bits and the
1029 minor version number in the lower 16 bits.
1031 *******************************************************************************/
1033 jint GetVersion(JNIEnv *env)
1035 STATISTICS(jniinvokation());
1037 /* we support JNI 1.4 */
1039 return JNI_VERSION_1_4;
1043 /* Class Operations ***********************************************************/
1045 /* DefineClass *****************************************************************
1047 Loads a class from a buffer of raw class data. The buffer
1048 containing the raw class data is not referenced by the VM after the
1049 DefineClass call returns, and it may be discarded if desired.
1051 *******************************************************************************/
1053 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1054 const jbyte *buf, jsize bufLen)
1056 java_lang_ClassLoader *cl;
1057 java_lang_String *s;
1061 STATISTICS(jniinvokation());
1063 cl = (java_lang_ClassLoader *) loader;
1064 s = javastring_new_char(name);
1065 ba = (java_bytearray *) buf;
1067 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1070 return (jclass) NewLocalRef(env, (jobject) c);
1074 /* FindClass *******************************************************************
1076 This function loads a locally-defined class. It searches the
1077 directories and zip files specified by the CLASSPATH environment
1078 variable for the class with the specified name.
1080 *******************************************************************************/
1082 jclass FindClass(JNIEnv *env, const char *name)
1088 STATISTICS(jniinvokation());
1090 u = utf_new_char_classname((char *) name);
1092 /* Check stacktrace for classloader, if one found use it,
1093 otherwise use the system classloader. */
1095 /* Quote from the JNI documentation:
1097 In the Java 2 Platform, FindClass locates the class loader
1098 associated with the current native method. If the native code
1099 belongs to a system class, no class loader will be
1100 involved. Otherwise, the proper class loader will be invoked to
1101 load and link the named class. When FindClass is called through
1102 the Invocation Interface, there is no current native method or
1103 its associated class loader. In that case, the result of
1104 ClassLoader.getBaseClassLoader is used." */
1106 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1107 /* these JITs support stacktraces, and so does the interpreter */
1109 cc = stacktrace_getCurrentClass();
1111 # if defined(ENABLE_INTRP)
1112 /* the interpreter supports stacktraces, even if the JIT does not */
1115 cc = stacktrace_getCurrentClass();
1121 /* if no Java method was found, use the system classloader */
1124 c = load_class_from_sysloader(u);
1126 c = load_class_from_classloader(u, cc->classloader);
1134 return (jclass) NewLocalRef(env, (jobject) c);
1138 /* GetSuperclass ***************************************************************
1140 If clazz represents any class other than the class Object, then
1141 this function returns the object that represents the superclass of
1142 the class specified by clazz.
1144 *******************************************************************************/
1146 jclass GetSuperclass(JNIEnv *env, jclass sub)
1150 STATISTICS(jniinvokation());
1152 c = ((classinfo *) sub)->super.cls;
1157 return (jclass) NewLocalRef(env, (jobject) c);
1161 /* IsAssignableFrom ************************************************************
1163 Determines whether an object of sub can be safely cast to sup.
1165 *******************************************************************************/
1167 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1169 STATISTICS(jniinvokation());
1171 return Java_java_lang_VMClass_isAssignableFrom(env,
1173 (java_lang_Class *) sup,
1174 (java_lang_Class *) sub);
1178 /* Throw ***********************************************************************
1180 Causes a java.lang.Throwable object to be thrown.
1182 *******************************************************************************/
1184 jint Throw(JNIEnv *env, jthrowable obj)
1186 STATISTICS(jniinvokation());
1188 *exceptionptr = (java_objectheader *) obj;
1194 /* ThrowNew ********************************************************************
1196 Constructs an exception object from the specified class with the
1197 message specified by message and causes that exception to be
1200 *******************************************************************************/
1202 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1204 java_lang_Throwable *o;
1205 java_lang_String *s;
1207 STATISTICS(jniinvokation());
1209 s = (java_lang_String *) javastring_new_char(msg);
1211 /* instantiate exception object */
1213 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1219 *exceptionptr = (java_objectheader *) o;
1225 /* ExceptionOccurred ***********************************************************
1227 Determines if an exception is being thrown. The exception stays
1228 being thrown until either the native code calls ExceptionClear(),
1229 or the Java code handles the exception.
1231 *******************************************************************************/
1233 jthrowable ExceptionOccurred(JNIEnv *env)
1235 java_objectheader *e;
1237 STATISTICS(jniinvokation());
1241 return NewLocalRef(env, (jthrowable) e);
1245 /* ExceptionDescribe ***********************************************************
1247 Prints an exception and a backtrace of the stack to a system
1248 error-reporting channel, such as stderr. This is a convenience
1249 routine provided for debugging.
1251 *******************************************************************************/
1253 void ExceptionDescribe(JNIEnv *env)
1255 java_objectheader *e;
1258 STATISTICS(jniinvokation());
1263 /* clear exception, because we are calling jit code again */
1265 *exceptionptr = NULL;
1267 /* get printStackTrace method from exception class */
1269 m = class_resolveclassmethod(e->vftbl->class,
1270 utf_printStackTrace,
1276 /* XXX what should we do? */
1279 /* print the stacktrace */
1281 (void) vm_call_method(m, e);
1286 /* ExceptionClear **************************************************************
1288 Clears any exception that is currently being thrown. If no
1289 exception is currently being thrown, this routine has no effect.
1291 *******************************************************************************/
1293 void ExceptionClear(JNIEnv *env)
1295 STATISTICS(jniinvokation());
1297 *exceptionptr = NULL;
1301 /* FatalError ******************************************************************
1303 Raises a fatal error and does not expect the VM to recover. This
1304 function does not return.
1306 *******************************************************************************/
1308 void FatalError(JNIEnv *env, const char *msg)
1310 STATISTICS(jniinvokation());
1312 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1316 /* PushLocalFrame **************************************************************
1318 Creates a new local reference frame, in which at least a given
1319 number of local references can be created.
1321 *******************************************************************************/
1323 jint PushLocalFrame(JNIEnv* env, jint capacity)
1326 localref_table *lrt;
1327 localref_table *nlrt;
1329 STATISTICS(jniinvokation());
1334 /* Allocate new local reference table on Java heap. Calculate the
1335 additional memory we have to allocate. */
1337 if (capacity > LOCALREFTABLE_CAPACITY)
1338 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1342 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1347 /* get current local reference table from thread */
1349 lrt = LOCALREFTABLE;
1351 /* Set up the new local reference table and add it to the local
1354 nlrt->capacity = capacity;
1356 nlrt->localframes = lrt->localframes + 1;
1359 /* store new local reference table in thread */
1361 LOCALREFTABLE = nlrt;
1367 /* PopLocalFrame ***************************************************************
1369 Pops off the current local reference frame, frees all the local
1370 references, and returns a local reference in the previous local
1371 reference frame for the given result object.
1373 *******************************************************************************/
1375 jobject PopLocalFrame(JNIEnv* env, jobject result)
1377 localref_table *lrt;
1378 localref_table *plrt;
1381 STATISTICS(jniinvokation());
1383 /* get current local reference table from thread */
1385 lrt = LOCALREFTABLE;
1387 localframes = lrt->localframes;
1389 /* Don't delete the top local frame, as this one is allocated in
1390 the native stub on the stack and is freed automagically on
1393 if (localframes == 1)
1394 return NewLocalRef(env, result);
1396 /* release all current local frames */
1398 for (; localframes >= 1; localframes--) {
1399 /* get previous frame */
1403 /* clear all reference entries */
1405 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1409 /* set new local references table */
1414 /* store new local reference table in thread */
1416 LOCALREFTABLE = lrt;
1418 /* add local reference and return the value */
1420 return NewLocalRef(env, result);
1424 /* DeleteLocalRef **************************************************************
1426 Deletes the local reference pointed to by localRef.
1428 *******************************************************************************/
1430 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1432 java_objectheader *o;
1433 localref_table *lrt;
1436 STATISTICS(jniinvokation());
1438 o = (java_objectheader *) localRef;
1440 /* get local reference table (thread specific) */
1442 lrt = LOCALREFTABLE;
1444 /* go through all local frames */
1446 for (; lrt != NULL; lrt = lrt->prev) {
1448 /* and try to remove the reference */
1450 for (i = 0; i < lrt->capacity; i++) {
1451 if (lrt->refs[i] == o) {
1452 lrt->refs[i] = NULL;
1460 /* this should not happen */
1462 /* if (opt_checkjni) */
1463 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1464 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1468 /* IsSameObject ****************************************************************
1470 Tests whether two references refer to the same Java object.
1472 *******************************************************************************/
1474 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1476 STATISTICS(jniinvokation());
1485 /* NewLocalRef *****************************************************************
1487 Creates a new local reference that refers to the same object as ref.
1489 *******************************************************************************/
1491 jobject NewLocalRef(JNIEnv *env, jobject ref)
1493 localref_table *lrt;
1496 STATISTICS(jniinvokation());
1501 /* get local reference table (thread specific) */
1503 lrt = LOCALREFTABLE;
1505 /* Check if we have space for the requested reference? No,
1506 allocate a new frame. This is actually not what the spec says,
1507 but for compatibility reasons... */
1509 if (lrt->used == lrt->capacity) {
1510 if (EnsureLocalCapacity(env, 16) != 0)
1513 /* get the new local reference table */
1515 lrt = LOCALREFTABLE;
1518 /* insert the reference */
1520 for (i = 0; i < lrt->capacity; i++) {
1521 if (lrt->refs[i] == NULL) {
1522 lrt->refs[i] = (java_objectheader *) ref;
1529 /* should not happen, just to be sure */
1533 /* keep compiler happy */
1539 /* EnsureLocalCapacity *********************************************************
1541 Ensures that at least a given number of local references can be
1542 created in the current thread
1544 *******************************************************************************/
1546 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1548 localref_table *lrt;
1550 log_text("JNI-Call: EnsureLocalCapacity");
1552 STATISTICS(jniinvokation());
1554 /* get local reference table (thread specific) */
1556 lrt = LOCALREFTABLE;
1558 /* check if capacity elements are available in the local references table */
1560 if ((lrt->used + capacity) > lrt->capacity)
1561 return PushLocalFrame(env, capacity);
1567 /* AllocObject *****************************************************************
1569 Allocates a new Java object without invoking any of the
1570 constructors for the object. Returns a reference to the object.
1572 *******************************************************************************/
1574 jobject AllocObject(JNIEnv *env, jclass clazz)
1577 java_objectheader *o;
1579 STATISTICS(jniinvokation());
1581 c = (classinfo *) clazz;
1583 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1585 new_exception_utfmessage(string_java_lang_InstantiationException,
1592 return NewLocalRef(env, o);
1596 /* NewObject *******************************************************************
1598 Programmers place all arguments that are to be passed to the
1599 constructor immediately following the methodID
1600 argument. NewObject() accepts these arguments and passes them to
1601 the Java method that the programmer wishes to invoke.
1603 *******************************************************************************/
1605 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1607 java_objectheader *o;
1611 STATISTICS(jniinvokation());
1613 m = (methodinfo *) methodID;
1617 o = builtin_new(clazz);
1622 /* call constructor */
1624 va_start(ap, methodID);
1625 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1628 return NewLocalRef(env, o);
1632 /* NewObjectV ******************************************************************
1634 Programmers place all arguments that are to be passed to the
1635 constructor in an args argument of type va_list that immediately
1636 follows the methodID argument. NewObjectV() accepts these
1637 arguments, and, in turn, passes them to the Java method that the
1638 programmer wishes to invoke.
1640 *******************************************************************************/
1642 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1644 java_objectheader *o;
1647 STATISTICS(jniinvokation());
1649 m = (methodinfo *) methodID;
1653 o = builtin_new(clazz);
1658 /* call constructor */
1660 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1662 return NewLocalRef(env, o);
1666 /* NewObjectA *****************************************************************
1668 Programmers place all arguments that are to be passed to the
1669 constructor in an args array of jvalues that immediately follows
1670 the methodID argument. NewObjectA() accepts the arguments in this
1671 array, and, in turn, passes them to the Java method that the
1672 programmer wishes to invoke.
1674 *******************************************************************************/
1676 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1678 java_objectheader *o;
1681 STATISTICS(jniinvokation());
1683 m = (methodinfo *) methodID;
1687 o = builtin_new(clazz);
1692 /* call constructor */
1694 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1696 return NewLocalRef(env, o);
1700 /* GetObjectClass **************************************************************
1702 Returns the class of an object.
1704 *******************************************************************************/
1706 jclass GetObjectClass(JNIEnv *env, jobject obj)
1708 java_objectheader *o;
1711 STATISTICS(jniinvokation());
1713 o = (java_objectheader *) obj;
1715 if ((o == NULL) || (o->vftbl == NULL))
1718 c = o->vftbl->class;
1720 return (jclass) NewLocalRef(env, (jobject) c);
1724 /* IsInstanceOf ****************************************************************
1726 Tests whether an object is an instance of a class.
1728 *******************************************************************************/
1730 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1732 STATISTICS(jniinvokation());
1734 return Java_java_lang_VMClass_isInstance(env,
1736 (java_lang_Class *) clazz,
1737 (java_lang_Object *) obj);
1741 /* Reflection Support *********************************************************/
1743 /* FromReflectedMethod *********************************************************
1745 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1746 object to a method ID.
1748 *******************************************************************************/
1750 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1756 STATISTICS(jniinvokation());
1761 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1762 java_lang_reflect_Method *rm;
1764 rm = (java_lang_reflect_Method *) method;
1765 c = (classinfo *) (rm->declaringClass);
1768 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1769 java_lang_reflect_Constructor *rc;
1771 rc = (java_lang_reflect_Constructor *) method;
1772 c = (classinfo *) (rc->clazz);
1778 mi = &(c->methods[slot]);
1780 return (jmethodID) mi;
1784 /* FromReflectedField **********************************************************
1786 Converts a java.lang.reflect.Field to a field ID.
1788 *******************************************************************************/
1790 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1792 java_lang_reflect_Field *rf;
1796 STATISTICS(jniinvokation());
1798 rf = (java_lang_reflect_Field *) field;
1803 c = (classinfo *) rf->declaringClass;
1805 f = &(c->fields[rf->slot]);
1807 return (jfieldID) f;
1811 /* ToReflectedMethod ***********************************************************
1813 Converts a method ID derived from cls to an instance of the
1814 java.lang.reflect.Method class or to an instance of the
1815 java.lang.reflect.Constructor class.
1817 *******************************************************************************/
1819 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1821 STATISTICS(jniinvokation());
1823 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1829 /* ToReflectedField ************************************************************
1831 Converts a field ID derived from cls to an instance of the
1832 java.lang.reflect.Field class.
1834 *******************************************************************************/
1836 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1839 STATISTICS(jniinvokation());
1841 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1847 /* Calling Instance Methods ***************************************************/
1849 /* GetMethodID *****************************************************************
1851 Returns the method ID for an instance (nonstatic) method of a class
1852 or interface. The method may be defined in one of the clazz's
1853 superclasses and inherited by clazz. The method is determined by
1854 its name and signature.
1856 GetMethodID() causes an uninitialized class to be initialized.
1858 *******************************************************************************/
1860 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1868 STATISTICS(jniinvokation());
1870 c = (classinfo *) clazz;
1875 if (!(c->state & CLASS_INITIALIZED))
1876 if (!initialize_class(c))
1879 /* try to get the method of the class or one of it's superclasses */
1881 uname = utf_new_char((char *) name);
1882 udesc = utf_new_char((char *) sig);
1884 m = class_resolvemethod(clazz, uname, udesc);
1886 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1887 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1892 return (jmethodID) m;
1896 /* JNI-functions for calling instance methods *********************************/
1898 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1900 java_objectheader *o;
1902 java_objectheader *ret;
1905 o = (java_objectheader *) obj;
1906 m = (methodinfo *) methodID;
1908 va_start(ap, methodID);
1909 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1912 return NewLocalRef(env, ret);
1916 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1918 java_objectheader *o;
1920 java_objectheader *ret;
1922 o = (java_objectheader *) obj;
1923 m = (methodinfo *) methodID;
1925 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1927 return NewLocalRef(env, ret);
1931 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1933 java_objectheader *o;
1935 java_objectheader *ret;
1937 o = (java_objectheader *) obj;
1938 m = (methodinfo *) methodID;
1940 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1942 return NewLocalRef(env, ret);
1946 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1948 java_objectheader *o;
1953 o = (java_objectheader *) obj;
1954 m = (methodinfo *) methodID;
1956 va_start(ap, methodID);
1957 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1964 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1966 java_objectheader *o;
1970 o = (java_objectheader *) obj;
1971 m = (methodinfo *) methodID;
1973 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1979 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1981 java_objectheader *o;
1985 o = (java_objectheader *) obj;
1986 m = (methodinfo *) methodID;
1988 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1994 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1996 java_objectheader *o;
2001 o = (java_objectheader *) obj;
2002 m = (methodinfo *) methodID;
2004 va_start(ap, methodID);
2005 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2012 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2014 java_objectheader *o;
2018 o = (java_objectheader *) obj;
2019 m = (methodinfo *) methodID;
2021 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2027 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2029 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2035 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2037 java_objectheader *o;
2042 o = (java_objectheader *) obj;
2043 m = (methodinfo *) methodID;
2045 va_start(ap, methodID);
2046 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2053 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2055 java_objectheader *o;
2059 o = (java_objectheader *) obj;
2060 m = (methodinfo *) methodID;
2062 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2068 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2070 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2076 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2078 java_objectheader *o;
2083 o = (java_objectheader *) obj;
2084 m = (methodinfo *) methodID;
2086 va_start(ap, methodID);
2087 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2094 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2096 java_objectheader *o;
2100 o = (java_objectheader *) obj;
2101 m = (methodinfo *) methodID;
2103 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2109 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2111 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2118 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2120 java_objectheader *o;
2125 o = (java_objectheader *) obj;
2126 m = (methodinfo *) methodID;
2128 va_start(ap, methodID);
2129 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2136 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2138 java_objectheader *o;
2142 o = (java_objectheader *) obj;
2143 m = (methodinfo *) methodID;
2145 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2151 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2153 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2160 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2162 java_objectheader *o;
2167 o = (java_objectheader *) obj;
2168 m = (methodinfo *) methodID;
2170 va_start(ap, methodID);
2171 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2178 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2180 java_objectheader *o;
2184 o = (java_objectheader *) obj;
2185 m = (methodinfo *) methodID;
2187 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2193 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2195 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2202 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2204 java_objectheader *o;
2209 o = (java_objectheader *) obj;
2210 m = (methodinfo *) methodID;
2212 va_start(ap, methodID);
2213 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2220 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2222 java_objectheader *o;
2226 o = (java_objectheader *) obj;
2227 m = (methodinfo *) methodID;
2229 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2235 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2237 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2244 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2246 java_objectheader *o;
2251 o = (java_objectheader *) obj;
2252 m = (methodinfo *) methodID;
2254 va_start(ap, methodID);
2255 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2262 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2264 java_objectheader *o;
2268 o = (java_objectheader *) obj;
2269 m = (methodinfo *) methodID;
2271 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2277 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2279 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2286 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2288 java_objectheader *o;
2292 o = (java_objectheader *) obj;
2293 m = (methodinfo *) methodID;
2295 va_start(ap, methodID);
2296 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2301 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2303 java_objectheader *o;
2306 o = (java_objectheader *) obj;
2307 m = (methodinfo *) methodID;
2309 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2313 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2315 java_objectheader *o;
2318 o = (java_objectheader *) obj;
2319 m = (methodinfo *) methodID;
2321 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2326 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2328 java_objectheader *o;
2331 java_objectheader *r;
2334 o = (java_objectheader *) obj;
2335 c = (classinfo *) clazz;
2336 m = (methodinfo *) methodID;
2338 va_start(ap, methodID);
2339 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2342 return NewLocalRef(env, r);
2346 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2348 java_objectheader *o;
2351 java_objectheader *r;
2353 o = (java_objectheader *) obj;
2354 c = (classinfo *) clazz;
2355 m = (methodinfo *) methodID;
2357 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2359 return NewLocalRef(env, r);
2363 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2365 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2367 return NewLocalRef(env, NULL);
2372 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2374 java_objectheader *o;
2380 o = (java_objectheader *) obj;
2381 c = (classinfo *) clazz;
2382 m = (methodinfo *) methodID;
2384 va_start(ap, methodID);
2385 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2392 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2394 java_objectheader *o;
2399 o = (java_objectheader *) obj;
2400 c = (classinfo *) clazz;
2401 m = (methodinfo *) methodID;
2403 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2409 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2411 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2417 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2419 java_objectheader *o;
2425 o = (java_objectheader *) obj;
2426 c = (classinfo *) clazz;
2427 m = (methodinfo *) methodID;
2429 va_start(ap, methodID);
2430 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2437 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2439 java_objectheader *o;
2444 o = (java_objectheader *) obj;
2445 c = (classinfo *) clazz;
2446 m = (methodinfo *) methodID;
2448 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2454 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2456 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2463 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2465 java_objectheader *o;
2471 o = (java_objectheader *) obj;
2472 c = (classinfo *) clazz;
2473 m = (methodinfo *) methodID;
2475 va_start(ap, methodID);
2476 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2483 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2485 java_objectheader *o;
2490 o = (java_objectheader *) obj;
2491 c = (classinfo *) clazz;
2492 m = (methodinfo *) methodID;
2494 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2500 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2502 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2509 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2511 java_objectheader *o;
2517 o = (java_objectheader *) obj;
2518 c = (classinfo *) clazz;
2519 m = (methodinfo *) methodID;
2521 va_start(ap, methodID);
2522 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2529 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2531 java_objectheader *o;
2536 o = (java_objectheader *) obj;
2537 c = (classinfo *) clazz;
2538 m = (methodinfo *) methodID;
2540 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2546 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2548 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2555 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2557 java_objectheader *o;
2563 o = (java_objectheader *) obj;
2564 c = (classinfo *) clazz;
2565 m = (methodinfo *) methodID;
2567 va_start(ap, methodID);
2568 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2575 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2577 java_objectheader *o;
2582 o = (java_objectheader *) obj;
2583 c = (classinfo *) clazz;
2584 m = (methodinfo *) methodID;
2586 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2592 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2594 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2601 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2603 java_objectheader *o;
2609 o = (java_objectheader *) obj;
2610 c = (classinfo *) clazz;
2611 m = (methodinfo *) methodID;
2613 va_start(ap, methodID);
2614 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2621 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2623 java_objectheader *o;
2628 o = (java_objectheader *) obj;
2629 c = (classinfo *) clazz;
2630 m = (methodinfo *) methodID;
2632 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2638 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2640 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2647 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2649 java_objectheader *o;
2655 o = (java_objectheader *) obj;
2656 c = (classinfo *) clazz;
2657 m = (methodinfo *) methodID;
2659 va_start(ap, methodID);
2660 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2667 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2669 java_objectheader *o;
2674 o = (java_objectheader *) obj;
2675 c = (classinfo *) clazz;
2676 m = (methodinfo *) methodID;
2678 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2684 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2686 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2693 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2695 java_objectheader *o;
2701 o = (java_objectheader *) obj;
2702 c = (classinfo *) clazz;
2703 m = (methodinfo *) methodID;
2705 va_start(ap, methodID);
2706 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2713 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2715 java_objectheader *o;
2720 o = (java_objectheader *) obj;
2721 c = (classinfo *) clazz;
2722 m = (methodinfo *) methodID;
2724 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2730 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2732 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2739 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2741 java_objectheader *o;
2746 o = (java_objectheader *) obj;
2747 c = (classinfo *) clazz;
2748 m = (methodinfo *) methodID;
2750 va_start(ap, methodID);
2751 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2756 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2758 java_objectheader *o;
2762 o = (java_objectheader *) obj;
2763 c = (classinfo *) clazz;
2764 m = (methodinfo *) methodID;
2766 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2770 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2772 java_objectheader *o;
2776 o = (java_objectheader *) obj;
2777 c = (classinfo *) clazz;
2778 m = (methodinfo *) methodID;
2780 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2784 /* Accessing Fields of Objects ************************************************/
2786 /* GetFieldID ******************************************************************
2788 Returns the field ID for an instance (nonstatic) field of a
2789 class. The field is specified by its name and signature. The
2790 Get<type>Field and Set<type>Field families of accessor functions
2791 use field IDs to retrieve object fields.
2793 *******************************************************************************/
2795 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2802 STATISTICS(jniinvokation());
2804 uname = utf_new_char((char *) name);
2805 udesc = utf_new_char((char *) sig);
2807 f = class_findfield(clazz, uname, udesc);
2810 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2812 return (jfieldID) f;
2816 /* Get<type>Field Routines *****************************************************
2818 This family of accessor routines returns the value of an instance
2819 (nonstatic) field of an object. The field to access is specified by
2820 a field ID obtained by calling GetFieldID().
2822 *******************************************************************************/
2824 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2826 java_objectheader *o;
2828 STATISTICS(jniinvokation());
2830 o = GET_FIELD(obj, java_objectheader*, fieldID);
2832 return NewLocalRef(env, o);
2836 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2840 STATISTICS(jniinvokation());
2842 i = GET_FIELD(obj, s4, fieldID);
2844 return (jboolean) i;
2848 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2852 STATISTICS(jniinvokation());
2854 i = GET_FIELD(obj, s4, fieldID);
2860 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2864 STATISTICS(jniinvokation());
2866 i = GET_FIELD(obj, s4, fieldID);
2872 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2876 STATISTICS(jniinvokation());
2878 i = GET_FIELD(obj, s4, fieldID);
2884 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2886 java_objectheader *o;
2890 STATISTICS(jniinvokation());
2892 o = (java_objectheader *) obj;
2893 f = (fieldinfo *) fieldID;
2895 i = GET_FIELD(o, s4, f);
2901 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2905 STATISTICS(jniinvokation());
2907 l = GET_FIELD(obj, s8, fieldID);
2913 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2917 STATISTICS(jniinvokation());
2919 f = GET_FIELD(obj, float, fieldID);
2925 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2929 STATISTICS(jniinvokation());
2931 d = GET_FIELD(obj, double, fieldID);
2937 /* Set<type>Field Routines *****************************************************
2939 This family of accessor routines sets the value of an instance
2940 (nonstatic) field of an object. The field to access is specified by
2941 a field ID obtained by calling GetFieldID().
2943 *******************************************************************************/
2945 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2947 STATISTICS(jniinvokation());
2949 SET_FIELD(obj, java_objectheader*, fieldID, value);
2953 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2955 STATISTICS(jniinvokation());
2957 SET_FIELD(obj, s4, fieldID, value);
2961 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2963 STATISTICS(jniinvokation());
2965 SET_FIELD(obj, s4, fieldID, value);
2969 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2971 STATISTICS(jniinvokation());
2973 SET_FIELD(obj, s4, fieldID, value);
2977 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2979 STATISTICS(jniinvokation());
2981 SET_FIELD(obj, s4, fieldID, value);
2985 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2987 STATISTICS(jniinvokation());
2989 SET_FIELD(obj, s4, fieldID, value);
2993 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2995 STATISTICS(jniinvokation());
2997 SET_FIELD(obj, s8, fieldID, value);
3001 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
3003 STATISTICS(jniinvokation());
3005 SET_FIELD(obj, float, fieldID, value);
3009 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3011 STATISTICS(jniinvokation());
3013 SET_FIELD(obj, double, fieldID, value);
3017 /* Calling Static Methods *****************************************************/
3019 /* GetStaticMethodID ***********************************************************
3021 Returns the method ID for a static method of a class. The method is
3022 specified by its name and signature.
3024 GetStaticMethodID() causes an uninitialized class to be
3027 *******************************************************************************/
3029 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3037 STATISTICS(jniinvokation());
3039 c = (classinfo *) clazz;
3044 if (!(c->state & CLASS_INITIALIZED))
3045 if (!initialize_class(c))
3048 /* try to get the static method of the class */
3050 uname = utf_new_char((char *) name);
3051 udesc = utf_new_char((char *) sig);
3053 m = class_resolvemethod(c, uname, udesc);
3055 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3056 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3061 return (jmethodID) m;
3065 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3068 java_objectheader *o;
3071 m = (methodinfo *) methodID;
3073 va_start(ap, methodID);
3074 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3077 return NewLocalRef(env, o);
3081 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3084 java_objectheader *o;
3086 m = (methodinfo *) methodID;
3088 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3090 return NewLocalRef(env, o);
3094 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3097 java_objectheader *o;
3099 m = (methodinfo *) methodID;
3101 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3103 return NewLocalRef(env, o);
3107 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3113 m = (methodinfo *) methodID;
3115 va_start(ap, methodID);
3116 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3123 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3128 m = (methodinfo *) methodID;
3130 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3136 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3138 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3144 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3150 m = (methodinfo *) methodID;
3152 va_start(ap, methodID);
3153 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3160 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3165 m = (methodinfo *) methodID;
3167 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3173 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3175 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3181 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3187 m = (methodinfo *) methodID;
3189 va_start(ap, methodID);
3190 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3197 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3202 m = (methodinfo *) methodID;
3204 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3210 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3212 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3218 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3224 m = (methodinfo *) methodID;
3226 va_start(ap, methodID);
3227 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3234 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3239 m = (methodinfo *) methodID;
3241 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3247 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3249 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3255 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3261 m = (methodinfo *) methodID;
3263 va_start(ap, methodID);
3264 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3271 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3276 m = (methodinfo *) methodID;
3278 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3284 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3286 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3292 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3298 m = (methodinfo *) methodID;
3300 va_start(ap, methodID);
3301 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3308 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3314 m = (methodinfo *) methodID;
3316 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3322 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3324 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3331 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3337 m = (methodinfo *) methodID;
3339 va_start(ap, methodID);
3340 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3347 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3352 m = (methodinfo *) methodID;
3354 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3360 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3362 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3368 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3374 m = (methodinfo *) methodID;
3376 va_start(ap, methodID);
3377 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3384 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3389 m = (methodinfo *) methodID;
3391 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3397 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3399 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3405 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3410 m = (methodinfo *) methodID;
3412 va_start(ap, methodID);
3413 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3418 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3422 m = (methodinfo *) methodID;
3424 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3428 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3432 m = (methodinfo *) methodID;
3434 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3438 /* Accessing Static Fields ****************************************************/
3440 /* GetStaticFieldID ************************************************************
3442 Returns the field ID for a static field of a class. The field is
3443 specified by its name and signature. The GetStatic<type>Field and
3444 SetStatic<type>Field families of accessor functions use field IDs
3445 to retrieve static fields.
3447 *******************************************************************************/
3449 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3453 STATISTICS(jniinvokation());
3455 f = class_findfield(clazz,
3456 utf_new_char((char *) name),
3457 utf_new_char((char *) sig));
3460 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3462 return (jfieldID) f;
3466 /* GetStatic<type>Field ********************************************************
3468 This family of accessor routines returns the value of a static
3471 *******************************************************************************/
3473 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3478 STATISTICS(jniinvokation());
3480 c = (classinfo *) clazz;
3481 f = (fieldinfo *) fieldID;
3483 if (!(c->state & CLASS_INITIALIZED))
3484 if (!initialize_class(c))
3487 return NewLocalRef(env, f->value.a);
3491 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3496 STATISTICS(jniinvokation());
3498 c = (classinfo *) clazz;
3499 f = (fieldinfo *) fieldID;
3501 if (!(c->state & CLASS_INITIALIZED))
3502 if (!initialize_class(c))
3509 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3514 STATISTICS(jniinvokation());
3516 c = (classinfo *) clazz;
3517 f = (fieldinfo *) fieldID;
3519 if (!(c->state & CLASS_INITIALIZED))
3520 if (!initialize_class(c))
3527 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3532 STATISTICS(jniinvokation());
3534 c = (classinfo *) clazz;
3535 f = (fieldinfo *) fieldID;
3537 if (!(c->state & CLASS_INITIALIZED))
3538 if (!initialize_class(c))
3545 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3550 STATISTICS(jniinvokation());
3552 c = (classinfo *) clazz;
3553 f = (fieldinfo *) fieldID;
3555 if (!(c->state & CLASS_INITIALIZED))
3556 if (!initialize_class(c))
3563 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3568 STATISTICS(jniinvokation());
3570 c = (classinfo *) clazz;
3571 f = (fieldinfo *) fieldID;
3573 if (!(c->state & CLASS_INITIALIZED))
3574 if (!initialize_class(c))
3581 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3586 STATISTICS(jniinvokation());
3588 c = (classinfo *) clazz;
3589 f = (fieldinfo *) fieldID;
3591 if (!(c->state & CLASS_INITIALIZED))
3592 if (!initialize_class(c))
3599 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3604 STATISTICS(jniinvokation());
3606 c = (classinfo *) clazz;
3607 f = (fieldinfo *) fieldID;
3609 if (!(c->state & CLASS_INITIALIZED))
3610 if (!initialize_class(c))
3617 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3622 STATISTICS(jniinvokation());
3624 c = (classinfo *) clazz;
3625 f = (fieldinfo *) fieldID;
3627 if (!(c->state & CLASS_INITIALIZED))
3628 if (!initialize_class(c))
3635 /* SetStatic<type>Field *******************************************************
3637 This family of accessor routines sets the value of a static field
3640 *******************************************************************************/
3642 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3647 STATISTICS(jniinvokation());
3649 c = (classinfo *) clazz;
3650 f = (fieldinfo *) fieldID;
3652 if (!(c->state & CLASS_INITIALIZED))
3653 if (!initialize_class(c))
3660 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3665 STATISTICS(jniinvokation());
3667 c = (classinfo *) clazz;
3668 f = (fieldinfo *) fieldID;
3670 if (!(c->state & CLASS_INITIALIZED))
3671 if (!initialize_class(c))
3678 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3683 STATISTICS(jniinvokation());
3685 c = (classinfo *) clazz;
3686 f = (fieldinfo *) fieldID;
3688 if (!(c->state & CLASS_INITIALIZED))
3689 if (!initialize_class(c))
3696 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3701 STATISTICS(jniinvokation());
3703 c = (classinfo *) clazz;
3704 f = (fieldinfo *) fieldID;
3706 if (!(c->state & CLASS_INITIALIZED))
3707 if (!initialize_class(c))
3714 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3719 STATISTICS(jniinvokation());
3721 c = (classinfo *) clazz;
3722 f = (fieldinfo *) fieldID;
3724 if (!(c->state & CLASS_INITIALIZED))
3725 if (!initialize_class(c))
3732 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3737 STATISTICS(jniinvokation());
3739 c = (classinfo *) clazz;
3740 f = (fieldinfo *) fieldID;
3742 if (!(c->state & CLASS_INITIALIZED))
3743 if (!initialize_class(c))
3750 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3755 STATISTICS(jniinvokation());
3757 c = (classinfo *) clazz;
3758 f = (fieldinfo *) fieldID;
3760 if (!(c->state & CLASS_INITIALIZED))
3761 if (!initialize_class(c))
3768 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3773 STATISTICS(jniinvokation());
3775 c = (classinfo *) clazz;
3776 f = (fieldinfo *) fieldID;
3778 if (!(c->state & CLASS_INITIALIZED))
3779 if (!initialize_class(c))
3786 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3791 STATISTICS(jniinvokation());
3793 c = (classinfo *) clazz;
3794 f = (fieldinfo *) fieldID;
3796 if (!(c->state & CLASS_INITIALIZED))
3797 if (!initialize_class(c))
3804 /* String Operations **********************************************************/
3806 /* NewString *******************************************************************
3808 Create new java.lang.String object from an array of Unicode
3811 *******************************************************************************/
3813 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3815 java_lang_String *s;
3819 STATISTICS(jniinvokation());
3821 s = (java_lang_String *) builtin_new(class_java_lang_String);
3822 a = builtin_newarray_char(len);
3824 /* javastring or characterarray could not be created */
3829 for (i = 0; i < len; i++)
3830 a->data[i] = buf[i];
3836 return (jstring) NewLocalRef(env, (jobject) s);
3840 static jchar emptyStringJ[]={0,0};
3842 /* GetStringLength *************************************************************
3844 Returns the length (the count of Unicode characters) of a Java
3847 *******************************************************************************/
3849 jsize GetStringLength(JNIEnv *env, jstring str)
3851 return ((java_lang_String *) str)->count;
3855 /******************** convertes javastring to u2-array ****************************/
3857 u2 *javastring_tou2(jstring so)
3859 java_lang_String *s;
3864 STATISTICS(jniinvokation());
3866 s = (java_lang_String *) so;
3876 /* allocate memory */
3878 stringbuffer = MNEW(u2, s->count + 1);
3882 for (i = 0; i < s->count; i++)
3883 stringbuffer[i] = a->data[s->offset + i];
3885 /* terminate string */
3887 stringbuffer[i] = '\0';
3889 return stringbuffer;
3893 /* GetStringChars **************************************************************
3895 Returns a pointer to the array of Unicode characters of the
3896 string. This pointer is valid until ReleaseStringchars() is called.
3898 *******************************************************************************/
3900 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3904 STATISTICS(jniinvokation());
3906 jc = javastring_tou2(str);
3918 return emptyStringJ;
3922 /* ReleaseStringChars **********************************************************
3924 Informs the VM that the native code no longer needs access to
3925 chars. The chars argument is a pointer obtained from string using
3928 *******************************************************************************/
3930 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3932 STATISTICS(jniinvokation());
3934 if (chars == emptyStringJ)
3937 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3941 /* NewStringUTF ****************************************************************
3943 Constructs a new java.lang.String object from an array of UTF-8 characters.
3945 *******************************************************************************/
3947 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3949 java_lang_String *s;
3951 STATISTICS(jniinvokation());
3953 s = javastring_new(utf_new_char(bytes));
3955 return (jstring) NewLocalRef(env, (jobject) s);
3959 /****************** returns the utf8 length in bytes of a string *******************/
3961 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3963 java_lang_String *s = (java_lang_String*) string;
3965 STATISTICS(jniinvokation());
3967 return (jsize) u2_utflength(s->value->data, s->count);
3971 /* GetStringUTFChars ***********************************************************
3973 Returns a pointer to an array of UTF-8 characters of the
3974 string. This array is valid until it is released by
3975 ReleaseStringUTFChars().
3977 *******************************************************************************/
3979 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3983 STATISTICS(jniinvokation());
3991 u = javastring_toutf((java_lang_String *) string, false);
4000 /* ReleaseStringUTFChars *******************************************************
4002 Informs the VM that the native code no longer needs access to
4003 utf. The utf argument is a pointer derived from string using
4004 GetStringUTFChars().
4006 *******************************************************************************/
4008 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4010 STATISTICS(jniinvokation());
4012 /* XXX we don't release utf chars right now, perhaps that should be done
4013 later. Since there is always one reference the garbage collector will
4018 /* Array Operations ***********************************************************/
4020 /* GetArrayLength **************************************************************
4022 Returns the number of elements in the array.
4024 *******************************************************************************/
4026 jsize GetArrayLength(JNIEnv *env, jarray array)
4028 java_arrayheader *a;
4030 STATISTICS(jniinvokation());
4032 a = (java_arrayheader *) array;
4038 /* NewObjectArray **************************************************************
4040 Constructs a new array holding objects in class elementClass. All
4041 elements are initially set to initialElement.
4043 *******************************************************************************/
4045 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4047 java_objectarray *oa;
4050 STATISTICS(jniinvokation());
4053 exceptions_throw_negativearraysizeexception();
4057 oa = builtin_anewarray(length, elementClass);
4062 /* set all elements to initialElement */
4064 for (i = 0; i < length; i++)
4065 oa->data[i] = initialElement;
4067 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4071 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4073 java_objectarray *oa;
4076 STATISTICS(jniinvokation());
4078 oa = (java_objectarray *) array;
4080 if (index >= oa->header.size) {
4081 exceptions_throw_arrayindexoutofboundsexception();
4085 o = oa->data[index];
4087 return NewLocalRef(env, o);
4091 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4093 java_objectarray *oa;
4094 java_objectheader *o;
4096 STATISTICS(jniinvokation());
4098 oa = (java_objectarray *) array;
4099 o = (java_objectheader *) val;
4101 if (index >= oa->header.size) {
4102 exceptions_throw_arrayindexoutofboundsexception();
4106 /* check if the class of value is a subclass of the element class
4109 if (!builtin_canstore(oa, o)) {
4110 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4115 oa->data[index] = val;
4119 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4121 java_booleanarray *ba;
4123 STATISTICS(jniinvokation());
4126 exceptions_throw_negativearraysizeexception();
4130 ba = builtin_newarray_boolean(len);
4132 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4136 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4140 STATISTICS(jniinvokation());
4143 exceptions_throw_negativearraysizeexception();
4147 ba = builtin_newarray_byte(len);
4149 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4153 jcharArray NewCharArray(JNIEnv *env, jsize len)
4157 STATISTICS(jniinvokation());
4160 exceptions_throw_negativearraysizeexception();
4164 ca = builtin_newarray_char(len);
4166 return (jcharArray) NewLocalRef(env, (jobject) ca);
4170 jshortArray NewShortArray(JNIEnv *env, jsize len)
4172 java_shortarray *sa;
4174 STATISTICS(jniinvokation());
4177 exceptions_throw_negativearraysizeexception();
4181 sa = builtin_newarray_short(len);
4183 return (jshortArray) NewLocalRef(env, (jobject) sa);
4187 jintArray NewIntArray(JNIEnv *env, jsize len)
4191 STATISTICS(jniinvokation());
4194 exceptions_throw_negativearraysizeexception();
4198 ia = builtin_newarray_int(len);
4200 return (jintArray) NewLocalRef(env, (jobject) ia);
4204 jlongArray NewLongArray(JNIEnv *env, jsize len)
4208 STATISTICS(jniinvokation());
4211 exceptions_throw_negativearraysizeexception();
4215 la = builtin_newarray_long(len);
4217 return (jlongArray) NewLocalRef(env, (jobject) la);
4221 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4223 java_floatarray *fa;
4225 STATISTICS(jniinvokation());
4228 exceptions_throw_negativearraysizeexception();
4232 fa = builtin_newarray_float(len);
4234 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4238 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4240 java_doublearray *da;
4242 STATISTICS(jniinvokation());
4245 exceptions_throw_negativearraysizeexception();
4249 da = builtin_newarray_double(len);
4251 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4255 /* Get<PrimitiveType>ArrayElements *********************************************
4257 A family of functions that returns the body of the primitive array.
4259 *******************************************************************************/
4261 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4264 java_booleanarray *ba;
4266 STATISTICS(jniinvokation());
4268 ba = (java_booleanarray *) array;
4271 *isCopy = JNI_FALSE;
4277 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4281 STATISTICS(jniinvokation());
4283 ba = (java_bytearray *) array;
4286 *isCopy = JNI_FALSE;
4292 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4296 STATISTICS(jniinvokation());
4298 ca = (java_chararray *) array;
4301 *isCopy = JNI_FALSE;
4307 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4309 java_shortarray *sa;
4311 STATISTICS(jniinvokation());
4313 sa = (java_shortarray *) array;
4316 *isCopy = JNI_FALSE;
4322 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4326 STATISTICS(jniinvokation());
4328 ia = (java_intarray *) array;
4331 *isCopy = JNI_FALSE;
4337 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4341 STATISTICS(jniinvokation());
4343 la = (java_longarray *) array;
4346 *isCopy = JNI_FALSE;
4348 /* We cast this one to prevent a compiler warning on 64-bit
4349 systems since GNU Classpath typedef jlong to long long. */
4351 return (jlong *) la->data;
4355 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4357 java_floatarray *fa;
4359 STATISTICS(jniinvokation());
4361 fa = (java_floatarray *) array;
4364 *isCopy = JNI_FALSE;
4370 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4373 java_doublearray *da;
4375 STATISTICS(jniinvokation());
4377 da = (java_doublearray *) array;
4380 *isCopy = JNI_FALSE;
4386 /* Release<PrimitiveType>ArrayElements *****************************************
4388 A family of functions that informs the VM that the native code no
4389 longer needs access to elems. The elems argument is a pointer
4390 derived from array using the corresponding
4391 Get<PrimitiveType>ArrayElements() function. If necessary, this
4392 function copies back all changes made to elems to the original
4395 *******************************************************************************/
4397 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4398 jboolean *elems, jint mode)
4400 java_booleanarray *ba;
4402 STATISTICS(jniinvokation());
4404 ba = (java_booleanarray *) array;
4406 if (elems != ba->data) {
4409 MCOPY(ba->data, elems, u1, ba->header.size);
4412 MCOPY(ba->data, elems, u1, ba->header.size);
4413 /* XXX TWISTI how should it be freed? */
4416 /* XXX TWISTI how should it be freed? */
4423 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4428 STATISTICS(jniinvokation());
4430 ba = (java_bytearray *) array;
4432 if (elems != ba->data) {
4435 MCOPY(ba->data, elems, s1, ba->header.size);
4438 MCOPY(ba->data, elems, s1, ba->header.size);
4439 /* XXX TWISTI how should it be freed? */
4442 /* XXX TWISTI how should it be freed? */
4449 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4454 STATISTICS(jniinvokation());
4456 ca = (java_chararray *) array;
4458 if (elems != ca->data) {
4461 MCOPY(ca->data, elems, u2, ca->header.size);
4464 MCOPY(ca->data, elems, u2, ca->header.size);
4465 /* XXX TWISTI how should it be freed? */
4468 /* XXX TWISTI how should it be freed? */
4475 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4478 java_shortarray *sa;
4480 STATISTICS(jniinvokation());
4482 sa = (java_shortarray *) array;
4484 if (elems != sa->data) {
4487 MCOPY(sa->data, elems, s2, sa->header.size);
4490 MCOPY(sa->data, elems, s2, sa->header.size);
4491 /* XXX TWISTI how should it be freed? */
4494 /* XXX TWISTI how should it be freed? */
4501 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4506 STATISTICS(jniinvokation());
4508 ia = (java_intarray *) array;
4510 if (elems != ia->data) {
4513 MCOPY(ia->data, elems, s4, ia->header.size);
4516 MCOPY(ia->data, elems, s4, ia->header.size);
4517 /* XXX TWISTI how should it be freed? */
4520 /* XXX TWISTI how should it be freed? */
4527 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4532 STATISTICS(jniinvokation());
4534 la = (java_longarray *) array;
4536 /* We cast this one to prevent a compiler warning on 64-bit
4537 systems since GNU Classpath typedef jlong to long long. */
4539 if ((s8 *) elems != la->data) {
4542 MCOPY(la->data, elems, s8, la->header.size);
4545 MCOPY(la->data, elems, s8, la->header.size);
4546 /* XXX TWISTI how should it be freed? */
4549 /* XXX TWISTI how should it be freed? */
4556 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4559 java_floatarray *fa;
4561 STATISTICS(jniinvokation());
4563 fa = (java_floatarray *) array;
4565 if (elems != fa->data) {
4568 MCOPY(fa->data, elems, float, fa->header.size);
4571 MCOPY(fa->data, elems, float, fa->header.size);
4572 /* XXX TWISTI how should it be freed? */
4575 /* XXX TWISTI how should it be freed? */
4582 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4583 jdouble *elems, jint mode)
4585 java_doublearray *da;
4587 STATISTICS(jniinvokation());
4589 da = (java_doublearray *) array;
4591 if (elems != da->data) {
4594 MCOPY(da->data, elems, double, da->header.size);
4597 MCOPY(da->data, elems, double, da->header.size);
4598 /* XXX TWISTI how should it be freed? */
4601 /* XXX TWISTI how should it be freed? */
4608 /* Get<PrimitiveType>ArrayRegion **********************************************
4610 A family of functions that copies a region of a primitive array
4613 *******************************************************************************/
4615 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4616 jsize len, jboolean *buf)
4618 java_booleanarray *ba;
4620 STATISTICS(jniinvokation());
4622 ba = (java_booleanarray *) array;
4624 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4625 exceptions_throw_arrayindexoutofboundsexception();
4627 MCOPY(buf, &ba->data[start], u1, len);
4631 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4636 STATISTICS(jniinvokation());
4638 ba = (java_bytearray *) array;
4640 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4641 exceptions_throw_arrayindexoutofboundsexception();
4643 MCOPY(buf, &ba->data[start], s1, len);
4647 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4652 STATISTICS(jniinvokation());
4654 ca = (java_chararray *) array;
4656 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4657 exceptions_throw_arrayindexoutofboundsexception();
4659 MCOPY(buf, &ca->data[start], u2, len);
4663 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4664 jsize len, jshort *buf)
4666 java_shortarray *sa;
4668 STATISTICS(jniinvokation());
4670 sa = (java_shortarray *) array;
4672 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4673 exceptions_throw_arrayindexoutofboundsexception();
4675 MCOPY(buf, &sa->data[start], s2, len);
4679 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4684 STATISTICS(jniinvokation());
4686 ia = (java_intarray *) array;
4688 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4689 exceptions_throw_arrayindexoutofboundsexception();
4691 MCOPY(buf, &ia->data[start], s4, len);
4695 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4700 STATISTICS(jniinvokation());
4702 la = (java_longarray *) array;
4704 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4705 exceptions_throw_arrayindexoutofboundsexception();
4707 MCOPY(buf, &la->data[start], s8, len);
4711 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4712 jsize len, jfloat *buf)
4714 java_floatarray *fa;
4716 STATISTICS(jniinvokation());
4718 fa = (java_floatarray *) array;
4720 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4721 exceptions_throw_arrayindexoutofboundsexception();
4723 MCOPY(buf, &fa->data[start], float, len);
4727 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4728 jsize len, jdouble *buf)
4730 java_doublearray *da;
4732 STATISTICS(jniinvokation());
4734 da = (java_doublearray *) array;
4736 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4737 exceptions_throw_arrayindexoutofboundsexception();
4739 MCOPY(buf, &da->data[start], double, len);
4743 /* Set<PrimitiveType>ArrayRegion **********************************************
4745 A family of functions that copies back a region of a primitive
4746 array from a buffer.
4748 *******************************************************************************/
4750 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4751 jsize len, jboolean *buf)
4753 java_booleanarray *ba;
4755 STATISTICS(jniinvokation());
4757 ba = (java_booleanarray *) array;
4759 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4760 exceptions_throw_arrayindexoutofboundsexception();
4762 MCOPY(&ba->data[start], buf, u1, len);
4766 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4771 STATISTICS(jniinvokation());
4773 ba = (java_bytearray *) array;
4775 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4776 exceptions_throw_arrayindexoutofboundsexception();
4778 MCOPY(&ba->data[start], buf, s1, len);
4782 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4787 STATISTICS(jniinvokation());
4789 ca = (java_chararray *) array;
4791 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4792 exceptions_throw_arrayindexoutofboundsexception();
4794 MCOPY(&ca->data[start], buf, u2, len);
4798 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4799 jsize len, jshort *buf)
4801 java_shortarray *sa;
4803 STATISTICS(jniinvokation());
4805 sa = (java_shortarray *) array;
4807 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4808 exceptions_throw_arrayindexoutofboundsexception();
4810 MCOPY(&sa->data[start], buf, s2, len);
4814 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4819 STATISTICS(jniinvokation());
4821 ia = (java_intarray *) array;
4823 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4824 exceptions_throw_arrayindexoutofboundsexception();
4826 MCOPY(&ia->data[start], buf, s4, len);
4830 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4835 STATISTICS(jniinvokation());
4837 la = (java_longarray *) array;
4839 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4840 exceptions_throw_arrayindexoutofboundsexception();
4842 MCOPY(&la->data[start], buf, s8, len);
4846 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4847 jsize len, jfloat *buf)
4849 java_floatarray *fa;
4851 STATISTICS(jniinvokation());
4853 fa = (java_floatarray *) array;
4855 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4856 exceptions_throw_arrayindexoutofboundsexception();
4858 MCOPY(&fa->data[start], buf, float, len);
4862 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4863 jsize len, jdouble *buf)
4865 java_doublearray *da;
4867 STATISTICS(jniinvokation());
4869 da = (java_doublearray *) array;
4871 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4872 exceptions_throw_arrayindexoutofboundsexception();
4874 MCOPY(&da->data[start], buf, double, len);
4878 /* Registering Native Methods *************************************************/
4880 /* RegisterNatives *************************************************************
4882 Registers native methods with the class specified by the clazz
4883 argument. The methods parameter specifies an array of
4884 JNINativeMethod structures that contain the names, signatures, and
4885 function pointers of the native methods. The nMethods parameter
4886 specifies the number of native methods in the array.
4888 *******************************************************************************/
4890 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4893 STATISTICS(jniinvokation());
4895 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4901 /* UnregisterNatives ***********************************************************
4903 Unregisters native methods of a class. The class goes back to the
4904 state before it was linked or registered with its native method
4907 This function should not be used in normal native code. Instead, it
4908 provides special programs a way to reload and relink native
4911 *******************************************************************************/
4913 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4915 STATISTICS(jniinvokation());
4917 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4919 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4925 /* Monitor Operations *********************************************************/
4927 /* MonitorEnter ****************************************************************
4929 Enters the monitor associated with the underlying Java object
4932 *******************************************************************************/
4934 jint MonitorEnter(JNIEnv *env, jobject obj)
4936 STATISTICS(jniinvokation());
4939 exceptions_throw_nullpointerexception();
4943 #if defined(USE_THREADS)
4944 builtin_monitorenter(obj);
4951 /* MonitorExit *****************************************************************
4953 The current thread must be the owner of the monitor associated with
4954 the underlying Java object referred to by obj. The thread
4955 decrements the counter indicating the number of times it has
4956 entered this monitor. If the value of the counter becomes zero, the
4957 current thread releases the monitor.
4959 *******************************************************************************/
4961 jint MonitorExit(JNIEnv *env, jobject obj)
4963 STATISTICS(jniinvokation());
4966 exceptions_throw_nullpointerexception();
4970 #if defined(USE_THREADS)
4971 builtin_monitorexit(obj);
4978 /* JavaVM Interface ***********************************************************/
4980 /* GetJavaVM *******************************************************************
4982 Returns the Java VM interface (used in the Invocation API)
4983 associated with the current thread. The result is placed at the
4984 location pointed to by the second argument, vm.
4986 *******************************************************************************/
4988 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4990 STATISTICS(jniinvokation());
4992 *vm = (JavaVM *) _Jv_jvm;
4998 /* GetStringRegion *************************************************************
5000 Copies len number of Unicode characters beginning at offset start
5001 to the given buffer buf.
5003 Throws StringIndexOutOfBoundsException on index overflow.
5005 *******************************************************************************/
5007 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
5009 java_lang_String *s;
5012 STATISTICS(jniinvokation());
5014 s = (java_lang_String *) str;
5017 if ((start < 0) || (len < 0) || (start > s->count) ||
5018 (start + len > s->count)) {
5019 exceptions_throw_stringindexoutofboundsexception();
5023 MCOPY(buf, &ca->data[start], u2, len);
5027 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5029 STATISTICS(jniinvokation());
5031 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5035 /* GetPrimitiveArrayCritical ***************************************************
5037 Obtain a direct pointer to array elements.
5039 *******************************************************************************/
5041 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5046 ba = (java_bytearray *) array;
5048 /* do the same as Kaffe does */
5050 bp = GetByteArrayElements(env, ba, isCopy);
5056 /* ReleasePrimitiveArrayCritical ***********************************************
5058 No specific documentation.
5060 *******************************************************************************/
5062 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5065 STATISTICS(jniinvokation());
5067 /* do the same as Kaffe does */
5069 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5073 /* GetStringCritical ***********************************************************
5075 The semantics of these two functions are similar to the existing
5076 Get/ReleaseStringChars functions.
5078 *******************************************************************************/
5080 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5082 STATISTICS(jniinvokation());
5084 return GetStringChars(env, string, isCopy);
5088 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5090 STATISTICS(jniinvokation());
5092 ReleaseStringChars(env, string, cstring);
5096 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5098 STATISTICS(jniinvokation());
5100 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5106 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5108 STATISTICS(jniinvokation());
5110 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5114 /* NewGlobalRef ****************************************************************
5116 Creates a new global reference to the object referred to by the obj
5119 *******************************************************************************/
5121 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
5123 java_objectheader *o;
5124 java_lang_Integer *refcount;
5125 java_objectheader *newval;
5127 STATISTICS(jniinvokation());
5129 #if defined(USE_THREADS)
5130 builtin_monitorenter(*global_ref_table);
5133 o = vm_call_method(getmid, *global_ref_table, lobj);
5135 refcount = (java_lang_Integer *) o;
5137 if (refcount == NULL) {
5138 newval = native_new_and_init_int(class_java_lang_Integer, 1);
5140 if (newval == NULL) {
5141 #if defined(USE_THREADS)
5142 builtin_monitorexit(*global_ref_table);
5147 (void) vm_call_method(putmid, *global_ref_table, lobj, newval);
5150 /* we can access the object itself, as we are in a
5151 synchronized section */
5156 #if defined(USE_THREADS)
5157 builtin_monitorexit(*global_ref_table);
5164 /* DeleteGlobalRef *************************************************************
5166 Deletes the global reference pointed to by globalRef.
5168 *******************************************************************************/
5170 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5172 java_objectheader *o;
5173 java_lang_Integer *refcount;
5176 STATISTICS(jniinvokation());
5178 #if defined(USE_THREADS)
5179 builtin_monitorenter(*global_ref_table);
5182 o = vm_call_method(getmid, *global_ref_table, globalRef);
5184 refcount = (java_lang_Integer *) o;
5186 if (refcount == NULL) {
5187 log_text("JNI-DeleteGlobalRef: unable to find global reference");
5191 /* we can access the object itself, as we are in a synchronized
5194 val = refcount->value - 1;
5197 (void) vm_call_method(removemid, *global_ref_table, refcount);
5200 /* we do not create a new object, but set the new value into
5203 refcount->value = val;
5206 #if defined(USE_THREADS)
5207 builtin_monitorexit(*global_ref_table);
5212 /* ExceptionCheck **************************************************************
5214 Returns JNI_TRUE when there is a pending exception; otherwise,
5217 *******************************************************************************/
5219 jboolean ExceptionCheck(JNIEnv *env)
5221 STATISTICS(jniinvokation());
5223 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5227 /* New JNI 1.4 functions ******************************************************/
5229 /* NewDirectByteBuffer *********************************************************
5231 Allocates and returns a direct java.nio.ByteBuffer referring to the
5232 block of memory starting at the memory address address and
5233 extending capacity bytes.
5235 *******************************************************************************/
5237 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5239 java_objectheader *nbuf;
5240 #if SIZEOF_VOID_P == 8
5241 gnu_classpath_Pointer64 *paddress;
5243 gnu_classpath_Pointer32 *paddress;
5246 STATISTICS(jniinvokation());
5248 /* alocate a gnu.classpath.Pointer{32,64} object */
5250 #if SIZEOF_VOID_P == 8
5251 if (!(paddress = (gnu_classpath_Pointer64 *)
5252 builtin_new(class_gnu_classpath_Pointer64)))
5254 if (!(paddress = (gnu_classpath_Pointer32 *)
5255 builtin_new(class_gnu_classpath_Pointer32)))
5259 /* fill gnu.classpath.Pointer{32,64} with address */
5261 paddress->data = (ptrint) address;
5263 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5265 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5266 (jmethodID) dbbirw_init, NULL, paddress,
5267 (jint) capacity, (jint) capacity, (jint) 0);
5269 /* add local reference and return the value */
5271 return NewLocalRef(env, nbuf);
5275 /* GetDirectBufferAddress ******************************************************
5277 Fetches and returns the starting address of the memory region
5278 referenced by the given direct java.nio.Buffer.
5280 *******************************************************************************/
5282 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5284 java_nio_DirectByteBufferImpl *nbuf;
5285 #if SIZEOF_VOID_P == 8
5286 gnu_classpath_Pointer64 *address;
5288 gnu_classpath_Pointer32 *address;
5291 STATISTICS(jniinvokation());
5293 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5296 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5298 #if SIZEOF_VOID_P == 8
5299 address = (gnu_classpath_Pointer64 *) nbuf->address;
5301 address = (gnu_classpath_Pointer32 *) nbuf->address;
5304 return (void *) address->data;
5308 /* GetDirectBufferCapacity *****************************************************
5310 Fetches and returns the capacity in bytes of the memory region
5311 referenced by the given direct java.nio.Buffer.
5313 *******************************************************************************/
5315 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5317 java_nio_Buffer *nbuf;
5319 STATISTICS(jniinvokation());
5321 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5324 nbuf = (java_nio_Buffer *) buf;
5326 return (jlong) nbuf->cap;
5330 /* DestroyJavaVM ***************************************************************
5332 Unloads a Java VM and reclaims its resources. Only the main thread
5333 can unload the VM. The system waits until the main thread is only
5334 remaining user thread before it destroys the VM.
5336 *******************************************************************************/
5338 jint DestroyJavaVM(JavaVM *vm)
5342 STATISTICS(jniinvokation());
5344 status = vm_destroy(vm);
5350 /* AttachCurrentThread *********************************************************
5352 Attaches the current thread to a Java VM. Returns a JNI interface
5353 pointer in the JNIEnv argument.
5355 Trying to attach a thread that is already attached is a no-op.
5357 A native thread cannot be attached simultaneously to two Java VMs.
5359 When a thread is attached to the VM, the context class loader is
5360 the bootstrap loader.
5362 *******************************************************************************/
5364 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5366 STATISTICS(jniinvokation());
5368 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5370 #if !defined(HAVE___THREAD)
5371 /* cacao_thread_attach();*/
5373 #error "No idea how to implement that. Perhaps Stefan knows"
5382 jint DetachCurrentThread(JavaVM *vm)
5384 STATISTICS(jniinvokation());
5386 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5392 /* GetEnv **********************************************************************
5394 If the current thread is not attached to the VM, sets *env to NULL,
5395 and returns JNI_EDETACHED. If the specified version is not
5396 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5397 sets *env to the appropriate interface, and returns JNI_OK.
5399 *******************************************************************************/
5401 jint GetEnv(JavaVM *vm, void **env, jint version)
5403 STATISTICS(jniinvokation());
5405 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
5406 if (thread_getself() == NULL) {
5409 return JNI_EDETACHED;
5413 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5414 (version == JNI_VERSION_1_4)) {
5420 #if defined(ENABLE_JVMTI)
5421 if (version == JVMTI_VERSION_1_0) {
5422 *env = (void *) new_jvmtienv();
5431 return JNI_EVERSION;
5436 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5438 STATISTICS(jniinvokation());
5440 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5446 /* JNI invocation table *******************************************************/
5448 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5454 AttachCurrentThread,
5455 DetachCurrentThread,
5457 AttachCurrentThreadAsDaemon
5461 /* JNI function table *********************************************************/
5463 struct JNINativeInterface _Jv_JNINativeInterface = {
5472 FromReflectedMethod,
5493 EnsureLocalCapacity,
5536 CallNonvirtualObjectMethod,
5537 CallNonvirtualObjectMethodV,
5538 CallNonvirtualObjectMethodA,
5539 CallNonvirtualBooleanMethod,
5540 CallNonvirtualBooleanMethodV,
5541 CallNonvirtualBooleanMethodA,
5542 CallNonvirtualByteMethod,
5543 CallNonvirtualByteMethodV,
5544 CallNonvirtualByteMethodA,
5545 CallNonvirtualCharMethod,
5546 CallNonvirtualCharMethodV,
5547 CallNonvirtualCharMethodA,
5548 CallNonvirtualShortMethod,
5549 CallNonvirtualShortMethodV,
5550 CallNonvirtualShortMethodA,
5551 CallNonvirtualIntMethod,
5552 CallNonvirtualIntMethodV,
5553 CallNonvirtualIntMethodA,
5554 CallNonvirtualLongMethod,
5555 CallNonvirtualLongMethodV,
5556 CallNonvirtualLongMethodA,
5557 CallNonvirtualFloatMethod,
5558 CallNonvirtualFloatMethodV,
5559 CallNonvirtualFloatMethodA,
5560 CallNonvirtualDoubleMethod,
5561 CallNonvirtualDoubleMethodV,
5562 CallNonvirtualDoubleMethodA,
5563 CallNonvirtualVoidMethod,
5564 CallNonvirtualVoidMethodV,
5565 CallNonvirtualVoidMethodA,
5590 CallStaticObjectMethod,
5591 CallStaticObjectMethodV,
5592 CallStaticObjectMethodA,
5593 CallStaticBooleanMethod,
5594 CallStaticBooleanMethodV,
5595 CallStaticBooleanMethodA,
5596 CallStaticByteMethod,
5597 CallStaticByteMethodV,
5598 CallStaticByteMethodA,
5599 CallStaticCharMethod,
5600 CallStaticCharMethodV,
5601 CallStaticCharMethodA,
5602 CallStaticShortMethod,
5603 CallStaticShortMethodV,
5604 CallStaticShortMethodA,
5605 CallStaticIntMethod,
5606 CallStaticIntMethodV,
5607 CallStaticIntMethodA,
5608 CallStaticLongMethod,
5609 CallStaticLongMethodV,
5610 CallStaticLongMethodA,
5611 CallStaticFloatMethod,
5612 CallStaticFloatMethodV,
5613 CallStaticFloatMethodA,
5614 CallStaticDoubleMethod,
5615 CallStaticDoubleMethodV,
5616 CallStaticDoubleMethodA,
5617 CallStaticVoidMethod,
5618 CallStaticVoidMethodV,
5619 CallStaticVoidMethodA,
5623 GetStaticObjectField,
5624 GetStaticBooleanField,
5627 GetStaticShortField,
5630 GetStaticFloatField,
5631 GetStaticDoubleField,
5632 SetStaticObjectField,
5633 SetStaticBooleanField,
5636 SetStaticShortField,
5639 SetStaticFloatField,
5640 SetStaticDoubleField,
5650 ReleaseStringUTFChars,
5655 GetObjectArrayElement,
5656 SetObjectArrayElement,
5667 GetBooleanArrayElements,
5668 GetByteArrayElements,
5669 GetCharArrayElements,
5670 GetShortArrayElements,
5671 GetIntArrayElements,
5672 GetLongArrayElements,
5673 GetFloatArrayElements,
5674 GetDoubleArrayElements,
5676 ReleaseBooleanArrayElements,
5677 ReleaseByteArrayElements,
5678 ReleaseCharArrayElements,
5679 ReleaseShortArrayElements,
5680 ReleaseIntArrayElements,
5681 ReleaseLongArrayElements,
5682 ReleaseFloatArrayElements,
5683 ReleaseDoubleArrayElements,
5685 GetBooleanArrayRegion,
5688 GetShortArrayRegion,
5691 GetFloatArrayRegion,
5692 GetDoubleArrayRegion,
5693 SetBooleanArrayRegion,
5696 SetShortArrayRegion,
5699 SetFloatArrayRegion,
5700 SetDoubleArrayRegion,
5710 /* new JNI 1.2 functions */
5715 GetPrimitiveArrayCritical,
5716 ReleasePrimitiveArrayCritical,
5719 ReleaseStringCritical,
5722 DeleteWeakGlobalRef,
5726 /* new JNI 1.4 functions */
5728 NewDirectByteBuffer,
5729 GetDirectBufferAddress,
5730 GetDirectBufferCapacity
5734 /* Invocation API Functions ***************************************************/
5736 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5738 Returns a default configuration for the Java VM.
5740 *******************************************************************************/
5742 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5744 JavaVMInitArgs *_vm_args;
5746 _vm_args = (JavaVMInitArgs *) vm_args;
5748 /* GNU classpath currently supports JNI 1.2 */
5750 switch (_vm_args->version) {
5751 case JNI_VERSION_1_1:
5752 _vm_args->version = JNI_VERSION_1_1;
5755 case JNI_VERSION_1_2:
5756 case JNI_VERSION_1_4:
5757 _vm_args->ignoreUnrecognized = JNI_FALSE;
5758 _vm_args->options = NULL;
5759 _vm_args->nOptions = 0;
5770 /* JNI_GetCreatedJavaVMs *******************************************************
5772 Returns all Java VMs that have been created. Pointers to VMs are written in
5773 the buffer vmBuf in the order they are created. At most bufLen number of
5774 entries will be written. The total number of created VMs is returned in
5777 *******************************************************************************/
5779 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5781 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5787 /* JNI_CreateJavaVM ************************************************************
5789 Loads and initializes a Java VM. The current thread becomes the main thread.
5790 Sets the env argument to the JNI interface pointer of the main thread.
5792 *******************************************************************************/
5794 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5796 JavaVMInitArgs *_vm_args;
5799 localref_table *lrt;
5801 /* get the arguments for the new JVM */
5803 _vm_args = (JavaVMInitArgs *) vm_args;
5805 /* get the VM and Env tables (must be set before vm_create) */
5807 env = NEW(_Jv_JNIEnv);
5808 env->env = &_Jv_JNINativeInterface;
5810 /* XXX Set the global variable. Maybe we should do that differently. */
5814 /* actually create the JVM */
5816 if (!vm_create(_vm_args))
5819 /* create and fill a JavaVM structure */
5821 jvm = NEW(_Jv_JavaVM);
5822 jvm->functions = &_Jv_JNIInvokeInterface;
5824 /* XXX Set the global variable. Maybe we should do that differently. */
5828 /* setup the local ref table (must be created after vm_create) */
5830 lrt = GCNEW(localref_table);
5832 lrt->capacity = LOCALREFTABLE_CAPACITY;
5834 lrt->localframes = 1;
5835 lrt->prev = LOCALREFTABLE;
5837 /* clear the references array (memset is faster then a for-loop) */
5839 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5841 LOCALREFTABLE = lrt;
5843 /* now return the values */
5845 *p_vm = (JavaVM *) jvm;
5846 *p_env = (void *) env;
5853 * These are local overrides for various environment variables in Emacs.
5854 * Please do not remove this and leave it at the end of the file, where
5855 * Emacs will automagically detect them.
5856 * ---------------------------------------------------------------------
5859 * indent-tabs-mode: t
5863 * vim:noexpandtab:sw=4:ts=4: