Some changes from my thesis.
[cacao.git] / native.c
index c6aadd279fbe4122530c862f511e1e1c5f3f67c7..1a0ecb8fe1cda484ab626f2589cdefb95bf4e323 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 1082 2004-05-26 15:04:54Z jowenn $
+   $Id: native.c 1567 2004-11-23 16:01:51Z twisti $
 
 */
 
 #include <utime.h>
 
 #include "config.h"
+#include "exceptions.h"
 #include "global.h"
-#include "main.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 "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 <fcntl.h>
 
 #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;
@@ -103,72 +107,6 @@ classinfo *class_java_lang_Integer;
 methodinfo *method_vmclass_init;
 
 
-/* specify some exception strings for code generation */
-
-char *string_java_lang_ArithmeticException =
-    "java/lang/ArithmeticException";
-
-char *string_java_lang_ArithmeticException_message =
-    "/ by zero";
-
-char *string_java_lang_ArrayIndexOutOfBoundsException =
-    "java/lang/ArrayIndexOutOfBoundsException";
-
-char *string_java_lang_ArrayStoreException =
-    "java/lang/ArrayStoreException";
-
-char *string_java_lang_ClassCastException =
-    "java/lang/ClassCastException";
-
-char *string_java_lang_ClassNotFoundException =
-       "java/lang/ClassNotFoundException";
-
-char *string_java_lang_CloneNotSupportedException =
-    "java/lang/CloneNotSupportedException";
-
-char *string_java_lang_IllegalArgumentException =
-    "java/lang/IllegalArgumentException";
-
-char *string_java_lang_IllegalMonitorStateException =
-    "java/lang/IllegalMonitorStateException";
-
-char *string_java_lang_NegativeArraySizeException =
-    "java/lang/NegativeArraySizeException";
-
-char *string_java_lang_NoSuchFieldException =
-       "java/lang/NoSuchFieldException";
-
-char *string_java_lang_NoSuchMethodException =
-       "java/lang/NoSuchMethodException";
-
-char *string_java_lang_NullPointerException =
-    "java/lang/NullPointerException";
-
-
-/* specify some error strings for code generation */
-
-char *string_java_lang_ClassCircularityError =
-    "java/lang/ClassCircularityError";
-
-char *string_java_lang_ClassFormatError =
-    "java/lang/ClassFormatError";
-
-char *string_java_lang_LinkageError =
-    "java/lang/LinkageError";
-
-char *string_java_lang_NoClassDefFoundError =
-    "java/lang/NoClassDefFoundError";
-
-char *string_java_lang_NoSuchFieldError =
-       "java/lang/NoSuchFieldError";
-
-char *string_java_lang_NoSuchMethodError =
-       "java/lang/NoSuchMethodError";
-
-char *string_java_lang_OutOfMemoryError =
-    "java/lang/OutOfMemoryError";
-
-
 /* the system classloader object */
 struct java_lang_ClassLoader *SystemClassLoader = NULL;
 
@@ -181,46 +119,10 @@ java_objectheader* _exceptionptr = NULL;
 
 void use_class_as_object(classinfo *c) 
 {
-/*     vftbl *vt; */
-/*     vftbl *newtbl; */
-       java_objectheader *vmo;
-
-/*     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;
-        
-               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");
-               }
-
-               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;
-#if 0
-               setfield_critical(class_java_lang_Class,vmo,"vmClass",          "Ljava/lang/VMClass;",  jobject, (jobject) class_java_lang_Class /*this*/);
-#endif
-
-       }
+               c->classvftbl = true;
+       }
             
 }
 
@@ -228,12 +130,9 @@ void use_class_as_object(classinfo *c)
 /*************************** include native methods ***************************/ 
 
 #ifdef USE_GTK 
-#include "nat/GdkGraphics.c"
 #include "nat/GtkComponentPeer.c"
-#include "nat/GdkPixbufDecoder.c"
 #include "nat/GtkScrollPanePeer.c"
 #include "nat/GtkFileDialogPeer.c"
-#include "nat/GtkLabelPeer.c"
 #endif
 
 
@@ -242,144 +141,19 @@ 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"
-
-};
-
-
+#ifdef STATIC_CLASSPATH
 #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;
+#endif
 
-
-/******************************************************************************/
-/******************************************************************************/
-#include "natcalls.h"
-
-/* string call comparison table initialized */
-
-/******************************************************************************/
 /******************************************************************************/
 
