From f9631ed750b3300f0b4ba422c41b6024b08ce750 Mon Sep 17 00:00:00 2001 From: yeom Date: Tue, 13 Dec 2011 01:43:14 +0000 Subject: [PATCH] changes. --- .../SSJava/DefinitelyWrittenCheck.java | 245 ++++++++++-------- .../SSJava/MP3Decoder/LayerIIIDecoder.java | 243 +++++++++-------- .../SSJava/MP3Decoder/SynthesisFilter.java | 6 +- 3 files changed, 262 insertions(+), 232 deletions(-) diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 2e1598d2..fd02c24d 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -8,6 +8,7 @@ import java.util.LinkedList; import java.util.Set; import java.util.Stack; +import Analysis.Liveness; import Analysis.CallGraph.CallGraph; import Analysis.Loops.LoopFinder; import IR.Descriptor; @@ -37,6 +38,8 @@ public class DefinitelyWrittenCheck { State state; CallGraph callGraph; + Liveness liveness; + int debugcount = 0; // maps a descriptor to its known dependents: namely @@ -127,6 +130,8 @@ public class DefinitelyWrittenCheck { private SharedLocMap calleeUnionBoundDeleteSet; private SharedLocMap calleeIntersectBoundSharedSet; + Set liveInTempSetToEventLoop; + private Hashtable mapDescToLocation; private TempDescriptor LOCAL; @@ -168,6 +173,8 @@ public class DefinitelyWrittenCheck { this.mapMethodToSharedLocCoverSet = new Hashtable, NTuple>>(); this.mapFlatNodeToDeleteSet = new Hashtable(); + this.liveness = new Liveness(); + this.liveInTempSetToEventLoop = new HashSet(); } public void definitelyWrittenCheck() { @@ -344,31 +351,35 @@ public class DefinitelyWrittenCheck { if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop") && !lhs.getSymbol().startsWith("rightop") && rhs.getType().isImmutable()) { - Location dstLoc = getLocation(lhs); - if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) { - NTuple lhsHeapPath = computePath(lhs); - NTuple lhsLocTuple = mapDescriptorToLocationPath.get(lhs); + if (mapHeapPath.containsKey(rhs)) { + Location dstLoc = getLocation(lhs); + if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) { + NTuple lhsHeapPath = computePath(lhs); + NTuple lhsLocTuple = mapDescriptorToLocationPath.get(lhs); - Location srcLoc = getLocation(lhs); + Location srcLoc = getLocation(lhs); - // computing gen/kill set - computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - if (!dstLoc.equals(srcLoc)) { - computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); - } else { - computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath); - updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); - } + // computing gen/kill set + computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + if (!dstLoc.equals(srcLoc)) { + computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); + } else { + computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath); + updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath); + } - // System.out.println("VAR WRITE:" + fn); - // System.out.println("lhsLocTuple=" + lhsLocTuple + - // " lhsHeapPath=" + lhsHeapPath); - // System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc); - // System.out.println("KILLSET=" + killSet); - // System.out.println("GENSet=" + genSet); - // System.out.println("DELETESET=" + currDeleteSet); + // System.out.println("VAR WRITE:" + fn); + // System.out.println("lhsLocTuple=" + lhsLocTuple + + // " lhsHeapPath=" + lhsHeapPath); + // System.out.println("dstLoc=" + dstLoc + " srcLoc=" + srcLoc); + // System.out.println("KILLSET=" + killSet); + // System.out.println("GENSet=" + genSet); + // System.out.println("DELETESET=" + currDeleteSet); + } + } else { + break; } } @@ -705,54 +716,59 @@ public class DefinitelyWrittenCheck { if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop") && !lhs.getSymbol().startsWith("rightop")) { - NTuple rhsLocTuple = new NTuple(); - NTuple lhsLocTuple = new NTuple(); - if (mapDescriptorToLocationPath.containsKey(rhs)) { - mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs)); - lhsLocTuple = mapDescriptorToLocationPath.get(lhs); - } else { - // rhs side - if (rhs.getType().getExtension() != null - && rhs.getType().getExtension() instanceof SSJavaType) { + if (mapHeapPath.containsKey(rhs)) { + NTuple rhsLocTuple = new NTuple(); + NTuple lhsLocTuple = new NTuple(); + if (mapDescriptorToLocationPath.containsKey(rhs)) { + mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs)); + lhsLocTuple = mapDescriptorToLocationPath.get(lhs); + } else { + // rhs side + if (rhs.getType().getExtension() != null + && rhs.getType().getExtension() instanceof SSJavaType) { - if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) { - rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc() - .getTuple()); + if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) { + rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc() + .getTuple()); + } + + } else { + NTuple locTuple = deriveLocationTuple(md, rhs); + if (locTuple != null) { + rhsLocTuple.addAll(locTuple); + } + } + if (rhsLocTuple.size() > 0) { + mapDescriptorToLocationPath.put(rhs, rhsLocTuple); } - } else { - NTuple locTuple = deriveLocationTuple(md, rhs); - if (locTuple != null) { - rhsLocTuple.addAll(locTuple); + // lhs side + if (lhs.getType().getExtension() != null + && lhs.getType().getExtension() instanceof SSJavaType) { + lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc() + .getTuple()); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); + } else if (mapDescriptorToLocationPath.get(rhs) != null) { + // propagate rhs's location to lhs + lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs)); + mapDescriptorToLocationPath.put(lhs, lhsLocTuple); } } - if (rhsLocTuple.size() > 0) { - mapDescriptorToLocationPath.put(rhs, rhsLocTuple); - } - // lhs side - if (lhs.getType().getExtension() != null - && lhs.getType().getExtension() instanceof SSJavaType) { - lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc() - .getTuple()); - mapDescriptorToLocationPath.put(lhs, lhsLocTuple); - } else if (mapDescriptorToLocationPath.get(rhs) != null) { - // propagate rhs's location to lhs - lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs)); - mapDescriptorToLocationPath.put(lhs, lhsLocTuple); - } - } + if (isEventLoopBody && lhs.getType().isPrimitive() + && !lhs.getSymbol().startsWith("srctmp")) { - if (isEventLoopBody && lhs.getType().isPrimitive() - && !lhs.getSymbol().startsWith("srctmp")) { + NTuple lhsHeapPath = computePath(lhs); - NTuple lhsHeapPath = computePath(lhs); + if (lhsLocTuple != null) { + addMayWrittenSet(md, lhsLocTuple, lhsHeapPath); + } - if (lhsLocTuple != null) { - addMayWrittenSet(md, lhsLocTuple, lhsHeapPath); } - + } else { + break; } + } } @@ -1288,11 +1304,10 @@ public class DefinitelyWrittenCheck { hasWriteEffect = true; } - if (hasWriteEffect) { + if (hasWriteEffect && mapHeapPath.containsKey(lhs)) { // write(lhs) - NTuple rhsHeapPath = computePath(rhs); NTuple lhsHeapPath = new NTuple(); - lhsHeapPath.addAll(rhsHeapPath); + lhsHeapPath.addAll(mapHeapPath.get(lhs)); Location lhsLoc = getLocation(lhs); if (ssjava.isSharedLocation(lhsLoc)) { @@ -1381,47 +1396,51 @@ public class DefinitelyWrittenCheck { fld = getArrayField(td); } - // write(field) - NTuple lhsHeapPath = computePath(lhs); - NTuple fldHeapPath = new NTuple(lhsHeapPath.getList()); - if (fn.kind() == FKind.FlatSetFieldNode) { - fldHeapPath.add(fld); - } - - // shared loc extension - Location fieldLoc; - if (fn.kind() == FKind.FlatSetFieldNode) { - fieldLoc = (Location) fld.getType().getExtension(); - } else { - NTuple locTuple = mapDescriptorToLocationPath.get(lhs); - fieldLoc = locTuple.get(locTuple.size() - 1); - } - - if (ssjava.isSharedLocation(fieldLoc)) { + // set up heap path + NTuple lhsHeapPath = mapHeapPath.get(lhs); + if (lhsHeapPath != null) { + // write(field) + NTuple fldHeapPath = new NTuple(lhsHeapPath.getList()); + if (fn.kind() == FKind.FlatSetFieldNode) { + fldHeapPath.add(fld); + } - NTuple fieldLocTuple = new NTuple(); - fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs)); + // shared loc extension + Location fieldLoc; if (fn.kind() == FKind.FlatSetFieldNode) { - fieldLocTuple.add(fieldLoc); + fieldLoc = (Location) fld.getType().getExtension(); + } else { + NTuple locTuple = mapDescriptorToLocationPath.get(lhs); + fieldLoc = locTuple.get(locTuple.size() - 1); } - Set> writtenSet = - mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple); + if (ssjava.isSharedLocation(fieldLoc)) { + + NTuple fieldLocTuple = new NTuple(); + fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs)); + if (fn.kind() == FKind.FlatSetFieldNode) { + fieldLocTuple.add(fieldLoc); + } + + Set> writtenSet = + mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple); + + if (isCovered(fieldLocTuple, writtenSet)) { + computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet); + computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet); + } else { + computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet); + } - if (isCovered(fieldLocTuple, writtenSet)) { - computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet); - computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet); } else { - computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet); + computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet); + computeGENSetForWrite(fldHeapPath, readWriteGenSet); } - } else { - computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet); - computeGENSetForWrite(fldHeapPath, readWriteGenSet); - } + // System.out.println("KILLSET=" + readWriteKillSet); + // System.out.println("GENSet=" + readWriteGenSet); - // System.out.println("KILLSET=" + readWriteKillSet); - // System.out.println("GENSet=" + readWriteGenSet); + } } break; @@ -1437,13 +1456,16 @@ public class DefinitelyWrittenCheck { // System.out.println("KILLSET=" + readWriteKillSet); // System.out.println("GENSet=" + readWriteGenSet); - checkManyRead(fc, curr); } break; } computeNewMapping(curr, readWriteKillSet, readWriteGenSet); + if (fn instanceof FlatCall) { + checkManyRead((FlatCall) fn, curr); + } + // System.out.println("#######" + curr); } @@ -1501,6 +1523,9 @@ public class DefinitelyWrittenCheck { Set> coverSet = mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple); + // System.out.println("locTuple=" + locTuple + " coverSet=" + coverSet + + // " currSet=" + inSet); + return inSet.containsAll(coverSet); } @@ -1611,7 +1636,7 @@ public class DefinitelyWrittenCheck { Hashtable, Set> KILLSet) { Set> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc); - System.out.println("boundMustWriteSet=" + boundMustWriteSet); + System.out.println("#boundMustWriteSet=" + boundMustWriteSet); for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) { NTuple heapPath = (NTuple) iterator.next(); @@ -1619,7 +1644,7 @@ public class DefinitelyWrittenCheck { if (isSharedLocation(heapPath)) { NTuple locTuple = getLocationTuple(heapPath); - if (isCovered(locTuple, sharedLocMap.get(locTuple))) { + if (isCovered(locTuple, sharedLocMap.get(locTuple)) && curr.containsKey(heapPath)) { // if it is shared loc and corresponding shared loc has been covered KILLSet.put(heapPath, curr.get(heapPath)); } @@ -2056,6 +2081,10 @@ public class DefinitelyWrittenCheck { Set methodDescriptorsToAnalyze = new HashSet(); methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet()); sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze); + + liveInTempSetToEventLoop = + liveness.getLiveInTemps(state.getMethodFlat(methodContainingSSJavaLoop), + ssjava.getSSJavaLoopEntrance()); } private void methodReadWriteSetAnalysis() { @@ -2150,6 +2179,13 @@ public class DefinitelyWrittenCheck { mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet); mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet); + for (Iterator iterator = liveInTempSetToEventLoop.iterator(); iterator.hasNext();) { + TempDescriptor liveIn = (TempDescriptor) iterator.next(); + NTuple heapPath = new NTuple(); + heapPath.add(liveIn); + mapHeapPath.put(liveIn, heapPath); + } + methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet, mayWriteSet, true); @@ -2237,16 +2273,17 @@ public class DefinitelyWrittenCheck { // mapHeapPath.put(lhs, lhsHeapPath); // } else - if (rhsHeapPath != null) { + if (rhsHeapPath != null && (!lhs.getType().isPrimitive())) { mapHeapPath.put(lhs, mapHeapPath.get(rhs)); } else { - if (isEventLoopBody) { - NTuple heapPath = new NTuple(); - heapPath.add(rhs); - mapHeapPath.put(lhs, heapPath); - } else { - break; - } + break; + // if (isEventLoopBody) { + // NTuple lhsHeapPath = new NTuple(); + // lhsHeapPath.add(rhs); + // mapHeapPath.put(lhs, lhsHeapPath); + // } else { + // break; + // } } // shared loc extension diff --git a/Robust/src/Benchmarks/SSJava/MP3Decoder/LayerIIIDecoder.java b/Robust/src/Benchmarks/SSJava/MP3Decoder/LayerIIIDecoder.java index 3936ca16..8739d5c4 100644 --- a/Robust/src/Benchmarks/SSJava/MP3Decoder/LayerIIIDecoder.java +++ b/Robust/src/Benchmarks/SSJava/MP3Decoder/LayerIIIDecoder.java @@ -32,8 +32,6 @@ *---------------------------------------------------------------------- */ - - /** * Class Implementing Layer 3 Decoder. * @@ -646,7 +644,7 @@ final class LayerIIIDecoder implements FrameDecoder { // System.out.println("Counter = ................................."+counter); // if (counter < 609) // { - counter++; // count should be loc* + // counter++; // count should be loc* // buffer.write_buffer(1); // buffer!!! // } // else if (counter == 609) @@ -699,8 +697,7 @@ final class LayerIIIDecoder implements FrameDecoder { si.ch[ch].gr[gr].big_values = sib.get_bits(9); si.ch[ch].gr[gr].global_gain = sib.get_bits(8); si.ch[ch].gr[gr].scalefac_compress = sib.get_bits(4); - @LOC("THIS,LayerIIIDecoder.SI,III_side_info_t.TEMP") int cond = - sib.get_bits(1); + @LOC("THIS,LayerIIIDecoder.SI,III_side_info_t.TEMP") int cond = sib.get_bits(1); // si.ch[ch].gr[gr].window_switching_flag = sib.get_bits(1); // if ((si.ch[ch].gr[gr].window_switching_flag) != 0) { if (cond != 0) { @@ -758,8 +755,7 @@ final class LayerIIIDecoder implements FrameDecoder { si.ch[ch].gr[0].global_gain = sib.get_bits(8); si.ch[ch].gr[0].scalefac_compress = sib.get_bits(9); - @LOC("THIS,LayerIIIDecoder.SI,III_side_info_t.TEMP") int cond = - sib.get_bits(1); + @LOC("THIS,LayerIIIDecoder.SI,III_side_info_t.TEMP") int cond = sib.get_bits(1); // si.ch[ch].gr[0].window_switching_flag = sib.get_bits(1); // if ((si.ch[ch].gr[0].window_switching_flag) != 0) { if (cond != 0) { @@ -1817,7 +1813,6 @@ final class LayerIIIDecoder implements FrameDecoder { && !(si.ch[ch].gr[gr].mixed_block_flag != 0)) return; - if ((si.ch[ch].gr[gr].window_switching_flag != 0) && (si.ch[ch].gr[gr].mixed_block_flag != 0) && (si.ch[ch].gr[gr].block_type == 2)) { sb18lim = 18; @@ -2391,7 +2386,6 @@ final class LayerIIIDecoder implements FrameDecoder { // This may be adjusted for performance without any problems. // public static final int POW_TABLE_LIMIT=512; - private static final int slen[][] = { { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }, { 0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3 } }; @@ -2842,134 +2836,131 @@ final class LayerIIIDecoder implements FrameDecoder { } +/************************************************************/ +/* L3TABLE */ +/************************************************************/ +@LATTICE("N