Java Code Examples for proguard.classfile.instruction.ConstantInstruction

The following examples show how to use proguard.classfile.instruction.ConstantInstruction. These examples are extracted from open source projects. 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
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    Instruction patternInstruction = patternInstructions[patternInstructionIndex];

    // Check if the instruction matches the next instruction in the sequence.
    boolean condition =
        matchingOpcodes(constantInstruction, patternInstruction) &&
        matchingConstantIndices(clazz,
                                constantInstruction.constantIndex,
                                ((ConstantInstruction)patternInstruction).constantIndex) &&
        matchingArguments(constantInstruction.constant,
                          ((ConstantInstruction)patternInstruction).constant);

    // Check if the instruction sequence is matching now.
    checkMatch(condition,
               clazz,
               method,
               codeAttribute,
               offset,
               constantInstruction);
}
 
Example 2
Source Project: java-n-IDE-for-Android   Source File: BridgeMethodFixer.java    License: 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 3
Source Project: java-n-IDE-for-Android   Source File: InstructionWriter.java    License: Apache License 2.0 6 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    try
    {
        // Try to write out the instruction.
        constantInstruction.write(codeAttribute, offset);
    }
    catch (IllegalArgumentException exception)
    {
        // Create a new constant instruction that will fit.
        Instruction replacementInstruction =
            new ConstantInstruction(constantInstruction.opcode,
                                    constantInstruction.constantIndex,
                                    constantInstruction.constant).shrink();

        replaceInstruction(offset, replacementInstruction);

        // Write out a dummy constant instruction for now.
        constantInstruction.constantIndex = 0;
        constantInstruction.constant      = 0;
        constantInstruction.write(codeAttribute, offset);
    }
}
 
Example 4
private void debug(Clazz clazz,
                   Method method,
                   int                 offset,
                   ConstantInstruction constantInstruction,
                   Instruction replacementInstruction)
{
    System.out.println("MethodInvocationFixer:");
    System.out.println("  Class       = "+clazz.getName());
    System.out.println("  Method      = "+method.getName(clazz)+method.getDescriptor(clazz));
    System.out.println("  Instruction = "+constantInstruction.toString(offset));
    System.out.println("  -> Class    = "+referencedClass);
    System.out.println("     Method   = "+referencedMethod);
    if ((referencedClass.getAccessFlags() & ClassConstants.INTERNAL_ACC_INTERFACE) != 0)
    {
        System.out.println("     Parameter size   = "+(ClassUtil.internalMethodParameterSize(referencedMethod.getDescriptor(referencedMethodClass), false)));
    }
    System.out.println("  Replacement instruction = "+replacementInstruction.toString(offset));
}
 
Example 5
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 6
Source Project: java-n-IDE-for-Android   Source File: InvocationUnit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given stack corresponding to the execution of the given
 * field or method reference instruction.
 */
public void invokeMember(Clazz clazz,
                         Method method,
                         CodeAttribute codeAttribute,
                         int offset,
                         ConstantInstruction constantInstruction,
                         Stack stack);
 
Example 7
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    for (int index = 0; index < instructionVisitorCount; index++)
    {
        instructionVisitors[index].visitConstantInstruction(clazz, method, codeAttribute, offset, constantInstruction);
    }
}
 
Example 8
Source Project: java-n-IDE-for-Android   Source File: ClassPrinter.java    License: Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    println(constantInstruction.toString(offset));

    indent();
    clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    outdent();
}
 
Example 9
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    byte opcode = constantInstruction.opcode;

    // Could this instruction be a .class construct?
    if (opcode == InstructionConstants.OP_LDC ||
        opcode == InstructionConstants.OP_LDC_W)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex,
                                      this);
    }
}
 
Example 10
Source Project: java-n-IDE-for-Android   Source File: InstructionAdder.java    License: Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Create a copy of the instruction.
    Instruction newConstantInstruction =
        new ConstantInstruction(constantInstruction.opcode,
                                constantAdder.addConstant(clazz, constantInstruction.constantIndex),
                                constantInstruction.constant).shrink();

    // Add the instruction.
    codeAttributeComposer.appendInstruction(offset, newConstantInstruction);
}
 
Example 11
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Is the new constant pool index different from the original one?
    int newConstantIndex = remapConstantIndex(constantInstruction.constantIndex);
    if (newConstantIndex != constantInstruction.constantIndex)
    {
        // Replace the instruction.
        Instruction replacementInstruction =
            new ConstantInstruction(constantInstruction.opcode,
                                    newConstantIndex,
                                    constantInstruction.constant).shrink();

        codeAttributeEditor.replaceInstruction(offset, replacementInstruction);
    }
}
 
Example 12
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Write out the instruction.
    instructionWriter.visitConstantInstruction(clazz,
                                               method,
                                               codeAttribute,
                                               newOffset,
                                               constantInstruction);

    newOffset += constantInstruction.length(newOffset);
}
 
