harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r727683 [6/11] - in /harmony/enhanced/classlib/branches/java6: ./ doc/ make/ modules/accessibility/src/main/java/javax/accessibility/ modules/archive/src/main/java/java/util/jar/ modules/archive/src/main/java/java/util/zip/ modules/archive/...
Date Thu, 18 Dec 2008 09:46:26 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Thu Dec 18 01:46:12 2008
@@ -154,27 +154,29 @@
                 bciRenumbering.add(i, new Integer(++renumberedOffset));
             }
         }
-        if (renumberedOffset + 1 != bciRenumbering.size()) {
-            throw new RuntimeException("Mistake made with renumbering");
-        }
-        for (int i = bcLabel.size() - 1; i >= 0; i--) {
-            Object label = bcLabel.get(i);
-            if (label instanceof Integer) {
-                break;
-            } else if (label instanceof Label) {
-                bcLabel.remove(i);
-                Integer offset = (Integer) labelsToOffsets.get(label);
-                Integer relativeOffset = (Integer) bcLabelRelativeOffsets.get(i);
-                bcLabel.add(i, new Integer(((Integer)bciRenumbering.get(offset.intValue())).intValue() - ((Integer)bciRenumbering.get(relativeOffset.intValue())).intValue()));
+        if (renumberedOffset != 0) {
+            if(renumberedOffset + 1 != bciRenumbering.size()) {
+                throw new RuntimeException("Mistake made with renumbering");
             }
+            for (int i = bcLabel.size() - 1; i >= 0; i--) {
+                Object label = bcLabel.get(i);
+                if (label instanceof Integer) {
+                    break;
+                } else if (label instanceof Label) {
+                    bcLabel.remove(i);
+                    Integer offset = (Integer) labelsToOffsets.get(label);
+                    Integer relativeOffset = (Integer) bcLabelRelativeOffsets.get(i);
+                    bcLabel.add(i, new Integer(((Integer)bciRenumbering.get(offset.intValue())).intValue() - ((Integer)bciRenumbering.get(relativeOffset.intValue())).intValue()));
+                }
+            }
+            bcCodes.add(endMarker);
+            segment.getClassBands().doBciRenumbering(bciRenumbering,
+                    labelsToOffsets);
+            bciRenumbering.clear();
+            labelsToOffsets.clear();
+            byteCodeOffset = 0;
+            renumberedOffset = 0;
         }
-        bcCodes.add(endMarker);
-        segment.getClassBands().doBciRenumbering(bciRenumbering,
-                labelsToOffsets);
-        bciRenumbering.clear();
-        labelsToOffsets.clear();
-        byteCodeOffset = 0;
-        renumberedOffset = 0;
     }
 
     public void visitLabel(Label label) {
@@ -299,6 +301,8 @@
             } else if (constant instanceof CPClass) {
                 bcCodes.add(new Integer(236)); // cldc
                 bcClassRef.add(constant);
+            } else {
+                throw new RuntimeException("Constant should not be null");
             }
         } else {
             byteCodeOffset += 2;
@@ -329,7 +333,7 @@
             bcLabel.add(labels[i]);
             bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
         }
-        int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - byteCodeOffset + 1;
+        int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
         byteCodeOffset += padding + 8 + 8 * keys.length;
         updateRenumbering();
     }
@@ -407,7 +411,7 @@
             bcLabel.add(labels[i]);
             bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
         }
-        int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - byteCodeOffset + 1;
+        int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
         byteCodeOffset+= (padding + 12 + 4 * labels.length);
         updateRenumbering();
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPClass.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPClass.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPClass.java Thu Dec 18 01:46:12 2008
@@ -21,10 +21,19 @@
 
     private final String className;
     private final CPUTF8 utf8;
+    private final boolean isInnerClass;
 
     public CPClass(CPUTF8 utf8) {
         this.utf8 = utf8;
         this.className = utf8.getUnderlyingString();
+        char[] chars = className.toCharArray();
+        for (int i = 0; i < chars.length; i++) {
+            if(chars[i] <= 0x2D) {
+                isInnerClass = true;
+                return;
+            }
+        }
+        isInnerClass = false;
     }
 
     public int compareTo(Object arg0) {
@@ -39,4 +48,8 @@
         return utf8.getIndex();
     }
 
+    public boolean isInnerClass() {
+        return isInnerClass;
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPSignature.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPSignature.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPSignature.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CPSignature.java Thu Dec 18 01:46:12 2008
@@ -48,15 +48,14 @@
             return classes.size() - ((CPSignature) arg0).classes.size();
         }
         if (classes.size() > 0) {
-            int classComp = 0;
             for (int i = classes.size() - 1; i >=0; i--) {
                 CPClass cpClass = (CPClass) classes.get(i);
                 CPClass compareClass = (CPClass) ((CPSignature) arg0).classes
                         .get(i);
-                classComp = classComp * 10 + cpClass.compareTo(compareClass);
-            }
-            if(classComp != 0) {
-                return classComp;
+                int classComp = cpClass.compareTo(compareClass);
+                if(classComp != 0) {
+                    return classComp;
+                }
             }
         }
         return signature.compareTo(((CPSignature) arg0).signature);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Thu Dec 18 01:46:12 2008
@@ -19,11 +19,17 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
+import org.apache.harmony.pack200.IcBands.IcTuple;
 import org.objectweb.asm.Attribute;
 import org.objectweb.asm.Label;
+import org.objectweb.asm.Opcodes;
 
 public class ClassBands extends BandSet {
 
@@ -40,6 +46,7 @@
     private final int[] major_versions;
 
     private final long[] class_flags;
+    private int[] class_attr_calls;
     private final List classSourceFile = new ArrayList();
     private final List classEnclosingMethodClass = new ArrayList();
     private final List classEnclosingMethodDesc = new ArrayList();
@@ -51,12 +58,14 @@
     private final int[] class_field_count;
     private final CPNameAndType[][] field_descr;
     private final long[][] field_flags;
+    private int[] field_attr_calls;
     private final List fieldConstantValueKQ = new ArrayList();
     private final List fieldSignature = new ArrayList();
 
     private final int[] class_method_count;
     private final CPNameAndType[][] method_descr;
     private final long[][] method_flags;
+    private int[] method_attr_calls;
     private final List methodSignature = new ArrayList();
     private final List methodExceptionNumber = new ArrayList();
     private final List methodExceptionClasses = new ArrayList();
@@ -86,16 +95,33 @@
     private final List codeLocalVariableTypeTableTypeRS = new ArrayList();
     private final List codeLocalVariableTypeTableSlot = new ArrayList();
 
+    private final MetadataBandGroup class_RVA_bands;
+    private final MetadataBandGroup class_RIA_bands;
+    private final MetadataBandGroup field_RVA_bands;
+    private final MetadataBandGroup field_RIA_bands;
+    private final MetadataBandGroup method_RVA_bands;
+    private final MetadataBandGroup method_RIA_bands;
+    private final MetadataBandGroup method_RVPA_bands;
+    private final MetadataBandGroup method_RIPA_bands;
+    private final MetadataBandGroup method_AD_bands;
+
     private final List tempFieldFlags = new ArrayList();
     private final List tempFieldDesc = new ArrayList();
     private final List tempMethodFlags = new ArrayList();
     private final List tempMethodDesc = new ArrayList();
 
-    public ClassBands(SegmentHeader header, CpBands cpBands,
-            AttributeDefinitionBands attrBands, int numClasses) {
-        this.header = header;
-        this.cpBands = cpBands;
-        this.attrBands = attrBands;
+    private boolean anySyntheticClasses = false;
+    private boolean anySyntheticFields = false;
+    private boolean anySyntheticMethods = false;
+    private final Segment segment;
+
+    private final Map classReferencesInnerClass = new HashMap();
+
+    public ClassBands(Segment segment, int numClasses) {
+        this.segment = segment;
+        this.header = segment.getSegmentHeader();
+        this.cpBands = segment.getCpBands();
+        this.attrBands = segment.getAttrBands();
         class_this = new CPClass[numClasses];
         class_super = new CPClass[numClasses];
         class_interface_count = new int[numClasses];
@@ -109,14 +135,29 @@
         // minor_versions = new int[numClasses];
         major_versions = new int[numClasses];
         class_flags = new long[numClasses];
+
+        class_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
+        class_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_CLASS, cpBands);
+        field_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
+        field_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_FIELD, cpBands);
+        method_RVA_bands = new MetadataBandGroup("RVA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
+        method_RIA_bands = new MetadataBandGroup("RIA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
+        method_RVPA_bands = new MetadataBandGroup("RVPA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
+        method_RIPA_bands = new MetadataBandGroup("RIPA", MetadataBandGroup.CONTEXT_METHOD, cpBands);
+        method_AD_bands = new MetadataBandGroup("AD", MetadataBandGroup.CONTEXT_METHOD, cpBands);
     }
 
     private int index = 0;
 
     private int numMethodArgs = 0;
+    private int[] class_InnerClasses_N;
+    private CPClass[] class_InnerClasses_RC;
+    private int[] class_InnerClasses_F;
+    private List classInnerClassesOuterRCN;
+    private List classInnerClassesNameRUN;
 
     public void addClass(int major, int flags, String className,
-            String superName, String[] interfaces) {
+            String signature, String superName, String[] interfaces) {
         class_this[index] = cpBands.getCPClass(className);
         class_super[index] = cpBands.getCPClass(superName);
         class_interface_count[index] = interfaces.length;
@@ -126,10 +167,46 @@
         }
         major_versions[index] = major;
         class_flags[index] = flags;
+        if(!anySyntheticClasses && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
+            cpBands.addCPUtf8("Synthetic");
+            anySyntheticClasses = true;
+        }
+        if((flags & Opcodes.ACC_DEPRECATED) != 0) { // ASM uses (1<<17) flag for deprecated
+            flags = flags & ~Opcodes.ACC_DEPRECATED;
+            flags = flags | (1<<20);
+        }
+        if(signature != null) {
+            class_flags[index] |= (1 << 19);
+            classSignature.add(cpBands.getCPSignature(signature));
+        }
+    }
+
+    public void currentClassReferencesInnerClass(CPClass inner) {
+        if(!(index >= class_this.length)) {
+            CPClass currentClass = class_this[index];
+            if(currentClass != null && !currentClass.equals(inner) && !isInnerClassOf(currentClass, inner)) {
+                Set referencedInnerClasses = (Set)classReferencesInnerClass.get(currentClass);
+                if(referencedInnerClasses == null) {
+                    referencedInnerClasses = new HashSet();
+                    classReferencesInnerClass.put(currentClass, referencedInnerClasses);
+                }
+                referencedInnerClasses.add(inner);
+            }
+        }
+    }
+
+    private boolean isInnerClassOf(CPClass possibleInner, CPClass possibleOuter) {
+        String currentClassName = possibleInner.toString();
+        if(possibleInner.isInnerClass()) {
+            String superClassName = currentClassName.substring(0, currentClassName.lastIndexOf('$'));
+            return superClassName.equals(possibleOuter.toString());
+        }
+        return false;
     }
 
     public void addField(int flags, String name, String desc, String signature,
             Object value) {
+        flags = flags & 0xFFFF;
         CPMethodOrField field = cpBands.addCPField(class_this[index], name,
                 desc);
         tempFieldDesc.add(field.getDesc());
@@ -137,10 +214,18 @@
             fieldSignature.add(cpBands.getCPSignature(signature));
             flags |= (1 << 19);
         }
+        if((flags & Opcodes.ACC_DEPRECATED) != 0) { // ASM uses (1<<17) flag for deprecated
+            flags = flags & ~Opcodes.ACC_DEPRECATED;
+            flags = flags | (1<<20);
+        }
         if (value != null) {
             fieldConstantValueKQ.add(cpBands.getConstant(value));
             flags |= (1 << 17);
         }
+        if(!anySyntheticFields && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
+            cpBands.addCPUtf8("Synthetic");
+            anySyntheticFields = true;
+        }
         tempFieldFlags.add(new Long(flags));
     }
 
@@ -188,20 +273,97 @@
                 removed++;
             }
         }
-    }
 
-    public void pack(OutputStream out) throws IOException, Pack200Exception {
-        int[] classThis = new int[class_this.length];
-        for (int i = 0; i < classThis.length; i++) {
-            classThis[i] = class_this[i].getIndex();
+        // Compute any required IcLocals
+        List innerClassesN = new ArrayList();
+        List icLocal = new ArrayList();
+        for (int i = 0; i < class_this.length; i++) {
+            CPClass cpClass = class_this[i];
+            Set referencedInnerClasses = (Set) classReferencesInnerClass.get(cpClass);
+            if(referencedInnerClasses != null) {
+                int innerN = 0;
+                List innerClasses = segment.getIcBands().getInnerClassesForOuter(cpClass.toString());
+                if(innerClasses != null) {
+                    for (Iterator iterator2 = innerClasses.iterator(); iterator2
+                            .hasNext();) {
+                        referencedInnerClasses.remove(((IcTuple)iterator2.next()).C);
+                    }
+                }
+                for (Iterator iterator2 = referencedInnerClasses.iterator(); iterator2
+                        .hasNext();) {
+                    CPClass inner = (CPClass) iterator2.next();
+                    IcTuple icTuple = segment.getIcBands().getIcTuple(inner);
+                    if(icTuple != null) {
+                        // should transmit an icLocal entry
+                        icLocal.add(icTuple);
+                        innerN++;
+                    }
+                }
+                if(innerN != 0) {
+                    innerClassesN.add(new Integer(innerN));
+                    class_flags[i] |= (1 << 23);
+                }
+            }
         }
-        out.write(encodeBandInt("class_this", classThis, Codec.DELTA5));
-
-        int[] classSuper = new int[class_super.length];
-        for (int i = 0; i < classSuper.length; i++) {
-            classSuper[i] = class_super[i].getIndex();
+        class_InnerClasses_N = listToArray(innerClassesN);
+        class_InnerClasses_RC = new CPClass[icLocal.size()];
+        class_InnerClasses_F = new int[icLocal.size()];
+        classInnerClassesOuterRCN = new ArrayList();
+        classInnerClassesNameRUN = new ArrayList();
+        for (int i = 0; i < class_InnerClasses_RC.length; i++) {
+            IcTuple icTuple = (IcTuple) icLocal.get(i);
+            class_InnerClasses_RC[i] = (icTuple.C);
+            if(icTuple.C2 == null && icTuple.N == null) {
+                class_InnerClasses_F[i] = 0;
+            } else {
+                if (icTuple.F == 0) {
+                    class_InnerClasses_F[i] = 0x00010000;
+                } else {
+                    class_InnerClasses_F[i] = icTuple.F;
+                }
+                classInnerClassesOuterRCN.add(icTuple.C2);
+                classInnerClassesNameRUN.add(icTuple.N);
+            }
+        }
+        // Calculate any backwards calls from metadata bands
+        List classAttrCalls = new ArrayList();
+        List fieldAttrCalls = new ArrayList();
+        List methodAttrCalls = new ArrayList();
+        if(class_RVA_bands.hasContent()) {
+            classAttrCalls.add(new Integer(class_RVA_bands.numBackwardsCalls()));
+        }
+        if(class_RIA_bands.hasContent()) {
+            classAttrCalls.add(new Integer(class_RIA_bands.numBackwardsCalls()));
+        }
+        if(field_RVA_bands.hasContent()) {
+            fieldAttrCalls.add(new Integer(field_RVA_bands.numBackwardsCalls()));
+        }
+        if(field_RIA_bands.hasContent()) {
+            fieldAttrCalls.add(new Integer(field_RIA_bands.numBackwardsCalls()));
+        }
+        if(method_RVA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RVA_bands.numBackwardsCalls()));
+        }
+        if(method_RIA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RIA_bands.numBackwardsCalls()));
+        }
+        if(method_RVPA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RVPA_bands.numBackwardsCalls()));
+        }
+        if(method_RIPA_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_RIPA_bands.numBackwardsCalls()));
         }
-        out.write(encodeBandInt("class_super", classSuper, Codec.DELTA5));
+        if(method_AD_bands.hasContent()) {
+            methodAttrCalls.add(new Integer(method_AD_bands.numBackwardsCalls()));
+        }
+        class_attr_calls = listToArray(classAttrCalls);
+        field_attr_calls = listToArray(fieldAttrCalls);
+        method_attr_calls = listToArray(methodAttrCalls);
+    }
+
+    public void pack(OutputStream out) throws IOException, Pack200Exception {
+        out.write(encodeBandInt("class_this", getInts(class_this), Codec.DELTA5));
+        out.write(encodeBandInt("class_super", getInts(class_super), Codec.DELTA5));
         out.write(encodeBandInt("class_interface_count", class_interface_count,
                 Codec.DELTA5));
 
@@ -217,9 +379,8 @@
                 }
             }
         }
