proguard.classfile.visitor.ClassPrinter Java Examples

The following examples show how to use proguard.classfile.visitor.ClassPrinter. 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: ProGuard.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Prints out the contents of the program classes.
 */
private void dump() throws IOException
{
    if (configuration.verbose)
    {
        System.out.println("Printing classes to [" + fileName(configuration.dump) + "]...");
    }

    PrintStream ps = createPrintStream(configuration.dump);
    try
    {
        programClassPool.classesAccept(new ClassPrinter(ps));
    }
    finally
    {
        closePrintStream(ps);
    }
}
 
Example #2
Source File: EvaluationSimplifier.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the evaluation simplifier has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while simplifying instructions after partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
            System.err.println("Not optimizing this method");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                throw ex;
            }
        }
    }
 
Example #3
Source File: CodeSubroutineInliner.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the subroutine inliner has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while inlining subroutines:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());
            }

            throw ex;
        }
    }
 
Example #4
Source File: StackSizeComputer.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the code has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while computing stack sizes:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());
            }

            throw ex;
        }
    }
 
Example #5
Source File: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG = DEBUG_RESULTS =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the evaluation shrinker has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while shrinking instructions after partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
            System.err.println("Not optimizing this method");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                throw ex;
            }
        }
    }
 
Example #6
Source File: EvaluationSimplifier.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the evaluation simplifier has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while simplifying instructions after partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
            System.err.println("Not optimizing this method");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                throw ex;
            }
        }
    }
 
Example #7
Source File: ClassMerger.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramClass(ProgramClass programClass)
{
    //final String CLASS_NAME = "abc/Def";
    //DEBUG = programClass.getName().equals(CLASS_NAME) ||
    //        targetClass.getName().equals(CLASS_NAME);

    // TODO: Remove this when the class merger has stabilized.
    // Catch any unexpected exceptions from the actual visiting method.
    try
    {
        visitProgramClass0(programClass);
    }
    catch (RuntimeException ex)
    {
        System.err.println("Unexpected error while merging classes:");
        System.err.println("  Class        = ["+programClass.getName()+"]");
        System.err.println("  Target class = ["+targetClass.getName()+"]");
        System.err.println("  Exception    = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

        if (DEBUG)
        {
            programClass.accept(new ClassPrinter());
            targetClass.accept(new ClassPrinter());
        }

        throw ex;
    }
}
 
Example #8
Source File: MethodInliner.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    // TODO: Remove this when the method inliner has stabilized.
    // Catch any unexpected exceptions from the actual visiting method.
    try
    {
        // Process the code.
        visitCodeAttribute0(clazz, method, codeAttribute);
    }
    catch (RuntimeException ex)
    {
        System.err.println("Unexpected error while inlining method:");
        System.err.println("  Target class   = ["+targetClass.getName()+"]");
        System.err.println("  Target method  = ["+targetMethod.getName(targetClass)+targetMethod.getDescriptor(targetClass)+"]");
        if (inlining)
        {
            System.err.println("  Inlined class  = ["+clazz.getName()+"]");
            System.err.println("  Inlined method = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
        }
        System.err.println("  Exception      = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
        System.err.println("Not inlining this method");

        if (DEBUG)
        {
            targetMethod.accept(targetClass, new ClassPrinter());
            if (inlining)
            {
                method.accept(clazz, new ClassPrinter());
            }

            throw ex;
        }
    }
}
 
Example #9
Source File: StackSizeComputer.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the code has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while computing stack sizes:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());
            }

            throw ex;
        }
    }
 
Example #10
Source File: EvaluationSimplifier.java    From proguard with GNU General Public License v2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the evaluation simplifier has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while simplifying instructions after partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
            System.err.println("Not optimizing this method");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                throw ex;
            }
        }
    }
 
Example #11
Source File: StackSizeComputer.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the code has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while computing stack sizes:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());
            }

            throw ex;
        }
    }
 
