-/****************************** 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
- Chages: Andreas Krall EMAIL: cacao@complang.tuwien.ac.at
- Mark Probst 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: 1997/10/28
+ 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
-#ifndef __global_h_
-#define __global_h_ /* schani */
+ $Id: global.h 1326 2004-07-21 13:22:33Z twisti $
-#define STATISTICS /* andi */
+*/
-/***************************** 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 **************************/
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+#include <pthread.h>
+#endif
-#include "sysdep/types.h"
+#define STATISTICS /* if enabled collects program statistics */
+/*
+ * 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 ***************************/
+/*
+ * CACAO_TYPECHECK activates typechecking (part of bytecode verification)
+ */
+#define CACAO_TYPECHECK
-typedef void *voidptr; /* generic pointer */
+/*
+ * 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
+
+/*
+ * Macros for configuration of the typechecking code
+ *
+ * TYPECHECK_STATISTICS activates gathering statistical information.
+ * TYPEINFO_DEBUG activates debug checks and debug helpers in typeinfo.c
+ * TYPECHECK_DEBUG activates debug checks in typecheck.c
+ * TYPEINFO_DEBUG_TEST activates the typeinfo test at startup.
+ * TYPECHECK_VERBOSE_IMPORTANT activates important debug messages
+ * TYPECHECK_VERBOSE activates all debug messages
+ */
+#ifdef CACAO_TYPECHECK
+/*#define TYPECHECK_STATISTICS*/
+/*#define TYPEINFO_DEBUG*/
+/*#define TYPECHECK_DEBUG*/
+/*#define TYPEINFO_DEBUG_TEST*/
+/*#define TYPECHECK_VERBOSE*/
+/*#define TYPECHECK_VERBOSE_IMPORTANT*/
+#if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
+#define TYPECHECK_VERBOSE_OPT
+#endif
+#endif
-typedef u1 bool; /* boolean data type */
+/* additional data types ******************************************************/
+
+typedef void *voidptr; /* generic pointer */
+
+typedef int bool; /* boolean data type */
#define true 1
#define false 0
typedef void (*functionptr) (); /* generic function pointer */
-#define MAX_ALIGN 8 /* most generic alignment for JavaVM values */
+/* immediate data union */
+typedef union {
+ s4 i;
+ s8 l;
+ float f;
+ double d;
+ void *a;
+ u1 b[8];
+} imm_union;
+
+
+#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
-/**************************** shutdown function *******************************/
-void cacao_shutdown(s4 status);
+#define MAX_ALIGN 8 /* most generic alignment for JavaVM values */
-/**************************** 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 arbitrarily*/
+#define TYPE_ADDRESS 4 /* all other types can be numbered arbitrarly */
#define TYPE_VOID 10
-/**************************** Java class file constants ***********************/
+/* Java class file constants **************************************************/
#define MAGIC 0xcafebabe
-#define MINOR_VERSION 3
-#define MAJOR_VERSION 45
-
-#define CONSTANT_Class 7
-#define CONSTANT_Fieldref 9
-#define CONSTANT_Methodref 10
-#define CONSTANT_InterfaceMethodref 11
-#define CONSTANT_String 8
-#define CONSTANT_Integer 3
-#define CONSTANT_Float 4
-#define CONSTANT_Long 5
-#define CONSTANT_Double 6
-#define CONSTANT_NameAndType 12
-#define CONSTANT_Utf8 1
-
-#define CONSTANT_Arraydescriptor 13
-#define CONSTANT_UNUSED 0
-
+#define MINOR_VERSION 0
+#define MAJOR_VERSION 48
+
+#define CONSTANT_Class 7
+#define CONSTANT_Fieldref 9
+#define CONSTANT_Methodref 10
+#define CONSTANT_InterfaceMethodref 11
+#define CONSTANT_String 8
+#define CONSTANT_Integer 3
+#define CONSTANT_Float 4
+#define CONSTANT_Long 5
+#define CONSTANT_Double 6
+#define CONSTANT_NameAndType 12
+#define CONSTANT_Utf8 1
+
+#define CONSTANT_UNUSED 0
#define ACC_PUBLIC 0x0001
#define ACC_PRIVATE 0x0002
#define ACC_PROTECTED 0x0004
#define ACC_STATIC 0x0008
#define ACC_FINAL 0x0010
+#define ACC_SUPER 0x0020
#define ACC_SYNCHRONIZED 0x0020
#define ACC_VOLATILE 0x0040
#define ACC_TRANSIENT 0x0080
#define ACC_NATIVE 0x0100
#define ACC_INTERFACE 0x0200
#define ACC_ABSTRACT 0x0400
+#define ACC_STRICT 0x0800
+/* resolve typedef cycles *****************************************************/
-
-/**************************** 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 struct _vftbl vftbl_t;
typedef u1* methodptr;
+typedef struct fieldinfo fieldinfo;
+typedef struct exceptiontable exceptiontable;
+typedef struct methodinfo methodinfo;
+typedef struct lineinfo lineinfo;
+typedef struct arraydescriptor arraydescriptor;
+
+
+/* constant pool entries *******************************************************
+
+ All constant pool entries need a data structure which contain the entrys
+ value. In some cases this structure exist already, in the remaining cases
+ this structure must be generated:
+ kind structure generated?
+ ----------------------------------------------------------------------
+ CONSTANT_Class classinfo no
+ CONSTANT_Fieldref constant_FMIref yes
+ CONSTANT_Methodref constant_FMIref yes
+ CONSTANT_InterfaceMethodref constant_FMIref yes
+ CONSTANT_String unicode no
+ CONSTANT_Integer constant_integer yes
+ CONSTANT_Float constant_float yes
+ CONSTANT_Long constant_long yes
+ CONSTANT_Double constant_double yes
+ CONSTANT_NameAndType constant_nameandtype yes
+ CONSTANT_Utf8 unicode no
+ CONSTANT_UNUSED -
-/********************** data structures of UNICODE symbol *********************/
+*******************************************************************************/
-struct unicode {
- unicode *hashlink; /* externe Verkettung f"ur die unicode-Hashtabelle */
- u4 key; /* Hash-Schl"ussel (h"angt nur vom Text ab) */
- int length; /* L"ange des Textes */
- u2 *text; /* Zeiger auf den Text (jeder Buchstabe 16 Bit) */
- classinfo *class; /* gegebenenfalls Referenz auf die Klasse dieses
- Namens (oder NULL, wenn es keine solche gibt) */
- struct java_objectheader *string;
- /* gegebenenfalls Referenz auf einen konstanten
- String mit dem entsprechenden Wert */
+/* 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
+ +-------------------+
+ | |
+ ...
+ | |
+ +-------------------+
+
+*/
+
+
+/* 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 */
};
-/* Alle Unicode-Symbole werden in einer einzigen globalen Tabelle
- (Hashtabelle) verwaltet, jedes Symbol wird nur einmal angelegt.
- -> Speicherersparnis, und "Uberpr"ufung auf Gleichheit durch einfachen
- Zeigervergleich */
+/* data structure of internal javastrings stored in global hashtable **********/
-/************ data structures of remaining constant pool entries **************/
+struct literalstring {
+ literalstring *hashlink; /* link for external hash chain */
+ java_objectheader *string;
+};
-typedef struct {
- classinfo *class;
- unicode *name;
- unicode *descriptor;
+/* data structure for storing information needed for a stacktrace across native functions*/
+struct native_stackframeinfo {
+ void *oldThreadspecificHeadValue;
+ void **addressOfThreadspecificHead;
+ methodinfo *method;
+ void *returnToFromNative;
+
+#if 0
+ void *returnFromNative;
+ void *addrReturnFromNative;
+ methodinfo *method;
+ struct native_stackframeinfo *next;
+ struct native_stackframeinfo *prev;
+#endif
+};
+
+typedef struct native_stackframeinfo native_stackframeinfo;
+
+struct stacktraceelement {
+#if POINTERSIZE == 8
+ u8 linenumber;
+#else
+ u4 linenumber;
+#endif
+ methodinfo *method;
+};
+
+typedef struct stacktraceelement stacktraceelement;
+
+/* data structure for calls from c code to java methods */
+
+struct jni_callblock {
+ u8 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 */
+} hashtable;
+
+
+/* data structures of remaining constant pool entries *************************/
+
+typedef struct { /* Fieldref, Methodref and InterfaceMethodref */
+ classinfo *class; /* class containing this field/method/interface */
+ utf *name; /* field/method/interface name */
+ utf *descriptor; /* field/method/interface type descriptor string */
} constant_FMIref;
-typedef struct {
- s4 value;
+typedef struct { /* Integer */
+ s4 value;
} constant_integer;
+
-typedef struct {
- float value;
+typedef struct { /* Float */
+ float value;
} constant_float;
-typedef struct {
- s8 value;
+
+typedef struct { /* Long */
+ s8 value;
} constant_long;
-typedef struct {
- double value;
+
+typedef struct { /* Double */
+ double value;
} constant_double;
-typedef struct {
- unicode *name;
- unicode *descriptor;
+typedef struct { /* NameAndType (Field or Method) */
+ utf *name; /* field/method name */
+ utf *descriptor; /* field/method type descriptor string */
} constant_nameandtype;
-typedef struct constant_arraydescriptor {
- int arraytype;
- classinfo *objectclass;
- struct constant_arraydescriptor *elementdescriptor;
-} constant_arraydescriptor;
-
-/* Mit einem Arraydescriptor kann ein Array-Typ dargestellt werden.
- Bei normalen Arrays (z.B. Array von Bytes,...) gen"ugt dazu,
- dass das Feld arraytype die entsprechende Kennzahl enth"alt
- (z.B. ARRAYTYPE_BYTE).
- Bei Arrays von Objekten (arraytype=ARRAYTYPE_OBJECT) muss das
- Feld objectclass auf die Klassenstruktur der m"oglichen
- Element-Objekte zeigen.
- Bei Arrays von Arrays (arraytype=ARRAYTYPE_ARRAY) muss das
- Feld elementdescriptor auf eine weiter arraydescriptor-Struktur
- zeigen, die die Element-Typen beschreibt.
- */
-
-
-
-/********* Anmerkungen zum Constant-Pool:
-
- Die Typen der Eintr"age in den Constant-Pool werden durch die oben
- definierten CONSTANT_.. Werte angegeben.
- Bei allen Typen muss zus"atzlich noch eine Datenstruktur hinzugef"ugt
- werden, die den wirklichen Wert angibt.
- Bei manchen Typen reicht es, einen Verweis auf eine schon bereits
- existierende Struktur (z.B. unicode-Texte) einzutragen, bei anderen
- muss diese Struktur erst extra erzeugt werden.
- Ich habe folgende Datenstrukturen f"ur diese Typen verwendet:
-
- Typ Struktur extra erzeugt?
- ----------------------------------------------------------------------
- CONSTANT_Class classinfo nein
- CONSTANT_Fieldref constant_FMIref ja
- CONSTANT_Methodref constant_FMIref ja
- CONSTANT_InterfaceMethodref constant_FMIref ja
- CONSTANT_String unicode nein
- CONSTANT_Integer constant_integer ja
- CONSTANT_Float constant_float ja
- CONSTANT_Long constant_long ja
- CONSTANT_Double constant_double ja
- CONSTANT_NameAndType constant_nameandtype ja
- CONSTANT_Utf8 unicode nein
- CONSTANT_Arraydescriptor constant_arraydescriptor ja
- CONSTANT_UNUSED -
-
-*******************************/
-
-
-
-/***************** Die Datenstrukturen fuer das Laufzeitsystem ***************/
+/* data structures of the runtime system **************************************/
+/* objects *********************************************************************
- /********* Objekte **********
+ All objects (and arrays) which resides on the heap need the following
+ header at the beginning of the data structure.
+*/
- Alle Objekte (und Arrays), die am Heap gespeichert werden, m"ussen eine
- folgende spezielle Datenstruktur ganz vorne stehen haben:
+struct java_objectheader { /* header for all objects */
+ vftbl_t *vftbl; /* pointer to virtual function table */
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+ long monitorBits;
+#endif
+};
- */
-typedef struct java_objectheader { /* Der Header f"ur alle Objekte */
- vftbl *vftbl; /* Zeiger auf die Function Table */
-} java_objectheader;
+/* arrays **********************************************************************
+ 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.
+*/
-/********* Arrays ***********
-
- Alle Arrays in Java sind auch gleichzeitig Objekte (d.h. sie haben auch
- den obligatorischen Object-Header und darin einen Verweis auf eine Klasse)
- Es gibt aber (der Einfachheit halber) nur eine einzige Klasse f"ur alle
- m"oglichen Typen von Arrays, deshalb wird der tats"achliche Typ in einem
- Feld im Array-Objekt selbst gespeichert.
- Die Typen sind: */
-
-#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
-
-
-/** Der Header f"ur ein Java-Array **/
-
-typedef struct java_arrayheader { /* Der Arrayheader f"ur alle Arrays */
- java_objectheader objheader; /* Der Object-Header */
- s4 size; /* Gr"osse des Arrays */
- s4 arraytype; /* Typ der Elemente */
+/* 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 */
+ s4 size; /* array size */
+#ifdef SIZE_FROM_CLASSINFO
+ s4 alignedsize; /* phil */
+#endif
} java_arrayheader;
-/** Die Unterschiedlichen Strukturen f"ur alle Typen von Arrays **/
+/* structs for all kinds of arrays ********************************************/
typedef struct java_chararray {
- java_arrayheader header;
- u2 data[1];
+ java_arrayheader header;
+ u2 data[1];
} java_chararray;
typedef struct java_floatheader {
- java_arrayheader header;
- float data[1];
+ java_arrayheader header;
+ float data[1];
} java_floatarray;
typedef struct java_doublearray {
- java_arrayheader header;
- double data[1];
+ java_arrayheader header;
+ double data[1];
} java_doublearray;
-
-/* achtung: die beiden Stukturen booleanarray und bytearray m"ussen
- identisches memory-layout haben, weil mit den selben Funktionen
- darauf zugegriffen wird */
+/* booleanarray and bytearray need identical memory layout (access methods
+ use the same machine code */
typedef struct java_booleanarray {
- java_arrayheader header;
- u1 data[1];
+ java_arrayheader header;
+ u1 data[1];
} java_booleanarray;
typedef struct java_bytearray {
- java_arrayheader header;
- s1 data[1];
+ java_arrayheader header;
+ s1 data[1];
} java_bytearray;
typedef struct java_shortarray {
- java_arrayheader header;
- s2 data[1];
+ java_arrayheader header;
+ s2 data[1];
} java_shortarray;
typedef struct java_intarray {
- java_arrayheader header;
- s4 data[1];
+ java_arrayheader header;
+ s4 data[1];
} java_intarray;
typedef struct java_longarray {
- java_arrayheader header;
- s8 data[1];
+ java_arrayheader header;
+ s8 data[1];
} java_longarray;
-
-/* ACHTUNG: die beiden folgenden Strukturen m"ussen unbedingt gleiches
- Memory-Layout haben, weil mit ein und der selben Funktion auf die
- data-Eintr"age beider Typen zugegriffen wird !!!! */
+/* objectarray and arrayarray need identical memory layout (access methods
+ use the same machine code */
typedef struct java_objectarray {
- java_arrayheader header;
- classinfo *elementtype;
- java_objectheader *data[1];
+ java_arrayheader header;
+ 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 {
+ 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 */
+ char *arrayname; /* name of primitive array class */
+ classinfo *arrayclass; /* primitive array class */
+ vftbl_t *arrayvftbl; /* vftbl of primitive array class */
+} primitivetypeinfo;
-/************** Strukturen f"ur Klassen, Felder & Methoden *****************/
+/* field, method and class structures *****************************************/
+#include "jit/sets.h"
+typedef struct xtafldinfo {
+ bool fieldChecked;
+ classinfo *fldClassType;
+ classSet *XTAclassSet; /* field class type set */
+} xtafldinfo;
- /*** Struktur: fieldinfo ***/
-typedef struct fieldinfo { /* Struktur f"ur ein Feld einer Klasse */
- s4 flags; /* die ACC-Flags */
- s4 type; /* Grunddatentyp */
- unicode *name; /* Name des Felds */
- unicode *descriptor; /* Typedescriptor in JavaVM-Form */
+/* fieldinfo ******************************************************************/
+
+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 vom Anfang des Objektes */
- /* (bei Instanzvariablen) */
+ s4 offset; /* offset from start of object (instance variables) */
- union { /* Speicher f"ur den Wert */
- s4 i; /* (bei Klassenvariablen) */
- s8 l;
- float f;
- double d;
- void *a;
- } value;
-
-} fieldinfo;
+ imm_union value; /* storage for static values (class variables) */
+ classinfo *class; /* needed by typechecker. Could be optimized */
+ /* away by using constant_FMIref instead of */
+ /* fieldinfo throughout the compiler. */
+
+ xtafldinfo *xta;
+};
-/*** Struktur: exceptiontable ***/
-typedef struct exceptiontable { /* Exceptionhandler-Eintrag in einer Methode */
- s4 startpc; /* Anfang des G"ultigkeitsbereichs */
- s4 endpc; /* Ende des Bereichs (exklusive) */
- s4 handlerpc; /* JavaVM-Position des Handlers */
- classinfo *catchtype; /* Typ der behandelten Exceptions (oder
- NULL, wenn alle behandelt werden sollen) */
-} exceptiontable;
+/* exceptiontable *************************************************************/
+struct exceptiontable { /* 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;
-/*** Struktur: methodinfo ***/
+ s4 handlerpc; /* pc of exception handler */
+ struct basicblock *handler;
-typedef struct methodinfo { /* Struktur f"ur eine Methode einer Klasse */
- s4 flags; /* die ACC-Flags */
- unicode *name; /* Name der Methode */
- unicode *descriptor; /* der JavaVM-Descriptorstring f"ur Methoden */
- s4 returntype; /* only temporary valid, return type */
- s4 paramcount; /* only temporary valid, number of parameters */
- u1 *paramtypes; /* only temporary valid, parameter types */
- classinfo *class; /* Die Klasse, der die Methode geh"ort */
- u4 vftblindex; /* Index dieser Methode f"ur die Virtual
- Function Table (wenn es keine statische
- Methode ist) */
+ classinfo *catchtype; /* catchtype of exception (NULL == catchall) */
+ exceptiontable *next; /* used to build a list of exception when */
+ /* loops are copied */
+ exceptiontable *down; /* instead of the old array, a list is used */
+};
- s4 maxstack; /* maximale Stacktiefe des JavaVM-Codes */
- s4 maxlocals; /* maximale Anzahl der JavaVM-Variablen */
- u4 jcodelength; /* L"ange des JavaVM-Codes */
- u1 *jcode; /* und Zeiger auf den JavaVM-Code */
- s4 exceptiontablelength; /* L"ange der Exceptintable */
- exceptiontable *exceptiontable; /* Die Exceptiontable selber */
+/* methodinfo static info ****************************************************/
- u1 *stubroutine; /* STUB-Routine for compiling or calling
- natives */
- u4 mcodelength; /* L"ange des generierten Maschinencodes */
- u1 *mcode; /* Zeiger auf den Maschinencode */
- u1 *entrypoint; /* Entrypoint to the Maschine-Code */
-} methodinfo;
+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 */
-/*** Struktur: classinfo ***/
+ methSet *calls; /* methods this method calls */
+ methSet *calledBy; /* methods that call this method */
+ methSet *marked; //not in Dez /* 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;
-struct classinfo { /* Datenstruktur f"ur eine Klasse */
- java_objectheader header; /* Weil auch Klassen als Objekte angesprochen
- werden */
- s4 flags; /* Die ACC-Flags */
- unicode *name; /* Name der Klasse */
-
- s4 cpcount; /* Anzahl der Eintr"age im Constant-Pool */
- u1 *cptags; /* Die TAGs f"ur den Constant-Pool */
- voidptr *cpinfos; /* Die Zeiger auf die Info-Strukturen */
-
- classinfo *super; /* Zeiger auf die "ubergeordnete Klasse */
-
- s4 interfacescount; /* Anzahl der Interfaces */
- classinfo **interfaces; /* Zeiger auf die Interfaces */
-
- s4 fieldscount; /* Anzahl der Felder */
- fieldinfo *fields; /* Die Tabelle der Felder */
-
- s4 methodscount; /* Anzahl der Methoden */
- methodinfo *methods; /* Die Tabelle der Methoden */
-
-
- listnode listnode; /* Verkettungsstruktur (f"ur Listen) */
+/* lineinfo *****************************************************************/
+
+struct lineinfo {
+ u2 start_pc;
+ u2 line_number;
+};
+
+
+/* methodinfo *****************************************************************/
+
+struct methodinfo { /* method structure */
+ java_objectheader header; /* we need this in jit's monitorenter */
+ s4 flags; /* ACC flags */
+ 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*/
+
+ bool isleafmethod; /* does method call subroutines */
+
+ classinfo *class; /* class, the method belongs to */
+ s4 vftblindex; /* index of method in virtual function table
+ (if it is a virtual method) */
+ s4 maxstack; /* maximum stack depth of method */
+ s4 maxlocals; /* maximum number of local variables */
+ s4 jcodelength; /* length of JavaVM code */
+ u1 *jcode; /* pointer to JavaVM code */
+
+ s4 basicblockcount; /* number of basic blocks */
+ struct basicblock *basicblocks; /* points to basic block array */
+ s4 *basicblockindex; /* a table which contains for every byte */
+ /* of JavaVM code a basic block index if */
+ /* at this byte is the start of a basic */
+ /* block */
+
+ s4 instructioncount; /* number of JavaVM instructions */
+ struct instruction *instructions; /* points to intermediate code instructions */
+
+ s4 stackcount; /* number of stack elements */
+ struct stackelement *stack; /* points to intermediate code instructions */
+
+ s4 exceptiontablelength;/* exceptiontable length */
+ exceptiontable *exceptiontable; /* the exceptiontable */
+
+ u2 thrownexceptionscount;/*number of exceptions declared to be thrown by a method*/
+ classinfo **thrownexceptions; /*array of classinfos of declared exceptions*/
+
+ u2 linenumbercount; /* number of linenumber attributes */
+ lineinfo *linenumbers; /* array of lineinfo items */
+
+ struct registerdata *registerdata; /* struct with all regalloc stuff */
+
+ struct codegendata *codegendata;/* struct with codegen stuff */
+
+ 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 */
+
+ /*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;
+ s4 nativelyoverloaded; /*used in header.c and only valid there*/
+};
+
+
+/* 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 */
+ 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 */
+
+ s4 cpcount; /* number of entries in constant pool */
+ u1 *cptags; /* constant pool tags */
+ voidptr *cpinfos; /* pointer to constant pool info structures */
+
+ classinfo *super; /* super class pointer */
+ classinfo *sub; /* sub class pointer */
+ classinfo *nextsub; /* pointer to next class in sub class list */
+
+ s4 interfacescount; /* number of interfaces */
+ classinfo **interfaces; /* pointer to interfaces */
+
+ s4 fieldscount; /* number of fields */
+ fieldinfo *fields; /* field table */
- bool initialized; /* true, wenn Klasse bereits Initialisiert */
- bool linked; /* wird von `class_link` auf true gesetzt */
- s4 index; /* Hierarchietiefe (bei normalen Klassen)
- oder fortlaufende Nummer (bei Interfaces)*/
- u4 instancesize; /* Gr"osse eines Objektes dieser Klasse */
+ s4 methodscount; /* number of methods */
+ methodinfo *methods; /* method table */
- vftbl *vftbl;
+ listnode listnode; /* linkage */
- methodinfo* finalizer; /* Finalizer-Methode f"ur die Klasse */
-#ifdef JIT_MARKER_SUPPORT
- methodinfo* marker;
+ bool initialized; /* true, if class already initialised */
+ bool initializing; /* flag for the compiler */
+ bool loaded; /* true, if class already loaded */
+ bool linked; /* true, if class already linked */
+ 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_t *vftbl; /* pointer to virtual function table */
+
+ methodinfo *finalizer; /* finalizer method */
+
+ 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 */
+ utf *packagename; /* full name of the package */
+ utf *sourcefile; /* classfile name containing this class */
+ java_objectheader *classloader; /* 0 for bootstrap classloader */
};
+
+/* check if class is an array class. Only use for linked classes! */
+#define CLASS_IS_ARRAY(clsinfo) ((clsinfo)->vftbl->arraydesc != NULL)
+
+
+/* virtual function table ******************************************************
+
+ The vtbl has a bidirectional layout with open ends at both sides.
+ interfacetablelength gives the number of entries of the interface table at
+ the start of the vftbl. The vftbl pointer points to &interfacetable[0].
+ vftbllength gives the number of entries of table at the end of the vftbl.
+
+ runtime type check (checkcast):
+
+ Different methods are used for runtime type check depending on the
+ argument of checkcast/instanceof.
+ A check against a class is implemented via relative numbering on the class
+ hierachy tree. The tree is numbered in a depth first traversal setting
+ the base field and the diff field. The diff field gets the result of
+ (high - base) so that a range check can be implemented by an unsigned
+ compare. A sub type test is done by checking the inclusion of base of
+ the sub class in the range of the superclass.
+
+ A check against an interface is implemented via the interfacevftbl. If the
+ interfacevftbl contains a nonnull value a class is a subclass of this
+ interface.
+
+ interfacetable:
+
+ Like standard virtual methods interface methods are called using
+ virtual function tables. All interfaces are numbered sequentially
+ (starting with zero). For each class there exist an interface table
+ of virtual function tables for each implemented interface. The length
+ of the interface table is determined by the highest number of an
+ implemented interface.
+
+ The following example assumes a class which implements interface 0 and 3:
+
+ interfacetablelength = 4
+
+ | ... | +----------+
+ +-----------+ | method 2 |---> method z
+ | class | | method 1 |---> method y
+ +-----------+ | method 0 |---> method x
+ | ivftbl 0 |----------> +----------+
+ vftblptr ---> +-----------+
+ | ivftbl -1 |--> NULL +----------+
+ | ivftbl -2 |--> NULL | method 1 |---> method x
+ | ivftbl -3 |-----+ | method 0 |---> method a
+ +-----------+ +----> +----------+
+
+ +---------------+
+ | length 3 = 2 |
+ | length 2 = 0 |
+ | length 1 = 0 |
+ | length 0 = 3 |
+ interfacevftbllength ---> +---------------+
+
+*******************************************************************************/
+
+struct _vftbl {
+ methodptr *interfacetable[1]; /* interface table (access via macro) */
-struct vftbl {
- classinfo *class; /* Class, the function table belongs to */
+ classinfo *class; /* class, the vtbl belongs to */
- s4 vftbllength; /* L"aenge der Virtual Function Table */
+ arraydescriptor *arraydesc; /* for array classes, otherwise NULL */
- s4 interfacetablelength; /* L"ange der Interfacetable */
- u4 *interfacevftbllength; /* -> siehe unten */
- methodptr **interfacevftbl;
+ 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 */
- methodptr table[1];
+ methodptr table[1]; /* class vftbl */
+};
+
+#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_t *componentvftbl; /* vftbl of the component type, NULL for primit. */
+ vftbl_t *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 */
+ short elementtype; /* ARRAYTYPE_* constant */
};
-/*********** Anmerkungen zur Interfacetable:
-
- "Ahnlich wie die 'normalen' virtuellen Methoden k"onnen auch die
- Interface-Methoden mit Hilfe einer Art Virtual Function Table
- aufgerufen werden.
- Dazu werden alle Interfaces im System fortlaufend nummeriert (beginnend
- bei 0), und f"ur jede Klasse wird eine ganze Tabelle von
- Virtual Function Tables erzeugt, n"amlich zu jedem Interface, das die
- Klasse implementiert, eine.
-
- z.B. Nehmen wir an, eine Klasse implementiert zwei Interfaces (die durch
- die Nummerierung die Indizes 0 und 3 bekommen haben)
-
- Das sieht dann ungef"ahr so aus:
- -------------- -------------
- interfacevftbl ---> | Eintrag 0 |---------> | Methode 0 |---> Methode X
- | Eintrag 1 |--> NULL | Methode 1 |---> Methode Y
- | Eintrag 2 |--> NULL | Methode 2 |---> Methode Z
- | Eintrag 3 |-----+ -------------
- -------------- |
- +---> -------------
- | Methode 0 |---> Methode X
- | Methode 1 |---> Methode A
- -------------
- ---------------
- interfacevftlblength ---> | Wert 0 = 3 |
- | Wert 1 = 0 |
- | Wert 2 = 0 |
- | Wert 3 = 2 |
- ---------------
-
- Der Aufruf einer Interface-Methode geht dann so vor sich:
- Zur Compilezeit steht der Index (i) des Interfaces und die Stelle (s), wo
- in der entsprechenden Untertabelle die Methode eingetragen ist, schon fest.
- Also muss zur Laufzeit nur mehr der n-te Eintrag aus der Interfacetable
- gelesen werden, von dieser Tabelle aus wird der s-te Eintrag geholt,
- und diese Methode wird angesprungen.
-
-****************/
-
-
-
-/************************* Referenzen auf die wichtigen Systemklassen ********************/
-
-extern classinfo *class_java_lang_Object;
-extern classinfo *class_java_lang_String;
-extern classinfo *class_java_lang_ClassCastException;
-extern classinfo *class_java_lang_NullPointerException;
-extern classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
-extern classinfo *class_java_lang_NegativeArraySizeException;
-extern classinfo *class_java_lang_OutOfMemoryError;
-extern classinfo *class_java_lang_ArithmeticException;
-extern classinfo *class_java_lang_ArrayStoreException;
-extern classinfo *class_java_lang_ThreadDeath; /* schani */
-
-extern classinfo *class_array;
-
-
-/********************** Vorgefertigte Instanzen einiger Systemklassen ********************/
-
-extern java_objectheader *proto_java_lang_ClassCastException;
-extern java_objectheader *proto_java_lang_NullPointerException;
-extern java_objectheader *proto_java_lang_ArrayIndexOutOfBoundsException;
-extern java_objectheader *proto_java_lang_NegativeArraySizeException;
-extern java_objectheader *proto_java_lang_OutOfMemoryError;
-extern java_objectheader *proto_java_lang_ArithmeticException;
-extern java_objectheader *proto_java_lang_ArrayStoreException;
-extern java_objectheader *proto_java_lang_ThreadDeath; /* schani */
-
-
-/********************** flag variables *********************/
-
-extern bool compileall;
-extern bool runverbose;
-extern bool verbose;
-
-
-/********************** trace 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_all_methods;
-extern int count_vmcode_len;
-extern int count_extable_len;
+/* flag variables *************************************************************/
+
+extern bool cacao_initializing;
+
+#ifdef TYPECHECK_VERBOSE_OPT
+extern bool typecheckverbose;
+#endif
+
+/*extern int pClassHeir;*/
+/*extern int pCallgraph;*/
+/*extern int pOpcodes;*/
+/*extern int pStats;*/
+
+/*extern void RT_jit_parse(methodinfo *m);*/
+
+
+/* table of primitive types ***************************************************/
+
+/* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
+ * constants (except ARRAYTYPE_OBJECT).
+ */
+extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
+
+
+/* macros for descriptor parsing **********************************************/
+
+/* SKIP_FIELDDESCRIPTOR:
+ * utf_ptr must point to the first character 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. Better use SKIP_FIELDDESCRIPTOR_SAFE.
+ */
+#define SKIP_FIELDDESCRIPTOR(utf_ptr) \
+ do { while (*(utf_ptr)=='[') (utf_ptr)++; \
+ if (*(utf_ptr)++=='L') \
+ while(*(utf_ptr)++ != ';') /* skip */; } while(0)
+
+/* SKIP_FIELDDESCRIPTOR_SAFE:
+ * utf_ptr must point to the first character of a field descriptor.
+ * After the macro call utf_ptr points to the first character after
+ * the field descriptor.
+ *
+ * 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) \
+ do { 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; }} while(0)
+
+
+/* Synchronization ************************************************************/
+
+#if defined(USE_THREADS) && defined(NATIVE_THREADS)
+void cast_lock();
+void cast_unlock();
+void compiler_lock();
+void compiler_unlock();
#endif
+#endif /* _GLOBAL_H */
+
/*
* These are local overrides for various environment variables in Emacs.