-/*--------------- native method calls & classes used -------------------------*/
-
-void throw_exception_exit()
-{
-       java_objectheader *xptr;
-       classinfo *c;
-       methodinfo *pss;
-
-       if (*exceptionptr) {
-               xptr = *exceptionptr;
-
-               /* clear exception, because we are calling jit code again */
-               *exceptionptr = NULL;
-
-               printf("Exception in thread \"main\" ");
-               fflush(stdout);
-
-               c = xptr->vftbl->class;
-
-/*             ts = class_resolveclassmethod(c, */
-/*                                                                       utf_new_char("toString"), */
-/*                                                                       utf_new_char("()Ljava/lang/String;"), */
-/*                                                                       class_java_lang_Object, */
-/*                                                                       false); */
-
-/*             if (!ts) { */
-/*                     panic("internal error"); */
-/*             } */
-
-/*             tostring = asm_calljavafunction(ts, xptr, NULL, NULL, NULL); */
-
-/*             utf_display(javastring_toutf(tostring, false)); */
-
-               pss = class_resolveclassmethod(c,
-                                                                          utf_new_char("printStackTrace"),
-                                                                          utf_new_char("()V"),
-                                                                          class_java_lang_Object,
-                                                                          false);
-
-               /* print the stacktrace */
-               if (pss) {
-                       asm_calljavafunction(pss, xptr, NULL, NULL, NULL);
-
-               } else {
-                       panic("printStackTrace not found!");
-               }
-
-               fflush(stdout);
-
-               /* good bye! */
-               exit(1);
-       }
-}
-
-
-java_objectheader *new_exception(char *classname)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init(c);
-}
-
-java_objectheader *new_exception_message(char *classname, char *message)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init_string(c, javastring_new_char(message));
-}
-
-
-java_objectheader *new_exception_throwable(char *classname, java_lang_Throwable *throwable)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init_throwable(c, throwable);
-}
-
-
-java_objectheader *new_exception_utfmessage(char *classname, utf *message)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init_string(c, javastring_new(message));
-}
-
-
-java_objectheader *new_exception_javastring(char *classname, java_lang_String *message)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init_string(c, message);
-}
-
-
-java_objectheader *new_exception_int(char *classname, s4 i)
-{
-       classinfo *c = class_new(utf_new_char(classname));
-
-       return native_new_and_init_int(c, i);
-}
+#include "natcalls.h"
 
 
 /*********************** function: native_loadclasses **************************
@@ -453,6 +227,7 @@ void native_loadclasses()
        class_java_lang_Void = class_new(utf_new_char("java/lang/Void"));
        class_load(class_java_lang_Void);
        class_link(class_java_lang_Void);
+
 }
 
 
@@ -479,15 +254,6 @@ void init_systemclassloader()
 }
 
 
-/********************* 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
@@ -502,6 +268,7 @@ void native_setclasspath(char *path)
 functionptr native_findfunction(utf *cname, utf *mname, 
                                                                utf *desc, bool isstatic)
 {
+#ifdef STATIC_CLASSPATH
        int i;
        /* entry of table for fast string comparison */
        struct nativecompref *n;
@@ -599,6 +366,10 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
        /* keep compiler happy */
        return NULL;
+#else
+/* dynamic classpath */
+  return 0;
+#endif
 }
 
 
