* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / method.c
1 /* src/vm/method.c - method functions
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: Reinhard Grafl
28
29    Changes: Andreas Krall
30             Roman Obermaiser
31             Mark Probst
32             Edwin Steiner
33             Christian Thalinger
34
35    $Id: method.c 4357 2006-01-22 23:33:38Z twisti $
36
37 */
38
39
40 #include "config.h"
41
42 #include <stdio.h>
43
44 #include "vm/types.h"
45
46 #include "mm/memory.h"
47 #include "vm/class.h"
48 #include "vm/global.h"
49 #include "vm/loader.h"
50 #include "vm/method.h"
51
52
53 /* method_free *****************************************************************
54
55    Frees all memory that was allocated for this method.
56
57 *******************************************************************************/
58
59 void method_free(methodinfo *m)
60 {
61         if (m->jcode)
62                 MFREE(m->jcode, u1, m->jcodelength);
63
64         if (m->exceptiontable)
65                 MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
66
67         if (m->mcode)
68                 CFREE((void *) (ptrint) m->mcode, m->mcodelength);
69
70         if (m->stubroutine) {
71                 if (m->flags & ACC_NATIVE) {
72                         removenativestub(m->stubroutine);
73
74                 } else {
75                         removecompilerstub(m->stubroutine);
76                 }
77         }
78 }
79
80
81 /* method_canoverwrite *********************************************************
82
83    Check if m and old are identical with respect to type and
84    name. This means that old can be overwritten with m.
85         
86 *******************************************************************************/
87
88 bool method_canoverwrite(methodinfo *m, methodinfo *old)
89 {
90         if (m->name != old->name)
91                 return false;
92
93         if (m->descriptor != old->descriptor)
94                 return false;
95
96         if (m->flags & ACC_STATIC)
97                 return false;
98
99         return true;
100 }
101
102 /* method_descriptor2types *****************************************************
103
104    Fills in the following members of the given methodinfo:
105        returntype
106            paramcount
107        paramtypes          
108
109    Note:
110        This function uses dump_alloc functions to allocate memory.
111
112 *******************************************************************************/                
113
114 void method_descriptor2types(methodinfo *m)
115 {
116         u1 *types, *tptr;
117         int pcount, i;
118         methoddesc *md = m->parseddesc;
119         typedesc *paramtype;
120         
121         pcount = md->paramcount;
122         if ((m->flags & ACC_STATIC) == 0)
123                 pcount++; /* count this pointer */
124         
125         types = DMNEW(u1,pcount);
126         tptr = types;
127         
128         if (!(m->flags & ACC_STATIC)) {
129                 /* this pointer */
130                 *tptr++ = TYPE_ADR;
131         }
132
133         paramtype = md->paramtypes;
134         for (i=0; i<md->paramcount; ++i,++paramtype)
135                 *tptr++ = paramtype->type;
136
137         m->returntype = md->returntype.type;
138         m->paramcount = pcount;
139         m->paramtypes = types;
140 }
141
142
143 /* method_printflags ***********************************************************
144
145    Prints the flags of a method to stdout like.
146
147 *******************************************************************************/
148
149 #if !defined(NDEBUG)
150 void method_printflags(methodinfo *m)
151 {
152         if (m->flags & ACC_PUBLIC)       printf(" PUBLIC");
153         if (m->flags & ACC_PRIVATE)      printf(" PRIVATE");
154         if (m->flags & ACC_PROTECTED)    printf(" PROTECTED");
155         if (m->flags & ACC_STATIC)       printf(" STATIC");
156         if (m->flags & ACC_FINAL)        printf(" FINAL");
157         if (m->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
158         if (m->flags & ACC_VOLATILE)     printf(" VOLATILE");
159         if (m->flags & ACC_TRANSIENT)    printf(" TRANSIENT");
160         if (m->flags & ACC_NATIVE)       printf(" NATIVE");
161         if (m->flags & ACC_INTERFACE)    printf(" INTERFACE");
162         if (m->flags & ACC_ABSTRACT)     printf(" ABSTRACT");
163 }
164 #endif /* !defined(NDEBUG) */
165
166
167 /* method_print ****************************************************************
168
169    Prints a method to stdout like:
170
171    java.lang.Object.<init>()V
172
173 *******************************************************************************/
174
175 #if !defined(NDEBUG)
176 void method_print(methodinfo *m)
177 {
178         utf_display_classname(m->class->name);
179         printf(".");
180         utf_display(m->name);
181         utf_display(m->descriptor);
182
183         method_printflags(m);
184 }
185 #endif /* !defined(NDEBUG) */
186
187
188 /* method_println **************************************************************
189
190    Prints a method plus new line to stdout like:
191
192    java.lang.Object.<init>()V
193
194 *******************************************************************************/
195
196 #if !defined(NDEBUG)
197 void method_println(methodinfo *m)
198 {
199         method_print(m);
200         printf("\n");
201 }
202 #endif /* !defined(NDEBUG) */
203
204
205 /*
206  * These are local overrides for various environment variables in Emacs.
207  * Please do not remove this and leave it at the end of the file, where
208  * Emacs will automagically detect them.
209  * ---------------------------------------------------------------------
210  * Local variables:
211  * mode: c
212  * indent-tabs-mode: t
213  * c-basic-offset: 4
214  * tab-width: 4
215  * End:
216  */