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 8312 2007-08-15 22:10:22Z twisti $
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);
178 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
181 /* jni_init ********************************************************************
183 Initialize the JNI subsystem.
185 *******************************************************************************/
189 /* create global ref hashtable */
191 hashtable_global_ref = NEW(hashtable);
193 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
196 #if defined(ENABLE_JAVASE)
197 /* direct buffer stuff */
199 if (!(class_java_nio_Buffer =
200 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
201 !link_class(class_java_nio_Buffer))
204 # if defined(WITH_CLASSPATH_GNU)
205 if (!(class_java_nio_DirectByteBufferImpl =
206 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
207 !link_class(class_java_nio_DirectByteBufferImpl))
210 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
211 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
212 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
216 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
218 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
221 # if SIZEOF_VOID_P == 8
222 if (!(class_gnu_classpath_Pointer64 =
223 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
224 !link_class(class_gnu_classpath_Pointer64))
227 if (!(class_gnu_classpath_Pointer32 =
228 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
229 !link_class(class_gnu_classpath_Pointer32))
233 #endif /* defined(ENABLE_JAVASE) */
239 /* _Jv_jni_CallObjectMethod ****************************************************
241 Internal function to call Java Object methods.
243 *******************************************************************************/
245 static java_handle_t *_Jv_jni_CallObjectMethod(java_handle_t *o,
247 methodinfo *m, va_list ap)
252 STATISTICS(jniinvokation());
255 exceptions_throw_nullpointerexception();
259 /* Class initialization is done by the JIT compiler. This is ok
260 since a static method always belongs to the declaring class. */
262 if (m->flags & ACC_STATIC) {
263 /* For static methods we reset the object. */
268 /* for convenience */
273 /* For instance methods we make a virtual function table lookup. */
275 resm = method_vftbl_lookup(vftbl, m);
278 STATISTICS(jnicallXmethodnvokation());
280 ro = vm_call_method_valist(resm, o, ap);
286 /* _Jv_jni_CallObjectMethodA ***************************************************
288 Internal function to call Java Object methods.
290 *******************************************************************************/
292 static java_handle_t *_Jv_jni_CallObjectMethodA(java_handle_t *o,
300 STATISTICS(jniinvokation());
303 exceptions_throw_nullpointerexception();
307 /* Class initialization is done by the JIT compiler. This is ok
308 since a static method always belongs to the declaring class. */
310 if (m->flags & ACC_STATIC) {
311 /* For static methods we reset the object. */
316 /* for convenience */
321 /* For instance methods we make a virtual function table lookup. */
323 resm = method_vftbl_lookup(vftbl, m);
326 STATISTICS(jnicallXmethodnvokation());
328 ro = vm_call_method_jvalue(resm, o, args);
334 /* _Jv_jni_CallIntMethod *******************************************************
336 Internal function to call Java integer class methods (boolean,
337 byte, char, short, int).
339 *******************************************************************************/
341 static jint _Jv_jni_CallIntMethod(java_handle_t *o, vftbl_t *vftbl,
342 methodinfo *m, va_list ap)
347 STATISTICS(jniinvokation());
350 exceptions_throw_nullpointerexception();
354 /* Class initialization is done by the JIT compiler. This is ok
355 since a static method always belongs to the declaring class. */
357 if (m->flags & ACC_STATIC) {
358 /* For static methods we reset the object. */
363 /* for convenience */
368 /* For instance methods we make a virtual function table lookup. */
370 resm = method_vftbl_lookup(vftbl, m);
373 STATISTICS(jnicallXmethodnvokation());
375 i = vm_call_method_int_valist(resm, o, ap);
381 /* _Jv_jni_CallIntMethodA ******************************************************
383 Internal function to call Java integer class methods (boolean,
384 byte, char, short, int).
386 *******************************************************************************/
388 static jint _Jv_jni_CallIntMethodA(java_handle_t *o, vftbl_t *vftbl,
389 methodinfo *m, const jvalue *args)
394 STATISTICS(jniinvokation());
397 exceptions_throw_nullpointerexception();
401 /* Class initialization is done by the JIT compiler. This is ok
402 since a static method always belongs to the declaring class. */
404 if (m->flags & ACC_STATIC) {
405 /* For static methods we reset the object. */
410 /* for convenience */
415 /* For instance methods we make a virtual function table lookup. */
417 resm = method_vftbl_lookup(vftbl, m);
420 STATISTICS(jnicallXmethodnvokation());
422 i = vm_call_method_int_jvalue(resm, o, args);
428 /* _Jv_jni_CallLongMethod ******************************************************
430 Internal function to call Java long methods.
432 *******************************************************************************/
434 static jlong _Jv_jni_CallLongMethod(java_handle_t *o, vftbl_t *vftbl,
435 methodinfo *m, va_list ap)
440 STATISTICS(jniinvokation());
443 exceptions_throw_nullpointerexception();
447 /* Class initialization is done by the JIT compiler. This is ok
448 since a static method always belongs to the declaring class. */
450 if (m->flags & ACC_STATIC) {
451 /* For static methods we reset the object. */
456 /* for convenience */
461 /* For instance methods we make a virtual function table lookup. */
463 resm = method_vftbl_lookup(vftbl, m);
466 STATISTICS(jnicallXmethodnvokation());
468 l = vm_call_method_long_valist(resm, o, ap);
474 /* _Jv_jni_CallLongMethodA *****************************************************
476 Internal function to call Java long methods.
478 *******************************************************************************/
480 static jlong _Jv_jni_CallLongMethodA(java_handle_t *o, vftbl_t *vftbl,
481 methodinfo *m, const jvalue *args)
486 STATISTICS(jniinvokation());
489 exceptions_throw_nullpointerexception();
493 /* Class initialization is done by the JIT compiler. This is ok
494 since a static method always belongs to the declaring class. */
496 if (m->flags & ACC_STATIC) {
497 /* For static methods we reset the object. */
502 /* for convenience */
507 /* For instance methods we make a virtual function table lookup. */
509 resm = method_vftbl_lookup(vftbl, m);
512 STATISTICS(jnicallXmethodnvokation());
514 l = vm_call_method_long_jvalue(resm, o, args);
520 /* _Jv_jni_CallFloatMethod *****************************************************
522 Internal function to call Java float methods.
524 *******************************************************************************/
526 static jfloat _Jv_jni_CallFloatMethod(java_handle_t *o, vftbl_t *vftbl,
527 methodinfo *m, va_list ap)
532 /* Class initialization is done by the JIT compiler. This is ok
533 since a static method always belongs to the declaring class. */
535 if (m->flags & ACC_STATIC) {
536 /* For static methods we reset the object. */
541 /* for convenience */
546 /* For instance methods we make a virtual function table lookup. */
548 resm = method_vftbl_lookup(vftbl, m);
551 STATISTICS(jnicallXmethodnvokation());
553 f = vm_call_method_float_valist(resm, o, ap);
559 /* _Jv_jni_CallFloatMethodA ****************************************************
561 Internal function to call Java float methods.
563 *******************************************************************************/
565 static jfloat _Jv_jni_CallFloatMethodA(java_handle_t *o, vftbl_t *vftbl,
566 methodinfo *m, const jvalue *args)
571 /* Class initialization is done by the JIT compiler. This is ok
572 since a static method always belongs to the declaring class. */
574 if (m->flags & ACC_STATIC) {
575 /* For static methods we reset the object. */
580 /* for convenience */
585 /* For instance methods we make a virtual function table lookup. */
587 resm = method_vftbl_lookup(vftbl, m);
590 STATISTICS(jnicallXmethodnvokation());
592 f = vm_call_method_float_jvalue(resm, o, args);
598 /* _Jv_jni_CallDoubleMethod ****************************************************
600 Internal function to call Java double methods.
602 *******************************************************************************/
604 static jdouble _Jv_jni_CallDoubleMethod(java_handle_t *o, vftbl_t *vftbl,
605 methodinfo *m, va_list ap)
610 /* Class initialization is done by the JIT compiler. This is ok
611 since a static method always belongs to the declaring class. */
613 if (m->flags & ACC_STATIC) {
614 /* For static methods we reset the object. */
619 /* for convenience */
624 /* For instance methods we make a virtual function table lookup. */
626 resm = method_vftbl_lookup(vftbl, m);
629 d = vm_call_method_double_valist(resm, o, ap);
635 /* _Jv_jni_CallDoubleMethodA ***************************************************
637 Internal function to call Java double methods.
639 *******************************************************************************/
641 static jdouble _Jv_jni_CallDoubleMethodA(java_handle_t *o, vftbl_t *vftbl,
642 methodinfo *m, const jvalue *args)
647 /* Class initialization is done by the JIT compiler. This is ok
648 since a static method always belongs to the declaring class. */
650 if (m->flags & ACC_STATIC) {
651 /* For static methods we reset the object. */
656 /* for convenience */
661 /* For instance methods we make a virtual function table lookup. */
663 resm = method_vftbl_lookup(vftbl, m);
666 d = vm_call_method_double_jvalue(resm, o, args);
672 /* _Jv_jni_CallVoidMethod ******************************************************
674 Internal function to call Java void methods.
676 *******************************************************************************/
678 static void _Jv_jni_CallVoidMethod(java_handle_t *o, vftbl_t *vftbl,
679 methodinfo *m, va_list ap)
684 exceptions_throw_nullpointerexception();
688 /* Class initialization is done by the JIT compiler. This is ok
689 since a static method always belongs to the declaring class. */
691 if (m->flags & ACC_STATIC) {
692 /* For static methods we reset the object. */
697 /* for convenience */
702 /* For instance methods we make a virtual function table lookup. */
704 resm = method_vftbl_lookup(vftbl, m);
707 STATISTICS(jnicallXmethodnvokation());
709 (void) vm_call_method_valist(resm, o, ap);
713 /* _Jv_jni_CallVoidMethodA *****************************************************
715 Internal function to call Java void methods.
717 *******************************************************************************/
719 static void _Jv_jni_CallVoidMethodA(java_handle_t *o, vftbl_t *vftbl,
720 methodinfo *m, const jvalue *args)
725 exceptions_throw_nullpointerexception();
729 /* Class initialization is done by the JIT compiler. This is ok
730 since a static method always belongs to the declaring class. */
732 if (m->flags & ACC_STATIC) {
733 /* For static methods we reset the object. */
738 /* for convenience */
743 /* For instance methods we make a virtual function table lookup. */
745 resm = method_vftbl_lookup(vftbl, m);
748 STATISTICS(jnicallXmethodnvokation());
750 (void) vm_call_method_jvalue(resm, o, args);
754 /* _Jv_jni_invokeNative ********************************************************
756 Invoke a method on the given object with the given arguments.
758 For instance methods OBJ must be != NULL and the method is looked up
759 in the vftbl of the object.
761 For static methods, OBJ is ignored.
763 *******************************************************************************/
765 java_handle_t *_Jv_jni_invokeNative(methodinfo *m, java_handle_t *o,
766 java_objectarray *params)
778 exceptions_throw_nullpointerexception();
782 argcount = m->parseddesc->paramcount;
783 paramcount = argcount;
785 /* if method is non-static, remove the `this' pointer */
787 if (!(m->flags & ACC_STATIC))
790 /* For instance methods the object has to be an instance of the
791 class the method belongs to. For static methods the obj
792 parameter is ignored. */
794 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
795 exceptions_throw_illegalargumentexception();
799 /* check if we got the right number of arguments */
801 if (((params == NULL) && (paramcount != 0)) ||
802 (params && (params->header.size != paramcount)))
804 exceptions_throw_illegalargumentexception();
808 /* for instance methods we need an object */
810 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
811 /* XXX not sure if that is the correct exception */
812 exceptions_throw_nullpointerexception();
816 /* for static methods, zero object to make subsequent code simpler */
817 if (m->flags & ACC_STATIC)
821 /* for instance methods we must do a vftbl lookup */
822 resm = method_vftbl_lookup(o->vftbl, m);
825 /* for static methods, just for convenience */
829 /* mark start of dump memory area */
831 dumpsize = dump_size();
833 /* Fill the argument array from a object-array. */
835 array = vm_array_from_objectarray(resm, o, params);
837 /* The array can be NULL if we don't have any arguments to pass
838 and the architecture does not have any argument registers
839 (e.g. i386). In that case we additionally check for an
842 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
843 /* release dump area */
845 dump_release(dumpsize);
850 switch (resm->parseddesc->returntype.decltype) {
852 (void) vm_call_array(resm, array);
856 case PRIMITIVETYPE_BOOLEAN:
857 case PRIMITIVETYPE_BYTE:
858 case PRIMITIVETYPE_CHAR:
859 case PRIMITIVETYPE_SHORT:
860 case PRIMITIVETYPE_INT:
861 value.i = vm_call_int_array(resm, array);
862 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
865 case PRIMITIVETYPE_LONG:
866 value.l = vm_call_long_array(resm, array);
867 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
870 case PRIMITIVETYPE_FLOAT:
871 value.f = vm_call_float_array(resm, array);
872 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
875 case PRIMITIVETYPE_DOUBLE:
876 value.d = vm_call_double_array(resm, array);
877 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
881 ro = vm_call_array(resm, array);
885 vm_abort("_Jv_jni_invokeNative: invalid return type %d", resm->parseddesc->returntype.decltype);
888 xptr = exceptions_get_exception();
891 /* clear exception pointer, we are calling JIT code again */
893 exceptions_clear_exception();
895 exceptions_throw_invocationtargetexception(xptr);
898 /* release dump area */
900 dump_release(dumpsize);
906 /* GetVersion ******************************************************************
908 Returns the major version number in the higher 16 bits and the
909 minor version number in the lower 16 bits.
911 *******************************************************************************/
913 jint _Jv_JNI_GetVersion(JNIEnv *env)
915 STATISTICS(jniinvokation());
917 /* we support JNI 1.4 */
919 return JNI_VERSION_1_4;
923 /* Class Operations ***********************************************************/
925 /* DefineClass *****************************************************************
927 Loads a class from a buffer of raw class data. The buffer
928 containing the raw class data is not referenced by the VM after the
929 DefineClass call returns, and it may be discarded if desired.
931 *******************************************************************************/
933 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
934 const jbyte *buf, jsize bufLen)
936 #if defined(ENABLE_JAVASE)
941 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
943 u = utf_new_char(name);
944 cl = (classloader *) loader;
946 c = class_define(u, cl, bufLen, (const uint8_t *) buf);
948 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
950 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
952 /* keep compiler happy */
959 /* FindClass *******************************************************************
961 This function loads a locally-defined class. It searches the
962 directories and zip files specified by the CLASSPATH environment
963 variable for the class with the specified name.
965 *******************************************************************************/
967 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
969 #if defined(ENABLE_JAVASE)
974 STATISTICS(jniinvokation());
976 u = utf_new_char_classname((char *) name);
978 /* Check stacktrace for classloader, if one found use it,
979 otherwise use the system classloader. */
981 /* Quote from the JNI documentation:
983 In the Java 2 Platform, FindClass locates the class loader
984 associated with the current native method. If the native code
985 belongs to a system class, no class loader will be
986 involved. Otherwise, the proper class loader will be invoked to
987 load and link the named class. When FindClass is called through
988 the Invocation Interface, there is no current native method or
989 its associated class loader. In that case, the result of
990 ClassLoader.getBaseClassLoader is used." */
992 cc = stacktrace_getCurrentClass();
995 c = load_class_from_sysloader(u);
997 c = load_class_from_classloader(u, cc->classloader);
1005 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1007 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1009 /* keep compiler happy */
1016 /* GetSuperclass ***************************************************************
1018 If clazz represents any class other than the class Object, then
1019 this function returns the object that represents the superclass of
1020 the class specified by clazz.
1022 *******************************************************************************/
1024 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1029 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1031 c = (classinfo *) sub;
1036 super = class_get_superclass(c);
1038 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1042 /* IsAssignableFrom ************************************************************
1044 Determines whether an object of sub can be safely cast to sup.
1046 *******************************************************************************/
1048 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1050 java_lang_Class *csup;
1051 java_lang_Class *csub;
1053 csup = (java_lang_Class *) sup;
1054 csub = (java_lang_Class *) sub;
1056 STATISTICS(jniinvokation());
1058 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1062 /* Throw ***********************************************************************
1064 Causes a java.lang.Throwable object to be thrown.
1066 *******************************************************************************/
1068 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1072 STATISTICS(jniinvokation());
1074 o = (java_handle_t *) obj;
1076 exceptions_set_exception(o);
1082 /* ThrowNew ********************************************************************
1084 Constructs an exception object from the specified class with the
1085 message specified by message and causes that exception to be
1088 *******************************************************************************/
1090 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1096 STATISTICS(jniinvokation());
1098 c = (classinfo *) clazz;
1101 s = javastring_new_from_utf_string(msg);
1103 /* instantiate exception object */
1105 o = native_new_and_init_string(c, s);
1110 exceptions_set_exception(o);
1116 /* ExceptionOccurred ***********************************************************
1118 Determines if an exception is being thrown. The exception stays
1119 being thrown until either the native code calls ExceptionClear(),
1120 or the Java code handles the exception.
1122 *******************************************************************************/
1124 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1128 STATISTICS(jniinvokation());
1130 o = exceptions_get_exception();
1132 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1136 /* ExceptionDescribe ***********************************************************
1138 Prints an exception and a backtrace of the stack to a system
1139 error-reporting channel, such as stderr. This is a convenience
1140 routine provided for debugging.
1142 *******************************************************************************/
1144 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1149 STATISTICS(jniinvokation());
1151 o = exceptions_get_exception();
1154 /* clear exception, because we are calling jit code again */
1156 exceptions_clear_exception();
1158 /* get printStackTrace method from exception class */
1160 m = class_resolveclassmethod(o->vftbl->class,
1161 utf_printStackTrace,
1167 /* XXX what should we do? */
1170 /* print the stacktrace */
1172 (void) vm_call_method(m, o);
1177 /* ExceptionClear **************************************************************
1179 Clears any exception that is currently being thrown. If no
1180 exception is currently being thrown, this routine has no effect.
1182 *******************************************************************************/
1184 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1186 STATISTICS(jniinvokation());
1188 exceptions_clear_exception();
1192 /* FatalError ******************************************************************
1194 Raises a fatal error and does not expect the VM to recover. This
1195 function does not return.
1197 *******************************************************************************/
1199 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1201 STATISTICS(jniinvokation());
1203 /* this seems to be the best way */
1205 vm_abort("JNI Fatal error: %s", msg);
1209 /* PushLocalFrame **************************************************************
1211 Creates a new local reference frame, in which at least a given
1212 number of local references can be created.
1214 *******************************************************************************/
1216 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1218 STATISTICS(jniinvokation());
1223 /* add new local reference frame to current table */
1225 if (!localref_frame_push(capacity))
1232 /* PopLocalFrame ***************************************************************
1234 Pops off the current local reference frame, frees all the local
1235 references, and returns a local reference in the previous local
1236 reference frame for the given result object.
1238 *******************************************************************************/
1240 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1242 STATISTICS(jniinvokation());
1244 /* release all current local frames */
1246 localref_frame_pop_all();
1248 /* add local reference and return the value */
1250 return _Jv_JNI_NewLocalRef(env, result);
1254 /* DeleteLocalRef **************************************************************
1256 Deletes the local reference pointed to by localRef.
1258 *******************************************************************************/
1260 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1263 localref_table *lrt;
1266 STATISTICS(jniinvokation());
1268 o = (java_handle_t *) localRef;
1270 /* get local reference table (thread specific) */
1272 lrt = LOCALREFTABLE;
1274 /* go through all local frames */
1276 for (; lrt != NULL; lrt = lrt->prev) {
1278 /* and try to remove the reference */
1280 for (i = 0; i < lrt->capacity; i++) {
1281 if (lrt->refs[i] == o) {
1282 lrt->refs[i] = NULL;
1290 /* this should not happen */
1292 /* if (opt_checkjni) */
1293 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1294 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1298 /* IsSameObject ****************************************************************
1300 Tests whether two references refer to the same Java object.
1302 *******************************************************************************/
1304 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1306 STATISTICS(jniinvokation());
1315 /* NewLocalRef *****************************************************************
1317 Creates a new local reference that refers to the same object as ref.
1319 *******************************************************************************/
1321 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1323 localref_table *lrt;
1326 STATISTICS(jniinvokation());
1331 /* get local reference table (thread specific) */
1333 lrt = LOCALREFTABLE;
1335 /* Check if we have space for the requested reference? No,
1336 allocate a new frame. This is actually not what the spec says,
1337 but for compatibility reasons... */
1339 if (lrt->used == lrt->capacity) {
1340 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1343 /* get the new local reference table */
1345 lrt = LOCALREFTABLE;
1348 /* insert the reference */
1350 for (i = 0; i < lrt->capacity; i++) {
1351 if (lrt->refs[i] == NULL) {
1352 lrt->refs[i] = (java_handle_t *) ref;
1359 /* should not happen, just to be sure */
1363 /* keep compiler happy */
1369 /* EnsureLocalCapacity *********************************************************
1371 Ensures that at least a given number of local references can be
1372 created in the current thread
1374 *******************************************************************************/
1376 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1378 localref_table *lrt;
1380 STATISTICS(jniinvokation());
1382 /* get local reference table (thread specific) */
1384 lrt = LOCALREFTABLE;
1386 /* check if capacity elements are available in the local references table */
1388 if ((lrt->used + capacity) > lrt->capacity)
1389 return _Jv_JNI_PushLocalFrame(env, capacity);
1395 /* AllocObject *****************************************************************
1397 Allocates a new Java object without invoking any of the
1398 constructors for the object. Returns a reference to the object.
1400 *******************************************************************************/
1402 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1407 STATISTICS(jniinvokation());
1409 c = (classinfo *) clazz;
1411 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1412 exceptions_throw_instantiationexception(c);
1418 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1422 /* NewObject *******************************************************************
1424 Programmers place all arguments that are to be passed to the
1425 constructor immediately following the methodID
1426 argument. NewObject() accepts these arguments and passes them to
1427 the Java method that the programmer wishes to invoke.
1429 *******************************************************************************/
1431 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1438 STATISTICS(jniinvokation());
1440 c = (classinfo *) clazz;
1441 m = (methodinfo *) methodID;
1450 /* call constructor */
1452 va_start(ap, methodID);
1453 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1456 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1460 /* NewObjectV ******************************************************************
1462 Programmers place all arguments that are to be passed to the
1463 constructor in an args argument of type va_list that immediately
1464 follows the methodID argument. NewObjectV() accepts these
1465 arguments, and, in turn, passes them to the Java method that the
1466 programmer wishes to invoke.
1468 *******************************************************************************/
1470 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1477 STATISTICS(jniinvokation());
1479 c = (classinfo *) clazz;
1480 m = (methodinfo *) methodID;
1489 /* call constructor */
1491 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1493 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1497 /* NewObjectA *****************************************************************
1499 Programmers place all arguments that are to be passed to the
1500 constructor in an args array of jvalues that immediately follows
1501 the methodID argument. NewObjectA() accepts the arguments in this
1502 array, and, in turn, passes them to the Java method that the
1503 programmer wishes to invoke.
1505 *******************************************************************************/
1507 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1514 STATISTICS(jniinvokation());
1516 c = (classinfo *) clazz;
1517 m = (methodinfo *) methodID;
1526 /* call constructor */
1528 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1530 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1534 /* GetObjectClass **************************************************************
1536 Returns the class of an object.
1538 *******************************************************************************/
1540 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1545 STATISTICS(jniinvokation());
1547 o = (java_handle_t *) obj;
1549 if ((o == NULL) || (o->vftbl == NULL))
1552 c = o->vftbl->class;
1554 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1558 /* IsInstanceOf ****************************************************************
1560 Tests whether an object is an instance of a class.
1562 *******************************************************************************/
1564 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1567 java_lang_Object *o;
1569 STATISTICS(jniinvokation());
1571 c = (java_lang_Class *) clazz;
1572 o = (java_lang_Object *) obj;
1574 return _Jv_java_lang_Class_isInstance(c, o);
1578 /* Reflection Support *********************************************************/
1580 /* FromReflectedMethod *********************************************************
1582 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1583 object to a method ID.
1585 *******************************************************************************/
1587 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1589 #if defined(ENABLE_JAVASE)
1595 STATISTICS(jniinvokation());
1597 o = (java_handle_t *) method;
1602 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
1603 java_lang_reflect_Method *rm;
1605 rm = (java_lang_reflect_Method *) method;
1606 LLNI_field_get_cls(rm, clazz, c);
1607 LLNI_field_get_val(rm, slot , slot);
1609 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
1610 java_lang_reflect_Constructor *rc;
1612 rc = (java_lang_reflect_Constructor *) method;
1613 LLNI_field_get_cls(rc, clazz, c);
1614 LLNI_field_get_val(rc, slot , slot);
1619 m = &(c->methods[slot]);
1621 return (jmethodID) m;
1623 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1625 /* keep compiler happy */
1632 /* FromReflectedField **********************************************************
1634 Converts a java.lang.reflect.Field to a field ID.
1636 *******************************************************************************/
1638 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1640 #if defined(ENABLE_JAVASE)
1641 java_lang_reflect_Field *rf;
1646 STATISTICS(jniinvokation());
1648 rf = (java_lang_reflect_Field *) field;
1653 LLNI_field_get_cls(rf, clazz, c);
1654 LLNI_field_get_val(rf, slot , slot);
1655 f = &(c->fields[slot]);
1657 return (jfieldID) f;
1659 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1661 /* keep compiler happy */
1668 /* ToReflectedMethod ***********************************************************
1670 Converts a method ID derived from cls to an instance of the
1671 java.lang.reflect.Method class or to an instance of the
1672 java.lang.reflect.Constructor class.
1674 *******************************************************************************/
1676 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1679 #if defined(ENABLE_JAVASE)
1681 java_lang_reflect_Constructor *rc;
1682 java_lang_reflect_Method *rm;
1684 STATISTICS(jniinvokation());
1686 m = (methodinfo *) methodID;
1688 /* HotSpot does the same assert. */
1690 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
1692 if (m->name == utf_init) {
1693 rc = reflect_constructor_new(m);
1695 return (jobject) rc;
1698 rm = reflect_method_new(m);
1700 return (jobject) rm;
1703 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
1705 /* keep compiler happy */
1712 /* ToReflectedField ************************************************************
1714 Converts a field ID derived from cls to an instance of the
1715 java.lang.reflect.Field class.
1717 *******************************************************************************/
1719 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1722 STATISTICS(jniinvokation());
1724 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1730 /* Calling Instance Methods ***************************************************/
1732 /* GetMethodID *****************************************************************
1734 Returns the method ID for an instance (nonstatic) method of a class
1735 or interface. The method may be defined in one of the clazz's
1736 superclasses and inherited by clazz. The method is determined by
1737 its name and signature.
1739 GetMethodID() causes an uninitialized class to be initialized.
1741 *******************************************************************************/
1743 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1751 STATISTICS(jniinvokation());
1753 c = (classinfo *) clazz;
1758 if (!(c->state & CLASS_INITIALIZED))
1759 if (!initialize_class(c))
1762 /* try to get the method of the class or one of it's superclasses */
1764 uname = utf_new_char((char *) name);
1765 udesc = utf_new_char((char *) sig);
1767 m = class_resolvemethod(c, uname, udesc);
1769 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1770 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1775 return (jmethodID) m;
1779 /* JNI-functions for calling instance methods *********************************/
1781 #define JNI_CALL_VIRTUAL_METHOD(name, type, intern) \
1782 type _Jv_JNI_Call##name##Method(JNIEnv *env, jobject obj, \
1783 jmethodID methodID, ...) \
1790 o = (java_handle_t *) obj; \
1791 m = (methodinfo *) methodID; \
1793 va_start(ap, methodID); \
1794 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, ap); \
1800 JNI_CALL_VIRTUAL_METHOD(Boolean, jboolean, Int)
1801 JNI_CALL_VIRTUAL_METHOD(Byte, jbyte, Int)
1802 JNI_CALL_VIRTUAL_METHOD(Char, jchar, Int)
1803 JNI_CALL_VIRTUAL_METHOD(Short, jshort, Int)
1804 JNI_CALL_VIRTUAL_METHOD(Int, jint, Int)
1805 JNI_CALL_VIRTUAL_METHOD(Long, jlong, Long)
1806 JNI_CALL_VIRTUAL_METHOD(Float, jfloat, Float)
1807 JNI_CALL_VIRTUAL_METHOD(Double, jdouble, Double)
1810 #define JNI_CALL_VIRTUAL_METHOD_V(name, type, intern) \
1811 type _Jv_JNI_Call##name##MethodV(JNIEnv *env, jobject obj, \
1812 jmethodID methodID, va_list args) \
1818 o = (java_handle_t *) obj; \
1819 m = (methodinfo *) methodID; \
1821 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, args); \
1826 JNI_CALL_VIRTUAL_METHOD_V(Boolean, jboolean, Int)
1827 JNI_CALL_VIRTUAL_METHOD_V(Byte, jbyte, Int)
1828 JNI_CALL_VIRTUAL_METHOD_V(Char, jchar, Int)
1829 JNI_CALL_VIRTUAL_METHOD_V(Short, jshort, Int)
1830 JNI_CALL_VIRTUAL_METHOD_V(Int, jint, Int)
1831 JNI_CALL_VIRTUAL_METHOD_V(Long, jlong, Long)
1832 JNI_CALL_VIRTUAL_METHOD_V(Float, jfloat, Float)
1833 JNI_CALL_VIRTUAL_METHOD_V(Double, jdouble, Double)
1836 #define JNI_CALL_VIRTUAL_METHOD_A(name, type, intern) \
1837 type _Jv_JNI_Call##name##MethodA(JNIEnv *env, jobject obj, \
1838 jmethodID methodID, \
1839 const jvalue *args) \
1845 o = (java_handle_t *) obj; \
1846 m = (methodinfo *) methodID; \
1848 ret = _Jv_jni_Call##intern##MethodA(o, o->vftbl, m, args); \
1853 JNI_CALL_VIRTUAL_METHOD_A(Boolean, jboolean, Int)
1854 JNI_CALL_VIRTUAL_METHOD_A(Byte, jbyte, Int)
1855 JNI_CALL_VIRTUAL_METHOD_A(Char, jchar, Int)
1856 JNI_CALL_VIRTUAL_METHOD_A(Short, jshort, Int)
1857 JNI_CALL_VIRTUAL_METHOD_A(Int, jint, Int)
1858 JNI_CALL_VIRTUAL_METHOD_A(Long, jlong, Long)
1859 JNI_CALL_VIRTUAL_METHOD_A(Float, jfloat, Float)
1860 JNI_CALL_VIRTUAL_METHOD_A(Double, jdouble, Double)
1863 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1871 o = (java_handle_t *) obj;
1872 m = (methodinfo *) methodID;
1874 va_start(ap, methodID);
1875 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1878 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1882 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1889 o = (java_handle_t *) obj;
1890 m = (methodinfo *) methodID;
1892 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1894 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1898 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1905 o = (java_handle_t *) obj;
1906 m = (methodinfo *) methodID;
1908 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1910 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1915 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1921 o = (java_handle_t *) obj;
1922 m = (methodinfo *) methodID;
1924 va_start(ap, methodID);
1925 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1930 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1936 o = (java_handle_t *) obj;
1937 m = (methodinfo *) methodID;
1939 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1943 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1949 o = (java_handle_t *) obj;
1950 m = (methodinfo *) methodID;
1952 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1957 #define JNI_CALL_NONVIRTUAL_METHOD(name, type, intern) \
1958 type _Jv_JNI_CallNonvirtual##name##Method(JNIEnv *env, jobject obj, \
1959 jclass clazz, jmethodID methodID, \
1968 o = (java_handle_t *) obj; \
1969 c = (classinfo *) clazz; \
1970 m = (methodinfo *) methodID; \
1972 va_start(ap, methodID); \
1973 ret = _Jv_jni_Call##intern##Method(o, c->vftbl, m, ap); \
1979 JNI_CALL_NONVIRTUAL_METHOD(Boolean, jboolean, Int)
1980 JNI_CALL_NONVIRTUAL_METHOD(Byte, jbyte, Int)
1981 JNI_CALL_NONVIRTUAL_METHOD(Char, jchar, Int)
1982 JNI_CALL_NONVIRTUAL_METHOD(Short, jshort, Int)
1983 JNI_CALL_NONVIRTUAL_METHOD(Int, jint, Int)
1984 JNI_CALL_NONVIRTUAL_METHOD(Long, jlong, Long)
1985 JNI_CALL_NONVIRTUAL_METHOD(Float, jfloat, Float)
1986 JNI_CALL_NONVIRTUAL_METHOD(Double, jdouble, Double)
1989 #define JNI_CALL_NONVIRTUAL_METHOD_V(name, type, intern) \
1990 type _Jv_JNI_CallNonvirtual##name##MethodV(JNIEnv *env, jobject obj, \
1991 jclass clazz, jmethodID methodID, \
1999 o = (java_handle_t *) obj; \
2000 c = (classinfo *) clazz; \
2001 m = (methodinfo *) methodID; \
2003 ret = _Jv_jni_CallIntMethod(o, c->vftbl, m, args); \
2008 JNI_CALL_NONVIRTUAL_METHOD_V(Boolean, jboolean, Int)
2009 JNI_CALL_NONVIRTUAL_METHOD_V(Byte, jbyte, Int)
2010 JNI_CALL_NONVIRTUAL_METHOD_V(Char, jchar, Int)
2011 JNI_CALL_NONVIRTUAL_METHOD_V(Short, jshort, Int)
2012 JNI_CALL_NONVIRTUAL_METHOD_V(Int, jint, Int)
2013 JNI_CALL_NONVIRTUAL_METHOD_V(Long, jlong, Long)
2014 JNI_CALL_NONVIRTUAL_METHOD_V(Float, jfloat, Float)
2015 JNI_CALL_NONVIRTUAL_METHOD_V(Double, jdouble, Double)
2018 #define JNI_CALL_NONVIRTUAL_METHOD_A(name, type, intern) \
2019 type _Jv_JNI_CallNonvirtual##name##MethodA(JNIEnv *env, jobject obj, \
2020 jclass clazz, jmethodID methodID, \
2021 const jvalue *args) \
2023 log_text("JNI-Call: CallNonvirtual##name##MethodA: IMPLEMENT ME!"); \
2028 JNI_CALL_NONVIRTUAL_METHOD_A(Boolean, jboolean, Int)
2029 JNI_CALL_NONVIRTUAL_METHOD_A(Byte, jbyte, Int)
2030 JNI_CALL_NONVIRTUAL_METHOD_A(Char, jchar, Int)
2031 JNI_CALL_NONVIRTUAL_METHOD_A(Short, jshort, Int)
2032 JNI_CALL_NONVIRTUAL_METHOD_A(Int, jint, Int)
2033 JNI_CALL_NONVIRTUAL_METHOD_A(Long, jlong, Long)
2034 JNI_CALL_NONVIRTUAL_METHOD_A(Float, jfloat, Float)
2035 JNI_CALL_NONVIRTUAL_METHOD_A(Double, jdouble, Double)
2037 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2038 jclass clazz, jmethodID methodID,
2047 o = (java_handle_t *) obj;
2048 c = (classinfo *) clazz;
2049 m = (methodinfo *) methodID;
2051 va_start(ap, methodID);
2052 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2055 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2059 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2060 jclass clazz, jmethodID methodID,
2068 o = (java_handle_t *) obj;
2069 c = (classinfo *) clazz;
2070 m = (methodinfo *) methodID;
2072 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2074 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2078 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2079 jclass clazz, jmethodID methodID,
2082 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2084 return _Jv_JNI_NewLocalRef(env, NULL);
2088 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2089 jmethodID methodID, ...)
2096 o = (java_handle_t *) obj;
2097 c = (classinfo *) clazz;
2098 m = (methodinfo *) methodID;
2100 va_start(ap, methodID);
2101 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2106 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2107 jmethodID methodID, va_list args)
2113 o = (java_handle_t *) obj;
2114 c = (classinfo *) clazz;
2115 m = (methodinfo *) methodID;
2117 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2121 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2122 jmethodID methodID, const jvalue * args)
2128 o = (java_handle_t *) obj;
2129 c = (classinfo *) clazz;
2130 m = (methodinfo *) methodID;
2132 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2136 /* Accessing Fields of Objects ************************************************/
2138 /* GetFieldID ******************************************************************
2140 Returns the field ID for an instance (nonstatic) field of a
2141 class. The field is specified by its name and signature. The
2142 Get<type>Field and Set<type>Field families of accessor functions
2143 use field IDs to retrieve object fields.
2145 *******************************************************************************/
2147 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2155 STATISTICS(jniinvokation());
2157 c = (classinfo *) clazz;
2159 /* XXX NPE check? */
2161 uname = utf_new_char((char *) name);
2162 udesc = utf_new_char((char *) sig);
2164 f = class_findfield(c, uname, udesc);
2167 exceptions_throw_nosuchfielderror(c, uname);
2169 return (jfieldID) f;
2173 /* Get<type>Field Routines *****************************************************
2175 This family of accessor routines returns the value of an instance
2176 (nonstatic) field of an object. The field to access is specified by
2177 a field ID obtained by calling GetFieldID().
2179 *******************************************************************************/
2181 #define JNI_GET_FIELD(name, type, intern) \
2182 type _Jv_JNI_Get##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID) \
2186 STATISTICS(jniinvokation()); \
2188 ret = GET_FIELD(obj, intern, fieldID); \
2190 return (type) ret; \
2193 JNI_GET_FIELD(Boolean, jboolean, s4)
2194 JNI_GET_FIELD(Byte, jbyte, s4)
2195 JNI_GET_FIELD(Char, jchar, s4)
2196 JNI_GET_FIELD(Short, jshort, s4)
2197 JNI_GET_FIELD(Int, jint, s4)
2198 JNI_GET_FIELD(Long, jlong, s8)
2199 JNI_GET_FIELD(Float, jfloat, float)
2200 JNI_GET_FIELD(Double, jdouble, double)
2203 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2207 STATISTICS(jniinvokation());
2209 #warning this needs to be fixed
2210 o = GET_FIELD(obj, java_handle_t*, fieldID);
2212 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2216 /* Set<type>Field Routines *****************************************************
2218 This family of accessor routines sets the value of an instance
2219 (nonstatic) field of an object. The field to access is specified by
2220 a field ID obtained by calling GetFieldID().
2222 *******************************************************************************/
2224 #define JNI_SET_FIELD(name, type, intern) \
2225 void _Jv_JNI_Set##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID, \
2228 STATISTICS(jniinvokation()); \
2230 SET_FIELD(obj, intern, fieldID, value); \
2233 JNI_SET_FIELD(Boolean, jboolean, s4)
2234 JNI_SET_FIELD(Byte, jbyte, s4)
2235 JNI_SET_FIELD(Char, jchar, s4)
2236 JNI_SET_FIELD(Short, jshort, s4)
2237 JNI_SET_FIELD(Int, jint, s4)
2238 JNI_SET_FIELD(Long, jlong, s8)
2239 JNI_SET_FIELD(Float, jfloat, float)
2240 JNI_SET_FIELD(Double, jdouble, double)
2243 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
2246 STATISTICS(jniinvokation());
2248 #warning this needs to be fixed
2249 SET_FIELD(obj, java_handle_t*, fieldID, value);
2253 /* Calling Static Methods *****************************************************/
2255 /* GetStaticMethodID ***********************************************************
2257 Returns the method ID for a static method of a class. The method is
2258 specified by its name and signature.
2260 GetStaticMethodID() causes an uninitialized class to be
2263 *******************************************************************************/
2265 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
2273 STATISTICS(jniinvokation());
2275 c = (classinfo *) clazz;
2280 if (!(c->state & CLASS_INITIALIZED))
2281 if (!initialize_class(c))
2284 /* try to get the static method of the class */
2286 uname = utf_new_char((char *) name);
2287 udesc = utf_new_char((char *) sig);
2289 m = class_resolvemethod(c, uname, udesc);
2291 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
2292 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2297 return (jmethodID) m;
2301 #define JNI_CALL_STATIC_METHOD(name, type, intern) \
2302 type _Jv_JNI_CallStatic##name##Method(JNIEnv *env, jclass clazz, \
2303 jmethodID methodID, ...) \
2309 m = (methodinfo *) methodID; \
2311 va_start(ap, methodID); \
2312 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, ap); \
2318 JNI_CALL_STATIC_METHOD(Boolean, jboolean, Int)
2319 JNI_CALL_STATIC_METHOD(Byte, jbyte, Int)
2320 JNI_CALL_STATIC_METHOD(Char, jchar, Int)
2321 JNI_CALL_STATIC_METHOD(Short, jshort, Int)
2322 JNI_CALL_STATIC_METHOD(Int, jint, Int)
2323 JNI_CALL_STATIC_METHOD(Long, jlong, Long)
2324 JNI_CALL_STATIC_METHOD(Float, jfloat, Float)
2325 JNI_CALL_STATIC_METHOD(Double, jdouble, Double)
2328 #define JNI_CALL_STATIC_METHOD_V(name, type, intern) \
2329 type _Jv_JNI_CallStatic##name##MethodV(JNIEnv *env, jclass clazz, \
2330 jmethodID methodID, va_list args) \
2335 m = (methodinfo *) methodID; \
2337 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, args); \
2342 JNI_CALL_STATIC_METHOD_V(Boolean, jboolean, Int)
2343 JNI_CALL_STATIC_METHOD_V(Byte, jbyte, Int)
2344 JNI_CALL_STATIC_METHOD_V(Char, jchar, Int)
2345 JNI_CALL_STATIC_METHOD_V(Short, jshort, Int)
2346 JNI_CALL_STATIC_METHOD_V(Int, jint, Int)
2347 JNI_CALL_STATIC_METHOD_V(Long, jlong, Long)
2348 JNI_CALL_STATIC_METHOD_V(Float, jfloat, Float)
2349 JNI_CALL_STATIC_METHOD_V(Double, jdouble, Double)
2352 #define JNI_CALL_STATIC_METHOD_A(name, type, intern) \
2353 type _Jv_JNI_CallStatic##name##MethodA(JNIEnv *env, jclass clazz, \
2354 jmethodID methodID, const jvalue *args) \
2359 m = (methodinfo *) methodID; \
2361 res = _Jv_jni_Call##intern##MethodA(NULL, NULL, m, args); \
2366 JNI_CALL_STATIC_METHOD_A(Boolean, jboolean, Int)
2367 JNI_CALL_STATIC_METHOD_A(Byte, jbyte, Int)
2368 JNI_CALL_STATIC_METHOD_A(Char, jchar, Int)
2369 JNI_CALL_STATIC_METHOD_A(Short, jshort, Int)
2370 JNI_CALL_STATIC_METHOD_A(Int, jint, Int)
2371 JNI_CALL_STATIC_METHOD_A(Long, jlong, Long)
2372 JNI_CALL_STATIC_METHOD_A(Float, jfloat, Float)
2373 JNI_CALL_STATIC_METHOD_A(Double, jdouble, Double)
2376 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
2377 jmethodID methodID, ...)
2383 m = (methodinfo *) methodID;
2385 va_start(ap, methodID);
2386 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
2389 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2393 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
2394 jmethodID methodID, va_list args)
2399 m = (methodinfo *) methodID;
2401 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
2403 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2407 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
2408 jmethodID methodID, const jvalue *args)
2413 m = (methodinfo *) methodID;
2415 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
2417 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2421 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
2422 jmethodID methodID, ...)
2427 m = (methodinfo *) methodID;
2429 va_start(ap, methodID);
2430 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
2435 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
2436 jmethodID methodID, va_list args)
2440 m = (methodinfo *) methodID;
2442 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
2446 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
2447 jmethodID methodID, const jvalue * args)
2451 m = (methodinfo *) methodID;
2453 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
2457 /* Accessing Static Fields ****************************************************/
2459 /* GetStaticFieldID ************************************************************
2461 Returns the field ID for a static field of a class. The field is
2462 specified by its name and signature. The GetStatic<type>Field and
2463 SetStatic<type>Field families of accessor functions use field IDs
2464 to retrieve static fields.
2466 *******************************************************************************/
2468 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
2476 STATISTICS(jniinvokation());
2478 c = (classinfo *) clazz;
2480 uname = utf_new_char((char *) name);
2481 usig = utf_new_char((char *) sig);
2483 f = class_findfield(c, uname, usig);
2486 exceptions_throw_nosuchfielderror(c, uname);
2488 return (jfieldID) f;
2492 /* GetStatic<type>Field ********************************************************
2494 This family of accessor routines returns the value of a static
2497 *******************************************************************************/
2499 #define JNI_GET_STATIC_FIELD(name, type, field) \
2500 type _Jv_JNI_GetStatic##name##Field(JNIEnv *env, jclass clazz, \
2506 STATISTICS(jniinvokation()); \
2508 c = (classinfo *) clazz; \
2509 f = (fieldinfo *) fieldID; \
2511 if (!(c->state & CLASS_INITIALIZED)) \
2512 if (!initialize_class(c)) \
2515 return f->value->field; \
2518 JNI_GET_STATIC_FIELD(Boolean, jboolean, i)
2519 JNI_GET_STATIC_FIELD(Byte, jbyte, i)
2520 JNI_GET_STATIC_FIELD(Char, jchar, i)
2521 JNI_GET_STATIC_FIELD(Short, jshort, i)
2522 JNI_GET_STATIC_FIELD(Int, jint, i)
2523 JNI_GET_STATIC_FIELD(Long, jlong, l)
2524 JNI_GET_STATIC_FIELD(Float, jfloat, f)
2525 JNI_GET_STATIC_FIELD(Double, jdouble, d)
2528 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
2534 STATISTICS(jniinvokation());
2536 c = (classinfo *) clazz;
2537 f = (fieldinfo *) fieldID;
2539 if (!(c->state & CLASS_INITIALIZED))
2540 if (!initialize_class(c))
2543 return _Jv_JNI_NewLocalRef(env, f->value->a);
2547 /* SetStatic<type>Field *******************************************************
2549 This family of accessor routines sets the value of a static field
2552 *******************************************************************************/
2554 #define JNI_SET_STATIC_FIELD(name, type, field) \
2555 void _Jv_JNI_SetStatic##name##Field(JNIEnv *env, jclass clazz, \
2562 STATISTICS(jniinvokation()); \
2564 c = (classinfo *) clazz; \
2565 f = (fieldinfo *) fieldID; \
2567 if (!(c->state & CLASS_INITIALIZED)) \
2568 if (!initialize_class(c)) \
2571 f->value->field = value; \
2574 JNI_SET_STATIC_FIELD(Boolean, jboolean, i)
2575 JNI_SET_STATIC_FIELD(Byte, jbyte, i)
2576 JNI_SET_STATIC_FIELD(Char, jchar, i)
2577 JNI_SET_STATIC_FIELD(Short, jshort, i)
2578 JNI_SET_STATIC_FIELD(Int, jint, i)
2579 JNI_SET_STATIC_FIELD(Long, jlong, l)
2580 JNI_SET_STATIC_FIELD(Float, jfloat, f)
2581 JNI_SET_STATIC_FIELD(Double, jdouble, d)
2584 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
2590 STATISTICS(jniinvokation());
2592 c = (classinfo *) clazz;
2593 f = (fieldinfo *) fieldID;
2595 if (!(c->state & CLASS_INITIALIZED))
2596 if (!initialize_class(c))
2599 f->value->a = value;
2603 /* String Operations **********************************************************/
2605 /* NewString *******************************************************************
2607 Create new java.lang.String object from an array of Unicode
2610 *******************************************************************************/
2612 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
2614 java_lang_String *s;
2618 STATISTICS(jniinvokation());
2620 s = (java_lang_String *) builtin_new(class_java_lang_String);
2621 a = builtin_newarray_char(len);
2623 /* javastring or characterarray could not be created */
2624 if ((a == NULL) || (s == NULL))
2628 for (i = 0; i < len; i++)
2629 a->data[i] = buf[i];
2631 LLNI_field_set_ref(s, value , a);
2632 LLNI_field_set_val(s, offset, 0);
2633 LLNI_field_set_val(s, count , len);
2635 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2639 static jchar emptyStringJ[]={0,0};
2641 /* GetStringLength *************************************************************
2643 Returns the length (the count of Unicode characters) of a Java
2646 *******************************************************************************/
2648 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
2650 java_lang_String *s;
2653 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
2655 s = (java_lang_String *) str;
2657 LLNI_field_get_val(s, count, len);
2663 /******************** convertes javastring to u2-array ****************************/
2665 u2 *javastring_tou2(jstring so)
2667 java_lang_String *s;
2672 STATISTICS(jniinvokation());
2674 s = (java_lang_String *) so;
2679 LLNI_field_get_ref(s, value, a);
2684 /* allocate memory */
2686 stringbuffer = MNEW(u2, LLNI_field_direct(s, count) + 1);
2690 for (i = 0; i < LLNI_field_direct(s, count); i++)
2691 stringbuffer[i] = a->data[LLNI_field_direct(s, offset) + i];
2693 /* terminate string */
2695 stringbuffer[i] = '\0';
2697 return stringbuffer;
2701 /* GetStringChars **************************************************************
2703 Returns a pointer to the array of Unicode characters of the
2704 string. This pointer is valid until ReleaseStringChars() is called.
2706 *******************************************************************************/
2708 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
2712 STATISTICS(jniinvokation());
2714 jc = javastring_tou2(str);
2726 return emptyStringJ;
2730 /* ReleaseStringChars **********************************************************
2732 Informs the VM that the native code no longer needs access to
2733 chars. The chars argument is a pointer obtained from string using
2736 *******************************************************************************/
2738 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
2740 java_lang_String *s;
2742 STATISTICS(jniinvokation());
2744 if (chars == emptyStringJ)
2747 s = (java_lang_String *) str;
2749 MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
2753 /* NewStringUTF ****************************************************************
2755 Constructs a new java.lang.String object from an array of UTF-8
2758 *******************************************************************************/
2760 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
2762 java_lang_String *s;
2764 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
2766 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
2768 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2772 /****************** returns the utf8 length in bytes of a string *******************/
2774 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
2776 java_lang_String *s;
2779 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
2781 s = (java_lang_String *) string;
2783 length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
2789 /* GetStringUTFChars ***********************************************************
2791 Returns a pointer to an array of UTF-8 characters of the
2792 string. This array is valid until it is released by
2793 ReleaseStringUTFChars().
2795 *******************************************************************************/
2797 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
2802 STATISTICS(jniinvokation());
2810 u = javastring_toutf((java_handle_t *) string, false);
2819 /* ReleaseStringUTFChars *******************************************************
2821 Informs the VM that the native code no longer needs access to
2822 utf. The utf argument is a pointer derived from string using
2823 GetStringUTFChars().
2825 *******************************************************************************/
2827 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
2829 STATISTICS(jniinvokation());
2831 /* XXX we don't release utf chars right now, perhaps that should be done
2832 later. Since there is always one reference the garbage collector will
2837 /* Array Operations ***********************************************************/
2839 /* GetArrayLength **************************************************************
2841 Returns the number of elements in the array.
2843 *******************************************************************************/
2845 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
2847 java_arrayheader *a;
2849 STATISTICS(jniinvokation());
2851 a = (java_arrayheader *) array;
2857 /* NewObjectArray **************************************************************
2859 Constructs a new array holding objects in class elementClass. All
2860 elements are initially set to initialElement.
2862 *******************************************************************************/
2864 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
2865 jclass elementClass, jobject initialElement)
2869 java_objectarray *oa;
2872 STATISTICS(jniinvokation());
2874 c = (classinfo *) elementClass;
2875 o = (java_handle_t *) initialElement;
2878 exceptions_throw_negativearraysizeexception();
2882 oa = builtin_anewarray(length, c);
2887 /* set all elements to initialElement */
2889 for (i = 0; i < length; i++)
2892 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
2896 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
2899 java_objectarray *oa;
2902 STATISTICS(jniinvokation());
2904 oa = (java_objectarray *) array;
2906 if (index >= oa->header.size) {
2907 exceptions_throw_arrayindexoutofboundsexception();
2911 o = oa->data[index];
2913 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2917 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
2918 jsize index, jobject val)
2920 java_objectarray *oa;
2923 STATISTICS(jniinvokation());
2925 oa = (java_objectarray *) array;
2926 o = (java_handle_t *) val;
2928 if (index >= oa->header.size) {
2929 exceptions_throw_arrayindexoutofboundsexception();
2933 /* check if the class of value is a subclass of the element class
2936 if (!builtin_canstore(oa, o))
2939 oa->data[index] = o;
2943 #define JNI_NEW_ARRAY(name, type, intern) \
2944 type _Jv_JNI_New##name##Array(JNIEnv *env, jsize len) \
2946 java_##intern##array *a; \
2948 STATISTICS(jniinvokation()); \
2951 exceptions_throw_negativearraysizeexception(); \
2955 a = builtin_newarray_##intern(len); \
2957 return (type) _Jv_JNI_NewLocalRef(env, (jobject) a); \
2960 JNI_NEW_ARRAY(Boolean, jbooleanArray, boolean)
2961 JNI_NEW_ARRAY(Byte, jbyteArray, byte)
2962 JNI_NEW_ARRAY(Char, jcharArray, char)
2963 JNI_NEW_ARRAY(Short, jshortArray, byte)
2964 JNI_NEW_ARRAY(Int, jintArray, int)
2965 JNI_NEW_ARRAY(Long, jlongArray, long)
2966 JNI_NEW_ARRAY(Float, jfloatArray, float)
2967 JNI_NEW_ARRAY(Double, jdoubleArray, double)
2970 /* Get<PrimitiveType>ArrayElements *********************************************
2972 A family of functions that returns the body of the primitive array.
2974 *******************************************************************************/
2976 #define JNI_GET_ARRAY_ELEMENTS(name, type, intern) \
2977 type *_Jv_JNI_Get##name##ArrayElements(JNIEnv *env, type##Array array, \
2980 java_##intern##array *a; \
2982 STATISTICS(jniinvokation()); \
2984 a = (java_##intern##array *) array; \
2987 *isCopy = JNI_FALSE; \
2992 JNI_GET_ARRAY_ELEMENTS(Boolean, jboolean, boolean)
2993 JNI_GET_ARRAY_ELEMENTS(Byte, jbyte, byte)
2994 JNI_GET_ARRAY_ELEMENTS(Char, jchar, char)
2995 JNI_GET_ARRAY_ELEMENTS(Short, jshort, short)
2996 JNI_GET_ARRAY_ELEMENTS(Int, jint, int)
2997 JNI_GET_ARRAY_ELEMENTS(Long, jlong, long)
2998 JNI_GET_ARRAY_ELEMENTS(Float, jfloat, float)
2999 JNI_GET_ARRAY_ELEMENTS(Double, jdouble, double)
3002 /* Release<PrimitiveType>ArrayElements *****************************************
3004 A family of functions that informs the VM that the native code no
3005 longer needs access to elems. The elems argument is a pointer
3006 derived from array using the corresponding
3007 Get<PrimitiveType>ArrayElements() function. If necessary, this
3008 function copies back all changes made to elems to the original
3011 *******************************************************************************/
3013 #define JNI_RELEASE_ARRAY_ELEMENTS(name, type, intern, intern2) \
3014 void _Jv_JNI_Release##name##ArrayElements(JNIEnv *env, type##Array array, \
3015 type *elems, jint mode) \
3017 java_##intern##array *a; \
3019 STATISTICS(jniinvokation()); \
3021 a = (java_##intern##array *) array; \
3023 if (elems != a->data) { \
3026 MCOPY(a->data, elems, intern2, a->header.size); \
3029 MCOPY(a->data, elems, intern2, a->header.size); \
3030 /* XXX TWISTI how should it be freed? */ \
3033 /* XXX TWISTI how should it be freed? */ \
3039 JNI_RELEASE_ARRAY_ELEMENTS(Boolean, jboolean, boolean, u1)
3040 JNI_RELEASE_ARRAY_ELEMENTS(Byte, jbyte, byte, s1)
3041 JNI_RELEASE_ARRAY_ELEMENTS(Char, jchar, char, u2)
3042 JNI_RELEASE_ARRAY_ELEMENTS(Short, jshort, short, s2)
3043 JNI_RELEASE_ARRAY_ELEMENTS(Int, jint, int, s4)
3044 JNI_RELEASE_ARRAY_ELEMENTS(Long, jlong, long, s8)
3045 JNI_RELEASE_ARRAY_ELEMENTS(Float, jfloat, float, float)
3046 JNI_RELEASE_ARRAY_ELEMENTS(Double, jdouble, double, double)
3049 /* Get<PrimitiveType>ArrayRegion **********************************************
3051 A family of functions that copies a region of a primitive array
3054 *******************************************************************************/
3056 #define JNI_GET_ARRAY_REGION(name, type, intern, intern2) \
3057 void _Jv_JNI_Get##name##ArrayRegion(JNIEnv *env, type##Array array, \
3058 jsize start, jsize len, type *buf) \
3060 java_##intern##array *a; \
3062 STATISTICS(jniinvokation()); \
3064 a = (java_##intern##array *) array; \
3066 if ((start < 0) || (len < 0) || (start + len > a->header.size)) \
3067 exceptions_throw_arrayindexoutofboundsexception(); \
3069 MCOPY(buf, &a->data[start], intern2, len); \
3072 JNI_GET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3073 JNI_GET_ARRAY_REGION(Byte, jbyte, byte, s1)
3074 JNI_GET_ARRAY_REGION(Char, jchar, char, u2)
3075 JNI_GET_ARRAY_REGION(Short, jshort, short, s2)
3076 JNI_GET_ARRAY_REGION(Int, jint, int, s4)
3077 JNI_GET_ARRAY_REGION(Long, jlong, long, s8)
3078 JNI_GET_ARRAY_REGION(Float, jfloat, float, float)
3079 JNI_GET_ARRAY_REGION(Double, jdouble, double, double)
3082 /* Set<PrimitiveType>ArrayRegion **********************************************
3084 A family of functions that copies back a region of a primitive
3085 array from a buffer.
3087 *******************************************************************************/
3089 #define JNI_SET_ARRAY_REGION(name, type, intern, intern2) \
3090 void _Jv_JNI_Set##name##ArrayRegion(JNIEnv *env, type##Array array, \
3091 jsize start, jsize len, const type *buf) \
3093 java_##intern##array *a; \
3095 STATISTICS(jniinvokation()); \
3097 a = (java_##intern##array *) array; \
3099 if ((start < 0) || (len < 0) || (start + len > a->header.size)) \
3100 exceptions_throw_arrayindexoutofboundsexception(); \
3102 MCOPY(&a->data[start], buf, intern2, len); \
3105 JNI_SET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3106 JNI_SET_ARRAY_REGION(Byte, jbyte, byte, s1)
3107 JNI_SET_ARRAY_REGION(Char, jchar, char, u2)
3108 JNI_SET_ARRAY_REGION(Short, jshort, short, s2)
3109 JNI_SET_ARRAY_REGION(Int, jint, int, s4)
3110 JNI_SET_ARRAY_REGION(Long, jlong, long, s8)
3111 JNI_SET_ARRAY_REGION(Float, jfloat, float, float)
3112 JNI_SET_ARRAY_REGION(Double, jdouble, double, double)
3115 /* Registering Native Methods *************************************************/
3117 /* RegisterNatives *************************************************************
3119 Registers native methods with the class specified by the clazz
3120 argument. The methods parameter specifies an array of
3121 JNINativeMethod structures that contain the names, signatures, and
3122 function pointers of the native methods. The nMethods parameter
3123 specifies the number of native methods in the array.
3125 *******************************************************************************/
3127 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
3128 const JNINativeMethod *methods, jint nMethods)
3132 STATISTICS(jniinvokation());
3134 c = (classinfo *) clazz;
3136 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
3137 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
3140 native_method_register(c->name, methods, nMethods);
3146 /* UnregisterNatives ***********************************************************
3148 Unregisters native methods of a class. The class goes back to the
3149 state before it was linked or registered with its native method
3152 This function should not be used in normal native code. Instead, it
3153 provides special programs a way to reload and relink native
3156 *******************************************************************************/
3158 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
3160 STATISTICS(jniinvokation());
3162 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
3164 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
3170 /* Monitor Operations *********************************************************/
3172 /* MonitorEnter ****************************************************************
3174 Enters the monitor associated with the underlying Java object
3177 *******************************************************************************/
3179 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
3181 STATISTICS(jniinvokation());
3184 exceptions_throw_nullpointerexception();
3188 LOCK_MONITOR_ENTER(obj);
3194 /* MonitorExit *****************************************************************
3196 The current thread must be the owner of the monitor associated with
3197 the underlying Java object referred to by obj. The thread
3198 decrements the counter indicating the number of times it has
3199 entered this monitor. If the value of the counter becomes zero, the
3200 current thread releases the monitor.
3202 *******************************************************************************/
3204 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
3206 STATISTICS(jniinvokation());
3209 exceptions_throw_nullpointerexception();
3213 LOCK_MONITOR_EXIT(obj);
3219 /* JavaVM Interface ***********************************************************/
3221 /* GetJavaVM *******************************************************************
3223 Returns the Java VM interface (used in the Invocation API)
3224 associated with the current thread. The result is placed at the
3225 location pointed to by the second argument, vm.
3227 *******************************************************************************/
3229 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
3231 STATISTICS(jniinvokation());
3233 *vm = (JavaVM *) _Jv_jvm;
3239 /* GetStringRegion *************************************************************
3241 Copies len number of Unicode characters beginning at offset start
3242 to the given buffer buf.
3244 Throws StringIndexOutOfBoundsException on index overflow.
3246 *******************************************************************************/
3248 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
3251 java_lang_String *s;
3254 STATISTICS(jniinvokation());
3256 s = (java_lang_String *) str;
3257 LLNI_field_get_ref(s, value, ca);
3259 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
3260 (start + len > LLNI_field_direct(s, count))) {
3261 exceptions_throw_stringindexoutofboundsexception();
3265 MCOPY(buf, &ca->data[start], u2, len);
3269 /* GetStringUTFRegion **********************************************************
3271 Translates len number of Unicode characters beginning at offset
3272 start into UTF-8 format and place the result in the given buffer
3275 Throws StringIndexOutOfBoundsException on index overflow.
3277 *******************************************************************************/
3279 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
3280 jsize len, char *buf)
3282 java_lang_String *s;
3286 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
3288 s = (java_lang_String *) str;
3289 LLNI_field_get_ref(s, value, ca);
3291 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
3292 (start + len > LLNI_field_direct(s, count))) {
3293 exceptions_throw_stringindexoutofboundsexception();
3297 for (i = 0; i < len; i++)
3298 buf[i] = ca->data[LLNI_field_direct(s, offset) + start + i];
3304 /* GetPrimitiveArrayCritical ***************************************************
3306 Obtain a direct pointer to array elements.
3308 *******************************************************************************/
3310 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
3316 ba = (java_bytearray *) array;
3318 /* do the same as Kaffe does */
3320 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
3326 /* ReleasePrimitiveArrayCritical ***********************************************
3328 No specific documentation.
3330 *******************************************************************************/
3332 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
3333 void *carray, jint mode)
3335 STATISTICS(jniinvokation());
3337 /* do the same as Kaffe does */
3339 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
3344 /* GetStringCritical ***********************************************************
3346 The semantics of these two functions are similar to the existing
3347 Get/ReleaseStringChars functions.
3349 *******************************************************************************/
3351 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
3354 STATISTICS(jniinvokation());
3356 return _Jv_JNI_GetStringChars(env, string, isCopy);
3360 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
3361 const jchar *cstring)
3363 STATISTICS(jniinvokation());
3365 _Jv_JNI_ReleaseStringChars(env, string, cstring);
3369 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
3371 STATISTICS(jniinvokation());
3373 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
3379 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
3381 STATISTICS(jniinvokation());
3383 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
3387 /* NewGlobalRef ****************************************************************
3389 Creates a new global reference to the object referred to by the obj
3392 *******************************************************************************/
3394 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
3396 hashtable_global_ref_entry *gre;
3397 u4 key; /* hashkey */
3398 u4 slot; /* slot in hashtable */
3401 STATISTICS(jniinvokation());
3403 o = (java_handle_t *) obj;
3405 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3407 /* normally addresses are aligned to 4, 8 or 16 bytes */
3409 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
3410 slot = key & (hashtable_global_ref->size - 1);
3411 gre = hashtable_global_ref->ptr[slot];
3413 /* search external hash chain for the entry */
3417 /* global object found, increment the reference */
3421 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3426 gre = gre->hashlink; /* next element in external chain */
3429 /* global ref not found, create a new one */
3431 gre = NEW(hashtable_global_ref_entry);
3436 /* insert entry into hashtable */
3438 gre->hashlink = hashtable_global_ref->ptr[slot];
3440 hashtable_global_ref->ptr[slot] = gre;
3442 /* update number of hashtable-entries */
3444 hashtable_global_ref->entries++;
3446 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3452 /* DeleteGlobalRef *************************************************************
3454 Deletes the global reference pointed to by globalRef.
3456 *******************************************************************************/
3458 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
3460 hashtable_global_ref_entry *gre;
3461 hashtable_global_ref_entry *prevgre;
3462 u4 key; /* hashkey */
3463 u4 slot; /* slot in hashtable */
3466 STATISTICS(jniinvokation());
3468 o = (java_handle_t *) globalRef;
3470 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3472 /* normally addresses are aligned to 4, 8 or 16 bytes */
3474 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
3475 slot = key & (hashtable_global_ref->size - 1);
3476 gre = hashtable_global_ref->ptr[slot];
3478 /* initialize prevgre */
3482 /* search external hash chain for the entry */
3486 /* global object found, decrement the reference count */
3490 /* if reference count is 0, remove the entry */
3492 if (gre->refs == 0) {
3493 /* special handling if it's the first in the chain */
3495 if (prevgre == NULL)
3496 hashtable_global_ref->ptr[slot] = gre->hashlink;
3498 prevgre->hashlink = gre->hashlink;
3500 FREE(gre, hashtable_global_ref_entry);
3503 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3508 prevgre = gre; /* save current pointer for removal */
3509 gre = gre->hashlink; /* next element in external chain */
3512 log_println("JNI-DeleteGlobalRef: global reference not found");
3514 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3518 /* ExceptionCheck **************************************************************
3520 Returns JNI_TRUE when there is a pending exception; otherwise,
3523 *******************************************************************************/
3525 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
3529 STATISTICS(jniinvokation());
3531 o = exceptions_get_exception();
3533 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
3537 /* New JNI 1.4 functions ******************************************************/
3539 /* NewDirectByteBuffer *********************************************************
3541 Allocates and returns a direct java.nio.ByteBuffer referring to the
3542 block of memory starting at the memory address address and
3543 extending capacity bytes.
3545 *******************************************************************************/
3547 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
3549 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3550 java_handle_t *nbuf;
3552 # if SIZEOF_VOID_P == 8
3553 gnu_classpath_Pointer64 *paddress;
3555 gnu_classpath_Pointer32 *paddress;
3558 STATISTICS(jniinvokation());
3560 /* alocate a gnu.classpath.Pointer{32,64} object */
3562 # if SIZEOF_VOID_P == 8
3563 if (!(paddress = (gnu_classpath_Pointer64 *)
3564 builtin_new(class_gnu_classpath_Pointer64)))
3566 if (!(paddress = (gnu_classpath_Pointer32 *)
3567 builtin_new(class_gnu_classpath_Pointer32)))
3571 /* fill gnu.classpath.Pointer{32,64} with address */
3573 LLNI_field_set_val(paddress, data, (ptrint) address);
3575 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
3577 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
3578 (jmethodID) dbbirw_init, NULL, paddress,
3579 (jint) capacity, (jint) capacity, (jint) 0);
3581 /* add local reference and return the value */
3583 return _Jv_JNI_NewLocalRef(env, nbuf);
3585 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
3587 /* keep compiler happy */
3594 /* GetDirectBufferAddress ******************************************************
3596 Fetches and returns the starting address of the memory region
3597 referenced by the given direct java.nio.Buffer.
3599 *******************************************************************************/
3601 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
3603 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3604 java_nio_DirectByteBufferImpl *nbuf;
3605 # if SIZEOF_VOID_P == 8
3606 gnu_classpath_Pointer64 *paddress;
3608 gnu_classpath_Pointer32 *paddress;
3612 STATISTICS(jniinvokation());
3614 if (!builtin_instanceof(buf, class_java_nio_Buffer))
3617 nbuf = (java_nio_DirectByteBufferImpl *) buf;
3619 # if SIZEOF_VOID_P == 8
3620 LLNI_field_get_ref(nbuf, address, paddress);
3621 /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
3623 LLNI_field_get_ref(nbuf, address, paddress);
3624 /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
3627 if (paddress == NULL)
3630 LLNI_field_get_val(paddress, data, address);
3631 /* this was the cast to avaoid warning: (void *) paddress->data */
3635 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
3637 /* keep compiler happy */
3644 /* GetDirectBufferCapacity *****************************************************
3646 Fetches and returns the capacity in bytes of the memory region
3647 referenced by the given direct java.nio.Buffer.
3649 *******************************************************************************/
3651 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
3653 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3655 java_nio_Buffer *nbuf;
3658 STATISTICS(jniinvokation());
3660 o = (java_handle_t *) buf;
3662 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
3665 nbuf = (java_nio_Buffer *) o;
3667 LLNI_field_get_val(nbuf, cap, capacity);
3671 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
3673 /* keep compiler happy */
3680 /* DestroyJavaVM ***************************************************************
3682 Unloads a Java VM and reclaims its resources. Only the main thread
3683 can unload the VM. The system waits until the main thread is only
3684 remaining user thread before it destroys the VM.
3686 *******************************************************************************/
3688 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
3692 STATISTICS(jniinvokation());
3694 status = vm_destroy(vm);
3700 /* AttachCurrentThread *********************************************************
3702 Attaches the current thread to a Java VM. Returns a JNI interface
3703 pointer in the JNIEnv argument.
3705 Trying to attach a thread that is already attached is a no-op.
3707 A native thread cannot be attached simultaneously to two Java VMs.
3709 When a thread is attached to the VM, the context class loader is
3710 the bootstrap loader.
3712 *******************************************************************************/
3714 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
3716 JavaVMAttachArgs *vm_aargs;
3718 #if defined(ENABLE_THREADS)
3719 if (threads_get_current_threadobject() == NULL) {
3720 vm_aargs = (JavaVMAttachArgs *) thr_args;
3722 if (vm_aargs != NULL) {
3723 if ((vm_aargs->version != JNI_VERSION_1_2) &&
3724 (vm_aargs->version != JNI_VERSION_1_4))
3725 return JNI_EVERSION;
3728 if (!threads_attach_current_thread(vm_aargs, false))
3731 if (!localref_table_init())
3742 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
3744 STATISTICS(jniinvokation());
3746 return jni_attach_current_thread(p_env, thr_args, false);
3750 /* DetachCurrentThread *********************************************************
3752 Detaches the current thread from a Java VM. All Java monitors held
3753 by this thread are released. All Java threads waiting for this
3754 thread to die are notified.
3756 In JDK 1.1, the main thread cannot be detached from the VM. It must
3757 call DestroyJavaVM to unload the entire VM.
3759 In the JDK, the main thread can be detached from the VM.
3761 The main thread, which is the thread that created the Java VM,
3762 cannot be detached from the VM. Instead, the main thread must call
3763 JNI_DestroyJavaVM() to unload the entire VM.
3765 *******************************************************************************/
3767 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
3769 #if defined(ENABLE_THREADS)
3770 threadobject *thread;
3772 STATISTICS(jniinvokation());
3774 thread = threads_get_current_threadobject();
3779 if (!threads_detach_thread(thread))
3787 /* GetEnv **********************************************************************
3789 If the current thread is not attached to the VM, sets *env to NULL,
3790 and returns JNI_EDETACHED. If the specified version is not
3791 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
3792 sets *env to the appropriate interface, and returns JNI_OK.
3794 *******************************************************************************/
3796 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
3798 STATISTICS(jniinvokation());
3800 #if defined(ENABLE_THREADS)
3801 if (threads_get_current_threadobject() == NULL) {
3804 return JNI_EDETACHED;
3808 /* check the JNI version */
3811 case JNI_VERSION_1_1:
3812 case JNI_VERSION_1_2:
3813 case JNI_VERSION_1_4:
3821 #if defined(ENABLE_JVMTI)
3822 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
3823 == JVMTI_VERSION_INTERFACE_JVMTI) {
3825 *env = (void *) jvmti_new_environment();
3834 return JNI_EVERSION;
3838 /* AttachCurrentThreadAsDaemon *************************************************
3840 Same semantics as AttachCurrentThread, but the newly-created
3841 java.lang.Thread instance is a daemon.
3843 If the thread has already been attached via either
3844 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
3845 simply sets the value pointed to by penv to the JNIEnv of the
3846 current thread. In this case neither AttachCurrentThread nor this
3847 routine have any effect on the daemon status of the thread.
3849 *******************************************************************************/
3851 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
3853 STATISTICS(jniinvokation());
3855 return jni_attach_current_thread(penv, args, true);
3859 /* JNI invocation table *******************************************************/
3861 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
3866 _Jv_JNI_DestroyJavaVM,
3867 _Jv_JNI_AttachCurrentThread,
3868 _Jv_JNI_DetachCurrentThread,
3870 _Jv_JNI_AttachCurrentThreadAsDaemon
3874 /* JNI function table *********************************************************/
3876 struct JNINativeInterface_ _Jv_JNINativeInterface = {
3883 _Jv_JNI_DefineClass,
3885 _Jv_JNI_FromReflectedMethod,
3886 _Jv_JNI_FromReflectedField,
3887 _Jv_JNI_ToReflectedMethod,
3888 _Jv_JNI_GetSuperclass,
3889 _Jv_JNI_IsAssignableFrom,
3890 _Jv_JNI_ToReflectedField,
3894 _Jv_JNI_ExceptionOccurred,
3895 _Jv_JNI_ExceptionDescribe,
3896 _Jv_JNI_ExceptionClear,
3898 _Jv_JNI_PushLocalFrame,
3899 _Jv_JNI_PopLocalFrame,
3901 _Jv_JNI_NewGlobalRef,
3902 _Jv_JNI_DeleteGlobalRef,
3903 _Jv_JNI_DeleteLocalRef,
3904 _Jv_JNI_IsSameObject,
3905 _Jv_JNI_NewLocalRef,
3906 _Jv_JNI_EnsureLocalCapacity,
3908 _Jv_JNI_AllocObject,
3913 _Jv_JNI_GetObjectClass,
3914 _Jv_JNI_IsInstanceOf,
3916 _Jv_JNI_GetMethodID,
3918 _Jv_JNI_CallObjectMethod,
3919 _Jv_JNI_CallObjectMethodV,
3920 _Jv_JNI_CallObjectMethodA,
3921 _Jv_JNI_CallBooleanMethod,
3922 _Jv_JNI_CallBooleanMethodV,
3923 _Jv_JNI_CallBooleanMethodA,
3924 _Jv_JNI_CallByteMethod,
3925 _Jv_JNI_CallByteMethodV,
3926 _Jv_JNI_CallByteMethodA,
3927 _Jv_JNI_CallCharMethod,
3928 _Jv_JNI_CallCharMethodV,
3929 _Jv_JNI_CallCharMethodA,
3930 _Jv_JNI_CallShortMethod,
3931 _Jv_JNI_CallShortMethodV,
3932 _Jv_JNI_CallShortMethodA,
3933 _Jv_JNI_CallIntMethod,
3934 _Jv_JNI_CallIntMethodV,
3935 _Jv_JNI_CallIntMethodA,
3936 _Jv_JNI_CallLongMethod,
3937 _Jv_JNI_CallLongMethodV,
3938 _Jv_JNI_CallLongMethodA,
3939 _Jv_JNI_CallFloatMethod,
3940 _Jv_JNI_CallFloatMethodV,
3941 _Jv_JNI_CallFloatMethodA,
3942 _Jv_JNI_CallDoubleMethod,
3943 _Jv_JNI_CallDoubleMethodV,
3944 _Jv_JNI_CallDoubleMethodA,
3945 _Jv_JNI_CallVoidMethod,
3946 _Jv_JNI_CallVoidMethodV,
3947 _Jv_JNI_CallVoidMethodA,
3949 _Jv_JNI_CallNonvirtualObjectMethod,
3950 _Jv_JNI_CallNonvirtualObjectMethodV,
3951 _Jv_JNI_CallNonvirtualObjectMethodA,
3952 _Jv_JNI_CallNonvirtualBooleanMethod,
3953 _Jv_JNI_CallNonvirtualBooleanMethodV,
3954 _Jv_JNI_CallNonvirtualBooleanMethodA,
3955 _Jv_JNI_CallNonvirtualByteMethod,
3956 _Jv_JNI_CallNonvirtualByteMethodV,
3957 _Jv_JNI_CallNonvirtualByteMethodA,
3958 _Jv_JNI_CallNonvirtualCharMethod,
3959 _Jv_JNI_CallNonvirtualCharMethodV,
3960 _Jv_JNI_CallNonvirtualCharMethodA,
3961 _Jv_JNI_CallNonvirtualShortMethod,
3962 _Jv_JNI_CallNonvirtualShortMethodV,
3963 _Jv_JNI_CallNonvirtualShortMethodA,
3964 _Jv_JNI_CallNonvirtualIntMethod,
3965 _Jv_JNI_CallNonvirtualIntMethodV,
3966 _Jv_JNI_CallNonvirtualIntMethodA,
3967 _Jv_JNI_CallNonvirtualLongMethod,
3968 _Jv_JNI_CallNonvirtualLongMethodV,
3969 _Jv_JNI_CallNonvirtualLongMethodA,
3970 _Jv_JNI_CallNonvirtualFloatMethod,
3971 _Jv_JNI_CallNonvirtualFloatMethodV,
3972 _Jv_JNI_CallNonvirtualFloatMethodA,
3973 _Jv_JNI_CallNonvirtualDoubleMethod,
3974 _Jv_JNI_CallNonvirtualDoubleMethodV,
3975 _Jv_JNI_CallNonvirtualDoubleMethodA,
3976 _Jv_JNI_CallNonvirtualVoidMethod,
3977 _Jv_JNI_CallNonvirtualVoidMethodV,
3978 _Jv_JNI_CallNonvirtualVoidMethodA,
3982 _Jv_JNI_GetObjectField,
3983 _Jv_JNI_GetBooleanField,
3984 _Jv_JNI_GetByteField,
3985 _Jv_JNI_GetCharField,
3986 _Jv_JNI_GetShortField,
3987 _Jv_JNI_GetIntField,
3988 _Jv_JNI_GetLongField,
3989 _Jv_JNI_GetFloatField,
3990 _Jv_JNI_GetDoubleField,
3991 _Jv_JNI_SetObjectField,
3992 _Jv_JNI_SetBooleanField,
3993 _Jv_JNI_SetByteField,
3994 _Jv_JNI_SetCharField,
3995 _Jv_JNI_SetShortField,
3996 _Jv_JNI_SetIntField,
3997 _Jv_JNI_SetLongField,
3998 _Jv_JNI_SetFloatField,
3999 _Jv_JNI_SetDoubleField,
4001 _Jv_JNI_GetStaticMethodID,
4003 _Jv_JNI_CallStaticObjectMethod,
4004 _Jv_JNI_CallStaticObjectMethodV,
4005 _Jv_JNI_CallStaticObjectMethodA,
4006 _Jv_JNI_CallStaticBooleanMethod,
4007 _Jv_JNI_CallStaticBooleanMethodV,
4008 _Jv_JNI_CallStaticBooleanMethodA,
4009 _Jv_JNI_CallStaticByteMethod,
4010 _Jv_JNI_CallStaticByteMethodV,
4011 _Jv_JNI_CallStaticByteMethodA,
4012 _Jv_JNI_CallStaticCharMethod,
4013 _Jv_JNI_CallStaticCharMethodV,
4014 _Jv_JNI_CallStaticCharMethodA,
4015 _Jv_JNI_CallStaticShortMethod,
4016 _Jv_JNI_CallStaticShortMethodV,
4017 _Jv_JNI_CallStaticShortMethodA,
4018 _Jv_JNI_CallStaticIntMethod,
4019 _Jv_JNI_CallStaticIntMethodV,
4020 _Jv_JNI_CallStaticIntMethodA,
4021 _Jv_JNI_CallStaticLongMethod,
4022 _Jv_JNI_CallStaticLongMethodV,
4023 _Jv_JNI_CallStaticLongMethodA,
4024 _Jv_JNI_CallStaticFloatMethod,
4025 _Jv_JNI_CallStaticFloatMethodV,
4026 _Jv_JNI_CallStaticFloatMethodA,
4027 _Jv_JNI_CallStaticDoubleMethod,
4028 _Jv_JNI_CallStaticDoubleMethodV,
4029 _Jv_JNI_CallStaticDoubleMethodA,
4030 _Jv_JNI_CallStaticVoidMethod,
4031 _Jv_JNI_CallStaticVoidMethodV,
4032 _Jv_JNI_CallStaticVoidMethodA,
4034 _Jv_JNI_GetStaticFieldID,
4036 _Jv_JNI_GetStaticObjectField,
4037 _Jv_JNI_GetStaticBooleanField,
4038 _Jv_JNI_GetStaticByteField,
4039 _Jv_JNI_GetStaticCharField,
4040 _Jv_JNI_GetStaticShortField,
4041 _Jv_JNI_GetStaticIntField,
4042 _Jv_JNI_GetStaticLongField,
4043 _Jv_JNI_GetStaticFloatField,
4044 _Jv_JNI_GetStaticDoubleField,
4045 _Jv_JNI_SetStaticObjectField,
4046 _Jv_JNI_SetStaticBooleanField,
4047 _Jv_JNI_SetStaticByteField,
4048 _Jv_JNI_SetStaticCharField,
4049 _Jv_JNI_SetStaticShortField,
4050 _Jv_JNI_SetStaticIntField,
4051 _Jv_JNI_SetStaticLongField,
4052 _Jv_JNI_SetStaticFloatField,
4053 _Jv_JNI_SetStaticDoubleField,
4056 _Jv_JNI_GetStringLength,
4057 _Jv_JNI_GetStringChars,
4058 _Jv_JNI_ReleaseStringChars,
4060 _Jv_JNI_NewStringUTF,
4061 _Jv_JNI_GetStringUTFLength,
4062 _Jv_JNI_GetStringUTFChars,
4063 _Jv_JNI_ReleaseStringUTFChars,
4065 _Jv_JNI_GetArrayLength,
4067 _Jv_JNI_NewObjectArray,
4068 _Jv_JNI_GetObjectArrayElement,
4069 _Jv_JNI_SetObjectArrayElement,
4071 _Jv_JNI_NewBooleanArray,
4072 _Jv_JNI_NewByteArray,
4073 _Jv_JNI_NewCharArray,
4074 _Jv_JNI_NewShortArray,
4075 _Jv_JNI_NewIntArray,
4076 _Jv_JNI_NewLongArray,
4077 _Jv_JNI_NewFloatArray,
4078 _Jv_JNI_NewDoubleArray,
4080 _Jv_JNI_GetBooleanArrayElements,
4081 _Jv_JNI_GetByteArrayElements,
4082 _Jv_JNI_GetCharArrayElements,
4083 _Jv_JNI_GetShortArrayElements,
4084 _Jv_JNI_GetIntArrayElements,
4085 _Jv_JNI_GetLongArrayElements,
4086 _Jv_JNI_GetFloatArrayElements,
4087 _Jv_JNI_GetDoubleArrayElements,
4089 _Jv_JNI_ReleaseBooleanArrayElements,
4090 _Jv_JNI_ReleaseByteArrayElements,
4091 _Jv_JNI_ReleaseCharArrayElements,
4092 _Jv_JNI_ReleaseShortArrayElements,
4093 _Jv_JNI_ReleaseIntArrayElements,
4094 _Jv_JNI_ReleaseLongArrayElements,
4095 _Jv_JNI_ReleaseFloatArrayElements,
4096 _Jv_JNI_ReleaseDoubleArrayElements,
4098 _Jv_JNI_GetBooleanArrayRegion,
4099 _Jv_JNI_GetByteArrayRegion,
4100 _Jv_JNI_GetCharArrayRegion,
4101 _Jv_JNI_GetShortArrayRegion,
4102 _Jv_JNI_GetIntArrayRegion,
4103 _Jv_JNI_GetLongArrayRegion,
4104 _Jv_JNI_GetFloatArrayRegion,
4105 _Jv_JNI_GetDoubleArrayRegion,
4106 _Jv_JNI_SetBooleanArrayRegion,
4107 _Jv_JNI_SetByteArrayRegion,
4108 _Jv_JNI_SetCharArrayRegion,
4109 _Jv_JNI_SetShortArrayRegion,
4110 _Jv_JNI_SetIntArrayRegion,
4111 _Jv_JNI_SetLongArrayRegion,
4112 _Jv_JNI_SetFloatArrayRegion,
4113 _Jv_JNI_SetDoubleArrayRegion,
4115 _Jv_JNI_RegisterNatives,
4116 _Jv_JNI_UnregisterNatives,
4118 _Jv_JNI_MonitorEnter,
4119 _Jv_JNI_MonitorExit,
4123 /* new JNI 1.2 functions */
4125 _Jv_JNI_GetStringRegion,
4126 _Jv_JNI_GetStringUTFRegion,
4128 _Jv_JNI_GetPrimitiveArrayCritical,
4129 _Jv_JNI_ReleasePrimitiveArrayCritical,
4131 _Jv_JNI_GetStringCritical,
4132 _Jv_JNI_ReleaseStringCritical,
4134 _Jv_JNI_NewWeakGlobalRef,
4135 _Jv_JNI_DeleteWeakGlobalRef,
4137 _Jv_JNI_ExceptionCheck,
4139 /* new JNI 1.4 functions */
4141 _Jv_JNI_NewDirectByteBuffer,
4142 _Jv_JNI_GetDirectBufferAddress,
4143 _Jv_JNI_GetDirectBufferCapacity
4147 /* Invocation API Functions ***************************************************/
4149 /* JNI_GetDefaultJavaVMInitArgs ************************************************
4151 Returns a default configuration for the Java VM.
4153 *******************************************************************************/
4155 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
4157 JavaVMInitArgs *_vm_args;
4159 _vm_args = (JavaVMInitArgs *) vm_args;
4161 /* GNU classpath currently supports JNI 1.2 */
4163 switch (_vm_args->version) {
4164 case JNI_VERSION_1_1:
4165 _vm_args->version = JNI_VERSION_1_1;
4168 case JNI_VERSION_1_2:
4169 case JNI_VERSION_1_4:
4170 _vm_args->ignoreUnrecognized = JNI_FALSE;
4171 _vm_args->options = NULL;
4172 _vm_args->nOptions = 0;
4183 /* JNI_GetCreatedJavaVMs *******************************************************
4185 Returns all Java VMs that have been created. Pointers to VMs are written in
4186 the buffer vmBuf in the order they are created. At most bufLen number of
4187 entries will be written. The total number of created VMs is returned in
4190 *******************************************************************************/
4192 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
4194 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
4199 /* We currently only support 1 VM running. */
4201 vmBuf[0] = (JavaVM *) _Jv_jvm;
4208 /* JNI_CreateJavaVM ************************************************************
4210 Loads and initializes a Java VM. The current thread becomes the main thread.
4211 Sets the env argument to the JNI interface pointer of the main thread.
4213 *******************************************************************************/
4215 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
4217 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
4219 /* actually create the JVM */
4221 if (!vm_createjvm(p_vm, p_env, vm_args))
4229 * These are local overrides for various environment variables in Emacs.
4230 * Please do not remove this and leave it at the end of the file, where
4231 * Emacs will automagically detect them.
4232 * ---------------------------------------------------------------------
4235 * indent-tabs-mode: t
4239 * vim:noexpandtab:sw=4:ts=4: