x86_64 include added
[cacao.git] / jni.c
diff --git a/jni.c b/jni.c
index b0b167ff2ab0725d7c233afecbb704ed24deb233..265a28a8c9c01c4ec6ba15b9347703c461285667 100644 (file)
--- a/jni.c
+++ b/jni.c
@@ -1,17 +1,52 @@
-/********************************** jni.c *****************************************
+/* jni.c - implementation of the Java Native Interface functions
 
 
-       implementation of the Java Native Interface functions                             
-       which are used in the JNI function table                                         
+   Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+   R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
+   M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
+   P. Tomsich, J. Wenninger, M. Platter
 
 
-***********************************************************************************/
+   This file is part of CACAO.
+
+   This program is free software; you can redistribute it and/or
+   modify it under the terms of the GNU General Public License as
+   published by the Free Software Foundation; either version 2, or (at
+   your option) any later version.
+
+   This program is distributed in the hope that it will be useful, but
+   WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software
+   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+   02111-1307, USA.
+
+   Contact: cacao@complang.tuwien.ac.at
+
+   Authors: ?
 
 
+   Changes: Joseph Wenninger, Martin Platter
+
+   $Id: jni.c 1384 2004-08-02 11:41:26Z motse $
+
+*/
+
+
+#include <string.h>
+#include "exceptions.h"
+#include "main.h"
 #include "jni.h"
 #include "global.h"
 #include "loader.h"
 #include "tables.h"
 #include "native.h"
 #include "builtin.h"
 #include "jni.h"
 #include "global.h"
 #include "loader.h"
 #include "tables.h"
 #include "native.h"
 #include "builtin.h"
+#include "options.h"
+#include "statistics.h"
 #include "threads/thread.h"
 #include "threads/thread.h"
+#include "toolbox/logging.h"
+#include "toolbox/memory.h"
 #include "nat/java_lang_Byte.h"
 #include "nat/java_lang_Character.h"
 #include "nat/java_lang_Short.h"
 #include "nat/java_lang_Byte.h"
 #include "nat/java_lang_Character.h"
 #include "nat/java_lang_Short.h"
 #define JNI_VERSION       0x00010002
 
 
 #define JNI_VERSION       0x00010002
 
 
-static utf* utf_char=0;
-static utf* utf_bool=0;
-static utf* utf_byte=0;
-static utf* utf_short=0;
-static utf* utf_int=0;
-static utf* utf_long=0;
-static utf* utf_float=0;
-static utf* utf_double=0;
+#define PTR_TO_ITEM(ptr)   ((u8)(size_t)(ptr))
+
+static utf* utf_char = 0;
+static utf* utf_bool = 0;
+static utf* utf_byte  =0;
+static utf* utf_short = 0;
+static utf* utf_int = 0;
+static utf* utf_long = 0;
+static utf* utf_float = 0;
+static utf* utf_double = 0;
+
 
 /********************* accessing instance-fields **********************************/
 
 
 /********************* accessing instance-fields **********************************/
 
@@ -45,38 +83,34 @@ static utf* utf_double=0;
 
 u4 get_parametercount(methodinfo *m)
 {
 
 u4 get_parametercount(methodinfo *m)
 {
-    utf  *descr    =  m->descriptor;    /* method-descriptor */
-    char *utf_ptr  =  descr->text;      /* current position in utf-text */
-    char *desc_end =  utf_end(descr);   /* points behind utf string     */
-    java_objectarray* result;
-    int parametercount = 0;
-   int i;
+       utf  *descr    =  m->descriptor;    /* method-descriptor */
+       char *utf_ptr  =  descr->text;      /* current position in utf-text */
+       char *desc_end =  utf_end(descr);   /* points behind utf string     */
+       u4 parametercount = 0;
 
 
-    /* skip '(' */
-    utf_nextu2(&utf_ptr);
+       /* skip '(' */
+       utf_nextu2(&utf_ptr);
 
     /* determine number of parameters */
 
     /* determine number of parameters */
-    while ( *utf_ptr != ')' ) {
-        get_type(&utf_ptr,desc_end,true);
-        parametercount++;
-    }
+       while (*utf_ptr != ')') {
+               get_type(&utf_ptr, desc_end, true);
+               parametercount++;
+       }
 
 
-    return parametercount;
+       return parametercount;
 }
 
 
 
 }
 
 
 
-void fill_callblock(void *obj,utf *descr,jni_callblock blk[], va_list data, char ret) {
-    char *utf__ptr  =  descr->text;      /* current position in utf-text */
-    char **utf_ptr  =  &utf__ptr;
-    char *desc_end =  utf_end(descr);   /* points behind utf string     */
-
+void fill_callblock(void *obj, utf *descr, jni_callblock blk[], va_list data, char ret)
+{
+    char *utf__ptr = descr->text;      /* current position in utf-text */
+    char **utf_ptr = &utf__ptr;
+    char *desc_end = utf_end(descr);   /* points behind utf string     */
     int cnt;
     int cnt;
-
-    jdouble d;
-    jlong l;
     u4 dummy;
     char c;
     u4 dummy;
     char c;
+
        /*
     log_text("fill_callblock");
     utf_display(descr);
        /*
     log_text("fill_callblock");
     utf_display(descr);
@@ -86,98 +120,105 @@ void fill_callblock(void *obj,utf *descr,jni_callblock blk[], va_list data, char
     utf_nextu2(utf_ptr);
 
     /* determine number of parameters */
     utf_nextu2(utf_ptr);
 
     /* determine number of parameters */
-   if (obj) {
-          blk[0].itemtype=TYPE_ADR;
-          blk[0].item=(u8)(u4)obj;
-          cnt=1;
-   } else cnt=0;
-   while ( **utf_ptr != ')' ) {
-       if (*utf_ptr>=desc_end)
+       if (obj) {
+               blk[0].itemtype = TYPE_ADR;
+               blk[0].item = PTR_TO_ITEM(obj);
+               cnt = 1;
+       } else cnt = 0;
+
+       while (**utf_ptr != ')') {
+               if (*utf_ptr >= desc_end)
                panic("illegal method descriptor");
 
                panic("illegal method descriptor");
 
-       switch (utf_nextu2(utf_ptr)) {
-       /* primitive types */
-             case 'B' :
-             case 'C' :
-             case 'S' : 
-             case 'Z' :
-                        blk[cnt].itemtype=TYPE_INT;
-                        blk[cnt].item=(u8) va_arg(data,int);
-                        break;
-             case 'I' :
-                        blk[cnt].itemtype=TYPE_INT;
-                        dummy=va_arg(data,u4);
-                        /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
-                        blk[cnt].item=(u8)dummy;
-
-                        break;
-
-             case 'J' : 
-                        blk[cnt].itemtype=TYPE_LNG;
-                        blk[cnt].item=(u8)va_arg(data,jlong);
-                                break;
-             case 'F' : 
-                        blk[cnt].itemtype=TYPE_FLT;
-                        *((jfloat*)(&blk[cnt].item))=((jfloat)va_arg(data,jdouble));
-                        break;
-
-             case 'D' : 
-                        blk[cnt].itemtype=TYPE_DBL;
-                        *((jdouble*)(&blk[cnt].item))=(jdouble)va_arg(data,jdouble);
-                        break;
-             case 'V' : panic ("V not allowed as function parameter");
-                        break;
-             case 'L' : {
-                           while (utf_nextu2(utf_ptr)!=';')
-
-                           blk[cnt].itemtype=TYPE_ADR;
-                           blk[cnt].item=(u8)(u4)va_arg(data,void*);
-                           break;                      
-                        }
-             case '[' : {
-                         /* XXX */
-                           /* arrayclass */
-                                   char *start = *utf_ptr;
-                           char ch;
-                           while ((ch = utf_nextu2(utf_ptr))=='[')
-                           if (ch == 'L') {
-                               while (utf_nextu2(utf_ptr)!=';') {}
-                                   }
+               switch (utf_nextu2(utf_ptr)) {
+                       /* primitive types */
+               case 'B':
+               case 'C':
+               case 'S': 
+               case 'Z':
+                       blk[cnt].itemtype = TYPE_INT;
+                       blk[cnt].item = (u8) va_arg(data, int);
+                       break;
+
+               case 'I':
+                       blk[cnt].itemtype = TYPE_INT;
+                       dummy = va_arg(data, u4);
+                       /*printf("fill_callblock: pos:%d, value:%d\n",cnt,dummy);*/
+                       blk[cnt].item = (u8) dummy;
+                       break;
+
+               case 'J':
+                       blk[cnt].itemtype = TYPE_LNG;
+                       blk[cnt].item = (u8) va_arg(data, jlong);
+                       break;
+
+               case 'F':
+                       blk[cnt].itemtype = TYPE_FLT;
+                       *((jfloat *) (&blk[cnt].item)) = (jfloat) va_arg(data, jdouble);
+                       break;
+
+               case 'D':
+                       blk[cnt].itemtype = TYPE_DBL;
+                       *((jdouble *) (&blk[cnt].item)) = (jdouble) va_arg(data, jdouble);
+                       break;
+
+               case 'V':
+                       panic ("V not allowed as function parameter");
+                       break;
+                       
+               case 'L':
+                       while (utf_nextu2(utf_ptr) != ';')
+                           blk[cnt].itemtype = TYPE_ADR;
+                       blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
+                       break;
+                       
+               case '[':
+                       {
+                               /* XXX */
+                               /* arrayclass */
+/*                             char *start = *utf_ptr; */
+                               char ch;
+                               while ((ch = utf_nextu2(utf_ptr)) == '[')
+                                       if (ch == 'L') {
+                                               while (utf_nextu2(utf_ptr) != ';') {}
+                                       }
        
        
-                            ch=utf_nextu2(utf_ptr);
-                           blk[cnt].itemtype=TYPE_ADR;
-                           blk[cnt].item=(u8)(u4)va_arg(data,void*);
-                           break;                      
-                        }
+                               ch = utf_nextu2(utf_ptr);
+                               blk[cnt].itemtype = TYPE_ADR;
+                               blk[cnt].item = PTR_TO_ITEM(va_arg(data, void*));
+                               break;                  
+                       }
+               }
+               cnt++;
        }
        }
-       cnt++;
-   }
-
-   /*the standard doesn't say anything about return value checking, but it appears to be usefull*/
-   c=utf_nextu2(utf_ptr);
-   c=utf_nextu2(utf_ptr);
-   /*printf("%c  %c\n",ret,c);*/
-   if (ret=='O') {
-       if (!((c=='L') || (c=='['))) log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
-   } else if (ret != c) log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
 
 
+       /*the standard doesn't say anything about return value checking, but it appears to be usefull*/
+       c = utf_nextu2(utf_ptr);
+       c = utf_nextu2(utf_ptr);
+       /*printf("%c  %c\n",ret,c);*/
+       if (ret == 'O') {
+               if (!((c == 'L') || (c == '[')))
+                       log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
+       } else if (ret != c)
+               log_text("\n====\nWarning call*Method called for function with wrong return type\n====");
 }
 
 }
 
