CallLongMethod implementation added
[cacao.git] / native.c
index 214fa903c3db72cb5e461537297ab0743dd60b9a..c5c2561611ccb5351e8908b94dc628b13ba0270a 100644 (file)
--- a/native.c
+++ b/native.c
@@ -31,7 +31,7 @@
    The .hh files created with the header file generator are all
    included here as are the C functions implementing these methods.
 
-   $Id: native.c 930 2004-03-02 21:18:23Z jowenn $
+   $Id: native.c 1361 2004-07-28 10:51:14Z twisti $
 
 */
 
 #include <utime.h>
 
 #include "config.h"
+#include "exceptions.h"
 #include "global.h"
+#include "options.h"
 #include "jni.h"
 #include "native.h"
-#include "nativetypes.hh"
 #include "builtin.h"
 #include "asmpart.h"
 #include "tables.h"
 #include "loader.h"
 #include "jni.h"
-#include "toolbox/loging.h"
+#include "jit/jit.h"
+#include "toolbox/logging.h"
 #include "toolbox/memory.h"
 #include "threads/thread.h"
 #include "threads/threadio.h"
 #include "threads/locks.h"
+#include "nat/java_lang_VMClass.h"
+#include "nat/java_lang_Throwable.h"
 
 /* Include files for IO functions */
 
 
 #include "threads/threadio.h"
 
-/* searchpath for classfiles */
-char *classpath;
+/* include table of native functions */
+
+#include "nativetable.inc"
+
 
 /* for java-string to char conversion */
 #define MAXSTRINGSIZE 1000                          
 
+
 /******************** systemclasses required for native methods ***************/
 
 classinfo *class_java_lang_Class;
 classinfo *class_java_lang_VMClass;
-methodinfo *method_vmclass_init;
-/* static classinfo *class_java_lang_Cloneable=0; */ /* now in global.h */
-classinfo *class_java_lang_CloneNotSupportedException;
 classinfo *class_java_lang_System;
 classinfo *class_java_lang_ClassLoader;
 classinfo *class_gnu_java_lang_SystemClassLoader;
-classinfo *class_java_lang_NoClassDefFoundError;
-classinfo *class_java_lang_ClassNotFoundException;
-classinfo *class_java_lang_LinkageError;
-classinfo *class_java_lang_InstantiationException;
-classinfo *class_java_lang_NoSuchMethodError;   
-classinfo *class_java_lang_NoSuchFieldError;
-classinfo *class_java_lang_ClassFormatError;
-classinfo *class_java_lang_IllegalArgumentException;
-classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
-classinfo *class_java_lang_NoSuchFieldException;
-classinfo *class_java_io_SyncFailedException;
-classinfo *class_java_io_IOException;
-classinfo *class_java_io_FileNotFoundException;
-classinfo *class_java_io_UnixFileSystem;
-classinfo *class_java_security_PrivilegedActionException;
-classinfo *class_java_net_UnknownHostException;
-classinfo *class_java_net_SocketException;
-classinfo *class_java_lang_NoSuchMethodException;
+classinfo *class_java_lang_SecurityManager;
 classinfo *class_java_lang_Double;
 classinfo *class_java_lang_Float;
 classinfo *class_java_lang_Long;
@@ -117,59 +104,26 @@ classinfo *class_java_lang_Void;
 classinfo *class_java_lang_Character;
 classinfo *class_java_lang_Integer;
 
+methodinfo *method_vmclass_init;
+
+
 /* the system classloader object */
 struct java_lang_ClassLoader *SystemClassLoader = NULL;
 
 /* for raising exceptions from native methods */
