* Updated header: Added 2006. Changed address of FSF. Changed email
[cacao.git] / src / vm / jit / inline / parseXTA.c
index ac9a6b9936b9e7ca129d9977d20c784f0b4147b1..aef76060f91f51abd4f570debd98896f45c4f648 100644 (file)
@@ -11,12 +11,13 @@ What about recursion???  x.a calls x.a
 Now wondering if there is a memory corruption because XTA seems to finish ok
 ****/
 
-/* jit/parseXTA.c - parser and print functions for Rapid Type Analyis
+/* src/vm/jit/inline/parseXTA.c - parser and print functions for
+                                  Rapid Type Analyis
 
-   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.
 
@@ -32,14 +33,16 @@ Now wondering if there is a memory corruption because XTA seems to finish ok
 
    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: Carolyn Oates
 
-   $Id: parseXTA.c 2189 2005-04-02 02:05:59Z edwin $
+   Changes: Christian Thalinger
+
+   $Id: parseXTA.c 4357 2006-01-22 23:33:38Z twisti $
 
 */
 
@@ -115,6 +118,8 @@ Results: (currently) with -stat see # methods marked used
  
 ****************/
 
+
+#include <assert.h>
 #include <stdio.h>
 #include <string.h>
 
@@ -122,13 +127,13 @@ Results: (currently) with -stat see # methods marked used
 #include "cacao/cacao.h"
 #include "mm/memory.h"   
 #include "toolbox/list.h"
+#include "toolbox/logging.h"
 #include "vm/class.h"
 #include "vm/linker.h"
 #include "vm/loader.h"
 #include "vm/resolve.h"
 #include "vm/options.h"
 #include "vm/statistics.h"
-#include "vm/tables.h"
 #include "vm/jit/jit.h"
 #include "vm/jit/parse.h"
 #include "vm/jit/inline/parseXTA.h"
@@ -170,10 +175,12 @@ static classSetNode *descriptor2typesL(methodinfo *m)
        char *class; 
        char *desc;
        classSetNode *p=NULL;
+       classinfo *clsinfo;
+       
        if (debugInfo >= 1) {
                printf("In descriptor2typesL >>>\t"); fflush(stdout);
                utf_display(m->class->name); printf(".");
-               method_display(m);fflush(stdout);
+               method_println(m);fflush(stdout);
        }
 
        pcount = 0;
@@ -215,8 +222,12 @@ static classSetNode *descriptor2typesL(methodinfo *m)
                        class = strtok(desc,";");
                        desc = strtok(NULL,"\0");
                        /* get/save classinfo ptr */
-                       classtypes[pcount-1] = class_get(utf_new_char(class));
-                       p = addClassCone(p,  class_get(utf_new_char(class)));
+                       if (!(clsinfo = load_class_bootstrap(utf_new_char(class)))) {
+                               log_text("could not load class in descriptor2typesL");
+                               assert(0);
+                       }
+                       classtypes[pcount-1] = clsinfo;
+                       p = addClassCone(p, clsinfo);
                        if (debugInfo >= 1) {
                                printf("LParam#%i 's class type is: %s\n",pcount-1,class);fflush(stdout);
                                printf("Lclasstypes[%i]=",pcount-1);fflush(stdout);
@@ -231,8 +242,12 @@ static classSetNode *descriptor2typesL(methodinfo *m)
                                class = strtok(desc,";");
                                desc = strtok(NULL,"\0");
                                /* get/save classinfo ptr */
-                               classtypes[pcount-1] = class_get(utf_new_char(class));
-                               p= addClassCone(p,  class_get(utf_new_char(class)));
+                               if (!(clsinfo = load_class_bootstrap(utf_new_char(class)))) {
+                                       log_text("could not load class in descriptor2typesL");
+                                       assert(0);
+                               }
+                               classtypes[pcount-1] = clsinfo;
+                               p= addClassCone(p, clsinfo);
                                if (debugInfo >= 1) {
                                        printf("[Param#%i 's class type is: %s\n",pcount-1,class);
                                        printf("[classtypes[%i]=",pcount-1);fflush(stdout);
@@ -244,7 +259,8 @@ static classSetNode *descriptor2typesL(methodinfo *m)
                                classtypes[pcount-1] = NULL;
                        break;
                default:   
-                       panic("Ill formed methodtype-descriptor");
+                       log_text("Ill formed methodtype-descriptor");
+                       assert(0);
                }
        }
 
