-/* builtin.c - functions for unsupported operations
+/* src/vm/builtin.c - functions for unsupported operations
- Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
- R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
- M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
- P. Tomsich, J. Wenninger
+ Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
+ R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
+ C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
+ Institut f. Computersprachen - TU Wien
This file is part of CACAO.
Andreas Krall
Mark Probst
+ Changes: Christian Thalinger
+
Contains C functions for JavaVM Instructions that cannot be
translated to machine language directly. Consequently, the
generated machine code for these instructions contains function
calls instead of machine instructions, using the C calling
convention.
- $Id: builtin.c 664 2003-11-21 18:24:01Z jowenn $
+ $Id: builtin.c 3134 2005-08-23 14:45:29Z cacao $
*/
#include <assert.h>
+#include <stdlib.h>
#include <string.h>
-#include "main.h"
-#include "global.h"
-#include "builtin.h"
-#include "native.h"
-#include "loader.h"
-#include "tables.h"
-#include "asmpart.h"
-#include "threads/thread.h"
-#include "threads/locks.h"
-#include "toolbox/loging.h"
-#include "toolbox/memory.h"
-
-#include "native-math.h"
+
+#include "config.h"
+#include "arch.h"
+#include "md-abi.h"
+#include "types.h"
+
+#include "classpath/native/fdlibm/fdlibm.h"
+
+#include "mm/boehm.h"
+#include "mm/memory.h"
+#include "native/native.h"
+#include "native/include/java_lang_Cloneable.h"
+#include "native/include/java_lang_Object.h" /* required by VMObject */
+#include "native/include/java_lang_VMObject.h"
+
+#if defined(USE_THREADS)
+# if defined(NATIVE_THREADS)
+# include "threads/native/threads.h"
+# else
+# include "threads/green/threads.h"
+# include "threads/green/locks.h"
+# endif
+#endif
+
+#include "toolbox/logging.h"
+#include "toolbox/util.h"
+#include "vm/builtin.h"
+#include "vm/exceptions.h"
+#include "vm/global.h"
+#include "vm/initialize.h"
+#include "vm/loader.h"
+#include "vm/options.h"
+#include "vm/stringlocal.h"
+#include "vm/tables.h"
+#include "vm/jit/asmpart.h"
+#include "vm/jit/patcher.h"
+
#undef DEBUG /*define DEBUG 1*/
-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"}
-};
+THREADSPECIFIC methodinfo* _threadrootmethod = NULL;
+THREADSPECIFIC void *_thread_nativestackframeinfo = NULL;
+
+
+/* include builtin tables *****************************************************/
+
+#include "vm/builtintable.inc"
+
+
+/* builtintable_init ***********************************************************
+
+ Parse the descriptors of builtin functions and create the parsed
+ descriptors.
+
+*******************************************************************************/
+
+static bool builtintable_init(void)
+{
+ descriptor_pool *descpool;
+ s4 dumpsize;
+ utf *descriptor;
+ s4 entries_internal;
+ s4 entries_automatic;
+ s4 i;
+
+ /* mark start of dump memory area */
+
+ dumpsize = dump_size();
+
+ /* create a new descriptor pool */
+
+ descpool = descriptor_pool_new(class_java_lang_Object);
+
+ /* add some entries we need */
+
+ if (!descriptor_pool_add_class(descpool, utf_java_lang_Object))
+ return false;
+
+ if (!descriptor_pool_add_class(descpool, utf_java_lang_Class))
+ return false;
+
+ /* calculate table entries statically */
+
+ entries_internal =
+ sizeof(builtintable_internal) / sizeof(builtintable_entry);
+
+ entries_automatic =
+ sizeof(builtintable_automatic) / sizeof(builtintable_entry)
+ - 1; /* last filler entry (comment see builtintable.inc) */
+
+ /* first add all descriptors to the pool */
+
+ for (i = 0; i < entries_internal; i++) {
+ /* create a utf8 string from descriptor */
+
+ descriptor = utf_new_char(builtintable_internal[i].descriptor);
+
+ if (!descriptor_pool_add(descpool, descriptor, NULL)) {
+ /* release dump area */
+
+ dump_release(dumpsize);
+
+ return false;
+ }
+ }
+
+ for (i = 0; i < entries_automatic; i++) {
+ /* create a utf8 string from descriptor */
+
+ descriptor = utf_new_char(builtintable_automatic[i].descriptor);
+
+ if (!descriptor_pool_add(descpool, descriptor, NULL)) {
+ /* release dump area */
+
+ dump_release(dumpsize);
+
+ return false;
+ }
+ }
+
+ /* create the class reference table */
+
+ (void) descriptor_pool_create_classrefs(descpool, NULL);
+
+ /* allocate space for the parsed descriptors */
+
+ descriptor_pool_alloc_parsed_descriptors(descpool);
+
+ /* now parse all descriptors */
+
+ for (i = 0; i < entries_internal; i++) {
+ /* create a utf8 string from descriptor */
+
+ descriptor = utf_new_char(builtintable_internal[i].descriptor);
+
+ /* parse the descriptor, builtin is always static (no `this' pointer) */
+
+ builtintable_internal[i].md =
+ descriptor_pool_parse_method_descriptor(descpool, descriptor,
+ ACC_STATIC, NULL);
+ }
+
+ for (i = 0; i < entries_automatic; i++) {
+ /* create a utf8 string from descriptor */
+
+ descriptor = utf_new_char(builtintable_automatic[i].descriptor);
+
+ /* parse the descriptor, builtin is always static (no `this' pointer) */
+
+ builtintable_automatic[i].md =
+ descriptor_pool_parse_method_descriptor(descpool, descriptor,
+ ACC_STATIC, NULL);
+ }
+
+ /* release dump area */
+
+ dump_release(dumpsize);
+
+ return true;
+}
+
+
+/* builtintable_comparator *****************************************************
+
+ qsort comparator for the automatic builtin table.
+
+*******************************************************************************/
+
+static int builtintable_comparator(const void *a, const void *b)
+{
+ builtintable_entry *bte1;
+ builtintable_entry *bte2;
+
+ bte1 = (builtintable_entry *) a;
+ bte2 = (builtintable_entry *) b;
+
+ return (bte1->opcode < bte2->opcode) ? -1 : (bte1->opcode > bte2->opcode);
+}
+
+
+/* builtintable_sort_automatic *************************************************
+
+ Sorts the automatic builtin table.
+
+*******************************************************************************/
+
+static void builtintable_sort_automatic(void)
+{
+ s4 entries;
+
+ /* calculate table size statically (`- 1' comment see builtintable.inc) */
+
+ entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1;
+
+ qsort(builtintable_automatic, entries, sizeof(builtintable_entry),
+ builtintable_comparator);
+}
+
+
+/* builtin_init ****************************************************************
+
+ XXX
+
+*******************************************************************************/
+
+bool builtin_init(void)
+{
+ /* initialize the builtin tables */
+
+ if (!builtintable_init())
+ return false;
+
+ /* sort builtin tables */
+
+ builtintable_sort_automatic();
+
+ return true;
+}
+
+
+/* builtintable_get_internal ***************************************************
+
+ Finds an entry in the builtintable for internal functions and
+ returns the a pointer to the structure.
+
+*******************************************************************************/
+
+builtintable_entry *builtintable_get_internal(functionptr fp)
+{
+ s4 i;
+
+ for (i = 0; builtintable_internal[i].fp != NULL; i++) {
+ if (builtintable_internal[i].fp == fp)
+ return &builtintable_internal[i];
+ }
+
+ return NULL;
+}
+
+
+/* builtintable_get_automatic **************************************************
+
+ Finds an entry in the builtintable for functions which are replaced
+ automatically and returns the a pointer to the structure.
+
+*******************************************************************************/
+
+builtintable_entry *builtintable_get_automatic(s4 opcode)
+{
+ builtintable_entry *first;
+ builtintable_entry *last;
+ builtintable_entry *middle;
+ s4 half;
+ s4 entries;
+
+ /* calculate table size statically (`- 1' comment see builtintable.inc) */
+
+ entries = sizeof(builtintable_automatic) / sizeof(builtintable_entry) - 1;
+
+ first = builtintable_automatic;
+ last = builtintable_automatic + entries;
+
+ while (entries > 0) {
+ half = entries / 2;
+ middle = first + half;
+
+ if (middle->opcode < opcode) {
+ first = middle + 1;
+ entries -= half + 1;
+ } else
+ entries = half;
+ }
+
+ return (first != last ? first : NULL);
+}
/*****************************************************************************
0 ... otherwise
*****************************************************************************/
+s4 builtin_isanysubclass(classinfo *sub, classinfo *super)
+{
+ s4 res;
+ castinfo classvalues;
+
+ if (sub == super)
+ return 1;
-s4 builtin_isanysubclass (classinfo *sub, classinfo *super)
-{
- classinfo *tmp;
if (super->flags & ACC_INTERFACE)
return (sub->vftbl->interfacetablelength > super->index) &&
(sub->vftbl->interfacetable[-super->index] != NULL);
- /*
- while (sub != 0)
- if (sub == super)
- return 1;
- else
- sub = sub->super;
-
- return 0;
- */
+ asm_getclassvalues_atomic(super->vftbl, sub->vftbl, &classvalues);
-/*
- for (tmp=sub;tmp!=0;tmp=tmp->super) {
- printf("->");
- utf_display(tmp->name);
- }
- printf("\n\n");
-
- for (tmp=super;tmp!=0;tmp=tmp->super) {
- printf("->");
- utf_display(tmp->name);
- }
- printf("\n");
-
+ res = (u4) (classvalues.sub_baseval - classvalues.super_baseval) <=
+ (u4) classvalues.super_diffval;
- printf("sub->vftbl->baseval %d, super->vftbl->baseval %d\n diff %d, super->vftbl->diffval %d\n",
- sub->vftbl->baseval, super->vftbl->baseval, (unsigned)(sub->vftbl->baseval - super->vftbl->baseval),
- super->vftbl->diffval); */
-
- return (unsigned) (sub->vftbl->baseval - super->vftbl->baseval) <=
- (unsigned) (super->vftbl->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;
-
- if ((base = super->baseval) <= 0)
+ s4 res;
+ s4 base;
+ castinfo classvalues;
+
+ if (sub == super)
+ return 1;
+
+ asm_getclassvalues_atomic(super, sub, &classvalues);
+
+ if ((base = classvalues.super_baseval) <= 0)
/* super is an interface */
- return (sub->interfacetablelength > -base) &&
+ res = (sub->interfacetablelength > -base) &&
(sub->interfacetable[base] != NULL);
- return (unsigned) (sub->baseval - base)
- <= (unsigned) (super->diffval);
+ else
+ res = (u4) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (u4) classvalues.super_diffval;
+
+ return res;
}
{
#ifdef DEBUG
log_text ("builtin_instanceof called");
-
- /* XXX remove log */
- /*
- sprintf(logtext,"instanceof(");
- utf_sprint(logtext+strlen(logtext),obj->vftbl->class->name);
- sprintf(logtext+strlen(logtext),",");
- utf_sprint(logtext+strlen(logtext),class);
- sprintf(logtext+strlen(logtext),")");
- dolog();
- */
#endif
- if (!obj) return 0;
- return builtin_isanysubclass (obj->vftbl->class, class);
+ if (!obj)
+ return 0;
+
+ return builtin_isanysubclass(obj->vftbl->class, class);
}
log_text("builtin_checkcast called");
#endif
- /* XXX remove log */
- /*
- sprintf(logtext,"checkcast(");
- utf_sprint(logtext+strlen(logtext),obj->vftbl->class->name);
- sprintf(logtext+strlen(logtext),",");
- utf_sprint(logtext+strlen(logtext),class);
- sprintf(logtext+strlen(logtext),")");
- dolog();
- */
-
if (obj == NULL)
return 1;
if (builtin_isanysubclass(obj->vftbl->class, class))
}
-/*********** internal function: builtin_descriptorscompatible ******************
+/* builtin_descriptorscompatible ***********************************************
- Checks if two array type descriptors are assignment compatible
- Return value: 1 ... target = desc is possible
- 0 ... otherwise
-
-******************************************************************************/
+ Checks if two array type descriptors are assignment compatible
-/* XXX delete */
-#if 0
-static s4 builtin_descriptorscompatible(constant_arraydescriptor *desc, constant_arraydescriptor *target)
-{
- if (desc == target) return 1;
- if (desc->arraytype != target->arraytype) return 0;
-
- switch (target->arraytype) {
- case ARRAYTYPE_OBJECT:
- return builtin_isanysubclass(desc->objectclass, target->objectclass);
- case ARRAYTYPE_ARRAY:
- return builtin_descriptorscompatible
- (desc->elementdescriptor, target->elementdescriptor);
- default: return 1;
- }
-}
-#endif
+ Return value: 1 ... target = desc is possible
+ 0 ... otherwise
+
+*******************************************************************************/
-/* XXX inline this? */
-static s4 builtin_descriptorscompatible(arraydescriptor *desc,arraydescriptor *target)
+static s4 builtin_descriptorscompatible(arraydescriptor *desc, arraydescriptor *target)
{
- if (desc==target) return 1;
- if (desc->arraytype != target->arraytype) return 0;
- if (desc->arraytype != ARRAYTYPE_OBJECT) return 1;
+ if (desc == target)
+ return 1;
+
+ if (desc->arraytype != target->arraytype)
+ return 0;
+
+ 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} */
- return builtin_isanysubclass_vftbl(pseudo_class_Arraystub_vftbl,target->elementvftbl);
+ return builtin_isanysubclass_vftbl(pseudo_class_Arraystub->vftbl, target->elementvftbl);
}
-/******************** function: builtin_checkarraycast ***********************
-
- Checks if an object is really a subtype of the requested array type.
- The object has to be an array to begin with. For simple arrays (int, short,
- double, etc.) the types have to match exactly.
- For arrays of objects, the type of elements in the array has to be a
- subtype (or the same type) of the requested element type. For arrays of
- arrays (which in turn can again be arrays of arrays), the types at the
- lowest level have to satisfy the corresponding sub class relation.
-
- Return value: 1 ... cast is possible
- 0 ... otherwise
-
- ATTENTION: a cast with a NULL pointer is always possible.
-
-*****************************************************************************/
-/* XXX delete */
-#if 0
-s4 builtin_checkarraycast(java_objectheader *o, constant_arraydescriptor *desc)
-{
- java_arrayheader *a = (java_arrayheader*) o;
+/* builtin_arraycheckcast ******************************************************
- if (!o) return 1;
- if (o->vftbl->class != class_array) {
-#ifdef DEBUG
- printf("#### checkarraycast failed 1\n");
-#endif
- return 0;
- }
-
- if (a->arraytype != desc->arraytype) {
-#ifdef DEBUG
- printf("#### checkarraycast failed 2\n");
-#endif
- return 0;
- }
+ Checks if an object is really a subtype of the requested array
+ type. The object has to be an array to begin with. For simple
+ arrays (int, short, double, etc.) the types have to match exactly.
+ For arrays of objects, the type of elements in the array has to be
+ a subtype (or the same type) of the requested element type. For
+ arrays of arrays (which in turn can again be arrays of arrays), the
+ types at the lowest level have to satisfy the corresponding sub
+ class relation.
- switch (a->arraytype) {
- case ARRAYTYPE_OBJECT: {
- java_objectarray *oa = (java_objectarray*) o;
- int result = builtin_isanysubclass(oa->elementtype, desc->objectclass);
-
-#ifdef DEBUG
- if (!result)
- printf("#### checkarraycast failed 3\n");
-#endif
- return result;
- }
- case ARRAYTYPE_ARRAY: {
- java_arrayarray *aa = (java_arrayarray*) o;
- int result = builtin_descriptorscompatible
- (aa->elementdescriptor, desc->elementdescriptor);
-
-#ifdef DEBUG
- if (!result)
- printf("#### checkarraycast failed 4\n");
-#endif
- return result;
- }
- default:
- return 1;
- }
-}
-#endif
+*******************************************************************************/
-s4 builtin_checkarraycast(java_objectheader *o,arraydescriptor *target)
+s4 builtin_arraycheckcast(java_objectheader *o, vftbl_t *target)
{
arraydescriptor *desc;
-
- if (!o) return 1;
- if ((desc = o->vftbl->arraydesc) == NULL) return 0;
- return builtin_descriptorscompatible(desc,target);
-}
+ if (!o)
+ return 1;
-/* XXX delete */
-#if 0
-s4 builtin_arrayinstanceof(java_objectheader *obj, constant_arraydescriptor *desc)
-{
- if (!obj) return 1;
- return builtin_checkarraycast (obj, desc);
+ if ((desc = o->vftbl->arraydesc) == NULL)
+ return 0;
+
+ return builtin_descriptorscompatible(desc, target->arraydesc);
}
-#endif
-s4 builtin_arrayinstanceof(java_objectheader *obj,arraydescriptor *desc)
+
+s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl_t *target)
{
- if (!obj) return 1;
- return builtin_checkarraycast (obj, desc);
+ if (!obj)
+ return 1;
+
+ return builtin_arraycheckcast(obj, target);
}
+
/************************** exception functions *******************************
******************************************************************************/
-java_objectheader *builtin_throw_exception(java_objectheader *local_exceptionptr)
+java_objectheader *builtin_throw_exception(java_objectheader *xptr)
{
- if (verbose) {
- 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: <Nullpointer instead of exception>");
- 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");
- }
- dolog();
- }
- exceptionptr = local_exceptionptr;
- return local_exceptionptr;
-}
+ java_lang_Throwable *t;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ if (opt_verbose) {
+ t = (java_lang_Throwable *) xptr;
-/******************* function: builtin_canstore *******************************
+ /* calculate message length */
- Checks, if an object can be stored in an array.
- Return value: 1 ... possible
- 0 ... otherwise
+ logtextlen = strlen("Builtin exception thrown: ") + strlen("0");
-******************************************************************************/
+ if (t) {
+ logtextlen +=
+ utf_strlen(xptr->vftbl->class->name) +
+ strlen(": ") +
+ javastring_strlen((java_objectheader *) t->detailMessage);
-/* XXX delete */
-#if 0
-s4 builtin_canstore(java_objectarray *a, java_objectheader *o)
-{
- if (!o) return 1;
-
- switch (a->header.arraytype) {
- case ARRAYTYPE_OBJECT:
- if (!builtin_checkcast(o, a->elementtype)) {
- return 0;
- }
- return 1;
- break;
+ } else
+ logtextlen += strlen("(nil)");
+
+ /* allocate memory */
+
+ dumpsize = dump_size();
+
+ logtext = DMNEW(char, logtextlen);
+
+ strcpy(logtext, "Builtin exception thrown: ");
+
+ if (t) {
+ utf_sprint_classname(logtext + strlen(logtext),
+ xptr->vftbl->class->name);
+
+ if (t->detailMessage) {
+ char *buf;
- case ARRAYTYPE_ARRAY:
- if (!builtin_checkarraycast
- (o, ((java_arrayarray*)a)->elementdescriptor)) {
- return 0;
+ buf = javastring_tochar((java_objectheader *) t->detailMessage);
+ strcat(logtext, ": ");
+ strcat(logtext, buf);
+ MFREE(buf, char, strlen(buf));
+ }
+
+ } else {
+ strcat(logtext, "(nil)");
}
- return 1;
- break;
- default:
- panic("builtin_canstore called with invalid arraytype");
- return 0;
+ log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
}
+
+ *exceptionptr = xptr;
+
+ return xptr;
}
-#endif
-s4 builtin_canstore (java_objectarray *a, java_objectheader *o)
+
+
+/* builtin_canstore ************************************************************
+
+ Checks, if an object can be stored in an array.
+
+ Return value: 1 ... possible
+ 0 ... otherwise
+
+*******************************************************************************/
+
+s4 builtin_canstore(java_objectarray *a, java_objectheader *o)
{
arraydescriptor *desc;
arraydescriptor *valuedesc;
- vftbl *componentvftbl;
- vftbl *valuevftbl;
- int dim_m1;
+ vftbl_t *componentvftbl;
+ vftbl_t *valuevftbl;
int base;
+ castinfo classvalues;
- if (!o) return 1;
+ if (!o)
+ return 1;
/* The following is guaranteed (by verifier checks):
*
*/
desc = a->header.objheader.vftbl->arraydesc;
- componentvftbl = desc->componentvftbl;
+ componentvftbl = desc->componentvftbl;
valuevftbl = o->vftbl;
- /* XXX remove log */
- /*
- log_text("builtin_canstore");
- print_arraydescriptor(stdout,desc);
- utf_sprint(logtext,valuevftbl->class->name);
- dolog();
- */
+ if ((desc->dimension - 1) == 0) {
+ s4 res;
- if ((dim_m1 = desc->dimension - 1) == 0) {
/* {a is a one-dimensional array} */
/* {a is an array of references} */
if (valuevftbl == componentvftbl)
return 1;
- /* XXX remove log */
- /* log_text("not same vftbl"); */
+ asm_getclassvalues_atomic(componentvftbl, valuevftbl, &classvalues);
- if ((base = componentvftbl->baseval) <= 0)
+ if ((base = classvalues.super_baseval) <= 0)
/* an array of interface references */
return (valuevftbl->interfacetablelength > -base &&
valuevftbl->interfacetable[base] != NULL);
- return (unsigned)(valuevftbl->baseval - base)
- <= (unsigned)(componentvftbl->diffval);
- }
- /* {a has dimension > 1} */
+ res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (unsigned) classvalues.super_diffval;
+
+ return res;
+ }
+
+ /* {a has dimension > 1} */
/* {componentvftbl->arraydesc != NULL} */
/* check if o is an array */
return builtin_descriptorscompatible(valuedesc,componentvftbl->arraydesc);
}
+
/* This is an optimized version where a is guaranteed to be one-dimensional */
s4 builtin_canstore_onedim (java_objectarray *a, java_objectheader *o)
{
arraydescriptor *desc;
- vftbl *elementvftbl;
- vftbl *valuevftbl;
+ vftbl_t *elementvftbl;
+ vftbl_t *valuevftbl;
+ s4 res;
int base;
+ castinfo classvalues;
if (!o) return 1;
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);
-
- return (unsigned)(valuevftbl->baseval - base)
- <= (unsigned)(elementvftbl->diffval);
+
+ res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (unsigned) classvalues.super_diffval;
+
+ return res;
}
+
/* 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)
+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;
if (valuevftbl == elementvftbl)
return 1;
- return (unsigned)(valuevftbl->baseval - elementvftbl->baseval)
- <= (unsigned)(elementvftbl->diffval);
+ asm_getclassvalues_atomic(elementvftbl, valuevftbl, &classvalues);
+
+ res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (unsigned) classvalues.super_diffval;
+
+ return res;
}
-/******************** Function: builtin_new **********************************
+/* builtin_new *****************************************************************
- Creates a new instance of class c on the heap.
- Return value: pointer to the object or NULL if no memory is
- available
-
-*****************************************************************************/
+ Creates a new instance of class c on the heap.
-#define ALIGNMENT 3
-#define align_size(size) ((size + ((1 << ALIGNMENT) - 1)) & ~((1 << ALIGNMENT) - 1))
+ Return value: pointer to the object or NULL if no memory is
+ available
+
+*******************************************************************************/
java_objectheader *builtin_new(classinfo *c)
{
java_objectheader *o;
- class_init(c);
+ /* is the class loaded */
+
+ assert(c->loaded);
+
+ /* is the class linked */
+ if (!c->linked)
+ if (!link_class(c))
+ return NULL;
+
+ if (!c->initialized) {
+ if (initverbose)
+ log_message_class("Initialize class (from builtin_new): ", c);
+
+ if (!initialize_class(c))
+ return NULL;
+ }
-#ifdef SIZE_FROM_CLASSINFO
- c->alignedsize = align_size(c->instancesize);
- o = heap_allocate(c->alignedsize, true, c->finalizer);
-#else
o = heap_allocate(c->instancesize, true, c->finalizer);
-#endif
- if (!o) return NULL;
-
- memset(o, 0, c->instancesize);
+
+ if (!o)
+ return NULL;
+
+ MSET(o, 0, u1, c->instancesize);
o->vftbl = c->vftbl;
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ initObjectLock(o);
+#endif
+
return o;
}
+/* builtin_newarray ************************************************************
+
+ Creates an array with the given vftbl on the heap.
+
+ Return value: pointer to the array or NULL if no memory is available
+
+ CAUTION: The given vftbl must be the vftbl of the *array* class,
+ not of the element class.
+*******************************************************************************/
-java_arrayheader *builtin_newarray(s4 size,vftbl *arrayvftbl)
+java_arrayheader *builtin_newarray(s4 size, vftbl_t *arrayvftbl)
{
- /* XXX remove log */
- /*
- sprintf(logtext,"newarray size=%d class=",size);
- utf_sprint(logtext+strlen(logtext),arrayvftbl->class->name);
- dolog();
- */
+ java_arrayheader *a;
+ arraydescriptor *desc;
+ s4 dataoffset;
+ s4 componentsize;
+ s4 actualsize;
- java_arrayheader *a;
- arraydescriptor *desc = arrayvftbl->arraydesc;
- s4 dataoffset = desc->dataoffset;
- s4 componentsize = desc->componentsize;
+ desc = arrayvftbl->arraydesc;
+ dataoffset = desc->dataoffset;
+ componentsize = desc->componentsize;
-#ifdef SIZE_FROM_CLASSINFO
- s4 actualsize = align_size(dataoffset + size * componentsize);
-#else
- s4 actualsize = dataoffset + size * componentsize;
-#endif
- a = (java_arrayheader *)
- heap_allocate(actualsize,
- (desc->arraytype == ARRAYTYPE_OBJECT),
- NULL);
-
- if (!a) return NULL;
- memset(a,0,actualsize);
-
- a->objheader.vftbl = arrayvftbl;
- a->size = size;
-#ifdef SIZE_FROM_CLASSINFO
- a->alignedsize = actualsize;
+ if (size < 0) {
+ *exceptionptr = new_negativearraysizeexception();
+ return NULL;
+ }
+
+ actualsize = dataoffset + size * componentsize;
+
+ 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;
+
+ MSET(a, 0, u1, actualsize);
+
+ a->objheader.vftbl = arrayvftbl;
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ initObjectLock(&a->objheader);
#endif
- return a;
-}
-java_objectarray *
-builtin_anewarray(s4 size,classinfo *component)
-{
- return (java_objectarray*) builtin_newarray(size,class_array_of(component)->vftbl);
-}
+ a->size = size;
-/* XXX delete */
-#if 0
-java_objectarray *builtin_anewarray (s4 size, classinfo *elementtype)
-{
- java_objectarray *a;
- a = (java_objectarray*)__builtin_newarray(sizeof(java_objectarray),
- size,
- true,
- sizeof(void*),
- ARRAYTYPE_OBJECT,
- elementtype);
- if (!a) return NULL;
-
- a->elementtype = elementtype;
return a;
}
-#endif
-/******************** function: builtin_newarray_array ***********************
- Creates an array of pointers to arrays on the heap.
- Parameters:
- size ......... number of elements
- elementdesc .. pointer to the array description structure for the
- element arrays
+/* builtin_anewarray ***********************************************************
+
+ 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
+
+*******************************************************************************/
+
+java_objectarray *builtin_anewarray(s4 size, classinfo *component)
+{
+ classinfo *c;
- Return value: pointer to the array or NULL if no memory is available
+ /* is class loaded */
+ assert(component->loaded);
-*****************************************************************************/
+ /* is class linked */
+ if (!component->linked)
+ if (!link_class(component))
+ return NULL;
-/* XXX delete */
-#if 0
-java_arrayarray *builtin_newarray_array
- (s4 size, constant_arraydescriptor *elementdesc)
-{
- java_arrayarray *a;
- a = (java_arrayarray*)__builtin_newarray(sizeof(java_arrayarray),
- size,
- true,
- sizeof(void*),
- ARRAYTYPE_ARRAY,
- elementdesc->objectclass);
- if (!a) return NULL;
-
- a->elementdescriptor = elementdesc;
- return a;
+ c = class_array_of(component, true);
+
+ if (!c)
+ return NULL;
+
+ return (java_objectarray *) builtin_newarray(size, c->vftbl);
}
-#endif
-/******************** function: builtin_newarray_boolean ************************
+/* builtin_newarray_int ********************************************************
- Creates an array of bytes on the heap. The array is designated as an array
- of booleans (important for casts)
-
- Return value: pointer to the array or NULL if no memory is available
+ Creates an array of 32 bit Integers on the heap.
-*****************************************************************************/
+ Return value: pointer to the array or NULL if no memory is
+ available
-/* XXX delete */
-#if 0
-java_booleanarray *builtin_newarray_boolean (s4 size)
-{
- java_booleanarray *a;
- a = (java_booleanarray*)__builtin_newarray(sizeof(java_booleanarray),
- size,
- false,
- sizeof(u1),
- ARRAYTYPE_BOOLEAN,
- NULL);
- return a;
-}
-#endif
+*******************************************************************************/
-java_intarray *builtin_newarray_int (s4 size)
+java_intarray *builtin_newarray_int(s4 size)
{
- return (java_intarray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_INT].arrayvftbl);
+ return (java_intarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_INT].arrayvftbl);
}
-java_longarray *builtin_newarray_long (s4 size)
-{
- return (java_longarray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_LONG].arrayvftbl);
-}
-java_floatarray *builtin_newarray_float (s4 size)
-{
- return (java_floatarray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_FLOAT].arrayvftbl);
-}
+/* builtin_newarray_long *******************************************************
-java_doublearray *builtin_newarray_double (s4 size)
-{
- return (java_doublearray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_DOUBLE].arrayvftbl);
-}
+ Creates an array of 64 bit Integers on the heap.
-java_bytearray *builtin_newarray_byte (s4 size)
-{
- return (java_bytearray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_BYTE].arrayvftbl);
-}
+ Return value: pointer to the array or NULL if no memory is
+ available
-java_chararray *builtin_newarray_char (s4 size)
-{
- return (java_chararray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl);
-}
+*******************************************************************************/
-java_shortarray *builtin_newarray_short (s4 size)
+java_longarray *builtin_newarray_long(s4 size)
{
- return (java_shortarray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_SHORT].arrayvftbl);
+ return (java_longarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_LONG].arrayvftbl);
}
-java_booleanarray *builtin_newarray_boolean (s4 size)
-{
- return (java_booleanarray*) builtin_newarray(size,primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
-}
-/******************** function: builtin_newarray_char ************************
+/* builtin_newarray_float ******************************************************
- Creates an array of characters on the heap.
+ Creates an array of 32 bit IEEE floats 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 delete */
-#if 0
-java_chararray *builtin_newarray_char (s4 size)
-{
- java_chararray *a;
- a = (java_chararray*)__builtin_newarray(sizeof(java_chararray),
- size,
- false,
- sizeof(u2),
- ARRAYTYPE_CHAR,
- NULL);
- return a;
+java_floatarray *builtin_newarray_float(s4 size)
+{
+ return (java_floatarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_FLOAT].arrayvftbl);
}
-/******************** function: builtin_newarray_float ***********************
+/* builtin_newarray_double *****************************************************
- Creates an array of 32 bit IEEE floats on the heap.
+ Creates an array of 64 bit IEEE floats 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 delete */
-java_floatarray *builtin_newarray_float (s4 size)
+java_doublearray *builtin_newarray_double(s4 size)
{
- java_floatarray *a;
- a = (java_floatarray*)__builtin_newarray(sizeof(java_floatarray),
- size,
- false,
- sizeof(float),
- ARRAYTYPE_FLOAT,
- NULL);
- return a;
+ return (java_doublearray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_DOUBLE].arrayvftbl);
}
-/******************** function: builtin_newarray_double ***********************
+/* builtin_newarray_byte *******************************************************
- Creates an array of 64 bit IEEE floats on the heap.
+ Creates an array of 8 bit Integers 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
-*****************************************************************************/
+*******************************************************************************/
-java_doublearray *builtin_newarray_double (s4 size)
+java_bytearray *builtin_newarray_byte(s4 size)
{
- java_doublearray *a;
- a = (java_doublearray*)__builtin_newarray(sizeof(java_doublearray),
- size,
- false,
- sizeof(double),
- ARRAYTYPE_DOUBLE,
- NULL);
- return a;
+ return (java_bytearray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_BYTE].arrayvftbl);
}
+/* builtin_newarray_char *******************************************************
+ Creates an array of characters on the heap.
-/******************** function: builtin_newarray_byte ***********************
-
- Creates an array of 8 bit Integers 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 delete */
-java_bytearray *builtin_newarray_byte (s4 size)
+java_chararray *builtin_newarray_char(s4 size)
{
- java_bytearray *a;
- a = (java_bytearray*)__builtin_newarray(sizeof(java_bytearray),
- size,
- false,
- sizeof(u1),
- ARRAYTYPE_BYTE,
- NULL);
- return a;
+ return (java_chararray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl);
}
-/******************** function: builtin_newarray_short ***********************
+/* builtin_newarray_short ******************************************************
- Creates an array of 16 bit Integers on the heap.
+ Creates an array of 16 bit Integers 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 delete */
java_shortarray *builtin_newarray_short(s4 size)
{
- java_shortarray *a;
- a = (java_shortarray*)__builtin_newarray(sizeof(java_shortarray),
- size,
- false,
- sizeof(s2),
- ARRAYTYPE_SHORT,
- NULL);
- return a;
+ return (java_shortarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_SHORT].arrayvftbl);
}
-/******************** Function: builtin_newarray_int ***********************
+/* builtin_newarray_boolean ****************************************************
- Creates an array of 32 bit Integers on the heap.
-
- Return value: pointer to the array or NULL if no memory is available
+ Creates an array of bytes on the heap. The array is designated as
+ an array of booleans (important for casts)
+
+ Return value: pointer to the array or NULL if no memory is
+ available
-*****************************************************************************/
+*******************************************************************************/
-<<<<<<< builtin.c
-/* XXX delete */
-java_intarray *builtin_newarray_int(s4 size)
+java_booleanarray *builtin_newarray_boolean(s4 size)
{
- java_intarray *a;
- a = (java_intarray*)__builtin_newarray(sizeof(java_intarray),
- size,
- false,
- sizeof(s4),
- ARRAYTYPE_INT,
- NULL);
-
-#if 0
- if (a == NULL) {
- asm_handle_builtin_exception(proto_java_lang_OutOfMemoryError);
- }
-#endif
-
- return a;
+ return (java_booleanarray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
}
-/******************** Function: builtin_newarray_long ***********************
+/* builtin_multianewarray ******************************************************
- Creates an array of 64 bit Integers on the heap.
+ Creates a multi-dimensional array on the heap. The dimensions are
+ passed in an array of longs.
- Return value: pointer to the array or NULL if no memory is available
+ Arguments:
+ n............number of dimensions to create
+ arrayvftbl...vftbl of the array class
+ dims.........array containing the size of each dimension to create
-*****************************************************************************/
+ Return value: pointer to the array or NULL if no memory is
+ available
-<<<<<<< builtin.c
-/* XXX delete */
-java_longarray *builtin_newarray_long(s4 size)
-{
- java_longarray *a;
- a = (java_longarray*)__builtin_newarray(sizeof(java_longarray),
- size,
- false,
- sizeof(s8),
- ARRAYTYPE_LONG,
- NULL);
- return a;
-}
+******************************************************************************/
+java_arrayheader *builtin_multianewarray(int n, vftbl_t *arrayvftbl, long *dims)
+{
+ s4 size, i;
+ java_arrayheader *a;
+ vftbl_t *componentvftbl;
-/* XXX delete */
-/***************** function: builtin_multianewarray ***************************
+ /* create this dimension */
- Creates a multi-dimensional array on the heap. The dimensions are passed in
- an array of Integers. The type for the array is passed as a reference to a
- constant_arraydescriptor structure.
+ size = (s4) dims[0];
+ a = builtin_newarray(size, arrayvftbl);
- Return value: pointer to the array or NULL if no memory is available
+ if (!a)
+ return NULL;
-******************************************************************************/
+ /* if this is the last dimension return */
- /* Helper functions */
+ if (!--n)
+ return a;
-/* XXX delete */
-static java_arrayheader *multianewarray_part(java_intarray *dims, int thisdim,
- constant_arraydescriptor *desc)
-{
- u4 size,i;
- java_arrayarray *a;
+ /* get the vftbl of the components to create */
- size = dims->data[thisdim];
-
- if (thisdim == (dims->header.size - 1)) {
- /* last dimension reached */
-
- switch (desc -> arraytype) {
- case ARRAYTYPE_BOOLEAN:
- return (java_arrayheader*) builtin_newarray_boolean(size);
- case ARRAYTYPE_CHAR:
- return (java_arrayheader*) builtin_newarray_char(size);
- case ARRAYTYPE_FLOAT:
- return (java_arrayheader*) builtin_newarray_float(size);
- case ARRAYTYPE_DOUBLE:
- return (java_arrayheader*) builtin_newarray_double(size);
- case ARRAYTYPE_BYTE:
- return (java_arrayheader*) builtin_newarray_byte(size);
- case ARRAYTYPE_SHORT:
- return (java_arrayheader*) builtin_newarray_short(size);
- case ARRAYTYPE_INT:
- return (java_arrayheader*) builtin_newarray_int(size);
- case ARRAYTYPE_LONG:
- return (java_arrayheader*) builtin_newarray_long(size);
- case ARRAYTYPE_OBJECT:
- return (java_arrayheader*) builtin_anewarray(size, desc->objectclass);
-
- case ARRAYTYPE_ARRAY:
- return (java_arrayheader*) builtin_newarray_array(size, desc->elementdescriptor);
-
- default: panic("Invalid arraytype in multianewarray");
- }
- }
+ componentvftbl = arrayvftbl->arraydesc->componentvftbl;
- /* if the last dimension has not been reached yet */
+ /* The verifier guarantees that the dimension count is in the range. */
- if (desc->arraytype != ARRAYTYPE_ARRAY)
- panic("multianewarray with too many dimensions");
+ /* create the component arrays */
- a = builtin_newarray_array(size, desc->elementdescriptor);
- if (!a) return NULL;
-
for (i = 0; i < size; i++) {
- java_arrayheader *ea =
- multianewarray_part(dims, thisdim + 1, desc->elementdescriptor);
- if (!ea) return NULL;
+ java_arrayheader *ea =
+#if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+ /* we save an s4 to a s8 slot, 8-byte aligned */
- a->data[i] = ea;
- }
+ builtin_multianewarray(n, componentvftbl, dims + 2);
+#else
+ builtin_multianewarray(n, componentvftbl, dims + 1);
+#endif
+
+ if (!ea)
+ return NULL;
- return (java_arrayheader*) a;
-}
+ ((java_objectarray *) a)->data[i] = (java_objectheader *) ea;
+ }
-/* XXX delete */
-java_arrayheader *builtin_multianewarray(java_intarray *dims,
- constant_arraydescriptor *desc)
-{
- return multianewarray_part(dims, 0, desc);
+ return a;
}
-static java_arrayheader *nmultianewarray_part(int n, long *dims, int thisdim,
- constant_arraydescriptor *desc)
-{
- int size, i;
- java_arrayarray *a;
+/*****************************************************************************
+ METHOD LOGGING
- size = (int) dims[thisdim];
+ Various functions for printing a message at method entry or exit (for
+ debugging)
- if (thisdim == (n - 1)) {
- /* last dimension reached */
-
- switch (desc -> arraytype) {
- case ARRAYTYPE_BOOLEAN:
- return (java_arrayheader*) builtin_newarray_boolean(size);
- case ARRAYTYPE_CHAR:
- return (java_arrayheader*) builtin_newarray_char(size);
- case ARRAYTYPE_FLOAT:
- return (java_arrayheader*) builtin_newarray_float(size);
- case ARRAYTYPE_DOUBLE:
- return (java_arrayheader*) builtin_newarray_double(size);
- case ARRAYTYPE_BYTE:
- return (java_arrayheader*) builtin_newarray_byte(size);
- case ARRAYTYPE_SHORT:
- return (java_arrayheader*) builtin_newarray_short(size);
- case ARRAYTYPE_INT:
- return (java_arrayheader*) builtin_newarray_int(size);
- case ARRAYTYPE_LONG:
- return (java_arrayheader*) builtin_newarray_long(size);
- case ARRAYTYPE_OBJECT:
- return (java_arrayheader*) builtin_anewarray(size,
- desc->objectclass);
- case ARRAYTYPE_ARRAY:
- return (java_arrayheader*) builtin_newarray_array(size,
- desc->elementdescriptor);
-
- default: panic ("Invalid arraytype in multianewarray");
- }
- }
+*****************************************************************************/
- /* if the last dimension has not been reached yet */
+u4 methodindent = 0;
- if (desc->arraytype != ARRAYTYPE_ARRAY)
- panic ("multianewarray with too many dimensions");
+java_objectheader *builtin_trace_exception(java_objectheader *xptr,
+ methodinfo *m,
+ void *pos,
+ s4 line,
+ s4 noindent)
+{
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
- a = builtin_newarray_array(size, desc->elementdescriptor);
- if (!a) return NULL;
-
- for (i = 0; i < size; i++) {
- java_arrayheader *ea =
- nmultianewarray_part(n, dims, thisdim + 1, desc->elementdescriptor);
- if (!ea) return NULL;
+ if (opt_verbose || runverbose || verboseexception) {
+ /* calculate message length */
- a -> data[i] = ea;
- }
-
- return (java_arrayheader*) a;
-}
+ if (xptr) {
+ logtextlen =
+ strlen("Exception ") +
+ utf_strlen(xptr->vftbl->class->name);
+
+ } else
+ logtextlen = strlen("Some Throwable");
+
+ logtextlen += strlen(" thrown in ");
+
+ if (m) {
+ logtextlen +=
+ utf_strlen(m->class->name) +
+ strlen(".") +
+ utf_strlen(m->name) +
+ utf_strlen(m->descriptor) +
+ strlen("(NOSYNC,NATIVE");
+
+#if SIZEOF_VOID_P == 8
+ logtextlen +=
+ strlen(")(0x123456789abcdef0) at position 0x123456789abcdef0 (");
+#else
+ logtextlen += strlen(")(0x12345678) at position 0x12345678 (");
#endif
-/**************** function: builtin_nmultianewarray ***************************
+ if (m->class->sourcefile == NULL)
+ logtextlen += strlen("<NO CLASSFILE INFORMATION>");
+ else
+ logtextlen += utf_strlen(m->class->sourcefile);
- Creates a multi-dimensional array on the heap. The dimensions are passed in
- an array of longs.
+ logtextlen += strlen(":65536)");
- Arguments:
- n............number of dimensions to create
- arrayvftbl...vftbl of the array class
- dims.........array containing the size of each dimension to create
+ } else
+ logtextlen += strlen("call_java_method");
- Return value: pointer to the array or NULL if no memory is available
+ logtextlen += strlen("0");
-******************************************************************************/
+ /* allocate memory */
-java_arrayheader *builtin_nmultianewarray (int n,
- vftbl *arrayvftbl, long *dims)
-{
- int size, i;
- java_arrayheader *a;
- vftbl *componentvftbl;
+ dumpsize = dump_size();
- /* create this dimension */
- size = (int) dims[0];
- a = builtin_newarray(size,arrayvftbl);
- if (!a) return NULL;
+ logtext = DMNEW(char, logtextlen);
- /* if this is the last dimension return */
- if (!--n) return a;
+ if (xptr) {
+ strcpy(logtext, "Exception ");
+ utf_strcat_classname(logtext, xptr->vftbl->class->name);
- /* 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");
+ } else {
+ strcpy(logtext, "Some Throwable");
+ }
- /* 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;
- }
+ strcat(logtext, " thrown in ");
- return a;
-}
+ if (m) {
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
-/* XXX delete */
-#if 0
-java_arrayheader *builtin_nmultianewarray (int size,
- constant_arraydescriptor *desc, long *dims)
-{
- (void) builtin_newarray_int(size); /* for compatibility with -old */
- return nmultianewarray_part (size, dims, 0, desc);
-}
-#endif
+ if (m->flags & ACC_SYNCHRONIZED)
+ strcat(logtext, "(SYNC");
+ else
+ strcat(logtext, "(NOSYNC");
+ if (m->flags & ACC_NATIVE) {
+ strcat(logtext, ",NATIVE");
+#if SIZEOF_VOID_P == 8
+ sprintf(logtext + strlen(logtext),
+ ")(0x%016lx) at position 0x%016lx",
+ (ptrint) m->entrypoint, (ptrint) pos);
+#else
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x",
+ (ptrint) m->entrypoint, (ptrint) pos);
+#endif
-/************************* function: builtin_aastore *************************
+ } else {
+#if SIZEOF_VOID_P == 8
+ sprintf(logtext + strlen(logtext),
+ ")(0x%016lx) at position 0x%016lx (",
+ (ptrint) m->entrypoint, (ptrint) pos);
+#else
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x (",
+ (ptrint) m->entrypoint, (ptrint) pos);
+#endif
- Stores a reference to an object into an object array or into an array
- array. Before any action is performed, the validity of the operation is
- checked.
+ if (m->class->sourcefile == NULL)
+ strcat(logtext, "<NO CLASSFILE INFORMATION>");
+ else
+ utf_strcat(logtext, m->class->sourcefile);
- Return value: 1 ... ok
- 0 ... this object cannot be stored into this array
+ sprintf(logtext + strlen(logtext), ":%d)", line);
+ }
-*****************************************************************************/
+ } else
+ strcat(logtext, "call_java_method");
-/* XXX delete */
-#if 0
-s4 builtin_aastore (java_objectarray *a, s4 index, java_objectheader *o)
-{
- if (builtin_canstore(a,o)) {
- a->data[index] = o;
- return 1;
+ log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
}
- return 0;
+
+ return xptr;
}
-#endif
+/* builtin_trace_args **********************************************************
+ XXX
+*******************************************************************************/
-/*****************************************************************************
- METHOD LOGGING
+#ifdef TRACE_ARGS_NUM
+void builtin_trace_args(s8 a0, s8 a1,
+#if TRACE_ARGS_NUM >= 4
+ s8 a2, s8 a3,
+#endif /* TRACE_ARGS_NUM >= 4 */
+#if TRACE_ARGS_NUM >= 6
+ s8 a4, s8 a5,
+#endif /* TRACE_ARGS_NUM >= 6 */
+#if TRACE_ARGS_NUM == 8
+ s8 a6, s8 a7,
+#endif /* TRACE_ARGS_NUM == 8 */
+ methodinfo *m)
+{
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
- Various functions for printing a message at method entry or exit (for
- debugging)
-
-*****************************************************************************/
+ md = m->parseddesc;
+ /* calculate message length */
-u4 methodindent = 0;
+ logtextlen =
+ methodindent + strlen("called: ") +
+ utf_strlen(m->class->name) +
+ strlen(".") +
+ utf_strlen(m->name) +
+ utf_strlen(m->descriptor) +
+ strlen(" SYNCHRONIZED") + strlen("(") + strlen(")");
-java_objectheader *builtin_trace_exception(java_objectheader *exceptionptr,
- methodinfo *method, int *pos,
- int noindent)
-{
+ /* add maximal argument length */
- if (!noindent)
- methodindent--;
- if (verbose || runverbose) {
- printf("Exception ");
- if (exceptionptr) {
- utf_display (exceptionptr->vftbl->class->name);
- }
- else {
- printf("Error: <Nullpointer instead of exception>");
- 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");
+ logtextlen += strlen("0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, ...(255)");
- }
- printf(" thrown in ");
- if (method) {
- utf_display (method->class->name);
- printf(".");
- utf_display (method->name);
- if (method->flags & ACC_SYNCHRONIZED)
- printf("(SYNC)");
- else
- printf("(NOSYNC)");
- printf("(%p) at position %p\n", method->entrypoint, pos);
- }
- else
- printf("call_java_method\n");
- fflush (stdout);
- }
- return exceptionptr;
-}
+ /* allocate memory */
+ dumpsize = dump_size();
-#ifdef TRACE_ARGS_NUM
-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)
-{
+ logtext = DMNEW(char, logtextlen);
- int i;
for (i = 0; i < methodindent; i++)
logtext[i] = '\t';
- sprintf(logtext + methodindent, "called: ");
- 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);
- sprintf(logtext + strlen(logtext), "(");
-
- switch (method->paramcount) {
+
+ strcpy(logtext + methodindent, "called: ");
+
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
+
+ if (m->flags & ACC_PUBLIC) strcat(logtext, " PUBLIC");
+ if (m->flags & ACC_PRIVATE) strcat(logtext, " PRIVATE");
+ if (m->flags & ACC_PROTECTED) strcat(logtext, " PROTECTED");
+ if (m->flags & ACC_STATIC) strcat(logtext, " STATIC");
+ if (m->flags & ACC_FINAL) strcat(logtext, " FINAL");
+ if (m->flags & ACC_SYNCHRONIZED) strcat(logtext, " SYNCHRONIZED");
+ if (m->flags & ACC_VOLATILE) strcat(logtext, " VOLATILE");
+ if (m->flags & ACC_TRANSIENT) strcat(logtext, " TRANSIENT");
+ if (m->flags & ACC_NATIVE) strcat(logtext, " NATIVE");
+ if (m->flags & ACC_INTERFACE) strcat(logtext, " INTERFACE");
+ if (m->flags & ACC_ABSTRACT) strcat(logtext, " ABSTRACT");
+
+ strcat(logtext, "(");
+
+ /* xxxprintf ?Bug? an PowerPc Linux (rlwinm.inso) */
+ /* Only Arguments in integer Registers are passed correctly here */
+ /* long longs spilled on Stack have an wrong offset of +4 */
+ /* So preliminary Bugfix: Only pass 3 params at once to sprintf */
+ /* for SIZEOG_VOID_P == 4 && TRACE_ARGS_NUM == 8 */
+ switch (md->paramcount) {
case 0:
break;
-#if defined(__I386__)
+#if SIZEOF_VOID_P == 4
case 1:
- sprintf(logtext+strlen(logtext), "%llx", a0);
+ sprintf(logtext + strlen(logtext),
+ "0x%llx",
+ a0);
break;
case 2:
- sprintf(logtext+strlen(logtext), "%llx, %llx", a0, a1);
+ sprintf(logtext + strlen(logtext),
+ "0x%llx, 0x%llx",
+ a0, a1);
break;
+#if TRACE_ARGS_NUM >= 4
case 3:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx", a0, a1, a2);
+ sprintf(logtext + strlen(logtext),
+ "0x%llx, 0x%llx, 0x%llx",
+ a0, a1, a2);
break;
case 4:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx",
- a0, a1, a2, a3);
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, 0x%llx"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext), ", 0x%llx", a3);
+
break;
+#endif /* TRACE_ARGS_NUM >= 4 */
+#if TRACE_ARGS_NUM >= 6
case 5:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx",
- a0, a1, a2, a3, a4);
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, 0x%llx"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext), ", 0x%llx, 0x%llx", a3, a4);
break;
+
case 6:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx",
- a0, a1, a2, a3, a4, a5);
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, 0x%llx"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext), ", 0x%llx, 0x%llx, 0x%llx"
+ , a3, a4, a5);
break;
+#endif /* TRACE_ARGS_NUM >= 6 */
-#if TRACE_ARGS_NUM > 6
+#if TRACE_ARGS_NUM == 8
case 7:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, %llx",
- a0, a1, a2, a3, a4, a5, a6);
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, 0x%llx"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext), ", 0x%llx, 0x%llx, 0x%llx"
+ , a3, a4, a5);
+ sprintf(logtext + strlen(logtext), ", 0x%llx", a6);
break;
case 8:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, %llx, %llx",
- a0, a1, a2, a3, a4, a5, a6, a7);
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, 0x%llx"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext), ", 0x%llx, 0x%llx, 0x%llx"
+ , a3, a4, a5);
+ sprintf(logtext + strlen(logtext), ", 0x%llx, 0x%llx", a6, a7);
break;
+#endif /* TRACE_ARGS_NUM == 8 */
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);
- break;
-#else
- default:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, ...(%d)",
- a0, a1, a2, a3, a4, a5, method->paramcount - 6);
- break;
+#if TRACE_ARGS_NUM == 2
+ sprintf(logtext + strlen(logtext), "0x%llx, 0x%llx, ...(%d)", a0, a1, md->paramcount - 2);
+
+#elif TRACE_ARGS_NUM == 4
+ sprintf(logtext + strlen(logtext),
+ "0x%llx, 0x%llx, 0x%llx, 0x%llx, ...(%d)",
+ a0, a1, a2, a3, md->paramcount - 4);
+
+#elif TRACE_ARGS_NUM == 6
+ sprintf(logtext + strlen(logtext),
+ "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, ...(%d)",
+ a0, a1, a2, a3, a4, a5, md->paramcount - 6);
+
+#elif TRACE_ARGS_NUM == 8
+ sprintf(logtext + strlen(logtext),"0x%llx, 0x%llx, 0x%llx,"
+ , a0, a1, a2);
+ sprintf(logtext + strlen(logtext)," 0x%llx, 0x%llx, 0x%llx,"
+ , a3, a4, a5);
+ sprintf(logtext + strlen(logtext)," 0x%llx, 0x%llx, ...(%d)"
+ , a6, a7, md->paramcount - 8);
#endif
-#else
+ break;
+
+#else /* SIZEOF_VOID_P == 4 */
+
case 1:
- sprintf(logtext+strlen(logtext), "%lx", a0);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx",
+ a0);
break;
case 2:
- sprintf(logtext+strlen(logtext), "%lx, %lx", a0, a1);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx",
+ a0, a1);
break;
case 3:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx", a0, a1, a2);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx", a0, a1, a2);
break;
case 4:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx",
- a0, a1, a2, a3);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx",
+ a0, a1, a2, a3);
break;
+#if TRACE_ARGS_NUM >= 6
case 5:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx",
- a0, a1, a2, a3, a4);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx",
+ a0, a1, a2, a3, a4);
break;
case 6:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx",
- a0, a1, a2, a3, a4, a5);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx",
+ a0, a1, a2, a3, a4, a5);
break;
+#endif /* TRACE_ARGS_NUM >= 6 */
-#if TRACE_ARGS_NUM > 6
+#if TRACE_ARGS_NUM == 8
case 7:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx, %lx",
- a0, a1, a2, a3, a4, a5, a6);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx",
+ a0, a1, a2, a3, a4, a5, a6);
break;
case 8:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx",
- a0, a1, a2, a3, a4, a5, a6, a7);
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx",
+ a0, a1, a2, a3, a4, a5, a6, a7);
break;
+#endif /* TRACE_ARGS_NUM == 8 */
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);
- break;
-#else
- default:
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, %lx, %lx, ...(%d)",
- a0, a1, a2, a3, a4, a5, method->paramcount - 6);
- break;
-#endif
+#if TRACE_ARGS_NUM == 4
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, ...(%d)",
+ a0, a1, a2, a3, md->paramcount - 4);
+
+#elif TRACE_ARGS_NUM == 6
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, ...(%d)",
+ a0, a1, a2, a3, a4, a5, md->paramcount - 6);
+
+#elif TRACE_ARGS_NUM == 8
+ sprintf(logtext + strlen(logtext),
+ "0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, 0x%lx, ...(%d)",
+ a0, a1, a2, a3, a4, a5, a6, a7, md->paramcount - 8);
#endif
+ break;
+#endif /* SIZEOF_VOID_P == 4 */
}
- sprintf (logtext+strlen(logtext), ")");
- dolog ();
+
+ strcat(logtext, ")");
+
+ log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
methodindent++;
}
#endif
-void builtin_displaymethodstart(methodinfo *method)
-{
- sprintf(logtext, " ");
- sprintf(logtext + methodindent, "called: ");
- 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);
- dolog();
- methodindent++;
-}
+/* builtin_displaymethodstop ***************************************************
+ XXX
-void builtin_displaymethodstop(methodinfo *method, s8 l, double d, float f)
+*******************************************************************************/
+
+void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f)
{
- int i;
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+ imm_union imu;
+
+ md = m->parseddesc;
+
+ /* calculate message length */
+
+ logtextlen =
+ methodindent + strlen("finished: ") +
+ utf_strlen(m->class->name) +
+ strlen(".") +
+ utf_strlen(m->name) +
+ utf_strlen(m->descriptor) +
+ strlen(" SYNCHRONIZED") + strlen("(") + strlen(")");
+
+ /* add maximal argument length */
+
+ logtextlen += strlen("->0.4872328470301428 (0x0123456789abcdef)");
+
+ /* allocate memory */
+
+ dumpsize = dump_size();
+
+ logtext = DMNEW(char, logtextlen);
+
+ /* generate the message */
+
for (i = 0; i < methodindent; i++)
logtext[i] = '\t';
- methodindent--;
- sprintf(logtext + methodindent, "finished: ");
- 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);
-
- switch (method->returntype) {
+
+ if (methodindent)
+ methodindent--;
+ else
+ log_text("WARNING: unmatched methodindent--");
+
+ strcpy(logtext + methodindent, "finished: ");
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
+
+ switch (md->returntype.type) {
case TYPE_INT:
- sprintf(logtext + strlen(logtext), "->%d", (s4) l);
+ sprintf(logtext + strlen(logtext), "->%d (0x%08x)", (s4) l, (s4) l);
break;
- case TYPE_LONG:
-#if defined(__I386__)
- sprintf(logtext + strlen(logtext), "->%lld", (s8) l);
+
+ case TYPE_LNG:
+#if SIZEOF_VOID_P == 4
+ sprintf(logtext + strlen(logtext), "->%lld (0x%016llx)", (s8) l, l);
#else
- sprintf(logtext + strlen(logtext), "->%ld", (s8) l);
+ sprintf(logtext + strlen(logtext), "->%ld (0x%016lx)", (s8) l, l);
#endif
break;
- case TYPE_ADDRESS:
-#if defined(__I386__)
- sprintf(logtext + strlen(logtext), "->%p", (u1*) ((s4) l));
-#else
- sprintf(logtext + strlen(logtext), "->%p", (u1*) l);
-#endif
+
+ case TYPE_ADR:
+ sprintf(logtext + strlen(logtext), "->%p", (void *) (ptrint) l);
break;
- case TYPE_FLOAT:
- sprintf(logtext + strlen(logtext), "->%g", f);
+
+ case TYPE_FLT:
+ imu.f = f;
+ sprintf(logtext + strlen(logtext), "->%.8f (0x%08x)", f, imu.i);
break;
- case TYPE_DOUBLE:
- sprintf(logtext + strlen(logtext), "->%g", d);
+
+ case TYPE_DBL:
+ imu.d = d;
+#if SIZEOF_VOID_P == 4
+ sprintf(logtext + strlen(logtext), "->%.16g (0x%016llx)", d, imu.l);
+#else
+ sprintf(logtext + strlen(logtext), "->%.16g (0x%016lx)", d, imu.l);
+#endif
break;
}
- dolog();
-}
+ log_text(logtext);
-void builtin_displaymethodexception(methodinfo *method)
-{
- int i;
- 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);
- dolog();
+ /* release memory */
+
+ dump_release(dumpsize);
}
SYNCHRONIZATION FUNCTIONS
*****************************************************************************/
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
/*
* Lock the mutex of an object.
*/
-#ifdef USE_THREADS
-void
-internal_lock_mutex_for_object (java_objectheader *object)
+void internal_lock_mutex_for_object(java_objectheader *object)
{
mutexHashEntry *entry;
int hashValue;
#endif
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
/*
* Unlocks the mutex of an object.
*/
-#ifdef USE_THREADS
-void
-internal_unlock_mutex_for_object (java_objectheader *object)
+void internal_unlock_mutex_for_object (java_objectheader *object)
{
int hashValue;
mutexHashEntry *entry;
#endif
+#if defined(USE_THREADS)
void builtin_monitorenter(java_objectheader *o)
{
-#ifdef USE_THREADS
+#if !defined(NATIVE_THREADS)
int hashValue;
- assert(blockInts == 0);
-
++blockInts;
hashValue = MUTEX_HASH_VALUE(o);
internal_lock_mutex_for_object(o);
--blockInts;
-
- assert(blockInts == 0);
+#else
+ monitorEnter((threadobject *) THREADOBJECT, o);
#endif
}
+#endif
-void builtin_monitorexit (java_objectheader *o)
+#if defined(USE_THREADS)
+/*
+ * 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)
{
-#ifdef USE_THREADS
- int hashValue;
+ use_class_as_object(c);
+ builtin_monitorenter(&c->header);
+}
+#endif
- assert(blockInts == 0);
+
+#if defined(USE_THREADS)
+void builtin_monitorexit(java_objectheader *o)
+{
+#if !defined(NATIVE_THREADS)
+ int hashValue;
++blockInts;
internal_unlock_mutex_for_object(o);
--blockInts;
-
- assert(blockInts == 0);
+#else
+ monitorExit((threadobject *) THREADOBJECT, o);
#endif
}
+#endif
/*****************************************************************************
******************************************************************************/
-
s8 builtin_ladd(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a + b;
+ c = a + b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lsub(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a - b;
+ c = a - b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lmul(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a * b;
+ c = a * b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_ldiv(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a / b;
+ c = a / b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lrem(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a % b;
+ c = a % b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lshl(s8 a, s4 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a << (b & 63);
+ c = a << (b & 63);
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lshr(s8 a, s4 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a >> (b & 63);
+ c = a >> (b & 63);
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lushr(s8 a, s4 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return ((u8) a) >> (b & 63);
+ c = ((u8) a) >> (b & 63);
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_land(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a & b;
+ c = a & b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lor(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a | b;
+ c = a | b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lxor(s8 a, s8 b)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a ^ b;
+ c = a ^ b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s8 builtin_lneg(s8 a)
-{
+{
+ s8 c;
+
#if U8_AVAILABLE
- return -a;
+ c = -a;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
s4 builtin_lcmp(s8 a, s8 b)
float builtin_fadd(float a, float b)
{
- if (isnanf(a)) return FLT_NAN;
- if (isnanf(b)) return FLT_NAN;
+ if (isnanf(a)) return intBitsToFloat(FLT_NAN);
+ if (isnanf(b)) return intBitsToFloat(FLT_NAN);
if (finitef(a)) {
if (finitef(b))
return a + b;
if (copysignf(1.0, a) == copysignf(1.0, b))
return a;
else
- return FLT_NAN;
+ return intBitsToFloat(FLT_NAN);
}
}
}
float builtin_fmul(float a, float b)
{
- if (isnanf(a)) return FLT_NAN;
- if (isnanf(b)) return FLT_NAN;
+ if (isnanf(a)) return intBitsToFloat(FLT_NAN);
+ if (isnanf(b)) return intBitsToFloat(FLT_NAN);
if (finitef(a)) {
- if (finitef(b)) return a*b;
+ if (finitef(b)) return a * b;
else {
- if (a == 0) return FLT_NAN;
+ if (a == 0) return intBitsToFloat(FLT_NAN);
else return copysignf(b, copysignf(1.0, b)*a);
}
}
else {
if (finitef(b)) {
- if (b == 0) return FLT_NAN;
+ if (b == 0) return intBitsToFloat(FLT_NAN);
else return copysignf(a, copysignf(1.0, a)*b);
}
else {
}
+/* builtin_ddiv ****************************************************************
+
+ Implementation as described in VM Spec.
+
+*******************************************************************************/
+
float builtin_fdiv(float a, float b)
{
- if (finitef(a) && finitef(b)) {
- if (b != 0)
+ if (finitef(a)) {
+ if (finitef(b)) {
+ /* If neither value1' nor value2' is NaN, the sign of the result */
+ /* is positive if both values have the same sign, negative if the */
+ /* values have different signs. */
+
return a / b;
- else {
- if (a > 0)
- return FLT_POSINF;
- else if (a < 0)
- return FLT_NEGINF;
+
+ } else {
+ if (isnanf(b)) {
+ /* If either value1' or value2' is NaN, the result is NaN. */
+
+ return intBitsToFloat(FLT_NAN);
+
+ } else {
+ /* Division of a finite value by an infinity results in a */
+ /* signed zero, with the sign-producing rule just given. */
+
+ /* is sign equal? */
+
+ if (copysignf(1.0, a) == copysignf(1.0, b))
+ return 0.0;
+ else
+ return -0.0;
+ }
+ }
+
+ } else {
+ if (isnanf(a)) {
+ /* If either value1' or value2' is NaN, the result is NaN. */
+
+ return intBitsToFloat(FLT_NAN);
+
+ } else if (finitef(b)) {
+ /* Division of an infinity by a finite value results in a signed */
+ /* infinity, with the sign-producing rule just given. */
+
+ /* is sign equal? */
+
+ if (copysignf(1.0, a) == copysignf(1.0, b))
+ return intBitsToFloat(FLT_POSINF);
+ else
+ return intBitsToFloat(FLT_NEGINF);
+
+ } else {
+ /* Division of an infinity by an infinity results in NaN. */
+
+ return intBitsToFloat(FLT_NAN);
}
}
- return FLT_NAN;
}
double builtin_dadd(double a, double b)
{
- if (isnan(a)) return DBL_NAN;
- if (isnan(b)) return DBL_NAN;
+ if (isnan(a)) return longBitsToDouble(DBL_NAN);
+ if (isnan(b)) return longBitsToDouble(DBL_NAN);
if (finite(a)) {
- if (finite(b)) return a+b;
+ if (finite(b)) return a + b;
else return b;
}
else {
if (finite(b)) return a;
else {
if (copysign(1.0, a)==copysign(1.0, b)) return a;
- else return DBL_NAN;
+ else return longBitsToDouble(DBL_NAN);
}
}
}
double builtin_dmul(double a, double b)
{
- if (isnan(a)) return DBL_NAN;
- if (isnan(b)) return DBL_NAN;
+ if (isnan(a)) return longBitsToDouble(DBL_NAN);
+ if (isnan(b)) return longBitsToDouble(DBL_NAN);
if (finite(a)) {
if (finite(b)) return a * b;
else {
- if (a == 0) return DBL_NAN;
+ if (a == 0) return longBitsToDouble(DBL_NAN);
else return copysign(b, copysign(1.0, b) * a);
}
}
else {
if (finite(b)) {
- if (b == 0) return DBL_NAN;
+ if (b == 0) return longBitsToDouble(DBL_NAN);
else return copysign(a, copysign(1.0, a) * b);
}
else {
}
+/* builtin_ddiv ****************************************************************
+
+ Implementation as described in VM Spec.
+
+*******************************************************************************/
+
double builtin_ddiv(double a, double b)
{
- if (finite(a) && finite(b)) {
- if (b != 0)
+ if (finite(a)) {
+ if (finite(b)) {
+ /* If neither value1' nor value2' is NaN, the sign of the result */
+ /* is positive if both values have the same sign, negative if the */
+ /* values have different signs. */
+
return a / b;
- else {
- if (a > 0)
- return DBL_POSINF;
- else if (a < 0)
- return DBL_NEGINF;
+
+ } else {
+ if (isnan(b)) {
+ /* If either value1' or value2' is NaN, the result is NaN. */
+
+ return longBitsToDouble(DBL_NAN);
+
+ } else {
+ /* Division of a finite value by an infinity results in a */
+ /* signed zero, with the sign-producing rule just given. */
+
+ /* is sign equal? */
+
+ if (copysign(1.0, a) == copysign(1.0, b))
+ return 0.0;
+ else
+ return -0.0;
+ }
+ }
+
+ } else {
+ if (isnan(a)) {
+ /* If either value1' or value2' is NaN, the result is NaN. */
+
+ return longBitsToDouble(DBL_NAN);
+
+ } else if (finite(b)) {
+ /* Division of an infinity by a finite value results in a signed */
+ /* infinity, with the sign-producing rule just given. */
+
+ /* is sign equal? */
+
+ if (copysign(1.0, a) == copysign(1.0, b))
+ return longBitsToDouble(DBL_POSINF);
+ else
+ return longBitsToDouble(DBL_NEGINF);
+
+ } else {
+ /* Division of an infinity by an infinity results in NaN. */
+
+ return longBitsToDouble(DBL_NAN);
}
}
- return DBL_NAN;
}
return fmod(a, b);
}
+/* builtin_dneg ****************************************************************
+
+ Implemented as described in VM Spec.
+
+*******************************************************************************/
double builtin_dneg(double a)
{
- if (isnan(a)) return a;
- else {
- if (finite(a)) return -a;
- else return copysign(a, -copysign(1.0, a));
+ if (isnan(a)) {
+ /* If the operand is NaN, the result is NaN (recall that NaN has no */
+ /* sign). */
+
+ return a;
+
+ } else {
+ if (finite(a)) {
+ /* If the operand is a zero, the result is the zero of opposite */
+ /* sign. */
+
+ return -a;
+
+ } else {
+ /* If the operand is an infinity, the result is the infinity of */
+ /* opposite sign. */
+
+ return copysign(a, -copysign(1.0, a));
+ }
}
}
#if U8_AVAILABLE
return i;
#else
- s8 v; v.high = 0; v.low=i; return v;
+ s8 v;
+ v.high = 0;
+ v.low = i;
+ return v;
#endif
}
s4 builtin_f2i(float a)
{
+ s4 i;
+
+ i = builtin_d2i((double) a);
- return builtin_d2i((double) a);
+ return i;
/* float f;
s8 builtin_f2l(float a)
{
+ s8 l;
+
+ l = builtin_d2l((double) a);
- return builtin_d2l((double) a);
+ return l;
/* float f;
if (finitef(a)) return (double) a;
else {
if (isnanf(a))
- return DBL_NAN;
+ return longBitsToDouble(DBL_NAN);
else
- return copysign(DBL_POSINF, (double) copysignf(1.0, a) );
+ return copysign(longBitsToDouble(DBL_POSINF), (double) copysignf(1.0, a) );
}
}
return (float) a;
else {
if (isnan(a))
- return FLT_NAN;
+ return intBitsToFloat(FLT_NAN);
else
- return copysignf(FLT_POSINF, (float) copysign(1.0, a));
+ return copysignf(intBitsToFloat(FLT_POSINF), (float) copysign(1.0, a));
}
}
-java_arrayheader *builtin_clone_array(void *env,java_arrayheader *o) {
- return Java_java_lang_VMObject_clone ( 0 , 0, o);
+/* used to convert FLT_xxx defines into float values */
+
+inline float intBitsToFloat(s4 i)
+{
+ imm_union imb;
+
+ imb.i = i;
+ return imb.f;
+}
+
+
+/* used to convert DBL_xxx defines into double values */
+
+inline float longBitsToDouble(s8 l)
+{
+ imm_union imb;
+
+ imb.l = l;
+ return imb.d;
+}
+
+
+/* builtin_clone_array *********************************************************
+
+ Wrapper function for cloning arrays.
+
+*******************************************************************************/
+
+java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o)
+{
+ java_arrayheader *ah;
+ java_lang_Cloneable *c;
+
+ c = (java_lang_Object *) o;
+
+ ah = (java_arrayheader *) Java_java_lang_VMObject_clone(0, 0, c);
+
+ return ah;
+}
+
+
+/* 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(void)
+{
+ return builtin_get_exceptionptrptr();
+}
+#endif
+
+
+methodinfo *builtin_asm_get_threadrootmethod(void)
+{
+ return *threadrootmethod;
+}
+
+
+void *builtin_asm_get_stackframeinfo(void)
+{
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ return &THREADINFO->_stackframeinfo;
+#else
+ /* XXX FIXME FOR OLD THREAD IMPL (jowenn) */
+
+ 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;
+
+ /* XXX change this if line numbers bigger than u2 are allowed, the */
+ /* currently supported class file format does no allow that */
+
+ (*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;
}