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