-/* 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: 1998/10/30
+ 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
-#ifndef __global_h_
-#define __global_h_
+ Authors: Reinhard Grafl
+ Andreas Krall
-#define OLD_COMPILER /* if enabled makes old compiler available */
+ Changes: Mark Probst
+ Philipp Tomsich
-#define STATISTICS /* if enabled collects program statistics */
+ $Id: global.h 557 2003-11-02 22:51:59Z twisti $
-/* JIT_MARKER_SUPPORT is the define used to toggle Just-in-time generated
- marker functions on and off.
*/
-#undef JIT_MARKER_SUPPORT /* phil */
-/* standard includes **********************************************************/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#ifndef _GLOBAL_H
+#define _GLOBAL_H
-#include "toolbox/memory.h"
-#include "toolbox/chain.h"
+#include "config.h"
+#include "types.h"
#include "toolbox/list.h"
-#include "toolbox/loging.h"
-/* system dependent types *****************************************************/
+#define _GNU_SOURCE
+
+#define STATISTICS /* if enabled collects program statistics */
-#include "sysdep/types.h"
+/*
+ * SIZE_FROM_CLASSINFO toggles between the bitmap_based and the new method
+ * of determining the sizes of objects on the heap.
+ */
+#define SIZE_FROM_CLASSINFO
/* additional data types ******************************************************/
#define true 1
#define false 0
+#define PRIMITIVETYPE_COUNT 9 /* number of primitive types */
+
typedef void (*functionptr) (); /* generic function pointer */
#define MAX_ALIGN 8 /* most generic alignment for JavaVM values */
-
/* shutdown function **********************************************************/
void cacao_shutdown(s4 status);
/* resolve typedef cycles *****************************************************/
-typedef struct unicode unicode;
+typedef struct utf utf;
+typedef struct literalstring literalstring;
typedef struct java_objectheader java_objectheader;
typedef struct classinfo classinfo;
typedef struct vftbl vftbl;
typedef u1* methodptr;
+typedef struct fieldinfo fieldinfo;
+typedef struct methodinfo methodinfo;
/* constant pool entries *******************************************************
*******************************************************************************/
-/* data structures of Unicode symbol *******************************************
+/* data structures for hashtables ********************************************
+
+
+ All utf-symbols, javastrings and classes are stored in global hashtables,
+ so every symbol exists only once. Equal symbols have identical pointers.
+ The functions for adding hashtable elements search the table for the
+ element with the specified name/text and return it on success. Otherwise a
+ new hashtable element is created.
+
+ The hashtables use external linking for handling collisions. The hashtable
+ structure contains a pointer <ptr> to the array of hashtable slots. The
+ number of hashtable slots and therefore the size of this array is specified
+ by the element <size> of hashtable structure. <entries> contains the number
+ of all hashtable elements stored in the table, including those in the
+ external chains.
+ The hashtable element structures (utf, literalstring, classinfo) contain
+ both a pointer to the next hashtable element as a link for the external hash
+ chain and the key of the element. The key is computed from the text of
+ the string or the classname by using up to 8 characters.
+
+ If the number of entries in the hashtable exceeds twice the size of the
+ hashtableslot-array it is supposed that the average length of the
+ external chains has reached a value beyond 2. Therefore the functions for
+ adding hashtable elements (utf_new, class_new, literalstring_new) double
+ the hashtableslot-array. In this restructuring process all elements have
+ to be inserted into the new hashtable and new external chains must be built.
+
+
+example for the layout of a hashtable:
+
+hashtable.ptr--> +-------------------+
+ | |
+ ...
+ | |
+ +-------------------+ +-------------------+ +-------------------+
+ | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
+ +-------------------+ +-------------------+ +-------------------+
+ | hashtable element |
+ +-------------------+ +-------------------+
+ | hashtable element |-->| hashtable element |-->NULL
+ +-------------------+ +-------------------+
+ | hashtable element |-->NULL
+ +-------------------+
+ | |
+ ...
+ | |
+ +-------------------+
- All Unicode symbols are stored in one global (hash) table, every symbol
- exists only once. Equal symbols have identical pointers.
*/
-struct unicode {
- unicode *hashlink; /* link for external hash chain */
- u4 key; /* hash key (computed from text) */
- int length; /* text length */
- u2 *text; /* pointer to text (each character is 16 Bit) */
- classinfo *class; /* class pointer if it exists, otherwise NULL */
- java_objectheader *string; /* string pointer if it exists, otherwise NULL*/
+
+/* data structure for utf8 symbols ********************************************/
+
+struct utf {
+ utf *hashlink; /* link for external hash chain */
+ int blength; /* text length in bytes */
+ char *text; /* pointer to text */
+};
+
+
+/* data structure of internal javastrings stored in global hashtable **********/
+
+struct literalstring {
+ literalstring *hashlink; /* link for external hash chain */
+ java_objectheader *string;
};
+/* data structure for accessing hashtables ************************************/
+
+typedef struct {
+ 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 */
+typedef struct { /* Fieldref, Methodref and InterfaceMethodref */
classinfo *class; /* class containing this field/method/interface */
- unicode *name; /* field/method/interface name */
- unicode *descriptor; /* field/method/interface type descriptor string */
+ utf *name; /* field/method/interface name */
+ 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) */
- unicode *name; /* field/method name */
- unicode *descriptor; /* field/method type descriptor string */
+ 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).
+
+/*
+ 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 {
typedef struct java_arrayheader { /* header for all arrays */
java_objectheader objheader; /* object header */
s4 size; /* array size */
+#ifdef SIZE_FROM_CLASSINFO
+ s4 alignedsize; /* phil */
+#endif
s4 arraytype; /* array type from previous list */
} java_arrayheader;
} java_arrayarray;
+/* structure for primitive classes ********************************************/
+
+typedef struct primitivetypeinfo {
+ classinfo *class_wrap; /* class for wrapping primitive type */
+ classinfo *class_primitive; /* primitive class */
+ char *wrapname; /* name of class for wrapping */
+ char typesig; /* one character type signature */
+ char *name; /* name of primitive 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 ******************************************************************/
-typedef struct fieldinfo {/* field of a class */
- s4 flags; /* ACC flags */
- s4 type; /* basic data type */
- unicode *name; /* name of field */
- unicode *descriptor; /* JavaVM descriptor string of field */
+struct fieldinfo { /* field of a class */
+ 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;
double d;
void *a;
} value;
+
+ xtafldinfo *xta;
+};
-} fieldinfo;
-
+struct basicblock;
/* exceptiontable *************************************************************/
+typedef struct xtable { /* exceptiontable entry in a method */
+ s4 startpc; /* start pc of guarded area (inclusive) */
+ struct basicblock *start;
+
+ s4 endpc; /* end pc of guarded area (exklusive) */
+ struct basicblock *end;
+
+ s4 handlerpc; /* pc of exception handler */
+ struct basicblock *handler;
+
+ classinfo *catchtype; /* catchtype of exception (NULL == catchall) */
+ struct xtable *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) */
} exceptiontable;
+/* methodinfo static info ****************************************************/
+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;
+
/* methodinfo *****************************************************************/
-typedef struct methodinfo { /* method structure */
+struct methodinfo { /* method structure */
s4 flags; /* ACC flags */
- unicode *name; /* name of method */
- unicode *descriptor; /* JavaVM descriptor string of method */
+ utf *name; /* name of method */
+ utf *descriptor; /* JavaVM descriptor string of method */
s4 returntype; /* only temporary valid, return type */
+ classinfo *returnclass; /* pointer to classinfo for the rtn type */ /*XTA*/
s4 paramcount; /* only temporary valid, parameter count */
u1 *paramtypes; /* only temporary valid, parameter types */
+ classinfo **paramclass; /* pointer to classinfo for a parameter */ /*XTA*/
+
classinfo *class; /* class, the method belongs to */
s4 vftblindex; /* index of method in virtual function table
(if it is a virtual method) */
u1 *jcode; /* pointer to JavaVM code */
s4 exceptiontablelength;/* exceptiontable length */
- exceptiontable *exceptiontable; /* the exceptiontable */
+ exceptiontable *exceptiontable;
+ /* the exceptiontable */
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 */
-} methodinfo;
+ /*rtainfo rta;*/
+ xtainfo *xta;
+
+ 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;
+};
+
+/* innerclassinfo *************************************************************/
+
+typedef struct innerclassinfo {
+ classinfo *inner_class; /* inner class pointer */
+ classinfo *outer_class; /* outer class pointer */
+ utf *name; /* innerclass name */
+ s4 flags; /* ACC flags */
+} innerclassinfo;
+
/* classinfo ******************************************************************/
struct classinfo { /* class structure */
java_objectheader header; /* classes are also objects */
s4 flags; /* ACC flags */
- unicode *name; /* class name */
+ utf *name; /* class name */
s4 cpcount; /* number of entries in constant pool */
u1 *cptags; /* constant pool tags */
bool initialized; /* true, if class already initialised */
bool linked; /* true, if class already linked */
- s4 index; /* hierarchy depth (classes) or index
+ s4 index; /* hierarchy depth (classes) or index
(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 */
methodinfo *finalizer; /* finalizer method */
-#ifdef JIT_MARKER_SUPPORT
- methodinfo *marker;
-#endif
+
+ u2 innerclasscount; /* number of inner classes */
+ innerclassinfo *innerclass;
+
+ classinfo *hashlink; /* link for external hash chain */
+ bool classvftbl; /* has its own copy of the Class vtbl */
+
+ s4 classUsed; /* 0= not used 1 = used CO-RT */
+
+ classSetNode *impldBy; /* implemented by class set */
};
extern classinfo *class_java_lang_ArithmeticException;
extern classinfo *class_java_lang_ArrayStoreException;
extern classinfo *class_java_lang_ThreadDeath;
-
extern classinfo *class_array;
-
/* instances of some system classes *******************************************/
extern java_objectheader *proto_java_lang_ClassCastException;
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 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);
/* statistic variables ********************************************************/
extern int count_class_infos;
extern int count_const_pool_len;
extern int count_vftbl_len;
-extern int count_unicode_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;
-#endif
+/* table of primitive types ***************************************************/
+
+extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
+
+#endif /* _GLOBAL_H */
/*