X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=global.h;h=7e079e9e365a017fb840dda44feb917dd3af1405;hb=31f21488d35e775095190f8698b93a21bac1fc13;hp=efc7eda7282514a6eea7113c9bce81421f02b745;hpb=aa8717b7b437db5b5e6ef3711ef70ec4a14aab06;p=cacao.git diff --git a/global.h b/global.h index efc7eda72..7e079e9e3 100644 --- a/global.h +++ b/global.h @@ -31,7 +31,7 @@ Philipp Tomsich Edwin Steiner - $Id: global.h 717 2003-12-07 22:02:19Z twisti $ + $Id: global.h 1326 2004-07-21 13:22:33Z twisti $ */ @@ -39,12 +39,15 @@ #ifndef _GLOBAL_H #define _GLOBAL_H + #include "config.h" #include "types.h" #include "toolbox/list.h" -#define _GNU_SOURCE +#if defined(USE_THREADS) && defined(NATIVE_THREADS) +#include +#endif #define STATISTICS /* if enabled collects program statistics */ @@ -59,9 +62,17 @@ */ #define CACAO_TYPECHECK +/* + * TYPECHECK_STACK_COMPCAT activates full checking of computational + * categories for stack manipulations (POP,POP2,SWAP,DUP,DUP2,DUP_X1, + * DUP2_X1,DUP_X2,DUP2_X2). + */ +#define TYPECHECK_STACK_COMPCAT + /* * Macros for configuration of the typechecking code * + * TYPECHECK_STATISTICS activates gathering statistical information. * TYPEINFO_DEBUG activates debug checks and debug helpers in typeinfo.c * TYPECHECK_DEBUG activates debug checks in typecheck.c * TYPEINFO_DEBUG_TEST activates the typeinfo test at startup. @@ -69,10 +80,11 @@ * TYPECHECK_VERBOSE activates all debug messages */ #ifdef CACAO_TYPECHECK -#define TYPEINFO_DEBUG -#define TYPECHECK_DEBUG +/*#define TYPECHECK_STATISTICS*/ +/*#define TYPEINFO_DEBUG*/ +/*#define TYPECHECK_DEBUG*/ /*#define TYPEINFO_DEBUG_TEST*/ -#define TYPECHECK_VERBOSE +/*#define TYPECHECK_VERBOSE*/ /*#define TYPECHECK_VERBOSE_IMPORTANT*/ #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT) #define TYPECHECK_VERBOSE_OPT @@ -89,6 +101,8 @@ typedef int bool; /* boolean data type */ #define true 1 #define false 0 +typedef void (*functionptr) (); /* generic function pointer */ + /* immediate data union */ @@ -117,18 +131,13 @@ typedef union { #define PRIMITIVETYPE_BOOLEAN 7 #define PRIMITIVETYPE_VOID 8 -typedef void (*functionptr) (); /* generic function pointer */ - #define MAX_ALIGN 8 /* most generic alignment for JavaVM values */ -/* shutdown function **********************************************************/ - -void cacao_shutdown(s4 status); - /* basic data types ***********************************************************/ +/* CAUTION: jit/jit.h relies on these numerical values! */ #define TYPE_INT 0 /* the JavaVM types must numbered in the */ #define TYPE_LONG 1 /* same order as the ICMD_Ixxx to ICMD_Axxx */ #define TYPE_FLOAT 2 /* instructions (LOAD and STORE) */ @@ -141,8 +150,8 @@ void cacao_shutdown(s4 status); /* Java class file constants **************************************************/ #define MAGIC 0xcafebabe -#define MINOR_VERSION 3 -#define MAJOR_VERSION 45 +#define MINOR_VERSION 0 +#define MAJOR_VERSION 48 #define CONSTANT_Class 7 #define CONSTANT_Fieldref 9 @@ -163,6 +172,7 @@ void cacao_shutdown(s4 status); #define ACC_PROTECTED 0x0004 #define ACC_STATIC 0x0008 #define ACC_FINAL 0x0010 +#define ACC_SUPER 0x0020 #define ACC_SYNCHRONIZED 0x0020 #define ACC_VOLATILE 0x0040 #define ACC_TRANSIENT 0x0080 @@ -177,10 +187,12 @@ typedef struct utf utf; typedef struct literalstring literalstring; typedef struct java_objectheader java_objectheader; typedef struct classinfo classinfo; -typedef struct vftbl vftbl; +typedef struct _vftbl vftbl_t; typedef u1* methodptr; typedef struct fieldinfo fieldinfo; +typedef struct exceptiontable exceptiontable; typedef struct methodinfo methodinfo; +typedef struct lineinfo lineinfo; typedef struct arraydescriptor arraydescriptor; @@ -275,10 +287,39 @@ struct literalstring { }; +/* data structure for storing information needed for a stacktrace across native functions*/ +struct native_stackframeinfo { + void *oldThreadspecificHeadValue; + void **addressOfThreadspecificHead; + methodinfo *method; + void *returnToFromNative; + +#if 0 + void *returnFromNative; + void *addrReturnFromNative; + methodinfo *method; + struct native_stackframeinfo *next; + struct native_stackframeinfo *prev; +#endif +}; + +typedef struct native_stackframeinfo native_stackframeinfo; + +struct stacktraceelement { +#if POINTERSIZE == 8 + u8 linenumber; +#else + u4 linenumber; +#endif + methodinfo *method; +}; + +typedef struct stacktraceelement stacktraceelement; + /* data structure for calls from c code to java methods */ struct jni_callblock { - u1 itemtype; + u8 itemtype; u8 item; }; @@ -338,7 +379,10 @@ typedef struct { /* NameAndType (Field or Method) */ */ struct java_objectheader { /* header for all objects */ - vftbl *vftbl; /* pointer to virtual function table */ + vftbl_t *vftbl; /* pointer to virtual function table */ +#if defined(USE_THREADS) && defined(NATIVE_THREADS) + long monitorBits; +#endif }; @@ -439,13 +483,13 @@ typedef struct primitivetypeinfo { char *name; /* name of primitive class */ char *arrayname; /* name of primitive array class */ classinfo *arrayclass; /* primitive array class */ - vftbl *arrayvftbl; /* vftbl of primitive array class */ + vftbl_t *arrayvftbl; /* vftbl of primitive array class */ } primitivetypeinfo; /* field, method and class structures *****************************************/ -#include "sets.h" +#include "jit/sets.h" typedef struct xtafldinfo { bool fieldChecked; classinfo *fldClassType; @@ -464,16 +508,18 @@ struct fieldinfo { /* field of a class */ s4 offset; /* offset from start of object (instance variables) */ imm_union value; /* storage for static values (class variables) */ + + classinfo *class; /* needed by typechecker. Could be optimized */ + /* away by using constant_FMIref instead of */ + /* fieldinfo throughout the compiler. */ xtafldinfo *xta; }; -struct basicblock; - /* exceptiontable *************************************************************/ -typedef struct xtable { /* exceptiontable entry in a method */ +struct exceptiontable { /* exceptiontable entry in a method */ s4 startpc; /* start pc of guarded area (inclusive) */ struct basicblock *start; @@ -484,21 +530,14 @@ typedef struct xtable { /* exceptiontable entry in a method */ struct basicblock *handler; classinfo *catchtype; /* catchtype of exception (NULL == catchall) */ - struct xtable *next; /* used to build a list of exception when */ + exceptiontable *next; /* used to build a list of exception when */ /* loops are copied */ - struct xtable *down; /* instead of the old array, a list is used */ -} xtable; - - -typedef struct exceptiontable { /* exceptiontable entry in a method */ - s4 startpc; /* start pc of guarded area (inclusive) */ - s4 endpc; /* end pc of guarded area (exklusive) */ - s4 handlerpc; /* pc of exception handler */ - classinfo *catchtype; /* catchtype of exception (NULL == catchall) */ -} exceptiontable; + exceptiontable *down; /* instead of the old array, a list is used */ +}; /* methodinfo static info ****************************************************/ + typedef struct xtainfo { s4 XTAmethodUsed; /* XTA if used in callgraph - not used /used */ classSet *XTAclassSet; /* method class type set */ @@ -508,17 +547,26 @@ typedef struct xtainfo { methSet *calls; /* methods this method calls */ methSet *calledBy; /* methods that call this method */ - methSet *marked; /* methods that marked by this method */ - /*methSet *markedBy*/ + methSet *marked; //not in Dez /* methods that marked by this method */ + methSet *markedBy; fldSet *fldsUsed; /* fields used by this method */ /*methSetNode *interfaceCalls*/ /* methods this method calls as interface */ bool chgdSinceLastParse; /* Changed since last parse ? */ } xtainfo; +/* lineinfo *****************************************************************/ + +struct lineinfo { + u2 start_pc; + u2 line_number; +}; + + /* methodinfo *****************************************************************/ struct methodinfo { /* method structure */ + java_objectheader header; /* we need this in jit's monitorenter */ s4 flags; /* ACC flags */ utf *name; /* name of method */ utf *descriptor; /* JavaVM descriptor string of method */ @@ -527,7 +575,9 @@ struct methodinfo { /* method structure */ s4 paramcount; /* only temporary valid, parameter count */ u1 *paramtypes; /* only temporary valid, parameter types */ classinfo **paramclass; /* pointer to classinfo for a parameter */ /*XTA*/ - + + bool isleafmethod; /* does method call subroutines */ + classinfo *class; /* class, the method belongs to */ s4 vftblindex; /* index of method in virtual function table (if it is a virtual method) */ @@ -536,11 +586,33 @@ struct methodinfo { /* method structure */ s4 jcodelength; /* length of JavaVM code */ u1 *jcode; /* pointer to JavaVM code */ + s4 basicblockcount; /* number of basic blocks */ + struct basicblock *basicblocks; /* points to basic block array */ + s4 *basicblockindex; /* a table which contains for every byte */ + /* of JavaVM code a basic block index if */ + /* at this byte is the start of a basic */ + /* block */ + + s4 instructioncount; /* number of JavaVM instructions */ + struct instruction *instructions; /* points to intermediate code instructions */ + + s4 stackcount; /* number of stack elements */ + struct stackelement *stack; /* points to intermediate code instructions */ + s4 exceptiontablelength;/* exceptiontable length */ - exceptiontable *exceptiontable; - /* the exceptiontable */ + exceptiontable *exceptiontable; /* the exceptiontable */ + + u2 thrownexceptionscount;/*number of exceptions declared to be thrown by a method*/ + classinfo **thrownexceptions; /*array of classinfos of declared exceptions*/ + + u2 linenumbercount; /* number of linenumber attributes */ + lineinfo *linenumbers; /* array of lineinfo items */ - u1 *stubroutine; /* stub for compiling or calling natives */ + struct registerdata *registerdata; /* struct with all regalloc stuff */ + + struct codegendata *codegendata;/* struct with codegen stuff */ + + u1 *stubroutine; /* stub for compiling or calling natives */ s4 mcodelength; /* legth of generated machine code */ u1 *mcode; /* pointer to machine code */ u1 *entrypoint; /* entry point in machine code */ @@ -553,6 +625,7 @@ struct methodinfo { /* method structure */ /* should # method def'd and used be kept after static parse (will it be used?) */ s4 subRedefs; s4 subRedefsUsed; + s4 nativelyoverloaded; /*used in header.c and only valid there*/ }; @@ -575,13 +648,12 @@ struct classinfo { /* class structure */ struct java_lang_VMClass* vmClass; struct java_lang_reflect_Constructor* constructor; - - s4 initializing_thread; /* gnu classpath */ - s4 erroneous_state; /* gnu classpath */ - struct gnu_classpath_RawData* vmData; /* gnu classpath */ + s4 initializing_thread; /* gnu classpath */ + s4 erroneous_state; /* gnu classpath */ + struct gnu_classpath_RawData* vmData; /* gnu classpath */ s4 flags; /* ACC flags */ - utf *name; /* class name */ + utf *name; /* class name */ s4 cpcount; /* number of entries in constant pool */ u1 *cptags; /* constant pool tags */ @@ -602,18 +674,19 @@ struct classinfo { /* class structure */ listnode listnode; /* linkage */ - bool initialized; /* true, if class already initialised */ + bool initialized; /* true, if class already initialised */ + bool initializing; /* flag for the compiler */ bool loaded; /* true, if class already loaded */ bool linked; /* true, if class already linked */ s4 index; /* hierarchy depth (classes) or index - (interfaces) */ + (interfaces) */ s4 instancesize; /* size of an instance of this class */ #ifdef SIZE_FROM_CLASSINFO s4 alignedsize; /* size of an instance, aligned to the allocation size on the heap */ #endif - vftbl *vftbl; /* pointer to virtual function table */ + vftbl_t *vftbl; /* pointer to virtual function table */ methodinfo *finalizer; /* finalizer method */ @@ -626,10 +699,13 @@ struct classinfo { /* class structure */ s4 classUsed; /* 0= not used 1 = used CO-RT */ classSetNode *impldBy; /* implemented by class set */ + utf *packagename; /* full name of the package */ + utf *sourcefile; /* classfile name containing this class */ + java_objectheader *classloader; /* 0 for bootstrap classloader */ }; /* check if class is an array class. Only use for linked classes! */ -#define CLASS_IS_ARRAY(clsinfo) (clsinfo->vftbl->arraydesc != NULL) +#define CLASS_IS_ARRAY(clsinfo) ((clsinfo)->vftbl->arraydesc != NULL) /* virtual function table ****************************************************** @@ -688,7 +764,7 @@ struct classinfo { /* class structure */ *******************************************************************************/ -struct vftbl { +struct _vftbl { methodptr *interfacetable[1]; /* interface table (access via macro) */ classinfo *class; /* class, the vtbl belongs to */ @@ -720,81 +796,30 @@ struct vftbl { *******************************************************************************/ struct arraydescriptor { - vftbl *componentvftbl; /* vftbl of the component type, NULL for primit. */ - vftbl *elementvftbl; /* vftbl of the element type, NULL for primitive */ + vftbl_t *componentvftbl; /* vftbl of the component type, NULL for primit. */ + vftbl_t *elementvftbl; /* vftbl of the element type, NULL for primitive */ short arraytype; /* ARRAYTYPE_* constant */ short dimension; /* dimension of the array (always >= 1) */ s4 dataoffset; /* offset of the array data from object pointer */ s4 componentsize; /* size of a component in bytes */ - short elementtype; /* ARRAYTYPE_* constant (XXX optimize away?) */ + short elementtype; /* ARRAYTYPE_* constant */ }; -/* references to some system classes ******************************************/ - -extern classinfo *class_java_lang_Object; -extern classinfo *class_java_lang_String; -extern classinfo *class_java_lang_Throwable; -extern classinfo *class_java_lang_Cloneable; -extern classinfo *class_java_io_Serializable; -extern classinfo *class_java_lang_ClassCastException; -extern classinfo *class_java_lang_NullPointerException; -extern classinfo *class_java_lang_ArrayIndexOutOfBoundsException; -extern classinfo *class_java_lang_NegativeArraySizeException; -extern classinfo *class_java_lang_OutOfMemoryError; -extern classinfo *class_java_lang_ArithmeticException; -extern classinfo *class_java_lang_ArrayStoreException; -extern classinfo *class_java_lang_ThreadDeath; -extern classinfo *pseudo_class_Arraystub; -extern classinfo *pseudo_class_Null; -extern vftbl *pseudo_class_Arraystub_vftbl; - - -/* instances of some system classes *******************************************/ - -extern java_objectheader *proto_java_lang_ClassCastException; -extern java_objectheader *proto_java_lang_NullPointerException; -extern java_objectheader *proto_java_lang_ArrayIndexOutOfBoundsException; -extern java_objectheader *proto_java_lang_NegativeArraySizeException; -extern java_objectheader *proto_java_lang_OutOfMemoryError; -extern java_objectheader *proto_java_lang_ArithmeticException; -extern java_objectheader *proto_java_lang_ArrayStoreException; -extern java_objectheader *proto_java_lang_ThreadDeath; - - /* flag variables *************************************************************/ -extern bool compileall; -extern bool runverbose; -extern bool verbose; -extern bool opt_rt; /* Rapid Type Analysis for better inlining CO-RT*/ -extern bool opt_xta; /* X Type Analysis for better inlining CO-XTA*/ -extern bool opt_vta; /* Variable Type Analysis for better inlining CO-VTA*/ +extern bool cacao_initializing; + #ifdef TYPECHECK_VERBOSE_OPT extern bool typecheckverbose; #endif -//extern int pClassHeir; -//extern int pCallgraph; -//extern int pOpcodes; -//extern int pStats; - -//extern void RT_jit_parse(methodinfo *m); +/*extern int pClassHeir;*/ +/*extern int pCallgraph;*/ +/*extern int pOpcodes;*/ +/*extern int pStats;*/ - -/* statistic variables ********************************************************/ - -extern int count_class_infos; -extern int count_const_pool_len; -extern int count_vftbl_len; -extern int count_utf_len; -extern int count_all_methods; -extern int count_vmcode_len; -extern int count_extable_len; -extern int count_class_loads; -extern int count_class_inits; -extern int count_utf_new; -extern int count_utf_new_found; +/*extern void RT_jit_parse(methodinfo *m);*/ /* table of primitive types ***************************************************/ @@ -807,18 +832,25 @@ extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT]; /* macros for descriptor parsing **********************************************/ -/* utf_ptr must point to the 'L' or the '[' of a field descriptor. +/* SKIP_FIELDDESCRIPTOR: + * utf_ptr must point to the first character of a field descriptor. * After the macro call utf_ptr points to the first character after * the field descriptor. * * CAUTION: This macro does not check for an unexpected end of the - * descriptor. + * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE. */ -#define SKIP_FIELDDESCRIPTOR(utf_ptr) \ - { while (*(utf_ptr)=='[') (utf_ptr)++; \ - if (*(utf_ptr)++=='L') \ - while(*(utf_ptr)++ != ';') /* skip */; } -/* Input: +#define SKIP_FIELDDESCRIPTOR(utf_ptr) \ + do { while (*(utf_ptr)=='[') (utf_ptr)++; \ + if (*(utf_ptr)++=='L') \ + while(*(utf_ptr)++ != ';') /* skip */; } while(0) + +/* SKIP_FIELDDESCRIPTOR_SAFE: + * utf_ptr must point to the first character of a field descriptor. + * After the macro call utf_ptr points to the first character after + * the field descriptor. + * + * Input: * utf_ptr....points to first char of descriptor * end_ptr....points to first char after the end of the string * errorflag..must be initialized (to false) by the caller! @@ -826,15 +858,26 @@ extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT]; * utf_ptr....points to first char after the descriptor * errorflag..set to true if the string ended unexpectedly */ -#define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag) \ - { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++; \ - if ((utf_ptr) == (end_ptr)) \ - (errorflag) = true; \ - else \ - if (*(utf_ptr)++=='L') { \ - while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';') /* skip */; \ - if ((utf_ptr)[-1] != ';') \ - (errorflag) = true; }} +#define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag) \ + do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++; \ + if ((utf_ptr) == (end_ptr)) \ + (errorflag) = true; \ + else \ + if (*(utf_ptr)++=='L') { \ + while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';') \ + /* skip */; \ + if ((utf_ptr)[-1] != ';') \ + (errorflag) = true; }} while(0) + + +/* Synchronization ************************************************************/ + +#if defined(USE_THREADS) && defined(NATIVE_THREADS) +void cast_lock(); +void cast_unlock(); +void compiler_lock(); +void compiler_unlock(); +#endif #endif /* _GLOBAL_H */