9edecdf37f596027c5f00ef2ced5e2d9c38969a6
[cacao.git] / src / vm / global.h
1 /* global.h - global definitions
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28             Andreas Krall
29
30    Changes: Mark Probst
31             Philipp Tomsich
32                         Edwin Steiner
33
34    $Id: global.h 1187 2004-06-19 12:26:33Z twisti $
35
36 */
37
38
39 #ifndef _GLOBAL_H
40 #define _GLOBAL_H
41
42
43 #include "config.h"
44 #include "types.h"
45 #include "toolbox/list.h"
46
47
48 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
49 #include <pthread.h>
50 #endif
51
52 #define STATISTICS          /* if enabled collects program statistics         */
53
54 /* 
55  * SIZE_FROM_CLASSINFO toggles between the bitmap_based and the new method 
56  * of determining the sizes of objects on the heap.
57  */
58 #define SIZE_FROM_CLASSINFO
59
60 /*
61  * CACAO_TYPECHECK activates typechecking (part of bytecode verification)
62  */
63 #define CACAO_TYPECHECK
64
65 /*
66  * TYPECHECK_STACK_COMPCAT activates full checking of computational
67  * categories for stack manipulations (POP,POP2,SWAP,DUP,DUP2,DUP_X1,
68  * DUP2_X1,DUP_X2,DUP2_X2).
69  */
70 /* #define TYPECHECK_STACK_COMPCAT */
71
72 /*
73  * Macros for configuration of the typechecking code
74  *
75  * TYPECHECK_STATISTICS activates gathering statistical information.
76  * TYPEINFO_DEBUG activates debug checks and debug helpers in typeinfo.c
77  * TYPECHECK_DEBUG activates debug checks in typecheck.c
78  * TYPEINFO_DEBUG_TEST activates the typeinfo test at startup.
79  * TYPECHECK_VERBOSE_IMPORTANT activates important debug messages
80  * TYPECHECK_VERBOSE activates all debug messages
81  */
82 #ifdef CACAO_TYPECHECK
83 /*#define TYPECHECK_STATISTICS*/
84 /*#define TYPEINFO_DEBUG*/
85 /*#define TYPECHECK_DEBUG*/
86 /*#define TYPEINFO_DEBUG_TEST*/
87 /*#define TYPECHECK_VERBOSE*/
88 /*#define TYPECHECK_VERBOSE_IMPORTANT*/
89 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
90 #define TYPECHECK_VERBOSE_OPT
91 #endif
92 #endif
93
94
95 /* additional data types ******************************************************/
96
97 typedef void *voidptr;          /* generic pointer */
98
99 typedef int   bool;             /* boolean data type */
100
101 #define true  1
102 #define false 0
103
104
105 /* immediate data union */
106
107 typedef union {
108     s4 i;
109     s8 l;
110     float f;
111     double d;
112     void *a;
113     u1 b[8];
114 } imm_union;
115
116
117 #define PRIMITIVETYPE_COUNT  9  /* number of primitive types */
118
119 /* CAUTION: Don't change the numerical values! These constants are
120  * used as indices into the primitive type table.
121  */
122 #define PRIMITIVETYPE_INT     0
123 #define PRIMITIVETYPE_LONG    1
124 #define PRIMITIVETYPE_FLOAT   2
125 #define PRIMITIVETYPE_DOUBLE  3
126 #define PRIMITIVETYPE_BYTE    4
127 #define PRIMITIVETYPE_CHAR    5
128 #define PRIMITIVETYPE_SHORT   6
129 #define PRIMITIVETYPE_BOOLEAN 7
130 #define PRIMITIVETYPE_VOID    8
131
132 typedef void (*functionptr) (); /* generic function pointer */
133
134
135 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
136
137
138 /* basic data types ***********************************************************/
139
140 /* CAUTION: jit/jit.h relies on these numerical values! */
141 #define TYPE_INT      0         /* the JavaVM types must numbered in the      */
142 #define TYPE_LONG     1         /* same order as the ICMD_Ixxx to ICMD_Axxx   */
143 #define TYPE_FLOAT    2         /* instructions (LOAD and STORE)              */
144 #define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
145 #define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
146
147 #define TYPE_VOID    10
148
149
150 /* Java class file constants **************************************************/
151
152 #define MAGIC         0xcafebabe
153 #define MINOR_VERSION 0
154 #define MAJOR_VERSION 48
155
156 #define CONSTANT_Class                 7
157 #define CONSTANT_Fieldref              9
158 #define CONSTANT_Methodref            10
159 #define CONSTANT_InterfaceMethodref   11
160 #define CONSTANT_String                8
161 #define CONSTANT_Integer               3
162 #define CONSTANT_Float                 4
163 #define CONSTANT_Long                  5
164 #define CONSTANT_Double                6
165 #define CONSTANT_NameAndType          12
166 #define CONSTANT_Utf8                  1
167
168 #define CONSTANT_UNUSED                0
169
170 #define ACC_PUBLIC                0x0001
171 #define ACC_PRIVATE               0x0002
172 #define ACC_PROTECTED             0x0004
173 #define ACC_STATIC                0x0008
174 #define ACC_FINAL                 0x0010
175 #define ACC_SUPER                 0x0020
176 #define ACC_SYNCHRONIZED          0x0020
177 #define ACC_VOLATILE              0x0040
178 #define ACC_TRANSIENT             0x0080
179 #define ACC_NATIVE                0x0100
180 #define ACC_INTERFACE             0x0200
181 #define ACC_ABSTRACT              0x0400
182 #define ACC_STRICT                0x0800
183
184 /* resolve typedef cycles *****************************************************/
185
186 typedef struct utf utf;
187 typedef struct literalstring literalstring;
188 typedef struct java_objectheader java_objectheader; 
189 typedef struct classinfo classinfo; 
190 typedef struct vftbl vftbl;
191 typedef u1* methodptr;
192 typedef struct fieldinfo  fieldinfo; 
193 typedef struct methodinfo methodinfo; 
194 typedef struct lineinfo lineinfo; 
195 typedef struct arraydescriptor arraydescriptor;
196
197
198 /* constant pool entries *******************************************************
199
200         All constant pool entries need a data structure which contain the entrys
201         value. In some cases this structure exist already, in the remaining cases
202         this structure must be generated:
203
204                 kind                      structure                     generated?
205         ----------------------------------------------------------------------
206     CONSTANT_Class               classinfo                           no
207     CONSTANT_Fieldref            constant_FMIref                    yes
208     CONSTANT_Methodref           constant_FMIref                    yes
209     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
210     CONSTANT_String              unicode                             no
211     CONSTANT_Integer             constant_integer                   yes
212     CONSTANT_Float               constant_float                     yes
213     CONSTANT_Long                constant_long                      yes
214     CONSTANT_Double              constant_double                    yes
215     CONSTANT_NameAndType         constant_nameandtype               yes
216     CONSTANT_Utf8                unicode                             no
217     CONSTANT_UNUSED              -
218
219 *******************************************************************************/
220
221 /* data structures for hashtables ********************************************
222
223
224         All utf-symbols, javastrings and classes are stored in global hashtables,
225         so every symbol exists only once. Equal symbols have identical pointers.
226         The functions for adding hashtable elements search the table for the 
227         element with the specified name/text and return it on success. Otherwise a 
228         new hashtable element is created.
229
230     The hashtables use external linking for handling collisions. The hashtable 
231         structure contains a pointer <ptr> to the array of hashtable slots. The 
232         number of hashtable slots and therefore the size of this array is specified 
233         by the element <size> of hashtable structure. <entries> contains the number
234         of all hashtable elements stored in the table, including those in the 
235         external chains.
236         The hashtable element structures (utf, literalstring, classinfo) contain
237         both a pointer to the next hashtable element as a link for the external hash 
238         chain and the key of the element. The key is computed from the text of
239         the string or the classname by using up to 8 characters.
240         
241         If the number of entries in the hashtable exceeds twice the size of the 
242         hashtableslot-array it is supposed that the average length of the 
243         external chains has reached a value beyond 2. Therefore the functions for
244         adding hashtable elements (utf_new, class_new, literalstring_new) double
245         the hashtableslot-array. In this restructuring process all elements have
246         to be inserted into the new hashtable and new external chains must be built.
247
248
249 example for the layout of a hashtable:
250
251 hashtable.ptr-->  +-------------------+
252                   |                   |
253                            ...
254                   |                   |
255                   +-------------------+   +-------------------+   +-------------------+
256                   | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
257                   +-------------------+   +-------------------+   +-------------------+
258                   | hashtable element |
259                   +-------------------+   +-------------------+   
260                   | hashtable element |-->| hashtable element |-->NULL
261                   +-------------------+   +-------------------+   
262                   | hashtable element |-->NULL
263                   +-------------------+
264                   |                   |
265                            ...
266                   |                   |
267                   +-------------------+
268
269 */
270
271
272 /* data structure for utf8 symbols ********************************************/
273
274 struct utf {
275         utf        *hashlink;       /* link for external hash chain               */
276         int         blength;        /* text length in bytes                       */           
277         char       *text;           /* pointer to text                            */
278 };
279
280
281 /* data structure of internal javastrings stored in global hashtable **********/
282
283 struct literalstring {
284         literalstring     *hashlink;     /* link for external hash chain          */
285         java_objectheader *string;  
286 };
287
288
289 /* data structure for storing information needed for a stacktrace across native functions*/
290 struct native_stackframeinfo {
291         void *oldThreadspecificHeadValue;
292         void **addressOfThreadspecificHead;
293         methodinfo *method;
294         void *returnToFromNative;
295
296 #if 0
297         void *returnFromNative;
298         void *addrReturnFromNative;
299         methodinfo *method;
300         struct native_stackframeinfo *next;
301         struct native_stackframeinfo *prev;
302 #endif
303 };
304
305 typedef struct native_stackframeinfo native_stackframeinfo;
306
307 struct stacktraceelement {
308 #if POINTERSIZE == 8
309         u8 linenumber;
310 #else
311         u4 linenumber;
312 #endif
313         methodinfo *method;
314 };
315
316 typedef struct stacktraceelement stacktraceelement;
317
318 /* data structure for calls from c code to java methods */
319
320 struct jni_callblock {
321         u8 itemtype;
322         u8 item;
323 };
324
325 typedef struct jni_callblock jni_callblock;
326
327
328 /* data structure for accessing hashtables ************************************/
329
330 typedef struct {            
331         u4 size;
332         u4 entries;        /* number of entries in the table */
333         void **ptr;        /* pointer to hashtable */
334 } hashtable;
335
336
337 /* data structures of remaining constant pool entries *************************/
338
339 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
340         classinfo *class;       /* class containing this field/method/interface   */
341         utf       *name;        /* field/method/interface name                    */
342         utf       *descriptor;  /* field/method/interface type descriptor string  */
343 } constant_FMIref;
344
345
346 typedef struct {            /* Integer                                        */
347         s4 value;
348 } constant_integer;
349
350         
351 typedef struct {            /* Float                                          */
352         float value;
353 } constant_float;
354
355
356 typedef struct {            /* Long                                           */
357         s8 value;
358 } constant_long;
359         
360
361 typedef struct {            /* Double                                         */
362         double value;
363 } constant_double;
364
365
366 typedef struct {            /* NameAndType (Field or Method)                  */
367         utf *name;              /* field/method name                              */
368         utf *descriptor;        /* field/method type descriptor string            */
369 } constant_nameandtype;
370
371
372 /* data structures of the runtime system **************************************/
373
374 /* objects *********************************************************************
375
376         All objects (and arrays) which resides on the heap need the following
377         header at the beginning of the data structure.
378 */
379
380 struct java_objectheader {              /* header for all objects             */
381         vftbl *vftbl;                       /* pointer to virtual function table  */
382 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
383         long monitorBits;
384 #endif
385 };
386
387
388
389 /* arrays **********************************************************************
390
391         All arrays are objects (they need the object header with a pointer
392         to a vftbl (array class table). There is one class for each array
393         type. The array type is described by an arraydescriptor struct
394         which is referenced by the vftbl.
395 */
396
397 /* CAUTION: Don't change the numerical values! These constants (with
398  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
399  * primitive type table.
400  */
401 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
402 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
403 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
404 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
405 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
406 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
407 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
408 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
409 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
410
411 typedef struct java_arrayheader {       /* header for all arrays              */
412         java_objectheader objheader;        /* object header                      */
413         s4 size;                            /* array size                         */
414 #ifdef SIZE_FROM_CLASSINFO
415         s4 alignedsize; /* phil */
416 #endif
417 } java_arrayheader;
418
419
420
421 /* structs for all kinds of arrays ********************************************/
422
423 typedef struct java_chararray {
424         java_arrayheader header;
425         u2 data[1];
426 } java_chararray;
427
428 typedef struct java_floatheader {
429         java_arrayheader header;
430         float data[1];
431 } java_floatarray;
432
433 typedef struct java_doublearray {
434         java_arrayheader header;
435         double data[1];
436 } java_doublearray;
437
438 /*  booleanarray and bytearray need identical memory layout (access methods
439     use the same machine code */
440
441 typedef struct java_booleanarray {
442         java_arrayheader header;
443         u1 data[1];
444 } java_booleanarray;
445
446 typedef struct java_bytearray {
447         java_arrayheader header;
448         s1 data[1];
449 } java_bytearray;
450
451 typedef struct java_shortarray {
452         java_arrayheader header;
453         s2 data[1];
454 } java_shortarray;
455
456 typedef struct java_intarray {
457         java_arrayheader header;
458         s4 data[1];
459 } java_intarray;
460
461 typedef struct java_longarray {
462         java_arrayheader header;
463         s8 data[1];
464 } java_longarray;
465
466 /*  objectarray and arrayarray need identical memory layout (access methods
467     use the same machine code */
468
469 typedef struct java_objectarray {
470         java_arrayheader header;
471         java_objectheader *data[1];
472 } java_objectarray;
473
474
475 /* structure for primitive classes ********************************************/
476
477 typedef struct primitivetypeinfo {
478         classinfo *class_wrap;               /* class for wrapping primitive type */
479         classinfo *class_primitive;          /* primitive class                   */
480         char      *wrapname;                 /* name of class for wrapping        */
481         char      typesig;                   /* one character type signature      */
482         char      *name;                     /* name of primitive class           */
483         char      *arrayname;                /* name of primitive array class     */
484         classinfo *arrayclass;               /* primitive array class             */
485         vftbl     *arrayvftbl;               /* vftbl of primitive array class    */
486 } primitivetypeinfo;
487
488
489 /* field, method and class structures *****************************************/
490
491 #include "jit/sets.h"
492 typedef struct xtafldinfo {
493         bool       fieldChecked;                
494         classinfo *fldClassType;
495         classSet  *XTAclassSet;          /* field class type set                  */
496 } xtafldinfo;
497
498
499 /* fieldinfo ******************************************************************/
500
501 struct fieldinfo {            /* field of a class                                 */
502         s4  flags;            /* ACC flags                                        */
503         s4  type;             /* basic data type                                  */
504         utf *name;            /* name of field                                    */
505         utf *descriptor;      /* JavaVM descriptor string of field                */
506         
507         s4  offset;           /* offset from start of object (instance variables) */
508
509         imm_union value;      /* storage for static values (class variables)      */
510
511         classinfo *class;     /* needed by typechecker. Could be optimized        */
512                               /* away by using constant_FMIref instead of         */
513                               /* fieldinfo throughout the compiler.               */
514         
515         xtafldinfo *xta;
516 };
517
518 struct basicblock;
519
520
521 /* exceptiontable *************************************************************/
522
523 typedef struct xtable {         /* exceptiontable entry in a method           */
524         s4         startpc;         /* start pc of guarded area (inclusive)       */
525         struct basicblock *start;
526
527         s4         endpc;           /* end pc of guarded area (exklusive)         */
528         struct basicblock *end;
529
530         s4         handlerpc;       /* pc of exception handler                    */
531         struct basicblock *handler;
532
533         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
534         struct xtable *next;        /* used to build a list of exception when     */
535                                     /* loops are copied */
536         struct xtable *down;        /* instead of the old array, a list is used   */
537 } xtable;
538
539
540 typedef struct exceptiontable { /* exceptiontable entry in a method           */
541         s4         startpc;         /* start pc of guarded area (inclusive)       */
542         s4         endpc;           /* end pc of guarded area (exklusive)         */
543         s4         handlerpc;       /* pc of exception handler                    */
544         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
545 } exceptiontable;
546
547
548 /* methodinfo  static info ****************************************************/
549 typedef struct xtainfo {
550         s4          XTAmethodUsed;     /* XTA if used in callgraph - not used /used */
551         classSet    *XTAclassSet;      /* method class type set                 */ 
552         /*classSet      *PartClassSet */   /* method class type set                 */ 
553
554         classSetNode    *paramClassSet; /* cone set of methods parameters       */
555
556         methSet         *calls;            /* methods this method calls                 */ 
557         methSet         *calledBy;         /* methods that call this method         */ 
558         methSet         *marked;  //not in Dez         /* methods that marked by this method    */ 
559         methSet         *markedBy;
560         fldSet          *fldsUsed;         /* fields used by this method             */ 
561         /*methSetNode  *interfaceCalls*/   /* methods this method calls as interface */ 
562         bool           chgdSinceLastParse; /* Changed since last parse ?          */
563 } xtainfo; 
564
565
566 /* lineinfo *****************************************************************/
567 struct lineinfo {
568         u2 start_pc;
569         u2 line_number;
570 };
571
572 /* methodinfo *****************************************************************/
573
574 struct methodinfo {                 /* method structure                       */
575         s4             flags;               /* ACC flags                              */
576         utf       *name;                /* name of method                         */
577         utf       *descriptor;          /* JavaVM descriptor string of method     */
578         s4         returntype;          /* only temporary valid, return type      */
579         classinfo *returnclass;         /* pointer to classinfo for the rtn type  */ /*XTA*/ 
580         s4         paramcount;          /* only temporary valid, parameter count  */
581         u1        *paramtypes;          /* only temporary valid, parameter types  */
582         classinfo **paramclass;         /* pointer to classinfo for a parameter   */ /*XTA*/
583         
584         classinfo *class;               /* class, the method belongs to           */
585         s4         vftblindex;          /* index of method in virtual function table
586                                            (if it is a virtual method)            */
587         s4         maxstack;            /* maximum stack depth of method          */
588         s4         maxlocals;           /* maximum number of local variables      */
589         s4         jcodelength;         /* length of JavaVM code                  */
590         u1        *jcode;               /* pointer to JavaVM code                 */
591
592         s4         exceptiontablelength;/* exceptiontable length                  */
593         exceptiontable *exceptiontable; /* the exceptiontable                     */
594
595         u2        thrownexceptionscount;/*number of exceptions declared to be thrown by a method*/
596         classinfo **thrownexceptions;   /*array of classinfos of declared exceptions*/
597
598         u2         linenumbercount;     /*number of linenumber attributes*/
599         lineinfo  *linenumbers;         /*array of lineinfo items (start_pc,line_number)*/
600
601         u1        *stubroutine;         /* stub for compiling or calling natives  */    
602         s4         mcodelength;         /* legth of generated machine code        */
603         u1        *mcode;               /* pointer to machine code                */
604         u1        *entrypoint;          /* entry point in machine code            */
605
606         /*rtainfo   rta;*/
607         xtainfo    *xta;
608
609         s4        methodUsed;           /* marked (might be used later) /not used /used */
610         s4        monoPoly;             /* call is mono or poly or unknown        */ /*RT stats */
611         /* should # method def'd and used be kept after static parse (will it be used?) */
612         s4        subRedefs;
613         s4        subRedefsUsed;
614         s4        nativelyoverloaded;           /*used in header.c and only valid there*/
615 };
616
617
618 /* innerclassinfo *************************************************************/
619
620 typedef struct innerclassinfo {
621         classinfo *inner_class;       /* inner class pointer                      */
622         classinfo *outer_class;       /* outer class pointer                      */
623         utf *name;                    /* innerclass name                          */ 
624         s4 flags;                     /* ACC flags                                */
625 } innerclassinfo;
626
627
628 /* classinfo ******************************************************************/
629
630 struct classinfo {                /* class structure                          */
631         java_objectheader header;     /* classes are also objects                 */
632         java_objectarray* signers;
633         struct java_security_ProtectionDomain* pd;
634         struct java_lang_VMClass* vmClass;
635         struct java_lang_reflect_Constructor* constructor;
636
637         s4 initializing_thread;       /* gnu classpath                            */
638         s4 erroneous_state;           /* gnu classpath                            */
639         struct gnu_classpath_RawData* vmData; /* gnu classpath                    */
640
641         s4          flags;            /* ACC flags                                */
642         utf        *name;             /* class name                               */
643
644         s4          cpcount;          /* number of entries in constant pool       */
645         u1         *cptags;           /* constant pool tags                       */
646         voidptr    *cpinfos;          /* pointer to constant pool info structures */
647
648         classinfo  *super;            /* super class pointer                      */
649         classinfo  *sub;              /* sub class pointer                        */
650         classinfo  *nextsub;          /* pointer to next class in sub class list  */
651
652         s4          interfacescount;  /* number of interfaces                     */
653         classinfo **interfaces;       /* pointer to interfaces                    */
654
655         s4          fieldscount;      /* number of fields                         */
656         fieldinfo  *fields;           /* field table                              */
657
658         s4          methodscount;     /* number of methods                        */
659         methodinfo *methods;          /* method table                             */
660
661         listnode    listnode;         /* linkage                                  */
662
663         bool        initialized;      /* true, if class already initialised       */
664         bool        initializing;     /* flag for the compiler                    */
665         bool        loaded;           /* true, if class already loaded            */
666         bool        linked;           /* true, if class already linked            */
667         s4          index;            /* hierarchy depth (classes) or index
668                                          (interfaces)                             */
669         s4          instancesize;     /* size of an instance of this class        */
670 #ifdef SIZE_FROM_CLASSINFO
671         s4          alignedsize;      /* size of an instance, aligned to the 
672                                                                          allocation size on the heap              */
673 #endif
674
675         vftbl      *vftbl;            /* pointer to virtual function table        */
676
677         methodinfo *finalizer;        /* finalizer method                         */
678
679     u2             innerclasscount;   /* number of inner classes              */
680     innerclassinfo *innerclass;
681
682     classinfo      *hashlink;         /* link for external hash chain         */
683         bool        classvftbl;       /* has its own copy of the Class vtbl       */
684
685         s4          classUsed;        /* 0= not used 1 = used   CO-RT             */
686
687         classSetNode *impldBy;        /* implemented by class set                 */
688         utf        *packagename;      /* full name of the package                 */
689         utf        *sourcefile;       /* classfile name containing this class     */
690         java_objectheader *classloader;       /* 0 for bootstrap classloader */
691 };
692
693 /* check if class is an array class. Only use for linked classes! */
694 #define CLASS_IS_ARRAY(clsinfo)  ((clsinfo)->vftbl->arraydesc != NULL)
695
696
697 /* virtual function table ******************************************************
698
699         The vtbl has a bidirectional layout with open ends at both sides.
700         interfacetablelength gives the number of entries of the interface table at
701         the start of the vftbl. The vftbl pointer points to &interfacetable[0].
702         vftbllength gives the number of entries of table at the end of the vftbl.
703
704         runtime type check (checkcast):
705
706         Different methods are used for runtime type check depending on the
707         argument of checkcast/instanceof.
708         
709         A check against a class is implemented via relative numbering on the class
710         hierachy tree. The tree is numbered in a depth first traversal setting
711         the base field and the diff field. The diff field gets the result of
712         (high - base) so that a range check can be implemented by an unsigned
713         compare. A sub type test is done by checking the inclusion of base of
714         the sub class in the range of the superclass.
715
716         A check against an interface is implemented via the interfacevftbl. If the
717         interfacevftbl contains a nonnull value a class is a subclass of this
718         interface.
719
720         interfacetable:
721
722         Like standard virtual methods interface methods are called using
723         virtual function tables. All interfaces are numbered sequentially
724         (starting with zero). For each class there exist an interface table
725         of virtual function tables for each implemented interface. The length
726         of the interface table is determined by the highest number of an
727         implemented interface.
728
729         The following example assumes a class which implements interface 0 and 3:
730
731         interfacetablelength = 4
732
733                   | ...       |            +----------+
734                       +-----------+            | method 2 |---> method z
735                       | class     |            | method 1 |---> method y
736                       +-----------+            | method 0 |---> method x
737                       | ivftbl  0 |----------> +----------+
738         vftblptr ---> +-----------+
739                   | ivftbl -1 |--> NULL    +----------+
740                   | ivftbl -2 |--> NULL    | method 1 |---> method x
741                   | ivftbl -3 |-----+      | method 0 |---> method a
742                   +-----------+     +----> +----------+
743      
744                               +---------------+
745                                   | length 3 = 2  |
746                                   | length 2 = 0  |
747                                   | length 1 = 0  |
748                                   | length 0 = 3  |
749         interfacevftbllength ---> +---------------+
750
751 *******************************************************************************/
752
753 struct vftbl {
754         methodptr   *interfacetable[1];    /* interface table (access via macro)  */
755
756         classinfo   *class;                /* class, the vtbl belongs to          */
757
758         arraydescriptor *arraydesc;        /* for array classes, otherwise NULL   */
759
760         s4           vftbllength;          /* virtual function table length       */
761         s4           interfacetablelength; /* interface table length              */
762
763         s4           baseval;              /* base for runtime type check         */
764                                            /* (-index for interfaces)             */
765         s4           diffval;              /* high - base for runtime type check  */
766
767         s4          *interfacevftbllength; /* length of interface vftbls          */
768         
769         methodptr    table[1];             /* class vftbl                         */
770 };
771
772 #define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
773
774
775 /* arraydescriptor ************************************************************
776
777     For every array class an arraydescriptor is allocated which
778     describes the array class.
779         The arraydescriptor is referenced from the vftbl of the array
780         class.
781
782 *******************************************************************************/
783
784 struct arraydescriptor {
785         vftbl *componentvftbl;   /* vftbl of the component type, NULL for primit. */
786         vftbl *elementvftbl;     /* vftbl of the element type, NULL for primitive */
787         short  arraytype;        /* ARRAYTYPE_* constant                          */
788         short  dimension;        /* dimension of the array (always >= 1)          */
789     s4     dataoffset;       /* offset of the array data from object pointer  */
790         s4     componentsize;    /* size of a component in bytes                  */
791         short  elementtype;      /* ARRAYTYPE_* constant                          */
792 };
793
794
795 /* flag variables *************************************************************/
796
797 extern bool cacao_initializing;
798 extern bool compileall;
799 extern bool runverbose;         
800 extern bool verboseexception;         
801 extern bool verbose;         
802 extern bool opt_rt;             /* Rapid Type Analysis for better inlining CO-RT*/
803 extern bool opt_xta;            /* X Type Analysis for better inlining    CO-XTA*/
804 extern bool opt_vta;            /* Variable Type Analysis for better inlining    CO-VTA*/
805 extern bool opt_verify;         /* true if classfiles should be verified      */
806 #ifdef TYPECHECK_VERBOSE_OPT
807 extern bool typecheckverbose;
808 #endif
809
810 /*extern int pClassHeir;*/
811 /*extern int pCallgraph;*/
812 /*extern int pOpcodes;*/
813 /*extern int pStats;*/
814
815 /*extern void RT_jit_parse(methodinfo *m);*/
816
817
818 /* statistic variables ********************************************************/
819
820 extern int count_class_infos;
821 extern int count_const_pool_len;
822 extern int count_vftbl_len;
823 extern int count_utf_len;
824 extern int count_all_methods;
825 extern int count_vmcode_len;
826 extern int count_extable_len;
827 extern int count_class_loads;
828 extern int count_class_inits;
829 extern int count_utf_new;
830 extern int count_utf_new_found;
831
832
833 /* table of primitive types ***************************************************/
834
835 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
836  * constants (except ARRAYTYPE_OBJECT).
837  */
838 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
839
840
841 /* macros for descriptor parsing **********************************************/
842
843 /* SKIP_FIELDDESCRIPTOR:
844  * utf_ptr must point to the first character of a field descriptor.
845  * After the macro call utf_ptr points to the first character after
846  * the field descriptor.
847  *
848  * CAUTION: This macro does not check for an unexpected end of the
849  * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE.
850  */
851 #define SKIP_FIELDDESCRIPTOR(utf_ptr)                                                   \
852         do { while (*(utf_ptr)=='[') (utf_ptr)++;                                       \
853                 if (*(utf_ptr)++=='L')                                                                  \
854                         while(*(utf_ptr)++ != ';') /* skip */; } while(0)
855
856 /* SKIP_FIELDDESCRIPTOR_SAFE:
857  * utf_ptr must point to the first character of a field descriptor.
858  * After the macro call utf_ptr points to the first character after
859  * the field descriptor.
860  *
861  * Input:
862  *     utf_ptr....points to first char of descriptor
863  *     end_ptr....points to first char after the end of the string
864  *     errorflag..must be initialized (to false) by the caller!
865  * Output:
866  *     utf_ptr....points to first char after the descriptor
867  *     errorflag..set to true if the string ended unexpectedly
868  */
869 #define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag)                    \
870         do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++;     \
871                 if ((utf_ptr) == (end_ptr))                                                                             \
872                         (errorflag) = true;                                                                                     \
873                 else                                                                                                                    \
874                         if (*(utf_ptr)++=='L') {                                                                        \
875                                 while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';')    \
876                                         /* skip */;                                                                                     \
877                                 if ((utf_ptr)[-1] != ';')                                                               \
878                                         (errorflag) = true; }} while(0)
879
880
881 /* Synchronization ************************************************************/
882
883 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
884 void cast_lock();
885 void cast_unlock();
886 void compiler_lock();
887 void compiler_unlock();
888 #endif
889
890 #endif /* _GLOBAL_H */
891
892
893 /*
894  * These are local overrides for various environment variables in Emacs.
895  * Please do not remove this and leave it at the end of the file, where
896  * Emacs will automagically detect them.
897  * ---------------------------------------------------------------------
898  * Local variables:
899  * mode: c
900  * indent-tabs-mode: t
901  * c-basic-offset: 4
902  * tab-width: 4
903  * End:
904  */