* renamed CACAO_TYPECHECK to ENABLE_VERIFIER
[cacao.git] / src / vm / method.c
1 /* src/vm/method.c - method functions
2
3    Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
4    R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
5    C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
6    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., 59 Temple Place - Suite 330, Boston, MA
23    02111-1307, USA.
24
25    Contact: cacao@complang.tuwien.ac.at
26
27    Authors: Reinhard Grafl
28
29    Changes: Andreas Krall
30             Roman Obermaiser
31             Mark Probst
32             Edwin Steiner
33             Christian Thalinger
34
35    $Id: method.c 3412 2005-10-12 12:54:02Z twisti $
36
37 */
38
39
40 #include "vm/global.h"
41 #include "mm/memory.h"
42 #include "vm/method.h"
43 #include "vm/class.h"
44 #include "vm/loader.h"
45 #include "vm/jit/codegen.inc.h"
46
47
48 /* method_free *****************************************************************
49
50    Frees all memory that was allocated for this method.
51
52 *******************************************************************************/
53
54 void method_free(methodinfo *m)
55 {
56         if (m->jcode)
57                 MFREE(m->jcode, u1, m->jcodelength);
58
59         if (m->exceptiontable)
60                 MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
61
62         if (m->mcode)
63                 CFREE((void *) (ptrint) m->mcode, m->mcodelength);
64
65         if (m->stubroutine) {
66                 if (m->flags & ACC_NATIVE) {
67                         removenativestub(m->stubroutine);
68
69                 } else {
70                         removecompilerstub(m->stubroutine);
71                 }
72         }
73 }
74
75
76 /* method_canoverwrite *********************************************************
77
78    Check if m and old are identical with respect to type and
79    name. This means that old can be overwritten with m.
80         
81 *******************************************************************************/
82
83 bool method_canoverwrite(methodinfo *m, methodinfo *old)
84 {
85         if (m->name != old->name)
86                 return false;
87
88         if (m->descriptor != old->descriptor)
89                 return false;
90
91         if (m->flags & ACC_STATIC)
92                 return false;
93
94         return true;
95 }
96
97 /* method_descriptor2types *****************************************************
98
99    Fills in the following members of the given methodinfo:
100        returntype
101            paramcount
102        paramtypes          
103
104    Note:
105        This function uses dump_alloc functions to allocate memory.
106
107 *******************************************************************************/                
108
109 void method_descriptor2types(methodinfo *m)
110 {
111         u1 *types, *tptr;
112         int pcount, i;
113         methoddesc *md = m->parseddesc;
114         typedesc *paramtype;
115         
116         pcount = md->paramcount;
117         if ((m->flags & ACC_STATIC) == 0)
118                 pcount++; /* count this pointer */
119         
120         types = DMNEW(u1,pcount);
121         tptr = types;
122         
123         if (!(m->flags & ACC_STATIC)) {
124                 /* this pointer */
125                 *tptr++ = TYPE_ADR;
126         }
127
128         paramtype = md->paramtypes;
129         for (i=0; i<md->paramcount; ++i,++paramtype)
130                 *tptr++ = paramtype->type;
131
132         m->returntype = md->returntype.type;
133         m->paramcount = pcount;
134         m->paramtypes = types;
135 }
136
137 /************** Function: method_display  (debugging only) **************/
138
139 void method_display(methodinfo *m)
140 {
141         printf("   ");
142         printflags(m->flags);
143         printf(" ");
144         utf_display(m->name);
145         printf(" "); 
146         utf_display(m->descriptor);
147         printf("\n");
148 }
149
150 /************** Function: method_display_w_class  (debugging only) **************/
151
152 void method_display_w_class(methodinfo *m)
153 {
154         printflags(m->class->flags);
155         printf(" "); fflush(stdout);
156         utf_display(m->class->name);
157         printf(".");fflush(stdout);
158
159         printf("   ");
160         printflags(m->flags);
161         printf(" "); fflush(stdout);
162         utf_display(m->name);
163         printf(" "); fflush(stdout);
164         utf_display(m->descriptor);
165         printf("\n"); fflush(stdout);
166 }
167
168 /************** Function: method_display_flags_last  (debugging only) **************/
169
170 void method_display_flags_last(methodinfo *m)
171 {
172         printf(" ");
173         utf_display(m->name);
174         printf(" ");
175         utf_display(m->descriptor);
176         printf("   ");
177         printflags(m->flags);
178         printf("\n");
179 }
180
181
182 /*
183  * These are local overrides for various environment variables in Emacs.
184  * Please do not remove this and leave it at the end of the file, where
185  * Emacs will automagically detect them.
186  * ---------------------------------------------------------------------
187  * Local variables:
188  * mode: c
189  * indent-tabs-mode: t
190  * c-basic-offset: 4
191  * tab-width: 4
192  * End:
193  */