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