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 5580 2006-09-29 12:46:15Z 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/cacaodbg.h"
84 #if defined(ENABLE_THREADS)
85 # include "threads/native/lock.h"
86 # include "threads/native/threads.h"
88 # include "threads/none/lock.h"
91 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/loader.h"
97 #include "vm/options.h"
98 #include "vm/resolve.h"
99 #include "vm/statistics.h"
100 #include "vm/stringlocal.h"
101 #include "vm/jit/asmpart.h"
102 #include "vm/jit/jit.h"
103 #include "vm/statistics.h"
107 /* global variables ***********************************************************/
109 /* global reference table *****************************************************/
111 /* hashsize must be power of 2 */
113 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
115 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
118 /* direct buffer stuff ********************************************************/
120 static classinfo *class_java_nio_Buffer;
121 static classinfo *class_java_nio_DirectByteBufferImpl;
122 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
123 #if SIZEOF_VOID_P == 8
124 static classinfo *class_gnu_classpath_Pointer64;
126 static classinfo *class_gnu_classpath_Pointer32;
129 static methodinfo *dbbirw_init;
132 /* local reference table ******************************************************/
134 #if !defined(ENABLE_THREADS)
135 localref_table *_no_threads_localref_table;
139 /* accessing instance fields macros *******************************************/
141 #define SET_FIELD(o,type,f,value) \
142 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
144 #define GET_FIELD(o,type,f) \
145 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
148 /* some forward declarations **************************************************/
150 jobject NewLocalRef(JNIEnv *env, jobject ref);
151 jint EnsureLocalCapacity(JNIEnv* env, jint capacity);
154 /* jni_init ********************************************************************
156 Initialize the JNI subsystem.
158 *******************************************************************************/
162 /* create global ref hashtable */
164 hashtable_global_ref = NEW(hashtable);
166 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
169 /* direct buffer stuff */
171 if (!(class_java_nio_Buffer =
172 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
173 !link_class(class_java_nio_Buffer))
176 if (!(class_java_nio_DirectByteBufferImpl =
177 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
178 !link_class(class_java_nio_DirectByteBufferImpl))
181 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
182 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
183 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
187 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
189 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
192 #if SIZEOF_VOID_P == 8
193 if (!(class_gnu_classpath_Pointer64 =
194 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
195 !link_class(class_gnu_classpath_Pointer64))
198 if (!(class_gnu_classpath_Pointer32 =
199 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
200 !link_class(class_gnu_classpath_Pointer32))
208 /* _Jv_jni_vmargs_from_objectarray *********************************************
212 *******************************************************************************/
214 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
217 java_objectarray *params)
219 java_objectheader *param;
221 typedesc *paramtypes;
227 paramcount = descr->paramcount;
228 paramtypes = descr->paramtypes;
230 /* if method is non-static fill first block and skip `this' pointer */
236 vmargs[0].type = TYPE_ADR;
237 vmargs[0].data.l = (u8) (ptrint) o;
244 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
245 switch (paramtypes->type) {
246 /* primitive types */
251 param = params->data[j];
256 /* internally used data type */
257 vmargs[i].type = paramtypes->type;
259 /* convert the value according to its declared type */
261 c = param->vftbl->class;
263 switch (paramtypes->decltype) {
264 case PRIMITIVETYPE_BOOLEAN:
265 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
266 value = (s8) ((java_lang_Boolean *) param)->value;
270 vmargs[i].data.l = value;
273 case PRIMITIVETYPE_BYTE:
274 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
275 value = (s8) ((java_lang_Byte *) param)->value;
279 vmargs[i].data.l = value;
282 case PRIMITIVETYPE_CHAR:
283 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
284 value = (s8) ((java_lang_Character *) param)->value;
288 vmargs[i].data.l = value;
291 case PRIMITIVETYPE_SHORT:
292 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
293 value = (s8) ((java_lang_Short *) param)->value;
294 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
295 value = (s8) ((java_lang_Byte *) param)->value;
299 vmargs[i].data.l = value;
302 case PRIMITIVETYPE_INT:
303 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
304 value = (s8) ((java_lang_Integer *) param)->value;
305 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
306 value = (s8) ((java_lang_Short *) param)->value;
307 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
308 value = (s8) ((java_lang_Byte *) param)->value;
312 vmargs[i].data.l = value;
315 case PRIMITIVETYPE_LONG:
316 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
317 value = (s8) ((java_lang_Long *) param)->value;
318 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
319 value = (s8) ((java_lang_Integer *) param)->value;
320 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
321 value = (s8) ((java_lang_Short *) param)->value;
322 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
323 value = (s8) ((java_lang_Byte *) param)->value;
327 vmargs[i].data.l = value;
330 case PRIMITIVETYPE_FLOAT:
331 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
332 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
337 case PRIMITIVETYPE_DOUBLE:
338 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
339 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
340 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
341 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
352 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
355 if (params->data[j] != 0) {
356 if (paramtypes->arraydim > 0) {
357 if (!builtin_arrayinstanceof(params->data[j], c))
361 if (!builtin_instanceof(params->data[j], c))
366 vmargs[i].type = TYPE_ADR;
367 vmargs[i].data.l = (u8) (ptrint) params->data[j];
376 /* *rettype = descr->returntype.decltype; */
381 exceptions_throw_illegalargumentexception();
386 /* _Jv_jni_CallObjectMethod ****************************************************
388 Internal function to call Java Object methods.
390 *******************************************************************************/
392 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
394 methodinfo *m, va_list ap)
397 java_objectheader *ro;
399 STATISTICS(jniinvokation());
402 exceptions_throw_nullpointerexception();
406 /* Class initialization is done by the JIT compiler. This is ok
407 since a static method always belongs to the declaring class. */
409 if (m->flags & ACC_STATIC) {
410 /* For static methods we reset the object. */
415 /* for convenience */
420 /* For instance methods we make a virtual function table lookup. */
422 resm = method_vftbl_lookup(vftbl, m);
425 STATISTICS(jnicallXmethodnvokation());
427 ro = vm_call_method_valist(resm, o, ap);
433 /* _Jv_jni_CallObjectMethodA ***************************************************
435 Internal function to call Java Object methods.
437 *******************************************************************************/
439 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
441 methodinfo *m, jvalue *args)
444 java_objectheader *ro;
446 STATISTICS(jniinvokation());
449 exceptions_throw_nullpointerexception();
453 /* Class initialization is done by the JIT compiler. This is ok
454 since a static method always belongs to the declaring class. */
456 if (m->flags & ACC_STATIC) {
457 /* For static methods we reset the object. */
462 /* for convenience */
467 /* For instance methods we make a virtual function table lookup. */
469 resm = method_vftbl_lookup(vftbl, m);
472 STATISTICS(jnicallXmethodnvokation());
474 ro = vm_call_method_jvalue(resm, o, args);
480 /* _Jv_jni_CallIntMethod *******************************************************
482 Internal function to call Java integer class methods (boolean,
483 byte, char, short, int).
485 *******************************************************************************/
487 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
488 methodinfo *m, va_list ap)
493 STATISTICS(jniinvokation());
496 exceptions_throw_nullpointerexception();
500 /* Class initialization is done by the JIT compiler. This is ok
501 since a static method always belongs to the declaring class. */
503 if (m->flags & ACC_STATIC) {
504 /* For static methods we reset the object. */
509 /* for convenience */
514 /* For instance methods we make a virtual function table lookup. */
516 resm = method_vftbl_lookup(vftbl, m);
519 STATISTICS(jnicallXmethodnvokation());
521 i = vm_call_method_int_valist(resm, o, ap);
527 /* _Jv_jni_CallIntMethodA ******************************************************
529 Internal function to call Java integer class methods (boolean,
530 byte, char, short, int).
532 *******************************************************************************/
534 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
535 methodinfo *m, jvalue *args)
540 STATISTICS(jniinvokation());
543 exceptions_throw_nullpointerexception();
547 /* Class initialization is done by the JIT compiler. This is ok
548 since a static method always belongs to the declaring class. */
550 if (m->flags & ACC_STATIC) {
551 /* For static methods we reset the object. */
556 /* for convenience */
561 /* For instance methods we make a virtual function table lookup. */
563 resm = method_vftbl_lookup(vftbl, m);
566 STATISTICS(jnicallXmethodnvokation());
568 i = vm_call_method_int_jvalue(resm, o, args);
574 /* _Jv_jni_CallLongMethod ******************************************************
576 Internal function to call Java long methods.
578 *******************************************************************************/
580 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
581 methodinfo *m, va_list ap)
586 STATISTICS(jniinvokation());
589 exceptions_throw_nullpointerexception();
593 /* Class initialization is done by the JIT compiler. This is ok
594 since a static method always belongs to the declaring class. */
596 if (m->flags & ACC_STATIC) {
597 /* For static methods we reset the object. */
602 /* for convenience */
607 /* For instance methods we make a virtual function table lookup. */
609 resm = method_vftbl_lookup(vftbl, m);
612 STATISTICS(jnicallXmethodnvokation());
614 l = vm_call_method_long_valist(resm, o, ap);
620 /* _Jv_jni_CallFloatMethod *****************************************************
622 Internal function to call Java float methods.
624 *******************************************************************************/
626 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
627 methodinfo *m, va_list ap)
632 /* Class initialization is done by the JIT compiler. This is ok
633 since a static method always belongs to the declaring class. */
635 if (m->flags & ACC_STATIC) {
636 /* For static methods we reset the object. */
641 /* for convenience */
646 /* For instance methods we make a virtual function table lookup. */
648 resm = method_vftbl_lookup(vftbl, m);
651 STATISTICS(jnicallXmethodnvokation());
653 f = vm_call_method_float_valist(resm, o, ap);
659 /* _Jv_jni_CallDoubleMethod ****************************************************
661 Internal function to call Java double methods.
663 *******************************************************************************/
665 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
666 methodinfo *m, va_list ap)
671 /* Class initialization is done by the JIT compiler. This is ok
672 since a static method always belongs to the declaring class. */
674 if (m->flags & ACC_STATIC) {
675 /* For static methods we reset the object. */
680 /* for convenience */
685 /* For instance methods we make a virtual function table lookup. */
687 resm = method_vftbl_lookup(vftbl, m);
690 d = vm_call_method_double_valist(resm, o, ap);
696 /* _Jv_jni_CallVoidMethod ******************************************************
698 Internal function to call Java void methods.
700 *******************************************************************************/
702 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
703 methodinfo *m, va_list ap)
708 exceptions_throw_nullpointerexception();
712 /* Class initialization is done by the JIT compiler. This is ok
713 since a static method always belongs to the declaring class. */
715 if (m->flags & ACC_STATIC) {
716 /* For static methods we reset the object. */
721 /* for convenience */
726 /* For instance methods we make a virtual function table lookup. */
728 resm = method_vftbl_lookup(vftbl, m);
731 STATISTICS(jnicallXmethodnvokation());
733 (void) vm_call_method_valist(resm, o, ap);
737 /* _Jv_jni_CallVoidMethodA *****************************************************
739 Internal function to call Java void methods.
741 *******************************************************************************/
743 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
744 methodinfo *m, jvalue *args)
749 exceptions_throw_nullpointerexception();
753 /* Class initialization is done by the JIT compiler. This is ok
754 since a static method always belongs to the declaring class. */
756 if (m->flags & ACC_STATIC) {
757 /* For static methods we reset the object. */
762 /* for convenience */
767 /* For instance methods we make a virtual function table lookup. */
769 resm = method_vftbl_lookup(vftbl, m);
772 STATISTICS(jnicallXmethodnvokation());
774 (void) vm_call_method_jvalue(resm, o, args);
778 /* _Jv_jni_invokeNative ********************************************************
780 Invoke a method on the given object with the given arguments.
782 For instance methods OBJ must be != NULL and the method is looked up
783 in the vftbl of the object.
785 For static methods, OBJ is ignored.
787 *******************************************************************************/
789 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
790 java_objectarray *params)
794 java_objectheader *ro;
799 exceptions_throw_nullpointerexception();
803 argcount = m->parseddesc->paramcount;
804 paramcount = argcount;
806 /* if method is non-static, remove the `this' pointer */
808 if (!(m->flags & ACC_STATIC))
811 /* For instance methods the object has to be an instance of the
812 class the method belongs to. For static methods the obj
813 parameter is ignored. */
815 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
817 new_exception_message(string_java_lang_IllegalArgumentException,
818 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
822 /* check if we got the right number of arguments */
824 if (((params == NULL) && (paramcount != 0)) ||
825 (params && (params->header.size != paramcount)))
828 new_exception(string_java_lang_IllegalArgumentException);
832 /* for instance methods we need an object */
834 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
836 new_exception_message(string_java_lang_NullPointerException,
837 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
841 /* for static methods, zero object to make subsequent code simpler */
842 if (m->flags & ACC_STATIC)
846 /* for instance methods we must do a vftbl lookup */
847 resm = method_vftbl_lookup(o->vftbl, m);
850 /* for static methods, just for convenience */
854 vmargs = MNEW(vm_arg, argcount);
856 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
859 switch (resm->parseddesc->returntype.decltype) {
861 (void) vm_call_method_vmarg(resm, argcount, vmargs);
866 case PRIMITIVETYPE_BOOLEAN: {
868 java_lang_Boolean *bo;
870 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
872 ro = builtin_new(class_java_lang_Boolean);
874 /* setting the value of the object direct */
876 bo = (java_lang_Boolean *) ro;
881 case PRIMITIVETYPE_BYTE: {
885 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
887 ro = builtin_new(class_java_lang_Byte);
889 /* setting the value of the object direct */
891 bo = (java_lang_Byte *) ro;
896 case PRIMITIVETYPE_CHAR: {
898 java_lang_Character *co;
900 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
902 ro = builtin_new(class_java_lang_Character);
904 /* setting the value of the object direct */
906 co = (java_lang_Character *) ro;
911 case PRIMITIVETYPE_SHORT: {
915 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
917 ro = builtin_new(class_java_lang_Short);
919 /* setting the value of the object direct */
921 so = (java_lang_Short *) ro;
926 case PRIMITIVETYPE_INT: {
928 java_lang_Integer *io;
930 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
932 ro = builtin_new(class_java_lang_Integer);
934 /* setting the value of the object direct */
936 io = (java_lang_Integer *) ro;
941 case PRIMITIVETYPE_LONG: {
945 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
947 ro = builtin_new(class_java_lang_Long);
949 /* setting the value of the object direct */
951 lo = (java_lang_Long *) ro;
956 case PRIMITIVETYPE_FLOAT: {
960 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
962 ro = builtin_new(class_java_lang_Float);
964 /* setting the value of the object direct */
966 fo = (java_lang_Float *) ro;
971 case PRIMITIVETYPE_DOUBLE: {
973 java_lang_Double *_do;
975 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
977 ro = builtin_new(class_java_lang_Double);
979 /* setting the value of the object direct */
981 _do = (java_lang_Double *) ro;
987 ro = vm_call_method_vmarg(resm, argcount, vmargs);
991 /* if this happens the exception has already been set by
992 fill_callblock_from_objectarray */
994 MFREE(vmargs, vm_arg, argcount);
999 MFREE(vmargs, vm_arg, argcount);
1001 if (*exceptionptr) {
1002 java_objectheader *cause;
1004 cause = *exceptionptr;
1006 /* clear exception pointer, we are calling JIT code again */
1008 *exceptionptr = NULL;
1011 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1012 (java_lang_Throwable *) cause);
1019 /* GetVersion ******************************************************************
1021 Returns the major version number in the higher 16 bits and the
1022 minor version number in the lower 16 bits.
1024 *******************************************************************************/
1026 jint GetVersion(JNIEnv *env)
1028 STATISTICS(jniinvokation());
1030 /* we support JNI 1.4 */
1032 return JNI_VERSION_1_4;
1036 /* Class Operations ***********************************************************/
1038 /* DefineClass *****************************************************************
1040 Loads a class from a buffer of raw class data. The buffer
1041 containing the raw class data is not referenced by the VM after the
1042 DefineClass call returns, and it may be discarded if desired.
1044 *******************************************************************************/
1046 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1047 const jbyte *buf, jsize bufLen)
1049 java_lang_ClassLoader *cl;
1050 java_lang_String *s;
1054 STATISTICS(jniinvokation());
1056 cl = (java_lang_ClassLoader *) loader;
1057 s = javastring_new_from_utf_string(name);
1058 ba = (java_bytearray *) buf;
1060 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1063 return (jclass) NewLocalRef(env, (jobject) c);
1067 /* FindClass *******************************************************************
1069 This function loads a locally-defined class. It searches the
1070 directories and zip files specified by the CLASSPATH environment
1071 variable for the class with the specified name.
1073 *******************************************************************************/
1075 jclass FindClass(JNIEnv *env, const char *name)
1081 STATISTICS(jniinvokation());
1083 u = utf_new_char_classname((char *) name);
1085 /* Check stacktrace for classloader, if one found use it,
1086 otherwise use the system classloader. */
1088 /* Quote from the JNI documentation:
1090 In the Java 2 Platform, FindClass locates the class loader
1091 associated with the current native method. If the native code
1092 belongs to a system class, no class loader will be
1093 involved. Otherwise, the proper class loader will be invoked to
1094 load and link the named class. When FindClass is called through
1095 the Invocation Interface, there is no current native method or
1096 its associated class loader. In that case, the result of
1097 ClassLoader.getBaseClassLoader is used." */
1099 cc = stacktrace_getCurrentClass();
1102 c = load_class_from_sysloader(u);
1104 c = load_class_from_classloader(u, cc->classloader);
1112 return (jclass) NewLocalRef(env, (jobject) c);
1116 /* GetSuperclass ***************************************************************
1118 If clazz represents any class other than the class Object, then
1119 this function returns the object that represents the superclass of
1120 the class specified by clazz.
1122 *******************************************************************************/
1124 jclass GetSuperclass(JNIEnv *env, jclass sub)
1128 STATISTICS(jniinvokation());
1130 c = ((classinfo *) sub)->super.cls;
1135 return (jclass) NewLocalRef(env, (jobject) c);
1139 /* IsAssignableFrom ************************************************************
1141 Determines whether an object of sub can be safely cast to sup.
1143 *******************************************************************************/
1145 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1147 STATISTICS(jniinvokation());
1149 return Java_java_lang_VMClass_isAssignableFrom(env,
1151 (java_lang_Class *) sup,
1152 (java_lang_Class *) sub);
1156 /* Throw ***********************************************************************
1158 Causes a java.lang.Throwable object to be thrown.
1160 *******************************************************************************/
1162 jint Throw(JNIEnv *env, jthrowable obj)
1164 STATISTICS(jniinvokation());
1166 *exceptionptr = (java_objectheader *) obj;
1172 /* ThrowNew ********************************************************************
1174 Constructs an exception object from the specified class with the
1175 message specified by message and causes that exception to be
1178 *******************************************************************************/
1180 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1183 java_lang_Throwable *o;
1184 java_lang_String *s;
1186 STATISTICS(jniinvokation());
1188 c = (classinfo *) clazz;
1189 s = (java_lang_String *) javastring_new_from_utf_string(msg);
1191 /* instantiate exception object */
1193 o = (java_lang_Throwable *) native_new_and_init_string(c, s);
1198 *exceptionptr = (java_objectheader *) o;
1204 /* ExceptionOccurred ***********************************************************
1206 Determines if an exception is being thrown. The exception stays
1207 being thrown until either the native code calls ExceptionClear(),
1208 or the Java code handles the exception.
1210 *******************************************************************************/
1212 jthrowable ExceptionOccurred(JNIEnv *env)
1214 java_objectheader *e;
1216 STATISTICS(jniinvokation());
1220 return NewLocalRef(env, (jthrowable) e);
1224 /* ExceptionDescribe ***********************************************************
1226 Prints an exception and a backtrace of the stack to a system
1227 error-reporting channel, such as stderr. This is a convenience
1228 routine provided for debugging.
1230 *******************************************************************************/
1232 void ExceptionDescribe(JNIEnv *env)
1234 java_objectheader *e;
1237 STATISTICS(jniinvokation());
1242 /* clear exception, because we are calling jit code again */
1244 *exceptionptr = NULL;
1246 /* get printStackTrace method from exception class */
1248 m = class_resolveclassmethod(e->vftbl->class,
1249 utf_printStackTrace,
1255 /* XXX what should we do? */
1258 /* print the stacktrace */
1260 (void) vm_call_method(m, e);
1265 /* ExceptionClear **************************************************************
1267 Clears any exception that is currently being thrown. If no
1268 exception is currently being thrown, this routine has no effect.
1270 *******************************************************************************/
1272 void ExceptionClear(JNIEnv *env)
1274 STATISTICS(jniinvokation());
1276 *exceptionptr = NULL;
1280 /* FatalError ******************************************************************
1282 Raises a fatal error and does not expect the VM to recover. This
1283 function does not return.
1285 *******************************************************************************/
1287 void FatalError(JNIEnv *env, const char *msg)
1289 STATISTICS(jniinvokation());
1291 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1295 /* PushLocalFrame **************************************************************
1297 Creates a new local reference frame, in which at least a given
1298 number of local references can be created.
1300 *******************************************************************************/
1302 jint PushLocalFrame(JNIEnv* env, jint capacity)
1305 localref_table *lrt;
1306 localref_table *nlrt;
1308 STATISTICS(jniinvokation());
1313 /* Allocate new local reference table on Java heap. Calculate the
1314 additional memory we have to allocate. */
1316 if (capacity > LOCALREFTABLE_CAPACITY)
1317 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1321 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1326 /* get current local reference table from thread */
1328 lrt = LOCALREFTABLE;
1330 /* Set up the new local reference table and add it to the local
1333 nlrt->capacity = capacity;
1335 nlrt->localframes = lrt->localframes + 1;
1338 /* store new local reference table in thread */
1340 LOCALREFTABLE = nlrt;
1346 /* PopLocalFrame ***************************************************************
1348 Pops off the current local reference frame, frees all the local
1349 references, and returns a local reference in the previous local
1350 reference frame for the given result object.
1352 *******************************************************************************/
1354 jobject PopLocalFrame(JNIEnv* env, jobject result)
1356 localref_table *lrt;
1357 localref_table *plrt;
1360 STATISTICS(jniinvokation());
1362 /* get current local reference table from thread */
1364 lrt = LOCALREFTABLE;
1366 localframes = lrt->localframes;
1368 /* Don't delete the top local frame, as this one is allocated in
1369 the native stub on the stack and is freed automagically on
1372 if (localframes == 1)
1373 return NewLocalRef(env, result);
1375 /* release all current local frames */
1377 for (; localframes >= 1; localframes--) {
1378 /* get previous frame */
1382 /* clear all reference entries */
1384 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1388 /* set new local references table */
1393 /* store new local reference table in thread */
1395 LOCALREFTABLE = lrt;
1397 /* add local reference and return the value */
1399 return NewLocalRef(env, result);
1403 /* DeleteLocalRef **************************************************************
1405 Deletes the local reference pointed to by localRef.
1407 *******************************************************************************/
1409 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1411 java_objectheader *o;
1412 localref_table *lrt;
1415 STATISTICS(jniinvokation());
1417 o = (java_objectheader *) localRef;
1419 /* get local reference table (thread specific) */
1421 lrt = LOCALREFTABLE;
1423 /* go through all local frames */
1425 for (; lrt != NULL; lrt = lrt->prev) {
1427 /* and try to remove the reference */
1429 for (i = 0; i < lrt->capacity; i++) {
1430 if (lrt->refs[i] == o) {
1431 lrt->refs[i] = NULL;
1439 /* this should not happen */
1441 /* if (opt_checkjni) */
1442 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1443 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1447 /* IsSameObject ****************************************************************
1449 Tests whether two references refer to the same Java object.
1451 *******************************************************************************/
1453 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1455 STATISTICS(jniinvokation());
1464 /* NewLocalRef *****************************************************************
1466 Creates a new local reference that refers to the same object as ref.
1468 *******************************************************************************/
1470 jobject NewLocalRef(JNIEnv *env, jobject ref)
1472 localref_table *lrt;
1475 STATISTICS(jniinvokation());
1480 /* get local reference table (thread specific) */
1482 lrt = LOCALREFTABLE;
1484 /* Check if we have space for the requested reference? No,
1485 allocate a new frame. This is actually not what the spec says,
1486 but for compatibility reasons... */
1488 if (lrt->used == lrt->capacity) {
1489 if (EnsureLocalCapacity(env, 16) != 0)
1492 /* get the new local reference table */
1494 lrt = LOCALREFTABLE;
1497 /* insert the reference */
1499 for (i = 0; i < lrt->capacity; i++) {
1500 if (lrt->refs[i] == NULL) {
1501 lrt->refs[i] = (java_objectheader *) ref;
1508 /* should not happen, just to be sure */
1512 /* keep compiler happy */
1518 /* EnsureLocalCapacity *********************************************************
1520 Ensures that at least a given number of local references can be
1521 created in the current thread
1523 *******************************************************************************/
1525 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1527 localref_table *lrt;
1529 log_text("JNI-Call: EnsureLocalCapacity");
1531 STATISTICS(jniinvokation());
1533 /* get local reference table (thread specific) */
1535 lrt = LOCALREFTABLE;
1537 /* check if capacity elements are available in the local references table */
1539 if ((lrt->used + capacity) > lrt->capacity)
1540 return PushLocalFrame(env, capacity);
1546 /* AllocObject *****************************************************************
1548 Allocates a new Java object without invoking any of the
1549 constructors for the object. Returns a reference to the object.
1551 *******************************************************************************/
1553 jobject AllocObject(JNIEnv *env, jclass clazz)
1556 java_objectheader *o;
1558 STATISTICS(jniinvokation());
1560 c = (classinfo *) clazz;
1562 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1564 new_exception_utfmessage(string_java_lang_InstantiationException,
1571 return NewLocalRef(env, o);
1575 /* NewObject *******************************************************************
1577 Programmers place all arguments that are to be passed to the
1578 constructor immediately following the methodID
1579 argument. NewObject() accepts these arguments and passes them to
1580 the Java method that the programmer wishes to invoke.
1582 *******************************************************************************/
1584 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1586 java_objectheader *o;
1590 STATISTICS(jniinvokation());
1592 m = (methodinfo *) methodID;
1596 o = builtin_new(clazz);
1601 /* call constructor */
1603 va_start(ap, methodID);
1604 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1607 return NewLocalRef(env, o);
1611 /* NewObjectV ******************************************************************
1613 Programmers place all arguments that are to be passed to the
1614 constructor in an args argument of type va_list that immediately
1615 follows the methodID argument. NewObjectV() accepts these
1616 arguments, and, in turn, passes them to the Java method that the
1617 programmer wishes to invoke.
1619 *******************************************************************************/
1621 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1623 java_objectheader *o;
1626 STATISTICS(jniinvokation());
1628 m = (methodinfo *) methodID;
1632 o = builtin_new(clazz);
1637 /* call constructor */
1639 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1641 return NewLocalRef(env, o);
1645 /* NewObjectA *****************************************************************
1647 Programmers place all arguments that are to be passed to the
1648 constructor in an args array of jvalues that immediately follows
1649 the methodID argument. NewObjectA() accepts the arguments in this
1650 array, and, in turn, passes them to the Java method that the
1651 programmer wishes to invoke.
1653 *******************************************************************************/
1655 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1657 java_objectheader *o;
1660 STATISTICS(jniinvokation());
1662 m = (methodinfo *) methodID;
1666 o = builtin_new(clazz);
1671 /* call constructor */
1673 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1675 return NewLocalRef(env, o);
1679 /* GetObjectClass **************************************************************
1681 Returns the class of an object.
1683 *******************************************************************************/
1685 jclass GetObjectClass(JNIEnv *env, jobject obj)
1687 java_objectheader *o;
1690 STATISTICS(jniinvokation());
1692 o = (java_objectheader *) obj;
1694 if ((o == NULL) || (o->vftbl == NULL))
1697 c = o->vftbl->class;
1699 return (jclass) NewLocalRef(env, (jobject) c);
1703 /* IsInstanceOf ****************************************************************
1705 Tests whether an object is an instance of a class.
1707 *******************************************************************************/
1709 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1711 STATISTICS(jniinvokation());
1713 return Java_java_lang_VMClass_isInstance(env,
1715 (java_lang_Class *) clazz,
1716 (java_lang_Object *) obj);
1720 /* Reflection Support *********************************************************/
1722 /* FromReflectedMethod *********************************************************
1724 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1725 object to a method ID.
1727 *******************************************************************************/
1729 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1735 STATISTICS(jniinvokation());
1740 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1741 java_lang_reflect_Method *rm;
1743 rm = (java_lang_reflect_Method *) method;
1744 c = (classinfo *) (rm->declaringClass);
1747 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1748 java_lang_reflect_Constructor *rc;
1750 rc = (java_lang_reflect_Constructor *) method;
1751 c = (classinfo *) (rc->clazz);
1757 mi = &(c->methods[slot]);
1759 return (jmethodID) mi;
1763 /* FromReflectedField **********************************************************
1765 Converts a java.lang.reflect.Field to a field ID.
1767 *******************************************************************************/
1769 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1771 java_lang_reflect_Field *rf;
1775 STATISTICS(jniinvokation());
1777 rf = (java_lang_reflect_Field *) field;
1782 c = (classinfo *) rf->declaringClass;
1784 f = &(c->fields[rf->slot]);
1786 return (jfieldID) f;
1790 /* ToReflectedMethod ***********************************************************
1792 Converts a method ID derived from cls to an instance of the
1793 java.lang.reflect.Method class or to an instance of the
1794 java.lang.reflect.Constructor class.
1796 *******************************************************************************/
1798 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1800 STATISTICS(jniinvokation());
1802 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1808 /* ToReflectedField ************************************************************
1810 Converts a field ID derived from cls to an instance of the
1811 java.lang.reflect.Field class.
1813 *******************************************************************************/
1815 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1818 STATISTICS(jniinvokation());
1820 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1826 /* Calling Instance Methods ***************************************************/
1828 /* GetMethodID *****************************************************************
1830 Returns the method ID for an instance (nonstatic) method of a class
1831 or interface. The method may be defined in one of the clazz's
1832 superclasses and inherited by clazz. The method is determined by
1833 its name and signature.
1835 GetMethodID() causes an uninitialized class to be initialized.
1837 *******************************************************************************/
1839 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1847 STATISTICS(jniinvokation());
1849 c = (classinfo *) clazz;
1854 if (!(c->state & CLASS_INITIALIZED))
1855 if (!initialize_class(c))
1858 /* try to get the method of the class or one of it's superclasses */
1860 uname = utf_new_char((char *) name);
1861 udesc = utf_new_char((char *) sig);
1863 m = class_resolvemethod(clazz, uname, udesc);
1865 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1866 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1871 return (jmethodID) m;
1875 /* JNI-functions for calling instance methods *********************************/
1877 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1879 java_objectheader *o;
1881 java_objectheader *ret;
1884 o = (java_objectheader *) obj;
1885 m = (methodinfo *) methodID;
1887 va_start(ap, methodID);
1888 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1891 return NewLocalRef(env, ret);
1895 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1897 java_objectheader *o;
1899 java_objectheader *ret;
1901 o = (java_objectheader *) obj;
1902 m = (methodinfo *) methodID;
1904 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1906 return NewLocalRef(env, ret);
1910 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1912 java_objectheader *o;
1914 java_objectheader *ret;
1916 o = (java_objectheader *) obj;
1917 m = (methodinfo *) methodID;
1919 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1921 return NewLocalRef(env, ret);
1925 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1927 java_objectheader *o;
1932 o = (java_objectheader *) obj;
1933 m = (methodinfo *) methodID;
1935 va_start(ap, methodID);
1936 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1943 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1945 java_objectheader *o;
1949 o = (java_objectheader *) obj;
1950 m = (methodinfo *) methodID;
1952 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1958 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1960 java_objectheader *o;
1964 o = (java_objectheader *) obj;
1965 m = (methodinfo *) methodID;
1967 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1973 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1975 java_objectheader *o;
1980 o = (java_objectheader *) obj;
1981 m = (methodinfo *) methodID;
1983 va_start(ap, methodID);
1984 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1991 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1993 java_objectheader *o;
1997 o = (java_objectheader *) obj;
1998 m = (methodinfo *) methodID;
2000 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2006 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2008 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2014 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2016 java_objectheader *o;
2021 o = (java_objectheader *) obj;
2022 m = (methodinfo *) methodID;
2024 va_start(ap, methodID);
2025 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2032 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2034 java_objectheader *o;
2038 o = (java_objectheader *) obj;
2039 m = (methodinfo *) methodID;
2041 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2047 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2049 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2055 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2057 java_objectheader *o;
2062 o = (java_objectheader *) obj;
2063 m = (methodinfo *) methodID;
2065 va_start(ap, methodID);
2066 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2073 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2075 java_objectheader *o;
2079 o = (java_objectheader *) obj;
2080 m = (methodinfo *) methodID;
2082 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2088 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2090 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2097 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2099 java_objectheader *o;
2104 o = (java_objectheader *) obj;
2105 m = (methodinfo *) methodID;
2107 va_start(ap, methodID);
2108 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2115 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2117 java_objectheader *o;
2121 o = (java_objectheader *) obj;
2122 m = (methodinfo *) methodID;
2124 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2130 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2132 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2139 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2141 java_objectheader *o;
2146 o = (java_objectheader *) obj;
2147 m = (methodinfo *) methodID;
2149 va_start(ap, methodID);
2150 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2157 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2159 java_objectheader *o;
2163 o = (java_objectheader *) obj;
2164 m = (methodinfo *) methodID;
2166 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2172 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2174 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2181 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2183 java_objectheader *o;
2188 o = (java_objectheader *) obj;
2189 m = (methodinfo *) methodID;
2191 va_start(ap, methodID);
2192 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2199 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2201 java_objectheader *o;
2205 o = (java_objectheader *) obj;
2206 m = (methodinfo *) methodID;
2208 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2214 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2216 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2223 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2225 java_objectheader *o;
2230 o = (java_objectheader *) obj;
2231 m = (methodinfo *) methodID;
2233 va_start(ap, methodID);
2234 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2241 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2243 java_objectheader *o;
2247 o = (java_objectheader *) obj;
2248 m = (methodinfo *) methodID;
2250 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2256 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2258 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2265 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2267 java_objectheader *o;
2271 o = (java_objectheader *) obj;
2272 m = (methodinfo *) methodID;
2274 va_start(ap, methodID);
2275 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2280 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2282 java_objectheader *o;
2285 o = (java_objectheader *) obj;
2286 m = (methodinfo *) methodID;
2288 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2292 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2294 java_objectheader *o;
2297 o = (java_objectheader *) obj;
2298 m = (methodinfo *) methodID;
2300 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2305 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2307 java_objectheader *o;
2310 java_objectheader *r;
2313 o = (java_objectheader *) obj;
2314 c = (classinfo *) clazz;
2315 m = (methodinfo *) methodID;
2317 va_start(ap, methodID);
2318 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2321 return NewLocalRef(env, r);
2325 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2327 java_objectheader *o;
2330 java_objectheader *r;
2332 o = (java_objectheader *) obj;
2333 c = (classinfo *) clazz;
2334 m = (methodinfo *) methodID;
2336 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2338 return NewLocalRef(env, r);
2342 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2344 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2346 return NewLocalRef(env, NULL);
2351 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2353 java_objectheader *o;
2359 o = (java_objectheader *) obj;
2360 c = (classinfo *) clazz;
2361 m = (methodinfo *) methodID;
2363 va_start(ap, methodID);
2364 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2371 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2373 java_objectheader *o;
2378 o = (java_objectheader *) obj;
2379 c = (classinfo *) clazz;
2380 m = (methodinfo *) methodID;
2382 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2388 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2390 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2396 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2398 java_objectheader *o;
2404 o = (java_objectheader *) obj;
2405 c = (classinfo *) clazz;
2406 m = (methodinfo *) methodID;
2408 va_start(ap, methodID);
2409 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2416 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2418 java_objectheader *o;
2423 o = (java_objectheader *) obj;
2424 c = (classinfo *) clazz;
2425 m = (methodinfo *) methodID;
2427 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2433 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2435 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2442 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2444 java_objectheader *o;
2450 o = (java_objectheader *) obj;
2451 c = (classinfo *) clazz;
2452 m = (methodinfo *) methodID;
2454 va_start(ap, methodID);
2455 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2462 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2464 java_objectheader *o;
2469 o = (java_objectheader *) obj;
2470 c = (classinfo *) clazz;
2471 m = (methodinfo *) methodID;
2473 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2479 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2481 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2488 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2490 java_objectheader *o;
2496 o = (java_objectheader *) obj;
2497 c = (classinfo *) clazz;
2498 m = (methodinfo *) methodID;
2500 va_start(ap, methodID);
2501 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2508 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2510 java_objectheader *o;
2515 o = (java_objectheader *) obj;
2516 c = (classinfo *) clazz;
2517 m = (methodinfo *) methodID;
2519 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2525 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2527 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2534 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2536 java_objectheader *o;
2542 o = (java_objectheader *) obj;
2543 c = (classinfo *) clazz;
2544 m = (methodinfo *) methodID;
2546 va_start(ap, methodID);
2547 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2554 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2556 java_objectheader *o;
2561 o = (java_objectheader *) obj;
2562 c = (classinfo *) clazz;
2563 m = (methodinfo *) methodID;
2565 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2571 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2573 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2580 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2582 java_objectheader *o;
2588 o = (java_objectheader *) obj;
2589 c = (classinfo *) clazz;
2590 m = (methodinfo *) methodID;
2592 va_start(ap, methodID);
2593 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2600 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2602 java_objectheader *o;
2607 o = (java_objectheader *) obj;
2608 c = (classinfo *) clazz;
2609 m = (methodinfo *) methodID;
2611 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2617 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2619 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2626 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2628 java_objectheader *o;
2634 o = (java_objectheader *) obj;
2635 c = (classinfo *) clazz;
2636 m = (methodinfo *) methodID;
2638 va_start(ap, methodID);
2639 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2646 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2648 java_objectheader *o;
2653 o = (java_objectheader *) obj;
2654 c = (classinfo *) clazz;
2655 m = (methodinfo *) methodID;
2657 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2663 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2665 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2672 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2674 java_objectheader *o;
2680 o = (java_objectheader *) obj;
2681 c = (classinfo *) clazz;
2682 m = (methodinfo *) methodID;
2684 va_start(ap, methodID);
2685 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2692 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2694 java_objectheader *o;
2699 o = (java_objectheader *) obj;
2700 c = (classinfo *) clazz;
2701 m = (methodinfo *) methodID;
2703 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2709 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2711 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2718 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2720 java_objectheader *o;
2725 o = (java_objectheader *) obj;
2726 c = (classinfo *) clazz;
2727 m = (methodinfo *) methodID;
2729 va_start(ap, methodID);
2730 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2735 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2737 java_objectheader *o;
2741 o = (java_objectheader *) obj;
2742 c = (classinfo *) clazz;
2743 m = (methodinfo *) methodID;
2745 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2749 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2751 java_objectheader *o;
2755 o = (java_objectheader *) obj;
2756 c = (classinfo *) clazz;
2757 m = (methodinfo *) methodID;
2759 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2763 /* Accessing Fields of Objects ************************************************/
2765 /* GetFieldID ******************************************************************
2767 Returns the field ID for an instance (nonstatic) field of a
2768 class. The field is specified by its name and signature. The
2769 Get<type>Field and Set<type>Field families of accessor functions
2770 use field IDs to retrieve object fields.
2772 *******************************************************************************/
2774 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2781 STATISTICS(jniinvokation());
2783 uname = utf_new_char((char *) name);
2784 udesc = utf_new_char((char *) sig);
2786 f = class_findfield(clazz, uname, udesc);
2789 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2791 return (jfieldID) f;
2795 /* Get<type>Field Routines *****************************************************
2797 This family of accessor routines returns the value of an instance
2798 (nonstatic) field of an object. The field to access is specified by
2799 a field ID obtained by calling GetFieldID().
2801 *******************************************************************************/
2803 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2805 java_objectheader *o;
2807 STATISTICS(jniinvokation());
2809 o = GET_FIELD(obj, java_objectheader*, fieldID);
2811 return NewLocalRef(env, o);
2815 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2819 STATISTICS(jniinvokation());
2821 i = GET_FIELD(obj, s4, fieldID);
2823 return (jboolean) i;
2827 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2831 STATISTICS(jniinvokation());
2833 i = GET_FIELD(obj, s4, fieldID);
2839 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2843 STATISTICS(jniinvokation());
2845 i = GET_FIELD(obj, s4, fieldID);
2851 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2855 STATISTICS(jniinvokation());
2857 i = GET_FIELD(obj, s4, fieldID);
2863 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2865 java_objectheader *o;
2869 STATISTICS(jniinvokation());
2871 o = (java_objectheader *) obj;
2872 f = (fieldinfo *) fieldID;
2874 i = GET_FIELD(o, s4, f);
2880 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2884 STATISTICS(jniinvokation());
2886 l = GET_FIELD(obj, s8, fieldID);
2892 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2896 STATISTICS(jniinvokation());
2898 f = GET_FIELD(obj, float, fieldID);
2904 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2908 STATISTICS(jniinvokation());
2910 d = GET_FIELD(obj, double, fieldID);
2916 /* Set<type>Field Routines *****************************************************
2918 This family of accessor routines sets the value of an instance
2919 (nonstatic) field of an object. The field to access is specified by
2920 a field ID obtained by calling GetFieldID().
2922 *******************************************************************************/
2924 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2926 STATISTICS(jniinvokation());
2928 SET_FIELD(obj, java_objectheader*, fieldID, value);
2932 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2934 STATISTICS(jniinvokation());
2936 SET_FIELD(obj, s4, fieldID, value);
2940 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2942 STATISTICS(jniinvokation());
2944 SET_FIELD(obj, s4, fieldID, value);
2948 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2950 STATISTICS(jniinvokation());
2952 SET_FIELD(obj, s4, fieldID, value);
2956 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2958 STATISTICS(jniinvokation());
2960 SET_FIELD(obj, s4, fieldID, value);
2964 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2966 STATISTICS(jniinvokation());
2968 SET_FIELD(obj, s4, fieldID, value);
2972 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2974 STATISTICS(jniinvokation());
2976 SET_FIELD(obj, s8, fieldID, value);
2980 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
2982 STATISTICS(jniinvokation());
2984 SET_FIELD(obj, float, fieldID, value);
2988 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
2990 STATISTICS(jniinvokation());
2992 SET_FIELD(obj, double, fieldID, value);
2996 /* Calling Static Methods *****************************************************/
2998 /* GetStaticMethodID ***********************************************************
3000 Returns the method ID for a static method of a class. The method is
3001 specified by its name and signature.
3003 GetStaticMethodID() causes an uninitialized class to be
3006 *******************************************************************************/
3008 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3016 STATISTICS(jniinvokation());
3018 c = (classinfo *) clazz;
3023 if (!(c->state & CLASS_INITIALIZED))
3024 if (!initialize_class(c))
3027 /* try to get the static method of the class */
3029 uname = utf_new_char((char *) name);
3030 udesc = utf_new_char((char *) sig);
3032 m = class_resolvemethod(c, uname, udesc);
3034 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3035 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3040 return (jmethodID) m;
3044 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3047 java_objectheader *o;
3050 m = (methodinfo *) methodID;
3052 va_start(ap, methodID);
3053 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3056 return NewLocalRef(env, o);
3060 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3063 java_objectheader *o;
3065 m = (methodinfo *) methodID;
3067 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3069 return NewLocalRef(env, o);
3073 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3076 java_objectheader *o;
3078 m = (methodinfo *) methodID;
3080 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3082 return NewLocalRef(env, o);
3086 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3092 m = (methodinfo *) methodID;
3094 va_start(ap, methodID);
3095 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3102 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3107 m = (methodinfo *) methodID;
3109 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3115 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3117 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3123 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3129 m = (methodinfo *) methodID;
3131 va_start(ap, methodID);
3132 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3139 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3144 m = (methodinfo *) methodID;
3146 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3152 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3154 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3160 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3166 m = (methodinfo *) methodID;
3168 va_start(ap, methodID);
3169 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3176 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3181 m = (methodinfo *) methodID;
3183 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3189 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3191 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3197 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3203 m = (methodinfo *) methodID;
3205 va_start(ap, methodID);
3206 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3213 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3218 m = (methodinfo *) methodID;
3220 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3226 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3228 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3234 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3240 m = (methodinfo *) methodID;
3242 va_start(ap, methodID);
3243 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3250 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3255 m = (methodinfo *) methodID;
3257 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3263 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3265 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3271 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3277 m = (methodinfo *) methodID;
3279 va_start(ap, methodID);
3280 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3287 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3293 m = (methodinfo *) methodID;
3295 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3301 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3303 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3310 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3316 m = (methodinfo *) methodID;
3318 va_start(ap, methodID);
3319 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3326 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3331 m = (methodinfo *) methodID;
3333 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3339 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3341 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3347 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3353 m = (methodinfo *) methodID;
3355 va_start(ap, methodID);
3356 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3363 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3368 m = (methodinfo *) methodID;
3370 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3376 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3378 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3384 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3389 m = (methodinfo *) methodID;
3391 va_start(ap, methodID);
3392 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3397 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3401 m = (methodinfo *) methodID;
3403 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3407 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3411 m = (methodinfo *) methodID;
3413 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3417 /* Accessing Static Fields ****************************************************/
3419 /* GetStaticFieldID ************************************************************
3421 Returns the field ID for a static field of a class. The field is
3422 specified by its name and signature. The GetStatic<type>Field and
3423 SetStatic<type>Field families of accessor functions use field IDs
3424 to retrieve static fields.
3426 *******************************************************************************/
3428 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3432 STATISTICS(jniinvokation());
3434 f = class_findfield(clazz,
3435 utf_new_char((char *) name),
3436 utf_new_char((char *) sig));
3439 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3441 return (jfieldID) f;
3445 /* GetStatic<type>Field ********************************************************
3447 This family of accessor routines returns the value of a static
3450 *******************************************************************************/
3452 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3457 STATISTICS(jniinvokation());
3459 c = (classinfo *) clazz;
3460 f = (fieldinfo *) fieldID;
3462 if (!(c->state & CLASS_INITIALIZED))
3463 if (!initialize_class(c))
3466 return NewLocalRef(env, f->value.a);
3470 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3475 STATISTICS(jniinvokation());
3477 c = (classinfo *) clazz;
3478 f = (fieldinfo *) fieldID;
3480 if (!(c->state & CLASS_INITIALIZED))
3481 if (!initialize_class(c))
3488 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3493 STATISTICS(jniinvokation());
3495 c = (classinfo *) clazz;
3496 f = (fieldinfo *) fieldID;
3498 if (!(c->state & CLASS_INITIALIZED))
3499 if (!initialize_class(c))
3506 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3511 STATISTICS(jniinvokation());
3513 c = (classinfo *) clazz;
3514 f = (fieldinfo *) fieldID;
3516 if (!(c->state & CLASS_INITIALIZED))
3517 if (!initialize_class(c))
3524 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3529 STATISTICS(jniinvokation());
3531 c = (classinfo *) clazz;
3532 f = (fieldinfo *) fieldID;
3534 if (!(c->state & CLASS_INITIALIZED))
3535 if (!initialize_class(c))
3542 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3547 STATISTICS(jniinvokation());
3549 c = (classinfo *) clazz;
3550 f = (fieldinfo *) fieldID;
3552 if (!(c->state & CLASS_INITIALIZED))
3553 if (!initialize_class(c))
3560 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3565 STATISTICS(jniinvokation());
3567 c = (classinfo *) clazz;
3568 f = (fieldinfo *) fieldID;
3570 if (!(c->state & CLASS_INITIALIZED))
3571 if (!initialize_class(c))
3578 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3583 STATISTICS(jniinvokation());
3585 c = (classinfo *) clazz;
3586 f = (fieldinfo *) fieldID;
3588 if (!(c->state & CLASS_INITIALIZED))
3589 if (!initialize_class(c))
3596 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3601 STATISTICS(jniinvokation());
3603 c = (classinfo *) clazz;
3604 f = (fieldinfo *) fieldID;
3606 if (!(c->state & CLASS_INITIALIZED))
3607 if (!initialize_class(c))
3614 /* SetStatic<type>Field *******************************************************
3616 This family of accessor routines sets the value of a static field
3619 *******************************************************************************/
3621 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3626 STATISTICS(jniinvokation());
3628 c = (classinfo *) clazz;
3629 f = (fieldinfo *) fieldID;
3631 if (!(c->state & CLASS_INITIALIZED))
3632 if (!initialize_class(c))
3639 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3644 STATISTICS(jniinvokation());
3646 c = (classinfo *) clazz;
3647 f = (fieldinfo *) fieldID;
3649 if (!(c->state & CLASS_INITIALIZED))
3650 if (!initialize_class(c))
3657 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3662 STATISTICS(jniinvokation());
3664 c = (classinfo *) clazz;
3665 f = (fieldinfo *) fieldID;
3667 if (!(c->state & CLASS_INITIALIZED))
3668 if (!initialize_class(c))
3675 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3680 STATISTICS(jniinvokation());
3682 c = (classinfo *) clazz;
3683 f = (fieldinfo *) fieldID;
3685 if (!(c->state & CLASS_INITIALIZED))
3686 if (!initialize_class(c))
3693 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3698 STATISTICS(jniinvokation());
3700 c = (classinfo *) clazz;
3701 f = (fieldinfo *) fieldID;
3703 if (!(c->state & CLASS_INITIALIZED))
3704 if (!initialize_class(c))
3711 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3716 STATISTICS(jniinvokation());
3718 c = (classinfo *) clazz;
3719 f = (fieldinfo *) fieldID;
3721 if (!(c->state & CLASS_INITIALIZED))
3722 if (!initialize_class(c))
3729 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3734 STATISTICS(jniinvokation());
3736 c = (classinfo *) clazz;
3737 f = (fieldinfo *) fieldID;
3739 if (!(c->state & CLASS_INITIALIZED))
3740 if (!initialize_class(c))
3747 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3752 STATISTICS(jniinvokation());
3754 c = (classinfo *) clazz;
3755 f = (fieldinfo *) fieldID;
3757 if (!(c->state & CLASS_INITIALIZED))
3758 if (!initialize_class(c))
3765 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3770 STATISTICS(jniinvokation());
3772 c = (classinfo *) clazz;
3773 f = (fieldinfo *) fieldID;
3775 if (!(c->state & CLASS_INITIALIZED))
3776 if (!initialize_class(c))
3783 /* String Operations **********************************************************/
3785 /* NewString *******************************************************************
3787 Create new java.lang.String object from an array of Unicode
3790 *******************************************************************************/
3792 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3794 java_lang_String *s;
3798 STATISTICS(jniinvokation());
3800 s = (java_lang_String *) builtin_new(class_java_lang_String);
3801 a = builtin_newarray_char(len);
3803 /* javastring or characterarray could not be created */
3808 for (i = 0; i < len; i++)
3809 a->data[i] = buf[i];
3815 return (jstring) NewLocalRef(env, (jobject) s);
3819 static jchar emptyStringJ[]={0,0};
3821 /* GetStringLength *************************************************************
3823 Returns the length (the count of Unicode characters) of a Java
3826 *******************************************************************************/
3828 jsize GetStringLength(JNIEnv *env, jstring str)
3830 return ((java_lang_String *) str)->count;
3834 /******************** convertes javastring to u2-array ****************************/
3836 u2 *javastring_tou2(jstring so)
3838 java_lang_String *s;
3843 STATISTICS(jniinvokation());
3845 s = (java_lang_String *) so;
3855 /* allocate memory */
3857 stringbuffer = MNEW(u2, s->count + 1);
3861 for (i = 0; i < s->count; i++)
3862 stringbuffer[i] = a->data[s->offset + i];
3864 /* terminate string */
3866 stringbuffer[i] = '\0';
3868 return stringbuffer;
3872 /* GetStringChars **************************************************************
3874 Returns a pointer to the array of Unicode characters of the
3875 string. This pointer is valid until ReleaseStringchars() is called.
3877 *******************************************************************************/
3879 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3883 STATISTICS(jniinvokation());
3885 jc = javastring_tou2(str);
3897 return emptyStringJ;
3901 /* ReleaseStringChars **********************************************************
3903 Informs the VM that the native code no longer needs access to
3904 chars. The chars argument is a pointer obtained from string using
3907 *******************************************************************************/
3909 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3911 STATISTICS(jniinvokation());
3913 if (chars == emptyStringJ)
3916 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3920 /* NewStringUTF ****************************************************************
3922 Constructs a new java.lang.String object from an array of UTF-8 characters.
3924 *******************************************************************************/
3926 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3928 java_lang_String *s;
3930 STATISTICS(jniinvokation());
3932 s = javastring_new(utf_new_char(bytes));
3934 return (jstring) NewLocalRef(env, (jobject) s);
3938 /****************** returns the utf8 length in bytes of a string *******************/
3940 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3942 java_lang_String *s = (java_lang_String*) string;
3944 STATISTICS(jniinvokation());
3946 return (jsize) u2_utflength(s->value->data, s->count);
3950 /* GetStringUTFChars ***********************************************************
3952 Returns a pointer to an array of UTF-8 characters of the
3953 string. This array is valid until it is released by
3954 ReleaseStringUTFChars().
3956 *******************************************************************************/
3958 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3962 STATISTICS(jniinvokation());
3970 u = javastring_toutf((java_lang_String *) string, false);
3979 /* ReleaseStringUTFChars *******************************************************
3981 Informs the VM that the native code no longer needs access to
3982 utf. The utf argument is a pointer derived from string using
3983 GetStringUTFChars().
3985 *******************************************************************************/
3987 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
3989 STATISTICS(jniinvokation());
3991 /* XXX we don't release utf chars right now, perhaps that should be done
3992 later. Since there is always one reference the garbage collector will
3997 /* Array Operations ***********************************************************/
3999 /* GetArrayLength **************************************************************
4001 Returns the number of elements in the array.
4003 *******************************************************************************/
4005 jsize GetArrayLength(JNIEnv *env, jarray array)
4007 java_arrayheader *a;
4009 STATISTICS(jniinvokation());
4011 a = (java_arrayheader *) array;
4017 /* NewObjectArray **************************************************************
4019 Constructs a new array holding objects in class elementClass. All
4020 elements are initially set to initialElement.
4022 *******************************************************************************/
4024 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
4026 java_objectarray *oa;
4029 STATISTICS(jniinvokation());
4032 exceptions_throw_negativearraysizeexception();
4036 oa = builtin_anewarray(length, elementClass);
4041 /* set all elements to initialElement */
4043 for (i = 0; i < length; i++)
4044 oa->data[i] = initialElement;
4046 return (jobjectArray) NewLocalRef(env, (jobject) oa);
4050 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
4052 java_objectarray *oa;
4055 STATISTICS(jniinvokation());
4057 oa = (java_objectarray *) array;
4059 if (index >= oa->header.size) {
4060 exceptions_throw_arrayindexoutofboundsexception();
4064 o = oa->data[index];
4066 return NewLocalRef(env, o);
4070 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4072 java_objectarray *oa;
4073 java_objectheader *o;
4075 STATISTICS(jniinvokation());
4077 oa = (java_objectarray *) array;
4078 o = (java_objectheader *) val;
4080 if (index >= oa->header.size) {
4081 exceptions_throw_arrayindexoutofboundsexception();
4085 /* check if the class of value is a subclass of the element class
4088 if (!builtin_canstore(oa, o)) {
4089 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4094 oa->data[index] = val;
4098 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4100 java_booleanarray *ba;
4102 STATISTICS(jniinvokation());
4105 exceptions_throw_negativearraysizeexception();
4109 ba = builtin_newarray_boolean(len);
4111 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4115 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4119 STATISTICS(jniinvokation());
4122 exceptions_throw_negativearraysizeexception();
4126 ba = builtin_newarray_byte(len);
4128 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4132 jcharArray NewCharArray(JNIEnv *env, jsize len)
4136 STATISTICS(jniinvokation());
4139 exceptions_throw_negativearraysizeexception();
4143 ca = builtin_newarray_char(len);
4145 return (jcharArray) NewLocalRef(env, (jobject) ca);
4149 jshortArray NewShortArray(JNIEnv *env, jsize len)
4151 java_shortarray *sa;
4153 STATISTICS(jniinvokation());
4156 exceptions_throw_negativearraysizeexception();
4160 sa = builtin_newarray_short(len);
4162 return (jshortArray) NewLocalRef(env, (jobject) sa);
4166 jintArray NewIntArray(JNIEnv *env, jsize len)
4170 STATISTICS(jniinvokation());
4173 exceptions_throw_negativearraysizeexception();
4177 ia = builtin_newarray_int(len);
4179 return (jintArray) NewLocalRef(env, (jobject) ia);
4183 jlongArray NewLongArray(JNIEnv *env, jsize len)
4187 STATISTICS(jniinvokation());
4190 exceptions_throw_negativearraysizeexception();
4194 la = builtin_newarray_long(len);
4196 return (jlongArray) NewLocalRef(env, (jobject) la);
4200 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4202 java_floatarray *fa;
4204 STATISTICS(jniinvokation());
4207 exceptions_throw_negativearraysizeexception();
4211 fa = builtin_newarray_float(len);
4213 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4217 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4219 java_doublearray *da;
4221 STATISTICS(jniinvokation());
4224 exceptions_throw_negativearraysizeexception();
4228 da = builtin_newarray_double(len);
4230 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4234 /* Get<PrimitiveType>ArrayElements *********************************************
4236 A family of functions that returns the body of the primitive array.
4238 *******************************************************************************/
4240 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4243 java_booleanarray *ba;
4245 STATISTICS(jniinvokation());
4247 ba = (java_booleanarray *) array;
4250 *isCopy = JNI_FALSE;
4256 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4260 STATISTICS(jniinvokation());
4262 ba = (java_bytearray *) array;
4265 *isCopy = JNI_FALSE;
4271 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4275 STATISTICS(jniinvokation());
4277 ca = (java_chararray *) array;
4280 *isCopy = JNI_FALSE;
4286 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4288 java_shortarray *sa;
4290 STATISTICS(jniinvokation());
4292 sa = (java_shortarray *) array;
4295 *isCopy = JNI_FALSE;
4301 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4305 STATISTICS(jniinvokation());
4307 ia = (java_intarray *) array;
4310 *isCopy = JNI_FALSE;
4316 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4320 STATISTICS(jniinvokation());
4322 la = (java_longarray *) array;
4325 *isCopy = JNI_FALSE;
4327 /* We cast this one to prevent a compiler warning on 64-bit
4328 systems since GNU Classpath typedef jlong to long long. */
4330 return (jlong *) la->data;
4334 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4336 java_floatarray *fa;
4338 STATISTICS(jniinvokation());
4340 fa = (java_floatarray *) array;
4343 *isCopy = JNI_FALSE;
4349 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4352 java_doublearray *da;
4354 STATISTICS(jniinvokation());
4356 da = (java_doublearray *) array;
4359 *isCopy = JNI_FALSE;
4365 /* Release<PrimitiveType>ArrayElements *****************************************
4367 A family of functions that informs the VM that the native code no
4368 longer needs access to elems. The elems argument is a pointer
4369 derived from array using the corresponding
4370 Get<PrimitiveType>ArrayElements() function. If necessary, this
4371 function copies back all changes made to elems to the original
4374 *******************************************************************************/
4376 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4377 jboolean *elems, jint mode)
4379 java_booleanarray *ba;
4381 STATISTICS(jniinvokation());
4383 ba = (java_booleanarray *) array;
4385 if (elems != ba->data) {
4388 MCOPY(ba->data, elems, u1, ba->header.size);
4391 MCOPY(ba->data, elems, u1, ba->header.size);
4392 /* XXX TWISTI how should it be freed? */
4395 /* XXX TWISTI how should it be freed? */
4402 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4407 STATISTICS(jniinvokation());
4409 ba = (java_bytearray *) array;
4411 if (elems != ba->data) {
4414 MCOPY(ba->data, elems, s1, ba->header.size);
4417 MCOPY(ba->data, elems, s1, ba->header.size);
4418 /* XXX TWISTI how should it be freed? */
4421 /* XXX TWISTI how should it be freed? */
4428 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4433 STATISTICS(jniinvokation());
4435 ca = (java_chararray *) array;
4437 if (elems != ca->data) {
4440 MCOPY(ca->data, elems, u2, ca->header.size);
4443 MCOPY(ca->data, elems, u2, ca->header.size);
4444 /* XXX TWISTI how should it be freed? */
4447 /* XXX TWISTI how should it be freed? */
4454 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4457 java_shortarray *sa;
4459 STATISTICS(jniinvokation());
4461 sa = (java_shortarray *) array;
4463 if (elems != sa->data) {
4466 MCOPY(sa->data, elems, s2, sa->header.size);
4469 MCOPY(sa->data, elems, s2, sa->header.size);
4470 /* XXX TWISTI how should it be freed? */
4473 /* XXX TWISTI how should it be freed? */
4480 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4485 STATISTICS(jniinvokation());
4487 ia = (java_intarray *) array;
4489 if (elems != ia->data) {
4492 MCOPY(ia->data, elems, s4, ia->header.size);
4495 MCOPY(ia->data, elems, s4, ia->header.size);
4496 /* XXX TWISTI how should it be freed? */
4499 /* XXX TWISTI how should it be freed? */
4506 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4511 STATISTICS(jniinvokation());
4513 la = (java_longarray *) array;
4515 /* We cast this one to prevent a compiler warning on 64-bit
4516 systems since GNU Classpath typedef jlong to long long. */
4518 if ((s8 *) elems != la->data) {
4521 MCOPY(la->data, elems, s8, la->header.size);
4524 MCOPY(la->data, elems, s8, la->header.size);
4525 /* XXX TWISTI how should it be freed? */
4528 /* XXX TWISTI how should it be freed? */
4535 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4538 java_floatarray *fa;
4540 STATISTICS(jniinvokation());
4542 fa = (java_floatarray *) array;
4544 if (elems != fa->data) {
4547 MCOPY(fa->data, elems, float, fa->header.size);
4550 MCOPY(fa->data, elems, float, fa->header.size);
4551 /* XXX TWISTI how should it be freed? */
4554 /* XXX TWISTI how should it be freed? */
4561 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4562 jdouble *elems, jint mode)
4564 java_doublearray *da;
4566 STATISTICS(jniinvokation());
4568 da = (java_doublearray *) array;
4570 if (elems != da->data) {
4573 MCOPY(da->data, elems, double, da->header.size);
4576 MCOPY(da->data, elems, double, da->header.size);
4577 /* XXX TWISTI how should it be freed? */
4580 /* XXX TWISTI how should it be freed? */
4587 /* Get<PrimitiveType>ArrayRegion **********************************************
4589 A family of functions that copies a region of a primitive array
4592 *******************************************************************************/
4594 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4595 jsize len, jboolean *buf)
4597 java_booleanarray *ba;
4599 STATISTICS(jniinvokation());
4601 ba = (java_booleanarray *) array;
4603 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4604 exceptions_throw_arrayindexoutofboundsexception();
4606 MCOPY(buf, &ba->data[start], u1, len);
4610 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4615 STATISTICS(jniinvokation());
4617 ba = (java_bytearray *) array;
4619 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4620 exceptions_throw_arrayindexoutofboundsexception();
4622 MCOPY(buf, &ba->data[start], s1, len);
4626 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4631 STATISTICS(jniinvokation());
4633 ca = (java_chararray *) array;
4635 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4636 exceptions_throw_arrayindexoutofboundsexception();
4638 MCOPY(buf, &ca->data[start], u2, len);
4642 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4643 jsize len, jshort *buf)
4645 java_shortarray *sa;
4647 STATISTICS(jniinvokation());
4649 sa = (java_shortarray *) array;
4651 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4652 exceptions_throw_arrayindexoutofboundsexception();
4654 MCOPY(buf, &sa->data[start], s2, len);
4658 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4663 STATISTICS(jniinvokation());
4665 ia = (java_intarray *) array;
4667 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4668 exceptions_throw_arrayindexoutofboundsexception();
4670 MCOPY(buf, &ia->data[start], s4, len);
4674 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4679 STATISTICS(jniinvokation());
4681 la = (java_longarray *) array;
4683 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4684 exceptions_throw_arrayindexoutofboundsexception();
4686 MCOPY(buf, &la->data[start], s8, len);
4690 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4691 jsize len, jfloat *buf)
4693 java_floatarray *fa;
4695 STATISTICS(jniinvokation());
4697 fa = (java_floatarray *) array;
4699 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4700 exceptions_throw_arrayindexoutofboundsexception();
4702 MCOPY(buf, &fa->data[start], float, len);
4706 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4707 jsize len, jdouble *buf)
4709 java_doublearray *da;
4711 STATISTICS(jniinvokation());
4713 da = (java_doublearray *) array;
4715 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4716 exceptions_throw_arrayindexoutofboundsexception();
4718 MCOPY(buf, &da->data[start], double, len);
4722 /* Set<PrimitiveType>ArrayRegion **********************************************
4724 A family of functions that copies back a region of a primitive
4725 array from a buffer.
4727 *******************************************************************************/
4729 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4730 jsize len, jboolean *buf)
4732 java_booleanarray *ba;
4734 STATISTICS(jniinvokation());
4736 ba = (java_booleanarray *) array;
4738 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4739 exceptions_throw_arrayindexoutofboundsexception();
4741 MCOPY(&ba->data[start], buf, u1, len);
4745 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4750 STATISTICS(jniinvokation());
4752 ba = (java_bytearray *) array;
4754 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4755 exceptions_throw_arrayindexoutofboundsexception();
4757 MCOPY(&ba->data[start], buf, s1, len);
4761 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4766 STATISTICS(jniinvokation());
4768 ca = (java_chararray *) array;
4770 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4771 exceptions_throw_arrayindexoutofboundsexception();
4773 MCOPY(&ca->data[start], buf, u2, len);
4777 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4778 jsize len, jshort *buf)
4780 java_shortarray *sa;
4782 STATISTICS(jniinvokation());
4784 sa = (java_shortarray *) array;
4786 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4787 exceptions_throw_arrayindexoutofboundsexception();
4789 MCOPY(&sa->data[start], buf, s2, len);
4793 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4798 STATISTICS(jniinvokation());
4800 ia = (java_intarray *) array;
4802 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4803 exceptions_throw_arrayindexoutofboundsexception();
4805 MCOPY(&ia->data[start], buf, s4, len);
4809 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4814 STATISTICS(jniinvokation());
4816 la = (java_longarray *) array;
4818 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4819 exceptions_throw_arrayindexoutofboundsexception();
4821 MCOPY(&la->data[start], buf, s8, len);
4825 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4826 jsize len, jfloat *buf)
4828 java_floatarray *fa;
4830 STATISTICS(jniinvokation());
4832 fa = (java_floatarray *) array;
4834 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4835 exceptions_throw_arrayindexoutofboundsexception();
4837 MCOPY(&fa->data[start], buf, float, len);
4841 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4842 jsize len, jdouble *buf)
4844 java_doublearray *da;
4846 STATISTICS(jniinvokation());
4848 da = (java_doublearray *) array;
4850 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4851 exceptions_throw_arrayindexoutofboundsexception();
4853 MCOPY(&da->data[start], buf, double, len);
4857 /* Registering Native Methods *************************************************/
4859 /* RegisterNatives *************************************************************
4861 Registers native methods with the class specified by the clazz
4862 argument. The methods parameter specifies an array of
4863 JNINativeMethod structures that contain the names, signatures, and
4864 function pointers of the native methods. The nMethods parameter
4865 specifies the number of native methods in the array.
4867 *******************************************************************************/
4869 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4872 STATISTICS(jniinvokation());
4874 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4875 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
4876 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
4883 /* UnregisterNatives ***********************************************************
4885 Unregisters native methods of a class. The class goes back to the
4886 state before it was linked or registered with its native method
4889 This function should not be used in normal native code. Instead, it
4890 provides special programs a way to reload and relink native
4893 *******************************************************************************/
4895 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4897 STATISTICS(jniinvokation());
4899 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4901 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4907 /* Monitor Operations *********************************************************/
4909 /* MonitorEnter ****************************************************************
4911 Enters the monitor associated with the underlying Java object
4914 *******************************************************************************/
4916 jint MonitorEnter(JNIEnv *env, jobject obj)
4918 STATISTICS(jniinvokation());
4921 exceptions_throw_nullpointerexception();
4925 LOCK_MONITOR_ENTER(obj);
4931 /* MonitorExit *****************************************************************
4933 The current thread must be the owner of the monitor associated with
4934 the underlying Java object referred to by obj. The thread
4935 decrements the counter indicating the number of times it has
4936 entered this monitor. If the value of the counter becomes zero, the
4937 current thread releases the monitor.
4939 *******************************************************************************/
4941 jint MonitorExit(JNIEnv *env, jobject obj)
4943 STATISTICS(jniinvokation());
4946 exceptions_throw_nullpointerexception();
4950 LOCK_MONITOR_EXIT(obj);
4956 /* JavaVM Interface ***********************************************************/
4958 /* GetJavaVM *******************************************************************
4960 Returns the Java VM interface (used in the Invocation API)
4961 associated with the current thread. The result is placed at the
4962 location pointed to by the second argument, vm.
4964 *******************************************************************************/
4966 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4968 STATISTICS(jniinvokation());
4970 *vm = (JavaVM *) _Jv_jvm;
4976 /* GetStringRegion *************************************************************
4978 Copies len number of Unicode characters beginning at offset start
4979 to the given buffer buf.
4981 Throws StringIndexOutOfBoundsException on index overflow.
4983 *******************************************************************************/
4985 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
4987 java_lang_String *s;
4990 STATISTICS(jniinvokation());
4992 s = (java_lang_String *) str;
4995 if ((start < 0) || (len < 0) || (start > s->count) ||
4996 (start + len > s->count)) {
4997 exceptions_throw_stringindexoutofboundsexception();
5001 MCOPY(buf, &ca->data[start], u2, len);
5005 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
5007 STATISTICS(jniinvokation());
5009 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5013 /* GetPrimitiveArrayCritical ***************************************************
5015 Obtain a direct pointer to array elements.
5017 *******************************************************************************/
5019 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
5024 ba = (java_bytearray *) array;
5026 /* do the same as Kaffe does */
5028 bp = GetByteArrayElements(env, ba, isCopy);
5034 /* ReleasePrimitiveArrayCritical ***********************************************
5036 No specific documentation.
5038 *******************************************************************************/
5040 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
5043 STATISTICS(jniinvokation());
5045 /* do the same as Kaffe does */
5047 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
5051 /* GetStringCritical ***********************************************************
5053 The semantics of these two functions are similar to the existing
5054 Get/ReleaseStringChars functions.
5056 *******************************************************************************/
5058 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5060 STATISTICS(jniinvokation());
5062 return GetStringChars(env, string, isCopy);
5066 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5068 STATISTICS(jniinvokation());
5070 ReleaseStringChars(env, string, cstring);
5074 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5076 STATISTICS(jniinvokation());
5078 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5084 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5086 STATISTICS(jniinvokation());
5088 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5092 /* NewGlobalRef ****************************************************************
5094 Creates a new global reference to the object referred to by the obj
5097 *******************************************************************************/
5099 jobject NewGlobalRef(JNIEnv* env, jobject obj)
5101 hashtable_global_ref_entry *gre;
5102 u4 key; /* hashkey */
5103 u4 slot; /* slot in hashtable */
5105 STATISTICS(jniinvokation());
5107 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5109 /* normally addresses are aligned to 4, 8 or 16 bytes */
5111 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5112 slot = key & (hashtable_global_ref->size - 1);
5113 gre = hashtable_global_ref->ptr[slot];
5115 /* search external hash chain for the entry */
5118 if (gre->o == obj) {
5119 /* global object found, increment the reference */
5123 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5128 gre = gre->hashlink; /* next element in external chain */
5131 /* global ref not found, create a new one */
5133 gre = NEW(hashtable_global_ref_entry);
5138 /* insert entry into hashtable */
5140 gre->hashlink = hashtable_global_ref->ptr[slot];
5142 hashtable_global_ref->ptr[slot] = gre;
5144 /* update number of hashtable-entries */
5146 hashtable_global_ref->entries++;
5148 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5154 /* DeleteGlobalRef *************************************************************
5156 Deletes the global reference pointed to by globalRef.
5158 *******************************************************************************/
5160 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5162 hashtable_global_ref_entry *gre;
5163 hashtable_global_ref_entry *prevgre;
5164 u4 key; /* hashkey */
5165 u4 slot; /* slot in hashtable */
5167 STATISTICS(jniinvokation());
5169 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5171 /* normally addresses are aligned to 4, 8 or 16 bytes */
5173 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5174 slot = key & (hashtable_global_ref->size - 1);
5175 gre = hashtable_global_ref->ptr[slot];
5177 /* initialize prevgre */
5181 /* search external hash chain for the entry */
5184 if (gre->o == globalRef) {
5185 /* global object found, decrement the reference count */
5189 /* if reference count is 0, remove the entry */
5191 if (gre->refs == 0) {
5192 /* special handling if it's the first in the chain */
5194 if (prevgre == NULL)
5195 hashtable_global_ref->ptr[slot] = gre->hashlink;
5197 prevgre->hashlink = gre->hashlink;
5199 FREE(gre, hashtable_global_ref_entry);
5202 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5207 prevgre = gre; /* save current pointer for removal */
5208 gre = gre->hashlink; /* next element in external chain */
5211 log_println("JNI-DeleteGlobalRef: global reference not found");
5213 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5217 /* ExceptionCheck **************************************************************
5219 Returns JNI_TRUE when there is a pending exception; otherwise,
5222 *******************************************************************************/
5224 jboolean ExceptionCheck(JNIEnv *env)
5226 STATISTICS(jniinvokation());
5228 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5232 /* New JNI 1.4 functions ******************************************************/
5234 /* NewDirectByteBuffer *********************************************************
5236 Allocates and returns a direct java.nio.ByteBuffer referring to the
5237 block of memory starting at the memory address address and
5238 extending capacity bytes.
5240 *******************************************************************************/
5242 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5244 java_objectheader *nbuf;
5245 #if SIZEOF_VOID_P == 8
5246 gnu_classpath_Pointer64 *paddress;
5248 gnu_classpath_Pointer32 *paddress;
5251 STATISTICS(jniinvokation());
5253 /* alocate a gnu.classpath.Pointer{32,64} object */
5255 #if SIZEOF_VOID_P == 8
5256 if (!(paddress = (gnu_classpath_Pointer64 *)
5257 builtin_new(class_gnu_classpath_Pointer64)))
5259 if (!(paddress = (gnu_classpath_Pointer32 *)
5260 builtin_new(class_gnu_classpath_Pointer32)))
5264 /* fill gnu.classpath.Pointer{32,64} with address */
5266 paddress->data = (ptrint) address;
5268 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5270 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5271 (jmethodID) dbbirw_init, NULL, paddress,
5272 (jint) capacity, (jint) capacity, (jint) 0);
5274 /* add local reference and return the value */
5276 return NewLocalRef(env, nbuf);
5280 /* GetDirectBufferAddress ******************************************************
5282 Fetches and returns the starting address of the memory region
5283 referenced by the given direct java.nio.Buffer.
5285 *******************************************************************************/
5287 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5289 java_nio_DirectByteBufferImpl *nbuf;
5290 #if SIZEOF_VOID_P == 8
5291 gnu_classpath_Pointer64 *address;
5293 gnu_classpath_Pointer32 *address;
5296 STATISTICS(jniinvokation());
5298 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5301 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5303 #if SIZEOF_VOID_P == 8
5304 address = (gnu_classpath_Pointer64 *) nbuf->address;
5306 address = (gnu_classpath_Pointer32 *) nbuf->address;
5309 if (address == NULL)
5312 return (void *) address->data;
5316 /* GetDirectBufferCapacity *****************************************************
5318 Fetches and returns the capacity in bytes of the memory region
5319 referenced by the given direct java.nio.Buffer.
5321 *******************************************************************************/
5323 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5325 java_nio_Buffer *nbuf;
5327 STATISTICS(jniinvokation());
5329 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5332 nbuf = (java_nio_Buffer *) buf;
5334 return (jlong) nbuf->cap;
5338 /* DestroyJavaVM ***************************************************************
5340 Unloads a Java VM and reclaims its resources. Only the main thread
5341 can unload the VM. The system waits until the main thread is only
5342 remaining user thread before it destroys the VM.
5344 *******************************************************************************/
5346 jint DestroyJavaVM(JavaVM *vm)
5350 STATISTICS(jniinvokation());
5352 status = vm_destroy(vm);
5358 /* AttachCurrentThread *********************************************************
5360 Attaches the current thread to a Java VM. Returns a JNI interface
5361 pointer in the JNIEnv argument.
5363 Trying to attach a thread that is already attached is a no-op.
5365 A native thread cannot be attached simultaneously to two Java VMs.
5367 When a thread is attached to the VM, the context class loader is
5368 the bootstrap loader.
5370 *******************************************************************************/
5372 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5374 STATISTICS(jniinvokation());
5376 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5384 jint DetachCurrentThread(JavaVM *vm)
5386 STATISTICS(jniinvokation());
5388 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5394 /* GetEnv **********************************************************************
5396 If the current thread is not attached to the VM, sets *env to NULL,
5397 and returns JNI_EDETACHED. If the specified version is not
5398 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5399 sets *env to the appropriate interface, and returns JNI_OK.
5401 *******************************************************************************/
5403 jint GetEnv(JavaVM *vm, void **env, jint version)
5405 STATISTICS(jniinvokation());
5407 #if defined(ENABLE_THREADS)
5408 if (threads_get_current_threadobject() == NULL) {
5411 return JNI_EDETACHED;
5415 /* check the JNI version */
5418 case JNI_VERSION_1_1:
5419 case JNI_VERSION_1_2:
5420 case JNI_VERSION_1_4:
5428 #if defined(ENABLE_JVMTI)
5429 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5430 == JVMTI_VERSION_INTERFACE_JVMTI) {
5432 *env = (void *) jvmti_new_environment();
5441 return JNI_EVERSION;
5446 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5448 STATISTICS(jniinvokation());
5450 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5456 /* JNI invocation table *******************************************************/
5458 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5464 AttachCurrentThread,
5465 DetachCurrentThread,
5467 AttachCurrentThreadAsDaemon
5471 /* JNI function table *********************************************************/
5473 struct JNINativeInterface _Jv_JNINativeInterface = {
5482 FromReflectedMethod,
5503 EnsureLocalCapacity,
5546 CallNonvirtualObjectMethod,
5547 CallNonvirtualObjectMethodV,
5548 CallNonvirtualObjectMethodA,
5549 CallNonvirtualBooleanMethod,
5550 CallNonvirtualBooleanMethodV,
5551 CallNonvirtualBooleanMethodA,
5552 CallNonvirtualByteMethod,
5553 CallNonvirtualByteMethodV,
5554 CallNonvirtualByteMethodA,
5555 CallNonvirtualCharMethod,
5556 CallNonvirtualCharMethodV,
5557 CallNonvirtualCharMethodA,
5558 CallNonvirtualShortMethod,
5559 CallNonvirtualShortMethodV,
5560 CallNonvirtualShortMethodA,
5561 CallNonvirtualIntMethod,
5562 CallNonvirtualIntMethodV,
5563 CallNonvirtualIntMethodA,
5564 CallNonvirtualLongMethod,
5565 CallNonvirtualLongMethodV,
5566 CallNonvirtualLongMethodA,
5567 CallNonvirtualFloatMethod,
5568 CallNonvirtualFloatMethodV,
5569 CallNonvirtualFloatMethodA,
5570 CallNonvirtualDoubleMethod,
5571 CallNonvirtualDoubleMethodV,
5572 CallNonvirtualDoubleMethodA,
5573 CallNonvirtualVoidMethod,
5574 CallNonvirtualVoidMethodV,
5575 CallNonvirtualVoidMethodA,
5600 CallStaticObjectMethod,
5601 CallStaticObjectMethodV,
5602 CallStaticObjectMethodA,
5603 CallStaticBooleanMethod,
5604 CallStaticBooleanMethodV,
5605 CallStaticBooleanMethodA,
5606 CallStaticByteMethod,
5607 CallStaticByteMethodV,
5608 CallStaticByteMethodA,
5609 CallStaticCharMethod,
5610 CallStaticCharMethodV,
5611 CallStaticCharMethodA,
5612 CallStaticShortMethod,
5613 CallStaticShortMethodV,
5614 CallStaticShortMethodA,
5615 CallStaticIntMethod,
5616 CallStaticIntMethodV,
5617 CallStaticIntMethodA,
5618 CallStaticLongMethod,
5619 CallStaticLongMethodV,
5620 CallStaticLongMethodA,
5621 CallStaticFloatMethod,
5622 CallStaticFloatMethodV,
5623 CallStaticFloatMethodA,
5624 CallStaticDoubleMethod,
5625 CallStaticDoubleMethodV,
5626 CallStaticDoubleMethodA,
5627 CallStaticVoidMethod,
5628 CallStaticVoidMethodV,
5629 CallStaticVoidMethodA,
5633 GetStaticObjectField,
5634 GetStaticBooleanField,
5637 GetStaticShortField,
5640 GetStaticFloatField,
5641 GetStaticDoubleField,
5642 SetStaticObjectField,
5643 SetStaticBooleanField,
5646 SetStaticShortField,
5649 SetStaticFloatField,
5650 SetStaticDoubleField,
5660 ReleaseStringUTFChars,
5665 GetObjectArrayElement,
5666 SetObjectArrayElement,
5677 GetBooleanArrayElements,
5678 GetByteArrayElements,
5679 GetCharArrayElements,
5680 GetShortArrayElements,
5681 GetIntArrayElements,
5682 GetLongArrayElements,
5683 GetFloatArrayElements,
5684 GetDoubleArrayElements,
5686 ReleaseBooleanArrayElements,
5687 ReleaseByteArrayElements,
5688 ReleaseCharArrayElements,
5689 ReleaseShortArrayElements,
5690 ReleaseIntArrayElements,
5691 ReleaseLongArrayElements,
5692 ReleaseFloatArrayElements,
5693 ReleaseDoubleArrayElements,
5695 GetBooleanArrayRegion,
5698 GetShortArrayRegion,
5701 GetFloatArrayRegion,
5702 GetDoubleArrayRegion,
5703 SetBooleanArrayRegion,
5706 SetShortArrayRegion,
5709 SetFloatArrayRegion,
5710 SetDoubleArrayRegion,
5720 /* new JNI 1.2 functions */
5725 GetPrimitiveArrayCritical,
5726 ReleasePrimitiveArrayCritical,
5729 ReleaseStringCritical,
5732 DeleteWeakGlobalRef,
5736 /* new JNI 1.4 functions */
5738 NewDirectByteBuffer,
5739 GetDirectBufferAddress,
5740 GetDirectBufferCapacity
5744 /* Invocation API Functions ***************************************************/
5746 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5748 Returns a default configuration for the Java VM.
5750 *******************************************************************************/
5752 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5754 JavaVMInitArgs *_vm_args;
5756 _vm_args = (JavaVMInitArgs *) vm_args;
5758 /* GNU classpath currently supports JNI 1.2 */
5760 switch (_vm_args->version) {
5761 case JNI_VERSION_1_1:
5762 _vm_args->version = JNI_VERSION_1_1;
5765 case JNI_VERSION_1_2:
5766 case JNI_VERSION_1_4:
5767 _vm_args->ignoreUnrecognized = JNI_FALSE;
5768 _vm_args->options = NULL;
5769 _vm_args->nOptions = 0;
5780 /* JNI_GetCreatedJavaVMs *******************************************************
5782 Returns all Java VMs that have been created. Pointers to VMs are written in
5783 the buffer vmBuf in the order they are created. At most bufLen number of
5784 entries will be written. The total number of created VMs is returned in
5787 *******************************************************************************/
5789 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5791 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5797 /* JNI_CreateJavaVM ************************************************************
5799 Loads and initializes a Java VM. The current thread becomes the main thread.
5800 Sets the env argument to the JNI interface pointer of the main thread.
5802 *******************************************************************************/
5804 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5806 JavaVMInitArgs *_vm_args;
5809 localref_table *lrt;
5811 /* get the arguments for the new JVM */
5813 _vm_args = (JavaVMInitArgs *) vm_args;
5815 /* get the VM and Env tables (must be set before vm_create) */
5817 env = NEW(_Jv_JNIEnv);
5818 env->env = &_Jv_JNINativeInterface;
5820 /* XXX Set the global variable. Maybe we should do that differently. */
5824 /* create and fill a JavaVM structure */
5826 vm = NEW(_Jv_JavaVM);
5827 vm->functions = &_Jv_JNIInvokeInterface;
5829 /* XXX Set the global variable. Maybe we should do that differently. */
5830 /* XXX JVMTI Agents needs a JavaVM */
5834 /* actually create the JVM */
5836 if (!vm_create(_vm_args)) {
5837 /* release allocated memory */
5839 FREE(env, _Jv_JNIEnv);
5840 FREE(vm, _Jv_JavaVM);
5845 /* setup the local ref table (must be created after vm_create) */
5847 lrt = GCNEW(localref_table);
5849 lrt->capacity = LOCALREFTABLE_CAPACITY;
5851 lrt->localframes = 1;
5852 lrt->prev = LOCALREFTABLE;
5854 /* clear the references array (memset is faster then a for-loop) */
5856 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5858 LOCALREFTABLE = lrt;
5860 /* now return the values */
5862 *p_vm = (JavaVM *) vm;
5863 *p_env = (void *) env;
5870 * These are local overrides for various environment variables in Emacs.
5871 * Please do not remove this and leave it at the end of the file, where
5872 * Emacs will automagically detect them.
5873 * ---------------------------------------------------------------------
5876 * indent-tabs-mode: t
5880 * vim:noexpandtab:sw=4:ts=4: