harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r673381 - /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/
Date Wed, 02 Jul 2008 13:02:17 GMT
Author: sjanuary
Date: Wed Jul  2 06:02:16 2008
New Revision: 673381

URL: http://svn.apache.org/viewvc?rev=673381&view=rev
Log:
Pack200 - more progress in packing class bands

Added:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java   (with props)
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java   (with props)
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java   (with props)
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java   (with props)
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java   (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPString.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Archive.java Wed Jul  2 06:02:16 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.harmony.pack200;
 
+import java.io.BufferedOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -41,11 +42,11 @@
 
     public Archive(JarInputStream inputStream, OutputStream outputStream) {
         this.inputStream = inputStream;
-        this.outputStream = outputStream;
+        this.outputStream = new BufferedOutputStream(outputStream);
     }
 
     public Archive(JarFile jarFile, OutputStream outputStream) {
-        this.outputStream = outputStream;
+        this.outputStream = new BufferedOutputStream(outputStream);
         this.jarFile = jarFile;
         inputStream = null;
     }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/AttributeDefinitionBands.java Wed Jul  2 06:02:16 2008
@@ -101,8 +101,8 @@
         for (int i = 0; i < attributeDefinitionLayout.length; i++) {
             AttributeDefinition def = (AttributeDefinition) attributeDefinitions.get(i);
             attributeDefinitionHeader[i] = def.contextType | (def.index << 2);
-            attributeDefinitionName[i] = cpBands.getCpUtf8(def.name).getIndex();
-            attributeDefinitionLayout[i] = cpBands.getCpUtf8(def.layout).getIndex();
+            attributeDefinitionName[i] = cpBands.getCPUtf8(def.name).getIndex();
+            attributeDefinitionLayout[i] = cpBands.getCPUtf8(def.layout).getIndex();
         }
 
         out.write(encodeBandInt(attributeDefinitionHeader, Codec.BYTE1));
@@ -175,4 +175,9 @@
 
     }
 
+    public int getIndex(Unknown attr) {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BandSet.java Wed Jul  2 06:02:16 2008
@@ -37,4 +37,41 @@
         return defaultCodec.encode(ints);
     }
 
