Cleanup (unused code; formatting; typos)

master
Roman Shevchenko 10 years ago
parent 0b9402bd45
commit 52a7e1c7e9
  1. 13
      src/org/jetbrains/java/decompiler/main/collectors/VarNamesCollector.java
  2. 71
      src/org/jetbrains/java/decompiler/main/rels/ClassWrapper.java
  3. 81
      src/org/jetbrains/java/decompiler/main/rels/MethodProcessorRunnable.java

@ -16,15 +16,15 @@
package org.jetbrains.java.decompiler.main.collectors; package org.jetbrains.java.decompiler.main.collectors;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
public class VarNamesCollector { public class VarNamesCollector {
private HashSet<String> usedNames = new HashSet<String>(); private Set<String> usedNames = new HashSet<String>();
public VarNamesCollector() { public VarNamesCollector() { }
}
public VarNamesCollector(HashSet<String> setNames) { public VarNamesCollector(Set<String> setNames) {
usedNames.addAll(setNames); usedNames.addAll(setNames);
} }
@ -37,15 +37,10 @@ public class VarNamesCollector {
} }
public String getFreeName(String proposition) { public String getFreeName(String proposition) {
while (usedNames.contains(proposition)) { while (usedNames.contains(proposition)) {
proposition += "x"; proposition += "x";
} }
usedNames.add(proposition); usedNames.add(proposition);
return proposition; return proposition;
} }
public HashSet<String> getUsedNames() {
return usedNames;
}
} }

