Skip to content

Commit

Permalink
fix spotbugs#601: stop updating global var, use local var to store te…
Browse files Browse the repository at this point in the history
…mporal debug flag
  • Loading branch information
KengoTODA authored and RahulNagekar committed Dec 3, 2018
1 parent 4621a22 commit 60d3619
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ Currently the versioning policy of this project follows [Semantic Versioning v2.
## Unreleased - 2018-??-??
* Start migrating STDOUT/STDERR usage to a logging framework

### Fixed
* Dataflow generates too much log ([#601](https://github.com/spotbugs/spotbugs/issues/601))

## 3.1.9 - 2018-11-20

### Fixed
Expand Down
45 changes: 22 additions & 23 deletions spotbugs/src/main/java/edu/umd/cs/findbugs/ba/Dataflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public int compare(BasicBlock o1, BasicBlock o2) {
*/
public void execute() throws DataflowAnalysisException {
boolean change;
boolean debugWas = DEBUG;
if (DEBUG) {
boolean debug = DEBUG;
if (debug) {
reportAnalysis("Executing");
}

Expand All @@ -152,8 +152,8 @@ public void execute() throws DataflowAnalysisException {
change = false;
boolean sawBackEdge = false;
++numIterations;
if (numIterations > MAX_ITERS && !DEBUG) {
DEBUG = true;
if (numIterations > MAX_ITERS && !debug) {
debug = true;
reportAnalysis("Too many iterations");
System.out.println(this.getClass().getName());
if (this.getClass() == UnconditionalValueDerefDataflow.class || this.getClass() == LiveLocalStoreDataflow.class) {
Expand All @@ -175,7 +175,7 @@ public void execute() throws DataflowAnalysisException {
}
}

if (DEBUG) {
if (debug) {
System.out.println("----------------------------------------------------------------------");
System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
MethodGen mg = cfg.getMethodGen();
Expand All @@ -191,7 +191,7 @@ public void execute() throws DataflowAnalysisException {

analysis.startIteration();

if (DEBUG && firstTime && blockOrder instanceof ReverseDFSOrder) {
if (debug && firstTime && blockOrder instanceof ReverseDFSOrder) {
ReverseDFSOrder rBlockOrder = (ReverseDFSOrder) blockOrder;
System.out.println("Entry point is: " + logicalEntryBlock());
System.out.println("Basic block order: ");
Expand All @@ -204,7 +204,7 @@ public void execute() throws DataflowAnalysisException {
}
Iterator<BasicBlock> i = blockOrder.blockIterator();
if (numIterations > 3 && numIterations % 2 == 0 && blockOrder instanceof ReverseDFSOrder) {
if (DEBUG) {
if (debug) {
System.out.println("Trying program order");
}
TreeSet<BasicBlock> bb = new TreeSet<>(new BackwardProgramOrder());
Expand All @@ -213,14 +213,14 @@ public void execute() throws DataflowAnalysisException {
BasicBlock block = j.next();
bb.add(block);
}
if (DEBUG) {
if (debug) {
for (BasicBlock block : bb) {
debug(block, "\n");
}
}
i = bb.iterator();
}
if (DEBUG) {
if (debug) {
dumpDataflow(analysis);
}

Expand Down Expand Up @@ -248,7 +248,7 @@ public void execute() throws DataflowAnalysisException {
if (block == logicalEntryBlock()) {
analysis.makeFactTop(start);
analysis.initEntryFact(start);
if (DEBUG) {
if (debug) {
debug(block, "Init entry fact ==> " + analysis.factToString(start) + "\n");
}
needToRecompute = true;
Expand All @@ -274,7 +274,7 @@ public void execute() throws DataflowAnalysisException {

int direction = blockOrder.compare(block, logicalPred);

if (DEBUG) {
if (debug) {
debug(block, "direction " + direction + " for " + blockId(logicalPred) + "\n");
}
if (direction < 0) {
Expand All @@ -289,7 +289,7 @@ public void execute() throws DataflowAnalysisException {
if (predLastUpdated >= lastCalculated) {

needToRecompute = true;
if (DEBUG) {
if (debug) {
debug(block, "\n Need to recompute. My timestamp = " + lastCalculated + ", pred timestamp = "
+ predLastUpdated + ",\n pred fact = " + predFact + "\n");
}
Expand Down Expand Up @@ -319,15 +319,15 @@ public void execute() throws DataflowAnalysisException {
analysis.copy(predFact, edgeFact);
analysis.edgeTransfer(edge, edgeFact);

if (DEBUG && !analysis.same(edgeFact, predFact)) {
if (debug && !analysis.same(edgeFact, predFact)) {
debug(block, logicalPred, edge, "Edge transfer " + analysis.factToString(predFact) + " ==> "
+ analysis.factToString(edgeFact));
}

// Merge the predecessor fact (possibly transformed
// by the edge transfer function)
// into the block's start fact.
if (DEBUG) {
if (debug) {
if (analysis.isTop(start)) {
debug(block, logicalPred, edge, "\n First pred is " + analysis.factToString(edgeFact)
+ "\n last updated at " + analysis.getLastUpdateTimestamp(predFact) + "\n");
Expand All @@ -351,13 +351,13 @@ public void execute() throws DataflowAnalysisException {
if (block.getFirstInstruction() != null) {
pos = block.getFirstInstruction().getPosition();
}
if (DEBUG) {
if (debug) {
System.out.println(" [" + pos + "]==> " + analysis.factToString(start) + " @ " + timestamp
+ " \n");
}
}
}
if (DEBUG) {
if (debug) {
debug(block, "start fact is " + analysis.factToString(start) + "\n");
}

Expand All @@ -378,7 +378,7 @@ public void execute() throws DataflowAnalysisException {
// analysis.copy(start, result);
// }

if (DEBUG && SystemProperties.getBoolean("dataflow.blockdebug")) {
if (debug && SystemProperties.getBoolean("dataflow.blockdebug")) {
debug(block, "Dumping flow values for block:\n");
Iterator<InstructionHandle> ii = block.instructionIterator();
while (ii.hasNext()) {
Expand All @@ -390,7 +390,7 @@ public void execute() throws DataflowAnalysisException {
}

// See if the result changed.
if (DEBUG) {
if (debug) {
debug(block, "orig result is " + (origResult == null ? "TOP" : analysis.factToString(origResult)) + "\n");
}
boolean thisResultChanged = false;
Expand All @@ -401,10 +401,10 @@ public void execute() throws DataflowAnalysisException {
}
if (thisResultChanged) {
timestamp++;
if (DEBUG) {
if (debug) {
debug(block, "result changed at timestamp " + timestamp + "\n");
}
if (DEBUG && !needToRecompute) {
if (debug && !needToRecompute) {
System.out.println("I thought I didn't need to recompute");
}
change = true;
Expand All @@ -413,7 +413,7 @@ public void execute() throws DataflowAnalysisException {
analysis.setLastUpdateTimestamp(result, originalResultTimestamp);
}

if (DEBUG) {
if (debug) {
debug(block,
"result is " + analysis.factToString(result) + " @ timestamp "
+ analysis.getLastUpdateTimestamp(result) + "\n");
Expand All @@ -427,7 +427,7 @@ public void execute() throws DataflowAnalysisException {

} while (change);

if (DEBUG) {
if (debug) {
System.out.println("-- Quiescence achieved-------------------------------------------------");
System.out.println(this.getClass().getName() + " iteration: " + numIterations + ", timestamp: " + timestamp);
MethodGen mg = cfg.getMethodGen();
Expand All @@ -436,7 +436,6 @@ public void execute() throws DataflowAnalysisException {
.printStackTrace(System.out);

}
DEBUG = debugWas;
}

private void reportAnalysis(String msg) {
Expand Down

0 comments on commit 60d3619

Please sign in to comment.