-        out
-                .write(encodeBandInt("class_interface", classInterface,
-                        Codec.DELTA5));
+        out.write(encodeBandInt("class_interface", classInterface,
+                Codec.DELTA5));
         out.write(encodeBandInt("class_field_count", class_field_count,
                 Codec.DELTA5));
         out.write(encodeBandInt("class_method_count", class_method_count,
@@ -267,28 +428,44 @@
             Pack200Exception {
         out.write(encodeFlags("field_flags", field_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_field_flags_hi()));
+//        *field_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *field_attr_indexes :UNSIGNED5 [SUM(*field_attr_count)]
+        out.write(encodeBandInt("field_attr_calls", field_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("fieldConstantValueKQ",
                 cpEntryListToArray(fieldConstantValueKQ), Codec.UNSIGNED5));
         out.write(encodeBandInt("fieldSignature",
                 cpEntryListToArray(fieldSignature), Codec.UNSIGNED5));
+        field_RVA_bands.pack(out);
+        field_RIA_bands.pack(out);
     }
 
     private void writeMethodAttributeBands(OutputStream out)
             throws IOException, Pack200Exception {
         out.write(encodeFlags("method_flags", method_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_method_flags_hi()));
+//        *method_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *method_attr_indexes :UNSIGNED5 [SUM(*method_attr_count)]
+        out.write(encodeBandInt("method_attr_calls", method_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionNumber",
                 listToArray(methodExceptionNumber), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionClasses",
                 cpEntryListToArray(methodExceptionClasses), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodSignature",
                 cpEntryListToArray(methodSignature), Codec.UNSIGNED5));
+        method_RVA_bands.pack(out);
+        method_RIA_bands.pack(out);
+        method_RVPA_bands.pack(out);
+        method_RIPA_bands.pack(out);
+        method_AD_bands.pack(out);
     }
 
     private void writeClassAttributeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeFlags("class_flags", class_flags, Codec.UNSIGNED5,
                 Codec.UNSIGNED5, header.have_class_flags_hi()));
+//        *class_attr_count :UNSIGNED5 [COUNT(1<<16,...)]
+//        *class_attr_indexes :UNSIGNED5 [SUM(*class_attr_count)]
+        out.write(encodeBandInt("class_attr_calls", class_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("classSourceFile",
                 cpEntryOrNullListToArray(classSourceFile), Codec.UNSIGNED5));
         out.write(encodeBandInt("class_enclosing_method_RC",
@@ -297,14 +474,29 @@
         out.write(encodeBandInt("class_EnclosingMethod_RDN",
                 cpEntryOrNullListToArray(classEnclosingMethodDesc),
                 Codec.UNSIGNED5));
-        out.write(encodeBandInt("classSignature",
+        out.write(encodeBandInt("class_Signature_RS",
                 cpEntryListToArray(classSignature), Codec.UNSIGNED5));
+        class_RVA_bands.pack(out);
+        class_RIA_bands.pack(out);
+        out.write(encodeBandInt("class_InnerClasses_N", class_InnerClasses_N, Codec.UNSIGNED5));
+        out.write(encodeBandInt("class_InnerClasses_RC", getInts(class_InnerClasses_RC), Codec.UNSIGNED5));
+        out.write(encodeBandInt("class_InnerClasses_F", class_InnerClasses_F, Codec.UNSIGNED5));
+        out.write(encodeBandInt("class_InnerClasses_outer_RCN", cpEntryOrNullListToArray(classInnerClassesOuterRCN), Codec.UNSIGNED5));
+        out.write(encodeBandInt("class_InnerClasses_name_RUN", cpEntryOrNullListToArray(classInnerClassesNameRUN), Codec.UNSIGNED5));
         out.write(encodeBandInt("classFileVersionMinor",
                 listToArray(classFileVersionMinor), Codec.UNSIGNED5));
         out.write(encodeBandInt("classFileVersionMajor",
                 listToArray(classFileVersionMajor), Codec.UNSIGNED5));
     }
 
+    private int[] getInts(CPClass[] cpClasses) {
+        int[] ints = new int[cpClasses.length];
+        for (int i = 0; i < ints.length; i++) {
+            ints[i] = cpClasses[i].getIndex();
+        }
+        return ints;
+    }
+
     private void writeCodeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeBandInt("codeHeaders", codeHeaders, Codec.BYTE1));
@@ -344,8 +536,7 @@
         out.write(encodeBandInt("code_LocalVariableTable_bci_P",
                 listToArray(codeLocalVariableTableBciP), Codec.BCI5));
         out.write(encodeBandInt("code_LocalVariableTable_span_O",
-                listToArray(codeLocalVariableTableSpanO), Codec.BRANCH5)); // TODO:
-                                                                            // Difference
+                listToArray(codeLocalVariableTableSpanO), Codec.BRANCH5));
         out.write(encodeBandInt("code_LocalVariableTable_name_RU",
                 cpEntryListToArray(codeLocalVariableTableNameRU),
                 Codec.UNSIGNED5));
@@ -387,9 +578,16 @@
             }
             flags |= (1 << 18);
         }
+        if((flags & Opcodes.ACC_DEPRECATED) != 0) { // ASM uses (1<<17) flag for deprecated
+            flags = flags & ~Opcodes.ACC_DEPRECATED;
+            flags = flags | (1<<20);
+        }
         tempMethodFlags.add(new Long(flags));
-        codeHandlerCount.add(ZERO);
         numMethodArgs = countArgs(desc);
+        if(!anySyntheticMethods && ((flags & (1 << 12)) != 0) && segment.getCurrentClassReader().hasSyntheticAttributes()) {
+            cpBands.addCPUtf8("Synthetic");
+            anySyntheticMethods = true;
+        }
     }
 
     protected static int countArgs(String descriptor) {
@@ -457,6 +655,9 @@
 
     public void addSourceFile(String source) {
         String implicitSourceFileName = class_this[index].toString();
+        if(implicitSourceFileName.indexOf('$') != -1) {
+            implicitSourceFileName = implicitSourceFileName.substring(0, implicitSourceFileName.indexOf('$'));
+        }
         implicitSourceFileName = implicitSourceFileName
                 .substring(implicitSourceFileName.lastIndexOf('/') + 1)
                 + ".java";
@@ -499,7 +700,9 @@
     }
 
     public void addCode() {
-        codeFlags.add(new Long(0));
+        codeHandlerCount.add(ZERO);
+        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) {
@@ -550,16 +753,9 @@
             codeLocalVariableTypeTableSlot.add(new Integer(indx));
         }
         // LocalVariableTable attribute
-        Long latestCodeFlag = (Long) codeFlags.get(codeFlags.size() - 1);
-        if ((latestCodeFlag.intValue() & (1 << 2)) == 0) {
-            codeFlags.remove(codeFlags.size() - 1);
-            codeFlags.add(new Long(latestCodeFlag.intValue() | (1 << 2)));
-            codeLocalVariableTableN.add(new Integer(1));
-        } else {
-            Integer numLocals = (Integer) codeLocalVariableTableN
-                    .remove(codeLocalVariableTableN.size() - 1);
-            codeLocalVariableTableN.add(new Integer(numLocals.intValue() + 1));
-        }
+        Integer numLocals = (Integer) codeLocalVariableTableN
+                .remove(codeLocalVariableTableN.size() - 1);
+        codeLocalVariableTableN.add(new Integer(numLocals.intValue() + 1));
         codeLocalVariableTableBciP.add(start);
         codeLocalVariableTableSpanO.add(end);
         codeLocalVariableTableNameRU.add(cpBands.getCPUtf8(name));
@@ -631,4 +827,111 @@
             }
         }
     }
+
+    public boolean isAnySyntheticClasses() {
+        return anySyntheticClasses;
+    }
+
+    public boolean isAnySyntheticFields() {
+        return anySyntheticFields;
+    }
+
+    public boolean isAnySyntheticMethods() {
+        return anySyntheticMethods;
+    }
+
+    public void addParameterAnnotation(int parameter, String desc,
+            boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
+        if(visible) {
+            method_RVPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            if((flag.intValue() & (1<<23)) != 0) {
+                method_RVPA_bands.incrementAnnoN();
+            } else {
+                method_RVPA_bands.newEntryInAnnoN();
+            }
+            tempMethodFlags.add(new Integer(flag.intValue() | (1<<23)));
+        } else {
+            method_RIPA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+            if((flag.intValue() & (1<<24)) != 0) {
+                method_RIPA_bands.incrementAnnoN();
+            } else {
+                method_RIPA_bands.newEntryInAnnoN();
+            }
+            tempMethodFlags.add(new Integer(flag.intValue() | (1<<24)));
+        }
+    }
+
+    public void addAnnotation(int context, String desc, boolean visible, List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
+        switch (context) {
+        case MetadataBandGroup.CONTEXT_CLASS:
+            if(visible) {
+                class_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                if((class_flags[index] & (1<<21)) != 0) {
+                    class_RVA_bands.incrementAnnoN();
+                } else {
+                    class_RVA_bands.newEntryInAnnoN();
+                    class_flags[index] = class_flags[index] | (1<<21);
+                }
+            } else {
+                class_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                if((class_flags[index] & (1<<22)) != 0) {
+                    class_RIA_bands.incrementAnnoN();
+                } else {
+                    class_RIA_bands.newEntryInAnnoN();
+                    class_flags[index] = class_flags[index] | (1<<22);
+                }
+            }
+            break;
+        case MetadataBandGroup.CONTEXT_FIELD:
+            if(visible) {
+                field_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                Long flag = (Long) tempFieldFlags.remove(tempFieldFlags.size() - 1);
+                if((flag.intValue() & (1<<21)) != 0) {
+                    field_RVA_bands.incrementAnnoN();
+                } else {
+                    field_RVA_bands.newEntryInAnnoN();
+                }
+                tempFieldFlags.add(new Long(flag.intValue() | (1<<21)));
+            } else {
+                field_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                Long flag = (Long) tempFieldFlags.remove(tempFieldFlags.size() - 1);
+                if((flag.intValue() & (1<<22)) != 0) {
+                    field_RIA_bands.incrementAnnoN();
+                } else {
+                    field_RIA_bands.newEntryInAnnoN();
+                }
+                tempFieldFlags.add(new Long(flag.intValue() | (1<<22)));
+            }
+            break;
+        case MetadataBandGroup.CONTEXT_METHOD:
+            if(visible) {
+                method_RVA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+                if((flag.intValue() & (1<<21)) != 0) {
+                    method_RVA_bands.incrementAnnoN();
+                } else {
+                    method_RVA_bands.newEntryInAnnoN();
+                }
+                tempMethodFlags.add(new Long(flag.intValue() | (1<<21)));
+            } else {
+                method_RIA_bands.addAnnotation(desc, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+                Long flag = (Long) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+                if((flag.intValue() & (1<<22)) != 0) {
+                    method_RIA_bands.incrementAnnoN();
+                } else {
+                    method_RIA_bands.newEntryInAnnoN();
+                }
+                tempMethodFlags.add(new Long(flag.intValue() | (1<<22)));
+            }
+            break;
+        }
+    }
+
+    public void addAnnotationDefault(List nameRU, List t, List values, List caseArrayN, List nestTypeRS, List nestNameRU, List nestPairN) {
+        method_AD_bands.addAnnotation(null, nameRU, t, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+        Integer flag = (Integer) tempMethodFlags.remove(tempMethodFlags.size() - 1);
+        tempMethodFlags.add(new Integer(flag.intValue() | (1<<25)));
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Thu Dec 18 01:46:12 2008
@@ -27,6 +27,8 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.objectweb.asm.Type;
+
 /**
  * Pack200 Constant Pool Bands
  */
@@ -54,12 +56,17 @@
     private final Map stringsToCpNameAndType = new HashMap();
     private final Map stringsToCpClass = new HashMap();
     private final Map stringsToCpSignature = new HashMap();
-    private final Map stringsToCpMethodOrField = new HashMap();
+    private final Map stringsToCpMethod = new HashMap();
+    private final Map stringsToCpField = new HashMap();
+    private final Map stringsToCpIMethod = new HashMap();
 
     private final Map objectsToCPConstant = new HashMap();
 
-    public CpBands(SegmentHeader segmentHeader) {
-        this.segmentHeader = segmentHeader;
+    private final Segment segment;
+
+    public CpBands(Segment segment) {
+        this.segmentHeader = segment.getSegmentHeader();
+        this.segment = segment;
         defaultAttributeNames.add("AnnotationDefault");
         defaultAttributeNames.add("RuntimeVisibleAnnotations");
         defaultAttributeNames.add("RuntimeInvisibleAnnotations");
@@ -132,24 +139,27 @@
         }
         int[] cpUtf8Chars = new int[chars.size()];
         int[] cpUtf8BigSuffix = new int[bigSuffix.size()];
-        int[] cpUtf8BigChars = new int[bigChars.size()];
+        int[][] cpUtf8BigChars = new int[bigSuffix.size()][];
         for (int i = 0; i < cpUtf8Chars.length; i++) {
             cpUtf8Chars[i] = ((Character) chars.get(i)).charValue();
         }
         for (int i = 0; i < cpUtf8BigSuffix.length; i++) {
-            cpUtf8BigSuffix[i] = ((Integer) bigSuffix.get(i)).intValue();
-        }
-        for (int i = 0; i < cpUtf8BigChars.length; i++) {
-            cpUtf8BigChars[i] = ((Character) bigChars.get(i)).charValue();
+            int numBigChars = ((Integer) bigSuffix.get(i)).intValue();
+            cpUtf8BigSuffix[i] = numBigChars;
+            cpUtf8BigChars[i] = new int[numBigChars];
+            for (int j = 0; j < numBigChars; j++) {
+                cpUtf8BigChars[i][j] = ((Character) bigChars.remove(0)).charValue();
+            }
         }
         out.write(encodeBandInt("cpUtf8Prefix", cpUtf8Prefix, Codec.DELTA5));
         out.write(encodeBandInt("cpUtf8Suffix", cpUtf8Suffix, Codec.UNSIGNED5));
         out.write(encodeBandInt("cpUtf8Chars", cpUtf8Chars, Codec.CHAR3));
         out.write(encodeBandInt("cpUtf8BigSuffix", cpUtf8BigSuffix,
                 Codec.DELTA5));
-        out
-                .write(encodeBandInt("cpUtf8BigChars", cpUtf8BigChars,
+        for (int i = 0; i < cpUtf8BigChars.length; i++) {
+            out.write(encodeBandInt("cpUtf8BigChars " + i, cpUtf8BigChars[i],
                         Codec.DELTA5));
+        }
     }
 
     private void addCharacters(List chars, char[] charArray) {
@@ -194,8 +204,8 @@
             loBits[i] = (int) l;
             i++;
         }
-        out.write(encodeBandInt("cp_Long_high", highBits, Codec.UDELTA5));
-        out.write(encodeBandInt("cp_Long_low", loBits, Codec.DELTA5));
+        out.write(encodeBandInt("cp_Long_hi", highBits, Codec.UDELTA5));
+        out.write(encodeBandInt("cp_Long_lo", loBits, Codec.DELTA5));
     }
 
     private void writeCpDouble(OutputStream out) throws IOException,
@@ -210,8 +220,8 @@
             loBits[i] = (int) l;
             i++;
         }
-        out.write(encodeBandInt("cp_Double_high", highBits, Codec.UDELTA5));
-        out.write(encodeBandInt("cp_Double_low", loBits, Codec.DELTA5));
+        out.write(encodeBandInt("cp_Double_hi", highBits, Codec.UDELTA5));
+        out.write(encodeBandInt("cp_Double_lo", loBits, Codec.DELTA5));
     }
 
     private void writeCpString(OutputStream out) throws IOException,
@@ -373,7 +383,7 @@
         }
     }
 
-    private void addCPUtf8(String utf8) {
+    void addCPUtf8(String utf8) {
         getCPUtf8(utf8);
     }
 
@@ -427,7 +437,19 @@
                 removeCpUtf8(signature);
                 for (Iterator iterator2 = classes.iterator(); iterator2
                         .hasNext();) {
-                    cpClasses.add(getCPClass((String) iterator2.next()));
+                    String className = (String) iterator2.next();
+                    CPClass cpClass = null;
+                    if(className!= null) {
+                        className = className.replace('.', '/');
+                        cpClass = (CPClass) stringsToCpClass.get(className);
+                        if (cpClass == null) {
+                            CPUTF8 cpUtf8 = getCPUtf8(className);
+                            cpClass = new CPClass(cpUtf8);
+                            cp_Class.add(cpClass);
+                            stringsToCpClass.put(className, cpClass);
+                        }
+                    }
+                    cpClasses.add(cpClass);
                 }
 
                 signatureUTF8 = getCPUtf8(signatureString.toString());
@@ -453,6 +475,9 @@
             cp_Class.add(cpClass);
             stringsToCpClass.put(className, cpClass);
         }
+        if(cpClass.isInnerClass()) {
+            segment.getClassBands().currentClassReferencesInnerClass(cpClass);
+        }
         return cpClass;
     }
 
@@ -475,13 +500,13 @@
 
     public CPMethodOrField getCPField(CPClass cpClass, String name, String desc) {
         String key = cpClass.toString() + ":" + name + ":" + desc;
-        CPMethodOrField cpF = (CPMethodOrField) stringsToCpMethodOrField
+        CPMethodOrField cpF = (CPMethodOrField) stringsToCpField
                 .get(key);
         if (cpF == null) {
             CPNameAndType nAndT = getCPNameAndType(name, desc);
             cpF = new CPMethodOrField(cpClass, nAndT);
             cp_Field.add(cpF);
-            stringsToCpMethodOrField.put(key, cpF);
+            stringsToCpField.put(key, cpF);
         }
         return cpF;
     }
