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