try fixing alpha
[cacao.git] / jni.c
1 /* jni.c - implementation of JNI functions
2
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
7
8    This file is part of CACAO.
9
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.
14
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.
19
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
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: ?
28
29    $Id: jni.c 676 2003-11-24 20:50:23Z twisti $
30
31 */
32
33
34 #include "jni.h"
35 #include "types.h"
36 #include "jit.h"
37 #include "builtin.h"
38 #include "loader.h"
39 #include "native.h"
40 #include "tables.h"
41 #include "asmpart.h"
42 #include "toolbox/memory.h"
43 #include "nat/java_lang_Throwable.h"
44
45
46 /********************* accessing instance-fields **********************************/
47
48 u4 get_parametercount(methodinfo *m)
49 {
50     utf  *descr    =  m->descriptor;    /* method-descriptor */
51     char *utf_ptr  =  descr->text;      /* current position in utf-text */
52     char *desc_end =  utf_end(descr);   /* points behind utf string     */
53     int parametercount = 0;
54
55     /* skip '(' */
56     utf_nextu2(&utf_ptr);
57
58     /* determine number of parameters */
59     while (*utf_ptr != ')') {
60         get_type(&utf_ptr, desc_end, true);
61         parametercount++;
62     }
63
64     return parametercount;
65 }
66
67
68
69 /* XXX it could be considered if we should do typechecking here in the future */
70 void fill_callblock(void *obj, utf *descr, jni_callblock blk[], va_list data, char ret)
71 {
72     char *utf__ptr  =  descr->text;      /* current position in utf-text */
73     char **utf_ptr  =  &utf__ptr;
74     char *desc_end =  utf_end(descr);   /* points behind utf string     */
75
76     int cnt;
77
78     u4 dummy;
79     char c;
80         /*
81           log_text("fill_callblock");
82           utf_display(descr);
83           log_text("====");
84         */
85     /* skip '(' */
86     utf_nextu2(utf_ptr);
87
88     /* determine number of parameters */
89         if (obj) {
90                 blk[0].itemtype = TYPE_ADR;
91                 blk[0].item = (u8)(u4)obj;
92                 cnt=1;
93
94         } else {
95                 cnt = 0;
96         }
97
98         while (**utf_ptr != ')') {
99                 if (*utf_ptr >= desc_end)
100                 panic("illegal method descriptor");
101
102                 /* primitive types */
103                 switch (utf_nextu2(utf_ptr)) {
104                 case 'B':
105                 case 'C':
106                 case 'S': 
107                 case 'Z':
108                         blk[cnt].itemtype = TYPE_INT;
109                         blk[cnt].item = (u8) va_arg(data, int);
110                         break;
111
112                 case 'I':
113                         blk[cnt].itemtype = TYPE_INT;
114                         dummy = va_arg(data, u4);
115                         /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
116                         blk[cnt].item = (u8) dummy;
117                         break;
118
119                 case 'J':
120                         blk[cnt].itemtype = TYPE_LNG;
121                         blk[cnt].item = (u8) va_arg(data, jlong);
122                         break;
123
124                 case 'F':
125                         blk[cnt].itemtype = TYPE_FLT;
126                         *((jfloat*) (&blk[cnt].item)) = ((jfloat) va_arg(data, jdouble));
127                         break;
128
129                 case 'D':
130                         blk[cnt].itemtype = TYPE_DBL;
131                         *((jdouble*) (&blk[cnt].item)) = (jdouble) va_arg(data, jdouble);
132                         break;
133
134                 case 'V':
135                         panic("V not allowed as function parameter");
136                         break;
137
138                 case 'L':
139                         while (utf_nextu2(utf_ptr) != ';')
140                             blk[cnt].itemtype = TYPE_ADR;
141
142                         blk[cnt].item = (u8)(u4) va_arg(data, void*);
143                         break;                  
144
145                 case '[' : {
146                         /* XXX need arrayclass change? no.*/
147                         /* arrayclass */
148                         char ch;
149                         while ((ch = utf_nextu2(utf_ptr)) == '[')
150                                 if (ch == 'L') {
151                                         while (utf_nextu2(utf_ptr) != ';') {}
152                                 }
153                         
154                         ch = utf_nextu2(utf_ptr);
155                         blk[cnt].itemtype = TYPE_ADR;
156                         blk[cnt].item = (u8)(u4) va_arg(data, void*);
157                         break;
158                 }
159                 }
160                 cnt++;
161         }
162
163         /*the standard doesn't say anything about return value checking, but it appears to be usefull*/
164         c = utf_nextu2(utf_ptr);
165         c = utf_nextu2(utf_ptr);
166         /*printf("%c  %c\n",ret,c);*/
167         if (ret == 'O') {
168                 if (!((c == 'L') || (c == '[')))
169                         log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
170
171         } else if (ret != c)
172                 log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
173 }
174
175
176
177 jmethodID get_virtual(jobject obj,jmethodID methodID) {
178         if (obj->vftbl->class==methodID->class) return methodID;
179         return class_resolvemethod (obj->vftbl->class, methodID->name, methodID->descriptor);
180 }
181
182 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
183         if (clazz==methodID->class) return methodID;
184         return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
185 }
186
187 jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
188 {       
189         int argcount;
190         jni_callblock *blk;
191         jobject ret;
192
193         /*
194           log_text("JNI-Call: CallObjectMethodV");
195           utf_display(methodID->name);
196           utf_display(methodID->descriptor);
197           printf("\nParmaeter count: %d\n",argcount);
198           utf_display(obj->vftbl->class->name);
199           printf("\n");
200         */
201
202         if (methodID==0) {
203                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
204                 return 0;
205         }
206         argcount=get_parametercount(methodID);
207
208         if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
209                 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
210                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
211                 return 0;
212         }
213         
214         if (obj && (! builtin_instanceof(obj,methodID->class))) {
215                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
216                 return 0;
217         }
218
219         if  (argcount>3) {
220                 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
221                 log_text("Too many arguments. CallObjectMethod does not support that");
222                 return 0;
223         }
224
225         blk = MNEW(jni_callblock, 4 /*argcount+2*/);
226
227         fill_callblock(obj,methodID->descriptor,blk,args,'O');
228
229         /*      printf("parameter: obj: %p",blk[0].item); */
230         ret=asm_calljavafunction2(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
231         MFREE(blk,jni_callblock,argcount+1);
232         /*      printf("(CallObjectMethodV)-->%p\n",ret); */
233         return ret;
234 }
235
236
237 /*
238   core function for integer class methods (bool, byte, short, integer)
239   This is basically needed for i386
240 */
241 jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list args)
242 {
243         int argcount;
244         jni_callblock *blk;
245         jint ret;
246
247 /*      printf("%p,     %c\n",retType,methodID,retType);*/
248
249         /*
250         log_text("JNI-Call: CallObjectMethodV");
251         utf_display(methodID->name);
252         utf_display(methodID->descriptor);
253         printf("\nParmaeter count: %d\n",argcount);
254         utf_display(obj->vftbl->class->name);
255         printf("\n");
256         */
257         if (methodID == 0) {
258                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
259                 return 0;
260         }
261         
262         argcount = get_parametercount(methodID);
263
264         if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
265                 ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
266                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
267                 return 0;
268         }
269
270         if (obj && (! builtin_instanceof(obj,methodID->class))) {
271                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
272                 return 0;
273         }
274
275
276         if  (argcount>3) {
277                 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
278                 log_text("Too many arguments. CallObjectMethod does not support that");
279                 return 0;
280         }
281
282         blk = MNEW(jni_callblock, 4 /*argcount+2*/);
283
284         fill_callblock(obj, methodID->descriptor, blk, args, retType);
285
286         /*      printf("parameter: obj: %p",blk[0].item); */
287         ret = (jint) asm_calljavafunction2(methodID,
288                                                                            argcount + 1,
289                                                                            (argcount + 1) * sizeof(jni_callblock),
290                                                                            blk);
291
292         MFREE(blk, jni_callblock, argcount + 1);
293         /*      printf("(CallObjectMethodV)-->%p\n",ret); */
294
295         return ret;
296 }
297
298
299 /*core function for long class functions*/
300 jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
301 {
302         int argcount;
303         jni_callblock *blk;
304         jlong ret;
305
306         /*
307         log_text("JNI-Call: CallObjectMethodV");
308         utf_display(methodID->name);
309         utf_display(methodID->descriptor);
310         printf("\nParmaeter count: %d\n",argcount);
311         utf_display(obj->vftbl->class->name);
312         printf("\n");
313         */
314         if (methodID==0) {
315                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
316                 return 0;
317         }
318         argcount=get_parametercount(methodID);
319
320         if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
321                    ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
322                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
323                 return 0;
324         }
325
326         if (obj && (! builtin_instanceof(obj,methodID->class))) {
327                 exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
328                 return 0;
329         }
330
331
332         if  (argcount>3) {
333                 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
334                 log_text("Too many arguments. CallObjectMethod does not support that");
335                 return 0;
336         }
337
338         blk = MNEW(jni_callblock, 4 /*argcount+2*/);
339
340         fill_callblock(obj,methodID->descriptor,blk,args,'L');
341
342         /*      printf("parameter: obj: %p",blk[0].item); */
343         ret=asm_calljavafunction2long(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
344         MFREE(blk,jni_callblock,argcount+1);
345         /*      printf("(CallObjectMethodV)-->%p\n",ret); */
346
347         return ret;
348 }
349
350
351 /*core function for float class methods (float,double)*/
352 jdouble callFloatMethod (jobject obj, jmethodID methodID, va_list args,char retType)
353 {
354         int argcount=get_parametercount(methodID);
355         jni_callblock *blk;
356         jdouble ret;
357
358         /*
359         log_text("JNI-Call: CallObjectMethodV");
360         utf_display(methodID->name);
361         utf_display(methodID->descriptor);
362         printf("\nParmaeter count: %d\n",argcount);
363         utf_display(obj->vftbl->class->name);
364         printf("\n");
365         */
366         if  (argcount>3) {
367                 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
368                 log_text("Too many arguments. CallObjectMethod does not support that");
369                 return 0;
370         }
371
372         blk = MNEW(jni_callblock, 4 /*argcount+2*/);
373
374         fill_callblock(obj,methodID->descriptor,blk,args,retType);
375
376         /*      printf("parameter: obj: %p",blk[0].item); */
377         ret=asm_calljavafunction2double(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
378         MFREE(blk,jni_callblock,argcount+1);
379         /*      printf("(CallObjectMethodV)-->%p\n",ret); */
380
381         return ret;
382 }
383
384
385 /*************************** function: jclass_findfield ****************************
386         
387         searches for field with specified name and type in a 'classinfo'-structur
388         if no such field is found NULL is returned 
389
390 ************************************************************************************/
391
392 fieldinfo *jclass_findfield (classinfo *c, utf *name, utf *desc)
393 {
394         s4 i;
395 /*      printf(" FieldCount: %d\n",c->fieldscount);
396         utf_display(c->name); */
397                 for (i = 0; i < c->fieldscount; i++) {
398 /*              utf_display(c->fields[i].name);
399                 printf("\n");
400                 utf_display(c->fields[i].descriptor);
401                 printf("\n");*/
402                 if ((c->fields[i].name == name) && (c->fields[i].descriptor == desc))
403                         return &(c->fields[i]);
404                 }
405
406         if (c->super) return jclass_findfield(c->super,name,desc);
407
408         return NULL;
409 }
410
411 /********************* returns version of native method interface *****************/
412
413 jint GetVersion (JNIEnv* env)
414 {
415         return JNI_VERSION;
416 }
417
418 /****************** loads a class from a buffer of raw class data *****************/
419
420 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len) 
421 {
422         jclass clazz; 
423
424         /* change suck-mode, so subsequent class_load will read from memory-buffer */
425         classload_buffer( (u1*) buf,len);
426
427         clazz = loader_load(utf_new_char ((char *) name));
428
429         /* restore old suck-mode */
430         classload_buffer(NULL,0);
431
432         return clazz;
433 }
434
435
436 /*************** loads locally defined class with the specified name **************/
437
438 jclass FindClass (JNIEnv* env, const char *name) 
439 {
440         classinfo *c;  
441   
442 /*      if (strcmp(name,"[B")==0) {
443                 c = loader_load(utf_new_char("The_Array_Class"));
444         }
445         else*/
446                 c = loader_load(utf_new_char_classname ((char *) name));
447
448         if (!c) exceptionptr = native_new_and_init(class_java_lang_ClassFormatError);
449
450         return c;
451 }
452   
453
454 /*********************************************************************************** 
455
456         converts java.lang.reflect.Method or 
457         java.lang.reflect.Constructor object to a method ID  
458   
459  **********************************************************************************/   
460   
461 jmethodID FromReflectedMethod(JNIEnv* env, jobject method)
462 {
463         /* log_text("JNI-Call: FromReflectedMethod"); */
464
465         return 0;
466 }
467
468
469 /*************** return superclass of the class represented by sub ****************/
470  
471 jclass GetSuperclass(JNIEnv* env, jclass sub) 
472 {
473         classinfo *c;
474
475         c = ((classinfo*) sub)->super;
476
477         if (!c) return NULL; 
478
479         use_class_as_object(c);
480
481         return c;               
482 }
483   
484  
485 /*********************** check whether sub can be cast to sup  ********************/
486   
487 jboolean IsAssignableForm(JNIEnv* env, jclass sub, jclass sup)
488 {
489         return builtin_isanysubclass(sub, sup);
490 }
491
492
493 /***** converts a field ID derived from cls to a java.lang.reflect.Field object ***/
494
495 jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isStatic)
496 {
497         /* log_text("JNI-Call: ToReflectedField"); */
498
499         return NULL;
500 }
501
502
503 /***************** throw java.lang.Throwable object  ******************************/
504
505 jint Throw(JNIEnv* env, jthrowable obj)
506 {
507         exceptionptr = (java_objectheader*) obj;
508
509         return 0;
510 }
511
512
513 /*********************************************************************************** 
514
515         create exception object from the class clazz with the 
516         specified message and cause it to be thrown
517
518  **********************************************************************************/   
519
520
521 jint ThrowNew (JNIEnv* env, jclass clazz, const char *msg) 
522 {
523         java_lang_Throwable *o;
524
525         /* instantiate exception object */
526         o = (java_lang_Throwable *) native_new_and_init ((classinfo*) clazz);
527
528         if (!o) return (-1);
529
530         o->detailMessage = (java_lang_String*) javastring_new_char((char *) msg);
531
532         exceptionptr = (java_objectheader*) o;  
533         return 0;
534 }
535
536 /************************* check if exception occured *****************************/
537
538 jthrowable ExceptionOccurred (JNIEnv* env) 
539 {
540         return (jthrowable) exceptionptr;
541 }
542
543 /********** print exception and a backtrace of the stack (for debugging) **********/
544
545 void ExceptionDescribe (JNIEnv* env) 
546 {
547         utf_display(exceptionptr->vftbl->class->name);
548         printf ("\n");
549         fflush (stdout);        
550 }
551
552
553 /******************* clear any exception currently being thrown *******************/
554
555 void ExceptionClear (JNIEnv* env) 
556 {
557         exceptionptr = NULL;    
558 }
559
560
561 /********** raises a fatal error and does not expect the VM to recover ************/
562
563 void FatalError (JNIEnv* env, const char *msg)
564 {
565         panic((char *) msg);    
566 }
567
568 /******************* creates a new local reference frame **************************/ 
569
570 jint PushLocalFrame(JNIEnv* env, jint capacity)
571 {
572         /* empty */
573
574         return 0;
575 }
576
577 /**************** Pops off the current local reference frame **********************/
578
579 jobject PopLocalFrame(JNIEnv* env, jobject result)
580 {
581         /* empty */
582
583         return NULL;
584 }
585     
586
587 /** Creates a new global reference to the object referred to by the obj argument **/
588     
589 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
590 {
591         heap_addreference((void**) &lobj);
592
593         return lobj;
594 }
595
596 /*************  Deletes the global reference pointed to by globalRef **************/
597
598 void DeleteGlobalRef (JNIEnv* env, jobject gref)
599 {
600         /* empty */
601 }
602
603
604 /*************** Deletes the local reference pointed to by localRef ***************/
605
606 void DeleteLocalRef (JNIEnv* env, jobject localRef)
607 {
608         /* empty */
609 }
610
611 /********** Tests whether two references refer to the same Java object ************/
612
613 jboolean IsSameObject (JNIEnv* env, jobject obj1, jobject obj2)
614 {
615         return (obj1==obj2);
616 }
617
618 /***** Creates a new local reference that refers to the same object as ref  *******/
619
620 jobject NewLocalRef (JNIEnv* env, jobject ref)
621 {
622         return ref;
623 }
624
625 /*********************************************************************************** 
626
627         Ensures that at least a given number of local references can 
628         be created in the current thread
629
630  **********************************************************************************/   
631
632 jint EnsureLocalCapacity (JNIEnv* env, jint capacity)
633 {
634         return 0; /* return 0 on success */
635 }
636
637
638 /********* Allocates a new Java object without invoking a constructor *************/
639
640 jobject AllocObject (JNIEnv* env, jclass clazz)
641 {
642         java_objectheader *o = builtin_new(clazz);      
643         return o;
644 }
645
646
647 /*********************************************************************************** 
648
649         Constructs a new Java object
650         arguments that are to be passed to the constructor are placed after methodID
651
652 ***********************************************************************************/
653
654 jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
655 {
656         java_objectheader *o;
657         void* args[3];
658         int argcount=get_parametercount(methodID);
659         int i;
660         va_list vaargs;
661
662         /* log_text("JNI-Call: NewObject"); */
663
664         if  (argcount>3) {
665                 exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
666                 log_text("Too many arguments. NewObject does not support that");
667                 return 0;
668         }
669
670         
671         o = builtin_new (clazz);         /*          create object */
672         
673         if (!o) return NULL;
674
675         va_start(vaargs,methodID);
676         for (i=0;i<argcount;i++) {
677                 args[i]=va_arg(vaargs,void*);
678         }
679         va_end(vaargs);
680         exceptionptr=asm_calljavamethod(methodID,o,args[0],args[1],args[2]);
681
682         return o;
683 }
684
685
686 /*********************************************************************************** 
687
688        Constructs a new Java object
689        arguments that are to be passed to the constructor are placed in va_list args 
690
691 ***********************************************************************************/
692
693 jobject NewObjectV(JNIEnv* env, jclass clazz, jmethodID methodID, va_list args)
694 {
695         /* log_text("JNI-Call: NewObjectV"); */
696
697         return NULL;
698 }
699
700
701 /*********************************************************************************** 
702
703         Constructs a new Java object
704         arguments that are to be passed to the constructor are placed in 
705         args array of jvalues 
706
707 ***********************************************************************************/
708
709 jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
710 {
711         /* log_text("JNI-Call: NewObjectA"); */
712
713         return NULL;
714 }
715
716
717 /************************ returns the class of an object **************************/ 
718
719 jclass GetObjectClass(JNIEnv* env, jobject obj)
720 {
721         classinfo *c = obj->vftbl->class;
722         use_class_as_object(c);
723
724         return c;
725 }
726
727
728 /************* tests whether an object is an instance of a class ******************/
729
730 jboolean IsInstanceOf(JNIEnv* env, jobject obj, jclass clazz)
731 {
732         return builtin_instanceof(obj,clazz);
733 }
734
735
736 /***************** converts a java.lang.reflect.Field to a field ID ***************/
737  
738 jfieldID FromReflectedField(JNIEnv* env, jobject field)
739 {
740         log_text("JNI-Call: FromReflectedField");
741
742         return 0;
743 }
744
745
746 /**********************************************************************************
747
748         converts a method ID to a java.lang.reflect.Method or 
749         java.lang.reflect.Constructor object
750
751 **********************************************************************************/
752
753 jobject ToReflectedMethod(JNIEnv* env, jclass cls, jmethodID methodID, jboolean isStatic)
754 {
755         log_text("JNI-Call: ToReflectedMethod");
756
757         return NULL;
758 }
759
760
761 /**************** returns the method ID for an instance method ********************/
762
763 jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *sig)
764 {
765         jmethodID m;
766
767         m = class_resolvemethod (
768                 clazz, 
769                 utf_new_char ((char*) name), 
770                 utf_new_char ((char*) sig)
771         );
772
773         if (!m) exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);          
774
775         return m;
776 }
777
778
779 /******************** JNI-functions for calling instance methods ******************/
780
781 jobject CallObjectMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
782 {
783         jobject ret;
784         va_list vaargs;
785
786 /*      log_text("JNI-Call: CallObjectMethod");*/
787
788         va_start(vaargs, methodID);
789         ret = callObjectMethod(obj, methodID, vaargs);
790         va_end(vaargs);
791
792         return ret;
793 }
794
795
796 jobject CallObjectMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
797 {
798         return callObjectMethod(obj,methodID,args);
799 }
800
801
802 jobject CallObjectMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
803 {
804         log_text("JNI-Call: CallObjectMethodA");
805
806         return NULL;
807 }
808
809
810
811
812 jboolean CallBooleanMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
813 {
814         jboolean ret;
815         va_list vaargs;
816
817 /*      log_text("JNI-Call: CallBooleanMethod");*/
818
819         va_start(vaargs,methodID);
820         ret = (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',vaargs);
821         va_end(vaargs);
822         return ret;
823
824 }
825
826 jboolean CallBooleanMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
827 {
828         return (jboolean)callIntegerMethod(obj,get_virtual(obj,methodID),'Z',args);
829
830 }
831
832 jboolean CallBooleanMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
833 {
834         log_text("JNI-Call: CallBooleanMethodA");
835
836         return 0;
837 }
838
839 jbyte CallByteMethod (JNIEnv *env, jobject obj, jmethodID methodID, ...)
840 {
841         jbyte ret;
842         va_list vaargs;
843
844 /*      log_text("JNI-Call: CallVyteMethod");*/
845
846         va_start(vaargs,methodID);
847         ret = callIntegerMethod(obj,get_virtual(obj,methodID),'B',vaargs);
848         va_end(vaargs);
849         return ret;
850
851 }
852
853 jbyte CallByteMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
854 {
855 /*      log_text("JNI-Call: CallByteMethodV");*/
856         return callIntegerMethod(obj,methodID,'B',args);
857 }
858
859
860 jbyte CallByteMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
861 {
862         log_text("JNI-Call: CallByteMethodA");
863
864         return 0;
865 }
866
867
868 jchar CallCharMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
869 {
870         jchar ret;
871         va_list vaargs;
872
873 /*      log_text("JNI-Call: CallCharMethod");*/
874
875         va_start(vaargs,methodID);
876         ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'C', vaargs);
877         va_end(vaargs);
878
879         return ret;
880 }
881
882
883 jchar CallCharMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
884 {
885 /*      log_text("JNI-Call: CallCharMethodV");*/
886         return callIntegerMethod(obj,get_virtual(obj,methodID),'C',args);
887 }
888
889
890 jchar CallCharMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
891 {
892         log_text("JNI-Call: CallCharMethodA");
893
894         return 0;
895 }
896
897
898 jshort CallShortMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
899 {
900         jshort ret;
901         va_list vaargs;
902
903 /*      log_text("JNI-Call: CallShortMethod");*/
904
905         va_start(vaargs, methodID);
906         ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'S', vaargs);
907         va_end(vaargs);
908
909         return ret;
910 }
911
912
913 jshort CallShortMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
914 {
915         return callIntegerMethod(obj, get_virtual(obj, methodID), 'S', args);
916 }
917
918
919 jshort CallShortMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
920 {
921         log_text("JNI-Call: CallShortMethodA");
922
923         return 0;
924 }
925
926
927
928 jint CallIntMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
929 {
930         jint ret;
931         va_list vaargs;
932
933         va_start(vaargs,methodID);
934         ret = callIntegerMethod(obj, get_virtual(obj, methodID), 'I', vaargs);
935         va_end(vaargs);
936
937         return ret;
938 }
939
940
941 jint CallIntMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
942 {
943         return callIntegerMethod(obj, get_virtual(obj, methodID), 'I', args);
944 }
945
946
947 jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
948 {
949         log_text("JNI-Call: CallIntMethodA");
950
951         return 0;
952 }
953
954
955
956 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
957 {
958         log_text("JNI-Call: CallLongMethod");
959
960         return 0;
961 }
962
963
964 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
965 {
966         log_text("JNI-Call: CallLongMethodV");
967
968         return 0;
969 }
970
971
972 jlong CallLongMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
973 {
974         log_text("JNI-Call: CallLongMethodA");
975
976         return 0;
977 }
978
979
980
981 jfloat CallFloatMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
982 {
983         jfloat ret;
984         va_list vaargs;
985
986 /*      log_text("JNI-Call: CallFloatMethod");*/
987
988         va_start(vaargs,methodID);
989         ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'F');
990         va_end(vaargs);
991
992         return ret;
993 }
994
995
996 jfloat CallFloatMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
997 {
998         log_text("JNI-Call: CallFloatMethodV");
999         return callFloatMethod(obj, get_virtual(obj, methodID), args, 'F');
1000 }
1001
1002
1003 jfloat CallFloatMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1004 {
1005         log_text("JNI-Call: CallFloatMethodA");
1006
1007         return 0;
1008 }
1009
1010
1011
1012 jdouble CallDoubleMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1013 {
1014         jdouble ret;
1015         va_list vaargs;
1016
1017 /*      log_text("JNI-Call: CallDoubleMethod");*/
1018
1019         va_start(vaargs,methodID);
1020         ret = callFloatMethod(obj, get_virtual(obj, methodID), vaargs, 'D');
1021         va_end(vaargs);
1022
1023         return ret;
1024 }
1025
1026
1027 jdouble CallDoubleMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1028 {
1029         log_text("JNI-Call: CallDoubleMethodV");
1030         return callFloatMethod(obj, get_virtual(obj, methodID), args, 'D');
1031 }
1032
1033
1034 jdouble CallDoubleMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
1035 {
1036         log_text("JNI-Call: CallDoubleMethodA");
1037         return 0;
1038 }
1039
1040
1041
1042 void CallVoidMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
1043 {
1044         va_list vaargs;
1045
1046 /*      log_text("JNI-Call: CallVoidMethod");*/
1047
1048         va_start(vaargs,methodID);
1049         (void) callIntegerMethod(obj, get_virtual(obj, methodID), 'V', vaargs);
1050         va_end(vaargs);
1051 }
1052
1053
1054 void CallVoidMethodV (JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
1055 {
1056         log_text("JNI-Call: CallVoidMethodV");
1057         (void)callIntegerMethod(obj,get_virtual(obj,methodID),'V',args);
1058 }
1059
1060
1061 void CallVoidMethodA (JNIEnv *env, jobject obj, jmethodID methodID, jvalue * args)
1062 {
1063         log_text("JNI-Call: CallVoidMethodA");
1064 }
1065
1066
1067
1068 jobject CallNonvirtualObjectMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1069 {
1070         log_text("JNI-Call: CallNonvirtualObjectMethod");
1071
1072         return NULL;
1073 }
1074
1075
1076 jobject CallNonvirtualObjectMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1077 {
1078         log_text("JNI-Call: CallNonvirtualObjectMethodV");
1079
1080         return NULL;
1081 }
1082
1083
1084 jobject CallNonvirtualObjectMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1085 {
1086         log_text("JNI-Call: CallNonvirtualObjectMethodA");
1087
1088         return NULL;
1089 }
1090
1091
1092
1093 jboolean CallNonvirtualBooleanMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1094 {
1095         jboolean ret;
1096         va_list vaargs;
1097
1098 /*      log_text("JNI-Call: CallNonvirtualBooleanMethod");*/
1099
1100         va_start(vaargs,methodID);
1101         ret = (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',vaargs);
1102         va_end(vaargs);
1103         return ret;
1104
1105 }
1106
1107
1108 jboolean CallNonvirtualBooleanMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1109 {
1110 /*      log_text("JNI-Call: CallNonvirtualBooleanMethodV");*/
1111         return (jboolean)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'Z',args);
1112 }
1113
1114
1115 jboolean CallNonvirtualBooleanMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1116 {
1117         log_text("JNI-Call: CallNonvirtualBooleanMethodA");
1118
1119         return 0;
1120 }
1121
1122
1123
1124 jbyte CallNonvirtualByteMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1125 {
1126         jbyte ret;
1127         va_list vaargs;
1128
1129 /*      log_text("JNI-Call: CallNonvirutalByteMethod");*/
1130
1131         va_start(vaargs,methodID);
1132         ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',vaargs);
1133         va_end(vaargs);
1134         return ret;
1135 }
1136
1137
1138 jbyte CallNonvirtualByteMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1139 {
1140         /*log_text("JNI-Call: CallNonvirtualByteMethodV"); */
1141         return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'B',args);
1142
1143 }
1144
1145
1146 jbyte CallNonvirtualByteMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1147 {
1148         log_text("JNI-Call: CallNonvirtualByteMethodA");
1149
1150         return 0;
1151 }
1152
1153
1154
1155 jchar CallNonvirtualCharMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1156 {
1157         jchar ret;
1158         va_list vaargs;
1159
1160 /*      log_text("JNI-Call: CallNonVirtualCharMethod");*/
1161
1162         va_start(vaargs,methodID);
1163         ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',vaargs);
1164         va_end(vaargs);
1165         return ret;
1166 }
1167
1168
1169 jchar CallNonvirtualCharMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1170 {
1171         /*log_text("JNI-Call: CallNonvirtualCharMethodV");*/
1172         return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'C',args);
1173 }
1174
1175
1176 jchar CallNonvirtualCharMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1177 {
1178         log_text("JNI-Call: CallNonvirtualCharMethodA");
1179
1180         return 0;
1181 }
1182
1183
1184
1185 jshort CallNonvirtualShortMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1186 {
1187         jshort ret;
1188         va_list vaargs;
1189
1190         /*log_text("JNI-Call: CallNonvirtualShortMethod");*/
1191
1192         va_start(vaargs,methodID);
1193         ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',vaargs);
1194         va_end(vaargs);
1195         return ret;
1196 }
1197
1198
1199 jshort CallNonvirtualShortMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1200 {
1201         /*log_text("JNI-Call: CallNonvirtualShortMethodV");*/
1202         return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'S',args);
1203 }
1204
1205
1206 jshort CallNonvirtualShortMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1207 {
1208         log_text("JNI-Call: CallNonvirtualShortMethodA");
1209
1210         return 0;
1211 }
1212
1213
1214
1215 jint CallNonvirtualIntMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1216 {
1217
1218         jint ret;
1219         va_list vaargs;
1220
1221         /*log_text("JNI-Call: CallNonvirtualIntMethod");*/
1222
1223         va_start(vaargs,methodID);
1224         ret = callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',vaargs);
1225         va_end(vaargs);
1226         return ret;
1227 }
1228
1229
1230 jint CallNonvirtualIntMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1231 {
1232         /*log_text("JNI-Call: CallNonvirtualIntMethodV");*/
1233         return callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'I',args);
1234 }
1235
1236
1237 jint CallNonvirtualIntMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1238 {
1239         log_text("JNI-Call: CallNonvirtualIntMethodA");
1240
1241         return 0;
1242 }
1243
1244
1245
1246 jlong CallNonvirtualLongMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1247 {
1248         log_text("JNI-Call: CallNonvirtualLongMethod");
1249
1250         return 0;
1251 }
1252
1253
1254 jlong CallNonvirtualLongMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1255 {
1256         log_text("JNI-Call: CallNonvirtualLongMethodV");
1257
1258         return 0;
1259 }
1260
1261
1262 jlong CallNonvirtualLongMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1263 {
1264         log_text("JNI-Call: CallNonvirtualLongMethodA");
1265
1266         return 0;
1267 }
1268
1269
1270
1271 jfloat CallNonvirtualFloatMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1272 {
1273         jfloat ret;
1274         va_list vaargs;
1275
1276         /*log_text("JNI-Call: CallNonvirtualFloatMethod");*/
1277
1278
1279         va_start(vaargs,methodID);
1280         ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'F');
1281         va_end(vaargs);
1282         return ret;
1283
1284 }
1285
1286
1287 jfloat CallNonvirtualFloatMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1288 {
1289         log_text("JNI-Call: CallNonvirtualFloatMethodV");
1290         return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'F');
1291 }
1292
1293
1294 jfloat CallNonvirtualFloatMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1295 {
1296         log_text("JNI-Call: CallNonvirtualFloatMethodA");
1297
1298         return 0;
1299 }
1300
1301
1302
1303 jdouble CallNonvirtualDoubleMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1304 {
1305         jdouble ret;
1306         va_list vaargs;
1307         log_text("JNI-Call: CallNonvirtualDoubleMethod");
1308
1309         va_start(vaargs,methodID);
1310         ret = callFloatMethod(obj,get_nonvirtual(clazz,methodID),vaargs,'D');
1311         va_end(vaargs);
1312         return ret;
1313
1314 }
1315
1316
1317 jdouble CallNonvirtualDoubleMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1318 {
1319 /*      log_text("JNI-Call: CallNonvirtualDoubleMethodV");*/
1320         return callFloatMethod(obj,get_nonvirtual(clazz,methodID),args,'D');
1321 }
1322
1323
1324 jdouble CallNonvirtualDoubleMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue *args)
1325 {
1326         log_text("JNI-Call: CallNonvirtualDoubleMethodA");
1327
1328         return 0;
1329 }
1330
1331
1332
1333 void CallNonvirtualVoidMethod (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, ...)
1334 {
1335         va_list vaargs;
1336
1337 /*      log_text("JNI-Call: CallNonvirtualVoidMethod");*/
1338
1339         va_start(vaargs,methodID);
1340         (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',vaargs);
1341         va_end(vaargs);
1342
1343 }
1344
1345
1346 void CallNonvirtualVoidMethodV (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, va_list args)
1347 {
1348 /*      log_text("JNI-Call: CallNonvirtualVoidMethodV");*/
1349
1350         (void)callIntegerMethod(obj,get_nonvirtual(clazz,methodID),'V',args);
1351
1352 }
1353
1354
1355 void CallNonvirtualVoidMethodA (JNIEnv *env, jobject obj, jclass clazz, jmethodID methodID, jvalue * args)
1356 {
1357         log_text("JNI-Call: CallNonvirtualVoidMethodA");
1358 }
1359
1360 /************************* JNI-functions for accessing fields ************************/
1361
1362 jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig) 
1363 {
1364         jfieldID f;
1365
1366 /*      log_text("========================= searching for:");
1367         log_text(name);
1368         log_text(sig);*/
1369         f = jclass_findfield(clazz,
1370                             utf_new_char ((char*) name), 
1371                             utf_new_char ((char*) sig)
1372                             ); 
1373         
1374         if (!f) { 
1375 /*              utf_display(clazz->name);
1376                 log_text(name);
1377                 log_text(sig);*/
1378                 exceptionptr =  native_new_and_init(class_java_lang_NoSuchFieldError);  
1379         }
1380         return f;
1381 }
1382
1383 /*************************** retrieve fieldid, abort on error ************************/
1384
1385 jfieldID getFieldID_critical(JNIEnv *env, jclass clazz, char *name, char *sig)
1386 {
1387     jfieldID id = GetFieldID(env, clazz, name, sig);
1388
1389     if (!id) {
1390        log_text("class:");
1391        utf_display(clazz->name);
1392        log_text("\nfield:");
1393        log_text(name);
1394        log_text("sig:");
1395        log_text(sig);
1396
1397        panic("setfield_critical failed"); 
1398     }
1399     return id;
1400 }
1401
1402 jobject GetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID)
1403 {
1404         return getField(obj,jobject,fieldID);
1405 }
1406
1407 jboolean GetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID)
1408 {
1409         return getField(obj,jboolean,fieldID);
1410 }
1411
1412
1413 jbyte GetByteField (JNIEnv *env, jobject obj, jfieldID fieldID)
1414 {
1415         return getField(obj,jbyte,fieldID);
1416 }
1417
1418
1419 jchar GetCharField (JNIEnv *env, jobject obj, jfieldID fieldID)
1420 {
1421         return getField(obj,jchar,fieldID);
1422 }
1423
1424
1425 jshort GetShortField (JNIEnv *env, jobject obj, jfieldID fieldID)
1426 {
1427         return getField(obj,jshort,fieldID);
1428 }
1429
1430
1431 jint GetIntField (JNIEnv *env, jobject obj, jfieldID fieldID)
1432 {
1433         return getField(obj,jint,fieldID);
1434 }
1435
1436
1437 jlong GetLongField (JNIEnv *env, jobject obj, jfieldID fieldID)
1438 {
1439         return getField(obj,jlong,fieldID);
1440 }
1441
1442
1443 jfloat GetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID)
1444 {
1445         return getField(obj,jfloat,fieldID);
1446 }
1447
1448
1449 jdouble GetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID)
1450 {
1451         return getField(obj,jdouble,fieldID);
1452 }
1453
1454 void SetObjectField (JNIEnv *env, jobject obj, jfieldID fieldID, jobject val)
1455 {
1456         setField(obj,jobject,fieldID,val);
1457 }
1458
1459
1460 void SetBooleanField (JNIEnv *env, jobject obj, jfieldID fieldID, jboolean val)
1461 {
1462         setField(obj,jboolean,fieldID,val);
1463 }
1464
1465
1466 void SetByteField (JNIEnv *env, jobject obj, jfieldID fieldID, jbyte val)
1467 {
1468         setField(obj,jbyte,fieldID,val);
1469 }
1470
1471
1472 void SetCharField (JNIEnv *env, jobject obj, jfieldID fieldID, jchar val)
1473 {
1474         setField(obj,jchar,fieldID,val);
1475 }
1476
1477
1478 void SetShortField (JNIEnv *env, jobject obj, jfieldID fieldID, jshort val)
1479 {
1480         setField(obj,jshort,fieldID,val);
1481 }
1482
1483
1484 void SetIntField (JNIEnv *env, jobject obj, jfieldID fieldID, jint val)
1485 {
1486         setField(obj,jint,fieldID,val);
1487 }
1488
1489
1490 void SetLongField (JNIEnv *env, jobject obj, jfieldID fieldID, jlong val)
1491 {
1492         setField(obj,jlong,fieldID,val);
1493 }
1494
1495
1496 void SetFloatField (JNIEnv *env, jobject obj, jfieldID fieldID, jfloat val)
1497 {
1498         setField(obj,jfloat,fieldID,val);
1499 }
1500
1501
1502 void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
1503 {
1504         setField(obj,jdouble,fieldID,val);
1505 }
1506
1507 /**************** JNI-functions for calling static methods **********************/ 
1508
1509 jmethodID GetStaticMethodID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
1510 {
1511         jmethodID m;
1512
1513         m = class_resolvemethod (
1514                 clazz, 
1515                 utf_new_char ((char*) name), 
1516                 utf_new_char ((char*) sig)
1517         );
1518
1519         if (!m) exceptionptr =  native_new_and_init(class_java_lang_NoSuchMethodError);  
1520
1521         return m;
1522 }
1523
1524 jobject CallStaticObjectMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1525 {
1526         log_text("JNI-Call: CallStaticObjectMethod");
1527
1528         return NULL;
1529 }
1530
1531
1532 jobject CallStaticObjectMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1533 {
1534         log_text("JNI-Call: CallStaticObjectMethodV");
1535
1536         return NULL;
1537 }
1538
1539
1540 jobject CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1541 {
1542         log_text("JNI-Call: CallStaticObjectMethodA");
1543
1544         return NULL;
1545 }
1546
1547
1548 jboolean CallStaticBooleanMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1549 {
1550         jboolean ret;
1551         va_list vaargs;
1552
1553 /*      log_text("JNI-Call: CallStaticBooleanMethod");*/
1554
1555         va_start(vaargs,methodID);
1556         ret = (jboolean)callIntegerMethod(0,methodID,'Z',vaargs);
1557         va_end(vaargs);
1558         return ret;
1559
1560 }
1561
1562
1563 jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1564 {
1565         return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
1566 }
1567
1568 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1569 {
1570         log_text("JNI-Call: CallStaticBooleanMethodA");
1571
1572         return 0;
1573 }
1574
1575
1576 jbyte CallStaticByteMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1577 {
1578         jbyte ret;
1579         va_list vaargs;
1580
1581         /*      log_text("JNI-Call: CallStaticByteMethod");*/
1582
1583         va_start(vaargs, methodID);
1584         ret = (jbyte) callIntegerMethod(0, methodID, 'B', vaargs);
1585         va_end(vaargs);
1586
1587         return ret;
1588 }
1589
1590
1591 jbyte CallStaticByteMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1592 {
1593         return (jbyte) callIntegerMethod(0, methodID, 'B', args);
1594 }
1595
1596
1597 jbyte CallStaticByteMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1598 {
1599         log_text("JNI-Call: CallStaticByteMethodA");
1600
1601         return 0;
1602 }
1603
1604
1605 jchar CallStaticCharMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1606 {
1607         jchar ret;
1608         va_list vaargs;
1609
1610         /*      log_text("JNI-Call: CallStaticByteMethod");*/
1611
1612         va_start(vaargs, methodID);
1613         ret = (jchar) callIntegerMethod(0, methodID, 'C', vaargs);
1614         va_end(vaargs);
1615
1616         return ret;
1617 }
1618
1619
1620 jchar CallStaticCharMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1621 {
1622         return (jchar) callIntegerMethod(0, methodID, 'C', args);
1623 }
1624
1625
1626 jchar CallStaticCharMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1627 {
1628         log_text("JNI-Call: CallStaticCharMethodA");
1629
1630         return 0;
1631 }
1632
1633
1634
1635 jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1636 {
1637         jshort ret;
1638         va_list vaargs;
1639
1640         /*      log_text("JNI-Call: CallStaticByteMethod");*/
1641
1642         va_start(vaargs,methodID);
1643         ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
1644         va_end(vaargs);
1645
1646         return ret;
1647 }
1648
1649
1650 jshort CallStaticShortMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1651 {
1652         /*log_text("JNI-Call: CallStaticShortMethodV");*/
1653         return (jshort) callIntegerMethod(0, methodID, 'S', args);
1654 }
1655
1656
1657 jshort CallStaticShortMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1658 {
1659         log_text("JNI-Call: CallStaticShortMethodA");
1660
1661         return 0;
1662 }
1663
1664
1665
1666 jint CallStaticIntMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1667 {
1668         jint ret;
1669         va_list vaargs;
1670
1671         /*      log_text("JNI-Call: CallStaticIntMethod");*/
1672
1673         va_start(vaargs, methodID);
1674         ret = callIntegerMethod(0, methodID, 'I', vaargs);
1675         va_end(vaargs);
1676
1677         return ret;
1678 }
1679
1680
1681 jint CallStaticIntMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1682 {
1683         log_text("JNI-Call: CallStaticIntMethodV");
1684
1685         return callIntegerMethod(0, methodID, 'I', args);
1686 }
1687
1688
1689 jint CallStaticIntMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1690 {
1691         log_text("JNI-Call: CallStaticIntMethodA");
1692
1693         return 0;
1694 }
1695
1696
1697
1698 jlong CallStaticLongMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1699 {
1700         jlong ret;
1701         va_list vaargs;
1702
1703         /*      log_text("JNI-Call: CallStaticLongMethod");*/
1704
1705         va_start(vaargs, methodID);
1706         ret = callLongMethod(0, methodID, vaargs);
1707         va_end(vaargs);
1708
1709         return ret;
1710 }
1711
1712
1713 jlong CallStaticLongMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1714 {
1715         log_text("JNI-Call: CallStaticLongMethodV");
1716         
1717         return callLongMethod(0,methodID,args);
1718 }
1719
1720
1721 jlong CallStaticLongMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1722 {
1723         log_text("JNI-Call: CallStaticLongMethodA");
1724
1725         return 0;
1726 }
1727
1728
1729
1730 jfloat CallStaticFloatMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1731 {
1732         jfloat ret;
1733         va_list vaargs;
1734
1735         /*      log_text("JNI-Call: CallStaticLongMethod");*/
1736
1737         va_start(vaargs, methodID);
1738         ret = callFloatMethod(0, methodID, vaargs, 'F');
1739         va_end(vaargs);
1740
1741         return ret;
1742 }
1743
1744
1745 jfloat CallStaticFloatMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1746 {
1747
1748         return callFloatMethod(0, methodID, args, 'F');
1749
1750 }
1751
1752
1753 jfloat CallStaticFloatMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1754 {
1755         log_text("JNI-Call: CallStaticFloatMethodA");
1756
1757         return 0;
1758 }
1759
1760
1761
1762 jdouble CallStaticDoubleMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
1763 {
1764         jdouble ret;
1765         va_list vaargs;
1766
1767         /*      log_text("JNI-Call: CallStaticDoubleMethod");*/
1768
1769         va_start(vaargs,methodID);
1770         ret = callFloatMethod(0, methodID, vaargs, 'D');
1771         va_end(vaargs);
1772
1773         return ret;
1774 }
1775
1776
1777 jdouble CallStaticDoubleMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
1778 {
1779         log_text("JNI-Call: CallStaticDoubleMethodV");
1780
1781         return callFloatMethod(0, methodID, args, 'D');
1782 }
1783
1784
1785 jdouble CallStaticDoubleMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
1786 {
1787         log_text("JNI-Call: CallStaticDoubleMethodA");
1788
1789         return 0;
1790 }
1791
1792
1793 void CallStaticVoidMethod(JNIEnv *env, jclass cls, jmethodID methodID, ...)
1794 {
1795         va_list vaargs;
1796
1797 /*      log_text("JNI-Call: CallStaticVoidMethod");*/
1798
1799         va_start(vaargs, methodID);
1800         (void) callIntegerMethod(0, methodID, 'V', vaargs);
1801         va_end(vaargs);
1802 }
1803
1804
1805 void CallStaticVoidMethodV(JNIEnv *env, jclass cls, jmethodID methodID, va_list args)
1806 {
1807         log_text("JNI-Call: CallStaticVoidMethodV");
1808         (void)callIntegerMethod(0, methodID, 'V', args);
1809 }
1810
1811
1812 void CallStaticVoidMethodA(JNIEnv *env, jclass cls, jmethodID methodID, jvalue * args)
1813 {
1814         log_text("JNI-Call: CallStaticVoidMethodA");
1815 }
1816
1817
1818 /****************** JNI-functions for accessing static fields ********************/
1819
1820 jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const char *sig) 
1821 {
1822         jfieldID f;
1823
1824         f = jclass_findfield(clazz,
1825                             utf_new_char ((char*) name), 
1826                             utf_new_char ((char*) sig)
1827                             ); 
1828         
1829         if (!f) exceptionptr =  native_new_and_init(class_java_lang_NoSuchFieldError);  
1830
1831         return f;
1832 }
1833
1834
1835 jobject GetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1836 {
1837         class_init(clazz);
1838         return fieldID->value.a;       
1839 }
1840
1841
1842 jboolean GetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1843 {
1844         class_init(clazz);
1845         return fieldID->value.i;       
1846 }
1847
1848
1849 jbyte GetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1850 {
1851         class_init(clazz);
1852         return fieldID->value.i;       
1853 }
1854
1855
1856 jchar GetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1857 {
1858         class_init(clazz);
1859         return fieldID->value.i;       
1860 }
1861
1862
1863 jshort GetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1864 {
1865         class_init(clazz);
1866         return fieldID->value.i;       
1867 }
1868
1869
1870 jint GetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1871 {
1872         class_init(clazz);
1873         return fieldID->value.i;       
1874 }
1875
1876
1877 jlong GetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1878 {
1879         class_init(clazz);
1880         return fieldID->value.l;
1881 }
1882
1883
1884 jfloat GetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1885 {
1886         class_init(clazz);
1887         return fieldID->value.f;
1888 }
1889
1890
1891 jdouble GetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID)
1892 {
1893         class_init(clazz);
1894         return fieldID->value.d;
1895 }
1896
1897
1898
1899 void SetStaticObjectField (JNIEnv *env, jclass clazz, jfieldID fieldID, jobject value)
1900 {
1901         class_init(clazz);
1902         fieldID->value.a = value;
1903 }
1904
1905
1906 void SetStaticBooleanField (JNIEnv *env, jclass clazz, jfieldID fieldID, jboolean value)
1907 {
1908         class_init(clazz);
1909         fieldID->value.i = value;
1910 }
1911
1912
1913 void SetStaticByteField (JNIEnv *env, jclass clazz, jfieldID fieldID, jbyte value)
1914 {
1915         class_init(clazz);
1916         fieldID->value.i = value;
1917 }
1918
1919
1920 void SetStaticCharField (JNIEnv *env, jclass clazz, jfieldID fieldID, jchar value)
1921 {
1922         class_init(clazz);
1923         fieldID->value.i = value;
1924 }
1925
1926
1927 void SetStaticShortField (JNIEnv *env, jclass clazz, jfieldID fieldID, jshort value)
1928 {
1929         class_init(clazz);
1930         fieldID->value.i = value;
1931 }
1932
1933
1934 void SetStaticIntField (JNIEnv *env, jclass clazz, jfieldID fieldID, jint value)
1935 {
1936         class_init(clazz);
1937         fieldID->value.i = value;
1938 }
1939
1940
1941 void SetStaticLongField (JNIEnv *env, jclass clazz, jfieldID fieldID, jlong value)
1942 {
1943         class_init(clazz);
1944         fieldID->value.l = value;
1945 }
1946
1947
1948 void SetStaticFloatField (JNIEnv *env, jclass clazz, jfieldID fieldID, jfloat value)
1949 {
1950         class_init(clazz);
1951         fieldID->value.f = value;
1952 }
1953
1954
1955 void SetStaticDoubleField (JNIEnv *env, jclass clazz, jfieldID fieldID, jdouble value)
1956 {
1957         class_init(clazz);
1958         fieldID->value.d = value;
1959 }
1960
1961
1962 /*****  create new java.lang.String object from an array of Unicode characters ****/ 
1963
1964 jstring NewString (JNIEnv *env, const jchar *buf, jsize len)
1965 {
1966         u4 i;
1967         java_lang_String *s;
1968         java_chararray *a;
1969         
1970         s = (java_lang_String*) builtin_new (class_java_lang_String);
1971         a = builtin_newarray_char (len);
1972
1973         /* javastring or characterarray could not be created */
1974         if ( (!a) || (!s) ) return NULL;
1975
1976         /* copy text */
1977         for (i=0; i<len; i++) a->data[i] = buf[i];
1978         s -> value = a;
1979         s -> offset = 0;
1980         s -> count = len;
1981
1982         return (jstring) s;
1983 }
1984
1985
1986 static char emptyString[]="";
1987
1988 /******************* returns the length of a Java string ***************************/
1989
1990 jsize GetStringLength (JNIEnv *env, jstring str)
1991 {
1992         return ((java_lang_String*) str)->count;
1993 }
1994
1995
1996 /********************  convertes javastring to u2-array ****************************/
1997         
1998 u2 *javastring_tou2 (jstring so) 
1999 {
2000         java_lang_String *s = (java_lang_String*) so;
2001         java_chararray *a;
2002         u4 i;
2003         u2 *stringbuffer;
2004         
2005         if (!s) return NULL;
2006
2007         a = s->value;
2008         if (!a) return NULL;
2009
2010         /* allocate memory */
2011         stringbuffer = MNEW( u2 , s->count + 1 );
2012
2013         /* copy text */
2014         for (i=0; i<s->count; i++) stringbuffer[i] = a->data[s->offset+i];
2015         
2016         /* terminate string */
2017         stringbuffer[i] = '\0';
2018
2019         return stringbuffer;
2020 }
2021
2022 /********* returns a pointer to an array of Unicode characters of the string *******/
2023
2024 const jchar *GetStringChars (JNIEnv *env, jstring str, jboolean *isCopy)
2025 {       
2026         jchar *jc=javastring_tou2(str);
2027
2028         if (jc) {
2029                 if (isCopy) *isCopy=JNI_TRUE;
2030                 return jc;
2031         }
2032         if (isCopy) *isCopy=JNI_TRUE;
2033         return emptyString;
2034 }
2035
2036 /**************** native code no longer needs access to chars **********************/
2037
2038 void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
2039 {
2040         if (chars==emptyString) return;
2041         MFREE(((jchar*) chars),jchar,((java_lang_String*) str)->count+1);
2042 }
2043
2044 /************ create new java.lang.String object from utf8-characterarray **********/
2045
2046 jstring NewStringUTF (JNIEnv *env, const char *utf)
2047 {
2048 /*    log_text("NewStringUTF called");*/
2049     return javastring_new(utf_new_char(utf));
2050 }
2051
2052 /****************** returns the utf8 length in bytes of a string *******************/
2053
2054 jsize GetStringUTFLength (JNIEnv *env, jstring string)
2055 {   
2056     java_lang_String *s = (java_lang_String*) string;
2057
2058     return (jsize) u2_utflength(s->value->data, s->count); 
2059 }
2060
2061 /************ converts a Javastring to an array of UTF-8 characters ****************/
2062
2063 const char* GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
2064 {
2065     utf *u;
2066     if (verbose) log_text("GetStringUTFChars:");
2067
2068     u=javastring_toutf((java_lang_String*) string,false);
2069     if (isCopy) *isCopy=JNI_FALSE;
2070     if (u) {
2071         return u->text;
2072     }
2073     return emptyString;
2074         
2075 }
2076
2077 /***************** native code no longer needs access to utf ***********************/
2078
2079 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
2080 {
2081     /*we don't release utf chars right now, perhaps that should be done later. Since there is always one reference
2082         the garbage collector will never get them*/
2083         /*
2084     log_text("JNI-Call: ReleaseStringUTFChars");
2085     utf_display(utf_new_char(chars));
2086         */
2087 }
2088
2089 /************************** array operations ***************************************/
2090
2091 jsize GetArrayLength (JNIEnv *env, jarray array)
2092 {
2093     return array->size;
2094 }
2095
2096 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
2097 {
2098     java_objectarray *j = builtin_anewarray (len, clazz);
2099     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2100     return j;
2101 }
2102
2103 jobject GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
2104 {
2105     jobject j = NULL;
2106
2107     if (index<array->header.size)       
2108         j = array->data[index];
2109     else
2110         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2111     
2112     return j;
2113 }
2114
2115 void SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobject val)
2116 {
2117     if (index>=array->header.size)      
2118         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2119     else {
2120
2121         /* check if the class of value is a subclass of the element class of the array */
2122
2123                 if (!builtin_canstore((java_objectarray*)array,(java_objectheader*)val))
2124                         exceptionptr = proto_java_lang_ArrayStoreException;
2125                 else
2126                         array->data[index] = val;
2127     }
2128 }
2129
2130
2131
2132 jbooleanArray NewBooleanArray (JNIEnv *env, jsize len)
2133 {
2134     java_booleanarray *j = builtin_newarray_boolean(len);
2135     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2136     return j;
2137 }
2138
2139
2140 jbyteArray NewByteArray (JNIEnv *env, jsize len)
2141 {
2142     java_bytearray *j = builtin_newarray_byte(len);
2143     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2144     return j;
2145 }
2146
2147
2148 jcharArray NewCharArray (JNIEnv *env, jsize len)
2149 {
2150     java_chararray *j = builtin_newarray_char(len);
2151     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2152     return j;
2153 }
2154
2155
2156 jshortArray NewShortArray (JNIEnv *env, jsize len)
2157 {
2158     java_shortarray *j = builtin_newarray_short(len);   
2159     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2160     return j;
2161 }
2162
2163
2164 jintArray NewIntArray (JNIEnv *env, jsize len)
2165 {
2166     java_intarray *j = builtin_newarray_int(len);
2167     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2168     return j;
2169 }
2170
2171
2172 jlongArray NewLongArray (JNIEnv *env, jsize len)
2173 {
2174     java_longarray *j = builtin_newarray_long(len);
2175     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2176     return j;
2177 }
2178
2179
2180 jfloatArray NewFloatArray (JNIEnv *env, jsize len)
2181 {
2182     java_floatarray *j = builtin_newarray_float(len);
2183     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2184     return j;
2185 }
2186
2187
2188 jdoubleArray NewDoubleArray (JNIEnv *env, jsize len)
2189 {
2190     java_doublearray *j = builtin_newarray_double(len);
2191     if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
2192     return j;
2193 }
2194
2195
2196 jboolean * GetBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *isCopy)
2197 {
2198     if (isCopy) *isCopy = JNI_FALSE;
2199     return array->data;
2200 }
2201
2202
2203 jbyte * GetByteArrayElements (JNIEnv *env, jbyteArray array, jboolean *isCopy)
2204 {
2205     if (isCopy) *isCopy = JNI_FALSE;
2206     return array->data;
2207 }
2208
2209
2210 jchar * GetCharArrayElements (JNIEnv *env, jcharArray array, jboolean *isCopy)
2211 {
2212     if (isCopy) *isCopy = JNI_FALSE;
2213     return array->data;
2214 }
2215
2216
2217 jshort * GetShortArrayElements (JNIEnv *env, jshortArray array, jboolean *isCopy)
2218 {
2219     if (isCopy) *isCopy = JNI_FALSE;
2220     return array->data;
2221 }
2222
2223
2224 jint * GetIntArrayElements (JNIEnv *env, jintArray array, jboolean *isCopy)
2225 {
2226     if (isCopy) *isCopy = JNI_FALSE;
2227     return array->data;
2228 }
2229
2230
2231 jlong * GetLongArrayElements (JNIEnv *env, jlongArray array, jboolean *isCopy)
2232 {
2233     if (isCopy) *isCopy = JNI_FALSE;
2234     return array->data;
2235 }
2236
2237
2238 jfloat * GetFloatArrayElements (JNIEnv *env, jfloatArray array, jboolean *isCopy)
2239 {
2240     if (isCopy) *isCopy = JNI_FALSE;
2241     return array->data;
2242 }
2243
2244
2245 jdouble * GetDoubleArrayElements (JNIEnv *env, jdoubleArray array, jboolean *isCopy)
2246 {
2247     if (isCopy) *isCopy = JNI_FALSE;
2248     return array->data;
2249 }
2250
2251
2252
2253 void ReleaseBooleanArrayElements (JNIEnv *env, jbooleanArray array, jboolean *elems, jint mode)
2254 {
2255     /* empty */
2256 }
2257
2258
2259 void ReleaseByteArrayElements (JNIEnv *env, jbyteArray array, jbyte *elems, jint mode)
2260 {
2261     /* empty */
2262 }
2263
2264
2265 void ReleaseCharArrayElements (JNIEnv *env, jcharArray array, jchar *elems, jint mode)
2266 {
2267     /* empty */
2268 }
2269
2270
2271 void ReleaseShortArrayElements (JNIEnv *env, jshortArray array, jshort *elems, jint mode)
2272 {
2273     /* empty */
2274 }
2275
2276
2277 void ReleaseIntArrayElements (JNIEnv *env, jintArray array, jint *elems, jint mode)
2278 {
2279     /* empty */
2280 }
2281
2282
2283 void ReleaseLongArrayElements (JNIEnv *env, jlongArray array, jlong *elems, jint mode)
2284 {
2285     /* empty */
2286 }
2287
2288
2289 void ReleaseFloatArrayElements (JNIEnv *env, jfloatArray array, jfloat *elems, jint mode)
2290 {
2291     /* empty */
2292 }
2293
2294
2295 void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems, jint mode)
2296 {
2297     /* empty */
2298 }
2299
2300 void GetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2301 {
2302     if (start<0 || len<0 || start+len>array->header.size)
2303         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2304     else
2305         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2306 }
2307
2308
2309 void GetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2310 {
2311     if (start<0 || len<0 || start+len>array->header.size) 
2312         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2313     else
2314         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
2315 }
2316
2317
2318 void GetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2319 {
2320     if (start<0 || len<0 || start+len>array->header.size)
2321         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2322     else
2323         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2324 }
2325
2326
2327 void GetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2328 {
2329     if (start<0 || len<0 || start+len>array->header.size)
2330         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2331     else        
2332         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2333 }
2334
2335
2336 void GetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2337 {
2338     if (start<0 || len<0 || start+len>array->header.size)       
2339         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2340     else
2341         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2342 }
2343
2344
2345 void GetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2346 {
2347     if (start<0 || len<0 || start+len>array->header.size)       
2348         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2349     else
2350         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2351 }
2352
2353
2354 void GetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2355 {
2356     if (start<0 || len<0 || start+len>array->header.size)       
2357         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2358     else
2359         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2360 }
2361
2362
2363 void GetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2364 {
2365     if (start<0 || len<0 || start+len>array->header.size) 
2366         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2367     else
2368         memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
2369 }
2370
2371
2372 void SetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
2373 {
2374     if (start<0 || len<0 || start+len>array->header.size)
2375         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2376     else
2377         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2378 }
2379
2380
2381 void SetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
2382 {
2383     if (start<0 || len<0 || start+len>array->header.size)
2384         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2385     else
2386         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2387 }
2388
2389
2390 void SetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
2391 {
2392     if (start<0 || len<0 || start+len>array->header.size)
2393         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2394     else
2395         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2396
2397 }
2398
2399
2400 void SetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
2401 {
2402     if (start<0 || len<0 || start+len>array->header.size)
2403         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2404     else
2405         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2406 }
2407
2408
2409 void SetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
2410 {
2411     if (start<0 || len<0 || start+len>array->header.size)
2412         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2413     else
2414         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2415
2416 }
2417
2418 void SetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
2419 {
2420     if (start<0 || len<0 || start+len>array->header.size)
2421         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2422     else
2423         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2424
2425 }
2426
2427 void SetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
2428 {
2429     if (start<0 || len<0 || start+len>array->header.size)
2430         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2431     else
2432         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2433
2434 }
2435
2436 void SetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
2437 {
2438     if (start<0 || len<0 || start+len>array->header.size)
2439         exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
2440     else
2441         memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
2442 }
2443
2444 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
2445 {
2446     log_text("JNI-Call: RegisterNatives");
2447     return 0;
2448 }
2449
2450
2451 jint UnregisterNatives (JNIEnv* env, jclass clazz)
2452 {
2453     log_text("JNI-Call: UnregisterNatives");
2454     return 0;
2455 }
2456
2457 /******************************* monitor operations ********************************/
2458
2459 jint MonitorEnter (JNIEnv* env, jobject obj)
2460 {
2461     builtin_monitorenter(obj);
2462     return 0;
2463 }
2464
2465
2466 jint MonitorExit (JNIEnv* env, jobject obj)
2467 {
2468     builtin_monitorexit(obj);
2469     return 0;
2470 }
2471
2472
2473 /************************************* JavaVM interface ****************************/
2474 #ifdef __cplusplus
2475 #error CPP mode not supported yet
2476 #else
2477 jint GetJavaVM (JNIEnv* env, JavaVM **vm)
2478 {
2479     log_text("JNI-Call: GetJavaVM");
2480     *vm=&javaVM;
2481     return 0;
2482 }
2483 #endif /*__cplusplus*/
2484
2485 void GetStringRegion (JNIEnv* env, jstring str, jsize start, jsize len, jchar *buf)
2486 {
2487     log_text("JNI-Call: GetStringRegion");
2488
2489 }
2490
2491 void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char *buf)
2492 {
2493     log_text("JNI-Call: GetStringUTFRegion");
2494
2495 }
2496
2497 /****************** obtain direct pointer to array elements ***********************/
2498
2499 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
2500 {
2501         java_objectheader *s = (java_objectheader*) array;
2502         arraydescriptor *desc = s->vftbl->arraydesc;
2503
2504         if (!desc) return NULL;
2505
2506         return ((u1*)s) + desc->dataoffset;
2507 }
2508
2509
2510 void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jint mode)
2511 {
2512         log_text("JNI-Call: ReleasePrimitiveArrayCritical");
2513
2514         /* empty */
2515 }
2516
2517 /********* returns a pointer to an array of Unicode characters of the string *******/
2518
2519 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
2520 {
2521         log_text("JNI-Call: GetStringCritical");
2522
2523         return GetStringChars(env,string,isCopy);
2524 }
2525
2526 /**************** native code no longer needs access to chars **********************/
2527
2528 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
2529 {
2530         log_text("JNI-Call: ReleaseStringCritical");
2531
2532         ReleaseStringChars(env,string,cstring);
2533 }
2534
2535
2536 jweak NewWeakGlobalRef (JNIEnv* env, jobject obj)
2537 {
2538         log_text("JNI-Call: NewWeakGlobalRef");
2539
2540         return obj;
2541 }
2542
2543
2544 void DeleteWeakGlobalRef (JNIEnv* env, jweak ref)
2545 {
2546         log_text("JNI-Call: DeleteWeakGlobalRef");
2547
2548         /* empty */
2549 }
2550
2551
2552 /******************************* check for pending exception ***********************/
2553
2554
2555 jboolean ExceptionCheck(JNIEnv* env)
2556 {
2557         log_text("JNI-Call: ExceptionCheck");
2558
2559         return exceptionptr ? JNI_TRUE : JNI_FALSE;
2560 }
2561
2562
2563
2564
2565
2566
2567 jint DestroyJavaVM(JavaVM *vm)
2568 {
2569         log_text("DestroyJavaVM called");
2570
2571         return 0;
2572 }
2573
2574
2575 jint AttachCurrentThread(JavaVM *vm, void **par1, void *par2)
2576 {
2577         log_text("AttachCurrentThread called");
2578
2579         return 0;
2580 }
2581
2582
2583 jint DetachCurrentThread(JavaVM *vm)
2584 {
2585         log_text("DetachCurrentThread called");
2586
2587         return 0;
2588 }
2589
2590
2591 jint GetEnv(JavaVM *vm, void **environment, jint jniversion)
2592 {
2593         *environment = &env;
2594
2595         return 0;
2596 }
2597
2598
2599 jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
2600 {
2601         log_text("AttachCurrentThreadAsDaemon called");
2602
2603         return 0;
2604 }
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616 /********************************* JNI invocation table ******************************/
2617
2618 struct _JavaVM javaVMTable={
2619    NULL,
2620    NULL,
2621    NULL,
2622    &DestroyJavaVM,
2623    &AttachCurrentThread,
2624    &DetachCurrentThread,
2625    &GetEnv,
2626    &AttachCurrentThreadAsDaemon
2627 };
2628
2629 JavaVM javaVM = &javaVMTable;
2630
2631
2632 /********************************* JNI function table ******************************/
2633
2634 struct JNI_Table envTable = {   
2635     NULL,
2636     NULL,
2637     NULL,
2638     NULL,    
2639     &GetVersion,
2640     &DefineClass,
2641     &FindClass,
2642     &FromReflectedMethod,
2643     &FromReflectedField,
2644     &ToReflectedMethod,
2645     &GetSuperclass,
2646     &IsAssignableForm,
2647     &ToReflectedField,
2648     &Throw,
2649     &ThrowNew,
2650     &ExceptionOccurred,
2651     &ExceptionDescribe,
2652     &ExceptionClear,
2653     &FatalError,
2654     &PushLocalFrame,
2655     &PopLocalFrame,
2656     &NewGlobalRef,
2657     &DeleteGlobalRef,
2658     &DeleteLocalRef,
2659     &IsSameObject,
2660     &NewLocalRef,
2661     &EnsureLocalCapacity,
2662     &AllocObject,
2663     &NewObject,
2664     &NewObjectV,
2665     &NewObjectA,
2666     &GetObjectClass,
2667     &IsInstanceOf,
2668     &GetMethodID,
2669     &CallObjectMethod,
2670     &CallObjectMethodV,
2671     &CallObjectMethodA,
2672     &CallBooleanMethod,
2673     &CallBooleanMethodV,
2674     &CallBooleanMethodA,
2675     &CallByteMethod,
2676     &CallByteMethodV,
2677     &CallByteMethodA,
2678     &CallCharMethod,
2679     &CallCharMethodV,
2680     &CallCharMethodA,
2681     &CallShortMethod,
2682     &CallShortMethodV,
2683     &CallShortMethodA,
2684     &CallIntMethod,
2685     &CallIntMethodV,
2686     &CallIntMethodA,
2687     &CallLongMethod,
2688     &CallLongMethodV,
2689     &CallLongMethodA,
2690     &CallFloatMethod,
2691     &CallFloatMethodV,
2692     &CallFloatMethodA,
2693     &CallDoubleMethod,
2694     &CallDoubleMethodV,
2695     &CallDoubleMethodA,
2696     &CallVoidMethod,
2697     &CallVoidMethodV,
2698     &CallVoidMethodA,
2699     &CallNonvirtualObjectMethod,
2700     &CallNonvirtualObjectMethodV,
2701     &CallNonvirtualObjectMethodA,
2702     &CallNonvirtualBooleanMethod,
2703     &CallNonvirtualBooleanMethodV,
2704     &CallNonvirtualBooleanMethodA,
2705     &CallNonvirtualByteMethod,
2706     &CallNonvirtualByteMethodV,
2707     &CallNonvirtualByteMethodA,
2708     &CallNonvirtualCharMethod,
2709     &CallNonvirtualCharMethodV,
2710     &CallNonvirtualCharMethodA,
2711     &CallNonvirtualShortMethod,
2712     &CallNonvirtualShortMethodV,
2713     &CallNonvirtualShortMethodA,
2714     &CallNonvirtualIntMethod,
2715     &CallNonvirtualIntMethodV,
2716     &CallNonvirtualIntMethodA,
2717     &CallNonvirtualLongMethod,
2718     &CallNonvirtualLongMethodV,
2719     &CallNonvirtualLongMethodA,
2720     &CallNonvirtualFloatMethod,
2721     &CallNonvirtualFloatMethodV,
2722     &CallNonvirtualFloatMethodA,
2723     &CallNonvirtualDoubleMethod,
2724     &CallNonvirtualDoubleMethodV,
2725     &CallNonvirtualDoubleMethodA,
2726     &CallNonvirtualVoidMethod,
2727     &CallNonvirtualVoidMethodV,
2728     &CallNonvirtualVoidMethodA,
2729     &GetFieldID,
2730     &GetObjectField,
2731     &GetBooleanField,
2732     &GetByteField,
2733     &GetCharField,
2734     &GetShortField,
2735     &GetIntField,
2736     &GetLongField,
2737     &GetFloatField,
2738     &GetDoubleField,
2739     &SetObjectField,
2740     &SetBooleanField,
2741     &SetByteField,
2742     &SetCharField,
2743     &SetShortField,
2744     &SetIntField,
2745     &SetLongField,
2746     &SetFloatField,
2747     &SetDoubleField,
2748     &GetStaticMethodID,
2749     &CallStaticObjectMethod,
2750     &CallStaticObjectMethodV,
2751     &CallStaticObjectMethodA,
2752     &CallStaticBooleanMethod,
2753     &CallStaticBooleanMethodV,
2754     &CallStaticBooleanMethodA,
2755     &CallStaticByteMethod,
2756     &CallStaticByteMethodV,
2757     &CallStaticByteMethodA,
2758     &CallStaticCharMethod,
2759     &CallStaticCharMethodV,
2760     &CallStaticCharMethodA,
2761     &CallStaticShortMethod,
2762     &CallStaticShortMethodV,
2763     &CallStaticShortMethodA,
2764     &CallStaticIntMethod,
2765     &CallStaticIntMethodV,
2766     &CallStaticIntMethodA,
2767     &CallStaticLongMethod,
2768     &CallStaticLongMethodV,
2769     &CallStaticLongMethodA,
2770     &CallStaticFloatMethod,
2771     &CallStaticFloatMethodV,
2772     &CallStaticFloatMethodA,
2773     &CallStaticDoubleMethod,
2774     &CallStaticDoubleMethodV,
2775     &CallStaticDoubleMethodA,
2776     &CallStaticVoidMethod,
2777     &CallStaticVoidMethodV,
2778     &CallStaticVoidMethodA,
2779     &GetStaticFieldID,
2780     &GetStaticObjectField,
2781     &GetStaticBooleanField,
2782     &GetStaticByteField,
2783     &GetStaticCharField,
2784     &GetStaticShortField,
2785     &GetStaticIntField,
2786     &GetStaticLongField,
2787     &GetStaticFloatField,
2788     &GetStaticDoubleField,
2789     &SetStaticObjectField,
2790     &SetStaticBooleanField,
2791     &SetStaticByteField,
2792     &SetStaticCharField,
2793     &SetStaticShortField,
2794     &SetStaticIntField,
2795     &SetStaticLongField,
2796     &SetStaticFloatField,
2797     &SetStaticDoubleField,
2798     &NewString,
2799     &GetStringLength,
2800     &GetStringChars,
2801     &ReleaseStringChars,
2802     &NewStringUTF,
2803     &GetStringUTFLength,
2804     &GetStringUTFChars,
2805     &ReleaseStringUTFChars,
2806     &GetArrayLength,
2807     &NewObjectArray,
2808     &GetObjectArrayElement,
2809     &SetObjectArrayElement,
2810     &NewBooleanArray,
2811     &NewByteArray,
2812     &NewCharArray,
2813     &NewShortArray,
2814     &NewIntArray,
2815     &NewLongArray,
2816     &NewFloatArray,
2817     &NewDoubleArray,
2818     &GetBooleanArrayElements,
2819     &GetByteArrayElements,
2820     &GetCharArrayElements,
2821     &GetShortArrayElements,
2822     &GetIntArrayElements,
2823     &GetLongArrayElements,
2824     &GetFloatArrayElements,
2825     &GetDoubleArrayElements,
2826     &ReleaseBooleanArrayElements,
2827     &ReleaseByteArrayElements,
2828     &ReleaseCharArrayElements,
2829     &ReleaseShortArrayElements,
2830     &ReleaseIntArrayElements,
2831     &ReleaseLongArrayElements,
2832     &ReleaseFloatArrayElements,
2833     &ReleaseDoubleArrayElements,
2834     &GetBooleanArrayRegion,
2835     &GetByteArrayRegion,
2836     &GetCharArrayRegion,
2837     &GetShortArrayRegion,
2838     &GetIntArrayRegion,
2839     &GetLongArrayRegion,
2840     &GetFloatArrayRegion,
2841     &GetDoubleArrayRegion,
2842     &SetBooleanArrayRegion,
2843     &SetByteArrayRegion,
2844     &SetCharArrayRegion,
2845     &SetShortArrayRegion,
2846     &SetIntArrayRegion,
2847     &SetLongArrayRegion,
2848     &SetFloatArrayRegion,
2849     &SetDoubleArrayRegion,
2850     &RegisterNatives,
2851     &UnregisterNatives,
2852     &MonitorEnter,
2853     &MonitorExit,
2854     &GetJavaVM,
2855     &GetStringRegion,
2856     &GetStringUTFRegion,
2857     &GetPrimitiveArrayCritical,
2858     &ReleasePrimitiveArrayCritical,
2859     &GetStringCritical,
2860     &ReleaseStringCritical,
2861     &NewWeakGlobalRef,
2862     &DeleteWeakGlobalRef,
2863     &ExceptionCheck
2864 };
2865
2866
2867 JNIEnv env = &envTable;
2868
2869
2870 /*
2871  * These are local overrides for various environment variables in Emacs.
2872  * Please do not remove this and leave it at the end of the file, where
2873  * Emacs will automagically detect them.
2874  * ---------------------------------------------------------------------
2875  * Local variables:
2876  * mode: c
2877  * indent-tabs-mode: t
2878  * c-basic-offset: 4
2879  * tab-width: 4
2880  * End:
2881  */