[Fb-contrib-commit] SF.net SVN: fb-contrib:[1239] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-07-30 04:40:00
|
Revision: 1239
http://fb-contrib.svn.sourceforge.net/fb-contrib/?rev=1239&view=rev
Author: dbrosius
Date: 2009-07-30 04:39:50 +0000 (Thu, 30 Jul 2009)
Log Message:
-----------
use Comparable instead of Object
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2009-07-30 04:32:24 UTC (rev 1238)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/BloatedAssignmentScope.java 2009-07-30 04:39:50 UTC (rev 1239)
@@ -46,28 +46,28 @@
* the assignment can be pushed down into the smaller scope to reduce the performance
* impact of that assignment.
*/
-public class BloatedAssignmentScope extends BytecodeScanningDetector
+public class BloatedAssignmentScope extends BytecodeScanningDetector
{
BugReporter bugReporter;
private OpcodeStack stack;
private Set<Integer> ignoreRegs;
private ScopeBlock rootScopeBlock;
- private Set<Integer> catchHandlers;
- private Set<Integer> switchTargets;
- private List<Integer> monitorSyncPCs;
- private boolean dontReport;
- private boolean sawDup;
- private boolean sawNull;
-
+ private Set<Integer> catchHandlers;
+ private Set<Integer> switchTargets;
+ private List<Integer> monitorSyncPCs;
+ private boolean dontReport;
+ private boolean sawDup;
+ private boolean sawNull;
+
/**
- * constructs a BAS detector given the reporter to report bugs on
+ * constructs a BAS detector given the reporter to report bugs on
- * @param bugReporter the sync of bug reports
- */
+ * @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
*
@@ -77,20 +77,20 @@
public void visitClassContext(ClassContext classContext) {
try {
ignoreRegs = new HashSet<Integer>();
- catchHandlers = new HashSet<Integer>();
- switchTargets = new HashSet<Integer>();
- monitorSyncPCs = new ArrayList<Integer>();
- stack = new OpcodeStack();
+ catchHandlers = new HashSet<Integer>();
+ switchTargets = new HashSet<Integer>();
+ monitorSyncPCs = new ArrayList<Integer>();
+ stack = new OpcodeStack();
super.visitClassContext(classContext);
} finally {
ignoreRegs = null;
- catchHandlers = null;
- switchTargets = null;
- monitorSyncPCs = null;
- stack = null;
+ catchHandlers = null;
+ switchTargets = null;
+ monitorSyncPCs = null;
+ stack = null;
}
}
-
+
/**
* implements the visitor to reset the register to location map
*
@@ -99,45 +99,45 @@
@Override
public void visitCode(Code obj) {
try {
-
+
ignoreRegs.clear();
Method method = getMethod();
if (!method.isStatic())
- {
- ignoreRegs.add(Integer14.valueOf(0));
- }
-
+ {
+ ignoreRegs.add(Integer14.valueOf(0));
+ }
+
int[] parmRegs = RegisterUtils.getParameterRegisters(method);
for (int parm : parmRegs) {
ignoreRegs.add(Integer14.valueOf(parm));
}
-
+
rootScopeBlock = new ScopeBlock(0, obj.getLength());
- catchHandlers.clear();
- CodeException[] exceptions = obj.getExceptionTable();
- if (exceptions != null) {
- for (CodeException ex : exceptions) {
- catchHandlers.add(Integer14.valueOf(ex.getHandlerPC()));
- }
- }
+ catchHandlers.clear();
+ CodeException[] exceptions = obj.getExceptionTable();
+ if (exceptions != null) {
+ for (CodeException ex : exceptions) {
+ catchHandlers.add(Integer14.valueOf(ex.getHandlerPC()));
+ }
+ }
- switchTargets.clear();
- stack.resetForMethodEntry(this);
- dontReport = false;
- sawDup = false;
- sawNull = false;
+ switchTargets.clear();
+ stack.resetForMethodEntry(this);
+ dontReport = false;
+ sawDup = false;
+ sawNull = false;
super.visitCode(obj);
-
- if (!dontReport)
- {
- rootScopeBlock.findBugs(new HashSet<Integer>());
- }
-
+
+ if (!dontReport)
+ {
+ rootScopeBlock.findBugs(new HashSet<Integer>());
+ }
+
} finally {
rootScopeBlock = null;
}
}
-
+
/**
* implements the visitor to look for variables assigned below the scope
* in which they are used.
@@ -146,258 +146,258 @@
*/
@Override
public void sawOpcode(int seen) {
- Object caller = null;
- try {
- if ((seen == ASTORE)
- || (seen == ISTORE)
- || (seen == LSTORE)
- || (seen == FSTORE)
- || (seen == DSTORE)
- || ((seen >= ASTORE_0) && (seen <= ASTORE_3))
- || ((seen >= ISTORE_0) && (seen <= ISTORE_3))
- || ((seen >= LSTORE_0) && (seen <= LSTORE_1))
- || ((seen >= FSTORE_0) && (seen <= FSTORE_1))
- || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) {
- int reg = RegisterUtils.getStoreReg(this, seen);
- Integer iReg = Integer14.valueOf(reg);
- int pc = getPC();
- if (catchHandlers.contains(Integer14.valueOf(pc)))
- {
- ignoreRegs.add(iReg);
- }
- else if (monitorSyncPCs.size() > 0)
- {
- ignoreRegs.add(iReg);
- }
- else if (sawNull)
- {
- ignoreRegs.add(iReg);
- }
-
- if (!ignoreRegs.contains(iReg)) {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
- if (sb != null) {
- Object assoc = null;
- if (stack.getStackDepth() > 0) {
- assoc = stack.getStackItem(0).getUserValue();
- }
- sb.addStore(reg, pc, assoc);
- if (sawDup)
- {
- sb.addLoad(reg, pc);
- }
- }
- else
- {
- ignoreRegs.add(iReg);
- }
- }
- } else if (seen == IINC) {
- int reg = getRegisterOperand();
- Integer iReg = Integer14.valueOf(reg);
- if (!ignoreRegs.contains(iReg)) {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
- if (sb != null)
- {
- sb.addLoad(reg, getPC());
- }
- else
- {
- ignoreRegs.add(iReg);
- }
- }
- int pc = getPC();
- if (catchHandlers.contains(Integer14.valueOf(pc)))
- {
- ignoreRegs.add(iReg);
- }
- else if (monitorSyncPCs.size() > 0)
- {
- ignoreRegs.add(iReg);
- }
- else if (sawNull)
- {
- ignoreRegs.add(iReg);
- }
-
- if (!ignoreRegs.contains(iReg)) {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
- if (sb != null) {
- sb.addStore(reg, pc, null);
- if (sawDup)
- {
- sb.addLoad(reg, pc);
- }
- }
- else
- {
- ignoreRegs.add(iReg);
- }
- }
- } else if ((seen == ALOAD)
- || (seen == ILOAD)
- || (seen == LLOAD)
- || (seen == FLOAD)
- || (seen == DLOAD)
- || ((seen >= ALOAD_0) && (seen <= ALOAD_3))
- || ((seen >= ILOAD_0) && (seen <= ILOAD_3))
- || ((seen >= LLOAD_0) && (seen <= LLOAD_1))
- || ((seen >= FLOAD_0) && (seen <= FLOAD_1))
- || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) {
- int reg = RegisterUtils.getLoadReg(this, seen);
- if (!ignoreRegs.contains(Integer14.valueOf(reg))) {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
- if (sb != null)
- {
- sb.addLoad(reg, getPC());
- }
- else
- {
- ignoreRegs.add(Integer14.valueOf(reg));
- }
- }
- } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) {
- int target = getBranchTarget();
- if (target > getPC()) {
- if ((seen == GOTO) || (seen == GOTO_W)) {
- Integer nextPC = Integer14.valueOf(getNextPC());
- if (!switchTargets.contains(nextPC)) {
- ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC());
- if (sb == null) {
- sb = new ScopeBlock(getPC(), target);
- sb.setLoop();
- sb.setGoto();
- rootScopeBlock.addChild(sb);
- } else {
- sb = new ScopeBlock(getPC(), target);
- sb.setGoto();
- rootScopeBlock.addChild(sb);
- }
- }
- } else {
- ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target);
- if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) {
- if (sb.isGoto()) {
- ScopeBlock parent = sb.getParent();
- sb.pushUpLoadStores();
- if (parent != null)
- {
- parent.removeChild(sb);
- }
- sb = new ScopeBlock(getPC(), target);
- rootScopeBlock.addChild(sb);
- } else {
- sb.pushUpLoadStores();
- sb.setStart(getPC());
- sb.setFinish(target);
- }
- } else {
- sb = new ScopeBlock(getPC(), target);
- rootScopeBlock.addChild(sb);
- }
- }
- } else {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
- if (sb != null)
- {
- sb.setLoop();
- }
- }
- } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) {
- int pc = getPC();
- int[] offsets = getSwitchOffsets();
- List<Integer> targets = new ArrayList<Integer>();
- for (int offset : offsets)
- {
- targets.add(Integer14.valueOf(offset + pc));
- }
- Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc);
- if (!targets.contains(defOffset))
- {
- targets.add(defOffset);
- }
- Collections.sort(targets);
-
- Integer lastTarget = targets.get(0);
- for (int i = 1; i < targets.size(); i++) {
- Integer nextTarget = targets.get(i);
- ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue());
- rootScopeBlock.addChild(sb);
- lastTarget = nextTarget;
- }
- switchTargets.addAll(targets);
- } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) {
- if ("wasNull".equals(getNameConstantOperand())
- && "()Z".equals(getSigConstantOperand()))
- {
- dontReport = true;
- }
-
- caller = getCallingObject();
-
- if (caller != null) {
- ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
- if (sb != null) {
- sb.removeByAssoc(caller);
- }
- }
-
- } else if (seen == MONITORENTER) {
- monitorSyncPCs.add(Integer14.valueOf(getPC()));
- } else if (seen == MONITOREXIT) {
- if (monitorSyncPCs.size() > 0)
- {
- monitorSyncPCs.remove(monitorSyncPCs.size() - 1);
- }
- }
-
- sawDup = (seen == DUP);
- sawNull = (seen == ACONST_NULL);
- } finally {
- stack.sawOpcode(this, seen);
- if (caller != null) {
- if (stack.getStackDepth() > 0) {
- OpcodeStack.Item item = stack.getStackItem(0);
- item.setUserValue(caller);
- }
- }
- }
+ Comparable<?> caller = null;
+ try {
+ if ((seen == ASTORE)
+ || (seen == ISTORE)
+ || (seen == LSTORE)
+ || (seen == FSTORE)
+ || (seen == DSTORE)
+ || ((seen >= ASTORE_0) && (seen <= ASTORE_3))
+ || ((seen >= ISTORE_0) && (seen <= ISTORE_3))
+ || ((seen >= LSTORE_0) && (seen <= LSTORE_1))
+ || ((seen >= FSTORE_0) && (seen <= FSTORE_1))
+ || ((seen >= DSTORE_0) && (seen <= DSTORE_1))) {
+ int reg = RegisterUtils.getStoreReg(this, seen);
+ Integer iReg = Integer14.valueOf(reg);
+ int pc = getPC();
+ if (catchHandlers.contains(Integer14.valueOf(pc)))
+ {
+ ignoreRegs.add(iReg);
+ }
+ else if (monitorSyncPCs.size() > 0)
+ {
+ ignoreRegs.add(iReg);
+ }
+ else if (sawNull)
+ {
+ ignoreRegs.add(iReg);
+ }
+
+ if (!ignoreRegs.contains(iReg)) {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
+ if (sb != null) {
+ Object assoc = null;
+ if (stack.getStackDepth() > 0) {
+ assoc = stack.getStackItem(0).getUserValue();
+ }
+ sb.addStore(reg, pc, assoc);
+ if (sawDup)
+ {
+ sb.addLoad(reg, pc);
+ }
+ }
+ else
+ {
+ ignoreRegs.add(iReg);
+ }
+ }
+ } else if (seen == IINC) {
+ int reg = getRegisterOperand();
+ Integer iReg = Integer14.valueOf(reg);
+ if (!ignoreRegs.contains(iReg)) {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
+ if (sb != null)
+ {
+ sb.addLoad(reg, getPC());
+ }
+ else
+ {
+ ignoreRegs.add(iReg);
+ }
+ }
+ int pc = getPC();
+ if (catchHandlers.contains(Integer14.valueOf(pc)))
+ {
+ ignoreRegs.add(iReg);
+ }
+ else if (monitorSyncPCs.size() > 0)
+ {
+ ignoreRegs.add(iReg);
+ }
+ else if (sawNull)
+ {
+ ignoreRegs.add(iReg);
+ }
+
+ if (!ignoreRegs.contains(iReg)) {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, pc);
+ if (sb != null) {
+ sb.addStore(reg, pc, null);
+ if (sawDup)
+ {
+ sb.addLoad(reg, pc);
+ }
+ }
+ else
+ {
+ ignoreRegs.add(iReg);
+ }
+ }
+ } else if ((seen == ALOAD)
+ || (seen == ILOAD)
+ || (seen == LLOAD)
+ || (seen == FLOAD)
+ || (seen == DLOAD)
+ || ((seen >= ALOAD_0) && (seen <= ALOAD_3))
+ || ((seen >= ILOAD_0) && (seen <= ILOAD_3))
+ || ((seen >= LLOAD_0) && (seen <= LLOAD_1))
+ || ((seen >= FLOAD_0) && (seen <= FLOAD_1))
+ || ((seen >= DLOAD_0) && (seen <= DLOAD_1))) {
+ int reg = RegisterUtils.getLoadReg(this, seen);
+ if (!ignoreRegs.contains(Integer14.valueOf(reg))) {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
+ if (sb != null)
+ {
+ sb.addLoad(reg, getPC());
+ }
+ else
+ {
+ ignoreRegs.add(Integer14.valueOf(reg));
+ }
+ }
+ } else if (((seen >= IFEQ) && (seen <= GOTO)) || (seen == GOTO_W)) {
+ int target = getBranchTarget();
+ if (target > getPC()) {
+ if ((seen == GOTO) || (seen == GOTO_W)) {
+ Integer nextPC = Integer14.valueOf(getNextPC());
+ if (!switchTargets.contains(nextPC)) {
+ ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), getNextPC());
+ if (sb == null) {
+ sb = new ScopeBlock(getPC(), target);
+ sb.setLoop();
+ sb.setGoto();
+ rootScopeBlock.addChild(sb);
+ } else {
+ sb = new ScopeBlock(getPC(), target);
+ sb.setGoto();
+ rootScopeBlock.addChild(sb);
+ }
+ }
+ } else {
+ ScopeBlock sb = findScopeBlockWithTarget(rootScopeBlock, getPC(), target);
+ if ((sb != null) && (!sb.isLoop) && !sb.hasChildren()) {
+ if (sb.isGoto()) {
+ ScopeBlock parent = sb.getParent();
+ sb.pushUpLoadStores();
+ if (parent != null)
+ {
+ parent.removeChild(sb);
+ }
+ sb = new ScopeBlock(getPC(), target);
+ rootScopeBlock.addChild(sb);
+ } else {
+ sb.pushUpLoadStores();
+ sb.setStart(getPC());
+ sb.setFinish(target);
+ }
+ } else {
+ sb = new ScopeBlock(getPC(), target);
+ rootScopeBlock.addChild(sb);
+ }
+ }
+ } else {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
+ if (sb != null)
+ {
+ sb.setLoop();
+ }
+ }
+ } else if ((seen == TABLESWITCH) || (seen == LOOKUPSWITCH)) {
+ int pc = getPC();
+ int[] offsets = getSwitchOffsets();
+ List<Integer> targets = new ArrayList<Integer>();
+ for (int offset : offsets)
+ {
+ targets.add(Integer14.valueOf(offset + pc));
+ }
+ Integer defOffset = Integer14.valueOf(getDefaultSwitchOffset() + pc);
+ if (!targets.contains(defOffset))
+ {
+ targets.add(defOffset);
+ }
+ Collections.sort(targets);
+
+ Integer lastTarget = targets.get(0);
+ for (int i = 1; i < targets.size(); i++) {
+ Integer nextTarget = targets.get(i);
+ ScopeBlock sb = new ScopeBlock(lastTarget.intValue(), nextTarget.intValue());
+ rootScopeBlock.addChild(sb);
+ lastTarget = nextTarget;
+ }
+ switchTargets.addAll(targets);
+ } else if ((seen == INVOKEVIRTUAL) || (seen == INVOKEINTERFACE)) {
+ if ("wasNull".equals(getNameConstantOperand())
+ && "()Z".equals(getSigConstantOperand()))
+ {
+ dontReport = true;
+ }
+
+ caller = getCallingObject();
+
+ if (caller != null) {
+ ScopeBlock sb = findScopeBlock(rootScopeBlock, getPC());
+ if (sb != null) {
+ sb.removeByAssoc(caller);
+ }
+ }
+
+ } else if (seen == MONITORENTER) {
+ monitorSyncPCs.add(Integer14.valueOf(getPC()));
+ } else if (seen == MONITOREXIT) {
+ if (monitorSyncPCs.size() > 0)
+ {
+ monitorSyncPCs.remove(monitorSyncPCs.size() - 1);
+ }
+ }
+
+ sawDup = (seen == DUP);
+ sawNull = (seen == ACONST_NULL);
+ } finally {
+ stack.sawOpcode(this, seen);
+ if (caller != null) {
+ if (stack.getStackDepth() > 0) {
+ OpcodeStack.Item item = stack.getStackItem(0);
+ item.setUserValue(caller);
+ }
+ }
+ }
}
-
+
/**
* returns either a register number of a field reference of the object that a method is being called on,
* or null, if it can't be determined.
*
* @return either an Integer for a register, or a String for the field name, or null
*/
- private Object getCallingObject() {
- String sig = getSigConstantOperand();
- if ("V".equals(Type.getReturnType(sig).getSignature()))
- {
- return null;
- }
-
- Type[] types = Type.getArgumentTypes(sig);
- if (stack.getStackDepth() <= types.length) {
- return null;
- }
-
- OpcodeStack.Item caller = stack.getStackItem(types.length);
- int reg = caller.getRegisterNumber();
- if (reg >= 0)
- {
- return Integer.valueOf(reg);
- }
-
- /* We ignore the possibility of two fields with the same name in different classes */
- XField f = caller.getXField();
- if (f != null)
- {
- return f.getName();
- }
- return null;
+ private Comparable<?> getCallingObject() {
+ String sig = getSigConstantOperand();
+ if ("V".equals(Type.getReturnType(sig).getSignature()))
+ {
+ return null;
+ }
+
+ Type[] types = Type.getArgumentTypes(sig);
+ if (stack.getStackDepth() <= types.length) {
+ return null;
+ }
+
+ OpcodeStack.Item caller = stack.getStackItem(types.length);
+ int reg = caller.getRegisterNumber();
+ if (reg >= 0)
+ {
+ return Integer.valueOf(reg);
+ }
+
+ /* We ignore the possibility of two fields with the same name in different classes */
+ XField f = caller.getXField();
+ if (f != null)
+ {
+ return f.getName();
+ }
+ return null;
}
- /**
+ /**
* returns the scope block in which this register was assigned, by traversing the scope block tree
*
* @param sb the scope block to start searching in
@@ -405,22 +405,22 @@
* @return the scope block or null if not found
*/
private ScopeBlock findScopeBlock(ScopeBlock sb, int pc) {
-
+
if ((pc > sb.getStart()) && (pc < sb.getFinish())) {
if (sb.children != null) {
for (ScopeBlock child : sb.children) {
ScopeBlock foundSb = findScopeBlock(child, pc);
if (foundSb != null)
- {
- return foundSb;
- }
+ {
+ return foundSb;
+ }
}
}
return sb;
}
return null;
}
-
+
/**
* returns an existing scope block that has the same target as the one looked for
*
@@ -430,28 +430,28 @@
* @return the scope block found or null
*/
private ScopeBlock findScopeBlockWithTarget(ScopeBlock sb, int start, int target) {
- ScopeBlock parentBlock = null;
+ ScopeBlock parentBlock = null;
if ((sb.startLocation < start) && (sb.finishLocation >= start)) {
- if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop()))
- {
- parentBlock = sb;
- }
- }
-
+ if ((sb.finishLocation <= target) || (sb.isGoto() && !sb.isLoop()))
+ {
+ parentBlock = sb;
+ }
+ }
+
if (sb.children != null)
{
for (ScopeBlock child : sb.children) {
ScopeBlock targetBlock = findScopeBlockWithTarget(child, start, target);
if (targetBlock != null)
- {
- return targetBlock;
- }
+ {
+ return targetBlock;
+ }
}
}
-
+
return parentBlock;
}
-
+
/** holds the description of a scope { } block, be it a for, if, while block
*/
private class ScopeBlock
@@ -460,12 +460,12 @@
private int startLocation;
private int finishLocation;
private boolean isLoop;
- private boolean isGoto;
+ private boolean isGoto;
private Map<Integer, Integer> loads;
private Map<Integer, Integer> stores;
private Map<Object, Integer> assocs;
private List<ScopeBlock> children;
-
+
/** construts a new scope block
*
* @param start the beginning of the block
@@ -476,13 +476,13 @@
startLocation = start;
finishLocation = finish;
isLoop = false;
- isGoto = false;
+ isGoto = false;
loads = null;
stores = null;
assocs = null;
children = null;
}
-
+
/**
* returns a string representation of the scope block
*
@@ -492,16 +492,16 @@
public String toString() {
return "Start=" + startLocation + " Finish=" + finishLocation + " Loop=" + isLoop + " Loads=" + loads + " Stores=" + stores;
}
-
- /**
- * returns the scope blocks parent
- *
- * @return the parent of this scope block
- */
- public ScopeBlock getParent() {
- return parent;
- }
-
+
+ /**
+ * returns the scope blocks parent
+ *
+ * @return the parent of this scope block
+ */
+ public ScopeBlock getParent() {
+ return parent;
+ }
+
/** returns the start of the block
*
* @return the start of the block
@@ -517,59 +517,59 @@
public int getFinish() {
return finishLocation;
}
-
- /**
- * sets the start pc of the block
- * @param start the start pc
- */
- public void setStart(int start) {
- startLocation = start;
- }
-
- /**
- * sets the finish pc of the block
- * @param finish the finish pc
- */
- public void setFinish(int finish) {
- finishLocation = finish;
- }
- public boolean hasChildren() {
- return children != null;
- }
/**
+ * sets the start pc of the block
+ * @param start the start pc
+ */
+ public void setStart(int start) {
+ startLocation = start;
+ }
+
+ /**
+ * sets the finish pc of the block
+ * @param finish the finish pc
+ */
+ public void setFinish(int finish) {
+ finishLocation = finish;
+ }
+
+ public boolean hasChildren() {
+ return children != null;
+ }
+ /**
* sets that this block is a loop
*/
public void setLoop() {
isLoop = true;
}
-
- /**
- * returns whether this scope block is a loop
- *
- * @returns whether this block is a loop
- */
- public boolean isLoop() {
- return isLoop;
- }
-
- /**
- * sets that this block was caused from a goto, (an if block exit)
- */
- public void setGoto() {
- isGoto = true;
- }
-
- /**
- * returns whether this block was caused from a goto
- *
- * @returns whether this block was caused by a goto
- */
- public boolean isGoto() {
- return isGoto;
- }
/**
+ * returns whether this scope block is a loop
+ *
+ * @returns whether this block is a loop
+ */
+ public boolean isLoop() {
+ return isLoop;
+ }
+
+ /**
+ * sets that this block was caused from a goto, (an if block exit)
+ */
+ public void setGoto() {
+ isGoto = true;
+ }
+
+ /**
+ * returns whether this block was caused from a goto
+ *
+ * @returns whether this block was caused by a goto
+ */
+ public boolean isGoto() {
+ return isGoto;
+ }
+
+ /**
* adds the register as a store in this scope block
*
* @param reg the register that was stored
@@ -577,37 +577,37 @@
*/
public void addStore(int reg, int pc, Object assocObject) {
if (stores == null)
- {
- stores = new HashMap<Integer, Integer>();
- }
-
+ {
+ stores = new HashMap<Integer, Integer>();
+ }
+
stores.put(Integer14.valueOf(reg), Integer14.valueOf(pc));
if (assocs == null)
- {
- assocs = new HashMap<Object, Integer>();
- }
+ {
+ assocs = new HashMap<Object, Integer>();
+ }
assocs.put(assocObject, Integer14.valueOf(reg));
}
-
- /**
+
+ /**
* removes stores to registers that where retrieved from method calls on assocObject
*
* @param assocObject the object that a method call was just performed on
*/
public void removeByAssoc(Object assocObject) {
- if (assocs != null) {
- Integer reg = assocs.remove(assocObject);
- if (reg != null) {
- if (loads != null) {
- loads.remove(reg);
- }
- if (stores != null) {
- stores.remove(reg);
- }
- }
- }
+ if (assocs != null) {
+ Integer reg = assocs.remove(assocObject);
+ if (reg != null) {
+ if (loads != null) {
+ loads.remove(reg);
+ }
+ if (stores != null) {
+ stores.remove(reg);
+ }
+ }
+ }
}
-
+
/**
* adds the register as a load in this scope block
*
@@ -616,13 +616,13 @@
*/
public void addLoad(int reg, int pc) {
if (loads == null)
- {
- loads = new HashMap<Integer, Integer>();
- }
-
+ {
+ loads = new HashMap<Integer, Integer>();
+ }
+
loads.put(Integer14.valueOf(reg), Integer14.valueOf(pc));
}
-
+
/**
* adds a scope block to this subtree by finding the correct place in the hierarchy to store it
*
@@ -652,77 +652,77 @@
children = new ArrayList<ScopeBlock>();
children.add(newChild);
}
-
- /**
- * removes a child from this node
- * @param child the child to remove
- */
- public void removeChild(ScopeBlock child) {
- if (children != null)
- {
- children.remove(child);
- }
- }
-
+
/**
+ * removes a child from this node
+ * @param child the child to remove
+ */
+ public void removeChild(ScopeBlock child) {
+ if (children != null)
+ {
+ children.remove(child);
+ }
+ }
+
+ /**
* report stores that occur at scopes higher than associated loads that are not involved with loops
*/
public void findBugs(Set<Integer> parentUsedRegs) {
if (isLoop)
- {
- return;
- }
-
- Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs);
- if (stores != null)
- {
- usedRegs.addAll(stores.keySet());
- }
- if (loads != null)
- {
- usedRegs.addAll(loads.keySet());
- }
-
+ {
+ return;
+ }
+
+ Set<Integer> usedRegs = new HashSet<Integer>(parentUsedRegs);
+ if (stores != null)
+ {
+ usedRegs.addAll(stores.keySet());
+ }
+ if (loads != null)
+ {
+ usedRegs.addAll(loads.keySet());
+ }
+
if (stores != null) {
if (loads != null)
- {
- stores.keySet().removeAll(loads.keySet());
- }
- stores.keySet().removeAll(parentUsedRegs);
-
- if (stores.size() > 0) {
- if (children != null) {
- for (Map.Entry<Integer, Integer> entry : stores.entrySet()) {
- int childUseCount = 0;
- boolean inLoop = false;
- Integer reg = entry.getKey();
- for (ScopeBlock child : children) {
- if (child.usesReg(reg)) {
- if (child.isLoop) {
- inLoop = true;
- break;
- }
- childUseCount++;
- }
- }
- if ((!inLoop) && (childUseCount == 1)) {
- bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY)
- .addClass(BloatedAssignmentScope.this)
- .addMethod(BloatedAssignmentScope.this)
- .addSourceLine(BloatedAssignmentScope.this, entry.getValue().intValue()));
- }
- }
- }
- }
+ {
+ stores.keySet().removeAll(loads.keySet());
+ }
+ stores.keySet().removeAll(parentUsedRegs);
+
+ if (stores.size() > 0) {
+ if (children != null) {
+ for (Map.Entry<Integer, Integer> entry : stores.entrySet()) {
+ int childUseCount = 0;
+ boolean inLoop = false;
+ Integer reg = entry.getKey();
+ for (ScopeBlock child : children) {
+ if (child.usesReg(reg)) {
+ if (child.isLoop) {
+ inLoop = true;
+ break;
+ }
+ childUseCount++;
+ }
+ }
+ if ((!inLoop) && (childUseCount == 1)) {
+ bugReporter.reportBug(new BugInstance(BloatedAssignmentScope.this, "BAS_BLOATED_ASSIGNMENT_SCOPE", NORMAL_PRIORITY)
+ .addClass(BloatedAssignmentScope.this)
+ .addMethod(BloatedAssignmentScope.this)
+ .addSourceLine(BloatedAssignmentScope.this, entry.getValue().intValue()));
+ }
+ }
+ }
+ }
}
-
+
if (children != null) {
for (ScopeBlock child : children) {
child.findBugs(usedRegs);
}
}
}
-
+
/**
* returns whether this block either loads or stores into the register in question
*
@@ -732,26 +732,26 @@
*/
public boolean usesReg(Integer reg) {
if ((loads != null) && (loads.containsKey(reg)))
- {
- return true;
- }
+ {
+ return true;
+ }
if ((stores != null) && (stores.containsKey(reg)))
- {
- return true;
- }
-
+ {
+ return true;
+ }
+
if (children != null) {
for (ScopeBlock child : children) {
if (child.usesReg(reg))
- {
- return true;
- }
+ {
+ return true;
+ }
}
}
-
+
return false;
}
-
+
/**
* push all loads and stores to this block up to the parent
*/
@@ -759,23 +759,23 @@
if (parent != null) {
if (loads != null) {
if (parent.loads != null)
- {
- parent.loads.putAll(loads);
- }
- else
- {
- parent.loads = loads;
- }
+ {
+ parent.loads.putAll(loads);
+ }
+ else
+ {
+ parent.loads = loads;
+ }
}
if (stores != null) {
if (parent.stores != null)
- {
- parent.stores.putAll(stores);
- }
- else
- {
- parent.stores = stores;
- }
+ {
+ parent.stores.putAll(stores);
+ }
+ else
+ {
+ parent.stores = stores;
+ }
}
loads = null;
stores = null;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|