Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [413] trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/det
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-04-08 14:10:37
|
Revision: 413 Author: dbrosius Date: 2006-04-08 07:10:32 -0700 (Sat, 08 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=413&view=rev Log Message: ----------- prescreen for MONITORENTER opcodes Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-04-08 14:10:00 UTC (rev 412) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-04-08 14:10:32 UTC (rev 413) @@ -18,15 +18,19 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.util.BitSet; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import org.apache.bcel.Constants; +import org.apache.bcel.classfile.Code; import org.apache.bcel.classfile.Method; import org.apache.bcel.generic.Type; import com.mebigfatguy.fbcontrib.utils.RegisterUtils; +import com.mebigfatguy.fbcontrib.utils.VersionTransition; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; @@ -73,22 +77,36 @@ } /** + * looks for methods that contain a MONITORENTER opcodes + * + * @param method the context object of the current method + * @return if the class uses synchronization + */ + public boolean prescreen(Method method) { + BitSet bytecodeSet = VersionTransition.getBytecodeSet(getClassContext(), method); + return (bytecodeSet != null) && (bytecodeSet.get(Constants.MONITORENTER)); + } + + /** * implement the visitor to reset the sync count, the stack, and gather some information * * @param obj the context object for the currently parsed method */ @Override - public void visitMethod(Method obj) { - if (obj.isSynchronized()) - syncPC = 0; - else - syncPC = -1; - isStatic = obj.isStatic(); - unsafeAliases.clear(); - unsafeAliases.add(new Integer(0)); - branchInfo.clear(); - unsafeCallOccurred = false; - stack.resetForMethodEntry(this); + public void visitCode(Code obj) { + Method m = getMethod(); + if (prescreen(m)) { + if (m.isSynchronized()) + syncPC = 0; + else + syncPC = -1; + isStatic = m.isStatic(); + unsafeAliases.clear(); + unsafeAliases.add(new Integer(0)); + branchInfo.clear(); + unsafeCallOccurred = false; + stack.resetForMethodEntry(this); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-04-17 03:38:17
|
Revision: 454 Author: dbrosius Date: 2006-04-16 20:38:12 -0700 (Sun, 16 Apr 2006) ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=454&view=rev Log Message: ----------- Manually cleanup memory now that StatelessDetector is removed. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-04-17 03:36:08 UTC (rev 453) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java 2006-04-17 03:38:12 UTC (rev 454) @@ -35,20 +35,20 @@ import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BytecodeScanningDetector; import edu.umd.cs.findbugs.OpcodeStack; -import edu.umd.cs.findbugs.StatelessDetector; +import edu.umd.cs.findbugs.ba.ClassContext; /** * looks for methods that are implemented using synchronized blocks, but are overly * synchronized because the beginning of the block only accesses local variables, * and not member variables, or this. */ -public class BloatedSynchronizedBlock extends BytecodeScanningDetector implements StatelessDetector +public class BloatedSynchronizedBlock extends BytecodeScanningDetector { private final BugReporter bugReporter; private static final String BSB_MIN_SAFE_CODE_SIZE = "fb-contrib.bsb.minsize"; - private final OpcodeStack stack = new OpcodeStack(); - private final Set<Integer> unsafeAliases = new HashSet<Integer>(); - private final Map<Integer, Integer> branchInfo = new HashMap<Integer, Integer>(); + private OpcodeStack stack; + private Set<Integer> unsafeAliases; + private Map<Integer, Integer> branchInfo; private int syncPC; private boolean isStatic; private final int minSafeCodeLength; @@ -64,15 +64,15 @@ minSafeCodeLength = Integer.getInteger(BSB_MIN_SAFE_CODE_SIZE, 16).intValue(); } - /** - * clone this detector so that it can be a StatelessDetector - * - * @return a clone of this object - * - * @throws CloneNotSupportedException never - */ - public final Object clone() throws CloneNotSupportedException { - return super.clone(); + @Override + public void visitClassContext(ClassContext classContext) { + stack = new OpcodeStack(); + unsafeAliases = new HashSet<Integer>(); + branchInfo = new HashMap<Integer, Integer>(); + super.visitClassContext(classContext); + stack = null; + unsafeAliases = null; + branchInfo = null; } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |