Java Code Examples for proguard.optimize.info.ParameterUsageMarker#getParameterSize()

The following examples show how to use proguard.optimize.info.ParameterUsageMarker#getParameterSize() . 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: EvaluationShrinker.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
{
    // Get the total size of the parameters.
    int parameterSize = ParameterUsageMarker.getParameterSize(programMethod);

    // Make the method invocation static, if possible.
    if ((programMethod.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) == 0 &&
        !ParameterUsageMarker.isParameterUsed(programMethod, 0))
    {
        replaceByStaticInvocation(programClass,
                                  invocationOffset,
                                  invocationInstruction);
    }

    // Remove unused parameters.
    for (int index = 0; index < parameterSize; index++)
    {
        if (!ParameterUsageMarker.isParameterUsed(programMethod, index))
        {
            TracedStack stack =
                partialEvaluator.getStackBefore(invocationOffset);

            int stackIndex = stack.size() - parameterSize + index;

            if (DEBUG)
            {
                System.out.println("  ["+invocationOffset+"] Ignoring parameter #"+index+" of "+programClass.getName()+"."+programMethod.getName(programClass)+programMethod.getDescriptor(programClass)+"] (stack entry #"+stackIndex+" ["+stack.getBottom(stackIndex)+"])");
                System.out.println("    Full stack: "+stack);
            }

            markStackSimplificationBefore(invocationOffset, stackIndex);
        }
    }
}
 
Example 2
Source File: ParameterShrinker.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)
{
    // Get the original parameter size that was saved.
    int oldParameterSize = ParameterUsageMarker.getParameterSize(method);

    // Compute the new parameter size from the shrunk descriptor.
    int newParameterSize =
        ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz),
                                              method.getAccessFlags());

    if (oldParameterSize > newParameterSize)
    {
        // Get the total size of the local variable frame.
        int maxLocals = codeAttribute.u2maxLocals;

        if (DEBUG)
        {
            System.out.println("ParameterShrinker: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz));
            System.out.println("  Old parameter size = " + oldParameterSize);
            System.out.println("  New parameter size = " + newParameterSize);
            System.out.println("  Max locals         = " + maxLocals);
        }

        // Create a variable map.
        int[] variableMap = new int[maxLocals];

        // Move unused parameters right after the parameter block.
        int usedParameterIndex   = 0;
        int unusedParameterIndex = newParameterSize;
        for (int parameterIndex = 0; parameterIndex < oldParameterSize; parameterIndex++)
        {
            // Is the variable required as a parameter?
            if (ParameterUsageMarker.isParameterUsed(method, parameterIndex))
            {
                // Keep the variable as a parameter.
                variableMap[parameterIndex] = usedParameterIndex++;
            }
            else
            {
                if (DEBUG)
                {
                    System.out.println("  Deleting parameter #"+parameterIndex);
                }

                // Shift the variable to the unused parameter block,
                // in case it is still used as a variable.
                variableMap[parameterIndex] = unusedParameterIndex++;

                // Visit the method, if required.
                if (extraVariableMemberVisitor != null)
                {
                    method.accept(clazz, extraVariableMemberVisitor);
                }
            }
        }

        // Fill out the remainder of the map.
        for (int variableIndex = oldParameterSize; variableIndex < maxLocals; variableIndex++)
        {
            variableMap[variableIndex] = variableIndex;
        }

        // Set the map.
        variableRemapper.setVariableMap(variableMap);

        // Remap the variables.
        variableRemapper.visitCodeAttribute(clazz, method, codeAttribute);
    }
}
 
