1 /* jni.c - implementation of the Java Native Interface functions
3 Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5 M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6 P. Tomsich, J. Wenninger
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., 59 Temple Place - Suite 330, Boston, MA
25 Contact: cacao@complang.tuwien.ac.at
29 Changes: Joseph Wenninger
31 $Id: jni.c 1005 2004-03-30 23:01:45Z twisti $
43 #include "threads/thread.h"
44 #include "toolbox/loging.h"
45 #include "toolbox/memory.h"
46 #include "nat/java_lang_Byte.h"
47 #include "nat/java_lang_Character.h"
48 #include "nat/java_lang_Short.h"
49 #include "nat/java_lang_Integer.h"
50 #include "nat/java_lang_Boolean.h"
51 #include "nat/java_lang_Long.h"
52 #include "nat/java_lang_Float.h"
53 #include "nat/java_lang_Double.h"
54 #include "nat/java_lang_Throwable.h"
57 #define JNI_VERSION 0x00010002
60 #define PTR_TO_ITEM(ptr) ((u8)(size_t)(ptr))
62 static utf* utf_char = 0;
63 static utf* utf_bool = 0;
64 static utf* utf_byte =0;
65 static utf* utf_short = 0;
66 static utf* utf_int = 0;
67 static utf* utf_long = 0;
68 static utf* utf_float = 0;
69 static utf* utf_double = 0;
72 /********************* accessing instance-fields **********************************/
74 #define setField(obj,typ,var,val) *((typ*) ((long int) obj + (long int) var->offset))=val;
75 #define getField(obj,typ,var) *((typ*) ((long int) obj + (long int) var->offset))
76 #define setfield_critical(clazz,obj,name,sig,jdatatype,val) setField(obj,jdatatype,getFieldID_critical(env,clazz,name,sig),val);
80 u4 get_parametercount(methodinfo *m)
82 utf *descr = m->descriptor; /* method-descriptor */
83 char *utf_ptr = descr->text; /* current position in utf-text */
84 char *desc_end = utf_end(descr); /* points behind utf string */
85 u4 parametercount = 0;
90 /* determine number of parameters */
91 while (*utf_ptr != ')') {
92 get_type(&utf_ptr, desc_end, true);
96 return parametercount;
101 void fill_callblock(void *obj, utf *descr, jni_callblock blk[], va_list data, char ret)
103 char *utf__ptr = descr->text; /* current position in utf-text */
104 char **utf_ptr = &utf__ptr;
105 char *desc_end = utf_end(descr); /* points behind utf string */
111 log_text("fill_callblock");
118 /* determine number of parameters */
120 blk[0].itemtype = TYPE_ADR;
121 blk[0].item = PTR_TO_ITEM(obj);
125 while (**utf_ptr != ')') {
126 if (*utf_ptr >= desc_end)
127 panic("illegal method descriptor");
129 switch (utf_nextu2(utf_ptr)) {
130 /* primitive types */
135 blk[cnt].itemtype = TYPE_INT;
136 blk[cnt].item = (u8) va_arg(data, int);
140 blk[cnt].itemtype = TYPE_INT;
141 dummy = va_arg(data, u4);
142 /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
143 blk[cnt].item = (u8) dummy;
147 blk[cnt].itemtype = TYPE_LNG;
148 blk[cnt].item = (u8) va_arg(data, jlong);
152 blk[cnt].itemtype = TYPE_FLT;
153 *((jfloat *) (&blk[cnt].item)) = (jfloat) va_arg(data, jdouble);
157 blk[cnt].itemtype = TYPE_DBL;
158 *((jdouble *) (&blk[cnt].item)) = (jdouble) va_arg(data, jdouble);
162 panic ("V not allowed as function parameter");
166 while (utf_nextu2(utf_ptr) != ';')
167 blk[cnt].itemtype = TYPE_ADR;
168 blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
175 /* char *start = *utf_ptr; */
177 while ((ch = utf_nextu2(utf_ptr)) == '[')
179 while (utf_nextu2(utf_ptr) != ';') {}
182 ch = utf_nextu2(utf_ptr);
183 blk[cnt].itemtype = TYPE_ADR;
184 blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
191 /*the standard doesn't say anything about return value checking, but it appears to be usefull*/
192 c = utf_nextu2(utf_ptr);
193 c = utf_nextu2(utf_ptr);
194 /*printf("%c %c\n",ret,c);*/
196 if (!((c == 'L') || (c == '[')))
197 log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
199 log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
203 /* XXX it could be considered if we should do typechecking here in the future */
204 char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_objectarray* params)
206 char *utf__ptr = descr->text; /* current position in utf-text */
207 char **utf_ptr = &utf__ptr;
208 char *desc_end = utf_end(descr); /* points behind utf string */
215 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
219 utf_char=utf_new_char("java/lang/Character");
220 utf_bool=utf_new_char("java/lang/Boolean");
221 utf_byte=utf_new_char("java/lang/Byte");
222 utf_short=utf_new_char("java/lang/Short");
223 utf_int=utf_new_char("java/lang/Integer");
224 utf_long=utf_new_char("java/lang/Long");
225 utf_float=utf_new_char("java/lang/Float");
226 utf_double=utf_new_char("java/lang/Double");
228 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
233 log_text("fill_callblock");
240 /* determine number of parameters */
242 blk[0].itemtype = TYPE_ADR;
243 blk[0].item = PTR_TO_ITEM(obj);
251 while (**utf_ptr != ')') {
252 if (*utf_ptr >= desc_end)
253 panic("illegal method descriptor");
255 /* primitive types */
256 switch (utf_nextu2(utf_ptr)) {
258 param = params->data[cnts];
260 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
263 if (param->vftbl->class->name == utf_byte) {
264 blk[cnt].itemtype = TYPE_INT;
265 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
268 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
274 param = params->data[cnts];
276 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
279 if (param->vftbl->class->name == utf_char) {
280 blk[cnt].itemtype = TYPE_INT;
281 blk[cnt].item = (u8) ((java_lang_Character *) param)->value;
284 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
290 param = params->data[cnts];
292 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
295 if (param->vftbl->class->name == utf_short) {
296 blk[cnt].itemtype = TYPE_INT;
297 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
300 if (param->vftbl->class->name == utf_byte) {
301 blk[cnt].itemtype = TYPE_INT;
302 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
305 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
312 param = params->data[cnts];
314 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
317 if (param->vftbl->class->name == utf_bool) {
318 blk[cnt].itemtype = TYPE_INT;
319 blk[cnt].item = (u8) ((java_lang_Boolean *) param)->value;
322 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
328 /*log_text("fill_callblock_objA: param 'I'");*/
329 param = params->data[cnts];
331 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
334 if (param->vftbl->class->name == utf_int) {
335 blk[cnt].itemtype = TYPE_INT;
336 blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
337 /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
339 if (param->vftbl->class->name == utf_short) {
340 blk[cnt].itemtype = TYPE_INT;
341 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
344 if (param->vftbl->class->name == utf_byte) {
345 blk[cnt].itemtype = TYPE_INT;
346 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
349 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
357 param = params->data[cnts];
359 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
362 if (param->vftbl->class->name == utf_long) {
363 blk[cnt].itemtype = TYPE_LNG;
364 blk[cnt].item = (u8) ((java_lang_Long *) param)->value;
367 if (param->vftbl->class->name == utf_int) {
368 blk[cnt].itemtype = TYPE_LNG;
369 blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
372 if (param->vftbl->class->name == utf_short) {
373 blk[cnt].itemtype = TYPE_LNG;
374 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
377 if (param->vftbl->class->name == utf_byte) {
378 blk[cnt].itemtype = TYPE_LNG;
379 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
381 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
391 param = params->data[cnts];
393 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
397 if (param->vftbl->class->name == utf_float) {
398 blk[cnt].itemtype = TYPE_FLT;
399 *((jfloat *) (&blk[cnt].item)) = (jfloat) ((java_lang_Float *) param)->value;
402 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
408 param = params->data[cnts];
410 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
414 if (param->vftbl->class->name == utf_double) {
415 blk[cnt].itemtype = TYPE_DBL;
416 *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
419 if (param->vftbl->class->name == utf_float) {
420 blk[cnt].itemtype = TYPE_DBL;
421 *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
424 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
431 panic("V not allowed as function parameter");
436 char *start = (*utf_ptr) - 1;
439 while (utf_nextu2(utf_ptr) != ';')
440 end = (*utf_ptr) + 1;
442 if (!builtin_instanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD))) {
443 if (params->data[cnts] != 0) {
444 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
449 blk[cnt].itemtype = TYPE_ADR;
450 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
456 char *start = (*utf_ptr) - 1;
460 while ((ch = utf_nextu2(utf_ptr)) == '[')
462 while (utf_nextu2(utf_ptr) != ';') {}
465 end = (*utf_ptr) - 1;
466 ch = utf_nextu2(utf_ptr);
468 if (!builtin_arrayinstanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD)->vftbl)) {
469 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
473 blk[cnt].itemtype = TYPE_ADR;
474 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
482 c = utf_nextu2(utf_ptr);
483 c = utf_nextu2(utf_ptr);
484 return c; /*return type needed usage of the right lowlevel methods*/
501 jmethodID get_virtual(jobject obj,jmethodID methodID) {
502 if (obj->vftbl->class==methodID->class) return methodID;
503 return class_resolvemethod (obj->vftbl->class, methodID->name, methodID->descriptor);
506 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
507 if (clazz==methodID->class) return methodID;
508 return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
513 jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
520 log_text("JNI-Call: CallObjectMethodV");
521 utf_display(methodID->name);
522 utf_display(methodID->descriptor);
523 printf("\nParmaeter count: %d\n",argcount);
524 utf_display(obj->vftbl->class->name);
529 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
533 argcount = get_parametercount(methodID);
535 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
536 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
537 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
541 if (obj && !builtin_instanceof(obj, methodID->class)) {
542 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
547 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
548 log_text("Too many arguments. CallObjectMethod does not support that");
552 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
554 fill_callblock(obj, methodID->descriptor, blk, args, 'O');
556 /* printf("parameter: obj: %p",blk[0].item); */
557 ret = asm_calljavafunction2(methodID,
559 (argcount + 1) * sizeof(jni_callblock),
562 MFREE(blk, jni_callblock, argcount + 1);
563 /* printf("(CallObjectMethodV)-->%p\n",ret); */
569 core function for integer class methods (bool, byte, short, integer)
570 This is basically needed for i386
572 jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list args)
578 /* printf("%p, %c\n",retType,methodID,retType);*/
581 log_text("JNI-Call: CallObjectMethodV");
582 utf_display(methodID->name);
583 utf_display(methodID->descriptor);
584 printf("\nParmaeter count: %d\n",argcount);
585 utf_display(obj->vftbl->class->name);
589 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
593 argcount = get_parametercount(methodID);
595 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
596 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
597 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
601 if (obj && !builtin_instanceof(obj, methodID->class)) {
602 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
608 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
609 log_text("Too many arguments. CallIntegerMethod does not support that");
613 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
615 fill_callblock(obj, methodID->descriptor, blk, args, retType);
617 /* printf("parameter: obj: %p",blk[0].item); */
618 ret = (jint) asm_calljavafunction2(methodID,
620 (argcount + 1) * sizeof(jni_callblock),
623 MFREE(blk, jni_callblock, argcount + 1);
624 /* printf("(CallObjectMethodV)-->%p\n",ret); */
630 /*core function for long class functions*/
631 jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
638 log_text("JNI-Call: CallObjectMethodV");
639 utf_display(methodID->name);
640 utf_display(methodID->descriptor);
641 printf("\nParmaeter count: %d\n",argcount);
642 utf_display(obj->vftbl->class->name);
646 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
650 argcount = get_parametercount(methodID);
652 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
653 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
654 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
658 if (obj && !builtin_instanceof(obj,methodID->class)) {
659 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
665 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
666 log_text("Too many arguments. CallObjectMethod does not support that");
670 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
672 fill_callblock(obj, methodID->descriptor, blk, args, 'L');
674 /* printf("parameter: obj: %p",blk[0].item); */
675 ret = asm_calljavafunction2long(methodID,
677 (argcount + 1) * sizeof(jni_callblock),
680 MFREE(blk, jni_callblock, argcount + 1);
681 /* printf("(CallObjectMethodV)-->%p\n",ret); */
687 /*core function for float class methods (float,double)*/
688 jdouble callFloatMethod(jobject obj, jmethodID methodID, va_list args,char retType)
690 int argcount = get_parametercount(methodID);
695 log_text("JNI-Call: CallObjectMethodV");
696 utf_display(methodID->name);
697 utf_display(methodID->descriptor);
698 printf("\nParmaeter count: %d\n",argcount);
699 utf_display(obj->vftbl->class->name);
704 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
705 log_text("Too many arguments. CallObjectMethod does not support that");
709 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
711 fill_callblock(obj, methodID->descriptor, blk, args, retType);
713 /* printf("parameter: obj: %p",blk[0].item); */
714 ret = asm_calljavafunction2double(methodID,
716 (argcount + 1) * sizeof(jni_callblock),
719 MFREE(blk, jni_callblock, argcount + 1);
720 /* printf("(CallObjectMethodV)-->%p\n",ret); */
726 /*************************** function: jclass_findfield ****************************
728 searches for field with specified name and type in a 'classinfo'-structur
729 if no such field is found NULL is returned
731 ************************************************************************************/
733 fieldinfo *jclass_findfield (classinfo *c, utf *name, utf *desc)
736 /* printf(" FieldCount: %d\n",c->fieldscount);
737 utf_display(c->name); */
738 for (i = 0; i < c->fieldscount; i++) {
739 /* utf_display(c->fields[i].name);
741 utf_display(c->fields[i].descriptor);
743 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
744 return &(c->fields[i]);
747 if (c->super) return jclass_findfield(c->super,name,desc);
752 /********************* returns version of native method interface *****************/
754 jint GetVersion (JNIEnv* env)
759 /****************** loads a class from a buffer of raw class data *****************/
761 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len)
765 /* change suck-mode, so subsequent class_load will read from memory-buffer */
766 classload_buffer( (u1*) buf,len);
768 clazz = loader_load(utf_new_char ((char *) name));
770 /* restore old suck-mode */
771 classload_buffer(NULL,0);
772 if (clazz) clazz->classloader=loader;
777 /*************** loads locally defined class with the specified name **************/
779 jclass FindClass(JNIEnv* env, const char *name)
783 /* if (strcmp(name,"[B")==0) {
784 c = loader_load(utf_new_char("The_Array_Class"));
787 c = loader_load(utf_new_char_classname((char *) name));
790 *exceptionptr = new_exception(string_java_lang_ClassFormatError);
796 /***********************************************************************************
798 converts java.lang.reflect.Method or
799 java.lang.reflect.Constructor object to a method ID
801 **********************************************************************************/
803 jmethodID FromReflectedMethod(JNIEnv* env, jobject method)
805 /* log_text("JNI-Call: FromReflectedMethod"); */
811 /*************** return superclass of the class represented by sub ****************/
813 jclass GetSuperclass(JNIEnv* env, jclass sub)
817 c = ((classinfo*) sub)->super;
821 use_class_as_object(c);
827 /*********************** check whether sub can be cast to sup ********************/
829 jboolean IsAssignableForm(JNIEnv* env, jclass sub, jclass sup)
831 return builtin_isanysubclass(sub, sup);
835 /***** converts a field ID derived from cls to a java.lang.reflect.Field object ***/
837 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isStatic)
839 /* log_text("JNI-Call: ToReflectedField"); */
845 /***************** throw java.lang.Throwable object ******************************/
847 jint Throw(JNIEnv* env, jthrowable obj)
849 *exceptionptr = (java_objectheader*) obj;
855 /*******************************************************************************
857 create exception object from the class clazz with the
858 specified message and cause it to be thrown
860 *******************************************************************************/
862 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
864 java_lang_Throwable *o;
866 /* instantiate exception object */
867 o = (java_lang_Throwable *) native_new_and_init((classinfo*) clazz);
871 o->detailMessage = (java_lang_String *) javastring_new_char((char *) msg);
873 *exceptionptr = (java_objectheader *) o;
879 /************************* check if exception occured *****************************/
881 jthrowable ExceptionOccurred (JNIEnv* env)
883 return (jthrowable) *exceptionptr;
886 /********** print exception and a backtrace of the stack (for debugging) **********/
888 void ExceptionDescribe (JNIEnv* env)
890 utf_display((*exceptionptr)->vftbl->class->name);
896 /******************* clear any exception currently being thrown *******************/
898 void ExceptionClear (JNIEnv* env)
900 *exceptionptr = NULL;
904 /********** raises a fatal error and does not expect the VM to recover ************/
906 void FatalError (JNIEnv* env, const char *msg)
911 /******************* creates a new local reference frame **************************/
913 jint PushLocalFrame(JNIEnv* env, jint capacity)
920 /**************** Pops off the current local reference frame **********************/
922 jobject PopLocalFrame(JNIEnv* env, jobject result)
930 /** Creates a new global reference to the object referred to by the obj argument **/
932 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
937 /************* Deletes the global reference pointed to by globalRef **************/
939 void DeleteGlobalRef (JNIEnv* env, jobject gref)
945 /*************** Deletes the local reference pointed to by localRef ***************/
947 void DeleteLocalRef (JNIEnv* env, jobject localRef)
952 /********** Tests whether two references refer to the same Java object ************/
954 jboolean IsSameObject (JNIEnv* env, jobject obj1, jobject obj2)
959 /***** Creates a new local reference that refers to the same object as ref *******/
961 jobject NewLocalRef (JNIEnv* env, jobject ref)
966 /***********************************************************************************
968 Ensures that at least a given number of local references can
969 be created in the current thread
971 **********************************************************************************/
973 jint EnsureLocalCapacity (JNIEnv* env, jint capacity)
975 return 0; /* return 0 on success */
979 /********* Allocates a new Java object without invoking a constructor *************/
981 jobject AllocObject (JNIEnv* env, jclass clazz)
983 java_objectheader *o = builtin_new(clazz);
988 /***********************************************************************************
990 Constructs a new Java object
991 arguments that are to be passed to the constructor are placed after methodID
993 ***********************************************************************************/
995 jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
997 java_objectheader *o;
999 int argcount=get_parametercount(methodID);
1003 /* log_text("JNI-Call: NewObject"); */
1006 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
1007 log_text("Too many arguments. NewObject does not support that");
1012 o = builtin_new (clazz); /* create object */
1014 if (!o) return NULL;
1016 va_start(vaargs,methodID);
1017 for (i=0;i<argcount;i++) {
1018 args[i]=va_arg(vaargs,void*);
1021 asm_calljavafunction(methodID,o,args[0],args[1],args[2]);
1027 /***********************************************************************************
1029 Constructs a new Java object
1030 arguments that are to be passed to the constructor are placed in va_list args
1032 ***********************************************************************************/
1034 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1036 /* log_text("JNI-Call: NewObjectV"); */
1042 /***********************************************************************************
1044 Constructs a new Java object
1045 arguments that are to be passed to the constructor are placed in
1046 args array of jvalues
1048 ***********************************************************************************/
1050 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1052 /* log_text("JNI-Call: NewObjectA"); */
1058 /************************ returns the class of an object **************************/
1060 jclass GetObjectClass(JNIEnv* env, jobject obj)
1062 classinfo *c = obj->vftbl->class;
1064 use_class_as_object(c);
1070 /************* tests whether an object is an instance of a class ******************/
1072 jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz)
1074 return builtin_instanceof(obj,clazz);
1078 /***************** converts a java.lang.reflect.Field to a field ID ***************/
1080 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1082 log_text("JNI-Call: FromReflectedField");
1088 /**********************************************************************************
1090 converts a method ID to a java.lang.reflect.Method or
1091 java.lang.reflect.Constructor object
1093 **********************************************************************************/
1095 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1097 log_text("JNI-Call: ToReflectedMethod");
1103 /**************** returns the method ID for an instance method ********************/
1105 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *sig)
1109 m = class_resolvemethod (
1111 utf_new_char ((char*) name),
1112 utf_new_char ((char*) sig)
1115 if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1121 /******************** JNI-functions for calling instance methods ******************/
1123 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1128 /* log_text("JNI-Call: CallObjectMethod");*/
1130 va_start(vaargs, methodID);
1131 ret = callObjectMethod(obj, methodID, vaargs);
1138 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1140 return callObjectMethod(obj,methodID,args);
1144 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1146 log_text("JNI-Call: CallObjectMethodA");
1154 jboolean CallBooleanMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1159 /* log_text("JNI-Call: CallBooleanMethod");*/
1161 va_start(vaargs,methodID);
1162 ret = (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',vaargs);
1168 jboolean CallBooleanMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1170 return (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',args);
1174 jboolean CallBooleanMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1176 log_text("JNI-Call: CallBooleanMethodA");
1181 jbyte CallByteMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1186 /* log_text("JNI-Call: CallVyteMethod");*/
1188 va_start(vaargs,methodID);
1189 ret = callIntegerMethod(obj,get_virtual(obj,methodID),'B',vaargs);
1195 jbyte CallByteMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1197 /* log_text("JNI-Call: CallByteMethodV");*/
1198 return callIntegerMethod(obj,methodID,'B',args);
1202 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1204 log_text("JNI-Call: CallByteMethodA");
1210 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1215 /* log_text("JNI-Call: CallCharMethod");*/
1217 va_start(vaargs,methodID);
1218 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'C', vaargs);
1225 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1227 /* log_text("JNI-Call: CallCharMethodV");*/
1228 return callIntegerMethod(obj,get_virtual(obj,methodID),'C',args);
1232 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1234 log_text("JNI-Call: CallCharMethodA");
1240 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1245 /* log_text("JNI-Call: CallShortMethod");*/
1247 va_start(vaargs, methodID);
1248 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'S', vaargs);
1255 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1257 return callIntegerMethod(obj, get_virtual(obj, methodID), 'S', args);
1261 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1263 log_text("JNI-Call: CallShortMethodA");
1270 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1275 va_start(vaargs,methodID);
1276 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'I', vaargs);
1283 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1285 return callIntegerMethod(obj, get_virtual(obj, methodID), 'I', args);
1289 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1291 log_text("JNI-Call: CallIntMethodA");
1298 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1300 log_text("JNI-Call: CallLongMethod");
1306 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1308 log_text("JNI-Call: CallLongMethodV");
1314 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1316 log_text("JNI-Call: CallLongMethodA");
1323 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1328 /* log_text("JNI-Call: CallFloatMethod");*/
1330 va_start(vaargs,methodID);
1331 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'F');
1338 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1340 log_text("JNI-Call: CallFloatMethodV");
1341 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'F');
1345 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1347 log_text("JNI-Call: CallFloatMethodA");
1354 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1359 /* log_text("JNI-Call: CallDoubleMethod");*/
1361 va_start(vaargs,methodID);
1362 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'D');
1369 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1371 log_text("JNI-Call: CallDoubleMethodV");
1372 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'D');
1376 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1378 log_text("JNI-Call: CallDoubleMethodA");
1384 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1388 /* log_text("JNI-Call: CallVoidMethod");*/
1390 va_start(vaargs,methodID);
1391 (void) callIntegerMethod(obj, get_virtual(obj, methodID), 'V', vaargs);
1396 void CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1398 log_text("JNI-Call: CallVoidMethodV");
1399 (void)callIntegerMethod(obj,get_virtual(obj,methodID),'V',args);
1403 void CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1405 log_text("JNI-Call: CallVoidMethodA");
1410 jobject CallNonvirtualObjectMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1412 log_text("JNI-Call: CallNonvirtualObjectMethod");
1418 jobject CallNonvirtualObjectMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1420 log_text("JNI-Call: CallNonvirtualObjectMethodV");
1426 jobject CallNonvirtualObjectMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1428 log_text("JNI-Call: CallNonvirtualObjectMethodA");
1435 jboolean CallNonvirtualBooleanMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1440 /* log_text("JNI-Call: CallNonvirtualBooleanMethod");*/
1442 va_start(vaargs,methodID);
1443 ret = (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',vaargs);
1450 jboolean CallNonvirtualBooleanMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1452 /* log_text("JNI-Call: CallNonvirtualBooleanMethodV");*/
1453 return (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',args);
1457 jboolean CallNonvirtualBooleanMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1459 log_text("JNI-Call: CallNonvirtualBooleanMethodA");
1466 jbyte CallNonvirtualByteMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1471 /* log_text("JNI-Call: CallNonvirutalByteMethod");*/
1473 va_start(vaargs,methodID);
1474 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',vaargs);
1480 jbyte CallNonvirtualByteMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1482 /*log_text("JNI-Call: CallNonvirtualByteMethodV"); */
1483 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',args);
1488 jbyte CallNonvirtualByteMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1490 log_text("JNI-Call: CallNonvirtualByteMethodA");
1497 jchar CallNonvirtualCharMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1502 /* log_text("JNI-Call: CallNonVirtualCharMethod");*/
1504 va_start(vaargs,methodID);
1505 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',vaargs);
1511 jchar CallNonvirtualCharMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1513 /*log_text("JNI-Call: CallNonvirtualCharMethodV");*/
1514 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',args);
1518 jchar CallNonvirtualCharMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1520 log_text("JNI-Call: CallNonvirtualCharMethodA");
1527 jshort CallNonvirtualShortMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1532 /*log_text("JNI-Call: CallNonvirtualShortMethod");*/
1534 va_start(vaargs,methodID);
1535 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',vaargs);
1541 jshort CallNonvirtualShortMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1543 /*log_text("JNI-Call: CallNonvirtualShortMethodV");*/
1544 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',args);
1548 jshort CallNonvirtualShortMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1550 log_text("JNI-Call: CallNonvirtualShortMethodA");
1557 jint CallNonvirtualIntMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1563 /*log_text("JNI-Call: CallNonvirtualIntMethod");*/
1565 va_start(vaargs,methodID);
1566 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',vaargs);
1572 jint CallNonvirtualIntMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1574 /*log_text("JNI-Call: CallNonvirtualIntMethodV");*/
1575 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',args);
1579 jint CallNonvirtualIntMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1581 log_text("JNI-Call: CallNonvirtualIntMethodA");
1588 jlong CallNonvirtualLongMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1590 log_text("JNI-Call: CallNonvirtualLongMethod");
1596 jlong CallNonvirtualLongMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1598 log_text("JNI-Call: CallNonvirtualLongMethodV");
1604 jlong CallNonvirtualLongMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1606 log_text("JNI-Call: CallNonvirtualLongMethodA");
1613 jfloat CallNonvirtualFloatMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1618 /*log_text("JNI-Call: CallNonvirtualFloatMethod");*/
1621 va_start(vaargs,methodID);
1622 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'F');
1629 jfloat CallNonvirtualFloatMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1631 log_text("JNI-Call: CallNonvirtualFloatMethodV");
1632 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'F');
1636 jfloat CallNonvirtualFloatMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1638 log_text("JNI-Call: CallNonvirtualFloatMethodA");
1645 jdouble CallNonvirtualDoubleMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1649 log_text("JNI-Call: CallNonvirtualDoubleMethod");
1651 va_start(vaargs,methodID);
1652 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'D');
1659 jdouble CallNonvirtualDoubleMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1661 /* log_text("JNI-Call: CallNonvirtualDoubleMethodV");*/
1662 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'D');
1666 jdouble CallNonvirtualDoubleMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1668 log_text("JNI-Call: CallNonvirtualDoubleMethodA");
1675 void CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1679 /* log_text("JNI-Call: CallNonvirtualVoidMethod");*/
1681 va_start(vaargs,methodID);
1682 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',vaargs);
1688 void CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1690 /* log_text("JNI-Call: CallNonvirtualVoidMethodV");*/
1692 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',args);
1697 void CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1699 log_text("JNI-Call: CallNonvirtualVoidMethodA");
1702 /************************* JNI-functions for accessing fields ************************/
1704 jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
1708 /* log_text("========================= searching for:");
1711 f = jclass_findfield(clazz,
1712 utf_new_char ((char*) name),
1713 utf_new_char ((char*) sig)
1717 /* utf_display(clazz->name);
1720 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
1725 /*************************** retrieve fieldid, abort on error ************************/
1727 jfieldID getFieldID_critical(JNIEnv *env, jclass clazz, char *name, char *sig)
1729 jfieldID id = GetFieldID(env, clazz, name, sig);
1733 utf_display(clazz->name);
1734 log_text("\nfield:");
1739 panic("setfield_critical failed");
1744 jobject GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
1746 return getField(obj,jobject,fieldID);
1749 jboolean GetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID)
1751 return getField(obj,jboolean,fieldID);
1755 jbyte GetByteField (JNIEnv *env, jobject obj, jfieldID fieldID)
1757 return getField(obj,jbyte,fieldID);
1761 jchar GetCharField (JNIEnv *env, jobject obj, jfieldID fieldID)
1763 return getField(obj,jchar,fieldID);
1767 jshort GetShortField (JNIEnv *env, jobject obj, jfieldID fieldID)
1769 return getField(obj,jshort,fieldID);
1773 jint GetIntField (JNIEnv *env, jobject obj, jfieldID fieldID)
1775 return getField(obj,jint,fieldID);
1779 jlong GetLongField (JNIEnv *env, jobject obj, jfieldID fieldID)
1781 return getField(obj,jlong,fieldID);
1785 jfloat GetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID)
1787 return getField(obj,jfloat,fieldID);
1791 jdouble GetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID)
1793 return getField(obj,jdouble,fieldID);
1796 void SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
1798 setField(obj,jobject,fieldID,val);
1802 void SetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val)
1804 setField(obj,jboolean,fieldID,val);
1808 void SetByteField (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val)
1810 setField(obj,jbyte,fieldID,val);
1814 void SetCharField (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val)
1816 setField(obj,jchar,fieldID,val);
1820 void SetShortField (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val)
1822 setField(obj,jshort,fieldID,val);
1826 void SetIntField (JNIEnv *env, jobject obj, jfieldID fieldID, jint val)
1828 setField(obj,jint,fieldID,val);
1832 void SetLongField (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val)
1834 setField(obj,jlong,fieldID,val);
1838 void SetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val)
1840 setField(obj,jfloat,fieldID,val);
1844 void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
1846 setField(obj,jdouble,fieldID,val);
1850 /**************** JNI-functions for calling static methods **********************/
1852 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
1856 m = class_resolvemethod(clazz,
1857 utf_new_char((char *) name),
1858 utf_new_char((char *) sig));
1860 if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1866 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1868 log_text("JNI-Call: CallStaticObjectMethod");
1874 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1876 log_text("JNI-Call: CallStaticObjectMethodV");
1882 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1884 log_text("JNI-Call: CallStaticObjectMethodA");
1890 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1895 /* log_text("JNI-Call: CallStaticBooleanMethod");*/
1897 va_start(vaargs, methodID);
1898 ret = (jboolean) callIntegerMethod(0, methodID, 'Z', vaargs);
1905 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1907 return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
1911 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1913 log_text("JNI-Call: CallStaticBooleanMethodA");
1919 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1924 /* log_text("JNI-Call: CallStaticByteMethod");*/
1926 va_start(vaargs, methodID);
1927 ret = (jbyte) callIntegerMethod(0, methodID, 'B', vaargs);
1934 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1936 return (jbyte) callIntegerMethod(0, methodID, 'B', args);
1940 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1942 log_text("JNI-Call: CallStaticByteMethodA");
1948 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1953 /* log_text("JNI-Call: CallStaticByteMethod");*/
1955 va_start(vaargs, methodID);
1956 ret = (jchar) callIntegerMethod(0, methodID, 'C', vaargs);
1963 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1965 return (jchar) callIntegerMethod(0, methodID, 'C', args);
1969 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1971 log_text("JNI-Call: CallStaticCharMethodA");
1978 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1983 /* log_text("JNI-Call: CallStaticByteMethod");*/
1985 va_start(vaargs, methodID);
1986 ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
1993 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1995 /*log_text("JNI-Call: CallStaticShortMethodV");*/
1996 return (jshort) callIntegerMethod(0, methodID, 'S', args);
2000 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2002 log_text("JNI-Call: CallStaticShortMethodA");
2009 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2014 /* log_text("JNI-Call: CallStaticIntMethod");*/
2016 va_start(vaargs, methodID);
2017 ret = callIntegerMethod(0, methodID, 'I', vaargs);
2024 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2026 log_text("JNI-Call: CallStaticIntMethodV");
2028 return callIntegerMethod(0, methodID, 'I', args);
2032 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2034 log_text("JNI-Call: CallStaticIntMethodA");
2041 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2046 /* log_text("JNI-Call: CallStaticLongMethod");*/
2048 va_start(vaargs, methodID);
2049 ret = callLongMethod(0, methodID, vaargs);
2056 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2058 log_text("JNI-Call: CallStaticLongMethodV");
2060 return callLongMethod(0,methodID,args);
2064 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2066 log_text("JNI-Call: CallStaticLongMethodA");
2073 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2078 /* log_text("JNI-Call: CallStaticLongMethod");*/
2080 va_start(vaargs, methodID);
2081 ret = callFloatMethod(0, methodID, vaargs, 'F');
2088 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2091 return callFloatMethod(0, methodID, args, 'F');
2096 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2098 log_text("JNI-Call: CallStaticFloatMethodA");
2105 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2110 /* log_text("JNI-Call: CallStaticDoubleMethod");*/
2112 va_start(vaargs,methodID);
2113 ret = callFloatMethod(0, methodID, vaargs, 'D');
2120 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2122 log_text("JNI-Call: CallStaticDoubleMethodV");
2124 return callFloatMethod(0, methodID, args, 'D');
2128 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2130 log_text("JNI-Call: CallStaticDoubleMethodA");
2136 void CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)
2140 /* log_text("JNI-Call: CallStaticVoidMethod");*/
2142 va_start(vaargs, methodID);
2143 (void) callIntegerMethod(0, methodID, 'V', vaargs);
2148 void CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)
2150 log_text("JNI-Call: CallStaticVoidMethodV");
2151 (void)callIntegerMethod(0, methodID, 'V', args);
2155 void CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args)
2157 log_text("JNI-Call: CallStaticVoidMethodA");
2161 /****************** JNI-functions for accessing static fields ********************/
2163 jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
2167 f = jclass_findfield(clazz,
2168 utf_new_char ((char*) name),
2169 utf_new_char ((char*) sig)
2172 if (!f) *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2178 jobject GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2181 return fieldID->value.a;
2185 jboolean GetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2188 return fieldID->value.i;
2192 jbyte GetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2195 return fieldID->value.i;
2199 jchar GetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2202 return fieldID->value.i;
2206 jshort GetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2209 return fieldID->value.i;
2213 jint GetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2216 return fieldID->value.i;
2220 jlong GetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2223 return fieldID->value.l;
2227 jfloat GetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2230 return fieldID->value.f;
2234 jdouble GetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2237 return fieldID->value.d;
2242 void SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
2245 fieldID->value.a = value;
2249 void SetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
2252 fieldID->value.i = value;
2256 void SetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
2259 fieldID->value.i = value;
2263 void SetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
2266 fieldID->value.i = value;
2270 void SetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
2273 fieldID->value.i = value;
2277 void SetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
2280 fieldID->value.i = value;
2284 void SetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
2287 fieldID->value.l = value;
2291 void SetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
2294 fieldID->value.f = value;
2298 void SetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
2301 fieldID->value.d = value;
2305 /***** create new java.lang.String object from an array of Unicode characters ****/
2307 jstring NewString (JNIEnv *env, const jchar *buf, jsize len)
2310 java_lang_String *s;
2313 s = (java_lang_String*) builtin_new (class_java_lang_String);
2314 a = builtin_newarray_char (len);
2316 /* javastring or characterarray could not be created */
2317 if ( (!a) || (!s) ) return NULL;
2320 for (i=0; i<len; i++) a->data[i] = buf[i];
2329 static char emptyString[]="";
2330 static jchar emptyStringJ[]={0,0};
2332 /******************* returns the length of a Java string ***************************/
2334 jsize GetStringLength (JNIEnv *env, jstring str)
2336 return ((java_lang_String*) str)->count;
2340 /******************** convertes javastring to u2-array ****************************/
2342 u2 *javastring_tou2 (jstring so)
2344 java_lang_String *s = (java_lang_String*) so;
2349 if (!s) return NULL;
2352 if (!a) return NULL;
2354 /* allocate memory */
2355 stringbuffer = MNEW( u2 , s->count + 1 );
2358 for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
2360 /* terminate string */
2361 stringbuffer[i] = '\0';
2363 return stringbuffer;
2366 /********* returns a pointer to an array of Unicode characters of the string *******/
2368 const jchar *GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy)
2370 jchar *jc=javastring_tou2(str);
2373 if (isCopy) *isCopy=JNI_TRUE;
2376 if (isCopy) *isCopy=JNI_TRUE;
2377 return emptyStringJ;
2380 /**************** native code no longer needs access to chars **********************/
2382 void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
2384 if (chars==emptyStringJ) return;
2385 MFREE(((jchar*) chars),jchar,((java_lang_String*) str)->count+1);
2388 /************ create new java.lang.String object from utf8-characterarray **********/
2390 jstring NewStringUTF (JNIEnv *env, const char *utf)
2392 /* log_text("NewStringUTF called");*/
2393 return (jstring) javastring_new(utf_new_char((char *) utf));
2396 /****************** returns the utf8 length in bytes of a string *******************/
2398 jsize GetStringUTFLength (JNIEnv *env, jstring string)
2400 java_lang_String *s = (java_lang_String*) string;
2402 return (jsize) u2_utflength(s->value->data, s->count);
2406 /************ converts a Javastring to an array of UTF-8 characters ****************/
2408 const char* GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
2412 u = javastring_toutf((java_lang_String *) string, false);
2415 *isCopy = JNI_FALSE;
2425 /***************** native code no longer needs access to utf ***********************/
2427 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
2429 /*we don't release utf chars right now, perhaps that should be done later. Since there is always one reference
2430 the garbage collector will never get them*/
2432 log_text("JNI-Call: ReleaseStringUTFChars");
2433 utf_display(utf_new_char(chars));
2437 /************************** array operations ***************************************/
2439 jsize GetArrayLength(JNIEnv *env, jarray array)
2445 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
2447 java_objectarray *j;
2450 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2454 j = builtin_anewarray(len, clazz);
2457 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2463 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
2467 if (index < array->header.size)
2468 j = array->data[index];
2470 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2476 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
2478 if (index >= array->header.size)
2479 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2482 /* check if the class of value is a subclass of the element class of the array */
2483 if (!builtin_canstore((java_objectarray *) array, (java_objectheader *) val))
2484 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
2487 array->data[index] = val;
2493 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
2495 java_booleanarray *j;
2498 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2502 j = builtin_newarray_boolean(len);
2505 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2511 jbyteArray NewByteArray(JNIEnv *env, jsize len)
2516 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2520 j = builtin_newarray_byte(len);
2523 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2529 jcharArray NewCharArray(JNIEnv *env, jsize len)
2534 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2538 j = builtin_newarray_char(len);
2541 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2547 jshortArray NewShortArray(JNIEnv *env, jsize len)
2552 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2556 j = builtin_newarray_short(len);
2559 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2565 jintArray NewIntArray(JNIEnv *env, jsize len)
2570 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2574 j = builtin_newarray_int(len);
2577 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2583 jlongArray NewLongArray(JNIEnv *env, jsize len)
2588 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2592 j = builtin_newarray_long(len);
2595 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2601 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
2606 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2610 j = builtin_newarray_float(len);
2613 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2619 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
2621 java_doublearray *j;
2624 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2628 j = builtin_newarray_double(len);
2631 *exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
2637 jboolean * GetBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *isCopy)
2639 if (isCopy) *isCopy = JNI_FALSE;
2644 jbyte * GetByteArrayElements (JNIEnv *env, jbyteArray array, jboolean *isCopy)
2646 if (isCopy) *isCopy = JNI_FALSE;
2651 jchar * GetCharArrayElements (JNIEnv *env, jcharArray array, jboolean *isCopy)
2653 if (isCopy) *isCopy = JNI_FALSE;
2658 jshort * GetShortArrayElements (JNIEnv *env, jshortArray array, jboolean *isCopy)
2660 if (isCopy) *isCopy = JNI_FALSE;
2665 jint * GetIntArrayElements (JNIEnv *env, jintArray array, jboolean *isCopy)
2667 if (isCopy) *isCopy = JNI_FALSE;
2672 jlong * GetLongArrayElements (JNIEnv *env, jlongArray array, jboolean *isCopy)
2674 if (isCopy) *isCopy = JNI_FALSE;
2679 jfloat * GetFloatArrayElements (JNIEnv *env, jfloatArray array, jboolean *isCopy)
2681 if (isCopy) *isCopy = JNI_FALSE;
2686 jdouble * GetDoubleArrayElements (JNIEnv *env, jdoubleArray array, jboolean *isCopy)
2688 if (isCopy) *isCopy = JNI_FALSE;
2694 void ReleaseBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode)
2700 void ReleaseByteArrayElements (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode)
2706 void ReleaseCharArrayElements (JNIEnv *env, jcharArray array, jchar *elems, jint mode)
2712 void ReleaseShortArrayElements (JNIEnv *env, jshortArray array, jshort *elems, jint mode)
2718 void ReleaseIntArrayElements (JNIEnv *env, jintArray array, jint *elems, jint mode)
2724 void ReleaseLongArrayElements (JNIEnv *env, jlongArray array, jlong *elems, jint mode)
2730 void ReleaseFloatArrayElements (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode)
2736 void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode)
2742 void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2744 if (start < 0 || len < 0 || start + len > array->header.size)
2745 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2748 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2752 void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2754 if (start < 0 || len < 0 || start + len > array->header.size)
2755 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2758 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2762 void GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2764 if (start < 0 || len < 0 || start + len > array->header.size)
2765 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2768 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2772 void GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2774 if (start < 0 || len < 0 || start + len > array->header.size)
2775 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2778 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2782 void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2784 if (start < 0 || len < 0 || start + len > array->header.size)
2785 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2788 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2792 void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2794 if (start < 0 || len < 0 || start + len > array->header.size)
2795 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2798 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2802 void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2804 if (start < 0 || len < 0 || start + len > array->header.size)
2805 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2808 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2812 void GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2814 if (start < 0 || len < 0 || start+len>array->header.size)
2815 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2818 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2822 void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2824 if (start < 0 || len < 0 || start + len > array->header.size)
2825 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2828 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2832 void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2834 if (start < 0 || len < 0 || start + len > array->header.size)
2835 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2838 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2842 void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2844 if (start < 0 || len < 0 || start + len > array->header.size)
2845 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2848 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2853 void SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2855 if (start < 0 || len < 0 || start + len > array->header.size)
2856 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2859 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2863 void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2865 if (start < 0 || len < 0 || start + len > array->header.size)
2866 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2869 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2874 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2876 if (start < 0 || len < 0 || start + len > array->header.size)
2877 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2880 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2885 void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2887 if (start < 0 || len < 0 || start + len > array->header.size)
2888 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2891 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2896 void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2898 if (start < 0 || len < 0 || start + len > array->header.size)
2899 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2902 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2906 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
2908 log_text("JNI-Call: RegisterNatives");
2913 jint UnregisterNatives (JNIEnv* env, jclass clazz)
2915 log_text("JNI-Call: UnregisterNatives");
2919 /******************************* monitor operations ********************************/
2921 jint MonitorEnter (JNIEnv* env, jobject obj)
2923 builtin_monitorenter(obj);
2928 jint MonitorExit (JNIEnv* env, jobject obj)
2930 builtin_monitorexit(obj);
2935 /************************************* JavaVM interface ****************************/
2937 #error CPP mode not supported yet
2939 jint GetJavaVM (JNIEnv* env, JavaVM **vm)
2941 log_text("JNI-Call: GetJavaVM");
2945 #endif /*__cplusplus*/
2947 void GetStringRegion (JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
2949 log_text("JNI-Call: GetStringRegion");
2953 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
2955 log_text("JNI-Call: GetStringUTFRegion");
2959 /************** obtain direct pointer to array elements ***********************/
2961 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
2963 java_objectheader *s = (java_objectheader*) array;
2964 arraydescriptor *desc = s->vftbl->arraydesc;
2966 if (!desc) return NULL;
2968 return ((u1*)s) + desc->dataoffset;
2972 void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jint mode)
2974 log_text("JNI-Call: ReleasePrimitiveArrayCritical");
2979 /**** returns a pointer to an array of Unicode characters of the string *******/
2981 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
2983 log_text("JNI-Call: GetStringCritical");
2985 return GetStringChars(env,string,isCopy);
2988 /*********** native code no longer needs access to chars **********************/
2990 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
2992 log_text("JNI-Call: ReleaseStringCritical");
2994 ReleaseStringChars(env,string,cstring);
2998 jweak NewWeakGlobalRef (JNIEnv* env, jobject obj)
3000 log_text("JNI-Call: NewWeakGlobalRef");
3006 void DeleteWeakGlobalRef (JNIEnv* env, jweak ref)
3008 log_text("JNI-Call: DeleteWeakGlobalRef");
3014 /******************************* check for pending exception ***********************/
3017 jboolean ExceptionCheck(JNIEnv* env)
3019 log_text("JNI-Call: ExceptionCheck");
3021 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
3029 jint DestroyJavaVM(JavaVM *vm)
3031 log_text("DestroyJavaVM called");
3037 jint AttachCurrentThread(JavaVM *vm, void **par1, void *par2)
3039 log_text("AttachCurrentThread called");
3045 jint DetachCurrentThread(JavaVM *vm)
3047 log_text("DetachCurrentThread called");
3053 jint GetEnv(JavaVM *vm, void **environment, jint jniversion)
3055 *environment = &env;
3061 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
3063 log_text("AttachCurrentThreadAsDaemon called");
3069 /********************************* JNI invocation table ******************************/
3071 struct _JavaVM javaVMTable={
3076 &AttachCurrentThread,
3077 &DetachCurrentThread,
3079 &AttachCurrentThreadAsDaemon
3082 JavaVM javaVM = &javaVMTable;
3085 /********************************* JNI function table ******************************/
3087 struct JNI_Table envTable = {
3095 &FromReflectedMethod,
3096 &FromReflectedField,
3114 &EnsureLocalCapacity,
3126 &CallBooleanMethodV,
3127 &CallBooleanMethodA,
3152 &CallNonvirtualObjectMethod,
3153 &CallNonvirtualObjectMethodV,
3154 &CallNonvirtualObjectMethodA,
3155 &CallNonvirtualBooleanMethod,
3156 &CallNonvirtualBooleanMethodV,
3157 &CallNonvirtualBooleanMethodA,
3158 &CallNonvirtualByteMethod,
3159 &CallNonvirtualByteMethodV,
3160 &CallNonvirtualByteMethodA,
3161 &CallNonvirtualCharMethod,
3162 &CallNonvirtualCharMethodV,
3163 &CallNonvirtualCharMethodA,
3164 &CallNonvirtualShortMethod,
3165 &CallNonvirtualShortMethodV,
3166 &CallNonvirtualShortMethodA,
3167 &CallNonvirtualIntMethod,
3168 &CallNonvirtualIntMethodV,
3169 &CallNonvirtualIntMethodA,
3170 &CallNonvirtualLongMethod,
3171 &CallNonvirtualLongMethodV,
3172 &CallNonvirtualLongMethodA,
3173 &CallNonvirtualFloatMethod,
3174 &CallNonvirtualFloatMethodV,
3175 &CallNonvirtualFloatMethodA,
3176 &CallNonvirtualDoubleMethod,
3177 &CallNonvirtualDoubleMethodV,
3178 &CallNonvirtualDoubleMethodA,
3179 &CallNonvirtualVoidMethod,
3180 &CallNonvirtualVoidMethodV,
3181 &CallNonvirtualVoidMethodA,
3202 &CallStaticObjectMethod,
3203 &CallStaticObjectMethodV,
3204 &CallStaticObjectMethodA,
3205 &CallStaticBooleanMethod,
3206 &CallStaticBooleanMethodV,
3207 &CallStaticBooleanMethodA,
3208 &CallStaticByteMethod,
3209 &CallStaticByteMethodV,
3210 &CallStaticByteMethodA,
3211 &CallStaticCharMethod,
3212 &CallStaticCharMethodV,
3213 &CallStaticCharMethodA,
3214 &CallStaticShortMethod,
3215 &CallStaticShortMethodV,
3216 &CallStaticShortMethodA,
3217 &CallStaticIntMethod,
3218 &CallStaticIntMethodV,
3219 &CallStaticIntMethodA,
3220 &CallStaticLongMethod,
3221 &CallStaticLongMethodV,
3222 &CallStaticLongMethodA,
3223 &CallStaticFloatMethod,
3224 &CallStaticFloatMethodV,
3225 &CallStaticFloatMethodA,
3226 &CallStaticDoubleMethod,
3227 &CallStaticDoubleMethodV,
3228 &CallStaticDoubleMethodA,
3229 &CallStaticVoidMethod,
3230 &CallStaticVoidMethodV,
3231 &CallStaticVoidMethodA,
3233 &GetStaticObjectField,
3234 &GetStaticBooleanField,
3235 &GetStaticByteField,
3236 &GetStaticCharField,
3237 &GetStaticShortField,
3239 &GetStaticLongField,
3240 &GetStaticFloatField,
3241 &GetStaticDoubleField,
3242 &SetStaticObjectField,
3243 &SetStaticBooleanField,
3244 &SetStaticByteField,
3245 &SetStaticCharField,
3246 &SetStaticShortField,
3248 &SetStaticLongField,
3249 &SetStaticFloatField,
3250 &SetStaticDoubleField,
3254 &ReleaseStringChars,
3256 &GetStringUTFLength,
3258 &ReleaseStringUTFChars,
3261 &GetObjectArrayElement,
3262 &SetObjectArrayElement,
3271 &GetBooleanArrayElements,
3272 &GetByteArrayElements,
3273 &GetCharArrayElements,
3274 &GetShortArrayElements,
3275 &GetIntArrayElements,
3276 &GetLongArrayElements,
3277 &GetFloatArrayElements,
3278 &GetDoubleArrayElements,
3279 &ReleaseBooleanArrayElements,
3280 &ReleaseByteArrayElements,
3281 &ReleaseCharArrayElements,
3282 &ReleaseShortArrayElements,
3283 &ReleaseIntArrayElements,
3284 &ReleaseLongArrayElements,
3285 &ReleaseFloatArrayElements,
3286 &ReleaseDoubleArrayElements,
3287 &GetBooleanArrayRegion,
3288 &GetByteArrayRegion,
3289 &GetCharArrayRegion,
3290 &GetShortArrayRegion,
3292 &GetLongArrayRegion,
3293 &GetFloatArrayRegion,
3294 &GetDoubleArrayRegion,
3295 &SetBooleanArrayRegion,
3296 &SetByteArrayRegion,
3297 &SetCharArrayRegion,
3298 &SetShortArrayRegion,
3300 &SetLongArrayRegion,
3301 &SetFloatArrayRegion,
3302 &SetDoubleArrayRegion,
3309 &GetStringUTFRegion,
3310 &GetPrimitiveArrayCritical,
3311 &ReleasePrimitiveArrayCritical,
3313 &ReleaseStringCritical,
3315 &DeleteWeakGlobalRef,
3319 JNIEnv env = &envTable;
3322 jobject *jni_method_invokeNativeHelper(JNIEnv *env, struct methodinfo *methodID, jobject obj, java_objectarray *params)
3329 if (methodID == 0) {
3330 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
3334 argcount = get_parametercount(methodID);
3336 if (obj && (!builtin_instanceof((java_objectheader *) obj, methodID->class))) {
3337 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/IllegalArgumentException")),
3338 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
3345 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3346 log_text("Too many arguments. invokeNativeHelper does not support that");
3350 if (((!params) && (argcount != 0)) || (params && (params->header.size != argcount))) {
3351 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3356 if (!(methodID->flags & ACC_STATIC) && (!obj)) {
3357 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/NullPointerException")),
3358 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
3362 if ((methodID->flags & ACC_STATIC) && (obj)) obj = 0;
3364 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
3366 retT = fill_callblock_objA(obj, methodID->descriptor, blk, params);
3370 (void) asm_calljavafunction2(methodID,
3372 (argcount + 1) * sizeof(jni_callblock),
3374 retVal = NULL; /*native_new_and_init(loader_load(utf_new_char("java/lang/Void")));*/
3379 intVal = (s4) asm_calljavafunction2(methodID,
3381 (argcount + 1) * sizeof(jni_callblock),
3383 retVal = builtin_new(loader_load_sysclass(NULL,
3384 utf_new_char("java/lang/Integer")));
3387 class_resolvemethod(retVal->vftbl->class,
3388 utf_new_char("<init>"),
3389 utf_new_char("(I)V")),
3396 intVal = (s4) asm_calljavafunction2(methodID,
3398 (argcount + 1) * sizeof(jni_callblock),
3400 retVal = builtin_new(loader_load_sysclass(NULL,
3401 utf_new_char("java/lang/Byte")));
3404 class_resolvemethod(retVal->vftbl->class,
3405 utf_new_char("<init>"),
3406 utf_new_char("(B)V")),
3413 intVal = (s4) asm_calljavafunction2(methodID,
3415 (argcount + 1) * sizeof(jni_callblock),
3417 retVal = builtin_new(loader_load_sysclass(NULL,
3418 utf_new_char("java/lang/Character")));
3421 class_resolvemethod(retVal->vftbl->class,
3422 utf_new_char("<init>"),
3423 utf_new_char("(C)V")),
3430 intVal = (s4) asm_calljavafunction2(methodID,
3432 (argcount + 1) * sizeof(jni_callblock),
3434 retVal = builtin_new(loader_load_sysclass(NULL,
3435 utf_new_char("java/lang/Short")));
3438 class_resolvemethod(retVal->vftbl->class,
3439 utf_new_char("<init>"),
3440 utf_new_char("(S)V")),
3447 intVal = (s4) asm_calljavafunction2(methodID,
3449 (argcount + 1) * sizeof(jni_callblock),
3451 retVal = builtin_new(loader_load_sysclass(NULL,
3452 utf_new_char("java/lang/Boolean")));
3455 class_resolvemethod(retVal->vftbl->class,
3456 utf_new_char("<init>"),
3457 utf_new_char("(Z)V")),
3464 intVal = asm_calljavafunction2long(methodID,
3466 (argcount + 1) * sizeof(jni_callblock),
3468 retVal = builtin_new(loader_load_sysclass(NULL,
3469 utf_new_char("java/lang/Long")));
3472 class_resolvemethod(retVal->vftbl->class,
3473 utf_new_char("<init>"),
3474 utf_new_char("(J)V")),
3481 floatVal = asm_calljavafunction2double(methodID,
3483 (argcount + 1) * sizeof(jni_callblock),
3485 retVal = builtin_new(loader_load_sysclass(NULL,
3486 utf_new_char("java/lang/Float")));
3489 class_resolvemethod(retVal->vftbl->class,
3490 utf_new_char("<init>"),
3491 utf_new_char("(F)V")),
3498 floatVal = asm_calljavafunction2double(methodID,
3500 (argcount + 1) * sizeof(jni_callblock),
3502 retVal = builtin_new(loader_load_sysclass(NULL,
3503 utf_new_char("java/lang/Double")));
3506 class_resolvemethod(retVal->vftbl->class,
3507 utf_new_char("<init>"),
3508 utf_new_char("(D)V")),
3513 case 'L': /* fall through */
3515 retVal = asm_calljavafunction2(methodID,
3517 (argcount + 1) * sizeof(jni_callblock),
3522 /* if this happens the acception has already been set by fill_callblock_objA*/
3523 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3524 return (jobject *) 0;
3527 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3529 if (*exceptionptr) {
3530 java_objectheader *exceptionToWrap=*exceptionptr;
3532 java_objectheader *ivte;
3535 ivtec = loader_load_sysclass(NULL,
3536 utf_new_char("java/lang/reflect/InvocationTargetException"));
3537 ivte = builtin_new(ivtec);
3538 asm_calljavafunction(class_resolvemethod(ivtec,
3539 utf_new_char("<init>"),
3540 utf_new_char("(Ljava/lang/Throwable;)V")),
3546 if (*exceptionptr != NULL)
3547 panic("jni.c: error while creating InvocationTargetException wrapper");
3549 *exceptionptr = ivte;
3552 return (jobject *) retVal;
3557 * These are local overrides for various environment variables in Emacs.
3558 * Please do not remove this and leave it at the end of the file, where
3559 * Emacs will automagically detect them.
3560 * ---------------------------------------------------------------------
3563 * indent-tabs-mode: t