+
 /* XXX it could be considered if we should do typechecking here in the future */
 char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_objectarray* params)
 {
 /* XXX it could be considered if we should do typechecking here in the future */
 char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_objectarray* params)
 {
-    char *utf__ptr  =  descr->text;      /* current position in utf-text */
-    char **utf_ptr  =  &utf__ptr;
-    char *desc_end =  utf_end(descr);   /* points behind utf string     */
+    char *utf__ptr = descr->text;      /* current position in utf-text */
+    char **utf_ptr = &utf__ptr;
+    char *desc_end = utf_end(descr);   /* points behind utf string     */
 
     jobject param;
     int cnt;
     int cnts;
 
     jobject param;
     int cnt;
     int cnts;
-
-    u4 dummy;
     char c;
     char c;
-    char *cp;
+
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
     intsDisable();
     intsDisable();
+#endif
        if (utf_char==0) {
                utf_char=utf_new_char("java/lang/Character");
                utf_bool=utf_new_char("java/lang/Boolean");
        if (utf_char==0) {
                utf_char=utf_new_char("java/lang/Character");
                utf_bool=utf_new_char("java/lang/Boolean");
@@ -188,7 +229,9 @@ char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_object
                utf_float=utf_new_char("java/lang/Float");
                utf_double=utf_new_char("java/lang/Double");
        }
                utf_float=utf_new_char("java/lang/Float");
                utf_double=utf_new_char("java/lang/Double");
        }
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
     intsRestore();
     intsRestore();
+#endif
 
        /*
          log_text("fill_callblock");
 
        /*
          log_text("fill_callblock");
@@ -201,201 +244,220 @@ char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_object
     /* determine number of parameters */
        if (obj) {
                blk[0].itemtype = TYPE_ADR;
     /* determine number of parameters */
        if (obj) {
                blk[0].itemtype = TYPE_ADR;
-               blk[0].item = (u8)(u4)obj;
+               blk[0].item = PTR_TO_ITEM(obj);
                cnt=1;
 
        } else {
                cnt = 0;
        }
 
                cnt=1;
 
        } else {
                cnt = 0;
        }
 
-       cnts=0;
+       cnts = 0;
        while (**utf_ptr != ')') {
                if (*utf_ptr >= desc_end)
                panic("illegal method descriptor");
 
                /* primitive types */
                switch (utf_nextu2(utf_ptr)) {
        while (**utf_ptr != ')') {
                if (*utf_ptr >= desc_end)
                panic("illegal method descriptor");
 
                /* primitive types */
                switch (utf_nextu2(utf_ptr)) {
-               case 'B':       
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               if (param->vftbl->class->name==utf_byte) {
-                                       blk[cnt].itemtype=TYPE_INT;
-                                       blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
-                               } else  {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               break;
+               case 'B':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_byte) {
+                               blk[cnt].itemtype = TYPE_INT;
+                               blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
+
+                       } else  {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       break;
+
                case 'C':
                case 'C':
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               if (param->vftbl->class->name==utf_char) {
-                                       blk[cnt].itemtype=TYPE_INT;
-                                       blk[cnt].item = (u8) ((struct java_lang_Character * )param)->value;
-                               } else  {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               break;
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_char) {
+                               blk[cnt].itemtype = TYPE_INT;
+                               blk[cnt].item = (u8) ((java_lang_Character *) param)->value;
 
 
-               case 'S': 
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+                       } else  {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       break;
+
+               case 'S':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_short) {
+                               blk[cnt].itemtype = TYPE_INT;
+                               blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
+
+                       } else  {
+                               if (param->vftbl->class->name == utf_byte) {
+                                       blk[cnt].itemtype = TYPE_INT;
+                                       blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
+
+                               } else {
+                                       *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                        return 0;
                                }
                                        return 0;
                                }
-                               if (param->vftbl->class->name==utf_short) {
-                                       blk[cnt].itemtype=TYPE_INT;
-                                       blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
+                       }
+                       break;
+
+               case 'Z':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_bool) {
+                               blk[cnt].itemtype = TYPE_INT;
+                               blk[cnt].item = (u8) ((java_lang_Boolean *) param)->value;
+
+                       } else {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       break;
+
+               case 'I':
+                       /*log_text("fill_callblock_objA: param 'I'");*/
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_int) {
+                               blk[cnt].itemtype = TYPE_INT;
+                               blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
+                               /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
+                       } else {
+                               if (param->vftbl->class->name == utf_short) {
+                                       blk[cnt].itemtype = TYPE_INT;
+                                       blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
+
                                } else  {
                                } else  {
-                                       if (param->vftbl->class->name==utf_byte) {
-                                               blk[cnt].itemtype=TYPE_INT;
-                                               blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
-                                       } else {
-                                               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+                                       if (param->vftbl->class->name == utf_byte) {
+                                               blk[cnt].itemtype = TYPE_INT;
+                                               blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
+
+                                       } else  {
+                                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                                return 0;
                                        }
                                }
                                                return 0;
                                        }
                                }
-                               break;
+                       }
+                       break;
 
 
-               case 'Z':
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               if (param->vftbl->class->name==utf_bool) {
-                                       blk[cnt].itemtype=TYPE_INT;
-                                       blk[cnt].item = (u8) ((struct java_lang_Boolean * )param)->value;
-                               } else  {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               break;
+               case 'J':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       if (param->vftbl->class->name == utf_long) {
+                               blk[cnt].itemtype = TYPE_LNG;
+                               blk[cnt].item = (u8) ((java_lang_Long *) param)->value;
+
+                       } else  {
+                               if (param->vftbl->class->name == utf_int) {
+                                       blk[cnt].itemtype = TYPE_LNG;
+                                       blk[cnt].item = (u8) ((java_lang_Integer *) param)->value;
 
 
-               case 'I':
-                               log_text("fill_callblock_objA: param 'I'");
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               if (param->vftbl->class->name==utf_int) {
-                                       blk[cnt].itemtype=TYPE_INT;
-                                       blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
-                                       /*printf("INT VALUE :%d\n",((struct java_lang_Integer * )param)->value);*/
                                } else {
                                } else {
-                                       if (param->vftbl->class->name==utf_short) {
-                                               blk[cnt].itemtype=TYPE_INT;
-                                               blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
-                                       } else  {
-                                               if (param->vftbl->class->name==utf_byte) {
-                                                       blk[cnt].itemtype=TYPE_INT;
-                                                       blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
+                                       if (param->vftbl->class->name == utf_short) {
+                                               blk[cnt].itemtype = TYPE_LNG;
+                                               blk[cnt].item = (u8) ((java_lang_Short *) param)->value;
 
 
+                                       } else  {
+                                               if (param->vftbl->class->name == utf_byte) {
+                                                       blk[cnt].itemtype = TYPE_LNG;
+                                                       blk[cnt].item = (u8) ((java_lang_Byte *) param)->value;
                                                } else  {
                                                } else  {
-                                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+                                                       *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                                        return 0;
                                                }
                                        }
                                }
                                                        return 0;
                                                }
                                        }
                                }
-                               break;
-               case 'J':
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               if (param->vftbl->class->name==utf_long) {
-                                       blk[cnt].itemtype=TYPE_LNG;
-                                       blk[cnt].item = (u8) ((struct java_lang_Long * )param)->value;
-                               } else  {
-                                       if (param->vftbl->class->name==utf_int) {
-                                               blk[cnt].itemtype=TYPE_LNG;
-                                               blk[cnt].item = (u8) ((struct java_lang_Integer * )param)->value;
-                                       } else {
-                                               if (param->vftbl->class->name==utf_short) {
-                                                       blk[cnt].itemtype=TYPE_LNG;
-                                                       blk[cnt].item = (u8) ((struct java_lang_Short* )param)->value;
-                                               } else  {
-                                                       if (param->vftbl->class->name==utf_byte) {
-                                                               blk[cnt].itemtype=TYPE_LNG;
-                                                               blk[cnt].item = (u8) ((struct java_lang_Byte * )param)->value;
-                                                       } else  {
-                                                               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                                               return 0;
-                                                       }
-                                               }
-                                       }
 
 
-                               }
-                               break;
+                       }
+                       break;
 
 
-               case 'F' : 
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
+               case 'F':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+
+                       if (param->vftbl->class->name == utf_float) {
+                               blk[cnt].itemtype = TYPE_FLT;
+                               *((jfloat *) (&blk[cnt].item)) = (jfloat) ((java_lang_Float *) param)->value;
+
+                       } else  {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+                       break;
+
+               case 'D':
+                       param = params->data[cnts];
+                       if (param == 0) {
+                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
+                               return 0;
+                       }
+
+                       if (param->vftbl->class->name == utf_double) {
+                               blk[cnt].itemtype = TYPE_DBL;
+                               *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
+
+                       } else  {
+                               if (param->vftbl->class->name == utf_float) {
+                                       blk[cnt].itemtype = TYPE_DBL;
+                                       *((jdouble *) (&blk[cnt].item)) = (jdouble) ((java_lang_Float *) param)->value;
 
 
-                               if (param->vftbl->class->name==utf_float) {
-                                       blk[cnt].itemtype=TYPE_FLT;
-                                       *((jfloat*)(&blk[cnt].item))=(jfloat) ((struct java_lang_Float*)param)->value;
                                } else  {
                                } else  {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                       return 0;
-                               }
-                               break;
-               case 'D' : 
-                               param=params->data[cnts];
-                               if (param==0) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+                                       *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                        return 0;
                                }
                                        return 0;
                                }
+                       }
+                       break;
 
 
-                               if (param->vftbl->class->name==utf_double) {
-                                       blk[cnt].itemtype=TYPE_DBL;
-                                       *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
-                               } else  {
-                                       if (param->vftbl->class->name==utf_float) {
-                                               blk[cnt].itemtype=TYPE_DBL;
-                                               *((jdouble*)(&blk[cnt].item))=(jdouble) ((struct java_lang_Float*)param)->value;
-                                       } else  {
-                                               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-                                               return 0;
-                                       }
-                               }
-                               break;
                case 'V':
                        panic("V not allowed as function parameter");
                        break;
 
                case 'V':
                        panic("V not allowed as function parameter");
                        break;
 
-               case 'L': {
-                               char *start=(*utf_ptr)-1;
-                               char *end;
+               case 'L':
+                       {
+                               char *start = (*utf_ptr) - 1;
+                               char *end = NULL;
 
                                while (utf_nextu2(utf_ptr) != ';')
 
                                while (utf_nextu2(utf_ptr) != ';')
-                               end=(*utf_ptr)+1;
-                               if (!builtin_instanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD))) {
-                                       if (params->data[cnts]!=0) {
-                                               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+                                       end = (*utf_ptr) + 1;
+
+                               if (!builtin_instanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD))) {
+                                       if (params->data[cnts] != 0) {
+                                               *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                                return 0;
                                        }                       
                                }
                                                return 0;
                                        }                       
                                }
-                               blk[cnt].itemtype = TYPE_ADR;
-                               blk[cnt].item= (u8)(u4) (params->data[cnts]);
+
+                               blk[cnt].itemtype = TYPE_ADR;
+                               blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
                                break;                  
                                break;                  
+                       }
 
 
-                         }
-               case '[' :
+               case '[':
                        {
                        {
-                               char *start=(*utf_ptr)-1;
+                               char *start = (*utf_ptr) - 1;
                                char *end;
 
                                char ch;
                                char *end;
 
                                char ch;
@@ -403,16 +465,17 @@ char fill_callblock_objA(void *obj, utf *descr, jni_callblock blk[], java_object
                                        if (ch == 'L') {
                                                while (utf_nextu2(utf_ptr) != ';') {}
                                        }
                                        if (ch == 'L') {
                                                while (utf_nextu2(utf_ptr) != ';') {}
                                        }
-                               end=(*utf_ptr)-1;
+
+                               end = (*utf_ptr) - 1;
                                ch = utf_nextu2(utf_ptr);
                                ch = utf_nextu2(utf_ptr);
-                               if (!builtin_arrayinstanceof(params->data[cnts],class_from_descriptor(start,end,0,CLASSLOAD_LOAD))) {
-                                       exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+
+                               if (!builtin_arrayinstanceof(params->data[cnts], class_from_descriptor(start, end, 0, CLASSLOAD_LOAD)->vftbl)) {
+                                       *exceptionptr = new_exception("java/lang/IllegalArgumentException");
                                        return 0;
                                        return 0;
-                                       
                                }
        
                                blk[cnt].itemtype = TYPE_ADR;
                                }
        
                                blk[cnt].itemtype = TYPE_ADR;
-                               blk[cnt].item = (u8)(u4) (params->data[cnts]);
+                               blk[cnt].item = PTR_TO_ITEM(params->data[cnts]);
                                break;
                        }
                }
                                break;
                        }
                }
