verifier documentation
[cacao.git] / global.h
1 /* global.h - global definitions
2
3    Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4    R. Grafl, A. Krall, C. Kruegel, C. Oates, R. Obermaisser,
5    M. Probst, S. Ring, E. Steiner, C. Thalinger, D. Thuernbeck,
6    P. Tomsich, J. Wenninger
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28             Andreas Krall
29
30    Changes: Mark Probst
31             Philipp Tomsich
32                         Edwin Steiner
33
34    $Id: global.h 871 2004-01-11 00:55:25Z edwin $
35
36 */
37
38
39 #ifndef _GLOBAL_H
40 #define _GLOBAL_H
41
42 #define _GNU_SOURCE
43
44 #include "config.h"
45 #include "types.h"
46 #include "toolbox/list.h"
47
48 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
49 #include <pthread.h>
50 #endif
51
52 #define STATISTICS          /* if enabled collects program statistics         */
53
54 /* 
55  * SIZE_FROM_CLASSINFO toggles between the bitmap_based and the new method 
56  * of determining the sizes of objects on the heap.
57  */
58 #define SIZE_FROM_CLASSINFO
59
60 /*
61  * CACAO_TYPECHECK activates typechecking (part of bytecode verification)
62  */
63 #define CACAO_TYPECHECK
64
65 /*
66  * TYPECHECK_STACK_COMPCAT activates full checking of computational
67  * categories for stack manipulations (POP,POP2,SWAP,DUP,DUP2,DUP_X1,
68  * DUP2_X1,DUP_X2,DUP2_X2).
69  */
70 /* #define TYPECHECK_STACK_COMPCAT */
71
72 /*
73  * Macros for configuration of the typechecking code
74  *
75  * TYPEINFO_DEBUG activates debug checks and debug helpers in typeinfo.c
76  * TYPECHECK_DEBUG activates debug checks in typecheck.c
77  * TYPEINFO_DEBUG_TEST activates the typeinfo test at startup.
78  * TYPECHECK_VERBOSE_IMPORTANT activates important debug messages
79  * TYPECHECK_VERBOSE activates all debug messages
80  */
81 #ifdef CACAO_TYPECHECK
82 #define TYPEINFO_DEBUG
83 #define TYPECHECK_DEBUG
84 /*#define TYPEINFO_DEBUG_TEST*/
85 #define TYPECHECK_VERBOSE
86 /*#define TYPECHECK_VERBOSE_IMPORTANT*/
87 #if defined(TYPECHECK_VERBOSE) || defined(TYPECHECK_VERBOSE_IMPORTANT)
88 #define TYPECHECK_VERBOSE_OPT
89 #endif
90 #endif
91
92
93 /* additional data types ******************************************************/
94
95 typedef void *voidptr;          /* generic pointer */
96
97 typedef int   bool;             /* boolean data type */
98
99 #define true  1
100 #define false 0
101
102
103 /* immediate data union */
104
105 typedef union {
106     s4 i;
107     s8 l;
108     float f;
109     double d;
110     void *a;
111     u1 b[8];
112 } imm_union;
113
114
115 #define PRIMITIVETYPE_COUNT  9  /* number of primitive types */
116
117 /* CAUTION: Don't change the numerical values! These constants are
118  * used as indices into the primitive type table.
119  */
120 #define PRIMITIVETYPE_INT     0
121 #define PRIMITIVETYPE_LONG    1
122 #define PRIMITIVETYPE_FLOAT   2
123 #define PRIMITIVETYPE_DOUBLE  3
124 #define PRIMITIVETYPE_BYTE    4
125 #define PRIMITIVETYPE_CHAR    5
126 #define PRIMITIVETYPE_SHORT   6
127 #define PRIMITIVETYPE_BOOLEAN 7
128 #define PRIMITIVETYPE_VOID    8
129
130 typedef void (*functionptr) (); /* generic function pointer */
131
132
133 #define MAX_ALIGN 8             /* most generic alignment for JavaVM values   */
134
135 /* shutdown function **********************************************************/
136
137 void cacao_shutdown(s4 status);
138
139
140 /* basic data types ***********************************************************/
141
142 /* CAUTION: jit/jit.h relies on these numerical values! */
143 #define TYPE_INT      0         /* the JavaVM types must numbered in the      */
144 #define TYPE_LONG     1         /* same order as the ICMD_Ixxx to ICMD_Axxx   */
145 #define TYPE_FLOAT    2         /* instructions (LOAD and STORE)              */
146 #define TYPE_DOUBLE   3         /* integer, long, float, double, address      */
147 #define TYPE_ADDRESS  4         /* all other types can be numbered arbitrarly */
148
149 #define TYPE_VOID    10
150
151
152 /* Java class file constants **************************************************/
153
154 #define MAGIC         0xcafebabe
155 #define MINOR_VERSION 3
156 #define MAJOR_VERSION 45
157
158 #define CONSTANT_Class                 7
159 #define CONSTANT_Fieldref              9
160 #define CONSTANT_Methodref            10
161 #define CONSTANT_InterfaceMethodref   11
162 #define CONSTANT_String                8
163 #define CONSTANT_Integer               3
164 #define CONSTANT_Float                 4
165 #define CONSTANT_Long                  5
166 #define CONSTANT_Double                6
167 #define CONSTANT_NameAndType          12
168 #define CONSTANT_Utf8                  1
169
170 #define CONSTANT_UNUSED                0
171
172 #define ACC_PUBLIC                0x0001
173 #define ACC_PRIVATE               0x0002
174 #define ACC_PROTECTED             0x0004
175 #define ACC_STATIC                0x0008
176 #define ACC_FINAL                 0x0010
177 #define ACC_SUPER                 0x0020
178 #define ACC_SYNCHRONIZED          0x0020
179 #define ACC_VOLATILE              0x0040
180 #define ACC_TRANSIENT             0x0080
181 #define ACC_NATIVE                0x0100
182 #define ACC_INTERFACE             0x0200
183 #define ACC_ABSTRACT              0x0400
184 #define ACC_STRICT                0x0800
185
186 /* resolve typedef cycles *****************************************************/
187
188 typedef struct utf utf;
189 typedef struct literalstring literalstring;
190 typedef struct java_objectheader java_objectheader; 
191 typedef struct classinfo classinfo; 
192 typedef struct vftbl vftbl;
193 typedef u1* methodptr;
194 typedef struct fieldinfo  fieldinfo; 
195 typedef struct methodinfo methodinfo; 
196 typedef struct arraydescriptor arraydescriptor;
197
198
199 /* constant pool entries *******************************************************
200
201         All constant pool entries need a data structure which contain the entrys
202         value. In some cases this structure exist already, in the remaining cases
203         this structure must be generated:
204
205                 kind                      structure                     generated?
206         ----------------------------------------------------------------------
207     CONSTANT_Class               classinfo                           no
208     CONSTANT_Fieldref            constant_FMIref                    yes
209     CONSTANT_Methodref           constant_FMIref                    yes
210     CONSTANT_InterfaceMethodref  constant_FMIref                    yes
211     CONSTANT_String              unicode                             no
212     CONSTANT_Integer             constant_integer                   yes
213     CONSTANT_Float               constant_float                     yes
214     CONSTANT_Long                constant_long                      yes
215     CONSTANT_Double              constant_double                    yes
216     CONSTANT_NameAndType         constant_nameandtype               yes
217     CONSTANT_Utf8                unicode                             no
218     CONSTANT_UNUSED              -
219
220 *******************************************************************************/
221
222 /* data structures for hashtables ********************************************
223
224
225         All utf-symbols, javastrings and classes are stored in global hashtables,
226         so every symbol exists only once. Equal symbols have identical pointers.
227         The functions for adding hashtable elements search the table for the 
228         element with the specified name/text and return it on success. Otherwise a 
229         new hashtable element is created.
230
231     The hashtables use external linking for handling collisions. The hashtable 
232         structure contains a pointer <ptr> to the array of hashtable slots. The 
233         number of hashtable slots and therefore the size of this array is specified 
234         by the element <size> of hashtable structure. <entries> contains the number
235         of all hashtable elements stored in the table, including those in the 
236         external chains.
237         The hashtable element structures (utf, literalstring, classinfo) contain
238         both a pointer to the next hashtable element as a link for the external hash 
239         chain and the key of the element. The key is computed from the text of
240         the string or the classname by using up to 8 characters.
241         
242         If the number of entries in the hashtable exceeds twice the size of the 
243         hashtableslot-array it is supposed that the average length of the 
244         external chains has reached a value beyond 2. Therefore the functions for
245         adding hashtable elements (utf_new, class_new, literalstring_new) double
246         the hashtableslot-array. In this restructuring process all elements have
247         to be inserted into the new hashtable and new external chains must be built.
248
249
250 example for the layout of a hashtable:
251
252 hashtable.ptr-->  +-------------------+
253                   |                   |
254                            ...
255                   |                   |
256                   +-------------------+   +-------------------+   +-------------------+
257                   | hashtable element |-->| hashtable element |-->| hashtable element |-->NULL
258                   +-------------------+   +-------------------+   +-------------------+
259                   | hashtable element |
260                   +-------------------+   +-------------------+   
261                   | hashtable element |-->| hashtable element |-->NULL
262                   +-------------------+   +-------------------+   
263                   | hashtable element |-->NULL
264                   +-------------------+
265                   |                   |
266                            ...
267                   |                   |
268                   +-------------------+
269
270 */
271
272
273 /* data structure for utf8 symbols ********************************************/
274
275 struct utf {
276         utf        *hashlink;       /* link for external hash chain               */
277         int         blength;        /* text length in bytes                       */           
278         char       *text;           /* pointer to text                            */
279 };
280
281
282 /* data structure of internal javastrings stored in global hashtable **********/
283
284 struct literalstring {
285         literalstring     *hashlink;     /* link for external hash chain          */
286         java_objectheader *string;  
287 };
288
289
290 /* data structure for calls from c code to java methods */
291
292 struct jni_callblock {
293         u1 itemtype;
294         u8 item;
295 };
296
297 typedef struct jni_callblock jni_callblock;
298
299
300 /* data structure for accessing hashtables ************************************/
301
302 typedef struct {            
303         u4 size;
304         u4 entries;        /* number of entries in the table */
305         void **ptr;        /* pointer to hashtable */
306 } hashtable;
307
308
309 /* data structures of remaining constant pool entries *************************/
310
311 typedef struct {            /* Fieldref, Methodref and InterfaceMethodref     */
312         classinfo *class;       /* class containing this field/method/interface   */
313         utf       *name;        /* field/method/interface name                    */
314         utf       *descriptor;  /* field/method/interface type descriptor string  */
315 } constant_FMIref;
316
317
318 typedef struct {            /* Integer                                        */
319         s4 value;
320 } constant_integer;
321
322         
323 typedef struct {            /* Float                                          */
324         float value;
325 } constant_float;
326
327
328 typedef struct {            /* Long                                           */
329         s8 value;
330 } constant_long;
331         
332
333 typedef struct {            /* Double                                         */
334         double value;
335 } constant_double;
336
337
338 typedef struct {            /* NameAndType (Field or Method)                  */
339         utf *name;              /* field/method name                              */
340         utf *descriptor;        /* field/method type descriptor string            */
341 } constant_nameandtype;
342
343
344 /* data structures of the runtime system **************************************/
345
346 /* objects *********************************************************************
347
348         All objects (and arrays) which resides on the heap need the following
349         header at the beginning of the data structure.
350 */
351
352 struct java_objectheader {              /* header for all objects             */
353         vftbl *vftbl;                       /* pointer to virtual function table  */
354 };
355
356
357
358 /* arrays **********************************************************************
359
360         All arrays are objects (they need the object header with a pointer
361         to a vftbl (array class table). There is one class for each array
362         type. The array type is described by an arraydescriptor struct
363         which is referenced by the vftbl.
364 */
365
366 /* CAUTION: Don't change the numerical values! These constants (with
367  * the exception of ARRAYTYPE_OBJECT) are used as indices in the
368  * primitive type table.
369  */
370 #define ARRAYTYPE_INT      PRIMITIVETYPE_INT
371 #define ARRAYTYPE_LONG     PRIMITIVETYPE_LONG
372 #define ARRAYTYPE_FLOAT    PRIMITIVETYPE_FLOAT
373 #define ARRAYTYPE_DOUBLE   PRIMITIVETYPE_DOUBLE
374 #define ARRAYTYPE_BYTE     PRIMITIVETYPE_BYTE
375 #define ARRAYTYPE_CHAR     PRIMITIVETYPE_CHAR
376 #define ARRAYTYPE_SHORT    PRIMITIVETYPE_SHORT
377 #define ARRAYTYPE_BOOLEAN  PRIMITIVETYPE_BOOLEAN
378 #define ARRAYTYPE_OBJECT   PRIMITIVETYPE_VOID     /* don't use as index! */
379
380 typedef struct java_arrayheader {       /* header for all arrays              */
381         java_objectheader objheader;        /* object header                      */
382         s4 size;                            /* array size                         */
383 #ifdef SIZE_FROM_CLASSINFO
384         s4 alignedsize; /* phil */
385 #endif
386 } java_arrayheader;
387
388
389
390 /* structs for all kinds of arrays ********************************************/
391
392 typedef struct java_chararray {
393         java_arrayheader header;
394         u2 data[1];
395 } java_chararray;
396
397 typedef struct java_floatheader {
398         java_arrayheader header;
399         float data[1];
400 } java_floatarray;
401
402 typedef struct java_doublearray {
403         java_arrayheader header;
404         double data[1];
405 } java_doublearray;
406
407 /*  booleanarray and bytearray need identical memory layout (access methods
408     use the same machine code */
409
410 typedef struct java_booleanarray {
411         java_arrayheader header;
412         u1 data[1];
413 } java_booleanarray;
414
415 typedef struct java_bytearray {
416         java_arrayheader header;
417         s1 data[1];
418 } java_bytearray;
419
420 typedef struct java_shortarray {
421         java_arrayheader header;
422         s2 data[1];
423 } java_shortarray;
424
425 typedef struct java_intarray {
426         java_arrayheader header;
427         s4 data[1];
428 } java_intarray;
429
430 typedef struct java_longarray {
431         java_arrayheader header;
432         s8 data[1];
433 } java_longarray;
434
435 /*  objectarray and arrayarray need identical memory layout (access methods
436     use the same machine code */
437
438 typedef struct java_objectarray {
439         java_arrayheader header;
440         java_objectheader *data[1];
441 } java_objectarray;
442
443
444 /* structure for primitive classes ********************************************/
445
446 typedef struct primitivetypeinfo {
447         classinfo *class_wrap;               /* class for wrapping primitive type */
448         classinfo *class_primitive;          /* primitive class                   */
449         char      *wrapname;                 /* name of class for wrapping        */
450         char      typesig;                   /* one character type signature      */
451         char      *name;                     /* name of primitive class           */
452         char      *arrayname;                /* name of primitive array class     */
453         classinfo *arrayclass;               /* primitive array class             */
454         vftbl     *arrayvftbl;               /* vftbl of primitive array class    */
455 } primitivetypeinfo;
456
457
458 /* field, method and class structures *****************************************/
459
460 #include "sets.h"
461 typedef struct xtafldinfo {
462         bool       fieldChecked;                
463         classinfo *fldClassType;
464         classSet  *XTAclassSet;          /* field class type set                  */
465 } xtafldinfo;
466
467
468 /* fieldinfo ******************************************************************/
469
470 struct fieldinfo {            /* field of a class                                 */
471         s4  flags;            /* ACC flags                                        */
472         s4  type;             /* basic data type                                  */
473         utf *name;            /* name of field                                    */
474         utf *descriptor;      /* JavaVM descriptor string of field                */
475         
476         s4  offset;           /* offset from start of object (instance variables) */
477
478         imm_union value;      /* storage for static values (class variables)      */
479
480         classinfo *class;     /* XXX needed by typechecker. Could be optimized    */
481                               /* away by using constant_FMIref instead of         */
482                               /* fieldinfo throughout the compiler.               */
483         
484         xtafldinfo *xta;
485 };
486
487 struct basicblock;
488
489
490 /* exceptiontable *************************************************************/
491
492 typedef struct xtable { /* exceptiontable entry in a method           */ 
493         s4         startpc;         /* start pc of guarded area (inclusive)       */
494         struct basicblock *start;
495
496         s4         endpc;           /* end pc of guarded area (exklusive)         */
497         struct basicblock *end;
498
499         s4         handlerpc;       /* pc of exception handler                    */
500         struct basicblock *handler;
501
502         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
503         struct xtable *next;        /* used to build a list of exception when     */
504                                     /* loops are copied */
505         struct xtable *down;        /* instead of the old array, a list is used   */
506 } xtable;
507
508
509 typedef struct exceptiontable { /* exceptiontable entry in a method           */ 
510         s4         startpc;         /* start pc of guarded area (inclusive)       */
511         s4         endpc;           /* end pc of guarded area (exklusive)         */
512         s4         handlerpc;       /* pc of exception handler                    */
513         classinfo *catchtype;       /* catchtype of exception (NULL == catchall)  */
514 } exceptiontable;
515
516
517 /* methodinfo  static info ****************************************************/
518 typedef struct xtainfo {
519         s4          XTAmethodUsed;     /* XTA if used in callgraph - not used /used */
520         classSet    *XTAclassSet;      /* method class type set                 */ 
521         /*classSet      *PartClassSet */   /* method class type set                 */ 
522
523         classSetNode    *paramClassSet; /* cone set of methods parameters       */
524
525         methSet         *calls;            /* methods this method calls                 */ 
526         methSet         *calledBy;         /* methods that call this method         */ 
527         methSet         *marked;           /* methods that marked by this method    */ 
528         /*methSet         *markedBy*/
529         fldSet          *fldsUsed;         /* fields used by this method             */ 
530         /*methSetNode  *interfaceCalls*/   /* methods this method calls as interface */ 
531         bool           chgdSinceLastParse; /* Changed since last parse ?          */
532 } xtainfo; 
533
534
535 /* methodinfo *****************************************************************/
536
537 struct methodinfo {                 /* method structure                       */
538         s4             flags;               /* ACC flags                              */
539         utf       *name;                /* name of method                         */
540         utf       *descriptor;          /* JavaVM descriptor string of method     */
541         s4         returntype;          /* only temporary valid, return type      */
542         classinfo *returnclass;         /* pointer to classinfo for the rtn type  */ /*XTA*/ 
543         s4         paramcount;          /* only temporary valid, parameter count  */
544         u1        *paramtypes;          /* only temporary valid, parameter types  */
545         classinfo **paramclass;         /* pointer to classinfo for a parameter   */ /*XTA*/
546         
547         classinfo *class;               /* class, the method belongs to           */
548         s4         vftblindex;          /* index of method in virtual function table
549                                            (if it is a virtual method)            */
550         s4         maxstack;            /* maximum stack depth of method          */
551         s4         maxlocals;           /* maximum number of local variables      */
552         s4         jcodelength;         /* length of JavaVM code                  */
553         u1        *jcode;               /* pointer to JavaVM code                 */
554
555         s4         exceptiontablelength;/* exceptiontable length                  */
556         exceptiontable *exceptiontable; 
557                                     /* the exceptiontable                     */
558
559         u1        *stubroutine;         /* stub for compiling or calling natives  */    
560         s4         mcodelength;         /* legth of generated machine code        */
561         u1        *mcode;               /* pointer to machine code                */
562         u1        *entrypoint;          /* entry point in machine code            */
563
564         /*rtainfo   rta;*/
565         xtainfo    *xta;
566
567         s4        methodUsed;           /* marked (might be used later) /not used /used */
568         s4        monoPoly;             /* call is mono or poly or unknown        */ /*RT stats */
569         /* should # method def'd and used be kept after static parse (will it be used?) */
570         s4        subRedefs;
571         s4        subRedefsUsed;
572 };
573
574
575 /* innerclassinfo *************************************************************/
576
577 typedef struct innerclassinfo {
578         classinfo *inner_class;       /* inner class pointer                      */
579         classinfo *outer_class;       /* outer class pointer                      */
580         utf *name;                    /* innerclass name                          */ 
581         s4 flags;                     /* ACC flags                                */
582 } innerclassinfo;
583
584
585 /* classinfo ******************************************************************/
586
587 struct classinfo {                /* class structure                          */
588         java_objectheader header;     /* classes are also objects                 */
589         java_objectarray* signers;
590         struct java_security_ProtectionDomain* pd;
591         struct java_lang_VMClass* vmClass;
592         struct java_lang_reflect_Constructor* constructor;
593
594
595         s4 initializing_thread;       /* gnu classpath */
596         s4 erroneous_state;           /* gnu classpath */
597         struct gnu_classpath_RawData* vmData; /* gnu classpath */
598
599         s4          flags;            /* ACC flags                                */
600         utf        *name;             /* class name                               */
601
602         s4          cpcount;          /* number of entries in constant pool       */
603         u1         *cptags;           /* constant pool tags                       */
604         voidptr    *cpinfos;          /* pointer to constant pool info structures */
605
606         classinfo  *super;            /* super class pointer                      */
607         classinfo  *sub;              /* sub class pointer                        */
608         classinfo  *nextsub;          /* pointer to next class in sub class list  */
609
610         s4          interfacescount;  /* number of interfaces                     */
611         classinfo **interfaces;       /* pointer to interfaces                    */
612
613         s4          fieldscount;      /* number of fields                         */
614         fieldinfo  *fields;           /* field table                              */
615
616         s4          methodscount;     /* number of methods                        */
617         methodinfo *methods;          /* method table                             */
618
619         listnode    listnode;         /* linkage                                  */
620
621         bool        initialized;      /* true, if class already initialised       */ 
622         bool        loaded;           /* true, if class already loaded            */
623         bool        linked;           /* true, if class already linked            */
624         s4          index;            /* hierarchy depth (classes) or index
625                                          (interfaces)                             */ 
626         s4          instancesize;     /* size of an instance of this class        */
627 #ifdef SIZE_FROM_CLASSINFO
628         s4          alignedsize;      /* size of an instance, aligned to the 
629                                                                          allocation size on the heap              */
630 #endif
631
632         vftbl      *vftbl;            /* pointer to virtual function table        */
633
634         methodinfo *finalizer;        /* finalizer method                         */
635
636     u2             innerclasscount;   /* number of inner classes              */
637     innerclassinfo *innerclass;
638
639     classinfo      *hashlink;         /* link for external hash chain         */
640         bool        classvftbl;       /* has its own copy of the Class vtbl       */
641
642         s4          classUsed;        /* 0= not used 1 = used   CO-RT             */
643
644         classSetNode *impldBy;        /* implemented by class set                 */
645         utf        *packagename;      /* full name of the package                 */
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 extern utf *array_packagename;
771
772
773 /* instances of some system classes *******************************************/
774
775 extern java_objectheader *proto_java_lang_ClassCastException;
776 extern java_objectheader *proto_java_lang_NullPointerException;
777 extern java_objectheader *proto_java_lang_ArrayIndexOutOfBoundsException;
778 extern java_objectheader *proto_java_lang_NegativeArraySizeException;
779 extern java_objectheader *proto_java_lang_OutOfMemoryError;
780 extern java_objectheader *proto_java_lang_ArithmeticException;
781 extern java_objectheader *proto_java_lang_ArrayStoreException;
782 extern java_objectheader *proto_java_lang_ThreadDeath;
783
784
785 /* flag variables *************************************************************/
786
787 extern bool compileall;
788 extern bool runverbose;         
789 extern bool verbose;         
790 extern bool opt_rt;             /* Rapid Type Analysis for better inlining CO-RT*/
791 extern bool opt_xta;            /* X Type Analysis for better inlining    CO-XTA*/
792 extern bool opt_vta;            /* Variable Type Analysis for better inlining    CO-VTA*/
793 extern bool opt_verify;         /* true if classfiles should be verified      */
794 #ifdef TYPECHECK_VERBOSE_OPT
795 extern bool typecheckverbose;
796 #endif
797
798 /*extern int pClassHeir;*/
799 /*extern int pCallgraph;*/
800 /*extern int pOpcodes;*/
801 /*extern int pStats;*/
802
803 /*extern void RT_jit_parse(methodinfo *m);*/
804
805
806 /* statistic variables ********************************************************/
807
808 extern int count_class_infos;
809 extern int count_const_pool_len;
810 extern int count_vftbl_len;
811 extern int count_utf_len;
812 extern int count_all_methods;
813 extern int count_vmcode_len;
814 extern int count_extable_len;
815 extern int count_class_loads;
816 extern int count_class_inits;
817 extern int count_utf_new;
818 extern int count_utf_new_found;
819
820
821 /* table of primitive types ***************************************************/
822
823 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_
824  * constants (except ARRAYTYPE_OBJECT).
825  */
826 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
827
828
829 /* macros for descriptor parsing **********************************************/
830
831 /* SKIP_FIELDDESCRIPTOR:
832  * utf_ptr must point to the first character of a field descriptor.
833  * After the macro call utf_ptr points to the first character after
834  * the field descriptor.
835  *
836  * CAUTION: This macro does not check for an unexpected end of the
837  * descriptor. Better use SKIP_FIELDDESCRIPTOR_SAFE.
838  */
839 #define SKIP_FIELDDESCRIPTOR(utf_ptr)                                                   \
840         do { while (*(utf_ptr)=='[') (utf_ptr)++;                                       \
841                 if (*(utf_ptr)++=='L')                                                                  \
842                         while(*(utf_ptr)++ != ';') /* skip */; } while(0)
843
844 /* SKIP_FIELDDESCRIPTOR_SAFE:
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  * Input:
850  *     utf_ptr....points to first char of descriptor
851  *     end_ptr....points to first char after the end of the string
852  *     errorflag..must be initialized (to false) by the caller!
853  * Output:
854  *     utf_ptr....points to first char after the descriptor
855  *     errorflag..set to true if the string ended unexpectedly
856  */
857 #define SKIP_FIELDDESCRIPTOR_SAFE(utf_ptr,end_ptr,errorflag)                    \
858         do { while ((utf_ptr) != (end_ptr) && *(utf_ptr)=='[') (utf_ptr)++;     \
859                 if ((utf_ptr) == (end_ptr))                                                                             \
860                         (errorflag) = true;                                                                                     \
861                 else                                                                                                                    \
862                         if (*(utf_ptr)++=='L') {                                                                        \
863                                 while((utf_ptr) != (end_ptr) && *(utf_ptr)++ != ';')    \
864                                         /* skip */;                                                                                     \
865                                 if ((utf_ptr)[-1] != ';')                                                               \
866                                         (errorflag) = true; }} while(0)
867
868
869 /* Synchronization ************************************************************/
870
871 #if defined(USE_THREADS) && defined(NATIVE_THREADS)
872 extern pthread_mutex_t compiler_mutex;
873 extern int cast_counter;
874
875 void cast_lock();
876 void cast_lock2();
877 void cast_unlock();
878 #endif
879
880 #endif /* _GLOBAL_H */
881
882
883 /*
884  * These are local overrides for various environment variables in Emacs.
885  * Please do not remove this and leave it at the end of the file, where
886  * Emacs will automagically detect them.
887  * ---------------------------------------------------------------------
888  * Local variables:
889  * mode: c
890  * indent-tabs-mode: t
891  * c-basic-offset: 4
892  * tab-width: 4
893  * End:
894  */