1 /* src/vmcore/linker.h - class linker header
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA
31 /* forward typedefs ***********************************************************/
33 typedef struct _vftbl vftbl_t;
34 typedef struct arraydescriptor arraydescriptor;
35 typedef struct primitivetypeinfo primitivetypeinfo;
41 #include "vmcore/class.h"
42 #include "vmcore/references.h"
45 /* virtual function table ******************************************************
47 The vtbl has a bidirectional layout with open ends at both sides.
48 interfacetablelength gives the number of entries of the interface
49 table at the start of the vftbl. The vftbl pointer points to
50 &interfacetable[0]. vftbllength gives the number of entries of
51 table at the end of the vftbl.
53 runtime type check (checkcast):
55 Different methods are used for runtime type check depending on the
56 argument of checkcast/instanceof.
58 A check against a class is implemented via relative numbering on
59 the class hierachy tree. The tree is numbered in a depth first
60 traversal setting the base field and the diff field. The diff field
61 gets the result of (high - base) so that a range check can be
62 implemented by an unsigned compare. A sub type test is done by
63 checking the inclusion of base of the sub class in the range of the
66 A check against an interface is implemented via the
67 interfacevftbl. If the interfacevftbl contains a nonnull value a
68 class is a subclass of this interface.
72 Like standard virtual methods interface methods are called using
73 virtual function tables. All interfaces are numbered sequentially
74 (starting with zero). For each class there exist an interface table
75 of virtual function tables for each implemented interface. The
76 length of the interface table is determined by the highest number
77 of an implemented interface.
79 The following example assumes a class which implements interface 0 and 3:
81 interfacetablelength = 4
84 +-----------+ | method 2 |---> method z
85 | class | | method 1 |---> method y
86 +-----------+ | method 0 |---> method x
87 | ivftbl 0 |----------> +----------+
88 vftblptr ---> +-----------+
89 | ivftbl -1 |--> NULL +----------+
90 | ivftbl -2 |--> NULL | method 1 |---> method x
91 | ivftbl -3 |-----+ | method 0 |---> method a
92 +-----------+ +----> +----------+
99 interfacevftbllength ---> +---------------+
101 *******************************************************************************/
104 methodptr *interfacetable[1]; /* interface table (access via macro) */
105 classinfo *clazz; /* class, the vtbl belongs to */
106 arraydescriptor *arraydesc; /* for array classes, otherwise NULL */
107 s4 vftbllength; /* virtual function table length */
108 s4 interfacetablelength; /* interface table length */
109 s4 baseval; /* base for runtime type check */
110 /* (-index for interfaces) */
111 s4 diffval; /* high - base for runtime type check */
112 s4 *interfacevftbllength; /* length of interface vftbls */
113 methodptr table[1]; /* class vftbl */
117 /* arraydescriptor *************************************************************
119 For every array class an arraydescriptor is allocated which
120 describes the array class. The arraydescriptor is referenced from
121 the vftbl of the array class.
123 *******************************************************************************/
125 struct arraydescriptor {
126 vftbl_t *componentvftbl; /* vftbl of the component type, NULL for primit. */
127 vftbl_t *elementvftbl; /* vftbl of the element type, NULL for primitive */
128 s2 arraytype; /* ARRAYTYPE_* constant */
129 s2 dimension; /* dimension of the array (always >= 1) */
130 s4 dataoffset; /* offset of the array data from object pointer */
131 s4 componentsize; /* size of a component in bytes */
132 s2 elementtype; /* ARRAYTYPE_* constant */
136 /* global variables ***********************************************************/
138 /* This lock must be taken while renumbering classes or while atomically */
139 /* accessing classes. */
141 extern java_object_t *linker_classrenumber_lock;
144 /* function prototypes ********************************************************/
146 void linker_preinit(void);
147 void linker_init(void);
148 classinfo *link_class(classinfo *c);
150 #endif /* _LINKER_H */
154 * These are local overrides for various environment variables in Emacs.
155 * Please do not remove this and leave it at the end of the file, where
156 * Emacs will automagically detect them.
157 * ---------------------------------------------------------------------
160 * indent-tabs-mode: t