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 6011 2006-11-16 15:56:44Z twisti $
47 #include "mm/gc-common.h"
48 #include "mm/memory.h"
49 #include "native/jni.h"
50 #include "native/native.h"
52 #include "native/include/gnu_classpath_Pointer.h"
54 #if SIZEOF_VOID_P == 8
55 # include "native/include/gnu_classpath_Pointer64.h"
57 # include "native/include/gnu_classpath_Pointer32.h"
60 #include "native/include/java_lang_Object.h"
61 #include "native/include/java_lang_Byte.h"
62 #include "native/include/java_lang_Character.h"
63 #include "native/include/java_lang_Short.h"
64 #include "native/include/java_lang_Integer.h"
65 #include "native/include/java_lang_Boolean.h"
66 #include "native/include/java_lang_Long.h"
67 #include "native/include/java_lang_Float.h"
68 #include "native/include/java_lang_Double.h"
69 #include "native/include/java_lang_Throwable.h"
70 #include "native/include/java_lang_reflect_Method.h"
71 #include "native/include/java_lang_reflect_Constructor.h"
72 #include "native/include/java_lang_reflect_Field.h"
74 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
75 #include "native/include/java_lang_VMClass.h"
76 #include "native/include/java_lang_VMClassLoader.h"
77 #include "native/include/java_nio_Buffer.h"
78 #include "native/include/java_nio_DirectByteBufferImpl.h"
80 #if defined(ENABLE_JVMTI)
81 # include "native/jvmti/cacaodbg.h"
84 #if defined(ENABLE_THREADS)
85 # include "threads/native/lock.h"
86 # include "threads/native/threads.h"
88 # include "threads/none/lock.h"
91 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/loader.h"
97 #include "vm/options.h"
98 #include "vm/resolve.h"
99 #include "vm/statistics.h"
100 #include "vm/stringlocal.h"
101 #include "vm/jit/asmpart.h"
102 #include "vm/jit/jit.h"
103 #include "vm/statistics.h"
107 /* global variables ***********************************************************/
109 /* global reference table *****************************************************/
111 /* hashsize must be power of 2 */
113 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
115 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
118 /* direct buffer stuff ********************************************************/
120 static classinfo *class_java_nio_Buffer;
121 static classinfo *class_java_nio_DirectByteBufferImpl;
122 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
123 #if SIZEOF_VOID_P == 8
124 static classinfo *class_gnu_classpath_Pointer64;
126 static classinfo *class_gnu_classpath_Pointer32;
129 static methodinfo *dbbirw_init;
132 /* local reference table ******************************************************/
134 #if !defined(ENABLE_THREADS)
135 localref_table *_no_threads_localref_table;
139 /* accessing instance fields macros *******************************************/
141 #define SET_FIELD(o,type,f,value) \
142 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
144 #define GET_FIELD(o,type,f) \
145 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
148 /* some forward declarations **************************************************/
150 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
151 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
154 /* jni_init ********************************************************************
156 Initialize the JNI subsystem.
158 *******************************************************************************/
162 /* create global ref hashtable */
164 hashtable_global_ref = NEW(hashtable);
166 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
169 /* direct buffer stuff */
171 if (!(class_java_nio_Buffer =
172 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
173 !link_class(class_java_nio_Buffer))
176 if (!(class_java_nio_DirectByteBufferImpl =
177 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
178 !link_class(class_java_nio_DirectByteBufferImpl))
181 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
182 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
183 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
187 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
189 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
192 #if SIZEOF_VOID_P == 8
193 if (!(class_gnu_classpath_Pointer64 =
194 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
195 !link_class(class_gnu_classpath_Pointer64))
198 if (!(class_gnu_classpath_Pointer32 =
199 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
200 !link_class(class_gnu_classpath_Pointer32))
208 /* jni_init_localref_table *****************************************************
210 Initializes the local references table of the current thread.
212 *******************************************************************************/
214 bool jni_init_localref_table(void)
218 lrt = GCNEW(localref_table);
223 lrt->capacity = LOCALREFTABLE_CAPACITY;
225 lrt->localframes = 1;
226 lrt->prev = LOCALREFTABLE;
228 /* clear the references array (memset is faster then a for-loop) */
230 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
238 /* _Jv_jni_vmargs_from_objectarray *********************************************
242 *******************************************************************************/
244 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
247 java_objectarray *params)
249 java_objectheader *param;
251 typedesc *paramtypes;
257 paramcount = descr->paramcount;
258 paramtypes = descr->paramtypes;
260 /* if method is non-static fill first block and skip `this' pointer */
266 vmargs[0].type = TYPE_ADR;
267 vmargs[0].data.l = (u8) (ptrint) o;
274 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
275 switch (paramtypes->type) {
276 /* primitive types */
281 param = params->data[j];
286 /* internally used data type */
287 vmargs[i].type = paramtypes->type;
289 /* convert the value according to its declared type */
291 c = param->vftbl->class;
293 switch (paramtypes->decltype) {
294 case PRIMITIVETYPE_BOOLEAN:
295 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
296 value = (s8) ((java_lang_Boolean *) param)->value;
300 vmargs[i].data.l = value;
303 case PRIMITIVETYPE_BYTE:
304 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
305 value = (s8) ((java_lang_Byte *) param)->value;
309 vmargs[i].data.l = value;
312 case PRIMITIVETYPE_CHAR:
313 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
314 value = (s8) ((java_lang_Character *) param)->value;
318 vmargs[i].data.l = value;
321 case PRIMITIVETYPE_SHORT:
322 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
323 value = (s8) ((java_lang_Short *) param)->value;
324 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
325 value = (s8) ((java_lang_Byte *) param)->value;
329 vmargs[i].data.l = value;
332 case PRIMITIVETYPE_INT:
333 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
334 value = (s8) ((java_lang_Integer *) param)->value;
335 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
336 value = (s8) ((java_lang_Short *) param)->value;
337 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
338 value = (s8) ((java_lang_Byte *) param)->value;
342 vmargs[i].data.l = value;
345 case PRIMITIVETYPE_LONG:
346 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
347 value = (s8) ((java_lang_Long *) param)->value;
348 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
349 value = (s8) ((java_lang_Integer *) param)->value;
350 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
351 value = (s8) ((java_lang_Short *) param)->value;
352 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
353 value = (s8) ((java_lang_Byte *) param)->value;
357 vmargs[i].data.l = value;
360 case PRIMITIVETYPE_FLOAT:
361 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
362 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
367 case PRIMITIVETYPE_DOUBLE:
368 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
369 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
370 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
371 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
382 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
385 if (params->data[j] != 0) {
386 if (paramtypes->arraydim > 0) {
387 if (!builtin_arrayinstanceof(params->data[j], c))
391 if (!builtin_instanceof(params->data[j], c))
396 vmargs[i].type = TYPE_ADR;
397 vmargs[i].data.l = (u8) (ptrint) params->data[j];
406 /* *rettype = descr->returntype.decltype; */
411 exceptions_throw_illegalargumentexception();
416 /* _Jv_jni_CallObjectMethod ****************************************************
418 Internal function to call Java Object methods.
420 *******************************************************************************/
422 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
424 methodinfo *m, va_list ap)
427 java_objectheader *ro;
429 STATISTICS(jniinvokation());
432 exceptions_throw_nullpointerexception();
436 /* Class initialization is done by the JIT compiler. This is ok
437 since a static method always belongs to the declaring class. */
439 if (m->flags & ACC_STATIC) {
440 /* For static methods we reset the object. */
445 /* for convenience */
450 /* For instance methods we make a virtual function table lookup. */
452 resm = method_vftbl_lookup(vftbl, m);
455 STATISTICS(jnicallXmethodnvokation());
457 ro = vm_call_method_valist(resm, o, ap);
463 /* _Jv_jni_CallObjectMethodA ***************************************************
465 Internal function to call Java Object methods.
467 *******************************************************************************/
469 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
471 methodinfo *m, jvalue *args)
474 java_objectheader *ro;
476 STATISTICS(jniinvokation());
479 exceptions_throw_nullpointerexception();
483 /* Class initialization is done by the JIT compiler. This is ok
484 since a static method always belongs to the declaring class. */
486 if (m->flags & ACC_STATIC) {
487 /* For static methods we reset the object. */
492 /* for convenience */
497 /* For instance methods we make a virtual function table lookup. */
499 resm = method_vftbl_lookup(vftbl, m);
502 STATISTICS(jnicallXmethodnvokation());
504 ro = vm_call_method_jvalue(resm, o, args);
510 /* _Jv_jni_CallIntMethod *******************************************************
512 Internal function to call Java integer class methods (boolean,
513 byte, char, short, int).
515 *******************************************************************************/
517 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
518 methodinfo *m, va_list ap)
523 STATISTICS(jniinvokation());
526 exceptions_throw_nullpointerexception();
530 /* Class initialization is done by the JIT compiler. This is ok
531 since a static method always belongs to the declaring class. */
533 if (m->flags & ACC_STATIC) {
534 /* For static methods we reset the object. */
539 /* for convenience */
544 /* For instance methods we make a virtual function table lookup. */
546 resm = method_vftbl_lookup(vftbl, m);
549 STATISTICS(jnicallXmethodnvokation());
551 i = vm_call_method_int_valist(resm, o, ap);
557 /* _Jv_jni_CallIntMethodA ******************************************************
559 Internal function to call Java integer class methods (boolean,
560 byte, char, short, int).
562 *******************************************************************************/
564 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
565 methodinfo *m, jvalue *args)
570 STATISTICS(jniinvokation());
573 exceptions_throw_nullpointerexception();
577 /* Class initialization is done by the JIT compiler. This is ok
578 since a static method always belongs to the declaring class. */
580 if (m->flags & ACC_STATIC) {
581 /* For static methods we reset the object. */
586 /* for convenience */
591 /* For instance methods we make a virtual function table lookup. */
593 resm = method_vftbl_lookup(vftbl, m);
596 STATISTICS(jnicallXmethodnvokation());
598 i = vm_call_method_int_jvalue(resm, o, args);
604 /* _Jv_jni_CallLongMethod ******************************************************
606 Internal function to call Java long methods.
608 *******************************************************************************/
610 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
611 methodinfo *m, va_list ap)
616 STATISTICS(jniinvokation());
619 exceptions_throw_nullpointerexception();
623 /* Class initialization is done by the JIT compiler. This is ok
624 since a static method always belongs to the declaring class. */
626 if (m->flags & ACC_STATIC) {
627 /* For static methods we reset the object. */
632 /* for convenience */
637 /* For instance methods we make a virtual function table lookup. */
639 resm = method_vftbl_lookup(vftbl, m);
642 STATISTICS(jnicallXmethodnvokation());
644 l = vm_call_method_long_valist(resm, o, ap);
650 /* _Jv_jni_CallFloatMethod *****************************************************
652 Internal function to call Java float methods.
654 *******************************************************************************/
656 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
657 methodinfo *m, va_list ap)
662 /* Class initialization is done by the JIT compiler. This is ok
663 since a static method always belongs to the declaring class. */
665 if (m->flags & ACC_STATIC) {
666 /* For static methods we reset the object. */
671 /* for convenience */
676 /* For instance methods we make a virtual function table lookup. */
678 resm = method_vftbl_lookup(vftbl, m);
681 STATISTICS(jnicallXmethodnvokation());
683 f = vm_call_method_float_valist(resm, o, ap);
689 /* _Jv_jni_CallDoubleMethod ****************************************************
691 Internal function to call Java double methods.
693 *******************************************************************************/
695 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
696 methodinfo *m, va_list ap)
701 /* Class initialization is done by the JIT compiler. This is ok
702 since a static method always belongs to the declaring class. */
704 if (m->flags & ACC_STATIC) {
705 /* For static methods we reset the object. */
710 /* for convenience */
715 /* For instance methods we make a virtual function table lookup. */
717 resm = method_vftbl_lookup(vftbl, m);
720 d = vm_call_method_double_valist(resm, o, ap);
726 /* _Jv_jni_CallVoidMethod ******************************************************
728 Internal function to call Java void methods.
730 *******************************************************************************/
732 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
733 methodinfo *m, va_list ap)
738 exceptions_throw_nullpointerexception();
742 /* Class initialization is done by the JIT compiler. This is ok
743 since a static method always belongs to the declaring class. */
745 if (m->flags & ACC_STATIC) {
746 /* For static methods we reset the object. */
751 /* for convenience */
756 /* For instance methods we make a virtual function table lookup. */
758 resm = method_vftbl_lookup(vftbl, m);
761 STATISTICS(jnicallXmethodnvokation());
763 (void) vm_call_method_valist(resm, o, ap);
767 /* _Jv_jni_CallVoidMethodA *****************************************************
769 Internal function to call Java void methods.
771 *******************************************************************************/
773 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
774 methodinfo *m, jvalue *args)
779 exceptions_throw_nullpointerexception();
783 /* Class initialization is done by the JIT compiler. This is ok
784 since a static method always belongs to the declaring class. */
786 if (m->flags & ACC_STATIC) {
787 /* For static methods we reset the object. */
792 /* for convenience */
797 /* For instance methods we make a virtual function table lookup. */
799 resm = method_vftbl_lookup(vftbl, m);
802 STATISTICS(jnicallXmethodnvokation());
804 (void) vm_call_method_jvalue(resm, o, args);
808 /* _Jv_jni_invokeNative ********************************************************
810 Invoke a method on the given object with the given arguments.
812 For instance methods OBJ must be != NULL and the method is looked up
813 in the vftbl of the object.
815 For static methods, OBJ is ignored.
817 *******************************************************************************/
819 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
820 java_objectarray *params)
824 java_objectheader *ro;
829 exceptions_throw_nullpointerexception();
833 argcount = m->parseddesc->paramcount;
834 paramcount = argcount;
836 /* if method is non-static, remove the `this' pointer */
838 if (!(m->flags & ACC_STATIC))
841 /* For instance methods the object has to be an instance of the
842 class the method belongs to. For static methods the obj
843 parameter is ignored. */
845 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
847 new_exception_message(string_java_lang_IllegalArgumentException,
848 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
852 /* check if we got the right number of arguments */
854 if (((params == NULL) && (paramcount != 0)) ||
855 (params && (params->header.size != paramcount)))
858 new_exception(string_java_lang_IllegalArgumentException);
862 /* for instance methods we need an object */
864 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
866 new_exception_message(string_java_lang_NullPointerException,
867 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
871 /* for static methods, zero object to make subsequent code simpler */
872 if (m->flags & ACC_STATIC)
876 /* for instance methods we must do a vftbl lookup */
877 resm = method_vftbl_lookup(o->vftbl, m);
880 /* for static methods, just for convenience */
884 vmargs = MNEW(vm_arg, argcount);
886 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
889 switch (resm->parseddesc->returntype.decltype) {
891 (void) vm_call_method_vmarg(resm, argcount, vmargs);
896 case PRIMITIVETYPE_BOOLEAN: {
898 java_lang_Boolean *bo;
900 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
902 ro = builtin_new(class_java_lang_Boolean);
904 /* setting the value of the object direct */
906 bo = (java_lang_Boolean *) ro;
911 case PRIMITIVETYPE_BYTE: {
915 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
917 ro = builtin_new(class_java_lang_Byte);
919 /* setting the value of the object direct */
921 bo = (java_lang_Byte *) ro;
926 case PRIMITIVETYPE_CHAR: {
928 java_lang_Character *co;
930 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
932 ro = builtin_new(class_java_lang_Character);
934 /* setting the value of the object direct */
936 co = (java_lang_Character *) ro;
941 case PRIMITIVETYPE_SHORT: {
945 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
947 ro = builtin_new(class_java_lang_Short);
949 /* setting the value of the object direct */
951 so = (java_lang_Short *) ro;
956 case PRIMITIVETYPE_INT: {
958 java_lang_Integer *io;
960 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
962 ro = builtin_new(class_java_lang_Integer);
964 /* setting the value of the object direct */
966 io = (java_lang_Integer *) ro;
971 case PRIMITIVETYPE_LONG: {
975 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
977 ro = builtin_new(class_java_lang_Long);
979 /* setting the value of the object direct */
981 lo = (java_lang_Long *) ro;
986 case PRIMITIVETYPE_FLOAT: {
990 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
992 ro = builtin_new(class_java_lang_Float);
994 /* setting the value of the object direct */
996 fo = (java_lang_Float *) ro;
1001 case PRIMITIVETYPE_DOUBLE: {
1003 java_lang_Double *_do;
1005 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1007 ro = builtin_new(class_java_lang_Double);
1009 /* setting the value of the object direct */
1011 _do = (java_lang_Double *) ro;
1017 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1021 /* if this happens the exception has already been set by
1022 fill_callblock_from_objectarray */
1024 MFREE(vmargs, vm_arg, argcount);
1029 MFREE(vmargs, vm_arg, argcount);
1031 if (*exceptionptr) {
1032 java_objectheader *cause;
1034 cause = *exceptionptr;
1036 /* clear exception pointer, we are calling JIT code again */
1038 *exceptionptr = NULL;
1041 new_exception_throwable(string_java_lang_reflect_InvocationTargetException,
1042 (java_lang_Throwable *) cause);
1049 /* GetVersion ******************************************************************
1051 Returns the major version number in the higher 16 bits and the
1052 minor version number in the lower 16 bits.
1054 *******************************************************************************/
1056 jint _Jv_JNI_GetVersion(JNIEnv *env)
1058 STATISTICS(jniinvokation());
1060 /* we support JNI 1.4 */
1062 return JNI_VERSION_1_4;
1066 /* Class Operations ***********************************************************/
1068 /* DefineClass *****************************************************************
1070 Loads a class from a buffer of raw class data. The buffer
1071 containing the raw class data is not referenced by the VM after the
1072 DefineClass call returns, and it may be discarded if desired.
1074 *******************************************************************************/
1076 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1077 const jbyte *buf, jsize bufLen)
1079 java_lang_ClassLoader *cl;
1080 java_lang_String *s;
1084 STATISTICS(jniinvokation());
1086 cl = (java_lang_ClassLoader *) loader;
1087 s = javastring_new_from_utf_string(name);
1088 ba = (java_bytearray *) buf;
1090 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1093 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1097 /* FindClass *******************************************************************
1099 This function loads a locally-defined class. It searches the
1100 directories and zip files specified by the CLASSPATH environment
1101 variable for the class with the specified name.
1103 *******************************************************************************/
1105 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1111 STATISTICS(jniinvokation());
1113 u = utf_new_char_classname((char *) name);
1115 /* Check stacktrace for classloader, if one found use it,
1116 otherwise use the system classloader. */
1118 /* Quote from the JNI documentation:
1120 In the Java 2 Platform, FindClass locates the class loader
1121 associated with the current native method. If the native code
1122 belongs to a system class, no class loader will be
1123 involved. Otherwise, the proper class loader will be invoked to
1124 load and link the named class. When FindClass is called through
1125 the Invocation Interface, there is no current native method or
1126 its associated class loader. In that case, the result of
1127 ClassLoader.getBaseClassLoader is used." */
1129 cc = stacktrace_getCurrentClass();
1132 c = load_class_from_sysloader(u);
1134 c = load_class_from_classloader(u, cc->classloader);
1142 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1146 /* GetSuperclass ***************************************************************
1148 If clazz represents any class other than the class Object, then
1149 this function returns the object that represents the superclass of
1150 the class specified by clazz.
1152 *******************************************************************************/
1154 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1158 STATISTICS(jniinvokation());
1160 c = ((classinfo *) sub)->super.cls;
1165 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1169 /* IsAssignableFrom ************************************************************
1171 Determines whether an object of sub can be safely cast to sup.
1173 *******************************************************************************/
1175 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1177 STATISTICS(jniinvokation());
1179 return Java_java_lang_VMClass_isAssignableFrom(env,
1181 (java_lang_Class *) sup,
1182 (java_lang_Class *) sub);
1186 /* Throw ***********************************************************************
1188 Causes a java.lang.Throwable object to be thrown.
1190 *******************************************************************************/
1192 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1194 STATISTICS(jniinvokation());
1196 *exceptionptr = (java_objectheader *) obj;
1202 /* ThrowNew ********************************************************************
1204 Constructs an exception object from the specified class with the
1205 message specified by message and causes that exception to be
1208 *******************************************************************************/
1210 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1213 java_lang_Throwable *o;
1214 java_lang_String *s;
1216 STATISTICS(jniinvokation());
1218 c = (classinfo *) clazz;
1219 s = (java_lang_String *) javastring_new_from_utf_string(msg);
1221 /* instantiate exception object */
1223 o = (java_lang_Throwable *) native_new_and_init_string(c, s);
1228 *exceptionptr = (java_objectheader *) o;
1234 /* ExceptionOccurred ***********************************************************
1236 Determines if an exception is being thrown. The exception stays
1237 being thrown until either the native code calls ExceptionClear(),
1238 or the Java code handles the exception.
1240 *******************************************************************************/
1242 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1244 java_objectheader *e;
1246 STATISTICS(jniinvokation());
1250 return _Jv_JNI_NewLocalRef(env, (jthrowable) e);
1254 /* ExceptionDescribe ***********************************************************
1256 Prints an exception and a backtrace of the stack to a system
1257 error-reporting channel, such as stderr. This is a convenience
1258 routine provided for debugging.
1260 *******************************************************************************/
1262 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1264 java_objectheader *e;
1267 STATISTICS(jniinvokation());
1272 /* clear exception, because we are calling jit code again */
1274 *exceptionptr = NULL;
1276 /* get printStackTrace method from exception class */
1278 m = class_resolveclassmethod(e->vftbl->class,
1279 utf_printStackTrace,
1285 /* XXX what should we do? */
1288 /* print the stacktrace */
1290 (void) vm_call_method(m, e);
1295 /* ExceptionClear **************************************************************
1297 Clears any exception that is currently being thrown. If no
1298 exception is currently being thrown, this routine has no effect.
1300 *******************************************************************************/
1302 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1304 STATISTICS(jniinvokation());
1306 *exceptionptr = NULL;
1310 /* FatalError ******************************************************************
1312 Raises a fatal error and does not expect the VM to recover. This
1313 function does not return.
1315 *******************************************************************************/
1317 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1319 STATISTICS(jniinvokation());
1321 throw_cacao_exception_exit(string_java_lang_InternalError, msg);
1325 /* PushLocalFrame **************************************************************
1327 Creates a new local reference frame, in which at least a given
1328 number of local references can be created.
1330 *******************************************************************************/
1332 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1335 localref_table *lrt;
1336 localref_table *nlrt;
1338 STATISTICS(jniinvokation());
1343 /* Allocate new local reference table on Java heap. Calculate the
1344 additional memory we have to allocate. */
1346 if (capacity > LOCALREFTABLE_CAPACITY)
1347 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1351 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1356 /* get current local reference table from thread */
1358 lrt = LOCALREFTABLE;
1360 /* Set up the new local reference table and add it to the local
1363 nlrt->capacity = capacity;
1365 nlrt->localframes = lrt->localframes + 1;
1368 /* store new local reference table in thread */
1370 LOCALREFTABLE = nlrt;
1376 /* PopLocalFrame ***************************************************************
1378 Pops off the current local reference frame, frees all the local
1379 references, and returns a local reference in the previous local
1380 reference frame for the given result object.
1382 *******************************************************************************/
1384 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1386 localref_table *lrt;
1387 localref_table *plrt;
1390 STATISTICS(jniinvokation());
1392 /* get current local reference table from thread */
1394 lrt = LOCALREFTABLE;
1396 localframes = lrt->localframes;
1398 /* Don't delete the top local frame, as this one is allocated in
1399 the native stub on the stack and is freed automagically on
1402 if (localframes == 1)
1403 return _Jv_JNI_NewLocalRef(env, result);
1405 /* release all current local frames */
1407 for (; localframes >= 1; localframes--) {
1408 /* get previous frame */
1412 /* clear all reference entries */
1414 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1418 /* set new local references table */
1423 /* store new local reference table in thread */
1425 LOCALREFTABLE = lrt;
1427 /* add local reference and return the value */
1429 return _Jv_JNI_NewLocalRef(env, result);
1433 /* DeleteLocalRef **************************************************************
1435 Deletes the local reference pointed to by localRef.
1437 *******************************************************************************/
1439 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1441 java_objectheader *o;
1442 localref_table *lrt;
1445 STATISTICS(jniinvokation());
1447 o = (java_objectheader *) localRef;
1449 /* get local reference table (thread specific) */
1451 lrt = LOCALREFTABLE;
1453 /* go through all local frames */
1455 for (; lrt != NULL; lrt = lrt->prev) {
1457 /* and try to remove the reference */
1459 for (i = 0; i < lrt->capacity; i++) {
1460 if (lrt->refs[i] == o) {
1461 lrt->refs[i] = NULL;
1469 /* this should not happen */
1471 /* if (opt_checkjni) */
1472 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1473 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1477 /* IsSameObject ****************************************************************
1479 Tests whether two references refer to the same Java object.
1481 *******************************************************************************/
1483 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1485 STATISTICS(jniinvokation());
1494 /* NewLocalRef *****************************************************************
1496 Creates a new local reference that refers to the same object as ref.
1498 *******************************************************************************/
1500 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1502 localref_table *lrt;
1505 STATISTICS(jniinvokation());
1510 /* get local reference table (thread specific) */
1512 lrt = LOCALREFTABLE;
1514 /* Check if we have space for the requested reference? No,
1515 allocate a new frame. This is actually not what the spec says,
1516 but for compatibility reasons... */
1518 if (lrt->used == lrt->capacity) {
1519 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1522 /* get the new local reference table */
1524 lrt = LOCALREFTABLE;
1527 /* insert the reference */
1529 for (i = 0; i < lrt->capacity; i++) {
1530 if (lrt->refs[i] == NULL) {
1531 lrt->refs[i] = (java_objectheader *) ref;
1538 /* should not happen, just to be sure */
1542 /* keep compiler happy */
1548 /* EnsureLocalCapacity *********************************************************
1550 Ensures that at least a given number of local references can be
1551 created in the current thread
1553 *******************************************************************************/
1555 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1557 localref_table *lrt;
1559 log_text("JNI-Call: EnsureLocalCapacity");
1561 STATISTICS(jniinvokation());
1563 /* get local reference table (thread specific) */
1565 lrt = LOCALREFTABLE;
1567 /* check if capacity elements are available in the local references table */
1569 if ((lrt->used + capacity) > lrt->capacity)
1570 return _Jv_JNI_PushLocalFrame(env, capacity);
1576 /* AllocObject *****************************************************************
1578 Allocates a new Java object without invoking any of the
1579 constructors for the object. Returns a reference to the object.
1581 *******************************************************************************/
1583 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1586 java_objectheader *o;
1588 STATISTICS(jniinvokation());
1590 c = (classinfo *) clazz;
1592 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1594 new_exception_utfmessage(string_java_lang_InstantiationException,
1601 return _Jv_JNI_NewLocalRef(env, o);
1605 /* NewObject *******************************************************************
1607 Programmers place all arguments that are to be passed to the
1608 constructor immediately following the methodID
1609 argument. NewObject() accepts these arguments and passes them to
1610 the Java method that the programmer wishes to invoke.
1612 *******************************************************************************/
1614 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1616 java_objectheader *o;
1620 STATISTICS(jniinvokation());
1622 m = (methodinfo *) methodID;
1626 o = builtin_new(clazz);
1631 /* call constructor */
1633 va_start(ap, methodID);
1634 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1637 return _Jv_JNI_NewLocalRef(env, o);
1641 /* NewObjectV ******************************************************************
1643 Programmers place all arguments that are to be passed to the
1644 constructor in an args argument of type va_list that immediately
1645 follows the methodID argument. NewObjectV() accepts these
1646 arguments, and, in turn, passes them to the Java method that the
1647 programmer wishes to invoke.
1649 *******************************************************************************/
1651 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1654 java_objectheader *o;
1657 STATISTICS(jniinvokation());
1659 m = (methodinfo *) methodID;
1663 o = builtin_new(clazz);
1668 /* call constructor */
1670 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1672 return _Jv_JNI_NewLocalRef(env, o);
1676 /* NewObjectA *****************************************************************
1678 Programmers place all arguments that are to be passed to the
1679 constructor in an args array of jvalues that immediately follows
1680 the methodID argument. NewObjectA() accepts the arguments in this
1681 array, and, in turn, passes them to the Java method that the
1682 programmer wishes to invoke.
1684 *******************************************************************************/
1686 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1689 java_objectheader *o;
1692 STATISTICS(jniinvokation());
1694 m = (methodinfo *) methodID;
1698 o = builtin_new(clazz);
1703 /* call constructor */
1705 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1707 return _Jv_JNI_NewLocalRef(env, o);
1711 /* GetObjectClass **************************************************************
1713 Returns the class of an object.
1715 *******************************************************************************/
1717 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1719 java_objectheader *o;
1722 STATISTICS(jniinvokation());
1724 o = (java_objectheader *) obj;
1726 if ((o == NULL) || (o->vftbl == NULL))
1729 c = o->vftbl->class;
1731 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1735 /* IsInstanceOf ****************************************************************
1737 Tests whether an object is an instance of a class.
1739 *******************************************************************************/
1741 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1743 STATISTICS(jniinvokation());
1745 return Java_java_lang_VMClass_isInstance(env,
1747 (java_lang_Class *) clazz,
1748 (java_lang_Object *) obj);
1752 /* Reflection Support *********************************************************/
1754 /* FromReflectedMethod *********************************************************
1756 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1757 object to a method ID.
1759 *******************************************************************************/
1761 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1767 STATISTICS(jniinvokation());
1772 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1773 java_lang_reflect_Method *rm;
1775 rm = (java_lang_reflect_Method *) method;
1776 c = (classinfo *) (rm->declaringClass);
1779 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1780 java_lang_reflect_Constructor *rc;
1782 rc = (java_lang_reflect_Constructor *) method;
1783 c = (classinfo *) (rc->clazz);
1789 mi = &(c->methods[slot]);
1791 return (jmethodID) mi;
1795 /* FromReflectedField **********************************************************
1797 Converts a java.lang.reflect.Field to a field ID.
1799 *******************************************************************************/
1801 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1803 java_lang_reflect_Field *rf;
1807 STATISTICS(jniinvokation());
1809 rf = (java_lang_reflect_Field *) field;
1814 c = (classinfo *) rf->declaringClass;
1816 f = &(c->fields[rf->slot]);
1818 return (jfieldID) f;
1822 /* ToReflectedMethod ***********************************************************
1824 Converts a method ID derived from cls to an instance of the
1825 java.lang.reflect.Method class or to an instance of the
1826 java.lang.reflect.Constructor class.
1828 *******************************************************************************/
1830 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1833 STATISTICS(jniinvokation());
1835 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1841 /* ToReflectedField ************************************************************
1843 Converts a field ID derived from cls to an instance of the
1844 java.lang.reflect.Field class.
1846 *******************************************************************************/
1848 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1851 STATISTICS(jniinvokation());
1853 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1859 /* Calling Instance Methods ***************************************************/
1861 /* GetMethodID *****************************************************************
1863 Returns the method ID for an instance (nonstatic) method of a class
1864 or interface. The method may be defined in one of the clazz's
1865 superclasses and inherited by clazz. The method is determined by
1866 its name and signature.
1868 GetMethodID() causes an uninitialized class to be initialized.
1870 *******************************************************************************/
1872 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1880 STATISTICS(jniinvokation());
1882 c = (classinfo *) clazz;
1887 if (!(c->state & CLASS_INITIALIZED))
1888 if (!initialize_class(c))
1891 /* try to get the method of the class or one of it's superclasses */
1893 uname = utf_new_char((char *) name);
1894 udesc = utf_new_char((char *) sig);
1896 m = class_resolvemethod(clazz, uname, udesc);
1898 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1899 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1904 return (jmethodID) m;
1908 /* JNI-functions for calling instance methods *********************************/
1910 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1913 java_objectheader *o;
1915 java_objectheader *ret;
1918 o = (java_objectheader *) obj;
1919 m = (methodinfo *) methodID;
1921 va_start(ap, methodID);
1922 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1925 return _Jv_JNI_NewLocalRef(env, ret);
1929 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1932 java_objectheader *o;
1934 java_objectheader *ret;
1936 o = (java_objectheader *) obj;
1937 m = (methodinfo *) methodID;
1939 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1941 return _Jv_JNI_NewLocalRef(env, ret);
1945 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1948 java_objectheader *o;
1950 java_objectheader *ret;
1952 o = (java_objectheader *) obj;
1953 m = (methodinfo *) methodID;
1955 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1957 return _Jv_JNI_NewLocalRef(env, ret);
1961 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1964 java_objectheader *o;
1969 o = (java_objectheader *) obj;
1970 m = (methodinfo *) methodID;
1972 va_start(ap, methodID);
1973 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1980 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
1981 jmethodID methodID, va_list args)
1983 java_objectheader *o;
1987 o = (java_objectheader *) obj;
1988 m = (methodinfo *) methodID;
1990 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1996 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
1997 jmethodID methodID, jvalue *args)
1999 java_objectheader *o;
2003 o = (java_objectheader *) obj;
2004 m = (methodinfo *) methodID;
2006 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2012 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2014 java_objectheader *o;
2019 o = (java_objectheader *) obj;
2020 m = (methodinfo *) methodID;
2022 va_start(ap, methodID);
2023 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2031 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2034 java_objectheader *o;
2038 o = (java_objectheader *) obj;
2039 m = (methodinfo *) methodID;
2041 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2047 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2050 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2056 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2058 java_objectheader *o;
2063 o = (java_objectheader *) obj;
2064 m = (methodinfo *) methodID;
2066 va_start(ap, methodID);
2067 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2074 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2077 java_objectheader *o;
2081 o = (java_objectheader *) obj;
2082 m = (methodinfo *) methodID;
2084 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2090 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2093 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2099 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2102 java_objectheader *o;
2107 o = (java_objectheader *) obj;
2108 m = (methodinfo *) methodID;
2110 va_start(ap, methodID);
2111 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2118 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2121 java_objectheader *o;
2125 o = (java_objectheader *) obj;
2126 m = (methodinfo *) methodID;
2128 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2134 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2137 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2144 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2146 java_objectheader *o;
2151 o = (java_objectheader *) obj;
2152 m = (methodinfo *) methodID;
2154 va_start(ap, methodID);
2155 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2162 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2165 java_objectheader *o;
2169 o = (java_objectheader *) obj;
2170 m = (methodinfo *) methodID;
2172 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2178 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2181 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2188 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2190 java_objectheader *o;
2195 o = (java_objectheader *) obj;
2196 m = (methodinfo *) methodID;
2198 va_start(ap, methodID);
2199 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2206 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2209 java_objectheader *o;
2213 o = (java_objectheader *) obj;
2214 m = (methodinfo *) methodID;
2216 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2222 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2225 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2232 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2235 java_objectheader *o;
2240 o = (java_objectheader *) obj;
2241 m = (methodinfo *) methodID;
2243 va_start(ap, methodID);
2244 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2251 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2254 java_objectheader *o;
2258 o = (java_objectheader *) obj;
2259 m = (methodinfo *) methodID;
2261 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2267 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2270 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2277 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2280 java_objectheader *o;
2285 o = (java_objectheader *) obj;
2286 m = (methodinfo *) methodID;
2288 va_start(ap, methodID);
2289 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2296 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2299 java_objectheader *o;
2303 o = (java_objectheader *) obj;
2304 m = (methodinfo *) methodID;
2306 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2312 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2315 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2322 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2324 java_objectheader *o;
2328 o = (java_objectheader *) obj;
2329 m = (methodinfo *) methodID;
2331 va_start(ap, methodID);
2332 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2337 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2340 java_objectheader *o;
2343 o = (java_objectheader *) obj;
2344 m = (methodinfo *) methodID;
2346 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2350 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2353 java_objectheader *o;
2356 o = (java_objectheader *) obj;
2357 m = (methodinfo *) methodID;
2359 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2364 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2365 jclass clazz, jmethodID methodID,
2368 java_objectheader *o;
2371 java_objectheader *r;
2374 o = (java_objectheader *) obj;
2375 c = (classinfo *) clazz;
2376 m = (methodinfo *) methodID;
2378 va_start(ap, methodID);
2379 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2382 return _Jv_JNI_NewLocalRef(env, r);
2386 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2387 jclass clazz, jmethodID methodID,
2390 java_objectheader *o;
2393 java_objectheader *r;
2395 o = (java_objectheader *) obj;
2396 c = (classinfo *) clazz;
2397 m = (methodinfo *) methodID;
2399 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2401 return _Jv_JNI_NewLocalRef(env, r);
2405 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2406 jclass clazz, jmethodID methodID,
2409 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2411 return _Jv_JNI_NewLocalRef(env, NULL);
2416 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2417 jclass clazz, jmethodID methodID,
2420 java_objectheader *o;
2426 o = (java_objectheader *) obj;
2427 c = (classinfo *) clazz;
2428 m = (methodinfo *) methodID;
2430 va_start(ap, methodID);
2431 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2438 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2439 jclass clazz, jmethodID methodID,
2442 java_objectheader *o;
2447 o = (java_objectheader *) obj;
2448 c = (classinfo *) clazz;
2449 m = (methodinfo *) methodID;
2451 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2457 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2458 jclass clazz, jmethodID methodID,
2461 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2467 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2468 jmethodID methodID, ...)
2470 java_objectheader *o;
2476 o = (java_objectheader *) obj;
2477 c = (classinfo *) clazz;
2478 m = (methodinfo *) methodID;
2480 va_start(ap, methodID);
2481 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2488 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2489 jmethodID methodID, va_list args)
2491 java_objectheader *o;
2496 o = (java_objectheader *) obj;
2497 c = (classinfo *) clazz;
2498 m = (methodinfo *) methodID;
2500 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2506 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2507 jmethodID methodID, jvalue *args)
2509 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2516 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2517 jmethodID methodID, ...)
2519 java_objectheader *o;
2525 o = (java_objectheader *) obj;
2526 c = (classinfo *) clazz;
2527 m = (methodinfo *) methodID;
2529 va_start(ap, methodID);
2530 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2537 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2538 jmethodID methodID, va_list args)
2540 java_objectheader *o;
2545 o = (java_objectheader *) obj;
2546 c = (classinfo *) clazz;
2547 m = (methodinfo *) methodID;
2549 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2555 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2556 jmethodID methodID, jvalue *args)
2558 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2565 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2566 jclass clazz, jmethodID methodID, ...)
2568 java_objectheader *o;
2574 o = (java_objectheader *) obj;
2575 c = (classinfo *) clazz;
2576 m = (methodinfo *) methodID;
2578 va_start(ap, methodID);
2579 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2586 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2587 jclass clazz, jmethodID methodID,
2590 java_objectheader *o;
2595 o = (java_objectheader *) obj;
2596 c = (classinfo *) clazz;
2597 m = (methodinfo *) methodID;
2599 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2605 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2606 jclass clazz, jmethodID methodID,
2609 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2616 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2617 jmethodID methodID, ...)
2619 java_objectheader *o;
2625 o = (java_objectheader *) obj;
2626 c = (classinfo *) clazz;
2627 m = (methodinfo *) methodID;
2629 va_start(ap, methodID);
2630 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2637 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2638 jmethodID methodID, va_list args)
2640 java_objectheader *o;
2645 o = (java_objectheader *) obj;
2646 c = (classinfo *) clazz;
2647 m = (methodinfo *) methodID;
2649 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2655 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2656 jmethodID methodID, jvalue *args)
2658 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2665 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2666 jmethodID methodID, ...)
2668 java_objectheader *o;
2674 o = (java_objectheader *) obj;
2675 c = (classinfo *) clazz;
2676 m = (methodinfo *) methodID;
2678 va_start(ap, methodID);
2679 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2686 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2687 jmethodID methodID, va_list args)
2689 java_objectheader *o;
2694 o = (java_objectheader *) obj;
2695 c = (classinfo *) clazz;
2696 m = (methodinfo *) methodID;
2698 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2704 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2705 jmethodID methodID, jvalue *args)
2707 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2714 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2715 jclass clazz, jmethodID methodID, ...)
2717 java_objectheader *o;
2723 o = (java_objectheader *) obj;
2724 c = (classinfo *) clazz;
2725 m = (methodinfo *) methodID;
2727 va_start(ap, methodID);
2728 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2735 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2736 jclass clazz, jmethodID methodID,
2739 java_objectheader *o;
2744 o = (java_objectheader *) obj;
2745 c = (classinfo *) clazz;
2746 m = (methodinfo *) methodID;
2748 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2754 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2755 jclass clazz, jmethodID methodID,
2758 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2765 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2766 jclass clazz, jmethodID methodID,
2769 java_objectheader *o;
2775 o = (java_objectheader *) obj;
2776 c = (classinfo *) clazz;
2777 m = (methodinfo *) methodID;
2779 va_start(ap, methodID);
2780 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2787 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2788 jclass clazz, jmethodID methodID,
2791 java_objectheader *o;
2796 o = (java_objectheader *) obj;
2797 c = (classinfo *) clazz;
2798 m = (methodinfo *) methodID;
2800 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2806 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2807 jclass clazz, jmethodID methodID,
2810 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2817 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2818 jmethodID methodID, ...)
2820 java_objectheader *o;
2825 o = (java_objectheader *) obj;
2826 c = (classinfo *) clazz;
2827 m = (methodinfo *) methodID;
2829 va_start(ap, methodID);
2830 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2835 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2836 jmethodID methodID, va_list args)
2838 java_objectheader *o;
2842 o = (java_objectheader *) obj;
2843 c = (classinfo *) clazz;
2844 m = (methodinfo *) methodID;
2846 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2850 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2851 jmethodID methodID, jvalue * args)
2853 java_objectheader *o;
2857 o = (java_objectheader *) obj;
2858 c = (classinfo *) clazz;
2859 m = (methodinfo *) methodID;
2861 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2865 /* Accessing Fields of Objects ************************************************/
2867 /* GetFieldID ******************************************************************
2869 Returns the field ID for an instance (nonstatic) field of a
2870 class. The field is specified by its name and signature. The
2871 Get<type>Field and Set<type>Field families of accessor functions
2872 use field IDs to retrieve object fields.
2874 *******************************************************************************/
2876 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2883 STATISTICS(jniinvokation());
2885 uname = utf_new_char((char *) name);
2886 udesc = utf_new_char((char *) sig);
2888 f = class_findfield(clazz, uname, udesc);
2891 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2893 return (jfieldID) f;
2897 /* Get<type>Field Routines *****************************************************
2899 This family of accessor routines returns the value of an instance
2900 (nonstatic) field of an object. The field to access is specified by
2901 a field ID obtained by calling GetFieldID().
2903 *******************************************************************************/
2905 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2907 java_objectheader *o;
2909 STATISTICS(jniinvokation());
2911 o = GET_FIELD(obj, java_objectheader*, fieldID);
2913 return _Jv_JNI_NewLocalRef(env, o);
2917 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2921 STATISTICS(jniinvokation());
2923 i = GET_FIELD(obj, s4, fieldID);
2925 return (jboolean) i;
2929 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2933 STATISTICS(jniinvokation());
2935 i = GET_FIELD(obj, s4, fieldID);
2941 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2945 STATISTICS(jniinvokation());
2947 i = GET_FIELD(obj, s4, fieldID);
2953 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2957 STATISTICS(jniinvokation());
2959 i = GET_FIELD(obj, s4, fieldID);
2965 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2967 java_objectheader *o;
2971 STATISTICS(jniinvokation());
2973 o = (java_objectheader *) obj;
2974 f = (fieldinfo *) fieldID;
2976 i = GET_FIELD(o, s4, f);
2982 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2986 STATISTICS(jniinvokation());
2988 l = GET_FIELD(obj, s8, fieldID);
2994 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2998 STATISTICS(jniinvokation());
3000 f = GET_FIELD(obj, float, fieldID);
3006 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3010 STATISTICS(jniinvokation());
3012 d = GET_FIELD(obj, double, fieldID);
3018 /* Set<type>Field Routines *****************************************************
3020 This family of accessor routines sets the value of an instance
3021 (nonstatic) field of an object. The field to access is specified by
3022 a field ID obtained by calling GetFieldID().
3024 *******************************************************************************/
3026 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3029 STATISTICS(jniinvokation());
3031 SET_FIELD(obj, java_objectheader*, fieldID, value);
3035 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3038 STATISTICS(jniinvokation());
3040 SET_FIELD(obj, s4, fieldID, value);
3044 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3047 STATISTICS(jniinvokation());
3049 SET_FIELD(obj, s4, fieldID, value);
3053 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3056 STATISTICS(jniinvokation());
3058 SET_FIELD(obj, s4, fieldID, value);
3062 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3065 STATISTICS(jniinvokation());
3067 SET_FIELD(obj, s4, fieldID, value);
3071 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3073 STATISTICS(jniinvokation());
3075 SET_FIELD(obj, s4, fieldID, value);
3079 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3082 STATISTICS(jniinvokation());
3084 SET_FIELD(obj, s8, fieldID, value);
3088 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3091 STATISTICS(jniinvokation());
3093 SET_FIELD(obj, float, fieldID, value);
3097 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3100 STATISTICS(jniinvokation());
3102 SET_FIELD(obj, double, fieldID, value);
3106 /* Calling Static Methods *****************************************************/
3108 /* GetStaticMethodID ***********************************************************
3110 Returns the method ID for a static method of a class. The method is
3111 specified by its name and signature.
3113 GetStaticMethodID() causes an uninitialized class to be
3116 *******************************************************************************/
3118 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3126 STATISTICS(jniinvokation());
3128 c = (classinfo *) clazz;
3133 if (!(c->state & CLASS_INITIALIZED))
3134 if (!initialize_class(c))
3137 /* try to get the static method of the class */
3139 uname = utf_new_char((char *) name);
3140 udesc = utf_new_char((char *) sig);
3142 m = class_resolvemethod(c, uname, udesc);
3144 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3145 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3150 return (jmethodID) m;
3154 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3155 jmethodID methodID, ...)
3158 java_objectheader *o;
3161 m = (methodinfo *) methodID;
3163 va_start(ap, methodID);
3164 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3167 return _Jv_JNI_NewLocalRef(env, o);
3171 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3172 jmethodID methodID, va_list args)
3175 java_objectheader *o;
3177 m = (methodinfo *) methodID;
3179 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3181 return _Jv_JNI_NewLocalRef(env, o);
3185 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3186 jmethodID methodID, jvalue *args)
3189 java_objectheader *o;
3191 m = (methodinfo *) methodID;
3193 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3195 return _Jv_JNI_NewLocalRef(env, o);
3199 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3200 jmethodID methodID, ...)
3206 m = (methodinfo *) methodID;
3208 va_start(ap, methodID);
3209 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3216 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3217 jmethodID methodID, va_list args)
3222 m = (methodinfo *) methodID;
3224 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3230 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3231 jmethodID methodID, jvalue *args)
3233 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3239 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3240 jmethodID methodID, ...)
3246 m = (methodinfo *) methodID;
3248 va_start(ap, methodID);
3249 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3256 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3257 jmethodID methodID, va_list args)
3262 m = (methodinfo *) methodID;
3264 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3270 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3271 jmethodID methodID, jvalue *args)
3273 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3279 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3280 jmethodID methodID, ...)
3286 m = (methodinfo *) methodID;
3288 va_start(ap, methodID);
3289 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3296 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3297 jmethodID methodID, va_list args)
3302 m = (methodinfo *) methodID;
3304 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3310 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3311 jmethodID methodID, jvalue *args)
3313 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3319 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3320 jmethodID methodID, ...)
3326 m = (methodinfo *) methodID;
3328 va_start(ap, methodID);
3329 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3336 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3337 jmethodID methodID, va_list args)
3342 m = (methodinfo *) methodID;
3344 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3350 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3351 jmethodID methodID, jvalue *args)
3353 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3359 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3366 m = (methodinfo *) methodID;
3368 va_start(ap, methodID);
3369 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3376 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3377 jmethodID methodID, va_list args)
3382 m = (methodinfo *) methodID;
3384 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3390 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3391 jmethodID methodID, jvalue *args)
3393 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3399 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3400 jmethodID methodID, ...)
3406 m = (methodinfo *) methodID;
3408 va_start(ap, methodID);
3409 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3416 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3417 jmethodID methodID, va_list args)
3422 m = (methodinfo *) methodID;
3424 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3430 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3431 jmethodID methodID, jvalue *args)
3433 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3440 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3441 jmethodID methodID, ...)
3447 m = (methodinfo *) methodID;
3449 va_start(ap, methodID);
3450 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3457 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3458 jmethodID methodID, va_list args)
3463 m = (methodinfo *) methodID;
3465 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3471 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3472 jmethodID methodID, jvalue *args)
3474 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3480 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3481 jmethodID methodID, ...)
3487 m = (methodinfo *) methodID;
3489 va_start(ap, methodID);
3490 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3497 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3498 jmethodID methodID, va_list args)
3503 m = (methodinfo *) methodID;
3505 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3511 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3512 jmethodID methodID, jvalue *args)
3514 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3520 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3521 jmethodID methodID, ...)
3526 m = (methodinfo *) methodID;
3528 va_start(ap, methodID);
3529 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3534 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3535 jmethodID methodID, va_list args)
3539 m = (methodinfo *) methodID;
3541 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3545 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3546 jmethodID methodID, jvalue * args)
3550 m = (methodinfo *) methodID;
3552 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3556 /* Accessing Static Fields ****************************************************/
3558 /* GetStaticFieldID ************************************************************
3560 Returns the field ID for a static field of a class. The field is
3561 specified by its name and signature. The GetStatic<type>Field and
3562 SetStatic<type>Field families of accessor functions use field IDs
3563 to retrieve static fields.
3565 *******************************************************************************/
3567 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3574 STATISTICS(jniinvokation());
3576 uname = utf_new_char((char *) name);
3577 usig = utf_new_char((char *) sig);
3579 f = class_findfield(clazz, uname, usig);
3582 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
3584 return (jfieldID) f;
3588 /* GetStatic<type>Field ********************************************************
3590 This family of accessor routines returns the value of a static
3593 *******************************************************************************/
3595 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3601 STATISTICS(jniinvokation());
3603 c = (classinfo *) clazz;
3604 f = (fieldinfo *) fieldID;
3606 if (!(c->state & CLASS_INITIALIZED))
3607 if (!initialize_class(c))
3610 return _Jv_JNI_NewLocalRef(env, f->value.a);
3614 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3620 STATISTICS(jniinvokation());
3622 c = (classinfo *) clazz;
3623 f = (fieldinfo *) fieldID;
3625 if (!(c->state & CLASS_INITIALIZED))
3626 if (!initialize_class(c))
3633 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3638 STATISTICS(jniinvokation());
3640 c = (classinfo *) clazz;
3641 f = (fieldinfo *) fieldID;
3643 if (!(c->state & CLASS_INITIALIZED))
3644 if (!initialize_class(c))
3651 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3656 STATISTICS(jniinvokation());
3658 c = (classinfo *) clazz;
3659 f = (fieldinfo *) fieldID;
3661 if (!(c->state & CLASS_INITIALIZED))
3662 if (!initialize_class(c))
3669 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3674 STATISTICS(jniinvokation());
3676 c = (classinfo *) clazz;
3677 f = (fieldinfo *) fieldID;
3679 if (!(c->state & CLASS_INITIALIZED))
3680 if (!initialize_class(c))
3687 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3692 STATISTICS(jniinvokation());
3694 c = (classinfo *) clazz;
3695 f = (fieldinfo *) fieldID;
3697 if (!(c->state & CLASS_INITIALIZED))
3698 if (!initialize_class(c))
3705 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3710 STATISTICS(jniinvokation());
3712 c = (classinfo *) clazz;
3713 f = (fieldinfo *) fieldID;
3715 if (!(c->state & CLASS_INITIALIZED))
3716 if (!initialize_class(c))
3723 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3728 STATISTICS(jniinvokation());
3730 c = (classinfo *) clazz;
3731 f = (fieldinfo *) fieldID;
3733 if (!(c->state & CLASS_INITIALIZED))
3734 if (!initialize_class(c))
3741 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3747 STATISTICS(jniinvokation());
3749 c = (classinfo *) clazz;
3750 f = (fieldinfo *) fieldID;
3752 if (!(c->state & CLASS_INITIALIZED))
3753 if (!initialize_class(c))
3760 /* SetStatic<type>Field *******************************************************
3762 This family of accessor routines sets the value of a static field
3765 *******************************************************************************/
3767 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3773 STATISTICS(jniinvokation());
3775 c = (classinfo *) clazz;
3776 f = (fieldinfo *) fieldID;
3778 if (!(c->state & CLASS_INITIALIZED))
3779 if (!initialize_class(c))
3786 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3792 STATISTICS(jniinvokation());
3794 c = (classinfo *) clazz;
3795 f = (fieldinfo *) fieldID;
3797 if (!(c->state & CLASS_INITIALIZED))
3798 if (!initialize_class(c))
3805 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3811 STATISTICS(jniinvokation());
3813 c = (classinfo *) clazz;
3814 f = (fieldinfo *) fieldID;
3816 if (!(c->state & CLASS_INITIALIZED))
3817 if (!initialize_class(c))
3824 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3830 STATISTICS(jniinvokation());
3832 c = (classinfo *) clazz;
3833 f = (fieldinfo *) fieldID;
3835 if (!(c->state & CLASS_INITIALIZED))
3836 if (!initialize_class(c))
3843 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3849 STATISTICS(jniinvokation());
3851 c = (classinfo *) clazz;
3852 f = (fieldinfo *) fieldID;
3854 if (!(c->state & CLASS_INITIALIZED))
3855 if (!initialize_class(c))
3862 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3868 STATISTICS(jniinvokation());
3870 c = (classinfo *) clazz;
3871 f = (fieldinfo *) fieldID;
3873 if (!(c->state & CLASS_INITIALIZED))
3874 if (!initialize_class(c))
3881 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3887 STATISTICS(jniinvokation());
3889 c = (classinfo *) clazz;
3890 f = (fieldinfo *) fieldID;
3892 if (!(c->state & CLASS_INITIALIZED))
3893 if (!initialize_class(c))
3900 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3906 STATISTICS(jniinvokation());
3908 c = (classinfo *) clazz;
3909 f = (fieldinfo *) fieldID;
3911 if (!(c->state & CLASS_INITIALIZED))
3912 if (!initialize_class(c))
3919 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3925 STATISTICS(jniinvokation());
3927 c = (classinfo *) clazz;
3928 f = (fieldinfo *) fieldID;
3930 if (!(c->state & CLASS_INITIALIZED))
3931 if (!initialize_class(c))
3938 /* String Operations **********************************************************/
3940 /* NewString *******************************************************************
3942 Create new java.lang.String object from an array of Unicode
3945 *******************************************************************************/
3947 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
3949 java_lang_String *s;
3953 STATISTICS(jniinvokation());
3955 s = (java_lang_String *) builtin_new(class_java_lang_String);
3956 a = builtin_newarray_char(len);
3958 /* javastring or characterarray could not be created */
3959 if ((a == NULL) || (s == NULL))
3963 for (i = 0; i < len; i++)
3964 a->data[i] = buf[i];
3970 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
3974 static jchar emptyStringJ[]={0,0};
3976 /* GetStringLength *************************************************************
3978 Returns the length (the count of Unicode characters) of a Java
3981 *******************************************************************************/
3983 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
3985 return ((java_lang_String *) str)->count;
3989 /******************** convertes javastring to u2-array ****************************/
3991 u2 *javastring_tou2(jstring so)
3993 java_lang_String *s;
3998 STATISTICS(jniinvokation());
4000 s = (java_lang_String *) so;
4010 /* allocate memory */
4012 stringbuffer = MNEW(u2, s->count + 1);
4016 for (i = 0; i < s->count; i++)
4017 stringbuffer[i] = a->data[s->offset + i];
4019 /* terminate string */
4021 stringbuffer[i] = '\0';
4023 return stringbuffer;
4027 /* GetStringChars **************************************************************
4029 Returns a pointer to the array of Unicode characters of the
4030 string. This pointer is valid until ReleaseStringchars() is called.
4032 *******************************************************************************/
4034 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4038 STATISTICS(jniinvokation());
4040 jc = javastring_tou2(str);
4052 return emptyStringJ;
4056 /* ReleaseStringChars **********************************************************
4058 Informs the VM that the native code no longer needs access to
4059 chars. The chars argument is a pointer obtained from string using
4062 *******************************************************************************/
4064 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4066 STATISTICS(jniinvokation());
4068 if (chars == emptyStringJ)
4071 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4075 /* NewStringUTF ****************************************************************
4077 Constructs a new java.lang.String object from an array of UTF-8 characters.
4079 *******************************************************************************/
4081 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4083 java_lang_String *s;
4085 STATISTICS(jniinvokation());
4087 s = javastring_safe_new_from_utf8(bytes);
4089 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4093 /****************** returns the utf8 length in bytes of a string *******************/
4095 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4097 java_lang_String *s = (java_lang_String*) string;
4099 STATISTICS(jniinvokation());
4101 return (jsize) u2_utflength(s->value->data, s->count);
4105 /* GetStringUTFChars ***********************************************************
4107 Returns a pointer to an array of UTF-8 characters of the
4108 string. This array is valid until it is released by
4109 ReleaseStringUTFChars().
4111 *******************************************************************************/
4113 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4118 STATISTICS(jniinvokation());
4126 u = javastring_toutf((java_lang_String *) string, false);
4135 /* ReleaseStringUTFChars *******************************************************
4137 Informs the VM that the native code no longer needs access to
4138 utf. The utf argument is a pointer derived from string using
4139 GetStringUTFChars().
4141 *******************************************************************************/
4143 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4145 STATISTICS(jniinvokation());
4147 /* XXX we don't release utf chars right now, perhaps that should be done
4148 later. Since there is always one reference the garbage collector will
4153 /* Array Operations ***********************************************************/
4155 /* GetArrayLength **************************************************************
4157 Returns the number of elements in the array.
4159 *******************************************************************************/
4161 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4163 java_arrayheader *a;
4165 STATISTICS(jniinvokation());
4167 a = (java_arrayheader *) array;
4173 /* NewObjectArray **************************************************************
4175 Constructs a new array holding objects in class elementClass. All
4176 elements are initially set to initialElement.
4178 *******************************************************************************/
4180 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4181 jclass elementClass, jobject initialElement)
4183 java_objectarray *oa;
4186 STATISTICS(jniinvokation());
4189 exceptions_throw_negativearraysizeexception();
4193 oa = builtin_anewarray(length, elementClass);
4198 /* set all elements to initialElement */
4200 for (i = 0; i < length; i++)
4201 oa->data[i] = initialElement;
4203 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4207 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4210 java_objectarray *oa;
4213 STATISTICS(jniinvokation());
4215 oa = (java_objectarray *) array;
4217 if (index >= oa->header.size) {
4218 exceptions_throw_arrayindexoutofboundsexception();
4222 o = oa->data[index];
4224 return _Jv_JNI_NewLocalRef(env, o);
4228 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4229 jsize index, jobject val)
4231 java_objectarray *oa;
4232 java_objectheader *o;
4234 STATISTICS(jniinvokation());
4236 oa = (java_objectarray *) array;
4237 o = (java_objectheader *) val;
4239 if (index >= oa->header.size) {
4240 exceptions_throw_arrayindexoutofboundsexception();
4244 /* check if the class of value is a subclass of the element class
4247 if (!builtin_canstore(oa, o)) {
4248 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
4253 oa->data[index] = val;
4257 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4259 java_booleanarray *ba;
4261 STATISTICS(jniinvokation());
4264 exceptions_throw_negativearraysizeexception();
4268 ba = builtin_newarray_boolean(len);
4270 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4274 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4278 STATISTICS(jniinvokation());
4281 exceptions_throw_negativearraysizeexception();
4285 ba = builtin_newarray_byte(len);
4287 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4291 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4295 STATISTICS(jniinvokation());
4298 exceptions_throw_negativearraysizeexception();
4302 ca = builtin_newarray_char(len);
4304 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4308 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4310 java_shortarray *sa;
4312 STATISTICS(jniinvokation());
4315 exceptions_throw_negativearraysizeexception();
4319 sa = builtin_newarray_short(len);
4321 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4325 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4329 STATISTICS(jniinvokation());
4332 exceptions_throw_negativearraysizeexception();
4336 ia = builtin_newarray_int(len);
4338 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4342 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4346 STATISTICS(jniinvokation());
4349 exceptions_throw_negativearraysizeexception();
4353 la = builtin_newarray_long(len);
4355 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4359 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4361 java_floatarray *fa;
4363 STATISTICS(jniinvokation());
4366 exceptions_throw_negativearraysizeexception();
4370 fa = builtin_newarray_float(len);
4372 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4376 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4378 java_doublearray *da;
4380 STATISTICS(jniinvokation());
4383 exceptions_throw_negativearraysizeexception();
4387 da = builtin_newarray_double(len);
4389 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4393 /* Get<PrimitiveType>ArrayElements *********************************************
4395 A family of functions that returns the body of the primitive array.
4397 *******************************************************************************/
4399 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4402 java_booleanarray *ba;
4404 STATISTICS(jniinvokation());
4406 ba = (java_booleanarray *) array;
4409 *isCopy = JNI_FALSE;
4415 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4420 STATISTICS(jniinvokation());
4422 ba = (java_bytearray *) array;
4425 *isCopy = JNI_FALSE;
4431 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4436 STATISTICS(jniinvokation());
4438 ca = (java_chararray *) array;
4441 *isCopy = JNI_FALSE;
4447 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4450 java_shortarray *sa;
4452 STATISTICS(jniinvokation());
4454 sa = (java_shortarray *) array;
4457 *isCopy = JNI_FALSE;
4463 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4468 STATISTICS(jniinvokation());
4470 ia = (java_intarray *) array;
4473 *isCopy = JNI_FALSE;
4479 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4484 STATISTICS(jniinvokation());
4486 la = (java_longarray *) array;
4489 *isCopy = JNI_FALSE;
4491 /* We cast this one to prevent a compiler warning on 64-bit
4492 systems since GNU Classpath typedef jlong to long long. */
4494 return (jlong *) la->data;
4498 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4501 java_floatarray *fa;
4503 STATISTICS(jniinvokation());
4505 fa = (java_floatarray *) array;
4508 *isCopy = JNI_FALSE;
4514 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4517 java_doublearray *da;
4519 STATISTICS(jniinvokation());
4521 da = (java_doublearray *) array;
4524 *isCopy = JNI_FALSE;
4530 /* Release<PrimitiveType>ArrayElements *****************************************
4532 A family of functions that informs the VM that the native code no
4533 longer needs access to elems. The elems argument is a pointer
4534 derived from array using the corresponding
4535 Get<PrimitiveType>ArrayElements() function. If necessary, this
4536 function copies back all changes made to elems to the original
4539 *******************************************************************************/
4541 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4542 jboolean *elems, jint mode)
4544 java_booleanarray *ba;
4546 STATISTICS(jniinvokation());
4548 ba = (java_booleanarray *) array;
4550 if (elems != ba->data) {
4553 MCOPY(ba->data, elems, u1, ba->header.size);
4556 MCOPY(ba->data, elems, u1, ba->header.size);
4557 /* XXX TWISTI how should it be freed? */
4560 /* XXX TWISTI how should it be freed? */
4567 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4568 jbyte *elems, jint mode)
4572 STATISTICS(jniinvokation());
4574 ba = (java_bytearray *) array;
4576 if (elems != ba->data) {
4579 MCOPY(ba->data, elems, s1, ba->header.size);
4582 MCOPY(ba->data, elems, s1, ba->header.size);
4583 /* XXX TWISTI how should it be freed? */
4586 /* XXX TWISTI how should it be freed? */
4593 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4594 jchar *elems, jint mode)
4598 STATISTICS(jniinvokation());
4600 ca = (java_chararray *) array;
4602 if (elems != ca->data) {
4605 MCOPY(ca->data, elems, u2, ca->header.size);
4608 MCOPY(ca->data, elems, u2, ca->header.size);
4609 /* XXX TWISTI how should it be freed? */
4612 /* XXX TWISTI how should it be freed? */
4619 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4620 jshort *elems, jint mode)
4622 java_shortarray *sa;
4624 STATISTICS(jniinvokation());
4626 sa = (java_shortarray *) array;
4628 if (elems != sa->data) {
4631 MCOPY(sa->data, elems, s2, sa->header.size);
4634 MCOPY(sa->data, elems, s2, sa->header.size);
4635 /* XXX TWISTI how should it be freed? */
4638 /* XXX TWISTI how should it be freed? */
4645 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4650 STATISTICS(jniinvokation());
4652 ia = (java_intarray *) array;
4654 if (elems != ia->data) {
4657 MCOPY(ia->data, elems, s4, ia->header.size);
4660 MCOPY(ia->data, elems, s4, ia->header.size);
4661 /* XXX TWISTI how should it be freed? */
4664 /* XXX TWISTI how should it be freed? */
4671 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4672 jlong *elems, jint mode)
4676 STATISTICS(jniinvokation());
4678 la = (java_longarray *) array;
4680 /* We cast this one to prevent a compiler warning on 64-bit
4681 systems since GNU Classpath typedef jlong to long long. */
4683 if ((s8 *) elems != la->data) {
4686 MCOPY(la->data, elems, s8, la->header.size);
4689 MCOPY(la->data, elems, s8, la->header.size);
4690 /* XXX TWISTI how should it be freed? */
4693 /* XXX TWISTI how should it be freed? */
4700 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4701 jfloat *elems, jint mode)
4703 java_floatarray *fa;
4705 STATISTICS(jniinvokation());
4707 fa = (java_floatarray *) array;
4709 if (elems != fa->data) {
4712 MCOPY(fa->data, elems, float, fa->header.size);
4715 MCOPY(fa->data, elems, float, fa->header.size);
4716 /* XXX TWISTI how should it be freed? */
4719 /* XXX TWISTI how should it be freed? */
4726 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4727 jdouble *elems, jint mode)
4729 java_doublearray *da;
4731 STATISTICS(jniinvokation());
4733 da = (java_doublearray *) array;
4735 if (elems != da->data) {
4738 MCOPY(da->data, elems, double, da->header.size);
4741 MCOPY(da->data, elems, double, da->header.size);
4742 /* XXX TWISTI how should it be freed? */
4745 /* XXX TWISTI how should it be freed? */
4752 /* Get<PrimitiveType>ArrayRegion **********************************************
4754 A family of functions that copies a region of a primitive array
4757 *******************************************************************************/
4759 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4760 jsize start, jsize len, jboolean *buf)
4762 java_booleanarray *ba;
4764 STATISTICS(jniinvokation());
4766 ba = (java_booleanarray *) array;
4768 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4769 exceptions_throw_arrayindexoutofboundsexception();
4771 MCOPY(buf, &ba->data[start], u1, len);
4775 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4776 jsize len, jbyte *buf)
4780 STATISTICS(jniinvokation());
4782 ba = (java_bytearray *) array;
4784 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4785 exceptions_throw_arrayindexoutofboundsexception();
4787 MCOPY(buf, &ba->data[start], s1, len);
4791 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4792 jsize len, jchar *buf)
4796 STATISTICS(jniinvokation());
4798 ca = (java_chararray *) array;
4800 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4801 exceptions_throw_arrayindexoutofboundsexception();
4803 MCOPY(buf, &ca->data[start], u2, len);
4807 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4808 jsize len, jshort *buf)
4810 java_shortarray *sa;
4812 STATISTICS(jniinvokation());
4814 sa = (java_shortarray *) array;
4816 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4817 exceptions_throw_arrayindexoutofboundsexception();
4819 MCOPY(buf, &sa->data[start], s2, len);
4823 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4824 jsize len, jint *buf)
4828 STATISTICS(jniinvokation());
4830 ia = (java_intarray *) array;
4832 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4833 exceptions_throw_arrayindexoutofboundsexception();
4835 MCOPY(buf, &ia->data[start], s4, len);
4839 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4840 jsize len, jlong *buf)
4844 STATISTICS(jniinvokation());
4846 la = (java_longarray *) array;
4848 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4849 exceptions_throw_arrayindexoutofboundsexception();
4851 MCOPY(buf, &la->data[start], s8, len);
4855 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4856 jsize len, jfloat *buf)
4858 java_floatarray *fa;
4860 STATISTICS(jniinvokation());
4862 fa = (java_floatarray *) array;
4864 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4865 exceptions_throw_arrayindexoutofboundsexception();
4867 MCOPY(buf, &fa->data[start], float, len);
4871 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4872 jsize len, jdouble *buf)
4874 java_doublearray *da;
4876 STATISTICS(jniinvokation());
4878 da = (java_doublearray *) array;
4880 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4881 exceptions_throw_arrayindexoutofboundsexception();
4883 MCOPY(buf, &da->data[start], double, len);
4887 /* Set<PrimitiveType>ArrayRegion **********************************************
4889 A family of functions that copies back a region of a primitive
4890 array from a buffer.
4892 *******************************************************************************/
4894 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4895 jsize start, jsize len, jboolean *buf)
4897 java_booleanarray *ba;
4899 STATISTICS(jniinvokation());
4901 ba = (java_booleanarray *) array;
4903 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4904 exceptions_throw_arrayindexoutofboundsexception();
4906 MCOPY(&ba->data[start], buf, u1, len);
4910 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4911 jsize len, jbyte *buf)
4915 STATISTICS(jniinvokation());
4917 ba = (java_bytearray *) array;
4919 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4920 exceptions_throw_arrayindexoutofboundsexception();
4922 MCOPY(&ba->data[start], buf, s1, len);
4926 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4927 jsize len, jchar *buf)
4931 STATISTICS(jniinvokation());
4933 ca = (java_chararray *) array;
4935 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4936 exceptions_throw_arrayindexoutofboundsexception();
4938 MCOPY(&ca->data[start], buf, u2, len);
4942 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4943 jsize len, jshort *buf)
4945 java_shortarray *sa;
4947 STATISTICS(jniinvokation());
4949 sa = (java_shortarray *) array;
4951 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4952 exceptions_throw_arrayindexoutofboundsexception();
4954 MCOPY(&sa->data[start], buf, s2, len);
4958 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4959 jsize len, jint *buf)
4963 STATISTICS(jniinvokation());
4965 ia = (java_intarray *) array;
4967 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4968 exceptions_throw_arrayindexoutofboundsexception();
4970 MCOPY(&ia->data[start], buf, s4, len);
4974 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
4975 jsize len, jlong *buf)
4979 STATISTICS(jniinvokation());
4981 la = (java_longarray *) array;
4983 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4984 exceptions_throw_arrayindexoutofboundsexception();
4986 MCOPY(&la->data[start], buf, s8, len);
4990 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4991 jsize len, jfloat *buf)
4993 java_floatarray *fa;
4995 STATISTICS(jniinvokation());
4997 fa = (java_floatarray *) array;
4999 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5000 exceptions_throw_arrayindexoutofboundsexception();
5002 MCOPY(&fa->data[start], buf, float, len);
5006 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5007 jsize len, jdouble *buf)
5009 java_doublearray *da;
5011 STATISTICS(jniinvokation());
5013 da = (java_doublearray *) array;
5015 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5016 exceptions_throw_arrayindexoutofboundsexception();
5018 MCOPY(&da->data[start], buf, double, len);
5022 /* Registering Native Methods *************************************************/
5024 /* RegisterNatives *************************************************************
5026 Registers native methods with the class specified by the clazz
5027 argument. The methods parameter specifies an array of
5028 JNINativeMethod structures that contain the names, signatures, and
5029 function pointers of the native methods. The nMethods parameter
5030 specifies the number of native methods in the array.
5032 *******************************************************************************/
5034 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5035 const JNINativeMethod *methods, jint nMethods)
5037 STATISTICS(jniinvokation());
5039 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5040 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5041 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5048 /* UnregisterNatives ***********************************************************
5050 Unregisters native methods of a class. The class goes back to the
5051 state before it was linked or registered with its native method
5054 This function should not be used in normal native code. Instead, it
5055 provides special programs a way to reload and relink native
5058 *******************************************************************************/
5060 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5062 STATISTICS(jniinvokation());
5064 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5066 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5072 /* Monitor Operations *********************************************************/
5074 /* MonitorEnter ****************************************************************
5076 Enters the monitor associated with the underlying Java object
5079 *******************************************************************************/
5081 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5083 STATISTICS(jniinvokation());
5086 exceptions_throw_nullpointerexception();
5090 LOCK_MONITOR_ENTER(obj);
5096 /* MonitorExit *****************************************************************
5098 The current thread must be the owner of the monitor associated with
5099 the underlying Java object referred to by obj. The thread
5100 decrements the counter indicating the number of times it has
5101 entered this monitor. If the value of the counter becomes zero, the
5102 current thread releases the monitor.
5104 *******************************************************************************/
5106 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5108 STATISTICS(jniinvokation());
5111 exceptions_throw_nullpointerexception();
5115 LOCK_MONITOR_EXIT(obj);
5121 /* JavaVM Interface ***********************************************************/
5123 /* GetJavaVM *******************************************************************
5125 Returns the Java VM interface (used in the Invocation API)
5126 associated with the current thread. The result is placed at the
5127 location pointed to by the second argument, vm.
5129 *******************************************************************************/
5131 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5133 STATISTICS(jniinvokation());
5135 *vm = (JavaVM *) _Jv_jvm;
5141 /* GetStringRegion *************************************************************
5143 Copies len number of Unicode characters beginning at offset start
5144 to the given buffer buf.
5146 Throws StringIndexOutOfBoundsException on index overflow.
5148 *******************************************************************************/
5150 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5153 java_lang_String *s;
5156 STATISTICS(jniinvokation());
5158 s = (java_lang_String *) str;
5161 if ((start < 0) || (len < 0) || (start > s->count) ||
5162 (start + len > s->count)) {
5163 exceptions_throw_stringindexoutofboundsexception();
5167 MCOPY(buf, &ca->data[start], u2, len);
5171 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5172 jsize len, char *buf)
5174 STATISTICS(jniinvokation());
5176 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5180 /* GetPrimitiveArrayCritical ***************************************************
5182 Obtain a direct pointer to array elements.
5184 *******************************************************************************/
5186 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5192 ba = (java_bytearray *) array;
5194 /* do the same as Kaffe does */
5196 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5202 /* ReleasePrimitiveArrayCritical ***********************************************
5204 No specific documentation.
5206 *******************************************************************************/
5208 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5209 void *carray, jint mode)
5211 STATISTICS(jniinvokation());
5213 /* do the same as Kaffe does */
5215 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5220 /* GetStringCritical ***********************************************************
5222 The semantics of these two functions are similar to the existing
5223 Get/ReleaseStringChars functions.
5225 *******************************************************************************/
5227 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5230 STATISTICS(jniinvokation());
5232 return _Jv_JNI_GetStringChars(env, string, isCopy);
5236 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5237 const jchar *cstring)
5239 STATISTICS(jniinvokation());
5241 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5245 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5247 STATISTICS(jniinvokation());
5249 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5255 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5257 STATISTICS(jniinvokation());
5259 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5263 /* NewGlobalRef ****************************************************************
5265 Creates a new global reference to the object referred to by the obj
5268 *******************************************************************************/
5270 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5272 hashtable_global_ref_entry *gre;
5273 u4 key; /* hashkey */
5274 u4 slot; /* slot in hashtable */
5276 STATISTICS(jniinvokation());
5278 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5280 /* normally addresses are aligned to 4, 8 or 16 bytes */
5282 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5283 slot = key & (hashtable_global_ref->size - 1);
5284 gre = hashtable_global_ref->ptr[slot];
5286 /* search external hash chain for the entry */
5289 if (gre->o == obj) {
5290 /* global object found, increment the reference */
5294 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5299 gre = gre->hashlink; /* next element in external chain */
5302 /* global ref not found, create a new one */
5304 gre = NEW(hashtable_global_ref_entry);
5309 /* insert entry into hashtable */
5311 gre->hashlink = hashtable_global_ref->ptr[slot];
5313 hashtable_global_ref->ptr[slot] = gre;
5315 /* update number of hashtable-entries */
5317 hashtable_global_ref->entries++;
5319 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5325 /* DeleteGlobalRef *************************************************************
5327 Deletes the global reference pointed to by globalRef.
5329 *******************************************************************************/
5331 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5333 hashtable_global_ref_entry *gre;
5334 hashtable_global_ref_entry *prevgre;
5335 u4 key; /* hashkey */
5336 u4 slot; /* slot in hashtable */
5338 STATISTICS(jniinvokation());
5340 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5342 /* normally addresses are aligned to 4, 8 or 16 bytes */
5344 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5345 slot = key & (hashtable_global_ref->size - 1);
5346 gre = hashtable_global_ref->ptr[slot];
5348 /* initialize prevgre */
5352 /* search external hash chain for the entry */
5355 if (gre->o == globalRef) {
5356 /* global object found, decrement the reference count */
5360 /* if reference count is 0, remove the entry */
5362 if (gre->refs == 0) {
5363 /* special handling if it's the first in the chain */
5365 if (prevgre == NULL)
5366 hashtable_global_ref->ptr[slot] = gre->hashlink;
5368 prevgre->hashlink = gre->hashlink;
5370 FREE(gre, hashtable_global_ref_entry);
5373 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5378 prevgre = gre; /* save current pointer for removal */
5379 gre = gre->hashlink; /* next element in external chain */
5382 log_println("JNI-DeleteGlobalRef: global reference not found");
5384 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5388 /* ExceptionCheck **************************************************************
5390 Returns JNI_TRUE when there is a pending exception; otherwise,
5393 *******************************************************************************/
5395 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5397 STATISTICS(jniinvokation());
5399 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5403 /* New JNI 1.4 functions ******************************************************/
5405 /* NewDirectByteBuffer *********************************************************
5407 Allocates and returns a direct java.nio.ByteBuffer referring to the
5408 block of memory starting at the memory address address and
5409 extending capacity bytes.
5411 *******************************************************************************/
5413 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5415 java_objectheader *nbuf;
5416 #if SIZEOF_VOID_P == 8
5417 gnu_classpath_Pointer64 *paddress;
5419 gnu_classpath_Pointer32 *paddress;
5422 STATISTICS(jniinvokation());
5424 /* alocate a gnu.classpath.Pointer{32,64} object */
5426 #if SIZEOF_VOID_P == 8
5427 if (!(paddress = (gnu_classpath_Pointer64 *)
5428 builtin_new(class_gnu_classpath_Pointer64)))
5430 if (!(paddress = (gnu_classpath_Pointer32 *)
5431 builtin_new(class_gnu_classpath_Pointer32)))
5435 /* fill gnu.classpath.Pointer{32,64} with address */
5437 paddress->data = (ptrint) address;
5439 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5441 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5442 (jmethodID) dbbirw_init, NULL, paddress,
5443 (jint) capacity, (jint) capacity, (jint) 0);
5445 /* add local reference and return the value */
5447 return _Jv_JNI_NewLocalRef(env, nbuf);
5451 /* GetDirectBufferAddress ******************************************************
5453 Fetches and returns the starting address of the memory region
5454 referenced by the given direct java.nio.Buffer.
5456 *******************************************************************************/
5458 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5460 java_nio_DirectByteBufferImpl *nbuf;
5461 #if SIZEOF_VOID_P == 8
5462 gnu_classpath_Pointer64 *address;
5464 gnu_classpath_Pointer32 *address;
5467 STATISTICS(jniinvokation());
5469 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5472 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5474 #if SIZEOF_VOID_P == 8
5475 address = (gnu_classpath_Pointer64 *) nbuf->address;
5477 address = (gnu_classpath_Pointer32 *) nbuf->address;
5480 if (address == NULL)
5483 return (void *) address->data;
5487 /* GetDirectBufferCapacity *****************************************************
5489 Fetches and returns the capacity in bytes of the memory region
5490 referenced by the given direct java.nio.Buffer.
5492 *******************************************************************************/
5494 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5496 java_nio_Buffer *nbuf;
5498 STATISTICS(jniinvokation());
5500 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5503 nbuf = (java_nio_Buffer *) buf;
5505 return (jlong) nbuf->cap;
5509 /* DestroyJavaVM ***************************************************************
5511 Unloads a Java VM and reclaims its resources. Only the main thread
5512 can unload the VM. The system waits until the main thread is only
5513 remaining user thread before it destroys the VM.
5515 *******************************************************************************/
5517 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5521 STATISTICS(jniinvokation());
5523 status = vm_destroy(vm);
5529 /* AttachCurrentThread *********************************************************
5531 Attaches the current thread to a Java VM. Returns a JNI interface
5532 pointer in the JNIEnv argument.
5534 Trying to attach a thread that is already attached is a no-op.
5536 A native thread cannot be attached simultaneously to two Java VMs.
5538 When a thread is attached to the VM, the context class loader is
5539 the bootstrap loader.
5541 *******************************************************************************/
5543 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5545 JavaVMAttachArgs *vm_aargs;
5547 #if defined(ENABLE_THREADS)
5548 if (threads_get_current_threadobject() == NULL) {
5549 vm_aargs = (JavaVMAttachArgs *) thr_args;
5551 if (vm_aargs != NULL) {
5552 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5553 (vm_aargs->version != JNI_VERSION_1_4))
5554 return JNI_EVERSION;
5557 if (!threads_attach_current_thread(vm_aargs, false))
5560 if (!jni_init_localref_table())
5571 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5573 STATISTICS(jniinvokation());
5575 return jni_attach_current_thread(p_env, thr_args, false);
5579 /* DetachCurrentThread *********************************************************
5581 Detaches the current thread from a Java VM. All Java monitors held
5582 by this thread are released. All Java threads waiting for this
5583 thread to die are notified.
5585 In JDK 1.1, the main thread cannot be detached from the VM. It must
5586 call DestroyJavaVM to unload the entire VM.
5588 In the JDK, the main thread can be detached from the VM.
5590 The main thread, which is the thread that created the Java VM,
5591 cannot be detached from the VM. Instead, the main thread must call
5592 JNI_DestroyJavaVM() to unload the entire VM.
5594 *******************************************************************************/
5596 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5598 #if defined(ENABLE_THREADS)
5599 threadobject *thread;
5601 STATISTICS(jniinvokation());
5603 thread = threads_get_current_threadobject();
5608 if (!threads_detach_thread(thread))
5616 /* GetEnv **********************************************************************
5618 If the current thread is not attached to the VM, sets *env to NULL,
5619 and returns JNI_EDETACHED. If the specified version is not
5620 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5621 sets *env to the appropriate interface, and returns JNI_OK.
5623 *******************************************************************************/
5625 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5627 STATISTICS(jniinvokation());
5629 #if defined(ENABLE_THREADS)
5630 if (threads_get_current_threadobject() == NULL) {
5633 return JNI_EDETACHED;
5637 /* check the JNI version */
5640 case JNI_VERSION_1_1:
5641 case JNI_VERSION_1_2:
5642 case JNI_VERSION_1_4:
5650 #if defined(ENABLE_JVMTI)
5651 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5652 == JVMTI_VERSION_INTERFACE_JVMTI) {
5654 *env = (void *) jvmti_new_environment();
5663 return JNI_EVERSION;
5667 /* AttachCurrentThreadAsDaemon *************************************************
5669 Same semantics as AttachCurrentThread, but the newly-created
5670 java.lang.Thread instance is a daemon.
5672 If the thread has already been attached via either
5673 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5674 simply sets the value pointed to by penv to the JNIEnv of the
5675 current thread. In this case neither AttachCurrentThread nor this
5676 routine have any effect on the daemon status of the thread.
5678 *******************************************************************************/
5680 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5682 STATISTICS(jniinvokation());
5684 return jni_attach_current_thread(penv, args, true);
5688 /* JNI invocation table *******************************************************/
5690 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5695 _Jv_JNI_DestroyJavaVM,
5696 _Jv_JNI_AttachCurrentThread,
5697 _Jv_JNI_DetachCurrentThread,
5699 _Jv_JNI_AttachCurrentThreadAsDaemon
5703 /* JNI function table *********************************************************/
5705 struct JNINativeInterface _Jv_JNINativeInterface = {
5712 _Jv_JNI_DefineClass,
5714 _Jv_JNI_FromReflectedMethod,
5715 _Jv_JNI_FromReflectedField,
5716 _Jv_JNI_ToReflectedMethod,
5717 _Jv_JNI_GetSuperclass,
5718 _Jv_JNI_IsAssignableFrom,
5719 _Jv_JNI_ToReflectedField,
5723 _Jv_JNI_ExceptionOccurred,
5724 _Jv_JNI_ExceptionDescribe,
5725 _Jv_JNI_ExceptionClear,
5727 _Jv_JNI_PushLocalFrame,
5728 _Jv_JNI_PopLocalFrame,
5730 _Jv_JNI_NewGlobalRef,
5731 _Jv_JNI_DeleteGlobalRef,
5732 _Jv_JNI_DeleteLocalRef,
5733 _Jv_JNI_IsSameObject,
5734 _Jv_JNI_NewLocalRef,
5735 _Jv_JNI_EnsureLocalCapacity,
5737 _Jv_JNI_AllocObject,
5742 _Jv_JNI_GetObjectClass,
5743 _Jv_JNI_IsInstanceOf,
5745 _Jv_JNI_GetMethodID,
5747 _Jv_JNI_CallObjectMethod,
5748 _Jv_JNI_CallObjectMethodV,
5749 _Jv_JNI_CallObjectMethodA,
5750 _Jv_JNI_CallBooleanMethod,
5751 _Jv_JNI_CallBooleanMethodV,
5752 _Jv_JNI_CallBooleanMethodA,
5753 _Jv_JNI_CallByteMethod,
5754 _Jv_JNI_CallByteMethodV,
5755 _Jv_JNI_CallByteMethodA,
5756 _Jv_JNI_CallCharMethod,
5757 _Jv_JNI_CallCharMethodV,
5758 _Jv_JNI_CallCharMethodA,
5759 _Jv_JNI_CallShortMethod,
5760 _Jv_JNI_CallShortMethodV,
5761 _Jv_JNI_CallShortMethodA,
5762 _Jv_JNI_CallIntMethod,
5763 _Jv_JNI_CallIntMethodV,
5764 _Jv_JNI_CallIntMethodA,
5765 _Jv_JNI_CallLongMethod,
5766 _Jv_JNI_CallLongMethodV,
5767 _Jv_JNI_CallLongMethodA,
5768 _Jv_JNI_CallFloatMethod,
5769 _Jv_JNI_CallFloatMethodV,
5770 _Jv_JNI_CallFloatMethodA,
5771 _Jv_JNI_CallDoubleMethod,
5772 _Jv_JNI_CallDoubleMethodV,
5773 _Jv_JNI_CallDoubleMethodA,
5774 _Jv_JNI_CallVoidMethod,
5775 _Jv_JNI_CallVoidMethodV,
5776 _Jv_JNI_CallVoidMethodA,
5778 _Jv_JNI_CallNonvirtualObjectMethod,
5779 _Jv_JNI_CallNonvirtualObjectMethodV,
5780 _Jv_JNI_CallNonvirtualObjectMethodA,
5781 _Jv_JNI_CallNonvirtualBooleanMethod,
5782 _Jv_JNI_CallNonvirtualBooleanMethodV,
5783 _Jv_JNI_CallNonvirtualBooleanMethodA,
5784 _Jv_JNI_CallNonvirtualByteMethod,
5785 _Jv_JNI_CallNonvirtualByteMethodV,
5786 _Jv_JNI_CallNonvirtualByteMethodA,
5787 _Jv_JNI_CallNonvirtualCharMethod,
5788 _Jv_JNI_CallNonvirtualCharMethodV,
5789 _Jv_JNI_CallNonvirtualCharMethodA,
5790 _Jv_JNI_CallNonvirtualShortMethod,
5791 _Jv_JNI_CallNonvirtualShortMethodV,
5792 _Jv_JNI_CallNonvirtualShortMethodA,
5793 _Jv_JNI_CallNonvirtualIntMethod,
5794 _Jv_JNI_CallNonvirtualIntMethodV,
5795 _Jv_JNI_CallNonvirtualIntMethodA,
5796 _Jv_JNI_CallNonvirtualLongMethod,
5797 _Jv_JNI_CallNonvirtualLongMethodV,
5798 _Jv_JNI_CallNonvirtualLongMethodA,
5799 _Jv_JNI_CallNonvirtualFloatMethod,
5800 _Jv_JNI_CallNonvirtualFloatMethodV,
5801 _Jv_JNI_CallNonvirtualFloatMethodA,
5802 _Jv_JNI_CallNonvirtualDoubleMethod,
5803 _Jv_JNI_CallNonvirtualDoubleMethodV,
5804 _Jv_JNI_CallNonvirtualDoubleMethodA,
5805 _Jv_JNI_CallNonvirtualVoidMethod,
5806 _Jv_JNI_CallNonvirtualVoidMethodV,
5807 _Jv_JNI_CallNonvirtualVoidMethodA,
5811 _Jv_JNI_GetObjectField,
5812 _Jv_JNI_GetBooleanField,
5813 _Jv_JNI_GetByteField,
5814 _Jv_JNI_GetCharField,
5815 _Jv_JNI_GetShortField,
5816 _Jv_JNI_GetIntField,
5817 _Jv_JNI_GetLongField,
5818 _Jv_JNI_GetFloatField,
5819 _Jv_JNI_GetDoubleField,
5820 _Jv_JNI_SetObjectField,
5821 _Jv_JNI_SetBooleanField,
5822 _Jv_JNI_SetByteField,
5823 _Jv_JNI_SetCharField,
5824 _Jv_JNI_SetShortField,
5825 _Jv_JNI_SetIntField,
5826 _Jv_JNI_SetLongField,
5827 _Jv_JNI_SetFloatField,
5828 _Jv_JNI_SetDoubleField,
5830 _Jv_JNI_GetStaticMethodID,
5832 _Jv_JNI_CallStaticObjectMethod,
5833 _Jv_JNI_CallStaticObjectMethodV,
5834 _Jv_JNI_CallStaticObjectMethodA,
5835 _Jv_JNI_CallStaticBooleanMethod,
5836 _Jv_JNI_CallStaticBooleanMethodV,
5837 _Jv_JNI_CallStaticBooleanMethodA,
5838 _Jv_JNI_CallStaticByteMethod,
5839 _Jv_JNI_CallStaticByteMethodV,
5840 _Jv_JNI_CallStaticByteMethodA,
5841 _Jv_JNI_CallStaticCharMethod,
5842 _Jv_JNI_CallStaticCharMethodV,
5843 _Jv_JNI_CallStaticCharMethodA,
5844 _Jv_JNI_CallStaticShortMethod,
5845 _Jv_JNI_CallStaticShortMethodV,
5846 _Jv_JNI_CallStaticShortMethodA,
5847 _Jv_JNI_CallStaticIntMethod,
5848 _Jv_JNI_CallStaticIntMethodV,
5849 _Jv_JNI_CallStaticIntMethodA,
5850 _Jv_JNI_CallStaticLongMethod,
5851 _Jv_JNI_CallStaticLongMethodV,
5852 _Jv_JNI_CallStaticLongMethodA,
5853 _Jv_JNI_CallStaticFloatMethod,
5854 _Jv_JNI_CallStaticFloatMethodV,
5855 _Jv_JNI_CallStaticFloatMethodA,
5856 _Jv_JNI_CallStaticDoubleMethod,
5857 _Jv_JNI_CallStaticDoubleMethodV,
5858 _Jv_JNI_CallStaticDoubleMethodA,
5859 _Jv_JNI_CallStaticVoidMethod,
5860 _Jv_JNI_CallStaticVoidMethodV,
5861 _Jv_JNI_CallStaticVoidMethodA,
5863 _Jv_JNI_GetStaticFieldID,
5865 _Jv_JNI_GetStaticObjectField,
5866 _Jv_JNI_GetStaticBooleanField,
5867 _Jv_JNI_GetStaticByteField,
5868 _Jv_JNI_GetStaticCharField,
5869 _Jv_JNI_GetStaticShortField,
5870 _Jv_JNI_GetStaticIntField,
5871 _Jv_JNI_GetStaticLongField,
5872 _Jv_JNI_GetStaticFloatField,
5873 _Jv_JNI_GetStaticDoubleField,
5874 _Jv_JNI_SetStaticObjectField,
5875 _Jv_JNI_SetStaticBooleanField,
5876 _Jv_JNI_SetStaticByteField,
5877 _Jv_JNI_SetStaticCharField,
5878 _Jv_JNI_SetStaticShortField,
5879 _Jv_JNI_SetStaticIntField,
5880 _Jv_JNI_SetStaticLongField,
5881 _Jv_JNI_SetStaticFloatField,
5882 _Jv_JNI_SetStaticDoubleField,
5885 _Jv_JNI_GetStringLength,
5886 _Jv_JNI_GetStringChars,
5887 _Jv_JNI_ReleaseStringChars,
5889 _Jv_JNI_NewStringUTF,
5890 _Jv_JNI_GetStringUTFLength,
5891 _Jv_JNI_GetStringUTFChars,
5892 _Jv_JNI_ReleaseStringUTFChars,
5894 _Jv_JNI_GetArrayLength,
5896 _Jv_JNI_NewObjectArray,
5897 _Jv_JNI_GetObjectArrayElement,
5898 _Jv_JNI_SetObjectArrayElement,
5900 _Jv_JNI_NewBooleanArray,
5901 _Jv_JNI_NewByteArray,
5902 _Jv_JNI_NewCharArray,
5903 _Jv_JNI_NewShortArray,
5904 _Jv_JNI_NewIntArray,
5905 _Jv_JNI_NewLongArray,
5906 _Jv_JNI_NewFloatArray,
5907 _Jv_JNI_NewDoubleArray,
5909 _Jv_JNI_GetBooleanArrayElements,
5910 _Jv_JNI_GetByteArrayElements,
5911 _Jv_JNI_GetCharArrayElements,
5912 _Jv_JNI_GetShortArrayElements,
5913 _Jv_JNI_GetIntArrayElements,
5914 _Jv_JNI_GetLongArrayElements,
5915 _Jv_JNI_GetFloatArrayElements,
5916 _Jv_JNI_GetDoubleArrayElements,
5918 _Jv_JNI_ReleaseBooleanArrayElements,
5919 _Jv_JNI_ReleaseByteArrayElements,
5920 _Jv_JNI_ReleaseCharArrayElements,
5921 _Jv_JNI_ReleaseShortArrayElements,
5922 _Jv_JNI_ReleaseIntArrayElements,
5923 _Jv_JNI_ReleaseLongArrayElements,
5924 _Jv_JNI_ReleaseFloatArrayElements,
5925 _Jv_JNI_ReleaseDoubleArrayElements,
5927 _Jv_JNI_GetBooleanArrayRegion,
5928 _Jv_JNI_GetByteArrayRegion,
5929 _Jv_JNI_GetCharArrayRegion,
5930 _Jv_JNI_GetShortArrayRegion,
5931 _Jv_JNI_GetIntArrayRegion,
5932 _Jv_JNI_GetLongArrayRegion,
5933 _Jv_JNI_GetFloatArrayRegion,
5934 _Jv_JNI_GetDoubleArrayRegion,
5935 _Jv_JNI_SetBooleanArrayRegion,
5936 _Jv_JNI_SetByteArrayRegion,
5937 _Jv_JNI_SetCharArrayRegion,
5938 _Jv_JNI_SetShortArrayRegion,
5939 _Jv_JNI_SetIntArrayRegion,
5940 _Jv_JNI_SetLongArrayRegion,
5941 _Jv_JNI_SetFloatArrayRegion,
5942 _Jv_JNI_SetDoubleArrayRegion,
5944 _Jv_JNI_RegisterNatives,
5945 _Jv_JNI_UnregisterNatives,
5947 _Jv_JNI_MonitorEnter,
5948 _Jv_JNI_MonitorExit,
5952 /* new JNI 1.2 functions */
5954 _Jv_JNI_GetStringRegion,
5955 _Jv_JNI_GetStringUTFRegion,
5957 _Jv_JNI_GetPrimitiveArrayCritical,
5958 _Jv_JNI_ReleasePrimitiveArrayCritical,
5960 _Jv_JNI_GetStringCritical,
5961 _Jv_JNI_ReleaseStringCritical,
5963 _Jv_JNI_NewWeakGlobalRef,
5964 _Jv_JNI_DeleteWeakGlobalRef,
5966 _Jv_JNI_ExceptionCheck,
5968 /* new JNI 1.4 functions */
5970 _Jv_JNI_NewDirectByteBuffer,
5971 _Jv_JNI_GetDirectBufferAddress,
5972 _Jv_JNI_GetDirectBufferCapacity
5976 /* Invocation API Functions ***************************************************/
5978 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5980 Returns a default configuration for the Java VM.
5982 *******************************************************************************/
5984 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5986 JavaVMInitArgs *_vm_args;
5988 _vm_args = (JavaVMInitArgs *) vm_args;
5990 /* GNU classpath currently supports JNI 1.2 */
5992 switch (_vm_args->version) {
5993 case JNI_VERSION_1_1:
5994 _vm_args->version = JNI_VERSION_1_1;
5997 case JNI_VERSION_1_2:
5998 case JNI_VERSION_1_4:
5999 _vm_args->ignoreUnrecognized = JNI_FALSE;
6000 _vm_args->options = NULL;
6001 _vm_args->nOptions = 0;
6012 /* JNI_GetCreatedJavaVMs *******************************************************
6014 Returns all Java VMs that have been created. Pointers to VMs are written in
6015 the buffer vmBuf in the order they are created. At most bufLen number of
6016 entries will be written. The total number of created VMs is returned in
6019 *******************************************************************************/
6021 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6023 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6029 /* JNI_CreateJavaVM ************************************************************
6031 Loads and initializes a Java VM. The current thread becomes the main thread.
6032 Sets the env argument to the JNI interface pointer of the main thread.
6034 *******************************************************************************/
6036 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6038 /* actually create the JVM */
6040 if (!vm_createjvm(p_vm, p_env, vm_args))
6048 * These are local overrides for various environment variables in Emacs.
6049 * Please do not remove this and leave it at the end of the file, where
6050 * Emacs will automagically detect them.
6051 * ---------------------------------------------------------------------
6054 * indent-tabs-mode: t
6058 * vim:noexpandtab:sw=4:ts=4: