From fad3af0b4de25f54a7bb4cd14ee17fec01ce8105 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 10 Nov 2014 16:05:22 +0100 Subject: [PATCH] IDEA-132625 (decompiler time limit) --- .../decompiler/main/rels/ClassWrapper.java | 2 +- .../main/rels/MethodProcessorRunnable.java | 17 ++++++---- .../java/decompiler/IdeaDecompiler.java | 1 + .../java/decompiler/IdeaDecompilerTest.java | 31 ++++++++++++------- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java index 93203556e76c..8f2958f83bb5 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java @@ -94,7 +94,7 @@ public class ClassWrapper { mtThread.start(); - while (mtThread.isAlive()) { + while (!mtProc.isFinished()) { synchronized (mtProc.lock) { mtProc.lock.wait(100); } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java index 3b2d72acb597..786babfedc76 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java @@ -41,6 +41,7 @@ public class MethodProcessorRunnable implements Runnable { private volatile RootStatement root; private volatile Throwable error; + private volatile boolean finished = false; public MethodProcessorRunnable(StructMethod method, VarProcessor varProc, DecompilerContext parentContext) { this.method = method; @@ -57,10 +58,6 @@ public class MethodProcessorRunnable implements Runnable { try { root = codeToJava(method, varProc); - - synchronized (lock) { - lock.notifyAll(); - } } catch (ThreadDeath ex) { throw ex; @@ -68,6 +65,14 @@ public class MethodProcessorRunnable implements Runnable { catch (Throwable ex) { error = ex; } + finally { + DecompilerContext.setCurrentContext(null); + } + + finished = true; + synchronized (lock) { + lock.notifyAll(); + } } public static RootStatement codeToJava(StructMethod mt, VarProcessor varProc) throws IOException { @@ -206,7 +211,7 @@ public class MethodProcessorRunnable implements Runnable { return root; } - public Throwable getError() { - return error; + public boolean isFinished() { + return finished; } } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java index 24f3f292bb2c..5cf87ed095ad 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.java @@ -82,6 +82,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light { myOptions.put(IFernflowerPreferences.LITERALS_AS_IS, "1"); myOptions.put(IFernflowerPreferences.NEW_LINE_SEPARATOR, "1"); myOptions.put(IFernflowerPreferences.BANNER, BANNER); + myOptions.put(IFernflowerPreferences.MAX_PROCESSING_METHOD, 30); Project project = DefaultProjectFactory.getInstance().getDefaultProject(); CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings(); diff --git a/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.java b/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.java index aaeb79ed0ada..81df4dd82859 100644 --- a/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.java +++ b/plugins/java-decompiler/plugin/test/org/jetbrains/java/decompiler/IdeaDecompilerTest.java @@ -21,19 +21,19 @@ import com.intellij.debugger.PositionManager; import com.intellij.openapi.application.PluginPathManager; import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.util.SystemInfo; +import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.registry.RegistryValue; -import com.intellij.openapi.vfs.StandardFileSystems; -import com.intellij.openapi.vfs.VfsUtilCore; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileVisitor; +import com.intellij.openapi.vfs.*; import com.intellij.pom.Navigatable; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.psi.impl.compiled.ClsFileImpl; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase; +import com.intellij.util.ThrowableRunnable; import com.intellij.util.containers.ContainerUtil; +import com.intellij.util.io.URLUtil; import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -47,9 +47,7 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase { public void testSimple() { String path = PlatformTestUtil.getRtJarPath() + "!/java/lang/String.class"; - VirtualFile file = StandardFileSystems.jar().findFileByPath(path); - assertNotNull(path, file); - + VirtualFile file = getTestFile(path); String decompiled = new IdeaDecompiler().getText(file).toString(); assertTrue(decompiled, decompiled.startsWith(IdeaDecompiler.BANNER + "package java.lang;\n")); assertTrue(decompiled, decompiled.contains("public final class String")); @@ -61,8 +59,7 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase { public void testStubCompatibility() { String path = PlatformTestUtil.getRtJarPath() + "!/java"; - VirtualFile dir = StandardFileSystems.jar().findFileByPath(path); - assertNotNull(path, dir); + VirtualFile dir = getTestFile(path); doTestStubCompatibility(dir); } @@ -123,8 +120,9 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase { } private VirtualFile getTestFile(String name) { - String path = myFixture.getTestDataPath() + "/" + name; - VirtualFile file = StandardFileSystems.local().refreshAndFindFileByPath(path); + String path = FileUtil.isAbsolute(name) ? name : myFixture.getTestDataPath() + "/" + name; + VirtualFileSystem fs = path.contains(URLUtil.JAR_SEPARATOR) ? StandardFileSystems.jar() : StandardFileSystems.local(); + VirtualFile file = fs.refreshAndFindFileByPath(path); assertNotNull(path, file); return file; } @@ -160,4 +158,15 @@ public class IdeaDecompilerTest extends LightCodeInsightFixtureTestCase { value.setValue(old); } } + + public void testPerformance() { + final IdeaDecompiler decompiler = new IdeaDecompiler(); + final VirtualFile file = getTestFile(PlatformTestUtil.getRtJarPath() + "!/javax/swing/JTable.class"); + PlatformTestUtil.startPerformanceTest("decompiling JTable.class", 2500, new ThrowableRunnable() { + @Override + public void run() throws Throwable { + decompiler.getText(file); + } + }).cpuBound().assertTiming(); + } }