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