[java decompiler] cleanup (dead code; optimizations; warnings)
This commit is contained in:
@@ -16,8 +16,7 @@ public class BasicBlock implements IGraphNode {
|
||||
// public fields
|
||||
// *****************************************************************************
|
||||
|
||||
public int id = 0;
|
||||
|
||||
public int id;
|
||||
public int mark = 0;
|
||||
|
||||
// *****************************************************************************
|
||||
@@ -26,15 +25,11 @@ public class BasicBlock implements IGraphNode {
|
||||
|
||||
private InstructionSequence seq = new SimpleInstructionSequence();
|
||||
|
||||
private List<BasicBlock> preds = new ArrayList<>();
|
||||
|
||||
private List<BasicBlock> succs = new ArrayList<>();
|
||||
|
||||
private final List<BasicBlock> preds = new ArrayList<>();
|
||||
private final List<BasicBlock> succs = new ArrayList<>();
|
||||
private final List<Integer> instrOldOffsets = new ArrayList<>();
|
||||
|
||||
private List<BasicBlock> predExceptions = new ArrayList<>();
|
||||
|
||||
private List<BasicBlock> succExceptions = new ArrayList<>();
|
||||
private final List<BasicBlock> predExceptions = new ArrayList<>();
|
||||
private final List<BasicBlock> succExceptions = new ArrayList<>();
|
||||
|
||||
public BasicBlock(int id) {
|
||||
this.id = id;
|
||||
@@ -44,7 +39,9 @@ public class BasicBlock implements IGraphNode {
|
||||
// public methods
|
||||
// *****************************************************************************
|
||||
|
||||
public Object clone() {
|
||||
@Override
|
||||
@SuppressWarnings("MethodDoesntCallSuperMethod")
|
||||
public BasicBlock clone() {
|
||||
BasicBlock block = new BasicBlock(id);
|
||||
|
||||
block.setSeq(seq.clone());
|
||||
@@ -53,14 +50,6 @@ public class BasicBlock implements IGraphNode {
|
||||
return block;
|
||||
}
|
||||
|
||||
public void free() {
|
||||
preds.clear();
|
||||
succs.clear();
|
||||
instrOldOffsets.clear();
|
||||
succExceptions.clear();
|
||||
seq = new SimpleInstructionSequence();
|
||||
}
|
||||
|
||||
public Instruction getInstruction(int index) {
|
||||
return seq.getInstr(index);
|
||||
}
|
||||
@@ -91,7 +80,7 @@ public class BasicBlock implements IGraphNode {
|
||||
}
|
||||
|
||||
public void removePredecessor(BasicBlock block) {
|
||||
while (preds.remove(block)) ;
|
||||
while (preds.remove(block)) /**/;
|
||||
}
|
||||
|
||||
public void addSuccessor(BasicBlock block) {
|
||||
@@ -100,7 +89,7 @@ public class BasicBlock implements IGraphNode {
|
||||
}
|
||||
|
||||
public void removeSuccessor(BasicBlock block) {
|
||||
while (succs.remove(block)) ;
|
||||
while (succs.remove(block)) /**/;
|
||||
block.removePredecessor(this);
|
||||
}
|
||||
|
||||
@@ -128,7 +117,7 @@ public class BasicBlock implements IGraphNode {
|
||||
}
|
||||
|
||||
public void removePredecessorException(BasicBlock block) {
|
||||
while (predExceptions.remove(block)) ;
|
||||
while (predExceptions.remove(block)) /**/;
|
||||
}
|
||||
|
||||
public void addSuccessorException(BasicBlock block) {
|
||||
@@ -139,7 +128,7 @@ public class BasicBlock implements IGraphNode {
|
||||
}
|
||||
|
||||
public void removeSuccessorException(BasicBlock block) {
|
||||
while (succExceptions.remove(block)) ;
|
||||
while (succExceptions.remove(block)) /**/;
|
||||
block.removePredecessorException(this);
|
||||
}
|
||||
|
||||
@@ -154,27 +143,6 @@ public class BasicBlock implements IGraphNode {
|
||||
return id + ":" + new_line_separator + seq.toString(indent);
|
||||
}
|
||||
|
||||
public String toStringOldIndices() {
|
||||
|
||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < seq.length(); i++) {
|
||||
if (i < instrOldOffsets.size()) {
|
||||
buf.append(instrOldOffsets.get(i));
|
||||
}
|
||||
else {
|
||||
buf.append("-1");
|
||||
}
|
||||
buf.append(": ");
|
||||
buf.append(seq.getInstr(i).toString());
|
||||
buf.append(new_line_separator);
|
||||
}
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public boolean isSuccessor(BasicBlock block) {
|
||||
for (BasicBlock succ : succs) {
|
||||
if (succ.id == block.id) {
|
||||
@@ -184,15 +152,6 @@ public class BasicBlock implements IGraphNode {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isPredecessor(BasicBlock block) {
|
||||
for (int i = 0; i < preds.size(); i++) {
|
||||
if (preds.get(i).id == block.id) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// *****************************************************************************
|
||||
// getter and setter methods
|
||||
// *****************************************************************************
|
||||
@@ -211,10 +170,6 @@ public class BasicBlock implements IGraphNode {
|
||||
return preds;
|
||||
}
|
||||
|
||||
public void setPreds(List<BasicBlock> preds) {
|
||||
this.preds = preds;
|
||||
}
|
||||
|
||||
public InstructionSequence getSeq() {
|
||||
return seq;
|
||||
}
|
||||
@@ -227,25 +182,11 @@ public class BasicBlock implements IGraphNode {
|
||||
return succs;
|
||||
}
|
||||
|
||||
public void setSuccs(List<BasicBlock> succs) {
|
||||
this.succs = succs;
|
||||
}
|
||||
|
||||
|
||||
public List<BasicBlock> getSuccExceptions() {
|
||||
return succExceptions;
|
||||
}
|
||||
|
||||
|
||||
public void setSuccExceptions(List<BasicBlock> succExceptions) {
|
||||
this.succExceptions = succExceptions;
|
||||
}
|
||||
|
||||
public List<BasicBlock> getPredExceptions() {
|
||||
return predExceptions;
|
||||
}
|
||||
|
||||
public void setPredExceptions(List<BasicBlock> predExceptions) {
|
||||
this.predExceptions = predExceptions;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
|
||||
private Map<BasicBlock, BasicBlock> subroutines;
|
||||
|
||||
private Set<BasicBlock> finallyExits = new HashSet<>();
|
||||
private final Set<BasicBlock> finallyExits = new HashSet<>();
|
||||
|
||||
// *****************************************************************************
|
||||
// constructors
|
||||
@@ -48,19 +48,6 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
// public methods
|
||||
// *****************************************************************************
|
||||
|
||||
public void free() {
|
||||
|
||||
for (BasicBlock block : blocks) {
|
||||
block.free();
|
||||
}
|
||||
|
||||
blocks.clear();
|
||||
first = null;
|
||||
last = null;
|
||||
exceptions.clear();
|
||||
finallyExits.clear();
|
||||
}
|
||||
|
||||
public void removeMarkers() {
|
||||
for (BasicBlock block : blocks) {
|
||||
block.mark = 0;
|
||||
@@ -80,12 +67,11 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
buf.append("----- Edges -----").append(new_line_separator);
|
||||
|
||||
List<BasicBlock> suc = block.getSuccs();
|
||||
for (int j = 0; j < suc.size(); j++) {
|
||||
buf.append(">>>>>>>>(regular) Block ").append(suc.get(j).id).append(new_line_separator);
|
||||
for (BasicBlock aSuc : suc) {
|
||||
buf.append(">>>>>>>>(regular) Block ").append(aSuc.id).append(new_line_separator);
|
||||
}
|
||||
suc = block.getSuccExceptions();
|
||||
for (int j = 0; j < suc.size(); j++) {
|
||||
BasicBlock handler = suc.get(j);
|
||||
for (BasicBlock handler : suc) {
|
||||
ExceptionRangeCFG range = getExceptionRange(handler, block);
|
||||
|
||||
if (range == null) {
|
||||
@@ -156,13 +142,7 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<Entry<BasicBlock, BasicBlock>> it = subroutines.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Entry<BasicBlock, BasicBlock> ent = it.next();
|
||||
if (ent.getKey() == block || ent.getValue() == block) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
subroutines.entrySet().removeIf(ent -> ent.getKey() == block || ent.getValue() == block);
|
||||
}
|
||||
|
||||
public ExceptionRangeCFG getExceptionRange(BasicBlock handler, BasicBlock block) {
|
||||
@@ -261,7 +241,7 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
for (int j = dests.length - 1; j >= 0; j--) {
|
||||
inststates[dests[j]] = 1;
|
||||
}
|
||||
inststates[swinstr.getDefaultdest()] = 1;
|
||||
inststates[swinstr.getDefaultDestination()] = 1;
|
||||
if (i + 1 < len) {
|
||||
inststates[i + 1] = 1;
|
||||
}
|
||||
@@ -322,7 +302,7 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
BasicBlock block = lstbb.get(i);
|
||||
Instruction instr = block.getLastInstruction();
|
||||
|
||||
boolean fallthrough = instr.canFallthrough();
|
||||
boolean fallthrough = instr.canFallThrough();
|
||||
BasicBlock bTemp;
|
||||
|
||||
switch (instr.group) {
|
||||
@@ -336,10 +316,10 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
SwitchInstruction sinstr = (SwitchInstruction)instr;
|
||||
int[] dests = sinstr.getDestinations();
|
||||
|
||||
bTemp = mapInstrBlocks.get(((SwitchInstruction)instr).getDefaultdest());
|
||||
bTemp = mapInstrBlocks.get(((SwitchInstruction)instr).getDefaultDestination());
|
||||
block.addSuccessor(bTemp);
|
||||
for (int j = 0; j < dests.length; j++) {
|
||||
bTemp = mapInstrBlocks.get(dests[j]);
|
||||
for (int dest1 : dests) {
|
||||
bTemp = mapInstrBlocks.get(dest1);
|
||||
block.addSuccessor(bTemp);
|
||||
}
|
||||
}
|
||||
@@ -617,9 +597,8 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
node.replaceSuccessor(child, mapNewNodes.get(childid));
|
||||
}
|
||||
else if (common_blocks.contains(child)) {
|
||||
|
||||
// make a copy of the current block
|
||||
BasicBlock copy = (BasicBlock)child.clone();
|
||||
BasicBlock copy = child.clone();
|
||||
copy.id = ++last_id;
|
||||
// copy all successors
|
||||
if (copy.getLastInstruction().opcode == CodeConstants.opc_ret &&
|
||||
@@ -816,10 +795,6 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public void setBlocks(VBStyleCollection<BasicBlock, Integer> blocks) {
|
||||
this.blocks = blocks;
|
||||
}
|
||||
|
||||
public BasicBlock getFirst() {
|
||||
return first;
|
||||
}
|
||||
@@ -828,39 +803,15 @@ public class ControlFlowGraph implements CodeConstants {
|
||||
this.first = first;
|
||||
}
|
||||
|
||||
public List<BasicBlock> getEndBlocks() {
|
||||
return last.getPreds();
|
||||
}
|
||||
|
||||
public List<ExceptionRangeCFG> getExceptions() {
|
||||
return exceptions;
|
||||
}
|
||||
|
||||
public void setExceptions(List<ExceptionRangeCFG> exceptions) {
|
||||
this.exceptions = exceptions;
|
||||
}
|
||||
|
||||
public BasicBlock getLast() {
|
||||
return last;
|
||||
}
|
||||
|
||||
public void setLast(BasicBlock last) {
|
||||
this.last = last;
|
||||
}
|
||||
|
||||
public Map<BasicBlock, BasicBlock> getSubroutines() {
|
||||
return subroutines;
|
||||
}
|
||||
|
||||
public void setSubroutines(Map<BasicBlock, BasicBlock> subroutines) {
|
||||
this.subroutines = subroutines;
|
||||
}
|
||||
|
||||
public Set<BasicBlock> getFinallyExits() {
|
||||
return finallyExits;
|
||||
}
|
||||
|
||||
public void setFinallyExits(HashSet<BasicBlock> finallyExits) {
|
||||
this.finallyExits = finallyExits;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,13 @@
|
||||
// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package org.jetbrains.java.decompiler.code.cfg;
|
||||
|
||||
import org.jetbrains.java.decompiler.main.DecompilerContext;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ExceptionRangeCFG {
|
||||
|
||||
private List<BasicBlock> protectedRange = new ArrayList<>(); // FIXME: replace with set
|
||||
|
||||
private final List<BasicBlock> protectedRange; // FIXME: replace with set
|
||||
private BasicBlock handler;
|
||||
|
||||
private List<String> exceptionTypes;
|
||||
|
||||
public ExceptionRangeCFG(List<BasicBlock> protectedRange, BasicBlock handler, List<String> exceptionType) {
|
||||
@@ -28,28 +23,6 @@ public class ExceptionRangeCFG {
|
||||
return protectedRange.contains(handler);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
String new_line_separator = DecompilerContext.getNewLineSeparator();
|
||||
|
||||
StringBuilder buf = new StringBuilder();
|
||||
|
||||
buf.append("exceptionType:");
|
||||
for (String exception_type : exceptionTypes) {
|
||||
buf.append(" ").append(exception_type);
|
||||
}
|
||||
buf.append(new_line_separator);
|
||||
|
||||
buf.append("handler: ").append(handler.id).append(new_line_separator);
|
||||
buf.append("range: ");
|
||||
for (int i = 0; i < protectedRange.size(); i++) {
|
||||
buf.append(protectedRange.get(i).id).append(" ");
|
||||
}
|
||||
buf.append(new_line_separator);
|
||||
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
public BasicBlock getHandler() {
|
||||
return handler;
|
||||
}
|
||||
@@ -62,16 +35,11 @@ public class ExceptionRangeCFG {
|
||||
return protectedRange;
|
||||
}
|
||||
|
||||
public void setProtectedRange(List<BasicBlock> protectedRange) {
|
||||
this.protectedRange = protectedRange;
|
||||
}
|
||||
|
||||
public List<String> getExceptionTypes() {
|
||||
return this.exceptionTypes;
|
||||
}
|
||||
|
||||
public void addExceptionType(String exceptionType) {
|
||||
|
||||
if (this.exceptionTypes == null) {
|
||||
return;
|
||||
}
|
||||
@@ -85,16 +53,6 @@ public class ExceptionRangeCFG {
|
||||
}
|
||||
|
||||
public String getUniqueExceptionsString() {
|
||||
|
||||
if (exceptionTypes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return exceptionTypes.stream().distinct().collect(Collectors.joining(":"));
|
||||
return exceptionTypes != null ? exceptionTypes.stream().distinct().collect(Collectors.joining(":")) : null;
|
||||
}
|
||||
|
||||
|
||||
// public void setExceptionType(String exceptionType) {
|
||||
// this.exceptionType = exceptionType;
|
||||
// }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user