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 808 2003-12-30 12:45:28Z 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 */
217 utf_char=utf_new_char("java/lang/Character");
218 utf_bool=utf_new_char("java/lang/Boolean");
219 utf_byte=utf_new_char("java/lang/Byte");
220 utf_short=utf_new_char("java/lang/Short");
221 utf_int=utf_new_char("java/lang/Integer");
222 utf_long=utf_new_char("java/lang/Long");
223 utf_float=utf_new_char("java/lang/Float");
224 utf_double=utf_new_char("java/lang/Double");
229 log_text("fill_callblock");
236 /* determine number of parameters */
238 blk[0].itemtype = TYPE_ADR;
239 blk[0].item = PTR_TO_ITEM(obj);
247 while (**utf_ptr != ')') {
248 if (*utf_ptr >= desc_end)
249 panic("illegal method descriptor");
251 /* primitive types */
252 switch (utf_nextu2(utf_ptr)) {
254 param=params->data[cnts];
256 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
259 if (param->vftbl->class->name==utf_byte) {
260 blk[cnt].itemtype=TYPE_INT;
261 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
263 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
268 param=params->data[cnts];
270 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
273 if (param->vftbl->class->name==utf_char) {
274 blk[cnt].itemtype=TYPE_INT;
275 blk[cnt].item = (u8) ((struct java_lang_Character * )param)->value;
277 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
283 param=params->data[cnts];
285 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
288 if (param->vftbl->class->name==utf_short) {
289 blk[cnt].itemtype=TYPE_INT;
290 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
292 if (param->vftbl->class->name==utf_byte) {
293 blk[cnt].itemtype=TYPE_INT;
294 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
296 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
303 param=params->data[cnts];
305 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
308 if (param->vftbl->class->name==utf_bool) {
309 blk[cnt].itemtype=TYPE_INT;
310 blk[cnt].item = (u8) ((struct java_lang_Boolean * )param)->value;
312 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
318 /*log_text("fill_callblock_objA: param 'I'");*/
319 param=params->data[cnts];
321 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
324 if (param->vftbl->class->name==utf_int) {
325 blk[cnt].itemtype=TYPE_INT;
326 blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
327 /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
329 if (param->vftbl->class->name==utf_short) {
330 blk[cnt].itemtype=TYPE_INT;
331 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
333 if (param->vftbl->class->name==utf_byte) {
334 blk[cnt].itemtype=TYPE_INT;
335 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
338 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
345 param=params->data[cnts];
347 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
350 if (param->vftbl->class->name==utf_long) {
351 blk[cnt].itemtype=TYPE_LNG;
352 blk[cnt].item = (u8) ((struct java_lang_Long * )param)->value;
354 if (param->vftbl->class->name==utf_int) {
355 blk[cnt].itemtype=TYPE_LNG;
356 blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
358 if (param->vftbl->class->name==utf_short) {
359 blk[cnt].itemtype=TYPE_LNG;
360 blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
362 if (param->vftbl->class->name==utf_byte) {
363 blk[cnt].itemtype=TYPE_LNG;
364 blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
366 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
376 param=params->data[cnts];
378 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
382 if (param->vftbl->class->name==utf_float) {
383 blk[cnt].itemtype=TYPE_FLT;
384 *((jfloat*)(&blk[cnt].item))=(jfloat) ((struct java_lang_Float*)param)->value;
386 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
391 param=params->data[cnts];
393 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
397 if (param->vftbl->class->name==utf_double) {
398 blk[cnt].itemtype=TYPE_DBL;
399 *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
401 if (param->vftbl->class->name==utf_float) {
402 blk[cnt].itemtype=TYPE_DBL;
403 *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
405 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
411 panic("V not allowed as function parameter");
415 char *start=(*utf_ptr)-1;
418 while (utf_nextu2(utf_ptr) != ';')
420 if (!builtin_instanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD))) {
421 if (params->data[cnts]!=0) {
422 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
426 blk[cnt].itemtype = TYPE_ADR;
427 blk[cnt].item= PTR_TO_ITEM(params->data[cnts]);
433 char *start=(*utf_ptr)-1;
437 while ((ch = utf_nextu2(utf_ptr)) == '[')
439 while (utf_nextu2(utf_ptr) != ';') {}
442 ch = utf_nextu2(utf_ptr);
443 if (!builtin_arrayinstanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD)->vftbl)) {
444 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
449 blk[cnt].itemtype = TYPE_ADR;
450 blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
458 c = utf_nextu2(utf_ptr);
459 c = utf_nextu2(utf_ptr);
460 return c; /*return type needed usage of the right lowlevel methods*/
477 jmethodID get_virtual(jobject obj,jmethodID methodID) {
478 if (obj->vftbl->class==methodID->class) return methodID;
479 return class_resolvemethod (obj->vftbl->class, methodID->name, methodID->descriptor);
482 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
483 if (clazz==methodID->class) return methodID;
484 return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
489 jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
496 log_text("JNI-Call: CallObjectMethodV");
497 utf_display(methodID->name);
498 utf_display(methodID->descriptor);
499 printf("\nParmaeter count: %d\n",argcount);
500 utf_display(obj->vftbl->class->name);
505 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
509 argcount = get_parametercount(methodID);
511 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
512 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
513 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
517 if (obj && !builtin_instanceof(obj, methodID->class)) {
518 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
523 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
524 log_text("Too many arguments. CallObjectMethod does not support that");
528 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
530 fill_callblock(obj, methodID->descriptor, blk, args, 'O');
532 /* printf("parameter: obj: %p",blk[0].item); */
533 ret = asm_calljavafunction2(methodID,
535 (argcount + 1) * sizeof(jni_callblock),
538 MFREE(blk, jni_callblock, argcount + 1);
539 /* printf("(CallObjectMethodV)-->%p\n",ret); */
545 core function for integer class methods (bool, byte, short, integer)
546 This is basically needed for i386
548 jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list args)
554 /* printf("%p, %c\n",retType,methodID,retType);*/
557 log_text("JNI-Call: CallObjectMethodV");
558 utf_display(methodID->name);
559 utf_display(methodID->descriptor);
560 printf("\nParmaeter count: %d\n",argcount);
561 utf_display(obj->vftbl->class->name);
565 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
569 argcount = get_parametercount(methodID);
571 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
572 ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
573 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
577 if (obj && !builtin_instanceof(obj, methodID->class)) {
578 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
584 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
585 log_text("Too many arguments. CallObjectMethod does not support that");
589 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
591 fill_callblock(obj, methodID->descriptor, blk, args, retType);
593 /* printf("parameter: obj: %p",blk[0].item); */
594 ret = (jint) asm_calljavafunction2(methodID,
596 (argcount + 1) * sizeof(jni_callblock),
599 MFREE(blk, jni_callblock, argcount + 1);
600 /* printf("(CallObjectMethodV)-->%p\n",ret); */
606 /*core function for long class functions*/
607 jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
614 log_text("JNI-Call: CallObjectMethodV");
615 utf_display(methodID->name);
616 utf_display(methodID->descriptor);
617 printf("\nParmaeter count: %d\n",argcount);
618 utf_display(obj->vftbl->class->name);
622 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
626 argcount = get_parametercount(methodID);
628 if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
629 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
630 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
634 if (obj && !builtin_instanceof(obj,methodID->class)) {
635 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
641 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
642 log_text("Too many arguments. CallObjectMethod does not support that");
646 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
648 fill_callblock(obj, methodID->descriptor, blk, args, 'L');
650 /* printf("parameter: obj: %p",blk[0].item); */
651 ret = asm_calljavafunction2long(methodID,
653 (argcount + 1) * sizeof(jni_callblock),
656 MFREE(blk, jni_callblock, argcount + 1);
657 /* printf("(CallObjectMethodV)-->%p\n",ret); */
663 /*core function for float class methods (float,double)*/
664 jdouble callFloatMethod(jobject obj, jmethodID methodID, va_list args,char retType)
666 int argcount = get_parametercount(methodID);
671 log_text("JNI-Call: CallObjectMethodV");
672 utf_display(methodID->name);
673 utf_display(methodID->descriptor);
674 printf("\nParmaeter count: %d\n",argcount);
675 utf_display(obj->vftbl->class->name);
680 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
681 log_text("Too many arguments. CallObjectMethod does not support that");
685 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
687 fill_callblock(obj, methodID->descriptor, blk, args, retType);
689 /* printf("parameter: obj: %p",blk[0].item); */
690 ret = asm_calljavafunction2double(methodID,
692 (argcount + 1) * sizeof(jni_callblock),
695 MFREE(blk, jni_callblock, argcount + 1);
696 /* printf("(CallObjectMethodV)-->%p\n",ret); */
702 /*************************** function: jclass_findfield ****************************
704 searches for field with specified name and type in a 'classinfo'-structur
705 if no such field is found NULL is returned
707 ************************************************************************************/
709 fieldinfo *jclass_findfield (classinfo *c, utf *name, utf *desc)
712 /* printf(" FieldCount: %d\n",c->fieldscount);
713 utf_display(c->name); */
714 for (i = 0; i < c->fieldscount; i++) {
715 /* utf_display(c->fields[i].name);
717 utf_display(c->fields[i].descriptor);
719 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
720 return &(c->fields[i]);
723 if (c->super) return jclass_findfield(c->super,name,desc);
728 /********************* returns version of native method interface *****************/
730 jint GetVersion (JNIEnv* env)
735 /****************** loads a class from a buffer of raw class data *****************/
737 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len)
741 /* change suck-mode, so subsequent class_load will read from memory-buffer */
742 classload_buffer( (u1*) buf,len);
744 clazz = loader_load(utf_new_char ((char *) name));
746 /* restore old suck-mode */
747 classload_buffer(NULL,0);
753 /*************** loads locally defined class with the specified name **************/
755 jclass FindClass (JNIEnv* env, const char *name)
759 /* if (strcmp(name,"[B")==0) {
760 c = loader_load(utf_new_char("The_Array_Class"));
763 c = loader_load(utf_new_char_classname ((char *) name));
765 if (!c) exceptionptr = native_new_and_init(class_java_lang_ClassFormatError);
771 /***********************************************************************************
773 converts java.lang.reflect.Method or
774 java.lang.reflect.Constructor object to a method ID
776 **********************************************************************************/
778 jmethodID FromReflectedMethod(JNIEnv* env, jobject method)
780 /* log_text("JNI-Call: FromReflectedMethod"); */
786 /*************** return superclass of the class represented by sub ****************/
788 jclass GetSuperclass(JNIEnv* env, jclass sub)
792 c = ((classinfo*) sub)->super;
796 use_class_as_object(c);
802 /*********************** check whether sub can be cast to sup ********************/
804 jboolean IsAssignableForm(JNIEnv* env, jclass sub, jclass sup)
806 return builtin_isanysubclass(sub, sup);
810 /***** converts a field ID derived from cls to a java.lang.reflect.Field object ***/
812 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isStatic)
814 /* log_text("JNI-Call: ToReflectedField"); */
820 /***************** throw java.lang.Throwable object ******************************/
822 jint Throw(JNIEnv* env, jthrowable obj)
824 exceptionptr = (java_objectheader*) obj;
830 /***********************************************************************************
832 create exception object from the class clazz with the
833 specified message and cause it to be thrown
835 **********************************************************************************/
837 jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg)
839 java_lang_Throwable *o;
841 /* instantiate exception object */
842 o = (java_lang_Throwable *) native_new_and_init ((classinfo*) clazz);
846 o->detailMessage = (java_lang_String*) javastring_new_char((char *) msg);
848 exceptionptr = (java_objectheader*) o;
854 /************************* check if exception occured *****************************/
856 jthrowable ExceptionOccurred (JNIEnv* env)
858 return (jthrowable) exceptionptr;
861 /********** print exception and a backtrace of the stack (for debugging) **********/
863 void ExceptionDescribe (JNIEnv* env)
865 utf_display(exceptionptr->vftbl->class->name);
871 /******************* clear any exception currently being thrown *******************/
873 void ExceptionClear (JNIEnv* env)
879 /********** raises a fatal error and does not expect the VM to recover ************/
881 void FatalError (JNIEnv* env, const char *msg)
886 /******************* creates a new local reference frame **************************/
888 jint PushLocalFrame(JNIEnv* env, jint capacity)
895 /**************** Pops off the current local reference frame **********************/
897 jobject PopLocalFrame(JNIEnv* env, jobject result)
905 /** Creates a new global reference to the object referred to by the obj argument **/
907 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
912 /************* Deletes the global reference pointed to by globalRef **************/
914 void DeleteGlobalRef (JNIEnv* env, jobject gref)
920 /*************** Deletes the local reference pointed to by localRef ***************/
922 void DeleteLocalRef (JNIEnv* env, jobject localRef)
927 /********** Tests whether two references refer to the same Java object ************/
929 jboolean IsSameObject (JNIEnv* env, jobject obj1, jobject obj2)
934 /***** Creates a new local reference that refers to the same object as ref *******/
936 jobject NewLocalRef (JNIEnv* env, jobject ref)
941 /***********************************************************************************
943 Ensures that at least a given number of local references can
944 be created in the current thread
946 **********************************************************************************/
948 jint EnsureLocalCapacity (JNIEnv* env, jint capacity)
950 return 0; /* return 0 on success */
954 /********* Allocates a new Java object without invoking a constructor *************/
956 jobject AllocObject (JNIEnv* env, jclass clazz)
958 java_objectheader *o = builtin_new(clazz);
963 /***********************************************************************************
965 Constructs a new Java object
966 arguments that are to be passed to the constructor are placed after methodID
968 ***********************************************************************************/
970 jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
972 java_objectheader *o;
974 int argcount=get_parametercount(methodID);
978 /* log_text("JNI-Call: NewObject"); */
981 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
982 log_text("Too many arguments. NewObject does not support that");
987 o = builtin_new (clazz); /* create object */
991 va_start(vaargs,methodID);
992 for (i=0;i<argcount;i++) {
993 args[i]=va_arg(vaargs,void*);
996 asm_calljavafunction(methodID,o,args[0],args[1],args[2]);
1002 /***********************************************************************************
1004 Constructs a new Java object
1005 arguments that are to be passed to the constructor are placed in va_list args
1007 ***********************************************************************************/
1009 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
1011 /* log_text("JNI-Call: NewObjectV"); */
1017 /***********************************************************************************
1019 Constructs a new Java object
1020 arguments that are to be passed to the constructor are placed in
1021 args array of jvalues
1023 ***********************************************************************************/
1025 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
1027 /* log_text("JNI-Call: NewObjectA"); */
1033 /************************ returns the class of an object **************************/
1035 jclass GetObjectClass(JNIEnv* env, jobject obj)
1037 classinfo *c = obj->vftbl->class;
1038 /* log_text("GetObjectClass");
1039 utf_display(obj->vftbl->class->name);*/
1040 use_class_as_object(c);
1042 /*printf("\nPointer: %p\n",c);*/
1047 /************* tests whether an object is an instance of a class ******************/
1049 jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz)
1051 return builtin_instanceof(obj,clazz);
1055 /***************** converts a java.lang.reflect.Field to a field ID ***************/
1057 jfieldID FromReflectedField(JNIEnv* env, jobject field)
1059 log_text("JNI-Call: FromReflectedField");
1065 /**********************************************************************************
1067 converts a method ID to a java.lang.reflect.Method or
1068 java.lang.reflect.Constructor object
1070 **********************************************************************************/
1072 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
1074 log_text("JNI-Call: ToReflectedMethod");
1080 /**************** returns the method ID for an instance method ********************/
1082 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *sig)
1086 m = class_resolvemethod (
1088 utf_new_char ((char*) name),
1089 utf_new_char ((char*) sig)
1092 if (!m) exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
1098 /******************** JNI-functions for calling instance methods ******************/
1100 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1105 /* log_text("JNI-Call: CallObjectMethod");*/
1107 va_start(vaargs, methodID);
1108 ret = callObjectMethod(obj, methodID, vaargs);
1115 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1117 return callObjectMethod(obj,methodID,args);
1121 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1123 log_text("JNI-Call: CallObjectMethodA");
1131 jboolean CallBooleanMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1136 /* log_text("JNI-Call: CallBooleanMethod");*/
1138 va_start(vaargs,methodID);
1139 ret = (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',vaargs);
1145 jboolean CallBooleanMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1147 return (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',args);
1151 jboolean CallBooleanMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1153 log_text("JNI-Call: CallBooleanMethodA");
1158 jbyte CallByteMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
1163 /* log_text("JNI-Call: CallVyteMethod");*/
1165 va_start(vaargs,methodID);
1166 ret = callIntegerMethod(obj,get_virtual(obj,methodID),'B',vaargs);
1172 jbyte CallByteMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1174 /* log_text("JNI-Call: CallByteMethodV");*/
1175 return callIntegerMethod(obj,methodID,'B',args);
1179 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1181 log_text("JNI-Call: CallByteMethodA");
1187 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1192 /* log_text("JNI-Call: CallCharMethod");*/
1194 va_start(vaargs,methodID);
1195 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'C', vaargs);
1202 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1204 /* log_text("JNI-Call: CallCharMethodV");*/
1205 return callIntegerMethod(obj,get_virtual(obj,methodID),'C',args);
1209 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1211 log_text("JNI-Call: CallCharMethodA");
1217 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1222 /* log_text("JNI-Call: CallShortMethod");*/
1224 va_start(vaargs, methodID);
1225 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'S', vaargs);
1232 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1234 return callIntegerMethod(obj, get_virtual(obj, methodID), 'S', args);
1238 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1240 log_text("JNI-Call: CallShortMethodA");
1247 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1252 va_start(vaargs,methodID);
1253 ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'I', vaargs);
1260 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1262 return callIntegerMethod(obj, get_virtual(obj, methodID), 'I', args);
1266 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1268 log_text("JNI-Call: CallIntMethodA");
1275 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1277 log_text("JNI-Call: CallLongMethod");
1283 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1285 log_text("JNI-Call: CallLongMethodV");
1291 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1293 log_text("JNI-Call: CallLongMethodA");
1300 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1305 /* log_text("JNI-Call: CallFloatMethod");*/
1307 va_start(vaargs,methodID);
1308 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'F');
1315 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1317 log_text("JNI-Call: CallFloatMethodV");
1318 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'F');
1322 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1324 log_text("JNI-Call: CallFloatMethodA");
1331 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1336 /* log_text("JNI-Call: CallDoubleMethod");*/
1338 va_start(vaargs,methodID);
1339 ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'D');
1346 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1348 log_text("JNI-Call: CallDoubleMethodV");
1349 return callFloatMethod(obj, get_virtual(obj, methodID), args, 'D');
1353 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1355 log_text("JNI-Call: CallDoubleMethodA");
1361 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1365 /* log_text("JNI-Call: CallVoidMethod");*/
1367 va_start(vaargs,methodID);
1368 (void) callIntegerMethod(obj, get_virtual(obj, methodID), 'V', vaargs);
1373 void CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1375 log_text("JNI-Call: CallVoidMethodV");
1376 (void)callIntegerMethod(obj,get_virtual(obj,methodID),'V',args);
1380 void CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1382 log_text("JNI-Call: CallVoidMethodA");
1387 jobject CallNonvirtualObjectMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1389 log_text("JNI-Call: CallNonvirtualObjectMethod");
1395 jobject CallNonvirtualObjectMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1397 log_text("JNI-Call: CallNonvirtualObjectMethodV");
1403 jobject CallNonvirtualObjectMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1405 log_text("JNI-Call: CallNonvirtualObjectMethodA");
1412 jboolean CallNonvirtualBooleanMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1417 /* log_text("JNI-Call: CallNonvirtualBooleanMethod");*/
1419 va_start(vaargs,methodID);
1420 ret = (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',vaargs);
1427 jboolean CallNonvirtualBooleanMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1429 /* log_text("JNI-Call: CallNonvirtualBooleanMethodV");*/
1430 return (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',args);
1434 jboolean CallNonvirtualBooleanMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1436 log_text("JNI-Call: CallNonvirtualBooleanMethodA");
1443 jbyte CallNonvirtualByteMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1448 /* log_text("JNI-Call: CallNonvirutalByteMethod");*/
1450 va_start(vaargs,methodID);
1451 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',vaargs);
1457 jbyte CallNonvirtualByteMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1459 /*log_text("JNI-Call: CallNonvirtualByteMethodV"); */
1460 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',args);
1465 jbyte CallNonvirtualByteMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1467 log_text("JNI-Call: CallNonvirtualByteMethodA");
1474 jchar CallNonvirtualCharMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1479 /* log_text("JNI-Call: CallNonVirtualCharMethod");*/
1481 va_start(vaargs,methodID);
1482 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',vaargs);
1488 jchar CallNonvirtualCharMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1490 /*log_text("JNI-Call: CallNonvirtualCharMethodV");*/
1491 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',args);
1495 jchar CallNonvirtualCharMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1497 log_text("JNI-Call: CallNonvirtualCharMethodA");
1504 jshort CallNonvirtualShortMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1509 /*log_text("JNI-Call: CallNonvirtualShortMethod");*/
1511 va_start(vaargs,methodID);
1512 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',vaargs);
1518 jshort CallNonvirtualShortMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1520 /*log_text("JNI-Call: CallNonvirtualShortMethodV");*/
1521 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',args);
1525 jshort CallNonvirtualShortMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1527 log_text("JNI-Call: CallNonvirtualShortMethodA");
1534 jint CallNonvirtualIntMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1540 /*log_text("JNI-Call: CallNonvirtualIntMethod");*/
1542 va_start(vaargs,methodID);
1543 ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',vaargs);
1549 jint CallNonvirtualIntMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1551 /*log_text("JNI-Call: CallNonvirtualIntMethodV");*/
1552 return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',args);
1556 jint CallNonvirtualIntMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1558 log_text("JNI-Call: CallNonvirtualIntMethodA");
1565 jlong CallNonvirtualLongMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1567 log_text("JNI-Call: CallNonvirtualLongMethod");
1573 jlong CallNonvirtualLongMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1575 log_text("JNI-Call: CallNonvirtualLongMethodV");
1581 jlong CallNonvirtualLongMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1583 log_text("JNI-Call: CallNonvirtualLongMethodA");
1590 jfloat CallNonvirtualFloatMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1595 /*log_text("JNI-Call: CallNonvirtualFloatMethod");*/
1598 va_start(vaargs,methodID);
1599 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'F');
1606 jfloat CallNonvirtualFloatMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1608 log_text("JNI-Call: CallNonvirtualFloatMethodV");
1609 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'F');
1613 jfloat CallNonvirtualFloatMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1615 log_text("JNI-Call: CallNonvirtualFloatMethodA");
1622 jdouble CallNonvirtualDoubleMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1626 log_text("JNI-Call: CallNonvirtualDoubleMethod");
1628 va_start(vaargs,methodID);
1629 ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'D');
1636 jdouble CallNonvirtualDoubleMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1638 /* log_text("JNI-Call: CallNonvirtualDoubleMethodV");*/
1639 return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'D');
1643 jdouble CallNonvirtualDoubleMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1645 log_text("JNI-Call: CallNonvirtualDoubleMethodA");
1652 void CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1656 /* log_text("JNI-Call: CallNonvirtualVoidMethod");*/
1658 va_start(vaargs,methodID);
1659 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',vaargs);
1665 void CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1667 /* log_text("JNI-Call: CallNonvirtualVoidMethodV");*/
1669 (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',args);
1674 void CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1676 log_text("JNI-Call: CallNonvirtualVoidMethodA");
1679 /************************* JNI-functions for accessing fields ************************/
1681 jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
1685 /* log_text("========================= searching for:");
1688 f = jclass_findfield(clazz,
1689 utf_new_char ((char*) name),
1690 utf_new_char ((char*) sig)
1694 /* utf_display(clazz->name);
1697 exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldError);
1702 /*************************** retrieve fieldid, abort on error ************************/
1704 jfieldID getFieldID_critical(JNIEnv *env, jclass clazz, char *name, char *sig)
1706 jfieldID id = GetFieldID(env, clazz, name, sig);
1710 utf_display(clazz->name);
1711 log_text("\nfield:");
1716 panic("setfield_critical failed");
1721 jobject GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
1723 return getField(obj,jobject,fieldID);
1726 jboolean GetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID)
1728 return getField(obj,jboolean,fieldID);
1732 jbyte GetByteField (JNIEnv *env, jobject obj, jfieldID fieldID)
1734 return getField(obj,jbyte,fieldID);
1738 jchar GetCharField (JNIEnv *env, jobject obj, jfieldID fieldID)
1740 return getField(obj,jchar,fieldID);
1744 jshort GetShortField (JNIEnv *env, jobject obj, jfieldID fieldID)
1746 return getField(obj,jshort,fieldID);
1750 jint GetIntField (JNIEnv *env, jobject obj, jfieldID fieldID)
1752 return getField(obj,jint,fieldID);
1756 jlong GetLongField (JNIEnv *env, jobject obj, jfieldID fieldID)
1758 return getField(obj,jlong,fieldID);
1762 jfloat GetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID)
1764 return getField(obj,jfloat,fieldID);
1768 jdouble GetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID)
1770 return getField(obj,jdouble,fieldID);
1773 void SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
1775 setField(obj,jobject,fieldID,val);
1779 void SetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val)
1781 setField(obj,jboolean,fieldID,val);
1785 void SetByteField (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val)
1787 setField(obj,jbyte,fieldID,val);
1791 void SetCharField (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val)
1793 setField(obj,jchar,fieldID,val);
1797 void SetShortField (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val)
1799 setField(obj,jshort,fieldID,val);
1803 void SetIntField (JNIEnv *env, jobject obj, jfieldID fieldID, jint val)
1805 setField(obj,jint,fieldID,val);
1809 void SetLongField (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val)
1811 setField(obj,jlong,fieldID,val);
1815 void SetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val)
1817 setField(obj,jfloat,fieldID,val);
1821 void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
1823 setField(obj,jdouble,fieldID,val);
1827 /**************** JNI-functions for calling static methods **********************/
1829 jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
1833 m = class_resolvemethod(
1835 utf_new_char((char*) name),
1836 utf_new_char((char*) sig));
1838 if (!m) exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
1844 jobject CallStaticObjectMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1846 log_text("JNI-Call: CallStaticObjectMethod");
1852 jobject CallStaticObjectMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1854 log_text("JNI-Call: CallStaticObjectMethodV");
1860 jobject CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1862 log_text("JNI-Call: CallStaticObjectMethodA");
1868 jboolean CallStaticBooleanMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1873 /* log_text("JNI-Call: CallStaticBooleanMethod");*/
1875 va_start(vaargs,methodID);
1876 ret = (jboolean)callIntegerMethod(0,methodID,'Z',vaargs);
1883 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1885 return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
1888 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1890 log_text("JNI-Call: CallStaticBooleanMethodA");
1896 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1901 /* log_text("JNI-Call: CallStaticByteMethod");*/
1903 va_start(vaargs, methodID);
1904 ret = (jbyte) callIntegerMethod(0, methodID, 'B', vaargs);
1911 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1913 return (jbyte) callIntegerMethod(0, methodID, 'B', args);
1917 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1919 log_text("JNI-Call: CallStaticByteMethodA");
1925 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1930 /* log_text("JNI-Call: CallStaticByteMethod");*/
1932 va_start(vaargs, methodID);
1933 ret = (jchar) callIntegerMethod(0, methodID, 'C', vaargs);
1940 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1942 return (jchar) callIntegerMethod(0, methodID, 'C', args);
1946 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1948 log_text("JNI-Call: CallStaticCharMethodA");
1955 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1960 /* log_text("JNI-Call: CallStaticByteMethod");*/
1962 va_start(vaargs,methodID);
1963 ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
1970 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1972 /*log_text("JNI-Call: CallStaticShortMethodV");*/
1973 return (jshort) callIntegerMethod(0, methodID, 'S', args);
1977 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1979 log_text("JNI-Call: CallStaticShortMethodA");
1986 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1991 /* log_text("JNI-Call: CallStaticIntMethod");*/
1993 va_start(vaargs, methodID);
1994 ret = callIntegerMethod(0, methodID, 'I', vaargs);
2001 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2003 log_text("JNI-Call: CallStaticIntMethodV");
2005 return callIntegerMethod(0, methodID, 'I', args);
2009 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2011 log_text("JNI-Call: CallStaticIntMethodA");
2018 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2023 /* log_text("JNI-Call: CallStaticLongMethod");*/
2025 va_start(vaargs, methodID);
2026 ret = callLongMethod(0, methodID, vaargs);
2033 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2035 log_text("JNI-Call: CallStaticLongMethodV");
2037 return callLongMethod(0,methodID,args);
2041 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2043 log_text("JNI-Call: CallStaticLongMethodA");
2050 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2055 /* log_text("JNI-Call: CallStaticLongMethod");*/
2057 va_start(vaargs, methodID);
2058 ret = callFloatMethod(0, methodID, vaargs, 'F');
2065 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2068 return callFloatMethod(0, methodID, args, 'F');
2073 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2075 log_text("JNI-Call: CallStaticFloatMethodA");
2082 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
2087 /* log_text("JNI-Call: CallStaticDoubleMethod");*/
2089 va_start(vaargs,methodID);
2090 ret = callFloatMethod(0, methodID, vaargs, 'D');
2097 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
2099 log_text("JNI-Call: CallStaticDoubleMethodV");
2101 return callFloatMethod(0, methodID, args, 'D');
2105 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
2107 log_text("JNI-Call: CallStaticDoubleMethodA");
2113 void CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)
2117 /* log_text("JNI-Call: CallStaticVoidMethod");*/
2119 va_start(vaargs, methodID);
2120 (void) callIntegerMethod(0, methodID, 'V', vaargs);
2125 void CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)
2127 log_text("JNI-Call: CallStaticVoidMethodV");
2128 (void)callIntegerMethod(0, methodID, 'V', args);
2132 void CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args)
2134 log_text("JNI-Call: CallStaticVoidMethodA");
2138 /****************** JNI-functions for accessing static fields ********************/
2140 jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
2144 f = jclass_findfield(clazz,
2145 utf_new_char ((char*) name),
2146 utf_new_char ((char*) sig)
2149 if (!f) exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldError);
2155 jobject GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2158 return fieldID->value.a;
2162 jboolean GetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2165 return fieldID->value.i;
2169 jbyte GetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2172 return fieldID->value.i;
2176 jchar GetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2179 return fieldID->value.i;
2183 jshort GetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2186 return fieldID->value.i;
2190 jint GetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2193 return fieldID->value.i;
2197 jlong GetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2200 return fieldID->value.l;
2204 jfloat GetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2207 return fieldID->value.f;
2211 jdouble GetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID)
2214 return fieldID->value.d;
2219 void SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
2222 fieldID->value.a = value;
2226 void SetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
2229 fieldID->value.i = value;
2233 void SetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
2236 fieldID->value.i = value;
2240 void SetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
2243 fieldID->value.i = value;
2247 void SetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
2250 fieldID->value.i = value;
2254 void SetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
2257 fieldID->value.i = value;
2261 void SetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
2264 fieldID->value.l = value;
2268 void SetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
2271 fieldID->value.f = value;
2275 void SetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
2278 fieldID->value.d = value;
2282 /***** create new java.lang.String object from an array of Unicode characters ****/
2284 jstring NewString (JNIEnv *env, const jchar *buf, jsize len)
2287 java_lang_String *s;
2290 s = (java_lang_String*) builtin_new (class_java_lang_String);
2291 a = builtin_newarray_char (len);
2293 /* javastring or characterarray could not be created */
2294 if ( (!a) || (!s) ) return NULL;
2297 for (i=0; i<len; i++) a->data[i] = buf[i];
2306 static char emptyString[]="";
2307 static jchar emptyStringJ[]={0,0};
2309 /******************* returns the length of a Java string ***************************/
2311 jsize GetStringLength (JNIEnv *env, jstring str)
2313 return ((java_lang_String*) str)->count;
2317 /******************** convertes javastring to u2-array ****************************/
2319 u2 *javastring_tou2 (jstring so)
2321 java_lang_String *s = (java_lang_String*) so;
2326 if (!s) return NULL;
2329 if (!a) return NULL;
2331 /* allocate memory */
2332 stringbuffer = MNEW( u2 , s->count + 1 );
2335 for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
2337 /* terminate string */
2338 stringbuffer[i] = '\0';
2340 return stringbuffer;
2343 /********* returns a pointer to an array of Unicode characters of the string *******/
2345 const jchar *GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy)
2347 jchar *jc=javastring_tou2(str);
2350 if (isCopy) *isCopy=JNI_TRUE;
2353 if (isCopy) *isCopy=JNI_TRUE;
2354 return emptyStringJ;
2357 /**************** native code no longer needs access to chars **********************/
2359 void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
2361 if (chars==emptyStringJ) return;
2362 MFREE(((jchar*) chars),jchar,((java_lang_String*) str)->count+1);
2365 /************ create new java.lang.String object from utf8-characterarray **********/
2367 jstring NewStringUTF (JNIEnv *env, const char *utf)
2369 /* log_text("NewStringUTF called");*/
2370 return (jstring) javastring_new(utf_new_char((char *) utf));
2373 /****************** returns the utf8 length in bytes of a string *******************/
2375 jsize GetStringUTFLength (JNIEnv *env, jstring string)
2377 java_lang_String *s = (java_lang_String*) string;
2379 return (jsize) u2_utflength(s->value->data, s->count);
2382 /************ converts a Javastring to an array of UTF-8 characters ****************/
2384 const char* GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
2387 if (verbose) log_text("GetStringUTFChars:");
2389 u=javastring_toutf((java_lang_String*) string,false);
2390 if (isCopy) *isCopy=JNI_FALSE;
2398 /***************** native code no longer needs access to utf ***********************/
2400 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
2402 /*we don't release utf chars right now, perhaps that should be done later. Since there is always one reference
2403 the garbage collector will never get them*/
2405 log_text("JNI-Call: ReleaseStringUTFChars");
2406 utf_display(utf_new_char(chars));
2410 /************************** array operations ***************************************/
2412 jsize GetArrayLength (JNIEnv *env, jarray array)
2417 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
2419 java_objectarray *j;
2421 exceptionptr=proto_java_lang_NegativeArraySizeException;
2424 j = builtin_anewarray (len, clazz);
2425 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2429 jobject GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
2433 if (index<array->header.size)
2434 j = array->data[index];
2436 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2441 void SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobject val)
2443 if (index>=array->header.size)
2444 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2447 /* check if the class of value is a subclass of the element class of the array */
2449 if (!builtin_canstore((java_objectarray*)array,(java_objectheader*)val))
2450 exceptionptr = proto_java_lang_ArrayStoreException;
2452 array->data[index] = val;
2458 jbooleanArray NewBooleanArray (JNIEnv *env, jsize len)
2460 java_booleanarray *j;
2462 exceptionptr=proto_java_lang_NegativeArraySizeException;
2465 j = builtin_newarray_boolean(len);
2466 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2471 jbyteArray NewByteArray (JNIEnv *env, jsize len)
2475 exceptionptr=proto_java_lang_NegativeArraySizeException;
2478 j = builtin_newarray_byte(len);
2479 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2484 jcharArray NewCharArray (JNIEnv *env, jsize len)
2488 exceptionptr=proto_java_lang_NegativeArraySizeException;
2491 j = builtin_newarray_char(len);
2492 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2497 jshortArray NewShortArray (JNIEnv *env, jsize len)
2501 exceptionptr=proto_java_lang_NegativeArraySizeException;
2504 j = builtin_newarray_short(len);
2505 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2510 jintArray NewIntArray (JNIEnv *env, jsize len)
2514 exceptionptr=proto_java_lang_NegativeArraySizeException;
2517 j = builtin_newarray_int(len);
2518 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2523 jlongArray NewLongArray (JNIEnv *env, jsize len)
2527 exceptionptr=proto_java_lang_NegativeArraySizeException;
2530 j = builtin_newarray_long(len);
2531 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2536 jfloatArray NewFloatArray (JNIEnv *env, jsize len)
2540 exceptionptr=proto_java_lang_NegativeArraySizeException;
2543 j = builtin_newarray_float(len);
2544 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2549 jdoubleArray NewDoubleArray (JNIEnv *env, jsize len)
2551 java_doublearray *j;
2553 exceptionptr=proto_java_lang_NegativeArraySizeException;
2556 j = builtin_newarray_double(len);
2557 if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2562 jboolean * GetBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *isCopy)
2564 if (isCopy) *isCopy = JNI_FALSE;
2569 jbyte * GetByteArrayElements (JNIEnv *env, jbyteArray array, jboolean *isCopy)
2571 if (isCopy) *isCopy = JNI_FALSE;
2576 jchar * GetCharArrayElements (JNIEnv *env, jcharArray array, jboolean *isCopy)
2578 if (isCopy) *isCopy = JNI_FALSE;
2583 jshort * GetShortArrayElements (JNIEnv *env, jshortArray array, jboolean *isCopy)
2585 if (isCopy) *isCopy = JNI_FALSE;
2590 jint * GetIntArrayElements (JNIEnv *env, jintArray array, jboolean *isCopy)
2592 if (isCopy) *isCopy = JNI_FALSE;
2597 jlong * GetLongArrayElements (JNIEnv *env, jlongArray array, jboolean *isCopy)
2599 if (isCopy) *isCopy = JNI_FALSE;
2604 jfloat * GetFloatArrayElements (JNIEnv *env, jfloatArray array, jboolean *isCopy)
2606 if (isCopy) *isCopy = JNI_FALSE;
2611 jdouble * GetDoubleArrayElements (JNIEnv *env, jdoubleArray array, jboolean *isCopy)
2613 if (isCopy) *isCopy = JNI_FALSE;
2619 void ReleaseBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode)
2625 void ReleaseByteArrayElements (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode)
2631 void ReleaseCharArrayElements (JNIEnv *env, jcharArray array, jchar *elems, jint mode)
2637 void ReleaseShortArrayElements (JNIEnv *env, jshortArray array, jshort *elems, jint mode)
2643 void ReleaseIntArrayElements (JNIEnv *env, jintArray array, jint *elems, jint mode)
2649 void ReleaseLongArrayElements (JNIEnv *env, jlongArray array, jlong *elems, jint mode)
2655 void ReleaseFloatArrayElements (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode)
2661 void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode)
2666 void GetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2668 if (start<0 || len<0 || start+len>array->header.size)
2669 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2671 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2675 void GetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2677 if (start<0 || len<0 || start+len>array->header.size)
2678 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2680 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2684 void GetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2686 if (start<0 || len<0 || start+len>array->header.size)
2687 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2689 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2693 void GetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2695 if (start<0 || len<0 || start+len>array->header.size)
2696 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2698 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2702 void GetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2704 if (start<0 || len<0 || start+len>array->header.size)
2705 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2707 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2711 void GetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2713 if (start<0 || len<0 || start+len>array->header.size)
2714 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2716 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2720 void GetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2722 if (start<0 || len<0 || start+len>array->header.size)
2723 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2725 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2729 void GetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2731 if (start<0 || len<0 || start+len>array->header.size)
2732 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2734 memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2738 void SetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2740 if (start<0 || len<0 || start+len>array->header.size)
2741 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2743 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2747 void SetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2749 if (start<0 || len<0 || start+len>array->header.size)
2750 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2752 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2756 void SetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2758 if (start<0 || len<0 || start+len>array->header.size)
2759 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2761 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2766 void SetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2768 if (start<0 || len<0 || start+len>array->header.size)
2769 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2771 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2775 void SetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2777 if (start<0 || len<0 || start+len>array->header.size)
2778 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2780 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2784 void SetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2786 if (start<0 || len<0 || start+len>array->header.size)
2787 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2789 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2793 void SetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2795 if (start<0 || len<0 || start+len>array->header.size)
2796 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2798 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2802 void SetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2804 if (start<0 || len<0 || start+len>array->header.size)
2805 exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2807 memcpy(&array->data[start],buf,len*sizeof(array->data[0]));
2810 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
2812 log_text("JNI-Call: RegisterNatives");
2817 jint UnregisterNatives (JNIEnv* env, jclass clazz)
2819 log_text("JNI-Call: UnregisterNatives");
2823 /******************************* monitor operations ********************************/
2825 jint MonitorEnter (JNIEnv* env, jobject obj)
2827 builtin_monitorenter(obj);
2832 jint MonitorExit (JNIEnv* env, jobject obj)
2834 builtin_monitorexit(obj);
2839 /************************************* JavaVM interface ****************************/
2841 #error CPP mode not supported yet
2843 jint GetJavaVM (JNIEnv* env, JavaVM **vm)
2845 log_text("JNI-Call: GetJavaVM");
2849 #endif /*__cplusplus*/
2851 void GetStringRegion (JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
2853 log_text("JNI-Call: GetStringRegion");
2857 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
2859 log_text("JNI-Call: GetStringUTFRegion");
2863 /****************** obtain direct pointer to array elements ***********************/
2865 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
2867 java_objectheader *s = (java_objectheader*) array;
2868 arraydescriptor *desc = s->vftbl->arraydesc;
2870 if (!desc) return NULL;
2872 return ((u1*)s) + desc->dataoffset;
2876 void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jint mode)
2878 log_text("JNI-Call: ReleasePrimitiveArrayCritical");
2883 /********* returns a pointer to an array of Unicode characters of the string *******/
2885 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
2887 log_text("JNI-Call: GetStringCritical");
2889 return GetStringChars(env,string,isCopy);
2892 /**************** native code no longer needs access to chars **********************/
2894 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
2896 log_text("JNI-Call: ReleaseStringCritical");
2898 ReleaseStringChars(env,string,cstring);
2902 jweak NewWeakGlobalRef (JNIEnv* env, jobject obj)
2904 log_text("JNI-Call: NewWeakGlobalRef");
2910 void DeleteWeakGlobalRef (JNIEnv* env, jweak ref)
2912 log_text("JNI-Call: DeleteWeakGlobalRef");
2918 /******************************* check for pending exception ***********************/
2921 jboolean ExceptionCheck(JNIEnv* env)
2923 log_text("JNI-Call: ExceptionCheck");
2925 return exceptionptr ? JNI_TRUE : JNI_FALSE;
2933 jint DestroyJavaVM(JavaVM *vm)
2935 log_text("DestroyJavaVM called");
2941 jint AttachCurrentThread(JavaVM *vm, void **par1, void *par2)
2943 log_text("AttachCurrentThread called");
2949 jint DetachCurrentThread(JavaVM *vm)
2951 log_text("DetachCurrentThread called");
2957 jint GetEnv(JavaVM *vm, void **environment, jint jniversion)
2959 *environment = &env;
2965 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
2967 log_text("AttachCurrentThreadAsDaemon called");
2973 /********************************* JNI invocation table ******************************/
2975 struct _JavaVM javaVMTable={
2980 &AttachCurrentThread,
2981 &DetachCurrentThread,
2983 &AttachCurrentThreadAsDaemon
2986 JavaVM javaVM = &javaVMTable;
2989 /********************************* JNI function table ******************************/
2991 struct JNI_Table envTable = {
2999 &FromReflectedMethod,
3000 &FromReflectedField,
3018 &EnsureLocalCapacity,
3030 &CallBooleanMethodV,
3031 &CallBooleanMethodA,
3056 &CallNonvirtualObjectMethod,
3057 &CallNonvirtualObjectMethodV,
3058 &CallNonvirtualObjectMethodA,
3059 &CallNonvirtualBooleanMethod,
3060 &CallNonvirtualBooleanMethodV,
3061 &CallNonvirtualBooleanMethodA,
3062 &CallNonvirtualByteMethod,
3063 &CallNonvirtualByteMethodV,
3064 &CallNonvirtualByteMethodA,
3065 &CallNonvirtualCharMethod,
3066 &CallNonvirtualCharMethodV,
3067 &CallNonvirtualCharMethodA,
3068 &CallNonvirtualShortMethod,
3069 &CallNonvirtualShortMethodV,
3070 &CallNonvirtualShortMethodA,
3071 &CallNonvirtualIntMethod,
3072 &CallNonvirtualIntMethodV,
3073 &CallNonvirtualIntMethodA,
3074 &CallNonvirtualLongMethod,
3075 &CallNonvirtualLongMethodV,
3076 &CallNonvirtualLongMethodA,
3077 &CallNonvirtualFloatMethod,
3078 &CallNonvirtualFloatMethodV,
3079 &CallNonvirtualFloatMethodA,
3080 &CallNonvirtualDoubleMethod,
3081 &CallNonvirtualDoubleMethodV,
3082 &CallNonvirtualDoubleMethodA,
3083 &CallNonvirtualVoidMethod,
3084 &CallNonvirtualVoidMethodV,
3085 &CallNonvirtualVoidMethodA,
3106 &CallStaticObjectMethod,
3107 &CallStaticObjectMethodV,
3108 &CallStaticObjectMethodA,
3109 &CallStaticBooleanMethod,
3110 &CallStaticBooleanMethodV,
3111 &CallStaticBooleanMethodA,
3112 &CallStaticByteMethod,
3113 &CallStaticByteMethodV,
3114 &CallStaticByteMethodA,
3115 &CallStaticCharMethod,
3116 &CallStaticCharMethodV,
3117 &CallStaticCharMethodA,
3118 &CallStaticShortMethod,
3119 &CallStaticShortMethodV,
3120 &CallStaticShortMethodA,
3121 &CallStaticIntMethod,
3122 &CallStaticIntMethodV,
3123 &CallStaticIntMethodA,
3124 &CallStaticLongMethod,
3125 &CallStaticLongMethodV,
3126 &CallStaticLongMethodA,
3127 &CallStaticFloatMethod,
3128 &CallStaticFloatMethodV,
3129 &CallStaticFloatMethodA,
3130 &CallStaticDoubleMethod,
3131 &CallStaticDoubleMethodV,
3132 &CallStaticDoubleMethodA,
3133 &CallStaticVoidMethod,
3134 &CallStaticVoidMethodV,
3135 &CallStaticVoidMethodA,
3137 &GetStaticObjectField,
3138 &GetStaticBooleanField,
3139 &GetStaticByteField,
3140 &GetStaticCharField,
3141 &GetStaticShortField,
3143 &GetStaticLongField,
3144 &GetStaticFloatField,
3145 &GetStaticDoubleField,
3146 &SetStaticObjectField,
3147 &SetStaticBooleanField,
3148 &SetStaticByteField,
3149 &SetStaticCharField,
3150 &SetStaticShortField,
3152 &SetStaticLongField,
3153 &SetStaticFloatField,
3154 &SetStaticDoubleField,
3158 &ReleaseStringChars,
3160 &GetStringUTFLength,
3162 &ReleaseStringUTFChars,
3165 &GetObjectArrayElement,
3166 &SetObjectArrayElement,
3175 &GetBooleanArrayElements,
3176 &GetByteArrayElements,
3177 &GetCharArrayElements,
3178 &GetShortArrayElements,
3179 &GetIntArrayElements,
3180 &GetLongArrayElements,
3181 &GetFloatArrayElements,
3182 &GetDoubleArrayElements,
3183 &ReleaseBooleanArrayElements,
3184 &ReleaseByteArrayElements,
3185 &ReleaseCharArrayElements,
3186 &ReleaseShortArrayElements,
3187 &ReleaseIntArrayElements,
3188 &ReleaseLongArrayElements,
3189 &ReleaseFloatArrayElements,
3190 &ReleaseDoubleArrayElements,
3191 &GetBooleanArrayRegion,
3192 &GetByteArrayRegion,
3193 &GetCharArrayRegion,
3194 &GetShortArrayRegion,
3196 &GetLongArrayRegion,
3197 &GetFloatArrayRegion,
3198 &GetDoubleArrayRegion,
3199 &SetBooleanArrayRegion,
3200 &SetByteArrayRegion,
3201 &SetCharArrayRegion,
3202 &SetShortArrayRegion,
3204 &SetLongArrayRegion,
3205 &SetFloatArrayRegion,
3206 &SetDoubleArrayRegion,
3213 &GetStringUTFRegion,
3214 &GetPrimitiveArrayCritical,
3215 &ReleasePrimitiveArrayCritical,
3217 &ReleaseStringCritical,
3219 &DeleteWeakGlobalRef,
3223 JNIEnv env = &envTable;
3226 jobject *jni_method_invokeNativeHelper(JNIEnv *env, struct methodinfo *methodID, jobject obj, java_objectarray *params)
3233 if (methodID == 0) {
3234 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
3237 argcount = get_parametercount(methodID);
3239 if (obj && (!builtin_instanceof((java_objectheader*)obj, methodID->class))) {
3240 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/IllegalArgumentException")),
3241 "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
3248 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3249 log_text("Too many arguments. invokeNativeHelper does not support that");
3253 if ( ((!params) && (argcount!=0)) ||
3254 (params && (params->header.size!=argcount))
3256 exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
3261 if (!(methodID->flags & ACC_STATIC) && (!obj)) {
3262 (*env)->ThrowNew(env, loader_load(utf_new_char("java/lang/NullPointerException")),
3263 "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
3267 if ((methodID->flags & ACC_STATIC) && (obj)) obj = 0;
3269 blk = MNEW(jni_callblock, 4 /*argcount+2*/);
3271 retT = fill_callblock_objA(obj, methodID->descriptor, blk, params);
3275 (void) asm_calljavafunction2(methodID,
3277 (argcount + 1) * sizeof(jni_callblock),
3279 retVal = NULL; /*native_new_and_init(loader_load(utf_new_char("java/lang/Void")));*/
3284 intVal = (s4) asm_calljavafunction2(methodID,
3286 (argcount + 1) * sizeof(jni_callblock),
3288 retVal = builtin_new(loader_load_sysclass(NULL,
3289 utf_new_char("java/lang/Integer")));
3292 class_resolvemethod(retVal->vftbl->class,
3293 utf_new_char("<init>"),
3294 utf_new_char("(I)V")),
3301 intVal = (s4) asm_calljavafunction2(methodID,
3303 (argcount + 1) * sizeof(jni_callblock),
3305 retVal = builtin_new(loader_load_sysclass(NULL,
3306 utf_new_char("java/lang/Byte")));
3309 class_resolvemethod(retVal->vftbl->class,
3310 utf_new_char("<init>"),
3311 utf_new_char("(B)V")),
3318 intVal = (s4) asm_calljavafunction2(methodID,
3320 (argcount + 1) * sizeof(jni_callblock),
3322 retVal = builtin_new(loader_load_sysclass(NULL,
3323 utf_new_char("java/lang/Character")));
3326 class_resolvemethod(retVal->vftbl->class,
3327 utf_new_char("<init>"),
3328 utf_new_char("(C)V")),
3335 intVal = (s4) asm_calljavafunction2(methodID,
3337 (argcount + 1) * sizeof(jni_callblock),
3339 retVal = builtin_new(loader_load_sysclass(NULL,
3340 utf_new_char("java/lang/Short")));
3343 class_resolvemethod(retVal->vftbl->class,
3344 utf_new_char("<init>"),
3345 utf_new_char("(S)V")),
3352 intVal = (s4) asm_calljavafunction2(methodID,
3354 (argcount + 1) * sizeof(jni_callblock),
3356 retVal = builtin_new(loader_load_sysclass(NULL,
3357 utf_new_char("java/lang/Boolean")));
3360 class_resolvemethod(retVal->vftbl->class,
3361 utf_new_char("<init>"),
3362 utf_new_char("(Z)V")),
3369 intVal = asm_calljavafunction2long(methodID,
3371 (argcount + 1) * sizeof(jni_callblock),
3373 retVal = builtin_new(loader_load_sysclass(NULL,
3374 utf_new_char("java/lang/Long")));
3377 class_resolvemethod(retVal->vftbl->class,
3378 utf_new_char("<init>"),
3379 utf_new_char("(J)V")),
3386 floatVal = asm_calljavafunction2double(methodID,
3388 (argcount + 1) * sizeof(jni_callblock),
3390 retVal = builtin_new(loader_load_sysclass(NULL,
3391 utf_new_char("java/lang/Float")));
3394 class_resolvemethod(retVal->vftbl->class,
3395 utf_new_char("<init>"),
3396 utf_new_char("(F)V")),
3403 floatVal = asm_calljavafunction2double(methodID,
3405 (argcount + 1) * sizeof(jni_callblock),
3407 retVal = builtin_new(loader_load_sysclass(NULL,
3408 utf_new_char("java/lang/Double")));
3411 class_resolvemethod(retVal->vftbl->class,
3412 utf_new_char("<init>"),
3413 utf_new_char("(D)V")),
3418 case 'L': /* fall through */
3420 retVal = asm_calljavafunction2(methodID,
3422 (argcount + 1) * sizeof(jni_callblock),
3427 /* if this happens the acception has already been set by fill_callblock_objA*/
3428 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3429 return (jobject *) 0;
3432 MFREE(blk, jni_callblock, 4 /*argcount+2*/);
3435 java_objectheader *exceptionToWrap=exceptionptr;
3436 classinfo *ivtec = loader_load_sysclass(NULL,
3437 utf_new_char("java/lang/reflect/InvocationTargetException"));
3438 java_objectheader* ivte = builtin_new(ivtec);
3439 asm_calljavafunction(class_resolvemethod(ivtec,
3440 utf_new_char("<init>"),
3441 utf_new_char("(Ljava/lang/Throwable;)V")),
3447 if (exceptionptr != NULL)
3448 panic("jni.c: error while creating InvocationTargetException wrapper");
3450 exceptionptr = ivte;
3453 return (jobject *) retVal;
3458 * These are local overrides for various environment variables in Emacs.
3459 * Please do not remove this and leave it at the end of the file, where
3460 * Emacs will automagically detect them.
3461 * ---------------------------------------------------------------------
3464 * indent-tabs-mode: t