1 /* src/vm/method.c - method functions
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
8 This file is part of CACAO.
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.
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.
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
25 Contact: cacao@cacaojvm.org
27 Authors: Reinhard Grafl
29 Changes: Andreas Krall
35 $Id: method.c 5038 2006-06-19 22:22:34Z twisti $
47 #include "mm/memory.h"
49 #include "vm/global.h"
50 #include "vm/linker.h"
51 #include "vm/loader.h"
52 #include "vm/method.h"
53 #include "vm/jit/methodheader.h"
56 /* method_free *****************************************************************
58 Frees all memory that was allocated for this method.
60 *******************************************************************************/
62 void method_free(methodinfo *m)
65 MFREE(m->jcode, u1, m->jcodelength);
67 if (m->exceptiontable)
68 MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
70 code_free_code_of_method(m);
73 if (m->flags & ACC_NATIVE) {
74 removenativestub(m->stubroutine);
77 removecompilerstub(m->stubroutine);
83 /* method_canoverwrite *********************************************************
85 Check if m and old are identical with respect to type and
86 name. This means that old can be overwritten with m.
88 *******************************************************************************/
90 bool method_canoverwrite(methodinfo *m, methodinfo *old)
92 if (m->name != old->name)
95 if (m->descriptor != old->descriptor)
98 if (m->flags & ACC_STATIC)
105 /* method_vftbl_lookup *********************************************************
107 Does a method lookup in the passed virtual function table. This
108 function does exactly the same thing as JIT, but additionally
109 relies on the fact, that the methodinfo pointer is at the first
110 data segment slot (even for compiler stubs).
112 *******************************************************************************/
114 methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m)
118 methodinfo *resm; /* pointer to new resolved method */
121 /* If the method is not an instance method, just return it. */
123 if (m->flags & ACC_STATIC)
128 /* Get the method from the virtual function table. Is this an
131 if (m->class->flags & ACC_INTERFACE) {
132 pmptr = vftbl->interfacetable[-(m->class->index)];
133 mptr = pmptr[(m - m->class->methods)];
136 mptr = vftbl->table[m->vftblindex];
139 /* and now get the codeinfo pointer from the first data segment slot */
141 code = *((codeinfo **) (mptr + CodeinfoPointer));
149 /* method_printflags ***********************************************************
151 Prints the flags of a method to stdout like.
153 *******************************************************************************/
156 void method_printflags(methodinfo *m)
163 if (m->flags & ACC_PUBLIC) printf(" PUBLIC");
164 if (m->flags & ACC_PRIVATE) printf(" PRIVATE");
165 if (m->flags & ACC_PROTECTED) printf(" PROTECTED");
166 if (m->flags & ACC_STATIC) printf(" STATIC");
167 if (m->flags & ACC_FINAL) printf(" FINAL");
168 if (m->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
169 if (m->flags & ACC_VOLATILE) printf(" VOLATILE");
170 if (m->flags & ACC_TRANSIENT) printf(" TRANSIENT");
171 if (m->flags & ACC_NATIVE) printf(" NATIVE");
172 if (m->flags & ACC_INTERFACE) printf(" INTERFACE");
173 if (m->flags & ACC_ABSTRACT) printf(" ABSTRACT");
175 #endif /* !defined(NDEBUG) */
178 /* method_print ****************************************************************
180 Prints a method to stdout like:
182 java.lang.Object.<init>()V
184 *******************************************************************************/
187 void method_print(methodinfo *m)
194 utf_display_printable_ascii_classname(m->class->name);
196 utf_display_printable_ascii(m->name);
197 utf_display_printable_ascii(m->descriptor);
199 method_printflags(m);
201 #endif /* !defined(NDEBUG) */
204 /* method_println **************************************************************
206 Prints a method plus new line to stdout like:
208 java.lang.Object.<init>()V
210 *******************************************************************************/
213 void method_println(methodinfo *m)
218 #endif /* !defined(NDEBUG) */
221 /* method_methodref_print ******************************************************
223 Prints a method reference to stdout.
225 *******************************************************************************/
228 void method_methodref_print(constant_FMIref *mr)
231 printf("(constant_FMIref *)NULL");
235 if (IS_FMIREF_RESOLVED(mr)) {
237 method_print(mr->p.method);
240 printf("<methodref> ");
241 utf_display_printable_ascii_classname(mr->p.classref->name);
243 utf_display_printable_ascii(mr->name);
244 utf_display_printable_ascii(mr->descriptor);
247 #endif /* !defined(NDEBUG) */
250 /* method_methodref_println ****************************************************
252 Prints a method reference to stdout, followed by a newline.
254 *******************************************************************************/
257 void method_methodref_println(constant_FMIref *mr)
259 method_methodref_print(mr);
262 #endif /* !defined(NDEBUG) */
266 * These are local overrides for various environment variables in Emacs.
267 * Please do not remove this and leave it at the end of the file, where
268 * Emacs will automagically detect them.
269 * ---------------------------------------------------------------------
272 * indent-tabs-mode: t
276 * vim:noexpandtab:sw=4:ts=4: