* src/vm/jit/arm/codegen.c: Remove hack for return value in float registers.
[cacao.git] / src / vm / jit / code.hpp
1 /* src/vm/jit/code.hpp - codeinfo struct for representing compiled code
2
3    Copyright (C) 1996-2005, 2006, 2007, 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 _CODE_HPP
27 #define _CODE_HPP
28
29 #include "config.h"
30
31 #include <assert.h>
32 #include <stdint.h>
33
34 #include "vm/types.h"
35
36 #include "toolbox/list.hpp"
37
38 #include "vm/global.h"
39 #include "vm/method.hpp"
40
41 #include "vm/jit/exceptiontable.h"
42 #include "vm/jit/linenumbertable.hpp"
43 #include "vm/jit/methodheader.h"
44 #include "vm/jit/patcher-common.hpp"
45 #include "vm/jit/replace.hpp"
46
47
48 /* constants ******************************************************************/
49
50 #define CODE_FLAG_INVALID         0x0001
51 #define CODE_FLAG_LEAFMETHOD      0x0002
52 #define CODE_FLAG_SYNCHRONIZED    0x0004
53 #define CODE_FLAG_TLH             0x0008
54
55
56 /* codeinfo *******************************************************************
57
58    A codeinfo represents a particular realization of a method in
59    machine code.
60
61    ATTENTION: The methodinfo entry in the code-structure MUST have the
62    offset 0, otherwise we have a problem in our compiler stub. This is
63    checked with an assert in code_init().
64
65 *******************************************************************************/
66
67 struct codeinfo {
68         methodinfo   *m;                    /* method this is a realization of    */
69         codeinfo     *prev;                 /* previous codeinfo of this method   */
70
71         uint32_t      flags;                /* OR of CODE_FLAG_ constants         */
72
73         u1            optlevel;             /* optimization level of this code    */
74
75         /* machine code */
76         u1           *mcode;                /* pointer to machine code            */
77         u1           *entrypoint;           /* machine code entry point           */
78         s4            mcodelength;          /* length of generated machine code   */
79
80         /* runtime information */
81         int32_t       stackframesize;       /* size of the stackframe in slots    */
82         int32_t       synchronizedoffset;   /* stack offset of synchronized obj.  */
83         uint8_t       savedintcount;        /* number of callee saved int regs    */
84         uint8_t       savedfltcount;        /* number of callee saved flt regs    */
85 # if defined(HAS_ADDRESS_REGISTER_FILE)
86         uint8_t       savedadrcount;        /* number of callee saved adr regs    */
87 # endif
88
89         exceptiontable_t  *exceptiontable;
90         LinenumberTable* linenumbertable;
91
92         /* patcher list */
93 #ifdef __cplusplus
94         LockedList<patchref_t>* patchers;
95 #else
96         LockedList*   patchers;
97 #endif
98
99         /* replacement */
100 #if defined(ENABLE_REPLACEMENT)
101         rplpoint     *rplpoints;            /* replacement points                 */
102         rplalloc     *regalloc;             /* register allocation info           */
103         s4            rplpointcount;        /* number of replacement points       */
104         s4            globalcount;          /* number of global allocations       */
105         s4            regalloccount;        /* number of total allocations        */
106         s4            memuse;               /* number of arg + local slots        */
107         u1           *savedmcode;           /* saved code under patches           */
108 #endif
109
110         /* profiling information */
111 #if defined(ENABLE_PROFILING)
112         u4            frequency;            /* number of method invocations       */
113         s4            basicblockcount;      /* number of basic blocks             */
114         u4           *bbfrequency;          /* basic block profiling information  */
115         s8            cycles;               /* number of cpu cycles               */
116 #endif
117 };
118
119
120 #ifdef __cplusplus
121 extern "C" {
122 #endif
123
124 /* inline functions ***********************************************************/
125
126 /* code_xxx_invalid ************************************************************
127
128    Functions for CODE_FLAG_INVALID.
129
130 *******************************************************************************/
131
132 inline static int code_is_invalid(codeinfo *code)
133 {
134         return (code->flags & CODE_FLAG_INVALID);
135 }
136
137 inline static void code_flag_invalid(codeinfo *code)
138 {
139         code->flags |= CODE_FLAG_INVALID;
140 }
141
142 inline static void code_unflag_invalid(codeinfo *code)
143 {
144         code->flags &= ~CODE_FLAG_INVALID;
145 }
146
147
148 /* code_xxx_leafmethod *********************************************************
149
150    Functions for CODE_FLAG_LEAFMETHOD.
151
152 *******************************************************************************/
153
154 inline static int code_is_leafmethod(codeinfo *code)
155 {
156         return (code->flags & CODE_FLAG_LEAFMETHOD);
157 }
158
159 inline static void code_flag_leafmethod(codeinfo *code)
160 {
161         code->flags |= CODE_FLAG_LEAFMETHOD;
162 }
163
164 inline static void code_unflag_leafmethod(codeinfo *code)
165 {
166         code->flags &= ~CODE_FLAG_LEAFMETHOD;
167 }
168
169
170 /* code_xxx_synchronized *******************************************************
171
172    Functions for CODE_FLAG_SYNCHRONIZED.
173
174 *******************************************************************************/
175
176 inline static int code_is_synchronized(codeinfo *code)
177 {
178         return (code->flags & CODE_FLAG_SYNCHRONIZED);
179 }
180
181 inline static void code_flag_synchronized(codeinfo *code)
182 {
183         code->flags |= CODE_FLAG_SYNCHRONIZED;
184 }
185
186 inline static void code_unflag_synchronized(codeinfo *code)
187 {
188         code->flags &= ~CODE_FLAG_SYNCHRONIZED;
189 }
190
191
192 /* code_get_codeinfo_for_pv ****************************************************
193
194    Return the codeinfo for the given PV.
195
196    IN:
197        pv...............PV
198
199    RETURN VALUE:
200        the codeinfo *
201
202 *******************************************************************************/
203
204 inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
205 {
206         codeinfo *code;
207
208         assert(pv != NULL);
209
210         code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
211
212         return code;
213 }
214
215
216 /* function prototypes ********************************************************/
217
218 void code_init(void);
219
220 codeinfo *code_codeinfo_new(methodinfo *m);
221 void code_codeinfo_free(codeinfo *code);
222
223 codeinfo *code_find_codeinfo_for_pc(void *pc);
224 codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc);
225
226 methodinfo *code_get_methodinfo_for_pv(void *pv);
227
228 #if defined(ENABLE_REPLACEMENT)
229 int code_get_sync_slot_count(codeinfo *code);
230 #endif /* defined(ENABLE_REPLACEMENT) */
231
232 void code_free_code_of_method(methodinfo *m);
233
234 #ifdef __cplusplus
235 }
236 #endif
237
238 #endif // _CODE_HPP
239
240
241 /*
242  * These are local overrides for various environment variables in Emacs.
243  * Please do not remove this and leave it at the end of the file, where
244  * Emacs will automagically detect them.
245  * ---------------------------------------------------------------------
246  * Local variables:
247  * mode: c++
248  * indent-tabs-mode: t
249  * c-basic-offset: 4
250  * tab-width: 4
251  * End:
252  * vim:noexpandtab:sw=4:ts=4:
253  */