proguard.classfile.instruction.InstructionConstants Java Examples

The following examples show how to use proguard.classfile.instruction.InstructionConstants. 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: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;
    // Check for instructions that might cause side effects.
    if (opcode == InstructionConstants.OP_GETSTATIC     ||
        opcode == InstructionConstants.OP_PUTSTATIC     ||
        opcode == InstructionConstants.OP_GETFIELD      ||
        opcode == InstructionConstants.OP_PUTFIELD      ||
        opcode == InstructionConstants.OP_INVOKEVIRTUAL ||
        opcode == InstructionConstants.OP_INVOKESPECIAL ||
        opcode == InstructionConstants.OP_INVOKESTATIC  ||
        opcode == InstructionConstants.OP_INVOKEINTERFACE)
    {
        // Check if the field is write-only or volatile, or if the invoked
        // method is causing any side effects.
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example #2
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the given instruction by an infinite loop.
 */
private void replaceByInfiniteLoop(Clazz       clazz,
                                   int         offset,
                                   Instruction instruction)
{
    // Replace the instruction by an infinite loop.
    Instruction replacementInstruction =
        new BranchInstruction(InstructionConstants.OP_GOTO, 0);

    if (DEBUG) System.out.println("  Replacing unreachable instruction by infinite loop "+replacementInstruction.toString(offset));

    codeAttributeEditor.replaceInstruction(offset, replacementInstruction);

    // Visit the instruction, if required.
    if (extraInstructionVisitor != null)
    {
        // Note: we're not passing the right arguments for now, knowing that
        // they aren't used anyway.
        instruction.accept(clazz, null, null, offset, extraInstructionVisitor);
    }
}
 
Example #3
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 #4
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Replaces the reference pushing instruction at the given offset by a
 * simpler push instruction, if possible.
 */
private void replaceReferencePushInstruction(Clazz       clazz,
                                             int         offset,
                                             Instruction instruction)
{
    Value pushedValue = partialEvaluator.getStackAfter(offset).getTop(0);
    if (pushedValue.isParticular())
    {
        // A reference value can only be specific if it is null.
        replaceConstantPushInstruction(clazz,
                                       offset,
                                       instruction,
                                       InstructionConstants.OP_ACONST_NULL,
                                       0);
    }
}
 
Example #5
Source File: BranchTargetFinder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
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));
    }
}
 
Example #6
Source File: BridgeMethodFixer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKESTATIC:
        case InstructionConstants.OP_INVOKEINTERFACE:
            // Get the name of the bridged method.
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);

            // Check if the name is different.
            if (!method.getName(clazz).equals(bridgedMethodName))
            {
                if (DEBUG)
                {
                    System.out.println("BridgeMethodFixer: ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"] does not bridge to ["+bridgedMethodName+"]");
                }

                // Clear the bridge flag.
                ((ProgramMethod)method).u2accessFlags &= ~ClassConstants.INTERNAL_ACC_BRIDGE;
            }
            break;
    }
}
 
Example #7
Source File: CodeAttributeComposer.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args)
{
    CodeAttributeComposer composer = new CodeAttributeComposer();

    composer.beginCodeFragment(4);
    composer.appendInstruction(0, new SimpleInstruction(InstructionConstants.OP_ICONST_0));
    composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ISTORE, 0));
    composer.appendInstruction(2, new BranchInstruction(InstructionConstants.OP_GOTO, 1));

    composer.beginCodeFragment(4);
    composer.appendInstruction(0, new VariableInstruction(InstructionConstants.OP_IINC, 0, 1));
    composer.appendInstruction(1, new VariableInstruction(InstructionConstants.OP_ILOAD, 0));
    composer.appendInstruction(2, new SimpleInstruction(InstructionConstants.OP_ICONST_5));
    composer.appendInstruction(3, new BranchInstruction(InstructionConstants.OP_IFICMPLT, -3));
    composer.endCodeFragment();

    composer.appendInstruction(3, new SimpleInstruction(InstructionConstants.OP_RETURN));
    composer.endCodeFragment();
}
 
Example #8
Source File: BranchTargetFinder.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
{
    // Mark the instruction.
    instructionMarks[offset] |= INSTRUCTION;

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

    byte opcode = simpleInstruction.opcode;
    if (opcode == InstructionConstants.OP_IRETURN ||
        opcode == InstructionConstants.OP_LRETURN ||
        opcode == InstructionConstants.OP_FRETURN ||
        opcode == InstructionConstants.OP_DRETURN ||
        opcode == InstructionConstants.OP_ARETURN ||
        opcode == InstructionConstants.OP_ATHROW)
    {
        // Mark the branch origin.
        markBranchOrigin(offset);

        // Mark the next instruction.
        markAfterBranchOrigin(offset + simpleInstruction.length(offset));
    }
}
 
