You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by zh...@apache.org on 2009/07/01 12:13:30 UTC

svn commit: r790097 [2/2] - in /harmony/enhanced: classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=790097&r1=790096&r2=790097&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Wed Jul  1 10:13:29 2009
@@ -24,6 +24,7 @@
 import java.util.List;
 
 import org.apache.harmony.pack200.Archive.File;
+import org.apache.harmony.pack200.Archive.SegmentUnit;
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
 import org.objectweb.asm.ClassReader;
@@ -52,7 +53,7 @@
     private PackingOptions options;
     private boolean stripDebug;
     private Attribute[] nonStandardAttributePrototypes;
-
+    
     /**
      * The main method on Segment. Reads in all the class files, packs them and
      * then writes the packed segment out to the given OutputStream.
@@ -69,23 +70,41 @@
      * @throws IOException
      * @throws Pack200Exception
      */
-    public void pack(List classes, List files, OutputStream out, PackingOptions options)
+    public void pack(SegmentUnit segmentUnit, OutputStream out, PackingOptions options)
             throws IOException, Pack200Exception {
         this.options = options;
         this.stripDebug = options.isStripDebug();
         int effort = options.getEffort();
         nonStandardAttributePrototypes = options.getUnknownAttributePrototypes();
+        
+        PackingUtils.log("Start to pack a new segment with "
+                + segmentUnit.fileListSize() + " files including "
+                + segmentUnit.classListSize() + " classes");
+        
+        PackingUtils.log("Initialize a header for the segment");
         segmentHeader = new SegmentHeader();
-        segmentHeader.setFile_count(files.size());
+        segmentHeader.setFile_count(segmentUnit.fileListSize());
         segmentHeader.setHave_all_code_flags(!stripDebug);
+        
+        PackingUtils.log("Setup constant pool bands for the segment");
         cpBands = new CpBands(this, effort);
+        
+        PackingUtils.log("Setup attribute definition bands for the segment");
         attributeDefinitionBands = new AttributeDefinitionBands(this, effort, nonStandardAttributePrototypes);
+        
+        PackingUtils.log("Setup internal class bands for the segment");
         icBands = new IcBands(segmentHeader, cpBands, effort);
-        classBands = new ClassBands(this, classes.size(), effort, stripDebug);
+        
+        PackingUtils.log("Setup class bands for the segment");
+        classBands = new ClassBands(this, segmentUnit.classListSize(), effort, stripDebug);
+        
+        PackingUtils.log("Setup byte code bands for the segment");
         bcBands = new BcBands(cpBands, this, effort);
-        fileBands = new FileBands(cpBands, segmentHeader, options, files, classes, effort);
+        
+        PackingUtils.log("Setup file bands for the segment");
+        fileBands = new FileBands(cpBands, segmentHeader, options, segmentUnit, effort);
 
-        processClasses(classes, files);
+        processClasses(segmentUnit);
 
         cpBands.finaliseBands();
         attributeDefinitionBands.finaliseBands();
@@ -98,22 +117,35 @@
         // before segmentHeader because the band_headers band is only created
         // when the other bands are packed, but comes before them in the packed
         // file.
-        ByteArrayOutputStream tempStream = new ByteArrayOutputStream();
+        ByteArrayOutputStream bandsOutputStream = new ByteArrayOutputStream();
 
-        cpBands.pack(tempStream);
-        attributeDefinitionBands.pack(tempStream);
-        icBands.pack(tempStream);
-        classBands.pack(tempStream);
-        bcBands.pack(tempStream);
-        fileBands.pack(tempStream);
-
-        segmentHeader.pack(out);
-        tempStream.writeTo(out);
-    }
-
-    private void processClasses(List classes, List files) throws Pack200Exception {
-        segmentHeader.setClass_count(classes.size());
-        for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
+        PackingUtils.log("Packing...");
+        cpBands.pack(bandsOutputStream);
+        attributeDefinitionBands.pack(bandsOutputStream);
+        icBands.pack(bandsOutputStream);
+        classBands.pack(bandsOutputStream);
+        bcBands.pack(bandsOutputStream);
+        fileBands.pack(bandsOutputStream);
+
+        ByteArrayOutputStream headerOutputStream = new ByteArrayOutputStream();
+        segmentHeader.pack(headerOutputStream);
+
+        headerOutputStream.writeTo(out);
+        bandsOutputStream.writeTo(out);
+        
+        segmentUnit.addPackedByteAmount(headerOutputStream.size());
+        segmentUnit.addPackedByteAmount(bandsOutputStream.size());
+        
+        PackingUtils.log("Wrote total of " + segmentUnit.getPackedByteAmount()
+                + " bytes");
+        PackingUtils.log("Transmitted " + segmentUnit.fileListSize() + " files of "
+                + segmentUnit.getByteAmount() + " input bytes in a segment of "
+                + segmentUnit.getPackedByteAmount() + " bytes");
+    }
+
+    private void processClasses(SegmentUnit segmentUnit) throws Pack200Exception {
+        segmentHeader.setClass_count(segmentUnit.classListSize());
+        for (Iterator iterator = segmentUnit.getClassList().iterator(); iterator.hasNext();) {
             Pack200ClassReader classReader = (Pack200ClassReader) iterator
                     .next();
             currentClassReader = classReader;
@@ -129,7 +161,7 @@
                 classBands.removeCurrentClass();
                 String name = classReader.getFileName();
                 boolean found = false;
-                for (Iterator iterator2 = files.iterator(); iterator2
+                for (Iterator iterator2 = segmentUnit.getFileList().iterator(); iterator2
                         .hasNext();) {
                     File file = (File) iterator2.next();
                     if(file.getName().equals(name)) {

Modified: harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java?rev=790097&r1=790096&r2=790097&view=diff
==============================================================================
--- harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java (original)
+++ harmony/enhanced/jdktools/trunk/modules/jretools/src/main/java/org/apache/harmony/jretools/pack200/Main.java Wed Jul  1 10:13:29 2009
@@ -124,18 +124,31 @@
                 options.setQuiet(true);
                 options.setVerbose(false);
             } else if (args[i].startsWith("-l")) {
-                options.setLogFile(args[i].substring(2));
+                String logFileName = args[i].substring(2);
+                if (logFileName.length() == 0) {
+                    if (i + 1 < args.length) {
+                        logFileName = args[++i];
+                    } else {
+                        printErrorMessage("Bad argument: -l ?");
+                        printUsage();
+                        return;
+                    }
+                }
+                options.setLogFile(logFileName);
+            } else if (args[i].startsWith("--log-file=")) {
+                options.setLogFile(args[i].substring(11));
             } else if ("-r".equals(args[i]) || "--repack".equals(args[i])) {
                 options.setRepack(true);
             } else if (args[i].startsWith("-f")) {
                 String packPropertyFileName = args[i].substring(2);
-                if (packPropertyFileName.length() > 0) {
-                } else if (i + 1 < args.length) {
-                    packPropertyFileName = args[++i];
-                } else {
-                    printErrorMessage("Bad argument: -f ?");
-                    printUsage();
-                    return;
+                if (packPropertyFileName.length() == 0) {
+                    if (i + 1 < args.length) {
+                        packPropertyFileName = args[++i];
+                    } else {
+                        printErrorMessage("Bad argument: -f ?");
+                        printUsage();
+                        return;
+                    }
                 }
                 loadPackProperties(packPropertyFileName, options);
             } else if (args[i].startsWith("--config-file=")) {