[Fb-contrib-commit] SF.net SVN: fb-contrib: [1013] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib
Brought to you by:
dbrosius
From: <dbr...@us...> - 2008-03-23 05:10:49
|
Revision: 1013 http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1013&view=rev Author: dbrosius Date: 2008-03-22 22:10:55 -0700 (Sat, 22 Mar 2008) Log Message: ----------- need to remove registers from collection groups when that variable goes out of scope Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-03-20 05:39:32 UTC (rev 1012) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/DeletingWhileIterating.java 2008-03-23 05:10:55 UTC (rev 1013) @@ -29,6 +29,8 @@ import org.apache.bcel.Repository; import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.JavaClass; +import org.apache.bcel.classfile.LocalVariable; +import org.apache.bcel.classfile.LocalVariableTable; import com.mebigfatguy.fbcontrib.utils.Integer14; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; @@ -85,6 +87,7 @@ private List<Set<Comparable<?>>> collectionGroups; private Map<Integer, Integer> groupToIterator; private Map<Integer, Loop> loops; + private Map<Integer, Set<Integer>> endOfScopes; /** * constructs a DWI detector given the reporter to report bugs on @@ -115,6 +118,7 @@ collectionGroups = null; groupToIterator = null; loops = null; + endOfScopes = null; } } @@ -129,6 +133,8 @@ collectionGroups.clear(); groupToIterator.clear(); loops.clear(); + buildVariableEndScopeMap(); + super.visitCode(obj); } @@ -278,6 +284,8 @@ OpcodeStack.Item itm = stack.getStackItem(0); itm.setUserValue(Integer14.valueOf(groupId)); } + + processEndOfScopes(Integer14.valueOf(getPC())); } } @@ -348,6 +356,42 @@ } } + private void buildVariableEndScopeMap() { + endOfScopes = new HashMap<Integer, Set<Integer>>(); + + LocalVariableTable lvt = getMethod().getLocalVariableTable(); + if (lvt != null) { + int len = lvt.getLength(); + for (int i = 0; i < len; i++) { + LocalVariable lv = lvt.getLocalVariable(i); + if (lv != null) { + Integer endPC = Integer14.valueOf(lv.getStartPC() + lv.getLength()); + Set<Integer> vars = endOfScopes.get(endPC); + if (vars == null) { + vars = new HashSet<Integer>(); + endOfScopes.put(endPC, vars); + } + vars.add(Integer14.valueOf(lv.getIndex())); + } + } + } + } + + private void processEndOfScopes(Integer pc) { + Set<Integer> endVars = endOfScopes.get(pc); + if (endVars != null) { + for (Integer v : endVars) { + Iterator<Set<Comparable<?>>> it = collectionGroups.iterator(); + while (it.hasNext()) { + Set<Comparable<?>> gv = it.next(); + if (gv.contains(v)) { + gv.remove(v); + } + } + } + } + } + static class Loop { public int loopStart; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |