* src/vm/jit/intrp/codegen.c (createcalljavafunction):
[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 4404 2006-02-03 12:38:03Z 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
103 /* method_printflags ***********************************************************
104
105    Prints the flags of a method to stdout like.
106
107 *******************************************************************************/
108
109 #if !defined(NDEBUG)
110 void method_printflags(methodinfo *m)
111 {
112         if (m == NULL) {
113                 printf("NULL");
114                 return;
115         }
116
117         if (m->flags & ACC_PUBLIC)       printf(" PUBLIC");
118         if (m->flags & ACC_PRIVATE)      printf(" PRIVATE");
119         if (m->flags & ACC_PROTECTED)    printf(" PROTECTED");
120         if (m->flags & ACC_STATIC)       printf(" STATIC");
121         if (m->flags & ACC_FINAL)        printf(" FINAL");
122         if (m->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
123         if (m->flags & ACC_VOLATILE)     printf(" VOLATILE");
124         if (m->flags & ACC_TRANSIENT)    printf(" TRANSIENT");
125         if (m->flags & ACC_NATIVE)       printf(" NATIVE");
126         if (m->flags & ACC_INTERFACE)    printf(" INTERFACE");
127         if (m->flags & ACC_ABSTRACT)     printf(" ABSTRACT");
128 }
129 #endif /* !defined(NDEBUG) */
130
131
132 /* method_print ****************************************************************
133
134    Prints a method to stdout like:
135
136    java.lang.Object.<init>()V
137
138 *******************************************************************************/
139
140 #if !defined(NDEBUG)
141 void method_print(methodinfo *m)
142 {
143         if (m == NULL) {
144                 printf("NULL");
145                 return;
146         }
147
148         utf_display_classname(m->class->name);
149         printf(".");
150         utf_display(m->name);
151         utf_display(m->descriptor);
152
153         method_printflags(m);
154 }
155 #endif /* !defined(NDEBUG) */
156
157
158 /* method_println **************************************************************
159
160    Prints a method plus new line to stdout like:
161
162    java.lang.Object.<init>()V
163
164 *******************************************************************************/
165
166 #if !defined(NDEBUG)
167 void method_println(methodinfo *m)
168 {
169         method_print(m);
170         printf("\n");
171 }
172 #endif /* !defined(NDEBUG) */
173
174
175 /*
176  * These are local overrides for various environment variables in Emacs.
177  * Please do not remove this and leave it at the end of the file, where
178  * Emacs will automagically detect them.
179  * ---------------------------------------------------------------------
180  * Local variables:
181  * mode: c
182  * indent-tabs-mode: t
183  * c-basic-offset: 4
184  * tab-width: 4
185  * End:
186  */