optimizer.java
来自「proguard 一个java的混淆器」· Java 代码 · 共 424 行 · 第 1/2 页
JAVA
424 行
new AllFieldVisitor( new WriteOnlyFieldFilter(writeOnlyFieldCounter)), new AllFieldVisitor( new ConstantMemberFilter(constantFieldCounter)), new AllMethodVisitor( new ConstantMemberFilter(constantMethodCounter)), })); // Simplify based on partial evaluation. // Also remove unused parameters from the stack before method invocations, // for MethodDescriptorShrinker, MethodStaticizer. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new EvaluationSimplifier( new PartialEvaluator(new SpecificValueFactory(), new UnusedParameterInvocationUnit(new LoadingInvocationUnit()), false), pushCounter, branchCounter, deletedCounter, addedCounter))));// // Specializing the class member descriptors seems to increase the// // class file size, on average.// // Specialize all class member descriptors.// programClassPool.classesAccept(new AllMemberVisitor(// new OptimizationInfoMemberFilter(// new MemberDescriptorSpecializer())));//// // Fix all references to classes, for MemberDescriptorSpecializer.// programClassPool.classesAccept(new AllMemberVisitor(// new OptimizationInfoMemberFilter(// new ClassReferenceFixer(true)))); // Inline interfaces with single implementations. programClassPool.classesAccept(new SingleImplementationInliner()); // Restore the interface references from these single implementations. programClassPool.classesAccept(new SingleImplementationFixer()); if (configuration.allowAccessModification) { // Fix the access flags of referenced classes and class members, // for SingleImplementationInliner. programClassPool.classesAccept(new AllConstantVisitor( new AccessFixer())); } // Fix all references to classes, for SingleImplementationInliner. programClassPool.classesAccept(new ClassReferenceFixer(true)); // Fix all references to class members, for SingleImplementationInliner. programClassPool.classesAccept(new MemberReferenceFixer()); // Count all method invocations. // Mark super invocations and other access of methods. // Mark all exception catches of methods. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new MultiAttributeVisitor( new AttributeVisitor[] { new AllInstructionVisitor( new MultiInstructionVisitor( new InstructionVisitor[] { new MethodInvocationMarker(), new SuperInvocationMarker(), new BackwardBranchMarker(), new AccessMethodMarker(), })), new CatchExceptionMarker(), })))); // Inline methods that are only invoked once. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new MethodInliner(configuration.allowAccessModification, true, inliningCounter)))); // Inline short methods. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new MethodInliner(configuration.allowAccessModification, false, inliningCounter)))); // Mark all class members that can not be made private. programClassPool.classesAccept(new NonPrivateMemberMarker()); // Make all non-private and unmarked class members in non-interface // classes private. programClassPool.classesAccept(new ClassAccessFilter(0, ClassConstants.INTERNAL_ACC_INTERFACE, new AllMemberVisitor( new MemberAccessFilter(0, ClassConstants.INTERNAL_ACC_PRIVATE, new MemberPrivatizer(privateFieldCounter, privateMethodCounter))))); if (configuration.allowAccessModification) { // Fix the access flags of referenced classes and class members, // for MethodInliner. programClassPool.classesAccept(new AllConstantVisitor( new AccessFixer())); } // Fix invocations of methods that have become non-abstract or private, // for SingleImplementationInliner, MemberPrivatizer, AccessFixer. programClassPool.classesAccept(new AllMemberVisitor( new AllAttributeVisitor( new MethodInvocationFixer()))); // Create a branch target marker and a code attribute editor that can // be reused for all code attributes. BranchTargetFinder branchTargetFinder = new BranchTargetFinder(); CodeAttributeEditor codeAttributeEditor = new CodeAttributeEditor(); // Share common blocks of code at branches. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new GotoCommonCodeReplacer(commonCodeCounter)))); // Perform various peephole optimisations. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new PeepholeOptimizer(branchTargetFinder, codeAttributeEditor, new MultiInstructionVisitor( new InstructionVisitor[] { new InstructionSequencesReplacer(InstructionSequenceConstants.PATTERN_CONSTANTS, InstructionSequenceConstants.INSTRUCTION_SEQUENCES, branchTargetFinder, codeAttributeEditor, peepholeCounter), new GotoGotoReplacer( codeAttributeEditor, peepholeCounter), new GotoReturnReplacer( codeAttributeEditor, peepholeCounter), }))))); // Remove unnecessary exception handlers. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new UnreachableExceptionRemover(exceptionCounter)))); // Remove unreachable code. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new UnreachableCodeRemover(deletedCounter)))); // Remove all unused local variables. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new VariableShrinker(variableShrinkCounter)))); // Optimize the variables. programClassPool.classesAccept(new AllMethodVisitor( new AllAttributeVisitor( new VariableOptimizer(!configuration.microEdition)))); int singleImplementationCount = singleImplementationCounter.getCount(); int finalClassCount = finalClassCounter .getCount(); int privateFieldCount = privateFieldCounter .getCount(); int privateMethodCount = privateMethodCounter .getCount(); int staticMethodCount = staticMethodCounter .getCount(); int finalMethodCount = finalMethodCounter .getCount(); int writeOnlyFieldCount = writeOnlyFieldCounter .getCount(); int constantFieldCount = constantFieldCounter .getCount(); int constantMethodCount = constantMethodCounter .getCount(); int descriptorShrinkCount = descriptorShrinkCounter .getCount(); int parameterShrinkCount = parameterShrinkCounter .getCount(); int variableShrinkCount = variableShrinkCounter .getCount(); int exceptionCount = exceptionCounter .getCount(); int inliningCount = inliningCounter .getCount(); int commonCodeCount = commonCodeCounter .getCount(); int pushCount = pushCounter .getCount(); int branchCount = branchCounter .getCount(); int removedCount = deletedCounter .getCount() - addedCounter.getCount(); int peepholeCount = peepholeCounter .getCount(); if (configuration.verbose) { System.out.println(" Number of inlined interfaces: "+singleImplementationCount); System.out.println(" Number of finalized classes: "+finalClassCount); System.out.println(" Number of privatized fields: "+privateFieldCount); System.out.println(" Number of privatized methods: "+privateMethodCount); System.out.println(" Number of staticized methods: "+staticMethodCount); System.out.println(" Number of finalized methods: "+finalMethodCount); System.out.println(" Number of removed write-only fields: "+writeOnlyFieldCount); System.out.println(" Number of inlined constant fields: "+constantFieldCount); System.out.println(" Number of inlined constant methods: "+constantMethodCount); System.out.println(" Number of simplified method declarations: "+descriptorShrinkCount); System.out.println(" Number of removed parameters: "+parameterShrinkCount); System.out.println(" Number of removed local variables: "+variableShrinkCount); System.out.println(" Number of inlined method calls: "+inliningCount); System.out.println(" Number of removed exception blocks: "+exceptionCount); System.out.println(" Number of merged code blocks: "+commonCodeCount); System.out.println(" Number of simplified push instructions: "+pushCount); System.out.println(" Number of simplified branches: "+branchCount); System.out.println(" Number of removed instructions: "+removedCount); System.out.println(" Number of peephole optimizations: "+peepholeCount); } return singleImplementationCount > 0 || finalClassCount > 0 || privateFieldCount > 0 || privateMethodCount > 0 || staticMethodCount > 0 || finalMethodCount > 0 || writeOnlyFieldCount > 0 || constantFieldCount > 0 || constantMethodCount > 0 || descriptorShrinkCount > 0 || parameterShrinkCount > 0 || variableShrinkCount > 0 || inliningCount > 0 || exceptionCount > 0 || commonCodeCount > 0 || pushCount > 0 || branchCount > 0 || removedCount > 0 || peepholeCount > 0; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?