From: jjenista Date: Tue, 5 May 2009 22:08:19 +0000 (+0000) Subject: Several bug fixes. Now that tokens have a mutable element, reference var sets, they... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=463404bbb3e4ea156960359add5331055df75789;p=IRC.git Several bug fixes. Now that tokens have a mutable element, reference var sets, they must be deep copied when merging table to avoid altering two tables with one operation. A bug in removal by temp prevented sese-var mapping from being updated also. A change in table implementation makes a difference between public and private ops like add and remove. Any public op calls the private version and then asserts consistency. Private versions can be called in more complex operatios and don't necessarily have to leave the table consistent until the bigger op is finished. Much easier to find source of bugs this way. --- diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index d4e9af6a..35626a9a 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -393,9 +393,7 @@ public class MLPAnalysis { FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn; assert fsen.equals( currentSESE ); vstTable.age( currentSESE ); - vstTable.assertConsistency(); - } break; case FKind.FlatSESEExitNode: { @@ -411,9 +409,7 @@ public class MLPAnalysis { virLiveIn.addAll( virLiveInOld ); } livenessVirtualReads.put( fn, virLiveIn ); - vstTable.assertConsistency(); - } break; case FKind.FlatOpNode: { @@ -455,9 +451,7 @@ public class MLPAnalysis { // only break if this is an ASSIGN op node, // otherwise fall through to default case - vstTable.assertConsistency(); - break; } } @@ -483,7 +477,6 @@ public class MLPAnalysis { } vstTable.assertConsistency(); - } break; } // end switch diff --git a/Robust/src/Analysis/MLP/VarSrcTokTable.java b/Robust/src/Analysis/MLP/VarSrcTokTable.java index f2ff7245..7c04a92c 100644 --- a/Robust/src/Analysis/MLP/VarSrcTokTable.java +++ b/Robust/src/Analysis/MLP/VarSrcTokTable.java @@ -11,6 +11,12 @@ import java.io.*; // elements will be consistent after EVERY operation. Also, // a consistent assert method allows a debugger to ask whether // an operation has produced an inconsistent VarSrcTokTable. + +// in an effort to make sure operations keep the table consistent, +// all public methods that are also used by other methods for +// intermediate results (add and remove are used in other methods) +// there should be a public version that calls the private version +// so consistency is checked after public ops, but not private ops public class VarSrcTokTable { // a set of every token in the table @@ -35,53 +41,45 @@ public class VarSrcTokTable { assertConsistency(); } - + + // make a deep copy of the in table public VarSrcTokTable( VarSrcTokTable in ) { - trueSet = (HashSet) in.trueSet.clone(); + this(); + merge( in ); + assertConsistency(); + } - Iterator itr; Set s; - sese2vst = new Hashtable< FlatSESEEnterNode, Set >(); - itr = in.sese2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey(); - HashSet s1 = (HashSet) me.getValue(); - assert s1 != null; - sese2vst.put( sese, - (HashSet) (s1.clone()) ); - } + public void add( VariableSourceToken vst ) { + addPrivate( vst ); + assertConsistency(); + } - var2vst = new Hashtable< TempDescriptor, Set >(); - itr = in.var2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - TempDescriptor var = (TempDescriptor) me.getKey(); - HashSet s1 = (HashSet) me.getValue(); - assert s1 != null; - var2vst.put( var, - (HashSet) (s1.clone()) ); - } + private void addPrivate( VariableSourceToken vst ) { - sv2vst = new Hashtable< SVKey, Set >(); - itr = in.sv2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - SVKey key = (SVKey) me.getKey(); - HashSet s1 = (HashSet) me.getValue(); - assert s1 != null; - sv2vst.put( key, - (HashSet) (s1.clone()) ); - } + // make sure we aren't clobbering anything! + if( trueSet.contains( vst ) ) { + // if something with the same hashcode is in the true set, they might + // have different reference variable sets because that set is not considered + // in a token's equality, so make sure we smooth that out right here + Iterator vstItr = trueSet.iterator(); + while( vstItr.hasNext() ) { + VariableSourceToken vstAlready = vstItr.next(); - assertConsistency(); - } + if( vstAlready.equals( vst ) ) { + // take out the one that is in (we dont' want collisions in + // any of the other hash map sets either) + removePrivate( vstAlready ); - public void add( VariableSourceToken vst ) { + // combine reference variable sets + vst.getRefVars().addAll( vstAlready.getRefVars() ); - // make sure we aren't clobbering anything! - assert !trueSet.contains( vst ); + // now jump back as we are adding in a brand new token + break; + } + } + } trueSet.add( vst ); @@ -112,15 +110,14 @@ public class VarSrcTokTable { s.add( vst ); sv2vst.put( key, s ); } - - assertConsistency(); } public void addAll( Set s ) { Iterator itr = s.iterator(); while( itr.hasNext() ) { - add( itr.next() ); + addPrivate( itr.next() ); } + assertConsistency(); } @@ -179,113 +176,33 @@ public class VarSrcTokTable { } - public void merge( VarSrcTokTable table ) { + // merge now makes a deep copy of incoming stuff because tokens may + // be modified (reference var sets) by later ops that change more + // than one table, causing inconsistency + public void merge( VarSrcTokTable in ) { - if( table == null ) { + if( in == null ) { return; } - - System.out.println( "MERGING\n" ); - System.out.println( "THIS="+this.toStringPrettyVerbose() ); - System.out.println( "TABLEIN="+table.toStringPrettyVerbose() ); - - - trueSet.addAll( table.trueSet ); - - Iterator itr; - - - // merge sese2vst mappings - itr = this.sese2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey(); - Set s1 = (Set) me.getValue(); - Set s2 = table.sese2vst.get( sese ); - assert s1 != null; - - if( s2 != null ) { - s1.addAll( s2 ); - } - } - itr = table.sese2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - FlatSESEEnterNode sese = (FlatSESEEnterNode) me.getKey(); - Set s2 = (Set) me.getValue(); - Set s1 = this.sese2vst.get( sese ); - assert s2 != null; - - if( s1 == null ) { - this.sese2vst.put( sese, s2 ); - } - } - - - // merge var2vst mappings - itr = this.var2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - TempDescriptor var = (TempDescriptor) me.getKey(); - Set s1 = (Set) me.getValue(); - Set s2 = table.var2vst.get( var ); - assert s1 != null; - - if( s2 != null ) { - s1.addAll( s2 ); - } - } - itr = table.var2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - TempDescriptor var = (TempDescriptor) me.getKey(); - Set s2 = (Set) me.getValue(); - Set s1 = this.var2vst.get( var ); - assert s2 != null; - - if( s1 == null ) { - this.var2vst.put( var, s2 ); - } - } - - - // merge sv2vst mappings - itr = this.sv2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - SVKey key = (SVKey) me.getKey(); - Set s1 = (Set) me.getValue(); - Set s2 = table.sv2vst.get( key ); - assert s1 != null; - - if( s2 != null ) { - s1.addAll( s2 ); - } - } - itr = table.sv2vst.entrySet().iterator(); - while( itr.hasNext() ) { - Map.Entry me = (Map.Entry) itr.next(); - SVKey key = (SVKey) me.getKey(); - Set s2 = (Set) me.getValue(); - Set s1 = this.sv2vst.get( key ); - assert s2 != null; - - if( s1 == null ) { - this.sv2vst.put( key, s2 ); - } + Iterator vstItr = in.trueSet.iterator(); + while( vstItr.hasNext() ) { + VariableSourceToken vst = vstItr.next(); + this.addPrivate( vst.copy() ); } - System.out.println( "OUT="+this.toStringPrettyVerbose() ); - - assertConsistency(); } // remove operations must leave the trueSet - // and the hash maps consistent! + // and the hash maps consistent public void remove( VariableSourceToken vst ) { + removePrivate( vst ); + assertConsistency(); + } + + private void removePrivate( VariableSourceToken vst ) { trueSet.remove( vst ); Set s; @@ -303,11 +220,15 @@ public class VarSrcTokTable { s = get( vst.getSESE(), refVar ); if( s != null ) { s.remove( vst ); } } + } + + public void remove( FlatSESEEnterNode sese ) { + removePrivate( sese ); assertConsistency(); } - public void remove( FlatSESEEnterNode sese ) { + public void removePrivate( FlatSESEEnterNode sese ) { Set s = sese2vst.get( sese ); if( s == null ) { return; @@ -316,15 +237,19 @@ public class VarSrcTokTable { Iterator itr = s.iterator(); while( itr.hasNext() ) { VariableSourceToken vst = itr.next(); - remove( vst ); + removePrivate( vst ); } sese2vst.remove( sese ); + } + + public void remove( TempDescriptor refVar ) { + removePrivate( refVar ); assertConsistency(); } - public void remove( TempDescriptor refVar ) { + private void removePrivate( TempDescriptor refVar ) { Set s = var2vst.get( refVar ); if( s == null ) { return; @@ -344,47 +269,31 @@ public class VarSrcTokTable { itr = forRemoval.iterator(); while( itr.hasNext() ) { - // here's a token marked for removal, take it out as it is - // in this state - VariableSourceToken vst = itr.next(); - remove( vst ); - // if there are other references to the token, alter the - // token and then re-add it to this table, because it has - // a new hash value now + // here's a token marked for removal + VariableSourceToken vst = itr.next(); Set refVars = vst.getRefVars(); - refVars.remove( refVar ); - if( refVars.size() > 0 ) { - add( vst ); + + // if there was only one one variable + // referencing this token, just take it + // out of the table all together + if( refVars.size() == 1 ) { + removePrivate( vst ); } + + refVars.remove( refVar ); } var2vst.remove( refVar ); - - assertConsistency(); } + public void remove( FlatSESEEnterNode sese, TempDescriptor var ) { - // dont' use this yet + // don't seem to need this, don't bother maintaining + // until its clear we need it assert false; - - SVKey key = new SVKey( sese, var ); - Set s = sv2vst.get( key ); - if( s == null ) { - return; - } - - Iterator itr = s.iterator(); - while( itr.hasNext() ) { - VariableSourceToken vst = itr.next(); - remove( vst ); - } - - sv2vst.remove( key ); - - assertConsistency(); } @@ -630,6 +539,7 @@ public class VarSrcTokTable { Map.Entry me = (Map.Entry) itr.next(); VariableSourceToken vst = (VariableSourceToken) me.getKey(); Set s1 = (Set) me.getValue(); + assert vst.getRefVars().equals( s1 ); } } diff --git a/Robust/src/Analysis/MLP/VariableSourceToken.java b/Robust/src/Analysis/MLP/VariableSourceToken.java index a8fd33ce..2682fe22 100644 --- a/Robust/src/Analysis/MLP/VariableSourceToken.java +++ b/Robust/src/Analysis/MLP/VariableSourceToken.java @@ -39,6 +39,20 @@ public class VariableSourceToken { return addrVar; } + public VariableSourceToken copy() { + Set refVarsCopy = new HashSet(); + + Iterator rvItr = refVars.iterator(); + while( rvItr.hasNext() ) { + refVarsCopy.add( rvItr.next() ); + } + + return new VariableSourceToken( refVarsCopy, + sese, + new Integer( seseAge ), + addrVar ); + } + public boolean equals( Object o ) { if( o == null ) { return false;