@@ -504,6 +529,16 @@
             } else if (value instanceof String) {
                 constant = new CPString(getCPUtf8((String) value));
                 cp_String.add(constant);
+            } else if (value instanceof Type) {
+                String className = ((Type) value).getClassName();
+                if(className.endsWith("[]")) {
+                    className = "[L" + className.substring(0, className.length() - 2);
+                    while(className.endsWith("[]")) {
+                        className = "[" + className.substring(0, className.length() - 2);
+                    }
+                    className += ";";
+                }
+                constant = getCPClass(className);
             }
             objectsToCPConstant.put(value, constant);
         }
@@ -512,13 +547,13 @@
 
     public CPMethodOrField getCPMethod(CPClass cpClass, String name, String desc) {
         String key = cpClass.toString() + ":" + name + ":" + desc;
-        CPMethodOrField cpM = (CPMethodOrField) stringsToCpMethodOrField
+        CPMethodOrField cpM = (CPMethodOrField) stringsToCpMethod
                 .get(key);
         if (cpM == null) {
             CPNameAndType nAndT = getCPNameAndType(name, desc);
             cpM = new CPMethodOrField(cpClass, nAndT);
             cp_Method.add(cpM);
-            stringsToCpMethodOrField.put(key, cpM);
+            stringsToCpMethod.put(key, cpM);
         }
         return cpM;
     }
@@ -526,13 +561,13 @@
     public CPMethodOrField getCPIMethod(CPClass cpClass, String name,
             String desc) {
         String key = cpClass.toString() + ":" + name + ":" + desc;
-        CPMethodOrField cpIM = (CPMethodOrField) stringsToCpMethodOrField
+        CPMethodOrField cpIM = (CPMethodOrField) stringsToCpIMethod
                 .get(key);
         if (cpIM == null) {
             CPNameAndType nAndT = getCPNameAndType(name, desc);
             cpIM = new CPMethodOrField(cpClass, nAndT);
             cp_Imethod.add(cpIM);
-            stringsToCpMethodOrField.put(key, cpIM);
+            stringsToCpIMethod.put(key, cpIM);
         }
         return cpIM;
     }
