* Removed all Id tags.
[cacao.git] / src / vm / global.h
index 5ff4ce0a599461dea57b213ee82ef726e71f5cd5..f3938b91abef16984c2d98c573f305848b272ea8 100644 (file)
@@ -1,6 +1,6 @@
 /* src/vm/global.h - global definitions
 
-   Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+   Copyright (C) 1996-2005, 2007, 2006 R. Grafl, A. Krall, C. Kruegel,
    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
    J. Wenninger, Institut f. Computersprachen - TU Wien
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Contact: cacao@cacaojvm.org
-
-   Authors: Reinhard Grafl
-            Andreas Krall
-
-   Changes: Mark Probst
-            Philipp Tomsich
-            Edwin Steiner
-            Joseph Wenninger
-            Christian Thalinger
-
-   $Id: global.h 4417 2006-02-03 22:24:55Z twisti $
-
 */
 
 
@@ -42,7 +29,7 @@
 #define _GLOBAL_H
 
 #include "config.h"
-#include "types.h"
+#include "vm/types.h"
 
 
 /* additional data types ******************************************************/
@@ -51,12 +38,21 @@ typedef void *voidptr;                  /* generic pointer                    */
 typedef void (*functionptr) (void);     /* generic function pointer           */
 typedef u1* methodptr;
 
-typedef int   bool;                     /* boolean data type                  */
+typedef unsigned int bool;              /* boolean data type                  */
 
