fix(cli): improve memory usage in jadx-cli (#2524)
This commit is contained in:
@@ -11,6 +11,7 @@ import jadx.api.JadxDecompiler;
|
||||
import jadx.api.impl.AnnotatedCodeWriter;
|
||||
import jadx.api.impl.NoOpCodeCache;
|
||||
import jadx.api.impl.SimpleCodeWriter;
|
||||
import jadx.api.usage.impl.EmptyUsageInfoCache;
|
||||
import jadx.cli.LogHelper.LogLevelEnum;
|
||||
import jadx.cli.plugins.JadxFilesGetter;
|
||||
import jadx.core.utils.exceptions.JadxArgsValidateException;
|
||||
@@ -57,6 +58,7 @@ public class JadxCLI {
|
||||
LogHelper.setLogLevelsForLoadingStage();
|
||||
JadxArgs jadxArgs = cliArgs.toJadxArgs();
|
||||
jadxArgs.setCodeCache(new NoOpCodeCache());
|
||||
jadxArgs.setUsageInfoCache(new EmptyUsageInfoCache());
|
||||
jadxArgs.setPluginLoader(new JadxExternalPluginsLoader());
|
||||
jadxArgs.setFilesGetter(JadxFilesGetter.INSTANCE);
|
||||
initCodeWriterProvider(jadxArgs);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package jadx.core.dex.attributes.nodes;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import jadx.api.CommentsLevel;
|
||||
@@ -30,10 +31,10 @@ public class JadxCommentsAttr implements IJadxAttribute {
|
||||
return newAttr;
|
||||
}
|
||||
|
||||
private final Map<CommentsLevel, List<String>> comments = new EnumMap<>(CommentsLevel.class);
|
||||
private final Map<CommentsLevel, Set<String>> comments = new EnumMap<>(CommentsLevel.class);
|
||||
|
||||
public void add(CommentsLevel level, String comment) {
|
||||
comments.computeIfAbsent(level, l -> new ArrayList<>()).add(comment);
|
||||
comments.computeIfAbsent(level, l -> new HashSet<>()).add(comment);
|
||||
}
|
||||
|
||||
public List<String> formatAndFilter(CommentsLevel level) {
|
||||
@@ -47,12 +48,11 @@ public class JadxCommentsAttr implements IJadxAttribute {
|
||||
return e.getValue().stream()
|
||||
.map(v -> "JADX " + levelName + ": " + v);
|
||||
})
|
||||
.distinct()
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public Map<CommentsLevel, List<String>> getComments() {
|
||||
public Map<CommentsLevel, Set<String>> getComments() {
|
||||
return comments;
|
||||
}
|
||||
|
||||
|
||||
@@ -150,6 +150,8 @@ public class ClassNode extends NotificationAttrNode
|
||||
IUsageInfoData usageInfoData = root.getArgs().getUsageInfoCache().get(root);
|
||||
if (usageInfoData != null) {
|
||||
usageInfoData.applyForClass(this);
|
||||
} else {
|
||||
LOG.warn("Can't restore usage data for class: {}", this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ public class DecompilerScheduler implements IDecompileScheduler {
|
||||
mergedBatch = new ArrayList<>(MERGED_BATCH_SIZE);
|
||||
}
|
||||
} else {
|
||||
List<JavaClass> batch = new ArrayList<>(depsSize + 1);
|
||||
List<JavaClass> batch = new ArrayList<>();
|
||||
for (JavaClass dep : cls.getDependencies()) {
|
||||
JavaClass topDep = dep.getTopParentClass();
|
||||
if (!added.contains(topDep)) {
|
||||
@@ -75,7 +75,7 @@ public class DecompilerScheduler implements IDecompileScheduler {
|
||||
}
|
||||
batch.sort(cmpDepSize);
|
||||
batch.add(cls);
|
||||
result.add(batch);
|
||||
result.add(Utils.lockList(batch));
|
||||
}
|
||||
}
|
||||
if (!mergedBatch.isEmpty()) {
|
||||
|
||||
Reference in New Issue
Block a user