Merged with tip.
[cacao.git] / src / vm / global.h
index 0664da6b368e3d85e62e8ec276049cdd0626a09a..2a09e47c1fdafb958d9fedf361c010c83051c87d 100644 (file)
@@ -1,9 +1,7 @@
 /* src/vm/global.h - global definitions
 
 /* src/vm/global.h - global definitions
 
-   Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
-   R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
-   C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
-   Institut f. Computersprachen - TU Wien
+   Copyright (C) 1996-2005, 2006, 2007, 2008
+   CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
 
    This file is part of CACAO.
 
 
    This file is part of CACAO.
 
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.
-
-   Contact: cacao@complang.tuwien.ac.at
-
-   Authors: Reinhard Grafl
-            Andreas Krall
-
-   Changes: Mark Probst
-            Philipp Tomsich
-            Edwin Steiner
-            Joseph Wenninger
-            Christian Thalinger
-
-   $Id: global.h 3811 2005-11-28 16:23:40Z edwin $
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA.
 
 */
 
 
 */
 
 #define _GLOBAL_H
 
 #include "config.h"
 #define _GLOBAL_H
 
 #include "config.h"
-#include "types.h"
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "vm/types.h"
 
 
 /* additional data types ******************************************************/
 
 
 /* additional data types ******************************************************/
@@ -51,11 +40,14 @@ typedef void *voidptr;                  /* generic pointer                    */
 typedef void (*functionptr) (void);     /* generic function pointer           */
 typedef u1* methodptr;
 
 typedef void (*functionptr) (void);     /* generic function pointer           */
 typedef u1* methodptr;
 
-typedef int   bool;                     /* boolean data type                  */
-
-#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 */
 
 
 /* immediate data union */
 
@@ -67,39 +59,42 @@ typedef union {
        void       *a;
        functionptr fp;
        u1          b[8];
        void       *a;
        functionptr fp;
        u1          b[8];
+#if defined(ENABLE_SSA)
+       struct imm  _i;
+#endif
 } imm_union;
 
 
 } imm_union;
 
 
-/* forward typedefs ***********************************************************/
+/* alignment macros ***********************************************************/
 
 
-typedef struct java_objectheader java_objectheader; 
-typedef struct java_objectarray java_objectarray;
+#define ALIGN_EVEN(a)                   ((a) = (((a) + 1) & ~1))
+#define ALIGN_ODD(a)                    ((a) =   (a) | 1       )
 
 
+#define ALIGN_2(a)                      ALIGN_EVEN(a)
 
 
-/* define some CACAO paths ****************************************************/
 
 
-#define CACAO_VM_ZIP_PATH           "/share/cacao/vm.zip"
-#define CLASSPATH_LIBRARY_PATH      "/lib/classpath"
-#define CLASSPATH_GLIBJ_ZIP_PATH    "/share/classpath/" GLIBJZ_STRING
+/* printf format defines ******************************************************/
 
 
+/* Define printf formats which change size between 32- and 64-bit. */
 
 
-/*
- * ENABLE_VERIFIER activates bytecode verification and other checks
- */
-#define ENABLE_VERIFIER
+#if SIZEOF_VOID_P == 8
+# define PRINTF_FORMAT_INT64_T    "%ld"
+#else
+# define PRINTF_FORMAT_INT64_T    "%lld"
+#endif
 
 
-/*
- * 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 ************************/
+/* convenience macros *********************************************************/
 
 
-#if !defined(USE_THREADS)
-#define THREADSPECIFIC
-#endif
+/* Makes a string of the argument (which is not macro-expanded). */
+
+#define STR(a)  #a
+
+
+/* forward typedefs ***********************************************************/
+
+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   */
 
 
 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
@@ -107,48 +102,44 @@ typedef struct java_objectarray java_objectarray;
 
 /* basic data types ***********************************************************/
 
 
 /* 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
 
 
 #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 **************************************************/
 
 
 /* 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
 
 
 /* Java class file constants **************************************************/
 
 #define MAGIC             0xCAFEBABE
-#define MAJOR_VERSION     49
+#define MAJOR_VERSION     50
 #define MINOR_VERSION     0
 
 
 #define MINOR_VERSION     0
 
 
@@ -192,31 +183,66 @@ typedef struct java_objectarray java_objectarray;
 #define ACC_SYNTHETIC       0x1000
 #define ACC_ANNOTATION      0x2000
 #define ACC_ENUM            0x4000
 #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 */
+
+#define ACC_CLASS_PRIMITIVE         0x00010000
+#define ACC_CLASS_MEMBER            0x00020000
+#define ACC_CLASS_ANONYMOUS         0x00040000
+
+#define ACC_CLASS_HAS_POINTERS      0x00080000/* instance contains pointers   */
+
+#define ACC_CLASS_REFERENCE_MASK    0x00700000
+#define ACC_CLASS_REFERENCE_SOFT    0x00100000
+#define ACC_CLASS_REFERENCE_WEAK    0x00200000
+#define ACC_CLASS_REFERENCE_PHANTOM 0x00400000
 
 
-struct jni_callblock {
-       u8 itemtype;
-       u8 item;
-};
 
 
-typedef struct jni_callblock jni_callblock;
+/* 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 */
+#define ACC_METHOD_EA          0x00080000     /* method being escape analyzed */
+#define ACC_METHOD_MONOMORPHY_USED \
+                               0x00100000
+#define ACC_METHOD_PARENT_MONOMORPHY_USED \
+                               0x00200000
 
 
 /* data structures of the runtime system **************************************/
 
 
 
 /* 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.
 
 
    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_MARK1         0x02
+#define HDRFLAG_MARK2         0x04
+#define HDRFLAG_UNCOLLECTABLE 0x08
+#define HDRFLAG_HASH_TAKEN    0x10
+#define HDRFLAG_HASH_ATTACHED 0x20
+#define HDRFLAG_REFERENCING   0x40
+
+struct java_object_t {                 /* header for all objects              */
+       struct _vftbl *vftbl;              /* pointer to virtual function table   */
+#if defined(ENABLE_THREADS)
+       uintptr_t      lockword;
+#endif
+#if defined(ENABLE_GC_CACAO)
+       uintptr_t      hdrflags;           /* word containing the GC bits         */
+#endif
+#if defined(ENABLE_ESCAPE_CHECK)
+       void *method;
+       void *thread;
+       uintptr_t escape;
 #endif
 };
 
 #endif
 };
 
@@ -229,116 +255,116 @@ struct java_objectheader {              /* header for all objects             */
        which is referenced by the vftbl.
 */
 
        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                         */
        s4 size;                            /* array size                         */
-} java_arrayheader;
+} java_array_t;
 
 
 
 /* structs for all kinds of arrays ********************************************/
 
 
 
 
 /* structs for all kinds of arrays ********************************************/
 
-typedef struct java_chararray {
-       java_arrayheader header;
-       u2 data[1];
-} java_chararray;
-
-typedef struct java_floatheader {
-       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 */
 
 /*  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];
        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];
        s1 data[1];
-} java_bytearray;
+} java_bytearray_t;
+
+typedef struct java_chararray_t {
+       java_array_t header;
+       u2 data[1];
+} java_chararray_t;
 
 
-typedef struct java_shortarray {
-       java_arrayheader header;
+typedef struct java_shortarray_t {
+       java_array_t header;
        s2 data[1];
        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];
        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];
        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 */
 
 
 /*  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 defined(ENABLE_HANDLES)
+typedef struct java_handle_t {
+       java_object_t *heap_object;
+} java_handle_t;
+
+typedef struct java_handle_objectarray_t  { java_objectarray_t  *heap_object; } java_handle_objectarray_t;
+typedef struct java_handle_booleanarray_t { java_booleanarray_t *heap_object; } java_handle_booleanarray_t;
+typedef struct java_handle_bytearray_t    { java_bytearray_t    *heap_object; } java_handle_bytearray_t;
+typedef struct java_handle_chararray_t    { java_chararray_t    *heap_object; } java_handle_chararray_t;
+typedef struct java_handle_shortarray_t   { java_shortarray_t   *heap_object; } java_handle_shortarray_t;
+typedef struct java_handle_intarray_t     { java_intarray_t     *heap_object; } java_handle_intarray_t;
+typedef struct java_handle_longarray_t    { java_longarray_t    *heap_object; } java_handle_longarray_t;
+typedef struct java_handle_floatarray_t   { java_floatarray_t   *heap_object; } java_handle_floatarray_t;
+typedef struct java_handle_doublearray_t  { java_doublearray_t  *heap_object; } java_handle_doublearray_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
 
 
 #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 */
 #endif
 
 #endif /* _GLOBAL_H */
@@ -355,4 +381,5 @@ void compiler_unlock();
  * c-basic-offset: 4
  * tab-width: 4
  * End:
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */
  */