summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/main
diff options
context:
space:
mode:
authorRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-08-29 21:58:12 +0400
committerRoman Shevchenko <roman.shevchenko@jetbrains.com>2014-08-29 21:58:12 +0400
commitf5431c3bb14854025dc1f0ec470b77497f79494c (patch)
tree909c1c06492d849fa062a60c56a02dd26e7095b6 /src/org/jetbrains/java/decompiler/main
parent63b8d35d08a198215ddabb42cca5b0e823232768 (diff)
downloadfernflower-f5431c3bb14854025dc1f0ec470b77497f79494c.tar
fernflower-f5431c3bb14854025dc1f0ec470b77497f79494c.tar.gz
fernflower-f5431c3bb14854025dc1f0ec470b77497f79494c.tar.lz
fernflower-f5431c3bb14854025dc1f0ec470b77497f79494c.tar.xz
fernflower-f5431c3bb14854025dc1f0ec470b77497f79494c.zip
java-decompiler: post-import cleanup (common fixes and optimizations)
Diffstat (limited to 'src/org/jetbrains/java/decompiler/main')
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java10
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassWriter.java8
-rw-r--r--src/org/jetbrains/java/decompiler/main/ClassesProcessor.java12
-rw-r--r--src/org/jetbrains/java/decompiler/main/Fernflower.java4
-rw-r--r--src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java3
-rw-r--r--src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java38
-rw-r--r--src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java6
-rw-r--r--src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java26
-rw-r--r--src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java26
-rw-r--r--src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java2
10 files changed, 58 insertions, 77 deletions
diff --git a/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java b/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java
index 060497a..937d59b 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassReference14Processor.java
@@ -122,9 +122,9 @@ public class ClassReference14Processor {
}
}
- private void processClassRec(ClassNode node,
- final HashMap<ClassWrapper, MethodWrapper> mapClassMeths,
- final HashSet<ClassWrapper> setFound) {
+ private static void processClassRec(ClassNode node,
+ final HashMap<ClassWrapper, MethodWrapper> mapClassMeths,
+ final HashSet<ClassWrapper> setFound) {
final ClassWrapper wrapper = node.wrapper;
@@ -221,7 +221,7 @@ public class ClassReference14Processor {
}
- private boolean replaceInvocations(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) {
+ private static boolean replaceInvocations(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) {
boolean res = false;
@@ -250,7 +250,7 @@ public class ClassReference14Processor {
}
- private String isClass14Invocation(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) {
+ private static String isClass14Invocation(Exprent exprent, ClassWrapper wrapper, MethodWrapper meth) {
if (exprent.type == Exprent.EXPRENT_FUNCTION) {
FunctionExprent fexpr = (FunctionExprent)exprent;
diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
index 7808b26..d16c203 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java
@@ -1046,7 +1046,7 @@ public class ClassWriter {
return !hidemethod;
}
- private List<AnnotationExprent> getAllAnnotations(VBStyleCollection<StructGeneralAttribute, String> attributes) {
+ private static List<AnnotationExprent> getAllAnnotations(VBStyleCollection<StructGeneralAttribute, String> attributes) {
String[] annattrnames = new String[]{StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS,
StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS};
@@ -1063,7 +1063,7 @@ public class ClassWriter {
return lst;
}
- private List<List<AnnotationExprent>> getAllParameterAnnotations(VBStyleCollection<StructGeneralAttribute, String> attributes) {
+ private static List<List<AnnotationExprent>> getAllParameterAnnotations(VBStyleCollection<StructGeneralAttribute, String> attributes) {
String[] annattrnames = new String[]{StructGeneralAttribute.ATTRIBUTE_RUNTIME_VISIBLE_PARAMETER_ANNOTATIONS,
StructGeneralAttribute.ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS};
@@ -1095,7 +1095,7 @@ public class ClassWriter {
return ret;
}
- private String getDescriptorPrintOut(String descriptor, int element) {
+ private static String getDescriptorPrintOut(String descriptor, int element) {
switch (element) {
case 0: // class
@@ -1125,7 +1125,7 @@ public class ClassWriter {
}
}
- private String getTypePrintOut(VarType type) {
+ private static String getTypePrintOut(VarType type) {
String strtype = ExprProcessor.getCastTypeName(type, false);
if (ExprProcessor.UNDEFINED_TYPE_STRING.equals(strtype) &&
DecompilerContext.getOption(IFernflowerPreferences.UNDEFINED_PARAM_TYPE_OBJECT)) {
diff --git a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
index 155dee0..9230c68 100644
--- a/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
+++ b/src/org/jetbrains/java/decompiler/main/ClassesProcessor.java
@@ -303,7 +303,7 @@ public class ClassesProcessor {
}
}
- private void initWrappers(ClassNode node) throws IOException {
+ private static void initWrappers(ClassNode node) throws IOException {
if (node.type == ClassNode.CLASS_LAMBDA) {
return;
@@ -319,7 +319,7 @@ public class ClassesProcessor {
}
}
- private void addClassnameToImport(ClassNode node, ImportCollector imp) {
+ private static void addClassnameToImport(ClassNode node, ImportCollector imp) {
if (node.simpleName != null && node.simpleName.length() > 0) {
imp.getShortName(node.type == ClassNode.CLASS_ROOT ? node.classStruct.qualifiedName : node.simpleName, false);
@@ -330,7 +330,7 @@ public class ClassesProcessor {
}
}
- private void destroyWrappers(ClassNode node) {
+ private static void destroyWrappers(ClassNode node) {
node.wrapper = null;
node.classStruct.releaseResources();
@@ -345,7 +345,7 @@ public class ClassesProcessor {
}
- public class ClassNode {
+ public static class ClassNode {
public static final int CLASS_ROOT = 0;
public static final int CLASS_MEMBER = 1;
@@ -436,9 +436,7 @@ public class ClassesProcessor {
return null;
}
- public class LambdaInformation {
-
-
+ public static class LambdaInformation {
public String class_name;
public String method_name;
public String method_descriptor;
diff --git a/src/org/jetbrains/java/decompiler/main/Fernflower.java b/src/org/jetbrains/java/decompiler/main/Fernflower.java
index bc0fcd4..88655a9 100644
--- a/src/org/jetbrains/java/decompiler/main/Fernflower.java
+++ b/src/org/jetbrains/java/decompiler/main/Fernflower.java
@@ -50,9 +50,7 @@ public class Fernflower implements IDecompiledData {
public void decompileContext() {
if (DecompilerContext.getOption(IFernflowerPreferences.RENAME_ENTITIES)) {
- IdentifierConverter ren = new IdentifierConverter();
- ren.rename(structcontext);
- ren = null;
+ new IdentifierConverter().rename(structcontext);
}
clprocessor = new ClassesProcessor(structcontext);
diff --git a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java
index 0a8261f..50a55cf 100644
--- a/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java
+++ b/src/org/jetbrains/java/decompiler/main/decompiler/ConsoleDecompiler.java
@@ -311,8 +311,7 @@ public class ConsoleDecompiler implements IBytecodeProvider, IDecompilatSaver {
String filename = new File(getAbsolutePath(path), archivename).getAbsolutePath();
mapArchiveEntries.remove(filename);
- ZipOutputStream out = mapArchiveStreams.remove(filename);
-
+ OutputStream out = mapArchiveStreams.remove(filename);
out.flush();
out.close();
}
diff --git a/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java
index f0e8591..0991fa4 100644
--- a/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java
+++ b/src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java
@@ -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;
diff --git a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java
index 3d42bda..3150894 100644
--- a/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java
+++ b/src/org/jetbrains/java/decompiler/main/rels/LambdaProcessor.java
@@ -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());
diff --git a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java
index eeee352..da05640 100644
--- a/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java
+++ b/src/org/jetbrains/java/decompiler/main/rels/MethodProcessorThread.java
@@ -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;
}
diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java
index 6cd2204..e637632 100644
--- a/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java
+++ b/src/org/jetbrains/java/decompiler/main/rels/NestedClassProcessor.java
@@ -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;
diff --git a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java
index d8c67ac..8551856 100644
--- a/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java
+++ b/src/org/jetbrains/java/decompiler/main/rels/NestedMemberAccess.java
@@ -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;