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