@@ -277,16 +293,23 @@ static classSetNode *descriptor2typesL(methodinfo *m)
                          
                /* get class string */
                class = strtok(desc,";");
-               m->returnclass = class_get(utf_new_char(class));
+               if (!(clsinfo = load_class_bootstrap(utf_new_char(class)))) {
+                       log_text("could not load class in descriptor2typesL");
+                       assert(0);
+               }
+               m->returnclass = clsinfo;
                if (m->returnclass == NULL) {
                        printf("class=<%s>\t",class); fflush(stdout);
-                       panic ("return class not found");
+                       log_text("return class not found");
+                       assert(0);
                }
                break;
        case 'V':  m->returntype = TYPE_VOID;
                break;
 
-       default:   panic("Ill formed methodtype-descriptor-ReturnType");
+       default:
+               log_text("Ill formed methodtype-descriptor-ReturnType");
+               assert(0);
        }
 
        m->paramcount = pcount;
@@ -342,7 +365,7 @@ xtainfo *xtainfoInit(methodinfo *m)
         if (m->xta != NULL)
                 return m->xta; /* already initialized */
 
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
        count_methods_marked_used++;
 #endif
 
@@ -429,8 +452,14 @@ mCalls->xta->calls->tail->monoPoly = monoPoly;
 mCalled->xta->calledBy = add2MethSet(mCalled->xta->calledBy, mCalls);
 
 /* IS THIS REALLY NEEDED???? */
-if (mCalled->xta->calledBy == NULL) panic("mCalled->xta->calledBy is NULL!!!");
-if (mCalls->xta->calls == NULL) panic("mCalls->xta->calls is NULL!!!");
+if (mCalled->xta->calledBy == NULL) {
+       log_text("mCalled->xta->calledBy is NULL!!!");
+       assert(0);
+}
+if (mCalls->xta->calls == NULL) {
+       log_text("mCalls->xta->calls is NULL!!!");
+       assert(0);
+}
 
 }
 