Example 13
Source Project: java-n-IDE-for-Android   Source File: DotClassMarker.java    License: 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 14
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 15
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_INVOKESPECIAL)
    {
        invokesSuperMethods = false;

        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);

        if (invokesSuperMethods)
        {
            setInvokesSuperMethods(method);
        }
    }
}
 
Example 16
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_INSTANCEOF)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example 17
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    if (constantInstruction.opcode == InstructionConstants.OP_NEW)
    {
        clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
}
 
Example 18
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
    {
        byte opcode = constantInstruction.opcode;

        // Check for instructions that may throw exceptions.
        switch (opcode)
        {
            case InstructionConstants.OP_GETSTATIC:
            case InstructionConstants.OP_PUTSTATIC:
            case InstructionConstants.OP_GETFIELD:
            case InstructionConstants.OP_PUTFIELD:
            case InstructionConstants.OP_INVOKEVIRTUAL:
            case InstructionConstants.OP_INVOKESPECIAL:
            case InstructionConstants.OP_INVOKESTATIC:
            case InstructionConstants.OP_INVOKEINTERFACE:
            case InstructionConstants.OP_NEW:
            case InstructionConstants.OP_ANEWARRAY:
            case InstructionConstants.OP_CHECKCAST:
            case InstructionConstants.OP_INSTANCEOF:
            case InstructionConstants.OP_MULTIANEWARRAY:
                // These instructions may throw exceptions.
                mayThrowExceptions = true;
        }

//          case InstructionConstants.OP_INVOKEVIRTUAL:
//          case InstructionConstants.OP_INVOKESPECIAL:
//          case InstructionConstants.OP_INVOKESTATIC:
//          case InstructionConstants.OP_INVOKEINTERFACE:
//            // Check if the invoking the method may throw an exception.
//            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    }
 
Example 19
Source Project: java-n-IDE-for-Android   Source File: LivenessAnalyzer.java    License: Apache License 2.0 5 votes vote down vote up
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    // Special case: variable 0 ('this') in an initializer has to be alive
    // as long as it hasn't been initialized.
     if (offset == partialEvaluator.superInitializationOffset())
    {
        alive |= 1L;
    }
}
 
Example 20
Source Project: java-n-IDE-for-Android   Source File: EvaluationShrinker.java    License: 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_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKESTATIC:
        case InstructionConstants.OP_INVOKEINTERFACE:
            this.invocationOffset      = offset;
            this.invocationInstruction = constantInstruction;
            clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
            break;
    }
}
 
Example 21
Source Project: java-n-IDE-for-Android   Source File: EvaluationShrinker.java    License: 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 22
Source Project: java-n-IDE-for-Android   Source File: EvaluationShrinker.java    License: 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 23
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
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 25
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
{
    replacementInstruction =
        new ConstantInstruction(constantInstruction.opcode,
                                instructionSequenceMatcher.matchedConstantIndex(constantInstruction.constantIndex),
                                instructionSequenceMatcher.matchedArgument(constantInstruction.constant));
}
 
Example 26
Source Project: java-n-IDE-for-Android   Source File: BranchTargetFinder.java    License: 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 27
Source Project: atlas   Source File: ClassDetailVisitor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset,
                                     ConstantInstruction constantInstruction) {
    //println("visitConstantInstruction >>>" + constantInstruction.toString(offset));

    //indent();
    clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this);
    //outdent();
}
 
Example 28
Source Project: proguard   Source File: InvocationUnit.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Updates the given stack corresponding to the execution of the given
 * field or method reference instruction.
 */
public void invokeMember(Clazz               clazz,
                         Method              method,
                         CodeAttribute       codeAttribute,
                         int                 offset,
                         ConstantInstruction constantInstruction,
                         Stack               stack);
 
Example 29
Source Project: bazel   Source File: InvocationUnit.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Updates the given stack corresponding to the execution of the given
 * field or method reference instruction.
 */
public void invokeMember(Clazz               clazz,
                         Method              method,
                         CodeAttribute       codeAttribute,
                         int                 offset,
                         ConstantInstruction constantInstruction,
                         Stack               stack);
 
Example 30
public void invokeMember(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction, Stack stack)
{
    int constantIndex = constantInstruction.constantIndex;

    switch (constantInstruction.opcode)
    {
        case InstructionConstants.OP_GETSTATIC:
            isStatic = true;
            isLoad   = true;
            break;

        case InstructionConstants.OP_PUTSTATIC:
            isStatic = true;
            isLoad   = false;
            break;

        case InstructionConstants.OP_GETFIELD:
            isStatic = false;
            isLoad   = true;
            break;

        case InstructionConstants.OP_PUTFIELD:
            isStatic = false;
            isLoad   = false;
            break;

        case InstructionConstants.OP_INVOKESTATIC:
            isStatic = true;
            break;

        case InstructionConstants.OP_INVOKEVIRTUAL:
        case InstructionConstants.OP_INVOKESPECIAL:
        case InstructionConstants.OP_INVOKEINTERFACE:
            isStatic = false;
            break;
    }

    // Pop the parameters and push the return value.
    this.stack = stack;
    clazz.constantPoolEntryAccept(constantIndex, this);
    this.stack = null;
}