@ -46,27 +46,23 @@ public class ClassWrapper {
private VBStyleCollection<Exprent, String> dynamicFieldInitializers = new VBStyleCollection<Exprent, String>(); private VBStyleCollection<Exprent, String> dynamicFieldInitializers = new VBStyleCollection<Exprent, String>();
private VBStyleCollection<MethodWrapper, String> methods = new VBStyleCollection<MethodWrapper, String>(); private VBStyleCollection<MethodWrapper, String> methods = new VBStyleCollection<MethodWrapper, String>();
public ClassWrapper(StructClass classStruct) { public ClassWrapper(StructClass classStruct) {
this.classStruct = classStruct; this.classStruct = classStruct;
} }
public void init() throws IOException { public void init() throws IOException {
DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct); DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct);
DecompilerContext.getLogger().startClass(classStruct.qualifiedName); DecompilerContext.getLogger().startClass(classStruct.qualifiedName);
// collect field names // collect field names
HashSet<String> setFieldNames = new HashSet<String>(); Set<String> setFieldNames = new HashSet<String>();
for (StructField fd : classStruct.getFields()) { for (StructField fd : classStruct.getFields()) {
setFieldNames.add(fd.getName()); setFieldNames.add(fd.getName());
} }
int maxsec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString()); int maxSec = Integer.parseInt(DecompilerContext.getProperty(IFernflowerPreferences.MAX_PROCESSING_METHOD).toString());
for (StructMethod mt : classStruct.getMethods()) { for (StructMethod mt : classStruct.getMethods()) {
DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor()); DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor());
VarNamesCollector vc = new VarNamesCollector(); VarNamesCollector vc = new VarNamesCollector();
@ -78,8 +74,8 @@ public class ClassWrapper {
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD, mt); DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD, mt);
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, MethodDescriptor.parseDescriptor(mt.getDescriptor())); DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, MethodDescriptor.parseDescriptor(mt.getDescriptor()));
VarProcessor varproc = new VarProcessor(); VarProcessor varProc = new VarProcessor();
DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc); DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varProc);
RootStatement root = null; RootStatement root = null;
@ -87,62 +83,61 @@ public class ClassWrapper {
try { try {
if (mt.containsCode()) { if (mt.containsCode()) {
if (maxSec == 0) {
if (maxsec == 0) { // blocking wait root = MethodProcessorRunnable.codeToJava(mt, varProc);
root = MethodProcessorThread.codeToJava(mt, varproc);
} }
else { else {
MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext()); MethodProcessorRunnable mtProc = new MethodProcessorRunnable(mt, varProc, DecompilerContext.getCurrentContext());
Thread mtthread = new Thread(mtproc);
long stopAt = System.currentTimeMillis() + maxsec * 1000;
mtthread.start(); Thread mtThread = new Thread(mtProc);
long stopAt = System.currentTimeMillis() + maxSec * 1000;
while (mtthread.isAlive()) { mtThread.start();
synchronized (mtproc.lock) { while (mtThread.isAlive()) {
mtproc.lock.wait(100); synchronized (mtProc.lock) {
mtProc.lock.wait(100);
} }
if (System.currentTimeMillis() >= stopAt) { if (System.currentTimeMillis() >= stopAt) {
String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted."; String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted.";
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR); DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR);
killThread(mtthread); killThread(mtThread);
isError = true; isError = true;
break; break;
} }
} }
if (!isError) { if (!isError) {
root = mtproc.getResult(); root = mtProc.getResult();
} }
} }
} }
else { else {
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC); boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC);
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor()); MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
int paramcount = 0; int paramCount = 0;
if (thisvar) { if (thisVar) {
varproc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName); varProc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName);
paramcount = 1; paramCount = 1;
} }
paramcount += md.params.length; paramCount += md.params.length;
int varindex = 0; int varIndex = 0;
for (int i = 0; i < paramcount; i++) { for (int i = 0; i < paramCount; i++) {
varproc.setVarName(new VarVersionPair(varindex, 0), vc.getFreeName(varindex)); varProc.setVarName(new VarVersionPair(varIndex, 0), vc.getFreeName(varIndex));
if (thisvar) { if (thisVar) {
if (i == 0) { if (i == 0) {
varindex++; varIndex++;
} }
else { else {
varindex += md.params[i - 1].stackSize; varIndex += md.params[i - 1].stackSize;
} }
} }
else { else {
varindex += md.params[i].stackSize; varIndex += md.params[i].stackSize;
} }
} }
} }
@ -152,13 +147,13 @@ public class ClassWrapper {
isError = true; isError = true;
} }
MethodWrapper meth = new MethodWrapper(root, varproc, mt, counter); MethodWrapper methodWrapper = new MethodWrapper(root, varProc, mt, counter);
meth.decompiledWithErrors = isError; methodWrapper.decompiledWithErrors = isError;
methods.addWithKey(meth, InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor())); methods.addWithKey(methodWrapper, InterpreterUtil.makeUniqueKey(mt.getName(), mt.getDescriptor()));
// rename vars so that no one has the same name as a field // rename vars so that no one has the same name as a field
varproc.refreshVarNames(new VarNamesCollector(setFieldNames)); varProc.refreshVarNames(new VarNamesCollector(setFieldNames));
// if debug information present and should be used // if debug information present and should be used
if (DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_VAR_NAMES)) { if (DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_VAR_NAMES)) {
@ -166,7 +161,7 @@ public class ClassWrapper {
StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE); StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
if (attr != null) { if (attr != null) {
varproc.setDebugVarNames(attr.getMapVarNames()); varProc.setDebugVarNames(attr.getMapVarNames());
} }
} }

