harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r999824 - in /harmony/enhanced/java/branches/java6/classlib/modules/pack200/src: main/java/org/apache/harmony/unpack200/ main/java/org/apache/harmony/unpack200/bytecode/ test/java/org/apache/harmony/unpack200/tests/ test/resources/org/apach...
Date Wed, 22 Sep 2010 09:12:21 GMT
Author: sjanuary
Date: Wed Sep 22 09:12:20 2010
New Revision: 999824

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

Added:
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java
  (with props)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java
  (with props)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.jar
  (with props)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.pack.gz
  (with props)
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/pack200-java6.jar
  (with props)
Modified:
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayout.java
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayoutMap.java
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
    harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttrDefinitionBands.java
Wed Sep 22 09:12:20 2010
@@ -33,6 +33,7 @@ import org.apache.harmony.unpack200.byte
 import org.apache.harmony.unpack200.bytecode.LocalVariableTypeTableAttribute;
 import org.apache.harmony.unpack200.bytecode.SignatureAttribute;
 import org.apache.harmony.unpack200.bytecode.SourceFileAttribute;
+import org.apache.harmony.unpack200.bytecode.StackMapTableAttribute;
 
 /**
  * Attribute definition bands are the set of bands used to define extra
@@ -108,6 +109,7 @@ public class AttrDefinitionBands extends
         LocalVariableTypeTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("LocalVariableTypeTable"));
//$NON-NLS-1$
         SignatureAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("Signature"));
//$NON-NLS-1$
         SourceFileAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("SourceFile"));
//$NON-NLS-1$
+        StackMapTableAttribute.setAttributeName(segment.getCpBands().cpUTF8Value("StackMapTable"));
//$NON-NLS-1$
         MetadataBandGroup.setRvaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleAnnotations"));
         MetadataBandGroup.setRiaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeInvisibleAnnotations"));
         MetadataBandGroup.setRvpaAttributeName(segment.getCpBands().cpUTF8Value("RuntimeVisibleParameterAnnotations"));

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayout.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayout.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayout.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayout.java
Wed Sep 22 09:12:20 2010
@@ -52,6 +52,7 @@ public class AttributeLayout implements 
     public static final String ATTRIBUTE_LINE_NUMBER_TABLE = "LineNumberTable"; //$NON-NLS-1$
     public static final String ATTRIBUTE_LOCAL_VARIABLE_TABLE = "LocalVariableTable"; //$NON-NLS-1$
     public static final String ATTRIBUTE_LOCAL_VARIABLE_TYPE_TABLE = "LocalVariableTypeTable";
//$NON-NLS-1$
+    public static final String ATTRIBUTE_STACK_MAP_TABLE = "StackMapTable"; //$NON-NLS-1$
     public static final String ATTRIBUTE_RUNTIME_INVISIBLE_ANNOTATIONS = "RuntimeInvisibleAnnotations";
//$NON-NLS-1$
     public static final String ATTRIBUTE_RUNTIME_INVISIBLE_PARAMETER_ANNOTATIONS = "RuntimeInvisibleParameterAnnotations";
//$NON-NLS-1$
     public static final String ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS = "RuntimeVisibleAnnotations";
//$NON-NLS-1$

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayoutMap.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayoutMap.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayoutMap.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/AttributeLayoutMap.java
Wed Sep 22 09:12:20 2010
@@ -42,6 +42,8 @@ public class AttributeLayoutMap {
                         AttributeLayout.CONTEXT_FIELD, "", 0),
                 new AttributeLayout(AttributeLayout.ACC_PUBLIC,
                         AttributeLayout.CONTEXT_METHOD, "", 0),
+                new AttributeLayout(AttributeLayout.ATTRIBUTE_STACK_MAP_TABLE,
+                        AttributeLayout.CONTEXT_CODE, "*", 0),
                 new AttributeLayout(AttributeLayout.ACC_PRIVATE,
                         AttributeLayout.CONTEXT_CLASS, "", 1),
                 new AttributeLayout(AttributeLayout.ACC_PRIVATE,

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
Wed Sep 22 09:12:20 2010
@@ -37,6 +37,7 @@ import org.apache.harmony.unpack200.byte
 import org.apache.harmony.unpack200.bytecode.LocalVariableTypeTableAttribute;
 import org.apache.harmony.unpack200.bytecode.SignatureAttribute;
 import org.apache.harmony.unpack200.bytecode.SourceFileAttribute;
+import org.apache.harmony.unpack200.bytecode.StackMapTableAttribute;
 
 /**
  * Class Bands
@@ -116,6 +117,8 @@ public class ClassBands extends BandSet 
 
     private boolean [] codeHasAttributes;
 
+    private StackMapTableBands stackMapTableBands;
+
     /**
      * @param segment
      */
