/** * implements the visitor to reset the opcode stack, and initialize if tracking collections * * @param classContext * the currently parsed java class */ @Override public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); ifBlocks = new IfBlocks(); gotoBranchPCs = new BitSet(); casePositions = new BitSet(); super.visitClassContext(classContext); } finally { stack = null; ifBlocks = null; catchPCs = null; gotoBranchPCs = null; casePositions = null; } }
public void add(IfBlock block) { if (blocks.isEmpty()) { blocks.addLast(block); return; } IfBlock lastBlock = blocks.getLast(); if (block.getStart() > lastBlock.getEnd()) { blocks.addLast(block); } else { lastBlock.getSubIfBlocks().add(block); } }
@Override public void visitCode(Code obj) { Method m = getMethod(); if (m.getReturnType() == Type.VOID) { return; } stack.resetForMethodEntry(this); ifBlocks.clear(); activeUnconditional = null; CodeException[] ces = obj.getExceptionTable(); if (CollectionUtils.isEmpty(ces)) { catchPCs = null; } else { catchPCs = new BitSet(); for (CodeException ce : ces) { catchPCs.set(ce.getHandlerPC()); } } gotoBranchPCs.clear(); casePositions.clear(); lookingForResetOp = false; try { super.visitCode(obj); } catch (StopOpcodeParsingException e) { // reported an issue, so get out } }
int blockCount = ifBlocks.countBlockEndsAtPC(getPC()); gotoBranchPCs.set(target); } else if ((catchPCs == null) || !catchPCs.get(getNextPC())) { ifBlocks.add(new IfBlock(getNextPC(), target)); ifBlocks.removeLoopBlocks(target); IfBlock blockAtPC = ifBlocks.getBlockAt(getPC()); if ((blockAtPC != null) && (getNextPC() == blockAtPC.getEnd()) && !gotoAcrossPC(getNextPC())) { activeUnconditional = blockAtPC;
int blockCount = ifBlocks.countBlockEndsAtPC(getPC()); gotoBranchPCs.set(target); } else if ((catchPCs == null) || !catchPCs.get(getNextPC())) { ifBlocks.add(new IfBlock(getNextPC(), target)); ifBlocks.removeLoopBlocks(target); IfBlock blockAtPC = ifBlocks.getBlockAt(getPC()); if ((blockAtPC != null) && (getNextPC() == blockAtPC.getEnd()) && !gotoAcrossPC(getNextPC())) { activeUnconditional = blockAtPC;
/** * counts all blocks including nested block that are closed off at the current pc * * @param pc * the current pc * @return how many blocks have ended at the pc */ public int countBlockEndsAtPC(int pc) { if (blocks.isEmpty()) { return 0; } int count = 0; Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if (pc >= block.getStart()) { if (block.hasSubBlocks()) { count += block.getSubIfBlocks().countBlockEndsAtPC(pc); } } if (pc == block.getEnd()) { count++; } } return count; }
/** * counts all blocks including nested block that are closed off at the current pc * * @param pc * the current pc * @return how many blocks have ended at the pc */ public int countBlockEndsAtPC(int pc) { if (blocks.isEmpty()) { return 0; } int count = 0; Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if (pc >= block.getStart()) { if (block.hasSubBlocks()) { count += block.getSubIfBlocks().countBlockEndsAtPC(pc); } } if (pc == block.getEnd()) { count++; } } return count; }
@Override public void visitCode(Code obj) { Method m = getMethod(); if (m.getReturnType() == Type.VOID) { return; } stack.resetForMethodEntry(this); ifBlocks.clear(); activeUnconditional = null; CodeException[] ces = obj.getExceptionTable(); if (CollectionUtils.isEmpty(ces)) { catchPCs = null; } else { catchPCs = new BitSet(); for (CodeException ce : ces) { catchPCs.set(ce.getHandlerPC()); } } gotoBranchPCs.clear(); casePositions.clear(); lookingForResetOp = false; try { super.visitCode(obj); } catch (StopOpcodeParsingException e) { // reported an issue, so get out } }
@Nullable public IfBlock getBlockAt(int pc) { if (blocks.isEmpty()) { return null; } Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if ((pc >= block.getStart()) && (pc <= block.getEnd())) { if (block.hasSubBlocks()) { IfBlock foundBlock = block.getSubIfBlocks().getBlockAt(pc); if (foundBlock != null) { return foundBlock; } } return block; } } return null; }
/** * implements the visitor to reset the opcode stack, and initialize if tracking collections * * @param classContext * the currently parsed java class */ @Override public void visitClassContext(ClassContext classContext) { try { stack = new OpcodeStack(); ifBlocks = new IfBlocks(); gotoBranchPCs = new BitSet(); casePositions = new BitSet(); super.visitClassContext(classContext); } finally { stack = null; ifBlocks = null; catchPCs = null; gotoBranchPCs = null; casePositions = null; } }
@Nullable public IfBlock getBlockAt(int pc) { if (blocks.isEmpty()) { return null; } Iterator<IfBlock> it = blocks.iterator(); while (it.hasNext()) { IfBlock block = it.next(); if ((pc >= block.getStart()) && (pc <= block.getEnd())) { if (block.hasSubBlocks()) { IfBlock foundBlock = block.getSubIfBlocks().getBlockAt(pc); if (foundBlock != null) { return foundBlock; } } return block; } } return null; }
public boolean hasSubBlocks() { return (subBlocks == null) || !subBlocks.isEmpty(); }
public boolean hasSubBlocks() { return (subBlocks == null) || !subBlocks.isEmpty(); }
public IfBlocks getSubIfBlocks() { if (subBlocks == null) { subBlocks = new IfBlocks(); } return subBlocks; }
public void add(IfBlock block) { if (blocks.isEmpty()) { blocks.addLast(block); return; } IfBlock lastBlock = blocks.getLast(); if (block.getStart() > lastBlock.getEnd()) { blocks.addLast(block); } else { lastBlock.getSubIfBlocks().add(block); } }
public IfBlocks getSubIfBlocks() { if (subBlocks == null) { subBlocks = new IfBlocks(); } return subBlocks; }