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;
import java.util.HashSet;
import java.util.Set;
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);
}
@ -37,15 +37,10 @@ public class VarNamesCollector {
}
public String getFreeName(String proposition) {
while (usedNames.contains(proposition)) {
proposition += "x";
}
usedNames.add(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<MethodWrapper, String> methods = new VBStyleCollection<MethodWrapper, String>();
public ClassWrapper(StructClass classStruct) {
this.classStruct = classStruct;
}
public void init() throws IOException {
DecompilerContext.setProperty(DecompilerContext.CURRENT_CLASS, classStruct);
DecompilerContext.getLogger().startClass(classStruct.qualifiedName);
// collect field names
HashSet<String> setFieldNames = new HashSet<String>();
Set<String> setFieldNames = new HashSet<String>();
for (StructField fd : classStruct.getFields()) {
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()) {
DecompilerContext.getLogger().startMethod(mt.getName() + " " + mt.getDescriptor());
VarNamesCollector vc = new VarNamesCollector();
@ -78,8 +74,8 @@ public class ClassWrapper {
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD, mt);
DecompilerContext.setProperty(DecompilerContext.CURRENT_METHOD_DESCRIPTOR, MethodDescriptor.parseDescriptor(mt.getDescriptor()));
VarProcessor varproc = new VarProcessor();
DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varproc);
VarProcessor varProc = new VarProcessor();
DecompilerContext.setProperty(DecompilerContext.CURRENT_VAR_PROCESSOR, varProc);
RootStatement root = null;
@ -87,62 +83,61 @@ public class ClassWrapper {
try {
if (mt.containsCode()) {
if (maxsec == 0) { // blocking wait
root = MethodProcessorThread.codeToJava(mt, varproc);
if (maxSec == 0) {
root = MethodProcessorRunnable.codeToJava(mt, varProc);
}
else {
MethodProcessorThread mtproc = new MethodProcessorThread(mt, varproc, DecompilerContext.getCurrentContext());
Thread mtthread = new Thread(mtproc);
long stopAt = System.currentTimeMillis() + maxsec * 1000;
MethodProcessorRunnable mtProc = new MethodProcessorRunnable(mt, varProc, DecompilerContext.getCurrentContext());
mtthread.start();
Thread mtThread = new Thread(mtProc);
long stopAt = System.currentTimeMillis() + maxSec * 1000;
while (mtthread.isAlive()) {
mtThread.start();
synchronized (mtproc.lock) {
mtproc.lock.wait(100);
while (mtThread.isAlive()) {
synchronized (mtProc.lock) {
mtProc.lock.wait(100);
}
if (System.currentTimeMillis() >= stopAt) {
String message = "Processing time limit exceeded for method " + mt.getName() + ", execution interrupted.";
DecompilerContext.getLogger().writeMessage(message, IFernflowerLogger.Severity.ERROR);
killThread(mtthread);
killThread(mtThread);
isError = true;
break;
}
}
if (!isError) {
root = mtproc.getResult();
root = mtProc.getResult();
}
}
}
else {
boolean thisvar = !mt.hasModifier(CodeConstants.ACC_STATIC);
boolean thisVar = !mt.hasModifier(CodeConstants.ACC_STATIC);
MethodDescriptor md = MethodDescriptor.parseDescriptor(mt.getDescriptor());
int paramcount = 0;
if (thisvar) {
varproc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName);
paramcount = 1;
int paramCount = 0;
if (thisVar) {
varProc.getThisVars().put(new VarVersionPair(0, 0), classStruct.qualifiedName);
paramCount = 1;
}
paramcount += md.params.length;
paramCount += md.params.length;
int varindex = 0;
for (int i = 0; i < paramcount; i++) {
varproc.setVarName(new VarVersionPair(varindex, 0), vc.getFreeName(varindex));
int varIndex = 0;
for (int i = 0; i < paramCount; i++) {
varProc.setVarName(new VarVersionPair(varIndex, 0), vc.getFreeName(varIndex));
if (thisvar) {
if (thisVar) {
if (i == 0) {
varindex++;
varIndex++;
}
else {
varindex += md.params[i - 1].stackSize;
varIndex += md.params[i - 1].stackSize;
}
}
else {
varindex += md.params[i].stackSize;
varIndex += md.params[i].stackSize;
}
}
}
@ -152,13 +147,13 @@ public class ClassWrapper {
isError = true;
}
MethodWrapper meth = new MethodWrapper(root, varproc, mt, counter);
meth.decompiledWithErrors = isError;
MethodWrapper methodWrapper = new MethodWrapper(root, varProc, mt, counter);
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
varproc.refreshVarNames(new VarNamesCollector(setFieldNames));
varProc.refreshVarNames(new VarNamesCollector(setFieldNames));
// if debug information present and should be used
if (DecompilerContext.getOption(IFernflowerPreferences.USE_DEBUG_VAR_NAMES)) {
@ -166,7 +161,7 @@ public class ClassWrapper {
StructGeneralAttribute.ATTRIBUTE_LOCAL_VARIABLE_TABLE);
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;
public class MethodProcessorThread implements Runnable {
public class MethodProcessorRunnable implements Runnable {
public final Object lock = new Object();
private final StructMethod method;
private final VarProcessor varproc;
private final VarProcessor varProc;
private final DecompilerContext parentContext;
private volatile RootStatement root;
private volatile Throwable error;
public MethodProcessorThread(StructMethod method, VarProcessor varproc, DecompilerContext parentContext) {
public MethodProcessorRunnable(StructMethod method, VarProcessor varProc, DecompilerContext parentContext) {
this.method = method;
this.varproc = varproc;
this.varProc = varProc;
this.parentContext = parentContext;
}
@Override
public void run() {
DecompilerContext.setCurrentContext(parentContext);
error = null;
root = null;
try {
root = codeToJava(method, varproc);
root = codeToJava(method, varProc);
synchronized (lock) {
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();
boolean isInitializer = "<clinit>".equals(mt.getName()); // for now static initializer only
@ -80,29 +79,15 @@ public class MethodProcessorThread implements Runnable {
InstructionSequence seq = mt.getInstructionSequence();
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);
graph.inlineJsr(mt);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern4.dot"), true);
// TODO: move to the start, before jsr inlining
DeadCodeHelper.connectDummyExitBlock(graph);
DeadCodeHelper.removeGotos(graph);
ExceptionDeobfuscator.removeCircularRanges(graph);
//DeadCodeHelper.removeCircularRanges(graph);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
ExceptionDeobfuscator.removeCircularRanges(graph);
ExceptionDeobfuscator.restorePopRanges(graph);
@ -110,15 +95,11 @@ public class MethodProcessorThread implements Runnable {
ExceptionDeobfuscator.removeEmptyRanges(graph);
}
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
if (DecompilerContext.getOption(IFernflowerPreferences.NO_EXCEPTIONS_RETURN)) {
// special case: single return instruction outside of a protected range
DeadCodeHelper.incorporateValueReturns(graph);
}
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern5.dot"), true);
// ExceptionDeobfuscator.restorePopRanges(graph);
ExceptionDeobfuscator.insertEmptyExceptionHandlerBlocks(graph);
@ -126,22 +107,14 @@ public class MethodProcessorThread implements Runnable {
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)) {
DecompilerContext.getLogger().writeMessage("Heavily obfuscated exception ranges found!", IFernflowerLogger.Severity.WARN);
}
RootStatement root = DomHelper.parseGraph(graph);
FinallyProcessor fproc = new FinallyProcessor(varproc);
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());
FinallyProcessor fProc = new FinallyProcessor(varProc);
while (fProc.iterateGraph(mt, root, 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
DomHelper.removeSynchronizedHandler(root);
// DotExporter.toDotFile(graph, new File("c:\\Temp\\fern3.dot"), true);
// System.out.println(graph.toString());
// LabelHelper.lowContinueLabels(root, new HashSet<StatEdge>());
SequenceHelper.condenseSequences(root);
@ -161,20 +131,11 @@ public class MethodProcessorThread implements Runnable {
ExprProcessor proc = new ExprProcessor();
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) {
StackVarsProcessor stackproc = new StackVarsProcessor();
stackproc.simplifyStackVars(root, mt, cl);
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
varproc.setVarVersions(root);
StackVarsProcessor stackProc = new StackVarsProcessor();
stackProc.simplifyStackVars(root, mt, cl);
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
varProc.setVarVersions(root);
if (!new PPandMMHelper().findPPandMM(root)) {
break;
@ -182,11 +143,9 @@ public class MethodProcessorThread implements Runnable {
}
while (true) {
LabelHelper.cleanUpEdges(root);
while (true) {
MergeHelper.enhanceLoops(root);
if (LoopExtractHelper.extractLoops(root)) {
@ -199,22 +158,18 @@ public class MethodProcessorThread implements Runnable {
}
if (DecompilerContext.getOption(IFernflowerPreferences.IDEA_NOT_NULL_ANNOTATION)) {
if (IdeaNotNullHelper.removeHardcodedChecks(root, mt)) {
SequenceHelper.condenseSequences(root);
StackVarsProcessor stackproc = new StackVarsProcessor();
stackproc.simplifyStackVars(root, mt, cl);
StackVarsProcessor stackProc = new StackVarsProcessor();
stackProc.simplifyStackVars(root, mt, cl);
varproc.setVarVersions(root);
varProc.setVarVersions(root);
}
}
LabelHelper.identifyLabels(root);
// System.out.println("~~~~~~~~~~~~~~~~~~~~~~ \r\n"+root.toJava());
if (InlineSingleBlockHelper.inlineSingleBlocks(root)) {
continue;
}
@ -234,7 +189,7 @@ public class MethodProcessorThread implements Runnable {
SecondaryFunctionsHelper.identifySecondaryFunctions(root);
varproc.setVarDefinitions(root);
varProc.setVarDefinitions(root);
// must be the last invocation, because it makes the statement structure inconsistent
// FIXME: new edge type needed
@ -242,8 +197,6 @@ public class MethodProcessorThread implements Runnable {
mt.releaseResources();
// System.out.println("++++++++++++++++++++++/// \r\n"+root.toJava());
return root;
}
Loading…
Cancel
Save