Index: src/main/java/org/apache/harmony/pack200/profiler/Profiler.java =================================================================== --- src/main/java/org/apache/harmony/pack200/profiler/Profiler.java (revision 0) +++ src/main/java/org/apache/harmony/pack200/profiler/Profiler.java (revision 0) @@ -0,0 +1,118 @@ +package org.apache.harmony.pack200.profiler; + +public class Profiler { + + + public static final int UNPACK = 1; + public static final int SEG_UNPACK = 2; + public static final int SEG_PARSESEG = 3; + + public static final int SEGHEADER_UNPACK = 5; + public static final int ADB_UNPACK = 6; + public static final int BCBANDS_UNPACK = 7; + public static final int BCBANDS_UNPACK_PARSE1 = 20; + public static final int BCBANDS_UNPACK_PARSE2 = 21; + public static final int BCBANDS_UNPACK_SELECT = 22; + public static final int BCBANDS_UNPACK_ATTRLAYOUT = 23; + public static final int BCBANDS_UNPACK_METHODS = 24; + public static final int CBANDS_UNPACK = 8; + public static final int CBANDS_UNPACK_FIELDS = 25; + public static final int CBANDS_UNPACK_METHODS = 26; + public static final int CBANDS_UNPACK_CLASSATTR = 27; + public static final int CBANDS_UNPACK_CODE = 28; + + public static final int CPBANDS_UNPACK = 9; + public static final int FBANDS_UNPACK = 10; + public static final int ICBANDS_UNPACK = 11; + + public static final int SEG_WRITEJAR = 4; + public static final int SEG_BUILDCF = 12; + public static final int SEG_BUILDCF_SFATTR = 29; + public static final int SEG_BUILDCF_CFATTR = 30; + public static final int SEG_BUILDCF_INTF = 31; + public static final int SEG_BUILDCF_FIELDS = 32; + public static final int SEG_BUILDCF_METHODS = 33; + public static final int SEG_BUILDCF_ADDNESTED = 34; + public static final int SEG_BUILDCF_INNER = 35; + public static final int SEG_BUILDCF_FINAL = 36; + public static final int CLASSF_WRITE = 13; + public static final int CLASSF_WRITE_CP = 15; + public static final int CLASSF_WRITE_INTF = 16; + public static final int CLASSF_WRITE_FIELDS = 17; + public static final int CLASSF_WRITE_METHODS = 18; + public static final int CLASSF_WRITE_ATTR = 19; + + public static final int SEG_WRITEPRIM = 14; + + + + + + private static int length = 50; + private static long[] startTimes = new long[length]; + private static long[] sumTimes = new long[length]; + + static { + for(int i = 0; i < length; i++) { + startTimes[i] = -1; + } + } + + + public static void markStart(int event) { + if (startTimes[event] != -1) { + System.err.println("Missed event: " + event); + } + startTimes[event] = getTime(); + } + + public static void markStop(int event) { + sumTimes[event] += getTime() - startTimes[event]; + startTimes[event] = -1; + } + + public static void printStats() { + System.out.println("Unpack: " + sumTimes[UNPACK]); + System.out.println(" segment unpack: " + sumTimes[SEG_UNPACK]); + System.out.println(" parse segment: " + sumTimes[SEG_PARSESEG]); + System.out.println(" parse header: " + sumTimes[SEGHEADER_UNPACK]); + System.out.println(" parse ADB: " + sumTimes[ADB_UNPACK]); + System.out.println(" parse bcbands: " + sumTimes[BCBANDS_UNPACK]); + System.out.println(" parse1: " + sumTimes[BCBANDS_UNPACK_PARSE1]); + System.out.println(" parse2: " + sumTimes[BCBANDS_UNPACK_PARSE2]); + System.out.println(" select: " + sumTimes[BCBANDS_UNPACK_SELECT]); + System.out.println(" attrlayout: " + sumTimes[BCBANDS_UNPACK_ATTRLAYOUT]); + System.out.println(" methods: " + sumTimes[BCBANDS_UNPACK_METHODS]); + System.out.println(" parse cbands: " + sumTimes[CBANDS_UNPACK]); + System.out.println(" classattr: " + sumTimes[CBANDS_UNPACK_CLASSATTR]); + System.out.println(" code: " + sumTimes[CBANDS_UNPACK_CODE]); + System.out.println(" fields: " + sumTimes[CBANDS_UNPACK_FIELDS]); + System.out.println(" methods: " + sumTimes[CBANDS_UNPACK_METHODS]); + System.out.println(" parse cpbands: " + sumTimes[CPBANDS_UNPACK]); + System.out.println(" parse fbands: " + sumTimes[FBANDS_UNPACK]); + System.out.println(" parse icbands: " + sumTimes[ICBANDS_UNPACK]); + System.out.println(" write jar: " + sumTimes[SEG_WRITEJAR]); + System.out.println(" build classf: " + sumTimes[SEG_BUILDCF]); + System.out.println(" sfattrs: " + sumTimes[SEG_BUILDCF_SFATTR]); + System.out.println(" cfattrs: " + sumTimes[SEG_BUILDCF_CFATTR]); + System.out.println(" fields: " + sumTimes[SEG_BUILDCF_FIELDS]); + System.out.println(" interfaces: " + sumTimes[SEG_BUILDCF_INTF]); + System.out.println(" methods: " + sumTimes[SEG_BUILDCF_METHODS]); + System.out.println(" addNested: " + sumTimes[SEG_BUILDCF_ADDNESTED]); + System.out.println(" inner: " + sumTimes[SEG_BUILDCF_INNER]); + System.out.println(" final: " + sumTimes[SEG_BUILDCF_FINAL]); + System.out.println(" write classf: " + sumTimes[CLASSF_WRITE]); + System.out.println(" constpool: " + sumTimes[CLASSF_WRITE_CP]); + System.out.println(" interfaces: " + sumTimes[CLASSF_WRITE_INTF]); + System.out.println(" attributes: " + sumTimes[CLASSF_WRITE_ATTR]); + System.out.println(" methods: " + sumTimes[CLASSF_WRITE_METHODS]); + System.out.println(" fields: " + sumTimes[CLASSF_WRITE_FIELDS]); + System.out.println(" write primit: " + sumTimes[SEG_WRITEPRIM]); + } + + private static long getTime() { + return System.currentTimeMillis(); + } + +} + Property changes on: src\main\java\org\apache\harmony\pack200\profiler\Profiler.java ___________________________________________________________________ Name: svn:keywords + Date Author Revision URL Id Index: src/main/java/org/apache/harmony/unpack200/Segment.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/Segment.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/Segment.java (working copy) @@ -33,6 +33,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; import org.apache.harmony.unpack200.bytecode.Attribute; import org.apache.harmony.unpack200.bytecode.CPClass; import org.apache.harmony.unpack200.bytecode.CPField; @@ -98,6 +99,7 @@ private PrintWriter logStream; private ClassFile buildClassFile(int classNum) throws Pack200Exception { + Profiler.markStart(Profiler.SEG_BUILDCF); ClassFile classFile = new ClassFile(); classFile.major = header.getDefaultClassMajorVersion(); // TODO If // classVersionMajor[] use @@ -105,6 +107,8 @@ classFile.minor = header.getDefaultClassMinorVersion(); // TODO if // classVersionMinor[] use // that instead + + // build constant pool ClassConstantPool cp = classFile.pool; int fullNameIndexInCpClass = classBands.getClassThisInts()[classNum]; @@ -113,7 +117,8 @@ int i = fullName.lastIndexOf("/") + 1; // if lastIndexOf==-1, then // -1+1=0, so str.substring(0) // == str - + + Profiler.markStart(Profiler.SEG_BUILDCF_SFATTR); // Get the source file attribute ArrayList classAttributes = classBands.getClassAttributes()[classNum]; SourceFileAttribute sourceFileAttribute = null; @@ -152,7 +157,9 @@ classFile.attributes = new Attribute[] { (Attribute) cp .add(sourceFileAttribute) }; } + Profiler.markStop(Profiler.SEG_BUILDCF_SFATTR); + Profiler.markStart(Profiler.SEG_BUILDCF_CFATTR); // If we see any class attributes, add them to the class's attributes // that will // be written out. Keep SourceFileAttributes out since we just @@ -176,11 +183,14 @@ cp.add(attrib); classFile.attributes[originalAttributes.length + index] = attrib; } + Profiler.markStop(Profiler.SEG_BUILDCF_CFATTR); // this/superclass ClassFileEntry cfThis = cp.add(cpBands.cpClassValue(fullNameIndexInCpClass)); ClassFileEntry cfSuper = cp.add(cpBands.cpClassValue(classBands .getClassSuperInts()[classNum])); + + Profiler.markStart(Profiler.SEG_BUILDCF_INTF); // add interfaces ClassFileEntry cfInterfaces[] = new ClassFileEntry[classBands .getClassInterfacesInts()[classNum].length]; @@ -188,6 +198,9 @@ cfInterfaces[i] = cp.add(cpBands.cpClassValue(classBands .getClassInterfacesInts()[classNum][i])); } + Profiler.markStop(Profiler.SEG_BUILDCF_INTF); + + Profiler.markStart(Profiler.SEG_BUILDCF_FIELDS); // add fields ClassFileEntry cfFields[] = new ClassFileEntry[classBands .getClassFieldCount()[classNum]]; @@ -202,7 +215,10 @@ .getFieldFlags()[classNum][i], classBands .getFieldAttributes()[classNum][i])); } - // add methods + Profiler.markStop(Profiler.SEG_BUILDCF_FIELDS); + + Profiler.markStart(Profiler.SEG_BUILDCF_METHODS); + // add methods ClassFileEntry cfMethods[] = new ClassFileEntry[classBands .getClassMethodCount()[classNum]]; // methodDescr and methodFlags used to create this @@ -217,8 +233,13 @@ .getMethodFlags()[classNum][i], classBands .getMethodAttributes()[classNum][i])); } + Profiler.markStop(Profiler.SEG_BUILDCF_METHODS); + + Profiler.markStart(Profiler.SEG_BUILDCF_ADDNESTED); cp.addNestedEntries(); + Profiler.markStop(Profiler.SEG_BUILDCF_ADDNESTED); + Profiler.markStart(Profiler.SEG_BUILDCF_INNER); // add inner class attribute (if required) boolean addInnerClassesAttr = false; IcTuple[] ic_local = getClassBands().getIcLocal()[classNum]; @@ -283,6 +304,9 @@ classFile.attributes = newAttrs; cp.addWithNestedEntries(innerClassesAttribute); } + Profiler.markStop(Profiler.SEG_BUILDCF_INNER); + + Profiler.markStart(Profiler.SEG_BUILDCF_FINAL); // sort CP according to cp_All cp.resolve(this); // NOTE the indexOf is only valid after the cp.resolve() @@ -297,6 +321,8 @@ } classFile.fields = cfFields; classFile.methods = cfMethods; + Profiler.markStop(Profiler.SEG_BUILDCF_FINAL); + Profiler.markStop(Profiler.SEG_BUILDCF); return classFile; } @@ -366,6 +392,7 @@ */ private void parseSegment(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.SEG_PARSESEG); log(LOG_LEVEL_VERBOSE, "-------"); header = new SegmentHeader(this); header.unpack(in); @@ -381,6 +408,7 @@ bcBands.unpack(in); fileBands = new FileBands(this); fileBands.unpack(in); + Profiler.markStop(Profiler.SEG_PARSESEG); } /** @@ -394,10 +422,12 @@ */ public void unpack(InputStream in, JarOutputStream out) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.SEG_UNPACK); if (!in.markSupported()) in = new BufferedInputStream(in); parseSegment(in); writeJar(out); + Profiler.markStop(Profiler.SEG_UNPACK); } /** @@ -416,6 +446,7 @@ */ public void writeJar(JarOutputStream out) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.SEG_WRITEJAR); fileBands.processFileBits(); BufferedOutputStream buffer = new BufferedOutputStream(out); DataOutputStream dos = new DataOutputStream(buffer); @@ -459,14 +490,17 @@ dos.flush(); classNum++; } else { + Profiler.markStart(Profiler.SEG_WRITEPRIM); long size = fileSize[i]; entry.setSize(size); // TODO pull from in byte[] data = fileBits[i]; out.write(data); + Profiler.markStop(Profiler.SEG_WRITEPRIM); } } dos.flush(); + Profiler.markStop(Profiler.SEG_WRITEJAR); } public SegmentConstantPool getConstantPool() { Index: src/main/java/org/apache/harmony/unpack200/IcBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/IcBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/IcBands.java (working copy) @@ -24,6 +24,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; import org.apache.harmony.unpack200.bytecode.CPClass; import org.apache.harmony.unpack200.bytecode.ClassConstantPool; @@ -53,6 +54,8 @@ * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream) */ public void unpack(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.ICBANDS_UNPACK); + // Read IC bands int innerClassCount = header.getInnerClassCount(); int[] icThisClassInts = decodeBandInt("ic_this_class", in, @@ -102,6 +105,7 @@ } icAll[i] = new IcTuple(icTupleC, icTupleF, icTupleC2, icTupleN, cIndex, c2Index, nIndex); } + Profiler.markStop(Profiler.ICBANDS_UNPACK); } public IcTuple[] getIcTuples() { Index: src/main/java/org/apache/harmony/unpack200/CpBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/CpBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/CpBands.java (working copy) @@ -23,6 +23,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; import org.apache.harmony.unpack200.bytecode.CPClass; import org.apache.harmony.unpack200.bytecode.CPDouble; import org.apache.harmony.unpack200.bytecode.CPFieldRef; @@ -99,6 +100,8 @@ } public void unpack(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.CPBANDS_UNPACK); + parseCpUtf8(in); parseCpInt(in); parseCpFloat(in); @@ -123,6 +126,8 @@ fieldOffset = descrOffset + cpDescriptor.length; methodOffset = fieldOffset + cpFieldClass.length; imethodOffset = methodOffset + cpMethodClass.length; + + Profiler.markStop(Profiler.CPBANDS_UNPACK); } /** Index: src/main/java/org/apache/harmony/unpack200/SegmentHeader.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/SegmentHeader.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/SegmentHeader.java (working copy) @@ -24,6 +24,7 @@ import org.apache.harmony.pack200.BHSDCodec; import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; /** * SegmentHeader is the header band of a {@link Segment} @@ -96,6 +97,7 @@ public void unpack(InputStream in) throws IOException, Pack200Exception, Error, Pack200Exception { + Profiler.markStart(Profiler.SEGHEADER_UNPACK); long word[] = decodeScalar("archive_magic_word", in, Codec.BYTE1, magic.length); for (int m = 0; m < magic.length; m++) @@ -117,6 +119,7 @@ readFully(in, bandHeaders); setBandHeadersData(bandHeaders); } + Profiler.markStop(Profiler.SEGHEADER_UNPACK); } /** Index: src/main/java/org/apache/harmony/unpack200/ClassBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/ClassBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/ClassBands.java (working copy) @@ -24,6 +24,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; import org.apache.harmony.unpack200.bytecode.Attribute; import org.apache.harmony.unpack200.bytecode.CPClass; import org.apache.harmony.unpack200.bytecode.CPNameAndType; @@ -134,6 +135,7 @@ * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream) */ public void unpack(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.CBANDS_UNPACK); int classCount = header.getClassCount(); classThisInts = decodeBandInt("class_this", in, Codec.DELTA5, classCount); classThis = getReferences(classThisInts, cpBands.getCpClass()); @@ -147,11 +149,23 @@ classCount); classMethodCount = decodeBandInt("class_method_count", in, Codec.DELTA5, classCount); + Profiler.markStart(Profiler.CBANDS_UNPACK_FIELDS); parseFieldBands(in); + Profiler.markStop(Profiler.CBANDS_UNPACK_FIELDS); + + Profiler.markStart(Profiler.CBANDS_UNPACK_METHODS); parseMethodBands(in); + Profiler.markStop(Profiler.CBANDS_UNPACK_METHODS); + + Profiler.markStart(Profiler.CBANDS_UNPACK_CLASSATTR); parseClassAttrBands(in); + Profiler.markStop(Profiler.CBANDS_UNPACK_CLASSATTR); + + Profiler.markStart(Profiler.CBANDS_UNPACK_CODE); parseCodeBands(in); - + Profiler.markStop(Profiler.CBANDS_UNPACK_CODE); + + Profiler.markStop(Profiler.CBANDS_UNPACK); } private void parseFieldBands(InputStream in) throws IOException, Index: src/main/java/org/apache/harmony/unpack200/bytecode/ClassFile.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/bytecode/ClassFile.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/bytecode/ClassFile.java (working copy) @@ -19,6 +19,8 @@ import java.io.DataOutputStream; import java.io.IOException; +import org.apache.harmony.pack200.profiler.Profiler; + /** * ClassFile is used to represent and write out Java class files. */ @@ -37,10 +39,13 @@ public Attribute[] attributes; public void write(DataOutputStream dos) throws IOException { + Profiler.markStart(Profiler.CLASSF_WRITE); dos.writeInt(magic); dos.writeShort(minor); dos.writeShort(major); dos.writeShort(pool.size() + 1); + + Profiler.markStart(Profiler.CLASSF_WRITE_CP); for (int i = 1; i <= pool.size(); i++) { ConstantPoolEntry entry; (entry = (ConstantPoolEntry) pool.get(i)).doWrite(dos); @@ -50,24 +55,41 @@ || entry.getTag() == ConstantPoolEntry.CP_Long) i++; } + Profiler.markStop(Profiler.CLASSF_WRITE_CP); + dos.writeShort(accessFlags); dos.writeShort(thisClass); dos.writeShort(superClass); + + Profiler.markStart(Profiler.CLASSF_WRITE_INTF); dos.writeShort(interfaces.length); for (int i = 0; i < interfaces.length; i++) { dos.writeShort(interfaces[i]); } + Profiler.markStop(Profiler.CLASSF_WRITE_INTF); + + Profiler.markStart(Profiler.CLASSF_WRITE_FIELDS); dos.writeShort(fields.length); for (int i = 0; i < fields.length; i++) { fields[i].write(dos); } + Profiler.markStop(Profiler.CLASSF_WRITE_FIELDS); + + Profiler.markStart(Profiler.CLASSF_WRITE_METHODS); dos.writeShort(methods.length); for (int i = 0; i < methods.length; i++) { methods[i].write(dos); } + Profiler.markStop(Profiler.CLASSF_WRITE_METHODS); + + Profiler.markStart(Profiler.CLASSF_WRITE_ATTR); dos.writeShort(attributes.length); for (int i = 0; i < attributes.length; i++) { attributes[i].write(dos); } + Profiler.markStop(Profiler.CLASSF_WRITE_ATTR); + + Profiler.markStop(Profiler.CLASSF_WRITE); } + } Index: src/main/java/org/apache/harmony/unpack200/Archive.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/Archive.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/Archive.java (working copy) @@ -30,6 +30,7 @@ import java.util.zip.GZIPInputStream; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; /** * Archive is the main entry point to unpack200. An archive is constructed with @@ -96,6 +97,8 @@ * @throws IOException */ public void unpack() throws Pack200Exception, IOException { + Profiler.markStart(Profiler.UNPACK); + outputStream.setComment("PACK200"); try { if (!inputStream.markSupported()) { @@ -190,6 +193,9 @@ throw new Pack200Exception("Failed to delete the input file."); } } + + Profiler.markStop(Profiler.UNPACK); + Profiler.printStats(); } private boolean available(InputStream inputStream) throws IOException { Index: src/main/java/org/apache/harmony/unpack200/FileBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/FileBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/FileBands.java (working copy) @@ -21,6 +21,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; /** * Parses the file band headers (not including the actual bits themselves). At @@ -59,6 +60,7 @@ * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream) */ public void unpack(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.FBANDS_UNPACK); int numberOfFiles = header.getNumberOfFiles(); SegmentOptions options = header.getOptions(); @@ -80,10 +82,12 @@ } this.in = in; // store for use by processFileBits(), which is called // later + + Profiler.markStop(Profiler.FBANDS_UNPACK); } // TODO: stream the file bits directly somehow - public void processFileBits() throws IOException, Pack200Exception { + public void processFileBits() throws IOException, Pack200Exception { // now read in the bytes int numberOfFiles = header.getNumberOfFiles(); fileBits = new byte[numberOfFiles][]; @@ -97,7 +101,7 @@ throw new Pack200Exception("Expected to read " + size + " bytes but read " + read); } - } + } } public byte[][] getFileBits() { Index: src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java (working copy) @@ -21,6 +21,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; /** * Attribute definition bands are the set of bands used to define extra @@ -49,6 +50,8 @@ * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream) */ public void unpack(InputStream in) throws IOException, Pack200Exception { + Profiler.markStart(Profiler.ADB_UNPACK); + int attributeDefinitionCount = header.getAttributeDefinitionCount(); attributeDefinitionHeader = decodeBandInt("attr_definition_headers", in, Codec.BYTE1, attributeDefinitionCount); @@ -76,6 +79,8 @@ attributeDefinitionMap.add(layout, newBands); } attributeDefinitionMap.checkMap(); + + Profiler.markStop(Profiler.ADB_UNPACK); } public AttributeLayoutMap getAttributeDefinitionMap() { Index: src/main/java/org/apache/harmony/unpack200/BcBands.java =================================================================== --- src/main/java/org/apache/harmony/unpack200/BcBands.java (revision 675615) +++ src/main/java/org/apache/harmony/unpack200/BcBands.java (working copy) @@ -25,6 +25,7 @@ import org.apache.harmony.pack200.Codec; import org.apache.harmony.pack200.Pack200Exception; +import org.apache.harmony.pack200.profiler.Profiler; import org.apache.harmony.unpack200.bytecode.Attribute; import org.apache.harmony.unpack200.bytecode.BCIRenumberedAttribute; import org.apache.harmony.unpack200.bytecode.ByteCode; @@ -83,7 +84,7 @@ * @see org.apache.harmony.unpack200.BandSet#unpack(java.io.InputStream) */ public void unpack(InputStream in) throws IOException, Pack200Exception { - + Profiler.markStart(Profiler.BCBANDS_UNPACK); AttributeLayoutMap attributeDefinitionMap = segment .getAttrDefinitionBands().getAttributeDefinitionMap(); int classCount = header.getClassCount(); @@ -116,6 +117,7 @@ int bcEscCount = 0; int bcEscRefCount = 0; + Profiler.markStart(Profiler.BCBANDS_UNPACK_ATTRLAYOUT); AttributeLayout abstractModifier = attributeDefinitionMap .getAttributeLayout(AttributeLayout.ACC_ABSTRACT, AttributeLayout.CONTEXT_METHOD); @@ -125,6 +127,8 @@ AttributeLayout staticModifier = attributeDefinitionMap .getAttributeLayout(AttributeLayout.ACC_STATIC, AttributeLayout.CONTEXT_METHOD); + Profiler.markStop(Profiler.BCBANDS_UNPACK_ATTRLAYOUT); + methodByteCodePacked = new byte[classCount][][]; int bcParsed = 0; @@ -137,16 +141,24 @@ long methodFlag = methodFlags[c][m]; if (!abstractModifier.matches(methodFlag) && !nativeModifier.matches(methodFlag)) { + + Profiler.markStart(Profiler.BCBANDS_UNPACK_PARSE1); ByteArrayOutputStream codeBytes = new ByteArrayOutputStream(); byte code; while ((code = (byte) (0xff & in.read())) != -1) codeBytes.write(code); methodByteCodePacked[c][m] = codeBytes.toByteArray(); bcParsed += methodByteCodePacked[c][m].length; + Profiler.markStop(Profiler.BCBANDS_UNPACK_PARSE1); + + Profiler.markStart(Profiler.BCBANDS_UNPACK_PARSE2); int[] codes = new int[methodByteCodePacked[c][m].length]; for (int i = 0; i < codes.length; i++) { codes[i] = methodByteCodePacked[c][m][i] & 0xff; } + Profiler.markStop(Profiler.BCBANDS_UNPACK_PARSE2); + + Profiler.markStart(Profiler.BCBANDS_UNPACK_SELECT); for (int i = 0; i < methodByteCodePacked[c][m].length; i++) { int codePacked = 0xff & methodByteCodePacked[c][m][i]; switch (codePacked) { @@ -299,6 +311,7 @@ } } } + Profiler.markStop(Profiler.BCBANDS_UNPACK_SELECT); } } } @@ -388,6 +401,7 @@ int[][] handlerClassTypes = segment.getClassBands() .getCodeHandlerClassRCN(); + Profiler.markStart(Profiler.BCBANDS_UNPACK_METHODS); for (int c = 0; c < classCount; c++) { int numberOfMethods = methodFlags[c].length; for (int m = 0; m < numberOfMethods; m++) { @@ -457,6 +471,8 @@ } } } + Profiler.markStop(Profiler.BCBANDS_UNPACK_METHODS); + Profiler.markStop(Profiler.BCBANDS_UNPACK); } private boolean startsWithIf(int codePacked) {