From 5ff48a98c56677af1046ba71bb1774efae75175b Mon Sep 17 00:00:00 2001 From: Mikhail Pyltsin Date: Sun, 18 Jun 2023 14:50:51 +0200 Subject: [PATCH] Revert "IJ-CR-108265 [java-decompiler] IDEA-198397. Add limits for decompiler. Move inheritance to BGT" This reverts commit 6a7ae0444c39238e21475234c0bb988cf86a5af6. GitOrigin-RevId: 56545f54ff83b256d93ef5c54191f9183524f50d --- .../codeInsight/daemon/impl/MarkerType.java | 7 +-- .../decompiler/main/CancellationManager.java | 13 +----- .../main/extern/IFernflowerPreferences.java | 4 -- .../decompiler/main/rels/ClassWrapper.java | 2 +- .../modules/decompiler/stats/Statement.java | 8 ---- .../java/decompiler/struct/StructMethod.java | 5 --- .../java/decompiler/CancellableTest.java | 4 +- .../decompiler/IdeaCancellationManager.java | 22 ++-------- .../java/decompiler/IdeaDecompiler.kt | 43 +++++-------------- 9 files changed, 19 insertions(+), 89 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java index 447d91a2c9fd..d53f17c5963c 100644 --- a/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java +++ b/java/java-impl/src/com/intellij/codeInsight/daemon/impl/MarkerType.java @@ -174,12 +174,7 @@ public class MarkerType { .elementsConsumer((methods, navigator) -> { if (!methods.isEmpty()) { boolean showMethodNames = !PsiUtil.allMethodsHaveSameSignature(methods.toArray(PsiMethod.EMPTY_ARRAY)); - navigator.presentationProvider(element -> { - if (element instanceof PsiCompiledElement) { - ((PsiCompiledElement)element).getMirror(); // load decompiler in background thread - } - return GotoTargetHandler.computePresentation(element, showMethodNames); - }); + navigator.presentationProvider(element -> GotoTargetHandler.computePresentation(element, showMethodNames)); } }) .navigate(e, DaemonBundle.message("navigation.title.super.method", method.getName()), method.getProject()); diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/CancellationManager.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/CancellationManager.java index fd4f68f72408..ae7deebb6078 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/CancellationManager.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/CancellationManager.java @@ -3,22 +3,13 @@ package org.jetbrains.java.decompiler.main; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.java.decompiler.struct.StructClass; @ApiStatus.Experimental public interface CancellationManager { /** * @throws CanceledException if the process has been canceled. */ - default void checkCanceled() throws CanceledException { - checkCanceled(null); - } - - /** - * @throws CanceledException if the process has been canceled. - */ - void checkCanceled(@Nullable StructClass classStruct) throws CanceledException; + void checkCanceled() throws CanceledException; /** * Called every time the body of a new method is started to be decompiled @@ -59,7 +50,7 @@ public interface CancellationManager { } @Override - public void checkCanceled(StructClass classStruct) throws CanceledException { + public void checkCanceled() throws CanceledException { if (maxMilis <= 0 || startMilis <= 0) { return; } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java index 88f645a6a9e8..5448e7900953 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/extern/IFernflowerPreferences.java @@ -37,8 +37,6 @@ public interface IFernflowerPreferences { String LOG_LEVEL = "log"; String MAX_PROCESSING_METHOD = "mpm"; - String MAX_BYTES_CLASS_NOT_UNDER_PROGRESS = "mlmnup"; - String MAX_LENGTH_CLASS = "mlm"; String RENAME_ENTITIES = "ren"; String USER_RENAMER_CLASS = "urc"; String NEW_LINE_SEPARATOR = "nls"; @@ -85,8 +83,6 @@ public interface IFernflowerPreferences { defaults.put(LOG_LEVEL, IFernflowerLogger.Severity.INFO.name()); defaults.put(MAX_PROCESSING_METHOD, "0"); - defaults.put(MAX_BYTES_CLASS_NOT_UNDER_PROGRESS, "0"); - defaults.put(MAX_LENGTH_CLASS, "0"); defaults.put(RENAME_ENTITIES, "0"); defaults.put(NEW_LINE_SEPARATOR, (InterpreterUtil.IS_WINDOWS ? "0" : "1")); defaults.put(INDENT_STRING, " "); 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 b7ecc60f0b73..ad30feea9598 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 @@ -45,6 +45,7 @@ public class ClassWrapper { boolean testMode = DecompilerContext.getOption(IFernflowerPreferences.UNIT_TEST_MODE); CancellationManager cancellationManager = DecompilerContext.getCancellationManager(); for (StructMethod mt : classStruct.getMethods()) { + cancellationManager.checkCanceled(); DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor()); MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor()); @@ -59,7 +60,6 @@ public class ClassWrapper { boolean isError = false; try { - cancellationManager.checkCanceled(classStruct); if (mt.containsCode()) { if (testMode) { root = MethodProcessorRunnable.codeToJava(classStruct, mt, md, varProc); diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java index 84c4ee380ee2..5d7a8cce83fb 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/modules/decompiler/stats/Statement.java @@ -421,8 +421,6 @@ public abstract class Statement implements IMatchable { } public boolean containsStatementStrict(Statement stat) { - cancellationManager.checkCanceled(); - if (stats.contains(stat)) { return true; } @@ -578,7 +576,6 @@ public abstract class Statement implements IMatchable { // ***************************************************************************** public void changeEdgeNode(EdgeDirection direction, StatEdge edge, Statement value) { - cancellationManager.checkCanceled(); Map> mapEdges = direction == EdgeDirection.BACKWARD ? mapPredEdges : mapSuccEdges; Map> mapStates = direction == EdgeDirection.BACKWARD ? mapPredStates : mapSuccStates; @@ -612,7 +609,6 @@ public abstract class Statement implements IMatchable { } public void changeEdgeType(EdgeDirection direction, StatEdge edge, EdgeType newtype) { - cancellationManager.checkCanceled(); EdgeType oldtype = edge.getType(); if (oldtype == newtype) { @@ -660,7 +656,6 @@ public abstract class Statement implements IMatchable { } public List getNeighbours(EdgeType type, EdgeDirection direction) { - cancellationManager.checkCanceled(); Map> map = direction == EdgeDirection.BACKWARD ? mapPredStates : mapSuccStates; @@ -705,7 +700,6 @@ public abstract class Statement implements IMatchable { } public Statement getFirst() { - cancellationManager.checkCanceled(); return first; } @@ -768,7 +762,6 @@ public abstract class Statement implements IMatchable { public Statement getParent() { - cancellationManager.checkCanceled(); return parent; } @@ -786,7 +779,6 @@ public abstract class Statement implements IMatchable { } public List getExprents() { - cancellationManager.checkCanceled(); return exprents; } diff --git a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/struct/StructMethod.java b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/struct/StructMethod.java index 5ce83c9ba644..b908ed26c27a 100644 --- a/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/struct/StructMethod.java +++ b/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/struct/StructMethod.java @@ -332,9 +332,4 @@ public class StructMethod extends StructMember { public String toString() { return name; } - - - public int getCodeLength() { - return codeLength; - } } diff --git a/plugins/java-decompiler/engine/test/org/jetbrains/java/decompiler/CancellableTest.java b/plugins/java-decompiler/engine/test/org/jetbrains/java/decompiler/CancellableTest.java index 85480d78e67b..b3ac62b28873 100644 --- a/plugins/java-decompiler/engine/test/org/jetbrains/java/decompiler/CancellableTest.java +++ b/plugins/java-decompiler/engine/test/org/jetbrains/java/decompiler/CancellableTest.java @@ -2,10 +2,8 @@ package org.jetbrains.java.decompiler; import org.assertj.core.api.Assertions; -import org.jetbrains.annotations.Nullable; import org.jetbrains.java.decompiler.main.CancellationManager; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; -import org.jetbrains.java.decompiler.struct.StructClass; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -36,7 +34,7 @@ public class CancellableTest { private final AtomicInteger myAtomicInteger = new AtomicInteger(0); @Override - public void checkCanceled(@Nullable StructClass classStruct) throws CanceledException { + public void checkCanceled() throws CanceledException { check(); } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaCancellationManager.java b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaCancellationManager.java index b0b0ada88d41..17fecd0cd97f 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaCancellationManager.java +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaCancellationManager.java @@ -1,42 +1,26 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.java.decompiler; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressManager; import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; import org.jetbrains.java.decompiler.main.CancellationManager; -import org.jetbrains.java.decompiler.struct.StructClass; -import org.jetbrains.java.decompiler.struct.StructMethod; @ApiStatus.Experimental public class IdeaCancellationManager extends CancellationManager.TimeoutCancellationManager { - private final int maxClassLength; - - public IdeaCancellationManager(int maxMethodTimeoutSec, int maxClassLength) { + public IdeaCancellationManager(int maxMethodTimeoutSec) { super(maxMethodTimeoutSec); - this.maxClassLength = maxClassLength; } @Override - public void checkCanceled(@Nullable StructClass classStruct) throws CanceledException { - if (classStruct != null && !ApplicationManager.getApplication().isUnitTestMode()) { - int methodsLength = 0; - for (StructMethod method : classStruct.getMethods()) { - methodsLength += method.getCodeLength(); - } - if (maxClassLength > 0 && methodsLength > maxClassLength) { - throw new TimeExceedException(); - } - } + public void checkCanceled() throws CanceledException { try { ProgressManager.checkCanceled(); } catch (ProcessCanceledException e) { throw new CanceledException(e); } - super.checkCanceled(null); + super.checkCanceled(); } } diff --git a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.kt b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.kt index 317417f29c38..95c36dc00561 100644 --- a/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.kt +++ b/plugins/java-decompiler/plugin/src/org/jetbrains/java/decompiler/IdeaDecompiler.kt @@ -27,7 +27,6 @@ import com.intellij.psi.compiled.ClassFileDecompilers import com.intellij.psi.impl.compiled.ClsFileImpl import com.intellij.ui.components.LegalNoticeDialog import com.intellij.util.FileContentUtilCore -import com.intellij.util.ui.EDT import org.jetbrains.java.decompiler.main.CancellationManager import org.jetbrains.java.decompiler.main.decompiler.BaseDecompiler import org.jetbrains.java.decompiler.main.extern.ClassFormatException @@ -62,8 +61,6 @@ class IdeaDecompiler : ClassFileDecompilers.Light() { IFernflowerPreferences.NEW_LINE_SEPARATOR to "1", IFernflowerPreferences.BANNER to BANNER, IFernflowerPreferences.MAX_PROCESSING_METHOD to 60, - IFernflowerPreferences.MAX_BYTES_CLASS_NOT_UNDER_PROGRESS to 20_000, - IFernflowerPreferences.MAX_LENGTH_CLASS to 15_000, IFernflowerPreferences.INDENT_STRING to indent, IFernflowerPreferences.IGNORE_INVALID_BYTECODE to "1", IFernflowerPreferences.VERIFY_ANONYMOUS_CLASSES to "1", @@ -125,26 +122,9 @@ class IdeaDecompiler : ClassFileDecompilers.Light() { override fun accepts(file: VirtualFile): Boolean = true - override fun getText(file: VirtualFile): CharSequence { - if (canWork()) { - val previous = TASK_KEY.pop(file)?.get() - if (previous != null) { - return previous - } - else { - val maxBytes = myOptions.value[IFernflowerPreferences.MAX_BYTES_CLASS_NOT_UNDER_PROGRESS]?.toString()?.toIntOrNull() ?: 0 - return if (!ApplicationManager.getApplication().isUnitTestMode && maxBytes > 0 && EDT.isCurrentThreadEdt() && file.length > maxBytes) { - ClsFileImpl.decompile(file) - } - else { - decompile(file) - } - } - } - else { - return ClsFileImpl.decompile(file) - } - } + override fun getText(file: VirtualFile): CharSequence = + if (canWork()) TASK_KEY.pop(file)?.get() ?: decompile(file) + else ClsFileImpl.decompile(file) private fun decompile(file: VirtualFile): CharSequence { val indicator = ProgressManager.getInstance().progressIndicator @@ -168,9 +148,8 @@ class IdeaDecompiler : ClassFileDecompilers.Light() { val saver = MyResultSaver() val maxSecProcessingMethod = options[IFernflowerPreferences.MAX_PROCESSING_METHOD]?.toString()?.toIntOrNull() ?: 0 - val maxLengthClass = options[IFernflowerPreferences.MAX_LENGTH_CLASS]?.toString()?.toIntOrNull() ?: 0 val decompiler = BaseDecompiler(provider, saver, options, myLogger.value, - IdeaCancellationManager(maxSecProcessingMethod, maxLengthClass)) + IdeaCancellationManager(maxSecProcessingMethod)) files.forEach { decompiler.addSource(File(it.path)) } try { decompiler.decompileContext() @@ -223,19 +202,19 @@ class IdeaDecompiler : ClassFileDecompilers.Light() { } } - override fun saveFolder(path: String) {} + override fun saveFolder(path: String) { } - override fun copyFile(source: String, path: String, entryName: String) {} + override fun copyFile(source: String, path: String, entryName: String) { } - override fun createArchive(path: String, archiveName: String, manifest: Manifest) {} + override fun createArchive(path: String, archiveName: String, manifest: Manifest) { } - override fun saveDirEntry(path: String, archiveName: String, entryName: String) {} + override fun saveDirEntry(path: String, archiveName: String, entryName: String) { } - override fun copyEntry(source: String, path: String, archiveName: String, entry: String) {} + override fun copyEntry(source: String, path: String, archiveName: String, entry: String) { } - override fun saveClassEntry(path: String, archiveName: String, qualifiedName: String, entryName: String, content: String) {} + override fun saveClassEntry(path: String, archiveName: String, qualifiedName: String, entryName: String, content: String) { } - override fun closeArchive(path: String, archiveName: String) {} + override fun closeArchive(path: String, archiveName: String) { } } private fun Key.pop(holder: UserDataHolder): T? {