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