@@ -446,6 +509,7 @@ jmethodID get_virtual(jobject obj,jmethodID methodID) {
 
 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
        if (clazz==methodID->class) return methodID;
 
 jmethodID get_nonvirtual(jclass clazz,jmethodID methodID) {
        if (clazz==methodID->class) return methodID;
+/*class_resolvemethod -> classfindmethod? (JOWENN)*/
        return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
 }
 
        return class_resolvemethod (clazz, methodID->name, methodID->descriptor);
 }
 
@@ -466,36 +530,41 @@ jobject callObjectMethod (jobject obj, jmethodID methodID, va_list args)
          printf("\n");
        */
 
          printf("\n");
        */
 
-       if (methodID==0) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
+       if (methodID == 0) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError); 
                return 0;
        }
                return 0;
        }
-        argcount=get_parametercount(methodID);
 
 
-       if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
-               ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+       argcount = get_parametercount(methodID);
+
+       if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
+               ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
        
                return 0;
        }
        
-       if (obj && (! builtin_instanceof(obj,methodID->class))) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+       if (obj && !builtin_instanceof(obj, methodID->class)) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
 
                return 0;
        }
 
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
-       fill_callblock(obj,methodID->descriptor,blk,args,'O');
+       fill_callblock(obj, methodID->descriptor, blk, args, 'O');
 
        /*      printf("parameter: obj: %p",blk[0].item); */
 
        /*      printf("parameter: obj: %p",blk[0].item); */
