Skip to content

Commit

Permalink
cache post dom map of whole methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielFi committed Dec 8, 2023
1 parent e02adab commit cbd443b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
12 changes: 12 additions & 0 deletions jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package jadx.core.dex.nodes;

import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -73,6 +75,7 @@ public class MethodNode extends NotificationAttrNode implements IMethodDetails,
private int blocksMaxCId;
private BlockNode enterBlock;
private BlockNode exitBlock;
private Map<BlockNode, BitSet> postDominanceMap;
private List<SSAVar> sVars;
private List<ExceptionHandler> exceptionHandlers;
private List<LoopInfo> loops;
Expand Down Expand Up @@ -119,6 +122,7 @@ public void unload() {
blocks = null;
enterBlock = null;
exitBlock = null;
postDominanceMap = null;
region = null;
exceptionHandlers = Collections.emptyList();
loops = Collections.emptyList();
Expand Down Expand Up @@ -399,6 +403,14 @@ public boolean isPreExitBlocks(BlockNode block) {
return exitBlock.getPredecessors().contains(block);
}

public Map<BlockNode, BitSet> getPostDominanceMap() {
return postDominanceMap;
}

public void setPostDominanceMap(Map<BlockNode, BitSet> postDominanceMap) {
this.postDominanceMap = postDominanceMap;
}

public void registerLoop(LoopInfo loop) {
if (loops.isEmpty()) {
loops = new ArrayList<>(5);
Expand Down
7 changes: 6 additions & 1 deletion jadx-core/src/main/java/jadx/core/utils/BlockUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,12 @@ public static boolean replaceInsn(MethodNode mth, InsnNode oldInsn, InsnNode new
}

public static Map<BlockNode, BitSet> calcPostDominance(MethodNode mth) {
return calcPartialPostDominance(mth, mth.getBasicBlocks(), mth.getPreExitBlocks().get(0));
Map<BlockNode, BitSet> postDominanceMap = mth.getPostDominanceMap();
if (postDominanceMap == null) {
postDominanceMap = calcPartialPostDominance(mth, mth.getBasicBlocks(), mth.getPreExitBlocks().get(0));
mth.setPostDominanceMap(postDominanceMap);
}
return postDominanceMap;
}

public static Map<BlockNode, BitSet> calcPartialPostDominance(MethodNode mth, Collection<BlockNode> blockNodes, BlockNode exitBlock) {
Expand Down

0 comments on commit cbd443b

Please sign in to comment.