Skip to content

Commit

Permalink
fix(SimpleLocalDefs): thread safe support
Browse files Browse the repository at this point in the history
  • Loading branch information
notify committed Oct 14, 2024
1 parent df366fb commit e2d9ded
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions src/main/java/soot/toolkits/scalar/SimpleLocalDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.google.common.collect.Maps;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
Expand Down Expand Up @@ -309,7 +310,7 @@ public enum FlowAnalysisMode {
}

private final LocalDefs def;

private Map<Local, Integer> localNumberMap;
/**
*
* @param graph
Expand Down Expand Up @@ -337,12 +338,11 @@ public SimpleLocalDefs(UnitGraph graph, FlowAnalysisMode mode) {
}

// reassign local numbers
int[] oldNumbers = assignNumbers(locals);
this.localNumberMap = number2index(locals);

this.def = init(graph, locals, mode);

// restore local numbering
restoreNumbers(locals, oldNumbers);
this.localNumberMap = null;

if (time) {
Timers.v().defsTimer.end();
Expand All @@ -355,14 +355,13 @@ protected void restoreNumbers(Local[] locals, int[] oldNumbers) {
}
}

protected int[] assignNumbers(Local[] locals) {
protected Map<Local, Integer> number2index(Local[] locals) {
final int N = locals.length;
int[] oldNumbers = new int[N];
Map<Local, Integer> localNumberMap = Maps.newHashMapWithExpectedSize(N);
for (int i = 0; i < N; i++) {
oldNumbers[i] = locals[i].getNumber();
locals[i].setNumber(i);
localNumberMap.put(locals[i], i);
}
return oldNumbers;
return localNumberMap;
}

protected LocalDefs init(DirectedGraph<Unit> graph, Local[] locals, FlowAnalysisMode mode) {
Expand Down Expand Up @@ -415,7 +414,7 @@ protected LocalDefs init(DirectedGraph<Unit> graph, Local[] locals, FlowAnalysis

// Is protected so that in case we have a smarter implementation we can use it.
protected int getLocalNumber(Local l) {
return l.getNumber();
return localNumberMap.get(l);
}

@Override
Expand Down

0 comments on commit e2d9ded

Please sign in to comment.