* src/vm/options.c (opt_foo): Added. This is a development option.
[cacao.git] / src / vm / method.c
index 1012c6870a27461fa410d87d96188b5548dea6fa..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 2100 2005-03-28 21:57:23Z 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/codegen.inc.h"
+#include "vm/jit/methodheader.h"
 
 
 /* method_free *****************************************************************
@@ -56,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) {
@@ -92,49 +102,164 @@ bool method_canoverwrite(methodinfo *m, methodinfo *old)
 }
 
 
-/************** Function: method_display  (debugging only) **************/
+/* method_vftbl_lookup *********************************************************
+
+   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).
+
+*******************************************************************************/
+
+methodinfo *method_vftbl_lookup(vftbl_t *vftbl, methodinfo* m)
+{
+       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;
+       }
+
+       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
 
-void method_display(methodinfo *m)
+*******************************************************************************/
+
+#if !defined(NDEBUG)
+void method_print(methodinfo *m)
 {
-       printf("   ");
-       printflags(m->flags);
-       printf(" ");
-       utf_display(m->name);
-       printf(" "); 
-       utf_display(m->descriptor);
+       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) */
+
+
+/* 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) */
 
 
 /*
@@ -148,4 +273,5 @@ void method_display_flags_last(methodinfo *m)
  * c-basic-offset: 4
  * tab-width: 4
  * End:
+ * vim:noexpandtab:sw=4:ts=4:
  */