* src/vm/jit/trace.c (trace_java_call_enter): Removed unused variable.
[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 <stdint.h>
34
35 #include "vm/types.h"
36
37 #include "toolbox/list.h"
38
39 #include "vm/global.h"
40
41 #include "vm/jit/exceptiontable.h"
42 #include "vm/jit/linenumbertable.h"
43 #include "vm/jit/replace.h"
44
45 #include "vmcore/method.h"
46
47
48 /* constants ******************************************************************/
49
50 #define CODE_FLAG_INVALID         0x0001
51 #define CODE_FLAG_LEAFMETHOD      0x0002
52 #define CODE_FLAG_SYNCHRONIZED    0x0004
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 #if defined(ENABLE_REPLACEMENT)
90         rplpoint     *rplpoints;            /* replacement points                 */
91         rplalloc     *regalloc;             /* register allocation info           */
92         s4            rplpointcount;        /* number of replacement points       */
93         s4            globalcount;          /* number of global allocations       */
94         s4            regalloccount;        /* number of total allocations        */
95         s4            memuse;               /* number of arg + local slots        */
96         s4            stackframesize;       /* size of the stackframe in slots    */
97         u1            savedintcount;        /* number of callee saved int regs    */
98         u1            savedfltcount;        /* number of callee saved flt regs    */
99 # if defined(HAS_ADDRESS_REGISTER_FILE)
100         u1            savedadrcount;        /* number of callee saved adr regs    */
101 # endif
102         u1           *savedmcode;           /* saved code under patches           */
103 #endif
104
105 #if defined(ENABLE_PROFILING)
106         u4            frequency;            /* number of method invocations       */
107         u4           *bbfrequency;                  
108         s8            cycles;               /* number of cpu cycles               */
109 #endif
110 };
111
112
113 /* inline functions ***********************************************************/
114
115 /* code_xxx_invalid ************************************************************
116
117    Functions for CODE_FLAG_INVALID.
118
119 *******************************************************************************/
120
121 inline static int code_is_invalid(codeinfo *code)
122 {
123         return (code->flags & CODE_FLAG_INVALID);
124 }
125
126 inline static void code_flag_invalid(codeinfo *code)
127 {
128         code->flags |= CODE_FLAG_INVALID;
129 }
130
131 inline static void code_unflag_invalid(codeinfo *code)
132 {
133         code->flags &= ~CODE_FLAG_INVALID;
134 }
135
136
137 /* code_xxx_leafmethod *********************************************************
138
139    Functions for CODE_FLAG_LEAFMETHOD.
140
141 *******************************************************************************/
142
143 inline static int code_is_leafmethod(codeinfo *code)
144 {
145         return (code->flags & CODE_FLAG_LEAFMETHOD);
146 }
147
148 inline static void code_flag_leafmethod(codeinfo *code)
149 {
150         code->flags |= CODE_FLAG_LEAFMETHOD;
151 }
152
153 inline static void code_unflag_leafmethod(codeinfo *code)
154 {
155         code->flags &= ~CODE_FLAG_LEAFMETHOD;
156 }
157
158
159 /* code_xxx_synchronized *******************************************************
160
161    Functions for CODE_FLAG_SYNCHRONIZED.
162
163 *******************************************************************************/
164
165 inline static int code_is_synchronized(codeinfo *code)
166 {
167         return (code->flags & CODE_FLAG_SYNCHRONIZED);
168 }
169
170 inline static void code_flag_synchronized(codeinfo *code)
171 {
172         code->flags |= CODE_FLAG_SYNCHRONIZED;
173 }
174
175 inline static void code_unflag_synchronized(codeinfo *code)
176 {
177         code->flags &= ~CODE_FLAG_SYNCHRONIZED;
178 }
179
180
181 /* function prototypes ********************************************************/
182
183 bool code_init(void);
184
185 codeinfo *code_codeinfo_new(methodinfo *m);
186 void code_codeinfo_free(codeinfo *code);
187
188 codeinfo *code_find_codeinfo_for_pc(u1 *pc);
189 codeinfo *code_find_codeinfo_for_pc_nocheck(u1 *pc);
190
191 codeinfo   *code_get_codeinfo_for_pv(u1 *pv);
192 methodinfo *code_get_methodinfo_for_pv(u1 *pv);
193
194 #if defined(ENABLE_REPLACEMENT)
195 int code_get_sync_slot_count(codeinfo *code);
196 #endif /* defined(ENABLE_REPLACEMENT) */
197
198 void code_free_code_of_method(methodinfo *m);
199
200 #endif /* _CODE_H */
201
202
203 /*
204  * These are local overrides for various environment variables in Emacs.
205  * Please do not remove this and leave it at the end of the file, where
206  * Emacs will automagically detect them.
207  * ---------------------------------------------------------------------
208  * Local variables:
209  * mode: c
210  * indent-tabs-mode: t
211  * c-basic-offset: 4
212  * tab-width: 4
213  * End:
214  * vim:noexpandtab:sw=4:ts=4:
215  */