提交 a4632d6e 编写于 作者: S Skylot

core: fix high memory usage while process conditions

上级 2a3162f8
......@@ -3,8 +3,6 @@ package jadx.core.dex.regions.conditions;
import jadx.core.dex.nodes.BlockNode;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public final class IfInfo {
......@@ -12,13 +10,13 @@ public final class IfInfo {
private final Set<BlockNode> mergedBlocks;
private final BlockNode thenBlock;
private final BlockNode elseBlock;
private final List<BlockNode> skipBlocks;
private final Set<BlockNode> skipBlocks;
private BlockNode outBlock;
@Deprecated
private BlockNode ifBlock;
public IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock) {
this(condition, thenBlock, elseBlock, new HashSet<BlockNode>(), new LinkedList<BlockNode>());
this(condition, thenBlock, elseBlock, new HashSet<BlockNode>(), new HashSet<BlockNode>());
}
public IfInfo(IfCondition condition, IfInfo info) {
......@@ -30,7 +28,7 @@ public final class IfInfo {
}
private IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock,
Set<BlockNode> mergedBlocks, List<BlockNode> skipBlocks) {
Set<BlockNode> mergedBlocks, Set<BlockNode> skipBlocks) {
this.condition = condition;
this.thenBlock = thenBlock;
this.elseBlock = elseBlock;
......@@ -47,6 +45,13 @@ public final class IfInfo {
return tmpIf;
}
public void merge(IfInfo... arr) {
for (IfInfo info : arr) {
mergedBlocks.addAll(info.getMergedBlocks());
skipBlocks.addAll(info.getSkipBlocks());
}
}
public IfCondition getCondition() {
return condition;
}
......@@ -55,6 +60,10 @@ public final class IfInfo {
return mergedBlocks;
}
public Set<BlockNode> getSkipBlocks() {
return skipBlocks;
}
public BlockNode getThenBlock() {
return thenBlock;
}
......@@ -71,10 +80,6 @@ public final class IfInfo {
this.outBlock = outBlock;
}
public List<BlockNode> getSkipBlocks() {
return skipBlocks;
}
public BlockNode getIfBlock() {
return ifBlock;
}
......
......@@ -190,12 +190,7 @@ public class IfMakerHelper {
nextThen.getCondition(), nextElse.getCondition());
IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock());
result.setIfBlock(currentIf.getIfBlock());
result.getMergedBlocks().addAll(currentIf.getMergedBlocks());
result.getMergedBlocks().addAll(nextThen.getMergedBlocks());
result.getMergedBlocks().addAll(nextElse.getMergedBlocks());
result.getSkipBlocks().addAll(currentIf.getSkipBlocks());
result.getSkipBlocks().addAll(nextThen.getSkipBlocks());
result.getSkipBlocks().addAll(nextElse.getSkipBlocks());
result.merge(currentIf, nextThen, nextElse);
confirmMerge(result);
return result;
}
......@@ -215,10 +210,7 @@ public class IfMakerHelper {
IfCondition condition = IfCondition.merge(mergeOperation, first.getCondition(), second.getCondition());
IfInfo result = new IfInfo(condition, second);
result.setIfBlock(first.getIfBlock());
result.getMergedBlocks().addAll(first.getMergedBlocks());
result.getMergedBlocks().addAll(second.getMergedBlocks());
result.getSkipBlocks().addAll(first.getSkipBlocks());
result.getSkipBlocks().addAll(second.getSkipBlocks());
result.merge(first, second);
BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock();
skipSimplePath(otherPathBlock, result.getSkipBlocks());
......@@ -303,7 +295,7 @@ public class IfMakerHelper {
return null;
}
private static void skipSimplePath(BlockNode block, List<BlockNode> skipped) {
private static void skipSimplePath(BlockNode block, Set<BlockNode> skipped) {
while (block != null
&& block.getCleanSuccessors().size() < 2
&& block.getPredecessors().size() == 1) {
......
package jadx.tests.internal.conditions;
import jadx.api.InternalJadxTest;
import jadx.core.dex.nodes.ClassNode;
import org.junit.Test;
import static jadx.tests.utils.JadxMatchers.containsOne;
import static org.junit.Assert.assertThat;
public class TestConditions15 extends InternalJadxTest {
public static class TestCls {
private static boolean test(final String name) {
if (isEmpty(name)) {
return false;
}
if ("1".equals(name)
|| "2".equals(name)
|| "3".equals(name)
|| "4".equals(name)
|| "5".equals(name)
|| "6".equals(name)
|| "7".equals(name)
|| "8".equals(name)
|| "9".equals(name)
|| "10".equals(name)
|| "11".equals(name)
|| "12".equals(name)
|| "13".equals(name)
|| "14".equals(name)
|| "15".equals(name)
|| "16".equals(name)
|| "17".equals(name)
|| "18".equals(name)
|| "19".equals(name)
|| "20".equals(name)
|| "22".equals(name)
|| "22".equals(name)
|| "23".equals(name)
|| "24".equals(name)
|| "25".equals(name)
|| "26".equals(name)
|| "27".equals(name)
|| "28".equals(name)
|| "29".equals(name)
|| "30".equals(name)) {
return false;
} else {
return true;
}
}
private static boolean isEmpty(String name) {
return name.isEmpty();
}
}
@Test
public void test() {
ClassNode cls = getClassNode(TestCls.class);
String code = cls.getCode().toString();
System.out.println(code);
assertThat(code, containsOne("\"1\".equals(name)"));
assertThat(code, containsOne("\"30\".equals(name)"));
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册