summaryrefslogtreecommitdiff
path: root/src/proguard/shrink
diff options
context:
space:
mode:
Diffstat (limited to 'src/proguard/shrink')
-rw-r--r--src/proguard/shrink/AnnotationUsageMarker.java2
-rw-r--r--src/proguard/shrink/ClassShrinker.java193
-rw-r--r--src/proguard/shrink/InnerUsageMarker.java2
-rw-r--r--src/proguard/shrink/InterfaceUsageMarker.java2
-rw-r--r--src/proguard/shrink/LocalVariableTypeUsageMarker.java5
-rw-r--r--src/proguard/shrink/ShortestUsageMark.java2
-rw-r--r--src/proguard/shrink/ShortestUsageMarker.java2
-rw-r--r--src/proguard/shrink/ShortestUsagePrinter.java2
-rw-r--r--src/proguard/shrink/Shrinker.java14
-rw-r--r--src/proguard/shrink/SignatureUsageMarker.java19
-rw-r--r--src/proguard/shrink/UsageMarker.java83
-rw-r--r--src/proguard/shrink/UsagePrinter.java3
-rw-r--r--src/proguard/shrink/UsedClassFilter.java2
-rw-r--r--src/proguard/shrink/UsedMemberFilter.java2
14 files changed, 224 insertions, 109 deletions
diff --git a/src/proguard/shrink/AnnotationUsageMarker.java b/src/proguard/shrink/AnnotationUsageMarker.java
index b9051a0..2cc0266 100644
--- a/src/proguard/shrink/AnnotationUsageMarker.java
+++ b/src/proguard/shrink/AnnotationUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/ClassShrinker.java b/src/proguard/shrink/ClassShrinker.java
index f590c63..3c3a55e 100644
--- a/src/proguard/shrink/ClassShrinker.java
+++ b/src/proguard/shrink/ClassShrinker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -50,8 +50,10 @@ implements ClassVisitor,
{
private final UsageMarker usageMarker;
- private int[] constantIndexMap = new int[ClassConstants.TYPICAL_CONSTANT_POOL_SIZE];
- private final ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper();
+ 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();
/**
@@ -71,10 +73,13 @@ implements ClassVisitor,
{
// Shrink the arrays for constant pool, interfaces, fields, methods,
// and class attributes.
- programClass.u2interfacesCount =
- shrinkConstantIndexArray(programClass.constantPool,
- programClass.u2interfaces,
- programClass.u2interfacesCount);
+ 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 =
@@ -109,8 +114,11 @@ implements ClassVisitor,
constantPoolRemapper.visitProgramClass(programClass);
}
- // Remove the unused interfaces from the class signature.
- programClass.attributesAccept(new SignatureShrinker());
+ // 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 =
@@ -150,9 +158,18 @@ implements ClassVisitor,
public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute)
{
// Shrink the array of BootstrapMethodInfo objects.
- bootstrapMethodsAttribute.u2bootstrapMethodsCount =
- shrinkArray(bootstrapMethodsAttribute.bootstrapMethods,
- bootstrapMethodsAttribute.u2bootstrapMethodsCount);
+ 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);
+ }
}
@@ -228,7 +245,7 @@ implements ClassVisitor,
public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute)
{
// Loop over all parameters.
- for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u2parametersCount; parameterIndex++)
+ for (int parameterIndex = 0; parameterIndex < parameterAnnotationsAttribute.u1parametersCount; parameterIndex++)
{
// Shrink the parameter annotations array.
parameterAnnotationsAttribute.u2parameterAnnotationsCount[parameterIndex] =
@@ -256,10 +273,10 @@ implements ClassVisitor,
/**
- * This AttributeVisitor updates the Utf8 constants of class signatures,
- * removing any unused interfaces.
+ * This AttributeVisitor updates the Utf8 constants of signatures
+ * of classes, fields, and methods.
*/
- private class SignatureShrinker
+ private class MySignatureCleaner
extends SimplifiedVisitor
implements AttributeVisitor
{
@@ -271,55 +288,41 @@ implements ClassVisitor,
Clazz[] referencedClasses = signatureAttribute.referencedClasses;
if (referencedClasses != null)
{
- // Go over the generic definitions, superclass and implemented interfaces.
- String signature = clazz.getString(signatureAttribute.u2signatureIndex);
+ // Go over the classes in the signature.
+ String signature = signatureAttribute.getSignature(clazz);
+
+ DescriptorClassEnumeration classEnumeration =
+ new DescriptorClassEnumeration(signature);
- InternalTypeEnumeration internalTypeEnumeration =
- new InternalTypeEnumeration(signature);
+ int referencedClassIndex = 0;
+ // Start construction a new signature.
StringBuffer newSignatureBuffer = new StringBuffer();
- int referencedClassIndex = 0;
- int newReferencedClassIndex = 0;
+ newSignatureBuffer.append(classEnumeration.nextFluff());
- while (internalTypeEnumeration.hasMoreTypes())
+ while (classEnumeration.hasMoreClassNames())
{
- // Consider the classes referenced by this signature.
- String type = internalTypeEnumeration.nextType();
- int classCount = new DescriptorClassEnumeration(type).classCount();
+ String className = classEnumeration.nextClassName();
+ // Replace the class name if it is unused.
Clazz referencedClass = referencedClasses[referencedClassIndex];
- if (referencedClass == null ||
- usageMarker.isUsed(referencedClass))
+ if (referencedClass != null &&
+ !usageMarker.isUsed(referencedClass))
{
- // Append the superclass or interface.
- newSignatureBuffer.append(type);
-
- // Copy the referenced classes.
- for (int counter = 0; counter < classCount; counter++)
- {
- referencedClasses[newReferencedClassIndex++] =
- referencedClasses[referencedClassIndex++];
- }
- }
- else
- {
- // Skip the referenced classes.
- referencedClassIndex += classCount;
+ className = ClassConstants.NAME_JAVA_LANG_OBJECT;
+
+ referencedClasses[referencedClassIndex] = null;
}
- }
- if (newReferencedClassIndex < referencedClassIndex)
- {
- // Update the signature.
- ((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());
+ referencedClassIndex++;
- // Clear the unused entries.
- while (newReferencedClassIndex < referencedClassIndex)
- {
- referencedClasses[newReferencedClassIndex++] = null;
- }
+ newSignatureBuffer.append(className);
+ newSignatureBuffer.append(classEnumeration.nextFluff());
}
+
+ // Update the signature.
+ ((Utf8Constant)((ProgramClass)clazz).constantPool[signatureAttribute.u2signatureIndex]).setString(newSignatureBuffer.toString());
}
}
}
@@ -353,7 +356,8 @@ implements ClassVisitor,
/**
* Removes all entries that are not marked as being used from the given
- * constant pool.
+ * 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)
@@ -373,7 +377,8 @@ implements ClassVisitor,
Constant constant = constantPool[index];
- // Don't update the flag if this is the second half of a long entry.
+ // 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);
@@ -381,8 +386,17 @@ implements ClassVisitor,
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.
@@ -393,6 +407,28 @@ implements ClassVisitor,
/**
+ * 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.
@@ -451,6 +487,49 @@ implements ClassVisitor,
/**
+ * 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.
@@ -462,9 +541,11 @@ implements ClassVisitor,
// Shift the used objects together.
for (int index = 0; index < length; index++)
{
- if (usageMarker.isUsed(array[index]))
+ VisitorAccepter visitorAccepter = array[index];
+
+ if (usageMarker.isUsed(visitorAccepter))
{
- array[counter++] = array[index];
+ array[counter++] = visitorAccepter;
}
}
diff --git a/src/proguard/shrink/InnerUsageMarker.java b/src/proguard/shrink/InnerUsageMarker.java
index 6d77e81..a65b519 100644
--- a/src/proguard/shrink/InnerUsageMarker.java
+++ b/src/proguard/shrink/InnerUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/InterfaceUsageMarker.java b/src/proguard/shrink/InterfaceUsageMarker.java
index 240838e..ecdf678 100644
--- a/src/proguard/shrink/InterfaceUsageMarker.java
+++ b/src/proguard/shrink/InterfaceUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/LocalVariableTypeUsageMarker.java b/src/proguard/shrink/LocalVariableTypeUsageMarker.java
index 573d8f6..3d6ef27 100644
--- a/src/proguard/shrink/LocalVariableTypeUsageMarker.java
+++ b/src/proguard/shrink/LocalVariableTypeUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -18,7 +18,6 @@
* 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.*;
@@ -48,7 +47,7 @@ implements AttributeVisitor,
{
private final UsageMarker usageMarker;
- // Fields acting as a return parameters for several methods.
+ // Fields acting as return values for several visitor methods.
private boolean tableUsed;
private boolean variableInfoUsed;
diff --git a/src/proguard/shrink/ShortestUsageMark.java b/src/proguard/shrink/ShortestUsageMark.java
index e2df7fa..80d1c8f 100644
--- a/src/proguard/shrink/ShortestUsageMark.java
+++ b/src/proguard/shrink/ShortestUsageMark.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/ShortestUsageMarker.java b/src/proguard/shrink/ShortestUsageMarker.java
index 1ac6e7e..6718e68 100644
--- a/src/proguard/shrink/ShortestUsageMarker.java
+++ b/src/proguard/shrink/ShortestUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/ShortestUsagePrinter.java b/src/proguard/shrink/ShortestUsagePrinter.java
index 8740b9f..c6075ea 100644
--- a/src/proguard/shrink/ShortestUsagePrinter.java
+++ b/src/proguard/shrink/ShortestUsagePrinter.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/Shrinker.java b/src/proguard/shrink/Shrinker.java
index 0472c3d..72f878b 100644
--- a/src/proguard/shrink/Shrinker.java
+++ b/src/proguard/shrink/Shrinker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -73,8 +73,8 @@ public class Shrinker
new MultiClassVisitor(new ClassVisitor[]
{
usageMarker,
- new NamedMethodVisitor(ClassConstants.INTERNAL_METHOD_NAME_INIT,
- ClassConstants.INTERNAL_METHOD_TYPE_INIT,
+ new NamedMethodVisitor(ClassConstants.METHOD_NAME_INIT,
+ ClassConstants.METHOD_TYPE_INIT,
usageMarker)
});
@@ -88,6 +88,7 @@ public class Shrinker
// Mark the seeds.
programClassPool.accept(classPoolvisitor);
libraryClassPool.accept(classPoolvisitor);
+ libraryClassPool.classesAccept(usageMarker);
// Mark interfaces that have to be kept.
programClassPool.classesAccept(new InterfaceUsageMarker(usageMarker));
@@ -100,7 +101,6 @@ public class Shrinker
{
new InnerUsageMarker(usageMarker),
new AnnotationUsageMarker(usageMarker),
- new SignatureUsageMarker(usageMarker),
new LocalVariableTypeUsageMarker(usageMarker)
}))));
@@ -146,7 +146,7 @@ public class Shrinker
}
}
- // Discard unused program classes.
+ // Clean up used program classes and discard unused program classes.
int originalProgramClassPoolSize = programClassPool.size();
ClassPool newProgramClassPool = new ClassPool();
@@ -160,6 +160,10 @@ public class Shrinker
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)
diff --git a/src/proguard/shrink/SignatureUsageMarker.java b/src/proguard/shrink/SignatureUsageMarker.java
index 9c5cd4d..91bfcdd 100644
--- a/src/proguard/shrink/SignatureUsageMarker.java
+++ b/src/proguard/shrink/SignatureUsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -23,8 +23,8 @@ package proguard.shrink;
import proguard.classfile.*;
import proguard.classfile.attribute.*;
-import proguard.classfile.attribute.visitor.*;
-import proguard.classfile.constant.*;
+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;
@@ -67,8 +67,8 @@ implements AttributeVisitor,
public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
{
- // Only keep the signature if all of its classes are used.
- attributeUsed = true;
+ // Only keep the signature if any of its classes are used.
+ attributeUsed = false;
signatureAttribute.referencedClassesAccept(this);
if (attributeUsed)
@@ -84,15 +84,18 @@ implements AttributeVisitor,
// Implementations for ClassVisitor.
- public void visitLibraryClass(LibraryClass libraryClass) {}
+ 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))
+ if (usageMarker.isUsed(programClass))
{
- attributeUsed = false;
+ attributeUsed = true;
}
}
diff --git a/src/proguard/shrink/UsageMarker.java b/src/proguard/shrink/UsageMarker.java
index 51210b5..88a88fd 100644
--- a/src/proguard/shrink/UsageMarker.java
+++ b/src/proguard/shrink/UsageMarker.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -52,6 +52,7 @@ implements ClassVisitor,
ExceptionInfoVisitor,
StackMapFrameVisitor,
VerificationTypeVisitor,
+ ParameterInfoVisitor,
LocalVariableInfoVisitor,
LocalVariableTypeInfoVisitor,
// AnnotationVisitor,
@@ -71,8 +72,8 @@ implements ClassVisitor,
new MyNonEmptyMethodUsageMarker());
private final ConstantVisitor parameterlessConstructorMarker = new ConstantTagFilter(new int[] { ClassConstants.CONSTANT_String, ClassConstants.CONSTANT_Class },
new ReferencedClassVisitor(
- new NamedMethodVisitor(ClassConstants.INTERNAL_METHOD_NAME_INIT,
- ClassConstants.INTERNAL_METHOD_TYPE_INIT,
+ new NamedMethodVisitor(ClassConstants.METHOD_NAME_INIT,
+ ClassConstants.METHOD_TYPE_INIT,
this)));
// Implementations for ClassVisitor.
@@ -105,8 +106,8 @@ implements ClassVisitor,
interfaceUsageMarker);
// Explicitly mark the <clinit> method, if it's not empty.
- programClass.methodAccept(ClassConstants.INTERNAL_METHOD_NAME_CLINIT,
- ClassConstants.INTERNAL_METHOD_TYPE_CLINIT,
+ programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT,
+ ClassConstants.METHOD_TYPE_CLINIT,
nonEmptyMethodUsageMarker);
// Process all class members that have already been marked as possibly used.
@@ -355,18 +356,18 @@ implements ClassVisitor,
{
int accessFlags = method.getAccessFlags();
if ((accessFlags &
- (ClassConstants.INTERNAL_ACC_PRIVATE |
- ClassConstants.INTERNAL_ACC_STATIC)) == 0 &&
+ (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.INTERNAL_ACC_PRIVATE |
- ClassConstants.INTERNAL_ACC_STATIC |
- ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) == 0 ? 0 :
- ClassConstants.INTERNAL_ACC_ABSTRACT);
+ 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,
@@ -448,6 +449,9 @@ implements ClassVisitor,
markConstant(clazz, invokeDynamicConstant.u2nameAndTypeIndex);
+ // Mark the referenced descriptor classes.
+ invokeDynamicConstant.referencedClassesAccept(this);
+
// Mark the bootstrap methods attribute.
clazz.attributesAccept(new MyBootStrapMethodUsageMarker(invokeDynamicConstant.u2bootstrapMethodAttributeIndex));
}
@@ -507,6 +511,9 @@ implements ClassVisitor,
markAsUsed(methodTypeConstant);
markConstant(clazz, methodTypeConstant.u2descriptorIndex);
+
+ // Mark the referenced descriptor classes.
+ methodTypeConstant.referencedClassesAccept(this);
}
}
@@ -553,11 +560,11 @@ implements ClassVisitor,
markAsUsed(bootstrapMethodsAttribute);
markConstant(clazz, bootstrapMethodsAttribute.u2attributeNameIndex);
-
- bootstrapMethodsAttribute.bootstrapMethodEntryAccept(clazz,
- bootstrapMethodIndex,
- this);
}
+
+ bootstrapMethodsAttribute.bootstrapMethodEntryAccept(clazz,
+ bootstrapMethodIndex,
+ this);
}
@@ -658,12 +665,15 @@ implements ClassVisitor,
public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute)
{
- // Don't mark the attribute and its contents yet. We may mark them later,
- // in SignatureUsageMarker.
- //markAsUsed(signatureAttribute);
- //
- //markConstant(clazz, signatureAttribute.u2attributeNameIndex);
- //markConstant(clazz, signatureAttribute.u2signatureIndex);
+ 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);
}
@@ -676,6 +686,17 @@ implements ClassVisitor,
}
+ 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);
@@ -787,12 +808,12 @@ implements ClassVisitor,
{
// 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);
+ //markAsUsed(annotationDefaultAttribute);
+ //
+ //markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex);
+ //
+ //// Mark the constant pool entries referenced by the element value.
+ //annotationDefaultAttribute.defaultValueAccept(clazz, this);
}
@@ -865,6 +886,14 @@ implements ClassVisitor,
}
+ // 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)
diff --git a/src/proguard/shrink/UsagePrinter.java b/src/proguard/shrink/UsagePrinter.java
index 69df7fa..2b1a9d8 100644
--- a/src/proguard/shrink/UsagePrinter.java
+++ b/src/proguard/shrink/UsagePrinter.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
@@ -138,7 +138,6 @@ implements ClassVisitor,
{
printClassNameHeader();
- ps.print("====");
ps.print(" ");
programMethod.attributesAccept(programClass, this);
ps.println(ClassUtil.externalFullMethodDescription(
diff --git a/src/proguard/shrink/UsedClassFilter.java b/src/proguard/shrink/UsedClassFilter.java
index 7630b0b..93548c5 100644
--- a/src/proguard/shrink/UsedClassFilter.java
+++ b/src/proguard/shrink/UsedClassFilter.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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
diff --git a/src/proguard/shrink/UsedMemberFilter.java b/src/proguard/shrink/UsedMemberFilter.java
index f1a9c75..d5ff5b0 100644
--- a/src/proguard/shrink/UsedMemberFilter.java
+++ b/src/proguard/shrink/UsedMemberFilter.java
@@ -2,7 +2,7 @@
* ProGuard -- shrinking, optimization, obfuscation, and preverification
* of Java bytecode.
*
- * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu)
+ * 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