-THREADSPECIFIC java_objectheader* _exceptionptr = NULL;
+#if !defined(USE_THREADS) || !defined(NATIVE_THREADS)
+java_objectheader* _exceptionptr = NULL;
+#endif
 
 /************* use classinfo structure as java.lang.Class object **************/
 
 void use_class_as_object(classinfo *c) 
 {
-       vftbl *vt;
-/*     vftbl *newtbl; */
-
-       if (!class_java_lang_Class)
-               class_java_lang_Class = class_new(utf_new_char ("java/lang/Class"));
-
-       vt = class_java_lang_Class->vftbl;
-
-
        if (!c->classvftbl) {
-               c->classvftbl = true;
-
-               /*                copy_vftbl(&newtbl, vt);
-                                                 newtbl->class = c->header.vftbl->class;
-                                                 newtbl->baseval = c->header.vftbl->baseval;
-                                                 newtbl->diffval = c->header.vftbl->diffval;
-                                                 c->header.vftbl = newtbl;*/
-               
                c->header.vftbl = class_java_lang_Class->vftbl;
-        
-               if (!class_java_lang_VMClass) {
-                       loader_load_sysclass(&class_java_lang_VMClass,
-                                                                utf_new_char("java/lang/VMClass"));
-
-                       method_vmclass_init =
-                               class_findmethod(class_java_lang_VMClass,
-                                                                utf_new_char("<init>"),
-                                                                utf_new_char("(Lgnu/classpath/RawData;)V"));
-
-                       if (method_vmclass_init == 0) {
-                               class_showmethods(class_java_lang_VMClass);
-                               panic("Needed class initializer for VMClass could not be found");
-                       }
-               }
-               {     
-                       java_objectheader *vmo = builtin_new(class_java_lang_VMClass);
-
-                       if (!vmo) panic("Error while creating instance of java/lang/VMClass");
-                       asm_calljavafunction(method_vmclass_init, vmo, c, NULL, NULL);
-                       c->vmClass = (java_lang_VMClass *) vmo;
-                       /*log_text("VMCLASS has been attached");*/
-               }
-       }
+               c->classvftbl = true;
+       }
+            
 }
 
 
@@ -181,7 +135,6 @@ void use_class_as_object(classinfo *c)
 #include "nat/GdkPixbufDecoder.c"
 #include "nat/GtkScrollPanePeer.c"
 #include "nat/GtkFileDialogPeer.c"
-#include "nat/GtkLabelPeer.c"
 #endif
 
 
@@ -190,209 +143,92 @@ void use_class_as_object(classinfo *c)
 #undef JOWENN_DEBUG
 #undef JOWENN_DEBUG1
 
-/* table for locating native methods */
-static struct nativeref {
-       char *classname;
-       char *methodname;
-       char *descriptor;
-       bool isstatic;
-       functionptr func;
-} nativetable [] = {
-
-#include "nativetable.hh"
-
-};
-
-
 #define NATIVETABLESIZE  (sizeof(nativetable)/sizeof(struct nativeref))
 
 /* table for fast string comparison */
-static struct nativecompref {
-       utf *classname;
-       utf *methodname;
-       utf *descriptor;
-       bool isstatic;
-       functionptr func;
-} nativecomptable [NATIVETABLESIZE];
+static nativecompref nativecomptable[NATIVETABLESIZE];
 
 /* string comparsion table initialized */
 static bool nativecompdone = false;
 
 
 /******************************************************************************/
-/******************************************************************************/
-#include "natcalls.h"
-
-/* string call comparison table initialized */
-
-/******************************************************************************/
-/******************************************************************************/
-
-/*--------------- native method calls & classes used -------------------------*/
-
 
-
-/* throw some loader exceptions */
-
-void throw_noclassdeffounderror_message(utf* classname)
-{
-       if (!class_java_lang_NoClassDefFoundError) {
-               panic("java.lang.NoClassDefFoundError not found. Maybe wrong classpath?");
-       }
-
-       /* throws a NoClassDefFoundError with message */
-       *exceptionptr = native_new_and_init_string(class_java_lang_NoClassDefFoundError,
-                                                                                         javastring_new(classname));
-}
+#include "natcalls.h"
 
 
-void throw_linkageerror_message(utf* classname)
-{
-       if (!class_java_lang_LinkageError) {
-               panic("java.lang.LinkageError not found. Maybe wrong classpath?");
-       }
+/*********************** function: native_loadclasses **************************
 
-       /* throws a LinkageError with message */
-       *exceptionptr = native_new_and_init_string(class_java_lang_LinkageError,
-                                                                                         javastring_new(classname));
-}
+       load classes required for native methods        
 
+*******************************************************************************/
 
-void throw_exception_message(char *classname, char *message)
+void native_loadclasses()
 {
-       classinfo *c = class_new(utf_new_char(classname));
-
-       if (!c->linked)
-               panic("...");
+       static int classesLoaded = 0; /*temporary hack JoWenn*/
 
-       *exceptionptr = native_new_and_init_string(c,
-                                                                                          javastring_new_char(message));
-}
+       if (classesLoaded)
+               return;
 
+       classesLoaded = 1;
 
