-/* vm/builtin.c - functions for unsupported operations
+/* 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,
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 1934 2005-02-10 10:58:43Z twisti $
+ $Id: builtin.c 2369 2005-04-25 14:06:16Z twisti $
*/
#include <assert.h>
-#include <string.h>
#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+#include "config.h"
+#include "arch.h"
+#include "types.h"
#include "mm/boehm.h"
#include "mm/memory.h"
#include "native/native.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
+#include "vm/initialize.h"
#include "vm/loader.h"
#include "vm/options.h"
#include "vm/stringlocal.h"
#include "vm/tables.h"
#include "vm/jit/asmpart.h"
+#include "vm/jit/patcher.h"
#undef DEBUG /*define DEBUG 1*/
THREADSPECIFIC void *_thread_nativestackframeinfo = NULL;
+#if defined(USEBUILTINTABLE)
+
+#if 0
+stdopdescriptor builtintable[] = {
+ { ICMD_LCMP, TYPE_LONG, TYPE_LONG, TYPE_INT, ICMD_BUILTIN2,
+ (functionptr) builtin_lcmp , SUPPORT_LONG && SUPPORT_LONG_CMP, false },
+ { ICMD_LAND, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_land , SUPPORT_LONG && SUPPORT_LONG_LOGICAL, false },
+ { ICMD_LOR, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lor , SUPPORT_LONG && SUPPORT_LONG_LOGICAL, false },
+ { ICMD_LXOR, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lxor , SUPPORT_LONG && SUPPORT_LONG_LOGICAL, false },
+ { ICMD_LSHL, TYPE_LONG, TYPE_INT, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lshl , SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
+ { ICMD_LSHR, TYPE_LONG, TYPE_INT, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lshr, SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
+ { ICMD_LUSHR, TYPE_LONG, TYPE_INT, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lushr, SUPPORT_LONG && SUPPORT_LONG_SHIFT, false },
+ { ICMD_LADD, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_ladd , SUPPORT_LONG && SUPPORT_LONG_ADD, false },
+ { ICMD_LSUB, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lsub , SUPPORT_LONG && SUPPORT_LONG_ADD, false },
+ { ICMD_LNEG, TYPE_LONG, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1,
+ (functionptr) builtin_lneg, SUPPORT_LONG && SUPPORT_LONG_ADD, true },
+ { ICMD_LMUL, TYPE_LONG, TYPE_LONG, TYPE_LONG, ICMD_BUILTIN2,
+ (functionptr) builtin_lmul , SUPPORT_LONG && SUPPORT_LONG_MUL, false },
+ { ICMD_I2F, TYPE_INT, TYPE_VOID, TYPE_FLOAT, ICMD_BUILTIN1,
+ (functionptr) builtin_i2f, SUPPORT_FLOAT && SUPPORT_IFCVT, true },
+ { ICMD_I2D, TYPE_INT, TYPE_VOID, TYPE_DOUBLE, ICMD_BUILTIN1,
+ (functionptr) builtin_i2d, SUPPORT_DOUBLE && SUPPORT_IFCVT, true },
+ { ICMD_L2F, TYPE_LONG, TYPE_VOID, TYPE_FLOAT, ICMD_BUILTIN1,
+ (functionptr) builtin_l2f, SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_LONG_FCVT, true },
+ { ICMD_L2D, TYPE_LONG, TYPE_VOID, TYPE_DOUBLE, ICMD_BUILTIN1,
+ (functionptr) builtin_l2d, SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_LONG_FCVT, true },
+ { ICMD_F2L, TYPE_FLOAT, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1,
+ (functionptr) builtin_f2l, SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_LONG_ICVT, true },
+ { ICMD_D2L, TYPE_DOUBLE, TYPE_VOID, TYPE_LONG, ICMD_BUILTIN1,
+ (functionptr) builtin_d2l, SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_LONG_ICVT, true },
+ { ICMD_F2I, TYPE_FLOAT, TYPE_VOID, TYPE_INT, ICMD_BUILTIN1,
+ (functionptr) builtin_f2i, SUPPORT_FLOAT && SUPPORT_FICVT, true },
+ { ICMD_D2I, TYPE_DOUBLE, TYPE_VOID, TYPE_INT, ICMD_BUILTIN1,
+ (functionptr) builtin_d2i, SUPPORT_DOUBLE && SUPPORT_FICVT, true },
+ { 255, 0, 0, 0, 0, NULL, true, false },
+};
+
+#endif
+
+static int builtintablelen;
+
+#endif /* USEBUILTINTABLE */
+
+
+/*****************************************************************************
+ TABLE OF BUILTIN FUNCTIONS
+
+ This table lists the builtin functions which are used inside
+ BUILTIN* opcodes.
+
+ The first part of the table (up to the 255-marker) lists the
+ opcodes which are automatically replaced in stack.c.
+
+ The second part lists the builtin functions which are "manually"
+ used for BUILTIN* opcodes in parse.c and stack.c.
+
+*****************************************************************************/
+
+builtin_descriptor builtin_desc[] = {
+#if defined(USEBUILTINTABLE)
+ {ICMD_LCMP , BUILTIN_lcmp ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_INT ,
+ SUPPORT_LONG && SUPPORT_LONG_CMP,false,"lcmp"},
+
+ {ICMD_LAND , BUILTIN_land ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_LOGICAL,false,"land"},
+ {ICMD_LOR , BUILTIN_lor ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_LOGICAL,false,"lor"},
+ {ICMD_LXOR , BUILTIN_lxor ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_LOGICAL,false,"lxor"},
+
+ {ICMD_LSHL , BUILTIN_lshl ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_INT ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lshl"},
+ {ICMD_LSHR , BUILTIN_lshr ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_INT ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lshr"},
+ {ICMD_LUSHR, BUILTIN_lushr,ICMD_BUILTIN2,TYPE_LONG ,TYPE_INT ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_SHIFT,false,"lushr"},
+
+ {ICMD_LADD , BUILTIN_ladd ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_ADD,false,"ladd"},
+ {ICMD_LSUB , BUILTIN_lsub ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_ADD,false,"lsub"},
+ {ICMD_LNEG , BUILTIN_lneg ,ICMD_BUILTIN1,TYPE_LONG ,TYPE_VOID ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_ADD,false,"lneg"},
+ {ICMD_LMUL , BUILTIN_lmul ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_LONG && SUPPORT_LONG_MUL,false,"lmul"},
+
+ {ICMD_I2F , BUILTIN_i2f ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_FLOAT ,
+ SUPPORT_FLOAT && SUPPORT_IFCVT,true ,"i2f"},
+ {ICMD_I2D , BUILTIN_i2d ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_DOUBLE,
+ SUPPORT_DOUBLE && SUPPORT_IFCVT,true ,"i2d"},
+ {ICMD_L2F , BUILTIN_l2f ,ICMD_BUILTIN1,TYPE_LONG ,TYPE_VOID ,TYPE_VOID ,TYPE_FLOAT ,
+ SUPPORT_LONG && SUPPORT_FLOAT && SUPPORT_LONG_FCVT,true ,"l2f"},
+ {ICMD_L2D , BUILTIN_l2d ,ICMD_BUILTIN1,TYPE_LONG ,TYPE_VOID ,TYPE_VOID ,TYPE_DOUBLE,
+ SUPPORT_LONG && SUPPORT_DOUBLE && SUPPORT_LONG_FCVT,true ,"l2d"},
+ {ICMD_F2L , BUILTIN_f2l ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_FLOAT && SUPPORT_LONG && SUPPORT_LONG_ICVT,true ,"f2l"},
+ {ICMD_D2L , BUILTIN_d2l ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID ,TYPE_VOID ,TYPE_LONG ,
+ SUPPORT_DOUBLE && SUPPORT_LONG && SUPPORT_LONG_ICVT,true ,"d2l"},
+ {ICMD_F2I , BUILTIN_f2i ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID ,TYPE_VOID ,TYPE_INT ,
+ SUPPORT_FLOAT && SUPPORT_FICVT,true ,"f2i"},
+ {ICMD_D2I , BUILTIN_d2i ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID ,TYPE_VOID ,TYPE_INT ,
+ SUPPORT_DOUBLE && SUPPORT_FICVT,true ,"d2i"},
+
+ { ICMD_FADD , BUILTIN_fadd , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT, true, "fadd" },
+ { ICMD_FSUB , BUILTIN_fsub , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT, true, "fsub" },
+ { ICMD_FMUL , BUILTIN_fmul , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT, true, "fmul" },
+ { ICMD_FDIV , BUILTIN_fdiv , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT, true, "fdiv" },
+ { ICMD_FNEG , BUILTIN_fneg , ICMD_BUILTIN1, TYPE_FLT, TYPE_VOID , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT, true, "fneg" },
+ { ICMD_FCMPL, BUILTIN_fcmpl , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_INT, SUPPORT_FLOAT, true, "fcmpl" },
+ { ICMD_FCMPG, BUILTIN_fcmpg , ICMD_BUILTIN2, TYPE_FLT, TYPE_FLT , TYPE_VOID , TYPE_INT, SUPPORT_FLOAT, true, "fcmpg" },
+
+ { ICMD_DADD , BUILTIN_dadd , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_DBL, SUPPORT_DOUBLE, true, "dadd" },
+ { ICMD_DSUB , BUILTIN_dsub , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_DBL, SUPPORT_DOUBLE, true, "dsub" },
+ { ICMD_DMUL , BUILTIN_dmul , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_DBL, SUPPORT_DOUBLE, true, "dmul" },
+ { ICMD_DDIV , BUILTIN_ddiv , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_DBL, SUPPORT_DOUBLE, true, "ddiv" },
+ { ICMD_DNEG , BUILTIN_dneg , ICMD_BUILTIN1, TYPE_DBL, TYPE_VOID , TYPE_VOID , TYPE_DBL, SUPPORT_DOUBLE, true, "dneg" },
+ { ICMD_DCMPL, BUILTIN_dcmpl , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_INT, SUPPORT_DOUBLE, true, "dcmpl" },
+ { ICMD_DCMPG, BUILTIN_dcmpg , ICMD_BUILTIN2, TYPE_DBL, TYPE_DBL , TYPE_VOID , TYPE_INT, SUPPORT_DOUBLE, true, "dcmpg" },
+
+ { ICMD_F2D, BUILTIN_f2d , ICMD_BUILTIN1, TYPE_FLT, TYPE_VOID , TYPE_VOID , TYPE_DBL, SUPPORT_FLOAT && SUPPORT_DOUBLE, true, "f2d" },
+ { ICMD_D2F, BUILTIN_d2f , ICMD_BUILTIN1, TYPE_DBL, TYPE_VOID , TYPE_VOID , TYPE_FLT, SUPPORT_FLOAT && SUPPORT_DOUBLE, true, "d2f" },
+#endif
+
+ /* this record marks the end of the automatically replaced opcodes */
+ {255,NULL,0,0,0,0,0,0,0,"<INVALID>"},
+
+ /* the following functions are not replaced automatically */
+
+#if defined(__ALPHA__)
+ {255, BUILTIN_f2l ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID ,TYPE_VOID ,TYPE_LONG ,0,0,"f2l"},
+ {255, BUILTIN_d2l ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID ,TYPE_VOID ,TYPE_LONG ,0,0,"d2l"},
+ {255, BUILTIN_f2i ,ICMD_BUILTIN1,TYPE_FLOAT ,TYPE_VOID ,TYPE_VOID ,TYPE_INT ,0,0,"f2i"},
+ {255, BUILTIN_d2i ,ICMD_BUILTIN1,TYPE_DOUBLE,TYPE_VOID ,TYPE_VOID ,TYPE_INT ,0,0,"d2i"},
+#endif
+
+ {255,BUILTIN_instanceof ,ICMD_BUILTIN2,TYPE_ADR ,TYPE_ADR ,TYPE_VOID ,TYPE_INT ,0,0,"instanceof"},
+ {255,BUILTIN_arrayinstanceof ,ICMD_BUILTIN2,TYPE_ADR ,TYPE_ADR ,TYPE_VOID ,TYPE_INT ,0,0,"arrayinstanceof"},
+ {255,BUILTIN_checkarraycast ,ICMD_BUILTIN2,TYPE_ADR ,TYPE_ADR ,TYPE_VOID ,TYPE_VOID ,0,0,"checkarraycast"},
+ {255,BUILTIN_aastore ,ICMD_BUILTIN3,TYPE_ADR ,TYPE_INT ,TYPE_ADR ,TYPE_VOID ,0,0,"aastore"},
+ {255,BUILTIN_new ,ICMD_BUILTIN1,TYPE_ADR ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"new"},
+ {255,BUILTIN_newarray ,ICMD_BUILTIN2,TYPE_INT ,TYPE_ADR ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray"},
+ {255,BUILTIN_newarray_boolean,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_boolean"},
+ {255,BUILTIN_newarray_char ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_char"},
+ {255,BUILTIN_newarray_float ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_float"},
+ {255,BUILTIN_newarray_double ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_double"},
+ {255,BUILTIN_newarray_byte ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_byte"},
+ {255,BUILTIN_newarray_short ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_short"},
+ {255,BUILTIN_newarray_int ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_int"},
+ {255,BUILTIN_newarray_long ,ICMD_BUILTIN1,TYPE_INT ,TYPE_VOID ,TYPE_VOID ,TYPE_ADR ,0,0,"newarray_long"},
+#if defined(USE_THREADS)
+ {255,BUILTIN_monitorenter ,ICMD_BUILTIN1,TYPE_ADR ,TYPE_VOID ,TYPE_VOID ,TYPE_VOID ,0,0,"monitorenter"},
+ {255,BUILTIN_monitorexit ,ICMD_BUILTIN1,TYPE_ADR ,TYPE_VOID ,TYPE_VOID ,TYPE_VOID ,0,0,"monitorexit"},
+#endif
+#if !SUPPORT_DIVISION
+ {255,BUILTIN_idiv ,ICMD_BUILTIN2,TYPE_INT ,TYPE_INT ,TYPE_VOID ,TYPE_INT ,0,0,"idiv"},
+ {255,BUILTIN_irem ,ICMD_BUILTIN2,TYPE_INT ,TYPE_INT ,TYPE_VOID ,TYPE_INT ,0,0,"irem"},
+#endif
+#if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
+ {255,BUILTIN_ldiv ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,0,0,"ldiv"},
+ {255,BUILTIN_lrem ,ICMD_BUILTIN2,TYPE_LONG ,TYPE_LONG ,TYPE_VOID ,TYPE_LONG ,0,0,"lrem"},
+#endif
+ {255,BUILTIN_frem ,ICMD_BUILTIN2,TYPE_FLOAT ,TYPE_FLOAT ,TYPE_VOID ,TYPE_FLOAT ,0,0,"frem"},
+ {255,BUILTIN_drem ,ICMD_BUILTIN2,TYPE_DOUBLE,TYPE_DOUBLE,TYPE_VOID ,TYPE_DOUBLE,0,0,"drem"},
+
+
+#if defined(__X86_64__) || defined(__I386__)
+ /* assembler code patching functions */
+
+ { 255, PATCHER_builtin_new , ICMD_BUILTIN1, TYPE_ADR , TYPE_VOID , TYPE_VOID , TYPE_ADR , 0, 0, "new (calling patcher_builtin_new)" },
+ { 255, PATCHER_builtin_newarray , ICMD_BUILTIN1, TYPE_ADR , TYPE_VOID , TYPE_VOID , TYPE_ADR , 0, 0, "newarray (calling patcher_builtin_newarray)" },
+ { 255, PATCHER_builtin_checkarraycast , ICMD_BUILTIN2, TYPE_ADR , TYPE_ADR , TYPE_VOID , TYPE_VOID , 0, 0, "checkarraycast (calling patcher_builtin_checkarraycast)" },
+ { 255, PATCHER_builtin_arrayinstanceof, ICMD_BUILTIN2, TYPE_ADR , TYPE_ADR , TYPE_VOID , TYPE_INT , 0, 0, "arrayinstanceof (calling patcher_builtin_arrayinstanceof)" },
+#endif
+
+
+ /* this record marks the end of the list */
+
+ { 0, NULL, 0, 0, 0, 0, 0, 0, 0, "<END>" }
+};
+
+
+#if defined(USEBUILTINTABLE)
+
+static int stdopcompare(const void *a, const void *b)
+{
+ builtin_descriptor *o1 = (builtin_descriptor *) a;
+ builtin_descriptor *o2 = (builtin_descriptor *) b;
+ if (!o1->supported && o2->supported)
+ return -1;
+ if (o1->supported && !o2->supported)
+ return 1;
+ return (o1->opcode < o2->opcode) ? -1 : (o1->opcode > o2->opcode);
+}
+
+
+void sort_builtintable(void)
+{
+ int len;
+
+ len = 0;
+ while (builtin_desc[len].opcode != 255) len++;
+ qsort(builtin_desc, len, sizeof(builtin_descriptor), stdopcompare);
+
+ for (--len; len>=0 && builtin_desc[len].supported; len--);
+ builtintablelen = ++len;
+}
+
+
+builtin_descriptor *find_builtin(int icmd)
+{
+ builtin_descriptor *first = builtin_desc;
+ builtin_descriptor *last = builtin_desc + builtintablelen;
+ int len = last - first;
+ int half;
+ builtin_descriptor *middle;
+
+ while (len > 0) {
+ half = len / 2;
+ middle = first + half;
+ if (middle->opcode < icmd) {
+ first = middle + 1;
+ len -= half + 1;
+ } else
+ len = half;
+ }
+ return first != last ? first : NULL;
+}
+
+#endif /* defined(USEBUILTINTABLE) */
+
+
/*****************************************************************************
TYPE CHECKS
*****************************************************************************/
#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);
}
}
-/*********** 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) {
/* 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;
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_checkarraycast ******************************************************
- Checks if an object is really a subtype of the requested array type.
- The object has to be an array to begin with. For simple arrays (int, short,
- double, etc.) the types have to match exactly.
- For arrays of objects, the type of elements in the array has to be a
- subtype (or the same type) of the requested element type. For arrays of
- arrays (which in turn can again be arrays of arrays), the types at the
- lowest level have to satisfy the corresponding sub class relation.
-
- Return value: 1 ... cast is possible
- 0 ... otherwise
+ 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.
- ATTENTION: a cast with a NULL pointer is always possible.
-
-*****************************************************************************/
+*******************************************************************************/
s4 builtin_checkarraycast(java_objectheader *o, vftbl_t *target)
{
arraydescriptor *desc;
-
- if (!o) return 1;
- if ((desc = o->vftbl->arraydesc) == NULL) return 0;
+ if (!o)
+ return 1;
+
+ if ((desc = o->vftbl->arraydesc) == NULL)
+ return 0;
+
return builtin_descriptorscompatible(desc, target->arraydesc);
}
}
-/******************** 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 */
- if (!c->loaded)
- if (!class_load(c))
- return NULL;
+ /*utf_fprint(stderr,c->name);fprintf(stderr,"\n");*/
+ assert(c->loaded);
/* is the class linked */
if (!c->linked)
- if (!class_link(c))
+ if (!link_class(c))
return NULL;
if (!c->initialized) {
if (initverbose)
log_message_class("Initialize class (from builtin_new): ", c);
- if (!class_init(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);
+ MSET(o, 0, u1, c->instancesize);
o->vftbl = c->vftbl;
+
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
initObjectLock(o);
#endif
}
-/********************** Function: builtin_newarray **************************
+/* builtin_newarray ************************************************************
- Creates an array with the given vftbl on the heap.
+ Creates an array with the given vftbl 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
- CAUTION: The given vftbl must be the vftbl of the *array* class,
- not of the element class.
+ 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)
{
componentsize = desc->componentsize;
if (size < 0) {
- *exceptionptr =
- new_exception(string_java_lang_NegativeArraySizeException);
+ *exceptionptr = new_negativearraysizeexception();
return NULL;
}
-#ifdef SIZE_FROM_CLASSINFO
- actualsize = align_size(dataoffset + size * componentsize);
actualsize = dataoffset + size * componentsize;
-#else
- actualsize = 0;
-#endif
if (((u4) actualsize) < ((u4) size)) { /* overflow */
*exceptionptr = new_exception(string_java_lang_OutOfMemoryError);
return NULL;
}
- a = heap_allocate(actualsize,
- (desc->arraytype == ARRAYTYPE_OBJECT),
- NULL);
+ a = heap_allocate(actualsize, (desc->arraytype == ARRAYTYPE_OBJECT), NULL);
if (!a)
return NULL;
- memset(a, 0, actualsize);
+ MSET(a, 0, u1, actualsize);
a->objheader.vftbl = arrayvftbl;
+
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
initObjectLock(&a->objheader);
#endif
+
a->size = size;
-#ifdef SIZE_FROM_CLASSINFO
- a->alignedsize = actualsize;
-#endif
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)
{
+ classinfo *c;
+
/* is class loaded */
- if (!component->loaded)
- if (!class_load(component))
- return NULL;
+ assert(component->loaded);
/* is class linked */
if (!component->linked)
- if (!class_link(component))
+ if (!link_class(component))
return NULL;
- return (java_objectarray *) builtin_newarray(size, class_array_of(component)->vftbl);
+ c = class_array_of(component, true);
+
+ if (!c)
+ return NULL;
+
+ return (java_objectarray *) builtin_newarray(size, c->vftbl);
}
-/******************** Function: builtin_newarray_int ***********************
+/* builtin_newarray_int ********************************************************
- Creates an array of 32 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_intarray *builtin_newarray_int(s4 size)
{
- return (java_intarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_INT].arrayvftbl);
+ return (java_intarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_INT].arrayvftbl);
}
-/******************** Function: builtin_newarray_long ***********************
+/* builtin_newarray_long *******************************************************
- Creates an array of 64 bit Integers 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_longarray *builtin_newarray_long(s4 size)
{
- return (java_longarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_LONG].arrayvftbl);
+ return (java_longarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_LONG].arrayvftbl);
}
-/******************** function: builtin_newarray_float ***********************
+/* builtin_newarray_float ******************************************************
- Creates an array of 32 bit IEEE floats 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_floatarray *builtin_newarray_float(s4 size)
{
- return (java_floatarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_FLOAT].arrayvftbl);
+ return (java_floatarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_FLOAT].arrayvftbl);
}
-/******************** function: builtin_newarray_double ***********************
+/* builtin_newarray_double *****************************************************
- Creates an array of 64 bit IEEE floats on the heap.
+ Creates an array of 64 bit IEEE floats on the heap.
- Return value: pointer to the array or NULL if no memory is available
+ Return value: pointer to the array or NULL if no memory is
+ available
-*****************************************************************************/
+*******************************************************************************/
java_doublearray *builtin_newarray_double(s4 size)
{
- return (java_doublearray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_DOUBLE].arrayvftbl);
+ return (java_doublearray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_DOUBLE].arrayvftbl);
}
-/******************** function: builtin_newarray_byte ***********************
+/* builtin_newarray_byte *******************************************************
- Creates an array of 8 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_bytearray *builtin_newarray_byte(s4 size)
{
- return (java_bytearray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_BYTE].arrayvftbl);
+ return (java_bytearray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_BYTE].arrayvftbl);
}
-/******************** function: builtin_newarray_char ************************
+/* builtin_newarray_char *******************************************************
- Creates an array of characters 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_chararray *builtin_newarray_char(s4 size)
{
- return (java_chararray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl);
+ return (java_chararray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_CHAR].arrayvftbl);
}
-/******************** function: builtin_newarray_short ***********************
+/* builtin_newarray_short ******************************************************
- Creates an array of 16 bit Integers on the heap.
+ Creates an array of 16 bit Integers on the heap.
- Return value: pointer to the array or NULL if no memory is available
+ Return value: pointer to the array or NULL if no memory is
+ available
-*****************************************************************************/
+*******************************************************************************/
java_shortarray *builtin_newarray_short(s4 size)
{
- return (java_shortarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_SHORT].arrayvftbl);
+ return (java_shortarray *)
+ builtin_newarray(size, primitivetype_table[ARRAYTYPE_SHORT].arrayvftbl);
}
-/******************** function: builtin_newarray_boolean ************************
+/* builtin_newarray_boolean ****************************************************
- Creates an array of bytes on the heap. The array is designated as an array
- of booleans (important for casts)
+ 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
+ Return value: pointer to the array or NULL if no memory is
+ available
-*****************************************************************************/
+*******************************************************************************/
java_booleanarray *builtin_newarray_boolean(s4 size)
{
- return (java_booleanarray*) builtin_newarray(size, primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
+ return (java_booleanarray *)
+ builtin_newarray(size,
+ primitivetype_table[ARRAYTYPE_BOOLEAN].arrayvftbl);
}
-/**************** function: builtin_nmultianewarray ***************************
+/* builtin_multianewarray ******************************************************
- 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
******************************************************************************/
-java_arrayheader *builtin_nmultianewarray(int n, vftbl_t *arrayvftbl, long *dims)
-/* java_arrayheader *builtin_nmultianewarray(int n, classinfo *arrayclass, long *dims) */
+java_arrayheader *builtin_multianewarray(int n, vftbl_t *arrayvftbl, long *dims)
{
s4 size, i;
java_arrayheader *a;
vftbl_t *componentvftbl;
-/* utf_display(arrayclass->name); */
-
-/* class_load(arrayclass); */
-/* class_link(arrayclass); */
-
/* create this dimension */
+
size = (s4) dims[0];
a = builtin_newarray(size, arrayvftbl);
-/* a = builtin_newarray(size, arrayclass->vftbl); */
if (!a)
return NULL;
/* if this is the last dimension return */
+
if (!--n)
return a;
/* get the vftbl of the components to create */
+
componentvftbl = arrayvftbl->arraydesc->componentvftbl;
-/* component = arrayclass->vftbl->arraydesc; */
/* The verifier guarantees this. */
/* if (!componentvftbl) */
/* panic ("multianewarray with too many dimensions"); */
/* create the component arrays */
+
for (i = 0; i < size; i++) {
java_arrayheader *ea =
- builtin_nmultianewarray(n, componentvftbl, dims + 1);
+ builtin_multianewarray(n, componentvftbl, dims + 1);
if (!ea)
return NULL;
s4 line,
s4 noindent)
{
+ char logtext[MAXLOGTEXT];
+
if (!noindent) {
if (methodindent)
methodindent--;
}
if (opt_verbose || runverbose || verboseexception) {
if (xptr) {
- printf("Exception ");
- utf_display_classname(xptr->vftbl->class->name);
+ sprintf(logtext,"Exception ");
+ utf_sprint_classname(logtext+strlen(logtext), xptr->vftbl->class->name);
} else {
- printf("Some Throwable");
+ sprintf(logtext,"Some Throwable");
}
- printf(" thrown in ");
+ sprintf(logtext+strlen(logtext), " thrown in ");
if (m) {
- utf_display_classname(m->class->name);
- printf(".");
- utf_display(m->name);
+ utf_sprint_classname(logtext+strlen(logtext), m->class->name);
+ sprintf(logtext+strlen(logtext), ".");
+ utf_sprint(logtext+strlen(logtext), m->name);
if (m->flags & ACC_SYNCHRONIZED) {
- printf("(SYNC");
+ sprintf(logtext+strlen(logtext), "(SYNC");
} else{
- printf("(NOSYNC");
+ sprintf(logtext+strlen(logtext), "(NOSYNC");
}
if (m->flags & ACC_NATIVE) {
- printf(",NATIVE");
+ sprintf(logtext+strlen(logtext), ",NATIVE");
#if POINTERSIZE == 8
- printf(")(0x%016lx) at position 0x%016lx\n", (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext+strlen(logtext), ")(0x%016lx) at position 0x%016lx\n", (ptrint) m->entrypoint, (ptrint) pos);
#else
- printf(")(0x%08x) at position 0x%08x\n", (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext+strlen(logtext), ")(0x%08x) at position 0x%08x\n", (ptrint) m->entrypoint, (ptrint) pos);
#endif
} else {
#if POINTERSIZE == 8
- printf(")(0x%016lx) at position 0x%016lx (", (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext+strlen(logtext), ")(0x%016lx) at position 0x%016lx (", (ptrint) m->entrypoint, (ptrint) pos);
#else
- printf(")(0x%08x) at position 0x%08x (", (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext+strlen(logtext), ")(0x%08x) at position 0x%08x (", (ptrint) m->entrypoint, (ptrint) pos);
#endif
if (m->class->sourcefile == NULL) {
- printf("<NO CLASSFILE INFORMATION>");
+ sprintf(logtext+strlen(logtext), "<NO CLASSFILE INFORMATION>");
} else {
- utf_display(m->class->sourcefile);
+ utf_sprint(logtext+strlen(logtext), m->class->sourcefile);
}
- printf(":%d)\n", line);
+ sprintf(logtext+strlen(logtext), ":%d)\n", line);
}
} else
- printf("call_java_method\n");
- fflush(stdout);
+ sprintf(logtext+strlen(logtext), "call_java_method\n");
+
+ log_text(logtext);
}
return xptr;
char logtext[MAXLOGTEXT];
for (i = 0; i < methodindent; i++)
logtext[i] = '\t';
+ if (methodindent == 0)
+ sprintf(logtext + methodindent, "1st_call: ");
+ else
+ sprintf(logtext + methodindent, "called: ");
- sprintf(logtext + methodindent, "called: ");
utf_sprint_classname(logtext + strlen(logtext), m->class->name);
sprintf(logtext + strlen(logtext), ".");
utf_sprint(logtext + strlen(logtext), m->name);
- utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
+ utf_sprint(logtext + strlen(logtext), m->descriptor);
if (m->flags & ACC_PUBLIC) sprintf(logtext + strlen(logtext), " PUBLIC");
if (m->flags & ACC_PRIVATE) sprintf(logtext + strlen(logtext), " PRIVATE");
utf_sprint_classname(logtext + strlen(logtext), m->class->name);
sprintf(logtext + strlen(logtext), ".");
utf_sprint(logtext + strlen(logtext), m->name);
- utf_sprint_classname(logtext + strlen(logtext), m->descriptor);
+ utf_sprint(logtext + strlen(logtext), m->descriptor);
switch (m->returntype) {
case TYPE_INT:
#if defined(USE_THREADS)
-void *builtin_monitorexit(java_objectheader *o)
+void builtin_monitorexit(java_objectheader *o)
{
#if !defined(NATIVE_THREADS)
int hashValue;
internal_unlock_mutex_for_object(o);
--blockInts;
- return o;
#else
monitorExit((threadobject *) THREADOBJECT, o);
- return o;
#endif
}
#endif
{
/*log_text("builtin_asm_get_stackframeinfo()");*/
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ /*printf("stackframeinfo: %p,%p\n",&THREADINFO->_stackframeinfo,*(&THREADINFO->_stackframeinfo));*/
return &THREADINFO->_stackframeinfo;
#else
#if defined(__GNUC__)