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 8070 2007-06-13 14:26:41Z twisti $
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
40 #include "native/jni.h"
41 #include "native/native.h"
43 #if defined(ENABLE_JAVASE)
44 # if defined(WITH_CLASSPATH_GNU)
45 # include "native/include/gnu_classpath_Pointer.h"
47 # if SIZEOF_VOID_P == 8
48 # include "native/include/gnu_classpath_Pointer64.h"
50 # include "native/include/gnu_classpath_Pointer32.h"
55 #include "native/include/java_lang_Object.h"
56 #include "native/include/java_lang_Byte.h"
57 #include "native/include/java_lang_Character.h"
58 #include "native/include/java_lang_Short.h"
59 #include "native/include/java_lang_Integer.h"
60 #include "native/include/java_lang_Boolean.h"
61 #include "native/include/java_lang_Long.h"
62 #include "native/include/java_lang_Float.h"
63 #include "native/include/java_lang_Double.h"
64 #include "native/include/java_lang_String.h"
65 #include "native/include/java_lang_Throwable.h"
67 #if defined(ENABLE_JAVASE)
68 # include "native/include/java_lang_ClassLoader.h"
70 # include "native/include/java_lang_reflect_Constructor.h"
71 # include "native/include/java_lang_reflect_Field.h"
72 # include "native/include/java_lang_reflect_Method.h"
74 # include "native/include/java_nio_Buffer.h"
75 # include "native/include/java_nio_DirectByteBufferImpl.h"
78 #if defined(ENABLE_JVMTI)
79 # include "native/jvmti/cacaodbg.h"
82 #include "native/vm/java_lang_Class.h"
84 #if defined(ENABLE_JAVASE)
85 # include "native/vm/java_lang_ClassLoader.h"
88 #include "threads/lock-common.h"
89 #include "threads/threads-common.h"
91 #include "toolbox/logging.h"
93 #include "vm/builtin.h"
94 #include "vm/exceptions.h"
95 #include "vm/global.h"
96 #include "vm/initialize.h"
97 #include "vm/resolve.h"
98 #include "vm/stringlocal.h"
101 #include "vm/jit/asmpart.h"
102 #include "vm/jit/jit.h"
103 #include "vm/jit/stacktrace.h"
105 #include "vmcore/loader.h"
106 #include "vmcore/options.h"
107 #include "vmcore/primitive.h"
108 #include "vmcore/statistics.h"
111 /* global variables ***********************************************************/
113 /* global reference table *****************************************************/
115 /* hashsize must be power of 2 */
117 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
119 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
122 /* direct buffer stuff ********************************************************/
124 #if defined(ENABLE_JAVASE)
125 static classinfo *class_java_nio_Buffer;
126 static classinfo *class_java_nio_DirectByteBufferImpl;
127 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
129 # if defined(WITH_CLASSPATH_GNU)
130 # if SIZEOF_VOID_P == 8
131 static classinfo *class_gnu_classpath_Pointer64;
133 static classinfo *class_gnu_classpath_Pointer32;
137 static methodinfo *dbbirw_init;
141 /* local reference table ******************************************************/
143 #if !defined(ENABLE_THREADS)
144 localref_table *_no_threads_localref_table;
148 /* accessing instance fields macros *******************************************/
150 #define SET_FIELD(o,type,f,value) \
151 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset)) = (type) (value)
153 #define GET_FIELD(o,type,f) \
154 *((type *) ((ptrint) (o) + (ptrint) ((fieldinfo *) (f))->offset))
157 /* some forward declarations **************************************************/
159 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
160 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
163 /* jni_init ********************************************************************
165 Initialize the JNI subsystem.
167 *******************************************************************************/
171 /* create global ref hashtable */
173 hashtable_global_ref = NEW(hashtable);
175 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
178 #if defined(ENABLE_JAVASE)
179 /* direct buffer stuff */
181 if (!(class_java_nio_Buffer =
182 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
183 !link_class(class_java_nio_Buffer))
186 if (!(class_java_nio_DirectByteBufferImpl =
187 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
188 !link_class(class_java_nio_DirectByteBufferImpl))
191 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
192 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
193 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
197 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
199 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
202 # if defined(WITH_CLASSPATH_GNU)
203 # if SIZEOF_VOID_P == 8
204 if (!(class_gnu_classpath_Pointer64 =
205 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
206 !link_class(class_gnu_classpath_Pointer64))
209 if (!(class_gnu_classpath_Pointer32 =
210 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
211 !link_class(class_gnu_classpath_Pointer32))
215 #endif /* defined(ENABLE_JAVASE) */
221 /* jni_init_localref_table *****************************************************
223 Initializes the local references table of the current thread.
225 *******************************************************************************/
227 bool jni_init_localref_table(void)
231 lrt = GCNEW(localref_table);
236 lrt->capacity = LOCALREFTABLE_CAPACITY;
238 lrt->localframes = 1;
239 lrt->prev = LOCALREFTABLE;
241 /* clear the references array (memset is faster then a for-loop) */
243 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
251 /* _Jv_jni_CallObjectMethod ****************************************************
253 Internal function to call Java Object methods.
255 *******************************************************************************/
257 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
259 methodinfo *m, va_list ap)
262 java_objectheader *ro;
264 STATISTICS(jniinvokation());
267 exceptions_throw_nullpointerexception();
271 /* Class initialization is done by the JIT compiler. This is ok
272 since a static method always belongs to the declaring class. */
274 if (m->flags & ACC_STATIC) {
275 /* For static methods we reset the object. */
280 /* for convenience */
285 /* For instance methods we make a virtual function table lookup. */
287 resm = method_vftbl_lookup(vftbl, m);
290 STATISTICS(jnicallXmethodnvokation());
292 ro = vm_call_method_valist(resm, o, ap);
298 /* _Jv_jni_CallObjectMethodA ***************************************************
300 Internal function to call Java Object methods.
302 *******************************************************************************/
304 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
306 methodinfo *m, jvalue *args)
309 java_objectheader *ro;
311 STATISTICS(jniinvokation());
314 exceptions_throw_nullpointerexception();
318 /* Class initialization is done by the JIT compiler. This is ok
319 since a static method always belongs to the declaring class. */
321 if (m->flags & ACC_STATIC) {
322 /* For static methods we reset the object. */
327 /* for convenience */
332 /* For instance methods we make a virtual function table lookup. */
334 resm = method_vftbl_lookup(vftbl, m);
337 STATISTICS(jnicallXmethodnvokation());
339 ro = vm_call_method_jvalue(resm, o, args);
345 /* _Jv_jni_CallIntMethod *******************************************************
347 Internal function to call Java integer class methods (boolean,
348 byte, char, short, int).
350 *******************************************************************************/
352 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
353 methodinfo *m, va_list ap)
358 STATISTICS(jniinvokation());
361 exceptions_throw_nullpointerexception();
365 /* Class initialization is done by the JIT compiler. This is ok
366 since a static method always belongs to the declaring class. */
368 if (m->flags & ACC_STATIC) {
369 /* For static methods we reset the object. */
374 /* for convenience */
379 /* For instance methods we make a virtual function table lookup. */
381 resm = method_vftbl_lookup(vftbl, m);
384 STATISTICS(jnicallXmethodnvokation());
386 i = vm_call_method_int_valist(resm, o, ap);
392 /* _Jv_jni_CallIntMethodA ******************************************************
394 Internal function to call Java integer class methods (boolean,
395 byte, char, short, int).
397 *******************************************************************************/
399 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
400 methodinfo *m, jvalue *args)
405 STATISTICS(jniinvokation());
408 exceptions_throw_nullpointerexception();
412 /* Class initialization is done by the JIT compiler. This is ok
413 since a static method always belongs to the declaring class. */
415 if (m->flags & ACC_STATIC) {
416 /* For static methods we reset the object. */
421 /* for convenience */
426 /* For instance methods we make a virtual function table lookup. */
428 resm = method_vftbl_lookup(vftbl, m);
431 STATISTICS(jnicallXmethodnvokation());
433 i = vm_call_method_int_jvalue(resm, o, args);
439 /* _Jv_jni_CallLongMethod ******************************************************
441 Internal function to call Java long methods.
443 *******************************************************************************/
445 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
446 methodinfo *m, va_list ap)
451 STATISTICS(jniinvokation());
454 exceptions_throw_nullpointerexception();
458 /* Class initialization is done by the JIT compiler. This is ok
459 since a static method always belongs to the declaring class. */
461 if (m->flags & ACC_STATIC) {
462 /* For static methods we reset the object. */
467 /* for convenience */
472 /* For instance methods we make a virtual function table lookup. */
474 resm = method_vftbl_lookup(vftbl, m);
477 STATISTICS(jnicallXmethodnvokation());
479 l = vm_call_method_long_valist(resm, o, ap);
485 /* _Jv_jni_CallLongMethodA *****************************************************
487 Internal function to call Java long methods.
489 *******************************************************************************/
491 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
492 methodinfo *m, jvalue *args)
497 STATISTICS(jniinvokation());
500 exceptions_throw_nullpointerexception();
504 /* Class initialization is done by the JIT compiler. This is ok
505 since a static method always belongs to the declaring class. */
507 if (m->flags & ACC_STATIC) {
508 /* For static methods we reset the object. */
513 /* for convenience */
518 /* For instance methods we make a virtual function table lookup. */
520 resm = method_vftbl_lookup(vftbl, m);
523 STATISTICS(jnicallXmethodnvokation());
525 l = vm_call_method_long_jvalue(resm, o, args);
531 /* _Jv_jni_CallFloatMethod *****************************************************
533 Internal function to call Java float methods.
535 *******************************************************************************/
537 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
538 methodinfo *m, va_list ap)
543 /* Class initialization is done by the JIT compiler. This is ok
544 since a static method always belongs to the declaring class. */
546 if (m->flags & ACC_STATIC) {
547 /* For static methods we reset the object. */
552 /* for convenience */
557 /* For instance methods we make a virtual function table lookup. */
559 resm = method_vftbl_lookup(vftbl, m);
562 STATISTICS(jnicallXmethodnvokation());
564 f = vm_call_method_float_valist(resm, o, ap);
570 /* _Jv_jni_CallFloatMethodA ****************************************************
572 Internal function to call Java float methods.
574 *******************************************************************************/
576 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
577 methodinfo *m, jvalue *args)
582 /* Class initialization is done by the JIT compiler. This is ok
583 since a static method always belongs to the declaring class. */
585 if (m->flags & ACC_STATIC) {
586 /* For static methods we reset the object. */
591 /* for convenience */
596 /* For instance methods we make a virtual function table lookup. */
598 resm = method_vftbl_lookup(vftbl, m);
601 STATISTICS(jnicallXmethodnvokation());
603 f = vm_call_method_float_jvalue(resm, o, args);
609 /* _Jv_jni_CallDoubleMethod ****************************************************
611 Internal function to call Java double methods.
613 *******************************************************************************/
615 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
616 methodinfo *m, va_list ap)
621 /* Class initialization is done by the JIT compiler. This is ok
622 since a static method always belongs to the declaring class. */
624 if (m->flags & ACC_STATIC) {
625 /* For static methods we reset the object. */
630 /* for convenience */
635 /* For instance methods we make a virtual function table lookup. */
637 resm = method_vftbl_lookup(vftbl, m);
640 d = vm_call_method_double_valist(resm, o, ap);
646 /* _Jv_jni_CallDoubleMethodA ***************************************************
648 Internal function to call Java double methods.
650 *******************************************************************************/
652 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
653 methodinfo *m, jvalue *args)
658 /* Class initialization is done by the JIT compiler. This is ok
659 since a static method always belongs to the declaring class. */
661 if (m->flags & ACC_STATIC) {
662 /* For static methods we reset the object. */
667 /* for convenience */
672 /* For instance methods we make a virtual function table lookup. */
674 resm = method_vftbl_lookup(vftbl, m);
677 d = vm_call_method_double_jvalue(resm, o, args);
683 /* _Jv_jni_CallVoidMethod ******************************************************
685 Internal function to call Java void methods.
687 *******************************************************************************/
689 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
690 methodinfo *m, va_list ap)
695 exceptions_throw_nullpointerexception();
699 /* Class initialization is done by the JIT compiler. This is ok
700 since a static method always belongs to the declaring class. */
702 if (m->flags & ACC_STATIC) {
703 /* For static methods we reset the object. */
708 /* for convenience */
713 /* For instance methods we make a virtual function table lookup. */
715 resm = method_vftbl_lookup(vftbl, m);
718 STATISTICS(jnicallXmethodnvokation());
720 (void) vm_call_method_valist(resm, o, ap);
724 /* _Jv_jni_CallVoidMethodA *****************************************************
726 Internal function to call Java void methods.
728 *******************************************************************************/
730 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
731 methodinfo *m, jvalue *args)
736 exceptions_throw_nullpointerexception();
740 /* Class initialization is done by the JIT compiler. This is ok
741 since a static method always belongs to the declaring class. */
743 if (m->flags & ACC_STATIC) {
744 /* For static methods we reset the object. */
749 /* for convenience */
754 /* For instance methods we make a virtual function table lookup. */
756 resm = method_vftbl_lookup(vftbl, m);
759 STATISTICS(jnicallXmethodnvokation());
761 (void) vm_call_method_jvalue(resm, o, args);
765 /* _Jv_jni_invokeNative ********************************************************
767 Invoke a method on the given object with the given arguments.
769 For instance methods OBJ must be != NULL and the method is looked up
770 in the vftbl of the object.
772 For static methods, OBJ is ignored.
774 *******************************************************************************/
776 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
777 java_objectarray *params)
781 java_objectheader *ro;
784 java_objectheader *xptr;
787 exceptions_throw_nullpointerexception();
791 argcount = m->parseddesc->paramcount;
792 paramcount = argcount;
794 /* if method is non-static, remove the `this' pointer */
796 if (!(m->flags & ACC_STATIC))
799 /* For instance methods the object has to be an instance of the
800 class the method belongs to. For static methods the obj
801 parameter is ignored. */
803 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
804 exceptions_throw_illegalargumentexception();
808 /* check if we got the right number of arguments */
810 if (((params == NULL) && (paramcount != 0)) ||
811 (params && (params->header.size != paramcount)))
813 exceptions_throw_illegalargumentexception();
817 /* for instance methods we need an object */
819 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
820 /* XXX not sure if that is the correct exception */
821 exceptions_throw_nullpointerexception();
825 /* for static methods, zero object to make subsequent code simpler */
826 if (m->flags & ACC_STATIC)
830 /* for instance methods we must do a vftbl lookup */
831 resm = method_vftbl_lookup(o->vftbl, m);
834 /* for static methods, just for convenience */
838 vmargs = MNEW(vm_arg, argcount);
840 if (!vm_vmargs_from_objectarray(resm, o, vmargs, params)) {
841 MFREE(vmargs, vm_arg, argcount);
845 switch (resm->parseddesc->returntype.decltype) {
847 (void) vm_call_method_vmarg(resm, argcount, vmargs);
852 case PRIMITIVETYPE_BOOLEAN: {
854 java_lang_Boolean *bo;
856 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
858 ro = builtin_new(class_java_lang_Boolean);
860 /* setting the value of the object direct */
862 bo = (java_lang_Boolean *) ro;
867 case PRIMITIVETYPE_BYTE: {
871 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
873 ro = builtin_new(class_java_lang_Byte);
875 /* setting the value of the object direct */
877 bo = (java_lang_Byte *) ro;
882 case PRIMITIVETYPE_CHAR: {
884 java_lang_Character *co;
886 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
888 ro = builtin_new(class_java_lang_Character);
890 /* setting the value of the object direct */
892 co = (java_lang_Character *) ro;
897 case PRIMITIVETYPE_SHORT: {
901 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
903 ro = builtin_new(class_java_lang_Short);
905 /* setting the value of the object direct */
907 so = (java_lang_Short *) ro;
912 case PRIMITIVETYPE_INT: {
914 java_lang_Integer *io;
916 i = vm_call_method_int_vmarg(resm, argcount, vmargs);
918 ro = builtin_new(class_java_lang_Integer);
920 /* setting the value of the object direct */
922 io = (java_lang_Integer *) ro;
927 case PRIMITIVETYPE_LONG: {
931 l = vm_call_method_long_vmarg(resm, argcount, vmargs);
933 ro = builtin_new(class_java_lang_Long);
935 /* setting the value of the object direct */
937 lo = (java_lang_Long *) ro;
942 case PRIMITIVETYPE_FLOAT: {
946 f = vm_call_method_float_vmarg(resm, argcount, vmargs);
948 ro = builtin_new(class_java_lang_Float);
950 /* setting the value of the object direct */
952 fo = (java_lang_Float *) ro;
957 case PRIMITIVETYPE_DOUBLE: {
959 java_lang_Double *_do;
961 d = vm_call_method_double_vmarg(resm, argcount, vmargs);
963 ro = builtin_new(class_java_lang_Double);
965 /* setting the value of the object direct */
967 _do = (java_lang_Double *) ro;
973 ro = vm_call_method_vmarg(resm, argcount, vmargs);
977 /* if this happens the exception has already been set by
978 fill_callblock_from_objectarray */
980 MFREE(vmargs, vm_arg, argcount);
985 MFREE(vmargs, vm_arg, argcount);
987 xptr = exceptions_get_exception();
990 /* clear exception pointer, we are calling JIT code again */
992 exceptions_clear_exception();
994 exceptions_throw_invocationtargetexception(xptr);
1001 /* GetVersion ******************************************************************
1003 Returns the major version number in the higher 16 bits and the
1004 minor version number in the lower 16 bits.
1006 *******************************************************************************/
1008 jint _Jv_JNI_GetVersion(JNIEnv *env)
1010 STATISTICS(jniinvokation());
1012 /* we support JNI 1.4 */
1014 return JNI_VERSION_1_4;
1018 /* Class Operations ***********************************************************/
1020 /* DefineClass *****************************************************************
1022 Loads a class from a buffer of raw class data. The buffer
1023 containing the raw class data is not referenced by the VM after the
1024 DefineClass call returns, and it may be discarded if desired.
1026 *******************************************************************************/
1028 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1029 const jbyte *buf, jsize bufLen)
1031 #if defined(ENABLE_JAVASE)
1032 java_lang_ClassLoader *cl;
1033 java_lang_String *s;
1037 STATISTICS(jniinvokation());
1039 cl = (java_lang_ClassLoader *) loader;
1040 s = (java_lang_String *) javastring_new_from_utf_string(name);
1041 ba = (java_bytearray *) buf;
1043 c = (jclass) _Jv_java_lang_ClassLoader_defineClass(cl, s, ba, 0, bufLen,
1046 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1048 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1050 /* keep compiler happy */
1057 /* FindClass *******************************************************************
1059 This function loads a locally-defined class. It searches the
1060 directories and zip files specified by the CLASSPATH environment
1061 variable for the class with the specified name.
1063 *******************************************************************************/
1065 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1067 #if defined(ENABLE_JAVASE)
1072 STATISTICS(jniinvokation());
1074 u = utf_new_char_classname((char *) name);
1076 /* Check stacktrace for classloader, if one found use it,
1077 otherwise use the system classloader. */
1079 /* Quote from the JNI documentation:
1081 In the Java 2 Platform, FindClass locates the class loader
1082 associated with the current native method. If the native code
1083 belongs to a system class, no class loader will be
1084 involved. Otherwise, the proper class loader will be invoked to
1085 load and link the named class. When FindClass is called through
1086 the Invocation Interface, there is no current native method or
1087 its associated class loader. In that case, the result of
1088 ClassLoader.getBaseClassLoader is used." */
1090 cc = stacktrace_getCurrentClass();
1093 c = load_class_from_sysloader(u);
1095 c = load_class_from_classloader(u, cc->classloader);
1103 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1105 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1107 /* keep compiler happy */
1114 /* GetSuperclass ***************************************************************
1116 If clazz represents any class other than the class Object, then
1117 this function returns the object that represents the superclass of
1118 the class specified by clazz.
1120 *******************************************************************************/
1122 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1126 STATISTICS(jniinvokation());
1128 c = ((classinfo *) sub)->super.cls;
1133 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1137 /* IsAssignableFrom ************************************************************
1139 Determines whether an object of sub can be safely cast to sup.
1141 *******************************************************************************/
1143 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1145 java_lang_Class *csup;
1146 java_lang_Class *csub;
1148 csup = (java_lang_Class *) sup;
1149 csub = (java_lang_Class *) sub;
1151 STATISTICS(jniinvokation());
1153 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1157 /* Throw ***********************************************************************
1159 Causes a java.lang.Throwable object to be thrown.
1161 *******************************************************************************/
1163 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1165 java_objectheader *o;
1167 STATISTICS(jniinvokation());
1169 o = (java_objectheader *) obj;
1171 exceptions_set_exception(o);
1177 /* ThrowNew ********************************************************************
1179 Constructs an exception object from the specified class with the
1180 message specified by message and causes that exception to be
1183 *******************************************************************************/
1185 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1188 java_objectheader *o;
1189 java_objectheader *s;
1191 STATISTICS(jniinvokation());
1193 c = (classinfo *) clazz;
1194 s = javastring_new_from_utf_string(msg);
1196 /* instantiate exception object */
1198 o = native_new_and_init_string(c, s);
1203 exceptions_set_exception(o);
1209 /* ExceptionOccurred ***********************************************************
1211 Determines if an exception is being thrown. The exception stays
1212 being thrown until either the native code calls ExceptionClear(),
1213 or the Java code handles the exception.
1215 *******************************************************************************/
1217 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1219 java_objectheader *o;
1221 STATISTICS(jniinvokation());
1223 o = exceptions_get_exception();
1225 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1229 /* ExceptionDescribe ***********************************************************
1231 Prints an exception and a backtrace of the stack to a system
1232 error-reporting channel, such as stderr. This is a convenience
1233 routine provided for debugging.
1235 *******************************************************************************/
1237 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1239 java_objectheader *o;
1242 STATISTICS(jniinvokation());
1244 o = exceptions_get_exception();
1247 /* clear exception, because we are calling jit code again */
1249 exceptions_clear_exception();
1251 /* get printStackTrace method from exception class */
1253 m = class_resolveclassmethod(o->vftbl->class,
1254 utf_printStackTrace,
1260 /* XXX what should we do? */
1263 /* print the stacktrace */
1265 (void) vm_call_method(m, o);
1270 /* ExceptionClear **************************************************************
1272 Clears any exception that is currently being thrown. If no
1273 exception is currently being thrown, this routine has no effect.
1275 *******************************************************************************/
1277 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1279 STATISTICS(jniinvokation());
1281 exceptions_clear_exception();
1285 /* FatalError ******************************************************************
1287 Raises a fatal error and does not expect the VM to recover. This
1288 function does not return.
1290 *******************************************************************************/
1292 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1294 STATISTICS(jniinvokation());
1296 /* this seems to be the best way */
1298 vm_abort("JNI Fatal error: %s", msg);
1302 /* PushLocalFrame **************************************************************
1304 Creates a new local reference frame, in which at least a given
1305 number of local references can be created.
1307 *******************************************************************************/
1309 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1312 localref_table *lrt;
1313 localref_table *nlrt;
1315 STATISTICS(jniinvokation());
1320 /* Allocate new local reference table on Java heap. Calculate the
1321 additional memory we have to allocate. */
1323 if (capacity > LOCALREFTABLE_CAPACITY)
1324 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1328 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1333 /* get current local reference table from thread */
1335 lrt = LOCALREFTABLE;
1337 /* Set up the new local reference table and add it to the local
1340 nlrt->capacity = capacity;
1342 nlrt->localframes = lrt->localframes + 1;
1345 /* store new local reference table in thread */
1347 LOCALREFTABLE = nlrt;
1353 /* PopLocalFrame ***************************************************************
1355 Pops off the current local reference frame, frees all the local
1356 references, and returns a local reference in the previous local
1357 reference frame for the given result object.
1359 *******************************************************************************/
1361 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1363 localref_table *lrt;
1364 localref_table *plrt;
1367 STATISTICS(jniinvokation());
1369 /* get current local reference table from thread */
1371 lrt = LOCALREFTABLE;
1373 localframes = lrt->localframes;
1375 /* Don't delete the top local frame, as this one is allocated in
1376 the native stub on the stack and is freed automagically on
1379 if (localframes == 1)
1380 return _Jv_JNI_NewLocalRef(env, result);
1382 /* release all current local frames */
1384 for (; localframes >= 1; localframes--) {
1385 /* get previous frame */
1389 /* clear all reference entries */
1391 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1395 /* set new local references table */
1400 /* store new local reference table in thread */
1402 LOCALREFTABLE = lrt;
1404 /* add local reference and return the value */
1406 return _Jv_JNI_NewLocalRef(env, result);
1410 /* DeleteLocalRef **************************************************************
1412 Deletes the local reference pointed to by localRef.
1414 *******************************************************************************/
1416 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1418 java_objectheader *o;
1419 localref_table *lrt;
1422 STATISTICS(jniinvokation());
1424 o = (java_objectheader *) localRef;
1426 /* get local reference table (thread specific) */
1428 lrt = LOCALREFTABLE;
1430 /* go through all local frames */
1432 for (; lrt != NULL; lrt = lrt->prev) {
1434 /* and try to remove the reference */
1436 for (i = 0; i < lrt->capacity; i++) {
1437 if (lrt->refs[i] == o) {
1438 lrt->refs[i] = NULL;
1446 /* this should not happen */
1448 /* if (opt_checkjni) */
1449 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1450 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1454 /* IsSameObject ****************************************************************
1456 Tests whether two references refer to the same Java object.
1458 *******************************************************************************/
1460 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1462 STATISTICS(jniinvokation());
1471 /* NewLocalRef *****************************************************************
1473 Creates a new local reference that refers to the same object as ref.
1475 *******************************************************************************/
1477 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1479 localref_table *lrt;
1482 STATISTICS(jniinvokation());
1487 /* get local reference table (thread specific) */
1489 lrt = LOCALREFTABLE;
1491 /* Check if we have space for the requested reference? No,
1492 allocate a new frame. This is actually not what the spec says,
1493 but for compatibility reasons... */
1495 if (lrt->used == lrt->capacity) {
1496 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1499 /* get the new local reference table */
1501 lrt = LOCALREFTABLE;
1504 /* insert the reference */
1506 for (i = 0; i < lrt->capacity; i++) {
1507 if (lrt->refs[i] == NULL) {
1508 lrt->refs[i] = (java_objectheader *) ref;
1515 /* should not happen, just to be sure */
1519 /* keep compiler happy */
1525 /* EnsureLocalCapacity *********************************************************
1527 Ensures that at least a given number of local references can be
1528 created in the current thread
1530 *******************************************************************************/
1532 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1534 localref_table *lrt;
1536 STATISTICS(jniinvokation());
1538 /* get local reference table (thread specific) */
1540 lrt = LOCALREFTABLE;
1542 /* check if capacity elements are available in the local references table */
1544 if ((lrt->used + capacity) > lrt->capacity)
1545 return _Jv_JNI_PushLocalFrame(env, capacity);
1551 /* AllocObject *****************************************************************
1553 Allocates a new Java object without invoking any of the
1554 constructors for the object. Returns a reference to the object.
1556 *******************************************************************************/
1558 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1561 java_objectheader *o;
1563 STATISTICS(jniinvokation());
1565 c = (classinfo *) clazz;
1567 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1568 exceptions_throw_instantiationexception(c);
1574 return _Jv_JNI_NewLocalRef(env, o);
1578 /* NewObject *******************************************************************
1580 Programmers place all arguments that are to be passed to the
1581 constructor immediately following the methodID
1582 argument. NewObject() accepts these arguments and passes them to
1583 the Java method that the programmer wishes to invoke.
1585 *******************************************************************************/
1587 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1589 java_objectheader *o;
1593 STATISTICS(jniinvokation());
1595 m = (methodinfo *) methodID;
1599 o = builtin_new(clazz);
1604 /* call constructor */
1606 va_start(ap, methodID);
1607 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1610 return _Jv_JNI_NewLocalRef(env, o);
1614 /* NewObjectV ******************************************************************
1616 Programmers place all arguments that are to be passed to the
1617 constructor in an args argument of type va_list that immediately
1618 follows the methodID argument. NewObjectV() accepts these
1619 arguments, and, in turn, passes them to the Java method that the
1620 programmer wishes to invoke.
1622 *******************************************************************************/
1624 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1627 java_objectheader *o;
1630 STATISTICS(jniinvokation());
1632 m = (methodinfo *) methodID;
1636 o = builtin_new(clazz);
1641 /* call constructor */
1643 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1645 return _Jv_JNI_NewLocalRef(env, o);
1649 /* NewObjectA *****************************************************************
1651 Programmers place all arguments that are to be passed to the
1652 constructor in an args array of jvalues that immediately follows
1653 the methodID argument. NewObjectA() accepts the arguments in this
1654 array, and, in turn, passes them to the Java method that the
1655 programmer wishes to invoke.
1657 *******************************************************************************/
1659 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1662 java_objectheader *o;
1665 STATISTICS(jniinvokation());
1667 m = (methodinfo *) methodID;
1671 o = builtin_new(clazz);
1676 /* call constructor */
1678 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1680 return _Jv_JNI_NewLocalRef(env, o);
1684 /* GetObjectClass **************************************************************
1686 Returns the class of an object.
1688 *******************************************************************************/
1690 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1692 java_objectheader *o;
1695 STATISTICS(jniinvokation());
1697 o = (java_objectheader *) obj;
1699 if ((o == NULL) || (o->vftbl == NULL))
1702 c = o->vftbl->class;
1704 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1708 /* IsInstanceOf ****************************************************************
1710 Tests whether an object is an instance of a class.
1712 *******************************************************************************/
1714 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1717 java_lang_Object *o;
1719 STATISTICS(jniinvokation());
1721 c = (java_lang_Class *) clazz;
1722 o = (java_lang_Object *) obj;
1724 return _Jv_java_lang_Class_isInstance(c, o);
1728 /* Reflection Support *********************************************************/
1730 /* FromReflectedMethod *********************************************************
1732 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1733 object to a method ID.
1735 *******************************************************************************/
1737 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1739 #if defined(ENABLE_JAVASE)
1744 STATISTICS(jniinvokation());
1749 if (builtin_instanceof(method, class_java_lang_reflect_Method)) {
1750 java_lang_reflect_Method *rm;
1752 rm = (java_lang_reflect_Method *) method;
1753 c = (classinfo *) (rm->declaringClass);
1756 else if (builtin_instanceof(method, class_java_lang_reflect_Constructor)) {
1757 java_lang_reflect_Constructor *rc;
1759 rc = (java_lang_reflect_Constructor *) method;
1760 c = (classinfo *) (rc->clazz);
1766 mi = &(c->methods[slot]);
1768 return (jmethodID) mi;
1770 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1772 /* keep compiler happy */
1779 /* FromReflectedField **********************************************************
1781 Converts a java.lang.reflect.Field to a field ID.
1783 *******************************************************************************/
1785 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1787 #if defined(ENABLE_JAVASE)
1788 java_lang_reflect_Field *rf;
1792 STATISTICS(jniinvokation());
1794 rf = (java_lang_reflect_Field *) field;
1799 c = (classinfo *) rf->declaringClass;
1801 f = &(c->fields[rf->slot]);
1803 return (jfieldID) f;
1805 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1807 /* keep compiler happy */
1814 /* ToReflectedMethod ***********************************************************
1816 Converts a method ID derived from cls to an instance of the
1817 java.lang.reflect.Method class or to an instance of the
1818 java.lang.reflect.Constructor class.
1820 *******************************************************************************/
1822 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1825 STATISTICS(jniinvokation());
1827 log_text("JNI-Call: ToReflectedMethod: IMPLEMENT ME!");
1833 /* ToReflectedField ************************************************************
1835 Converts a field ID derived from cls to an instance of the
1836 java.lang.reflect.Field class.
1838 *******************************************************************************/
1840 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1843 STATISTICS(jniinvokation());
1845 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1851 /* Calling Instance Methods ***************************************************/
1853 /* GetMethodID *****************************************************************
1855 Returns the method ID for an instance (nonstatic) method of a class
1856 or interface. The method may be defined in one of the clazz's
1857 superclasses and inherited by clazz. The method is determined by
1858 its name and signature.
1860 GetMethodID() causes an uninitialized class to be initialized.
1862 *******************************************************************************/
1864 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1872 STATISTICS(jniinvokation());
1874 c = (classinfo *) clazz;
1879 if (!(c->state & CLASS_INITIALIZED))
1880 if (!initialize_class(c))
1883 /* try to get the method of the class or one of it's superclasses */
1885 uname = utf_new_char((char *) name);
1886 udesc = utf_new_char((char *) sig);
1888 m = class_resolvemethod(clazz, uname, udesc);
1890 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1891 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1896 return (jmethodID) m;
1900 /* JNI-functions for calling instance methods *********************************/
1902 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1905 java_objectheader *o;
1907 java_objectheader *ret;
1910 o = (java_objectheader *) obj;
1911 m = (methodinfo *) methodID;
1913 va_start(ap, methodID);
1914 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1917 return _Jv_JNI_NewLocalRef(env, ret);
1921 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1924 java_objectheader *o;
1926 java_objectheader *ret;
1928 o = (java_objectheader *) obj;
1929 m = (methodinfo *) methodID;
1931 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1933 return _Jv_JNI_NewLocalRef(env, ret);
1937 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1940 java_objectheader *o;
1942 java_objectheader *ret;
1944 o = (java_objectheader *) obj;
1945 m = (methodinfo *) methodID;
1947 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1949 return _Jv_JNI_NewLocalRef(env, ret);
1953 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1956 java_objectheader *o;
1961 o = (java_objectheader *) obj;
1962 m = (methodinfo *) methodID;
1964 va_start(ap, methodID);
1965 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1972 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
1973 jmethodID methodID, va_list args)
1975 java_objectheader *o;
1979 o = (java_objectheader *) obj;
1980 m = (methodinfo *) methodID;
1982 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1988 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
1989 jmethodID methodID, jvalue *args)
1991 java_objectheader *o;
1995 o = (java_objectheader *) obj;
1996 m = (methodinfo *) methodID;
1998 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2004 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2006 java_objectheader *o;
2011 o = (java_objectheader *) obj;
2012 m = (methodinfo *) methodID;
2014 va_start(ap, methodID);
2015 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2023 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2026 java_objectheader *o;
2030 o = (java_objectheader *) obj;
2031 m = (methodinfo *) methodID;
2033 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2039 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2042 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2048 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2050 java_objectheader *o;
2055 o = (java_objectheader *) obj;
2056 m = (methodinfo *) methodID;
2058 va_start(ap, methodID);
2059 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2066 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2069 java_objectheader *o;
2073 o = (java_objectheader *) obj;
2074 m = (methodinfo *) methodID;
2076 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2082 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2085 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2091 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2094 java_objectheader *o;
2099 o = (java_objectheader *) obj;
2100 m = (methodinfo *) methodID;
2102 va_start(ap, methodID);
2103 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2110 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2113 java_objectheader *o;
2117 o = (java_objectheader *) obj;
2118 m = (methodinfo *) methodID;
2120 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2126 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2129 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2136 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2138 java_objectheader *o;
2143 o = (java_objectheader *) obj;
2144 m = (methodinfo *) methodID;
2146 va_start(ap, methodID);
2147 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2154 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2157 java_objectheader *o;
2161 o = (java_objectheader *) obj;
2162 m = (methodinfo *) methodID;
2164 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2170 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2173 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2180 jlong _Jv_JNI_CallLongMethod(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 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2198 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2201 java_objectheader *o;
2205 o = (java_objectheader *) obj;
2206 m = (methodinfo *) methodID;
2208 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2214 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2217 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2224 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2227 java_objectheader *o;
2232 o = (java_objectheader *) obj;
2233 m = (methodinfo *) methodID;
2235 va_start(ap, methodID);
2236 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2243 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2246 java_objectheader *o;
2250 o = (java_objectheader *) obj;
2251 m = (methodinfo *) methodID;
2253 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2259 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2262 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2269 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2272 java_objectheader *o;
2277 o = (java_objectheader *) obj;
2278 m = (methodinfo *) methodID;
2280 va_start(ap, methodID);
2281 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2288 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2291 java_objectheader *o;
2295 o = (java_objectheader *) obj;
2296 m = (methodinfo *) methodID;
2298 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2304 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2307 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2314 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2316 java_objectheader *o;
2320 o = (java_objectheader *) obj;
2321 m = (methodinfo *) methodID;
2323 va_start(ap, methodID);
2324 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2329 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2332 java_objectheader *o;
2335 o = (java_objectheader *) obj;
2336 m = (methodinfo *) methodID;
2338 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2342 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2345 java_objectheader *o;
2348 o = (java_objectheader *) obj;
2349 m = (methodinfo *) methodID;
2351 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2356 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2357 jclass clazz, jmethodID methodID,
2360 java_objectheader *o;
2363 java_objectheader *r;
2366 o = (java_objectheader *) obj;
2367 c = (classinfo *) clazz;
2368 m = (methodinfo *) methodID;
2370 va_start(ap, methodID);
2371 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2374 return _Jv_JNI_NewLocalRef(env, r);
2378 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2379 jclass clazz, jmethodID methodID,
2382 java_objectheader *o;
2385 java_objectheader *r;
2387 o = (java_objectheader *) obj;
2388 c = (classinfo *) clazz;
2389 m = (methodinfo *) methodID;
2391 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2393 return _Jv_JNI_NewLocalRef(env, r);
2397 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2398 jclass clazz, jmethodID methodID,
2401 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2403 return _Jv_JNI_NewLocalRef(env, NULL);
2408 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2409 jclass clazz, jmethodID methodID,
2412 java_objectheader *o;
2418 o = (java_objectheader *) obj;
2419 c = (classinfo *) clazz;
2420 m = (methodinfo *) methodID;
2422 va_start(ap, methodID);
2423 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2430 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2431 jclass clazz, jmethodID methodID,
2434 java_objectheader *o;
2439 o = (java_objectheader *) obj;
2440 c = (classinfo *) clazz;
2441 m = (methodinfo *) methodID;
2443 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2449 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2450 jclass clazz, jmethodID methodID,
2453 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2459 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2460 jmethodID methodID, ...)
2462 java_objectheader *o;
2468 o = (java_objectheader *) obj;
2469 c = (classinfo *) clazz;
2470 m = (methodinfo *) methodID;
2472 va_start(ap, methodID);
2473 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2480 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2481 jmethodID methodID, va_list args)
2483 java_objectheader *o;
2488 o = (java_objectheader *) obj;
2489 c = (classinfo *) clazz;
2490 m = (methodinfo *) methodID;
2492 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2498 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2499 jmethodID methodID, jvalue *args)
2501 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2508 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2509 jmethodID methodID, ...)
2511 java_objectheader *o;
2517 o = (java_objectheader *) obj;
2518 c = (classinfo *) clazz;
2519 m = (methodinfo *) methodID;
2521 va_start(ap, methodID);
2522 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2529 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2530 jmethodID methodID, va_list args)
2532 java_objectheader *o;
2537 o = (java_objectheader *) obj;
2538 c = (classinfo *) clazz;
2539 m = (methodinfo *) methodID;
2541 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2547 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2548 jmethodID methodID, jvalue *args)
2550 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2557 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2558 jclass clazz, jmethodID methodID, ...)
2560 java_objectheader *o;
2566 o = (java_objectheader *) obj;
2567 c = (classinfo *) clazz;
2568 m = (methodinfo *) methodID;
2570 va_start(ap, methodID);
2571 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2578 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2579 jclass clazz, jmethodID methodID,
2582 java_objectheader *o;
2587 o = (java_objectheader *) obj;
2588 c = (classinfo *) clazz;
2589 m = (methodinfo *) methodID;
2591 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2597 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2598 jclass clazz, jmethodID methodID,
2601 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2608 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2609 jmethodID methodID, ...)
2611 java_objectheader *o;
2617 o = (java_objectheader *) obj;
2618 c = (classinfo *) clazz;
2619 m = (methodinfo *) methodID;
2621 va_start(ap, methodID);
2622 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2629 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2630 jmethodID methodID, va_list args)
2632 java_objectheader *o;
2637 o = (java_objectheader *) obj;
2638 c = (classinfo *) clazz;
2639 m = (methodinfo *) methodID;
2641 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2647 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2648 jmethodID methodID, jvalue *args)
2650 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2657 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2658 jmethodID methodID, ...)
2660 java_objectheader *o;
2666 o = (java_objectheader *) obj;
2667 c = (classinfo *) clazz;
2668 m = (methodinfo *) methodID;
2670 va_start(ap, methodID);
2671 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2678 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2679 jmethodID methodID, va_list args)
2681 java_objectheader *o;
2686 o = (java_objectheader *) obj;
2687 c = (classinfo *) clazz;
2688 m = (methodinfo *) methodID;
2690 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2696 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2697 jmethodID methodID, jvalue *args)
2699 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2706 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2707 jclass clazz, jmethodID methodID, ...)
2709 java_objectheader *o;
2715 o = (java_objectheader *) obj;
2716 c = (classinfo *) clazz;
2717 m = (methodinfo *) methodID;
2719 va_start(ap, methodID);
2720 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2727 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2728 jclass clazz, jmethodID methodID,
2731 java_objectheader *o;
2736 o = (java_objectheader *) obj;
2737 c = (classinfo *) clazz;
2738 m = (methodinfo *) methodID;
2740 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2746 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2747 jclass clazz, jmethodID methodID,
2750 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2757 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2758 jclass clazz, jmethodID methodID,
2761 java_objectheader *o;
2767 o = (java_objectheader *) obj;
2768 c = (classinfo *) clazz;
2769 m = (methodinfo *) methodID;
2771 va_start(ap, methodID);
2772 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2779 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2780 jclass clazz, jmethodID methodID,
2783 java_objectheader *o;
2788 o = (java_objectheader *) obj;
2789 c = (classinfo *) clazz;
2790 m = (methodinfo *) methodID;
2792 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2798 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2799 jclass clazz, jmethodID methodID,
2802 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2809 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2810 jmethodID methodID, ...)
2812 java_objectheader *o;
2817 o = (java_objectheader *) obj;
2818 c = (classinfo *) clazz;
2819 m = (methodinfo *) methodID;
2821 va_start(ap, methodID);
2822 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2827 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2828 jmethodID methodID, va_list args)
2830 java_objectheader *o;
2834 o = (java_objectheader *) obj;
2835 c = (classinfo *) clazz;
2836 m = (methodinfo *) methodID;
2838 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2842 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2843 jmethodID methodID, jvalue * args)
2845 java_objectheader *o;
2849 o = (java_objectheader *) obj;
2850 c = (classinfo *) clazz;
2851 m = (methodinfo *) methodID;
2853 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2857 /* Accessing Fields of Objects ************************************************/
2859 /* GetFieldID ******************************************************************
2861 Returns the field ID for an instance (nonstatic) field of a
2862 class. The field is specified by its name and signature. The
2863 Get<type>Field and Set<type>Field families of accessor functions
2864 use field IDs to retrieve object fields.
2866 *******************************************************************************/
2868 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2876 STATISTICS(jniinvokation());
2878 c = (classinfo *) clazz;
2880 uname = utf_new_char((char *) name);
2881 udesc = utf_new_char((char *) sig);
2883 f = class_findfield(clazz, uname, udesc);
2886 exceptions_throw_nosuchfielderror(c, uname);
2888 return (jfieldID) f;
2892 /* Get<type>Field Routines *****************************************************
2894 This family of accessor routines returns the value of an instance
2895 (nonstatic) field of an object. The field to access is specified by
2896 a field ID obtained by calling GetFieldID().
2898 *******************************************************************************/
2900 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2902 java_objectheader *o;
2904 STATISTICS(jniinvokation());
2906 o = GET_FIELD(obj, java_objectheader*, fieldID);
2908 return _Jv_JNI_NewLocalRef(env, o);
2912 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2916 STATISTICS(jniinvokation());
2918 i = GET_FIELD(obj, s4, fieldID);
2920 return (jboolean) i;
2924 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2928 STATISTICS(jniinvokation());
2930 i = GET_FIELD(obj, s4, fieldID);
2936 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2940 STATISTICS(jniinvokation());
2942 i = GET_FIELD(obj, s4, fieldID);
2948 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2952 STATISTICS(jniinvokation());
2954 i = GET_FIELD(obj, s4, fieldID);
2960 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2962 java_objectheader *o;
2966 STATISTICS(jniinvokation());
2968 o = (java_objectheader *) obj;
2969 f = (fieldinfo *) fieldID;
2971 i = GET_FIELD(o, s4, f);
2977 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2981 STATISTICS(jniinvokation());
2983 l = GET_FIELD(obj, s8, fieldID);
2989 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2993 STATISTICS(jniinvokation());
2995 f = GET_FIELD(obj, float, fieldID);
3001 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3005 STATISTICS(jniinvokation());
3007 d = GET_FIELD(obj, double, fieldID);
3013 /* Set<type>Field Routines *****************************************************
3015 This family of accessor routines sets the value of an instance
3016 (nonstatic) field of an object. The field to access is specified by
3017 a field ID obtained by calling GetFieldID().
3019 *******************************************************************************/
3021 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3024 STATISTICS(jniinvokation());
3026 SET_FIELD(obj, java_objectheader*, fieldID, value);
3030 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3033 STATISTICS(jniinvokation());
3035 SET_FIELD(obj, s4, fieldID, value);
3039 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3042 STATISTICS(jniinvokation());
3044 SET_FIELD(obj, s4, fieldID, value);
3048 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3051 STATISTICS(jniinvokation());
3053 SET_FIELD(obj, s4, fieldID, value);
3057 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3060 STATISTICS(jniinvokation());
3062 SET_FIELD(obj, s4, fieldID, value);
3066 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3068 STATISTICS(jniinvokation());
3070 SET_FIELD(obj, s4, fieldID, value);
3074 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3077 STATISTICS(jniinvokation());
3079 SET_FIELD(obj, s8, fieldID, value);
3083 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3086 STATISTICS(jniinvokation());
3088 SET_FIELD(obj, float, fieldID, value);
3092 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3095 STATISTICS(jniinvokation());
3097 SET_FIELD(obj, double, fieldID, value);
3101 /* Calling Static Methods *****************************************************/
3103 /* GetStaticMethodID ***********************************************************
3105 Returns the method ID for a static method of a class. The method is
3106 specified by its name and signature.
3108 GetStaticMethodID() causes an uninitialized class to be
3111 *******************************************************************************/
3113 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3121 STATISTICS(jniinvokation());
3123 c = (classinfo *) clazz;
3128 if (!(c->state & CLASS_INITIALIZED))
3129 if (!initialize_class(c))
3132 /* try to get the static method of the class */
3134 uname = utf_new_char((char *) name);
3135 udesc = utf_new_char((char *) sig);
3137 m = class_resolvemethod(c, uname, udesc);
3139 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3140 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3145 return (jmethodID) m;
3149 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3150 jmethodID methodID, ...)
3153 java_objectheader *o;
3156 m = (methodinfo *) methodID;
3158 va_start(ap, methodID);
3159 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3162 return _Jv_JNI_NewLocalRef(env, o);
3166 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3167 jmethodID methodID, va_list args)
3170 java_objectheader *o;
3172 m = (methodinfo *) methodID;
3174 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3176 return _Jv_JNI_NewLocalRef(env, o);
3180 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3181 jmethodID methodID, jvalue *args)
3184 java_objectheader *o;
3186 m = (methodinfo *) methodID;
3188 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3190 return _Jv_JNI_NewLocalRef(env, o);
3194 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3195 jmethodID methodID, ...)
3201 m = (methodinfo *) methodID;
3203 va_start(ap, methodID);
3204 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3211 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3212 jmethodID methodID, va_list args)
3217 m = (methodinfo *) methodID;
3219 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3225 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3226 jmethodID methodID, jvalue *args)
3231 m = (methodinfo *) methodID;
3233 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3239 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3240 jmethodID methodID, ...)
3246 m = (methodinfo *) methodID;
3248 va_start(ap, methodID);
3249 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3256 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3257 jmethodID methodID, va_list args)
3262 m = (methodinfo *) methodID;
3264 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3270 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3271 jmethodID methodID, jvalue *args)
3276 m = (methodinfo *) methodID;
3278 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3284 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3285 jmethodID methodID, ...)
3291 m = (methodinfo *) methodID;
3293 va_start(ap, methodID);
3294 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3301 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3302 jmethodID methodID, va_list args)
3307 m = (methodinfo *) methodID;
3309 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3315 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3316 jmethodID methodID, jvalue *args)
3321 m = (methodinfo *) methodID;
3323 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3329 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3330 jmethodID methodID, ...)
3336 m = (methodinfo *) methodID;
3338 va_start(ap, methodID);
3339 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3346 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3347 jmethodID methodID, va_list args)
3352 m = (methodinfo *) methodID;
3354 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3360 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3361 jmethodID methodID, jvalue *args)
3366 m = (methodinfo *) methodID;
3368 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3374 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3381 m = (methodinfo *) methodID;
3383 va_start(ap, methodID);
3384 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3391 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3392 jmethodID methodID, va_list args)
3397 m = (methodinfo *) methodID;
3399 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3405 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3406 jmethodID methodID, jvalue *args)
3411 m = (methodinfo *) methodID;
3413 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3419 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3420 jmethodID methodID, ...)
3426 m = (methodinfo *) methodID;
3428 va_start(ap, methodID);
3429 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3436 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3437 jmethodID methodID, va_list args)
3442 m = (methodinfo *) methodID;
3444 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3450 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3451 jmethodID methodID, jvalue *args)
3456 m = (methodinfo *) methodID;
3458 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3465 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3466 jmethodID methodID, ...)
3472 m = (methodinfo *) methodID;
3474 va_start(ap, methodID);
3475 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3482 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3483 jmethodID methodID, va_list args)
3488 m = (methodinfo *) methodID;
3490 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3496 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3497 jmethodID methodID, jvalue *args)
3502 m = (methodinfo *) methodID;
3504 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3510 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3511 jmethodID methodID, ...)
3517 m = (methodinfo *) methodID;
3519 va_start(ap, methodID);
3520 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3527 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3528 jmethodID methodID, va_list args)
3533 m = (methodinfo *) methodID;
3535 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3541 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3542 jmethodID methodID, jvalue *args)
3547 m = (methodinfo *) methodID;
3549 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3555 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3556 jmethodID methodID, ...)
3561 m = (methodinfo *) methodID;
3563 va_start(ap, methodID);
3564 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3569 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3570 jmethodID methodID, va_list args)
3574 m = (methodinfo *) methodID;
3576 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3580 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3581 jmethodID methodID, jvalue * args)
3585 m = (methodinfo *) methodID;
3587 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3591 /* Accessing Static Fields ****************************************************/
3593 /* GetStaticFieldID ************************************************************
3595 Returns the field ID for a static field of a class. The field is
3596 specified by its name and signature. The GetStatic<type>Field and
3597 SetStatic<type>Field families of accessor functions use field IDs
3598 to retrieve static fields.
3600 *******************************************************************************/
3602 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3610 STATISTICS(jniinvokation());
3612 c = (classinfo *) clazz;
3614 uname = utf_new_char((char *) name);
3615 usig = utf_new_char((char *) sig);
3617 f = class_findfield(clazz, uname, usig);
3620 exceptions_throw_nosuchfielderror(c, uname);
3622 return (jfieldID) f;
3626 /* GetStatic<type>Field ********************************************************
3628 This family of accessor routines returns the value of a static
3631 *******************************************************************************/
3633 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3639 STATISTICS(jniinvokation());
3641 c = (classinfo *) clazz;
3642 f = (fieldinfo *) fieldID;
3644 if (!(c->state & CLASS_INITIALIZED))
3645 if (!initialize_class(c))
3648 return _Jv_JNI_NewLocalRef(env, f->value.a);
3652 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3658 STATISTICS(jniinvokation());
3660 c = (classinfo *) clazz;
3661 f = (fieldinfo *) fieldID;
3663 if (!(c->state & CLASS_INITIALIZED))
3664 if (!initialize_class(c))
3671 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3676 STATISTICS(jniinvokation());
3678 c = (classinfo *) clazz;
3679 f = (fieldinfo *) fieldID;
3681 if (!(c->state & CLASS_INITIALIZED))
3682 if (!initialize_class(c))
3689 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3694 STATISTICS(jniinvokation());
3696 c = (classinfo *) clazz;
3697 f = (fieldinfo *) fieldID;
3699 if (!(c->state & CLASS_INITIALIZED))
3700 if (!initialize_class(c))
3707 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3712 STATISTICS(jniinvokation());
3714 c = (classinfo *) clazz;
3715 f = (fieldinfo *) fieldID;
3717 if (!(c->state & CLASS_INITIALIZED))
3718 if (!initialize_class(c))
3725 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3730 STATISTICS(jniinvokation());
3732 c = (classinfo *) clazz;
3733 f = (fieldinfo *) fieldID;
3735 if (!(c->state & CLASS_INITIALIZED))
3736 if (!initialize_class(c))
3743 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3748 STATISTICS(jniinvokation());
3750 c = (classinfo *) clazz;
3751 f = (fieldinfo *) fieldID;
3753 if (!(c->state & CLASS_INITIALIZED))
3754 if (!initialize_class(c))
3761 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3766 STATISTICS(jniinvokation());
3768 c = (classinfo *) clazz;
3769 f = (fieldinfo *) fieldID;
3771 if (!(c->state & CLASS_INITIALIZED))
3772 if (!initialize_class(c))
3779 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3785 STATISTICS(jniinvokation());
3787 c = (classinfo *) clazz;
3788 f = (fieldinfo *) fieldID;
3790 if (!(c->state & CLASS_INITIALIZED))
3791 if (!initialize_class(c))
3798 /* SetStatic<type>Field *******************************************************
3800 This family of accessor routines sets the value of a static field
3803 *******************************************************************************/
3805 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3811 STATISTICS(jniinvokation());
3813 c = (classinfo *) clazz;
3814 f = (fieldinfo *) fieldID;
3816 if (!(c->state & CLASS_INITIALIZED))
3817 if (!initialize_class(c))
3824 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3830 STATISTICS(jniinvokation());
3832 c = (classinfo *) clazz;
3833 f = (fieldinfo *) fieldID;
3835 if (!(c->state & CLASS_INITIALIZED))
3836 if (!initialize_class(c))
3843 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3849 STATISTICS(jniinvokation());
3851 c = (classinfo *) clazz;
3852 f = (fieldinfo *) fieldID;
3854 if (!(c->state & CLASS_INITIALIZED))
3855 if (!initialize_class(c))
3862 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3868 STATISTICS(jniinvokation());
3870 c = (classinfo *) clazz;
3871 f = (fieldinfo *) fieldID;
3873 if (!(c->state & CLASS_INITIALIZED))
3874 if (!initialize_class(c))
3881 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3887 STATISTICS(jniinvokation());
3889 c = (classinfo *) clazz;
3890 f = (fieldinfo *) fieldID;
3892 if (!(c->state & CLASS_INITIALIZED))
3893 if (!initialize_class(c))
3900 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3906 STATISTICS(jniinvokation());
3908 c = (classinfo *) clazz;
3909 f = (fieldinfo *) fieldID;
3911 if (!(c->state & CLASS_INITIALIZED))
3912 if (!initialize_class(c))
3919 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3925 STATISTICS(jniinvokation());
3927 c = (classinfo *) clazz;
3928 f = (fieldinfo *) fieldID;
3930 if (!(c->state & CLASS_INITIALIZED))
3931 if (!initialize_class(c))
3938 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3944 STATISTICS(jniinvokation());
3946 c = (classinfo *) clazz;
3947 f = (fieldinfo *) fieldID;
3949 if (!(c->state & CLASS_INITIALIZED))
3950 if (!initialize_class(c))
3957 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3963 STATISTICS(jniinvokation());
3965 c = (classinfo *) clazz;
3966 f = (fieldinfo *) fieldID;
3968 if (!(c->state & CLASS_INITIALIZED))
3969 if (!initialize_class(c))
3976 /* String Operations **********************************************************/
3978 /* NewString *******************************************************************
3980 Create new java.lang.String object from an array of Unicode
3983 *******************************************************************************/
3985 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
3987 java_lang_String *s;
3991 STATISTICS(jniinvokation());
3993 s = (java_lang_String *) builtin_new(class_java_lang_String);
3994 a = builtin_newarray_char(len);
3996 /* javastring or characterarray could not be created */
3997 if ((a == NULL) || (s == NULL))
4001 for (i = 0; i < len; i++)
4002 a->data[i] = buf[i];
4008 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4012 static jchar emptyStringJ[]={0,0};
4014 /* GetStringLength *************************************************************
4016 Returns the length (the count of Unicode characters) of a Java
4019 *******************************************************************************/
4021 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4023 return ((java_lang_String *) str)->count;
4027 /******************** convertes javastring to u2-array ****************************/
4029 u2 *javastring_tou2(jstring so)
4031 java_lang_String *s;
4036 STATISTICS(jniinvokation());
4038 s = (java_lang_String *) so;
4048 /* allocate memory */
4050 stringbuffer = MNEW(u2, s->count + 1);
4054 for (i = 0; i < s->count; i++)
4055 stringbuffer[i] = a->data[s->offset + i];
4057 /* terminate string */
4059 stringbuffer[i] = '\0';
4061 return stringbuffer;
4065 /* GetStringChars **************************************************************
4067 Returns a pointer to the array of Unicode characters of the
4068 string. This pointer is valid until ReleaseStringChars() is called.
4070 *******************************************************************************/
4072 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4076 STATISTICS(jniinvokation());
4078 jc = javastring_tou2(str);
4090 return emptyStringJ;
4094 /* ReleaseStringChars **********************************************************
4096 Informs the VM that the native code no longer needs access to
4097 chars. The chars argument is a pointer obtained from string using
4100 *******************************************************************************/
4102 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4104 STATISTICS(jniinvokation());
4106 if (chars == emptyStringJ)
4109 MFREE(((jchar *) chars), jchar, ((java_lang_String *) str)->count + 1);
4113 /* NewStringUTF ****************************************************************
4115 Constructs a new java.lang.String object from an array of UTF-8
4118 *******************************************************************************/
4120 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4122 java_lang_String *s;
4124 STATISTICS(jniinvokation());
4126 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4128 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4132 /****************** returns the utf8 length in bytes of a string *******************/
4134 jsize _Jv_JNI_GetStringUTFLength (JNIEnv *env, jstring string)
4136 java_lang_String *s = (java_lang_String*) string;
4138 STATISTICS(jniinvokation());
4140 return (jsize) u2_utflength(s->value->data, s->count);
4144 /* GetStringUTFChars ***********************************************************
4146 Returns a pointer to an array of UTF-8 characters of the
4147 string. This array is valid until it is released by
4148 ReleaseStringUTFChars().
4150 *******************************************************************************/
4152 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4157 STATISTICS(jniinvokation());
4165 u = javastring_toutf((java_objectheader *) string, false);
4174 /* ReleaseStringUTFChars *******************************************************
4176 Informs the VM that the native code no longer needs access to
4177 utf. The utf argument is a pointer derived from string using
4178 GetStringUTFChars().
4180 *******************************************************************************/
4182 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4184 STATISTICS(jniinvokation());
4186 /* XXX we don't release utf chars right now, perhaps that should be done
4187 later. Since there is always one reference the garbage collector will
4192 /* Array Operations ***********************************************************/
4194 /* GetArrayLength **************************************************************
4196 Returns the number of elements in the array.
4198 *******************************************************************************/
4200 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4202 java_arrayheader *a;
4204 STATISTICS(jniinvokation());
4206 a = (java_arrayheader *) array;
4212 /* NewObjectArray **************************************************************
4214 Constructs a new array holding objects in class elementClass. All
4215 elements are initially set to initialElement.
4217 *******************************************************************************/
4219 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4220 jclass elementClass, jobject initialElement)
4222 java_objectarray *oa;
4225 STATISTICS(jniinvokation());
4228 exceptions_throw_negativearraysizeexception();
4232 oa = builtin_anewarray(length, elementClass);
4237 /* set all elements to initialElement */
4239 for (i = 0; i < length; i++)
4240 oa->data[i] = initialElement;
4242 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4246 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4249 java_objectarray *oa;
4252 STATISTICS(jniinvokation());
4254 oa = (java_objectarray *) array;
4256 if (index >= oa->header.size) {
4257 exceptions_throw_arrayindexoutofboundsexception();
4261 o = oa->data[index];
4263 return _Jv_JNI_NewLocalRef(env, o);
4267 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4268 jsize index, jobject val)
4270 java_objectarray *oa;
4271 java_objectheader *o;
4273 STATISTICS(jniinvokation());
4275 oa = (java_objectarray *) array;
4276 o = (java_objectheader *) val;
4278 if (index >= oa->header.size) {
4279 exceptions_throw_arrayindexoutofboundsexception();
4283 /* check if the class of value is a subclass of the element class
4286 if (!builtin_canstore(oa, o))
4289 oa->data[index] = val;
4293 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4295 java_booleanarray *ba;
4297 STATISTICS(jniinvokation());
4300 exceptions_throw_negativearraysizeexception();
4304 ba = builtin_newarray_boolean(len);
4306 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4310 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4314 STATISTICS(jniinvokation());
4317 exceptions_throw_negativearraysizeexception();
4321 ba = builtin_newarray_byte(len);
4323 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4327 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4331 STATISTICS(jniinvokation());
4334 exceptions_throw_negativearraysizeexception();
4338 ca = builtin_newarray_char(len);
4340 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4344 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4346 java_shortarray *sa;
4348 STATISTICS(jniinvokation());
4351 exceptions_throw_negativearraysizeexception();
4355 sa = builtin_newarray_short(len);
4357 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4361 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4365 STATISTICS(jniinvokation());
4368 exceptions_throw_negativearraysizeexception();
4372 ia = builtin_newarray_int(len);
4374 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4378 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4382 STATISTICS(jniinvokation());
4385 exceptions_throw_negativearraysizeexception();
4389 la = builtin_newarray_long(len);
4391 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4395 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4397 java_floatarray *fa;
4399 STATISTICS(jniinvokation());
4402 exceptions_throw_negativearraysizeexception();
4406 fa = builtin_newarray_float(len);
4408 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4412 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4414 java_doublearray *da;
4416 STATISTICS(jniinvokation());
4419 exceptions_throw_negativearraysizeexception();
4423 da = builtin_newarray_double(len);
4425 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4429 /* Get<PrimitiveType>ArrayElements *********************************************
4431 A family of functions that returns the body of the primitive array.
4433 *******************************************************************************/
4435 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4438 java_booleanarray *ba;
4440 STATISTICS(jniinvokation());
4442 ba = (java_booleanarray *) array;
4445 *isCopy = JNI_FALSE;
4451 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4456 STATISTICS(jniinvokation());
4458 ba = (java_bytearray *) array;
4461 *isCopy = JNI_FALSE;
4467 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4472 STATISTICS(jniinvokation());
4474 ca = (java_chararray *) array;
4477 *isCopy = JNI_FALSE;
4483 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4486 java_shortarray *sa;
4488 STATISTICS(jniinvokation());
4490 sa = (java_shortarray *) array;
4493 *isCopy = JNI_FALSE;
4499 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4504 STATISTICS(jniinvokation());
4506 ia = (java_intarray *) array;
4509 *isCopy = JNI_FALSE;
4515 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4520 STATISTICS(jniinvokation());
4522 la = (java_longarray *) array;
4525 *isCopy = JNI_FALSE;
4527 /* We cast this one to prevent a compiler warning on 64-bit
4528 systems since GNU Classpath typedef jlong to long long. */
4530 return (jlong *) la->data;
4534 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4537 java_floatarray *fa;
4539 STATISTICS(jniinvokation());
4541 fa = (java_floatarray *) array;
4544 *isCopy = JNI_FALSE;
4550 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4553 java_doublearray *da;
4555 STATISTICS(jniinvokation());
4557 da = (java_doublearray *) array;
4560 *isCopy = JNI_FALSE;
4566 /* Release<PrimitiveType>ArrayElements *****************************************
4568 A family of functions that informs the VM that the native code no
4569 longer needs access to elems. The elems argument is a pointer
4570 derived from array using the corresponding
4571 Get<PrimitiveType>ArrayElements() function. If necessary, this
4572 function copies back all changes made to elems to the original
4575 *******************************************************************************/
4577 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4578 jboolean *elems, jint mode)
4580 java_booleanarray *ba;
4582 STATISTICS(jniinvokation());
4584 ba = (java_booleanarray *) array;
4586 if (elems != ba->data) {
4589 MCOPY(ba->data, elems, u1, ba->header.size);
4592 MCOPY(ba->data, elems, u1, ba->header.size);
4593 /* XXX TWISTI how should it be freed? */
4596 /* XXX TWISTI how should it be freed? */
4603 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4604 jbyte *elems, jint mode)
4608 STATISTICS(jniinvokation());
4610 ba = (java_bytearray *) array;
4612 if (elems != ba->data) {
4615 MCOPY(ba->data, elems, s1, ba->header.size);
4618 MCOPY(ba->data, elems, s1, ba->header.size);
4619 /* XXX TWISTI how should it be freed? */
4622 /* XXX TWISTI how should it be freed? */
4629 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4630 jchar *elems, jint mode)
4634 STATISTICS(jniinvokation());
4636 ca = (java_chararray *) array;
4638 if (elems != ca->data) {
4641 MCOPY(ca->data, elems, u2, ca->header.size);
4644 MCOPY(ca->data, elems, u2, ca->header.size);
4645 /* XXX TWISTI how should it be freed? */
4648 /* XXX TWISTI how should it be freed? */
4655 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4656 jshort *elems, jint mode)
4658 java_shortarray *sa;
4660 STATISTICS(jniinvokation());
4662 sa = (java_shortarray *) array;
4664 if (elems != sa->data) {
4667 MCOPY(sa->data, elems, s2, sa->header.size);
4670 MCOPY(sa->data, elems, s2, sa->header.size);
4671 /* XXX TWISTI how should it be freed? */
4674 /* XXX TWISTI how should it be freed? */
4681 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4686 STATISTICS(jniinvokation());
4688 ia = (java_intarray *) array;
4690 if (elems != ia->data) {
4693 MCOPY(ia->data, elems, s4, ia->header.size);
4696 MCOPY(ia->data, elems, s4, ia->header.size);
4697 /* XXX TWISTI how should it be freed? */
4700 /* XXX TWISTI how should it be freed? */
4707 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4708 jlong *elems, jint mode)
4712 STATISTICS(jniinvokation());
4714 la = (java_longarray *) array;
4716 /* We cast this one to prevent a compiler warning on 64-bit
4717 systems since GNU Classpath typedef jlong to long long. */
4719 if ((s8 *) elems != la->data) {
4722 MCOPY(la->data, elems, s8, la->header.size);
4725 MCOPY(la->data, elems, s8, la->header.size);
4726 /* XXX TWISTI how should it be freed? */
4729 /* XXX TWISTI how should it be freed? */
4736 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4737 jfloat *elems, jint mode)
4739 java_floatarray *fa;
4741 STATISTICS(jniinvokation());
4743 fa = (java_floatarray *) array;
4745 if (elems != fa->data) {
4748 MCOPY(fa->data, elems, float, fa->header.size);
4751 MCOPY(fa->data, elems, float, fa->header.size);
4752 /* XXX TWISTI how should it be freed? */
4755 /* XXX TWISTI how should it be freed? */
4762 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4763 jdouble *elems, jint mode)
4765 java_doublearray *da;
4767 STATISTICS(jniinvokation());
4769 da = (java_doublearray *) array;
4771 if (elems != da->data) {
4774 MCOPY(da->data, elems, double, da->header.size);
4777 MCOPY(da->data, elems, double, da->header.size);
4778 /* XXX TWISTI how should it be freed? */
4781 /* XXX TWISTI how should it be freed? */
4788 /* Get<PrimitiveType>ArrayRegion **********************************************
4790 A family of functions that copies a region of a primitive array
4793 *******************************************************************************/
4795 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4796 jsize start, jsize len, jboolean *buf)
4798 java_booleanarray *ba;
4800 STATISTICS(jniinvokation());
4802 ba = (java_booleanarray *) array;
4804 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4805 exceptions_throw_arrayindexoutofboundsexception();
4807 MCOPY(buf, &ba->data[start], u1, len);
4811 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4812 jsize len, jbyte *buf)
4816 STATISTICS(jniinvokation());
4818 ba = (java_bytearray *) array;
4820 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4821 exceptions_throw_arrayindexoutofboundsexception();
4823 MCOPY(buf, &ba->data[start], s1, len);
4827 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4828 jsize len, jchar *buf)
4832 STATISTICS(jniinvokation());
4834 ca = (java_chararray *) array;
4836 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4837 exceptions_throw_arrayindexoutofboundsexception();
4839 MCOPY(buf, &ca->data[start], u2, len);
4843 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4844 jsize len, jshort *buf)
4846 java_shortarray *sa;
4848 STATISTICS(jniinvokation());
4850 sa = (java_shortarray *) array;
4852 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4853 exceptions_throw_arrayindexoutofboundsexception();
4855 MCOPY(buf, &sa->data[start], s2, len);
4859 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4860 jsize len, jint *buf)
4864 STATISTICS(jniinvokation());
4866 ia = (java_intarray *) array;
4868 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4869 exceptions_throw_arrayindexoutofboundsexception();
4871 MCOPY(buf, &ia->data[start], s4, len);
4875 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4876 jsize len, jlong *buf)
4880 STATISTICS(jniinvokation());
4882 la = (java_longarray *) array;
4884 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4885 exceptions_throw_arrayindexoutofboundsexception();
4887 MCOPY(buf, &la->data[start], s8, len);
4891 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4892 jsize len, jfloat *buf)
4894 java_floatarray *fa;
4896 STATISTICS(jniinvokation());
4898 fa = (java_floatarray *) array;
4900 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4901 exceptions_throw_arrayindexoutofboundsexception();
4903 MCOPY(buf, &fa->data[start], float, len);
4907 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4908 jsize len, jdouble *buf)
4910 java_doublearray *da;
4912 STATISTICS(jniinvokation());
4914 da = (java_doublearray *) array;
4916 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4917 exceptions_throw_arrayindexoutofboundsexception();
4919 MCOPY(buf, &da->data[start], double, len);
4923 /* Set<PrimitiveType>ArrayRegion **********************************************
4925 A family of functions that copies back a region of a primitive
4926 array from a buffer.
4928 *******************************************************************************/
4930 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4931 jsize start, jsize len, jboolean *buf)
4933 java_booleanarray *ba;
4935 STATISTICS(jniinvokation());
4937 ba = (java_booleanarray *) array;
4939 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4940 exceptions_throw_arrayindexoutofboundsexception();
4942 MCOPY(&ba->data[start], buf, u1, len);
4946 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4947 jsize len, jbyte *buf)
4951 STATISTICS(jniinvokation());
4953 ba = (java_bytearray *) array;
4955 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4956 exceptions_throw_arrayindexoutofboundsexception();
4958 MCOPY(&ba->data[start], buf, s1, len);
4962 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4963 jsize len, jchar *buf)
4967 STATISTICS(jniinvokation());
4969 ca = (java_chararray *) array;
4971 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4972 exceptions_throw_arrayindexoutofboundsexception();
4974 MCOPY(&ca->data[start], buf, u2, len);
4978 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4979 jsize len, jshort *buf)
4981 java_shortarray *sa;
4983 STATISTICS(jniinvokation());
4985 sa = (java_shortarray *) array;
4987 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4988 exceptions_throw_arrayindexoutofboundsexception();
4990 MCOPY(&sa->data[start], buf, s2, len);
4994 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4995 jsize len, jint *buf)
4999 STATISTICS(jniinvokation());
5001 ia = (java_intarray *) array;
5003 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5004 exceptions_throw_arrayindexoutofboundsexception();
5006 MCOPY(&ia->data[start], buf, s4, len);
5010 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5011 jsize len, jlong *buf)
5015 STATISTICS(jniinvokation());
5017 la = (java_longarray *) array;
5019 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5020 exceptions_throw_arrayindexoutofboundsexception();
5022 MCOPY(&la->data[start], buf, s8, len);
5026 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5027 jsize len, jfloat *buf)
5029 java_floatarray *fa;
5031 STATISTICS(jniinvokation());
5033 fa = (java_floatarray *) array;
5035 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5036 exceptions_throw_arrayindexoutofboundsexception();
5038 MCOPY(&fa->data[start], buf, float, len);
5042 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5043 jsize len, jdouble *buf)
5045 java_doublearray *da;
5047 STATISTICS(jniinvokation());
5049 da = (java_doublearray *) array;
5051 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5052 exceptions_throw_arrayindexoutofboundsexception();
5054 MCOPY(&da->data[start], buf, double, len);
5058 /* Registering Native Methods *************************************************/
5060 /* RegisterNatives *************************************************************
5062 Registers native methods with the class specified by the clazz
5063 argument. The methods parameter specifies an array of
5064 JNINativeMethod structures that contain the names, signatures, and
5065 function pointers of the native methods. The nMethods parameter
5066 specifies the number of native methods in the array.
5068 *******************************************************************************/
5070 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5071 const JNINativeMethod *methods, jint nMethods)
5073 STATISTICS(jniinvokation());
5075 log_text("JNI-Call: RegisterNatives: IMPLEMENT ME!!!");
5076 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5077 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5084 /* UnregisterNatives ***********************************************************
5086 Unregisters native methods of a class. The class goes back to the
5087 state before it was linked or registered with its native method
5090 This function should not be used in normal native code. Instead, it
5091 provides special programs a way to reload and relink native
5094 *******************************************************************************/
5096 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5098 STATISTICS(jniinvokation());
5100 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5102 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5108 /* Monitor Operations *********************************************************/
5110 /* MonitorEnter ****************************************************************
5112 Enters the monitor associated with the underlying Java object
5115 *******************************************************************************/
5117 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5119 STATISTICS(jniinvokation());
5122 exceptions_throw_nullpointerexception();
5126 LOCK_MONITOR_ENTER(obj);
5132 /* MonitorExit *****************************************************************
5134 The current thread must be the owner of the monitor associated with
5135 the underlying Java object referred to by obj. The thread
5136 decrements the counter indicating the number of times it has
5137 entered this monitor. If the value of the counter becomes zero, the
5138 current thread releases the monitor.
5140 *******************************************************************************/
5142 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5144 STATISTICS(jniinvokation());
5147 exceptions_throw_nullpointerexception();
5151 LOCK_MONITOR_EXIT(obj);
5157 /* JavaVM Interface ***********************************************************/
5159 /* GetJavaVM *******************************************************************
5161 Returns the Java VM interface (used in the Invocation API)
5162 associated with the current thread. The result is placed at the
5163 location pointed to by the second argument, vm.
5165 *******************************************************************************/
5167 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5169 STATISTICS(jniinvokation());
5171 *vm = (JavaVM *) _Jv_jvm;
5177 /* GetStringRegion *************************************************************
5179 Copies len number of Unicode characters beginning at offset start
5180 to the given buffer buf.
5182 Throws StringIndexOutOfBoundsException on index overflow.
5184 *******************************************************************************/
5186 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5189 java_lang_String *s;
5192 STATISTICS(jniinvokation());
5194 s = (java_lang_String *) str;
5197 if ((start < 0) || (len < 0) || (start > s->count) ||
5198 (start + len > s->count)) {
5199 exceptions_throw_stringindexoutofboundsexception();
5203 MCOPY(buf, &ca->data[start], u2, len);
5207 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5208 jsize len, char *buf)
5210 STATISTICS(jniinvokation());
5212 log_text("JNI-Call: GetStringUTFRegion: IMPLEMENT ME!");
5216 /* GetPrimitiveArrayCritical ***************************************************
5218 Obtain a direct pointer to array elements.
5220 *******************************************************************************/
5222 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5228 ba = (java_bytearray *) array;
5230 /* do the same as Kaffe does */
5232 bp = _Jv_JNI_GetByteArrayElements(env, ba, isCopy);
5238 /* ReleasePrimitiveArrayCritical ***********************************************
5240 No specific documentation.
5242 *******************************************************************************/
5244 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5245 void *carray, jint mode)
5247 STATISTICS(jniinvokation());
5249 /* do the same as Kaffe does */
5251 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5256 /* GetStringCritical ***********************************************************
5258 The semantics of these two functions are similar to the existing
5259 Get/ReleaseStringChars functions.
5261 *******************************************************************************/
5263 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5266 STATISTICS(jniinvokation());
5268 return _Jv_JNI_GetStringChars(env, string, isCopy);
5272 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5273 const jchar *cstring)
5275 STATISTICS(jniinvokation());
5277 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5281 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5283 STATISTICS(jniinvokation());
5285 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5291 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5293 STATISTICS(jniinvokation());
5295 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5299 /* NewGlobalRef ****************************************************************
5301 Creates a new global reference to the object referred to by the obj
5304 *******************************************************************************/
5306 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5308 hashtable_global_ref_entry *gre;
5309 u4 key; /* hashkey */
5310 u4 slot; /* slot in hashtable */
5312 STATISTICS(jniinvokation());
5314 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5316 /* normally addresses are aligned to 4, 8 or 16 bytes */
5318 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5319 slot = key & (hashtable_global_ref->size - 1);
5320 gre = hashtable_global_ref->ptr[slot];
5322 /* search external hash chain for the entry */
5325 if (gre->o == obj) {
5326 /* global object found, increment the reference */
5330 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5335 gre = gre->hashlink; /* next element in external chain */
5338 /* global ref not found, create a new one */
5340 gre = NEW(hashtable_global_ref_entry);
5345 /* insert entry into hashtable */
5347 gre->hashlink = hashtable_global_ref->ptr[slot];
5349 hashtable_global_ref->ptr[slot] = gre;
5351 /* update number of hashtable-entries */
5353 hashtable_global_ref->entries++;
5355 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5361 /* DeleteGlobalRef *************************************************************
5363 Deletes the global reference pointed to by globalRef.
5365 *******************************************************************************/
5367 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5369 hashtable_global_ref_entry *gre;
5370 hashtable_global_ref_entry *prevgre;
5371 u4 key; /* hashkey */
5372 u4 slot; /* slot in hashtable */
5374 STATISTICS(jniinvokation());
5376 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5378 /* normally addresses are aligned to 4, 8 or 16 bytes */
5380 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5381 slot = key & (hashtable_global_ref->size - 1);
5382 gre = hashtable_global_ref->ptr[slot];
5384 /* initialize prevgre */
5388 /* search external hash chain for the entry */
5391 if (gre->o == globalRef) {
5392 /* global object found, decrement the reference count */
5396 /* if reference count is 0, remove the entry */
5398 if (gre->refs == 0) {
5399 /* special handling if it's the first in the chain */
5401 if (prevgre == NULL)
5402 hashtable_global_ref->ptr[slot] = gre->hashlink;
5404 prevgre->hashlink = gre->hashlink;
5406 FREE(gre, hashtable_global_ref_entry);
5409 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5414 prevgre = gre; /* save current pointer for removal */
5415 gre = gre->hashlink; /* next element in external chain */
5418 log_println("JNI-DeleteGlobalRef: global reference not found");
5420 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5424 /* ExceptionCheck **************************************************************
5426 Returns JNI_TRUE when there is a pending exception; otherwise,
5429 *******************************************************************************/
5431 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5433 java_objectheader *o;
5435 STATISTICS(jniinvokation());
5437 o = exceptions_get_exception();
5439 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5443 /* New JNI 1.4 functions ******************************************************/
5445 /* NewDirectByteBuffer *********************************************************
5447 Allocates and returns a direct java.nio.ByteBuffer referring to the
5448 block of memory starting at the memory address address and
5449 extending capacity bytes.
5451 *******************************************************************************/
5453 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5455 #if defined(ENABLE_JAVASE)
5456 java_objectheader *nbuf;
5457 # if SIZEOF_VOID_P == 8
5458 gnu_classpath_Pointer64 *paddress;
5460 gnu_classpath_Pointer32 *paddress;
5463 STATISTICS(jniinvokation());
5465 /* alocate a gnu.classpath.Pointer{32,64} object */
5467 # if SIZEOF_VOID_P == 8
5468 if (!(paddress = (gnu_classpath_Pointer64 *)
5469 builtin_new(class_gnu_classpath_Pointer64)))
5471 if (!(paddress = (gnu_classpath_Pointer32 *)
5472 builtin_new(class_gnu_classpath_Pointer32)))
5476 /* fill gnu.classpath.Pointer{32,64} with address */
5478 paddress->data = (ptrint) address;
5480 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5482 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5483 (jmethodID) dbbirw_init, NULL, paddress,
5484 (jint) capacity, (jint) capacity, (jint) 0);
5486 /* add local reference and return the value */
5488 return _Jv_JNI_NewLocalRef(env, nbuf);
5490 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5492 /* keep compiler happy */
5499 /* GetDirectBufferAddress ******************************************************
5501 Fetches and returns the starting address of the memory region
5502 referenced by the given direct java.nio.Buffer.
5504 *******************************************************************************/
5506 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5508 #if defined(ENABLE_JAVASE)
5509 java_nio_DirectByteBufferImpl *nbuf;
5510 # if SIZEOF_VOID_P == 8
5511 gnu_classpath_Pointer64 *address;
5513 gnu_classpath_Pointer32 *address;
5516 STATISTICS(jniinvokation());
5518 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5521 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5523 # if SIZEOF_VOID_P == 8
5524 address = (gnu_classpath_Pointer64 *) nbuf->address;
5526 address = (gnu_classpath_Pointer32 *) nbuf->address;
5529 if (address == NULL)
5532 return (void *) address->data;
5534 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5536 /* keep compiler happy */
5543 /* GetDirectBufferCapacity *****************************************************
5545 Fetches and returns the capacity in bytes of the memory region
5546 referenced by the given direct java.nio.Buffer.
5548 *******************************************************************************/
5550 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5552 #if defined(ENABLE_JAVASE)
5553 java_nio_Buffer *nbuf;
5555 STATISTICS(jniinvokation());
5557 if (!builtin_instanceof(buf, class_java_nio_DirectByteBufferImpl))
5560 nbuf = (java_nio_Buffer *) buf;
5562 return (jlong) nbuf->cap;
5564 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5566 /* keep compiler happy */
5573 /* DestroyJavaVM ***************************************************************
5575 Unloads a Java VM and reclaims its resources. Only the main thread
5576 can unload the VM. The system waits until the main thread is only
5577 remaining user thread before it destroys the VM.
5579 *******************************************************************************/
5581 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5585 STATISTICS(jniinvokation());
5587 status = vm_destroy(vm);
5593 /* AttachCurrentThread *********************************************************
5595 Attaches the current thread to a Java VM. Returns a JNI interface
5596 pointer in the JNIEnv argument.
5598 Trying to attach a thread that is already attached is a no-op.
5600 A native thread cannot be attached simultaneously to two Java VMs.
5602 When a thread is attached to the VM, the context class loader is
5603 the bootstrap loader.
5605 *******************************************************************************/
5607 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5609 JavaVMAttachArgs *vm_aargs;
5611 #if defined(ENABLE_THREADS)
5612 if (threads_get_current_threadobject() == NULL) {
5613 vm_aargs = (JavaVMAttachArgs *) thr_args;
5615 if (vm_aargs != NULL) {
5616 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5617 (vm_aargs->version != JNI_VERSION_1_4))
5618 return JNI_EVERSION;
5621 if (!threads_attach_current_thread(vm_aargs, false))
5624 if (!jni_init_localref_table())
5635 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5637 STATISTICS(jniinvokation());
5639 return jni_attach_current_thread(p_env, thr_args, false);
5643 /* DetachCurrentThread *********************************************************
5645 Detaches the current thread from a Java VM. All Java monitors held
5646 by this thread are released. All Java threads waiting for this
5647 thread to die are notified.
5649 In JDK 1.1, the main thread cannot be detached from the VM. It must
5650 call DestroyJavaVM to unload the entire VM.
5652 In the JDK, the main thread can be detached from the VM.
5654 The main thread, which is the thread that created the Java VM,
5655 cannot be detached from the VM. Instead, the main thread must call
5656 JNI_DestroyJavaVM() to unload the entire VM.
5658 *******************************************************************************/
5660 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5662 #if defined(ENABLE_THREADS)
5663 threadobject *thread;
5665 STATISTICS(jniinvokation());
5667 thread = threads_get_current_threadobject();
5672 if (!threads_detach_thread(thread))
5680 /* GetEnv **********************************************************************
5682 If the current thread is not attached to the VM, sets *env to NULL,
5683 and returns JNI_EDETACHED. If the specified version is not
5684 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5685 sets *env to the appropriate interface, and returns JNI_OK.
5687 *******************************************************************************/
5689 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5691 STATISTICS(jniinvokation());
5693 #if defined(ENABLE_THREADS)
5694 if (threads_get_current_threadobject() == NULL) {
5697 return JNI_EDETACHED;
5701 /* check the JNI version */
5704 case JNI_VERSION_1_1:
5705 case JNI_VERSION_1_2:
5706 case JNI_VERSION_1_4:
5714 #if defined(ENABLE_JVMTI)
5715 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5716 == JVMTI_VERSION_INTERFACE_JVMTI) {
5718 *env = (void *) jvmti_new_environment();
5727 return JNI_EVERSION;
5731 /* AttachCurrentThreadAsDaemon *************************************************
5733 Same semantics as AttachCurrentThread, but the newly-created
5734 java.lang.Thread instance is a daemon.
5736 If the thread has already been attached via either
5737 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5738 simply sets the value pointed to by penv to the JNIEnv of the
5739 current thread. In this case neither AttachCurrentThread nor this
5740 routine have any effect on the daemon status of the thread.
5742 *******************************************************************************/
5744 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5746 STATISTICS(jniinvokation());
5748 return jni_attach_current_thread(penv, args, true);
5752 /* JNI invocation table *******************************************************/
5754 const struct JNIInvokeInterface _Jv_JNIInvokeInterface = {
5759 _Jv_JNI_DestroyJavaVM,
5760 _Jv_JNI_AttachCurrentThread,
5761 _Jv_JNI_DetachCurrentThread,
5763 _Jv_JNI_AttachCurrentThreadAsDaemon
5767 /* JNI function table *********************************************************/
5769 struct JNINativeInterface _Jv_JNINativeInterface = {
5776 _Jv_JNI_DefineClass,
5778 _Jv_JNI_FromReflectedMethod,
5779 _Jv_JNI_FromReflectedField,
5780 _Jv_JNI_ToReflectedMethod,
5781 _Jv_JNI_GetSuperclass,
5782 _Jv_JNI_IsAssignableFrom,
5783 _Jv_JNI_ToReflectedField,
5787 _Jv_JNI_ExceptionOccurred,
5788 _Jv_JNI_ExceptionDescribe,
5789 _Jv_JNI_ExceptionClear,
5791 _Jv_JNI_PushLocalFrame,
5792 _Jv_JNI_PopLocalFrame,
5794 _Jv_JNI_NewGlobalRef,
5795 _Jv_JNI_DeleteGlobalRef,
5796 _Jv_JNI_DeleteLocalRef,
5797 _Jv_JNI_IsSameObject,
5798 _Jv_JNI_NewLocalRef,
5799 _Jv_JNI_EnsureLocalCapacity,
5801 _Jv_JNI_AllocObject,
5806 _Jv_JNI_GetObjectClass,
5807 _Jv_JNI_IsInstanceOf,
5809 _Jv_JNI_GetMethodID,
5811 _Jv_JNI_CallObjectMethod,
5812 _Jv_JNI_CallObjectMethodV,
5813 _Jv_JNI_CallObjectMethodA,
5814 _Jv_JNI_CallBooleanMethod,
5815 _Jv_JNI_CallBooleanMethodV,
5816 _Jv_JNI_CallBooleanMethodA,
5817 _Jv_JNI_CallByteMethod,
5818 _Jv_JNI_CallByteMethodV,
5819 _Jv_JNI_CallByteMethodA,
5820 _Jv_JNI_CallCharMethod,
5821 _Jv_JNI_CallCharMethodV,
5822 _Jv_JNI_CallCharMethodA,
5823 _Jv_JNI_CallShortMethod,
5824 _Jv_JNI_CallShortMethodV,
5825 _Jv_JNI_CallShortMethodA,
5826 _Jv_JNI_CallIntMethod,
5827 _Jv_JNI_CallIntMethodV,
5828 _Jv_JNI_CallIntMethodA,
5829 _Jv_JNI_CallLongMethod,
5830 _Jv_JNI_CallLongMethodV,
5831 _Jv_JNI_CallLongMethodA,
5832 _Jv_JNI_CallFloatMethod,
5833 _Jv_JNI_CallFloatMethodV,
5834 _Jv_JNI_CallFloatMethodA,
5835 _Jv_JNI_CallDoubleMethod,
5836 _Jv_JNI_CallDoubleMethodV,
5837 _Jv_JNI_CallDoubleMethodA,
5838 _Jv_JNI_CallVoidMethod,
5839 _Jv_JNI_CallVoidMethodV,
5840 _Jv_JNI_CallVoidMethodA,
5842 _Jv_JNI_CallNonvirtualObjectMethod,
5843 _Jv_JNI_CallNonvirtualObjectMethodV,
5844 _Jv_JNI_CallNonvirtualObjectMethodA,
5845 _Jv_JNI_CallNonvirtualBooleanMethod,
5846 _Jv_JNI_CallNonvirtualBooleanMethodV,
5847 _Jv_JNI_CallNonvirtualBooleanMethodA,
5848 _Jv_JNI_CallNonvirtualByteMethod,
5849 _Jv_JNI_CallNonvirtualByteMethodV,
5850 _Jv_JNI_CallNonvirtualByteMethodA,
5851 _Jv_JNI_CallNonvirtualCharMethod,
5852 _Jv_JNI_CallNonvirtualCharMethodV,
5853 _Jv_JNI_CallNonvirtualCharMethodA,
5854 _Jv_JNI_CallNonvirtualShortMethod,
5855 _Jv_JNI_CallNonvirtualShortMethodV,
5856 _Jv_JNI_CallNonvirtualShortMethodA,
5857 _Jv_JNI_CallNonvirtualIntMethod,
5858 _Jv_JNI_CallNonvirtualIntMethodV,
5859 _Jv_JNI_CallNonvirtualIntMethodA,
5860 _Jv_JNI_CallNonvirtualLongMethod,
5861 _Jv_JNI_CallNonvirtualLongMethodV,
5862 _Jv_JNI_CallNonvirtualLongMethodA,
5863 _Jv_JNI_CallNonvirtualFloatMethod,
5864 _Jv_JNI_CallNonvirtualFloatMethodV,
5865 _Jv_JNI_CallNonvirtualFloatMethodA,
5866 _Jv_JNI_CallNonvirtualDoubleMethod,
5867 _Jv_JNI_CallNonvirtualDoubleMethodV,
5868 _Jv_JNI_CallNonvirtualDoubleMethodA,
5869 _Jv_JNI_CallNonvirtualVoidMethod,
5870 _Jv_JNI_CallNonvirtualVoidMethodV,
5871 _Jv_JNI_CallNonvirtualVoidMethodA,
5875 _Jv_JNI_GetObjectField,
5876 _Jv_JNI_GetBooleanField,
5877 _Jv_JNI_GetByteField,
5878 _Jv_JNI_GetCharField,
5879 _Jv_JNI_GetShortField,
5880 _Jv_JNI_GetIntField,
5881 _Jv_JNI_GetLongField,
5882 _Jv_JNI_GetFloatField,
5883 _Jv_JNI_GetDoubleField,
5884 _Jv_JNI_SetObjectField,
5885 _Jv_JNI_SetBooleanField,
5886 _Jv_JNI_SetByteField,
5887 _Jv_JNI_SetCharField,
5888 _Jv_JNI_SetShortField,
5889 _Jv_JNI_SetIntField,
5890 _Jv_JNI_SetLongField,
5891 _Jv_JNI_SetFloatField,
5892 _Jv_JNI_SetDoubleField,
5894 _Jv_JNI_GetStaticMethodID,
5896 _Jv_JNI_CallStaticObjectMethod,
5897 _Jv_JNI_CallStaticObjectMethodV,
5898 _Jv_JNI_CallStaticObjectMethodA,
5899 _Jv_JNI_CallStaticBooleanMethod,
5900 _Jv_JNI_CallStaticBooleanMethodV,
5901 _Jv_JNI_CallStaticBooleanMethodA,
5902 _Jv_JNI_CallStaticByteMethod,
5903 _Jv_JNI_CallStaticByteMethodV,
5904 _Jv_JNI_CallStaticByteMethodA,
5905 _Jv_JNI_CallStaticCharMethod,
5906 _Jv_JNI_CallStaticCharMethodV,
5907 _Jv_JNI_CallStaticCharMethodA,
5908 _Jv_JNI_CallStaticShortMethod,
5909 _Jv_JNI_CallStaticShortMethodV,
5910 _Jv_JNI_CallStaticShortMethodA,
5911 _Jv_JNI_CallStaticIntMethod,
5912 _Jv_JNI_CallStaticIntMethodV,
5913 _Jv_JNI_CallStaticIntMethodA,
5914 _Jv_JNI_CallStaticLongMethod,
5915 _Jv_JNI_CallStaticLongMethodV,
5916 _Jv_JNI_CallStaticLongMethodA,
5917 _Jv_JNI_CallStaticFloatMethod,
5918 _Jv_JNI_CallStaticFloatMethodV,
5919 _Jv_JNI_CallStaticFloatMethodA,
5920 _Jv_JNI_CallStaticDoubleMethod,
5921 _Jv_JNI_CallStaticDoubleMethodV,
5922 _Jv_JNI_CallStaticDoubleMethodA,
5923 _Jv_JNI_CallStaticVoidMethod,
5924 _Jv_JNI_CallStaticVoidMethodV,
5925 _Jv_JNI_CallStaticVoidMethodA,
5927 _Jv_JNI_GetStaticFieldID,
5929 _Jv_JNI_GetStaticObjectField,
5930 _Jv_JNI_GetStaticBooleanField,
5931 _Jv_JNI_GetStaticByteField,
5932 _Jv_JNI_GetStaticCharField,
5933 _Jv_JNI_GetStaticShortField,
5934 _Jv_JNI_GetStaticIntField,
5935 _Jv_JNI_GetStaticLongField,
5936 _Jv_JNI_GetStaticFloatField,
5937 _Jv_JNI_GetStaticDoubleField,
5938 _Jv_JNI_SetStaticObjectField,
5939 _Jv_JNI_SetStaticBooleanField,
5940 _Jv_JNI_SetStaticByteField,
5941 _Jv_JNI_SetStaticCharField,
5942 _Jv_JNI_SetStaticShortField,
5943 _Jv_JNI_SetStaticIntField,
5944 _Jv_JNI_SetStaticLongField,
5945 _Jv_JNI_SetStaticFloatField,
5946 _Jv_JNI_SetStaticDoubleField,
5949 _Jv_JNI_GetStringLength,
5950 _Jv_JNI_GetStringChars,
5951 _Jv_JNI_ReleaseStringChars,
5953 _Jv_JNI_NewStringUTF,
5954 _Jv_JNI_GetStringUTFLength,
5955 _Jv_JNI_GetStringUTFChars,
5956 _Jv_JNI_ReleaseStringUTFChars,
5958 _Jv_JNI_GetArrayLength,
5960 _Jv_JNI_NewObjectArray,
5961 _Jv_JNI_GetObjectArrayElement,
5962 _Jv_JNI_SetObjectArrayElement,
5964 _Jv_JNI_NewBooleanArray,
5965 _Jv_JNI_NewByteArray,
5966 _Jv_JNI_NewCharArray,
5967 _Jv_JNI_NewShortArray,
5968 _Jv_JNI_NewIntArray,
5969 _Jv_JNI_NewLongArray,
5970 _Jv_JNI_NewFloatArray,
5971 _Jv_JNI_NewDoubleArray,
5973 _Jv_JNI_GetBooleanArrayElements,
5974 _Jv_JNI_GetByteArrayElements,
5975 _Jv_JNI_GetCharArrayElements,
5976 _Jv_JNI_GetShortArrayElements,
5977 _Jv_JNI_GetIntArrayElements,
5978 _Jv_JNI_GetLongArrayElements,
5979 _Jv_JNI_GetFloatArrayElements,
5980 _Jv_JNI_GetDoubleArrayElements,
5982 _Jv_JNI_ReleaseBooleanArrayElements,
5983 _Jv_JNI_ReleaseByteArrayElements,
5984 _Jv_JNI_ReleaseCharArrayElements,
5985 _Jv_JNI_ReleaseShortArrayElements,
5986 _Jv_JNI_ReleaseIntArrayElements,
5987 _Jv_JNI_ReleaseLongArrayElements,
5988 _Jv_JNI_ReleaseFloatArrayElements,
5989 _Jv_JNI_ReleaseDoubleArrayElements,
5991 _Jv_JNI_GetBooleanArrayRegion,
5992 _Jv_JNI_GetByteArrayRegion,
5993 _Jv_JNI_GetCharArrayRegion,
5994 _Jv_JNI_GetShortArrayRegion,
5995 _Jv_JNI_GetIntArrayRegion,
5996 _Jv_JNI_GetLongArrayRegion,
5997 _Jv_JNI_GetFloatArrayRegion,
5998 _Jv_JNI_GetDoubleArrayRegion,
5999 _Jv_JNI_SetBooleanArrayRegion,
6000 _Jv_JNI_SetByteArrayRegion,
6001 _Jv_JNI_SetCharArrayRegion,
6002 _Jv_JNI_SetShortArrayRegion,
6003 _Jv_JNI_SetIntArrayRegion,
6004 _Jv_JNI_SetLongArrayRegion,
6005 _Jv_JNI_SetFloatArrayRegion,
6006 _Jv_JNI_SetDoubleArrayRegion,
6008 _Jv_JNI_RegisterNatives,
6009 _Jv_JNI_UnregisterNatives,
6011 _Jv_JNI_MonitorEnter,
6012 _Jv_JNI_MonitorExit,
6016 /* new JNI 1.2 functions */
6018 _Jv_JNI_GetStringRegion,
6019 _Jv_JNI_GetStringUTFRegion,
6021 _Jv_JNI_GetPrimitiveArrayCritical,
6022 _Jv_JNI_ReleasePrimitiveArrayCritical,
6024 _Jv_JNI_GetStringCritical,
6025 _Jv_JNI_ReleaseStringCritical,
6027 _Jv_JNI_NewWeakGlobalRef,
6028 _Jv_JNI_DeleteWeakGlobalRef,
6030 _Jv_JNI_ExceptionCheck,
6032 /* new JNI 1.4 functions */
6034 _Jv_JNI_NewDirectByteBuffer,
6035 _Jv_JNI_GetDirectBufferAddress,
6036 _Jv_JNI_GetDirectBufferCapacity
6040 /* Invocation API Functions ***************************************************/
6042 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6044 Returns a default configuration for the Java VM.
6046 *******************************************************************************/
6048 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6050 JavaVMInitArgs *_vm_args;
6052 _vm_args = (JavaVMInitArgs *) vm_args;
6054 /* GNU classpath currently supports JNI 1.2 */
6056 switch (_vm_args->version) {
6057 case JNI_VERSION_1_1:
6058 _vm_args->version = JNI_VERSION_1_1;
6061 case JNI_VERSION_1_2:
6062 case JNI_VERSION_1_4:
6063 _vm_args->ignoreUnrecognized = JNI_FALSE;
6064 _vm_args->options = NULL;
6065 _vm_args->nOptions = 0;
6076 /* JNI_GetCreatedJavaVMs *******************************************************
6078 Returns all Java VMs that have been created. Pointers to VMs are written in
6079 the buffer vmBuf in the order they are created. At most bufLen number of
6080 entries will be written. The total number of created VMs is returned in
6083 *******************************************************************************/
6085 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6087 log_text("JNI_GetCreatedJavaVMs: IMPLEMENT ME!!!");
6093 /* JNI_CreateJavaVM ************************************************************
6095 Loads and initializes a Java VM. The current thread becomes the main thread.
6096 Sets the env argument to the JNI interface pointer of the main thread.
6098 *******************************************************************************/
6100 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6102 /* actually create the JVM */
6104 if (!vm_createjvm(p_vm, p_env, vm_args))
6112 * These are local overrides for various environment variables in Emacs.
6113 * Please do not remove this and leave it at the end of the file, where
6114 * Emacs will automagically detect them.
6115 * ---------------------------------------------------------------------
6118 * indent-tabs-mode: t
6122 * vim:noexpandtab:sw=4:ts=4: