From abd8e0d2e04202e9c6c25873742495b2f3461bf8 Mon Sep 17 00:00:00 2001 From: adash Date: Tue, 19 Feb 2008 21:14:14 +0000 Subject: [PATCH] java: out of heap space bug fix --- .../Analysis/Prefetch/PrefetchAnalysis.java | 76 ++++++++++++++++++- Robust/src/IR/Flat/BuildCode.java | 63 +++++++-------- Robust/src/buildscript | 1 + 3 files changed, 105 insertions(+), 35 deletions(-) diff --git a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java index 6296abdc..97017bcc 100644 --- a/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java +++ b/Robust/src/Analysis/Prefetch/PrefetchAnalysis.java @@ -29,7 +29,7 @@ public class PrefetchAnalysis { public static final float PREFETCH_THRESHOLD_PROB = (float)0.30; public static final float BRANCH_TRUE_EDGE_PROB = (float)0.5; public static final float BRANCH_FALSE_EDGE_PROB = (float)0.5; - + public PrefetchAnalysis(State state, CallGraph callgraph, TypeUtil typeutil) { this.typeutil=typeutil; this.state=state; @@ -37,6 +37,8 @@ public class PrefetchAnalysis { prefetch_hash = new Hashtable>(); pmap_hash = new Hashtable>(); DoPrefetch(); + prefetch_hash = null; + pmap_hash = null; } /** This function returns true if a tempdescriptor object is found in the array of descriptors @@ -115,6 +117,8 @@ public class PrefetchAnalysis { if(newprefetchset.size() > 0) { addFlatPrefetchNode(newprefetchset); } + newprefetchset = null; + pset1_hash = null; } } @@ -128,6 +132,9 @@ public class PrefetchAnalysis { prefetch_hash.put(fn, nodehash); tovisit.remove(fn); } + + nodehash = null; + /* Visit and process nodes */ tovisit = fm.getNodeSet(); while(!tovisit.isEmpty()) { @@ -191,7 +198,9 @@ public class PrefetchAnalysis { child_prefetch_set_copy = (Hashtable) prefetch_hash.get(child_node).clone(); } processFlatCondBranch(curr, child_prefetch_set_copy, i, branch_prefetch_set, parentpmap); + parentpmap = null; } + branch_prefetch_set = null; break; case FKind.FlatOpNode: processFlatOpNode(curr, child_prefetch_set_copy, parentpmap); @@ -230,6 +239,10 @@ public class PrefetchAnalysis { System.out.println("NO SUCH FLATNODE"); break; } + + /* Free Heap Memory */ + child_prefetch_set_copy = null; + parentpmap = null; } /**This function compares all the prefetch pairs in a Prefetch set hashtable and @@ -377,6 +390,11 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + + /* Free Heap Memory */ + currcopy = null; + tocompare = null; + pm = null; } /** This function processes the prefetch set of a FlatElementNode @@ -487,6 +505,11 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + + /* Free heap memory */ + currcopy = null; + tocompare = null; + pm = null; } /** This function processes the prefetch set of a FlatSetFieldNode @@ -566,6 +589,10 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function processes the prefetch set of a FlatSetElementNode @@ -645,6 +672,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function applies rules and does analysis for a FlatOpNode @@ -686,6 +716,8 @@ public class PrefetchAnalysis { } child_prefetch_set_copy.remove(newpp); } + newdesc = null; + newpp = null; /* For cases like x=y with child prefetch set r[i].x, r[x].p, r[p+x].q*/ } else if(isTempDescFound(copyofchildpp, currfopn.getDest())) { ArrayList newdesc = new ArrayList(); @@ -706,6 +738,8 @@ public class PrefetchAnalysis { } child_prefetch_set_copy.remove(newpp); } + newdesc = null; + newpp = null; }else { continue; } @@ -769,6 +803,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function processes a FlatLiteralNode where cases such as @@ -851,6 +888,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function processes a FlatMethod where the method propagates @@ -886,6 +926,8 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + tocompare = null; + pm = null; } /** This Function processes the FlatCalls @@ -930,6 +972,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function handles the processes the FlatNode of type FlatCondBranch @@ -1022,6 +1067,9 @@ public class PrefetchAnalysis { prefetch_hash.put(curr,branch_prefetch_set); } } + /* Free heap memory */ + tocompare = null; + pm = null; } /** If FlatNode is not concerned with the prefetch set of its Child then propagate @@ -1058,6 +1106,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This functions processes for FlatNewNode @@ -1146,6 +1197,9 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + /* Free heap memory */ + tocompare = null; + pm = null; } /** This functions processes for FlatTagDeclaration @@ -1190,6 +1244,10 @@ public class PrefetchAnalysis { /* Overwrite the new prefetch set to the global hash table */ prefetch_hash.put(curr,tocompare); } + + /* Free heap memory */ + tocompare = null; + pm = null; } /** This function prints the Prefetch pairs of a given flatnode */ @@ -1226,6 +1284,11 @@ public class PrefetchAnalysis { } } + /* Free Heap Memory */ + pset1_init = null; + newtovisit = null; + + /* Delete redundant and subset prefetch pairs */ delSubsetPPairs(); /* Start with a top down sorted order of nodes */ @@ -1278,6 +1341,11 @@ public class PrefetchAnalysis { ppairs.remove(pp); } } + + /* Free heap memory */ + pplist = null; + pplength = null; + ppisMod = null; } } @@ -1464,6 +1532,12 @@ public class PrefetchAnalysis { newprefetchset.put(fn, s); } } + + /* Free heap memory */ + pset1 = null; + pset2 = null; + newpset = null; + prefetchset = null; } private void addFlatPrefetchNode(Hashtable> newprefetchset) { diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 44c7efcd..8b24c523 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1298,7 +1298,6 @@ public class BuildCode { current_node=current_node.getNext(0); } else throw new Error(); } - output.println("}\n\n"); } @@ -1432,25 +1431,9 @@ public class BuildCode { int i,j; if (state.PREFETCH) { - Iterator it = fpn.hspp.iterator(); output.println("/* prefetch */"); output.println("; /* empty statement to avoid compiler error */"); - - /* TODO Add support for arrays, Currently handles only field pointers*/ - /* The while loop below removes all prefetch tuples with arrays from the set of prefetches */ - /* - while(it.hasNext()) { - PrefetchPair pp = (PrefetchPair) it.next(); - for(i = 0; i < pp.desc.size(); i++) { - if(pp.getDescAt(i) instanceof IndexDescriptor) { - fpn.hspp.remove((PrefetchPair) pp); - it = fpn.hspp.iterator(); - break; - } - } - } - */ - //it = fpn.hspp.iterator(); + Iterator it = fpn.hspp.iterator(); String oidlist = new String(); while(it.hasNext()) { PrefetchPair pp = (PrefetchPair) it.next(); @@ -1513,10 +1496,15 @@ public class BuildCode { count+", fieldarry_"+count+");"); count++; } + + /* Free heap memory */ + fieldoffset = null; + endoffset = null; + oids = null; } public void generateInsideTransCode(FlatMethod fm, LocalityBinding lb,PrintWriter output,PrefetchPair pp,Vector oids, Vector fieldoffset,Vector endoffset, int tuplecount){ - int i; + int i,j; short offsetcount = 0; Object newdesc = pp.desc.get(0); @@ -1543,6 +1531,7 @@ public class BuildCode { generateTemp(fm, pp.base, lb) + "[" + tstlbl + "] : NULL)"); oids.add(oid); } + for(i = 1; i < pp.desc.size(); i++) { TypeDescriptor newtd; String newfieldoffset; @@ -1551,10 +1540,12 @@ public class BuildCode { if(desc instanceof FieldDescriptor) { Object prevdesc = pp.getDescAt(i-1); if(prevdesc instanceof IndexDescriptor){ - if((i-1) == 0) + if((i-1) == 0) { newtd = pp.base.getType(); - //FIXME currently handles one dimensional arrays - newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + } else { + //FIXME currently handles one dimensional arrays + newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + } } else { newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType(); } @@ -1563,8 +1554,8 @@ public class BuildCode { fieldoffset.add(newfieldoffset); } else { String tstlbl = new String(); - for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { - tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + for(j = 0; j < ((IndexDescriptor)desc).tddesc.size(); j++) { + tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(j), lb) + "+"; } tstlbl += ((IndexDescriptor)desc).offset.toString(); newfieldoffset = new String("(short)("+tstlbl+")"); @@ -1581,7 +1572,7 @@ public class BuildCode { } public void generateOutsideTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount) { - int i; + int i,j; short offsetcount = 0; String oid = new String(" (unsigned int) (" + generateTemp(fm, pp.base, lb)+ ")"); @@ -1597,8 +1588,12 @@ public class BuildCode { } else { Object prevdesc = pp.getDescAt(i-1); if(prevdesc instanceof IndexDescriptor){ - //FIXME currently handles one dimensional arrays - newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + if((i-1) == 0) { + newtd = pp.base.getType(); + } else { + //FIXME currently handles one dimensional arrays + newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + } } else { newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType(); } @@ -1607,8 +1602,8 @@ public class BuildCode { ((FieldDescriptor)desc).getSafeSymbol()+ "))"); } else { String tstlbl = new String(); - for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { - tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + for(j = 0; j < ((IndexDescriptor)desc).tddesc.size(); j++) { + tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(j), lb) + "+"; } tstlbl += ((IndexDescriptor)desc).offset.toString(); newfieldoffset = new String("(short)("+tstlbl+")"); @@ -1626,7 +1621,7 @@ public class BuildCode { } public void generateLocalTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp,Vector oids, Vector fieldoffset,Vector endoffset, int tuplecount) { - int i, j; + int i, j, k; short offsetcount = 0; Vector prefix = new Vector(); @@ -1646,7 +1641,7 @@ public class BuildCode { tstlbl += fd.getSafeSymbol() + ": NULL"; oid += tstlbl+ " )"; oids.add(oid); - for(j=i+1; j < pp.desc.size(); j++) { + for(j = i+1; j < pp.desc.size(); j++) { TypeDescriptor newtd; String newfieldoffset; Object desc = pp.getDescAt(j); @@ -1663,8 +1658,8 @@ public class BuildCode { ((FieldDescriptor)desc).getSafeSymbol()+ "))"); } else { String indexlbl = new String(); - for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { - indexlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + for(k = 0; k < ((IndexDescriptor)desc).tddesc.size(); k++) { + indexlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(k), lb) + "+"; } indexlbl += ((IndexDescriptor)desc).offset.toString(); newfieldoffset = new String("(short)("+indexlbl+")"); @@ -1701,7 +1696,7 @@ public class BuildCode { tstlbl += prefix.get(j) + "["; } indexstring += "["; - for(j=0; j