summaryrefslogtreecommitdiff
path: root/src/proguard/shrink
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/shrink')
-rw-r--r--src/proguard/shrink/AnnotationUsageMarker.java327
-rw-r--r--src/proguard/shrink/ClassShrinker.java560
-rw-r--r--src/proguard/shrink/InnerUsageMarker.java174
-rw-r--r--src/proguard/shrink/InterfaceUsageMarker.java152
-rw-r--r--src/proguard/shrink/LocalVariableTypeUsageMarker.java177
-rw-r--r--src/proguard/shrink/ShortestUsageMark.java183
-rw-r--r--src/proguard/shrink/ShortestUsageMarker.java277
-rw-r--r--src/proguard/shrink/ShortestUsagePrinter.java220
-rw-r--r--src/proguard/shrink/Shrinker.java183
-rw-r--r--src/proguard/shrink/SignatureUsageMarker.java120
-rw-r--r--src/proguard/shrink/UsageMarker.java1081
-rw-r--r--src/proguard/shrink/UsagePrinter.java184
-rw-r--r--src/proguard/shrink/UsedClassFilter.java74
-rw-r--r--src/proguard/shrink/UsedMemberFilter.java93
-rw-r--r--src/proguard/shrink/package.html3
15 files changed, 0 insertions, 3808 deletions
diff --git a/src/proguard/shrink/AnnotationUsageMarker.java b/src/proguard/shrink/AnnotationUsageMarker.java
deleted file mode 100644
index 2cc0266..0000000
--- a/src/proguard/shrink/AnnotationUsageMarker.java
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.Attribute;
-import proguard.classfile.attribute.annotation.*;
-import proguard.classfile.attribute.annotation.visitor.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.constant.*;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.*;
-
-/**
- * This AttributeVisitor recursively marks all necessary annotation information
- * in the attributes that it visits.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class AnnotationUsageMarker
-extends SimplifiedVisitor
-implements AttributeVisitor,
- AnnotationVisitor,
- ElementValueVisitor,
- ConstantVisitor,
- ClassVisitor,
- MemberVisitor
-{
- private final UsageMarker usageMarker;
-
- // Fields acting as a return parameters for several methods.
- private boolean attributeUsed;
- private boolean annotationUsed;
- private boolean allClassesUsed;
- private boolean methodUsed;
-
-
- /**
- * Creates a new AnnotationUsageMarker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public AnnotationUsageMarker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
- {
- // Mark the necessary annotation information.
- attributeUsed = false;
- annotationsAttribute.annotationsAccept(clazz, this);
-
- if (attributeUsed)
- {
- // We got a positive used flag, so some annotation is being used.
- // Mark this attribute as being used as well.
- usageMarker.markAsUsed(annotationsAttribute);
-
- markConstant(clazz, annotationsAttribute.u2attributeNameIndex);
- }
- }
-
-
- public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
- {
- // Mark the necessary annotation information.
- attributeUsed = false;
- parameterAnnotationsAttribute.annotationsAccept(clazz, method, this);
-
- if (attributeUsed)
- {
- // We got a positive used flag, so some annotation is being used.
- // Mark this attribute as being used as well.
- usageMarker.markAsUsed(parameterAnnotationsAttribute);
-
- markConstant(clazz, parameterAnnotationsAttribute.u2attributeNameIndex);
- }
- }
-
-
- public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
- {
- // Mark the necessary annotation information in any annotation elements.
- annotationDefaultAttribute.defaultValueAccept(clazz, this);
-
- // Always mark annotation defaults.
- usageMarker.markAsUsed(annotationDefaultAttribute);
-
- markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex);
- }
-
-
- // Implementations for AnnotationVisitor.
-
- public void visitAnnotation(Clazz clazz, Annotation annotation)
- {
- if (isReferencedClassUsed(annotation))
- {
- // Mark the annotation as being used.
- usageMarker.markAsUsed(annotation);
-
- markConstant(clazz, annotation.u2typeIndex);
-
- // Mark the necessary element values.
- annotation.elementValuesAccept(clazz, this);
-
- // The return values.
- annotationUsed = true;
- attributeUsed = true;
- }
- }
-
-
- // Implementations for ElementValueVisitor.
-
- public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
- {
- if (isReferencedMethodUsed(constantElementValue))
- {
- // Mark the element value as being used.
- usageMarker.markAsUsed(constantElementValue);
-
- markConstant(clazz, constantElementValue.u2elementNameIndex);
- markConstant(clazz, constantElementValue.u2constantValueIndex);
- }
- }
-
-
- public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
- {
- if (isReferencedMethodUsed(enumConstantElementValue))
- {
- // Check the referenced classes.
- allClassesUsed = true;
- enumConstantElementValue.referencedClassesAccept(this);
-
- if (allClassesUsed)
- {
- // Mark the element value as being used.
- usageMarker.markAsUsed(enumConstantElementValue);
-
- markConstant(clazz, enumConstantElementValue.u2elementNameIndex);
- markConstant(clazz, enumConstantElementValue.u2typeNameIndex);
- markConstant(clazz, enumConstantElementValue.u2constantNameIndex);
- }
- }
- }
-
-
- public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
- {
- if (isReferencedMethodUsed(classElementValue))
- {
- // Mark the element value as being used.
- usageMarker.markAsUsed(classElementValue);
-
- markConstant(clazz, classElementValue.u2elementNameIndex);
- markConstant(clazz, classElementValue.u2classInfoIndex);
-
- // Mark the referenced classes, since they can be retrieved from
- // the annotation and then used.
- // TODO: This could mark more annotation methods, affecting other annotations.
- classElementValue.referencedClassesAccept(usageMarker);
- }
- }
-
-
- public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
- {
- if (isReferencedMethodUsed(annotationElementValue))
- {
- boolean oldAnnotationUsed = annotationUsed;
-
- // Check and mark the contained annotation.
- annotationUsed = false;
- annotationElementValue.annotationAccept(clazz, this);
-
- if (annotationUsed)
- {
- // Mark the element value as being used.
- usageMarker.markAsUsed(annotationElementValue);
-
- markConstant(clazz, annotationElementValue.u2elementNameIndex);
- }
-
- annotationUsed = oldAnnotationUsed;
- }
- }
-
-
- public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
- {
- if (isReferencedMethodUsed(arrayElementValue))
- {
- // Check and mark the contained element values.
- arrayElementValue.elementValuesAccept(clazz, annotation, this);
-
- // Mark the element value as being used.
- usageMarker.markAsUsed(arrayElementValue);
-
- markConstant(clazz, arrayElementValue.u2elementNameIndex);
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitAnyConstant(Clazz clazz, Constant constant)
- {
- usageMarker.markAsUsed(constant);
- }
-
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- // Is the class constant marked as being used?
- if (!usageMarker.isUsed(classConstant))
- {
- // Check the referenced class.
- allClassesUsed = true;
- classConstant.referencedClassAccept(this);
-
- // Is the referenced class marked as being used?
- if (allClassesUsed)
- {
- // Mark the class constant and its Utf8 constant.
- usageMarker.markAsUsed(classConstant);
-
- markConstant(clazz, classConstant.u2nameIndex);
- }
- }
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- allClassesUsed &= usageMarker.isUsed(programClass);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- methodUsed = usageMarker.isUsed(programMethod);
- }
-
-
- public void visitLibraryMethod(LibraryClass LibraryClass, LibraryMethod libraryMethod)
- {
- }
-
-
- // Small utility methods.
-
- /**
- * Returns whether the annotation class has been marked as being used.
- */
- private boolean isReferencedClassUsed(Annotation annotation)
- {
- // Check if the referenced class is being used.
- allClassesUsed = true;
- annotation.referencedClassAccept(this);
-
- return allClassesUsed;
- }
-
-
- /**
- * Returns whether the annotation method has been marked as being used.
- */
- private boolean isReferencedMethodUsed(ElementValue elementValue)
- {
- // Check if the referenced method is being used.
- methodUsed = true;
- elementValue.referencedMethodAccept(this);
-
- return methodUsed;
- }
-
-
- /**
- * Marks the specified constant pool entry.
- */
- private void markConstant(Clazz clazz, int index)
- {
- if (index > 0)
- {
- clazz.constantPoolEntryAccept(index, this);
- }
- }
-}
diff --git a/src/proguard/shrink/ClassShrinker.java b/src/proguard/shrink/ClassShrinker.java
deleted file mode 100644
index 3c3a55e..0000000
--- a/src/proguard/shrink/ClassShrinker.java
+++ /dev/null
@@ -1,560 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.annotation.*;
-import proguard.classfile.attribute.annotation.visitor.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.*;
-import proguard.classfile.editor.*;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-import java.util.Arrays;
-
-/**
- * This ClassVisitor removes constant pool entries, class members, and other
- * class elements that are not marked as being used.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class ClassShrinker
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor,
- AnnotationVisitor,
- ElementValueVisitor
-{
- private final UsageMarker usageMarker;
-
- private int[] constantIndexMap = new int[ClassConstants.TYPICAL_CONSTANT_POOL_SIZE];
- private int[] bootstrapMethodIndexMap = new int[ClassConstants.TYPICAL_CONSTANT_POOL_SIZE];
- private final ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper();
- private final BootstrapMethodRemapper bootstrapMethodRemapper = new BootstrapMethodRemapper();
-
-
- /**
- * Creates a new ClassShrinker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public ClassShrinker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Shrink the arrays for constant pool, interfaces, fields, methods,
- // and class attributes.
- if (programClass.u2interfacesCount > 0)
- {
- new InterfaceDeleter(shrinkFlags(programClass.constantPool,
- programClass.u2interfaces,
- programClass.u2interfacesCount))
- .visitProgramClass(programClass);
- }
-
- // Shrinking the constant pool also sets up an index map.
- int newConstantPoolCount =
- shrinkConstantPool(programClass.constantPool,
- programClass.u2constantPoolCount);
-
- programClass.u2fieldsCount =
- shrinkArray(programClass.fields,
- programClass.u2fieldsCount);
-
- programClass.u2methodsCount =
- shrinkArray(programClass.methods,
- programClass.u2methodsCount);
-
- programClass.u2attributesCount =
- shrinkArray(programClass.attributes,
- programClass.u2attributesCount);
-
- // Compact the remaining fields, methods, and attributes,
- // and remap their references to the constant pool.
- programClass.fieldsAccept(this);
- programClass.methodsAccept(this);
- programClass.attributesAccept(this);
-
- // Remap the references to the constant pool if it has shrunk.
- if (newConstantPoolCount < programClass.u2constantPoolCount)
- {
- programClass.u2constantPoolCount = newConstantPoolCount;
-
- // Remap all constant pool references.
- constantPoolRemapper.setConstantIndexMap(constantIndexMap);
- constantPoolRemapper.visitProgramClass(programClass);
- }
-
- // Replace any unused classes in the signatures.
- MySignatureCleaner signatureCleaner = new MySignatureCleaner();
- programClass.fieldsAccept(new AllAttributeVisitor(signatureCleaner));
- programClass.methodsAccept(new AllAttributeVisitor(signatureCleaner));
- programClass.attributesAccept(signatureCleaner);
-
- // Compact the extra field pointing to the subclasses of this class.
- programClass.subClasses =
- shrinkToNewArray(programClass.subClasses);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // Library classes are left unchanged.
-
- // Compact the extra field pointing to the subclasses of this class.
- libraryClass.subClasses =
- shrinkToNewArray(libraryClass.subClasses);
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramMember(ProgramClass programClass, ProgramMember programMember)
- {
- // Shrink the attributes array.
- programMember.u2attributesCount =
- shrinkArray(programMember.attributes,
- programMember.u2attributesCount);
-
- // Shrink any attributes.
- programMember.attributesAccept(programClass, this);
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
- {
- // Shrink the array of BootstrapMethodInfo objects.
- int newBootstrapMethodsCount =
- shrinkBootstrapMethodArray(bootstrapMethodsAttribute.bootstrapMethods,
- bootstrapMethodsAttribute.u2bootstrapMethodsCount);
-
- if (newBootstrapMethodsCount < bootstrapMethodsAttribute.u2bootstrapMethodsCount)
- {
- bootstrapMethodsAttribute.u2bootstrapMethodsCount = newBootstrapMethodsCount;
-
- // Remap all constant pool references.
- bootstrapMethodRemapper.setConstantIndexMap(bootstrapMethodIndexMap);
- clazz.constantPoolEntriesAccept(bootstrapMethodRemapper);
- }
- }
-
-
- public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
- {
- // Shrink the array of InnerClassesInfo objects.
- innerClassesAttribute.u2classesCount =
- shrinkArray(innerClassesAttribute.classes,
- innerClassesAttribute.u2classesCount);
- }
-
-
- public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
- {
- // Sometimes, a class is still referenced (apparently as a dummy class),
- // but its enclosing method is not. Then remove the reference to
- // the enclosing method.
- // E.g. the anonymous inner class javax.swing.JList$1 is defined inside
- // a constructor of javax.swing.JList, but it is also referenced as a
- // dummy argument in a constructor of javax.swing.JList$ListSelectionHandler.
- if (enclosingMethodAttribute.referencedMethod != null &&
- !usageMarker.isUsed(enclosingMethodAttribute.referencedMethod))
- {
- enclosingMethodAttribute.u2nameAndTypeIndex = 0;
-
- enclosingMethodAttribute.referencedMethod = null;
- }
- }
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- // Shrink the attributes array.
- codeAttribute.u2attributesCount =
- shrinkArray(codeAttribute.attributes,
- codeAttribute.u2attributesCount);
-
- // Shrink the attributes themselves.
- codeAttribute.attributesAccept(clazz, method, this);
- }
-
-
- public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
- {
- // Shrink the local variable info array.
- localVariableTableAttribute.u2localVariableTableLength =
- shrinkArray(localVariableTableAttribute.localVariableTable,
- localVariableTableAttribute.u2localVariableTableLength);
- }
-
-
- public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
- {
- // Shrink the local variable type info array.
- localVariableTypeTableAttribute.u2localVariableTypeTableLength =
- shrinkArray(localVariableTypeTableAttribute.localVariableTypeTable,
- localVariableTypeTableAttribute.u2localVariableTypeTableLength);
- }
-
-
- public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
- {
- // Shrink the annotations array.
- annotationsAttribute.u2annotationsCount =
- shrinkArray(annotationsAttribute.annotations,
- annotationsAttribute.u2annotationsCount);
-
- // Shrink the annotations themselves.
- annotationsAttribute.annotationsAccept(clazz, this);
- }
-
-
- public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
- {
- // Loop over all parameters.
- for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u1parametersCount; parameterIndex++)
- {
- // Shrink the parameter annotations array.
- parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex] =
- shrinkArray(parameterAnnotationsAttribute.parameterAnnotations[parameterIndex],
- parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex]);
- }
-
- // Shrink the annotations themselves.
- parameterAnnotationsAttribute.annotationsAccept(clazz, method, this);
- }
-
-
- // Implementations for AnnotationVisitor.
-
- public void visitAnnotation(Clazz clazz, Annotation annotation)
- {
- // Shrink the element values array.
- annotation.u2elementValuesCount =
- shrinkArray(annotation.elementValues,
- annotation.u2elementValuesCount);
-
- // Shrink the element values themselves.
- annotation.elementValuesAccept(clazz, this);
- }
-
-
- /**
- * This AttributeVisitor updates the Utf8 constants of signatures
- * of classes, fields, and methods.
- */
- private class MySignatureCleaner
- extends SimplifiedVisitor
- implements AttributeVisitor
- {
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
- {
- Clazz[] referencedClasses = signatureAttribute.referencedClasses;
- if (referencedClasses != null)
- {
- // Go over the classes in the signature.
- String signature = signatureAttribute.getSignature(clazz);
-
- DescriptorClassEnumeration classEnumeration =
- new DescriptorClassEnumeration(signature);
-
- int referencedClassIndex = 0;
-
- // Start construction a new signature.
- StringBuffer newSignatureBuffer = new StringBuffer();
-
- newSignatureBuffer.append(classEnumeration.nextFluff());
-
- while (classEnumeration.hasMoreClassNames())
- {
- String className = classEnumeration.nextClassName();
-
- // Replace the class name if it is unused.
- Clazz referencedClass = referencedClasses[referencedClassIndex];
- if (referencedClass != null &&
- !usageMarker.isUsed(referencedClass))
- {
- className = ClassConstants.NAME_JAVA_LANG_OBJECT;
-
- referencedClasses[referencedClassIndex] = null;
- }
-
- referencedClassIndex++;
-
- newSignatureBuffer.append(className);
- newSignatureBuffer.append(classEnumeration.nextFluff());
- }
-
- // Update the signature.
- ((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());
- }
- }
- }
-
-
- // Implementations for ElementValueVisitor.
-
- public void visitAnyElementValue(Clazz clazz, Annotation annotation, ElementValue elementValue) {}
-
-
- public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
- {
- // Shrink the contained annotation.
- annotationElementValue.annotationAccept(clazz, this);
- }
-
-
- public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
- {
- // Shrink the element values array.
- arrayElementValue.u2elementValuesCount =
- shrinkArray(arrayElementValue.elementValues,
- arrayElementValue.u2elementValuesCount);
-
- // Shrink the element values themselves.
- arrayElementValue.elementValuesAccept(clazz, annotation, this);
- }
-
-
- // Small utility methods.
-
- /**
- * Removes all entries that are not marked as being used from the given
- * constant pool. Creates a map from the old indices to the new indices
- * as a side effect.
- * @return the new number of entries.
- */
- private int shrinkConstantPool(Constant[] constantPool, int length)
- {
- if (constantIndexMap.length < length)
- {
- constantIndexMap = new int[length];
- }
-
- int counter = 1;
- boolean isUsed = false;
-
- // Shift the used constant pool entries together.
- for (int index = 1; index < length; index++)
- {
- constantIndexMap[index] = counter;
-
- Constant constant = constantPool[index];
-
- // Is the constant being used? Don't update the flag if this is the
- // second half of a long entry.
- if (constant != null)
- {
- isUsed = usageMarker.isUsed(constant);
- }
-
- if (isUsed)
- {
- // Remember the new index.
- constantIndexMap[index] = counter;
-
- // Shift the constant pool entry.
- constantPool[counter++] = constant;
- }
- else
- {
- // Remember an invalid index.
- constantIndexMap[index] = -1;
- }
- }
-
- // Clear the remaining constant pool elements.
- Arrays.fill(constantPool, counter, length, null);
-
- return counter;
- }
-
-
- /**
- * Creates an array marking unused constant pool entries for all the
- * elements in the given array of constant pool indices.
- * @return an array of flags indicating unused elements.
- */
- private boolean[] shrinkFlags(Constant[] constantPool, int[] array, int length)
- {
- boolean[] unused = new boolean[length];
-
- // Shift the used objects together.
- for (int index = 0; index < length; index++)
- {
- if (!usageMarker.isUsed(constantPool[array[index]]))
- {
- unused[index] = true;
- }
- }
-
- return unused;
- }
-
-
- /**
- * Removes all indices that point to unused constant pool entries
- * from the given array.
- * @return the new number of indices.
- */
- private int shrinkConstantIndexArray(Constant[] constantPool, int[] array, int length)
- {
- int counter = 0;
-
- // Shift the used objects together.
- for (int index = 0; index < length; index++)
- {
- if (usageMarker.isUsed(constantPool[array[index]]))
- {
- array[counter++] = array[index];
- }
- }
-
- // Clear the remaining array elements.
- Arrays.fill(array, counter, length, 0);
-
- return counter;
- }
-
-
- /**
- * Removes all Clazz objects that are not marked as being used
- * from the given array and returns the remaining objects in a an array
- * of the right size.
- * @return the new array.
- */
- private Clazz[] shrinkToNewArray(Clazz[] array)
- {
- if (array == null)
- {
- return null;
- }
-
- // Shrink the given array in-place.
- int length = shrinkArray(array, array.length);
- if (length == 0)
- {
- return null;
- }
-
- // Return immediately if the array is of right size already.
- if (length == array.length)
- {
- return array;
- }
-
- // Copy the remaining elements into a new array of the right size.
- Clazz[] newArray = new Clazz[length];
- System.arraycopy(array, 0, newArray, 0, length);
- return newArray;
- }
-
-
- /**
- * Removes all entries that are not marked as being used from the given
- * array of bootstrap methods. Creates a map from the old indices to the
- * new indices as a side effect.
- * @return the new number of entries.
- */
- private int shrinkBootstrapMethodArray(BootstrapMethodInfo[] bootstrapMethods, int length)
- {
- if (bootstrapMethodIndexMap.length < length)
- {
- bootstrapMethodIndexMap = new int[length];
- }
-
- int counter = 0;
-
- // Shift the used bootstrap methods together.
- for (int index = 0; index < length; index++)
- {
- BootstrapMethodInfo bootstrapMethod = bootstrapMethods[index];
-
- // Is the entry being used?
- if (usageMarker.isUsed(bootstrapMethod))
- {
- // Remember the new index.
- bootstrapMethodIndexMap[index] = counter;
-
- // Shift the entry.
- bootstrapMethods[counter++] = bootstrapMethod;
- }
- else
- {
- // Remember an invalid index.
- bootstrapMethodIndexMap[index] = -1;
- }
- }
-
- // Clear the remaining bootstrap methods.
- Arrays.fill(bootstrapMethods, counter, length, null);
-
- return counter;
- }
-
-
- /**
- * Removes all VisitorAccepter objects that are not marked as being used
- * from the given array.
- * @return the new number of VisitorAccepter objects.
- */
- private int shrinkArray(VisitorAccepter[] array, int length)
- {
- int counter = 0;
-
- // Shift the used objects together.
- for (int index = 0; index < length; index++)
- {
- VisitorAccepter visitorAccepter = array[index];
-
- if (usageMarker.isUsed(visitorAccepter))
- {
- array[counter++] = visitorAccepter;
- }
- }
-
- // Clear any remaining array elements.
- if (counter < length)
- {
- Arrays.fill(array, counter, length, null);
- }
-
- return counter;
- }
-}
diff --git a/src/proguard/shrink/InnerUsageMarker.java b/src/proguard/shrink/InnerUsageMarker.java
deleted file mode 100644
index a65b519..0000000
--- a/src/proguard/shrink/InnerUsageMarker.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.*;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This AttributeVisitor recursively marks all necessary inner class information
- * in the attributes that it visits.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class InnerUsageMarker
-extends SimplifiedVisitor
-implements AttributeVisitor,
- InnerClassesInfoVisitor,
- ConstantVisitor,
- ClassVisitor
-{
- private final UsageMarker usageMarker;
-
- // Fields acting as a return parameters for several methods.
- private boolean attributeUsed;
- private boolean classUsed;
-
-
- /**
- * Creates a new InnerUsageMarker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public InnerUsageMarker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
- {
- // Mark the necessary inner classes information.
- attributeUsed = false;
- innerClassesAttribute.innerClassEntriesAccept(clazz, this);
-
- if (attributeUsed)
- {
- // We got a positive used flag, so some inner class is being used.
- // Mark this attribute as being used as well.
- usageMarker.markAsUsed(innerClassesAttribute);
-
- markConstant(clazz, innerClassesAttribute.u2attributeNameIndex);
- }
- }
-
-
- // Implementations for InnerClassesInfoVisitor.
-
- public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
- {
- boolean innerClassesInfoUsed = usageMarker.isUsed(innerClassesInfo);
-
- if (!innerClassesInfoUsed)
- {
- // Check if the inner class (if any) is marked as being used.
- classUsed = true;
- innerClassesInfo.innerClassConstantAccept(clazz, this);
- innerClassesInfoUsed = classUsed;
-
- // Check if the outer class (if any) is marked as being used.
- classUsed = true;
- innerClassesInfo.outerClassConstantAccept(clazz, this);
- innerClassesInfoUsed &= classUsed;
-
- // If both the inner class and the outer class are marked as being
- // used, then mark this InnerClassesInfo as well.
- if (innerClassesInfoUsed)
- {
- usageMarker.markAsUsed(innerClassesInfo);
-
- innerClassesInfo.innerNameConstantAccept(clazz, this);
- }
- }
-
- // The return value.
- attributeUsed |= innerClassesInfoUsed;
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- classUsed = usageMarker.isUsed(classConstant);
-
- // Is the class constant marked as being used?
- if (!classUsed)
- {
- // Check the referenced class.
- classUsed = true;
- classConstant.referencedClassAccept(this);
-
- // Is the referenced class marked as being used?
- if (classUsed)
- {
- // Mark the class constant and its Utf8 constant.
- usageMarker.markAsUsed(classConstant);
-
- markConstant(clazz, classConstant.u2nameIndex);
- }
- }
- }
-
-
- public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
- {
- usageMarker.markAsUsed(utf8Constant);
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- classUsed = usageMarker.isUsed(programClass);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- classUsed = true;
- }
-
-
- // Small utility methods.
-
- /**
- * Marks the given constant pool entry of the given class. This includes
- * visiting any other referenced constant pool entries.
- */
- private void markConstant(Clazz clazz, int index)
- {
- clazz.constantPoolEntryAccept(index, this);
- }
-}
diff --git a/src/proguard/shrink/InterfaceUsageMarker.java b/src/proguard/shrink/InterfaceUsageMarker.java
deleted file mode 100644
index ecdf678..0000000
--- a/src/proguard/shrink/InterfaceUsageMarker.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.constant.*;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-
-/**
- * This ClassVisitor recursively marks all interface
- * classes that are being used in the visited class.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class InterfaceUsageMarker
-extends SimplifiedVisitor
-implements ClassVisitor,
- ConstantVisitor
-{
- private final UsageMarker usageMarker;
-
- // Fields acting as a return parameters for several methods.
- private boolean used;
- private boolean anyUsed;
-
-
- /**
- * Creates a new InterfaceUsageMarker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public InterfaceUsageMarker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- boolean classUsed = usageMarker.isUsed(programClass);
- boolean classPossiblyUsed = usageMarker.isPossiblyUsed(programClass);
-
- if (classUsed || classPossiblyUsed)
- {
- // Check if any interfaces are being used.
- boolean oldAnyUsed = anyUsed;
- anyUsed = false;
-
- programClass.interfaceConstantsAccept(this);
-
- classUsed |= anyUsed;
- anyUsed = oldAnyUsed;
-
- // Is this an interface with a preliminary mark?
- if (classPossiblyUsed)
- {
- // Should it be included now?
- if (classUsed)
- {
- // At least one if this interface's interfaces is being used.
- // Mark this interface as well.
- usageMarker.markAsUsed(programClass);
-
- // Mark this interface's name.
- programClass.thisClassConstantAccept(this);
-
- // Mark the superclass (java/lang/Object).
- programClass.superClassConstantAccept(this);
- }
- else
- {
- // Unmark this interface, so we don't bother looking at it again.
- usageMarker.markAsUnused(programClass);
- }
- }
- }
-
- // The return value.
- used = classUsed;
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // The return values.
- used = true;
- anyUsed = true;
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- boolean classUsed = usageMarker.isUsed(classConstant);
-
- if (!classUsed)
- {
- // The ClassConstant isn't marked as being used yet. But maybe it
- // should be included as an interface, so check the actual class.
- classConstant.referencedClassAccept(this);
- classUsed = used;
-
- if (classUsed)
- {
- // The class is being used. Mark the ClassConstant as being used
- // as well.
- usageMarker.markAsUsed(classConstant);
-
- clazz.constantPoolEntryAccept(classConstant.u2nameIndex, this);
- }
- }
-
- // The return values.
- used = classUsed;
- anyUsed |= classUsed;
- }
-
-
- public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
- {
- if (!usageMarker.isUsed(utf8Constant))
- {
- usageMarker.markAsUsed(utf8Constant);
- }
- }
-}
diff --git a/src/proguard/shrink/LocalVariableTypeUsageMarker.java b/src/proguard/shrink/LocalVariableTypeUsageMarker.java
deleted file mode 100644
index 3d6ef27..0000000
--- a/src/proguard/shrink/LocalVariableTypeUsageMarker.java
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.Constant;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This AttributeVisitor recursively marks all information that points to used
- * classes, in the LocalVariableTable and LocalVariableTypeTable attributes that
- * it visits.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class LocalVariableTypeUsageMarker
-extends SimplifiedVisitor
-implements AttributeVisitor,
- LocalVariableInfoVisitor,
- LocalVariableTypeInfoVisitor,
- ClassVisitor,
- ConstantVisitor
-{
- private final UsageMarker usageMarker;
-
- // Fields acting as return values for several visitor methods.
- private boolean tableUsed;
- private boolean variableInfoUsed;
-
-
- /**
- * Creates a new LocalVariableTypeUsageMarker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public LocalVariableTypeUsageMarker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
- {
- // Check and mark the individual entries.
- tableUsed = false;
- localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
-
- // Mark the table if any of the entries is marked.
- if (tableUsed)
- {
- usageMarker.markAsUsed(localVariableTableAttribute);
-
- markConstant(clazz, localVariableTableAttribute.u2attributeNameIndex);
- }
- }
-
-
- public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
- {
- // Check and mark the individual entries.
- tableUsed = false;
- localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
-
- // Mark the table if any of the entries is marked.
- if (tableUsed)
- {
- usageMarker.markAsUsed(localVariableTypeTableAttribute);
-
- markConstant(clazz, localVariableTypeTableAttribute.u2attributeNameIndex);
- }
- }
-
-
- // Implementations for LocalVariableInfoVisitor.
-
- public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
- {
- // Only keep the local variable info if all of its classes are used.
- variableInfoUsed = true;
- localVariableInfo.referencedClassAccept(this);
-
- if (variableInfoUsed)
- {
- // We got a positive used flag, so the local variable info is useful.
- usageMarker.markAsUsed(localVariableInfo);
-
- markConstant(clazz, localVariableInfo.u2nameIndex);
- markConstant(clazz, localVariableInfo.u2descriptorIndex);
-
- tableUsed = true;
- }
- }
-
-
- // Implementations for LocalVariableTypeInfoVisitor.
-
- public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
- {
- // Only keep the local variable info if all of its classes are used.
- variableInfoUsed = true;
- localVariableTypeInfo.referencedClassesAccept(this);
-
- if (variableInfoUsed)
- {
- // We got a positive used flag, so the local variable info is useful.
- usageMarker.markAsUsed(localVariableTypeInfo);
-
- markConstant(clazz, localVariableTypeInfo.u2nameIndex);
- markConstant(clazz, localVariableTypeInfo.u2signatureIndex);
-
- tableUsed = true;
- }
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitLibraryClass(LibraryClass libraryClass) {}
-
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Don't keep the local variable info if one of its classes is not used.
- if (!usageMarker.isUsed(programClass))
- {
- variableInfoUsed = false;
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitAnyConstant(Clazz clazz, Constant constant)
- {
- usageMarker.markAsUsed(constant);
- }
-
-
- // Small utility methods.
-
- /**
- * Marks the given constant pool entry of the given class.
- */
- private void markConstant(Clazz clazz, int index)
- {
- clazz.constantPoolEntryAccept(index, this);
- }
-}
diff --git a/src/proguard/shrink/ShortestUsageMark.java b/src/proguard/shrink/ShortestUsageMark.java
deleted file mode 100644
index 80d1c8f..0000000
--- a/src/proguard/shrink/ShortestUsageMark.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.*;
-
-
-/**
- * This class can be used as a mark when keeping classes, class members, and
- * other elements. It can be certain or preliminary. It also contains additional
- * information about the reasons why an element is being kept.
- *
- * @see ClassShrinker
- *
- * @author Eric Lafortune
- */
-final class ShortestUsageMark
-{
- private final boolean certain;
- private final String reason;
- private final int depth;
- private Clazz clazz;
- private Member member;
-
-
- /**
- * Creates a new certain ShortestUsageMark.
- * @param reason the reason for this mark.
- */
- public ShortestUsageMark(String reason)
- {
- this.certain = true;
- this.reason = reason;
- this.depth = 0;
- }
-
-
- /**
- * Creates a new certain ShortestUsageMark.
- * @param previousUsageMark the previous mark to which this one is linked.
- * @param reason the reason for this mark.
- * @param clazz the class causing this mark.
- */
- public ShortestUsageMark(ShortestUsageMark previousUsageMark,
- String reason,
- int cost,
- Clazz clazz)
- {
- this(previousUsageMark, reason, cost, clazz, null);
- }
-
-
- /**
- * Creates a new certain ShortestUsageMark.
- * @param previousUsageMark the previous mark to which this one is linked.
- * @param reason the reason for this mark.
- * @param clazz the class causing this mark.
- * @param member the member in the above class causing this mark.
- * @param cost the added cost of following this path.
- */
- public ShortestUsageMark(ShortestUsageMark previousUsageMark,
- String reason,
- int cost,
- Clazz clazz,
- Member member)
- {
- this.certain = true;
- this.reason = reason;
- this.depth = previousUsageMark.depth + cost;
- this.clazz = clazz;
- this.member = member;
- }
-
-
- /**
- * Creates a new ShortestUsageMark, based on another mark.
- * @param otherUsageMark the other mark, whose properties will be copied.
- * @param certain specifies whether this is a certain mark.
- */
- public ShortestUsageMark(ShortestUsageMark otherUsageMark,
- boolean certain)
- {
- this.certain = certain;
- this.reason = otherUsageMark.reason;
- this.depth = otherUsageMark.depth;
- this.clazz = otherUsageMark.clazz;
- this.member = otherUsageMark.member;
- }
-
-
- /**
- * Returns whether this is a certain mark.
- */
- public boolean isCertain()
- {
- return certain;
- }
-
-
- /**
- * Returns the reason for this mark.
- */
- public String getReason()
- {
- return reason;
- }
-
-
- /**
- * Returns whether this mark has a shorter chain of reasons than the
- * given mark.
- */
- public boolean isShorter(ShortestUsageMark otherUsageMark)
- {
- return this.depth < otherUsageMark.depth;
- }
-
-
- /**
- * Returns whether this is mark is caused by the given class.
- */
- public boolean isCausedBy(Clazz clazz)
- {
- return clazz.equals(this.clazz);
- }
-
-
- /**
- * Applies the given class visitor to this mark's class, if any,
- * and if this mark doesn't have a member.
- */
- public void acceptClassVisitor(ClassVisitor classVisitor)
- {
- if (clazz != null &&
- member == null)
- {
- clazz.accept(classVisitor);
- }
- }
-
-
- /**
- * Applies the given class visitor to this mark's member, if any.
- */
- public void acceptMemberVisitor(MemberVisitor memberVisitor)
- {
- if (clazz != null &&
- member != null)
- {
- member.accept(clazz, memberVisitor);
- }
- }
-
-
- // Implementations for Object.
-
- public String toString()
- {
- return "certain=" + certain + ", depth="+depth+": " +
- reason +
- (clazz != null ? clazz.getName() : "(none)") + ": " +
- (member != null ? member.getName(clazz) : "(none)");
- }
-}
diff --git a/src/proguard/shrink/ShortestUsageMarker.java b/src/proguard/shrink/ShortestUsageMarker.java
deleted file mode 100644
index 6718e68..0000000
--- a/src/proguard/shrink/ShortestUsageMarker.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.*;
-
-
-/**
- * This ClassVisitor and MemberVisitor recursively marks all classes
- * and class elements that are being used. For each element, it finds the
- * shortest chain of dependencies.
- *
- * @see ClassShrinker
- *
- * @author Eric Lafortune
- */
-public class ShortestUsageMarker extends UsageMarker
-{
- private static final ShortestUsageMark INITIAL_MARK =
- new ShortestUsageMark("is kept by a directive in the configuration.\n\n");
-
-
- // A field acting as a parameter to the visitor methods.
- private ShortestUsageMark currentUsageMark = INITIAL_MARK;
-
- // A utility object to check for recursive causes.
- private final MyRecursiveCauseChecker recursiveCauseChecker = new MyRecursiveCauseChecker();
-
-
- // Overriding implementations for UsageMarker.
-
- protected void markProgramClassBody(ProgramClass programClass)
- {
- ShortestUsageMark previousUsageMark = currentUsageMark;
-
- currentUsageMark = new ShortestUsageMark(getShortestUsageMark(programClass),
- "is extended by ",
- 10000,
- programClass);
-
- super.markProgramClassBody(programClass);
-
- currentUsageMark = previousUsageMark;
- }
-
-
- protected void markProgramFieldBody(ProgramClass programClass, ProgramField programField)
- {
- ShortestUsageMark previousUsageMark = currentUsageMark;
-
- currentUsageMark = new ShortestUsageMark(getShortestUsageMark(programField),
- "is referenced by ",
- 1,
- programClass,
- programField);
-
- super.markProgramFieldBody(programClass, programField);
-
- currentUsageMark = previousUsageMark;
- }
-
-
- protected void markProgramMethodBody(ProgramClass programClass, ProgramMethod programMethod)
- {
- ShortestUsageMark previousUsageMark = currentUsageMark;
-
- currentUsageMark = new ShortestUsageMark(getShortestUsageMark(programMethod),
- "is invoked by ",
- 1,
- programClass,
- programMethod);
-
- super.markProgramMethodBody(programClass, programMethod);
-
- currentUsageMark = previousUsageMark;
- }
-
-
- protected void markMethodHierarchy(Clazz clazz, Method method)
- {
- ShortestUsageMark previousUsageMark = currentUsageMark;
-
- currentUsageMark = new ShortestUsageMark(getShortestUsageMark(method),
- "implements ",
- 100,
- clazz,
- method);
-
- super.markMethodHierarchy(clazz, method);
-
- currentUsageMark = previousUsageMark;
- }
-
-
- // Small utility methods.
-
- protected void markAsUsed(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- ShortestUsageMark shortestUsageMark =
- visitorInfo != null &&
- visitorInfo instanceof ShortestUsageMark &&
- !((ShortestUsageMark)visitorInfo).isCertain() &&
- !currentUsageMark.isShorter((ShortestUsageMark)visitorInfo) ?
- new ShortestUsageMark((ShortestUsageMark)visitorInfo, true):
- currentUsageMark;
-
- visitorAccepter.setVisitorInfo(shortestUsageMark);
- }
-
-
- protected boolean shouldBeMarkedAsUsed(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- return //!(visitorAccepter instanceof Clazz &&
- // isCausedBy(currentUsageMark, (Clazz)visitorAccepter)) &&
- (visitorInfo == null ||
- !(visitorInfo instanceof ShortestUsageMark) ||
- !((ShortestUsageMark)visitorInfo).isCertain() ||
- currentUsageMark.isShorter((ShortestUsageMark)visitorInfo));
- }
-
-
- protected boolean isUsed(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- return visitorInfo != null &&
- visitorInfo instanceof ShortestUsageMark &&
- ((ShortestUsageMark)visitorInfo).isCertain();
- }
-
-
- protected void markAsPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- visitorAccepter.setVisitorInfo(new ShortestUsageMark(currentUsageMark, false));
- }
-
-
- protected boolean shouldBeMarkedAsPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- return visitorInfo == null ||
- !(visitorInfo instanceof ShortestUsageMark) ||
- (!((ShortestUsageMark)visitorInfo).isCertain() &&
- currentUsageMark.isShorter((ShortestUsageMark)visitorInfo));
- }
-
-
- protected boolean isPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- return visitorInfo != null &&
- visitorInfo instanceof ShortestUsageMark &&
- !((ShortestUsageMark)visitorInfo).isCertain();
- }
-
-
- protected ShortestUsageMark getShortestUsageMark(VisitorAccepter visitorAccepter)
- {
- Object visitorInfo = visitorAccepter.getVisitorInfo();
-
- return (ShortestUsageMark)visitorInfo;
- }
-
-
- // Small utility methods.
-
- private boolean isCausedBy(ShortestUsageMark shortestUsageMark,
- Clazz clazz)
- {
- return recursiveCauseChecker.check(shortestUsageMark, clazz);
- }
-
-
- private class MyRecursiveCauseChecker implements ClassVisitor, MemberVisitor
- {
- private Clazz checkClass;
- private boolean isRecursing;
-
-
- public boolean check(ShortestUsageMark shortestUsageMark,
- Clazz clazz)
- {
- checkClass = clazz;
- isRecursing = false;
-
- shortestUsageMark.acceptClassVisitor(this);
- shortestUsageMark.acceptMemberVisitor(this);
-
- return isRecursing;
- }
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- checkCause(programClass);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- checkCause(libraryClass);
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- checkCause(programField);
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- checkCause(programMethod);
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- checkCause(libraryField);
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- checkCause(libraryMethod);
- }
-
-
- // Small utility methods.
-
- private void checkCause(VisitorAccepter visitorAccepter)
- {
- if (ShortestUsageMarker.this.isUsed(visitorAccepter))
- {
- ShortestUsageMark shortestUsageMark = ShortestUsageMarker.this.getShortestUsageMark(visitorAccepter);
-
- // Check the class of this mark, if any
- isRecursing = shortestUsageMark.isCausedBy(checkClass);
-
- // Check the causing class or method, if still necessary.
- if (!isRecursing)
- {
- shortestUsageMark.acceptClassVisitor(this);
- shortestUsageMark.acceptMemberVisitor(this);
- }
- }
- }
- }
-}
diff --git a/src/proguard/shrink/ShortestUsagePrinter.java b/src/proguard/shrink/ShortestUsagePrinter.java
deleted file mode 100644
index c6075ea..0000000
--- a/src/proguard/shrink/ShortestUsagePrinter.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-import java.io.PrintStream;
-
-
-/**
- * This ClassVisitor and MemberVisitor prints out the reasons why
- * classes and class members have been marked as being used.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class ShortestUsagePrinter
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor
-{
- private final ShortestUsageMarker shortestUsageMarker;
- private final boolean verbose;
- private final PrintStream ps;
-
-
- /**
- * Creates a new UsagePrinter that prints verbosely to <code>System.out</code>.
- * @param shortestUsageMarker the usage marker that was used to mark the
- * classes and class members.
- */
- public ShortestUsagePrinter(ShortestUsageMarker shortestUsageMarker)
- {
- this(shortestUsageMarker, true);
- }
-
-
- /**
- * Creates a new UsagePrinter that prints to the given stream.
- * @param shortestUsageMarker the usage marker that was used to mark the
- * classes and class members.
- * @param verbose specifies whether the output should be verbose.
- */
- public ShortestUsagePrinter(ShortestUsageMarker shortestUsageMarker,
- boolean verbose)
- {
- this(shortestUsageMarker, verbose, System.out);
- }
-
- /**
- * Creates a new UsagePrinter that prints to the given stream.
- * @param shortestUsageMarker the usage marker that was used to mark the
- * classes and class members.
- * @param verbose specifies whether the output should be verbose.
- * @param printStream the stream to which to print.
- */
- public ShortestUsagePrinter(ShortestUsageMarker shortestUsageMarker,
- boolean verbose,
- PrintStream printStream)
- {
- this.shortestUsageMarker = shortestUsageMarker;
- this.verbose = verbose;
- this.ps = printStream;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Print the name of this class.
- ps.println(ClassUtil.externalClassName(programClass.getName()));
-
- // Print the reason for keeping this class.
- printReason(programClass);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // Print the name of this class.
- ps.println(ClassUtil.externalClassName(libraryClass.getName()));
-
- // Print the reason for keeping this class.
- ps.println(" is a library class.\n");
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- // Print the name of this field.
- String name = programField.getName(programClass);
- String type = programField.getDescriptor(programClass);
-
- ps.println(ClassUtil.externalClassName(programClass.getName()) +
- (verbose ?
- ": " + ClassUtil.externalFullFieldDescription(0, name, type):
- "." + name));
-
- // Print the reason for keeping this method.
- printReason(programField);
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- // Print the name of this method.
- String name = programMethod.getName(programClass);
- String type = programMethod.getDescriptor(programClass);
-
- ps.print(ClassUtil.externalClassName(programClass.getName()) +
- (verbose ?
- ": " + ClassUtil.externalFullMethodDescription(programClass.getName(), 0, name, type):
- "." + name));
- programMethod.attributesAccept(programClass, this);
- ps.println();
-
- // Print the reason for keeping this method.
- printReason(programMethod);
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- // Print the name of this field.
- String name = libraryField.getName(libraryClass);
- String type = libraryField.getDescriptor(libraryClass);
-
- ps.println(ClassUtil.externalClassName(libraryClass.getName()) +
- (verbose ?
- ": " + ClassUtil.externalFullFieldDescription(0, name, type):
- "." + name));
-
- // Print the reason for keeping this field.
- ps.println(" is a library field.\n");
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- // Print the name of this method.
- String name = libraryMethod.getName(libraryClass);
- String type = libraryMethod.getDescriptor(libraryClass);
-
- ps.println(ClassUtil.externalClassName(libraryClass.getName()) +
- (verbose ?
- ": " + ClassUtil.externalFullMethodDescription(libraryClass.getName(), 0, name, type):
- "." + name));
-
- // Print the reason for keeping this method.
- ps.println(" is a library method.\n");
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- codeAttribute.attributesAccept(clazz, method, this);
- }
-
-
- public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
- {
- ps.print(" (" +
- lineNumberTableAttribute.getLowestLineNumber() + ":" +
- lineNumberTableAttribute.getHighestLineNumber() + ")");
- }
-
-
- // Small utility methods.
-
- private void printReason(VisitorAccepter visitorAccepter)
- {
- if (shortestUsageMarker.isUsed(visitorAccepter))
- {
- ShortestUsageMark shortestUsageMark = shortestUsageMarker.getShortestUsageMark(visitorAccepter);
-
- // Print the reason for keeping this class.
- ps.print(" " + shortestUsageMark.getReason());
-
- // Print the class or method that is responsible, with its reasons.
- shortestUsageMark.acceptClassVisitor(this);
- shortestUsageMark.acceptMemberVisitor(this);
- }
- else
- {
- ps.println(" is not being kept.\n");
- }
- }
-}
diff --git a/src/proguard/shrink/Shrinker.java b/src/proguard/shrink/Shrinker.java
deleted file mode 100644
index 72f878b..0000000
--- a/src/proguard/shrink/Shrinker.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.*;
-import proguard.classfile.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.visitor.*;
-
-import java.io.*;
-
-/**
- * This class shrinks class pools according to a given configuration.
- *
- * @author Eric Lafortune
- */
-public class Shrinker
-{
- private final Configuration configuration;
-
-
- /**
- * Creates a new Shrinker.
- */
- public Shrinker(Configuration configuration)
- {
- this.configuration = configuration;
- }
-
-
- /**
- * Performs shrinking of the given program class pool.
- */
- public ClassPool execute(ClassPool programClassPool,
- ClassPool libraryClassPool) throws IOException
- {
- // Check if we have at least some keep commands.
- if (configuration.keep == null)
- {
- throw new IOException("You have to specify '-keep' options for the shrinking step.");
- }
-
- // Clean up any old visitor info.
- programClassPool.classesAccept(new ClassCleaner());
- libraryClassPool.classesAccept(new ClassCleaner());
-
- // Create a visitor for marking the seeds.
- UsageMarker usageMarker = configuration.whyAreYouKeeping == null ?
- new UsageMarker() :
- new ShortestUsageMarker();
-
- // Automatically mark the parameterless constructors of seed classes,
- // mainly for convenience and for backward compatibility.
- ClassVisitor classUsageMarker =
- new MultiClassVisitor(new ClassVisitor[]
- {
- usageMarker,
- new NamedMethodVisitor(ClassConstants.METHOD_NAME_INIT,
- ClassConstants.METHOD_TYPE_INIT,
- usageMarker)
- });
-
- ClassPoolVisitor classPoolvisitor =
- ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.keep,
- classUsageMarker,
- usageMarker,
- true,
- false,
- false);
- // Mark the seeds.
- programClassPool.accept(classPoolvisitor);
- libraryClassPool.accept(classPoolvisitor);
- libraryClassPool.classesAccept(usageMarker);
-
- // Mark interfaces that have to be kept.
- programClassPool.classesAccept(new InterfaceUsageMarker(usageMarker));
-
- // Mark the inner class and annotation information that has to be kept.
- programClassPool.classesAccept(
- new UsedClassFilter(usageMarker,
- new AllAttributeVisitor(true,
- new MultiAttributeVisitor(new AttributeVisitor[]
- {
- new InnerUsageMarker(usageMarker),
- new AnnotationUsageMarker(usageMarker),
- new LocalVariableTypeUsageMarker(usageMarker)
- }))));
-
- // Should we explain ourselves?
- if (configuration.whyAreYouKeeping != null)
- {
- System.out.println();
-
- // Create a visitor for explaining classes and class members.
- ShortestUsagePrinter shortestUsagePrinter =
- new ShortestUsagePrinter((ShortestUsageMarker)usageMarker,
- configuration.verbose);
-
- ClassPoolVisitor whyClassPoolvisitor =
- ClassSpecificationVisitorFactory.createClassPoolVisitor(configuration.whyAreYouKeeping,
- shortestUsagePrinter,
- shortestUsagePrinter);
-
- // Mark the seeds.
- programClassPool.accept(whyClassPoolvisitor);
- libraryClassPool.accept(whyClassPoolvisitor);
- }
-
- if (configuration.printUsage != null)
- {
- PrintStream ps =
- configuration.printUsage == Configuration.STD_OUT ? System.out :
- new PrintStream(
- new BufferedOutputStream(
- new FileOutputStream(configuration.printUsage)));
-
- // Print out items that will be removed.
- programClassPool.classesAcceptAlphabetically(
- new UsagePrinter(usageMarker, true, ps));
-
- if (ps == System.out)
- {
- ps.flush();
- }
- else
- {
- ps.close();
- }
- }
-
- // Clean up used program classes and discard unused program classes.
- int originalProgramClassPoolSize = programClassPool.size();
-
- ClassPool newProgramClassPool = new ClassPool();
- programClassPool.classesAccept(
- new UsedClassFilter(usageMarker,
- new MultiClassVisitor(
- new ClassVisitor[] {
- new ClassShrinker(usageMarker),
- new ClassPoolFiller(newProgramClassPool)
- })));
-
- programClassPool.clear();
-
- // Clean up library classes.
- libraryClassPool.classesAccept(
- new ClassShrinker(usageMarker));
-
- // Check if we have at least some output classes.
- int newProgramClassPoolSize = newProgramClassPool.size();
- if (newProgramClassPoolSize == 0)
- {
- throw new IOException("The output jar is empty. Did you specify the proper '-keep' options?");
- }
-
- if (configuration.verbose)
- {
- System.out.println("Removing unused program classes and class elements...");
- System.out.println(" Original number of program classes: " + originalProgramClassPoolSize);
- System.out.println(" Final number of program classes: " + newProgramClassPoolSize);
- }
-
- return newProgramClassPool;
- }
-}
diff --git a/src/proguard/shrink/SignatureUsageMarker.java b/src/proguard/shrink/SignatureUsageMarker.java
deleted file mode 100644
index 91bfcdd..0000000
--- a/src/proguard/shrink/SignatureUsageMarker.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.constant.Constant;
-import proguard.classfile.constant.visitor.ConstantVisitor;
-import proguard.classfile.util.SimplifiedVisitor;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This AttributeVisitor recursively marks all Signature attributes that it
- * visits and that point to used classes.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class SignatureUsageMarker
-extends SimplifiedVisitor
-implements AttributeVisitor,
- ClassVisitor,
- ConstantVisitor
-{
- private final UsageMarker usageMarker;
-
- // Fields acting as a return parameters for several methods.
- private boolean attributeUsed;
-
-
- /**
- * Creates a new SignatureUsageMarker.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- */
- public SignatureUsageMarker(UsageMarker usageMarker)
- {
- this.usageMarker = usageMarker;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
- {
- // Only keep the signature if any of its classes are used.
- attributeUsed = false;
- signatureAttribute.referencedClassesAccept(this);
-
- if (attributeUsed)
- {
- // We got a positive used flag, so the signature is useful.
- usageMarker.markAsUsed(signatureAttribute);
-
- markConstant(clazz, signatureAttribute.u2attributeNameIndex);
- markConstant(clazz, signatureAttribute.u2signatureIndex);
- }
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- attributeUsed = true;
- }
-
-
- public void visitProgramClass(ProgramClass programClass)
- {
- // Don't keep the signature if one of its classes is not used.
- if (usageMarker.isUsed(programClass))
- {
- attributeUsed = true;
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitAnyConstant(Clazz clazz, Constant constant)
- {
- usageMarker.markAsUsed(constant);
- }
-
-
- // Small utility methods.
-
- /**
- * Marks the given constant pool entry of the given class.
- */
- private void markConstant(Clazz clazz, int index)
- {
- clazz.constantPoolEntryAccept(index, this);
- }
-}
diff --git a/src/proguard/shrink/UsageMarker.java b/src/proguard/shrink/UsageMarker.java
deleted file mode 100644
index 88a88fd..0000000
--- a/src/proguard/shrink/UsageMarker.java
+++ /dev/null
@@ -1,1081 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.annotation.*;
-import proguard.classfile.attribute.preverification.*;
-import proguard.classfile.attribute.preverification.visitor.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.*;
-import proguard.classfile.constant.visitor.*;
-import proguard.classfile.instruction.*;
-import proguard.classfile.instruction.visitor.InstructionVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-
-/**
- * This ClassVisitor and MemberVisitor recursively marks all classes and class
- * elements that are being used.
- *
- * @see ClassShrinker
- *
- * @author Eric Lafortune
- */
-class UsageMarker
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- ConstantVisitor,
- AttributeVisitor,
- InnerClassesInfoVisitor,
- ExceptionInfoVisitor,
- StackMapFrameVisitor,
- VerificationTypeVisitor,
- ParameterInfoVisitor,
- LocalVariableInfoVisitor,
- LocalVariableTypeInfoVisitor,
-// AnnotationVisitor,
-// ElementValueVisitor,
- InstructionVisitor
-{
- // A visitor info flag to indicate the ProgramMember object is being used,
- // if its Clazz can be determined as being used as well.
- private static final Object POSSIBLY_USED = new Object();
- // A visitor info flag to indicate the visitor accepter is being used.
- private static final Object USED = new Object();
-
-
- private final MyInterfaceUsageMarker interfaceUsageMarker = new MyInterfaceUsageMarker();
- private final MyPossiblyUsedMemberUsageMarker possiblyUsedMemberUsageMarker = new MyPossiblyUsedMemberUsageMarker();
- private final MemberVisitor nonEmptyMethodUsageMarker = new AllAttributeVisitor(
- new MyNonEmptyMethodUsageMarker());
- private final ConstantVisitor parameterlessConstructorMarker = new ConstantTagFilter(new int[] { ClassConstants.CONSTANT_String, ClassConstants.CONSTANT_Class },
- new ReferencedClassVisitor(
- new NamedMethodVisitor(ClassConstants.METHOD_NAME_INIT,
- ClassConstants.METHOD_TYPE_INIT,
- this)));
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- if (shouldBeMarkedAsUsed(programClass))
- {
- // Mark this class.
- markAsUsed(programClass);
-
- markProgramClassBody(programClass);
- }
- }
-
-
- protected void markProgramClassBody(ProgramClass programClass)
- {
- // Mark this class's name.
- markConstant(programClass, programClass.u2thisClass);
-
- // Mark the superclass.
- if (programClass.u2superClass != 0)
- {
- markConstant(programClass, programClass.u2superClass);
- }
-
- // Give the interfaces preliminary marks.
- programClass.hierarchyAccept(false, false, true, false,
- interfaceUsageMarker);
-
- // Explicitly mark the <clinit> method, if it's not empty.
- programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT,
- ClassConstants.METHOD_TYPE_CLINIT,
- nonEmptyMethodUsageMarker);
-
- // Process all class members that have already been marked as possibly used.
- programClass.fieldsAccept(possiblyUsedMemberUsageMarker);
- programClass.methodsAccept(possiblyUsedMemberUsageMarker);
-
- // Mark the attributes.
- programClass.attributesAccept(this);
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- if (shouldBeMarkedAsUsed(libraryClass))
- {
- markAsUsed(libraryClass);
-
- // We're not going to analyze all library code. We're assuming that
- // if this class is being used, all of its methods will be used as
- // well. We'll mark them as such (here and in all subclasses).
-
- // Mark the superclass.
- Clazz superClass = libraryClass.superClass;
- if (superClass != null)
- {
- superClass.accept(this);
- }
-
- // Mark the interfaces.
- Clazz[] interfaceClasses = libraryClass.interfaceClasses;
- if (interfaceClasses != null)
- {
- for (int index = 0; index < interfaceClasses.length; index++)
- {
- if (interfaceClasses[index] != null)
- {
- interfaceClasses[index].accept(this);
- }
- }
- }
-
- // Mark all methods.
- libraryClass.methodsAccept(this);
- }
- }
-
-
- /**
- * This ClassVisitor marks ProgramClass objects as possibly used,
- * and it visits LibraryClass objects with its outer UsageMarker.
- */
- private class MyInterfaceUsageMarker
- implements ClassVisitor
- {
- public void visitProgramClass(ProgramClass programClass)
- {
- if (shouldBeMarkedAsPossiblyUsed(programClass))
- {
- // We can't process the interface yet, because it might not
- // be required. Give it a preliminary mark.
- markAsPossiblyUsed(programClass);
- }
- }
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- // Make sure all library interface methods are marked.
- UsageMarker.this.visitLibraryClass(libraryClass);
- }
- }
-
-
- /**
- * This MemberVisitor marks ProgramField and ProgramMethod objects that
- * have already been marked as possibly used.
- */
- private class MyPossiblyUsedMemberUsageMarker
- extends SimplifiedVisitor
- implements MemberVisitor
- {
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- // Has the method already been referenced?
- if (isPossiblyUsed(programField))
- {
- markAsUsed(programField);
-
- // Mark the name and descriptor.
- markConstant(programClass, programField.u2nameIndex);
- markConstant(programClass, programField.u2descriptorIndex);
-
- // Mark the attributes.
- programField.attributesAccept(programClass, UsageMarker.this);
-
- // Mark the classes referenced in the descriptor string.
- programField.referencedClassesAccept(UsageMarker.this);
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- // Has the method already been referenced?
- if (isPossiblyUsed(programMethod))
- {
- markAsUsed(programMethod);
-
- // Mark the method body.
- markProgramMethodBody(programClass, programMethod);
-
- // Note that, if the method has been marked as possibly used,
- // the method hierarchy has already been marked (cfr. below).
- }
- }
- }
-
-
- /**
- * This AttributeVisitor marks ProgramMethod objects of non-empty methods.
- */
- private class MyNonEmptyMethodUsageMarker
- extends SimplifiedVisitor
- implements AttributeVisitor
- {
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- if (codeAttribute.u4codeLength > 1)
- {
- method.accept(clazz, UsageMarker.this);
- }
- }
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- if (shouldBeMarkedAsUsed(programField))
- {
- // Is the field's class used?
- if (isUsed(programClass))
- {
- markAsUsed(programField);
-
- // Mark the field body.
- markProgramFieldBody(programClass, programField);
- }
-
- // Hasn't the field been marked as possibly being used yet?
- else if (shouldBeMarkedAsPossiblyUsed(programField))
- {
- // We can't process the field yet, because the class isn't
- // marked as being used (yet). Give it a preliminary mark.
- markAsPossiblyUsed(programField);
- }
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- if (shouldBeMarkedAsUsed(programMethod))
- {
- // Is the method's class used?
- if (isUsed(programClass))
- {
- markAsUsed(programMethod);
-
- // Mark the method body.
- markProgramMethodBody(programClass, programMethod);
-
- // Mark the method hierarchy.
- markMethodHierarchy(programClass, programMethod);
- }
-
- // Hasn't the method been marked as possibly being used yet?
- else if (shouldBeMarkedAsPossiblyUsed(programMethod))
- {
- // We can't process the method yet, because the class isn't
- // marked as being used (yet). Give it a preliminary mark.
- markAsPossiblyUsed(programMethod);
-
- // Mark the method hierarchy.
- markMethodHierarchy(programClass, programMethod);
- }
- }
- }
-
-
- public void visitLibraryField(LibraryClass programClass, LibraryField programField) {}
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- if (shouldBeMarkedAsUsed(libraryMethod))
- {
- markAsUsed(libraryMethod);
-
- // Mark the method hierarchy.
- markMethodHierarchy(libraryClass, libraryMethod);
- }
- }
-
-
- protected void markProgramFieldBody(ProgramClass programClass, ProgramField programField)
- {
- // Mark the name and descriptor.
- markConstant(programClass, programField.u2nameIndex);
- markConstant(programClass, programField.u2descriptorIndex);
-
- // Mark the attributes.
- programField.attributesAccept(programClass, this);
-
- // Mark the classes referenced in the descriptor string.
- programField.referencedClassesAccept(this);
- }
-
-
- protected void markProgramMethodBody(ProgramClass programClass, ProgramMethod programMethod)
- {
- // Mark the name and descriptor.
- markConstant(programClass, programMethod.u2nameIndex);
- markConstant(programClass, programMethod.u2descriptorIndex);
-
- // Mark the attributes.
- programMethod.attributesAccept(programClass, this);
-
- // Mark the classes referenced in the descriptor string.
- programMethod.referencedClassesAccept(this);
- }
-
-
- /**
- * Marks the hierarchy of implementing or overriding methods corresponding
- * to the given method, if any.
- */
- protected void markMethodHierarchy(Clazz clazz, Method method)
- {
- int accessFlags = method.getAccessFlags();
- if ((accessFlags &
- (ClassConstants.ACC_PRIVATE |
- ClassConstants.ACC_STATIC)) == 0 &&
- !ClassUtil.isInitializer(method.getName(clazz)))
- {
- // We can skip private and static methods in the hierarchy, and
- // also abstract methods, unless they might widen a current
- // non-public access.
- int requiredUnsetAccessFlags =
- ClassConstants.ACC_PRIVATE |
- ClassConstants.ACC_STATIC |
- ((accessFlags & ClassConstants.ACC_PUBLIC) == 0 ? 0 :
- ClassConstants.ACC_ABSTRACT);
-
- clazz.accept(new ConcreteClassDownTraveler(
- new ClassHierarchyTraveler(true, true, false, true,
- new NamedMethodVisitor(method.getName(clazz),
- method.getDescriptor(clazz),
- new MemberAccessFilter(0, requiredUnsetAccessFlags,
- this)))));
- }
- }
-
-
- // Implementations for ConstantVisitor.
-
- public void visitIntegerConstant(Clazz clazz, IntegerConstant integerConstant)
- {
- if (shouldBeMarkedAsUsed(integerConstant))
- {
- markAsUsed(integerConstant);
- }
- }
-
-
- public void visitLongConstant(Clazz clazz, LongConstant longConstant)
- {
- if (shouldBeMarkedAsUsed(longConstant))
- {
- markAsUsed(longConstant);
- }
- }
-
-
- public void visitFloatConstant(Clazz clazz, FloatConstant floatConstant)
- {
- if (shouldBeMarkedAsUsed(floatConstant))
- {
- markAsUsed(floatConstant);
- }
- }
-
-
- public void visitDoubleConstant(Clazz clazz, DoubleConstant doubleConstant)
- {
- if (shouldBeMarkedAsUsed(doubleConstant))
- {
- markAsUsed(doubleConstant);
- }
- }
-
-
- public void visitStringConstant(Clazz clazz, StringConstant stringConstant)
- {
- if (shouldBeMarkedAsUsed(stringConstant))
- {
- markAsUsed(stringConstant);
-
- markConstant(clazz, stringConstant.u2stringIndex);
-
- // Mark the referenced class and class member, if any.
- stringConstant.referencedClassAccept(this);
- stringConstant.referencedMemberAccept(this);
- }
- }
-
-
- public void visitUtf8Constant(Clazz clazz, Utf8Constant utf8Constant)
- {
- if (shouldBeMarkedAsUsed(utf8Constant))
- {
- markAsUsed(utf8Constant);
- }
- }
-
-
- public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant)
- {
- if (shouldBeMarkedAsUsed(invokeDynamicConstant))
- {
- markAsUsed(invokeDynamicConstant);
-
- markConstant(clazz, invokeDynamicConstant.u2nameAndTypeIndex);
-
- // Mark the referenced descriptor classes.
- invokeDynamicConstant.referencedClassesAccept(this);
-
- // Mark the bootstrap methods attribute.
- clazz.attributesAccept(new MyBootStrapMethodUsageMarker(invokeDynamicConstant.u2bootstrapMethodAttributeIndex));
- }
- }
-
-
- public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant)
- {
- if (shouldBeMarkedAsUsed(methodHandleConstant))
- {
- markAsUsed(methodHandleConstant);
-
- markConstant(clazz, methodHandleConstant.u2referenceIndex);
- }
- }
-
-
- public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant)
- {
- if (shouldBeMarkedAsUsed(refConstant))
- {
- markAsUsed(refConstant);
-
- markConstant(clazz, refConstant.u2classIndex);
- markConstant(clazz, refConstant.u2nameAndTypeIndex);
-
- // When compiled with "-target 1.2" or higher, the class or
- // interface actually containing the referenced class member may
- // be higher up the hierarchy. Make sure it's marked, in case it
- // isn't used elsewhere.
- refConstant.referencedClassAccept(this);
-
- // Mark the referenced class member itself.
- refConstant.referencedMemberAccept(this);
- }
- }
-
-
- public void visitClassConstant(Clazz clazz, ClassConstant classConstant)
- {
- if (shouldBeMarkedAsUsed(classConstant))
- {
- markAsUsed(classConstant);
-
- markConstant(clazz, classConstant.u2nameIndex);
-
- // Mark the referenced class itself.
- classConstant.referencedClassAccept(this);
- }
- }
-
-
- public void visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant)
- {
- if (shouldBeMarkedAsUsed(methodTypeConstant))
- {
- markAsUsed(methodTypeConstant);
-
- markConstant(clazz, methodTypeConstant.u2descriptorIndex);
-
- // Mark the referenced descriptor classes.
- methodTypeConstant.referencedClassesAccept(this);
- }
- }
-
-
- public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant)
- {
- if (shouldBeMarkedAsUsed(nameAndTypeConstant))
- {
- markAsUsed(nameAndTypeConstant);
-
- markConstant(clazz, nameAndTypeConstant.u2nameIndex);
- markConstant(clazz, nameAndTypeConstant.u2descriptorIndex);
- }
- }
-
-
- /**
- * This AttributeVisitor marks the bootstrap methods attributes, their
- * method entries, their method handles, and their arguments.
- */
- private class MyBootStrapMethodUsageMarker
- extends SimplifiedVisitor
- implements AttributeVisitor,
- BootstrapMethodInfoVisitor
- {
- private int bootstrapMethodIndex;
-
-
- private MyBootStrapMethodUsageMarker(int bootstrapMethodIndex)
- {
- this.bootstrapMethodIndex = bootstrapMethodIndex;
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
- {
- if (shouldBeMarkedAsUsed(bootstrapMethodsAttribute))
- {
- markAsUsed(bootstrapMethodsAttribute);
-
- markConstant(clazz, bootstrapMethodsAttribute.u2attributeNameIndex);
- }
-
- bootstrapMethodsAttribute.bootstrapMethodEntryAccept(clazz,
- bootstrapMethodIndex,
- this);
- }
-
-
- // Implementations for BootstrapMethodInfoVisitor.
-
- public void visitBootstrapMethodInfo(Clazz clazz, BootstrapMethodInfo bootstrapMethodInfo)
- {
- markAsUsed(bootstrapMethodInfo);
-
- markConstant(clazz, bootstrapMethodInfo.u2methodHandleIndex);
-
- // Mark the constant pool entries referenced by the arguments.
- bootstrapMethodInfo.methodArgumentsAccept(clazz, UsageMarker.this);
- }
- }
-
-
- // Implementations for AttributeVisitor.
- // Note that attributes are typically only referenced once, so we don't
- // test if they have been marked already.
-
- public void visitUnknownAttribute(Clazz clazz, UnknownAttribute unknownAttribute)
- {
- // This is the best we can do for unknown attributes.
- markAsUsed(unknownAttribute);
-
- markConstant(clazz, unknownAttribute.u2attributeNameIndex);
- }
-
-
- public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
- {
- // Don't mark the attribute and its name here. We may mark it in
- // MyBootStrapMethodsAttributeUsageMarker.
- }
-
-
- public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute)
- {
- markAsUsed(sourceFileAttribute);
-
- markConstant(clazz, sourceFileAttribute.u2attributeNameIndex);
- markConstant(clazz, sourceFileAttribute.u2sourceFileIndex);
- }
-
-
- public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute)
- {
- markAsUsed(sourceDirAttribute);
-
- markConstant(clazz, sourceDirAttribute.u2attributeNameIndex);
- markConstant(clazz, sourceDirAttribute.u2sourceDirIndex);
- }
-
-
- public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute)
- {
- // Don't mark the attribute and its name yet. We may mark it later, in
- // InnerUsageMarker.
- //markAsUsed(innerClassesAttribute);
-
- //markConstant(clazz, innerClassesAttribute.u2attrNameIndex);
-
- // Do mark the outer class entries.
- innerClassesAttribute.innerClassEntriesAccept(clazz, this);
- }
-
-
- public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute)
- {
- markAsUsed(enclosingMethodAttribute);
-
- markConstant(clazz, enclosingMethodAttribute.u2attributeNameIndex);
- markConstant(clazz, enclosingMethodAttribute.u2classIndex);
-
- if (enclosingMethodAttribute.u2nameAndTypeIndex != 0)
- {
- markConstant(clazz, enclosingMethodAttribute.u2nameAndTypeIndex);
- }
- }
-
-
- public void visitDeprecatedAttribute(Clazz clazz, DeprecatedAttribute deprecatedAttribute)
- {
- markAsUsed(deprecatedAttribute);
-
- markConstant(clazz, deprecatedAttribute.u2attributeNameIndex);
- }
-
-
- public void visitSyntheticAttribute(Clazz clazz, SyntheticAttribute syntheticAttribute)
- {
- markAsUsed(syntheticAttribute);
-
- markConstant(clazz, syntheticAttribute.u2attributeNameIndex);
- }
-
-
- public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
- {
- markAsUsed(signatureAttribute);
-
- markConstant(clazz, signatureAttribute.u2attributeNameIndex);
- markConstant(clazz, signatureAttribute.u2signatureIndex);
-
- // Don't mark the referenced classes. We'll clean them up in
- // ClassShrinker, if they appear unused.
- //// Mark the classes referenced in the descriptor string.
- //signatureAttribute.referencedClassesAccept(this);
- }
-
-
- public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute)
- {
- markAsUsed(constantValueAttribute);
-
- markConstant(clazz, constantValueAttribute.u2attributeNameIndex);
- markConstant(clazz, constantValueAttribute.u2constantValueIndex);
- }
-
-
- public void visitMethodParametersAttribute(Clazz clazz, Method method, MethodParametersAttribute methodParametersAttribute)
- {
- markAsUsed(methodParametersAttribute);
-
- markConstant(clazz, methodParametersAttribute.u2attributeNameIndex);
-
- // Mark the constant pool entries referenced by the parameter information.
- methodParametersAttribute.parametersAccept(clazz, method, this);
- }
-
-
- public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute)
- {
- markAsUsed(exceptionsAttribute);
-
- markConstant(clazz, exceptionsAttribute.u2attributeNameIndex);
-
- // Mark the constant pool entries referenced by the exceptions.
- exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz, this);
- }
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- markAsUsed(codeAttribute);
-
- markConstant(clazz, codeAttribute.u2attributeNameIndex);
-
- // Mark the constant pool entries referenced by the instructions,
- // by the exceptions, and by the attributes.
- codeAttribute.instructionsAccept(clazz, method, this);
- codeAttribute.exceptionsAccept(clazz, method, this);
- codeAttribute.attributesAccept(clazz, method, this);
- }
-
-
- public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute)
- {
- markAsUsed(stackMapAttribute);
-
- markConstant(clazz, stackMapAttribute.u2attributeNameIndex);
-
- // Mark the constant pool entries referenced by the stack map frames.
- stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this);
- }
-
-
- public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute)
- {
- markAsUsed(stackMapTableAttribute);
-
- markConstant(clazz, stackMapTableAttribute.u2attributeNameIndex);
-
- // Mark the constant pool entries referenced by the stack map frames.
- stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this);
- }
-
-
- public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
- {
- markAsUsed(lineNumberTableAttribute);
-
- markConstant(clazz, lineNumberTableAttribute.u2attributeNameIndex);
- }
-
-
- public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute)
- {
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in LocalVariableTypeUsageMarker.
- //markAsUsed(localVariableTableAttribute);
- //
- //markConstant(clazz, localVariableTableAttribute.u2attributeNameIndex);
- //
- //// Mark the constant pool entries referenced by the local variables.
- //localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
- }
-
-
- public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute)
- {
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in LocalVariableTypeUsageMarker.
- //markAsUsed(localVariableTypeTableAttribute);
- //
- //markConstant(clazz, localVariableTypeTableAttribute.u2attributeNameIndex);
- //
- //// Mark the constant pool entries referenced by the local variable types.
- //localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this);
- }
-
-
- public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute)
- {
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in AnnotationUsageMarker.
- //markAsUsed(annotationsAttribute);
- //
- //markConstant(clazz, annotationsAttribute.u2attributeNameIndex);
- //
- //// Mark the constant pool entries referenced by the annotations.
- //annotationsAttribute.annotationsAccept(clazz, this);
- }
-
-
- public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
- {
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in AnnotationUsageMarker.
- //markAsUsed(parameterAnnotationsAttribute);
- //
- //markConstant(clazz, parameterAnnotationsAttribute.u2attributeNameIndex);
- //
- //// Mark the constant pool entries referenced by the annotations.
- //parameterAnnotationsAttribute.annotationsAccept(clazz, method, this);
- }
-
-
- public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute)
- {
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in AnnotationUsageMarker.
- //markAsUsed(annotationDefaultAttribute);
- //
- //markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex);
- //
- //// Mark the constant pool entries referenced by the element value.
- //annotationDefaultAttribute.defaultValueAccept(clazz, this);
- }
-
-
- // Implementations for ExceptionInfoVisitor.
-
- public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo)
- {
- markAsUsed(exceptionInfo);
-
- if (exceptionInfo.u2catchType != 0)
- {
- markConstant(clazz, exceptionInfo.u2catchType);
- }
- }
-
-
- // Implementations for InnerClassesInfoVisitor.
-
- public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo)
- {
- // At this point, we only mark outer classes of this class.
- // Inner class can be marked later, by InnerUsageMarker.
- if (innerClassesInfo.u2innerClassIndex != 0 &&
- clazz.getName().equals(clazz.getClassName(innerClassesInfo.u2innerClassIndex)))
- {
- markAsUsed(innerClassesInfo);
-
- innerClassesInfo.innerClassConstantAccept(clazz, this);
- innerClassesInfo.outerClassConstantAccept(clazz, this);
- innerClassesInfo.innerNameConstantAccept(clazz, this);
- }
- }
-
-
- // Implementations for StackMapFrameVisitor.
-
- public void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame) {}
-
-
- public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame)
- {
- // Mark the constant pool entries referenced by the verification types.
- sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this);
- }
-
-
- public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame)
- {
- // Mark the constant pool entries referenced by the verification types.
- moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this);
- }
-
-
- public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame)
- {
- // Mark the constant pool entries referenced by the verification types.
- fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this);
- fullFrame.stackAccept(clazz, method, codeAttribute, offset, this);
- }
-
-
- // Implementations for VerificationTypeVisitor.
-
- public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType) {}
-
-
- public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType)
- {
- markConstant(clazz, objectType.u2classIndex);
- }
-
-
- // Implementations for ParameterInfoVisitor.
-
- public void visitParameterInfo(Clazz clazz, Method method, int parameterIndex, ParameterInfo parameterInfo)
- {
- markConstant(clazz, parameterInfo.u2nameIndex);
- }
-
-
- // Implementations for LocalVariableInfoVisitor.
-
- public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo)
- {
- markConstant(clazz, localVariableInfo.u2nameIndex);
- markConstant(clazz, localVariableInfo.u2descriptorIndex);
- }
-
-
- // Implementations for LocalVariableTypeInfoVisitor.
-
- public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo)
- {
- markConstant(clazz, localVariableTypeInfo.u2nameIndex);
- markConstant(clazz, localVariableTypeInfo.u2signatureIndex);
- }
-
-
-// // Implementations for AnnotationVisitor.
-//
-// public void visitAnnotation(Clazz clazz, Annotation annotation)
-// {
-// markConstant(clazz, annotation.u2typeIndex);
-//
-// // Mark the constant pool entries referenced by the element values.
-// annotation.elementValuesAccept(clazz, this);
-// }
-//
-//
-// // Implementations for ElementValueVisitor.
-//
-// public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue)
-// {
-// if (constantElementValue.u2elementNameIndex != 0)
-// {
-// markConstant(clazz, constantElementValue.u2elementNameIndex);
-// }
-//
-// markConstant(clazz, constantElementValue.u2constantValueIndex);
-// }
-//
-//
-// public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue)
-// {
-// if (enumConstantElementValue.u2elementNameIndex != 0)
-// {
-// markConstant(clazz, enumConstantElementValue.u2elementNameIndex);
-// }
-//
-// markConstant(clazz, enumConstantElementValue.u2typeNameIndex);
-// markConstant(clazz, enumConstantElementValue.u2constantNameIndex);
-// }
-//
-//
-// public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue)
-// {
-// if (classElementValue.u2elementNameIndex != 0)
-// {
-// markConstant(clazz, classElementValue.u2elementNameIndex);
-// }
-//
-// // Mark the referenced class constant pool entry.
-// markConstant(clazz, classElementValue.u2classInfoIndex);
-// }
-//
-//
-// public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue)
-// {
-// if (annotationElementValue.u2elementNameIndex != 0)
-// {
-// markConstant(clazz, annotationElementValue.u2elementNameIndex);
-// }
-//
-// // Mark the constant pool entries referenced by the annotation.
-// annotationElementValue.annotationAccept(clazz, this);
-// }
-//
-//
-// public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue)
-// {
-// if (arrayElementValue.u2elementNameIndex != 0)
-// {
-// markConstant(clazz, arrayElementValue.u2elementNameIndex);
-// }
-//
-// // Mark the constant pool entries referenced by the element values.
-// arrayElementValue.elementValuesAccept(clazz, annotation, this);
-// }
-
-
- // Implementations for InstructionVisitor.
-
- public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) {}
-
-
- public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction)
- {
- markConstant(clazz, constantInstruction.constantIndex);
-
- // Also mark the parameterless constructor of the class, in case the
- // string constant or class constant is being used in a Class.forName
- // or a .class construct.
- clazz.constantPoolEntryAccept(constantInstruction.constantIndex,
- parameterlessConstructorMarker);
- }
-
-
- // Small utility methods.
-
- /**
- * Marks the given visitor accepter as being used.
- */
- protected void markAsUsed(VisitorAccepter visitorAccepter)
- {
- visitorAccepter.setVisitorInfo(USED);
- }
-
-
- /**
- * Returns whether the given visitor accepter should still be marked as
- * being used.
- */
- protected boolean shouldBeMarkedAsUsed(VisitorAccepter visitorAccepter)
- {
- return visitorAccepter.getVisitorInfo() != USED;
- }
-
-
- /**
- * Returns whether the given visitor accepter has been marked as being used.
- */
- protected boolean isUsed(VisitorAccepter visitorAccepter)
- {
- return visitorAccepter.getVisitorInfo() == USED;
- }
-
-
- /**
- * Marks the given visitor accepter as possibly being used.
- */
- protected void markAsPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- visitorAccepter.setVisitorInfo(POSSIBLY_USED);
- }
-
-
- /**
- * Returns whether the given visitor accepter should still be marked as
- * possibly being used.
- */
- protected boolean shouldBeMarkedAsPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- return visitorAccepter.getVisitorInfo() != USED &&
- visitorAccepter.getVisitorInfo() != POSSIBLY_USED;
- }
-
-
- /**
- * Returns whether the given visitor accepter has been marked as possibly
- * being used.
- */
- protected boolean isPossiblyUsed(VisitorAccepter visitorAccepter)
- {
- return visitorAccepter.getVisitorInfo() == POSSIBLY_USED;
- }
-
-
- /**
- * Clears any usage marks from the given visitor accepter.
- */
- protected void markAsUnused(VisitorAccepter visitorAccepter)
- {
- visitorAccepter.setVisitorInfo(null);
- }
-
-
- /**
- * Marks the given constant pool entry of the given class. This includes
- * visiting any referenced objects.
- */
- private void markConstant(Clazz clazz, int index)
- {
- clazz.constantPoolEntryAccept(index, this);
- }
-}
diff --git a/src/proguard/shrink/UsagePrinter.java b/src/proguard/shrink/UsagePrinter.java
deleted file mode 100644
index 2b1a9d8..0000000
--- a/src/proguard/shrink/UsagePrinter.java
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.AttributeVisitor;
-import proguard.classfile.util.*;
-import proguard.classfile.visitor.*;
-
-import java.io.PrintStream;
-
-
-/**
- * This ClassVisitor prints out the classes and class members that have been
- * marked as being used (or not used).
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class UsagePrinter
-extends SimplifiedVisitor
-implements ClassVisitor,
- MemberVisitor,
- AttributeVisitor
-{
- private final UsageMarker usageMarker;
- private final boolean printUnusedItems;
- private final PrintStream ps;
-
- // A field to remember the class name, if a header is needed for class members.
- private String className;
-
-
- /**
- * Creates a new UsagePrinter that prints to <code>System.out</code>.
- * @param usageMarker the usage marker that was used to mark the
- * classes and class members.
- * @param printUnusedItems a flag that indicates whether only unused items
- * should be printed, or alternatively, only used
- * items.
- */
- public UsagePrinter(UsageMarker usageMarker,
- boolean printUnusedItems)
- {
- this(usageMarker, printUnusedItems, System.out);
- }
-
-
- /**
- * Creates a new UsagePrinter that prints to the given stream.
- * @param usageMarker the usage marker that was used to mark the
- * classes and class members.
- * @param printUnusedItems a flag that indicates whether only unused items
- * should be printed, or alternatively, only used
- * items.
- * @param printStream the stream to which to print.
- */
- public UsagePrinter(UsageMarker usageMarker,
- boolean printUnusedItems,
- PrintStream printStream)
- {
- this.usageMarker = usageMarker;
- this.printUnusedItems = printUnusedItems;
- this.ps = printStream;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- if (usageMarker.isUsed(programClass))
- {
- if (printUnusedItems)
- {
- className = programClass.getName();
-
- programClass.fieldsAccept(this);
- programClass.methodsAccept(this);
-
- className = null;
- }
- else
- {
- ps.println(ClassUtil.externalClassName(programClass.getName()));
- }
- }
- else
- {
- if (printUnusedItems)
- {
- ps.println(ClassUtil.externalClassName(programClass.getName()));
- }
- }
- }
-
-
- // Implementations for MemberVisitor.
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- if (usageMarker.isUsed(programField) ^ printUnusedItems)
- {
- printClassNameHeader();
-
- ps.println(" " +
- ClassUtil.externalFullFieldDescription(
- programField.getAccessFlags(),
- programField.getName(programClass),
- programField.getDescriptor(programClass)));
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- if (usageMarker.isUsed(programMethod) ^ printUnusedItems)
- {
- printClassNameHeader();
-
- ps.print(" ");
- programMethod.attributesAccept(programClass, this);
- ps.println(ClassUtil.externalFullMethodDescription(
- programClass.getName(),
- programMethod.getAccessFlags(),
- programMethod.getName(programClass),
- programMethod.getDescriptor(programClass)));
- }
- }
-
-
- // Implementations for AttributeVisitor.
-
- public void visitAnyAttribute(Clazz clazz, Attribute attribute) {}
-
-
- public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute)
- {
- codeAttribute.attributesAccept(clazz, method, this);
- }
-
-
- public void visitLineNumberTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LineNumberTableAttribute lineNumberTableAttribute)
- {
- ps.print(lineNumberTableAttribute.getLowestLineNumber() + ":" +
- lineNumberTableAttribute.getHighestLineNumber() + ":");
- }
-
-
- // Small utility methods.
-
- /**
- * Prints the class name field. The field is then cleared, so it is not
- * printed again.
- */
- private void printClassNameHeader()
- {
- if (className != null)
- {
- ps.println(ClassUtil.externalClassName(className) + ":");
- className = null;
- }
- }
-}
diff --git a/src/proguard/shrink/UsedClassFilter.java b/src/proguard/shrink/UsedClassFilter.java
deleted file mode 100644
index 93548c5..0000000
--- a/src/proguard/shrink/UsedClassFilter.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.ClassVisitor;
-
-/**
- * This ClassVisitor delegates all its method calls to another ClassVisitor,
- * but only for Clazz objects that are marked as used.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class UsedClassFilter
-implements ClassVisitor
-{
- private final UsageMarker usageMarker;
- private final ClassVisitor classVisitor;
-
-
- /**
- * Creates a new UsedClassFilter.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- * @param classVisitor the class visitor to which the visiting will be
- * delegated.
- */
- public UsedClassFilter(UsageMarker usageMarker,
- ClassVisitor classVisitor)
- {
- this.usageMarker = usageMarker;
- this.classVisitor = classVisitor;
- }
-
-
- // Implementations for ClassVisitor.
-
- public void visitProgramClass(ProgramClass programClass)
- {
- if (usageMarker.isUsed(programClass))
- {
- classVisitor.visitProgramClass(programClass);
- }
- }
-
-
- public void visitLibraryClass(LibraryClass libraryClass)
- {
- if (usageMarker.isUsed(libraryClass))
- {
- classVisitor.visitLibraryClass(libraryClass);
- }
- }
-}
diff --git a/src/proguard/shrink/UsedMemberFilter.java b/src/proguard/shrink/UsedMemberFilter.java
deleted file mode 100644
index d5ff5b0..0000000
--- a/src/proguard/shrink/UsedMemberFilter.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * ProGuard -- shrinking, optimization, obfuscation, and preverification
- * of Java bytecode.
- *
- * Copyright (c) 2002-2014 Eric Lafortune (eric@graphics.cornell.edu)
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write to the Free Software Foundation, Inc.,
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
-package proguard.shrink;
-
-import proguard.classfile.*;
-import proguard.classfile.visitor.MemberVisitor;
-
-/**
- * This MemberVisitor delegates all its method calls to another MemberVisitor,
- * but only for Member objects that are marked as used.
- *
- * @see UsageMarker
- *
- * @author Eric Lafortune
- */
-public class UsedMemberFilter
-implements MemberVisitor
-{
- private final UsageMarker usageMarker;
- private final MemberVisitor memberVisitor;
-
-
- /**
- * Creates a new UsedMemberFilter.
- * @param usageMarker the usage marker that is used to mark the classes
- * and class members.
- * @param memberVisitor the member visitor to which the visiting will be
- * delegated.
- */
- public UsedMemberFilter(UsageMarker usageMarker,
- MemberVisitor memberVisitor)
- {
- this.usageMarker = usageMarker;
- this.memberVisitor = memberVisitor;
- }
-
-
- // Implementations for MemberVisitor.
-
-
- public void visitProgramField(ProgramClass programClass, ProgramField programField)
- {
- if (usageMarker.isUsed(programField))
- {
- memberVisitor.visitProgramField(programClass, programField);
- }
- }
-
-
- public void visitProgramMethod(ProgramClass programClass, ProgramMethod programMethod)
- {
- if (usageMarker.isUsed(programMethod))
- {
- memberVisitor.visitProgramMethod(programClass, programMethod);
- }
- }
-
-
- public void visitLibraryField(LibraryClass libraryClass, LibraryField libraryField)
- {
- if (usageMarker.isUsed(libraryField))
- {
- memberVisitor.visitLibraryField(libraryClass, libraryField);
- }
- }
-
-
- public void visitLibraryMethod(LibraryClass libraryClass, LibraryMethod libraryMethod)
- {
- if (usageMarker.isUsed(libraryMethod))
- {
- memberVisitor.visitLibraryMethod(libraryClass, libraryMethod);
- }
- }
-}
diff --git a/src/proguard/shrink/package.html b/src/proguard/shrink/package.html
deleted file mode 100644
index 8973198..0000000
--- a/src/proguard/shrink/package.html
+++ /dev/null
@@ -1,3 +0,0 @@
-<body>
-This package contains classes to perform shrinking of class files.
-</body>