-       ret=asm_calljavafunction2(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
-       MFREE(blk,jni_callblock,argcount+1);
+       ret = asm_calljavafunction2(methodID,
+                                                               argcount + 1,
+                                                               (argcount + 1) * sizeof(jni_callblock),
+                                                               blk);
+
+       MFREE(blk, jni_callblock, argcount + 1);
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
        return ret;
 }
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
        return ret;
 }
@@ -522,27 +591,27 @@ jint callIntegerMethod(jobject obj, jmethodID methodID, char retType, va_list ar
         printf("\n");
         */
        if (methodID == 0) {
         printf("\n");
         */
        if (methodID == 0) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError); 
                return 0;
        }
         
        argcount = get_parametercount(methodID);
 
                return 0;
        }
         
        argcount = get_parametercount(methodID);
 
-       if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
-               ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+       if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
+               ((!(methodID->flags & ACC_STATIC)) && (obj != 0)) )) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
 
                return 0;
        }
 
-       if (obj && (! builtin_instanceof(obj,methodID->class))) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+       if (obj && !builtin_instanceof(obj, methodID->class)) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
 
 
                return 0;
        }
 
 
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
-               log_text("Too many arguments. CallObjectMethod does not support that");
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
+               log_text("Too many arguments. CallIntegerMethod does not support that");
                return 0;
        }
 
                return 0;
        }
 
@@ -570,45 +639,50 @@ jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
        jni_callblock *blk;
        jlong ret;
 
        jni_callblock *blk;
        jlong ret;
 
-       /*
+/*     
         log_text("JNI-Call: CallObjectMethodV");
         utf_display(methodID->name);
         utf_display(methodID->descriptor);
         printf("\nParmaeter count: %d\n",argcount);
         utf_display(obj->vftbl->class->name);
         printf("\n");
         log_text("JNI-Call: CallObjectMethodV");
         utf_display(methodID->name);
         utf_display(methodID->descriptor);
         printf("\nParmaeter count: %d\n",argcount);
         utf_display(obj->vftbl->class->name);
         printf("\n");
-        */
-       if (methodID==0) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
+*/      
+       if (methodID == 0) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError); 
                return 0;
        }
                return 0;
        }
-       argcount=get_parametercount(methodID);
 
 
-       if (!( ((methodID->flags & ACC_STATIC) && (obj==0)) ||
+       argcount = get_parametercount(methodID);
+
+       if (!( ((methodID->flags & ACC_STATIC) && (obj == 0)) ||
                   ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
                   ((!(methodID->flags & ACC_STATIC)) && (obj!=0)) )) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
 
                return 0;
        }
 
-       if (obj && (! builtin_instanceof(obj,methodID->class))) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);
+       if (obj && !builtin_instanceof(obj,methodID->class)) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
                return 0;
        }
 
 
                return 0;
        }
 
 
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
-       fill_callblock(obj,methodID->descriptor,blk,args,'L');
+       fill_callblock(obj, methodID->descriptor, blk, args, 'J');
 
        /*      printf("parameter: obj: %p",blk[0].item); */
 
        /*      printf("parameter: obj: %p",blk[0].item); */
-       ret=asm_calljavafunction2long(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
-       MFREE(blk,jni_callblock,argcount+1);
+       ret = asm_calljavafunction2long(methodID,
+                                                                       argcount + 1,
+                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                       blk);
+
+       MFREE(blk, jni_callblock, argcount + 1);
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
 
        return ret;
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
 
        return ret;
@@ -616,9 +690,9 @@ jlong callLongMethod(jobject obj, jmethodID methodID, va_list args)
 
 
 /*core function for float class methods (float,double)*/
 
 
 /*core function for float class methods (float,double)*/
-jdouble callFloatMethod (jobject obj, jmethodID methodID, va_list args,char retType)
+jdouble callFloatMethod(jobject obj, jmethodID methodID, va_list args,char retType)
 {
 {
-       int argcount=get_parametercount(methodID);
+       int argcount = get_parametercount(methodID);
        jni_callblock *blk;
        jdouble ret;
 
        jni_callblock *blk;
        jdouble ret;
 
@@ -630,19 +704,24 @@ jdouble callFloatMethod (jobject obj, jmethodID methodID, va_list args,char retT
         utf_display(obj->vftbl->class->name);
         printf("\n");
         */
         utf_display(obj->vftbl->class->name);
         printf("\n");
         */
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
                log_text("Too many arguments. CallObjectMethod does not support that");
                return 0;
        }
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
-       fill_callblock(obj,methodID->descriptor,blk,args,retType);
+       fill_callblock(obj, methodID->descriptor, blk, args, retType);
 
        /*      printf("parameter: obj: %p",blk[0].item); */
 
        /*      printf("parameter: obj: %p",blk[0].item); */
-       ret=asm_calljavafunction2double(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
-       MFREE(blk,jni_callblock,argcount+1);
+       ret = asm_calljavafunction2double(methodID,
+                                                                         argcount + 1,
+                                                                         (argcount + 1) * sizeof(jni_callblock),
+                                                                         blk);
+
+       MFREE(blk, jni_callblock, argcount + 1);
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
 
        return ret;
        /*      printf("(CallObjectMethodV)-->%p\n",ret); */
 
        return ret;
@@ -682,19 +761,69 @@ jint GetVersion (JNIEnv* env)
        return JNI_VERSION;
 }
 
        return JNI_VERSION;
 }
 
+
 /****************** loads a class from a buffer of raw class data *****************/
 
 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len) 
 {
 /****************** loads a class from a buffer of raw class data *****************/
 
 jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *buf, jsize len) 
 {
-        jclass clazz; 
+       jclass clazz; 
+       classbuffer *cb;
+       s8 starttime;
+       s8 stoptime;
+
+#if defined(USE_THREADS)
+#if defined(NATIVE_THREADS)
+       compiler_lock();
+       tables_lock();
+#else
+       intsDisable();
+#endif
+#endif
+
+       /* measure time */
+       if (getloadingtime)
+               starttime = getcputime();
+
+       clazz = class_new(utf_new_char((char *) name));
 
 
-       /* change suck-mode, so subsequent class_load will read from memory-buffer */
-       classload_buffer( (u1*) buf,len);
+       /* build a classbuffer with the given data */
+       cb = NEW(classbuffer);
+       cb->class = clazz;
+       cb->size = len;
+       cb->data = (u1 *) buf;
+       cb->pos = cb->data - 1;
 
 
-        clazz = loader_load(utf_new_char ((char *) name));
+       class_load_intern(cb);
 
 
-       /* restore old suck-mode */
-       classload_buffer(NULL,0);
+       /* free memory */
+       FREE(cb, classbuffer);
+
+       /* measure time */
+       if (getloadingtime) {
+               stoptime = getcputime();
+               loadingtime += (stoptime - starttime);
+       }
+
+#if defined(USE_THREADS)
+#if defined(NATIVE_THREADS)
+       tables_unlock();
+       compiler_unlock();
+#else
+       intsRestore();
+#endif
+#endif
+
+       if (*exceptionptr)
+               return NULL;
+
+       /* XXX link the class here? */
+       class_link(clazz);
+
+       if (*exceptionptr)
+               return NULL;
+
+       if (clazz)
+               clazz->classloader = loader;
 
        return clazz;
 }
 
        return clazz;
 }
