Authors: Carolyn Oates
- $Id: parseRT.c 619 2003-11-13 13:49:23Z twisti $
+ $Id: parseRT.c 1296 2004-07-10 17:02:15Z stefan $
+
+Changes:
+opcode put into functions
+changed class_findmethod class_fetchmethod
*/
-#include "parseRT.h"
+#include "options.h"
+#include "jit/parseRT.h"
+
/*------------ global variables -----------------------------------------*/
#define MAXCALLGRAPH 5000
-bool XTAOPTbypass = false;
-bool XTAOPTbypass2 = false; /* for now invokeinterface */
-bool XTAOPTbypass3 = false; /* print XTA classsets in stats */
-int XTAdebug = 0;
-int XTAfld = 0;
+#include "jit/parseRTflags.h"
+
+
+bool NATIVE = false; // Dez version chasing Native problems
+
+int callgraphAddedBy[MAXCALLGRAPH]; // add comment
int methRT = 0;
int methRTlast = -1;
int methRTmax = MAXCALLGRAPH;
methodinfo **callgraph;
/*methodinfo *callgraph[MAXCALLGRAPH];*/
-
+
int methXTA = 0;
int methXTAlast = -1;
static bool nativecallcompdone=0 ;
static bool firstCall= true;
+static bool parse1 = true;
static bool AfterMain = false;
static FILE *rtMissed; /* Methods missed during RTA parse of Main */
/* so easier to build dynmanic calls file */
+static FILE *appldynm; /* Methods dynamically loaded by application */
+static utf *utf_OBJECT; /* utf_new_char("Object"); */
static utf *utf_MAIN; /* utf_new_char("main"); */
static utf *INIT ; /* utf_new_char("<init>"); */
static utf *CLINIT ; /* utf_new_char("<clinit>"); */
/* addToCallgraph - adds to RTA callgraph and */
/* sets meth->methodUsed to USED */
/*--------------------------------------------------------------*/
+// if ((meth->methodUsed != USED) && (!(meth->flags & ACC_ABSTRACT)) ) {
#define ADDTOCALLGRAPH(meth) if ((meth->methodUsed != USED) && (!(meth->flags & ACC_ABSTRACT)) ) { \
+ if (opt_rt) { \
callgraph[++methRTlast] = meth ; \
meth->methodUsed = USED; \
if(pWhenMarked>=1) \
{printf("\n Added to Call Graph #%i:", \
- methRTlast); \
+ methRTlast); \
printf("\t <used flags c/m> <%i/%i> %i\t", \
meth->class->classUsed, \
meth->methodUsed, \
printf(" method name ="); \
utf_display(meth->class->name);printf("."); \
method_display(meth);fflush(stdout);} \
- }
-
+ } }
/*--------------------------------------------------------------*/
bool rtaSubUsed(classinfo *class, methodinfo *meth) {
for (subs=class->sub; subs != NULL; subs = subs->nextsub) {
if (subs->classUsed == USED) {
- if (class_findmethod(class, meth->name, meth->descriptor) == NULL)
+ if (class_findmethod_w(class, meth->name, meth->descriptor,"rtaSubUsed") == NULL)
return false;
else
return true;
/* with the same method name */
/* */
/*-------------------------------------------------------------------------------*/
-void addMarkedMethods(classinfo *ci) {
+void rtaAddMarkedMethods(classinfo *ci) {
int ii,jj,mm;
/* add marked methods to callgraph */
ADDTOCALLGRAPH(mi)
}
else {
-
+// from Dez if (NATIVE == true) { printf("NOT MARKED: "); method_display(mi);}
+
for (jj=0; jj < ci -> interfacescount; jj++) {
classinfo *ici = ci -> interfaces [jj];
/* use resolve method....!!!! */
{
if (m->xta != NULL)
return m->xta;
-
- if (m->xta != NULL)
- return m->xta;
-
m ->xta = (xtainfo *) NEW(xtainfo);
m ->xta-> XTAmethodUsed = NOTUSED;
m ->xta-> XTAclassSet = NULL;
+ m ->xta-> XTAclassSet = add2ClassSet ( m ->xta-> XTAclassSet, m->class);
+
/* PartClassSet */
m->xta->paramClassSet = NULL;
m->xta->calls = NULL;
m->xta->calledBy = NULL;
- m->xta->marked = NULL;
- /*m ->xta->markedBy = NULL */
+ m->xta->marked = NULL; /* comment out*/
+ m ->xta->markedBy = NULL;
m->xta->fldsUsed = NULL;
/*m ->xta->interfaceCalls = NULL*/
m->xta->chgdSinceLastParse = false;
/* for each SmCalls class */
for (c=c1; c != NULL; c = c->nextClass) {
- vftbl *p_cl_vt = p->classType->vftbl;
- vftbl *c_cl_vt = c->classType->vftbl;
+ vftbl_t *p_cl_vt = p->classType->vftbl;
+ vftbl_t *c_cl_vt = c->classType->vftbl;
/* if SmCalls class is in the Params Class range */
if ( (p_cl_vt->baseval <= c_cl_vt->baseval)
cs1 = SmCalled->xta->XTAclassSet->head;
for (cs =cs1; cs != NULL; cs = cs->nextClass) {
classinfo *c = cs->classType;
- vftbl *r_cl_vt = SmCalled->returnclass->vftbl;
- vftbl *c_cl_vt = c->vftbl;
+ vftbl_t *r_cl_vt = SmCalled->returnclass->vftbl;
+ vftbl_t *c_cl_vt = c->vftbl;
/* if class is a subtype of the return type, then add to SmCalls class set (ie.interscection)*/
if ( (r_cl_vt->baseval <= r_cl_vt->baseval)
if (mi->xta == NULL)
mi->xta = xtainfoInit(mi);
if (mi->xta->XTAmethodUsed != USED) { /* if static method not in callgraph */
- XTAcallgraph[++methXTAlast] = mi;
mi->xta->XTAmethodUsed = USED;
- /** XTAPRINTcallgraph2 */
-
- if(pWhenMarked>=1) {
- printf("\n XTA Added to Call Graph #%i:",
- methXTAlast);
- printf(" method name ="); fflush(stdout);
- if (mi == NULL) panic ("Method ptr NULL!!!");
- if (mi->class == NULL) panic ("Method class ptr NULL!!!");
- if (mi->class->name == NULL) panic ("Method class name ptr NULL!!!");
- utf_display(mi->class->name);fflush(stdout); printf(".");fflush(stdout);
- method_display(mi);fflush(stdout);
- }
+ if (!(mi->flags & ACC_ABSTRACT)) {
+ if (mi->methodUsed != USED) {
+ XTAcallgraph[++methXTAlast] = mi;
+ mi->methodUsed = USED;
+ /*RTprint*/ if (pClassHeir >= 1) {
+ XTAPRINTcallgraph2
+ }
+ }
+ }
- }
+ }
+ /*RTAprint*/ if(pWhenMarked>=1) {
+ /*RTAprint*/ printf("\nxxxxxxxxxxxxxxxxx XTA set Used or Added to Call Graph #%i:",
+ /*RTAprint*/ methXTAlast);
+ /*RTAprint*/ printf(" method name ="); fflush(stdout);
+ /*RTAprint*/ utf_display(mi->class->name);fflush(stdout); printf(".");fflush(stdout);
+ /*RTAprint*/ method_display(mi);fflush(stdout);
+ /*RTAprint*/ printf("\t\t\t\tcalledBy:");
+ /*RTAprint*/ utf_display(rt_method->class->name);fflush(stdout); printf(".");fflush(stdout);
+ /*RTAprint*/ method_display(rt_method);fflush(stdout);
+ /*RTAprint*/ }
/* add call edges */
rt_method->xta->calls = add2MethSet(rt_method->xta->calls, mi);
rt_method->xta->calls->tail->monoPoly = monoPoly;
for (subs=class->sub; subs != NULL; subs = subs->nextsub) {
/* if class used */
if (inSet(subtypesUsedSet,subs)) {
- if (class_findmethod(class, meth->name, meth->descriptor) == NULL)
+ if (class_findmethod_w(class, meth->name, meth->descriptor, "xtaSubUsed") == NULL)
return false;
- else
- return true;
+ else {
+ if (class_findmethod_w(subs, meth->name, meth->descriptor, "xtaSubUsed") == NULL)
+ return true;
+ }
}
if (xtaSubUsed(subs, meth, subtypesUsedSet))
return false;
utf *name = topmethod -> name;
utf *descriptor = topmethod -> descriptor;
- /****
+ /****/
printf("xtaMarkMethod for:"); utf_display(class->name);fflush(stdout);
method_display(topmethod);
- **/
+ /**/
submeth = class_resolvemethod(class, name, descriptor);
- /***
- printf(" def: "); utf_display(submeth->class->name);fflush(stdout);
- method_display(submeth);
- ****/
+ /***/
+ printf(" def: "); utf_display(submeth->class->name); printf("\n");fflush(stdout);
+ /****/
/* Basic checks */
if (submeth == NULL)
- panic("parse XTA: Method not found in class hierarchy");
+ panic("parse XTA: Method not found in class hierarchy");
if (submeth->xta == NULL)
submeth->xta = xtainfoInit(submeth);
if (subtypesUsedSet != NULL) {
if (xtaSubUsed (class,submeth,subtypesUsedSet)) {
xtaAddCallEdges(submeth,POLY);
+ return; //Dez
}
- }
- else {
- rt_method->xta->marked = add2MethSet(rt_method->xta->marked, submeth);
+ submeth->xta->markedBy = add2MethSet(submeth->xta->markedBy,rt_method);
+ /****
+ printf("\t(defd) Added to MarkBy Set\n"); fflush(stdout);
+ utf_display(submeth->class->name); printf("."); fflush(stdout);
+ method_display(submeth);
+ printMethodSet(submeth->xta->markedBy);
+ ****/
+
}
}
}
/*--- Method NOT defined in class -----------------------------*/
if (!(inSet(subtypesUsedSet,submeth->class) )){ /* class with method def is not used */
if (!(inSet(subtypesUsedSet,class) )) { /* class currently resolving is not used */
- rt_method->xta->marked = add2MethSet(rt_method->xta->marked, submeth);
- /*printf("Added to marked Set: "); fflush(stdout);printMethodSet(rt_method->xta->marked);*/
+ submeth->xta->markedBy = add2MethSet(submeth->xta->markedBy,rt_method);
+ submeth->xta->markedBy = add2MethSet(submeth->xta->markedBy,rt_method);
+ /****
+ printf("\t(^^defd) Added to MarkBy Set\n"); fflush(stdout);
+ utf_display(submeth->class->name); printf("."); fflush(stdout);
+ method_display(submeth);
+ printMethodSet(submeth->xta->markedBy);
+ ****/
}
}
if ( (inSet(subtypesUsedSet,submeth->class)) /* class with method def is used */
for (subs = class->sub; subs != NULL; subs = subs->nextsub) {
/* xtaPRINTmarkSubs1 */
xtaMarkSubs(subs, topmethod, subtypesUsedSet);
+ }
}
- }
- }
- return;
+ }
+}
+
+/*-------------------------------------------------------------------------------*/
+/* Add Marked methods for input class ci */
+/* Add methods with the same name and descriptor as implemented interfaces */
+/* with the same method name */
+/* */
+/*-------------------------------------------------------------------------------*/
+void xtaAddMarkedMethods(classinfo *ci) {
+ int ii,jj,mm;
+
+ /* add marked methods to callgraph */
+ for (ii=0; ii<ci->methodscount; ii++) {
+ methodinfo *mi = &(ci->methods[ii]);
+ if (mi->xta != NULL) {
+ if (mi->xta->markedBy != NULL) {
+ methSetNode *mcnode;
+ for (mcnode = mi->xta->markedBy->head; mcnode != NULL; mcnode = mcnode ->nextmethRef) {
+ methodinfo *mc = mcnode->methRef;
+ if (pWhenMarked >= 1) {
+ printf("ADDED a method that was MARKED\n");
+ }
+ xtaAddCallEdges(mi,POLY);
+ }
+ }
+ {
+ for (jj=0; jj < ci -> interfacescount; jj++) {
+ classinfo *ici = ci -> interfaces [jj];
+ /* use resolve method....!!!! */
+ if (ici -> classUsed != NOTUSED) {
+ for (mm=0; mm< ici->methodscount; mm++) {
+ methodinfo *imi = &(ici->methods[mm]);
+ if (imi->xta != NULL) {
+ if ((imi->xta->XTAmethodUsed == USED)
+ && ( (imi->name == mi->name)
+ && (imi->descriptor == mi->descriptor))) {
+ if (pWhenMarked >= 1)
+ printf("ADDED a method that was used by an interface\n");
+ xtaAddCallEdges(mi,POLY);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
/*-------------------------------------------------------------------------------*/
+/* Both RTA and XTA */
/*-------------------------------------------------------------------------------*/
-int addClassInit(classinfo *ci) {
+int addClassInit(classinfo *ci, bool clinits, bool finalizes, bool addmark) {
/* CHANGE to a kind of table look-up for a list of class/methods (currently 3)
*/
int m, m1=-1, m2=-1, mf=-1;
methodinfo *mi;
- for (m=0; m < ci->methodscount; m++) {
- /*<clnit> class init method */
- if (ci->methods[m].name == CLINIT) {
- m1=m;
- }
- /* Special case: System class has an extra initializer method */
- if ((utf_java_lang_system == ci->name)
- && (utf_initializeSystemClass == ci->methods[m].name)) {
- m2=m;
- }
-
- /* Finalize methods */
- if ((ci->methods[m].name == FINALIZE)
- && (ci->name != utf_java_lang_Object)) {
- mf=m;
- }
-
- }
-
- if (m1 >= 0) { /* No <clinit> available - ignore */
+ if (clinits) { /* No <clinit> available - ignore */
/* Get clinit methodinfo ptr */
- mi = class_findmethod (ci,ci->methods[m1].name , NULL);
-
- /*--- RTA ---*/
- if ( mi->methodUsed != USED) {
- mi->class->classUsed = PARTUSED;
- ADDTOCALLGRAPH(mi)
+ if ((mi = class_resolvemethod(ci,CLINIT, EMPTY_DESC)) !=NULL) {
+ if (mi->class != ci) {
+ printf("WARNING:::::<clinit> method not found in class requested: ");
+ utf_display(ci->name); printf(" found in:"); utf_display(mi->class->name);
+ printf("\n");
+ }
+ /*--- RTA ---*/
+ if ( mi->methodUsed != USED) {
+ mi->class->classUsed = PARTUSED;
+ ADDTOCALLGRAPH(mi)
}
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta)) {
- xtaAddCallEdges(mi,MONO);
+ /*--- XTA ---*/
+ if ((XTAOPTbypass) || (opt_xta)) {
+ xtaAddCallEdges(mi,MONO);
+ }
+ }
+ else {
+ printf("class=");utf_display(ci->name);
+ printf(" super=");
+ if (ci->super != NULL)
+ utf_display(ci->super->name);
+ else
+ printf("NULL");
+ if ( (ci->super->name != utf_OBJECT) && (ci->name != utf_OBJECT) )
+ panic("<clinit> method not found");
+ }
}
- }
-
- if (mf >= 0) {
+ if (finalizes) {
/* Get finalize methodinfo ptr */
- mi = class_findmethod (ci,ci->methods[mf].name , NULL);
-
- /*--- RTA ---*/
- if ( mi->methodUsed != USED) {
- mi->class->classUsed = PARTUSED;
- ADDTOCALLGRAPH(mi)
+ if ( (mi = class_findmethod (ci,FINALIZE, EMPTY_DESC)) != NULL) {
+ /*--- RTA ---*/
+ if ( mi->methodUsed != USED) {
+ mi->class->classUsed = PARTUSED;
+ ADDTOCALLGRAPH(mi)
}
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta)) {
- xtaAddCallEdges(mi,MONO);
+ /*--- XTA ---*/
+ if ((XTAOPTbypass) || (opt_xta)) {
+ xtaAddCallEdges(mi,MONO);
+ }
+ }
}
- }
/*Special Case for System class init:
add java/lang/initializeSystemClass to callgraph */
- if (m2 >= 0) {
+ /* XXX TWISTI */
+/* if (class->name == utf_initializeSystemClass) { */
+ if (mi->class->name == utf_initializeSystemClass) {
/* Get clinit methodinfo ptr */
- mi = class_findmethod (ci,ci->methods[m2].name , NULL);
-
- /*--- RTA ---*/
- if ( mi->methodUsed != USED) {
- mi->class->classUsed = PARTUSED;
- ADDTOCALLGRAPH(mi)
+ if ((mi = class_findmethod (ci,utf_initializeSystemClass, EMPTY_DESC)) != NULL) {
+ /*--- RTA ---*/
+ if ( mi->methodUsed != USED) {
+ mi->class->classUsed = PARTUSED;
+ ADDTOCALLGRAPH(mi)
}
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta)) {
- xtaAddCallEdges(mi,MONO);
+ /*--- XTA ---*/
+ if ((XTAOPTbypass) || (opt_xta)) {
+ xtaAddCallEdges(mi,MONO);
+ }
+ }
+ }
+ if (addmark) {
+ /* add marked methods to callgraph */
+ if ((XTAOPTbypass) || (opt_xta))
+ xtaAddMarkedMethods(ci);
+ else
+ rtaAddMarkedMethods(ci);
}
- }
-
- /* add marked methods to callgraph */
- addMarkedMethods(ci);
return m;
}
/*-------------------------------------------------------------------------------*/
-/*xx*/ void addUsedInterfaceMethods(classinfo *ci) {
+void rtaAddUsedInterfaceMethods(classinfo *ci) {
int jj,mm;
/* add used interfaces methods to callgraph */
printf("Interface Method used: "); utf_display(ici->name);printf(".");method_display(imi);fflush(stdout);
/* Mark this method used in the (used) implementing class and its subclasses */
- printf("MAY ADD methods that was used by an interface\n");
+ printf("rMAY ADD methods that was used by an interface\n");
}
rtaMarkSubs(ci,imi);
}
}
}
+/*-------------------------------------------------------------------------------*/
+void rtaMarkInterfaceSubs(methodinfo *mi) {
+ classSetNode *subs;
+ if (mi->class->classUsed == NOTUSED) {
+ mi->class->classUsed = USED;
+ class_java_lang_Object->impldBy = addElement(class_java_lang_Object -> impldBy, mi->class);
+ }
+
+ /* add interface class to list kept in Object */
+ mi->methodUsed = USED;
+ mi->monoPoly = POLY;
+
+ subs = mi->class->impldBy;
+ RTAPRINT08invokeInterface1
+ while (subs != NULL) {
+ classinfo * isubs = subs->classType;
+ RTAPRINT09invokeInterface2
+ /* Mark method (mark/used) in classes that implement the method */
+ if (isubs->classUsed != NOTUSED) {
+ methodinfo *submeth;
+
+ submeth = class_findmethod(isubs,mi->name, mi->descriptor);
+ if (submeth != NULL)
+ submeth->monoPoly = POLY; /* poly even if nosubs */
+ rtaMarkSubs(isubs, mi);
+ }
+
+ subs = subs->nextClass;
+ } /* end while */
+}
+
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------------------------*/
-void xtaMarkInterfaceSubs(methodinfo *mCalled) {
- classSetNode * Si;
+void xtaAddUsedInterfaceMethods(classinfo *ci) {
+ int jj,mm;
+
+/* add used interfaces methods to callgraph */
+for (jj=0; jj < ci -> interfacescount; jj++) {
+ classinfo *ici = ci -> interfaces [jj];
- /* for every class that implements the interface of the method called */
- for (Si = mCalled->class->impldBy; Si != NULL; Si = Si->nextClass) {
- /* add all definitions of this method for this interface */
- methodinfo *submeth;
- classSetNode *subtypesUsedSet = NULL;
-
- submeth = class_findmethod(Si->classType, mCalled->name, mCalled->descriptor);
- if (submeth == NULL) { /* search up the heir - ignore for now!!! */
- submeth = class_resolvemethod(Si->classType, mCalled->name, mCalled->descriptor);
- }
+ if (pWhenMarked >= 1) {
+ printf("XInterface used: ");fflush(stdout);
+ utf_display(ici->name);
+ printf("<%i>\t",ici -> classUsed ); fflush(stdout);
+ if (ici -> classUsed == NOTUSED) printf("\t classUsed=NOTUSED\n" );
+ if (ici -> classUsed == USED) printf("\t classUsed=USED\n");
+ if (ici -> classUsed == PARTUSED) printf("\t classUsed=PARTUSED\n");
+ fflush(stdout);
+ }
+ /* add class to interfaces list of classes that implement it */
+ ici -> impldBy = addElement(ici -> impldBy, ci);
- if (rt_method->xta->XTAclassSet != NULL)
- subtypesUsedSet = intersectSubtypesWithSet(Si->classType, rt_method->xta->XTAclassSet->head);
-
- printf(" \nXTA subtypesUsedSet: "); fflush(stdout);
- printSet(subtypesUsedSet);
- xtaMarkSubs(Si->classType, submeth, subtypesUsedSet);
- }
+ /* if interface class is used */
+ if (ici -> classUsed != NOTUSED) {
+
+ /* for each interface method implementation that has already been used */
+ for (mm=0; mm< ici->methodscount; mm++) {
+ methodinfo *imi = &(ici->methods[mm]); /*interface method */
+printf("==%i==%i\n",ici->methodscount,mm);
+ if (imi->xta == NULL)
+ xtainfoInit (imi);
+ /*RTAprint*/if (pWhenMarked >= 1) {
+ /*RTAprint*/ if (imi->xta->XTAmethodUsed != USED) {
+ /*RTAprint*/ if (imi->xta->XTAmethodUsed==NOTUSED)
+ printf("Interface Method notused: ");
+ /*RTAprint*/ if (imi->xta->XTAmethodUsed==MARKED)
+ printf("Interface Method marked: ");
+ /*RTAprint*/ utf_display(ici->name);printf(".");
+ /*RTAprint*/ method_display(imi);fflush(stdout);
+ /*RTAprint*/ }
+ /*RTAprint*/ }
+ if (imi->xta->XTAmethodUsed == USED) {
+ methSetNode *mCalledBy = NULL;
+ if (pWhenMarked >= 1) {
+ printf("Interface Method used: "); utf_display(ici->name);printf(".");
+ method_display(imi);fflush(stdout);
+
+ /* Mark this method used in the (used) implementing class &its subclasses */
+ printf("xMAY ADD methods that was used by an interface\n"); fflush(stdout);
+ }
+ if (pWhenMarked >= 1) {
+ printf("calledBy set ="); fflush(stdout);
+ printMethodSet(imi->xta->calledBy);
+ }
+ if (imi->xta->calledBy != NULL) {
+ /* for each calledBy method */
+ for ( mCalledBy = imi->xta->calledBy->head;
+ mCalledBy != NULL;
+ mCalledBy = mCalledBy->nextmethRef) {
+ if (pWhenMarked >= 1) {
+ printf("xtaMarkSubs(");
+ utf_display(ci->name); printf("."); fflush(stdout);
+ method_display(imi);
+ printf("mCalledBy method class set BEFORE\n"); fflush(stdout);
+ printSet(mCalledBy->methRef->xta->XTAclassSet->head);
+ }
+ xtaMarkSubs(ci,imi,mCalledBy->methRef->xta->XTAclassSet->head);
+ if (pWhenMarked >= 1) {
+ printf("mCalledBy method class set AFTER \n"); fflush(stdout);
+ printSet(mCalledBy->methRef->xta->XTAclassSet->head);
+ }
+ }
+ }
+ }
+ }
+ }
+ } /* end for */
}
+/*-------------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------------*/
+void xtaMarkInterfaceSubs(methodinfo *mi) {
+ classSetNode *subs;
+ classSetNode * Si;
+
+ if (mi->xta == NULL)
+ xtainfoInit (mi);
+
+ if (mi->class->classUsed != USED) {
+ mi->class->classUsed = USED;
+ class_java_lang_Object->impldBy = addElement(class_java_lang_Object -> impldBy, mi->class);
+ }
+
+ /* add interface class to list kept in Object */
+ if (pWhenMarked >= 1) {
+ printf("Marking Interface Method: "); fflush(stdout);
+ }
+ xtaAddCallEdges(mi,POLY);
+
+ subs = mi->class->impldBy;
+ RTAPRINT08invokeInterface1
+ while (subs != NULL) {
+ classinfo * isubs = subs->classType;
+ RTAPRINT09invokeInterface2
+ /* Mark method (mark/used) in classes that implement the method */
+ if (isubs->classUsed != NOTUSED) {
+ methodinfo *submeth;
+
+ submeth = class_resolvemethod(isubs,mi->name, mi->descriptor);
+ if (submeth != NULL) ///+1
+ {
+ classSetNode *subtypesUsedSet = NULL;
+ submeth->monoPoly = POLY; /* poly even if nosubs */
+
+ mi->xta->XTAmethodUsed = USED;
+ if (rt_method->xta->XTAclassSet != NULL)
+ subtypesUsedSet =
+ intersectSubtypesWithSet
+ (subs->classType, rt_method->xta->XTAclassSet->head);
+
+ if (pWhenMarked >= 1) {
+ /*RTAprint*/ printf(" \nXTA subtypesUsedSet: ");
+ /*RTAprint*/ fflush(stdout);
+ /*RTAprint*/ printSet(subtypesUsedSet);
+ }
+ xtaMarkSubs(subs->classType, mi, subtypesUsedSet);
+ }
+ }
+ subs = subs->nextClass;
+ }
+}
+/*-------------------------------------------------------------------------------*/
+
/*-------------------------------------------------------------------------------*/
bool xtaAddFldClassTypeInfo(fieldinfo *fi) {
strcpy(desc,++utf_ptr);
cname = strtok(desc,";");
if (XTAdebug >= 1) {
- printf("STATIC field's type is: %s\n",cname);
+ printf("STATIC fields type is: %s\n",cname);
fflush(stdout);
}
class = class_get(utf_new_char(cname));
/* Sx = intersection of type+subtypes(field x) */
/* and Sm (where putstatic code is) */
for (c=c1; c != NULL; c=c->nextClass) {
- vftbl *f_cl_vt = fi->xta->fldClassType->vftbl;
- vftbl *c_cl_vt = c-> classType->vftbl;
+ vftbl_t *f_cl_vt = fi->xta->fldClassType->vftbl;
+ vftbl_t *c_cl_vt = c-> classType->vftbl;
if (XTAfld >=2 ) {
printf("\tXTA class = ");fflush(stdout);
utf_display(c->classType->name);
}
}
+/*-------------------------------------------------------------------------------*/
+/* -- Processes STATIC & PRIVATE methods
+
+ * -- called for INVOKESTATIC, INVOKESPECIAL - PRIVATE and
+ * STATIC / PRIVATE methods used by NATIVE methods
+ *-------------------------------------------------------------------------------*/
+
+// Dez Version but gives too many Missed
+void invokestatic2( methodinfo *mi) {
+
+mi->class->classUsed = PARTUSED;
+/*-- RTA --*/
+addClassInit(mi->class, true, true, true);
+ RTAPRINT04invokestatic1
+
+if (opt_rt) {
+ ADDTOCALLGRAPH(mi)
+ } /* end RTA */
+
+/*-- XTA --*/
+if ((XTAOPTbypass) || (opt_xta)) {
+ mi->class->classUsed = PARTUSED;
+ rt_method->xta->XTAclassSet = add2ClassSet(rt_method->xta->XTAclassSet,mi->class);
+ xtaAddCallEdges(mi,MONO);
+ } /* end XTA */
+}
+
+
+
+//// from just RTA version before Dez changes
+void invokestatic(methodinfo *mi){
+ RTAPRINT04invokestatic1
+if (mi->class->classUsed == NOTUSED) {
+ mi->class->classUsed = USED;
+ RTAPRINT05invokestatic2
+ }
+ addClassInit(mi->class,true, true, true);
+
+ if (opt_rt) {
+ ADDTOCALLGRAPH(mi)
+ } /* end RTA */
+ /*-- XTA --*/
+ if ((XTAOPTbypass) || (opt_xta)) {
+ xtaAddCallEdges(mi,MONO);
+ } /* end XTA */
+}
+
+
+/*-------------------------------------------------------------------------------*/
+/* -- Processes <INIT> methods
+
+ * -- called for INVOKESPECIAL - <init> and
+ * <init> methods used by NATIVE methods
+ *-------------------------------------------------------------------------------*/
+
+void initMethods(methodinfo *mi) {
+
+classinfo *ci = mi->class;
+
+/* new class so add marked methods */
+if (opt_rt) {
+ if (( mi->methodUsed != USED) || (mi->class->classUsed == PARTUSED)) {
+ /*--- process NORMAL <init> method ---------------------------------------------*/
+ if ( mi->methodUsed != USED) {
+ /* Normal <init>
+ - mark class as USED and <init> to callgraph */
+
+ /*-- RTA --*/
+// addClassInit(mi->class,true, true, false);
+ ci->classUsed = USED;
+ rtaAddMarkedMethods(ci); /* add to callgraph marked methods */
+ RTAPRINT06Binvoke_spec_init
+ rtaAddUsedInterfaceMethods(ci);
+ ADDTOCALLGRAPH(mi)
+ }
+ }
+ }
+
+/*-- XTA --*/
+if ((XTAOPTbypass) || (opt_xta)) {
+ if (mi->xta == NULL) {
+ mi->xta = xtainfoInit(mi);
+ }
+ if ((mi->xta->XTAmethodUsed != USED) || (mi->class->classUsed == PARTUSED)) {
+ ci->classUsed = USED;
+ rt_method->xta->XTAclassSet = add2ClassSet(rt_method->xta->XTAclassSet,ci );
+ xtaAddMarkedMethods(ci); /* add to callgraph marked methods */
+ xtaAddUsedInterfaceMethods(ci);
+ xtaAddCallEdges(mi,MONO);
+ RTAPRINT06CXTAinvoke_spec_init1
+ } /* end XTA */
+ }
+}
+
+/*-------------------------------------------------------------------------------*/
+/* -- Processes VIRTUAL methods
+
+ * -- called for INVOKEVIRTUAL and
+ * virtual methods used by NATIVE methods
+ *-------------------------------------------------------------------------------*/
+
+void invokevirtual(methodinfo *mi) {
+
+/*--- RTA ---*/
+ RTAPRINT07invoke_spec_virt2
+mi->class->classUsed = USED; // Should this be later?
+
+if ((mi->flags & ACC_STATIC) || (mi->flags & ACC_PRIVATE) || (mi->flags & ACC_FINAL) ) {
+ invokestatic(mi);
+ return;
+ }
+
+
+mi->monoPoly = POLY;
+
+if (opt_rt) {
+ rtaMarkSubs(mi->class,mi);
+ }
+
+/*--- XTA ---*/
+if ((XTAOPTbypass) || (opt_xta)) {
+ classSetNode *subtypesUsedSet = NULL;
+ if (rt_method->xta->XTAclassSet != NULL)
+ subtypesUsedSet =
+ intersectSubtypesWithSet(mi->class, rt_method->xta->XTAclassSet->head);
+ else
+ subtypesUsedSet = addElement(subtypesUsedSet, rt_method->class);
+ /*****/
+ printf(" \nXTA subtypesUsedSet: "); fflush(stdout);
+ printSet(subtypesUsedSet);
+ /*****/
+ xtaMarkSubs(mi->class, mi, subtypesUsedSet);
+ } /* end XTA */
+}
+
/*-------------------------------------------------------------------------------*/
-static void parseRT()
+void invokeinterface( methodinfo *mi ) {
+ /*RTAprint*/ if (pWhenMarked >= 1) {
+ /*RTAprint*/ printf("\t");fflush(stdout);
+ /*RTAprint*/ utf_display(mi->class->name); printf(".");fflush(stdout);
+ /*RTAprint*/ method_display(mi); fflush(stdout);
+ /*RTAprint*/ }
+
+if (mi->flags & ACC_STATIC)
+ panic ("Static/Nonstatic mismatch calling static method");
+ RTAPRINT08AinvokeInterface0
+/*--- RTA ---*/
+if (opt_rt) {
+ rtaMarkInterfaceSubs(mi);
+ }
+/*--- XTA ---*/
+if ((XTAOPTbypass2) || (opt_xta)) {
+ xtaMarkInterfaceSubs(mi);
+ }
+}
+
+/*-------------------------------------------------------------------------------*/
+void newClasses(classinfo *ci) {
+ if (pWhenMarked >= 1) {
+ printf("\tclass=");fflush(stdout);
+ utf_display(ci->name); fflush(stdout);
+ printf("=\n");fflush(stdout);
+ }
+/*--- RTA ---*/
+if (ci->classUsed != USED) {
+ RTAPRINT10new
+ ci->classUsed = USED; /* add to heirarchy */
+ /* Add this class to the implemented by list of the abstract interface */
+ rtaAddUsedInterfaceMethods(ci);
+ addClassInit(ci, true, true, false);
+ }
+/*--- XTA ---*/
+if ((XTAOPTbypass) || (opt_xta))
+ {
+ xtaAddUsedInterfaceMethods(ci);
+ rt_method->xta->XTAclassSet = add2ClassSet(rt_method->xta->XTAclassSet,ci ); /*XTA*/
+ RTAPRINT10newXTA
+ }
+}
+
+/*-------------------------------------------------------------------------------*/
+static void parseRT(methodinfo *m)
{
int p; /* java instruction counter */
int nextp; /* start of next java instruction */
fi = class_findfield (fr->class,fr->name, fr->descriptor);
RTAPRINT03putstatic1
- /*--- RTA ---*/
+ /*--- RTA ---*/
/* class with field - marked in addClassinit */
- addClassInit(fr->class);
+ addClassInit(fr->class, true, true, false);
/*--- XTA ---*/
if ((XTAOPTbypass) || (opt_xta))
fi = class_findfield (fr->class,fr->name, fr->descriptor);
RTAPRINT03putstatic1
- /*--- RTA ---*/
- /* class with field - marked in addClassinit */
- addClassInit(fr->class);
+ /*--- RTA ---*/
+ /* class with field - marked in addClassinit */
+ addClassInit(fr->class,true, true, true);
/*--- XTA ---*/
if ((XTAOPTbypass) || (opt_xta) )
methodinfo *mi;
mr = class_getconstant (rt_class, i, CONSTANT_Methodref);
- mi = class_findmethod (mr->class, mr->name, mr->descriptor);
+ mi = class_resolveclassmethod (mr->class, mr->name, mr->descriptor, m->class, true);
+ if (!mi)
+ panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */
/*-- RTA --*/
- RTAPRINT04invokestatic1
- if (mi->class->classUsed == NOTUSED) {
- mi->class->classUsed = USED;
- RTAPRINT05invokestatic2
- }
- addClassInit(mi->class);
-
- ADDTOCALLGRAPH(mi)
- fflush(stdout);
- /*-- XTA --*/
- if ((XTAOPTbypass) || (opt_xta)) {
- xtaAddCallEdges(mi,MONO);
- } /* end XTA */
+ invokestatic(mi);
}
break;
case JAVA_INVOKESPECIAL:
i = rt_code_get_u2(p + 1);
{
- constant_FMIref *mr;
- methodinfo *mi;
- classinfo *ci;
+ constant_FMIref *mr;
+ methodinfo *mi;
- mr = class_getconstant (rt_class, i, CONSTANT_Methodref);
- mi = class_findmethod (mr->class, mr->name, mr->descriptor);
- ci = mi->class;
- RTAPRINT06invoke_spec_virt1
- /*--- PRIVATE Method -----------------------------------------------------*/
- if (mi->name != INIT) { /* if method called is PRIVATE */
- RTAPRINT07invoke_spec_virt2
+ mr = class_getconstant (rt_class, i, CONSTANT_Methodref);
+ mi = class_resolveclassmethod (mr->class, mr->name, mr->descriptor, m->class, true);
+ if (!mi)
+ panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */
+ RTAPRINT06invoke_spec_virt1
+ /*--- PRIVATE Method -----------------------------------------------------*/
+ if (mi->name != INIT) { /* if method called is PRIVATE */
+ RTAPRINT07invoke_spec_virt2
RTAPRINT04invokestatic1
- /*-- RTA --*/ /* was just markSubs(mi); */
- ADDTOCALLGRAPH(mi)
-
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta)) {
- xtaAddCallEdges(mi,MONO);
- } /* end XTA */
- }
-
- else {
- /*--- Test for super <init> which is: <init> calling its super class <init> -*/
-
- /* new class so add marked methods */
- if (( mi->methodUsed != USED) || (mi->class->classUsed == PARTUSED)) {
- /*--- process NORMAL <init> method ---------------------------------------------*/
- if ( mi->methodUsed != USED) {
- /* Normal <init>
- - mark class as USED and <init> to callgraph */
-
- /*-- RTA --*/
- ci->classUsed = USED;
- addMarkedMethods(ci); /* add to callgraph marked methods */
- RTAPRINT06Binvoke_spec_init
- addUsedInterfaceMethods(ci);
- ADDTOCALLGRAPH(mi)
-
- /*-- XTA --*/
- if ((XTAOPTbypass) || (opt_xta)) {
- rt_method->xta->XTAclassSet = add2ClassSet(rt_method->xta->XTAclassSet,ci );
- xtaAddCallEdges(mi,MONO);
- RTAPRINT06CXTAinvoke_spec_init1
- } /* end XTA */
- }
- }
- }
+ invokestatic(mi);
+ }
+ else {
+ /*--- Test for super <init> which is: <init> calling its super class <init> -*/
+ initMethods(mi);
+ }
}
break;
case JAVA_INVOKEVIRTUAL:
i = rt_code_get_u2(p + 1);
{
- constant_FMIref *mr;
- methodinfo *mi;
+ constant_FMIref *mr;
+ methodinfo *mi;
- mr = class_getconstant (rt_class, i, CONSTANT_Methodref);
- mi = class_findmethod (mr->class, mr->name, mr->descriptor);
-
- /*--- RTA ---*/
- RTAPRINT07invoke_spec_virt2
- mi->monoPoly = POLY;
- rtaMarkSubs(mi->class,mi);
+ mr = class_getconstant (rt_class, i, CONSTANT_Methodref);
+ mi = class_resolveclassmethod (mr->class, mr->name, mr->descriptor, m->class, true);
+ if (!mi)
+ panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta)) {
- classSetNode *subtypesUsedSet = NULL;
- if (rt_method->xta->XTAclassSet != NULL)
- subtypesUsedSet = intersectSubtypesWithSet(mi->class, rt_method->xta->XTAclassSet->head);
- /*****
- printf(" \nXTA subtypesUsedSet: "); fflush(stdout);
- printSet(subtypesUsedSet);
- *****/
- xtaMarkSubs(mi->class, mi, subtypesUsedSet);
- } /* end XTA */
+ invokevirtual(mi);
}
break;
case JAVA_INVOKEINTERFACE:
i = rt_code_get_u2(p + 1);
{
- constant_FMIref *mr;
- methodinfo *mi;
- classSetNode *subs;
- classSetNode *subtypesUsedSet = NULL;
-
- mr = class_getconstant (rt_class, i, CONSTANT_InterfaceMethodref);
- mi = class_findmethod (mr->class, mr->name, mr->descriptor);
-
- if (mi->flags & ACC_STATIC)
- panic ("Static/Nonstatic mismatch calling static method");
-
- /*--- RTA ---*/
- RTAPRINT08AinvokeInterface0
- if (mi->class->classUsed == NOTUSED) {
- mi->class->classUsed = USED; /*??PARTUSED;*/
- class_java_lang_Object->impldBy = addElement(class_java_lang_Object -> impldBy, mi->class);
- }
-
- /* add interface class to list kept in Object */
- mi->methodUsed = USED;
- mi->monoPoly = POLY;
-
- subs = mi->class->impldBy;
- RTAPRINT08invokeInterface1
- while (subs != NULL) {
- classinfo * isubs = subs->classType;
- RTAPRINT09invokeInterface2
- /* Mark method (mark/used) in classes that implement the method */
- if (isubs->classUsed != NOTUSED) {
- methodinfo *submeth;
-
- submeth = class_findmethod(isubs,mi->name, mi->descriptor);
- if (submeth != NULL)
- submeth->monoPoly = POLY; /* poly even if nosubs */
- rtaMarkSubs(isubs, mi);
- }
- /* XTA */
- if ((XTAOPTbypass) || (opt_xta))
- {
- if (rt_method->xta->XTAclassSet != NULL)
- subtypesUsedSet =
- intersectSubtypesWithSet
- (subs->classType, rt_method->xta->XTAclassSet->head);
-
- printf(" \nXTA subtypesUsedSet: ");
- fflush(stdout);
- printSet(subtypesUsedSet);
- xtaMarkSubs(subs->classType, mi, subtypesUsedSet);
- }
-
- subs = subs->nextClass;
- }
-
- /*--- XTA ---*/
- if ((XTAOPTbypass2) || (opt_xta))
- {
- xtaMarkInterfaceSubs(mi);
- }
+ constant_FMIref *mr;
+ methodinfo *mi;
+
+ mr = class_getconstant (rt_class, i, CONSTANT_InterfaceMethodref);
+ mi = class_resolveinterfacemethod (mr->class, mr->name, mr->descriptor, m->class, true);
+ if (!mi)
+ panic("Exception thrown while parsing bytecode"); /* XXX should be passed on */
+ invokeinterface(mi);
}
break;
classinfo *ci;
ci = class_getconstant (rt_class, i, CONSTANT_Class);
- if (pWhenMarked >= 1) {
- printf("\tclass=");fflush(stdout);
- utf_display(ci->name); fflush(stdout);
- printf("=\n");fflush(stdout);
- }
- /*--- RTA ---*/
- if (ci->classUsed != USED) {
- RTAPRINT10new
- ci->classUsed = USED; /* add to heirarchy */
- /* Add this class to the implemented by list of the abstract interface */
- addUsedInterfaceMethods(ci);
- addClassInit(ci);
- }
- /*--- XTA ---*/
- if ((XTAOPTbypass) || (opt_xta))
- {
- rt_method->xta->XTAclassSet = add2ClassSet(rt_method->xta->XTAclassSet,ci ); /*XTA*/
- RTAPRINT10newXTA
- }
+ newClasses(ci);
}
break;
class = class_get(c1);
if (class == NULL) {
- return; /*Note: Since NativeCalls is for mult programs some may not be loaded - that's ok */
+ utf_display(c1);
+ printf(" WARNING: CLASS used by NATIVE method is NULL so loaded\n");
+/* loader_load_sysclass(NULL, c1); */
+/* class = class_get(c1); */
+ class = class_new(c1);
+ if (class == NULL) {
+ panic("CLASS used by NATIVE method is NULL and loading didn't help\n");
+ return; /*Note: Since NativeCalls is for mult programs some may not be loaded - that's ok */
+ }
}
if (class->classUsed == NOTUSED) {
+printf("NATIVE_MARKED CLASS USED "); utf_display(class->name); printf("\n");
class->classUsed = USED; /* MARK CLASS USED */
/* add marked methods to callgraph */
- addMarkedMethods(class);
+ rtaAddMarkedMethods(class);
}
- meth = class_findmethod (class, m1, d1);
+ meth = class_findmethod_w (class, m1, d1,"findMarkNativeUsedMeth");
if (meth == NULL) {
utf_display(class->name);printf(".");utf_display(m1);printf(" ");utf_display(d1);
- printf("WARNING from parseRT: Method given is used by Native method call, but NOT FOUND\n");
+ panic("WARNING from parseRT: Method given is used by Native method call, but NOT FOUND\n");
}
else
rtaMarkSubs(class,meth);
class->classUsed = USED;
/* add marked methods to callgraph */
- addMarkedMethods(class);
+ rtaAddMarkedMethods(class);
}
&& (rt_descriptor == nativeCompCalls[i].methods[j].descriptor)) {
found=true;
-
+printf("#%i#\n",nativeCompCalls[i].callCnt[j]);
/* mark methods and classes used by this native class.method */
for (k=0; k < nativeCompCalls[i].callCnt[j]; k++) {
if (nativeCompCalls[i].methods[j].methodCalls[k].methodname != NULL) {
}
+
+/*-------------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------------*/
+/* still need to look at field sets in 2nd pass and clinit ..... */
+void XTA_jit_parse2(methodinfo *m)
+{
+int methRT; /* local */
+ if (XTAdebug >= 1)
+ printf("\n\nStarting Round 2 XTA !!!!!!!!!!!!!!\n");
+
+ /* for each method in XTA worklist = callgraph (use RTA for now) */
+ methRT=0;
+ //while (methRT <= methRTlast) {
+ while (methRT <= methXTAlast) {
+ rt_method = XTAcallgraph[methRT];
+ rt_class = rt_method->class;
+ rt_descriptor = rt_method->descriptor;
+ rt_jcodelength = rt_method->jcodelength;
+ rt_jcode = rt_method->jcode;
+
+ if (! ( (rt_method->flags & ACC_NATIVE )
+ || (rt_method->flags & ACC_ABSTRACT) ) ) {
+ if (XTAdebug >= 1) {
+ printf("\n!!!!! XTA Round 2 Parse of #%i:",methRT);fflush(stdout);
+ utf_display(rt_class->name); printf("."); fflush(stdout);
+ method_display(rt_method);
+ }
+ /* if XTA type set changed since last parse */
+ if (rt_method->xta->chgdSinceLastParse) {
+
+ /* get types from methods it is calledBy */
+ xtaPassAllCalledByParams ();
+
+ /* Pass parameter types to methods it calls and send the return type those called by */
+ xtaMethodCalls_and_sendReturnType();
+ }
+ }
+ methRT++;
+ }
+ if (XTAdebug >= 1) {
+
+ printf("\n\nEND_OF Round 2 XTA !!!!!!!!!!!!!!\n");
+ printXTACallgraph ();
+ }
+
+ RTAPRINT14CallgraphLast /*was >=2 */
+ RTAPRINT15HeirarchyiLast /*was >= 2 */
+ }
+
+
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
void mainRTAparseInit (methodinfo *m )
if (firstCall) {
firstCall=false;
+ /* Frequently used utf strings */
+ utf_OBJECT = utf_new_char("java/lang/Object");
utf_MAIN = utf_new_char("main");
INIT = utf_new_char("<init>");
CLINIT = utf_new_char("<clinit>");
FINALIZE = utf_new_char("finalize");
EMPTY_DESC= utf_new_char("()V");
+ /* open file for list of methods parsed before main method or missed and parsed after main */
if ( (rtMissed = fopen("rtMissed", "w")) == NULL) {
- printf("CACAO - rtMissed file: can't open file to write\n");
+ printf("CACAO - rtMissed file: cant open file to write\n");
}
else {
fprintf(rtMissed,"To Help User create a dymLoad file \n");
fprintf(rtMissed,
- "Not parsed in the static analysis parse of Main: #rt parse / #missed class.method (descriptor) \n");
+ "Not parsed in the static analysis parse of Main: #rt parse / #missed class.method (descriptor) \n");
fprintf(rtMissed,"\n\tBEFORE MAIN RT PARSE\n");
fflush(rtMissed);
fclose(rtMissed);
}
- callgraph = MNEW (methodinfo*, MAXCALLGRAPH); /****/
+ /* Allocate callgraph */
+ if (opt_rt) {
+ callgraph = MNEW (methodinfo*, MAXCALLGRAPH); /****/
+ }
if ((XTAOPTbypass) || (opt_xta)) {
printf("XTAXTA CALLGRAPHS allocated\n");
XTAcallgraph = MNEW (methodinfo*, MAXCALLGRAPH);
+ }
}
- }
if (m->name == utf_MAIN) {
rtMissed = fopen("rtMissed","a");
}
else {
if ( (rtMissed = fopen("rtMissed", "a")) == NULL) {
- printf("CACAO - rtMissed file: can't open file to write\n");
+ printf("CACAO - rtMissed file: cant open file to write\n");
}
else {
fprintf(rtMissed,"#%i/#%i ",methRTlast+1,missedCnt++ );
}
if (AfterMain) {
printf("#%i : ",methRT);
- printf("Method missed by static analysis Main parse. See rtMissed file");
+ printf("Method missed by static analysis Main parse. See ./rtMissed file\n");
/*** panic ("Method missed by static analysis Main parse. See rtMissed file");**/
}
}
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
-/* still need to look at field sets in 2nd pass and clinit ..... */
-void XTA_jit_parse2(methodinfo *m)
-{
- if (XTAdebug >= 1)
- printf("\n\nStarting Round 2 XTA !!!!!!!!!!!!!!\n");
- /* for each method in XTA worklist = callgraph (use RTA for now) */
- methRT=0;
+void RTparseCGWorklist (methodinfo *m) {
+printf("IIIIIIIIIIIIIIIIIIIIn RTparseCGWorklist\n"); fflush(stdout);
+ if (m->methodUsed == USED) return;
+ if ((firstCall) || (parse1) || (m->name == utf_MAIN))
+ mainRTAparseInit (m);
+ parse1= false;
+ m->methodUsed = USED;
+
+ /* initialise parameter type descriptor */
+ callgraph[++methRTlast] = m; /*-- RTA --*/
+ RTAPRINT11addedtoCallgraph
+ /* <init> then like a new class so add marked methods to callgraph */
+ if (m->name == INIT) { /* need for <init>s parsed efore Main */
+ classinfo *ci;
+ ci = m->class;
+ ci->classUsed = USED;
+ if (pWhenMarked >= 1) {
+ printf("Class=");utf_display(ci->name);
+ }
+ /* add marked methods to callgraph */
+ RTAPRINT11addedtoCallgraph2
+ rtaAddMarkedMethods(ci);
+ } /* if */
+
+ /*---- RTA call graph worklist -----***/
while (methRT <= methRTlast) {
rt_method = callgraph[methRT];
- rt_class = rt_method->class;
- rt_descriptor = rt_method->descriptor;
- rt_jcodelength = rt_method->jcodelength;
- rt_jcode = rt_method->jcode;
+ rt_class = rt_method->class;
+ rt_descriptor = rt_method->descriptor;
+ rt_jcodelength = rt_method->jcodelength;
+ rt_jcode = rt_method->jcode;
if (! ( (rt_method->flags & ACC_NATIVE )
|| (rt_method->flags & ACC_ABSTRACT) ) ) {
- if (XTAdebug >= 1) {
- printf("\n!!!!! XTA Round 2 Parse of #%i:",methRT);fflush(stdout);
- utf_display(rt_class->name); printf("."); fflush(stdout);
- method_display(rt_method);
+ parseRT(m);
}
- /* if XTA type set changed since last parse */
- if (rt_method->xta->chgdSinceLastParse) {
+ //if (true == false) { // At moment nativecalls.h is not current and neither helps nor hinders
+ else {
+ RTAPRINT12bAbstractNative
+ if (rt_method->flags & ACC_NATIVE ) {
+ RTAPRINT12aNative
+ /* mark used and add to callgraph methods and classes used by NATIVE method */
+ markNativeMethodsRT(rt_class->name,rt_method->name,rt_descriptor);
+ }
+ if (rt_method->flags & ACC_ABSTRACT) {
+ panic("ABSTRACT_SHOULD not ever get into the callgraph!!!!!****!!!****!!!!****!!!!\n");
+ }
+ }
+ methRT++;
+ RTAPRINT12Callgraph
+ RTAPRINT13Heirarchy
+ } /* while */
- /* get types from methods it is calledBy */
- xtaPassAllCalledByParams ();
+ if (m->class->classUsed == NOTUSED)
+ m->class->classUsed = USED; /* say Main's class has a method used ??*/
+}
- /* Pass parameter types to methods it calls and send the return type those called by */
- xtaMethodCalls_and_sendReturnType();
- }
+
+/*-------------------------------------------------------------------------------*/
+/*--------------------------------------------------------*/
+int getdymline(char *line, int max, FILE *inFP) {
+if (fgets(line, max, inFP) == NULL)
+ return 0;
+else {
+ return strlen((const char *)line);
+ }
+}
+
+/*-------------------------------------------------------------------------------*/
+
+methodinfo *getApplicationDynamics ( ) {
+char line[512]="";
+char *classname;
+char *methname ;
+char *desc;
+int rc;
+
+classinfo *class;
+methodinfo *mi;
+
+if ( (appldynm = fopen("appldynm", "r")) == NULL) {
+ printf("parseRT - appldynm file: no appldynm file - ok if nothing in rtMissed after Main\n");
+ return NULL;
+}
+
+if ( getdymline(line,512,appldynm) != 0)
+ {
+ printf("line=%s\n",line); fflush(stdout);
+
+ classname = strtok(line," \n");
+ methname = strtok(NULL," \n");
+ if (methname == NULL) { /* if no meth */
+ panic("parseRT - dynamic loaded class/method/desc in appldynm has no method");
}
- methRT++;
- }
- if (XTAdebug >= 1) {
+ desc = strtok(NULL," \n");
+ if (desc == NULL) { /* if no desc */
+ panic("parseRT - dynamic loaded class/method/desc in appldynm has no descriptor");
+ }
+ printf("appldynm class=%s meth=%s desc=%s\n",classname, methname,desc); fflush(stdout);
- printf("\n\nEND_OF Round 2 XTA !!!!!!!!!!!!!!\n");
- printXTACallgraph ();
- }
-
- RTAPRINT14CallgraphLast /*was >=2 */
- RTAPRINT15HeirarchyiLast /*was >= 2 */
+ class = class_get(utf_new_char(classname));
+ if (class == NULL) {
+/* class = loader_load_sysclass(NULL, utf_new_char(classname)); */
+ class = class_new(utf_new_char(classname));
}
+ mi = class_fetchmethod(class,utf_new_char(methname), utf_new_char(desc)) ;
+ printf("+++++--3--+++++\t");
+ RTparseCGWorklist (mi) ;
+
+ }
+fclose(appldynm);
+return NULL;
+}
/*-------------------------------------------------------------------------------*/
void RT_jit_parse(methodinfo *m)
{
- /*-- RTA --*/
+classinfo *class;
+methodinfo * mi;
+classinfo *topclass;
+
+/*-- RTA -- *******************************************************/
+ if (opt_rt)
+ {
+ /*---- java/lang/Object.<clinit> ----*/
+ if ((firstCall == false) || (true == false))
+ {
+ parse1 = true;
if (m->methodUsed == USED) return;
- mainRTAparseInit (m);
-
- /* initialise parameter type descriptor */
- callgraph[++methRTlast] = m; /*-- RTA --*/
- m->methodUsed = USED;
- RTAPRINT11addedtoCallgraph
- /* <init> then like a new class so add marked methods to callgraph */
- if (m->name == INIT) { /* need for <init>s parsed efore Main */
- classinfo *ci;
- ci = m->class;
- ci->classUsed = USED;
- if (pWhenMarked >= 1) {
- printf("Class=");utf_display(ci->name);
- }
- /* add marked methods to callgraph */
- RTAPRINT11addedtoCallgraph2
- addMarkedMethods(ci);
- } /* if */
+ printf("MMMMMMMMMMMMMMMMMMMMMMMMMMMMissed\n"); fflush(stdout);
+ RTparseCGWorklist (m) ;
+ /*RTAprint*/ if (pCallgraph >= 1) {
+ /*RTAprint*/ printCallgraph ();}
+ /*RTprint*/ //if (pClassHeir >= 1) {
+ /*RTprint*/ // printRThierarchyInfo(m);
+ /*RTprint*/ // }
+ /*RTprint*/ /**printObjectClassHeirarchyAll( );**/
+ fflush(stdout);
+ printf("END MMMMMMMMMMMMMMMMMMMMMMMMMMMMissed\n"); fflush(stdout);
+ return;
+ }
+ else
+ {
+ parse1 = true;
+ printf("SSSSSSSSSSSSSSSSSSSSSStatic Analysis \n"); fflush(stdout);
+ printf("+++++--1--+++++\t");
+ RTparseCGWorklist (m) ;
+
+ class = class_get(utf_new_char("java/lang/Thread"));
+ mi = class_fetchmethod(class,clinit_name(),clinit_desc()) ;
+ printf("+++++--2--+++++\t");
+ RTparseCGWorklist (mi) ;
+
+ class = class_get(utf_new_char("java/lang/ThreadGroup"));
+ mi = class_fetchmethod(class,clinit_name(),clinit_desc()) ;
+ printf("+++++--3--+++++\t");
+ RTparseCGWorklist (mi) ;
+
+
+ class = class_get(utf_new_char("java/lang/Throwable"));
+ mi = class_fetchmethod(class,clinit_name(),clinit_desc()) ;
+ printf("+++++--4--+++++\t");
+ RTparseCGWorklist (mi) ;
+
+ printf("mainstring=%s=\n",mainstring);fflush(stdout);
+/* class = loader_load_sysclass(NULL, utf_new_char(mainString)); */
+ class = class_new(utf_new_char(mainstring));
+ mi = class_fetchmethod( class,
+ utf_new_char("main"),
+ utf_new_char("([Ljava/lang/String;)V")
+ );
+ printf("+++++--5--+++++\t");
+ RTparseCGWorklist (mi) ;
+
+ printf("+++++--6--+++++\t");
+ getApplicationDynamics();
+
+printf("-+-+-+-+-+-+-+-+-+-+-33"); fflush(stdout);
+
+ /*RTAprint*/ if (pCallgraph >= 1) {
+ /*RTAprint*/ printCallgraph ();}
+ /*RTprint*/ //if (pClassHeir >= 1) {
+ /*RTprint*/ // printRThierarchyInfo(m);
+ /*RTprint*/ // }
+ /*RTprint*/ /**printObjectClassHeirarchyAll( );**/
+ fflush(stdout);
+printf("-+-+-+-+-+-+-+-+-+-+-44"); fflush(stdout);
+ /** MFREE(callgraph,methodinfo*,MAXCALLGRAPH); causes stack overflow **/
+ }
+ } /* end opt_rt */
- /*-- XTA --*/
+/*-- XTA -- *******************************************************/
if ((XTAOPTbypass) || (opt_xta)) {
+ if (m->xta != NULL) {
+ if (m->xta->XTAmethodUsed == USED) return;
+ }
+ mainRTAparseInit (m);
+
XTAcallgraph[++methXTAlast] = m;
if (m->xta == NULL) {
m->xta = xtainfoInit(m);
- }
- m->xta->XTAmethodUsed = USED;
- {methodinfo *mi = m;
- XTAPRINTcallgraph2
}
- }
-
- /*-- Call graph work list loop -----------------*/
-
- while (methRT <= methRTlast) {
- rt_method = callgraph[methRT];
- rt_class = rt_method->class;
- rt_descriptor = rt_method->descriptor;
- rt_jcodelength = rt_method->jcodelength;
- rt_jcode = rt_method->jcode;
-
- if (! ( (rt_method->flags & ACC_NATIVE )
- || (rt_method->flags & ACC_ABSTRACT) ) ) {
- parseRT();
- }
- else {
- RTAPRINT12bAbstractNative
- if (rt_method->flags & ACC_NATIVE ) {
- RTAPRINT12aNative
- /* mark used and add to callgraph methods and classes used by NATIVE method */
- markNativeMethodsRT(rt_class->name,rt_method->name,rt_descriptor);
- }
- if (rt_method->flags & ACC_ABSTRACT) {
- panic("ABSTRACT_SHOULD not ever get into the callgraph!!!!!****!!!****!!!!****!!!!\n");
+ m->xta->XTAmethodUsed = USED;
+ {methodinfo *mi = m;
+ printf("<");fflush(stdout);
+ XTAPRINTcallgraph2
}
}
- methRT++;
- RTAPRINT12Callgraph
- RTAPRINT13Heirarchy
- } /* while */
-
+ /*-- Call graph work list loop -----------------*/
+ /*---- XTA call graph worklist -----***/
+ useXTAcallgraph = true;
+ if ((useXTAcallgraph) && (opt_xta)) {
+ printf("USING XTA call graph>>>>>>>>>><<\n");
+
+ while (methXTA <= methXTAlast) {
+ rt_method = XTAcallgraph[methXTA];
+ printf("xTA CALLGRAPH #%i:",methXTA); fflush(stdout);
+ method_display(rt_method);
+ rt_class = rt_method->class;
+ rt_descriptor = rt_method->descriptor;
+ rt_jcodelength = rt_method->jcodelength;
+ rt_jcode = rt_method->jcode;
+
+ if (! ( (rt_method->flags & ACC_NATIVE )
+ || (rt_method->flags & ACC_ABSTRACT) ) ) {
+ parseRT(m);
+ }
+ else {
+ RTAPRINT12bAbstractNative
+ if (rt_method->flags & ACC_NATIVE ) {
+ RTAPRINT12aNative
+ /* mark used and add to callgraph methods and classes used by NATIVE method */
+ markNativeMethodsRT(rt_class->name,rt_method->name,rt_descriptor);
+ }
+ if (rt_method->flags & ACC_ABSTRACT) {
+ panic("ABSTRACT_SHOULD not ever get into the callgraph!!!!!****!!!****!!!!****!!!!\n");
+ }
+ }
+ methXTA++;
+ RTAPRINT12Callgraph
+ RTAPRINT13Heirarchy
+ } /* while */
if (m->class->classUsed == NOTUSED)
m->class->classUsed = USED; /* say Main's class has a method used ??*/
printXTACallgraph ();
- RTAPRINT14CallgraphLast /* was >=2*/
- /***RTAPRINT15HeirarchyiLast **/ /*was >= 2 */
- if (m->name == utf_MAIN) {
- /*RTAprint*/ if ((pCallgraph >= 1) && (opt_rt)) {
- /*RTAprint*/ printCallgraph (); }
-
- /*RTprint*/ if ((pClassHeir >= 1) && (opt_rt)) {
- /*RTprint*/ printf("Last RTA Info -");
+ if (m->name == utf_MAIN) { /*-- MAIN specific -- */
+ /*RTAprint*/ if (pCallgraph >= 1) {
+ /*RTAprint*/ printXTACallgraph (); }
+ /*RTprint*/ if (pClassHeir >= 1) {
+ /*RTprint*/ printf("Last RTA Info -+-+-");
/*RTprint*/ printRThierarchyInfo(m);
/*RTprint*/ }
- /*RTprint*/ printObjectClassHeirarchy1( );
+ /*RTprint*/ /**printObjectClassHeirarchyAll( );**/
fflush(stdout);
-
- if ((XTAOPTbypass) || (opt_xta)) {
- /*--- XTA round 2+ "parse" - use info structures only so not a real parse */
- XTA_jit_parse2(m);
+ /*--- XTA round 2+ "parse" - use info structures only so not a real parse */
+ XTA_jit_parse2(m);
+ printf("XTAXTA CALLGRAPHS -SHOULD BE BUT ISNT- returned \n");
+ //MFREE(XTAcallgraph,methodinfo*,MAXCALLGRAPH);
}
- MFREE(callgraph,methodinfo*,MAXCALLGRAPH);
- if ((XTAOPTbypass) || (opt_xta)) {
- printf("XTAXTA CALLGRAPHS returned \n");
- MFREE(XTAcallgraph,methodinfo*,MAXCALLGRAPH);
- }
- }
+ } /* end opt_xta */
+
+ RTAPRINT14CallgraphLast /* was >=2*/
+ /***RTAPRINT15HeirarchyiLast **/ /*was >= 2 */
return;
}