Line data Source code
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 {
51 : CODE_FLAG_INVALID = 0x0001,
52 : CODE_FLAG_LEAFMETHOD = 0x0002,
53 : CODE_FLAG_SYNCHRONIZED = 0x0004,
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;
61 : typedef LockedList<PatcherPtrTy> PatcherListTy;
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 :
93 : exceptiontable_t *exceptiontable;
94 : LinenumberTable* linenumbertable;
95 :
96 : /* patcher list */
97 : //LockedList<patchref_t>* patchers;
98 : PatcherListTy* 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 0 : inline static int code_is_invalid(codeinfo *code)
130 : {
131 0 : return (code->flags & CODE_FLAG_INVALID);
132 : }
133 :
134 0 : inline static void code_flag_invalid(codeinfo *code)
135 : {
136 0 : code->flags |= CODE_FLAG_INVALID;
137 0 : }
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 2271205 : inline static int code_is_leafmethod(codeinfo *code)
152 : {
153 2271205 : return (code->flags & CODE_FLAG_LEAFMETHOD);
154 : }
155 :
156 102093 : inline static void code_flag_leafmethod(codeinfo *code)
157 : {
158 102093 : code->flags |= CODE_FLAG_LEAFMETHOD;
159 102093 : }
160 :
161 441872 : inline static void code_unflag_leafmethod(codeinfo *code)
162 : {
163 441872 : code->flags &= ~CODE_FLAG_LEAFMETHOD;
164 441872 : }
165 :
166 :
167 : /* code_xxx_synchronized *******************************************************
168 :
169 : Functions for CODE_FLAG_SYNCHRONIZED.
170 :
171 : *******************************************************************************/
172 :
173 296586 : inline static int code_is_synchronized(codeinfo *code)
174 : {
175 296586 : return (code->flags & CODE_FLAG_SYNCHRONIZED);
176 : }
177 :
178 3231 : inline static void code_flag_synchronized(codeinfo *code)
179 : {
180 3231 : code->flags |= CODE_FLAG_SYNCHRONIZED;
181 3231 : }
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 15550751 : inline static codeinfo *code_get_codeinfo_for_pv(void *pv)
202 : {
203 : codeinfo *code;
204 :
205 15550751 : assert(pv != NULL);
206 :
207 15550751 : code = *((codeinfo **) (((uintptr_t) pv) + CodeinfoPointer));
208 :
209 15550751 : return code;
210 : }
211 :
212 :
213 : /* function prototypes ********************************************************/
214 :
215 : void code_init(void);
216 :
217 : codeinfo *code_codeinfo_new(methodinfo *m);
218 : void code_codeinfo_free(codeinfo *code);
219 :
220 : codeinfo *code_find_codeinfo_for_pc(void *pc);
221 : codeinfo *code_find_codeinfo_for_pc_nocheck(void *pc);
222 :
223 : methodinfo *code_get_methodinfo_for_pv(void *pv);
224 :
225 : #if defined(ENABLE_REPLACEMENT)
226 : int code_get_sync_slot_count(codeinfo *code);
227 : #endif /* defined(ENABLE_REPLACEMENT) */
228 :
229 : void code_free_code_of_method(methodinfo *m);
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 : */
|