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 7723 2007-04-16 18:03:08Z 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 #if defined(ENABLE_THREADS)
88 # include "threads/native/lock.h"
89 # include "threads/native/threads.h"
91 # include "threads/none/lock.h"
92 # include "threads/none/threads.h"
95 #include "toolbox/logging.h"
97 #include "vm/builtin.h"
98 #include "vm/exceptions.h"
99 #include "vm/global.h"
100 #include "vm/initialize.h"
101 #include "vm/stringlocal.h"
104 #include "vm/jit/asmpart.h"
105 #include "vm/jit/jit.h"
106 #include "vm/jit/stacktrace.h"
108 #include "vmcore/loader.h"
109 #include "vmcore/options.h"
110 #include "vm/resolve.h"
111 #include "vmcore/statistics.h"
114 /* global variables ***********************************************************/
116 /* global reference table *****************************************************/
118 /* hashsize must be power of 2 */
120 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
122 hashtable *hashtable_global_ref; /* hashtable for globalrefs */
125 /* direct buffer stuff ********************************************************/
127 #if defined(ENABLE_JAVASE)
128 static classinfo *class_java_nio_Buffer;
129 static classinfo *class_java_nio_DirectByteBufferImpl;
130 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
132 # if defined(WITH_CLASSPATH_GNU)
133 # if SIZEOF_VOID_P == 8
134 static classinfo *class_gnu_classpath_Pointer64;
136 static classinfo *class_gnu_classpath_Pointer32;
140 static methodinfo *dbbirw_init;
144 /* local reference table ******************************************************/
146 #if !defined(ENABLE_THREADS)
147 localref_table *_no_threads_localref_table;
151 /* accessing instance fields macros *******************************************/
153 #define SET_FIELD(o,type,f,value) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
156 #define GET_FIELD(o,type,f) \
157 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
160 /* some forward declarations **************************************************/
162 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
163 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
166 /* jni_init ********************************************************************
168 Initialize the JNI subsystem.
170 *******************************************************************************/
174 /* create global ref hashtable */
176 hashtable_global_ref = NEW(hashtable);
178 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
181 #if defined(ENABLE_JAVASE)
182 /* direct buffer stuff */
184 if (!(class_java_nio_Buffer =
185 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
186 !link_class(class_java_nio_Buffer))
189 if (!(class_java_nio_DirectByteBufferImpl =
190 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
191 !link_class(class_java_nio_DirectByteBufferImpl))
194 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
195 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
196 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
200 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
202 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
205 # if defined(WITH_CLASSPATH_GNU)
206 # if SIZEOF_VOID_P == 8
207 if (!(class_gnu_classpath_Pointer64 =
208 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
209 !link_class(class_gnu_classpath_Pointer64))
212 if (!(class_gnu_classpath_Pointer32 =
213 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
214 !link_class(class_gnu_classpath_Pointer32))
218 #endif /* defined(ENABLE_JAVASE) */
224 /* jni_init_localref_table *****************************************************
226 Initializes the local references table of the current thread.
228 *******************************************************************************/
230 bool jni_init_localref_table(void)
234 #if defined(ENABLE_GC_CACAO)
235 /* XXX this one will never get freed for the main thread;
236 call jni_free_localref_table() if you want to do it! */
237 lrt = NEW(localref_table);
239 lrt = GCNEW(localref_table);
245 lrt->capacity = LOCALREFTABLE_CAPACITY;
247 lrt->localframes = 1;
248 lrt->prev = LOCALREFTABLE;
250 /* clear the references array (memset is faster then a for-loop) */
252 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
260 /* jni_init_localref_table *****************************************************
262 Frees the local references table of the current thread.
264 *******************************************************************************/
266 bool jni_free_localref_table(void)
270 #if defined(ENABLE_GC_CACAO)
274 assert(lrt->prev == NULL);
276 FREE(lrt, localref_table);
278 LOCALREFTABLE = NULL;
285 /* _Jv_jni_vmargs_from_objectarray *********************************************
289 *******************************************************************************/
291 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
294 java_objectarray *params)
296 java_objectheader *param;
298 typedesc *paramtypes;
304 paramcount = descr->paramcount;
305 paramtypes = descr->paramtypes;
307 /* if method is non-static fill first block and skip `this' pointer */
313 vmargs[0].type = TYPE_ADR;
314 vmargs[0].data.l = (u8) (ptrint) o;
321 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
322 switch (paramtypes->type) {
323 /* primitive types */
328 param = params->data[j];
333 /* internally used data type */
334 vmargs[i].type = paramtypes->type;
336 /* convert the value according to its declared type */
338 c = param->vftbl->class;
340 switch (paramtypes->decltype) {
341 case PRIMITIVETYPE_BOOLEAN:
342 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
343 value = (s8) ((java_lang_Boolean *) param)->value;
347 vmargs[i].data.l = value;
350 case PRIMITIVETYPE_BYTE:
351 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
352 value = (s8) ((java_lang_Byte *) param)->value;
356 vmargs[i].data.l = value;
359 case PRIMITIVETYPE_CHAR:
360 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
361 value = (s8) ((java_lang_Character *) param)->value;
365 vmargs[i].data.l = value;
368 case PRIMITIVETYPE_SHORT:
369 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
370 value = (s8) ((java_lang_Short *) param)->value;
371 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
372 value = (s8) ((java_lang_Byte *) param)->value;
376 vmargs[i].data.l = value;
379 case PRIMITIVETYPE_INT:
380 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
381 value = (s8) ((java_lang_Integer *) param)->value;
382 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
383 value = (s8) ((java_lang_Short *) param)->value;
384 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
385 value = (s8) ((java_lang_Byte *) param)->value;
389 vmargs[i].data.l = value;
392 case PRIMITIVETYPE_LONG:
393 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
394 value = (s8) ((java_lang_Long *) param)->value;
395 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
396 value = (s8) ((java_lang_Integer *) param)->value;
397 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
398 value = (s8) ((java_lang_Short *) param)->value;
399 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
400 value = (s8) ((java_lang_Byte *) param)->value;
404 vmargs[i].data.l = value;
407 case PRIMITIVETYPE_FLOAT:
408 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
409 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
414 case PRIMITIVETYPE_DOUBLE:
415 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
416 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
417 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
418 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
429 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
432 if (params->data[j] != 0) {
433 if (paramtypes->arraydim > 0) {
434 if (!builtin_arrayinstanceof(params->data[j], c))
438 if (!builtin_instanceof(params->data[j], c))
443 vmargs[i].type = TYPE_ADR;
444 vmargs[i].data.l = (u8) (ptrint) params->data[j];
453 /* *rettype = descr->returntype.decltype; */
458 exceptions_throw_illegalargumentexception();
463 /* _Jv_jni_CallObjectMethod ****************************************************
465 Internal function to call Java Object methods.
467 *******************************************************************************/
469 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
471 methodinfo *m, va_list ap)
474 java_objectheader *ro;
476 STATISTICS(jniinvokation());
479 exceptions_throw_nullpointerexception();
483 /* Class initialization is done by the JIT compiler. This is ok
484 since a static method always belongs to the declaring class. */
486 if (m->flags & ACC_STATIC) {
487 /* For static methods we reset the object. */
492 /* for convenience */
497 /* For instance methods we make a virtual function table lookup. */
499 resm = method_vftbl_lookup(vftbl, m);
502 STATISTICS(jnicallXmethodnvokation());
504 ro = vm_call_method_valist(resm, o, ap);
510 /* _Jv_jni_CallObjectMethodA ***************************************************
512 Internal function to call Java Object methods.
514 *******************************************************************************/
516 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
518 methodinfo *m, jvalue *args)
521 java_objectheader *ro;
523 STATISTICS(jniinvokation());
526 exceptions_throw_nullpointerexception();
530 /* Class initialization is done by the JIT compiler. This is ok
531 since a static method always belongs to the declaring class. */
533 if (m->flags & ACC_STATIC) {
534 /* For static methods we reset the object. */
539 /* for convenience */
544 /* For instance methods we make a virtual function table lookup. */
546 resm = method_vftbl_lookup(vftbl, m);
549 STATISTICS(jnicallXmethodnvokation());
551 ro = vm_call_method_jvalue(resm, o, args);
557 /* _Jv_jni_CallIntMethod *******************************************************
559 Internal function to call Java integer class methods (boolean,
560 byte, char, short, int).
562 *******************************************************************************/
564 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
565 methodinfo *m, va_list ap)
570 STATISTICS(jniinvokation());
573 exceptions_throw_nullpointerexception();
577 /* Class initialization is done by the JIT compiler. This is ok
578 since a static method always belongs to the declaring class. */
580 if (m->flags & ACC_STATIC) {
581 /* For static methods we reset the object. */
586 /* for convenience */
591 /* For instance methods we make a virtual function table lookup. */
593 resm = method_vftbl_lookup(vftbl, m);
596 STATISTICS(jnicallXmethodnvokation());
598 i = vm_call_method_int_valist(resm, o, ap);
604 /* _Jv_jni_CallIntMethodA ******************************************************
606 Internal function to call Java integer class methods (boolean,
607 byte, char, short, int).
609 *******************************************************************************/
611 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
612 methodinfo *m, jvalue *args)
617 STATISTICS(jniinvokation());
620 exceptions_throw_nullpointerexception();
624 /* Class initialization is done by the JIT compiler. This is ok
625 since a static method always belongs to the declaring class. */
627 if (m->flags & ACC_STATIC) {
628 /* For static methods we reset the object. */
633 /* for convenience */
638 /* For instance methods we make a virtual function table lookup. */
640 resm = method_vftbl_lookup(vftbl, m);
643 STATISTICS(jnicallXmethodnvokation());
645 i = vm_call_method_int_jvalue(resm, o, args);
651 /* _Jv_jni_CallLongMethod ******************************************************
653 Internal function to call Java long methods.
655 *******************************************************************************/
657 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
658 methodinfo *m, va_list ap)
663 STATISTICS(jniinvokation());
666 exceptions_throw_nullpointerexception();
670 /* Class initialization is done by the JIT compiler. This is ok
671 since a static method always belongs to the declaring class. */
673 if (m->flags & ACC_STATIC) {
674 /* For static methods we reset the object. */
679 /* for convenience */
684 /* For instance methods we make a virtual function table lookup. */
686 resm = method_vftbl_lookup(vftbl, m);
689 STATISTICS(jnicallXmethodnvokation());
691 l = vm_call_method_long_valist(resm, o, ap);
697 /* _Jv_jni_CallFloatMethod *****************************************************
699 Internal function to call Java float methods.
701 *******************************************************************************/
703 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
704 methodinfo *m, va_list ap)
709 /* Class initialization is done by the JIT compiler. This is ok
710 since a static method always belongs to the declaring class. */
712 if (m->flags & ACC_STATIC) {
713 /* For static methods we reset the object. */
718 /* for convenience */
723 /* For instance methods we make a virtual function table lookup. */
725 resm = method_vftbl_lookup(vftbl, m);
728 STATISTICS(jnicallXmethodnvokation());
730 f = vm_call_method_float_valist(resm, o, ap);
736 /* _Jv_jni_CallDoubleMethod ****************************************************
738 Internal function to call Java double methods.
740 *******************************************************************************/
742 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
743 methodinfo *m, va_list ap)
748 /* Class initialization is done by the JIT compiler. This is ok
749 since a static method always belongs to the declaring class. */
751 if (m->flags & ACC_STATIC) {
752 /* For static methods we reset the object. */
757 /* for convenience */
762 /* For instance methods we make a virtual function table lookup. */
764 resm = method_vftbl_lookup(vftbl, m);
767 d = vm_call_method_double_valist(resm, o, ap);
773 /* _Jv_jni_CallVoidMethod ******************************************************
775 Internal function to call Java void methods.
777 *******************************************************************************/
779 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
780 methodinfo *m, va_list ap)
785 exceptions_throw_nullpointerexception();
789 /* Class initialization is done by the JIT compiler. This is ok
790 since a static method always belongs to the declaring class. */
792 if (m->flags & ACC_STATIC) {
793 /* For static methods we reset the object. */
798 /* for convenience */
803 /* For instance methods we make a virtual function table lookup. */
805 resm = method_vftbl_lookup(vftbl, m);
808 STATISTICS(jnicallXmethodnvokation());
810 (void) vm_call_method_valist(resm, o, ap);
814 /* _Jv_jni_CallVoidMethodA *****************************************************
816 Internal function to call Java void methods.
818 *******************************************************************************/
820 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
821 methodinfo *m, jvalue *args)
826 exceptions_throw_nullpointerexception();
830 /* Class initialization is done by the JIT compiler. This is ok
831 since a static method always belongs to the declaring class. */
833 if (m->flags & ACC_STATIC) {
834 /* For static methods we reset the object. */
839 /* for convenience */
844 /* For instance methods we make a virtual function table lookup. */
846 resm = method_vftbl_lookup(vftbl, m);
849 STATISTICS(jnicallXmethodnvokation());
851 (void) vm_call_method_jvalue(resm, o, args);
855 /* _Jv_jni_invokeNative ********************************************************
857 Invoke a method on the given object with the given arguments.
859 For instance methods OBJ must be != NULL and the method is looked up
860 in the vftbl of the object.
862 For static methods, OBJ is ignored.
864 *******************************************************************************/
866 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
867 java_objectarray *params)
871 java_objectheader *ro;
874 java_objectheader *xptr;
877 exceptions_throw_nullpointerexception();
881 argcount = m->parseddesc->paramcount;
882 paramcount = argcount;
884 /* if method is non-static, remove the `this' pointer */
886 if (!(m->flags & ACC_STATIC))
889 /* For instance methods the object has to be an instance of the
890 class the method belongs to. For static methods the obj
891 parameter is ignored. */
893 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
894 exceptions_throw_illegalargumentexception();
898 /* check if we got the right number of arguments */
900 if (((params == NULL) && (paramcount != 0)) ||
901 (params && (params->header.size != paramcount)))
903 exceptions_throw_illegalargumentexception();
907 /* for instance methods we need an object */
909 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
910 /* XXX not sure if that is the correct exception */
911 exceptions_throw_nullpointerexception();
915 /* for static methods, zero object to make subsequent code simpler */
916 if (m->flags & ACC_STATIC)
920 /* for instance methods we must do a vftbl lookup */
921 resm = method_vftbl_lookup(o->vftbl, m);
924 /* for static methods, just for convenience */
928 vmargs = MNEW(vm_arg, argcount);
930 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
931 MFREE(vmargs, vm_arg, argcount);
935 switch (resm->parseddesc->returntype.decltype) {
937 (void) vm_call_method_vmarg(resm, argcount, vmargs);
942 case PRIMITIVETYPE_BOOLEAN: {
944 java_lang_Boolean *bo;
946 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
948 ro = builtin_new(class_java_lang_Boolean);
950 /* setting the value of the object direct */
952 bo = (java_lang_Boolean *) ro;
957 case PRIMITIVETYPE_BYTE: {
961 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
963 ro = builtin_new(class_java_lang_Byte);
965 /* setting the value of the object direct */
967 bo = (java_lang_Byte *) ro;
972 case PRIMITIVETYPE_CHAR: {
974 java_lang_Character *co;
976 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
978 ro = builtin_new(class_java_lang_Character);
980 /* setting the value of the object direct */
982 co = (java_lang_Character *) ro;
987 case PRIMITIVETYPE_SHORT: {
991 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
993 ro = builtin_new(class_java_lang_Short);
995 /* setting the value of the object direct */
997 so = (java_lang_Short *) ro;
1002 case PRIMITIVETYPE_INT: {
1004 java_lang_Integer *io;
1006 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1008 ro = builtin_new(class_java_lang_Integer);
1010 /* setting the value of the object direct */
1012 io = (java_lang_Integer *) ro;
1017 case PRIMITIVETYPE_LONG: {
1021 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1023 ro = builtin_new(class_java_lang_Long);
1025 /* setting the value of the object direct */
1027 lo = (java_lang_Long *) ro;
1032 case PRIMITIVETYPE_FLOAT: {
1034 java_lang_Float *fo;
1036 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1038 ro = builtin_new(class_java_lang_Float);
1040 /* setting the value of the object direct */
1042 fo = (java_lang_Float *) ro;
1047 case PRIMITIVETYPE_DOUBLE: {
1049 java_lang_Double *_do;
1051 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1053 ro = builtin_new(class_java_lang_Double);
1055 /* setting the value of the object direct */
1057 _do = (java_lang_Double *) ro;
1063 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1067 /* if this happens the exception has already been set by
1068 fill_callblock_from_objectarray */
1070 MFREE(vmargs, vm_arg, argcount);
1075 MFREE(vmargs, vm_arg, argcount);
1077 xptr = exceptions_get_exception();
1080 /* clear exception pointer, we are calling JIT code again */
1082 exceptions_clear_exception();
1084 exceptions_throw_invocationtargetexception(xptr);
1091 /* GetVersion ******************************************************************
1093 Returns the major version number in the higher 16 bits and the
1094 minor version number in the lower 16 bits.
1096 *******************************************************************************/
1098 jint _Jv_JNI_GetVersion(JNIEnv *env)
1100 STATISTICS(jniinvokation());
1102 /* we support JNI 1.4 */
1104 return JNI_VERSION_1_4;
1108 /* Class Operations ***********************************************************/
1110 /* DefineClass *****************************************************************
1112 Loads a class from a buffer of raw class data. The buffer
1113 containing the raw class data is not referenced by the VM after the
1114 DefineClass call returns, and it may be discarded if desired.
1116 *******************************************************************************/
1118 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1119 const jbyte *buf, jsize bufLen)
1121 #if defined(ENABLE_JAVASE)
1122 java_lang_ClassLoader *cl;
1123 java_lang_String *s;
1127 STATISTICS(jniinvokation());
1129 cl = (java_lang_ClassLoader *) loader;
1130 s = (java_lang_String *) javastring_new_from_utf_string(name);
1131 ba = (java_bytearray *) buf;
1133 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1136 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1138 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1140 /* keep compiler happy */
1147 /* FindClass *******************************************************************
1149 This function loads a locally-defined class. It searches the
1150 directories and zip files specified by the CLASSPATH environment
1151 variable for the class with the specified name.
1153 *******************************************************************************/
1155 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1157 #if defined(ENABLE_JAVASE)
1162 STATISTICS(jniinvokation());
1164 u = utf_new_char_classname((char *) name);
1166 /* Check stacktrace for classloader, if one found use it,
1167 otherwise use the system classloader. */
1169 /* Quote from the JNI documentation:
1171 In the Java 2 Platform, FindClass locates the class loader
1172 associated with the current native method. If the native code
1173 belongs to a system class, no class loader will be
1174 involved. Otherwise, the proper class loader will be invoked to
1175 load and link the named class. When FindClass is called through
1176 the Invocation Interface, there is no current native method or
1177 its associated class loader. In that case, the result of
1178 ClassLoader.getBaseClassLoader is used." */
1180 cc = stacktrace_getCurrentClass();
1183 c = load_class_from_sysloader(u);
1185 c = load_class_from_classloader(u, cc->classloader);
1193 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1195 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1197 /* keep compiler happy */
1204 /* GetSuperclass ***************************************************************
1206 If clazz represents any class other than the class Object, then
1207 this function returns the object that represents the superclass of
1208 the class specified by clazz.
1210 *******************************************************************************/
1212 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1216 STATISTICS(jniinvokation());
1218 c = ((classinfo *) sub)->super.cls;
1223 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1227 /* IsAssignableFrom ************************************************************
1229 Determines whether an object of sub can be safely cast to sup.
1231 *******************************************************************************/
1233 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1235 java_lang_Class *csup;
1236 java_lang_Class *csub;
1238 csup = (java_lang_Class *) sup;
1239 csub = (java_lang_Class *) sub;
1241 STATISTICS(jniinvokation());
1243 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1247 /* Throw ***********************************************************************
1249 Causes a java.lang.Throwable object to be thrown.
1251 *******************************************************************************/
1253 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1255 java_objectheader *o;
1257 STATISTICS(jniinvokation());
1259 o = (java_objectheader *) obj;
1261 exceptions_set_exception(o);
1267 /* ThrowNew ********************************************************************
1269 Constructs an exception object from the specified class with the
1270 message specified by message and causes that exception to be
1273 *******************************************************************************/
1275 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1278 java_objectheader *o;
1279 java_objectheader *s;
1281 STATISTICS(jniinvokation());
1283 c = (classinfo *) clazz;
1284 s = javastring_new_from_utf_string(msg);
1286 /* instantiate exception object */
1288 o = native_new_and_init_string(c, s);
1293 exceptions_set_exception(o);
1299 /* ExceptionOccurred ***********************************************************
1301 Determines if an exception is being thrown. The exception stays
1302 being thrown until either the native code calls ExceptionClear(),
1303 or the Java code handles the exception.
1305 *******************************************************************************/
1307 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1309 java_objectheader *o;
1311 STATISTICS(jniinvokation());
1313 o = exceptions_get_exception();
1315 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1319 /* ExceptionDescribe ***********************************************************
1321 Prints an exception and a backtrace of the stack to a system
1322 error-reporting channel, such as stderr. This is a convenience
1323 routine provided for debugging.
1325 *******************************************************************************/
1327 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1329 java_objectheader *o;
1332 STATISTICS(jniinvokation());
1334 o = exceptions_get_exception();
1337 /* clear exception, because we are calling jit code again */
1339 exceptions_clear_exception();
1341 /* get printStackTrace method from exception class */
1343 m = class_resolveclassmethod(o->vftbl->class,
1344 utf_printStackTrace,
1350 /* XXX what should we do? */
1353 /* print the stacktrace */
1355 (void) vm_call_method(m, o);
1360 /* ExceptionClear **************************************************************
1362 Clears any exception that is currently being thrown. If no
1363 exception is currently being thrown, this routine has no effect.
1365 *******************************************************************************/
1367 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1369 STATISTICS(jniinvokation());
1371 exceptions_clear_exception();
1375 /* FatalError ******************************************************************
1377 Raises a fatal error and does not expect the VM to recover. This
1378 function does not return.
1380 *******************************************************************************/
1382 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1384 STATISTICS(jniinvokation());
1386 /* this seems to be the best way */
1392 /* PushLocalFrame **************************************************************
1394 Creates a new local reference frame, in which at least a given
1395 number of local references can be created.
1397 *******************************************************************************/
1399 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1402 localref_table *lrt;
1403 localref_table *nlrt;
1405 STATISTICS(jniinvokation());
1410 /* Allocate new local reference table on Java heap. Calculate the
1411 additional memory we have to allocate. */
1413 if (capacity > LOCALREFTABLE_CAPACITY)
1414 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1418 #if defined(ENABLE_GC_CACAO)
1419 nlrt = MNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1421 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1427 /* get current local reference table from thread */
1429 lrt = LOCALREFTABLE;
1431 /* Set up the new local reference table and add it to the local
1434 nlrt->capacity = capacity;
1436 nlrt->localframes = lrt->localframes + 1;
1439 /* store new local reference table in thread */
1441 LOCALREFTABLE = nlrt;
1447 /* PopLocalFrame ***************************************************************
1449 Pops off the current local reference frame, frees all the local
1450 references, and returns a local reference in the previous local
1451 reference frame for the given result object.
1453 *******************************************************************************/
1455 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1457 localref_table *lrt;
1458 localref_table *plrt;
1462 STATISTICS(jniinvokation());
1464 /* get current local reference table from thread */
1466 lrt = LOCALREFTABLE;
1468 localframes = lrt->localframes;
1470 /* Don't delete the top local frame, as this one is allocated in
1471 the native stub on the stack and is freed automagically on
1474 if (localframes == 1)
1475 return _Jv_JNI_NewLocalRef(env, result);
1477 /* release all current local frames */
1479 for (; localframes >= 1; localframes--) {
1480 /* get previous frame */
1484 /* clear all reference entries */
1486 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1490 #if defined(ENABLE_GC_CACAO)
1491 /* for the exact GC local reference tables are not on the heap,
1492 so we need to free them explicitly here. */
1494 if (lrt->capacity > LOCALREFTABLE_CAPACITY)
1495 additionalrefs = lrt->capacity - LOCALREFTABLE_CAPACITY;
1499 MFREE(lrt, u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1502 /* set new local references table */
1507 /* store new local reference table in thread */
1509 LOCALREFTABLE = lrt;
1511 /* add local reference and return the value */
1513 return _Jv_JNI_NewLocalRef(env, result);
1517 /* DeleteLocalRef **************************************************************
1519 Deletes the local reference pointed to by localRef.
1521 *******************************************************************************/
1523 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1525 java_objectheader *o;
1526 localref_table *lrt;
1529 STATISTICS(jniinvokation());
1531 o = (java_objectheader *) localRef;
1533 /* get local reference table (thread specific) */
1535 lrt = LOCALREFTABLE;
1537 /* go through all local frames */
1539 for (; lrt != NULL; lrt = lrt->prev) {
1541 /* and try to remove the reference */
1543 for (i = 0; i < lrt->capacity; i++) {
1544 if (lrt->refs[i] == o) {
1545 lrt->refs[i] = NULL;
1553 /* this should not happen */
1555 /* if (opt_checkjni) */
1556 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1557 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1561 /* IsSameObject ****************************************************************
1563 Tests whether two references refer to the same Java object.
1565 *******************************************************************************/
1567 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1569 STATISTICS(jniinvokation());
1578 /* NewLocalRef *****************************************************************
1580 Creates a new local reference that refers to the same object as ref.
1582 *******************************************************************************/
1584 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1586 localref_table *lrt;
1589 STATISTICS(jniinvokation());
1594 /* get local reference table (thread specific) */
1596 lrt = LOCALREFTABLE;
1598 /* Check if we have space for the requested reference? No,
1599 allocate a new frame. This is actually not what the spec says,
1600 but for compatibility reasons... */
1602 if (lrt->used == lrt->capacity) {
1603 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1606 /* get the new local reference table */
1608 lrt = LOCALREFTABLE;
1611 /* insert the reference */
1613 for (i = 0; i < lrt->capacity; i++) {
1614 if (lrt->refs[i] == NULL) {
1615 lrt->refs[i] = (java_objectheader *) ref;
1622 /* should not happen, just to be sure */
1626 /* keep compiler happy */
1632 /* EnsureLocalCapacity *********************************************************
1634 Ensures that at least a given number of local references can be
1635 created in the current thread
1637 *******************************************************************************/
1639 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1641 localref_table *lrt;
1643 STATISTICS(jniinvokation());
1645 /* get local reference table (thread specific) */
1647 lrt = LOCALREFTABLE;
1649 /* check if capacity elements are available in the local references table */
1651 if ((lrt->used + capacity) > lrt->capacity)
1652 return _Jv_JNI_PushLocalFrame(env, capacity);
1658 /* AllocObject *****************************************************************
1660 Allocates a new Java object without invoking any of the
1661 constructors for the object. Returns a reference to the object.
1663 *******************************************************************************/
1665 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1668 java_objectheader *o;
1670 STATISTICS(jniinvokation());
1672 c = (classinfo *) clazz;
1674 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1675 exceptions_throw_instantiationexception(c);
1681 return _Jv_JNI_NewLocalRef(env, o);
1685 /* NewObject *******************************************************************
1687 Programmers place all arguments that are to be passed to the
1688 constructor immediately following the methodID
1689 argument. NewObject() accepts these arguments and passes them to
1690 the Java method that the programmer wishes to invoke.
1692 *******************************************************************************/
1694 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1696 java_objectheader *o;
1700 STATISTICS(jniinvokation());
1702 m = (methodinfo *) methodID;
1706 o = builtin_new(clazz);
1711 /* call constructor */
1713 va_start(ap, methodID);
1714 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1717 return _Jv_JNI_NewLocalRef(env, o);
1721 /* NewObjectV ******************************************************************
1723 Programmers place all arguments that are to be passed to the
1724 constructor in an args argument of type va_list that immediately
1725 follows the methodID argument. NewObjectV() accepts these
1726 arguments, and, in turn, passes them to the Java method that the
1727 programmer wishes to invoke.
1729 *******************************************************************************/
1731 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1734 java_objectheader *o;
1737 STATISTICS(jniinvokation());
1739 m = (methodinfo *) methodID;
1743 o = builtin_new(clazz);
1748 /* call constructor */
1750 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1752 return _Jv_JNI_NewLocalRef(env, o);
1756 /* NewObjectA *****************************************************************
1758 Programmers place all arguments that are to be passed to the
1759 constructor in an args array of jvalues that immediately follows
1760 the methodID argument. NewObjectA() accepts the arguments in this
1761 array, and, in turn, passes them to the Java method that the
1762 programmer wishes to invoke.
1764 *******************************************************************************/
1766 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1769 java_objectheader *o;
1772 STATISTICS(jniinvokation());
1774 m = (methodinfo *) methodID;
1778 o = builtin_new(clazz);
1783 /* call constructor */
1785 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1787 return _Jv_JNI_NewLocalRef(env, o);
1791 /* GetObjectClass **************************************************************
1793 Returns the class of an object.
1795 *******************************************************************************/
1797 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1799 java_objectheader *o;
1802 STATISTICS(jniinvokation());
1804 o = (java_objectheader *) obj;
1806 if ((o == NULL) || (o->vftbl == NULL))
1809 c = o->vftbl->class;
1811 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1815 /* IsInstanceOf ****************************************************************
1817 Tests whether an object is an instance of a class.
1819 *******************************************************************************/
1821 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1824 java_lang_Object *o;
1826 STATISTICS(jniinvokation());
1828 c = (java_lang_Class *) clazz;
1829 o = (java_lang_Object *) obj;
1831 return _Jv_java_lang_Class_isInstance(c, o);
1835 /* Reflection Support *********************************************************/
1837 /* FromReflectedMethod *********************************************************
1839 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1840 object to a method ID.
1842 *******************************************************************************/
1844 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1846 #if defined(ENABLE_JAVASE)
1851 STATISTICS(jniinvokation());
1856 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1857 java_lang_reflect_Method *rm;
1859 rm = (java_lang_reflect_Method *) method;
1860 c = (classinfo *) (rm->declaringClass);
1863 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1864 java_lang_reflect_Constructor *rc;
1866 rc = (java_lang_reflect_Constructor *) method;
1867 c = (classinfo *) (rc->clazz);
1873 mi = &(c->methods[slot]);
1875 return (jmethodID) mi;
1877 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1879 /* keep compiler happy */
1886 /* FromReflectedField **********************************************************
1888 Converts a java.lang.reflect.Field to a field ID.
1890 *******************************************************************************/
1892 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1894 #if defined(ENABLE_JAVASE)
1895 java_lang_reflect_Field *rf;
1899 STATISTICS(jniinvokation());
1901 rf = (java_lang_reflect_Field *) field;
1906 c = (classinfo *) rf->declaringClass;
1908 f = &(c->fields[rf->slot]);
1910 return (jfieldID) f;
1912 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1914 /* keep compiler happy */
1921 /* ToReflectedMethod ***********************************************************
1923 Converts a method ID derived from cls to an instance of the
1924 java.lang.reflect.Method class or to an instance of the
1925 java.lang.reflect.Constructor class.
1927 *******************************************************************************/
1929 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1932 STATISTICS(jniinvokation());
1934 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1940 /* ToReflectedField ************************************************************
1942 Converts a field ID derived from cls to an instance of the
1943 java.lang.reflect.Field class.
1945 *******************************************************************************/
1947 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1950 STATISTICS(jniinvokation());
1952 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1958 /* Calling Instance Methods ***************************************************/
1960 /* GetMethodID *****************************************************************
1962 Returns the method ID for an instance (nonstatic) method of a class
1963 or interface. The method may be defined in one of the clazz's
1964 superclasses and inherited by clazz. The method is determined by
1965 its name and signature.
1967 GetMethodID() causes an uninitialized class to be initialized.
1969 *******************************************************************************/
1971 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1979 STATISTICS(jniinvokation());
1981 c = (classinfo *) clazz;
1986 if (!(c->state & CLASS_INITIALIZED))
1987 if (!initialize_class(c))
1990 /* try to get the method of the class or one of it's superclasses */
1992 uname = utf_new_char((char *) name);
1993 udesc = utf_new_char((char *) sig);
1995 m = class_resolvemethod(clazz, uname, udesc);
1997 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1998 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2003 return (jmethodID) m;
2007 /* JNI-functions for calling instance methods *********************************/
2009 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2012 java_objectheader *o;
2014 java_objectheader *ret;
2017 o = (java_objectheader *) obj;
2018 m = (methodinfo *) methodID;
2020 va_start(ap, methodID);
2021 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2024 return _Jv_JNI_NewLocalRef(env, ret);
2028 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2031 java_objectheader *o;
2033 java_objectheader *ret;
2035 o = (java_objectheader *) obj;
2036 m = (methodinfo *) methodID;
2038 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2040 return _Jv_JNI_NewLocalRef(env, ret);
2044 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2047 java_objectheader *o;
2049 java_objectheader *ret;
2051 o = (java_objectheader *) obj;
2052 m = (methodinfo *) methodID;
2054 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2056 return _Jv_JNI_NewLocalRef(env, ret);
2060 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2063 java_objectheader *o;
2068 o = (java_objectheader *) obj;
2069 m = (methodinfo *) methodID;
2071 va_start(ap, methodID);
2072 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2079 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2080 jmethodID methodID, va_list args)
2082 java_objectheader *o;
2086 o = (java_objectheader *) obj;
2087 m = (methodinfo *) methodID;
2089 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2095 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2096 jmethodID methodID, jvalue *args)
2098 java_objectheader *o;
2102 o = (java_objectheader *) obj;
2103 m = (methodinfo *) methodID;
2105 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2111 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2113 java_objectheader *o;
2118 o = (java_objectheader *) obj;
2119 m = (methodinfo *) methodID;
2121 va_start(ap, methodID);
2122 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2130 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2133 java_objectheader *o;
2137 o = (java_objectheader *) obj;
2138 m = (methodinfo *) methodID;
2140 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2146 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2149 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2155 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2157 java_objectheader *o;
2162 o = (java_objectheader *) obj;
2163 m = (methodinfo *) methodID;
2165 va_start(ap, methodID);
2166 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2173 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2176 java_objectheader *o;
2180 o = (java_objectheader *) obj;
2181 m = (methodinfo *) methodID;
2183 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2189 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2192 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2198 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2201 java_objectheader *o;
2206 o = (java_objectheader *) obj;
2207 m = (methodinfo *) methodID;
2209 va_start(ap, methodID);
2210 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2217 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2220 java_objectheader *o;
2224 o = (java_objectheader *) obj;
2225 m = (methodinfo *) methodID;
2227 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2233 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2236 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2243 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2245 java_objectheader *o;
2250 o = (java_objectheader *) obj;
2251 m = (methodinfo *) methodID;
2253 va_start(ap, methodID);
2254 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2261 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2264 java_objectheader *o;
2268 o = (java_objectheader *) obj;
2269 m = (methodinfo *) methodID;
2271 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2277 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2280 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2287 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2289 java_objectheader *o;
2294 o = (java_objectheader *) obj;
2295 m = (methodinfo *) methodID;
2297 va_start(ap, methodID);
2298 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2305 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2308 java_objectheader *o;
2312 o = (java_objectheader *) obj;
2313 m = (methodinfo *) methodID;
2315 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2321 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2324 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2331 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2334 java_objectheader *o;
2339 o = (java_objectheader *) obj;
2340 m = (methodinfo *) methodID;
2342 va_start(ap, methodID);
2343 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2350 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2353 java_objectheader *o;
2357 o = (java_objectheader *) obj;
2358 m = (methodinfo *) methodID;
2360 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2366 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2369 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2376 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2379 java_objectheader *o;
2384 o = (java_objectheader *) obj;
2385 m = (methodinfo *) methodID;
2387 va_start(ap, methodID);
2388 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2395 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2398 java_objectheader *o;
2402 o = (java_objectheader *) obj;
2403 m = (methodinfo *) methodID;
2405 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2411 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2414 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2421 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2423 java_objectheader *o;
2427 o = (java_objectheader *) obj;
2428 m = (methodinfo *) methodID;
2430 va_start(ap, methodID);
2431 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2436 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2439 java_objectheader *o;
2442 o = (java_objectheader *) obj;
2443 m = (methodinfo *) methodID;
2445 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2449 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2452 java_objectheader *o;
2455 o = (java_objectheader *) obj;
2456 m = (methodinfo *) methodID;
2458 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2463 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2464 jclass clazz, jmethodID methodID,
2467 java_objectheader *o;
2470 java_objectheader *r;
2473 o = (java_objectheader *) obj;
2474 c = (classinfo *) clazz;
2475 m = (methodinfo *) methodID;
2477 va_start(ap, methodID);
2478 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2481 return _Jv_JNI_NewLocalRef(env, r);
2485 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2486 jclass clazz, jmethodID methodID,
2489 java_objectheader *o;
2492 java_objectheader *r;
2494 o = (java_objectheader *) obj;
2495 c = (classinfo *) clazz;
2496 m = (methodinfo *) methodID;
2498 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2500 return _Jv_JNI_NewLocalRef(env, r);
2504 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2505 jclass clazz, jmethodID methodID,
2508 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2510 return _Jv_JNI_NewLocalRef(env, NULL);
2515 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2516 jclass clazz, jmethodID methodID,
2519 java_objectheader *o;
2525 o = (java_objectheader *) obj;
2526 c = (classinfo *) clazz;
2527 m = (methodinfo *) methodID;
2529 va_start(ap, methodID);
2530 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2537 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2538 jclass clazz, jmethodID methodID,
2541 java_objectheader *o;
2546 o = (java_objectheader *) obj;
2547 c = (classinfo *) clazz;
2548 m = (methodinfo *) methodID;
2550 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2556 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2557 jclass clazz, jmethodID methodID,
2560 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2566 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2567 jmethodID methodID, ...)
2569 java_objectheader *o;
2575 o = (java_objectheader *) obj;
2576 c = (classinfo *) clazz;
2577 m = (methodinfo *) methodID;
2579 va_start(ap, methodID);
2580 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2587 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2588 jmethodID methodID, va_list args)
2590 java_objectheader *o;
2595 o = (java_objectheader *) obj;
2596 c = (classinfo *) clazz;
2597 m = (methodinfo *) methodID;
2599 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2605 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2606 jmethodID methodID, jvalue *args)
2608 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2615 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2616 jmethodID methodID, ...)
2618 java_objectheader *o;
2624 o = (java_objectheader *) obj;
2625 c = (classinfo *) clazz;
2626 m = (methodinfo *) methodID;
2628 va_start(ap, methodID);
2629 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2636 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2637 jmethodID methodID, va_list args)
2639 java_objectheader *o;
2644 o = (java_objectheader *) obj;
2645 c = (classinfo *) clazz;
2646 m = (methodinfo *) methodID;
2648 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2654 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2655 jmethodID methodID, jvalue *args)
2657 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2664 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2665 jclass clazz, jmethodID methodID, ...)
2667 java_objectheader *o;
2673 o = (java_objectheader *) obj;
2674 c = (classinfo *) clazz;
2675 m = (methodinfo *) methodID;
2677 va_start(ap, methodID);
2678 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2685 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2686 jclass clazz, jmethodID methodID,
2689 java_objectheader *o;
2694 o = (java_objectheader *) obj;
2695 c = (classinfo *) clazz;
2696 m = (methodinfo *) methodID;
2698 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2704 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2705 jclass clazz, jmethodID methodID,
2708 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2715 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2716 jmethodID methodID, ...)
2718 java_objectheader *o;
2724 o = (java_objectheader *) obj;
2725 c = (classinfo *) clazz;
2726 m = (methodinfo *) methodID;
2728 va_start(ap, methodID);
2729 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2736 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2737 jmethodID methodID, va_list args)
2739 java_objectheader *o;
2744 o = (java_objectheader *) obj;
2745 c = (classinfo *) clazz;
2746 m = (methodinfo *) methodID;
2748 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2754 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2755 jmethodID methodID, jvalue *args)
2757 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2764 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2765 jmethodID methodID, ...)
2767 java_objectheader *o;
2773 o = (java_objectheader *) obj;
2774 c = (classinfo *) clazz;
2775 m = (methodinfo *) methodID;
2777 va_start(ap, methodID);
2778 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2785 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2786 jmethodID methodID, va_list args)
2788 java_objectheader *o;
2793 o = (java_objectheader *) obj;
2794 c = (classinfo *) clazz;
2795 m = (methodinfo *) methodID;
2797 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2803 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2804 jmethodID methodID, jvalue *args)
2806 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2813 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2814 jclass clazz, jmethodID methodID, ...)
2816 java_objectheader *o;
2822 o = (java_objectheader *) obj;
2823 c = (classinfo *) clazz;
2824 m = (methodinfo *) methodID;
2826 va_start(ap, methodID);
2827 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2834 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2835 jclass clazz, jmethodID methodID,
2838 java_objectheader *o;
2843 o = (java_objectheader *) obj;
2844 c = (classinfo *) clazz;
2845 m = (methodinfo *) methodID;
2847 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2853 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2854 jclass clazz, jmethodID methodID,
2857 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2864 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2865 jclass clazz, jmethodID methodID,
2868 java_objectheader *o;
2874 o = (java_objectheader *) obj;
2875 c = (classinfo *) clazz;
2876 m = (methodinfo *) methodID;
2878 va_start(ap, methodID);
2879 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2886 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2887 jclass clazz, jmethodID methodID,
2890 java_objectheader *o;
2895 o = (java_objectheader *) obj;
2896 c = (classinfo *) clazz;
2897 m = (methodinfo *) methodID;
2899 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2905 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2906 jclass clazz, jmethodID methodID,
2909 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2916 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2917 jmethodID methodID, ...)
2919 java_objectheader *o;
2924 o = (java_objectheader *) obj;
2925 c = (classinfo *) clazz;
2926 m = (methodinfo *) methodID;
2928 va_start(ap, methodID);
2929 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2934 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2935 jmethodID methodID, va_list args)
2937 java_objectheader *o;
2941 o = (java_objectheader *) obj;
2942 c = (classinfo *) clazz;
2943 m = (methodinfo *) methodID;
2945 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2949 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2950 jmethodID methodID, jvalue * args)
2952 java_objectheader *o;
2956 o = (java_objectheader *) obj;
2957 c = (classinfo *) clazz;
2958 m = (methodinfo *) methodID;
2960 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2964 /* Accessing Fields of Objects ************************************************/
2966 /* GetFieldID ******************************************************************
2968 Returns the field ID for an instance (nonstatic) field of a
2969 class. The field is specified by its name and signature. The
2970 Get<type>Field and Set<type>Field families of accessor functions
2971 use field IDs to retrieve object fields.
2973 *******************************************************************************/
2975 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2983 STATISTICS(jniinvokation());
2985 c = (classinfo *) clazz;
2987 uname = utf_new_char((char *) name);
2988 udesc = utf_new_char((char *) sig);
2990 f = class_findfield(clazz, uname, udesc);
2993 exceptions_throw_nosuchfielderror(c, uname);
2995 return (jfieldID) f;
2999 /* Get<type>Field Routines *****************************************************
3001 This family of accessor routines returns the value of an instance
3002 (nonstatic) field of an object. The field to access is specified by
3003 a field ID obtained by calling GetFieldID().
3005 *******************************************************************************/
3007 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3009 java_objectheader *o;
3011 STATISTICS(jniinvokation());
3013 o = GET_FIELD(obj, java_objectheader*, fieldID);
3015 return _Jv_JNI_NewLocalRef(env, o);
3019 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3023 STATISTICS(jniinvokation());
3025 i = GET_FIELD(obj, s4, fieldID);
3027 return (jboolean) i;
3031 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3035 STATISTICS(jniinvokation());
3037 i = GET_FIELD(obj, s4, fieldID);
3043 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3047 STATISTICS(jniinvokation());
3049 i = GET_FIELD(obj, s4, fieldID);
3055 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3059 STATISTICS(jniinvokation());
3061 i = GET_FIELD(obj, s4, fieldID);
3067 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3069 java_objectheader *o;
3073 STATISTICS(jniinvokation());
3075 o = (java_objectheader *) obj;
3076 f = (fieldinfo *) fieldID;
3078 i = GET_FIELD(o, s4, f);
3084 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3088 STATISTICS(jniinvokation());
3090 l = GET_FIELD(obj, s8, fieldID);
3096 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3100 STATISTICS(jniinvokation());
3102 f = GET_FIELD(obj, float, fieldID);
3108 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3112 STATISTICS(jniinvokation());
3114 d = GET_FIELD(obj, double, fieldID);
3120 /* Set<type>Field Routines *****************************************************
3122 This family of accessor routines sets the value of an instance
3123 (nonstatic) field of an object. The field to access is specified by
3124 a field ID obtained by calling GetFieldID().
3126 *******************************************************************************/
3128 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3131 STATISTICS(jniinvokation());
3133 SET_FIELD(obj, java_objectheader*, fieldID, value);
3137 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3140 STATISTICS(jniinvokation());
3142 SET_FIELD(obj, s4, fieldID, value);
3146 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3149 STATISTICS(jniinvokation());
3151 SET_FIELD(obj, s4, fieldID, value);
3155 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3158 STATISTICS(jniinvokation());
3160 SET_FIELD(obj, s4, fieldID, value);
3164 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3167 STATISTICS(jniinvokation());
3169 SET_FIELD(obj, s4, fieldID, value);
3173 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3175 STATISTICS(jniinvokation());
3177 SET_FIELD(obj, s4, fieldID, value);
3181 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3184 STATISTICS(jniinvokation());
3186 SET_FIELD(obj, s8, fieldID, value);
3190 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3193 STATISTICS(jniinvokation());
3195 SET_FIELD(obj, float, fieldID, value);
3199 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3202 STATISTICS(jniinvokation());
3204 SET_FIELD(obj, double, fieldID, value);
3208 /* Calling Static Methods *****************************************************/
3210 /* GetStaticMethodID ***********************************************************
3212 Returns the method ID for a static method of a class. The method is
3213 specified by its name and signature.
3215 GetStaticMethodID() causes an uninitialized class to be
3218 *******************************************************************************/
3220 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3228 STATISTICS(jniinvokation());
3230 c = (classinfo *) clazz;
3235 if (!(c->state & CLASS_INITIALIZED))
3236 if (!initialize_class(c))
3239 /* try to get the static method of the class */
3241 uname = utf_new_char((char *) name);
3242 udesc = utf_new_char((char *) sig);
3244 m = class_resolvemethod(c, uname, udesc);
3246 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3247 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3252 return (jmethodID) m;
3256 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3257 jmethodID methodID, ...)
3260 java_objectheader *o;
3263 m = (methodinfo *) methodID;
3265 va_start(ap, methodID);
3266 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3269 return _Jv_JNI_NewLocalRef(env, o);
3273 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3274 jmethodID methodID, va_list args)
3277 java_objectheader *o;
3279 m = (methodinfo *) methodID;
3281 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3283 return _Jv_JNI_NewLocalRef(env, o);
3287 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3288 jmethodID methodID, jvalue *args)
3291 java_objectheader *o;
3293 m = (methodinfo *) methodID;
3295 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3297 return _Jv_JNI_NewLocalRef(env, o);
3301 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3302 jmethodID methodID, ...)
3308 m = (methodinfo *) methodID;
3310 va_start(ap, methodID);
3311 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3318 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3319 jmethodID methodID, va_list args)
3324 m = (methodinfo *) methodID;
3326 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3332 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3333 jmethodID methodID, jvalue *args)
3335 log_text("JNI-Call: CallStaticBooleanMethodA: IMPLEMENT ME!");
3341 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3342 jmethodID methodID, ...)
3348 m = (methodinfo *) methodID;
3350 va_start(ap, methodID);
3351 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3358 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3359 jmethodID methodID, va_list args)
3364 m = (methodinfo *) methodID;
3366 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3372 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3373 jmethodID methodID, jvalue *args)
3375 log_text("JNI-Call: CallStaticByteMethodA: IMPLEMENT ME!");
3381 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3382 jmethodID methodID, ...)
3388 m = (methodinfo *) methodID;
3390 va_start(ap, methodID);
3391 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3398 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3399 jmethodID methodID, va_list args)
3404 m = (methodinfo *) methodID;
3406 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3412 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3413 jmethodID methodID, jvalue *args)
3415 log_text("JNI-Call: CallStaticCharMethodA: IMPLEMENT ME!");
3421 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3422 jmethodID methodID, ...)
3428 m = (methodinfo *) methodID;
3430 va_start(ap, methodID);
3431 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3438 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3439 jmethodID methodID, va_list args)
3444 m = (methodinfo *) methodID;
3446 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3452 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3453 jmethodID methodID, jvalue *args)
3455 log_text("JNI-Call: CallStaticShortMethodA: IMPLEMENT ME!");
3461 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3468 m = (methodinfo *) methodID;
3470 va_start(ap, methodID);
3471 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3478 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3479 jmethodID methodID, va_list args)
3484 m = (methodinfo *) methodID;
3486 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3492 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3493 jmethodID methodID, jvalue *args)
3495 log_text("JNI-Call: CallStaticIntMethodA: IMPLEMENT ME!");
3501 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3502 jmethodID methodID, ...)
3508 m = (methodinfo *) methodID;
3510 va_start(ap, methodID);
3511 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3518 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3519 jmethodID methodID, va_list args)
3524 m = (methodinfo *) methodID;
3526 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3532 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3533 jmethodID methodID, jvalue *args)
3535 log_text("JNI-Call: CallStaticLongMethodA: IMPLEMENT ME!");
3542 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3543 jmethodID methodID, ...)
3549 m = (methodinfo *) methodID;
3551 va_start(ap, methodID);
3552 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3559 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3560 jmethodID methodID, va_list args)
3565 m = (methodinfo *) methodID;
3567 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3573 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3574 jmethodID methodID, jvalue *args)
3576 log_text("JNI-Call: CallStaticFloatMethodA: IMPLEMENT ME!");
3582 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3583 jmethodID methodID, ...)
3589 m = (methodinfo *) methodID;
3591 va_start(ap, methodID);
3592 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3599 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3600 jmethodID methodID, va_list args)
3605 m = (methodinfo *) methodID;
3607 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3613 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3614 jmethodID methodID, jvalue *args)
3616 log_text("JNI-Call: CallStaticDoubleMethodA: IMPLEMENT ME!");
3622 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3623 jmethodID methodID, ...)
3628 m = (methodinfo *) methodID;
3630 va_start(ap, methodID);
3631 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3636 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3637 jmethodID methodID, va_list args)
3641 m = (methodinfo *) methodID;
3643 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3647 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3648 jmethodID methodID, jvalue * args)
3652 m = (methodinfo *) methodID;
3654 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3658 /* Accessing Static Fields ****************************************************/
3660 /* GetStaticFieldID ************************************************************
3662 Returns the field ID for a static field of a class. The field is
3663 specified by its name and signature. The GetStatic<type>Field and
3664 SetStatic<type>Field families of accessor functions use field IDs
3665 to retrieve static fields.
3667 *******************************************************************************/
3669 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3677 STATISTICS(jniinvokation());
3679 c = (classinfo *) clazz;
3681 uname = utf_new_char((char *) name);
3682 usig = utf_new_char((char *) sig);
3684 f = class_findfield(clazz, uname, usig);
3687 exceptions_throw_nosuchfielderror(c, uname);
3689 return (jfieldID) f;
3693 /* GetStatic<type>Field ********************************************************
3695 This family of accessor routines returns the value of a static
3698 *******************************************************************************/
3700 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3706 STATISTICS(jniinvokation());
3708 c = (classinfo *) clazz;
3709 f = (fieldinfo *) fieldID;
3711 if (!(c->state & CLASS_INITIALIZED))
3712 if (!initialize_class(c))
3715 return _Jv_JNI_NewLocalRef(env, f->value.a);
3719 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3725 STATISTICS(jniinvokation());
3727 c = (classinfo *) clazz;
3728 f = (fieldinfo *) fieldID;
3730 if (!(c->state & CLASS_INITIALIZED))
3731 if (!initialize_class(c))
3738 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3743 STATISTICS(jniinvokation());
3745 c = (classinfo *) clazz;
3746 f = (fieldinfo *) fieldID;
3748 if (!(c->state & CLASS_INITIALIZED))
3749 if (!initialize_class(c))
3756 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3761 STATISTICS(jniinvokation());
3763 c = (classinfo *) clazz;
3764 f = (fieldinfo *) fieldID;
3766 if (!(c->state & CLASS_INITIALIZED))
3767 if (!initialize_class(c))
3774 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3779 STATISTICS(jniinvokation());
3781 c = (classinfo *) clazz;
3782 f = (fieldinfo *) fieldID;
3784 if (!(c->state & CLASS_INITIALIZED))
3785 if (!initialize_class(c))
3792 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3797 STATISTICS(jniinvokation());
3799 c = (classinfo *) clazz;
3800 f = (fieldinfo *) fieldID;
3802 if (!(c->state & CLASS_INITIALIZED))
3803 if (!initialize_class(c))
3810 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3815 STATISTICS(jniinvokation());
3817 c = (classinfo *) clazz;
3818 f = (fieldinfo *) fieldID;
3820 if (!(c->state & CLASS_INITIALIZED))
3821 if (!initialize_class(c))
3828 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3833 STATISTICS(jniinvokation());
3835 c = (classinfo *) clazz;
3836 f = (fieldinfo *) fieldID;
3838 if (!(c->state & CLASS_INITIALIZED))
3839 if (!initialize_class(c))
3846 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3852 STATISTICS(jniinvokation());
3854 c = (classinfo *) clazz;
3855 f = (fieldinfo *) fieldID;
3857 if (!(c->state & CLASS_INITIALIZED))
3858 if (!initialize_class(c))
3865 /* SetStatic<type>Field *******************************************************
3867 This family of accessor routines sets the value of a static field
3870 *******************************************************************************/
3872 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3878 STATISTICS(jniinvokation());
3880 c = (classinfo *) clazz;
3881 f = (fieldinfo *) fieldID;
3883 if (!(c->state & CLASS_INITIALIZED))
3884 if (!initialize_class(c))
3891 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3897 STATISTICS(jniinvokation());
3899 c = (classinfo *) clazz;
3900 f = (fieldinfo *) fieldID;
3902 if (!(c->state & CLASS_INITIALIZED))
3903 if (!initialize_class(c))
3910 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3916 STATISTICS(jniinvokation());
3918 c = (classinfo *) clazz;
3919 f = (fieldinfo *) fieldID;
3921 if (!(c->state & CLASS_INITIALIZED))
3922 if (!initialize_class(c))
3929 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3935 STATISTICS(jniinvokation());
3937 c = (classinfo *) clazz;
3938 f = (fieldinfo *) fieldID;
3940 if (!(c->state & CLASS_INITIALIZED))
3941 if (!initialize_class(c))
3948 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3954 STATISTICS(jniinvokation());
3956 c = (classinfo *) clazz;
3957 f = (fieldinfo *) fieldID;
3959 if (!(c->state & CLASS_INITIALIZED))
3960 if (!initialize_class(c))
3967 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3973 STATISTICS(jniinvokation());
3975 c = (classinfo *) clazz;
3976 f = (fieldinfo *) fieldID;
3978 if (!(c->state & CLASS_INITIALIZED))
3979 if (!initialize_class(c))
3986 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3992 STATISTICS(jniinvokation());
3994 c = (classinfo *) clazz;
3995 f = (fieldinfo *) fieldID;
3997 if (!(c->state & CLASS_INITIALIZED))
3998 if (!initialize_class(c))
4005 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4011 STATISTICS(jniinvokation());
4013 c = (classinfo *) clazz;
4014 f = (fieldinfo *) fieldID;
4016 if (!(c->state & CLASS_INITIALIZED))
4017 if (!initialize_class(c))
4024 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4030 STATISTICS(jniinvokation());
4032 c = (classinfo *) clazz;
4033 f = (fieldinfo *) fieldID;
4035 if (!(c->state & CLASS_INITIALIZED))
4036 if (!initialize_class(c))
4043 /* String Operations **********************************************************/
4045 /* NewString *******************************************************************
4047 Create new java.lang.String object from an array of Unicode
4050 *******************************************************************************/
4052 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4054 java_lang_String *s;
4058 STATISTICS(jniinvokation());
4060 s = (java_lang_String *) builtin_new(class_java_lang_String);
4061 a = builtin_newarray_char(len);
4063 /* javastring or characterarray could not be created */
4064 if ((a == NULL) || (s == NULL))
4068 for (i = 0; i < len; i++)
4069 a->data[i] = buf[i];
4075 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4079 static jchar emptyStringJ[]={0,0};
4081 /* GetStringLength *************************************************************
4083 Returns the length (the count of Unicode characters) of a Java
4086 *******************************************************************************/
4088 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4090 return ((java_lang_String *) str)->count;
4094 /******************** convertes javastring to u2-array ****************************/
4096 u2 *javastring_tou2(jstring so)
4098 java_lang_String *s;
4103 STATISTICS(jniinvokation());
4105 s = (java_lang_String *) so;
4115 /* allocate memory */
4117 stringbuffer = MNEW(u2, s->count + 1);
4121 for (i = 0; i < s->count; i++)
4122 stringbuffer[i] = a->data[s->offset + i];
4124 /* terminate string */
4126 stringbuffer[i] = '\0';
4128 return stringbuffer;
4132 /* GetStringChars **************************************************************
4134 Returns a pointer to the array of Unicode characters of the
4135 string. This pointer is valid until ReleaseStringChars() is called.
4137 *******************************************************************************/
4139 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4143 STATISTICS(jniinvokation());
4145 jc = javastring_tou2(str);
4157 return emptyStringJ;
4161 /* ReleaseStringChars **********************************************************
4163 Informs the VM that the native code no longer needs access to
4164 chars. The chars argument is a pointer obtained from string using
4167 *******************************************************************************/
4169 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4171 STATISTICS(jniinvokation());
4173 if (chars == emptyStringJ)
4176 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4180 /* NewStringUTF ****************************************************************
4182 Constructs a new java.lang.String object from an array of UTF-8
4185 *******************************************************************************/
4187 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4189 java_lang_String *s;
4191 STATISTICS(jniinvokation());
4193 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4195 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4199 /****************** returns the utf8 length in bytes of a string *******************/
4201 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4203 java_lang_String *s = (java_lang_String*) string;
4205 STATISTICS(jniinvokation());
4207 return (jsize) u2_utflength(s->value->data, s->count);
4211 /* GetStringUTFChars ***********************************************************
4213 Returns a pointer to an array of UTF-8 characters of the
4214 string. This array is valid until it is released by
4215 ReleaseStringUTFChars().
4217 *******************************************************************************/
4219 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4224 STATISTICS(jniinvokation());
4232 u = javastring_toutf((java_objectheader *) string, false);
4241 /* ReleaseStringUTFChars *******************************************************
4243 Informs the VM that the native code no longer needs access to
4244 utf. The utf argument is a pointer derived from string using
4245 GetStringUTFChars().
4247 *******************************************************************************/
4249 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4251 STATISTICS(jniinvokation());
4253 /* XXX we don't release utf chars right now, perhaps that should be done
4254 later. Since there is always one reference the garbage collector will
4259 /* Array Operations ***********************************************************/
4261 /* GetArrayLength **************************************************************
4263 Returns the number of elements in the array.
4265 *******************************************************************************/
4267 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4269 java_arrayheader *a;
4271 STATISTICS(jniinvokation());
4273 a = (java_arrayheader *) array;
4279 /* NewObjectArray **************************************************************
4281 Constructs a new array holding objects in class elementClass. All
4282 elements are initially set to initialElement.
4284 *******************************************************************************/
4286 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4287 jclass elementClass, jobject initialElement)
4289 java_objectarray *oa;
4292 STATISTICS(jniinvokation());
4295 exceptions_throw_negativearraysizeexception();
4299 oa = builtin_anewarray(length, elementClass);
4304 /* set all elements to initialElement */
4306 for (i = 0; i < length; i++)
4307 oa->data[i] = initialElement;
4309 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4313 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4316 java_objectarray *oa;
4319 STATISTICS(jniinvokation());
4321 oa = (java_objectarray *) array;
4323 if (index >= oa->header.size) {
4324 exceptions_throw_arrayindexoutofboundsexception();
4328 o = oa->data[index];
4330 return _Jv_JNI_NewLocalRef(env, o);
4334 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4335 jsize index, jobject val)
4337 java_objectarray *oa;
4338 java_objectheader *o;
4340 STATISTICS(jniinvokation());
4342 oa = (java_objectarray *) array;
4343 o = (java_objectheader *) val;
4345 if (index >= oa->header.size) {
4346 exceptions_throw_arrayindexoutofboundsexception();
4350 /* check if the class of value is a subclass of the element class
4353 if (!builtin_canstore(oa, o))
4356 oa->data[index] = val;
4360 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4362 java_booleanarray *ba;
4364 STATISTICS(jniinvokation());
4367 exceptions_throw_negativearraysizeexception();
4371 ba = builtin_newarray_boolean(len);
4373 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4377 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4381 STATISTICS(jniinvokation());
4384 exceptions_throw_negativearraysizeexception();
4388 ba = builtin_newarray_byte(len);
4390 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4394 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4398 STATISTICS(jniinvokation());
4401 exceptions_throw_negativearraysizeexception();
4405 ca = builtin_newarray_char(len);
4407 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4411 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4413 java_shortarray *sa;
4415 STATISTICS(jniinvokation());
4418 exceptions_throw_negativearraysizeexception();
4422 sa = builtin_newarray_short(len);
4424 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4428 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4432 STATISTICS(jniinvokation());
4435 exceptions_throw_negativearraysizeexception();
4439 ia = builtin_newarray_int(len);
4441 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4445 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4449 STATISTICS(jniinvokation());
4452 exceptions_throw_negativearraysizeexception();
4456 la = builtin_newarray_long(len);
4458 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4462 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4464 java_floatarray *fa;
4466 STATISTICS(jniinvokation());
4469 exceptions_throw_negativearraysizeexception();
4473 fa = builtin_newarray_float(len);
4475 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4479 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4481 java_doublearray *da;
4483 STATISTICS(jniinvokation());
4486 exceptions_throw_negativearraysizeexception();
4490 da = builtin_newarray_double(len);
4492 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4496 /* Get<PrimitiveType>ArrayElements *********************************************
4498 A family of functions that returns the body of the primitive array.
4500 *******************************************************************************/
4502 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4505 java_booleanarray *ba;
4507 STATISTICS(jniinvokation());
4509 ba = (java_booleanarray *) array;
4512 *isCopy = JNI_FALSE;
4518 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4523 STATISTICS(jniinvokation());
4525 ba = (java_bytearray *) array;
4528 *isCopy = JNI_FALSE;
4534 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4539 STATISTICS(jniinvokation());
4541 ca = (java_chararray *) array;
4544 *isCopy = JNI_FALSE;
4550 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4553 java_shortarray *sa;
4555 STATISTICS(jniinvokation());
4557 sa = (java_shortarray *) array;
4560 *isCopy = JNI_FALSE;
4566 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4571 STATISTICS(jniinvokation());
4573 ia = (java_intarray *) array;
4576 *isCopy = JNI_FALSE;
4582 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4587 STATISTICS(jniinvokation());
4589 la = (java_longarray *) array;
4592 *isCopy = JNI_FALSE;
4594 /* We cast this one to prevent a compiler warning on 64-bit
4595 systems since GNU Classpath typedef jlong to long long. */
4597 return (jlong *) la->data;
4601 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4604 java_floatarray *fa;
4606 STATISTICS(jniinvokation());
4608 fa = (java_floatarray *) array;
4611 *isCopy = JNI_FALSE;
4617 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4620 java_doublearray *da;
4622 STATISTICS(jniinvokation());
4624 da = (java_doublearray *) array;
4627 *isCopy = JNI_FALSE;
4633 /* Release<PrimitiveType>ArrayElements *****************************************
4635 A family of functions that informs the VM that the native code no
4636 longer needs access to elems. The elems argument is a pointer
4637 derived from array using the corresponding
4638 Get<PrimitiveType>ArrayElements() function. If necessary, this
4639 function copies back all changes made to elems to the original
4642 *******************************************************************************/
4644 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4645 jboolean *elems, jint mode)
4647 java_booleanarray *ba;
4649 STATISTICS(jniinvokation());
4651 ba = (java_booleanarray *) array;
4653 if (elems != ba->data) {
4656 MCOPY(ba->data, elems, u1, ba->header.size);
4659 MCOPY(ba->data, elems, u1, ba->header.size);
4660 /* XXX TWISTI how should it be freed? */
4663 /* XXX TWISTI how should it be freed? */
4670 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4671 jbyte *elems, jint mode)
4675 STATISTICS(jniinvokation());
4677 ba = (java_bytearray *) array;
4679 if (elems != ba->data) {
4682 MCOPY(ba->data, elems, s1, ba->header.size);
4685 MCOPY(ba->data, elems, s1, ba->header.size);
4686 /* XXX TWISTI how should it be freed? */
4689 /* XXX TWISTI how should it be freed? */
4696 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4697 jchar *elems, jint mode)
4701 STATISTICS(jniinvokation());
4703 ca = (java_chararray *) array;
4705 if (elems != ca->data) {
4708 MCOPY(ca->data, elems, u2, ca->header.size);
4711 MCOPY(ca->data, elems, u2, ca->header.size);
4712 /* XXX TWISTI how should it be freed? */
4715 /* XXX TWISTI how should it be freed? */
4722 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4723 jshort *elems, jint mode)
4725 java_shortarray *sa;
4727 STATISTICS(jniinvokation());
4729 sa = (java_shortarray *) array;
4731 if (elems != sa->data) {
4734 MCOPY(sa->data, elems, s2, sa->header.size);
4737 MCOPY(sa->data, elems, s2, sa->header.size);
4738 /* XXX TWISTI how should it be freed? */
4741 /* XXX TWISTI how should it be freed? */
4748 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4753 STATISTICS(jniinvokation());
4755 ia = (java_intarray *) array;
4757 if (elems != ia->data) {
4760 MCOPY(ia->data, elems, s4, ia->header.size);
4763 MCOPY(ia->data, elems, s4, ia->header.size);
4764 /* XXX TWISTI how should it be freed? */
4767 /* XXX TWISTI how should it be freed? */
4774 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4775 jlong *elems, jint mode)
4779 STATISTICS(jniinvokation());
4781 la = (java_longarray *) array;
4783 /* We cast this one to prevent a compiler warning on 64-bit
4784 systems since GNU Classpath typedef jlong to long long. */
4786 if ((s8 *) elems != la->data) {
4789 MCOPY(la->data, elems, s8, la->header.size);
4792 MCOPY(la->data, elems, s8, la->header.size);
4793 /* XXX TWISTI how should it be freed? */
4796 /* XXX TWISTI how should it be freed? */
4803 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4804 jfloat *elems, jint mode)
4806 java_floatarray *fa;
4808 STATISTICS(jniinvokation());
4810 fa = (java_floatarray *) array;
4812 if (elems != fa->data) {
4815 MCOPY(fa->data, elems, float, fa->header.size);
4818 MCOPY(fa->data, elems, float, fa->header.size);
4819 /* XXX TWISTI how should it be freed? */
4822 /* XXX TWISTI how should it be freed? */
4829 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4830 jdouble *elems, jint mode)
4832 java_doublearray *da;
4834 STATISTICS(jniinvokation());
4836 da = (java_doublearray *) array;
4838 if (elems != da->data) {
4841 MCOPY(da->data, elems, double, da->header.size);
4844 MCOPY(da->data, elems, double, da->header.size);
4845 /* XXX TWISTI how should it be freed? */
4848 /* XXX TWISTI how should it be freed? */
4855 /* Get<PrimitiveType>ArrayRegion **********************************************
4857 A family of functions that copies a region of a primitive array
4860 *******************************************************************************/
4862 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4863 jsize start, jsize len, jboolean *buf)
4865 java_booleanarray *ba;
4867 STATISTICS(jniinvokation());
4869 ba = (java_booleanarray *) array;
4871 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4872 exceptions_throw_arrayindexoutofboundsexception();
4874 MCOPY(buf, &ba->data[start], u1, len);
4878 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4879 jsize len, jbyte *buf)
4883 STATISTICS(jniinvokation());
4885 ba = (java_bytearray *) array;
4887 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4888 exceptions_throw_arrayindexoutofboundsexception();
4890 MCOPY(buf, &ba->data[start], s1, len);
4894 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4895 jsize len, jchar *buf)
4899 STATISTICS(jniinvokation());
4901 ca = (java_chararray *) array;
4903 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4904 exceptions_throw_arrayindexoutofboundsexception();
4906 MCOPY(buf, &ca->data[start], u2, len);
4910 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4911 jsize len, jshort *buf)
4913 java_shortarray *sa;
4915 STATISTICS(jniinvokation());
4917 sa = (java_shortarray *) array;
4919 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4920 exceptions_throw_arrayindexoutofboundsexception();
4922 MCOPY(buf, &sa->data[start], s2, len);
4926 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4927 jsize len, jint *buf)
4931 STATISTICS(jniinvokation());
4933 ia = (java_intarray *) array;
4935 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4936 exceptions_throw_arrayindexoutofboundsexception();
4938 MCOPY(buf, &ia->data[start], s4, len);
4942 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4943 jsize len, jlong *buf)
4947 STATISTICS(jniinvokation());
4949 la = (java_longarray *) array;
4951 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4952 exceptions_throw_arrayindexoutofboundsexception();
4954 MCOPY(buf, &la->data[start], s8, len);
4958 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4959 jsize len, jfloat *buf)
4961 java_floatarray *fa;
4963 STATISTICS(jniinvokation());
4965 fa = (java_floatarray *) array;
4967 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4968 exceptions_throw_arrayindexoutofboundsexception();
4970 MCOPY(buf, &fa->data[start], float, len);
4974 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4975 jsize len, jdouble *buf)
4977 java_doublearray *da;
4979 STATISTICS(jniinvokation());
4981 da = (java_doublearray *) array;
4983 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4984 exceptions_throw_arrayindexoutofboundsexception();
4986 MCOPY(buf, &da->data[start], double, len);
4990 /* Set<PrimitiveType>ArrayRegion **********************************************
4992 A family of functions that copies back a region of a primitive
4993 array from a buffer.
4995 *******************************************************************************/
4997 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4998 jsize start, jsize len, jboolean *buf)
5000 java_booleanarray *ba;
5002 STATISTICS(jniinvokation());
5004 ba = (java_booleanarray *) array;
5006 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5007 exceptions_throw_arrayindexoutofboundsexception();
5009 MCOPY(&ba->data[start], buf, u1, len);
5013 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5014 jsize len, jbyte *buf)
5018 STATISTICS(jniinvokation());
5020 ba = (java_bytearray *) array;
5022 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5023 exceptions_throw_arrayindexoutofboundsexception();
5025 MCOPY(&ba->data[start], buf, s1, len);
5029 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5030 jsize len, jchar *buf)
5034 STATISTICS(jniinvokation());
5036 ca = (java_chararray *) array;
5038 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5039 exceptions_throw_arrayindexoutofboundsexception();
5041 MCOPY(&ca->data[start], buf, u2, len);
5045 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5046 jsize len, jshort *buf)
5048 java_shortarray *sa;
5050 STATISTICS(jniinvokation());
5052 sa = (java_shortarray *) array;
5054 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5055 exceptions_throw_arrayindexoutofboundsexception();
5057 MCOPY(&sa->data[start], buf, s2, len);
5061 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5062 jsize len, jint *buf)
5066 STATISTICS(jniinvokation());
5068 ia = (java_intarray *) array;
5070 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5071 exceptions_throw_arrayindexoutofboundsexception();
5073 MCOPY(&ia->data[start], buf, s4, len);
5077 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5078 jsize len, jlong *buf)
5082 STATISTICS(jniinvokation());
5084 la = (java_longarray *) array;
5086 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5087 exceptions_throw_arrayindexoutofboundsexception();
5089 MCOPY(&la->data[start], buf, s8, len);
5093 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5094 jsize len, jfloat *buf)
5096 java_floatarray *fa;
5098 STATISTICS(jniinvokation());
5100 fa = (java_floatarray *) array;
5102 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5103 exceptions_throw_arrayindexoutofboundsexception();
5105 MCOPY(&fa->data[start], buf, float, len);
5109 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5110 jsize len, jdouble *buf)
5112 java_doublearray *da;
5114 STATISTICS(jniinvokation());
5116 da = (java_doublearray *) array;
5118 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5119 exceptions_throw_arrayindexoutofboundsexception();
5121 MCOPY(&da->data[start], buf, double, len);
5125 /* Registering Native Methods *************************************************/
5127 /* RegisterNatives *************************************************************
5129 Registers native methods with the class specified by the clazz
5130 argument. The methods parameter specifies an array of
5131 JNINativeMethod structures that contain the names, signatures, and
5132 function pointers of the native methods. The nMethods parameter
5133 specifies the number of native methods in the array.
5135 *******************************************************************************/
5137 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5138 const JNINativeMethod *methods, jint nMethods)
5140 STATISTICS(jniinvokation());
5142 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5143 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5144 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5151 /* UnregisterNatives ***********************************************************
5153 Unregisters native methods of a class. The class goes back to the
5154 state before it was linked or registered with its native method
5157 This function should not be used in normal native code. Instead, it
5158 provides special programs a way to reload and relink native
5161 *******************************************************************************/
5163 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5165 STATISTICS(jniinvokation());
5167 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5169 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5175 /* Monitor Operations *********************************************************/
5177 /* MonitorEnter ****************************************************************
5179 Enters the monitor associated with the underlying Java object
5182 *******************************************************************************/
5184 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5186 STATISTICS(jniinvokation());
5189 exceptions_throw_nullpointerexception();
5193 LOCK_MONITOR_ENTER(obj);
5199 /* MonitorExit *****************************************************************
5201 The current thread must be the owner of the monitor associated with
5202 the underlying Java object referred to by obj. The thread
5203 decrements the counter indicating the number of times it has
5204 entered this monitor. If the value of the counter becomes zero, the
5205 current thread releases the monitor.
5207 *******************************************************************************/
5209 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5211 STATISTICS(jniinvokation());
5214 exceptions_throw_nullpointerexception();
5218 LOCK_MONITOR_EXIT(obj);
5224 /* JavaVM Interface ***********************************************************/
5226 /* GetJavaVM *******************************************************************
5228 Returns the Java VM interface (used in the Invocation API)
5229 associated with the current thread. The result is placed at the
5230 location pointed to by the second argument, vm.
5232 *******************************************************************************/
5234 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5236 STATISTICS(jniinvokation());
5238 *vm = (JavaVM *) _Jv_jvm;
5244 /* GetStringRegion *************************************************************
5246 Copies len number of Unicode characters beginning at offset start
5247 to the given buffer buf.
5249 Throws StringIndexOutOfBoundsException on index overflow.
5251 *******************************************************************************/
5253 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5256 java_lang_String *s;
5259 STATISTICS(jniinvokation());
5261 s = (java_lang_String *) str;
5264 if ((start < 0) || (len < 0) || (start > s->count) ||
5265 (start + len > s->count)) {
5266 exceptions_throw_stringindexoutofboundsexception();
5270 MCOPY(buf, &ca->data[start], u2, len);
5274 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5275 jsize len, char *buf)
5277 STATISTICS(jniinvokation());
5279 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5283 /* GetPrimitiveArrayCritical ***************************************************
5285 Obtain a direct pointer to array elements.
5287 *******************************************************************************/
5289 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5295 ba = (java_bytearray *) array;
5297 /* do the same as Kaffe does */
5299 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5305 /* ReleasePrimitiveArrayCritical ***********************************************
5307 No specific documentation.
5309 *******************************************************************************/
5311 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5312 void *carray, jint mode)
5314 STATISTICS(jniinvokation());
5316 /* do the same as Kaffe does */
5318 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5323 /* GetStringCritical ***********************************************************
5325 The semantics of these two functions are similar to the existing
5326 Get/ReleaseStringChars functions.
5328 *******************************************************************************/
5330 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5333 STATISTICS(jniinvokation());
5335 return _Jv_JNI_GetStringChars(env, string, isCopy);
5339 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5340 const jchar *cstring)
5342 STATISTICS(jniinvokation());
5344 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5348 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5350 STATISTICS(jniinvokation());
5352 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5358 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5360 STATISTICS(jniinvokation());
5362 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5366 /* NewGlobalRef ****************************************************************
5368 Creates a new global reference to the object referred to by the obj
5371 *******************************************************************************/
5373 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5375 hashtable_global_ref_entry *gre;
5376 u4 key; /* hashkey */
5377 u4 slot; /* slot in hashtable */
5379 STATISTICS(jniinvokation());
5381 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5383 /* normally addresses are aligned to 4, 8 or 16 bytes */
5385 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5386 slot = key & (hashtable_global_ref->size - 1);
5387 gre = hashtable_global_ref->ptr[slot];
5389 /* search external hash chain for the entry */
5392 if (gre->o == obj) {
5393 /* global object found, increment the reference */
5397 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5402 gre = gre->hashlink; /* next element in external chain */
5405 /* global ref not found, create a new one */
5407 gre = NEW(hashtable_global_ref_entry);
5412 /* insert entry into hashtable */
5414 gre->hashlink = hashtable_global_ref->ptr[slot];
5416 hashtable_global_ref->ptr[slot] = gre;
5418 /* update number of hashtable-entries */
5420 hashtable_global_ref->entries++;
5422 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5428 /* DeleteGlobalRef *************************************************************
5430 Deletes the global reference pointed to by globalRef.
5432 *******************************************************************************/
5434 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5436 hashtable_global_ref_entry *gre;
5437 hashtable_global_ref_entry *prevgre;
5438 u4 key; /* hashkey */
5439 u4 slot; /* slot in hashtable */
5441 STATISTICS(jniinvokation());
5443 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5445 /* normally addresses are aligned to 4, 8 or 16 bytes */
5447 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5448 slot = key & (hashtable_global_ref->size - 1);
5449 gre = hashtable_global_ref->ptr[slot];
5451 /* initialize prevgre */
5455 /* search external hash chain for the entry */
5458 if (gre->o == globalRef) {
5459 /* global object found, decrement the reference count */
5463 /* if reference count is 0, remove the entry */
5465 if (gre->refs == 0) {
5466 /* special handling if it's the first in the chain */
5468 if (prevgre == NULL)
5469 hashtable_global_ref->ptr[slot] = gre->hashlink;
5471 prevgre->hashlink = gre->hashlink;
5473 FREE(gre, hashtable_global_ref_entry);
5476 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5481 prevgre = gre; /* save current pointer for removal */
5482 gre = gre->hashlink; /* next element in external chain */
5485 log_println("JNI-DeleteGlobalRef: global reference not found");
5487 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5491 /* ExceptionCheck **************************************************************
5493 Returns JNI_TRUE when there is a pending exception; otherwise,
5496 *******************************************************************************/
5498 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5500 java_objectheader *o;
5502 STATISTICS(jniinvokation());
5504 o = exceptions_get_exception();
5506 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5510 /* New JNI 1.4 functions ******************************************************/
5512 /* NewDirectByteBuffer *********************************************************
5514 Allocates and returns a direct java.nio.ByteBuffer referring to the
5515 block of memory starting at the memory address address and
5516 extending capacity bytes.
5518 *******************************************************************************/
5520 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5522 #if defined(ENABLE_JAVASE)
5523 java_objectheader *nbuf;
5524 # if SIZEOF_VOID_P == 8
5525 gnu_classpath_Pointer64 *paddress;
5527 gnu_classpath_Pointer32 *paddress;
5530 STATISTICS(jniinvokation());
5532 /* alocate a gnu.classpath.Pointer{32,64} object */
5534 # if SIZEOF_VOID_P == 8
5535 if (!(paddress = (gnu_classpath_Pointer64 *)
5536 builtin_new(class_gnu_classpath_Pointer64)))
5538 if (!(paddress = (gnu_classpath_Pointer32 *)
5539 builtin_new(class_gnu_classpath_Pointer32)))
5543 /* fill gnu.classpath.Pointer{32,64} with address */
5545 paddress->data = (ptrint) address;
5547 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5549 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5550 (jmethodID) dbbirw_init, NULL, paddress,
5551 (jint) capacity, (jint) capacity, (jint) 0);
5553 /* add local reference and return the value */
5555 return _Jv_JNI_NewLocalRef(env, nbuf);
5557 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5559 /* keep compiler happy */
5566 /* GetDirectBufferAddress ******************************************************
5568 Fetches and returns the starting address of the memory region
5569 referenced by the given direct java.nio.Buffer.
5571 *******************************************************************************/
5573 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5575 #if defined(ENABLE_JAVASE)
5576 java_nio_DirectByteBufferImpl *nbuf;
5577 # if SIZEOF_VOID_P == 8
5578 gnu_classpath_Pointer64 *address;
5580 gnu_classpath_Pointer32 *address;
5583 STATISTICS(jniinvokation());
5585 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5588 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5590 # if SIZEOF_VOID_P == 8
5591 address = (gnu_classpath_Pointer64 *) nbuf->address;
5593 address = (gnu_classpath_Pointer32 *) nbuf->address;
5596 if (address == NULL)
5599 return (void *) address->data;
5601 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5603 /* keep compiler happy */
5610 /* GetDirectBufferCapacity *****************************************************
5612 Fetches and returns the capacity in bytes of the memory region
5613 referenced by the given direct java.nio.Buffer.
5615 *******************************************************************************/
5617 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5619 #if defined(ENABLE_JAVASE)
5620 java_nio_Buffer *nbuf;
5622 STATISTICS(jniinvokation());
5624 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5627 nbuf = (java_nio_Buffer *) buf;
5629 return (jlong) nbuf->cap;
5631 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5633 /* keep compiler happy */
5640 /* DestroyJavaVM ***************************************************************
5642 Unloads a Java VM and reclaims its resources. Only the main thread
5643 can unload the VM. The system waits until the main thread is only
5644 remaining user thread before it destroys the VM.
5646 *******************************************************************************/
5648 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5652 STATISTICS(jniinvokation());
5654 status = vm_destroy(vm);
5660 /* AttachCurrentThread *********************************************************
5662 Attaches the current thread to a Java VM. Returns a JNI interface
5663 pointer in the JNIEnv argument.
5665 Trying to attach a thread that is already attached is a no-op.
5667 A native thread cannot be attached simultaneously to two Java VMs.
5669 When a thread is attached to the VM, the context class loader is
5670 the bootstrap loader.
5672 *******************************************************************************/
5674 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5676 JavaVMAttachArgs *vm_aargs;
5678 #if defined(ENABLE_THREADS)
5679 if (threads_get_current_threadobject() == NULL) {
5680 vm_aargs = (JavaVMAttachArgs *) thr_args;
5682 if (vm_aargs != NULL) {
5683 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5684 (vm_aargs->version != JNI_VERSION_1_4))
5685 return JNI_EVERSION;
5688 if (!threads_attach_current_thread(vm_aargs, false))
5691 if (!jni_init_localref_table())
5702 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5704 STATISTICS(jniinvokation());
5706 return jni_attach_current_thread(p_env, thr_args, false);
5710 /* DetachCurrentThread *********************************************************
5712 Detaches the current thread from a Java VM. All Java monitors held
5713 by this thread are released. All Java threads waiting for this
5714 thread to die are notified.
5716 In JDK 1.1, the main thread cannot be detached from the VM. It must
5717 call DestroyJavaVM to unload the entire VM.
5719 In the JDK, the main thread can be detached from the VM.
5721 The main thread, which is the thread that created the Java VM,
5722 cannot be detached from the VM. Instead, the main thread must call
5723 JNI_DestroyJavaVM() to unload the entire VM.
5725 *******************************************************************************/
5727 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5729 #if defined(ENABLE_THREADS)
5730 threadobject *thread;
5732 STATISTICS(jniinvokation());
5734 thread = threads_get_current_threadobject();
5739 if (!jni_free_localref_table())
5742 if (!threads_detach_thread(thread))
5750 /* GetEnv **********************************************************************
5752 If the current thread is not attached to the VM, sets *env to NULL,
5753 and returns JNI_EDETACHED. If the specified version is not
5754 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5755 sets *env to the appropriate interface, and returns JNI_OK.
5757 *******************************************************************************/
5759 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5761 STATISTICS(jniinvokation());
5763 #if defined(ENABLE_THREADS)
5764 if (threads_get_current_threadobject() == NULL) {
5767 return JNI_EDETACHED;
5771 /* check the JNI version */
5774 case JNI_VERSION_1_1:
5775 case JNI_VERSION_1_2:
5776 case JNI_VERSION_1_4:
5784 #if defined(ENABLE_JVMTI)
5785 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5786 == JVMTI_VERSION_INTERFACE_JVMTI) {
5788 *env = (void *) jvmti_new_environment();
5797 return JNI_EVERSION;
5801 /* AttachCurrentThreadAsDaemon *************************************************
5803 Same semantics as AttachCurrentThread, but the newly-created
5804 java.lang.Thread instance is a daemon.
5806 If the thread has already been attached via either
5807 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5808 simply sets the value pointed to by penv to the JNIEnv of the
5809 current thread. In this case neither AttachCurrentThread nor this
5810 routine have any effect on the daemon status of the thread.
5812 *******************************************************************************/
5814 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5816 STATISTICS(jniinvokation());
5818 return jni_attach_current_thread(penv, args, true);
5822 /* JNI invocation table *******************************************************/
5824 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5829 _Jv_JNI_DestroyJavaVM,
5830 _Jv_JNI_AttachCurrentThread,
5831 _Jv_JNI_DetachCurrentThread,
5833 _Jv_JNI_AttachCurrentThreadAsDaemon
5837 /* JNI function table *********************************************************/
5839 struct JNINativeInterface _Jv_JNINativeInterface = {
5846 _Jv_JNI_DefineClass,
5848 _Jv_JNI_FromReflectedMethod,
5849 _Jv_JNI_FromReflectedField,
5850 _Jv_JNI_ToReflectedMethod,
5851 _Jv_JNI_GetSuperclass,
5852 _Jv_JNI_IsAssignableFrom,
5853 _Jv_JNI_ToReflectedField,
5857 _Jv_JNI_ExceptionOccurred,
5858 _Jv_JNI_ExceptionDescribe,
5859 _Jv_JNI_ExceptionClear,
5861 _Jv_JNI_PushLocalFrame,
5862 _Jv_JNI_PopLocalFrame,
5864 _Jv_JNI_NewGlobalRef,
5865 _Jv_JNI_DeleteGlobalRef,
5866 _Jv_JNI_DeleteLocalRef,
5867 _Jv_JNI_IsSameObject,
5868 _Jv_JNI_NewLocalRef,
5869 _Jv_JNI_EnsureLocalCapacity,
5871 _Jv_JNI_AllocObject,
5876 _Jv_JNI_GetObjectClass,
5877 _Jv_JNI_IsInstanceOf,
5879 _Jv_JNI_GetMethodID,
5881 _Jv_JNI_CallObjectMethod,
5882 _Jv_JNI_CallObjectMethodV,
5883 _Jv_JNI_CallObjectMethodA,
5884 _Jv_JNI_CallBooleanMethod,
5885 _Jv_JNI_CallBooleanMethodV,
5886 _Jv_JNI_CallBooleanMethodA,
5887 _Jv_JNI_CallByteMethod,
5888 _Jv_JNI_CallByteMethodV,
5889 _Jv_JNI_CallByteMethodA,
5890 _Jv_JNI_CallCharMethod,
5891 _Jv_JNI_CallCharMethodV,
5892 _Jv_JNI_CallCharMethodA,
5893 _Jv_JNI_CallShortMethod,
5894 _Jv_JNI_CallShortMethodV,
5895 _Jv_JNI_CallShortMethodA,
5896 _Jv_JNI_CallIntMethod,
5897 _Jv_JNI_CallIntMethodV,
5898 _Jv_JNI_CallIntMethodA,
5899 _Jv_JNI_CallLongMethod,
5900 _Jv_JNI_CallLongMethodV,
5901 _Jv_JNI_CallLongMethodA,
5902 _Jv_JNI_CallFloatMethod,
5903 _Jv_JNI_CallFloatMethodV,
5904 _Jv_JNI_CallFloatMethodA,
5905 _Jv_JNI_CallDoubleMethod,
5906 _Jv_JNI_CallDoubleMethodV,
5907 _Jv_JNI_CallDoubleMethodA,
5908 _Jv_JNI_CallVoidMethod,
5909 _Jv_JNI_CallVoidMethodV,
5910 _Jv_JNI_CallVoidMethodA,
5912 _Jv_JNI_CallNonvirtualObjectMethod,
5913 _Jv_JNI_CallNonvirtualObjectMethodV,
5914 _Jv_JNI_CallNonvirtualObjectMethodA,
5915 _Jv_JNI_CallNonvirtualBooleanMethod,
5916 _Jv_JNI_CallNonvirtualBooleanMethodV,
5917 _Jv_JNI_CallNonvirtualBooleanMethodA,
5918 _Jv_JNI_CallNonvirtualByteMethod,
5919 _Jv_JNI_CallNonvirtualByteMethodV,
5920 _Jv_JNI_CallNonvirtualByteMethodA,
5921 _Jv_JNI_CallNonvirtualCharMethod,
5922 _Jv_JNI_CallNonvirtualCharMethodV,
5923 _Jv_JNI_CallNonvirtualCharMethodA,
5924 _Jv_JNI_CallNonvirtualShortMethod,
5925 _Jv_JNI_CallNonvirtualShortMethodV,
5926 _Jv_JNI_CallNonvirtualShortMethodA,
5927 _Jv_JNI_CallNonvirtualIntMethod,
5928 _Jv_JNI_CallNonvirtualIntMethodV,
5929 _Jv_JNI_CallNonvirtualIntMethodA,
5930 _Jv_JNI_CallNonvirtualLongMethod,
5931 _Jv_JNI_CallNonvirtualLongMethodV,
5932 _Jv_JNI_CallNonvirtualLongMethodA,
5933 _Jv_JNI_CallNonvirtualFloatMethod,
5934 _Jv_JNI_CallNonvirtualFloatMethodV,
5935 _Jv_JNI_CallNonvirtualFloatMethodA,
5936 _Jv_JNI_CallNonvirtualDoubleMethod,
5937 _Jv_JNI_CallNonvirtualDoubleMethodV,
5938 _Jv_JNI_CallNonvirtualDoubleMethodA,
5939 _Jv_JNI_CallNonvirtualVoidMethod,
5940 _Jv_JNI_CallNonvirtualVoidMethodV,
5941 _Jv_JNI_CallNonvirtualVoidMethodA,
5945 _Jv_JNI_GetObjectField,
5946 _Jv_JNI_GetBooleanField,
5947 _Jv_JNI_GetByteField,
5948 _Jv_JNI_GetCharField,
5949 _Jv_JNI_GetShortField,
5950 _Jv_JNI_GetIntField,
5951 _Jv_JNI_GetLongField,
5952 _Jv_JNI_GetFloatField,
5953 _Jv_JNI_GetDoubleField,
5954 _Jv_JNI_SetObjectField,
5955 _Jv_JNI_SetBooleanField,
5956 _Jv_JNI_SetByteField,
5957 _Jv_JNI_SetCharField,
5958 _Jv_JNI_SetShortField,
5959 _Jv_JNI_SetIntField,
5960 _Jv_JNI_SetLongField,
5961 _Jv_JNI_SetFloatField,
5962 _Jv_JNI_SetDoubleField,
5964 _Jv_JNI_GetStaticMethodID,
5966 _Jv_JNI_CallStaticObjectMethod,
5967 _Jv_JNI_CallStaticObjectMethodV,
5968 _Jv_JNI_CallStaticObjectMethodA,
5969 _Jv_JNI_CallStaticBooleanMethod,
5970 _Jv_JNI_CallStaticBooleanMethodV,
5971 _Jv_JNI_CallStaticBooleanMethodA,
5972 _Jv_JNI_CallStaticByteMethod,
5973 _Jv_JNI_CallStaticByteMethodV,
5974 _Jv_JNI_CallStaticByteMethodA,
5975 _Jv_JNI_CallStaticCharMethod,
5976 _Jv_JNI_CallStaticCharMethodV,
5977 _Jv_JNI_CallStaticCharMethodA,
5978 _Jv_JNI_CallStaticShortMethod,
5979 _Jv_JNI_CallStaticShortMethodV,
5980 _Jv_JNI_CallStaticShortMethodA,
5981 _Jv_JNI_CallStaticIntMethod,
5982 _Jv_JNI_CallStaticIntMethodV,
5983 _Jv_JNI_CallStaticIntMethodA,
5984 _Jv_JNI_CallStaticLongMethod,
5985 _Jv_JNI_CallStaticLongMethodV,
5986 _Jv_JNI_CallStaticLongMethodA,
5987 _Jv_JNI_CallStaticFloatMethod,
5988 _Jv_JNI_CallStaticFloatMethodV,
5989 _Jv_JNI_CallStaticFloatMethodA,
5990 _Jv_JNI_CallStaticDoubleMethod,
5991 _Jv_JNI_CallStaticDoubleMethodV,
5992 _Jv_JNI_CallStaticDoubleMethodA,
5993 _Jv_JNI_CallStaticVoidMethod,
5994 _Jv_JNI_CallStaticVoidMethodV,
5995 _Jv_JNI_CallStaticVoidMethodA,
5997 _Jv_JNI_GetStaticFieldID,
5999 _Jv_JNI_GetStaticObjectField,
6000 _Jv_JNI_GetStaticBooleanField,
6001 _Jv_JNI_GetStaticByteField,
6002 _Jv_JNI_GetStaticCharField,
6003 _Jv_JNI_GetStaticShortField,
6004 _Jv_JNI_GetStaticIntField,
6005 _Jv_JNI_GetStaticLongField,
6006 _Jv_JNI_GetStaticFloatField,
6007 _Jv_JNI_GetStaticDoubleField,
6008 _Jv_JNI_SetStaticObjectField,
6009 _Jv_JNI_SetStaticBooleanField,
6010 _Jv_JNI_SetStaticByteField,
6011 _Jv_JNI_SetStaticCharField,
6012 _Jv_JNI_SetStaticShortField,
6013 _Jv_JNI_SetStaticIntField,
6014 _Jv_JNI_SetStaticLongField,
6015 _Jv_JNI_SetStaticFloatField,
6016 _Jv_JNI_SetStaticDoubleField,
6019 _Jv_JNI_GetStringLength,
6020 _Jv_JNI_GetStringChars,
6021 _Jv_JNI_ReleaseStringChars,
6023 _Jv_JNI_NewStringUTF,
6024 _Jv_JNI_GetStringUTFLength,
6025 _Jv_JNI_GetStringUTFChars,
6026 _Jv_JNI_ReleaseStringUTFChars,
6028 _Jv_JNI_GetArrayLength,
6030 _Jv_JNI_NewObjectArray,
6031 _Jv_JNI_GetObjectArrayElement,
6032 _Jv_JNI_SetObjectArrayElement,
6034 _Jv_JNI_NewBooleanArray,
6035 _Jv_JNI_NewByteArray,
6036 _Jv_JNI_NewCharArray,
6037 _Jv_JNI_NewShortArray,
6038 _Jv_JNI_NewIntArray,
6039 _Jv_JNI_NewLongArray,
6040 _Jv_JNI_NewFloatArray,
6041 _Jv_JNI_NewDoubleArray,
6043 _Jv_JNI_GetBooleanArrayElements,
6044 _Jv_JNI_GetByteArrayElements,
6045 _Jv_JNI_GetCharArrayElements,
6046 _Jv_JNI_GetShortArrayElements,
6047 _Jv_JNI_GetIntArrayElements,
6048 _Jv_JNI_GetLongArrayElements,
6049 _Jv_JNI_GetFloatArrayElements,
6050 _Jv_JNI_GetDoubleArrayElements,
6052 _Jv_JNI_ReleaseBooleanArrayElements,
6053 _Jv_JNI_ReleaseByteArrayElements,
6054 _Jv_JNI_ReleaseCharArrayElements,
6055 _Jv_JNI_ReleaseShortArrayElements,
6056 _Jv_JNI_ReleaseIntArrayElements,
6057 _Jv_JNI_ReleaseLongArrayElements,
6058 _Jv_JNI_ReleaseFloatArrayElements,
6059 _Jv_JNI_ReleaseDoubleArrayElements,
6061 _Jv_JNI_GetBooleanArrayRegion,
6062 _Jv_JNI_GetByteArrayRegion,
6063 _Jv_JNI_GetCharArrayRegion,
6064 _Jv_JNI_GetShortArrayRegion,
6065 _Jv_JNI_GetIntArrayRegion,
6066 _Jv_JNI_GetLongArrayRegion,
6067 _Jv_JNI_GetFloatArrayRegion,
6068 _Jv_JNI_GetDoubleArrayRegion,
6069 _Jv_JNI_SetBooleanArrayRegion,
6070 _Jv_JNI_SetByteArrayRegion,
6071 _Jv_JNI_SetCharArrayRegion,
6072 _Jv_JNI_SetShortArrayRegion,
6073 _Jv_JNI_SetIntArrayRegion,
6074 _Jv_JNI_SetLongArrayRegion,
6075 _Jv_JNI_SetFloatArrayRegion,
6076 _Jv_JNI_SetDoubleArrayRegion,
6078 _Jv_JNI_RegisterNatives,
6079 _Jv_JNI_UnregisterNatives,
6081 _Jv_JNI_MonitorEnter,
6082 _Jv_JNI_MonitorExit,
6086 /* new JNI 1.2 functions */
6088 _Jv_JNI_GetStringRegion,
6089 _Jv_JNI_GetStringUTFRegion,
6091 _Jv_JNI_GetPrimitiveArrayCritical,
6092 _Jv_JNI_ReleasePrimitiveArrayCritical,
6094 _Jv_JNI_GetStringCritical,
6095 _Jv_JNI_ReleaseStringCritical,
6097 _Jv_JNI_NewWeakGlobalRef,
6098 _Jv_JNI_DeleteWeakGlobalRef,
6100 _Jv_JNI_ExceptionCheck,
6102 /* new JNI 1.4 functions */
6104 _Jv_JNI_NewDirectByteBuffer,
6105 _Jv_JNI_GetDirectBufferAddress,
6106 _Jv_JNI_GetDirectBufferCapacity
6110 /* Invocation API Functions ***************************************************/
6112 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6114 Returns a default configuration for the Java VM.
6116 *******************************************************************************/
6118 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6120 JavaVMInitArgs *_vm_args;
6122 _vm_args = (JavaVMInitArgs *) vm_args;
6124 /* GNU classpath currently supports JNI 1.2 */
6126 switch (_vm_args->version) {
6127 case JNI_VERSION_1_1:
6128 _vm_args->version = JNI_VERSION_1_1;
6131 case JNI_VERSION_1_2:
6132 case JNI_VERSION_1_4:
6133 _vm_args->ignoreUnrecognized = JNI_FALSE;
6134 _vm_args->options = NULL;
6135 _vm_args->nOptions = 0;
6146 /* JNI_GetCreatedJavaVMs *******************************************************
6148 Returns all Java VMs that have been created. Pointers to VMs are written in
6149 the buffer vmBuf in the order they are created. At most bufLen number of
6150 entries will be written. The total number of created VMs is returned in
6153 *******************************************************************************/
6155 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6157 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6163 /* JNI_CreateJavaVM ************************************************************
6165 Loads and initializes a Java VM. The current thread becomes the main thread.
6166 Sets the env argument to the JNI interface pointer of the main thread.
6168 *******************************************************************************/
6170 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6172 /* actually create the JVM */
6174 if (!vm_createjvm(p_vm, p_env, vm_args))
6182 * These are local overrides for various environment variables in Emacs.
6183 * Please do not remove this and leave it at the end of the file, where
6184 * Emacs will automagically detect them.
6185 * ---------------------------------------------------------------------
6188 * indent-tabs-mode: t
6192 * vim:noexpandtab:sw=4:ts=4: