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