use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.
the class ExceptionEdgeEnhancer method process.
@Override
public void process() {
Set<Integer> positions = new HashSet<Integer>();
for (CodeExceptionGen ceg : exceptions) {
int t1 = ceg.getStartPC().getPosition();
int t2 = ceg.getHandlerPC().getPosition();
positions.add(t1);
positions.add(t2);
}
Map<Integer, InstructionHandle> ivc = new HashMap<Integer, InstructionHandle>();
for (InstructionHandle iv : igc.getGraph().vertexSet()) {
if (positions.contains(iv.getPosition())) {
ivc.put(iv.getPosition(), iv);
}
}
//now, we will map the CEG.
for (CodeExceptionGen ceg : exceptions) {
int t1 = ceg.getStartPC().getPosition();
int t2 = ceg.getHandlerPC().getPosition();
InstructionHandle source = ivc.get(t1);
InstructionHandle target = ivc.get(t2);
IntermediateEdge ie = new IntermediateEdge();
addExceptionHandle(ie, ceg);
ie.setType(EdgeType.EXCEPTION);
igc.getGraph().addEdge(source, target, ie);
}
}
use of org.apache.bcel.generic.CodeExceptionGen in project candle-decompiler by bradsdavis.
the class IntermediateTryCatch method process.
public void process() {
Set<BlockRange> tryBlock = new TreeSet<BlockRange>(new BlockRangeComparator());
Map<BlockRange, List<CodeExceptionGen>> tryRangeGen = new HashMap<BlockRange, List<CodeExceptionGen>>();
Map<InstructionHandle, List<CodeExceptionGen>> tryRangeFinally = new HashMap<InstructionHandle, List<CodeExceptionGen>>();
//create try statements...
for (CodeExceptionGen ceg : method.getExceptionHandlers()) {
InstructionHandle min = ceg.getStartPC();
InstructionHandle max = ceg.getEndPC();
BlockRange tryRange = new BlockRange();
tryRange.setStart(min);
tryRange.setEnd(max);
AbstractIntermediate handle = igc.findNextNode(ceg.getHandlerPC());
LOG.debug("RANGE: " + ceg);
LOG.debug("Range: " + tryRange + " , Target: " + handle.getInstruction().getPosition() + " , Handle: " + handle.getInstruction());
if (ceg.getCatchType() == null) {
if (!tryRangeFinally.containsKey(ceg.getHandlerPC())) {
tryRangeFinally.put(ceg.getHandlerPC(), new LinkedList<CodeExceptionGen>());
}
tryRangeFinally.get(ceg.getHandlerPC()).add(ceg);
continue;
}
tryBlock.add(tryRange);
if (!tryRangeGen.containsKey(tryRange)) {
tryRangeGen.put(tryRange, new LinkedList<CodeExceptionGen>());
}
tryRangeGen.get(tryRange).add(ceg);
}
for (BlockRange tryRange : tryBlock) {
//create try block... create each catch block... link the two together for graph sake.
//look up block...
InstructionHandle start = tryRange.getStart();
TryIntermediate tryIntermediate = new TryIntermediate(start);
tryIntermediate.getBlockRange().setStart(tryRange.getStart());
tryIntermediate.getBlockRange().setEnd(tryRange.getEnd());
igc.getGraph().addVertex(tryIntermediate);
//add line between try and node.
AbstractIntermediate tryFirst = igc.findNextNode(start);
igc.redirectPredecessors(tryFirst, tryIntermediate);
igc.getGraph().addEdge(tryIntermediate, tryFirst);
if (tryRangeGen.containsKey(tryRange)) {
//create catch statements...
for (CodeExceptionGen ceg : tryRangeGen.get(tryRange)) {
generateCatch(tryIntermediate, ceg);
}
}
}
//create a finally node for each handle of finally & link
for (InstructionHandle finallyTargetHandle : tryRangeFinally.keySet()) {
//get reference to target...
AbstractIntermediate finallyTargetNode = igc.findNextNode(finallyTargetHandle);
//change the instruction to a finally...
FinallyIntermediate finallyIntermediate = new FinallyIntermediate(finallyTargetNode.getInstruction(), new HashSet<CodeExceptionGen>(tryRangeFinally.get(finallyTargetHandle)));
igc.getGraph().addVertex(finallyIntermediate);
//now, we need to redirect from the existing throws to finally.
igc.redirectSuccessors(finallyTargetNode, finallyIntermediate);
//retract existing.
igc.getGraph().removeVertex(finallyTargetNode);
}
}
use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.
the class FindUsedConstants method find.
private void find(Method method) {
MethodGen mg = new MethodGen(method, clazz.getClassName(), cpool);
InstructionList il = mg.getInstructionList();
InstructionFinder f = new InstructionFinder(il);
// find instructions that access the constant pool
// collect all indices to constants in ClassInfo
String cpInstr = "CPInstruction";
for (Iterator it = f.search(cpInstr); it.hasNext(); ) {
InstructionHandle[] match = (InstructionHandle[]) it.next();
InstructionHandle first = match[0];
CPInstruction ii = (CPInstruction) first.getInstruction();
int idx = ii.getIndex();
Constant co = cpool.getConstant(idx);
int len = 1;
switch(co.getTag()) {
case Constants.CONSTANT_Long:
case Constants.CONSTANT_Double:
len = 2;
break;
}
// we don't need the field references in the cpool anymore
if (co.getTag() != Constants.CONSTANT_Fieldref) {
getCli().addUsedConst(idx, len);
}
// also modify the index!
// Constant cnst = cpool.getConstant(ii.getIndex());
// int newIndex = addConstant(cnst);
//System.out.println(ii+" -> "+newIndex);
// ii.setIndex(newIndex);
}
il.dispose();
CodeExceptionGen[] et = mg.getExceptionHandlers();
for (int i = 0; i < et.length; i++) {
ObjectType ctype = et[i].getCatchType();
if (ctype != null) {
getCli().addUsedConst(cpool.lookupClass(ctype.getClassName()), 1);
}
}
}
use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.
the class InstructionInterpreter method interpret.
public void interpret(boolean initialize) {
InstructionList il = methodInfo.getCode().getInstructionList(true, false);
InstructionHandle entry = il.getStart();
Map<InstructionHandle, T> start = new HashMap<InstructionHandle, T>();
start.put(entry, initialize ? analysis.initial(entry) : analysis.bottom());
// start at exception handler entries too?
if (startAtExceptionHandlers) {
for (CodeExceptionGen eg : methodInfo.getCode().getExceptionHandlers()) {
InstructionHandle ih = eg.getHandlerPC();
start.put(ih, initialize ? analysis.initial(eg) : analysis.bottom());
}
}
interpret(il, start, initialize);
}
use of org.apache.bcel.generic.CodeExceptionGen in project jop by jop-devel.
the class MethodCode method getStartingExceptionRanges.
/**
* Get a list of all exception ranges which start at this instruction.
* @param ih the instruction to check
* @return a list of all exception ranges with this instruction as start instruction, or an empty list.
*/
public List<CodeExceptionGen> getStartingExceptionRanges(InstructionHandle ih) {
List<CodeExceptionGen> list = new ArrayList<CodeExceptionGen>();
InstructionTargeter[] targeters = ih.getTargeters();
if (targeters == null)
return list;
for (InstructionTargeter t : targeters) {
if (t instanceof CodeExceptionGen) {
CodeExceptionGen ceg = (CodeExceptionGen) t;
if (ceg.getStartPC().equals(ih)) {
list.add(ceg);
}
}
}
return list;
}
Aggregations