-/*********************** function: native_loadclasses **************************
+       class_java_lang_Cloneable =
+               class_new(utf_new_char("java/lang/Cloneable"));
+       class_load(class_java_lang_Cloneable);
+       class_link(class_java_lang_Cloneable);
 
-       load classes required for native methods        
+       class_java_lang_Class =
+               class_new(utf_new_char("java/lang/Class"));
+       class_load(class_java_lang_Class);
+       class_link(class_java_lang_Class);
 
-*******************************************************************************/
+       class_java_lang_VMClass =
+               class_new(utf_new_char("java/lang/VMClass"));
+       class_load(class_java_lang_VMClass);
+       class_link(class_java_lang_VMClass);
 
-void native_loadclasses()
-{
-       static int classesLoaded=0; /*temporary hack JoWenn*/
-       if (classesLoaded) return;
-       classesLoaded = 1;
-/*     log_text("loadclasses entered");*/
-
-
-       /*class_java_lang_System =*/
-       (void) class_new(utf_new_char("java/lang/VMClass"));/*JoWenn*/
-       (void) class_new(utf_new_char("java/lang/Class"));/*JoWenn*/
-
-       /* class_new adds the class to the list of classes to be loaded */
-       if (!class_java_lang_Cloneable)
-               class_java_lang_Cloneable = 
-                       class_new(utf_new_char("java/lang/Cloneable"));
-/*     log_text("loadclasses: class_java_lang_Cloneable has been initialized");*/
-       class_java_lang_CloneNotSupportedException = 
-               class_new(utf_new_char("java/lang/CloneNotSupportedException"));
-       if (!class_java_lang_Class)
-               class_java_lang_Class =
-                       class_new(utf_new_char("java/lang/Class"));
-       class_java_io_IOException = 
-               class_new(utf_new_char("java/io/IOException"));
-       class_java_io_FileNotFoundException = 
-               class_new(utf_new_char("java/io/FileNotFoundException"));
-       class_java_lang_NoClassDefFoundError =
-               class_new(utf_new_char("java/lang/NoClassDefFoundError"));
-       class_java_lang_ClassNotFoundException =
-               class_new(utf_new_char("java/lang/ClassNotFoundException"));
-       class_java_lang_LinkageError =
-               class_new(utf_new_char("java/lang/LinkageError"));
-       class_java_lang_InstantiationException =
-               class_new(utf_new_char("java/lang/InstantiationException"));
-       class_java_lang_NoSuchMethodError =
-               class_new(utf_new_char("java/lang/NoSuchMethodError"));
-       class_java_lang_NoSuchFieldError =
-               class_new(utf_new_char("java/lang/NoSuchFieldError"));  
-       class_java_lang_ClassFormatError =
-               class_new(utf_new_char("java/lang/ClassFormatError"));  
-       class_java_io_SyncFailedException =
-               class_new(utf_new_char("java/io/SyncFailedException"));
-               
-/*     log_text("native_loadclasses: class_new(\"java/lang/ClassLoader\")");           */
        class_java_lang_ClassLoader =
-               class_new(utf_new_char("java/lang/ClassLoader"));       
-       class_gnu_java_lang_SystemClassLoader =
-               class_new(utf_new_char("gnu/java/lang/SystemClassLoader"));     
-
-/*     log_text("native_loadclasses: class_new(\"java/security/PrivilegedActionException\")");         */
-       class_java_security_PrivilegedActionException =
-               class_new(utf_new_char("java/security/PrivilegedActionException"));
-
-       loader_load_sysclass(&class_java_net_UnknownHostException,
-                                                utf_new_char("java/net/UnknownHostException"));
-       loader_load_sysclass(&class_java_net_SocketException,
-                                                utf_new_char("java/net/SocketException"));
-
-       class_java_lang_IllegalArgumentException =
-               class_new(utf_new_char("java/lang/IllegalArgumentException"));
-       class_java_lang_ArrayIndexOutOfBoundsException =
-               class_new(utf_new_char("java/lang/ArrayIndexOutOfBoundsException"));
-       class_java_lang_NoSuchFieldException =
-               class_new(utf_new_char("java/lang/NoSuchFieldException"));
-       class_java_lang_NoSuchMethodException = 
-               class_new(utf_new_char("java/lang/NoSuchMethodException"));
+               class_new(utf_new_char("java/lang/ClassLoader"));
+       class_load(class_java_lang_ClassLoader);
+       class_link(class_java_lang_ClassLoader);
 
        /* load classes for wrapping primitive types */
-       class_java_lang_Double    = class_new(utf_new_char("java/lang/Double"));
-       class_init(class_java_lang_Double);
+       class_java_lang_Double = class_new(utf_new_char("java/lang/Double"));
+       class_load(class_java_lang_Double);
+       class_link(class_java_lang_Double);
 
-       class_java_lang_Float     = class_new(utf_new_char("java/lang/Float"));
-       class_java_lang_Character =     class_new(utf_new_char("java/lang/Character"));
-       class_java_lang_Integer   = class_new(utf_new_char("java/lang/Integer"));
-       class_java_lang_Long      = class_new(utf_new_char("java/lang/Long"));
-       class_java_lang_Byte      = class_new(utf_new_char("java/lang/Byte"));
-       class_java_lang_Short     = class_new(utf_new_char("java/lang/Short"));
-       class_java_lang_Boolean   = class_new(utf_new_char("java/lang/Boolean"));
-       class_java_lang_Void      = class_new(utf_new_char("java/lang/Void"));
+       class_java_lang_Float = class_new(utf_new_char("java/lang/Float"));
+       class_load(class_java_lang_Float);
+       class_link(class_java_lang_Float);
 
-       classesLoaded = 1;
-}
+       class_java_lang_Character =     class_new(utf_new_char("java/lang/Character"));
+       class_load(class_java_lang_Character);
+       class_link(class_java_lang_Character);
 