@@ -613,12 +384,20 @@ functionptr native_findfunction(utf *cname, utf *mname,
 
 java_lang_String *javastring_new(utf *u)
 {
-       char *utf_ptr = u->text;        /* current utf character in utf string    */
-       int utflength = utf_strlen(u);  /* length of utf-string if uncompressed   */
+       char *utf_ptr;                  /* current utf character in utf string    */
+       u4 utflength;                   /* length of utf-string if uncompressed   */
        java_lang_String *s;                /* result-string                          */
        java_chararray *a;
        s4 i;
-       
+
+       if (!u) {
+               *exceptionptr = new_nullpointerexception();
+               return NULL;
+       }
+
+       utf_ptr = u->text;
+       utflength = utf_strlen(u);
+
        s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(utflength);
 
@@ -651,10 +430,17 @@ java_lang_String *javastring_new(utf *u)
 java_lang_String *javastring_new_char(char *text)
 {
        s4 i;
-       s4 len = strlen(text); /* length of the string */
+       s4 len;                /* length of the string */
        java_lang_String *s;   /* result-string */
        java_chararray *a;
-       
+
+       if (!text) {
+               *exceptionptr = new_nullpointerexception();
+               return NULL;
+       }
+
+       len = strlen(text);
+
        s = (java_lang_String *) builtin_new(class_java_lang_String);
        a = builtin_newarray_char(len);
 
@@ -781,7 +567,7 @@ java_objectheader *native_new_and_init(classinfo *c)
                                                 utf_new_char("()V"));
                                                      
        if (!m) {                           /* initializer not found              */
-               if (verbose) {
+               if (opt_verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
                        utf_sprint_classname(logtext + strlen(logtext), c->name);
@@ -818,7 +604,7 @@ java_objectheader *native_new_and_init_string(classinfo *c, java_lang_String *s)
                                                 utf_new_char("(Ljava/lang/String;)V"));
                                                      
        if (!m) {                                       /* initializer not found  */
-               if (verbose) {
+               if (opt_verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
                        utf_sprint_classname(logtext + strlen(logtext), c->name);
@@ -854,7 +640,7 @@ java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
                                                 utf_new_char("(I)V"));
                                                      
        if (!m) {                                       /* initializer not found  */
-               if (verbose) {
+               if (opt_verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
                        utf_sprint_classname(logtext + strlen(logtext), c->name);
@@ -865,7 +651,11 @@ java_objectheader *native_new_and_init_int(classinfo *c, s4 i)
 
        /* call initializer */
 
+#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;
 }
@@ -890,7 +680,7 @@ java_objectheader *native_new_and_init_throwable(classinfo *c, java_lang_Throwab
                                                 utf_new_char("(Ljava/lang/Throwable;)V"));
                                                      
        if (!m) {                                       /* initializer not found  */
-               if (verbose) {
+               if (opt_verbose) {
                        char logtext[MAXLOGTEXT];
                        sprintf(logtext, "Warning: class has no instance-initializer: ");
                        utf_sprint_classname(logtext + strlen(logtext), c->name);
@@ -1001,12 +791,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;
 
@@ -1088,11 +872,11 @@ 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;  
+    u4 key;
+    u4 slot;
     u2 i;
 
-//#define DEBUG_LITERALSTRING_U2
+/* #define DEBUG_LITERALSTRING_U2 */
 #ifdef DEBUG_LITERALSTRING_U2
     printf("literalstring_u2: length=%d, offset=%d\n", length, offset);
        fflush(stdout);
@@ -1115,7 +899,7 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
 
                        /* string already in hashtable, free memory */
                        if (!copymode)
-                               lit_mem_free(a, sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10);
+                               mem_free(a, sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10);
 
 #ifdef DEBUG_LITERALSTRING_U2
                        printf("literalstring_u2: foundentry at %p\n", js);
@@ -1134,7 +918,7 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
     if (copymode) {
                /* create copy of u2-array for new javastring */
                u4 arraysize = sizeof(java_chararray) + sizeof(u2) * (length - 1) + 10;
-               stringdata = lit_mem_alloc(arraysize);
+               stringdata = mem_alloc(arraysize);
 /*             memcpy(stringdata, a, arraysize); */
                memcpy(&(stringdata->header), &(a->header), sizeof(java_arrayheader));
                memcpy(&(stringdata->data), &(a->data) + offset, sizeof(u2) * (length - 1) + 10);
@@ -1147,31 +931,50 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
     stringdata->header.objheader.vftbl = primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl;
     stringdata->header.size = length;
 
-    /* create new javastring */
-    js = LNEW(java_lang_String);
-       /* TWISTI */
-/*      js->header.vftbl = class_java_lang_String->vftbl; */
-    js->header.vftbl = class_load(class_new(utf_new_char("java/lang/String")))->vftbl;
-    js->value  = stringdata;
-    js->offset = 0;
-    js->count  = length;
-
-    /* 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 */
-    string_hash.entries++;
-
-    /* reorganization of hashtable */       
-    if (string_hash.entries > (string_hash.size * 2)) {
+       /* 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 = NEW(java_lang_String);
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+       initObjectLock(&js->header);
+#endif
+       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 number of hashtable entries */
+       string_hash.entries++;
+
+       /* reorganization of hashtable */       
+       if (string_hash.entries > (string_hash.size * 2)) {
                /* reorganization of hashtable, average length of 
-         the external chains is approx. 2                */  
+                  the external chains is approx. 2                */  
 
                u4 i;
-               literalstring *s;     
+               literalstring *s;
                hashtable newhash; /* the new hashtable */
       
                /* create new hashtable, double the size */
@@ -1197,16 +1000,9 @@ java_objectheader *literalstring_u2(java_chararray *a, u4 length, u4 offset,
                /* dispose old table */ 
                MFREE(string_hash.ptr, void*, string_hash.size);
                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;
+       return (java_objectheader *) js;
 }
 
 
@@ -1225,7 +1021,7 @@ java_objectheader *literalstring_new(utf *u)
     u4 i;
 
     /* allocate memory */ 
-    a = lit_mem_alloc(sizeof(java_chararray) + sizeof(u2) * (utflength - 1) + 10);
+    a = mem_alloc(sizeof(java_chararray) + sizeof(u2) * (utflength - 1) + 10);
 
     /* convert utf-string to u2-array */
     for (i = 0; i < utflength; i++)
@@ -1247,14 +1043,14 @@ void literalstring_free(java_objectheader* sobj)
        java_chararray *a = s->value;
 
        /* dispose memory of java.lang.String object */
-       LFREE(s, java_lang_String);
+       FREE(s, java_lang_String);
 
        /* dispose memory of java-characterarray */
-       LFREE(a, sizeof(java_chararray) + sizeof(u2) * (a->header.size - 1)); /* +10 ?? */
+       FREE(a, sizeof(java_chararray) + sizeof(u2) * (a->header.size - 1)); /* +10 ?? */
 }
 
 
-void copy_vftbl(vftbl **dest, vftbl *src)
+void copy_vftbl(vftbl_t **dest, vftbl_t *src)
 {
     *dest = src;
 #if 0
@@ -1296,7 +1092,7 @@ utf *create_methodsig(java_objectarray* types, char *retType)
     if (retType) buffer_size += strlen(retType);
 
     /* allocate buffer */
-    buffer = MNEW(u1, buffer_size);
+    buffer = MNEW(char, buffer_size);
     pos    = buffer;
     
     /* method-desciptor starts with parenthesis */
@@ -1362,7 +1158,7 @@ utf *create_methodsig(java_objectarray* types, char *retType)
 
     /* create utf-string */
     result = utf_new(buffer, (pos - buffer));
-    MFREE(buffer, u1, buffer_size);
+    MFREE(buffer, char, buffer_size);
 
     return result;
 }
@@ -1390,12 +1186,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) 
 {
@@ -1410,45 +1206,49 @@ 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) {
-    u2 exccount=m->thrownexceptionscount;
+java_objectarray* get_exceptiontypes(methodinfo *m)
+{
+    u2 excount;
     u2 i;
     java_objectarray *result;
+
+       excount = m->thrownexceptionscount;
+
     /* 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;
+    result = builtin_anewarray(excount, class_java_lang_Class);
+
+    for (i = 0; i < excount; i++) {
+               java_objectheader *o = (java_objectheader *) (m->thrownexceptions[i]);
+               use_class_as_object((classinfo *) o);
+               result->data[i] = o;
     }
+
     return result;
 }
 
@@ -1602,51 +1402,71 @@ 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
-        java_objectarray *tmpArray;
-        int i;
-        classinfo **current;
+#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);*/
-        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_t size;
+
+       size = (((size_t) start) - ((size_t) end)) / sizeof(classinfo*);
+
+       /*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);
+       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);*/
                use_class_as_object(c);
-               tmpArray->data[i]=c;
-        }
-       return tmpArray;
+               tmpArray->data[i] = (java_objectheader *) c;
+       }
 
+       return tmpArray;
 }
 
-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
-        int i;
-        classinfo **current;
+#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");
+       size_t size;
+
+       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);*/
 
-        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) {
+       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--;
                }
@@ -1654,23 +1474,26 @@ java_lang_ClassLoader *builtin_asm_getclassloader(classinfo **end,classinfo **st
 
        privilegedAction=class_new(utf_new_char("java/security/PrivilegedAction"));
 
-        for(i=0,current=start;i<size;i++,current--) {
-               c=*current;
-               if (c==privilegedAction) return NULL;
-               if (c->classloader) return c->classloader;
-        }
-       return NULL;
+       for(i = 0, current = start; i < size; i++, current--) {
+               c = *current;
 
+               if (c == privilegedAction)
+                       return NULL;
 
+               if (c->classloader)
+                       return (java_lang_ClassLoader *) c->classloader;
+       }
 
+       return NULL;
 
-/*
+       /*
         log_text("Java_java_lang_VMSecurityManager_currentClassLoader");
         init_systemclassloader();
 
         return SystemClassLoader;*/
 }
 
+
 /*
  * 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