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 8287 2007-08-10 15:10:29Z 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/resolve.h"
107 #include "vm/stringlocal.h"
110 #include "vm/jit/asmpart.h"
111 #include "vm/jit/jit.h"
112 #include "vm/jit/stacktrace.h"
114 #include "vmcore/loader.h"
115 #include "vmcore/options.h"
116 #include "vmcore/primitive.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;
812 exceptions_throw_nullpointerexception();
816 argcount = m->parseddesc->paramcount;
817 paramcount = argcount;
819 /* if method is non-static, remove the `this' pointer */
821 if (!(m->flags & ACC_STATIC))
824 /* For instance methods the object has to be an instance of the
825 class the method belongs to. For static methods the obj
826 parameter is ignored. */
828 if (!(m->flags & ACC_STATIC) && o && (!builtin_instanceof(o, m->class))) {
829 exceptions_throw_illegalargumentexception();
833 /* check if we got the right number of arguments */
835 if (((params == NULL) && (paramcount != 0)) ||
836 (params && (params->header.size != paramcount)))
838 exceptions_throw_illegalargumentexception();
842 /* for instance methods we need an object */
844 if (!(m->flags & ACC_STATIC) && (o == NULL)) {
845 /* XXX not sure if that is the correct exception */
846 exceptions_throw_nullpointerexception();
850 /* for static methods, zero object to make subsequent code simpler */
851 if (m->flags & ACC_STATIC)
855 /* for instance methods we must do a vftbl lookup */
856 resm = method_vftbl_lookup(o->vftbl, m);
859 /* for static methods, just for convenience */
863 /* mark start of dump memory area */
865 dumpsize = dump_size();
867 /* Fill the argument array from a object-array. */
869 array = vm_array_from_objectarray(resm, o, params);
871 /* The array can be NULL if we don't have any arguments to pass
872 and the architecture does not have any argument registers
873 (e.g. i386). In that case we additionally check for an
876 if ((array == NULL) && (exceptions_get_exception() != NULL)) {
877 /* release dump area */
879 dump_release(dumpsize);
884 switch (resm->parseddesc->returntype.decltype) {
886 (void) vm_call_array(resm, array);
891 case PRIMITIVETYPE_BOOLEAN: {
893 java_lang_Boolean *bo;
895 i = vm_call_int_array(resm, array);
897 ro = builtin_new(class_java_lang_Boolean);
899 /* setting the value of the object direct */
901 bo = (java_lang_Boolean *) ro;
902 LLNI_field_set_val(bo, value, i);
906 case PRIMITIVETYPE_BYTE: {
910 i = vm_call_int_array(resm, array);
912 ro = builtin_new(class_java_lang_Byte);
914 /* setting the value of the object direct */
916 bo = (java_lang_Byte *) ro;
917 LLNI_field_set_val(bo, value, i);
921 case PRIMITIVETYPE_CHAR: {
923 java_lang_Character *co;
925 i = vm_call_int_array(resm, array);
927 ro = builtin_new(class_java_lang_Character);
929 /* setting the value of the object direct */
931 co = (java_lang_Character *) ro;
932 LLNI_field_set_val(co, value, i);
936 case PRIMITIVETYPE_SHORT: {
940 i = vm_call_int_array(resm, array);
942 ro = builtin_new(class_java_lang_Short);
944 /* setting the value of the object direct */
946 so = (java_lang_Short *) ro;
947 LLNI_field_set_val(so, value, i);
951 case PRIMITIVETYPE_INT: {
953 java_lang_Integer *io;
955 i = vm_call_int_array(resm, array);
957 ro = builtin_new(class_java_lang_Integer);
959 /* setting the value of the object direct */
961 io = (java_lang_Integer *) ro;
962 LLNI_field_set_val(io, value, i);
966 case PRIMITIVETYPE_LONG: {
970 l = vm_call_long_array(resm, array);
972 ro = builtin_new(class_java_lang_Long);
974 /* setting the value of the object direct */
976 lo = (java_lang_Long *) ro;
977 LLNI_field_set_val(lo, value, l);
981 case PRIMITIVETYPE_FLOAT: {
985 f = vm_call_float_array(resm, array);
987 ro = builtin_new(class_java_lang_Float);
989 /* setting the value of the object direct */
991 fo = (java_lang_Float *) ro;
992 LLNI_field_set_val(fo, value, f);
996 case PRIMITIVETYPE_DOUBLE: {
998 java_lang_Double *_do;
1000 d = vm_call_double_array(resm, array);
1002 ro = builtin_new(class_java_lang_Double);
1004 /* setting the value of the object direct */
1006 _do = (java_lang_Double *) ro;
1007 LLNI_field_set_val(_do, value, d);
1012 ro = vm_call_array(resm, array);
1016 /* if this happens the exception has already been set by
1017 fill_callblock_from_objectarray */
1019 /* release dump area */
1021 dump_release(dumpsize);
1026 xptr = exceptions_get_exception();
1029 /* clear exception pointer, we are calling JIT code again */
1031 exceptions_clear_exception();
1033 exceptions_throw_invocationtargetexception(xptr);
1036 /* release dump area */
1038 dump_release(dumpsize);
1044 /* GetVersion ******************************************************************
1046 Returns the major version number in the higher 16 bits and the
1047 minor version number in the lower 16 bits.
1049 *******************************************************************************/
1051 jint _Jv_JNI_GetVersion(JNIEnv *env)
1053 STATISTICS(jniinvokation());
1055 /* we support JNI 1.4 */
1057 return JNI_VERSION_1_4;
1061 /* Class Operations ***********************************************************/
1063 /* DefineClass *****************************************************************
1065 Loads a class from a buffer of raw class data. The buffer
1066 containing the raw class data is not referenced by the VM after the
1067 DefineClass call returns, and it may be discarded if desired.
1069 *******************************************************************************/
1071 jclass _Jv_JNI_DefineClass(JNIEnv *env, const char *name, jobject loader,
1072 const jbyte *buf, jsize bufLen)
1074 #if defined(ENABLE_JAVASE)
1076 java_objectheader *cl;
1079 TRACEJNICALLS("_Jv_JNI_DefineClass(env=%p, name=%s, loader=%p, buf=%p, bufLen=%d", env, name, loader, buf, bufLen);
1081 u = utf_new_char(name);
1082 cl = (java_objectheader *) loader;
1084 c = class_define(u, cl, bufLen, (const uint8_t *) buf);
1086 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1088 vm_abort("_Jv_JNI_DefineClass: not implemented in this configuration");
1090 /* keep compiler happy */
1097 /* FindClass *******************************************************************
1099 This function loads a locally-defined class. It searches the
1100 directories and zip files specified by the CLASSPATH environment
1101 variable for the class with the specified name.
1103 *******************************************************************************/
1105 jclass _Jv_JNI_FindClass(JNIEnv *env, const char *name)
1107 #if defined(ENABLE_JAVASE)
1112 STATISTICS(jniinvokation());
1114 u = utf_new_char_classname((char *) name);
1116 /* Check stacktrace for classloader, if one found use it,
1117 otherwise use the system classloader. */
1119 /* Quote from the JNI documentation:
1121 In the Java 2 Platform, FindClass locates the class loader
1122 associated with the current native method. If the native code
1123 belongs to a system class, no class loader will be
1124 involved. Otherwise, the proper class loader will be invoked to
1125 load and link the named class. When FindClass is called through
1126 the Invocation Interface, there is no current native method or
1127 its associated class loader. In that case, the result of
1128 ClassLoader.getBaseClassLoader is used." */
1130 cc = stacktrace_getCurrentClass();
1133 c = load_class_from_sysloader(u);
1135 c = load_class_from_classloader(u, cc->classloader);
1143 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1145 vm_abort("_Jv_JNI_FindClass: not implemented in this configuration");
1147 /* keep compiler happy */
1154 /* GetSuperclass ***************************************************************
1156 If clazz represents any class other than the class Object, then
1157 this function returns the object that represents the superclass of
1158 the class specified by clazz.
1160 *******************************************************************************/
1162 jclass _Jv_JNI_GetSuperclass(JNIEnv *env, jclass sub)
1167 TRACEJNICALLS("_Jv_JNI_GetSuperclass(env=%p, sub=%p)", env, sub);
1169 c = (classinfo *) sub;
1174 super = class_get_superclass(c);
1176 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) super);
1180 /* IsAssignableFrom ************************************************************
1182 Determines whether an object of sub can be safely cast to sup.
1184 *******************************************************************************/
1186 jboolean _Jv_JNI_IsAssignableFrom(JNIEnv *env, jclass sub, jclass sup)
1188 java_lang_Class *csup;
1189 java_lang_Class *csub;
1191 csup = (java_lang_Class *) sup;
1192 csub = (java_lang_Class *) sub;
1194 STATISTICS(jniinvokation());
1196 return _Jv_java_lang_Class_isAssignableFrom(csup, csub);
1200 /* Throw ***********************************************************************
1202 Causes a java.lang.Throwable object to be thrown.
1204 *******************************************************************************/
1206 jint _Jv_JNI_Throw(JNIEnv *env, jthrowable obj)
1208 java_objectheader *o;
1210 STATISTICS(jniinvokation());
1212 o = (java_objectheader *) obj;
1214 exceptions_set_exception(o);
1220 /* ThrowNew ********************************************************************
1222 Constructs an exception object from the specified class with the
1223 message specified by message and causes that exception to be
1226 *******************************************************************************/
1228 jint _Jv_JNI_ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
1231 java_objectheader *o;
1232 java_objectheader *s;
1234 STATISTICS(jniinvokation());
1236 c = (classinfo *) clazz;
1239 s = javastring_new_from_utf_string(msg);
1241 /* instantiate exception object */
1243 o = native_new_and_init_string(c, s);
1248 exceptions_set_exception(o);
1254 /* ExceptionOccurred ***********************************************************
1256 Determines if an exception is being thrown. The exception stays
1257 being thrown until either the native code calls ExceptionClear(),
1258 or the Java code handles the exception.
1260 *******************************************************************************/
1262 jthrowable _Jv_JNI_ExceptionOccurred(JNIEnv *env)
1264 java_objectheader *o;
1266 STATISTICS(jniinvokation());
1268 o = exceptions_get_exception();
1270 return _Jv_JNI_NewLocalRef(env, (jthrowable) o);
1274 /* ExceptionDescribe ***********************************************************
1276 Prints an exception and a backtrace of the stack to a system
1277 error-reporting channel, such as stderr. This is a convenience
1278 routine provided for debugging.
1280 *******************************************************************************/
1282 void _Jv_JNI_ExceptionDescribe(JNIEnv *env)
1284 java_objectheader *o;
1287 STATISTICS(jniinvokation());
1289 o = exceptions_get_exception();
1292 /* clear exception, because we are calling jit code again */
1294 exceptions_clear_exception();
1296 /* get printStackTrace method from exception class */
1298 m = class_resolveclassmethod(o->vftbl->class,
1299 utf_printStackTrace,
1305 /* XXX what should we do? */
1308 /* print the stacktrace */
1310 (void) vm_call_method(m, o);
1315 /* ExceptionClear **************************************************************
1317 Clears any exception that is currently being thrown. If no
1318 exception is currently being thrown, this routine has no effect.
1320 *******************************************************************************/
1322 void _Jv_JNI_ExceptionClear(JNIEnv *env)
1324 STATISTICS(jniinvokation());
1326 exceptions_clear_exception();
1330 /* FatalError ******************************************************************
1332 Raises a fatal error and does not expect the VM to recover. This
1333 function does not return.
1335 *******************************************************************************/
1337 void _Jv_JNI_FatalError(JNIEnv *env, const char *msg)
1339 STATISTICS(jniinvokation());
1341 /* this seems to be the best way */
1343 vm_abort("JNI Fatal error: %s", msg);
1347 /* PushLocalFrame **************************************************************
1349 Creates a new local reference frame, in which at least a given
1350 number of local references can be created.
1352 *******************************************************************************/
1354 jint _Jv_JNI_PushLocalFrame(JNIEnv* env, jint capacity)
1357 localref_table *lrt;
1358 localref_table *nlrt;
1360 STATISTICS(jniinvokation());
1365 /* Allocate new local reference table on Java heap. Calculate the
1366 additional memory we have to allocate. */
1368 if (capacity > LOCALREFTABLE_CAPACITY)
1369 additionalrefs = capacity - LOCALREFTABLE_CAPACITY;
1373 nlrt = GCMNEW(u1, sizeof(localref_table) + additionalrefs * SIZEOF_VOID_P);
1378 /* get current local reference table from thread */
1380 lrt = LOCALREFTABLE;
1382 /* Set up the new local reference table and add it to the local
1385 nlrt->capacity = capacity;
1387 nlrt->localframes = lrt->localframes + 1;
1390 /* store new local reference table in thread */
1392 LOCALREFTABLE = nlrt;
1398 /* PopLocalFrame ***************************************************************
1400 Pops off the current local reference frame, frees all the local
1401 references, and returns a local reference in the previous local
1402 reference frame for the given result object.
1404 *******************************************************************************/
1406 jobject _Jv_JNI_PopLocalFrame(JNIEnv* env, jobject result)
1408 localref_table *lrt;
1409 localref_table *plrt;
1412 STATISTICS(jniinvokation());
1414 /* get current local reference table from thread */
1416 lrt = LOCALREFTABLE;
1418 localframes = lrt->localframes;
1420 /* Don't delete the top local frame, as this one is allocated in
1421 the native stub on the stack and is freed automagically on
1424 if (localframes == 1)
1425 return _Jv_JNI_NewLocalRef(env, result);
1427 /* release all current local frames */
1429 for (; localframes >= 1; localframes--) {
1430 /* get previous frame */
1434 /* clear all reference entries */
1436 MSET(&lrt->refs[0], 0, java_objectheader*, lrt->capacity);
1440 /* set new local references table */
1445 /* store new local reference table in thread */
1447 LOCALREFTABLE = lrt;
1449 /* add local reference and return the value */
1451 return _Jv_JNI_NewLocalRef(env, result);
1455 /* DeleteLocalRef **************************************************************
1457 Deletes the local reference pointed to by localRef.
1459 *******************************************************************************/
1461 void _Jv_JNI_DeleteLocalRef(JNIEnv *env, jobject localRef)
1463 java_objectheader *o;
1464 localref_table *lrt;
1467 STATISTICS(jniinvokation());
1469 o = (java_objectheader *) localRef;
1471 /* get local reference table (thread specific) */
1473 lrt = LOCALREFTABLE;
1475 /* go through all local frames */
1477 for (; lrt != NULL; lrt = lrt->prev) {
1479 /* and try to remove the reference */
1481 for (i = 0; i < lrt->capacity; i++) {
1482 if (lrt->refs[i] == o) {
1483 lrt->refs[i] = NULL;
1491 /* this should not happen */
1493 /* if (opt_checkjni) */
1494 /* FatalError(env, "Bad global or local ref passed to JNI"); */
1495 log_text("JNI-DeleteLocalRef: Local ref passed to JNI not found");
1499 /* IsSameObject ****************************************************************
1501 Tests whether two references refer to the same Java object.
1503 *******************************************************************************/
1505 jboolean _Jv_JNI_IsSameObject(JNIEnv *env, jobject ref1, jobject ref2)
1507 STATISTICS(jniinvokation());
1516 /* NewLocalRef *****************************************************************
1518 Creates a new local reference that refers to the same object as ref.
1520 *******************************************************************************/
1522 jobject _Jv_JNI_NewLocalRef(JNIEnv *env, jobject ref)
1524 localref_table *lrt;
1527 STATISTICS(jniinvokation());
1532 /* get local reference table (thread specific) */
1534 lrt = LOCALREFTABLE;
1536 /* Check if we have space for the requested reference? No,
1537 allocate a new frame. This is actually not what the spec says,
1538 but for compatibility reasons... */
1540 if (lrt->used == lrt->capacity) {
1541 if (_Jv_JNI_EnsureLocalCapacity(env, 16) != 0)
1544 /* get the new local reference table */
1546 lrt = LOCALREFTABLE;
1549 /* insert the reference */
1551 for (i = 0; i < lrt->capacity; i++) {
1552 if (lrt->refs[i] == NULL) {
1553 lrt->refs[i] = (java_objectheader *) ref;
1560 /* should not happen, just to be sure */
1564 /* keep compiler happy */
1570 /* EnsureLocalCapacity *********************************************************
1572 Ensures that at least a given number of local references can be
1573 created in the current thread
1575 *******************************************************************************/
1577 jint _Jv_JNI_EnsureLocalCapacity(JNIEnv* env, jint capacity)
1579 localref_table *lrt;
1581 STATISTICS(jniinvokation());
1583 /* get local reference table (thread specific) */
1585 lrt = LOCALREFTABLE;
1587 /* check if capacity elements are available in the local references table */
1589 if ((lrt->used + capacity) > lrt->capacity)
1590 return _Jv_JNI_PushLocalFrame(env, capacity);
1596 /* AllocObject *****************************************************************
1598 Allocates a new Java object without invoking any of the
1599 constructors for the object. Returns a reference to the object.
1601 *******************************************************************************/
1603 jobject _Jv_JNI_AllocObject(JNIEnv *env, jclass clazz)
1606 java_objectheader *o;
1608 STATISTICS(jniinvokation());
1610 c = (classinfo *) clazz;
1612 if ((c->flags & ACC_INTERFACE) || (c->flags & ACC_ABSTRACT)) {
1613 exceptions_throw_instantiationexception(c);
1619 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1623 /* NewObject *******************************************************************
1625 Programmers place all arguments that are to be passed to the
1626 constructor immediately following the methodID
1627 argument. NewObject() accepts these arguments and passes them to
1628 the Java method that the programmer wishes to invoke.
1630 *******************************************************************************/
1632 jobject _Jv_JNI_NewObject(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1634 java_objectheader *o;
1639 STATISTICS(jniinvokation());
1641 c = (classinfo *) clazz;
1642 m = (methodinfo *) methodID;
1651 /* call constructor */
1653 va_start(ap, methodID);
1654 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
1657 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1661 /* NewObjectV ******************************************************************
1663 Programmers place all arguments that are to be passed to the
1664 constructor in an args argument of type va_list that immediately
1665 follows the methodID argument. NewObjectV() accepts these
1666 arguments, and, in turn, passes them to the Java method that the
1667 programmer wishes to invoke.
1669 *******************************************************************************/
1671 jobject _Jv_JNI_NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID,
1674 java_objectheader *o;
1678 STATISTICS(jniinvokation());
1680 c = (classinfo *) clazz;
1681 m = (methodinfo *) methodID;
1690 /* call constructor */
1692 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
1694 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1698 /* NewObjectA *****************************************************************
1700 Programmers place all arguments that are to be passed to the
1701 constructor in an args array of jvalues that immediately follows
1702 the methodID argument. NewObjectA() accepts the arguments in this
1703 array, and, in turn, passes them to the Java method that the
1704 programmer wishes to invoke.
1706 *******************************************************************************/
1708 jobject _Jv_JNI_NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID,
1711 java_objectheader *o;
1715 STATISTICS(jniinvokation());
1717 c = (classinfo *) clazz;
1718 m = (methodinfo *) methodID;
1727 /* call constructor */
1729 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
1731 return _Jv_JNI_NewLocalRef(env, (jobject) o);
1735 /* GetObjectClass **************************************************************
1737 Returns the class of an object.
1739 *******************************************************************************/
1741 jclass _Jv_JNI_GetObjectClass(JNIEnv *env, jobject obj)
1743 java_objectheader *o;
1746 STATISTICS(jniinvokation());
1748 o = (java_objectheader *) obj;
1750 if ((o == NULL) || (o->vftbl == NULL))
1753 c = o->vftbl->class;
1755 return (jclass) _Jv_JNI_NewLocalRef(env, (jobject) c);
1759 /* IsInstanceOf ****************************************************************
1761 Tests whether an object is an instance of a class.
1763 *******************************************************************************/
1765 jboolean _Jv_JNI_IsInstanceOf(JNIEnv *env, jobject obj, jclass clazz)
1768 java_lang_Object *o;
1770 STATISTICS(jniinvokation());
1772 c = (java_lang_Class *) clazz;
1773 o = (java_lang_Object *) obj;
1775 return _Jv_java_lang_Class_isInstance(c, o);
1779 /* Reflection Support *********************************************************/
1781 /* FromReflectedMethod *********************************************************
1783 Converts java.lang.reflect.Method or java.lang.reflect.Constructor
1784 object to a method ID.
1786 *******************************************************************************/
1788 jmethodID _Jv_JNI_FromReflectedMethod(JNIEnv *env, jobject method)
1790 #if defined(ENABLE_JAVASE)
1791 java_objectheader *o;
1796 STATISTICS(jniinvokation());
1798 o = (java_objectheader *) method;
1803 if (builtin_instanceof(o, class_java_lang_reflect_Method)) {
1804 java_lang_reflect_Method *rm;
1806 rm = (java_lang_reflect_Method *) method;
1807 LLNI_field_get_cls(rm, clazz, c);
1808 LLNI_field_get_val(rm, slot , slot);
1810 else if (builtin_instanceof(o, class_java_lang_reflect_Constructor)) {
1811 java_lang_reflect_Constructor *rc;
1813 rc = (java_lang_reflect_Constructor *) method;
1814 LLNI_field_get_cls(rc, clazz, c);
1815 LLNI_field_get_val(rc, slot , slot);
1820 m = &(c->methods[slot]);
1822 return (jmethodID) m;
1824 vm_abort("_Jv_JNI_FromReflectedMethod: not implemented in this configuration");
1826 /* keep compiler happy */
1833 /* FromReflectedField **********************************************************
1835 Converts a java.lang.reflect.Field to a field ID.
1837 *******************************************************************************/
1839 jfieldID _Jv_JNI_FromReflectedField(JNIEnv* env, jobject field)
1841 #if defined(ENABLE_JAVASE)
1842 java_lang_reflect_Field *rf;
1847 STATISTICS(jniinvokation());
1849 rf = (java_lang_reflect_Field *) field;
1854 LLNI_field_get_cls(rf, clazz, c);
1855 LLNI_field_get_val(rf, slot , slot);
1856 f = &(c->fields[slot]);
1858 return (jfieldID) f;
1860 vm_abort("_Jv_JNI_FromReflectedField: not implemented in this configuration");
1862 /* keep compiler happy */
1869 /* ToReflectedMethod ***********************************************************
1871 Converts a method ID derived from cls to an instance of the
1872 java.lang.reflect.Method class or to an instance of the
1873 java.lang.reflect.Constructor class.
1875 *******************************************************************************/
1877 jobject _Jv_JNI_ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID,
1880 #if defined(ENABLE_JAVASE)
1882 java_lang_reflect_Constructor *rc;
1883 java_lang_reflect_Method *rm;
1885 STATISTICS(jniinvokation());
1887 m = (methodinfo *) methodID;
1889 /* HotSpot does the same assert. */
1891 assert(((m->flags & ACC_STATIC) != 0) == (isStatic != 0));
1893 if (m->name == utf_init) {
1894 rc = reflect_constructor_new(m);
1896 return (jobject) rc;
1899 rm = reflect_method_new(m);
1901 return (jobject) rm;
1904 vm_abort("_Jv_JNI_ToReflectedMethod: not implemented in this configuration");
1906 /* keep compiler happy */
1913 /* ToReflectedField ************************************************************
1915 Converts a field ID derived from cls to an instance of the
1916 java.lang.reflect.Field class.
1918 *******************************************************************************/
1920 jobject _Jv_JNI_ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID,
1923 STATISTICS(jniinvokation());
1925 log_text("JNI-Call: ToReflectedField: IMPLEMENT ME!");
1931 /* Calling Instance Methods ***************************************************/
1933 /* GetMethodID *****************************************************************
1935 Returns the method ID for an instance (nonstatic) method of a class
1936 or interface. The method may be defined in one of the clazz's
1937 superclasses and inherited by clazz. The method is determined by
1938 its name and signature.
1940 GetMethodID() causes an uninitialized class to be initialized.
1942 *******************************************************************************/
1944 jmethodID _Jv_JNI_GetMethodID(JNIEnv* env, jclass clazz, const char *name,
1952 STATISTICS(jniinvokation());
1954 c = (classinfo *) clazz;
1959 if (!(c->state & CLASS_INITIALIZED))
1960 if (!initialize_class(c))
1963 /* try to get the method of the class or one of it's superclasses */
1965 uname = utf_new_char((char *) name);
1966 udesc = utf_new_char((char *) sig);
1968 m = class_resolvemethod(c, uname, udesc);
1970 if ((m == NULL) || (m->flags & ACC_STATIC)) {
1971 exceptions_throw_nosuchmethoderror(c, uname, udesc);
1976 return (jmethodID) m;
1980 /* JNI-functions for calling instance methods *********************************/
1982 jobject _Jv_JNI_CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID,
1985 java_objectheader *o;
1987 java_objectheader *ret;
1990 o = (java_objectheader *) obj;
1991 m = (methodinfo *) methodID;
1993 va_start(ap, methodID);
1994 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, ap);
1997 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2001 jobject _Jv_JNI_CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2004 java_objectheader *o;
2006 java_objectheader *ret;
2008 o = (java_objectheader *) obj;
2009 m = (methodinfo *) methodID;
2011 ret = _Jv_jni_CallObjectMethod(o, o->vftbl, m, args);
2013 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2017 jobject _Jv_JNI_CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2020 java_objectheader *o;
2022 java_objectheader *ret;
2024 o = (java_objectheader *) obj;
2025 m = (methodinfo *) methodID;
2027 ret = _Jv_jni_CallObjectMethodA(o, o->vftbl, m, args);
2029 return _Jv_JNI_NewLocalRef(env, (jobject) ret);
2033 jboolean _Jv_JNI_CallBooleanMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2036 java_objectheader *o;
2041 o = (java_objectheader *) obj;
2042 m = (methodinfo *) methodID;
2044 va_start(ap, methodID);
2045 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2052 jboolean _Jv_JNI_CallBooleanMethodV(JNIEnv *env, jobject obj,
2053 jmethodID methodID, va_list args)
2055 java_objectheader *o;
2059 o = (java_objectheader *) obj;
2060 m = (methodinfo *) methodID;
2062 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2068 jboolean _Jv_JNI_CallBooleanMethodA(JNIEnv *env, jobject obj,
2069 jmethodID methodID, const jvalue *args)
2071 java_objectheader *o;
2075 o = (java_objectheader *) obj;
2076 m = (methodinfo *) methodID;
2078 b = _Jv_jni_CallIntMethodA(o, o->vftbl, m, args);
2084 jbyte _Jv_JNI_CallByteMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2086 java_objectheader *o;
2091 o = (java_objectheader *) obj;
2092 m = (methodinfo *) methodID;
2094 va_start(ap, methodID);
2095 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2103 jbyte _Jv_JNI_CallByteMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2106 java_objectheader *o;
2110 o = (java_objectheader *) obj;
2111 m = (methodinfo *) methodID;
2113 b = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2119 jbyte _Jv_JNI_CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2122 log_text("JNI-Call: CallByteMethodA: IMPLEMENT ME!");
2128 jchar _Jv_JNI_CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2130 java_objectheader *o;
2135 o = (java_objectheader *) obj;
2136 m = (methodinfo *) methodID;
2138 va_start(ap, methodID);
2139 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2146 jchar _Jv_JNI_CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2149 java_objectheader *o;
2153 o = (java_objectheader *) obj;
2154 m = (methodinfo *) methodID;
2156 c = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2162 jchar _Jv_JNI_CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2165 log_text("JNI-Call: CallCharMethodA: IMPLEMENT ME!");
2171 jshort _Jv_JNI_CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2174 java_objectheader *o;
2179 o = (java_objectheader *) obj;
2180 m = (methodinfo *) methodID;
2182 va_start(ap, methodID);
2183 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2190 jshort _Jv_JNI_CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2193 java_objectheader *o;
2197 o = (java_objectheader *) obj;
2198 m = (methodinfo *) methodID;
2200 s = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2206 jshort _Jv_JNI_CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2209 log_text("JNI-Call: CallShortMethodA: IMPLEMENT ME!");
2216 jint _Jv_JNI_CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2218 java_objectheader *o;
2223 o = (java_objectheader *) obj;
2224 m = (methodinfo *) methodID;
2226 va_start(ap, methodID);
2227 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, ap);
2234 jint _Jv_JNI_CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2237 java_objectheader *o;
2241 o = (java_objectheader *) obj;
2242 m = (methodinfo *) methodID;
2244 i = _Jv_jni_CallIntMethod(o, o->vftbl, m, args);
2250 jint _Jv_JNI_CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2253 log_text("JNI-Call: CallIntMethodA: IMPLEMENT ME!");
2260 jlong _Jv_JNI_CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2262 java_objectheader *o;
2267 o = (java_objectheader *) obj;
2268 m = (methodinfo *) methodID;
2270 va_start(ap, methodID);
2271 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, ap);
2278 jlong _Jv_JNI_CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2281 java_objectheader *o;
2285 o = (java_objectheader *) obj;
2286 m = (methodinfo *) methodID;
2288 l = _Jv_jni_CallLongMethod(o, o->vftbl, m, args);
2294 jlong _Jv_JNI_CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2297 log_text("JNI-Call: CallLongMethodA: IMPLEMENT ME!");
2304 jfloat _Jv_JNI_CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2307 java_objectheader *o;
2312 o = (java_objectheader *) obj;
2313 m = (methodinfo *) methodID;
2315 va_start(ap, methodID);
2316 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, ap);
2323 jfloat _Jv_JNI_CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2326 java_objectheader *o;
2330 o = (java_objectheader *) obj;
2331 m = (methodinfo *) methodID;
2333 f = _Jv_jni_CallFloatMethod(o, o->vftbl, m, args);
2339 jfloat _Jv_JNI_CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2342 log_text("JNI-Call: CallFloatMethodA: IMPLEMENT ME!");
2349 jdouble _Jv_JNI_CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID,
2352 java_objectheader *o;
2357 o = (java_objectheader *) obj;
2358 m = (methodinfo *) methodID;
2360 va_start(ap, methodID);
2361 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, ap);
2368 jdouble _Jv_JNI_CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2371 java_objectheader *o;
2375 o = (java_objectheader *) obj;
2376 m = (methodinfo *) methodID;
2378 d = _Jv_jni_CallDoubleMethod(o, o->vftbl, m, args);
2384 jdouble _Jv_JNI_CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2387 log_text("JNI-Call: CallDoubleMethodA: IMPLEMENT ME!");
2394 void _Jv_JNI_CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
2396 java_objectheader *o;
2400 o = (java_objectheader *) obj;
2401 m = (methodinfo *) methodID;
2403 va_start(ap, methodID);
2404 _Jv_jni_CallVoidMethod(o, o->vftbl, m, ap);
2409 void _Jv_JNI_CallVoidMethodV(JNIEnv *env, jobject obj, jmethodID methodID,
2412 java_objectheader *o;
2415 o = (java_objectheader *) obj;
2416 m = (methodinfo *) methodID;
2418 _Jv_jni_CallVoidMethod(o, o->vftbl, m, args);
2422 void _Jv_JNI_CallVoidMethodA(JNIEnv *env, jobject obj, jmethodID methodID,
2425 java_objectheader *o;
2428 o = (java_objectheader *) obj;
2429 m = (methodinfo *) methodID;
2431 _Jv_jni_CallVoidMethodA(o, o->vftbl, m, args);
2436 jobject _Jv_JNI_CallNonvirtualObjectMethod(JNIEnv *env, jobject obj,
2437 jclass clazz, jmethodID methodID,
2440 java_objectheader *o;
2443 java_objectheader *r;
2446 o = (java_objectheader *) obj;
2447 c = (classinfo *) clazz;
2448 m = (methodinfo *) methodID;
2450 va_start(ap, methodID);
2451 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, ap);
2454 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2458 jobject _Jv_JNI_CallNonvirtualObjectMethodV(JNIEnv *env, jobject obj,
2459 jclass clazz, jmethodID methodID,
2462 java_objectheader *o;
2465 java_objectheader *r;
2467 o = (java_objectheader *) obj;
2468 c = (classinfo *) clazz;
2469 m = (methodinfo *) methodID;
2471 r = _Jv_jni_CallObjectMethod(o, c->vftbl, m, args);
2473 return _Jv_JNI_NewLocalRef(env, (jobject) r);
2477 jobject _Jv_JNI_CallNonvirtualObjectMethodA(JNIEnv *env, jobject obj,
2478 jclass clazz, jmethodID methodID,
2481 log_text("JNI-Call: CallNonvirtualObjectMethodA: IMPLEMENT ME!");
2483 return _Jv_JNI_NewLocalRef(env, NULL);
2488 jboolean _Jv_JNI_CallNonvirtualBooleanMethod(JNIEnv *env, jobject obj,
2489 jclass clazz, jmethodID methodID,
2492 java_objectheader *o;
2498 o = (java_objectheader *) obj;
2499 c = (classinfo *) clazz;
2500 m = (methodinfo *) methodID;
2502 va_start(ap, methodID);
2503 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2510 jboolean _Jv_JNI_CallNonvirtualBooleanMethodV(JNIEnv *env, jobject obj,
2511 jclass clazz, jmethodID methodID,
2514 java_objectheader *o;
2519 o = (java_objectheader *) obj;
2520 c = (classinfo *) clazz;
2521 m = (methodinfo *) methodID;
2523 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2529 jboolean _Jv_JNI_CallNonvirtualBooleanMethodA(JNIEnv *env, jobject obj,
2530 jclass clazz, jmethodID methodID,
2533 log_text("JNI-Call: CallNonvirtualBooleanMethodA: IMPLEMENT ME!");
2539 jbyte _Jv_JNI_CallNonvirtualByteMethod(JNIEnv *env, jobject obj, jclass clazz,
2540 jmethodID methodID, ...)
2542 java_objectheader *o;
2548 o = (java_objectheader *) obj;
2549 c = (classinfo *) clazz;
2550 m = (methodinfo *) methodID;
2552 va_start(ap, methodID);
2553 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2560 jbyte _Jv_JNI_CallNonvirtualByteMethodV(JNIEnv *env, jobject obj, jclass clazz,
2561 jmethodID methodID, va_list args)
2563 java_objectheader *o;
2568 o = (java_objectheader *) obj;
2569 c = (classinfo *) clazz;
2570 m = (methodinfo *) methodID;
2572 b = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2578 jbyte _Jv_JNI_CallNonvirtualByteMethodA(JNIEnv *env, jobject obj, jclass clazz,
2579 jmethodID methodID, const jvalue *args)
2581 log_text("JNI-Call: CallNonvirtualByteMethodA: IMPLEMENT ME!");
2588 jchar _Jv_JNI_CallNonvirtualCharMethod(JNIEnv *env, jobject obj, jclass clazz,
2589 jmethodID methodID, ...)
2591 java_objectheader *o;
2597 o = (java_objectheader *) obj;
2598 c = (classinfo *) clazz;
2599 m = (methodinfo *) methodID;
2601 va_start(ap, methodID);
2602 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2609 jchar _Jv_JNI_CallNonvirtualCharMethodV(JNIEnv *env, jobject obj, jclass clazz,
2610 jmethodID methodID, va_list args)
2612 java_objectheader *o;
2617 o = (java_objectheader *) obj;
2618 c = (classinfo *) clazz;
2619 m = (methodinfo *) methodID;
2621 ch = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2627 jchar _Jv_JNI_CallNonvirtualCharMethodA(JNIEnv *env, jobject obj, jclass clazz,
2628 jmethodID methodID, const jvalue *args)
2630 log_text("JNI-Call: CallNonvirtualCharMethodA: IMPLEMENT ME!");
2637 jshort _Jv_JNI_CallNonvirtualShortMethod(JNIEnv *env, jobject obj,
2638 jclass clazz, jmethodID methodID, ...)
2640 java_objectheader *o;
2646 o = (java_objectheader *) obj;
2647 c = (classinfo *) clazz;
2648 m = (methodinfo *) methodID;
2650 va_start(ap, methodID);
2651 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2658 jshort _Jv_JNI_CallNonvirtualShortMethodV(JNIEnv *env, jobject obj,
2659 jclass clazz, jmethodID methodID,
2662 java_objectheader *o;
2667 o = (java_objectheader *) obj;
2668 c = (classinfo *) clazz;
2669 m = (methodinfo *) methodID;
2671 s = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2677 jshort _Jv_JNI_CallNonvirtualShortMethodA(JNIEnv *env, jobject obj,
2678 jclass clazz, jmethodID methodID,
2681 log_text("JNI-Call: CallNonvirtualShortMethodA: IMPLEMENT ME!");
2688 jint _Jv_JNI_CallNonvirtualIntMethod(JNIEnv *env, jobject obj, jclass clazz,
2689 jmethodID methodID, ...)
2691 java_objectheader *o;
2697 o = (java_objectheader *) obj;
2698 c = (classinfo *) clazz;
2699 m = (methodinfo *) methodID;
2701 va_start(ap, methodID);
2702 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, ap);
2709 jint _Jv_JNI_CallNonvirtualIntMethodV(JNIEnv *env, jobject obj, jclass clazz,
2710 jmethodID methodID, va_list args)
2712 java_objectheader *o;
2717 o = (java_objectheader *) obj;
2718 c = (classinfo *) clazz;
2719 m = (methodinfo *) methodID;
2721 i = _Jv_jni_CallIntMethod(o, c->vftbl, m, args);
2727 jint _Jv_JNI_CallNonvirtualIntMethodA(JNIEnv *env, jobject obj, jclass clazz,
2728 jmethodID methodID, const jvalue *args)
2730 log_text("JNI-Call: CallNonvirtualIntMethodA: IMPLEMENT ME!");
2737 jlong _Jv_JNI_CallNonvirtualLongMethod(JNIEnv *env, jobject obj, jclass clazz,
2738 jmethodID methodID, ...)
2740 java_objectheader *o;
2746 o = (java_objectheader *) obj;
2747 c = (classinfo *) clazz;
2748 m = (methodinfo *) methodID;
2750 va_start(ap, methodID);
2751 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, ap);
2758 jlong _Jv_JNI_CallNonvirtualLongMethodV(JNIEnv *env, jobject obj, jclass clazz,
2759 jmethodID methodID, va_list args)
2761 java_objectheader *o;
2766 o = (java_objectheader *) obj;
2767 c = (classinfo *) clazz;
2768 m = (methodinfo *) methodID;
2770 l = _Jv_jni_CallLongMethod(o, c->vftbl, m, args);
2776 jlong _Jv_JNI_CallNonvirtualLongMethodA(JNIEnv *env, jobject obj, jclass clazz,
2777 jmethodID methodID, const jvalue *args)
2779 log_text("JNI-Call: CallNonvirtualLongMethodA: IMPLEMENT ME!");
2786 jfloat _Jv_JNI_CallNonvirtualFloatMethod(JNIEnv *env, jobject obj,
2787 jclass clazz, jmethodID methodID, ...)
2789 java_objectheader *o;
2795 o = (java_objectheader *) obj;
2796 c = (classinfo *) clazz;
2797 m = (methodinfo *) methodID;
2799 va_start(ap, methodID);
2800 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, ap);
2807 jfloat _Jv_JNI_CallNonvirtualFloatMethodV(JNIEnv *env, jobject obj,
2808 jclass clazz, jmethodID methodID,
2811 java_objectheader *o;
2816 o = (java_objectheader *) obj;
2817 c = (classinfo *) clazz;
2818 m = (methodinfo *) methodID;
2820 f = _Jv_jni_CallFloatMethod(o, c->vftbl, m, args);
2826 jfloat _Jv_JNI_CallNonvirtualFloatMethodA(JNIEnv *env, jobject obj,
2827 jclass clazz, jmethodID methodID,
2830 log_text("JNI-Call: CallNonvirtualFloatMethodA: IMPLEMENT ME!");
2837 jdouble _Jv_JNI_CallNonvirtualDoubleMethod(JNIEnv *env, jobject obj,
2838 jclass clazz, jmethodID methodID,
2841 java_objectheader *o;
2847 o = (java_objectheader *) obj;
2848 c = (classinfo *) clazz;
2849 m = (methodinfo *) methodID;
2851 va_start(ap, methodID);
2852 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, ap);
2859 jdouble _Jv_JNI_CallNonvirtualDoubleMethodV(JNIEnv *env, jobject obj,
2860 jclass clazz, jmethodID methodID,
2863 java_objectheader *o;
2868 o = (java_objectheader *) obj;
2869 c = (classinfo *) clazz;
2870 m = (methodinfo *) methodID;
2872 d = _Jv_jni_CallDoubleMethod(o, c->vftbl, m, args);
2878 jdouble _Jv_JNI_CallNonvirtualDoubleMethodA(JNIEnv *env, jobject obj,
2879 jclass clazz, jmethodID methodID,
2882 log_text("JNI-Call: CallNonvirtualDoubleMethodA: IMPLEMENT ME!");
2889 void _Jv_JNI_CallNonvirtualVoidMethod(JNIEnv *env, jobject obj, jclass clazz,
2890 jmethodID methodID, ...)
2892 java_objectheader *o;
2897 o = (java_objectheader *) obj;
2898 c = (classinfo *) clazz;
2899 m = (methodinfo *) methodID;
2901 va_start(ap, methodID);
2902 _Jv_jni_CallVoidMethod(o, c->vftbl, m, ap);
2907 void _Jv_JNI_CallNonvirtualVoidMethodV(JNIEnv *env, jobject obj, jclass clazz,
2908 jmethodID methodID, va_list args)
2910 java_objectheader *o;
2914 o = (java_objectheader *) obj;
2915 c = (classinfo *) clazz;
2916 m = (methodinfo *) methodID;
2918 _Jv_jni_CallVoidMethod(o, c->vftbl, m, args);
2922 void _Jv_JNI_CallNonvirtualVoidMethodA(JNIEnv *env, jobject obj, jclass clazz,
2923 jmethodID methodID, const jvalue * args)
2925 java_objectheader *o;
2929 o = (java_objectheader *) obj;
2930 c = (classinfo *) clazz;
2931 m = (methodinfo *) methodID;
2933 _Jv_jni_CallVoidMethodA(o, c->vftbl, m, args);
2937 /* Accessing Fields of Objects ************************************************/
2939 /* GetFieldID ******************************************************************
2941 Returns the field ID for an instance (nonstatic) field of a
2942 class. The field is specified by its name and signature. The
2943 Get<type>Field and Set<type>Field families of accessor functions
2944 use field IDs to retrieve object fields.
2946 *******************************************************************************/
2948 jfieldID _Jv_JNI_GetFieldID(JNIEnv *env, jclass clazz, const char *name,
2956 STATISTICS(jniinvokation());
2958 c = (classinfo *) clazz;
2960 /* XXX NPE check? */
2962 uname = utf_new_char((char *) name);
2963 udesc = utf_new_char((char *) sig);
2965 f = class_findfield(c, uname, udesc);
2968 exceptions_throw_nosuchfielderror(c, uname);
2970 return (jfieldID) f;
2974 /* Get<type>Field Routines *****************************************************
2976 This family of accessor routines returns the value of an instance
2977 (nonstatic) field of an object. The field to access is specified by
2978 a field ID obtained by calling GetFieldID().
2980 *******************************************************************************/
2982 jobject _Jv_JNI_GetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID)
2984 java_objectheader *o;
2986 STATISTICS(jniinvokation());
2988 o = GET_FIELD(obj, java_objectheader*, fieldID);
2990 return _Jv_JNI_NewLocalRef(env, (jobject) o);
2994 jboolean _Jv_JNI_GetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID)
2998 STATISTICS(jniinvokation());
3000 i = GET_FIELD(obj, s4, fieldID);
3002 return (jboolean) i;
3006 jbyte _Jv_JNI_GetByteField(JNIEnv *env, jobject obj, jfieldID fieldID)
3010 STATISTICS(jniinvokation());
3012 i = GET_FIELD(obj, s4, fieldID);
3018 jchar _Jv_JNI_GetCharField(JNIEnv *env, jobject obj, jfieldID fieldID)
3022 STATISTICS(jniinvokation());
3024 i = GET_FIELD(obj, s4, fieldID);
3030 jshort _Jv_JNI_GetShortField(JNIEnv *env, jobject obj, jfieldID fieldID)
3034 STATISTICS(jniinvokation());
3036 i = GET_FIELD(obj, s4, fieldID);
3042 jint _Jv_JNI_GetIntField(JNIEnv *env, jobject obj, jfieldID fieldID)
3044 java_objectheader *o;
3048 STATISTICS(jniinvokation());
3050 o = (java_objectheader *) obj;
3051 f = (fieldinfo *) fieldID;
3053 i = GET_FIELD(o, s4, f);
3059 jlong _Jv_JNI_GetLongField(JNIEnv *env, jobject obj, jfieldID fieldID)
3063 STATISTICS(jniinvokation());
3065 l = GET_FIELD(obj, s8, fieldID);
3071 jfloat _Jv_JNI_GetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID)
3075 STATISTICS(jniinvokation());
3077 f = GET_FIELD(obj, float, fieldID);
3083 jdouble _Jv_JNI_GetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID)
3087 STATISTICS(jniinvokation());
3089 d = GET_FIELD(obj, double, fieldID);
3095 /* Set<type>Field Routines *****************************************************
3097 This family of accessor routines sets the value of an instance
3098 (nonstatic) field of an object. The field to access is specified by
3099 a field ID obtained by calling GetFieldID().
3101 *******************************************************************************/
3103 void _Jv_JNI_SetObjectField(JNIEnv *env, jobject obj, jfieldID fieldID,
3106 STATISTICS(jniinvokation());
3108 SET_FIELD(obj, java_objectheader*, fieldID, value);
3112 void _Jv_JNI_SetBooleanField(JNIEnv *env, jobject obj, jfieldID fieldID,
3115 STATISTICS(jniinvokation());
3117 SET_FIELD(obj, s4, fieldID, value);
3121 void _Jv_JNI_SetByteField(JNIEnv *env, jobject obj, jfieldID fieldID,
3124 STATISTICS(jniinvokation());
3126 SET_FIELD(obj, s4, fieldID, value);
3130 void _Jv_JNI_SetCharField(JNIEnv *env, jobject obj, jfieldID fieldID,
3133 STATISTICS(jniinvokation());
3135 SET_FIELD(obj, s4, fieldID, value);
3139 void _Jv_JNI_SetShortField(JNIEnv *env, jobject obj, jfieldID fieldID,
3142 STATISTICS(jniinvokation());
3144 SET_FIELD(obj, s4, fieldID, value);
3148 void _Jv_JNI_SetIntField(JNIEnv *env, jobject obj, jfieldID fieldID, jint value)
3150 STATISTICS(jniinvokation());
3152 SET_FIELD(obj, s4, fieldID, value);
3156 void _Jv_JNI_SetLongField(JNIEnv *env, jobject obj, jfieldID fieldID,
3159 STATISTICS(jniinvokation());
3161 SET_FIELD(obj, s8, fieldID, value);
3165 void _Jv_JNI_SetFloatField(JNIEnv *env, jobject obj, jfieldID fieldID,
3168 STATISTICS(jniinvokation());
3170 SET_FIELD(obj, float, fieldID, value);
3174 void _Jv_JNI_SetDoubleField(JNIEnv *env, jobject obj, jfieldID fieldID,
3177 STATISTICS(jniinvokation());
3179 SET_FIELD(obj, double, fieldID, value);
3183 /* Calling Static Methods *****************************************************/
3185 /* GetStaticMethodID ***********************************************************
3187 Returns the method ID for a static method of a class. The method is
3188 specified by its name and signature.
3190 GetStaticMethodID() causes an uninitialized class to be
3193 *******************************************************************************/
3195 jmethodID _Jv_JNI_GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name,
3203 STATISTICS(jniinvokation());
3205 c = (classinfo *) clazz;
3210 if (!(c->state & CLASS_INITIALIZED))
3211 if (!initialize_class(c))
3214 /* try to get the static method of the class */
3216 uname = utf_new_char((char *) name);
3217 udesc = utf_new_char((char *) sig);
3219 m = class_resolvemethod(c, uname, udesc);
3221 if ((m == NULL) || !(m->flags & ACC_STATIC)) {
3222 exceptions_throw_nosuchmethoderror(c, uname, udesc);
3227 return (jmethodID) m;
3231 jobject _Jv_JNI_CallStaticObjectMethod(JNIEnv *env, jclass clazz,
3232 jmethodID methodID, ...)
3235 java_objectheader *o;
3238 m = (methodinfo *) methodID;
3240 va_start(ap, methodID);
3241 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, ap);
3244 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3248 jobject _Jv_JNI_CallStaticObjectMethodV(JNIEnv *env, jclass clazz,
3249 jmethodID methodID, va_list args)
3252 java_objectheader *o;
3254 m = (methodinfo *) methodID;
3256 o = _Jv_jni_CallObjectMethod(NULL, NULL, m, args);
3258 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3262 jobject _Jv_JNI_CallStaticObjectMethodA(JNIEnv *env, jclass clazz,
3263 jmethodID methodID, const jvalue *args)
3266 java_objectheader *o;
3268 m = (methodinfo *) methodID;
3270 o = _Jv_jni_CallObjectMethodA(NULL, NULL, m, args);
3272 return _Jv_JNI_NewLocalRef(env, (jobject) o);
3276 jboolean _Jv_JNI_CallStaticBooleanMethod(JNIEnv *env, jclass clazz,
3277 jmethodID methodID, ...)
3283 m = (methodinfo *) methodID;
3285 va_start(ap, methodID);
3286 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3293 jboolean _Jv_JNI_CallStaticBooleanMethodV(JNIEnv *env, jclass clazz,
3294 jmethodID methodID, va_list args)
3299 m = (methodinfo *) methodID;
3301 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3307 jboolean _Jv_JNI_CallStaticBooleanMethodA(JNIEnv *env, jclass clazz,
3308 jmethodID methodID, const jvalue *args)
3313 m = (methodinfo *) methodID;
3315 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3321 jbyte _Jv_JNI_CallStaticByteMethod(JNIEnv *env, jclass clazz,
3322 jmethodID methodID, ...)
3328 m = (methodinfo *) methodID;
3330 va_start(ap, methodID);
3331 b = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3338 jbyte _Jv_JNI_CallStaticByteMethodV(JNIEnv *env, jclass clazz,
3339 jmethodID methodID, va_list args)
3344 m = (methodinfo *) methodID;
3346 b = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3352 jbyte _Jv_JNI_CallStaticByteMethodA(JNIEnv *env, jclass clazz,
3353 jmethodID methodID, const jvalue *args)
3358 m = (methodinfo *) methodID;
3360 b = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3366 jchar _Jv_JNI_CallStaticCharMethod(JNIEnv *env, jclass clazz,
3367 jmethodID methodID, ...)
3373 m = (methodinfo *) methodID;
3375 va_start(ap, methodID);
3376 c = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3383 jchar _Jv_JNI_CallStaticCharMethodV(JNIEnv *env, jclass clazz,
3384 jmethodID methodID, va_list args)
3389 m = (methodinfo *) methodID;
3391 c = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3397 jchar _Jv_JNI_CallStaticCharMethodA(JNIEnv *env, jclass clazz,
3398 jmethodID methodID, const jvalue *args)
3403 m = (methodinfo *) methodID;
3405 c = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3411 jshort _Jv_JNI_CallStaticShortMethod(JNIEnv *env, jclass clazz,
3412 jmethodID methodID, ...)
3418 m = (methodinfo *) methodID;
3420 va_start(ap, methodID);
3421 s = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3428 jshort _Jv_JNI_CallStaticShortMethodV(JNIEnv *env, jclass clazz,
3429 jmethodID methodID, va_list args)
3434 m = (methodinfo *) methodID;
3436 s = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3442 jshort _Jv_JNI_CallStaticShortMethodA(JNIEnv *env, jclass clazz,
3443 jmethodID methodID, const jvalue *args)
3448 m = (methodinfo *) methodID;
3450 s = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3456 jint _Jv_JNI_CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID,
3463 m = (methodinfo *) methodID;
3465 va_start(ap, methodID);
3466 i = _Jv_jni_CallIntMethod(NULL, NULL, m, ap);
3473 jint _Jv_JNI_CallStaticIntMethodV(JNIEnv *env, jclass clazz,
3474 jmethodID methodID, va_list args)
3479 m = (methodinfo *) methodID;
3481 i = _Jv_jni_CallIntMethod(NULL, NULL, m, args);
3487 jint _Jv_JNI_CallStaticIntMethodA(JNIEnv *env, jclass clazz,
3488 jmethodID methodID, const jvalue *args)
3493 m = (methodinfo *) methodID;
3495 i = _Jv_jni_CallIntMethodA(NULL, NULL, m, args);
3501 jlong _Jv_JNI_CallStaticLongMethod(JNIEnv *env, jclass clazz,
3502 jmethodID methodID, ...)
3508 m = (methodinfo *) methodID;
3510 va_start(ap, methodID);
3511 l = _Jv_jni_CallLongMethod(NULL, NULL, m, ap);
3518 jlong _Jv_JNI_CallStaticLongMethodV(JNIEnv *env, jclass clazz,
3519 jmethodID methodID, va_list args)
3524 m = (methodinfo *) methodID;
3526 l = _Jv_jni_CallLongMethod(NULL, NULL, m, args);
3532 jlong _Jv_JNI_CallStaticLongMethodA(JNIEnv *env, jclass clazz,
3533 jmethodID methodID, const jvalue *args)
3538 m = (methodinfo *) methodID;
3540 l = _Jv_jni_CallLongMethodA(NULL, NULL, m, args);
3547 jfloat _Jv_JNI_CallStaticFloatMethod(JNIEnv *env, jclass clazz,
3548 jmethodID methodID, ...)
3554 m = (methodinfo *) methodID;
3556 va_start(ap, methodID);
3557 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, ap);
3564 jfloat _Jv_JNI_CallStaticFloatMethodV(JNIEnv *env, jclass clazz,
3565 jmethodID methodID, va_list args)
3570 m = (methodinfo *) methodID;
3572 f = _Jv_jni_CallFloatMethod(NULL, NULL, m, args);
3578 jfloat _Jv_JNI_CallStaticFloatMethodA(JNIEnv *env, jclass clazz,
3579 jmethodID methodID, const jvalue *args)
3584 m = (methodinfo *) methodID;
3586 f = _Jv_jni_CallFloatMethodA(NULL, NULL, m, args);
3592 jdouble _Jv_JNI_CallStaticDoubleMethod(JNIEnv *env, jclass clazz,
3593 jmethodID methodID, ...)
3599 m = (methodinfo *) methodID;
3601 va_start(ap, methodID);
3602 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, ap);
3609 jdouble _Jv_JNI_CallStaticDoubleMethodV(JNIEnv *env, jclass clazz,
3610 jmethodID methodID, va_list args)
3615 m = (methodinfo *) methodID;
3617 d = _Jv_jni_CallDoubleMethod(NULL, NULL, m, args);
3623 jdouble _Jv_JNI_CallStaticDoubleMethodA(JNIEnv *env, jclass clazz,
3624 jmethodID methodID, const jvalue *args)
3629 m = (methodinfo *) methodID;
3631 d = _Jv_jni_CallDoubleMethodA(NULL, NULL, m, args);
3637 void _Jv_JNI_CallStaticVoidMethod(JNIEnv *env, jclass clazz,
3638 jmethodID methodID, ...)
3643 m = (methodinfo *) methodID;
3645 va_start(ap, methodID);
3646 _Jv_jni_CallVoidMethod(NULL, NULL, m, ap);
3651 void _Jv_JNI_CallStaticVoidMethodV(JNIEnv *env, jclass clazz,
3652 jmethodID methodID, va_list args)
3656 m = (methodinfo *) methodID;
3658 _Jv_jni_CallVoidMethod(NULL, NULL, m, args);
3662 void _Jv_JNI_CallStaticVoidMethodA(JNIEnv *env, jclass clazz,
3663 jmethodID methodID, const jvalue * args)
3667 m = (methodinfo *) methodID;
3669 _Jv_jni_CallVoidMethodA(NULL, NULL, m, args);
3673 /* Accessing Static Fields ****************************************************/
3675 /* GetStaticFieldID ************************************************************
3677 Returns the field ID for a static field of a class. The field is
3678 specified by its name and signature. The GetStatic<type>Field and
3679 SetStatic<type>Field families of accessor functions use field IDs
3680 to retrieve static fields.
3682 *******************************************************************************/
3684 jfieldID _Jv_JNI_GetStaticFieldID(JNIEnv *env, jclass clazz, const char *name,
3692 STATISTICS(jniinvokation());
3694 c = (classinfo *) clazz;
3696 uname = utf_new_char((char *) name);
3697 usig = utf_new_char((char *) sig);
3699 f = class_findfield(c, uname, usig);
3702 exceptions_throw_nosuchfielderror(c, uname);
3704 return (jfieldID) f;
3708 /* GetStatic<type>Field ********************************************************
3710 This family of accessor routines returns the value of a static
3713 *******************************************************************************/
3715 jobject _Jv_JNI_GetStaticObjectField(JNIEnv *env, jclass clazz,
3721 STATISTICS(jniinvokation());
3723 c = (classinfo *) clazz;
3724 f = (fieldinfo *) fieldID;
3726 if (!(c->state & CLASS_INITIALIZED))
3727 if (!initialize_class(c))
3730 return _Jv_JNI_NewLocalRef(env, f->value->a);
3734 jboolean _Jv_JNI_GetStaticBooleanField(JNIEnv *env, jclass clazz,
3740 STATISTICS(jniinvokation());
3742 c = (classinfo *) clazz;
3743 f = (fieldinfo *) fieldID;
3745 if (!(c->state & CLASS_INITIALIZED))
3746 if (!initialize_class(c))
3753 jbyte _Jv_JNI_GetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3758 STATISTICS(jniinvokation());
3760 c = (classinfo *) clazz;
3761 f = (fieldinfo *) fieldID;
3763 if (!(c->state & CLASS_INITIALIZED))
3764 if (!initialize_class(c))
3771 jchar _Jv_JNI_GetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3776 STATISTICS(jniinvokation());
3778 c = (classinfo *) clazz;
3779 f = (fieldinfo *) fieldID;
3781 if (!(c->state & CLASS_INITIALIZED))
3782 if (!initialize_class(c))
3789 jshort _Jv_JNI_GetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3794 STATISTICS(jniinvokation());
3796 c = (classinfo *) clazz;
3797 f = (fieldinfo *) fieldID;
3799 if (!(c->state & CLASS_INITIALIZED))
3800 if (!initialize_class(c))
3807 jint _Jv_JNI_GetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3812 STATISTICS(jniinvokation());
3814 c = (classinfo *) clazz;
3815 f = (fieldinfo *) fieldID;
3817 if (!(c->state & CLASS_INITIALIZED))
3818 if (!initialize_class(c))
3825 jlong _Jv_JNI_GetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3830 STATISTICS(jniinvokation());
3832 c = (classinfo *) clazz;
3833 f = (fieldinfo *) fieldID;
3835 if (!(c->state & CLASS_INITIALIZED))
3836 if (!initialize_class(c))
3843 jfloat _Jv_JNI_GetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID)
3848 STATISTICS(jniinvokation());
3850 c = (classinfo *) clazz;
3851 f = (fieldinfo *) fieldID;
3853 if (!(c->state & CLASS_INITIALIZED))
3854 if (!initialize_class(c))
3861 jdouble _Jv_JNI_GetStaticDoubleField(JNIEnv *env, jclass clazz,
3867 STATISTICS(jniinvokation());
3869 c = (classinfo *) clazz;
3870 f = (fieldinfo *) fieldID;
3872 if (!(c->state & CLASS_INITIALIZED))
3873 if (!initialize_class(c))
3880 /* SetStatic<type>Field *******************************************************
3882 This family of accessor routines sets the value of a static field
3885 *******************************************************************************/
3887 void _Jv_JNI_SetStaticObjectField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3893 STATISTICS(jniinvokation());
3895 c = (classinfo *) clazz;
3896 f = (fieldinfo *) fieldID;
3898 if (!(c->state & CLASS_INITIALIZED))
3899 if (!initialize_class(c))
3902 f->value->a = value;
3906 void _Jv_JNI_SetStaticBooleanField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3912 STATISTICS(jniinvokation());
3914 c = (classinfo *) clazz;
3915 f = (fieldinfo *) fieldID;
3917 if (!(c->state & CLASS_INITIALIZED))
3918 if (!initialize_class(c))
3921 f->value->i = value;
3925 void _Jv_JNI_SetStaticByteField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3931 STATISTICS(jniinvokation());
3933 c = (classinfo *) clazz;
3934 f = (fieldinfo *) fieldID;
3936 if (!(c->state & CLASS_INITIALIZED))
3937 if (!initialize_class(c))
3940 f->value->i = value;
3944 void _Jv_JNI_SetStaticCharField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3950 STATISTICS(jniinvokation());
3952 c = (classinfo *) clazz;
3953 f = (fieldinfo *) fieldID;
3955 if (!(c->state & CLASS_INITIALIZED))
3956 if (!initialize_class(c))
3959 f->value->i = value;
3963 void _Jv_JNI_SetStaticShortField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3969 STATISTICS(jniinvokation());
3971 c = (classinfo *) clazz;
3972 f = (fieldinfo *) fieldID;
3974 if (!(c->state & CLASS_INITIALIZED))
3975 if (!initialize_class(c))
3978 f->value->i = value;
3982 void _Jv_JNI_SetStaticIntField(JNIEnv *env, jclass clazz, jfieldID fieldID,
3988 STATISTICS(jniinvokation());
3990 c = (classinfo *) clazz;
3991 f = (fieldinfo *) fieldID;
3993 if (!(c->state & CLASS_INITIALIZED))
3994 if (!initialize_class(c))
3997 f->value->i = value;
4001 void _Jv_JNI_SetStaticLongField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4007 STATISTICS(jniinvokation());
4009 c = (classinfo *) clazz;
4010 f = (fieldinfo *) fieldID;
4012 if (!(c->state & CLASS_INITIALIZED))
4013 if (!initialize_class(c))
4016 f->value->l = value;
4020 void _Jv_JNI_SetStaticFloatField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4026 STATISTICS(jniinvokation());
4028 c = (classinfo *) clazz;
4029 f = (fieldinfo *) fieldID;
4031 if (!(c->state & CLASS_INITIALIZED))
4032 if (!initialize_class(c))
4035 f->value->f = value;
4039 void _Jv_JNI_SetStaticDoubleField(JNIEnv *env, jclass clazz, jfieldID fieldID,
4045 STATISTICS(jniinvokation());
4047 c = (classinfo *) clazz;
4048 f = (fieldinfo *) fieldID;
4050 if (!(c->state & CLASS_INITIALIZED))
4051 if (!initialize_class(c))
4054 f->value->d = value;
4058 /* String Operations **********************************************************/
4060 /* NewString *******************************************************************
4062 Create new java.lang.String object from an array of Unicode
4065 *******************************************************************************/
4067 jstring _Jv_JNI_NewString(JNIEnv *env, const jchar *buf, jsize len)
4069 java_lang_String *s;
4073 STATISTICS(jniinvokation());
4075 s = (java_lang_String *) builtin_new(class_java_lang_String);
4076 a = builtin_newarray_char(len);
4078 /* javastring or characterarray could not be created */
4079 if ((a == NULL) || (s == NULL))
4083 for (i = 0; i < len; i++)
4084 a->data[i] = buf[i];
4086 LLNI_field_set_ref(s, value , a);
4087 LLNI_field_set_val(s, offset, 0);
4088 LLNI_field_set_val(s, count , len);
4090 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4094 static jchar emptyStringJ[]={0,0};
4096 /* GetStringLength *************************************************************
4098 Returns the length (the count of Unicode characters) of a Java
4101 *******************************************************************************/
4103 jsize _Jv_JNI_GetStringLength(JNIEnv *env, jstring str)
4105 java_lang_String *s;
4108 TRACEJNICALLS("_Jv_JNI_GetStringLength(env=%p, str=%p)", env, str);
4110 s = (java_lang_String *) str;
4112 LLNI_field_get_val(s, count, len);
4118 /******************** convertes javastring to u2-array ****************************/
4120 u2 *javastring_tou2(jstring so)
4122 java_lang_String *s;
4127 STATISTICS(jniinvokation());
4129 s = (java_lang_String *) so;
4134 LLNI_field_get_ref(s, value, a);
4139 /* allocate memory */
4141 stringbuffer = MNEW(u2, LLNI_field_direct(s, count) + 1);
4145 for (i = 0; i < LLNI_field_direct(s, count); i++)
4146 stringbuffer[i] = a->data[LLNI_field_direct(s, offset) + i];
4148 /* terminate string */
4150 stringbuffer[i] = '\0';
4152 return stringbuffer;
4156 /* GetStringChars **************************************************************
4158 Returns a pointer to the array of Unicode characters of the
4159 string. This pointer is valid until ReleaseStringChars() is called.
4161 *******************************************************************************/
4163 const jchar *_Jv_JNI_GetStringChars(JNIEnv *env, jstring str, jboolean *isCopy)
4167 STATISTICS(jniinvokation());
4169 jc = javastring_tou2(str);
4181 return emptyStringJ;
4185 /* ReleaseStringChars **********************************************************
4187 Informs the VM that the native code no longer needs access to
4188 chars. The chars argument is a pointer obtained from string using
4191 *******************************************************************************/
4193 void _Jv_JNI_ReleaseStringChars(JNIEnv *env, jstring str, const jchar *chars)
4195 java_lang_String *s;
4197 STATISTICS(jniinvokation());
4199 if (chars == emptyStringJ)
4202 s = (java_lang_String *) str;
4204 MFREE(((jchar *) chars), jchar, LLNI_field_direct(s, count) + 1);
4208 /* NewStringUTF ****************************************************************
4210 Constructs a new java.lang.String object from an array of UTF-8
4213 *******************************************************************************/
4215 jstring _Jv_JNI_NewStringUTF(JNIEnv *env, const char *bytes)
4217 java_lang_String *s;
4219 TRACEJNICALLS("_Jv_JNI_NewStringUTF(env=%p, bytes=%s)", env, bytes);
4221 s = (java_lang_String *) javastring_safe_new_from_utf8(bytes);
4223 return (jstring) _Jv_JNI_NewLocalRef(env, (jobject) s);
4227 /****************** returns the utf8 length in bytes of a string *******************/
4229 jsize _Jv_JNI_GetStringUTFLength(JNIEnv *env, jstring string)
4231 java_lang_String *s;
4234 TRACEJNICALLS("_Jv_JNI_GetStringUTFLength(env=%p, string=%p)", env, string);
4236 s = (java_lang_String *) string;
4238 length = u2_utflength(LLNI_field_direct(s, value)->data, LLNI_field_direct(s, count));
4244 /* GetStringUTFChars ***********************************************************
4246 Returns a pointer to an array of UTF-8 characters of the
4247 string. This array is valid until it is released by
4248 ReleaseStringUTFChars().
4250 *******************************************************************************/
4252 const char *_Jv_JNI_GetStringUTFChars(JNIEnv *env, jstring string,
4257 STATISTICS(jniinvokation());
4265 u = javastring_toutf((java_objectheader *) string, false);
4274 /* ReleaseStringUTFChars *******************************************************
4276 Informs the VM that the native code no longer needs access to
4277 utf. The utf argument is a pointer derived from string using
4278 GetStringUTFChars().
4280 *******************************************************************************/
4282 void _Jv_JNI_ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf)
4284 STATISTICS(jniinvokation());
4286 /* XXX we don't release utf chars right now, perhaps that should be done
4287 later. Since there is always one reference the garbage collector will
4292 /* Array Operations ***********************************************************/
4294 /* GetArrayLength **************************************************************
4296 Returns the number of elements in the array.
4298 *******************************************************************************/
4300 jsize _Jv_JNI_GetArrayLength(JNIEnv *env, jarray array)
4302 java_arrayheader *a;
4304 STATISTICS(jniinvokation());
4306 a = (java_arrayheader *) array;
4312 /* NewObjectArray **************************************************************
4314 Constructs a new array holding objects in class elementClass. All
4315 elements are initially set to initialElement.
4317 *******************************************************************************/
4319 jobjectArray _Jv_JNI_NewObjectArray(JNIEnv *env, jsize length,
4320 jclass elementClass, jobject initialElement)
4323 java_objectheader *o;
4324 java_objectarray *oa;
4327 STATISTICS(jniinvokation());
4329 c = (classinfo *) elementClass;
4330 o = (java_objectheader *) initialElement;
4333 exceptions_throw_negativearraysizeexception();
4337 oa = builtin_anewarray(length, c);
4342 /* set all elements to initialElement */
4344 for (i = 0; i < length; i++)
4347 return (jobjectArray) _Jv_JNI_NewLocalRef(env, (jobject) oa);
4351 jobject _Jv_JNI_GetObjectArrayElement(JNIEnv *env, jobjectArray array,
4354 java_objectarray *oa;
4355 java_objectheader *o;
4357 STATISTICS(jniinvokation());
4359 oa = (java_objectarray *) array;
4361 if (index >= oa->header.size) {
4362 exceptions_throw_arrayindexoutofboundsexception();
4366 o = oa->data[index];
4368 return _Jv_JNI_NewLocalRef(env, (jobject) o);
4372 void _Jv_JNI_SetObjectArrayElement(JNIEnv *env, jobjectArray array,
4373 jsize index, jobject val)
4375 java_objectarray *oa;
4376 java_objectheader *o;
4378 STATISTICS(jniinvokation());
4380 oa = (java_objectarray *) array;
4381 o = (java_objectheader *) val;
4383 if (index >= oa->header.size) {
4384 exceptions_throw_arrayindexoutofboundsexception();
4388 /* check if the class of value is a subclass of the element class
4391 if (!builtin_canstore(oa, o))
4394 oa->data[index] = o;
4398 jbooleanArray _Jv_JNI_NewBooleanArray(JNIEnv *env, jsize len)
4400 java_booleanarray *ba;
4402 STATISTICS(jniinvokation());
4405 exceptions_throw_negativearraysizeexception();
4409 ba = builtin_newarray_boolean(len);
4411 return (jbooleanArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4415 jbyteArray _Jv_JNI_NewByteArray(JNIEnv *env, jsize len)
4419 STATISTICS(jniinvokation());
4422 exceptions_throw_negativearraysizeexception();
4426 ba = builtin_newarray_byte(len);
4428 return (jbyteArray) _Jv_JNI_NewLocalRef(env, (jobject) ba);
4432 jcharArray _Jv_JNI_NewCharArray(JNIEnv *env, jsize len)
4436 STATISTICS(jniinvokation());
4439 exceptions_throw_negativearraysizeexception();
4443 ca = builtin_newarray_char(len);
4445 return (jcharArray) _Jv_JNI_NewLocalRef(env, (jobject) ca);
4449 jshortArray _Jv_JNI_NewShortArray(JNIEnv *env, jsize len)
4451 java_shortarray *sa;
4453 STATISTICS(jniinvokation());
4456 exceptions_throw_negativearraysizeexception();
4460 sa = builtin_newarray_short(len);
4462 return (jshortArray) _Jv_JNI_NewLocalRef(env, (jobject) sa);
4466 jintArray _Jv_JNI_NewIntArray(JNIEnv *env, jsize len)
4470 STATISTICS(jniinvokation());
4473 exceptions_throw_negativearraysizeexception();
4477 ia = builtin_newarray_int(len);
4479 return (jintArray) _Jv_JNI_NewLocalRef(env, (jobject) ia);
4483 jlongArray _Jv_JNI_NewLongArray(JNIEnv *env, jsize len)
4487 STATISTICS(jniinvokation());
4490 exceptions_throw_negativearraysizeexception();
4494 la = builtin_newarray_long(len);
4496 return (jlongArray) _Jv_JNI_NewLocalRef(env, (jobject) la);
4500 jfloatArray _Jv_JNI_NewFloatArray(JNIEnv *env, jsize len)
4502 java_floatarray *fa;
4504 STATISTICS(jniinvokation());
4507 exceptions_throw_negativearraysizeexception();
4511 fa = builtin_newarray_float(len);
4513 return (jfloatArray) _Jv_JNI_NewLocalRef(env, (jobject) fa);
4517 jdoubleArray _Jv_JNI_NewDoubleArray(JNIEnv *env, jsize len)
4519 java_doublearray *da;
4521 STATISTICS(jniinvokation());
4524 exceptions_throw_negativearraysizeexception();
4528 da = builtin_newarray_double(len);
4530 return (jdoubleArray) _Jv_JNI_NewLocalRef(env, (jobject) da);
4534 /* Get<PrimitiveType>ArrayElements *********************************************
4536 A family of functions that returns the body of the primitive array.
4538 *******************************************************************************/
4540 jboolean *_Jv_JNI_GetBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4543 java_booleanarray *ba;
4545 STATISTICS(jniinvokation());
4547 ba = (java_booleanarray *) array;
4550 *isCopy = JNI_FALSE;
4556 jbyte *_Jv_JNI_GetByteArrayElements(JNIEnv *env, jbyteArray array,
4561 STATISTICS(jniinvokation());
4563 ba = (java_bytearray *) array;
4566 *isCopy = JNI_FALSE;
4572 jchar *_Jv_JNI_GetCharArrayElements(JNIEnv *env, jcharArray array,
4577 STATISTICS(jniinvokation());
4579 ca = (java_chararray *) array;
4582 *isCopy = JNI_FALSE;
4588 jshort *_Jv_JNI_GetShortArrayElements(JNIEnv *env, jshortArray array,
4591 java_shortarray *sa;
4593 STATISTICS(jniinvokation());
4595 sa = (java_shortarray *) array;
4598 *isCopy = JNI_FALSE;
4604 jint *_Jv_JNI_GetIntArrayElements(JNIEnv *env, jintArray array,
4609 STATISTICS(jniinvokation());
4611 ia = (java_intarray *) array;
4614 *isCopy = JNI_FALSE;
4620 jlong *_Jv_JNI_GetLongArrayElements(JNIEnv *env, jlongArray array,
4625 STATISTICS(jniinvokation());
4627 la = (java_longarray *) array;
4630 *isCopy = JNI_FALSE;
4632 /* We cast this one to prevent a compiler warning on 64-bit
4633 systems since GNU Classpath typedef jlong to long long. */
4635 return (jlong *) la->data;
4639 jfloat *_Jv_JNI_GetFloatArrayElements(JNIEnv *env, jfloatArray array,
4642 java_floatarray *fa;
4644 STATISTICS(jniinvokation());
4646 fa = (java_floatarray *) array;
4649 *isCopy = JNI_FALSE;
4655 jdouble *_Jv_JNI_GetDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4658 java_doublearray *da;
4660 STATISTICS(jniinvokation());
4662 da = (java_doublearray *) array;
4665 *isCopy = JNI_FALSE;
4671 /* Release<PrimitiveType>ArrayElements *****************************************
4673 A family of functions that informs the VM that the native code no
4674 longer needs access to elems. The elems argument is a pointer
4675 derived from array using the corresponding
4676 Get<PrimitiveType>ArrayElements() function. If necessary, this
4677 function copies back all changes made to elems to the original
4680 *******************************************************************************/
4682 void _Jv_JNI_ReleaseBooleanArrayElements(JNIEnv *env, jbooleanArray array,
4683 jboolean *elems, jint mode)
4685 java_booleanarray *ba;
4687 STATISTICS(jniinvokation());
4689 ba = (java_booleanarray *) array;
4691 if (elems != ba->data) {
4694 MCOPY(ba->data, elems, u1, ba->header.size);
4697 MCOPY(ba->data, elems, u1, ba->header.size);
4698 /* XXX TWISTI how should it be freed? */
4701 /* XXX TWISTI how should it be freed? */
4708 void _Jv_JNI_ReleaseByteArrayElements(JNIEnv *env, jbyteArray array,
4709 jbyte *elems, jint mode)
4713 STATISTICS(jniinvokation());
4715 ba = (java_bytearray *) array;
4717 if (elems != ba->data) {
4720 MCOPY(ba->data, elems, s1, ba->header.size);
4723 MCOPY(ba->data, elems, s1, ba->header.size);
4724 /* XXX TWISTI how should it be freed? */
4727 /* XXX TWISTI how should it be freed? */
4734 void _Jv_JNI_ReleaseCharArrayElements(JNIEnv *env, jcharArray array,
4735 jchar *elems, jint mode)
4739 STATISTICS(jniinvokation());
4741 ca = (java_chararray *) array;
4743 if (elems != ca->data) {
4746 MCOPY(ca->data, elems, u2, ca->header.size);
4749 MCOPY(ca->data, elems, u2, ca->header.size);
4750 /* XXX TWISTI how should it be freed? */
4753 /* XXX TWISTI how should it be freed? */
4760 void _Jv_JNI_ReleaseShortArrayElements(JNIEnv *env, jshortArray array,
4761 jshort *elems, jint mode)
4763 java_shortarray *sa;
4765 STATISTICS(jniinvokation());
4767 sa = (java_shortarray *) array;
4769 if (elems != sa->data) {
4772 MCOPY(sa->data, elems, s2, sa->header.size);
4775 MCOPY(sa->data, elems, s2, sa->header.size);
4776 /* XXX TWISTI how should it be freed? */
4779 /* XXX TWISTI how should it be freed? */
4786 void _Jv_JNI_ReleaseIntArrayElements(JNIEnv *env, jintArray array, jint *elems,
4791 STATISTICS(jniinvokation());
4793 ia = (java_intarray *) array;
4795 if (elems != ia->data) {
4798 MCOPY(ia->data, elems, s4, ia->header.size);
4801 MCOPY(ia->data, elems, s4, ia->header.size);
4802 /* XXX TWISTI how should it be freed? */
4805 /* XXX TWISTI how should it be freed? */
4812 void _Jv_JNI_ReleaseLongArrayElements(JNIEnv *env, jlongArray array,
4813 jlong *elems, jint mode)
4817 STATISTICS(jniinvokation());
4819 la = (java_longarray *) array;
4821 /* We cast this one to prevent a compiler warning on 64-bit
4822 systems since GNU Classpath typedef jlong to long long. */
4824 if ((s8 *) elems != la->data) {
4827 MCOPY(la->data, elems, s8, la->header.size);
4830 MCOPY(la->data, elems, s8, la->header.size);
4831 /* XXX TWISTI how should it be freed? */
4834 /* XXX TWISTI how should it be freed? */
4841 void _Jv_JNI_ReleaseFloatArrayElements(JNIEnv *env, jfloatArray array,
4842 jfloat *elems, jint mode)
4844 java_floatarray *fa;
4846 STATISTICS(jniinvokation());
4848 fa = (java_floatarray *) array;
4850 if (elems != fa->data) {
4853 MCOPY(fa->data, elems, float, fa->header.size);
4856 MCOPY(fa->data, elems, float, fa->header.size);
4857 /* XXX TWISTI how should it be freed? */
4860 /* XXX TWISTI how should it be freed? */
4867 void _Jv_JNI_ReleaseDoubleArrayElements(JNIEnv *env, jdoubleArray array,
4868 jdouble *elems, jint mode)
4870 java_doublearray *da;
4872 STATISTICS(jniinvokation());
4874 da = (java_doublearray *) array;
4876 if (elems != da->data) {
4879 MCOPY(da->data, elems, double, da->header.size);
4882 MCOPY(da->data, elems, double, da->header.size);
4883 /* XXX TWISTI how should it be freed? */
4886 /* XXX TWISTI how should it be freed? */
4893 /* Get<PrimitiveType>ArrayRegion **********************************************
4895 A family of functions that copies a region of a primitive array
4898 *******************************************************************************/
4900 void _Jv_JNI_GetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
4901 jsize start, jsize len, jboolean *buf)
4903 java_booleanarray *ba;
4905 STATISTICS(jniinvokation());
4907 ba = (java_booleanarray *) array;
4909 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4910 exceptions_throw_arrayindexoutofboundsexception();
4912 MCOPY(buf, &ba->data[start], u1, len);
4916 void _Jv_JNI_GetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
4917 jsize len, jbyte *buf)
4921 STATISTICS(jniinvokation());
4923 ba = (java_bytearray *) array;
4925 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
4926 exceptions_throw_arrayindexoutofboundsexception();
4928 MCOPY(buf, &ba->data[start], s1, len);
4932 void _Jv_JNI_GetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
4933 jsize len, jchar *buf)
4937 STATISTICS(jniinvokation());
4939 ca = (java_chararray *) array;
4941 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
4942 exceptions_throw_arrayindexoutofboundsexception();
4944 MCOPY(buf, &ca->data[start], u2, len);
4948 void _Jv_JNI_GetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
4949 jsize len, jshort *buf)
4951 java_shortarray *sa;
4953 STATISTICS(jniinvokation());
4955 sa = (java_shortarray *) array;
4957 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
4958 exceptions_throw_arrayindexoutofboundsexception();
4960 MCOPY(buf, &sa->data[start], s2, len);
4964 void _Jv_JNI_GetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
4965 jsize len, jint *buf)
4969 STATISTICS(jniinvokation());
4971 ia = (java_intarray *) array;
4973 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
4974 exceptions_throw_arrayindexoutofboundsexception();
4976 MCOPY(buf, &ia->data[start], s4, len);
4980 void _Jv_JNI_GetLongArrayRegion(JNIEnv *env, jlongArray array, jsize start,
4981 jsize len, jlong *buf)
4985 STATISTICS(jniinvokation());
4987 la = (java_longarray *) array;
4989 if ((start < 0) || (len < 0) || (start + len > la->header.size))
4990 exceptions_throw_arrayindexoutofboundsexception();
4992 MCOPY(buf, &la->data[start], s8, len);
4996 void _Jv_JNI_GetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
4997 jsize len, jfloat *buf)
4999 java_floatarray *fa;
5001 STATISTICS(jniinvokation());
5003 fa = (java_floatarray *) array;
5005 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5006 exceptions_throw_arrayindexoutofboundsexception();
5008 MCOPY(buf, &fa->data[start], float, len);
5012 void _Jv_JNI_GetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5013 jsize len, jdouble *buf)
5015 java_doublearray *da;
5017 STATISTICS(jniinvokation());
5019 da = (java_doublearray *) array;
5021 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5022 exceptions_throw_arrayindexoutofboundsexception();
5024 MCOPY(buf, &da->data[start], double, len);
5028 /* Set<PrimitiveType>ArrayRegion **********************************************
5030 A family of functions that copies back a region of a primitive
5031 array from a buffer.
5033 *******************************************************************************/
5035 void _Jv_JNI_SetBooleanArrayRegion(JNIEnv *env, jbooleanArray array,
5036 jsize start, jsize len, const jboolean *buf)
5038 java_booleanarray *ba;
5040 STATISTICS(jniinvokation());
5042 ba = (java_booleanarray *) array;
5044 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5045 exceptions_throw_arrayindexoutofboundsexception();
5047 MCOPY(&ba->data[start], buf, u1, len);
5051 void _Jv_JNI_SetByteArrayRegion(JNIEnv *env, jbyteArray array, jsize start,
5052 jsize len, const jbyte *buf)
5056 STATISTICS(jniinvokation());
5058 ba = (java_bytearray *) array;
5060 if ((start < 0) || (len < 0) || (start + len > ba->header.size))
5061 exceptions_throw_arrayindexoutofboundsexception();
5063 MCOPY(&ba->data[start], buf, s1, len);
5067 void _Jv_JNI_SetCharArrayRegion(JNIEnv *env, jcharArray array, jsize start,
5068 jsize len, const jchar *buf)
5072 STATISTICS(jniinvokation());
5074 ca = (java_chararray *) array;
5076 if ((start < 0) || (len < 0) || (start + len > ca->header.size))
5077 exceptions_throw_arrayindexoutofboundsexception();
5079 MCOPY(&ca->data[start], buf, u2, len);
5083 void _Jv_JNI_SetShortArrayRegion(JNIEnv *env, jshortArray array, jsize start,
5084 jsize len, const jshort *buf)
5086 java_shortarray *sa;
5088 STATISTICS(jniinvokation());
5090 sa = (java_shortarray *) array;
5092 if ((start < 0) || (len < 0) || (start + len > sa->header.size))
5093 exceptions_throw_arrayindexoutofboundsexception();
5095 MCOPY(&sa->data[start], buf, s2, len);
5099 void _Jv_JNI_SetIntArrayRegion(JNIEnv *env, jintArray array, jsize start,
5100 jsize len, const jint *buf)
5104 STATISTICS(jniinvokation());
5106 ia = (java_intarray *) array;
5108 if ((start < 0) || (len < 0) || (start + len > ia->header.size))
5109 exceptions_throw_arrayindexoutofboundsexception();
5111 MCOPY(&ia->data[start], buf, s4, len);
5115 void _Jv_JNI_SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start,
5116 jsize len, const jlong *buf)
5120 STATISTICS(jniinvokation());
5122 la = (java_longarray *) array;
5124 if ((start < 0) || (len < 0) || (start + len > la->header.size))
5125 exceptions_throw_arrayindexoutofboundsexception();
5127 MCOPY(&la->data[start], buf, s8, len);
5131 void _Jv_JNI_SetFloatArrayRegion(JNIEnv *env, jfloatArray array, jsize start,
5132 jsize len, const jfloat *buf)
5134 java_floatarray *fa;
5136 STATISTICS(jniinvokation());
5138 fa = (java_floatarray *) array;
5140 if ((start < 0) || (len < 0) || (start + len > fa->header.size))
5141 exceptions_throw_arrayindexoutofboundsexception();
5143 MCOPY(&fa->data[start], buf, float, len);
5147 void _Jv_JNI_SetDoubleArrayRegion(JNIEnv *env, jdoubleArray array, jsize start,
5148 jsize len, const jdouble *buf)
5150 java_doublearray *da;
5152 STATISTICS(jniinvokation());
5154 da = (java_doublearray *) array;
5156 if ((start < 0) || (len < 0) || (start + len > da->header.size))
5157 exceptions_throw_arrayindexoutofboundsexception();
5159 MCOPY(&da->data[start], buf, double, len);
5163 /* Registering Native Methods *************************************************/
5165 /* RegisterNatives *************************************************************
5167 Registers native methods with the class specified by the clazz
5168 argument. The methods parameter specifies an array of
5169 JNINativeMethod structures that contain the names, signatures, and
5170 function pointers of the native methods. The nMethods parameter
5171 specifies the number of native methods in the array.
5173 *******************************************************************************/
5175 jint _Jv_JNI_RegisterNatives(JNIEnv *env, jclass clazz,
5176 const JNINativeMethod *methods, jint nMethods)
5180 STATISTICS(jniinvokation());
5182 c = (classinfo *) clazz;
5184 /* XXX: if implemented this needs a call to jvmti_NativeMethodBind
5185 if (jvmti) jvmti_NativeMethodBind(method, address, new_address_ptr);
5188 native_method_register(c->name, methods, nMethods);
5194 /* UnregisterNatives ***********************************************************
5196 Unregisters native methods of a class. The class goes back to the
5197 state before it was linked or registered with its native method
5200 This function should not be used in normal native code. Instead, it
5201 provides special programs a way to reload and relink native
5204 *******************************************************************************/
5206 jint _Jv_JNI_UnregisterNatives(JNIEnv *env, jclass clazz)
5208 STATISTICS(jniinvokation());
5210 /* XXX TWISTI hmm, maybe we should not support that (like kaffe) */
5212 log_text("JNI-Call: UnregisterNatives: IMPLEMENT ME!!!");
5218 /* Monitor Operations *********************************************************/
5220 /* MonitorEnter ****************************************************************
5222 Enters the monitor associated with the underlying Java object
5225 *******************************************************************************/
5227 jint _Jv_JNI_MonitorEnter(JNIEnv *env, jobject obj)
5229 STATISTICS(jniinvokation());
5232 exceptions_throw_nullpointerexception();
5236 LOCK_MONITOR_ENTER(obj);
5242 /* MonitorExit *****************************************************************
5244 The current thread must be the owner of the monitor associated with
5245 the underlying Java object referred to by obj. The thread
5246 decrements the counter indicating the number of times it has
5247 entered this monitor. If the value of the counter becomes zero, the
5248 current thread releases the monitor.
5250 *******************************************************************************/
5252 jint _Jv_JNI_MonitorExit(JNIEnv *env, jobject obj)
5254 STATISTICS(jniinvokation());
5257 exceptions_throw_nullpointerexception();
5261 LOCK_MONITOR_EXIT(obj);
5267 /* JavaVM Interface ***********************************************************/
5269 /* GetJavaVM *******************************************************************
5271 Returns the Java VM interface (used in the Invocation API)
5272 associated with the current thread. The result is placed at the
5273 location pointed to by the second argument, vm.
5275 *******************************************************************************/
5277 jint _Jv_JNI_GetJavaVM(JNIEnv *env, JavaVM **vm)
5279 STATISTICS(jniinvokation());
5281 *vm = (JavaVM *) _Jv_jvm;
5287 /* GetStringRegion *************************************************************
5289 Copies len number of Unicode characters beginning at offset start
5290 to the given buffer buf.
5292 Throws StringIndexOutOfBoundsException on index overflow.
5294 *******************************************************************************/
5296 void _Jv_JNI_GetStringRegion(JNIEnv* env, jstring str, jsize start, jsize len,
5299 java_lang_String *s;
5302 STATISTICS(jniinvokation());
5304 s = (java_lang_String *) str;
5305 LLNI_field_get_ref(s, value, ca);
5307 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
5308 (start + len > LLNI_field_direct(s, count))) {
5309 exceptions_throw_stringindexoutofboundsexception();
5313 MCOPY(buf, &ca->data[start], u2, len);
5317 /* GetStringUTFRegion **********************************************************
5319 Translates len number of Unicode characters beginning at offset
5320 start into UTF-8 format and place the result in the given buffer
5323 Throws StringIndexOutOfBoundsException on index overflow.
5325 *******************************************************************************/
5327 void _Jv_JNI_GetStringUTFRegion(JNIEnv* env, jstring str, jsize start,
5328 jsize len, char *buf)
5330 java_lang_String *s;
5334 TRACEJNICALLS("_Jv_JNI_GetStringUTFRegion(env=%p, str=%p, start=%d, len=%d, buf=%p)", env, str, start, len, buf);
5336 s = (java_lang_String *) str;
5337 LLNI_field_get_ref(s, value, ca);
5339 if ((start < 0) || (len < 0) || (start > LLNI_field_direct(s, count)) ||
5340 (start + len > LLNI_field_direct(s, count))) {
5341 exceptions_throw_stringindexoutofboundsexception();
5345 for (i = 0; i < len; i++)
5346 buf[i] = ca->data[LLNI_field_direct(s, offset) + start + i];
5352 /* GetPrimitiveArrayCritical ***************************************************
5354 Obtain a direct pointer to array elements.
5356 *******************************************************************************/
5358 void *_Jv_JNI_GetPrimitiveArrayCritical(JNIEnv *env, jarray array,
5364 ba = (java_bytearray *) array;
5366 /* do the same as Kaffe does */
5368 bp = _Jv_JNI_GetByteArrayElements(env, (jbyteArray) ba, isCopy);
5374 /* ReleasePrimitiveArrayCritical ***********************************************
5376 No specific documentation.
5378 *******************************************************************************/
5380 void _Jv_JNI_ReleasePrimitiveArrayCritical(JNIEnv *env, jarray array,
5381 void *carray, jint mode)
5383 STATISTICS(jniinvokation());
5385 /* do the same as Kaffe does */
5387 _Jv_JNI_ReleaseByteArrayElements(env, (jbyteArray) array, (jbyte *) carray,
5392 /* GetStringCritical ***********************************************************
5394 The semantics of these two functions are similar to the existing
5395 Get/ReleaseStringChars functions.
5397 *******************************************************************************/
5399 const jchar *_Jv_JNI_GetStringCritical(JNIEnv *env, jstring string,
5402 STATISTICS(jniinvokation());
5404 return _Jv_JNI_GetStringChars(env, string, isCopy);
5408 void _Jv_JNI_ReleaseStringCritical(JNIEnv *env, jstring string,
5409 const jchar *cstring)
5411 STATISTICS(jniinvokation());
5413 _Jv_JNI_ReleaseStringChars(env, string, cstring);
5417 jweak _Jv_JNI_NewWeakGlobalRef(JNIEnv* env, jobject obj)
5419 STATISTICS(jniinvokation());
5421 log_text("JNI-Call: NewWeakGlobalRef: IMPLEMENT ME!");
5427 void _Jv_JNI_DeleteWeakGlobalRef(JNIEnv* env, jweak ref)
5429 STATISTICS(jniinvokation());
5431 log_text("JNI-Call: DeleteWeakGlobalRef: IMPLEMENT ME");
5435 /* NewGlobalRef ****************************************************************
5437 Creates a new global reference to the object referred to by the obj
5440 *******************************************************************************/
5442 jobject _Jv_JNI_NewGlobalRef(JNIEnv* env, jobject obj)
5444 hashtable_global_ref_entry *gre;
5445 u4 key; /* hashkey */
5446 u4 slot; /* slot in hashtable */
5447 java_objectheader *o;
5449 STATISTICS(jniinvokation());
5451 o = (java_objectheader *) obj;
5453 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5455 /* normally addresses are aligned to 4, 8 or 16 bytes */
5457 key = ((u4) (ptrint) obj) >> 4; /* align to 16-byte boundaries */
5458 slot = key & (hashtable_global_ref->size - 1);
5459 gre = hashtable_global_ref->ptr[slot];
5461 /* search external hash chain for the entry */
5465 /* global object found, increment the reference */
5469 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5474 gre = gre->hashlink; /* next element in external chain */
5477 /* global ref not found, create a new one */
5479 gre = NEW(hashtable_global_ref_entry);
5484 /* insert entry into hashtable */
5486 gre->hashlink = hashtable_global_ref->ptr[slot];
5488 hashtable_global_ref->ptr[slot] = gre;
5490 /* update number of hashtable-entries */
5492 hashtable_global_ref->entries++;
5494 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5500 /* DeleteGlobalRef *************************************************************
5502 Deletes the global reference pointed to by globalRef.
5504 *******************************************************************************/
5506 void _Jv_JNI_DeleteGlobalRef(JNIEnv* env, jobject globalRef)
5508 hashtable_global_ref_entry *gre;
5509 hashtable_global_ref_entry *prevgre;
5510 u4 key; /* hashkey */
5511 u4 slot; /* slot in hashtable */
5512 java_objectheader *o;
5514 STATISTICS(jniinvokation());
5516 o = (java_objectheader *) globalRef;
5518 LOCK_MONITOR_ENTER(hashtable_global_ref->header);
5520 /* normally addresses are aligned to 4, 8 or 16 bytes */
5522 key = ((u4) (ptrint) globalRef) >> 4; /* align to 16-byte boundaries */
5523 slot = key & (hashtable_global_ref->size - 1);
5524 gre = hashtable_global_ref->ptr[slot];
5526 /* initialize prevgre */
5530 /* search external hash chain for the entry */
5534 /* global object found, decrement the reference count */
5538 /* if reference count is 0, remove the entry */
5540 if (gre->refs == 0) {
5541 /* special handling if it's the first in the chain */
5543 if (prevgre == NULL)
5544 hashtable_global_ref->ptr[slot] = gre->hashlink;
5546 prevgre->hashlink = gre->hashlink;
5548 FREE(gre, hashtable_global_ref_entry);
5551 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5556 prevgre = gre; /* save current pointer for removal */
5557 gre = gre->hashlink; /* next element in external chain */
5560 log_println("JNI-DeleteGlobalRef: global reference not found");
5562 LOCK_MONITOR_EXIT(hashtable_global_ref->header);
5566 /* ExceptionCheck **************************************************************
5568 Returns JNI_TRUE when there is a pending exception; otherwise,
5571 *******************************************************************************/
5573 jboolean _Jv_JNI_ExceptionCheck(JNIEnv *env)
5575 java_objectheader *o;
5577 STATISTICS(jniinvokation());
5579 o = exceptions_get_exception();
5581 return (o != NULL) ? JNI_TRUE : JNI_FALSE;
5585 /* New JNI 1.4 functions ******************************************************/
5587 /* NewDirectByteBuffer *********************************************************
5589 Allocates and returns a direct java.nio.ByteBuffer referring to the
5590 block of memory starting at the memory address address and
5591 extending capacity bytes.
5593 *******************************************************************************/
5595 jobject _Jv_JNI_NewDirectByteBuffer(JNIEnv *env, void *address, jlong capacity)
5597 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5598 java_objectheader *nbuf;
5600 # if SIZEOF_VOID_P == 8
5601 gnu_classpath_Pointer64 *paddress;
5603 gnu_classpath_Pointer32 *paddress;
5606 STATISTICS(jniinvokation());
5608 /* alocate a gnu.classpath.Pointer{32,64} object */
5610 # if SIZEOF_VOID_P == 8
5611 if (!(paddress = (gnu_classpath_Pointer64 *)
5612 builtin_new(class_gnu_classpath_Pointer64)))
5614 if (!(paddress = (gnu_classpath_Pointer32 *)
5615 builtin_new(class_gnu_classpath_Pointer32)))
5619 /* fill gnu.classpath.Pointer{32,64} with address */
5621 LLNI_field_set_val(paddress, data, (ptrint) address);
5623 /* create a java.nio.DirectByteBufferImpl$ReadWrite object */
5625 nbuf = (*env)->NewObject(env, class_java_nio_DirectByteBufferImpl_ReadWrite,
5626 (jmethodID) dbbirw_init, NULL, paddress,
5627 (jint) capacity, (jint) capacity, (jint) 0);
5629 /* add local reference and return the value */
5631 return _Jv_JNI_NewLocalRef(env, nbuf);
5633 vm_abort("_Jv_JNI_NewDirectByteBuffer: not implemented in this configuration");
5635 /* keep compiler happy */
5642 /* GetDirectBufferAddress ******************************************************
5644 Fetches and returns the starting address of the memory region
5645 referenced by the given direct java.nio.Buffer.
5647 *******************************************************************************/
5649 void *_Jv_JNI_GetDirectBufferAddress(JNIEnv *env, jobject buf)
5651 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5652 java_nio_DirectByteBufferImpl *nbuf;
5653 # if SIZEOF_VOID_P == 8
5654 gnu_classpath_Pointer64 *paddress;
5656 gnu_classpath_Pointer32 *paddress;
5660 STATISTICS(jniinvokation());
5662 if (!builtin_instanceof(buf, class_java_nio_Buffer))
5665 nbuf = (java_nio_DirectByteBufferImpl *) buf;
5667 # if SIZEOF_VOID_P == 8
5668 LLNI_field_get_ref(nbuf, address, paddress);
5669 /* this was the cast to avaoid warning: (gnu_classpath_Pointer64 *) nbuf->address; */
5671 LLNI_field_get_ref(nbuf, address, paddress);
5672 /* this was the cast to avaoid warning: (gnu_classpath_Pointer32 *) nbuf->address; */
5675 if (paddress == NULL)
5678 LLNI_field_get_val(paddress, data, address);
5679 /* this was the cast to avaoid warning: (void *) paddress->data */
5683 vm_abort("_Jv_JNI_GetDirectBufferAddress: not implemented in this configuration");
5685 /* keep compiler happy */
5692 /* GetDirectBufferCapacity *****************************************************
5694 Fetches and returns the capacity in bytes of the memory region
5695 referenced by the given direct java.nio.Buffer.
5697 *******************************************************************************/
5699 jlong _Jv_JNI_GetDirectBufferCapacity(JNIEnv* env, jobject buf)
5701 #if defined(ENABLE_JAVASE) && defined(WITH_CLASSPATH_GNU)
5702 java_objectheader *o;
5703 java_nio_Buffer *nbuf;
5706 STATISTICS(jniinvokation());
5708 o = (java_objectheader *) buf;
5710 if (!builtin_instanceof(o, class_java_nio_DirectByteBufferImpl))
5713 nbuf = (java_nio_Buffer *) o;
5715 LLNI_field_get_val(nbuf, cap, capacity);
5719 vm_abort("_Jv_JNI_GetDirectBufferCapacity: not implemented in this configuration");
5721 /* keep compiler happy */
5728 /* DestroyJavaVM ***************************************************************
5730 Unloads a Java VM and reclaims its resources. Only the main thread
5731 can unload the VM. The system waits until the main thread is only
5732 remaining user thread before it destroys the VM.
5734 *******************************************************************************/
5736 jint _Jv_JNI_DestroyJavaVM(JavaVM *vm)
5740 STATISTICS(jniinvokation());
5742 status = vm_destroy(vm);
5748 /* AttachCurrentThread *********************************************************
5750 Attaches the current thread to a Java VM. Returns a JNI interface
5751 pointer in the JNIEnv argument.
5753 Trying to attach a thread that is already attached is a no-op.
5755 A native thread cannot be attached simultaneously to two Java VMs.
5757 When a thread is attached to the VM, the context class loader is
5758 the bootstrap loader.
5760 *******************************************************************************/
5762 static s4 jni_attach_current_thread(void **p_env, void *thr_args, bool isdaemon)
5764 JavaVMAttachArgs *vm_aargs;
5766 #if defined(ENABLE_THREADS)
5767 if (threads_get_current_threadobject() == NULL) {
5768 vm_aargs = (JavaVMAttachArgs *) thr_args;
5770 if (vm_aargs != NULL) {
5771 if ((vm_aargs->version != JNI_VERSION_1_2) &&
5772 (vm_aargs->version != JNI_VERSION_1_4))
5773 return JNI_EVERSION;
5776 if (!threads_attach_current_thread(vm_aargs, false))
5779 if (!jni_init_localref_table())
5790 jint _Jv_JNI_AttachCurrentThread(JavaVM *vm, void **p_env, void *thr_args)
5792 STATISTICS(jniinvokation());
5794 return jni_attach_current_thread(p_env, thr_args, false);
5798 /* DetachCurrentThread *********************************************************
5800 Detaches the current thread from a Java VM. All Java monitors held
5801 by this thread are released. All Java threads waiting for this
5802 thread to die are notified.
5804 In JDK 1.1, the main thread cannot be detached from the VM. It must
5805 call DestroyJavaVM to unload the entire VM.
5807 In the JDK, the main thread can be detached from the VM.
5809 The main thread, which is the thread that created the Java VM,
5810 cannot be detached from the VM. Instead, the main thread must call
5811 JNI_DestroyJavaVM() to unload the entire VM.
5813 *******************************************************************************/
5815 jint _Jv_JNI_DetachCurrentThread(JavaVM *vm)
5817 #if defined(ENABLE_THREADS)
5818 threadobject *thread;
5820 STATISTICS(jniinvokation());
5822 thread = threads_get_current_threadobject();
5827 if (!threads_detach_thread(thread))
5835 /* GetEnv **********************************************************************
5837 If the current thread is not attached to the VM, sets *env to NULL,
5838 and returns JNI_EDETACHED. If the specified version is not
5839 supported, sets *env to NULL, and returns JNI_EVERSION. Otherwise,
5840 sets *env to the appropriate interface, and returns JNI_OK.
5842 *******************************************************************************/
5844 jint _Jv_JNI_GetEnv(JavaVM *vm, void **env, jint version)
5846 STATISTICS(jniinvokation());
5848 #if defined(ENABLE_THREADS)
5849 if (threads_get_current_threadobject() == NULL) {
5852 return JNI_EDETACHED;
5856 /* check the JNI version */
5859 case JNI_VERSION_1_1:
5860 case JNI_VERSION_1_2:
5861 case JNI_VERSION_1_4:
5869 #if defined(ENABLE_JVMTI)
5870 if ((version & JVMTI_VERSION_MASK_INTERFACE_TYPE)
5871 == JVMTI_VERSION_INTERFACE_JVMTI) {
5873 *env = (void *) jvmti_new_environment();
5882 return JNI_EVERSION;
5886 /* AttachCurrentThreadAsDaemon *************************************************
5888 Same semantics as AttachCurrentThread, but the newly-created
5889 java.lang.Thread instance is a daemon.
5891 If the thread has already been attached via either
5892 AttachCurrentThread or AttachCurrentThreadAsDaemon, this routine
5893 simply sets the value pointed to by penv to the JNIEnv of the
5894 current thread. In this case neither AttachCurrentThread nor this
5895 routine have any effect on the daemon status of the thread.
5897 *******************************************************************************/
5899 jint _Jv_JNI_AttachCurrentThreadAsDaemon(JavaVM *vm, void **penv, void *args)
5901 STATISTICS(jniinvokation());
5903 return jni_attach_current_thread(penv, args, true);
5907 /* JNI invocation table *******************************************************/
5909 const struct JNIInvokeInterface_ _Jv_JNIInvokeInterface = {
5914 _Jv_JNI_DestroyJavaVM,
5915 _Jv_JNI_AttachCurrentThread,
5916 _Jv_JNI_DetachCurrentThread,
5918 _Jv_JNI_AttachCurrentThreadAsDaemon
5922 /* JNI function table *********************************************************/
5924 struct JNINativeInterface_ _Jv_JNINativeInterface = {
5931 _Jv_JNI_DefineClass,
5933 _Jv_JNI_FromReflectedMethod,
5934 _Jv_JNI_FromReflectedField,
5935 _Jv_JNI_ToReflectedMethod,
5936 _Jv_JNI_GetSuperclass,
5937 _Jv_JNI_IsAssignableFrom,
5938 _Jv_JNI_ToReflectedField,
5942 _Jv_JNI_ExceptionOccurred,
5943 _Jv_JNI_ExceptionDescribe,
5944 _Jv_JNI_ExceptionClear,
5946 _Jv_JNI_PushLocalFrame,
5947 _Jv_JNI_PopLocalFrame,
5949 _Jv_JNI_NewGlobalRef,
5950 _Jv_JNI_DeleteGlobalRef,
5951 _Jv_JNI_DeleteLocalRef,
5952 _Jv_JNI_IsSameObject,
5953 _Jv_JNI_NewLocalRef,
5954 _Jv_JNI_EnsureLocalCapacity,
5956 _Jv_JNI_AllocObject,
5961 _Jv_JNI_GetObjectClass,
5962 _Jv_JNI_IsInstanceOf,
5964 _Jv_JNI_GetMethodID,
5966 _Jv_JNI_CallObjectMethod,
5967 _Jv_JNI_CallObjectMethodV,
5968 _Jv_JNI_CallObjectMethodA,
5969 _Jv_JNI_CallBooleanMethod,
5970 _Jv_JNI_CallBooleanMethodV,
5971 _Jv_JNI_CallBooleanMethodA,
5972 _Jv_JNI_CallByteMethod,
5973 _Jv_JNI_CallByteMethodV,
5974 _Jv_JNI_CallByteMethodA,
5975 _Jv_JNI_CallCharMethod,
5976 _Jv_JNI_CallCharMethodV,
5977 _Jv_JNI_CallCharMethodA,
5978 _Jv_JNI_CallShortMethod,
5979 _Jv_JNI_CallShortMethodV,
5980 _Jv_JNI_CallShortMethodA,
5981 _Jv_JNI_CallIntMethod,
5982 _Jv_JNI_CallIntMethodV,
5983 _Jv_JNI_CallIntMethodA,
5984 _Jv_JNI_CallLongMethod,
5985 _Jv_JNI_CallLongMethodV,
5986 _Jv_JNI_CallLongMethodA,
5987 _Jv_JNI_CallFloatMethod,
5988 _Jv_JNI_CallFloatMethodV,
5989 _Jv_JNI_CallFloatMethodA,
5990 _Jv_JNI_CallDoubleMethod,
5991 _Jv_JNI_CallDoubleMethodV,
5992 _Jv_JNI_CallDoubleMethodA,
5993 _Jv_JNI_CallVoidMethod,
5994 _Jv_JNI_CallVoidMethodV,
5995 _Jv_JNI_CallVoidMethodA,
5997 _Jv_JNI_CallNonvirtualObjectMethod,
5998 _Jv_JNI_CallNonvirtualObjectMethodV,
5999 _Jv_JNI_CallNonvirtualObjectMethodA,
6000 _Jv_JNI_CallNonvirtualBooleanMethod,
6001 _Jv_JNI_CallNonvirtualBooleanMethodV,
6002 _Jv_JNI_CallNonvirtualBooleanMethodA,
6003 _Jv_JNI_CallNonvirtualByteMethod,
6004 _Jv_JNI_CallNonvirtualByteMethodV,
6005 _Jv_JNI_CallNonvirtualByteMethodA,
6006 _Jv_JNI_CallNonvirtualCharMethod,
6007 _Jv_JNI_CallNonvirtualCharMethodV,
6008 _Jv_JNI_CallNonvirtualCharMethodA,
6009 _Jv_JNI_CallNonvirtualShortMethod,
6010 _Jv_JNI_CallNonvirtualShortMethodV,
6011 _Jv_JNI_CallNonvirtualShortMethodA,
6012 _Jv_JNI_CallNonvirtualIntMethod,
6013 _Jv_JNI_CallNonvirtualIntMethodV,
6014 _Jv_JNI_CallNonvirtualIntMethodA,
6015 _Jv_JNI_CallNonvirtualLongMethod,
6016 _Jv_JNI_CallNonvirtualLongMethodV,
6017 _Jv_JNI_CallNonvirtualLongMethodA,
6018 _Jv_JNI_CallNonvirtualFloatMethod,
6019 _Jv_JNI_CallNonvirtualFloatMethodV,
6020 _Jv_JNI_CallNonvirtualFloatMethodA,
6021 _Jv_JNI_CallNonvirtualDoubleMethod,
6022 _Jv_JNI_CallNonvirtualDoubleMethodV,
6023 _Jv_JNI_CallNonvirtualDoubleMethodA,
6024 _Jv_JNI_CallNonvirtualVoidMethod,
6025 _Jv_JNI_CallNonvirtualVoidMethodV,
6026 _Jv_JNI_CallNonvirtualVoidMethodA,
6030 _Jv_JNI_GetObjectField,
6031 _Jv_JNI_GetBooleanField,
6032 _Jv_JNI_GetByteField,
6033 _Jv_JNI_GetCharField,
6034 _Jv_JNI_GetShortField,
6035 _Jv_JNI_GetIntField,
6036 _Jv_JNI_GetLongField,
6037 _Jv_JNI_GetFloatField,
6038 _Jv_JNI_GetDoubleField,
6039 _Jv_JNI_SetObjectField,
6040 _Jv_JNI_SetBooleanField,
6041 _Jv_JNI_SetByteField,
6042 _Jv_JNI_SetCharField,
6043 _Jv_JNI_SetShortField,
6044 _Jv_JNI_SetIntField,
6045 _Jv_JNI_SetLongField,
6046 _Jv_JNI_SetFloatField,
6047 _Jv_JNI_SetDoubleField,
6049 _Jv_JNI_GetStaticMethodID,
6051 _Jv_JNI_CallStaticObjectMethod,
6052 _Jv_JNI_CallStaticObjectMethodV,
6053 _Jv_JNI_CallStaticObjectMethodA,
6054 _Jv_JNI_CallStaticBooleanMethod,
6055 _Jv_JNI_CallStaticBooleanMethodV,
6056 _Jv_JNI_CallStaticBooleanMethodA,
6057 _Jv_JNI_CallStaticByteMethod,
6058 _Jv_JNI_CallStaticByteMethodV,
6059 _Jv_JNI_CallStaticByteMethodA,
6060 _Jv_JNI_CallStaticCharMethod,
6061 _Jv_JNI_CallStaticCharMethodV,
6062 _Jv_JNI_CallStaticCharMethodA,
6063 _Jv_JNI_CallStaticShortMethod,
6064 _Jv_JNI_CallStaticShortMethodV,
6065 _Jv_JNI_CallStaticShortMethodA,
6066 _Jv_JNI_CallStaticIntMethod,
6067 _Jv_JNI_CallStaticIntMethodV,
6068 _Jv_JNI_CallStaticIntMethodA,
6069 _Jv_JNI_CallStaticLongMethod,
6070 _Jv_JNI_CallStaticLongMethodV,
6071 _Jv_JNI_CallStaticLongMethodA,
6072 _Jv_JNI_CallStaticFloatMethod,
6073 _Jv_JNI_CallStaticFloatMethodV,
6074 _Jv_JNI_CallStaticFloatMethodA,
6075 _Jv_JNI_CallStaticDoubleMethod,
6076 _Jv_JNI_CallStaticDoubleMethodV,
6077 _Jv_JNI_CallStaticDoubleMethodA,
6078 _Jv_JNI_CallStaticVoidMethod,
6079 _Jv_JNI_CallStaticVoidMethodV,
6080 _Jv_JNI_CallStaticVoidMethodA,
6082 _Jv_JNI_GetStaticFieldID,
6084 _Jv_JNI_GetStaticObjectField,
6085 _Jv_JNI_GetStaticBooleanField,
6086 _Jv_JNI_GetStaticByteField,
6087 _Jv_JNI_GetStaticCharField,
6088 _Jv_JNI_GetStaticShortField,
6089 _Jv_JNI_GetStaticIntField,
6090 _Jv_JNI_GetStaticLongField,
6091 _Jv_JNI_GetStaticFloatField,
6092 _Jv_JNI_GetStaticDoubleField,
6093 _Jv_JNI_SetStaticObjectField,
6094 _Jv_JNI_SetStaticBooleanField,
6095 _Jv_JNI_SetStaticByteField,
6096 _Jv_JNI_SetStaticCharField,
6097 _Jv_JNI_SetStaticShortField,
6098 _Jv_JNI_SetStaticIntField,
6099 _Jv_JNI_SetStaticLongField,
6100 _Jv_JNI_SetStaticFloatField,
6101 _Jv_JNI_SetStaticDoubleField,
6104 _Jv_JNI_GetStringLength,
6105 _Jv_JNI_GetStringChars,
6106 _Jv_JNI_ReleaseStringChars,
6108 _Jv_JNI_NewStringUTF,
6109 _Jv_JNI_GetStringUTFLength,
6110 _Jv_JNI_GetStringUTFChars,
6111 _Jv_JNI_ReleaseStringUTFChars,
6113 _Jv_JNI_GetArrayLength,
6115 _Jv_JNI_NewObjectArray,
6116 _Jv_JNI_GetObjectArrayElement,
6117 _Jv_JNI_SetObjectArrayElement,
6119 _Jv_JNI_NewBooleanArray,
6120 _Jv_JNI_NewByteArray,
6121 _Jv_JNI_NewCharArray,
6122 _Jv_JNI_NewShortArray,
6123 _Jv_JNI_NewIntArray,
6124 _Jv_JNI_NewLongArray,
6125 _Jv_JNI_NewFloatArray,
6126 _Jv_JNI_NewDoubleArray,
6128 _Jv_JNI_GetBooleanArrayElements,
6129 _Jv_JNI_GetByteArrayElements,
6130 _Jv_JNI_GetCharArrayElements,
6131 _Jv_JNI_GetShortArrayElements,
6132 _Jv_JNI_GetIntArrayElements,
6133 _Jv_JNI_GetLongArrayElements,
6134 _Jv_JNI_GetFloatArrayElements,
6135 _Jv_JNI_GetDoubleArrayElements,
6137 _Jv_JNI_ReleaseBooleanArrayElements,
6138 _Jv_JNI_ReleaseByteArrayElements,
6139 _Jv_JNI_ReleaseCharArrayElements,
6140 _Jv_JNI_ReleaseShortArrayElements,
6141 _Jv_JNI_ReleaseIntArrayElements,
6142 _Jv_JNI_ReleaseLongArrayElements,
6143 _Jv_JNI_ReleaseFloatArrayElements,
6144 _Jv_JNI_ReleaseDoubleArrayElements,
6146 _Jv_JNI_GetBooleanArrayRegion,
6147 _Jv_JNI_GetByteArrayRegion,
6148 _Jv_JNI_GetCharArrayRegion,
6149 _Jv_JNI_GetShortArrayRegion,
6150 _Jv_JNI_GetIntArrayRegion,
6151 _Jv_JNI_GetLongArrayRegion,
6152 _Jv_JNI_GetFloatArrayRegion,
6153 _Jv_JNI_GetDoubleArrayRegion,
6154 _Jv_JNI_SetBooleanArrayRegion,
6155 _Jv_JNI_SetByteArrayRegion,
6156 _Jv_JNI_SetCharArrayRegion,
6157 _Jv_JNI_SetShortArrayRegion,
6158 _Jv_JNI_SetIntArrayRegion,
6159 _Jv_JNI_SetLongArrayRegion,
6160 _Jv_JNI_SetFloatArrayRegion,
6161 _Jv_JNI_SetDoubleArrayRegion,
6163 _Jv_JNI_RegisterNatives,
6164 _Jv_JNI_UnregisterNatives,
6166 _Jv_JNI_MonitorEnter,
6167 _Jv_JNI_MonitorExit,
6171 /* new JNI 1.2 functions */
6173 _Jv_JNI_GetStringRegion,
6174 _Jv_JNI_GetStringUTFRegion,
6176 _Jv_JNI_GetPrimitiveArrayCritical,
6177 _Jv_JNI_ReleasePrimitiveArrayCritical,
6179 _Jv_JNI_GetStringCritical,
6180 _Jv_JNI_ReleaseStringCritical,
6182 _Jv_JNI_NewWeakGlobalRef,
6183 _Jv_JNI_DeleteWeakGlobalRef,
6185 _Jv_JNI_ExceptionCheck,
6187 /* new JNI 1.4 functions */
6189 _Jv_JNI_NewDirectByteBuffer,
6190 _Jv_JNI_GetDirectBufferAddress,
6191 _Jv_JNI_GetDirectBufferCapacity
6195 /* Invocation API Functions ***************************************************/
6197 /* JNI_GetDefaultJavaVMInitArgs ************************************************
6199 Returns a default configuration for the Java VM.
6201 *******************************************************************************/
6203 jint JNI_GetDefaultJavaVMInitArgs(void *vm_args)
6205 JavaVMInitArgs *_vm_args;
6207 _vm_args = (JavaVMInitArgs *) vm_args;
6209 /* GNU classpath currently supports JNI 1.2 */
6211 switch (_vm_args->version) {
6212 case JNI_VERSION_1_1:
6213 _vm_args->version = JNI_VERSION_1_1;
6216 case JNI_VERSION_1_2:
6217 case JNI_VERSION_1_4:
6218 _vm_args->ignoreUnrecognized = JNI_FALSE;
6219 _vm_args->options = NULL;
6220 _vm_args->nOptions = 0;
6231 /* JNI_GetCreatedJavaVMs *******************************************************
6233 Returns all Java VMs that have been created. Pointers to VMs are written in
6234 the buffer vmBuf in the order they are created. At most bufLen number of
6235 entries will be written. The total number of created VMs is returned in
6238 *******************************************************************************/
6240 jint JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs)
6242 TRACEJNICALLS("JNI_GetCreatedJavaVMs(vmBuf=%p, jsize=%d, jsize=%p)", vmBuf, bufLen, nVMs);
6247 /* We currently only support 1 VM running. */
6249 vmBuf[0] = (JavaVM *) _Jv_jvm;
6256 /* JNI_CreateJavaVM ************************************************************
6258 Loads and initializes a Java VM. The current thread becomes the main thread.
6259 Sets the env argument to the JNI interface pointer of the main thread.
6261 *******************************************************************************/
6263 jint JNI_CreateJavaVM(JavaVM **p_vm, void **p_env, void *vm_args)
6265 TRACEJNICALLS("JNI_CreateJavaVM(p_vm=%p, p_env=%p, vm_args=%p)", p_vm, p_env, vm_args);
6267 /* actually create the JVM */
6269 if (!vm_createjvm(p_vm, p_env, vm_args))
6277 * These are local overrides for various environment variables in Emacs.
6278 * Please do not remove this and leave it at the end of the file, where
6279 * Emacs will automagically detect them.
6280 * ---------------------------------------------------------------------
6283 * indent-tabs-mode: t
6287 * vim:noexpandtab:sw=4:ts=4: