X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fvm%2Fglobal.h;h=e761d76eb3a0af8d705ee15dad35f10247856d93;hb=fa8651a5a680d2f25e03d6df5fd275e70d5cc696;hp=27ed990e265fe7c3480b0c0f8df9f9bfd94f35d6;hpb=0e10b741c333aacac611c3f90902e404a225bf41;p=cacao.git diff --git a/src/vm/global.h b/src/vm/global.h index 27ed990e2..e761d76eb 100644 --- a/src/vm/global.h +++ b/src/vm/global.h @@ -1,9 +1,7 @@ /* src/vm/global.h - global definitions - Copyright (C) 1996-2005, 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 + Copyright (C) 1996-2005, 2006, 2007, 2008, 2010 + CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO This file is part of CACAO. @@ -22,19 +20,6 @@ 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 4552 2006-03-04 17:15:44Z twisti $ - */ @@ -42,20 +27,26 @@ #define _GLOBAL_H #include "config.h" -#include "types.h" + +#include +#include + +#include "vm/types.h" /* additional data types ******************************************************/ -typedef void *voidptr; /* generic pointer */ 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 */ @@ -67,93 +58,99 @@ typedef union { void *a; functionptr fp; u1 b[8]; +#if defined(ENABLE_SSA) + struct imm _i; +#endif } imm_union; -/* forward typedefs ***********************************************************/ +/* alignment macros ***********************************************************/ + +#define ALIGN_EVEN(a) ((a) = (((a) + 1) & ~1)) +#define ALIGN_ODD(a) ((a) = (a) | 1 ) + +#define ALIGN_2(a) ALIGN_EVEN(a) -typedef struct java_objectheader java_objectheader; -typedef struct java_objectarray java_objectarray; +/* printf format defines ******************************************************/ -/* define some CACAO paths ****************************************************/ +/* Define printf formats which change size between 32- and 64-bit. */ -#if defined(ENABLE_ZLIB) -# define CACAO_VM_ZIP_PATH CACAO_PREFIX "/share/cacao/" VM_ZIP_STRING +#if SIZEOF_VOID_P == 8 +# define PRINTF_FORMAT_INTPTR_T "0x%016lx" +# define PRINTF_FORMAT_INT64_T "%ld" #else -# define CACAO_VM_ZIP_PATH CACAO_PREFIX "/share/cacao/" +# define PRINTF_FORMAT_INTPTR_T "0x%08lx" +# define PRINTF_FORMAT_INT64_T "%lld" #endif -#define CLASSPATH_GLIBJ_ZIP_PATH CLASSPATH_PREFIX "/share/classpath/" GLIBJ_ZIP_STRING -#define CLASSPATH_LIBRARY_PATH CLASSPATH_LIBDIR "/classpath" +/* convenience macros *********************************************************/ -/* - * ENABLE_VERIFIER activates bytecode verification and other checks - */ -#define ENABLE_VERIFIER +/* Makes a string of the argument (which is not macro-expanded). */ -/* - * 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 +#define STR(a) #a -/* if we have threads disabled this one is not defined ************************/ +/* There are multiple definitions of MIN out there, but we cannot be sure. */ -#if !defined(USE_THREADS) -#define THREADSPECIFIC +#ifndef MIN +# define MIN(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#ifndef MAX +# define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif +/* 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 */ /* 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 @@ -199,20 +196,66 @@ typedef struct java_objectarray java_objectarray; #define ACC_ENUM 0x4000 #define ACC_MIRANDA 0x8000 +/* special flags used in classinfo ********************************************/ + +#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 + + +/* 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 **************************************/ -/* 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_MARK1 0x02 +#define HDRFLAG_MARK2 0x04 +#define HDRFLAG_UNCOLLECTABLE 0x08 +#define HDRFLAG_HASH_TAKEN 0x10 +#define HDRFLAG_HASH_ATTACHED 0x20 +#define HDRFLAG_REFERENCING 0x40 + +#include "threads/lockword.hpp" + +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 }; @@ -225,24 +268,10 @@ 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; @@ -251,90 +280,89 @@ typedef struct java_arrayheader { /* header for all arrays */ /* 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_chararray { - java_arrayheader header; +typedef struct java_chararray_t { + java_array_t header; u2 data[1]; -} java_chararray; +} java_chararray_t; -typedef struct java_shortarray { - java_arrayheader header; +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 { - java_arrayheader header; +typedef struct java_floatarray_t { + java_array_t header; float data[1]; -} java_floatarray; +} java_floatarray_t; -typedef struct java_doublearray { - java_arrayheader header; +typedef struct java_doublearray_t { + java_array_t header; double data[1]; -} java_doublearray; +} 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(); -#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" - -#if defined(USE_THREADS) - #define THREADCLASS "java/lang/Thread" - #define THREADMETH "" - #define THREADDESC "(Ljava/lang/VMThread;Ljava/lang/String;IZ)V" - - #define THREADGROUPCLASS "java/lang/ThreadGroup" - #define THREADGROUPMETH "addThread" - #define THREADGROUPDESC "(Ljava/lang/Thread;)V" +typedef java_object_t java_handle_t; +typedef java_handle_t java_handle_array_t; +typedef java_handle_array_t java_handle_objectarray_t; +typedef java_handle_array_t java_handle_booleanarray_t; +typedef java_handle_array_t java_handle_bytearray_t; +typedef java_handle_array_t java_handle_chararray_t; +typedef java_handle_array_t java_handle_shortarray_t; +typedef java_handle_array_t java_handle_intarray_t; +typedef java_handle_array_t java_handle_longarray_t; +typedef java_handle_array_t java_handle_floatarray_t; +typedef java_handle_array_t java_handle_doublearray_t; + + +/* global constants related to the verifier ***********************************/ + +/* 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. */ + +#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 */ @@ -351,4 +379,5 @@ void compiler_unlock(); * c-basic-offset: 4 * tab-width: 4 * End: + * vim:noexpandtab:sw=4:ts=4: */