+       class_java_lang_Integer = class_new(utf_new_char("java/lang/Integer"));
+       class_load(class_java_lang_Integer);
+       class_link(class_java_lang_Integer);
 
-/*************** adds a class to the vector of loaded classes ****************/
+       class_java_lang_Long = class_new(utf_new_char("java/lang/Long"));
+       class_load(class_java_lang_Long);
+       class_link(class_java_lang_Long);
 
-void systemclassloader_addclass(classinfo *c)
-{
-       methodinfo *m;
+       class_java_lang_Byte = class_new(utf_new_char("java/lang/Byte"));
+       class_load(class_java_lang_Byte);
+       class_link(class_java_lang_Byte);
 
-       /* find method addClass of java.lang.ClassLoader */
-       m = class_resolvemethod(class_java_lang_ClassLoader,
-                                                       utf_new_char("addClass"),
-                                                       utf_new_char("(Ljava/lang/Class;)")
-                                                       );
-       
-       if (!m)
-               panic("warning: cannot initialize classloader");
-
-       /* prepare class to be passed as argument */
-       use_class_as_object (c);
-
-       /* call 'addClass' */
-       asm_calljavafunction(m,
-                                                (java_objectheader*) SystemClassLoader, 
-                                                (java_objectheader*) c,
-                                                NULL,  
-                                                NULL
-                                                );
-}
+       class_java_lang_Short = class_new(utf_new_char("java/lang/Short"));
+       class_load(class_java_lang_Short);
+       class_link(class_java_lang_Short);
 
+       class_java_lang_Boolean = class_new(utf_new_char("java/lang/Boolean"));
+       class_load(class_java_lang_Boolean);
+       class_link(class_java_lang_Boolean);
 
-/*************** adds a library to the vector of loaded libraries *************/
+       class_java_lang_Void = class_new(utf_new_char("java/lang/Void"));
+       class_load(class_java_lang_Void);
+       class_link(class_java_lang_Void);
 
-void systemclassloader_addlibrary(java_objectheader *o)
-{
-       log_text("systemclassloader_addlibrary");
 }
 
 
