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
36 #include "mm/gc-common.h"
37 #include "mm/memory.h"
39 #include "native/jni.h"
40 #include "native/llni.h"
41 #include "native/localref.h"
42 #include "native/native.h"
44 #if defined(ENABLE_JAVASE)
45 # if defined(WITH_CLASSPATH_GNU)
46 # include "native/include/gnu_classpath_Pointer.h"
48 # if SIZEOF_VOID_P == 8
49 # include "native/include/gnu_classpath_Pointer64.h"
51 # include "native/include/gnu_classpath_Pointer32.h"
56 #include "native/include/java_lang_Object.h"
57 #include "native/include/java_lang_Byte.h"
58 #include "native/include/java_lang_Character.h"
59 #include "native/include/java_lang_Short.h"
60 #include "native/include/java_lang_Integer.h"
61 #include "native/include/java_lang_Boolean.h"
62 #include "native/include/java_lang_Long.h"
63 #include "native/include/java_lang_Float.h"
64 #include "native/include/java_lang_Double.h"
65 #include "native/include/java_lang_String.h"
66 #include "native/include/java_lang_Throwable.h"
68 #if defined(ENABLE_JAVASE)
69 # if defined(WITH_CLASSPATH_SUN)
70 # include "native/include/java_nio_ByteBuffer.h" /* required by j.l.CL */
73 # include "native/include/java_lang_ClassLoader.h"
75 # include "native/include/java_lang_reflect_Constructor.h"
76 # include "native/include/java_lang_reflect_Field.h"
77 # include "native/include/java_lang_reflect_Method.h"
79 # include "native/include/java_nio_Buffer.h"
81 # if defined(WITH_CLASSPATH_GNU)
82 # include "native/include/java_nio_DirectByteBufferImpl.h"
86 #if defined(ENABLE_JVMTI)
87 # include "native/jvmti/cacaodbg.h"
90 #include "native/vm/java_lang_Class.h"
92 #if defined(ENABLE_JAVASE)
93 # include "native/vm/java_lang_ClassLoader.h"
94 # include "native/vm/reflect.h"
97 #include "threads/lock-common.h"
98 #include "threads/threads-common.h"
100 #include "toolbox/logging.h"
102 #include "vm/builtin.h"
103 #include "vm/exceptions.h"
104 #include "vm/global.h"
105 #include "vm/initialize.h"
106 #include "vm/primitive.h"
107 #include "vm/resolve.h"
108 #include "vm/stringlocal.h"
111 #include "vm/jit/asmpart.h"
112 #include "vm/jit/jit.h"
113 #include "vm/jit/stacktrace.h"
115 #include "vmcore/loader.h"
116 #include "vmcore/options.h"
117 #include "vmcore/statistics.h"
120 /* debug **********************************************************************/
123 # define TRACEJNICALLS(format, ...) \
125 if (opt_TraceJNICalls) { \
126 log_println((format), __VA_ARGS__); \
130 # define TRACEJNICALLS(format, ...)
134 /* global variables ***********************************************************/
136 /* global reference table *****************************************************/
138 /* hashsize must be power of 2 */
140 #define HASHTABLE_GLOBAL_REF_SIZE 64 /* initial size of globalref-hash */
142 static hashtable *hashtable_global_ref; /* hashtable for globalrefs */
145 /* direct buffer stuff ********************************************************/
147 #if defined(ENABLE_JAVASE)
148 static classinfo *class_java_nio_Buffer;
149 static classinfo *class_java_nio_DirectByteBufferImpl;
150 static classinfo *class_java_nio_DirectByteBufferImpl_ReadWrite;
152 # if defined(WITH_CLASSPATH_GNU)
153 # if SIZEOF_VOID_P == 8
154 static classinfo *class_gnu_classpath_Pointer64;
156 static classinfo *class_gnu_classpath_Pointer32;
160 static methodinfo *dbbirw_init;
164 /* accessing instance fields macros *******************************************/
166 #define SET_FIELD(o,type,f,value) \
167 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset))) = (type) (value)
169 #define GET_FIELD(o,type,f) \
170 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset)))
173 /* some forward declarations **************************************************/
175 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
176 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
179 /* jni_init ********************************************************************
181 Initialize the JNI subsystem.
183 *******************************************************************************/
187 /* create global ref hashtable */
189 hashtable_global_ref = NEW(hashtable);
191 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
194 #if defined(ENABLE_JAVASE)
195 /* direct buffer stuff */
197 if (!(class_java_nio_Buffer =
198 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
199 !link_class(class_java_nio_Buffer))
202 # if defined(WITH_CLASSPATH_GNU)
203 if (!(class_java_nio_DirectByteBufferImpl =
204 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
205 !link_class(class_java_nio_DirectByteBufferImpl))
208 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
209 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
210 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
214 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
216 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
219 # if SIZEOF_VOID_P == 8
220 if (!(class_gnu_classpath_Pointer64 =
221 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
222 !link_class(class_gnu_classpath_Pointer64))
225 if (!(class_gnu_classpath_Pointer32 =
226 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
227 !link_class(class_gnu_classpath_Pointer32))
231 #endif /* defined(ENABLE_JAVASE) */
237 /* _Jv_jni_CallObjectMethod ****************************************************
239 Internal function to call Java Object methods.
241 *******************************************************************************/
243 static java_handle_t *_Jv_jni_CallObjectMethod(java_handle_t *o,
245 methodinfo *m, va_list ap)
250 STATISTICS(jniinvokation());
253 exceptions_throw_nullpointerexception();
257 /* Class initialization is done by the JIT compiler. This is ok
258 since a static method always belongs to the declaring class. */
260 if (m->flags & ACC_STATIC) {
261 /* For static methods we reset the object. */
266 /* for convenience */
271 /* For instance methods we make a virtual function table lookup. */
273 resm = method_vftbl_lookup(vftbl, m);
276 STATISTICS(jnicallXmethodnvokation());
278 ro = vm_call_method_valist(resm, o, ap);
284 /* _Jv_jni_CallObjectMethodA ***************************************************
286 Internal function to call Java Object methods.
288 *******************************************************************************/
290 static java_handle_t *_Jv_jni_CallObjectMethodA(java_handle_t *o,
298 STATISTICS(jniinvokation());
301 exceptions_throw_nullpointerexception();
305 /* Class initialization is done by the JIT compiler. This is ok
306 since a static method always belongs to the declaring class. */
308 if (m->flags & ACC_STATIC) {
309 /* For static methods we reset the object. */
314 /* for convenience */
319 /* For instance methods we make a virtual function table lookup. */
321 resm = method_vftbl_lookup(vftbl, m);
324 STATISTICS(jnicallXmethodnvokation());
326 ro = vm_call_method_jvalue(resm, o, args);
332 /* _Jv_jni_CallIntMethod *******************************************************
334 Internal function to call Java integer class methods (boolean,
335 byte, char, short, int).
337 *******************************************************************************/
339 static jint _Jv_jni_CallIntMethod(java_handle_t *o, vftbl_t *vftbl,
340 methodinfo *m, va_list ap)
345 STATISTICS(jniinvokation());
348 exceptions_throw_nullpointerexception();
352 /* Class initialization is done by the JIT compiler. This is ok
353 since a static method always belongs to the declaring class. */
355 if (m->flags & ACC_STATIC) {
356 /* For static methods we reset the object. */
361 /* for convenience */
366 /* For instance methods we make a virtual function table lookup. */
368 resm = method_vftbl_lookup(vftbl, m);
371 STATISTICS(jnicallXmethodnvokation());
373 i = vm_call_method_int_valist(resm, o, ap);
379 /* _Jv_jni_CallIntMethodA ******************************************************
381 Internal function to call Java integer class methods (boolean,
382 byte, char, short, int).
384 *******************************************************************************/
386 static jint _Jv_jni_CallIntMethodA(java_handle_t *o, vftbl_t *vftbl,
387 methodinfo *m, const jvalue *args)
392 STATISTICS(jniinvokation());
395 exceptions_throw_nullpointerexception();
399 /* Class initialization is done by the JIT compiler. This is ok
400 since a static method always belongs to the declaring class. */
402 if (m->flags & ACC_STATIC) {
403 /* For static methods we reset the object. */
408 /* for convenience */
413 /* For instance methods we make a virtual function table lookup. */
415 resm = method_vftbl_lookup(vftbl, m);
418 STATISTICS(jnicallXmethodnvokation());
420 i = vm_call_method_int_jvalue(resm, o, args);
426 /* _Jv_jni_CallLongMethod ******************************************************
428 Internal function to call Java long methods.
430 *******************************************************************************/
432 static jlong _Jv_jni_CallLongMethod(java_handle_t *o, vftbl_t *vftbl,
433 methodinfo *m, va_list ap)
438 STATISTICS(jniinvokation());
441 exceptions_throw_nullpointerexception();
445 /* Class initialization is done by the JIT compiler. This is ok
446 since a static method always belongs to the declaring class. */
448 if (m->flags & ACC_STATIC) {
449 /* For static methods we reset the object. */
454 /* for convenience */
459 /* For instance methods we make a virtual function table lookup. */
461 resm = method_vftbl_lookup(vftbl, m);
464 STATISTICS(jnicallXmethodnvokation());
466 l = vm_call_method_long_valist(resm, o, ap);
472 /* _Jv_jni_CallLongMethodA *****************************************************
474 Internal function to call Java long methods.
476 *******************************************************************************/
478 static jlong _Jv_jni_CallLongMethodA(java_handle_t *o, vftbl_t *vftbl,
479 methodinfo *m, const jvalue *args)
484 STATISTICS(jniinvokation());
487 exceptions_throw_nullpointerexception();
491 /* Class initialization is done by the JIT compiler. This is ok
492 since a static method always belongs to the declaring class. */
494 if (m->flags & ACC_STATIC) {
495 /* For static methods we reset the object. */
500 /* for convenience */
505 /* For instance methods we make a virtual function table lookup. */
507 resm = method_vftbl_lookup(vftbl, m);
510 STATISTICS(jnicallXmethodnvokation());
512 l = vm_call_method_long_jvalue(resm, o, args);
518 /* _Jv_jni_CallFloatMethod *****************************************************
520 Internal function to call Java float methods.
522 *******************************************************************************/
524 static jfloat _Jv_jni_CallFloatMethod(java_handle_t *o, vftbl_t *vftbl,
525 methodinfo *m, va_list ap)
530 /* Class initialization is done by the JIT compiler. This is ok
531 since a static method always belongs to the declaring class. */
533 if (m->flags & ACC_STATIC) {
534 /* For static methods we reset the object. */
539 /* for convenience */
544 /* For instance methods we make a virtual function table lookup. */
546 resm = method_vftbl_lookup(vftbl, m);
549 STATISTICS(jnicallXmethodnvokation());
551 f = vm_call_method_float_valist(resm, o, ap);
557 /* _Jv_jni_CallFloatMethodA ****************************************************
559 Internal function to call Java float methods.
561 *******************************************************************************/
563 static jfloat _Jv_jni_CallFloatMethodA(java_handle_t *o, vftbl_t *vftbl,
564 methodinfo *m, const jvalue *args)
569 /* Class initialization is done by the JIT compiler. This is ok
570 since a static method always belongs to the declaring class. */
572 if (m->flags & ACC_STATIC) {
573 /* For static methods we reset the object. */
578 /* for convenience */
583 /* For instance methods we make a virtual function table lookup. */
585 resm = method_vftbl_lookup(vftbl, m);
588 STATISTICS(jnicallXmethodnvokation());
590 f = vm_call_method_float_jvalue(resm, o, args);
596 /* _Jv_jni_CallDoubleMethod ****************************************************
598 Internal function to call Java double methods.
600 *******************************************************************************/
602 static jdouble _Jv_jni_CallDoubleMethod(java_handle_t *o, vftbl_t *vftbl,
603 methodinfo *m, va_list ap)
608 /* Class initialization is done by the JIT compiler. This is ok
609 since a static method always belongs to the declaring class. */
611 if (m->flags & ACC_STATIC) {
612 /* For static methods we reset the object. */
617 /* for convenience */
622 /* For instance methods we make a virtual function table lookup. */
624 resm = method_vftbl_lookup(vftbl, m);
627 d = vm_call_method_double_valist(resm, o, ap);
633 /* _Jv_jni_CallDoubleMethodA ***************************************************
635 Internal function to call Java double methods.
637 *******************************************************************************/
639 static jdouble _Jv_jni_CallDoubleMethodA(java_handle_t *o, vftbl_t *vftbl,
640 methodinfo *m, const jvalue *args)
645 /* Class initialization is done by the JIT compiler. This is ok
646 since a static method always belongs to the declaring class. */
648 if (m->flags & ACC_STATIC) {
649 /* For static methods we reset the object. */
654 /* for convenience */
659 /* For instance methods we make a virtual function table lookup. */
661 resm = method_vftbl_lookup(vftbl, m);
664 d = vm_call_method_double_jvalue(resm, o, args);
670 /* _Jv_jni_CallVoidMethod ******************************************************
672 Internal function to call Java void methods.
674 *******************************************************************************/
676 static void _Jv_jni_CallVoidMethod(java_handle_t *o, vftbl_t *vftbl,
677 methodinfo *m, va_list ap)
682 exceptions_throw_nullpointerexception();
686 /* Class initialization is done by the JIT compiler. This is ok
687 since a static method always belongs to the declaring class. */
689 if (m->flags & ACC_STATIC) {
690 /* For static methods we reset the object. */
695 /* for convenience */
700 /* For instance methods we make a virtual function table lookup. */
702 resm = method_vftbl_lookup(vftbl, m);
705 STATISTICS(jnicallXmethodnvokation());
707 (void) vm_call_method_valist(resm, o, ap);
711 /* _Jv_jni_CallVoidMethodA *****************************************************
713 Internal function to call Java void methods.
715 *******************************************************************************/
717 static void _Jv_jni_CallVoidMethodA(java_handle_t *o, vftbl_t *vftbl,
718 methodinfo *m, const jvalue *args)
723 exceptions_throw_nullpointerexception();
727 /* Class initialization is done by the JIT compiler. This is ok
728 since a static method always belongs to the declaring class. */
730 if (m->flags & ACC_STATIC) {
731 /* For static methods we reset the object. */
736 /* for convenience */
741 /* For instance methods we make a virtual function table lookup. */
743 resm = method_vftbl_lookup(vftbl, m);
746 STATISTICS(jnicallXmethodnvokation());
748 (void) vm_call_method_jvalue(resm, o, args);
752 /* _Jv_jni_invokeNative ********************************************************
754 Invoke a method on the given object with the given arguments.
756 For instance methods OBJ must be != NULL and the method is looked up
757 in the vftbl of the object.
759 For static methods, OBJ is ignored.
761 *******************************************************************************/
763 java_handle_t *_Jv_jni_invokeNative(methodinfo *m, java_handle_t *o,
764 java_handle_objectarray_t *params)
776 exceptions_throw_nullpointerexception();
780 argcount = m->parseddesc->paramcount;
781 paramcount = argcount;
783 /* if method is non-static, remove the `this' pointer */
785 if (!(m->flags & ACC_STATIC))
788 /* For instance methods the object has to be an instance of the
789 class the method belongs to. For static methods the obj
790 parameter is ignored. */
792 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
793 exceptions_throw_illegalargumentexception();
797 /* check if we got the right number of arguments */
799 if (((params == NULL) && (paramcount != 0)) ||
800 (params && (LLNI_array_size(params) != paramcount)))
802 exceptions_throw_illegalargumentexception();
806 /* for instance methods we need an object */
808 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
809 /* XXX not sure if that is the correct exception */
810 exceptions_throw_nullpointerexception();
814 /* for static methods, zero object to make subsequent code simpler */
815 if (m->flags & ACC_STATIC)
819 /* for instance methods we must do a vftbl lookup */
820 resm = method_vftbl_lookup(o->vftbl, m);
823 /* for static methods, just for convenience */
827 /* mark start of dump memory area */
829 dumpsize = dump_size();
831 /* Fill the argument array from a object-array. */
833 array = vm_array_from_objectarray(resm, o, params);
835 /* The array can be NULL if we don't have any arguments to pass
836 and the architecture does not have any argument registers
837 (e.g. i386). In that case we additionally check for an
840 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
841 /* release dump area */
843 dump_release(dumpsize);
848 switch (resm->parseddesc->returntype.decltype) {
850 (void) vm_call_array(resm, array);
854 case PRIMITIVETYPE_BOOLEAN:
855 case PRIMITIVETYPE_BYTE:
856 case PRIMITIVETYPE_CHAR:
857 case PRIMITIVETYPE_SHORT:
858 case PRIMITIVETYPE_INT:
859 value.i = vm_call_int_array(resm, array);
860 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
863 case PRIMITIVETYPE_LONG:
864 value.l = vm_call_long_array(resm, array);
865 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
868 case PRIMITIVETYPE_FLOAT:
869 value.f = vm_call_float_array(resm, array);
870 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
873 case PRIMITIVETYPE_DOUBLE:
874 value.d = vm_call_double_array(resm, array);
875 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
879 ro = vm_call_array(resm, array);
883 vm_abort("_Jv_jni_invokeNative: invalid return type %d", resm->parseddesc->returntype.decltype);
886 xptr = exceptions_get_exception();
889 /* clear exception pointer, we are calling JIT code again */
891 exceptions_clear_exception();
893 exceptions_throw_invocationtargetexception(xptr);
896 /* release dump area */
898 dump_release(dumpsize);
904 /* GetVersion ******************************************************************
906 Returns the major version number in the higher 16 bits and the
907 minor version number in the lower 16 bits.
909 *******************************************************************************/
911 jint _Jv_JNI_GetVersion(JNIEnv *env)
913 STATISTICS(jniinvokation());
915 /* we support JNI 1.4 */
917 return JNI_VERSION_1_4;
921 /* Class Operations ***********************************************************/
923 /* DefineClass *****************************************************************
925 Loads a class from a buffer of raw class data. The buffer
926 containing the raw class data is not referenced by the VM after the
927 DefineClass call returns, and it may be discarded if desired.
929 *******************************************************************************/
931 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
932 const jbyte *buf, jsize bufLen)
934 #if defined(ENABLE_JAVASE)
939 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d)", env, name, loader, buf, bufLen);
941 u = utf_new_char(name);
942 cl = (classloader *) loader;
944 c = class_define(u, cl, bufLen, (const uint8_t *) buf, NULL);
946 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
948 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
950 /* keep compiler happy */
957 /* FindClass *******************************************************************
959 This function loads a locally-defined class. It searches the
960 directories and zip files specified by the CLASSPATH environment
961 variable for the class with the specified name.
963 *******************************************************************************/
965 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
967 #if defined(ENABLE_JAVASE)
972 STATISTICS(jniinvokation());
974 u = utf_new_char_classname((char *) name);
976 /* Check stacktrace for classloader, if one found use it,
977 otherwise use the system classloader. */
979 /* Quote from the JNI documentation:
981 In the Java 2 Platform, FindClass locates the class loader
982 associated with the current native method. If the native code
983 belongs to a system class, no class loader will be
984 involved. Otherwise, the proper class loader will be invoked to
985 load and link the named class. When FindClass is called through
986 the Invocation Interface, there is no current native method or
987 its associated class loader. In that case, the result of
988 ClassLoader.getBaseClassLoader is used." */
990 cc = stacktrace_getCurrentClass();
993 c = load_class_from_sysloader(u);
995 c = load_class_from_classloader(u, cc->classloader);
1003 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1005 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1007 /* keep compiler happy */
1014 /* GetSuperclass ***************************************************************
1016 If clazz represents any class other than the class Object, then
1017 this function returns the object that represents the superclass of
1018 the class specified by clazz.
1020 *******************************************************************************/
1022 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1027 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1029 c = LLNI_classinfo_unwrap(sub);
1034 super = class_get_superclass(c);
1036 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1040 /* IsAssignableFrom ************************************************************
1042 Determines whether an object of sub can be safely cast to sup.
1044 *******************************************************************************/
1046 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1048 java_lang_Class *csup;
1049 java_lang_Class *csub;
1051 csup = (java_lang_Class *) sup;
1052 csub = (java_lang_Class *) sub;
1054 STATISTICS(jniinvokation());
1056 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1060 /* Throw ***********************************************************************
1062 Causes a java.lang.Throwable object to be thrown.
1064 *******************************************************************************/
1066 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1070 STATISTICS(jniinvokation());
1072 o = (java_handle_t *) obj;
1074 exceptions_set_exception(o);
1080 /* ThrowNew ********************************************************************
1082 Constructs an exception object from the specified class with the
1083 message specified by message and causes that exception to be
1086 *******************************************************************************/
1088 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1094 STATISTICS(jniinvokation());
1096 c = LLNI_classinfo_unwrap(clazz);
1099 s = javastring_new_from_utf_string(msg);
1101 /* instantiate exception object */
1103 o = native_new_and_init_string(c, s);
1108 exceptions_set_exception(o);
1114 /* ExceptionOccurred ***********************************************************
1116 Determines if an exception is being thrown. The exception stays
1117 being thrown until either the native code calls ExceptionClear(),
1118 or the Java code handles the exception.
1120 *******************************************************************************/
1122 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1126 STATISTICS(jniinvokation());
1128 o = exceptions_get_exception();
1130 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1134 /* ExceptionDescribe ***********************************************************
1136 Prints an exception and a backtrace of the stack to a system
1137 error-reporting channel, such as stderr. This is a convenience
1138 routine provided for debugging.
1140 *******************************************************************************/
1142 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1147 STATISTICS(jniinvokation());
1149 o = exceptions_get_exception();
1152 /* clear exception, because we are calling jit code again */
1154 exceptions_clear_exception();
1156 /* get printStackTrace method from exception class */
1158 m = class_resolveclassmethod(o->vftbl->class,
1159 utf_printStackTrace,
1165 /* XXX what should we do? */
1168 /* print the stacktrace */
1170 (void) vm_call_method(m, o);
1175 /* ExceptionClear **************************************************************
1177 Clears any exception that is currently being thrown. If no
1178 exception is currently being thrown, this routine has no effect.
1180 *******************************************************************************/
1182 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1184 STATISTICS(jniinvokation());
1186 exceptions_clear_exception();
1190 /* FatalError ******************************************************************
1192 Raises a fatal error and does not expect the VM to recover. This
1193 function does not return.
1195 *******************************************************************************/
1197 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1199 STATISTICS(jniinvokation());
1201 /* this seems to be the best way */
1203 vm_abort("JNI Fatal error: %s", msg);
1207 /* PushLocalFrame **************************************************************
1209 Creates a new local reference frame, in which at least a given
1210 number of local references can be created.
1212 *******************************************************************************/
1214 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1216 STATISTICS(jniinvokation());
1221 /* add new local reference frame to current table */
1223 if (!localref_frame_push(capacity))
1230 /* PopLocalFrame ***************************************************************
1232 Pops off the current local reference frame, frees all the local
1233 references, and returns a local reference in the previous local
1234 reference frame for the given result object.
1236 *******************************************************************************/
1238 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1240 STATISTICS(jniinvokation());
1242 /* release all current local frames */
1244 localref_frame_pop_all();
1246 /* add local reference and return the value */
1248 return _Jv_JNI_NewLocalRef(env, result);
1252 /* DeleteLocalRef **************************************************************
1254 Deletes the local reference pointed to by localRef.
1256 *******************************************************************************/
1258 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1261 localref_table *lrt;
1264 STATISTICS(jniinvokation());
1266 o = (java_handle_t *) localRef;
1268 /* get local reference table (thread specific) */
1270 lrt = LOCALREFTABLE;
1272 /* go through all local frames */
1274 for (; lrt != NULL; lrt = lrt->prev) {
1276 /* and try to remove the reference */
1278 for (i = 0; i < lrt->capacity; i++) {
1279 if (lrt->refs[i] == o) {
1280 lrt->refs[i] = NULL;
1288 /* this should not happen */
1290 /* if (opt_checkjni) */
1291 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1292 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1296 /* IsSameObject ****************************************************************
1298 Tests whether two references refer to the same Java object.
1300 *******************************************************************************/
1302 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1304 STATISTICS(jniinvokation());
1313 /* NewLocalRef *****************************************************************
1315 Creates a new local reference that refers to the same object as ref.
1317 *******************************************************************************/
1319 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1321 localref_table *lrt;
1324 STATISTICS(jniinvokation());
1329 /* get local reference table (thread specific) */
1331 lrt = LOCALREFTABLE;
1333 /* Check if we have space for the requested reference? No,
1334 allocate a new frame. This is actually not what the spec says,
1335 but for compatibility reasons... */
1337 if (lrt->used == lrt->capacity) {
1338 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1341 /* get the new local reference table */
1343 lrt = LOCALREFTABLE;
1346 /* insert the reference */
1348 for (i = 0; i < lrt->capacity; i++) {
1349 if (lrt->refs[i] == NULL) {
1350 lrt->refs[i] = (java_handle_t *) ref;
1357 /* should not happen, just to be sure */
1361 /* keep compiler happy */
1367 /* EnsureLocalCapacity *********************************************************
1369 Ensures that at least a given number of local references can be
1370 created in the current thread
1372 *******************************************************************************/
1374 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1376 localref_table *lrt;
1378 STATISTICS(jniinvokation());
1380 /* get local reference table (thread specific) */
1382 lrt = LOCALREFTABLE;
1384 /* check if capacity elements are available in the local references table */
1386 if ((lrt->used + capacity) > lrt->capacity)
1387 return _Jv_JNI_PushLocalFrame(env, capacity);
1393 /* AllocObject *****************************************************************
1395 Allocates a new Java object without invoking any of the
1396 constructors for the object. Returns a reference to the object.
1398 *******************************************************************************/
1400 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1405 STATISTICS(jniinvokation());
1407 c = LLNI_classinfo_unwrap(clazz);
1409 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1410 exceptions_throw_instantiationexception(c);
1416 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1420 /* NewObject *******************************************************************
1422 Programmers place all arguments that are to be passed to the
1423 constructor immediately following the methodID
1424 argument. NewObject() accepts these arguments and passes them to
1425 the Java method that the programmer wishes to invoke.
1427 *******************************************************************************/
1429 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1436 STATISTICS(jniinvokation());
1438 c = LLNI_classinfo_unwrap(clazz);
1439 m = (methodinfo *) methodID;
1448 /* call constructor */
1450 va_start(ap, methodID);
1451 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1454 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1458 /* NewObjectV ******************************************************************
1460 Programmers place all arguments that are to be passed to the
1461 constructor in an args argument of type va_list that immediately
1462 follows the methodID argument. NewObjectV() accepts these
1463 arguments, and, in turn, passes them to the Java method that the
1464 programmer wishes to invoke.
1466 *******************************************************************************/
1468 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1475 STATISTICS(jniinvokation());
1477 c = LLNI_classinfo_unwrap(clazz);
1478 m = (methodinfo *) methodID;
1487 /* call constructor */
1489 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1491 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1495 /* NewObjectA *****************************************************************
1497 Programmers place all arguments that are to be passed to the
1498 constructor in an args array of jvalues that immediately follows
1499 the methodID argument. NewObjectA() accepts the arguments in this
1500 array, and, in turn, passes them to the Java method that the
1501 programmer wishes to invoke.
1503 *******************************************************************************/
1505 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1512 STATISTICS(jniinvokation());
1514 c = LLNI_classinfo_unwrap(clazz);
1515 m = (methodinfo *) methodID;
1524 /* call constructor */
1526 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1528 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1532 /* GetObjectClass **************************************************************
1534 Returns the class of an object.
1536 *******************************************************************************/
1538 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1543 STATISTICS(jniinvokation());
1545 o = (java_handle_t *) obj;
1547 if ((o == NULL) || (o->vftbl == NULL))
1550 c = o->vftbl->class;
1552 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1556 /* IsInstanceOf ****************************************************************
1558 Tests whether an object is an instance of a class.
1560 *******************************************************************************/
1562 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1565 java_lang_Object *o;
1567 STATISTICS(jniinvokation());
1569 c = (java_lang_Class *) clazz;
1570 o = (java_lang_Object *) obj;
1572 return _Jv_java_lang_Class_isInstance(c, o);
1576 /* Reflection Support *********************************************************/
1578 /* FromReflectedMethod *********************************************************
1580 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1581 object to a method ID.
1583 *******************************************************************************/
1585 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1587 #if defined(ENABLE_JAVASE)
1593 STATISTICS(jniinvokation());
1595 o = (java_handle_t *) method;
1600 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
1601 java_lang_reflect_Method *rm;
1603 rm = (java_lang_reflect_Method *) method;
1604 LLNI_field_get_cls(rm, clazz, c);
1605 LLNI_field_get_val(rm, slot , slot);
1607 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
1608 java_lang_reflect_Constructor *rc;
1610 rc = (java_lang_reflect_Constructor *) method;
1611 LLNI_field_get_cls(rc, clazz, c);
1612 LLNI_field_get_val(rc, slot , slot);
1617 m = &(c->methods[slot]);
1619 return (jmethodID) m;
1621 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1623 /* keep compiler happy */
1630 /* FromReflectedField **********************************************************
1632 Converts a java.lang.reflect.Field to a field ID.
1634 *******************************************************************************/
1636 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1638 #if defined(ENABLE_JAVASE)
1639 java_lang_reflect_Field *rf;
1644 STATISTICS(jniinvokation());
1646 rf = (java_lang_reflect_Field *) field;
1651 LLNI_field_get_cls(rf, clazz, c);
1652 LLNI_field_get_val(rf, slot , slot);
1653 f = &(c->fields[slot]);
1655 return (jfieldID) f;
1657 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1659 /* keep compiler happy */
1666 /* ToReflectedMethod ***********************************************************
1668 Converts a method ID derived from cls to an instance of the
1669 java.lang.reflect.Method class or to an instance of the
1670 java.lang.reflect.Constructor class.
1672 *******************************************************************************/
1674 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1677 #if defined(ENABLE_JAVASE)
1679 java_lang_reflect_Constructor *rc;
1680 java_lang_reflect_Method *rm;
1682 STATISTICS(jniinvokation());
1684 m = (methodinfo *) methodID;
1686 /* HotSpot does the same assert. */
1688 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
1690 if (m->name == utf_init) {
1691 rc = reflect_constructor_new(m);
1693 return (jobject) rc;
1696 rm = reflect_method_new(m);
1698 return (jobject) rm;
1701 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
1703 /* keep compiler happy */
1710 /* ToReflectedField ************************************************************
1712 Converts a field ID derived from cls to an instance of the
1713 java.lang.reflect.Field class.
1715 *******************************************************************************/
1717 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1720 STATISTICS(jniinvokation());
1722 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1728 /* Calling Instance Methods ***************************************************/
1730 /* GetMethodID *****************************************************************
1732 Returns the method ID for an instance (nonstatic) method of a class
1733 or interface. The method may be defined in one of the clazz's
1734 superclasses and inherited by clazz. The method is determined by
1735 its name and signature.
1737 GetMethodID() causes an uninitialized class to be initialized.
1739 *******************************************************************************/
1741 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1749 STATISTICS(jniinvokation());
1751 c = LLNI_classinfo_unwrap(clazz);
1756 if (!(c->state & CLASS_INITIALIZED))
1757 if (!initialize_class(c))
1760 /* try to get the method of the class or one of it's superclasses */
1762 uname = utf_new_char((char *) name);
1763 udesc = utf_new_char((char *) sig);
1765 m = class_resolvemethod(c, uname, udesc);
1767 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1768 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1773 return (jmethodID) m;
1777 /* JNI-functions for calling instance methods *********************************/
1779 #define JNI_CALL_VIRTUAL_METHOD(name, type, intern) \
1780 type _Jv_JNI_Call##name##Method(JNIEnv *env, jobject obj, \
1781 jmethodID methodID, ...) \
1788 o = (java_handle_t *) obj; \
1789 m = (methodinfo *) methodID; \
1791 va_start(ap, methodID); \
1792 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, ap); \
1798 JNI_CALL_VIRTUAL_METHOD(Boolean, jboolean, Int)
1799 JNI_CALL_VIRTUAL_METHOD(Byte, jbyte, Int)
1800 JNI_CALL_VIRTUAL_METHOD(Char, jchar, Int)
1801 JNI_CALL_VIRTUAL_METHOD(Short, jshort, Int)
1802 JNI_CALL_VIRTUAL_METHOD(Int, jint, Int)
1803 JNI_CALL_VIRTUAL_METHOD(Long, jlong, Long)
1804 JNI_CALL_VIRTUAL_METHOD(Float, jfloat, Float)
1805 JNI_CALL_VIRTUAL_METHOD(Double, jdouble, Double)
1808 #define JNI_CALL_VIRTUAL_METHOD_V(name, type, intern) \
1809 type _Jv_JNI_Call##name##MethodV(JNIEnv *env, jobject obj, \
1810 jmethodID methodID, va_list args) \
1816 o = (java_handle_t *) obj; \
1817 m = (methodinfo *) methodID; \
1819 ret = _Jv_jni_Call##intern##Method(o, o->vftbl, m, args); \
1824 JNI_CALL_VIRTUAL_METHOD_V(Boolean, jboolean, Int)
1825 JNI_CALL_VIRTUAL_METHOD_V(Byte, jbyte, Int)
1826 JNI_CALL_VIRTUAL_METHOD_V(Char, jchar, Int)
1827 JNI_CALL_VIRTUAL_METHOD_V(Short, jshort, Int)
1828 JNI_CALL_VIRTUAL_METHOD_V(Int, jint, Int)
1829 JNI_CALL_VIRTUAL_METHOD_V(Long, jlong, Long)
1830 JNI_CALL_VIRTUAL_METHOD_V(Float, jfloat, Float)
1831 JNI_CALL_VIRTUAL_METHOD_V(Double, jdouble, Double)
1834 #define JNI_CALL_VIRTUAL_METHOD_A(name, type, intern) \
1835 type _Jv_JNI_Call##name##MethodA(JNIEnv *env, jobject obj, \
1836 jmethodID methodID, \
1837 const jvalue *args) \
1843 o = (java_handle_t *) obj; \
1844 m = (methodinfo *) methodID; \
1846 ret = _Jv_jni_Call##intern##MethodA(o, o->vftbl, m, args); \
1851 JNI_CALL_VIRTUAL_METHOD_A(Boolean, jboolean, Int)
1852 JNI_CALL_VIRTUAL_METHOD_A(Byte, jbyte, Int)
1853 JNI_CALL_VIRTUAL_METHOD_A(Char, jchar, Int)
1854 JNI_CALL_VIRTUAL_METHOD_A(Short, jshort, Int)
1855 JNI_CALL_VIRTUAL_METHOD_A(Int, jint, Int)
1856 JNI_CALL_VIRTUAL_METHOD_A(Long, jlong, Long)
1857 JNI_CALL_VIRTUAL_METHOD_A(Float, jfloat, Float)
1858 JNI_CALL_VIRTUAL_METHOD_A(Double, jdouble, Double)
1861 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1869 o = (java_handle_t *) obj;
1870 m = (methodinfo *) methodID;
1872 va_start(ap, methodID);
1873 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1876 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1880 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1887 o = (java_handle_t *) obj;
1888 m = (methodinfo *) methodID;
1890 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1892 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1896 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1903 o = (java_handle_t *) obj;
1904 m = (methodinfo *) methodID;
1906 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1908 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1913 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1919 o = (java_handle_t *) obj;
1920 m = (methodinfo *) methodID;
1922 va_start(ap, methodID);
1923 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1928 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1934 o = (java_handle_t *) obj;
1935 m = (methodinfo *) methodID;
1937 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1941 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1947 o = (java_handle_t *) obj;
1948 m = (methodinfo *) methodID;
1950 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1955 #define JNI_CALL_NONVIRTUAL_METHOD(name, type, intern) \
1956 type _Jv_JNI_CallNonvirtual##name##Method(JNIEnv *env, jobject obj, \
1957 jclass clazz, jmethodID methodID, \
1966 o = (java_handle_t *) obj; \
1967 c = LLNI_classinfo_unwrap(clazz); \
1968 m = (methodinfo *) methodID; \
1970 va_start(ap, methodID); \
1971 ret = _Jv_jni_Call##intern##Method(o, c->vftbl, m, ap); \
1977 JNI_CALL_NONVIRTUAL_METHOD(Boolean, jboolean, Int)
1978 JNI_CALL_NONVIRTUAL_METHOD(Byte, jbyte, Int)
1979 JNI_CALL_NONVIRTUAL_METHOD(Char, jchar, Int)
1980 JNI_CALL_NONVIRTUAL_METHOD(Short, jshort, Int)
1981 JNI_CALL_NONVIRTUAL_METHOD(Int, jint, Int)
1982 JNI_CALL_NONVIRTUAL_METHOD(Long, jlong, Long)
1983 JNI_CALL_NONVIRTUAL_METHOD(Float, jfloat, Float)
1984 JNI_CALL_NONVIRTUAL_METHOD(Double, jdouble, Double)
1987 #define JNI_CALL_NONVIRTUAL_METHOD_V(name, type, intern) \
1988 type _Jv_JNI_CallNonvirtual##name##MethodV(JNIEnv *env, jobject obj, \
1989 jclass clazz, jmethodID methodID, \
1997 o = (java_handle_t *) obj; \
1998 c = LLNI_classinfo_unwrap(clazz); \
1999 m = (methodinfo *) methodID; \
2001 ret = _Jv_jni_CallIntMethod(o, c->vftbl, m, args); \
2006 JNI_CALL_NONVIRTUAL_METHOD_V(Boolean, jboolean, Int)
2007 JNI_CALL_NONVIRTUAL_METHOD_V(Byte, jbyte, Int)
2008 JNI_CALL_NONVIRTUAL_METHOD_V(Char, jchar, Int)
2009 JNI_CALL_NONVIRTUAL_METHOD_V(Short, jshort, Int)
2010 JNI_CALL_NONVIRTUAL_METHOD_V(Int, jint, Int)
2011 JNI_CALL_NONVIRTUAL_METHOD_V(Long, jlong, Long)
2012 JNI_CALL_NONVIRTUAL_METHOD_V(Float, jfloat, Float)
2013 JNI_CALL_NONVIRTUAL_METHOD_V(Double, jdouble, Double)
2016 #define JNI_CALL_NONVIRTUAL_METHOD_A(name, type, intern) \
2017 type _Jv_JNI_CallNonvirtual##name##MethodA(JNIEnv *env, jobject obj, \
2018 jclass clazz, jmethodID methodID, \
2019 const jvalue *args) \
2021 log_text("JNI-Call: CallNonvirtual##name##MethodA: IMPLEMENT ME!"); \
2026 JNI_CALL_NONVIRTUAL_METHOD_A(Boolean, jboolean, Int)
2027 JNI_CALL_NONVIRTUAL_METHOD_A(Byte, jbyte, Int)
2028 JNI_CALL_NONVIRTUAL_METHOD_A(Char, jchar, Int)
2029 JNI_CALL_NONVIRTUAL_METHOD_A(Short, jshort, Int)
2030 JNI_CALL_NONVIRTUAL_METHOD_A(Int, jint, Int)
2031 JNI_CALL_NONVIRTUAL_METHOD_A(Long, jlong, Long)
2032 JNI_CALL_NONVIRTUAL_METHOD_A(Float, jfloat, Float)
2033 JNI_CALL_NONVIRTUAL_METHOD_A(Double, jdouble, Double)
2035 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2036 jclass clazz, jmethodID methodID,
2045 o = (java_handle_t *) obj;
2046 c = LLNI_classinfo_unwrap(clazz);
2047 m = (methodinfo *) methodID;
2049 va_start(ap, methodID);
2050 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2053 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2057 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2058 jclass clazz, jmethodID methodID,
2066 o = (java_handle_t *) obj;
2067 c = LLNI_classinfo_unwrap(clazz);
2068 m = (methodinfo *) methodID;
2070 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2072 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2076 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2077 jclass clazz, jmethodID methodID,
2080 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2082 return _Jv_JNI_NewLocalRef(env, NULL);
2086 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2087 jmethodID methodID, ...)
2094 o = (java_handle_t *) obj;
2095 c = LLNI_classinfo_unwrap(clazz);
2096 m = (methodinfo *) methodID;
2098 va_start(ap, methodID);
2099 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2104 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2105 jmethodID methodID, va_list args)
2111 o = (java_handle_t *) obj;
2112 c = LLNI_classinfo_unwrap(clazz);
2113 m = (methodinfo *) methodID;
2115 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2119 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2120 jmethodID methodID, const jvalue * args)
2126 o = (java_handle_t *) obj;
2127 c = LLNI_classinfo_unwrap(clazz);
2128 m = (methodinfo *) methodID;
2130 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2134 /* Accessing Fields of Objects ************************************************/
2136 /* GetFieldID ******************************************************************
2138 Returns the field ID for an instance (nonstatic) field of a
2139 class. The field is specified by its name and signature. The
2140 Get<type>Field and Set<type>Field families of accessor functions
2141 use field IDs to retrieve object fields.
2143 *******************************************************************************/
2145 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2153 STATISTICS(jniinvokation());
2155 c = LLNI_classinfo_unwrap(clazz);
2157 /* XXX NPE check? */
2159 uname = utf_new_char((char *) name);
2160 udesc = utf_new_char((char *) sig);
2162 f = class_findfield(c, uname, udesc);
2165 exceptions_throw_nosuchfielderror(c, uname);
2167 return (jfieldID) f;
2171 /* Get<type>Field Routines *****************************************************
2173 This family of accessor routines returns the value of an instance
2174 (nonstatic) field of an object. The field to access is specified by
2175 a field ID obtained by calling GetFieldID().
2177 *******************************************************************************/
2179 #define JNI_GET_FIELD(name, type, intern) \
2180 type _Jv_JNI_Get##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID) \
2184 STATISTICS(jniinvokation()); \
2186 ret = GET_FIELD(obj, intern, fieldID); \
2188 return (type) ret; \
2191 JNI_GET_FIELD(Boolean, jboolean, s4)
2192 JNI_GET_FIELD(Byte, jbyte, s4)
2193 JNI_GET_FIELD(Char, jchar, s4)
2194 JNI_GET_FIELD(Short, jshort, s4)
2195 JNI_GET_FIELD(Int, jint, s4)
2196 JNI_GET_FIELD(Long, jlong, s8)
2197 JNI_GET_FIELD(Float, jfloat, float)
2198 JNI_GET_FIELD(Double, jdouble, double)
2201 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2205 STATISTICS(jniinvokation());
2207 #warning this needs to be fixed
2208 o = GET_FIELD(obj, java_handle_t*, fieldID);
2210 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2214 /* Set<type>Field Routines *****************************************************
2216 This family of accessor routines sets the value of an instance
2217 (nonstatic) field of an object. The field to access is specified by
2218 a field ID obtained by calling GetFieldID().
2220 *******************************************************************************/
2222 #define JNI_SET_FIELD(name, type, intern) \
2223 void _Jv_JNI_Set##name##Field(JNIEnv *env, jobject obj, jfieldID fieldID, \
2226 STATISTICS(jniinvokation()); \
2228 SET_FIELD(obj, intern, fieldID, value); \
2231 JNI_SET_FIELD(Boolean, jboolean, s4)
2232 JNI_SET_FIELD(Byte, jbyte, s4)
2233 JNI_SET_FIELD(Char, jchar, s4)
2234 JNI_SET_FIELD(Short, jshort, s4)
2235 JNI_SET_FIELD(Int, jint, s4)
2236 JNI_SET_FIELD(Long, jlong, s8)
2237 JNI_SET_FIELD(Float, jfloat, float)
2238 JNI_SET_FIELD(Double, jdouble, double)
2241 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
2244 STATISTICS(jniinvokation());
2246 #warning this needs to be fixed
2247 SET_FIELD(obj, java_handle_t*, fieldID, value);
2251 /* Calling Static Methods *****************************************************/
2253 /* GetStaticMethodID ***********************************************************
2255 Returns the method ID for a static method of a class. The method is
2256 specified by its name and signature.
2258 GetStaticMethodID() causes an uninitialized class to be
2261 *******************************************************************************/
2263 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
2271 STATISTICS(jniinvokation());
2273 c = LLNI_classinfo_unwrap(clazz);
2278 if (!(c->state & CLASS_INITIALIZED))
2279 if (!initialize_class(c))
2282 /* try to get the static method of the class */
2284 uname = utf_new_char((char *) name);
2285 udesc = utf_new_char((char *) sig);
2287 m = class_resolvemethod(c, uname, udesc);
2289 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
2290 exceptions_throw_nosuchmethoderror(c, uname, udesc);
2295 return (jmethodID) m;
2299 #define JNI_CALL_STATIC_METHOD(name, type, intern) \
2300 type _Jv_JNI_CallStatic##name##Method(JNIEnv *env, jclass clazz, \
2301 jmethodID methodID, ...) \
2307 m = (methodinfo *) methodID; \
2309 va_start(ap, methodID); \
2310 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, ap); \
2316 JNI_CALL_STATIC_METHOD(Boolean, jboolean, Int)
2317 JNI_CALL_STATIC_METHOD(Byte, jbyte, Int)
2318 JNI_CALL_STATIC_METHOD(Char, jchar, Int)
2319 JNI_CALL_STATIC_METHOD(Short, jshort, Int)
2320 JNI_CALL_STATIC_METHOD(Int, jint, Int)
2321 JNI_CALL_STATIC_METHOD(Long, jlong, Long)
2322 JNI_CALL_STATIC_METHOD(Float, jfloat, Float)
2323 JNI_CALL_STATIC_METHOD(Double, jdouble, Double)
2326 #define JNI_CALL_STATIC_METHOD_V(name, type, intern) \
2327 type _Jv_JNI_CallStatic##name##MethodV(JNIEnv *env, jclass clazz, \
2328 jmethodID methodID, va_list args) \
2333 m = (methodinfo *) methodID; \
2335 res = _Jv_jni_Call##intern##Method(NULL, NULL, m, args); \
2340 JNI_CALL_STATIC_METHOD_V(Boolean, jboolean, Int)
2341 JNI_CALL_STATIC_METHOD_V(Byte, jbyte, Int)
2342 JNI_CALL_STATIC_METHOD_V(Char, jchar, Int)
2343 JNI_CALL_STATIC_METHOD_V(Short, jshort, Int)
2344 JNI_CALL_STATIC_METHOD_V(Int, jint, Int)
2345 JNI_CALL_STATIC_METHOD_V(Long, jlong, Long)
2346 JNI_CALL_STATIC_METHOD_V(Float, jfloat, Float)
2347 JNI_CALL_STATIC_METHOD_V(Double, jdouble, Double)
2350 #define JNI_CALL_STATIC_METHOD_A(name, type, intern) \
2351 type _Jv_JNI_CallStatic##name##MethodA(JNIEnv *env, jclass clazz, \
2352 jmethodID methodID, const jvalue *args) \
2357 m = (methodinfo *) methodID; \
2359 res = _Jv_jni_Call##intern##MethodA(NULL, NULL, m, args); \
2364 JNI_CALL_STATIC_METHOD_A(Boolean, jboolean, Int)
2365 JNI_CALL_STATIC_METHOD_A(Byte, jbyte, Int)
2366 JNI_CALL_STATIC_METHOD_A(Char, jchar, Int)
2367 JNI_CALL_STATIC_METHOD_A(Short, jshort, Int)
2368 JNI_CALL_STATIC_METHOD_A(Int, jint, Int)
2369 JNI_CALL_STATIC_METHOD_A(Long, jlong, Long)
2370 JNI_CALL_STATIC_METHOD_A(Float, jfloat, Float)
2371 JNI_CALL_STATIC_METHOD_A(Double, jdouble, Double)
2374 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
2375 jmethodID methodID, ...)
2381 m = (methodinfo *) methodID;
2383 va_start(ap, methodID);
2384 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
2387 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2391 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
2392 jmethodID methodID, va_list args)
2397 m = (methodinfo *) methodID;
2399 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
2401 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2405 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
2406 jmethodID methodID, const jvalue *args)
2411 m = (methodinfo *) methodID;
2413 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
2415 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2419 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
2420 jmethodID methodID, ...)
2425 m = (methodinfo *) methodID;
2427 va_start(ap, methodID);
2428 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
2433 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
2434 jmethodID methodID, va_list args)
2438 m = (methodinfo *) methodID;
2440 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
2444 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
2445 jmethodID methodID, const jvalue * args)
2449 m = (methodinfo *) methodID;
2451 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
2455 /* Accessing Static Fields ****************************************************/
2457 /* GetStaticFieldID ************************************************************
2459 Returns the field ID for a static field of a class. The field is
2460 specified by its name and signature. The GetStatic<type>Field and
2461 SetStatic<type>Field families of accessor functions use field IDs
2462 to retrieve static fields.
2464 *******************************************************************************/
2466 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
2474 STATISTICS(jniinvokation());
2476 c = LLNI_classinfo_unwrap(clazz);
2478 uname = utf_new_char((char *) name);
2479 usig = utf_new_char((char *) sig);
2481 f = class_findfield(c, uname, usig);
2484 exceptions_throw_nosuchfielderror(c, uname);
2486 return (jfieldID) f;
2490 /* GetStatic<type>Field ********************************************************
2492 This family of accessor routines returns the value of a static
2495 *******************************************************************************/
2497 #define JNI_GET_STATIC_FIELD(name, type, field) \
2498 type _Jv_JNI_GetStatic##name##Field(JNIEnv *env, jclass clazz, \
2504 STATISTICS(jniinvokation()); \
2506 c = LLNI_classinfo_unwrap(clazz); \
2507 f = (fieldinfo *) fieldID; \
2509 if (!(c->state & CLASS_INITIALIZED)) \
2510 if (!initialize_class(c)) \
2513 return f->value->field; \
2516 JNI_GET_STATIC_FIELD(Boolean, jboolean, i)
2517 JNI_GET_STATIC_FIELD(Byte, jbyte, i)
2518 JNI_GET_STATIC_FIELD(Char, jchar, i)
2519 JNI_GET_STATIC_FIELD(Short, jshort, i)
2520 JNI_GET_STATIC_FIELD(Int, jint, i)
2521 JNI_GET_STATIC_FIELD(Long, jlong, l)
2522 JNI_GET_STATIC_FIELD(Float, jfloat, f)
2523 JNI_GET_STATIC_FIELD(Double, jdouble, d)
2526 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
2532 STATISTICS(jniinvokation());
2534 c = LLNI_classinfo_unwrap(clazz);
2535 f = (fieldinfo *) fieldID;
2537 if (!(c->state & CLASS_INITIALIZED))
2538 if (!initialize_class(c))
2541 return _Jv_JNI_NewLocalRef(env, f->value->a);
2545 /* SetStatic<type>Field *******************************************************
2547 This family of accessor routines sets the value of a static field
2550 *******************************************************************************/
2552 #define JNI_SET_STATIC_FIELD(name, type, field) \
2553 void _Jv_JNI_SetStatic##name##Field(JNIEnv *env, jclass clazz, \
2560 STATISTICS(jniinvokation()); \
2562 c = LLNI_classinfo_unwrap(clazz); \
2563 f = (fieldinfo *) fieldID; \
2565 if (!(c->state & CLASS_INITIALIZED)) \
2566 if (!initialize_class(c)) \
2569 f->value->field = value; \
2572 JNI_SET_STATIC_FIELD(Boolean, jboolean, i)
2573 JNI_SET_STATIC_FIELD(Byte, jbyte, i)
2574 JNI_SET_STATIC_FIELD(Char, jchar, i)
2575 JNI_SET_STATIC_FIELD(Short, jshort, i)
2576 JNI_SET_STATIC_FIELD(Int, jint, i)
2577 JNI_SET_STATIC_FIELD(Long, jlong, l)
2578 JNI_SET_STATIC_FIELD(Float, jfloat, f)
2579 JNI_SET_STATIC_FIELD(Double, jdouble, d)
2582 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
2588 STATISTICS(jniinvokation());
2590 c = LLNI_classinfo_unwrap(clazz);
2591 f = (fieldinfo *) fieldID;
2593 if (!(c->state & CLASS_INITIALIZED))
2594 if (!initialize_class(c))
2597 f->value->a = value;
2601 /* String Operations **********************************************************/
2603 /* NewString *******************************************************************
2605 Create new java.lang.String object from an array of Unicode
2608 *******************************************************************************/
2610 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
2612 java_lang_String *s;
2613 java_handle_chararray_t *a;
2616 STATISTICS(jniinvokation());
2618 s = (java_lang_String *) builtin_new(class_java_lang_String);
2619 a = builtin_newarray_char(len);
2621 /* javastring or characterarray could not be created */
2622 if ((a == NULL) || (s == NULL))
2626 for (i = 0; i < len; i++)
2627 LLNI_array_direct(a, i) = buf[i];
2629 LLNI_field_set_ref(s, value , a);
2630 LLNI_field_set_val(s, offset, 0);
2631 LLNI_field_set_val(s, count , len);
2633 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2637 static jchar emptyStringJ[]={0,0};
2639 /* GetStringLength *************************************************************
2641 Returns the length (the count of Unicode characters) of a Java
2644 *******************************************************************************/
2646 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
2648 java_lang_String *s;
2651 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
2653 s = (java_lang_String *) str;
2655 LLNI_field_get_val(s, count, len);
2661 /******************** convertes javastring to u2-array ****************************/
2663 u2 *javastring_tou2(jstring so)
2665 java_lang_String *s;
2666 java_handle_chararray_t *a;
2672 STATISTICS(jniinvokation());
2674 s = (java_lang_String *) so;
2679 LLNI_field_get_ref(s, value, a);
2684 LLNI_field_get_val(s, count, count);
2685 LLNI_field_get_val(s, offset, offset);
2687 /* allocate memory */
2689 stringbuffer = MNEW(u2, count + 1);
2693 for (i = 0; i < count; i++)
2694 stringbuffer[i] = LLNI_array_direct(a, offset + i);
2696 /* terminate string */
2698 stringbuffer[i] = '\0';
2700 return stringbuffer;
2704 /* GetStringChars **************************************************************
2706 Returns a pointer to the array of Unicode characters of the
2707 string. This pointer is valid until ReleaseStringChars() is called.
2709 *******************************************************************************/
2711 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
2715 STATISTICS(jniinvokation());
2717 jc = javastring_tou2(str);
2729 return emptyStringJ;
2733 /* ReleaseStringChars **********************************************************
2735 Informs the VM that the native code no longer needs access to
2736 chars. The chars argument is a pointer obtained from string using
2739 *******************************************************************************/
2741 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
2743 java_lang_String *s;
2745 STATISTICS(jniinvokation());
2747 if (chars == emptyStringJ)
2750 s = (java_lang_String *) str;
2752 MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
2756 /* NewStringUTF ****************************************************************
2758 Constructs a new java.lang.String object from an array of UTF-8
2761 *******************************************************************************/
2763 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
2765 java_lang_String *s;
2767 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
2769 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
2771 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
2775 /****************** returns the utf8 length in bytes of a string *******************/
2777 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
2779 java_lang_String *s;
2782 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
2784 s = (java_lang_String *) string;
2786 length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
2792 /* GetStringUTFChars ***********************************************************
2794 Returns a pointer to an array of UTF-8 characters of the
2795 string. This array is valid until it is released by
2796 ReleaseStringUTFChars().
2798 *******************************************************************************/
2800 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
2805 STATISTICS(jniinvokation());
2813 u = javastring_toutf((java_handle_t *) string, false);
2822 /* ReleaseStringUTFChars *******************************************************
2824 Informs the VM that the native code no longer needs access to
2825 utf. The utf argument is a pointer derived from string using
2826 GetStringUTFChars().
2828 *******************************************************************************/
2830 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
2832 STATISTICS(jniinvokation());
2834 /* XXX we don't release utf chars right now, perhaps that should be done
2835 later. Since there is always one reference the garbage collector will
2840 /* Array Operations ***********************************************************/
2842 /* GetArrayLength **************************************************************
2844 Returns the number of elements in the array.
2846 *******************************************************************************/
2848 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
2853 STATISTICS(jniinvokation());
2855 a = (java_handle_t *) array;
2857 size = LLNI_array_size(a);
2863 /* NewObjectArray **************************************************************
2865 Constructs a new array holding objects in class elementClass. All
2866 elements are initially set to initialElement.
2868 *******************************************************************************/
2870 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
2871 jclass elementClass, jobject initialElement)
2875 java_handle_objectarray_t *oa;
2878 STATISTICS(jniinvokation());
2880 c = LLNI_classinfo_unwrap(elementClass);
2881 o = (java_handle_t *) initialElement;
2884 exceptions_throw_negativearraysizeexception();
2888 oa = builtin_anewarray(length, c);
2893 /* set all elements to initialElement */
2895 for (i = 0; i < length; i++)
2896 LLNI_objectarray_element_set(oa, i, o);
2898 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
2902 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
2905 java_handle_objectarray_t *oa;
2908 STATISTICS(jniinvokation());
2910 oa = (java_handle_objectarray_t *) array;
2912 if (index >= LLNI_array_size(oa)) {
2913 exceptions_throw_arrayindexoutofboundsexception();
2917 LLNI_objectarray_element_get(oa, index, o);
2919 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2923 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
2924 jsize index, jobject val)
2926 java_handle_objectarray_t *oa;
2929 STATISTICS(jniinvokation());
2931 oa = (java_handle_objectarray_t *) array;
2932 o = (java_handle_t *) val;
2934 if (index >= LLNI_array_size(oa)) {
2935 exceptions_throw_arrayindexoutofboundsexception();
2939 /* check if the class of value is a subclass of the element class
2942 if (!builtin_canstore(oa, o))
2945 LLNI_objectarray_element_set(oa, index, o);
2949 #define JNI_NEW_ARRAY(name, type, intern) \
2950 type _Jv_JNI_New##name##Array(JNIEnv *env, jsize len) \
2952 java_handle_##intern##array_t *a; \
2954 STATISTICS(jniinvokation()); \
2957 exceptions_throw_negativearraysizeexception(); \
2961 a = builtin_newarray_##intern(len); \
2963 return (type) _Jv_JNI_NewLocalRef(env, (jobject) a); \
2966 JNI_NEW_ARRAY(Boolean, jbooleanArray, boolean)
2967 JNI_NEW_ARRAY(Byte, jbyteArray, byte)
2968 JNI_NEW_ARRAY(Char, jcharArray, char)
2969 JNI_NEW_ARRAY(Short, jshortArray, byte)
2970 JNI_NEW_ARRAY(Int, jintArray, int)
2971 JNI_NEW_ARRAY(Long, jlongArray, long)
2972 JNI_NEW_ARRAY(Float, jfloatArray, float)
2973 JNI_NEW_ARRAY(Double, jdoubleArray, double)
2976 /* Get<PrimitiveType>ArrayElements *********************************************
2978 A family of functions that returns the body of the primitive array.
2980 *******************************************************************************/
2982 #define JNI_GET_ARRAY_ELEMENTS(name, type, intern) \
2983 type *_Jv_JNI_Get##name##ArrayElements(JNIEnv *env, type##Array array, \
2986 java_handle_##intern##array_t *a; \
2988 STATISTICS(jniinvokation()); \
2990 a = (java_handle_##intern##array_t *) array; \
2993 *isCopy = JNI_FALSE; \
2995 return LLNI_array_data(a); \
2998 JNI_GET_ARRAY_ELEMENTS(Boolean, jboolean, boolean)
2999 JNI_GET_ARRAY_ELEMENTS(Byte, jbyte, byte)
3000 JNI_GET_ARRAY_ELEMENTS(Char, jchar, char)
3001 JNI_GET_ARRAY_ELEMENTS(Short, jshort, short)
3002 JNI_GET_ARRAY_ELEMENTS(Int, jint, int)
3003 JNI_GET_ARRAY_ELEMENTS(Long, jlong, long)
3004 JNI_GET_ARRAY_ELEMENTS(Float, jfloat, float)
3005 JNI_GET_ARRAY_ELEMENTS(Double, jdouble, double)
3008 /* Release<PrimitiveType>ArrayElements *****************************************
3010 A family of functions that informs the VM that the native code no
3011 longer needs access to elems. The elems argument is a pointer
3012 derived from array using the corresponding
3013 Get<PrimitiveType>ArrayElements() function. If necessary, this
3014 function copies back all changes made to elems to the original
3017 *******************************************************************************/
3019 #define JNI_RELEASE_ARRAY_ELEMENTS(name, type, intern, intern2) \
3020 void _Jv_JNI_Release##name##ArrayElements(JNIEnv *env, type##Array array, \
3021 type *elems, jint mode) \
3023 java_handle_##intern##array_t *a; \
3025 STATISTICS(jniinvokation()); \
3027 a = (java_handle_##intern##array_t *) array; \
3029 if (elems != LLNI_array_data(a)) { \
3032 MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
3035 MCOPY(LLNI_array_data(a), elems, intern2, LLNI_array_size(a)); \
3036 /* XXX TWISTI how should it be freed? */ \
3039 /* XXX TWISTI how should it be freed? */ \
3045 JNI_RELEASE_ARRAY_ELEMENTS(Boolean, jboolean, boolean, u1)
3046 JNI_RELEASE_ARRAY_ELEMENTS(Byte, jbyte, byte, s1)
3047 JNI_RELEASE_ARRAY_ELEMENTS(Char, jchar, char, u2)
3048 JNI_RELEASE_ARRAY_ELEMENTS(Short, jshort, short, s2)
3049 JNI_RELEASE_ARRAY_ELEMENTS(Int, jint, int, s4)
3050 JNI_RELEASE_ARRAY_ELEMENTS(Long, jlong, long, s8)
3051 JNI_RELEASE_ARRAY_ELEMENTS(Float, jfloat, float, float)
3052 JNI_RELEASE_ARRAY_ELEMENTS(Double, jdouble, double, double)
3055 /* Get<PrimitiveType>ArrayRegion **********************************************
3057 A family of functions that copies a region of a primitive array
3060 *******************************************************************************/
3062 #define JNI_GET_ARRAY_REGION(name, type, intern, intern2) \
3063 void _Jv_JNI_Get##name##ArrayRegion(JNIEnv *env, type##Array array, \
3064 jsize start, jsize len, type *buf) \
3066 java_handle_##intern##array_t *a; \
3068 STATISTICS(jniinvokation()); \
3070 a = (java_handle_##intern##array_t *) array; \
3072 if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
3073 exceptions_throw_arrayindexoutofboundsexception(); \
3075 MCOPY(buf, &LLNI_array_direct(a, start), intern2, len); \
3078 JNI_GET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3079 JNI_GET_ARRAY_REGION(Byte, jbyte, byte, s1)
3080 JNI_GET_ARRAY_REGION(Char, jchar, char, u2)
3081 JNI_GET_ARRAY_REGION(Short, jshort, short, s2)
3082 JNI_GET_ARRAY_REGION(Int, jint, int, s4)
3083 JNI_GET_ARRAY_REGION(Long, jlong, long, s8)
3084 JNI_GET_ARRAY_REGION(Float, jfloat, float, float)
3085 JNI_GET_ARRAY_REGION(Double, jdouble, double, double)
3088 /* Set<PrimitiveType>ArrayRegion **********************************************
3090 A family of functions that copies back a region of a primitive
3091 array from a buffer.
3093 *******************************************************************************/
3095 #define JNI_SET_ARRAY_REGION(name, type, intern, intern2) \
3096 void _Jv_JNI_Set##name##ArrayRegion(JNIEnv *env, type##Array array, \
3097 jsize start, jsize len, const type *buf) \
3099 java_handle_##intern##array_t *a; \
3101 STATISTICS(jniinvokation()); \
3103 a = (java_handle_##intern##array_t *) array; \
3105 if ((start < 0) || (len < 0) || (start + len > LLNI_array_size(a))) \
3106 exceptions_throw_arrayindexoutofboundsexception(); \
3108 MCOPY(&LLNI_array_direct(a, start), buf, intern2, len); \
3111 JNI_SET_ARRAY_REGION(Boolean, jboolean, boolean, u1)
3112 JNI_SET_ARRAY_REGION(Byte, jbyte, byte, s1)
3113 JNI_SET_ARRAY_REGION(Char, jchar, char, u2)
3114 JNI_SET_ARRAY_REGION(Short, jshort, short, s2)
3115 JNI_SET_ARRAY_REGION(Int, jint, int, s4)
3116 JNI_SET_ARRAY_REGION(Long, jlong, long, s8)
3117 JNI_SET_ARRAY_REGION(Float, jfloat, float, float)
3118 JNI_SET_ARRAY_REGION(Double, jdouble, double, double)
3121 /* Registering Native Methods *************************************************/
3123 /* RegisterNatives *************************************************************
3125 Registers native methods with the class specified by the clazz
3126 argument. The methods parameter specifies an array of
3127 JNINativeMethod structures that contain the names, signatures, and
3128 function pointers of the native methods. The nMethods parameter
3129 specifies the number of native methods in the array.
3131 *******************************************************************************/
3133 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
3134 const JNINativeMethod *methods, jint nMethods)
3138 STATISTICS(jniinvokation());
3140 c = LLNI_classinfo_unwrap(clazz);
3142 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
3143 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
3146 native_method_register(c->name, methods, nMethods);
3152 /* UnregisterNatives ***********************************************************
3154 Unregisters native methods of a class. The class goes back to the
3155 state before it was linked or registered with its native method
3158 This function should not be used in normal native code. Instead, it
3159 provides special programs a way to reload and relink native
3162 *******************************************************************************/
3164 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
3166 STATISTICS(jniinvokation());
3168 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
3170 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
3176 /* Monitor Operations *********************************************************/
3178 /* MonitorEnter ****************************************************************
3180 Enters the monitor associated with the underlying Java object
3183 *******************************************************************************/
3185 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
3187 STATISTICS(jniinvokation());
3190 exceptions_throw_nullpointerexception();
3194 LOCK_MONITOR_ENTER(obj);
3200 /* MonitorExit *****************************************************************
3202 The current thread must be the owner of the monitor associated with
3203 the underlying Java object referred to by obj. The thread
3204 decrements the counter indicating the number of times it has
3205 entered this monitor. If the value of the counter becomes zero, the
3206 current thread releases the monitor.
3208 *******************************************************************************/
3210 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
3212 STATISTICS(jniinvokation());
3215 exceptions_throw_nullpointerexception();
3219 LOCK_MONITOR_EXIT(obj);
3225 /* JavaVM Interface ***********************************************************/
3227 /* GetJavaVM *******************************************************************
3229 Returns the Java VM interface (used in the Invocation API)
3230 associated with the current thread. The result is placed at the
3231 location pointed to by the second argument, vm.
3233 *******************************************************************************/
3235 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
3237 STATISTICS(jniinvokation());
3239 *vm = (JavaVM *) _Jv_jvm;
3245 /* GetStringRegion *************************************************************
3247 Copies len number of Unicode characters beginning at offset start
3248 to the given buffer buf.
3250 Throws StringIndexOutOfBoundsException on index overflow.
3252 *******************************************************************************/
3254 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
3257 java_lang_String *s;
3258 java_handle_chararray_t *ca;
3260 STATISTICS(jniinvokation());
3262 s = (java_lang_String *) str;
3263 LLNI_field_get_ref(s, value, ca);
3265 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
3266 (start + len > LLNI_field_direct(s, count))) {
3267 exceptions_throw_stringindexoutofboundsexception();
3271 MCOPY(buf, &LLNI_array_direct(ca, start), u2, len);
3275 /* GetStringUTFRegion **********************************************************
3277 Translates len number of Unicode characters beginning at offset
3278 start into UTF-8 format and place the result in the given buffer
3281 Throws StringIndexOutOfBoundsException on index overflow.
3283 *******************************************************************************/
3285 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
3286 jsize len, char *buf)
3288 java_lang_String *s;
3289 java_handle_chararray_t *ca;
3294 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
3296 s = (java_lang_String *) str;
3297 LLNI_field_get_ref(s, value, ca);
3298 LLNI_field_get_val(s, count, count);
3299 LLNI_field_get_val(s, offset, offset);
3301 if ((start < 0) || (len < 0) || (start > count) || (start + len > count)) {
3302 exceptions_throw_stringindexoutofboundsexception();
3306 for (i = 0; i < len; i++)
3307 buf[i] = LLNI_array_direct(ca, offset + start + i);
3313 /* GetPrimitiveArrayCritical ***************************************************
3315 Obtain a direct pointer to array elements.
3317 *******************************************************************************/
3319 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
3322 java_handle_bytearray_t *ba;
3325 ba = (java_handle_bytearray_t *) array;
3327 /* do the same as Kaffe does */
3329 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
3335 /* ReleasePrimitiveArrayCritical ***********************************************
3337 No specific documentation.
3339 *******************************************************************************/
3341 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
3342 void *carray, jint mode)
3344 STATISTICS(jniinvokation());
3346 /* do the same as Kaffe does */
3348 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
3353 /* GetStringCritical ***********************************************************
3355 The semantics of these two functions are similar to the existing
3356 Get/ReleaseStringChars functions.
3358 *******************************************************************************/
3360 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
3363 STATISTICS(jniinvokation());
3365 return _Jv_JNI_GetStringChars(env, string, isCopy);
3369 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
3370 const jchar *cstring)
3372 STATISTICS(jniinvokation());
3374 _Jv_JNI_ReleaseStringChars(env, string, cstring);
3378 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
3380 STATISTICS(jniinvokation());
3382 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
3388 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
3390 STATISTICS(jniinvokation());
3392 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
3396 /* NewGlobalRef ****************************************************************
3398 Creates a new global reference to the object referred to by the obj
3401 *******************************************************************************/
3403 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
3405 hashtable_global_ref_entry *gre;
3406 u4 key; /* hashkey */
3407 u4 slot; /* slot in hashtable */
3410 STATISTICS(jniinvokation());
3412 o = (java_handle_t *) obj;
3414 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3416 /* normally addresses are aligned to 4, 8 or 16 bytes */
3418 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
3419 slot = key & (hashtable_global_ref->size - 1);
3420 gre = hashtable_global_ref->ptr[slot];
3422 /* search external hash chain for the entry */
3426 /* global object found, increment the reference */
3430 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3435 gre = gre->hashlink; /* next element in external chain */
3438 /* global ref not found, create a new one */
3440 gre = NEW(hashtable_global_ref_entry);
3445 /* insert entry into hashtable */
3447 gre->hashlink = hashtable_global_ref->ptr[slot];
3449 hashtable_global_ref->ptr[slot] = gre;
3451 /* update number of hashtable-entries */
3453 hashtable_global_ref->entries++;
3455 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3461 /* DeleteGlobalRef *************************************************************
3463 Deletes the global reference pointed to by globalRef.
3465 *******************************************************************************/
3467 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
3469 hashtable_global_ref_entry *gre;
3470 hashtable_global_ref_entry *prevgre;
3471 u4 key; /* hashkey */
3472 u4 slot; /* slot in hashtable */
3475 STATISTICS(jniinvokation());
3477 o = (java_handle_t *) globalRef;
3479 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
3481 /* normally addresses are aligned to 4, 8 or 16 bytes */
3483 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
3484 slot = key & (hashtable_global_ref->size - 1);
3485 gre = hashtable_global_ref->ptr[slot];
3487 /* initialize prevgre */
3491 /* search external hash chain for the entry */
3495 /* global object found, decrement the reference count */
3499 /* if reference count is 0, remove the entry */
3501 if (gre->refs == 0) {
3502 /* special handling if it's the first in the chain */
3504 if (prevgre == NULL)
3505 hashtable_global_ref->ptr[slot] = gre->hashlink;
3507 prevgre->hashlink = gre->hashlink;
3509 FREE(gre, hashtable_global_ref_entry);
3512 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3517 prevgre = gre; /* save current pointer for removal */
3518 gre = gre->hashlink; /* next element in external chain */
3521 log_println("JNI-DeleteGlobalRef: global reference not found");
3523 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
3527 /* ExceptionCheck **************************************************************
3529 Returns JNI_TRUE when there is a pending exception; otherwise,
3532 *******************************************************************************/
3534 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
3538 STATISTICS(jniinvokation());
3540 o = exceptions_get_exception();
3542 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
3546 /* New JNI 1.4 functions ******************************************************/
3548 /* NewDirectByteBuffer *********************************************************
3550 Allocates and returns a direct java.nio.ByteBuffer referring to the
3551 block of memory starting at the memory address address and
3552 extending capacity bytes.
3554 *******************************************************************************/
3556 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
3558 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3559 java_handle_t *nbuf;
3561 # if SIZEOF_VOID_P == 8
3562 gnu_classpath_Pointer64 *paddress;
3564 gnu_classpath_Pointer32 *paddress;
3567 STATISTICS(jniinvokation());
3569 /* alocate a gnu.classpath.Pointer{32,64} object */
3571 # if SIZEOF_VOID_P == 8
3572 if (!(paddress = (gnu_classpath_Pointer64 *)
3573 builtin_new(class_gnu_classpath_Pointer64)))
3575 if (!(paddress = (gnu_classpath_Pointer32 *)
3576 builtin_new(class_gnu_classpath_Pointer32)))
3580 /* fill gnu.classpath.Pointer{32,64} with address */
3582 LLNI_field_set_val(paddress, data, (ptrint) address);
3584 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
3586 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
3587 (jmethodID) dbbirw_init, NULL, paddress,
3588 (jint) capacity, (jint) capacity, (jint) 0);
3590 /* add local reference and return the value */
3592 return _Jv_JNI_NewLocalRef(env, nbuf);
3594 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
3596 /* keep compiler happy */
3603 /* GetDirectBufferAddress ******************************************************
3605 Fetches and returns the starting address of the memory region
3606 referenced by the given direct java.nio.Buffer.
3608 *******************************************************************************/
3610 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
3612 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3613 java_nio_DirectByteBufferImpl *nbuf;
3614 # if SIZEOF_VOID_P == 8
3615 gnu_classpath_Pointer64 *paddress;
3617 gnu_classpath_Pointer32 *paddress;
3621 STATISTICS(jniinvokation());
3623 if (!builtin_instanceof(buf, class_java_nio_Buffer))
3626 nbuf = (java_nio_DirectByteBufferImpl *) buf;
3628 # if SIZEOF_VOID_P == 8
3629 LLNI_field_get_ref(nbuf, address, paddress);
3630 /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
3632 LLNI_field_get_ref(nbuf, address, paddress);
3633 /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
3636 if (paddress == NULL)
3639 LLNI_field_get_val(paddress, data, address);
3640 /* this was the cast to avaoid warning: (void *) paddress->data */
3644 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
3646 /* keep compiler happy */
3653 /* GetDirectBufferCapacity *****************************************************
3655 Fetches and returns the capacity in bytes of the memory region
3656 referenced by the given direct java.nio.Buffer.
3658 *******************************************************************************/
3660 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
3662 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
3664 java_nio_Buffer *nbuf;
3667 STATISTICS(jniinvokation());
3669 o = (java_handle_t *) buf;
3671 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
3674 nbuf = (java_nio_Buffer *) o;
3676 LLNI_field_get_val(nbuf, cap, capacity);
3680 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
3682 /* keep compiler happy */
3689 /* DestroyJavaVM ***************************************************************
3691 Unloads a Java VM and reclaims its resources. Only the main thread
3692 can unload the VM. The system waits until the main thread is only
3693 remaining user thread before it destroys the VM.
3695 *******************************************************************************/
3697 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
3701 STATISTICS(jniinvokation());
3703 status = vm_destroy(vm);
3709 /* AttachCurrentThread *********************************************************
3711 Attaches the current thread to a Java VM. Returns a JNI interface
3712 pointer in the JNIEnv argument.
3714 Trying to attach a thread that is already attached is a no-op.
3716 A native thread cannot be attached simultaneously to two Java VMs.
3718 When a thread is attached to the VM, the context class loader is
3719 the bootstrap loader.
3721 *******************************************************************************/
3723 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
3725 JavaVMAttachArgs *vm_aargs;
3727 #if defined(ENABLE_THREADS)
3728 if (threads_get_current_threadobject() == NULL) {
3729 vm_aargs = (JavaVMAttachArgs *) thr_args;
3731 if (vm_aargs != NULL) {
3732 if ((vm_aargs->version != JNI_VERSION_1_2) &&
3733 (vm_aargs->version != JNI_VERSION_1_4))
3734 return JNI_EVERSION;
3737 if (!threads_attach_current_thread(vm_aargs, false))
3740 if (!localref_table_init())
3751 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
3753 STATISTICS(jniinvokation());
3755 return jni_attach_current_thread(p_env, thr_args, false);
3759 /* DetachCurrentThread *********************************************************
3761 Detaches the current thread from a Java VM. All Java monitors held
3762 by this thread are released. All Java threads waiting for this
3763 thread to die are notified.
3765 In JDK 1.1, the main thread cannot be detached from the VM. It must
3766 call DestroyJavaVM to unload the entire VM.
3768 In the JDK, the main thread can be detached from the VM.
3770 The main thread, which is the thread that created the Java VM,
3771 cannot be detached from the VM. Instead, the main thread must call
3772 JNI_DestroyJavaVM() to unload the entire VM.
3774 *******************************************************************************/
3776 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
3778 #if defined(ENABLE_THREADS)
3779 threadobject *thread;
3781 STATISTICS(jniinvokation());
3783 thread = threads_get_current_threadobject();
3788 if (!threads_detach_thread(thread))
3796 /* GetEnv **********************************************************************
3798 If the current thread is not attached to the VM, sets *env to NULL,
3799 and returns JNI_EDETACHED. If the specified version is not
3800 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
3801 sets *env to the appropriate interface, and returns JNI_OK.
3803 *******************************************************************************/
3805 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
3807 STATISTICS(jniinvokation());
3809 #if defined(ENABLE_THREADS)
3810 if (threads_get_current_threadobject() == NULL) {
3813 return JNI_EDETACHED;
3817 /* check the JNI version */
3820 case JNI_VERSION_1_1:
3821 case JNI_VERSION_1_2:
3822 case JNI_VERSION_1_4:
3830 #if defined(ENABLE_JVMTI)
3831 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
3832 == JVMTI_VERSION_INTERFACE_JVMTI) {
3834 *env = (void *) jvmti_new_environment();
3843 return JNI_EVERSION;
3847 /* AttachCurrentThreadAsDaemon *************************************************
3849 Same semantics as AttachCurrentThread, but the newly-created
3850 java.lang.Thread instance is a daemon.
3852 If the thread has already been attached via either
3853 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
3854 simply sets the value pointed to by penv to the JNIEnv of the
3855 current thread. In this case neither AttachCurrentThread nor this
3856 routine have any effect on the daemon status of the thread.
3858 *******************************************************************************/
3860 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
3862 STATISTICS(jniinvokation());
3864 return jni_attach_current_thread(penv, args, true);
3868 /* JNI invocation table *******************************************************/
3870 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
3875 _Jv_JNI_DestroyJavaVM,
3876 _Jv_JNI_AttachCurrentThread,
3877 _Jv_JNI_DetachCurrentThread,
3879 _Jv_JNI_AttachCurrentThreadAsDaemon
3883 /* JNI function table *********************************************************/
3885 struct JNINativeInterface_ _Jv_JNINativeInterface = {
3892 _Jv_JNI_DefineClass,
3894 _Jv_JNI_FromReflectedMethod,
3895 _Jv_JNI_FromReflectedField,
3896 _Jv_JNI_ToReflectedMethod,
3897 _Jv_JNI_GetSuperclass,
3898 _Jv_JNI_IsAssignableFrom,
3899 _Jv_JNI_ToReflectedField,
3903 _Jv_JNI_ExceptionOccurred,
3904 _Jv_JNI_ExceptionDescribe,
3905 _Jv_JNI_ExceptionClear,
3907 _Jv_JNI_PushLocalFrame,
3908 _Jv_JNI_PopLocalFrame,
3910 _Jv_JNI_NewGlobalRef,
3911 _Jv_JNI_DeleteGlobalRef,
3912 _Jv_JNI_DeleteLocalRef,
3913 _Jv_JNI_IsSameObject,
3914 _Jv_JNI_NewLocalRef,
3915 _Jv_JNI_EnsureLocalCapacity,
3917 _Jv_JNI_AllocObject,
3922 _Jv_JNI_GetObjectClass,
3923 _Jv_JNI_IsInstanceOf,
3925 _Jv_JNI_GetMethodID,
3927 _Jv_JNI_CallObjectMethod,
3928 _Jv_JNI_CallObjectMethodV,
3929 _Jv_JNI_CallObjectMethodA,
3930 _Jv_JNI_CallBooleanMethod,
3931 _Jv_JNI_CallBooleanMethodV,
3932 _Jv_JNI_CallBooleanMethodA,
3933 _Jv_JNI_CallByteMethod,
3934 _Jv_JNI_CallByteMethodV,
3935 _Jv_JNI_CallByteMethodA,
3936 _Jv_JNI_CallCharMethod,
3937 _Jv_JNI_CallCharMethodV,
3938 _Jv_JNI_CallCharMethodA,
3939 _Jv_JNI_CallShortMethod,
3940 _Jv_JNI_CallShortMethodV,
3941 _Jv_JNI_CallShortMethodA,
3942 _Jv_JNI_CallIntMethod,
3943 _Jv_JNI_CallIntMethodV,
3944 _Jv_JNI_CallIntMethodA,
3945 _Jv_JNI_CallLongMethod,
3946 _Jv_JNI_CallLongMethodV,
3947 _Jv_JNI_CallLongMethodA,
3948 _Jv_JNI_CallFloatMethod,
3949 _Jv_JNI_CallFloatMethodV,
3950 _Jv_JNI_CallFloatMethodA,
3951 _Jv_JNI_CallDoubleMethod,
3952 _Jv_JNI_CallDoubleMethodV,
3953 _Jv_JNI_CallDoubleMethodA,
3954 _Jv_JNI_CallVoidMethod,
3955 _Jv_JNI_CallVoidMethodV,
3956 _Jv_JNI_CallVoidMethodA,
3958 _Jv_JNI_CallNonvirtualObjectMethod,
3959 _Jv_JNI_CallNonvirtualObjectMethodV,
3960 _Jv_JNI_CallNonvirtualObjectMethodA,
3961 _Jv_JNI_CallNonvirtualBooleanMethod,
3962 _Jv_JNI_CallNonvirtualBooleanMethodV,
3963 _Jv_JNI_CallNonvirtualBooleanMethodA,
3964 _Jv_JNI_CallNonvirtualByteMethod,
3965 _Jv_JNI_CallNonvirtualByteMethodV,
3966 _Jv_JNI_CallNonvirtualByteMethodA,
3967 _Jv_JNI_CallNonvirtualCharMethod,
3968 _Jv_JNI_CallNonvirtualCharMethodV,
3969 _Jv_JNI_CallNonvirtualCharMethodA,
3970 _Jv_JNI_CallNonvirtualShortMethod,
3971 _Jv_JNI_CallNonvirtualShortMethodV,
3972 _Jv_JNI_CallNonvirtualShortMethodA,
3973 _Jv_JNI_CallNonvirtualIntMethod,
3974 _Jv_JNI_CallNonvirtualIntMethodV,
3975 _Jv_JNI_CallNonvirtualIntMethodA,
3976 _Jv_JNI_CallNonvirtualLongMethod,
3977 _Jv_JNI_CallNonvirtualLongMethodV,
3978 _Jv_JNI_CallNonvirtualLongMethodA,
3979 _Jv_JNI_CallNonvirtualFloatMethod,
3980 _Jv_JNI_CallNonvirtualFloatMethodV,
3981 _Jv_JNI_CallNonvirtualFloatMethodA,
3982 _Jv_JNI_CallNonvirtualDoubleMethod,
3983 _Jv_JNI_CallNonvirtualDoubleMethodV,
3984 _Jv_JNI_CallNonvirtualDoubleMethodA,
3985 _Jv_JNI_CallNonvirtualVoidMethod,
3986 _Jv_JNI_CallNonvirtualVoidMethodV,
3987 _Jv_JNI_CallNonvirtualVoidMethodA,
3991 _Jv_JNI_GetObjectField,
3992 _Jv_JNI_GetBooleanField,
3993 _Jv_JNI_GetByteField,
3994 _Jv_JNI_GetCharField,
3995 _Jv_JNI_GetShortField,
3996 _Jv_JNI_GetIntField,
3997 _Jv_JNI_GetLongField,
3998 _Jv_JNI_GetFloatField,
3999 _Jv_JNI_GetDoubleField,
4000 _Jv_JNI_SetObjectField,
4001 _Jv_JNI_SetBooleanField,
4002 _Jv_JNI_SetByteField,
4003 _Jv_JNI_SetCharField,
4004 _Jv_JNI_SetShortField,
4005 _Jv_JNI_SetIntField,
4006 _Jv_JNI_SetLongField,
4007 _Jv_JNI_SetFloatField,
4008 _Jv_JNI_SetDoubleField,
4010 _Jv_JNI_GetStaticMethodID,
4012 _Jv_JNI_CallStaticObjectMethod,
4013 _Jv_JNI_CallStaticObjectMethodV,
4014 _Jv_JNI_CallStaticObjectMethodA,
4015 _Jv_JNI_CallStaticBooleanMethod,
4016 _Jv_JNI_CallStaticBooleanMethodV,
4017 _Jv_JNI_CallStaticBooleanMethodA,
4018 _Jv_JNI_CallStaticByteMethod,
4019 _Jv_JNI_CallStaticByteMethodV,
4020 _Jv_JNI_CallStaticByteMethodA,
4021 _Jv_JNI_CallStaticCharMethod,
4022 _Jv_JNI_CallStaticCharMethodV,
4023 _Jv_JNI_CallStaticCharMethodA,
4024 _Jv_JNI_CallStaticShortMethod,
4025 _Jv_JNI_CallStaticShortMethodV,
4026 _Jv_JNI_CallStaticShortMethodA,
4027 _Jv_JNI_CallStaticIntMethod,
4028 _Jv_JNI_CallStaticIntMethodV,
4029 _Jv_JNI_CallStaticIntMethodA,
4030 _Jv_JNI_CallStaticLongMethod,
4031 _Jv_JNI_CallStaticLongMethodV,
4032 _Jv_JNI_CallStaticLongMethodA,
4033 _Jv_JNI_CallStaticFloatMethod,
4034 _Jv_JNI_CallStaticFloatMethodV,
4035 _Jv_JNI_CallStaticFloatMethodA,
4036 _Jv_JNI_CallStaticDoubleMethod,
4037 _Jv_JNI_CallStaticDoubleMethodV,
4038 _Jv_JNI_CallStaticDoubleMethodA,
4039 _Jv_JNI_CallStaticVoidMethod,
4040 _Jv_JNI_CallStaticVoidMethodV,
4041 _Jv_JNI_CallStaticVoidMethodA,
4043 _Jv_JNI_GetStaticFieldID,
4045 _Jv_JNI_GetStaticObjectField,
4046 _Jv_JNI_GetStaticBooleanField,
4047 _Jv_JNI_GetStaticByteField,
4048 _Jv_JNI_GetStaticCharField,
4049 _Jv_JNI_GetStaticShortField,
4050 _Jv_JNI_GetStaticIntField,
4051 _Jv_JNI_GetStaticLongField,
4052 _Jv_JNI_GetStaticFloatField,
4053 _Jv_JNI_GetStaticDoubleField,
4054 _Jv_JNI_SetStaticObjectField,
4055 _Jv_JNI_SetStaticBooleanField,
4056 _Jv_JNI_SetStaticByteField,
4057 _Jv_JNI_SetStaticCharField,
4058 _Jv_JNI_SetStaticShortField,
4059 _Jv_JNI_SetStaticIntField,
4060 _Jv_JNI_SetStaticLongField,
4061 _Jv_JNI_SetStaticFloatField,
4062 _Jv_JNI_SetStaticDoubleField,
4065 _Jv_JNI_GetStringLength,
4066 _Jv_JNI_GetStringChars,
4067 _Jv_JNI_ReleaseStringChars,
4069 _Jv_JNI_NewStringUTF,
4070 _Jv_JNI_GetStringUTFLength,
4071 _Jv_JNI_GetStringUTFChars,
4072 _Jv_JNI_ReleaseStringUTFChars,
4074 _Jv_JNI_GetArrayLength,
4076 _Jv_JNI_NewObjectArray,
4077 _Jv_JNI_GetObjectArrayElement,
4078 _Jv_JNI_SetObjectArrayElement,
4080 _Jv_JNI_NewBooleanArray,
4081 _Jv_JNI_NewByteArray,
4082 _Jv_JNI_NewCharArray,
4083 _Jv_JNI_NewShortArray,
4084 _Jv_JNI_NewIntArray,
4085 _Jv_JNI_NewLongArray,
4086 _Jv_JNI_NewFloatArray,
4087 _Jv_JNI_NewDoubleArray,
4089 _Jv_JNI_GetBooleanArrayElements,
4090 _Jv_JNI_GetByteArrayElements,
4091 _Jv_JNI_GetCharArrayElements,
4092 _Jv_JNI_GetShortArrayElements,
4093 _Jv_JNI_GetIntArrayElements,
4094 _Jv_JNI_GetLongArrayElements,
4095 _Jv_JNI_GetFloatArrayElements,
4096 _Jv_JNI_GetDoubleArrayElements,
4098 _Jv_JNI_ReleaseBooleanArrayElements,
4099 _Jv_JNI_ReleaseByteArrayElements,
4100 _Jv_JNI_ReleaseCharArrayElements,
4101 _Jv_JNI_ReleaseShortArrayElements,
4102 _Jv_JNI_ReleaseIntArrayElements,
4103 _Jv_JNI_ReleaseLongArrayElements,
4104 _Jv_JNI_ReleaseFloatArrayElements,
4105 _Jv_JNI_ReleaseDoubleArrayElements,
4107 _Jv_JNI_GetBooleanArrayRegion,
4108 _Jv_JNI_GetByteArrayRegion,
4109 _Jv_JNI_GetCharArrayRegion,
4110 _Jv_JNI_GetShortArrayRegion,
4111 _Jv_JNI_GetIntArrayRegion,
4112 _Jv_JNI_GetLongArrayRegion,
4113 _Jv_JNI_GetFloatArrayRegion,
4114 _Jv_JNI_GetDoubleArrayRegion,
4115 _Jv_JNI_SetBooleanArrayRegion,
4116 _Jv_JNI_SetByteArrayRegion,
4117 _Jv_JNI_SetCharArrayRegion,
4118 _Jv_JNI_SetShortArrayRegion,
4119 _Jv_JNI_SetIntArrayRegion,
4120 _Jv_JNI_SetLongArrayRegion,
4121 _Jv_JNI_SetFloatArrayRegion,
4122 _Jv_JNI_SetDoubleArrayRegion,
4124 _Jv_JNI_RegisterNatives,
4125 _Jv_JNI_UnregisterNatives,
4127 _Jv_JNI_MonitorEnter,
4128 _Jv_JNI_MonitorExit,
4132 /* new JNI 1.2 functions */
4134 _Jv_JNI_GetStringRegion,
4135 _Jv_JNI_GetStringUTFRegion,
4137 _Jv_JNI_GetPrimitiveArrayCritical,
4138 _Jv_JNI_ReleasePrimitiveArrayCritical,
4140 _Jv_JNI_GetStringCritical,
4141 _Jv_JNI_ReleaseStringCritical,
4143 _Jv_JNI_NewWeakGlobalRef,
4144 _Jv_JNI_DeleteWeakGlobalRef,
4146 _Jv_JNI_ExceptionCheck,
4148 /* new JNI 1.4 functions */
4150 _Jv_JNI_NewDirectByteBuffer,
4151 _Jv_JNI_GetDirectBufferAddress,
4152 _Jv_JNI_GetDirectBufferCapacity
4156 /* Invocation API Functions ***************************************************/
4158 /* JNI_GetDefaultJavaVMInitArgs ************************************************
4160 Returns a default configuration for the Java VM.
4162 *******************************************************************************/
4164 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
4166 JavaVMInitArgs *_vm_args;
4168 _vm_args = (JavaVMInitArgs *) vm_args;
4170 /* GNU classpath currently supports JNI 1.2 */
4172 switch (_vm_args->version) {
4173 case JNI_VERSION_1_1:
4174 _vm_args->version = JNI_VERSION_1_1;
4177 case JNI_VERSION_1_2:
4178 case JNI_VERSION_1_4:
4179 _vm_args->ignoreUnrecognized = JNI_FALSE;
4180 _vm_args->options = NULL;
4181 _vm_args->nOptions = 0;
4192 /* JNI_GetCreatedJavaVMs *******************************************************
4194 Returns all Java VMs that have been created. Pointers to VMs are written in
4195 the buffer vmBuf in the order they are created. At most bufLen number of
4196 entries will be written. The total number of created VMs is returned in
4199 *******************************************************************************/
4201 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
4203 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
4208 /* We currently only support 1 VM running. */
4210 vmBuf[0] = (JavaVM *) _Jv_jvm;
4217 /* JNI_CreateJavaVM ************************************************************
4219 Loads and initializes a Java VM. The current thread becomes the main thread.
4220 Sets the env argument to the JNI interface pointer of the main thread.
4222 *******************************************************************************/
4224 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
4226 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
4228 /* actually create the JVM */
4230 if (!vm_createjvm(p_vm, p_env, vm_args))
4238 * These are local overrides for various environment variables in Emacs.
4239 * Please do not remove this and leave it at the end of the file, where
4240 * Emacs will automagically detect them.
4241 * ---------------------------------------------------------------------
4244 * indent-tabs-mode: t
4248 * vim:noexpandtab:sw=4:ts=4: