X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=builtin.c;h=ae8f01742b4923add036e91635961a3d66f8f627;hb=a23aa5f8faa05bab8bfcae2d2c47b25de7c55269;hp=4aadbfa8b8a299d552a8831791dfcd08fc44d921;hpb=bf9ddb371291268b8938b47089b1db5f394262e0;p=cacao.git diff --git a/builtin.c b/builtin.c index 4aadbfa8b..ae8f01742 100644 --- a/builtin.c +++ b/builtin.c @@ -34,7 +34,7 @@ calls instead of machine instructions, using the C calling convention. - $Id: builtin.c 851 2004-01-05 23:59:28Z stefan $ + $Id: builtin.c 1369 2004-08-01 21:53:32Z stefan $ */ @@ -42,8 +42,9 @@ #include #include #include -#include "main.h" +#include "exceptions.h" #include "global.h" +#include "options.h" #include "builtin.h" #include "native.h" #include "loader.h" @@ -52,7 +53,7 @@ #include "mm/boehm.h" #include "threads/thread.h" #include "threads/locks.h" -#include "toolbox/loging.h" +#include "toolbox/logging.h" #include "toolbox/memory.h" #include "nat/java_lang_Cloneable.h" #include "nat/java_lang_VMObject.h" @@ -60,103 +61,8 @@ #undef DEBUG /*define DEBUG 1*/ -/* XXX delete? */ -#if 0 -builtin_descriptor builtin_desc[] = { - {(functionptr) builtin_instanceof, "instanceof"}, - {(functionptr) builtin_checkcast, "checkcast"}, - {(functionptr) asm_builtin_checkcast, "checkcast"}, - {(functionptr) builtin_arrayinstanceof, "arrayinstanceof"}, -#if defined(__I386__) - {(functionptr) asm_builtin_arrayinstanceof,"arrayinstanceof"}, -#endif - {(functionptr) builtin_checkarraycast, "checkarraycast"}, - {(functionptr) asm_builtin_checkarraycast, "checkarraycast"}, - {(functionptr) asm_builtin_aastore, "aastore"}, - {(functionptr) builtin_new, "new"}, - {(functionptr) builtin_newarray, "newarray"}, - {(functionptr) builtin_anewarray, "anewarray"}, -#if defined(__I386__) - /* - * have 2 parameters (needs stack manipulation) - */ - {(functionptr) asm_builtin_newarray, "newarray"}, -#endif - {(functionptr) builtin_newarray_boolean, "newarray_boolean"}, - {(functionptr) builtin_newarray_char, "newarray_char"}, - {(functionptr) builtin_newarray_float, "newarray_float"}, - {(functionptr) builtin_newarray_double, "newarray_double"}, - {(functionptr) builtin_newarray_byte, "newarray_byte"}, - {(functionptr) builtin_newarray_short, "newarray_short"}, - {(functionptr) builtin_newarray_int, "newarray_int"}, - {(functionptr) builtin_newarray_long, "newarray_long"}, - {(functionptr) builtin_displaymethodstart, "displaymethodstart"}, - {(functionptr) builtin_displaymethodstop, "displaymethodstop"}, - {(functionptr) builtin_monitorenter, "monitorenter"}, - {(functionptr) asm_builtin_monitorenter, "monitorenter"}, - {(functionptr) builtin_monitorexit, "monitorexit"}, - {(functionptr) asm_builtin_monitorexit, "monitorexit"}, -#if !SUPPORT_DIVISION - {(functionptr) builtin_idiv, "idiv"}, - {(functionptr) asm_builtin_idiv, "idiv"}, - {(functionptr) builtin_irem, "irem"}, - {(functionptr) asm_builtin_irem, "irem"}, -#endif - {(functionptr) builtin_ladd, "ladd"}, - {(functionptr) builtin_lsub, "lsub"}, - {(functionptr) builtin_lmul, "lmul"}, -#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) - {(functionptr) builtin_ldiv, "ldiv"}, - {(functionptr) asm_builtin_ldiv, "ldiv"}, - {(functionptr) builtin_lrem, "lrem"}, - {(functionptr) asm_builtin_lrem, "lrem"}, -#endif - {(functionptr) builtin_lshl, "lshl"}, - {(functionptr) builtin_lshr, "lshr"}, - {(functionptr) builtin_lushr, "lushr"}, - {(functionptr) builtin_land, "land"}, - {(functionptr) builtin_lor, "lor"}, - {(functionptr) builtin_lxor, "lxor"}, - {(functionptr) builtin_lneg, "lneg"}, - {(functionptr) builtin_lcmp, "lcmp"}, - {(functionptr) builtin_fadd, "fadd"}, - {(functionptr) builtin_fsub, "fsub"}, - {(functionptr) builtin_fmul, "fmul"}, - {(functionptr) builtin_fdiv, "fdiv"}, - {(functionptr) builtin_frem, "frem"}, - {(functionptr) builtin_fneg, "fneg"}, - {(functionptr) builtin_fcmpl, "fcmpl"}, - {(functionptr) builtin_fcmpg, "fcmpg"}, - {(functionptr) builtin_dadd, "dadd"}, - {(functionptr) builtin_dsub, "dsub"}, - {(functionptr) builtin_dmul, "dmul"}, - {(functionptr) builtin_ddiv, "ddiv"}, - {(functionptr) builtin_drem, "drem"}, - {(functionptr) builtin_dneg, "dneg"}, - {(functionptr) builtin_dcmpl, "dcmpl"}, - {(functionptr) builtin_dcmpg, "dcmpg"}, - {(functionptr) builtin_i2l, "i2l"}, - {(functionptr) builtin_i2f, "i2f"}, - {(functionptr) builtin_i2d, "i2d"}, - {(functionptr) builtin_l2i, "l2i"}, - {(functionptr) builtin_l2f, "l2f"}, - {(functionptr) builtin_l2d, "l2d"}, - {(functionptr) builtin_f2i, "f2i"}, - {(functionptr) builtin_f2l, "f2l"}, - {(functionptr) builtin_f2d, "f2d"}, - {(functionptr) builtin_d2i, "d2i"}, - {(functionptr) builtin_d2l, "d2l"}, -#if defined(__I386__) - {(functionptr) asm_builtin_f2i, "f2i"}, - {(functionptr) asm_builtin_f2l, "f2l"}, - {(functionptr) asm_builtin_d2i, "d2i"}, - {(functionptr) asm_builtin_d2l, "d2l"}, -#endif - {(functionptr) builtin_d2f, "d2f"}, - {(functionptr) NULL, "unknown"} -}; -#endif - +THREADSPECIFIC methodinfo* _threadrootmethod = NULL; +THREADSPECIFIC void *_thread_nativestackframeinfo=NULL; /***************************************************************************** TYPE CHECKS @@ -175,6 +81,7 @@ builtin_descriptor builtin_desc[] = { s4 builtin_isanysubclass(classinfo *sub, classinfo *super) { s4 res; + castinfo classvalues; /*classinfo *tmp;*/ if (super->flags & ACC_INTERFACE) @@ -209,41 +116,29 @@ s4 builtin_isanysubclass(classinfo *sub, classinfo *super) sub->vftbl->baseval, super->vftbl->baseval, (unsigned)(sub->vftbl->baseval - super->vftbl->baseval), super->vftbl->diffval); */ -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_lock(); -#endif - - res = (unsigned) (sub->vftbl->baseval - super->vftbl->baseval) <= - (unsigned) (super->vftbl->diffval); + asm_getclassvalues_atomic(super->vftbl, sub->vftbl, &classvalues); -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_unlock(); -#endif + res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval) <= + (unsigned) classvalues.super_diffval; return res; } -/* XXX inline this? */ -s4 builtin_isanysubclass_vftbl(vftbl *sub,vftbl *super) +s4 builtin_isanysubclass_vftbl(vftbl_t *sub,vftbl_t *super) { - int base; s4 res; + int base; + castinfo classvalues; -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_lock(); -#endif + asm_getclassvalues_atomic(super, sub, &classvalues); - if ((base = super->baseval) <= 0) + if ((base = classvalues.super_baseval) <= 0) /* super is an interface */ res = (sub->interfacetablelength > -base) && (sub->interfacetable[base] != NULL); else - res = (unsigned) (sub->baseval - base) - <= (unsigned) (super->diffval); - -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_unlock(); -#endif + res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval) + <= (unsigned) classvalues.super_diffval; return res; } @@ -310,7 +205,6 @@ s4 builtin_checkcast(java_objectheader *obj, classinfo *class) ******************************************************************************/ -/* XXX inline this? */ static s4 builtin_descriptorscompatible(arraydescriptor *desc,arraydescriptor *target) { if (desc==target) return 1; @@ -318,8 +212,11 @@ static s4 builtin_descriptorscompatible(arraydescriptor *desc,arraydescriptor *t if (desc->arraytype != ARRAYTYPE_OBJECT) return 1; /* {both arrays are arrays of references} */ - if (desc->dimension == target->dimension) + if (desc->dimension == target->dimension) { + /* an array which contains elements of interface types is allowed to be casted to Object (JOWENN)*/ + if ( (desc->elementvftbl->baseval<0) && (target->elementvftbl->baseval==1) ) return 1; return builtin_isanysubclass_vftbl(desc->elementvftbl,target->elementvftbl); + } if (desc->dimension < target->dimension) return 0; /* {desc has higher dimension than target} */ @@ -344,7 +241,7 @@ static s4 builtin_descriptorscompatible(arraydescriptor *desc,arraydescriptor *t *****************************************************************************/ -s4 builtin_checkarraycast(java_objectheader *o, vftbl *target) +s4 builtin_checkarraycast(java_objectheader *o, vftbl_t *target) { arraydescriptor *desc; @@ -355,7 +252,7 @@ s4 builtin_checkarraycast(java_objectheader *o, vftbl *target) } -s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl *target) +s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl_t *target) { if (!obj) return 1; return builtin_checkarraycast(obj, target); @@ -366,60 +263,35 @@ s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl *target) ******************************************************************************/ -java_objectheader *builtin_throw_exception(java_objectheader *local_exceptionptr) +java_objectheader *builtin_throw_exception(java_objectheader *xptr) { if (verbose) { char logtext[MAXLOGTEXT]; sprintf(logtext, "Builtin exception thrown: "); - if (local_exceptionptr) - utf_sprint(logtext + strlen(logtext), local_exceptionptr->vftbl->class->name); - else { - sprintf(logtext+strlen(logtext),"%s","Error: "); - if (!proto_java_lang_ClassCastException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ClassCastException==0"); - if (!proto_java_lang_NullPointerException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_NullPointerException==0"); - if (!proto_java_lang_NullPointerException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_NullPointerException==0"); - if (!proto_java_lang_ArrayIndexOutOfBoundsException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ArrayIndexOutOfBoundsException==0"); - if (!proto_java_lang_NegativeArraySizeException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_NegativeArraySizeException==0"); - if (!proto_java_lang_OutOfMemoryError) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_OutOfMemoryError==0"); - if (!proto_java_lang_ArithmeticException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ArithmeticException==0"); - if (!proto_java_lang_ArrayStoreException) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ArrayStoreException==0"); - if (!proto_java_lang_ThreadDeath) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ThreadDeath==0"); - if (!proto_java_lang_ThreadDeath) sprintf(logtext+strlen(logtext),"%s","proto_java_lang_ThreadDeath==0"); + if (xptr) { + java_lang_Throwable *t = (java_lang_Throwable *) xptr; + + utf_sprint_classname(logtext + strlen(logtext), + xptr->vftbl->class->name); + + if (t->detailMessage) { + sprintf(logtext + strlen(logtext), ": %s", + javastring_tochar(t->detailMessage)); } + + } else { + sprintf(logtext + strlen(logtext), "Error: "); + } log_text(logtext); } - exceptionptr = local_exceptionptr; - return local_exceptionptr; -} -java_objectheader *builtin_get_exceptionptr() -{ -#if defined(USE_THREADS) && defined(NATIVE_THREADS) -#ifdef HAVE___THREAD - return exceptionptr; -#else - pthread_getspecific(tkey_exceptionptr); -#endif -#else - panic("builtin_get_exceptionptr should not be used in this configuration"); - return NULL; -#endif -} + *exceptionptr = xptr; -void builtin_set_exceptionptr(java_objectheader *e) -{ -#if defined(USE_THREADS) && defined(NATIVE_THREADS) -#ifdef HAVE___THREAD - exceptionptr = e; -#else - pthread_setspecific(tkey_exceptionptr, e); -#endif -#else - panic("builtin_set_exceptionptr should not be used in this configuration"); -#endif + return xptr; } + /******************* function: builtin_canstore ******************************* Checks, if an object can be stored in an array. @@ -432,10 +304,11 @@ s4 builtin_canstore (java_objectarray *a, java_objectheader *o) { arraydescriptor *desc; arraydescriptor *valuedesc; - vftbl *componentvftbl; - vftbl *valuevftbl; + vftbl_t *componentvftbl; + vftbl_t *valuevftbl; int dim_m1; int base; + castinfo classvalues; if (!o) return 1; @@ -459,21 +332,15 @@ s4 builtin_canstore (java_objectarray *a, java_objectheader *o) if (valuevftbl == componentvftbl) return 1; - if ((base = componentvftbl->baseval) <= 0) + asm_getclassvalues_atomic(componentvftbl, valuevftbl, &classvalues); + + if ((base = classvalues.super_baseval) <= 0) /* an array of interface references */ return (valuevftbl->interfacetablelength > -base && valuevftbl->interfacetable[base] != NULL); -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_lock(); -#endif - - res = (unsigned)(valuevftbl->baseval - base) - <= (unsigned)(componentvftbl->diffval); - -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_unlock(); -#endif + res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval) + <= (unsigned) classvalues.super_diffval; return res; } @@ -493,10 +360,11 @@ s4 builtin_canstore (java_objectarray *a, java_objectheader *o) s4 builtin_canstore_onedim (java_objectarray *a, java_objectheader *o) { arraydescriptor *desc; - vftbl *elementvftbl; - vftbl *valuevftbl; - int base; + vftbl_t *elementvftbl; + vftbl_t *valuevftbl; s4 res; + int base; + castinfo classvalues; if (!o) return 1; @@ -517,21 +385,15 @@ s4 builtin_canstore_onedim (java_objectarray *a, java_objectheader *o) if (valuevftbl == elementvftbl) return 1; - if ((base = elementvftbl->baseval) <= 0) + asm_getclassvalues_atomic(elementvftbl, valuevftbl, &classvalues); + + if ((base = classvalues.super_baseval) <= 0) /* an array of interface references */ return (valuevftbl->interfacetablelength > -base && valuevftbl->interfacetable[base] != NULL); - -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_lock(); -#endif - - res = (unsigned)(valuevftbl->baseval - base) - <= (unsigned)(elementvftbl->diffval); -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_unlock(); -#endif + res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval) + <= (unsigned) classvalues.super_diffval; return res; } @@ -539,12 +401,12 @@ s4 builtin_canstore_onedim (java_objectarray *a, java_objectheader *o) /* This is an optimized version where a is guaranteed to be a * one-dimensional array of a class type */ -/* XXX this could be inlined by the code generator */ s4 builtin_canstore_onedim_class(java_objectarray *a, java_objectheader *o) { - vftbl *elementvftbl; - vftbl *valuevftbl; + vftbl_t *elementvftbl; + vftbl_t *valuevftbl; s4 res; + castinfo classvalues; if (!o) return 1; @@ -565,16 +427,10 @@ s4 builtin_canstore_onedim_class(java_objectarray *a, java_objectheader *o) if (valuevftbl == elementvftbl) return 1; -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_lock(); -#endif + asm_getclassvalues_atomic(elementvftbl, valuevftbl, &classvalues); - res = (unsigned)(valuevftbl->baseval - elementvftbl->baseval) - <= (unsigned)(elementvftbl->diffval); - -#if defined(USE_THREADS) && defined(NATIVE_THREADS) - cast_unlock(); -#endif + res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval) + <= (unsigned) classvalues.super_diffval; return res; } @@ -595,7 +451,23 @@ java_objectheader *builtin_new(classinfo *c) { java_objectheader *o; - class_init(c); + /* is the class loaded */ + if (!c->loaded) + if (!class_load(c)) + return NULL; + + /* is the class linked */ + if (!c->linked) + if (!class_link(c)) + return NULL; + + if (!c->initialized) { + if (initverbose) + log_message_class("Initialize class (from builtin_new): ", c); + + if (!class_init(c)) + return NULL; + } #ifdef SIZE_FROM_CLASSINFO c->alignedsize = align_size(c->instancesize); @@ -603,15 +475,21 @@ java_objectheader *builtin_new(classinfo *c) #else o = heap_allocate(c->instancesize, true, c->finalizer); #endif - if (!o) return NULL; - + + if (!o) + return NULL; + memset(o, 0, c->instancesize); o->vftbl = c->vftbl; +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + initObjectLock(o); +#endif return o; } + /********************** Function: builtin_newarray ************************** Creates an array with the given vftbl on the heap. @@ -623,39 +501,49 @@ java_objectheader *builtin_new(classinfo *c) *****************************************************************************/ -java_arrayheader *builtin_newarray(s4 size, vftbl *arrayvftbl) +java_arrayheader *builtin_newarray(s4 size, vftbl_t *arrayvftbl) { java_arrayheader *a; - arraydescriptor *desc = arrayvftbl->arraydesc; - s4 dataoffset = desc->dataoffset; - s4 componentsize = desc->componentsize; + arraydescriptor *desc; + s4 dataoffset; + s4 componentsize; s4 actualsize; - if (size<0) { - exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/NegativeArraySizeException"))); + desc = arrayvftbl->arraydesc; + dataoffset = desc->dataoffset; + componentsize = desc->componentsize; + + if (size < 0) { + *exceptionptr = + new_exception(string_java_lang_NegativeArraySizeException); return NULL; } + #ifdef SIZE_FROM_CLASSINFO actualsize = align_size(dataoffset + size * componentsize); -#else actualsize = dataoffset + size * componentsize; +#else + actualsize = 0; #endif - if (((u4)actualsize)<((u4)size)) { /* overflow */ - exceptionptr = native_new_and_init(loader_load(utf_new_char("java/lang/OutOfMemoryError"))); + if (((u4) actualsize) < ((u4) size)) { /* overflow */ + *exceptionptr = new_exception(string_java_lang_OutOfMemoryError); return NULL; } + a = heap_allocate(actualsize, (desc->arraytype == ARRAYTYPE_OBJECT), NULL); - if (!a) return NULL; - memset(a, 0, actualsize); - + if (!a) + return NULL; - /*printf("builtin_newarray: Created an array of size : %d\n",size);*/ + memset(a, 0, actualsize); a->objheader.vftbl = arrayvftbl; +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + initObjectLock(&a->objheader); +#endif a->size = size; #ifdef SIZE_FROM_CLASSINFO a->alignedsize = actualsize; @@ -669,7 +557,7 @@ java_arrayheader *builtin_newarray(s4 size, vftbl *arrayvftbl) Creates an array of references to the given class type on the heap. - Return value: pointer to the array or NULL if no memory is available + Return value: pointer to the array or NULL if no memory is available XXX This function does not do The Right Thing, because it uses a classinfo pointer at runtime. builtin_newarray should be used @@ -679,7 +567,17 @@ java_arrayheader *builtin_newarray(s4 size, vftbl *arrayvftbl) java_objectarray *builtin_anewarray(s4 size, classinfo *component) { - return (java_objectarray*) builtin_newarray(size, class_array_of(component)->vftbl); + /* is class loaded */ + if (!component->loaded) + if (!class_load(component)) + return NULL; + + /* is class linked */ + if (!component->linked) + if (!class_link(component)) + return NULL; + + return (java_objectarray *) builtin_newarray(size, class_array_of(component)->vftbl); } @@ -810,33 +708,47 @@ java_booleanarray *builtin_newarray_boolean(s4 size) ******************************************************************************/ - /* Helper functions */ - -java_arrayheader *builtin_nmultianewarray (int n, vftbl *arrayvftbl, long *dims) +java_arrayheader *builtin_nmultianewarray(int n, vftbl_t *arrayvftbl, long *dims) +/* java_arrayheader *builtin_nmultianewarray(int n, classinfo *arrayclass, long *dims) */ { - int size, i; + s4 size, i; java_arrayheader *a; - vftbl *componentvftbl; + vftbl_t *componentvftbl; + +/* utf_display(arrayclass->name); */ +/* class_load(arrayclass); */ +/* class_link(arrayclass); */ + /* create this dimension */ - size = (int) dims[0]; - a = builtin_newarray(size,arrayvftbl); - if (!a) return NULL; + size = (s4) dims[0]; + a = builtin_newarray(size, arrayvftbl); +/* a = builtin_newarray(size, arrayclass->vftbl); */ + + if (!a) + return NULL; /* if this is the last dimension return */ - if (!--n) return a; + if (!--n) + return a; /* get the vftbl of the components to create */ componentvftbl = arrayvftbl->arraydesc->componentvftbl; - if (!componentvftbl) /* XXX the verifier could check this */ - panic ("multianewarray with too many dimensions"); +/* component = arrayclass->vftbl->arraydesc; */ + + /* The verifier guarantees this. */ + /* if (!componentvftbl) */ + /* panic ("multianewarray with too many dimensions"); */ /* create the component arrays */ for (i = 0; i < size; i++) { java_arrayheader *ea = - builtin_nmultianewarray(n,componentvftbl,dims+1); - if (!ea) return NULL; - ((java_objectarray*)a)->data[i] = (java_objectheader *) ea; + builtin_nmultianewarray(n, componentvftbl, dims + 1); + + if (!ea) + return NULL; + + ((java_objectarray *) a)->data[i] = (java_objectheader *) ea; } return a; @@ -851,12 +763,13 @@ java_arrayheader *builtin_nmultianewarray (int n, vftbl *arrayvftbl, long *dims) *****************************************************************************/ - u4 methodindent = 0; -java_objectheader *builtin_trace_exception(java_objectheader *exceptionptr, - methodinfo *method, int *pos, - int noindent) +java_objectheader *builtin_trace_exception(java_objectheader *xptr, + methodinfo *m, + void *pos, + s4 line, + s4 noindent) { if (!noindent) { if (methodindent) @@ -864,41 +777,42 @@ java_objectheader *builtin_trace_exception(java_objectheader *exceptionptr, else log_text("WARNING: unmatched methodindent--"); } - if (verbose || runverbose) { - printf("Exception "); - if (exceptionptr) { - utf_display (exceptionptr->vftbl->class->name); - } - else { - printf("Error: "); - if (!proto_java_lang_ClassCastException) printf("%s","proto_java_lang_ClassCastException==0"); - if (!proto_java_lang_NullPointerException) printf("%s","proto_java_lang_NullPointerException==0"); - if (!proto_java_lang_NullPointerException) printf("%s","proto_java_lang_NullPointerException==0"); - if (!proto_java_lang_ArrayIndexOutOfBoundsException) printf("%s","proto_java_lang_ArrayIndexOutOfBoundsException==0"); - if (!proto_java_lang_NegativeArraySizeException) printf("%s","proto_java_lang_NegativeArraySizeException==0"); - if (!proto_java_lang_OutOfMemoryError) printf("%s","proto_java_lang_OutOfMemoryError==0"); - if (!proto_java_lang_ArithmeticException) printf("%s","proto_java_lang_ArithmeticException==0"); - if (!proto_java_lang_ArrayStoreException) printf("%s","proto_java_lang_ArrayStoreException==0"); - if (!proto_java_lang_ThreadDeath) printf("%s","proto_java_lang_ThreadDeath==0"); - if (!proto_java_lang_ThreadDeath) printf("%s","proto_java_lang_ThreadDeath==0"); + if (verbose || runverbose || verboseexception) { + if (xptr) { + printf("Exception "); + utf_display_classname(xptr->vftbl->class->name); + } else { + printf("Some Throwable"); } printf(" thrown in "); - if (method) { - utf_display (method->class->name); + + if (m) { + utf_display_classname(m->class->name); printf("."); - utf_display (method->name); - if (method->flags & ACC_SYNCHRONIZED) - printf("(SYNC)"); + utf_display(m->name); + if (m->flags & ACC_SYNCHRONIZED) + printf("(SYNC"); else - printf("(NOSYNC)"); - printf("(%p) at position %p\n", method->entrypoint, pos); - } - else + printf("(NOSYNC"); + if (m->flags & ACC_NATIVE) { + printf(",NATIVE"); + printf(")(%p) at position %p\n", m->entrypoint, pos); + } else { + printf(")(%p) at position %p (", m->entrypoint, pos); + if (m->class->sourcefile==NULL) + printf(""); + else + utf_display(m->class->sourcefile); + printf(":%d)\n", line); + } + + } else printf("call_java_method\n"); fflush (stdout); } - return exceptionptr; + + return xptr; } @@ -907,24 +821,39 @@ void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, #if TRACE_ARGS_NUM > 6 s8 a6, s8 a7, #endif - methodinfo *method) + methodinfo *m) { - int i; + s4 i; char logtext[MAXLOGTEXT]; for (i = 0; i < methodindent; i++) logtext[i] = '\t'; + sprintf(logtext + methodindent, "called: "); - utf_sprint(logtext + strlen(logtext), method->class->name); + utf_sprint_classname(logtext + strlen(logtext), m->class->name); sprintf(logtext + strlen(logtext), "."); - utf_sprint(logtext + strlen(logtext), method->name); - utf_sprint(logtext + strlen(logtext), method->descriptor); + utf_sprint(logtext + strlen(logtext), m->name); + utf_sprint_classname(logtext + strlen(logtext), m->descriptor); + + if (m->flags & ACC_PUBLIC) sprintf(logtext + strlen(logtext), " PUBLIC"); + if (m->flags & ACC_PRIVATE) sprintf(logtext + strlen(logtext), " PRIVATE"); + if (m->flags & ACC_PROTECTED) sprintf(logtext + strlen(logtext), " PROTECTED"); + if (m->flags & ACC_STATIC) sprintf(logtext + strlen(logtext), " STATIC"); + if (m->flags & ACC_FINAL) sprintf(logtext + strlen(logtext), " FINAL"); + if (m->flags & ACC_SYNCHRONIZED) sprintf(logtext + strlen(logtext), " SYNCHRONIZED"); + if (m->flags & ACC_VOLATILE) sprintf(logtext + strlen(logtext), " VOLATILE"); + if (m->flags & ACC_TRANSIENT) sprintf(logtext + strlen(logtext), " TRANSIENT"); + if (m->flags & ACC_NATIVE) sprintf(logtext + strlen(logtext), " NATIVE"); + if (m->flags & ACC_INTERFACE) sprintf(logtext + strlen(logtext), " INTERFACE"); + if (m->flags & ACC_ABSTRACT) sprintf(logtext + strlen(logtext), " ABSTRACT"); + + sprintf(logtext + strlen(logtext), "("); - switch (method->paramcount) { + switch (m->paramcount) { case 0: break; -#if defined(__I386__) +#if defined(__I386__) || defined(__POWERPC__) case 1: sprintf(logtext+strlen(logtext), "%llx", a0); break; @@ -965,12 +894,12 @@ void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, default: sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, %llx, %llx, ...(%d)", - a0, a1, a2, a3, a4, a5, a6, a7, method->paramcount - 8); + a0, a1, a2, a3, a4, a5, a6, a7, m->paramcount - 8); break; #else default: sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, ...(%d)", - a0, a1, a2, a3, a4, a5, method->paramcount - 6); + a0, a1, a2, a3, a4, a5, m->paramcount - 6); break; #endif #else @@ -1014,17 +943,18 @@ void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, default: sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx, ...(%d)", - a0, a1, a2, a3, a4, a5, a6, a7, method->paramcount - 8); + a0, a1, a2, a3, a4, a5, a6, a7, m->paramcount - 8); break; #else default: sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx, ...(%d)", - a0, a1, a2, a3, a4, a5, method->paramcount - 6); + a0, a1, a2, a3, a4, a5, m->paramcount - 6); break; #endif #endif } - sprintf (logtext+strlen(logtext), ")"); + + sprintf(logtext + strlen(logtext), ")"); log_text(logtext); methodindent++; @@ -1032,21 +962,34 @@ void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3, s8 a4, s8 a5, #endif -void builtin_displaymethodstart(methodinfo *method) +void builtin_displaymethodstart(methodinfo *m) { char logtext[MAXLOGTEXT]; sprintf(logtext, " "); sprintf(logtext + methodindent, "called: "); - utf_sprint(logtext + strlen(logtext), method->class->name); + utf_sprint(logtext + strlen(logtext), m->class->name); sprintf(logtext + strlen(logtext), "."); - utf_sprint(logtext + strlen(logtext), method->name); - utf_sprint(logtext + strlen(logtext), method->descriptor); + utf_sprint(logtext + strlen(logtext), m->name); + utf_sprint(logtext + strlen(logtext), m->descriptor); + + if (m->flags & ACC_PUBLIC) sprintf(logtext + strlen(logtext), " PUBLIC"); + if (m->flags & ACC_PRIVATE) sprintf(logtext + strlen(logtext), " PRIVATE"); + if (m->flags & ACC_PROTECTED) sprintf(logtext + strlen(logtext), " PROTECTED"); + if (m->flags & ACC_STATIC) sprintf(logtext + strlen(logtext), " STATIC"); + if (m->flags & ACC_FINAL) sprintf(logtext + strlen(logtext), " FINAL"); + if (m->flags & ACC_SYNCHRONIZED) sprintf(logtext + strlen(logtext), " SYNCHRONIZED"); + if (m->flags & ACC_VOLATILE) sprintf(logtext + strlen(logtext), " VOLATILE"); + if (m->flags & ACC_TRANSIENT) sprintf(logtext + strlen(logtext), " TRANSIENT"); + if (m->flags & ACC_NATIVE) sprintf(logtext + strlen(logtext), " NATIVE"); + if (m->flags & ACC_INTERFACE) sprintf(logtext + strlen(logtext), " INTERFACE"); + if (m->flags & ACC_ABSTRACT) sprintf(logtext + strlen(logtext), " ABSTRACT"); + log_text(logtext); methodindent++; } -void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f) +void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f) { int i; char logtext[MAXLOGTEXT]; @@ -1056,33 +999,38 @@ void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f) methodindent--; else log_text("WARNING: unmatched methodindent--"); + sprintf(logtext + methodindent, "finished: "); - utf_sprint(logtext + strlen(logtext), method->class->name); + utf_sprint_classname(logtext + strlen(logtext), m->class->name); sprintf(logtext + strlen(logtext), "."); - utf_sprint(logtext + strlen(logtext), method->name); - utf_sprint(logtext + strlen(logtext), method->descriptor); + utf_sprint(logtext + strlen(logtext), m->name); + utf_sprint_classname(logtext + strlen(logtext), m->descriptor); - switch (method->returntype) { + switch (m->returntype) { case TYPE_INT: sprintf(logtext + strlen(logtext), "->%d", (s4) l); break; + case TYPE_LONG: -#if defined(__I386__) +#if defined(__I386__) || defined(__POWERPC__) sprintf(logtext + strlen(logtext), "->%lld", (s8) l); #else sprintf(logtext + strlen(logtext), "->%ld", (s8) l); #endif break; + case TYPE_ADDRESS: -#if defined(__I386__) +#if defined(__I386__) || defined(__POWERPC__) sprintf(logtext + strlen(logtext), "->%p", (u1*) ((s4) l)); #else sprintf(logtext + strlen(logtext), "->%p", (u1*) l); #endif break; + case TYPE_FLOAT: sprintf(logtext + strlen(logtext), "->%g", f); break; + case TYPE_DOUBLE: sprintf(logtext + strlen(logtext), "->%g", d); break; @@ -1091,21 +1039,6 @@ void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f) } -void builtin_displaymethodexception(methodinfo *method) -{ - int i; - char logtext[MAXLOGTEXT]; - for (i = 0; i < methodindent; i++) - logtext[i] = '\t'; - sprintf(logtext + methodindent, "exception abort: "); - utf_sprint(logtext + strlen(logtext), method->class->name); - sprintf(logtext + strlen(logtext), "."); - utf_sprint(logtext + strlen(logtext), method->name); - utf_sprint(logtext + strlen(logtext), method->descriptor); - log_text(logtext); -} - - /**************************************************************************** SYNCHRONIZATION FUNCTIONS *****************************************************************************/ @@ -1115,7 +1048,7 @@ void builtin_displaymethodexception(methodinfo *method) */ void internal_lock_mutex_for_object(java_objectheader *object) { -#ifdef USE_THREADS +#if defined(USE_THREADS) && !defined(NATIVE_THREADS) mutexHashEntry *entry; int hashValue; @@ -1165,7 +1098,7 @@ void internal_lock_mutex_for_object(java_objectheader *object) */ void internal_unlock_mutex_for_object (java_objectheader *object) { -#ifdef USE_THREADS +#if defined(USE_THREADS) && !defined(NATIVE_THREADS) int hashValue; mutexHashEntry *entry; @@ -1197,11 +1130,10 @@ void internal_unlock_mutex_for_object (java_objectheader *object) void builtin_monitorenter(java_objectheader *o) { -#ifdef USE_THREADS +#if defined(USE_THREADS) +#if !defined(NATIVE_THREADS) int hashValue; - assert(blockInts == 0); - ++blockInts; hashValue = MUTEX_HASH_VALUE(o); @@ -1212,19 +1144,31 @@ void builtin_monitorenter(java_objectheader *o) internal_lock_mutex_for_object(o); --blockInts; - - assert(blockInts == 0); +#else + monitorEnter((threadobject *) THREADOBJECT, o); +#endif #endif } +/* + * Locks the class object - needed for static synchronized methods. + * The use_class_as_object call is needed in order to circumvent a + * possible deadlock with builtin_monitorenter called by another + * thread calling use_class_as_object. + */ +void builtin_staticmonitorenter(classinfo *c) +{ + use_class_as_object(c); + builtin_monitorenter(&c->header); +} + -void builtin_monitorexit (java_objectheader *o) +void *builtin_monitorexit(java_objectheader *o) { -#ifdef USE_THREADS +#if defined(USE_THREADS) +#if !defined(NATIVE_THREADS) int hashValue; - assert(blockInts == 0); - ++blockInts; hashValue = MUTEX_HASH_VALUE(o); @@ -1239,8 +1183,11 @@ void builtin_monitorexit (java_objectheader *o) internal_unlock_mutex_for_object(o); --blockInts; - - assert(blockInts == 0); + return o; +#else + monitorExit((threadobject *) THREADOBJECT, o); + return o; +#endif #endif } @@ -1841,6 +1788,64 @@ java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o) } +s4 builtin_dummy() +{ + panic("Internal error: builtin_dummy called (native function is missing)"); + return 0; /* for the compiler */ +} + + +/* builtin_asm_get_exceptionptrptr ********************************************* + + this is a wrapper for calls from asmpart + +*******************************************************************************/ + +#if defined(USE_THREADS) && defined(NATIVE_THREADS) +java_objectheader **builtin_asm_get_exceptionptrptr() +{ + return builtin_get_exceptionptrptr(); +} +#endif + + +methodinfo *builtin_asm_get_threadrootmethod() +{ + return *threadrootmethod; +} + + +inline void* builtin_asm_get_stackframeinfo() +{ +/*log_text("builtin_asm_get_stackframeinfo()");*/ +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + return &THREADINFO->_stackframeinfo; +#else +#if defined(__GNUC__) +#warning FIXME FOR OLD THREAD IMPL (jowenn) +#endif + return &_thread_nativestackframeinfo; /* no threading, at least no native*/ +#endif +} + +stacktraceelement *builtin_stacktrace_copy(stacktraceelement **el,stacktraceelement *begin, stacktraceelement *end) { +/* stacktraceelement *el;*/ + size_t s; + s=(end-begin); + /*printf ("begin: %p, end: %p, diff: %ld, size :%ld\n",begin,end,s,s*sizeof(stacktraceelement));*/ + *el=heap_allocate(sizeof(stacktraceelement)*(s+1), true, 0); +#if 0 + *el=MNEW(stacktraceelement,s+1); /*GC*/ +#endif + memcpy(*el,begin,(end-begin)*sizeof(stacktraceelement)); + (*el)[s].method=0; +#if defined(__GNUC__) +#warning change this if line numbers bigger than u2 are allowed, the currently supported class file format does no allow that +#endif + (*el)[s].linenumber=-1; /* -1 can never be reched otherwise, since line numbers are only u2, so it is save to use that as flag */ + return *el; +} + /* * 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