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 5785 2006-10-15 22:25:54Z edwin $
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/options.h"
54 #include "vm/jit/methodheader.h"
57 /* method_free *****************************************************************
59 Frees all memory that was allocated for this method.
61 *******************************************************************************/
63 void method_free(methodinfo *m)
66 MFREE(m->jcode, u1, m->jcodelength);
68 if (m->rawexceptiontable)
69 MFREE(m->rawexceptiontable, raw_exception_entry, m->rawexceptiontablelength);
71 code_free_code_of_method(m);
74 if (m->flags & ACC_NATIVE) {
75 removenativestub(m->stubroutine);
78 removecompilerstub(m->stubroutine);
84 /* method_canoverwrite *********************************************************
86 Check if m and old are identical with respect to type and
87 name. This means that old can be overwritten with m.
89 *******************************************************************************/
91 bool method_canoverwrite(methodinfo *m, methodinfo *old)
93 if (m->name != old->name)
96 if (m->descriptor != old->descriptor)
99 if (m->flags & ACC_STATIC)
106 /* method_vftbl_lookup *********************************************************
108 Does a method lookup in the passed virtual function table. This
109 function does exactly the same thing as JIT, but additionally
110 relies on the fact, that the methodinfo pointer is at the first
111 data segment slot (even for compiler stubs).
113 *******************************************************************************/
115 methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m)
119 methodinfo *resm; /* pointer to new resolved method */
122 /* If the method is not an instance method, just return it. */
124 if (m->flags & ACC_STATIC)
129 /* Get the method from the virtual function table. Is this an
132 if (m->class->flags & ACC_INTERFACE) {
133 pmptr = vftbl->interfacetable[-(m->class->index)];
134 mptr = pmptr[(m - m->class->methods)];
137 mptr = vftbl->table[m->vftblindex];
140 /* and now get the codeinfo pointer from the first data segment slot */
142 code = *((codeinfo **) (mptr + CodeinfoPointer));
150 /* method_printflags ***********************************************************
152 Prints the flags of a method to stdout like.
154 *******************************************************************************/
157 void method_printflags(methodinfo *m)
164 if (m->flags & ACC_PUBLIC) printf(" PUBLIC");
165 if (m->flags & ACC_PRIVATE) printf(" PRIVATE");
166 if (m->flags & ACC_PROTECTED) printf(" PROTECTED");
167 if (m->flags & ACC_STATIC) printf(" STATIC");
168 if (m->flags & ACC_FINAL) printf(" FINAL");
169 if (m->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
170 if (m->flags & ACC_VOLATILE) printf(" VOLATILE");
171 if (m->flags & ACC_TRANSIENT) printf(" TRANSIENT");
172 if (m->flags & ACC_NATIVE) printf(" NATIVE");
173 if (m->flags & ACC_INTERFACE) printf(" INTERFACE");
174 if (m->flags & ACC_ABSTRACT) printf(" ABSTRACT");
176 #endif /* !defined(NDEBUG) */
179 /* method_print ****************************************************************
181 Prints a method to stdout like:
183 java.lang.Object.<init>()V
185 *******************************************************************************/
188 void method_print(methodinfo *m)
195 utf_display_printable_ascii_classname(m->class->name);
197 utf_display_printable_ascii(m->name);
198 utf_display_printable_ascii(m->descriptor);
200 method_printflags(m);
202 #endif /* !defined(NDEBUG) */
205 /* method_println **************************************************************
207 Prints a method plus new line to stdout like:
209 java.lang.Object.<init>()V
211 *******************************************************************************/
214 void method_println(methodinfo *m)
216 if (opt_debugcolor) printf("\033[31m"); /* red */
218 if (opt_debugcolor) printf("\033[m");
221 #endif /* !defined(NDEBUG) */
224 /* method_methodref_print ******************************************************
226 Prints a method reference to stdout.
228 *******************************************************************************/
231 void method_methodref_print(constant_FMIref *mr)
234 printf("(constant_FMIref *)NULL");
238 if (IS_FMIREF_RESOLVED(mr)) {
240 method_print(mr->p.method);
243 printf("<methodref> ");
244 utf_display_printable_ascii_classname(mr->p.classref->name);
246 utf_display_printable_ascii(mr->name);
247 utf_display_printable_ascii(mr->descriptor);
250 #endif /* !defined(NDEBUG) */
253 /* method_methodref_println ****************************************************
255 Prints a method reference to stdout, followed by a newline.
257 *******************************************************************************/
260 void method_methodref_println(constant_FMIref *mr)
262 method_methodref_print(mr);
265 #endif /* !defined(NDEBUG) */
269 * These are local overrides for various environment variables in Emacs.
270 * Please do not remove this and leave it at the end of the file, where
271 * Emacs will automagically detect them.
272 * ---------------------------------------------------------------------
275 * indent-tabs-mode: t
279 * vim:noexpandtab:sw=4:ts=4: