[Fb-contrib-commit] SF.net SVN: fb-contrib: [697] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-11-30 06:05:11
|
Revision: 697 http://svn.sourceforge.net/fb-contrib/?rev=697&view=rev Author: dbrosius Date: 2006-11-29 22:05:11 -0800 (Wed, 29 Nov 2006) Log Message: ----------- initial checkin BAS Added Paths: ----------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java Added: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java (rev 0) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2006-11-30 06:05:11 UTC (rev 697) @@ -0,0 +1,77 @@ +package com.mebigfatguy.fbcontrib.detect; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.bcel.classfile.Code; + +import com.mebigfatguy.fbcontrib.utils.RegisterUtils; + +import edu.umd.cs.findbugs.BugReporter; +import edu.umd.cs.findbugs.BytecodeScanningDetector; +import edu.umd.cs.findbugs.ba.ClassContext; + +/** + * looks for variable assignments at a scope larger than its use. In this case, + * the assignment can be pushed down into the smaller scope to reduce the performance + * impact of that assignment. + */ +public class BloatedAssignmentScope extends BytecodeScanningDetector +{ + private BugReporter bugReporter; + private Map<Integer, Integer> regToLocationMap; + private Map<Integer, Integer> scopeBlockMap; + + /** + * constructs a BLT detector given the reporter to report bugs on + + * @param bugReporter the sync of bug reports + */ + public BloatedAssignmentScope(BugReporter bugReporter) { + this.bugReporter = bugReporter; + } + + /** + * implements the visitor to create and the clear the register to location map + * + * @param classContext the context object of the currently parsed class + */ + @Override + public void visitClassContext(ClassContext classContext) { + try { + regToLocationMap = new HashMap<Integer, Integer>(); + scopeBlockMap = new HashMap<Integer, Integer>(); + super.visitClassContext(classContext); + } finally { + regToLocationMap = null; + scopeBlockMap = null; + } + } + + /** + * implements the visitor to reset the register to location map + * + * @param obj the context object of the currently parsed code block + */ + @Override + public void visitCode(Code obj) { + regToLocationMap.clear(); + scopeBlockMap.clear(); + super.visitCode(obj); + } + + /** + * implements the visitor to look for variables assigned out side of the scope + * in which they are used. + * + * @param seen the opcode of the currently parsed instruction + */ + @Override + public void sawOpcode(int seen) { + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + int reg = RegisterUtils.getAStoreReg(this, seen); + } else if ((seen == ALOAD) || ((seen >= ALOAD_0) && (seen <= ALOAD_3))) { + int reg = RegisterUtils.getALoadReg(this, seen); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |