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