@@ -822,6 +825,76 @@ public class ClassBands extends BandSet 
         int[] codeAttrCalls = decodeBandInt("code_attr_calls", in,
                 Codec.UNSIGNED5, callCount);
 
+        boolean hasStackMapTables = segment.getSegmentHeader()
+                .getArchiveMajor() > 150;
+        AttributeLayout stackMapTableLayout = attrMap.getAttributeLayout(
+                AttributeLayout.ATTRIBUTE_STACK_MAP_TABLE,
+                AttributeLayout.CONTEXT_CODE);
+        if (hasStackMapTables) {
+            int stackMapTableCount = SegmentUtils.countMatches(codeFlags,
+                    stackMapTableLayout);
+            int[] stackMapTableN = decodeBandInt("code_StackMapTable_N", in,
+                    Codec.UNSIGNED5, stackMapTableCount);
+            int[][] stackMapTableFrameT = decodeBandInt(
+                    "code_StackMapTable_frame_T", in, Codec.BYTE1,
+                    stackMapTableN);
+            int count255 = 0;
+            int offsetCount = 0;
+            int verificationTypeInfoCount = 0;
+            for (int i = 0; i < stackMapTableFrameT.length; i++) {
+                for (int j = 0; j < stackMapTableFrameT[i].length; j++) {
+                    int tag = stackMapTableFrameT[i][j];
+                    if (tag == 255) {
+                        count255++;
+                        offsetCount++;
+                    } else if (tag >= 247 && tag <= 254) {
+                        offsetCount++;
+                    }
+                    if (tag >= 64 && tag <= 127) {
+                        verificationTypeInfoCount++;
+                    } else if (tag == 247 || tag == 252) {
+                        verificationTypeInfoCount++;
+                    } else if (tag == 253) {
+                        verificationTypeInfoCount += 2;
+                    } else if (tag == 254) {
+                        verificationTypeInfoCount += 3;
+                    }
+                }
+            }
+            int[] stackMapTableLocalN = decodeBandInt(
+                    "code_StackMapTable_local_N", in, Codec.UNSIGNED5, count255);
+            int[] stackMapTableStackN = decodeBandInt(
+                    "code_StackMapTable_stack_N", in, Codec.UNSIGNED5, count255);
+            for (int i = 0; i < stackMapTableLocalN.length; i++) {
+                verificationTypeInfoCount += stackMapTableLocalN[i];
+            }
+            for (int i = 0; i < stackMapTableStackN.length; i++) {
+                verificationTypeInfoCount += stackMapTableStackN[i];
+            }
+            int[] stackMapTableOffset = decodeBandInt(
+                    "code_StackMapTable_offset", in, Codec.UNSIGNED5,
+                    offsetCount);
+            int[] stackMapTableT = decodeBandInt("", in, Codec.BYTE1,
+                    verificationTypeInfoCount);
+            int sevenCount = 0;
+            int eightCount = 0;
+            for (int i = 0; i < stackMapTableT.length; i++) {
+                if (stackMapTableT[i] == 7) {
+                    sevenCount++;
+                } else if (stackMapTableT[i] == 8) {
+                    eightCount++;
+                }
+            }
+            CPClass[] stackMapTableRC = parseCPClassReferences(
+                    "code_StackMapTable_RC", in, Codec.UNSIGNED5, sevenCount);
+            int[] stackMapTableP = decodeBandInt("code_StackMapTable_P", in,
+                    Codec.BCI5, eightCount);
+            stackMapTableBands = new StackMapTableBands(stackMapTableFrameT,
+                    stackMapTableLocalN, stackMapTableStackN,
+                    stackMapTableOffset, stackMapTableT, stackMapTableRC,
+                    stackMapTableP);
+        }
+
         AttributeLayout lineNumberTableLayout = attrMap.getAttributeLayout(
                 AttributeLayout.ATTRIBUTE_LINE_NUMBER_TABLE,
                 AttributeLayout.CONTEXT_CODE);
@@ -919,6 +992,10 @@ public class ClassBands extends BandSet 
         int lvtIndex = 0;
         int lvttIndex = 0;
         for (int i = 0; i < codeFlagsCount; i++) {
+            if(hasStackMapTables && stackMapTableLayout.matches(codeFlags[i])) {
+                StackMapTableAttribute smta = stackMapTableBands.nextStackMapTableAttribute();
+                codeAttributes[i].add(smta);
+            }
             if (lineNumberTableLayout.matches(codeFlags[i])) {
                 LineNumberTableAttribute lnta = new LineNumberTableAttribute(
                         lineNumberTableN[lineNumberIndex],
@@ -959,7 +1036,6 @@ public class ClassBands extends BandSet 
                 }
             }
         }
-
     }
 
     private int parseFieldMetadataBands(InputStream in, int[] fieldAttrCalls)
@@ -1118,7 +1194,7 @@ public class ClassBands extends BandSet 
         int backwardsCallsUsed = 0;
         String[] RxA = new String[] { "RVA", "RIA", "RVPA", "RIPA", "AD" };
         int[] rxaCounts = new int[] { 0, 0, 0, 0, 0 };
-        
+
         AttributeLayout rvaLayout = attrMap.getAttributeLayout(
                 AttributeLayout.ATTRIBUTE_RUNTIME_VISIBLE_ANNOTATIONS,
                 AttributeLayout.CONTEXT_METHOD);

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/SegmentHeader.java
Wed Sep 22 09:12:20 2010
@@ -141,7 +141,7 @@ public class SegmentHeader {
      *             if the minor version is not 7
      */
     private void setArchiveMinorVersion(int version) throws Pack200Exception {
-        if (version != 7)
+        if (version != 7 && version != 1)
             throw new Pack200Exception("Invalid segment minor version");
         archiveMinor = version;
     }
@@ -155,12 +155,16 @@ public class SegmentHeader {
      *             if the major version is not 150
      */
     private void setArchiveMajorVersion(int version) throws Pack200Exception {
-        if (version != 150)
+        if (version != 150 && version != 160)
             throw new Pack200Exception("Invalid segment major version: "
                     + version);
         archiveMajor = version;
     }
 
+    public int getArchiveMajor() {
+        return archiveMajor;
+    }
+
     public long getArchiveModtime() {
         return archiveModtime;
     }

Added: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java?rev=999824&view=auto
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java
(added)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java
Wed Sep 22 09:12:20 2010
@@ -0,0 +1,126 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.unpack200;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.harmony.unpack200.bytecode.CPClass;
+import org.apache.harmony.unpack200.bytecode.StackMapTableAttribute;
+
+/**
+ * Set of bands that hold data about StackMapTable attributes
+ */
+public class StackMapTableBands {
+
+    private final int[][] frameT;
+    private int frameTIndex;
+
+    private final int[] localN;
+    private int localNIndex;
+
+    private final int[] stackN;
+    private int stackNIndex;
+
+    private final int[] offset;
+    private int offsetIndex;
+
+    private final int[] t;
+    int tIndex = 0;
+
+    private final CPClass[] rc;
+    private int rcIndex;
+
+    private final int[] p;
+    private int pIndex;
+
+    public StackMapTableBands(
+            int[][] frameT, int[] localN,
+            int[] stackN, int[] offset,
+            int[] t, CPClass[] rc,
+            int[] p) {
+        this.frameT = frameT;
+        this.localN = localN;
+        this.stackN = stackN;
+        this.offset = offset;
+        this.t = t;
+        this.rc = rc;
+        this.p = p;
+    }
+
+    public StackMapTableAttribute nextStackMapTableAttribute() {
+        List frames = new ArrayList();
+
+        for (int i = 0; i < frameT[frameTIndex].length; i++) {
+            int frameType = frameT[frameTIndex][i];
+            StackMapTableAttribute.Frame frame = new StackMapTableAttribute.Frame(frameType);
+            if(frameType >= 64 && frameType <= 127) {
+                List stack = new ArrayList();
+                stack.add(getNextVerificationTypeInfo());
+                frame.setStack(stack);
+            } else if (frameType == 247) {
+                frame.setOffsetDelta(offset[offsetIndex++]);
+                List stack = new ArrayList();
+                stack.add(getNextVerificationTypeInfo());
+                frame.setStack(stack);
+            } else if (frameType >= 248 && frameType <= 251) {
+                frame.setOffsetDelta(offset[offsetIndex++]);
+            } else if (frameType >= 252 && frameType <= 254) {
+                frame.setOffsetDelta(offset[offsetIndex++]);
+                List locals = new ArrayList();
+                int numLocals = frameType -251;
+                for (int j = 0; j < numLocals; j++) {
+                    locals.add(getNextVerificationTypeInfo());
+                }
+                frame.setLocals(locals);
+            } else if (frameType == 255) {
+                frame.setOffsetDelta(offset[offsetIndex++]);
+                List locals = new ArrayList();
+                int numLocals = localN[localNIndex++];
+                for (int j = 0; j < numLocals; j++) {
+                    locals.add(getNextVerificationTypeInfo());
+                }
+                frame.setLocals(locals);
+                List stack = new ArrayList();
+                int numberOnStack = stackN[stackNIndex++];
+                for (int j = 0; j < numberOnStack; j++) {
+                    stack.add(getNextVerificationTypeInfo());
+                }
+                frame.setStack(stack);
+            }
+            frames.add(frame);
+        }
+
+        StackMapTableAttribute stackMapTableAttribute = new StackMapTableAttribute(frames);
+        frameTIndex++;
+        return stackMapTableAttribute;
+    }
+
+    private StackMapTableAttribute.VerificationTypeInfo getNextVerificationTypeInfo() {
+        int tag = t[tIndex++];
+        if(tag == 7) {
+            CPClass classRef = rc[rcIndex++];
+            return new StackMapTableAttribute.VerificationTypeInfo(tag, classRef);
+        } else if (tag == 8) {
+            int offset = p[pIndex++];
+            return new StackMapTableAttribute.VerificationTypeInfo(tag, offset);
+        } else {
+            return new StackMapTableAttribute.VerificationTypeInfo(tag);
+        }
+    }
+
+}

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/StackMapTableBands.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java?rev=999824&view=auto
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java
(added)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java
Wed Sep 22 09:12:20 2010
@@ -0,0 +1,299 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.unpack200.bytecode;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.harmony.pack200.Pack200Exception;
+
+/**
+ * StackMapTable attribute
+ */
+public class StackMapTableAttribute extends BCIRenumberedAttribute {
+
+    private static CPUTF8 attributeName;
+
+    private final List frames;
+
+    public static void setAttributeName(CPUTF8 cpUTF8Value) {
+        attributeName = cpUTF8Value;
+    }
+
+    public StackMapTableAttribute(List frames) {
+        super(attributeName);
+        this.frames = frames;
+    }
+
+    public String toString() {
+        return "StackMapTableAttribute";
+    }
+
+    protected int getLength() {
+        int length = 2;
+        for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
+            Frame frame = (Frame) iterator.next();
+            length += frame.getLength();
+        }
+        return length;
+    }
+
+    protected void writeBody(DataOutputStream dos) throws IOException {
+        dos.writeShort(frames.size());
+        for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
+            Frame frame = (Frame) iterator.next();
+            frame.writeBody(dos);
+        }
+    }
+
+    protected void resolve(ClassConstantPool pool) {
+        super.resolve(pool);
+        for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
+            Frame frame = (Frame) iterator.next();
+            frame.resolve(pool);
+        }
+    }
+
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        List classFileEntries = new ArrayList();
+        classFileEntries.add(attributeName);
+        for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
+            Frame frame = (Frame) iterator.next();
+            classFileEntries.addAll(frame.getNestedClassFileEntries());
+        }
+        ClassFileEntry[] entries = new ClassFileEntry[classFileEntries.size()];
+        for (int i = 0; i < entries.length; i++) {
+            entries[i] = (ClassFileEntry) classFileEntries.get(i);
+        }
+        return entries;
+    }
+
+    protected int[] getStartPCs() {
+        // Don't do anything here because we've overridden renumber.
+        return null;
+    }
+
+    public void renumber(List byteCodeOffsets) throws Pack200Exception {
+        for (Iterator iterator = frames.iterator(); iterator.hasNext();) {
+            Frame frame = (Frame) iterator.next();
+            frame.renumber(byteCodeOffsets);
+        }
+    }
+
+    public static class Frame {
+
+        private final int frameType;
+        private int offsetDelta;
+        private List locals;
+        private List stack;
+
+        public Frame(int frameType) {
+            this.frameType = frameType;
+        }
+
+        public void setOffsetDelta(int offsetDelta) {
+            this.offsetDelta = offsetDelta;
+        }
+
+        public void setLocals(List locals) {
+            this.locals = locals;
+        }
+
+        public void setStack(List stack) {
+            this.stack = stack;
+        }
+
+        protected void resolve(ClassConstantPool pool) {
+            if (locals != null) {
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    info.resolve(pool);
+                }
+            }
+            if (stack != null) {
+                for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    info.resolve(pool);
+                }
+            }
+        }
+
+        public int getLength() {
+            int length = 0;
+            if (frameType <= 63) {
+                length = 1;
+            } else if (frameType <= 127) {
+                VerificationTypeInfo info = (VerificationTypeInfo) stack.get(0);
+                length = 1 + info.getLength();
+            } else if (frameType == 247) {
+                VerificationTypeInfo info = (VerificationTypeInfo) stack.get(0);
+                length = 3 + info.getLength();
+            } else if (frameType >= 248 && frameType <= 251) {
+                length = 3;
+            } else if (frameType >= 252 && frameType <= 254) {
+                length = 3;
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    length += info.getLength();
+                }
+            } else if (frameType == 255) {
+                length = 7;
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    length += info.getLength();
+                }
+                for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    length += info.getLength();
+                }
+            }
+            return length;
+        }
+
+        public void renumber(List byteCodeOffsets) {
+            if(locals != null) {
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    if(info.tag == 8) {
+                        info.offset = ((Integer)byteCodeOffsets.get(info.offset)).intValue();
+                    }
+                }
+            }
+            if(stack != null) {
+                for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    if(info.tag == 8) {
+                        info.offset = ((Integer)byteCodeOffsets.get(info.offset)).intValue();
+                    }
+                }
+            }
+        }
+
+        public List getNestedClassFileEntries() {
+            List nested = new ArrayList();
+            if(locals != null) {
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator.next();
+                    if(info.cpClass != null) {
+                        nested.add(info.cpClass);
+                    }
+                }
+            }
+            if(stack != null) {
+                for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator.next();
+                    if(info.cpClass != null) {
+                        nested.add(info.cpClass);
+                    }
+                }
+            }
+            return nested;
+        }
+
+        public void writeBody(DataOutputStream dos) throws IOException {
+            dos.writeByte(frameType);
+            if (frameType >= 64 && frameType <= 127) {
+                VerificationTypeInfo info = (VerificationTypeInfo) stack.get(0);
+                info.writeBody(dos);
+            } else if (frameType == 247) {
+                dos.writeShort(offsetDelta);
+                VerificationTypeInfo info = (VerificationTypeInfo) stack.get(0);
+                info.writeBody(dos);
+            } else if (frameType >= 248 && frameType <= 251) {
+                dos.writeShort(offsetDelta);
+            } else if (frameType >= 252 && frameType <= 254) {
+                dos.writeShort(offsetDelta);
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    info.writeBody(dos);
+                }
+            } else if (frameType == 255) {
+                dos.writeShort(offsetDelta);
+                dos.writeShort(locals.size());
+                for (Iterator iterator = locals.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    info.writeBody(dos);
+                }
+                dos.writeShort(stack.size());
+                for (Iterator iterator = stack.iterator(); iterator.hasNext();) {
+                    VerificationTypeInfo info = (VerificationTypeInfo) iterator
+                            .next();
+                    info.writeBody(dos);
+                }
+            }
+        }
+    }
+
+    public static class VerificationTypeInfo {
+
+        private final int tag;
+        private final int length;
+        private int offset;
+        private CPClass cpClass;
+        private int cpClassIndex;
+
+        public VerificationTypeInfo(int tag) {
+            this.tag = tag;
+            length = 1;
+        }
+
+        public VerificationTypeInfo(int tag, CPClass cpClass) {
+            this.tag = tag;
+            this.cpClass = cpClass;
+            length = 3;
+        }
+
+        public VerificationTypeInfo(int tag, int offset) {
+            this.tag = tag;
+            this.offset = offset;
+            length = 3;
+        }
+
+        public int getLength() {
+            return length;
+        }
+
+        public void writeBody(DataOutputStream dos) throws IOException {
+            dos.writeByte(tag);
+            if (tag == 7) {
+                dos.writeShort(cpClassIndex);
+            } else if (tag == 8) {
+                dos.writeShort(offset);
+            }
+        }
+
+        protected void resolve(ClassConstantPool pool) {
+            if(cpClass != null) {
+                cpClass.resolve(pool);
+                cpClassIndex = pool.indexOf(cpClass);
+            }
+        }
+    }
+
+}
\ No newline at end of file

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/StackMapTableAttribute.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java?rev=999824&r1=999823&r2=999824&view=diff
==============================================================================
--- harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
(original)
+++ harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/java/org/apache/harmony/unpack200/tests/ArchiveTest.java
Wed Sep 22 09:12:20 2010
@@ -26,6 +26,7 @@ import java.io.FileReader;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.URISyntaxException;
 import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
