Revert "IJ-CR-108265 [java-decompiler] IDEA-198397. Add limits for decompiler. Move inheritance to BGT"

This reverts commit 6a7ae0444c39238e21475234c0bb988cf86a5af6.

GitOrigin-RevId: 56545f54ff83b256d93ef5c54191f9183524f50d
This commit is contained in:
Mikhail Pyltsin
2023-06-18 14:50:51 +02:00
committed by intellij-monorepo-bot
parent 208e04bb65
commit 5ff48a98c5
9 changed files with 19 additions and 89 deletions

View File

@@ -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;
}

View File

@@ -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, " ");

View File

@@ -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);

View File

@@ -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<EdgeType, List<StatEdge>> mapEdges = direction == EdgeDirection.BACKWARD ? mapPredEdges : mapSuccEdges;
Map<EdgeType, List<Statement>> 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<Statement> getNeighbours(EdgeType type, EdgeDirection direction) {
cancellationManager.checkCanceled();
Map<EdgeType, List<Statement>> 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<Exprent> getExprents() {
cancellationManager.checkCanceled();
return exprents;
}

View File

@@ -332,9 +332,4 @@ public class StructMethod extends StructMember {
public String toString() {
return name;
}
public int getCodeLength() {
return codeLength;
}
}

View File

@@ -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();
}

View File

@@ -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();
}
}

View File

@@ -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 <T> Key<T>.pop(holder: UserDataHolder): T? {