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 8374 2007-08-21 10:20:33Z michi $
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
41 #include "native/jni.h"
42 #include "native/llni.h"
43 #include "native/localref.h"
44 #include "native/native.h"
46 #if defined(ENABLE_JAVASE)
47 # if defined(WITH_CLASSPATH_GNU)
48 # include "native/include/gnu_classpath_Pointer.h"
50 # if SIZEOF_VOID_P == 8
51 # include "native/include/gnu_classpath_Pointer64.h"
53 # include "native/include/gnu_classpath_Pointer32.h"
58 #include "native/include/java_lang_Object.h"
59 #include "native/include/java_lang_Byte.h"
60 #include "native/include/java_lang_Character.h"
61 #include "native/include/java_lang_Short.h"
62 #include "native/include/java_lang_Integer.h"
63 #include "native/include/java_lang_Boolean.h"
64 #include "native/include/java_lang_Long.h"
65 #include "native/include/java_lang_Float.h"
66 #include "native/include/java_lang_Double.h"
67 #include "native/include/java_lang_String.h"
68 #include "native/include/java_lang_Throwable.h"
70 #if defined(ENABLE_JAVASE)
71 # if defined(WITH_CLASSPATH_SUN)
72 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
75 # include "native/include/java_lang_ClassLoader.h"
77 # include "native/include/java_lang_reflect_Constructor.h"
78 # include "native/include/java_lang_reflect_Field.h"
79 # include "native/include/java_lang_reflect_Method.h"
81 # include "native/include/java_nio_Buffer.h"
83 # if defined(WITH_CLASSPATH_GNU)
84 # include "native/include/java_nio_DirectByteBufferImpl.h"
88 #if defined(ENABLE_JVMTI)
89 # include "native/jvmti/cacaodbg.h"
92 #include "native/vm/java_lang_Class.h"
94 #if defined(ENABLE_JAVASE)
95 # include "native/vm/java_lang_ClassLoader.h"
96 # include "native/vm/reflect.h"
99 #include "threads/lock-common.h"
100 #include "threads/threads-common.h"
102 #include "toolbox/logging.h"
104 #include "vm/builtin.h"
105 #include "vm/exceptions.h"
106 #include "vm/global.h"
107 #include "vm/initialize.h"
108 #include "vm/primitive.h"
109 #include "vm/resolve.h"
110 #include "vm/stringlocal.h"
113 #include "vm/jit/asmpart.h"
114 #include "vm/jit/jit.h"
115 #include "vm/jit/stacktrace.h"
117 #include "vmcore/loader.h"
118 #include "vmcore/options.h"
119 #include "vmcore/statistics.h"
122 /* debug **********************************************************************/
125 # define TRACEJNICALLS(format, ...) \
127 if (opt_TraceJNICalls) { \
128 log_println((format), __VA_ARGS__); \
132 # define TRACEJNICALLS(format, ...)
136 /* global variables ***********************************************************/
138 /* global reference table *****************************************************/
140 /* hashsize must be power of 2 */
142 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
144 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
147 /* direct buffer stuff ********************************************************/
149 #if defined(ENABLE_JAVASE)
150 static classinfo *class_java_nio_Buffer;
151 static classinfo *class_java_nio_DirectByteBufferImpl;
152 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
154 # if defined(WITH_CLASSPATH_GNU)
155 # if SIZEOF_VOID_P == 8
156 static classinfo *class_gnu_classpath_Pointer64;
158 static classinfo *class_gnu_classpath_Pointer32;
162 static methodinfo *dbbirw_init;
166 /* accessing instance fields macros *******************************************/
168 #define SET_FIELD(o,type,f,value) \
169 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset))) = (type) (value)
171 #define GET_FIELD(o,type,f) \
172 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset)))
175 /* some forward declarations **************************************************/
177 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
180 /* jni_init ********************************************************************
182 Initialize the JNI subsystem.
184 *******************************************************************************/
188 /* create global ref hashtable */
190 hashtable_global_ref = NEW(hashtable);
192 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
195 #if defined(ENABLE_JAVASE)
196 /* direct buffer stuff */
198 if (!(class_java_nio_Buffer =
199 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
200 !link_class(class_java_nio_Buffer))
203 # if defined(WITH_CLASSPATH_GNU)
204 if (!(class_java_nio_DirectByteBufferImpl =
205 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
206 !link_class(class_java_nio_DirectByteBufferImpl))
209 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
210 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
211 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
215 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
217 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
220 # if SIZEOF_VOID_P == 8
221 if (!(class_gnu_classpath_Pointer64 =
222 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
223 !link_class(class_gnu_classpath_Pointer64))
226 if (!(class_gnu_classpath_Pointer32 =
227 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
228 !link_class(class_gnu_classpath_Pointer32))
232 #endif /* defined(ENABLE_JAVASE) */
238 /* _Jv_jni_CallObjectMethod ****************************************************
240 Internal function to call Java Object methods.
242 *******************************************************************************/
244 static java_handle_t *_Jv_jni_CallObjectMethod(java_handle_t *o,
246 methodinfo *m, va_list ap)
251 STATISTICS(jniinvokation());
254 exceptions_throw_nullpointerexception();
258 /* Class initialization is done by the JIT compiler. This is ok
259 since a static method always belongs to the declaring class. */
261 if (m->flags & ACC_STATIC) {
262 /* For static methods we reset the object. */
267 /* for convenience */
272 /* For instance methods we make a virtual function table lookup. */
274 resm = method_vftbl_lookup(vftbl, m);
277 STATISTICS(jnicallXmethodnvokation());
279 ro = vm_call_method_valist(resm, o, ap);
285 /* _Jv_jni_CallObjectMethodA ***************************************************
287 Internal function to call Java Object methods.
289 *******************************************************************************/
291 static java_handle_t *_Jv_jni_CallObjectMethodA(java_handle_t *o,
299 STATISTICS(jniinvokation());
302 exceptions_throw_nullpointerexception();
306 /* Class initialization is done by the JIT compiler. This is ok
307 since a static method always belongs to the declaring class. */
309 if (m->flags & ACC_STATIC) {
310 /* For static methods we reset the object. */
315 /* for convenience */
320 /* For instance methods we make a virtual function table lookup. */
322 resm = method_vftbl_lookup(vftbl, m);
325 STATISTICS(jnicallXmethodnvokation());
327 ro = vm_call_method_jvalue(resm, o, args);
333 /* _Jv_jni_CallIntMethod *******************************************************
335 Internal function to call Java integer class methods (boolean,
336 byte, char, short, int).
338 *******************************************************************************/
340 static jint _Jv_jni_CallIntMethod(java_handle_t *o, vftbl_t *vftbl,
341 methodinfo *m, va_list ap)
346 STATISTICS(jniinvokation());
349 exceptions_throw_nullpointerexception();
353 /* Class initialization is done by the JIT compiler. This is ok
354 since a static method always belongs to the declaring class. */
356 if (m->flags & ACC_STATIC) {
357 /* For static methods we reset the object. */
362 /* for convenience */
367 /* For instance methods we make a virtual function table lookup. */
369 resm = method_vftbl_lookup(vftbl, m);
372 STATISTICS(jnicallXmethodnvokation());
374 i = vm_call_method_int_valist(resm, o, ap);
380 /* _Jv_jni_CallIntMethodA ******************************************************
382 Internal function to call Java integer class methods (boolean,
383 byte, char, short, int).
385 *******************************************************************************/
387 static jint _Jv_jni_CallIntMethodA(java_handle_t *o, vftbl_t *vftbl,
388 methodinfo *m, const jvalue *args)
393 STATISTICS(jniinvokation());
396 exceptions_throw_nullpointerexception();
400 /* Class initialization is done by the JIT compiler. This is ok
401 since a static method always belongs to the declaring class. */
403 if (m->flags & ACC_STATIC) {
404 /* For static methods we reset the object. */
409 /* for convenience */
414 /* For instance methods we make a virtual function table lookup. */
416 resm = method_vftbl_lookup(vftbl, m);
419 STATISTICS(jnicallXmethodnvokation());
421 i = vm_call_method_int_jvalue(resm, o, args);
427 /* _Jv_jni_CallLongMethod ******************************************************
429 Internal function to call Java long methods.
431 *******************************************************************************/
433 static jlong _Jv_jni_CallLongMethod(java_handle_t *o, vftbl_t *vftbl,
434 methodinfo *m, va_list ap)
439 STATISTICS(jniinvokation());
442 exceptions_throw_nullpointerexception();
446 /* Class initialization is done by the JIT compiler. This is ok
447 since a static method always belongs to the declaring class. */
449 if (m->flags & ACC_STATIC) {
450 /* For static methods we reset the object. */
455 /* for convenience */
460 /* For instance methods we make a virtual function table lookup. */
462 resm = method_vftbl_lookup(vftbl, m);
465 STATISTICS(jnicallXmethodnvokation());
467 l = vm_call_method_long_valist(resm, o, ap);
473 /* _Jv_jni_CallLongMethodA *****************************************************
475 Internal function to call Java long methods.
477 *******************************************************************************/
479 static jlong _Jv_jni_CallLongMethodA(java_handle_t *o, vftbl_t *vftbl,
480 methodinfo *m, const jvalue *args)
485 STATISTICS(jniinvokation());
488 exceptions_throw_nullpointerexception();
492 /* Class initialization is done by the JIT compiler. This is ok
493 since a static method always belongs to the declaring class. */
495 if (m->flags & ACC_STATIC) {
496 /* For static methods we reset the object. */
501 /* for convenience */
506 /* For instance methods we make a virtual function table lookup. */
508 resm = method_vftbl_lookup(vftbl, m);
511 STATISTICS(jnicallXmethodnvokation());
513 l = vm_call_method_long_jvalue(resm, o, args);
519 /* _Jv_jni_CallFloatMethod *****************************************************
521 Internal function to call Java float methods.
523 *******************************************************************************/
525 static jfloat _Jv_jni_CallFloatMethod(java_handle_t *o, vftbl_t *vftbl,
526 methodinfo *m, va_list ap)
531 /* Class initialization is done by the JIT compiler. This is ok
532 since a static method always belongs to the declaring class. */
534 if (m->flags & ACC_STATIC) {
535 /* For static methods we reset the object. */
540 /* for convenience */
545 /* For instance methods we make a virtual function table lookup. */
547 resm = method_vftbl_lookup(vftbl, m);
550 STATISTICS(jnicallXmethodnvokation());
552 f = vm_call_method_float_valist(resm, o, ap);
558 /* _Jv_jni_CallFloatMethodA ****************************************************
560 Internal function to call Java float methods.
562 *******************************************************************************/
564 static jfloat _Jv_jni_CallFloatMethodA(java_handle_t *o, vftbl_t *vftbl,
565 methodinfo *m, const jvalue *args)
570 /* Class initialization is done by the JIT compiler. This is ok
571 since a static method always belongs to the declaring class. */
573 if (m->flags & ACC_STATIC) {
574 /* For static methods we reset the object. */
579 /* for convenience */
584 /* For instance methods we make a virtual function table lookup. */
586 resm = method_vftbl_lookup(vftbl, m);
589 STATISTICS(jnicallXmethodnvokation());
591 f = vm_call_method_float_jvalue(resm, o, args);
597 /* _Jv_jni_CallDoubleMethod ****************************************************
599 Internal function to call Java double methods.
601 *******************************************************************************/
603 static jdouble _Jv_jni_CallDoubleMethod(java_handle_t *o, vftbl_t *vftbl,
604 methodinfo *m, va_list ap)
609 /* Class initialization is done by the JIT compiler. This is ok
610 since a static method always belongs to the declaring class. */
612 if (m->flags & ACC_STATIC) {
613 /* For static methods we reset the object. */
618 /* for convenience */
623 /* For instance methods we make a virtual function table lookup. */
625 resm = method_vftbl_lookup(vftbl, m);
628 d = vm_call_method_double_valist(resm, o, ap);
634 /* _Jv_jni_CallDoubleMethodA ***************************************************
636 Internal function to call Java double methods.
638 *******************************************************************************/
640 static jdouble _Jv_jni_CallDoubleMethodA(java_handle_t *o, vftbl_t *vftbl,
641 methodinfo *m, const jvalue *args)
646 /* Class initialization is done by the JIT compiler. This is ok
647 since a static method always belongs to the declaring class. */
649 if (m->flags & ACC_STATIC) {
650 /* For static methods we reset the object. */
655 /* for convenience */
660 /* For instance methods we make a virtual function table lookup. */
662 resm = method_vftbl_lookup(vftbl, m);
665 d = vm_call_method_double_jvalue(resm, o, args);
671 /* _Jv_jni_CallVoidMethod ******************************************************
673 Internal function to call Java void methods.
675 *******************************************************************************/
677 static void _Jv_jni_CallVoidMethod(java_handle_t *o, vftbl_t *vftbl,
678 methodinfo *m, va_list ap)
683 exceptions_throw_nullpointerexception();
687 /* Class initialization is done by the JIT compiler. This is ok
688 since a static method always belongs to the declaring class. */
690 if (m->flags & ACC_STATIC) {
691 /* For static methods we reset the object. */
696 /* for convenience */
701 /* For instance methods we make a virtual function table lookup. */
703 resm = method_vftbl_lookup(vftbl, m);
706 STATISTICS(jnicallXmethodnvokation());
708 (void) vm_call_method_valist(resm, o, ap);
712 /* _Jv_jni_CallVoidMethodA *****************************************************
714 Internal function to call Java void methods.
716 *******************************************************************************/
718 static void _Jv_jni_CallVoidMethodA(java_handle_t *o, vftbl_t *vftbl,
719 methodinfo *m, const jvalue *args)
724 exceptions_throw_nullpointerexception();
728 /* Class initialization is done by the JIT compiler. This is ok
729 since a static method always belongs to the declaring class. */
731 if (m->flags & ACC_STATIC) {
732 /* For static methods we reset the object. */
737 /* for convenience */
742 /* For instance methods we make a virtual function table lookup. */
744 resm = method_vftbl_lookup(vftbl, m);
747 STATISTICS(jnicallXmethodnvokation());
749 (void) vm_call_method_jvalue(resm, o, args);
753 /* _Jv_jni_invokeNative ********************************************************
755 Invoke a method on the given object with the given arguments.
757 For instance methods OBJ must be != NULL and the method is looked up
758 in the vftbl of the object.
760 For static methods, OBJ is ignored.
762 *******************************************************************************/
764 java_handle_t *_Jv_jni_invokeNative(methodinfo *m, java_handle_t *o,
765 java_handle_objectarray_t *params)
777 exceptions_throw_nullpointerexception();
781 argcount = m->parseddesc->paramcount;
782 paramcount = argcount;
784 /* if method is non-static, remove the `this' pointer */
786 if (!(m->flags & ACC_STATIC))
789 /* For instance methods the object has to be an instance of the
790 class the method belongs to. For static methods the obj
791 parameter is ignored. */
793 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
794 exceptions_throw_illegalargumentexception();
798 /* check if we got the right number of arguments */
800 if (((params == NULL) && (paramcount != 0)) ||
801 (params && (LLNI_array_size(params) != paramcount)))
803 exceptions_throw_illegalargumentexception();
807 /* for instance methods we need an object */
809 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
810 /* XXX not sure if that is the correct exception */
811 exceptions_throw_nullpointerexception();
815 /* for static methods, zero object to make subsequent code simpler */
816 if (m->flags & ACC_STATIC)
820 /* for instance methods we must do a vftbl lookup */
821 resm = method_vftbl_lookup(o->vftbl, m);
824 /* for static methods, just for convenience */
828 /* mark start of dump memory area */
830 dumpsize = dump_size();
832 /* Fill the argument array from a object-array. */
834 array = vm_array_from_objectarray(resm, o, params);
836 /* The array can be NULL if we don't have any arguments to pass
837 and the architecture does not have any argument registers
838 (e.g. i386). In that case we additionally check for an
841 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
842 /* release dump area */
844 dump_release(dumpsize);
849 switch (resm->parseddesc->returntype.decltype) {
851 (void) vm_call_array(resm, array);
855 case PRIMITIVETYPE_BOOLEAN:
856 case PRIMITIVETYPE_BYTE:
857 case PRIMITIVETYPE_CHAR:
858 case PRIMITIVETYPE_SHORT:
859 case PRIMITIVETYPE_INT:
860 value.i = vm_call_int_array(resm, array);
861 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
864 case PRIMITIVETYPE_LONG:
865 value.l = vm_call_long_array(resm, array);
866 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
869 case PRIMITIVETYPE_FLOAT:
870 value.f = vm_call_float_array(resm, array);
871 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
874 case PRIMITIVETYPE_DOUBLE:
875 value.d = vm_call_double_array(resm, array);
876 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
880 ro = vm_call_array(resm, array);
884 vm_abort("_Jv_jni_invokeNative: invalid return type %d", resm->parseddesc->returntype.decltype);
887 xptr = exceptions_get_exception();
890 /* clear exception pointer, we are calling JIT code again */
892 exceptions_clear_exception();
894 exceptions_throw_invocationtargetexception(xptr);
897 /* release dump area */
899 dump_release(dumpsize);
905 /* GetVersion ******************************************************************
907 Returns the major version number in the higher 16 bits and the
908 minor version number in the lower 16 bits.
910 *******************************************************************************/
912 jint _Jv_JNI_GetVersion(JNIEnv *env)
914 STATISTICS(jniinvokation());
916 /* we support JNI 1.4 */
918 return JNI_VERSION_1_4;
922 /* Class Operations ***********************************************************/
924 /* DefineClass *****************************************************************
926 Loads a class from a buffer of raw class data. The buffer
927 containing the raw class data is not referenced by the VM after the
928 DefineClass call returns, and it may be discarded if desired.
930 *******************************************************************************/
932 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
933 const jbyte *buf, jsize bufLen)
935 #if defined(ENABLE_JAVASE)
940 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
942 u = utf_new_char(name);
943 cl = loader_hashtable_classloader_add((java_handle_t *) loader);
945 c = class_define(u, cl, bufLen, (const uint8_t *) buf);
947 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
949 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
951 /* keep compiler happy */
958 /* FindClass *******************************************************************
960 This function loads a locally-defined class. It searches the
961 directories and zip files specified by the CLASSPATH environment
962 variable for the class with the specified name.
964 *******************************************************************************/
966 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
968 #if defined(ENABLE_JAVASE)
973 STATISTICS(jniinvokation());
975 u = utf_new_char_classname((char *) name);
977 /* Check stacktrace for classloader, if one found use it,
978 otherwise use the system classloader. */
980 /* Quote from the JNI documentation:
982 In the Java 2 Platform, FindClass locates the class loader
983 associated with the current native method. If the native code
984 belongs to a system class, no class loader will be
985 involved. Otherwise, the proper class loader will be invoked to
986 load and link the named class. When FindClass is called through
987 the Invocation Interface, there is no current native method or
988 its associated class loader. In that case, the result of
989 ClassLoader.getBaseClassLoader is used." */
991 cc = stacktrace_getCurrentClass();
994 c = load_class_from_sysloader(u);
996 c = load_class_from_classloader(u, cc->classloader);
1004 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1006 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1008 /* keep compiler happy */
1015 /* GetSuperclass ***************************************************************
1017 If clazz represents any class other than the class Object, then
1018 this function returns the object that represents the superclass of
1019 the class specified by clazz.
1021 *******************************************************************************/
1023 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1028 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1030 c = LLNI_classinfo_unwrap(sub);
1035 super = class_get_superclass(c);
1037 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1041 /* IsAssignableFrom ************************************************************
1043 Determines whether an object of sub can be safely cast to sup.
1045 *******************************************************************************/
1047 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1049 java_lang_Class *csup;
1050 java_lang_Class *csub;
1052 csup = (java_lang_Class *) sup;
1053 csub = (java_lang_Class *) sub;
1055 STATISTICS(jniinvokation());
1057 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1061 /* Throw ***********************************************************************
1063 Causes a java.lang.Throwable object to be thrown.
1065 *******************************************************************************/
1067 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1071 STATISTICS(jniinvokation());
1073 o = (java_handle_t *) obj;
1075 exceptions_set_exception(o);
1081 /* ThrowNew ********************************************************************
1083 Constructs an exception object from the specified class with the
1084 message specified by message and causes that exception to be
1087 *******************************************************************************/
1089 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1095 STATISTICS(jniinvokation());
1097 c = LLNI_classinfo_unwrap(clazz);
1100 s = javastring_new_from_utf_string(msg);
1102 /* instantiate exception object */
1104 o = native_new_and_init_string(c, s);
1109 exceptions_set_exception(o);
1115 /* ExceptionOccurred ***********************************************************
1117 Determines if an exception is being thrown. The exception stays
1118 being thrown until either the native code calls ExceptionClear(),
1119 or the Java code handles the exception.
1121 *******************************************************************************/
1123 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1127 STATISTICS(jniinvokation());
1129 o = exceptions_get_exception();
1131 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1135 /* ExceptionDescribe ***********************************************************
1137 Prints an exception and a backtrace of the stack to a system
1138 error-reporting channel, such as stderr. This is a convenience
1139 routine provided for debugging.
1141 *******************************************************************************/
1143 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1148 STATISTICS(jniinvokation());
1150 o = exceptions_get_exception();
1153 /* clear exception, because we are calling jit code again */
1155 exceptions_clear_exception();
1157 /* get printStackTrace method from exception class */
1159 m = class_resolveclassmethod(o->vftbl->class,
1160 utf_printStackTrace,
1166 /* XXX what should we do? */
1169 /* print the stacktrace */
1171 (void) vm_call_method(m, o);
1176 /* ExceptionClear **************************************************************
1178 Clears any exception that is currently being thrown. If no
1179 exception is currently being thrown, this routine has no effect.
1181 *******************************************************************************/
1183 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1185 STATISTICS(jniinvokation());
1187 exceptions_clear_exception();
1191 /* FatalError ******************************************************************
1193 Raises a fatal error and does not expect the VM to recover. This
1194 function does not return.
1196 *******************************************************************************/
1198 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1200 STATISTICS(jniinvokation());
1202 /* this seems to be the best way */
1204 vm_abort("JNI Fatal error: %s", msg);
1208 /* PushLocalFrame **************************************************************
1210 Creates a new local reference frame, in which at least a given
1211 number of local references can be created.
1213 *******************************************************************************/
1215 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1217 STATISTICS(jniinvokation());
1222 /* add new local reference frame to current table */
1224 if (!localref_frame_push(capacity))
1231 /* PopLocalFrame ***************************************************************
1233 Pops off the current local reference frame, frees all the local
1234 references, and returns a local reference in the previous local
1235 reference frame for the given result object.
1237 *******************************************************************************/
1239 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1241 STATISTICS(jniinvokation());
1243 /* release all current local frames */
1245 localref_frame_pop_all();
1247 /* add local reference and return the value */
1249 return _Jv_JNI_NewLocalRef(env, result);
1253 /* DeleteLocalRef **************************************************************
1255 Deletes the local reference pointed to by localRef.
1257 *******************************************************************************/
1259 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1262 localref_table *lrt;
1265 STATISTICS(jniinvokation());
1267 o = (java_handle_t *) localRef;
1269 /* get local reference table (thread specific) */
1271 lrt = LOCALREFTABLE;
1273 /* go through all local frames */
1275 for (; lrt != NULL; lrt = lrt->prev) {
1277 /* and try to remove the reference */
1279 for (i = 0; i < lrt->capacity; i++) {
1280 if (lrt->refs[i] == o) {
1281 lrt->refs[i] = NULL;
1289 /* this should not happen */
1291 /* if (opt_checkjni) */
1292 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1293 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1297 /* IsSameObject ****************************************************************
1299 Tests whether two references refer to the same Java object.
1301 *******************************************************************************/
1303 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1305 STATISTICS(jniinvokation());
1314 /* NewLocalRef *****************************************************************
1316 Creates a new local reference that refers to the same object as ref.
1318 *******************************************************************************/
1320 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1322 java_handle_t *localref;
1324 STATISTICS(jniinvokation());
1329 /* insert the reference */
1331 localref = localref_add(ref);
1337 /* EnsureLocalCapacity *********************************************************
1339 Ensures that at least a given number of local references can be
1340 created in the current thread
1342 *******************************************************************************/
1344 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1346 localref_table *lrt;
1348 STATISTICS(jniinvokation());
1350 /* get local reference table (thread specific) */
1352 lrt = LOCALREFTABLE;
1354 /* check if capacity elements are available in the local references table */
1356 if ((lrt->used + capacity) > lrt->capacity)
1357 return _Jv_JNI_PushLocalFrame(env, capacity);
1363 /* AllocObject *****************************************************************
1365 Allocates a new Java object without invoking any of the
1366 constructors for the object. Returns a reference to the object.
1368 *******************************************************************************/
1370 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1375 STATISTICS(jniinvokation());
1377 c = LLNI_classinfo_unwrap(clazz);
1379 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1380 exceptions_throw_instantiationexception(c);
1386 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1390 /* NewObject *******************************************************************
1392 Programmers place all arguments that are to be passed to the
1393 constructor immediately following the methodID
1394 argument. NewObject() accepts these arguments and passes them to
1395 the Java method that the programmer wishes to invoke.
1397 *******************************************************************************/
1399 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1406 STATISTICS(jniinvokation());
1408 c = LLNI_classinfo_unwrap(clazz);
1409 m = (methodinfo *) methodID;
1418 /* call constructor */
1420 va_start(ap, methodID);
1421 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1424 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1428 /* NewObjectV ******************************************************************
1430 Programmers place all arguments that are to be passed to the
1431 constructor in an args argument of type va_list that immediately
1432 follows the methodID argument. NewObjectV() accepts these
1433 arguments, and, in turn, passes them to the Java method that the
1434 programmer wishes to invoke.
1436 *******************************************************************************/
1438 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1445 STATISTICS(jniinvokation());
1447 c = LLNI_classinfo_unwrap(clazz);
1448 m = (methodinfo *) methodID;
1457 /* call constructor */
1459 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1461 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1465 /* NewObjectA *****************************************************************
1467 Programmers place all arguments that are to be passed to the
1468 constructor in an args array of jvalues that immediately follows
1469 the methodID argument. NewObjectA() accepts the arguments in this
1470 array, and, in turn, passes them to the Java method that the
1471 programmer wishes to invoke.
1473 *******************************************************************************/
1475 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1482 STATISTICS(jniinvokation());
1484 c = LLNI_classinfo_unwrap(clazz);
1485 m = (methodinfo *) methodID;
1494 /* call constructor */
1496 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1498 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1502 /* GetObjectClass **************************************************************
1504 Returns the class of an object.
1506 *******************************************************************************/
1508 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1513 STATISTICS(jniinvokation());
1515 o = (java_handle_t *) obj;
1517 if ((o == NULL) || (o->vftbl == NULL))
1520 c = o->vftbl->class;
1522 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1526 /* IsInstanceOf ****************************************************************
1528 Tests whether an object is an instance of a class.
1530 *******************************************************************************/
1532 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1535 java_lang_Object *o;
1537 STATISTICS(jniinvokation());
1539 c = (java_lang_Class *) clazz;
1540 o = (java_lang_Object *) obj;
1542 return _Jv_java_lang_Class_isInstance(c, o);
1546 /* Reflection Support *********************************************************/
1548 /* FromReflectedMethod *********************************************************
1550 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1551 object to a method ID.
1553 *******************************************************************************/
1555 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1557 #if defined(ENABLE_JAVASE)
1563 STATISTICS(jniinvokation());
1565 o = (java_handle_t *) method;
1570 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
1571 java_lang_reflect_Method *rm;
1573 rm = (java_lang_reflect_Method *) method;
1574 LLNI_field_get_cls(rm, clazz, c);
1575 LLNI_field_get_val(rm, slot , slot);
1577 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
1578 java_lang_reflect_Constructor *rc;
1580 rc = (java_lang_reflect_Constructor *) method;
1581 LLNI_field_get_cls(rc, clazz, c);
1582 LLNI_field_get_val(rc, slot , slot);
1587 m = &(c->methods[slot]);
1589 return (jmethodID) m;
1591 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1593 /* keep compiler happy */
1600 /* FromReflectedField **********************************************************
1602 Converts a java.lang.reflect.Field to a field ID.
1604 *******************************************************************************/
1606 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1608 #if defined(ENABLE_JAVASE)
1609 java_lang_reflect_Field *rf;
1614 STATISTICS(jniinvokation());
1616 rf = (java_lang_reflect_Field *) field;
1621 LLNI_field_get_cls(rf, clazz, c);
1622 LLNI_field_get_val(rf, slot , slot);
1623 f = &(c->fields[slot]);
1625 return (jfieldID) f;
1627 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1629 /* keep compiler happy */
1636 /* ToReflectedMethod ***********************************************************
1638 Converts a method ID derived from cls to an instance of the
1639 java.lang.reflect.Method class or to an instance of the
1640 java.lang.reflect.Constructor class.
1642 *******************************************************************************/
1644 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1647 #if defined(ENABLE_JAVASE)
1649 java_lang_reflect_Constructor *rc;
1650 java_lang_reflect_Method *rm;
1652 STATISTICS(jniinvokation());
1654 m = (methodinfo *) methodID;
1656 /* HotSpot does the same assert. */
1658 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
1660 if (m->name == utf_init) {
1661 rc = reflect_constructor_new(m);
1663 return (jobject) rc;
1666 rm = reflect_method_new(m);
1668 return (jobject) rm;
1671 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
1673 /* keep compiler happy */
1680 /* ToReflectedField ************************************************************
1682 Converts a field ID derived from cls to an instance of the
1683 java.lang.reflect.Field class.
1685 *******************************************************************************/
1687 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1690 STATISTICS(jniinvokation());
1692 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1698 /* Calling Instance Methods ***************************************************/
1700 /* GetMethodID *****************************************************************
1702 Returns the method ID for an instance (nonstatic) method of a class
1703 or interface. The method may be defined in one of the clazz's
1704 superclasses and inherited by clazz. The method is determined by
1705 its name and signature.
1707 GetMethodID() causes an uninitialized class to be initialized.
1709 *******************************************************************************/
1711 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1719 STATISTICS(jniinvokation());
1721 c = LLNI_classinfo_unwrap(clazz);
1726 if (!(c->state & CLASS_INITIALIZED))
1727 if (!initialize_class(c))
1730 /* try to get the method of the class or one of it's superclasses */
1732 uname = utf_new_char((char *) name);
1733 udesc = utf_new_char((char *) sig);
1735 m = class_resolvemethod(c, uname, udesc);
1737 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1738 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1743 return (jmethodID) m;
1747 /* JNI-functions for calling instance methods *********************************/
1749 #define JNI_CALL_VIRTUAL_METHOD(name, type, intern) \
1750 type _Jv_JNI_Call##name##Method(JNIEnv *env, jobject obj, \
1751 jmethodID methodID, ...) \
1758 o = (java_handle_t *) obj; \
1759 m = (methodinfo *) methodID; \
1761 va_start(ap, methodID); \
1762 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, ap); \
1768 JNI_CALL_VIRTUAL_METHOD(Boolean, jboolean, Int)
1769 JNI_CALL_VIRTUAL_METHOD(Byte, jbyte, Int)
1770 JNI_CALL_VIRTUAL_METHOD(Char, jchar, Int)
1771 JNI_CALL_VIRTUAL_METHOD(Short, jshort, Int)
1772 JNI_CALL_VIRTUAL_METHOD(Int, jint, Int)
1773 JNI_CALL_VIRTUAL_METHOD(Long, jlong, Long)
1774 JNI_CALL_VIRTUAL_METHOD(Float, jfloat, Float)
1775 JNI_CALL_VIRTUAL_METHOD(Double, jdouble, Double)
1778 #define JNI_CALL_VIRTUAL_METHOD_V(name, type, intern) \
1779 type _Jv_JNI_Call##name##MethodV(JNIEnv *env, jobject obj, \
1780 jmethodID methodID, va_list args) \
1786 o = (java_handle_t *) obj; \
1787 m = (methodinfo *) methodID; \
1789 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, args); \
1794 JNI_CALL_VIRTUAL_METHOD_V(Boolean, jboolean, Int)
1795 JNI_CALL_VIRTUAL_METHOD_V(Byte, jbyte, Int)
1796 JNI_CALL_VIRTUAL_METHOD_V(Char, jchar, Int)
1797 JNI_CALL_VIRTUAL_METHOD_V(Short, jshort, Int)
1798 JNI_CALL_VIRTUAL_METHOD_V(Int, jint, Int)
1799 JNI_CALL_VIRTUAL_METHOD_V(Long, jlong, Long)
1800 JNI_CALL_VIRTUAL_METHOD_V(Float, jfloat, Float)
1801 JNI_CALL_VIRTUAL_METHOD_V(Double, jdouble, Double)
1804 #define JNI_CALL_VIRTUAL_METHOD_A(name, type, intern) \
1805 type _Jv_JNI_Call##name##MethodA(JNIEnv *env, jobject obj, \
1806 jmethodID methodID, \
1807 const jvalue *args) \
1813 o = (java_handle_t *) obj; \
1814 m = (methodinfo *) methodID; \
1816 ret = _Jv_jni_Call##intern##MethodA(o, o->vftbl, m, args); \
1821 JNI_CALL_VIRTUAL_METHOD_A(Boolean, jboolean, Int)
1822 JNI_CALL_VIRTUAL_METHOD_A(Byte, jbyte, Int)
1823 JNI_CALL_VIRTUAL_METHOD_A(Char, jchar, Int)
1824 JNI_CALL_VIRTUAL_METHOD_A(Short, jshort, Int)
1825 JNI_CALL_VIRTUAL_METHOD_A(Int, jint, Int)
1826 JNI_CALL_VIRTUAL_METHOD_A(Long, jlong, Long)
1827 JNI_CALL_VIRTUAL_METHOD_A(Float, jfloat, Float)
1828 JNI_CALL_VIRTUAL_METHOD_A(Double, jdouble, Double)
1831 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1839 o = (java_handle_t *) obj;
1840 m = (methodinfo *) methodID;
1842 va_start(ap, methodID);
1843 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1846 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1850 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1857 o = (java_handle_t *) obj;
1858 m = (methodinfo *) methodID;
1860 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1862 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1866 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1873 o = (java_handle_t *) obj;
1874 m = (methodinfo *) methodID;
1876 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1878 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1883 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1889 o = (java_handle_t *) obj;
1890 m = (methodinfo *) methodID;
1892 va_start(ap, methodID);
1893 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1898 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1904 o = (java_handle_t *) obj;
1905 m = (methodinfo *) methodID;
1907 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1911 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1917 o = (java_handle_t *) obj;
1918 m = (methodinfo *) methodID;
1920 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1925 #define JNI_CALL_NONVIRTUAL_METHOD(name, type, intern) \
1926 type _Jv_JNI_CallNonvirtual##name##Method(JNIEnv *env, jobject obj, \
1927 jclass clazz, jmethodID methodID, \
1936 o = (java_handle_t *) obj; \
1937 c = LLNI_classinfo_unwrap(clazz); \
1938 m = (methodinfo *) methodID; \
1940 va_start(ap, methodID); \
1941 ret = _Jv_jni_Call##intern##Method(o, c->vftbl, m, ap); \
1947 JNI_CALL_NONVIRTUAL_METHOD(Boolean, jboolean, Int)
1948 JNI_CALL_NONVIRTUAL_METHOD(Byte, jbyte, Int)
1949 JNI_CALL_NONVIRTUAL_METHOD(Char, jchar, Int)
1950 JNI_CALL_NONVIRTUAL_METHOD(Short, jshort, Int)
1951 JNI_CALL_NONVIRTUAL_METHOD(Int, jint, Int)
1952 JNI_CALL_NONVIRTUAL_METHOD(Long, jlong, Long)
1953 JNI_CALL_NONVIRTUAL_METHOD(Float, jfloat, Float)
1954 JNI_CALL_NONVIRTUAL_METHOD(Double, jdouble, Double)
1957 #define JNI_CALL_NONVIRTUAL_METHOD_V(name, type, intern) \
1958 type _Jv_JNI_CallNonvirtual##name##MethodV(JNIEnv *env, jobject obj, \
1959 jclass clazz, jmethodID methodID, \
1967 o = (java_handle_t *) obj; \
1968 c = LLNI_classinfo_unwrap(clazz); \
1969 m = (methodinfo *) methodID; \
1971 ret = _Jv_jni_CallIntMethod(o, c->vftbl, m, args); \
1976 JNI_CALL_NONVIRTUAL_METHOD_V(Boolean, jboolean, Int)
1977 JNI_CALL_NONVIRTUAL_METHOD_V(Byte, jbyte, Int)
1978 JNI_CALL_NONVIRTUAL_METHOD_V(Char, jchar, Int)
1979 JNI_CALL_NONVIRTUAL_METHOD_V(Short, jshort, Int)
1980 JNI_CALL_NONVIRTUAL_METHOD_V(Int, jint, Int)
1981 JNI_CALL_NONVIRTUAL_METHOD_V(Long, jlong, Long)
1982 JNI_CALL_NONVIRTUAL_METHOD_V(Float, jfloat, Float)
1983 JNI_CALL_NONVIRTUAL_METHOD_V(Double, jdouble, Double)
1986 #define JNI_CALL_NONVIRTUAL_METHOD_A(name, type, intern) \
1987 type _Jv_JNI_CallNonvirtual##name##MethodA(JNIEnv *env, jobject obj, \
1988 jclass clazz, jmethodID methodID, \
1989 const jvalue *args) \
1991 log_text("JNI-Call: CallNonvirtual##name##MethodA: IMPLEMENT ME!"); \
1996 JNI_CALL_NONVIRTUAL_METHOD_A(Boolean, jboolean, Int)
1997 JNI_CALL_NONVIRTUAL_METHOD_A(Byte, jbyte, Int)
1998 JNI_CALL_NONVIRTUAL_METHOD_A(Char, jchar, Int)
1999 JNI_CALL_NONVIRTUAL_METHOD_A(Short, jshort, Int)
2000 JNI_CALL_NONVIRTUAL_METHOD_A(Int, jint, Int)
2001 JNI_CALL_NONVIRTUAL_METHOD_A(Long, jlong, Long)
2002 JNI_CALL_NONVIRTUAL_METHOD_A(Float, jfloat, Float)
2003 JNI_CALL_NONVIRTUAL_METHOD_A(Double, jdouble, Double)
2005 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2006 jclass clazz, jmethodID methodID,
2015 o = (java_handle_t *) obj;
2016 c = LLNI_classinfo_unwrap(clazz);
2017 m = (methodinfo *) methodID;
2019 va_start(ap, methodID);
2020 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2023 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2027 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2028 jclass clazz, jmethodID methodID,
2036 o = (java_handle_t *) obj;
2037 c = LLNI_classinfo_unwrap(clazz);
2038 m = (methodinfo *) methodID;
2040 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2042 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2046 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2047 jclass clazz, jmethodID methodID,
2050 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2052 return _Jv_JNI_NewLocalRef(env, NULL);
2056 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2057 jmethodID methodID, ...)
2064 o = (java_handle_t *) obj;
2065 c = LLNI_classinfo_unwrap(clazz);
2066 m = (methodinfo *) methodID;
2068 va_start(ap, methodID);
2069 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2074 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2075 jmethodID methodID, va_list args)
2081 o = (java_handle_t *) obj;
2082 c = LLNI_classinfo_unwrap(clazz);
2083 m = (methodinfo *) methodID;
2085 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2089 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2090 jmethodID methodID, const jvalue * args)
2096 o = (java_handle_t *) obj;
2097 c = LLNI_classinfo_unwrap(clazz);
2098 m = (methodinfo *) methodID;
2100 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2104 /* Accessing Fields of Objects ************************************************/
2106 /* GetFieldID ******************************************************************
2108 Returns the field ID for an instance (nonstatic) field of a
2109 class. The field is specified by its name and signature. The
2110 Get<type>Field and Set<type>Field families of accessor functions
2111 use field IDs to retrieve object fields.
2113 *******************************************************************************/
2115 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2123 STATISTICS(jniinvokation());
2125 c = LLNI_classinfo_unwrap(clazz);
2127 /* XXX NPE check? */
2129 uname = utf_new_char((char *) name);
2130 udesc = utf_new_char((char *) sig);
2132 f = class_findfield(c, uname, udesc);
2135 exceptions_throw_nosuchfielderror(c, uname);
2137 return (jfieldID) f;
2141 /* Get<type>Field Routines *****************************************************
2143 This family of accessor routines returns the value of an instance
2144 (nonstatic) field of an object. The field to access is specified by
2145 a field ID obtained by calling GetFieldID().
2147 *******************************************************************************/
2149 #define JNI_GET_FIELD(name, type, intern) \
2150 type _Jv_JNI_Get##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID) \
2154 STATISTICS(jniinvokation()); \
2156 ret = GET_FIELD(obj, intern, fieldID); \
2158 return (type) ret; \
2161 JNI_GET_FIELD(Boolean, jboolean, s4)
2162 JNI_GET_FIELD(Byte, jbyte, s4)
2163 JNI_GET_FIELD(Char, jchar, s4)
2164 JNI_GET_FIELD(Short, jshort, s4)
2165 JNI_GET_FIELD(Int, jint, s4)
2166 JNI_GET_FIELD(Long, jlong, s8)
2167 JNI_GET_FIELD(Float, jfloat, float)
2168 JNI_GET_FIELD(Double, jdouble, double)
2171 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2175 STATISTICS(jniinvokation());
2177 #warning this needs to be fixed
2178 o = GET_FIELD(obj, java_handle_t*, fieldID);
2180 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2184 /* Set<type>Field Routines *****************************************************
2186 This family of accessor routines sets the value of an instance
2187 (nonstatic) field of an object. The field to access is specified by
2188 a field ID obtained by calling GetFieldID().
2190 *******************************************************************************/
2192 #define JNI_SET_FIELD(name, type, intern) \
2193 void _Jv_JNI_Set##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID, \
2196 STATISTICS(jniinvokation()); \
2198 SET_FIELD(obj, intern, fieldID, value); \
2201 JNI_SET_FIELD(Boolean, jboolean, s4)
2202 JNI_SET_FIELD(Byte, jbyte, s4)
2203 JNI_SET_FIELD(Char, jchar, s4)
2204 JNI_SET_FIELD(Short, jshort, s4)
2205 JNI_SET_FIELD(Int, jint, s4)
2206 JNI_SET_FIELD(Long, jlong, s8)
2207 JNI_SET_FIELD(Float, jfloat, float)
2208 JNI_SET_FIELD(Double, jdouble, double)
2211 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
2214 STATISTICS(jniinvokation());
2216 #warning this needs to be fixed
2217 SET_FIELD(obj, java_handle_t*, fieldID, value);
2221 /* Calling Static Methods *****************************************************/
2223 /* GetStaticMethodID ***********************************************************
2225 Returns the method ID for a static method of a class. The method is
2226 specified by its name and signature.
2228 GetStaticMethodID() causes an uninitialized class to be
2231 *******************************************************************************/
2233 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
2241 STATISTICS(jniinvokation());
2243 c = LLNI_classinfo_unwrap(clazz);
2248 if (!(c->state & CLASS_INITIALIZED))
2249 if (!initialize_class(c))
2252 /* try to get the static method of the class */
2254 uname = utf_new_char((char *) name);
2255 udesc = utf_new_char((char *) sig);
2257 m = class_resolvemethod(c, uname, udesc);
2259 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
2260 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2265 return (jmethodID) m;
2269 #define JNI_CALL_STATIC_METHOD(name, type, intern) \
2270 type _Jv_JNI_CallStatic##name##Method(JNIEnv *env, jclass clazz, \
2271 jmethodID methodID, ...) \
2277 m = (methodinfo *) methodID; \
2279 va_start(ap, methodID); \
2280 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, ap); \
2286 JNI_CALL_STATIC_METHOD(Boolean, jboolean, Int)
2287 JNI_CALL_STATIC_METHOD(Byte, jbyte, Int)
2288 JNI_CALL_STATIC_METHOD(Char, jchar, Int)
2289 JNI_CALL_STATIC_METHOD(Short, jshort, Int)
2290 JNI_CALL_STATIC_METHOD(Int, jint, Int)
2291 JNI_CALL_STATIC_METHOD(Long, jlong, Long)
2292 JNI_CALL_STATIC_METHOD(Float, jfloat, Float)
2293 JNI_CALL_STATIC_METHOD(Double, jdouble, Double)
2296 #define JNI_CALL_STATIC_METHOD_V(name, type, intern) \
2297 type _Jv_JNI_CallStatic##name##MethodV(JNIEnv *env, jclass clazz, \
2298 jmethodID methodID, va_list args) \
2303 m = (methodinfo *) methodID; \
2305 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, args); \
2310 JNI_CALL_STATIC_METHOD_V(Boolean, jboolean, Int)
2311 JNI_CALL_STATIC_METHOD_V(Byte, jbyte, Int)
2312 JNI_CALL_STATIC_METHOD_V(Char, jchar, Int)
2313 JNI_CALL_STATIC_METHOD_V(Short, jshort, Int)
2314 JNI_CALL_STATIC_METHOD_V(Int, jint, Int)
2315 JNI_CALL_STATIC_METHOD_V(Long, jlong, Long)
2316 JNI_CALL_STATIC_METHOD_V(Float, jfloat, Float)
2317 JNI_CALL_STATIC_METHOD_V(Double, jdouble, Double)
2320 #define JNI_CALL_STATIC_METHOD_A(name, type, intern) \
2321 type _Jv_JNI_CallStatic##name##MethodA(JNIEnv *env, jclass clazz, \
2322 jmethodID methodID, const jvalue *args) \
2327 m = (methodinfo *) methodID; \
2329 res = _Jv_jni_Call##intern##MethodA(NULL, NULL, m, args); \
2334 JNI_CALL_STATIC_METHOD_A(Boolean, jboolean, Int)
2335 JNI_CALL_STATIC_METHOD_A(Byte, jbyte, Int)
2336 JNI_CALL_STATIC_METHOD_A(Char, jchar, Int)
2337 JNI_CALL_STATIC_METHOD_A(Short, jshort, Int)
2338 JNI_CALL_STATIC_METHOD_A(Int, jint, Int)
2339 JNI_CALL_STATIC_METHOD_A(Long, jlong, Long)
2340 JNI_CALL_STATIC_METHOD_A(Float, jfloat, Float)
2341 JNI_CALL_STATIC_METHOD_A(Double, jdouble, Double)
2344 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
2345 jmethodID methodID, ...)
2351 m = (methodinfo *) methodID;
2353 va_start(ap, methodID);
2354 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
2357 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2361 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
2362 jmethodID methodID, va_list args)
2367 m = (methodinfo *) methodID;
2369 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
2371 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2375 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
2376 jmethodID methodID, const jvalue *args)
2381 m = (methodinfo *) methodID;
2383 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
2385 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2389 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
2390 jmethodID methodID, ...)
2395 m = (methodinfo *) methodID;
2397 va_start(ap, methodID);
2398 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
2403 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
2404 jmethodID methodID, va_list args)
2408 m = (methodinfo *) methodID;
2410 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
2414 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
2415 jmethodID methodID, const jvalue * args)
2419 m = (methodinfo *) methodID;
2421 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
2425 /* Accessing Static Fields ****************************************************/
2427 /* GetStaticFieldID ************************************************************
2429 Returns the field ID for a static field of a class. The field is
2430 specified by its name and signature. The GetStatic<type>Field and
2431 SetStatic<type>Field families of accessor functions use field IDs
2432 to retrieve static fields.
2434 *******************************************************************************/
2436 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
2444 STATISTICS(jniinvokation());
2446 c = LLNI_classinfo_unwrap(clazz);
2448 uname = utf_new_char((char *) name);
2449 usig = utf_new_char((char *) sig);
2451 f = class_findfield(c, uname, usig);
2454 exceptions_throw_nosuchfielderror(c, uname);
2456 return (jfieldID) f;
2460 /* GetStatic<type>Field ********************************************************
2462 This family of accessor routines returns the value of a static
2465 *******************************************************************************/
2467 #define JNI_GET_STATIC_FIELD(name, type, field) \
2468 type _Jv_JNI_GetStatic##name##Field(JNIEnv *env, jclass clazz, \
2474 STATISTICS(jniinvokation()); \
2476 c = LLNI_classinfo_unwrap(clazz); \
2477 f = (fieldinfo *) fieldID; \
2479 if (!(c->state & CLASS_INITIALIZED)) \
2480 if (!initialize_class(c)) \
2483 return f->value->field; \
2486 JNI_GET_STATIC_FIELD(Boolean, jboolean, i)
2487 JNI_GET_STATIC_FIELD(Byte, jbyte, i)
2488 JNI_GET_STATIC_FIELD(Char, jchar, i)
2489 JNI_GET_STATIC_FIELD(Short, jshort, i)
2490 JNI_GET_STATIC_FIELD(Int, jint, i)
2491 JNI_GET_STATIC_FIELD(Long, jlong, l)
2492 JNI_GET_STATIC_FIELD(Float, jfloat, f)
2493 JNI_GET_STATIC_FIELD(Double, jdouble, d)
2496 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
2502 STATISTICS(jniinvokation());
2504 c = LLNI_classinfo_unwrap(clazz);
2505 f = (fieldinfo *) fieldID;
2507 if (!(c->state & CLASS_INITIALIZED))
2508 if (!initialize_class(c))
2511 return _Jv_JNI_NewLocalRef(env, f->value->a);
2515 /* SetStatic<type>Field *******************************************************
2517 This family of accessor routines sets the value of a static field
2520 *******************************************************************************/
2522 #define JNI_SET_STATIC_FIELD(name, type, field) \
2523 void _Jv_JNI_SetStatic##name##Field(JNIEnv *env, jclass clazz, \
2530 STATISTICS(jniinvokation()); \
2532 c = LLNI_classinfo_unwrap(clazz); \
2533 f = (fieldinfo *) fieldID; \
2535 if (!(c->state & CLASS_INITIALIZED)) \
2536 if (!initialize_class(c)) \
2539 f->value->field = value; \
2542 JNI_SET_STATIC_FIELD(Boolean, jboolean, i)
2543 JNI_SET_STATIC_FIELD(Byte, jbyte, i)
2544 JNI_SET_STATIC_FIELD(Char, jchar, i)
2545 JNI_SET_STATIC_FIELD(Short, jshort, i)
2546 JNI_SET_STATIC_FIELD(Int, jint, i)
2547 JNI_SET_STATIC_FIELD(Long, jlong, l)
2548 JNI_SET_STATIC_FIELD(Float, jfloat, f)
2549 JNI_SET_STATIC_FIELD(Double, jdouble, d)
2552 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
2558 STATISTICS(jniinvokation());
2560 c = LLNI_classinfo_unwrap(clazz);
2561 f = (fieldinfo *) fieldID;
2563 if (!(c->state & CLASS_INITIALIZED))
2564 if (!initialize_class(c))
2567 f->value->a = value;
2571 /* String Operations **********************************************************/
2573 /* NewString *******************************************************************
2575 Create new java.lang.String object from an array of Unicode
2578 *******************************************************************************/
2580 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
2582 java_lang_String *s;
2583 java_handle_chararray_t *a;
2586 STATISTICS(jniinvokation());
2588 s = (java_lang_String *) builtin_new(class_java_lang_String);
2589 a = builtin_newarray_char(len);
2591 /* javastring or characterarray could not be created */
2592 if ((a == NULL) || (s == NULL))
2596 for (i = 0; i < len; i++)
2597 LLNI_array_direct(a, i) = buf[i];
2599 LLNI_field_set_ref(s, value , a);
2600 LLNI_field_set_val(s, offset, 0);
2601 LLNI_field_set_val(s, count , len);
2603 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2607 static jchar emptyStringJ[]={0,0};
2609 /* GetStringLength *************************************************************
2611 Returns the length (the count of Unicode characters) of a Java
2614 *******************************************************************************/
2616 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
2618 java_lang_String *s;
2621 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
2623 s = (java_lang_String *) str;
2625 LLNI_field_get_val(s, count, len);
2631 /******************** convertes javastring to u2-array ****************************/
2633 u2 *javastring_tou2(jstring so)
2635 java_lang_String *s;
2636 java_handle_chararray_t *a;
2642 STATISTICS(jniinvokation());
2644 s = (java_lang_String *) so;
2649 LLNI_field_get_ref(s, value, a);
2654 LLNI_field_get_val(s, count, count);
2655 LLNI_field_get_val(s, offset, offset);
2657 /* allocate memory */
2659 stringbuffer = MNEW(u2, count + 1);
2663 for (i = 0; i < count; i++)
2664 stringbuffer[i] = LLNI_array_direct(a, offset + i);
2666 /* terminate string */
2668 stringbuffer[i] = '\0';
2670 return stringbuffer;
2674 /* GetStringChars **************************************************************
2676 Returns a pointer to the array of Unicode characters of the
2677 string. This pointer is valid until ReleaseStringChars() is called.
2679 *******************************************************************************/
2681 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
2685 STATISTICS(jniinvokation());
2687 jc = javastring_tou2(str);
2699 return emptyStringJ;
2703 /* ReleaseStringChars **********************************************************
2705 Informs the VM that the native code no longer needs access to
2706 chars. The chars argument is a pointer obtained from string using
2709 *******************************************************************************/
2711 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
2713 java_lang_String *s;
2715 STATISTICS(jniinvokation());
2717 if (chars == emptyStringJ)
2720 s = (java_lang_String *) str;
2722 MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
2726 /* NewStringUTF ****************************************************************
2728 Constructs a new java.lang.String object from an array of UTF-8
2731 *******************************************************************************/
2733 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
2735 java_lang_String *s;
2737 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
2739 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
2741 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2745 /****************** returns the utf8 length in bytes of a string *******************/
2747 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
2749 java_lang_String *s;
2752 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
2754 s = (java_lang_String *) string;
2756 length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
2762 /* GetStringUTFChars ***********************************************************
2764 Returns a pointer to an array of UTF-8 characters of the
2765 string. This array is valid until it is released by
2766 ReleaseStringUTFChars().
2768 *******************************************************************************/
2770 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
2775 STATISTICS(jniinvokation());
2783 u = javastring_toutf((java_handle_t *) string, false);
2792 /* ReleaseStringUTFChars *******************************************************
2794 Informs the VM that the native code no longer needs access to
2795 utf. The utf argument is a pointer derived from string using
2796 GetStringUTFChars().
2798 *******************************************************************************/
2800 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
2802 STATISTICS(jniinvokation());
2804 /* XXX we don't release utf chars right now, perhaps that should be done
2805 later. Since there is always one reference the garbage collector will
2810 /* Array Operations ***********************************************************/
2812 /* GetArrayLength **************************************************************
2814 Returns the number of elements in the array.
2816 *******************************************************************************/
2818 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
2823 STATISTICS(jniinvokation());
2825 a = (java_handle_t *) array;
2827 size = LLNI_array_size(a);
2833 /* NewObjectArray **************************************************************
2835 Constructs a new array holding objects in class elementClass. All
2836 elements are initially set to initialElement.
2838 *******************************************************************************/
2840 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
2841 jclass elementClass, jobject initialElement)
2845 java_handle_objectarray_t *oa;
2848 STATISTICS(jniinvokation());
2850 c = LLNI_classinfo_unwrap(elementClass);
2851 o = (java_handle_t *) initialElement;
2854 exceptions_throw_negativearraysizeexception();
2858 oa = builtin_anewarray(length, c);
2863 /* set all elements to initialElement */
2865 for (i = 0; i < length; i++)
2866 LLNI_objectarray_element_set(oa, i, o);
2868 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
2872 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
2875 java_handle_objectarray_t *oa;
2878 STATISTICS(jniinvokation());
2880 oa = (java_handle_objectarray_t *) array;
2882 if (index >= LLNI_array_size(oa)) {
2883 exceptions_throw_arrayindexoutofboundsexception();
2887 LLNI_objectarray_element_get(oa, index, o);
2889 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2893 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
2894 jsize index, jobject val)
2896 java_handle_objectarray_t *oa;
2899 STATISTICS(jniinvokation());
2901 oa = (java_handle_objectarray_t *) array;
2902 o = (java_handle_t *) val;
2904 if (index >= LLNI_array_size(oa)) {
2905 exceptions_throw_arrayindexoutofboundsexception();
2909 /* check if the class of value is a subclass of the element class
2912 if (!builtin_canstore(oa, o))
2915 LLNI_objectarray_element_set(oa, index, o);
2919 #define JNI_NEW_ARRAY(name, type, intern) \
2920 type _Jv_JNI_New##name##Array(JNIEnv *env, jsize len) \
2922 java_handle_##intern##array_t *a; \
2924 STATISTICS(jniinvokation()); \
2927 exceptions_throw_negativearraysizeexception(); \
2931 a = builtin_newarray_##intern(len); \
2933 return (type) _Jv_JNI_NewLocalRef(env, (jobject) a); \
2936 JNI_NEW_ARRAY(Boolean, jbooleanArray, boolean)
2937 JNI_NEW_ARRAY(Byte, jbyteArray, byte)
2938 JNI_NEW_ARRAY(Char, jcharArray, char)
2939 JNI_NEW_ARRAY(Short, jshortArray, byte)
2940 JNI_NEW_ARRAY(Int, jintArray, int)
2941 JNI_NEW_ARRAY(Long, jlongArray, long)
2942 JNI_NEW_ARRAY(Float, jfloatArray, float)
2943 JNI_NEW_ARRAY(Double, jdoubleArray, double)
2946 /* Get<PrimitiveType>ArrayElements *********************************************
2948 A family of functions that returns the body of the primitive array.
2950 *******************************************************************************/
2952 #define JNI_GET_ARRAY_ELEMENTS(name, type, intern) \
2953 type *_Jv_JNI_Get##name##ArrayElements(JNIEnv *env, type##Array array, \
2956 java_handle_##intern##array_t *a; \
2958 STATISTICS(jniinvokation()); \
2960 a = (java_handle_##intern##array_t *) array; \
2963 *isCopy = JNI_FALSE; \
2965 return LLNI_array_data(a); \
2968 JNI_GET_ARRAY_ELEMENTS(Boolean, jboolean, boolean)
2969 JNI_GET_ARRAY_ELEMENTS(Byte, jbyte, byte)
2970 JNI_GET_ARRAY_ELEMENTS(Char, jchar, char)
2971 JNI_GET_ARRAY_ELEMENTS(Short, jshort, short)
2972 JNI_GET_ARRAY_ELEMENTS(Int, jint, int)
2973 JNI_GET_ARRAY_ELEMENTS(Long, jlong, long)
2974 JNI_GET_ARRAY_ELEMENTS(Float, jfloat, float)
2975 JNI_GET_ARRAY_ELEMENTS(Double, jdouble, double)
2978 /* Release<PrimitiveType>ArrayElements *****************************************
2980 A family of functions that informs the VM that the native code no
2981 longer needs access to elems. The elems argument is a pointer
2982 derived from array using the corresponding
2983 Get<PrimitiveType>ArrayElements() function. If necessary, this
2984 function copies back all changes made to elems to the original
2987 *******************************************************************************/
2989 #define JNI_RELEASE_ARRAY_ELEMENTS(name, type, intern, intern2) \
2990 void _Jv_JNI_Release##name##ArrayElements(JNIEnv *env, type##Array array, \
2991 type *elems, jint mode) \
2993 java_handle_##intern##array_t *a; \
2995 STATISTICS(jniinvokation()); \
2997 a = (java_handle_##intern##array_t *) array; \
2999 if (elems != LLNI_array_data(a)) { \
3002 MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
3005 MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
3006 /* XXX TWISTI how should it be freed? */ \
3009 /* XXX TWISTI how should it be freed? */ \
3015 JNI_RELEASE_ARRAY_ELEMENTS(Boolean, jboolean, boolean, u1)
3016 JNI_RELEASE_ARRAY_ELEMENTS(Byte, jbyte, byte, s1)
3017 JNI_RELEASE_ARRAY_ELEMENTS(Char, jchar, char, u2)
3018 JNI_RELEASE_ARRAY_ELEMENTS(Short, jshort, short, s2)
3019 JNI_RELEASE_ARRAY_ELEMENTS(Int, jint, int, s4)
3020 JNI_RELEASE_ARRAY_ELEMENTS(Long, jlong, long, s8)
3021 JNI_RELEASE_ARRAY_ELEMENTS(Float, jfloat, float, float)
3022 JNI_RELEASE_ARRAY_ELEMENTS(Double, jdouble, double, double)
3025 /* Get<PrimitiveType>ArrayRegion **********************************************
3027 A family of functions that copies a region of a primitive array
3030 *******************************************************************************/
3032 #define JNI_GET_ARRAY_REGION(name, type, intern, intern2) \
3033 void _Jv_JNI_Get##name##ArrayRegion(JNIEnv *env, type##Array array, \
3034 jsize start, jsize len, type *buf) \
3036 java_handle_##intern##array_t *a; \
3038 STATISTICS(jniinvokation()); \
3040 a = (java_handle_##intern##array_t *) array; \
3042 if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
3043 exceptions_throw_arrayindexoutofboundsexception(); \
3045 MCOPY(buf, &LLNI_array_direct(a, start), intern2, len); \
3048 JNI_GET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3049 JNI_GET_ARRAY_REGION(Byte, jbyte, byte, s1)
3050 JNI_GET_ARRAY_REGION(Char, jchar, char, u2)
3051 JNI_GET_ARRAY_REGION(Short, jshort, short, s2)
3052 JNI_GET_ARRAY_REGION(Int, jint, int, s4)
3053 JNI_GET_ARRAY_REGION(Long, jlong, long, s8)
3054 JNI_GET_ARRAY_REGION(Float, jfloat, float, float)
3055 JNI_GET_ARRAY_REGION(Double, jdouble, double, double)
3058 /* Set<PrimitiveType>ArrayRegion **********************************************
3060 A family of functions that copies back a region of a primitive
3061 array from a buffer.
3063 *******************************************************************************/
3065 #define JNI_SET_ARRAY_REGION(name, type, intern, intern2) \
3066 void _Jv_JNI_Set##name##ArrayRegion(JNIEnv *env, type##Array array, \
3067 jsize start, jsize len, const type *buf) \
3069 java_handle_##intern##array_t *a; \
3071 STATISTICS(jniinvokation()); \
3073 a = (java_handle_##intern##array_t *) array; \
3075 if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
3076 exceptions_throw_arrayindexoutofboundsexception(); \
3078 MCOPY(&LLNI_array_direct(a, start), buf, intern2, len); \
3081 JNI_SET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3082 JNI_SET_ARRAY_REGION(Byte, jbyte, byte, s1)
3083 JNI_SET_ARRAY_REGION(Char, jchar, char, u2)
3084 JNI_SET_ARRAY_REGION(Short, jshort, short, s2)
3085 JNI_SET_ARRAY_REGION(Int, jint, int, s4)
3086 JNI_SET_ARRAY_REGION(Long, jlong, long, s8)
3087 JNI_SET_ARRAY_REGION(Float, jfloat, float, float)
3088 JNI_SET_ARRAY_REGION(Double, jdouble, double, double)
3091 /* Registering Native Methods *************************************************/
3093 /* RegisterNatives *************************************************************
3095 Registers native methods with the class specified by the clazz
3096 argument. The methods parameter specifies an array of
3097 JNINativeMethod structures that contain the names, signatures, and
3098 function pointers of the native methods. The nMethods parameter
3099 specifies the number of native methods in the array.
3101 *******************************************************************************/
3103 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
3104 const JNINativeMethod *methods, jint nMethods)
3108 STATISTICS(jniinvokation());
3110 c = LLNI_classinfo_unwrap(clazz);
3112 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
3113 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
3116 native_method_register(c->name, methods, nMethods);
3122 /* UnregisterNatives ***********************************************************
3124 Unregisters native methods of a class. The class goes back to the
3125 state before it was linked or registered with its native method
3128 This function should not be used in normal native code. Instead, it
3129 provides special programs a way to reload and relink native
3132 *******************************************************************************/
3134 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
3136 STATISTICS(jniinvokation());
3138 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
3140 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
3146 /* Monitor Operations *********************************************************/
3148 /* MonitorEnter ****************************************************************
3150 Enters the monitor associated with the underlying Java object
3153 *******************************************************************************/
3155 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
3157 STATISTICS(jniinvokation());
3160 exceptions_throw_nullpointerexception();
3164 LOCK_MONITOR_ENTER(obj);
3170 /* MonitorExit *****************************************************************
3172 The current thread must be the owner of the monitor associated with
3173 the underlying Java object referred to by obj. The thread
3174 decrements the counter indicating the number of times it has
3175 entered this monitor. If the value of the counter becomes zero, the
3176 current thread releases the monitor.
3178 *******************************************************************************/
3180 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
3182 STATISTICS(jniinvokation());
3185 exceptions_throw_nullpointerexception();
3189 LOCK_MONITOR_EXIT(obj);
3195 /* JavaVM Interface ***********************************************************/
3197 /* GetJavaVM *******************************************************************
3199 Returns the Java VM interface (used in the Invocation API)
3200 associated with the current thread. The result is placed at the
3201 location pointed to by the second argument, vm.
3203 *******************************************************************************/
3205 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
3207 STATISTICS(jniinvokation());
3209 *vm = (JavaVM *) _Jv_jvm;
3215 /* GetStringRegion *************************************************************
3217 Copies len number of Unicode characters beginning at offset start
3218 to the given buffer buf.
3220 Throws StringIndexOutOfBoundsException on index overflow.
3222 *******************************************************************************/
3224 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
3227 java_lang_String *s;
3228 java_handle_chararray_t *ca;
3230 STATISTICS(jniinvokation());
3232 s = (java_lang_String *) str;
3233 LLNI_field_get_ref(s, value, ca);
3235 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
3236 (start + len > LLNI_field_direct(s, count))) {
3237 exceptions_throw_stringindexoutofboundsexception();
3241 MCOPY(buf, &LLNI_array_direct(ca, start), u2, len);
3245 /* GetStringUTFRegion **********************************************************
3247 Translates len number of Unicode characters beginning at offset
3248 start into UTF-8 format and place the result in the given buffer
3251 Throws StringIndexOutOfBoundsException on index overflow.
3253 *******************************************************************************/
3255 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
3256 jsize len, char *buf)
3258 java_lang_String *s;
3259 java_handle_chararray_t *ca;
3264 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
3266 s = (java_lang_String *) str;
3267 LLNI_field_get_ref(s, value, ca);
3268 LLNI_field_get_val(s, count, count);
3269 LLNI_field_get_val(s, offset, offset);
3271 if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) {
3272 exceptions_throw_stringindexoutofboundsexception();
3276 for (i = 0; i < len; i++)
3277 buf[i] = LLNI_array_direct(ca, offset + start + i);
3283 /* GetPrimitiveArrayCritical ***************************************************
3285 Obtain a direct pointer to array elements.
3287 *******************************************************************************/
3289 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
3292 java_handle_bytearray_t *ba;
3295 ba = (java_handle_bytearray_t *) array;
3297 /* do the same as Kaffe does */
3299 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
3305 /* ReleasePrimitiveArrayCritical ***********************************************
3307 No specific documentation.
3309 *******************************************************************************/
3311 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
3312 void *carray, jint mode)
3314 STATISTICS(jniinvokation());
3316 /* do the same as Kaffe does */
3318 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
3323 /* GetStringCritical ***********************************************************
3325 The semantics of these two functions are similar to the existing
3326 Get/ReleaseStringChars functions.
3328 *******************************************************************************/
3330 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
3333 STATISTICS(jniinvokation());
3335 return _Jv_JNI_GetStringChars(env, string, isCopy);
3339 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
3340 const jchar *cstring)
3342 STATISTICS(jniinvokation());
3344 _Jv_JNI_ReleaseStringChars(env, string, cstring);
3348 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
3350 STATISTICS(jniinvokation());
3352 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
3358 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
3360 STATISTICS(jniinvokation());
3362 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
3366 /* NewGlobalRef ****************************************************************
3368 Creates a new global reference to the object referred to by the obj
3371 *******************************************************************************/
3373 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
3375 hashtable_global_ref_entry *gre;
3376 u4 key; /* hashkey */
3377 u4 slot; /* slot in hashtable */
3380 STATISTICS(jniinvokation());
3382 o = (java_handle_t *) obj;
3384 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3386 /* normally addresses are aligned to 4, 8 or 16 bytes */
3388 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
3389 slot = key & (hashtable_global_ref->size - 1);
3390 gre = hashtable_global_ref->ptr[slot];
3392 /* search external hash chain for the entry */
3396 /* global object found, increment the reference */
3400 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3405 gre = gre->hashlink; /* next element in external chain */
3408 /* global ref not found, create a new one */
3410 gre = NEW(hashtable_global_ref_entry);
3412 #if defined(ENABLE_GC_CACAO)
3413 /* register global ref with the GC */
3415 gc_reference_register(&(gre->o), GC_REFTYPE_JNI_GLOBALREF);
3421 /* insert entry into hashtable */
3423 gre->hashlink = hashtable_global_ref->ptr[slot];
3425 hashtable_global_ref->ptr[slot] = gre;
3427 /* update number of hashtable-entries */
3429 hashtable_global_ref->entries++;
3431 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3437 /* DeleteGlobalRef *************************************************************
3439 Deletes the global reference pointed to by globalRef.
3441 *******************************************************************************/
3443 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
3445 hashtable_global_ref_entry *gre;
3446 hashtable_global_ref_entry *prevgre;
3447 u4 key; /* hashkey */
3448 u4 slot; /* slot in hashtable */
3451 STATISTICS(jniinvokation());
3453 o = (java_handle_t *) globalRef;
3455 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3457 /* normally addresses are aligned to 4, 8 or 16 bytes */
3459 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
3460 slot = key & (hashtable_global_ref->size - 1);
3461 gre = hashtable_global_ref->ptr[slot];
3463 /* initialize prevgre */
3467 /* search external hash chain for the entry */
3471 /* global object found, decrement the reference count */
3475 /* if reference count is 0, remove the entry */
3477 if (gre->refs == 0) {
3478 /* special handling if it's the first in the chain */
3480 if (prevgre == NULL)
3481 hashtable_global_ref->ptr[slot] = gre->hashlink;
3483 prevgre->hashlink = gre->hashlink;
3485 #if defined(ENABLE_GC_CACAO)
3486 /* unregister global ref with the GC */
3488 gc_reference_unregister(&(gre->o));
3491 FREE(gre, hashtable_global_ref_entry);
3494 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3499 prevgre = gre; /* save current pointer for removal */
3500 gre = gre->hashlink; /* next element in external chain */
3503 log_println("JNI-DeleteGlobalRef: global reference not found");
3505 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3509 /* ExceptionCheck **************************************************************
3511 Returns JNI_TRUE when there is a pending exception; otherwise,
3514 *******************************************************************************/
3516 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
3520 STATISTICS(jniinvokation());
3522 o = exceptions_get_exception();
3524 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
3528 /* New JNI 1.4 functions ******************************************************/
3530 /* NewDirectByteBuffer *********************************************************
3532 Allocates and returns a direct java.nio.ByteBuffer referring to the
3533 block of memory starting at the memory address address and
3534 extending capacity bytes.
3536 *******************************************************************************/
3538 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
3540 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3541 java_handle_t *nbuf;
3543 # if SIZEOF_VOID_P == 8
3544 gnu_classpath_Pointer64 *paddress;
3546 gnu_classpath_Pointer32 *paddress;
3549 STATISTICS(jniinvokation());
3551 /* alocate a gnu.classpath.Pointer{32,64} object */
3553 # if SIZEOF_VOID_P == 8
3554 if (!(paddress = (gnu_classpath_Pointer64 *)
3555 builtin_new(class_gnu_classpath_Pointer64)))
3557 if (!(paddress = (gnu_classpath_Pointer32 *)
3558 builtin_new(class_gnu_classpath_Pointer32)))
3562 /* fill gnu.classpath.Pointer{32,64} with address */
3564 LLNI_field_set_val(paddress, data, (ptrint) address);
3566 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
3568 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
3569 (jmethodID) dbbirw_init, NULL, paddress,
3570 (jint) capacity, (jint) capacity, (jint) 0);
3572 /* add local reference and return the value */
3574 return _Jv_JNI_NewLocalRef(env, nbuf);
3576 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
3578 /* keep compiler happy */
3585 /* GetDirectBufferAddress ******************************************************
3587 Fetches and returns the starting address of the memory region
3588 referenced by the given direct java.nio.Buffer.
3590 *******************************************************************************/
3592 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
3594 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3595 java_nio_DirectByteBufferImpl *nbuf;
3596 # if SIZEOF_VOID_P == 8
3597 gnu_classpath_Pointer64 *paddress;
3599 gnu_classpath_Pointer32 *paddress;
3603 STATISTICS(jniinvokation());
3605 if (!builtin_instanceof(buf, class_java_nio_Buffer))
3608 nbuf = (java_nio_DirectByteBufferImpl *) buf;
3610 # if SIZEOF_VOID_P == 8
3611 LLNI_field_get_ref(nbuf, address, paddress);
3612 /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
3614 LLNI_field_get_ref(nbuf, address, paddress);
3615 /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
3618 if (paddress == NULL)
3621 LLNI_field_get_val(paddress, data, address);
3622 /* this was the cast to avaoid warning: (void *) paddress->data */
3626 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
3628 /* keep compiler happy */
3635 /* GetDirectBufferCapacity *****************************************************
3637 Fetches and returns the capacity in bytes of the memory region
3638 referenced by the given direct java.nio.Buffer.
3640 *******************************************************************************/
3642 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
3644 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3646 java_nio_Buffer *nbuf;
3649 STATISTICS(jniinvokation());
3651 o = (java_handle_t *) buf;
3653 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
3656 nbuf = (java_nio_Buffer *) o;
3658 LLNI_field_get_val(nbuf, cap, capacity);
3662 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
3664 /* keep compiler happy */
3671 /* DestroyJavaVM ***************************************************************
3673 Unloads a Java VM and reclaims its resources. Only the main thread
3674 can unload the VM. The system waits until the main thread is only
3675 remaining user thread before it destroys the VM.
3677 *******************************************************************************/
3679 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
3683 STATISTICS(jniinvokation());
3685 status = vm_destroy(vm);
3691 /* AttachCurrentThread *********************************************************
3693 Attaches the current thread to a Java VM. Returns a JNI interface
3694 pointer in the JNIEnv argument.
3696 Trying to attach a thread that is already attached is a no-op.
3698 A native thread cannot be attached simultaneously to two Java VMs.
3700 When a thread is attached to the VM, the context class loader is
3701 the bootstrap loader.
3703 *******************************************************************************/
3705 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
3707 JavaVMAttachArgs *vm_aargs;
3709 #if defined(ENABLE_THREADS)
3710 if (threads_get_current_threadobject() == NULL) {
3711 vm_aargs = (JavaVMAttachArgs *) thr_args;
3713 if (vm_aargs != NULL) {
3714 if ((vm_aargs->version != JNI_VERSION_1_2) &&
3715 (vm_aargs->version != JNI_VERSION_1_4))
3716 return JNI_EVERSION;
3719 if (!threads_attach_current_thread(vm_aargs, false))
3722 if (!localref_table_init())
3733 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
3735 STATISTICS(jniinvokation());
3737 return jni_attach_current_thread(p_env, thr_args, false);
3741 /* DetachCurrentThread *********************************************************
3743 Detaches the current thread from a Java VM. All Java monitors held
3744 by this thread are released. All Java threads waiting for this
3745 thread to die are notified.
3747 In JDK 1.1, the main thread cannot be detached from the VM. It must
3748 call DestroyJavaVM to unload the entire VM.
3750 In the JDK, the main thread can be detached from the VM.
3752 The main thread, which is the thread that created the Java VM,
3753 cannot be detached from the VM. Instead, the main thread must call
3754 JNI_DestroyJavaVM() to unload the entire VM.
3756 *******************************************************************************/
3758 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
3760 #if defined(ENABLE_THREADS)
3761 threadobject *thread;
3763 STATISTICS(jniinvokation());
3765 thread = threads_get_current_threadobject();
3770 if (!localref_table_destroy())
3773 if (!threads_detach_thread(thread))
3781 /* GetEnv **********************************************************************
3783 If the current thread is not attached to the VM, sets *env to NULL,
3784 and returns JNI_EDETACHED. If the specified version is not
3785 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
3786 sets *env to the appropriate interface, and returns JNI_OK.
3788 *******************************************************************************/
3790 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
3792 STATISTICS(jniinvokation());
3794 #if defined(ENABLE_THREADS)
3795 if (threads_get_current_threadobject() == NULL) {
3798 return JNI_EDETACHED;
3802 /* check the JNI version */
3805 case JNI_VERSION_1_1:
3806 case JNI_VERSION_1_2:
3807 case JNI_VERSION_1_4:
3815 #if defined(ENABLE_JVMTI)
3816 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
3817 == JVMTI_VERSION_INTERFACE_JVMTI) {
3819 *env = (void *) jvmti_new_environment();
3828 return JNI_EVERSION;
3832 /* AttachCurrentThreadAsDaemon *************************************************
3834 Same semantics as AttachCurrentThread, but the newly-created
3835 java.lang.Thread instance is a daemon.
3837 If the thread has already been attached via either
3838 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
3839 simply sets the value pointed to by penv to the JNIEnv of the
3840 current thread. In this case neither AttachCurrentThread nor this
3841 routine have any effect on the daemon status of the thread.
3843 *******************************************************************************/
3845 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
3847 STATISTICS(jniinvokation());
3849 return jni_attach_current_thread(penv, args, true);
3853 /* JNI invocation table *******************************************************/
3855 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
3860 _Jv_JNI_DestroyJavaVM,
3861 _Jv_JNI_AttachCurrentThread,
3862 _Jv_JNI_DetachCurrentThread,
3864 _Jv_JNI_AttachCurrentThreadAsDaemon
3868 /* JNI function table *********************************************************/
3870 struct JNINativeInterface_ _Jv_JNINativeInterface = {
3877 _Jv_JNI_DefineClass,
3879 _Jv_JNI_FromReflectedMethod,
3880 _Jv_JNI_FromReflectedField,
3881 _Jv_JNI_ToReflectedMethod,
3882 _Jv_JNI_GetSuperclass,
3883 _Jv_JNI_IsAssignableFrom,
3884 _Jv_JNI_ToReflectedField,
3888 _Jv_JNI_ExceptionOccurred,
3889 _Jv_JNI_ExceptionDescribe,
3890 _Jv_JNI_ExceptionClear,
3892 _Jv_JNI_PushLocalFrame,
3893 _Jv_JNI_PopLocalFrame,
3895 _Jv_JNI_NewGlobalRef,
3896 _Jv_JNI_DeleteGlobalRef,
3897 _Jv_JNI_DeleteLocalRef,
3898 _Jv_JNI_IsSameObject,
3899 _Jv_JNI_NewLocalRef,
3900 _Jv_JNI_EnsureLocalCapacity,
3902 _Jv_JNI_AllocObject,
3907 _Jv_JNI_GetObjectClass,
3908 _Jv_JNI_IsInstanceOf,
3910 _Jv_JNI_GetMethodID,
3912 _Jv_JNI_CallObjectMethod,
3913 _Jv_JNI_CallObjectMethodV,
3914 _Jv_JNI_CallObjectMethodA,
3915 _Jv_JNI_CallBooleanMethod,
3916 _Jv_JNI_CallBooleanMethodV,
3917 _Jv_JNI_CallBooleanMethodA,
3918 _Jv_JNI_CallByteMethod,
3919 _Jv_JNI_CallByteMethodV,
3920 _Jv_JNI_CallByteMethodA,
3921 _Jv_JNI_CallCharMethod,
3922 _Jv_JNI_CallCharMethodV,
3923 _Jv_JNI_CallCharMethodA,
3924 _Jv_JNI_CallShortMethod,
3925 _Jv_JNI_CallShortMethodV,
3926 _Jv_JNI_CallShortMethodA,
3927 _Jv_JNI_CallIntMethod,
3928 _Jv_JNI_CallIntMethodV,
3929 _Jv_JNI_CallIntMethodA,
3930 _Jv_JNI_CallLongMethod,
3931 _Jv_JNI_CallLongMethodV,
3932 _Jv_JNI_CallLongMethodA,
3933 _Jv_JNI_CallFloatMethod,
3934 _Jv_JNI_CallFloatMethodV,
3935 _Jv_JNI_CallFloatMethodA,
3936 _Jv_JNI_CallDoubleMethod,
3937 _Jv_JNI_CallDoubleMethodV,
3938 _Jv_JNI_CallDoubleMethodA,
3939 _Jv_JNI_CallVoidMethod,
3940 _Jv_JNI_CallVoidMethodV,
3941 _Jv_JNI_CallVoidMethodA,
3943 _Jv_JNI_CallNonvirtualObjectMethod,
3944 _Jv_JNI_CallNonvirtualObjectMethodV,
3945 _Jv_JNI_CallNonvirtualObjectMethodA,
3946 _Jv_JNI_CallNonvirtualBooleanMethod,
3947 _Jv_JNI_CallNonvirtualBooleanMethodV,
3948 _Jv_JNI_CallNonvirtualBooleanMethodA,
3949 _Jv_JNI_CallNonvirtualByteMethod,
3950 _Jv_JNI_CallNonvirtualByteMethodV,
3951 _Jv_JNI_CallNonvirtualByteMethodA,
3952 _Jv_JNI_CallNonvirtualCharMethod,
3953 _Jv_JNI_CallNonvirtualCharMethodV,
3954 _Jv_JNI_CallNonvirtualCharMethodA,
3955 _Jv_JNI_CallNonvirtualShortMethod,
3956 _Jv_JNI_CallNonvirtualShortMethodV,
3957 _Jv_JNI_CallNonvirtualShortMethodA,
3958 _Jv_JNI_CallNonvirtualIntMethod,
3959 _Jv_JNI_CallNonvirtualIntMethodV,
3960 _Jv_JNI_CallNonvirtualIntMethodA,
3961 _Jv_JNI_CallNonvirtualLongMethod,
3962 _Jv_JNI_CallNonvirtualLongMethodV,
3963 _Jv_JNI_CallNonvirtualLongMethodA,
3964 _Jv_JNI_CallNonvirtualFloatMethod,
3965 _Jv_JNI_CallNonvirtualFloatMethodV,
3966 _Jv_JNI_CallNonvirtualFloatMethodA,
3967 _Jv_JNI_CallNonvirtualDoubleMethod,
3968 _Jv_JNI_CallNonvirtualDoubleMethodV,
3969 _Jv_JNI_CallNonvirtualDoubleMethodA,
3970 _Jv_JNI_CallNonvirtualVoidMethod,
3971 _Jv_JNI_CallNonvirtualVoidMethodV,
3972 _Jv_JNI_CallNonvirtualVoidMethodA,
3976 _Jv_JNI_GetObjectField,
3977 _Jv_JNI_GetBooleanField,
3978 _Jv_JNI_GetByteField,
3979 _Jv_JNI_GetCharField,
3980 _Jv_JNI_GetShortField,
3981 _Jv_JNI_GetIntField,
3982 _Jv_JNI_GetLongField,
3983 _Jv_JNI_GetFloatField,
3984 _Jv_JNI_GetDoubleField,
3985 _Jv_JNI_SetObjectField,
3986 _Jv_JNI_SetBooleanField,
3987 _Jv_JNI_SetByteField,
3988 _Jv_JNI_SetCharField,
3989 _Jv_JNI_SetShortField,
3990 _Jv_JNI_SetIntField,
3991 _Jv_JNI_SetLongField,
3992 _Jv_JNI_SetFloatField,
3993 _Jv_JNI_SetDoubleField,
3995 _Jv_JNI_GetStaticMethodID,
3997 _Jv_JNI_CallStaticObjectMethod,
3998 _Jv_JNI_CallStaticObjectMethodV,
3999 _Jv_JNI_CallStaticObjectMethodA,
4000 _Jv_JNI_CallStaticBooleanMethod,
4001 _Jv_JNI_CallStaticBooleanMethodV,
4002 _Jv_JNI_CallStaticBooleanMethodA,
4003 _Jv_JNI_CallStaticByteMethod,
4004 _Jv_JNI_CallStaticByteMethodV,
4005 _Jv_JNI_CallStaticByteMethodA,
4006 _Jv_JNI_CallStaticCharMethod,
4007 _Jv_JNI_CallStaticCharMethodV,
4008 _Jv_JNI_CallStaticCharMethodA,
4009 _Jv_JNI_CallStaticShortMethod,
4010 _Jv_JNI_CallStaticShortMethodV,
4011 _Jv_JNI_CallStaticShortMethodA,
4012 _Jv_JNI_CallStaticIntMethod,
4013 _Jv_JNI_CallStaticIntMethodV,
4014 _Jv_JNI_CallStaticIntMethodA,
4015 _Jv_JNI_CallStaticLongMethod,
4016 _Jv_JNI_CallStaticLongMethodV,
4017 _Jv_JNI_CallStaticLongMethodA,
4018 _Jv_JNI_CallStaticFloatMethod,
4019 _Jv_JNI_CallStaticFloatMethodV,
4020 _Jv_JNI_CallStaticFloatMethodA,
4021 _Jv_JNI_CallStaticDoubleMethod,
4022 _Jv_JNI_CallStaticDoubleMethodV,
4023 _Jv_JNI_CallStaticDoubleMethodA,
4024 _Jv_JNI_CallStaticVoidMethod,
4025 _Jv_JNI_CallStaticVoidMethodV,
4026 _Jv_JNI_CallStaticVoidMethodA,
4028 _Jv_JNI_GetStaticFieldID,
4030 _Jv_JNI_GetStaticObjectField,
4031 _Jv_JNI_GetStaticBooleanField,
4032 _Jv_JNI_GetStaticByteField,
4033 _Jv_JNI_GetStaticCharField,
4034 _Jv_JNI_GetStaticShortField,
4035 _Jv_JNI_GetStaticIntField,
4036 _Jv_JNI_GetStaticLongField,
4037 _Jv_JNI_GetStaticFloatField,
4038 _Jv_JNI_GetStaticDoubleField,
4039 _Jv_JNI_SetStaticObjectField,
4040 _Jv_JNI_SetStaticBooleanField,
4041 _Jv_JNI_SetStaticByteField,
4042 _Jv_JNI_SetStaticCharField,
4043 _Jv_JNI_SetStaticShortField,
4044 _Jv_JNI_SetStaticIntField,
4045 _Jv_JNI_SetStaticLongField,
4046 _Jv_JNI_SetStaticFloatField,
4047 _Jv_JNI_SetStaticDoubleField,
4050 _Jv_JNI_GetStringLength,
4051 _Jv_JNI_GetStringChars,
4052 _Jv_JNI_ReleaseStringChars,
4054 _Jv_JNI_NewStringUTF,
4055 _Jv_JNI_GetStringUTFLength,
4056 _Jv_JNI_GetStringUTFChars,
4057 _Jv_JNI_ReleaseStringUTFChars,
4059 _Jv_JNI_GetArrayLength,
4061 _Jv_JNI_NewObjectArray,
4062 _Jv_JNI_GetObjectArrayElement,
4063 _Jv_JNI_SetObjectArrayElement,
4065 _Jv_JNI_NewBooleanArray,
4066 _Jv_JNI_NewByteArray,
4067 _Jv_JNI_NewCharArray,
4068 _Jv_JNI_NewShortArray,
4069 _Jv_JNI_NewIntArray,
4070 _Jv_JNI_NewLongArray,
4071 _Jv_JNI_NewFloatArray,
4072 _Jv_JNI_NewDoubleArray,
4074 _Jv_JNI_GetBooleanArrayElements,
4075 _Jv_JNI_GetByteArrayElements,
4076 _Jv_JNI_GetCharArrayElements,
4077 _Jv_JNI_GetShortArrayElements,
4078 _Jv_JNI_GetIntArrayElements,
4079 _Jv_JNI_GetLongArrayElements,
4080 _Jv_JNI_GetFloatArrayElements,
4081 _Jv_JNI_GetDoubleArrayElements,
4083 _Jv_JNI_ReleaseBooleanArrayElements,
4084 _Jv_JNI_ReleaseByteArrayElements,
4085 _Jv_JNI_ReleaseCharArrayElements,
4086 _Jv_JNI_ReleaseShortArrayElements,
4087 _Jv_JNI_ReleaseIntArrayElements,
4088 _Jv_JNI_ReleaseLongArrayElements,
4089 _Jv_JNI_ReleaseFloatArrayElements,
4090 _Jv_JNI_ReleaseDoubleArrayElements,
4092 _Jv_JNI_GetBooleanArrayRegion,
4093 _Jv_JNI_GetByteArrayRegion,
4094 _Jv_JNI_GetCharArrayRegion,
4095 _Jv_JNI_GetShortArrayRegion,
4096 _Jv_JNI_GetIntArrayRegion,
4097 _Jv_JNI_GetLongArrayRegion,
4098 _Jv_JNI_GetFloatArrayRegion,
4099 _Jv_JNI_GetDoubleArrayRegion,
4100 _Jv_JNI_SetBooleanArrayRegion,
4101 _Jv_JNI_SetByteArrayRegion,
4102 _Jv_JNI_SetCharArrayRegion,
4103 _Jv_JNI_SetShortArrayRegion,
4104 _Jv_JNI_SetIntArrayRegion,
4105 _Jv_JNI_SetLongArrayRegion,
4106 _Jv_JNI_SetFloatArrayRegion,
4107 _Jv_JNI_SetDoubleArrayRegion,
4109 _Jv_JNI_RegisterNatives,
4110 _Jv_JNI_UnregisterNatives,
4112 _Jv_JNI_MonitorEnter,
4113 _Jv_JNI_MonitorExit,
4117 /* new JNI 1.2 functions */
4119 _Jv_JNI_GetStringRegion,
4120 _Jv_JNI_GetStringUTFRegion,
4122 _Jv_JNI_GetPrimitiveArrayCritical,
4123 _Jv_JNI_ReleasePrimitiveArrayCritical,
4125 _Jv_JNI_GetStringCritical,
4126 _Jv_JNI_ReleaseStringCritical,
4128 _Jv_JNI_NewWeakGlobalRef,
4129 _Jv_JNI_DeleteWeakGlobalRef,
4131 _Jv_JNI_ExceptionCheck,
4133 /* new JNI 1.4 functions */
4135 _Jv_JNI_NewDirectByteBuffer,
4136 _Jv_JNI_GetDirectBufferAddress,
4137 _Jv_JNI_GetDirectBufferCapacity
4141 /* Invocation API Functions ***************************************************/
4143 /* JNI_GetDefaultJavaVMInitArgs ************************************************
4145 Returns a default configuration for the Java VM.
4147 *******************************************************************************/
4149 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
4151 JavaVMInitArgs *_vm_args;
4153 _vm_args = (JavaVMInitArgs *) vm_args;
4155 /* GNU classpath currently supports JNI 1.2 */
4157 switch (_vm_args->version) {
4158 case JNI_VERSION_1_1:
4159 _vm_args->version = JNI_VERSION_1_1;
4162 case JNI_VERSION_1_2:
4163 case JNI_VERSION_1_4:
4164 _vm_args->ignoreUnrecognized = JNI_FALSE;
4165 _vm_args->options = NULL;
4166 _vm_args->nOptions = 0;
4177 /* JNI_GetCreatedJavaVMs *******************************************************
4179 Returns all Java VMs that have been created. Pointers to VMs are written in
4180 the buffer vmBuf in the order they are created. At most bufLen number of
4181 entries will be written. The total number of created VMs is returned in
4184 *******************************************************************************/
4186 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
4188 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
4193 /* We currently only support 1 VM running. */
4195 vmBuf[0] = (JavaVM *) _Jv_jvm;
4202 /* JNI_CreateJavaVM ************************************************************
4204 Loads and initializes a Java VM. The current thread becomes the main thread.
4205 Sets the env argument to the JNI interface pointer of the main thread.
4207 *******************************************************************************/
4209 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
4211 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
4213 /* actually create the JVM */
4215 if (!vm_createjvm(p_vm, p_env, vm_args))
4223 * These are local overrides for various environment variables in Emacs.
4224 * Please do not remove this and leave it at the end of the file, where
4225 * Emacs will automagically detect them.
4226 * ---------------------------------------------------------------------
4229 * indent-tabs-mode: t
4233 * vim:noexpandtab:sw=4:ts=4: