CACAO
vftbl.hpp
Go to the documentation of this file.
1 /* src/vm/vftbl.hpp - virtual function table
2 
3  Copyright (C) 2008
4  CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
5 
6  This file is part of CACAO.
7 
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.
12 
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.
17 
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
21  02110-1301, USA.
22 
23 */
24 
25 
26 #ifndef VFTBL_HPP_
27 #define VFTBL_HPP_ 1
28 
29 /* virtual function table ******************************************************
30 
31  The vtbl has a bidirectional layout with open ends at both sides.
32  interfacetablelength gives the number of entries of the interface
33  table at the start of the vftbl. The vftbl pointer points to
34  &interfacetable[0]. vftbllength gives the number of entries of
35  table at the end of the vftbl.
36 
37  runtime type check (checkcast):
38 
39  Different methods are used for runtime type check depending on the
40  argument of checkcast/instanceof.
41 
42  A check against a class is implemented via relative numbering on
43  the class hierachy tree. The tree is numbered in a depth first
44  traversal setting the base field and the diff field. The diff field
45  gets the result of (high - base) so that a range check can be
46  implemented by an unsigned compare. A sub type test is done by
47  checking the inclusion of base of the sub class in the range of the
48  superclass.
49 
50  A check against an interface is implemented via the
51  interfacevftbl. If the interfacevftbl contains a nonnull value a
52  class is a subclass of this interface.
53 
54  interfacetable:
55 
56  Like standard virtual methods interface methods are called using
57  virtual function tables. All interfaces are numbered sequentially
58  (starting with zero). For each class there exist an interface table
59  of virtual function tables for each implemented interface. The
60  length of the interface table is determined by the highest number
61  of an implemented interface.
62 
63  The following example assumes a class which implements interface 0 and 3:
64 
65  interfacetablelength = 4
66 
67  | ... | +----------+
68  +-----------+ | method 2 |---> method z
69  | class | | method 1 |---> method y
70  +-----------+ | method 0 |---> method x
71  | ivftbl 0 |----------> +----------+
72  vftblptr ---> +-----------+
73  | ivftbl -1 |--> NULL +----------+
74  | ivftbl -2 |--> NULL | method 1 |---> method x
75  | ivftbl -3 |-----+ | method 0 |---> method a
76  +-----------+ +----> +----------+
77 
78  +---------------+
79  | length 3 = 2 |
80  | length 2 = 0 |
81  | length 1 = 0 |
82  | length 0 = 3 |
83  interfacevftbllength ---> +---------------+
84 
85 *******************************************************************************/
86 
87 // Includes.
88 #include "arch.hpp" // for USES_NEW_SUBTYPE
89 #include "vm/global.hpp" // for methodptr
90 
91 #if USES_NEW_SUBTYPE
92 #define DISPLAY_SIZE 4
93 #endif
94 
95 struct classinfo;
96 struct arraydescriptor;
97 
98 struct vftbl_t {
99  methodptr *interfacetable[1]; /* interface table (access via macro) */
100  classinfo *clazz; /* class, the vtbl belongs to */
101  arraydescriptor *arraydesc; /* for array classes, otherwise NULL */
102  s4 vftbllength; /* virtual function table length */
103  s4 interfacetablelength; /* interface table length */
104  s4 baseval; /* base for runtime type check */
105  /* (-index for interfaces) */
106  s4 diffval; /* high - base for runtime type check */
107 
108 #if USES_NEW_SUBTYPE
109  s4 subtype_depth;
110  s4 subtype_offset;
111  vftbl_t *subtype_display[DISPLAY_SIZE+1]; /* the last one is cache */
112  vftbl_t **subtype_overflow;
113 #endif
114 
115  s4 *interfacevftbllength; /* length of interface vftbls */
116  methodptr table[1]; /* class vftbl */
117 };
118 
119 #endif // VFTBL_HPP_
120 
121 
122 /*
123  * These are local overrides for various environment variables in Emacs.
124  * Please do not remove this and leave it at the end of the file, where
125  * Emacs will automagically detect them.
126  * ---------------------------------------------------------------------
127  * Local variables:
128  * mode: c++
129  * indent-tabs-mode: t
130  * c-basic-offset: 4
131  * tab-width: 4
132  * End:
133  * vim:noexpandtab:sw=4:ts=4:
134  */
methodptr * interfacetable[1]
Definition: vftbl.hpp:99
u1 * methodptr
Definition: global.hpp:40
s4 * interfacevftbllength
Definition: vftbl.hpp:115
s4 interfacetablelength
Definition: vftbl.hpp:103
s4 vftbllength
Definition: vftbl.hpp:102
s4 baseval
Definition: vftbl.hpp:104
classinfo * clazz
Definition: vftbl.hpp:100
int32_t s4
Definition: types.hpp:45
arraydescriptor * arraydesc
Definition: vftbl.hpp:101
methodptr table[1]
Definition: vftbl.hpp:116
s4 diffval
Definition: vftbl.hpp:106