CACAO
code.hpp
Go to the documentation of this file.
1 /* src/vm/jit/code.hpp - codeinfo struct for representing compiled code
2 
3  Copyright (C) 1996-2013
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_ 1
28 
29 #include <memory>
30 
31 #include "config.h" // for ENABLE_REPLACEMENT, ENABLE_PROFILING
32 #include <assert.h> // for assert
33 #include <stdint.h> // for int32_t, uint8_t, uint32_t, etc
34 #include <stdlib.h> // for NULL
35 #include "vm/jit/methodheader.hpp" // for CodeInfoPointer
36 #include "vm/types.hpp" // for u1, s4
37 
38 #include "vm/jit/PatcherNew.hpp" // for cacao::Patcher
39 
40 class LinenumberTable;
41 struct exceptiontable_t;
42 struct methodinfo;
43 struct patchref_t;
44 struct rplalloc;
45 struct rplpoint;
46 template <class T> class LockedList;
47 
48 
49 /* constants ******************************************************************/
50 
51 enum CodeFlag {
55  CODE_FLAG_TLH = 0x0008,
56  CODE_FLAG_USING_FRAMEPTR = 0x0010 // TODO probably only needed for x86_64?
57 };
58 
59 typedef std::shared_ptr<cacao::Patcher> PatcherPtrTy;
61 
62 /* codeinfo *******************************************************************
63 
64  A codeinfo represents a particular realization of a method in
65  machine code.
66 
67  ATTENTION: The methodinfo entry in the code-structure MUST have the
68  offset 0, otherwise we have a problem in our compiler stub. This is
69  checked with an assert in code_init().
70 
71 *******************************************************************************/
72 
73 struct codeinfo {
74  methodinfo *m; /* method this is a realization of */
75  codeinfo *prev; /* previous codeinfo of this method */
76 
77  uint32_t flags; /* OR of CODE_FLAG_ constants */
78 
79  u1 optlevel; /* optimization level of this code */
80 
81  /* machine code */
82  u1 *mcode; /* pointer to machine code */
83  u1 *entrypoint; /* machine code entry point */
84  s4 mcodelength; /* length of generated machine code */
85 
86  /* runtime information */
87  int32_t stackframesize; /* size of the stackframe in slots */
88  int32_t synchronizedoffset; /* stack offset of synchronized obj. */
89  uint8_t savedintcount; /* number of callee saved int regs */
90  uint8_t savedfltcount; /* number of callee saved flt regs */
91 
94 
95  /* patcher list */
96  //LockedList<patchref_t>* patchers;
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 /* inline functions ***********************************************************/
121 
122 /* code_xxx_invalid ************************************************************
123 
124  Functions for CODE_FLAG_INVALID.
125 
126 *******************************************************************************/
127 
128 inline static int code_is_invalid(codeinfo *code)
129 {
130  return (code->flags & CODE_FLAG_INVALID);
131 }
132 
133 inline static void code_flag_invalid(codeinfo *code)
134 {
135  code->flags |= CODE_FLAG_INVALID;
136 }
137 
138 inline static void code_unflag_invalid(codeinfo *code)
139 {
140  code->flags &= ~CODE_FLAG_INVALID;
141 }
142 
143 
144 /* code_xxx_leafmethod *********************************************************
145 
146  Functions for CODE_FLAG_LEAFMETHOD.
147 
148 *******************************************************************************/
149 
150 inline static int code_is_leafmethod(codeinfo *code)
151 {
152  return (code->flags & CODE_FLAG_LEAFMETHOD);
153 }
154 
155 inline static void code_flag_leafmethod(codeinfo *code)
156 {
157  code->flags |= CODE_FLAG_LEAFMETHOD;
158 }
159 
160 inline static void code_unflag_leafmethod(codeinfo *code)
161 {
162  code->flags &= ~CODE_FLAG_LEAFMETHOD;
163 }
164 
165 
166 /* code_xxx_synchronized *******************************************************
167 
168  Functions for CODE_FLAG_SYNCHRONIZED.
169 
170 *******************************************************************************/
171 
172 inline static int code_is_synchronized(codeinfo *code)
173 {
174  return (code->flags & CODE_FLAG_SYNCHRONIZED);
175 }
176 
177 inline static void code_flag_synchronized(codeinfo *code)
178 {
179  code->flags |= CODE_FLAG_SYNCHRONIZED;
180 }
181 
182 inline static void code_unflag_synchronized(codeinfo *code)
183 {
184  code->flags &= ~CODE_FLAG_SYNCHRONIZED;
185 }
186 
187 
188 /* code_xxx_using_frameptr *****************************************************
189 
190  Functions for CODE_FLAG_USING_FRAMEPTR.
191 
192 *******************************************************************************/
193 
194 inline static int code_is_using_frameptr(codeinfo *code)
195 {
196  return (code->flags & CODE_FLAG_USING_FRAMEPTR);
197 }
198 
199 inline static void code_flag_using_frameptr(codeinfo *code)
200 {
202 }
203 
204 inline static void code_unflag_using_frameptr(codeinfo *code)
205 {
207 }
208 
209 
210 /* code_get_codeinfo_for_pv ****************************************************
211 
212  Return the codeinfo for the given PV.
213 
214  IN:
215  pv...............PV
216 
217  RETURN VALUE:
218  the codeinfo *
219 
220 *******************************************************************************/
221 
222 inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
223 {
224  codeinfo *code;
225 
226  assert(pv != NULL);
227 
228  code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
229 
230  return code;
231 }
232 
233 
234 /* function prototypes ********************************************************/
235 
236 void code_init(void);
237 
239 void code_codeinfo_free(codeinfo *code);
240 
243 
245 
246 #if defined(ENABLE_REPLACEMENT)
247 int code_get_sync_slot_count(codeinfo *code);
248 #endif
249 
251 
252 #endif // CODE_HPP_
253 
254 
255 /*
256  * These are local overrides for various environment variables in Emacs.
257  * Please do not remove this and leave it at the end of the file, where
258  * Emacs will automagically detect them.
259  * ---------------------------------------------------------------------
260  * Local variables:
261  * mode: c++
262  * indent-tabs-mode: t
263  * c-basic-offset: 4
264  * tab-width: 4
265  * End:
266  * vim:noexpandtab:sw=4:ts=4:
267  */
#define pv
Definition: md-asm.hpp:65
void code_codeinfo_free(codeinfo *code)
Definition: code.cpp:213
List implementation with a Mutex.
Definition: list.hpp:65
std::shared_ptr< cacao::Patcher > PatcherPtrTy
Definition: code.hpp:59
methodinfo * code_get_methodinfo_for_pv(void *pv)
Definition: code.cpp:150
CodeFlag
Definition: code.hpp:51
void code_init(void)
Definition: code.cpp:46
Linenumber table of a Java method.
uint8_t savedfltcount
Definition: code.hpp:90
static int code_is_invalid(codeinfo *code)
Definition: code.hpp:128
int32_t stackframesize
Definition: code.hpp:87
u1 optlevel
Definition: code.hpp:79
codeinfo * code_find_codeinfo_for_pc_nocheck(void *pc)
Definition: code.cpp:125
static void code_flag_invalid(codeinfo *code)
Definition: code.hpp:133
static void code_flag_synchronized(codeinfo *code)
Definition: code.hpp:177
uint8_t u1
Definition: types.hpp:40
static void code_unflag_leafmethod(codeinfo *code)
Definition: code.hpp:160
s4 mcodelength
Definition: code.hpp:84
int64_t s8
Definition: types.hpp:48
static int code_is_using_frameptr(codeinfo *code)
Definition: code.hpp:194
static int code_is_leafmethod(codeinfo *code)
Definition: code.hpp:150
void code_free_code_of_method(methodinfo *m)
Definition: code.cpp:249
methodinfo * m
Definition: code.hpp:74
codeinfo * code_codeinfo_new(methodinfo *m)
Definition: code.cpp:72
u1 * mcode
Definition: code.hpp:82
exceptiontable_t * exceptiontable
Definition: code.hpp:92
codeinfo * code_find_codeinfo_for_pc(void *pc)
Definition: code.cpp:101
static codeinfo * code_get_codeinfo_for_pv(void *pv)
Definition: code.hpp:222
static void code_flag_using_frameptr(codeinfo *code)
Definition: code.hpp:199
LockedList< PatcherPtrTy > PatcherListTy
Definition: code.hpp:60
#define CodeinfoPointer
static void code_flag_leafmethod(codeinfo *code)
Definition: code.hpp:155
int32_t s4
Definition: types.hpp:45
codeinfo * prev
Definition: code.hpp:75
bool regalloc(jitdata *jd)
Definition: simplereg.cpp:262
uint32_t u4
Definition: types.hpp:46
#define pc
Definition: md-asm.hpp:56
int32_t synchronizedoffset
Definition: code.hpp:88
PatcherListTy * patchers
Definition: code.hpp:97
static void code_unflag_using_frameptr(codeinfo *code)
Definition: code.hpp:204
LinenumberTable * linenumbertable
Definition: code.hpp:93
static int code_is_synchronized(codeinfo *code)
Definition: code.hpp:172
static void code_unflag_invalid(codeinfo *code)
Definition: code.hpp:138
uint32_t flags
Definition: code.hpp:77
uint8_t savedintcount
Definition: code.hpp:89
static void code_unflag_synchronized(codeinfo *code)
Definition: code.hpp:182
u1 * entrypoint
Definition: code.hpp:83