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 7918 2007-05-20 20:42:18Z michi $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #if defined(ENABLE_JAVASE)
43 # if defined(WITH_CLASSPATH_GNU)
44 # include "native/include/gnu_classpath_Pointer.h"
46 # if SIZEOF_VOID_P == 8
47 # include "native/include/gnu_classpath_Pointer64.h"
49 # include "native/include/gnu_classpath_Pointer32.h"
54 #include "native/include/java_lang_Object.h"
55 #include "native/include/java_lang_Byte.h"
56 #include "native/include/java_lang_Character.h"
57 #include "native/include/java_lang_Short.h"
58 #include "native/include/java_lang_Integer.h"
59 #include "native/include/java_lang_Boolean.h"
60 #include "native/include/java_lang_Long.h"
61 #include "native/include/java_lang_Float.h"
62 #include "native/include/java_lang_Double.h"
63 #include "native/include/java_lang_String.h"
64 #include "native/include/java_lang_Throwable.h"
66 #if defined(ENABLE_JAVASE)
67 # include "native/include/java_lang_ClassLoader.h"
69 # include "native/include/java_lang_reflect_Constructor.h"
70 # include "native/include/java_lang_reflect_Field.h"
71 # include "native/include/java_lang_reflect_Method.h"
73 # include "native/include/java_nio_Buffer.h"
74 # include "native/include/java_nio_DirectByteBufferImpl.h"
77 #if defined(ENABLE_JVMTI)
78 # include "native/jvmti/cacaodbg.h"
81 #include "native/vm/java_lang_Class.h"
83 #if defined(ENABLE_JAVASE)
84 # include "native/vm/java_lang_ClassLoader.h"
87 #include "threads/lock-common.h"
88 #include "threads/threads-common.h"
90 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/stringlocal.h"
99 #include "vm/jit/asmpart.h"
100 #include "vm/jit/jit.h"
101 #include "vm/jit/stacktrace.h"
103 #include "vmcore/loader.h"
104 #include "vmcore/options.h"
105 #include "vm/resolve.h"
106 #include "vmcore/statistics.h"
109 /* global variables ***********************************************************/
111 /* global reference table *****************************************************/
113 /* hashsize must be power of 2 */
115 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
117 hashtable *hashtable_global_ref; /* hashtable for globalrefs */
120 /* direct buffer stuff ********************************************************/
122 #if defined(ENABLE_JAVASE)
123 static classinfo *class_java_nio_Buffer;
124 static classinfo *class_java_nio_DirectByteBufferImpl;
125 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
127 # if defined(WITH_CLASSPATH_GNU)
128 # if SIZEOF_VOID_P == 8
129 static classinfo *class_gnu_classpath_Pointer64;
131 static classinfo *class_gnu_classpath_Pointer32;
135 static methodinfo *dbbirw_init;
139 /* local reference table ******************************************************/
141 #if !defined(ENABLE_THREADS)
142 localref_table *_no_threads_localref_table;
146 /* accessing instance fields macros *******************************************/
148 #define SET_FIELD(o,type,f,value) \
149 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
151 #define GET_FIELD(o,type,f) \
152 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
155 /* some forward declarations **************************************************/
157 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
158 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
161 /* jni_init ********************************************************************
163 Initialize the JNI subsystem.
165 *******************************************************************************/
169 /* create global ref hashtable */
171 hashtable_global_ref = NEW(hashtable);
173 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
176 #if defined(ENABLE_JAVASE)
177 /* direct buffer stuff */
179 if (!(class_java_nio_Buffer =
180 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
181 !link_class(class_java_nio_Buffer))
184 if (!(class_java_nio_DirectByteBufferImpl =
185 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
186 !link_class(class_java_nio_DirectByteBufferImpl))
189 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
190 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
191 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
195 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
197 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
200 # if defined(WITH_CLASSPATH_GNU)
201 # if SIZEOF_VOID_P == 8
202 if (!(class_gnu_classpath_Pointer64 =
203 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
204 !link_class(class_gnu_classpath_Pointer64))
207 if (!(class_gnu_classpath_Pointer32 =
208 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
209 !link_class(class_gnu_classpath_Pointer32))
213 #endif /* defined(ENABLE_JAVASE) */
219 /* jni_init_localref_table *****************************************************
221 Initializes the local references table of the current thread.
223 *******************************************************************************/
225 bool jni_init_localref_table(void)
229 #if defined(ENABLE_GC_CACAO)
230 /* XXX this one will never get freed for the main thread;
231 call jni_free_localref_table() if you want to do it! */
232 lrt = NEW(localref_table);
234 lrt = GCNEW(localref_table);
240 lrt->capacity = LOCALREFTABLE_CAPACITY;
242 lrt->localframes = 1;
243 lrt->prev = LOCALREFTABLE;
245 /* clear the references array (memset is faster then a for-loop) */
247 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
255 /* jni_init_localref_table *****************************************************
257 Frees the local references table of the current thread.
259 *******************************************************************************/
261 bool jni_free_localref_table(void)
265 #if defined(ENABLE_GC_CACAO)
269 assert(lrt->prev == NULL);
271 FREE(lrt, localref_table);
273 LOCALREFTABLE = NULL;
280 /* _Jv_jni_vmargs_from_objectarray *********************************************
284 *******************************************************************************/
286 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
289 java_objectarray *params)
291 java_objectheader *param;
293 typedesc *paramtypes;
299 paramcount = descr->paramcount;
300 paramtypes = descr->paramtypes;
302 /* if method is non-static fill first block and skip `this' pointer */
308 vmargs[0].type = TYPE_ADR;
309 vmargs[0].data.l = (u8) (ptrint) o;
316 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
317 switch (paramtypes->type) {
318 /* primitive types */
323 param = params->data[j];
328 /* internally used data type */
329 vmargs[i].type = paramtypes->type;
331 /* convert the value according to its declared type */
333 c = param->vftbl->class;
335 switch (paramtypes->decltype) {
336 case PRIMITIVETYPE_BOOLEAN:
337 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
338 value = (s8) ((java_lang_Boolean *) param)->value;
342 vmargs[i].data.l = value;
345 case PRIMITIVETYPE_BYTE:
346 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
347 value = (s8) ((java_lang_Byte *) param)->value;
351 vmargs[i].data.l = value;
354 case PRIMITIVETYPE_CHAR:
355 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
356 value = (s8) ((java_lang_Character *) param)->value;
360 vmargs[i].data.l = value;
363 case PRIMITIVETYPE_SHORT:
364 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
365 value = (s8) ((java_lang_Short *) param)->value;
366 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
367 value = (s8) ((java_lang_Byte *) param)->value;
371 vmargs[i].data.l = value;
374 case PRIMITIVETYPE_INT:
375 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
376 value = (s8) ((java_lang_Integer *) param)->value;
377 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
378 value = (s8) ((java_lang_Short *) param)->value;
379 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
380 value = (s8) ((java_lang_Byte *) param)->value;
384 vmargs[i].data.l = value;
387 case PRIMITIVETYPE_LONG:
388 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
389 value = (s8) ((java_lang_Long *) param)->value;
390 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
391 value = (s8) ((java_lang_Integer *) param)->value;
392 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
393 value = (s8) ((java_lang_Short *) param)->value;
394 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
395 value = (s8) ((java_lang_Byte *) param)->value;
399 vmargs[i].data.l = value;
402 case PRIMITIVETYPE_FLOAT:
403 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
404 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
409 case PRIMITIVETYPE_DOUBLE:
410 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
411 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
412 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
413 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
424 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
427 if (params->data[j] != 0) {
428 if (paramtypes->arraydim > 0) {
429 if (!builtin_arrayinstanceof(params->data[j], c))
433 if (!builtin_instanceof(params->data[j], c))
438 vmargs[i].type = TYPE_ADR;
439 vmargs[i].data.l = (u8) (ptrint) params->data[j];
448 /* *rettype = descr->returntype.decltype; */
453 exceptions_throw_illegalargumentexception();
458 /* _Jv_jni_CallObjectMethod ****************************************************
460 Internal function to call Java Object methods.
462 *******************************************************************************/
464 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
466 methodinfo *m, va_list ap)
469 java_objectheader *ro;
471 STATISTICS(jniinvokation());
474 exceptions_throw_nullpointerexception();
478 /* Class initialization is done by the JIT compiler. This is ok
479 since a static method always belongs to the declaring class. */
481 if (m->flags & ACC_STATIC) {
482 /* For static methods we reset the object. */
487 /* for convenience */
492 /* For instance methods we make a virtual function table lookup. */
494 resm = method_vftbl_lookup(vftbl, m);
497 STATISTICS(jnicallXmethodnvokation());
499 ro = vm_call_method_valist(resm, o, ap);
505 /* _Jv_jni_CallObjectMethodA ***************************************************
507 Internal function to call Java Object methods.
509 *******************************************************************************/
511 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
513 methodinfo *m, jvalue *args)
516 java_objectheader *ro;
518 STATISTICS(jniinvokation());
521 exceptions_throw_nullpointerexception();
525 /* Class initialization is done by the JIT compiler. This is ok
526 since a static method always belongs to the declaring class. */
528 if (m->flags & ACC_STATIC) {
529 /* For static methods we reset the object. */
534 /* for convenience */
539 /* For instance methods we make a virtual function table lookup. */
541 resm = method_vftbl_lookup(vftbl, m);
544 STATISTICS(jnicallXmethodnvokation());
546 ro = vm_call_method_jvalue(resm, o, args);
552 /* _Jv_jni_CallIntMethod *******************************************************
554 Internal function to call Java integer class methods (boolean,
555 byte, char, short, int).
557 *******************************************************************************/
559 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
560 methodinfo *m, va_list ap)
565 STATISTICS(jniinvokation());
568 exceptions_throw_nullpointerexception();
572 /* Class initialization is done by the JIT compiler. This is ok
573 since a static method always belongs to the declaring class. */
575 if (m->flags & ACC_STATIC) {
576 /* For static methods we reset the object. */
581 /* for convenience */
586 /* For instance methods we make a virtual function table lookup. */
588 resm = method_vftbl_lookup(vftbl, m);
591 STATISTICS(jnicallXmethodnvokation());
593 i = vm_call_method_int_valist(resm, o, ap);
599 /* _Jv_jni_CallIntMethodA ******************************************************
601 Internal function to call Java integer class methods (boolean,
602 byte, char, short, int).
604 *******************************************************************************/
606 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
607 methodinfo *m, jvalue *args)
612 STATISTICS(jniinvokation());
615 exceptions_throw_nullpointerexception();
619 /* Class initialization is done by the JIT compiler. This is ok
620 since a static method always belongs to the declaring class. */
622 if (m->flags & ACC_STATIC) {
623 /* For static methods we reset the object. */
628 /* for convenience */
633 /* For instance methods we make a virtual function table lookup. */
635 resm = method_vftbl_lookup(vftbl, m);
638 STATISTICS(jnicallXmethodnvokation());
640 i = vm_call_method_int_jvalue(resm, o, args);
646 /* _Jv_jni_CallLongMethod ******************************************************
648 Internal function to call Java long methods.
650 *******************************************************************************/
652 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
653 methodinfo *m, va_list ap)
658 STATISTICS(jniinvokation());
661 exceptions_throw_nullpointerexception();
665 /* Class initialization is done by the JIT compiler. This is ok
666 since a static method always belongs to the declaring class. */
668 if (m->flags & ACC_STATIC) {
669 /* For static methods we reset the object. */
674 /* for convenience */
679 /* For instance methods we make a virtual function table lookup. */
681 resm = method_vftbl_lookup(vftbl, m);
684 STATISTICS(jnicallXmethodnvokation());
686 l = vm_call_method_long_valist(resm, o, ap);
692 /* _Jv_jni_CallFloatMethod *****************************************************
694 Internal function to call Java float methods.
696 *******************************************************************************/
698 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
699 methodinfo *m, va_list ap)
704 /* Class initialization is done by the JIT compiler. This is ok
705 since a static method always belongs to the declaring class. */
707 if (m->flags & ACC_STATIC) {
708 /* For static methods we reset the object. */
713 /* for convenience */
718 /* For instance methods we make a virtual function table lookup. */
720 resm = method_vftbl_lookup(vftbl, m);
723 STATISTICS(jnicallXmethodnvokation());
725 f = vm_call_method_float_valist(resm, o, ap);
731 /* _Jv_jni_CallDoubleMethod ****************************************************
733 Internal function to call Java double methods.
735 *******************************************************************************/
737 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
738 methodinfo *m, va_list ap)
743 /* Class initialization is done by the JIT compiler. This is ok
744 since a static method always belongs to the declaring class. */
746 if (m->flags & ACC_STATIC) {
747 /* For static methods we reset the object. */
752 /* for convenience */
757 /* For instance methods we make a virtual function table lookup. */
759 resm = method_vftbl_lookup(vftbl, m);
762 d = vm_call_method_double_valist(resm, o, ap);
768 /* _Jv_jni_CallVoidMethod ******************************************************
770 Internal function to call Java void methods.
772 *******************************************************************************/
774 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
775 methodinfo *m, va_list ap)
780 exceptions_throw_nullpointerexception();
784 /* Class initialization is done by the JIT compiler. This is ok
785 since a static method always belongs to the declaring class. */
787 if (m->flags & ACC_STATIC) {
788 /* For static methods we reset the object. */
793 /* for convenience */
798 /* For instance methods we make a virtual function table lookup. */
800 resm = method_vftbl_lookup(vftbl, m);
803 STATISTICS(jnicallXmethodnvokation());
805 (void) vm_call_method_valist(resm, o, ap);
809 /* _Jv_jni_CallVoidMethodA *****************************************************
811 Internal function to call Java void methods.
813 *******************************************************************************/
815 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
816 methodinfo *m, jvalue *args)
821 exceptions_throw_nullpointerexception();
825 /* Class initialization is done by the JIT compiler. This is ok
826 since a static method always belongs to the declaring class. */
828 if (m->flags & ACC_STATIC) {
829 /* For static methods we reset the object. */
834 /* for convenience */
839 /* For instance methods we make a virtual function table lookup. */
841 resm = method_vftbl_lookup(vftbl, m);
844 STATISTICS(jnicallXmethodnvokation());
846 (void) vm_call_method_jvalue(resm, o, args);
850 /* _Jv_jni_invokeNative ********************************************************
852 Invoke a method on the given object with the given arguments.
854 For instance methods OBJ must be != NULL and the method is looked up
855 in the vftbl of the object.
857 For static methods, OBJ is ignored.
859 *******************************************************************************/
861 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
862 java_objectarray *params)
866 java_objectheader *ro;
869 java_objectheader *xptr;
872 exceptions_throw_nullpointerexception();
876 argcount = m->parseddesc->paramcount;
877 paramcount = argcount;
879 /* if method is non-static, remove the `this' pointer */
881 if (!(m->flags & ACC_STATIC))
884 /* For instance methods the object has to be an instance of the
885 class the method belongs to. For static methods the obj
886 parameter is ignored. */
888 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
889 exceptions_throw_illegalargumentexception();
893 /* check if we got the right number of arguments */
895 if (((params == NULL) && (paramcount != 0)) ||
896 (params && (params->header.size != paramcount)))
898 exceptions_throw_illegalargumentexception();
902 /* for instance methods we need an object */
904 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
905 /* XXX not sure if that is the correct exception */
906 exceptions_throw_nullpointerexception();
910 /* for static methods, zero object to make subsequent code simpler */
911 if (m->flags & ACC_STATIC)
915 /* for instance methods we must do a vftbl lookup */
916 resm = method_vftbl_lookup(o->vftbl, m);
919 /* for static methods, just for convenience */
923 vmargs = MNEW(vm_arg, argcount);
925 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
926 MFREE(vmargs, vm_arg, argcount);
930 switch (resm->parseddesc->returntype.decltype) {
932 (void) vm_call_method_vmarg(resm, argcount, vmargs);
937 case PRIMITIVETYPE_BOOLEAN: {
939 java_lang_Boolean *bo;
941 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
943 ro = builtin_new(class_java_lang_Boolean);
945 /* setting the value of the object direct */
947 bo = (java_lang_Boolean *) ro;
952 case PRIMITIVETYPE_BYTE: {
956 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
958 ro = builtin_new(class_java_lang_Byte);
960 /* setting the value of the object direct */
962 bo = (java_lang_Byte *) ro;
967 case PRIMITIVETYPE_CHAR: {
969 java_lang_Character *co;
971 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
973 ro = builtin_new(class_java_lang_Character);
975 /* setting the value of the object direct */
977 co = (java_lang_Character *) ro;
982 case PRIMITIVETYPE_SHORT: {
986 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
988 ro = builtin_new(class_java_lang_Short);
990 /* setting the value of the object direct */
992 so = (java_lang_Short *) ro;
997 case PRIMITIVETYPE_INT: {
999 java_lang_Integer *io;
1001 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1003 ro = builtin_new(class_java_lang_Integer);
1005 /* setting the value of the object direct */
1007 io = (java_lang_Integer *) ro;
1012 case PRIMITIVETYPE_LONG: {
1016 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1018 ro = builtin_new(class_java_lang_Long);
1020 /* setting the value of the object direct */
1022 lo = (java_lang_Long *) ro;
1027 case PRIMITIVETYPE_FLOAT: {
1029 java_lang_Float *fo;
1031 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1033 ro = builtin_new(class_java_lang_Float);
1035 /* setting the value of the object direct */
1037 fo = (java_lang_Float *) ro;
1042 case PRIMITIVETYPE_DOUBLE: {
1044 java_lang_Double *_do;
1046 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1048 ro = builtin_new(class_java_lang_Double);
1050 /* setting the value of the object direct */
1052 _do = (java_lang_Double *) ro;
1058 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1062 /* if this happens the exception has already been set by
1063 fill_callblock_from_objectarray */
1065 MFREE(vmargs, vm_arg, argcount);
1070 MFREE(vmargs, vm_arg, argcount);
1072 xptr = exceptions_get_exception();
1075 /* clear exception pointer, we are calling JIT code again */
1077 exceptions_clear_exception();
1079 exceptions_throw_invocationtargetexception(xptr);
1086 /* GetVersion ******************************************************************
1088 Returns the major version number in the higher 16 bits and the
1089 minor version number in the lower 16 bits.
1091 *******************************************************************************/
1093 jint _Jv_JNI_GetVersion(JNIEnv *env)
1095 STATISTICS(jniinvokation());
1097 /* we support JNI 1.4 */
1099 return JNI_VERSION_1_4;
1103 /* Class Operations ***********************************************************/
1105 /* DefineClass *****************************************************************
1107 Loads a class from a buffer of raw class data. The buffer
1108 containing the raw class data is not referenced by the VM after the
1109 DefineClass call returns, and it may be discarded if desired.
1111 *******************************************************************************/
1113 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1114 const jbyte *buf, jsize bufLen)
1116 #if defined(ENABLE_JAVASE)
1117 java_lang_ClassLoader *cl;
1118 java_lang_String *s;
1122 STATISTICS(jniinvokation());
1124 cl = (java_lang_ClassLoader *) loader;
1125 s = (java_lang_String *) javastring_new_from_utf_string(name);
1126 ba = (java_bytearray *) buf;
1128 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1131 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1133 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1135 /* keep compiler happy */
1142 /* FindClass *******************************************************************
1144 This function loads a locally-defined class. It searches the
1145 directories and zip files specified by the CLASSPATH environment
1146 variable for the class with the specified name.
1148 *******************************************************************************/
1150 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1152 #if defined(ENABLE_JAVASE)
1157 STATISTICS(jniinvokation());
1159 u = utf_new_char_classname((char *) name);
1161 /* Check stacktrace for classloader, if one found use it,
1162 otherwise use the system classloader. */
1164 /* Quote from the JNI documentation:
1166 In the Java 2 Platform, FindClass locates the class loader
1167 associated with the current native method. If the native code
1168 belongs to a system class, no class loader will be
1169 involved. Otherwise, the proper class loader will be invoked to
1170 load and link the named class. When FindClass is called through
1171 the Invocation Interface, there is no current native method or
1172 its associated class loader. In that case, the result of
1173 ClassLoader.getBaseClassLoader is used." */
1175 cc = stacktrace_getCurrentClass();
1178 c = load_class_from_sysloader(u);
1180 c = load_class_from_classloader(u, cc->classloader);
1188 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1190 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1192 /* keep compiler happy */
1199 /* GetSuperclass ***************************************************************
1201 If clazz represents any class other than the class Object, then
1202 this function returns the object that represents the superclass of
1203 the class specified by clazz.
1205 *******************************************************************************/
1207 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1211 STATISTICS(jniinvokation());
1213 c = ((classinfo *) sub)->super.cls;
1218 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1222 /* IsAssignableFrom ************************************************************
1224 Determines whether an object of sub can be safely cast to sup.
1226 *******************************************************************************/
1228 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1230 java_lang_Class *csup;
1231 java_lang_Class *csub;
1233 csup = (java_lang_Class *) sup;
1234 csub = (java_lang_Class *) sub;
1236 STATISTICS(jniinvokation());
1238 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1242 /* Throw ***********************************************************************
1244 Causes a java.lang.Throwable object to be thrown.
1246 *******************************************************************************/
1248 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1250 java_objectheader *o;
1252 STATISTICS(jniinvokation());
1254 o = (java_objectheader *) obj;
1256 exceptions_set_exception(o);
1262 /* ThrowNew ********************************************************************
1264 Constructs an exception object from the specified class with the
1265 message specified by message and causes that exception to be
1268 *******************************************************************************/
1270 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1273 java_objectheader *o;
1274 java_objectheader *s;
1276 STATISTICS(jniinvokation());
1278 c = (classinfo *) clazz;
1279 s = javastring_new_from_utf_string(msg);
1281 /* instantiate exception object */
1283 o = native_new_and_init_string(c, s);
1288 exceptions_set_exception(o);
1294 /* ExceptionOccurred ***********************************************************
1296 Determines if an exception is being thrown. The exception stays
1297 being thrown until either the native code calls ExceptionClear(),
1298 or the Java code handles the exception.
1300 *******************************************************************************/
1302 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1304 java_objectheader *o;
1306 STATISTICS(jniinvokation());
1308 o = exceptions_get_exception();
1310 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1314 /* ExceptionDescribe ***********************************************************
1316 Prints an exception and a backtrace of the stack to a system
1317 error-reporting channel, such as stderr. This is a convenience
1318 routine provided for debugging.
1320 *******************************************************************************/
1322 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1324 java_objectheader *o;
1327 STATISTICS(jniinvokation());
1329 o = exceptions_get_exception();
1332 /* clear exception, because we are calling jit code again */
1334 exceptions_clear_exception();
1336 /* get printStackTrace method from exception class */
1338 m = class_resolveclassmethod(o->vftbl->class,
1339 utf_printStackTrace,
1345 /* XXX what should we do? */
1348 /* print the stacktrace */
1350 (void) vm_call_method(m, o);
1355 /* ExceptionClear **************************************************************
1357 Clears any exception that is currently being thrown. If no
1358 exception is currently being thrown, this routine has no effect.
1360 *******************************************************************************/
1362 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1364 STATISTICS(jniinvokation());
1366 exceptions_clear_exception();
1370 /* FatalError ******************************************************************
1372 Raises a fatal error and does not expect the VM to recover. This
1373 function does not return.
1375 *******************************************************************************/
1377 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1379 STATISTICS(jniinvokation());
1381 /* this seems to be the best way */
1387 /* PushLocalFrame **************************************************************
1389 Creates a new local reference frame, in which at least a given
1390 number of local references can be created.
1392 *******************************************************************************/
1394 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1397 localref_table *lrt;
1398 localref_table *nlrt;
1400 STATISTICS(jniinvokation());
1405 /* Allocate new local reference table on Java heap. Calculate the
1406 additional memory we have to allocate. */
1408 if (capacity > LOCALREFTABLE_CAPACITY)
1409 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1413 #if defined(ENABLE_GC_CACAO)
1414 nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1416 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1422 /* get current local reference table from thread */
1424 lrt = LOCALREFTABLE;
1426 /* Set up the new local reference table and add it to the local
1429 nlrt->capacity = capacity;
1431 nlrt->localframes = lrt->localframes + 1;
1434 /* store new local reference table in thread */
1436 LOCALREFTABLE = nlrt;
1442 /* PopLocalFrame ***************************************************************
1444 Pops off the current local reference frame, frees all the local
1445 references, and returns a local reference in the previous local
1446 reference frame for the given result object.
1448 *******************************************************************************/
1450 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1452 localref_table *lrt;
1453 localref_table *plrt;
1457 STATISTICS(jniinvokation());
1459 /* get current local reference table from thread */
1461 lrt = LOCALREFTABLE;
1463 localframes = lrt->localframes;
1465 /* Don't delete the top local frame, as this one is allocated in
1466 the native stub on the stack and is freed automagically on
1469 if (localframes == 1)
1470 return _Jv_JNI_NewLocalRef(env, result);
1472 /* release all current local frames */
1474 for (; localframes >= 1; localframes--) {
1475 /* get previous frame */
1479 /* clear all reference entries */
1481 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1485 #if defined(ENABLE_GC_CACAO)
1486 /* for the exact GC local reference tables are not on the heap,
1487 so we need to free them explicitly here. */
1489 if (lrt->capacity > LOCALREFTABLE_CAPACITY)
1490 additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
1494 MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1497 /* set new local references table */
1502 /* store new local reference table in thread */
1504 LOCALREFTABLE = lrt;
1506 /* add local reference and return the value */
1508 return _Jv_JNI_NewLocalRef(env, result);
1512 /* DeleteLocalRef **************************************************************
1514 Deletes the local reference pointed to by localRef.
1516 *******************************************************************************/
1518 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1520 java_objectheader *o;
1521 localref_table *lrt;
1524 STATISTICS(jniinvokation());
1526 o = (java_objectheader *) localRef;
1528 /* get local reference table (thread specific) */
1530 lrt = LOCALREFTABLE;
1532 /* go through all local frames */
1534 for (; lrt != NULL; lrt = lrt->prev) {
1536 /* and try to remove the reference */
1538 for (i = 0; i < lrt->capacity; i++) {
1539 if (lrt->refs[i] == o) {
1540 lrt->refs[i] = NULL;
1548 /* this should not happen */
1550 /* if (opt_checkjni) */
1551 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1552 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1556 /* IsSameObject ****************************************************************
1558 Tests whether two references refer to the same Java object.
1560 *******************************************************************************/
1562 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1564 STATISTICS(jniinvokation());
1573 /* NewLocalRef *****************************************************************
1575 Creates a new local reference that refers to the same object as ref.
1577 *******************************************************************************/
1579 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1581 localref_table *lrt;
1584 STATISTICS(jniinvokation());
1589 /* get local reference table (thread specific) */
1591 lrt = LOCALREFTABLE;
1593 /* Check if we have space for the requested reference? No,
1594 allocate a new frame. This is actually not what the spec says,
1595 but for compatibility reasons... */
1597 if (lrt->used == lrt->capacity) {
1598 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1601 /* get the new local reference table */
1603 lrt = LOCALREFTABLE;
1606 /* insert the reference */
1608 for (i = 0; i < lrt->capacity; i++) {
1609 if (lrt->refs[i] == NULL) {
1610 lrt->refs[i] = (java_objectheader *) ref;
1617 /* should not happen, just to be sure */
1621 /* keep compiler happy */
1627 /* EnsureLocalCapacity *********************************************************
1629 Ensures that at least a given number of local references can be
1630 created in the current thread
1632 *******************************************************************************/
1634 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1636 localref_table *lrt;
1638 STATISTICS(jniinvokation());
1640 /* get local reference table (thread specific) */
1642 lrt = LOCALREFTABLE;
1644 /* check if capacity elements are available in the local references table */
1646 if ((lrt->used + capacity) > lrt->capacity)
1647 return _Jv_JNI_PushLocalFrame(env, capacity);
1653 /* AllocObject *****************************************************************
1655 Allocates a new Java object without invoking any of the
1656 constructors for the object. Returns a reference to the object.
1658 *******************************************************************************/
1660 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1663 java_objectheader *o;
1665 STATISTICS(jniinvokation());
1667 c = (classinfo *) clazz;
1669 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1670 exceptions_throw_instantiationexception(c);
1676 return _Jv_JNI_NewLocalRef(env, o);
1680 /* NewObject *******************************************************************
1682 Programmers place all arguments that are to be passed to the
1683 constructor immediately following the methodID
1684 argument. NewObject() accepts these arguments and passes them to
1685 the Java method that the programmer wishes to invoke.
1687 *******************************************************************************/
1689 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1691 java_objectheader *o;
1695 STATISTICS(jniinvokation());
1697 m = (methodinfo *) methodID;
1701 o = builtin_new(clazz);
1706 /* call constructor */
1708 va_start(ap, methodID);
1709 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1712 return _Jv_JNI_NewLocalRef(env, o);
1716 /* NewObjectV ******************************************************************
1718 Programmers place all arguments that are to be passed to the
1719 constructor in an args argument of type va_list that immediately
1720 follows the methodID argument. NewObjectV() accepts these
1721 arguments, and, in turn, passes them to the Java method that the
1722 programmer wishes to invoke.
1724 *******************************************************************************/
1726 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1729 java_objectheader *o;
1732 STATISTICS(jniinvokation());
1734 m = (methodinfo *) methodID;
1738 o = builtin_new(clazz);
1743 /* call constructor */
1745 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1747 return _Jv_JNI_NewLocalRef(env, o);
1751 /* NewObjectA *****************************************************************
1753 Programmers place all arguments that are to be passed to the
1754 constructor in an args array of jvalues that immediately follows
1755 the methodID argument. NewObjectA() accepts the arguments in this
1756 array, and, in turn, passes them to the Java method that the
1757 programmer wishes to invoke.
1759 *******************************************************************************/
1761 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1764 java_objectheader *o;
1767 STATISTICS(jniinvokation());
1769 m = (methodinfo *) methodID;
1773 o = builtin_new(clazz);
1778 /* call constructor */
1780 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1782 return _Jv_JNI_NewLocalRef(env, o);
1786 /* GetObjectClass **************************************************************
1788 Returns the class of an object.
1790 *******************************************************************************/
1792 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1794 java_objectheader *o;
1797 STATISTICS(jniinvokation());
1799 o = (java_objectheader *) obj;
1801 if ((o == NULL) || (o->vftbl == NULL))
1804 c = o->vftbl->class;
1806 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1810 /* IsInstanceOf ****************************************************************
1812 Tests whether an object is an instance of a class.
1814 *******************************************************************************/
1816 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1819 java_lang_Object *o;
1821 STATISTICS(jniinvokation());
1823 c = (java_lang_Class *) clazz;
1824 o = (java_lang_Object *) obj;
1826 return _Jv_java_lang_Class_isInstance(c, o);
1830 /* Reflection Support *********************************************************/
1832 /* FromReflectedMethod *********************************************************
1834 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1835 object to a method ID.
1837 *******************************************************************************/
1839 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1841 #if defined(ENABLE_JAVASE)
1846 STATISTICS(jniinvokation());
1851 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1852 java_lang_reflect_Method *rm;
1854 rm = (java_lang_reflect_Method *) method;
1855 c = (classinfo *) (rm->declaringClass);
1858 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1859 java_lang_reflect_Constructor *rc;
1861 rc = (java_lang_reflect_Constructor *) method;
1862 c = (classinfo *) (rc->clazz);
1868 mi = &(c->methods[slot]);
1870 return (jmethodID) mi;
1872 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1874 /* keep compiler happy */
1881 /* FromReflectedField **********************************************************
1883 Converts a java.lang.reflect.Field to a field ID.
1885 *******************************************************************************/
1887 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1889 #if defined(ENABLE_JAVASE)
1890 java_lang_reflect_Field *rf;
1894 STATISTICS(jniinvokation());
1896 rf = (java_lang_reflect_Field *) field;
1901 c = (classinfo *) rf->declaringClass;
1903 f = &(c->fields[rf->slot]);
1905 return (jfieldID) f;
1907 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1909 /* keep compiler happy */
1916 /* ToReflectedMethod ***********************************************************
1918 Converts a method ID derived from cls to an instance of the
1919 java.lang.reflect.Method class or to an instance of the
1920 java.lang.reflect.Constructor class.
1922 *******************************************************************************/
1924 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1927 STATISTICS(jniinvokation());
1929 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1935 /* ToReflectedField ************************************************************
1937 Converts a field ID derived from cls to an instance of the
1938 java.lang.reflect.Field class.
1940 *******************************************************************************/
1942 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1945 STATISTICS(jniinvokation());
1947 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1953 /* Calling Instance Methods ***************************************************/
1955 /* GetMethodID *****************************************************************
1957 Returns the method ID for an instance (nonstatic) method of a class
1958 or interface. The method may be defined in one of the clazz's
1959 superclasses and inherited by clazz. The method is determined by
1960 its name and signature.
1962 GetMethodID() causes an uninitialized class to be initialized.
1964 *******************************************************************************/
1966 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1974 STATISTICS(jniinvokation());
1976 c = (classinfo *) clazz;
1981 if (!(c->state & CLASS_INITIALIZED))
1982 if (!initialize_class(c))
1985 /* try to get the method of the class or one of it's superclasses */
1987 uname = utf_new_char((char *) name);
1988 udesc = utf_new_char((char *) sig);
1990 m = class_resolvemethod(clazz, uname, udesc);
1992 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1993 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1998 return (jmethodID) m;
2002 /* JNI-functions for calling instance methods *********************************/
2004 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2007 java_objectheader *o;
2009 java_objectheader *ret;
2012 o = (java_objectheader *) obj;
2013 m = (methodinfo *) methodID;
2015 va_start(ap, methodID);
2016 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2019 return _Jv_JNI_NewLocalRef(env, ret);
2023 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2026 java_objectheader *o;
2028 java_objectheader *ret;
2030 o = (java_objectheader *) obj;
2031 m = (methodinfo *) methodID;
2033 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2035 return _Jv_JNI_NewLocalRef(env, ret);
2039 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2042 java_objectheader *o;
2044 java_objectheader *ret;
2046 o = (java_objectheader *) obj;
2047 m = (methodinfo *) methodID;
2049 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2051 return _Jv_JNI_NewLocalRef(env, ret);
2055 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2058 java_objectheader *o;
2063 o = (java_objectheader *) obj;
2064 m = (methodinfo *) methodID;
2066 va_start(ap, methodID);
2067 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2074 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2075 jmethodID methodID, va_list args)
2077 java_objectheader *o;
2081 o = (java_objectheader *) obj;
2082 m = (methodinfo *) methodID;
2084 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2090 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2091 jmethodID methodID, jvalue *args)
2093 java_objectheader *o;
2097 o = (java_objectheader *) obj;
2098 m = (methodinfo *) methodID;
2100 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2106 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2108 java_objectheader *o;
2113 o = (java_objectheader *) obj;
2114 m = (methodinfo *) methodID;
2116 va_start(ap, methodID);
2117 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2125 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2128 java_objectheader *o;
2132 o = (java_objectheader *) obj;
2133 m = (methodinfo *) methodID;
2135 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2141 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2144 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2150 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2152 java_objectheader *o;
2157 o = (java_objectheader *) obj;
2158 m = (methodinfo *) methodID;
2160 va_start(ap, methodID);
2161 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2168 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2171 java_objectheader *o;
2175 o = (java_objectheader *) obj;
2176 m = (methodinfo *) methodID;
2178 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2184 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2187 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2193 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2196 java_objectheader *o;
2201 o = (java_objectheader *) obj;
2202 m = (methodinfo *) methodID;
2204 va_start(ap, methodID);
2205 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2212 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2215 java_objectheader *o;
2219 o = (java_objectheader *) obj;
2220 m = (methodinfo *) methodID;
2222 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2228 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2231 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2238 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2240 java_objectheader *o;
2245 o = (java_objectheader *) obj;
2246 m = (methodinfo *) methodID;
2248 va_start(ap, methodID);
2249 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2256 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2259 java_objectheader *o;
2263 o = (java_objectheader *) obj;
2264 m = (methodinfo *) methodID;
2266 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2272 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2275 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2282 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2284 java_objectheader *o;
2289 o = (java_objectheader *) obj;
2290 m = (methodinfo *) methodID;
2292 va_start(ap, methodID);
2293 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2300 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2303 java_objectheader *o;
2307 o = (java_objectheader *) obj;
2308 m = (methodinfo *) methodID;
2310 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2316 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2319 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2326 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2329 java_objectheader *o;
2334 o = (java_objectheader *) obj;
2335 m = (methodinfo *) methodID;
2337 va_start(ap, methodID);
2338 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2345 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2348 java_objectheader *o;
2352 o = (java_objectheader *) obj;
2353 m = (methodinfo *) methodID;
2355 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2361 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2364 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2371 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2374 java_objectheader *o;
2379 o = (java_objectheader *) obj;
2380 m = (methodinfo *) methodID;
2382 va_start(ap, methodID);
2383 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2390 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2393 java_objectheader *o;
2397 o = (java_objectheader *) obj;
2398 m = (methodinfo *) methodID;
2400 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2406 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2409 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2416 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2418 java_objectheader *o;
2422 o = (java_objectheader *) obj;
2423 m = (methodinfo *) methodID;
2425 va_start(ap, methodID);
2426 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2431 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2434 java_objectheader *o;
2437 o = (java_objectheader *) obj;
2438 m = (methodinfo *) methodID;
2440 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2444 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2447 java_objectheader *o;
2450 o = (java_objectheader *) obj;
2451 m = (methodinfo *) methodID;
2453 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2458 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2459 jclass clazz, jmethodID methodID,
2462 java_objectheader *o;
2465 java_objectheader *r;
2468 o = (java_objectheader *) obj;
2469 c = (classinfo *) clazz;
2470 m = (methodinfo *) methodID;
2472 va_start(ap, methodID);
2473 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2476 return _Jv_JNI_NewLocalRef(env, r);
2480 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2481 jclass clazz, jmethodID methodID,
2484 java_objectheader *o;
2487 java_objectheader *r;
2489 o = (java_objectheader *) obj;
2490 c = (classinfo *) clazz;
2491 m = (methodinfo *) methodID;
2493 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2495 return _Jv_JNI_NewLocalRef(env, r);
2499 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2500 jclass clazz, jmethodID methodID,
2503 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2505 return _Jv_JNI_NewLocalRef(env, NULL);
2510 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2511 jclass clazz, jmethodID methodID,
2514 java_objectheader *o;
2520 o = (java_objectheader *) obj;
2521 c = (classinfo *) clazz;
2522 m = (methodinfo *) methodID;
2524 va_start(ap, methodID);
2525 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2532 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2533 jclass clazz, jmethodID methodID,
2536 java_objectheader *o;
2541 o = (java_objectheader *) obj;
2542 c = (classinfo *) clazz;
2543 m = (methodinfo *) methodID;
2545 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2551 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2552 jclass clazz, jmethodID methodID,
2555 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2561 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2562 jmethodID methodID, ...)
2564 java_objectheader *o;
2570 o = (java_objectheader *) obj;
2571 c = (classinfo *) clazz;
2572 m = (methodinfo *) methodID;
2574 va_start(ap, methodID);
2575 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2582 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2583 jmethodID methodID, va_list args)
2585 java_objectheader *o;
2590 o = (java_objectheader *) obj;
2591 c = (classinfo *) clazz;
2592 m = (methodinfo *) methodID;
2594 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2600 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2601 jmethodID methodID, jvalue *args)
2603 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2610 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2611 jmethodID methodID, ...)
2613 java_objectheader *o;
2619 o = (java_objectheader *) obj;
2620 c = (classinfo *) clazz;
2621 m = (methodinfo *) methodID;
2623 va_start(ap, methodID);
2624 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2631 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2632 jmethodID methodID, va_list args)
2634 java_objectheader *o;
2639 o = (java_objectheader *) obj;
2640 c = (classinfo *) clazz;
2641 m = (methodinfo *) methodID;
2643 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2649 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2650 jmethodID methodID, jvalue *args)
2652 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2659 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2660 jclass clazz, jmethodID methodID, ...)
2662 java_objectheader *o;
2668 o = (java_objectheader *) obj;
2669 c = (classinfo *) clazz;
2670 m = (methodinfo *) methodID;
2672 va_start(ap, methodID);
2673 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2680 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2681 jclass clazz, jmethodID methodID,
2684 java_objectheader *o;
2689 o = (java_objectheader *) obj;
2690 c = (classinfo *) clazz;
2691 m = (methodinfo *) methodID;
2693 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2699 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2700 jclass clazz, jmethodID methodID,
2703 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2710 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2711 jmethodID methodID, ...)
2713 java_objectheader *o;
2719 o = (java_objectheader *) obj;
2720 c = (classinfo *) clazz;
2721 m = (methodinfo *) methodID;
2723 va_start(ap, methodID);
2724 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2731 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2732 jmethodID methodID, va_list args)
2734 java_objectheader *o;
2739 o = (java_objectheader *) obj;
2740 c = (classinfo *) clazz;
2741 m = (methodinfo *) methodID;
2743 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2749 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2750 jmethodID methodID, jvalue *args)
2752 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2759 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2760 jmethodID methodID, ...)
2762 java_objectheader *o;
2768 o = (java_objectheader *) obj;
2769 c = (classinfo *) clazz;
2770 m = (methodinfo *) methodID;
2772 va_start(ap, methodID);
2773 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2780 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2781 jmethodID methodID, va_list args)
2783 java_objectheader *o;
2788 o = (java_objectheader *) obj;
2789 c = (classinfo *) clazz;
2790 m = (methodinfo *) methodID;
2792 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2798 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2799 jmethodID methodID, jvalue *args)
2801 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2808 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2809 jclass clazz, jmethodID methodID, ...)
2811 java_objectheader *o;
2817 o = (java_objectheader *) obj;
2818 c = (classinfo *) clazz;
2819 m = (methodinfo *) methodID;
2821 va_start(ap, methodID);
2822 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2829 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2830 jclass clazz, jmethodID methodID,
2833 java_objectheader *o;
2838 o = (java_objectheader *) obj;
2839 c = (classinfo *) clazz;
2840 m = (methodinfo *) methodID;
2842 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2848 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2849 jclass clazz, jmethodID methodID,
2852 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2859 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2860 jclass clazz, jmethodID methodID,
2863 java_objectheader *o;
2869 o = (java_objectheader *) obj;
2870 c = (classinfo *) clazz;
2871 m = (methodinfo *) methodID;
2873 va_start(ap, methodID);
2874 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2881 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2882 jclass clazz, jmethodID methodID,
2885 java_objectheader *o;
2890 o = (java_objectheader *) obj;
2891 c = (classinfo *) clazz;
2892 m = (methodinfo *) methodID;
2894 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2900 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2901 jclass clazz, jmethodID methodID,
2904 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2911 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2912 jmethodID methodID, ...)
2914 java_objectheader *o;
2919 o = (java_objectheader *) obj;
2920 c = (classinfo *) clazz;
2921 m = (methodinfo *) methodID;
2923 va_start(ap, methodID);
2924 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2929 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2930 jmethodID methodID, va_list args)
2932 java_objectheader *o;
2936 o = (java_objectheader *) obj;
2937 c = (classinfo *) clazz;
2938 m = (methodinfo *) methodID;
2940 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2944 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2945 jmethodID methodID, jvalue * args)
2947 java_objectheader *o;
2951 o = (java_objectheader *) obj;
2952 c = (classinfo *) clazz;
2953 m = (methodinfo *) methodID;
2955 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2959 /* Accessing Fields of Objects ************************************************/
2961 /* GetFieldID ******************************************************************
2963 Returns the field ID for an instance (nonstatic) field of a
2964 class. The field is specified by its name and signature. The
2965 Get<type>Field and Set<type>Field families of accessor functions
2966 use field IDs to retrieve object fields.
2968 *******************************************************************************/
2970 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2978 STATISTICS(jniinvokation());
2980 c = (classinfo *) clazz;
2982 uname = utf_new_char((char *) name);
2983 udesc = utf_new_char((char *) sig);
2985 f = class_findfield(clazz, uname, udesc);
2988 exceptions_throw_nosuchfielderror(c, uname);
2990 return (jfieldID) f;
2994 /* Get<type>Field Routines *****************************************************
2996 This family of accessor routines returns the value of an instance
2997 (nonstatic) field of an object. The field to access is specified by
2998 a field ID obtained by calling GetFieldID().
3000 *******************************************************************************/
3002 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3004 java_objectheader *o;
3006 STATISTICS(jniinvokation());
3008 o = GET_FIELD(obj, java_objectheader*, fieldID);
3010 return _Jv_JNI_NewLocalRef(env, o);
3014 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3018 STATISTICS(jniinvokation());
3020 i = GET_FIELD(obj, s4, fieldID);
3022 return (jboolean) i;
3026 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3030 STATISTICS(jniinvokation());
3032 i = GET_FIELD(obj, s4, fieldID);
3038 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3042 STATISTICS(jniinvokation());
3044 i = GET_FIELD(obj, s4, fieldID);
3050 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3054 STATISTICS(jniinvokation());
3056 i = GET_FIELD(obj, s4, fieldID);
3062 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3064 java_objectheader *o;
3068 STATISTICS(jniinvokation());
3070 o = (java_objectheader *) obj;
3071 f = (fieldinfo *) fieldID;
3073 i = GET_FIELD(o, s4, f);
3079 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3083 STATISTICS(jniinvokation());
3085 l = GET_FIELD(obj, s8, fieldID);
3091 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3095 STATISTICS(jniinvokation());
3097 f = GET_FIELD(obj, float, fieldID);
3103 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3107 STATISTICS(jniinvokation());
3109 d = GET_FIELD(obj, double, fieldID);
3115 /* Set<type>Field Routines *****************************************************
3117 This family of accessor routines sets the value of an instance
3118 (nonstatic) field of an object. The field to access is specified by
3119 a field ID obtained by calling GetFieldID().
3121 *******************************************************************************/
3123 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3126 STATISTICS(jniinvokation());
3128 SET_FIELD(obj, java_objectheader*, fieldID, value);
3132 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3135 STATISTICS(jniinvokation());
3137 SET_FIELD(obj, s4, fieldID, value);
3141 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3144 STATISTICS(jniinvokation());
3146 SET_FIELD(obj, s4, fieldID, value);
3150 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3153 STATISTICS(jniinvokation());
3155 SET_FIELD(obj, s4, fieldID, value);
3159 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3162 STATISTICS(jniinvokation());
3164 SET_FIELD(obj, s4, fieldID, value);
3168 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3170 STATISTICS(jniinvokation());
3172 SET_FIELD(obj, s4, fieldID, value);
3176 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3179 STATISTICS(jniinvokation());
3181 SET_FIELD(obj, s8, fieldID, value);
3185 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3188 STATISTICS(jniinvokation());
3190 SET_FIELD(obj, float, fieldID, value);
3194 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3197 STATISTICS(jniinvokation());
3199 SET_FIELD(obj, double, fieldID, value);
3203 /* Calling Static Methods *****************************************************/
3205 /* GetStaticMethodID ***********************************************************
3207 Returns the method ID for a static method of a class. The method is
3208 specified by its name and signature.
3210 GetStaticMethodID() causes an uninitialized class to be
3213 *******************************************************************************/
3215 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3223 STATISTICS(jniinvokation());
3225 c = (classinfo *) clazz;
3230 if (!(c->state & CLASS_INITIALIZED))
3231 if (!initialize_class(c))
3234 /* try to get the static method of the class */
3236 uname = utf_new_char((char *) name);
3237 udesc = utf_new_char((char *) sig);
3239 m = class_resolvemethod(c, uname, udesc);
3241 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3242 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3247 return (jmethodID) m;
3251 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3252 jmethodID methodID, ...)
3255 java_objectheader *o;
3258 m = (methodinfo *) methodID;
3260 va_start(ap, methodID);
3261 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3264 return _Jv_JNI_NewLocalRef(env, o);
3268 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3269 jmethodID methodID, va_list args)
3272 java_objectheader *o;
3274 m = (methodinfo *) methodID;
3276 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3278 return _Jv_JNI_NewLocalRef(env, o);
3282 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3283 jmethodID methodID, jvalue *args)
3286 java_objectheader *o;
3288 m = (methodinfo *) methodID;
3290 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3292 return _Jv_JNI_NewLocalRef(env, o);
3296 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3297 jmethodID methodID, ...)
3303 m = (methodinfo *) methodID;
3305 va_start(ap, methodID);
3306 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3313 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3314 jmethodID methodID, va_list args)
3319 m = (methodinfo *) methodID;
3321 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3327 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3328 jmethodID methodID, jvalue *args)
3330 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3336 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3337 jmethodID methodID, ...)
3343 m = (methodinfo *) methodID;
3345 va_start(ap, methodID);
3346 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3353 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3354 jmethodID methodID, va_list args)
3359 m = (methodinfo *) methodID;
3361 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3367 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3368 jmethodID methodID, jvalue *args)
3370 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3376 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3377 jmethodID methodID, ...)
3383 m = (methodinfo *) methodID;
3385 va_start(ap, methodID);
3386 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3393 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3394 jmethodID methodID, va_list args)
3399 m = (methodinfo *) methodID;
3401 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3407 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3408 jmethodID methodID, jvalue *args)
3410 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3416 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3417 jmethodID methodID, ...)
3423 m = (methodinfo *) methodID;
3425 va_start(ap, methodID);
3426 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3433 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3434 jmethodID methodID, va_list args)
3439 m = (methodinfo *) methodID;
3441 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3447 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3448 jmethodID methodID, jvalue *args)
3450 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3456 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3463 m = (methodinfo *) methodID;
3465 va_start(ap, methodID);
3466 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3473 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3474 jmethodID methodID, va_list args)
3479 m = (methodinfo *) methodID;
3481 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3487 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3488 jmethodID methodID, jvalue *args)
3490 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3496 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3497 jmethodID methodID, ...)
3503 m = (methodinfo *) methodID;
3505 va_start(ap, methodID);
3506 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3513 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3514 jmethodID methodID, va_list args)
3519 m = (methodinfo *) methodID;
3521 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3527 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3528 jmethodID methodID, jvalue *args)
3530 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3537 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3538 jmethodID methodID, ...)
3544 m = (methodinfo *) methodID;
3546 va_start(ap, methodID);
3547 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3554 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3555 jmethodID methodID, va_list args)
3560 m = (methodinfo *) methodID;
3562 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3568 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3569 jmethodID methodID, jvalue *args)
3571 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3577 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3578 jmethodID methodID, ...)
3584 m = (methodinfo *) methodID;
3586 va_start(ap, methodID);
3587 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3594 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3595 jmethodID methodID, va_list args)
3600 m = (methodinfo *) methodID;
3602 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3608 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3609 jmethodID methodID, jvalue *args)
3611 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3617 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3618 jmethodID methodID, ...)
3623 m = (methodinfo *) methodID;
3625 va_start(ap, methodID);
3626 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3631 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3632 jmethodID methodID, va_list args)
3636 m = (methodinfo *) methodID;
3638 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3642 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3643 jmethodID methodID, jvalue * args)
3647 m = (methodinfo *) methodID;
3649 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3653 /* Accessing Static Fields ****************************************************/
3655 /* GetStaticFieldID ************************************************************
3657 Returns the field ID for a static field of a class. The field is
3658 specified by its name and signature. The GetStatic<type>Field and
3659 SetStatic<type>Field families of accessor functions use field IDs
3660 to retrieve static fields.
3662 *******************************************************************************/
3664 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3672 STATISTICS(jniinvokation());
3674 c = (classinfo *) clazz;
3676 uname = utf_new_char((char *) name);
3677 usig = utf_new_char((char *) sig);
3679 f = class_findfield(clazz, uname, usig);
3682 exceptions_throw_nosuchfielderror(c, uname);
3684 return (jfieldID) f;
3688 /* GetStatic<type>Field ********************************************************
3690 This family of accessor routines returns the value of a static
3693 *******************************************************************************/
3695 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3701 STATISTICS(jniinvokation());
3703 c = (classinfo *) clazz;
3704 f = (fieldinfo *) fieldID;
3706 if (!(c->state & CLASS_INITIALIZED))
3707 if (!initialize_class(c))
3710 return _Jv_JNI_NewLocalRef(env, f->value.a);
3714 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3720 STATISTICS(jniinvokation());
3722 c = (classinfo *) clazz;
3723 f = (fieldinfo *) fieldID;
3725 if (!(c->state & CLASS_INITIALIZED))
3726 if (!initialize_class(c))
3733 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3738 STATISTICS(jniinvokation());
3740 c = (classinfo *) clazz;
3741 f = (fieldinfo *) fieldID;
3743 if (!(c->state & CLASS_INITIALIZED))
3744 if (!initialize_class(c))
3751 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3756 STATISTICS(jniinvokation());
3758 c = (classinfo *) clazz;
3759 f = (fieldinfo *) fieldID;
3761 if (!(c->state & CLASS_INITIALIZED))
3762 if (!initialize_class(c))
3769 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3774 STATISTICS(jniinvokation());
3776 c = (classinfo *) clazz;
3777 f = (fieldinfo *) fieldID;
3779 if (!(c->state & CLASS_INITIALIZED))
3780 if (!initialize_class(c))
3787 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3792 STATISTICS(jniinvokation());
3794 c = (classinfo *) clazz;
3795 f = (fieldinfo *) fieldID;
3797 if (!(c->state & CLASS_INITIALIZED))
3798 if (!initialize_class(c))
3805 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3810 STATISTICS(jniinvokation());
3812 c = (classinfo *) clazz;
3813 f = (fieldinfo *) fieldID;
3815 if (!(c->state & CLASS_INITIALIZED))
3816 if (!initialize_class(c))
3823 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3828 STATISTICS(jniinvokation());
3830 c = (classinfo *) clazz;
3831 f = (fieldinfo *) fieldID;
3833 if (!(c->state & CLASS_INITIALIZED))
3834 if (!initialize_class(c))
3841 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3847 STATISTICS(jniinvokation());
3849 c = (classinfo *) clazz;
3850 f = (fieldinfo *) fieldID;
3852 if (!(c->state & CLASS_INITIALIZED))
3853 if (!initialize_class(c))
3860 /* SetStatic<type>Field *******************************************************
3862 This family of accessor routines sets the value of a static field
3865 *******************************************************************************/
3867 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3873 STATISTICS(jniinvokation());
3875 c = (classinfo *) clazz;
3876 f = (fieldinfo *) fieldID;
3878 if (!(c->state & CLASS_INITIALIZED))
3879 if (!initialize_class(c))
3886 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3892 STATISTICS(jniinvokation());
3894 c = (classinfo *) clazz;
3895 f = (fieldinfo *) fieldID;
3897 if (!(c->state & CLASS_INITIALIZED))
3898 if (!initialize_class(c))
3905 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3911 STATISTICS(jniinvokation());
3913 c = (classinfo *) clazz;
3914 f = (fieldinfo *) fieldID;
3916 if (!(c->state & CLASS_INITIALIZED))
3917 if (!initialize_class(c))
3924 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3930 STATISTICS(jniinvokation());
3932 c = (classinfo *) clazz;
3933 f = (fieldinfo *) fieldID;
3935 if (!(c->state & CLASS_INITIALIZED))
3936 if (!initialize_class(c))
3943 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3949 STATISTICS(jniinvokation());
3951 c = (classinfo *) clazz;
3952 f = (fieldinfo *) fieldID;
3954 if (!(c->state & CLASS_INITIALIZED))
3955 if (!initialize_class(c))
3962 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3968 STATISTICS(jniinvokation());
3970 c = (classinfo *) clazz;
3971 f = (fieldinfo *) fieldID;
3973 if (!(c->state & CLASS_INITIALIZED))
3974 if (!initialize_class(c))
3981 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3987 STATISTICS(jniinvokation());
3989 c = (classinfo *) clazz;
3990 f = (fieldinfo *) fieldID;
3992 if (!(c->state & CLASS_INITIALIZED))
3993 if (!initialize_class(c))
4000 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4006 STATISTICS(jniinvokation());
4008 c = (classinfo *) clazz;
4009 f = (fieldinfo *) fieldID;
4011 if (!(c->state & CLASS_INITIALIZED))
4012 if (!initialize_class(c))
4019 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4025 STATISTICS(jniinvokation());
4027 c = (classinfo *) clazz;
4028 f = (fieldinfo *) fieldID;
4030 if (!(c->state & CLASS_INITIALIZED))
4031 if (!initialize_class(c))
4038 /* String Operations **********************************************************/
4040 /* NewString *******************************************************************
4042 Create new java.lang.String object from an array of Unicode
4045 *******************************************************************************/
4047 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4049 java_lang_String *s;
4053 STATISTICS(jniinvokation());
4055 s = (java_lang_String *) builtin_new(class_java_lang_String);
4056 a = builtin_newarray_char(len);
4058 /* javastring or characterarray could not be created */
4059 if ((a == NULL) || (s == NULL))
4063 for (i = 0; i < len; i++)
4064 a->data[i] = buf[i];
4070 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4074 static jchar emptyStringJ[]={0,0};
4076 /* GetStringLength *************************************************************
4078 Returns the length (the count of Unicode characters) of a Java
4081 *******************************************************************************/
4083 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4085 return ((java_lang_String *) str)->count;
4089 /******************** convertes javastring to u2-array ****************************/
4091 u2 *javastring_tou2(jstring so)
4093 java_lang_String *s;
4098 STATISTICS(jniinvokation());
4100 s = (java_lang_String *) so;
4110 /* allocate memory */
4112 stringbuffer = MNEW(u2, s->count + 1);
4116 for (i = 0; i < s->count; i++)
4117 stringbuffer[i] = a->data[s->offset + i];
4119 /* terminate string */
4121 stringbuffer[i] = '\0';
4123 return stringbuffer;
4127 /* GetStringChars **************************************************************
4129 Returns a pointer to the array of Unicode characters of the
4130 string. This pointer is valid until ReleaseStringChars() is called.
4132 *******************************************************************************/
4134 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4138 STATISTICS(jniinvokation());
4140 jc = javastring_tou2(str);
4152 return emptyStringJ;
4156 /* ReleaseStringChars **********************************************************
4158 Informs the VM that the native code no longer needs access to
4159 chars. The chars argument is a pointer obtained from string using
4162 *******************************************************************************/
4164 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4166 STATISTICS(jniinvokation());
4168 if (chars == emptyStringJ)
4171 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4175 /* NewStringUTF ****************************************************************
4177 Constructs a new java.lang.String object from an array of UTF-8
4180 *******************************************************************************/
4182 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4184 java_lang_String *s;
4186 STATISTICS(jniinvokation());
4188 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4190 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4194 /****************** returns the utf8 length in bytes of a string *******************/
4196 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4198 java_lang_String *s = (java_lang_String*) string;
4200 STATISTICS(jniinvokation());
4202 return (jsize) u2_utflength(s->value->data, s->count);
4206 /* GetStringUTFChars ***********************************************************
4208 Returns a pointer to an array of UTF-8 characters of the
4209 string. This array is valid until it is released by
4210 ReleaseStringUTFChars().
4212 *******************************************************************************/
4214 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4219 STATISTICS(jniinvokation());
4227 u = javastring_toutf((java_objectheader *) string, false);
4236 /* ReleaseStringUTFChars *******************************************************
4238 Informs the VM that the native code no longer needs access to
4239 utf. The utf argument is a pointer derived from string using
4240 GetStringUTFChars().
4242 *******************************************************************************/
4244 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4246 STATISTICS(jniinvokation());
4248 /* XXX we don't release utf chars right now, perhaps that should be done
4249 later. Since there is always one reference the garbage collector will
4254 /* Array Operations ***********************************************************/
4256 /* GetArrayLength **************************************************************
4258 Returns the number of elements in the array.
4260 *******************************************************************************/
4262 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4264 java_arrayheader *a;
4266 STATISTICS(jniinvokation());
4268 a = (java_arrayheader *) array;
4274 /* NewObjectArray **************************************************************
4276 Constructs a new array holding objects in class elementClass. All
4277 elements are initially set to initialElement.
4279 *******************************************************************************/
4281 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4282 jclass elementClass, jobject initialElement)
4284 java_objectarray *oa;
4287 STATISTICS(jniinvokation());
4290 exceptions_throw_negativearraysizeexception();
4294 oa = builtin_anewarray(length, elementClass);
4299 /* set all elements to initialElement */
4301 for (i = 0; i < length; i++)
4302 oa->data[i] = initialElement;
4304 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4308 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4311 java_objectarray *oa;
4314 STATISTICS(jniinvokation());
4316 oa = (java_objectarray *) array;
4318 if (index >= oa->header.size) {
4319 exceptions_throw_arrayindexoutofboundsexception();
4323 o = oa->data[index];
4325 return _Jv_JNI_NewLocalRef(env, o);
4329 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4330 jsize index, jobject val)
4332 java_objectarray *oa;
4333 java_objectheader *o;
4335 STATISTICS(jniinvokation());
4337 oa = (java_objectarray *) array;
4338 o = (java_objectheader *) val;
4340 if (index >= oa->header.size) {
4341 exceptions_throw_arrayindexoutofboundsexception();
4345 /* check if the class of value is a subclass of the element class
4348 if (!builtin_canstore(oa, o))
4351 oa->data[index] = val;
4355 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4357 java_booleanarray *ba;
4359 STATISTICS(jniinvokation());
4362 exceptions_throw_negativearraysizeexception();
4366 ba = builtin_newarray_boolean(len);
4368 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4372 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4376 STATISTICS(jniinvokation());
4379 exceptions_throw_negativearraysizeexception();
4383 ba = builtin_newarray_byte(len);
4385 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4389 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4393 STATISTICS(jniinvokation());
4396 exceptions_throw_negativearraysizeexception();
4400 ca = builtin_newarray_char(len);
4402 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4406 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4408 java_shortarray *sa;
4410 STATISTICS(jniinvokation());
4413 exceptions_throw_negativearraysizeexception();
4417 sa = builtin_newarray_short(len);
4419 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4423 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4427 STATISTICS(jniinvokation());
4430 exceptions_throw_negativearraysizeexception();
4434 ia = builtin_newarray_int(len);
4436 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4440 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4444 STATISTICS(jniinvokation());
4447 exceptions_throw_negativearraysizeexception();
4451 la = builtin_newarray_long(len);
4453 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4457 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4459 java_floatarray *fa;
4461 STATISTICS(jniinvokation());
4464 exceptions_throw_negativearraysizeexception();
4468 fa = builtin_newarray_float(len);
4470 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4474 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4476 java_doublearray *da;
4478 STATISTICS(jniinvokation());
4481 exceptions_throw_negativearraysizeexception();
4485 da = builtin_newarray_double(len);
4487 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4491 /* Get<PrimitiveType>ArrayElements *********************************************
4493 A family of functions that returns the body of the primitive array.
4495 *******************************************************************************/
4497 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4500 java_booleanarray *ba;
4502 STATISTICS(jniinvokation());
4504 ba = (java_booleanarray *) array;
4507 *isCopy = JNI_FALSE;
4513 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4518 STATISTICS(jniinvokation());
4520 ba = (java_bytearray *) array;
4523 *isCopy = JNI_FALSE;
4529 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4534 STATISTICS(jniinvokation());
4536 ca = (java_chararray *) array;
4539 *isCopy = JNI_FALSE;
4545 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4548 java_shortarray *sa;
4550 STATISTICS(jniinvokation());
4552 sa = (java_shortarray *) array;
4555 *isCopy = JNI_FALSE;
4561 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4566 STATISTICS(jniinvokation());
4568 ia = (java_intarray *) array;
4571 *isCopy = JNI_FALSE;
4577 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4582 STATISTICS(jniinvokation());
4584 la = (java_longarray *) array;
4587 *isCopy = JNI_FALSE;
4589 /* We cast this one to prevent a compiler warning on 64-bit
4590 systems since GNU Classpath typedef jlong to long long. */
4592 return (jlong *) la->data;
4596 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4599 java_floatarray *fa;
4601 STATISTICS(jniinvokation());
4603 fa = (java_floatarray *) array;
4606 *isCopy = JNI_FALSE;
4612 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4615 java_doublearray *da;
4617 STATISTICS(jniinvokation());
4619 da = (java_doublearray *) array;
4622 *isCopy = JNI_FALSE;
4628 /* Release<PrimitiveType>ArrayElements *****************************************
4630 A family of functions that informs the VM that the native code no
4631 longer needs access to elems. The elems argument is a pointer
4632 derived from array using the corresponding
4633 Get<PrimitiveType>ArrayElements() function. If necessary, this
4634 function copies back all changes made to elems to the original
4637 *******************************************************************************/
4639 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4640 jboolean *elems, jint mode)
4642 java_booleanarray *ba;
4644 STATISTICS(jniinvokation());
4646 ba = (java_booleanarray *) array;
4648 if (elems != ba->data) {
4651 MCOPY(ba->data, elems, u1, ba->header.size);
4654 MCOPY(ba->data, elems, u1, ba->header.size);
4655 /* XXX TWISTI how should it be freed? */
4658 /* XXX TWISTI how should it be freed? */
4665 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4666 jbyte *elems, jint mode)
4670 STATISTICS(jniinvokation());
4672 ba = (java_bytearray *) array;
4674 if (elems != ba->data) {
4677 MCOPY(ba->data, elems, s1, ba->header.size);
4680 MCOPY(ba->data, elems, s1, ba->header.size);
4681 /* XXX TWISTI how should it be freed? */
4684 /* XXX TWISTI how should it be freed? */
4691 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4692 jchar *elems, jint mode)
4696 STATISTICS(jniinvokation());
4698 ca = (java_chararray *) array;
4700 if (elems != ca->data) {
4703 MCOPY(ca->data, elems, u2, ca->header.size);
4706 MCOPY(ca->data, elems, u2, ca->header.size);
4707 /* XXX TWISTI how should it be freed? */
4710 /* XXX TWISTI how should it be freed? */
4717 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4718 jshort *elems, jint mode)
4720 java_shortarray *sa;
4722 STATISTICS(jniinvokation());
4724 sa = (java_shortarray *) array;
4726 if (elems != sa->data) {
4729 MCOPY(sa->data, elems, s2, sa->header.size);
4732 MCOPY(sa->data, elems, s2, sa->header.size);
4733 /* XXX TWISTI how should it be freed? */
4736 /* XXX TWISTI how should it be freed? */
4743 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4748 STATISTICS(jniinvokation());
4750 ia = (java_intarray *) array;
4752 if (elems != ia->data) {
4755 MCOPY(ia->data, elems, s4, ia->header.size);
4758 MCOPY(ia->data, elems, s4, ia->header.size);
4759 /* XXX TWISTI how should it be freed? */
4762 /* XXX TWISTI how should it be freed? */
4769 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4770 jlong *elems, jint mode)
4774 STATISTICS(jniinvokation());
4776 la = (java_longarray *) array;
4778 /* We cast this one to prevent a compiler warning on 64-bit
4779 systems since GNU Classpath typedef jlong to long long. */
4781 if ((s8 *) elems != la->data) {
4784 MCOPY(la->data, elems, s8, la->header.size);
4787 MCOPY(la->data, elems, s8, la->header.size);
4788 /* XXX TWISTI how should it be freed? */
4791 /* XXX TWISTI how should it be freed? */
4798 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4799 jfloat *elems, jint mode)
4801 java_floatarray *fa;
4803 STATISTICS(jniinvokation());
4805 fa = (java_floatarray *) array;
4807 if (elems != fa->data) {
4810 MCOPY(fa->data, elems, float, fa->header.size);
4813 MCOPY(fa->data, elems, float, fa->header.size);
4814 /* XXX TWISTI how should it be freed? */
4817 /* XXX TWISTI how should it be freed? */
4824 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4825 jdouble *elems, jint mode)
4827 java_doublearray *da;
4829 STATISTICS(jniinvokation());
4831 da = (java_doublearray *) array;
4833 if (elems != da->data) {
4836 MCOPY(da->data, elems, double, da->header.size);
4839 MCOPY(da->data, elems, double, da->header.size);
4840 /* XXX TWISTI how should it be freed? */
4843 /* XXX TWISTI how should it be freed? */
4850 /* Get<PrimitiveType>ArrayRegion **********************************************
4852 A family of functions that copies a region of a primitive array
4855 *******************************************************************************/
4857 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4858 jsize start, jsize len, jboolean *buf)
4860 java_booleanarray *ba;
4862 STATISTICS(jniinvokation());
4864 ba = (java_booleanarray *) array;
4866 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4867 exceptions_throw_arrayindexoutofboundsexception();
4869 MCOPY(buf, &ba->data[start], u1, len);
4873 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4874 jsize len, jbyte *buf)
4878 STATISTICS(jniinvokation());
4880 ba = (java_bytearray *) array;
4882 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4883 exceptions_throw_arrayindexoutofboundsexception();
4885 MCOPY(buf, &ba->data[start], s1, len);
4889 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4890 jsize len, jchar *buf)
4894 STATISTICS(jniinvokation());
4896 ca = (java_chararray *) array;
4898 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4899 exceptions_throw_arrayindexoutofboundsexception();
4901 MCOPY(buf, &ca->data[start], u2, len);
4905 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4906 jsize len, jshort *buf)
4908 java_shortarray *sa;
4910 STATISTICS(jniinvokation());
4912 sa = (java_shortarray *) array;
4914 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4915 exceptions_throw_arrayindexoutofboundsexception();
4917 MCOPY(buf, &sa->data[start], s2, len);
4921 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4922 jsize len, jint *buf)
4926 STATISTICS(jniinvokation());
4928 ia = (java_intarray *) array;
4930 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4931 exceptions_throw_arrayindexoutofboundsexception();
4933 MCOPY(buf, &ia->data[start], s4, len);
4937 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4938 jsize len, jlong *buf)
4942 STATISTICS(jniinvokation());
4944 la = (java_longarray *) array;
4946 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4947 exceptions_throw_arrayindexoutofboundsexception();
4949 MCOPY(buf, &la->data[start], s8, len);
4953 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4954 jsize len, jfloat *buf)
4956 java_floatarray *fa;
4958 STATISTICS(jniinvokation());
4960 fa = (java_floatarray *) array;
4962 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4963 exceptions_throw_arrayindexoutofboundsexception();
4965 MCOPY(buf, &fa->data[start], float, len);
4969 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4970 jsize len, jdouble *buf)
4972 java_doublearray *da;
4974 STATISTICS(jniinvokation());
4976 da = (java_doublearray *) array;
4978 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4979 exceptions_throw_arrayindexoutofboundsexception();
4981 MCOPY(buf, &da->data[start], double, len);
4985 /* Set<PrimitiveType>ArrayRegion **********************************************
4987 A family of functions that copies back a region of a primitive
4988 array from a buffer.
4990 *******************************************************************************/
4992 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4993 jsize start, jsize len, jboolean *buf)
4995 java_booleanarray *ba;
4997 STATISTICS(jniinvokation());
4999 ba = (java_booleanarray *) array;
5001 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5002 exceptions_throw_arrayindexoutofboundsexception();
5004 MCOPY(&ba->data[start], buf, u1, len);
5008 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5009 jsize len, jbyte *buf)
5013 STATISTICS(jniinvokation());
5015 ba = (java_bytearray *) array;
5017 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5018 exceptions_throw_arrayindexoutofboundsexception();
5020 MCOPY(&ba->data[start], buf, s1, len);
5024 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5025 jsize len, jchar *buf)
5029 STATISTICS(jniinvokation());
5031 ca = (java_chararray *) array;
5033 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5034 exceptions_throw_arrayindexoutofboundsexception();
5036 MCOPY(&ca->data[start], buf, u2, len);
5040 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5041 jsize len, jshort *buf)
5043 java_shortarray *sa;
5045 STATISTICS(jniinvokation());
5047 sa = (java_shortarray *) array;
5049 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5050 exceptions_throw_arrayindexoutofboundsexception();
5052 MCOPY(&sa->data[start], buf, s2, len);
5056 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5057 jsize len, jint *buf)
5061 STATISTICS(jniinvokation());
5063 ia = (java_intarray *) array;
5065 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5066 exceptions_throw_arrayindexoutofboundsexception();
5068 MCOPY(&ia->data[start], buf, s4, len);
5072 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5073 jsize len, jlong *buf)
5077 STATISTICS(jniinvokation());
5079 la = (java_longarray *) array;
5081 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5082 exceptions_throw_arrayindexoutofboundsexception();
5084 MCOPY(&la->data[start], buf, s8, len);
5088 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5089 jsize len, jfloat *buf)
5091 java_floatarray *fa;
5093 STATISTICS(jniinvokation());
5095 fa = (java_floatarray *) array;
5097 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5098 exceptions_throw_arrayindexoutofboundsexception();
5100 MCOPY(&fa->data[start], buf, float, len);
5104 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5105 jsize len, jdouble *buf)
5107 java_doublearray *da;
5109 STATISTICS(jniinvokation());
5111 da = (java_doublearray *) array;
5113 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5114 exceptions_throw_arrayindexoutofboundsexception();
5116 MCOPY(&da->data[start], buf, double, len);
5120 /* Registering Native Methods *************************************************/
5122 /* RegisterNatives *************************************************************
5124 Registers native methods with the class specified by the clazz
5125 argument. The methods parameter specifies an array of
5126 JNINativeMethod structures that contain the names, signatures, and
5127 function pointers of the native methods. The nMethods parameter
5128 specifies the number of native methods in the array.
5130 *******************************************************************************/
5132 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5133 const JNINativeMethod *methods, jint nMethods)
5135 STATISTICS(jniinvokation());
5137 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5138 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5139 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5146 /* UnregisterNatives ***********************************************************
5148 Unregisters native methods of a class. The class goes back to the
5149 state before it was linked or registered with its native method
5152 This function should not be used in normal native code. Instead, it
5153 provides special programs a way to reload and relink native
5156 *******************************************************************************/
5158 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5160 STATISTICS(jniinvokation());
5162 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5164 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5170 /* Monitor Operations *********************************************************/
5172 /* MonitorEnter ****************************************************************
5174 Enters the monitor associated with the underlying Java object
5177 *******************************************************************************/
5179 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5181 STATISTICS(jniinvokation());
5184 exceptions_throw_nullpointerexception();
5188 LOCK_MONITOR_ENTER(obj);
5194 /* MonitorExit *****************************************************************
5196 The current thread must be the owner of the monitor associated with
5197 the underlying Java object referred to by obj. The thread
5198 decrements the counter indicating the number of times it has
5199 entered this monitor. If the value of the counter becomes zero, the
5200 current thread releases the monitor.
5202 *******************************************************************************/
5204 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5206 STATISTICS(jniinvokation());
5209 exceptions_throw_nullpointerexception();
5213 LOCK_MONITOR_EXIT(obj);
5219 /* JavaVM Interface ***********************************************************/
5221 /* GetJavaVM *******************************************************************
5223 Returns the Java VM interface (used in the Invocation API)
5224 associated with the current thread. The result is placed at the
5225 location pointed to by the second argument, vm.
5227 *******************************************************************************/
5229 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5231 STATISTICS(jniinvokation());
5233 *vm = (JavaVM *) _Jv_jvm;
5239 /* GetStringRegion *************************************************************
5241 Copies len number of Unicode characters beginning at offset start
5242 to the given buffer buf.
5244 Throws StringIndexOutOfBoundsException on index overflow.
5246 *******************************************************************************/
5248 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5251 java_lang_String *s;
5254 STATISTICS(jniinvokation());
5256 s = (java_lang_String *) str;
5259 if ((start < 0) || (len < 0) || (start > s->count) ||
5260 (start + len > s->count)) {
5261 exceptions_throw_stringindexoutofboundsexception();
5265 MCOPY(buf, &ca->data[start], u2, len);
5269 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5270 jsize len, char *buf)
5272 STATISTICS(jniinvokation());
5274 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5278 /* GetPrimitiveArrayCritical ***************************************************
5280 Obtain a direct pointer to array elements.
5282 *******************************************************************************/
5284 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5290 ba = (java_bytearray *) array;
5292 /* do the same as Kaffe does */
5294 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5300 /* ReleasePrimitiveArrayCritical ***********************************************
5302 No specific documentation.
5304 *******************************************************************************/
5306 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5307 void *carray, jint mode)
5309 STATISTICS(jniinvokation());
5311 /* do the same as Kaffe does */
5313 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5318 /* GetStringCritical ***********************************************************
5320 The semantics of these two functions are similar to the existing
5321 Get/ReleaseStringChars functions.
5323 *******************************************************************************/
5325 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5328 STATISTICS(jniinvokation());
5330 return _Jv_JNI_GetStringChars(env, string, isCopy);
5334 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5335 const jchar *cstring)
5337 STATISTICS(jniinvokation());
5339 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5343 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5345 STATISTICS(jniinvokation());
5347 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5353 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5355 STATISTICS(jniinvokation());
5357 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5361 /* NewGlobalRef ****************************************************************
5363 Creates a new global reference to the object referred to by the obj
5366 *******************************************************************************/
5368 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5370 hashtable_global_ref_entry *gre;
5371 u4 key; /* hashkey */
5372 u4 slot; /* slot in hashtable */
5374 STATISTICS(jniinvokation());
5376 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5378 /* normally addresses are aligned to 4, 8 or 16 bytes */
5380 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5381 slot = key & (hashtable_global_ref->size - 1);
5382 gre = hashtable_global_ref->ptr[slot];
5384 /* search external hash chain for the entry */
5387 if (gre->o == obj) {
5388 /* global object found, increment the reference */
5392 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5397 gre = gre->hashlink; /* next element in external chain */
5400 /* global ref not found, create a new one */
5402 gre = NEW(hashtable_global_ref_entry);
5407 /* insert entry into hashtable */
5409 gre->hashlink = hashtable_global_ref->ptr[slot];
5411 hashtable_global_ref->ptr[slot] = gre;
5413 /* update number of hashtable-entries */
5415 hashtable_global_ref->entries++;
5417 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5423 /* DeleteGlobalRef *************************************************************
5425 Deletes the global reference pointed to by globalRef.
5427 *******************************************************************************/
5429 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5431 hashtable_global_ref_entry *gre;
5432 hashtable_global_ref_entry *prevgre;
5433 u4 key; /* hashkey */
5434 u4 slot; /* slot in hashtable */
5436 STATISTICS(jniinvokation());
5438 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5440 /* normally addresses are aligned to 4, 8 or 16 bytes */
5442 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5443 slot = key & (hashtable_global_ref->size - 1);
5444 gre = hashtable_global_ref->ptr[slot];
5446 /* initialize prevgre */
5450 /* search external hash chain for the entry */
5453 if (gre->o == globalRef) {
5454 /* global object found, decrement the reference count */
5458 /* if reference count is 0, remove the entry */
5460 if (gre->refs == 0) {
5461 /* special handling if it's the first in the chain */
5463 if (prevgre == NULL)
5464 hashtable_global_ref->ptr[slot] = gre->hashlink;
5466 prevgre->hashlink = gre->hashlink;
5468 FREE(gre, hashtable_global_ref_entry);
5471 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5476 prevgre = gre; /* save current pointer for removal */
5477 gre = gre->hashlink; /* next element in external chain */
5480 log_println("JNI-DeleteGlobalRef: global reference not found");
5482 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5486 /* ExceptionCheck **************************************************************
5488 Returns JNI_TRUE when there is a pending exception; otherwise,
5491 *******************************************************************************/
5493 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5495 java_objectheader *o;
5497 STATISTICS(jniinvokation());
5499 o = exceptions_get_exception();
5501 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5505 /* New JNI 1.4 functions ******************************************************/
5507 /* NewDirectByteBuffer *********************************************************
5509 Allocates and returns a direct java.nio.ByteBuffer referring to the
5510 block of memory starting at the memory address address and
5511 extending capacity bytes.
5513 *******************************************************************************/
5515 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5517 #if defined(ENABLE_JAVASE)
5518 java_objectheader *nbuf;
5519 # if SIZEOF_VOID_P == 8
5520 gnu_classpath_Pointer64 *paddress;
5522 gnu_classpath_Pointer32 *paddress;
5525 STATISTICS(jniinvokation());
5527 /* alocate a gnu.classpath.Pointer{32,64} object */
5529 # if SIZEOF_VOID_P == 8
5530 if (!(paddress = (gnu_classpath_Pointer64 *)
5531 builtin_new(class_gnu_classpath_Pointer64)))
5533 if (!(paddress = (gnu_classpath_Pointer32 *)
5534 builtin_new(class_gnu_classpath_Pointer32)))
5538 /* fill gnu.classpath.Pointer{32,64} with address */
5540 paddress->data = (ptrint) address;
5542 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5544 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5545 (jmethodID) dbbirw_init, NULL, paddress,
5546 (jint) capacity, (jint) capacity, (jint) 0);
5548 /* add local reference and return the value */
5550 return _Jv_JNI_NewLocalRef(env, nbuf);
5552 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5554 /* keep compiler happy */
5561 /* GetDirectBufferAddress ******************************************************
5563 Fetches and returns the starting address of the memory region
5564 referenced by the given direct java.nio.Buffer.
5566 *******************************************************************************/
5568 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5570 #if defined(ENABLE_JAVASE)
5571 java_nio_DirectByteBufferImpl *nbuf;
5572 # if SIZEOF_VOID_P == 8
5573 gnu_classpath_Pointer64 *address;
5575 gnu_classpath_Pointer32 *address;
5578 STATISTICS(jniinvokation());
5580 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5583 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5585 # if SIZEOF_VOID_P == 8
5586 address = (gnu_classpath_Pointer64 *) nbuf->address;
5588 address = (gnu_classpath_Pointer32 *) nbuf->address;
5591 if (address == NULL)
5594 return (void *) address->data;
5596 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5598 /* keep compiler happy */
5605 /* GetDirectBufferCapacity *****************************************************
5607 Fetches and returns the capacity in bytes of the memory region
5608 referenced by the given direct java.nio.Buffer.
5610 *******************************************************************************/
5612 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5614 #if defined(ENABLE_JAVASE)
5615 java_nio_Buffer *nbuf;
5617 STATISTICS(jniinvokation());
5619 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5622 nbuf = (java_nio_Buffer *) buf;
5624 return (jlong) nbuf->cap;
5626 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5628 /* keep compiler happy */
5635 /* DestroyJavaVM ***************************************************************
5637 Unloads a Java VM and reclaims its resources. Only the main thread
5638 can unload the VM. The system waits until the main thread is only
5639 remaining user thread before it destroys the VM.
5641 *******************************************************************************/
5643 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5647 STATISTICS(jniinvokation());
5649 status = vm_destroy(vm);
5655 /* AttachCurrentThread *********************************************************
5657 Attaches the current thread to a Java VM. Returns a JNI interface
5658 pointer in the JNIEnv argument.
5660 Trying to attach a thread that is already attached is a no-op.
5662 A native thread cannot be attached simultaneously to two Java VMs.
5664 When a thread is attached to the VM, the context class loader is
5665 the bootstrap loader.
5667 *******************************************************************************/
5669 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5671 JavaVMAttachArgs *vm_aargs;
5673 #if defined(ENABLE_THREADS)
5674 if (threads_get_current_threadobject() == NULL) {
5675 vm_aargs = (JavaVMAttachArgs *) thr_args;
5677 if (vm_aargs != NULL) {
5678 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5679 (vm_aargs->version != JNI_VERSION_1_4))
5680 return JNI_EVERSION;
5683 if (!threads_attach_current_thread(vm_aargs, false))
5686 if (!jni_init_localref_table())
5697 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5699 STATISTICS(jniinvokation());
5701 return jni_attach_current_thread(p_env, thr_args, false);
5705 /* DetachCurrentThread *********************************************************
5707 Detaches the current thread from a Java VM. All Java monitors held
5708 by this thread are released. All Java threads waiting for this
5709 thread to die are notified.
5711 In JDK 1.1, the main thread cannot be detached from the VM. It must
5712 call DestroyJavaVM to unload the entire VM.
5714 In the JDK, the main thread can be detached from the VM.
5716 The main thread, which is the thread that created the Java VM,
5717 cannot be detached from the VM. Instead, the main thread must call
5718 JNI_DestroyJavaVM() to unload the entire VM.
5720 *******************************************************************************/
5722 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5724 #if defined(ENABLE_THREADS)
5725 threadobject *thread;
5727 STATISTICS(jniinvokation());
5729 thread = threads_get_current_threadobject();
5734 if (!jni_free_localref_table())
5737 if (!threads_detach_thread(thread))
5745 /* GetEnv **********************************************************************
5747 If the current thread is not attached to the VM, sets *env to NULL,
5748 and returns JNI_EDETACHED. If the specified version is not
5749 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5750 sets *env to the appropriate interface, and returns JNI_OK.
5752 *******************************************************************************/
5754 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5756 STATISTICS(jniinvokation());
5758 #if defined(ENABLE_THREADS)
5759 if (threads_get_current_threadobject() == NULL) {
5762 return JNI_EDETACHED;
5766 /* check the JNI version */
5769 case JNI_VERSION_1_1:
5770 case JNI_VERSION_1_2:
5771 case JNI_VERSION_1_4:
5779 #if defined(ENABLE_JVMTI)
5780 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5781 == JVMTI_VERSION_INTERFACE_JVMTI) {
5783 *env = (void *) jvmti_new_environment();
5792 return JNI_EVERSION;
5796 /* AttachCurrentThreadAsDaemon *************************************************
5798 Same semantics as AttachCurrentThread, but the newly-created
5799 java.lang.Thread instance is a daemon.
5801 If the thread has already been attached via either
5802 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5803 simply sets the value pointed to by penv to the JNIEnv of the
5804 current thread. In this case neither AttachCurrentThread nor this
5805 routine have any effect on the daemon status of the thread.
5807 *******************************************************************************/
5809 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5811 STATISTICS(jniinvokation());
5813 return jni_attach_current_thread(penv, args, true);
5817 /* JNI invocation table *******************************************************/
5819 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5824 _Jv_JNI_DestroyJavaVM,
5825 _Jv_JNI_AttachCurrentThread,
5826 _Jv_JNI_DetachCurrentThread,
5828 _Jv_JNI_AttachCurrentThreadAsDaemon
5832 /* JNI function table *********************************************************/
5834 struct JNINativeInterface _Jv_JNINativeInterface = {
5841 _Jv_JNI_DefineClass,
5843 _Jv_JNI_FromReflectedMethod,
5844 _Jv_JNI_FromReflectedField,
5845 _Jv_JNI_ToReflectedMethod,
5846 _Jv_JNI_GetSuperclass,
5847 _Jv_JNI_IsAssignableFrom,
5848 _Jv_JNI_ToReflectedField,
5852 _Jv_JNI_ExceptionOccurred,
5853 _Jv_JNI_ExceptionDescribe,
5854 _Jv_JNI_ExceptionClear,
5856 _Jv_JNI_PushLocalFrame,
5857 _Jv_JNI_PopLocalFrame,
5859 _Jv_JNI_NewGlobalRef,
5860 _Jv_JNI_DeleteGlobalRef,
5861 _Jv_JNI_DeleteLocalRef,
5862 _Jv_JNI_IsSameObject,
5863 _Jv_JNI_NewLocalRef,
5864 _Jv_JNI_EnsureLocalCapacity,
5866 _Jv_JNI_AllocObject,
5871 _Jv_JNI_GetObjectClass,
5872 _Jv_JNI_IsInstanceOf,
5874 _Jv_JNI_GetMethodID,
5876 _Jv_JNI_CallObjectMethod,
5877 _Jv_JNI_CallObjectMethodV,
5878 _Jv_JNI_CallObjectMethodA,
5879 _Jv_JNI_CallBooleanMethod,
5880 _Jv_JNI_CallBooleanMethodV,
5881 _Jv_JNI_CallBooleanMethodA,
5882 _Jv_JNI_CallByteMethod,
5883 _Jv_JNI_CallByteMethodV,
5884 _Jv_JNI_CallByteMethodA,
5885 _Jv_JNI_CallCharMethod,
5886 _Jv_JNI_CallCharMethodV,
5887 _Jv_JNI_CallCharMethodA,
5888 _Jv_JNI_CallShortMethod,
5889 _Jv_JNI_CallShortMethodV,
5890 _Jv_JNI_CallShortMethodA,
5891 _Jv_JNI_CallIntMethod,
5892 _Jv_JNI_CallIntMethodV,
5893 _Jv_JNI_CallIntMethodA,
5894 _Jv_JNI_CallLongMethod,
5895 _Jv_JNI_CallLongMethodV,
5896 _Jv_JNI_CallLongMethodA,
5897 _Jv_JNI_CallFloatMethod,
5898 _Jv_JNI_CallFloatMethodV,
5899 _Jv_JNI_CallFloatMethodA,
5900 _Jv_JNI_CallDoubleMethod,
5901 _Jv_JNI_CallDoubleMethodV,
5902 _Jv_JNI_CallDoubleMethodA,
5903 _Jv_JNI_CallVoidMethod,
5904 _Jv_JNI_CallVoidMethodV,
5905 _Jv_JNI_CallVoidMethodA,
5907 _Jv_JNI_CallNonvirtualObjectMethod,
5908 _Jv_JNI_CallNonvirtualObjectMethodV,
5909 _Jv_JNI_CallNonvirtualObjectMethodA,
5910 _Jv_JNI_CallNonvirtualBooleanMethod,
5911 _Jv_JNI_CallNonvirtualBooleanMethodV,
5912 _Jv_JNI_CallNonvirtualBooleanMethodA,
5913 _Jv_JNI_CallNonvirtualByteMethod,
5914 _Jv_JNI_CallNonvirtualByteMethodV,
5915 _Jv_JNI_CallNonvirtualByteMethodA,
5916 _Jv_JNI_CallNonvirtualCharMethod,
5917 _Jv_JNI_CallNonvirtualCharMethodV,
5918 _Jv_JNI_CallNonvirtualCharMethodA,
5919 _Jv_JNI_CallNonvirtualShortMethod,
5920 _Jv_JNI_CallNonvirtualShortMethodV,
5921 _Jv_JNI_CallNonvirtualShortMethodA,
5922 _Jv_JNI_CallNonvirtualIntMethod,
5923 _Jv_JNI_CallNonvirtualIntMethodV,
5924 _Jv_JNI_CallNonvirtualIntMethodA,
5925 _Jv_JNI_CallNonvirtualLongMethod,
5926 _Jv_JNI_CallNonvirtualLongMethodV,
5927 _Jv_JNI_CallNonvirtualLongMethodA,
5928 _Jv_JNI_CallNonvirtualFloatMethod,
5929 _Jv_JNI_CallNonvirtualFloatMethodV,
5930 _Jv_JNI_CallNonvirtualFloatMethodA,
5931 _Jv_JNI_CallNonvirtualDoubleMethod,
5932 _Jv_JNI_CallNonvirtualDoubleMethodV,
5933 _Jv_JNI_CallNonvirtualDoubleMethodA,
5934 _Jv_JNI_CallNonvirtualVoidMethod,
5935 _Jv_JNI_CallNonvirtualVoidMethodV,
5936 _Jv_JNI_CallNonvirtualVoidMethodA,
5940 _Jv_JNI_GetObjectField,
5941 _Jv_JNI_GetBooleanField,
5942 _Jv_JNI_GetByteField,
5943 _Jv_JNI_GetCharField,
5944 _Jv_JNI_GetShortField,
5945 _Jv_JNI_GetIntField,
5946 _Jv_JNI_GetLongField,
5947 _Jv_JNI_GetFloatField,
5948 _Jv_JNI_GetDoubleField,
5949 _Jv_JNI_SetObjectField,
5950 _Jv_JNI_SetBooleanField,
5951 _Jv_JNI_SetByteField,
5952 _Jv_JNI_SetCharField,
5953 _Jv_JNI_SetShortField,
5954 _Jv_JNI_SetIntField,
5955 _Jv_JNI_SetLongField,
5956 _Jv_JNI_SetFloatField,
5957 _Jv_JNI_SetDoubleField,
5959 _Jv_JNI_GetStaticMethodID,
5961 _Jv_JNI_CallStaticObjectMethod,
5962 _Jv_JNI_CallStaticObjectMethodV,
5963 _Jv_JNI_CallStaticObjectMethodA,
5964 _Jv_JNI_CallStaticBooleanMethod,
5965 _Jv_JNI_CallStaticBooleanMethodV,
5966 _Jv_JNI_CallStaticBooleanMethodA,
5967 _Jv_JNI_CallStaticByteMethod,
5968 _Jv_JNI_CallStaticByteMethodV,
5969 _Jv_JNI_CallStaticByteMethodA,
5970 _Jv_JNI_CallStaticCharMethod,
5971 _Jv_JNI_CallStaticCharMethodV,
5972 _Jv_JNI_CallStaticCharMethodA,
5973 _Jv_JNI_CallStaticShortMethod,
5974 _Jv_JNI_CallStaticShortMethodV,
5975 _Jv_JNI_CallStaticShortMethodA,
5976 _Jv_JNI_CallStaticIntMethod,
5977 _Jv_JNI_CallStaticIntMethodV,
5978 _Jv_JNI_CallStaticIntMethodA,
5979 _Jv_JNI_CallStaticLongMethod,
5980 _Jv_JNI_CallStaticLongMethodV,
5981 _Jv_JNI_CallStaticLongMethodA,
5982 _Jv_JNI_CallStaticFloatMethod,
5983 _Jv_JNI_CallStaticFloatMethodV,
5984 _Jv_JNI_CallStaticFloatMethodA,
5985 _Jv_JNI_CallStaticDoubleMethod,
5986 _Jv_JNI_CallStaticDoubleMethodV,
5987 _Jv_JNI_CallStaticDoubleMethodA,
5988 _Jv_JNI_CallStaticVoidMethod,
5989 _Jv_JNI_CallStaticVoidMethodV,
5990 _Jv_JNI_CallStaticVoidMethodA,
5992 _Jv_JNI_GetStaticFieldID,
5994 _Jv_JNI_GetStaticObjectField,
5995 _Jv_JNI_GetStaticBooleanField,
5996 _Jv_JNI_GetStaticByteField,
5997 _Jv_JNI_GetStaticCharField,
5998 _Jv_JNI_GetStaticShortField,
5999 _Jv_JNI_GetStaticIntField,
6000 _Jv_JNI_GetStaticLongField,
6001 _Jv_JNI_GetStaticFloatField,
6002 _Jv_JNI_GetStaticDoubleField,
6003 _Jv_JNI_SetStaticObjectField,
6004 _Jv_JNI_SetStaticBooleanField,
6005 _Jv_JNI_SetStaticByteField,
6006 _Jv_JNI_SetStaticCharField,
6007 _Jv_JNI_SetStaticShortField,
6008 _Jv_JNI_SetStaticIntField,
6009 _Jv_JNI_SetStaticLongField,
6010 _Jv_JNI_SetStaticFloatField,
6011 _Jv_JNI_SetStaticDoubleField,
6014 _Jv_JNI_GetStringLength,
6015 _Jv_JNI_GetStringChars,
6016 _Jv_JNI_ReleaseStringChars,
6018 _Jv_JNI_NewStringUTF,
6019 _Jv_JNI_GetStringUTFLength,
6020 _Jv_JNI_GetStringUTFChars,
6021 _Jv_JNI_ReleaseStringUTFChars,
6023 _Jv_JNI_GetArrayLength,
6025 _Jv_JNI_NewObjectArray,
6026 _Jv_JNI_GetObjectArrayElement,
6027 _Jv_JNI_SetObjectArrayElement,
6029 _Jv_JNI_NewBooleanArray,
6030 _Jv_JNI_NewByteArray,
6031 _Jv_JNI_NewCharArray,
6032 _Jv_JNI_NewShortArray,
6033 _Jv_JNI_NewIntArray,
6034 _Jv_JNI_NewLongArray,
6035 _Jv_JNI_NewFloatArray,
6036 _Jv_JNI_NewDoubleArray,
6038 _Jv_JNI_GetBooleanArrayElements,
6039 _Jv_JNI_GetByteArrayElements,
6040 _Jv_JNI_GetCharArrayElements,
6041 _Jv_JNI_GetShortArrayElements,
6042 _Jv_JNI_GetIntArrayElements,
6043 _Jv_JNI_GetLongArrayElements,
6044 _Jv_JNI_GetFloatArrayElements,
6045 _Jv_JNI_GetDoubleArrayElements,
6047 _Jv_JNI_ReleaseBooleanArrayElements,
6048 _Jv_JNI_ReleaseByteArrayElements,
6049 _Jv_JNI_ReleaseCharArrayElements,
6050 _Jv_JNI_ReleaseShortArrayElements,
6051 _Jv_JNI_ReleaseIntArrayElements,
6052 _Jv_JNI_ReleaseLongArrayElements,
6053 _Jv_JNI_ReleaseFloatArrayElements,
6054 _Jv_JNI_ReleaseDoubleArrayElements,
6056 _Jv_JNI_GetBooleanArrayRegion,
6057 _Jv_JNI_GetByteArrayRegion,
6058 _Jv_JNI_GetCharArrayRegion,
6059 _Jv_JNI_GetShortArrayRegion,
6060 _Jv_JNI_GetIntArrayRegion,
6061 _Jv_JNI_GetLongArrayRegion,
6062 _Jv_JNI_GetFloatArrayRegion,
6063 _Jv_JNI_GetDoubleArrayRegion,
6064 _Jv_JNI_SetBooleanArrayRegion,
6065 _Jv_JNI_SetByteArrayRegion,
6066 _Jv_JNI_SetCharArrayRegion,
6067 _Jv_JNI_SetShortArrayRegion,
6068 _Jv_JNI_SetIntArrayRegion,
6069 _Jv_JNI_SetLongArrayRegion,
6070 _Jv_JNI_SetFloatArrayRegion,
6071 _Jv_JNI_SetDoubleArrayRegion,
6073 _Jv_JNI_RegisterNatives,
6074 _Jv_JNI_UnregisterNatives,
6076 _Jv_JNI_MonitorEnter,
6077 _Jv_JNI_MonitorExit,
6081 /* new JNI 1.2 functions */
6083 _Jv_JNI_GetStringRegion,
6084 _Jv_JNI_GetStringUTFRegion,
6086 _Jv_JNI_GetPrimitiveArrayCritical,
6087 _Jv_JNI_ReleasePrimitiveArrayCritical,
6089 _Jv_JNI_GetStringCritical,
6090 _Jv_JNI_ReleaseStringCritical,
6092 _Jv_JNI_NewWeakGlobalRef,
6093 _Jv_JNI_DeleteWeakGlobalRef,
6095 _Jv_JNI_ExceptionCheck,
6097 /* new JNI 1.4 functions */
6099 _Jv_JNI_NewDirectByteBuffer,
6100 _Jv_JNI_GetDirectBufferAddress,
6101 _Jv_JNI_GetDirectBufferCapacity
6105 /* Invocation API Functions ***************************************************/
6107 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6109 Returns a default configuration for the Java VM.
6111 *******************************************************************************/
6113 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6115 JavaVMInitArgs *_vm_args;
6117 _vm_args = (JavaVMInitArgs *) vm_args;
6119 /* GNU classpath currently supports JNI 1.2 */
6121 switch (_vm_args->version) {
6122 case JNI_VERSION_1_1:
6123 _vm_args->version = JNI_VERSION_1_1;
6126 case JNI_VERSION_1_2:
6127 case JNI_VERSION_1_4:
6128 _vm_args->ignoreUnrecognized = JNI_FALSE;
6129 _vm_args->options = NULL;
6130 _vm_args->nOptions = 0;
6141 /* JNI_GetCreatedJavaVMs *******************************************************
6143 Returns all Java VMs that have been created. Pointers to VMs are written in
6144 the buffer vmBuf in the order they are created. At most bufLen number of
6145 entries will be written. The total number of created VMs is returned in
6148 *******************************************************************************/
6150 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6152 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6158 /* JNI_CreateJavaVM ************************************************************
6160 Loads and initializes a Java VM. The current thread becomes the main thread.
6161 Sets the env argument to the JNI interface pointer of the main thread.
6163 *******************************************************************************/
6165 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6167 /* actually create the JVM */
6169 if (!vm_createjvm(p_vm, p_env, vm_args))
6177 * These are local overrides for various environment variables in Emacs.
6178 * Please do not remove this and leave it at the end of the file, where
6179 * Emacs will automagically detect them.
6180 * ---------------------------------------------------------------------
6183 * indent-tabs-mode: t
6187 * vim:noexpandtab:sw=4:ts=4: