* src/vm/jit/powerpc/disass.c: Fixed copyright header.
[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 R. Grafl, A. Krall, C. Kruegel,
4    C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5    E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6    J. Wenninger, Institut f. Computersprachen - TU Wien
7
8    This file is part of CACAO.
9
10    This program is free software; you can redistribute it and/or
11    modify it under the terms of the GNU General Public License as
12    published by the Free Software Foundation; either version 2, or (at
13    your option) any later version.
14
15    This program is distributed in the hope that it will be useful, but
16    WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18    General Public License for more details.
19
20    You should have received a copy of the GNU General Public License
21    along with this program; if not, write to the Free Software
22    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23    02110-1301, USA.
24
25 */
26
27
28 #ifndef _CODE_H
29 #define _CODE_H
30
31 #include "config.h"
32
33 #include <assert.h>
34 #include <stdint.h>
35
36 #include "vm/types.h"
37
38 #include "toolbox/list.h"
39
40 #include "vm/global.h"
41
42 #include "vm/jit/exceptiontable.h"
43 #include "vm/jit/linenumbertable.h"
44 #include "vm/jit/methodheader.h"
45 #include "vm/jit/replace.h"
46
47 #include "vmcore/method.h"
48
49
50 /* constants ******************************************************************/
51
52 #define CODE_FLAG_INVALID         0x0001
53 #define CODE_FLAG_LEAFMETHOD      0x0002
54 #define CODE_FLAG_SYNCHRONIZED    0x0004
55
56
57 /* codeinfo *******************************************************************
58
59    A codeinfo represents a particular realization of a method in
60    machine code.
61
62    ATTENTION: The methodinfo entry in the code-structure MUST have the
63    offset 0, otherwise we have a problem in our compiler stub. This is
64    checked with an assert in code_init().
65
66 *******************************************************************************/
67
68 struct codeinfo {
69         methodinfo   *m;                    /* method this is a realization of    */
70         codeinfo     *prev;                 /* previous codeinfo of this method   */
71
72         uint32_t      flags;                /* OR of CODE_FLAG_ constants         */
73
74         u1            optlevel;             /* optimization level of this code    */
75         s4            basicblockcount;      /* number of basic blocks             */
76
77         int32_t       synchronizedoffset;   /* stack offset of synchronized obj.  */
78
79         /* machine code */
80         u1           *mcode;                /* pointer to machine code            */
81         u1           *entrypoint;           /* machine code entry point           */
82         s4            mcodelength;          /* length of generated machine code   */
83
84         exceptiontable_t  *exceptiontable;
85         linenumbertable_t *linenumbertable;
86
87         /* patcher list */
88         list_t       *patchers;
89
90         /* replacement */                                   
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         s4            stackframesize;       /* size of the stackframe in slots    */
99         u1            savedintcount;        /* number of callee saved int regs    */
100         u1            savedfltcount;        /* number of callee saved flt regs    */
101 # if defined(HAS_ADDRESS_REGISTER_FILE)
102         u1            savedadrcount;        /* number of callee saved adr regs    */
103 # endif
104         u1           *savedmcode;           /* saved code under patches           */
105 #endif
106
107 #if defined(ENABLE_PROFILING)
108         u4            frequency;            /* number of method invocations       */
109         u4           *bbfrequency;                  
110         s8            cycles;               /* number of cpu cycles               */
111 #endif
112 };
113
114
115 /* inline functions ***********************************************************/
116
117 /* code_xxx_invalid ************************************************************
118
119    Functions for CODE_FLAG_INVALID.
120
121 *******************************************************************************/
122
123 inline static int code_is_invalid(codeinfo *code)
124 {
125         return (code->flags & CODE_FLAG_INVALID);
126 }
127
128 inline static void code_flag_invalid(codeinfo *code)
129 {
130         code->flags |= CODE_FLAG_INVALID;
131 }
132
133 inline static void code_unflag_invalid(codeinfo *code)
134 {
135         code->flags &= ~CODE_FLAG_INVALID;
136 }
137
138
139 /* code_xxx_leafmethod *********************************************************
140
141    Functions for CODE_FLAG_LEAFMETHOD.
142
143 *******************************************************************************/
144
145 inline static int code_is_leafmethod(codeinfo *code)
146 {
147         return (code->flags & CODE_FLAG_LEAFMETHOD);
148 }
149
150 inline static void code_flag_leafmethod(codeinfo *code)
151 {
152         code->flags |= CODE_FLAG_LEAFMETHOD;
153 }
154
155 inline static void code_unflag_leafmethod(codeinfo *code)
156 {
157         code->flags &= ~CODE_FLAG_LEAFMETHOD;
158 }
159
160
161 /* code_xxx_synchronized *******************************************************
162
163    Functions for CODE_FLAG_SYNCHRONIZED.
164
165 *******************************************************************************/
166
167 inline static int code_is_synchronized(codeinfo *code)
168 {
169         return (code->flags & CODE_FLAG_SYNCHRONIZED);
170 }
171
172 inline static void code_flag_synchronized(codeinfo *code)
173 {
174         code->flags |= CODE_FLAG_SYNCHRONIZED;
175 }
176
177 inline static void code_unflag_synchronized(codeinfo *code)
178 {
179         code->flags &= ~CODE_FLAG_SYNCHRONIZED;
180 }
181
182
183 /* code_get_codeinfo_for_pv ****************************************************
184
185    Return the codeinfo for the given PV.
186
187    IN:
188        pv...............PV
189
190    RETURN VALUE:
191        the codeinfo *
192
193 *******************************************************************************/
194
195 inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
196 {
197         codeinfo *code;
198
199         assert(pv != NULL);
200
201         code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
202
203         return code;
204 }
205
206
207 /* function prototypes ********************************************************/
208
209 bool code_init(void);
210
211 codeinfo *code_codeinfo_new(methodinfo *m);
212 void code_codeinfo_free(codeinfo *code);
213
214 codeinfo *code_find_codeinfo_for_pc(u1 *pc);
215 codeinfo *code_find_codeinfo_for_pc_nocheck(u1 *pc);
216
217 methodinfo *code_get_methodinfo_for_pv(u1 *pv);
218
219 #if defined(ENABLE_REPLACEMENT)
220 int code_get_sync_slot_count(codeinfo *code);
221 #endif /* defined(ENABLE_REPLACEMENT) */
222
223 void code_free_code_of_method(methodinfo *m);
224
225 #endif /* _CODE_H */
226
227
228 /*
229  * These are local overrides for various environment variables in Emacs.
230  * Please do not remove this and leave it at the end of the file, where
231  * Emacs will automagically detect them.
232  * ---------------------------------------------------------------------
233  * Local variables:
234  * mode: c
235  * indent-tabs-mode: t
236  * c-basic-offset: 4
237  * tab-width: 4
238  * End:
239  * vim:noexpandtab:sw=4:ts=4:
240  */