Java Code Examples for proguard.classfile.instruction.InstructionConstants#OP_JSR

The following examples show how to use proguard.classfile.instruction.InstructionConstants#OP_JSR . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    switch (branchInstruction.opcode)
    {
        case InstructionConstants.OP_GOTO:
        case InstructionConstants.OP_GOTO_W:
            // Don't replace unconditional branches.
            break;

        case InstructionConstants.OP_JSR:
        case InstructionConstants.OP_JSR_W:
            replaceJsrInstruction(clazz, offset, branchInstruction);
            break;

        default:
            replaceBranchInstruction(clazz, offset, branchInstruction);
            break;
    }
}
 
Example 2
Source File: StackSizeComputer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    byte opcode = branchInstruction.opcode;

    // Evaluate the target instruction blocks.
    evaluateInstructionBlock(clazz,
                             method,
                             codeAttribute,
                             offset +
                             branchInstruction.branchOffset);

    // Evaluate the instructions after a subroutine branch.
    if (opcode == InstructionConstants.OP_JSR ||
        opcode == InstructionConstants.OP_JSR_W)
    {
        // We assume subroutine calls (jsr and jsr_w instructions) don't
        // change the stack, other than popping the return value.
        stackSize -= 1;

        evaluateInstructionBlock(clazz,
                                 method,
                                 codeAttribute,
                                 offset + branchInstruction.length(offset));
    }

    // Some branch instructions always end the current instruction block.
    exitInstructionBlock =
        opcode == InstructionConstants.OP_GOTO   ||
        opcode == InstructionConstants.OP_GOTO_W ||
        opcode == InstructionConstants.OP_JSR    ||
        opcode == InstructionConstants.OP_JSR_W;
}
 
Example 3
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    byte opcode = branchInstruction.opcode;

    // Check for instructions that might cause side effects.
    if (includeReturnInstructions &&
        (opcode == InstructionConstants.OP_JSR ||
         opcode == InstructionConstants.OP_JSR_W))
    {
        hasSideEffects = true;
    }
}
 
Example 4
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    // Explicitly mark the produced stack entry of a 'jsr' instruction,
    // because the consuming 'astore' instruction of the subroutine is
    // cleared every time it is traced.
    if (branchInstruction.opcode == InstructionConstants.OP_JSR ||
        branchInstruction.opcode == InstructionConstants.OP_JSR_W)
    {
        markStackEntryAfter(offset, 0);
    }
    else
    {
        markStackProducers(clazz, offset, branchInstruction);
    }
}
 
Example 5
Source File: BranchTargetFinder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    // Mark the branch origin.
    markBranchOrigin(offset);

    // Check if this is the first instruction of a subroutine.
    checkSubroutine(offset);

    // Mark the branch target.
    markBranchTarget(offset, branchInstruction.branchOffset);

    byte opcode = branchInstruction.opcode;
    if (opcode == InstructionConstants.OP_JSR ||
        opcode == InstructionConstants.OP_JSR_W)
    {
        // Mark the subroutine invocation.
        instructionMarks[offset] |= SUBROUTINE_INVOCATION;

        // Mark the subroutine start.
        int targetOffset = offset + branchInstruction.branchOffset;
        subroutineStarts[targetOffset] = targetOffset;
    }
    else if (opcode == InstructionConstants.OP_GOTO ||
             opcode == InstructionConstants.OP_GOTO_W)
    {
        // Mark the next instruction.
        markAfterBranchOrigin(offset + branchInstruction.length(offset));
    }
}
 
Example 6
Source File: CodeSubroutineInliner.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitBranchInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, BranchInstruction branchInstruction)
{
    byte opcode = branchInstruction.opcode;
    if (opcode == InstructionConstants.OP_JSR ||
        opcode == InstructionConstants.OP_JSR_W)
    {
        int branchOffset = branchInstruction.branchOffset;
        int branchTarget = offset + branchOffset;

        // Is the subroutine ever returning?
        if (branchTargetFinder.isSubroutineReturning(branchTarget))
        {
            // Append a label at this offset instead of the subroutine invocation.
            codeAttributeComposer.appendLabel(offset);

            // Inline the invoked subroutine.
            inlineSubroutine(clazz,
                             method,
                             codeAttribute,
                             offset,
                             branchTarget);
        }
        else
        {
            if (DEBUG)
            {
                System.out.println("Replacing subroutine invocation at ["+offset+"] by a simple branch");
            }

            // Replace the subroutine invocation by a simple branch.
            Instruction replacementInstruction =
                new BranchInstruction(InstructionConstants.OP_GOTO,
                                      branchOffset).shrink();

            codeAttributeComposer.appendInstruction(offset, replacementInstruction);
        }
    }
    else
    {
        // Append the instruction.
        codeAttributeComposer.appendInstruction(offset, branchInstruction);
    }
}