gui: Perform classes unload in the background UnloadJob
This should improve interface responsibility if there are many classes to refresh after rename.
This commit is contained in:
@@ -54,11 +54,22 @@ public class BackgroundWorker extends SwingWorker<Void, Void> {
|
||||
runJob(cache.getDecompileJob());
|
||||
LOG.debug("Memory usage: After decompile: {}", UiUtils.memoryInfo());
|
||||
|
||||
LOG.info("Memory usage: Before refresh: {}", UiUtils.memoryInfo());
|
||||
long start = System.nanoTime();
|
||||
runJob(cache.getRefreshJob());
|
||||
cache.setRefreshJob(null);
|
||||
LOG.info("Memory usage: After refresh: {}, refresh took {} ms", UiUtils.memoryInfo(), (System.nanoTime() - start) / 1000000);
|
||||
if (cache.getUnloadJob() != null) {
|
||||
LOG.info("Memory usage: Before unload: {}", UiUtils.memoryInfo());
|
||||
long start = System.nanoTime();
|
||||
runJob(cache.getUnloadJob());
|
||||
cache.setUnloadJob(null);
|
||||
LOG.info("Memory usage: After unload: {}, unload took {} ms", UiUtils.memoryInfo(), (System.nanoTime() - start) / 1000000);
|
||||
}
|
||||
|
||||
if (cache.getRefreshJob() != null) {
|
||||
LOG.info("Memory usage: Before refresh: {}", UiUtils.memoryInfo());
|
||||
long start = System.nanoTime();
|
||||
runJob(cache.getRefreshJob());
|
||||
cache.setRefreshJob(null);
|
||||
LOG.info("Memory usage: After refresh: {}, refresh took {} ms", UiUtils.memoryInfo(),
|
||||
(System.nanoTime() - start) / 1000000);
|
||||
}
|
||||
|
||||
LOG.debug("Memory usage: Before index: {}", UiUtils.memoryInfo());
|
||||
runJob(cache.getIndexJob());
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package jadx.gui.jobs;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import jadx.api.JavaClass;
|
||||
import jadx.gui.JadxWrapper;
|
||||
|
||||
public class UnloadJob extends BackgroundJob {
|
||||
|
||||
private Set<JavaClass> refreshClasses;
|
||||
|
||||
public UnloadJob(JadxWrapper jadxWrapper, int threadsCount, Set<JavaClass> refreshClasses) {
|
||||
super(jadxWrapper, threadsCount);
|
||||
this.refreshClasses = refreshClasses;
|
||||
}
|
||||
|
||||
protected void runJob() {
|
||||
for (final JavaClass cls : refreshClasses) {
|
||||
addTask(() -> {
|
||||
cls.unload();
|
||||
cls.getClassNode().deepUnload();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInfoString() {
|
||||
return "Refreshing: ";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -415,7 +415,7 @@ public class MainWindow extends JFrame {
|
||||
}
|
||||
}
|
||||
|
||||
synchronized void runBackgroundRefreshAndIndexJobs() {
|
||||
synchronized void runBackgroundUnloadRefreshAndIndexJobs() {
|
||||
cancelBackgroundJobs();
|
||||
backgroundWorker = new BackgroundWorker(cacheObject, progressPane);
|
||||
backgroundWorker.exec();
|
||||
|
||||
@@ -30,6 +30,7 @@ import jadx.core.dex.visitors.RenameVisitor;
|
||||
import jadx.core.utils.files.InputFile;
|
||||
import jadx.gui.jobs.IndexJob;
|
||||
import jadx.gui.jobs.RefreshJob;
|
||||
import jadx.gui.jobs.UnloadJob;
|
||||
import jadx.gui.treemodel.JClass;
|
||||
import jadx.gui.treemodel.JField;
|
||||
import jadx.gui.treemodel.JMethod;
|
||||
@@ -39,7 +40,6 @@ import jadx.gui.ui.codearea.ClassCodeContentPanel;
|
||||
import jadx.gui.ui.codearea.CodeArea;
|
||||
import jadx.gui.ui.codearea.CodePanel;
|
||||
import jadx.gui.utils.CacheObject;
|
||||
import jadx.gui.utils.CodeUsageInfo;
|
||||
import jadx.gui.utils.NLS;
|
||||
import jadx.gui.utils.TextStandardActions;
|
||||
|
||||
@@ -222,10 +222,6 @@ public class RenameDialog extends JDialog {
|
||||
refreshTabs(mainWindow.getTabbedPane(), updatedClasses);
|
||||
|
||||
if (updatedClasses.size() > 0) {
|
||||
for (JavaClass updatedClass : updatedClasses) {
|
||||
updatedClass.unload();
|
||||
updatedClass.getClassNode().deepUnload();
|
||||
}
|
||||
setRefreshTask(updatedClasses);
|
||||
}
|
||||
|
||||
@@ -268,19 +264,21 @@ public class RenameDialog extends JDialog {
|
||||
|
||||
private void setRefreshTask(Set<JavaClass> refreshClasses) {
|
||||
CacheObject cache = mainWindow.getCacheObject();
|
||||
UnloadJob unloadJob = new UnloadJob(mainWindow.getWrapper(), mainWindow.getSettings().getThreadsCount(), refreshClasses);
|
||||
RefreshJob refreshJob = new RefreshJob(mainWindow.getWrapper(), mainWindow.getSettings().getThreadsCount(), refreshClasses);
|
||||
LOG.info("Waiting for old refreshJob");
|
||||
while (cache.getRefreshJob() != null) {
|
||||
LOG.info("Waiting for old unloadJob and refreshJob");
|
||||
while (cache.getUnloadJob() != null || cache.getRefreshJob() != null) {
|
||||
try {
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
LOG.info("Old refreshJob finished");
|
||||
LOG.info("Old unloadJob and refreshJob finished");
|
||||
cache.setUnloadJob(unloadJob);
|
||||
cache.setRefreshJob(refreshJob);
|
||||
cache.setIndexJob(new IndexJob(mainWindow.getWrapper(), mainWindow.getCacheObject(), mainWindow.getSettings().getThreadsCount()));
|
||||
mainWindow.runBackgroundRefreshAndIndexJobs();
|
||||
mainWindow.runBackgroundUnloadRefreshAndIndexJobs();
|
||||
}
|
||||
|
||||
private void initCommon() {
|
||||
|
||||
@@ -8,6 +8,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import jadx.gui.jobs.DecompileJob;
|
||||
import jadx.gui.jobs.IndexJob;
|
||||
import jadx.gui.jobs.RefreshJob;
|
||||
import jadx.gui.jobs.UnloadJob;
|
||||
import jadx.gui.ui.SearchDialog;
|
||||
import jadx.gui.utils.search.TextSearchIndex;
|
||||
|
||||
@@ -15,6 +16,7 @@ public class CacheObject {
|
||||
|
||||
private DecompileJob decompileJob;
|
||||
private IndexJob indexJob;
|
||||
private UnloadJob unloadJob;
|
||||
private RefreshJob refreshJob;
|
||||
|
||||
private TextSearchIndex textIndex;
|
||||
@@ -99,4 +101,12 @@ public class CacheObject {
|
||||
public void setRefreshJob(RefreshJob refreshJob) {
|
||||
this.refreshJob = refreshJob;
|
||||
}
|
||||
|
||||
public UnloadJob getUnloadJob() {
|
||||
return unloadJob;
|
||||
}
|
||||
|
||||
public void setUnloadJob(UnloadJob unloadJob) {
|
||||
this.unloadJob = unloadJob;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user