old ARGVAR handling in stack.c eliminated
[cacao.git] / src / vm / linker.h
1 /* src/vm/linker.h - class linker header
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    Institut f. Computersprachen - TU Wien
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: Christian Thalinger
28
29    Changes:
30
31    $Id: linker.h 2181 2005-04-01 16:53:33Z edwin $
32 */
33
34
35 #ifndef _LINKER_H
36 #define _LINKER_H
37
38 /* forward typedefs ***********************************************************/
39
40 typedef struct _vftbl vftbl_t;
41 typedef struct arraydescriptor arraydescriptor;
42 typedef struct primitivetypeinfo primitivetypeinfo;
43
44
45 #include "vm/references.h"
46
47
48 /* virtual function table ******************************************************
49
50    The vtbl has a bidirectional layout with open ends at both sides.
51    interfacetablelength gives the number of entries of the interface
52    table at the start of the vftbl. The vftbl pointer points to
53    &interfacetable[0].  vftbllength gives the number of entries of
54    table at the end of the vftbl.
55
56    runtime type check (checkcast):
57
58    Different methods are used for runtime type check depending on the
59    argument of checkcast/instanceof.
60         
61    A check against a class is implemented via relative numbering on
62    the class hierachy tree. The tree is numbered in a depth first
63    traversal setting the base field and the diff field. The diff field
64    gets the result of (high - base) so that a range check can be
65    implemented by an unsigned compare. A sub type test is done by
66    checking the inclusion of base of the sub class in the range of the
67    superclass.
68
69    A check against an interface is implemented via the
70    interfacevftbl. If the interfacevftbl contains a nonnull value a
71    class is a subclass of this interface.
72
73    interfacetable:
74
75    Like standard virtual methods interface methods are called using
76    virtual function tables. All interfaces are numbered sequentially
77    (starting with zero). For each class there exist an interface table
78    of virtual function tables for each implemented interface. The
79    length of the interface table is determined by the highest number
80    of an implemented interface.
81
82    The following example assumes a class which implements interface 0 and 3:
83
84    interfacetablelength = 4
85
86                   | ...       |            +----------+
87                       +-----------+            | method 2 |---> method z
88                       | class     |            | method 1 |---> method y
89                       +-----------+            | method 0 |---> method x
90                       | ivftbl  0 |----------> +----------+
91         vftblptr ---> +-----------+
92                   | ivftbl -1 |--> NULL    +----------+
93                   | ivftbl -2 |--> NULL    | method 1 |---> method x
94                   | ivftbl -3 |-----+      | method 0 |---> method a
95                   +-----------+     +----> +----------+
96      
97                               +---------------+
98                                   | length 3 = 2  |
99                                   | length 2 = 0  |
100                                   | length 1 = 0  |
101                                   | length 0 = 3  |
102         interfacevftbllength ---> +---------------+
103
104 *******************************************************************************/
105
106 struct _vftbl {
107         methodptr   *interfacetable[1];    /* interface table (access via macro)  */
108         classinfo   *class;                /* class, the vtbl belongs to          */
109         arraydescriptor *arraydesc;        /* for array classes, otherwise NULL   */
110         s4           vftbllength;          /* virtual function table length       */
111         s4           interfacetablelength; /* interface table length              */
112         s4           baseval;              /* base for runtime type check         */
113                                            /* (-index for interfaces)             */
114         s4           diffval;              /* high - base for runtime type check  */
115         s4          *interfacevftbllength; /* length of interface vftbls          */
116         methodptr    table[1];             /* class vftbl                         */
117 };
118
119
120 /* arraydescriptor *************************************************************
121
122    For every array class an arraydescriptor is allocated which
123    describes the array class. The arraydescriptor is referenced from
124    the vftbl of the array class.
125
126 *******************************************************************************/
127
128 struct arraydescriptor {
129         vftbl_t *componentvftbl; /* vftbl of the component type, NULL for primit. */
130         vftbl_t *elementvftbl;   /* vftbl of the element type, NULL for primitive */
131         s2       arraytype;      /* ARRAYTYPE_* constant                          */
132         s2       dimension;      /* dimension of the array (always >= 1)          */
133         s4       dataoffset;     /* offset of the array data from object pointer  */
134         s4       componentsize;  /* size of a component in bytes                  */
135         s2       elementtype;    /* ARRAYTYPE_* constant                          */
136 };
137
138
139 /* primitivetypeinfo **********************************************************/
140
141 struct primitivetypeinfo {
142         classinfo *class_wrap;               /* class for wrapping primitive type */
143         classinfo *class_primitive;          /* primitive class                   */
144         char      *wrapname;                 /* name of class for wrapping        */
145         char       typesig;                  /* one character type signature      */
146         char      *name;                     /* name of primitive class           */
147         char      *arrayname;                /* name of primitive array class     */
148         classinfo *arrayclass;               /* primitive array class             */
149         vftbl_t   *arrayvftbl;               /* vftbl of primitive array class    */
150 };
151
152
153 /* global variables ***********************************************************/
154
155 /* This array can be indexed by the PRIMITIVETYPE_ and ARRAYTYPE_ constants   */
156 /* (except ARRAYTYPE_OBJECT).                                                 */
157
158 extern primitivetypeinfo primitivetype_table[PRIMITIVETYPE_COUNT];
159
160
161 /* function prototypes ********************************************************/
162
163 bool linker_init(void);
164 classinfo *link_class(classinfo *c);
165
166 /* debug print arraydescriptor */
167 void print_arraydescriptor(FILE *file, arraydescriptor *desc);
168
169 #endif /* _LINKER_H */
170
171
172 /*
173  * These are local overrides for various environment variables in Emacs.
174  * Please do not remove this and leave it at the end of the file, where
175  * Emacs will automagically detect them.
176  * ---------------------------------------------------------------------
177  * Local variables:
178  * mode: c
179  * indent-tabs-mode: t
180  * c-basic-offset: 4
181  * tab-width: 4
182  * End:
183  */