@@ -702,17 +831,21 @@ jclass DefineClass(JNIEnv* env, const char *name, jobject loader, const jbyte *b
 
 /*************** loads locally defined class with the specified name **************/
 
 
 /*************** loads locally defined class with the specified name **************/
 
-jclass FindClass (JNIEnv* env, const char *name) 
+jclass FindClass(JNIEnv* env, const char *name) 
 {
        classinfo *c;  
   
 {
        classinfo *c;  
   
-/*     if (strcmp(name,"[B")==0) {
-               c = loader_load(utf_new_char("The_Array_Class"));
-       }
-       else*/
-               c = loader_load(utf_new_char_classname ((char *) name));
+       c = class_new(utf_new_char_classname((char *) name));
 
 
-       if (!c) exceptionptr = native_new_and_init(class_java_lang_ClassFormatError);
+       class_load(c);
+
+       if (*exceptionptr)
+               return NULL;
+
+       class_link(c);
+
+       if (*exceptionptr)
+               return NULL;
 
        return c;
 }
 
        return c;
 }
@@ -771,47 +904,48 @@ jobject ToReflectedField(JNIEnv* env, jclass cls, jfieldID fieldID, jboolean isS
 
 jint Throw(JNIEnv* env, jthrowable obj)
 {
 
 jint Throw(JNIEnv* env, jthrowable obj)
 {
-       exceptionptr = (java_objectheader*) obj;
+       *exceptionptr = (java_objectheader*) obj;
 
        return 0;
 }
 
 
 
        return 0;
 }
 
 
-/*********************************************************************************** 
+/*******************************************************************************
 
        create exception object from the class clazz with the 
        specified message and cause it to be thrown
 
 
        create exception object from the class clazz with the 
        specified message and cause it to be thrown
 
- **********************************************************************************/   
-
+*******************************************************************************/
 
 
-jint ThrowNew (JNIEnv* env, jclass clazz, const char *msg) 
+jint ThrowNew(JNIEnv* env, jclass clazz, const char *msg) 
 {
        java_lang_Throwable *o;
 
        /* instantiate exception object */
 {
        java_lang_Throwable *o;
 
        /* instantiate exception object */
-       o = (java_lang_Throwable *) native_new_and_init ((classinfo*) clazz);
+       o = (java_lang_Throwable *) native_new_and_init((classinfo*) clazz);
 
        if (!o) return (-1);
 
 
        if (!o) return (-1);
 
-       o->detailMessage = (java_lang_String*) javastring_new_char((char *) msg);
+       o->detailMessage = (java_lang_String *) javastring_new_char((char *) msg);
+
+       *exceptionptr = (java_objectheader *) o;
 
 
-       exceptionptr = (java_objectheader*) o;  
        return 0;
 }
 
        return 0;
 }
 
+
 /************************* check if exception occured *****************************/
 
 jthrowable ExceptionOccurred (JNIEnv* env) 
 {
 /************************* check if exception occured *****************************/
 
 jthrowable ExceptionOccurred (JNIEnv* env) 
 {
-       return (jthrowable) exceptionptr;
+       return (jthrowable) *exceptionptr;
 }
 
 /********** print exception and a backtrace of the stack (for debugging) **********/
 
 void ExceptionDescribe (JNIEnv* env) 
 {
 }
 
 /********** print exception and a backtrace of the stack (for debugging) **********/
 
 void ExceptionDescribe (JNIEnv* env) 
 {
-       utf_display(exceptionptr->vftbl->class->name);
+       utf_display((*exceptionptr)->vftbl->class->name);
        printf ("\n");
        fflush (stdout);        
 }
        printf ("\n");
        fflush (stdout);        
 }
@@ -821,7 +955,7 @@ void ExceptionDescribe (JNIEnv* env)
 
 void ExceptionClear (JNIEnv* env) 
 {
 
 void ExceptionClear (JNIEnv* env) 
 {
-       exceptionptr = NULL;    
+       *exceptionptr = NULL;   
 }
 
 
 }
 
 
@@ -855,8 +989,6 @@ jobject PopLocalFrame(JNIEnv* env, jobject result)
     
 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
 {
     
 jobject NewGlobalRef(JNIEnv* env, jobject lobj)
 {
-       heap_addreference((void**) &lobj);
-
        return lobj;
 }
 
        return lobj;
 }
 
@@ -928,8 +1060,8 @@ jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
 
        /* log_text("JNI-Call: NewObject"); */
 
 
        /* log_text("JNI-Call: NewObject"); */
 
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                log_text("Too many arguments. NewObject does not support that");
                return 0;
        }
                log_text("Too many arguments. NewObject does not support that");
                return 0;
        }
@@ -944,7 +1076,7 @@ jobject NewObject (JNIEnv* env, jclass clazz, jmethodID methodID, ...)
                args[i]=va_arg(vaargs,void*);
        }
        va_end(vaargs);
                args[i]=va_arg(vaargs,void*);
        }
        va_end(vaargs);
-       exceptionptr=asm_calljavamethod(methodID,o,args[0],args[1],args[2]);
+       asm_calljavafunction(methodID,o,args[0],args[1],args[2]);
 
        return o;
 }
 
        return o;
 }
@@ -986,11 +1118,9 @@ jobject NewObjectA(JNIEnv* env, jclass clazz, jmethodID methodID, jvalue *args)
 jclass GetObjectClass(JNIEnv* env, jobject obj)
 {
        classinfo *c = obj->vftbl->class;
 jclass GetObjectClass(JNIEnv* env, jobject obj)
 {
        classinfo *c = obj->vftbl->class;
-/*     log_text("GetObjectClass");
-       utf_display(obj->vftbl->class->name);*/
+
        use_class_as_object(c);
 
        use_class_as_object(c);
 
-       /*printf("\nPointer: %p\n",c);*/
        return c;
 }
 
        return c;
 }
 
@@ -1040,8 +1170,11 @@ jmethodID GetMethodID(JNIEnv* env, jclass clazz, const char *name, const char *s
                utf_new_char ((char*) sig)
        );
 
                utf_new_char ((char*) sig)
        );
 
-       if (!m) exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError);          
-
+       if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
+       else if (m->flags & ACC_STATIC)   {
+               m=0;
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
+       }
        return m;
 }
 
        return m;
 }
 
@@ -1225,17 +1358,20 @@ jint CallIntMethodA(JNIEnv *env, jobject obj, jmethodID methodID, jvalue *args)
 
 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
 {
 
 jlong CallLongMethod(JNIEnv *env, jobject obj, jmethodID methodID, ...)
 {
-       log_text("JNI-Call: CallLongMethod");
+       jlong ret;
+       va_list vaargs;
+       
+       va_start(vaargs,methodID);
+       ret = callLongMethod(obj,get_virtual(obj, methodID),vaargs);
+       va_end(vaargs);
 
 
-       return 0;
+       return ret;
 }
 
 
 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
 {
 }
 
 
 jlong CallLongMethodV(JNIEnv *env, jobject obj, jmethodID methodID, va_list args)
 {
-       log_text("JNI-Call: CallLongMethodV");
-
-       return 0;
+       return  callLongMethod(obj,get_virtual(obj, methodID),args);
 }
 
 
 }
 
 
@@ -1645,7 +1781,7 @@ jfieldID GetFieldID (JNIEnv *env, jclass clazz, const char *name, const char *si
 /*             utf_display(clazz->name);
                log_text(name);
                log_text(sig);*/
 /*             utf_display(clazz->name);
                log_text(name);
                log_text(sig);*/
-               exceptionptr =  native_new_and_init(class_java_lang_NoSuchFieldError);  
+               *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);  
        }
        return f;
 }
        }
        return f;
 }
@@ -1774,40 +1910,51 @@ void SetDoubleField (JNIEnv *env, jobject obj, jfieldID fieldID, jdouble val)
         setField(obj,jdouble,fieldID,val);
 }
 
         setField(obj,jdouble,fieldID,val);
 }
 
+
 /**************** JNI-functions for calling static methods **********************/ 
 
 /**************** JNI-functions for calling static methods **********************/ 
 
-jmethodID GetStaticMethodID (JNIEnv *env, jclass clazz, const char *name, const char *sig)
+jmethodID GetStaticMethodID(JNIEnv *env, jclass clazz, const char *name, const char *sig)
 {
        jmethodID m;
 
 {
        jmethodID m;
 
-       m = class_resolvemethod (
-               clazz, 
-               utf_new_char ((char*) name), 
-               utf_new_char ((char*) sig)
-       );
+       m = class_resolvemethod(clazz,
+                                                       utf_new_char((char *) name),
+                                                       utf_new_char((char *) sig));
 
 
-       if (!m) exceptionptr =  native_new_and_init(class_java_lang_NoSuchMethodError);  
+       if (!m) *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
+       else if (!(m->flags & ACC_STATIC))   {
+               m=0;
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError);
+       }
 
        return m;
 }
 
 
        return m;
 }
 
-jobject CallStaticObjectMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
+
+jobject CallStaticObjectMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
 {
 {
-       log_text("JNI-Call: CallStaticObjectMethod");
+       jobject ret;
+       va_list vaargs;
 
 
-       return NULL;
+       /* log_text("JNI-Call: CallStaticObjectMethod");*/
+
+       va_start(vaargs, methodID);
+       ret = callObjectMethod(0, methodID, vaargs);
+       va_end(vaargs);
+
+       return ret;
 }
 
 
 }
 
 
