From b2f0e67f6ba3340e0c14b81770efd7491fa4ef40 Mon Sep 17 00:00:00 2001 From: yeom Date: Thu, 21 Jul 2011 02:00:20 +0000 Subject: [PATCH] more changes. --- Robust/src/Analysis/SSJava/FlowDownCheck.java | 187 +++++++++++++----- .../SSJava/MethodAnnotationCheck.java | 23 +-- Robust/src/Tests/ssJava/mp3decoder/Crc16.java | 21 +- .../src/Tests/ssJava/mp3decoder/Decoder.java | 13 +- .../src/Tests/ssJava/mp3decoder/Header.java | 18 +- .../ssJava/mp3decoder/LayerIDecoder.java | 4 +- .../ssJava/mp3decoder/LayerIIDecoder.java | 8 +- .../ssJava/mp3decoder/LayerIIIDecoder.java | 2 +- .../ssJava/mp3decoder/SynthesisFilter.java | 14 +- .../Tests/ssJava/mp3decoder/huffcodetab.java | 4 +- 10 files changed, 201 insertions(+), 93 deletions(-) diff --git a/Robust/src/Analysis/SSJava/FlowDownCheck.java b/Robust/src/Analysis/SSJava/FlowDownCheck.java index 41439daa..74e1c252 100644 --- a/Robust/src/Analysis/SSJava/FlowDownCheck.java +++ b/Robust/src/Analysis/SSJava/FlowDownCheck.java @@ -43,6 +43,7 @@ import IR.Tree.ReturnNode; import IR.Tree.SubBlockNode; import IR.Tree.SwitchBlockNode; import IR.Tree.SwitchStatementNode; +import IR.Tree.SynchronizedNode; import IR.Tree.TertiaryNode; import IR.Tree.TreeNode; import Util.Pair; @@ -283,9 +284,43 @@ public class FlowDownCheck { case Kind.LoopNode: checkDeclarationInLoopNode(md, nametable, (LoopNode) bsn); break; + + case Kind.IfStatementNode: + checkDeclarationInIfStatementNode(md, nametable, (IfStatementNode) bsn); + return; + + case Kind.SwitchStatementNode: + checkDeclarationInSwitchStatementNode(md, nametable, (SwitchStatementNode) bsn); + return; + + case Kind.SynchronizedNode: + checkDeclarationInSynchronizedNode(md, nametable, (SynchronizedNode) bsn); + return; + + } + } + + private void checkDeclarationInSynchronizedNode(MethodDescriptor md, SymbolTable nametable, + SynchronizedNode sbn) { + checkDeclarationInBlockNode(md, nametable, sbn.getBlockNode()); + } + + private void checkDeclarationInSwitchStatementNode(MethodDescriptor md, SymbolTable nametable, + SwitchStatementNode ssn) { + BlockNode sbn = ssn.getSwitchBody(); + for (int i = 0; i < sbn.size(); i++) { + SwitchBlockNode node = (SwitchBlockNode) sbn.get(i); + checkDeclarationInBlockNode(md, nametable, node.getSwitchBlockStatement()); } } + private void checkDeclarationInIfStatementNode(MethodDescriptor md, SymbolTable nametable, + IfStatementNode isn) { + checkDeclarationInBlockNode(md, nametable, isn.getTrueBlock()); + if (isn.getFalseBlock() != null) + checkDeclarationInBlockNode(md, nametable, isn.getFalseBlock()); + } + private void checkDeclarationInLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln) { if (ln.getType() == LoopNode.FORLOOP) { @@ -434,12 +469,6 @@ public class FlowDownCheck { // declaration annotation CompositeLocation declaredReturnLoc = md2ReturnLoc.get(md); - System.out.println("\nreturnLocAt=" + declaredReturnLoc); - System.out.println("returnValueLoc=" + returnValueLoc); - System.out.println("COMPARE RESULT=" - + CompositeLattice.compare(declaredReturnLoc, returnValueLoc, - generateErrorMessage(md.getClassDesc(), rn))); - int compareResult = CompositeLattice.compare(returnValueLoc, declaredReturnLoc, generateErrorMessage(md.getClassDesc(), rn)); @@ -596,15 +625,10 @@ public class FlowDownCheck { private CompositeLocation checkLocationFromDeclarationNode(MethodDescriptor md, SymbolTable nametable, DeclarationNode dn) { - System.out.println("##DeclarationNode=" + dn.printNode(0) + " " - + generateErrorMessage(md.getClassDesc(), dn)); - VarDescriptor vd = dn.getVarDescriptor(); CompositeLocation destLoc = d2loc.get(vd); - System.out.println("##DeclarationNode destLoc=" + destLoc + " of vd=" + vd + " of md=" + md); - if (dn.getExpression() != null) { CompositeLocation expressionLoc = checkLocationFromExpressionNode(md, nametable, dn.getExpression(), @@ -806,20 +830,18 @@ public class FlowDownCheck { argList.add(callerArg); } - System.out.println("##"); - System.out.println("min.getMethod()=" + min.getMethod() + " argList=" + argList); - System.out.println("computeReturnLocation=" - + md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList)); + System.out.println("\n## computeReturnLocation=" + min.getMethod() + " argList=" + argList); + CompositeLocation compLoc = md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList); + DeltaLocation delta = new DeltaLocation(compLoc, 1); + System.out.println("##computeReturnLocation=" + delta); - return md2ReturnLocGen.get(min.getMethod()).computeReturnLocation(argList); + return delta; } private void checkCalleeConstraints(MethodDescriptor md, SymbolTable nametable, MethodInvokeNode min) { - System.out.println("checkCalleeConstraints " + generateErrorMessage(md.getClassDesc(), min)); - if (min.numArgs() > 1) { // caller needs to guarantee that it passes arguments in regarding to // callee's hierarchy @@ -828,7 +850,6 @@ public class FlowDownCheck { CompositeLocation callerArg1 = checkLocationFromExpressionNode(md, nametable, en, new CompositeLocation()); - ClassDescriptor calleecd = min.getMethod().getClassDesc(); VarDescriptor calleevd = (VarDescriptor) min.getMethod().getParameter(i); CompositeLocation calleeLoc1 = d2loc.get(calleevd); @@ -845,9 +866,6 @@ public class FlowDownCheck { VarDescriptor calleevd2 = (VarDescriptor) min.getMethod().getParameter(currentIdx); CompositeLocation calleeLoc2 = d2loc.get(calleevd2); - System.out.println("#callerResult=" + callerArg1 + " " + callerArg2); - System.out.println("#calleeResult=" + calleeLoc1 + " " + calleeLoc2); - int callerResult = CompositeLattice.compare(callerArg1, callerArg2, generateErrorMessage(md.getClassDesc(), min)); @@ -944,6 +962,7 @@ public class FlowDownCheck { System.out.println("checking op node=" + on.printNode(0) + generateErrorMessage(md.getClassDesc(), on)); + System.out.println("# op node=" + on.printNode(0)); System.out.println("left loc=" + leftLoc + " from " + on.getLeft().getClass()); if (on.getRight() != null) { System.out.println("right loc=" + rightLoc + " from " + on.getRight().kind()); @@ -1024,6 +1043,7 @@ public class FlowDownCheck { loc.addLocation(locElement); return loc; } + Descriptor d = (Descriptor) nametable.get(varname); // CompositeLocation localLoc = null; @@ -1040,6 +1060,7 @@ public class FlowDownCheck { // if it is 'static final', the location has TOP since no one can // change its value loc.addLocation(Location.createTopLocation(md)); + return loc; } else { // if 'static', the location has pre-assigned global loc MethodLattice localLattice = ssjava.getMethodLattice(md); @@ -1061,6 +1082,24 @@ public class FlowDownCheck { Location fieldLoc = (Location) fd.getType().getExtension(); loc.addLocation(fieldLoc); + } else if (d == null) { + + // check if the var is a static field of the class + FieldDescriptor fd = nn.getField(); + ClassDescriptor cd = nn.getClassDesc(); + + if (fd != null && cd != null) { + + if (fd.isStatic() && fd.isFinal()) { + loc.addLocation(Location.createTopLocation(md)); + return loc; + } else { + MethodLattice localLattice = ssjava.getMethodLattice(md); + Location fieldLoc = new Location(md, localLattice.getThisLoc()); + loc.addLocation(fieldLoc); + } + } + } } return loc; @@ -1074,8 +1113,14 @@ public class FlowDownCheck { FieldDescriptor fd = fan.getField(); - if (ltd.isClassNameRef()) { - // using a class name directly + String varName = null; + if (left.kind() == Kind.NameNode) { + NameDescriptor nd = ((NameNode) left).getName(); + varName = nd.toString(); + } + + if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) { + // using a class name directly or access using this if (fd.isStatic() && fd.isFinal()) { loc.addLocation(Location.createTopLocation(md)); return loc; @@ -1449,37 +1494,97 @@ public class FlowDownCheck { } Location loc2 = compLoc2.get(i); - if (!loc1.getDescriptor().equals(loc2.getDescriptor())) { + Descriptor d1 = loc1.getDescriptor(); + Descriptor d2 = loc2.getDescriptor(); + + Descriptor descriptor; + + if (d1 instanceof ClassDescriptor && d2 instanceof ClassDescriptor) { + + if (d1.equals(d2)) { + descriptor = d1; + } else { + // identifying which one is parent class + Set d1SubClassesSet = ssjava.tu.getSubClasses((ClassDescriptor) d1); + Set d2SubClassesSet = ssjava.tu.getSubClasses((ClassDescriptor) d2); + + if (d1 == null && d2 == null) { + throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + + " because they are not comparable at " + msg); + } else if (d1 != null && d1SubClassesSet.contains(d2)) { + descriptor = d1; + } else if (d2 != null && d2SubClassesSet.contains(d1)) { + descriptor = d2; + } else { + throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + + " because they are not comparable at " + msg); + } + } + + } else if (d1 instanceof MethodDescriptor && d2 instanceof MethodDescriptor) { + + if (d1.equals(d2)) { + descriptor = d1; + } else { + + // identifying which one is parent class + MethodDescriptor md1 = (MethodDescriptor) d1; + MethodDescriptor md2 = (MethodDescriptor) d2; + + if (!md1.matches(md2)) { + throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + + " because they are not comparable at " + msg); + } + + Set d1SubClassesSet = + ssjava.tu.getSubClasses(((MethodDescriptor) d1).getClassDesc()); + Set d2SubClassesSet = + ssjava.tu.getSubClasses(((MethodDescriptor) d2).getClassDesc()); + + if (d1 == null && d2 == null) { + throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + + " because they are not comparable at " + msg); + } else if (d1 != null && d1SubClassesSet.contains(d2)) { + descriptor = d1; + } else if (d2 != null && d2SubClassesSet.contains(d1)) { + descriptor = d2; + } else { + throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + + " because they are not comparable at " + msg); + } + } + + } else { throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 + " because they are not comparable at " + msg); } - Descriptor d1 = loc1.getDescriptor(); - Descriptor d2 = loc2.getDescriptor(); + // SSJavaLattice lattice1 = getLatticeByDescriptor(d1); + // SSJavaLattice lattice2 = getLatticeByDescriptor(d2); - SSJavaLattice lattice1 = getLatticeByDescriptor(d1); - SSJavaLattice lattice2 = getLatticeByDescriptor(d2); + SSJavaLattice lattice = getLatticeByDescriptor(descriptor); // check if the spin location is appeared only at the end of the // composite location - if (lattice1.getSpinLocSet().contains(loc1.getLocIdentifier())) { + if (lattice.getSpinLocSet().contains(loc1.getLocIdentifier())) { if (i != (compLoc1.getSize() - 1)) { - throw new Error("The spin location " + loc1.getLocIdentifier() + throw new Error("The shared location " + loc1.getLocIdentifier() + " cannot be appeared in the middle of composite location at" + msg); } } - if (lattice2.getSpinLocSet().contains(loc2.getLocIdentifier())) { + if (lattice.getSpinLocSet().contains(loc2.getLocIdentifier())) { if (i != (compLoc2.getSize() - 1)) { throw new Error("The spin location " + loc2.getLocIdentifier() + " cannot be appeared in the middle of composite location at " + msg); } } - if (!lattice1.equals(lattice2)) { - throw new Error("Failed to compare two locations of " + compLoc1 + " and " + compLoc2 - + " because they are not comparable at " + msg); - } + // if (!lattice1.equals(lattice2)) { + // throw new Error("Failed to compare two locations of " + compLoc1 + + // " and " + compLoc2 + // + " because they are not comparable at " + msg); + // } if (loc1.getLocIdentifier().equals(loc2.getLocIdentifier())) { numOfTie++; @@ -1487,11 +1592,11 @@ public class FlowDownCheck { // note that the spinning location only can be appeared in the last // part of the composite location if (awareSharedLoc && numOfTie == compLoc1.getSize() - && lattice1.getSpinLocSet().contains(loc1.getLocIdentifier())) { + && lattice.getSpinLocSet().contains(loc1.getLocIdentifier())) { return ComparisonResult.GREATER; } continue; - } else if (lattice1.isGreaterThan(loc1.getLocIdentifier(), loc2.getLocIdentifier())) { + } else if (lattice.isGreaterThan(loc1.getLocIdentifier(), loc2.getLocIdentifier())) { return ComparisonResult.GREATER; } else { return ComparisonResult.LESS; @@ -1731,12 +1836,6 @@ class ReturnLocGenerator { // compute GLB of arguments subset that are same or higher than return // location CompositeLocation glb = CompositeLattice.calculateGLB(inputGLB); - - System.out.println("### computeReturnLocation"); - System.out.println("### args=" + args); - System.out.println("### calculateGLB=" + inputGLB); - System.out.println("### glb=" + glb); - return glb; } } diff --git a/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java b/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java index d1914e02..f05fcff0 100644 --- a/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java +++ b/Robust/src/Analysis/SSJava/MethodAnnotationCheck.java @@ -90,28 +90,19 @@ public class MethodAnnotationCheck { if (!visited.contains(p)) { visited.add(p); - if (calleeMD.getClassDesc().isInterface()) { - calleeMD.getClassDesc(); - } - tovisit.add(calleeMD); - if (calleeMD.isAbstract()) { - Set possibleCalleeSet = - (Set) ssjava.getCallGraph().getMethods(calleeMD); - - for (Iterator iterator2 = possibleCalleeSet.iterator(); iterator2.hasNext();) { - MethodDescriptor possibleCallee = (MethodDescriptor) iterator2.next(); + Set possibleCalleeSet = + (Set) ssjava.getCallGraph().getMethods(calleeMD); - if (!possibleCallee.isAbstract()) { - ssjava.addAnnotationRequire(possibleCallee); - tovisit.add(possibleCallee); - } + for (Iterator iterator2 = possibleCalleeSet.iterator(); iterator2.hasNext();) { + MethodDescriptor possibleCallee = (MethodDescriptor) iterator2.next(); + if (!possibleCallee.isAbstract()) { + ssjava.addAnnotationRequire(possibleCallee); + tovisit.add(possibleCallee); } - } else { - ssjava.addAnnotationRequire(calleeMD); } } diff --git a/Robust/src/Tests/ssJava/mp3decoder/Crc16.java b/Robust/src/Tests/ssJava/mp3decoder/Crc16.java index ae35b481..aea133ed 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Crc16.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Crc16.java @@ -46,16 +46,17 @@ public final class Crc16 */ public void add_bits (@LOC("IN") int bitstring, @LOC("IN") int length) { - @LOC("SH") int bitmask = 1 << (length - 1); - do - if (((crc & 0x8000) == 0) ^ ((bitstring & bitmask) == 0 )) - { - crc <<= 1; - crc ^= polynomial; - } - else - crc <<= 1; - while ((bitmask >>>= 1) != 0); + @LOC("SH") int bitmask = 1 << (length - 1); + do{ + if (((crc & 0x8000) == 0) ^ ((bitstring & bitmask) == 0 )) + { + crc <<= 1; + crc ^= polynomial; + } + else{ + crc <<= 1; + } + }while ((bitmask >>>= 1) != 0); } /** diff --git a/Robust/src/Tests/ssJava/mp3decoder/Decoder.java b/Robust/src/Tests/ssJava/mp3decoder/Decoder.java index 46c87ba2..6b8a588c 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Decoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Decoder.java @@ -27,7 +27,7 @@ * @version 0.0.7 12/12/99 * @since 0.0.5 */ -@LATTICE("ST,OUT,FIL,DE,O,EQ,PA,INIT") +@LATTICE("ST,OUT,FIL,DE,O,EQ,PA,INIT,DE*") public class Decoder implements DecoderErrors { static private final Params DEFAULT_PARAMS = new Params(); @@ -145,10 +145,17 @@ public class Decoder implements DecoderErrors output.clear_buffer(); - @LOC("DE") FrameDecoder decoder = retrieveDecoder(header, stream, layer); - + @LOC("TH,Decoder.DE") FrameDecoder decoder = retrieveDecoder(header, stream, layer); decoder.decodeFrame(); + if(layer==3){ + l3decoder=(LayerIIIDecoder)decoder; + }else if(layer==2){ + l2decoder=(LayerIIDecoder)decoder; + }else{ + l1decoder=(LayerIDecoder)decoder; + } + output.write_buffer(1); return output; diff --git a/Robust/src/Tests/ssJava/mp3decoder/Header.java b/Robust/src/Tests/ssJava/mp3decoder/Header.java index 02826144..cd7fb01f 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/Header.java +++ b/Robust/src/Tests/ssJava/mp3decoder/Header.java @@ -353,19 +353,19 @@ public final class Header /** * Returns version. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int version() { return h_version; } /** * Returns Layer ID. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int layer() { return h_layer; } /** * Returns bitrate index. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int bitrate_index() { return h_bitrate_index; } /** @@ -381,7 +381,7 @@ public final class Header /** * Returns Mode. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int mode() { return h_mode; } /** @@ -425,7 +425,7 @@ public final class Header * Returns Checksum flag. * Compares computed checksum with stream checksum. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public boolean checksum_ok () { return (checksum == crc.checksum()); } // Seeking and layer III stuff @@ -441,13 +441,13 @@ public final class Header /** * Returns Slots. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int slots() { return nSlots; } /** * Returns Mode Extension. */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int mode_extension() { return h_mode_extension; } // E.B -> private to public @@ -762,7 +762,7 @@ public final class Header * Returns the number of subbands in the current frame. * @return number of subbands */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int number_of_subbands() {return h_number_of_subbands;} /** @@ -772,6 +772,6 @@ public final class Header * subbands above that limit are in intensity stereo mode. * @return intensity */ - @RETURNLOC("THIS") + @RETURNLOC("OUT") public int intensity_stereo_bound() {return h_intensity_stereo_bound;} } diff --git a/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java b/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java index b3572bf1..3b2285b0 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/LayerIDecoder.java @@ -40,7 +40,7 @@ @LOC("H") protected int which_channels; @LOC("H") protected int mode; - @LOC("H") protected int num_subbands; + @LOC("SH") protected int num_subbands; @LOC("L") protected Subband[] subbands; @LOC("H") protected Crc16 crc = null; // new Crc16[1] to enable CRC checking. @@ -354,7 +354,7 @@ sample = sample * factor + offset; // requantization if (channels == OutputChannels.BOTH_CHANNELS) { - @LOC("OUT") float sample1 = sample * scalefactor; + @LOC("OUT") float sample1 = sample * scalefactor; @LOC("OUT") float sample2 = sample * channel2_scalefactor; filter1.input_sample(sample1, subbandnumber); filter2.input_sample(sample2, subbandnumber); diff --git a/Robust/src/Tests/ssJava/mp3decoder/LayerIIDecoder.java b/Robust/src/Tests/ssJava/mp3decoder/LayerIIDecoder.java index a6740fac..28142504 100644 --- a/Robust/src/Tests/ssJava/mp3decoder/LayerIIDecoder.java +++ b/Robust/src/Tests/ssJava/mp3decoder/LayerIIDecoder.java @@ -65,8 +65,9 @@ class LayerIIDecoder extends LayerIDecoder implements FrameDecoder protected void readScaleFactorSelection() { // eom note: num_subbands is defined in LayerIDecoder so it has (THIS, LayerIDecoder) Loc - for (@LOC("V,LayerIIDecoder.SH") int i = 0; i < num_subbands; ++i) - ((SubbandLayer2)subbands[i]).read_scalefactor_selection(stream, crc); + for (@LOC("V,LayerIIDecoder.SH") int i = 0; i < num_subbands; ++i){ + ((SubbandLayer2)subbands[i]).read_scalefactor_selection(stream, crc); + } } @@ -677,7 +678,8 @@ class LayerIIDecoder extends LayerIDecoder implements FrameDecoder /** * */ - @LATTICE("OUT