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