* src/vm/jit/code.c (code_codeinfo_new): Commented.
[cacao.git] / src / vm / jit / code.c
1 /* vm/jit/code.c - codeinfo struct for representing compiled code
2
3    Copyright (C) 1996-2005, 2006 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    Contact: cacao@cacaojvm.org
26
27    Authors: Edwin Steiner
28
29    Changes:
30
31    $Id$
32
33 */
34
35
36 #include "config.h"
37 #include "vm/types.h"
38
39 #include <assert.h>
40
41 #include "vm/jit/code.h"
42 #include "mm/memory.h"
43 #include "vm/options.h"
44 #include "arch.h"
45
46 /* code_codeinfo_new ***********************************************************
47
48    Create a new codeinfo for the given method.
49    
50    IN:
51        m................method to create a new codeinfo for
52
53    Note: codeinfo.m is set to m, all other fields are zeroed.
54
55    RETURN VALUE:
56        a new, initialized codeinfo, or
57            NULL if an exception occurred.
58   
59 *******************************************************************************/
60
61 codeinfo *code_codeinfo_new(methodinfo *m)
62 {
63         codeinfo *code;
64
65         code = NEW(codeinfo);
66
67         memset(code,0,sizeof(codeinfo));
68
69         code->m = m;
70         
71         return code;
72 }
73
74 /* code_get_sync_slot_count ****************************************************
75
76    Return the number of stack slots used for storing the synchronized object
77    (and the return value around monitorExit calls) by the given code.
78    
79    IN:
80        code.............the codeinfo of the code in question
81                             (must be != NULL)
82
83    RETURN VALUE:
84        the number of stack slots used for synchronization
85   
86 *******************************************************************************/
87
88 int code_get_sync_slot_count(codeinfo *code)
89 {
90         assert(code);
91
92         if (!checksync)
93                 return 0;
94
95         if (!(code->m->flags & ACC_SYNCHRONIZED))
96                 return 0;
97
98         /* XXX generalize to all archs */
99 #ifdef HAS_4BYTE_STACKSLOT
100         return (IS_2_WORD_TYPE(code->m->parseddesc->returntype.type)) ? 2 : 1;
101 #else
102         return 1;
103 #endif
104 }
105
106 /* code_get_stack_frame_size ***************************************************
107
108    Return the number of stack slots that the stack frame of the given code
109    comprises.
110    
111    IN:
112        code.............the codeinfo of the code in question
113                             (must be != NULL)
114
115    RETURN VALUE:
116        the number of stack slots
117   
118 *******************************************************************************/
119
120 int code_get_stack_frame_size(codeinfo *code)
121 {
122         int count;
123         
124         assert(code);
125
126         /* XXX generalize to all archs */
127 #ifdef HAS_4BYTE_STACKSLOT
128         count = code->memuse + code->savedintcount + 2*code->savedfltcount;
129 #else
130         count = code->memuse + code->savedintcount + code->savedfltcount;
131 #endif
132
133         count += code_get_sync_slot_count(code);
134
135         return count;
136 }
137
138 /* code_codeinfo_free **********************************************************
139
140    Free the memory used by a codeinfo.
141    
142    IN:
143        code.............the codeinfo to free
144
145 *******************************************************************************/
146
147 void code_codeinfo_free(codeinfo *code)
148 {
149         if (!code)
150                 return;
151
152         if (code->mcode)
153                 CFREE((void *) (ptrint) code->mcode, code->mcodelength);
154
155         replace_free_replacement_points(code);
156
157         FREE(code,codeinfo);
158 }
159
160 /* code_free_code_of_method ****************************************************
161
162    Free all codeinfos of the given method
163    
164    IN:
165        m................the method of which the codeinfos are to be freed
166
167 *******************************************************************************/
168
169 void code_free_code_of_method(methodinfo *m)
170 {
171         codeinfo *nextcode;
172         codeinfo *code;
173
174         if (!m)
175                 return;
176         
177         nextcode = m->code;
178         while (nextcode) {
179                 code = nextcode;
180                 nextcode = code->prev;
181                 code_codeinfo_free(code);
182         }
183
184         m->code = NULL;
185 }
186
187 /*
188  * These are local overrides for various environment variables in Emacs.
189  * Please do not remove this and leave it at the end of the file, where
190  * Emacs will automagically detect them.
191  * ---------------------------------------------------------------------
192  * Local variables:
193  * mode: c
194  * indent-tabs-mode: t
195  * c-basic-offset: 4
196  * tab-width: 4
197  * End:
198  * vim:noexpandtab:sw=4:ts=4:
199  */