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