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 4567 2006-03-07 10:48:24Z twisti $
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/jvmti.h"
84 #if defined(USE_THREADS)
85 # if defined(NATIVE_THREADS)
86 # include "threads/native/threads.h"
88 # include "threads/green/threads.h"
92 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/loader.h"
98 #include "vm/options.h"
99 #include "vm/resolve.h"
100 #include "vm/statistics.h"
101 #include "vm/stringlocal.h"
102 #include "vm/jit/asmpart.h"
103 #include "vm/jit/jit.h"
104 #include "vm/statistics.h"
108 /* global variables ***********************************************************/
110 /* global reference table *****************************************************/
112 static java_objectheader **global_ref_table;
114 /* jmethodID and jclass caching variables for NewGlobalRef and DeleteGlobalRef*/
115 static classinfo *ihmclass = NULL;
116 static methodinfo *putmid = NULL;
117 static methodinfo *getmid = NULL;
118 static methodinfo *removemid = NULL;
121 /* direct buffer stuff ********************************************************/
123 static classinfo *class_java_nio_Buffer;
124 static classinfo *class_java_nio_DirectByteBufferImpl;
125 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
126 #if SIZEOF_VOID_P == 8
127 static classinfo *class_gnu_classpath_Pointer64;
129 static classinfo *class_gnu_classpath_Pointer32;
132 static methodinfo *dbbirw_init;
135 /* local reference table ******************************************************/
137 #if !defined(USE_THREADS)
138 localref_table *_no_threads_localref_table;
142 /* accessing instance fields macros *******************************************/
144 #define SET_FIELD(o,type,f,value) \
145 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
147 #define GET_FIELD(o,type,f) \
148 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
151 /* some forward declarations **************************************************/
153 jobject NewLocalRef(JNIEnv *env, jobject ref);
156 /* jni_init ********************************************************************
158 Initialize the JNI subsystem.
160 *******************************************************************************/
164 /* initalize global reference table */
167 load_class_bootstrap(utf_new_char("java/util/IdentityHashMap"))))
170 global_ref_table = GCNEW(jobject);
172 if (!(*global_ref_table = native_new_and_init(ihmclass)))
175 if (!(getmid = class_resolvemethod(ihmclass, utf_get,
176 utf_java_lang_Object__java_lang_Object)))
179 if (!(putmid = class_resolvemethod(ihmclass, utf_put,
180 utf_new_char("(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;"))))
184 class_resolvemethod(ihmclass, utf_remove,
185 utf_java_lang_Object__java_lang_Object)))
189 /* direct buffer stuff */
191 if (!(class_java_nio_Buffer =
192 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
193 !link_class(class_java_nio_Buffer))
196 if (!(class_java_nio_DirectByteBufferImpl =
197 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
198 !link_class(class_java_nio_DirectByteBufferImpl))
201 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
202 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
203 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
207 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
209 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
212 #if SIZEOF_VOID_P == 8
213 if (!(class_gnu_classpath_Pointer64 =
214 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
215 !link_class(class_gnu_classpath_Pointer64))
218 if (!(class_gnu_classpath_Pointer32 =
219 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
220 !link_class(class_gnu_classpath_Pointer32))
228 /* _Jv_jni_vmargs_from_objectarray *********************************************
232 *******************************************************************************/
234 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
237 java_objectarray *params)
239 java_objectheader *param;
241 typedesc *paramtypes;
246 paramcount = descr->paramcount;
247 paramtypes = descr->paramtypes;
249 /* if method is non-static fill first block and skip `this' pointer */
255 vmargs[0].type = TYPE_ADR;
256 vmargs[0].data = (u8) (ptrint) o;
263 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
264 switch (paramtypes->type) {
265 /* primitive types */
270 param = params->data[j];
275 /* internally used data type */
276 vmargs[i].type = paramtypes->type;
278 /* convert the value according to its declared type */
280 c = param->vftbl->class;
282 switch (paramtypes->decltype) {
283 case PRIMITIVETYPE_BOOLEAN:
284 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
285 vmargs[i].data = (s8) ((java_lang_Boolean *) param)->value;
290 case PRIMITIVETYPE_BYTE:
291 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
292 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
297 case PRIMITIVETYPE_CHAR:
298 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
299 vmargs[i].data = (s8) ((java_lang_Character *) param)->value;
304 case PRIMITIVETYPE_SHORT:
305 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
306 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
307 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
308 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
313 case PRIMITIVETYPE_INT:
314 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
315 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
316 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
317 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
318 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
319 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
324 case PRIMITIVETYPE_LONG:
325 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
326 vmargs[i].data = (s8) ((java_lang_Long *) param)->value;
327 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
328 vmargs[i].data = (s8) ((java_lang_Integer *) param)->value;
329 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
330 vmargs[i].data = (s8) ((java_lang_Short *) param)->value;
331 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
332 vmargs[i].data = (s8) ((java_lang_Byte *) param)->value;
337 case PRIMITIVETYPE_FLOAT:
338 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
339 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
344 case PRIMITIVETYPE_DOUBLE:
345 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
346 *((jdouble *) (&vmargs[i].data)) = (jdouble) ((java_lang_Double *) param)->value;
347 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
348 *((jfloat *) (&vmargs[i].data)) = (jfloat) ((java_lang_Float *) param)->value;
359 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
362 if (params->data[j] != 0) {
363 if (paramtypes->arraydim > 0) {
364 if (!builtin_arrayinstanceof(params->data[j], c))
368 if (!builtin_instanceof(params->data[j], c))
372 vmargs[i].type = TYPE_ADR;
373 vmargs[i].data = (u8) (ptrint) params->data[j];
382 /* *rettype = descr->returntype.decltype; */
387 exceptions_throw_illegalargumentexception();
392 /* _Jv_jni_CallObjectMethod ****************************************************
394 Internal function to call Java Object methods.
396 *******************************************************************************/
398 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
400 methodinfo *m, va_list ap)
403 java_objectheader *ro;
405 STATISTICS(jniinvokation());
408 exceptions_throw_nullpointerexception();
412 /* Class initialization is done by the JIT compiler. This is ok
413 since a static method always belongs to the declaring class. */
415 if (m->flags & ACC_STATIC) {
416 /* For static methods we reset the object. */
421 /* for convenience */
426 /* For instance methods we make a virtual function table lookup. */
428 resm = method_vftbl_lookup(vftbl, m);
431 STATISTICS(jnicallXmethodnvokation());
433 ro = vm_call_method_valist(resm, o, ap);
439 /* _Jv_jni_CallObjectMethodA ***************************************************
441 Internal function to call Java Object methods.
443 *******************************************************************************/
445 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
447 methodinfo *m, jvalue *args)
450 java_objectheader *ro;
452 STATISTICS(jniinvokation());
455 exceptions_throw_nullpointerexception();
459 /* Class initialization is done by the JIT compiler. This is ok
460 since a static method always belongs to the declaring class. */
462 if (m->flags & ACC_STATIC) {
463 /* For static methods we reset the object. */
468 /* for convenience */
473 /* For instance methods we make a virtual function table lookup. */
475 resm = method_vftbl_lookup(vftbl, m);
478 STATISTICS(jnicallXmethodnvokation());
480 ro = vm_call_method_jvalue(resm, o, args);
486 /* _Jv_jni_CallIntMethod *******************************************************
488 Internal function to call Java integer class methods (boolean,
489 byte, char, short, int).
491 *******************************************************************************/
493 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
494 methodinfo *m, va_list ap)
499 STATISTICS(jniinvokation());
502 exceptions_throw_nullpointerexception();
506 /* Class initialization is done by the JIT compiler. This is ok
507 since a static method always belongs to the declaring class. */
509 if (m->flags & ACC_STATIC) {
510 /* For static methods we reset the object. */
515 /* for convenience */
520 /* For instance methods we make a virtual function table lookup. */
522 resm = method_vftbl_lookup(vftbl, m);
525 STATISTICS(jnicallXmethodnvokation());
527 i = vm_call_method_int_valist(resm, o, ap);
533 /* _Jv_jni_CallIntMethodA ******************************************************
535 Internal function to call Java integer class methods (boolean,
536 byte, char, short, int).
538 *******************************************************************************/
540 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
541 methodinfo *m, jvalue *args)
546 STATISTICS(jniinvokation());
549 exceptions_throw_nullpointerexception();
553 /* Class initialization is done by the JIT compiler. This is ok
554 since a static method always belongs to the declaring class. */
556 if (m->flags & ACC_STATIC) {
557 /* For static methods we reset the object. */
562 /* for convenience */
567 /* For instance methods we make a virtual function table lookup. */
569 resm = method_vftbl_lookup(vftbl, m);
572 STATISTICS(jnicallXmethodnvokation());
574 i = vm_call_method_int_jvalue(resm, o, args);
580 /* _Jv_jni_CallLongMethod ******************************************************
582 Internal function to call Java long methods.
584 *******************************************************************************/
586 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
587 methodinfo *m, va_list ap)
592 STATISTICS(jniinvokation());
595 exceptions_throw_nullpointerexception();
599 /* Class initialization is done by the JIT compiler. This is ok
600 since a static method always belongs to the declaring class. */
602 if (m->flags & ACC_STATIC) {
603 /* For static methods we reset the object. */
608 /* for convenience */
613 /* For instance methods we make a virtual function table lookup. */
615 resm = method_vftbl_lookup(vftbl, m);
618 STATISTICS(jnicallXmethodnvokation());
620 l = vm_call_method_long_valist(resm, o, ap);
626 /* _Jv_jni_CallFloatMethod *****************************************************
628 Internal function to call Java float methods.
630 *******************************************************************************/
632 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
633 methodinfo *m, va_list ap)
638 /* Class initialization is done by the JIT compiler. This is ok
639 since a static method always belongs to the declaring class. */
641 if (m->flags & ACC_STATIC) {
642 /* For static methods we reset the object. */
647 /* for convenience */
652 /* For instance methods we make a virtual function table lookup. */
654 resm = method_vftbl_lookup(vftbl, m);
657 STATISTICS(jnicallXmethodnvokation());
659 f = vm_call_method_float_valist(resm, o, ap);
665 /* _Jv_jni_CallDoubleMethod ****************************************************
667 Internal function to call Java double methods.
669 *******************************************************************************/
671 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
672 methodinfo *m, va_list ap)
677 /* Class initialization is done by the JIT compiler. This is ok
678 since a static method always belongs to the declaring class. */
680 if (m->flags & ACC_STATIC) {
681 /* For static methods we reset the object. */
686 /* for convenience */
691 /* For instance methods we make a virtual function table lookup. */
693 resm = method_vftbl_lookup(vftbl, m);
696 d = vm_call_method_double_valist(resm, o, ap);
702 /* _Jv_jni_CallVoidMethod ******************************************************
704 Internal function to call Java void methods.
706 *******************************************************************************/
708 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
709 methodinfo *m, va_list ap)
714 exceptions_throw_nullpointerexception();
718 /* Class initialization is done by the JIT compiler. This is ok
719 since a static method always belongs to the declaring class. */
721 if (m->flags & ACC_STATIC) {
722 /* For static methods we reset the object. */
727 /* for convenience */
732 /* For instance methods we make a virtual function table lookup. */
734 resm = method_vftbl_lookup(vftbl, m);
737 STATISTICS(jnicallXmethodnvokation());
739 (void) vm_call_method_valist(resm, o, ap);
743 /* _Jv_jni_CallVoidMethodA *****************************************************
745 Internal function to call Java void methods.
747 *******************************************************************************/
749 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
750 methodinfo *m, jvalue *args)
755 exceptions_throw_nullpointerexception();
759 /* Class initialization is done by the JIT compiler. This is ok
760 since a static method always belongs to the declaring class. */
762 if (m->flags & ACC_STATIC) {
763 /* For static methods we reset the object. */
768 /* for convenience */
773 /* For instance methods we make a virtual function table lookup. */
775 resm = method_vftbl_lookup(vftbl, m);
778 STATISTICS(jnicallXmethodnvokation());
780 (void) vm_call_method_jvalue(resm, o, args);
784 /* _Jv_jni_invokeNative ********************************************************
786 Invoke a method on the given object with the given arguments.
788 For instance methods OBJ must be != NULL and the method is looked up
789 in the vftbl of the object.
791 For static methods, OBJ is ignored.
793 *******************************************************************************/
795 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
796 java_objectarray *params)
800 java_objectheader *ro;
805 exceptions_throw_nullpointerexception();
809 argcount = m->parseddesc->paramcount;
810 paramcount = argcount;
812 /* if method is non-static, remove the `this' pointer */
814 if (!(m->flags & ACC_STATIC))
817 /* For instance methods the object has to be an instance of the
818 class the method belongs to. For static methods the obj
819 parameter is ignored. */
821 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
823 new_exception_message(string_java_lang_IllegalArgumentException,
824 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
828 /* check if we got the right number of arguments */
830 if (((params == NULL) && (paramcount != 0)) ||
831 (params && (params->header.size != paramcount)))
834 new_exception(string_java_lang_IllegalArgumentException);
838 /* for instance methods we need an object */
840 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
842 new_exception_message(string_java_lang_NullPointerException,
843 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
847 /* for static methods, zero object to make subsequent code simpler */
848 if (m->flags & ACC_STATIC)
852 /* for instance methods we must do a vftbl lookup */
853 resm = method_vftbl_lookup(o->vftbl, m);
856 /* for static methods, just for convenience */
860 vmargs = MNEW(vm_arg, argcount);
862 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
865 switch (resm->parseddesc->returntype.decltype) {
867 (void) vm_call_method_vmarg(resm, argcount, vmargs);
872 case PRIMITIVETYPE_BOOLEAN: {
874 java_lang_Boolean *bo;
876 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
878 ro = builtin_new(class_java_lang_Boolean);
880 /* setting the value of the object direct */
882 bo = (java_lang_Boolean *) ro;
887 case PRIMITIVETYPE_BYTE: {
891 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
893 ro = builtin_new(class_java_lang_Byte);
895 /* setting the value of the object direct */
897 bo = (java_lang_Byte *) ro;
902 case PRIMITIVETYPE_CHAR: {
904 java_lang_Character *co;
906 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
908 ro = builtin_new(class_java_lang_Character);
910 /* setting the value of the object direct */
912 co = (java_lang_Character *) ro;
917 case PRIMITIVETYPE_SHORT: {
921 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
923 ro = builtin_new(class_java_lang_Short);
925 /* setting the value of the object direct */
927 so = (java_lang_Short *) ro;
932 case PRIMITIVETYPE_INT: {
934 java_lang_Integer *io;
936 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
938 ro = builtin_new(class_java_lang_Integer);
940 /* setting the value of the object direct */
942 io = (java_lang_Integer *) ro;
947 case PRIMITIVETYPE_LONG: {
951 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
953 ro = builtin_new(class_java_lang_Long);
955 /* setting the value of the object direct */
957 lo = (java_lang_Long *) ro;
962 case PRIMITIVETYPE_FLOAT: {
966 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
968 ro = builtin_new(class_java_lang_Float);
970 /* setting the value of the object direct */
972 fo = (java_lang_Float *) ro;
977 case PRIMITIVETYPE_DOUBLE: {
979 java_lang_Double *_do;
981 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
983 ro = builtin_new(class_java_lang_Double);
985 /* setting the value of the object direct */
987 _do = (java_lang_Double *) ro;
993 ro = vm_call_method_vmarg(resm, argcount, vmargs);
997 /* if this happens the exception has already been set by
998 fill_callblock_from_objectarray */
1000 MFREE(vmargs, vm_arg, argcount);
1005 MFREE(vmargs, vm_arg, argcount);
1007 if (*exceptionptr) {
1008 java_objectheader *cause;
1010 cause = *exceptionptr;
1012 /* clear exception pointer, we are calling JIT code again */
1014 *exceptionptr = NULL;
1017 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1018 (java_lang_Throwable *) cause);
1025 /* GetVersion ******************************************************************
1027 Returns the major version number in the higher 16 bits and the
1028 minor version number in the lower 16 bits.
1030 *******************************************************************************/
1032 jint GetVersion(JNIEnv *env)
1034 STATISTICS(jniinvokation());
1036 /* we support JNI 1.4 */
1038 return JNI_VERSION_1_4;
1042 /* Class Operations ***********************************************************/
1044 /* DefineClass *****************************************************************
1046 Loads a class from a buffer of raw class data. The buffer
1047 containing the raw class data is not referenced by the VM after the
1048 DefineClass call returns, and it may be discarded if desired.
1050 *******************************************************************************/
1052 jclass DefineClass(JNIEnv *env, const char *name, jobject loader,
1053 const jbyte *buf, jsize bufLen)
1055 java_lang_ClassLoader *cl;
1056 java_lang_String *s;
1060 STATISTICS(jniinvokation());
1062 cl = (java_lang_ClassLoader *) loader;
1063 s = javastring_new_char(name);
1064 ba = (java_bytearray *) buf;
1066 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1069 return (jclass) NewLocalRef(env, (jobject) c);
1073 /* FindClass *******************************************************************
1075 This function loads a locally-defined class. It searches the
1076 directories and zip files specified by the CLASSPATH environment
1077 variable for the class with the specified name.
1079 *******************************************************************************/
1081 jclass FindClass(JNIEnv *env, const char *name)
1087 STATISTICS(jniinvokation());
1089 u = utf_new_char_classname((char *) name);
1091 /* Check stacktrace for classloader, if one found use it,
1092 otherwise use the system classloader. */
1094 /* Quote from the JNI documentation:
1096 In the Java 2 Platform, FindClass locates the class loader
1097 associated with the current native method. If the native code
1098 belongs to a system class, no class loader will be
1099 involved. Otherwise, the proper class loader will be invoked to
1100 load and link the named class. When FindClass is called through
1101 the Invocation Interface, there is no current native method or
1102 its associated class loader. In that case, the result of
1103 ClassLoader.getBaseClassLoader is used." */
1105 #if defined(__ALPHA__) || defined(__ARM__) || defined(__I386__) || defined(__MIPS__) || defined(__POWERPC__) || defined(__X86_64__)
1106 /* these JITs support stacktraces, and so does the interpreter */
1108 cc = stacktrace_getCurrentClass();
1110 # if defined(ENABLE_INTRP)
1111 /* the interpreter supports stacktraces, even if the JIT does not */
1114 cc = stacktrace_getCurrentClass();
1120 /* if no Java method was found, use the system classloader */
1123 c = load_class_from_sysloader(u);
1125 c = load_class_from_classloader(u, cc->classloader);
1133 return (jclass) NewLocalRef(env, (jobject) c);
1137 /* GetSuperclass ***************************************************************
1139 If clazz represents any class other than the class Object, then
1140 this function returns the object that represents the superclass of
1141 the class specified by clazz.
1143 *******************************************************************************/
1145 jclass GetSuperclass(JNIEnv *env, jclass sub)
1149 STATISTICS(jniinvokation());
1151 c = ((classinfo *) sub)->super.cls;
1156 return (jclass) NewLocalRef(env, (jobject) c);
1160 /* IsAssignableFrom ************************************************************
1162 Determines whether an object of sub can be safely cast to sup.
1164 *******************************************************************************/
1166 jboolean IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1168 STATISTICS(jniinvokation());
1170 return Java_java_lang_VMClass_isAssignableFrom(env,
1172 (java_lang_Class *) sup,
1173 (java_lang_Class *) sub);
1177 /* Throw ***********************************************************************
1179 Causes a java.lang.Throwable object to be thrown.
1181 *******************************************************************************/
1183 jint Throw(JNIEnv *env, jthrowable obj)
1185 STATISTICS(jniinvokation());
1187 *exceptionptr = (java_objectheader *) obj;
1193 /* ThrowNew ********************************************************************
1195 Constructs an exception object from the specified class with the
1196 message specified by message and causes that exception to be
1199 *******************************************************************************/
1201 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1203 java_lang_Throwable *o;
1204 java_lang_String *s;
1206 STATISTICS(jniinvokation());
1208 s = (java_lang_String *) javastring_new_char(msg);
1210 /* instantiate exception object */
1212 o = (java_lang_Throwable *) native_new_and_init_string((classinfo *) clazz,
1218 *exceptionptr = (java_objectheader *) o;
1224 /* ExceptionOccurred ***********************************************************
1226 Determines if an exception is being thrown. The exception stays
1227 being thrown until either the native code calls ExceptionClear(),
1228 or the Java code handles the exception.
1230 *******************************************************************************/
1232 jthrowable ExceptionOccurred(JNIEnv *env)
1234 java_objectheader *e;
1236 STATISTICS(jniinvokation());
1240 return NewLocalRef(env, (jthrowable) e);
1244 /* ExceptionDescribe ***********************************************************
1246 Prints an exception and a backtrace of the stack to a system
1247 error-reporting channel, such as stderr. This is a convenience
1248 routine provided for debugging.
1250 *******************************************************************************/
1252 void ExceptionDescribe(JNIEnv *env)
1254 java_objectheader *e;
1257 STATISTICS(jniinvokation());
1262 /* clear exception, because we are calling jit code again */
1264 *exceptionptr = NULL;
1266 /* get printStackTrace method from exception class */
1268 m = class_resolveclassmethod(e->vftbl->class,
1269 utf_printStackTrace,
1275 /* XXX what should we do? */
1278 /* print the stacktrace */
1280 (void) vm_call_method(m, e);
1285 /* ExceptionClear **************************************************************
1287 Clears any exception that is currently being thrown. If no
1288 exception is currently being thrown, this routine has no effect.
1290 *******************************************************************************/
1292 void ExceptionClear(JNIEnv *env)
1294 STATISTICS(jniinvokation());
1296 *exceptionptr = NULL;
1300 /* FatalError ******************************************************************
1302 Raises a fatal error and does not expect the VM to recover. This
1303 function does not return.
1305 *******************************************************************************/
1307 void FatalError(JNIEnv *env, const char *msg)
1309 STATISTICS(jniinvokation());
1311 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1315 /* PushLocalFrame **************************************************************
1317 Creates a new local reference frame, in which at least a given
1318 number of local references can be created.
1320 *******************************************************************************/
1322 jint PushLocalFrame(JNIEnv* env, jint capacity)
1324 STATISTICS(jniinvokation());
1326 log_text("JNI-Call: PushLocalFrame: IMPLEMENT ME!");
1333 /* PopLocalFrame ***************************************************************
1335 Pops off the current local reference frame, frees all the local
1336 references, and returns a local reference in the previous local
1337 reference frame for the given result object.
1339 *******************************************************************************/
1341 jobject PopLocalFrame(JNIEnv* env, jobject result)
1343 STATISTICS(jniinvokation());
1345 log_text("JNI-Call: PopLocalFrame: IMPLEMENT ME!");
1349 /* add local reference and return the value */
1351 return NewLocalRef(env, NULL);
1355 /* DeleteLocalRef **************************************************************
1357 Deletes the local reference pointed to by localRef.
1359 *******************************************************************************/
1361 void DeleteLocalRef(JNIEnv *env, jobject localRef)
1363 java_objectheader *o;
1364 localref_table *lrt;
1367 STATISTICS(jniinvokation());
1369 o = (java_objectheader *) localRef;
1371 /* get local reference table (thread specific) */
1373 lrt = LOCALREFTABLE;
1375 /* remove the reference */
1377 for (i = 0; i < lrt->capacity; i++) {
1378 if (lrt->refs[i] == o) {
1379 lrt->refs[i] = NULL;
1386 /* this should not happen */
1388 /* if (opt_checkjni) */
1389 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1390 log_text("JNI-DeleteLocalRef: Bad global or local ref passed to JNI");
1394 /* IsSameObject ****************************************************************
1396 Tests whether two references refer to the same Java object.
1398 *******************************************************************************/
1400 jboolean IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1402 STATISTICS(jniinvokation());
1411 /* NewLocalRef *****************************************************************
1413 Creates a new local reference that refers to the same object as ref.
1415 *******************************************************************************/
1417 jobject NewLocalRef(JNIEnv *env, jobject ref)
1419 localref_table *lrt;
1422 STATISTICS(jniinvokation());
1427 /* get local reference table (thread specific) */
1429 lrt = LOCALREFTABLE;
1431 /* check if we have space for the requested reference */
1433 if (lrt->used == lrt->capacity) {
1434 /* throw_cacao_exception_exit(string_java_lang_InternalError, */
1435 /* "Too many local references"); */
1436 fprintf(stderr, "Too many local references");
1440 /* insert the reference */
1442 for (i = 0; i < lrt->capacity; i++) {
1443 if (lrt->refs[i] == NULL) {
1444 lrt->refs[i] = (java_objectheader *) ref;
1451 /* should not happen, just to be sure */
1455 /* keep compiler happy */
1461 /* EnsureLocalCapacity *********************************************************
1463 Ensures that at least a given number of local references can be
1464 created in the current thread
1466 *******************************************************************************/
1468 jint EnsureLocalCapacity(JNIEnv* env, jint capacity)
1470 localref_table *lrt;
1472 STATISTICS(jniinvokation());
1474 /* get local reference table (thread specific) */
1476 lrt = LOCALREFTABLE;
1478 /* check if capacity elements are available in the local references table */
1480 if ((lrt->used + capacity) > lrt->capacity) {
1481 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
1489 /* AllocObject *****************************************************************
1491 Allocates a new Java object without invoking any of the
1492 constructors for the object. Returns a reference to the object.
1494 *******************************************************************************/
1496 jobject AllocObject(JNIEnv *env, jclass clazz)
1499 java_objectheader *o;
1501 STATISTICS(jniinvokation());
1503 c = (classinfo *) clazz;
1505 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1507 new_exception_utfmessage(string_java_lang_InstantiationException,
1514 return NewLocalRef(env, o);
1518 /* NewObject *******************************************************************
1520 Programmers place all arguments that are to be passed to the
1521 constructor immediately following the methodID
1522 argument. NewObject() accepts these arguments and passes them to
1523 the Java method that the programmer wishes to invoke.
1525 *******************************************************************************/
1527 jobject NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1529 java_objectheader *o;
1533 STATISTICS(jniinvokation());
1535 m = (methodinfo *) methodID;
1539 o = builtin_new(clazz);
1544 /* call constructor */
1546 va_start(ap, methodID);
1547 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1550 return NewLocalRef(env, o);
1554 /* NewObjectV ******************************************************************
1556 Programmers place all arguments that are to be passed to the
1557 constructor in an args argument of type va_list that immediately
1558 follows the methodID argument. NewObjectV() accepts these
1559 arguments, and, in turn, passes them to the Java method that the
1560 programmer wishes to invoke.
1562 *******************************************************************************/
1564 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1566 java_objectheader *o;
1569 STATISTICS(jniinvokation());
1571 m = (methodinfo *) methodID;
1575 o = builtin_new(clazz);
1580 /* call constructor */
1582 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1584 return NewLocalRef(env, o);
1588 /* NewObjectA *****************************************************************
1590 Programmers place all arguments that are to be passed to the
1591 constructor in an args array of jvalues that immediately follows
1592 the methodID argument. NewObjectA() accepts the arguments in this
1593 array, and, in turn, passes them to the Java method that the
1594 programmer wishes to invoke.
1596 *******************************************************************************/
1598 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1600 java_objectheader *o;
1603 STATISTICS(jniinvokation());
1605 m = (methodinfo *) methodID;
1609 o = builtin_new(clazz);
1614 /* call constructor */
1616 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1618 return NewLocalRef(env, o);
1622 /* GetObjectClass **************************************************************
1624 Returns the class of an object.
1626 *******************************************************************************/
1628 jclass GetObjectClass(JNIEnv *env, jobject obj)
1630 java_objectheader *o;
1633 STATISTICS(jniinvokation());
1635 o = (java_objectheader *) obj;
1637 if ((o == NULL) || (o->vftbl == NULL))
1640 c = o->vftbl->class;
1642 return (jclass) NewLocalRef(env, (jobject) c);
1646 /* IsInstanceOf ****************************************************************
1648 Tests whether an object is an instance of a class.
1650 *******************************************************************************/
1652 jboolean IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1654 STATISTICS(jniinvokation());
1656 return Java_java_lang_VMClass_isInstance(env,
1658 (java_lang_Class *) clazz,
1659 (java_lang_Object *) obj);
1663 /* Reflection Support *********************************************************/
1665 /* FromReflectedMethod *********************************************************
1667 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1668 object to a method ID.
1670 *******************************************************************************/
1672 jmethodID FromReflectedMethod(JNIEnv *env, jobject method)
1678 STATISTICS(jniinvokation());
1683 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1684 java_lang_reflect_Method *rm;
1686 rm = (java_lang_reflect_Method *) method;
1687 c = (classinfo *) (rm->declaringClass);
1690 } else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1691 java_lang_reflect_Constructor *rc;
1693 rc = (java_lang_reflect_Constructor *) method;
1694 c = (classinfo *) (rc->clazz);
1700 mi = &(c->methods[slot]);
1702 return (jmethodID) mi;
1706 /* FromReflectedField **********************************************************
1708 Converts a java.lang.reflect.Field to a field ID.
1710 *******************************************************************************/
1712 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1714 java_lang_reflect_Field *rf;
1718 STATISTICS(jniinvokation());
1720 rf = (java_lang_reflect_Field *) field;
1725 c = (classinfo *) rf->declaringClass;
1727 f = &(c->fields[rf->slot]);
1729 return (jfieldID) f;
1733 /* ToReflectedMethod ***********************************************************
1735 Converts a method ID derived from cls to an instance of the
1736 java.lang.reflect.Method class or to an instance of the
1737 java.lang.reflect.Constructor class.
1739 *******************************************************************************/
1741 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1743 STATISTICS(jniinvokation());
1745 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1751 /* ToReflectedField ************************************************************
1753 Converts a field ID derived from cls to an instance of the
1754 java.lang.reflect.Field class.
1756 *******************************************************************************/
1758 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1761 STATISTICS(jniinvokation());
1763 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1769 /* Calling Instance Methods ***************************************************/
1771 /* GetMethodID *****************************************************************
1773 Returns the method ID for an instance (nonstatic) method of a class
1774 or interface. The method may be defined in one of the clazz's
1775 superclasses and inherited by clazz. The method is determined by
1776 its name and signature.
1778 GetMethodID() causes an uninitialized class to be initialized.
1780 *******************************************************************************/
1782 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1790 STATISTICS(jniinvokation());
1792 c = (classinfo *) clazz;
1797 if (!(c->state & CLASS_INITIALIZED))
1798 if (!initialize_class(c))
1801 /* try to get the method of the class or one of it's superclasses */
1803 uname = utf_new_char((char *) name);
1804 udesc = utf_new_char((char *) sig);
1806 m = class_resolvemethod(clazz, uname, udesc);
1808 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1809 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1814 return (jmethodID) m;
1818 /* JNI-functions for calling instance methods *********************************/
1820 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1822 java_objectheader *o;
1824 java_objectheader *ret;
1827 o = (java_objectheader *) obj;
1828 m = (methodinfo *) methodID;
1830 va_start(ap, methodID);
1831 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1834 return NewLocalRef(env, ret);
1838 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1840 java_objectheader *o;
1842 java_objectheader *ret;
1844 o = (java_objectheader *) obj;
1845 m = (methodinfo *) methodID;
1847 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1849 return NewLocalRef(env, ret);
1853 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1855 java_objectheader *o;
1857 java_objectheader *ret;
1859 o = (java_objectheader *) obj;
1860 m = (methodinfo *) methodID;
1862 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1864 return NewLocalRef(env, ret);
1868 jboolean CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1870 java_objectheader *o;
1875 o = (java_objectheader *) obj;
1876 m = (methodinfo *) methodID;
1878 va_start(ap, methodID);
1879 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1886 jboolean CallBooleanMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1888 java_objectheader *o;
1892 o = (java_objectheader *) obj;
1893 m = (methodinfo *) methodID;
1895 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1901 jboolean CallBooleanMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1903 java_objectheader *o;
1907 o = (java_objectheader *) obj;
1908 m = (methodinfo *) methodID;
1910 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1916 jbyte CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1918 java_objectheader *o;
1923 o = (java_objectheader *) obj;
1924 m = (methodinfo *) methodID;
1926 va_start(ap, methodID);
1927 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1934 jbyte CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1936 java_objectheader *o;
1940 o = (java_objectheader *) obj;
1941 m = (methodinfo *) methodID;
1943 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1949 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1951 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
1957 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1959 java_objectheader *o;
1964 o = (java_objectheader *) obj;
1965 m = (methodinfo *) methodID;
1967 va_start(ap, methodID);
1968 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1975 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1977 java_objectheader *o;
1981 o = (java_objectheader *) obj;
1982 m = (methodinfo *) methodID;
1984 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1990 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1992 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
1998 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2000 java_objectheader *o;
2005 o = (java_objectheader *) obj;
2006 m = (methodinfo *) methodID;
2008 va_start(ap, methodID);
2009 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2016 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2018 java_objectheader *o;
2022 o = (java_objectheader *) obj;
2023 m = (methodinfo *) methodID;
2025 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2031 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2033 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2040 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2042 java_objectheader *o;
2047 o = (java_objectheader *) obj;
2048 m = (methodinfo *) methodID;
2050 va_start(ap, methodID);
2051 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2058 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2060 java_objectheader *o;
2064 o = (java_objectheader *) obj;
2065 m = (methodinfo *) methodID;
2067 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2073 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2075 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2082 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2084 java_objectheader *o;
2089 o = (java_objectheader *) obj;
2090 m = (methodinfo *) methodID;
2092 va_start(ap, methodID);
2093 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2100 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2102 java_objectheader *o;
2106 o = (java_objectheader *) obj;
2107 m = (methodinfo *) methodID;
2109 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2115 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2117 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2124 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2126 java_objectheader *o;
2131 o = (java_objectheader *) obj;
2132 m = (methodinfo *) methodID;
2134 va_start(ap, methodID);
2135 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2142 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2144 java_objectheader *o;
2148 o = (java_objectheader *) obj;
2149 m = (methodinfo *) methodID;
2151 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2157 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2159 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2166 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2168 java_objectheader *o;
2173 o = (java_objectheader *) obj;
2174 m = (methodinfo *) methodID;
2176 va_start(ap, methodID);
2177 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2184 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2186 java_objectheader *o;
2190 o = (java_objectheader *) obj;
2191 m = (methodinfo *) methodID;
2193 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2199 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2201 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2208 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2210 java_objectheader *o;
2214 o = (java_objectheader *) obj;
2215 m = (methodinfo *) methodID;
2217 va_start(ap, methodID);
2218 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2223 void CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
2225 java_objectheader *o;
2228 o = (java_objectheader *) obj;
2229 m = (methodinfo *) methodID;
2231 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2235 void CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
2237 java_objectheader *o;
2240 o = (java_objectheader *) obj;
2241 m = (methodinfo *) methodID;
2243 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2248 jobject CallNonvirtualObjectMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2250 java_objectheader *o;
2253 java_objectheader *r;
2256 o = (java_objectheader *) obj;
2257 c = (classinfo *) clazz;
2258 m = (methodinfo *) methodID;
2260 va_start(ap, methodID);
2261 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2264 return NewLocalRef(env, r);
2268 jobject CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2270 java_objectheader *o;
2273 java_objectheader *r;
2275 o = (java_objectheader *) obj;
2276 c = (classinfo *) clazz;
2277 m = (methodinfo *) methodID;
2279 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2281 return NewLocalRef(env, r);
2285 jobject CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2287 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2289 return NewLocalRef(env, NULL);
2294 jboolean CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2296 java_objectheader *o;
2302 o = (java_objectheader *) obj;
2303 c = (classinfo *) clazz;
2304 m = (methodinfo *) methodID;
2306 va_start(ap, methodID);
2307 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2314 jboolean CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2316 java_objectheader *o;
2321 o = (java_objectheader *) obj;
2322 c = (classinfo *) clazz;
2323 m = (methodinfo *) methodID;
2325 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2331 jboolean CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2333 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2339 jbyte CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2341 java_objectheader *o;
2347 o = (java_objectheader *) obj;
2348 c = (classinfo *) clazz;
2349 m = (methodinfo *) methodID;
2351 va_start(ap, methodID);
2352 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2359 jbyte CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2361 java_objectheader *o;
2366 o = (java_objectheader *) obj;
2367 c = (classinfo *) clazz;
2368 m = (methodinfo *) methodID;
2370 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2376 jbyte CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2378 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2385 jchar CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2387 java_objectheader *o;
2393 o = (java_objectheader *) obj;
2394 c = (classinfo *) clazz;
2395 m = (methodinfo *) methodID;
2397 va_start(ap, methodID);
2398 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2405 jchar CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2407 java_objectheader *o;
2412 o = (java_objectheader *) obj;
2413 c = (classinfo *) clazz;
2414 m = (methodinfo *) methodID;
2416 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2422 jchar CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2424 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2431 jshort CallNonvirtualShortMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2433 java_objectheader *o;
2439 o = (java_objectheader *) obj;
2440 c = (classinfo *) clazz;
2441 m = (methodinfo *) methodID;
2443 va_start(ap, methodID);
2444 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2451 jshort CallNonvirtualShortMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2453 java_objectheader *o;
2458 o = (java_objectheader *) obj;
2459 c = (classinfo *) clazz;
2460 m = (methodinfo *) methodID;
2462 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2468 jshort CallNonvirtualShortMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2470 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2477 jint CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2479 java_objectheader *o;
2485 o = (java_objectheader *) obj;
2486 c = (classinfo *) clazz;
2487 m = (methodinfo *) methodID;
2489 va_start(ap, methodID);
2490 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2497 jint CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2499 java_objectheader *o;
2504 o = (java_objectheader *) obj;
2505 c = (classinfo *) clazz;
2506 m = (methodinfo *) methodID;
2508 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2514 jint CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2516 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2523 jlong CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2525 java_objectheader *o;
2531 o = (java_objectheader *) obj;
2532 c = (classinfo *) clazz;
2533 m = (methodinfo *) methodID;
2535 va_start(ap, methodID);
2536 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2543 jlong CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2545 java_objectheader *o;
2550 o = (java_objectheader *) obj;
2551 c = (classinfo *) clazz;
2552 m = (methodinfo *) methodID;
2554 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2560 jlong CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2562 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2569 jfloat CallNonvirtualFloatMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2571 java_objectheader *o;
2577 o = (java_objectheader *) obj;
2578 c = (classinfo *) clazz;
2579 m = (methodinfo *) methodID;
2581 va_start(ap, methodID);
2582 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2589 jfloat CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2591 java_objectheader *o;
2596 o = (java_objectheader *) obj;
2597 c = (classinfo *) clazz;
2598 m = (methodinfo *) methodID;
2600 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2606 jfloat CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2608 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2615 jdouble CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2617 java_objectheader *o;
2623 o = (java_objectheader *) obj;
2624 c = (classinfo *) clazz;
2625 m = (methodinfo *) methodID;
2627 va_start(ap, methodID);
2628 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2635 jdouble CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2637 java_objectheader *o;
2642 o = (java_objectheader *) obj;
2643 c = (classinfo *) clazz;
2644 m = (methodinfo *) methodID;
2646 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2652 jdouble CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
2654 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2661 void CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
2663 java_objectheader *o;
2668 o = (java_objectheader *) obj;
2669 c = (classinfo *) clazz;
2670 m = (methodinfo *) methodID;
2672 va_start(ap, methodID);
2673 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2678 void CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
2680 java_objectheader *o;
2684 o = (java_objectheader *) obj;
2685 c = (classinfo *) clazz;
2686 m = (methodinfo *) methodID;
2688 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2692 void CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
2694 java_objectheader *o;
2698 o = (java_objectheader *) obj;
2699 c = (classinfo *) clazz;
2700 m = (methodinfo *) methodID;
2702 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2706 /* Accessing Fields of Objects ************************************************/
2708 /* GetFieldID ******************************************************************
2710 Returns the field ID for an instance (nonstatic) field of a
2711 class. The field is specified by its name and signature. The
2712 Get<type>Field and Set<type>Field families of accessor functions
2713 use field IDs to retrieve object fields.
2715 *******************************************************************************/
2717 jfieldID GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2724 STATISTICS(jniinvokation());
2726 uname = utf_new_char((char *) name);
2727 udesc = utf_new_char((char *) sig);
2729 f = class_findfield(clazz, uname, udesc);
2732 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2734 return (jfieldID) f;
2738 /* Get<type>Field Routines *****************************************************
2740 This family of accessor routines returns the value of an instance
2741 (nonstatic) field of an object. The field to access is specified by
2742 a field ID obtained by calling GetFieldID().
2744 *******************************************************************************/
2746 jobject GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2748 java_objectheader *o;
2750 STATISTICS(jniinvokation());
2752 o = GET_FIELD(obj, java_objectheader*, fieldID);
2754 return NewLocalRef(env, o);
2758 jboolean GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2762 STATISTICS(jniinvokation());
2764 i = GET_FIELD(obj, s4, fieldID);
2766 return (jboolean) i;
2770 jbyte GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2774 STATISTICS(jniinvokation());
2776 i = GET_FIELD(obj, s4, fieldID);
2782 jchar GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2786 STATISTICS(jniinvokation());
2788 i = GET_FIELD(obj, s4, fieldID);
2794 jshort GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2798 STATISTICS(jniinvokation());
2800 i = GET_FIELD(obj, s4, fieldID);
2806 jint GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2808 java_objectheader *o;
2812 STATISTICS(jniinvokation());
2814 o = (java_objectheader *) obj;
2815 f = (fieldinfo *) fieldID;
2817 i = GET_FIELD(o, s4, f);
2823 jlong GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2827 STATISTICS(jniinvokation());
2829 l = GET_FIELD(obj, s8, fieldID);
2835 jfloat GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2839 STATISTICS(jniinvokation());
2841 f = GET_FIELD(obj, float, fieldID);
2847 jdouble GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2851 STATISTICS(jniinvokation());
2853 d = GET_FIELD(obj, double, fieldID);
2859 /* Set<type>Field Routines *****************************************************
2861 This family of accessor routines sets the value of an instance
2862 (nonstatic) field of an object. The field to access is specified by
2863 a field ID obtained by calling GetFieldID().
2865 *******************************************************************************/
2867 void SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID, jobject value)
2869 STATISTICS(jniinvokation());
2871 SET_FIELD(obj, java_objectheader*, fieldID, value);
2875 void SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID, jboolean value)
2877 STATISTICS(jniinvokation());
2879 SET_FIELD(obj, s4, fieldID, value);
2883 void SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID, jbyte value)
2885 STATISTICS(jniinvokation());
2887 SET_FIELD(obj, s4, fieldID, value);
2891 void SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID, jchar value)
2893 STATISTICS(jniinvokation());
2895 SET_FIELD(obj, s4, fieldID, value);
2899 void SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID, jshort value)
2901 STATISTICS(jniinvokation());
2903 SET_FIELD(obj, s4, fieldID, value);
2907 void SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
2909 STATISTICS(jniinvokation());
2911 SET_FIELD(obj, s4, fieldID, value);
2915 void SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID, jlong value)
2917 STATISTICS(jniinvokation());
2919 SET_FIELD(obj, s8, fieldID, value);
2923 void SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID, jfloat value)
2925 STATISTICS(jniinvokation());
2927 SET_FIELD(obj, float, fieldID, value);
2931 void SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID, jdouble value)
2933 STATISTICS(jniinvokation());
2935 SET_FIELD(obj, double, fieldID, value);
2939 /* Calling Static Methods *****************************************************/
2941 /* GetStaticMethodID ***********************************************************
2943 Returns the method ID for a static method of a class. The method is
2944 specified by its name and signature.
2946 GetStaticMethodID() causes an uninitialized class to be
2949 *******************************************************************************/
2951 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
2959 STATISTICS(jniinvokation());
2961 c = (classinfo *) clazz;
2966 if (!(c->state & CLASS_INITIALIZED))
2967 if (!initialize_class(c))
2970 /* try to get the static method of the class */
2972 uname = utf_new_char((char *) name);
2973 udesc = utf_new_char((char *) sig);
2975 m = class_resolvemethod(c, uname, udesc);
2977 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
2978 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2983 return (jmethodID) m;
2987 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2990 java_objectheader *o;
2993 m = (methodinfo *) methodID;
2995 va_start(ap, methodID);
2996 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
2999 return NewLocalRef(env, o);
3003 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3006 java_objectheader *o;
3008 m = (methodinfo *) methodID;
3010 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3012 return NewLocalRef(env, o);
3016 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3019 java_objectheader *o;
3021 m = (methodinfo *) methodID;
3023 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3025 return NewLocalRef(env, o);
3029 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3035 m = (methodinfo *) methodID;
3037 va_start(ap, methodID);
3038 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3045 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3050 m = (methodinfo *) methodID;
3052 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3058 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3060 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3066 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3072 m = (methodinfo *) methodID;
3074 va_start(ap, methodID);
3075 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3082 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3087 m = (methodinfo *) methodID;
3089 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3095 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3097 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3103 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3109 m = (methodinfo *) methodID;
3111 va_start(ap, methodID);
3112 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3119 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3124 m = (methodinfo *) methodID;
3126 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3132 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3134 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3140 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3146 m = (methodinfo *) methodID;
3148 va_start(ap, methodID);
3149 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3156 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3161 m = (methodinfo *) methodID;
3163 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3169 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3171 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3177 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3183 m = (methodinfo *) methodID;
3185 va_start(ap, methodID);
3186 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3193 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3198 m = (methodinfo *) methodID;
3200 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3206 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3208 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3214 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3220 m = (methodinfo *) methodID;
3222 va_start(ap, methodID);
3223 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3230 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
3236 m = (methodinfo *) methodID;
3238 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3244 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3246 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3253 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3259 m = (methodinfo *) methodID;
3261 va_start(ap, methodID);
3262 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3269 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3274 m = (methodinfo *) methodID;
3276 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3282 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3284 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3290 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3296 m = (methodinfo *) methodID;
3298 va_start(ap, methodID);
3299 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3306 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3311 m = (methodinfo *) methodID;
3313 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3319 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
3321 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3327 void CallStaticVoidMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
3332 m = (methodinfo *) methodID;
3334 va_start(ap, methodID);
3335 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3340 void CallStaticVoidMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
3344 m = (methodinfo *) methodID;
3346 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3350 void CallStaticVoidMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue * args)
3354 m = (methodinfo *) methodID;
3356 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3360 /* Accessing Static Fields ****************************************************/
3362 /* GetStaticFieldID ************************************************************
3364 Returns the field ID for a static field of a class. The field is
3365 specified by its name and signature. The GetStatic<type>Field and
3366 SetStatic<type>Field families of accessor functions use field IDs
3367 to retrieve static fields.
3369 *******************************************************************************/
3371 jfieldID GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
3375 STATISTICS(jniinvokation());
3377 f = class_findfield(clazz,
3378 utf_new_char((char *) name),
3379 utf_new_char((char *) sig));
3382 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3384 return (jfieldID) f;
3388 /* GetStatic<type>Field ********************************************************
3390 This family of accessor routines returns the value of a static
3393 *******************************************************************************/
3395 jobject GetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3400 STATISTICS(jniinvokation());
3402 c = (classinfo *) clazz;
3403 f = (fieldinfo *) fieldID;
3405 if (!(c->state & CLASS_INITIALIZED))
3406 if (!initialize_class(c))
3409 return NewLocalRef(env, f->value.a);
3413 jboolean GetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3418 STATISTICS(jniinvokation());
3420 c = (classinfo *) clazz;
3421 f = (fieldinfo *) fieldID;
3423 if (!(c->state & CLASS_INITIALIZED))
3424 if (!initialize_class(c))
3431 jbyte GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3436 STATISTICS(jniinvokation());
3438 c = (classinfo *) clazz;
3439 f = (fieldinfo *) fieldID;
3441 if (!(c->state & CLASS_INITIALIZED))
3442 if (!initialize_class(c))
3449 jchar GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3454 STATISTICS(jniinvokation());
3456 c = (classinfo *) clazz;
3457 f = (fieldinfo *) fieldID;
3459 if (!(c->state & CLASS_INITIALIZED))
3460 if (!initialize_class(c))
3467 jshort GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3472 STATISTICS(jniinvokation());
3474 c = (classinfo *) clazz;
3475 f = (fieldinfo *) fieldID;
3477 if (!(c->state & CLASS_INITIALIZED))
3478 if (!initialize_class(c))
3485 jint GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3490 STATISTICS(jniinvokation());
3492 c = (classinfo *) clazz;
3493 f = (fieldinfo *) fieldID;
3495 if (!(c->state & CLASS_INITIALIZED))
3496 if (!initialize_class(c))
3503 jlong GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3508 STATISTICS(jniinvokation());
3510 c = (classinfo *) clazz;
3511 f = (fieldinfo *) fieldID;
3513 if (!(c->state & CLASS_INITIALIZED))
3514 if (!initialize_class(c))
3521 jfloat GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3526 STATISTICS(jniinvokation());
3528 c = (classinfo *) clazz;
3529 f = (fieldinfo *) fieldID;
3531 if (!(c->state & CLASS_INITIALIZED))
3532 if (!initialize_class(c))
3539 jdouble GetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3544 STATISTICS(jniinvokation());
3546 c = (classinfo *) clazz;
3547 f = (fieldinfo *) fieldID;
3549 if (!(c->state & CLASS_INITIALIZED))
3550 if (!initialize_class(c))
3557 /* SetStatic<type>Field *******************************************************
3559 This family of accessor routines sets the value of a static field
3562 *******************************************************************************/
3564 void SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
3569 STATISTICS(jniinvokation());
3571 c = (classinfo *) clazz;
3572 f = (fieldinfo *) fieldID;
3574 if (!(c->state & CLASS_INITIALIZED))
3575 if (!initialize_class(c))
3582 void SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
3587 STATISTICS(jniinvokation());
3589 c = (classinfo *) clazz;
3590 f = (fieldinfo *) fieldID;
3592 if (!(c->state & CLASS_INITIALIZED))
3593 if (!initialize_class(c))
3600 void SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
3605 STATISTICS(jniinvokation());
3607 c = (classinfo *) clazz;
3608 f = (fieldinfo *) fieldID;
3610 if (!(c->state & CLASS_INITIALIZED))
3611 if (!initialize_class(c))
3618 void SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
3623 STATISTICS(jniinvokation());
3625 c = (classinfo *) clazz;
3626 f = (fieldinfo *) fieldID;
3628 if (!(c->state & CLASS_INITIALIZED))
3629 if (!initialize_class(c))
3636 void SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
3641 STATISTICS(jniinvokation());
3643 c = (classinfo *) clazz;
3644 f = (fieldinfo *) fieldID;
3646 if (!(c->state & CLASS_INITIALIZED))
3647 if (!initialize_class(c))
3654 void SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
3659 STATISTICS(jniinvokation());
3661 c = (classinfo *) clazz;
3662 f = (fieldinfo *) fieldID;
3664 if (!(c->state & CLASS_INITIALIZED))
3665 if (!initialize_class(c))
3672 void SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
3677 STATISTICS(jniinvokation());
3679 c = (classinfo *) clazz;
3680 f = (fieldinfo *) fieldID;
3682 if (!(c->state & CLASS_INITIALIZED))
3683 if (!initialize_class(c))
3690 void SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
3695 STATISTICS(jniinvokation());
3697 c = (classinfo *) clazz;
3698 f = (fieldinfo *) fieldID;
3700 if (!(c->state & CLASS_INITIALIZED))
3701 if (!initialize_class(c))
3708 void SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
3713 STATISTICS(jniinvokation());
3715 c = (classinfo *) clazz;
3716 f = (fieldinfo *) fieldID;
3718 if (!(c->state & CLASS_INITIALIZED))
3719 if (!initialize_class(c))
3726 /* String Operations **********************************************************/
3728 /* NewString *******************************************************************
3730 Create new java.lang.String object from an array of Unicode
3733 *******************************************************************************/
3735 jstring NewString(JNIEnv *env, const jchar *buf, jsize len)
3737 java_lang_String *s;
3741 STATISTICS(jniinvokation());
3743 s = (java_lang_String *) builtin_new(class_java_lang_String);
3744 a = builtin_newarray_char(len);
3746 /* javastring or characterarray could not be created */
3751 for (i = 0; i < len; i++)
3752 a->data[i] = buf[i];
3758 return (jstring) NewLocalRef(env, (jobject) s);
3762 static jchar emptyStringJ[]={0,0};
3764 /* GetStringLength *************************************************************
3766 Returns the length (the count of Unicode characters) of a Java
3769 *******************************************************************************/
3771 jsize GetStringLength(JNIEnv *env, jstring str)
3773 return ((java_lang_String *) str)->count;
3777 /******************** convertes javastring to u2-array ****************************/
3779 u2 *javastring_tou2(jstring so)
3781 java_lang_String *s;
3786 STATISTICS(jniinvokation());
3788 s = (java_lang_String *) so;
3798 /* allocate memory */
3800 stringbuffer = MNEW(u2, s->count + 1);
3804 for (i = 0; i < s->count; i++)
3805 stringbuffer[i] = a->data[s->offset + i];
3807 /* terminate string */
3809 stringbuffer[i] = '\0';
3811 return stringbuffer;
3815 /* GetStringChars **************************************************************
3817 Returns a pointer to the array of Unicode characters of the
3818 string. This pointer is valid until ReleaseStringchars() is called.
3820 *******************************************************************************/
3822 const jchar *GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
3826 STATISTICS(jniinvokation());
3828 jc = javastring_tou2(str);
3840 return emptyStringJ;
3844 /* ReleaseStringChars **********************************************************
3846 Informs the VM that the native code no longer needs access to
3847 chars. The chars argument is a pointer obtained from string using
3850 *******************************************************************************/
3852 void ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
3854 STATISTICS(jniinvokation());
3856 if (chars == emptyStringJ)
3859 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
3863 /* NewStringUTF ****************************************************************
3865 Constructs a new java.lang.String object from an array of UTF-8 characters.
3867 *******************************************************************************/
3869 jstring NewStringUTF(JNIEnv *env, const char *bytes)
3871 java_lang_String *s;
3873 STATISTICS(jniinvokation());
3875 s = javastring_new(utf_new_char(bytes));
3877 return (jstring) NewLocalRef(env, (jobject) s);
3881 /****************** returns the utf8 length in bytes of a string *******************/
3883 jsize GetStringUTFLength (JNIEnv *env, jstring string)
3885 java_lang_String *s = (java_lang_String*) string;
3887 STATISTICS(jniinvokation());
3889 return (jsize) u2_utflength(s->value->data, s->count);
3893 /* GetStringUTFChars ***********************************************************
3895 Returns a pointer to an array of UTF-8 characters of the
3896 string. This array is valid until it is released by
3897 ReleaseStringUTFChars().
3899 *******************************************************************************/
3901 const char *GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
3905 STATISTICS(jniinvokation());
3913 u = javastring_toutf((java_lang_String *) string, false);
3922 /* ReleaseStringUTFChars *******************************************************
3924 Informs the VM that the native code no longer needs access to
3925 utf. The utf argument is a pointer derived from string using
3926 GetStringUTFChars().
3928 *******************************************************************************/
3930 void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
3932 STATISTICS(jniinvokation());
3934 /* XXX we don't release utf chars right now, perhaps that should be done
3935 later. Since there is always one reference the garbage collector will
3940 /* Array Operations ***********************************************************/
3942 /* GetArrayLength **************************************************************
3944 Returns the number of elements in the array.
3946 *******************************************************************************/
3948 jsize GetArrayLength(JNIEnv *env, jarray array)
3950 java_arrayheader *a;
3952 STATISTICS(jniinvokation());
3954 a = (java_arrayheader *) array;
3960 /* NewObjectArray **************************************************************
3962 Constructs a new array holding objects in class elementClass. All
3963 elements are initially set to initialElement.
3965 *******************************************************************************/
3967 jobjectArray NewObjectArray(JNIEnv *env, jsize length, jclass elementClass, jobject initialElement)
3969 java_objectarray *oa;
3972 STATISTICS(jniinvokation());
3975 exceptions_throw_negativearraysizeexception();
3979 oa = builtin_anewarray(length, elementClass);
3984 /* set all elements to initialElement */
3986 for (i = 0; i < length; i++)
3987 oa->data[i] = initialElement;
3989 return (jobjectArray) NewLocalRef(env, (jobject) oa);
3993 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
3995 java_objectarray *oa;
3998 STATISTICS(jniinvokation());
4000 oa = (java_objectarray *) array;
4002 if (index >= oa->header.size) {
4003 exceptions_throw_arrayindexoutofboundsexception();
4007 o = oa->data[index];
4009 return NewLocalRef(env, o);
4013 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
4015 java_objectarray *oa;
4016 java_objectheader *o;
4018 STATISTICS(jniinvokation());
4020 oa = (java_objectarray *) array;
4021 o = (java_objectheader *) val;
4023 if (index >= oa->header.size) {
4024 exceptions_throw_arrayindexoutofboundsexception();
4028 /* check if the class of value is a subclass of the element class
4031 if (!builtin_canstore(oa, o)) {
4032 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4037 oa->data[index] = val;
4041 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
4043 java_booleanarray *ba;
4045 STATISTICS(jniinvokation());
4048 exceptions_throw_negativearraysizeexception();
4052 ba = builtin_newarray_boolean(len);
4054 return (jbooleanArray) NewLocalRef(env, (jobject) ba);
4058 jbyteArray NewByteArray(JNIEnv *env, jsize len)
4062 STATISTICS(jniinvokation());
4065 exceptions_throw_negativearraysizeexception();
4069 ba = builtin_newarray_byte(len);
4071 return (jbyteArray) NewLocalRef(env, (jobject) ba);
4075 jcharArray NewCharArray(JNIEnv *env, jsize len)
4079 STATISTICS(jniinvokation());
4082 exceptions_throw_negativearraysizeexception();
4086 ca = builtin_newarray_char(len);
4088 return (jcharArray) NewLocalRef(env, (jobject) ca);
4092 jshortArray NewShortArray(JNIEnv *env, jsize len)
4094 java_shortarray *sa;
4096 STATISTICS(jniinvokation());
4099 exceptions_throw_negativearraysizeexception();
4103 sa = builtin_newarray_short(len);
4105 return (jshortArray) NewLocalRef(env, (jobject) sa);
4109 jintArray NewIntArray(JNIEnv *env, jsize len)
4113 STATISTICS(jniinvokation());
4116 exceptions_throw_negativearraysizeexception();
4120 ia = builtin_newarray_int(len);
4122 return (jintArray) NewLocalRef(env, (jobject) ia);
4126 jlongArray NewLongArray(JNIEnv *env, jsize len)
4130 STATISTICS(jniinvokation());
4133 exceptions_throw_negativearraysizeexception();
4137 la = builtin_newarray_long(len);
4139 return (jlongArray) NewLocalRef(env, (jobject) la);
4143 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
4145 java_floatarray *fa;
4147 STATISTICS(jniinvokation());
4150 exceptions_throw_negativearraysizeexception();
4154 fa = builtin_newarray_float(len);
4156 return (jfloatArray) NewLocalRef(env, (jobject) fa);
4160 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
4162 java_doublearray *da;
4164 STATISTICS(jniinvokation());
4167 exceptions_throw_negativearraysizeexception();
4171 da = builtin_newarray_double(len);
4173 return (jdoubleArray) NewLocalRef(env, (jobject) da);
4177 /* Get<PrimitiveType>ArrayElements *********************************************
4179 A family of functions that returns the body of the primitive array.
4181 *******************************************************************************/
4183 jboolean *GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4186 java_booleanarray *ba;
4188 STATISTICS(jniinvokation());
4190 ba = (java_booleanarray *) array;
4193 *isCopy = JNI_FALSE;
4199 jbyte *GetByteArrayElements(JNIEnv *env, jbyteArray array, jboolean *isCopy)
4203 STATISTICS(jniinvokation());
4205 ba = (java_bytearray *) array;
4208 *isCopy = JNI_FALSE;
4214 jchar *GetCharArrayElements(JNIEnv *env, jcharArray array, jboolean *isCopy)
4218 STATISTICS(jniinvokation());
4220 ca = (java_chararray *) array;
4223 *isCopy = JNI_FALSE;
4229 jshort *GetShortArrayElements(JNIEnv *env, jshortArray array, jboolean *isCopy)
4231 java_shortarray *sa;
4233 STATISTICS(jniinvokation());
4235 sa = (java_shortarray *) array;
4238 *isCopy = JNI_FALSE;
4244 jint *GetIntArrayElements(JNIEnv *env, jintArray array, jboolean *isCopy)
4248 STATISTICS(jniinvokation());
4250 ia = (java_intarray *) array;
4253 *isCopy = JNI_FALSE;
4259 jlong *GetLongArrayElements(JNIEnv *env, jlongArray array, jboolean *isCopy)
4263 STATISTICS(jniinvokation());
4265 la = (java_longarray *) array;
4268 *isCopy = JNI_FALSE;
4270 /* We cast this one to prevent a compiler warning on 64-bit
4271 systems since GNU Classpath typedef jlong to long long. */
4273 return (jlong *) la->data;
4277 jfloat *GetFloatArrayElements(JNIEnv *env, jfloatArray array, jboolean *isCopy)
4279 java_floatarray *fa;
4281 STATISTICS(jniinvokation());
4283 fa = (java_floatarray *) array;
4286 *isCopy = JNI_FALSE;
4292 jdouble *GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4295 java_doublearray *da;
4297 STATISTICS(jniinvokation());
4299 da = (java_doublearray *) array;
4302 *isCopy = JNI_FALSE;
4308 /* Release<PrimitiveType>ArrayElements *****************************************
4310 A family of functions that informs the VM that the native code no
4311 longer needs access to elems. The elems argument is a pointer
4312 derived from array using the corresponding
4313 Get<PrimitiveType>ArrayElements() function. If necessary, this
4314 function copies back all changes made to elems to the original
4317 *******************************************************************************/
4319 void ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4320 jboolean *elems, jint mode)
4322 java_booleanarray *ba;
4324 STATISTICS(jniinvokation());
4326 ba = (java_booleanarray *) array;
4328 if (elems != ba->data) {
4331 MCOPY(ba->data, elems, u1, ba->header.size);
4334 MCOPY(ba->data, elems, u1, ba->header.size);
4335 /* XXX TWISTI how should it be freed? */
4338 /* XXX TWISTI how should it be freed? */
4345 void ReleaseByteArrayElements(JNIEnv *env, jbyteArray array, jbyte *elems,
4350 STATISTICS(jniinvokation());
4352 ba = (java_bytearray *) array;
4354 if (elems != ba->data) {
4357 MCOPY(ba->data, elems, s1, ba->header.size);
4360 MCOPY(ba->data, elems, s1, ba->header.size);
4361 /* XXX TWISTI how should it be freed? */
4364 /* XXX TWISTI how should it be freed? */
4371 void ReleaseCharArrayElements(JNIEnv *env, jcharArray array, jchar *elems,
4376 STATISTICS(jniinvokation());
4378 ca = (java_chararray *) array;
4380 if (elems != ca->data) {
4383 MCOPY(ca->data, elems, u2, ca->header.size);
4386 MCOPY(ca->data, elems, u2, ca->header.size);
4387 /* XXX TWISTI how should it be freed? */
4390 /* XXX TWISTI how should it be freed? */
4397 void ReleaseShortArrayElements(JNIEnv *env, jshortArray array, jshort *elems,
4400 java_shortarray *sa;
4402 STATISTICS(jniinvokation());
4404 sa = (java_shortarray *) array;
4406 if (elems != sa->data) {
4409 MCOPY(sa->data, elems, s2, sa->header.size);
4412 MCOPY(sa->data, elems, s2, sa->header.size);
4413 /* XXX TWISTI how should it be freed? */
4416 /* XXX TWISTI how should it be freed? */
4423 void ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4428 STATISTICS(jniinvokation());
4430 ia = (java_intarray *) array;
4432 if (elems != ia->data) {
4435 MCOPY(ia->data, elems, s4, ia->header.size);
4438 MCOPY(ia->data, elems, s4, ia->header.size);
4439 /* XXX TWISTI how should it be freed? */
4442 /* XXX TWISTI how should it be freed? */
4449 void ReleaseLongArrayElements(JNIEnv *env, jlongArray array, jlong *elems,
4454 STATISTICS(jniinvokation());
4456 la = (java_longarray *) array;
4458 /* We cast this one to prevent a compiler warning on 64-bit
4459 systems since GNU Classpath typedef jlong to long long. */
4461 if ((s8 *) elems != la->data) {
4464 MCOPY(la->data, elems, s8, la->header.size);
4467 MCOPY(la->data, elems, s8, la->header.size);
4468 /* XXX TWISTI how should it be freed? */
4471 /* XXX TWISTI how should it be freed? */
4478 void ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems,
4481 java_floatarray *fa;
4483 STATISTICS(jniinvokation());
4485 fa = (java_floatarray *) array;
4487 if (elems != fa->data) {
4490 MCOPY(fa->data, elems, float, fa->header.size);
4493 MCOPY(fa->data, elems, float, fa->header.size);
4494 /* XXX TWISTI how should it be freed? */
4497 /* XXX TWISTI how should it be freed? */
4504 void ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4505 jdouble *elems, jint mode)
4507 java_doublearray *da;
4509 STATISTICS(jniinvokation());
4511 da = (java_doublearray *) array;
4513 if (elems != da->data) {
4516 MCOPY(da->data, elems, double, da->header.size);
4519 MCOPY(da->data, elems, double, da->header.size);
4520 /* XXX TWISTI how should it be freed? */
4523 /* XXX TWISTI how should it be freed? */
4530 /* Get<PrimitiveType>ArrayRegion **********************************************
4532 A family of functions that copies a region of a primitive array
4535 *******************************************************************************/
4537 void GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4538 jsize len, jboolean *buf)
4540 java_booleanarray *ba;
4542 STATISTICS(jniinvokation());
4544 ba = (java_booleanarray *) array;
4546 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4547 exceptions_throw_arrayindexoutofboundsexception();
4549 MCOPY(buf, &ba->data[start], u1, len);
4553 void GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4558 STATISTICS(jniinvokation());
4560 ba = (java_bytearray *) array;
4562 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4563 exceptions_throw_arrayindexoutofboundsexception();
4565 MCOPY(buf, &ba->data[start], s1, len);
4569 void GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4574 STATISTICS(jniinvokation());
4576 ca = (java_chararray *) array;
4578 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4579 exceptions_throw_arrayindexoutofboundsexception();
4581 MCOPY(buf, &ca->data[start], u2, len);
4585 void GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4586 jsize len, jshort *buf)
4588 java_shortarray *sa;
4590 STATISTICS(jniinvokation());
4592 sa = (java_shortarray *) array;
4594 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4595 exceptions_throw_arrayindexoutofboundsexception();
4597 MCOPY(buf, &sa->data[start], s2, len);
4601 void GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4606 STATISTICS(jniinvokation());
4608 ia = (java_intarray *) array;
4610 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4611 exceptions_throw_arrayindexoutofboundsexception();
4613 MCOPY(buf, &ia->data[start], s4, len);
4617 void GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start, jsize len,
4622 STATISTICS(jniinvokation());
4624 la = (java_longarray *) array;
4626 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4627 exceptions_throw_arrayindexoutofboundsexception();
4629 MCOPY(buf, &la->data[start], s8, len);
4633 void GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4634 jsize len, jfloat *buf)
4636 java_floatarray *fa;
4638 STATISTICS(jniinvokation());
4640 fa = (java_floatarray *) array;
4642 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4643 exceptions_throw_arrayindexoutofboundsexception();
4645 MCOPY(buf, &fa->data[start], float, len);
4649 void GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4650 jsize len, jdouble *buf)
4652 java_doublearray *da;
4654 STATISTICS(jniinvokation());
4656 da = (java_doublearray *) array;
4658 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4659 exceptions_throw_arrayindexoutofboundsexception();
4661 MCOPY(buf, &da->data[start], double, len);
4665 /* Set<PrimitiveType>ArrayRegion **********************************************
4667 A family of functions that copies back a region of a primitive
4668 array from a buffer.
4670 *******************************************************************************/
4672 void SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array, jsize start,
4673 jsize len, jboolean *buf)
4675 java_booleanarray *ba;
4677 STATISTICS(jniinvokation());
4679 ba = (java_booleanarray *) array;
4681 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4682 exceptions_throw_arrayindexoutofboundsexception();
4684 MCOPY(&ba->data[start], buf, u1, len);
4688 void SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start, jsize len,
4693 STATISTICS(jniinvokation());
4695 ba = (java_bytearray *) array;
4697 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4698 exceptions_throw_arrayindexoutofboundsexception();
4700 MCOPY(&ba->data[start], buf, s1, len);
4704 void SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start, jsize len,
4709 STATISTICS(jniinvokation());
4711 ca = (java_chararray *) array;
4713 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4714 exceptions_throw_arrayindexoutofboundsexception();
4716 MCOPY(&ca->data[start], buf, u2, len);
4720 void SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4721 jsize len, jshort *buf)
4723 java_shortarray *sa;
4725 STATISTICS(jniinvokation());
4727 sa = (java_shortarray *) array;
4729 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4730 exceptions_throw_arrayindexoutofboundsexception();
4732 MCOPY(&sa->data[start], buf, s2, len);
4736 void SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start, jsize len,
4741 STATISTICS(jniinvokation());
4743 ia = (java_intarray *) array;
4745 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4746 exceptions_throw_arrayindexoutofboundsexception();
4748 MCOPY(&ia->data[start], buf, s4, len);
4752 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len,
4757 STATISTICS(jniinvokation());
4759 la = (java_longarray *) array;
4761 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4762 exceptions_throw_arrayindexoutofboundsexception();
4764 MCOPY(&la->data[start], buf, s8, len);
4768 void SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4769 jsize len, jfloat *buf)
4771 java_floatarray *fa;
4773 STATISTICS(jniinvokation());
4775 fa = (java_floatarray *) array;
4777 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4778 exceptions_throw_arrayindexoutofboundsexception();
4780 MCOPY(&fa->data[start], buf, float, len);
4784 void SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4785 jsize len, jdouble *buf)
4787 java_doublearray *da;
4789 STATISTICS(jniinvokation());
4791 da = (java_doublearray *) array;
4793 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4794 exceptions_throw_arrayindexoutofboundsexception();
4796 MCOPY(&da->data[start], buf, double, len);
4800 /* Registering Native Methods *************************************************/
4802 /* RegisterNatives *************************************************************
4804 Registers native methods with the class specified by the clazz
4805 argument. The methods parameter specifies an array of
4806 JNINativeMethod structures that contain the names, signatures, and
4807 function pointers of the native methods. The nMethods parameter
4808 specifies the number of native methods in the array.
4810 *******************************************************************************/
4812 jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods,
4815 STATISTICS(jniinvokation());
4817 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
4823 /* UnregisterNatives ***********************************************************
4825 Unregisters native methods of a class. The class goes back to the
4826 state before it was linked or registered with its native method
4829 This function should not be used in normal native code. Instead, it
4830 provides special programs a way to reload and relink native
4833 *******************************************************************************/
4835 jint UnregisterNatives(JNIEnv *env, jclass clazz)
4837 STATISTICS(jniinvokation());
4839 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
4841 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
4847 /* Monitor Operations *********************************************************/
4849 /* MonitorEnter ****************************************************************
4851 Enters the monitor associated with the underlying Java object
4854 *******************************************************************************/
4856 jint MonitorEnter(JNIEnv *env, jobject obj)
4858 STATISTICS(jniinvokation());
4861 exceptions_throw_nullpointerexception();
4865 #if defined(USE_THREADS)
4866 builtin_monitorenter(obj);
4873 /* MonitorExit *****************************************************************
4875 The current thread must be the owner of the monitor associated with
4876 the underlying Java object referred to by obj. The thread
4877 decrements the counter indicating the number of times it has
4878 entered this monitor. If the value of the counter becomes zero, the
4879 current thread releases the monitor.
4881 *******************************************************************************/
4883 jint MonitorExit(JNIEnv *env, jobject obj)
4885 STATISTICS(jniinvokation());
4888 exceptions_throw_nullpointerexception();
4892 #if defined(USE_THREADS)
4893 builtin_monitorexit(obj);
4900 /* JavaVM Interface ***********************************************************/
4902 /* GetJavaVM *******************************************************************
4904 Returns the Java VM interface (used in the Invocation API)
4905 associated with the current thread. The result is placed at the
4906 location pointed to by the second argument, vm.
4908 *******************************************************************************/
4910 jint GetJavaVM(JNIEnv *env, JavaVM **vm)
4912 STATISTICS(jniinvokation());
4914 *vm = (JavaVM *) _Jv_jvm;
4920 /* GetStringRegion *************************************************************
4922 Copies len number of Unicode characters beginning at offset start
4923 to the given buffer buf.
4925 Throws StringIndexOutOfBoundsException on index overflow.
4927 *******************************************************************************/
4929 void GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
4931 java_lang_String *s;
4934 STATISTICS(jniinvokation());
4936 s = (java_lang_String *) str;
4939 if ((start < 0) || (len < 0) || (start > s->count) ||
4940 (start + len > s->count)) {
4941 exceptions_throw_stringindexoutofboundsexception();
4945 MCOPY(buf, &ca->data[start], u2, len);
4949 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
4951 STATISTICS(jniinvokation());
4953 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
4957 /* GetPrimitiveArrayCritical ***************************************************
4959 Obtain a direct pointer to array elements.
4961 *******************************************************************************/
4963 void *GetPrimitiveArrayCritical(JNIEnv *env, jarray array, jboolean *isCopy)
4968 ba = (java_bytearray *) array;
4970 /* do the same as Kaffe does */
4972 bp = GetByteArrayElements(env, ba, isCopy);
4978 /* ReleasePrimitiveArrayCritical ***********************************************
4980 No specific documentation.
4982 *******************************************************************************/
4984 void ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array, void *carray,
4987 STATISTICS(jniinvokation());
4989 /* do the same as Kaffe does */
4991 ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray, mode);
4995 /* GetStringCritical ***********************************************************
4997 The semantics of these two functions are similar to the existing
4998 Get/ReleaseStringChars functions.
5000 *******************************************************************************/
5002 const jchar *GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy)
5004 STATISTICS(jniinvokation());
5006 return GetStringChars(env, string, isCopy);
5010 void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *cstring)
5012 STATISTICS(jniinvokation());
5014 ReleaseStringChars(env, string, cstring);
5018 jweak NewWeakGlobalRef(JNIEnv* env, jobject obj)
5020 STATISTICS(jniinvokation());
5022 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5028 void DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5030 STATISTICS(jniinvokation());
5032 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5036 /* NewGlobalRef ****************************************************************
5038 Creates a new global reference to the object referred to by the obj
5041 *******************************************************************************/
5043 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
5045 java_objectheader *o;
5046 java_lang_Integer *refcount;
5047 java_objectheader *newval;
5049 STATISTICS(jniinvokation());
5051 #if defined(USE_THREADS)
5052 builtin_monitorenter(*global_ref_table);
5055 o = vm_call_method(getmid, *global_ref_table, lobj);
5057 refcount = (java_lang_Integer *) o;
5059 if (refcount == NULL) {
5060 newval = native_new_and_init_int(class_java_lang_Integer, 1);
5062 if (newval == NULL) {
5063 #if defined(USE_THREADS)
5064 builtin_monitorexit(*global_ref_table);
5069 (void) vm_call_method(putmid, *global_ref_table, lobj, newval);
5072 /* we can access the object itself, as we are in a
5073 synchronized section */
5078 #if defined(USE_THREADS)
5079 builtin_monitorexit(*global_ref_table);
5086 /* DeleteGlobalRef *************************************************************
5088 Deletes the global reference pointed to by globalRef.
5090 *******************************************************************************/
5092 void DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5094 java_objectheader *o;
5095 java_lang_Integer *refcount;
5098 STATISTICS(jniinvokation());
5100 #if defined(USE_THREADS)
5101 builtin_monitorenter(*global_ref_table);
5104 o = vm_call_method(getmid, *global_ref_table, globalRef);
5106 refcount = (java_lang_Integer *) o;
5108 if (refcount == NULL) {
5109 log_text("JNI-DeleteGlobalRef: unable to find global reference");
5113 /* we can access the object itself, as we are in a synchronized
5116 val = refcount->value - 1;
5119 (void) vm_call_method(removemid, *global_ref_table, refcount);
5122 /* we do not create a new object, but set the new value into
5125 refcount->value = val;
5128 #if defined(USE_THREADS)
5129 builtin_monitorexit(*global_ref_table);
5134 /* ExceptionCheck **************************************************************
5136 Returns JNI_TRUE when there is a pending exception; otherwise,
5139 *******************************************************************************/
5141 jboolean ExceptionCheck(JNIEnv *env)
5143 STATISTICS(jniinvokation());
5145 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5149 /* New JNI 1.4 functions ******************************************************/
5151 /* NewDirectByteBuffer *********************************************************
5153 Allocates and returns a direct java.nio.ByteBuffer referring to the
5154 block of memory starting at the memory address address and
5155 extending capacity bytes.
5157 *******************************************************************************/
5159 jobject NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5161 java_objectheader *nbuf;
5162 #if SIZEOF_VOID_P == 8
5163 gnu_classpath_Pointer64 *paddress;
5165 gnu_classpath_Pointer32 *paddress;
5168 STATISTICS(jniinvokation());
5170 /* alocate a gnu.classpath.Pointer{32,64} object */
5172 #if SIZEOF_VOID_P == 8
5173 if (!(paddress = (gnu_classpath_Pointer64 *)
5174 builtin_new(class_gnu_classpath_Pointer64)))
5176 if (!(paddress = (gnu_classpath_Pointer32 *)
5177 builtin_new(class_gnu_classpath_Pointer32)))
5181 /* fill gnu.classpath.Pointer{32,64} with address */
5183 paddress->data = (ptrint) address;
5185 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5187 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5188 (jmethodID) dbbirw_init, NULL, paddress,
5189 (jint) capacity, (jint) capacity, (jint) 0);
5191 /* add local reference and return the value */
5193 return NewLocalRef(env, nbuf);
5197 /* GetDirectBufferAddress ******************************************************
5199 Fetches and returns the starting address of the memory region
5200 referenced by the given direct java.nio.Buffer.
5202 *******************************************************************************/
5204 void *GetDirectBufferAddress(JNIEnv *env, jobject buf)
5206 java_nio_DirectByteBufferImpl *nbuf;
5207 #if SIZEOF_VOID_P == 8
5208 gnu_classpath_Pointer64 *address;
5210 gnu_classpath_Pointer32 *address;
5213 STATISTICS(jniinvokation());
5215 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5218 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5220 #if SIZEOF_VOID_P == 8
5221 address = (gnu_classpath_Pointer64 *) nbuf->address;
5223 address = (gnu_classpath_Pointer32 *) nbuf->address;
5226 return (void *) address->data;
5230 /* GetDirectBufferCapacity *****************************************************
5232 Fetches and returns the capacity in bytes of the memory region
5233 referenced by the given direct java.nio.Buffer.
5235 *******************************************************************************/
5237 jlong GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5239 java_nio_Buffer *nbuf;
5241 STATISTICS(jniinvokation());
5243 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5246 nbuf = (java_nio_Buffer *) buf;
5248 return (jlong) nbuf->cap;
5252 /* DestroyJavaVM ***************************************************************
5254 Unloads a Java VM and reclaims its resources. Only the main thread
5255 can unload the VM. The system waits until the main thread is only
5256 remaining user thread before it destroys the VM.
5258 *******************************************************************************/
5260 jint DestroyJavaVM(JavaVM *vm)
5264 STATISTICS(jniinvokation());
5266 status = vm_destroy(vm);
5272 /* AttachCurrentThread *********************************************************
5274 Attaches the current thread to a Java VM. Returns a JNI interface
5275 pointer in the JNIEnv argument.
5277 Trying to attach a thread that is already attached is a no-op.
5279 A native thread cannot be attached simultaneously to two Java VMs.
5281 When a thread is attached to the VM, the context class loader is
5282 the bootstrap loader.
5284 *******************************************************************************/
5286 jint AttachCurrentThread(JavaVM *vm, void **env, void *thr_args)
5288 STATISTICS(jniinvokation());
5290 log_text("JNI-Call: AttachCurrentThread: IMPLEMENT ME!");
5292 #if !defined(HAVE___THREAD)
5293 /* cacao_thread_attach();*/
5295 #error "No idea how to implement that. Perhaps Stefan knows"
5304 jint DetachCurrentThread(JavaVM *vm)
5306 STATISTICS(jniinvokation());
5308 log_text("JNI-Call: DetachCurrentThread: IMPLEMENT ME!");
5314 /* GetEnv **********************************************************************
5316 If the current thread is not attached to the VM, sets *env to NULL,
5317 and returns JNI_EDETACHED. If the specified version is not
5318 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5319 sets *env to the appropriate interface, and returns JNI_OK.
5321 *******************************************************************************/
5323 jint GetEnv(JavaVM *vm, void **env, jint version)
5325 STATISTICS(jniinvokation());
5327 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
5328 if (thread_getself() == NULL) {
5331 return JNI_EDETACHED;
5335 if ((version == JNI_VERSION_1_1) || (version == JNI_VERSION_1_2) ||
5336 (version == JNI_VERSION_1_4)) {
5342 #if defined(ENABLE_JVMTI)
5343 if (version == JVMTI_VERSION_1_0) {
5344 *env = (void *) new_jvmtienv();
5353 return JNI_EVERSION;
5358 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
5360 STATISTICS(jniinvokation());
5362 log_text("JNI-Call: AttachCurrentThreadAsDaemon: IMPLEMENT ME!");
5368 /* JNI invocation table *******************************************************/
5370 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5376 AttachCurrentThread,
5377 DetachCurrentThread,
5379 AttachCurrentThreadAsDaemon
5383 /* JNI function table *********************************************************/
5385 struct JNINativeInterface _Jv_JNINativeInterface = {
5394 FromReflectedMethod,
5415 EnsureLocalCapacity,
5458 CallNonvirtualObjectMethod,
5459 CallNonvirtualObjectMethodV,
5460 CallNonvirtualObjectMethodA,
5461 CallNonvirtualBooleanMethod,
5462 CallNonvirtualBooleanMethodV,
5463 CallNonvirtualBooleanMethodA,
5464 CallNonvirtualByteMethod,
5465 CallNonvirtualByteMethodV,
5466 CallNonvirtualByteMethodA,
5467 CallNonvirtualCharMethod,
5468 CallNonvirtualCharMethodV,
5469 CallNonvirtualCharMethodA,
5470 CallNonvirtualShortMethod,
5471 CallNonvirtualShortMethodV,
5472 CallNonvirtualShortMethodA,
5473 CallNonvirtualIntMethod,
5474 CallNonvirtualIntMethodV,
5475 CallNonvirtualIntMethodA,
5476 CallNonvirtualLongMethod,
5477 CallNonvirtualLongMethodV,
5478 CallNonvirtualLongMethodA,
5479 CallNonvirtualFloatMethod,
5480 CallNonvirtualFloatMethodV,
5481 CallNonvirtualFloatMethodA,
5482 CallNonvirtualDoubleMethod,
5483 CallNonvirtualDoubleMethodV,
5484 CallNonvirtualDoubleMethodA,
5485 CallNonvirtualVoidMethod,
5486 CallNonvirtualVoidMethodV,
5487 CallNonvirtualVoidMethodA,
5512 CallStaticObjectMethod,
5513 CallStaticObjectMethodV,
5514 CallStaticObjectMethodA,
5515 CallStaticBooleanMethod,
5516 CallStaticBooleanMethodV,
5517 CallStaticBooleanMethodA,
5518 CallStaticByteMethod,
5519 CallStaticByteMethodV,
5520 CallStaticByteMethodA,
5521 CallStaticCharMethod,
5522 CallStaticCharMethodV,
5523 CallStaticCharMethodA,
5524 CallStaticShortMethod,
5525 CallStaticShortMethodV,
5526 CallStaticShortMethodA,
5527 CallStaticIntMethod,
5528 CallStaticIntMethodV,
5529 CallStaticIntMethodA,
5530 CallStaticLongMethod,
5531 CallStaticLongMethodV,
5532 CallStaticLongMethodA,
5533 CallStaticFloatMethod,
5534 CallStaticFloatMethodV,
5535 CallStaticFloatMethodA,
5536 CallStaticDoubleMethod,
5537 CallStaticDoubleMethodV,
5538 CallStaticDoubleMethodA,
5539 CallStaticVoidMethod,
5540 CallStaticVoidMethodV,
5541 CallStaticVoidMethodA,
5545 GetStaticObjectField,
5546 GetStaticBooleanField,
5549 GetStaticShortField,
5552 GetStaticFloatField,
5553 GetStaticDoubleField,
5554 SetStaticObjectField,
5555 SetStaticBooleanField,
5558 SetStaticShortField,
5561 SetStaticFloatField,
5562 SetStaticDoubleField,
5572 ReleaseStringUTFChars,
5577 GetObjectArrayElement,
5578 SetObjectArrayElement,
5589 GetBooleanArrayElements,
5590 GetByteArrayElements,
5591 GetCharArrayElements,
5592 GetShortArrayElements,
5593 GetIntArrayElements,
5594 GetLongArrayElements,
5595 GetFloatArrayElements,
5596 GetDoubleArrayElements,
5598 ReleaseBooleanArrayElements,
5599 ReleaseByteArrayElements,
5600 ReleaseCharArrayElements,
5601 ReleaseShortArrayElements,
5602 ReleaseIntArrayElements,
5603 ReleaseLongArrayElements,
5604 ReleaseFloatArrayElements,
5605 ReleaseDoubleArrayElements,
5607 GetBooleanArrayRegion,
5610 GetShortArrayRegion,
5613 GetFloatArrayRegion,
5614 GetDoubleArrayRegion,
5615 SetBooleanArrayRegion,
5618 SetShortArrayRegion,
5621 SetFloatArrayRegion,
5622 SetDoubleArrayRegion,
5632 /* new JNI 1.2 functions */
5637 GetPrimitiveArrayCritical,
5638 ReleasePrimitiveArrayCritical,
5641 ReleaseStringCritical,
5644 DeleteWeakGlobalRef,
5648 /* new JNI 1.4 functions */
5650 NewDirectByteBuffer,
5651 GetDirectBufferAddress,
5652 GetDirectBufferCapacity
5656 /* Invocation API Functions ***************************************************/
5658 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5660 Returns a default configuration for the Java VM.
5662 *******************************************************************************/
5664 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5666 JavaVMInitArgs *_vm_args;
5668 _vm_args = (JavaVMInitArgs *) vm_args;
5670 /* GNU classpath currently supports JNI 1.2 */
5672 switch (_vm_args->version) {
5673 case JNI_VERSION_1_1:
5674 _vm_args->version = JNI_VERSION_1_1;
5677 case JNI_VERSION_1_2:
5678 case JNI_VERSION_1_4:
5679 _vm_args->ignoreUnrecognized = JNI_FALSE;
5680 _vm_args->options = NULL;
5681 _vm_args->nOptions = 0;
5692 /* JNI_GetCreatedJavaVMs *******************************************************
5694 Returns all Java VMs that have been created. Pointers to VMs are written in
5695 the buffer vmBuf in the order they are created. At most bufLen number of
5696 entries will be written. The total number of created VMs is returned in
5699 *******************************************************************************/
5701 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
5703 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
5709 /* JNI_CreateJavaVM ************************************************************
5711 Loads and initializes a Java VM. The current thread becomes the main thread.
5712 Sets the env argument to the JNI interface pointer of the main thread.
5714 *******************************************************************************/
5716 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
5718 JavaVMInitArgs *_vm_args;
5721 localref_table *lrt;
5723 /* get the arguments for the new JVM */
5725 _vm_args = (JavaVMInitArgs *) vm_args;
5727 /* get the VM and Env tables (must be set before vm_create) */
5729 env = NEW(_Jv_JNIEnv);
5730 env->env = &_Jv_JNINativeInterface;
5732 /* XXX Set the global variable. Maybe we should do that differently. */
5736 /* actually create the JVM */
5738 if (!vm_create(_vm_args))
5741 /* create and fill a JavaVM structure */
5743 jvm = NEW(_Jv_JavaVM);
5744 jvm->functions = &_Jv_JNIInvokeInterface;
5746 /* XXX Set the global variable. Maybe we should do that differently. */
5750 /* setup the local ref table (must be created after vm_create) */
5752 lrt = GCNEW(localref_table);
5754 lrt->capacity = LOCALREFTABLE_CAPACITY;
5756 lrt->localframes = 1;
5757 lrt->prev = LOCALREFTABLE;
5759 /* clear the references array (memset is faster then a for-loop) */
5761 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
5763 LOCALREFTABLE = lrt;
5765 /* now return the values */
5767 *p_vm = (JavaVM *) jvm;
5768 *p_env = (void *) env;
5775 * These are local overrides for various environment variables in Emacs.
5776 * Please do not remove this and leave it at the end of the file, where
5777 * Emacs will automagically detect them.
5778 * ---------------------------------------------------------------------
5781 * indent-tabs-mode: t
5785 * vim:noexpandtab:sw=4:ts=4: