harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r1002186 - in /harmony/enhanced/java/branches/java6/classlib/modules/pack200/src: main/java/org/apache/harmony/pack200/ test/java/org/apache/harmony/pack200/tests/
Date Tue, 28 Sep 2010 14:43:39 GMT
Author: sjanuary
Date: Tue Sep 28 14:43:38 2010
New Revision: 1002186

URL: http://svn.apache.org/viewvc?rev=1002186&view=rev
Log:
Pack200 - pack support for the Java 6 StackMapTable class file attribute

Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
  (contents, props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
  (contents, props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
  (contents, props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
  (contents, props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
  (contents, props changed)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
  (contents, props changed)

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
Tue Sep 28 14:43:38 2010
@@ -438,14 +438,13 @@ public class BcBands extends BandSet {
             bcLabelRelativeOffsets.add(byteCodeOffset);
         }
         int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
-        byteCodeOffset += padding + 8 + 8 * keys.length;
+        byteCodeOffset += 1 + padding + 8 + 8 * keys.length;
         updateRenumbering();
     }
 
     public void visitMethodInsn(int opcode, String owner, String name,
             String desc) {
         byteCodeOffset += 3;
-        updateRenumbering();
         switch (opcode) {
         case 182: // invokevirtual
         case 183: // invokespecial
@@ -495,11 +494,13 @@ public class BcBands extends BandSet {
             bcCodes.add(opcode);
             break;
         case 185: // invokeinterface
+            byteCodeOffset += 2;
             CPMethodOrField cpIMethod = cpBands.getCPIMethod(owner, name, desc);
             bcIMethodRef.add(cpIMethod);
             bcCodes.add(INVOKEINTERFACE);
             break;
         }
+        updateRenumbering();
     }
 
     public void visitMultiANewArrayInsn(String desc, int dimensions) {
@@ -522,7 +523,7 @@ public class BcBands extends BandSet {
             bcLabel.add(labels[i]);
             bcLabelRelativeOffsets.add(byteCodeOffset);
         }
-        int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
+        int padding = byteCodeOffset % 4 == 0 ? 0 : 4 - (byteCodeOffset % 4);
         byteCodeOffset+= (padding + 12 + 4 * labels.length);
         updateRenumbering();
     }
@@ -579,4 +580,8 @@ public class BcBands extends BandSet {
         updateRenumbering();
     }
 
+    public int getByteCodeOffset() {
+        return byteCodeOffset;
+    }
+
 }

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
Tue Sep 28 14:43:38 2010
@@ -100,6 +100,15 @@ public class ClassBands extends BandSet 
     private final List codeLocalVariableTypeTableTypeRS = new ArrayList();
     private final IntList codeLocalVariableTypeTableSlot = new IntList();
 
+    private final IntList codeStackMapTableN = new IntList();
+    private final IntList codeStackMapTableFrameT = new IntList();
+    private final IntList codeStackMapTableLocalN = new IntList();
+    private final IntList codeStackMapTableStackN = new IntList();
+    private final IntList codeStackMapTableOffset = new IntList();
+    private final IntList codeStackMapTableT = new IntList();
+    private final List codeStackMapTableRC = new ArrayList();
+    private final List codeStackMapTableP = new ArrayList();
+
     private final MetadataBandGroup class_RVA_bands;
     private final MetadataBandGroup class_RIA_bands;
     private final MetadataBandGroup field_RVA_bands;
@@ -864,6 +873,65 @@ public class ClassBands extends BandSet 
                         + " bytes from code_attr_calls["
                         + code_attr_calls.length + "]");
 
+        encodedBand = encodeBandInt("code_StackMapTable_N",
+                codeStackMapTableN.toArray(), Codec.UNSIGNED5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_N["
+                + codeStackMapTableN.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_frame_T",
+                codeStackMapTableFrameT.toArray(), Codec.BYTE1);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_frame_T["
+                + codeStackMapTableFrameT.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_local_N",
+                codeStackMapTableLocalN.toArray(), Codec.UNSIGNED5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_local_N["
+                + codeStackMapTableLocalN.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_stack_N",
+                codeStackMapTableStackN.toArray(), Codec.UNSIGNED5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_stack_N["
+                + codeStackMapTableStackN.size() + "]");
+
+        encodedBand = encodeBandInt("code_StackMapTable_offset",
+                codeStackMapTableOffset.toArray(), Codec.UNSIGNED5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_offset["
+                + codeStackMapTableOffset.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_T",
+                codeStackMapTableT.toArray(), Codec.BYTE1);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_T["
+                + codeStackMapTableT.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_RC",
+                cpBands.cpEntryListToArray(codeStackMapTableRC),
+                Codec.UNSIGNED5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_RC["
+                + codeStackMapTableRC.size() + "]");
+        encodedBand = encodeBandInt("code_StackMapTable_P",
+                cpBands.integerListToArray(codeStackMapTableP), Codec.BCI5);
+        out.write(encodedBand);
+        PackingUtils.log("Wrote " + encodedBand.length
+                + " bytes from code_StackMapTable_P["
+                + codeStackMapTableP.size() + "]");
+//        *code_StackMapTable_N :UNSIGNED5 [COUNT(StackMapTable,...)]
+//        *code_StackMapTable_frame_T :BYTE1 [SUM(*code_StackMapTable_N)]
+//        *code_StackMapTable_local_N :UNSIGNED5 [COUNT(255,*code_StackMapTable_frame_T)]
+//        *code_StackMapTable_stack_N :UNSIGNED5 [COUNT(255,*code_StackMapTable_frame_T)]
+//        *code_StackMapTable_offset :UNSIGNED5 [...]
+//        *code_StackMapTable_T :BYTE1 [...]
+//        *code_StackMapTable_RC :UNSIGNED5 [COUNT(7,*code_StackMapTable_T)]
+//        *code_StackMapTable_P :BCI5 [COUNT(8,*code_StackMapTable_T)]
+
         encodedBand = encodeBandInt("code_LineNumberTable_N",
                 codeLineNumberTableN.toArray(), Codec.UNSIGNED5);
         out.write(encodedBand);
@@ -1256,6 +1324,83 @@ public class ClassBands extends BandSet 
         codeLocalVariableTableSlot.add(indx);
     }
 
+    public void addStackMapTableFrame(int frameType, int offset, int nLocal, Object[] local,
int nStack,
+            Object[] stack) {
+        Long latestCodeFlag = (Long) codeFlags.get(codeFlags.size() - 1);
+        if ((latestCodeFlag.intValue() & 1) == 0) {
+            codeFlags.remove(codeFlags.size() - 1);
+            codeFlags.add(new Long(latestCodeFlag.intValue() | 1));
+            codeStackMapTableN.add(1);
+        } else {
+            codeStackMapTableN
+                    .increment(codeStackMapTableN.size() - 1);
+        }
+        boolean hasLocals = false;
+        boolean hasStack = false;
+        if(frameType == Opcodes.F_SAME) {
+            if(offset > 63) {
+                codeStackMapTableFrameT.add(251);
+                codeStackMapTableOffset.add(offset);
+            } else {
+                codeStackMapTableFrameT.add(offset);
+            }
+        } else if (frameType == Opcodes.F_SAME1) {
+            hasStack = true;
+            if(offset + 64 > 127) {
+                codeStackMapTableFrameT.add(247);
+                codeStackMapTableOffset.add(offset);
+            } else {
+                codeStackMapTableFrameT.add(offset + 64);
+            }
+        } else if (frameType == Opcodes.F_CHOP) {
+            codeStackMapTableFrameT.add(251 - nLocal);
+            codeStackMapTableOffset.add(offset);
+        }  else if (frameType == Opcodes.F_APPEND) {
+            codeStackMapTableFrameT.add(251 + nLocal);
+            codeStackMapTableOffset.add(offset);
+            hasLocals = true;
+        } else if (frameType == Opcodes.F_FULL) {
+            codeStackMapTableFrameT.add(255);
+            codeStackMapTableOffset.add(offset);
+            codeStackMapTableLocalN.add(nLocal);
+            codeStackMapTableStackN.add(nStack);
+            hasLocals = true;
+            hasStack = true;
+        }
+        if(hasLocals) {
+            for (int i = 0; i < nLocal; i++) {
+                Object localItem = local[i];
+                if(localItem instanceof Integer) {
+                    codeStackMapTableT.add(((Integer) localItem).intValue());
+                } else if (localItem == null) {
+                    codeStackMapTableT.add(5);
+                } else if (localItem instanceof String) {
+                    codeStackMapTableT.add(7);
+                    codeStackMapTableRC.add(cpBands.getCPClass((String) localItem));
+                } else if (localItem instanceof Label) {
+                    codeStackMapTableT.add(8);
+                    codeStackMapTableP.add(localItem);
+                }
+            }
+        }
+        if(hasStack) {
+            for (int i = 0; i < nStack; i++) {
+                Object stackItem = stack[i];
+                if(stackItem instanceof Integer) {
+                    codeStackMapTableT.add(((Integer)stackItem).intValue());
+                } else if (stackItem == null) {
+                    codeStackMapTableT.add(5);
+                } else if (stackItem instanceof String) {
+                    codeStackMapTableT.add(7);
+                    codeStackMapTableRC.add(cpBands.getCPClass((String) stackItem));
+                } else if (stackItem instanceof Label) {
+                    codeStackMapTableT.add(8);
+                    codeStackMapTableP.add(stackItem);
+                }
+            }
+        }
+    }
+
     public void doBciRenumbering(IntList bciRenumbering, Map labelsToOffsets) {
         renumberBci(codeLineNumberTableBciP, bciRenumbering, labelsToOffsets);
         renumberBci(codeLocalVariableTableBciP, bciRenumbering, labelsToOffsets);
@@ -1271,7 +1416,7 @@ public class ClassBands extends BandSet 
                 bciRenumbering, labelsToOffsets);
         renumberDoubleOffsetBci(codeHandlerStartP, codeHandlerEndPO, codeHandlerCatchPO,
                 bciRenumbering, labelsToOffsets);
-
+        renumberBci(codeStackMapTableP, bciRenumbering, labelsToOffsets);
         for (Iterator iterator = classAttributeBands.iterator(); iterator.hasNext();) {
             NewAttributeBands newAttributeBandSet = (NewAttributeBands) iterator.next();
             newAttributeBandSet.renumberBci(bciRenumbering, labelsToOffsets);

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
Tue Sep 28 14:43:38 2010
@@ -51,6 +51,7 @@ public class CpBands extends BandSet {
     private final Set cp_Imethod = new TreeSet();
 
     private final Map stringsToCpUtf8 = new HashMap();
+    private final Map stringsToCpString = new HashMap();
     private final Map stringsToCpNameAndType = new HashMap();
     private final Map stringsToCpClass = new HashMap();
     private final Map stringsToCpSignature = new HashMap();
@@ -71,6 +72,7 @@ public class CpBands extends BandSet {
         defaultAttributeNames.add("RuntimeVisibleParameterAnnotations");
         defaultAttributeNames.add("RuntimeInvisibleParameterAnnotations");
         defaultAttributeNames.add("Code");
+        defaultAttributeNames.add("StackMapTable");
         defaultAttributeNames.add("LineNumberTable");
         defaultAttributeNames.add("LocalVariableTable");
         defaultAttributeNames.add("LocalVariableTypeTable");
@@ -475,7 +477,7 @@ public class CpBands extends BandSet {
     private void removeCpUtf8(String string) {
         CPUTF8 utf8 = (CPUTF8) stringsToCpUtf8.get(string);
         if (utf8 != null) {
-            if(stringsToCpClass.get(string) == null) { // don't remove if strings are also
in cpclass
+            if(stringsToCpClass.get(string) == null && stringsToCpString.get(string)
== null) { // don't remove if strings are also in cpclass
                 stringsToCpUtf8.remove(string);
                 cp_Utf8.remove(utf8);
             }
@@ -623,6 +625,7 @@ public class CpBands extends BandSet {
             } else if (value instanceof String) {
                 constant = new CPString(getCPUtf8((String) value));
                 cp_String.add(constant);
+                stringsToCpString.put(value, constant);
             } else if (value instanceof Type) {
                 String className = ((Type) value).getClassName();
                 if(className.endsWith("[]")) {

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
Tue Sep 28 14:43:38 2010
@@ -267,6 +267,8 @@ public class Segment implements ClassVis
      */
     public class SegmentMethodVisitor implements MethodVisitor {
 
+        private int previousFrameLocation;
+
         public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
             return new SegmentAnnotationVisitor(
                     MetadataBandGroup.CONTEXT_METHOD, desc, visible);
@@ -318,12 +320,14 @@ public class Segment implements ClassVis
 
         public void visitCode() {
             classBands.addCode();
+            previousFrameLocation = 0;
         }
 
-        public void visitFrame(int arg0, int arg1, Object[] arg2, int arg3,
-                Object[] arg4) {
-            // TODO: Java 6 - implement support for this
-
+        public void visitFrame(int type, int nLocal, Object[] local,
+                int nStack, Object[] stack) {
+            int offset = bcBands.getByteCodeOffset();
+            classBands.addStackMapTableFrame(type, offset - previousFrameLocation, nLocal,
local, nStack, stack);
+            previousFrameLocation = offset + 1;
         }
 
         public void visitLabel(Label label) {
@@ -537,14 +541,14 @@ public class Segment implements ClassVis
             values.add(value);
         }
     }
-    
+
     public class ArrayVisitor implements AnnotationVisitor  {
-        
-        private int indexInCaseArrayN;
-        private List caseArrayN;
-        private List values;
-        private List nameRU;
-        private List T;
+
+        private final int indexInCaseArrayN;
+        private final List caseArrayN;
+        private final List values;
+        private final List nameRU;
+        private final List T;
 
         public ArrayVisitor(List caseArrayN, List T, List nameRU, List values) {
             this.caseArrayN = caseArrayN;
@@ -553,7 +557,7 @@ public class Segment implements ClassVis
             this.values = values;
             this.indexInCaseArrayN = caseArrayN.size() - 1;
         }
-        
+
         public void visit(String name, Object value) {
             Integer numCases = (Integer) caseArrayN.remove(indexInCaseArrayN);
             caseArrayN.add(indexInCaseArrayN, new Integer(numCases.intValue() + 1));

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
Tue Sep 28 14:43:38 2010
@@ -34,8 +34,8 @@ public class SegmentHeader extends BandS
     }
 
     private static final int[] magic = { 0xCA, 0xFE, 0xD0, 0x0D };
-    private static final int archive_minver = 7;
-    private static final int archive_majver = 150;
+    private static int archive_minver = 7;
+    private static int archive_majver = 150;
 
     private int archive_options;
 
@@ -292,6 +292,10 @@ public class SegmentHeader extends BandS
 
     public void addMajorVersion(int major) {
         majverCounter.add(major);
+        if(major >= 50) {
+            archive_majver = 160;
+            archive_minver = 1;
+        }
     }
 
     /**

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=1002186&r1=1002185&r2=1002186&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
Tue Sep 28 14:43:38 2010
@@ -298,6 +298,29 @@ public class ArchiveTest extends TestCas
 		}
     }
 
+    public void testJava6ClassFiles() throws IOException, Pack200Exception, URISyntaxException
{
+        // pack
+        in = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/pack200-java6.jar").toURI()));
+        file = File.createTempFile("p200-java6", ".pack");
+        file.deleteOnExit();
+        out = new FileOutputStream(file);
+        PackingOptions options = new PackingOptions();
+        options.setGzip(false);
+        Archive ar = new Archive(in, out, options);
+        ar.pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("p200-java6out", ".jar");
+        file2.deleteOnExit();
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2,
out2);
+        archive.unpack();
+    }
+
     private void compareJarEntries(JarFile jarFile, JarFile jarFile2)
             throws IOException {
         Enumeration entries = jarFile.entries();

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message