-/* global.h ********************************************************************
+/* global.h - global definitions
- Copyright (c) 1997 A. Krall, R. Grafl, M. Gschwind, M. Probst
+ Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
+ R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
+ M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
+ P. Tomsich, J. Wenninger
- See file COPYRIGHT for information on usage and disclaimer of warranties
+ This file is part of CACAO.
- Contains global definitions which are used in the whole program, includes
- some files and contains global used macros.
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
- Authors: Reinhard Grafl EMAIL: cacao@complang.tuwien.ac.at
- Andreas Krall (andi) EMAIL: cacao@complang.tuwien.ac.at
- Changes: Mark Probst (schani) EMAIL: cacao@complang.tuwien.ac.at
- Philipp Tomsich (phil) EMAIL: cacao@complang.tuwien.ac.at
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
- Last Change: $Id: global.h 468 2003-10-04 17:15:31Z carolyn $
+ 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
+
+ $Id: global.h 682 2003-12-01 15:33:30Z jowenn $
+
+*/
-#ifndef __global_h_
-#define __global_h_
+
+#ifndef _GLOBAL_H
+#define _GLOBAL_H
#include "config.h"
+#include "types.h"
+#include "toolbox/list.h"
-#define NEW_GC /* if enabled, includes the new gc. -- phil. */
+
+#define _GNU_SOURCE
#define STATISTICS /* if enabled collects program statistics */
/*
- * JIT_MARKER_SUPPORT is the define used to toggle Just-in-time generated
- * marker functions on and off.
- *
* SIZE_FROM_CLASSINFO toggles between the bitmap_based and the new method
* of determining the sizes of objects on the heap.
*/
-#undef JIT_MARKER_SUPPORT /* phil */
#define SIZE_FROM_CLASSINFO
/* standard includes **********************************************************/
#define PRIMITIVETYPE_COUNT 9 /* number of primitive types */
+/* CAUTION: Don't change the numerical values! These constants are
+ * used as indices into the primitive type table.
+ */
+#define PRIMITIVETYPE_INT 0
+#define PRIMITIVETYPE_LONG 1
+#define PRIMITIVETYPE_FLOAT 2
+#define PRIMITIVETYPE_DOUBLE 3
+#define PRIMITIVETYPE_BYTE 4
+#define PRIMITIVETYPE_CHAR 5
+#define PRIMITIVETYPE_SHORT 6
+#define PRIMITIVETYPE_BOOLEAN 7
+#define PRIMITIVETYPE_VOID 8
+
typedef void (*functionptr) (); /* generic function pointer */
#define CONSTANT_NameAndType 12
#define CONSTANT_Utf8 1
-#define CONSTANT_Arraydescriptor 13
#define CONSTANT_UNUSED 0
#define ACC_PUBLIC 0x0001
#define ACC_NATIVE 0x0100
#define ACC_INTERFACE 0x0200
#define ACC_ABSTRACT 0x0400
-
+#define ACC_STRICT 0x0800
/* resolve typedef cycles *****************************************************/
typedef u1* methodptr;
typedef struct fieldinfo fieldinfo;
typedef struct methodinfo methodinfo;
+typedef struct arraydescriptor arraydescriptor;
/* constant pool entries *******************************************************
CONSTANT_Double constant_double yes
CONSTANT_NameAndType constant_nameandtype yes
CONSTANT_Utf8 unicode no
- CONSTANT_Arraydescriptor constant_arraydescriptor yes
CONSTANT_UNUSED -
*******************************************************************************/
char *text; /* pointer to text */
};
+
/* data structure of internal javastrings stored in global hashtable **********/
struct literalstring {
java_objectheader *string;
};
+
+/* data structure for calls from c code to java methods */
+
+struct jni_callblock {
+ u1 itemtype;
+ u8 item;
+};
+
+typedef struct jni_callblock jni_callblock;
+
+
/* data structure for accessing hashtables ************************************/
typedef struct {
- u4 size;
- u4 entries; /* number of entries in the table */
- void **ptr; /* pointer to hashtable */
+ u4 size;
+ u4 entries; /* number of entries in the table */
+ void **ptr; /* pointer to hashtable */
} hashtable;
+
/* data structures of remaining constant pool entries *************************/
typedef struct { /* Fieldref, Methodref and InterfaceMethodref */
utf *descriptor; /* field/method/interface type descriptor string */
} constant_FMIref;
+
typedef struct { /* Integer */
s4 value;
} constant_integer;
+
typedef struct { /* Float */
float value;
} constant_float;
+
typedef struct { /* Long */
s8 value;
} constant_long;
+
typedef struct { /* Double */
double value;
} constant_double;
+
typedef struct { /* NameAndType (Field or Method) */
utf *name; /* field/method name */
utf *descriptor; /* field/method type descriptor string */
} constant_nameandtype;
-/* arraydescriptor describes array types. Basic array types contain their
- type in the arraytype field, objectclass contains a class pointer for
- arrays of objects (arraytype == ARRAYTYPE_OBJECT), elementdescriptor
- contains a pointer to an arraydescriptor which describes the element
- types in the case of arrays of arrays (arraytype == ARRAYTYPE_ARRAY).
-*/
-
-typedef struct constant_arraydescriptor {
- int arraytype;
- classinfo *objectclass;
- struct constant_arraydescriptor *elementdescriptor;
-} constant_arraydescriptor;
-
-#include "jit/sets.h"
/* data structures of the runtime system **************************************/
/* arrays **********************************************************************
- All arrays are objects (they need the object header with a pointer to a
- vvftbl (array class table). There is only one class for all arrays. The
- type of an array is stored directly in the array object. Following types
- are defined:
+ All arrays are objects (they need the object header with a pointer
+ to a vftbl (array class table). There is one class for each array
+ type. The array type is described by an arraydescriptor struct
+ which is referenced by the vftbl.
*/
-#define ARRAYTYPE_INT 0
-#define ARRAYTYPE_LONG 1
-#define ARRAYTYPE_FLOAT 2
-#define ARRAYTYPE_DOUBLE 3
-#define ARRAYTYPE_BYTE 4
-#define ARRAYTYPE_CHAR 5
-#define ARRAYTYPE_SHORT 6
-#define ARRAYTYPE_BOOLEAN 7
-#define ARRAYTYPE_OBJECT 8
-#define ARRAYTYPE_ARRAY 9
+/* 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 */
#ifdef SIZE_FROM_CLASSINFO
s4 alignedsize; /* phil */
#endif
- s4 arraytype; /* array type from previous list */
} java_arrayheader;
typedef struct java_objectarray {
java_arrayheader header;
- classinfo *elementtype;
java_objectheader *data[1];
} java_objectarray;
-typedef struct java_arrayarray {
- java_arrayheader header;
- constant_arraydescriptor *elementdescriptor;
- java_arrayheader *data[1];
-} java_arrayarray;
-
-
/* structure for primitive classes ********************************************/
typedef struct primitivetypeinfo {
char *wrapname; /* name of class for wrapping */
char typesig; /* one character type signature */
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 */
} primitivetypeinfo;
+
/* field, method and class structures *****************************************/
+#include "sets.h"
+typedef struct xtafldinfo {
+ bool fieldChecked;
+ classinfo *fldClassType;
+ classSet *XTAclassSet; /* field class type set */
+} xtafldinfo;
+
+
/* fieldinfo ******************************************************************/
struct fieldinfo { /* field of a class */
- s4 flags; /* ACC flags */
- s4 type; /* basic data type */
+ s4 flags; /* ACC flags */
+ s4 type; /* basic data type */
utf *name; /* name of field */
utf *descriptor; /* JavaVM descriptor string of field */
- s4 offset; /* offset from start of object (instance variables) */
+ s4 offset; /* offset from start of object (instance variables) */
union { /* storage for static values (class variables) */
s4 i;
void *a;
} value;
- /*--- XTA ---*/
- s4 fieldUsed; /* initialized to NOTUSED; set to USED when type checked */
- bool fieldChecked;
- classinfo *fldClassType;
- classSet *XTAclassSet; /* field class type set */
- s4 lastRoundChgd;
- /*--- VTA ---*/
- s4 VTAfieldUsed; /* -1=marked (might be used) 0=not used 1=used */
- classSetNode *VTAclassSet; /* field class type set */
-
-} ;
+ xtafldinfo *xta;
+};
struct basicblock;
/* methodinfo static info ****************************************************/
-/*typedef struct rtainfo {
+typedef struct xtainfo {
+ s4 XTAmethodUsed; /* XTA if used in callgraph - not used /used */
+ classSet *XTAclassSet; /* method class type set */
+ /*classSet *PartClassSet */ /* method class type set */
+
+ classSetNode *paramClassSet; /* cone set of methods parameters */
+
+ methSet *calls; /* methods this method calls */
+ methSet *calledBy; /* methods that call this method */
+ methSet *marked; /* 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;
-} rtainfo; */
/* methodinfo *****************************************************************/
-struct methodinfo { /* method structure */
- s4 flags; /* ACC flags */
+struct methodinfo { /* method structure */
+ s4 flags; /* ACC flags */
utf *name; /* name of method */
utf *descriptor; /* JavaVM descriptor string of method */
s4 returntype; /* only temporary valid, return type */
u1 *entrypoint; /* entry point in machine code */
/*rtainfo rta;*/
- /*xtainfo xta;*/
+ xtainfo *xta;
- s4 methodUsed; /* marked (might be used later) /not used /used */
- s4 monoPoly; /* call is mono or poly or unknown */ /*RT stats */
+ s4 methodUsed; /* marked (might be used later) /not used /used */
+ s4 monoPoly; /* call is mono or poly or unknown */ /*RT stats */
/* should # method def'd and used be kept after static parse (will it be used?) */
s4 subRedefs;
s4 subRedefsUsed;
-
- /* --- XTA --- */
- s4 XTAmethodUsed; /* XTA if used in callgraph - not used /used */
- classSet *XTAclassSet; /* method class type set */
- classSet *PartClassSet; /* method class type set */
-
- classSetNode *paramClassSet; /* cone set of methods parameters */
-
- methSet *calls; /* methods this method calls */
- methSet *calledBy; /* methods that call this method */
- methSet *marked; /* methods that marked by this method */
- methSet *markedBy;
- fldSet *fldsUsed; /* fields used by this method */
- bool chgdSinceLastParse; /* Changed since last parse ? */
-
- s4 lastRoundParsed; /* Last round parsed */
- methSetNode *interfaceCalls; /* methods this method calls as interface */
-
- /* --- VTA --- */
- classSetNode *VTAclassSet; /* method class type set */
- methSetNode *VTAcalls; /* methods this method calls */
- classSetNode **VTAlocalSets; /*VTA*/
- classSetNode **VTAstackType; /*VTA*/
};
struct classinfo { /* class structure */
java_objectheader header; /* classes are also objects */
+ java_objectarray* signers;
+ struct java_security_ProtectionDomain* pd;
+ 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 flags; /* ACC flags */
utf *name; /* class name */
listnode listnode; /* linkage */
bool initialized; /* true, if class already initialised */
+ bool loaded; /* true, if class already loaded */
bool linked; /* true, if class already linked */
s4 index; /* hierarchy depth (classes) or index
(interfaces) */
vftbl *vftbl; /* pointer to virtual function table */
methodinfo *finalizer; /* finalizer method */
-#ifdef JIT_MARKER_SUPPORT
- methodinfo *marker;
-#endif
u2 innerclasscount; /* number of inner classes */
innerclassinfo *innerclass;
classSetNode *impldBy; /* implemented by class set */
};
+/* check if class is an array class. Only use for linked classes! */
+#define CLASS_IS_ARRAY(clsinfo) (clsinfo->vftbl->arraydesc != NULL)
+
/* virtual function table ******************************************************
classinfo *class; /* class, the vtbl belongs to */
+ arraydescriptor *arraydesc; /* for array classes, otherwise NULL */
+
s4 vftbllength; /* virtual function table length */
s4 interfacetablelength; /* interface table length */
s4 baseval; /* base for runtime type check */
+ /* (-index for interfaces) */
s4 diffval; /* high - base for runtime type check */
s4 *interfacevftbllength; /* length of interface vftbls */
#define VFTBLINTERFACETABLE(v,i) (v)->interfacetable[-i]
+/* arraydescriptor ************************************************************
+
+ For every array class an arraydescriptor is allocated which
+ describes the array class.
+ The arraydescriptor is referenced from the vftbl of the array
+ class.
+
+*******************************************************************************/
+
+struct arraydescriptor {
+ vftbl *componentvftbl; /* vftbl of the component type, NULL for primit. */
+ vftbl *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 */
+};
+
/* 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_ArithmeticException;
extern classinfo *class_java_lang_ArrayStoreException;
extern classinfo *class_java_lang_ThreadDeath;
-extern classinfo *class_array;
+extern classinfo *pseudo_class_Arraystub;
+extern classinfo *pseudo_class_Null;
+extern vftbl *pseudo_class_Arraystub_vftbl;
/* instances of some system classes *******************************************/
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 int pClassHeir;
-extern int pCallgraph;
-extern int pOpcodes;
-extern int pStats;
+//extern int pClassHeir;
+//extern int pCallgraph;
+//extern int pOpcodes;
+//extern int pStats;
-extern void RT_jit_parse(methodinfo *m);
-extern void printCallgraph ();
-extern void printRThierarchyInfo(methodinfo *m);
-extern void printObjectClassHeirarchy();
-
-extern void XTA_jit_parse(methodinfo *m);
+//extern void RT_jit_parse(methodinfo *m);
/* statistic variables ********************************************************/
/* table of primitive types ***************************************************/
+/* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
+ * constants (except ARRAYTYPE_OBJECT).
+ */
extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
-#endif
+/* macros for descriptor parsing **********************************************/
+
+/* utf_ptr must point to the 'L' or the '[' 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.
+ */
+#define SKIP_FIELDDESCRIPTOR(utf_ptr) \
+ { while (*(utf_ptr)=='[') (utf_ptr)++; \
+ if (*(utf_ptr)++=='L') \
+ while(*(utf_ptr)++ != ';') /* skip */; }
+/* 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!
+ * Output:
+ * 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; }}
+
+
+#endif
/*
* These are local overrides for various environment variables in Emacs.