@@ -404,11 +240,12 @@ void systemclassloader_addlibrary(java_objectheader *o)
 
 void init_systemclassloader() 
 {
+       log_text("init_systemclassloader");
        if (!SystemClassLoader) {
                native_loadclasses();
                log_text("Initializing new system class loader");
                /* create object and call initializer */
-               SystemClassLoader = (java_lang_ClassLoader*) native_new_and_init(class_gnu_java_lang_SystemClassLoader);/*class_java_lang_ClassLoader);*/
+               SystemClassLoader = (java_lang_ClassLoader *) native_new_and_init(class_new(utf_new_char("gnu/java/lang/SystemClassLoader")));
 
                /* systemclassloader has no parent */
                SystemClassLoader->parent      = NULL;
@@ -418,43 +255,6 @@ void init_systemclassloader()
 }
 
 
-/********************* add loaded library name  *******************************/
-
-void systemclassloader_addlibname(java_objectheader *o)
-{
-       methodinfo *m;
-       jfieldID id;
-
-       m = class_resolvemethod(loader_load_sysclass(NULL, utf_new_char ("java/util/Vector")),
-                                                       utf_new_char("addElement"),
-                                                       utf_new_char("(Ljava/lang/Object;)V"));
-
-       if (!m) panic("cannot initialize classloader");
-
-       id = envTable.GetStaticFieldID(&env,
-                                                                  class_java_lang_ClassLoader,
-                                                                  "loadedLibraryNames",
-                                                                  "Ljava/util/Vector;");
-
-       if (!id) panic("can not access ClassLoader");
-
-       asm_calljavafunction(m,
-                                                envTable.GetStaticObjectField(&env, class_java_lang_ClassLoader, id),
-                                                o,
-                                                NULL,  
-                                                NULL);
-}
-
-
-/********************* function: native_setclasspath **************************/
-void native_setclasspath(char *path)
-{
-       /* set searchpath for classfiles */
-       classpath = path;
-}
-
-
 /*********************** Function: native_findfunction *************************
 
        Looks up a method (must have the same class name, method name, descriptor
@@ -562,7 +362,7 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
        MFREE(buffer, char, buffer_len);
 
-       exit(1);
+/*     exit(1); */
 
        /* keep compiler happy */
        return NULL;
@@ -578,7 +378,6 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
 *******************************************************************************/
 
-/*  java_objectheader *javastring_new(utf *u) */
 java_lang_String *javastring_new(utf *u)
 {
        char *utf_ptr = u->text;        /* current utf character in utf string    */
@@ -587,13 +386,11 @@ java_lang_String *javastring_new(utf *u)
        java_chararray *a;
        s4 i;
        
-/*     log_text("javastring_new");*/
-       
-       s = (java_lang_String*) builtin_new(class_java_lang_String);
+       s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(utflength);
 
        /* javastring or character-array could not be created */
-       if ((!a) || (!s))
+       if (!a || !s)
                return NULL;
 
        /* decompress utf-string */
@@ -605,7 +402,6 @@ java_lang_String *javastring_new(utf *u)
        s->offset = 0;
        s->count  = utflength;
 
-/*     return (java_objectheader*) s; */
        return s;
 }
 
@@ -619,20 +415,18 @@ java_lang_String *javastring_new(utf *u)
 
 *******************************************************************************/
 
-/*  java_objectheader *javastring_new_char (char *text) */
-java_lang_String *javastring_new_char (char *text)
+java_lang_String *javastring_new_char(char *text)
 {
        s4 i;
        s4 len = strlen(text); /* length of the string */
        java_lang_String *s;   /* result-string */
        java_chararray *a;
        
-       /*log_text("javastring_new_char");*/
-       s = (java_lang_String*) builtin_new(class_java_lang_String);
+       s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(len);
 
        /* javastring or character-array could not be created */
-       if ((!a) || (!s))
+       if (!a || !s)
                return NULL;
 
        /* copy text */
@@ -644,7 +438,6 @@ java_lang_String *javastring_new_char (char *text)
        s->offset = 0;
        s->count  = len;
 
-/*     return (java_objectheader*) s; */
        return s;
 }
 
@@ -697,6 +490,7 @@ char *javastring_tochar(java_objectheader *so)
 fieldinfo *class_findfield_approx(classinfo *c, utf *name)
 {
        s4 i;
+
        for (i = 0; i < c->fieldscount; i++) {
                /* compare field names */
                if ((c->fields[i].name == name))
@@ -704,22 +498,25 @@ fieldinfo *class_findfield_approx(classinfo *c, utf *name)
        }
 
        /* field was not found, raise exception */      
-       *exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldException);
+       *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
 
        return NULL;
 }
 
-s4 class_findfield_index_approx (classinfo *c, utf *name)
+
+s4 class_findfield_index_approx(classinfo *c, utf *name)
 {
        s4 i;
+
        for (i = 0; i < c->fieldscount; i++) {
                /* compare field names */
                if ((c->fields[i].name == name))
                        return i;
-               }
+       }
 
        /* field was not found, raise exception */      
-       *exceptionptr = native_new_and_init(class_java_lang_NoSuchFieldException);
+       *exceptionptr = new_exception(string_java_lang_NoSuchFieldException);
+
        return -1;
 }
 
@@ -736,27 +533,98 @@ java_objectheader *native_new_and_init(classinfo *c)
        methodinfo *m;
        java_objectheader *o;
 