Example #9
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the given instruction by an infinite loop.
 */
private void replaceByInfiniteLoop(Clazz clazz,
                                   int   offset)
{
    if (DEBUG) System.out.println("  Inserting infinite loop at ["+offset+"]");

    // Mark the instruction.
    markInstruction(offset);

    // Replace the instruction by an infinite loop.
    Instruction replacementInstruction =
        new BranchInstruction(InstructionConstants.OP_GOTO, 0);

    codeAttributeEditor.replaceInstruction(offset, replacementInstruction);
}
 
Example #10
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 #11
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the instruction at a given offset by a static invocation.
 */
private void replaceByStaticInvocation(Clazz               clazz,
                                       int                 offset,
                                       ConstantInstruction constantInstruction)
{
    // Remember the replacement instruction.
    Instruction replacementInstruction =
         new ConstantInstruction(InstructionConstants.OP_INVOKESTATIC,
                                 constantInstruction.constantIndex).shrink();

    if (DEBUG) System.out.println("  Replacing by static invocation "+constantInstruction.toString(offset)+" -> "+replacementInstruction.toString());

    codeAttributeEditor.replaceInstruction(offset, replacementInstruction);
}
 
Example #12
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the opcode of a push instruction corresponding to the given
 * computational type.
 * @param computationalType the computational type to be pushed on the stack.
 */
private byte pushOpcode(int computationalType)
{
    switch (computationalType)
    {
        case Value.TYPE_INTEGER:            return InstructionConstants.OP_ICONST_0;
        case Value.TYPE_LONG:               return InstructionConstants.OP_LCONST_0;
        case Value.TYPE_FLOAT:              return InstructionConstants.OP_FCONST_0;
        case Value.TYPE_DOUBLE:             return InstructionConstants.OP_DCONST_0;
        case Value.TYPE_REFERENCE:
        case Value.TYPE_INSTRUCTION_OFFSET: return InstructionConstants.OP_ACONST_NULL;
    }

    throw new IllegalArgumentException("No push opcode for computational type ["+computationalType+"]");
}
 
Example #13
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 #14
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Mark the initializer invocation, if this is a 'new' instruction.
    if (constantInstruction.opcode == InstructionConstants.OP_NEW)
    {
        markInitialization(offset);
    }

    markStackProducers(clazz, offset, constantInstruction);
}
 
Example #15
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
{
    byte opcode = variableInstruction.opcode;

    // Check for instructions that might cause side effects.
    if (includeReturnInstructions &&
        opcode == InstructionConstants.OP_RET)
    {
        hasSideEffects = true;
    }
}
 
Example #16
Source File: ReadWriteFieldMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;

    // Check for instructions that involve fields.
    switch (opcode)
    {
        case InstructionConstants.OP_LDC:
        case InstructionConstants.OP_LDC_W:
            // Mark the field, if any, as being read from and written to.
            reading = true;
            writing = true;
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
            break;

        case InstructionConstants.OP_GETSTATIC:
        case InstructionConstants.OP_GETFIELD:
            // Mark the field as being read from.
            reading = true;
            writing = false;
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
            break;

        case InstructionConstants.OP_PUTSTATIC:
        case InstructionConstants.OP_PUTFIELD:
            // Mark the field as being written to.
            reading = false;
            writing = true;
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
            break;
    }
}
 
Example #17
Source File: SideEffectInstructionChecker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
{
    byte opcode = simpleInstruction.opcode;

    // Check for instructions that might cause side effects.
    if (opcode == InstructionConstants.OP_IASTORE      ||
        opcode == InstructionConstants.OP_LASTORE      ||
        opcode == InstructionConstants.OP_FASTORE      ||
        opcode == InstructionConstants.OP_DASTORE      ||
        opcode == InstructionConstants.OP_AASTORE      ||
        opcode == InstructionConstants.OP_BASTORE      ||
        opcode == InstructionConstants.OP_CASTORE      ||
        opcode == InstructionConstants.OP_SASTORE      ||
        opcode == InstructionConstants.OP_ATHROW       ||
        opcode == InstructionConstants.OP_MONITORENTER ||
        opcode == InstructionConstants.OP_MONITOREXIT  ||
        (includeReturnInstructions &&
         (opcode == InstructionConstants.OP_IRETURN ||
          opcode == InstructionConstants.OP_LRETURN ||
          opcode == InstructionConstants.OP_FRETURN ||
          opcode == InstructionConstants.OP_DRETURN ||
          opcode == InstructionConstants.OP_ARETURN ||
          opcode == InstructionConstants.OP_RETURN)))
    {
        // These instructions always cause a side effect.
        hasSideEffects = true;
    }

}
 
