diff options
Diffstat (limited to 'src/proguard/optimize/info')
34 files changed, 516 insertions, 149 deletions
diff --git a/src/proguard/optimize/info/AccessMethodMarker.java b/src/proguard/optimize/info/AccessMethodMarker.java index e4c8d7c..4c3c17b 100644 --- a/src/proguard/optimize/info/AccessMethodMarker.java +++ b/src/proguard/optimize/info/AccessMethodMarker.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 @@ -21,8 +21,7 @@ package proguard.optimize.info; import proguard.classfile.*; -import proguard.classfile.attribute.*; -import proguard.classfile.attribute.visitor.*; +import proguard.classfile.attribute.CodeAttribute; import proguard.classfile.constant.*; import proguard.classfile.constant.visitor.ConstantVisitor; import proguard.classfile.instruction.*; @@ -110,7 +109,7 @@ implements InstructionVisitor, { int accessFlags = clazz.getAccessFlags(); - if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) == 0) + if ((accessFlags & ClassConstants.ACC_PUBLIC) == 0) { setAccessesPackageCode(invokingMethod); } @@ -123,15 +122,15 @@ implements InstructionVisitor, { int accessFlags = member.getAccessFlags(); - if ((accessFlags & ClassConstants.INTERNAL_ACC_PRIVATE) != 0) + if ((accessFlags & ClassConstants.ACC_PRIVATE) != 0) { setAccessesPrivateCode(invokingMethod); } - else if ((accessFlags & ClassConstants.INTERNAL_ACC_PROTECTED) != 0) + else if ((accessFlags & ClassConstants.ACC_PROTECTED) != 0) { setAccessesProtectedCode(invokingMethod); } - else if ((accessFlags & ClassConstants.INTERNAL_ACC_PUBLIC) == 0) + else if ((accessFlags & ClassConstants.ACC_PUBLIC) == 0) { setAccessesPackageCode(invokingMethod); } diff --git a/src/proguard/optimize/info/BackwardBranchMarker.java b/src/proguard/optimize/info/BackwardBranchMarker.java index 07bfefb..089b66e 100644 --- a/src/proguard/optimize/info/BackwardBranchMarker.java +++ b/src/proguard/optimize/info/BackwardBranchMarker.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/optimize/info/CatchExceptionMarker.java b/src/proguard/optimize/info/CatchExceptionMarker.java index 8f87a08..2894d2a 100644 --- a/src/proguard/optimize/info/CatchExceptionMarker.java +++ b/src/proguard/optimize/info/CatchExceptionMarker.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/optimize/info/CaughtClassFilter.java b/src/proguard/optimize/info/CaughtClassFilter.java index 762e7de..0c32151 100644 --- a/src/proguard/optimize/info/CaughtClassFilter.java +++ b/src/proguard/optimize/info/CaughtClassFilter.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/optimize/info/CaughtClassMarker.java b/src/proguard/optimize/info/CaughtClassMarker.java index 1752f0c..31ee1a8 100644 --- a/src/proguard/optimize/info/CaughtClassMarker.java +++ b/src/proguard/optimize/info/CaughtClassMarker.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 @@ -21,7 +21,6 @@ package proguard.optimize.info; import proguard.classfile.*; -import proguard.classfile.util.SimplifiedVisitor; import proguard.classfile.visitor.ClassVisitor; /** diff --git a/src/proguard/optimize/info/ClassOptimizationInfo.java b/src/proguard/optimize/info/ClassOptimizationInfo.java index dbe041e..5ac56f9 100644 --- a/src/proguard/optimize/info/ClassOptimizationInfo.java +++ b/src/proguard/optimize/info/ClassOptimizationInfo.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 @@ -34,6 +34,7 @@ public class ClassOptimizationInfo private boolean isInstanceofed = false; private boolean isDotClassed = false; private boolean isCaught = false; + private boolean isSimpleEnum = false; private boolean containsStaticInitializer = false; private boolean containsPackageVisibleMembers = false; private boolean invokesPackageVisibleMembers = false; @@ -88,6 +89,18 @@ public class ClassOptimizationInfo } + public void setSimpleEnum(boolean simple) + { + isSimpleEnum = simple; + } + + + public boolean isSimpleEnum() + { + return isSimpleEnum; + } + + public void setContainsStaticInitializer() { containsStaticInitializer = true; @@ -157,7 +170,6 @@ public class ClassOptimizationInfo public static ClassOptimizationInfo getClassOptimizationInfo(Clazz clazz) { Object visitorInfo = clazz.getVisitorInfo(); - return visitorInfo instanceof ClassOptimizationInfo ? (ClassOptimizationInfo)visitorInfo : null; diff --git a/src/proguard/optimize/info/ClassOptimizationInfoSetter.java b/src/proguard/optimize/info/ClassOptimizationInfoSetter.java index f3d78e2..b9211e7 100644 --- a/src/proguard/optimize/info/ClassOptimizationInfoSetter.java +++ b/src/proguard/optimize/info/ClassOptimizationInfoSetter.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 @@ -20,7 +20,7 @@ */ package proguard.optimize.info; -import proguard.classfile.*; +import proguard.classfile.ProgramClass; import proguard.classfile.util.SimplifiedVisitor; import proguard.classfile.visitor.ClassVisitor; import proguard.optimize.KeepMarker; diff --git a/src/proguard/optimize/info/DotClassFilter.java b/src/proguard/optimize/info/DotClassFilter.java index c3fd878..8ab4f98 100644 --- a/src/proguard/optimize/info/DotClassFilter.java +++ b/src/proguard/optimize/info/DotClassFilter.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/optimize/info/DotClassMarker.java b/src/proguard/optimize/info/DotClassMarker.java index ef5cfd1..d9519ac 100644 --- a/src/proguard/optimize/info/DotClassMarker.java +++ b/src/proguard/optimize/info/DotClassMarker.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/optimize/info/DynamicInvocationMarker.java b/src/proguard/optimize/info/DynamicInvocationMarker.java new file mode 100644 index 0000000..daee6b4 --- /dev/null +++ b/src/proguard/optimize/info/DynamicInvocationMarker.java @@ -0,0 +1,79 @@ +/* + * 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.optimize.info; + +import proguard.classfile.*; +import proguard.classfile.attribute.CodeAttribute; +import proguard.classfile.constant.*; +import proguard.classfile.constant.visitor.ConstantVisitor; +import proguard.classfile.instruction.*; +import proguard.classfile.instruction.visitor.InstructionVisitor; +import proguard.classfile.util.SimplifiedVisitor; +import proguard.classfile.visitor.*; + +/** + * This InstructionVisitor marks whether the methods whose instructions it + * visits contain the invokedynamic instruction. + * + * @author Eric Lafortune + */ +public class DynamicInvocationMarker +extends SimplifiedVisitor +implements InstructionVisitor, + ConstantVisitor, + ClassVisitor, + MemberVisitor +{ + // 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) + { + if (constantInstruction.opcode == InstructionConstants.OP_INVOKEDYNAMIC) + { + setInvokesDynamically(method); + } + } + + + // Small utility methods. + + private static void setInvokesDynamically(Method method) + { + MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method); + if (info != null) + { + info.setInvokesDynamically(); + } + } + + + /** + * Returns whether the given method calls the invokedynamic instruction. + */ + public static boolean invokesDynamically(Method method) + { + MethodOptimizationInfo info = MethodOptimizationInfo.getMethodOptimizationInfo(method); + return info == null || info.invokesDynamically(); + } +} diff --git a/src/proguard/optimize/info/ExceptionInstructionChecker.java b/src/proguard/optimize/info/ExceptionInstructionChecker.java index 4bfa96f..a32a1d3 100644 --- a/src/proguard/optimize/info/ExceptionInstructionChecker.java +++ b/src/proguard/optimize/info/ExceptionInstructionChecker.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 @@ -22,12 +22,9 @@ package proguard.optimize.info; import proguard.classfile.*; import proguard.classfile.attribute.CodeAttribute; -import proguard.classfile.constant.RefConstant; -import proguard.classfile.constant.visitor.ConstantVisitor; import proguard.classfile.instruction.*; import proguard.classfile.instruction.visitor.InstructionVisitor; import proguard.classfile.util.SimplifiedVisitor; -import proguard.classfile.visitor.MemberVisitor; /** * This class can tell whether an instruction might throw exceptions. @@ -45,15 +42,90 @@ implements InstructionVisitor /** - * Returns whether the given instruction may throw exceptions. + * Returns whether the specified method may throw exceptions. */ - public boolean mayThrowExceptions(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) + public boolean mayThrowExceptions(Clazz clazz, + Method method, + CodeAttribute codeAttribute) { - mayThrowExceptions = false; + return mayThrowExceptions(clazz, + method, + codeAttribute, + 0, + codeAttribute.u4codeLength); + } + + + /** + * Returns whether the specified block of code may throw exceptions. + */ + public boolean mayThrowExceptions(Clazz clazz, + Method method, + CodeAttribute codeAttribute, + int startOffset, + int endOffset) + { + byte[] code = codeAttribute.code; + + // Go over all instructions. + int offset = startOffset; + while (offset < endOffset) + { + // Get the current instruction. + Instruction instruction = InstructionFactory.create(code, offset); - instruction.accept(clazz, method, codeAttribute, offset, this); + // Check if it may be throwing exceptions. + if (mayThrowExceptions(clazz, + method, + codeAttribute, + offset, + instruction)) + { + return true; + } - return mayThrowExceptions; + // Go to the next instruction. + offset += instruction.length(offset); + } + + return false; + } + + + /** + * Returns whether the specified instruction may throw exceptions. + */ + public boolean mayThrowExceptions(Clazz clazz, + Method method, + CodeAttribute codeAttribute, + int offset) + { + Instruction instruction = InstructionFactory.create(codeAttribute.code, offset); + + return mayThrowExceptions(clazz, + method, + codeAttribute, + offset, + instruction); + } + + + /** + * Returns whether the given instruction may throw exceptions. + */ + public boolean mayThrowExceptions(Clazz clazz, + Method method, + CodeAttribute codeAttribute, + int offset, + Instruction instruction) + { + return instruction.mayThrowExceptions(); + +// mayThrowExceptions = false; +// +// instruction.accept(clazz, method, codeAttribute, offset, this); +// +// return mayThrowExceptions; } @@ -64,15 +136,13 @@ implements InstructionVisitor public void visitSimpleInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SimpleInstruction simpleInstruction) { - byte opcode = simpleInstruction.opcode; - // Check for instructions that may throw exceptions. // Note that monitorexit can not sensibly throw exceptions, except the // broken and deprecated asynchronous ThreadDeath. Removing the // artificial infinite looping exception blocks that recent compilers // add does not strictly follow the JVM specs, but it does have the // additional benefit of avoiding a bug in the JVM in JDK 1.1. - switch (opcode) + switch (simpleInstruction.opcode) { case InstructionConstants.OP_IDIV: case InstructionConstants.OP_LDIV: @@ -101,16 +171,13 @@ implements InstructionVisitor // These instructions may throw exceptions. mayThrowExceptions = true; } - } public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) { - byte opcode = constantInstruction.opcode; - // Check for instructions that may throw exceptions. - switch (opcode) + switch (constantInstruction.opcode) { case InstructionConstants.OP_GETSTATIC: case InstructionConstants.OP_PUTSTATIC: @@ -128,7 +195,6 @@ implements InstructionVisitor case InstructionConstants.OP_MULTIANEWARRAY: // These instructions may throw exceptions. mayThrowExceptions = true; - } // case InstructionConstants.OP_INVOKEVIRTUAL: // case InstructionConstants.OP_INVOKESPECIAL: @@ -136,6 +202,7 @@ implements InstructionVisitor // case InstructionConstants.OP_INVOKEINTERFACE: // // Check if the invoking the method may throw an exception. // clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); + } } diff --git a/src/proguard/optimize/info/FieldOptimizationInfo.java b/src/proguard/optimize/info/FieldOptimizationInfo.java index 0fa9167..730eead 100644 --- a/src/proguard/optimize/info/FieldOptimizationInfo.java +++ b/src/proguard/optimize/info/FieldOptimizationInfo.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 @@ -21,11 +21,11 @@ package proguard.optimize.info; import proguard.classfile.*; -import proguard.classfile.attribute.visitor.*; import proguard.classfile.attribute.*; -import proguard.classfile.util.*; -import proguard.evaluation.value.*; +import proguard.classfile.attribute.visitor.*; +import proguard.classfile.util.SimplifiedVisitor; import proguard.evaluation.ConstantValueFactory; +import proguard.evaluation.value.*; /** * This class stores some optimization information that can be attached to @@ -37,8 +37,9 @@ public class FieldOptimizationInfo extends SimplifiedVisitor implements AttributeVisitor { - private static final SpecificValueFactory VALUE_FACTORY = new SpecificValueFactory(); - private static final ConstantValueFactory CONSTANT_VALUE_FACTORY = new ConstantValueFactory(VALUE_FACTORY); + private static final ParticularValueFactory VALUE_FACTORY = new ParticularValueFactory(); + private static final ConstantValueFactory CONSTANT_VALUE_FACTORY = new ConstantValueFactory(VALUE_FACTORY); + private static final InitialValueFactory INITIAL_VALUE_FACTORY = new InitialValueFactory(VALUE_FACTORY); private boolean isWritten; private boolean isRead; @@ -52,20 +53,9 @@ implements AttributeVisitor int accessFlags = field.getAccessFlags(); isWritten = - isRead = (accessFlags & ClassConstants.INTERNAL_ACC_VOLATILE) != 0; + isRead = (accessFlags & ClassConstants.ACC_VOLATILE) != 0; - if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0) - { - // See if we can initialize the static field with a constant value. - field.accept(clazz, new AllAttributeVisitor(this)); - } - - if ((accessFlags & ClassConstants.INTERNAL_ACC_FINAL) == 0 && - value == null) - { - // Otherwise initialize the non-final field with the default value. - value = initialValue(field.getDescriptor(clazz)); - } + resetValue(clazz, field); } @@ -129,6 +119,30 @@ implements AttributeVisitor } + public void resetValue(Clazz clazz, Field field) + { + int accessFlags = field.getAccessFlags(); + + value = null; + + // See if we can initialize a static field with a constant value. + if ((accessFlags & ClassConstants.ACC_STATIC) != 0) + { + field.accept(clazz, new AllAttributeVisitor(this)); + } + + // Otherwise initialize a non-final field with the default value. + // Conservatively, even a final field needs to be initialized with the + // default value, because it may be accessed before it is set. + if (value == null && + (SideEffectInstructionChecker.OPTIMIZE_CONSERVATIVELY || + (accessFlags & ClassConstants.ACC_FINAL) == 0)) + { + value = INITIAL_VALUE_FACTORY.createValue(field.getDescriptor(clazz)); + } + } + + public void generalizeValue(Value value) { this.value = this.value != null ? @@ -157,36 +171,6 @@ implements AttributeVisitor // Small utility methods. - private Value initialValue(String type) - { - switch (type.charAt(0)) - { - case ClassConstants.INTERNAL_TYPE_BOOLEAN: - case ClassConstants.INTERNAL_TYPE_BYTE: - case ClassConstants.INTERNAL_TYPE_CHAR: - case ClassConstants.INTERNAL_TYPE_SHORT: - case ClassConstants.INTERNAL_TYPE_INT: - return VALUE_FACTORY.createIntegerValue(0); - - case ClassConstants.INTERNAL_TYPE_LONG: - return VALUE_FACTORY.createLongValue(0L); - - case ClassConstants.INTERNAL_TYPE_FLOAT: - return VALUE_FACTORY.createFloatValue(0.0f); - - case ClassConstants.INTERNAL_TYPE_DOUBLE: - return VALUE_FACTORY.createDoubleValue(0.0); - - case ClassConstants.INTERNAL_TYPE_CLASS_START: - case ClassConstants.INTERNAL_TYPE_ARRAY: - return VALUE_FACTORY.createReferenceValueNull(); - - default: - throw new IllegalArgumentException("Invalid type ["+type+"]"); - } - } - - public static void setFieldOptimizationInfo(Clazz clazz, Field field) { field.setVisitorInfo(new FieldOptimizationInfo(clazz, field)); diff --git a/src/proguard/optimize/info/InstanceofClassFilter.java b/src/proguard/optimize/info/InstanceofClassFilter.java index 7cd85bc..ab345fb 100644 --- a/src/proguard/optimize/info/InstanceofClassFilter.java +++ b/src/proguard/optimize/info/InstanceofClassFilter.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/optimize/info/InstanceofClassMarker.java b/src/proguard/optimize/info/InstanceofClassMarker.java index 96d5baf..3556dd8 100644 --- a/src/proguard/optimize/info/InstanceofClassMarker.java +++ b/src/proguard/optimize/info/InstanceofClassMarker.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/optimize/info/InstantiationClassFilter.java b/src/proguard/optimize/info/InstantiationClassFilter.java index a659f06..7822205 100644 --- a/src/proguard/optimize/info/InstantiationClassFilter.java +++ b/src/proguard/optimize/info/InstantiationClassFilter.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/optimize/info/InstantiationClassMarker.java b/src/proguard/optimize/info/InstantiationClassMarker.java index b4afffd..3f90991 100644 --- a/src/proguard/optimize/info/InstantiationClassMarker.java +++ b/src/proguard/optimize/info/InstantiationClassMarker.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/optimize/info/MemberOptimizationInfoSetter.java b/src/proguard/optimize/info/MemberOptimizationInfoSetter.java index 3c27c93..ad64cf9 100644 --- a/src/proguard/optimize/info/MemberOptimizationInfoSetter.java +++ b/src/proguard/optimize/info/MemberOptimizationInfoSetter.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/optimize/info/MethodInvocationMarker.java b/src/proguard/optimize/info/MethodInvocationMarker.java index afb2336..c9a9131 100644 --- a/src/proguard/optimize/info/MethodInvocationMarker.java +++ b/src/proguard/optimize/info/MethodInvocationMarker.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/optimize/info/MethodOptimizationInfo.java b/src/proguard/optimize/info/MethodOptimizationInfo.java index fe754e5..9bfdb50 100644 --- a/src/proguard/optimize/info/MethodOptimizationInfo.java +++ b/src/proguard/optimize/info/MethodOptimizationInfo.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 @@ -38,6 +38,7 @@ public class MethodOptimizationInfo private boolean catchesExceptions = false; private boolean branchesBackward = false; private boolean invokesSuperMethods = false; + private boolean invokesDynamically = false; private boolean accessesPrivateCode = false; private boolean accessesPackageCode = false; private boolean accessesProtectedCode = false; @@ -58,7 +59,7 @@ public class MethodOptimizationInfo int parameterCount = ClassUtil.internalMethodParameterCount(method.getDescriptor(clazz)); - if ((method.getAccessFlags() & ClassConstants.INTERNAL_ACC_STATIC) == 0) + if ((method.getAccessFlags() & ClassConstants.ACC_STATIC) == 0) { parameterCount++; } @@ -142,6 +143,18 @@ public class MethodOptimizationInfo } + public void setInvokesDynamically() + { + invokesDynamically = true; + } + + + public boolean invokesDynamically() + { + return invokesDynamically; + } + + public void setAccessesPrivateCode() { accessesPrivateCode = true; @@ -256,6 +269,13 @@ public class MethodOptimizationInfo } + // For setting enum return values. + public void setReturnValue(Value returnValue) + { + this.returnValue = returnValue; + } + + public void merge(MethodOptimizationInfo other) { if (other != null) @@ -266,6 +286,7 @@ public class MethodOptimizationInfo this.catchesExceptions |= other.catchesExceptions; this.branchesBackward |= other.branchesBackward; this.invokesSuperMethods |= other.invokesSuperMethods; + this.invokesDynamically |= other.invokesDynamically; this.accessesPrivateCode |= other.accessesPrivateCode; this.accessesPackageCode |= other.accessesPackageCode; this.accessesProtectedCode |= other.accessesProtectedCode; diff --git a/src/proguard/optimize/info/NoSideEffectMethodMarker.java b/src/proguard/optimize/info/NoSideEffectMethodMarker.java index bf5ce45..34549b3 100644 --- a/src/proguard/optimize/info/NoSideEffectMethodMarker.java +++ b/src/proguard/optimize/info/NoSideEffectMethodMarker.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/optimize/info/NonPrivateMemberMarker.java b/src/proguard/optimize/info/NonPrivateMemberMarker.java index 06f8500..152e114 100644 --- a/src/proguard/optimize/info/NonPrivateMemberMarker.java +++ b/src/proguard/optimize/info/NonPrivateMemberMarker.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 @@ -49,13 +49,13 @@ implements ClassVisitor, programClass.constantPoolEntriesAccept(this); // Explicitly mark the <clinit> method. - programClass.methodAccept(ClassConstants.INTERNAL_METHOD_NAME_CLINIT, - ClassConstants.INTERNAL_METHOD_TYPE_CLINIT, + programClass.methodAccept(ClassConstants.METHOD_NAME_CLINIT, + ClassConstants.METHOD_TYPE_CLINIT, this); // Explicitly mark the parameterless <init> method. - programClass.methodAccept(ClassConstants.INTERNAL_METHOD_NAME_INIT, - ClassConstants.INTERNAL_METHOD_TYPE_INIT, + programClass.methodAccept(ClassConstants.METHOD_NAME_INIT, + ClassConstants.METHOD_TYPE_INIT, this); // Mark all methods that may have implementations. diff --git a/src/proguard/optimize/info/PackageVisibleMemberContainingClassMarker.java b/src/proguard/optimize/info/PackageVisibleMemberContainingClassMarker.java index 02e1a18..7f1dfdb 100644 --- a/src/proguard/optimize/info/PackageVisibleMemberContainingClassMarker.java +++ b/src/proguard/optimize/info/PackageVisibleMemberContainingClassMarker.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 @@ -39,7 +39,7 @@ implements ClassVisitor, public void visitAnyClass(Clazz clazz) { // Check the class itself. - if ((clazz.getAccessFlags() & ClassConstants.INTERNAL_ACC_PUBLIC) == 0) + if ((clazz.getAccessFlags() & ClassConstants.ACC_PUBLIC) == 0) { setPackageVisibleMembers(clazz); } @@ -57,8 +57,8 @@ implements ClassVisitor, public void visitAnyMember(Clazz clazz, Member member) { if ((member.getAccessFlags() & - (ClassConstants.INTERNAL_ACC_PRIVATE | - ClassConstants.INTERNAL_ACC_PUBLIC)) == 0) + (ClassConstants.ACC_PRIVATE | + ClassConstants.ACC_PUBLIC)) == 0) { setPackageVisibleMembers(clazz); } diff --git a/src/proguard/optimize/info/PackageVisibleMemberInvokingClassMarker.java b/src/proguard/optimize/info/PackageVisibleMemberInvokingClassMarker.java index 3148e3d..6a8e329 100644 --- a/src/proguard/optimize/info/PackageVisibleMemberInvokingClassMarker.java +++ b/src/proguard/optimize/info/PackageVisibleMemberInvokingClassMarker.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 @@ -21,8 +21,8 @@ package proguard.optimize.info; import proguard.classfile.*; -import proguard.classfile.constant.visitor.ConstantVisitor; import proguard.classfile.constant.*; +import proguard.classfile.constant.visitor.ConstantVisitor; import proguard.classfile.util.SimplifiedVisitor; import proguard.classfile.visitor.*; @@ -89,7 +89,7 @@ implements ConstantVisitor, public void visitAnyClass(Clazz clazz) { if ((clazz.getAccessFlags() & - ClassConstants.INTERNAL_ACC_PUBLIC) == 0) + ClassConstants.ACC_PUBLIC) == 0) { setInvokesPackageVisibleMembers(referencingClass); } @@ -101,8 +101,8 @@ implements ConstantVisitor, public void visitAnyMember(Clazz clazz, Member member) { if ((member.getAccessFlags() & - (ClassConstants.INTERNAL_ACC_PUBLIC | - ClassConstants.INTERNAL_ACC_PRIVATE)) == 0) + (ClassConstants.ACC_PUBLIC | + ClassConstants.ACC_PRIVATE)) == 0) { setInvokesPackageVisibleMembers(referencingClass); } diff --git a/src/proguard/optimize/info/ParameterUsageMarker.java b/src/proguard/optimize/info/ParameterUsageMarker.java index a2a264d..0061148 100644 --- a/src/proguard/optimize/info/ParameterUsageMarker.java +++ b/src/proguard/optimize/info/ParameterUsageMarker.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 @@ -89,7 +89,7 @@ implements MemberVisitor, // Must we mark the 'this' parameter? if (markThisParameter && - (accessFlags & ClassConstants.INTERNAL_ACC_STATIC) == 0) + (accessFlags & ClassConstants.ACC_STATIC) == 0) { // Mark the 'this' parameter. markParameterUsed(programMethod, 0); @@ -100,19 +100,19 @@ implements MemberVisitor, { // Mark all parameters, without the 'this' parameter. markUsedParameters(programMethod, - (accessFlags & ClassConstants.INTERNAL_ACC_STATIC) != 0 ? + (accessFlags & ClassConstants.ACC_STATIC) != 0 ? -1L : -2L); } // Is it a native method? - if ((accessFlags & ClassConstants.INTERNAL_ACC_NATIVE) != 0) + if ((accessFlags & ClassConstants.ACC_NATIVE) != 0) { // Mark all parameters. markUsedParameters(programMethod, -1L); } // Is it an abstract method? - else if ((accessFlags & ClassConstants.INTERNAL_ACC_ABSTRACT) != 0) + else if ((accessFlags & ClassConstants.ACC_ABSTRACT) != 0) { // Mark the 'this' parameter. markParameterUsed(programMethod, 0); @@ -123,10 +123,10 @@ implements MemberVisitor, { // Is the method not static, but synchronized, or can it have // other implementations, or is it a class instance initializer? - if ((accessFlags & ClassConstants.INTERNAL_ACC_STATIC) == 0 && - ((accessFlags & ClassConstants.INTERNAL_ACC_SYNCHRONIZED) != 0 || + if ((accessFlags & ClassConstants.ACC_STATIC) == 0 && + ((accessFlags & ClassConstants.ACC_SYNCHRONIZED) != 0 || programClass.mayHaveImplementations(programMethod) || - programMethod.getName(programClass).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT))) + programMethod.getName(programClass).equals(ClassConstants.METHOD_NAME_INIT))) { // Mark the 'this' parameter. markParameterUsed(programMethod, 0); diff --git a/src/proguard/optimize/info/ReadWriteFieldMarker.java b/src/proguard/optimize/info/ReadWriteFieldMarker.java index 6bd4b2f..ea98d3e 100644 --- a/src/proguard/optimize/info/ReadWriteFieldMarker.java +++ b/src/proguard/optimize/info/ReadWriteFieldMarker.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/optimize/info/SideEffectInstructionChecker.java b/src/proguard/optimize/info/SideEffectInstructionChecker.java index 91f1f02..49a1281 100644 --- a/src/proguard/optimize/info/SideEffectInstructionChecker.java +++ b/src/proguard/optimize/info/SideEffectInstructionChecker.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 @@ -33,7 +33,8 @@ import java.util.*; /** * This class can tell whether an instruction has any side effects outside of - * its method. Return instructions can be included or not. + * its method. Return instructions and local field accesses can be included or + * not. * * @see ReadWriteFieldMarker * @see StaticInitializerContainingClassMarker @@ -47,17 +48,25 @@ implements InstructionVisitor, ConstantVisitor, MemberVisitor { - private static final boolean OPTIMIZE_CONSERVATIVELY = System.getProperty("optimize.conservatively") != null; + static final boolean OPTIMIZE_CONSERVATIVELY = System.getProperty("optimize.conservatively") != null; private final boolean includeReturnInstructions; private final boolean includeLocalFieldAccess; // A return value for the visitor methods. + private boolean writingField; private Clazz referencingClass; private boolean hasSideEffects; + /** + * Creates a new SideEffectInstructionChecker + * @param includeReturnInstructions specifies whether return instructions + * count as side effects. + * @param includeLocalFieldAccess specifies whether reading or writing + * local fields counts as side effects. + */ public SideEffectInstructionChecker(boolean includeReturnInstructions, boolean includeLocalFieldAccess) { @@ -96,6 +105,10 @@ implements InstructionVisitor, // Check for instructions that might cause side effects. switch (opcode) { + case InstructionConstants.OP_IDIV: + case InstructionConstants.OP_LDIV: + case InstructionConstants.OP_IREM: + case InstructionConstants.OP_LREM: case InstructionConstants.OP_IALOAD: case InstructionConstants.OP_LALOAD: case InstructionConstants.OP_FALOAD: @@ -104,8 +117,13 @@ implements InstructionVisitor, case InstructionConstants.OP_BALOAD: case InstructionConstants.OP_CALOAD: case InstructionConstants.OP_SALOAD: + case InstructionConstants.OP_NEWARRAY: + case InstructionConstants.OP_ARRAYLENGTH: + case InstructionConstants.OP_ANEWARRAY: + case InstructionConstants.OP_MULTIANEWARRAY: // These instructions strictly taken may cause a side effect - // (NullPointerException, ArrayIndexOutOfBoundsException). + // (ArithmeticException, NullPointerException, + // ArrayIndexOutOfBoundsException, NegativeArraySizeException). hasSideEffects = OPTIMIZE_CONSERVATIVELY; break; @@ -160,16 +178,53 @@ implements InstructionVisitor, switch (opcode) { case InstructionConstants.OP_GETSTATIC: + // Check if accessing the field might cause any side effects. + writingField = false; + clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); + break; + case InstructionConstants.OP_PUTSTATIC: - case InstructionConstants.OP_INVOKESPECIAL: - case InstructionConstants.OP_INVOKESTATIC: - // Check if the field is write-only or volatile, or if the - // invoked method is causing any side effects. + // Check if accessing the field might cause any side effects. + writingField = true; clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); break; case InstructionConstants.OP_GETFIELD: + if (OPTIMIZE_CONSERVATIVELY) + { + // These instructions strictly taken may cause a side effect + // (NullPointerException). + hasSideEffects = true; + } + else + { + // Check if the field is write-only or volatile. + writingField = false; + clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); + } + break; + case InstructionConstants.OP_PUTFIELD: + if (OPTIMIZE_CONSERVATIVELY) + { + // These instructions strictly taken may cause a side effect + // (NullPointerException). + hasSideEffects = true; + } + else + { + // Check if the field is write-only or volatile. + writingField = true; + clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); + } + break; + + case InstructionConstants.OP_INVOKESPECIAL: + case InstructionConstants.OP_INVOKESTATIC: + // Check if the invoked method is causing any side effects. + clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); + break; + case InstructionConstants.OP_INVOKEVIRTUAL: case InstructionConstants.OP_INVOKEINTERFACE: case InstructionConstants.OP_INVOKEDYNAMIC: @@ -181,15 +236,16 @@ implements InstructionVisitor, } else { - // Check if the field is write-only or volatile, or if the - // invoked method is causing any side effects. + // Check if the invoked method is causing any side effects. clazz.constantPoolEntryAccept(constantInstruction.constantIndex, this); } break; + case InstructionConstants.OP_ANEWARRAY: case InstructionConstants.OP_CHECKCAST: + case InstructionConstants.OP_MULTIANEWARRAY: // This instructions strictly taken may cause a side effect - // (ClassCastException). + // (ClassCastException, NegativeArraySizeException). hasSideEffects = OPTIMIZE_CONSERVATIVELY; break; } @@ -252,11 +308,9 @@ implements InstructionVisitor, { hasSideEffects = (includeLocalFieldAccess || !programClass.equals(referencingClass)) && - ((ReadWriteFieldMarker.isRead(programField) && - ReadWriteFieldMarker.isWritten(programField)) || - ((programField.getAccessFlags() & ClassConstants.INTERNAL_ACC_VOLATILE) != 0) || - (!programClass.equals(referencingClass) && - !initializedSuperClasses(referencingClass).containsAll(initializedSuperClasses(programClass)))); + ((writingField && ReadWriteFieldMarker.isRead(programField)) || + (programField.getAccessFlags() & ClassConstants.ACC_VOLATILE) != 0 || + mayHaveSideEffects(referencingClass, programClass)); } @@ -267,8 +321,7 @@ implements InstructionVisitor, hasSideEffects = !NoSideEffectMethodMarker.hasNoSideEffects(programMethod) && (SideEffectMethodMarker.hasSideEffects(programMethod) || - (!programClass.equals(referencingClass) && - !initializedSuperClasses(referencingClass).containsAll(initializedSuperClasses(programClass)))); + mayHaveSideEffects(referencingClass, programClass)); } @@ -285,6 +338,21 @@ implements InstructionVisitor, } + // Small utility methods. + + /** + * Returns whether a field reference or method invocation from the + * referencing class to the referenced class might have any side + * effects. + */ + private boolean mayHaveSideEffects(Clazz referencingClass, Clazz referencedClass) + { + return + !referencedClass.equals(referencingClass) && + !initializedSuperClasses(referencingClass).containsAll(initializedSuperClasses(referencedClass)); + } + + /** * Returns the set of superclasses and interfaces that are initialized. */ @@ -296,8 +364,8 @@ implements InstructionVisitor, // static initializers. clazz.hierarchyAccept(true, true, true, false, new StaticInitializerContainingClassFilter( - new NamedMethodVisitor(ClassConstants.INTERNAL_METHOD_NAME_CLINIT, - ClassConstants.INTERNAL_METHOD_TYPE_CLINIT, + new NamedMethodVisitor(ClassConstants.METHOD_NAME_CLINIT, + ClassConstants.METHOD_TYPE_CLINIT, new SideEffectMethodFilter( new MemberToClassVisitor( new ClassCollector(set)))))); diff --git a/src/proguard/optimize/info/SideEffectMethodFilter.java b/src/proguard/optimize/info/SideEffectMethodFilter.java index 52e072a..3821870 100644 --- a/src/proguard/optimize/info/SideEffectMethodFilter.java +++ b/src/proguard/optimize/info/SideEffectMethodFilter.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/optimize/info/SideEffectMethodMarker.java b/src/proguard/optimize/info/SideEffectMethodMarker.java index f7953c0..79584e1 100644 --- a/src/proguard/optimize/info/SideEffectMethodMarker.java +++ b/src/proguard/optimize/info/SideEffectMethodMarker.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 @@ -86,8 +86,8 @@ implements ClassPoolVisitor, // Initialize the return value. hasSideEffects = (programMethod.getAccessFlags() & - (ClassConstants.INTERNAL_ACC_NATIVE | - ClassConstants.INTERNAL_ACC_SYNCHRONIZED)) != 0; + (ClassConstants.ACC_NATIVE | + ClassConstants.ACC_SYNCHRONIZED)) != 0; // Look further if the method hasn't been marked yet. if (!hasSideEffects) @@ -132,7 +132,7 @@ implements ClassPoolVisitor, int length = codeAttribute.u4codeLength; SideEffectInstructionChecker checker = - method.getName(clazz).equals(ClassConstants.INTERNAL_METHOD_NAME_CLINIT) ? + method.getName(clazz).equals(ClassConstants.METHOD_NAME_CLINIT) ? initializerSideEffectInstructionChecker : sideEffectInstructionChecker; diff --git a/src/proguard/optimize/info/SimpleEnumFilter.java b/src/proguard/optimize/info/SimpleEnumFilter.java new file mode 100644 index 0000000..8db58f4 --- /dev/null +++ b/src/proguard/optimize/info/SimpleEnumFilter.java @@ -0,0 +1,63 @@ +/* + * 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.optimize.info; + +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 simple enums. + * + * @see SimpleEnumMarker + * @author Eric Lafortune + */ +public class SimpleEnumFilter +implements ClassVisitor +{ + private final ClassVisitor classVisitor; + + + public SimpleEnumFilter(ClassVisitor classVisitor) + { + this.classVisitor = classVisitor; + } + + + // Implementations for ClassVisitor. + + public void visitProgramClass(ProgramClass programClass) + { + if (SimpleEnumMarker.isSimpleEnum(programClass)) + { + classVisitor.visitProgramClass(programClass); + } + } + + + public void visitLibraryClass(LibraryClass libraryClass) + { + if (SimpleEnumMarker.isSimpleEnum(libraryClass)) + { + classVisitor.visitLibraryClass(libraryClass); + } + } +}
\ No newline at end of file diff --git a/src/proguard/optimize/info/SimpleEnumMarker.java b/src/proguard/optimize/info/SimpleEnumMarker.java new file mode 100644 index 0000000..dfb1ccb --- /dev/null +++ b/src/proguard/optimize/info/SimpleEnumMarker.java @@ -0,0 +1,75 @@ +/* + * 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.optimize.info; + +import proguard.classfile.*; +import proguard.classfile.visitor.ClassVisitor; + +/** + * This ClassVisitor marks all program classes that it visits with a given + * flag for simple enums. + * + * @author Eric Lafortune + */ +public class SimpleEnumMarker +implements ClassVisitor +{ + private final boolean simple; + + + /** + * Creates a new SimpleEnumMarker that marks visited classes with the + * given flag. + */ + public SimpleEnumMarker(boolean simple) + { + this.simple = simple; + } + + + // Implementations for ClassVisitor. + + public void visitLibraryClass(LibraryClass libraryClass) {} + + public void visitProgramClass(ProgramClass programClass) + { + setSimpleEnum(programClass); + } + + + // Small utility methods. + + private void setSimpleEnum(Clazz clazz) + { + ClassOptimizationInfo info = ClassOptimizationInfo.getClassOptimizationInfo(clazz); + if (info != null) + { + info.setSimpleEnum(simple); + } + } + + + public static boolean isSimpleEnum(Clazz clazz) + { + ClassOptimizationInfo info = ClassOptimizationInfo.getClassOptimizationInfo(clazz); + return info != null && info.isSimpleEnum(); + } +}
\ No newline at end of file diff --git a/src/proguard/optimize/info/StaticInitializerContainingClassFilter.java b/src/proguard/optimize/info/StaticInitializerContainingClassFilter.java index 36aa392..ccb3d31 100644 --- a/src/proguard/optimize/info/StaticInitializerContainingClassFilter.java +++ b/src/proguard/optimize/info/StaticInitializerContainingClassFilter.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/optimize/info/StaticInitializerContainingClassMarker.java b/src/proguard/optimize/info/StaticInitializerContainingClassMarker.java index 3a7e642..12e0079 100644 --- a/src/proguard/optimize/info/StaticInitializerContainingClassMarker.java +++ b/src/proguard/optimize/info/StaticInitializerContainingClassMarker.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 @@ -22,7 +22,7 @@ package proguard.optimize.info; import proguard.classfile.*; import proguard.classfile.util.SimplifiedVisitor; -import proguard.classfile.visitor.*; +import proguard.classfile.visitor.ClassVisitor; /** * This ClassVisitor marks all classes that contain static initializers. @@ -37,8 +37,8 @@ implements ClassVisitor public void visitAnyClass(Clazz clazz) { - if (clazz.findMethod(ClassConstants.INTERNAL_METHOD_NAME_CLINIT, - ClassConstants.INTERNAL_METHOD_TYPE_CLINIT) != null) + if (clazz.findMethod(ClassConstants.METHOD_NAME_CLINIT, + ClassConstants.METHOD_TYPE_CLINIT) != null) { setStaticInitializer(clazz); } diff --git a/src/proguard/optimize/info/SuperInvocationMarker.java b/src/proguard/optimize/info/SuperInvocationMarker.java index 37b118a..990a9ea 100644 --- a/src/proguard/optimize/info/SuperInvocationMarker.java +++ b/src/proguard/optimize/info/SuperInvocationMarker.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 @@ -69,7 +69,7 @@ implements InstructionVisitor, { invokesSuperMethods = !clazz.equals(refConstant.referencedClass) && - !refConstant.getName(clazz).equals(ClassConstants.INTERNAL_METHOD_NAME_INIT); + !refConstant.getName(clazz).equals(ClassConstants.METHOD_NAME_INIT); } diff --git a/src/proguard/optimize/info/VariableUsageMarker.java b/src/proguard/optimize/info/VariableUsageMarker.java index b189ca9..1d3c04a 100644 --- a/src/proguard/optimize/info/VariableUsageMarker.java +++ b/src/proguard/optimize/info/VariableUsageMarker.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 |