-/* 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 908 2004-02-02 00:51:04Z twisti $
+ $Id: builtin.c 3801 2005-11-26 19:15:45Z twisti $
*/
#include <assert.h>
+#include <stdlib.h>
#include <string.h>
-#include <math.h>
-#include "main.h"
-#include "global.h"
-#include "builtin.h"
-#include "native.h"
-#include "loader.h"
-#include "tables.h"
-#include "asmpart.h"
+
+#include "config.h"
+#include "vm/types.h"
+
+#include "arch.h"
+#include "md-abi.h"
+
+#include "fdlibm/fdlibm.h"
+
#include "mm/boehm.h"
-#include "threads/thread.h"
-#include "threads/locks.h"
-#include "toolbox/loging.h"
-#include "toolbox/memory.h"
-#include "nat/java_lang_Cloneable.h"
-#include "nat/java_lang_VMObject.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"
+
+
+/* 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;
-#undef DEBUG /*define DEBUG 1*/
+ 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);
+}
/*****************************************************************************
*****************************************************************************/
s4 builtin_isanysubclass(classinfo *sub, classinfo *super)
-{
+{
s4 res;
+ castinfo classvalues;
- /*classinfo *tmp;*/
- if (super->flags & ACC_INTERFACE)
- return (sub->vftbl->interfacetablelength > super->index) &&
- (sub->vftbl->interfacetable[-super->index] != NULL);
+ if (sub == super)
+ return 1;
- /*
- while (sub != 0)
- if (sub == super)
- return 1;
- else
- sub = sub->super;
+ if (super->flags & ACC_INTERFACE) {
+ res = (sub->vftbl->interfacetablelength > super->index) &&
+ (sub->vftbl->interfacetable[-super->index] != NULL);
- return 0;
- */
+ } else {
+ asm_getclassvalues_atomic(super->vftbl, sub->vftbl, &classvalues);
-/*
- for (tmp=sub;tmp!=0;tmp=tmp->super) {
- printf("->");
- utf_display(tmp->name);
+ res = (u4) (classvalues.sub_baseval - classvalues.super_baseval) <=
+ (u4) classvalues.super_diffval;
}
- printf("\n\n");
-
- for (tmp=super;tmp!=0;tmp=tmp->super) {
- printf("->");
- utf_display(tmp->name);
- }
- printf("\n");
-
-
- 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); */
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- cast_lock();
-#endif
-
- res = (unsigned) (sub->vftbl->baseval - super->vftbl->baseval) <=
- (unsigned) (super->vftbl->diffval);
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- cast_unlock();
-#endif
return res;
}
-s4 builtin_isanysubclass_vftbl(vftbl *sub,vftbl *super)
+
+s4 builtin_isanysubclass_vftbl(vftbl_t *sub, vftbl_t *super)
{
- int base;
s4 res;
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- cast_lock();
-#endif
+ s4 base;
+ castinfo classvalues;
+
+ if (sub == super)
+ return 1;
- if ((base = super->baseval) <= 0)
+ asm_getclassvalues_atomic(super, sub, &classvalues);
+
+ 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
+ } else {
+ res = (u4) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (u4) classvalues.super_diffval;
+ }
return res;
}
*****************************************************************************/
-/* XXX should use vftbl */
s4 builtin_instanceof(java_objectheader *obj, classinfo *class)
{
-#ifdef DEBUG
- log_text ("builtin_instanceof called");
-#endif
- if (!obj) return 0;
- return builtin_isanysubclass (obj->vftbl->class, class);
+ if (!obj)
+ return 0;
+
+ return builtin_isanysubclass(obj->vftbl->class, class);
}
****************************************************************************/
-/* XXX should use vftbl */
s4 builtin_checkcast(java_objectheader *obj, classinfo *class)
{
-#ifdef DEBUG
- log_text("builtin_checkcast called");
-#endif
-
if (obj == NULL)
return 1;
+
if (builtin_isanysubclass(obj->vftbl->class, class))
return 1;
-#if DEBUG
- printf("#### checkcast failed ");
- utf_display(obj->vftbl->class->name);
- printf(" -> ");
- utf_display(class->name);
- printf("\n");
-#endif
-
return 0;
}
-/*********** 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
+
+ Return value: 1 ... target = desc is possible
+ 0 ... otherwise
-******************************************************************************/
+*******************************************************************************/
-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)
- return builtin_isanysubclass_vftbl(desc->elementvftbl,target->elementvftbl);
- if (desc->dimension < target->dimension) return 0;
+
+ 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 ***********************
+/* builtin_arraycheckcast ******************************************************
- 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.
+ 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.
-
-*****************************************************************************/
+*******************************************************************************/
-s4 builtin_checkarraycast(java_objectheader *o, vftbl *target)
+s4 builtin_arraycheckcast(java_objectheader *o, classinfo *targetclass)
{
arraydescriptor *desc;
-
- if (!o) return 1;
- if ((desc = o->vftbl->arraydesc) == NULL) return 0;
- return builtin_descriptorscompatible(desc, target->arraydesc);
+ if (!o)
+ return 1;
+
+ if ((desc = o->vftbl->arraydesc) == NULL)
+ return 0;
+
+ return builtin_descriptorscompatible(desc, targetclass->vftbl->arraydesc);
}
-s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl *target)
+s4 builtin_arrayinstanceof(java_objectheader *o, classinfo *targetclass)
{
- if (!obj) return 1;
- return builtin_checkarraycast(obj, target);
+ if (!o)
+ return 0;
+
+ return builtin_arraycheckcast(o, targetclass);
}
******************************************************************************/
-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: <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");
+ java_lang_Throwable *t;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+
+ if (opt_verbose) {
+ t = (java_lang_Throwable *) xptr;
+
+ /* calculate message length */
+
+ logtextlen = strlen("Builtin exception thrown: ") + strlen("0");
+
+ if (t) {
+ logtextlen +=
+ utf_strlen(xptr->vftbl->class->name) +
+ strlen(": ") +
+ javastring_strlen((java_objectheader *) t->detailMessage);
+
+ } 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;
+
+ buf = javastring_tochar((java_objectheader *) t->detailMessage);
+ strcat(logtext, ": ");
+ strcat(logtext, buf);
+ MFREE(buf, char, strlen(buf));
}
+
+ } else {
+ strcat(logtext, "(nil)");
+ }
+
log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
}
- *exceptionptr = local_exceptionptr;
- return local_exceptionptr;
-}
-void builtin_reset_exceptionptr()
-{
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-#ifdef HAVE___THREAD
- _exceptionptr = NULL;
-#else
- ((nativethread*) pthread_getspecific(tkey_exceptionptr))->_exceptionptr = 0;
-#endif
-#else
- panic("builtin_reset_exceptionptr should not be used in this configuration");
-#endif
+ *exceptionptr = xptr;
+
+ return xptr;
}
-/******************* function: builtin_canstore *******************************
- Checks, if an object can be stored in an array.
- Return value: 1 ... possible
- 0 ... otherwise
+/* builtin_canstore ************************************************************
-******************************************************************************/
+ Checks, if an object can be stored in an array.
-s4 builtin_canstore (java_objectarray *a, java_objectheader *o)
+ Return value: 1 ... possible
+ 0 ... otherwise
+
+*******************************************************************************/
+
+s4 builtin_canstore(java_objectarray *oa, java_objectheader *o)
{
arraydescriptor *desc;
arraydescriptor *valuedesc;
- vftbl *componentvftbl;
- vftbl *valuevftbl;
- int dim_m1;
- int base;
+ vftbl_t *componentvftbl;
+ vftbl_t *valuevftbl;
+ s4 base;
+ castinfo classvalues;
- if (!o) return 1;
+ if (!o)
+ return 1;
/* The following is guaranteed (by verifier checks):
*
* *) o->vftbl is not an interface vftbl
*/
- desc = a->header.objheader.vftbl->arraydesc;
- componentvftbl = desc->componentvftbl;
- valuevftbl = o->vftbl;
+ desc = oa->header.objheader.vftbl->arraydesc;
+ componentvftbl = desc->componentvftbl;
+ valuevftbl = o->vftbl;
- if ((dim_m1 = desc->dimension - 1) == 0) {
+ if ((desc->dimension - 1) == 0) {
s4 res;
/* {a is a one-dimensional array} */
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;
- }
- /* {a has dimension > 1} */
+ }
+
+ /* {a has dimension > 1} */
/* {componentvftbl->arraydesc != NULL} */
/* check if o is an array */
+
if ((valuedesc = valuevftbl->arraydesc) == NULL)
return 0;
+
/* {o is an array} */
- return builtin_descriptorscompatible(valuedesc,componentvftbl->arraydesc);
+ return builtin_descriptorscompatible(valuedesc, componentvftbl->arraydesc);
}
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;
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;
}
* one-dimensional array of a class type */
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;
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
- cast_lock();
-#endif
-
- res = (unsigned)(valuevftbl->baseval - elementvftbl->baseval)
- <= (unsigned)(elementvftbl->diffval);
+ asm_getclassvalues_atomic(elementvftbl, valuevftbl, &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;
}
-/******************** 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;
+ /* is the class loaded */
+
+ assert(c->loaded);
+
+ /* check if we can instantiate this class */
+
+ if (c->flags & ACC_ABSTRACT) {
+ *exceptionptr =
+ new_exception_utfmessage(string_java_lang_InstantiationError,
+ c->name);
+ return NULL;
+ }
+
+ /* is the class linked */
+ if (!c->linked)
+ if (!link_class(c))
+ return NULL;
+
if (!c->initialized) {
- if (initverbose) {
- char logtext[MAXLOGTEXT];
- sprintf(logtext, "Initialize class ");
- utf_sprint(logtext + strlen(logtext), c->name);
- sprintf(logtext + strlen(logtext), " (from builtin_new)");
- log_text(logtext);
- }
- class_init(c);
+ 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;
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.
+/* builtin_newarray ************************************************************
- Return value: pointer to the array or NULL if no memory is available
+ Creates an array with the given vftbl on the heap. This function
+ takes as class argument an array class.
- CAUTION: The given vftbl must be the vftbl of the *array* class,
- not of the element class.
+ Return value: pointer to the array or NULL if no memory is available
-*****************************************************************************/
+*******************************************************************************/
-java_arrayheader *builtin_newarray(s4 size, vftbl *arrayvftbl)
+java_arrayheader *builtin_newarray(s4 size, classinfo *arrayclass)
{
+ arraydescriptor *desc;
+ s4 dataoffset;
+ s4 componentsize;
+ s4 actualsize;
java_arrayheader *a;
- arraydescriptor *desc = arrayvftbl->arraydesc;
- s4 dataoffset = desc->dataoffset;
- s4 componentsize = desc->componentsize;
- s4 actualsize;
- if (size<0) {
- *exceptionptr=native_new_and_init(loader_load(utf_new_char("java/lang/NegativeArraySizeException")));
+ desc = arrayclass->vftbl->arraydesc;
+ dataoffset = desc->dataoffset;
+ componentsize = desc->componentsize;
+
+ if (size < 0) {
+ *exceptionptr = new_negativearraysizeexception();
return NULL;
}
-#ifdef SIZE_FROM_CLASSINFO
- actualsize = align_size(dataoffset + size * componentsize);
-#else
+
actualsize = dataoffset + size * componentsize;
-#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);
+ a = heap_allocate(actualsize, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
+ if (!a)
+ return NULL;
- /*printf("builtin_newarray: Created an array of size : %d\n",size);*/
+ a->objheader.vftbl = arrayclass->vftbl;
- a->objheader.vftbl = arrayvftbl;
- a->size = size;
-#ifdef SIZE_FROM_CLASSINFO
- a->alignedsize = actualsize;
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ initObjectLock(&a->objheader);
#endif
+ a->size = size;
+
return a;
}
-/********************** Function: builtin_anewarray *************************
-
- Creates an array of references to the given class type on the heap.
+/* builtin_anewarray ***********************************************************
- Return value: pointer to the array or NULL if no memory is available
+ Creates an array of references to the given class type on the heap.
- XXX This function does not do The Right Thing, because it uses a
- classinfo pointer at runtime. builtin_newarray should be used
- instead.
+ Return value: pointer to the array or NULL if no memory is
+ available
-*****************************************************************************/
+*******************************************************************************/
-java_objectarray *builtin_anewarray(s4 size, classinfo *component)
+java_objectarray *builtin_anewarray(s4 size, classinfo *componentclass)
{
- return (java_objectarray*) builtin_newarray(size, class_array_of(component)->vftbl);
-}
+ classinfo *arrayclass;
+
+ /* is class loaded */
+ assert(componentclass->loaded);
-/******************** Function: builtin_newarray_int ***********************
+ /* is class linked */
- Creates an array of 32 bit Integers on the heap.
+ if (!componentclass->linked)
+ if (!link_class(componentclass))
+ return NULL;
- Return value: pointer to the array or NULL if no memory is available
+ arrayclass = class_array_of(componentclass, true);
-*****************************************************************************/
+ if (!arrayclass)
+ return NULL;
-java_intarray *builtin_newarray_int(s4 size)
+ return (java_objectarray *) builtin_newarray(size, arrayclass);
+}
+
+
+/* builtin_newarray_boolean ****************************************************
+
+ 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
+
+*******************************************************************************/
+
+java_booleanarray *builtin_newarray_boolean(s4 size)
{
- return (java_intarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_INT].arrayvftbl);
+ return (java_booleanarray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_BOOLEAN].arrayclass);
}
-/******************** Function: builtin_newarray_long ***********************
+/* builtin_newarray_byte *******************************************************
- Creates an array of 64 bit Integers 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_longarray *builtin_newarray_long(s4 size)
+java_bytearray *builtin_newarray_byte(s4 size)
{
- return (java_longarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_LONG].arrayvftbl);
+ return (java_bytearray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_BYTE].arrayclass);
}
-/******************** function: builtin_newarray_float ***********************
+/* builtin_newarray_char *******************************************************
- Creates an array of 32 bit IEEE floats on the heap.
+ Creates an array of characters 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_floatarray *builtin_newarray_float(s4 size)
+java_chararray *builtin_newarray_char(s4 size)
{
- return (java_floatarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_FLOAT].arrayvftbl);
+ return (java_chararray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_CHAR].arrayclass);
}
-/******************** function: builtin_newarray_double ***********************
+/* builtin_newarray_short ******************************************************
- Creates an array of 64 bit IEEE floats 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
-*****************************************************************************/
+*******************************************************************************/
-java_doublearray *builtin_newarray_double(s4 size)
+java_shortarray *builtin_newarray_short(s4 size)
{
- return (java_doublearray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_DOUBLE].arrayvftbl);
+ return (java_shortarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_SHORT].arrayclass);
}
-/******************** function: builtin_newarray_byte ***********************
+/* builtin_newarray_int ********************************************************
- Creates an array of 8 bit Integers on the heap.
+ Creates an array of 32 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_bytearray *builtin_newarray_byte(s4 size)
+java_intarray *builtin_newarray_int(s4 size)
{
- return (java_bytearray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_BYTE].arrayvftbl);
+ return (java_intarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_INT].arrayclass);
}
-/******************** function: builtin_newarray_char ************************
+/* builtin_newarray_long *******************************************************
- Creates an array of characters on the heap.
+ Creates an array of 64 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_chararray *builtin_newarray_char(s4 size)
+java_longarray *builtin_newarray_long(s4 size)
{
- return (java_chararray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl);
+ return (java_longarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_LONG].arrayclass);
}
-/******************** function: builtin_newarray_short ***********************
+/* builtin_newarray_float ******************************************************
- Creates an array of 16 bit Integers 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
-*****************************************************************************/
+*******************************************************************************/
-java_shortarray *builtin_newarray_short(s4 size)
+java_floatarray *builtin_newarray_float(s4 size)
{
- return (java_shortarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_SHORT].arrayvftbl);
+ return (java_floatarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_FLOAT].arrayclass);
}
-/******************** function: builtin_newarray_boolean ************************
+/* builtin_newarray_double *****************************************************
- 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 64 bit IEEE floats on the heap.
-*****************************************************************************/
+ Return value: pointer to the array or NULL if no memory is
+ available
-java_booleanarray *builtin_newarray_boolean(s4 size)
+*******************************************************************************/
+
+java_doublearray *builtin_newarray_double(s4 size)
{
- return (java_booleanarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
+ return (java_doublearray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_DOUBLE].arrayclass);
}
-/**************** function: builtin_nmultianewarray ***************************
+/* builtin_multianewarray_intern ***********************************************
- Creates a multi-dimensional array on the heap. The dimensions are passed in
- an array of longs.
+ Creates a multi-dimensional array on the heap. The dimensions are
+ passed in an array of longs.
- Arguments:
- n............number of dimensions to create
- arrayvftbl...vftbl of the array class
- dims.........array containing the size of each dimension to create
+ 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
+ Return value: pointer to the array or NULL if no memory is
+ available
******************************************************************************/
- /* Helper functions */
-
-java_arrayheader *builtin_nmultianewarray (int n, vftbl *arrayvftbl, long *dims)
+static java_arrayheader *builtin_multianewarray_intern(int n,
+ classinfo *arrayclass,
+ long *dims)
{
- int size, i;
+ s4 size;
java_arrayheader *a;
- vftbl *componentvftbl;
+ classinfo *componentclass;
+ s4 i;
/* create this dimension */
- size = (int) dims[0];
- a = builtin_newarray(size,arrayvftbl);
- if (!a) return NULL;
+
+ size = (s4) dims[0];
+ a = builtin_newarray(size, arrayclass);
+
+ if (!a)
+ return NULL;
/* if this is the last dimension return */
- if (!--n) return a;
- /* get the vftbl of the components to create */
- componentvftbl = arrayvftbl->arraydesc->componentvftbl;
+ if (!--n)
+ return a;
+
+ /* get the class of the components to create */
- /* The verifier guarantees this. */
- /* if (!componentvftbl) */
- /* panic ("multianewarray with too many dimensions"); */
+ componentclass = arrayclass->vftbl->arraydesc->componentvftbl->class;
+
+ /* The verifier guarantees that the dimension count is in the range. */
/* 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;
+ java_arrayheader *ea =
+#if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+ /* we save an s4 to a s8 slot, 8-byte aligned */
+
+ builtin_multianewarray_intern(n, componentclass, dims + 2);
+#else
+ builtin_multianewarray_intern(n, componentclass, dims + 1);
+#endif
+
+ if (!ea)
+ return NULL;
+
+ ((java_objectarray *) a)->data[i] = (java_objectheader *) ea;
}
return a;
}
+/* builtin_multianewarray ******************************************************
+
+ Wrapper for builtin_multianewarray_intern which checks all
+ dimensions before we start allocating.
+
+******************************************************************************/
+
+java_arrayheader *builtin_multianewarray(int n, classinfo *arrayclass,
+ long *dims)
+{
+ s4 i;
+ s4 size;
+
+ /* check all dimensions before doing anything */
+
+ for (i = 0; i < n; i++) {
+#if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+ /* we save an s4 to a s8 slot, 8-byte aligned */
+ size = (s4) dims[i * 2];
+#else
+ size = (s4) dims[i];
+#endif
+
+ if (size < 0) {
+ *exceptionptr = new_negativearraysizeexception();
+ return NULL;
+ }
+ }
+
+ /* now call the real function */
+
+ return builtin_multianewarray_intern(n, arrayclass, dims);
+}
+
+
/*****************************************************************************
METHOD LOGGING
*****************************************************************************/
+s4 methodindent = 0;
+
+java_objectheader *builtin_trace_exception(java_objectheader *xptr,
+ methodinfo *m,
+ void *pos,
+ s4 indent)
+{
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+
+ if (opt_verbose || runverbose || opt_verboseexception) {
+ /* when running with verbosecall we remove one indent level */
+
+ if (runverbose && indent)
+ methodindent--;
+
+ /* calculate message length */
+
+ 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
+
+ if (m->class->sourcefile == NULL)
+ logtextlen += strlen("<NO CLASSFILE INFORMATION>");
+ else
+ logtextlen += utf_strlen(m->class->sourcefile);
+
+ logtextlen += strlen(":65536)");
+
+ } else
+ logtextlen += strlen("call_java_method");
+
+ logtextlen += strlen("0");
+
+ /* allocate memory */
+
+ dumpsize = dump_size();
+
+ logtext = DMNEW(char, logtextlen);
+
+ if (xptr) {
+ strcpy(logtext, "Exception ");
+ utf_strcat_classname(logtext, xptr->vftbl->class->name);
+
+ } else {
+ strcpy(logtext, "Some Throwable");
+ }
+
+ strcat(logtext, " thrown in ");
+
+ if (m) {
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
+
+ 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
+
+ } 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
+
+ if (m->class->sourcefile == NULL)
+ strcat(logtext, "<NO CLASSFILE INFORMATION>");
+ else
+ utf_strcat(logtext, m->class->sourcefile);
+
+ sprintf(logtext + strlen(logtext), ":%d)", 0);
+ }
+
+ } else
+ strcat(logtext, "call_java_method");
+
+ log_text(logtext);
-u4 methodindent = 0;
+ /* release memory */
-java_objectheader *builtin_trace_exception(java_objectheader *_exceptionptr,
- methodinfo *method, int *pos,
- int noindent)
-{
- if (!noindent) {
- if (methodindent)
- methodindent--;
- else
- log_text("WARNING: unmatched methodindent--");
- }
- if (verbose || runverbose) {
- printf("Exception ");
- if (_exceptionptr) {
- utf_display(_exceptionptr->vftbl->class->name);
+ dump_release(dumpsize);
- } 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");
+ /* print stacktrace for exception */
+ if (opt_verboseexception) {
+ exceptions_print_exception(xptr);
+ stacktrace_print_trace(xptr);
}
- 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;
+ return xptr;
}
+/* builtin_trace_args **********************************************************
+
+ XXX
+
+*******************************************************************************/
+
#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
+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
- methodinfo *method)
+#endif /* TRACE_ARGS_NUM == 8 */
+ methodinfo *m)
{
- int 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);
- sprintf(logtext + strlen(logtext), ".");
- utf_sprint(logtext + strlen(logtext), method->name);
- utf_sprint(logtext + strlen(logtext), method->descriptor);
-
- if ( method->flags & ACC_PUBLIC ) sprintf (logtext + strlen(logtext)," PUBLIC");
- if ( method->flags & ACC_PRIVATE ) sprintf (logtext + strlen(logtext)," PRIVATE");
- if ( method->flags & ACC_PROTECTED ) sprintf (logtext + strlen(logtext)," PROTECTED");
- if ( method->flags & ACC_STATIC ) sprintf (logtext + strlen(logtext)," STATIC");
- if ( method->flags & ACC_FINAL ) sprintf (logtext + strlen(logtext)," FINAL");
- if ( method->flags & ACC_SYNCHRONIZED ) sprintf (logtext + strlen(logtext)," SYNCHRONIZED");
- if ( method->flags & ACC_VOLATILE ) sprintf (logtext + strlen(logtext)," VOLATILE");
- if ( method->flags & ACC_TRANSIENT ) sprintf (logtext + strlen(logtext)," TRANSIENT");
- if ( method->flags & ACC_NATIVE ) sprintf (logtext + strlen(logtext)," NATIVE");
- if ( method->flags & ACC_INTERFACE ) sprintf (logtext + strlen(logtext)," INTERFACE");
- if ( method->flags & ACC_ABSTRACT ) sprintf (logtext + strlen(logtext)," ABSTRACT");
-
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+ s4 pos;
+
+ md = m->parseddesc;
- sprintf(logtext + strlen(logtext), "(");
+ /* calculate message length */
- switch (method->paramcount) {
+ logtextlen =
+ 6 + methodindent + strlen("called: ") +
+ utf_strlen(m->class->name) +
+ strlen(".") +
+ utf_strlen(m->name) +
+ utf_strlen(m->descriptor) +
+ strlen(" SYNCHRONIZED") + strlen("(") + strlen(")");
+
+ /* add maximal argument length */
+
+ logtextlen += strlen("0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, 0x123456789abcdef0, ...(255)");
+
+ /* allocate memory */
+
+ dumpsize = dump_size();
+
+ logtext = DMNEW(char, logtextlen);
+
+ sprintf(logtext,"-%d-",methodindent);
+ pos = strlen(logtext);
+
+ for (i = 0; i < methodindent; i++)
+ logtext[pos++] = '\t';
+
+ strcpy(logtext + pos, "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), ")");
+
+ strcat(logtext, ")");
+
log_text(logtext);
+ /* release memory */
+
+ dump_release(dumpsize);
+
methodindent++;
}
#endif
-void builtin_displaymethodstart(methodinfo *method)
-{
- char logtext[MAXLOGTEXT];
- 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);
-
- if ( method->flags & ACC_PUBLIC ) sprintf (logtext + strlen(logtext)," PUBLIC");
- if ( method->flags & ACC_PRIVATE ) sprintf (logtext + strlen(logtext)," PRIVATE");
- if ( method->flags & ACC_PROTECTED ) sprintf (logtext + strlen(logtext)," PROTECTED");
- if ( method->flags & ACC_STATIC ) sprintf (logtext + strlen(logtext)," STATIC");
- if ( method->flags & ACC_FINAL ) sprintf (logtext + strlen(logtext)," FINAL");
- if ( method->flags & ACC_SYNCHRONIZED ) sprintf (logtext + strlen(logtext)," SYNCHRONIZED");
- if ( method->flags & ACC_VOLATILE ) sprintf (logtext + strlen(logtext)," VOLATILE");
- if ( method->flags & ACC_TRANSIENT ) sprintf (logtext + strlen(logtext)," TRANSIENT");
- if ( method->flags & ACC_NATIVE ) sprintf (logtext + strlen(logtext)," NATIVE");
- if ( method->flags & ACC_INTERFACE ) sprintf (logtext + strlen(logtext)," INTERFACE");
- if ( method->flags & ACC_ABSTRACT ) sprintf (logtext + strlen(logtext)," ABSTRACT");
+/* builtin_displaymethodstop ***************************************************
- log_text(logtext);
- methodindent++;
-}
+ 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;
- char logtext[MAXLOGTEXT];
- for (i = 0; i < methodindent; i++)
- logtext[i] = '\t';
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+ s4 pos;
+ imm_union imu;
+
+ md = m->parseddesc;
+
+ /* calculate message length */
+
+ logtextlen =
+ 6 + 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);
+
+ /* outdent the log message */
+
if (methodindent)
methodindent--;
else
log_text("WARNING: unmatched 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) {
+ /* generate the message */
+
+ sprintf(logtext,"-%d-",methodindent);
+ pos = strlen(logtext);
+
+ for (i = 0; i < methodindent; i++)
+ logtext[pos++] = '\t';
+
+ strcpy(logtext + pos, "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;
}
+
log_text(logtext);
-}
+ /* release memory */
-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);
+ dump_release(dumpsize);
}
SYNCHRONIZATION FUNCTIONS
*****************************************************************************/
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
/*
* Lock the mutex of an object.
*/
void internal_lock_mutex_for_object(java_objectheader *object)
{
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
mutexHashEntry *entry;
int hashValue;
entry->object = object;
internal_lock_mutex(&entry->mutex);
-#endif
}
+#endif
+#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
/*
* Unlocks the mutex of an object.
*/
void internal_unlock_mutex_for_object (java_objectheader *object)
{
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
int hashValue;
mutexHashEntry *entry;
firstFreeOverflowEntry = unlinked;
}
}
-#endif
}
+#endif
+#if defined(USE_THREADS)
void builtin_monitorenter(java_objectheader *o)
{
-#if defined(USE_THREADS) && !defined(NATIVE_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.
+ */
+void builtin_staticmonitorenter(classinfo *c)
{
-#if defined(USE_THREADS) && !defined(NATIVE_THREADS)
- int hashValue;
+ 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)
/*********** Functions for floating point operations *************************/
+/* used to convert FLT_xxx defines into float values */
+
+static inline float intBitsToFloat(s4 i)
+{
+ imm_union imb;
+
+ imb.i = i;
+ return imb.f;
+}
+
+
+/* used to convert DBL_xxx defines into double values */
+
+static inline float longBitsToDouble(s8 l)
+{
+ imm_union imb;
+
+ imb.l = l;
+ return imb.d;
+}
+
+
float builtin_fadd(float a, float b)
{
if (isnanf(a)) return intBitsToFloat(FLT_NAN);
}
+/* 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)
+
+ } 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 if (a < 0)
+ else
return intBitsToFloat(FLT_NEGINF);
+
+ } else {
+ /* Division of an infinity by an infinity results in NaN. */
+
+ return intBitsToFloat(FLT_NAN);
}
}
- return intBitsToFloat(FLT_NAN);
}
}
+/* builtin_ddiv ****************************************************************
+
+ Implementation as described in VM Spec.
+
+*******************************************************************************/
+
double builtin_ddiv(double a, double b)
{
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 (isnan(b))
+ if (isnan(b)) {
+ /* If either value1' or value2' is NaN, the result is NaN. */
+
return longBitsToDouble(DBL_NAN);
- else
- return copysign(0.0, b);
+
+ } 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 (finite(b)) {
- if (a > 0)
+ 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 if (a < 0)
+ else
return longBitsToDouble(DBL_NEGINF);
- } else
+ } else {
+ /* Division of an infinity by an infinity results in NaN. */
+
return longBitsToDouble(DBL_NAN);
+ }
}
-
-/* if (finite(a) && finite(b)) { */
-/* if (b != 0) */
-/* return a / b; */
-/* else { */
-/* if (a > 0) */
-/* return longBitsToDouble(DBL_POSINF); */
-/* else if (a < 0) */
-/* return longBitsToDouble(DBL_NEGINF); */
-/* } */
-/* } */
-
- /* keep compiler happy */
- return 0;
}
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));
+ }
}
}
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;
}
-/* used to convert FLT_xxx defines into float values */
+/* builtin_clone_array *********************************************************
-inline float intBitsToFloat(s4 i)
-{
- imm_union imb;
+ Wrapper function for cloning arrays.
- imb.i = i;
- return imb.f;
-}
+*******************************************************************************/
+java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o)
+{
+ java_arrayheader *ah;
+ java_lang_Cloneable *c;
-/* used to convert DBL_xxx defines into double values */
+ c = (java_lang_Cloneable *) o;
-inline float longBitsToDouble(s8 l)
-{
- imm_union imb;
+ ah = (java_arrayheader *) Java_java_lang_VMObject_clone(0, 0, c);
- imb.l = l;
- return imb.d;
+ return ah;
}
-java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o)
-{
- return (java_arrayheader *) Java_java_lang_VMObject_clone(0, 0, (java_lang_Cloneable *) o);
-}
+/* builtin_asm_get_exceptionptrptr *********************************************
-s4 builtin_dummy()
+ this is a wrapper for calls from asmpart
+
+*******************************************************************************/
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+java_objectheader **builtin_asm_get_exceptionptrptr(void)
{
- panic("Internal error: builtin_dummy called (native function is missing)");
- return 0; /* for the compiler */
+ return builtin_get_exceptionptrptr();
}
+#endif
/*