@@ -551,12 +586,12 @@
 
     public CPMethodOrField addCPMethod(CPClass cpClass, String name, String desc) {
         String key = cpClass.toString() + ":" + name + ":" + desc;
-        CPMethodOrField cpM = (CPMethodOrField) stringsToCpMethodOrField
+        CPMethodOrField cpM = (CPMethodOrField) stringsToCpMethod
                 .get(key);
         if (cpM == null) {
             CPNameAndType nAndT = getCPNameAndType(name, desc);
             cpM = new CPMethodOrField(cpClass, nAndT);
-            stringsToCpMethodOrField.put(key, cpM);
+            stringsToCpMethod.put(key, cpM);
             cp_Method.add(cpM);
         }
         return cpM;
@@ -564,12 +599,12 @@
 
     public CPMethodOrField addCPField(CPClass cpClass, String name, String desc) {
         String key = cpClass.toString() + ":" + name + ":" + desc;
-        CPMethodOrField cpF = (CPMethodOrField) stringsToCpMethodOrField
+        CPMethodOrField cpF = (CPMethodOrField) stringsToCpField
                 .get(key);
         if (cpF == null) {
             CPNameAndType nAndT = getCPNameAndType(name, desc);
             cpF = new CPMethodOrField(cpClass, nAndT);
-            stringsToCpMethodOrField.put(key, cpF);
+            stringsToCpField.put(key, cpF);
             cp_Field.add(cpF);
         }
         return cpF;

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/IcBands.java Thu Dec 18 01:46:12 2008
@@ -19,17 +19,22 @@
 import java.io.IOException;
 import java.io.OutputStream;
 import java.util.ArrayList;
-import java.util.HashSet;
+import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 
 public class IcBands extends BandSet {
 
-    private final Set innerClasses = new HashSet();
+    private final Set innerClasses = new TreeSet();
     private final SegmentHeader segmentHeader;
     private final CpBands cpBands;
     private int bit16Count = 0;
 
+    private final Map outerToInner = new HashMap();
+
     public IcBands(SegmentHeader segmentHeader, CpBands cpBands) {
         this.segmentHeader = segmentHeader;
         this.cpBands = cpBands;
@@ -66,17 +71,58 @@
     public void addInnerClass(String name, String outerName, String innerName,
             int flags) {
         if(outerName != null || innerName != null) {
-            flags |= (1<<16);
-            boolean added = innerClasses.add(new IcTuple(cpBands.getCPClass(name), flags, cpBands.getCPClass(outerName), cpBands.getCPUtf8(innerName)));
-            if(added) {
-                bit16Count++;
+            if(namesArePredictable(name, outerName, innerName)) {
+                IcTuple innerClass = new IcTuple(cpBands.getCPClass(name), flags, null, null);
+                addToMap(outerName, innerClass);
+                innerClasses.add(innerClass);
+            } else {
+                flags |= (1<<16);
+                IcTuple icTuple = new IcTuple(cpBands.getCPClass(name), flags, cpBands.getCPClass(outerName), cpBands.getCPUtf8(innerName));
+                boolean added = innerClasses.add(icTuple);
+                if(added) {
+                    bit16Count++;
+                    addToMap(outerName, icTuple);
+                }
             }
         } else {
-            innerClasses.add(new IcTuple(cpBands.getCPClass(name), flags, cpBands.getCPClass(outerName), cpBands.getCPUtf8(innerName)));
+            IcTuple innerClass = new IcTuple(cpBands.getCPClass(name), flags, null, null);
+            addToMap(getOuter(name), innerClass);
+            innerClasses.add(innerClass);
         }
     }
 
-    private class IcTuple {
+    public List getInnerClassesForOuter(String outerClassName) {
+        return (List) outerToInner.get(outerClassName);
+    }
+
+    private String getOuter(String name) {
+        return name.substring(0, name.lastIndexOf('$'));
+    }
+
+    private void addToMap(String outerName, IcTuple icTuple) {
+        List tuples = (List) outerToInner.get(outerName);
+        if(tuples == null) {
+            tuples = new ArrayList();
+            outerToInner.put(outerName, tuples);
+            tuples.add(icTuple);
+        } else {
+            for (Iterator iterator = tuples.iterator(); iterator.hasNext();) {
+                IcTuple icT = (IcTuple) iterator.next();
+                if(icTuple.equals(icT)) {
+                    return;
+                }
+            }
+            tuples.add(icTuple);
+        }
+    }
+
+    private boolean namesArePredictable(String name, String outerName,
+            String innerName) {
+        // TODO: Could be multiple characters, not just $
+        return name.equals(outerName + '$' + innerName) && innerName.indexOf('$') == -1;
+    }
+
+    class IcTuple implements Comparable {
 
         protected CPClass C; // this class
         protected int F; // flags
@@ -93,7 +139,7 @@
         public boolean equals(Object o) {
             if(o instanceof IcTuple) {
                 IcTuple icT = (IcTuple)o;
-                return C.equals(icT.C) && F == icT.F && C2 != null ? C2.equals(icT.C2) : icT.C2 == null && N != null ? N.equals(icT.N) : icT.N == null;
+                return C.equals(icT.C) && F == icT.F && (C2 != null ? C2.equals(icT.C2) : icT.C2 == null) && (N != null ? N.equals(icT.N) : icT.N == null);
             }
             return false;
         }
@@ -101,6 +147,25 @@
         public int hashCode() {
             return (C.hashCode() * 37) + F;
         }
+
+        public String toString() {
+            return C.toString();
+        }
+
+        public int compareTo(Object arg0) {
+            return C.compareTo(((IcTuple)arg0).C);
+        }
+
+    }
+
+    public IcTuple getIcTuple(CPClass inner) {
+        for (Iterator iterator = innerClasses.iterator(); iterator.hasNext();) {
+            IcTuple icTuple = (IcTuple) iterator.next();
+            if(icTuple.C.equals(inner)) {
+                return icTuple;
+            }
+        }
+        return null;
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Pack200ClassReader.java Thu Dec 18 01:46:12 2008
@@ -28,6 +28,8 @@
 public class Pack200ClassReader extends ClassReader {
 
     private boolean lastConstantHadWideIndex;
+    private int lastUnsignedShort;
+    private boolean anySyntheticAttributes;
 
     /**
      * @param b
@@ -52,11 +54,31 @@
         super(name);
     }
 
+    public int readUnsignedShort(int index) {
+        // Doing this to check whether last load-constant instruction was ldc (18) or ldc_w (19)
+        // TODO:  Assess whether this impacts on performance
+        int unsignedShort = super.readUnsignedShort(index);
+        if(b[index - 1] == 19) {
+            lastUnsignedShort = unsignedShort;
+        } else {
+            lastUnsignedShort = Short.MIN_VALUE;
+        }
+        return unsignedShort;
+    }
+
     public Object readConst(int item, char[] buf) {
-        lastConstantHadWideIndex = item > Byte.MAX_VALUE;
+        lastConstantHadWideIndex = item == lastUnsignedShort;
         return super.readConst(item, buf);
     }
 
+    public String readUTF8(int arg0, char[] arg1) {
+        String utf8 = super.readUTF8(arg0, arg1);
+        if(!anySyntheticAttributes && utf8.equals("Synthetic")) {
+            anySyntheticAttributes = true;
+        }
+        return utf8;
+    }
+
     /**
      * @param b
      * @param off
@@ -70,4 +92,8 @@
         return lastConstantHadWideIndex;
     }
 
+    public boolean hasSyntheticAttributes() {
+        return anySyntheticAttributes;
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Thu Dec 18 01:46:12 2008
@@ -18,6 +18,7 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -27,6 +28,7 @@
 import org.objectweb.asm.FieldVisitor;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Type;
 
 public class Segment implements ClassVisitor {
 
@@ -38,25 +40,18 @@
     private BcBands bcBands;
     private FileBands fileBands;
 
-    // The current class - only to be used when processing the classes
-    private String currentClass;
-    private String superClass;
-
     private final SegmentFieldVisitor fieldVisitor = new SegmentFieldVisitor();
     private final SegmentMethodVisitor methodVisitor = new SegmentMethodVisitor();
-    private final SegmentAnnotationVisitor annotationVisitor = new SegmentAnnotationVisitor();
     private Pack200ClassReader currentClassReader;
 
     public void pack(List classes, List files, OutputStream out)
             throws IOException, Pack200Exception {
         segmentHeader = new SegmentHeader();
         segmentHeader.setFile_count(files.size());
-        cpBands = new CpBands(segmentHeader);
-        attributeDefinitionBands = new AttributeDefinitionBands(segmentHeader,
-                cpBands);
+        cpBands = new CpBands(this);
+        attributeDefinitionBands = new AttributeDefinitionBands(this);
         icBands = new IcBands(segmentHeader, cpBands);
-        classBands = new ClassBands(segmentHeader, cpBands,
-                attributeDefinitionBands, classes.size());
+        classBands = new ClassBands(this, classes.size());
         bcBands = new BcBands(cpBands, this);
         fileBands = new FileBands(cpBands, segmentHeader, files);
 
@@ -90,12 +85,11 @@
 
     public void visit(int version, int access, String name, String signature,
             String superName, String[] interfaces) {
-        currentClass = name;
-        superClass = superName;
         bcBands.setCurrentClass(name);
         bcBands.setSuperClass(superName);
         segmentHeader.addMajorVersion(version);
-        classBands.addClass(version, access, name, superName, interfaces);
+        classBands.addClass(version, access, name, signature, superName,
+                interfaces);
     }
 
     public void visitSource(String source, String debug) {
@@ -107,8 +101,9 @@
 
     }
 
-    public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-        return annotationVisitor;
+    public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+        return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_CLASS,
+                desc, visible);
     }
 
     public void visitAttribute(Attribute arg0) {
@@ -141,12 +136,13 @@
      */
     public class SegmentMethodVisitor implements MethodVisitor {
 
-        public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-            return annotationVisitor;
+        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(
+                    MetadataBandGroup.CONTEXT_METHOD, desc, visible);
         }
 
         public AnnotationVisitor visitAnnotationDefault() {
-            return annotationVisitor;
+            return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_METHOD);
         }
 
         public void visitAttribute(Attribute arg0) {
@@ -181,9 +177,10 @@
             classBands.addMaxStack(maxStack, maxLocals);
         }
 
-        public AnnotationVisitor visitParameterAnnotation(int arg0,
-                String arg1, boolean arg2) {
-            return annotationVisitor;
+        public AnnotationVisitor visitParameterAnnotation(int parameter,
+                String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(
+                    MetadataBandGroup.CONTEXT_METHOD, parameter, desc, visible);
         }
 
         public void visitTryCatchBlock(Label start, Label end, Label handler,
@@ -254,36 +251,170 @@
 
     public class SegmentAnnotationVisitor implements AnnotationVisitor {
 
-        public void visit(String arg0, Object arg1) {
-            // TODO Auto-generated method stub
-
-        }
-
-        public AnnotationVisitor visitAnnotation(String arg0, String arg1) {
-            // TODO Auto-generated method stub
-            return null;
-        }
-
-        public AnnotationVisitor visitArray(String arg0) {
-            // TODO Auto-generated method stub
-            return null;
+        private int context = -1;
+        private int parameter = -1;
+        private String desc;
+        private boolean visible;
+
+        private final List nameRU = new ArrayList();
+        private final List T = new ArrayList(); // tags
+        private final List values = new ArrayList();
+        private final List caseArrayN = new ArrayList();
+        private final List nestTypeRS = new ArrayList();
+        private final List nestNameRU = new ArrayList();
+        private final List nestPairN = new ArrayList();
+
+
+        public SegmentAnnotationVisitor(int context, String desc,
+                boolean visible) {
+            this.context = context;
+            this.desc = desc;
+            this.visible = visible;
+        }
+
+        public SegmentAnnotationVisitor(int context) {
+            this.context = context;
+        }
+
+        public SegmentAnnotationVisitor(int context, int parameter,
+                String desc, boolean visible) {
+            this.context = context;
+            this.parameter = parameter;
+            this.desc = desc;
+            this.visible = visible;
+        }
+
+        public void visit(String name, Object value) {
+            nameRU.add(name);
+            values.add(value);
+            addTag(value);
+        }
+
+        private void addTag(Object value) {
+            if(value instanceof Integer) {
+                T.add("I");
+            } else if (value instanceof Double) {
+                T.add("D");
+            } else if (value instanceof Float) {
+                T.add("F");
+            } else if (value instanceof Long) {
+                T.add("J");
+            } else if (value instanceof Byte) {
+                T.add("B");
+            } else if (value instanceof Character) {
+                T.add("C");
+            } else if (value instanceof Short) {
+                T.add("S");
+            } else if (value instanceof Boolean) {
+                T.add("Z");
+            } else if (value instanceof String) {
+                T.add("s");
+            } else if (value instanceof Type) {
+                T.add("c");
+            }
+        }
+
+        public AnnotationVisitor visitAnnotation(String name, String desc) {
+            T.add("@");
+            nameRU.add(name);
+            nestTypeRS.add(desc);
+            nestPairN.add(new Integer(0));
+            return new AnnotationVisitor() {
+                public void visit(String name, Object value) {
+                    Integer numPairs = (Integer) nestPairN.remove(nestPairN.size() - 1);
+                    nestPairN.add(new Integer(numPairs.intValue() + 1));
+                    nestNameRU.add(name);
+                    values.add(value);
+                    addTag(value);
+                }
+
+                public AnnotationVisitor visitAnnotation(String arg0,
+                        String arg1) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public AnnotationVisitor visitArray(String arg0) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public void visitEnd() {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public void visitEnum(String name, String desc, String value) {
+                    Integer numPairs = (Integer) nestPairN.remove(nestPairN.size() - 1);
+                    nestPairN.add(new Integer(numPairs.intValue() + 1));
+                    T.add("e");
+                    nestNameRU.add(name);
+                    values.add(desc);
+                    values.add(value);
+                }
+            };
+        }
+
+        public AnnotationVisitor visitArray(String name) {
+            T.add("[");
+            nameRU.add(name);
+            caseArrayN.add(new Integer(0));
+            return new AnnotationVisitor() {
+                public void visit(String name, Object value) {
+                    Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
+                    caseArrayN.add(new Integer(numCases.intValue() + 1));
+                    nameRU.add(name);
+                    values.add(value);
+                    addTag(value);
+                }
+
+                public AnnotationVisitor visitAnnotation(String arg0,
+                        String arg1) {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public AnnotationVisitor visitArray(String arg0) {
+                    throw new RuntimeException("Not yet supported");
+//                    return null;
+                }
+
+                public void visitEnd() {
+                    throw new RuntimeException("Not yet supported");
+                }
+
+                public void visitEnum(String name, String desc, String value) {
+                    Integer numCases = (Integer) caseArrayN.remove(caseArrayN.size() - 1);
+                    caseArrayN.add(new Integer(numCases.intValue() + 1));
+                    T.add("e");
+                    nameRU.add(name);
+                    values.add(desc);
+                    values.add(value);
+                }
+            };
         }
 
         public void visitEnd() {
-            // TODO Auto-generated method stub
-
+            if (desc == null) {
+                Segment.this.classBands.addAnnotationDefault(nameRU, T, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            } else if(parameter != -1) {
+                Segment.this.classBands.addParameterAnnotation(parameter, desc, visible, nameRU, T, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            } else {
+                Segment.this.classBands.addAnnotation(context, desc, visible, nameRU, T, values, caseArrayN, nestTypeRS, nestNameRU, nestPairN);
+            }
         }
 
-        public void visitEnum(String arg0, String arg1, String arg2) {
-            // TODO Auto-generated method stub
-
+        public void visitEnum(String name, String desc, String value) {
+            T.add("e");
+            nameRU.add(name);
+            values.add(desc);
+            values.add(value);
         }
     }
 
     public class SegmentFieldVisitor implements FieldVisitor {
 
-        public AnnotationVisitor visitAnnotation(String arg0, boolean arg1) {
-            return annotationVisitor;
+        public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
+            return new SegmentAnnotationVisitor(MetadataBandGroup.CONTEXT_FIELD,
+                    desc, visible);
         }
 
         public void visitAttribute(Attribute arg0) {
@@ -299,4 +430,24 @@
     public boolean lastConstantHadWideIndex() {
         return currentClassReader.lastConstantHadWideIndex();
     }
+
+    public CpBands getCpBands() {
+        return cpBands;
+    }
+
+    public SegmentHeader getSegmentHeader() {
+        return segmentHeader;
+    }
+
+    public AttributeDefinitionBands getAttrBands() {
+        return attributeDefinitionBands;
+    }
+
+    public IcBands getIcBands() {
+        return icBands;
+    }
+
+    public Pack200ClassReader getCurrentClassReader() {
+        return currentClassReader;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java Thu Dec 18 01:46:12 2008
@@ -355,8 +355,6 @@
                 bcEscRefCount);
         bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
         bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
-
-
     }
 
     public void unpack() throws Pack200Exception {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/ClassBands.java Thu Dec 18 01:46:12 2008
@@ -308,7 +308,7 @@
                 Codec.UNSIGNED5, methodAttrCounts);
         int callCount = getCallCount(methodAttrIndexes, methodFlags,
                 AttributeLayout.CONTEXT_METHOD);
-        methodAttrCalls = decodeBandInt("code_attr_calls", in, Codec.UNSIGNED5,
+        methodAttrCalls = decodeBandInt("method_attr_calls", in, Codec.UNSIGNED5,
                 callCount);
 
         // assign empty method attributes

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationDefaultAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationDefaultAttribute.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationDefaultAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationDefaultAttribute.java Thu Dec 18 01:46:12 2008
@@ -18,6 +18,8 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * AnnotationDefault class file attribute
@@ -57,4 +59,15 @@
         return this == obj;
     }
 
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        List nested = new ArrayList();
+        nested.add(attributeName);
+        nested.addAll(element_value.getClassFileEntries());
+        ClassFileEntry[] nestedEntries = new ClassFileEntry[nested.size()];
+        for (int i = 0; i < nestedEntries.length; i++) {
+            nestedEntries[i] = (ClassFileEntry) nested.get(i);
+        }
+        return nestedEntries;
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationsAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationsAttribute.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationsAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/AnnotationsAttribute.java Thu Dec 18 01:46:12 2008
@@ -18,6 +18,8 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Abstract superclass for Annotations attributes
@@ -29,10 +31,10 @@
      */
     public static class Annotation {
 
-        private int num_pairs;
-        private CPUTF8[] element_names;
-        private ElementValue[] element_values;
-        private CPUTF8 type;
+        private final int num_pairs;
+        private final CPUTF8[] element_names;
+        private final ElementValue[] element_values;
+        private final CPUTF8 type;
 
         // Resolved values
         private int type_index;
@@ -75,12 +77,21 @@
             }
         }
 
+        public List getClassFileEntries() {
+            List entries = new ArrayList();
+            for (int i = 0; i < element_names.length; i++) {
+                entries.add(element_names[i]);
+                entries.addAll(element_values[i].getClassFileEntries());
+            }
+            entries.add(type);
+            return entries;
+        }
     }
 
     public static class ElementValue {
 
-        private Object value;
-        private int tag;
+        private final Object value;
+        private final int tag;
 
         // resolved value index if it's a constant
         private int constant_value_index = -1;
@@ -90,6 +101,25 @@
             this.value = value;
         }
 
+        public List getClassFileEntries() {
+            List entries = new ArrayList(1);
+            if(value instanceof CPNameAndType) {
+                // used to represent enum, so don't include the actual CPNameAndType
+                entries.add(((CPNameAndType)value).name);
+                entries.add(((CPNameAndType)value).descriptor);
+            } else if(value instanceof ClassFileEntry) {
+                entries.add(value);
+            } else if (value instanceof ElementValue[]) {
+                ElementValue[] values = (ElementValue[]) value;
+                for (int i = 0; i < values.length; i++) {
+                    entries.addAll(values[i].getClassFileEntries());
+                }
+            } else if (value instanceof Annotation) {
+                entries.addAll(((Annotation)value).getClassFileEntries());
+            }
+            return entries;
+        }
+
         public void resolve(ClassConstantPool pool) {
             if (value instanceof CPConstant) {
                 ((CPConstant) value).resolve(pool);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleAnnotationsAttribute.java Thu Dec 18 01:46:12 2008
@@ -18,6 +18,8 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Annotations class file attribute, either a RuntimeVisibleAnnotations
@@ -66,4 +68,17 @@
     public boolean equals(Object obj) {
         return this == obj;
     }
+
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        List nested = new ArrayList();
+        nested.add(attributeName);
+        for (int i = 0; i < annotations.length; i++) {
+            nested.addAll(annotations[i].getClassFileEntries());
+        }
+        ClassFileEntry[] nestedEntries = new ClassFileEntry[nested.size()];
+        for (int i = 0; i < nestedEntries.length; i++) {
+            nestedEntries[i] = (ClassFileEntry) nested.get(i);
+        }
+        return nestedEntries;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleParameterAnnotationsAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleParameterAnnotationsAttribute.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleParameterAnnotationsAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/RuntimeVisibleorInvisibleParameterAnnotationsAttribute.java Thu Dec 18 01:46:12 2008
@@ -18,6 +18,8 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
  * Paramenter annotations class file attribute, either a
@@ -98,10 +100,31 @@
             return length;
         }
 
+        public List getClassFileEntries() {
+            List nested = new ArrayList();
+            for (int i = 0; i < annotations.length; i++) {
+                nested.addAll(annotations[i].getClassFileEntries());
+            }
+            return nested;
+        }
+
     }
 
     public boolean equals(Object obj) {
         return this == obj;
     }
 
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        List nested = new ArrayList();
+        nested.add(attributeName);
+        for (int i = 0; i < parameter_annotations.length; i++) {
+            nested.addAll(parameter_annotations[i].getClassFileEntries());
+        }
+        ClassFileEntry[] nestedEntries = new ClassFileEntry[nested.size()];
+        for (int i = 0; i < nestedEntries.length; i++) {
+            nestedEntries[i] = (ClassFileEntry) nested.get(i);
+        }
+        return nestedEntries;
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ReferenceForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ReferenceForm.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ReferenceForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ReferenceForm.java Thu Dec 18 01:46:12 2008
@@ -43,6 +43,9 @@
         ClassFileEntry[] nested = null;
         nested = new ClassFileEntry[] { globalPool.getConstantPoolEntry(
                 getPoolID(), offset) };
+        if(nested[0] == null) {
+            throw new NullPointerException("Null nested entries are not allowed");
+        }
         byteCode.setNested(nested);
         byteCode.setNestedPositions(new int[][] { { 0, 2 } });
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ArchiveTest.java Thu Dec 18 01:46:12 2008
@@ -25,6 +25,7 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.net.URISyntaxException;
+import java.util.Enumeration;
 import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarInputStream;
@@ -38,12 +39,11 @@
 
 public class ArchiveTest extends TestCase {
 
-    File file;
     JarInputStream in;
     OutputStream out;
+    File file;
 
-    public void testHelloWorld() throws IOException, Pack200Exception,
-            URISyntaxException {
+    public void testHelloWorld() throws IOException, Pack200Exception, URISyntaxException {
         in = new JarInputStream(
                 Archive.class
                         .getResourceAsStream("/org/apache/harmony/pack200/tests/hw.jar"));
@@ -92,7 +92,87 @@
         }
         reader1.close();
         reader2.close();
+    }
+
+    public void testSQL() 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);
+        new Archive(in, out, false).pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("sqlout", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2, out2);
+        archive.unpack();
+        JarFile jarFile = new JarFile(file2);
+        file2.deleteOnExit();
 
+        JarFile jarFile2 = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/sqlUnpacked.jar").toURI()));
+
+        compareFiles(jarFile, jarFile2);
+    }
+
+    public void testJNDI() throws IOException, Pack200Exception, URISyntaxException {
+        in = new JarInputStream(Archive.class
+                .getResourceAsStream("/org/apache/harmony/pack200/tests/jndi.jar"));
+        file = File.createTempFile("jndi", ".pack");
+        out = new FileOutputStream(file);
+        new Archive(in, out, false).pack();
+        in.close();
+        out.close();
+
+        // now unpack
+        InputStream in2 = new FileInputStream(file);
+        File file2 = File.createTempFile("jndiout", ".jar");
+        JarOutputStream out2 = new JarOutputStream(new FileOutputStream(file2));
+        org.apache.harmony.unpack200.Archive archive = new org.apache.harmony.unpack200.Archive(in2, out2);
+        archive.unpack();
+        JarFile jarFile = new JarFile(file2);
+        file2.deleteOnExit();
+        JarFile jarFile2 = new JarFile(new File(Archive.class.getResource(
+                "/org/apache/harmony/pack200/tests/jndiUnpacked.jar").toURI()));
+
+        compareFiles(jarFile, jarFile2);
+    }
+
+    private void compareFiles(JarFile jarFile, JarFile jarFile2)
+            throws IOException {
+        Enumeration entries = jarFile.entries();
+        while (entries.hasMoreElements()) {
+
+            JarEntry entry = (JarEntry) entries.nextElement();
+            assertNotNull(entry);
+
+            String name = entry.getName();
+            JarEntry entry2 = jarFile2.getJarEntry(name);
+            assertNotNull(entry2);
+            if(!name.equals("META-INF/MANIFEST.MF")) { // Manifests aren't necessarily byte-for-byte identical
+
+                InputStream ours = jarFile.getInputStream(entry);
+                InputStream expected = 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 files differ for " + name, line2, line1);
+                    line1 = reader1.readLine();
+                    line2 = reader2.readLine();
+                    i++;
+                }
+                reader1.close();
+                reader2.close();
+            }
+        }
     }
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hysock.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hysock.c?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hysock.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/unix/hysock.c Thu Dec 18 01:46:12 2008
@@ -2489,17 +2489,13 @@
   I_32 bytesRec = 0;
 
   bytesRec = recv (SOCKET_CAST (sock), buf, nbyte, flags);
-  if (-1 == bytesRec)
-    {
-      I_32 err = errno;
-      HYSOCKDEBUG ("<recv failed, err=%d>\n", err);
-      return portLibrary->error_set_last_error (portLibrary, err,
-                                                findError (err));
-    }
-  else
-    {
-      return bytesRec;
-    }
+  if (-1 == bytesRec) {
+    I_32 err = errno;
+    HYSOCKDEBUG ("<recv failed, err=%d>\n", err);
+    return portLibrary->error_set_last_error (portLibrary, err, findError(err));
+  } else {
+    return bytesRec;
+  }
 }
 
 #undef CDEV_CURRENT_FUNCTION

Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyerrorhelpers.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyerrorhelpers.c?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyerrorhelpers.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyerrorhelpers.c Thu Dec 18 01:46:12 2008
@@ -101,6 +101,7 @@
   rc =
     MultiByteToWideChar (CP_ACP, MB_PRECOMPOSED, buffer, -1, ubuffer,
 			 HYERROR_DEFAULT_BUFFER_SIZE);
+
   if (rc == 0)
     {
       const char *format;
@@ -142,16 +143,16 @@
 	{
 	  if ((out + 3) >= HYERROR_DEFAULT_BUFFER_SIZE)
 	    break;
-	  message[out++] = (char) (0x80 | (ch & 0x3f));
 	  message[out++] = (char) (0xc0 | (ch >> 6));
+	  message[out++] = (char) (0x80 | (ch & 0x3f));
 	}
       else
 	{
 	  if ((out + 4) >= HYERROR_DEFAULT_BUFFER_SIZE)
 	    break;
-	  message[out++] = (char) (0x80 | (ch & 0x3f));
-	  message[out++] = (char) (0x80 | ((ch >> 6) & 0x3f));
 	  message[out++] = (char) (0xe0 | (ch >> 12));
+	  message[out++] = (char) (0x80 | ((ch >> 6) & 0x3f));
+	  message[out++] = (char) (0x80 | (ch & 0x3f));
 	}
     }
   message[out] = '\0';

Modified: harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c?rev=727683&r1=727682&r2=727683&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c (original)
+++ harmony/enhanced/classlib/branches/java6/modules/portlib/src/main/native/port/windows/hyfile.c Thu Dec 18 01:46:12 2008
@@ -405,6 +405,7 @@
 {
     int len;
     int wlen;
+    int absLen;
     char *canonicalpath;
     int srcArrayCount=0;
     int destArrayCount=0;
@@ -413,8 +414,10 @@
     int *slashStack; //record position of every separator.
     
     // Buffer to store absolute path name.
-    char absPath[ABS_PATH_BUF_LEN];
- 
+    wchar_t *absPath = 0;
+    wchar_t *temp = 0;
+    int i = 0;
+
     if (!path) {
         *pathW = (void*) 0;
         return;
@@ -428,15 +431,7 @@
         return;
     }
 
-    // calculate an absolute path first
-    if (!GetFullPathNameA(path, ABS_PATH_BUF_LEN, absPath, (void*) 0))
-    {
-        // error occurred
-        *pathW = (void*) 0;
-        return;
-    }
-
-    len = strlen(absPath);
+    len = strlen(path);
 
     slashStack = portLibrary->mem_allocate_memory(portLibrary, len*sizeof(int));
     canonicalpath = portLibrary->mem_allocate_memory(portLibrary, len+5);
@@ -445,15 +440,15 @@
 
     for(srcArrayCount=0,destArrayCount=4;srcArrayCount<len;srcArrayCount++){
         // we have an absolute path already.
-        if(absPath[srcArrayCount]=='.'){
+        if(path[srcArrayCount]=='.'){
             // count the dots following last separator.
-            if(dotsCount>0 || absPath[srcArrayCount-1]=='\\'){
+            if(dotsCount>0 || path[srcArrayCount-1]=='\\'){
                 dotsCount++;
                 continue;
             }
         }
         // deal with the dots when we meet next separator.
-        if(absPath[srcArrayCount]=='\\'){
+        if(path[srcArrayCount]=='\\'){
             if(dotsCount == 1){
                 dotsCount = 0;
                 continue;
@@ -476,17 +471,40 @@
             canonicalpath[destArrayCount++]='.';
             dotsCount--;
         }
-        canonicalpath[destArrayCount++]=absPath[srcArrayCount];
+        canonicalpath[destArrayCount++]=path[srcArrayCount];
     }
     while(canonicalpath[destArrayCount-1] == '.'){
         destArrayCount--;
     }        
     canonicalpath[destArrayCount]='\0';
+
     wlen = MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, 0);
     *pathW = portLibrary->mem_allocate_memory(portLibrary, wlen*sizeof(wchar_t));
     MultiByteToWideChar(CP_UTF8, 0, canonicalpath, -1, *pathW, wlen);
     portLibrary->mem_free_memory(portLibrary, canonicalpath);
     portLibrary->mem_free_memory(portLibrary, slashStack);
+
+    // calculate an absolute path
+    // call unicode version explicitly, should not include "\\?\" prefix
+    absLen = GetFullPathNameW(*pathW + 4, 0, absPath, (void*) 0);
+    absPath = portLibrary->mem_allocate_memory(portLibrary, (absLen + 4)*sizeof(wchar_t));
+    absLen = GetFullPathNameW(*pathW + 4, absLen, absPath + 4, (void*) 0);
+
+    if (absLen == 0)
+    {
+        // error occurred
+        *pathW = (void*) 0;
+        return;
+    }
+    // add prefix "\\?\"
+    for (i = 0; i < 4; ++i) {
+        absPath[i] = (*pathW)[i];
+    }
+
+    temp = *pathW;
+    *pathW = absPath;
+    absPath = temp;
+    portLibrary->mem_free_memory(portLibrary, absPath);
 }
 
 #undef ABS_PATH_BUF_LEN
@@ -508,7 +526,6 @@
 {
     int returnVar=0;
     wchar_t *pathW;
-
     convert_path_to_unicode(portLibrary, path, &pathW);
     returnVar = CreateDirectoryW (pathW, 0);
     portLibrary->mem_free_memory(portLibrary, pathW);



Mime
View raw message