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, M. Platter
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, Martin Platter
31 $Id: jni.c 1411 2004-08-17 15:04:54Z twisti $
37 #include "exceptions.h"
46 #include "statistics.h"
47 #include "threads/thread.h"
48 #include "toolbox/logging.h"
49 #include "toolbox/memory.h"
50 #include "nat/java_lang_Byte.h"
51 #include "nat/java_lang_Character.h"
52 #include "nat/java_lang_Short.h"
53 #include "nat/java_lang_Integer.h"
54 #include "nat/java_lang_Boolean.h"
55 #include "nat/java_lang_Long.h"
56 #include "nat/java_lang_Float.h"
57 #include "nat/java_lang_Double.h"
58 #include "nat/java_lang_Throwable.h"
61 #define JNI_VERSION 0x00010002
64 #define PTR_TO_ITEM(ptr) ((u8)(size_t)(ptr))
66 static utf* utf_char = 0;
67 static utf* utf_bool = 0;
68 static utf* utf_byte =0;
69 static utf* utf_short = 0;
70 static utf* utf_int = 0;
71 static utf* utf_long = 0;
72 static utf* utf_float = 0;
73 static utf* utf_double = 0;
76 /********************* accessing instance-fields **********************************/
78 #define setField(obj,typ,var,val) *((typ*) ((long int) obj + (long int) var->offset))=val;
79 #define getField(obj,typ,var) *((typ*) ((long int) obj + (long int) var->offset))
80 #define setfield_critical(clazz,obj,name,sig,jdatatype,val) setField(obj,jdatatype,getFieldID_critical(env,clazz,name,sig),val);
84 u4 get_parametercount(methodinfo *m)
86 utf *descr = m->descriptor; /* method-descriptor */
87 char *utf_ptr = descr->text; /* current position in utf-text */
88 char *desc_end = utf_end(descr); /* points behind utf string */
89 u4 parametercount = 0;
94 /* determine number of parameters */
95 while (*utf_ptr != ')') {
96 get_type(&utf_ptr, desc_end, true);
100 return parametercount;
105 void fill_callblock(void *obj, utf *descr, jni_callblock blk[], va_list data, char ret)
107 char *utf__ptr = descr->text; /* current position in utf-text */
108 char **utf_ptr = &utf__ptr;
109 char *desc_end = utf_end(descr); /* points behind utf string */
115 log_text("fill_callblock");
122 /* determine number of parameters */
124 blk[0].itemtype = TYPE_ADR;
125 blk[0].item = PTR_TO_ITEM(obj);
129 while (**utf_ptr != ')') {
130 if (*utf_ptr >= desc_end)
131 panic("illegal method descriptor");
133 switch (utf_nextu2(utf_ptr)) {
134 /* primitive types */
139 blk[cnt].itemtype = TYPE_INT;
140 blk[cnt].item = (u8) va_arg(data, int);
144 blk[cnt].itemtype = TYPE_INT;
145 dummy = va_arg(data, u4);
146 /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
147 blk[cnt].item = (u8) dummy;
151 blk[cnt].itemtype = TYPE_LNG;
152 blk[cnt].item = (u8) va_arg(data, jlong);
156 blk[cnt].itemtype = TYPE_FLT;
157 *((jfloat *) (&blk[cnt].item)) = (jfloat) va_arg(data, jdouble);
161 blk[cnt].itemtype = TYPE_DBL;
162 *((jdouble *) (&blk[cnt].item)) = (jdouble) va_arg(data, jdouble);
166 panic ("V not allowed as function parameter");
170 while (utf_nextu2(utf_ptr) != ';')
171 blk[cnt].itemtype = TYPE_ADR;
172 blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
179 /* char *start = *utf_ptr; */
181 while ((ch = utf_nextu2(utf_ptr)) == '[')
183 while (utf_nextu2(utf_ptr) != ';') {}
186 ch = utf_nextu2(utf_ptr);
187 blk[cnt].itemtype = TYPE_ADR;
188 blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
195 /*the standard doesn't say anything about return value checking, but it appears to be usefull*/
196 c = utf_nextu2(utf_ptr);
197 c = utf_nextu2(utf_ptr);
198 /*printf("%c %c\n",ret,c);*/
200 if (!((c == 'L') || (c == '[')))
201 log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
203 log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
207 /* XXX it could be considered if we should do typechecking here in the future */
208 char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_objectarray* params)
210 char *utf__ptr = descr->text; /* current position in utf-text */
211 char **utf_ptr = &utf__ptr;
212 char *desc_end = utf_end(descr); /* points behind utf string */
219 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
223 utf_char=utf_new_char("java/lang/Character");
224 utf_bool=utf_new_char("java/lang/Boolean");
225 utf_byte=utf_new_char("java/lang/Byte");
226 utf_short=utf_new_char("java/lang/Short");
227 utf_int=utf_new_char("java/lang/Integer");
228 utf_long=utf_new_char("java/lang/Long");
229 utf_float=utf_new_char("java/lang/Float");
230 utf_double=utf_new_char("java/lang/Double");
232 #if defined(USE_THREADS) && !defined(NATIVE_THREADS)
237 log_text("fill_callblock");
244 /* determine number of parameters */
246 blk[0].itemtype = TYPE_ADR;
247 blk[0].item = PTR_TO_ITEM(obj);
255 while (**utf_ptr != ')') {
256 if (*utf_ptr >= desc_end)
257 panic("illegal method descriptor");
259 /* primitive types */
260 switch (utf_nextu2(utf_ptr)) {
262 param = params->data[cnts];
264 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
267 if (param->vftbl->class->name == utf_byte) {
268 blk[cnt].itemtype = TYPE_INT;
269 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
272 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
278 param = params->data[cnts];
280 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
283 if (param->vftbl->class->name == utf_char) {
284 blk[cnt].itemtype = TYPE_INT;
285 blk[cnt].item = (u8) ((java_lang_Character *) param)->value;
288 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
294 param = params->data[cnts];
296 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
299 if (param->vftbl->class->name == utf_short) {
300 blk[cnt].itemtype = TYPE_INT;
301 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
304 if (param->vftbl->class->name == utf_byte) {
305 blk[cnt].itemtype = TYPE_INT;
306 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
309 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
316 param = params->data[cnts];
318 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
321 if (param->vftbl->class->name == utf_bool) {
322 blk[cnt].itemtype = TYPE_INT;
323 blk[cnt].item = (u8) ((java_lang_Boolean *) param)->value;
326 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
332 /*log_text("fill_callblock_objA: param 'I'");*/
333 param = params->data[cnts];
335 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
338 if (param->vftbl->class->name == utf_int) {
339 blk[cnt].itemtype = TYPE_INT;
340 blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
341 /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
343 if (param->vftbl->class->name == utf_short) {
344 blk[cnt].itemtype = TYPE_INT;
345 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
348 if (param->vftbl->class->name == utf_byte) {
349 blk[cnt].itemtype = TYPE_INT;
350 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
353 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
361 param = params->data[cnts];
363 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
366 if (param->vftbl->class->name == utf_long) {
367 blk[cnt].itemtype = TYPE_LNG;
368 blk[cnt].item = (u8) ((java_lang_Long *) param)->value;
371 if (param->vftbl->class->name == utf_int) {
372 blk[cnt].itemtype = TYPE_LNG;
373 blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
376 if (param->vftbl->class->name == utf_short) {
377 blk[cnt].itemtype = TYPE_LNG;
378 blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
381 if (param->vftbl->class->name == utf_byte) {
382 blk[cnt].itemtype = TYPE_LNG;
383 blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
385 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
395 param = params->data[cnts];
397 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
401 if (param->vftbl->class->name == utf_float) {
402 blk[cnt].itemtype = TYPE_FLT;
403 *((jfloat *) (&blk[cnt].item)) = (jfloat) ((java_lang_Float *) param)->value;
406 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
412 param = params->data[cnts];
414 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
418 if (param->vftbl->class->name == utf_double) {
419 blk[cnt].itemtype = TYPE_DBL;
420 *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
423 if (param->vftbl->class->name == utf_float) {
424 blk[cnt].itemtype = TYPE_DBL;
425 *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
428 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
435 panic("V not allowed as function parameter");
440 char *start = (*utf_ptr) - 1;
443 while (utf_nextu2(utf_ptr) != ';')
444 end = (*utf_ptr) + 1;
446 if (!builtin_instanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD))) {
447 if (params->data[cnts] != 0) {
448 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
453 blk[cnt].itemtype = TYPE_ADR;
454 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
460 char *start = (*utf_ptr) - 1;
464 while ((ch = utf_nextu2(utf_ptr)) == '[')
466 while (utf_nextu2(utf_ptr) != ';') {}
469 end = (*utf_ptr) - 1;
470 ch = utf_nextu2(utf_ptr);
472 if (!builtin_arrayinstanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD)->vftbl)) {
473 *exceptionptr = new_exception("java/lang/IllegalArgumentException");
477 blk[cnt].itemtype = TYPE_ADR;
478 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
486 c = utf_nextu2(utf_ptr);
487 c = utf_nextu2(utf_ptr);
488 return c; /*return type needed usage of the right lowlevel methods*/
505 jmethodID get_virtual(jobject obj,jmethodID methodID) {
506 if (obj->vftbl->class==methodID->class) return methodID;
507 return class_resolvemethod (obj->vftbl->class, methodID->name, methodID->descriptor);
510 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
511 if (clazz==methodID->class) return methodID;
512 /*class_resolvemethod -> classfindmethod? (JOWENN)*/
513 return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
518 jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
525 log_text("JNI-Call: CallObjectMethodV");
526 utf_display(methodID->name);
527 utf_display(methodID->descriptor);
528 printf("\nParmaeter count: %d\n",argcount);
529 utf_display(obj->vftbl->class->name);
534 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
538 argcount = get_parametercount(methodID);
540 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
541 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
542 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
546 if (obj && !builtin_instanceof(obj, methodID->class)) {
547 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
552 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
553 log_text("Too many arguments. CallObjectMethod does not support that");
557 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
559 fill_callblock(obj, methodID->descriptor, blk, args, 'O');
561 /* printf("parameter: obj: %p",blk[0].item); */
562 ret = asm_calljavafunction2(methodID,
564 (argcount + 1) * sizeof(jni_callblock),
567 MFREE(blk, jni_callblock, argcount + 1);
568 /* printf("(CallObjectMethodV)-->%p\n",ret); */
574 core function for integer class methods (bool, byte, short, integer)
575 This is basically needed for i386
577 jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list args)
583 /* printf("%p, %c\n",retType,methodID,retType);*/
586 log_text("JNI-Call: CallObjectMethodV");
587 utf_display(methodID->name);
588 utf_display(methodID->descriptor);
589 printf("\nParmaeter count: %d\n",argcount);
590 utf_display(obj->vftbl->class->name);
594 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
598 argcount = get_parametercount(methodID);
600 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
601 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
602 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
606 if (obj && !builtin_instanceof(obj, methodID->class)) {
607 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
613 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
614 log_text("Too many arguments. CallIntegerMethod does not support that");
618 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
620 fill_callblock(obj, methodID->descriptor, blk, args, retType);
622 /* printf("parameter: obj: %p",blk[0].item); */
623 ret = (jint) asm_calljavafunction2(methodID,
625 (argcount + 1) * sizeof(jni_callblock),
628 MFREE(blk, jni_callblock, argcount + 1);
629 /* printf("(CallObjectMethodV)-->%p\n",ret); */
635 /*core function for long class functions*/
636 jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
643 log_text("JNI-Call: CallObjectMethodV");
644 utf_display(methodID->name);
645 utf_display(methodID->descriptor);
646 printf("\nParmaeter count: %d\n",argcount);
647 utf_display(obj->vftbl->class->name);
651 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
655 argcount = get_parametercount(methodID);
657 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
658 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
659 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
663 if (obj && !builtin_instanceof(obj,methodID->class)) {
664 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
670 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
671 log_text("Too many arguments. CallObjectMethod does not support that");
675 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
677 fill_callblock(obj, methodID->descriptor, blk, args, 'J');
679 /* printf("parameter: obj: %p",blk[0].item); */
680 ret = asm_calljavafunction2long(methodID,
682 (argcount + 1) * sizeof(jni_callblock),
685 MFREE(blk, jni_callblock, argcount + 1);
686 /* printf("(CallObjectMethodV)-->%p\n",ret); */
692 /*core function for float class methods (float,double)*/
693 jdouble callFloatMethod(jobject obj, jmethodID methodID, va_list args,char retType)
695 int argcount = get_parametercount(methodID);
700 log_text("JNI-Call: CallObjectMethodV");
701 utf_display(methodID->name);
702 utf_display(methodID->descriptor);
703 printf("\nParmaeter count: %d\n",argcount);
704 utf_display(obj->vftbl->class->name);
709 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
710 log_text("Too many arguments. CallObjectMethod does not support that");
714 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
716 fill_callblock(obj, methodID->descriptor, blk, args, retType);
718 /* printf("parameter: obj: %p",blk[0].item); */
719 ret = asm_calljavafunction2double(methodID,
721 (argcount + 1) * sizeof(jni_callblock),
724 MFREE(blk, jni_callblock, argcount + 1);
725 /* printf("(CallObjectMethodV)-->%p\n",ret); */
731 /*************************** function: jclass_findfield ****************************
733 searches for field with specified name and type in a 'classinfo'-structur
734 if no such field is found NULL is returned
736 ************************************************************************************/
738 fieldinfo *jclass_findfield (classinfo *c, utf *name, utf *desc)
741 /* printf(" FieldCount: %d\n",c->fieldscount);
742 utf_display(c->name); */
743 for (i = 0; i < c->fieldscount; i++) {
744 /* utf_display(c->fields[i].name);
746 utf_display(c->fields[i].descriptor);
748 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
749 return &(c->fields[i]);
752 if (c->super) return jclass_findfield(c->super,name,desc);
757 /********************* returns version of native method interface *****************/
759 jint GetVersion (JNIEnv* env)
765 /************** loads a class from a buffer of raw class data *****************/
767 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len)
773 c = class_new(utf_new_char_classname((char *) name));
775 /* enter a monitor on the class */
777 builtin_monitorenter((java_objectheader *) c);
783 /* build a classbuffer with the given data */
784 cb = NEW(classbuffer);
787 cb->data = (u1 *) buf;
788 cb->pos = cb->data - 1;
790 r = class_load_intern(cb);
792 /* if return value is NULL, we had a problem and the class is not loaded */
796 /* now free the allocated memory, otherwise we could ran into a DOS */
801 FREE(cb, classbuffer);
807 /* leave the monitor */
809 builtin_monitorexit((java_objectheader *) c);
811 /* XXX link the class here? */
812 /* if (class_link(c)) */
816 c->classloader = loader;
822 /*********** loads locally defined class with the specified name **************/
824 jclass FindClass(JNIEnv* env, const char *name)
828 c = class_new(utf_new_char_classname((char *) name));
840 /*******************************************************************************
842 converts java.lang.reflect.Method or
843 java.lang.reflect.Constructor object to a method ID
845 *******************************************************************************/
847 jmethodID FromReflectedMethod(JNIEnv* env, jobject method)
849 /* log_text("JNI-Call: FromReflectedMethod"); */
855 /*************** return superclass of the class represented by sub ****************/
857 jclass GetSuperclass(JNIEnv* env, jclass sub)
861 c = ((classinfo*) sub)->super;
865 use_class_as_object(c);
871 /*********************** check whether sub can be cast to sup ********************/
873 jboolean IsAssignableForm(JNIEnv* env, jclass sub, jclass sup)
875 return builtin_isanysubclass(sub, sup);
879 /***** converts a field ID derived from cls to a java.lang.reflect.Field object ***/
881 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isStatic)
883 /* log_text("JNI-Call: ToReflectedField"); */
889 /***************** throw java.lang.Throwable object ******************************/
891 jint Throw(JNIEnv* env, jthrowable obj)
893 *exceptionptr = (java_objectheader*) obj;
899 /*******************************************************************************
901 create exception object from the class clazz with the
902 specified message and cause it to be thrown
904 *******************************************************************************/
906 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
908 java_lang_Throwable *o;
910 /* instantiate exception object */
911 o = (java_lang_Throwable *) native_new_and_init((classinfo*) clazz);
915 o->detailMessage = (java_lang_String *) javastring_new_char((char *) msg);
917 *exceptionptr = (java_objectheader *) o;
923 /************************* check if exception occured *****************************/
925 jthrowable ExceptionOccurred (JNIEnv* env)
927 return (jthrowable) *exceptionptr;
930 /********** print exception and a backtrace of the stack (for debugging) **********/
932 void ExceptionDescribe (JNIEnv* env)
934 utf_display((*exceptionptr)->vftbl->class->name);
940 /******************* clear any exception currently being thrown *******************/
942 void ExceptionClear (JNIEnv* env)
944 *exceptionptr = NULL;
948 /********** raises a fatal error and does not expect the VM to recover ************/
950 void FatalError (JNIEnv* env, const char *msg)
955 /******************* creates a new local reference frame **************************/
957 jint PushLocalFrame(JNIEnv* env, jint capacity)
964 /**************** Pops off the current local reference frame **********************/
966 jobject PopLocalFrame(JNIEnv* env, jobject result)
974 /** Creates a new global reference to the object referred to by the obj argument **/
976 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
981 /************* Deletes the global reference pointed to by globalRef **************/
983 void DeleteGlobalRef (JNIEnv* env, jobject gref)
989 /*************** Deletes the local reference pointed to by localRef ***************/
991 void DeleteLocalRef (JNIEnv* env, jobject localRef)
996 /********** Tests whether two references refer to the same Java object ************/
998 jboolean IsSameObject (JNIEnv* env, jobject obj1, jobject obj2)
1000 return (obj1==obj2);
1003 /***** Creates a new local reference that refers to the same object as ref *******/
1005 jobject NewLocalRef (JNIEnv* env, jobject ref)
1010 /***********************************************************************************
1012 Ensures that at least a given number of local references can
1013 be created in the current thread
1015 **********************************************************************************/
1017 jint EnsureLocalCapacity (JNIEnv* env, jint capacity)
1019 return 0; /* return 0 on success */
1023 /********* Allocates a new Java object without invoking a constructor *************/
1025 jobject AllocObject (JNIEnv* env, jclass clazz)
1027 java_objectheader *o = builtin_new(clazz);
1032 /***********************************************************************************
1034 Constructs a new Java object
1035 arguments that are to be passed to the constructor are placed after methodID
1037 ***********************************************************************************/
1039 jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
1041 java_objectheader *o;
1043 int argcount=get_parametercount(methodID);
1047 /* log_text("JNI-Call: NewObject"); */
1050 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
1051 log_text("Too many arguments. NewObject does not support that");
1056 o = builtin_new (clazz); /* create object */
1058 if (!o) return NULL;
1060 va_start(vaargs,methodID);
1061 for (i=0;i<argcount;i++) {
1062 args[i]=va_arg(vaargs,void*);
1065 asm_calljavafunction(methodID,o,args[0],args[1],args[2]);
1071 /***********************************************************************************
1073 Constructs a new Java object
1074 arguments that are to be passed to the constructor are placed in va_list args
1076 ***********************************************************************************/
1078 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1080 /* log_text("JNI-Call: NewObjectV"); */
1086 /***********************************************************************************
1088 Constructs a new Java object
1089 arguments that are to be passed to the constructor are placed in
1090 args array of jvalues
1092 ***********************************************************************************/
1094 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1096 /* log_text("JNI-Call: NewObjectA"); */
1102 /************************ returns the class of an object **************************/
1104 jclass GetObjectClass(JNIEnv* env, jobject obj)
1106 classinfo *c = obj->vftbl->class;
1108 use_class_as_object(c);
1114 /************* tests whether an object is an instance of a class ******************/
1116 jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz)
1118 return builtin_instanceof(obj,clazz);
1122 /***************** converts a java.lang.reflect.Field to a field ID ***************/
1124 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1126 log_text("JNI-Call: FromReflectedField");
1132 /**********************************************************************************
1134 converts a method ID to a java.lang.reflect.Method or
1135 java.lang.reflect.Constructor object
1137 **********************************************************************************/
1139 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1141 log_text("JNI-Call: ToReflectedMethod");
1147 /**************** returns the method ID for an instance method ********************/
1149 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *sig)
1153 m = class_resolvemethod (
1155 utf_new_char ((char*) name),
1156 utf_new_char ((char*) sig)
1159 if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1160 else if (m->flags & ACC_STATIC) {
1162 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1168 /******************** JNI-functions for calling instance methods ******************/
1170 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1175 /* log_text("JNI-Call: CallObjectMethod");*/
1177 va_start(vaargs, methodID);
1178 ret = callObjectMethod(obj, methodID, vaargs);
1185 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1187 return callObjectMethod(obj,methodID,args);
1191 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1193 log_text("JNI-Call: CallObjectMethodA");
1201 jboolean CallBooleanMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1206 /* log_text("JNI-Call: CallBooleanMethod");*/
1208 va_start(vaargs,methodID);
1209 ret = (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',vaargs);
1215 jboolean CallBooleanMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1217 return (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',args);
1221 jboolean CallBooleanMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1223 log_text("JNI-Call: CallBooleanMethodA");
1228 jbyte CallByteMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1233 /* log_text("JNI-Call: CallVyteMethod");*/
1235 va_start(vaargs,methodID);
1236 ret = callIntegerMethod(obj,get_virtual(obj,methodID),'B',vaargs);
1242 jbyte CallByteMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1244 /* log_text("JNI-Call: CallByteMethodV");*/
1245 return callIntegerMethod(obj,methodID,'B',args);
1249 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1251 log_text("JNI-Call: CallByteMethodA");
1257 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1262 /* log_text("JNI-Call: CallCharMethod");*/
1264 va_start(vaargs,methodID);
1265 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'C', vaargs);
1272 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1274 /* log_text("JNI-Call: CallCharMethodV");*/
1275 return callIntegerMethod(obj,get_virtual(obj,methodID),'C',args);
1279 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1281 log_text("JNI-Call: CallCharMethodA");
1287 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1292 /* log_text("JNI-Call: CallShortMethod");*/
1294 va_start(vaargs, methodID);
1295 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'S', vaargs);
1302 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1304 return callIntegerMethod(obj, get_virtual(obj, methodID), 'S', args);
1308 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1310 log_text("JNI-Call: CallShortMethodA");
1317 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1322 va_start(vaargs,methodID);
1323 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'I', vaargs);
1330 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1332 return callIntegerMethod(obj, get_virtual(obj, methodID), 'I', args);
1336 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1338 log_text("JNI-Call: CallIntMethodA");
1345 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1350 va_start(vaargs,methodID);
1351 ret = callLongMethod(obj,get_virtual(obj, methodID),vaargs);
1358 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1360 return callLongMethod(obj,get_virtual(obj, methodID),args);
1364 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1366 log_text("JNI-Call: CallLongMethodA");
1373 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1378 /* log_text("JNI-Call: CallFloatMethod");*/
1380 va_start(vaargs,methodID);
1381 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'F');
1388 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1390 log_text("JNI-Call: CallFloatMethodV");
1391 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'F');
1395 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1397 log_text("JNI-Call: CallFloatMethodA");
1404 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1409 /* log_text("JNI-Call: CallDoubleMethod");*/
1411 va_start(vaargs,methodID);
1412 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'D');
1419 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1421 log_text("JNI-Call: CallDoubleMethodV");
1422 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'D');
1426 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1428 log_text("JNI-Call: CallDoubleMethodA");
1434 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1438 /* log_text("JNI-Call: CallVoidMethod");*/
1440 va_start(vaargs,methodID);
1441 (void) callIntegerMethod(obj, get_virtual(obj, methodID), 'V', vaargs);
1446 void CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1448 log_text("JNI-Call: CallVoidMethodV");
1449 (void)callIntegerMethod(obj,get_virtual(obj,methodID),'V',args);
1453 void CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1455 log_text("JNI-Call: CallVoidMethodA");
1460 jobject CallNonvirtualObjectMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1462 log_text("JNI-Call: CallNonvirtualObjectMethod");
1468 jobject CallNonvirtualObjectMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1470 log_text("JNI-Call: CallNonvirtualObjectMethodV");
1476 jobject CallNonvirtualObjectMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1478 log_text("JNI-Call: CallNonvirtualObjectMethodA");
1485 jboolean CallNonvirtualBooleanMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1490 /* log_text("JNI-Call: CallNonvirtualBooleanMethod");*/
1492 va_start(vaargs,methodID);
1493 ret = (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',vaargs);
1500 jboolean CallNonvirtualBooleanMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1502 /* log_text("JNI-Call: CallNonvirtualBooleanMethodV");*/
1503 return (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',args);
1507 jboolean CallNonvirtualBooleanMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1509 log_text("JNI-Call: CallNonvirtualBooleanMethodA");
1516 jbyte CallNonvirtualByteMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1521 /* log_text("JNI-Call: CallNonvirutalByteMethod");*/
1523 va_start(vaargs,methodID);
1524 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',vaargs);
1530 jbyte CallNonvirtualByteMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1532 /*log_text("JNI-Call: CallNonvirtualByteMethodV"); */
1533 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',args);
1538 jbyte CallNonvirtualByteMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1540 log_text("JNI-Call: CallNonvirtualByteMethodA");
1547 jchar CallNonvirtualCharMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1552 /* log_text("JNI-Call: CallNonVirtualCharMethod");*/
1554 va_start(vaargs,methodID);
1555 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',vaargs);
1561 jchar CallNonvirtualCharMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1563 /*log_text("JNI-Call: CallNonvirtualCharMethodV");*/
1564 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',args);
1568 jchar CallNonvirtualCharMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1570 log_text("JNI-Call: CallNonvirtualCharMethodA");
1577 jshort CallNonvirtualShortMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1582 /*log_text("JNI-Call: CallNonvirtualShortMethod");*/
1584 va_start(vaargs,methodID);
1585 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',vaargs);
1591 jshort CallNonvirtualShortMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1593 /*log_text("JNI-Call: CallNonvirtualShortMethodV");*/
1594 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',args);
1598 jshort CallNonvirtualShortMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1600 log_text("JNI-Call: CallNonvirtualShortMethodA");
1607 jint CallNonvirtualIntMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1613 /*log_text("JNI-Call: CallNonvirtualIntMethod");*/
1615 va_start(vaargs,methodID);
1616 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',vaargs);
1622 jint CallNonvirtualIntMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1624 /*log_text("JNI-Call: CallNonvirtualIntMethodV");*/
1625 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',args);
1629 jint CallNonvirtualIntMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1631 log_text("JNI-Call: CallNonvirtualIntMethodA");
1638 jlong CallNonvirtualLongMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1640 log_text("JNI-Call: CallNonvirtualLongMethod");
1646 jlong CallNonvirtualLongMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1648 log_text("JNI-Call: CallNonvirtualLongMethodV");
1654 jlong CallNonvirtualLongMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1656 log_text("JNI-Call: CallNonvirtualLongMethodA");
1663 jfloat CallNonvirtualFloatMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1668 /*log_text("JNI-Call: CallNonvirtualFloatMethod");*/
1671 va_start(vaargs,methodID);
1672 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'F');
1679 jfloat CallNonvirtualFloatMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1681 log_text("JNI-Call: CallNonvirtualFloatMethodV");
1682 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'F');
1686 jfloat CallNonvirtualFloatMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1688 log_text("JNI-Call: CallNonvirtualFloatMethodA");
1695 jdouble CallNonvirtualDoubleMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1699 log_text("JNI-Call: CallNonvirtualDoubleMethod");
1701 va_start(vaargs,methodID);
1702 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'D');
1709 jdouble CallNonvirtualDoubleMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1711 /* log_text("JNI-Call: CallNonvirtualDoubleMethodV");*/
1712 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'D');
1716 jdouble CallNonvirtualDoubleMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1718 log_text("JNI-Call: CallNonvirtualDoubleMethodA");
1725 void CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1729 /* log_text("JNI-Call: CallNonvirtualVoidMethod");*/
1731 va_start(vaargs,methodID);
1732 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',vaargs);
1738 void CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1740 /* log_text("JNI-Call: CallNonvirtualVoidMethodV");*/
1742 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',args);
1747 void CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1749 log_text("JNI-Call: CallNonvirtualVoidMethodA");
1752 /************************* JNI-functions for accessing fields ************************/
1754 jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
1758 /* log_text("========================= searching for:");
1761 f = jclass_findfield(clazz,
1762 utf_new_char ((char*) name),
1763 utf_new_char ((char*) sig)
1767 /* utf_display(clazz->name);
1770 *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
1775 /*************************** retrieve fieldid, abort on error ************************/
1777 jfieldID getFieldID_critical(JNIEnv *env, jclass clazz, char *name, char *sig)
1779 jfieldID id = GetFieldID(env, clazz, name, sig);
1783 utf_display(clazz->name);
1784 log_text("\nfield:");
1789 panic("setfield_critical failed");
1794 jobject GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
1796 return getField(obj,jobject,fieldID);
1799 jboolean GetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID)
1801 return getField(obj,jboolean,fieldID);
1805 jbyte GetByteField (JNIEnv *env, jobject obj, jfieldID fieldID)
1807 return getField(obj,jbyte,fieldID);
1811 jchar GetCharField (JNIEnv *env, jobject obj, jfieldID fieldID)
1813 return getField(obj,jchar,fieldID);
1817 jshort GetShortField (JNIEnv *env, jobject obj, jfieldID fieldID)
1819 return getField(obj,jshort,fieldID);
1823 jint GetIntField (JNIEnv *env, jobject obj, jfieldID fieldID)
1825 return getField(obj,jint,fieldID);
1829 jlong GetLongField (JNIEnv *env, jobject obj, jfieldID fieldID)
1831 return getField(obj,jlong,fieldID);
1835 jfloat GetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID)
1837 return getField(obj,jfloat,fieldID);
1841 jdouble GetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID)
1843 return getField(obj,jdouble,fieldID);
1846 void SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
1848 setField(obj,jobject,fieldID,val);
1852 void SetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val)
1854 setField(obj,jboolean,fieldID,val);
1858 void SetByteField (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val)
1860 setField(obj,jbyte,fieldID,val);
1864 void SetCharField (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val)
1866 setField(obj,jchar,fieldID,val);
1870 void SetShortField (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val)
1872 setField(obj,jshort,fieldID,val);
1876 void SetIntField (JNIEnv *env, jobject obj, jfieldID fieldID, jint val)
1878 setField(obj,jint,fieldID,val);
1882 void SetLongField (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val)
1884 setField(obj,jlong,fieldID,val);
1888 void SetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val)
1890 setField(obj,jfloat,fieldID,val);
1894 void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
1896 setField(obj,jdouble,fieldID,val);
1900 /**************** JNI-functions for calling static methods **********************/
1902 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
1906 m = class_resolvemethod(clazz,
1907 utf_new_char((char *) name),
1908 utf_new_char((char *) sig));
1910 if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1911 else if (!(m->flags & ACC_STATIC)) {
1913 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
1920 jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1925 /* log_text("JNI-Call: CallStaticObjectMethod");*/
1927 va_start(vaargs, methodID);
1928 ret = callObjectMethod(0, methodID, vaargs);
1935 jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1937 /* log_text("JNI-Call: CallStaticObjectMethodV"); */
1939 return callObjectMethod(0,methodID,args);
1943 jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1945 log_text("JNI-Call: CallStaticObjectMethodA");
1951 jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1956 va_start(vaargs, methodID);
1957 ret = (jboolean) callIntegerMethod(0, methodID, 'Z', vaargs);
1964 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1966 return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
1970 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1972 log_text("JNI-Call: CallStaticBooleanMethodA");
1978 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1983 /* log_text("JNI-Call: CallStaticByteMethod");*/
1985 va_start(vaargs, methodID);
1986 ret = (jbyte) callIntegerMethod(0, methodID, 'B', vaargs);
1993 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1995 return (jbyte) callIntegerMethod(0, methodID, 'B', args);
1999 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2001 log_text("JNI-Call: CallStaticByteMethodA");
2007 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2012 /* log_text("JNI-Call: CallStaticByteMethod");*/
2014 va_start(vaargs, methodID);
2015 ret = (jchar) callIntegerMethod(0, methodID, 'C', vaargs);
2022 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2024 return (jchar) callIntegerMethod(0, methodID, 'C', args);
2028 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2030 log_text("JNI-Call: CallStaticCharMethodA");
2037 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2042 /* log_text("JNI-Call: CallStaticByteMethod");*/
2044 va_start(vaargs, methodID);
2045 ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
2052 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2054 /*log_text("JNI-Call: CallStaticShortMethodV");*/
2055 return (jshort) callIntegerMethod(0, methodID, 'S', args);
2059 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2061 log_text("JNI-Call: CallStaticShortMethodA");
2068 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2073 /* log_text("JNI-Call: CallStaticIntMethod");*/
2075 va_start(vaargs, methodID);
2076 ret = callIntegerMethod(0, methodID, 'I', vaargs);
2083 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2085 log_text("JNI-Call: CallStaticIntMethodV");
2087 return callIntegerMethod(0, methodID, 'I', args);
2091 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2093 log_text("JNI-Call: CallStaticIntMethodA");
2100 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2105 /* log_text("JNI-Call: CallStaticLongMethod");*/
2107 va_start(vaargs, methodID);
2108 ret = callLongMethod(0, methodID, vaargs);
2115 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2117 log_text("JNI-Call: CallStaticLongMethodV");
2119 return callLongMethod(0,methodID,args);
2123 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2125 log_text("JNI-Call: CallStaticLongMethodA");
2132 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2137 /* log_text("JNI-Call: CallStaticLongMethod");*/
2139 va_start(vaargs, methodID);
2140 ret = callFloatMethod(0, methodID, vaargs, 'F');
2147 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2150 return callFloatMethod(0, methodID, args, 'F');
2155 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2157 log_text("JNI-Call: CallStaticFloatMethodA");
2164 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2169 /* log_text("JNI-Call: CallStaticDoubleMethod");*/
2171 va_start(vaargs,methodID);
2172 ret = callFloatMethod(0, methodID, vaargs, 'D');
2179 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2181 log_text("JNI-Call: CallStaticDoubleMethodV");
2183 return callFloatMethod(0, methodID, args, 'D');
2187 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2189 log_text("JNI-Call: CallStaticDoubleMethodA");
2195 void CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)
2199 /* log_text("JNI-Call: CallStaticVoidMethod");*/
2201 va_start(vaargs, methodID);
2202 (void) callIntegerMethod(0, methodID, 'V', vaargs);
2207 void CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)
2209 log_text("JNI-Call: CallStaticVoidMethodV");
2210 (void)callIntegerMethod(0, methodID, 'V', args);
2214 void CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args)
2216 log_text("JNI-Call: CallStaticVoidMethodA");
2220 /****************** JNI-functions for accessing static fields ********************/
2222 jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
2226 f = jclass_findfield(clazz,
2227 utf_new_char ((char*) name),
2228 utf_new_char ((char*) sig)
2231 if (!f) *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);
2237 jobject GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2240 return fieldID->value.a;
2244 jboolean GetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2247 return fieldID->value.i;
2251 jbyte GetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2254 return fieldID->value.i;
2258 jchar GetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2261 return fieldID->value.i;
2265 jshort GetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2268 return fieldID->value.i;
2272 jint GetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2275 return fieldID->value.i;
2279 jlong GetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2282 return fieldID->value.l;
2286 jfloat GetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2289 return fieldID->value.f;
2293 jdouble GetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2296 return fieldID->value.d;
2301 void SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
2304 fieldID->value.a = value;
2308 void SetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
2311 fieldID->value.i = value;
2315 void SetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
2318 fieldID->value.i = value;
2322 void SetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
2325 fieldID->value.i = value;
2329 void SetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
2332 fieldID->value.i = value;
2336 void SetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
2339 fieldID->value.i = value;
2343 void SetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
2346 fieldID->value.l = value;
2350 void SetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
2353 fieldID->value.f = value;
2357 void SetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
2360 fieldID->value.d = value;
2364 /***** create new java.lang.String object from an array of Unicode characters ****/
2366 jstring NewString (JNIEnv *env, const jchar *buf, jsize len)
2369 java_lang_String *s;
2372 s = (java_lang_String*) builtin_new (class_java_lang_String);
2373 a = builtin_newarray_char (len);
2375 /* javastring or characterarray could not be created */
2376 if ( (!a) || (!s) ) return NULL;
2379 for (i=0; i<len; i++) a->data[i] = buf[i];
2388 static char emptyString[]="";
2389 static jchar emptyStringJ[]={0,0};
2391 /******************* returns the length of a Java string ***************************/
2393 jsize GetStringLength (JNIEnv *env, jstring str)
2395 return ((java_lang_String*) str)->count;
2399 /******************** convertes javastring to u2-array ****************************/
2401 u2 *javastring_tou2 (jstring so)
2403 java_lang_String *s = (java_lang_String*) so;
2408 if (!s) return NULL;
2411 if (!a) return NULL;
2413 /* allocate memory */
2414 stringbuffer = MNEW( u2 , s->count + 1 );
2417 for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
2419 /* terminate string */
2420 stringbuffer[i] = '\0';
2422 return stringbuffer;
2425 /********* returns a pointer to an array of Unicode characters of the string *******/
2427 const jchar *GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy)
2429 jchar *jc=javastring_tou2(str);
2432 if (isCopy) *isCopy=JNI_TRUE;
2435 if (isCopy) *isCopy=JNI_TRUE;
2436 return emptyStringJ;
2439 /**************** native code no longer needs access to chars **********************/
2441 void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
2443 if (chars==emptyStringJ) return;
2444 MFREE(((jchar*) chars),jchar,((java_lang_String*) str)->count+1);
2447 /************ create new java.lang.String object from utf8-characterarray **********/
2449 jstring NewStringUTF (JNIEnv *env, const char *utf)
2451 /* log_text("NewStringUTF called");*/
2452 return (jstring) javastring_new(utf_new_char((char *) utf));
2455 /****************** returns the utf8 length in bytes of a string *******************/
2457 jsize GetStringUTFLength (JNIEnv *env, jstring string)
2459 java_lang_String *s = (java_lang_String*) string;
2461 return (jsize) u2_utflength(s->value->data, s->count);
2465 /************ converts a Javastring to an array of UTF-8 characters ****************/
2467 const char* GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
2471 u = javastring_toutf((java_lang_String *) string, false);
2474 *isCopy = JNI_FALSE;
2484 /***************** native code no longer needs access to utf ***********************/
2486 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
2488 /*we don't release utf chars right now, perhaps that should be done later. Since there is always one reference
2489 the garbage collector will never get them*/
2491 log_text("JNI-Call: ReleaseStringUTFChars");
2492 utf_display(utf_new_char(chars));
2496 /************************** array operations ***************************************/
2498 jsize GetArrayLength(JNIEnv *env, jarray array)
2504 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
2506 java_objectarray *j;
2509 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2513 j = builtin_anewarray(len, clazz);
2519 jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
2523 if (index < array->header.size)
2524 j = array->data[index];
2526 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2532 void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
2534 if (index >= array->header.size)
2535 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2538 /* check if the class of value is a subclass of the element class of the array */
2539 if (!builtin_canstore((java_objectarray *) array, (java_objectheader *) val))
2540 *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
2543 array->data[index] = val;
2549 jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
2551 java_booleanarray *j;
2554 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2558 j = builtin_newarray_boolean(len);
2564 jbyteArray NewByteArray(JNIEnv *env, jsize len)
2569 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2573 j = builtin_newarray_byte(len);
2579 jcharArray NewCharArray(JNIEnv *env, jsize len)
2584 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2588 j = builtin_newarray_char(len);
2594 jshortArray NewShortArray(JNIEnv *env, jsize len)
2599 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2603 j = builtin_newarray_short(len);
2609 jintArray NewIntArray(JNIEnv *env, jsize len)
2614 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2618 j = builtin_newarray_int(len);
2624 jlongArray NewLongArray(JNIEnv *env, jsize len)
2629 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2633 j = builtin_newarray_long(len);
2639 jfloatArray NewFloatArray(JNIEnv *env, jsize len)
2644 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2648 j = builtin_newarray_float(len);
2654 jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
2656 java_doublearray *j;
2659 *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
2663 j = builtin_newarray_double(len);
2669 jboolean * GetBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *isCopy)
2671 if (isCopy) *isCopy = JNI_FALSE;
2676 jbyte * GetByteArrayElements (JNIEnv *env, jbyteArray array, jboolean *isCopy)
2678 if (isCopy) *isCopy = JNI_FALSE;
2683 jchar * GetCharArrayElements (JNIEnv *env, jcharArray array, jboolean *isCopy)
2685 if (isCopy) *isCopy = JNI_FALSE;
2690 jshort * GetShortArrayElements (JNIEnv *env, jshortArray array, jboolean *isCopy)
2692 if (isCopy) *isCopy = JNI_FALSE;
2697 jint * GetIntArrayElements (JNIEnv *env, jintArray array, jboolean *isCopy)
2699 if (isCopy) *isCopy = JNI_FALSE;
2704 jlong * GetLongArrayElements (JNIEnv *env, jlongArray array, jboolean *isCopy)
2706 if (isCopy) *isCopy = JNI_FALSE;
2711 jfloat * GetFloatArrayElements (JNIEnv *env, jfloatArray array, jboolean *isCopy)
2713 if (isCopy) *isCopy = JNI_FALSE;
2718 jdouble * GetDoubleArrayElements (JNIEnv *env, jdoubleArray array, jboolean *isCopy)
2720 if (isCopy) *isCopy = JNI_FALSE;
2726 void ReleaseBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode)
2732 void ReleaseByteArrayElements (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode)
2738 void ReleaseCharArrayElements (JNIEnv *env, jcharArray array, jchar *elems, jint mode)
2744 void ReleaseShortArrayElements (JNIEnv *env, jshortArray array, jshort *elems, jint mode)
2750 void ReleaseIntArrayElements (JNIEnv *env, jintArray array, jint *elems, jint mode)
2756 void ReleaseLongArrayElements (JNIEnv *env, jlongArray array, jlong *elems, jint mode)
2762 void ReleaseFloatArrayElements (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode)
2768 void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode)
2774 void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2776 if (start < 0 || len < 0 || start + len > array->header.size)
2777 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2780 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2784 void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2786 if (start < 0 || len < 0 || start + len > array->header.size)
2787 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2790 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2794 void GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2796 if (start < 0 || len < 0 || start + len > array->header.size)
2797 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2800 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2804 void GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2806 if (start < 0 || len < 0 || start + len > array->header.size)
2807 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2810 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2814 void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2816 if (start < 0 || len < 0 || start + len > array->header.size)
2817 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2820 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2824 void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2826 if (start < 0 || len < 0 || start + len > array->header.size)
2827 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2830 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2834 void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2836 if (start < 0 || len < 0 || start + len > array->header.size)
2837 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2840 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2844 void GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2846 if (start < 0 || len < 0 || start+len>array->header.size)
2847 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2850 memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
2854 void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2856 if (start < 0 || len < 0 || start + len > array->header.size)
2857 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2860 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2864 void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2866 if (start < 0 || len < 0 || start + len > array->header.size)
2867 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2870 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2874 void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *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 SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *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]));
2895 void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2897 if (start < 0 || len < 0 || start + len > array->header.size)
2898 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2901 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2906 void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2908 if (start < 0 || len < 0 || start + len > array->header.size)
2909 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2912 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2917 void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2919 if (start < 0 || len < 0 || start + len > array->header.size)
2920 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2923 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2928 void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2930 if (start < 0 || len < 0 || start + len > array->header.size)
2931 *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
2934 memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
2938 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
2940 log_text("JNI-Call: RegisterNatives");
2945 jint UnregisterNatives (JNIEnv* env, jclass clazz)
2947 log_text("JNI-Call: UnregisterNatives");
2951 /******************************* monitor operations ********************************/
2953 jint MonitorEnter (JNIEnv* env, jobject obj)
2955 builtin_monitorenter(obj);
2960 jint MonitorExit (JNIEnv* env, jobject obj)
2962 builtin_monitorexit(obj);
2967 /************************************* JavaVM interface ****************************/
2969 #error CPP mode not supported yet
2971 jint GetJavaVM (JNIEnv* env, JavaVM **vm)
2973 log_text("JNI-Call: GetJavaVM");
2977 #endif /*__cplusplus*/
2979 void GetStringRegion (JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
2981 log_text("JNI-Call: GetStringRegion");
2985 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
2987 log_text("JNI-Call: GetStringUTFRegion");
2991 /************** obtain direct pointer to array elements ***********************/
2993 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
2995 java_objectheader *s = (java_objectheader*) array;
2996 arraydescriptor *desc = s->vftbl->arraydesc;
2998 if (!desc) return NULL;
3000 return ((u1*)s) + desc->dataoffset;
3004 void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jint mode)
3006 log_text("JNI-Call: ReleasePrimitiveArrayCritical");
3011 /**** returns a pointer to an array of Unicode characters of the string *******/
3013 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
3015 log_text("JNI-Call: GetStringCritical");
3017 return GetStringChars(env,string,isCopy);
3020 /*********** native code no longer needs access to chars **********************/
3022 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
3024 log_text("JNI-Call: ReleaseStringCritical");
3026 ReleaseStringChars(env,string,cstring);
3030 jweak NewWeakGlobalRef (JNIEnv* env, jobject obj)
3032 log_text("JNI-Call: NewWeakGlobalRef");
3038 void DeleteWeakGlobalRef (JNIEnv* env, jweak ref)
3040 log_text("JNI-Call: DeleteWeakGlobalRef");
3046 /******************************* check for pending exception ***********************/
3049 jboolean ExceptionCheck(JNIEnv* env)
3051 log_text("JNI-Call: ExceptionCheck");
3053 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
3061 jint DestroyJavaVM(JavaVM *vm)
3063 log_text("DestroyJavaVM called");
3069 jint AttachCurrentThread(JavaVM *vm, void **par1, void *par2)
3071 log_text("AttachCurrentThread called");
3077 jint DetachCurrentThread(JavaVM *vm)
3079 log_text("DetachCurrentThread called");
3085 jint GetEnv(JavaVM *vm, void **environment, jint jniversion)
3087 *environment = &env;
3093 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
3095 log_text("AttachCurrentThreadAsDaemon called");
3101 /********************************* JNI invocation table ******************************/
3103 struct _JavaVM javaVMTable={
3108 &AttachCurrentThread,
3109 &DetachCurrentThread,
3111 &AttachCurrentThreadAsDaemon
3114 JavaVM javaVM = &javaVMTable;
3117 /********************************* JNI function table ******************************/
3119 struct JNI_Table envTable = {
3127 &FromReflectedMethod,
3128 &FromReflectedField,
3146 &EnsureLocalCapacity,
3158 &CallBooleanMethodV,
3159 &CallBooleanMethodA,
3184 &CallNonvirtualObjectMethod,
3185 &CallNonvirtualObjectMethodV,
3186 &CallNonvirtualObjectMethodA,
3187 &CallNonvirtualBooleanMethod,
3188 &CallNonvirtualBooleanMethodV,
3189 &CallNonvirtualBooleanMethodA,
3190 &CallNonvirtualByteMethod,
3191 &CallNonvirtualByteMethodV,
3192 &CallNonvirtualByteMethodA,
3193 &CallNonvirtualCharMethod,
3194 &CallNonvirtualCharMethodV,
3195 &CallNonvirtualCharMethodA,
3196 &CallNonvirtualShortMethod,
3197 &CallNonvirtualShortMethodV,
3198 &CallNonvirtualShortMethodA,
3199 &CallNonvirtualIntMethod,
3200 &CallNonvirtualIntMethodV,
3201 &CallNonvirtualIntMethodA,
3202 &CallNonvirtualLongMethod,
3203 &CallNonvirtualLongMethodV,
3204 &CallNonvirtualLongMethodA,
3205 &CallNonvirtualFloatMethod,
3206 &CallNonvirtualFloatMethodV,
3207 &CallNonvirtualFloatMethodA,
3208 &CallNonvirtualDoubleMethod,
3209 &CallNonvirtualDoubleMethodV,
3210 &CallNonvirtualDoubleMethodA,
3211 &CallNonvirtualVoidMethod,
3212 &CallNonvirtualVoidMethodV,
3213 &CallNonvirtualVoidMethodA,
3234 &CallStaticObjectMethod,
3235 &CallStaticObjectMethodV,
3236 &CallStaticObjectMethodA,
3237 &CallStaticBooleanMethod,
3238 &CallStaticBooleanMethodV,
3239 &CallStaticBooleanMethodA,
3240 &CallStaticByteMethod,
3241 &CallStaticByteMethodV,
3242 &CallStaticByteMethodA,
3243 &CallStaticCharMethod,
3244 &CallStaticCharMethodV,
3245 &CallStaticCharMethodA,
3246 &CallStaticShortMethod,
3247 &CallStaticShortMethodV,
3248 &CallStaticShortMethodA,
3249 &CallStaticIntMethod,
3250 &CallStaticIntMethodV,
3251 &CallStaticIntMethodA,
3252 &CallStaticLongMethod,
3253 &CallStaticLongMethodV,
3254 &CallStaticLongMethodA,
3255 &CallStaticFloatMethod,
3256 &CallStaticFloatMethodV,
3257 &CallStaticFloatMethodA,
3258 &CallStaticDoubleMethod,
3259 &CallStaticDoubleMethodV,
3260 &CallStaticDoubleMethodA,
3261 &CallStaticVoidMethod,
3262 &CallStaticVoidMethodV,
3263 &CallStaticVoidMethodA,
3265 &GetStaticObjectField,
3266 &GetStaticBooleanField,
3267 &GetStaticByteField,
3268 &GetStaticCharField,
3269 &GetStaticShortField,
3271 &GetStaticLongField,
3272 &GetStaticFloatField,
3273 &GetStaticDoubleField,
3274 &SetStaticObjectField,
3275 &SetStaticBooleanField,
3276 &SetStaticByteField,
3277 &SetStaticCharField,
3278 &SetStaticShortField,
3280 &SetStaticLongField,
3281 &SetStaticFloatField,
3282 &SetStaticDoubleField,
3286 &ReleaseStringChars,
3288 &GetStringUTFLength,
3290 &ReleaseStringUTFChars,
3293 &GetObjectArrayElement,
3294 &SetObjectArrayElement,
3303 &GetBooleanArrayElements,
3304 &GetByteArrayElements,
3305 &GetCharArrayElements,
3306 &GetShortArrayElements,
3307 &GetIntArrayElements,
3308 &GetLongArrayElements,
3309 &GetFloatArrayElements,
3310 &GetDoubleArrayElements,
3311 &ReleaseBooleanArrayElements,
3312 &ReleaseByteArrayElements,
3313 &ReleaseCharArrayElements,
3314 &ReleaseShortArrayElements,
3315 &ReleaseIntArrayElements,
3316 &ReleaseLongArrayElements,
3317 &ReleaseFloatArrayElements,
3318 &ReleaseDoubleArrayElements,
3319 &GetBooleanArrayRegion,
3320 &GetByteArrayRegion,
3321 &GetCharArrayRegion,
3322 &GetShortArrayRegion,
3324 &GetLongArrayRegion,
3325 &GetFloatArrayRegion,
3326 &GetDoubleArrayRegion,
3327 &SetBooleanArrayRegion,
3328 &SetByteArrayRegion,
3329 &SetCharArrayRegion,
3330 &SetShortArrayRegion,
3332 &SetLongArrayRegion,
3333 &SetFloatArrayRegion,
3334 &SetDoubleArrayRegion,
3341 &GetStringUTFRegion,
3342 &GetPrimitiveArrayCritical,
3343 &ReleasePrimitiveArrayCritical,
3345 &ReleaseStringCritical,
3347 &DeleteWeakGlobalRef,
3351 JNIEnv env = &envTable;
3354 jobject *jni_method_invokeNativeHelper(JNIEnv *env, struct methodinfo *methodID, jobject obj, java_objectarray *params)
3361 if (methodID == 0) {
3362 *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
3366 argcount = get_parametercount(methodID);
3368 if (obj && (!builtin_instanceof((java_objectheader *) obj, methodID->class))) {
3369 *exceptionptr = new_exception_message(string_java_lang_IllegalArgumentException,
3370 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
3377 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
3378 log_text("Too many arguments. invokeNativeHelper does not support that");
3382 if (((!params) && (argcount != 0)) || (params && (params->header.size != argcount))) {
3383 *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
3388 if (!(methodID->flags & ACC_STATIC) && (!obj)) {
3389 *exceptionptr = new_exception_message(string_java_lang_NullPointerException,
3390 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
3394 if ((methodID->flags & ACC_STATIC) && (obj)) obj = 0;
3396 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
3398 retT = fill_callblock_objA(obj, methodID->descriptor, blk, params);
3402 (void) asm_calljavafunction2(methodID,
3404 (argcount + 1) * sizeof(jni_callblock),
3406 retVal = NULL; /*native_new_and_init(loader_load(utf_new_char("java/lang/Void")));*/
3411 intVal = (s4) asm_calljavafunction2(methodID,
3413 (argcount + 1) * sizeof(jni_callblock),
3415 retVal = builtin_new(class_new(utf_new_char("java/lang/Integer")));
3418 class_resolvemethod(retVal->vftbl->class,
3419 utf_new_char("<init>"),
3420 utf_new_char("(I)V")),
3427 intVal = (s4) asm_calljavafunction2(methodID,
3429 (argcount + 1) * sizeof(jni_callblock),
3431 retVal = builtin_new(class_new(utf_new_char("java/lang/Byte")));
3434 class_resolvemethod(retVal->vftbl->class,
3435 utf_new_char("<init>"),
3436 utf_new_char("(B)V")),
3443 intVal = (s4) asm_calljavafunction2(methodID,
3445 (argcount + 1) * sizeof(jni_callblock),
3447 retVal = builtin_new(class_new(utf_new_char("java/lang/Character")));
3450 class_resolvemethod(retVal->vftbl->class,
3451 utf_new_char("<init>"),
3452 utf_new_char("(C)V")),
3459 intVal = (s4) asm_calljavafunction2(methodID,
3461 (argcount + 1) * sizeof(jni_callblock),
3463 retVal = builtin_new(class_new(utf_new_char("java/lang/Short")));
3466 class_resolvemethod(retVal->vftbl->class,
3467 utf_new_char("<init>"),
3468 utf_new_char("(S)V")),
3475 intVal = (s4) asm_calljavafunction2(methodID,
3477 (argcount + 1) * sizeof(jni_callblock),
3479 retVal = builtin_new(class_new(utf_new_char("java/lang/Boolean")));
3482 class_resolvemethod(retVal->vftbl->class,
3483 utf_new_char("<init>"),
3484 utf_new_char("(Z)V")),
3491 intVal = asm_calljavafunction2long(methodID,
3493 (argcount + 1) * sizeof(jni_callblock),
3495 retVal = builtin_new(class_new(utf_new_char("java/lang/Long")));
3498 class_resolvemethod(retVal->vftbl->class,
3499 utf_new_char("<init>"),
3500 utf_new_char("(J)V")),
3507 floatVal = asm_calljavafunction2double(methodID,
3509 (argcount + 1) * sizeof(jni_callblock),
3511 retVal = builtin_new(class_new(utf_new_char("java/lang/Float")));
3514 class_resolvemethod(retVal->vftbl->class,
3515 utf_new_char("<init>"),
3516 utf_new_char("(F)V")),
3523 floatVal = asm_calljavafunction2double(methodID,
3525 (argcount + 1) * sizeof(jni_callblock),
3527 retVal = builtin_new(class_new(utf_new_char("java/lang/Double")));
3530 class_resolvemethod(retVal->vftbl->class,
3531 utf_new_char("<init>"),
3532 utf_new_char("(D)V")),
3537 case 'L': /* fall through */
3539 retVal = asm_calljavafunction2(methodID,
3541 (argcount + 1) * sizeof(jni_callblock),
3546 /* if this happens the acception has already been set by fill_callblock_objA*/
3547 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3548 return (jobject *) 0;
3551 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3553 if (*exceptionptr) {
3554 java_objectheader *exceptionToWrap = *exceptionptr;
3556 java_objectheader *ivte;
3558 *exceptionptr = NULL;
3559 ivtec = class_new(utf_new_char("java/lang/reflect/InvocationTargetException"));
3560 ivte = builtin_new(ivtec);
3561 asm_calljavafunction(class_resolvemethod(ivtec,
3562 utf_new_char("<init>"),
3563 utf_new_char("(Ljava/lang/Throwable;)V")),
3569 if (*exceptionptr != NULL)
3570 panic("jni.c: error while creating InvocationTargetException wrapper");
3572 *exceptionptr = ivte;
3575 return (jobject *) retVal;
3580 * These are local overrides for various environment variables in Emacs.
3581 * Please do not remove this and leave it at the end of the file, where
3582 * Emacs will automagically detect them.
3583 * ---------------------------------------------------------------------
3586 * indent-tabs-mode: t