-       /* if c==NULL it is probebly because loader_load failed */
-       if (!c) return *exceptionptr;
+       if (!c)
+               return *exceptionptr;
+
+       o = builtin_new(c);                 /* create object                      */
+       
+       if (!o)
+               return NULL;
+
+       /* find initializer */
+
+       m = class_findmethod(c,
+                                                utf_new_char("<init>"),
+                                                utf_new_char("()V"));
+                                                     
+       if (!m) {                           /* initializer not found              */
+               if (verbose) {
+                       char logtext[MAXLOGTEXT];
+                       sprintf(logtext, "Warning: class has no instance-initializer: ");
+                       utf_sprint_classname(logtext + strlen(logtext), c->name);
+                       log_text(logtext);
+               }
+               return o;
+       }
+
+       /* call initializer */
+
+       asm_calljavafunction(m, o, NULL, NULL, NULL);
+
+       return o;
+}
+
+
+java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
+{
+       methodinfo *m;
+       java_objectheader *o;
+
+       if (!c)
+               return *exceptionptr;
+
+       o = builtin_new(c);          /* create object          */
+
+       if (!o)
+               return NULL;
+
+       /* find initializer */
+
+       m = class_findmethod(c,
+                                                utf_new_char("<init>"),
+                                                utf_new_char("(Ljava/lang/String;)V"));
+                                                     
+       if (!m) {                                       /* initializer not found  */
+               if (verbose) {
+                       char logtext[MAXLOGTEXT];
+                       sprintf(logtext, "Warning: class has no instance-initializer: ");
+                       utf_sprint_classname(logtext + strlen(logtext), c->name);
+                       log_text(logtext);
+               }
+               return o;
+       }
+
+       /* call initializer */
+
+       asm_calljavafunction(m, o, s, NULL, NULL);
+
+       return o;
+}
+
+
+java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
+{
+       methodinfo *m;
+       java_objectheader *o;
+
+       if (!c)
+               return *exceptionptr;
 
        o = builtin_new(c);          /* create object          */
        
-        /*
-       printf("native_new_and_init ");
-       utf_display(c->name);
-       printf("\n");
-        */
        if (!o) return NULL;
-       /* printf("o!=NULL\n"); */
+
        /* find initializer */
 
-       m = class_findmethod(c, utf_new_char("<init>"), utf_new_char("()V"));
+       m = class_findmethod(c,
+                                                utf_new_char("<init>"),
+                                                utf_new_char("(I)V"));
                                                      
        if (!m) {                                       /* initializer not found  */
                if (verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
-                       utf_sprint(logtext + strlen(logtext), c->name);
+                       utf_sprint_classname(logtext + strlen(logtext), c->name);
                        log_text(logtext);
                }
                return o;
@@ -764,19 +632,23 @@ java_objectheader *native_new_and_init(classinfo *c)
 
        /* call initializer */
 
-       asm_calljavafunction(m, o, NULL, NULL, NULL);
+#if defined(__I386__) || defined(__POWERPC__)
+       asm_calljavafunction(m, o, (void *) i, NULL, NULL);
+#else
+       asm_calljavafunction(m, o, (void *) (s8) i, NULL, NULL);
+#endif
 
        return o;
 }
 
 
-java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
+java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwable *t)
 {
        methodinfo *m;
        java_objectheader *o;
 
-       /* if c==NULL it is probebly because loader_load failed */
-       if (!c) return *exceptionptr;
+       if (!c)
+               return *exceptionptr;
 
        o = builtin_new(c);          /* create object          */
        
@@ -786,13 +658,13 @@ java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
 
        m = class_findmethod(c,
                                                 utf_new_char("<init>"),
-                                                utf_new_char("(Ljava/lang/String;)V"));
+                                                utf_new_char("(Ljava/lang/Throwable;)V"));
                                                      
        if (!m) {                                       /* initializer not found  */
                if (verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
-                       utf_sprint(logtext + strlen(logtext), c->name);
+                       utf_sprint_classname(logtext + strlen(logtext), c->name);
                        log_text(logtext);
                }
                return o;
@@ -800,7 +672,7 @@ java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
 
        /* call initializer */
 
-       asm_calljavafunction(m, o, s, NULL, NULL);
+       asm_calljavafunction(m, o, t, NULL, NULL);
 
        return o;
 }
@@ -836,7 +708,7 @@ void stringtable_update ()
 
                                if (!js->header.vftbl) 
                                        /* vftbl of javastring is NULL */ 
-                                       js->header.vftbl = class_java_lang_String -> vftbl;
+                                       js->header.vftbl = class_java_lang_String->vftbl;
 
                                if (!a->header.objheader.vftbl) 
                                        /* vftbl of character-array is NULL */ 
@@ -900,12 +772,6 @@ utf *utf_new_u2(u2 *unicode_pos, u4 unicode_length, bool isclassname)
        buflength = u2_utflength(unicode_pos, unicode_length); 
        buffer    = MNEW(char, buflength);
  
