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