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