提交 9e0cd2e1 编写于 作者: J Jan S 提交者: skylot

fix(gui): add synchronizations to search index creation (#433)

* fix: unsynchronized search index creation (code usage) results in ArrayIndexOutOfBoundsException and stuck at 99%

* fix: use computeIfAbsent instead of synchronized block
上级 d1af7512
......@@ -35,7 +35,7 @@ public class HeapUsageBar extends JProgressBar implements ActionListener {
setMaximum(maxKB);
maxGB = maxKB / TWO_TO_20;
update();
timer = new Timer(1000, this);
timer = new Timer(2000, this);
}
public void update() {
......@@ -44,7 +44,7 @@ public class HeapUsageBar extends JProgressBar implements ActionListener {
setValue(usedKB);
setString(String.format(textFormat, (usedKB / TWO_TO_20), maxGB));
if (used > r.totalMemory() * 0.8) {
if (used > r.maxMemory() * 0.8) {
setForeground(RED);
} else {
setForeground(GREEN);
......
......@@ -5,6 +5,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import jadx.api.CodePosition;
import jadx.api.JavaClass;
......@@ -21,6 +22,10 @@ public class CodeUsageInfo {
public List<CodeNode> getUsageList() {
return usageList;
}
public synchronized void addUsage(CodeNode codeNode) {
usageList.add(codeNode);
}
}
private final JNodeCache nodeCache;
......@@ -29,7 +34,7 @@ public class CodeUsageInfo {
this.nodeCache = nodeCache;
}
private final Map<JNode, UsageInfo> usageMap = new HashMap<>();
private final Map<JNode, UsageInfo> usageMap = new ConcurrentHashMap<>();
public void processClass(JavaClass javaClass, CodeLinesInfo linesInfo, List<StringRef> lines) {
Map<CodePosition, JavaNode> usage = javaClass.getUsageMap();
......@@ -42,17 +47,13 @@ public class CodeUsageInfo {
private void addUsage(JNode jNode, JavaClass javaClass,
CodeLinesInfo linesInfo, CodePosition codePosition, List<StringRef> lines) {
UsageInfo usageInfo = usageMap.get(jNode);
if (usageInfo == null) {
usageInfo = new UsageInfo();
usageMap.put(jNode, usageInfo);
}
int line = codePosition.getLine();
JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(line);
StringRef codeLine = lines.get(line - 1);
JNode node = nodeCache.makeFrom(javaNodeByLine == null ? javaClass : javaNodeByLine);
UsageInfo usageInfo = usageMap.computeIfAbsent(jNode, key -> new UsageInfo());
int line = codePosition.getLine();
JavaNode javaNodeByLine = linesInfo.getJavaNodeByLine(line);
StringRef codeLine = lines.get(line - 1);
JNode node = nodeCache.makeFrom(javaNodeByLine == null ? javaClass : javaNodeByLine);
CodeNode codeNode = new CodeNode(node, line, codeLine);
usageInfo.getUsageList().add(codeNode);
usageInfo.addUsage(codeNode);
}
public List<CodeNode> getUsageList(JNode node) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册