IDEA-132625 (decompiler time limit)

This commit is contained in:
Roman Shevchenko
2014-11-10 16:59:17 +01:00
parent b58b71f9ee
commit fad3af0b4d
4 changed files with 33 additions and 18 deletions
@@ -94,7 +94,7 @@ public class ClassWrapper {
mtThread.start();
while (mtThread.isAlive()) {
while (!mtProc.isFinished()) {
synchronized (mtProc.lock) {
mtProc.lock.wait(100);
}
@@ -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;
}
}
@@ -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();
@@ -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();
}
}