1 /* src/vm/vftbl.hpp - virtual function table
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
29 // Forward declaration.
30 typedef struct _vftbl vftbl_t;
35 /* virtual function table ******************************************************
37 The vtbl has a bidirectional layout with open ends at both sides.
38 interfacetablelength gives the number of entries of the interface
39 table at the start of the vftbl. The vftbl pointer points to
40 &interfacetable[0]. vftbllength gives the number of entries of
41 table at the end of the vftbl.
43 runtime type check (checkcast):
45 Different methods are used for runtime type check depending on the
46 argument of checkcast/instanceof.
48 A check against a class is implemented via relative numbering on
49 the class hierachy tree. The tree is numbered in a depth first
50 traversal setting the base field and the diff field. The diff field
51 gets the result of (high - base) so that a range check can be
52 implemented by an unsigned compare. A sub type test is done by
53 checking the inclusion of base of the sub class in the range of the
56 A check against an interface is implemented via the
57 interfacevftbl. If the interfacevftbl contains a nonnull value a
58 class is a subclass of this interface.
62 Like standard virtual methods interface methods are called using
63 virtual function tables. All interfaces are numbered sequentially
64 (starting with zero). For each class there exist an interface table
65 of virtual function tables for each implemented interface. The
66 length of the interface table is determined by the highest number
67 of an implemented interface.
69 The following example assumes a class which implements interface 0 and 3:
71 interfacetablelength = 4
74 +-----------+ | method 2 |---> method z
75 | class | | method 1 |---> method y
76 +-----------+ | method 0 |---> method x
77 | ivftbl 0 |----------> +----------+
78 vftblptr ---> +-----------+
79 | ivftbl -1 |--> NULL +----------+
80 | ivftbl -2 |--> NULL | method 1 |---> method x
81 | ivftbl -3 |-----+ | method 0 |---> method a
82 +-----------+ +----> +----------+
89 interfacevftbllength ---> +---------------+
91 *******************************************************************************/
94 #include "vm/class.hpp"
95 #include "vm/references.h"
98 #define DISPLAY_SIZE 4
102 methodptr *interfacetable[1]; /* interface table (access via macro) */
103 classinfo *clazz; /* class, the vtbl belongs to */
104 arraydescriptor *arraydesc; /* for array classes, otherwise NULL */
105 s4 vftbllength; /* virtual function table length */
106 s4 interfacetablelength; /* interface table length */
107 s4 baseval; /* base for runtime type check */
108 /* (-index for interfaces) */
109 s4 diffval; /* high - base for runtime type check */
114 struct _vftbl *subtype_display[DISPLAY_SIZE+1]; /* the last one is cache */
115 struct _vftbl **subtype_overflow;
118 s4 *interfacevftbllength; /* length of interface vftbls */
119 methodptr table[1]; /* class vftbl */
126 * These are local overrides for various environment variables in Emacs.
127 * Please do not remove this and leave it at the end of the file, where
128 * Emacs will automagically detect them.
129 * ---------------------------------------------------------------------
132 * indent-tabs-mode: t
136 * vim:noexpandtab:sw=4:ts=4: