Update of /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26497/src/com/mebigfatguy/fbcontrib/detect
Modified Files:
BloatedSynchronizedBlock.java
Log Message:
ah poo, any static access is unsafe
Index: BloatedSynchronizedBlock.java
===================================================================
RCS file: /cvsroot/fb-contrib/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedSynchronizedBlock.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- BloatedSynchronizedBlock.java 7 Jan 2006 05:29:43 -0000 1.8
+++ BloatedSynchronizedBlock.java 7 Jan 2006 05:52:41 -0000 1.9
@@ -27,7 +27,6 @@
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
-import edu.umd.cs.findbugs.FieldAnnotation;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.StatelessDetector;
@@ -37,7 +36,6 @@
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 Set<String> unsafeFields = new HashSet<String>();
private int syncPC;
private int lastPC;
private boolean isStatic;
@@ -51,7 +49,7 @@
*/
public BloatedSynchronizedBlock(BugReporter bugReporter) {
this.bugReporter = bugReporter;
- minSafeCodeLength = Integer.getInteger(BSB_MIN_SAFE_CODE_SIZE, 10);
+ minSafeCodeLength = Integer.getInteger(BSB_MIN_SAFE_CODE_SIZE, 15).intValue();
}
/**
@@ -77,7 +75,6 @@
lastPC = -1;
isStatic = obj.isStatic();
unsafeAliases.clear();
- unsafeFields.clear();
thisCallOccurred = false;
stack.resetForMethodEntry(this);
}
@@ -110,7 +107,8 @@
thisCallOccurred = false;
} else
thisCallOccurred = false;
- }
+ } else if (seen == INVOKESTATIC)
+ thisCallOccurred = (getClassConstantOperand().equals(this.getClassContext().getJavaClass()));
else
thisCallOccurred = false;
@@ -122,27 +120,17 @@
int monitorReg = itm.getRegisterNumber();
if (monitorReg >= 0) {
unsafeAliases.add(new Integer(monitorReg));
- } else {
- FieldAnnotation fa = itm.getField();
- if (fa != null) {
- String name = fa.getFieldName();
- if (name != null)
- unsafeFields.add(name);
- }
- }
-
+ }
}
}
}
else if (seen == MONITOREXIT)
syncPC = -1;
else if (syncPC >= 0) {
- boolean unsafe = ((seen == PUTFIELD) || (seen == GETFIELD));
+ boolean unsafe = ((seen == PUTFIELD) || (seen == GETFIELD) || (seen == GETSTATIC) || (seen == PUTSTATIC));
unsafe |= (!isStatic) && ((seen == ALOAD_0) || (seen == ASTORE_0));
int aloadReg = aloadReg(seen);
unsafe |= (aloadReg >= 0) && unsafeAliases.contains(new Integer(aloadReg));
- String getStaticName = getStaticName(seen);
- unsafe |= (getStaticName != null) && unsafeFields.contains(getStaticName);
if (unsafe) {
if ((getPC() - syncPC) > minSafeCodeLength) {
bugReporter.reportBug(new BugInstance(this, "BSB_BLOATED_SYNCHRONIZED_BLOCK", NORMAL_PRIORITY)
@@ -188,21 +176,4 @@
return seen - ASTORE_0;
return -1;
}
-
- /**
- * returns the name of the field that is loaded with GETSTATIC, or null if not the getstatic instruction
- *
- * @param seen the currently visited opcode
- *
- * @return the fieldname used if it's a getstatic instruction, or null otherwise
- */
- public String getStaticName(int seen) {
- if (seen == GETSTATIC) {
- FieldAnnotation fa = FieldAnnotation.fromReferencedField(this);
- if (fa != null)
- return fa.getFieldName();
- }
- return null;
- }
-
}
|