-jobject CallStaticObjectMethodV (JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
+jobject CallStaticObjectMethodV(JNIEnv *env, jclass clazz, jmethodID methodID, va_list args)
 {
 {
-       log_text("JNI-Call: CallStaticObjectMethodV");
-
-       return NULL;
+       /* log_text("JNI-Call: CallStaticObjectMethodV"); */
+       
+       return callObjectMethod(0,methodID,args);
 }
 
 
 }
 
 
-jobject CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
+jobject CallStaticObjectMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
 {
        log_text("JNI-Call: CallStaticObjectMethodA");
 
 {
        log_text("JNI-Call: CallStaticObjectMethodA");
 
@@ -1815,18 +1962,16 @@ jobject CallStaticObjectMethodA (JNIEnv *env, jclass clazz, jmethodID methodID,
 }
 
 
 }
 
 
-jboolean CallStaticBooleanMethod (JNIEnv *env, jclass clazz, jmethodID methodID, ...)
+jboolean CallStaticBooleanMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
 {
 {
-        jboolean ret;
-        va_list vaargs;
-
-/*      log_text("JNI-Call: CallStaticBooleanMethod");*/
+       jboolean ret;
+       va_list vaargs;
 
 
-        va_start(vaargs,methodID);
-        ret = (jboolean)callIntegerMethod(0,methodID,'Z',vaargs);
-        va_end(vaargs);
-        return ret;
+       va_start(vaargs, methodID);
+       ret = (jboolean) callIntegerMethod(0, methodID, 'Z', vaargs);
+       va_end(vaargs);
 
 
+       return ret;
 }
 
 
 }
 
 
@@ -1835,6 +1980,7 @@ jboolean CallStaticBooleanMethodV(JNIEnv *env, jclass clazz, jmethodID methodID,
        return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
 }
 
        return (jboolean) callIntegerMethod(0, methodID, 'Z', args);
 }
 
+
 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
 {
        log_text("JNI-Call: CallStaticBooleanMethodA");
 jboolean CallStaticBooleanMethodA(JNIEnv *env, jclass clazz, jmethodID methodID, jvalue *args)
 {
        log_text("JNI-Call: CallStaticBooleanMethodA");
@@ -1909,7 +2055,7 @@ jshort CallStaticShortMethod(JNIEnv *env, jclass clazz, jmethodID methodID, ...)
 
        /*      log_text("JNI-Call: CallStaticByteMethod");*/
 
 
        /*      log_text("JNI-Call: CallStaticByteMethod");*/
 
-       va_start(vaargs,methodID);
+       va_start(vaargs, methodID);
        ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
        va_end(vaargs);
 
        ret = (jshort) callIntegerMethod(0, methodID, 'S', vaargs);
        va_end(vaargs);
 
@@ -2096,7 +2242,7 @@ jfieldID GetStaticFieldID (JNIEnv *env, jclass clazz, const char *name, const ch
                            utf_new_char ((char*) sig)
                            ); 
        
                            utf_new_char ((char*) sig)
                            ); 
        
-       if (!f) exceptionptr =  native_new_and_init(class_java_lang_NoSuchFieldError);  
+       if (!f) *exceptionptr = new_exception(string_java_lang_NoSuchFieldError);  
 
        return f;
 }
 
        return f;
 }
@@ -2317,7 +2463,7 @@ void ReleaseStringChars (JNIEnv *env, jstring str, const jchar *chars)
 jstring NewStringUTF (JNIEnv *env, const char *utf)
 {
 /*    log_text("NewStringUTF called");*/
 jstring NewStringUTF (JNIEnv *env, const char *utf)
 {
 /*    log_text("NewStringUTF called");*/
-    return javastring_new(utf_new_char(utf));
+    return (jstring) javastring_new(utf_new_char((char *) utf));
 }
 
 /****************** returns the utf8 length in bytes of a string *******************/
 }
 
 /****************** returns the utf8 length in bytes of a string *******************/
@@ -2329,22 +2475,26 @@ jsize GetStringUTFLength (JNIEnv *env, jstring string)
     return (jsize) u2_utflength(s->value->data, s->count); 
 }
 
     return (jsize) u2_utflength(s->value->data, s->count); 
 }
 
+
 /************ converts a Javastring to an array of UTF-8 characters ****************/
 
 /************ converts a Javastring to an array of UTF-8 characters ****************/
 
-const char* GetStringUTFChars (JNIEnv *env, jstring string, jboolean *isCopy)
+const char* GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy)
 {
     utf *u;
 {
     utf *u;
-    if (verbose) log_text("GetStringUTFChars:");
 
 
-    u=javastring_toutf((java_lang_String*) string,false);
-    if (isCopy) *isCopy=JNI_FALSE;
-    if (u) {
-       return u->text;
-    }
+    u = javastring_toutf((java_lang_String *) string, false);
+
+    if (isCopy)
+               *isCopy = JNI_FALSE;
+       
+    if (u)
+               return u->text;
+
     return emptyString;
        
 }
 
     return emptyString;
        
 }
 
+
 /***************** native code no longer needs access to utf ***********************/
 
 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
 /***************** native code no longer needs access to utf ***********************/
 
 void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
@@ -2359,45 +2509,50 @@ void ReleaseStringUTFChars (JNIEnv *env, jstring str, const char* chars)
 
 /************************** array operations ***************************************/
 
 
 /************************** array operations ***************************************/
 
-jsize GetArrayLength (JNIEnv *env, jarray array)
+jsize GetArrayLength(JNIEnv *env, jarray array)
 {
     return array->size;
 }
 
 {
     return array->size;
 }
 
+
 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
 {
        java_objectarray *j;
 jobjectArray NewObjectArray (JNIEnv *env, jsize len, jclass clazz, jobject init)
 {
        java_objectarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
-    j = builtin_anewarray (len, clazz);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
+    j = builtin_anewarray(len, clazz);
+
     return j;
 }
 
     return j;
 }
 
-jobject GetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index)
+
+jobject GetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index)
 {
     jobject j = NULL;
 
 {
     jobject j = NULL;
 
-    if (index<array->header.size)      
-       j = array->data[index];
+    if (index < array->header.size)    
+               j = array->data[index];
     else
     else
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
     
     return j;
 }
 
     
     return j;
 }
 
