java-decompiler: post-import cleanup (common fixes and optimizations)
This commit is contained in:
@@ -67,6 +67,8 @@ public class ClassWrapper {
|
||||
setFieldNames.add(fd.getName());
|
||||
}
|
||||
|
||||
int maxsec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString());
|
||||
|
||||
for (StructMethod mt : classStruct.getMethods()) {
|
||||
|
||||
DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor());
|
||||
@@ -83,7 +85,6 @@ public class ClassWrapper {
|
||||
VarProcessor varproc = new VarProcessor();
|
||||
DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc);
|
||||
|
||||
Thread mtthread = null;
|
||||
RootStatement root = null;
|
||||
|
||||
boolean isError = false;
|
||||
@@ -91,28 +92,25 @@ public class ClassWrapper {
|
||||
try {
|
||||
if (mt.containsCode()) {
|
||||
|
||||
int maxsec = 10 * Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString());
|
||||
|
||||
if (maxsec == 0) { // blocking wait
|
||||
root = MethodProcessorThread.codeToJava(mt, varproc);
|
||||
}
|
||||
else {
|
||||
MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext());
|
||||
mtthread = new Thread(mtproc);
|
||||
Thread mtthread = new Thread(mtproc);
|
||||
long stopAt = System.currentTimeMillis() + maxsec * 1000;
|
||||
|
||||
mtthread.start();
|
||||
|
||||
int sec = 0;
|
||||
while (mtthread.isAlive()) {
|
||||
|
||||
synchronized (mtproc) {
|
||||
mtproc.wait(100);
|
||||
synchronized (mtproc.lock) {
|
||||
mtproc.lock.wait(100);
|
||||
}
|
||||
|
||||
if (maxsec > 0 && ++sec > maxsec) {
|
||||
DecompilerContext.getLogger().writeMessage("Processing time limit (" + maxsec + " sec.) for method " +
|
||||
mt.getName() + " " + mt.getDescriptor() + " exceeded, execution interrupted.",
|
||||
IFernflowerLogger.ERROR);
|
||||
if (System.currentTimeMillis() >= stopAt) {
|
||||
String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted.";
|
||||
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.ERROR);
|
||||
mtthread.stop();
|
||||
isError = true;
|
||||
break;
|
||||
@@ -120,12 +118,7 @@ public class ClassWrapper {
|
||||
}
|
||||
|
||||
if (!isError) {
|
||||
if (mtproc.getError() != null) {
|
||||
throw mtproc.getError();
|
||||
}
|
||||
else {
|
||||
root = mtproc.getRoot();
|
||||
}
|
||||
root = mtproc.getResult();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -158,17 +151,6 @@ public class ClassWrapper {
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (ThreadDeath ex) {
|
||||
try {
|
||||
if (mtthread != null) {
|
||||
mtthread.stop();
|
||||
}
|
||||
}
|
||||
catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
throw ex;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
DecompilerContext.getLogger().writeMessage("Method " + mt.getName() + " " + mt.getDescriptor() + " couldn't be decompiled.", ex);
|
||||
isError = true;
|
||||
|
||||
@@ -112,9 +112,9 @@ public class LambdaProcessor {
|
||||
|
||||
LinkConstant content_method_handle = (LinkConstant)bootstrap_arguments.get(1);
|
||||
|
||||
ClassNode node_lambda = clprocessor.new ClassNode(content_method_handle.classname, content_method_handle.elementname,
|
||||
content_method_handle.descriptor, content_method_handle.index1,
|
||||
lambda_class_name, lambda_method_name, lambda_method_descriptor, cl);
|
||||
ClassNode node_lambda = new ClassNode(content_method_handle.classname, content_method_handle.elementname,
|
||||
content_method_handle.descriptor, content_method_handle.index1,
|
||||
lambda_class_name, lambda_method_name, lambda_method_descriptor, cl);
|
||||
node_lambda.simpleName = cl.qualifiedName + "##Lambda_" + invoke_dynamic.index1 + "_" + invoke_dynamic.index2;
|
||||
node_lambda.enclosingMethod = InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor());
|
||||
|
||||
|
||||
@@ -33,16 +33,16 @@ import java.io.IOException;
|
||||
|
||||
public class MethodProcessorThread implements Runnable {
|
||||
|
||||
private StructMethod method;
|
||||
private VarProcessor varproc;
|
||||
private DecompilerContext parentContext;
|
||||
public final Object lock = new Object();
|
||||
|
||||
private RootStatement root;
|
||||
private final StructMethod method;
|
||||
private final VarProcessor varproc;
|
||||
private final DecompilerContext parentContext;
|
||||
|
||||
private Throwable error;
|
||||
private volatile RootStatement root;
|
||||
private volatile Throwable error;
|
||||
|
||||
public MethodProcessorThread(StructMethod method, VarProcessor varproc,
|
||||
DecompilerContext parentContext) {
|
||||
public MethodProcessorThread(StructMethod method, VarProcessor varproc, DecompilerContext parentContext) {
|
||||
this.method = method;
|
||||
this.varproc = varproc;
|
||||
this.parentContext = parentContext;
|
||||
@@ -58,11 +58,13 @@ public class MethodProcessorThread implements Runnable {
|
||||
try {
|
||||
root = codeToJava(method, varproc);
|
||||
|
||||
synchronized (this) {
|
||||
this.notify();
|
||||
synchronized (lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
catch (ThreadDeath ignored) { }
|
||||
catch (ThreadDeath ex) {
|
||||
throw ex;
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
error = ex;
|
||||
}
|
||||
@@ -248,7 +250,9 @@ public class MethodProcessorThread implements Runnable {
|
||||
return root;
|
||||
}
|
||||
|
||||
public RootStatement getRoot() {
|
||||
public RootStatement getResult() throws Throwable {
|
||||
Throwable t = error;
|
||||
if (t != null) throw t;
|
||||
return root;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private void setLambdaVars(ClassNode parent, ClassNode child) {
|
||||
private static void setLambdaVars(ClassNode parent, ClassNode child) {
|
||||
|
||||
if (child.lambda_information.is_method_reference) { // method reference, no code and no parameters
|
||||
return;
|
||||
@@ -187,7 +187,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNotFoundClasses(ClassNode root, ClassNode node) {
|
||||
private static void checkNotFoundClasses(ClassNode root, ClassNode node) {
|
||||
|
||||
List<ClassNode> lstChildren = new ArrayList<ClassNode>(node.nested);
|
||||
|
||||
@@ -232,7 +232,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean insertNestedClass(ClassNode root, ClassNode child) {
|
||||
private static boolean insertNestedClass(ClassNode root, ClassNode child) {
|
||||
|
||||
Set<String> setEnclosing = child.enclosingClasses;
|
||||
|
||||
@@ -258,7 +258,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
|
||||
|
||||
private void computeLocalVarsAndDefinitions(final ClassNode node) {
|
||||
private static void computeLocalVarsAndDefinitions(final ClassNode node) {
|
||||
|
||||
// local var masks
|
||||
// class name, constructor descriptor, field mask
|
||||
@@ -433,7 +433,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private void insertLocalVars(final ClassNode parent, final ClassNode child) {
|
||||
private static void insertLocalVars(final ClassNode parent, final ClassNode child) {
|
||||
|
||||
// enclosing method, is null iff member class
|
||||
MethodWrapper encmeth = parent.wrapper.getMethods().getWithKey(child.enclosingMethod);
|
||||
@@ -634,7 +634,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, List<VarFieldPair>> getMaskLocalVars(ClassWrapper wrapper) {
|
||||
private static HashMap<String, List<VarFieldPair>> getMaskLocalVars(ClassWrapper wrapper) {
|
||||
|
||||
HashMap<String, List<VarFieldPair>> mapMasks = new HashMap<String, List<VarFieldPair>>();
|
||||
|
||||
@@ -666,7 +666,7 @@ public class NestedClassProcessor {
|
||||
return mapMasks;
|
||||
}
|
||||
|
||||
private String getEnclosingVarField(StructClass cl, MethodWrapper meth, DirectGraph graph, final int index) {
|
||||
private static String getEnclosingVarField(StructClass cl, MethodWrapper meth, DirectGraph graph, final int index) {
|
||||
|
||||
String field = "";
|
||||
|
||||
@@ -709,7 +709,7 @@ public class NestedClassProcessor {
|
||||
return field;
|
||||
}
|
||||
|
||||
private void mergeListSignatures(List<VarFieldPair> first, List<VarFieldPair> second, boolean both) {
|
||||
private static void mergeListSignatures(List<VarFieldPair> first, List<VarFieldPair> second, boolean both) {
|
||||
|
||||
int i = 1;
|
||||
while (true) {
|
||||
@@ -818,7 +818,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
|
||||
|
||||
private void setLocalClassDefinition(MethodWrapper meth, ClassNode node) {
|
||||
private static void setLocalClassDefinition(MethodWrapper meth, ClassNode node) {
|
||||
|
||||
RootStatement root = meth.root;
|
||||
|
||||
@@ -862,7 +862,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
|
||||
|
||||
private Statement findFirstBlock(Statement stat, HashSet<Statement> setStats) {
|
||||
private static Statement findFirstBlock(Statement stat, HashSet<Statement> setStats) {
|
||||
|
||||
LinkedList<Statement> stack = new LinkedList<Statement>();
|
||||
stack.add(stat);
|
||||
@@ -903,7 +903,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
|
||||
|
||||
private Statement getDefStatement(Statement stat, VarType classtype, HashSet<Statement> setStats) {
|
||||
private static Statement getDefStatement(Statement stat, VarType classtype, HashSet<Statement> setStats) {
|
||||
|
||||
List<Exprent> condlst = new ArrayList<Exprent>();
|
||||
Statement retstat = null;
|
||||
@@ -958,7 +958,7 @@ public class NestedClassProcessor {
|
||||
return retstat;
|
||||
}
|
||||
|
||||
private boolean searchForClass(Exprent exprent, VarType classtype) {
|
||||
private static boolean searchForClass(Exprent exprent, VarType classtype) {
|
||||
|
||||
List<Exprent> lst = exprent.getAllExprents(true);
|
||||
lst.add(exprent);
|
||||
@@ -1004,7 +1004,7 @@ public class NestedClassProcessor {
|
||||
}
|
||||
|
||||
|
||||
private class VarFieldPair {
|
||||
private static class VarFieldPair {
|
||||
|
||||
public String keyfield = "";
|
||||
public VarVersionPaar varpaar;
|
||||
|
||||
@@ -310,7 +310,7 @@ public class NestedMemberAccess {
|
||||
return res;
|
||||
}
|
||||
|
||||
private boolean sameTree(ClassNode caller, ClassNode callee) {
|
||||
private static boolean sameTree(ClassNode caller, ClassNode callee) {
|
||||
|
||||
if (caller.classStruct.qualifiedName.equals(callee.classStruct.qualifiedName)) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user