* src/vm/jit/x86_64/asmpart.S (asm_abstractmethoderror): Keep stack aligned.
[cacao.git] / src / vm / vftbl.hpp
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
28
29 // Forward declaration.
30 typedef struct _vftbl vftbl_t;
31
32 #include "config.h"
33
34
35 /* virtual function table ******************************************************
36
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.
42
43    runtime type check (checkcast):
44
45    Different methods are used for runtime type check depending on the
46    argument of checkcast/instanceof.
47         
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
54    superclass.
55
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.
59
60    interfacetable:
61
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.
68
69    The following example assumes a class which implements interface 0 and 3:
70
71    interfacetablelength = 4
72
73                   | ...       |            +----------+
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                   +-----------+     +----> +----------+
83      
84                               +---------------+
85                               | length 3 = 2  |
86                               | length 2 = 0  |
87                               | length 1 = 0  |
88                               | length 0 = 3  |
89     interfacevftbllength ---> +---------------+
90
91 *******************************************************************************/
92
93 // Includes.
94 #include "vm/class.hpp"
95 #include "vm/references.h"
96
97 #if USES_NEW_SUBTYPE
98 #define DISPLAY_SIZE 4
99 #endif
100
101 struct _vftbl {
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  */
110
111 #if USES_NEW_SUBTYPE
112         s4 subtype_depth;
113         s4 subtype_offset;
114         struct _vftbl *subtype_display[DISPLAY_SIZE+1];  /* the last one is cache */
115         struct _vftbl **subtype_overflow;
116 #endif
117
118         s4          *interfacevftbllength; /* length of interface vftbls          */
119         methodptr    table[1];             /* class vftbl                         */
120 };
121
122 #endif // _VFTBL_HPP
123
124
125 /*
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  * ---------------------------------------------------------------------
130  * Local variables:
131  * mode: c++
132  * indent-tabs-mode: t
133  * c-basic-offset: 4
134  * tab-width: 4
135  * End:
136  * vim:noexpandtab:sw=4:ts=4:
137  */