-#define true  1
-#define false 0
+#define true         1
+#define false        0
 
 
+#if defined(ENABLE_SSA)
+/* immediate to get an addidional target Local Var Index */
+/* for IINC in Combination with SSA */
+struct imm {
+       s4 i;
+       s4 op1_t;
+};
+#endif
+
 /* immediate data union */
 
 typedef union {
@@ -67,44 +63,24 @@ typedef union {
        void       *a;
        functionptr fp;
        u1          b[8];
+#if defined(ENABLE_SSA)
+       struct imm  _i;
+#endif
 } imm_union;
 
 
-/* forward typedefs ***********************************************************/
-
-typedef struct java_objectheader java_objectheader; 
-typedef struct java_objectarray java_objectarray;
-
-
-/* define some CACAO paths ****************************************************/
-
-#if defined(ENABLE_ZLIB)
-# define CACAO_VM_ZIP_PATH          CACAO_PREFIX "/share/cacao/vm.zip"
-#else
-# define CACAO_VM_ZIP_PATH          CACAO_PREFIX "/share/cacao/"
-#endif
-
-#define CLASSPATH_GLIBJ_ZIP_PATH    CLASSPATH_PREFIX "/share/classpath/" GLIBJZ_STRING
-#define CLASSPATH_LIBRARY_PATH      CLASSPATH_LIBDIR "/classpath"
+/* alignment macros ***********************************************************/
 
+#define ALIGN_EVEN(a)                   ((a) = (((a) + 1) & ~1))
+#define ALIGN_ODD(a)                    ((a) =   (a) | 1       )
 
-/*
- * ENABLE_VERIFIER activates bytecode verification and other checks
- */
-#define ENABLE_VERIFIER
+#define ALIGN_2(a)                      ALIGN_EVEN(a)
 
-/*
- * 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
 
-/* if we have threads disabled this one is not defined ************************/
+/* forward typedefs ***********************************************************/
 
-#if !defined(USE_THREADS)
-#define THREADSPECIFIC
-#endif
+typedef struct java_object_t java_object_t; 
+typedef struct java_objectarray_t java_objectarray_t;
 
 
 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
@@ -112,48 +88,44 @@ typedef struct java_objectarray java_objectarray;
 
 /* 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)              */
-#define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
-#define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
+/* The JavaVM types must numbered in the same order as the ICMD_Ixxx
+   to ICMD_Axxx instructions (LOAD and STORE).  All other types can be
+   numbered arbitrarily. */
+
+#define TYPE_INT     0
+#define TYPE_LNG     1
+#define TYPE_FLT     2
+#define TYPE_DBL     3
+#define TYPE_ADR     4
+
+#define TYPE_RET     8   /* must not share bits with TYPE_FLT or TYPE_LNG */
 
 #define TYPE_VOID    10
 
-/* primitive data types *******************************************************/
 
-/* These values are used in parsed descriptors and in some other places       */
-/* were the different types handled internally as TYPE_INT have to be         */
-/* distinguished.                                                             */
+#define IS_INT_LNG_TYPE(a)      (!((a) & TYPE_FLT))
+#define IS_FLT_DBL_TYPE(a)      ((a) & TYPE_FLT)
+#define IS_2_WORD_TYPE(a)       ((a) & TYPE_LNG)
 
-#define PRIMITIVETYPE_COUNT  11  /* number of primitive types (+ dummies)     */
+#define IS_INT_TYPE(a)          ((a) == TYPE_INT)
+#define IS_LNG_TYPE(a)          ((a) == TYPE_LNG)
+#define IS_FLT_TYPE(a)          ((a) == TYPE_FLT)
+#define IS_DBL_TYPE(a)          ((a) == TYPE_DBL)
+#define IS_ADR_TYPE(a)          ((a) == TYPE_ADR)
+
+#define IS_VOID_TYPE(a)         ((a) == TYPE_VOID)
 
-/* CAUTION: Don't change the numerical values! These constants are
- * used as indices into the primitive type table.
- */
-#define PRIMITIVETYPE_INT     TYPE_INT
-#define PRIMITIVETYPE_LONG    TYPE_LONG
-#define PRIMITIVETYPE_FLOAT   TYPE_FLOAT
-#define PRIMITIVETYPE_DOUBLE  TYPE_DOUBLE
-#define PRIMITIVETYPE_DUMMY1  TYPE_ADR     /* not used! */
-#define PRIMITIVETYPE_BYTE    5
-#define PRIMITIVETYPE_CHAR    6
-#define PRIMITIVETYPE_SHORT   7
-#define PRIMITIVETYPE_BOOLEAN 8
-#define PRIMITIVETYPE_DUMMY2  9            /* not used! */
-#define PRIMITIVETYPE_VOID    TYPE_VOID
 
 /* some Java related defines **************************************************/
 
-#define JAVA_VERSION    "1.4.2"         /* this version is supported by CACAO */
-#define CLASS_VERSION   "49.0"
+#define JAVA_VERSION    "1.5.0"         /* this version is supported by CACAO */
+#define CLASS_VERSION   "50.0"
 
 
 /* Java class file constants **************************************************/
 
 #define MAGIC             0xCAFEBABE
-#define MAJOR_VERSION     49
+#define MAJOR_VERSION     50
 #define MINOR_VERSION     0
 
 
@@ -197,31 +169,51 @@ typedef struct java_objectarray java_objectarray;
 #define ACC_SYNTHETIC       0x1000
 #define ACC_ANNOTATION      0x2000
 #define ACC_ENUM            0x4000
+#define ACC_MIRANDA         0x8000
 
+/* special flags used in classinfo ********************************************/
 
-/* data structure for calls from c code to java methods */
+#define ACC_CLASS_REFLECT_MASK      0x0000ffff/* flags reported by reflection */
 
-struct jni_callblock {
-       u8 itemtype;
-       u8 item;
-};
+#define ACC_CLASS_PRIMITIVE         0x00010000
+#define ACC_CLASS_MEMBER            0x00020000
+#define ACC_CLASS_ANONYMOUS         0x00040000
+
+#define ACC_CLASS_HAS_POINTERS      0x00080000/* instance contains pointers   */
 
-typedef struct jni_callblock jni_callblock;
+#define ACC_CLASS_REFERENCE_MASK    0x00700000
+#define ACC_CLASS_REFERENCE_SOFT    0x00100000
+#define ACC_CLASS_REFERENCE_WEAK    0x00200000
+#define ACC_CLASS_REFERENCE_PHANTOM 0x00400000
+
+
+/* special flags used in methodinfo *******************************************/
+
+#define ACC_METHOD_BUILTIN     0x00010000     /* use for descriptor parsing   */
+#define ACC_METHOD_IMPLEMENTED 0x00020000     /* there is an implementation   */
+#define ACC_METHOD_MONOMORPHIC 0x00040000     /* currently monomorphic method */
 
 
 /* data structures of the runtime system **************************************/
 
-/* java_objectheader ***********************************************************
+/* java_object_t ***************************************************************
 
    All objects (and arrays) which resides on the heap need the
    following header at the beginning of the data structure.
 
+   TODO: Include detailed description from the Wiki (ObjectHeader) here.
+
 *******************************************************************************/
 
-struct java_objectheader {              /* header for all objects             */
-       struct _vftbl *vftbl;               /* pointer to virtual function table  */
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-       void          *monitorPtr;
+#define HDRFLAG_FLC 0x01
+
+struct java_object_t {                 /* header for all objects              */
+       struct _vftbl            *vftbl;   /* pointer to virtual function table   */
+#if defined(ENABLE_THREADS)
+       struct lock_record_t *monitorPtr;
+#endif
+#if defined(ENABLE_THREADS) || defined(ENABLE_GC_CACAO)
+       ptrint                hdrflags;    /* word containing the FLC and GC bits */
 #endif
 };
 
@@ -234,116 +226,111 @@ struct java_objectheader {              /* header for all objects             */
        which is referenced by the vftbl.
 */
 
-/* CAUTION: Don't change the numerical values! These constants (with
- * the exception of ARRAYTYPE_OBJECT) are used as indices in the
- * primitive type table.
- */
-#define ARRAYTYPE_INT      PRIMITIVETYPE_INT
-#define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
-#define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
-#define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
-#define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
-#define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
-#define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
-#define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
-#define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
-
-typedef struct java_arrayheader {       /* header for all arrays              */
-       java_objectheader objheader;        /* object header                      */
+typedef struct java_array_t {           /* header for all arrays              */
+       java_object_t objheader;            /* object header                      */
        s4 size;                            /* array size                         */
-} java_arrayheader;
+} java_array_t;
 
 
 
 /* structs for all kinds of arrays ********************************************/
 
-typedef struct java_chararray {
-       java_arrayheader header;
-       u2 data[1];
-} java_chararray;
-
-typedef struct java_floatarray {
-       java_arrayheader header;
-       float data[1];
-} java_floatarray;
-
-typedef struct java_doublearray {
-       java_arrayheader header;
-       double data[1];
-} java_doublearray;
-
 /*  booleanarray and bytearray need identical memory layout (access methods
     use the same machine code */
 
-typedef struct java_booleanarray {
-       java_arrayheader header;
+typedef struct java_booleanarray_t {
+       java_array_t header;
        u1 data[1];
-} java_booleanarray;
+} java_booleanarray_t;
 
-typedef struct java_bytearray {
-       java_arrayheader header;
+typedef struct java_bytearray_t {
+       java_array_t header;
        s1 data[1];
-} java_bytearray;
+} java_bytearray_t;
 
-typedef struct java_shortarray {
-       java_arrayheader header;
+typedef struct java_chararray_t {
+       java_array_t header;
+       u2 data[1];
+} java_chararray_t;
+
+typedef struct java_shortarray_t {
+       java_array_t header;
        s2 data[1];
-} java_shortarray;
+} java_shortarray_t;
 
-typedef struct java_intarray {
-       java_arrayheader header;
+typedef struct java_intarray_t {
+       java_array_t header;
        s4 data[1];
-} java_intarray;
+} java_intarray_t;
 
-typedef struct java_longarray {
-       java_arrayheader header;
+typedef struct java_longarray_t {
+       java_array_t header;
        s8 data[1];
-} java_longarray;
+} java_longarray_t;
+
+typedef struct java_floatarray_t {
+       java_array_t header;
+       float data[1];
+} java_floatarray_t;
+
+typedef struct java_doublearray_t {
+       java_array_t header;
+       double data[1];
+} java_doublearray_t;
 
 /*  objectarray and arrayarray need identical memory layout (access methods
     use the same machine code */
 
-struct java_objectarray {
-       java_arrayheader   header;
-       java_objectheader *data[1];
+struct java_objectarray_t {
+       java_array_t   header;
+       java_object_t *data[1];
 };
 
 
-#define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
-
-
-/* flag variables *************************************************************/
+/* java_handle_t ***************************************************************
 
-extern bool cacao_initializing;
+   TODO: document me!
 
+*******************************************************************************/
 
-/* Synchronization ************************************************************/
-
-#if defined(USE_THREADS) && defined(NATIVE_THREADS)
-void cast_lock();
-void cast_unlock();
-void compiler_lock();
-void compiler_unlock();
+#if 0
+typedef struct java_handle_t {
+       java_object_t *heap_object;
+} java_handle_t;
+#elseif 0
+typedef union {
+       java_object_t    object;
+       java_array_t     array;
+} java_handle_t;
+#else
+typedef java_object_t       java_handle_t;
+typedef java_objectarray_t  java_handle_objectarray_t;
+typedef java_booleanarray_t java_handle_booleanarray_t;
+typedef java_bytearray_t    java_handle_bytearray_t;
+typedef java_chararray_t    java_handle_chararray_t;
+typedef java_shortarray_t   java_handle_shortarray_t;
+typedef java_intarray_t     java_handle_intarray_t;
+typedef java_longarray_t    java_handle_longarray_t;
+typedef java_floatarray_t   java_handle_floatarray_t;
+typedef java_doublearray_t  java_handle_doublearray_t;
 #endif
 
 
-/**** Methods: called directly by cacao, which defines the callpath ***/
-#define MAINCLASS mainstring
-#define MAINMETH "main"
-#define MAINDESC "([Ljava/lang/String;)V"
-
-#define EXITCLASS "java/lang/System"
-#define EXITMETH  "exit"
-#define EXITDESC  "(I)V"
+/* global constants related to the verifier ***********************************/
 
-#if defined(USE_THREADS)
- #define THREADCLASS "java/lang/Thread"
- #define THREADMETH  "<init>"
- #define THREADDESC  "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V"
+/* The verifier needs additional variables in the variable array. Since these */
+/* must be reserved and set by parse.c and stack.c, we define these numbers   */
+/* here to avoid mysterious hard-coded constants.                             */
+/* stack.c needs an extra variable if the verifier is disabled.               */
 
- #define THREADGROUPCLASS "java/lang/ThreadGroup"
- #define THREADGROUPMETH  "addThread"
- #define THREADGROUPDESC  "(Ljava/lang/Thread;)V"
+#if defined(ENABLE_VERIFIER)
+#    define VERIFIER_EXTRA_LOCALS  1
+#    define VERIFIER_EXTRA_VARS    1
+#    define STACK_EXTRA_VARS       0
+#else
+#    define VERIFIER_EXTRA_LOCALS  0
+#    define VERIFIER_EXTRA_VARS    0
+#    define STACK_EXTRA_VARS       1
 #endif
 
 #endif /* _GLOBAL_H */
@@ -360,4 +347,5 @@ void compiler_unlock();
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */