b9f3b49cfd4888c011fc8ac08fe9ab3b8e348907
[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 815 2003-12-31 13:22:44Z edwin $
35
36 */
37
38
39 #ifndef _GLOBAL_H
40 #define _GLOBAL_H
41
42 #include "config.h"
43 #include "types.h"
44 #include "toolbox/list.h"
45
46 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
47 #include <pthread.h>
48 #endif
49
50
51 #define _GNU_SOURCE
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  * TYPEINFO_DEBUG activates debug checks and debug helpers in typeinfo.c
77  * TYPECHECK_DEBUG activates debug checks in typecheck.c
78  * TYPEINFO_DEBUG_TEST activates the typeinfo test at startup.
79  * TYPECHECK_VERBOSE_IMPORTANT activates important debug messages
80  * TYPECHECK_VERBOSE activates all debug messages
81  */
82 #ifdef CACAO_TYPECHECK
83 #define TYPEINFO_DEBUG
84 #define TYPECHECK_DEBUG
85 /*#define TYPEINFO_DEBUG_TEST*/
86 #define TYPECHECK_VERBOSE
87 /*#define TYPECHECK_VERBOSE_IMPORTANT*/
88 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
89 #define TYPECHECK_VERBOSE_OPT
90 #endif
91 #endif
92
93
94 /* additional data types ******************************************************/
95
96 typedef void *voidptr;          /* generic pointer */
97
98 typedef int   bool;             /* boolean data type */
99
100 #define true  1
101 #define false 0
102
103
104 /* immediate data union */
105
106 typedef union {
107     s4 i;
108     s8 l;
109     float f;
110     double d;
111     void *a;
112     u1 b[8];
113 } imm_union;
114
115
116 #define PRIMITIVETYPE_COUNT  9  /* number of primitive types */
117
118 /* CAUTION: Don't change the numerical values! These constants are
119  * used as indices into the primitive type table.
120  */
121 #define PRIMITIVETYPE_INT     0
122 #define PRIMITIVETYPE_LONG    1
123 #define PRIMITIVETYPE_FLOAT   2
124 #define PRIMITIVETYPE_DOUBLE  3
125 #define PRIMITIVETYPE_BYTE    4
126 #define PRIMITIVETYPE_CHAR    5
127 #define PRIMITIVETYPE_SHORT   6
128 #define PRIMITIVETYPE_BOOLEAN 7
129 #define PRIMITIVETYPE_VOID    8
130
131 typedef void (*functionptr) (); /* generic function pointer */
132
133
134 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
135
136 /* shutdown function **********************************************************/
137
138 void cacao_shutdown(s4 status);
139
140
141 /* basic data types ***********************************************************/
142
143 /* CAUTION: jit/jit.h relies on these numerical values! */
144 #define TYPE_INT      0         /* the JavaVM types must numbered in the      */
145 #define TYPE_LONG     1         /* same order as the ICMD_Ixxx to ICMD_Axxx   */
146 #define TYPE_FLOAT    2         /* instructions (LOAD and STORE)              */
147 #define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
148 #define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
149
150 #define TYPE_VOID    10
151
152
153 /* Java class file constants **************************************************/
154
155 #define MAGIC         0xcafebabe
156 #define MINOR_VERSION 3
157 #define MAJOR_VERSION 45
158
159 #define CONSTANT_Class                 7
160 #define CONSTANT_Fieldref              9
161 #define CONSTANT_Methodref            10
162 #define CONSTANT_InterfaceMethodref   11
163 #define CONSTANT_String                8
164 #define CONSTANT_Integer               3
165 #define CONSTANT_Float                 4
166 #define CONSTANT_Long                  5
167 #define CONSTANT_Double                6
168 #define CONSTANT_NameAndType          12
169 #define CONSTANT_Utf8                  1
170
171 #define CONSTANT_UNUSED                0
172
173 #define ACC_PUBLIC                0x0001
174 #define ACC_PRIVATE               0x0002
175 #define ACC_PROTECTED             0x0004
176 #define ACC_STATIC                0x0008
177 #define ACC_FINAL                 0x0010
178 #define ACC_SUPER                 0x0020
179 #define ACC_SYNCHRONIZED          0x0020
180 #define ACC_VOLATILE              0x0040
181 #define ACC_TRANSIENT             0x0080
182 #define ACC_NATIVE                0x0100
183 #define ACC_INTERFACE             0x0200
184 #define ACC_ABSTRACT              0x0400
185 #define ACC_STRICT                0x0800
186
187 /* resolve typedef cycles *****************************************************/
188
189 typedef struct utf utf;
190 typedef struct literalstring literalstring;
191 typedef struct java_objectheader java_objectheader; 
192 typedef struct classinfo classinfo; 
193 typedef struct vftbl vftbl;
194 typedef u1* methodptr;
195 typedef struct fieldinfo  fieldinfo; 
196 typedef struct methodinfo methodinfo; 
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 calls from c code to java methods */
292
293 struct jni_callblock {
294         u1 itemtype;
295         u8 item;
296 };
297
298 typedef struct jni_callblock jni_callblock;
299
300
301 /* data structure for accessing hashtables ************************************/
302
303 typedef struct {            
304         u4 size;
305         u4 entries;        /* number of entries in the table */
306         void **ptr;        /* pointer to hashtable */
307 } hashtable;
308
309
310 /* data structures of remaining constant pool entries *************************/
311
312 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
313         classinfo *class;       /* class containing this field/method/interface   */
314         utf       *name;        /* field/method/interface name                    */
315         utf       *descriptor;  /* field/method/interface type descriptor string  */
316 } constant_FMIref;
317
318
319 typedef struct {            /* Integer                                        */
320         s4 value;
321 } constant_integer;
322
323         
324 typedef struct {            /* Float                                          */
325         float value;
326 } constant_float;
327
328
329 typedef struct {            /* Long                                           */
330         s8 value;
331 } constant_long;
332         
333
334 typedef struct {            /* Double                                         */
335         double value;
336 } constant_double;
337
338
339 typedef struct {            /* NameAndType (Field or Method)                  */
340         utf *name;              /* field/method name                              */
341         utf *descriptor;        /* field/method type descriptor string            */
342 } constant_nameandtype;
343
344
345 /* data structures of the runtime system **************************************/
346
347 /* objects *********************************************************************
348
349         All objects (and arrays) which resides on the heap need the following
350         header at the beginning of the data structure.
351 */
352
353 struct java_objectheader {              /* header for all objects             */
354         vftbl *vftbl;                       /* pointer to virtual function table  */
355 };
356
357
358
359 /* arrays **********************************************************************
360
361         All arrays are objects (they need the object header with a pointer
362         to a vftbl (array class table). There is one class for each array
363         type. The array type is described by an arraydescriptor struct
364         which is referenced by the vftbl.
365 */
366
367 /* CAUTION: Don't change the numerical values! These constants (with
368  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
369  * primitive type table.
370  */
371 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
372 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
373 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
374 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
375 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
376 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
377 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
378 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
379 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
380
381 typedef struct java_arrayheader {       /* header for all arrays              */
382         java_objectheader objheader;        /* object header                      */
383         s4 size;                            /* array size                         */
384 #ifdef SIZE_FROM_CLASSINFO
385         s4 alignedsize; /* phil */
386 #endif
387 } java_arrayheader;
388
389
390
391 /* structs for all kinds of arrays ********************************************/
392
393 typedef struct java_chararray {
394         java_arrayheader header;
395         u2 data[1];
396 } java_chararray;
397
398 typedef struct java_floatheader {
399         java_arrayheader header;
400         float data[1];
401 } java_floatarray;
402
403 typedef struct java_doublearray {
404         java_arrayheader header;
405         double data[1];
406 } java_doublearray;
407
408 /*  booleanarray and bytearray need identical memory layout (access methods
409     use the same machine code */
410
411 typedef struct java_booleanarray {
412         java_arrayheader header;
413         u1 data[1];
414 } java_booleanarray;
415
416 typedef struct java_bytearray {
417         java_arrayheader header;
418         s1 data[1];
419 } java_bytearray;
420
421 typedef struct java_shortarray {
422         java_arrayheader header;
423         s2 data[1];
424 } java_shortarray;
425
426 typedef struct java_intarray {
427         java_arrayheader header;
428         s4 data[1];
429 } java_intarray;
430
431 typedef struct java_longarray {
432         java_arrayheader header;
433         s8 data[1];
434 } java_longarray;
435
436 /*  objectarray and arrayarray need identical memory layout (access methods
437     use the same machine code */
438
439 typedef struct java_objectarray {
440         java_arrayheader header;
441         java_objectheader *data[1];
442 } java_objectarray;
443
444
445 /* structure for primitive classes ********************************************/
446
447 typedef struct primitivetypeinfo {
448         classinfo *class_wrap;               /* class for wrapping primitive type */
449         classinfo *class_primitive;          /* primitive class                   */
450         char      *wrapname;                 /* name of class for wrapping        */
451         char      typesig;                   /* one character type signature      */
452         char      *name;                     /* name of primitive class           */
453         char      *arrayname;                /* name of primitive array class     */
454         classinfo *arrayclass;               /* primitive array class             */
455         vftbl     *arrayvftbl;               /* vftbl of primitive array class    */
456 } primitivetypeinfo;
457
458
459 /* field, method and class structures *****************************************/
460
461 #include "sets.h"
462 typedef struct xtafldinfo {
463         bool       fieldChecked;                
464         classinfo *fldClassType;
465         classSet  *XTAclassSet;          /* field class type set                  */
466 } xtafldinfo;
467
468
469 /* fieldinfo ******************************************************************/
470
471 struct fieldinfo {            /* field of a class                                 */
472         s4  flags;            /* ACC flags                                        */
473         s4  type;             /* basic data type                                  */
474         utf *name;            /* name of field                                    */
475         utf *descriptor;      /* JavaVM descriptor string of field                */
476         
477         s4  offset;           /* offset from start of object (instance variables) */
478
479         imm_union value;      /* storage for static values (class variables)      */
480
481         classinfo *class;     /* XXX needed by typechecker. Could be optimized    */
482                               /* away by using constant_FMIref instead of         */
483                               /* fieldinfo throughout the compiler.               */
484         
485         xtafldinfo *xta;
486 };
487
488 struct basicblock;
489
490
491 /* exceptiontable *************************************************************/
492
493 typedef struct xtable { /* exceptiontable entry in a method           */ 
494         s4         startpc;         /* start pc of guarded area (inclusive)       */
495         struct basicblock *start;
496
497         s4         endpc;           /* end pc of guarded area (exklusive)         */
498         struct basicblock *end;
499
500         s4         handlerpc;       /* pc of exception handler                    */
501         struct basicblock *handler;
502
503         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
504         struct xtable *next;        /* used to build a list of exception when     */
505                                     /* loops are copied */
506         struct xtable *down;        /* instead of the old array, a list is used   */
507 } xtable;
508
509
510 typedef struct exceptiontable { /* exceptiontable entry in a method           */ 
511         s4         startpc;         /* start pc of guarded area (inclusive)       */
512         s4         endpc;           /* end pc of guarded area (exklusive)         */
513         s4         handlerpc;       /* pc of exception handler                    */
514         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
515 } exceptiontable;
516
517
518 /* methodinfo  static info ****************************************************/
519 typedef struct xtainfo {
520         s4          XTAmethodUsed;     /* XTA if used in callgraph - not used /used */
521         classSet    *XTAclassSet;      /* method class type set                 */ 
522         /*classSet      *PartClassSet */   /* method class type set                 */ 
523
524         classSetNode    *paramClassSet; /* cone set of methods parameters       */
525
526         methSet         *calls;            /* methods this method calls                 */ 
527         methSet         *calledBy;         /* methods that call this method         */ 
528         methSet         *marked;           /* methods that marked by this method    */ 
529         /*methSet         *markedBy*/
530         fldSet          *fldsUsed;         /* fields used by this method             */ 
531         /*methSetNode  *interfaceCalls*/   /* methods this method calls as interface */ 
532         bool           chgdSinceLastParse; /* Changed since last parse ?          */
533 } xtainfo; 
534
535
536 /* methodinfo *****************************************************************/
537
538 struct methodinfo {                 /* method structure                       */
539         s4             flags;               /* ACC flags                              */
540         utf       *name;                /* name of method                         */
541         utf       *descriptor;          /* JavaVM descriptor string of method     */
542         s4         returntype;          /* only temporary valid, return type      */
543         classinfo *returnclass;         /* pointer to classinfo for the rtn type  */ /*XTA*/ 
544         s4         paramcount;          /* only temporary valid, parameter count  */
545         u1        *paramtypes;          /* only temporary valid, parameter types  */
546         classinfo **paramclass;         /* pointer to classinfo for a parameter   */ /*XTA*/
547         
548         classinfo *class;               /* class, the method belongs to           */
549         s4         vftblindex;          /* index of method in virtual function table
550                                            (if it is a virtual method)            */
551         s4         maxstack;            /* maximum stack depth of method          */
552         s4         maxlocals;           /* maximum number of local variables      */
553         s4         jcodelength;         /* length of JavaVM code                  */
554         u1        *jcode;               /* pointer to JavaVM code                 */
555
556         s4         exceptiontablelength;/* exceptiontable length                  */
557         exceptiontable *exceptiontable; 
558                                     /* the exceptiontable                     */
559
560         u1        *stubroutine;         /* stub for compiling or calling natives  */    
561         s4         mcodelength;         /* legth of generated machine code        */
562         u1        *mcode;               /* pointer to machine code                */
563         u1        *entrypoint;          /* entry point in machine code            */
564
565         /*rtainfo   rta;*/
566         xtainfo    *xta;
567
568         s4        methodUsed;           /* marked (might be used later) /not used /used */
569         s4        monoPoly;             /* call is mono or poly or unknown        */ /*RT stats */
570         /* should # method def'd and used be kept after static parse (will it be used?) */
571         s4        subRedefs;
572         s4        subRedefsUsed;
573 };
574
575
576 /* innerclassinfo *************************************************************/
577
578 typedef struct innerclassinfo {
579         classinfo *inner_class;       /* inner class pointer                      */
580         classinfo *outer_class;       /* outer class pointer                      */
581         utf *name;                    /* innerclass name                          */ 
582         s4 flags;                     /* ACC flags                                */
583 } innerclassinfo;
584
585
586 /* classinfo ******************************************************************/
587
588 struct classinfo {                /* class structure                          */
589         java_objectheader header;     /* classes are also objects                 */
590         java_objectarray* signers;
591         struct java_security_ProtectionDomain* pd;
592         struct java_lang_VMClass* vmClass;
593         struct java_lang_reflect_Constructor* constructor;
594
595
596         s4 initializing_thread;       /* gnu classpath */
597         s4 erroneous_state;           /* gnu classpath */
598         struct gnu_classpath_RawData* vmData; /* gnu classpath */
599
600         s4          flags;            /* ACC flags                                */
601         utf        *name;             /* class name                               */ 
602
603         s4          cpcount;          /* number of entries in constant pool       */
604         u1         *cptags;           /* constant pool tags                       */
605         voidptr    *cpinfos;          /* pointer to constant pool info structures */
606
607         classinfo  *super;            /* super class pointer                      */
608         classinfo  *sub;              /* sub class pointer                        */
609         classinfo  *nextsub;          /* pointer to next class in sub class list  */
610
611         s4          interfacescount;  /* number of interfaces                     */
612         classinfo **interfaces;       /* pointer to interfaces                    */
613
614         s4          fieldscount;      /* number of fields                         */
615         fieldinfo  *fields;           /* field table                              */
616
617         s4          methodscount;     /* number of methods                        */
618         methodinfo *methods;          /* method table                             */
619
620         listnode    listnode;         /* linkage                                  */
621
622         bool        initialized;      /* true, if class already initialised       */ 
623         bool        loaded;           /* true, if class already loaded            */
624         bool        linked;           /* true, if class already linked            */
625         s4          index;            /* hierarchy depth (classes) or index
626                                          (interfaces)                             */ 
627         s4          instancesize;     /* size of an instance of this class        */
628 #ifdef SIZE_FROM_CLASSINFO
629         s4          alignedsize;      /* size of an instance, aligned to the 
630                                                                          allocation size on the heap              */
631 #endif
632
633         vftbl      *vftbl;            /* pointer to virtual function table        */
634
635         methodinfo *finalizer;        /* finalizer method                         */
636
637     u2             innerclasscount;   /* number of inner classes              */
638     innerclassinfo *innerclass;
639
640     classinfo      *hashlink;         /* link for external hash chain         */
641         bool        classvftbl;       /* has its own copy of the Class vtbl       */
642
643         s4          classUsed;        /* 0= not used 1 = used   CO-RT             */
644
645         classSetNode *impldBy;        /* implemented by class set                 */
646 };
647
648 /* check if class is an array class. Only use for linked classes! */
649 #define CLASS_IS_ARRAY(clsinfo)  ((clsinfo)->vftbl->arraydesc != NULL)
650
651
652 /* virtual function table ******************************************************
653
654         The vtbl has a bidirectional layout with open ends at both sides.
655         interfacetablelength gives the number of entries of the interface table at
656         the start of the vftbl. The vftbl pointer points to &interfacetable[0].
657         vftbllength gives the number of entries of table at the end of the vftbl.
658
659         runtime type check (checkcast):
660
661         Different methods are used for runtime type check depending on the
662         argument of checkcast/instanceof.
663         
664         A check against a class is implemented via relative numbering on the class
665         hierachy tree. The tree is numbered in a depth first traversal setting
666         the base field and the diff field. The diff field gets the result of
667         (high - base) so that a range check can be implemented by an unsigned
668         compare. A sub type test is done by checking the inclusion of base of
669         the sub class in the range of the superclass.
670
671         A check against an interface is implemented via the interfacevftbl. If the
672         interfacevftbl contains a nonnull value a class is a subclass of this
673         interface.
674
675         interfacetable:
676
677         Like standard virtual methods interface methods are called using
678         virtual function tables. All interfaces are numbered sequentially
679         (starting with zero). For each class there exist an interface table
680         of virtual function tables for each implemented interface. The length
681         of the interface table is determined by the highest number of an
682         implemented interface.
683
684         The following example assumes a class which implements interface 0 and 3:
685
686         interfacetablelength = 4
687
688                   | ...       |            +----------+
689                       +-----------+            | method 2 |---> method z
690                       | class     |            | method 1 |---> method y
691                       +-----------+            | method 0 |---> method x
692                       | ivftbl  0 |----------> +----------+
693         vftblptr ---> +-----------+
694                   | ivftbl -1 |--> NULL    +----------+
695                   | ivftbl -2 |--> NULL    | method 1 |---> method x
696                   | ivftbl -3 |-----+      | method 0 |---> method a
697                   +-----------+     +----> +----------+
698      
699                               +---------------+
700                                   | length 3 = 2  |
701                                   | length 2 = 0  |
702                                   | length 1 = 0  |
703                                   | length 0 = 3  |
704         interfacevftbllength ---> +---------------+
705
706 *******************************************************************************/
707
708 struct vftbl {
709         methodptr   *interfacetable[1];    /* interface table (access via macro)  */
710
711         classinfo   *class;                /* class, the vtbl belongs to          */
712
713         arraydescriptor *arraydesc;        /* for array classes, otherwise NULL   */
714
715         s4           vftbllength;          /* virtual function table length       */
716         s4           interfacetablelength; /* interface table length              */
717
718         s4           baseval;              /* base for runtime type check         */
719                                            /* (-index for interfaces)             */
720         s4           diffval;              /* high - base for runtime type check  */
721
722         s4          *interfacevftbllength; /* length of interface vftbls          */
723         
724         methodptr    table[1];             /* class vftbl                         */
725 };
726
727 #define VFTBLINTERFACETABLE(v,i)       (v)->interfacetable[-i]
728
729
730 /* arraydescriptor ************************************************************
731
732     For every array class an arraydescriptor is allocated which
733     describes the array class.
734         The arraydescriptor is referenced from the vftbl of the array
735         class.
736
737 *******************************************************************************/
738
739 struct arraydescriptor {
740         vftbl *componentvftbl;   /* vftbl of the component type, NULL for primit. */
741         vftbl *elementvftbl;     /* vftbl of the element type, NULL for primitive */
742         short  arraytype;        /* ARRAYTYPE_* constant                          */
743         short  dimension;        /* dimension of the array (always >= 1)          */
744     s4     dataoffset;       /* offset of the array data from object pointer  */
745         s4     componentsize;    /* size of a component in bytes                  */
746         short  elementtype;      /* ARRAYTYPE_* constant (XXX optimize away?)     */
747 };
748
749
750 /* references to some system classes ******************************************/
751
752 extern classinfo *class_java_lang_Object;
753 extern classinfo *class_java_lang_String;
754 extern classinfo *class_java_lang_Throwable;
755 extern classinfo *class_java_lang_Cloneable;
756 extern classinfo *class_java_io_Serializable;
757 extern classinfo *class_java_lang_ClassCastException;
758 extern classinfo *class_java_lang_NullPointerException;
759 extern classinfo *class_java_lang_ArrayIndexOutOfBoundsException;
760 extern classinfo *class_java_lang_NegativeArraySizeException;
761 extern classinfo *class_java_lang_OutOfMemoryError;
762 extern classinfo *class_java_lang_ArithmeticException;
763 extern classinfo *class_java_lang_ArrayStoreException;
764 extern classinfo *class_java_lang_ThreadDeath;
765 extern classinfo *pseudo_class_Arraystub;
766 extern classinfo *pseudo_class_Null;
767 extern classinfo *pseudo_class_New;
768 extern vftbl *pseudo_class_Arraystub_vftbl;
769
770
771 /* instances of some system classes *******************************************/
772
773 extern java_objectheader *proto_java_lang_ClassCastException;
774 extern java_objectheader *proto_java_lang_NullPointerException;
775 extern java_objectheader *proto_java_lang_ArrayIndexOutOfBoundsException;
776 extern java_objectheader *proto_java_lang_NegativeArraySizeException;
777 extern java_objectheader *proto_java_lang_OutOfMemoryError;
778 extern java_objectheader *proto_java_lang_ArithmeticException;
779 extern java_objectheader *proto_java_lang_ArrayStoreException;
780 extern java_objectheader *proto_java_lang_ThreadDeath;
781
782
783 /* flag variables *************************************************************/
784
785 extern bool compileall;
786 extern bool runverbose;         
787 extern bool verbose;         
788 extern bool opt_rt;             /* Rapid Type Analysis for better inlining CO-RT*/
789 extern bool opt_xta;            /* X Type Analysis for better inlining    CO-XTA*/
790 extern bool opt_vta;            /* Variable Type Analysis for better inlining    CO-VTA*/
791 extern bool opt_verify;         /* true if classfiles should be verified      */
792 #ifdef TYPECHECK_VERBOSE_OPT
793 extern bool typecheckverbose;
794 #endif
795
796 /*extern int pClassHeir;*/
797 /*extern int pCallgraph;*/
798 /*extern int pOpcodes;*/
799 /*extern int pStats;*/
800
801 /*extern void RT_jit_parse(methodinfo *m);*/
802
803
804 /* statistic variables ********************************************************/
805
806 extern int count_class_infos;
807 extern int count_const_pool_len;
808 extern int count_vftbl_len;
809 extern int count_utf_len;
810 extern int count_all_methods;
811 extern int count_vmcode_len;
812 extern int count_extable_len;
813 extern int count_class_loads;
814 extern int count_class_inits;
815 extern int count_utf_new;
816 extern int count_utf_new_found;
817
818
819 /* table of primitive types ***************************************************/
820
821 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
822  * constants (except ARRAYTYPE_OBJECT).
823  */
824 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
825
826
827 /* macros for descriptor parsing **********************************************/
828
829 /* SKIP_FIELDDESCRIPTOR:
830  * utf_ptr must point to the first character of a field descriptor.
831  * After the macro call utf_ptr points to the first character after
832  * the field descriptor.
833  *
834  * CAUTION: This macro does not check for an unexpected end of the
835  * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE.
836  */
837 #define SKIP_FIELDDESCRIPTOR(utf_ptr)                                                   \
838         do { while (*(utf_ptr)=='[') (utf_ptr)++;                                       \
839                 if (*(utf_ptr)++=='L')                                                                  \
840                         while(*(utf_ptr)++ != ';') /* skip */; } while(0)
841
842 /* SKIP_FIELDDESCRIPTOR_SAFE:
843  * utf_ptr must point to the first character of a field descriptor.
844  * After the macro call utf_ptr points to the first character after
845  * the field descriptor.
846  *
847  * Input:
848  *     utf_ptr....points to first char of descriptor
849  *     end_ptr....points to first char after the end of the string
850  *     errorflag..must be initialized (to false) by the caller!
851  * Output:
852  *     utf_ptr....points to first char after the descriptor
853  *     errorflag..set to true if the string ended unexpectedly
854  */
855 #define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag)                    \
856         do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++;     \
857                 if ((utf_ptr) == (end_ptr))                                                                             \
858                         (errorflag) = true;                                                                                     \
859                 else                                                                                                                    \
860                         if (*(utf_ptr)++=='L') {                                                                        \
861                                 while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';')    \
862                                         /* skip */;                                                                                     \
863                                 if ((utf_ptr)[-1] != ';')                                                               \
864                                         (errorflag) = true; }} while(0)
865
866
867 /* Synchronization ************************************************************/
868
869 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
870 extern pthread_mutex_t compiler_mutex;
871 extern int cast_counter;
872
873 void cast_lock();
874 void cast_lock2();
875 #endif
876
877 #endif /* _GLOBAL_H */
878
879
880 /*
881  * These are local overrides for various environment variables in Emacs.
882  * Please do not remove this and leave it at the end of the file, where
883  * Emacs will automagically detect them.
884  * ---------------------------------------------------------------------
885  * Local variables:
886  * mode: c
887  * indent-tabs-mode: t
888  * c-basic-offset: 4
889  * tab-width: 4
890  * End:
891  */