harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r738901 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/ test/resources/org/apache/harmony/pack200/tests/
Date Thu, 29 Jan 2009 15:55:16 GMT
Author: sjanuary
Date: Thu Jan 29 15:55:15 2009
New Revision: 738901

URL: http://svn.apache.org/viewvc?rev=738901&view=rev
Log:
Pack200 - code and a test for strip debug option

Added:
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpackedNoDebug.jar
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=738901&r1=738900&r2=738901&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
Thu Jan 29 15:55:15 2009
@@ -43,6 +43,7 @@
     private JarFile jarFile;
     private long segmentLimit = 1000000;
     private long currentSegmentSize;
+    private boolean stripDebug;
 
     public Archive(JarInputStream inputStream, OutputStream outputStream,
             boolean gzip) throws IOException {
@@ -63,6 +64,10 @@
         segmentLimit = limit;
     }
 
+    public void stripDebugAttributes() {
+        stripDebug = true;
+    }
+
     public void pack() throws Pack200Exception, IOException {
         List classes = new ArrayList();
         List files = new ArrayList();
@@ -82,7 +87,7 @@
                 if (!added) { // not added because segment has reached
                     // maximum size
                     if(classes.size() > 0 || files.size() > 0) {
-                        new Segment().pack(classes, files, outputStream);
+                        new Segment().pack(classes, files, outputStream, stripDebug);
                         classes = new ArrayList();
                         files = new ArrayList();
                         currentSegmentSize = 0;
@@ -94,7 +99,7 @@
                     }
                 } else if (segmentLimit == 0) {
                     // create a new segment for each class
-                    new Segment().pack(classes, files, outputStream);
+                    new Segment().pack(classes, files, outputStream, stripDebug);
                     classes = new ArrayList();
                     files = new ArrayList();
                 }
@@ -108,7 +113,7 @@
                         jarFile.getInputStream(jarEntry)), classes, files);
                 if (!added) { // not added because segment has reached maximum
                     // size
-                    new Segment().pack(classes, files, outputStream);
+                    new Segment().pack(classes, files, outputStream, stripDebug);
                     classes = new ArrayList();
                     files = new ArrayList();
                     currentSegmentSize = 0;
@@ -118,14 +123,14 @@
                     }
                 } else if (segmentLimit == 0) {
                     // create a new segment for each class
-                    new Segment().pack(classes, files, outputStream);
+                    new Segment().pack(classes, files, outputStream, stripDebug);
                     classes = new ArrayList();
                     files = new ArrayList();
                 }
             }
         }
         if(classes.size() > 0 || files.size() > 0) {
-            new Segment().pack(classes, files, outputStream);
+            new Segment().pack(classes, files, outputStream, stripDebug);
         }
         outputStream.close();
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=738901&r1=738900&r2=738901&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
Thu Jan 29 15:55:15 2009
@@ -240,7 +240,7 @@
             }
         }
         // Calculate code headers
-        codeHeaders = new int[codeFlags.size()];
+        codeHeaders = new int[codeHandlerCount.size()];
         int removed = 0;
         for (int i = 0; i < codeHeaders.length; i++) {
             int numHandlers = ((Integer) codeHandlerCount.get(i - removed))
@@ -271,6 +271,8 @@
                 codeMaxLocals.remove(i - removed);
                 codeMaxStack.remove(i - removed);
                 removed++;
+            } else if (!segment.getSegmentHeader().have_all_code_flags()) {
+                codeFlags.add(new Long(0));
             }
         }
 
@@ -590,6 +592,18 @@
         }
     }
 
+    public void endOfMethod() {
+        if(codeFlags.size() > 0) {
+            long latestCodeFlag = ((Long)codeFlags.get(codeFlags.size() - 1)).longValue();
+            int latestLocalVariableTableN = ((Integer)codeLocalVariableTableN.get(codeLocalVariableTableN.size()
- 1)).intValue();
+            if(latestCodeFlag == (1 << 2) && latestLocalVariableTableN == 0)
{
+                codeLocalVariableTableN.remove(codeLocalVariableTableN.size() - 1);
+                codeFlags.remove(codeFlags.size() - 1);
+                codeFlags.add(new Integer(0));
+            }
+        }
+    }
+
     protected static int countArgs(String descriptor) {
         int bra = descriptor.indexOf('(');
         int ket = descriptor.indexOf(')');
@@ -699,10 +713,12 @@
         codeMaxLocals.add(new Integer(maxLocals));
     }
 
-    public void addCode() {
+    public void addCode(boolean stripDebug) {
         codeHandlerCount.add(ZERO);
-        codeFlags.add(new Long((1 << 2))); // TODO: What if there's no debug information?
-        codeLocalVariableTableN.add(new Integer(0));
+        if(!stripDebug) {
+            codeFlags.add(new Long((1 << 2))); // TODO: What if there's no debug information?
+            codeLocalVariableTableN.add(new Integer(0));
+        }
     }
 
     public void addHandler(Label start, Label end, Label handler, String type) {

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=738901&r1=738900&r2=738901&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
Thu Jan 29 15:55:15 2009
@@ -43,11 +43,14 @@
     private final SegmentFieldVisitor fieldVisitor = new SegmentFieldVisitor();
     private final SegmentMethodVisitor methodVisitor = new SegmentMethodVisitor();
     private Pack200ClassReader currentClassReader;
+    private boolean stripDebug;
 
-    public void pack(List classes, List files, OutputStream out)
+    public void pack(List classes, List files, OutputStream out, boolean stripDebug)
             throws IOException, Pack200Exception {
+        this.stripDebug = stripDebug;
         segmentHeader = new SegmentHeader();
         segmentHeader.setFile_count(files.size());
+        segmentHeader.setHave_all_code_flags(!stripDebug);
         cpBands = new CpBands(this);
         attributeDefinitionBands = new AttributeDefinitionBands(this);
         icBands = new IcBands(segmentHeader, cpBands);
@@ -93,7 +96,9 @@
     }
 
     public void visitSource(String source, String debug) {
-        classBands.addSourceFile(source);
+        if(!stripDebug) {
+            classBands.addSourceFile(source);
+        }
     }
 
     public void visitOuterClass(String owner, String name, String desc) {
@@ -150,7 +155,7 @@
         }
 
         public void visitCode() {
-            classBands.addCode();
+            classBands.addCode(stripDebug);
         }
 
         public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3,
@@ -164,13 +169,17 @@
         }
 
         public void visitLineNumber(int line, Label start) {
-            classBands.addLineNumber(line, start);
+            if(!stripDebug) {
+                classBands.addLineNumber(line, start);
+            }
         }
 
         public void visitLocalVariable(String name, String desc,
                 String signature, Label start, Label end, int index) {
-            classBands.addLocalVariable(name, desc, signature, start, end,
-                    index);
+            if(!stripDebug) {
+                classBands.addLocalVariable(name, desc, signature, start, end,
+                        index);
+            }
         }
 
         public void visitMaxs(int maxStack, int maxLocals) {
@@ -189,6 +198,7 @@
         }
 
         public void visitEnd() {
+            classBands.endOfMethod();
             bcBands.visitEnd();
         }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=738901&r1=738900&r2=738901&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
Thu Jan 29 15:55:15 2009
@@ -369,4 +369,8 @@
         return have_file_options;
     }
 
+    public boolean have_all_code_flags() {
+        return have_all_code_flags;
+    }
+
 }
\ No newline at end of file

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=738901&r1=738900&r2=738901&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Thu Jan 29 15:55:15 2009
@@ -195,6 +195,35 @@
         out.close();
     }
 
+    public void testStripDebug() throws IOException, Pack200Exception, URISyntaxException
{
+        in = new JarInputStream(Archive.class
+                .getResourceAsStream("/org/apache/harmony/pack200/tests/sqlUnpacked.jar"));
+        file = File.createTempFile("sql", ".pack");
+        out = new FileOutputStream(file);
+        Archive archive = new Archive(in, out, false);
+        archive.stripDebugAttributes();
+        archive.pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("sqloutNoDebug", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive u2archive = new org.apache.harmony.unpack200.Archive(in2,
out2);
+        u2archive.unpack();
+
+        File compareFile = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpackedNoDebug.jar").toURI());
+        JarFile jarFile = new JarFile(file2);
+        assertTrue(file2.length() < 250000);
+        file2.deleteOnExit();
+
+        JarFile jarFile2 = new JarFile(compareFile);
+
+        compareFiles(jarFile, jarFile2);
+    }
+
     public void testAnnotations() throws IOException, Pack200Exception,
             URISyntaxException {
         in = new JarInputStream(

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpackedNoDebug.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpackedNoDebug.jar?rev=738901&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/sqlUnpackedNoDebug.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream



Mime
View raw message