New automake's don't like --include-deps anymore.
[cacao.git] / 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 1230 2004-06-30 19:41:23Z 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 exceptiontable exceptiontable;
194 typedef struct methodinfo methodinfo; 
195 typedef struct lineinfo lineinfo; 
196 typedef struct arraydescriptor arraydescriptor;
197
198
199 /* constant pool entries *******************************************************
200
201         All constant pool entries need a data structure which contain the entrys
202         value. In some cases this structure exist already, in the remaining cases
203         this structure must be generated:
204
205                 kind                      structure                     generated?
206         ----------------------------------------------------------------------
207     CONSTANT_Class               classinfo                           no
208     CONSTANT_Fieldref            constant_FMIref                    yes
209     CONSTANT_Methodref           constant_FMIref                    yes
210     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
211     CONSTANT_String              unicode                             no
212     CONSTANT_Integer             constant_integer                   yes
213     CONSTANT_Float               constant_float                     yes
214     CONSTANT_Long                constant_long                      yes
215     CONSTANT_Double              constant_double                    yes
216     CONSTANT_NameAndType         constant_nameandtype               yes
217     CONSTANT_Utf8                unicode                             no
218     CONSTANT_UNUSED              -
219
220 *******************************************************************************/
221
222 /* data structures for hashtables ********************************************
223
224
225         All utf-symbols, javastrings and classes are stored in global hashtables,
226         so every symbol exists only once. Equal symbols have identical pointers.
227         The functions for adding hashtable elements search the table for the 
228         element with the specified name/text and return it on success. Otherwise a 
229         new hashtable element is created.
230
231     The hashtables use external linking for handling collisions. The hashtable 
232         structure contains a pointer <ptr> to the array of hashtable slots. The 
233         number of hashtable slots and therefore the size of this array is specified 
234         by the element <size> of hashtable structure. <entries> contains the number
235         of all hashtable elements stored in the table, including those in the 
236         external chains.
237         The hashtable element structures (utf, literalstring, classinfo) contain
238         both a pointer to the next hashtable element as a link for the external hash 
239         chain and the key of the element. The key is computed from the text of
240         the string or the classname by using up to 8 characters.
241         
242         If the number of entries in the hashtable exceeds twice the size of the 
243         hashtableslot-array it is supposed that the average length of the 
244         external chains has reached a value beyond 2. Therefore the functions for
245         adding hashtable elements (utf_new, class_new, literalstring_new) double
246         the hashtableslot-array. In this restructuring process all elements have
247         to be inserted into the new hashtable and new external chains must be built.
248
249
250 example for the layout of a hashtable:
251
252 hashtable.ptr-->  +-------------------+
253                   |                   |
254                            ...
255                   |                   |
256                   +-------------------+   +-------------------+   +-------------------+
257                   | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
258                   +-------------------+   +-------------------+   +-------------------+
259                   | hashtable element |
260                   +-------------------+   +-------------------+   
261                   | hashtable element |-->| hashtable element |-->NULL
262                   +-------------------+   +-------------------+   
263                   | hashtable element |-->NULL
264                   +-------------------+
265                   |                   |
266                            ...
267                   |                   |
268                   +-------------------+
269
270 */
271
272
273 /* data structure for utf8 symbols ********************************************/
274
275 struct utf {
276         utf        *hashlink;       /* link for external hash chain               */
277         int         blength;        /* text length in bytes                       */           
278         char       *text;           /* pointer to text                            */
279 };
280
281
282 /* data structure of internal javastrings stored in global hashtable **********/
283
284 struct literalstring {
285         literalstring     *hashlink;     /* link for external hash chain          */
286         java_objectheader *string;  
287 };
288
289
290 /* data structure for storing information needed for a stacktrace across native functions*/
291 struct native_stackframeinfo {
292         void *oldThreadspecificHeadValue;
293         void **addressOfThreadspecificHead;
294         methodinfo *method;
295         void *returnToFromNative;
296
297 #if 0
298         void *returnFromNative;
299         void *addrReturnFromNative;
300         methodinfo *method;
301         struct native_stackframeinfo *next;
302         struct native_stackframeinfo *prev;
303 #endif
304 };
305
306 typedef struct native_stackframeinfo native_stackframeinfo;
307
308 struct stacktraceelement {
309 #if POINTERSIZE == 8
310         u8 linenumber;
311 #else
312         u4 linenumber;
313 #endif
314         methodinfo *method;
315 };
316
317 typedef struct stacktraceelement stacktraceelement;
318
319 /* data structure for calls from c code to java methods */
320
321 struct jni_callblock {
322         u8 itemtype;
323         u8 item;
324 };
325
326 typedef struct jni_callblock jni_callblock;
327
328
329 /* data structure for accessing hashtables ************************************/
330
331 typedef struct {            
332         u4 size;
333         u4 entries;        /* number of entries in the table */
334         void **ptr;        /* pointer to hashtable */
335 } hashtable;
336
337
338 /* data structures of remaining constant pool entries *************************/
339
340 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
341         classinfo *class;       /* class containing this field/method/interface   */
342         utf       *name;        /* field/method/interface name                    */
343         utf       *descriptor;  /* field/method/interface type descriptor string  */
344 } constant_FMIref;
345
346
347 typedef struct {            /* Integer                                        */
348         s4 value;
349 } constant_integer;
350
351         
352 typedef struct {            /* Float                                          */
353         float value;
354 } constant_float;
355
356
357 typedef struct {            /* Long                                           */
358         s8 value;
359 } constant_long;
360         
361
362 typedef struct {            /* Double                                         */
363         double value;
364 } constant_double;
365
366
367 typedef struct {            /* NameAndType (Field or Method)                  */
368         utf *name;              /* field/method name                              */
369         utf *descriptor;        /* field/method type descriptor string            */
370 } constant_nameandtype;
371
372
373 /* data structures of the runtime system **************************************/
374
375 /* objects *********************************************************************
376
377         All objects (and arrays) which resides on the heap need the following
378         header at the beginning of the data structure.
379 */
380
381 struct java_objectheader {              /* header for all objects             */
382         vftbl *vftbl;                       /* pointer to virtual function table  */
383 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
384         long monitorBits;
385 #endif
386 };
387
388
389
390 /* arrays **********************************************************************
391
392         All arrays are objects (they need the object header with a pointer
393         to a vftbl (array class table). There is one class for each array
394         type. The array type is described by an arraydescriptor struct
395         which is referenced by the vftbl.
396 */
397
398 /* CAUTION: Don't change the numerical values! These constants (with
399  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
400  * primitive type table.
401  */
402 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
403 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
404 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
405 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
406 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
407 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
408 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
409 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
410 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
411
412 typedef struct java_arrayheader {       /* header for all arrays              */
413         java_objectheader objheader;        /* object header                      */
414         s4 size;                            /* array size                         */
415 #ifdef SIZE_FROM_CLASSINFO
416         s4 alignedsize; /* phil */
417 #endif
418 } java_arrayheader;
419
420
421
422 /* structs for all kinds of arrays ********************************************/
423
424 typedef struct java_chararray {
425         java_arrayheader header;
426         u2 data[1];
427 } java_chararray;
428
429 typedef struct java_floatheader {
430         java_arrayheader header;
431         float data[1];
432 } java_floatarray;
433
434 typedef struct java_doublearray {
435         java_arrayheader header;
436         double data[1];
437 } java_doublearray;
438
439 /*  booleanarray and bytearray need identical memory layout (access methods
440     use the same machine code */
441
442 typedef struct java_booleanarray {
443         java_arrayheader header;
444         u1 data[1];
445 } java_booleanarray;
446
447 typedef struct java_bytearray {
448         java_arrayheader header;
449         s1 data[1];
450 } java_bytearray;
451
452 typedef struct java_shortarray {
453         java_arrayheader header;
454         s2 data[1];
455 } java_shortarray;
456
457 typedef struct java_intarray {
458         java_arrayheader header;
459         s4 data[1];
460 } java_intarray;
461
462 typedef struct java_longarray {
463         java_arrayheader header;
464         s8 data[1];
465 } java_longarray;
466
467 /*  objectarray and arrayarray need identical memory layout (access methods
468     use the same machine code */
469
470 typedef struct java_objectarray {
471         java_arrayheader header;
472         java_objectheader *data[1];
473 } java_objectarray;
474
475
476 /* structure for primitive classes ********************************************/
477
478 typedef struct primitivetypeinfo {
479         classinfo *class_wrap;               /* class for wrapping primitive type */
480         classinfo *class_primitive;          /* primitive class                   */
481         char      *wrapname;                 /* name of class for wrapping        */
482         char      typesig;                   /* one character type signature      */
483         char      *name;                     /* name of primitive class           */
484         char      *arrayname;                /* name of primitive array class     */
485         classinfo *arrayclass;               /* primitive array class             */
486         vftbl     *arrayvftbl;               /* vftbl of primitive array class    */
487 } primitivetypeinfo;
488
489
490 /* field, method and class structures *****************************************/
491
492 #include "jit/sets.h"
493 typedef struct xtafldinfo {
494         bool       fieldChecked;                
495         classinfo *fldClassType;
496         classSet  *XTAclassSet;          /* field class type set                  */
497 } xtafldinfo;
498
499
500 /* fieldinfo ******************************************************************/
501
502 struct fieldinfo {            /* field of a class                                 */
503         s4  flags;            /* ACC flags                                        */
504         s4  type;             /* basic data type                                  */
505         utf *name;            /* name of field                                    */
506         utf *descriptor;      /* JavaVM descriptor string of field                */
507         
508         s4  offset;           /* offset from start of object (instance variables) */
509
510         imm_union value;      /* storage for static values (class variables)      */
511
512         classinfo *class;     /* needed by typechecker. Could be optimized        */
513                               /* away by using constant_FMIref instead of         */
514                               /* fieldinfo throughout the compiler.               */
515         
516         xtafldinfo *xta;
517 };
518
519
520 /* exceptiontable *************************************************************/
521
522 struct exceptiontable {         /* exceptiontable entry in a method           */
523         s4         startpc;         /* start pc of guarded area (inclusive)       */
524         struct basicblock *start;
525
526         s4         endpc;           /* end pc of guarded area (exklusive)         */
527         struct basicblock *end;
528
529         s4         handlerpc;       /* pc of exception handler                    */
530         struct basicblock *handler;
531
532         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
533         exceptiontable *next;       /* used to build a list of exception when     */
534                                     /* loops are copied */
535         exceptiontable *down;       /* instead of the old array, a list is used   */
536 };
537
538
539 /* methodinfo  static info ****************************************************/
540
541 typedef struct xtainfo {
542         s4          XTAmethodUsed;     /* XTA if used in callgraph - not used /used */
543         classSet    *XTAclassSet;      /* method class type set                 */ 
544         /*classSet      *PartClassSet */   /* method class type set                 */ 
545
546         classSetNode    *paramClassSet; /* cone set of methods parameters       */
547
548         methSet         *calls;            /* methods this method calls                 */ 
549         methSet         *calledBy;         /* methods that call this method         */ 
550         methSet         *marked;  //not in Dez         /* methods that marked by this method    */ 
551         methSet         *markedBy;
552         fldSet          *fldsUsed;         /* fields used by this method             */ 
553         /*methSetNode  *interfaceCalls*/   /* methods this method calls as interface */ 
554         bool           chgdSinceLastParse; /* Changed since last parse ?          */
555 } xtainfo; 
556
557
558 /* lineinfo *****************************************************************/
559
560 struct lineinfo {
561         u2 start_pc;
562         u2 line_number;
563 };
564
565
566 /* methodinfo *****************************************************************/
567
568 struct methodinfo {                 /* method structure                       */
569         s4             flags;               /* ACC flags                              */
570         utf       *name;                /* name of method                         */
571         utf       *descriptor;          /* JavaVM descriptor string of method     */
572         s4         returntype;          /* only temporary valid, return type      */
573         classinfo *returnclass;         /* pointer to classinfo for the rtn type  */ /*XTA*/ 
574         s4         paramcount;          /* only temporary valid, parameter count  */
575         u1        *paramtypes;          /* only temporary valid, parameter types  */
576         classinfo **paramclass;         /* pointer to classinfo for a parameter   */ /*XTA*/
577
578         bool       isleafmethod;        /* does method call subroutines           */
579
580         classinfo *class;               /* class, the method belongs to           */
581         s4         vftblindex;          /* index of method in virtual function table
582                                            (if it is a virtual method)            */
583         s4         maxstack;            /* maximum stack depth of method          */
584         s4         maxlocals;           /* maximum number of local variables      */
585         s4         jcodelength;         /* length of JavaVM code                  */
586         u1        *jcode;               /* pointer to JavaVM code                 */
587
588         s4         basicblockcount;     /* number of basic blocks                 */
589         struct basicblock *basicblocks; /* points to basic block array            */
590         s4        *basicblockindex;     /* a table which contains for every byte  */
591                                         /* of JavaVM code a basic block index if  */
592                                         /* at this byte is the start of a basic   */
593                                         /* block                                  */
594
595         s4         instructioncount;    /* number of JavaVM instructions          */
596         struct instruction *instructions; /* points to intermediate code instructions */
597
598         s4         stackcount;          /* number of stack elements               */
599         struct stackelement *stack;     /* points to intermediate code instructions */
600
601         s4         exceptiontablelength;/* exceptiontable length                  */
602         exceptiontable *exceptiontable; /* the exceptiontable                     */
603
604         u2        thrownexceptionscount;/*number of exceptions declared to be thrown by a method*/
605         classinfo **thrownexceptions;   /*array of classinfos of declared exceptions*/
606
607         u2         linenumbercount;     /* number of linenumber attributes        */
608         lineinfo  *linenumbers;         /* array of lineinfo items                */
609
610         struct registerdata *registerdata; /* struct with all regalloc stuff      */
611
612         u1        *stubroutine;         /* stub for compiling or calling natives  */
613         s4         mcodelength;         /* legth of generated machine code        */
614         u1        *mcode;               /* pointer to machine code                */
615         u1        *entrypoint;          /* entry point in machine code            */
616
617         /*rtainfo   rta;*/
618         xtainfo    *xta;
619
620         s4        methodUsed;           /* marked (might be used later) /not used /used */
621         s4        monoPoly;             /* call is mono or poly or unknown        */ /*RT stats */
622         /* should # method def'd and used be kept after static parse (will it be used?) */
623         s4        subRedefs;
624         s4        subRedefsUsed;
625         s4        nativelyoverloaded;           /*used in header.c and only valid there*/
626 };
627
628
629 /* innerclassinfo *************************************************************/
630
631 typedef struct innerclassinfo {
632         classinfo *inner_class;       /* inner class pointer                      */
633         classinfo *outer_class;       /* outer class pointer                      */
634         utf *name;                    /* innerclass name                          */ 
635         s4 flags;                     /* ACC flags                                */
636 } innerclassinfo;
637
638
639 /* classinfo ******************************************************************/
640
641 struct classinfo {                /* class structure                          */
642         java_objectheader header;     /* classes are also objects                 */
643         java_objectarray* signers;
644         struct java_security_ProtectionDomain* pd;
645         struct java_lang_VMClass* vmClass;
646         struct java_lang_reflect_Constructor* constructor;
647
648         s4 initializing_thread;       /* gnu classpath                            */
649         s4 erroneous_state;           /* gnu classpath                            */
650         struct gnu_classpath_RawData* vmData; /* gnu classpath                    */
651
652         s4          flags;            /* ACC flags                                */
653         utf        *name;             /* class name                               */
654
655         s4          cpcount;          /* number of entries in constant pool       */
656         u1         *cptags;           /* constant pool tags                       */
657         voidptr    *cpinfos;          /* pointer to constant pool info structures */
658
659         classinfo  *super;            /* super class pointer                      */
660         classinfo  *sub;              /* sub class pointer                        */
661         classinfo  *nextsub;          /* pointer to next class in sub class list  */
662
663         s4          interfacescount;  /* number of interfaces                     */
664         classinfo **interfaces;       /* pointer to interfaces                    */
665
666         s4          fieldscount;      /* number of fields                         */
667         fieldinfo  *fields;           /* field table                              */
668
669         s4          methodscount;     /* number of methods                        */
670         methodinfo *methods;          /* method table                             */
671
672         listnode    listnode;         /* linkage                                  */
673
674         bool        initialized;      /* true, if class already initialised       */
675         bool        initializing;     /* flag for the compiler                    */
676         bool        loaded;           /* true, if class already loaded            */
677         bool        linked;           /* true, if class already linked            */
678         s4          index;            /* hierarchy depth (classes) or index
679                                          (interfaces)                             */
680         s4          instancesize;     /* size of an instance of this class        */
681 #ifdef SIZE_FROM_CLASSINFO
682         s4          alignedsize;      /* size of an instance, aligned to the 
683                                                                          allocation size on the heap              */
684 #endif
685
686         vftbl      *vftbl;            /* pointer to virtual function table        */
687
688         methodinfo *finalizer;        /* finalizer method                         */
689
690     u2             innerclasscount;   /* number of inner classes              */
691     innerclassinfo *innerclass;
692
693     classinfo      *hashlink;         /* link for external hash chain         */
694         bool        classvftbl;       /* has its own copy of the Class vtbl       */
695
696         s4          classUsed;        /* 0= not used 1 = used   CO-RT             */
697
698         classSetNode *impldBy;        /* implemented by class set                 */
699         utf        *packagename;      /* full name of the package                 */
700         utf        *sourcefile;       /* classfile name containing this class     */
701         java_objectheader *classloader;       /* 0 for bootstrap classloader */
702 };
703
704 /* check if class is an array class. Only use for linked classes! */
705 #define CLASS_IS_ARRAY(clsinfo)  ((clsinfo)->vftbl->arraydesc != NULL)
706
707
708 /* virtual function table ******************************************************
709
710         The vtbl has a bidirectional layout with open ends at both sides.
711         interfacetablelength gives the number of entries of the interface table at
712         the start of the vftbl. The vftbl pointer points to &interfacetable[0].
713         vftbllength gives the number of entries of table at the end of the vftbl.
714
715         runtime type check (checkcast):
716
717         Different methods are used for runtime type check depending on the
718         argument of checkcast/instanceof.
719         
720         A check against a class is implemented via relative numbering on the class
721         hierachy tree. The tree is numbered in a depth first traversal setting
722         the base field and the diff field. The diff field gets the result of
723         (high - base) so that a range check can be implemented by an unsigned
724         compare. A sub type test is done by checking the inclusion of base of
725         the sub class in the range of the superclass.
726
727         A check against an interface is implemented via the interfacevftbl. If the
728         interfacevftbl contains a nonnull value a class is a subclass of this
729         interface.
730
731         interfacetable:
732
733         Like standard virtual methods interface methods are called using
734         virtual function tables. All interfaces are numbered sequentially
735         (starting with zero). For each class there exist an interface table
736         of virtual function tables for each implemented interface. The length
737         of the interface table is determined by the highest number of an
738         implemented interface.
739
740         The following example assumes a class which implements interface 0 and 3:
741
742         interfacetablelength = 4
743
744                   | ...       |            +----------+
745                       +-----------+            | method 2 |---> method z
746                       | class     |            | method 1 |---> method y
747                       +-----------+            | method 0 |---> method x
748                       | ivftbl  0 |----------> +----------+
749         vftblptr ---> +-----------+
750                   | ivftbl -1 |--> NULL    +----------+
751                   | ivftbl -2 |--> NULL    | method 1 |---> method x
752                   | ivftbl -3 |-----+      | method 0 |---> method a
753                   +-----------+     +----> +----------+
754      
755                               +---------------+
756                                   | length 3 = 2  |
757                                   | length 2 = 0  |
758                                   | length 1 = 0  |
759                                   | length 0 = 3  |
760         interfacevftbllength ---> +---------------+
761
762 *******************************************************************************/
763
764 struct vftbl {
765         methodptr   *interfacetable[1];    /* interface table (access via macro)  */
766
767         classinfo   *class;                /* class, the vtbl belongs to          */
768
769         arraydescriptor *arraydesc;        /* for array classes, otherwise NULL   */
770
771         s4           vftbllength;          /* virtual function table length       */
772         s4           interfacetablelength; /* interface table length              */
773
774         s4           baseval;              /* base for runtime type check         */
775                                            /* (-index for interfaces)             */
776         s4           diffval;              /* high - base for runtime type check  */
777
778         s4          *interfacevftbllength; /* length of interface vftbls          */
779         
780         methodptr    table[1];             /* class vftbl                         */
781 };
782
783 #define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
784
785
786 /* arraydescriptor ************************************************************
787
788     For every array class an arraydescriptor is allocated which
789     describes the array class.
790         The arraydescriptor is referenced from the vftbl of the array
791         class.
792
793 *******************************************************************************/
794
795 struct arraydescriptor {
796         vftbl *componentvftbl;   /* vftbl of the component type, NULL for primit. */
797         vftbl *elementvftbl;     /* vftbl of the element type, NULL for primitive */
798         short  arraytype;        /* ARRAYTYPE_* constant                          */
799         short  dimension;        /* dimension of the array (always >= 1)          */
800     s4     dataoffset;       /* offset of the array data from object pointer  */
801         s4     componentsize;    /* size of a component in bytes                  */
802         short  elementtype;      /* ARRAYTYPE_* constant                          */
803 };
804
805
806 /* flag variables *************************************************************/
807
808 extern bool cacao_initializing;
809
810 #ifdef TYPECHECK_VERBOSE_OPT
811 extern bool typecheckverbose;
812 #endif
813
814 /*extern int pClassHeir;*/
815 /*extern int pCallgraph;*/
816 /*extern int pOpcodes;*/
817 /*extern int pStats;*/
818
819 /*extern void RT_jit_parse(methodinfo *m);*/
820
821
822 /* table of primitive types ***************************************************/
823
824 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
825  * constants (except ARRAYTYPE_OBJECT).
826  */
827 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
828
829
830 /* macros for descriptor parsing **********************************************/
831
832 /* SKIP_FIELDDESCRIPTOR:
833  * utf_ptr must point to the first character of a field descriptor.
834  * After the macro call utf_ptr points to the first character after
835  * the field descriptor.
836  *
837  * CAUTION: This macro does not check for an unexpected end of the
838  * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE.
839  */
840 #define SKIP_FIELDDESCRIPTOR(utf_ptr)                                                   \
841         do { while (*(utf_ptr)=='[') (utf_ptr)++;                                       \
842                 if (*(utf_ptr)++=='L')                                                                  \
843                         while(*(utf_ptr)++ != ';') /* skip */; } while(0)
844
845 /* SKIP_FIELDDESCRIPTOR_SAFE:
846  * utf_ptr must point to the first character of a field descriptor.
847  * After the macro call utf_ptr points to the first character after
848  * the field descriptor.
849  *
850  * Input:
851  *     utf_ptr....points to first char of descriptor
852  *     end_ptr....points to first char after the end of the string
853  *     errorflag..must be initialized (to false) by the caller!
854  * Output:
855  *     utf_ptr....points to first char after the descriptor
856  *     errorflag..set to true if the string ended unexpectedly
857  */
858 #define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag)                    \
859         do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++;     \
860                 if ((utf_ptr) == (end_ptr))                                                                             \
861                         (errorflag) = true;                                                                                     \
862                 else                                                                                                                    \
863                         if (*(utf_ptr)++=='L') {                                                                        \
864                                 while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';')    \
865                                         /* skip */;                                                                                     \
866                                 if ((utf_ptr)[-1] != ';')                                                               \
867                                         (errorflag) = true; }} while(0)
868
869
870 /* Synchronization ************************************************************/
871
872 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
873 void cast_lock();
874 void cast_unlock();
875 void compiler_lock();
876 void compiler_unlock();
877 #endif
878
879 #endif /* _GLOBAL_H */
880
881
882 /*
883  * These are local overrides for various environment variables in Emacs.
884  * Please do not remove this and leave it at the end of the file, where
885  * Emacs will automagically detect them.
886  * ---------------------------------------------------------------------
887  * Local variables:
888  * mode: c
889  * indent-tabs-mode: t
890  * c-basic-offset: 4
891  * tab-width: 4
892  * End:
893  */