-       /* memory allocation failed */
-       if (!buffer) {
-               printf("length: %d\n",buflength);
-               log_text("utf_new_u2:buffer==NULL");
-       }
-
        left = buflength;
        pos  = buffer;
 
@@ -987,8 +853,9 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
     literalstring *s;                /* hashtable element */
     java_lang_String *js;            /* u2-array wrapped in javastring */
     java_chararray *stringdata;      /* copy of u2-array */      
-    u4 key;   
-    u4 slot;  
+       classinfo *c;
+    u4 key;
+    u4 slot;
     u2 i;
 
 //#define DEBUG_LITERALSTRING_U2
@@ -1046,20 +913,38 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
     stringdata->header.objheader.vftbl = primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl;
     stringdata->header.size = length;
 
+       /* if we use eager loading, we have to check loaded String class */
+       if (opt_eager) {
+               class_java_lang_String =
+                       class_new_intern(utf_new_char("java/lang/String"));
+
+               if (!class_load(class_java_lang_String))
+                       return NULL;
+
+               list_addfirst(&unlinkedclasses, class_java_lang_String);
+       }
+
     /* create new javastring */
     js = LNEW(java_lang_String);
-    js->header.vftbl = class_java_lang_String->vftbl;
+       js->header.vftbl = class_java_lang_String->vftbl;
     js->value  = stringdata;
     js->offset = 0;
     js->count  = length;
 
+#ifdef DEBUG_LITERALSTRING_U2
+       printf("literalstring_u2: newly created at %p\n", js);
+       utf_display(javastring_toutf(js, 0));
+       printf("\n\n");
+       fflush(stdout);
+#endif
+                       
     /* create new literalstring */
     s = NEW(literalstring);
     s->hashlink = string_hash.ptr[slot];
     s->string   = (java_objectheader *) js;
     string_hash.ptr[slot] = s;
 
-    /* update numbe of hashtable entries */
+    /* update number of hashtable entries */
     string_hash.entries++;
 
     /* reorganization of hashtable */       
@@ -1068,7 +953,7 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
          the external chains is approx. 2                */  
 
                u4 i;
-               literalstring *s;     
+               literalstring *s;
                hashtable newhash; /* the new hashtable */
       
                /* create new hashtable, double the size */
@@ -1096,13 +981,6 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
                string_hash = newhash;
     }
 
-#ifdef DEBUG_LITERALSTRING_U2
-       printf("literalstring_u2: newly created at %p\n", js);
-       utf_display(javastring_toutf(js, 0));
-       printf("\n\n");
-       fflush(stdout);
-#endif
-                       
     return (java_objectheader *) js;
 }
 
@@ -1120,10 +998,7 @@ java_objectheader *literalstring_new(utf *u)
     u4 utflength  = utf_strlen(u);   /* length of utf-string if uncompressed */
     java_chararray *a;               /* u2-array constructed from utf string */
     u4 i;
-/*    log_text("literalstring_new"); */
-/*    utf_display(u);*/
-    /*if (utflength==0) while (1) sleep(60);*/
-/*    log_text("------------------");    */
+
     /* allocate memory */ 
     a = lit_mem_alloc(sizeof(java_chararray) + sizeof(u2) * (utflength - 1) + 10);
 
@@ -1146,8 +1021,6 @@ void literalstring_free(java_objectheader* sobj)
        java_lang_String *s = (java_lang_String *) sobj;
        java_chararray *a = s->value;
 
-       log_text("literalstring_free called");
-       
        /* dispose memory of java.lang.String object */
        LFREE(s, java_lang_String);
 
@@ -1156,7 +1029,7 @@ void literalstring_free(java_objectheader* sobj)
 }
 
 
-void copy_vftbl(vftbl **dest, vftbl *src)
+void copy_vftbl(vftbl_t **dest, vftbl_t *src)
 {
     *dest = src;
 #if 0
@@ -1236,6 +1109,7 @@ utf *create_methodsig(java_objectarray* types, char *retType)
                                goto next_type;
 
                        nomatch:
+                               ;
                        }
 
                        /* no primitive type and no arrayclass, so must be object */
@@ -1249,6 +1123,7 @@ utf *create_methodsig(java_objectarray* types, char *retType)
                        *pos++ = ';';
 
                next_type:
+                       ;
                }  
     }      
 
@@ -1290,12 +1165,12 @@ classinfo *get_type(char **utf_ptr,char *desc_end, bool skip)
 }
 
 
