* src/vm/jit/allocator/simplereg.c (new_allocate_scratch_registers):
[cacao.git] / src / vm / method.c
index 89c3c843c6e12c453fa55ec14ec8c475bc9ef752..6857e65c9c7f5bfcd866e92a90afe0eb83ad9002 100644 (file)
@@ -1,9 +1,9 @@
 /* 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 2186 2005-04-02 00:43:25Z edwin $
+   $Id: method.c 5038 2006-06-19 22:22:34Z twisti $
 
 */
 
 
-#include "vm/global.h"
+#include "config.h"
+
+#include <assert.h>
+#include <stdio.h>
+
+#include "vm/types.h"
+
 #include "mm/memory.h"
-#include "vm/method.h"
 #include "vm/class.h"
+#include "vm/global.h"
+#include "vm/linker.h"
 #include "vm/loader.h"
-#include "vm/jit/codegen.inc.h"
+#include "vm/method.h"
+#include "vm/jit/methodheader.h"
 
 
 /* method_free *****************************************************************
@@ -59,8 +67,7 @@ void method_free(methodinfo *m)
        if (m->exceptiontable)
                MFREE(m->exceptiontable, exceptiontable, m->exceptiontablelength);
 
-       if (m->mcode)
-               CFREE(m->mcode, m->mcodelength);
+       code_free_code_of_method(m);
 
        if (m->stubroutine) {
                if (m->flags & ACC_NATIVE) {
@@ -94,89 +101,165 @@ bool method_canoverwrite(methodinfo *m, methodinfo *old)
        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];
+       }
+
+       /* and now get the codeinfo pointer from the first data segment slot */
+
+       code = *((codeinfo **) (mptr + CodeinfoPointer));
+
+       resm = code->m;
+
+       return resm;
+}
+
+
+/* method_printflags ***********************************************************
+
+   Prints the flags of a method to stdout like.
+
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_printflags(methodinfo *m)
+{
+       if (m == NULL) {
+               printf("NULL");
+               return;
        }
 
-       paramtype = md->paramtypes;
-       for (i=0; i<md->paramcount; ++i,++paramtype)
-               *tptr++ = paramtype->type;
+       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
+
+*******************************************************************************/
 
-       m->returntype = md->returntype.type;
-       m->paramcount = pcount;
-       m->paramtypes = types;
+#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:
 
-/************** Function: method_display  (debugging only) **************/
+   java.lang.Object.<init>()V
 
-void method_display(methodinfo *m)
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_println(methodinfo *m)
 {
-       printf("   ");
-       printflags(m->flags);
-       printf(" ");
-       utf_display(m->name);
-       printf(" "); 
-       utf_display(m->descriptor);
+       method_print(m);
        printf("\n");
 }
+#endif /* !defined(NDEBUG) */
+
+
+/* method_methodref_print ******************************************************
 
-/************** Function: method_display_w_class  (debugging only) **************/
+   Prints a method reference to stdout.
 
-void method_display_w_class(methodinfo *m)
+*******************************************************************************/
+
+#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) */
 
 
 /*
@@ -190,4 +273,5 @@ void method_display_flags_last(methodinfo *m)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */