/* src/vm/method.c - method functions
- Copyright (C) 1996-2005 R. Grafl, A. Krall, C. Kruegel, C. Oates,
- R. Obermaisser, M. Platter, M. Probst, S. Ring, E. Steiner,
- C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich, J. Wenninger,
- Institut f. Computersprachen - TU Wien
+ Copyright (C) 1996-2005, 2006 R. Grafl, A. Krall, C. Kruegel,
+ C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
+ E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
+ J. Wenninger, Institut f. Computersprachen - TU Wien
This file is part of CACAO.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- 02111-1307, USA.
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
- Contact: cacao@complang.tuwien.ac.at
+ Contact: cacao@cacaojvm.org
Authors: Reinhard Grafl
Edwin Steiner
Christian Thalinger
- $Id: method.c 4008 2005-12-30 14:13:10Z twisti $
+ $Id: method.c 5038 2006-06-19 22:22:34Z twisti $
*/
#include "config.h"
+
+#include <assert.h>
+#include <stdio.h>
+
#include "vm/types.h"
#include "mm/memory.h"
#include "vm/class.h"
#include "vm/global.h"
+#include "vm/linker.h"
#include "vm/loader.h"
#include "vm/method.h"
+#include "vm/jit/methodheader.h"
/* method_free *****************************************************************
if (m->exceptiontable)
MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
- if (m->mcode)
- CFREE((void *) (ptrint) m->mcode, m->mcodelength);
+ code_free_code_of_method(m);
if (m->stubroutine) {
if (m->flags & ACC_NATIVE) {
return true;
}
-/* method_descriptor2types *****************************************************
- Fills in the following members of the given methodinfo:
- returntype
- paramcount
- paramtypes
+/* method_vftbl_lookup *********************************************************
- Note:
- This function uses dump_alloc functions to allocate memory.
+ Does a method lookup in the passed virtual function table. This
+ function does exactly the same thing as JIT, but additionally
+ relies on the fact, that the methodinfo pointer is at the first
+ data segment slot (even for compiler stubs).
-*******************************************************************************/
+*******************************************************************************/
-void method_descriptor2types(methodinfo *m)
+methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m)
{
- u1 *types, *tptr;
- int pcount, i;
- methoddesc *md = m->parseddesc;
- typedesc *paramtype;
-
- pcount = md->paramcount;
- if ((m->flags & ACC_STATIC) == 0)
- pcount++; /* count this pointer */
-
- types = DMNEW(u1,pcount);
- tptr = types;
-
- if (!(m->flags & ACC_STATIC)) {
- /* this pointer */
- *tptr++ = TYPE_ADR;
+ methodptr mptr;
+ methodptr *pmptr;
+ methodinfo *resm; /* pointer to new resolved method */
+ codeinfo *code;
+
+ /* If the method is not an instance method, just return it. */
+
+ if (m->flags & ACC_STATIC)
+ return m;
+
+ assert(vftbl);
+
+ /* Get the method from the virtual function table. Is this an
+ interface method? */
+
+ if (m->class->flags & ACC_INTERFACE) {
+ pmptr = vftbl->interfacetable[-(m->class->index)];
+ mptr = pmptr[(m - m->class->methods)];
+ }
+ else {
+ mptr = vftbl->table[m->vftblindex];
}
- paramtype = md->paramtypes;
- for (i=0; i<md->paramcount; ++i,++paramtype)
- *tptr++ = paramtype->type;
+ /* and now get the codeinfo pointer from the first data segment slot */
+
+ code = *((codeinfo **) (mptr + CodeinfoPointer));
- m->returntype = md->returntype.type;
- m->paramcount = pcount;
- m->paramtypes = types;
+ resm = code->m;
+
+ return resm;
}
-/************** Function: method_display (debugging only) **************/
-void method_display(methodinfo *m)
+/* method_printflags ***********************************************************
+
+ Prints the flags of a method to stdout like.
+
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_printflags(methodinfo *m)
{
- printf(" ");
- printflags(m->flags);
- printf(" ");
- utf_display(m->name);
- printf(" ");
- utf_display(m->descriptor);
+ if (m == NULL) {
+ printf("NULL");
+ return;
+ }
+
+ if (m->flags & ACC_PUBLIC) printf(" PUBLIC");
+ if (m->flags & ACC_PRIVATE) printf(" PRIVATE");
+ if (m->flags & ACC_PROTECTED) printf(" PROTECTED");
+ if (m->flags & ACC_STATIC) printf(" STATIC");
+ if (m->flags & ACC_FINAL) printf(" FINAL");
+ if (m->flags & ACC_SYNCHRONIZED) printf(" SYNCHRONIZED");
+ if (m->flags & ACC_VOLATILE) printf(" VOLATILE");
+ if (m->flags & ACC_TRANSIENT) printf(" TRANSIENT");
+ if (m->flags & ACC_NATIVE) printf(" NATIVE");
+ if (m->flags & ACC_INTERFACE) printf(" INTERFACE");
+ if (m->flags & ACC_ABSTRACT) printf(" ABSTRACT");
+}
+#endif /* !defined(NDEBUG) */
+
+
+/* method_print ****************************************************************
+
+ Prints a method to stdout like:
+
+ java.lang.Object.<init>()V
+
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_print(methodinfo *m)
+{
+ if (m == NULL) {
+ printf("NULL");
+ return;
+ }
+
+ utf_display_printable_ascii_classname(m->class->name);
+ printf(".");
+ utf_display_printable_ascii(m->name);
+ utf_display_printable_ascii(m->descriptor);
+
+ method_printflags(m);
+}
+#endif /* !defined(NDEBUG) */
+
+
+/* method_println **************************************************************
+
+ Prints a method plus new line to stdout like:
+
+ java.lang.Object.<init>()V
+
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_println(methodinfo *m)
+{
+ method_print(m);
printf("\n");
}
+#endif /* !defined(NDEBUG) */
-/************** Function: method_display_w_class (debugging only) **************/
-void method_display_w_class(methodinfo *m)
+/* method_methodref_print ******************************************************
+
+ Prints a method reference to stdout.
+
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_methodref_print(constant_FMIref *mr)
{
- printflags(m->class->flags);
- printf(" "); fflush(stdout);
- utf_display(m->class->name);
- printf(".");fflush(stdout);
-
- printf(" ");
- printflags(m->flags);
- printf(" "); fflush(stdout);
- utf_display(m->name);
- printf(" "); fflush(stdout);
- utf_display(m->descriptor);
- printf("\n"); fflush(stdout);
+ if (!mr) {
+ printf("(constant_FMIref *)NULL");
+ return;
+ }
+
+ if (IS_FMIREF_RESOLVED(mr)) {
+ printf("<method> ");
+ method_print(mr->p.method);
+ }
+ else {
+ printf("<methodref> ");
+ utf_display_printable_ascii_classname(mr->p.classref->name);
+ printf(".");
+ utf_display_printable_ascii(mr->name);
+ utf_display_printable_ascii(mr->descriptor);
+ }
}
+#endif /* !defined(NDEBUG) */
+
+
+/* method_methodref_println ****************************************************
-/************** Function: method_display_flags_last (debugging only) **************/
+ Prints a method reference to stdout, followed by a newline.
-void method_display_flags_last(methodinfo *m)
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_methodref_println(constant_FMIref *mr)
{
- printf(" ");
- utf_display(m->name);
- printf(" ");
- utf_display(m->descriptor);
- printf(" ");
- printflags(m->flags);
- printf("\n");
+ method_methodref_print(mr);
+ printf("\n");
}
+#endif /* !defined(NDEBUG) */
/*
* c-basic-offset: 4
* tab-width: 4
* End:
+ * vim:noexpandtab:sw=4:ts=4:
*/