* intrp_md_stacktrace_get_returnaddress: Added.
[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 4008 2005-12-30 14:13:10Z twisti $
36
37 */
38
39
40 #include "config.h"
41 #include "vm/types.h"
42
43 #include "mm/memory.h"
44 #include "vm/class.h"
45 #include "vm/global.h"
46 #include "vm/loader.h"
47 #include "vm/method.h"
48
49
50 /* method_free *****************************************************************
51
52    Frees all memory that was allocated for this method.
53
54 *******************************************************************************/
55
56 void method_free(methodinfo *m)
57 {
58         if (m->jcode)
59                 MFREE(m->jcode, u1, m->jcodelength);
60
61         if (m->exceptiontable)
62                 MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
63
64         if (m->mcode)
65                 CFREE((void *) (ptrint) m->mcode, m->mcodelength);
66
67         if (m->stubroutine) {
68                 if (m->flags & ACC_NATIVE) {
69                         removenativestub(m->stubroutine);
70
71                 } else {
72                         removecompilerstub(m->stubroutine);
73                 }
74         }
75 }
76
77
78 /* method_canoverwrite *********************************************************
79
80    Check if m and old are identical with respect to type and
81    name. This means that old can be overwritten with m.
82         
83 *******************************************************************************/
84
85 bool method_canoverwrite(methodinfo *m, methodinfo *old)
86 {
87         if (m->name != old->name)
88                 return false;
89
90         if (m->descriptor != old->descriptor)
91                 return false;
92
93         if (m->flags & ACC_STATIC)
94                 return false;
95
96         return true;
97 }
98
99 /* method_descriptor2types *****************************************************
100
101    Fills in the following members of the given methodinfo:
102        returntype
103            paramcount
104        paramtypes          
105
106    Note:
107        This function uses dump_alloc functions to allocate memory.
108
109 *******************************************************************************/                
110
111 void method_descriptor2types(methodinfo *m)
112 {
113         u1 *types, *tptr;
114         int pcount, i;
115         methoddesc *md = m->parseddesc;
116         typedesc *paramtype;
117         
118         pcount = md->paramcount;
119         if ((m->flags & ACC_STATIC) == 0)
120                 pcount++; /* count this pointer */
121         
122         types = DMNEW(u1,pcount);
123         tptr = types;
124         
125         if (!(m->flags & ACC_STATIC)) {
126                 /* this pointer */
127                 *tptr++ = TYPE_ADR;
128         }
129
130         paramtype = md->paramtypes;
131         for (i=0; i<md->paramcount; ++i,++paramtype)
132                 *tptr++ = paramtype->type;
133
134         m->returntype = md->returntype.type;
135         m->paramcount = pcount;
136         m->paramtypes = types;
137 }
138
139 /************** Function: method_display  (debugging only) **************/
140
141 void method_display(methodinfo *m)
142 {
143         printf("   ");
144         printflags(m->flags);
145         printf(" ");
146         utf_display(m->name);
147         printf(" "); 
148         utf_display(m->descriptor);
149         printf("\n");
150 }
151
152 /************** Function: method_display_w_class  (debugging only) **************/
153
154 void method_display_w_class(methodinfo *m)
155 {
156         printflags(m->class->flags);
157         printf(" "); fflush(stdout);
158         utf_display(m->class->name);
159         printf(".");fflush(stdout);
160
161         printf("   ");
162         printflags(m->flags);
163         printf(" "); fflush(stdout);
164         utf_display(m->name);
165         printf(" "); fflush(stdout);
166         utf_display(m->descriptor);
167         printf("\n"); fflush(stdout);
168 }
169
170 /************** Function: method_display_flags_last  (debugging only) **************/
171
172 void method_display_flags_last(methodinfo *m)
173 {
174         printf(" ");
175         utf_display(m->name);
176         printf(" ");
177         utf_display(m->descriptor);
178         printf("   ");
179         printflags(m->flags);
180         printf("\n");
181 }
182
183
184 /*
185  * These are local overrides for various environment variables in Emacs.
186  * Please do not remove this and leave it at the end of the file, where
187  * Emacs will automagically detect them.
188  * ---------------------------------------------------------------------
189  * Local variables:
190  * mode: c
191  * indent-tabs-mode: t
192  * c-basic-offset: 4
193  * tab-width: 4
194  * End:
195  */