Example #18
Source File: DotClassMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_LDC ||
        constantInstruction.opcode == InstructionConstants.OP_LDC_W)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example #19
Source File: GotoGotoReplacer.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)
{
    // Check if the instruction is an unconditional goto instruction.
    byte opcode = branchInstruction.opcode;
    if (opcode == InstructionConstants.OP_GOTO ||
        opcode == InstructionConstants.OP_GOTO_W)
    {
        // Check if the goto instruction points to another simple goto
        // instruction.
        int branchOffset = branchInstruction.branchOffset;
        int targetOffset = offset + branchOffset;

        if (branchOffset != branchInstruction.length(offset) &&
            !codeAttributeEditor.isModified(offset) &&
            !codeAttributeEditor.isModified(targetOffset))
        {
            Instruction targetInstruction =
                InstructionFactory.create(codeAttribute.code, targetOffset);

            if (targetInstruction.opcode == InstructionConstants.OP_GOTO)
            {
                // Simplify the goto instruction.
                int targetBranchOffset = ((BranchInstruction)targetInstruction).branchOffset;

                Instruction newBranchInstruction =
                     new BranchInstruction(opcode,
                                           (branchOffset + targetBranchOffset));
                codeAttributeEditor.replaceInstruction(offset,
                                                       newBranchInstruction);

                // Visit the instruction, if required.
                if (extraInstructionVisitor != null)
                {
                    extraInstructionVisitor.visitBranchInstruction(clazz, method, codeAttribute, offset, branchInstruction);
                }
            }
        }
    }
}
 
Example #20
Source File: MethodInliner.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
{
    // Are we inlining this instruction?
    if (inlining)
    {
        // Replace any return instructions by branches to the end of the code.
        switch (simpleInstruction.opcode)
        {
            case InstructionConstants.OP_IRETURN:
            case InstructionConstants.OP_LRETURN:
            case InstructionConstants.OP_FRETURN:
            case InstructionConstants.OP_DRETURN:
            case InstructionConstants.OP_ARETURN:
            case InstructionConstants.OP_RETURN:
                // Are we not at the last instruction?
                if (offset < codeAttribute.u4codeLength-1)
                {
                    // Replace the return instruction by a branch instruction.
                    Instruction branchInstruction =
                        new BranchInstruction(InstructionConstants.OP_GOTO_W,
                                              codeAttribute.u4codeLength - offset);

                    codeAttributeComposer.appendInstruction(offset,
                                                            branchInstruction.shrink());
                }
                else
                {
                    // Just leave out the instruction, but put in a label,
                    // for the sake of any other branch instructions.
                    codeAttributeComposer.appendLabel(offset);
                }

                return;
        }
    }

    codeAttributeComposer.appendInstruction(offset, simpleInstruction.shrink());
}
 
Example #21
Source File: GotoReturnReplacer.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)
{
    // Check if the instruction is an unconditional goto instruction.
    byte opcode = branchInstruction.opcode;
    if (opcode == InstructionConstants.OP_GOTO ||
        opcode == InstructionConstants.OP_GOTO_W)
    {
        // Check if the goto instruction points to a return instruction.
        int targetOffset = offset + branchInstruction.branchOffset;

        if (!codeAttributeEditor.isModified(offset) &&
            !codeAttributeEditor.isModified(targetOffset))
        {
            Instruction targetInstruction = InstructionFactory.create(codeAttribute.code,
                                                                      targetOffset);
            switch (targetInstruction.opcode)
            {
                case InstructionConstants.OP_IRETURN:
                case InstructionConstants.OP_LRETURN:
                case InstructionConstants.OP_FRETURN:
                case InstructionConstants.OP_DRETURN:
                case InstructionConstants.OP_ARETURN:
                case InstructionConstants.OP_RETURN:
                    // Replace the goto instruction by the return instruction.
                    Instruction returnInstruction =
                         new SimpleInstruction(targetInstruction.opcode);
                    codeAttributeEditor.replaceInstruction(offset,
                                                           returnInstruction);

                    // Visit the instruction, if required.
                    if (extraInstructionVisitor != null)
                    {
                        extraInstructionVisitor.visitBranchInstruction(clazz, method, codeAttribute, offset, branchInstruction);
                    }

                    break;
            }
        }
    }
}
 
Example #22
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 #23
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_GETSTATIC:
        case InstructionConstants.OP_GETFIELD:
            replaceAnyPushInstruction(clazz, offset, constantInstruction);
            break;

        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKESTATIC:
        case InstructionConstants.OP_INVOKEINTERFACE:
            if (constantInstruction.stackPushCount(clazz) > 0 &&
                !sideEffectInstructionChecker.hasSideEffects(clazz,
                                                             method,
                                                             codeAttribute,
                                                             offset,
                                                             constantInstruction))
            {
                replaceAnyPushInstruction(clazz, offset, constantInstruction);
            }

            break;

        case InstructionConstants.OP_CHECKCAST:
            replaceReferencePushInstruction(clazz, offset, constantInstruction);
            break;
    }
}
 