-void SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobject val)
+
+void SetObjectArrayElement(JNIEnv *env, jobjectArray array, jsize index, jobject val)
 {
 {
-    if (index>=array->header.size)     
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
-    else {
+    if (index >= array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
 
 
-       /* check if the class of value is a subclass of the element class of the array */
+    else {
+               /* check if the class of value is a subclass of the element class of the array */
+               if (!builtin_canstore((java_objectarray *) array, (java_objectheader *) val))
+                       *exceptionptr = new_exception(string_java_lang_ArrayStoreException);
 
 
-               if (!builtin_canstore((java_objectarray*)array,(java_objectheader*)val))
-                       exceptionptr = proto_java_lang_ArrayStoreException;
                else
                        array->data[index] = val;
     }
                else
                        array->data[index] = val;
     }
@@ -2405,106 +2560,122 @@ void SetObjectArrayElement (JNIEnv *env, jobjectArray array, jsize index, jobjec
 
 
 
 
 
 
-jbooleanArray NewBooleanArray (JNIEnv *env, jsize len)
+jbooleanArray NewBooleanArray(JNIEnv *env, jsize len)
 {
        java_booleanarray *j;
 {
        java_booleanarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_boolean(len);
     j = builtin_newarray_boolean(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jbyteArray NewByteArray (JNIEnv *env, jsize len)
+jbyteArray NewByteArray(JNIEnv *env, jsize len)
 {
        java_bytearray *j;
 {
        java_bytearray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_byte(len);
     j = builtin_newarray_byte(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jcharArray NewCharArray (JNIEnv *env, jsize len)
+jcharArray NewCharArray(JNIEnv *env, jsize len)
 {
        java_chararray *j;
 {
        java_chararray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_char(len);
     j = builtin_newarray_char(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jshortArray NewShortArray (JNIEnv *env, jsize len)
+jshortArray NewShortArray(JNIEnv *env, jsize len)
 {
        java_shortarray *j;
 {
        java_shortarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
-    j = builtin_newarray_short(len);   
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
+    j = builtin_newarray_short(len);
+
     return j;
 }
 
 
     return j;
 }
 
 
-jintArray NewIntArray (JNIEnv *env, jsize len)
+jintArray NewIntArray(JNIEnv *env, jsize len)
 {
        java_intarray *j;
 {
        java_intarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_int(len);
     j = builtin_newarray_int(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jlongArray NewLongArray (JNIEnv *env, jsize len)
+jlongArray NewLongArray(JNIEnv *env, jsize len)
 {
        java_longarray *j;
 {
        java_longarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_long(len);
     j = builtin_newarray_long(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jfloatArray NewFloatArray (JNIEnv *env, jsize len)
+jfloatArray NewFloatArray(JNIEnv *env, jsize len)
 {
        java_floatarray *j;
 {
        java_floatarray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_float(len);
     j = builtin_newarray_float(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
 
     return j;
 }
 
 
-jdoubleArray NewDoubleArray (JNIEnv *env, jsize len)
+jdoubleArray NewDoubleArray(JNIEnv *env, jsize len)
 {
        java_doublearray *j;
 {
        java_doublearray *j;
-    if (len<0) {
-               exceptionptr=proto_java_lang_NegativeArraySizeException;
+
+    if (len < 0) {
+               *exceptionptr = new_exception(string_java_lang_NegativeArraySizeException);
                return NULL;
     }
                return NULL;
     }
+
     j = builtin_newarray_double(len);
     j = builtin_newarray_double(len);
-    if (!j) exceptionptr = proto_java_lang_OutOfMemoryError;
+
     return j;
 }
 
     return j;
 }
 
@@ -2613,150 +2784,171 @@ void ReleaseDoubleArrayElements (JNIEnv *env, jdoubleArray array, jdouble *elems
     /* empty */
 }
 
     /* empty */
 }
 
-void GetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
+
+void GetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
+void GetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size) 
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size) 
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
+void GetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
+void GetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else       
     else       
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
+void GetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)      
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
+void GetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)      
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
+void GetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)      
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void GetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
+void GetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size) 
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start+len>array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(buf,&array->data[start],len*sizeof(array->data[0]));     
+               memcpy(buf, &array->data[start], len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void SetBooleanArrayRegion (JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
+void SetBooleanArrayRegion(JNIEnv* env, jbooleanArray array, jsize start, jsize len, jboolean *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void SetByteArrayRegion (JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
+void SetByteArrayRegion(JNIEnv* env, jbyteArray array, jsize start, jsize len, jbyte *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void SetCharArrayRegion (JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
+void SetCharArrayRegion(JNIEnv* env, jcharArray array, jsize start, jsize len, jchar *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 
 }
 
 
 
 }
 
 
-void SetShortArrayRegion (JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
+void SetShortArrayRegion(JNIEnv* env, jshortArray array, jsize start, jsize len, jshort *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 }
 
 
 }
 
 
-void SetIntArrayRegion (JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
+void SetIntArrayRegion(JNIEnv* env, jintArray array, jsize start, jsize len, jint *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 
 }
 
 
 }
 
-void SetLongArrayRegion (JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
+
+void SetLongArrayRegion(JNIEnv* env, jlongArray array, jsize start, jsize len, jlong *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 
 }
 
 
 }
 
-void SetFloatArrayRegion (JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
+
+void SetFloatArrayRegion(JNIEnv* env, jfloatArray array, jsize start, jsize len, jfloat *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 
 }
 
 
 }
 
-void SetDoubleArrayRegion (JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
+
+void SetDoubleArrayRegion(JNIEnv* env, jdoubleArray array, jsize start, jsize len, jdouble *buf)
 {
 {
-    if (start<0 || len<0 || start+len>array->header.size)
-       exceptionptr = proto_java_lang_ArrayIndexOutOfBoundsException;
+    if (start < 0 || len < 0 || start + len > array->header.size)
+               *exceptionptr = new_exception(string_java_lang_ArrayIndexOutOfBoundsException);
+
     else
     else
-       memcpy(&array->data[start],buf,len*sizeof(array->data[0]));     
+               memcpy(&array->data[start], buf, len * sizeof(array->data[0]));
 }
 
 }
 
+
 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
 {
     log_text("JNI-Call: RegisterNatives");
 jint RegisterNatives (JNIEnv* env, jclass clazz, const JNINativeMethod *methods, jint nMethods)
 {
     log_text("JNI-Call: RegisterNatives");
@@ -2810,7 +3002,7 @@ void GetStringUTFRegion (JNIEnv* env, jstring str, jsize start, jsize len, char
 
 }
 
 
 }
 
-/****************** obtain direct pointer to array elements ***********************/
+/************** obtain direct pointer to array elements ***********************/
 
 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
 {
 
 void * GetPrimitiveArrayCritical (JNIEnv* env, jarray array, jboolean *isCopy)
 {
@@ -2830,7 +3022,7 @@ void ReleasePrimitiveArrayCritical (JNIEnv* env, jarray array, void *carray, jin
        /* empty */
 }
 
        /* empty */
 }
 
-/********* returns a pointer to an array of Unicode characters of the string *******/
+/**** returns a pointer to an array of Unicode characters of the string *******/
 
 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
 {
 
 const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
 {
@@ -2839,7 +3031,7 @@ const jchar * GetStringCritical (JNIEnv* env, jstring string, jboolean *isCopy)
        return GetStringChars(env,string,isCopy);
 }
 
        return GetStringChars(env,string,isCopy);
 }
 
-/**************** native code no longer needs access to chars **********************/
+/*********** native code no longer needs access to chars **********************/
 
 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
 {
 
 void ReleaseStringCritical (JNIEnv* env, jstring string, const jchar *cstring)
 {
@@ -2872,7 +3064,7 @@ jboolean ExceptionCheck(JNIEnv* env)
 {
        log_text("JNI-Call: ExceptionCheck");
 
 {
        log_text("JNI-Call: ExceptionCheck");
 
-       return exceptionptr ? JNI_TRUE : JNI_FALSE;
+       return *exceptionptr ? JNI_TRUE : JNI_FALSE;
 }
 
 
 }
 
 
@@ -2920,15 +3112,6 @@ jint AttachCurrentThreadAsDaemon(JavaVM *vm, void **par1, void *par2)
 }
 
 
 }
 
 
-
-
-
-
-
-
-
-
-
 /********************************* JNI invocation table ******************************/
 
 struct _JavaVM javaVMTable={
 /********************************* JNI invocation table ******************************/
 
 struct _JavaVM javaVMTable={
@@ -3179,166 +3362,234 @@ struct JNI_Table envTable = {
     &ExceptionCheck
 };
 
     &ExceptionCheck
 };
 
-
 JNIEnv env = &envTable;
 
 
 JNIEnv env = &envTable;
 
 
-
-
-
-
-
-
-jobject *jni_method_invokeNativeHelper(JNIEnv *env,struct methodinfo *methodID,jobject obj, java_objectarray *params) {
+jobject *jni_method_invokeNativeHelper(JNIEnv *env, struct methodinfo *methodID, jobject obj, java_objectarray *params)
+{
        int argcount;
        jni_callblock *blk;
        int argcount;
        jni_callblock *blk;
-       jobject ret;
        char retT;
        jobject retVal;
        char retT;
        jobject retVal;
-       if (methodID==0) {
-               exceptionptr = native_new_and_init(class_java_lang_NoSuchMethodError); 
-               return 0;
+
+       if (methodID == 0) {
+               *exceptionptr = new_exception(string_java_lang_NoSuchMethodError); 
+               return NULL;
        }
        }
-        argcount=get_parametercount(methodID);
 
 
-       if (obj && (!builtin_instanceof((java_objectheader*)obj,methodID->class))) {
-               (*env)->ThrowNew(env,loader_load(utf_new_char("java/lang/IllegalArgumentException")),
-                       "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
-               return 0;
-       }
+       argcount = get_parametercount(methodID);
+
+       if (obj && (!builtin_instanceof((java_objectheader *) obj, methodID->class))) {
+               *exceptionptr = new_exception_message(string_java_lang_IllegalArgumentException,
+                                                                                         "Object parameter of wrong type in Java_java_lang_reflect_Method_invokeNative");
+               return 0;
+       }
 
 
 
 
 
 
-       if  (argcount>3) {
-               exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+       if (argcount > 3) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                log_text("Too many arguments. invokeNativeHelper does not support that");
                return 0;
        }
 
                log_text("Too many arguments. invokeNativeHelper does not support that");
                return 0;
        }
 
-       if ( ((!params) && (argcount!=0)) || 
-               (params && (params->header.size!=argcount))
-          ) {
-               exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/IllegalArgumentException")));
+       if (((!params) && (argcount != 0)) || (params && (params->header.size != argcount))) {
+               *exceptionptr = new_exception(string_java_lang_IllegalArgumentException);
                return 0;
        }
 
 
                return 0;
        }
 
 
-         if (!(methodID->flags & ACC_STATIC) && (!obj))  {
-               (*env)->ThrowNew(env,loader_load(utf_new_char("java/lang/NullPointerException")),
-                       "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
-               return 0;
-       }
+       if (!(methodID->flags & ACC_STATIC) && (!obj))  {
+               *exceptionptr = new_exception_message(string_java_lang_NullPointerException,
+                                                                                         "Static mismatch in Java_java_lang_reflect_Method_invokeNative");
+               return 0;
+       }
 
 
-       if ((methodID->flags & ACC_STATIC) && (obj)) obj=0;
+       if ((methodID->flags & ACC_STATIC) && (obj)) obj = 0;
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
 
        blk = MNEW(jni_callblock, 4 /*argcount+2*/);
 
-       retT=fill_callblock_objA(obj,methodID->descriptor,blk,params);
+       retT = fill_callblock_objA(obj, methodID->descriptor, blk, params);
 
        switch (retT) {
 
        switch (retT) {
-               case 'V':       (void)asm_calljavafunction2(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
-                               retVal=native_new_and_init(loader_load(utf_new_char("java/lang/Void")));
-                               break;
-               case 'I':       {
-                                       s4 intVal;      
-                                       intVal=(s4)asm_calljavafunction2(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Integer")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(I)V")),intVal);
-                               }
-                               break;
-               case 'B':       {
-                                       s4 intVal;      
-                                       intVal=(s4)asm_calljavafunction2(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Byte")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(B)V")),intVal);
-                               }
-                               break;
-               case 'C':       {
-                                       s4 intVal;      
-                                       intVal=(s4)asm_calljavafunction2(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Character")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(C)V")),intVal);
-                               }
-                               break;
-               case 'S':       {
-                                       s4 intVal;      
-                                       intVal=(s4)asm_calljavafunction2(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Short")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(S)V")),intVal);
-                               }
+       case 'V':
+               (void) asm_calljavafunction2(methodID,
+                                                                        argcount + 1,
+                                                                        (argcount + 1) * sizeof(jni_callblock),
+                                                                        blk);
+               retVal = NULL; /*native_new_and_init(loader_load(utf_new_char("java/lang/Void")));*/
+               break;
+
+       case 'I': {
+               s4 intVal;      
+               intVal = (s4) asm_calljavafunction2(methodID,
+                                                                                       argcount + 1,
+                                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                                       blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Integer")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(I)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'B': {
+               s4 intVal;      
+               intVal = (s4) asm_calljavafunction2(methodID,
+                                                                                       argcount + 1,
+                                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                                       blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Byte")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(B)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'C': {
+               s4 intVal;      
+               intVal = (s4) asm_calljavafunction2(methodID,
+                                                                                       argcount + 1,
+                                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                                       blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Character")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(C)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'S': {
+               s4 intVal;      
+               intVal = (s4) asm_calljavafunction2(methodID,
+                                                                                       argcount + 1,
+                                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                                       blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Short")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(S)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'Z': {
+               s4 intVal;      
+               intVal = (s4) asm_calljavafunction2(methodID,
+                                                                                       argcount + 1,
+                                                                                       (argcount + 1) * sizeof(jni_callblock),
+                                                                                       blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Boolean")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(Z)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'J': {
+               jlong intVal;   
+               intVal = asm_calljavafunction2long(methodID,
+                                                                                  argcount + 1,
+                                                                                  (argcount + 1) * sizeof(jni_callblock),
+                                                                                  blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Long")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(J)V")),
+                                          intVal);
+       }
+       break;
+
+       case 'F': {
+               jdouble floatVal;       
+               floatVal = asm_calljavafunction2double(methodID,
+                                                                                          argcount + 1,
+                                                                                          (argcount + 1) * sizeof(jni_callblock),
+                                                                                          blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Float")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(F)V")),
+                                          floatVal);
+       }
+       break;
+
+       case 'D': {
+               jdouble floatVal;       
+               floatVal = asm_calljavafunction2double(methodID,
+                                                                                          argcount + 1,
+                                                                                          (argcount + 1) * sizeof(jni_callblock),
+                                                                                          blk);
+               retVal = builtin_new(class_new(utf_new_char("java/lang/Double")));
+               CallVoidMethod(env,
+                                          retVal,
+                                          class_resolvemethod(retVal->vftbl->class,
+                                                                                  utf_new_char("<init>"),
+                                                                                  utf_new_char("(D)V")),
+                                          floatVal);
+       }
+       break;
 
 
-               case 'Z':       {
-                                       s4 intVal;      
-                                       intVal=(s4)asm_calljavafunction2(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Boolean")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(Z)V")),intVal);
-                               }
-                               break;
-               case 'J':       {
-                                       jlong intVal;   
-                                       intVal=asm_calljavafunction2long(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Long")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(J)V")),intVal);
-                               }
-                               break;
-               case 'F':       {
-                                       jdouble floatVal;       
-                                       floatVal=asm_calljavafunction2double(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Float")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(F)V")),floatVal);
-                               }
-                               break;
-               case 'D':       {
-                                       jdouble floatVal;       
-                                       floatVal=asm_calljavafunction2double(methodID,
-                                               argcount+1,(argcount+1)*sizeof(jni_callblock),blk);                                                                                             
-                                       retVal=builtin_new(loader_load(utf_new_char("java/lang/Double")));
-                                       CallVoidMethod(env,retVal,
-                                               class_resolvemethod(retVal->vftbl->class,
-                                               utf_new_char("<init>"),utf_new_char("(D)V")),floatVal);
-                               }
-                               break;
+       case 'L': /* fall through */
+       case '[':
+               retVal = asm_calljavafunction2(methodID,
+                                                                          argcount + 1,
+                                                                          (argcount + 1) * sizeof(jni_callblock),
+                                                                          blk);
+               break;
 
 
-               case 'L':       /* fall through */
-               case '[':       retVal=asm_calljavafunction2(methodID,argcount+1,(argcount+1)*sizeof(jni_callblock),blk);
-                               break;
-               default:        { 
-                                       /* if this happens the acception has already been set by fill_callblock_objA*/
-                                       MFREE(blk, jni_callblock, 4 /*argcount+2*/);
-                                       return (jobject*)0;
-                               }
+       default:
+               /* if this happens the acception has already been set by fill_callblock_objA*/
+               MFREE(blk, jni_callblock, 4 /*argcount+2*/);
+               return (jobject *) 0;
        }
        }
+
        MFREE(blk, jni_callblock, 4 /*argcount+2*/);
 
        MFREE(blk, jni_callblock, 4 /*argcount+2*/);
 
-       if (exceptionptr)
-               exceptionptr=native_new_and_init(loader_load("java/lang/reflect/InvocationTargetException"));
-       return retVal;  
+       if (*exceptionptr) {
+               java_objectheader *exceptionToWrap = *exceptionptr;
+               classinfo *ivtec;
+               java_objectheader *ivte;
+
+               *exceptionptr = NULL;
+               ivtec = class_new(utf_new_char("java/lang/reflect/InvocationTargetException"));
+               ivte = builtin_new(ivtec);
+               asm_calljavafunction(class_resolvemethod(ivtec,
+                                                                                                utf_new_char("<init>"),
+                                                                                                utf_new_char("(Ljava/lang/Throwable;)V")),
+                                                        ivte,
+                                                        exceptionToWrap,
+                                                        0,
+                                                        0);
+
+               if (*exceptionptr != NULL)
+                       panic("jni.c: error while creating InvocationTargetException wrapper");
+
+               *exceptionptr = ivte;
+       }
 
 
+       return (jobject *) retVal;
 }
 
 
 }
 
 
-
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where
 /*
  * These are local overrides for various environment variables in Emacs.
  * Please do not remove this and leave it at the end of the file, where