Example 3
Source File: ParameterShrinker.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)
{
    // Get the original parameter size that was saved.
    int oldParameterSize = ParameterUsageMarker.getParameterSize(method);

    // Compute the new parameter size from the shrunk descriptor.
    int newParameterSize =
        ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz),
                                              method.getAccessFlags());

    if (oldParameterSize > newParameterSize)
    {
        // Get the total size of the local variable frame.
        int maxLocals = codeAttribute.u2maxLocals;

        if (DEBUG)
        {
            System.out.println("ParameterShrinker: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz));
            System.out.println("  Old parameter size = " + oldParameterSize);
            System.out.println("  New parameter size = " + newParameterSize);
            System.out.println("  Max locals         = " + maxLocals);
        }

        // Create a variable map.
        int[] variableMap = new int[maxLocals];

        // Move unused parameters right after the parameter block.
        int usedParameterIndex   = 0;
        int unusedParameterIndex = newParameterSize;
        for (int parameterIndex = 0; parameterIndex < oldParameterSize; parameterIndex++)
        {
            // Is the variable required as a parameter?
            if (ParameterUsageMarker.isParameterUsed(method, parameterIndex))
            {
                // Keep the variable as a parameter.
                variableMap[parameterIndex] = usedParameterIndex++;
            }
            else
            {
                if (DEBUG)
                {
                    System.out.println("  Deleting parameter #"+parameterIndex);
                }

                // Shift the variable to the unused parameter block,
                // in case it is still used as a variable.
                variableMap[parameterIndex] = unusedParameterIndex++;

                // Visit the method, if required.
                if (extraVariableMemberVisitor != null)
                {
                    method.accept(clazz, extraVariableMemberVisitor);
                }
            }
        }

        // Fill out the remainder of the map.
        for (int variableIndex = oldParameterSize; variableIndex < maxLocals; variableIndex++)
        {
            variableMap[variableIndex] = variableIndex;
        }

        // Set the map.
        variableRemapper.setVariableMap(variableMap);

        // Remap the variables.
        variableRemapper.visitCodeAttribute(clazz, method, codeAttribute);
    }
}
 
Example 4
Source File: ParameterShrinker.java    From bazel with Apache License 2.0 4 votes vote down vote up
public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
{
    // Get the original parameter size that was saved.
    int oldParameterSize = ParameterUsageMarker.getParameterSize(method);

    // Compute the new parameter size from the shrunk descriptor.
    int newParameterSize =
        ClassUtil.internalMethodParameterSize(method.getDescriptor(clazz),
                                              method.getAccessFlags());

    if (oldParameterSize > newParameterSize)
    {
        // Get the total size of the local variable frame.
        int maxLocals = codeAttribute.u2maxLocals;

        if (DEBUG)
        {
            System.out.println("ParameterShrinker: "+clazz.getName()+"."+method.getName(clazz)+method.getDescriptor(clazz));
            System.out.println("  Old parameter size = " + oldParameterSize);
            System.out.println("  New parameter size = " + newParameterSize);
            System.out.println("  Max locals         = " + maxLocals);
        }

        // Create a variable map.
        int[] variableMap = new int[maxLocals];

        // Move unused parameters right after the parameter block.
        int usedParameterIndex   = 0;
        int unusedParameterIndex = newParameterSize;
        for (int parameterIndex = 0; parameterIndex < oldParameterSize; parameterIndex++)
        {
            // Is the variable required as a parameter?
            if (ParameterUsageMarker.isParameterUsed(method, parameterIndex))
            {
                // Keep the variable as a parameter.
                variableMap[parameterIndex] = usedParameterIndex++;
            }
            else
            {
                if (DEBUG)
                {
                    System.out.println("  Deleting parameter #"+parameterIndex);
                }

                // Shift the variable to the unused parameter block,
                // in case it is still used as a variable.
                variableMap[parameterIndex] = unusedParameterIndex++;

                // Visit the method, if required.
                if (extraVariableMemberVisitor != null)
                {
                    method.accept(clazz, extraVariableMemberVisitor);
                }
            }
        }

        // Fill out the remainder of the map.
        for (int variableIndex = oldParameterSize; variableIndex < maxLocals; variableIndex++)
        {
            variableMap[variableIndex] = variableIndex;
        }

        // Set the map.
        variableRemapper.setVariableMap(variableMap);

        // Remap the variables.
        variableRemapper.visitCodeAttribute(clazz, method, codeAttribute);
    }
}