/* src/vm/builtin.c - functions for unsupported operations
- 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
+ Copyright (C) 1996-2005, 2006 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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Authors: Reinhard Grafl
Andreas Krall
Mark Probst
Changes: Christian Thalinger
+ Edwin Steiner
Contains C functions for JavaVM Instructions that cannot be
translated to machine language directly. Consequently, the
calls instead of machine instructions, using the C calling
convention.
- $Id: builtin.c 2874 2005-06-29 14:57:36Z twisti $
+ $Id: builtin.c 4690 2006-03-27 11:37:46Z twisti $
*/
+#include "config.h"
+
#include <assert.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
-#include "config.h"
+#include "vm/types.h"
+
#include "arch.h"
#include "md-abi.h"
-#include "types.h"
+
+#include "fdlibm/fdlibm.h"
#include "mm/boehm.h"
#include "mm/memory.h"
#include "toolbox/logging.h"
#include "toolbox/util.h"
#include "vm/builtin.h"
+#include "vm/class.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*/
-
-THREADSPECIFIC methodinfo* _threadrootmethod = NULL;
-THREADSPECIFIC void *_thread_nativestackframeinfo = NULL;
-
-
/* include builtin tables *****************************************************/
#include "vm/builtintable.inc"
}
-/* builtintable_entry_debug_dump ***********************************************
-
- Prints a builtintable_entry in human-readable form.
-
-*******************************************************************************/
-
-void builtintable_entry_debug_dump(FILE *file, builtintable_entry *bte)
-{
- char *name;
- char *desc;
-
- if (!bte) {
- fprintf(file,"(builtintable_entry *)NULL");
- return;
- }
-
- name = bte->name;
- if (!name)
- name = "<name=NULL>";
- desc = (bte->md) ? "parsed " : bte->descriptor;
- if (!desc)
- desc = "<desc=NULL>";
- fprintf(file,"BUILTIN(%d,%p,%s %s",
- bte->opcode,(void*)bte->fp,name,desc);
- descriptor_debug_print_methoddesc(file,bte->md);
- fputc(')',file);
-}
-
-
/* builtintable_get_internal ***************************************************
Finds an entry in the builtintable for internal functions and
if (sub == super)
return 1;
- if (super->flags & ACC_INTERFACE)
- return (sub->vftbl->interfacetablelength > super->index) &&
+ if (super->flags & ACC_INTERFACE) {
+ res = (sub->vftbl->interfacetablelength > super->index) &&
(sub->vftbl->interfacetable[-super->index] != NULL);
- asm_getclassvalues_atomic(super->vftbl, sub->vftbl, &classvalues);
+ } else {
+ ASM_GETCLASSVALUES_ATOMIC(super->vftbl, sub->vftbl, &classvalues);
- res = (u4) (classvalues.sub_baseval - classvalues.super_baseval) <=
- (u4) classvalues.super_diffval;
+ res = (u4) (classvalues.sub_baseval - classvalues.super_baseval) <=
+ (u4) classvalues.super_diffval;
+ }
return res;
}
if (sub == super)
return 1;
- asm_getclassvalues_atomic(super, sub, &classvalues);
+ ASM_GETCLASSVALUES_ATOMIC(super, sub, &classvalues);
- if ((base = classvalues.super_baseval) <= 0)
+ if ((base = classvalues.super_baseval) <= 0) {
/* super is an interface */
res = (sub->interfacetablelength > -base) &&
(sub->interfacetable[base] != NULL);
- else
+ } 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;
****************************************************************************/
-/* 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;
}
*******************************************************************************/
-static s4 builtin_descriptorscompatible(arraydescriptor *desc, arraydescriptor *target)
+static s4 builtin_descriptorscompatible(arraydescriptor *desc,
+ arraydescriptor *target)
{
if (desc == target)
return 1;
/* {both arrays are arrays of references} */
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);
+ /* 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;
+
+ 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);
}
*******************************************************************************/
-s4 builtin_arraycheckcast(java_objectheader *o, vftbl_t *target)
+s4 builtin_arraycheckcast(java_objectheader *o, classinfo *targetclass)
{
arraydescriptor *desc;
if ((desc = o->vftbl->arraydesc) == NULL)
return 0;
- return builtin_descriptorscompatible(desc, target->arraydesc);
+ return builtin_descriptorscompatible(desc, targetclass->vftbl->arraydesc);
}
-s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl_t *target)
+s4 builtin_arrayinstanceof(java_objectheader *o, classinfo *targetclass)
{
- if (!obj)
- return 1;
+ if (!o)
+ return 0;
- return builtin_arraycheckcast(obj, target);
+ return builtin_arraycheckcast(o, targetclass);
}
******************************************************************************/
+#if !defined(NDEBUG)
java_objectheader *builtin_throw_exception(java_objectheader *xptr)
{
java_lang_Throwable *t;
logtextlen +=
utf_strlen(xptr->vftbl->class->name) +
strlen(": ") +
- javastring_strlen((java_objectheader *) t->detailMessage);
+ javastring_strlen(t->detailMessage);
} else
logtextlen += strlen("(nil)");
return xptr;
}
-
+#endif /* !defined(NDEBUG) */
/* builtin_canstore ************************************************************
*******************************************************************************/
-s4 builtin_canstore(java_objectarray *a, java_objectheader *o)
+s4 builtin_canstore(java_objectarray *oa, java_objectheader *o)
{
arraydescriptor *desc;
arraydescriptor *valuedesc;
- vftbl_t *componentvftbl;
- vftbl_t *valuevftbl;
- int base;
- castinfo classvalues;
-
+ vftbl_t *componentvftbl;
+ vftbl_t *valuevftbl;
+ s4 base;
+ castinfo classvalues;
+
if (!o)
return 1;
/* The following is guaranteed (by verifier checks):
*
- * *) a->...vftbl->arraydesc != NULL
- * *) a->...vftbl->arraydesc->componentvftbl != NULL
+ * *) oa->...vftbl->arraydesc != NULL
+ * *) oa->...vftbl->arraydesc->componentvftbl != NULL
* *) o->vftbl is not an interface vftbl
*/
- desc = a->header.objheader.vftbl->arraydesc;
+ desc = oa->header.objheader.vftbl->arraydesc;
componentvftbl = desc->componentvftbl;
- valuevftbl = o->vftbl;
+ valuevftbl = o->vftbl;
if ((desc->dimension - 1) == 0) {
s4 res;
- /* {a is a one-dimensional array} */
- /* {a is an array of references} */
+ /* {oa is a one-dimensional array} */
+ /* {oa is an array of references} */
if (valuevftbl == componentvftbl)
return 1;
- asm_getclassvalues_atomic(componentvftbl, valuevftbl, &classvalues);
+ 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);
- res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
- <= (unsigned) classvalues.super_diffval;
+ res = ((unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
+ <= (unsigned) classvalues.super_diffval);
return res;
}
- /* {a has dimension > 1} */
+ /* {oa 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);
}
if (valuevftbl == elementvftbl)
return 1;
- asm_getclassvalues_atomic(elementvftbl, valuevftbl, &classvalues);
+ ASM_GETCLASSVALUES_ATOMIC(elementvftbl, valuevftbl, &classvalues);
if ((base = classvalues.super_baseval) <= 0)
/* an array of interface references */
if (valuevftbl == elementvftbl)
return 1;
- asm_getclassvalues_atomic(elementvftbl, valuevftbl, &classvalues);
+ ASM_GETCLASSVALUES_ATOMIC(elementvftbl, valuevftbl, &classvalues);
res = (unsigned) (classvalues.sub_baseval - classvalues.super_baseval)
<= (unsigned) classvalues.super_diffval;
java_objectheader *o;
/* is the class loaded */
- /*utf_fprint(stderr,c->name);fprintf(stderr,"\n");*/
- assert(c->loaded);
+
+ assert(c->state & CLASS_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 (!(c->state & CLASS_LINKED))
if (!link_class(c))
return NULL;
- if (!c->initialized) {
+ if (!(c->state & CLASS_INITIALIZED)) {
+#if !defined(NDEBUG)
if (initverbose)
log_message_class("Initialize class (from builtin_new): ", c);
+#endif
if (!initialize_class(c))
return NULL;
if (!o)
return NULL;
- MSET(o, 0, u1, c->instancesize);
-
o->vftbl = c->vftbl;
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
/* builtin_newarray ************************************************************
- Creates an array with the given vftbl on the heap.
+ Creates an array with the given vftbl on the heap. This function
+ takes as class argument an array class.
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_t *arrayvftbl)
+java_arrayheader *builtin_newarray(s4 size, classinfo *arrayclass)
{
+ arraydescriptor *desc;
+ s4 dataoffset;
+ s4 componentsize;
+ s4 actualsize;
java_arrayheader *a;
- arraydescriptor *desc;
- s4 dataoffset;
- s4 componentsize;
- s4 actualsize;
- desc = arrayvftbl->arraydesc;
- dataoffset = desc->dataoffset;
+ desc = arrayclass->vftbl->arraydesc;
+ dataoffset = desc->dataoffset;
componentsize = desc->componentsize;
if (size < 0) {
- *exceptionptr = new_negativearraysizeexception();
+ exceptions_throw_negativearraysizeexception();
return NULL;
}
if (!a)
return NULL;
- MSET(a, 0, u1, actualsize);
-
- a->objheader.vftbl = arrayvftbl;
+ a->objheader.vftbl = arrayclass->vftbl;
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
initObjectLock(&a->objheader);
*******************************************************************************/
-java_objectarray *builtin_anewarray(s4 size, classinfo *component)
+java_objectarray *builtin_anewarray(s4 size, classinfo *componentclass)
{
- classinfo *c;
+ classinfo *arrayclass;
/* is class loaded */
- assert(component->loaded);
+
+ assert(componentclass->state & CLASS_LOADED);
/* is class linked */
- if (!component->linked)
- if (!link_class(component))
+
+ if (!(componentclass->state & CLASS_LINKED))
+ if (!link_class(componentclass))
return NULL;
- c = class_array_of(component, true);
+ arrayclass = class_array_of(componentclass, true);
- if (!c)
+ if (!arrayclass)
return NULL;
- return (java_objectarray *) builtin_newarray(size, c->vftbl);
+ return (java_objectarray *) builtin_newarray(size, arrayclass);
}
-/* builtin_newarray_int ********************************************************
-
- Creates an array of 32 bit Integers on the heap.
+/* 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_intarray *builtin_newarray_int(s4 size)
+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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* 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
*******************************************************************************/
-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);
}
-/* builtin_newarray_boolean ****************************************************
+/* builtin_newarray_double *****************************************************
+
+ Creates an array of 64 bit IEEE floats on the heap.
- 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)
+java_doublearray *builtin_newarray_double(s4 size)
{
- return (java_booleanarray *)
+ return (java_doublearray *)
builtin_newarray(size,
- primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
+ primitivetype_table[ARRAYTYPE_DOUBLE].arrayclass);
}
-/* builtin_multianewarray ******************************************************
+/* builtin_multianewarray_intern ***********************************************
Creates a multi-dimensional array on the heap. The dimensions are
passed in an array of longs.
******************************************************************************/
-java_arrayheader *builtin_multianewarray(int n, vftbl_t *arrayvftbl, long *dims)
+static java_arrayheader *builtin_multianewarray_intern(int n,
+ classinfo *arrayclass,
+ long *dims)
{
- s4 size, i;
+ s4 size;
java_arrayheader *a;
- vftbl_t *componentvftbl;
+ classinfo *componentclass;
+ s4 i;
/* create this dimension */
size = (s4) dims[0];
- a = builtin_newarray(size, arrayvftbl);
+ a = builtin_newarray(size, arrayclass);
if (!a)
return NULL;
if (!--n)
return a;
- /* get the vftbl of the components to create */
+ /* get the class of the components to create */
- componentvftbl = arrayvftbl->arraydesc->componentvftbl;
+ 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_multianewarray(n, componentvftbl, dims + 1);
+ 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;
}
+/* 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) {
+ exceptions_throw_negativearraysizeexception();
+ return NULL;
+ }
+ }
+
+ /* now call the real function */
+
+ return builtin_multianewarray_intern(n, arrayclass, dims);
+}
+
+
/*****************************************************************************
METHOD LOGGING
*****************************************************************************/
-u4 methodindent = 0;
+#if !defined(NDEBUG)
+static s4 methodindent = 0;
+static u4 callcount = 0;
java_objectheader *builtin_trace_exception(java_objectheader *xptr,
methodinfo *m,
void *pos,
- s4 line,
- s4 noindent)
+ s4 indent)
{
char *logtext;
s4 logtextlen;
s4 dumpsize;
+ codeinfo *code;
- if (!noindent) {
- if (methodindent)
- methodindent--;
- else
- log_text("WARNING: unmatched methodindent--");
- }
+ if (opt_verbosecall && indent)
+ methodindent--;
- if (opt_verbose || runverbose || verboseexception) {
- /* calculate message length */
+ /* calculate message length */
- if (xptr) {
- logtextlen =
- strlen("Exception ") +
- utf_strlen(xptr->vftbl->class->name);
+ if (xptr) {
+ logtextlen =
+ strlen("Exception ") +
+ utf_strlen(xptr->vftbl->class->name);
- } else
- logtextlen = strlen("Some Throwable");
+ } else {
+ logtextlen = strlen("Some Throwable");
+ }
- logtextlen += strlen(" thrown in ");
+ logtextlen += strlen(" thrown in ");
- if (m) {
- logtextlen +=
- utf_strlen(m->class->name) +
- strlen(".") +
- utf_strlen(m->name) +
- strlen("(NOSYNC,NATIVE");
+ 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 (");
+ logtextlen +=
+ strlen(")(0x123456789abcdef0) at position 0x123456789abcdef0 (");
#else
- logtextlen += strlen(")(0x12345678) at position 0x12345678 (");
+ logtextlen += strlen(")(0x12345678) at position 0x12345678 (");
#endif
- if (m->class->sourcefile == NULL)
- logtextlen += strlen("<NO CLASSFILE INFORMATION>");
- else
- logtextlen += utf_strlen(m->class->sourcefile);
+ if (m->class->sourcefile == NULL)
+ logtextlen += strlen("<NO CLASSFILE INFORMATION>");
+ else
+ logtextlen += utf_strlen(m->class->sourcefile);
- logtextlen += strlen(":65536)");
+ logtextlen += strlen(":65536)");
- } else
- logtextlen += strlen("call_java_method");
+ } else
+ logtextlen += strlen("call_java_method");
- logtextlen += strlen("0");
+ logtextlen += strlen("0");
- /* allocate memory */
+ /* allocate memory */
- dumpsize = dump_size();
+ dumpsize = dump_size();
- logtext = DMNEW(char, logtextlen);
+ logtext = DMNEW(char, logtextlen);
- if (xptr) {
- strcpy(logtext, "Exception ");
- utf_strcat_classname(logtext, xptr->vftbl->class->name);
+ if (xptr) {
+ strcpy(logtext, "Exception ");
+ utf_strcat_classname(logtext, xptr->vftbl->class->name);
- } else {
- strcpy(logtext, "Some Throwable");
- }
+ } else {
+ strcpy(logtext, "Some Throwable");
+ }
- strcat(logtext, " thrown in ");
+ strcat(logtext, " thrown in ");
- if (m) {
- utf_strcat_classname(logtext, m->class->name);
- strcat(logtext, ".");
- utf_strcat(logtext, m->name);
+ 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_SYNCHRONIZED)
+ strcat(logtext, "(SYNC");
+ else
+ strcat(logtext, "(NOSYNC");
- if (m->flags & ACC_NATIVE) {
- strcat(logtext, ",NATIVE");
+ if (m->flags & ACC_NATIVE) {
+ strcat(logtext, ",NATIVE");
+
+ code = m->code;
#if SIZEOF_VOID_P == 8
- sprintf(logtext + strlen(logtext),
- ")(0x%016lx) at position 0x%016lx",
- (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%016lx) at position 0x%016lx",
+ (ptrint) code->entrypoint, (ptrint) pos);
#else
- sprintf(logtext + strlen(logtext),
- ")(0x%08x) at position 0x%08x",
- (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x",
+ (ptrint) code->entrypoint, (ptrint) pos);
#endif
- } else {
+ } else {
+
+ /* XXX preliminary: This should get the actual codeinfo */
+ /* in which the exception happened. */
+ code = m->code;
+
#if SIZEOF_VOID_P == 8
- sprintf(logtext + strlen(logtext),
- ")(0x%016lx) at position 0x%016lx (",
- (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%016lx) at position 0x%016lx (",
+ (ptrint) code->entrypoint, (ptrint) pos);
#else
- sprintf(logtext + strlen(logtext),
- ")(0x%08x) at position 0x%08x (",
- (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x (",
+ (ptrint) code->entrypoint, (ptrint) pos);
#endif
- if (m->class->sourcefile == NULL)
- strcat(logtext, "<NO CLASSFILE INFORMATION>");
- else
- utf_strcat(logtext, m->class->sourcefile);
+ if (m->class->sourcefile == NULL)
+ strcat(logtext, "<NO CLASSFILE INFORMATION>");
+ else
+ utf_strcat(logtext, m->class->sourcefile);
- sprintf(logtext + strlen(logtext), ":%d)", line);
- }
+ sprintf(logtext + strlen(logtext), ":%d)", 0);
+ }
- } else
- strcat(logtext, "call_java_method");
+ } else
+ strcat(logtext, "call_java_method");
- log_text(logtext);
+ log_text(logtext);
- /* release memory */
+ /* release memory */
- dump_release(dumpsize);
- }
+ dump_release(dumpsize);
return xptr;
}
+#endif /* !defined(NDEBUG) */
/* builtin_trace_args **********************************************************
*******************************************************************************/
+#if !defined(NDEBUG)
+
#ifdef TRACE_ARGS_NUM
-void builtin_trace_args(s8 a0, s8 a1, s8 a2, s8 a3,
+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
+#endif /* TRACE_ARGS_NUM >= 6 */
#if TRACE_ARGS_NUM == 8
s8 a6, s8 a7,
-#endif
+#endif /* TRACE_ARGS_NUM == 8 */
methodinfo *m)
{
methoddesc *md;
s4 logtextlen;
s4 dumpsize;
s4 i;
+ s4 pos;
md = m->parseddesc;
/* calculate message length */
logtextlen =
- methodindent + strlen("called: ") +
+ strlen("4294967295 ") +
+ strlen("-2147483647-") + /* INT_MAX should be sufficient */
+ methodindent +
+ strlen("called: ") +
utf_strlen(m->class->name) +
strlen(".") +
utf_strlen(m->name) +
logtext = DMNEW(char, logtextlen);
+ callcount++;
+
+ sprintf(logtext, "%10d ", callcount);
+ sprintf(logtext + strlen(logtext), "-%d-", methodindent);
+
+ pos = strlen(logtext);
+
for (i = 0; i < methodindent; i++)
- logtext[i] = '\t';
+ logtext[pos++] = '\t';
- strcpy(logtext + methodindent, "called: ");
+ strcpy(logtext + pos, "called: ");
utf_strcat_classname(logtext, m->class->name);
strcat(logtext, ".");
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;
a0, a1);
break;
+#if TRACE_ARGS_NUM >= 4
case 3:
sprintf(logtext + strlen(logtext),
"0x%llx, 0x%llx, 0x%llx",
break;
case 4:
- sprintf(logtext + strlen(logtext),
- "0x%llx, 0x%llx, 0x%llx, 0x%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),
- "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%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),
- "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%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 == 8
case 7:
- sprintf(logtext + strlen(logtext),
- "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%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),
- "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%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:
-#if TRACE_ARGS_NUM == 4
+#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, m->paramcount - 4);
+ 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, m->paramcount - 6);
+ a0, a1, a2, a3, a4, a5, md->paramcount - 6);
#elif TRACE_ARGS_NUM == 8
- sprintf(logtext + strlen(logtext),
- "0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, 0x%llx, ...(%d)",
- a0, a1, a2, a3, a4, a5, a6, a7, m->paramcount - 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
break;
#if TRACE_ARGS_NUM == 4
sprintf(logtext + strlen(logtext),
"0x%lx, 0x%lx, 0x%lx, 0x%lx, ...(%d)",
- a0, a1, a2, a3, m->paramcount - 4);
+ 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, m->paramcount - 6);
+ 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, m->paramcount - 8);
+ a0, a1, a2, a3, a4, a5, a6, a7, md->paramcount - 8);
#endif
break;
#endif /* SIZEOF_VOID_P == 4 */
methodindent++;
}
#endif
+#endif /* !defined(NDEBUG) */
/* builtin_displaymethodstop ***************************************************
*******************************************************************************/
+#if !defined(NDEBUG)
void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f)
{
- methoddesc *md;
- char *logtext;
- s4 logtextlen;
- s4 dumpsize;
- s4 i;
- imm_union imu;
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+ s4 pos;
+ java_objectheader *o;
+ java_lang_String *s;
+ classinfo *c;
+ s4 len;
+ utf *u;
+ imm_union imu;
md = m->parseddesc;
/* calculate message length */
logtextlen =
- methodindent + strlen("finished: ") +
+ strlen("4294967295 ") +
+ strlen("-2147483647-") + /* INT_MAX should be sufficient */
+ methodindent +
+ strlen("finished: ") +
utf_strlen(m->class->name) +
strlen(".") +
utf_strlen(m->name) +
logtext = DMNEW(char, logtextlen);
- /* generate the message */
-
- for (i = 0; i < methodindent; i++)
- logtext[i] = '\t';
+ /* outdent the log message */
if (methodindent)
methodindent--;
else
log_text("WARNING: unmatched methodindent--");
- strcpy(logtext + methodindent, "finished: ");
+ /* generate the message */
+
+ sprintf(logtext, " ");
+ sprintf(logtext + strlen(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);
case TYPE_ADR:
sprintf(logtext + strlen(logtext), "->%p", (void *) (ptrint) l);
+
+ /* check return argument for java.lang.Class or java.lang.String */
+
+ o = (java_objectheader *) (ptrint) l;
+
+ if (o != NULL) {
+ if (o->vftbl->class == class_java_lang_String) {
+ /* get java.lang.String object and the length of the
+ string */
+
+ s= (java_lang_String *) (ptrint) l;
+
+ len = strlen(", String = \"") + javastring_strlen(s) +
+ strlen("\"");
+
+ /* realloc memory for string length */
+
+ DMREALLOC(logtext, char, logtextlen, logtextlen + len);
+
+ /* convert to utf8 string and strcat it to the logtext */
+
+ u = javastring_toutf(s, false);
+
+ strcat(logtext, ", String = \"");
+ utf_strcat(logtext, u);
+ strcat(logtext, "\"");
+
+ } else {
+ if (o->vftbl->class == class_java_lang_Class) {
+ /* if the object returned is a java.lang.Class
+ cast it to classinfo structure and get the name
+ of the class */
+
+ c = (classinfo *) (ptrint) l;
+
+ u = c->name;
+
+ } else {
+ /* if the object returned is not a java.lang.String or
+ a java.lang.Class just print the name of the class */
+
+ u = o->vftbl->class->name;
+ }
+
+ len = strlen(", Class = \"") + utf_strlen(u) + strlen("\"");
+
+ /* realloc memory for string length */
+
+ DMREALLOC(logtext, char, logtextlen, logtextlen + len);
+
+ /* strcat to the logtext */
+
+ strcat(logtext, ", Class = \"");
+ utf_strcat(logtext, u);
+ strcat(logtext, "\"");
+ }
+ }
break;
case TYPE_FLT:
dump_release(dumpsize);
}
+#endif /* !defined(NDEBUG) */
/****************************************************************************
#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)
{
- use_class_as_object(c);
- builtin_monitorenter(&c->header);
+ builtin_monitorenter(&c->object.header);
}
#endif
******************************************************************************/
-s4 builtin_idiv(s4 a, s4 b) { return a / b; }
-s4 builtin_irem(s4 a, s4 b) { return a % b; }
+#if !SUPPORT_DIVISION
+s4 builtin_idiv(s4 a, s4 b)
+{
+ s4 c;
+ c = a / b;
-/************** Functions for long arithmetics *******************************
+ return c;
+}
- On systems where 64 bit Integers are not supported by the CPU, these
- functions are needed.
+s4 builtin_irem(s4 a, s4 b)
+{
+ s4 c;
+
+ c = a % b;
+
+ return c;
+}
+#endif /* !SUPPORT_DIVISION */
-******************************************************************************/
+/* functions for long arithmetics **********************************************
+
+ On systems where 64 bit Integers are not supported by the CPU,
+ these functions are needed.
+
+******************************************************************************/
+#if !(SUPPORT_LONG && SUPPORT_LONG_ADD)
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 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 builtin_lneg(s8 a)
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a * b;
+ c = -a;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
+#endif /* !(SUPPORT_LONG && SUPPORT_LONG_ADD) */
+
+
+#if !(SUPPORT_LONG && SUPPORT_LONG_MUL)
+s8 builtin_lmul(s8 a, s8 b)
+{
+ s8 c;
-s8 builtin_ldiv(s8 a, s8 b)
-{
#if U8_AVAILABLE
- return a / b;
+ c = a * b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
+#endif /* !(SUPPORT_LONG && SUPPORT_LONG_MUL) */
+
+
+#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
+s8 builtin_ldiv(s8 a, s8 b)
+{
+ s8 c;
-s8 builtin_lrem(s8 a, s8 b)
-{
#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 builtin_lrem(s8 a, s8 b)
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a << (b & 63);
+ c = a % b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
+#endif /* !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV) */
+
+
+#if !(SUPPORT_LONG && SUPPORT_LONG_SHIFT)
+s8 builtin_lshl(s8 a, s4 b)
+{
+ s8 c;
-s8 builtin_lshr(s8 a, s4 b)
-{
#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 builtin_lshr(s8 a, s4 b)
+{
+ s8 c;
+
#if U8_AVAILABLE
- return ((u8) a) >> (b & 63);
+ c = a >> (b & 63);
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
-s8 builtin_land(s8 a, s8 b)
-{
+s8 builtin_lushr(s8 a, s4 b)
+{
+ s8 c;
+
#if U8_AVAILABLE
- return a & b;
+ c = ((u8) a) >> (b & 63);
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
+#endif /* !(SUPPORT_LONG && SUPPORT_LONG_SHIFT) */
+
+
+#if !(SUPPORT_LONG && SUPPORT_LONG_LOGICAL)
+s8 builtin_land(s8 a, s8 b)
+{
+ s8 c;
-s8 builtin_lor(s8 a, s8 b)
-{
#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 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_lneg(s8 a)
-{
+s8 builtin_lxor(s8 a, s8 b)
+{
+ s8 c;
+
#if U8_AVAILABLE
- return -a;
+ c = a ^ b;
#else
- return builtin_i2l(0);
+ c = builtin_i2l(0);
#endif
+
+ return c;
}
+#endif /* !(SUPPORT_LONG && SUPPORT_LONG_LOGICAL) */
+
-s4 builtin_lcmp(s8 a, s8 b)
+#if !(SUPPORT_LONG && SUPPORT_LONG_CMP)
+s4 builtin_lcmp(s8 a, s8 b)
{
#if U8_AVAILABLE
- if (a < b) return -1;
- if (a > b) return 1;
+ if (a < b)
+ return -1;
+
+ if (a > b)
+ return 1;
+
return 0;
#else
return 0;
#endif
}
+#endif /* !(SUPPORT_LONG && SUPPORT_LONG_CMP) */
+
+
+/* functions for unsupported floating instructions ****************************/
+
+/* 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;
+}
-/*********** Functions for floating point operations *************************/
+#if !SUPPORT_FLOAT
float builtin_fadd(float a, float b)
{
if (isnanf(a)) return intBitsToFloat(FLT_NAN);
}
-float builtin_frem(float a, float b)
-{
- return fmodf(a, b);
-}
-
-
float builtin_fneg(float a)
{
if (isnanf(a)) return a;
else return copysignf(a, -copysignf(1.0, a));
}
}
+#endif /* !SUPPORT_FLOAT */
+#if !SUPPORT_FLOAT || defined(ENABLE_INTRP)
s4 builtin_fcmpl(float a, float b)
{
if (isnanf(a)) return -1;
if (a == b) return 0;
return -1;
}
+#endif /* !SUPPORT_FLOAT || defined(ENABLE_INTRP) */
+float builtin_frem(float a, float b)
+{
+ return fmodf(a, b);
+}
+
-/************************* Functions for doubles ****************************/
+/* functions for unsupported double instructions ******************************/
+#if !SUPPORT_DOUBLE
double builtin_dadd(double a, double b)
{
if (isnan(a)) return longBitsToDouble(DBL_NAN);
}
-double builtin_drem(double a, double b)
-{
- return fmod(a, b);
-}
-
/* builtin_dneg ****************************************************************
Implemented as described in VM Spec.
}
}
}
+#endif /* !SUPPORT_DOUBLE */
+#if !SUPPORT_DOUBLE || defined(ENABLE_INTRP)
s4 builtin_dcmpl(double a, double b)
{
if (isnan(a)) return -1;
if (a == b) return 0;
return -1;
}
+#endif /* !SUPPORT_DOUBLE || defined(ENABLE_INTRP) */
+
+
+double builtin_drem(double a, double b)
+{
+ return fmod(a, b);
+}
-/*********************** Conversion operations ****************************/
+/* conversion operations ******************************************************/
+#if 0
s8 builtin_i2l(s4 i)
{
#if U8_AVAILABLE
#endif
}
+s4 builtin_l2i(s8 l)
+{
+#if U8_AVAILABLE
+ return (s4) l;
+#else
+ return l.low;
+#endif
+}
+#endif
+
+#if !(SUPPORT_FLOAT && SUPPORT_I2F)
float builtin_i2f(s4 a)
{
float f = (float) a;
return f;
}
+#endif /* !(SUPPORT_FLOAT && SUPPORT_I2F) */
+#if !(SUPPORT_DOUBLE && SUPPORT_I2D)
double builtin_i2d(s4 a)
{
double d = (double) a;
return d;
}
+#endif /* !(SUPPORT_DOUBLE && SUPPORT_I2D) */
-s4 builtin_l2i(s8 l)
-{
-#if U8_AVAILABLE
- return (s4) l;
-#else
- return l.low;
-#endif
-}
-
-
+#if !(SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_L2F)
float builtin_l2f(s8 a)
{
#if U8_AVAILABLE
return 0.0;
#endif
}
+#endif /* !(SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_L2F) */
+#if !(SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_L2D)
double builtin_l2d(s8 a)
{
#if U8_AVAILABLE
return 0.0;
#endif
}
+#endif /* !(SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_L2D) */
+#if !(SUPPORT_FLOAT && SUPPORT_F2I) || defined(ENABLE_INTRP)
s4 builtin_f2i(float a)
{
+ s4 i;
- return builtin_d2i((double) a);
+ i = builtin_d2i((double) a);
+
+ return i;
/* float f;
return 2147483647;
return (-2147483648); */
}
+#endif /* !(SUPPORT_FLOAT && SUPPORT_F2I) || defined(ENABLE_INTRP) */
+#if !(SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_F2L)
s8 builtin_f2l(float a)
{
+ s8 l;
+
+ l = builtin_d2l((double) a);
- return builtin_d2l((double) a);
+ return l;
/* float f;
return 9223372036854775807L;
return (-9223372036854775808L); */
}
+#endif /* !(SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_F2L) */
-double builtin_f2d(float a)
-{
- if (finitef(a)) return (double) a;
- else {
- if (isnanf(a))
- return longBitsToDouble(DBL_NAN);
- else
- return copysign(longBitsToDouble(DBL_POSINF), (double) copysignf(1.0, a) );
- }
-}
-
-
+#if !(SUPPORT_DOUBLE && SUPPORT_D2I) || defined(ENABLE_INTRP)
s4 builtin_d2i(double a)
{
double d;
return 2147483647;
return (-2147483647-1);
}
+#endif /* !(SUPPORT_DOUBLE && SUPPORT_D2I) || defined(ENABLE_INTRP) */
+#if !(SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_D2L)
s8 builtin_d2l(double a)
{
double d;
return 9223372036854775807LL;
return (-9223372036854775807LL-1);
}
+#endif /* !(SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_D2L) */
+#if !(SUPPORT_FLOAT && SUPPORT_DOUBLE)
+double builtin_f2d(float a)
+{
+ if (finitef(a)) return (double) a;
+ else {
+ if (isnanf(a))
+ return longBitsToDouble(DBL_NAN);
+ else
+ return copysign(longBitsToDouble(DBL_POSINF), (double) copysignf(1.0, a) );
+ }
+}
+
float builtin_d2f(double a)
{
if (finite(a))
return copysignf(intBitsToFloat(FLT_POSINF), (float) copysign(1.0, a));
}
}
+#endif /* !(SUPPORT_FLOAT && SUPPORT_DOUBLE) */
-/* 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;
+/* builtin_clone_array *********************************************************
- imb.l = l;
- return imb.d;
-}
+ Wrapper function for cloning arrays.
+*******************************************************************************/
java_arrayheader *builtin_clone_array(void *env, java_arrayheader *o)
{
- return (java_arrayheader *)
- Java_java_lang_VMObject_clone(0, 0, (java_lang_Cloneable *) o);
-}
+ java_arrayheader *ah;
+ java_lang_Cloneable *c;
+ c = (java_lang_Cloneable *) o;
-s4 builtin_dummy(void)
-{
- log_text("Internal error: builtin_dummy called (native function is missing)");
- assert(0);
-
- /* keep the compiler happy */
+ ah = (java_arrayheader *) Java_java_lang_VMObject_clone(0, 0, c);
- return 0;
+ return ah;
}
#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;
-}
-
-
/*
* These are local overrides for various environment variables in Emacs.
* Please do not remove this and leave it at the end of the file, where
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/