calls instead of machine instructions, using the C calling
convention.
- $Id: builtin.c 2382 2005-04-26 16:11:10Z twisti $
+ $Id: builtin.c 3134 2005-08-23 14:45:29Z cacao $
*/
#include <assert.h>
-#include <math.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "arch.h"
+#include "md-abi.h"
#include "types.h"
+
+#include "classpath/native/fdlibm/fdlibm.h"
+
#include "mm/boehm.h"
#include "mm/memory.h"
#include "native/native.h"
#include "native/include/java_lang_Cloneable.h"
+#include "native/include/java_lang_Object.h" /* required by VMObject */
#include "native/include/java_lang_VMObject.h"
#if defined(USE_THREADS)
#endif
#include "toolbox/logging.h"
+#include "toolbox/util.h"
#include "vm/builtin.h"
#include "vm/exceptions.h"
#include "vm/global.h"
THREADSPECIFIC void *_thread_nativestackframeinfo = NULL;
-#if defined(USEBUILTINTABLE)
+/* include builtin tables *****************************************************/
-#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 },
-};
+#include "vm/builtintable.inc"
-#endif
-static int builtintablelen;
+/* builtintable_init ***********************************************************
-#endif /* USEBUILTINTABLE */
+ Parse the descriptors of builtin functions and create the parsed
+ descriptors.
+*******************************************************************************/
-/*****************************************************************************
- TABLE OF BUILTIN FUNCTIONS
+static bool builtintable_init(void)
+{
+ descriptor_pool *descpool;
+ s4 dumpsize;
+ utf *descriptor;
+ s4 entries_internal;
+ s4 entries_automatic;
+ s4 i;
- This table lists the builtin functions which are used inside
- BUILTIN* opcodes.
+ /* mark start of dump memory area */
- The first part of the table (up to the 255-marker) lists the
- opcodes which are automatically replaced in stack.c.
+ dumpsize = dump_size();
- The second part lists the builtin functions which are "manually"
- used for BUILTIN* opcodes in parse.c and stack.c.
+ /* create a new descriptor pool */
-*****************************************************************************/
+ descpool = descriptor_pool_new(class_java_lang_Object);
-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
+ /* add some entries we need */
- /* this record marks the end of the automatically replaced opcodes */
- {255,NULL,0,0,0,0,0,0,0,"<INVALID>"},
+ if (!descriptor_pool_add_class(descpool, utf_java_lang_Object))
+ return false;
- /* 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
+ if (!descriptor_pool_add_class(descpool, utf_java_lang_Class))
+ return false;
- {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"},
+ /* calculate table entries statically */
+ entries_internal =
+ sizeof(builtintable_internal) / sizeof(builtintable_entry);
-#if defined(__X86_64__) || defined(__I386__) || defined(__ALPHA__)
- /* assembler code patching functions */
+ entries_automatic =
+ sizeof(builtintable_automatic) / sizeof(builtintable_entry)
+ - 1; /* last filler entry (comment see builtintable.inc) */
- { 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
+ /* 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 */
- /* this record marks the end of the list */
+ descriptor = utf_new_char(builtintable_automatic[i].descriptor);
- { 0, NULL, 0, 0, 0, 0, 0, 0, 0, "<END>" }
-};
+ /* 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;
+}
-#if defined(USEBUILTINTABLE)
+/* builtintable_comparator *****************************************************
-static int stdopcompare(const void *a, const void *b)
+ qsort comparator for the automatic builtin table.
+
+*******************************************************************************/
+
+static int builtintable_comparator(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);
+ 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;
}
-void sort_builtintable(void)
+/* 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)
{
- int len;
+ s4 i;
- len = 0;
- while (builtin_desc[len].opcode != 255) len++;
- qsort(builtin_desc, len, sizeof(builtin_descriptor), stdopcompare);
+ for (i = 0; builtintable_internal[i].fp != NULL; i++) {
+ if (builtintable_internal[i].fp == fp)
+ return &builtintable_internal[i];
+ }
- for (--len; len>=0 && builtin_desc[len].supported; len--);
- builtintablelen = ++len;
+ return NULL;
}
-builtin_descriptor *find_builtin(int icmd)
+/* 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)
{
- builtin_descriptor *first = builtin_desc;
- builtin_descriptor *last = builtin_desc + builtintablelen;
- int len = last - first;
- int half;
- builtin_descriptor *middle;
+ 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;
- while (len > 0) {
- half = len / 2;
+ first = builtintable_automatic;
+ last = builtintable_automatic + entries;
+
+ while (entries > 0) {
+ half = entries / 2;
middle = first + half;
- if (middle->opcode < icmd) {
+
+ if (middle->opcode < opcode) {
first = middle + 1;
- len -= half + 1;
+ entries -= half + 1;
} else
- len = half;
+ entries = half;
}
- return first != last ? first : NULL;
-}
-#endif /* defined(USEBUILTINTABLE) */
+ return (first != last ? first : NULL);
+}
/*****************************************************************************
}
-/* 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
*******************************************************************************/
-s4 builtin_checkarraycast(java_objectheader *o, vftbl_t *target)
+s4 builtin_arraycheckcast(java_objectheader *o, vftbl_t *target)
{
arraydescriptor *desc;
s4 builtin_arrayinstanceof(java_objectheader *obj, vftbl_t *target)
{
- if (!obj) return 1;
- return builtin_checkarraycast(obj, target);
+ if (!obj)
+ return 1;
+
+ return builtin_arraycheckcast(obj, target);
}
java_objectheader *builtin_throw_exception(java_objectheader *xptr)
{
+ java_lang_Throwable *t;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+
if (opt_verbose) {
- char logtext[MAXLOGTEXT];
- sprintf(logtext, "Builtin exception thrown: ");
+ t = (java_lang_Throwable *) xptr;
- if (xptr) {
- java_lang_Throwable *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);
char *buf;
buf = javastring_tochar((java_objectheader *) t->detailMessage);
- sprintf(logtext + strlen(logtext), ": %s", buf);
+ strcat(logtext, ": ");
+ strcat(logtext, buf);
MFREE(buf, char, strlen(buf));
}
} else {
- sprintf(logtext + strlen(logtext), "Error: <Nullpointer instead of exception>");
+ strcat(logtext, "(nil)");
}
log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
}
*exceptionptr = xptr;
-/******************* function: builtin_canstore *******************************
+/* builtin_canstore ************************************************************
- Checks, if an object can be stored in an array.
- Return value: 1 ... possible
- 0 ... otherwise
+ Checks, if an object can be stored in an array.
-******************************************************************************/
+ Return value: 1 ... possible
+ 0 ... otherwise
-s4 builtin_canstore (java_objectarray *a, java_objectheader *o)
+*******************************************************************************/
+
+s4 builtin_canstore(java_objectarray *a, java_objectheader *o)
{
arraydescriptor *desc;
arraydescriptor *valuedesc;
vftbl_t *componentvftbl;
vftbl_t *valuevftbl;
- int dim_m1;
int base;
castinfo classvalues;
- if (!o) return 1;
+ if (!o)
+ return 1;
/* The following is guaranteed (by verifier checks):
*
*/
desc = a->header.objheader.vftbl->arraydesc;
- componentvftbl = desc->componentvftbl;
+ componentvftbl = desc->componentvftbl;
valuevftbl = o->vftbl;
- if ((dim_m1 = desc->dimension - 1) == 0) {
+ if ((desc->dimension - 1) == 0) {
s4 res;
/* {a is a one-dimensional array} */
<= (unsigned) classvalues.super_diffval;
return res;
- }
- /* {a has dimension > 1} */
+ }
+
+ /* {a has dimension > 1} */
/* {componentvftbl->arraydesc != NULL} */
/* check if o is an array */
java_objectheader *o;
/* is the class loaded */
- /*utf_fprint(stderr,c->name);fprintf(stderr,"\n");*/
+
assert(c->loaded);
/* is the class linked */
componentvftbl = arrayvftbl->arraydesc->componentvftbl;
- /* The verifier guarantees this. */
- /* if (!componentvftbl) */
- /* panic ("multianewarray with too many dimensions"); */
+ /* The verifier guarantees that the dimension count is in the range. */
/* create the component arrays */
for (i = 0; i < size; i++) {
- java_arrayheader *ea =
+ java_arrayheader *ea =
+#if defined(__MIPS__) && (SIZEOF_VOID_P == 4)
+ /* we save an s4 to a s8 slot, 8-byte aligned */
+
+ builtin_multianewarray(n, componentvftbl, dims + 2);
+#else
builtin_multianewarray(n, componentvftbl, dims + 1);
+#endif
if (!ea)
return NULL;
s4 line,
s4 noindent)
{
- char logtext[MAXLOGTEXT];
-
- if (!noindent) {
- if (methodindent)
- methodindent--;
- else
- log_text("WARNING: unmatched methodindent--");
- }
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+
if (opt_verbose || runverbose || verboseexception) {
+ /* 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) {
- sprintf(logtext,"Exception ");
- utf_sprint_classname(logtext+strlen(logtext), xptr->vftbl->class->name);
+ strcpy(logtext, "Exception ");
+ utf_strcat_classname(logtext, xptr->vftbl->class->name);
} else {
- sprintf(logtext,"Some Throwable");
+ strcpy(logtext, "Some Throwable");
}
- sprintf(logtext+strlen(logtext), " thrown in ");
+
+ strcat(logtext, " thrown in ");
if (m) {
- 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) {
- sprintf(logtext+strlen(logtext), "(SYNC");
-
- } else{
- sprintf(logtext+strlen(logtext), "(NOSYNC");
- }
+ 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) {
- sprintf(logtext+strlen(logtext), ",NATIVE");
-#if POINTERSIZE == 8
- sprintf(logtext+strlen(logtext), ")(0x%016lx) at position 0x%016lx\n", (ptrint) m->entrypoint, (ptrint) pos);
+ 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\n", (ptrint) m->entrypoint, (ptrint) pos);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x",
+ (ptrint) m->entrypoint, (ptrint) pos);
#endif
} else {
-#if POINTERSIZE == 8
- sprintf(logtext+strlen(logtext), ")(0x%016lx) at position 0x%016lx (", (ptrint) m->entrypoint, (ptrint) pos);
+#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);
+ sprintf(logtext + strlen(logtext),
+ ")(0x%08x) at position 0x%08x (",
+ (ptrint) m->entrypoint, (ptrint) pos);
#endif
- if (m->class->sourcefile == NULL) {
- sprintf(logtext+strlen(logtext), "<NO CLASSFILE INFORMATION>");
- } else {
- utf_sprint(logtext+strlen(logtext), m->class->sourcefile);
- }
- sprintf(logtext+strlen(logtext), ":%d)\n", line);
+ if (m->class->sourcefile == NULL)
+ strcat(logtext, "<NO CLASSFILE INFORMATION>");
+ else
+ utf_strcat(logtext, m->class->sourcefile);
+
+ sprintf(logtext + strlen(logtext), ":%d)", line);
}
} else
- sprintf(logtext+strlen(logtext), "call_java_method\n");
+ strcat(logtext, "call_java_method");
log_text(logtext);
+
+ /* release memory */
+
+ dump_release(dumpsize);
}
return xptr;
}
+/* builtin_trace_args **********************************************************
+
+ XXX
+
+*******************************************************************************/
+
#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)
{
- s4 i;
- char logtext[MAXLOGTEXT];
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+
+ md = m->parseddesc;
+
+ /* calculate message length */
+
+ logtextlen =
+ 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);
+
for (i = 0; i < methodindent; i++)
logtext[i] = '\t';
- if (methodindent == 0)
- sprintf(logtext + methodindent, "1st_call: ");
- else
- 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(logtext + strlen(logtext), m->descriptor);
-
- if (m->flags & ACC_PUBLIC) sprintf(logtext + strlen(logtext), " PUBLIC");
- if (m->flags & ACC_PRIVATE) sprintf(logtext + strlen(logtext), " PRIVATE");
- if (m->flags & ACC_PROTECTED) sprintf(logtext + strlen(logtext), " PROTECTED");
- if (m->flags & ACC_STATIC) sprintf(logtext + strlen(logtext), " STATIC");
- if (m->flags & ACC_FINAL) sprintf(logtext + strlen(logtext), " FINAL");
- if (m->flags & ACC_SYNCHRONIZED) sprintf(logtext + strlen(logtext), " SYNCHRONIZED");
- if (m->flags & ACC_VOLATILE) sprintf(logtext + strlen(logtext), " VOLATILE");
- if (m->flags & ACC_TRANSIENT) sprintf(logtext + strlen(logtext), " TRANSIENT");
- if (m->flags & ACC_NATIVE) sprintf(logtext + strlen(logtext), " NATIVE");
- if (m->flags & ACC_INTERFACE) sprintf(logtext + strlen(logtext), " INTERFACE");
- if (m->flags & ACC_ABSTRACT) sprintf(logtext + strlen(logtext), " ABSTRACT");
-
-
- sprintf(logtext + strlen(logtext), "(");
- switch (m->paramcount) {
+ strcpy(logtext + methodindent, "called: ");
+
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
+
+ if (m->flags & ACC_PUBLIC) strcat(logtext, " PUBLIC");
+ if (m->flags & ACC_PRIVATE) strcat(logtext, " PRIVATE");
+ if (m->flags & ACC_PROTECTED) strcat(logtext, " PROTECTED");
+ if (m->flags & ACC_STATIC) strcat(logtext, " STATIC");
+ if (m->flags & ACC_FINAL) strcat(logtext, " FINAL");
+ if (m->flags & ACC_SYNCHRONIZED) strcat(logtext, " SYNCHRONIZED");
+ if (m->flags & ACC_VOLATILE) strcat(logtext, " VOLATILE");
+ if (m->flags & ACC_TRANSIENT) strcat(logtext, " TRANSIENT");
+ if (m->flags & ACC_NATIVE) strcat(logtext, " NATIVE");
+ if (m->flags & ACC_INTERFACE) strcat(logtext, " INTERFACE");
+ if (m->flags & ACC_ABSTRACT) strcat(logtext, " ABSTRACT");
+
+ strcat(logtext, "(");
+
+ /* xxxprintf ?Bug? an PowerPc Linux (rlwinm.inso) */
+ /* Only Arguments in integer Registers are passed correctly here */
+ /* long longs spilled on Stack have an wrong offset of +4 */
+ /* So preliminary Bugfix: Only pass 3 params at once to sprintf */
+ /* for SIZEOG_VOID_P == 4 && TRACE_ARGS_NUM == 8 */
+ switch (md->paramcount) {
case 0:
break;
-#if defined(__I386__) || defined(__POWERPC__)
+#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 == 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, m->paramcount - 8);
- break;
-#else /* TRACE_ARGS_NUM == 8 */
- default:
- sprintf(logtext+strlen(logtext), "%llx, %llx, %llx, %llx, %llx, %llx, ...(%d)",
- a0, a1, a2, a3, a4, a5, m->paramcount - 6);
+#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
break;
-#endif /* TRACE_ARGS_NUM == 8 */
-#else /* defined(__I386__) || defined(__POWERPC__) */
+
+#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 == 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:
#if TRACE_ARGS_NUM == 4
- sprintf(logtext+strlen(logtext), "%lx, %lx, %lx, %lx, ...(%d)",
- a0, a1, a2, a3, m->paramcount - 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), "%lx, %lx, %lx, %lx, %lx, %lx, ...(%d)",
- a0, a1, a2, a3, a4, a5, m->paramcount - 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), "%lx, %lx, %lx, %lx, %lx, %lx, %lx, %lx, ...(%d)",
- a0, a1, a2, a3, a4, a5, a6, a7, m->paramcount - 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 /* defined(__I386__) || defined(__POWERPC__) */
+#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 *m)
-{
- char logtext[MAXLOGTEXT];
- sprintf(logtext, " ");
- sprintf(logtext + methodindent, "called: ");
- utf_sprint(logtext + strlen(logtext), m->class->name);
- sprintf(logtext + strlen(logtext), ".");
- utf_sprint(logtext + strlen(logtext), m->name);
- utf_sprint(logtext + strlen(logtext), m->descriptor);
-
- if (m->flags & ACC_PUBLIC) sprintf(logtext + strlen(logtext), " PUBLIC");
- if (m->flags & ACC_PRIVATE) sprintf(logtext + strlen(logtext), " PRIVATE");
- if (m->flags & ACC_PROTECTED) sprintf(logtext + strlen(logtext), " PROTECTED");
- if (m->flags & ACC_STATIC) sprintf(logtext + strlen(logtext), " STATIC");
- if (m->flags & ACC_FINAL) sprintf(logtext + strlen(logtext), " FINAL");
- if (m->flags & ACC_SYNCHRONIZED) sprintf(logtext + strlen(logtext), " SYNCHRONIZED");
- if (m->flags & ACC_VOLATILE) sprintf(logtext + strlen(logtext), " VOLATILE");
- if (m->flags & ACC_TRANSIENT) sprintf(logtext + strlen(logtext), " TRANSIENT");
- if (m->flags & ACC_NATIVE) sprintf(logtext + strlen(logtext), " NATIVE");
- if (m->flags & ACC_INTERFACE) sprintf(logtext + strlen(logtext), " INTERFACE");
- if (m->flags & ACC_ABSTRACT) sprintf(logtext + strlen(logtext), " ABSTRACT");
+/* builtin_displaymethodstop ***************************************************
- log_text(logtext);
- methodindent++;
-}
+ XXX
+*******************************************************************************/
void builtin_displaymethodstop(methodinfo *m, s8 l, double d, float f)
{
- int i;
- char logtext[MAXLOGTEXT];
+ methoddesc *md;
+ char *logtext;
+ s4 logtextlen;
+ s4 dumpsize;
+ s4 i;
+ imm_union imu;
+
+ md = m->parseddesc;
+
+ /* calculate message length */
+
+ logtextlen =
+ methodindent + strlen("finished: ") +
+ utf_strlen(m->class->name) +
+ strlen(".") +
+ utf_strlen(m->name) +
+ utf_strlen(m->descriptor) +
+ strlen(" SYNCHRONIZED") + strlen("(") + strlen(")");
+
+ /* add maximal argument length */
+
+ logtextlen += strlen("->0.4872328470301428 (0x0123456789abcdef)");
+
+ /* allocate memory */
+
+ dumpsize = dump_size();
+
+ logtext = DMNEW(char, logtextlen);
+
+ /* generate the message */
+
for (i = 0; i < methodindent; i++)
logtext[i] = '\t';
+
if (methodindent)
methodindent--;
else
log_text("WARNING: unmatched methodindent--");
- sprintf(logtext + methodindent, "finished: ");
- utf_sprint_classname(logtext + strlen(logtext), m->class->name);
- sprintf(logtext + strlen(logtext), ".");
- utf_sprint(logtext + strlen(logtext), m->name);
- utf_sprint(logtext + strlen(logtext), m->descriptor);
+ strcpy(logtext + methodindent, "finished: ");
+ utf_strcat_classname(logtext, m->class->name);
+ strcat(logtext, ".");
+ utf_strcat(logtext, m->name);
+ utf_strcat(logtext, m->descriptor);
- switch (m->returntype) {
+ 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__) || defined(__POWERPC__)
- 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__) || defined(__POWERPC__)
- 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 */
+
+ dump_release(dumpsize);
}
******************************************************************************/
-
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)
}
+/* 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;
- return builtin_d2l((double) a);
+ l = builtin_d2l((double) a);
+
+ return l;
/* float f;
}
+/* builtin_clone_array *********************************************************
+
+ 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_Object *) o;
-s4 builtin_dummy()
-{
- panic("Internal error: builtin_dummy called (native function is missing)");
- return 0; /* for the compiler */
+ ah = (java_arrayheader *) Java_java_lang_VMObject_clone(0, 0, c);
+
+ return ah;
}
*******************************************************************************/
#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-java_objectheader **builtin_asm_get_exceptionptrptr()
+java_objectheader **builtin_asm_get_exceptionptrptr(void)
{
return builtin_get_exceptionptrptr();
}
#endif
-methodinfo *builtin_asm_get_threadrootmethod()
+methodinfo *builtin_asm_get_threadrootmethod(void)
{
return *threadrootmethod;
}
-inline void* builtin_asm_get_stackframeinfo()
+void *builtin_asm_get_stackframeinfo(void)
{
-/*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__)
-#warning FIXME FOR OLD THREAD IMPL (jowenn)
-#endif
- return &_thread_nativestackframeinfo; /* no threading, at least no native*/
+ /* 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 *builtin_stacktrace_copy(stacktraceelement **el,
+ stacktraceelement *begin,
+ stacktraceelement *end)
+{
/* stacktraceelement *el;*/
size_t s;
s=(end-begin);
#endif
memcpy(*el,begin,(end-begin)*sizeof(stacktraceelement));
(*el)[s].method=0;
-#if defined(__GNUC__)
-#warning change this if line numbers bigger than u2 are allowed, the currently supported class file format does no allow that
-#endif
+
+ /* 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