public void visitAnySwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SwitchInstruction switchInstruction) { // Mark the branch origin. markBranchOrigin(offset); // Check if this is the first instruction of a subroutine. checkSubroutine(offset); // Mark the branch targets of the default jump offset. markBranchTarget(offset, switchInstruction.defaultOffset); // Mark the branch targets of the jump offsets. markBranchTargets(offset, switchInstruction.jumpOffsets); // Mark the next instruction. markAfterBranchOrigin(offset + switchInstruction.length(offset)); }
/** * Returns whether the instruction at the given offset is the origin of a * branch instruction. */ public boolean isBranchOrigin(int instructionOffset) { return branchTargetFinder.isBranchOrigin(instructionOffset); }
/** * Returns whether the instruction at the given offset is the target of a * branch instruction or an exception. */ public boolean isBranchOrExceptionTarget(int instructionOffset) { return branchTargetFinder.isBranchTarget(instructionOffset) || branchTargetFinder.isExceptionHandler(instructionOffset); }
public void visitAnySwitchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SwitchInstruction switchInstruction) { // Mark the branch origin. markBranchOrigin(offset); // Check if this is an instruction of a subroutine. checkSubroutine(offset); // Mark the branch targets of the default jump offset. markBranch(offset, switchInstruction.defaultOffset); // Mark the branch targets of the jump offsets. markBranches(offset, switchInstruction.jumpOffsets); // Mark the next instruction. markAfterBranchOrigin(offset + switchInstruction.length(offset)); }
if (branchTargetFinder.isInstruction(newOffset1) ^ branchTargetFinder.isInstruction(newOffset2)) if (branchTargetFinder.isInstruction(newOffset1) && branchTargetFinder.isInstruction(newOffset2)) if (branchTargetFinder.isBranchOrigin(newOffset1) || branchTargetFinder.isBranchTarget(newOffset1) || branchTargetFinder.isExceptionStart(newOffset1) || branchTargetFinder.isExceptionEnd(newOffset1) || branchTargetFinder.isInitializer(newOffset1) || branchTargetFinder.isExceptionStart(newOffset2) || branchTargetFinder.isExceptionEnd(newOffset2) || isPop(code[newOffset1])) if (branchTargetFinder.isBranchTarget(newOffset2)) if (branchTargetFinder.isBranchTarget(newOffset1))
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction) { // Mark the instruction. instructionMarks[offset] |= INSTRUCTION; // Check if this is the first instruction of a subroutine. checkSubroutine(offset); if (variableInstruction.opcode == InstructionConstants.OP_RET) { // Mark the branch origin. markBranchOrigin(offset); // Mark the regular subroutine return. instructionMarks[offset] |= SUBROUTINE_RETURNING; // Mark the next instruction. markAfterBranchOrigin(offset + variableInstruction.length(offset)); } }
public void visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute) branchTargetFinder.visitCodeAttribute(clazz, method, codeAttribute); if (!branchTargetFinder.containsSubroutines()) if (branchTargetFinder.isSubroutine(offset) && branchTargetFinder.isSubroutineReturning(offset))
if (isInstruction(index)) if (isSubroutineStart(index)) if (isSubroutine(index)) if (isSubroutineReturning(index)) if (isInstruction(index)) (isExceptionHandler(index) ? 'H' : '-') + (isSubroutineInvocation(index) ? 'J' : '-') + (isSubroutineStart(index) ? 'S' : '-') + (isSubroutineReturning(index) ? 'r' : '-') + (isSubroutine(index) ? " ["+subroutineStart(index)+" -> "+subroutineEnd(index)+"]" : "") + (isNew(index) ? " ["+initializationOffset(index)+"] " : " ---- ") +
if (isInstruction(offset)) isSubroutineReturning(offset)) if (isSubroutine(offset)) if (isSubroutineReturning(subroutineStart)) if (isInstruction(index)) (isSubroutineStart(index) ? 'S' : '-') + (isSubroutineReturning(index) ? 'r' : '-') + (isSubroutine(index) ? " ["+subroutineStart(index)+" -> "+subroutineEnd(index)+"]" : "") + InstructionFactory.create(codeAttribute.code, index).toString(index));
/** * Returns the whether there is a boundary of an exception block between * the given offsets (including both). */ private boolean exceptionBoundary(CodeAttribute codeAttribute, int offset1, int offset2) { // Swap the offsets if the second one is smaller than the first one. if (offset2 < offset1) { int offset = offset1; offset1 = offset2; offset2 = offset; } // Check if there is a boundary of an exception block. for (int offset = offset1; offset <= offset2; offset++) { if (branchTargetFinder.isExceptionStart(offset) || branchTargetFinder.isExceptionEnd(offset)) { return true; } } return false; } }
if ((opcode == InstructionConstants.OP_GOTO || opcode == InstructionConstants.OP_GOTO_W) && !branchTargetFinder.isBranchTarget(offset)) if (branchTargetFinder.isInstruction(deleteOffset))
public void visitCodeAttribute0(Clazz clazz, Method method, CodeAttribute codeAttribute) branchTargetFinder.visitCodeAttribute(clazz, method, codeAttribute); if (branchTargetFinder.isSubroutine(offset) && branchTargetFinder.isSubroutineReturning(offset))
/** * Creates a new PartialEvaluator. * @param valueFactory the value factory that will create all values * during evaluation. * @param invocationUnit the invocation unit that will handle all * communication with other fields and methods. * @param evaluateAllCode a flag that specifies whether all branch targets * and exception handlers should be evaluated, * even if they are unreachable. */ public PartialEvaluator(ValueFactory valueFactory, InvocationUnit invocationUnit, boolean evaluateAllCode) { this(valueFactory, invocationUnit, evaluateAllCode, evaluateAllCode ? new BasicBranchUnit() : new TracedBranchUnit(), new BranchTargetFinder(), null); }
/** * Returns whether the instruction at the given offset is part of a * subroutine. */ public boolean isSubroutine(int instructionOffset) { return branchTargetFinder.isSubroutine(instructionOffset); }
/** * Returns whether the method is an instance initializer. */ public boolean isInitializer() { return branchTargetFinder.isInitializer(); }
/** * Returns whether there is an instruction at the given offset. */ public boolean isInstruction(int instructionOffset) { return branchTargetFinder.isInstruction(instructionOffset); }
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { // Mark the instruction. instructionMarks[offset] |= INSTRUCTION; // Check if this is an instruction of a subroutine. checkSubroutine(offset); byte opcode = constantInstruction.opcode; if (opcode == InstructionConstants.OP_NEW) { // Mark the creation. instructionMarks[offset] |= CREATION; } else if (opcode == InstructionConstants.OP_INVOKESPECIAL) { // Is it calling an instance initializer? isInitializer = false; clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); if (isInitializer) { // Mark the initializer. instructionMarks[offset] |= INITIALIZER; } } }
/** * Returns whether the instruction at the given offset is the start of * an exception handler. */ public boolean isExceptionHandler(int instructionOffset) { return branchTargetFinder.isExceptionHandler(instructionOffset); }
/** * Returns whether the instruction at the given offset is the target of a * branch instruction. */ public boolean isBranchTarget(int instructionOffset) { return branchTargetFinder.isBranchTarget(instructionOffset); }
if (branchTargetFinder.isInstruction(newOffset1) ^ branchTargetFinder.isInstruction(newOffset2)) if (branchTargetFinder.isInstruction(newOffset1) && branchTargetFinder.isInstruction(newOffset2)) if (branchTargetFinder.isBranchOrigin(newOffset1) || branchTargetFinder.isBranchTarget(newOffset1) || branchTargetFinder.isExceptionStart(newOffset1) || branchTargetFinder.isExceptionEnd(newOffset1) || branchTargetFinder.isInitializer(newOffset1) || branchTargetFinder.isExceptionStart(newOffset2) || branchTargetFinder.isExceptionEnd(newOffset2) || isPop(code[newOffset1])) if (branchTargetFinder.isBranchTarget(newOffset2)) if (branchTargetFinder.isBranchTarget(newOffset1))