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