@@ -444,6 +473,10 @@ bool xtaPassParams (methodinfo *Called, methodinfo *Calls, methSetNode *lastptrI
         classSetNode *cprev;
         bool          chgd = false;
 
+               /* prevent compiler warnings */
+
+               c1 = NULL;
+
         if (lastptrInto->lastptrIntoClassSet2 == NULL) {
                 if (Calls->xta->XTAclassSet != NULL)
                         c1 = Calls->xta->XTAclassSet->head;
@@ -665,7 +698,11 @@ void  xtaMethodCalls_and_sendReturnType(methodinfo *m)
 
         xtaAllFldsUsed (m);
 
-       if (m->xta == NULL) panic("m->xta null for return type\n");
+               if (m->xta == NULL) {
+                       log_text("m->xta null for return type");
+                       assert(0);
+               }
+
         /* for each method that this method calls */
         if (m->xta->calls == NULL)
                 s1 = NULL;
@@ -728,7 +765,10 @@ bool xtaAddFldClassTypeInfo(fieldinfo *fi) {
                                desc = MNEW(char, 256);
                                strcpy(desc,++utf_ptr);
                                cname = strtok(desc,";");
-                               class = class_get(utf_new_char(cname));
+                               if (!(class = load_class_bootstrap(utf_new_char(cname)))) {
+                                       log_text("could not load class in xtaAddFldClassTypeInfo");
+                                       assert(0);
+                               }
                                fi->xta->fldClassType= class;    /* save field's type class ptr */      
                        } 
                }
@@ -765,8 +805,8 @@ if (submeth == NULL) {
        utf_display(class->name); printf(".");
        METHINFOx(topmethod);
        printf("parse XTA: Method not found in class hierarchy");fflush(stdout);
-       panic("parse XTA: Method not found in class hierarchy");
-       }
+       assert(0);
+}
 
 /* if submeth called previously from this method then return */
 if (mCalls->xta->calls != NULL) {
@@ -931,11 +971,11 @@ void xtaAddUsedInterfaceMethods(methodinfo *m, classinfo *ci) {
                                methodinfo *imi = &(ici->methods[mm]);
                                        if  ( (XTA_DEBUGinf) && (imi->methodUsed != USED)) {
                                                printf("Interface Method %s: ", methFlgs[imi->methodUsed]); 
-                                               utf_display(ici->name);printf(".");method_display(imi);fflush(stdout);
+                                               utf_display(ici->name);printf(".");method_println(imi);fflush(stdout);
                                        }
                                if  (imi->methodUsed == USED) {
                                            if (XTA_DEBUGinf) { 
-                                               printf("Interface Method used: "); utf_display(ici->name);printf(".");method_display(imi);fflush(stdout);
+                                               printf("Interface Method used: "); utf_display(ici->name);printf(".");method_println(imi);fflush(stdout);
                                                /* Mark this method used in the (used) implementing class &its subclasses */
                                                printf("rMAY ADD methods that was used by an interface\n");
                                                }
@@ -1105,8 +1145,10 @@ if ((XTA_DEBUGr)||(XTA_DEBUGopcodes)) printf("\n");
                SHOWOPCODE(XTA_DEBUGopcodes)
 
                nextp = p + jcommandsize[opcode];   /* compute next instr start */
-               if (nextp > m->jcodelength)
-                       panic("Unexpected end of bytecode");
+               if (nextp > m->jcodelength) {
+                       log_text("Unexpected end of bytecode");
+                       assert(0);
+               }
 
                switch (opcode) {
 
@@ -1182,8 +1224,12 @@ if ((XTA_DEBUGr)||(XTA_DEBUGopcodes)) printf("\n");
                                classinfo *frclass;
 
                                fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
-                               if (!resolve_classref(m,fr->classref,resolveEager,true,&frclass))
-                                       panic("Could not resolve class reference");
+                               if (!fr)
+                                       return 0;
+                               if (!resolve_classref(m,fr->classref,resolveEager,true, true,&frclass)) {
+                                       log_text("Could not resolve class reference");
+                                       assert(0);
+                               }
                                LAZYLOADING(frclass)
 
                                fi = class_resolvefield(frclass,
@@ -1217,8 +1263,13 @@ printf(" PUTSTATIC:");fflush(stdout); utf_display(fi->class->name);printf(".");f
                                classinfo *frclass;
 
                                fr = class_getconstant(m->class, i, CONSTANT_Fieldref);
-                               if (!resolve_classref(m,fr->classref,resolveEager,true,&frclass))
-                                       panic("Could not resolve class reference");
+                               if (!fr)
+                                       return 0;
+                               if (!resolve_classref(m,fr->classref,resolveEager,true, true,&frclass)) {
+                                       log_text("Could not resolve class reference");
+                                       assert(0);
+                               }
+
                                LAZYLOADING(frclass)
 
                                fi = class_resolvefield(frclass,
@@ -1255,8 +1306,13 @@ printf(" GETSTATIC:");fflush(stdout); utf_display(fi->class->name);printf(".");f
                                classinfo *mrclass;
 
                                mr = class_getconstant(m->class, i, CONSTANT_Methodref);
-                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass))
-                                       panic("Could not resolve class reference");
+                               if (!mr)
+                                       return 0;
+                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
+                                       log_text("Could not resolve class reference");
+                                       assert(0);
+                               }
+
                                LAZYLOADING(mrclass) 
                                mi = class_resolveclassmethod(  mrclass,
                                                                                                mr->name,
@@ -1362,10 +1418,14 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                 methodinfo *mi;
                                                                classinfo *mrclass;
 
+                                                               /* XXX remove direct access */
                                mr = m->class->cpinfos[i];
                                 /*mr = class_getconstant(m->class, i, CONSTANT_Methodref)*/
-                                       if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass))
-                                               panic("Could not resolve class reference");
+                                       if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
+                                               log_text("Could not resolve class reference");
+                                               assert(0);
+                                       }
+
                                LAZYLOADING(mrclass) 
                                mi = class_resolveclassmethod(mrclass,
                                                 mr->name,
@@ -1419,8 +1479,13 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                                                                classinfo *mrclass;
 
                                 mr = class_getconstant(m->class, i, CONSTANT_InterfaceMethodref);
-                                                               if (!resolve_classref(m,mr->classref,resolveEager,true,&mrclass))
-                                                                       panic("Could not resolve class reference");
+                                                               if (!mr)
+                                                                       return 0;
+                                                               if (!resolve_classref(m,mr->classref,resolveEager,true, true,&mrclass)) {
+                                                                       log_text("Could not resolve class reference");
+                                                                       assert(0);
+                                                               }
+
                                 LAZYLOADING(mrclass)
 
                                 mi = class_resolveinterfacemethod(mrclass,
@@ -1446,7 +1511,11 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                         i = code_get_u2(p + 1,m);
                        {
                        classinfo *cls;
-                        cls = class_getconstant(m->class, i, CONSTANT_Class);
+                       constant_classref *cr;
+                       cr = (constant_classref *)class_getconstant(m->class, i, CONSTANT_Class);
+                       if (!cr)
+                               return 0;
+                       resolve_classref(NULL,cr,resolveEager,true, false,&cls);
                         /*** s_count++; look for s_counts for VTA */
                        /* add marked methods */
                        CLASSNAME(cls,"NEW : do nothing",XTA_DEBUGr);
@@ -1460,9 +1529,12 @@ utf_display(mr->descriptor); printf("\n");fflush(stdout);
                 /* class used */
                         i = code_get_u2(p + 1,m);
                         {
-                        classinfo *cls =
-                                (classinfo *)
-                            class_getconstant(m->class, i, CONSTANT_Class);
+                                                       constant_classref *cr;
+                                                       classinfo *cls;
+                                                       cr = (constant_classref*) class_getconstant(m->class, i, CONSTANT_Class);
+                                                       if (!cr)
+                                                               return 0;
+                                                       resolve_classref(NULL,cr,resolveEager,true, false,&cls);
                         LAZYLOADING(cls)
                                CLASSNAMEop(cls,XTA_DEBUGr);
                         if (cls->classUsed == NOTUSED){
@@ -1497,7 +1569,7 @@ else
 
 /*-- Get meth ptr for class.meth desc and add to XTA worklist --*/
 #define SYSADD(cls,meth,desc, is_mono_poly, txt) \
-  c = class_new(utf_new_char(cls)); \
+  c = load_class_bootstrap(utf_new_char(cls)); \
   LAZYLOADING(c) \
   callmeth = class_resolveclassmethod(c, \
     utf_new_char(meth), \
@@ -1613,9 +1685,10 @@ methodinfo *missedXTAworklist()
            if ((calls_class == NULL) || (calls_meth == NULL) || (calls_desc == NULL) 
            ||        (class == NULL) ||       (meth == NULL) ||       (desc == NULL))  
        ****/
-           if (        (class == NULL) ||       (meth == NULL) ||       (desc == NULL))  
-               panic (
-               "Error in xtaMissedIn file: Missing a part of calls_class.calls_meth calls calls_desc class.meth desc \n"); 
+           if (        (class == NULL) ||       (meth == NULL) ||       (desc == NULL)) {
+                       log_text("Error in xtaMissedIn file: Missing a part of calls_class.calls_meth calls calls_desc class.meth desc");
+                       assert(0);
+               }
            SYSADD(class,meth,desc, POLY, missedtxt)
            }
        fclose(xtaMissedIn);
@@ -1646,9 +1719,10 @@ void parseXTAmethod(methodinfo *xta_method) {
            else {
               printf("Abstract method in XTA Work List: ");
               METHINFOx(xta_method);
-              panic("Abstract method in XTA Work List.");
-               }
-            }                  
+              log_text("Abstract method in XTA Work List.");
+                  assert(0);
+               }
+       }               
 }
 
 void XTAprintCallgraph (list *xtaWorkList, char * txt);
@@ -1716,7 +1790,7 @@ void XTAprintCallgraph (list *xtaWorkList, char * txt)
     methodinfo *xta_meth;
 
  printf("\n%s\n",txt);
-#if defined(STATISTICS)
+#if defined(ENABLE_STATISTICS)
  printf("-*-*-*-*- XTA Callgraph Worklist:<%i>\n",count_methods_marked_used);
 #endif
 
@@ -1727,7 +1801,7 @@ void XTAprintCallgraph (list *xtaWorkList, char * txt)
          xta_meth = xta->method;
 
          printf("  (%i): ",i++);
-         method_display_w_class(xta_meth);
+         method_println(xta_meth);
         }
 
  printf("\n\n");