-/******************************************************************************************
+/* get_parametertypes **********************************************************
 
-       use the descriptor of a method to generate a java/lang/Class array
-       which contains the classes of the parametertypes of the method
+   use the descriptor of a method to generate a java/lang/Class array
+   which contains the classes of the parametertypes of the method
 
-*******************************************************************************************/
+*******************************************************************************/
 
 java_objectarray* get_parametertypes(methodinfo *m) 
 {
@@ -1310,36 +1185,44 @@ java_objectarray* get_parametertypes(methodinfo *m)
     utf_nextu2(&utf_ptr);
   
     /* 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++;
     }
 
     /* create class-array */
     result = builtin_anewarray(parametercount, class_java_lang_Class);
 
-    utf_ptr  =  descr->text;
+    utf_ptr = descr->text;
     utf_nextu2(&utf_ptr);
 
     /* get returntype classes */
     for (i = 0; i < parametercount; i++)
-           result->data[i] = (java_objectheader *) get_type(&utf_ptr,desc_end, false);
+           result->data[i] =
+                       (java_objectheader *) get_type(&utf_ptr, desc_end, false);
 
     return result;
 }
 
 
+/* get_exceptiontypes **********************************************************
 
+   get the exceptions which can be thrown by a method
 
+*******************************************************************************/
 
-/******************************************************************************************
-
-       get the exceptions which can be thrown by a method      
-
-*******************************************************************************************/
-
-java_objectarray* get_exceptiontypes(methodinfo *m) 
-{
+java_objectarray* get_exceptiontypes(methodinfo *m) {
+    u2 exccount=m->thrownexceptionscount;
+    u2 i;
+    java_objectarray *result;
+    /* create class-array */
+    result = builtin_anewarray(exccount, class_java_lang_Class);
+    for (i=0;i<exccount;i++) {
+       java_objectheader *oh=(java_objectheader*)(m->thrownexceptions[i]);
+       use_class_as_object(oh);
+       result->data[i]=oh;
+    }
+    return result;
 }
 
 
@@ -1492,22 +1375,33 @@ return true;
 /*--------------------------------------------------------*/
 
 
-java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start) {
+java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo **start)
+{
+#if defined(__GNUC__)
 #warning platform dependend
+#endif
         java_objectarray *tmpArray;
         int i;
         classinfo **current;
        classinfo *c;
         size_t size=(((size_t)start)-((size_t)end)) / sizeof (classinfo*);
-        printf("end %p, start %p, size %ld\n",end,start,size);
+        /*printf("end %p, start %p, size %ld\n",end,start,size);*/
         if (!class_java_lang_Class)
                 class_java_lang_Class = class_new(utf_new_char ("java/lang/Class"));
+        if (!class_java_lang_SecurityManager)
+                class_java_lang_SecurityManager = class_new(utf_new_char ("java/lang/SecurityManager"));
+       if (size>0) {
+               if (start==class_java_lang_SecurityManager) {
+                       size--;
+                       start--;
+               }
+       }
         tmpArray=builtin_newarray(size, class_array_of(class_java_lang_Class)->vftbl);
 
         for(i=0,current=start;i<size;i++,current--) {
                c=*current;
-               printf("%d\n",i);
-                utf_display(c->name);
+/*             printf("%d\n",i);
+                utf_display(c->name);*/
                use_class_as_object(c);
                tmpArray->data[i]=c;
         }
@@ -1515,15 +1409,27 @@ java_objectarray *builtin_asm_createclasscontextarray(classinfo **end,classinfo
 
 }
 
-java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start) {
+java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **start)
+{
+#if defined(__GNUC__)
 #warning platform dependend
+#endif
         int i;
         classinfo **current;
        classinfo *c;
        classinfo *privilegedAction;
         size_t size=(((size_t)start)-((size_t)end)) / sizeof (classinfo*);
-       log_text("builtin_asm_getclassloader");
-        printf("end %p, start %p, size %ld\n",end,start,size);
+/*     log_text("builtin_asm_getclassloader");
+        printf("end %p, start %p, size %ld\n",end,start,size);*/
+
+        if (!class_java_lang_SecurityManager)
+                class_java_lang_SecurityManager = class_new(utf_new_char ("java/lang/SecurityManager"));
+       if (size>0) {
+               if (start==class_java_lang_SecurityManager) {
+                       size--;
+                       start--;
+               }
+       }
 
        privilegedAction=class_new(utf_new_char("java/security/PrivilegedAction"));