@@ -74,23 +75,22 @@ public class ArchiveTest extends TestCas
         out = new JarOutputStream(new FileOutputStream(file));
         Archive archive = new Archive(in, out);
         archive.unpack();
-        JarFile jarFile = new JarFile(file);
 
         File compareFile = new File(Archive.class.getResource(
                 "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI());
 
-        JarFile jarFile2 = new JarFile(compareFile);
 
-        long differenceInJarSizes = Math.abs(compareFile.length()
-                - file.length());
+        compareFiles(compareFile, file);
+    }
 
-        assertTrue("Expected jar files to be a similar size, difference was "
-                + differenceInJarSizes + " bytes", differenceInJarSizes < 100);
+    private void compareFiles(File expected, File theFile) throws URISyntaxException,
+            IOException {
 
+        JarFile jarFile = new JarFile(theFile);
+        JarFile jarFile2 = new JarFile(expected);
         Enumeration entries = jarFile.entries();
         Enumeration entries2 = jarFile2.entries();
         while(entries.hasMoreElements() && entries2.hasMoreElements()) {
-
             JarEntry entry = (JarEntry) entries.nextElement();
             assertNotNull(entry);
             String name = entry.getName();
@@ -101,23 +101,26 @@ public class ArchiveTest extends TestCas
 
             assertEquals(name, name2);
 
-            InputStream ours = jarFile.getInputStream(entry);
-            InputStream expected = jarFile2.getInputStream(entry2);
+            if(name.indexOf('$') == -1) { // We're not quite identical for inner classes
+
+                InputStream ours = jarFile.getInputStream(entry);
+                InputStream expectedStr = jarFile2.getInputStream(entry2);
 
-            BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
-            BufferedReader reader2 = new BufferedReader(new InputStreamReader(
-                    expected));
-            String line1 = reader1.readLine();
-            String line2 = reader2.readLine();
-            int i = 1;
-            while (line1 != null || line2 != null) {
-                assertEquals("Unpacked class files differ for " + name, line2, line1);
-                line1 = reader1.readLine();
-                line2 = reader2.readLine();
-                i++;
+                BufferedReader reader1 = new BufferedReader(new InputStreamReader(ours));
+                BufferedReader reader2 = new BufferedReader(new InputStreamReader(
+                        expectedStr));
+                String line1 = reader1.readLine();
+                String line2 = reader2.readLine();
+                int i = 1;
+                while (line1 != null || line2 != null) {
+                    assertEquals("Unpacked class files differ for " + name, line2, line1);
+                    line1 = reader1.readLine();
+                    line2 = reader2.readLine();
+                    i++;
+                }
+                reader1.close();
+                reader2.close();
             }
-            reader1.close();
-            reader2.close();
         }
     }
 
@@ -219,7 +222,7 @@ public class ArchiveTest extends TestCas
         archive.unpack();
         assertFalse(copy.exists());
     }
-    
+
     public void testDeflateHint() throws Exception {
         in = Archive.class
                 .getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
@@ -231,7 +234,7 @@ public class ArchiveTest extends TestCas
         archive.unpack();
         JarFile jarFile = new JarFile(file);
         assertEquals(ZipEntry.DEFLATED, jarFile.getEntry("bin/test/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.class").getMethod());
-        
+
         in = Archive.class
                 .getResourceAsStream("/org/apache/harmony/pack200/tests/sql.pack.gz");
         file = File.createTempFile("sql", ".jar");
@@ -242,7 +245,18 @@ public class ArchiveTest extends TestCas
         archive.unpack();
         jarFile = new JarFile(file);
         assertEquals(ZipEntry.STORED, jarFile.getEntry("bin/test/org/apache/harmony/sql/tests/internal/rowset/CachedRowSetImplTest.class").getMethod());
-        
+    }
+
+    public void testJava6ClassFiles() throws Exception {
+        in = Archive.class
+                .getResourceAsStream("/org/apache/harmony/pack200/tests/p200-java6-RI.pack.gz");
+        file = File.createTempFile("p200-java6", ".jar");
+        out = new JarOutputStream(new FileOutputStream(file));
+        Archive archive = new Archive(in, out);
+        archive.unpack();
+        File compareFile = new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/p200-java6-RI.jar").toURI());
+        compareFiles(compareFile, file);
     }
 
     protected void tearDown() throws Exception {
@@ -300,7 +314,7 @@ public class ArchiveTest extends TestCas
         reader = new FileReader(logFile);
         assertTrue(reader.ready());
         reader.close();
-        
+
         // test append option
         long length = logFile.length();
         in = Archive.class

Added: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.jar
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.jar?rev=999824&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.pack.gz
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.pack.gz?rev=999824&view=auto
==============================================================================
Binary file - no diff available.

Propchange: harmony/enhanced/java/branches/java6/classlib/modules/pack200/src/test/resources/org/apache/harmony/pack200/tests/p200-java6-RI.pack.gz
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

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

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



Mime
View raw message