1 /* src/native/jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 $Id: jni.c 8291 2007-08-11 10:43:45Z twisti $
38 #include "mm/gc-common.h"
39 #include "mm/memory.h"
40 #include "native/jni.h"
41 #include "native/llni.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 /* local reference table ******************************************************/
166 #if !defined(ENABLE_THREADS)
167 localref_table *_no_threads_localref_table;
171 /* accessing instance fields macros *******************************************/
173 #define SET_FIELD(o,type,f,value) \
174 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset))) = (type) (value)
176 #define GET_FIELD(o,type,f) \
177 *((type *) (((intptr_t) (o)) + ((intptr_t) ((fieldinfo *) (f))->offset)))
180 /* some forward declarations **************************************************/
182 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref);
183 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity);
186 /* jni_init ********************************************************************
188 Initialize the JNI subsystem.
190 *******************************************************************************/
194 /* create global ref hashtable */
196 hashtable_global_ref = NEW(hashtable);
198 hashtable_create(hashtable_global_ref, HASHTABLE_GLOBAL_REF_SIZE);
201 #if defined(ENABLE_JAVASE)
202 /* direct buffer stuff */
204 if (!(class_java_nio_Buffer =
205 load_class_bootstrap(utf_new_char("java/nio/Buffer"))) ||
206 !link_class(class_java_nio_Buffer))
209 # if defined(WITH_CLASSPATH_GNU)
210 if (!(class_java_nio_DirectByteBufferImpl =
211 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl"))) ||
212 !link_class(class_java_nio_DirectByteBufferImpl))
215 if (!(class_java_nio_DirectByteBufferImpl_ReadWrite =
216 load_class_bootstrap(utf_new_char("java/nio/DirectByteBufferImpl$ReadWrite"))) ||
217 !link_class(class_java_nio_DirectByteBufferImpl_ReadWrite))
221 class_resolvemethod(class_java_nio_DirectByteBufferImpl_ReadWrite,
223 utf_new_char("(Ljava/lang/Object;Lgnu/classpath/Pointer;III)V"))))
226 # if SIZEOF_VOID_P == 8
227 if (!(class_gnu_classpath_Pointer64 =
228 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer64"))) ||
229 !link_class(class_gnu_classpath_Pointer64))
232 if (!(class_gnu_classpath_Pointer32 =
233 load_class_bootstrap(utf_new_char("gnu/classpath/Pointer32"))) ||
234 !link_class(class_gnu_classpath_Pointer32))
238 #endif /* defined(ENABLE_JAVASE) */
244 /* jni_init_localref_table *****************************************************
246 Initializes the local references table of the current thread.
248 *******************************************************************************/
250 bool jni_init_localref_table(void)
254 lrt = GCNEW(localref_table);
259 lrt->capacity = LOCALREFTABLE_CAPACITY;
261 lrt->localframes = 1;
262 lrt->prev = LOCALREFTABLE;
264 /* clear the references array (memset is faster then a for-loop) */
266 MSET(lrt->refs, 0, java_objectheader*, LOCALREFTABLE_CAPACITY);
274 /* _Jv_jni_CallObjectMethod ****************************************************
276 Internal function to call Java Object methods.
278 *******************************************************************************/
280 static java_objectheader *_Jv_jni_CallObjectMethod(java_objectheader *o,
282 methodinfo *m, va_list ap)
285 java_objectheader *ro;
287 STATISTICS(jniinvokation());
290 exceptions_throw_nullpointerexception();
294 /* Class initialization is done by the JIT compiler. This is ok
295 since a static method always belongs to the declaring class. */
297 if (m->flags & ACC_STATIC) {
298 /* For static methods we reset the object. */
303 /* for convenience */
308 /* For instance methods we make a virtual function table lookup. */
310 resm = method_vftbl_lookup(vftbl, m);
313 STATISTICS(jnicallXmethodnvokation());
315 ro = vm_call_method_valist(resm, o, ap);
321 /* _Jv_jni_CallObjectMethodA ***************************************************
323 Internal function to call Java Object methods.
325 *******************************************************************************/
327 static java_objectheader *_Jv_jni_CallObjectMethodA(java_objectheader *o,
333 java_objectheader *ro;
335 STATISTICS(jniinvokation());
338 exceptions_throw_nullpointerexception();
342 /* Class initialization is done by the JIT compiler. This is ok
343 since a static method always belongs to the declaring class. */
345 if (m->flags & ACC_STATIC) {
346 /* For static methods we reset the object. */
351 /* for convenience */
356 /* For instance methods we make a virtual function table lookup. */
358 resm = method_vftbl_lookup(vftbl, m);
361 STATISTICS(jnicallXmethodnvokation());
363 ro = vm_call_method_jvalue(resm, o, args);
369 /* _Jv_jni_CallIntMethod *******************************************************
371 Internal function to call Java integer class methods (boolean,
372 byte, char, short, int).
374 *******************************************************************************/
376 static jint _Jv_jni_CallIntMethod(java_objectheader *o, vftbl_t *vftbl,
377 methodinfo *m, va_list ap)
382 STATISTICS(jniinvokation());
385 exceptions_throw_nullpointerexception();
389 /* Class initialization is done by the JIT compiler. This is ok
390 since a static method always belongs to the declaring class. */
392 if (m->flags & ACC_STATIC) {
393 /* For static methods we reset the object. */
398 /* for convenience */
403 /* For instance methods we make a virtual function table lookup. */
405 resm = method_vftbl_lookup(vftbl, m);
408 STATISTICS(jnicallXmethodnvokation());
410 i = vm_call_method_int_valist(resm, o, ap);
416 /* _Jv_jni_CallIntMethodA ******************************************************
418 Internal function to call Java integer class methods (boolean,
419 byte, char, short, int).
421 *******************************************************************************/
423 static jint _Jv_jni_CallIntMethodA(java_objectheader *o, vftbl_t *vftbl,
424 methodinfo *m, const jvalue *args)
429 STATISTICS(jniinvokation());
432 exceptions_throw_nullpointerexception();
436 /* Class initialization is done by the JIT compiler. This is ok
437 since a static method always belongs to the declaring class. */
439 if (m->flags & ACC_STATIC) {
440 /* For static methods we reset the object. */
445 /* for convenience */
450 /* For instance methods we make a virtual function table lookup. */
452 resm = method_vftbl_lookup(vftbl, m);
455 STATISTICS(jnicallXmethodnvokation());
457 i = vm_call_method_int_jvalue(resm, o, args);
463 /* _Jv_jni_CallLongMethod ******************************************************
465 Internal function to call Java long methods.
467 *******************************************************************************/
469 static jlong _Jv_jni_CallLongMethod(java_objectheader *o, vftbl_t *vftbl,
470 methodinfo *m, va_list ap)
475 STATISTICS(jniinvokation());
478 exceptions_throw_nullpointerexception();
482 /* Class initialization is done by the JIT compiler. This is ok
483 since a static method always belongs to the declaring class. */
485 if (m->flags & ACC_STATIC) {
486 /* For static methods we reset the object. */
491 /* for convenience */
496 /* For instance methods we make a virtual function table lookup. */
498 resm = method_vftbl_lookup(vftbl, m);
501 STATISTICS(jnicallXmethodnvokation());
503 l = vm_call_method_long_valist(resm, o, ap);
509 /* _Jv_jni_CallLongMethodA *****************************************************
511 Internal function to call Java long methods.
513 *******************************************************************************/
515 static jlong _Jv_jni_CallLongMethodA(java_objectheader *o, vftbl_t *vftbl,
516 methodinfo *m, const jvalue *args)
521 STATISTICS(jniinvokation());
524 exceptions_throw_nullpointerexception();
528 /* Class initialization is done by the JIT compiler. This is ok
529 since a static method always belongs to the declaring class. */
531 if (m->flags & ACC_STATIC) {
532 /* For static methods we reset the object. */
537 /* for convenience */
542 /* For instance methods we make a virtual function table lookup. */
544 resm = method_vftbl_lookup(vftbl, m);
547 STATISTICS(jnicallXmethodnvokation());
549 l = vm_call_method_long_jvalue(resm, o, args);
555 /* _Jv_jni_CallFloatMethod *****************************************************
557 Internal function to call Java float methods.
559 *******************************************************************************/
561 static jfloat _Jv_jni_CallFloatMethod(java_objectheader *o, vftbl_t *vftbl,
562 methodinfo *m, va_list ap)
567 /* Class initialization is done by the JIT compiler. This is ok
568 since a static method always belongs to the declaring class. */
570 if (m->flags & ACC_STATIC) {
571 /* For static methods we reset the object. */
576 /* for convenience */
581 /* For instance methods we make a virtual function table lookup. */
583 resm = method_vftbl_lookup(vftbl, m);
586 STATISTICS(jnicallXmethodnvokation());
588 f = vm_call_method_float_valist(resm, o, ap);
594 /* _Jv_jni_CallFloatMethodA ****************************************************
596 Internal function to call Java float methods.
598 *******************************************************************************/
600 static jfloat _Jv_jni_CallFloatMethodA(java_objectheader *o, vftbl_t *vftbl,
601 methodinfo *m, const jvalue *args)
606 /* Class initialization is done by the JIT compiler. This is ok
607 since a static method always belongs to the declaring class. */
609 if (m->flags & ACC_STATIC) {
610 /* For static methods we reset the object. */
615 /* for convenience */
620 /* For instance methods we make a virtual function table lookup. */
622 resm = method_vftbl_lookup(vftbl, m);
625 STATISTICS(jnicallXmethodnvokation());
627 f = vm_call_method_float_jvalue(resm, o, args);
633 /* _Jv_jni_CallDoubleMethod ****************************************************
635 Internal function to call Java double methods.
637 *******************************************************************************/
639 static jdouble _Jv_jni_CallDoubleMethod(java_objectheader *o, vftbl_t *vftbl,
640 methodinfo *m, va_list ap)
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_valist(resm, o, ap);
670 /* _Jv_jni_CallDoubleMethodA ***************************************************
672 Internal function to call Java double methods.
674 *******************************************************************************/
676 static jdouble _Jv_jni_CallDoubleMethodA(java_objectheader *o, vftbl_t *vftbl,
677 methodinfo *m, const jvalue *args)
682 /* Class initialization is done by the JIT compiler. This is ok
683 since a static method always belongs to the declaring class. */
685 if (m->flags & ACC_STATIC) {
686 /* For static methods we reset the object. */
691 /* for convenience */
696 /* For instance methods we make a virtual function table lookup. */
698 resm = method_vftbl_lookup(vftbl, m);
701 d = vm_call_method_double_jvalue(resm, o, args);
707 /* _Jv_jni_CallVoidMethod ******************************************************
709 Internal function to call Java void methods.
711 *******************************************************************************/
713 static void _Jv_jni_CallVoidMethod(java_objectheader *o, vftbl_t *vftbl,
714 methodinfo *m, va_list ap)
719 exceptions_throw_nullpointerexception();
723 /* Class initialization is done by the JIT compiler. This is ok
724 since a static method always belongs to the declaring class. */
726 if (m->flags & ACC_STATIC) {
727 /* For static methods we reset the object. */
732 /* for convenience */
737 /* For instance methods we make a virtual function table lookup. */
739 resm = method_vftbl_lookup(vftbl, m);
742 STATISTICS(jnicallXmethodnvokation());
744 (void) vm_call_method_valist(resm, o, ap);
748 /* _Jv_jni_CallVoidMethodA *****************************************************
750 Internal function to call Java void methods.
752 *******************************************************************************/
754 static void _Jv_jni_CallVoidMethodA(java_objectheader *o, vftbl_t *vftbl,
755 methodinfo *m, const jvalue *args)
760 exceptions_throw_nullpointerexception();
764 /* Class initialization is done by the JIT compiler. This is ok
765 since a static method always belongs to the declaring class. */
767 if (m->flags & ACC_STATIC) {
768 /* For static methods we reset the object. */
773 /* for convenience */
778 /* For instance methods we make a virtual function table lookup. */
780 resm = method_vftbl_lookup(vftbl, m);
783 STATISTICS(jnicallXmethodnvokation());
785 (void) vm_call_method_jvalue(resm, o, args);
789 /* _Jv_jni_invokeNative ********************************************************
791 Invoke a method on the given object with the given arguments.
793 For instance methods OBJ must be != NULL and the method is looked up
794 in the vftbl of the object.
796 For static methods, OBJ is ignored.
798 *******************************************************************************/
800 java_objectheader *_Jv_jni_invokeNative(methodinfo *m, java_objectheader *o,
801 java_objectarray *params)
804 java_objectheader *ro;
807 java_objectheader *xptr;
813 exceptions_throw_nullpointerexception();
817 argcount = m->parseddesc->paramcount;
818 paramcount = argcount;
820 /* if method is non-static, remove the `this' pointer */
822 if (!(m->flags & ACC_STATIC))
825 /* For instance methods the object has to be an instance of the
826 class the method belongs to. For static methods the obj
827 parameter is ignored. */
829 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
830 exceptions_throw_illegalargumentexception();
834 /* check if we got the right number of arguments */
836 if (((params == NULL) && (paramcount != 0)) ||
837 (params && (params->header.size != paramcount)))
839 exceptions_throw_illegalargumentexception();
843 /* for instance methods we need an object */
845 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
846 /* XXX not sure if that is the correct exception */
847 exceptions_throw_nullpointerexception();
851 /* for static methods, zero object to make subsequent code simpler */
852 if (m->flags & ACC_STATIC)
856 /* for instance methods we must do a vftbl lookup */
857 resm = method_vftbl_lookup(o->vftbl, m);
860 /* for static methods, just for convenience */
864 /* mark start of dump memory area */
866 dumpsize = dump_size();
868 /* Fill the argument array from a object-array. */
870 array = vm_array_from_objectarray(resm, o, params);
872 /* The array can be NULL if we don't have any arguments to pass
873 and the architecture does not have any argument registers
874 (e.g. i386). In that case we additionally check for an
877 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
878 /* release dump area */
880 dump_release(dumpsize);
885 switch (resm->parseddesc->returntype.decltype) {
887 (void) vm_call_array(resm, array);
891 case PRIMITIVETYPE_BOOLEAN:
892 case PRIMITIVETYPE_BYTE:
893 case PRIMITIVETYPE_CHAR:
894 case PRIMITIVETYPE_SHORT:
895 case PRIMITIVETYPE_INT:
896 value.i = vm_call_int_array(resm, array);
897 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
900 case PRIMITIVETYPE_LONG:
901 value.l = vm_call_long_array(resm, array);
902 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
905 case PRIMITIVETYPE_FLOAT:
906 value.f = vm_call_float_array(resm, array);
907 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
910 case PRIMITIVETYPE_DOUBLE:
911 value.d = vm_call_double_array(resm, array);
912 ro = primitive_box(resm->parseddesc->returntype.decltype, value);
916 ro = vm_call_array(resm, array);
920 vm_abort("_Jv_jni_invokeNative: invalid return type %d", resm->parseddesc->returntype.decltype);
923 xptr = exceptions_get_exception();
926 /* clear exception pointer, we are calling JIT code again */
928 exceptions_clear_exception();
930 exceptions_throw_invocationtargetexception(xptr);
933 /* release dump area */
935 dump_release(dumpsize);
941 /* GetVersion ******************************************************************
943 Returns the major version number in the higher 16 bits and the
944 minor version number in the lower 16 bits.
946 *******************************************************************************/
948 jint _Jv_JNI_GetVersion(JNIEnv *env)
950 STATISTICS(jniinvokation());
952 /* we support JNI 1.4 */
954 return JNI_VERSION_1_4;
958 /* Class Operations ***********************************************************/
960 /* DefineClass *****************************************************************
962 Loads a class from a buffer of raw class data. The buffer
963 containing the raw class data is not referenced by the VM after the
964 DefineClass call returns, and it may be discarded if desired.
966 *******************************************************************************/
968 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
969 const jbyte *buf, jsize bufLen)
971 #if defined(ENABLE_JAVASE)
973 java_objectheader *cl;
976 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
978 u = utf_new_char(name);
979 cl = (java_objectheader *) loader;
981 c = class_define(u, cl, bufLen, (const uint8_t *) buf);
983 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
985 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
987 /* keep compiler happy */
994 /* FindClass *******************************************************************
996 This function loads a locally-defined class. It searches the
997 directories and zip files specified by the CLASSPATH environment
998 variable for the class with the specified name.
1000 *******************************************************************************/
1002 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1004 #if defined(ENABLE_JAVASE)
1009 STATISTICS(jniinvokation());
1011 u = utf_new_char_classname((char *) name);
1013 /* Check stacktrace for classloader, if one found use it,
1014 otherwise use the system classloader. */
1016 /* Quote from the JNI documentation:
1018 In the Java 2 Platform, FindClass locates the class loader
1019 associated with the current native method. If the native code
1020 belongs to a system class, no class loader will be
1021 involved. Otherwise, the proper class loader will be invoked to
1022 load and link the named class. When FindClass is called through
1023 the Invocation Interface, there is no current native method or
1024 its associated class loader. In that case, the result of
1025 ClassLoader.getBaseClassLoader is used." */
1027 cc = stacktrace_getCurrentClass();
1030 c = load_class_from_sysloader(u);
1032 c = load_class_from_classloader(u, cc->classloader);
1040 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1042 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1044 /* keep compiler happy */
1051 /* GetSuperclass ***************************************************************
1053 If clazz represents any class other than the class Object, then
1054 this function returns the object that represents the superclass of
1055 the class specified by clazz.
1057 *******************************************************************************/
1059 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1064 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1066 c = (classinfo *) sub;
1071 super = class_get_superclass(c);
1073 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1077 /* IsAssignableFrom ************************************************************
1079 Determines whether an object of sub can be safely cast to sup.
1081 *******************************************************************************/
1083 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1085 java_lang_Class *csup;
1086 java_lang_Class *csub;
1088 csup = (java_lang_Class *) sup;
1089 csub = (java_lang_Class *) sub;
1091 STATISTICS(jniinvokation());
1093 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1097 /* Throw ***********************************************************************
1099 Causes a java.lang.Throwable object to be thrown.
1101 *******************************************************************************/
1103 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1105 java_objectheader *o;
1107 STATISTICS(jniinvokation());
1109 o = (java_objectheader *) obj;
1111 exceptions_set_exception(o);
1117 /* ThrowNew ********************************************************************
1119 Constructs an exception object from the specified class with the
1120 message specified by message and causes that exception to be
1123 *******************************************************************************/
1125 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1128 java_objectheader *o;
1129 java_objectheader *s;
1131 STATISTICS(jniinvokation());
1133 c = (classinfo *) clazz;
1136 s = javastring_new_from_utf_string(msg);
1138 /* instantiate exception object */
1140 o = native_new_and_init_string(c, s);
1145 exceptions_set_exception(o);
1151 /* ExceptionOccurred ***********************************************************
1153 Determines if an exception is being thrown. The exception stays
1154 being thrown until either the native code calls ExceptionClear(),
1155 or the Java code handles the exception.
1157 *******************************************************************************/
1159 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1161 java_objectheader *o;
1163 STATISTICS(jniinvokation());
1165 o = exceptions_get_exception();
1167 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1171 /* ExceptionDescribe ***********************************************************
1173 Prints an exception and a backtrace of the stack to a system
1174 error-reporting channel, such as stderr. This is a convenience
1175 routine provided for debugging.
1177 *******************************************************************************/
1179 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1181 java_objectheader *o;
1184 STATISTICS(jniinvokation());
1186 o = exceptions_get_exception();
1189 /* clear exception, because we are calling jit code again */
1191 exceptions_clear_exception();
1193 /* get printStackTrace method from exception class */
1195 m = class_resolveclassmethod(o->vftbl->class,
1196 utf_printStackTrace,
1202 /* XXX what should we do? */
1205 /* print the stacktrace */
1207 (void) vm_call_method(m, o);
1212 /* ExceptionClear **************************************************************
1214 Clears any exception that is currently being thrown. If no
1215 exception is currently being thrown, this routine has no effect.
1217 *******************************************************************************/
1219 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1221 STATISTICS(jniinvokation());
1223 exceptions_clear_exception();
1227 /* FatalError ******************************************************************
1229 Raises a fatal error and does not expect the VM to recover. This
1230 function does not return.
1232 *******************************************************************************/
1234 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1236 STATISTICS(jniinvokation());
1238 /* this seems to be the best way */
1240 vm_abort("JNI Fatal error: %s", msg);
1244 /* PushLocalFrame **************************************************************
1246 Creates a new local reference frame, in which at least a given
1247 number of local references can be created.
1249 *******************************************************************************/
1251 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1254 localref_table *lrt;
1255 localref_table *nlrt;
1257 STATISTICS(jniinvokation());
1262 /* Allocate new local reference table on Java heap. Calculate the
1263 additional memory we have to allocate. */
1265 if (capacity > LOCALREFTABLE_CAPACITY)
1266 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1270 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1275 /* get current local reference table from thread */
1277 lrt = LOCALREFTABLE;
1279 /* Set up the new local reference table and add it to the local
1282 nlrt->capacity = capacity;
1284 nlrt->localframes = lrt->localframes + 1;
1287 /* store new local reference table in thread */
1289 LOCALREFTABLE = nlrt;
1295 /* PopLocalFrame ***************************************************************
1297 Pops off the current local reference frame, frees all the local
1298 references, and returns a local reference in the previous local
1299 reference frame for the given result object.
1301 *******************************************************************************/
1303 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1305 localref_table *lrt;
1306 localref_table *plrt;
1309 STATISTICS(jniinvokation());
1311 /* get current local reference table from thread */
1313 lrt = LOCALREFTABLE;
1315 localframes = lrt->localframes;
1317 /* Don't delete the top local frame, as this one is allocated in
1318 the native stub on the stack and is freed automagically on
1321 if (localframes == 1)
1322 return _Jv_JNI_NewLocalRef(env, result);
1324 /* release all current local frames */
1326 for (; localframes >= 1; localframes--) {
1327 /* get previous frame */
1331 /* clear all reference entries */
1333 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1337 /* set new local references table */
1342 /* store new local reference table in thread */
1344 LOCALREFTABLE = lrt;
1346 /* add local reference and return the value */
1348 return _Jv_JNI_NewLocalRef(env, result);
1352 /* DeleteLocalRef **************************************************************
1354 Deletes the local reference pointed to by localRef.
1356 *******************************************************************************/
1358 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1360 java_objectheader *o;
1361 localref_table *lrt;
1364 STATISTICS(jniinvokation());
1366 o = (java_objectheader *) localRef;
1368 /* get local reference table (thread specific) */
1370 lrt = LOCALREFTABLE;
1372 /* go through all local frames */
1374 for (; lrt != NULL; lrt = lrt->prev) {
1376 /* and try to remove the reference */
1378 for (i = 0; i < lrt->capacity; i++) {
1379 if (lrt->refs[i] == o) {
1380 lrt->refs[i] = NULL;
1388 /* this should not happen */
1390 /* if (opt_checkjni) */
1391 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1392 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1396 /* IsSameObject ****************************************************************
1398 Tests whether two references refer to the same Java object.
1400 *******************************************************************************/
1402 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1404 STATISTICS(jniinvokation());
1413 /* NewLocalRef *****************************************************************
1415 Creates a new local reference that refers to the same object as ref.
1417 *******************************************************************************/
1419 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1421 localref_table *lrt;
1424 STATISTICS(jniinvokation());
1429 /* get local reference table (thread specific) */
1431 lrt = LOCALREFTABLE;
1433 /* Check if we have space for the requested reference? No,
1434 allocate a new frame. This is actually not what the spec says,
1435 but for compatibility reasons... */
1437 if (lrt->used == lrt->capacity) {
1438 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1441 /* get the new local reference table */
1443 lrt = LOCALREFTABLE;
1446 /* insert the reference */
1448 for (i = 0; i < lrt->capacity; i++) {
1449 if (lrt->refs[i] == NULL) {
1450 lrt->refs[i] = (java_objectheader *) ref;
1457 /* should not happen, just to be sure */
1461 /* keep compiler happy */
1467 /* EnsureLocalCapacity *********************************************************
1469 Ensures that at least a given number of local references can be
1470 created in the current thread
1472 *******************************************************************************/
1474 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1476 localref_table *lrt;
1478 STATISTICS(jniinvokation());
1480 /* get local reference table (thread specific) */
1482 lrt = LOCALREFTABLE;
1484 /* check if capacity elements are available in the local references table */
1486 if ((lrt->used + capacity) > lrt->capacity)
1487 return _Jv_JNI_PushLocalFrame(env, capacity);
1493 /* AllocObject *****************************************************************
1495 Allocates a new Java object without invoking any of the
1496 constructors for the object. Returns a reference to the object.
1498 *******************************************************************************/
1500 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1503 java_objectheader *o;
1505 STATISTICS(jniinvokation());
1507 c = (classinfo *) clazz;
1509 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1510 exceptions_throw_instantiationexception(c);
1516 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1520 /* NewObject *******************************************************************
1522 Programmers place all arguments that are to be passed to the
1523 constructor immediately following the methodID
1524 argument. NewObject() accepts these arguments and passes them to
1525 the Java method that the programmer wishes to invoke.
1527 *******************************************************************************/
1529 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1531 java_objectheader *o;
1536 STATISTICS(jniinvokation());
1538 c = (classinfo *) clazz;
1539 m = (methodinfo *) methodID;
1548 /* call constructor */
1550 va_start(ap, methodID);
1551 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1554 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1558 /* NewObjectV ******************************************************************
1560 Programmers place all arguments that are to be passed to the
1561 constructor in an args argument of type va_list that immediately
1562 follows the methodID argument. NewObjectV() accepts these
1563 arguments, and, in turn, passes them to the Java method that the
1564 programmer wishes to invoke.
1566 *******************************************************************************/
1568 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1571 java_objectheader *o;
1575 STATISTICS(jniinvokation());
1577 c = (classinfo *) clazz;
1578 m = (methodinfo *) methodID;
1587 /* call constructor */
1589 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1591 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1595 /* NewObjectA *****************************************************************
1597 Programmers place all arguments that are to be passed to the
1598 constructor in an args array of jvalues that immediately follows
1599 the methodID argument. NewObjectA() accepts the arguments in this
1600 array, and, in turn, passes them to the Java method that the
1601 programmer wishes to invoke.
1603 *******************************************************************************/
1605 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1608 java_objectheader *o;
1612 STATISTICS(jniinvokation());
1614 c = (classinfo *) clazz;
1615 m = (methodinfo *) methodID;
1624 /* call constructor */
1626 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1628 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1632 /* GetObjectClass **************************************************************
1634 Returns the class of an object.
1636 *******************************************************************************/
1638 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1640 java_objectheader *o;
1643 STATISTICS(jniinvokation());
1645 o = (java_objectheader *) obj;
1647 if ((o == NULL) || (o->vftbl == NULL))
1650 c = o->vftbl->class;
1652 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1656 /* IsInstanceOf ****************************************************************
1658 Tests whether an object is an instance of a class.
1660 *******************************************************************************/
1662 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1665 java_lang_Object *o;
1667 STATISTICS(jniinvokation());
1669 c = (java_lang_Class *) clazz;
1670 o = (java_lang_Object *) obj;
1672 return _Jv_java_lang_Class_isInstance(c, o);
1676 /* Reflection Support *********************************************************/
1678 /* FromReflectedMethod *********************************************************
1680 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1681 object to a method ID.
1683 *******************************************************************************/
1685 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1687 #if defined(ENABLE_JAVASE)
1688 java_objectheader *o;
1693 STATISTICS(jniinvokation());
1695 o = (java_objectheader *) method;
1700 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
1701 java_lang_reflect_Method *rm;
1703 rm = (java_lang_reflect_Method *) method;
1704 LLNI_field_get_cls(rm, clazz, c);
1705 LLNI_field_get_val(rm, slot , slot);
1707 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
1708 java_lang_reflect_Constructor *rc;
1710 rc = (java_lang_reflect_Constructor *) method;
1711 LLNI_field_get_cls(rc, clazz, c);
1712 LLNI_field_get_val(rc, slot , slot);
1717 m = &(c->methods[slot]);
1719 return (jmethodID) m;
1721 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1723 /* keep compiler happy */
1730 /* FromReflectedField **********************************************************
1732 Converts a java.lang.reflect.Field to a field ID.
1734 *******************************************************************************/
1736 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1738 #if defined(ENABLE_JAVASE)
1739 java_lang_reflect_Field *rf;
1744 STATISTICS(jniinvokation());
1746 rf = (java_lang_reflect_Field *) field;
1751 LLNI_field_get_cls(rf, clazz, c);
1752 LLNI_field_get_val(rf, slot , slot);
1753 f = &(c->fields[slot]);
1755 return (jfieldID) f;
1757 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1759 /* keep compiler happy */
1766 /* ToReflectedMethod ***********************************************************
1768 Converts a method ID derived from cls to an instance of the
1769 java.lang.reflect.Method class or to an instance of the
1770 java.lang.reflect.Constructor class.
1772 *******************************************************************************/
1774 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1777 #if defined(ENABLE_JAVASE)
1779 java_lang_reflect_Constructor *rc;
1780 java_lang_reflect_Method *rm;
1782 STATISTICS(jniinvokation());
1784 m = (methodinfo *) methodID;
1786 /* HotSpot does the same assert. */
1788 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
1790 if (m->name == utf_init) {
1791 rc = reflect_constructor_new(m);
1793 return (jobject) rc;
1796 rm = reflect_method_new(m);
1798 return (jobject) rm;
1801 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
1803 /* keep compiler happy */
1810 /* ToReflectedField ************************************************************
1812 Converts a field ID derived from cls to an instance of the
1813 java.lang.reflect.Field class.
1815 *******************************************************************************/
1817 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1820 STATISTICS(jniinvokation());
1822 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1828 /* Calling Instance Methods ***************************************************/
1830 /* GetMethodID *****************************************************************
1832 Returns the method ID for an instance (nonstatic) method of a class
1833 or interface. The method may be defined in one of the clazz's
1834 superclasses and inherited by clazz. The method is determined by
1835 its name and signature.
1837 GetMethodID() causes an uninitialized class to be initialized.
1839 *******************************************************************************/
1841 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1849 STATISTICS(jniinvokation());
1851 c = (classinfo *) clazz;
1856 if (!(c->state & CLASS_INITIALIZED))
1857 if (!initialize_class(c))
1860 /* try to get the method of the class or one of it's superclasses */
1862 uname = utf_new_char((char *) name);
1863 udesc = utf_new_char((char *) sig);
1865 m = class_resolvemethod(c, uname, udesc);
1867 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1868 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1873 return (jmethodID) m;
1877 /* JNI-functions for calling instance methods *********************************/
1879 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1882 java_objectheader *o;
1884 java_objectheader *ret;
1887 o = (java_objectheader *) obj;
1888 m = (methodinfo *) methodID;
1890 va_start(ap, methodID);
1891 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1894 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1898 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
1901 java_objectheader *o;
1903 java_objectheader *ret;
1905 o = (java_objectheader *) obj;
1906 m = (methodinfo *) methodID;
1908 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
1910 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1914 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
1917 java_objectheader *o;
1919 java_objectheader *ret;
1921 o = (java_objectheader *) obj;
1922 m = (methodinfo *) methodID;
1924 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
1926 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
1930 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1933 java_objectheader *o;
1938 o = (java_objectheader *) obj;
1939 m = (methodinfo *) methodID;
1941 va_start(ap, methodID);
1942 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
1949 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
1950 jmethodID methodID, va_list args)
1952 java_objectheader *o;
1956 o = (java_objectheader *) obj;
1957 m = (methodinfo *) methodID;
1959 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
1965 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
1966 jmethodID methodID, const jvalue *args)
1968 java_objectheader *o;
1972 o = (java_objectheader *) obj;
1973 m = (methodinfo *) methodID;
1975 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
1981 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1983 java_objectheader *o;
1988 o = (java_objectheader *) obj;
1989 m = (methodinfo *) methodID;
1991 va_start(ap, methodID);
1992 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2000 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2003 java_objectheader *o;
2007 o = (java_objectheader *) obj;
2008 m = (methodinfo *) methodID;
2010 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2016 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2019 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2025 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2027 java_objectheader *o;
2032 o = (java_objectheader *) obj;
2033 m = (methodinfo *) methodID;
2035 va_start(ap, methodID);
2036 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2043 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2046 java_objectheader *o;
2050 o = (java_objectheader *) obj;
2051 m = (methodinfo *) methodID;
2053 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2059 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2062 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2068 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2071 java_objectheader *o;
2076 o = (java_objectheader *) obj;
2077 m = (methodinfo *) methodID;
2079 va_start(ap, methodID);
2080 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2087 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2090 java_objectheader *o;
2094 o = (java_objectheader *) obj;
2095 m = (methodinfo *) methodID;
2097 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2103 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2106 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2113 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2115 java_objectheader *o;
2120 o = (java_objectheader *) obj;
2121 m = (methodinfo *) methodID;
2123 va_start(ap, methodID);
2124 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2131 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2134 java_objectheader *o;
2138 o = (java_objectheader *) obj;
2139 m = (methodinfo *) methodID;
2141 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2147 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2150 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2157 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2159 java_objectheader *o;
2164 o = (java_objectheader *) obj;
2165 m = (methodinfo *) methodID;
2167 va_start(ap, methodID);
2168 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2175 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2178 java_objectheader *o;
2182 o = (java_objectheader *) obj;
2183 m = (methodinfo *) methodID;
2185 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2191 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2194 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2201 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2204 java_objectheader *o;
2209 o = (java_objectheader *) obj;
2210 m = (methodinfo *) methodID;
2212 va_start(ap, methodID);
2213 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2220 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2223 java_objectheader *o;
2227 o = (java_objectheader *) obj;
2228 m = (methodinfo *) methodID;
2230 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2236 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2239 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2246 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2249 java_objectheader *o;
2254 o = (java_objectheader *) obj;
2255 m = (methodinfo *) methodID;
2257 va_start(ap, methodID);
2258 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2265 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2268 java_objectheader *o;
2272 o = (java_objectheader *) obj;
2273 m = (methodinfo *) methodID;
2275 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2281 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2284 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2291 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2293 java_objectheader *o;
2297 o = (java_objectheader *) obj;
2298 m = (methodinfo *) methodID;
2300 va_start(ap, methodID);
2301 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2306 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2309 java_objectheader *o;
2312 o = (java_objectheader *) obj;
2313 m = (methodinfo *) methodID;
2315 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2319 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2322 java_objectheader *o;
2325 o = (java_objectheader *) obj;
2326 m = (methodinfo *) methodID;
2328 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2333 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2334 jclass clazz, jmethodID methodID,
2337 java_objectheader *o;
2340 java_objectheader *r;
2343 o = (java_objectheader *) obj;
2344 c = (classinfo *) clazz;
2345 m = (methodinfo *) methodID;
2347 va_start(ap, methodID);
2348 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2351 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2355 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2356 jclass clazz, jmethodID methodID,
2359 java_objectheader *o;
2362 java_objectheader *r;
2364 o = (java_objectheader *) obj;
2365 c = (classinfo *) clazz;
2366 m = (methodinfo *) methodID;
2368 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2370 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2374 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2375 jclass clazz, jmethodID methodID,
2378 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2380 return _Jv_JNI_NewLocalRef(env, NULL);
2385 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2386 jclass clazz, jmethodID methodID,
2389 java_objectheader *o;
2395 o = (java_objectheader *) obj;
2396 c = (classinfo *) clazz;
2397 m = (methodinfo *) methodID;
2399 va_start(ap, methodID);
2400 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2407 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2408 jclass clazz, jmethodID methodID,
2411 java_objectheader *o;
2416 o = (java_objectheader *) obj;
2417 c = (classinfo *) clazz;
2418 m = (methodinfo *) methodID;
2420 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2426 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2427 jclass clazz, jmethodID methodID,
2430 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2436 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2437 jmethodID methodID, ...)
2439 java_objectheader *o;
2445 o = (java_objectheader *) obj;
2446 c = (classinfo *) clazz;
2447 m = (methodinfo *) methodID;
2449 va_start(ap, methodID);
2450 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2457 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2458 jmethodID methodID, va_list args)
2460 java_objectheader *o;
2465 o = (java_objectheader *) obj;
2466 c = (classinfo *) clazz;
2467 m = (methodinfo *) methodID;
2469 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2475 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2476 jmethodID methodID, const jvalue *args)
2478 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2485 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2486 jmethodID methodID, ...)
2488 java_objectheader *o;
2494 o = (java_objectheader *) obj;
2495 c = (classinfo *) clazz;
2496 m = (methodinfo *) methodID;
2498 va_start(ap, methodID);
2499 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2506 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2507 jmethodID methodID, va_list args)
2509 java_objectheader *o;
2514 o = (java_objectheader *) obj;
2515 c = (classinfo *) clazz;
2516 m = (methodinfo *) methodID;
2518 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2524 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2525 jmethodID methodID, const jvalue *args)
2527 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2534 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2535 jclass clazz, jmethodID methodID, ...)
2537 java_objectheader *o;
2543 o = (java_objectheader *) obj;
2544 c = (classinfo *) clazz;
2545 m = (methodinfo *) methodID;
2547 va_start(ap, methodID);
2548 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2555 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2556 jclass clazz, jmethodID methodID,
2559 java_objectheader *o;
2564 o = (java_objectheader *) obj;
2565 c = (classinfo *) clazz;
2566 m = (methodinfo *) methodID;
2568 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2574 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2575 jclass clazz, jmethodID methodID,
2578 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2585 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2586 jmethodID methodID, ...)
2588 java_objectheader *o;
2594 o = (java_objectheader *) obj;
2595 c = (classinfo *) clazz;
2596 m = (methodinfo *) methodID;
2598 va_start(ap, methodID);
2599 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2606 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2607 jmethodID methodID, va_list args)
2609 java_objectheader *o;
2614 o = (java_objectheader *) obj;
2615 c = (classinfo *) clazz;
2616 m = (methodinfo *) methodID;
2618 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2624 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2625 jmethodID methodID, const jvalue *args)
2627 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2634 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2635 jmethodID methodID, ...)
2637 java_objectheader *o;
2643 o = (java_objectheader *) obj;
2644 c = (classinfo *) clazz;
2645 m = (methodinfo *) methodID;
2647 va_start(ap, methodID);
2648 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2655 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2656 jmethodID methodID, va_list args)
2658 java_objectheader *o;
2663 o = (java_objectheader *) obj;
2664 c = (classinfo *) clazz;
2665 m = (methodinfo *) methodID;
2667 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2673 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2674 jmethodID methodID, const jvalue *args)
2676 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2683 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2684 jclass clazz, jmethodID methodID, ...)
2686 java_objectheader *o;
2692 o = (java_objectheader *) obj;
2693 c = (classinfo *) clazz;
2694 m = (methodinfo *) methodID;
2696 va_start(ap, methodID);
2697 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2704 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2705 jclass clazz, jmethodID methodID,
2708 java_objectheader *o;
2713 o = (java_objectheader *) obj;
2714 c = (classinfo *) clazz;
2715 m = (methodinfo *) methodID;
2717 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2723 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2724 jclass clazz, jmethodID methodID,
2727 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2734 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2735 jclass clazz, jmethodID methodID,
2738 java_objectheader *o;
2744 o = (java_objectheader *) obj;
2745 c = (classinfo *) clazz;
2746 m = (methodinfo *) methodID;
2748 va_start(ap, methodID);
2749 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2756 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2757 jclass clazz, jmethodID methodID,
2760 java_objectheader *o;
2765 o = (java_objectheader *) obj;
2766 c = (classinfo *) clazz;
2767 m = (methodinfo *) methodID;
2769 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2775 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2776 jclass clazz, jmethodID methodID,
2779 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2786 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2787 jmethodID methodID, ...)
2789 java_objectheader *o;
2794 o = (java_objectheader *) obj;
2795 c = (classinfo *) clazz;
2796 m = (methodinfo *) methodID;
2798 va_start(ap, methodID);
2799 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2804 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2805 jmethodID methodID, va_list args)
2807 java_objectheader *o;
2811 o = (java_objectheader *) obj;
2812 c = (classinfo *) clazz;
2813 m = (methodinfo *) methodID;
2815 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2819 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2820 jmethodID methodID, const jvalue * args)
2822 java_objectheader *o;
2826 o = (java_objectheader *) obj;
2827 c = (classinfo *) clazz;
2828 m = (methodinfo *) methodID;
2830 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2834 /* Accessing Fields of Objects ************************************************/
2836 /* GetFieldID ******************************************************************
2838 Returns the field ID for an instance (nonstatic) field of a
2839 class. The field is specified by its name and signature. The
2840 Get<type>Field and Set<type>Field families of accessor functions
2841 use field IDs to retrieve object fields.
2843 *******************************************************************************/
2845 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2853 STATISTICS(jniinvokation());
2855 c = (classinfo *) clazz;
2857 /* XXX NPE check? */
2859 uname = utf_new_char((char *) name);
2860 udesc = utf_new_char((char *) sig);
2862 f = class_findfield(c, uname, udesc);
2865 exceptions_throw_nosuchfielderror(c, uname);
2867 return (jfieldID) f;
2871 /* Get<type>Field Routines *****************************************************
2873 This family of accessor routines returns the value of an instance
2874 (nonstatic) field of an object. The field to access is specified by
2875 a field ID obtained by calling GetFieldID().
2877 *******************************************************************************/
2879 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2881 java_objectheader *o;
2883 STATISTICS(jniinvokation());
2885 o = GET_FIELD(obj, java_objectheader*, fieldID);
2887 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2891 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2895 STATISTICS(jniinvokation());
2897 i = GET_FIELD(obj, s4, fieldID);
2899 return (jboolean) i;
2903 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
2907 STATISTICS(jniinvokation());
2909 i = GET_FIELD(obj, s4, fieldID);
2915 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
2919 STATISTICS(jniinvokation());
2921 i = GET_FIELD(obj, s4, fieldID);
2927 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
2931 STATISTICS(jniinvokation());
2933 i = GET_FIELD(obj, s4, fieldID);
2939 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
2941 java_objectheader *o;
2945 STATISTICS(jniinvokation());
2947 o = (java_objectheader *) obj;
2948 f = (fieldinfo *) fieldID;
2950 i = GET_FIELD(o, s4, f);
2956 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
2960 STATISTICS(jniinvokation());
2962 l = GET_FIELD(obj, s8, fieldID);
2968 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
2972 STATISTICS(jniinvokation());
2974 f = GET_FIELD(obj, float, fieldID);
2980 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
2984 STATISTICS(jniinvokation());
2986 d = GET_FIELD(obj, double, fieldID);
2992 /* Set<type>Field Routines *****************************************************
2994 This family of accessor routines sets the value of an instance
2995 (nonstatic) field of an object. The field to access is specified by
2996 a field ID obtained by calling GetFieldID().
2998 *******************************************************************************/
3000 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3003 STATISTICS(jniinvokation());
3005 SET_FIELD(obj, java_objectheader*, fieldID, value);
3009 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3012 STATISTICS(jniinvokation());
3014 SET_FIELD(obj, s4, fieldID, value);
3018 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3021 STATISTICS(jniinvokation());
3023 SET_FIELD(obj, s4, fieldID, value);
3027 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3030 STATISTICS(jniinvokation());
3032 SET_FIELD(obj, s4, fieldID, value);
3036 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3039 STATISTICS(jniinvokation());
3041 SET_FIELD(obj, s4, fieldID, value);
3045 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3047 STATISTICS(jniinvokation());
3049 SET_FIELD(obj, s4, fieldID, value);
3053 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3056 STATISTICS(jniinvokation());
3058 SET_FIELD(obj, s8, fieldID, value);
3062 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3065 STATISTICS(jniinvokation());
3067 SET_FIELD(obj, float, fieldID, value);
3071 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3074 STATISTICS(jniinvokation());
3076 SET_FIELD(obj, double, fieldID, value);
3080 /* Calling Static Methods *****************************************************/
3082 /* GetStaticMethodID ***********************************************************
3084 Returns the method ID for a static method of a class. The method is
3085 specified by its name and signature.
3087 GetStaticMethodID() causes an uninitialized class to be
3090 *******************************************************************************/
3092 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3100 STATISTICS(jniinvokation());
3102 c = (classinfo *) clazz;
3107 if (!(c->state & CLASS_INITIALIZED))
3108 if (!initialize_class(c))
3111 /* try to get the static method of the class */
3113 uname = utf_new_char((char *) name);
3114 udesc = utf_new_char((char *) sig);
3116 m = class_resolvemethod(c, uname, udesc);
3118 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3119 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3124 return (jmethodID) m;
3128 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3129 jmethodID methodID, ...)
3132 java_objectheader *o;
3135 m = (methodinfo *) methodID;
3137 va_start(ap, methodID);
3138 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3141 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3145 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3146 jmethodID methodID, va_list args)
3149 java_objectheader *o;
3151 m = (methodinfo *) methodID;
3153 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3155 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3159 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3160 jmethodID methodID, const jvalue *args)
3163 java_objectheader *o;
3165 m = (methodinfo *) methodID;
3167 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3169 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3173 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3174 jmethodID methodID, ...)
3180 m = (methodinfo *) methodID;
3182 va_start(ap, methodID);
3183 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3190 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3191 jmethodID methodID, va_list args)
3196 m = (methodinfo *) methodID;
3198 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3204 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3205 jmethodID methodID, const jvalue *args)
3210 m = (methodinfo *) methodID;
3212 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3218 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3219 jmethodID methodID, ...)
3225 m = (methodinfo *) methodID;
3227 va_start(ap, methodID);
3228 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3235 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3236 jmethodID methodID, va_list args)
3241 m = (methodinfo *) methodID;
3243 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3249 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3250 jmethodID methodID, const jvalue *args)
3255 m = (methodinfo *) methodID;
3257 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3263 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3264 jmethodID methodID, ...)
3270 m = (methodinfo *) methodID;
3272 va_start(ap, methodID);
3273 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3280 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3281 jmethodID methodID, va_list args)
3286 m = (methodinfo *) methodID;
3288 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3294 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3295 jmethodID methodID, const jvalue *args)
3300 m = (methodinfo *) methodID;
3302 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3308 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3309 jmethodID methodID, ...)
3315 m = (methodinfo *) methodID;
3317 va_start(ap, methodID);
3318 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3325 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3326 jmethodID methodID, va_list args)
3331 m = (methodinfo *) methodID;
3333 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3339 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3340 jmethodID methodID, const jvalue *args)
3345 m = (methodinfo *) methodID;
3347 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3353 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3360 m = (methodinfo *) methodID;
3362 va_start(ap, methodID);
3363 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3370 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3371 jmethodID methodID, va_list args)
3376 m = (methodinfo *) methodID;
3378 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3384 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3385 jmethodID methodID, const jvalue *args)
3390 m = (methodinfo *) methodID;
3392 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3398 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3399 jmethodID methodID, ...)
3405 m = (methodinfo *) methodID;
3407 va_start(ap, methodID);
3408 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3415 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3416 jmethodID methodID, va_list args)
3421 m = (methodinfo *) methodID;
3423 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3429 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3430 jmethodID methodID, const jvalue *args)
3435 m = (methodinfo *) methodID;
3437 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3444 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3445 jmethodID methodID, ...)
3451 m = (methodinfo *) methodID;
3453 va_start(ap, methodID);
3454 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3461 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3462 jmethodID methodID, va_list args)
3467 m = (methodinfo *) methodID;
3469 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3475 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3476 jmethodID methodID, const jvalue *args)
3481 m = (methodinfo *) methodID;
3483 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3489 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3490 jmethodID methodID, ...)
3496 m = (methodinfo *) methodID;
3498 va_start(ap, methodID);
3499 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3506 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3507 jmethodID methodID, va_list args)
3512 m = (methodinfo *) methodID;
3514 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3520 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3521 jmethodID methodID, const jvalue *args)
3526 m = (methodinfo *) methodID;
3528 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3534 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3535 jmethodID methodID, ...)
3540 m = (methodinfo *) methodID;
3542 va_start(ap, methodID);
3543 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3548 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3549 jmethodID methodID, va_list args)
3553 m = (methodinfo *) methodID;
3555 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3559 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3560 jmethodID methodID, const jvalue * args)
3564 m = (methodinfo *) methodID;
3566 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3570 /* Accessing Static Fields ****************************************************/
3572 /* GetStaticFieldID ************************************************************
3574 Returns the field ID for a static field of a class. The field is
3575 specified by its name and signature. The GetStatic<type>Field and
3576 SetStatic<type>Field families of accessor functions use field IDs
3577 to retrieve static fields.
3579 *******************************************************************************/
3581 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3589 STATISTICS(jniinvokation());
3591 c = (classinfo *) clazz;
3593 uname = utf_new_char((char *) name);
3594 usig = utf_new_char((char *) sig);
3596 f = class_findfield(c, uname, usig);
3599 exceptions_throw_nosuchfielderror(c, uname);
3601 return (jfieldID) f;
3605 /* GetStatic<type>Field ********************************************************
3607 This family of accessor routines returns the value of a static
3610 *******************************************************************************/
3612 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3618 STATISTICS(jniinvokation());
3620 c = (classinfo *) clazz;
3621 f = (fieldinfo *) fieldID;
3623 if (!(c->state & CLASS_INITIALIZED))
3624 if (!initialize_class(c))
3627 return _Jv_JNI_NewLocalRef(env, f->value->a);
3631 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3637 STATISTICS(jniinvokation());
3639 c = (classinfo *) clazz;
3640 f = (fieldinfo *) fieldID;
3642 if (!(c->state & CLASS_INITIALIZED))
3643 if (!initialize_class(c))
3650 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3655 STATISTICS(jniinvokation());
3657 c = (classinfo *) clazz;
3658 f = (fieldinfo *) fieldID;
3660 if (!(c->state & CLASS_INITIALIZED))
3661 if (!initialize_class(c))
3668 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3673 STATISTICS(jniinvokation());
3675 c = (classinfo *) clazz;
3676 f = (fieldinfo *) fieldID;
3678 if (!(c->state & CLASS_INITIALIZED))
3679 if (!initialize_class(c))
3686 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3691 STATISTICS(jniinvokation());
3693 c = (classinfo *) clazz;
3694 f = (fieldinfo *) fieldID;
3696 if (!(c->state & CLASS_INITIALIZED))
3697 if (!initialize_class(c))
3704 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3709 STATISTICS(jniinvokation());
3711 c = (classinfo *) clazz;
3712 f = (fieldinfo *) fieldID;
3714 if (!(c->state & CLASS_INITIALIZED))
3715 if (!initialize_class(c))
3722 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3727 STATISTICS(jniinvokation());
3729 c = (classinfo *) clazz;
3730 f = (fieldinfo *) fieldID;
3732 if (!(c->state & CLASS_INITIALIZED))
3733 if (!initialize_class(c))
3740 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3745 STATISTICS(jniinvokation());
3747 c = (classinfo *) clazz;
3748 f = (fieldinfo *) fieldID;
3750 if (!(c->state & CLASS_INITIALIZED))
3751 if (!initialize_class(c))
3758 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3764 STATISTICS(jniinvokation());
3766 c = (classinfo *) clazz;
3767 f = (fieldinfo *) fieldID;
3769 if (!(c->state & CLASS_INITIALIZED))
3770 if (!initialize_class(c))
3777 /* SetStatic<type>Field *******************************************************
3779 This family of accessor routines sets the value of a static field
3782 *******************************************************************************/
3784 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3790 STATISTICS(jniinvokation());
3792 c = (classinfo *) clazz;
3793 f = (fieldinfo *) fieldID;
3795 if (!(c->state & CLASS_INITIALIZED))
3796 if (!initialize_class(c))
3799 f->value->a = value;
3803 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3809 STATISTICS(jniinvokation());
3811 c = (classinfo *) clazz;
3812 f = (fieldinfo *) fieldID;
3814 if (!(c->state & CLASS_INITIALIZED))
3815 if (!initialize_class(c))
3818 f->value->i = value;
3822 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3828 STATISTICS(jniinvokation());
3830 c = (classinfo *) clazz;
3831 f = (fieldinfo *) fieldID;
3833 if (!(c->state & CLASS_INITIALIZED))
3834 if (!initialize_class(c))
3837 f->value->i = value;
3841 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3847 STATISTICS(jniinvokation());
3849 c = (classinfo *) clazz;
3850 f = (fieldinfo *) fieldID;
3852 if (!(c->state & CLASS_INITIALIZED))
3853 if (!initialize_class(c))
3856 f->value->i = value;
3860 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3866 STATISTICS(jniinvokation());
3868 c = (classinfo *) clazz;
3869 f = (fieldinfo *) fieldID;
3871 if (!(c->state & CLASS_INITIALIZED))
3872 if (!initialize_class(c))
3875 f->value->i = value;
3879 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3885 STATISTICS(jniinvokation());
3887 c = (classinfo *) clazz;
3888 f = (fieldinfo *) fieldID;
3890 if (!(c->state & CLASS_INITIALIZED))
3891 if (!initialize_class(c))
3894 f->value->i = value;
3898 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3904 STATISTICS(jniinvokation());
3906 c = (classinfo *) clazz;
3907 f = (fieldinfo *) fieldID;
3909 if (!(c->state & CLASS_INITIALIZED))
3910 if (!initialize_class(c))
3913 f->value->l = value;
3917 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3923 STATISTICS(jniinvokation());
3925 c = (classinfo *) clazz;
3926 f = (fieldinfo *) fieldID;
3928 if (!(c->state & CLASS_INITIALIZED))
3929 if (!initialize_class(c))
3932 f->value->f = value;
3936 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3942 STATISTICS(jniinvokation());
3944 c = (classinfo *) clazz;
3945 f = (fieldinfo *) fieldID;
3947 if (!(c->state & CLASS_INITIALIZED))
3948 if (!initialize_class(c))
3951 f->value->d = value;
3955 /* String Operations **********************************************************/
3957 /* NewString *******************************************************************
3959 Create new java.lang.String object from an array of Unicode
3962 *******************************************************************************/
3964 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
3966 java_lang_String *s;
3970 STATISTICS(jniinvokation());
3972 s = (java_lang_String *) builtin_new(class_java_lang_String);
3973 a = builtin_newarray_char(len);
3975 /* javastring or characterarray could not be created */
3976 if ((a == NULL) || (s == NULL))
3980 for (i = 0; i < len; i++)
3981 a->data[i] = buf[i];
3983 LLNI_field_set_ref(s, value , a);
3984 LLNI_field_set_val(s, offset, 0);
3985 LLNI_field_set_val(s, count , len);
3987 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
3991 static jchar emptyStringJ[]={0,0};
3993 /* GetStringLength *************************************************************
3995 Returns the length (the count of Unicode characters) of a Java
3998 *******************************************************************************/
4000 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4002 java_lang_String *s;
4005 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
4007 s = (java_lang_String *) str;
4009 LLNI_field_get_val(s, count, len);
4015 /******************** convertes javastring to u2-array ****************************/
4017 u2 *javastring_tou2(jstring so)
4019 java_lang_String *s;
4024 STATISTICS(jniinvokation());
4026 s = (java_lang_String *) so;
4031 LLNI_field_get_ref(s, value, a);
4036 /* allocate memory */
4038 stringbuffer = MNEW(u2, LLNI_field_direct(s, count) + 1);
4042 for (i = 0; i < LLNI_field_direct(s, count); i++)
4043 stringbuffer[i] = a->data[LLNI_field_direct(s, offset) + i];
4045 /* terminate string */
4047 stringbuffer[i] = '\0';
4049 return stringbuffer;
4053 /* GetStringChars **************************************************************
4055 Returns a pointer to the array of Unicode characters of the
4056 string. This pointer is valid until ReleaseStringChars() is called.
4058 *******************************************************************************/
4060 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4064 STATISTICS(jniinvokation());
4066 jc = javastring_tou2(str);
4078 return emptyStringJ;
4082 /* ReleaseStringChars **********************************************************
4084 Informs the VM that the native code no longer needs access to
4085 chars. The chars argument is a pointer obtained from string using
4088 *******************************************************************************/
4090 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4092 java_lang_String *s;
4094 STATISTICS(jniinvokation());
4096 if (chars == emptyStringJ)
4099 s = (java_lang_String *) str;
4101 MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
4105 /* NewStringUTF ****************************************************************
4107 Constructs a new java.lang.String object from an array of UTF-8
4110 *******************************************************************************/
4112 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4114 java_lang_String *s;
4116 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
4118 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4120 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4124 /****************** returns the utf8 length in bytes of a string *******************/
4126 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
4128 java_lang_String *s;
4131 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
4133 s = (java_lang_String *) string;
4135 length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
4141 /* GetStringUTFChars ***********************************************************
4143 Returns a pointer to an array of UTF-8 characters of the
4144 string. This array is valid until it is released by
4145 ReleaseStringUTFChars().
4147 *******************************************************************************/
4149 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4154 STATISTICS(jniinvokation());
4162 u = javastring_toutf((java_objectheader *) string, false);
4171 /* ReleaseStringUTFChars *******************************************************
4173 Informs the VM that the native code no longer needs access to
4174 utf. The utf argument is a pointer derived from string using
4175 GetStringUTFChars().
4177 *******************************************************************************/
4179 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4181 STATISTICS(jniinvokation());
4183 /* XXX we don't release utf chars right now, perhaps that should be done
4184 later. Since there is always one reference the garbage collector will
4189 /* Array Operations ***********************************************************/
4191 /* GetArrayLength **************************************************************
4193 Returns the number of elements in the array.
4195 *******************************************************************************/
4197 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4199 java_arrayheader *a;
4201 STATISTICS(jniinvokation());
4203 a = (java_arrayheader *) array;
4209 /* NewObjectArray **************************************************************
4211 Constructs a new array holding objects in class elementClass. All
4212 elements are initially set to initialElement.
4214 *******************************************************************************/
4216 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4217 jclass elementClass, jobject initialElement)
4220 java_objectheader *o;
4221 java_objectarray *oa;
4224 STATISTICS(jniinvokation());
4226 c = (classinfo *) elementClass;
4227 o = (java_objectheader *) initialElement;
4230 exceptions_throw_negativearraysizeexception();
4234 oa = builtin_anewarray(length, c);
4239 /* set all elements to initialElement */
4241 for (i = 0; i < length; i++)
4244 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4248 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4251 java_objectarray *oa;
4252 java_objectheader *o;
4254 STATISTICS(jniinvokation());
4256 oa = (java_objectarray *) array;
4258 if (index >= oa->header.size) {
4259 exceptions_throw_arrayindexoutofboundsexception();
4263 o = oa->data[index];
4265 return _Jv_JNI_NewLocalRef(env, (jobject) o);
4269 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4270 jsize index, jobject val)
4272 java_objectarray *oa;
4273 java_objectheader *o;
4275 STATISTICS(jniinvokation());
4277 oa = (java_objectarray *) array;
4278 o = (java_objectheader *) val;
4280 if (index >= oa->header.size) {
4281 exceptions_throw_arrayindexoutofboundsexception();
4285 /* check if the class of value is a subclass of the element class
4288 if (!builtin_canstore(oa, o))
4291 oa->data[index] = o;
4295 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4297 java_booleanarray *ba;
4299 STATISTICS(jniinvokation());
4302 exceptions_throw_negativearraysizeexception();
4306 ba = builtin_newarray_boolean(len);
4308 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4312 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4316 STATISTICS(jniinvokation());
4319 exceptions_throw_negativearraysizeexception();
4323 ba = builtin_newarray_byte(len);
4325 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4329 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4333 STATISTICS(jniinvokation());
4336 exceptions_throw_negativearraysizeexception();
4340 ca = builtin_newarray_char(len);
4342 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4346 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4348 java_shortarray *sa;
4350 STATISTICS(jniinvokation());
4353 exceptions_throw_negativearraysizeexception();
4357 sa = builtin_newarray_short(len);
4359 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4363 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4367 STATISTICS(jniinvokation());
4370 exceptions_throw_negativearraysizeexception();
4374 ia = builtin_newarray_int(len);
4376 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4380 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4384 STATISTICS(jniinvokation());
4387 exceptions_throw_negativearraysizeexception();
4391 la = builtin_newarray_long(len);
4393 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4397 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4399 java_floatarray *fa;
4401 STATISTICS(jniinvokation());
4404 exceptions_throw_negativearraysizeexception();
4408 fa = builtin_newarray_float(len);
4410 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4414 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4416 java_doublearray *da;
4418 STATISTICS(jniinvokation());
4421 exceptions_throw_negativearraysizeexception();
4425 da = builtin_newarray_double(len);
4427 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4431 /* Get<PrimitiveType>ArrayElements *********************************************
4433 A family of functions that returns the body of the primitive array.
4435 *******************************************************************************/
4437 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4440 java_booleanarray *ba;
4442 STATISTICS(jniinvokation());
4444 ba = (java_booleanarray *) array;
4447 *isCopy = JNI_FALSE;
4453 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4458 STATISTICS(jniinvokation());
4460 ba = (java_bytearray *) array;
4463 *isCopy = JNI_FALSE;
4469 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4474 STATISTICS(jniinvokation());
4476 ca = (java_chararray *) array;
4479 *isCopy = JNI_FALSE;
4485 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4488 java_shortarray *sa;
4490 STATISTICS(jniinvokation());
4492 sa = (java_shortarray *) array;
4495 *isCopy = JNI_FALSE;
4501 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4506 STATISTICS(jniinvokation());
4508 ia = (java_intarray *) array;
4511 *isCopy = JNI_FALSE;
4517 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4522 STATISTICS(jniinvokation());
4524 la = (java_longarray *) array;
4527 *isCopy = JNI_FALSE;
4529 /* We cast this one to prevent a compiler warning on 64-bit
4530 systems since GNU Classpath typedef jlong to long long. */
4532 return (jlong *) la->data;
4536 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4539 java_floatarray *fa;
4541 STATISTICS(jniinvokation());
4543 fa = (java_floatarray *) array;
4546 *isCopy = JNI_FALSE;
4552 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4555 java_doublearray *da;
4557 STATISTICS(jniinvokation());
4559 da = (java_doublearray *) array;
4562 *isCopy = JNI_FALSE;
4568 /* Release<PrimitiveType>ArrayElements *****************************************
4570 A family of functions that informs the VM that the native code no
4571 longer needs access to elems. The elems argument is a pointer
4572 derived from array using the corresponding
4573 Get<PrimitiveType>ArrayElements() function. If necessary, this
4574 function copies back all changes made to elems to the original
4577 *******************************************************************************/
4579 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4580 jboolean *elems, jint mode)
4582 java_booleanarray *ba;
4584 STATISTICS(jniinvokation());
4586 ba = (java_booleanarray *) array;
4588 if (elems != ba->data) {
4591 MCOPY(ba->data, elems, u1, ba->header.size);
4594 MCOPY(ba->data, elems, u1, ba->header.size);
4595 /* XXX TWISTI how should it be freed? */
4598 /* XXX TWISTI how should it be freed? */
4605 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4606 jbyte *elems, jint mode)
4610 STATISTICS(jniinvokation());
4612 ba = (java_bytearray *) array;
4614 if (elems != ba->data) {
4617 MCOPY(ba->data, elems, s1, ba->header.size);
4620 MCOPY(ba->data, elems, s1, ba->header.size);
4621 /* XXX TWISTI how should it be freed? */
4624 /* XXX TWISTI how should it be freed? */
4631 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4632 jchar *elems, jint mode)
4636 STATISTICS(jniinvokation());
4638 ca = (java_chararray *) array;
4640 if (elems != ca->data) {
4643 MCOPY(ca->data, elems, u2, ca->header.size);
4646 MCOPY(ca->data, elems, u2, ca->header.size);
4647 /* XXX TWISTI how should it be freed? */
4650 /* XXX TWISTI how should it be freed? */
4657 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4658 jshort *elems, jint mode)
4660 java_shortarray *sa;
4662 STATISTICS(jniinvokation());
4664 sa = (java_shortarray *) array;
4666 if (elems != sa->data) {
4669 MCOPY(sa->data, elems, s2, sa->header.size);
4672 MCOPY(sa->data, elems, s2, sa->header.size);
4673 /* XXX TWISTI how should it be freed? */
4676 /* XXX TWISTI how should it be freed? */
4683 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4688 STATISTICS(jniinvokation());
4690 ia = (java_intarray *) array;
4692 if (elems != ia->data) {
4695 MCOPY(ia->data, elems, s4, ia->header.size);
4698 MCOPY(ia->data, elems, s4, ia->header.size);
4699 /* XXX TWISTI how should it be freed? */
4702 /* XXX TWISTI how should it be freed? */
4709 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4710 jlong *elems, jint mode)
4714 STATISTICS(jniinvokation());
4716 la = (java_longarray *) array;
4718 /* We cast this one to prevent a compiler warning on 64-bit
4719 systems since GNU Classpath typedef jlong to long long. */
4721 if ((s8 *) elems != la->data) {
4724 MCOPY(la->data, elems, s8, la->header.size);
4727 MCOPY(la->data, elems, s8, la->header.size);
4728 /* XXX TWISTI how should it be freed? */
4731 /* XXX TWISTI how should it be freed? */
4738 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4739 jfloat *elems, jint mode)
4741 java_floatarray *fa;
4743 STATISTICS(jniinvokation());
4745 fa = (java_floatarray *) array;
4747 if (elems != fa->data) {
4750 MCOPY(fa->data, elems, float, fa->header.size);
4753 MCOPY(fa->data, elems, float, fa->header.size);
4754 /* XXX TWISTI how should it be freed? */
4757 /* XXX TWISTI how should it be freed? */
4764 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4765 jdouble *elems, jint mode)
4767 java_doublearray *da;
4769 STATISTICS(jniinvokation());
4771 da = (java_doublearray *) array;
4773 if (elems != da->data) {
4776 MCOPY(da->data, elems, double, da->header.size);
4779 MCOPY(da->data, elems, double, da->header.size);
4780 /* XXX TWISTI how should it be freed? */
4783 /* XXX TWISTI how should it be freed? */
4790 /* Get<PrimitiveType>ArrayRegion **********************************************
4792 A family of functions that copies a region of a primitive array
4795 *******************************************************************************/
4797 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4798 jsize start, jsize len, jboolean *buf)
4800 java_booleanarray *ba;
4802 STATISTICS(jniinvokation());
4804 ba = (java_booleanarray *) array;
4806 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4807 exceptions_throw_arrayindexoutofboundsexception();
4809 MCOPY(buf, &ba->data[start], u1, len);
4813 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4814 jsize len, jbyte *buf)
4818 STATISTICS(jniinvokation());
4820 ba = (java_bytearray *) array;
4822 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4823 exceptions_throw_arrayindexoutofboundsexception();
4825 MCOPY(buf, &ba->data[start], s1, len);
4829 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4830 jsize len, jchar *buf)
4834 STATISTICS(jniinvokation());
4836 ca = (java_chararray *) array;
4838 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4839 exceptions_throw_arrayindexoutofboundsexception();
4841 MCOPY(buf, &ca->data[start], u2, len);
4845 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4846 jsize len, jshort *buf)
4848 java_shortarray *sa;
4850 STATISTICS(jniinvokation());
4852 sa = (java_shortarray *) array;
4854 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4855 exceptions_throw_arrayindexoutofboundsexception();
4857 MCOPY(buf, &sa->data[start], s2, len);
4861 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4862 jsize len, jint *buf)
4866 STATISTICS(jniinvokation());
4868 ia = (java_intarray *) array;
4870 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4871 exceptions_throw_arrayindexoutofboundsexception();
4873 MCOPY(buf, &ia->data[start], s4, len);
4877 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4878 jsize len, jlong *buf)
4882 STATISTICS(jniinvokation());
4884 la = (java_longarray *) array;
4886 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4887 exceptions_throw_arrayindexoutofboundsexception();
4889 MCOPY(buf, &la->data[start], s8, len);
4893 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4894 jsize len, jfloat *buf)
4896 java_floatarray *fa;
4898 STATISTICS(jniinvokation());
4900 fa = (java_floatarray *) array;
4902 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
4903 exceptions_throw_arrayindexoutofboundsexception();
4905 MCOPY(buf, &fa->data[start], float, len);
4909 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
4910 jsize len, jdouble *buf)
4912 java_doublearray *da;
4914 STATISTICS(jniinvokation());
4916 da = (java_doublearray *) array;
4918 if ((start < 0) || (len < 0) || (start + len > da->header.size))
4919 exceptions_throw_arrayindexoutofboundsexception();
4921 MCOPY(buf, &da->data[start], double, len);
4925 /* Set<PrimitiveType>ArrayRegion **********************************************
4927 A family of functions that copies back a region of a primitive
4928 array from a buffer.
4930 *******************************************************************************/
4932 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4933 jsize start, jsize len, const jboolean *buf)
4935 java_booleanarray *ba;
4937 STATISTICS(jniinvokation());
4939 ba = (java_booleanarray *) array;
4941 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4942 exceptions_throw_arrayindexoutofboundsexception();
4944 MCOPY(&ba->data[start], buf, u1, len);
4948 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4949 jsize len, const jbyte *buf)
4953 STATISTICS(jniinvokation());
4955 ba = (java_bytearray *) array;
4957 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4958 exceptions_throw_arrayindexoutofboundsexception();
4960 MCOPY(&ba->data[start], buf, s1, len);
4964 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4965 jsize len, const jchar *buf)
4969 STATISTICS(jniinvokation());
4971 ca = (java_chararray *) array;
4973 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4974 exceptions_throw_arrayindexoutofboundsexception();
4976 MCOPY(&ca->data[start], buf, u2, len);
4980 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4981 jsize len, const jshort *buf)
4983 java_shortarray *sa;
4985 STATISTICS(jniinvokation());
4987 sa = (java_shortarray *) array;
4989 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4990 exceptions_throw_arrayindexoutofboundsexception();
4992 MCOPY(&sa->data[start], buf, s2, len);
4996 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4997 jsize len, const jint *buf)
5001 STATISTICS(jniinvokation());
5003 ia = (java_intarray *) array;
5005 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5006 exceptions_throw_arrayindexoutofboundsexception();
5008 MCOPY(&ia->data[start], buf, s4, len);
5012 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5013 jsize len, const jlong *buf)
5017 STATISTICS(jniinvokation());
5019 la = (java_longarray *) array;
5021 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5022 exceptions_throw_arrayindexoutofboundsexception();
5024 MCOPY(&la->data[start], buf, s8, len);
5028 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5029 jsize len, const jfloat *buf)
5031 java_floatarray *fa;
5033 STATISTICS(jniinvokation());
5035 fa = (java_floatarray *) array;
5037 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5038 exceptions_throw_arrayindexoutofboundsexception();
5040 MCOPY(&fa->data[start], buf, float, len);
5044 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5045 jsize len, const jdouble *buf)
5047 java_doublearray *da;
5049 STATISTICS(jniinvokation());
5051 da = (java_doublearray *) array;
5053 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5054 exceptions_throw_arrayindexoutofboundsexception();
5056 MCOPY(&da->data[start], buf, double, len);
5060 /* Registering Native Methods *************************************************/
5062 /* RegisterNatives *************************************************************
5064 Registers native methods with the class specified by the clazz
5065 argument. The methods parameter specifies an array of
5066 JNINativeMethod structures that contain the names, signatures, and
5067 function pointers of the native methods. The nMethods parameter
5068 specifies the number of native methods in the array.
5070 *******************************************************************************/
5072 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5073 const JNINativeMethod *methods, jint nMethods)
5077 STATISTICS(jniinvokation());
5079 c = (classinfo *) clazz;
5081 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5082 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5085 native_method_register(c->name, methods, nMethods);
5091 /* UnregisterNatives ***********************************************************
5093 Unregisters native methods of a class. The class goes back to the
5094 state before it was linked or registered with its native method
5097 This function should not be used in normal native code. Instead, it
5098 provides special programs a way to reload and relink native
5101 *******************************************************************************/
5103 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5105 STATISTICS(jniinvokation());
5107 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5109 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5115 /* Monitor Operations *********************************************************/
5117 /* MonitorEnter ****************************************************************
5119 Enters the monitor associated with the underlying Java object
5122 *******************************************************************************/
5124 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5126 STATISTICS(jniinvokation());
5129 exceptions_throw_nullpointerexception();
5133 LOCK_MONITOR_ENTER(obj);
5139 /* MonitorExit *****************************************************************
5141 The current thread must be the owner of the monitor associated with
5142 the underlying Java object referred to by obj. The thread
5143 decrements the counter indicating the number of times it has
5144 entered this monitor. If the value of the counter becomes zero, the
5145 current thread releases the monitor.
5147 *******************************************************************************/
5149 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5151 STATISTICS(jniinvokation());
5154 exceptions_throw_nullpointerexception();
5158 LOCK_MONITOR_EXIT(obj);
5164 /* JavaVM Interface ***********************************************************/
5166 /* GetJavaVM *******************************************************************
5168 Returns the Java VM interface (used in the Invocation API)
5169 associated with the current thread. The result is placed at the
5170 location pointed to by the second argument, vm.
5172 *******************************************************************************/
5174 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5176 STATISTICS(jniinvokation());
5178 *vm = (JavaVM *) _Jv_jvm;
5184 /* GetStringRegion *************************************************************
5186 Copies len number of Unicode characters beginning at offset start
5187 to the given buffer buf.
5189 Throws StringIndexOutOfBoundsException on index overflow.
5191 *******************************************************************************/
5193 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5196 java_lang_String *s;
5199 STATISTICS(jniinvokation());
5201 s = (java_lang_String *) str;
5202 LLNI_field_get_ref(s, value, ca);
5204 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
5205 (start + len > LLNI_field_direct(s, count))) {
5206 exceptions_throw_stringindexoutofboundsexception();
5210 MCOPY(buf, &ca->data[start], u2, len);
5214 /* GetStringUTFRegion **********************************************************
5216 Translates len number of Unicode characters beginning at offset
5217 start into UTF-8 format and place the result in the given buffer
5220 Throws StringIndexOutOfBoundsException on index overflow.
5222 *******************************************************************************/
5224 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5225 jsize len, char *buf)
5227 java_lang_String *s;
5231 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
5233 s = (java_lang_String *) str;
5234 LLNI_field_get_ref(s, value, ca);
5236 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
5237 (start + len > LLNI_field_direct(s, count))) {
5238 exceptions_throw_stringindexoutofboundsexception();
5242 for (i = 0; i < len; i++)
5243 buf[i] = ca->data[LLNI_field_direct(s, offset) + start + i];
5249 /* GetPrimitiveArrayCritical ***************************************************
5251 Obtain a direct pointer to array elements.
5253 *******************************************************************************/
5255 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5261 ba = (java_bytearray *) array;
5263 /* do the same as Kaffe does */
5265 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
5271 /* ReleasePrimitiveArrayCritical ***********************************************
5273 No specific documentation.
5275 *******************************************************************************/
5277 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5278 void *carray, jint mode)
5280 STATISTICS(jniinvokation());
5282 /* do the same as Kaffe does */
5284 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5289 /* GetStringCritical ***********************************************************
5291 The semantics of these two functions are similar to the existing
5292 Get/ReleaseStringChars functions.
5294 *******************************************************************************/
5296 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5299 STATISTICS(jniinvokation());
5301 return _Jv_JNI_GetStringChars(env, string, isCopy);
5305 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5306 const jchar *cstring)
5308 STATISTICS(jniinvokation());
5310 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5314 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5316 STATISTICS(jniinvokation());
5318 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5324 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5326 STATISTICS(jniinvokation());
5328 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5332 /* NewGlobalRef ****************************************************************
5334 Creates a new global reference to the object referred to by the obj
5337 *******************************************************************************/
5339 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5341 hashtable_global_ref_entry *gre;
5342 u4 key; /* hashkey */
5343 u4 slot; /* slot in hashtable */
5344 java_objectheader *o;
5346 STATISTICS(jniinvokation());
5348 o = (java_objectheader *) obj;
5350 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5352 /* normally addresses are aligned to 4, 8 or 16 bytes */
5354 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5355 slot = key & (hashtable_global_ref->size - 1);
5356 gre = hashtable_global_ref->ptr[slot];
5358 /* search external hash chain for the entry */
5362 /* global object found, increment the reference */
5366 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5371 gre = gre->hashlink; /* next element in external chain */
5374 /* global ref not found, create a new one */
5376 gre = NEW(hashtable_global_ref_entry);
5381 /* insert entry into hashtable */
5383 gre->hashlink = hashtable_global_ref->ptr[slot];
5385 hashtable_global_ref->ptr[slot] = gre;
5387 /* update number of hashtable-entries */
5389 hashtable_global_ref->entries++;
5391 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5397 /* DeleteGlobalRef *************************************************************
5399 Deletes the global reference pointed to by globalRef.
5401 *******************************************************************************/
5403 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5405 hashtable_global_ref_entry *gre;
5406 hashtable_global_ref_entry *prevgre;
5407 u4 key; /* hashkey */
5408 u4 slot; /* slot in hashtable */
5409 java_objectheader *o;
5411 STATISTICS(jniinvokation());
5413 o = (java_objectheader *) globalRef;
5415 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5417 /* normally addresses are aligned to 4, 8 or 16 bytes */
5419 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5420 slot = key & (hashtable_global_ref->size - 1);
5421 gre = hashtable_global_ref->ptr[slot];
5423 /* initialize prevgre */
5427 /* search external hash chain for the entry */
5431 /* global object found, decrement the reference count */
5435 /* if reference count is 0, remove the entry */
5437 if (gre->refs == 0) {
5438 /* special handling if it's the first in the chain */
5440 if (prevgre == NULL)
5441 hashtable_global_ref->ptr[slot] = gre->hashlink;
5443 prevgre->hashlink = gre->hashlink;
5445 FREE(gre, hashtable_global_ref_entry);
5448 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5453 prevgre = gre; /* save current pointer for removal */
5454 gre = gre->hashlink; /* next element in external chain */
5457 log_println("JNI-DeleteGlobalRef: global reference not found");
5459 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5463 /* ExceptionCheck **************************************************************
5465 Returns JNI_TRUE when there is a pending exception; otherwise,
5468 *******************************************************************************/
5470 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5472 java_objectheader *o;
5474 STATISTICS(jniinvokation());
5476 o = exceptions_get_exception();
5478 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5482 /* New JNI 1.4 functions ******************************************************/
5484 /* NewDirectByteBuffer *********************************************************
5486 Allocates and returns a direct java.nio.ByteBuffer referring to the
5487 block of memory starting at the memory address address and
5488 extending capacity bytes.
5490 *******************************************************************************/
5492 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5494 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5495 java_objectheader *nbuf;
5497 # if SIZEOF_VOID_P == 8
5498 gnu_classpath_Pointer64 *paddress;
5500 gnu_classpath_Pointer32 *paddress;
5503 STATISTICS(jniinvokation());
5505 /* alocate a gnu.classpath.Pointer{32,64} object */
5507 # if SIZEOF_VOID_P == 8
5508 if (!(paddress = (gnu_classpath_Pointer64 *)
5509 builtin_new(class_gnu_classpath_Pointer64)))
5511 if (!(paddress = (gnu_classpath_Pointer32 *)
5512 builtin_new(class_gnu_classpath_Pointer32)))
5516 /* fill gnu.classpath.Pointer{32,64} with address */
5518 LLNI_field_set_val(paddress, data, (ptrint) address);
5520 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5522 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5523 (jmethodID) dbbirw_init, NULL, paddress,
5524 (jint) capacity, (jint) capacity, (jint) 0);
5526 /* add local reference and return the value */
5528 return _Jv_JNI_NewLocalRef(env, nbuf);
5530 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5532 /* keep compiler happy */
5539 /* GetDirectBufferAddress ******************************************************
5541 Fetches and returns the starting address of the memory region
5542 referenced by the given direct java.nio.Buffer.
5544 *******************************************************************************/
5546 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5548 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5549 java_nio_DirectByteBufferImpl *nbuf;
5550 # if SIZEOF_VOID_P == 8
5551 gnu_classpath_Pointer64 *paddress;
5553 gnu_classpath_Pointer32 *paddress;
5557 STATISTICS(jniinvokation());
5559 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5562 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5564 # if SIZEOF_VOID_P == 8
5565 LLNI_field_get_ref(nbuf, address, paddress);
5566 /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
5568 LLNI_field_get_ref(nbuf, address, paddress);
5569 /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
5572 if (paddress == NULL)
5575 LLNI_field_get_val(paddress, data, address);
5576 /* this was the cast to avaoid warning: (void *) paddress->data */
5580 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5582 /* keep compiler happy */
5589 /* GetDirectBufferCapacity *****************************************************
5591 Fetches and returns the capacity in bytes of the memory region
5592 referenced by the given direct java.nio.Buffer.
5594 *******************************************************************************/
5596 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5598 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5599 java_objectheader *o;
5600 java_nio_Buffer *nbuf;
5603 STATISTICS(jniinvokation());
5605 o = (java_objectheader *) buf;
5607 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
5610 nbuf = (java_nio_Buffer *) o;
5612 LLNI_field_get_val(nbuf, cap, capacity);
5616 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5618 /* keep compiler happy */
5625 /* DestroyJavaVM ***************************************************************
5627 Unloads a Java VM and reclaims its resources. Only the main thread
5628 can unload the VM. The system waits until the main thread is only
5629 remaining user thread before it destroys the VM.
5631 *******************************************************************************/
5633 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5637 STATISTICS(jniinvokation());
5639 status = vm_destroy(vm);
5645 /* AttachCurrentThread *********************************************************
5647 Attaches the current thread to a Java VM. Returns a JNI interface
5648 pointer in the JNIEnv argument.
5650 Trying to attach a thread that is already attached is a no-op.
5652 A native thread cannot be attached simultaneously to two Java VMs.
5654 When a thread is attached to the VM, the context class loader is
5655 the bootstrap loader.
5657 *******************************************************************************/
5659 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5661 JavaVMAttachArgs *vm_aargs;
5663 #if defined(ENABLE_THREADS)
5664 if (threads_get_current_threadobject() == NULL) {
5665 vm_aargs = (JavaVMAttachArgs *) thr_args;
5667 if (vm_aargs != NULL) {
5668 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5669 (vm_aargs->version != JNI_VERSION_1_4))
5670 return JNI_EVERSION;
5673 if (!threads_attach_current_thread(vm_aargs, false))
5676 if (!jni_init_localref_table())
5687 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5689 STATISTICS(jniinvokation());
5691 return jni_attach_current_thread(p_env, thr_args, false);
5695 /* DetachCurrentThread *********************************************************
5697 Detaches the current thread from a Java VM. All Java monitors held
5698 by this thread are released. All Java threads waiting for this
5699 thread to die are notified.
5701 In JDK 1.1, the main thread cannot be detached from the VM. It must
5702 call DestroyJavaVM to unload the entire VM.
5704 In the JDK, the main thread can be detached from the VM.
5706 The main thread, which is the thread that created the Java VM,
5707 cannot be detached from the VM. Instead, the main thread must call
5708 JNI_DestroyJavaVM() to unload the entire VM.
5710 *******************************************************************************/
5712 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5714 #if defined(ENABLE_THREADS)
5715 threadobject *thread;
5717 STATISTICS(jniinvokation());
5719 thread = threads_get_current_threadobject();
5724 if (!threads_detach_thread(thread))
5732 /* GetEnv **********************************************************************
5734 If the current thread is not attached to the VM, sets *env to NULL,
5735 and returns JNI_EDETACHED. If the specified version is not
5736 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5737 sets *env to the appropriate interface, and returns JNI_OK.
5739 *******************************************************************************/
5741 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5743 STATISTICS(jniinvokation());
5745 #if defined(ENABLE_THREADS)
5746 if (threads_get_current_threadobject() == NULL) {
5749 return JNI_EDETACHED;
5753 /* check the JNI version */
5756 case JNI_VERSION_1_1:
5757 case JNI_VERSION_1_2:
5758 case JNI_VERSION_1_4:
5766 #if defined(ENABLE_JVMTI)
5767 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5768 == JVMTI_VERSION_INTERFACE_JVMTI) {
5770 *env = (void *) jvmti_new_environment();
5779 return JNI_EVERSION;
5783 /* AttachCurrentThreadAsDaemon *************************************************
5785 Same semantics as AttachCurrentThread, but the newly-created
5786 java.lang.Thread instance is a daemon.
5788 If the thread has already been attached via either
5789 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5790 simply sets the value pointed to by penv to the JNIEnv of the
5791 current thread. In this case neither AttachCurrentThread nor this
5792 routine have any effect on the daemon status of the thread.
5794 *******************************************************************************/
5796 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5798 STATISTICS(jniinvokation());
5800 return jni_attach_current_thread(penv, args, true);
5804 /* JNI invocation table *******************************************************/
5806 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
5811 _Jv_JNI_DestroyJavaVM,
5812 _Jv_JNI_AttachCurrentThread,
5813 _Jv_JNI_DetachCurrentThread,
5815 _Jv_JNI_AttachCurrentThreadAsDaemon
5819 /* JNI function table *********************************************************/
5821 struct JNINativeInterface_ _Jv_JNINativeInterface = {
5828 _Jv_JNI_DefineClass,
5830 _Jv_JNI_FromReflectedMethod,
5831 _Jv_JNI_FromReflectedField,
5832 _Jv_JNI_ToReflectedMethod,
5833 _Jv_JNI_GetSuperclass,
5834 _Jv_JNI_IsAssignableFrom,
5835 _Jv_JNI_ToReflectedField,
5839 _Jv_JNI_ExceptionOccurred,
5840 _Jv_JNI_ExceptionDescribe,
5841 _Jv_JNI_ExceptionClear,
5843 _Jv_JNI_PushLocalFrame,
5844 _Jv_JNI_PopLocalFrame,
5846 _Jv_JNI_NewGlobalRef,
5847 _Jv_JNI_DeleteGlobalRef,
5848 _Jv_JNI_DeleteLocalRef,
5849 _Jv_JNI_IsSameObject,
5850 _Jv_JNI_NewLocalRef,
5851 _Jv_JNI_EnsureLocalCapacity,
5853 _Jv_JNI_AllocObject,
5858 _Jv_JNI_GetObjectClass,
5859 _Jv_JNI_IsInstanceOf,
5861 _Jv_JNI_GetMethodID,
5863 _Jv_JNI_CallObjectMethod,
5864 _Jv_JNI_CallObjectMethodV,
5865 _Jv_JNI_CallObjectMethodA,
5866 _Jv_JNI_CallBooleanMethod,
5867 _Jv_JNI_CallBooleanMethodV,
5868 _Jv_JNI_CallBooleanMethodA,
5869 _Jv_JNI_CallByteMethod,
5870 _Jv_JNI_CallByteMethodV,
5871 _Jv_JNI_CallByteMethodA,
5872 _Jv_JNI_CallCharMethod,
5873 _Jv_JNI_CallCharMethodV,
5874 _Jv_JNI_CallCharMethodA,
5875 _Jv_JNI_CallShortMethod,
5876 _Jv_JNI_CallShortMethodV,
5877 _Jv_JNI_CallShortMethodA,
5878 _Jv_JNI_CallIntMethod,
5879 _Jv_JNI_CallIntMethodV,
5880 _Jv_JNI_CallIntMethodA,
5881 _Jv_JNI_CallLongMethod,
5882 _Jv_JNI_CallLongMethodV,
5883 _Jv_JNI_CallLongMethodA,
5884 _Jv_JNI_CallFloatMethod,
5885 _Jv_JNI_CallFloatMethodV,
5886 _Jv_JNI_CallFloatMethodA,
5887 _Jv_JNI_CallDoubleMethod,
5888 _Jv_JNI_CallDoubleMethodV,
5889 _Jv_JNI_CallDoubleMethodA,
5890 _Jv_JNI_CallVoidMethod,
5891 _Jv_JNI_CallVoidMethodV,
5892 _Jv_JNI_CallVoidMethodA,
5894 _Jv_JNI_CallNonvirtualObjectMethod,
5895 _Jv_JNI_CallNonvirtualObjectMethodV,
5896 _Jv_JNI_CallNonvirtualObjectMethodA,
5897 _Jv_JNI_CallNonvirtualBooleanMethod,
5898 _Jv_JNI_CallNonvirtualBooleanMethodV,
5899 _Jv_JNI_CallNonvirtualBooleanMethodA,
5900 _Jv_JNI_CallNonvirtualByteMethod,
5901 _Jv_JNI_CallNonvirtualByteMethodV,
5902 _Jv_JNI_CallNonvirtualByteMethodA,
5903 _Jv_JNI_CallNonvirtualCharMethod,
5904 _Jv_JNI_CallNonvirtualCharMethodV,
5905 _Jv_JNI_CallNonvirtualCharMethodA,
5906 _Jv_JNI_CallNonvirtualShortMethod,
5907 _Jv_JNI_CallNonvirtualShortMethodV,
5908 _Jv_JNI_CallNonvirtualShortMethodA,
5909 _Jv_JNI_CallNonvirtualIntMethod,
5910 _Jv_JNI_CallNonvirtualIntMethodV,
5911 _Jv_JNI_CallNonvirtualIntMethodA,
5912 _Jv_JNI_CallNonvirtualLongMethod,
5913 _Jv_JNI_CallNonvirtualLongMethodV,
5914 _Jv_JNI_CallNonvirtualLongMethodA,
5915 _Jv_JNI_CallNonvirtualFloatMethod,
5916 _Jv_JNI_CallNonvirtualFloatMethodV,
5917 _Jv_JNI_CallNonvirtualFloatMethodA,
5918 _Jv_JNI_CallNonvirtualDoubleMethod,
5919 _Jv_JNI_CallNonvirtualDoubleMethodV,
5920 _Jv_JNI_CallNonvirtualDoubleMethodA,
5921 _Jv_JNI_CallNonvirtualVoidMethod,
5922 _Jv_JNI_CallNonvirtualVoidMethodV,
5923 _Jv_JNI_CallNonvirtualVoidMethodA,
5927 _Jv_JNI_GetObjectField,
5928 _Jv_JNI_GetBooleanField,
5929 _Jv_JNI_GetByteField,
5930 _Jv_JNI_GetCharField,
5931 _Jv_JNI_GetShortField,
5932 _Jv_JNI_GetIntField,
5933 _Jv_JNI_GetLongField,
5934 _Jv_JNI_GetFloatField,
5935 _Jv_JNI_GetDoubleField,
5936 _Jv_JNI_SetObjectField,
5937 _Jv_JNI_SetBooleanField,
5938 _Jv_JNI_SetByteField,
5939 _Jv_JNI_SetCharField,
5940 _Jv_JNI_SetShortField,
5941 _Jv_JNI_SetIntField,
5942 _Jv_JNI_SetLongField,
5943 _Jv_JNI_SetFloatField,
5944 _Jv_JNI_SetDoubleField,
5946 _Jv_JNI_GetStaticMethodID,
5948 _Jv_JNI_CallStaticObjectMethod,
5949 _Jv_JNI_CallStaticObjectMethodV,
5950 _Jv_JNI_CallStaticObjectMethodA,
5951 _Jv_JNI_CallStaticBooleanMethod,
5952 _Jv_JNI_CallStaticBooleanMethodV,
5953 _Jv_JNI_CallStaticBooleanMethodA,
5954 _Jv_JNI_CallStaticByteMethod,
5955 _Jv_JNI_CallStaticByteMethodV,
5956 _Jv_JNI_CallStaticByteMethodA,
5957 _Jv_JNI_CallStaticCharMethod,
5958 _Jv_JNI_CallStaticCharMethodV,
5959 _Jv_JNI_CallStaticCharMethodA,
5960 _Jv_JNI_CallStaticShortMethod,
5961 _Jv_JNI_CallStaticShortMethodV,
5962 _Jv_JNI_CallStaticShortMethodA,
5963 _Jv_JNI_CallStaticIntMethod,
5964 _Jv_JNI_CallStaticIntMethodV,
5965 _Jv_JNI_CallStaticIntMethodA,
5966 _Jv_JNI_CallStaticLongMethod,
5967 _Jv_JNI_CallStaticLongMethodV,
5968 _Jv_JNI_CallStaticLongMethodA,
5969 _Jv_JNI_CallStaticFloatMethod,
5970 _Jv_JNI_CallStaticFloatMethodV,
5971 _Jv_JNI_CallStaticFloatMethodA,
5972 _Jv_JNI_CallStaticDoubleMethod,
5973 _Jv_JNI_CallStaticDoubleMethodV,
5974 _Jv_JNI_CallStaticDoubleMethodA,
5975 _Jv_JNI_CallStaticVoidMethod,
5976 _Jv_JNI_CallStaticVoidMethodV,
5977 _Jv_JNI_CallStaticVoidMethodA,
5979 _Jv_JNI_GetStaticFieldID,
5981 _Jv_JNI_GetStaticObjectField,
5982 _Jv_JNI_GetStaticBooleanField,
5983 _Jv_JNI_GetStaticByteField,
5984 _Jv_JNI_GetStaticCharField,
5985 _Jv_JNI_GetStaticShortField,
5986 _Jv_JNI_GetStaticIntField,
5987 _Jv_JNI_GetStaticLongField,
5988 _Jv_JNI_GetStaticFloatField,
5989 _Jv_JNI_GetStaticDoubleField,
5990 _Jv_JNI_SetStaticObjectField,
5991 _Jv_JNI_SetStaticBooleanField,
5992 _Jv_JNI_SetStaticByteField,
5993 _Jv_JNI_SetStaticCharField,
5994 _Jv_JNI_SetStaticShortField,
5995 _Jv_JNI_SetStaticIntField,
5996 _Jv_JNI_SetStaticLongField,
5997 _Jv_JNI_SetStaticFloatField,
5998 _Jv_JNI_SetStaticDoubleField,
6001 _Jv_JNI_GetStringLength,
6002 _Jv_JNI_GetStringChars,
6003 _Jv_JNI_ReleaseStringChars,
6005 _Jv_JNI_NewStringUTF,
6006 _Jv_JNI_GetStringUTFLength,
6007 _Jv_JNI_GetStringUTFChars,
6008 _Jv_JNI_ReleaseStringUTFChars,
6010 _Jv_JNI_GetArrayLength,
6012 _Jv_JNI_NewObjectArray,
6013 _Jv_JNI_GetObjectArrayElement,
6014 _Jv_JNI_SetObjectArrayElement,
6016 _Jv_JNI_NewBooleanArray,
6017 _Jv_JNI_NewByteArray,
6018 _Jv_JNI_NewCharArray,
6019 _Jv_JNI_NewShortArray,
6020 _Jv_JNI_NewIntArray,
6021 _Jv_JNI_NewLongArray,
6022 _Jv_JNI_NewFloatArray,
6023 _Jv_JNI_NewDoubleArray,
6025 _Jv_JNI_GetBooleanArrayElements,
6026 _Jv_JNI_GetByteArrayElements,
6027 _Jv_JNI_GetCharArrayElements,
6028 _Jv_JNI_GetShortArrayElements,
6029 _Jv_JNI_GetIntArrayElements,
6030 _Jv_JNI_GetLongArrayElements,
6031 _Jv_JNI_GetFloatArrayElements,
6032 _Jv_JNI_GetDoubleArrayElements,
6034 _Jv_JNI_ReleaseBooleanArrayElements,
6035 _Jv_JNI_ReleaseByteArrayElements,
6036 _Jv_JNI_ReleaseCharArrayElements,
6037 _Jv_JNI_ReleaseShortArrayElements,
6038 _Jv_JNI_ReleaseIntArrayElements,
6039 _Jv_JNI_ReleaseLongArrayElements,
6040 _Jv_JNI_ReleaseFloatArrayElements,
6041 _Jv_JNI_ReleaseDoubleArrayElements,
6043 _Jv_JNI_GetBooleanArrayRegion,
6044 _Jv_JNI_GetByteArrayRegion,
6045 _Jv_JNI_GetCharArrayRegion,
6046 _Jv_JNI_GetShortArrayRegion,
6047 _Jv_JNI_GetIntArrayRegion,
6048 _Jv_JNI_GetLongArrayRegion,
6049 _Jv_JNI_GetFloatArrayRegion,
6050 _Jv_JNI_GetDoubleArrayRegion,
6051 _Jv_JNI_SetBooleanArrayRegion,
6052 _Jv_JNI_SetByteArrayRegion,
6053 _Jv_JNI_SetCharArrayRegion,
6054 _Jv_JNI_SetShortArrayRegion,
6055 _Jv_JNI_SetIntArrayRegion,
6056 _Jv_JNI_SetLongArrayRegion,
6057 _Jv_JNI_SetFloatArrayRegion,
6058 _Jv_JNI_SetDoubleArrayRegion,
6060 _Jv_JNI_RegisterNatives,
6061 _Jv_JNI_UnregisterNatives,
6063 _Jv_JNI_MonitorEnter,
6064 _Jv_JNI_MonitorExit,
6068 /* new JNI 1.2 functions */
6070 _Jv_JNI_GetStringRegion,
6071 _Jv_JNI_GetStringUTFRegion,
6073 _Jv_JNI_GetPrimitiveArrayCritical,
6074 _Jv_JNI_ReleasePrimitiveArrayCritical,
6076 _Jv_JNI_GetStringCritical,
6077 _Jv_JNI_ReleaseStringCritical,
6079 _Jv_JNI_NewWeakGlobalRef,
6080 _Jv_JNI_DeleteWeakGlobalRef,
6082 _Jv_JNI_ExceptionCheck,
6084 /* new JNI 1.4 functions */
6086 _Jv_JNI_NewDirectByteBuffer,
6087 _Jv_JNI_GetDirectBufferAddress,
6088 _Jv_JNI_GetDirectBufferCapacity
6092 /* Invocation API Functions ***************************************************/
6094 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6096 Returns a default configuration for the Java VM.
6098 *******************************************************************************/
6100 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6102 JavaVMInitArgs *_vm_args;
6104 _vm_args = (JavaVMInitArgs *) vm_args;
6106 /* GNU classpath currently supports JNI 1.2 */
6108 switch (_vm_args->version) {
6109 case JNI_VERSION_1_1:
6110 _vm_args->version = JNI_VERSION_1_1;
6113 case JNI_VERSION_1_2:
6114 case JNI_VERSION_1_4:
6115 _vm_args->ignoreUnrecognized = JNI_FALSE;
6116 _vm_args->options = NULL;
6117 _vm_args->nOptions = 0;
6128 /* JNI_GetCreatedJavaVMs *******************************************************
6130 Returns all Java VMs that have been created. Pointers to VMs are written in
6131 the buffer vmBuf in the order they are created. At most bufLen number of
6132 entries will be written. The total number of created VMs is returned in
6135 *******************************************************************************/
6137 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6139 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
6144 /* We currently only support 1 VM running. */
6146 vmBuf[0] = (JavaVM *) _Jv_jvm;
6153 /* JNI_CreateJavaVM ************************************************************
6155 Loads and initializes a Java VM. The current thread becomes the main thread.
6156 Sets the env argument to the JNI interface pointer of the main thread.
6158 *******************************************************************************/
6160 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6162 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
6164 /* actually create the JVM */
6166 if (!vm_createjvm(p_vm, p_env, vm_args))
6174 * These are local overrides for various environment variables in Emacs.
6175 * Please do not remove this and leave it at the end of the file, where
6176 * Emacs will automagically detect them.
6177 * ---------------------------------------------------------------------
6180 * indent-tabs-mode: t
6184 * vim:noexpandtab:sw=4:ts=4: