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 4909 2006-05-13 23:10:21Z edwin $
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 /* hashsize must be power of 2 */
114 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
116 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
119 /* direct buffer stuff ********************************************************/
121 static classinfo *class_java_nio_Buffer;
122 static classinfo *class_java_nio_DirectByteBufferImpl;
123 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
124 #if SIZEOF_VOID_P == 8
125 static classinfo *class_gnu_classpath_Pointer64;
127 static classinfo *class_gnu_classpath_Pointer32;
130 static methodinfo *dbbirw_init;
133 /* local reference table ******************************************************/
135 #if !defined(USE_THREADS)
136 localref_table *_no_threads_localref_table;
140 /* accessing instance fields macros *******************************************/
142 #define SET_FIELD(o,type,f,value) \
143 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
145 #define GET_FIELD(o,type,f) \
146 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
149 /* some forward declarations **************************************************/
151 jobject NewLocalRef(JNIEnv *env, jobject ref);
152 jint EnsureLocalCapacity(JNIEnv* env, jint capacity);
155 /* jni_init ********************************************************************
157 Initialize the JNI subsystem.
159 *******************************************************************************/
163 /* create global ref hashtable */
165 hashtable_global_ref = NEW(hashtable);
167 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
170 /* direct buffer stuff */
172 if (!(class_java_nio_Buffer =
173 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
174 !link_class(class_java_nio_Buffer))
177 if (!(class_java_nio_DirectByteBufferImpl =
178 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
179 !link_class(class_java_nio_DirectByteBufferImpl))
182 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
183 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
184 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
188 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
190 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
193 #if SIZEOF_VOID_P == 8
194 if (!(class_gnu_classpath_Pointer64 =
195 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
196 !link_class(class_gnu_classpath_Pointer64))
199 if (!(class_gnu_classpath_Pointer32 =
200 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
201 !link_class(class_gnu_classpath_Pointer32))
209 /* _Jv_jni_vmargs_from_objectarray *********************************************
213 *******************************************************************************/
215 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
218 java_objectarray *params)
220 java_objectheader *param;
222 typedesc *paramtypes;
228 paramcount = descr->paramcount;
229 paramtypes = descr->paramtypes;
231 /* if method is non-static fill first block and skip `this' pointer */
237 vmargs[0].type = TYPE_ADR;
238 vmargs[0].data.l = (u8) (ptrint) o;
245 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
246 switch (paramtypes->type) {
247 /* primitive types */
252 param = params->data[j];
257 /* internally used data type */
258 vmargs[i].type = paramtypes->type;
260 /* convert the value according to its declared type */
262 c = param->vftbl->class;
264 switch (paramtypes->decltype) {
265 case PRIMITIVETYPE_BOOLEAN:
266 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
267 value = (s8) ((java_lang_Boolean *) param)->value;
271 vmargs[i].data.l = value;
274 case PRIMITIVETYPE_BYTE:
275 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
276 value = (s8) ((java_lang_Byte *) param)->value;
280 vmargs[i].data.l = value;
283 case PRIMITIVETYPE_CHAR:
284 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
285 value = (s8) ((java_lang_Character *) param)->value;
289 vmargs[i].data.l = value;
292 case PRIMITIVETYPE_SHORT:
293 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
294 value = (s8) ((java_lang_Short *) param)->value;
295 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
296 value = (s8) ((java_lang_Byte *) param)->value;
300 vmargs[i].data.l = value;
303 case PRIMITIVETYPE_INT:
304 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
305 value = (s8) ((java_lang_Integer *) param)->value;
306 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
307 value = (s8) ((java_lang_Short *) param)->value;
308 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
309 value = (s8) ((java_lang_Byte *) param)->value;
313 vmargs[i].data.l = value;
316 case PRIMITIVETYPE_LONG:
317 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
318 value = (s8) ((java_lang_Long *) param)->value;
319 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
320 value = (s8) ((java_lang_Integer *) param)->value;
321 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
322 value = (s8) ((java_lang_Short *) param)->value;
323 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
324 value = (s8) ((java_lang_Byte *) param)->value;
328 vmargs[i].data.l = value;
331 case PRIMITIVETYPE_FLOAT:
332 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
333 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
338 case PRIMITIVETYPE_DOUBLE:
339 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
340 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
341 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
342 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
353 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
356 if (params->data[j] != 0) {
357 if (paramtypes->arraydim > 0) {
358 if (!builtin_arrayinstanceof(params->data[j], c))
362 if (!builtin_instanceof(params->data[j], c))
367 vmargs[i].type = TYPE_ADR;
368 vmargs[i].data.l = (u8) (ptrint) params->data[j];
377 /* *rettype = descr->returntype.decltype; */
382 exceptions_throw_illegalargumentexception();
387 /* _Jv_jni_CallObjectMethod ****************************************************
389 Internal function to call Java Object methods.
391 *******************************************************************************/
393 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
395 methodinfo *m, va_list ap)
398 java_objectheader *ro;
400 STATISTICS(jniinvokation());
403 exceptions_throw_nullpointerexception();
407 /* Class initialization is done by the JIT compiler. This is ok
408 since a static method always belongs to the declaring class. */
410 if (m->flags & ACC_STATIC) {
411 /* For static methods we reset the object. */
416 /* for convenience */
421 /* For instance methods we make a virtual function table lookup. */
423 resm = method_vftbl_lookup(vftbl, m);
426 STATISTICS(jnicallXmethodnvokation());
428 ro = vm_call_method_valist(resm, o, ap);
434 /* _Jv_jni_CallObjectMethodA ***************************************************
436 Internal function to call Java Object methods.
438 *******************************************************************************/
440 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
442 methodinfo *m, jvalue *args)
445 java_objectheader *ro;
447 STATISTICS(jniinvokation());
450 exceptions_throw_nullpointerexception();
454 /* Class initialization is done by the JIT compiler. This is ok
455 since a static method always belongs to the declaring class. */
457 if (m->flags & ACC_STATIC) {
458 /* For static methods we reset the object. */
463 /* for convenience */
468 /* For instance methods we make a virtual function table lookup. */
470 resm = method_vftbl_lookup(vftbl, m);
473 STATISTICS(jnicallXmethodnvokation());
475 ro = vm_call_method_jvalue(resm, o, args);
481 /* _Jv_jni_CallIntMethod *******************************************************
483 Internal function to call Java integer class methods (boolean,
484 byte, char, short, int).
486 *******************************************************************************/
488 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
489 methodinfo *m, va_list ap)
494 STATISTICS(jniinvokation());
497 exceptions_throw_nullpointerexception();
501 /* Class initialization is done by the JIT compiler. This is ok
502 since a static method always belongs to the declaring class. */
504 if (m->flags & ACC_STATIC) {
505 /* For static methods we reset the object. */
510 /* for convenience */
515 /* For instance methods we make a virtual function table lookup. */
517 resm = method_vftbl_lookup(vftbl, m);
520 STATISTICS(jnicallXmethodnvokation());
522 i = vm_call_method_int_valist(resm, o, ap);
528 /* _Jv_jni_CallIntMethodA ******************************************************
530 Internal function to call Java integer class methods (boolean,
531 byte, char, short, int).
533 *******************************************************************************/
535 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
536 methodinfo *m, jvalue *args)
541 STATISTICS(jniinvokation());
544 exceptions_throw_nullpointerexception();
548 /* Class initialization is done by the JIT compiler. This is ok
549 since a static method always belongs to the declaring class. */
551 if (m->flags & ACC_STATIC) {
552 /* For static methods we reset the object. */
557 /* for convenience */
562 /* For instance methods we make a virtual function table lookup. */
564 resm = method_vftbl_lookup(vftbl, m);
567 STATISTICS(jnicallXmethodnvokation());
569 i = vm_call_method_int_jvalue(resm, o, args);
575 /* _Jv_jni_CallLongMethod ******************************************************
577 Internal function to call Java long methods.
579 *******************************************************************************/
581 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
582 methodinfo *m, va_list ap)
587 STATISTICS(jniinvokation());
590 exceptions_throw_nullpointerexception();
594 /* Class initialization is done by the JIT compiler. This is ok
595 since a static method always belongs to the declaring class. */
597 if (m->flags & ACC_STATIC) {
598 /* For static methods we reset the object. */
603 /* for convenience */
608 /* For instance methods we make a virtual function table lookup. */
610 resm = method_vftbl_lookup(vftbl, m);
613 STATISTICS(jnicallXmethodnvokation());
615 l = vm_call_method_long_valist(resm, o, ap);
621 /* _Jv_jni_CallFloatMethod *****************************************************
623 Internal function to call Java float methods.
625 *******************************************************************************/
627 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
628 methodinfo *m, va_list ap)
633 /* Class initialization is done by the JIT compiler. This is ok
634 since a static method always belongs to the declaring class. */
636 if (m->flags & ACC_STATIC) {
637 /* For static methods we reset the object. */
642 /* for convenience */
647 /* For instance methods we make a virtual function table lookup. */
649 resm = method_vftbl_lookup(vftbl, m);
652 STATISTICS(jnicallXmethodnvokation());
654 f = vm_call_method_float_valist(resm, o, ap);
660 /* _Jv_jni_CallDoubleMethod ****************************************************
662 Internal function to call Java double methods.
664 *******************************************************************************/
666 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
667 methodinfo *m, va_list ap)
672 /* Class initialization is done by the JIT compiler. This is ok
673 since a static method always belongs to the declaring class. */
675 if (m->flags & ACC_STATIC) {
676 /* For static methods we reset the object. */
681 /* for convenience */
686 /* For instance methods we make a virtual function table lookup. */
688 resm = method_vftbl_lookup(vftbl, m);
691 d = vm_call_method_double_valist(resm, o, ap);
697 /* _Jv_jni_CallVoidMethod ******************************************************
699 Internal function to call Java void methods.
701 *******************************************************************************/
703 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
704 methodinfo *m, va_list ap)
709 exceptions_throw_nullpointerexception();
713 /* Class initialization is done by the JIT compiler. This is ok
714 since a static method always belongs to the declaring class. */
716 if (m->flags & ACC_STATIC) {
717 /* For static methods we reset the object. */
722 /* for convenience */
727 /* For instance methods we make a virtual function table lookup. */
729 resm = method_vftbl_lookup(vftbl, m);
732 STATISTICS(jnicallXmethodnvokation());
734 (void) vm_call_method_valist(resm, o, ap);
738 /* _Jv_jni_CallVoidMethodA *****************************************************
740 Internal function to call Java void methods.
742 *******************************************************************************/
744 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
745 methodinfo *m, jvalue *args)
750 exceptions_throw_nullpointerexception();
754 /* Class initialization is done by the JIT compiler. This is ok
755 since a static method always belongs to the declaring class. */
757 if (m->flags & ACC_STATIC) {
758 /* For static methods we reset the object. */
763 /* for convenience */
768 /* For instance methods we make a virtual function table lookup. */
770 resm = method_vftbl_lookup(vftbl, m);
773 STATISTICS(jnicallXmethodnvokation());
775 (void) vm_call_method_jvalue(resm, o, args);
779 /* _Jv_jni_invokeNative ********************************************************
781 Invoke a method on the given object with the given arguments.
783 For instance methods OBJ must be != NULL and the method is looked up
784 in the vftbl of the object.
786 For static methods, OBJ is ignored.
788 *******************************************************************************/
790 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
791 java_objectarray *params)
795 java_objectheader *ro;
800 exceptions_throw_nullpointerexception();
804 argcount = m->parseddesc->paramcount;
805 paramcount = argcount;
807 /* if method is non-static, remove the `this' pointer */
809 if (!(m->flags & ACC_STATIC))
812 /* For instance methods the object has to be an instance of the
813 class the method belongs to. For static methods the obj
814 parameter is ignored. */
816 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
818 new_exception_message(string_java_lang_IllegalArgumentException,
819 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
823 /* check if we got the right number of arguments */
825 if (((params == NULL) && (paramcount != 0)) ||
826 (params && (params->header.size != paramcount)))
829 new_exception(string_java_lang_IllegalArgumentException);
833 /* for instance methods we need an object */
835 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
837 new_exception_message(string_java_lang_NullPointerException,
838 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
842 /* for static methods, zero object to make subsequent code simpler */
843 if (m->flags & ACC_STATIC)
847 /* for instance methods we must do a vftbl lookup */
848 resm = method_vftbl_lookup(o->vftbl, m);
851 /* for static methods, just for convenience */
855 vmargs = MNEW(vm_arg, argcount);
857 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
860 switch (resm->parseddesc->returntype.decltype) {
862 (void) vm_call_method_vmarg(resm, argcount, vmargs);
867 case PRIMITIVETYPE_BOOLEAN: {
869 java_lang_Boolean *bo;
871 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
873 ro = builtin_new(class_java_lang_Boolean);
875 /* setting the value of the object direct */
877 bo = (java_lang_Boolean *) ro;
882 case PRIMITIVETYPE_BYTE: {
886 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
888 ro = builtin_new(class_java_lang_Byte);
890 /* setting the value of the object direct */
892 bo = (java_lang_Byte *) ro;
897 case PRIMITIVETYPE_CHAR: {
899 java_lang_Character *co;
901 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
903 ro = builtin_new(class_java_lang_Character);
905 /* setting the value of the object direct */
907 co = (java_lang_Character *) ro;
912 case PRIMITIVETYPE_SHORT: {
916 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
918 ro = builtin_new(class_java_lang_Short);
920 /* setting the value of the object direct */
922 so = (java_lang_Short *) ro;
927 case PRIMITIVETYPE_INT: {
929 java_lang_Integer *io;
931 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
933 ro = builtin_new(class_java_lang_Integer);
935 /* setting the value of the object direct */
937 io = (java_lang_Integer *) ro;
942 case PRIMITIVETYPE_LONG: {
946 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
948 ro = builtin_new(class_java_lang_Long);
950 /* setting the value of the object direct */
952 lo = (java_lang_Long *) ro;
957 case PRIMITIVETYPE_FLOAT: {
961 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
963 ro = builtin_new(class_java_lang_Float);
965 /* setting the value of the object direct */
967 fo = (java_lang_Float *) ro;
972 case PRIMITIVETYPE_DOUBLE: {
974 java_lang_Double *_do;
976 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
978 ro = builtin_new(class_java_lang_Double);
980 /* setting the value of the object direct */
982 _do = (java_lang_Double *) ro;
988 ro = vm_call_method_vmarg(resm, argcount, vmargs);
992 /* if this happens the exception has already been set by
993 fill_callblock_from_objectarray */
995 MFREE(vmargs, vm_arg, argcount);
1000 MFREE(vmargs, vm_arg, argcount);
1002 if (*exceptionptr) {
1003 java_objectheader *cause;
1005 cause = *exceptionptr;
1007 /* clear exception pointer, we are calling JIT code again */
1009 *exceptionptr = NULL;
1012 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1013 (java_lang_Throwable *) cause);
1020 /* GetVersion ******************************************************************
1022 Returns the major version number in the higher 16 bits and the
1023 minor version number in the lower 16 bits.
1025 *******************************************************************************/
1027 jint GetVersion(JNIEnv *env)
1029 STATISTICS(jniinvokation());
1031 /* we support JNI 1.4 */
1033 return JNI_VERSION_1_4;
1037 /* Class Operations ***********************************************************/
1039 /* DefineClass *****************************************************************
1041 Loads a class from a buffer of raw class data. The buffer
1042 containing the raw class data is not referenced by the VM after the
1043 DefineClass call returns, and it may be discarded if desired.
1045 *******************************************************************************/
1047 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1048 const jbyte *buf, jsize bufLen)
1050 java_lang_ClassLoader *cl;
1051 java_lang_String *s;
1055 STATISTICS(jniinvokation());
1057 cl = (java_lang_ClassLoader *) loader;
1058 s = javastring_new_from_ascii(name);
1059 ba = (java_bytearray *) buf;
1061 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1064 return (jclass) NewLocalRef(env, (jobject) c);
1068 /* FindClass *******************************************************************
1070 This function loads a locally-defined class. It searches the
1071 directories and zip files specified by the CLASSPATH environment
1072 variable for the class with the specified name.
1074 *******************************************************************************/
1076 jclass FindClass(JNIEnv *env, const char *name)
1082 STATISTICS(jniinvokation());
1084 u = utf_new_char_classname((char *) name);
1086 /* Check stacktrace for classloader, if one found use it,
1087 otherwise use the system classloader. */
1089 /* Quote from the JNI documentation:
1091 In the Java 2 Platform, FindClass locates the class loader
1092 associated with the current native method. If the native code
1093 belongs to a system class, no class loader will be
1094 involved. Otherwise, the proper class loader will be invoked to
1095 load and link the named class. When FindClass is called through
1096 the Invocation Interface, there is no current native method or
1097 its associated class loader. In that case, the result of
1098 ClassLoader.getBaseClassLoader is used." */
1100 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1101 /* these JITs support stacktraces, and so does the interpreter */
1103 cc = stacktrace_getCurrentClass();
1105 # if defined(ENABLE_INTRP)
1106 /* the interpreter supports stacktraces, even if the JIT does not */
1109 cc = stacktrace_getCurrentClass();
1115 /* if no Java method was found, use the system classloader */
1118 c = load_class_from_sysloader(u);
1120 c = load_class_from_classloader(u, cc->classloader);
1128 return (jclass) NewLocalRef(env, (jobject) c);
1132 /* GetSuperclass ***************************************************************
1134 If clazz represents any class other than the class Object, then
1135 this function returns the object that represents the superclass of
1136 the class specified by clazz.
1138 *******************************************************************************/
1140 jclass GetSuperclass(JNIEnv *env, jclass sub)
1144 STATISTICS(jniinvokation());
1146 c = ((classinfo *) sub)->super.cls;
1151 return (jclass) NewLocalRef(env, (jobject) c);
1155 /* IsAssignableFrom ************************************************************
1157 Determines whether an object of sub can be safely cast to sup.
1159 *******************************************************************************/
1161 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1163 STATISTICS(jniinvokation());
1165 return Java_java_lang_VMClass_isAssignableFrom(env,
1167 (java_lang_Class *) sup,
1168 (java_lang_Class *) sub);
1172 /* Throw ***********************************************************************
1174 Causes a java.lang.Throwable object to be thrown.
1176 *******************************************************************************/
1178 jint Throw(JNIEnv *env, jthrowable obj)
1180 STATISTICS(jniinvokation());
1182 *exceptionptr = (java_objectheader *) obj;
1188 /* ThrowNew ********************************************************************
1190 Constructs an exception object from the specified class with the
1191 message specified by message and causes that exception to be
1194 *******************************************************************************/
1196 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1198 java_lang_Throwable *o;
1199 java_lang_String *s;
1201 STATISTICS(jniinvokation());
1203 s = (java_lang_String *) javastring_new_from_ascii(msg);
1205 /* instantiate exception object */
1207 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1213 *exceptionptr = (java_objectheader *) o;
1219 /* ExceptionOccurred ***********************************************************
1221 Determines if an exception is being thrown. The exception stays
1222 being thrown until either the native code calls ExceptionClear(),
1223 or the Java code handles the exception.
1225 *******************************************************************************/
1227 jthrowable ExceptionOccurred(JNIEnv *env)
1229 java_objectheader *e;
1231 STATISTICS(jniinvokation());
1235 return NewLocalRef(env, (jthrowable) e);
1239 /* ExceptionDescribe ***********************************************************
1241 Prints an exception and a backtrace of the stack to a system
1242 error-reporting channel, such as stderr. This is a convenience
1243 routine provided for debugging.
1245 *******************************************************************************/
1247 void ExceptionDescribe(JNIEnv *env)
1249 java_objectheader *e;
1252 STATISTICS(jniinvokation());
1257 /* clear exception, because we are calling jit code again */
1259 *exceptionptr = NULL;
1261 /* get printStackTrace method from exception class */
1263 m = class_resolveclassmethod(e->vftbl->class,
1264 utf_printStackTrace,
1270 /* XXX what should we do? */
1273 /* print the stacktrace */
1275 (void) vm_call_method(m, e);
1280 /* ExceptionClear **************************************************************
1282 Clears any exception that is currently being thrown. If no
1283 exception is currently being thrown, this routine has no effect.
1285 *******************************************************************************/
1287 void ExceptionClear(JNIEnv *env)
1289 STATISTICS(jniinvokation());
1291 *exceptionptr = NULL;
1295 /* FatalError ******************************************************************
1297 Raises a fatal error and does not expect the VM to recover. This
1298 function does not return.
1300 *******************************************************************************/
1302 void FatalError(JNIEnv *env, const char *msg)
1304 STATISTICS(jniinvokation());
1306 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1310 /* PushLocalFrame **************************************************************
1312 Creates a new local reference frame, in which at least a given
1313 number of local references can be created.
1315 *******************************************************************************/
1317 jint PushLocalFrame(JNIEnv* env, jint capacity)
1320 localref_table *lrt;
1321 localref_table *nlrt;
1323 STATISTICS(jniinvokation());
1328 /* Allocate new local reference table on Java heap. Calculate the
1329 additional memory we have to allocate. */
1331 if (capacity > LOCALREFTABLE_CAPACITY)
1332 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1336 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1341 /* get current local reference table from thread */
1343 lrt = LOCALREFTABLE;
1345 /* Set up the new local reference table and add it to the local
1348 nlrt->capacity = capacity;
1350 nlrt->localframes = lrt->localframes + 1;
1353 /* store new local reference table in thread */
1355 LOCALREFTABLE = nlrt;
1361 /* PopLocalFrame ***************************************************************
1363 Pops off the current local reference frame, frees all the local
1364 references, and returns a local reference in the previous local
1365 reference frame for the given result object.
1367 *******************************************************************************/
1369 jobject PopLocalFrame(JNIEnv* env, jobject result)
1371 localref_table *lrt;
1372 localref_table *plrt;
1375 STATISTICS(jniinvokation());
1377 /* get current local reference table from thread */
1379 lrt = LOCALREFTABLE;
1381 localframes = lrt->localframes;
1383 /* Don't delete the top local frame, as this one is allocated in
1384 the native stub on the stack and is freed automagically on
1387 if (localframes == 1)
1388 return NewLocalRef(env, result);
1390 /* release all current local frames */
1392 for (; localframes >= 1; localframes--) {
1393 /* get previous frame */
1397 /* clear all reference entries */
1399 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1403 /* set new local references table */
1408 /* store new local reference table in thread */
1410 LOCALREFTABLE = lrt;
1412 /* add local reference and return the value */
1414 return NewLocalRef(env, result);
1418 /* DeleteLocalRef **************************************************************
1420 Deletes the local reference pointed to by localRef.
1422 *******************************************************************************/
1424 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1426 java_objectheader *o;
1427 localref_table *lrt;
1430 STATISTICS(jniinvokation());
1432 o = (java_objectheader *) localRef;
1434 /* get local reference table (thread specific) */
1436 lrt = LOCALREFTABLE;
1438 /* go through all local frames */
1440 for (; lrt != NULL; lrt = lrt->prev) {
1442 /* and try to remove the reference */
1444 for (i = 0; i < lrt->capacity; i++) {
1445 if (lrt->refs[i] == o) {
1446 lrt->refs[i] = NULL;
1454 /* this should not happen */
1456 /* if (opt_checkjni) */
1457 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1458 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1462 /* IsSameObject ****************************************************************
1464 Tests whether two references refer to the same Java object.
1466 *******************************************************************************/
1468 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1470 STATISTICS(jniinvokation());
1479 /* NewLocalRef *****************************************************************
1481 Creates a new local reference that refers to the same object as ref.
1483 *******************************************************************************/
1485 jobject NewLocalRef(JNIEnv *env, jobject ref)
1487 localref_table *lrt;
1490 STATISTICS(jniinvokation());
1495 /* get local reference table (thread specific) */
1497 lrt = LOCALREFTABLE;
1499 /* Check if we have space for the requested reference? No,
1500 allocate a new frame. This is actually not what the spec says,
1501 but for compatibility reasons... */
1503 if (lrt->used == lrt->capacity) {
1504 if (EnsureLocalCapacity(env, 16) != 0)
1507 /* get the new local reference table */
1509 lrt = LOCALREFTABLE;
1512 /* insert the reference */
1514 for (i = 0; i < lrt->capacity; i++) {
1515 if (lrt->refs[i] == NULL) {
1516 lrt->refs[i] = (java_objectheader *) ref;
1523 /* should not happen, just to be sure */
1527 /* keep compiler happy */
1533 /* EnsureLocalCapacity *********************************************************
1535 Ensures that at least a given number of local references can be
1536 created in the current thread
1538 *******************************************************************************/
1540 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1542 localref_table *lrt;
1544 log_text("JNI-Call: EnsureLocalCapacity");
1546 STATISTICS(jniinvokation());
1548 /* get local reference table (thread specific) */
1550 lrt = LOCALREFTABLE;
1552 /* check if capacity elements are available in the local references table */
1554 if ((lrt->used + capacity) > lrt->capacity)
1555 return PushLocalFrame(env, capacity);
1561 /* AllocObject *****************************************************************
1563 Allocates a new Java object without invoking any of the
1564 constructors for the object. Returns a reference to the object.
1566 *******************************************************************************/
1568 jobject AllocObject(JNIEnv *env, jclass clazz)
1571 java_objectheader *o;
1573 STATISTICS(jniinvokation());
1575 c = (classinfo *) clazz;
1577 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1579 new_exception_utfmessage(string_java_lang_InstantiationException,
1586 return NewLocalRef(env, o);
1590 /* NewObject *******************************************************************
1592 Programmers place all arguments that are to be passed to the
1593 constructor immediately following the methodID
1594 argument. NewObject() accepts these arguments and passes them to
1595 the Java method that the programmer wishes to invoke.
1597 *******************************************************************************/
1599 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1601 java_objectheader *o;
1605 STATISTICS(jniinvokation());
1607 m = (methodinfo *) methodID;
1611 o = builtin_new(clazz);
1616 /* call constructor */
1618 va_start(ap, methodID);
1619 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1622 return NewLocalRef(env, o);
1626 /* NewObjectV ******************************************************************
1628 Programmers place all arguments that are to be passed to the
1629 constructor in an args argument of type va_list that immediately
1630 follows the methodID argument. NewObjectV() accepts these
1631 arguments, and, in turn, passes them to the Java method that the
1632 programmer wishes to invoke.
1634 *******************************************************************************/
1636 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1638 java_objectheader *o;
1641 STATISTICS(jniinvokation());
1643 m = (methodinfo *) methodID;
1647 o = builtin_new(clazz);
1652 /* call constructor */
1654 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1656 return NewLocalRef(env, o);
1660 /* NewObjectA *****************************************************************
1662 Programmers place all arguments that are to be passed to the
1663 constructor in an args array of jvalues that immediately follows
1664 the methodID argument. NewObjectA() accepts the arguments in this
1665 array, and, in turn, passes them to the Java method that the
1666 programmer wishes to invoke.
1668 *******************************************************************************/
1670 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1672 java_objectheader *o;
1675 STATISTICS(jniinvokation());
1677 m = (methodinfo *) methodID;
1681 o = builtin_new(clazz);
1686 /* call constructor */
1688 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1690 return NewLocalRef(env, o);
1694 /* GetObjectClass **************************************************************
1696 Returns the class of an object.
1698 *******************************************************************************/
1700 jclass GetObjectClass(JNIEnv *env, jobject obj)
1702 java_objectheader *o;
1705 STATISTICS(jniinvokation());
1707 o = (java_objectheader *) obj;
1709 if ((o == NULL) || (o->vftbl == NULL))
1712 c = o->vftbl->class;
1714 return (jclass) NewLocalRef(env, (jobject) c);
1718 /* IsInstanceOf ****************************************************************
1720 Tests whether an object is an instance of a class.
1722 *******************************************************************************/
1724 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1726 STATISTICS(jniinvokation());
1728 return Java_java_lang_VMClass_isInstance(env,
1730 (java_lang_Class *) clazz,
1731 (java_lang_Object *) obj);
1735 /* Reflection Support *********************************************************/
1737 /* FromReflectedMethod *********************************************************
1739 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1740 object to a method ID.
1742 *******************************************************************************/
1744 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1750 STATISTICS(jniinvokation());
1755 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1756 java_lang_reflect_Method *rm;
1758 rm = (java_lang_reflect_Method *) method;
1759 c = (classinfo *) (rm->declaringClass);
1762 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1763 java_lang_reflect_Constructor *rc;
1765 rc = (java_lang_reflect_Constructor *) method;
1766 c = (classinfo *) (rc->clazz);
1772 mi = &(c->methods[slot]);
1774 return (jmethodID) mi;
1778 /* FromReflectedField **********************************************************
1780 Converts a java.lang.reflect.Field to a field ID.
1782 *******************************************************************************/
1784 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1786 java_lang_reflect_Field *rf;
1790 STATISTICS(jniinvokation());
1792 rf = (java_lang_reflect_Field *) field;
1797 c = (classinfo *) rf->declaringClass;
1799 f = &(c->fields[rf->slot]);
1801 return (jfieldID) f;
1805 /* ToReflectedMethod ***********************************************************
1807 Converts a method ID derived from cls to an instance of the
1808 java.lang.reflect.Method class or to an instance of the
1809 java.lang.reflect.Constructor class.
1811 *******************************************************************************/
1813 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1815 STATISTICS(jniinvokation());
1817 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1823 /* ToReflectedField ************************************************************
1825 Converts a field ID derived from cls to an instance of the
1826 java.lang.reflect.Field class.
1828 *******************************************************************************/
1830 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1833 STATISTICS(jniinvokation());
1835 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1841 /* Calling Instance Methods ***************************************************/
1843 /* GetMethodID *****************************************************************
1845 Returns the method ID for an instance (nonstatic) method of a class
1846 or interface. The method may be defined in one of the clazz's
1847 superclasses and inherited by clazz. The method is determined by
1848 its name and signature.
1850 GetMethodID() causes an uninitialized class to be initialized.
1852 *******************************************************************************/
1854 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1862 STATISTICS(jniinvokation());
1864 c = (classinfo *) clazz;
1869 if (!(c->state & CLASS_INITIALIZED))
1870 if (!initialize_class(c))
1873 /* try to get the method of the class or one of it's superclasses */
1875 uname = utf_new_char((char *) name);
1876 udesc = utf_new_char((char *) sig);
1878 m = class_resolvemethod(clazz, uname, udesc);
1880 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1881 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1886 return (jmethodID) m;
1890 /* JNI-functions for calling instance methods *********************************/
1892 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1894 java_objectheader *o;
1896 java_objectheader *ret;
1899 o = (java_objectheader *) obj;
1900 m = (methodinfo *) methodID;
1902 va_start(ap, methodID);
1903 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1906 return NewLocalRef(env, ret);
1910 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1912 java_objectheader *o;
1914 java_objectheader *ret;
1916 o = (java_objectheader *) obj;
1917 m = (methodinfo *) methodID;
1919 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1921 return NewLocalRef(env, ret);
1925 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1927 java_objectheader *o;
1929 java_objectheader *ret;
1931 o = (java_objectheader *) obj;
1932 m = (methodinfo *) methodID;
1934 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1936 return NewLocalRef(env, ret);
1940 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1942 java_objectheader *o;
1947 o = (java_objectheader *) obj;
1948 m = (methodinfo *) methodID;
1950 va_start(ap, methodID);
1951 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1958 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1960 java_objectheader *o;
1964 o = (java_objectheader *) obj;
1965 m = (methodinfo *) methodID;
1967 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1973 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1975 java_objectheader *o;
1979 o = (java_objectheader *) obj;
1980 m = (methodinfo *) methodID;
1982 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1988 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1990 java_objectheader *o;
1995 o = (java_objectheader *) obj;
1996 m = (methodinfo *) methodID;
1998 va_start(ap, methodID);
1999 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2006 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2008 java_objectheader *o;
2012 o = (java_objectheader *) obj;
2013 m = (methodinfo *) methodID;
2015 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2021 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2023 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2029 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2031 java_objectheader *o;
2036 o = (java_objectheader *) obj;
2037 m = (methodinfo *) methodID;
2039 va_start(ap, methodID);
2040 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2047 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2049 java_objectheader *o;
2053 o = (java_objectheader *) obj;
2054 m = (methodinfo *) methodID;
2056 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2062 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2064 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2070 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2072 java_objectheader *o;
2077 o = (java_objectheader *) obj;
2078 m = (methodinfo *) methodID;
2080 va_start(ap, methodID);
2081 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2088 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2090 java_objectheader *o;
2094 o = (java_objectheader *) obj;
2095 m = (methodinfo *) methodID;
2097 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2103 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2105 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2112 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2114 java_objectheader *o;
2119 o = (java_objectheader *) obj;
2120 m = (methodinfo *) methodID;
2122 va_start(ap, methodID);
2123 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2130 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2132 java_objectheader *o;
2136 o = (java_objectheader *) obj;
2137 m = (methodinfo *) methodID;
2139 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2145 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2147 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2154 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2156 java_objectheader *o;
2161 o = (java_objectheader *) obj;
2162 m = (methodinfo *) methodID;
2164 va_start(ap, methodID);
2165 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2172 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2174 java_objectheader *o;
2178 o = (java_objectheader *) obj;
2179 m = (methodinfo *) methodID;
2181 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2187 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2189 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2196 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2198 java_objectheader *o;
2203 o = (java_objectheader *) obj;
2204 m = (methodinfo *) methodID;
2206 va_start(ap, methodID);
2207 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2214 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2216 java_objectheader *o;
2220 o = (java_objectheader *) obj;
2221 m = (methodinfo *) methodID;
2223 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2229 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2231 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2238 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2240 java_objectheader *o;
2245 o = (java_objectheader *) obj;
2246 m = (methodinfo *) methodID;
2248 va_start(ap, methodID);
2249 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2256 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2258 java_objectheader *o;
2262 o = (java_objectheader *) obj;
2263 m = (methodinfo *) methodID;
2265 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2271 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2273 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2280 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2282 java_objectheader *o;
2286 o = (java_objectheader *) obj;
2287 m = (methodinfo *) methodID;
2289 va_start(ap, methodID);
2290 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2295 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2297 java_objectheader *o;
2300 o = (java_objectheader *) obj;
2301 m = (methodinfo *) methodID;
2303 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2307 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2309 java_objectheader *o;
2312 o = (java_objectheader *) obj;
2313 m = (methodinfo *) methodID;
2315 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2320 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2322 java_objectheader *o;
2325 java_objectheader *r;
2328 o = (java_objectheader *) obj;
2329 c = (classinfo *) clazz;
2330 m = (methodinfo *) methodID;
2332 va_start(ap, methodID);
2333 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2336 return NewLocalRef(env, r);
2340 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2342 java_objectheader *o;
2345 java_objectheader *r;
2347 o = (java_objectheader *) obj;
2348 c = (classinfo *) clazz;
2349 m = (methodinfo *) methodID;
2351 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2353 return NewLocalRef(env, r);
2357 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2359 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2361 return NewLocalRef(env, NULL);
2366 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2368 java_objectheader *o;
2374 o = (java_objectheader *) obj;
2375 c = (classinfo *) clazz;
2376 m = (methodinfo *) methodID;
2378 va_start(ap, methodID);
2379 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2386 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2388 java_objectheader *o;
2393 o = (java_objectheader *) obj;
2394 c = (classinfo *) clazz;
2395 m = (methodinfo *) methodID;
2397 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2403 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2405 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2411 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2413 java_objectheader *o;
2419 o = (java_objectheader *) obj;
2420 c = (classinfo *) clazz;
2421 m = (methodinfo *) methodID;
2423 va_start(ap, methodID);
2424 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2431 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2433 java_objectheader *o;
2438 o = (java_objectheader *) obj;
2439 c = (classinfo *) clazz;
2440 m = (methodinfo *) methodID;
2442 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2448 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2450 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2457 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2459 java_objectheader *o;
2465 o = (java_objectheader *) obj;
2466 c = (classinfo *) clazz;
2467 m = (methodinfo *) methodID;
2469 va_start(ap, methodID);
2470 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2477 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2479 java_objectheader *o;
2484 o = (java_objectheader *) obj;
2485 c = (classinfo *) clazz;
2486 m = (methodinfo *) methodID;
2488 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2494 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2496 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2503 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2505 java_objectheader *o;
2511 o = (java_objectheader *) obj;
2512 c = (classinfo *) clazz;
2513 m = (methodinfo *) methodID;
2515 va_start(ap, methodID);
2516 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2523 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2525 java_objectheader *o;
2530 o = (java_objectheader *) obj;
2531 c = (classinfo *) clazz;
2532 m = (methodinfo *) methodID;
2534 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2540 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2542 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2549 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2551 java_objectheader *o;
2557 o = (java_objectheader *) obj;
2558 c = (classinfo *) clazz;
2559 m = (methodinfo *) methodID;
2561 va_start(ap, methodID);
2562 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2569 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2571 java_objectheader *o;
2576 o = (java_objectheader *) obj;
2577 c = (classinfo *) clazz;
2578 m = (methodinfo *) methodID;
2580 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2586 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2588 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2595 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2597 java_objectheader *o;
2603 o = (java_objectheader *) obj;
2604 c = (classinfo *) clazz;
2605 m = (methodinfo *) methodID;
2607 va_start(ap, methodID);
2608 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2615 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2617 java_objectheader *o;
2622 o = (java_objectheader *) obj;
2623 c = (classinfo *) clazz;
2624 m = (methodinfo *) methodID;
2626 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2632 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2634 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2641 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2643 java_objectheader *o;
2649 o = (java_objectheader *) obj;
2650 c = (classinfo *) clazz;
2651 m = (methodinfo *) methodID;
2653 va_start(ap, methodID);
2654 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2661 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2663 java_objectheader *o;
2668 o = (java_objectheader *) obj;
2669 c = (classinfo *) clazz;
2670 m = (methodinfo *) methodID;
2672 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2678 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2680 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2687 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2689 java_objectheader *o;
2695 o = (java_objectheader *) obj;
2696 c = (classinfo *) clazz;
2697 m = (methodinfo *) methodID;
2699 va_start(ap, methodID);
2700 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2707 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2709 java_objectheader *o;
2714 o = (java_objectheader *) obj;
2715 c = (classinfo *) clazz;
2716 m = (methodinfo *) methodID;
2718 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2724 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2726 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2733 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2735 java_objectheader *o;
2740 o = (java_objectheader *) obj;
2741 c = (classinfo *) clazz;
2742 m = (methodinfo *) methodID;
2744 va_start(ap, methodID);
2745 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2750 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2752 java_objectheader *o;
2756 o = (java_objectheader *) obj;
2757 c = (classinfo *) clazz;
2758 m = (methodinfo *) methodID;
2760 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2764 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2766 java_objectheader *o;
2770 o = (java_objectheader *) obj;
2771 c = (classinfo *) clazz;
2772 m = (methodinfo *) methodID;
2774 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2778 /* Accessing Fields of Objects ************************************************/
2780 /* GetFieldID ******************************************************************
2782 Returns the field ID for an instance (nonstatic) field of a
2783 class. The field is specified by its name and signature. The
2784 Get<type>Field and Set<type>Field families of accessor functions
2785 use field IDs to retrieve object fields.
2787 *******************************************************************************/
2789 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2796 STATISTICS(jniinvokation());
2798 uname = utf_new_char((char *) name);
2799 udesc = utf_new_char((char *) sig);
2801 f = class_findfield(clazz, uname, udesc);
2804 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2806 return (jfieldID) f;
2810 /* Get<type>Field Routines *****************************************************
2812 This family of accessor routines returns the value of an instance
2813 (nonstatic) field of an object. The field to access is specified by
2814 a field ID obtained by calling GetFieldID().
2816 *******************************************************************************/
2818 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2820 java_objectheader *o;
2822 STATISTICS(jniinvokation());
2824 o = GET_FIELD(obj, java_objectheader*, fieldID);
2826 return NewLocalRef(env, o);
2830 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2834 STATISTICS(jniinvokation());
2836 i = GET_FIELD(obj, s4, fieldID);
2838 return (jboolean) i;
2842 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2846 STATISTICS(jniinvokation());
2848 i = GET_FIELD(obj, s4, fieldID);
2854 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2858 STATISTICS(jniinvokation());
2860 i = GET_FIELD(obj, s4, fieldID);
2866 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2870 STATISTICS(jniinvokation());
2872 i = GET_FIELD(obj, s4, fieldID);
2878 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2880 java_objectheader *o;
2884 STATISTICS(jniinvokation());
2886 o = (java_objectheader *) obj;
2887 f = (fieldinfo *) fieldID;
2889 i = GET_FIELD(o, s4, f);
2895 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2899 STATISTICS(jniinvokation());
2901 l = GET_FIELD(obj, s8, fieldID);
2907 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2911 STATISTICS(jniinvokation());
2913 f = GET_FIELD(obj, float, fieldID);
2919 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2923 STATISTICS(jniinvokation());
2925 d = GET_FIELD(obj, double, fieldID);
2931 /* Set<type>Field Routines *****************************************************
2933 This family of accessor routines sets the value of an instance
2934 (nonstatic) field of an object. The field to access is specified by
2935 a field ID obtained by calling GetFieldID().
2937 *******************************************************************************/
2939 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2941 STATISTICS(jniinvokation());
2943 SET_FIELD(obj, java_objectheader*, fieldID, value);
2947 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2949 STATISTICS(jniinvokation());
2951 SET_FIELD(obj, s4, fieldID, value);
2955 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2957 STATISTICS(jniinvokation());
2959 SET_FIELD(obj, s4, fieldID, value);
2963 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2965 STATISTICS(jniinvokation());
2967 SET_FIELD(obj, s4, fieldID, value);
2971 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2973 STATISTICS(jniinvokation());
2975 SET_FIELD(obj, s4, fieldID, value);
2979 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2981 STATISTICS(jniinvokation());
2983 SET_FIELD(obj, s4, fieldID, value);
2987 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2989 STATISTICS(jniinvokation());
2991 SET_FIELD(obj, s8, fieldID, value);
2995 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
2997 STATISTICS(jniinvokation());
2999 SET_FIELD(obj, float, fieldID, value);
3003 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
3005 STATISTICS(jniinvokation());
3007 SET_FIELD(obj, double, fieldID, value);
3011 /* Calling Static Methods *****************************************************/
3013 /* GetStaticMethodID ***********************************************************
3015 Returns the method ID for a static method of a class. The method is
3016 specified by its name and signature.
3018 GetStaticMethodID() causes an uninitialized class to be
3021 *******************************************************************************/
3023 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3031 STATISTICS(jniinvokation());
3033 c = (classinfo *) clazz;
3038 if (!(c->state & CLASS_INITIALIZED))
3039 if (!initialize_class(c))
3042 /* try to get the static method of the class */
3044 uname = utf_new_char((char *) name);
3045 udesc = utf_new_char((char *) sig);
3047 m = class_resolvemethod(c, uname, udesc);
3049 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3050 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3055 return (jmethodID) m;
3059 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3062 java_objectheader *o;
3065 m = (methodinfo *) methodID;
3067 va_start(ap, methodID);
3068 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3071 return NewLocalRef(env, o);
3075 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3078 java_objectheader *o;
3080 m = (methodinfo *) methodID;
3082 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3084 return NewLocalRef(env, o);
3088 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3091 java_objectheader *o;
3093 m = (methodinfo *) methodID;
3095 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3097 return NewLocalRef(env, o);
3101 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3107 m = (methodinfo *) methodID;
3109 va_start(ap, methodID);
3110 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3117 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3122 m = (methodinfo *) methodID;
3124 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3130 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3132 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3138 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3144 m = (methodinfo *) methodID;
3146 va_start(ap, methodID);
3147 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3154 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3159 m = (methodinfo *) methodID;
3161 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3167 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3169 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3175 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3181 m = (methodinfo *) methodID;
3183 va_start(ap, methodID);
3184 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3191 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3196 m = (methodinfo *) methodID;
3198 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3204 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3206 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3212 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3218 m = (methodinfo *) methodID;
3220 va_start(ap, methodID);
3221 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3228 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3233 m = (methodinfo *) methodID;
3235 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3241 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3243 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3249 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3255 m = (methodinfo *) methodID;
3257 va_start(ap, methodID);
3258 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3265 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3270 m = (methodinfo *) methodID;
3272 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3278 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3280 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3286 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3292 m = (methodinfo *) methodID;
3294 va_start(ap, methodID);
3295 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3302 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3308 m = (methodinfo *) methodID;
3310 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3316 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3318 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3325 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3331 m = (methodinfo *) methodID;
3333 va_start(ap, methodID);
3334 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3341 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3346 m = (methodinfo *) methodID;
3348 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3354 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3356 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3362 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3368 m = (methodinfo *) methodID;
3370 va_start(ap, methodID);
3371 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3378 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3383 m = (methodinfo *) methodID;
3385 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3391 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3393 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3399 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3404 m = (methodinfo *) methodID;
3406 va_start(ap, methodID);
3407 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3412 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3416 m = (methodinfo *) methodID;
3418 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3422 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3426 m = (methodinfo *) methodID;
3428 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3432 /* Accessing Static Fields ****************************************************/
3434 /* GetStaticFieldID ************************************************************
3436 Returns the field ID for a static field of a class. The field is
3437 specified by its name and signature. The GetStatic<type>Field and
3438 SetStatic<type>Field families of accessor functions use field IDs
3439 to retrieve static fields.
3441 *******************************************************************************/
3443 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3447 STATISTICS(jniinvokation());
3449 f = class_findfield(clazz,
3450 utf_new_char((char *) name),
3451 utf_new_char((char *) sig));
3454 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3456 return (jfieldID) f;
3460 /* GetStatic<type>Field ********************************************************
3462 This family of accessor routines returns the value of a static
3465 *******************************************************************************/
3467 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3472 STATISTICS(jniinvokation());
3474 c = (classinfo *) clazz;
3475 f = (fieldinfo *) fieldID;
3477 if (!(c->state & CLASS_INITIALIZED))
3478 if (!initialize_class(c))
3481 return NewLocalRef(env, f->value.a);
3485 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3490 STATISTICS(jniinvokation());
3492 c = (classinfo *) clazz;
3493 f = (fieldinfo *) fieldID;
3495 if (!(c->state & CLASS_INITIALIZED))
3496 if (!initialize_class(c))
3503 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3508 STATISTICS(jniinvokation());
3510 c = (classinfo *) clazz;
3511 f = (fieldinfo *) fieldID;
3513 if (!(c->state & CLASS_INITIALIZED))
3514 if (!initialize_class(c))
3521 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3526 STATISTICS(jniinvokation());
3528 c = (classinfo *) clazz;
3529 f = (fieldinfo *) fieldID;
3531 if (!(c->state & CLASS_INITIALIZED))
3532 if (!initialize_class(c))
3539 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3544 STATISTICS(jniinvokation());
3546 c = (classinfo *) clazz;
3547 f = (fieldinfo *) fieldID;
3549 if (!(c->state & CLASS_INITIALIZED))
3550 if (!initialize_class(c))
3557 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3562 STATISTICS(jniinvokation());
3564 c = (classinfo *) clazz;
3565 f = (fieldinfo *) fieldID;
3567 if (!(c->state & CLASS_INITIALIZED))
3568 if (!initialize_class(c))
3575 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3580 STATISTICS(jniinvokation());
3582 c = (classinfo *) clazz;
3583 f = (fieldinfo *) fieldID;
3585 if (!(c->state & CLASS_INITIALIZED))
3586 if (!initialize_class(c))
3593 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3598 STATISTICS(jniinvokation());
3600 c = (classinfo *) clazz;
3601 f = (fieldinfo *) fieldID;
3603 if (!(c->state & CLASS_INITIALIZED))
3604 if (!initialize_class(c))
3611 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3616 STATISTICS(jniinvokation());
3618 c = (classinfo *) clazz;
3619 f = (fieldinfo *) fieldID;
3621 if (!(c->state & CLASS_INITIALIZED))
3622 if (!initialize_class(c))
3629 /* SetStatic<type>Field *******************************************************
3631 This family of accessor routines sets the value of a static field
3634 *******************************************************************************/
3636 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3641 STATISTICS(jniinvokation());
3643 c = (classinfo *) clazz;
3644 f = (fieldinfo *) fieldID;
3646 if (!(c->state & CLASS_INITIALIZED))
3647 if (!initialize_class(c))
3654 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3659 STATISTICS(jniinvokation());
3661 c = (classinfo *) clazz;
3662 f = (fieldinfo *) fieldID;
3664 if (!(c->state & CLASS_INITIALIZED))
3665 if (!initialize_class(c))
3672 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3677 STATISTICS(jniinvokation());
3679 c = (classinfo *) clazz;
3680 f = (fieldinfo *) fieldID;
3682 if (!(c->state & CLASS_INITIALIZED))
3683 if (!initialize_class(c))
3690 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3695 STATISTICS(jniinvokation());
3697 c = (classinfo *) clazz;
3698 f = (fieldinfo *) fieldID;
3700 if (!(c->state & CLASS_INITIALIZED))
3701 if (!initialize_class(c))
3708 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3713 STATISTICS(jniinvokation());
3715 c = (classinfo *) clazz;
3716 f = (fieldinfo *) fieldID;
3718 if (!(c->state & CLASS_INITIALIZED))
3719 if (!initialize_class(c))
3726 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3731 STATISTICS(jniinvokation());
3733 c = (classinfo *) clazz;
3734 f = (fieldinfo *) fieldID;
3736 if (!(c->state & CLASS_INITIALIZED))
3737 if (!initialize_class(c))
3744 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3749 STATISTICS(jniinvokation());
3751 c = (classinfo *) clazz;
3752 f = (fieldinfo *) fieldID;
3754 if (!(c->state & CLASS_INITIALIZED))
3755 if (!initialize_class(c))
3762 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3767 STATISTICS(jniinvokation());
3769 c = (classinfo *) clazz;
3770 f = (fieldinfo *) fieldID;
3772 if (!(c->state & CLASS_INITIALIZED))
3773 if (!initialize_class(c))
3780 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3785 STATISTICS(jniinvokation());
3787 c = (classinfo *) clazz;
3788 f = (fieldinfo *) fieldID;
3790 if (!(c->state & CLASS_INITIALIZED))
3791 if (!initialize_class(c))
3798 /* String Operations **********************************************************/
3800 /* NewString *******************************************************************
3802 Create new java.lang.String object from an array of Unicode
3805 *******************************************************************************/
3807 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3809 java_lang_String *s;
3813 STATISTICS(jniinvokation());
3815 s = (java_lang_String *) builtin_new(class_java_lang_String);
3816 a = builtin_newarray_char(len);
3818 /* javastring or characterarray could not be created */
3823 for (i = 0; i < len; i++)
3824 a->data[i] = buf[i];
3830 return (jstring) NewLocalRef(env, (jobject) s);
3834 static jchar emptyStringJ[]={0,0};
3836 /* GetStringLength *************************************************************
3838 Returns the length (the count of Unicode characters) of a Java
3841 *******************************************************************************/
3843 jsize GetStringLength(JNIEnv *env, jstring str)
3845 return ((java_lang_String *) str)->count;
3849 /******************** convertes javastring to u2-array ****************************/
3851 u2 *javastring_tou2(jstring so)
3853 java_lang_String *s;
3858 STATISTICS(jniinvokation());
3860 s = (java_lang_String *) so;
3870 /* allocate memory */
3872 stringbuffer = MNEW(u2, s->count + 1);
3876 for (i = 0; i < s->count; i++)
3877 stringbuffer[i] = a->data[s->offset + i];
3879 /* terminate string */
3881 stringbuffer[i] = '\0';
3883 return stringbuffer;
3887 /* GetStringChars **************************************************************
3889 Returns a pointer to the array of Unicode characters of the
3890 string. This pointer is valid until ReleaseStringchars() is called.
3892 *******************************************************************************/
3894 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3898 STATISTICS(jniinvokation());
3900 jc = javastring_tou2(str);
3912 return emptyStringJ;
3916 /* ReleaseStringChars **********************************************************
3918 Informs the VM that the native code no longer needs access to
3919 chars. The chars argument is a pointer obtained from string using
3922 *******************************************************************************/
3924 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3926 STATISTICS(jniinvokation());
3928 if (chars == emptyStringJ)
3931 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3935 /* NewStringUTF ****************************************************************
3937 Constructs a new java.lang.String object from an array of UTF-8 characters.
3939 *******************************************************************************/
3941 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3943 java_lang_String *s;
3945 STATISTICS(jniinvokation());
3947 s = javastring_new(utf_new_char(bytes));
3949 return (jstring) NewLocalRef(env, (jobject) s);
3953 /****************** returns the utf8 length in bytes of a string *******************/
3955 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3957 java_lang_String *s = (java_lang_String*) string;
3959 STATISTICS(jniinvokation());
3961 return (jsize) u2_utflength(s->value->data, s->count);
3965 /* GetStringUTFChars ***********************************************************
3967 Returns a pointer to an array of UTF-8 characters of the
3968 string. This array is valid until it is released by
3969 ReleaseStringUTFChars().
3971 *******************************************************************************/
3973 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3977 STATISTICS(jniinvokation());
3985 u = javastring_toutf((java_lang_String *) string, false);
3994 /* ReleaseStringUTFChars *******************************************************
3996 Informs the VM that the native code no longer needs access to
3997 utf. The utf argument is a pointer derived from string using
3998 GetStringUTFChars().
4000 *******************************************************************************/
4002 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4004 STATISTICS(jniinvokation());
4006 /* XXX we don't release utf chars right now, perhaps that should be done
4007 later. Since there is always one reference the garbage collector will
4012 /* Array Operations ***********************************************************/
4014 /* GetArrayLength **************************************************************
4016 Returns the number of elements in the array.
4018 *******************************************************************************/
4020 jsize GetArrayLength(JNIEnv *env, jarray array)
4022 java_arrayheader *a;
4024 STATISTICS(jniinvokation());
4026 a = (java_arrayheader *) array;
4032 /* NewObjectArray **************************************************************
4034 Constructs a new array holding objects in class elementClass. All
4035 elements are initially set to initialElement.
4037 *******************************************************************************/
4039 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4041 java_objectarray *oa;
4044 STATISTICS(jniinvokation());
4047 exceptions_throw_negativearraysizeexception();
4051 oa = builtin_anewarray(length, elementClass);
4056 /* set all elements to initialElement */
4058 for (i = 0; i < length; i++)
4059 oa->data[i] = initialElement;
4061 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4065 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4067 java_objectarray *oa;
4070 STATISTICS(jniinvokation());
4072 oa = (java_objectarray *) array;
4074 if (index >= oa->header.size) {
4075 exceptions_throw_arrayindexoutofboundsexception();
4079 o = oa->data[index];
4081 return NewLocalRef(env, o);
4085 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4087 java_objectarray *oa;
4088 java_objectheader *o;
4090 STATISTICS(jniinvokation());
4092 oa = (java_objectarray *) array;
4093 o = (java_objectheader *) val;
4095 if (index >= oa->header.size) {
4096 exceptions_throw_arrayindexoutofboundsexception();
4100 /* check if the class of value is a subclass of the element class
4103 if (!builtin_canstore(oa, o)) {
4104 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4109 oa->data[index] = val;
4113 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4115 java_booleanarray *ba;
4117 STATISTICS(jniinvokation());
4120 exceptions_throw_negativearraysizeexception();
4124 ba = builtin_newarray_boolean(len);
4126 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4130 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4134 STATISTICS(jniinvokation());
4137 exceptions_throw_negativearraysizeexception();
4141 ba = builtin_newarray_byte(len);
4143 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4147 jcharArray NewCharArray(JNIEnv *env, jsize len)
4151 STATISTICS(jniinvokation());
4154 exceptions_throw_negativearraysizeexception();
4158 ca = builtin_newarray_char(len);
4160 return (jcharArray) NewLocalRef(env, (jobject) ca);
4164 jshortArray NewShortArray(JNIEnv *env, jsize len)
4166 java_shortarray *sa;
4168 STATISTICS(jniinvokation());
4171 exceptions_throw_negativearraysizeexception();
4175 sa = builtin_newarray_short(len);
4177 return (jshortArray) NewLocalRef(env, (jobject) sa);
4181 jintArray NewIntArray(JNIEnv *env, jsize len)
4185 STATISTICS(jniinvokation());
4188 exceptions_throw_negativearraysizeexception();
4192 ia = builtin_newarray_int(len);
4194 return (jintArray) NewLocalRef(env, (jobject) ia);
4198 jlongArray NewLongArray(JNIEnv *env, jsize len)
4202 STATISTICS(jniinvokation());
4205 exceptions_throw_negativearraysizeexception();
4209 la = builtin_newarray_long(len);
4211 return (jlongArray) NewLocalRef(env, (jobject) la);
4215 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4217 java_floatarray *fa;
4219 STATISTICS(jniinvokation());
4222 exceptions_throw_negativearraysizeexception();
4226 fa = builtin_newarray_float(len);
4228 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4232 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4234 java_doublearray *da;
4236 STATISTICS(jniinvokation());
4239 exceptions_throw_negativearraysizeexception();
4243 da = builtin_newarray_double(len);
4245 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4249 /* Get<PrimitiveType>ArrayElements *********************************************
4251 A family of functions that returns the body of the primitive array.
4253 *******************************************************************************/
4255 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4258 java_booleanarray *ba;
4260 STATISTICS(jniinvokation());
4262 ba = (java_booleanarray *) array;
4265 *isCopy = JNI_FALSE;
4271 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4275 STATISTICS(jniinvokation());
4277 ba = (java_bytearray *) array;
4280 *isCopy = JNI_FALSE;
4286 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4290 STATISTICS(jniinvokation());
4292 ca = (java_chararray *) array;
4295 *isCopy = JNI_FALSE;
4301 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4303 java_shortarray *sa;
4305 STATISTICS(jniinvokation());
4307 sa = (java_shortarray *) array;
4310 *isCopy = JNI_FALSE;
4316 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4320 STATISTICS(jniinvokation());
4322 ia = (java_intarray *) array;
4325 *isCopy = JNI_FALSE;
4331 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4335 STATISTICS(jniinvokation());
4337 la = (java_longarray *) array;
4340 *isCopy = JNI_FALSE;
4342 /* We cast this one to prevent a compiler warning on 64-bit
4343 systems since GNU Classpath typedef jlong to long long. */
4345 return (jlong *) la->data;
4349 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4351 java_floatarray *fa;
4353 STATISTICS(jniinvokation());
4355 fa = (java_floatarray *) array;
4358 *isCopy = JNI_FALSE;
4364 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4367 java_doublearray *da;
4369 STATISTICS(jniinvokation());
4371 da = (java_doublearray *) array;
4374 *isCopy = JNI_FALSE;
4380 /* Release<PrimitiveType>ArrayElements *****************************************
4382 A family of functions that informs the VM that the native code no
4383 longer needs access to elems. The elems argument is a pointer
4384 derived from array using the corresponding
4385 Get<PrimitiveType>ArrayElements() function. If necessary, this
4386 function copies back all changes made to elems to the original
4389 *******************************************************************************/
4391 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4392 jboolean *elems, jint mode)
4394 java_booleanarray *ba;
4396 STATISTICS(jniinvokation());
4398 ba = (java_booleanarray *) array;
4400 if (elems != ba->data) {
4403 MCOPY(ba->data, elems, u1, ba->header.size);
4406 MCOPY(ba->data, elems, u1, ba->header.size);
4407 /* XXX TWISTI how should it be freed? */
4410 /* XXX TWISTI how should it be freed? */
4417 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4422 STATISTICS(jniinvokation());
4424 ba = (java_bytearray *) array;
4426 if (elems != ba->data) {
4429 MCOPY(ba->data, elems, s1, ba->header.size);
4432 MCOPY(ba->data, elems, s1, ba->header.size);
4433 /* XXX TWISTI how should it be freed? */
4436 /* XXX TWISTI how should it be freed? */
4443 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4448 STATISTICS(jniinvokation());
4450 ca = (java_chararray *) array;
4452 if (elems != ca->data) {
4455 MCOPY(ca->data, elems, u2, ca->header.size);
4458 MCOPY(ca->data, elems, u2, ca->header.size);
4459 /* XXX TWISTI how should it be freed? */
4462 /* XXX TWISTI how should it be freed? */
4469 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4472 java_shortarray *sa;
4474 STATISTICS(jniinvokation());
4476 sa = (java_shortarray *) array;
4478 if (elems != sa->data) {
4481 MCOPY(sa->data, elems, s2, sa->header.size);
4484 MCOPY(sa->data, elems, s2, sa->header.size);
4485 /* XXX TWISTI how should it be freed? */
4488 /* XXX TWISTI how should it be freed? */
4495 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4500 STATISTICS(jniinvokation());
4502 ia = (java_intarray *) array;
4504 if (elems != ia->data) {
4507 MCOPY(ia->data, elems, s4, ia->header.size);
4510 MCOPY(ia->data, elems, s4, ia->header.size);
4511 /* XXX TWISTI how should it be freed? */
4514 /* XXX TWISTI how should it be freed? */
4521 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4526 STATISTICS(jniinvokation());
4528 la = (java_longarray *) array;
4530 /* We cast this one to prevent a compiler warning on 64-bit
4531 systems since GNU Classpath typedef jlong to long long. */
4533 if ((s8 *) elems != la->data) {
4536 MCOPY(la->data, elems, s8, la->header.size);
4539 MCOPY(la->data, elems, s8, la->header.size);
4540 /* XXX TWISTI how should it be freed? */
4543 /* XXX TWISTI how should it be freed? */
4550 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4553 java_floatarray *fa;
4555 STATISTICS(jniinvokation());
4557 fa = (java_floatarray *) array;
4559 if (elems != fa->data) {
4562 MCOPY(fa->data, elems, float, fa->header.size);
4565 MCOPY(fa->data, elems, float, fa->header.size);
4566 /* XXX TWISTI how should it be freed? */
4569 /* XXX TWISTI how should it be freed? */
4576 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4577 jdouble *elems, jint mode)
4579 java_doublearray *da;
4581 STATISTICS(jniinvokation());
4583 da = (java_doublearray *) array;
4585 if (elems != da->data) {
4588 MCOPY(da->data, elems, double, da->header.size);
4591 MCOPY(da->data, elems, double, da->header.size);
4592 /* XXX TWISTI how should it be freed? */
4595 /* XXX TWISTI how should it be freed? */
4602 /* Get<PrimitiveType>ArrayRegion **********************************************
4604 A family of functions that copies a region of a primitive array
4607 *******************************************************************************/
4609 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4610 jsize len, jboolean *buf)
4612 java_booleanarray *ba;
4614 STATISTICS(jniinvokation());
4616 ba = (java_booleanarray *) array;
4618 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4619 exceptions_throw_arrayindexoutofboundsexception();
4621 MCOPY(buf, &ba->data[start], u1, len);
4625 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4630 STATISTICS(jniinvokation());
4632 ba = (java_bytearray *) array;
4634 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4635 exceptions_throw_arrayindexoutofboundsexception();
4637 MCOPY(buf, &ba->data[start], s1, len);
4641 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4646 STATISTICS(jniinvokation());
4648 ca = (java_chararray *) array;
4650 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4651 exceptions_throw_arrayindexoutofboundsexception();
4653 MCOPY(buf, &ca->data[start], u2, len);
4657 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4658 jsize len, jshort *buf)
4660 java_shortarray *sa;
4662 STATISTICS(jniinvokation());
4664 sa = (java_shortarray *) array;
4666 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4667 exceptions_throw_arrayindexoutofboundsexception();
4669 MCOPY(buf, &sa->data[start], s2, len);
4673 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4678 STATISTICS(jniinvokation());
4680 ia = (java_intarray *) array;
4682 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4683 exceptions_throw_arrayindexoutofboundsexception();
4685 MCOPY(buf, &ia->data[start], s4, len);
4689 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4694 STATISTICS(jniinvokation());
4696 la = (java_longarray *) array;
4698 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4699 exceptions_throw_arrayindexoutofboundsexception();
4701 MCOPY(buf, &la->data[start], s8, len);
4705 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4706 jsize len, jfloat *buf)
4708 java_floatarray *fa;
4710 STATISTICS(jniinvokation());
4712 fa = (java_floatarray *) array;
4714 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4715 exceptions_throw_arrayindexoutofboundsexception();
4717 MCOPY(buf, &fa->data[start], float, len);
4721 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4722 jsize len, jdouble *buf)
4724 java_doublearray *da;
4726 STATISTICS(jniinvokation());
4728 da = (java_doublearray *) array;
4730 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4731 exceptions_throw_arrayindexoutofboundsexception();
4733 MCOPY(buf, &da->data[start], double, len);
4737 /* Set<PrimitiveType>ArrayRegion **********************************************
4739 A family of functions that copies back a region of a primitive
4740 array from a buffer.
4742 *******************************************************************************/
4744 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4745 jsize len, jboolean *buf)
4747 java_booleanarray *ba;
4749 STATISTICS(jniinvokation());
4751 ba = (java_booleanarray *) array;
4753 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4754 exceptions_throw_arrayindexoutofboundsexception();
4756 MCOPY(&ba->data[start], buf, u1, len);
4760 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4765 STATISTICS(jniinvokation());
4767 ba = (java_bytearray *) array;
4769 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4770 exceptions_throw_arrayindexoutofboundsexception();
4772 MCOPY(&ba->data[start], buf, s1, len);
4776 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4781 STATISTICS(jniinvokation());
4783 ca = (java_chararray *) array;
4785 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4786 exceptions_throw_arrayindexoutofboundsexception();
4788 MCOPY(&ca->data[start], buf, u2, len);
4792 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4793 jsize len, jshort *buf)
4795 java_shortarray *sa;
4797 STATISTICS(jniinvokation());
4799 sa = (java_shortarray *) array;
4801 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4802 exceptions_throw_arrayindexoutofboundsexception();
4804 MCOPY(&sa->data[start], buf, s2, len);
4808 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4813 STATISTICS(jniinvokation());
4815 ia = (java_intarray *) array;
4817 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4818 exceptions_throw_arrayindexoutofboundsexception();
4820 MCOPY(&ia->data[start], buf, s4, len);
4824 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4829 STATISTICS(jniinvokation());
4831 la = (java_longarray *) array;
4833 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4834 exceptions_throw_arrayindexoutofboundsexception();
4836 MCOPY(&la->data[start], buf, s8, len);
4840 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4841 jsize len, jfloat *buf)
4843 java_floatarray *fa;
4845 STATISTICS(jniinvokation());
4847 fa = (java_floatarray *) array;
4849 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4850 exceptions_throw_arrayindexoutofboundsexception();
4852 MCOPY(&fa->data[start], buf, float, len);
4856 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4857 jsize len, jdouble *buf)
4859 java_doublearray *da;
4861 STATISTICS(jniinvokation());
4863 da = (java_doublearray *) array;
4865 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4866 exceptions_throw_arrayindexoutofboundsexception();
4868 MCOPY(&da->data[start], buf, double, len);
4872 /* Registering Native Methods *************************************************/
4874 /* RegisterNatives *************************************************************
4876 Registers native methods with the class specified by the clazz
4877 argument. The methods parameter specifies an array of
4878 JNINativeMethod structures that contain the names, signatures, and
4879 function pointers of the native methods. The nMethods parameter
4880 specifies the number of native methods in the array.
4882 *******************************************************************************/
4884 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4887 STATISTICS(jniinvokation());
4889 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4895 /* UnregisterNatives ***********************************************************
4897 Unregisters native methods of a class. The class goes back to the
4898 state before it was linked or registered with its native method
4901 This function should not be used in normal native code. Instead, it
4902 provides special programs a way to reload and relink native
4905 *******************************************************************************/
4907 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4909 STATISTICS(jniinvokation());
4911 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4913 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4919 /* Monitor Operations *********************************************************/
4921 /* MonitorEnter ****************************************************************
4923 Enters the monitor associated with the underlying Java object
4926 *******************************************************************************/
4928 jint MonitorEnter(JNIEnv *env, jobject obj)
4930 STATISTICS(jniinvokation());
4933 exceptions_throw_nullpointerexception();
4937 #if defined(USE_THREADS)
4938 builtin_monitorenter(obj);
4945 /* MonitorExit *****************************************************************
4947 The current thread must be the owner of the monitor associated with
4948 the underlying Java object referred to by obj. The thread
4949 decrements the counter indicating the number of times it has
4950 entered this monitor. If the value of the counter becomes zero, the
4951 current thread releases the monitor.
4953 *******************************************************************************/
4955 jint MonitorExit(JNIEnv *env, jobject obj)
4957 STATISTICS(jniinvokation());
4960 exceptions_throw_nullpointerexception();
4964 #if defined(USE_THREADS)
4965 builtin_monitorexit(obj);
4972 /* JavaVM Interface ***********************************************************/
4974 /* GetJavaVM *******************************************************************
4976 Returns the Java VM interface (used in the Invocation API)
4977 associated with the current thread. The result is placed at the
4978 location pointed to by the second argument, vm.
4980 *******************************************************************************/
4982 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4984 STATISTICS(jniinvokation());
4986 *vm = (JavaVM *) _Jv_jvm;
4992 /* GetStringRegion *************************************************************
4994 Copies len number of Unicode characters beginning at offset start
4995 to the given buffer buf.
4997 Throws StringIndexOutOfBoundsException on index overflow.
4999 *******************************************************************************/
5001 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
5003 java_lang_String *s;
5006 STATISTICS(jniinvokation());
5008 s = (java_lang_String *) str;
5011 if ((start < 0) || (len < 0) || (start > s->count) ||
5012 (start + len > s->count)) {
5013 exceptions_throw_stringindexoutofboundsexception();
5017 MCOPY(buf, &ca->data[start], u2, len);
5021 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5023 STATISTICS(jniinvokation());
5025 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5029 /* GetPrimitiveArrayCritical ***************************************************
5031 Obtain a direct pointer to array elements.
5033 *******************************************************************************/
5035 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5040 ba = (java_bytearray *) array;
5042 /* do the same as Kaffe does */
5044 bp = GetByteArrayElements(env, ba, isCopy);
5050 /* ReleasePrimitiveArrayCritical ***********************************************
5052 No specific documentation.
5054 *******************************************************************************/
5056 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5059 STATISTICS(jniinvokation());
5061 /* do the same as Kaffe does */
5063 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5067 /* GetStringCritical ***********************************************************
5069 The semantics of these two functions are similar to the existing
5070 Get/ReleaseStringChars functions.
5072 *******************************************************************************/
5074 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5076 STATISTICS(jniinvokation());
5078 return GetStringChars(env, string, isCopy);
5082 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5084 STATISTICS(jniinvokation());
5086 ReleaseStringChars(env, string, cstring);
5090 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5092 STATISTICS(jniinvokation());
5094 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5100 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5102 STATISTICS(jniinvokation());
5104 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5108 /* NewGlobalRef ****************************************************************
5110 Creates a new global reference to the object referred to by the obj
5113 *******************************************************************************/
5115 jobject NewGlobalRef(JNIEnv* env, jobject obj)
5117 hashtable_global_ref_entry *gre;
5118 u4 key; /* hashkey */
5119 u4 slot; /* slot in hashtable */
5121 STATISTICS(jniinvokation());
5123 #if defined(USE_THREADS)
5124 builtin_monitorenter(hashtable_global_ref->header);
5127 /* normally addresses are aligned to 4, 8 or 16 bytes */
5129 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5130 slot = key & (hashtable_global_ref->size - 1);
5131 gre = hashtable_global_ref->ptr[slot];
5133 /* search external hash chain for the entry */
5136 if (gre->o == obj) {
5137 /* global object found, increment the reference */
5141 #if defined(USE_THREADS)
5142 builtin_monitorexit(hashtable_global_ref->header);
5148 gre = gre->hashlink; /* next element in external chain */
5151 /* global ref not found, create a new one */
5153 gre = NEW(hashtable_global_ref_entry);
5158 /* insert entry into hashtable */
5160 gre->hashlink = hashtable_global_ref->ptr[slot];
5162 hashtable_global_ref->ptr[slot] = gre;
5164 /* update number of hashtable-entries */
5166 hashtable_global_ref->entries++;
5168 #if defined(USE_THREADS)
5169 builtin_monitorexit(hashtable_global_ref->header);
5176 /* DeleteGlobalRef *************************************************************
5178 Deletes the global reference pointed to by globalRef.
5180 *******************************************************************************/
5182 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5184 hashtable_global_ref_entry *gre;
5185 hashtable_global_ref_entry *prevgre;
5186 u4 key; /* hashkey */
5187 u4 slot; /* slot in hashtable */
5189 STATISTICS(jniinvokation());
5191 #if defined(USE_THREADS)
5192 builtin_monitorenter(hashtable_global_ref->header);
5195 /* normally addresses are aligned to 4, 8 or 16 bytes */
5197 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5198 slot = key & (hashtable_global_ref->size - 1);
5199 gre = hashtable_global_ref->ptr[slot];
5201 /* initialize prevgre */
5205 /* search external hash chain for the entry */
5208 if (gre->o == globalRef) {
5209 /* global object found, decrement the reference count */
5213 /* if reference count is 0, remove the entry */
5215 if (gre->refs == 0) {
5216 /* special handling if it's the first in the chain */
5218 if (prevgre == NULL)
5219 hashtable_global_ref->ptr[slot] = gre->hashlink;
5221 prevgre->hashlink = gre->hashlink;
5223 FREE(gre, hashtable_global_ref_entry);
5226 #if defined(USE_THREADS)
5227 builtin_monitorexit(hashtable_global_ref->header);
5233 prevgre = gre; /* save current pointer for removal */
5234 gre = gre->hashlink; /* next element in external chain */
5237 log_println("JNI-DeleteGlobalRef: global reference not found");
5239 #if defined(USE_THREADS)
5240 builtin_monitorexit(hashtable_global_ref->header);
5245 /* ExceptionCheck **************************************************************
5247 Returns JNI_TRUE when there is a pending exception; otherwise,
5250 *******************************************************************************/
5252 jboolean ExceptionCheck(JNIEnv *env)
5254 STATISTICS(jniinvokation());
5256 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5260 /* New JNI 1.4 functions ******************************************************/
5262 /* NewDirectByteBuffer *********************************************************
5264 Allocates and returns a direct java.nio.ByteBuffer referring to the
5265 block of memory starting at the memory address address and
5266 extending capacity bytes.
5268 *******************************************************************************/
5270 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5272 java_objectheader *nbuf;
5273 #if SIZEOF_VOID_P == 8
5274 gnu_classpath_Pointer64 *paddress;
5276 gnu_classpath_Pointer32 *paddress;
5279 STATISTICS(jniinvokation());
5281 /* alocate a gnu.classpath.Pointer{32,64} object */
5283 #if SIZEOF_VOID_P == 8
5284 if (!(paddress = (gnu_classpath_Pointer64 *)
5285 builtin_new(class_gnu_classpath_Pointer64)))
5287 if (!(paddress = (gnu_classpath_Pointer32 *)
5288 builtin_new(class_gnu_classpath_Pointer32)))
5292 /* fill gnu.classpath.Pointer{32,64} with address */
5294 paddress->data = (ptrint) address;
5296 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5298 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5299 (jmethodID) dbbirw_init, NULL, paddress,
5300 (jint) capacity, (jint) capacity, (jint) 0);
5302 /* add local reference and return the value */
5304 return NewLocalRef(env, nbuf);
5308 /* GetDirectBufferAddress ******************************************************
5310 Fetches and returns the starting address of the memory region
5311 referenced by the given direct java.nio.Buffer.
5313 *******************************************************************************/
5315 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5317 java_nio_DirectByteBufferImpl *nbuf;
5318 #if SIZEOF_VOID_P == 8
5319 gnu_classpath_Pointer64 *address;
5321 gnu_classpath_Pointer32 *address;
5324 STATISTICS(jniinvokation());
5326 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5329 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5331 #if SIZEOF_VOID_P == 8
5332 address = (gnu_classpath_Pointer64 *) nbuf->address;
5334 address = (gnu_classpath_Pointer32 *) nbuf->address;
5337 return (void *) address->data;
5341 /* GetDirectBufferCapacity *****************************************************
5343 Fetches and returns the capacity in bytes of the memory region
5344 referenced by the given direct java.nio.Buffer.
5346 *******************************************************************************/
5348 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5350 java_nio_Buffer *nbuf;
5352 STATISTICS(jniinvokation());
5354 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5357 nbuf = (java_nio_Buffer *) buf;
5359 return (jlong) nbuf->cap;
5363 /* DestroyJavaVM ***************************************************************
5365 Unloads a Java VM and reclaims its resources. Only the main thread
5366 can unload the VM. The system waits until the main thread is only
5367 remaining user thread before it destroys the VM.
5369 *******************************************************************************/
5371 jint DestroyJavaVM(JavaVM *vm)
5375 STATISTICS(jniinvokation());
5377 status = vm_destroy(vm);
5383 /* AttachCurrentThread *********************************************************
5385 Attaches the current thread to a Java VM. Returns a JNI interface
5386 pointer in the JNIEnv argument.
5388 Trying to attach a thread that is already attached is a no-op.
5390 A native thread cannot be attached simultaneously to two Java VMs.
5392 When a thread is attached to the VM, the context class loader is
5393 the bootstrap loader.
5395 *******************************************************************************/
5397 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5399 STATISTICS(jniinvokation());
5401 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5403 #if !defined(HAVE___THREAD)
5404 /* cacao_thread_attach();*/
5406 #error "No idea how to implement that. Perhaps Stefan knows"
5415 jint DetachCurrentThread(JavaVM *vm)
5417 STATISTICS(jniinvokation());
5419 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5425 /* GetEnv **********************************************************************
5427 If the current thread is not attached to the VM, sets *env to NULL,
5428 and returns JNI_EDETACHED. If the specified version is not
5429 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5430 sets *env to the appropriate interface, and returns JNI_OK.
5432 *******************************************************************************/
5434 jint GetEnv(JavaVM *vm, void **env, jint version)
5436 STATISTICS(jniinvokation());
5438 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
5439 if (threads_get_current_threadobject() == NULL) {
5442 return JNI_EDETACHED;
5446 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5447 (version == JNI_VERSION_1_4)) {
5453 #if defined(ENABLE_JVMTI)
5454 if (version == JVMTI_VERSION_1_0) {
5455 *env = (void *) new_jvmtienv();
5464 return JNI_EVERSION;
5469 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5471 STATISTICS(jniinvokation());
5473 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5479 /* JNI invocation table *******************************************************/
5481 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5487 AttachCurrentThread,
5488 DetachCurrentThread,
5490 AttachCurrentThreadAsDaemon
5494 /* JNI function table *********************************************************/
5496 struct JNINativeInterface _Jv_JNINativeInterface = {
5505 FromReflectedMethod,
5526 EnsureLocalCapacity,
5569 CallNonvirtualObjectMethod,
5570 CallNonvirtualObjectMethodV,
5571 CallNonvirtualObjectMethodA,
5572 CallNonvirtualBooleanMethod,
5573 CallNonvirtualBooleanMethodV,
5574 CallNonvirtualBooleanMethodA,
5575 CallNonvirtualByteMethod,
5576 CallNonvirtualByteMethodV,
5577 CallNonvirtualByteMethodA,
5578 CallNonvirtualCharMethod,
5579 CallNonvirtualCharMethodV,
5580 CallNonvirtualCharMethodA,
5581 CallNonvirtualShortMethod,
5582 CallNonvirtualShortMethodV,
5583 CallNonvirtualShortMethodA,
5584 CallNonvirtualIntMethod,
5585 CallNonvirtualIntMethodV,
5586 CallNonvirtualIntMethodA,
5587 CallNonvirtualLongMethod,
5588 CallNonvirtualLongMethodV,
5589 CallNonvirtualLongMethodA,
5590 CallNonvirtualFloatMethod,
5591 CallNonvirtualFloatMethodV,
5592 CallNonvirtualFloatMethodA,
5593 CallNonvirtualDoubleMethod,
5594 CallNonvirtualDoubleMethodV,
5595 CallNonvirtualDoubleMethodA,
5596 CallNonvirtualVoidMethod,
5597 CallNonvirtualVoidMethodV,
5598 CallNonvirtualVoidMethodA,
5623 CallStaticObjectMethod,
5624 CallStaticObjectMethodV,
5625 CallStaticObjectMethodA,
5626 CallStaticBooleanMethod,
5627 CallStaticBooleanMethodV,
5628 CallStaticBooleanMethodA,
5629 CallStaticByteMethod,
5630 CallStaticByteMethodV,
5631 CallStaticByteMethodA,
5632 CallStaticCharMethod,
5633 CallStaticCharMethodV,
5634 CallStaticCharMethodA,
5635 CallStaticShortMethod,
5636 CallStaticShortMethodV,
5637 CallStaticShortMethodA,
5638 CallStaticIntMethod,
5639 CallStaticIntMethodV,
5640 CallStaticIntMethodA,
5641 CallStaticLongMethod,
5642 CallStaticLongMethodV,
5643 CallStaticLongMethodA,
5644 CallStaticFloatMethod,
5645 CallStaticFloatMethodV,
5646 CallStaticFloatMethodA,
5647 CallStaticDoubleMethod,
5648 CallStaticDoubleMethodV,
5649 CallStaticDoubleMethodA,
5650 CallStaticVoidMethod,
5651 CallStaticVoidMethodV,
5652 CallStaticVoidMethodA,
5656 GetStaticObjectField,
5657 GetStaticBooleanField,
5660 GetStaticShortField,
5663 GetStaticFloatField,
5664 GetStaticDoubleField,
5665 SetStaticObjectField,
5666 SetStaticBooleanField,
5669 SetStaticShortField,
5672 SetStaticFloatField,
5673 SetStaticDoubleField,
5683 ReleaseStringUTFChars,
5688 GetObjectArrayElement,
5689 SetObjectArrayElement,
5700 GetBooleanArrayElements,
5701 GetByteArrayElements,
5702 GetCharArrayElements,
5703 GetShortArrayElements,
5704 GetIntArrayElements,
5705 GetLongArrayElements,
5706 GetFloatArrayElements,
5707 GetDoubleArrayElements,
5709 ReleaseBooleanArrayElements,
5710 ReleaseByteArrayElements,
5711 ReleaseCharArrayElements,
5712 ReleaseShortArrayElements,
5713 ReleaseIntArrayElements,
5714 ReleaseLongArrayElements,
5715 ReleaseFloatArrayElements,
5716 ReleaseDoubleArrayElements,
5718 GetBooleanArrayRegion,
5721 GetShortArrayRegion,
5724 GetFloatArrayRegion,
5725 GetDoubleArrayRegion,
5726 SetBooleanArrayRegion,
5729 SetShortArrayRegion,
5732 SetFloatArrayRegion,
5733 SetDoubleArrayRegion,
5743 /* new JNI 1.2 functions */
5748 GetPrimitiveArrayCritical,
5749 ReleasePrimitiveArrayCritical,
5752 ReleaseStringCritical,
5755 DeleteWeakGlobalRef,
5759 /* new JNI 1.4 functions */
5761 NewDirectByteBuffer,
5762 GetDirectBufferAddress,
5763 GetDirectBufferCapacity
5767 /* Invocation API Functions ***************************************************/
5769 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5771 Returns a default configuration for the Java VM.
5773 *******************************************************************************/
5775 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5777 JavaVMInitArgs *_vm_args;
5779 _vm_args = (JavaVMInitArgs *) vm_args;
5781 /* GNU classpath currently supports JNI 1.2 */
5783 switch (_vm_args->version) {
5784 case JNI_VERSION_1_1:
5785 _vm_args->version = JNI_VERSION_1_1;
5788 case JNI_VERSION_1_2:
5789 case JNI_VERSION_1_4:
5790 _vm_args->ignoreUnrecognized = JNI_FALSE;
5791 _vm_args->options = NULL;
5792 _vm_args->nOptions = 0;
5803 /* JNI_GetCreatedJavaVMs *******************************************************
5805 Returns all Java VMs that have been created. Pointers to VMs are written in
5806 the buffer vmBuf in the order they are created. At most bufLen number of
5807 entries will be written. The total number of created VMs is returned in
5810 *******************************************************************************/
5812 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5814 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5820 /* JNI_CreateJavaVM ************************************************************
5822 Loads and initializes a Java VM. The current thread becomes the main thread.
5823 Sets the env argument to the JNI interface pointer of the main thread.
5825 *******************************************************************************/
5827 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5829 JavaVMInitArgs *_vm_args;
5832 localref_table *lrt;
5834 /* get the arguments for the new JVM */
5836 _vm_args = (JavaVMInitArgs *) vm_args;
5838 /* get the VM and Env tables (must be set before vm_create) */
5840 env = NEW(_Jv_JNIEnv);
5841 env->env = &_Jv_JNINativeInterface;
5843 /* XXX Set the global variable. Maybe we should do that differently. */
5848 /* create and fill a JavaVM structure */
5850 jvm = NEW(_Jv_JavaVM);
5851 jvm->functions = &_Jv_JNIInvokeInterface;
5853 /* XXX Set the global variable. Maybe we should do that differently. */
5854 /* XXX JVMTI Agents needs a JavaVM */
5858 /* actually create the JVM */
5860 if (!vm_create(_vm_args))
5863 /* setup the local ref table (must be created after vm_create) */
5865 lrt = GCNEW(localref_table);
5867 lrt->capacity = LOCALREFTABLE_CAPACITY;
5869 lrt->localframes = 1;
5870 lrt->prev = LOCALREFTABLE;
5872 /* clear the references array (memset is faster then a for-loop) */
5874 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5876 LOCALREFTABLE = lrt;
5878 /* now return the values */
5880 *p_vm = (JavaVM *) jvm;
5881 *p_env = (void *) env;
5888 * These are local overrides for various environment variables in Emacs.
5889 * Please do not remove this and leave it at the end of the file, where
5890 * Emacs will automagically detect them.
5891 * ---------------------------------------------------------------------
5894 * indent-tabs-mode: t
5898 * vim:noexpandtab:sw=4:ts=4: