1 /* src/native/jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996-2005, 2006, 2007 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 $Id: jni.c 7265 2007-01-31 17:00:51Z twisti $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #include "native/include/gnu_classpath_Pointer.h"
44 #if SIZEOF_VOID_P == 8
45 # include "native/include/gnu_classpath_Pointer64.h"
47 # include "native/include/gnu_classpath_Pointer32.h"
50 #include "native/include/java_lang_Object.h"
51 #include "native/include/java_lang_Byte.h"
52 #include "native/include/java_lang_Character.h"
53 #include "native/include/java_lang_Short.h"
54 #include "native/include/java_lang_Integer.h"
55 #include "native/include/java_lang_Boolean.h"
56 #include "native/include/java_lang_Long.h"
57 #include "native/include/java_lang_Float.h"
58 #include "native/include/java_lang_Double.h"
59 #include "native/include/java_lang_String.h"
60 #include "native/include/java_lang_Throwable.h"
61 #include "native/include/java_lang_reflect_Method.h"
62 #include "native/include/java_lang_reflect_Constructor.h"
63 #include "native/include/java_lang_reflect_Field.h"
65 #include "native/include/java_lang_ClassLoader.h"
66 #include "native/include/java_lang_Class.h" /* for java_lang_VMClass.h */
67 #include "native/include/java_lang_VMClass.h"
68 #include "native/include/java_lang_VMClassLoader.h"
69 #include "native/include/java_nio_Buffer.h"
70 #include "native/include/java_nio_DirectByteBufferImpl.h"
72 #if defined(ENABLE_JVMTI)
73 # include "native/jvmti/cacaodbg.h"
76 #if defined(ENABLE_THREADS)
77 # include "threads/native/lock.h"
78 # include "threads/native/threads.h"
80 # include "threads/none/lock.h"
83 #include "toolbox/logging.h"
85 #include "vm/builtin.h"
86 #include "vm/exceptions.h"
87 #include "vm/global.h"
88 #include "vm/initialize.h"
89 #include "vm/stringlocal.h"
92 #include "vm/jit/asmpart.h"
93 #include "vm/jit/jit.h"
95 #include "vmcore/loader.h"
96 #include "vmcore/options.h"
97 #include "vmcore/resolve.h"
98 #include "vmcore/statistics.h"
101 /* global variables ***********************************************************/
103 /* global reference table *****************************************************/
105 /* hashsize must be power of 2 */
107 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
109 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
112 /* direct buffer stuff ********************************************************/
114 static classinfo *class_java_nio_Buffer;
115 static classinfo *class_java_nio_DirectByteBufferImpl;
116 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
117 #if SIZEOF_VOID_P == 8
118 static classinfo *class_gnu_classpath_Pointer64;
120 static classinfo *class_gnu_classpath_Pointer32;
123 static methodinfo *dbbirw_init;
126 /* local reference table ******************************************************/
128 #if !defined(ENABLE_THREADS)
129 localref_table *_no_threads_localref_table;
133 /* accessing instance fields macros *******************************************/
135 #define SET_FIELD(o,type,f,value) \
136 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
138 #define GET_FIELD(o,type,f) \
139 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
142 /* some forward declarations **************************************************/
144 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
145 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
148 /* jni_init ********************************************************************
150 Initialize the JNI subsystem.
152 *******************************************************************************/
156 /* create global ref hashtable */
158 hashtable_global_ref = NEW(hashtable);
160 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
163 /* direct buffer stuff */
165 if (!(class_java_nio_Buffer =
166 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
167 !link_class(class_java_nio_Buffer))
170 if (!(class_java_nio_DirectByteBufferImpl =
171 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
172 !link_class(class_java_nio_DirectByteBufferImpl))
175 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
176 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
177 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
181 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
183 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
186 #if SIZEOF_VOID_P == 8
187 if (!(class_gnu_classpath_Pointer64 =
188 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
189 !link_class(class_gnu_classpath_Pointer64))
192 if (!(class_gnu_classpath_Pointer32 =
193 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
194 !link_class(class_gnu_classpath_Pointer32))
202 /* jni_init_localref_table *****************************************************
204 Initializes the local references table of the current thread.
206 *******************************************************************************/
208 bool jni_init_localref_table(void)
212 lrt = GCNEW(localref_table);
217 lrt->capacity = LOCALREFTABLE_CAPACITY;
219 lrt->localframes = 1;
220 lrt->prev = LOCALREFTABLE;
222 /* clear the references array (memset is faster then a for-loop) */
224 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
232 /* _Jv_jni_vmargs_from_objectarray *********************************************
236 *******************************************************************************/
238 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
241 java_objectarray *params)
243 java_objectheader *param;
245 typedesc *paramtypes;
251 paramcount = descr->paramcount;
252 paramtypes = descr->paramtypes;
254 /* if method is non-static fill first block and skip `this' pointer */
260 vmargs[0].type = TYPE_ADR;
261 vmargs[0].data.l = (u8) (ptrint) o;
268 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
269 switch (paramtypes->type) {
270 /* primitive types */
275 param = params->data[j];
280 /* internally used data type */
281 vmargs[i].type = paramtypes->type;
283 /* convert the value according to its declared type */
285 c = param->vftbl->class;
287 switch (paramtypes->decltype) {
288 case PRIMITIVETYPE_BOOLEAN:
289 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
290 value = (s8) ((java_lang_Boolean *) param)->value;
294 vmargs[i].data.l = value;
297 case PRIMITIVETYPE_BYTE:
298 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
299 value = (s8) ((java_lang_Byte *) param)->value;
303 vmargs[i].data.l = value;
306 case PRIMITIVETYPE_CHAR:
307 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
308 value = (s8) ((java_lang_Character *) param)->value;
312 vmargs[i].data.l = value;
315 case PRIMITIVETYPE_SHORT:
316 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
317 value = (s8) ((java_lang_Short *) param)->value;
318 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
319 value = (s8) ((java_lang_Byte *) param)->value;
323 vmargs[i].data.l = value;
326 case PRIMITIVETYPE_INT:
327 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
328 value = (s8) ((java_lang_Integer *) param)->value;
329 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
330 value = (s8) ((java_lang_Short *) param)->value;
331 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
332 value = (s8) ((java_lang_Byte *) param)->value;
336 vmargs[i].data.l = value;
339 case PRIMITIVETYPE_LONG:
340 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
341 value = (s8) ((java_lang_Long *) param)->value;
342 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
343 value = (s8) ((java_lang_Integer *) param)->value;
344 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
345 value = (s8) ((java_lang_Short *) param)->value;
346 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
347 value = (s8) ((java_lang_Byte *) param)->value;
351 vmargs[i].data.l = value;
354 case PRIMITIVETYPE_FLOAT:
355 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
356 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
361 case PRIMITIVETYPE_DOUBLE:
362 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
363 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
364 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
365 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
376 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
379 if (params->data[j] != 0) {
380 if (paramtypes->arraydim > 0) {
381 if (!builtin_arrayinstanceof(params->data[j], c))
385 if (!builtin_instanceof(params->data[j], c))
390 vmargs[i].type = TYPE_ADR;
391 vmargs[i].data.l = (u8) (ptrint) params->data[j];
400 /* *rettype = descr->returntype.decltype; */
405 exceptions_throw_illegalargumentexception();
410 /* _Jv_jni_CallObjectMethod ****************************************************
412 Internal function to call Java Object methods.
414 *******************************************************************************/
416 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
418 methodinfo *m, va_list ap)
421 java_objectheader *ro;
423 STATISTICS(jniinvokation());
426 exceptions_throw_nullpointerexception();
430 /* Class initialization is done by the JIT compiler. This is ok
431 since a static method always belongs to the declaring class. */
433 if (m->flags & ACC_STATIC) {
434 /* For static methods we reset the object. */
439 /* for convenience */
444 /* For instance methods we make a virtual function table lookup. */
446 resm = method_vftbl_lookup(vftbl, m);
449 STATISTICS(jnicallXmethodnvokation());
451 ro = vm_call_method_valist(resm, o, ap);
457 /* _Jv_jni_CallObjectMethodA ***************************************************
459 Internal function to call Java Object methods.
461 *******************************************************************************/
463 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
465 methodinfo *m, jvalue *args)
468 java_objectheader *ro;
470 STATISTICS(jniinvokation());
473 exceptions_throw_nullpointerexception();
477 /* Class initialization is done by the JIT compiler. This is ok
478 since a static method always belongs to the declaring class. */
480 if (m->flags & ACC_STATIC) {
481 /* For static methods we reset the object. */
486 /* for convenience */
491 /* For instance methods we make a virtual function table lookup. */
493 resm = method_vftbl_lookup(vftbl, m);
496 STATISTICS(jnicallXmethodnvokation());
498 ro = vm_call_method_jvalue(resm, o, args);
504 /* _Jv_jni_CallIntMethod *******************************************************
506 Internal function to call Java integer class methods (boolean,
507 byte, char, short, int).
509 *******************************************************************************/
511 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
512 methodinfo *m, va_list ap)
517 STATISTICS(jniinvokation());
520 exceptions_throw_nullpointerexception();
524 /* Class initialization is done by the JIT compiler. This is ok
525 since a static method always belongs to the declaring class. */
527 if (m->flags & ACC_STATIC) {
528 /* For static methods we reset the object. */
533 /* for convenience */
538 /* For instance methods we make a virtual function table lookup. */
540 resm = method_vftbl_lookup(vftbl, m);
543 STATISTICS(jnicallXmethodnvokation());
545 i = vm_call_method_int_valist(resm, o, ap);
551 /* _Jv_jni_CallIntMethodA ******************************************************
553 Internal function to call Java integer class methods (boolean,
554 byte, char, short, int).
556 *******************************************************************************/
558 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
559 methodinfo *m, jvalue *args)
564 STATISTICS(jniinvokation());
567 exceptions_throw_nullpointerexception();
571 /* Class initialization is done by the JIT compiler. This is ok
572 since a static method always belongs to the declaring class. */
574 if (m->flags & ACC_STATIC) {
575 /* For static methods we reset the object. */
580 /* for convenience */
585 /* For instance methods we make a virtual function table lookup. */
587 resm = method_vftbl_lookup(vftbl, m);
590 STATISTICS(jnicallXmethodnvokation());
592 i = vm_call_method_int_jvalue(resm, o, args);
598 /* _Jv_jni_CallLongMethod ******************************************************
600 Internal function to call Java long methods.
602 *******************************************************************************/
604 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
605 methodinfo *m, va_list ap)
610 STATISTICS(jniinvokation());
613 exceptions_throw_nullpointerexception();
617 /* Class initialization is done by the JIT compiler. This is ok
618 since a static method always belongs to the declaring class. */
620 if (m->flags & ACC_STATIC) {
621 /* For static methods we reset the object. */
626 /* for convenience */
631 /* For instance methods we make a virtual function table lookup. */
633 resm = method_vftbl_lookup(vftbl, m);
636 STATISTICS(jnicallXmethodnvokation());
638 l = vm_call_method_long_valist(resm, o, ap);
644 /* _Jv_jni_CallFloatMethod *****************************************************
646 Internal function to call Java float methods.
648 *******************************************************************************/
650 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
651 methodinfo *m, va_list ap)
656 /* Class initialization is done by the JIT compiler. This is ok
657 since a static method always belongs to the declaring class. */
659 if (m->flags & ACC_STATIC) {
660 /* For static methods we reset the object. */
665 /* for convenience */
670 /* For instance methods we make a virtual function table lookup. */
672 resm = method_vftbl_lookup(vftbl, m);
675 STATISTICS(jnicallXmethodnvokation());
677 f = vm_call_method_float_valist(resm, o, ap);
683 /* _Jv_jni_CallDoubleMethod ****************************************************
685 Internal function to call Java double methods.
687 *******************************************************************************/
689 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
690 methodinfo *m, va_list ap)
695 /* Class initialization is done by the JIT compiler. This is ok
696 since a static method always belongs to the declaring class. */
698 if (m->flags & ACC_STATIC) {
699 /* For static methods we reset the object. */
704 /* for convenience */
709 /* For instance methods we make a virtual function table lookup. */
711 resm = method_vftbl_lookup(vftbl, m);
714 d = vm_call_method_double_valist(resm, o, ap);
720 /* _Jv_jni_CallVoidMethod ******************************************************
722 Internal function to call Java void methods.
724 *******************************************************************************/
726 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
727 methodinfo *m, va_list ap)
732 exceptions_throw_nullpointerexception();
736 /* Class initialization is done by the JIT compiler. This is ok
737 since a static method always belongs to the declaring class. */
739 if (m->flags & ACC_STATIC) {
740 /* For static methods we reset the object. */
745 /* for convenience */
750 /* For instance methods we make a virtual function table lookup. */
752 resm = method_vftbl_lookup(vftbl, m);
755 STATISTICS(jnicallXmethodnvokation());
757 (void) vm_call_method_valist(resm, o, ap);
761 /* _Jv_jni_CallVoidMethodA *****************************************************
763 Internal function to call Java void methods.
765 *******************************************************************************/
767 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
768 methodinfo *m, jvalue *args)
773 exceptions_throw_nullpointerexception();
777 /* Class initialization is done by the JIT compiler. This is ok
778 since a static method always belongs to the declaring class. */
780 if (m->flags & ACC_STATIC) {
781 /* For static methods we reset the object. */
786 /* for convenience */
791 /* For instance methods we make a virtual function table lookup. */
793 resm = method_vftbl_lookup(vftbl, m);
796 STATISTICS(jnicallXmethodnvokation());
798 (void) vm_call_method_jvalue(resm, o, args);
802 /* _Jv_jni_invokeNative ********************************************************
804 Invoke a method on the given object with the given arguments.
806 For instance methods OBJ must be != NULL and the method is looked up
807 in the vftbl of the object.
809 For static methods, OBJ is ignored.
811 *******************************************************************************/
813 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
814 java_objectarray *params)
818 java_objectheader *ro;
823 exceptions_throw_nullpointerexception();
827 argcount = m->parseddesc->paramcount;
828 paramcount = argcount;
830 /* if method is non-static, remove the `this' pointer */
832 if (!(m->flags & ACC_STATIC))
835 /* For instance methods the object has to be an instance of the
836 class the method belongs to. For static methods the obj
837 parameter is ignored. */
839 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
840 exceptions_throw_illegalargumentexception();
844 /* check if we got the right number of arguments */
846 if (((params == NULL) && (paramcount != 0)) ||
847 (params && (params->header.size != paramcount)))
849 exceptions_throw_illegalargumentexception();
853 /* for instance methods we need an object */
855 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
856 /* XXX not sure if that is the correct exception */
857 exceptions_throw_nullpointerexception();
861 /* for static methods, zero object to make subsequent code simpler */
862 if (m->flags & ACC_STATIC)
866 /* for instance methods we must do a vftbl lookup */
867 resm = method_vftbl_lookup(o->vftbl, m);
870 /* for static methods, just for convenience */
874 vmargs = MNEW(vm_arg, argcount);
876 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params))
879 switch (resm->parseddesc->returntype.decltype) {
881 (void) vm_call_method_vmarg(resm, argcount, vmargs);
886 case PRIMITIVETYPE_BOOLEAN: {
888 java_lang_Boolean *bo;
890 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
892 ro = builtin_new(class_java_lang_Boolean);
894 /* setting the value of the object direct */
896 bo = (java_lang_Boolean *) ro;
901 case PRIMITIVETYPE_BYTE: {
905 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
907 ro = builtin_new(class_java_lang_Byte);
909 /* setting the value of the object direct */
911 bo = (java_lang_Byte *) ro;
916 case PRIMITIVETYPE_CHAR: {
918 java_lang_Character *co;
920 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
922 ro = builtin_new(class_java_lang_Character);
924 /* setting the value of the object direct */
926 co = (java_lang_Character *) ro;
931 case PRIMITIVETYPE_SHORT: {
935 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
937 ro = builtin_new(class_java_lang_Short);
939 /* setting the value of the object direct */
941 so = (java_lang_Short *) ro;
946 case PRIMITIVETYPE_INT: {
948 java_lang_Integer *io;
950 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
952 ro = builtin_new(class_java_lang_Integer);
954 /* setting the value of the object direct */
956 io = (java_lang_Integer *) ro;
961 case PRIMITIVETYPE_LONG: {
965 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
967 ro = builtin_new(class_java_lang_Long);
969 /* setting the value of the object direct */
971 lo = (java_lang_Long *) ro;
976 case PRIMITIVETYPE_FLOAT: {
980 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
982 ro = builtin_new(class_java_lang_Float);
984 /* setting the value of the object direct */
986 fo = (java_lang_Float *) ro;
991 case PRIMITIVETYPE_DOUBLE: {
993 java_lang_Double *_do;
995 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
997 ro = builtin_new(class_java_lang_Double);
999 /* setting the value of the object direct */
1001 _do = (java_lang_Double *) ro;
1007 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1011 /* if this happens the exception has already been set by
1012 fill_callblock_from_objectarray */
1014 MFREE(vmargs, vm_arg, argcount);
1019 MFREE(vmargs, vm_arg, argcount);
1021 if (*exceptionptr) {
1022 java_objectheader *cause;
1024 /* clear exception pointer, we are calling JIT code again */
1026 cause = exceptions_get_and_clear_exception();
1028 exceptions_throw_invocationtargetexception(cause);
1035 /* GetVersion ******************************************************************
1037 Returns the major version number in the higher 16 bits and the
1038 minor version number in the lower 16 bits.
1040 *******************************************************************************/
1042 jint _Jv_JNI_GetVersion(JNIEnv *env)
1044 STATISTICS(jniinvokation());
1046 /* we support JNI 1.4 */
1048 return JNI_VERSION_1_4;
1052 /* Class Operations ***********************************************************/
1054 /* DefineClass *****************************************************************
1056 Loads a class from a buffer of raw class data. The buffer
1057 containing the raw class data is not referenced by the VM after the
1058 DefineClass call returns, and it may be discarded if desired.
1060 *******************************************************************************/
1062 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1063 const jbyte *buf, jsize bufLen)
1065 java_lang_ClassLoader *cl;
1066 java_lang_String *s;
1070 STATISTICS(jniinvokation());
1072 cl = (java_lang_ClassLoader *) loader;
1073 s = javastring_new_from_utf_string(name);
1074 ba = (java_bytearray *) buf;
1076 c = (jclass) Java_java_lang_VMClassLoader_defineClass(env, NULL, cl, s, ba,
1079 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1083 /* FindClass *******************************************************************
1085 This function loads a locally-defined class. It searches the
1086 directories and zip files specified by the CLASSPATH environment
1087 variable for the class with the specified name.
1089 *******************************************************************************/
1091 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1097 STATISTICS(jniinvokation());
1099 u = utf_new_char_classname((char *) name);
1101 /* Check stacktrace for classloader, if one found use it,
1102 otherwise use the system classloader. */
1104 /* Quote from the JNI documentation:
1106 In the Java 2 Platform, FindClass locates the class loader
1107 associated with the current native method. If the native code
1108 belongs to a system class, no class loader will be
1109 involved. Otherwise, the proper class loader will be invoked to
1110 load and link the named class. When FindClass is called through
1111 the Invocation Interface, there is no current native method or
1112 its associated class loader. In that case, the result of
1113 ClassLoader.getBaseClassLoader is used." */
1115 cc = stacktrace_getCurrentClass();
1118 c = load_class_from_sysloader(u);
1120 c = load_class_from_classloader(u, cc->classloader);
1128 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1132 /* GetSuperclass ***************************************************************
1134 If clazz represents any class other than the class Object, then
1135 this function returns the object that represents the superclass of
1136 the class specified by clazz.
1138 *******************************************************************************/
1140 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1144 STATISTICS(jniinvokation());
1146 c = ((classinfo *) sub)->super.cls;
1151 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1155 /* IsAssignableFrom ************************************************************
1157 Determines whether an object of sub can be safely cast to sup.
1159 *******************************************************************************/
1161 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1163 STATISTICS(jniinvokation());
1165 return Java_java_lang_VMClass_isAssignableFrom(env,
1167 (java_lang_Class *) sup,
1168 (java_lang_Class *) sub);
1172 /* Throw ***********************************************************************
1174 Causes a java.lang.Throwable object to be thrown.
1176 *******************************************************************************/
1178 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1180 STATISTICS(jniinvokation());
1182 *exceptionptr = (java_objectheader *) obj;
1188 /* ThrowNew ********************************************************************
1190 Constructs an exception object from the specified class with the
1191 message specified by message and causes that exception to be
1194 *******************************************************************************/
1196 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1199 java_objectheader *o;
1200 java_objectheader *s;
1202 STATISTICS(jniinvokation());
1204 c = (classinfo *) clazz;
1205 s = javastring_new_from_utf_string(msg);
1207 /* instantiate exception object */
1209 o = native_new_and_init_string(c, s);
1214 exceptions_set_exception(o);
1220 /* ExceptionOccurred ***********************************************************
1222 Determines if an exception is being thrown. The exception stays
1223 being thrown until either the native code calls ExceptionClear(),
1224 or the Java code handles the exception.
1226 *******************************************************************************/
1228 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1230 java_objectheader *e;
1232 STATISTICS(jniinvokation());
1236 return _Jv_JNI_NewLocalRef(env, (jthrowable) e);
1240 /* ExceptionDescribe ***********************************************************
1242 Prints an exception and a backtrace of the stack to a system
1243 error-reporting channel, such as stderr. This is a convenience
1244 routine provided for debugging.
1246 *******************************************************************************/
1248 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1250 java_objectheader *e;
1253 STATISTICS(jniinvokation());
1258 /* clear exception, because we are calling jit code again */
1260 *exceptionptr = NULL;
1262 /* get printStackTrace method from exception class */
1264 m = class_resolveclassmethod(e->vftbl->class,
1265 utf_printStackTrace,
1271 /* XXX what should we do? */
1274 /* print the stacktrace */
1276 (void) vm_call_method(m, e);
1281 /* ExceptionClear **************************************************************
1283 Clears any exception that is currently being thrown. If no
1284 exception is currently being thrown, this routine has no effect.
1286 *******************************************************************************/
1288 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1290 STATISTICS(jniinvokation());
1292 *exceptionptr = NULL;
1296 /* FatalError ******************************************************************
1298 Raises a fatal error and does not expect the VM to recover. This
1299 function does not return.
1301 *******************************************************************************/
1303 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1305 STATISTICS(jniinvokation());
1307 /* this seems to be the best way */
1313 /* PushLocalFrame **************************************************************
1315 Creates a new local reference frame, in which at least a given
1316 number of local references can be created.
1318 *******************************************************************************/
1320 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1323 localref_table *lrt;
1324 localref_table *nlrt;
1326 STATISTICS(jniinvokation());
1331 /* Allocate new local reference table on Java heap. Calculate the
1332 additional memory we have to allocate. */
1334 if (capacity > LOCALREFTABLE_CAPACITY)
1335 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1339 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1344 /* get current local reference table from thread */
1346 lrt = LOCALREFTABLE;
1348 /* Set up the new local reference table and add it to the local
1351 nlrt->capacity = capacity;
1353 nlrt->localframes = lrt->localframes + 1;
1356 /* store new local reference table in thread */
1358 LOCALREFTABLE = nlrt;
1364 /* PopLocalFrame ***************************************************************
1366 Pops off the current local reference frame, frees all the local
1367 references, and returns a local reference in the previous local
1368 reference frame for the given result object.
1370 *******************************************************************************/
1372 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1374 localref_table *lrt;
1375 localref_table *plrt;
1378 STATISTICS(jniinvokation());
1380 /* get current local reference table from thread */
1382 lrt = LOCALREFTABLE;
1384 localframes = lrt->localframes;
1386 /* Don't delete the top local frame, as this one is allocated in
1387 the native stub on the stack and is freed automagically on
1390 if (localframes == 1)
1391 return _Jv_JNI_NewLocalRef(env, result);
1393 /* release all current local frames */
1395 for (; localframes >= 1; localframes--) {
1396 /* get previous frame */
1400 /* clear all reference entries */
1402 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1406 /* set new local references table */
1411 /* store new local reference table in thread */
1413 LOCALREFTABLE = lrt;
1415 /* add local reference and return the value */
1417 return _Jv_JNI_NewLocalRef(env, result);
1421 /* DeleteLocalRef **************************************************************
1423 Deletes the local reference pointed to by localRef.
1425 *******************************************************************************/
1427 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1429 java_objectheader *o;
1430 localref_table *lrt;
1433 STATISTICS(jniinvokation());
1435 o = (java_objectheader *) localRef;
1437 /* get local reference table (thread specific) */
1439 lrt = LOCALREFTABLE;
1441 /* go through all local frames */
1443 for (; lrt != NULL; lrt = lrt->prev) {
1445 /* and try to remove the reference */
1447 for (i = 0; i < lrt->capacity; i++) {
1448 if (lrt->refs[i] == o) {
1449 lrt->refs[i] = NULL;
1457 /* this should not happen */
1459 /* if (opt_checkjni) */
1460 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1461 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1465 /* IsSameObject ****************************************************************
1467 Tests whether two references refer to the same Java object.
1469 *******************************************************************************/
1471 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1473 STATISTICS(jniinvokation());
1482 /* NewLocalRef *****************************************************************
1484 Creates a new local reference that refers to the same object as ref.
1486 *******************************************************************************/
1488 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1490 localref_table *lrt;
1493 STATISTICS(jniinvokation());
1498 /* get local reference table (thread specific) */
1500 lrt = LOCALREFTABLE;
1502 /* Check if we have space for the requested reference? No,
1503 allocate a new frame. This is actually not what the spec says,
1504 but for compatibility reasons... */
1506 if (lrt->used == lrt->capacity) {
1507 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1510 /* get the new local reference table */
1512 lrt = LOCALREFTABLE;
1515 /* insert the reference */
1517 for (i = 0; i < lrt->capacity; i++) {
1518 if (lrt->refs[i] == NULL) {
1519 lrt->refs[i] = (java_objectheader *) ref;
1526 /* should not happen, just to be sure */
1530 /* keep compiler happy */
1536 /* EnsureLocalCapacity *********************************************************
1538 Ensures that at least a given number of local references can be
1539 created in the current thread
1541 *******************************************************************************/
1543 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1545 localref_table *lrt;
1547 log_text("JNI-Call: EnsureLocalCapacity");
1549 STATISTICS(jniinvokation());
1551 /* get local reference table (thread specific) */
1553 lrt = LOCALREFTABLE;
1555 /* check if capacity elements are available in the local references table */
1557 if ((lrt->used + capacity) > lrt->capacity)
1558 return _Jv_JNI_PushLocalFrame(env, capacity);
1564 /* AllocObject *****************************************************************
1566 Allocates a new Java object without invoking any of the
1567 constructors for the object. Returns a reference to the object.
1569 *******************************************************************************/
1571 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1574 java_objectheader *o;
1576 STATISTICS(jniinvokation());
1578 c = (classinfo *) clazz;
1580 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1581 exceptions_throw_instantiationexception(c);
1587 return _Jv_JNI_NewLocalRef(env, o);
1591 /* NewObject *******************************************************************
1593 Programmers place all arguments that are to be passed to the
1594 constructor immediately following the methodID
1595 argument. NewObject() accepts these arguments and passes them to
1596 the Java method that the programmer wishes to invoke.
1598 *******************************************************************************/
1600 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1602 java_objectheader *o;
1606 STATISTICS(jniinvokation());
1608 m = (methodinfo *) methodID;
1612 o = builtin_new(clazz);
1617 /* call constructor */
1619 va_start(ap, methodID);
1620 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1623 return _Jv_JNI_NewLocalRef(env, o);
1627 /* NewObjectV ******************************************************************
1629 Programmers place all arguments that are to be passed to the
1630 constructor in an args argument of type va_list that immediately
1631 follows the methodID argument. NewObjectV() accepts these
1632 arguments, and, in turn, passes them to the Java method that the
1633 programmer wishes to invoke.
1635 *******************************************************************************/
1637 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1640 java_objectheader *o;
1643 STATISTICS(jniinvokation());
1645 m = (methodinfo *) methodID;
1649 o = builtin_new(clazz);
1654 /* call constructor */
1656 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1658 return _Jv_JNI_NewLocalRef(env, o);
1662 /* NewObjectA *****************************************************************
1664 Programmers place all arguments that are to be passed to the
1665 constructor in an args array of jvalues that immediately follows
1666 the methodID argument. NewObjectA() accepts the arguments in this
1667 array, and, in turn, passes them to the Java method that the
1668 programmer wishes to invoke.
1670 *******************************************************************************/
1672 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1675 java_objectheader *o;
1678 STATISTICS(jniinvokation());
1680 m = (methodinfo *) methodID;
1684 o = builtin_new(clazz);
1689 /* call constructor */
1691 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1693 return _Jv_JNI_NewLocalRef(env, o);
1697 /* GetObjectClass **************************************************************
1699 Returns the class of an object.
1701 *******************************************************************************/
1703 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1705 java_objectheader *o;
1708 STATISTICS(jniinvokation());
1710 o = (java_objectheader *) obj;
1712 if ((o == NULL) || (o->vftbl == NULL))
1715 c = o->vftbl->class;
1717 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1721 /* IsInstanceOf ****************************************************************
1723 Tests whether an object is an instance of a class.
1725 *******************************************************************************/
1727 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1729 STATISTICS(jniinvokation());
1731 return Java_java_lang_VMClass_isInstance(env,
1733 (java_lang_Class *) clazz,
1734 (java_lang_Object *) obj);
1738 /* Reflection Support *********************************************************/
1740 /* FromReflectedMethod *********************************************************
1742 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1743 object to a method ID.
1745 *******************************************************************************/
1747 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1753 STATISTICS(jniinvokation());
1758 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1759 java_lang_reflect_Method *rm;
1761 rm = (java_lang_reflect_Method *) method;
1762 c = (classinfo *) (rm->declaringClass);
1765 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1766 java_lang_reflect_Constructor *rc;
1768 rc = (java_lang_reflect_Constructor *) method;
1769 c = (classinfo *) (rc->clazz);
1775 mi = &(c->methods[slot]);
1777 return (jmethodID) mi;
1781 /* FromReflectedField **********************************************************
1783 Converts a java.lang.reflect.Field to a field ID.
1785 *******************************************************************************/
1787 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1789 java_lang_reflect_Field *rf;
1793 STATISTICS(jniinvokation());
1795 rf = (java_lang_reflect_Field *) field;
1800 c = (classinfo *) rf->declaringClass;
1802 f = &(c->fields[rf->slot]);
1804 return (jfieldID) f;
1808 /* ToReflectedMethod ***********************************************************
1810 Converts a method ID derived from cls to an instance of the
1811 java.lang.reflect.Method class or to an instance of the
1812 java.lang.reflect.Constructor class.
1814 *******************************************************************************/
1816 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1819 STATISTICS(jniinvokation());
1821 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1827 /* ToReflectedField ************************************************************
1829 Converts a field ID derived from cls to an instance of the
1830 java.lang.reflect.Field class.
1832 *******************************************************************************/
1834 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1837 STATISTICS(jniinvokation());
1839 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1845 /* Calling Instance Methods ***************************************************/
1847 /* GetMethodID *****************************************************************
1849 Returns the method ID for an instance (nonstatic) method of a class
1850 or interface. The method may be defined in one of the clazz's
1851 superclasses and inherited by clazz. The method is determined by
1852 its name and signature.
1854 GetMethodID() causes an uninitialized class to be initialized.
1856 *******************************************************************************/
1858 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1866 STATISTICS(jniinvokation());
1868 c = (classinfo *) clazz;
1873 if (!(c->state & CLASS_INITIALIZED))
1874 if (!initialize_class(c))
1877 /* try to get the method of the class or one of it's superclasses */
1879 uname = utf_new_char((char *) name);
1880 udesc = utf_new_char((char *) sig);
1882 m = class_resolvemethod(clazz, uname, udesc);
1884 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1885 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1890 return (jmethodID) m;
1894 /* JNI-functions for calling instance methods *********************************/
1896 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1899 java_objectheader *o;
1901 java_objectheader *ret;
1904 o = (java_objectheader *) obj;
1905 m = (methodinfo *) methodID;
1907 va_start(ap, methodID);
1908 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1911 return _Jv_JNI_NewLocalRef(env, ret);
1915 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1918 java_objectheader *o;
1920 java_objectheader *ret;
1922 o = (java_objectheader *) obj;
1923 m = (methodinfo *) methodID;
1925 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1927 return _Jv_JNI_NewLocalRef(env, ret);
1931 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1934 java_objectheader *o;
1936 java_objectheader *ret;
1938 o = (java_objectheader *) obj;
1939 m = (methodinfo *) methodID;
1941 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1943 return _Jv_JNI_NewLocalRef(env, ret);
1947 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1950 java_objectheader *o;
1955 o = (java_objectheader *) obj;
1956 m = (methodinfo *) methodID;
1958 va_start(ap, methodID);
1959 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1966 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
1967 jmethodID methodID, va_list args)
1969 java_objectheader *o;
1973 o = (java_objectheader *) obj;
1974 m = (methodinfo *) methodID;
1976 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1982 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
1983 jmethodID methodID, jvalue *args)
1985 java_objectheader *o;
1989 o = (java_objectheader *) obj;
1990 m = (methodinfo *) methodID;
1992 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1998 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2000 java_objectheader *o;
2005 o = (java_objectheader *) obj;
2006 m = (methodinfo *) methodID;
2008 va_start(ap, methodID);
2009 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2017 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2020 java_objectheader *o;
2024 o = (java_objectheader *) obj;
2025 m = (methodinfo *) methodID;
2027 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2033 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2036 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2042 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2044 java_objectheader *o;
2049 o = (java_objectheader *) obj;
2050 m = (methodinfo *) methodID;
2052 va_start(ap, methodID);
2053 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2060 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2063 java_objectheader *o;
2067 o = (java_objectheader *) obj;
2068 m = (methodinfo *) methodID;
2070 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2076 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2079 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2085 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2088 java_objectheader *o;
2093 o = (java_objectheader *) obj;
2094 m = (methodinfo *) methodID;
2096 va_start(ap, methodID);
2097 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2104 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2107 java_objectheader *o;
2111 o = (java_objectheader *) obj;
2112 m = (methodinfo *) methodID;
2114 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2120 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2123 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2130 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2132 java_objectheader *o;
2137 o = (java_objectheader *) obj;
2138 m = (methodinfo *) methodID;
2140 va_start(ap, methodID);
2141 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2148 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2151 java_objectheader *o;
2155 o = (java_objectheader *) obj;
2156 m = (methodinfo *) methodID;
2158 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2164 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2167 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2174 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2176 java_objectheader *o;
2181 o = (java_objectheader *) obj;
2182 m = (methodinfo *) methodID;
2184 va_start(ap, methodID);
2185 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2192 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2195 java_objectheader *o;
2199 o = (java_objectheader *) obj;
2200 m = (methodinfo *) methodID;
2202 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2208 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2211 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2218 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2221 java_objectheader *o;
2226 o = (java_objectheader *) obj;
2227 m = (methodinfo *) methodID;
2229 va_start(ap, methodID);
2230 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2237 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2240 java_objectheader *o;
2244 o = (java_objectheader *) obj;
2245 m = (methodinfo *) methodID;
2247 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2253 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2256 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2263 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2266 java_objectheader *o;
2271 o = (java_objectheader *) obj;
2272 m = (methodinfo *) methodID;
2274 va_start(ap, methodID);
2275 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2282 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2285 java_objectheader *o;
2289 o = (java_objectheader *) obj;
2290 m = (methodinfo *) methodID;
2292 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2298 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2301 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2308 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2310 java_objectheader *o;
2314 o = (java_objectheader *) obj;
2315 m = (methodinfo *) methodID;
2317 va_start(ap, methodID);
2318 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2323 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2326 java_objectheader *o;
2329 o = (java_objectheader *) obj;
2330 m = (methodinfo *) methodID;
2332 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2336 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2339 java_objectheader *o;
2342 o = (java_objectheader *) obj;
2343 m = (methodinfo *) methodID;
2345 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2350 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2351 jclass clazz, jmethodID methodID,
2354 java_objectheader *o;
2357 java_objectheader *r;
2360 o = (java_objectheader *) obj;
2361 c = (classinfo *) clazz;
2362 m = (methodinfo *) methodID;
2364 va_start(ap, methodID);
2365 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2368 return _Jv_JNI_NewLocalRef(env, r);
2372 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2373 jclass clazz, jmethodID methodID,
2376 java_objectheader *o;
2379 java_objectheader *r;
2381 o = (java_objectheader *) obj;
2382 c = (classinfo *) clazz;
2383 m = (methodinfo *) methodID;
2385 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2387 return _Jv_JNI_NewLocalRef(env, r);
2391 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2392 jclass clazz, jmethodID methodID,
2395 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2397 return _Jv_JNI_NewLocalRef(env, NULL);
2402 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2403 jclass clazz, jmethodID methodID,
2406 java_objectheader *o;
2412 o = (java_objectheader *) obj;
2413 c = (classinfo *) clazz;
2414 m = (methodinfo *) methodID;
2416 va_start(ap, methodID);
2417 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2424 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2425 jclass clazz, jmethodID methodID,
2428 java_objectheader *o;
2433 o = (java_objectheader *) obj;
2434 c = (classinfo *) clazz;
2435 m = (methodinfo *) methodID;
2437 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2443 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2444 jclass clazz, jmethodID methodID,
2447 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2453 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2454 jmethodID methodID, ...)
2456 java_objectheader *o;
2462 o = (java_objectheader *) obj;
2463 c = (classinfo *) clazz;
2464 m = (methodinfo *) methodID;
2466 va_start(ap, methodID);
2467 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2474 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2475 jmethodID methodID, va_list args)
2477 java_objectheader *o;
2482 o = (java_objectheader *) obj;
2483 c = (classinfo *) clazz;
2484 m = (methodinfo *) methodID;
2486 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2492 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2493 jmethodID methodID, jvalue *args)
2495 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2502 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2503 jmethodID methodID, ...)
2505 java_objectheader *o;
2511 o = (java_objectheader *) obj;
2512 c = (classinfo *) clazz;
2513 m = (methodinfo *) methodID;
2515 va_start(ap, methodID);
2516 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2523 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2524 jmethodID methodID, va_list args)
2526 java_objectheader *o;
2531 o = (java_objectheader *) obj;
2532 c = (classinfo *) clazz;
2533 m = (methodinfo *) methodID;
2535 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2541 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2542 jmethodID methodID, jvalue *args)
2544 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2551 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2552 jclass clazz, jmethodID methodID, ...)
2554 java_objectheader *o;
2560 o = (java_objectheader *) obj;
2561 c = (classinfo *) clazz;
2562 m = (methodinfo *) methodID;
2564 va_start(ap, methodID);
2565 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2572 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2573 jclass clazz, jmethodID methodID,
2576 java_objectheader *o;
2581 o = (java_objectheader *) obj;
2582 c = (classinfo *) clazz;
2583 m = (methodinfo *) methodID;
2585 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2591 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2592 jclass clazz, jmethodID methodID,
2595 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2602 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2603 jmethodID methodID, ...)
2605 java_objectheader *o;
2611 o = (java_objectheader *) obj;
2612 c = (classinfo *) clazz;
2613 m = (methodinfo *) methodID;
2615 va_start(ap, methodID);
2616 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2623 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2624 jmethodID methodID, va_list args)
2626 java_objectheader *o;
2631 o = (java_objectheader *) obj;
2632 c = (classinfo *) clazz;
2633 m = (methodinfo *) methodID;
2635 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2641 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2642 jmethodID methodID, jvalue *args)
2644 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2651 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2652 jmethodID methodID, ...)
2654 java_objectheader *o;
2660 o = (java_objectheader *) obj;
2661 c = (classinfo *) clazz;
2662 m = (methodinfo *) methodID;
2664 va_start(ap, methodID);
2665 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2672 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2673 jmethodID methodID, va_list args)
2675 java_objectheader *o;
2680 o = (java_objectheader *) obj;
2681 c = (classinfo *) clazz;
2682 m = (methodinfo *) methodID;
2684 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2690 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2691 jmethodID methodID, jvalue *args)
2693 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2700 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2701 jclass clazz, jmethodID methodID, ...)
2703 java_objectheader *o;
2709 o = (java_objectheader *) obj;
2710 c = (classinfo *) clazz;
2711 m = (methodinfo *) methodID;
2713 va_start(ap, methodID);
2714 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2721 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2722 jclass clazz, jmethodID methodID,
2725 java_objectheader *o;
2730 o = (java_objectheader *) obj;
2731 c = (classinfo *) clazz;
2732 m = (methodinfo *) methodID;
2734 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2740 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2741 jclass clazz, jmethodID methodID,
2744 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2751 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2752 jclass clazz, jmethodID methodID,
2755 java_objectheader *o;
2761 o = (java_objectheader *) obj;
2762 c = (classinfo *) clazz;
2763 m = (methodinfo *) methodID;
2765 va_start(ap, methodID);
2766 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2773 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2774 jclass clazz, jmethodID methodID,
2777 java_objectheader *o;
2782 o = (java_objectheader *) obj;
2783 c = (classinfo *) clazz;
2784 m = (methodinfo *) methodID;
2786 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2792 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2793 jclass clazz, jmethodID methodID,
2796 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2803 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2804 jmethodID methodID, ...)
2806 java_objectheader *o;
2811 o = (java_objectheader *) obj;
2812 c = (classinfo *) clazz;
2813 m = (methodinfo *) methodID;
2815 va_start(ap, methodID);
2816 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2821 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2822 jmethodID methodID, va_list args)
2824 java_objectheader *o;
2828 o = (java_objectheader *) obj;
2829 c = (classinfo *) clazz;
2830 m = (methodinfo *) methodID;
2832 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2836 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2837 jmethodID methodID, jvalue * args)
2839 java_objectheader *o;
2843 o = (java_objectheader *) obj;
2844 c = (classinfo *) clazz;
2845 m = (methodinfo *) methodID;
2847 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2851 /* Accessing Fields of Objects ************************************************/
2853 /* GetFieldID ******************************************************************
2855 Returns the field ID for an instance (nonstatic) field of a
2856 class. The field is specified by its name and signature. The
2857 Get<type>Field and Set<type>Field families of accessor functions
2858 use field IDs to retrieve object fields.
2860 *******************************************************************************/
2862 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2870 STATISTICS(jniinvokation());
2872 c = (classinfo *) clazz;
2874 uname = utf_new_char((char *) name);
2875 udesc = utf_new_char((char *) sig);
2877 f = class_findfield(clazz, uname, udesc);
2880 exceptions_throw_nosuchfielderror(c, uname);
2882 return (jfieldID) f;
2886 /* Get<type>Field Routines *****************************************************
2888 This family of accessor routines returns the value of an instance
2889 (nonstatic) field of an object. The field to access is specified by
2890 a field ID obtained by calling GetFieldID().
2892 *******************************************************************************/
2894 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2896 java_objectheader *o;
2898 STATISTICS(jniinvokation());
2900 o = GET_FIELD(obj, java_objectheader*, fieldID);
2902 return _Jv_JNI_NewLocalRef(env, o);
2906 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2910 STATISTICS(jniinvokation());
2912 i = GET_FIELD(obj, s4, fieldID);
2914 return (jboolean) i;
2918 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2922 STATISTICS(jniinvokation());
2924 i = GET_FIELD(obj, s4, fieldID);
2930 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2934 STATISTICS(jniinvokation());
2936 i = GET_FIELD(obj, s4, fieldID);
2942 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2946 STATISTICS(jniinvokation());
2948 i = GET_FIELD(obj, s4, fieldID);
2954 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2956 java_objectheader *o;
2960 STATISTICS(jniinvokation());
2962 o = (java_objectheader *) obj;
2963 f = (fieldinfo *) fieldID;
2965 i = GET_FIELD(o, s4, f);
2971 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2975 STATISTICS(jniinvokation());
2977 l = GET_FIELD(obj, s8, fieldID);
2983 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2987 STATISTICS(jniinvokation());
2989 f = GET_FIELD(obj, float, fieldID);
2995 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2999 STATISTICS(jniinvokation());
3001 d = GET_FIELD(obj, double, fieldID);
3007 /* Set<type>Field Routines *****************************************************
3009 This family of accessor routines sets the value of an instance
3010 (nonstatic) field of an object. The field to access is specified by
3011 a field ID obtained by calling GetFieldID().
3013 *******************************************************************************/
3015 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3018 STATISTICS(jniinvokation());
3020 SET_FIELD(obj, java_objectheader*, fieldID, value);
3024 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3027 STATISTICS(jniinvokation());
3029 SET_FIELD(obj, s4, fieldID, value);
3033 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3036 STATISTICS(jniinvokation());
3038 SET_FIELD(obj, s4, fieldID, value);
3042 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3045 STATISTICS(jniinvokation());
3047 SET_FIELD(obj, s4, fieldID, value);
3051 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3054 STATISTICS(jniinvokation());
3056 SET_FIELD(obj, s4, fieldID, value);
3060 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3062 STATISTICS(jniinvokation());
3064 SET_FIELD(obj, s4, fieldID, value);
3068 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3071 STATISTICS(jniinvokation());
3073 SET_FIELD(obj, s8, fieldID, value);
3077 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3080 STATISTICS(jniinvokation());
3082 SET_FIELD(obj, float, fieldID, value);
3086 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3089 STATISTICS(jniinvokation());
3091 SET_FIELD(obj, double, fieldID, value);
3095 /* Calling Static Methods *****************************************************/
3097 /* GetStaticMethodID ***********************************************************
3099 Returns the method ID for a static method of a class. The method is
3100 specified by its name and signature.
3102 GetStaticMethodID() causes an uninitialized class to be
3105 *******************************************************************************/
3107 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3115 STATISTICS(jniinvokation());
3117 c = (classinfo *) clazz;
3122 if (!(c->state & CLASS_INITIALIZED))
3123 if (!initialize_class(c))
3126 /* try to get the static method of the class */
3128 uname = utf_new_char((char *) name);
3129 udesc = utf_new_char((char *) sig);
3131 m = class_resolvemethod(c, uname, udesc);
3133 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3134 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3139 return (jmethodID) m;
3143 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3144 jmethodID methodID, ...)
3147 java_objectheader *o;
3150 m = (methodinfo *) methodID;
3152 va_start(ap, methodID);
3153 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3156 return _Jv_JNI_NewLocalRef(env, o);
3160 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3161 jmethodID methodID, va_list args)
3164 java_objectheader *o;
3166 m = (methodinfo *) methodID;
3168 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3170 return _Jv_JNI_NewLocalRef(env, o);
3174 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3175 jmethodID methodID, jvalue *args)
3178 java_objectheader *o;
3180 m = (methodinfo *) methodID;
3182 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3184 return _Jv_JNI_NewLocalRef(env, o);
3188 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3189 jmethodID methodID, ...)
3195 m = (methodinfo *) methodID;
3197 va_start(ap, methodID);
3198 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3205 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3206 jmethodID methodID, va_list args)
3211 m = (methodinfo *) methodID;
3213 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3219 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3220 jmethodID methodID, jvalue *args)
3222 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3228 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3229 jmethodID methodID, ...)
3235 m = (methodinfo *) methodID;
3237 va_start(ap, methodID);
3238 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3245 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3246 jmethodID methodID, va_list args)
3251 m = (methodinfo *) methodID;
3253 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3259 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3260 jmethodID methodID, jvalue *args)
3262 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3268 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3269 jmethodID methodID, ...)
3275 m = (methodinfo *) methodID;
3277 va_start(ap, methodID);
3278 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3285 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3286 jmethodID methodID, va_list args)
3291 m = (methodinfo *) methodID;
3293 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3299 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3300 jmethodID methodID, jvalue *args)
3302 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3308 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3309 jmethodID methodID, ...)
3315 m = (methodinfo *) methodID;
3317 va_start(ap, methodID);
3318 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3325 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3326 jmethodID methodID, va_list args)
3331 m = (methodinfo *) methodID;
3333 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3339 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3340 jmethodID methodID, jvalue *args)
3342 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3348 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3355 m = (methodinfo *) methodID;
3357 va_start(ap, methodID);
3358 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3365 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3366 jmethodID methodID, va_list args)
3371 m = (methodinfo *) methodID;
3373 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3379 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3380 jmethodID methodID, jvalue *args)
3382 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3388 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3389 jmethodID methodID, ...)
3395 m = (methodinfo *) methodID;
3397 va_start(ap, methodID);
3398 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3405 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3406 jmethodID methodID, va_list args)
3411 m = (methodinfo *) methodID;
3413 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3419 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3420 jmethodID methodID, jvalue *args)
3422 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3429 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3430 jmethodID methodID, ...)
3436 m = (methodinfo *) methodID;
3438 va_start(ap, methodID);
3439 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3446 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3447 jmethodID methodID, va_list args)
3452 m = (methodinfo *) methodID;
3454 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3460 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3461 jmethodID methodID, jvalue *args)
3463 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3469 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3470 jmethodID methodID, ...)
3476 m = (methodinfo *) methodID;
3478 va_start(ap, methodID);
3479 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3486 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3487 jmethodID methodID, va_list args)
3492 m = (methodinfo *) methodID;
3494 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3500 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3501 jmethodID methodID, jvalue *args)
3503 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3509 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3510 jmethodID methodID, ...)
3515 m = (methodinfo *) methodID;
3517 va_start(ap, methodID);
3518 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3523 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3524 jmethodID methodID, va_list args)
3528 m = (methodinfo *) methodID;
3530 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3534 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3535 jmethodID methodID, jvalue * args)
3539 m = (methodinfo *) methodID;
3541 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3545 /* Accessing Static Fields ****************************************************/
3547 /* GetStaticFieldID ************************************************************
3549 Returns the field ID for a static field of a class. The field is
3550 specified by its name and signature. The GetStatic<type>Field and
3551 SetStatic<type>Field families of accessor functions use field IDs
3552 to retrieve static fields.
3554 *******************************************************************************/
3556 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3564 STATISTICS(jniinvokation());
3566 c = (classinfo *) clazz;
3568 uname = utf_new_char((char *) name);
3569 usig = utf_new_char((char *) sig);
3571 f = class_findfield(clazz, uname, usig);
3574 exceptions_throw_nosuchfielderror(c, uname);
3576 return (jfieldID) f;
3580 /* GetStatic<type>Field ********************************************************
3582 This family of accessor routines returns the value of a static
3585 *******************************************************************************/
3587 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3593 STATISTICS(jniinvokation());
3595 c = (classinfo *) clazz;
3596 f = (fieldinfo *) fieldID;
3598 if (!(c->state & CLASS_INITIALIZED))
3599 if (!initialize_class(c))
3602 return _Jv_JNI_NewLocalRef(env, f->value.a);
3606 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3612 STATISTICS(jniinvokation());
3614 c = (classinfo *) clazz;
3615 f = (fieldinfo *) fieldID;
3617 if (!(c->state & CLASS_INITIALIZED))
3618 if (!initialize_class(c))
3625 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3630 STATISTICS(jniinvokation());
3632 c = (classinfo *) clazz;
3633 f = (fieldinfo *) fieldID;
3635 if (!(c->state & CLASS_INITIALIZED))
3636 if (!initialize_class(c))
3643 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3648 STATISTICS(jniinvokation());
3650 c = (classinfo *) clazz;
3651 f = (fieldinfo *) fieldID;
3653 if (!(c->state & CLASS_INITIALIZED))
3654 if (!initialize_class(c))
3661 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3666 STATISTICS(jniinvokation());
3668 c = (classinfo *) clazz;
3669 f = (fieldinfo *) fieldID;
3671 if (!(c->state & CLASS_INITIALIZED))
3672 if (!initialize_class(c))
3679 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3684 STATISTICS(jniinvokation());
3686 c = (classinfo *) clazz;
3687 f = (fieldinfo *) fieldID;
3689 if (!(c->state & CLASS_INITIALIZED))
3690 if (!initialize_class(c))
3697 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3702 STATISTICS(jniinvokation());
3704 c = (classinfo *) clazz;
3705 f = (fieldinfo *) fieldID;
3707 if (!(c->state & CLASS_INITIALIZED))
3708 if (!initialize_class(c))
3715 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3720 STATISTICS(jniinvokation());
3722 c = (classinfo *) clazz;
3723 f = (fieldinfo *) fieldID;
3725 if (!(c->state & CLASS_INITIALIZED))
3726 if (!initialize_class(c))
3733 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3739 STATISTICS(jniinvokation());
3741 c = (classinfo *) clazz;
3742 f = (fieldinfo *) fieldID;
3744 if (!(c->state & CLASS_INITIALIZED))
3745 if (!initialize_class(c))
3752 /* SetStatic<type>Field *******************************************************
3754 This family of accessor routines sets the value of a static field
3757 *******************************************************************************/
3759 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3765 STATISTICS(jniinvokation());
3767 c = (classinfo *) clazz;
3768 f = (fieldinfo *) fieldID;
3770 if (!(c->state & CLASS_INITIALIZED))
3771 if (!initialize_class(c))
3778 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3784 STATISTICS(jniinvokation());
3786 c = (classinfo *) clazz;
3787 f = (fieldinfo *) fieldID;
3789 if (!(c->state & CLASS_INITIALIZED))
3790 if (!initialize_class(c))
3797 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3803 STATISTICS(jniinvokation());
3805 c = (classinfo *) clazz;
3806 f = (fieldinfo *) fieldID;
3808 if (!(c->state & CLASS_INITIALIZED))
3809 if (!initialize_class(c))
3816 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3822 STATISTICS(jniinvokation());
3824 c = (classinfo *) clazz;
3825 f = (fieldinfo *) fieldID;
3827 if (!(c->state & CLASS_INITIALIZED))
3828 if (!initialize_class(c))
3835 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3841 STATISTICS(jniinvokation());
3843 c = (classinfo *) clazz;
3844 f = (fieldinfo *) fieldID;
3846 if (!(c->state & CLASS_INITIALIZED))
3847 if (!initialize_class(c))
3854 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3860 STATISTICS(jniinvokation());
3862 c = (classinfo *) clazz;
3863 f = (fieldinfo *) fieldID;
3865 if (!(c->state & CLASS_INITIALIZED))
3866 if (!initialize_class(c))
3873 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3879 STATISTICS(jniinvokation());
3881 c = (classinfo *) clazz;
3882 f = (fieldinfo *) fieldID;
3884 if (!(c->state & CLASS_INITIALIZED))
3885 if (!initialize_class(c))
3892 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3898 STATISTICS(jniinvokation());
3900 c = (classinfo *) clazz;
3901 f = (fieldinfo *) fieldID;
3903 if (!(c->state & CLASS_INITIALIZED))
3904 if (!initialize_class(c))
3911 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3917 STATISTICS(jniinvokation());
3919 c = (classinfo *) clazz;
3920 f = (fieldinfo *) fieldID;
3922 if (!(c->state & CLASS_INITIALIZED))
3923 if (!initialize_class(c))
3930 /* String Operations **********************************************************/
3932 /* NewString *******************************************************************
3934 Create new java.lang.String object from an array of Unicode
3937 *******************************************************************************/
3939 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
3941 java_lang_String *s;
3945 STATISTICS(jniinvokation());
3947 s = (java_lang_String *) builtin_new(class_java_lang_String);
3948 a = builtin_newarray_char(len);
3950 /* javastring or characterarray could not be created */
3951 if ((a == NULL) || (s == NULL))
3955 for (i = 0; i < len; i++)
3956 a->data[i] = buf[i];
3962 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
3966 static jchar emptyStringJ[]={0,0};
3968 /* GetStringLength *************************************************************
3970 Returns the length (the count of Unicode characters) of a Java
3973 *******************************************************************************/
3975 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
3977 return ((java_lang_String *) str)->count;
3981 /******************** convertes javastring to u2-array ****************************/
3983 u2 *javastring_tou2(jstring so)
3985 java_lang_String *s;
3990 STATISTICS(jniinvokation());
3992 s = (java_lang_String *) so;
4002 /* allocate memory */
4004 stringbuffer = MNEW(u2, s->count + 1);
4008 for (i = 0; i < s->count; i++)
4009 stringbuffer[i] = a->data[s->offset + i];
4011 /* terminate string */
4013 stringbuffer[i] = '\0';
4015 return stringbuffer;
4019 /* GetStringChars **************************************************************
4021 Returns a pointer to the array of Unicode characters of the
4022 string. This pointer is valid until ReleaseStringchars() is called.
4024 *******************************************************************************/
4026 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4030 STATISTICS(jniinvokation());
4032 jc = javastring_tou2(str);
4044 return emptyStringJ;
4048 /* ReleaseStringChars **********************************************************
4050 Informs the VM that the native code no longer needs access to
4051 chars. The chars argument is a pointer obtained from string using
4054 *******************************************************************************/
4056 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4058 STATISTICS(jniinvokation());
4060 if (chars == emptyStringJ)
4063 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4067 /* NewStringUTF ****************************************************************
4069 Constructs a new java.lang.String object from an array of UTF-8 characters.
4071 *******************************************************************************/
4073 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4075 java_lang_String *s;
4077 STATISTICS(jniinvokation());
4079 s = javastring_safe_new_from_utf8(bytes);
4081 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4085 /****************** returns the utf8 length in bytes of a string *******************/
4087 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4089 java_lang_String *s = (java_lang_String*) string;
4091 STATISTICS(jniinvokation());
4093 return (jsize) u2_utflength(s->value->data, s->count);
4097 /* GetStringUTFChars ***********************************************************
4099 Returns a pointer to an array of UTF-8 characters of the
4100 string. This array is valid until it is released by
4101 ReleaseStringUTFChars().
4103 *******************************************************************************/
4105 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4110 STATISTICS(jniinvokation());
4118 u = javastring_toutf((java_lang_String *) string, false);
4127 /* ReleaseStringUTFChars *******************************************************
4129 Informs the VM that the native code no longer needs access to
4130 utf. The utf argument is a pointer derived from string using
4131 GetStringUTFChars().
4133 *******************************************************************************/
4135 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4137 STATISTICS(jniinvokation());
4139 /* XXX we don't release utf chars right now, perhaps that should be done
4140 later. Since there is always one reference the garbage collector will
4145 /* Array Operations ***********************************************************/
4147 /* GetArrayLength **************************************************************
4149 Returns the number of elements in the array.
4151 *******************************************************************************/
4153 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4155 java_arrayheader *a;
4157 STATISTICS(jniinvokation());
4159 a = (java_arrayheader *) array;
4165 /* NewObjectArray **************************************************************
4167 Constructs a new array holding objects in class elementClass. All
4168 elements are initially set to initialElement.
4170 *******************************************************************************/
4172 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4173 jclass elementClass, jobject initialElement)
4175 java_objectarray *oa;
4178 STATISTICS(jniinvokation());
4181 exceptions_throw_negativearraysizeexception();
4185 oa = builtin_anewarray(length, elementClass);
4190 /* set all elements to initialElement */
4192 for (i = 0; i < length; i++)
4193 oa->data[i] = initialElement;
4195 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4199 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4202 java_objectarray *oa;
4205 STATISTICS(jniinvokation());
4207 oa = (java_objectarray *) array;
4209 if (index >= oa->header.size) {
4210 exceptions_throw_arrayindexoutofboundsexception();
4214 o = oa->data[index];
4216 return _Jv_JNI_NewLocalRef(env, o);
4220 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4221 jsize index, jobject val)
4223 java_objectarray *oa;
4224 java_objectheader *o;
4226 STATISTICS(jniinvokation());
4228 oa = (java_objectarray *) array;
4229 o = (java_objectheader *) val;
4231 if (index >= oa->header.size) {
4232 exceptions_throw_arrayindexoutofboundsexception();
4236 /* check if the class of value is a subclass of the element class
4239 if (!builtin_canstore(oa, o)) {
4240 exceptions_throw_arraystoreexception();
4244 oa->data[index] = val;
4248 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4250 java_booleanarray *ba;
4252 STATISTICS(jniinvokation());
4255 exceptions_throw_negativearraysizeexception();
4259 ba = builtin_newarray_boolean(len);
4261 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4265 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4269 STATISTICS(jniinvokation());
4272 exceptions_throw_negativearraysizeexception();
4276 ba = builtin_newarray_byte(len);
4278 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4282 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4286 STATISTICS(jniinvokation());
4289 exceptions_throw_negativearraysizeexception();
4293 ca = builtin_newarray_char(len);
4295 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4299 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4301 java_shortarray *sa;
4303 STATISTICS(jniinvokation());
4306 exceptions_throw_negativearraysizeexception();
4310 sa = builtin_newarray_short(len);
4312 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4316 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4320 STATISTICS(jniinvokation());
4323 exceptions_throw_negativearraysizeexception();
4327 ia = builtin_newarray_int(len);
4329 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4333 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4337 STATISTICS(jniinvokation());
4340 exceptions_throw_negativearraysizeexception();
4344 la = builtin_newarray_long(len);
4346 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4350 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4352 java_floatarray *fa;
4354 STATISTICS(jniinvokation());
4357 exceptions_throw_negativearraysizeexception();
4361 fa = builtin_newarray_float(len);
4363 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4367 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4369 java_doublearray *da;
4371 STATISTICS(jniinvokation());
4374 exceptions_throw_negativearraysizeexception();
4378 da = builtin_newarray_double(len);
4380 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4384 /* Get<PrimitiveType>ArrayElements *********************************************
4386 A family of functions that returns the body of the primitive array.
4388 *******************************************************************************/
4390 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4393 java_booleanarray *ba;
4395 STATISTICS(jniinvokation());
4397 ba = (java_booleanarray *) array;
4400 *isCopy = JNI_FALSE;
4406 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4411 STATISTICS(jniinvokation());
4413 ba = (java_bytearray *) array;
4416 *isCopy = JNI_FALSE;
4422 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4427 STATISTICS(jniinvokation());
4429 ca = (java_chararray *) array;
4432 *isCopy = JNI_FALSE;
4438 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4441 java_shortarray *sa;
4443 STATISTICS(jniinvokation());
4445 sa = (java_shortarray *) array;
4448 *isCopy = JNI_FALSE;
4454 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4459 STATISTICS(jniinvokation());
4461 ia = (java_intarray *) array;
4464 *isCopy = JNI_FALSE;
4470 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4475 STATISTICS(jniinvokation());
4477 la = (java_longarray *) array;
4480 *isCopy = JNI_FALSE;
4482 /* We cast this one to prevent a compiler warning on 64-bit
4483 systems since GNU Classpath typedef jlong to long long. */
4485 return (jlong *) la->data;
4489 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4492 java_floatarray *fa;
4494 STATISTICS(jniinvokation());
4496 fa = (java_floatarray *) array;
4499 *isCopy = JNI_FALSE;
4505 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4508 java_doublearray *da;
4510 STATISTICS(jniinvokation());
4512 da = (java_doublearray *) array;
4515 *isCopy = JNI_FALSE;
4521 /* Release<PrimitiveType>ArrayElements *****************************************
4523 A family of functions that informs the VM that the native code no
4524 longer needs access to elems. The elems argument is a pointer
4525 derived from array using the corresponding
4526 Get<PrimitiveType>ArrayElements() function. If necessary, this
4527 function copies back all changes made to elems to the original
4530 *******************************************************************************/
4532 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4533 jboolean *elems, jint mode)
4535 java_booleanarray *ba;
4537 STATISTICS(jniinvokation());
4539 ba = (java_booleanarray *) array;
4541 if (elems != ba->data) {
4544 MCOPY(ba->data, elems, u1, ba->header.size);
4547 MCOPY(ba->data, elems, u1, ba->header.size);
4548 /* XXX TWISTI how should it be freed? */
4551 /* XXX TWISTI how should it be freed? */
4558 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4559 jbyte *elems, jint mode)
4563 STATISTICS(jniinvokation());
4565 ba = (java_bytearray *) array;
4567 if (elems != ba->data) {
4570 MCOPY(ba->data, elems, s1, ba->header.size);
4573 MCOPY(ba->data, elems, s1, ba->header.size);
4574 /* XXX TWISTI how should it be freed? */
4577 /* XXX TWISTI how should it be freed? */
4584 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4585 jchar *elems, jint mode)
4589 STATISTICS(jniinvokation());
4591 ca = (java_chararray *) array;
4593 if (elems != ca->data) {
4596 MCOPY(ca->data, elems, u2, ca->header.size);
4599 MCOPY(ca->data, elems, u2, ca->header.size);
4600 /* XXX TWISTI how should it be freed? */
4603 /* XXX TWISTI how should it be freed? */
4610 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4611 jshort *elems, jint mode)
4613 java_shortarray *sa;
4615 STATISTICS(jniinvokation());
4617 sa = (java_shortarray *) array;
4619 if (elems != sa->data) {
4622 MCOPY(sa->data, elems, s2, sa->header.size);
4625 MCOPY(sa->data, elems, s2, sa->header.size);
4626 /* XXX TWISTI how should it be freed? */
4629 /* XXX TWISTI how should it be freed? */
4636 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4641 STATISTICS(jniinvokation());
4643 ia = (java_intarray *) array;
4645 if (elems != ia->data) {
4648 MCOPY(ia->data, elems, s4, ia->header.size);
4651 MCOPY(ia->data, elems, s4, ia->header.size);
4652 /* XXX TWISTI how should it be freed? */
4655 /* XXX TWISTI how should it be freed? */
4662 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4663 jlong *elems, jint mode)
4667 STATISTICS(jniinvokation());
4669 la = (java_longarray *) array;
4671 /* We cast this one to prevent a compiler warning on 64-bit
4672 systems since GNU Classpath typedef jlong to long long. */
4674 if ((s8 *) elems != la->data) {
4677 MCOPY(la->data, elems, s8, la->header.size);
4680 MCOPY(la->data, elems, s8, la->header.size);
4681 /* XXX TWISTI how should it be freed? */
4684 /* XXX TWISTI how should it be freed? */
4691 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4692 jfloat *elems, jint mode)
4694 java_floatarray *fa;
4696 STATISTICS(jniinvokation());
4698 fa = (java_floatarray *) array;
4700 if (elems != fa->data) {
4703 MCOPY(fa->data, elems, float, fa->header.size);
4706 MCOPY(fa->data, elems, float, fa->header.size);
4707 /* XXX TWISTI how should it be freed? */
4710 /* XXX TWISTI how should it be freed? */
4717 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4718 jdouble *elems, jint mode)
4720 java_doublearray *da;
4722 STATISTICS(jniinvokation());
4724 da = (java_doublearray *) array;
4726 if (elems != da->data) {
4729 MCOPY(da->data, elems, double, da->header.size);
4732 MCOPY(da->data, elems, double, da->header.size);
4733 /* XXX TWISTI how should it be freed? */
4736 /* XXX TWISTI how should it be freed? */
4743 /* Get<PrimitiveType>ArrayRegion **********************************************
4745 A family of functions that copies a region of a primitive array
4748 *******************************************************************************/
4750 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4751 jsize start, jsize len, jboolean *buf)
4753 java_booleanarray *ba;
4755 STATISTICS(jniinvokation());
4757 ba = (java_booleanarray *) array;
4759 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4760 exceptions_throw_arrayindexoutofboundsexception();
4762 MCOPY(buf, &ba->data[start], u1, len);
4766 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4767 jsize len, jbyte *buf)
4771 STATISTICS(jniinvokation());
4773 ba = (java_bytearray *) array;
4775 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4776 exceptions_throw_arrayindexoutofboundsexception();
4778 MCOPY(buf, &ba->data[start], s1, len);
4782 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4783 jsize len, jchar *buf)
4787 STATISTICS(jniinvokation());
4789 ca = (java_chararray *) array;
4791 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4792 exceptions_throw_arrayindexoutofboundsexception();
4794 MCOPY(buf, &ca->data[start], u2, len);
4798 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4799 jsize len, jshort *buf)
4801 java_shortarray *sa;
4803 STATISTICS(jniinvokation());
4805 sa = (java_shortarray *) array;
4807 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4808 exceptions_throw_arrayindexoutofboundsexception();
4810 MCOPY(buf, &sa->data[start], s2, len);
4814 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4815 jsize len, jint *buf)
4819 STATISTICS(jniinvokation());
4821 ia = (java_intarray *) array;
4823 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4824 exceptions_throw_arrayindexoutofboundsexception();
4826 MCOPY(buf, &ia->data[start], s4, len);
4830 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4831 jsize len, jlong *buf)
4835 STATISTICS(jniinvokation());
4837 la = (java_longarray *) array;
4839 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4840 exceptions_throw_arrayindexoutofboundsexception();
4842 MCOPY(buf, &la->data[start], s8, len);
4846 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4847 jsize len, jfloat *buf)
4849 java_floatarray *fa;
4851 STATISTICS(jniinvokation());
4853 fa = (java_floatarray *) array;
4855 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4856 exceptions_throw_arrayindexoutofboundsexception();
4858 MCOPY(buf, &fa->data[start], float, len);
4862 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4863 jsize len, jdouble *buf)
4865 java_doublearray *da;
4867 STATISTICS(jniinvokation());
4869 da = (java_doublearray *) array;
4871 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4872 exceptions_throw_arrayindexoutofboundsexception();
4874 MCOPY(buf, &da->data[start], double, len);
4878 /* Set<PrimitiveType>ArrayRegion **********************************************
4880 A family of functions that copies back a region of a primitive
4881 array from a buffer.
4883 *******************************************************************************/
4885 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4886 jsize start, jsize len, jboolean *buf)
4888 java_booleanarray *ba;
4890 STATISTICS(jniinvokation());
4892 ba = (java_booleanarray *) array;
4894 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4895 exceptions_throw_arrayindexoutofboundsexception();
4897 MCOPY(&ba->data[start], buf, u1, len);
4901 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4902 jsize len, jbyte *buf)
4906 STATISTICS(jniinvokation());
4908 ba = (java_bytearray *) array;
4910 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4911 exceptions_throw_arrayindexoutofboundsexception();
4913 MCOPY(&ba->data[start], buf, s1, len);
4917 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4918 jsize len, jchar *buf)
4922 STATISTICS(jniinvokation());
4924 ca = (java_chararray *) array;
4926 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4927 exceptions_throw_arrayindexoutofboundsexception();
4929 MCOPY(&ca->data[start], buf, u2, len);
4933 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4934 jsize len, jshort *buf)
4936 java_shortarray *sa;
4938 STATISTICS(jniinvokation());
4940 sa = (java_shortarray *) array;
4942 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4943 exceptions_throw_arrayindexoutofboundsexception();
4945 MCOPY(&sa->data[start], buf, s2, len);
4949 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4950 jsize len, jint *buf)
4954 STATISTICS(jniinvokation());
4956 ia = (java_intarray *) array;
4958 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4959 exceptions_throw_arrayindexoutofboundsexception();
4961 MCOPY(&ia->data[start], buf, s4, len);
4965 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
4966 jsize len, jlong *buf)
4970 STATISTICS(jniinvokation());
4972 la = (java_longarray *) array;
4974 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4975 exceptions_throw_arrayindexoutofboundsexception();
4977 MCOPY(&la->data[start], buf, s8, len);
4981 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4982 jsize len, jfloat *buf)
4984 java_floatarray *fa;
4986 STATISTICS(jniinvokation());
4988 fa = (java_floatarray *) array;
4990 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4991 exceptions_throw_arrayindexoutofboundsexception();
4993 MCOPY(&fa->data[start], buf, float, len);
4997 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4998 jsize len, jdouble *buf)
5000 java_doublearray *da;
5002 STATISTICS(jniinvokation());
5004 da = (java_doublearray *) array;
5006 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5007 exceptions_throw_arrayindexoutofboundsexception();
5009 MCOPY(&da->data[start], buf, double, len);
5013 /* Registering Native Methods *************************************************/
5015 /* RegisterNatives *************************************************************
5017 Registers native methods with the class specified by the clazz
5018 argument. The methods parameter specifies an array of
5019 JNINativeMethod structures that contain the names, signatures, and
5020 function pointers of the native methods. The nMethods parameter
5021 specifies the number of native methods in the array.
5023 *******************************************************************************/
5025 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5026 const JNINativeMethod *methods, jint nMethods)
5028 STATISTICS(jniinvokation());
5030 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5031 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5032 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5039 /* UnregisterNatives ***********************************************************
5041 Unregisters native methods of a class. The class goes back to the
5042 state before it was linked or registered with its native method
5045 This function should not be used in normal native code. Instead, it
5046 provides special programs a way to reload and relink native
5049 *******************************************************************************/
5051 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5053 STATISTICS(jniinvokation());
5055 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5057 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5063 /* Monitor Operations *********************************************************/
5065 /* MonitorEnter ****************************************************************
5067 Enters the monitor associated with the underlying Java object
5070 *******************************************************************************/
5072 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5074 STATISTICS(jniinvokation());
5077 exceptions_throw_nullpointerexception();
5081 LOCK_MONITOR_ENTER(obj);
5087 /* MonitorExit *****************************************************************
5089 The current thread must be the owner of the monitor associated with
5090 the underlying Java object referred to by obj. The thread
5091 decrements the counter indicating the number of times it has
5092 entered this monitor. If the value of the counter becomes zero, the
5093 current thread releases the monitor.
5095 *******************************************************************************/
5097 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5099 STATISTICS(jniinvokation());
5102 exceptions_throw_nullpointerexception();
5106 LOCK_MONITOR_EXIT(obj);
5112 /* JavaVM Interface ***********************************************************/
5114 /* GetJavaVM *******************************************************************
5116 Returns the Java VM interface (used in the Invocation API)
5117 associated with the current thread. The result is placed at the
5118 location pointed to by the second argument, vm.
5120 *******************************************************************************/
5122 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5124 STATISTICS(jniinvokation());
5126 *vm = (JavaVM *) _Jv_jvm;
5132 /* GetStringRegion *************************************************************
5134 Copies len number of Unicode characters beginning at offset start
5135 to the given buffer buf.
5137 Throws StringIndexOutOfBoundsException on index overflow.
5139 *******************************************************************************/
5141 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5144 java_lang_String *s;
5147 STATISTICS(jniinvokation());
5149 s = (java_lang_String *) str;
5152 if ((start < 0) || (len < 0) || (start > s->count) ||
5153 (start + len > s->count)) {
5154 exceptions_throw_stringindexoutofboundsexception();
5158 MCOPY(buf, &ca->data[start], u2, len);
5162 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5163 jsize len, char *buf)
5165 STATISTICS(jniinvokation());
5167 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5171 /* GetPrimitiveArrayCritical ***************************************************
5173 Obtain a direct pointer to array elements.
5175 *******************************************************************************/
5177 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5183 ba = (java_bytearray *) array;
5185 /* do the same as Kaffe does */
5187 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5193 /* ReleasePrimitiveArrayCritical ***********************************************
5195 No specific documentation.
5197 *******************************************************************************/
5199 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5200 void *carray, jint mode)
5202 STATISTICS(jniinvokation());
5204 /* do the same as Kaffe does */
5206 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5211 /* GetStringCritical ***********************************************************
5213 The semantics of these two functions are similar to the existing
5214 Get/ReleaseStringChars functions.
5216 *******************************************************************************/
5218 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5221 STATISTICS(jniinvokation());
5223 return _Jv_JNI_GetStringChars(env, string, isCopy);
5227 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5228 const jchar *cstring)
5230 STATISTICS(jniinvokation());
5232 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5236 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5238 STATISTICS(jniinvokation());
5240 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5246 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5248 STATISTICS(jniinvokation());
5250 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5254 /* NewGlobalRef ****************************************************************
5256 Creates a new global reference to the object referred to by the obj
5259 *******************************************************************************/
5261 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5263 hashtable_global_ref_entry *gre;
5264 u4 key; /* hashkey */
5265 u4 slot; /* slot in hashtable */
5267 STATISTICS(jniinvokation());
5269 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5271 /* normally addresses are aligned to 4, 8 or 16 bytes */
5273 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5274 slot = key & (hashtable_global_ref->size - 1);
5275 gre = hashtable_global_ref->ptr[slot];
5277 /* search external hash chain for the entry */
5280 if (gre->o == obj) {
5281 /* global object found, increment the reference */
5285 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5290 gre = gre->hashlink; /* next element in external chain */
5293 /* global ref not found, create a new one */
5295 gre = NEW(hashtable_global_ref_entry);
5300 /* insert entry into hashtable */
5302 gre->hashlink = hashtable_global_ref->ptr[slot];
5304 hashtable_global_ref->ptr[slot] = gre;
5306 /* update number of hashtable-entries */
5308 hashtable_global_ref->entries++;
5310 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5316 /* DeleteGlobalRef *************************************************************
5318 Deletes the global reference pointed to by globalRef.
5320 *******************************************************************************/
5322 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5324 hashtable_global_ref_entry *gre;
5325 hashtable_global_ref_entry *prevgre;
5326 u4 key; /* hashkey */
5327 u4 slot; /* slot in hashtable */
5329 STATISTICS(jniinvokation());
5331 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5333 /* normally addresses are aligned to 4, 8 or 16 bytes */
5335 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5336 slot = key & (hashtable_global_ref->size - 1);
5337 gre = hashtable_global_ref->ptr[slot];
5339 /* initialize prevgre */
5343 /* search external hash chain for the entry */
5346 if (gre->o == globalRef) {
5347 /* global object found, decrement the reference count */
5351 /* if reference count is 0, remove the entry */
5353 if (gre->refs == 0) {
5354 /* special handling if it's the first in the chain */
5356 if (prevgre == NULL)
5357 hashtable_global_ref->ptr[slot] = gre->hashlink;
5359 prevgre->hashlink = gre->hashlink;
5361 FREE(gre, hashtable_global_ref_entry);
5364 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5369 prevgre = gre; /* save current pointer for removal */
5370 gre = gre->hashlink; /* next element in external chain */
5373 log_println("JNI-DeleteGlobalRef: global reference not found");
5375 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5379 /* ExceptionCheck **************************************************************
5381 Returns JNI_TRUE when there is a pending exception; otherwise,
5384 *******************************************************************************/
5386 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5388 STATISTICS(jniinvokation());
5390 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
5394 /* New JNI 1.4 functions ******************************************************/
5396 /* NewDirectByteBuffer *********************************************************
5398 Allocates and returns a direct java.nio.ByteBuffer referring to the
5399 block of memory starting at the memory address address and
5400 extending capacity bytes.
5402 *******************************************************************************/
5404 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5406 java_objectheader *nbuf;
5407 #if SIZEOF_VOID_P == 8
5408 gnu_classpath_Pointer64 *paddress;
5410 gnu_classpath_Pointer32 *paddress;
5413 STATISTICS(jniinvokation());
5415 /* alocate a gnu.classpath.Pointer{32,64} object */
5417 #if SIZEOF_VOID_P == 8
5418 if (!(paddress = (gnu_classpath_Pointer64 *)
5419 builtin_new(class_gnu_classpath_Pointer64)))
5421 if (!(paddress = (gnu_classpath_Pointer32 *)
5422 builtin_new(class_gnu_classpath_Pointer32)))
5426 /* fill gnu.classpath.Pointer{32,64} with address */
5428 paddress->data = (ptrint) address;
5430 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5432 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5433 (jmethodID) dbbirw_init, NULL, paddress,
5434 (jint) capacity, (jint) capacity, (jint) 0);
5436 /* add local reference and return the value */
5438 return _Jv_JNI_NewLocalRef(env, nbuf);
5442 /* GetDirectBufferAddress ******************************************************
5444 Fetches and returns the starting address of the memory region
5445 referenced by the given direct java.nio.Buffer.
5447 *******************************************************************************/
5449 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5451 java_nio_DirectByteBufferImpl *nbuf;
5452 #if SIZEOF_VOID_P == 8
5453 gnu_classpath_Pointer64 *address;
5455 gnu_classpath_Pointer32 *address;
5458 STATISTICS(jniinvokation());
5460 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5463 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5465 #if SIZEOF_VOID_P == 8
5466 address = (gnu_classpath_Pointer64 *) nbuf->address;
5468 address = (gnu_classpath_Pointer32 *) nbuf->address;
5471 if (address == NULL)
5474 return (void *) address->data;
5478 /* GetDirectBufferCapacity *****************************************************
5480 Fetches and returns the capacity in bytes of the memory region
5481 referenced by the given direct java.nio.Buffer.
5483 *******************************************************************************/
5485 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5487 java_nio_Buffer *nbuf;
5489 STATISTICS(jniinvokation());
5491 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5494 nbuf = (java_nio_Buffer *) buf;
5496 return (jlong) nbuf->cap;
5500 /* DestroyJavaVM ***************************************************************
5502 Unloads a Java VM and reclaims its resources. Only the main thread
5503 can unload the VM. The system waits until the main thread is only
5504 remaining user thread before it destroys the VM.
5506 *******************************************************************************/
5508 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5512 STATISTICS(jniinvokation());
5514 status = vm_destroy(vm);
5520 /* AttachCurrentThread *********************************************************
5522 Attaches the current thread to a Java VM. Returns a JNI interface
5523 pointer in the JNIEnv argument.
5525 Trying to attach a thread that is already attached is a no-op.
5527 A native thread cannot be attached simultaneously to two Java VMs.
5529 When a thread is attached to the VM, the context class loader is
5530 the bootstrap loader.
5532 *******************************************************************************/
5534 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5536 JavaVMAttachArgs *vm_aargs;
5538 #if defined(ENABLE_THREADS)
5539 if (threads_get_current_threadobject() == NULL) {
5540 vm_aargs = (JavaVMAttachArgs *) thr_args;
5542 if (vm_aargs != NULL) {
5543 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5544 (vm_aargs->version != JNI_VERSION_1_4))
5545 return JNI_EVERSION;
5548 if (!threads_attach_current_thread(vm_aargs, false))
5551 if (!jni_init_localref_table())
5562 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5564 STATISTICS(jniinvokation());
5566 return jni_attach_current_thread(p_env, thr_args, false);
5570 /* DetachCurrentThread *********************************************************
5572 Detaches the current thread from a Java VM. All Java monitors held
5573 by this thread are released. All Java threads waiting for this
5574 thread to die are notified.
5576 In JDK 1.1, the main thread cannot be detached from the VM. It must
5577 call DestroyJavaVM to unload the entire VM.
5579 In the JDK, the main thread can be detached from the VM.
5581 The main thread, which is the thread that created the Java VM,
5582 cannot be detached from the VM. Instead, the main thread must call
5583 JNI_DestroyJavaVM() to unload the entire VM.
5585 *******************************************************************************/
5587 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5589 #if defined(ENABLE_THREADS)
5590 threadobject *thread;
5592 STATISTICS(jniinvokation());
5594 thread = threads_get_current_threadobject();
5599 if (!threads_detach_thread(thread))
5607 /* GetEnv **********************************************************************
5609 If the current thread is not attached to the VM, sets *env to NULL,
5610 and returns JNI_EDETACHED. If the specified version is not
5611 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5612 sets *env to the appropriate interface, and returns JNI_OK.
5614 *******************************************************************************/
5616 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5618 STATISTICS(jniinvokation());
5620 #if defined(ENABLE_THREADS)
5621 if (threads_get_current_threadobject() == NULL) {
5624 return JNI_EDETACHED;
5628 /* check the JNI version */
5631 case JNI_VERSION_1_1:
5632 case JNI_VERSION_1_2:
5633 case JNI_VERSION_1_4:
5641 #if defined(ENABLE_JVMTI)
5642 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5643 == JVMTI_VERSION_INTERFACE_JVMTI) {
5645 *env = (void *) jvmti_new_environment();
5654 return JNI_EVERSION;
5658 /* AttachCurrentThreadAsDaemon *************************************************
5660 Same semantics as AttachCurrentThread, but the newly-created
5661 java.lang.Thread instance is a daemon.
5663 If the thread has already been attached via either
5664 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5665 simply sets the value pointed to by penv to the JNIEnv of the
5666 current thread. In this case neither AttachCurrentThread nor this
5667 routine have any effect on the daemon status of the thread.
5669 *******************************************************************************/
5671 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5673 STATISTICS(jniinvokation());
5675 return jni_attach_current_thread(penv, args, true);
5679 /* JNI invocation table *******************************************************/
5681 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5686 _Jv_JNI_DestroyJavaVM,
5687 _Jv_JNI_AttachCurrentThread,
5688 _Jv_JNI_DetachCurrentThread,
5690 _Jv_JNI_AttachCurrentThreadAsDaemon
5694 /* JNI function table *********************************************************/
5696 struct JNINativeInterface _Jv_JNINativeInterface = {
5703 _Jv_JNI_DefineClass,
5705 _Jv_JNI_FromReflectedMethod,
5706 _Jv_JNI_FromReflectedField,
5707 _Jv_JNI_ToReflectedMethod,
5708 _Jv_JNI_GetSuperclass,
5709 _Jv_JNI_IsAssignableFrom,
5710 _Jv_JNI_ToReflectedField,
5714 _Jv_JNI_ExceptionOccurred,
5715 _Jv_JNI_ExceptionDescribe,
5716 _Jv_JNI_ExceptionClear,
5718 _Jv_JNI_PushLocalFrame,
5719 _Jv_JNI_PopLocalFrame,
5721 _Jv_JNI_NewGlobalRef,
5722 _Jv_JNI_DeleteGlobalRef,
5723 _Jv_JNI_DeleteLocalRef,
5724 _Jv_JNI_IsSameObject,
5725 _Jv_JNI_NewLocalRef,
5726 _Jv_JNI_EnsureLocalCapacity,
5728 _Jv_JNI_AllocObject,
5733 _Jv_JNI_GetObjectClass,
5734 _Jv_JNI_IsInstanceOf,
5736 _Jv_JNI_GetMethodID,
5738 _Jv_JNI_CallObjectMethod,
5739 _Jv_JNI_CallObjectMethodV,
5740 _Jv_JNI_CallObjectMethodA,
5741 _Jv_JNI_CallBooleanMethod,
5742 _Jv_JNI_CallBooleanMethodV,
5743 _Jv_JNI_CallBooleanMethodA,
5744 _Jv_JNI_CallByteMethod,
5745 _Jv_JNI_CallByteMethodV,
5746 _Jv_JNI_CallByteMethodA,
5747 _Jv_JNI_CallCharMethod,
5748 _Jv_JNI_CallCharMethodV,
5749 _Jv_JNI_CallCharMethodA,
5750 _Jv_JNI_CallShortMethod,
5751 _Jv_JNI_CallShortMethodV,
5752 _Jv_JNI_CallShortMethodA,
5753 _Jv_JNI_CallIntMethod,
5754 _Jv_JNI_CallIntMethodV,
5755 _Jv_JNI_CallIntMethodA,
5756 _Jv_JNI_CallLongMethod,
5757 _Jv_JNI_CallLongMethodV,
5758 _Jv_JNI_CallLongMethodA,
5759 _Jv_JNI_CallFloatMethod,
5760 _Jv_JNI_CallFloatMethodV,
5761 _Jv_JNI_CallFloatMethodA,
5762 _Jv_JNI_CallDoubleMethod,
5763 _Jv_JNI_CallDoubleMethodV,
5764 _Jv_JNI_CallDoubleMethodA,
5765 _Jv_JNI_CallVoidMethod,
5766 _Jv_JNI_CallVoidMethodV,
5767 _Jv_JNI_CallVoidMethodA,
5769 _Jv_JNI_CallNonvirtualObjectMethod,
5770 _Jv_JNI_CallNonvirtualObjectMethodV,
5771 _Jv_JNI_CallNonvirtualObjectMethodA,
5772 _Jv_JNI_CallNonvirtualBooleanMethod,
5773 _Jv_JNI_CallNonvirtualBooleanMethodV,
5774 _Jv_JNI_CallNonvirtualBooleanMethodA,
5775 _Jv_JNI_CallNonvirtualByteMethod,
5776 _Jv_JNI_CallNonvirtualByteMethodV,
5777 _Jv_JNI_CallNonvirtualByteMethodA,
5778 _Jv_JNI_CallNonvirtualCharMethod,
5779 _Jv_JNI_CallNonvirtualCharMethodV,
5780 _Jv_JNI_CallNonvirtualCharMethodA,
5781 _Jv_JNI_CallNonvirtualShortMethod,
5782 _Jv_JNI_CallNonvirtualShortMethodV,
5783 _Jv_JNI_CallNonvirtualShortMethodA,
5784 _Jv_JNI_CallNonvirtualIntMethod,
5785 _Jv_JNI_CallNonvirtualIntMethodV,
5786 _Jv_JNI_CallNonvirtualIntMethodA,
5787 _Jv_JNI_CallNonvirtualLongMethod,
5788 _Jv_JNI_CallNonvirtualLongMethodV,
5789 _Jv_JNI_CallNonvirtualLongMethodA,
5790 _Jv_JNI_CallNonvirtualFloatMethod,
5791 _Jv_JNI_CallNonvirtualFloatMethodV,
5792 _Jv_JNI_CallNonvirtualFloatMethodA,
5793 _Jv_JNI_CallNonvirtualDoubleMethod,
5794 _Jv_JNI_CallNonvirtualDoubleMethodV,
5795 _Jv_JNI_CallNonvirtualDoubleMethodA,
5796 _Jv_JNI_CallNonvirtualVoidMethod,
5797 _Jv_JNI_CallNonvirtualVoidMethodV,
5798 _Jv_JNI_CallNonvirtualVoidMethodA,
5802 _Jv_JNI_GetObjectField,
5803 _Jv_JNI_GetBooleanField,
5804 _Jv_JNI_GetByteField,
5805 _Jv_JNI_GetCharField,
5806 _Jv_JNI_GetShortField,
5807 _Jv_JNI_GetIntField,
5808 _Jv_JNI_GetLongField,
5809 _Jv_JNI_GetFloatField,
5810 _Jv_JNI_GetDoubleField,
5811 _Jv_JNI_SetObjectField,
5812 _Jv_JNI_SetBooleanField,
5813 _Jv_JNI_SetByteField,
5814 _Jv_JNI_SetCharField,
5815 _Jv_JNI_SetShortField,
5816 _Jv_JNI_SetIntField,
5817 _Jv_JNI_SetLongField,
5818 _Jv_JNI_SetFloatField,
5819 _Jv_JNI_SetDoubleField,
5821 _Jv_JNI_GetStaticMethodID,
5823 _Jv_JNI_CallStaticObjectMethod,
5824 _Jv_JNI_CallStaticObjectMethodV,
5825 _Jv_JNI_CallStaticObjectMethodA,
5826 _Jv_JNI_CallStaticBooleanMethod,
5827 _Jv_JNI_CallStaticBooleanMethodV,
5828 _Jv_JNI_CallStaticBooleanMethodA,
5829 _Jv_JNI_CallStaticByteMethod,
5830 _Jv_JNI_CallStaticByteMethodV,
5831 _Jv_JNI_CallStaticByteMethodA,
5832 _Jv_JNI_CallStaticCharMethod,
5833 _Jv_JNI_CallStaticCharMethodV,
5834 _Jv_JNI_CallStaticCharMethodA,
5835 _Jv_JNI_CallStaticShortMethod,
5836 _Jv_JNI_CallStaticShortMethodV,
5837 _Jv_JNI_CallStaticShortMethodA,
5838 _Jv_JNI_CallStaticIntMethod,
5839 _Jv_JNI_CallStaticIntMethodV,
5840 _Jv_JNI_CallStaticIntMethodA,
5841 _Jv_JNI_CallStaticLongMethod,
5842 _Jv_JNI_CallStaticLongMethodV,
5843 _Jv_JNI_CallStaticLongMethodA,
5844 _Jv_JNI_CallStaticFloatMethod,
5845 _Jv_JNI_CallStaticFloatMethodV,
5846 _Jv_JNI_CallStaticFloatMethodA,
5847 _Jv_JNI_CallStaticDoubleMethod,
5848 _Jv_JNI_CallStaticDoubleMethodV,
5849 _Jv_JNI_CallStaticDoubleMethodA,
5850 _Jv_JNI_CallStaticVoidMethod,
5851 _Jv_JNI_CallStaticVoidMethodV,
5852 _Jv_JNI_CallStaticVoidMethodA,
5854 _Jv_JNI_GetStaticFieldID,
5856 _Jv_JNI_GetStaticObjectField,
5857 _Jv_JNI_GetStaticBooleanField,
5858 _Jv_JNI_GetStaticByteField,
5859 _Jv_JNI_GetStaticCharField,
5860 _Jv_JNI_GetStaticShortField,
5861 _Jv_JNI_GetStaticIntField,
5862 _Jv_JNI_GetStaticLongField,
5863 _Jv_JNI_GetStaticFloatField,
5864 _Jv_JNI_GetStaticDoubleField,
5865 _Jv_JNI_SetStaticObjectField,
5866 _Jv_JNI_SetStaticBooleanField,
5867 _Jv_JNI_SetStaticByteField,
5868 _Jv_JNI_SetStaticCharField,
5869 _Jv_JNI_SetStaticShortField,
5870 _Jv_JNI_SetStaticIntField,
5871 _Jv_JNI_SetStaticLongField,
5872 _Jv_JNI_SetStaticFloatField,
5873 _Jv_JNI_SetStaticDoubleField,
5876 _Jv_JNI_GetStringLength,
5877 _Jv_JNI_GetStringChars,
5878 _Jv_JNI_ReleaseStringChars,
5880 _Jv_JNI_NewStringUTF,
5881 _Jv_JNI_GetStringUTFLength,
5882 _Jv_JNI_GetStringUTFChars,
5883 _Jv_JNI_ReleaseStringUTFChars,
5885 _Jv_JNI_GetArrayLength,
5887 _Jv_JNI_NewObjectArray,
5888 _Jv_JNI_GetObjectArrayElement,
5889 _Jv_JNI_SetObjectArrayElement,
5891 _Jv_JNI_NewBooleanArray,
5892 _Jv_JNI_NewByteArray,
5893 _Jv_JNI_NewCharArray,
5894 _Jv_JNI_NewShortArray,
5895 _Jv_JNI_NewIntArray,
5896 _Jv_JNI_NewLongArray,
5897 _Jv_JNI_NewFloatArray,
5898 _Jv_JNI_NewDoubleArray,
5900 _Jv_JNI_GetBooleanArrayElements,
5901 _Jv_JNI_GetByteArrayElements,
5902 _Jv_JNI_GetCharArrayElements,
5903 _Jv_JNI_GetShortArrayElements,
5904 _Jv_JNI_GetIntArrayElements,
5905 _Jv_JNI_GetLongArrayElements,
5906 _Jv_JNI_GetFloatArrayElements,
5907 _Jv_JNI_GetDoubleArrayElements,
5909 _Jv_JNI_ReleaseBooleanArrayElements,
5910 _Jv_JNI_ReleaseByteArrayElements,
5911 _Jv_JNI_ReleaseCharArrayElements,
5912 _Jv_JNI_ReleaseShortArrayElements,
5913 _Jv_JNI_ReleaseIntArrayElements,
5914 _Jv_JNI_ReleaseLongArrayElements,
5915 _Jv_JNI_ReleaseFloatArrayElements,
5916 _Jv_JNI_ReleaseDoubleArrayElements,
5918 _Jv_JNI_GetBooleanArrayRegion,
5919 _Jv_JNI_GetByteArrayRegion,
5920 _Jv_JNI_GetCharArrayRegion,
5921 _Jv_JNI_GetShortArrayRegion,
5922 _Jv_JNI_GetIntArrayRegion,
5923 _Jv_JNI_GetLongArrayRegion,
5924 _Jv_JNI_GetFloatArrayRegion,
5925 _Jv_JNI_GetDoubleArrayRegion,
5926 _Jv_JNI_SetBooleanArrayRegion,
5927 _Jv_JNI_SetByteArrayRegion,
5928 _Jv_JNI_SetCharArrayRegion,
5929 _Jv_JNI_SetShortArrayRegion,
5930 _Jv_JNI_SetIntArrayRegion,
5931 _Jv_JNI_SetLongArrayRegion,
5932 _Jv_JNI_SetFloatArrayRegion,
5933 _Jv_JNI_SetDoubleArrayRegion,
5935 _Jv_JNI_RegisterNatives,
5936 _Jv_JNI_UnregisterNatives,
5938 _Jv_JNI_MonitorEnter,
5939 _Jv_JNI_MonitorExit,
5943 /* new JNI 1.2 functions */
5945 _Jv_JNI_GetStringRegion,
5946 _Jv_JNI_GetStringUTFRegion,
5948 _Jv_JNI_GetPrimitiveArrayCritical,
5949 _Jv_JNI_ReleasePrimitiveArrayCritical,
5951 _Jv_JNI_GetStringCritical,
5952 _Jv_JNI_ReleaseStringCritical,
5954 _Jv_JNI_NewWeakGlobalRef,
5955 _Jv_JNI_DeleteWeakGlobalRef,
5957 _Jv_JNI_ExceptionCheck,
5959 /* new JNI 1.4 functions */
5961 _Jv_JNI_NewDirectByteBuffer,
5962 _Jv_JNI_GetDirectBufferAddress,
5963 _Jv_JNI_GetDirectBufferCapacity
5967 /* Invocation API Functions ***************************************************/
5969 /* JNI_GetDefaultJavaVMInitArgs ************************************************
5971 Returns a default configuration for the Java VM.
5973 *******************************************************************************/
5975 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
5977 JavaVMInitArgs *_vm_args;
5979 _vm_args = (JavaVMInitArgs *) vm_args;
5981 /* GNU classpath currently supports JNI 1.2 */
5983 switch (_vm_args->version) {
5984 case JNI_VERSION_1_1:
5985 _vm_args->version = JNI_VERSION_1_1;
5988 case JNI_VERSION_1_2:
5989 case JNI_VERSION_1_4:
5990 _vm_args->ignoreUnrecognized = JNI_FALSE;
5991 _vm_args->options = NULL;
5992 _vm_args->nOptions = 0;
6003 /* JNI_GetCreatedJavaVMs *******************************************************
6005 Returns all Java VMs that have been created. Pointers to VMs are written in
6006 the buffer vmBuf in the order they are created. At most bufLen number of
6007 entries will be written. The total number of created VMs is returned in
6010 *******************************************************************************/
6012 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6014 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6020 /* JNI_CreateJavaVM ************************************************************
6022 Loads and initializes a Java VM. The current thread becomes the main thread.
6023 Sets the env argument to the JNI interface pointer of the main thread.
6025 *******************************************************************************/
6027 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6029 /* actually create the JVM */
6031 if (!vm_createjvm(p_vm, p_env, vm_args))
6039 * These are local overrides for various environment variables in Emacs.
6040 * Please do not remove this and leave it at the end of the file, where
6041 * Emacs will automagically detect them.
6042 * ---------------------------------------------------------------------
6045 * indent-tabs-mode: t
6049 * vim:noexpandtab:sw=4:ts=4: