[Fb-contrib-commit] fb-contrib/src/com/mebigfatguy/fbcontrib/detect BloatedSynchronizedBlock.java,1.
Brought to you by:
dbrosius
|
From: Dave B. <dbr...@us...> - 2006-01-27 04:30:58
|
Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29594/src/com/mebigfatguy/fbcontrib/detect Modified Files: BloatedSynchronizedBlock.java Log Message: if a branch occurs inside the safe section of a BSB, then make sure the entire branch is inside, otherwise clip off the safe section at the start of the branch. Index: BloatedSynchronizedBlock.java =================================================================== RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- BloatedSynchronizedBlock.java 16 Jan 2006 01:10:19 -0000 1.10 +++ BloatedSynchronizedBlock.java 27 Jan 2006 04:30:49 -0000 1.11 @@ -18,7 +18,9 @@ */ package com.mebigfatguy.fbcontrib.detect; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; import org.apache.bcel.classfile.Method; @@ -36,6 +38,7 @@ private static final String BSB_MIN_SAFE_CODE_SIZE = "fb-contrib.bsb.minsize"; private OpcodeStack stack = new OpcodeStack(); private Set<Integer> unsafeAliases = new HashSet<Integer>(); + private Map<Integer, Integer> branchInfo = new HashMap<Integer, Integer>(); private int syncPC; private int lastPC; private boolean isStatic; @@ -75,6 +78,7 @@ lastPC = -1; isStatic = obj.isStatic(); unsafeAliases.clear(); + branchInfo.clear(); thisCallOccurred = false; stack.resetForMethodEntry(this); } @@ -109,6 +113,13 @@ thisCallOccurred = false; } else if (seen == INVOKESTATIC) thisCallOccurred = (getDottedClassConstantOperand().equals(this.getClassContext().getJavaClass().getClassName())); + else if ((seen >= IFEQ) && (seen <= GOTO)) + { + Integer from = new Integer(getPC()); + Integer to = new Integer(getBranchTarget()); + branchInfo.put(from, to); + thisCallOccurred = false; + } else thisCallOccurred = false; @@ -134,11 +145,25 @@ int aloadReg = aloadReg(seen); unsafe |= (aloadReg >= 0) && unsafeAliases.contains(new Integer(aloadReg)); if (unsafe) { - if ((getPC() - syncPC) > minSafeCodeLength) { - bugReporter.reportBug(new BugInstance(this, "BSB_BLOATED_SYNCHRONIZED_BLOCK", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLineRange(this, syncPC + 1, lastPC)); + //If a branch exists in the safe code, make sure the entire branch + //is in the safe code, otherwise trim before the branch + int pc = getPC(); + if ((pc - syncPC) > minSafeCodeLength) { + for (Map.Entry<Integer, Integer> entry : branchInfo.entrySet()) { + int bStart = entry.getKey().intValue(); + if ((bStart >= syncPC) && (bStart <= pc)) { + int bEnd = entry.getValue().intValue(); + if (bEnd > pc) { + pc = bStart; + } + } + } + if ((pc - syncPC) > minSafeCodeLength) { + bugReporter.reportBug(new BugInstance(this, "BSB_BLOATED_SYNCHRONIZED_BLOCK", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLineRange(this, syncPC + 1, lastPC)); + } } syncPC = -1; } |