Example #12
Source File: EvaluationSimplifier.java    From bazel with Apache License 2.0 5 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the evaluation simplifier has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while simplifying instructions after partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");
            System.err.println("Not optimizing this method");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                throw ex;
            }
        }
    }
 
Example #13
Source File: PartialEvaluator.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
    {
//        DEBUG = DEBUG_RESULTS =
//            clazz.getName().equals("abc/Def") &&
//            method.getName(clazz).equals("abc");

        // TODO: Remove this when the partial evaluator has stabilized.
        // Catch any unexpected exceptions from the actual visiting method.
        try
        {
            // Process the code.
            visitCodeAttribute0(clazz, method, codeAttribute);
        }
        catch (RuntimeException ex)
        {
            System.err.println("Unexpected error while performing partial evaluation:");
            System.err.println("  Class       = ["+clazz.getName()+"]");
            System.err.println("  Method      = ["+method.getName(clazz)+method.getDescriptor(clazz)+"]");
            System.err.println("  Exception   = ["+ex.getClass().getName()+"] ("+ex.getMessage()+")");

            if (DEBUG)
            {
                method.accept(clazz, new ClassPrinter());

                System.out.println("Evaluation results:");

                int offset = 0;
                do
                {
                    if (isBranchOrExceptionTarget(offset))
                    {
                        System.out.println("Branch target from ["+branchOriginValues[offset]+"]:");
                        if (isTraced(offset))
                        {
                            System.out.println("  Vars:  "+variablesBefore[offset]);
                            System.out.println("  Stack: "+stacksBefore[offset]);
                        }
                    }

                    Instruction instruction = InstructionFactory.create(codeAttribute.code,
                                                                        offset);
                    System.out.println(instruction.toString(offset));

                    if (isTraced(offset))
                    {
                        int initializationOffset = branchTargetFinder.initializationOffset(offset);
                        if (initializationOffset != NONE)
                        {
                            System.out.println("     is to be initialized at ["+initializationOffset+"]");
                        }

                        InstructionOffsetValue branchTargets = branchTargets(offset);
                        if (branchTargets != null)
                        {
                            System.out.println("     has overall been branching to "+branchTargets);
                        }

                        System.out.println("  Vars:  "+variablesAfter[offset]);
                        System.out.println("  Stack: "+stacksAfter[offset]);
                    }

                    offset += instruction.length(offset);
                }
                while (offset < codeAttribute.u4codeLength);
            }

            throw ex;
        }
    }
 
Example #14
Source File: CodeAttributeComposer.java    From proguard with GNU General Public License v2.0 4 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    if (DEBUG)
    {
        System.out.println("CodeAttributeComposer: putting results in ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"]");
    }

    if (level != -1)
    {
        throw new IllegalArgumentException("Code fragment not ended ["+level+"]");
    }

    level++;

    // Make sure the code attribute has sufficient space for the composed
    // code.
    if (codeAttribute.u4codeLength < codeLength)
    {
        codeAttribute.code = new byte[codeLength];
    }

    // Copy the composed code over into the code attribute.
    codeAttribute.u4codeLength = codeLength;
    System.arraycopy(code, 0, codeAttribute.code, 0, codeLength);

    // Remove exceptions with empty code blocks (done before).
    //exceptionTableLength =
    //    removeEmptyExceptions(exceptionTable, exceptionTableLength);

    // Make sure the exception table has sufficient space for the composed
    // exceptions.
    if (codeAttribute.exceptionTable.length < exceptionTableLength)
    {
        codeAttribute.exceptionTable = new ExceptionInfo[exceptionTableLength];
    }

    // Copy the exception table.
    codeAttribute.u2exceptionTableLength = exceptionTableLength;
    System.arraycopy(exceptionTable, 0, codeAttribute.exceptionTable, 0, exceptionTableLength);

    // Update the maximum stack size and local variable frame size.
    stackSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);
    variableSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);

    // Add a new line number table for the line numbers, if necessary.
    if (lineNumberTableLength > 0 &&
        codeAttribute.getAttribute(clazz, ClassConstants.ATTR_LineNumberTable) == null)
    {
        int attributeNameIndex =
            new ConstantPoolEditor((ProgramClass)clazz)
                .addUtf8Constant(ClassConstants.ATTR_LineNumberTable);

        new AttributesEditor((ProgramClass)clazz, (ProgramMember)method, codeAttribute, false)
            .addAttribute(new LineNumberTableAttribute(attributeNameIndex, 0, null));
    }

    // Copy the line number table and the local variable table.
    codeAttribute.attributesAccept(clazz, method, this);

    // Remap the exception table (done before).
    //codeAttribute.exceptionsAccept(clazz, method, this);

    // Remove exceptions with empty code blocks (done before).
    //codeAttribute.u2exceptionTableLength =
    //    removeEmptyExceptions(codeAttribute.exceptionTable,
    //                          codeAttribute.u2exceptionTableLength);

    // Make sure instructions are widened if necessary.
    instructionWriter.visitCodeAttribute(clazz, method, codeAttribute);

    level--;

    if (DEBUG)
    {
        codeAttribute.accept(clazz, method, new ClassPrinter());
    }
}
 
Example #15
Source File: CodeAttributeComposer.java    From bazel with Apache License 2.0 4 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    if (DEBUG)
    {
        System.out.println("CodeAttributeComposer: putting results in ["+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz)+"]");
    }

    if (level != -1)
    {
        throw new IllegalArgumentException("Code fragment not ended ["+level+"]");
    }

    level++;

    // Make sure the code attribute has sufficient space for the composed
    // code.
    if (codeAttribute.u4codeLength < codeLength)
    {
        codeAttribute.code = new byte[codeLength];
    }

    // Copy the composed code over into the code attribute.
    codeAttribute.u4codeLength = codeLength;
    System.arraycopy(code, 0, codeAttribute.code, 0, codeLength);

    // Remove exceptions with empty code blocks (done before).
    //exceptionTableLength =
    //    removeEmptyExceptions(exceptionTable, exceptionTableLength);

    // Make sure the exception table has sufficient space for the composed
    // exceptions.
    if (codeAttribute.exceptionTable.length < exceptionTableLength)
    {
        codeAttribute.exceptionTable = new ExceptionInfo[exceptionTableLength];
    }

    // Copy the exception table.
    codeAttribute.u2exceptionTableLength = exceptionTableLength;
    System.arraycopy(exceptionTable, 0, codeAttribute.exceptionTable, 0, exceptionTableLength);

    // Update the maximum stack size and local variable frame size.
    stackSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);
    variableSizeUpdater.visitCodeAttribute(clazz, method, codeAttribute);

    // Add a new line number table for the line numbers, if necessary.
    if (lineNumberTableLength > 0 &&
        codeAttribute.getAttribute(clazz, ClassConstants.ATTR_LineNumberTable) == null)
    {
        int attributeNameIndex =
            new ConstantPoolEditor((ProgramClass)clazz)
                .addUtf8Constant(ClassConstants.ATTR_LineNumberTable);

        new AttributesEditor((ProgramClass)clazz, (ProgramMember)method, codeAttribute, false)
            .addAttribute(new LineNumberTableAttribute(attributeNameIndex, 0, null));
    }

    // Copy the line number table and the local variable table.
    codeAttribute.attributesAccept(clazz, method, this);

    // Remap the exception table (done before).
    //codeAttribute.exceptionsAccept(clazz, method, this);

    // Remove exceptions with empty code blocks (done before).
    //codeAttribute.u2exceptionTableLength =
    //    removeEmptyExceptions(codeAttribute.exceptionTable,
    //                          codeAttribute.u2exceptionTableLength);

    // Make sure instructions are widened if necessary.
    instructionWriter.visitCodeAttribute(clazz, method, codeAttribute);

    level--;

    if (DEBUG)
    {
        codeAttribute.accept(clazz, method, new ClassPrinter());
    }
}