1b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang/* 2b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * ProGuard -- shrinking, optimization, obfuscation, and preverification 3b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * of Java bytecode. 4b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 5b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Copyright (c) 2002-2013 Eric Lafortune (eric@graphics.cornell.edu) 6b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 7b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * This program is free software; you can redistribute it and/or modify it 8b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * under the terms of the GNU General Public License as published by the Free 9b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Software Foundation; either version 2 of the License, or (at your option) 10b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * any later version. 11b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 12b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * This program is distributed in the hope that it will be useful, but WITHOUT 13b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 14b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 15b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * more details. 16b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 17b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * You should have received a copy of the GNU General Public License along 18b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * with this program; if not, write to the Free Software Foundation, Inc., 19b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 21b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangpackage proguard.classfile.editor; 22b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 23b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.*; 24b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.*; 25b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.annotation.*; 26b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.annotation.visitor.*; 27b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.preverification.*; 28b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.preverification.visitor.*; 29b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.attribute.visitor.*; 30b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.constant.*; 31b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.constant.visitor.ConstantVisitor; 32b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.instruction.*; 33b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.instruction.visitor.InstructionVisitor; 34b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.util.SimplifiedVisitor; 35b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport proguard.classfile.visitor.*; 36b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 37b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimport java.util.Arrays; 38b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 39b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang/** 40b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * This ClassVisitor removes all unused entries from the constant pool. 41b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * 42b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * @author Eric Lafortune 43b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 44b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangpublic class ConstantPoolShrinker 45b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangextends SimplifiedVisitor 46b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wangimplements ClassVisitor, 47b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang MemberVisitor, 48b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang ConstantVisitor, 49b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang AttributeVisitor, 50b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang BootstrapMethodInfoVisitor, 51b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang InnerClassesInfoVisitor, 52b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang ExceptionInfoVisitor, 53b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang StackMapFrameVisitor, 54b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang VerificationTypeVisitor, 55b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang LocalVariableInfoVisitor, 56b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang LocalVariableTypeInfoVisitor, 57b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang AnnotationVisitor, 58b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang ElementValueVisitor, 59b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang InstructionVisitor 60b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang{ 61b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // A visitor info flag to indicate the constant is being used. 62b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private static final Object USED = new Object(); 63b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 64b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private int[] constantIndexMap = new int[ClassConstants.TYPICAL_CONSTANT_POOL_SIZE]; 65b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private final ConstantPoolRemapper constantPoolRemapper = new ConstantPoolRemapper(); 66b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 67b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 68b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for ClassVisitor. 69b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 70b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitProgramClass(ProgramClass programClass) 71b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 72b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark this class's name. 73b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(programClass, programClass.u2thisClass); 74b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 75b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the superclass class constant. 76b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.superClassConstantAccept(this); 77b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 78b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the interface class constants. 79b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.interfaceConstantsAccept(this); 80b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 81b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constants referenced by the class members. 82b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.fieldsAccept(this); 83b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.methodsAccept(this); 84b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 85b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the attributes. 86b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.attributesAccept(this); 87b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 88b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Shift the used constant pool entries together, filling out the 89b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // index map. 90b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int newConstantPoolCount = 91b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang shrinkConstantPool(programClass.constantPool, 92b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.u2constantPoolCount); 93b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 94b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Remap the references to the constant pool if it has shrunk. 95b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (newConstantPoolCount < programClass.u2constantPoolCount) 96b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 97b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programClass.u2constantPoolCount = newConstantPoolCount; 98b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 99b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Remap all constant pool references. 100b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constantPoolRemapper.setConstantIndexMap(constantIndexMap); 101b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constantPoolRemapper.visitProgramClass(programClass); 102b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 103b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 104b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 105b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 106b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for MemberVisitor. 107b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 108b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitProgramMember(ProgramClass programClass, ProgramMember programMember) 109b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 110b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the name and descriptor. 111b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(programClass, programMember.u2nameIndex); 112b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(programClass, programMember.u2descriptorIndex); 113b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 114b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the attributes. 115b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang programMember.attributesAccept(programClass, this); 116b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 117b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 118b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 119b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for ConstantVisitor. 120b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 121b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyConstant(Clazz clazz, Constant constant) 122b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 123b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(constant); 124b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 125b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 126b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 127b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitStringConstant(Clazz clazz, StringConstant stringConstant) 128b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 129b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(stringConstant); 130b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 131b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, stringConstant.u2stringIndex); 132b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 133b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 134b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 135b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitInvokeDynamicConstant(Clazz clazz, InvokeDynamicConstant invokeDynamicConstant) 136b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 137b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(invokeDynamicConstant); 138b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 139b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, invokeDynamicConstant.u2nameAndTypeIndex); 140b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 141b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the bootstrap methods attribute. 142b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang clazz.attributesAccept(this); 143b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 144b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 145b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 146b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitMethodHandleConstant(Clazz clazz, MethodHandleConstant methodHandleConstant) 147b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 148b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(methodHandleConstant); 149b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 150b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, methodHandleConstant.u2referenceIndex); 151b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 152b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 153b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 154b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyRefConstant(Clazz clazz, RefConstant refConstant) 155b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 156b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(refConstant); 157b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 158b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, refConstant.u2classIndex); 159b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, refConstant.u2nameAndTypeIndex); 160b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 161b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 162b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 163b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitClassConstant(Clazz clazz, ClassConstant classConstant) 164b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 165b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(classConstant); 166b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 167b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, classConstant.u2nameIndex); 168b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 169b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 170b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 171b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitMethodTypeConstant(Clazz clazz, MethodTypeConstant methodTypeConstant) 172b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 173b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(methodTypeConstant); 174b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 175b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, methodTypeConstant.u2descriptorIndex); 176b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 177b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 178b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 179b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitNameAndTypeConstant(Clazz clazz, NameAndTypeConstant nameAndTypeConstant) 180b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 181b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markAsUsed(nameAndTypeConstant); 182b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 183b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, nameAndTypeConstant.u2nameIndex); 184b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, nameAndTypeConstant.u2descriptorIndex); 185b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 186b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 187b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 188b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for AttributeVisitor. 189b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 190b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyAttribute(Clazz clazz, Attribute attribute) 191b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 192b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, attribute.u2attributeNameIndex); 193b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 194b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 195b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 196b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitBootstrapMethodsAttribute(Clazz clazz, BootstrapMethodsAttribute bootstrapMethodsAttribute) 197b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 198b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, bootstrapMethodsAttribute.u2attributeNameIndex); 199b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 200b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the bootstrap method entries. 201b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang bootstrapMethodsAttribute.bootstrapMethodEntriesAccept(clazz, this); 202b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 203b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 204b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 205b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitSourceFileAttribute(Clazz clazz, SourceFileAttribute sourceFileAttribute) 206b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 207b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, sourceFileAttribute.u2attributeNameIndex); 208b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, sourceFileAttribute.u2sourceFileIndex); 209b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 210b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 211b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 212b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitSourceDirAttribute(Clazz clazz, SourceDirAttribute sourceDirAttribute) 213b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 214b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, sourceDirAttribute.u2attributeNameIndex); 215b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, sourceDirAttribute.u2sourceDirIndex); 216b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 217b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 218b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 219b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitInnerClassesAttribute(Clazz clazz, InnerClassesAttribute innerClassesAttribute) 220b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 221b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, innerClassesAttribute.u2attributeNameIndex); 222b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 223b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the outer class entries. 224b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang innerClassesAttribute.innerClassEntriesAccept(clazz, this); 225b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 226b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 227b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 228b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitEnclosingMethodAttribute(Clazz clazz, EnclosingMethodAttribute enclosingMethodAttribute) 229b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 230b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enclosingMethodAttribute.u2attributeNameIndex); 231b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enclosingMethodAttribute.u2classIndex); 232b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 233b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (enclosingMethodAttribute.u2nameAndTypeIndex != 0) 234b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 235b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enclosingMethodAttribute.u2nameAndTypeIndex); 236b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 237b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 238b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 239b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 240b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitSignatureAttribute(Clazz clazz, SignatureAttribute signatureAttribute) 241b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 242b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, signatureAttribute.u2attributeNameIndex); 243b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, signatureAttribute.u2signatureIndex); 244b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 245b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 246b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 247b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitConstantValueAttribute(Clazz clazz, Field field, ConstantValueAttribute constantValueAttribute) 248b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 249b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, constantValueAttribute.u2attributeNameIndex); 250b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, constantValueAttribute.u2constantValueIndex); 251b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 252b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 253b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 254b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitExceptionsAttribute(Clazz clazz, Method method, ExceptionsAttribute exceptionsAttribute) 255b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 256b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, exceptionsAttribute.u2attributeNameIndex); 257b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 258b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the exceptions. 259b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang exceptionsAttribute.exceptionEntriesAccept((ProgramClass)clazz, this); 260b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 261b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 262b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 263b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitCodeAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute) 264b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 265b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, codeAttribute.u2attributeNameIndex); 266b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 267b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the instructions, 268b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // by the exceptions, and by the attributes. 269b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang codeAttribute.instructionsAccept(clazz, method, this); 270b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang codeAttribute.exceptionsAccept(clazz, method, this); 271b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang codeAttribute.attributesAccept(clazz, method, this); 272b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 273b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 274b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 275b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitStackMapAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapAttribute stackMapAttribute) 276b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 277b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, stackMapAttribute.u2attributeNameIndex); 278b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 279b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the stack map frames. 280b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang stackMapAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this); 281b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 282b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 283b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 284b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitStackMapTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, StackMapTableAttribute stackMapTableAttribute) 285b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 286b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, stackMapTableAttribute.u2attributeNameIndex); 287b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 288b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the stack map frames. 289b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang stackMapTableAttribute.stackMapFramesAccept(clazz, method, codeAttribute, this); 290b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 291b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 292b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 293b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitLocalVariableTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTableAttribute localVariableTableAttribute) 294b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 295b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableTableAttribute.u2attributeNameIndex); 296b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 297b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the local variables. 298b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang localVariableTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); 299b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 300b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 301b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 302b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitLocalVariableTypeTableAttribute(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeTableAttribute localVariableTypeTableAttribute) 303b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 304b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableTypeTableAttribute.u2attributeNameIndex); 305b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 306b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the local variable types. 307b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang localVariableTypeTableAttribute.localVariablesAccept(clazz, method, codeAttribute, this); 308b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 309b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 310b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 311b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyAnnotationsAttribute(Clazz clazz, AnnotationsAttribute annotationsAttribute) 312b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 313b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, annotationsAttribute.u2attributeNameIndex); 314b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 315b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the annotations. 316b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang annotationsAttribute.annotationsAccept(clazz, this); 317b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 318b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 319b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 320b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyParameterAnnotationsAttribute(Clazz clazz, Method method, ParameterAnnotationsAttribute parameterAnnotationsAttribute) 321b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 322b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, parameterAnnotationsAttribute.u2attributeNameIndex); 323b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 324b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the annotations. 325b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang parameterAnnotationsAttribute.annotationsAccept(clazz, method, this); 326b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 327b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 328b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 329b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnnotationDefaultAttribute(Clazz clazz, Method method, AnnotationDefaultAttribute annotationDefaultAttribute) 330b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 331b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, annotationDefaultAttribute.u2attributeNameIndex); 332b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 333b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the element value. 334b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang annotationDefaultAttribute.defaultValueAccept(clazz, this); 335b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 336b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 337b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 338b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for BootstrapMethodInfoVisitor. 339b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 340b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitBootstrapMethodInfo(Clazz clazz, BootstrapMethodInfo bootstrapMethodInfo) 341b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 342b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, bootstrapMethodInfo.u2methodHandleIndex); 343b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 344b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the arguments. 345b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang bootstrapMethodInfo.methodArgumentsAccept(clazz, this); 346b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 347b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 348b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 349b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for InnerClassesInfoVisitor. 350b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 351b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitInnerClassesInfo(Clazz clazz, InnerClassesInfo innerClassesInfo) 352b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 353b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang innerClassesInfo.innerClassConstantAccept(clazz, this); 354b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang innerClassesInfo.outerClassConstantAccept(clazz, this); 355b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang innerClassesInfo.innerNameConstantAccept(clazz, this); 356b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 357b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 358b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 359b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for ExceptionInfoVisitor. 360b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 361b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitExceptionInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, ExceptionInfo exceptionInfo) 362b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 363b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (exceptionInfo.u2catchType != 0) 364b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 365b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, exceptionInfo.u2catchType); 366b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 367b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 368b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 369b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 370b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for StackMapFrameVisitor. 371b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 372b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyStackMapFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, StackMapFrame stackMapFrame) {} 373b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 374b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 375b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitSameOneFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, SameOneFrame sameOneFrame) 376b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 377b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the verification types. 378b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang sameOneFrame.stackItemAccept(clazz, method, codeAttribute, offset, this); 379b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 380b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 381b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 382b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitMoreZeroFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, MoreZeroFrame moreZeroFrame) 383b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 384b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the verification types. 385b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang moreZeroFrame.additionalVariablesAccept(clazz, method, codeAttribute, offset, this); 386b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 387b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 388b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 389b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitFullFrame(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, FullFrame fullFrame) 390b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 391b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the verification types. 392b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang fullFrame.variablesAccept(clazz, method, codeAttribute, offset, this); 393b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang fullFrame.stackAccept(clazz, method, codeAttribute, offset, this); 394b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 395b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 396b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 397b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for VerificationTypeVisitor. 398b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 399b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyVerificationType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, VerificationType verificationType) {} 400b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 401b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 402b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitObjectType(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ObjectType objectType) 403b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 404b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, objectType.u2classIndex); 405b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 406b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 407b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 408b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for LocalVariableInfoVisitor. 409b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 410b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitLocalVariableInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableInfo localVariableInfo) 411b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 412b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableInfo.u2nameIndex); 413b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableInfo.u2descriptorIndex); 414b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 415b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 416b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 417b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for LocalVariableTypeInfoVisitor. 418b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 419b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitLocalVariableTypeInfo(Clazz clazz, Method method, CodeAttribute codeAttribute, LocalVariableTypeInfo localVariableTypeInfo) 420b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 421b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableTypeInfo.u2nameIndex); 422b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, localVariableTypeInfo.u2signatureIndex); 423b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 424b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 425b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 426b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for AnnotationVisitor. 427b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 428b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnnotation(Clazz clazz, Annotation annotation) 429b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 430b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, annotation.u2typeIndex); 431b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 432b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the element values. 433b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang annotation.elementValuesAccept(clazz, this); 434b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 435b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 436b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 437b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for ElementValueVisitor. 438b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 439b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitConstantElementValue(Clazz clazz, Annotation annotation, ConstantElementValue constantElementValue) 440b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 441b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (constantElementValue.u2elementNameIndex != 0) 442b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 443b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, constantElementValue.u2elementNameIndex); 444b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 445b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 446b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, constantElementValue.u2constantValueIndex); 447b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 448b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 449b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 450b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitEnumConstantElementValue(Clazz clazz, Annotation annotation, EnumConstantElementValue enumConstantElementValue) 451b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 452b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (enumConstantElementValue.u2elementNameIndex != 0) 453b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 454b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enumConstantElementValue.u2elementNameIndex); 455b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 456b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 457b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enumConstantElementValue.u2typeNameIndex); 458b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, enumConstantElementValue.u2constantNameIndex); 459b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 460b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 461b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 462b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitClassElementValue(Clazz clazz, Annotation annotation, ClassElementValue classElementValue) 463b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 464b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (classElementValue.u2elementNameIndex != 0) 465b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 466b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, classElementValue.u2elementNameIndex); 467b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 468b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 469b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, classElementValue.u2classInfoIndex); 470b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 471b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 472b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 473b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnnotationElementValue(Clazz clazz, Annotation annotation, AnnotationElementValue annotationElementValue) 474b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 475b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (annotationElementValue.u2elementNameIndex != 0) 476b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 477b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, annotationElementValue.u2elementNameIndex); 478b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 479b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 480b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the annotation. 481b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang annotationElementValue.annotationAccept(clazz, this); 482b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 483b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 484b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 485b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitArrayElementValue(Clazz clazz, Annotation annotation, ArrayElementValue arrayElementValue) 486b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 487b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (arrayElementValue.u2elementNameIndex != 0) 488b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 489b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, arrayElementValue.u2elementNameIndex); 490b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 491b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 492b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Mark the constant pool entries referenced by the element values. 493b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang arrayElementValue.elementValuesAccept(clazz, annotation, this); 494b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 495b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 496b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 497b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Implementations for InstructionVisitor. 498b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 499b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitAnyInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, Instruction instruction) {} 500b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 501b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 502b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang public void visitConstantInstruction(Clazz clazz, Method method, CodeAttribute codeAttribute, int offset, ConstantInstruction constantInstruction) 503b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 504b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang markConstant(clazz, constantInstruction.constantIndex); 505b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 506b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 507b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 508b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Small utility methods. 509b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 510b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang /** 511b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Marks the given constant pool entry of the given class. This includes 512b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * visiting any referenced objects. 513b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 514b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private void markConstant(Clazz clazz, int index) 515b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 516b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang clazz.constantPoolEntryAccept(index, this); 517b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 518b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 519b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 520b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang /** 521b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Marks the given visitor accepter as being used. 522b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 523b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private void markAsUsed(Constant constant) 524b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 525b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constant.setVisitorInfo(USED); 526b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 527b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 528b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 529b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang /** 530b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Returns whether the given visitor accepter has been marked as being used. 531b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 532b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private boolean isUsed(VisitorAccepter visitorAccepter) 533b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 534b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang return visitorAccepter.getVisitorInfo() == USED; 535b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 536b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 537b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 538b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang /** 539b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * Removes all constants that are not marked as being used from the given 540b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * constant pool. 541b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang * @return the new number of entries. 542b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang */ 543b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang private int shrinkConstantPool(Constant[] constantPool, int length) 544b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 545b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Create a new index map, if necessary. 546b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (constantIndexMap.length < length) 547b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 548b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constantIndexMap = new int[length]; 549b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 550b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 551b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang int counter = 1; 552b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang boolean isUsed = false; 553b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 554b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Shift the used constant pool entries together. 555b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang for (int index = 1; index < length; index++) 556b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 557b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constantIndexMap[index] = counter; 558b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 559b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang Constant constant = constantPool[index]; 560b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 561b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Don't update the flag if this is the second half of a long entry. 562b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (constant != null) 563b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 564b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang isUsed = isUsed(constant); 565b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 566b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 567b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang if (isUsed) 568b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang { 569b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang constantPool[counter++] = constant; 570b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 571b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 572b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 573b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang // Clear the remaining constant pool elements. 574b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang Arrays.fill(constantPool, counter, length, null); 575b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang 576b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang return counter; 577b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang } 578b9cc48a43ed984587c939d02fba5316bf5c0df6eYing Wang} 579