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 8058 2007-06-10 19:30:25Z twisti $
37 #include "mm/gc-common.h"
38 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/native.h"
42 #if defined(ENABLE_JAVASE)
43 # if defined(WITH_CLASSPATH_GNU)
44 # include "native/include/gnu_classpath_Pointer.h"
46 # if SIZEOF_VOID_P == 8
47 # include "native/include/gnu_classpath_Pointer64.h"
49 # include "native/include/gnu_classpath_Pointer32.h"
54 #include "native/include/java_lang_Object.h"
55 #include "native/include/java_lang_Byte.h"
56 #include "native/include/java_lang_Character.h"
57 #include "native/include/java_lang_Short.h"
58 #include "native/include/java_lang_Integer.h"
59 #include "native/include/java_lang_Boolean.h"
60 #include "native/include/java_lang_Long.h"
61 #include "native/include/java_lang_Float.h"
62 #include "native/include/java_lang_Double.h"
63 #include "native/include/java_lang_String.h"
64 #include "native/include/java_lang_Throwable.h"
66 #if defined(ENABLE_JAVASE)
67 # include "native/include/java_lang_ClassLoader.h"
69 # include "native/include/java_lang_reflect_Constructor.h"
70 # include "native/include/java_lang_reflect_Field.h"
71 # include "native/include/java_lang_reflect_Method.h"
73 # include "native/include/java_nio_Buffer.h"
74 # include "native/include/java_nio_DirectByteBufferImpl.h"
77 #if defined(ENABLE_JVMTI)
78 # include "native/jvmti/cacaodbg.h"
81 #include "native/vm/java_lang_Class.h"
83 #if defined(ENABLE_JAVASE)
84 # include "native/vm/java_lang_ClassLoader.h"
87 #include "threads/lock-common.h"
88 #include "threads/threads-common.h"
90 #include "toolbox/logging.h"
92 #include "vm/builtin.h"
93 #include "vm/exceptions.h"
94 #include "vm/global.h"
95 #include "vm/initialize.h"
96 #include "vm/stringlocal.h"
99 #include "vm/jit/asmpart.h"
100 #include "vm/jit/jit.h"
101 #include "vm/jit/stacktrace.h"
103 #include "vmcore/loader.h"
104 #include "vmcore/options.h"
105 #include "vm/resolve.h"
106 #include "vmcore/statistics.h"
109 /* global variables ***********************************************************/
111 /* global reference table *****************************************************/
113 /* hashsize must be power of 2 */
115 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
117 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
120 /* direct buffer stuff ********************************************************/
122 #if defined(ENABLE_JAVASE)
123 static classinfo *class_java_nio_Buffer;
124 static classinfo *class_java_nio_DirectByteBufferImpl;
125 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
127 # if defined(WITH_CLASSPATH_GNU)
128 # if SIZEOF_VOID_P == 8
129 static classinfo *class_gnu_classpath_Pointer64;
131 static classinfo *class_gnu_classpath_Pointer32;
135 static methodinfo *dbbirw_init;
139 /* local reference table ******************************************************/
141 #if !defined(ENABLE_THREADS)
142 localref_table *_no_threads_localref_table;
146 /* accessing instance fields macros *******************************************/
148 #define SET_FIELD(o,type,f,value) \
149 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
151 #define GET_FIELD(o,type,f) \
152 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
155 /* some forward declarations **************************************************/
157 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
158 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
161 /* jni_init ********************************************************************
163 Initialize the JNI subsystem.
165 *******************************************************************************/
169 /* create global ref hashtable */
171 hashtable_global_ref = NEW(hashtable);
173 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
176 #if defined(ENABLE_JAVASE)
177 /* direct buffer stuff */
179 if (!(class_java_nio_Buffer =
180 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
181 !link_class(class_java_nio_Buffer))
184 if (!(class_java_nio_DirectByteBufferImpl =
185 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
186 !link_class(class_java_nio_DirectByteBufferImpl))
189 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
190 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
191 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
195 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
197 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
200 # if defined(WITH_CLASSPATH_GNU)
201 # if SIZEOF_VOID_P == 8
202 if (!(class_gnu_classpath_Pointer64 =
203 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
204 !link_class(class_gnu_classpath_Pointer64))
207 if (!(class_gnu_classpath_Pointer32 =
208 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
209 !link_class(class_gnu_classpath_Pointer32))
213 #endif /* defined(ENABLE_JAVASE) */
219 /* jni_init_localref_table *****************************************************
221 Initializes the local references table of the current thread.
223 *******************************************************************************/
225 bool jni_init_localref_table(void)
229 lrt = GCNEW(localref_table);
234 lrt->capacity = LOCALREFTABLE_CAPACITY;
236 lrt->localframes = 1;
237 lrt->prev = LOCALREFTABLE;
239 /* clear the references array (memset is faster then a for-loop) */
241 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
249 /* _Jv_jni_vmargs_from_objectarray *********************************************
253 *******************************************************************************/
255 static bool _Jv_jni_vmargs_from_objectarray(java_objectheader *o,
258 java_objectarray *params)
260 java_objectheader *param;
262 typedesc *paramtypes;
268 paramcount = descr->paramcount;
269 paramtypes = descr->paramtypes;
271 /* if method is non-static fill first block and skip `this' pointer */
277 vmargs[0].type = TYPE_ADR;
278 vmargs[0].data.l = (u8) (ptrint) o;
285 for (j = 0; j < paramcount; i++, j++, paramtypes++) {
286 switch (paramtypes->type) {
287 /* primitive types */
292 param = params->data[j];
297 /* internally used data type */
298 vmargs[i].type = paramtypes->type;
300 /* convert the value according to its declared type */
302 c = param->vftbl->class;
304 switch (paramtypes->decltype) {
305 case PRIMITIVETYPE_BOOLEAN:
306 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
307 value = (s8) ((java_lang_Boolean *) param)->value;
311 vmargs[i].data.l = value;
314 case PRIMITIVETYPE_BYTE:
315 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
316 value = (s8) ((java_lang_Byte *) param)->value;
320 vmargs[i].data.l = value;
323 case PRIMITIVETYPE_CHAR:
324 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
325 value = (s8) ((java_lang_Character *) param)->value;
329 vmargs[i].data.l = value;
332 case PRIMITIVETYPE_SHORT:
333 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
334 value = (s8) ((java_lang_Short *) param)->value;
335 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
336 value = (s8) ((java_lang_Byte *) param)->value;
340 vmargs[i].data.l = value;
343 case PRIMITIVETYPE_INT:
344 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
345 value = (s8) ((java_lang_Integer *) param)->value;
346 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
347 value = (s8) ((java_lang_Short *) param)->value;
348 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
349 value = (s8) ((java_lang_Byte *) param)->value;
353 vmargs[i].data.l = value;
356 case PRIMITIVETYPE_LONG:
357 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
358 value = (s8) ((java_lang_Long *) param)->value;
359 else if (c == primitivetype_table[PRIMITIVETYPE_INT].class_wrap)
360 value = (s8) ((java_lang_Integer *) param)->value;
361 else if (c == primitivetype_table[PRIMITIVETYPE_SHORT].class_wrap)
362 value = (s8) ((java_lang_Short *) param)->value;
363 else if (c == primitivetype_table[PRIMITIVETYPE_BYTE].class_wrap)
364 value = (s8) ((java_lang_Byte *) param)->value;
368 vmargs[i].data.l = value;
371 case PRIMITIVETYPE_FLOAT:
372 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
373 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
378 case PRIMITIVETYPE_DOUBLE:
379 if (c == primitivetype_table[paramtypes->decltype].class_wrap)
380 vmargs[i].data.d = (jdouble) ((java_lang_Double *) param)->value;
381 else if (c == primitivetype_table[PRIMITIVETYPE_FLOAT].class_wrap)
382 vmargs[i].data.f = (jfloat) ((java_lang_Float *) param)->value;
393 if (!resolve_class_from_typedesc(paramtypes, true, true, &c))
396 if (params->data[j] != 0) {
397 if (paramtypes->arraydim > 0) {
398 if (!builtin_arrayinstanceof(params->data[j], c))
402 if (!builtin_instanceof(params->data[j], c))
407 vmargs[i].type = TYPE_ADR;
408 vmargs[i].data.l = (u8) (ptrint) params->data[j];
417 /* *rettype = descr->returntype.decltype; */
422 exceptions_throw_illegalargumentexception();
427 /* _Jv_jni_CallObjectMethod ****************************************************
429 Internal function to call Java Object methods.
431 *******************************************************************************/
433 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
435 methodinfo *m, va_list ap)
438 java_objectheader *ro;
440 STATISTICS(jniinvokation());
443 exceptions_throw_nullpointerexception();
447 /* Class initialization is done by the JIT compiler. This is ok
448 since a static method always belongs to the declaring class. */
450 if (m->flags & ACC_STATIC) {
451 /* For static methods we reset the object. */
456 /* for convenience */
461 /* For instance methods we make a virtual function table lookup. */
463 resm = method_vftbl_lookup(vftbl, m);
466 STATISTICS(jnicallXmethodnvokation());
468 ro = vm_call_method_valist(resm, o, ap);
474 /* _Jv_jni_CallObjectMethodA ***************************************************
476 Internal function to call Java Object methods.
478 *******************************************************************************/
480 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
482 methodinfo *m, jvalue *args)
485 java_objectheader *ro;
487 STATISTICS(jniinvokation());
490 exceptions_throw_nullpointerexception();
494 /* Class initialization is done by the JIT compiler. This is ok
495 since a static method always belongs to the declaring class. */
497 if (m->flags & ACC_STATIC) {
498 /* For static methods we reset the object. */
503 /* for convenience */
508 /* For instance methods we make a virtual function table lookup. */
510 resm = method_vftbl_lookup(vftbl, m);
513 STATISTICS(jnicallXmethodnvokation());
515 ro = vm_call_method_jvalue(resm, o, args);
521 /* _Jv_jni_CallIntMethod *******************************************************
523 Internal function to call Java integer class methods (boolean,
524 byte, char, short, int).
526 *******************************************************************************/
528 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
529 methodinfo *m, va_list ap)
534 STATISTICS(jniinvokation());
537 exceptions_throw_nullpointerexception();
541 /* Class initialization is done by the JIT compiler. This is ok
542 since a static method always belongs to the declaring class. */
544 if (m->flags & ACC_STATIC) {
545 /* For static methods we reset the object. */
550 /* for convenience */
555 /* For instance methods we make a virtual function table lookup. */
557 resm = method_vftbl_lookup(vftbl, m);
560 STATISTICS(jnicallXmethodnvokation());
562 i = vm_call_method_int_valist(resm, o, ap);
568 /* _Jv_jni_CallIntMethodA ******************************************************
570 Internal function to call Java integer class methods (boolean,
571 byte, char, short, int).
573 *******************************************************************************/
575 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
576 methodinfo *m, jvalue *args)
581 STATISTICS(jniinvokation());
584 exceptions_throw_nullpointerexception();
588 /* Class initialization is done by the JIT compiler. This is ok
589 since a static method always belongs to the declaring class. */
591 if (m->flags & ACC_STATIC) {
592 /* For static methods we reset the object. */
597 /* for convenience */
602 /* For instance methods we make a virtual function table lookup. */
604 resm = method_vftbl_lookup(vftbl, m);
607 STATISTICS(jnicallXmethodnvokation());
609 i = vm_call_method_int_jvalue(resm, o, args);
615 /* _Jv_jni_CallLongMethod ******************************************************
617 Internal function to call Java long methods.
619 *******************************************************************************/
621 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
622 methodinfo *m, va_list ap)
627 STATISTICS(jniinvokation());
630 exceptions_throw_nullpointerexception();
634 /* Class initialization is done by the JIT compiler. This is ok
635 since a static method always belongs to the declaring class. */
637 if (m->flags & ACC_STATIC) {
638 /* For static methods we reset the object. */
643 /* for convenience */
648 /* For instance methods we make a virtual function table lookup. */
650 resm = method_vftbl_lookup(vftbl, m);
653 STATISTICS(jnicallXmethodnvokation());
655 l = vm_call_method_long_valist(resm, o, ap);
661 /* _Jv_jni_CallLongMethodA *****************************************************
663 Internal function to call Java long methods.
665 *******************************************************************************/
667 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
668 methodinfo *m, jvalue *args)
673 STATISTICS(jniinvokation());
676 exceptions_throw_nullpointerexception();
680 /* Class initialization is done by the JIT compiler. This is ok
681 since a static method always belongs to the declaring class. */
683 if (m->flags & ACC_STATIC) {
684 /* For static methods we reset the object. */
689 /* for convenience */
694 /* For instance methods we make a virtual function table lookup. */
696 resm = method_vftbl_lookup(vftbl, m);
699 STATISTICS(jnicallXmethodnvokation());
701 l = vm_call_method_long_jvalue(resm, o, args);
707 /* _Jv_jni_CallFloatMethod *****************************************************
709 Internal function to call Java float methods.
711 *******************************************************************************/
713 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
714 methodinfo *m, va_list ap)
719 /* Class initialization is done by the JIT compiler. This is ok
720 since a static method always belongs to the declaring class. */
722 if (m->flags & ACC_STATIC) {
723 /* For static methods we reset the object. */
728 /* for convenience */
733 /* For instance methods we make a virtual function table lookup. */
735 resm = method_vftbl_lookup(vftbl, m);
738 STATISTICS(jnicallXmethodnvokation());
740 f = vm_call_method_float_valist(resm, o, ap);
746 /* _Jv_jni_CallFloatMethodA ****************************************************
748 Internal function to call Java float methods.
750 *******************************************************************************/
752 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
753 methodinfo *m, jvalue *args)
758 /* Class initialization is done by the JIT compiler. This is ok
759 since a static method always belongs to the declaring class. */
761 if (m->flags & ACC_STATIC) {
762 /* For static methods we reset the object. */
767 /* for convenience */
772 /* For instance methods we make a virtual function table lookup. */
774 resm = method_vftbl_lookup(vftbl, m);
777 STATISTICS(jnicallXmethodnvokation());
779 f = vm_call_method_float_jvalue(resm, o, args);
785 /* _Jv_jni_CallDoubleMethod ****************************************************
787 Internal function to call Java double methods.
789 *******************************************************************************/
791 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
792 methodinfo *m, va_list ap)
797 /* Class initialization is done by the JIT compiler. This is ok
798 since a static method always belongs to the declaring class. */
800 if (m->flags & ACC_STATIC) {
801 /* For static methods we reset the object. */
806 /* for convenience */
811 /* For instance methods we make a virtual function table lookup. */
813 resm = method_vftbl_lookup(vftbl, m);
816 d = vm_call_method_double_valist(resm, o, ap);
822 /* _Jv_jni_CallDoubleMethodA ***************************************************
824 Internal function to call Java double methods.
826 *******************************************************************************/
828 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
829 methodinfo *m, jvalue *args)
834 /* Class initialization is done by the JIT compiler. This is ok
835 since a static method always belongs to the declaring class. */
837 if (m->flags & ACC_STATIC) {
838 /* For static methods we reset the object. */
843 /* for convenience */
848 /* For instance methods we make a virtual function table lookup. */
850 resm = method_vftbl_lookup(vftbl, m);
853 d = vm_call_method_double_jvalue(resm, o, args);
859 /* _Jv_jni_CallVoidMethod ******************************************************
861 Internal function to call Java void methods.
863 *******************************************************************************/
865 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
866 methodinfo *m, va_list ap)
871 exceptions_throw_nullpointerexception();
875 /* Class initialization is done by the JIT compiler. This is ok
876 since a static method always belongs to the declaring class. */
878 if (m->flags & ACC_STATIC) {
879 /* For static methods we reset the object. */
884 /* for convenience */
889 /* For instance methods we make a virtual function table lookup. */
891 resm = method_vftbl_lookup(vftbl, m);
894 STATISTICS(jnicallXmethodnvokation());
896 (void) vm_call_method_valist(resm, o, ap);
900 /* _Jv_jni_CallVoidMethodA *****************************************************
902 Internal function to call Java void methods.
904 *******************************************************************************/
906 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
907 methodinfo *m, jvalue *args)
912 exceptions_throw_nullpointerexception();
916 /* Class initialization is done by the JIT compiler. This is ok
917 since a static method always belongs to the declaring class. */
919 if (m->flags & ACC_STATIC) {
920 /* For static methods we reset the object. */
925 /* for convenience */
930 /* For instance methods we make a virtual function table lookup. */
932 resm = method_vftbl_lookup(vftbl, m);
935 STATISTICS(jnicallXmethodnvokation());
937 (void) vm_call_method_jvalue(resm, o, args);
941 /* _Jv_jni_invokeNative ********************************************************
943 Invoke a method on the given object with the given arguments.
945 For instance methods OBJ must be != NULL and the method is looked up
946 in the vftbl of the object.
948 For static methods, OBJ is ignored.
950 *******************************************************************************/
952 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
953 java_objectarray *params)
957 java_objectheader *ro;
960 java_objectheader *xptr;
963 exceptions_throw_nullpointerexception();
967 argcount = m->parseddesc->paramcount;
968 paramcount = argcount;
970 /* if method is non-static, remove the `this' pointer */
972 if (!(m->flags & ACC_STATIC))
975 /* For instance methods the object has to be an instance of the
976 class the method belongs to. For static methods the obj
977 parameter is ignored. */
979 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
980 exceptions_throw_illegalargumentexception();
984 /* check if we got the right number of arguments */
986 if (((params == NULL) && (paramcount != 0)) ||
987 (params && (params->header.size != paramcount)))
989 exceptions_throw_illegalargumentexception();
993 /* for instance methods we need an object */
995 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
996 /* XXX not sure if that is the correct exception */
997 exceptions_throw_nullpointerexception();
1001 /* for static methods, zero object to make subsequent code simpler */
1002 if (m->flags & ACC_STATIC)
1006 /* for instance methods we must do a vftbl lookup */
1007 resm = method_vftbl_lookup(o->vftbl, m);
1010 /* for static methods, just for convenience */
1014 vmargs = MNEW(vm_arg, argcount);
1016 if (!_Jv_jni_vmargs_from_objectarray(o, resm->parseddesc, vmargs, params)) {
1017 MFREE(vmargs, vm_arg, argcount);
1021 switch (resm->parseddesc->returntype.decltype) {
1023 (void) vm_call_method_vmarg(resm, argcount, vmargs);
1028 case PRIMITIVETYPE_BOOLEAN: {
1030 java_lang_Boolean *bo;
1032 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1034 ro = builtin_new(class_java_lang_Boolean);
1036 /* setting the value of the object direct */
1038 bo = (java_lang_Boolean *) ro;
1043 case PRIMITIVETYPE_BYTE: {
1047 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1049 ro = builtin_new(class_java_lang_Byte);
1051 /* setting the value of the object direct */
1053 bo = (java_lang_Byte *) ro;
1058 case PRIMITIVETYPE_CHAR: {
1060 java_lang_Character *co;
1062 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1064 ro = builtin_new(class_java_lang_Character);
1066 /* setting the value of the object direct */
1068 co = (java_lang_Character *) ro;
1073 case PRIMITIVETYPE_SHORT: {
1075 java_lang_Short *so;
1077 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1079 ro = builtin_new(class_java_lang_Short);
1081 /* setting the value of the object direct */
1083 so = (java_lang_Short *) ro;
1088 case PRIMITIVETYPE_INT: {
1090 java_lang_Integer *io;
1092 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
1094 ro = builtin_new(class_java_lang_Integer);
1096 /* setting the value of the object direct */
1098 io = (java_lang_Integer *) ro;
1103 case PRIMITIVETYPE_LONG: {
1107 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
1109 ro = builtin_new(class_java_lang_Long);
1111 /* setting the value of the object direct */
1113 lo = (java_lang_Long *) ro;
1118 case PRIMITIVETYPE_FLOAT: {
1120 java_lang_Float *fo;
1122 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
1124 ro = builtin_new(class_java_lang_Float);
1126 /* setting the value of the object direct */
1128 fo = (java_lang_Float *) ro;
1133 case PRIMITIVETYPE_DOUBLE: {
1135 java_lang_Double *_do;
1137 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
1139 ro = builtin_new(class_java_lang_Double);
1141 /* setting the value of the object direct */
1143 _do = (java_lang_Double *) ro;
1149 ro = vm_call_method_vmarg(resm, argcount, vmargs);
1153 /* if this happens the exception has already been set by
1154 fill_callblock_from_objectarray */
1156 MFREE(vmargs, vm_arg, argcount);
1161 MFREE(vmargs, vm_arg, argcount);
1163 xptr = exceptions_get_exception();
1166 /* clear exception pointer, we are calling JIT code again */
1168 exceptions_clear_exception();
1170 exceptions_throw_invocationtargetexception(xptr);
1177 /* GetVersion ******************************************************************
1179 Returns the major version number in the higher 16 bits and the
1180 minor version number in the lower 16 bits.
1182 *******************************************************************************/
1184 jint _Jv_JNI_GetVersion(JNIEnv *env)
1186 STATISTICS(jniinvokation());
1188 /* we support JNI 1.4 */
1190 return JNI_VERSION_1_4;
1194 /* Class Operations ***********************************************************/
1196 /* DefineClass *****************************************************************
1198 Loads a class from a buffer of raw class data. The buffer
1199 containing the raw class data is not referenced by the VM after the
1200 DefineClass call returns, and it may be discarded if desired.
1202 *******************************************************************************/
1204 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1205 const jbyte *buf, jsize bufLen)
1207 #if defined(ENABLE_JAVASE)
1208 java_lang_ClassLoader *cl;
1209 java_lang_String *s;
1213 STATISTICS(jniinvokation());
1215 cl = (java_lang_ClassLoader *) loader;
1216 s = (java_lang_String *) javastring_new_from_utf_string(name);
1217 ba = (java_bytearray *) buf;
1219 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1222 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1224 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1226 /* keep compiler happy */
1233 /* FindClass *******************************************************************
1235 This function loads a locally-defined class. It searches the
1236 directories and zip files specified by the CLASSPATH environment
1237 variable for the class with the specified name.
1239 *******************************************************************************/
1241 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1243 #if defined(ENABLE_JAVASE)
1248 STATISTICS(jniinvokation());
1250 u = utf_new_char_classname((char *) name);
1252 /* Check stacktrace for classloader, if one found use it,
1253 otherwise use the system classloader. */
1255 /* Quote from the JNI documentation:
1257 In the Java 2 Platform, FindClass locates the class loader
1258 associated with the current native method. If the native code
1259 belongs to a system class, no class loader will be
1260 involved. Otherwise, the proper class loader will be invoked to
1261 load and link the named class. When FindClass is called through
1262 the Invocation Interface, there is no current native method or
1263 its associated class loader. In that case, the result of
1264 ClassLoader.getBaseClassLoader is used." */
1266 cc = stacktrace_getCurrentClass();
1269 c = load_class_from_sysloader(u);
1271 c = load_class_from_classloader(u, cc->classloader);
1279 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1281 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1283 /* keep compiler happy */
1290 /* GetSuperclass ***************************************************************
1292 If clazz represents any class other than the class Object, then
1293 this function returns the object that represents the superclass of
1294 the class specified by clazz.
1296 *******************************************************************************/
1298 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1302 STATISTICS(jniinvokation());
1304 c = ((classinfo *) sub)->super.cls;
1309 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1313 /* IsAssignableFrom ************************************************************
1315 Determines whether an object of sub can be safely cast to sup.
1317 *******************************************************************************/
1319 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1321 java_lang_Class *csup;
1322 java_lang_Class *csub;
1324 csup = (java_lang_Class *) sup;
1325 csub = (java_lang_Class *) sub;
1327 STATISTICS(jniinvokation());
1329 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1333 /* Throw ***********************************************************************
1335 Causes a java.lang.Throwable object to be thrown.
1337 *******************************************************************************/
1339 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1341 java_objectheader *o;
1343 STATISTICS(jniinvokation());
1345 o = (java_objectheader *) obj;
1347 exceptions_set_exception(o);
1353 /* ThrowNew ********************************************************************
1355 Constructs an exception object from the specified class with the
1356 message specified by message and causes that exception to be
1359 *******************************************************************************/
1361 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1364 java_objectheader *o;
1365 java_objectheader *s;
1367 STATISTICS(jniinvokation());
1369 c = (classinfo *) clazz;
1370 s = javastring_new_from_utf_string(msg);
1372 /* instantiate exception object */
1374 o = native_new_and_init_string(c, s);
1379 exceptions_set_exception(o);
1385 /* ExceptionOccurred ***********************************************************
1387 Determines if an exception is being thrown. The exception stays
1388 being thrown until either the native code calls ExceptionClear(),
1389 or the Java code handles the exception.
1391 *******************************************************************************/
1393 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1395 java_objectheader *o;
1397 STATISTICS(jniinvokation());
1399 o = exceptions_get_exception();
1401 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1405 /* ExceptionDescribe ***********************************************************
1407 Prints an exception and a backtrace of the stack to a system
1408 error-reporting channel, such as stderr. This is a convenience
1409 routine provided for debugging.
1411 *******************************************************************************/
1413 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1415 java_objectheader *o;
1418 STATISTICS(jniinvokation());
1420 o = exceptions_get_exception();
1423 /* clear exception, because we are calling jit code again */
1425 exceptions_clear_exception();
1427 /* get printStackTrace method from exception class */
1429 m = class_resolveclassmethod(o->vftbl->class,
1430 utf_printStackTrace,
1436 /* XXX what should we do? */
1439 /* print the stacktrace */
1441 (void) vm_call_method(m, o);
1446 /* ExceptionClear **************************************************************
1448 Clears any exception that is currently being thrown. If no
1449 exception is currently being thrown, this routine has no effect.
1451 *******************************************************************************/
1453 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1455 STATISTICS(jniinvokation());
1457 exceptions_clear_exception();
1461 /* FatalError ******************************************************************
1463 Raises a fatal error and does not expect the VM to recover. This
1464 function does not return.
1466 *******************************************************************************/
1468 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1470 STATISTICS(jniinvokation());
1472 /* this seems to be the best way */
1474 vm_abort("JNI Fatal error: %s", msg);
1478 /* PushLocalFrame **************************************************************
1480 Creates a new local reference frame, in which at least a given
1481 number of local references can be created.
1483 *******************************************************************************/
1485 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1488 localref_table *lrt;
1489 localref_table *nlrt;
1491 STATISTICS(jniinvokation());
1496 /* Allocate new local reference table on Java heap. Calculate the
1497 additional memory we have to allocate. */
1499 if (capacity > LOCALREFTABLE_CAPACITY)
1500 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1504 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1509 /* get current local reference table from thread */
1511 lrt = LOCALREFTABLE;
1513 /* Set up the new local reference table and add it to the local
1516 nlrt->capacity = capacity;
1518 nlrt->localframes = lrt->localframes + 1;
1521 /* store new local reference table in thread */
1523 LOCALREFTABLE = nlrt;
1529 /* PopLocalFrame ***************************************************************
1531 Pops off the current local reference frame, frees all the local
1532 references, and returns a local reference in the previous local
1533 reference frame for the given result object.
1535 *******************************************************************************/
1537 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1539 localref_table *lrt;
1540 localref_table *plrt;
1543 STATISTICS(jniinvokation());
1545 /* get current local reference table from thread */
1547 lrt = LOCALREFTABLE;
1549 localframes = lrt->localframes;
1551 /* Don't delete the top local frame, as this one is allocated in
1552 the native stub on the stack and is freed automagically on
1555 if (localframes == 1)
1556 return _Jv_JNI_NewLocalRef(env, result);
1558 /* release all current local frames */
1560 for (; localframes >= 1; localframes--) {
1561 /* get previous frame */
1565 /* clear all reference entries */
1567 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1571 /* set new local references table */
1576 /* store new local reference table in thread */
1578 LOCALREFTABLE = lrt;
1580 /* add local reference and return the value */
1582 return _Jv_JNI_NewLocalRef(env, result);
1586 /* DeleteLocalRef **************************************************************
1588 Deletes the local reference pointed to by localRef.
1590 *******************************************************************************/
1592 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1594 java_objectheader *o;
1595 localref_table *lrt;
1598 STATISTICS(jniinvokation());
1600 o = (java_objectheader *) localRef;
1602 /* get local reference table (thread specific) */
1604 lrt = LOCALREFTABLE;
1606 /* go through all local frames */
1608 for (; lrt != NULL; lrt = lrt->prev) {
1610 /* and try to remove the reference */
1612 for (i = 0; i < lrt->capacity; i++) {
1613 if (lrt->refs[i] == o) {
1614 lrt->refs[i] = NULL;
1622 /* this should not happen */
1624 /* if (opt_checkjni) */
1625 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1626 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1630 /* IsSameObject ****************************************************************
1632 Tests whether two references refer to the same Java object.
1634 *******************************************************************************/
1636 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1638 STATISTICS(jniinvokation());
1647 /* NewLocalRef *****************************************************************
1649 Creates a new local reference that refers to the same object as ref.
1651 *******************************************************************************/
1653 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1655 localref_table *lrt;
1658 STATISTICS(jniinvokation());
1663 /* get local reference table (thread specific) */
1665 lrt = LOCALREFTABLE;
1667 /* Check if we have space for the requested reference? No,
1668 allocate a new frame. This is actually not what the spec says,
1669 but for compatibility reasons... */
1671 if (lrt->used == lrt->capacity) {
1672 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1675 /* get the new local reference table */
1677 lrt = LOCALREFTABLE;
1680 /* insert the reference */
1682 for (i = 0; i < lrt->capacity; i++) {
1683 if (lrt->refs[i] == NULL) {
1684 lrt->refs[i] = (java_objectheader *) ref;
1691 /* should not happen, just to be sure */
1695 /* keep compiler happy */
1701 /* EnsureLocalCapacity *********************************************************
1703 Ensures that at least a given number of local references can be
1704 created in the current thread
1706 *******************************************************************************/
1708 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1710 localref_table *lrt;
1712 STATISTICS(jniinvokation());
1714 /* get local reference table (thread specific) */
1716 lrt = LOCALREFTABLE;
1718 /* check if capacity elements are available in the local references table */
1720 if ((lrt->used + capacity) > lrt->capacity)
1721 return _Jv_JNI_PushLocalFrame(env, capacity);
1727 /* AllocObject *****************************************************************
1729 Allocates a new Java object without invoking any of the
1730 constructors for the object. Returns a reference to the object.
1732 *******************************************************************************/
1734 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1737 java_objectheader *o;
1739 STATISTICS(jniinvokation());
1741 c = (classinfo *) clazz;
1743 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1744 exceptions_throw_instantiationexception(c);
1750 return _Jv_JNI_NewLocalRef(env, o);
1754 /* NewObject *******************************************************************
1756 Programmers place all arguments that are to be passed to the
1757 constructor immediately following the methodID
1758 argument. NewObject() accepts these arguments and passes them to
1759 the Java method that the programmer wishes to invoke.
1761 *******************************************************************************/
1763 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1765 java_objectheader *o;
1769 STATISTICS(jniinvokation());
1771 m = (methodinfo *) methodID;
1775 o = builtin_new(clazz);
1780 /* call constructor */
1782 va_start(ap, methodID);
1783 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1786 return _Jv_JNI_NewLocalRef(env, o);
1790 /* NewObjectV ******************************************************************
1792 Programmers place all arguments that are to be passed to the
1793 constructor in an args argument of type va_list that immediately
1794 follows the methodID argument. NewObjectV() accepts these
1795 arguments, and, in turn, passes them to the Java method that the
1796 programmer wishes to invoke.
1798 *******************************************************************************/
1800 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1803 java_objectheader *o;
1806 STATISTICS(jniinvokation());
1808 m = (methodinfo *) methodID;
1812 o = builtin_new(clazz);
1817 /* call constructor */
1819 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1821 return _Jv_JNI_NewLocalRef(env, o);
1825 /* NewObjectA *****************************************************************
1827 Programmers place all arguments that are to be passed to the
1828 constructor in an args array of jvalues that immediately follows
1829 the methodID argument. NewObjectA() accepts the arguments in this
1830 array, and, in turn, passes them to the Java method that the
1831 programmer wishes to invoke.
1833 *******************************************************************************/
1835 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1838 java_objectheader *o;
1841 STATISTICS(jniinvokation());
1843 m = (methodinfo *) methodID;
1847 o = builtin_new(clazz);
1852 /* call constructor */
1854 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1856 return _Jv_JNI_NewLocalRef(env, o);
1860 /* GetObjectClass **************************************************************
1862 Returns the class of an object.
1864 *******************************************************************************/
1866 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1868 java_objectheader *o;
1871 STATISTICS(jniinvokation());
1873 o = (java_objectheader *) obj;
1875 if ((o == NULL) || (o->vftbl == NULL))
1878 c = o->vftbl->class;
1880 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1884 /* IsInstanceOf ****************************************************************
1886 Tests whether an object is an instance of a class.
1888 *******************************************************************************/
1890 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1893 java_lang_Object *o;
1895 STATISTICS(jniinvokation());
1897 c = (java_lang_Class *) clazz;
1898 o = (java_lang_Object *) obj;
1900 return _Jv_java_lang_Class_isInstance(c, o);
1904 /* Reflection Support *********************************************************/
1906 /* FromReflectedMethod *********************************************************
1908 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1909 object to a method ID.
1911 *******************************************************************************/
1913 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1915 #if defined(ENABLE_JAVASE)
1920 STATISTICS(jniinvokation());
1925 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1926 java_lang_reflect_Method *rm;
1928 rm = (java_lang_reflect_Method *) method;
1929 c = (classinfo *) (rm->declaringClass);
1932 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1933 java_lang_reflect_Constructor *rc;
1935 rc = (java_lang_reflect_Constructor *) method;
1936 c = (classinfo *) (rc->clazz);
1942 mi = &(c->methods[slot]);
1944 return (jmethodID) mi;
1946 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1948 /* keep compiler happy */
1955 /* FromReflectedField **********************************************************
1957 Converts a java.lang.reflect.Field to a field ID.
1959 *******************************************************************************/
1961 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1963 #if defined(ENABLE_JAVASE)
1964 java_lang_reflect_Field *rf;
1968 STATISTICS(jniinvokation());
1970 rf = (java_lang_reflect_Field *) field;
1975 c = (classinfo *) rf->declaringClass;
1977 f = &(c->fields[rf->slot]);
1979 return (jfieldID) f;
1981 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1983 /* keep compiler happy */
1990 /* ToReflectedMethod ***********************************************************
1992 Converts a method ID derived from cls to an instance of the
1993 java.lang.reflect.Method class or to an instance of the
1994 java.lang.reflect.Constructor class.
1996 *******************************************************************************/
1998 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
2001 STATISTICS(jniinvokation());
2003 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
2009 /* ToReflectedField ************************************************************
2011 Converts a field ID derived from cls to an instance of the
2012 java.lang.reflect.Field class.
2014 *******************************************************************************/
2016 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
2019 STATISTICS(jniinvokation());
2021 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
2027 /* Calling Instance Methods ***************************************************/
2029 /* GetMethodID *****************************************************************
2031 Returns the method ID for an instance (nonstatic) method of a class
2032 or interface. The method may be defined in one of the clazz's
2033 superclasses and inherited by clazz. The method is determined by
2034 its name and signature.
2036 GetMethodID() causes an uninitialized class to be initialized.
2038 *******************************************************************************/
2040 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
2048 STATISTICS(jniinvokation());
2050 c = (classinfo *) clazz;
2055 if (!(c->state & CLASS_INITIALIZED))
2056 if (!initialize_class(c))
2059 /* try to get the method of the class or one of it's superclasses */
2061 uname = utf_new_char((char *) name);
2062 udesc = utf_new_char((char *) sig);
2064 m = class_resolvemethod(clazz, uname, udesc);
2066 if ((m == NULL) || (m->flags & ACC_STATIC)) {
2067 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2072 return (jmethodID) m;
2076 /* JNI-functions for calling instance methods *********************************/
2078 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2081 java_objectheader *o;
2083 java_objectheader *ret;
2086 o = (java_objectheader *) obj;
2087 m = (methodinfo *) methodID;
2089 va_start(ap, methodID);
2090 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
2093 return _Jv_JNI_NewLocalRef(env, ret);
2097 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2100 java_objectheader *o;
2102 java_objectheader *ret;
2104 o = (java_objectheader *) obj;
2105 m = (methodinfo *) methodID;
2107 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2109 return _Jv_JNI_NewLocalRef(env, ret);
2113 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2116 java_objectheader *o;
2118 java_objectheader *ret;
2120 o = (java_objectheader *) obj;
2121 m = (methodinfo *) methodID;
2123 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2125 return _Jv_JNI_NewLocalRef(env, ret);
2129 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2132 java_objectheader *o;
2137 o = (java_objectheader *) obj;
2138 m = (methodinfo *) methodID;
2140 va_start(ap, methodID);
2141 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2148 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2149 jmethodID methodID, va_list args)
2151 java_objectheader *o;
2155 o = (java_objectheader *) obj;
2156 m = (methodinfo *) methodID;
2158 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2164 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2165 jmethodID methodID, jvalue *args)
2167 java_objectheader *o;
2171 o = (java_objectheader *) obj;
2172 m = (methodinfo *) methodID;
2174 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2180 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2182 java_objectheader *o;
2187 o = (java_objectheader *) obj;
2188 m = (methodinfo *) methodID;
2190 va_start(ap, methodID);
2191 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2199 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2202 java_objectheader *o;
2206 o = (java_objectheader *) obj;
2207 m = (methodinfo *) methodID;
2209 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2215 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2218 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2224 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2226 java_objectheader *o;
2231 o = (java_objectheader *) obj;
2232 m = (methodinfo *) methodID;
2234 va_start(ap, methodID);
2235 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2242 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2245 java_objectheader *o;
2249 o = (java_objectheader *) obj;
2250 m = (methodinfo *) methodID;
2252 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2258 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2261 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2267 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2270 java_objectheader *o;
2275 o = (java_objectheader *) obj;
2276 m = (methodinfo *) methodID;
2278 va_start(ap, methodID);
2279 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2286 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2289 java_objectheader *o;
2293 o = (java_objectheader *) obj;
2294 m = (methodinfo *) methodID;
2296 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2302 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2305 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2312 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2314 java_objectheader *o;
2319 o = (java_objectheader *) obj;
2320 m = (methodinfo *) methodID;
2322 va_start(ap, methodID);
2323 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2330 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2333 java_objectheader *o;
2337 o = (java_objectheader *) obj;
2338 m = (methodinfo *) methodID;
2340 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2346 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2349 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2356 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2358 java_objectheader *o;
2363 o = (java_objectheader *) obj;
2364 m = (methodinfo *) methodID;
2366 va_start(ap, methodID);
2367 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2374 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2377 java_objectheader *o;
2381 o = (java_objectheader *) obj;
2382 m = (methodinfo *) methodID;
2384 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2390 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2393 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2400 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2403 java_objectheader *o;
2408 o = (java_objectheader *) obj;
2409 m = (methodinfo *) methodID;
2411 va_start(ap, methodID);
2412 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2419 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2422 java_objectheader *o;
2426 o = (java_objectheader *) obj;
2427 m = (methodinfo *) methodID;
2429 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2435 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2438 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2445 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2448 java_objectheader *o;
2453 o = (java_objectheader *) obj;
2454 m = (methodinfo *) methodID;
2456 va_start(ap, methodID);
2457 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2464 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2467 java_objectheader *o;
2471 o = (java_objectheader *) obj;
2472 m = (methodinfo *) methodID;
2474 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2480 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2483 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2490 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2492 java_objectheader *o;
2496 o = (java_objectheader *) obj;
2497 m = (methodinfo *) methodID;
2499 va_start(ap, methodID);
2500 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2505 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2508 java_objectheader *o;
2511 o = (java_objectheader *) obj;
2512 m = (methodinfo *) methodID;
2514 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2518 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2521 java_objectheader *o;
2524 o = (java_objectheader *) obj;
2525 m = (methodinfo *) methodID;
2527 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2532 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2533 jclass clazz, jmethodID methodID,
2536 java_objectheader *o;
2539 java_objectheader *r;
2542 o = (java_objectheader *) obj;
2543 c = (classinfo *) clazz;
2544 m = (methodinfo *) methodID;
2546 va_start(ap, methodID);
2547 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2550 return _Jv_JNI_NewLocalRef(env, r);
2554 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2555 jclass clazz, jmethodID methodID,
2558 java_objectheader *o;
2561 java_objectheader *r;
2563 o = (java_objectheader *) obj;
2564 c = (classinfo *) clazz;
2565 m = (methodinfo *) methodID;
2567 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2569 return _Jv_JNI_NewLocalRef(env, r);
2573 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2574 jclass clazz, jmethodID methodID,
2577 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2579 return _Jv_JNI_NewLocalRef(env, NULL);
2584 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2585 jclass clazz, jmethodID methodID,
2588 java_objectheader *o;
2594 o = (java_objectheader *) obj;
2595 c = (classinfo *) clazz;
2596 m = (methodinfo *) methodID;
2598 va_start(ap, methodID);
2599 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2606 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2607 jclass clazz, jmethodID methodID,
2610 java_objectheader *o;
2615 o = (java_objectheader *) obj;
2616 c = (classinfo *) clazz;
2617 m = (methodinfo *) methodID;
2619 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2625 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2626 jclass clazz, jmethodID methodID,
2629 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2635 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2636 jmethodID methodID, ...)
2638 java_objectheader *o;
2644 o = (java_objectheader *) obj;
2645 c = (classinfo *) clazz;
2646 m = (methodinfo *) methodID;
2648 va_start(ap, methodID);
2649 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2656 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2657 jmethodID methodID, va_list args)
2659 java_objectheader *o;
2664 o = (java_objectheader *) obj;
2665 c = (classinfo *) clazz;
2666 m = (methodinfo *) methodID;
2668 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2674 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2675 jmethodID methodID, jvalue *args)
2677 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2684 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2685 jmethodID methodID, ...)
2687 java_objectheader *o;
2693 o = (java_objectheader *) obj;
2694 c = (classinfo *) clazz;
2695 m = (methodinfo *) methodID;
2697 va_start(ap, methodID);
2698 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2705 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2706 jmethodID methodID, va_list args)
2708 java_objectheader *o;
2713 o = (java_objectheader *) obj;
2714 c = (classinfo *) clazz;
2715 m = (methodinfo *) methodID;
2717 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2723 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2724 jmethodID methodID, jvalue *args)
2726 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2733 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2734 jclass clazz, jmethodID methodID, ...)
2736 java_objectheader *o;
2742 o = (java_objectheader *) obj;
2743 c = (classinfo *) clazz;
2744 m = (methodinfo *) methodID;
2746 va_start(ap, methodID);
2747 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2754 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2755 jclass clazz, jmethodID methodID,
2758 java_objectheader *o;
2763 o = (java_objectheader *) obj;
2764 c = (classinfo *) clazz;
2765 m = (methodinfo *) methodID;
2767 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2773 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2774 jclass clazz, jmethodID methodID,
2777 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2784 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2785 jmethodID methodID, ...)
2787 java_objectheader *o;
2793 o = (java_objectheader *) obj;
2794 c = (classinfo *) clazz;
2795 m = (methodinfo *) methodID;
2797 va_start(ap, methodID);
2798 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2805 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2806 jmethodID methodID, va_list args)
2808 java_objectheader *o;
2813 o = (java_objectheader *) obj;
2814 c = (classinfo *) clazz;
2815 m = (methodinfo *) methodID;
2817 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2823 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2824 jmethodID methodID, jvalue *args)
2826 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2833 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2834 jmethodID methodID, ...)
2836 java_objectheader *o;
2842 o = (java_objectheader *) obj;
2843 c = (classinfo *) clazz;
2844 m = (methodinfo *) methodID;
2846 va_start(ap, methodID);
2847 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2854 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2855 jmethodID methodID, va_list args)
2857 java_objectheader *o;
2862 o = (java_objectheader *) obj;
2863 c = (classinfo *) clazz;
2864 m = (methodinfo *) methodID;
2866 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2872 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2873 jmethodID methodID, jvalue *args)
2875 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2882 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2883 jclass clazz, jmethodID methodID, ...)
2885 java_objectheader *o;
2891 o = (java_objectheader *) obj;
2892 c = (classinfo *) clazz;
2893 m = (methodinfo *) methodID;
2895 va_start(ap, methodID);
2896 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2903 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2904 jclass clazz, jmethodID methodID,
2907 java_objectheader *o;
2912 o = (java_objectheader *) obj;
2913 c = (classinfo *) clazz;
2914 m = (methodinfo *) methodID;
2916 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2922 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2923 jclass clazz, jmethodID methodID,
2926 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2933 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2934 jclass clazz, jmethodID methodID,
2937 java_objectheader *o;
2943 o = (java_objectheader *) obj;
2944 c = (classinfo *) clazz;
2945 m = (methodinfo *) methodID;
2947 va_start(ap, methodID);
2948 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2955 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2956 jclass clazz, jmethodID methodID,
2959 java_objectheader *o;
2964 o = (java_objectheader *) obj;
2965 c = (classinfo *) clazz;
2966 m = (methodinfo *) methodID;
2968 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2974 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2975 jclass clazz, jmethodID methodID,
2978 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2985 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2986 jmethodID methodID, ...)
2988 java_objectheader *o;
2993 o = (java_objectheader *) obj;
2994 c = (classinfo *) clazz;
2995 m = (methodinfo *) methodID;
2997 va_start(ap, methodID);
2998 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
3003 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
3004 jmethodID methodID, va_list args)
3006 java_objectheader *o;
3010 o = (java_objectheader *) obj;
3011 c = (classinfo *) clazz;
3012 m = (methodinfo *) methodID;
3014 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
3018 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
3019 jmethodID methodID, jvalue * args)
3021 java_objectheader *o;
3025 o = (java_objectheader *) obj;
3026 c = (classinfo *) clazz;
3027 m = (methodinfo *) methodID;
3029 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
3033 /* Accessing Fields of Objects ************************************************/
3035 /* GetFieldID ******************************************************************
3037 Returns the field ID for an instance (nonstatic) field of a
3038 class. The field is specified by its name and signature. The
3039 Get<type>Field and Set<type>Field families of accessor functions
3040 use field IDs to retrieve object fields.
3042 *******************************************************************************/
3044 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
3052 STATISTICS(jniinvokation());
3054 c = (classinfo *) clazz;
3056 uname = utf_new_char((char *) name);
3057 udesc = utf_new_char((char *) sig);
3059 f = class_findfield(clazz, uname, udesc);
3062 exceptions_throw_nosuchfielderror(c, uname);
3064 return (jfieldID) f;
3068 /* Get<type>Field Routines *****************************************************
3070 This family of accessor routines returns the value of an instance
3071 (nonstatic) field of an object. The field to access is specified by
3072 a field ID obtained by calling GetFieldID().
3074 *******************************************************************************/
3076 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
3078 java_objectheader *o;
3080 STATISTICS(jniinvokation());
3082 o = GET_FIELD(obj, java_objectheader*, fieldID);
3084 return _Jv_JNI_NewLocalRef(env, o);
3088 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
3092 STATISTICS(jniinvokation());
3094 i = GET_FIELD(obj, s4, fieldID);
3096 return (jboolean) i;
3100 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3104 STATISTICS(jniinvokation());
3106 i = GET_FIELD(obj, s4, fieldID);
3112 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3116 STATISTICS(jniinvokation());
3118 i = GET_FIELD(obj, s4, fieldID);
3124 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3128 STATISTICS(jniinvokation());
3130 i = GET_FIELD(obj, s4, fieldID);
3136 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3138 java_objectheader *o;
3142 STATISTICS(jniinvokation());
3144 o = (java_objectheader *) obj;
3145 f = (fieldinfo *) fieldID;
3147 i = GET_FIELD(o, s4, f);
3153 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3157 STATISTICS(jniinvokation());
3159 l = GET_FIELD(obj, s8, fieldID);
3165 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3169 STATISTICS(jniinvokation());
3171 f = GET_FIELD(obj, float, fieldID);
3177 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3181 STATISTICS(jniinvokation());
3183 d = GET_FIELD(obj, double, fieldID);
3189 /* Set<type>Field Routines *****************************************************
3191 This family of accessor routines sets the value of an instance
3192 (nonstatic) field of an object. The field to access is specified by
3193 a field ID obtained by calling GetFieldID().
3195 *******************************************************************************/
3197 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3200 STATISTICS(jniinvokation());
3202 SET_FIELD(obj, java_objectheader*, fieldID, value);
3206 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3209 STATISTICS(jniinvokation());
3211 SET_FIELD(obj, s4, fieldID, value);
3215 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3218 STATISTICS(jniinvokation());
3220 SET_FIELD(obj, s4, fieldID, value);
3224 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3227 STATISTICS(jniinvokation());
3229 SET_FIELD(obj, s4, fieldID, value);
3233 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3236 STATISTICS(jniinvokation());
3238 SET_FIELD(obj, s4, fieldID, value);
3242 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3244 STATISTICS(jniinvokation());
3246 SET_FIELD(obj, s4, fieldID, value);
3250 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3253 STATISTICS(jniinvokation());
3255 SET_FIELD(obj, s8, fieldID, value);
3259 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3262 STATISTICS(jniinvokation());
3264 SET_FIELD(obj, float, fieldID, value);
3268 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3271 STATISTICS(jniinvokation());
3273 SET_FIELD(obj, double, fieldID, value);
3277 /* Calling Static Methods *****************************************************/
3279 /* GetStaticMethodID ***********************************************************
3281 Returns the method ID for a static method of a class. The method is
3282 specified by its name and signature.
3284 GetStaticMethodID() causes an uninitialized class to be
3287 *******************************************************************************/
3289 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3297 STATISTICS(jniinvokation());
3299 c = (classinfo *) clazz;
3304 if (!(c->state & CLASS_INITIALIZED))
3305 if (!initialize_class(c))
3308 /* try to get the static method of the class */
3310 uname = utf_new_char((char *) name);
3311 udesc = utf_new_char((char *) sig);
3313 m = class_resolvemethod(c, uname, udesc);
3315 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3316 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3321 return (jmethodID) m;
3325 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3326 jmethodID methodID, ...)
3329 java_objectheader *o;
3332 m = (methodinfo *) methodID;
3334 va_start(ap, methodID);
3335 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3338 return _Jv_JNI_NewLocalRef(env, o);
3342 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3343 jmethodID methodID, va_list args)
3346 java_objectheader *o;
3348 m = (methodinfo *) methodID;
3350 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3352 return _Jv_JNI_NewLocalRef(env, o);
3356 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3357 jmethodID methodID, jvalue *args)
3360 java_objectheader *o;
3362 m = (methodinfo *) methodID;
3364 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3366 return _Jv_JNI_NewLocalRef(env, o);
3370 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3371 jmethodID methodID, ...)
3377 m = (methodinfo *) methodID;
3379 va_start(ap, methodID);
3380 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3387 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3388 jmethodID methodID, va_list args)
3393 m = (methodinfo *) methodID;
3395 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3401 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3402 jmethodID methodID, jvalue *args)
3407 m = (methodinfo *) methodID;
3409 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3415 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3416 jmethodID methodID, ...)
3422 m = (methodinfo *) methodID;
3424 va_start(ap, methodID);
3425 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3432 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3433 jmethodID methodID, va_list args)
3438 m = (methodinfo *) methodID;
3440 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3446 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3447 jmethodID methodID, jvalue *args)
3452 m = (methodinfo *) methodID;
3454 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3460 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3461 jmethodID methodID, ...)
3467 m = (methodinfo *) methodID;
3469 va_start(ap, methodID);
3470 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3477 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3478 jmethodID methodID, va_list args)
3483 m = (methodinfo *) methodID;
3485 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3491 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3492 jmethodID methodID, jvalue *args)
3497 m = (methodinfo *) methodID;
3499 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3505 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3506 jmethodID methodID, ...)
3512 m = (methodinfo *) methodID;
3514 va_start(ap, methodID);
3515 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3522 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3523 jmethodID methodID, va_list args)
3528 m = (methodinfo *) methodID;
3530 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3536 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3537 jmethodID methodID, jvalue *args)
3542 m = (methodinfo *) methodID;
3544 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3550 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3557 m = (methodinfo *) methodID;
3559 va_start(ap, methodID);
3560 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3567 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3568 jmethodID methodID, va_list args)
3573 m = (methodinfo *) methodID;
3575 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3581 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3582 jmethodID methodID, jvalue *args)
3587 m = (methodinfo *) methodID;
3589 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3595 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3596 jmethodID methodID, ...)
3602 m = (methodinfo *) methodID;
3604 va_start(ap, methodID);
3605 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3612 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3613 jmethodID methodID, va_list args)
3618 m = (methodinfo *) methodID;
3620 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3626 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3627 jmethodID methodID, jvalue *args)
3632 m = (methodinfo *) methodID;
3634 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3641 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3642 jmethodID methodID, ...)
3648 m = (methodinfo *) methodID;
3650 va_start(ap, methodID);
3651 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3658 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3659 jmethodID methodID, va_list args)
3664 m = (methodinfo *) methodID;
3666 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3672 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3673 jmethodID methodID, jvalue *args)
3678 m = (methodinfo *) methodID;
3680 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3686 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3687 jmethodID methodID, ...)
3693 m = (methodinfo *) methodID;
3695 va_start(ap, methodID);
3696 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3703 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3704 jmethodID methodID, va_list args)
3709 m = (methodinfo *) methodID;
3711 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3717 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3718 jmethodID methodID, jvalue *args)
3723 m = (methodinfo *) methodID;
3725 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3731 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3732 jmethodID methodID, ...)
3737 m = (methodinfo *) methodID;
3739 va_start(ap, methodID);
3740 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3745 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3746 jmethodID methodID, va_list args)
3750 m = (methodinfo *) methodID;
3752 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3756 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3757 jmethodID methodID, jvalue * args)
3761 m = (methodinfo *) methodID;
3763 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3767 /* Accessing Static Fields ****************************************************/
3769 /* GetStaticFieldID ************************************************************
3771 Returns the field ID for a static field of a class. The field is
3772 specified by its name and signature. The GetStatic<type>Field and
3773 SetStatic<type>Field families of accessor functions use field IDs
3774 to retrieve static fields.
3776 *******************************************************************************/
3778 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3786 STATISTICS(jniinvokation());
3788 c = (classinfo *) clazz;
3790 uname = utf_new_char((char *) name);
3791 usig = utf_new_char((char *) sig);
3793 f = class_findfield(clazz, uname, usig);
3796 exceptions_throw_nosuchfielderror(c, uname);
3798 return (jfieldID) f;
3802 /* GetStatic<type>Field ********************************************************
3804 This family of accessor routines returns the value of a static
3807 *******************************************************************************/
3809 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3815 STATISTICS(jniinvokation());
3817 c = (classinfo *) clazz;
3818 f = (fieldinfo *) fieldID;
3820 if (!(c->state & CLASS_INITIALIZED))
3821 if (!initialize_class(c))
3824 return _Jv_JNI_NewLocalRef(env, f->value.a);
3828 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3834 STATISTICS(jniinvokation());
3836 c = (classinfo *) clazz;
3837 f = (fieldinfo *) fieldID;
3839 if (!(c->state & CLASS_INITIALIZED))
3840 if (!initialize_class(c))
3847 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3852 STATISTICS(jniinvokation());
3854 c = (classinfo *) clazz;
3855 f = (fieldinfo *) fieldID;
3857 if (!(c->state & CLASS_INITIALIZED))
3858 if (!initialize_class(c))
3865 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3870 STATISTICS(jniinvokation());
3872 c = (classinfo *) clazz;
3873 f = (fieldinfo *) fieldID;
3875 if (!(c->state & CLASS_INITIALIZED))
3876 if (!initialize_class(c))
3883 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3888 STATISTICS(jniinvokation());
3890 c = (classinfo *) clazz;
3891 f = (fieldinfo *) fieldID;
3893 if (!(c->state & CLASS_INITIALIZED))
3894 if (!initialize_class(c))
3901 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3906 STATISTICS(jniinvokation());
3908 c = (classinfo *) clazz;
3909 f = (fieldinfo *) fieldID;
3911 if (!(c->state & CLASS_INITIALIZED))
3912 if (!initialize_class(c))
3919 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3924 STATISTICS(jniinvokation());
3926 c = (classinfo *) clazz;
3927 f = (fieldinfo *) fieldID;
3929 if (!(c->state & CLASS_INITIALIZED))
3930 if (!initialize_class(c))
3937 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3942 STATISTICS(jniinvokation());
3944 c = (classinfo *) clazz;
3945 f = (fieldinfo *) fieldID;
3947 if (!(c->state & CLASS_INITIALIZED))
3948 if (!initialize_class(c))
3955 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3961 STATISTICS(jniinvokation());
3963 c = (classinfo *) clazz;
3964 f = (fieldinfo *) fieldID;
3966 if (!(c->state & CLASS_INITIALIZED))
3967 if (!initialize_class(c))
3974 /* SetStatic<type>Field *******************************************************
3976 This family of accessor routines sets the value of a static field
3979 *******************************************************************************/
3981 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3987 STATISTICS(jniinvokation());
3989 c = (classinfo *) clazz;
3990 f = (fieldinfo *) fieldID;
3992 if (!(c->state & CLASS_INITIALIZED))
3993 if (!initialize_class(c))
4000 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4006 STATISTICS(jniinvokation());
4008 c = (classinfo *) clazz;
4009 f = (fieldinfo *) fieldID;
4011 if (!(c->state & CLASS_INITIALIZED))
4012 if (!initialize_class(c))
4019 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4025 STATISTICS(jniinvokation());
4027 c = (classinfo *) clazz;
4028 f = (fieldinfo *) fieldID;
4030 if (!(c->state & CLASS_INITIALIZED))
4031 if (!initialize_class(c))
4038 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4044 STATISTICS(jniinvokation());
4046 c = (classinfo *) clazz;
4047 f = (fieldinfo *) fieldID;
4049 if (!(c->state & CLASS_INITIALIZED))
4050 if (!initialize_class(c))
4057 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4063 STATISTICS(jniinvokation());
4065 c = (classinfo *) clazz;
4066 f = (fieldinfo *) fieldID;
4068 if (!(c->state & CLASS_INITIALIZED))
4069 if (!initialize_class(c))
4076 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4082 STATISTICS(jniinvokation());
4084 c = (classinfo *) clazz;
4085 f = (fieldinfo *) fieldID;
4087 if (!(c->state & CLASS_INITIALIZED))
4088 if (!initialize_class(c))
4095 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4101 STATISTICS(jniinvokation());
4103 c = (classinfo *) clazz;
4104 f = (fieldinfo *) fieldID;
4106 if (!(c->state & CLASS_INITIALIZED))
4107 if (!initialize_class(c))
4114 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4120 STATISTICS(jniinvokation());
4122 c = (classinfo *) clazz;
4123 f = (fieldinfo *) fieldID;
4125 if (!(c->state & CLASS_INITIALIZED))
4126 if (!initialize_class(c))
4133 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4139 STATISTICS(jniinvokation());
4141 c = (classinfo *) clazz;
4142 f = (fieldinfo *) fieldID;
4144 if (!(c->state & CLASS_INITIALIZED))
4145 if (!initialize_class(c))
4152 /* String Operations **********************************************************/
4154 /* NewString *******************************************************************
4156 Create new java.lang.String object from an array of Unicode
4159 *******************************************************************************/
4161 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4163 java_lang_String *s;
4167 STATISTICS(jniinvokation());
4169 s = (java_lang_String *) builtin_new(class_java_lang_String);
4170 a = builtin_newarray_char(len);
4172 /* javastring or characterarray could not be created */
4173 if ((a == NULL) || (s == NULL))
4177 for (i = 0; i < len; i++)
4178 a->data[i] = buf[i];
4184 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4188 static jchar emptyStringJ[]={0,0};
4190 /* GetStringLength *************************************************************
4192 Returns the length (the count of Unicode characters) of a Java
4195 *******************************************************************************/
4197 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4199 return ((java_lang_String *) str)->count;
4203 /******************** convertes javastring to u2-array ****************************/
4205 u2 *javastring_tou2(jstring so)
4207 java_lang_String *s;
4212 STATISTICS(jniinvokation());
4214 s = (java_lang_String *) so;
4224 /* allocate memory */
4226 stringbuffer = MNEW(u2, s->count + 1);
4230 for (i = 0; i < s->count; i++)
4231 stringbuffer[i] = a->data[s->offset + i];
4233 /* terminate string */
4235 stringbuffer[i] = '\0';
4237 return stringbuffer;
4241 /* GetStringChars **************************************************************
4243 Returns a pointer to the array of Unicode characters of the
4244 string. This pointer is valid until ReleaseStringChars() is called.
4246 *******************************************************************************/
4248 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4252 STATISTICS(jniinvokation());
4254 jc = javastring_tou2(str);
4266 return emptyStringJ;
4270 /* ReleaseStringChars **********************************************************
4272 Informs the VM that the native code no longer needs access to
4273 chars. The chars argument is a pointer obtained from string using
4276 *******************************************************************************/
4278 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4280 STATISTICS(jniinvokation());
4282 if (chars == emptyStringJ)
4285 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4289 /* NewStringUTF ****************************************************************
4291 Constructs a new java.lang.String object from an array of UTF-8
4294 *******************************************************************************/
4296 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4298 java_lang_String *s;
4300 STATISTICS(jniinvokation());
4302 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4304 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4308 /****************** returns the utf8 length in bytes of a string *******************/
4310 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4312 java_lang_String *s = (java_lang_String*) string;
4314 STATISTICS(jniinvokation());
4316 return (jsize) u2_utflength(s->value->data, s->count);
4320 /* GetStringUTFChars ***********************************************************
4322 Returns a pointer to an array of UTF-8 characters of the
4323 string. This array is valid until it is released by
4324 ReleaseStringUTFChars().
4326 *******************************************************************************/
4328 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4333 STATISTICS(jniinvokation());
4341 u = javastring_toutf((java_objectheader *) string, false);
4350 /* ReleaseStringUTFChars *******************************************************
4352 Informs the VM that the native code no longer needs access to
4353 utf. The utf argument is a pointer derived from string using
4354 GetStringUTFChars().
4356 *******************************************************************************/
4358 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4360 STATISTICS(jniinvokation());
4362 /* XXX we don't release utf chars right now, perhaps that should be done
4363 later. Since there is always one reference the garbage collector will
4368 /* Array Operations ***********************************************************/
4370 /* GetArrayLength **************************************************************
4372 Returns the number of elements in the array.
4374 *******************************************************************************/
4376 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4378 java_arrayheader *a;
4380 STATISTICS(jniinvokation());
4382 a = (java_arrayheader *) array;
4388 /* NewObjectArray **************************************************************
4390 Constructs a new array holding objects in class elementClass. All
4391 elements are initially set to initialElement.
4393 *******************************************************************************/
4395 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4396 jclass elementClass, jobject initialElement)
4398 java_objectarray *oa;
4401 STATISTICS(jniinvokation());
4404 exceptions_throw_negativearraysizeexception();
4408 oa = builtin_anewarray(length, elementClass);
4413 /* set all elements to initialElement */
4415 for (i = 0; i < length; i++)
4416 oa->data[i] = initialElement;
4418 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4422 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4425 java_objectarray *oa;
4428 STATISTICS(jniinvokation());
4430 oa = (java_objectarray *) array;
4432 if (index >= oa->header.size) {
4433 exceptions_throw_arrayindexoutofboundsexception();
4437 o = oa->data[index];
4439 return _Jv_JNI_NewLocalRef(env, o);
4443 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4444 jsize index, jobject val)
4446 java_objectarray *oa;
4447 java_objectheader *o;
4449 STATISTICS(jniinvokation());
4451 oa = (java_objectarray *) array;
4452 o = (java_objectheader *) val;
4454 if (index >= oa->header.size) {
4455 exceptions_throw_arrayindexoutofboundsexception();
4459 /* check if the class of value is a subclass of the element class
4462 if (!builtin_canstore(oa, o))
4465 oa->data[index] = val;
4469 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4471 java_booleanarray *ba;
4473 STATISTICS(jniinvokation());
4476 exceptions_throw_negativearraysizeexception();
4480 ba = builtin_newarray_boolean(len);
4482 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4486 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4490 STATISTICS(jniinvokation());
4493 exceptions_throw_negativearraysizeexception();
4497 ba = builtin_newarray_byte(len);
4499 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4503 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4507 STATISTICS(jniinvokation());
4510 exceptions_throw_negativearraysizeexception();
4514 ca = builtin_newarray_char(len);
4516 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4520 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4522 java_shortarray *sa;
4524 STATISTICS(jniinvokation());
4527 exceptions_throw_negativearraysizeexception();
4531 sa = builtin_newarray_short(len);
4533 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4537 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4541 STATISTICS(jniinvokation());
4544 exceptions_throw_negativearraysizeexception();
4548 ia = builtin_newarray_int(len);
4550 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4554 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4558 STATISTICS(jniinvokation());
4561 exceptions_throw_negativearraysizeexception();
4565 la = builtin_newarray_long(len);
4567 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4571 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4573 java_floatarray *fa;
4575 STATISTICS(jniinvokation());
4578 exceptions_throw_negativearraysizeexception();
4582 fa = builtin_newarray_float(len);
4584 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4588 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4590 java_doublearray *da;
4592 STATISTICS(jniinvokation());
4595 exceptions_throw_negativearraysizeexception();
4599 da = builtin_newarray_double(len);
4601 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4605 /* Get<PrimitiveType>ArrayElements *********************************************
4607 A family of functions that returns the body of the primitive array.
4609 *******************************************************************************/
4611 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4614 java_booleanarray *ba;
4616 STATISTICS(jniinvokation());
4618 ba = (java_booleanarray *) array;
4621 *isCopy = JNI_FALSE;
4627 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4632 STATISTICS(jniinvokation());
4634 ba = (java_bytearray *) array;
4637 *isCopy = JNI_FALSE;
4643 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4648 STATISTICS(jniinvokation());
4650 ca = (java_chararray *) array;
4653 *isCopy = JNI_FALSE;
4659 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4662 java_shortarray *sa;
4664 STATISTICS(jniinvokation());
4666 sa = (java_shortarray *) array;
4669 *isCopy = JNI_FALSE;
4675 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4680 STATISTICS(jniinvokation());
4682 ia = (java_intarray *) array;
4685 *isCopy = JNI_FALSE;
4691 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4696 STATISTICS(jniinvokation());
4698 la = (java_longarray *) array;
4701 *isCopy = JNI_FALSE;
4703 /* We cast this one to prevent a compiler warning on 64-bit
4704 systems since GNU Classpath typedef jlong to long long. */
4706 return (jlong *) la->data;
4710 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4713 java_floatarray *fa;
4715 STATISTICS(jniinvokation());
4717 fa = (java_floatarray *) array;
4720 *isCopy = JNI_FALSE;
4726 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4729 java_doublearray *da;
4731 STATISTICS(jniinvokation());
4733 da = (java_doublearray *) array;
4736 *isCopy = JNI_FALSE;
4742 /* Release<PrimitiveType>ArrayElements *****************************************
4744 A family of functions that informs the VM that the native code no
4745 longer needs access to elems. The elems argument is a pointer
4746 derived from array using the corresponding
4747 Get<PrimitiveType>ArrayElements() function. If necessary, this
4748 function copies back all changes made to elems to the original
4751 *******************************************************************************/
4753 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4754 jboolean *elems, jint mode)
4756 java_booleanarray *ba;
4758 STATISTICS(jniinvokation());
4760 ba = (java_booleanarray *) array;
4762 if (elems != ba->data) {
4765 MCOPY(ba->data, elems, u1, ba->header.size);
4768 MCOPY(ba->data, elems, u1, ba->header.size);
4769 /* XXX TWISTI how should it be freed? */
4772 /* XXX TWISTI how should it be freed? */
4779 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4780 jbyte *elems, jint mode)
4784 STATISTICS(jniinvokation());
4786 ba = (java_bytearray *) array;
4788 if (elems != ba->data) {
4791 MCOPY(ba->data, elems, s1, ba->header.size);
4794 MCOPY(ba->data, elems, s1, ba->header.size);
4795 /* XXX TWISTI how should it be freed? */
4798 /* XXX TWISTI how should it be freed? */
4805 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4806 jchar *elems, jint mode)
4810 STATISTICS(jniinvokation());
4812 ca = (java_chararray *) array;
4814 if (elems != ca->data) {
4817 MCOPY(ca->data, elems, u2, ca->header.size);
4820 MCOPY(ca->data, elems, u2, ca->header.size);
4821 /* XXX TWISTI how should it be freed? */
4824 /* XXX TWISTI how should it be freed? */
4831 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4832 jshort *elems, jint mode)
4834 java_shortarray *sa;
4836 STATISTICS(jniinvokation());
4838 sa = (java_shortarray *) array;
4840 if (elems != sa->data) {
4843 MCOPY(sa->data, elems, s2, sa->header.size);
4846 MCOPY(sa->data, elems, s2, sa->header.size);
4847 /* XXX TWISTI how should it be freed? */
4850 /* XXX TWISTI how should it be freed? */
4857 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4862 STATISTICS(jniinvokation());
4864 ia = (java_intarray *) array;
4866 if (elems != ia->data) {
4869 MCOPY(ia->data, elems, s4, ia->header.size);
4872 MCOPY(ia->data, elems, s4, ia->header.size);
4873 /* XXX TWISTI how should it be freed? */
4876 /* XXX TWISTI how should it be freed? */
4883 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4884 jlong *elems, jint mode)
4888 STATISTICS(jniinvokation());
4890 la = (java_longarray *) array;
4892 /* We cast this one to prevent a compiler warning on 64-bit
4893 systems since GNU Classpath typedef jlong to long long. */
4895 if ((s8 *) elems != la->data) {
4898 MCOPY(la->data, elems, s8, la->header.size);
4901 MCOPY(la->data, elems, s8, la->header.size);
4902 /* XXX TWISTI how should it be freed? */
4905 /* XXX TWISTI how should it be freed? */
4912 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4913 jfloat *elems, jint mode)
4915 java_floatarray *fa;
4917 STATISTICS(jniinvokation());
4919 fa = (java_floatarray *) array;
4921 if (elems != fa->data) {
4924 MCOPY(fa->data, elems, float, fa->header.size);
4927 MCOPY(fa->data, elems, float, fa->header.size);
4928 /* XXX TWISTI how should it be freed? */
4931 /* XXX TWISTI how should it be freed? */
4938 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4939 jdouble *elems, jint mode)
4941 java_doublearray *da;
4943 STATISTICS(jniinvokation());
4945 da = (java_doublearray *) array;
4947 if (elems != da->data) {
4950 MCOPY(da->data, elems, double, da->header.size);
4953 MCOPY(da->data, elems, double, da->header.size);
4954 /* XXX TWISTI how should it be freed? */
4957 /* XXX TWISTI how should it be freed? */
4964 /* Get<PrimitiveType>ArrayRegion **********************************************
4966 A family of functions that copies a region of a primitive array
4969 *******************************************************************************/
4971 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4972 jsize start, jsize len, jboolean *buf)
4974 java_booleanarray *ba;
4976 STATISTICS(jniinvokation());
4978 ba = (java_booleanarray *) array;
4980 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4981 exceptions_throw_arrayindexoutofboundsexception();
4983 MCOPY(buf, &ba->data[start], u1, len);
4987 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4988 jsize len, jbyte *buf)
4992 STATISTICS(jniinvokation());
4994 ba = (java_bytearray *) array;
4996 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4997 exceptions_throw_arrayindexoutofboundsexception();
4999 MCOPY(buf, &ba->data[start], s1, len);
5003 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5004 jsize len, jchar *buf)
5008 STATISTICS(jniinvokation());
5010 ca = (java_chararray *) array;
5012 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5013 exceptions_throw_arrayindexoutofboundsexception();
5015 MCOPY(buf, &ca->data[start], u2, len);
5019 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5020 jsize len, jshort *buf)
5022 java_shortarray *sa;
5024 STATISTICS(jniinvokation());
5026 sa = (java_shortarray *) array;
5028 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5029 exceptions_throw_arrayindexoutofboundsexception();
5031 MCOPY(buf, &sa->data[start], s2, len);
5035 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5036 jsize len, jint *buf)
5040 STATISTICS(jniinvokation());
5042 ia = (java_intarray *) array;
5044 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5045 exceptions_throw_arrayindexoutofboundsexception();
5047 MCOPY(buf, &ia->data[start], s4, len);
5051 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
5052 jsize len, jlong *buf)
5056 STATISTICS(jniinvokation());
5058 la = (java_longarray *) array;
5060 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5061 exceptions_throw_arrayindexoutofboundsexception();
5063 MCOPY(buf, &la->data[start], s8, len);
5067 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5068 jsize len, jfloat *buf)
5070 java_floatarray *fa;
5072 STATISTICS(jniinvokation());
5074 fa = (java_floatarray *) array;
5076 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5077 exceptions_throw_arrayindexoutofboundsexception();
5079 MCOPY(buf, &fa->data[start], float, len);
5083 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5084 jsize len, jdouble *buf)
5086 java_doublearray *da;
5088 STATISTICS(jniinvokation());
5090 da = (java_doublearray *) array;
5092 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5093 exceptions_throw_arrayindexoutofboundsexception();
5095 MCOPY(buf, &da->data[start], double, len);
5099 /* Set<PrimitiveType>ArrayRegion **********************************************
5101 A family of functions that copies back a region of a primitive
5102 array from a buffer.
5104 *******************************************************************************/
5106 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5107 jsize start, jsize len, jboolean *buf)
5109 java_booleanarray *ba;
5111 STATISTICS(jniinvokation());
5113 ba = (java_booleanarray *) array;
5115 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5116 exceptions_throw_arrayindexoutofboundsexception();
5118 MCOPY(&ba->data[start], buf, u1, len);
5122 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5123 jsize len, jbyte *buf)
5127 STATISTICS(jniinvokation());
5129 ba = (java_bytearray *) array;
5131 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5132 exceptions_throw_arrayindexoutofboundsexception();
5134 MCOPY(&ba->data[start], buf, s1, len);
5138 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5139 jsize len, jchar *buf)
5143 STATISTICS(jniinvokation());
5145 ca = (java_chararray *) array;
5147 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5148 exceptions_throw_arrayindexoutofboundsexception();
5150 MCOPY(&ca->data[start], buf, u2, len);
5154 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5155 jsize len, jshort *buf)
5157 java_shortarray *sa;
5159 STATISTICS(jniinvokation());
5161 sa = (java_shortarray *) array;
5163 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5164 exceptions_throw_arrayindexoutofboundsexception();
5166 MCOPY(&sa->data[start], buf, s2, len);
5170 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5171 jsize len, jint *buf)
5175 STATISTICS(jniinvokation());
5177 ia = (java_intarray *) array;
5179 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5180 exceptions_throw_arrayindexoutofboundsexception();
5182 MCOPY(&ia->data[start], buf, s4, len);
5186 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5187 jsize len, jlong *buf)
5191 STATISTICS(jniinvokation());
5193 la = (java_longarray *) array;
5195 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5196 exceptions_throw_arrayindexoutofboundsexception();
5198 MCOPY(&la->data[start], buf, s8, len);
5202 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5203 jsize len, jfloat *buf)
5205 java_floatarray *fa;
5207 STATISTICS(jniinvokation());
5209 fa = (java_floatarray *) array;
5211 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5212 exceptions_throw_arrayindexoutofboundsexception();
5214 MCOPY(&fa->data[start], buf, float, len);
5218 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5219 jsize len, jdouble *buf)
5221 java_doublearray *da;
5223 STATISTICS(jniinvokation());
5225 da = (java_doublearray *) array;
5227 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5228 exceptions_throw_arrayindexoutofboundsexception();
5230 MCOPY(&da->data[start], buf, double, len);
5234 /* Registering Native Methods *************************************************/
5236 /* RegisterNatives *************************************************************
5238 Registers native methods with the class specified by the clazz
5239 argument. The methods parameter specifies an array of
5240 JNINativeMethod structures that contain the names, signatures, and
5241 function pointers of the native methods. The nMethods parameter
5242 specifies the number of native methods in the array.
5244 *******************************************************************************/
5246 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5247 const JNINativeMethod *methods, jint nMethods)
5249 STATISTICS(jniinvokation());
5251 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5252 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5253 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5260 /* UnregisterNatives ***********************************************************
5262 Unregisters native methods of a class. The class goes back to the
5263 state before it was linked or registered with its native method
5266 This function should not be used in normal native code. Instead, it
5267 provides special programs a way to reload and relink native
5270 *******************************************************************************/
5272 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5274 STATISTICS(jniinvokation());
5276 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5278 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5284 /* Monitor Operations *********************************************************/
5286 /* MonitorEnter ****************************************************************
5288 Enters the monitor associated with the underlying Java object
5291 *******************************************************************************/
5293 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5295 STATISTICS(jniinvokation());
5298 exceptions_throw_nullpointerexception();
5302 LOCK_MONITOR_ENTER(obj);
5308 /* MonitorExit *****************************************************************
5310 The current thread must be the owner of the monitor associated with
5311 the underlying Java object referred to by obj. The thread
5312 decrements the counter indicating the number of times it has
5313 entered this monitor. If the value of the counter becomes zero, the
5314 current thread releases the monitor.
5316 *******************************************************************************/
5318 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5320 STATISTICS(jniinvokation());
5323 exceptions_throw_nullpointerexception();
5327 LOCK_MONITOR_EXIT(obj);
5333 /* JavaVM Interface ***********************************************************/
5335 /* GetJavaVM *******************************************************************
5337 Returns the Java VM interface (used in the Invocation API)
5338 associated with the current thread. The result is placed at the
5339 location pointed to by the second argument, vm.
5341 *******************************************************************************/
5343 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5345 STATISTICS(jniinvokation());
5347 *vm = (JavaVM *) _Jv_jvm;
5353 /* GetStringRegion *************************************************************
5355 Copies len number of Unicode characters beginning at offset start
5356 to the given buffer buf.
5358 Throws StringIndexOutOfBoundsException on index overflow.
5360 *******************************************************************************/
5362 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5365 java_lang_String *s;
5368 STATISTICS(jniinvokation());
5370 s = (java_lang_String *) str;
5373 if ((start < 0) || (len < 0) || (start > s->count) ||
5374 (start + len > s->count)) {
5375 exceptions_throw_stringindexoutofboundsexception();
5379 MCOPY(buf, &ca->data[start], u2, len);
5383 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5384 jsize len, char *buf)
5386 STATISTICS(jniinvokation());
5388 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5392 /* GetPrimitiveArrayCritical ***************************************************
5394 Obtain a direct pointer to array elements.
5396 *******************************************************************************/
5398 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5404 ba = (java_bytearray *) array;
5406 /* do the same as Kaffe does */
5408 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5414 /* ReleasePrimitiveArrayCritical ***********************************************
5416 No specific documentation.
5418 *******************************************************************************/
5420 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5421 void *carray, jint mode)
5423 STATISTICS(jniinvokation());
5425 /* do the same as Kaffe does */
5427 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5432 /* GetStringCritical ***********************************************************
5434 The semantics of these two functions are similar to the existing
5435 Get/ReleaseStringChars functions.
5437 *******************************************************************************/
5439 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5442 STATISTICS(jniinvokation());
5444 return _Jv_JNI_GetStringChars(env, string, isCopy);
5448 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5449 const jchar *cstring)
5451 STATISTICS(jniinvokation());
5453 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5457 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5459 STATISTICS(jniinvokation());
5461 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5467 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5469 STATISTICS(jniinvokation());
5471 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5475 /* NewGlobalRef ****************************************************************
5477 Creates a new global reference to the object referred to by the obj
5480 *******************************************************************************/
5482 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5484 hashtable_global_ref_entry *gre;
5485 u4 key; /* hashkey */
5486 u4 slot; /* slot in hashtable */
5488 STATISTICS(jniinvokation());
5490 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5492 /* normally addresses are aligned to 4, 8 or 16 bytes */
5494 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5495 slot = key & (hashtable_global_ref->size - 1);
5496 gre = hashtable_global_ref->ptr[slot];
5498 /* search external hash chain for the entry */
5501 if (gre->o == obj) {
5502 /* global object found, increment the reference */
5506 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5511 gre = gre->hashlink; /* next element in external chain */
5514 /* global ref not found, create a new one */
5516 gre = NEW(hashtable_global_ref_entry);
5521 /* insert entry into hashtable */
5523 gre->hashlink = hashtable_global_ref->ptr[slot];
5525 hashtable_global_ref->ptr[slot] = gre;
5527 /* update number of hashtable-entries */
5529 hashtable_global_ref->entries++;
5531 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5537 /* DeleteGlobalRef *************************************************************
5539 Deletes the global reference pointed to by globalRef.
5541 *******************************************************************************/
5543 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5545 hashtable_global_ref_entry *gre;
5546 hashtable_global_ref_entry *prevgre;
5547 u4 key; /* hashkey */
5548 u4 slot; /* slot in hashtable */
5550 STATISTICS(jniinvokation());
5552 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5554 /* normally addresses are aligned to 4, 8 or 16 bytes */
5556 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5557 slot = key & (hashtable_global_ref->size - 1);
5558 gre = hashtable_global_ref->ptr[slot];
5560 /* initialize prevgre */
5564 /* search external hash chain for the entry */
5567 if (gre->o == globalRef) {
5568 /* global object found, decrement the reference count */
5572 /* if reference count is 0, remove the entry */
5574 if (gre->refs == 0) {
5575 /* special handling if it's the first in the chain */
5577 if (prevgre == NULL)
5578 hashtable_global_ref->ptr[slot] = gre->hashlink;
5580 prevgre->hashlink = gre->hashlink;
5582 FREE(gre, hashtable_global_ref_entry);
5585 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5590 prevgre = gre; /* save current pointer for removal */
5591 gre = gre->hashlink; /* next element in external chain */
5594 log_println("JNI-DeleteGlobalRef: global reference not found");
5596 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5600 /* ExceptionCheck **************************************************************
5602 Returns JNI_TRUE when there is a pending exception; otherwise,
5605 *******************************************************************************/
5607 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5609 java_objectheader *o;
5611 STATISTICS(jniinvokation());
5613 o = exceptions_get_exception();
5615 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5619 /* New JNI 1.4 functions ******************************************************/
5621 /* NewDirectByteBuffer *********************************************************
5623 Allocates and returns a direct java.nio.ByteBuffer referring to the
5624 block of memory starting at the memory address address and
5625 extending capacity bytes.
5627 *******************************************************************************/
5629 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5631 #if defined(ENABLE_JAVASE)
5632 java_objectheader *nbuf;
5633 # if SIZEOF_VOID_P == 8
5634 gnu_classpath_Pointer64 *paddress;
5636 gnu_classpath_Pointer32 *paddress;
5639 STATISTICS(jniinvokation());
5641 /* alocate a gnu.classpath.Pointer{32,64} object */
5643 # if SIZEOF_VOID_P == 8
5644 if (!(paddress = (gnu_classpath_Pointer64 *)
5645 builtin_new(class_gnu_classpath_Pointer64)))
5647 if (!(paddress = (gnu_classpath_Pointer32 *)
5648 builtin_new(class_gnu_classpath_Pointer32)))
5652 /* fill gnu.classpath.Pointer{32,64} with address */
5654 paddress->data = (ptrint) address;
5656 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5658 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5659 (jmethodID) dbbirw_init, NULL, paddress,
5660 (jint) capacity, (jint) capacity, (jint) 0);
5662 /* add local reference and return the value */
5664 return _Jv_JNI_NewLocalRef(env, nbuf);
5666 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5668 /* keep compiler happy */
5675 /* GetDirectBufferAddress ******************************************************
5677 Fetches and returns the starting address of the memory region
5678 referenced by the given direct java.nio.Buffer.
5680 *******************************************************************************/
5682 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5684 #if defined(ENABLE_JAVASE)
5685 java_nio_DirectByteBufferImpl *nbuf;
5686 # if SIZEOF_VOID_P == 8
5687 gnu_classpath_Pointer64 *address;
5689 gnu_classpath_Pointer32 *address;
5692 STATISTICS(jniinvokation());
5694 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5697 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5699 # if SIZEOF_VOID_P == 8
5700 address = (gnu_classpath_Pointer64 *) nbuf->address;
5702 address = (gnu_classpath_Pointer32 *) nbuf->address;
5705 if (address == NULL)
5708 return (void *) address->data;
5710 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5712 /* keep compiler happy */
5719 /* GetDirectBufferCapacity *****************************************************
5721 Fetches and returns the capacity in bytes of the memory region
5722 referenced by the given direct java.nio.Buffer.
5724 *******************************************************************************/
5726 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5728 #if defined(ENABLE_JAVASE)
5729 java_nio_Buffer *nbuf;
5731 STATISTICS(jniinvokation());
5733 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5736 nbuf = (java_nio_Buffer *) buf;
5738 return (jlong) nbuf->cap;
5740 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5742 /* keep compiler happy */
5749 /* DestroyJavaVM ***************************************************************
5751 Unloads a Java VM and reclaims its resources. Only the main thread
5752 can unload the VM. The system waits until the main thread is only
5753 remaining user thread before it destroys the VM.
5755 *******************************************************************************/
5757 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5761 STATISTICS(jniinvokation());
5763 status = vm_destroy(vm);
5769 /* AttachCurrentThread *********************************************************
5771 Attaches the current thread to a Java VM. Returns a JNI interface
5772 pointer in the JNIEnv argument.
5774 Trying to attach a thread that is already attached is a no-op.
5776 A native thread cannot be attached simultaneously to two Java VMs.
5778 When a thread is attached to the VM, the context class loader is
5779 the bootstrap loader.
5781 *******************************************************************************/
5783 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5785 JavaVMAttachArgs *vm_aargs;
5787 #if defined(ENABLE_THREADS)
5788 if (threads_get_current_threadobject() == NULL) {
5789 vm_aargs = (JavaVMAttachArgs *) thr_args;
5791 if (vm_aargs != NULL) {
5792 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5793 (vm_aargs->version != JNI_VERSION_1_4))
5794 return JNI_EVERSION;
5797 if (!threads_attach_current_thread(vm_aargs, false))
5800 if (!jni_init_localref_table())
5811 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5813 STATISTICS(jniinvokation());
5815 return jni_attach_current_thread(p_env, thr_args, false);
5819 /* DetachCurrentThread *********************************************************
5821 Detaches the current thread from a Java VM. All Java monitors held
5822 by this thread are released. All Java threads waiting for this
5823 thread to die are notified.
5825 In JDK 1.1, the main thread cannot be detached from the VM. It must
5826 call DestroyJavaVM to unload the entire VM.
5828 In the JDK, the main thread can be detached from the VM.
5830 The main thread, which is the thread that created the Java VM,
5831 cannot be detached from the VM. Instead, the main thread must call
5832 JNI_DestroyJavaVM() to unload the entire VM.
5834 *******************************************************************************/
5836 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5838 #if defined(ENABLE_THREADS)
5839 threadobject *thread;
5841 STATISTICS(jniinvokation());
5843 thread = threads_get_current_threadobject();
5848 if (!threads_detach_thread(thread))
5856 /* GetEnv **********************************************************************
5858 If the current thread is not attached to the VM, sets *env to NULL,
5859 and returns JNI_EDETACHED. If the specified version is not
5860 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5861 sets *env to the appropriate interface, and returns JNI_OK.
5863 *******************************************************************************/
5865 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5867 STATISTICS(jniinvokation());
5869 #if defined(ENABLE_THREADS)
5870 if (threads_get_current_threadobject() == NULL) {
5873 return JNI_EDETACHED;
5877 /* check the JNI version */
5880 case JNI_VERSION_1_1:
5881 case JNI_VERSION_1_2:
5882 case JNI_VERSION_1_4:
5890 #if defined(ENABLE_JVMTI)
5891 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5892 == JVMTI_VERSION_INTERFACE_JVMTI) {
5894 *env = (void *) jvmti_new_environment();
5903 return JNI_EVERSION;
5907 /* AttachCurrentThreadAsDaemon *************************************************
5909 Same semantics as AttachCurrentThread, but the newly-created
5910 java.lang.Thread instance is a daemon.
5912 If the thread has already been attached via either
5913 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5914 simply sets the value pointed to by penv to the JNIEnv of the
5915 current thread. In this case neither AttachCurrentThread nor this
5916 routine have any effect on the daemon status of the thread.
5918 *******************************************************************************/
5920 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5922 STATISTICS(jniinvokation());
5924 return jni_attach_current_thread(penv, args, true);
5928 /* JNI invocation table *******************************************************/
5930 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5935 _Jv_JNI_DestroyJavaVM,
5936 _Jv_JNI_AttachCurrentThread,
5937 _Jv_JNI_DetachCurrentThread,
5939 _Jv_JNI_AttachCurrentThreadAsDaemon
5943 /* JNI function table *********************************************************/
5945 struct JNINativeInterface _Jv_JNINativeInterface = {
5952 _Jv_JNI_DefineClass,
5954 _Jv_JNI_FromReflectedMethod,
5955 _Jv_JNI_FromReflectedField,
5956 _Jv_JNI_ToReflectedMethod,
5957 _Jv_JNI_GetSuperclass,
5958 _Jv_JNI_IsAssignableFrom,
5959 _Jv_JNI_ToReflectedField,
5963 _Jv_JNI_ExceptionOccurred,
5964 _Jv_JNI_ExceptionDescribe,
5965 _Jv_JNI_ExceptionClear,
5967 _Jv_JNI_PushLocalFrame,
5968 _Jv_JNI_PopLocalFrame,
5970 _Jv_JNI_NewGlobalRef,
5971 _Jv_JNI_DeleteGlobalRef,
5972 _Jv_JNI_DeleteLocalRef,
5973 _Jv_JNI_IsSameObject,
5974 _Jv_JNI_NewLocalRef,
5975 _Jv_JNI_EnsureLocalCapacity,
5977 _Jv_JNI_AllocObject,
5982 _Jv_JNI_GetObjectClass,
5983 _Jv_JNI_IsInstanceOf,
5985 _Jv_JNI_GetMethodID,
5987 _Jv_JNI_CallObjectMethod,
5988 _Jv_JNI_CallObjectMethodV,
5989 _Jv_JNI_CallObjectMethodA,
5990 _Jv_JNI_CallBooleanMethod,
5991 _Jv_JNI_CallBooleanMethodV,
5992 _Jv_JNI_CallBooleanMethodA,
5993 _Jv_JNI_CallByteMethod,
5994 _Jv_JNI_CallByteMethodV,
5995 _Jv_JNI_CallByteMethodA,
5996 _Jv_JNI_CallCharMethod,
5997 _Jv_JNI_CallCharMethodV,
5998 _Jv_JNI_CallCharMethodA,
5999 _Jv_JNI_CallShortMethod,
6000 _Jv_JNI_CallShortMethodV,
6001 _Jv_JNI_CallShortMethodA,
6002 _Jv_JNI_CallIntMethod,
6003 _Jv_JNI_CallIntMethodV,
6004 _Jv_JNI_CallIntMethodA,
6005 _Jv_JNI_CallLongMethod,
6006 _Jv_JNI_CallLongMethodV,
6007 _Jv_JNI_CallLongMethodA,
6008 _Jv_JNI_CallFloatMethod,
6009 _Jv_JNI_CallFloatMethodV,
6010 _Jv_JNI_CallFloatMethodA,
6011 _Jv_JNI_CallDoubleMethod,
6012 _Jv_JNI_CallDoubleMethodV,
6013 _Jv_JNI_CallDoubleMethodA,
6014 _Jv_JNI_CallVoidMethod,
6015 _Jv_JNI_CallVoidMethodV,
6016 _Jv_JNI_CallVoidMethodA,
6018 _Jv_JNI_CallNonvirtualObjectMethod,
6019 _Jv_JNI_CallNonvirtualObjectMethodV,
6020 _Jv_JNI_CallNonvirtualObjectMethodA,
6021 _Jv_JNI_CallNonvirtualBooleanMethod,
6022 _Jv_JNI_CallNonvirtualBooleanMethodV,
6023 _Jv_JNI_CallNonvirtualBooleanMethodA,
6024 _Jv_JNI_CallNonvirtualByteMethod,
6025 _Jv_JNI_CallNonvirtualByteMethodV,
6026 _Jv_JNI_CallNonvirtualByteMethodA,
6027 _Jv_JNI_CallNonvirtualCharMethod,
6028 _Jv_JNI_CallNonvirtualCharMethodV,
6029 _Jv_JNI_CallNonvirtualCharMethodA,
6030 _Jv_JNI_CallNonvirtualShortMethod,
6031 _Jv_JNI_CallNonvirtualShortMethodV,
6032 _Jv_JNI_CallNonvirtualShortMethodA,
6033 _Jv_JNI_CallNonvirtualIntMethod,
6034 _Jv_JNI_CallNonvirtualIntMethodV,
6035 _Jv_JNI_CallNonvirtualIntMethodA,
6036 _Jv_JNI_CallNonvirtualLongMethod,
6037 _Jv_JNI_CallNonvirtualLongMethodV,
6038 _Jv_JNI_CallNonvirtualLongMethodA,
6039 _Jv_JNI_CallNonvirtualFloatMethod,
6040 _Jv_JNI_CallNonvirtualFloatMethodV,
6041 _Jv_JNI_CallNonvirtualFloatMethodA,
6042 _Jv_JNI_CallNonvirtualDoubleMethod,
6043 _Jv_JNI_CallNonvirtualDoubleMethodV,
6044 _Jv_JNI_CallNonvirtualDoubleMethodA,
6045 _Jv_JNI_CallNonvirtualVoidMethod,
6046 _Jv_JNI_CallNonvirtualVoidMethodV,
6047 _Jv_JNI_CallNonvirtualVoidMethodA,
6051 _Jv_JNI_GetObjectField,
6052 _Jv_JNI_GetBooleanField,
6053 _Jv_JNI_GetByteField,
6054 _Jv_JNI_GetCharField,
6055 _Jv_JNI_GetShortField,
6056 _Jv_JNI_GetIntField,
6057 _Jv_JNI_GetLongField,
6058 _Jv_JNI_GetFloatField,
6059 _Jv_JNI_GetDoubleField,
6060 _Jv_JNI_SetObjectField,
6061 _Jv_JNI_SetBooleanField,
6062 _Jv_JNI_SetByteField,
6063 _Jv_JNI_SetCharField,
6064 _Jv_JNI_SetShortField,
6065 _Jv_JNI_SetIntField,
6066 _Jv_JNI_SetLongField,
6067 _Jv_JNI_SetFloatField,
6068 _Jv_JNI_SetDoubleField,
6070 _Jv_JNI_GetStaticMethodID,
6072 _Jv_JNI_CallStaticObjectMethod,
6073 _Jv_JNI_CallStaticObjectMethodV,
6074 _Jv_JNI_CallStaticObjectMethodA,
6075 _Jv_JNI_CallStaticBooleanMethod,
6076 _Jv_JNI_CallStaticBooleanMethodV,
6077 _Jv_JNI_CallStaticBooleanMethodA,
6078 _Jv_JNI_CallStaticByteMethod,
6079 _Jv_JNI_CallStaticByteMethodV,
6080 _Jv_JNI_CallStaticByteMethodA,
6081 _Jv_JNI_CallStaticCharMethod,
6082 _Jv_JNI_CallStaticCharMethodV,
6083 _Jv_JNI_CallStaticCharMethodA,
6084 _Jv_JNI_CallStaticShortMethod,
6085 _Jv_JNI_CallStaticShortMethodV,
6086 _Jv_JNI_CallStaticShortMethodA,
6087 _Jv_JNI_CallStaticIntMethod,
6088 _Jv_JNI_CallStaticIntMethodV,
6089 _Jv_JNI_CallStaticIntMethodA,
6090 _Jv_JNI_CallStaticLongMethod,
6091 _Jv_JNI_CallStaticLongMethodV,
6092 _Jv_JNI_CallStaticLongMethodA,
6093 _Jv_JNI_CallStaticFloatMethod,
6094 _Jv_JNI_CallStaticFloatMethodV,
6095 _Jv_JNI_CallStaticFloatMethodA,
6096 _Jv_JNI_CallStaticDoubleMethod,
6097 _Jv_JNI_CallStaticDoubleMethodV,
6098 _Jv_JNI_CallStaticDoubleMethodA,
6099 _Jv_JNI_CallStaticVoidMethod,
6100 _Jv_JNI_CallStaticVoidMethodV,
6101 _Jv_JNI_CallStaticVoidMethodA,
6103 _Jv_JNI_GetStaticFieldID,
6105 _Jv_JNI_GetStaticObjectField,
6106 _Jv_JNI_GetStaticBooleanField,
6107 _Jv_JNI_GetStaticByteField,
6108 _Jv_JNI_GetStaticCharField,
6109 _Jv_JNI_GetStaticShortField,
6110 _Jv_JNI_GetStaticIntField,
6111 _Jv_JNI_GetStaticLongField,
6112 _Jv_JNI_GetStaticFloatField,
6113 _Jv_JNI_GetStaticDoubleField,
6114 _Jv_JNI_SetStaticObjectField,
6115 _Jv_JNI_SetStaticBooleanField,
6116 _Jv_JNI_SetStaticByteField,
6117 _Jv_JNI_SetStaticCharField,
6118 _Jv_JNI_SetStaticShortField,
6119 _Jv_JNI_SetStaticIntField,
6120 _Jv_JNI_SetStaticLongField,
6121 _Jv_JNI_SetStaticFloatField,
6122 _Jv_JNI_SetStaticDoubleField,
6125 _Jv_JNI_GetStringLength,
6126 _Jv_JNI_GetStringChars,
6127 _Jv_JNI_ReleaseStringChars,
6129 _Jv_JNI_NewStringUTF,
6130 _Jv_JNI_GetStringUTFLength,
6131 _Jv_JNI_GetStringUTFChars,
6132 _Jv_JNI_ReleaseStringUTFChars,
6134 _Jv_JNI_GetArrayLength,
6136 _Jv_JNI_NewObjectArray,
6137 _Jv_JNI_GetObjectArrayElement,
6138 _Jv_JNI_SetObjectArrayElement,
6140 _Jv_JNI_NewBooleanArray,
6141 _Jv_JNI_NewByteArray,
6142 _Jv_JNI_NewCharArray,
6143 _Jv_JNI_NewShortArray,
6144 _Jv_JNI_NewIntArray,
6145 _Jv_JNI_NewLongArray,
6146 _Jv_JNI_NewFloatArray,
6147 _Jv_JNI_NewDoubleArray,
6149 _Jv_JNI_GetBooleanArrayElements,
6150 _Jv_JNI_GetByteArrayElements,
6151 _Jv_JNI_GetCharArrayElements,
6152 _Jv_JNI_GetShortArrayElements,
6153 _Jv_JNI_GetIntArrayElements,
6154 _Jv_JNI_GetLongArrayElements,
6155 _Jv_JNI_GetFloatArrayElements,
6156 _Jv_JNI_GetDoubleArrayElements,
6158 _Jv_JNI_ReleaseBooleanArrayElements,
6159 _Jv_JNI_ReleaseByteArrayElements,
6160 _Jv_JNI_ReleaseCharArrayElements,
6161 _Jv_JNI_ReleaseShortArrayElements,
6162 _Jv_JNI_ReleaseIntArrayElements,
6163 _Jv_JNI_ReleaseLongArrayElements,
6164 _Jv_JNI_ReleaseFloatArrayElements,
6165 _Jv_JNI_ReleaseDoubleArrayElements,
6167 _Jv_JNI_GetBooleanArrayRegion,
6168 _Jv_JNI_GetByteArrayRegion,
6169 _Jv_JNI_GetCharArrayRegion,
6170 _Jv_JNI_GetShortArrayRegion,
6171 _Jv_JNI_GetIntArrayRegion,
6172 _Jv_JNI_GetLongArrayRegion,
6173 _Jv_JNI_GetFloatArrayRegion,
6174 _Jv_JNI_GetDoubleArrayRegion,
6175 _Jv_JNI_SetBooleanArrayRegion,
6176 _Jv_JNI_SetByteArrayRegion,
6177 _Jv_JNI_SetCharArrayRegion,
6178 _Jv_JNI_SetShortArrayRegion,
6179 _Jv_JNI_SetIntArrayRegion,
6180 _Jv_JNI_SetLongArrayRegion,
6181 _Jv_JNI_SetFloatArrayRegion,
6182 _Jv_JNI_SetDoubleArrayRegion,
6184 _Jv_JNI_RegisterNatives,
6185 _Jv_JNI_UnregisterNatives,
6187 _Jv_JNI_MonitorEnter,
6188 _Jv_JNI_MonitorExit,
6192 /* new JNI 1.2 functions */
6194 _Jv_JNI_GetStringRegion,
6195 _Jv_JNI_GetStringUTFRegion,
6197 _Jv_JNI_GetPrimitiveArrayCritical,
6198 _Jv_JNI_ReleasePrimitiveArrayCritical,
6200 _Jv_JNI_GetStringCritical,
6201 _Jv_JNI_ReleaseStringCritical,
6203 _Jv_JNI_NewWeakGlobalRef,
6204 _Jv_JNI_DeleteWeakGlobalRef,
6206 _Jv_JNI_ExceptionCheck,
6208 /* new JNI 1.4 functions */
6210 _Jv_JNI_NewDirectByteBuffer,
6211 _Jv_JNI_GetDirectBufferAddress,
6212 _Jv_JNI_GetDirectBufferCapacity
6216 /* Invocation API Functions ***************************************************/
6218 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6220 Returns a default configuration for the Java VM.
6222 *******************************************************************************/
6224 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6226 JavaVMInitArgs *_vm_args;
6228 _vm_args = (JavaVMInitArgs *) vm_args;
6230 /* GNU classpath currently supports JNI 1.2 */
6232 switch (_vm_args->version) {
6233 case JNI_VERSION_1_1:
6234 _vm_args->version = JNI_VERSION_1_1;
6237 case JNI_VERSION_1_2:
6238 case JNI_VERSION_1_4:
6239 _vm_args->ignoreUnrecognized = JNI_FALSE;
6240 _vm_args->options = NULL;
6241 _vm_args->nOptions = 0;
6252 /* JNI_GetCreatedJavaVMs *******************************************************
6254 Returns all Java VMs that have been created. Pointers to VMs are written in
6255 the buffer vmBuf in the order they are created. At most bufLen number of
6256 entries will be written. The total number of created VMs is returned in
6259 *******************************************************************************/
6261 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6263 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6269 /* JNI_CreateJavaVM ************************************************************
6271 Loads and initializes a Java VM. The current thread becomes the main thread.
6272 Sets the env argument to the JNI interface pointer of the main thread.
6274 *******************************************************************************/
6276 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6278 /* actually create the JVM */
6280 if (!vm_createjvm(p_vm, p_env, vm_args))
6288 * These are local overrides for various environment variables in Emacs.
6289 * Please do not remove this and leave it at the end of the file, where
6290 * Emacs will automagically detect them.
6291 * ---------------------------------------------------------------------
6294 * indent-tabs-mode: t
6298 * vim:noexpandtab:sw=4:ts=4: