Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unsynchronized search index creation #433

Merged
merged 2 commits into from
Jan 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jadx-gui/src/main/java/jadx/gui/ui/HeapUsageBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public HeapUsageBar() {
setMaximum(maxKB);
maxGB = maxKB / TWO_TO_20;
update();
timer = new Timer(1000, this);
timer = new Timer(2000, this);
}

public void update() {
Expand All @@ -44,7 +44,7 @@ public void update() {
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);
Expand Down
23 changes: 12 additions & 11 deletions jadx-gui/src/main/java/jadx/gui/utils/CodeUsageInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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;
Expand All @@ -21,6 +22,10 @@ public static class UsageInfo {
public List<CodeNode> getUsageList() {
return usageList;
}

public synchronized void addUsage(CodeNode codeNode) {
usageList.add(codeNode);
}
}

private final JNodeCache nodeCache;
Expand All @@ -29,7 +34,7 @@ public CodeUsageInfo(JNodeCache nodeCache) {
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();
Expand All @@ -42,17 +47,13 @@ public void processClass(JavaClass javaClass, CodeLinesInfo linesInfo, List<Stri

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) {
Expand Down