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 944 2004-03-06 20:50:31Z 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 java_objectarray* result;
86 int parametercount = 0;
92 /* determine number of parameters */
93 while ( *utf_ptr != ')' ) {
94 get_type(&utf_ptr,desc_end,true);
98 return parametercount;
103 void fill_callblock(void *obj, utf *descr, jni_callblock blk[], va_list data, char ret)
105 char *utf__ptr = descr->text; /* current position in utf-text */
106 char **utf_ptr = &utf__ptr;
107 char *desc_end = utf_end(descr); /* points behind utf string */
116 log_text("fill_callblock");
123 /* determine number of parameters */
125 blk[0].itemtype = TYPE_ADR;
126 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);
143 blk[cnt].itemtype=TYPE_INT;
144 dummy=va_arg(data,u4);
145 /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
146 blk[cnt].item=(u8)dummy;
151 blk[cnt].itemtype=TYPE_LNG;
152 blk[cnt].item=(u8)va_arg(data,jlong);
155 blk[cnt].itemtype=TYPE_FLT;
156 *((jfloat*)(&blk[cnt].item))=((jfloat)va_arg(data,jdouble));
160 blk[cnt].itemtype=TYPE_DBL;
161 *((jdouble*)(&blk[cnt].item))=(jdouble)va_arg(data,jdouble);
163 case 'V' : panic ("V not allowed as function parameter");
166 while (utf_nextu2(utf_ptr)!=';')
168 blk[cnt].itemtype=TYPE_ADR;
169 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=='['))) log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
197 } else if (ret != c) log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
201 /* XXX it could be considered if we should do typechecking here in the future */
202 char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_objectarray* params)
204 char *utf__ptr = descr->text; /* current position in utf-text */
205 char **utf_ptr = &utf__ptr;
206 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=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
263 if (param->vftbl->class->name==utf_byte) {
264 blk[cnt].itemtype=TYPE_INT;
265 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
267 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
272 param=params->data[cnts];
274 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
277 if (param->vftbl->class->name==utf_char) {
278 blk[cnt].itemtype=TYPE_INT;
279 blk[cnt].item = (u8) ((struct java_lang_Character * )param)->value;
281 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
287 param=params->data[cnts];
289 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
292 if (param->vftbl->class->name==utf_short) {
293 blk[cnt].itemtype=TYPE_INT;
294 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
296 if (param->vftbl->class->name==utf_byte) {
297 blk[cnt].itemtype=TYPE_INT;
298 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
300 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
307 param=params->data[cnts];
309 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
312 if (param->vftbl->class->name==utf_bool) {
313 blk[cnt].itemtype=TYPE_INT;
314 blk[cnt].item = (u8) ((struct java_lang_Boolean * )param)->value;
316 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
322 /*log_text("fill_callblock_objA: param 'I'");*/
323 param=params->data[cnts];
325 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
328 if (param->vftbl->class->name==utf_int) {
329 blk[cnt].itemtype=TYPE_INT;
330 blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
331 /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
333 if (param->vftbl->class->name==utf_short) {
334 blk[cnt].itemtype=TYPE_INT;
335 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
337 if (param->vftbl->class->name==utf_byte) {
338 blk[cnt].itemtype=TYPE_INT;
339 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
342 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
349 param=params->data[cnts];
351 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
354 if (param->vftbl->class->name==utf_long) {
355 blk[cnt].itemtype=TYPE_LNG;
356 blk[cnt].item = (u8) ((struct java_lang_Long * )param)->value;
358 if (param->vftbl->class->name==utf_int) {
359 blk[cnt].itemtype=TYPE_LNG;
360 blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
362 if (param->vftbl->class->name==utf_short) {
363 blk[cnt].itemtype=TYPE_LNG;
364 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
366 if (param->vftbl->class->name==utf_byte) {
367 blk[cnt].itemtype=TYPE_LNG;
368 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
370 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
380 param=params->data[cnts];
382 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
386 if (param->vftbl->class->name==utf_float) {
387 blk[cnt].itemtype=TYPE_FLT;
388 *((jfloat*)(&blk[cnt].item))=(jfloat) ((struct java_lang_Float*)param)->value;
390 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
395 param=params->data[cnts];
397 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
401 if (param->vftbl->class->name==utf_double) {
402 blk[cnt].itemtype=TYPE_DBL;
403 *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
405 if (param->vftbl->class->name==utf_float) {
406 blk[cnt].itemtype=TYPE_DBL;
407 *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
409 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
415 panic("V not allowed as function parameter");
419 char *start=(*utf_ptr)-1;
422 while (utf_nextu2(utf_ptr) != ';')
424 if (!builtin_instanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD))) {
425 if (params->data[cnts]!=0) {
426 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
430 blk[cnt].itemtype = TYPE_ADR;
431 blk[cnt].item= PTR_TO_ITEM(params->data[cnts]);
437 char *start=(*utf_ptr)-1;
441 while ((ch = utf_nextu2(utf_ptr)) == '[')
443 while (utf_nextu2(utf_ptr) != ';') {}
446 ch = utf_nextu2(utf_ptr);
447 if (!builtin_arrayinstanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD)->vftbl)) {
448 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
453 blk[cnt].itemtype = TYPE_ADR;
454 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
462 c = utf_nextu2(utf_ptr);
463 c = utf_nextu2(utf_ptr);
464 return c; /*return type needed usage of the right lowlevel methods*/
481 jmethodID get_virtual(jobject obj,jmethodID methodID) {
482 if (obj->vftbl->class==methodID->class) return methodID;
483 return class_resolvemethod (obj->vftbl->class, methodID->name, methodID->descriptor);
486 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
487 if (clazz==methodID->class) return methodID;
488 return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
493 jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
500 log_text("JNI-Call: CallObjectMethodV");
501 utf_display(methodID->name);
502 utf_display(methodID->descriptor);
503 printf("\nParmaeter count: %d\n",argcount);
504 utf_display(obj->vftbl->class->name);
509 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
513 argcount = get_parametercount(methodID);
515 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
516 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
517 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
521 if (obj && !builtin_instanceof(obj, methodID->class)) {
522 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
527 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
528 log_text("Too many arguments. CallObjectMethod does not support that");
532 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
534 fill_callblock(obj, methodID->descriptor, blk, args, 'O');
536 /* printf("parameter: obj: %p",blk[0].item); */
537 ret = asm_calljavafunction2(methodID,
539 (argcount + 1) * sizeof(jni_callblock),
542 MFREE(blk, jni_callblock, argcount + 1);
543 /* printf("(CallObjectMethodV)-->%p\n",ret); */
549 core function for integer class methods (bool, byte, short, integer)
550 This is basically needed for i386
552 jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list args)
558 /* printf("%p, %c\n",retType,methodID,retType);*/
561 log_text("JNI-Call: CallObjectMethodV");
562 utf_display(methodID->name);
563 utf_display(methodID->descriptor);
564 printf("\nParmaeter count: %d\n",argcount);
565 utf_display(obj->vftbl->class->name);
569 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
573 argcount = get_parametercount(methodID);
575 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
576 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
577 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
581 if (obj && !builtin_instanceof(obj, methodID->class)) {
582 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
588 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
589 log_text("Too many arguments. CallObjectMethod does not support that");
593 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
595 fill_callblock(obj, methodID->descriptor, blk, args, retType);
597 /* printf("parameter: obj: %p",blk[0].item); */
598 ret = (jint) asm_calljavafunction2(methodID,
600 (argcount + 1) * sizeof(jni_callblock),
603 MFREE(blk, jni_callblock, argcount + 1);
604 /* printf("(CallObjectMethodV)-->%p\n",ret); */
610 /*core function for long class functions*/
611 jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
618 log_text("JNI-Call: CallObjectMethodV");
619 utf_display(methodID->name);
620 utf_display(methodID->descriptor);
621 printf("\nParmaeter count: %d\n",argcount);
622 utf_display(obj->vftbl->class->name);
626 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
630 argcount = get_parametercount(methodID);
632 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
633 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
634 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
638 if (obj && !builtin_instanceof(obj,methodID->class)) {
639 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
645 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
646 log_text("Too many arguments. CallObjectMethod does not support that");
650 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
652 fill_callblock(obj, methodID->descriptor, blk, args, 'L');
654 /* printf("parameter: obj: %p",blk[0].item); */
655 ret = asm_calljavafunction2long(methodID,
657 (argcount + 1) * sizeof(jni_callblock),
660 MFREE(blk, jni_callblock, argcount + 1);
661 /* printf("(CallObjectMethodV)-->%p\n",ret); */
667 /*core function for float class methods (float,double)*/
668 jdouble callFloatMethod(jobject obj, jmethodID methodID, va_list args,char retType)
670 int argcount = get_parametercount(methodID);
675 log_text("JNI-Call: CallObjectMethodV");
676 utf_display(methodID->name);
677 utf_display(methodID->descriptor);
678 printf("\nParmaeter count: %d\n",argcount);
679 utf_display(obj->vftbl->class->name);
684 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
685 log_text("Too many arguments. CallObjectMethod does not support that");
689 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
691 fill_callblock(obj, methodID->descriptor, blk, args, retType);
693 /* printf("parameter: obj: %p",blk[0].item); */
694 ret = asm_calljavafunction2double(methodID,
696 (argcount + 1) * sizeof(jni_callblock),
699 MFREE(blk, jni_callblock, argcount + 1);
700 /* printf("(CallObjectMethodV)-->%p\n",ret); */
706 /*************************** function: jclass_findfield ****************************
708 searches for field with specified name and type in a 'classinfo'-structur
709 if no such field is found NULL is returned
711 ************************************************************************************/
713 fieldinfo *jclass_findfield (classinfo *c, utf *name, utf *desc)
716 /* printf(" FieldCount: %d\n",c->fieldscount);
717 utf_display(c->name); */
718 for (i = 0; i < c->fieldscount; i++) {
719 /* utf_display(c->fields[i].name);
721 utf_display(c->fields[i].descriptor);
723 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
724 return &(c->fields[i]);
727 if (c->super) return jclass_findfield(c->super,name,desc);
732 /********************* returns version of native method interface *****************/
734 jint GetVersion (JNIEnv* env)
739 /****************** loads a class from a buffer of raw class data *****************/
741 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len)
745 /* change suck-mode, so subsequent class_load will read from memory-buffer */
746 classload_buffer( (u1*) buf,len);
748 clazz = loader_load(utf_new_char ((char *) name));
750 /* restore old suck-mode */
751 classload_buffer(NULL,0);
752 if (clazz) clazz->classloader=loader;
757 /*************** loads locally defined class with the specified name **************/
759 jclass FindClass (JNIEnv* env, const char *name)
763 /* if (strcmp(name,"[B")==0) {
764 c = loader_load(utf_new_char("The_Array_Class"));
767 c = loader_load(utf_new_char_classname ((char *) name));
769 if (!c) *exceptionptr = native_new_and_init(class_java_lang_ClassFormatError);
775 /***********************************************************************************
777 converts java.lang.reflect.Method or
778 java.lang.reflect.Constructor object to a method ID
780 **********************************************************************************/
782 jmethodID FromReflectedMethod(JNIEnv* env, jobject method)
784 /* log_text("JNI-Call: FromReflectedMethod"); */
790 /*************** return superclass of the class represented by sub ****************/
792 jclass GetSuperclass(JNIEnv* env, jclass sub)
796 c = ((classinfo*) sub)->super;
800 use_class_as_object(c);
806 /*********************** check whether sub can be cast to sup ********************/
808 jboolean IsAssignableForm(JNIEnv* env, jclass sub, jclass sup)
810 return builtin_isanysubclass(sub, sup);
814 /***** converts a field ID derived from cls to a java.lang.reflect.Field object ***/
816 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isStatic)
818 /* log_text("JNI-Call: ToReflectedField"); */
824 /***************** throw java.lang.Throwable object ******************************/
826 jint Throw(JNIEnv* env, jthrowable obj)
828 *exceptionptr = (java_objectheader*) obj;
834 /***********************************************************************************
836 create exception object from the class clazz with the
837 specified message and cause it to be thrown
839 **********************************************************************************/
841 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
843 java_lang_Throwable *o;
845 /* instantiate exception object */
846 o = (java_lang_Throwable *) native_new_and_init ((classinfo*) clazz);
850 o->detailMessage = (java_lang_String*) javastring_new_char((char *) msg);
852 *exceptionptr = (java_objectheader*) o;
858 /************************* check if exception occured *****************************/
860 jthrowable ExceptionOccurred (JNIEnv* env)
862 return (jthrowable) *exceptionptr;
865 /********** print exception and a backtrace of the stack (for debugging) **********/
867 void ExceptionDescribe (JNIEnv* env)
869 utf_display((*exceptionptr)->vftbl->class->name);
875 /******************* clear any exception currently being thrown *******************/
877 void ExceptionClear (JNIEnv* env)
879 *exceptionptr = NULL;
883 /********** raises a fatal error and does not expect the VM to recover ************/
885 void FatalError (JNIEnv* env, const char *msg)
890 /******************* creates a new local reference frame **************************/
892 jint PushLocalFrame(JNIEnv* env, jint capacity)
899 /**************** Pops off the current local reference frame **********************/
901 jobject PopLocalFrame(JNIEnv* env, jobject result)
909 /** Creates a new global reference to the object referred to by the obj argument **/
911 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
916 /************* Deletes the global reference pointed to by globalRef **************/
918 void DeleteGlobalRef (JNIEnv* env, jobject gref)
924 /*************** Deletes the local reference pointed to by localRef ***************/
926 void DeleteLocalRef (JNIEnv* env, jobject localRef)
931 /********** Tests whether two references refer to the same Java object ************/
933 jboolean IsSameObject (JNIEnv* env, jobject obj1, jobject obj2)
938 /***** Creates a new local reference that refers to the same object as ref *******/
940 jobject NewLocalRef (JNIEnv* env, jobject ref)
945 /***********************************************************************************
947 Ensures that at least a given number of local references can
948 be created in the current thread
950 **********************************************************************************/
952 jint EnsureLocalCapacity (JNIEnv* env, jint capacity)
954 return 0; /* return 0 on success */
958 /********* Allocates a new Java object without invoking a constructor *************/
960 jobject AllocObject (JNIEnv* env, jclass clazz)
962 java_objectheader *o = builtin_new(clazz);
967 /***********************************************************************************
969 Constructs a new Java object
970 arguments that are to be passed to the constructor are placed after methodID
972 ***********************************************************************************/
974 jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
976 java_objectheader *o;
978 int argcount=get_parametercount(methodID);
982 /* log_text("JNI-Call: NewObject"); */
985 *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
986 log_text("Too many arguments. NewObject does not support that");
991 o = builtin_new (clazz); /* create object */
995 va_start(vaargs,methodID);
996 for (i=0;i<argcount;i++) {
997 args[i]=va_arg(vaargs,void*);
1000 asm_calljavafunction(methodID,o,args[0],args[1],args[2]);
1006 /***********************************************************************************
1008 Constructs a new Java object
1009 arguments that are to be passed to the constructor are placed in va_list args
1011 ***********************************************************************************/
1013 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1015 /* log_text("JNI-Call: NewObjectV"); */
1021 /***********************************************************************************
1023 Constructs a new Java object
1024 arguments that are to be passed to the constructor are placed in
1025 args array of jvalues
1027 ***********************************************************************************/
1029 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1031 /* log_text("JNI-Call: NewObjectA"); */
1037 /************************ returns the class of an object **************************/
1039 jclass GetObjectClass(JNIEnv* env, jobject obj)
1041 classinfo *c = obj->vftbl->class;
1042 /* log_text("GetObjectClass");
1043 utf_display(obj->vftbl->class->name);*/
1044 use_class_as_object(c);
1046 /*printf("\nPointer: %p\n",c);*/
1051 /************* tests whether an object is an instance of a class ******************/
1053 jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz)
1055 return builtin_instanceof(obj,clazz);
1059 /***************** converts a java.lang.reflect.Field to a field ID ***************/
1061 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1063 log_text("JNI-Call: FromReflectedField");
1069 /**********************************************************************************
1071 converts a method ID to a java.lang.reflect.Method or
1072 java.lang.reflect.Constructor object
1074 **********************************************************************************/
1076 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1078 log_text("JNI-Call: ToReflectedMethod");
1084 /**************** returns the method ID for an instance method ********************/
1086 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *sig)
1090 m = class_resolvemethod (
1092 utf_new_char ((char*) name),
1093 utf_new_char ((char*) sig)
1096 if (!m) *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
1102 /******************** JNI-functions for calling instance methods ******************/
1104 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1109 /* log_text("JNI-Call: CallObjectMethod");*/
1111 va_start(vaargs, methodID);
1112 ret = callObjectMethod(obj, methodID, vaargs);
1119 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1121 return callObjectMethod(obj,methodID,args);
1125 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1127 log_text("JNI-Call: CallObjectMethodA");
1135 jboolean CallBooleanMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1140 /* log_text("JNI-Call: CallBooleanMethod");*/
1142 va_start(vaargs,methodID);
1143 ret = (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',vaargs);
1149 jboolean CallBooleanMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1151 return (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',args);
1155 jboolean CallBooleanMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1157 log_text("JNI-Call: CallBooleanMethodA");
1162 jbyte CallByteMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1167 /* log_text("JNI-Call: CallVyteMethod");*/
1169 va_start(vaargs,methodID);
1170 ret = callIntegerMethod(obj,get_virtual(obj,methodID),'B',vaargs);
1176 jbyte CallByteMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1178 /* log_text("JNI-Call: CallByteMethodV");*/
1179 return callIntegerMethod(obj,methodID,'B',args);
1183 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1185 log_text("JNI-Call: CallByteMethodA");
1191 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1196 /* log_text("JNI-Call: CallCharMethod");*/
1198 va_start(vaargs,methodID);
1199 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'C', vaargs);
1206 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1208 /* log_text("JNI-Call: CallCharMethodV");*/
1209 return callIntegerMethod(obj,get_virtual(obj,methodID),'C',args);
1213 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1215 log_text("JNI-Call: CallCharMethodA");
1221 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1226 /* log_text("JNI-Call: CallShortMethod");*/
1228 va_start(vaargs, methodID);
1229 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'S', vaargs);
1236 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1238 return callIntegerMethod(obj, get_virtual(obj, methodID), 'S', args);
1242 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1244 log_text("JNI-Call: CallShortMethodA");
1251 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1256 va_start(vaargs,methodID);
1257 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'I', vaargs);
1264 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1266 return callIntegerMethod(obj, get_virtual(obj, methodID), 'I', args);
1270 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1272 log_text("JNI-Call: CallIntMethodA");
1279 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1281 log_text("JNI-Call: CallLongMethod");
1287 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1289 log_text("JNI-Call: CallLongMethodV");
1295 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1297 log_text("JNI-Call: CallLongMethodA");
1304 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1309 /* log_text("JNI-Call: CallFloatMethod");*/
1311 va_start(vaargs,methodID);
1312 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'F');
1319 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1321 log_text("JNI-Call: CallFloatMethodV");
1322 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'F');
1326 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1328 log_text("JNI-Call: CallFloatMethodA");
1335 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1340 /* log_text("JNI-Call: CallDoubleMethod");*/
1342 va_start(vaargs,methodID);
1343 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'D');
1350 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1352 log_text("JNI-Call: CallDoubleMethodV");
1353 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'D');
1357 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1359 log_text("JNI-Call: CallDoubleMethodA");
1365 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1369 /* log_text("JNI-Call: CallVoidMethod");*/
1371 va_start(vaargs,methodID);
1372 (void) callIntegerMethod(obj, get_virtual(obj, methodID), 'V', vaargs);
1377 void CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1379 log_text("JNI-Call: CallVoidMethodV");
1380 (void)callIntegerMethod(obj,get_virtual(obj,methodID),'V',args);
1384 void CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1386 log_text("JNI-Call: CallVoidMethodA");
1391 jobject CallNonvirtualObjectMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1393 log_text("JNI-Call: CallNonvirtualObjectMethod");
1399 jobject CallNonvirtualObjectMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1401 log_text("JNI-Call: CallNonvirtualObjectMethodV");
1407 jobject CallNonvirtualObjectMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1409 log_text("JNI-Call: CallNonvirtualObjectMethodA");
1416 jboolean CallNonvirtualBooleanMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1421 /* log_text("JNI-Call: CallNonvirtualBooleanMethod");*/
1423 va_start(vaargs,methodID);
1424 ret = (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',vaargs);
1431 jboolean CallNonvirtualBooleanMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1433 /* log_text("JNI-Call: CallNonvirtualBooleanMethodV");*/
1434 return (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',args);
1438 jboolean CallNonvirtualBooleanMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1440 log_text("JNI-Call: CallNonvirtualBooleanMethodA");
1447 jbyte CallNonvirtualByteMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1452 /* log_text("JNI-Call: CallNonvirutalByteMethod");*/
1454 va_start(vaargs,methodID);
1455 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',vaargs);
1461 jbyte CallNonvirtualByteMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1463 /*log_text("JNI-Call: CallNonvirtualByteMethodV"); */
1464 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',args);
1469 jbyte CallNonvirtualByteMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1471 log_text("JNI-Call: CallNonvirtualByteMethodA");
1478 jchar CallNonvirtualCharMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1483 /* log_text("JNI-Call: CallNonVirtualCharMethod");*/
1485 va_start(vaargs,methodID);
1486 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',vaargs);
1492 jchar CallNonvirtualCharMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1494 /*log_text("JNI-Call: CallNonvirtualCharMethodV");*/
1495 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',args);
1499 jchar CallNonvirtualCharMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1501 log_text("JNI-Call: CallNonvirtualCharMethodA");
1508 jshort CallNonvirtualShortMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1513 /*log_text("JNI-Call: CallNonvirtualShortMethod");*/
1515 va_start(vaargs,methodID);
1516 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',vaargs);
1522 jshort CallNonvirtualShortMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1524 /*log_text("JNI-Call: CallNonvirtualShortMethodV");*/
1525 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',args);
1529 jshort CallNonvirtualShortMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1531 log_text("JNI-Call: CallNonvirtualShortMethodA");
1538 jint CallNonvirtualIntMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1544 /*log_text("JNI-Call: CallNonvirtualIntMethod");*/
1546 va_start(vaargs,methodID);
1547 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',vaargs);
1553 jint CallNonvirtualIntMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1555 /*log_text("JNI-Call: CallNonvirtualIntMethodV");*/
1556 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',args);
1560 jint CallNonvirtualIntMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1562 log_text("JNI-Call: CallNonvirtualIntMethodA");
1569 jlong CallNonvirtualLongMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1571 log_text("JNI-Call: CallNonvirtualLongMethod");
1577 jlong CallNonvirtualLongMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1579 log_text("JNI-Call: CallNonvirtualLongMethodV");
1585 jlong CallNonvirtualLongMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1587 log_text("JNI-Call: CallNonvirtualLongMethodA");
1594 jfloat CallNonvirtualFloatMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1599 /*log_text("JNI-Call: CallNonvirtualFloatMethod");*/
1602 va_start(vaargs,methodID);
1603 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'F');
1610 jfloat CallNonvirtualFloatMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1612 log_text("JNI-Call: CallNonvirtualFloatMethodV");
1613 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'F');
1617 jfloat CallNonvirtualFloatMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1619 log_text("JNI-Call: CallNonvirtualFloatMethodA");
1626 jdouble CallNonvirtualDoubleMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1630 log_text("JNI-Call: CallNonvirtualDoubleMethod");
1632 va_start(vaargs,methodID);
1633 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'D');
1640 jdouble CallNonvirtualDoubleMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1642 /* log_text("JNI-Call: CallNonvirtualDoubleMethodV");*/
1643 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'D');
1647 jdouble CallNonvirtualDoubleMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1649 log_text("JNI-Call: CallNonvirtualDoubleMethodA");
1656 void CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1660 /* log_text("JNI-Call: CallNonvirtualVoidMethod");*/
1662 va_start(vaargs,methodID);
1663 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',vaargs);
1669 void CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1671 /* log_text("JNI-Call: CallNonvirtualVoidMethodV");*/
1673 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',args);
1678 void CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1680 log_text("JNI-Call: CallNonvirtualVoidMethodA");
1683 /************************* JNI-functions for accessing fields ************************/
1685 jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
1689 /* log_text("========================= searching for:");
1692 f = jclass_findfield(clazz,
1693 utf_new_char ((char*) name),
1694 utf_new_char ((char*) sig)
1698 /* utf_display(clazz->name);
1701 *exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldError);
1706 /*************************** retrieve fieldid, abort on error ************************/
1708 jfieldID getFieldID_critical(JNIEnv *env, jclass clazz, char *name, char *sig)
1710 jfieldID id = GetFieldID(env, clazz, name, sig);
1714 utf_display(clazz->name);
1715 log_text("\nfield:");
1720 panic("setfield_critical failed");
1725 jobject GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
1727 return getField(obj,jobject,fieldID);
1730 jboolean GetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID)
1732 return getField(obj,jboolean,fieldID);
1736 jbyte GetByteField (JNIEnv *env, jobject obj, jfieldID fieldID)
1738 return getField(obj,jbyte,fieldID);
1742 jchar GetCharField (JNIEnv *env, jobject obj, jfieldID fieldID)
1744 return getField(obj,jchar,fieldID);
1748 jshort GetShortField (JNIEnv *env, jobject obj, jfieldID fieldID)
1750 return getField(obj,jshort,fieldID);
1754 jint GetIntField (JNIEnv *env, jobject obj, jfieldID fieldID)
1756 return getField(obj,jint,fieldID);
1760 jlong GetLongField (JNIEnv *env, jobject obj, jfieldID fieldID)
1762 return getField(obj,jlong,fieldID);
1766 jfloat GetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID)
1768 return getField(obj,jfloat,fieldID);
1772 jdouble GetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID)
1774 return getField(obj,jdouble,fieldID);
1777 void SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
1779 setField(obj,jobject,fieldID,val);
1783 void SetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val)
1785 setField(obj,jboolean,fieldID,val);
1789 void SetByteField (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val)
1791 setField(obj,jbyte,fieldID,val);
1795 void SetCharField (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val)
1797 setField(obj,jchar,fieldID,val);
1801 void SetShortField (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val)
1803 setField(obj,jshort,fieldID,val);
1807 void SetIntField (JNIEnv *env, jobject obj, jfieldID fieldID, jint val)
1809 setField(obj,jint,fieldID,val);
1813 void SetLongField (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val)
1815 setField(obj,jlong,fieldID,val);
1819 void SetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val)
1821 setField(obj,jfloat,fieldID,val);
1825 void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
1827 setField(obj,jdouble,fieldID,val);
1831 /**************** JNI-functions for calling static methods **********************/
1833 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
1837 m = class_resolvemethod(
1839 utf_new_char((char*) name),
1840 utf_new_char((char*) sig));
1842 if (!m) *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
1848 jobject CallStaticObjectMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1850 log_text("JNI-Call: CallStaticObjectMethod");
1856 jobject CallStaticObjectMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1858 log_text("JNI-Call: CallStaticObjectMethodV");
1864 jobject CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1866 log_text("JNI-Call: CallStaticObjectMethodA");
1872 jboolean CallStaticBooleanMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1877 /* log_text("JNI-Call: CallStaticBooleanMethod");*/
1879 va_start(vaargs,methodID);
1880 ret = (jboolean)callIntegerMethod(0,methodID,'Z',vaargs);
1887 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1889 return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
1892 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1894 log_text("JNI-Call: CallStaticBooleanMethodA");
1900 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1905 /* log_text("JNI-Call: CallStaticByteMethod");*/
1907 va_start(vaargs, methodID);
1908 ret = (jbyte) callIntegerMethod(0, methodID, 'B', vaargs);
1915 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1917 return (jbyte) callIntegerMethod(0, methodID, 'B', args);
1921 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1923 log_text("JNI-Call: CallStaticByteMethodA");
1929 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1934 /* log_text("JNI-Call: CallStaticByteMethod");*/
1936 va_start(vaargs, methodID);
1937 ret = (jchar) callIntegerMethod(0, methodID, 'C', vaargs);
1944 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1946 return (jchar) callIntegerMethod(0, methodID, 'C', args);
1950 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1952 log_text("JNI-Call: CallStaticCharMethodA");
1959 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1964 /* log_text("JNI-Call: CallStaticByteMethod");*/
1966 va_start(vaargs,methodID);
1967 ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
1974 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1976 /*log_text("JNI-Call: CallStaticShortMethodV");*/
1977 return (jshort) callIntegerMethod(0, methodID, 'S', args);
1981 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1983 log_text("JNI-Call: CallStaticShortMethodA");
1990 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1995 /* log_text("JNI-Call: CallStaticIntMethod");*/
1997 va_start(vaargs, methodID);
1998 ret = callIntegerMethod(0, methodID, 'I', vaargs);
2005 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2007 log_text("JNI-Call: CallStaticIntMethodV");
2009 return callIntegerMethod(0, methodID, 'I', args);
2013 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2015 log_text("JNI-Call: CallStaticIntMethodA");
2022 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2027 /* log_text("JNI-Call: CallStaticLongMethod");*/
2029 va_start(vaargs, methodID);
2030 ret = callLongMethod(0, methodID, vaargs);
2037 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2039 log_text("JNI-Call: CallStaticLongMethodV");
2041 return callLongMethod(0,methodID,args);
2045 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2047 log_text("JNI-Call: CallStaticLongMethodA");
2054 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2059 /* log_text("JNI-Call: CallStaticLongMethod");*/
2061 va_start(vaargs, methodID);
2062 ret = callFloatMethod(0, methodID, vaargs, 'F');
2069 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2072 return callFloatMethod(0, methodID, args, 'F');
2077 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2079 log_text("JNI-Call: CallStaticFloatMethodA");
2086 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2091 /* log_text("JNI-Call: CallStaticDoubleMethod");*/
2093 va_start(vaargs,methodID);
2094 ret = callFloatMethod(0, methodID, vaargs, 'D');
2101 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2103 log_text("JNI-Call: CallStaticDoubleMethodV");
2105 return callFloatMethod(0, methodID, args, 'D');
2109 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2111 log_text("JNI-Call: CallStaticDoubleMethodA");
2117 void CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)
2121 /* log_text("JNI-Call: CallStaticVoidMethod");*/
2123 va_start(vaargs, methodID);
2124 (void) callIntegerMethod(0, methodID, 'V', vaargs);
2129 void CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)
2131 log_text("JNI-Call: CallStaticVoidMethodV");
2132 (void)callIntegerMethod(0, methodID, 'V', args);
2136 void CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args)
2138 log_text("JNI-Call: CallStaticVoidMethodA");
2142 /****************** JNI-functions for accessing static fields ********************/
2144 jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
2148 f = jclass_findfield(clazz,
2149 utf_new_char ((char*) name),
2150 utf_new_char ((char*) sig)
2153 if (!f) *exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldError);
2159 jobject GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2162 return fieldID->value.a;
2166 jboolean GetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2169 return fieldID->value.i;
2173 jbyte GetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2176 return fieldID->value.i;
2180 jchar GetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2183 return fieldID->value.i;
2187 jshort GetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2190 return fieldID->value.i;
2194 jint GetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2197 return fieldID->value.i;
2201 jlong GetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2204 return fieldID->value.l;
2208 jfloat GetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2211 return fieldID->value.f;
2215 jdouble GetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2218 return fieldID->value.d;
2223 void SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
2226 fieldID->value.a = value;
2230 void SetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
2233 fieldID->value.i = value;
2237 void SetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
2240 fieldID->value.i = value;
2244 void SetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
2247 fieldID->value.i = value;
2251 void SetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
2254 fieldID->value.i = value;
2258 void SetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
2261 fieldID->value.i = value;
2265 void SetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
2268 fieldID->value.l = value;
2272 void SetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
2275 fieldID->value.f = value;
2279 void SetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
2282 fieldID->value.d = value;
2286 /***** create new java.lang.String object from an array of Unicode characters ****/
2288 jstring NewString (JNIEnv *env, const jchar *buf, jsize len)
2291 java_lang_String *s;
2294 s = (java_lang_String*) builtin_new (class_java_lang_String);
2295 a = builtin_newarray_char (len);
2297 /* javastring or characterarray could not be created */
2298 if ( (!a) || (!s) ) return NULL;
2301 for (i=0; i<len; i++) a->data[i] = buf[i];
2310 static char emptyString[]="";
2311 static jchar emptyStringJ[]={0,0};
2313 /******************* returns the length of a Java string ***************************/
2315 jsize GetStringLength (JNIEnv *env, jstring str)
2317 return ((java_lang_String*) str)->count;
2321 /******************** convertes javastring to u2-array ****************************/
2323 u2 *javastring_tou2 (jstring so)
2325 java_lang_String *s = (java_lang_String*) so;
2330 if (!s) return NULL;
2333 if (!a) return NULL;
2335 /* allocate memory */
2336 stringbuffer = MNEW( u2 , s->count + 1 );
2339 for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
2341 /* terminate string */
2342 stringbuffer[i] = '\0';
2344 return stringbuffer;
2347 /********* returns a pointer to an array of Unicode characters of the string *******/
2349 const jchar *GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy)
2351 jchar *jc=javastring_tou2(str);
2354 if (isCopy) *isCopy=JNI_TRUE;
2357 if (isCopy) *isCopy=JNI_TRUE;
2358 return emptyStringJ;
2361 /**************** native code no longer needs access to chars **********************/
2363 void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
2365 if (chars==emptyStringJ) return;
2366 MFREE(((jchar*) chars),jchar,((java_lang_String*) str)->count+1);
2369 /************ create new java.lang.String object from utf8-characterarray **********/
2371 jstring NewStringUTF (JNIEnv *env, const char *utf)
2373 /* log_text("NewStringUTF called");*/
2374 return (jstring) javastring_new(utf_new_char((char *) utf));
2377 /****************** returns the utf8 length in bytes of a string *******************/
2379 jsize GetStringUTFLength (JNIEnv *env, jstring string)
2381 java_lang_String *s = (java_lang_String*) string;
2383 return (jsize) u2_utflength(s->value->data, s->count);
2386 /************ converts a Javastring to an array of UTF-8 characters ****************/
2388 const char* GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
2391 if (verbose) log_text("GetStringUTFChars:");
2393 u=javastring_toutf((java_lang_String*) string,false);
2394 if (isCopy) *isCopy=JNI_FALSE;
2402 /***************** native code no longer needs access to utf ***********************/
2404 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
2406 /*we don't release utf chars right now, perhaps that should be done later. Since there is always one reference
2407 the garbage collector will never get them*/
2409 log_text("JNI-Call: ReleaseStringUTFChars");
2410 utf_display(utf_new_char(chars));
2414 /************************** array operations ***************************************/
2416 jsize GetArrayLength (JNIEnv *env, jarray array)
2421 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
2423 java_objectarray *j;
2425 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2428 j = builtin_anewarray (len, clazz);
2429 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2433 jobject GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
2437 if (index<array->header.size)
2438 j = array->data[index];
2440 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2445 void SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobject val)
2447 if (index>=array->header.size)
2448 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2451 /* check if the class of value is a subclass of the element class of the array */
2453 if (!builtin_canstore((java_objectarray*)array,(java_objectheader*)val))
2454 *exceptionptr = proto_java_lang_ArrayStoreException;
2456 array->data[index] = val;
2462 jbooleanArray NewBooleanArray (JNIEnv *env, jsize len)
2464 java_booleanarray *j;
2466 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2469 j = builtin_newarray_boolean(len);
2470 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2475 jbyteArray NewByteArray (JNIEnv *env, jsize len)
2479 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2482 j = builtin_newarray_byte(len);
2483 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2488 jcharArray NewCharArray (JNIEnv *env, jsize len)
2492 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2495 j = builtin_newarray_char(len);
2496 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2501 jshortArray NewShortArray (JNIEnv *env, jsize len)
2505 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2508 j = builtin_newarray_short(len);
2509 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2514 jintArray NewIntArray (JNIEnv *env, jsize len)
2518 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2521 j = builtin_newarray_int(len);
2522 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2527 jlongArray NewLongArray (JNIEnv *env, jsize len)
2531 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2534 j = builtin_newarray_long(len);
2535 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2540 jfloatArray NewFloatArray (JNIEnv *env, jsize len)
2544 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2547 j = builtin_newarray_float(len);
2548 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2553 jdoubleArray NewDoubleArray (JNIEnv *env, jsize len)
2555 java_doublearray *j;
2557 *exceptionptr=proto_java_lang_NegativeArraySizeException;
2560 j = builtin_newarray_double(len);
2561 if (!j) *exceptionptr = proto_java_lang_OutOfMemoryError;
2566 jboolean * GetBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *isCopy)
2568 if (isCopy) *isCopy = JNI_FALSE;
2573 jbyte * GetByteArrayElements (JNIEnv *env, jbyteArray array, jboolean *isCopy)
2575 if (isCopy) *isCopy = JNI_FALSE;
2580 jchar * GetCharArrayElements (JNIEnv *env, jcharArray array, jboolean *isCopy)
2582 if (isCopy) *isCopy = JNI_FALSE;
2587 jshort * GetShortArrayElements (JNIEnv *env, jshortArray array, jboolean *isCopy)
2589 if (isCopy) *isCopy = JNI_FALSE;
2594 jint * GetIntArrayElements (JNIEnv *env, jintArray array, jboolean *isCopy)
2596 if (isCopy) *isCopy = JNI_FALSE;
2601 jlong * GetLongArrayElements (JNIEnv *env, jlongArray array, jboolean *isCopy)
2603 if (isCopy) *isCopy = JNI_FALSE;
2608 jfloat * GetFloatArrayElements (JNIEnv *env, jfloatArray array, jboolean *isCopy)
2610 if (isCopy) *isCopy = JNI_FALSE;
2615 jdouble * GetDoubleArrayElements (JNIEnv *env, jdoubleArray array, jboolean *isCopy)
2617 if (isCopy) *isCopy = JNI_FALSE;
2623 void ReleaseBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode)
2629 void ReleaseByteArrayElements (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode)
2635 void ReleaseCharArrayElements (JNIEnv *env, jcharArray array, jchar *elems, jint mode)
2641 void ReleaseShortArrayElements (JNIEnv *env, jshortArray array, jshort *elems, jint mode)
2647 void ReleaseIntArrayElements (JNIEnv *env, jintArray array, jint *elems, jint mode)
2653 void ReleaseLongArrayElements (JNIEnv *env, jlongArray array, jlong *elems, jint mode)
2659 void ReleaseFloatArrayElements (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode)
2665 void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode)
2670 void GetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2672 if (start<0 || len<0 || start+len>array->header.size)
2673 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2675 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2679 void GetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2681 if (start<0 || len<0 || start+len>array->header.size)
2682 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2684 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2688 void GetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2690 if (start<0 || len<0 || start+len>array->header.size)
2691 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2693 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2697 void GetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2699 if (start<0 || len<0 || start+len>array->header.size)
2700 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2702 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2706 void GetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2708 if (start<0 || len<0 || start+len>array->header.size)
2709 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2711 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2715 void GetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2717 if (start<0 || len<0 || start+len>array->header.size)
2718 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2720 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2724 void GetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2726 if (start<0 || len<0 || start+len>array->header.size)
2727 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2729 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2733 void GetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2735 if (start<0 || len<0 || start+len>array->header.size)
2736 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2738 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2742 void SetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2744 if (start<0 || len<0 || start+len>array->header.size)
2745 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2747 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2751 void SetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2753 if (start<0 || len<0 || start+len>array->header.size)
2754 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2756 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2760 void SetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2762 if (start<0 || len<0 || start+len>array->header.size)
2763 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2765 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2770 void SetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2772 if (start<0 || len<0 || start+len>array->header.size)
2773 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2775 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2779 void SetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2781 if (start<0 || len<0 || start+len>array->header.size)
2782 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2784 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2788 void SetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2790 if (start<0 || len<0 || start+len>array->header.size)
2791 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2793 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2797 void SetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2799 if (start<0 || len<0 || start+len>array->header.size)
2800 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2802 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2806 void SetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2808 if (start<0 || len<0 || start+len>array->header.size)
2809 *exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2811 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2814 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
2816 log_text("JNI-Call: RegisterNatives");
2821 jint UnregisterNatives (JNIEnv* env, jclass clazz)
2823 log_text("JNI-Call: UnregisterNatives");
2827 /******************************* monitor operations ********************************/
2829 jint MonitorEnter (JNIEnv* env, jobject obj)
2831 builtin_monitorenter(obj);
2836 jint MonitorExit (JNIEnv* env, jobject obj)
2838 builtin_monitorexit(obj);
2843 /************************************* JavaVM interface ****************************/
2845 #error CPP mode not supported yet
2847 jint GetJavaVM (JNIEnv* env, JavaVM **vm)
2849 log_text("JNI-Call: GetJavaVM");
2853 #endif /*__cplusplus*/
2855 void GetStringRegion (JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
2857 log_text("JNI-Call: GetStringRegion");
2861 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
2863 log_text("JNI-Call: GetStringUTFRegion");
2867 /****************** obtain direct pointer to array elements ***********************/
2869 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
2871 java_objectheader *s = (java_objectheader*) array;
2872 arraydescriptor *desc = s->vftbl->arraydesc;
2874 if (!desc) return NULL;
2876 return ((u1*)s) + desc->dataoffset;
2880 void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jint mode)
2882 log_text("JNI-Call: ReleasePrimitiveArrayCritical");
2887 /********* returns a pointer to an array of Unicode characters of the string *******/
2889 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
2891 log_text("JNI-Call: GetStringCritical");
2893 return GetStringChars(env,string,isCopy);
2896 /**************** native code no longer needs access to chars **********************/
2898 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
2900 log_text("JNI-Call: ReleaseStringCritical");
2902 ReleaseStringChars(env,string,cstring);
2906 jweak NewWeakGlobalRef (JNIEnv* env, jobject obj)
2908 log_text("JNI-Call: NewWeakGlobalRef");
2914 void DeleteWeakGlobalRef (JNIEnv* env, jweak ref)
2916 log_text("JNI-Call: DeleteWeakGlobalRef");
2922 /******************************* check for pending exception ***********************/
2925 jboolean ExceptionCheck(JNIEnv* env)
2927 log_text("JNI-Call: ExceptionCheck");
2929 return *exceptionptr ? JNI_TRUE : JNI_FALSE;
2937 jint DestroyJavaVM(JavaVM *vm)
2939 log_text("DestroyJavaVM called");
2945 jint AttachCurrentThread(JavaVM *vm, void **par1, void *par2)
2947 log_text("AttachCurrentThread called");
2953 jint DetachCurrentThread(JavaVM *vm)
2955 log_text("DetachCurrentThread called");
2961 jint GetEnv(JavaVM *vm, void **environment, jint jniversion)
2963 *environment = &env;
2969 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
2971 log_text("AttachCurrentThreadAsDaemon called");
2977 /********************************* JNI invocation table ******************************/
2979 struct _JavaVM javaVMTable={
2984 &AttachCurrentThread,
2985 &DetachCurrentThread,
2987 &AttachCurrentThreadAsDaemon
2990 JavaVM javaVM = &javaVMTable;
2993 /********************************* JNI function table ******************************/
2995 struct JNI_Table envTable = {
3003 &FromReflectedMethod,
3004 &FromReflectedField,
3022 &EnsureLocalCapacity,
3034 &CallBooleanMethodV,
3035 &CallBooleanMethodA,
3060 &CallNonvirtualObjectMethod,
3061 &CallNonvirtualObjectMethodV,
3062 &CallNonvirtualObjectMethodA,
3063 &CallNonvirtualBooleanMethod,
3064 &CallNonvirtualBooleanMethodV,
3065 &CallNonvirtualBooleanMethodA,
3066 &CallNonvirtualByteMethod,
3067 &CallNonvirtualByteMethodV,
3068 &CallNonvirtualByteMethodA,
3069 &CallNonvirtualCharMethod,
3070 &CallNonvirtualCharMethodV,
3071 &CallNonvirtualCharMethodA,
3072 &CallNonvirtualShortMethod,
3073 &CallNonvirtualShortMethodV,
3074 &CallNonvirtualShortMethodA,
3075 &CallNonvirtualIntMethod,
3076 &CallNonvirtualIntMethodV,
3077 &CallNonvirtualIntMethodA,
3078 &CallNonvirtualLongMethod,
3079 &CallNonvirtualLongMethodV,
3080 &CallNonvirtualLongMethodA,
3081 &CallNonvirtualFloatMethod,
3082 &CallNonvirtualFloatMethodV,
3083 &CallNonvirtualFloatMethodA,
3084 &CallNonvirtualDoubleMethod,
3085 &CallNonvirtualDoubleMethodV,
3086 &CallNonvirtualDoubleMethodA,
3087 &CallNonvirtualVoidMethod,
3088 &CallNonvirtualVoidMethodV,
3089 &CallNonvirtualVoidMethodA,
3110 &CallStaticObjectMethod,
3111 &CallStaticObjectMethodV,
3112 &CallStaticObjectMethodA,
3113 &CallStaticBooleanMethod,
3114 &CallStaticBooleanMethodV,
3115 &CallStaticBooleanMethodA,
3116 &CallStaticByteMethod,
3117 &CallStaticByteMethodV,
3118 &CallStaticByteMethodA,
3119 &CallStaticCharMethod,
3120 &CallStaticCharMethodV,
3121 &CallStaticCharMethodA,
3122 &CallStaticShortMethod,
3123 &CallStaticShortMethodV,
3124 &CallStaticShortMethodA,
3125 &CallStaticIntMethod,
3126 &CallStaticIntMethodV,
3127 &CallStaticIntMethodA,
3128 &CallStaticLongMethod,
3129 &CallStaticLongMethodV,
3130 &CallStaticLongMethodA,
3131 &CallStaticFloatMethod,
3132 &CallStaticFloatMethodV,
3133 &CallStaticFloatMethodA,
3134 &CallStaticDoubleMethod,
3135 &CallStaticDoubleMethodV,
3136 &CallStaticDoubleMethodA,
3137 &CallStaticVoidMethod,
3138 &CallStaticVoidMethodV,
3139 &CallStaticVoidMethodA,
3141 &GetStaticObjectField,
3142 &GetStaticBooleanField,
3143 &GetStaticByteField,
3144 &GetStaticCharField,
3145 &GetStaticShortField,
3147 &GetStaticLongField,
3148 &GetStaticFloatField,
3149 &GetStaticDoubleField,
3150 &SetStaticObjectField,
3151 &SetStaticBooleanField,
3152 &SetStaticByteField,
3153 &SetStaticCharField,
3154 &SetStaticShortField,
3156 &SetStaticLongField,
3157 &SetStaticFloatField,
3158 &SetStaticDoubleField,
3162 &ReleaseStringChars,
3164 &GetStringUTFLength,
3166 &ReleaseStringUTFChars,
3169 &GetObjectArrayElement,
3170 &SetObjectArrayElement,
3179 &GetBooleanArrayElements,
3180 &GetByteArrayElements,
3181 &GetCharArrayElements,
3182 &GetShortArrayElements,
3183 &GetIntArrayElements,
3184 &GetLongArrayElements,
3185 &GetFloatArrayElements,
3186 &GetDoubleArrayElements,
3187 &ReleaseBooleanArrayElements,
3188 &ReleaseByteArrayElements,
3189 &ReleaseCharArrayElements,
3190 &ReleaseShortArrayElements,
3191 &ReleaseIntArrayElements,
3192 &ReleaseLongArrayElements,
3193 &ReleaseFloatArrayElements,
3194 &ReleaseDoubleArrayElements,
3195 &GetBooleanArrayRegion,
3196 &GetByteArrayRegion,
3197 &GetCharArrayRegion,
3198 &GetShortArrayRegion,
3200 &GetLongArrayRegion,
3201 &GetFloatArrayRegion,
3202 &GetDoubleArrayRegion,
3203 &SetBooleanArrayRegion,
3204 &SetByteArrayRegion,
3205 &SetCharArrayRegion,
3206 &SetShortArrayRegion,
3208 &SetLongArrayRegion,
3209 &SetFloatArrayRegion,
3210 &SetDoubleArrayRegion,
3217 &GetStringUTFRegion,
3218 &GetPrimitiveArrayCritical,
3219 &ReleasePrimitiveArrayCritical,
3221 &ReleaseStringCritical,
3223 &DeleteWeakGlobalRef,
3227 JNIEnv env = &envTable;
3230 jobject *jni_method_invokeNativeHelper(JNIEnv *env, struct methodinfo *methodID, jobject obj, java_objectarray *params)
3237 if (methodID == 0) {
3238 *exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
3241 argcount = get_parametercount(methodID);
3243 if (obj && (!builtin_instanceof((java_objectheader*)obj, methodID->class))) {
3244 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/IllegalArgumentException")),
3245 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
3252 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3253 log_text("Too many arguments. invokeNativeHelper does not support that");
3257 if ( ((!params) && (argcount!=0)) ||
3258 (params && (params->header.size!=argcount))
3260 *exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3265 if (!(methodID->flags & ACC_STATIC) && (!obj)) {
3266 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/NullPointerException")),
3267 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
3271 if ((methodID->flags & ACC_STATIC) && (obj)) obj = 0;
3273 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
3275 retT = fill_callblock_objA(obj, methodID->descriptor, blk, params);
3279 (void) asm_calljavafunction2(methodID,
3281 (argcount + 1) * sizeof(jni_callblock),
3283 retVal = NULL; /*native_new_and_init(loader_load(utf_new_char("java/lang/Void")));*/
3288 intVal = (s4) asm_calljavafunction2(methodID,
3290 (argcount + 1) * sizeof(jni_callblock),
3292 retVal = builtin_new(loader_load_sysclass(NULL,
3293 utf_new_char("java/lang/Integer")));
3296 class_resolvemethod(retVal->vftbl->class,
3297 utf_new_char("<init>"),
3298 utf_new_char("(I)V")),
3305 intVal = (s4) asm_calljavafunction2(methodID,
3307 (argcount + 1) * sizeof(jni_callblock),
3309 retVal = builtin_new(loader_load_sysclass(NULL,
3310 utf_new_char("java/lang/Byte")));
3313 class_resolvemethod(retVal->vftbl->class,
3314 utf_new_char("<init>"),
3315 utf_new_char("(B)V")),
3322 intVal = (s4) asm_calljavafunction2(methodID,
3324 (argcount + 1) * sizeof(jni_callblock),
3326 retVal = builtin_new(loader_load_sysclass(NULL,
3327 utf_new_char("java/lang/Character")));
3330 class_resolvemethod(retVal->vftbl->class,
3331 utf_new_char("<init>"),
3332 utf_new_char("(C)V")),
3339 intVal = (s4) asm_calljavafunction2(methodID,
3341 (argcount + 1) * sizeof(jni_callblock),
3343 retVal = builtin_new(loader_load_sysclass(NULL,
3344 utf_new_char("java/lang/Short")));
3347 class_resolvemethod(retVal->vftbl->class,
3348 utf_new_char("<init>"),
3349 utf_new_char("(S)V")),
3356 intVal = (s4) asm_calljavafunction2(methodID,
3358 (argcount + 1) * sizeof(jni_callblock),
3360 retVal = builtin_new(loader_load_sysclass(NULL,
3361 utf_new_char("java/lang/Boolean")));
3364 class_resolvemethod(retVal->vftbl->class,
3365 utf_new_char("<init>"),
3366 utf_new_char("(Z)V")),
3373 intVal = asm_calljavafunction2long(methodID,
3375 (argcount + 1) * sizeof(jni_callblock),
3377 retVal = builtin_new(loader_load_sysclass(NULL,
3378 utf_new_char("java/lang/Long")));
3381 class_resolvemethod(retVal->vftbl->class,
3382 utf_new_char("<init>"),
3383 utf_new_char("(J)V")),
3390 floatVal = asm_calljavafunction2double(methodID,
3392 (argcount + 1) * sizeof(jni_callblock),
3394 retVal = builtin_new(loader_load_sysclass(NULL,
3395 utf_new_char("java/lang/Float")));
3398 class_resolvemethod(retVal->vftbl->class,
3399 utf_new_char("<init>"),
3400 utf_new_char("(F)V")),
3407 floatVal = asm_calljavafunction2double(methodID,
3409 (argcount + 1) * sizeof(jni_callblock),
3411 retVal = builtin_new(loader_load_sysclass(NULL,
3412 utf_new_char("java/lang/Double")));
3415 class_resolvemethod(retVal->vftbl->class,
3416 utf_new_char("<init>"),
3417 utf_new_char("(D)V")),
3422 case 'L': /* fall through */
3424 retVal = asm_calljavafunction2(methodID,
3426 (argcount + 1) * sizeof(jni_callblock),
3431 /* if this happens the acception has already been set by fill_callblock_objA*/
3432 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3433 return (jobject *) 0;
3436 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3438 if (*exceptionptr) {
3439 java_objectheader *exceptionToWrap=*exceptionptr;
3441 java_objectheader *ivte;
3444 ivtec = loader_load_sysclass(NULL,
3445 utf_new_char("java/lang/reflect/InvocationTargetException"));
3446 ivte = builtin_new(ivtec);
3447 asm_calljavafunction(class_resolvemethod(ivtec,
3448 utf_new_char("<init>"),
3449 utf_new_char("(Ljava/lang/Throwable;)V")),
3455 if (*exceptionptr != NULL)
3456 panic("jni.c: error while creating InvocationTargetException wrapper");
3458 *exceptionptr = ivte;
3461 return (jobject *) retVal;
3466 * These are local overrides for various environment variables in Emacs.
3467 * Please do not remove this and leave it at the end of the file, where
3468 * Emacs will automagically detect them.
3469 * ---------------------------------------------------------------------
3472 * indent-tabs-mode: t