Example #24
Source File: BranchTargetFinder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Mark the instruction.
    instructionMarks[offset] |= INSTRUCTION;

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

    // Check if the instruction is a 'new' instruction.
    if (constantInstruction.opcode == InstructionConstants.OP_NEW)
    {
        // Push the 'new' instruction offset on the stack.
        recentCreationOffsets[recentCreationOffsetIndex++] = offset;
    }
    else
    {
        // Check if the instruction is an initializer invocation.
        isInitializer = false;
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
        if (isInitializer)
        {
            // Pop the 'new' instruction offset from the stack.
            int recentCreationOffset = recentCreationOffsets[--recentCreationOffsetIndex];

            // Fill it out in the creation offsets.
            creationOffsets[offset] = recentCreationOffset;

            // Fill out the initialization offsets.
            if (recentCreationOffset == AT_METHOD_ENTRY)
            {
                superInitializationOffset = offset;
            }
            else
            {
                initializationOffsets[recentCreationOffset] = offset;
            }
        }
    }
}
 
Example #25
Source File: ReachableCodeMarker.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 target.
    markBranchTarget(clazz,
                     method,
                     codeAttribute,
                     offset + branchInstruction.branchOffset);

    byte opcode = branchInstruction.opcode;
    if (opcode == InstructionConstants.OP_GOTO ||
        opcode == InstructionConstants.OP_GOTO_W)
    {
        next = false;
    }
}
 
Example #26
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes the given branch instruction, or replaces it by a simpler branch
 * instruction, if possible.
 */
private void replaceBranchInstruction(Clazz       clazz,
                                      int         offset,
                                      Instruction instruction)
{
    InstructionOffsetValue branchTargets = partialEvaluator.branchTargets(offset);

    // Is there exactly one branch target (not from a goto or jsr)?
    if (branchTargets != null &&
        branchTargets.instructionOffsetCount() == 1)
    {
        // Is it branching to the next instruction?
        int branchOffset = branchTargets.instructionOffset(0) - offset;
        if (branchOffset == instruction.length(offset))
        {
            if (DEBUG) System.out.println("  Ignoring zero branch instruction at ["+offset+"]");
        }
        else
        {
            // Replace the branch instruction by a simple branch instruction.
            Instruction replacementInstruction =
                new BranchInstruction(InstructionConstants.OP_GOTO_W,
                                      branchOffset).shrink();

            replaceInstruction(clazz, offset, instruction, replacementInstruction);
        }
    }
}
 
Example #27
Source File: DuplicateInitializerInvocationFixer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_INVOKESPECIAL)
    {
        hasBeenFixed = false;
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);

        if (hasBeenFixed)
        {
            Instruction extraInstruction =
                new SimpleInstruction(InstructionConstants.OP_ICONST_0);

            codeAttributeEditor.insertBeforeInstruction(offset,
                                                        extraInstruction);

            if (DEBUG)
            {
                System.out.println("  ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"] Inserting "+extraInstruction.toString()+" before "+constantInstruction.toString(offset));
            }

            if (extraAddedInstructionVisitor != null)
            {
                extraInstruction.accept(null, null, null, offset, extraAddedInstructionVisitor);
            }
        }
    }
}
 
Example #28
Source File: NopRemover.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
{
    // Check if the instruction is a nop instruction.
    if (simpleInstruction.opcode == InstructionConstants.OP_NOP &&
        !codeAttributeEditor.isModified(offset))
    {
        codeAttributeEditor.deleteInstruction(offset);

        // Visit the instruction, if required.
        if (extraInstructionVisitor != null)
        {
            extraInstructionVisitor.visitSimpleInstruction(clazz, method, codeAttribute, offset, simpleInstruction);
        }
    }
}
 
Example #29
Source File: ReachableCodeMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction)
{
    byte opcode = simpleInstruction.opcode;
    if (opcode == InstructionConstants.OP_IRETURN ||
        opcode == InstructionConstants.OP_LRETURN ||
        opcode == InstructionConstants.OP_FRETURN ||
        opcode == InstructionConstants.OP_DRETURN ||
        opcode == InstructionConstants.OP_ARETURN ||
        opcode == InstructionConstants.OP_RETURN  ||
        opcode == InstructionConstants.OP_ATHROW)
    {
        next = false;
    }
}
 
Example #30
Source File: ReachableCodeMarker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitVariableInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VariableInstruction variableInstruction)
{
    if (variableInstruction.opcode == InstructionConstants.OP_RET)
    {
        next = false;
    }
}