@ -31,32 +31,32 @@ import org.jetbrains.java.decompiler.struct.StructMethod;
import java.io.IOException; import java.io.IOException;
public class MethodProcessorThread implements Runnable { public class MethodProcessorRunnable implements Runnable {
public final Object lock = new Object(); public final Object lock = new Object();
private final StructMethod method; private final StructMethod method;
private final VarProcessor varproc; private final VarProcessor varProc;
private final DecompilerContext parentContext; private final DecompilerContext parentContext;
private volatile RootStatement root; private volatile RootStatement root;
private volatile Throwable error; private volatile Throwable error;
public MethodProcessorThread(StructMethod method, VarProcessor varproc, DecompilerContext parentContext) { public MethodProcessorRunnable(StructMethod method, VarProcessor varProc, DecompilerContext parentContext) {
this.method = method; this.method = method;
this.varproc = varproc; this.varProc = varProc;
this.parentContext = parentContext; this.parentContext = parentContext;
} }
@Override
public void run() { public void run() {
DecompilerContext.setCurrentContext(parentContext); DecompilerContext.setCurrentContext(parentContext);
error = null; error = null;
root = null; root = null;
try { try {
root = codeToJava(method, varproc); root = codeToJava(method, varProc);
synchronized (lock) { synchronized (lock) {
lock.notifyAll(); lock.notifyAll();
@ -70,8 +70,7 @@ public class MethodProcessorThread implements Runnable {
} }
} }
public static RootStatement codeToJava(StructMethod mt, VarProcessor varproc) throws IOException { public static RootStatement codeToJava(StructMethod mt, VarProcessor varProc) throws IOException {
StructClass cl = mt.getClassStruct(); StructClass cl = mt.getClassStruct();
boolean isInitializer = "<clinit>".equals(mt.getName()); // for now static initializer only boolean isInitializer = "<clinit>".equals(mt.getName()); // for now static initializer only
@ -80,29 +79,15 @@ public class MethodProcessorThread implements Runnable {
InstructionSequence seq = mt.getInstructionSequence(); InstructionSequence seq = mt.getInstructionSequence();
ControlFlowGraph graph = new ControlFlowGraph(seq); ControlFlowGraph graph = new ControlFlowGraph(seq);
// System.out.println(graph.toString());
// if(mt.getName().endsWith("_getActiveServers")) {
// System.out.println();
// }
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern1.dot"), true);
DeadCodeHelper.removeDeadBlocks(graph); DeadCodeHelper.removeDeadBlocks(graph);
graph.inlineJsr(mt); graph.inlineJsr(mt);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern4.dot"), true);
// TODO: move to the start, before jsr inlining // TODO: move to the start, before jsr inlining
DeadCodeHelper.connectDummyExitBlock(graph); DeadCodeHelper.connectDummyExitBlock(graph);
DeadCodeHelper.removeGotos(graph); DeadCodeHelper.removeGotos(graph);
ExceptionDeobfuscator.removeCircularRanges(graph);
//DeadCodeHelper.removeCircularRanges(graph);
ExceptionDeobfuscator.removeCircularRanges(graph);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
ExceptionDeobfuscator.restorePopRanges(graph); ExceptionDeobfuscator.restorePopRanges(graph);
@ -110,15 +95,11 @@ public class MethodProcessorThread implements Runnable {
ExceptionDeobfuscator.removeEmptyRanges(graph); ExceptionDeobfuscator.removeEmptyRanges(graph);
} }
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
if (DecompilerContext.getOption(IFernflowerPreferences.NO_EXCEPTIONS_RETURN)) { if (DecompilerContext.getOption(IFernflowerPreferences.NO_EXCEPTIONS_RETURN)) {
// special case: single return instruction outside of a protected range // special case: single return instruction outside of a protected range
DeadCodeHelper.incorporateValueReturns(graph); DeadCodeHelper.incorporateValueReturns(graph);
} }
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern5.dot"), true);
// ExceptionDeobfuscator.restorePopRanges(graph); // ExceptionDeobfuscator.restorePopRanges(graph);
ExceptionDeobfuscator.insertEmptyExceptionHandlerBlocks(graph); ExceptionDeobfuscator.insertEmptyExceptionHandlerBlocks(graph);
@ -126,22 +107,14 @@ public class MethodProcessorThread implements Runnable {
DecompilerContext.getCounterContainer().setCounter(CounterContainer.VAR_COUNTER, mt.getLocalVariables()); DecompilerContext.getCounterContainer().setCounter(CounterContainer.VAR_COUNTER, mt.getLocalVariables());
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
//System.out.println(graph.toString());
if (ExceptionDeobfuscator.hasObfuscatedExceptions(graph)) { if (ExceptionDeobfuscator.hasObfuscatedExceptions(graph)) {
DecompilerContext.getLogger().writeMessage("Heavily obfuscated exception ranges found!", IFernflowerLogger.Severity.WARN); DecompilerContext.getLogger().writeMessage("Heavily obfuscated exception ranges found!", IFernflowerLogger.Severity.WARN);
} }
RootStatement root = DomHelper.parseGraph(graph); RootStatement root = DomHelper.parseGraph(graph);
FinallyProcessor fproc = new FinallyProcessor(varproc); FinallyProcessor fProc = new FinallyProcessor(varProc);
while (fproc.iterateGraph(mt, root, graph)) { while (fProc.iterateGraph(mt, root, graph)) {
//DotExporter.toDotFile(graph, new File("c:\\Temp\\fern2.dot"), true);
//System.out.println(graph.toString());
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
root = DomHelper.parseGraph(graph); root = DomHelper.parseGraph(graph);
} }
@ -149,9 +122,6 @@ public class MethodProcessorThread implements Runnable {
// not until now because of comparison between synchronized statements in the finally cycle // not until now because of comparison between synchronized statements in the finally cycle
DomHelper.removeSynchronizedHandler(root); DomHelper.removeSynchronizedHandler(root);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
// System.out.println(graph.toString());
// LabelHelper.lowContinueLabels(root, new HashSet<StatEdge>()); // LabelHelper.lowContinueLabels(root, new HashSet<StatEdge>());
SequenceHelper.condenseSequences(root); SequenceHelper.condenseSequences(root);
@ -161,20 +131,11 @@ public class MethodProcessorThread implements Runnable {
ExprProcessor proc = new ExprProcessor(); ExprProcessor proc = new ExprProcessor();
proc.processStatement(root, cl); proc.processStatement(root, cl);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
// System.out.println(graph.toString());
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
while (true) { while (true) {
StackVarsProcessor stackproc = new StackVarsProcessor(); StackVarsProcessor stackProc = new StackVarsProcessor();
stackproc.simplifyStackVars(root, mt, cl); stackProc.simplifyStackVars(root, mt, cl);
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
varproc.setVarVersions(root);
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava()); varProc.setVarVersions(root);
if (!new PPandMMHelper().findPPandMM(root)) { if (!new PPandMMHelper().findPPandMM(root)) {
break; break;
@ -182,11 +143,9 @@ public class MethodProcessorThread implements Runnable {
} }
while (true) { while (true) {
LabelHelper.cleanUpEdges(root); LabelHelper.cleanUpEdges(root);
while (true) { while (true) {
MergeHelper.enhanceLoops(root); MergeHelper.enhanceLoops(root);
if (LoopExtractHelper.extractLoops(root)) { if (LoopExtractHelper.extractLoops(root)) {
@ -199,22 +158,18 @@ public class MethodProcessorThread implements Runnable {
} }
if (DecompilerContext.getOption(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION)) { if (DecompilerContext.getOption(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION)) {
if (IdeaNotNullHelper.removeHardcodedChecks(root, mt)) { if (IdeaNotNullHelper.removeHardcodedChecks(root, mt)) {
SequenceHelper.condenseSequences(root); SequenceHelper.condenseSequences(root);
StackVarsProcessor stackproc = new StackVarsProcessor(); StackVarsProcessor stackProc = new StackVarsProcessor();
stackproc.simplifyStackVars(root, mt, cl); stackProc.simplifyStackVars(root, mt, cl);
varproc.setVarVersions(root); varProc.setVarVersions(root);
} }
} }
LabelHelper.identifyLabels(root); LabelHelper.identifyLabels(root);
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
if (InlineSingleBlockHelper.inlineSingleBlocks(root)) { if (InlineSingleBlockHelper.inlineSingleBlocks(root)) {
continue; continue;
} }
@ -234,7 +189,7 @@ public class MethodProcessorThread implements Runnable {
SecondaryFunctionsHelper.identifySecondaryFunctions(root); SecondaryFunctionsHelper.identifySecondaryFunctions(root);
varproc.setVarDefinitions(root); varProc.setVarDefinitions(root);
// must be the last invocation, because it makes the statement structure inconsistent // must be the last invocation, because it makes the statement structure inconsistent
// FIXME: new edge type needed // FIXME: new edge type needed
@ -242,8 +197,6 @@ public class MethodProcessorThread implements Runnable {
mt.releaseResources(); mt.releaseResources();
// System.out.println("++++++++++++++++++++++/// \r\n"+root.toJava());
return root; return root;
} }
Loading…
Cancel
Save