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