+    public boolean isPredictableSourceFileName(String className, String sourceFileName) {
+        if (className.indexOf(".") != -1) {
+            className = className.substring(className.lastIndexOf(".") + 1);
+        }
+        if (className.indexOf("$") != -1) {
+            className = className.substring(0, className.indexOf("$"));
+        }
+        className += ".java";
+        return className.equals(sourceFileName);
+    }
+
+    protected byte[] encodeFlags(long[] flags, BHSDCodec loCodec, BHSDCodec hiCodec,
+            boolean haveHiFlags) throws Pack200Exception {
+        if(!haveHiFlags) {
+            int[] loBits = new int[flags.length];
+            for (int i = 0; i < flags.length; i++) {
+                loBits[i] = (int) flags[i];
+            }
+            return encodeBandInt(loBits, loCodec);
+        } else {
+
+            int[] hiBits = new int[flags.length];
+            int[] loBits = new int[flags.length];
+            for (int i = 0; i < flags.length; i++) {
+                long l = flags[i];
+                hiBits[i] = (int) (l >> 32);
+                loBits[i] = (int) l;
+            }
+            byte[] hi = encodeBandInt(hiBits, hiCodec);
+            byte[] lo = encodeBandInt(loBits, loCodec);
+            byte[] total = new byte[hi.length + lo.length];
+            System.arraycopy(hi, 0, total, 0, hi.length);
+            System.arraycopy(lo, 0, total, hi.length + 1, lo.length);
+            return total;
+        }
+    }
+
 }

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java?rev=673381&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java (added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java Wed Jul  2 06:02:16 2008
@@ -0,0 +1,22 @@
+/*
+ *  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.pack200;
+
+
+public abstract class CPConstant extends ConstantPoolEntry implements Comparable {
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPConstant.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java?rev=673381&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java (added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java Wed Jul  2 06:02:16 2008
@@ -0,0 +1,35 @@
+/*
+ *  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.pack200;
+
+
+public class CPDouble extends CPConstant {
+
+    private double theDouble;
+
+    public CPDouble(double theDouble) {
+        this.theDouble = theDouble;
+    }
+
+    public int compareTo(Object obj) {
+        return Double.compare(theDouble, ((CPDouble)obj).theDouble);
+    }
+
+    public double getDouble() {
+        return theDouble;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPDouble.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java?rev=673381&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java (added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java Wed Jul  2 06:02:16 2008
@@ -0,0 +1,35 @@
+/*
+ *  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.pack200;
+
+
+public class CPFloat extends CPConstant {
+
+    private float theFloat;
+
+    public CPFloat(float theFloat) {
+        this.theFloat = theFloat;
+    }
+
+    public int compareTo(Object obj) {
+        return Float.compare(theFloat, ((CPFloat)obj).theFloat);
+    }
+
+    public float getFloat() {
+        return theFloat;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPFloat.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java?rev=673381&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java (added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java Wed Jul  2 06:02:16 2008
@@ -0,0 +1,35 @@
+/*
+ *  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.pack200;
+
+
+public class CPInt extends CPConstant {
+
+    private int theInt;
+
+    public CPInt(int theInt) {
+        this.theInt = theInt;
+    }
+
+    public int compareTo(Object obj) {
+        return theInt - ((CPInt)obj).theInt;
+    }
+
+    public int getInt() {
+        return theInt;
+    }
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPInt.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java?rev=673381&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java (added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java Wed Jul  2 06:02:16 2008
@@ -0,0 +1,36 @@
+/*
+ *  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.pack200;
+
+
+public class CPLong extends CPConstant {
+
+    private long theLong;
+
+    public CPLong(long theLong) {
+        this.theLong = theLong;
+    }
+
+    public int compareTo(Object obj) {
+        return (int) (theLong - ((CPLong)obj).theLong);
+    }
+
+    public long getLong() {
+        return theLong;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPLong.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPString.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPString.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPString.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CPString.java Wed Jul  2 06:02:16 2008
@@ -17,7 +17,7 @@
 package org.apache.harmony.pack200;
 
 
-public class CPString extends ConstantPoolEntry implements Comparable {
+public class CPString extends CPConstant {
 
     private final String string;
     private final CPUTF8 utf8;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Wed Jul  2 06:02:16 2008
@@ -16,19 +16,77 @@
  */
 package org.apache.harmony.pack200;
 
+import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
 
+import org.apache.bcel.Constants;
+import org.apache.bcel.classfile.Attribute;
+import org.apache.bcel.classfile.Code;
+import org.apache.bcel.classfile.CodeException;
+import org.apache.bcel.classfile.Constant;
+import org.apache.bcel.classfile.ConstantValue;
+import org.apache.bcel.classfile.Deprecated;
+import org.apache.bcel.classfile.ExceptionTable;
 import org.apache.bcel.classfile.Field;
+import org.apache.bcel.classfile.InnerClasses;
 import org.apache.bcel.classfile.JavaClass;
+import org.apache.bcel.classfile.LineNumberTable;
+import org.apache.bcel.classfile.LocalVariableTable;
 import org.apache.bcel.classfile.Method;
-
+import org.apache.bcel.classfile.Signature;
+import org.apache.bcel.classfile.SourceFile;
+import org.apache.bcel.classfile.Unknown;
 
 public class ClassBands extends BandSet {
 
+    private SegmentHeader header;
     private final CpBands cpBands;
+    private AttributeDefinitionBands attrBands;
+
+    private final CPClass[] class_this;
+    private final CPClass[] class_super;
+    private final CPClass[][] class_interface;
+    private final int[] class_interface_count;
+
+    private final int[] major_versions;
+    private final int[] minor_versions;
+
+    private long[] class_flags;
+    private List classSourceFile = new ArrayList();
+    private List classEnclosingMethod = new ArrayList();
+    private List classSignature = new ArrayList();
+
+    private List classFileVersionMinor = new ArrayList();
+    private List classFileVersionMajor = new ArrayList();
+
+
+    private final int[] class_field_count;
+    private final CPNameAndType[][] field_descr;
+    private List fieldFlags = new ArrayList();
+    private List fieldConstantValueKQ = new ArrayList();
+
+    private final int[] class_method_count;
+    private final CPNameAndType[][] method_descr;
+    private List methodFlags = new ArrayList();
+
+    private List codeHeaders = new ArrayList();
+    private List codeMaxStack = new ArrayList();
+    private List codeMaxLocals = new ArrayList();
+    private List codeHandlerCount = new ArrayList();
+    private List codeHandlerStartP = new ArrayList();
+    private List codeHandlerEndPO = new ArrayList();
+    private List codeHandlerCatchPO = new ArrayList();
+    private List codeHandlerClass = new ArrayList();
+    private List codeFlags = new ArrayList();
+
 
-    public ClassBands(CpBands cpBands, int numClasses) {
+
+    public ClassBands(SegmentHeader header, CpBands cpBands, AttributeDefinitionBands attrBands, int numClasses) {
+        this.header = header;
         this.cpBands = cpBands;
+        this.attrBands = attrBands;
         class_this = new CPClass[numClasses];
         class_super = new CPClass[numClasses];
         class_interface_count = new int[numClasses];
@@ -37,28 +95,13 @@
         class_method_count = new int[numClasses];
         field_descr = new CPNameAndType[numClasses][];
         method_descr = new CPNameAndType[numClasses][];
+        minor_versions = new int[numClasses];
+        major_versions = new int[numClasses];
+        class_flags = new long[numClasses];
     }
 
     private int index = 0;
 
-    private final CPClass[] class_this;
-    private final CPClass[] class_super;
-    private final int[] class_interface_count;
-    private final CPClass[][] class_interface;
-    private final int[] class_field_count;
-    private final int[] class_method_count;
-    private final CPNameAndType[][] field_descr;
-    private final CPNameAndType[][] method_descr;
-
-    public void finaliseBands() {
-
-    }
-
-    public void pack(OutputStream out) {
-        // TODO Auto-generated method stub
-
-    }
-
     public void addClass(JavaClass obj) {
         class_this[index] = cpBands.getCPClass(obj.getClassName());
         class_super[index] = cpBands.getCPClass(obj.getSuperclassName());
@@ -67,22 +110,450 @@
         for (int i = 0; i < interfaces.length; i++) {
             class_interface[index][i] = cpBands.getCPClass(interfaces[i]);
         }
+        addClassAttributes(obj);
+
+        addFields(obj.getFields());
+
+        Method[] methods = obj.getMethods();
+        addMethods(methods);
+        addCode(methods);
+        index++;
+    }
+
+    private void addClassAttributes(JavaClass obj) {
+        int flags = obj.getAccessFlags();
+        Attribute[] attributes = obj.getAttributes();
+        for (int i = 0; i < attributes.length; i++) {
+            if(attributes[i] instanceof SourceFile) {
+                flags |= (1<<17);
+                String sourceFileName = ((SourceFile)attributes[i]).getSourceFileName();
+                if(isPredictableSourceFileName(obj.getClassName(), sourceFileName)) {
+                    classSourceFile.add(null);
+                } else {
+                    classSourceFile.add(cpBands.getCPUtf8(sourceFileName));
+                }
+//            } else if (attributes[i] instanceof EnclosingMethod) {
+//                flags |= (1<<18);
+            } else if (attributes[i] instanceof Signature) {
+                flags |= (1<<19);
+                classSignature.add(cpBands.getCPSignature(((Signature)attributes[i]).getSignature()));
+            } else if (attributes[i] instanceof Deprecated) {
+                flags |= (1<<20);
+//            } else if (attributes[i] instanceof RuntimeVisibleAnnotations) {
+//                flags |= (1<<21);
+//            } else if (attributes[i] instanceof RuntimeInvisibleAnnotations) {
+//                flags |= (1<<22);
+            } else if (attributes[i] instanceof InnerClasses) {
+                flags |= (1<<23);
+            } else if (attributes[i] instanceof Unknown) {
+                Unknown attr = (Unknown)attributes[i];
+                int index = attrBands.getIndex(attr);
+                flags |= (1<<index);
+
+            }
+        }
+        minor_versions[index] = obj.getMinor();
+        major_versions[index] = obj.getMajor();
+        class_flags[index] = flags;
+
+    }
+
+    private void addMethods(Method[] methods) {
+        class_method_count[index] = methods.length;
+        method_descr[index] = new CPNameAndType[methods.length];
+        for (int i = 0; i < methods.length; i++) {
+            method_descr[index][i] = cpBands.getCPNameAndType(methods[i]
+                    .getName(), methods[i].getSignature());
+
+            int flags = methods[i].getAccessFlags();
+            Attribute[] attributes = methods[i].getAttributes();
+            for (int j = 0; j < attributes.length; j++) {
+                if (attributes[j] instanceof Code) {
+                    flags |= (1<<17);
+                } else if (attributes[j] instanceof ExceptionTable) {
+                    flags |= (1<<18);
+                } else if (attributes[j] instanceof Signature) {
+                    flags |= (1<<19);
+                } else if (attributes[j] instanceof Deprecated) {
+                    flags |= (1<<20);
+//                } else if (attributes[j] instanceof RuntimeVisibleAnnotations) {
+//                    flags |= (1<<21);
+//                } else if (attributes[j] instanceof RuntimeInvisibleAnnotations) {
+//                    flags |= (1<<22);
+//                } else if (attributes[j] instanceof RuntimeVisibleParameterAnnotations) {
+//                    flags |= (1<<23);
+//                } else if (attributes[j] instanceof RuntimeInvisibleParameterAnnotations) {
+//                    flags |= (1<<24);
+//                } else if (attributes[j] instanceof AnnotationDefault) {
+//                    flags |= (1<<25);
+                } else if (attributes[j] instanceof Unknown) {
+                    Unknown attr = (Unknown)attributes[i];
+                    int index = attrBands.getIndex(attr);
+                    flags |= (1<<index);
+
+                }
+            }
+            methodFlags.add(new Long(flags));
+        }
+    }
 
-        Field[] fields = obj.getFields();
+    private void addFields(Field[] fields) {
         class_field_count[index] = fields.length;
         field_descr[index] = new CPNameAndType[fields.length];
         for (int i = 0; i < fields.length; i++) {
-            field_descr[index][i] = cpBands.getCPNameAndType(fields[i].getName(), fields[i].getSignature());
+            field_descr[index][i] = cpBands.getCPNameAndType(fields[i]
+                    .getName(), fields[i].getSignature());
+            int flags = fields[i].getAccessFlags();
+            Attribute[] attributes = fields[i].getAttributes();
+            for (int j = 0; j < attributes.length; j++) {
+                if (attributes[j] instanceof ConstantValue) {
+                    flags |= (1<<17);
+                    ConstantValue constV = ((ConstantValue)attributes[j]);
+                    Constant theConstant = constV.getConstantPool().getConstant(constV.getConstantValueIndex());
+                    CPConstant cpConstant = cpBands.getCPConstant(theConstant, constV.getConstantPool());
+                    fieldConstantValueKQ.add(cpConstant);
+                } else if (attributes[j] instanceof Signature) {
+                    flags |= (1<<19);
+                } else if (attributes[j] instanceof Deprecated) {
+                    flags |= (1<<20);
+//                } else if (attributes[j] instanceof RuntimeVisibleAnnotations) {
+//                    flags |= (1<<21);
+//                } else if (attributes[j] instanceof RuntimeInvisibleAnnotations) {
+//                    flags |= (1<<22);
+                } else if (attributes[j] instanceof Unknown) {
+                    Unknown attr = (Unknown)attributes[i];
+                    int index = attrBands.getIndex(attr);
+                    flags |= (1<<index);
+
+                }
+            }
+            fieldFlags.add(new Long(flags));
         }
 
-        Method[] methods = obj.getMethods();
-        class_method_count[index] = methods.length;
-        method_descr[index] = new CPNameAndType[methods.length];
+    }
+
+    private void addCode(Method[] methods) {
+
         for (int i = 0; i < methods.length; i++) {
-            method_descr[index][i] = cpBands.getCPNameAndType(methods[i].getName(), methods[i].getSignature());
+            Code code = methods[i].getCode();
+            if(code != null) {
+                int header = 0;
+                int maxLocals = code.getMaxLocals();
+                int maxStack = code.getMaxStack();
+                CodeException[] exceptions = code.getExceptionTable();
+                int handlers = exceptions.length;
+                if(handlers <= 2) {
+                    if (handlers == 0) {
+                        if(maxLocals < 11 && maxStack < 11) {
+                            header = 12*maxLocals + maxStack + 1;
+                        }
+                    } else if (handlers == 1) {
+                        if(maxLocals < 7 && maxStack < 7) {
+                            header = 8*maxLocals + maxStack + 145;
+                        }
+                    } else if (handlers == 2) {
+                        if(maxLocals < 6 && maxStack < 6) {
+                            header = 7*maxLocals + maxStack + 209;
+                        }
+                    }
+                }
+                codeHeaders.add(new Integer(header));
+                if(header == 0) {
+                    codeMaxStack.add(new Integer(maxStack));
+                    codeMaxLocals.add(new Integer(maxLocals));
+                    codeHandlerCount.add(new Integer(handlers));
+                }
+                for (int j = 0; j < exceptions.length; j++) {
+                    int startPC = exceptions[j].getStartPC();
+                    int endPC = exceptions[j].getEndPC();
+                    int catchPC = exceptions[j].getHandlerPC();
+                    int[] renumbered = renumberBCI(code.getCode());
+                    int renumberedStart = renumbered[startPC];
+                    int renumberedEnd = renumbered[endPC] - renumberedStart;
+                    int renumberedCatch = renumbered[catchPC] - renumberedEnd;
+                    codeHandlerStartP.add(new Integer(renumberedStart));
+                    codeHandlerEndPO.add(new Integer(renumberedEnd));
+                    codeHandlerCatchPO.add(new Integer(renumberedCatch));
+                    int catchType = exceptions[j].getCatchType();
+                    if(catchType == 0) {
+                        codeHandlerClass.add(null);
+                    } else {
+                        String className = methods[i].getConstantPool().getConstantString(catchType, Constants.CONSTANT_Class);
+                        codeHandlerClass.add(cpBands.getCPClass(className));
+                    }
+                }
+
+                int flags = 0;
+                Attribute[] attributes = methods[i].getAttributes();
+                for (int j = 0; j < attributes.length; j++) {
+                    if (attributes[j] instanceof LineNumberTable) {
+                        flags |= (1<<1);
+                    } else if (attributes[j] instanceof LocalVariableTable) {
+                        flags |= (1<<2);
+//                    } else if (attributes[j] instanceof LocalVariableTypeTable) {
+//                        flags |= (1<<3);
+                    } else if (attributes[j] instanceof Unknown) {
+                        Unknown attr = (Unknown)attributes[i];
+                        int index = attrBands.getIndex(attr);
+                        flags |= (1<<index);
+
+                    }
+                }
+                codeFlags.add(new Long(flags));
+            }
         }
+    }
 
-        index++;
+    private int[] listToArray(List integerList) {
+        int[] array = new int[integerList.size()];
+        for (int i = 0; i < array.length; i++) {
+            array[i] = ((Integer)integerList.get(i)).intValue();
+        }
+        return array;
+    }
+
+    private long[] longListToArray(List longList) {
+        long[] array = new long[longList.size()];
+        for (int i = 0; i < array.length; i++) {
+            array[i] = ((Long)longList.get(i)).longValue();
+        }
+        return array;
+    }
+
+    private int[] renumberBCI(byte[] code) {
+        int[] instructionBoundaries = getInstructionBoundaries(code);
+        int[] renumbered = new int[code.length];
+        int precedence = 1;
+        for (int i = 1; i < instructionBoundaries.length; i++) {
+            renumbered[instructionBoundaries[i]] = precedence;
+            precedence++;
+        }
+        for (int i = 1; i < renumbered.length; i++) {
+            if(renumbered[i] == 0) {
+                renumbered[i] = precedence;
+                precedence++;
+            }
+        }
+        return renumbered;
+    }
+
+    private int[] getInstructionBoundaries(byte[] code) {
+        List boundariesList = new ArrayList();
+        boolean wide = false;
+        for (int i = 0; i < code.length; i++) {
+            int b = code[i] & 0xFF;
+            boundariesList.add(new Integer(b));
+            if(b == Constants.WIDE) {
+                wide = true;
+            } else if (b == Constants.TABLESWITCH) {
+                int padding = (i + 1) % 4 == 0 ? 0 : 4 - i + 1;
+                i+= padding;
+                i+= 4;
+                byte b1 = code[i];
+                byte b2 = code[++i];
+                byte b3 = code[++i];
+                byte b4 = code[++i];
+                int low = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+                b1 = code[++i];
+                b2 = code[++i];
+                b3 = code[++i];
+                b4 = code[++i];
+                int high = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+                int jumpTableSize = 4 * (high - low + 1);
+                i += jumpTableSize;
+            } else if (b == Constants.LOOKUPSWITCH) {
+                int padding = (i + 1) % 4 == 0 ? 0 : 4 - i + 1;
+                i+= padding;
+                i+= 4;
+                byte b1 = code[i];
+                byte b2 = code[++i];
+                byte b3 = code[++i];
+                byte b4 = code[++i];
+                int npairs = (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
+                i += 8 * npairs;
+            } else {
+                if(b == 16 || b == 18 || (b >= 21 && b <= 25) || (b >= 54 && b <= 58) || b == 188) {
+                    i++;
+                    if(wide) {
+                        i++;
+                        wide = false;
+                    }
+                } else if (b == 17 || b == 19 || b == 20 || b== 132 || (b >= 153 && b <= 168)|| (b >= 178 && b <= 184) || b == 187 || b == 188 || b == 192 || b == 193 || b == 198 || b == 199) {
+                    i+=2;
+//                    don't think we need this...
+//                    if(wide) {
+//                        i+=2;
+//                        wide = false;
+//                    }
+                } else if (b == 185 || b == 200 || b == 201) {
+                    i+=4;
+                }
+            }
+        }
+        return listToArray(boundariesList);
+    }
+
+    public void finaliseBands() {
+        int defaultMinorVersion = header.getDefaultMinorVersion();
+        int defaultMajorVersion = header.getDefaultMajorVersion();
+
+        for (int i = 0; i < class_flags.length; i++) {
+            int major = major_versions[i];
+            int minor = minor_versions[i];
+            if(major != defaultMajorVersion || minor != defaultMinorVersion) {
+                class_flags[i] |= 1 << 24;
+                classFileVersionMajor.add(new Integer(major));
+                classFileVersionMinor.add(new Integer(minor));
+            }
+        }
+    }
+
+    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();
+        }
+        out.write(encodeBandInt(classThis, Codec.DELTA5));
+
+        int[] classSuper = new int[class_super.length];
+        for (int i = 0; i < classSuper.length; i++) {
+            classSuper[i] = class_super[i].getIndex();
+        }
+        out.write(encodeBandInt(classSuper, Codec.DELTA5));
+        out.write(encodeBandInt(class_interface_count, Codec.DELTA5));
+
+        int totalInterfaces = sum(class_interface_count);
+        int[] classInterface = new int[totalInterfaces];
+        int k = 0;
+        for (int i = 0; i < class_interface.length; i++) {
+            if(class_interface[i] != null) {
+                for (int j = 0; j < class_interface[i].length; j++) {
+                    CPClass cpClass = class_interface[i][j];
+                    classInterface[k] = cpClass.getIndex();
+                    k++;
+                }
+            }
+        }
+        out.write(encodeBandInt(classInterface, Codec.DELTA5));
+        out.write(encodeBandInt(class_field_count, Codec.DELTA5));
+        out.write(encodeBandInt(class_method_count, Codec.DELTA5));
+
+        int totalFields = sum(class_field_count);
+        int[] fieldDescr = new int[totalFields];
+        k = 0;
+        for (int i = 0; i < field_descr.length; i++) {
+            for (int j = 0; j < field_descr[i].length; j++) {
+                CPNameAndType descr = field_descr[i][j];
+                fieldDescr[k] = descr.getIndex();
+                k++;
+            }
+        }
+        out.write(encodeBandInt(fieldDescr, Codec.DELTA5));
+        writeFieldAttributeBands(out);
+
+        int totalMethods = sum(class_method_count);
+        int[] methodDescr = new int[totalMethods];
+        k = 0;
+        for (int i = 0; i < method_descr.length; i++) {
+            for (int j = 0; j < method_descr[i].length; j++) {
+                CPNameAndType descr = method_descr[i][j];
+                methodDescr[k] = descr.getIndex();
+                k++;
+            }
+        }
+        out.write(encodeBandInt(methodDescr, Codec.DELTA5));
+
+        writeMethodAttributeBands(out);
+        writeClassAttributeBands(out);
+        writeCodeBands(out);
+    }
+
+    private int sum(int[] ints) {
+        int sum = 0;
+        for (int i = 0; i < ints.length; i++) {
+            sum += ints[i];
+        }
+        return sum;
+    }
+
+    private void writeFieldAttributeBands(OutputStream out) throws IOException, Pack200Exception {
+        long[] field_flags = longListToArray(fieldFlags);
+        int[] field_constant_value = listToArray(fieldConstantValueKQ);
+
+        out.write(encodeFlags(field_flags, Codec.UNSIGNED5, Codec.UNSIGNED5, header.have_field_flags_hi()));
+    }
+
+    private void writeMethodAttributeBands(OutputStream out) throws IOException, Pack200Exception {
+        long[] method_flags = longListToArray(methodFlags);
+
+        out.write(encodeFlags(method_flags, Codec.UNSIGNED5, Codec.UNSIGNED5, header.have_method_flags_hi()));
+    }
+
+    private void writeClassAttributeBands(OutputStream out) throws IOException, Pack200Exception {
+        out.write(encodeFlags(class_flags, Codec.UNSIGNED5, Codec.UNSIGNED5, header.have_class_flags_hi()));
+        int[] class_source_file = new int[classSourceFile.size()];
+        for (int i = 0; i < class_source_file.length; i++) {
+            CPUTF8 sourceFile = (CPUTF8) classSourceFile.get(i);
+            if(sourceFile == null) {
+                class_source_file[i] = 0;
+            } else {
+                class_source_file[i] = sourceFile.getIndex() + 1;
+            }
+        }
+        out.write(encodeBandInt(class_source_file, Codec.UNSIGNED5));
+
+    }
+
+    private void writeCodeBands(OutputStream out) throws IOException, Pack200Exception {
+        int[] code_headers = listToArray(codeHeaders);
+        int[] code_max_stack = listToArray(codeMaxStack);
+        int[] code_max_na_locals = listToArray(codeMaxLocals);
+        int[] code_handler_count = listToArray(codeHandlerCount);
+        int[] code_handler_start_P = listToArray(codeHandlerStartP);
+        int[] code_handler_end_PO = listToArray(codeHandlerEndPO);
+        int[] code_handler_catch_PO = listToArray(codeHandlerCatchPO);
+        int[] code_handler_class = new int[codeHandlerClass.size()];
+        for (int j = 0; j < code_handler_class.length; j++) {
+            CPClass cpClass = (CPClass) codeHandlerClass.get(j);
+            code_handler_class[j] = cpClass == null ? 0 : cpClass.getIndex() + 1;
+        }
+        out.write(encodeBandInt(code_headers, Codec.BYTE1));
+        out.write(encodeBandInt(code_max_stack, Codec.UNSIGNED5));
+        out.write(encodeBandInt(code_max_na_locals, Codec.UNSIGNED5));
+        out.write(encodeBandInt(code_handler_count, Codec.UNSIGNED5));
+        out.write(encodeBandInt(code_handler_start_P, Codec.BCI5));
+        out.write(encodeBandInt(code_handler_end_PO, Codec.BRANCH5));
+        out.write(encodeBandInt(code_handler_catch_PO, Codec.BRANCH5));
+        out.write(encodeBandInt(code_handler_class, Codec.UNSIGNED5));
+        writeCodeAttributeBands(out);
+    }
+
+    private int[] flatten(int[][] twoDInts) {
+        int[] ints = new int[totalSize(twoDInts)];
+        int index = 0;
+        for (int i = 0; i < twoDInts.length; i++) {
+            for (int j = 0; j < twoDInts[i].length; j++) {
+                ints[index] = twoDInts[i][j];
+                index++;
+            }
+        }
+        return ints;
+    }
+
+    private int totalSize(int[][] ints) {
+        int count = 0;
+        for (int i = 0; i < ints.length; i++) {
+            for (int j = 0; j < ints[i].length; j++) {
+                count++;
+            }
+        }
+        return count;
+    }
+
+    private void writeCodeAttributeBands(OutputStream out) throws IOException, Pack200Exception {
+        long[] code_flags = longListToArray(codeFlags);
+
+        out.write(encodeFlags(code_flags, Codec.UNSIGNED5, Codec.UNSIGNED5, header.have_code_flags_hi()));
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/CpBands.java Wed Jul  2 06:02:16 2008
@@ -27,6 +27,7 @@
 import java.util.Set;
 import java.util.TreeSet;
 
+import org.apache.bcel.classfile.Constant;
 import org.apache.bcel.classfile.ConstantClass;
 import org.apache.bcel.classfile.ConstantDouble;
 import org.apache.bcel.classfile.ConstantFieldref;
@@ -70,6 +71,8 @@
     private final Map stringsToCpClass = new HashMap();
     private final Map stringsToCpSignature = new HashMap();
 
+    private final Map constantsToCPConstant = new HashMap();
+
     private ConstantPool currentConstantPool;
     private JavaClass currentClass;
 
@@ -175,8 +178,8 @@
         int[] cpInt = new int[cp_Int.size()];
         int i = 0;
         for (Iterator iterator = cp_Int.iterator(); iterator.hasNext();) {
-            Integer integer = (Integer) iterator.next();
-            cpInt[i] = integer.intValue();
+            CPInt integer = (CPInt) iterator.next();
+            cpInt[i] = integer.getInt();
             i++;
         }
         out.write(encodeBandInt(cpInt, Codec.UDELTA5));
@@ -187,8 +190,8 @@
         int[] cpFloat = new int[cp_Float.size()];
         int i = 0;
         for (Iterator iterator = cp_Float.iterator(); iterator.hasNext();) {
-            Float fl = (Float) iterator.next();
-            cpFloat[i] = Float.floatToIntBits(fl.floatValue());
+            CPFloat fl = (CPFloat) iterator.next();
+            cpFloat[i] = Float.floatToIntBits(fl.getFloat());
             i++;
         }
         out.write(encodeBandInt(cpFloat, Codec.UDELTA5));
@@ -200,8 +203,8 @@
         int[] loBits = new int[cp_Long.size()];
         int i = 0;
         for (Iterator iterator = cp_Long.iterator(); iterator.hasNext();) {
-            Long lng = (Long) iterator.next();
-            long l = lng.longValue();
+            CPLong lng = (CPLong) iterator.next();
+            long l = lng.getLong();
             highBits[i] = (int) (l >> 32);
             loBits[i] = (int) l;
             i++;
@@ -216,8 +219,8 @@
         int[] loBits = new int[cp_Double.size()];
         int i = 0;
         for (Iterator iterator = cp_Double.iterator(); iterator.hasNext();) {
-            Double dbl = (Double) iterator.next();
-            long l = Double.doubleToLongBits(dbl.doubleValue());
+            CPDouble dbl = (CPDouble) iterator.next();
+            long l = Double.doubleToLongBits(dbl.getDouble());
             highBits[i] = (int) (l >> 32);
             loBits[i] = (int) l;
             i++;
@@ -305,7 +308,7 @@
     }
 
     public void finaliseBands() {
-        addCpUtf8("");
+        addCPUtf8("");
         removeSignaturesFromCpUTF8();
         addIndices();
         segmentHeader.setCp_Utf8_count(cp_Utf8.size());
@@ -361,7 +364,14 @@
     }
 
     public void addConstantDouble(ConstantDouble constant) {
-        cp_Double.add(new Double((constant).getBytes()));
+        double d = (constant).getBytes();
+        Double bigD = new Double(d);
+        CPDouble cpd = (CPDouble) constantsToCPConstant.get(bigD);
+        if(cpd == null) {
+            cpd = new CPDouble(d);
+            cp_Double.add(cpd);
+            constantsToCPConstant.put(bigD, cpd);
+        }
     }
 
     public void addConstantFieldref(ConstantFieldref constant) {
@@ -375,11 +385,25 @@
     }
 
     public void addConstantFloat(ConstantFloat constant) {
-        cp_Float.add(new Float((constant).getBytes()));
+        float f = (constant).getBytes();
+        Float bigF = new Float(f);
+        CPFloat cpf = (CPFloat) constantsToCPConstant.get(bigF);
+        if(cpf == null) {
+            cpf = new CPFloat(f);
+            cp_Float.add(cpf);
+            constantsToCPConstant.put(bigF, cpf);
+        }
     }
 
     public void addConstantInteger(ConstantInteger constant) {
-        cp_Int.add(new Integer((constant).getBytes()));
+        int i = (constant).getBytes();
+        Integer bigI = new Integer(i);
+        CPInt cpi = (CPInt) constantsToCPConstant.get(bigI);
+        if(cpi == null) {
+            cpi = new CPInt(i);
+            cp_Int.add(cpi);
+            constantsToCPConstant.put(bigI, cpi);
+        }
     }
 
     public void addConstantInterfaceMethodref(
@@ -394,7 +418,14 @@
     }
 
     public void addConstantLong(ConstantLong constant) {
-        cp_Long.add(new Long((constant).getBytes()));
+        long l = (constant).getBytes();
+        Long bigL = new Long(l);
+        CPLong cpl = (CPLong) constantsToCPConstant.get(bigL);
+        if(cpl == null) {
+            cpl = new CPLong(l);
+            cp_Long.add(cpl);
+            constantsToCPConstant.put(bigL, cpl);
+        }
     }
 
     public void addConstantMethodref(ConstantMethodref constant) {
@@ -415,32 +446,32 @@
 
     public void addConstantString(ConstantString constant) {
         String string = constant.getBytes(currentConstantPool);
-        // CPString cpString = (CPString) stringsToCpString.get(string);
-        // if(cpString == null) {
-        CPString cpString = new CPString(getCpUtf8(string));
-        cp_String.add(cpString);
-        // stringsToCpString.put(string, cpString);
-        // }
+        CPString cpString = (CPString) constantsToCPConstant.get(string);
+        if (cpString == null) {
+            cpString = new CPString(getCPUtf8(string));
+            cp_String.add(cpString);
+            constantsToCPConstant.put(string, cpString);
+        }
     }
 
     public void addConstantUtf8(ConstantUtf8 constant) {
         String utf8 = constant.getBytes();
         if (!defaultAttributeNames.contains(utf8)) {
             if (utf8.endsWith(".java")) {
-                if (!isPredictableSourceFileName(utf8)) {
-                    addCpUtf8(utf8);
+                if (!isPredictableSourceFileName(currentClass.getClassName(), utf8)) {
+                    addCPUtf8(utf8);
                 }
             } else {
-                addCpUtf8(utf8);
+                addCPUtf8(utf8);
             }
         }
     }
 
-    private void addCpUtf8(String utf8) {
-        getCpUtf8(utf8);
+    private void addCPUtf8(String utf8) {
+        getCPUtf8(utf8);
     }
 
-    public CPUTF8 getCpUtf8(String utf8) {
+    public CPUTF8 getCPUtf8(String utf8) {
         CPUTF8 cpUtf8 = (CPUTF8) stringsToCpUtf8.get(utf8);
         if (cpUtf8 == null) {
             cpUtf8 = new CPUTF8(utf8);
@@ -454,11 +485,11 @@
         getCPNameAndType(name, signature);
     }
 
-    public void addSignature(String signature) {
-        getSignature(signature);
+    public void addCPSignature(String signature) {
+        getCPSignature(signature);
     }
 
-    private CPSignature getSignature(String signature) {
+    public CPSignature getCPSignature(String signature) {
         CPSignature cpS = (CPSignature) stringsToCpSignature.get(signature);
         if (cpS == null) {
             List cpClasses = new ArrayList();
@@ -490,9 +521,9 @@
                     cpClasses.add(getCPClass((String) iterator2.next()));
                 }
 
-                signatureUTF8 = getCpUtf8(signatureString.toString());
+                signatureUTF8 = getCPUtf8(signatureString.toString());
             } else {
-                signatureUTF8 = getCpUtf8(signature);
+                signatureUTF8 = getCPUtf8(signature);
             }
             cpS = new CPSignature(signature, signatureUTF8, cpClasses);
             cp_Signature.add(cpS);
@@ -505,7 +536,7 @@
         className = className.replace('.', '/');
         CPClass cpClass = (CPClass) stringsToCpClass.get(className);
         if (cpClass == null) {
-            CPUTF8 cpUtf8 = getCpUtf8(className);
+            CPUTF8 cpUtf8 = getCPUtf8(className);
             cpClass = new CPClass(cpUtf8);
             cp_Class.add(cpClass);
             stringsToCpClass.put(className, cpClass);
@@ -522,24 +553,30 @@
         CPNameAndType nameAndType = (CPNameAndType) stringsToCpNameAndType
                 .get(descr);
         if (nameAndType == null) {
-            nameAndType = new CPNameAndType(getCpUtf8(name),
-                    getSignature(signature));
+            nameAndType = new CPNameAndType(getCPUtf8(name),
+                    getCPSignature(signature));
             stringsToCpNameAndType.put(descr, nameAndType);
             cp_Descr.add(nameAndType);
         }
         return nameAndType;
     }
 
-    public boolean isPredictableSourceFileName(String name) {
-        String className = currentClass.getClassName();
-        if (className.indexOf(".") != -1) {
-            className = className.substring(className.lastIndexOf(".") + 1);
-        }
-        if (className.indexOf("$") != -1) {
-            className = className.substring(0, className.indexOf("$"));
+    public CPConstant getCPConstant(Constant theConstant, ConstantPool cp) {
+        Object key;
+        if(theConstant instanceof ConstantDouble) {
+            key = new Double(((ConstantDouble)theConstant).getBytes());
+        } else if (theConstant instanceof ConstantFloat) {
+            key = new Float(((ConstantFloat)theConstant).getBytes());
+        } else if (theConstant instanceof ConstantInteger) {
+            key = new Integer(((ConstantInteger)theConstant).getBytes());
+        } else if (theConstant instanceof ConstantLong) {
+            key = new Long(((ConstantLong)theConstant).getBytes());
+        } else if (theConstant instanceof ConstantString) {
+            key = ((ConstantString)theConstant).getBytes(cp);
+        } else {
+            throw new RuntimeException("Unexpected constant type: " + theConstant.getClass());
         }
-        className += ".java";
-        return className.equals(name);
+        return (CPConstant) constantsToCPConstant.get(key);
     }
 
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Segment.java Wed Jul  2 06:02:16 2008
@@ -67,14 +67,14 @@
     private ClassBands classBands;
     private BcBands bcBands;
     private FileBands fileBands;
-    
+
 
     public void pack(List classes, List files, OutputStream out) throws IOException, Pack200Exception {
         segmentHeader = new SegmentHeader();
         cpBands = new CpBands(segmentHeader);
         attributeDefinitionBands = new AttributeDefinitionBands(segmentHeader, cpBands);
         icBands = new IcBands(segmentHeader);
-        classBands = new ClassBands(cpBands, classes.size());
+        classBands = new ClassBands(segmentHeader, cpBands, attributeDefinitionBands, classes.size());
         bcBands = new BcBands();
         fileBands = new FileBands(segmentHeader, files);
 
@@ -96,6 +96,7 @@
     }
 
     private void processClasses(List classes) {
+        segmentHeader.setClass_count(classes.size());
         for (Iterator iterator = classes.iterator(); iterator.hasNext();) {
             JavaClass javaClass = (JavaClass) iterator.next();
             new DescendingVisitor(javaClass, this).visit();
@@ -219,7 +220,7 @@
     }
 
     public void visitLocalVariable(LocalVariable obj) {
-        cpBands.addSignature(obj.getSignature());
+        cpBands.addCPSignature(obj.getSignature());
     }
 
     public void visitLocalVariableTable(LocalVariableTable obj) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java?rev=673381&r1=673380&r2=673381&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/SegmentHeader.java Wed Jul  2 06:02:16 2008
@@ -248,6 +248,26 @@
     }
 
 
+    public boolean have_class_flags_hi() {
+        return have_class_flags_hi;
+    }
+
+
+    public boolean have_field_flags_hi() {
+        return have_field_flags_hi;
+    }
+
+
+    public boolean have_method_flags_hi() {
+        return have_method_flags_hi;
+    }
+
+
+    public boolean have_code_flags_hi() {
+        return have_code_flags_hi;
+    }
+
+
     public void setIc_count(int ic_count) {
         this.ic_count = ic_count;
     }
@@ -346,4 +366,12 @@
         }
     }
 
+    public int getDefaultMinorVersion() {
+        return minverCounter.getMostCommon();
+    }
+
+    public int getDefaultMajorVersion() {
+        return majverCounter.getMostCommon();
+    }
+
 }
\ No newline at end of file



Mime
View raw message