harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r635991 - in /harmony/enhanced/classlib/trunk/modules/pack200/src: main/java/org/apache/harmony/pack200/ main/java/org/apache/harmony/pack200/bytecode/ test/java/org/apache/harmony/pack200/tests/
Date Tue, 11 Mar 2008 16:07:11 GMT
Author: sjanuary
Date: Tue Mar 11 09:07:09 2008
New Revision: 635991

URL: http://svn.apache.org/viewvc?rev=635991&view=rev
Log:
Pack200 - minor code improvements and bug fixes

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/BHSDCodec.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ExceptionsAttribute.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/InnerClassesAttribute.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassVersionTest.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=635991&r1=635990&r2=635991&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
Tue Mar 11 09:07:09 2008
@@ -45,7 +45,7 @@
 
     private InputStream inputStream;
 
-    private JarOutputStream outputStream;
+    private final JarOutputStream outputStream;
 
     private boolean removePackFile;
 
@@ -157,7 +157,10 @@
         }
         if (removePackFile) {
             File file = new File(inputFileName);
-            file.delete();
+            boolean deleted = file.delete();
+            if(!deleted) {
+            	throw new Pack200Exception("Failed to delete the input file.");
+            }
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BHSDCodec.java
Tue Mar 11 09:07:09 2008
@@ -32,27 +32,27 @@
 	/**
 	 * The maximum number of bytes in each coding word
 	 */
-	private int b;
+	private final int b;
 
 	/**
 	 * Whether delta encoding is used (0=false,1=true)
 	 */
-	private int d;
+	private final int d;
 
 	/**
 	 * The radix of the encoding
 	 */
-	private int h;
+	private final int h;
 
 	/**
 	 * The co-parameter of h; h-256
 	 */
-	private int l;
+	private final int l;
 
 	/**
 	 * Represents signed numbers or not (0=unsigned,1/2=signed)
 	 */
-	private int s;
+	private final int s;
 
     private long cardinality;
 
@@ -157,29 +157,29 @@
             n++;
 		} while (n < b & isHigh(x));
 
-// TODO: Decide whether to use this algorithm instead (neater, possibly quicker but less
easy to understand)
-//        if (isSigned()) {
-//            int u = ((1 << s) - 1);
-//            if ((z & u) == u) {
-//                z = z >>> s ^ -1L;
-//            } else {
-//                z = z - (z >>> s);
-//            }
-//        }
-        if(isSigned()) {
-            long u = z;
-            long twoPowS = (long)Math.pow(2, s);
-            double twoPowSMinusOne = twoPowS-1;
-            if(u % twoPowS < twoPowSMinusOne) {
-                if(cardinality < Math.pow(2, 32)) {
-                    z = (long) (u - (Math.floor(u/ twoPowS)));
-                } else {
-                    z = cast32((long) (u - (Math.floor(u/ twoPowS))));
-                }
+        if (isSigned()) {
+            int u = ((1 << s) - 1);
+            if ((z & u) == u) {
+                z = z >>> s ^ -1L;
             } else {
-                z = (long) (-Math.floor(u/ twoPowS) - 1);
+                z = z - (z >>> s);
             }
         }
+// This algorithm does the same thing, but is probably slower.  Leaving in for now for readability
+//        if(isSigned()) {
+//            long u = z;
+//            long twoPowS = (long)Math.pow(2, s);
+//            double twoPowSMinusOne = twoPowS-1;
+//            if(u % twoPowS < twoPowSMinusOne) {
+//                if(cardinality < Math.pow(2, 32)) {
+//                    z = (long) (u - (Math.floor(u/ twoPowS)));
+//                } else {
+//                    z = cast32((long) (u - (Math.floor(u/ twoPowS))));
+//                }
+//            } else {
+//                z = (long) (-Math.floor(u/ twoPowS) - 1);
+//            }
+//        }
 	    if (isDelta())
 	        z += last;
 		return z;

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IcTuple.java
Tue Mar 11 09:07:09 2008
@@ -20,7 +20,7 @@
 
 public class IcTuple {
 
-    public static int NESTED_CLASS_FLAG = 0x00010000;
+    public static final int NESTED_CLASS_FLAG = 0x00010000;
     public String C; // this class
     public int F; // flags
     public String C2; // outer class
@@ -102,7 +102,7 @@
         if(predicted()) {
             return C;
         } else {
-            // TODO: this may not be right. What if I 
+            // TODO: this may not be right. What if I
             // get a class like Foo#Bar$Baz$Bug?
             return C2 + "$" + N;
         }
@@ -140,7 +140,7 @@
         // If we get to this point, nameComponents.length must be >=2
         int lastPosition = nameComponents.length - 1;
         cachedSimpleClassName = nameComponents[lastPosition];
-        cachedOuterClassString = new String();
+        cachedOuterClassString = "";
         for(int index=0; index < lastPosition; index++) {
             cachedOuterClassString += nameComponents[index];
             if(isAllDigits(nameComponents[index])) {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/NewAttributeBands.java
Tue Mar 11 09:07:09 2008
@@ -43,9 +43,7 @@
  */
 public class NewAttributeBands extends BandSet {
 
-    private AttributeLayout attributeLayout;
-
-    private List attributes;
+    private final AttributeLayout attributeLayout;
 
     private int backwardsCallCount;
 
@@ -68,15 +66,6 @@
     }
 
     /**
-     * Returns the list of attributes read in by this band set.  This method
-     * should only be called after unpack() or it will return null.
-     * @return List of Attributes
-     */
-    public List getAttributes() {
-        return attributes;
-    }
-
-    /**
      * Parse the bands relating to this AttributeLayout and return the correct
      * class file attributes as a List of {@link Attribute}
      * @throws Pack200Exception
@@ -364,7 +353,7 @@
 
     private class Integral extends LayoutElement {
 
-        private String tag;
+        private final String tag;
         private long[] band;
 
         public Integral(String tag) {
@@ -428,9 +417,9 @@
      */
     private class Replication extends LayoutElement {
 
-        private Integral countElement;
+        private final Integral countElement;
 
-        private List layoutElements = new ArrayList();
+        private final List layoutElements = new ArrayList();
 
         public Replication(String tag, String contents) throws IOException {
             this.countElement = new Integral(tag);
@@ -479,9 +468,9 @@
      */
     private class Union extends LayoutElement {
 
-        private Integral unionTag;
-        private List unionCases;
-        private List defaultCaseBody;
+        private final Integral unionTag;
+        private final List unionCases;
+        private final List defaultCaseBody;
         private int[] caseCounts;
         private int defaultCount;
 
@@ -572,7 +561,7 @@
 
     private class Call extends LayoutElement {
 
-        private int callableIndex;
+        private final int callableIndex;
         private Callable callable;
 
         public Call(int callableIndex) {
@@ -608,11 +597,11 @@
      */
     private class Reference extends LayoutElement {
 
-        private String tag;
+        private final String tag;
 
         private Object band;
 
-        private int length;
+        private final int length;
 
         public Reference(String tag) {
             this.tag = tag;
@@ -677,9 +666,9 @@
 
     }
 
-    private class Callable implements AttributeLayoutElement {
+    private static class Callable implements AttributeLayoutElement {
 
-        private List body;
+        private final List body;
 
         private boolean isBackwardsCallable;
 
@@ -748,7 +737,7 @@
 
         private List body;
 
-        private List tags;
+        private final List tags;
 
         public UnionCase(List tags) {
             this.tags = tags;
@@ -875,7 +864,10 @@
         }
         stream.reset();
         char[] digits = new char[length];
-        stream.read(digits);
+        int read = stream.read(digits);
+        if (read != digits.length) {
+        	throw new IOException("Error reading from the input stream");
+        }
         return Integer.parseInt((negative ? "-" : "") + new String(digits));
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
Tue Mar 11 09:07:09 2008
@@ -64,7 +64,7 @@
 		final ByteCode other = (ByteCode) obj;
 		if (getByteCodeForm() != other.getByteCodeForm())
 			return false;
-		if (!rewrite.equals(other.rewrite))
+		if (rewrite != other.rewrite)
 			return false;
 		return true;
 	}

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
Tue Mar 11 09:07:09 2008
@@ -26,27 +26,27 @@
 public class ClassConstantPool {
 
     // These are the domains in sorted order.
-    public static int DOMAIN_UNDEFINED = 0;
-    public static int DOMAIN_INTEGER = 1;
-    public static int DOMAIN_FLOAT = 2;
-    public static int DOMAIN_STRING = 3;
-    public static int DOMAIN_NORMALASCIIZ = 4;
-    public static int DOMAIN_LONG = 5;
-    public static int DOMAIN_DOUBLE = 6;
-    public static int DOMAIN_CLASSREF = 7;
-    public static int DOMAIN_SIGNATUREASCIIZ = 8;
-    public static int DOMAIN_NAMEANDTYPE = 9;
-    public static int DOMAIN_FIELD = 10;
-    public static int DOMAIN_METHOD = 11;
-    public static int DOMAIN_ATTRIBUTEASCIIZ = 12;
-    public static int NUM_DOMAINS = DOMAIN_ATTRIBUTEASCIIZ + 1;
+    public static final int DOMAIN_UNDEFINED = 0;
+    public static final int DOMAIN_INTEGER = 1;
+    public static final int DOMAIN_FLOAT = 2;
+    public static final int DOMAIN_STRING = 3;
+    public static final int DOMAIN_NORMALASCIIZ = 4;
+    public static final int DOMAIN_LONG = 5;
+    public static final int DOMAIN_DOUBLE = 6;
+    public static final int DOMAIN_CLASSREF = 7;
+    public static final int DOMAIN_SIGNATUREASCIIZ = 8;
+    public static final int DOMAIN_NAMEANDTYPE = 9;
+    public static final int DOMAIN_FIELD = 10;
+    public static final int DOMAIN_METHOD = 11;
+    public static final int DOMAIN_ATTRIBUTEASCIIZ = 12;
+    public static final int NUM_DOMAINS = DOMAIN_ATTRIBUTEASCIIZ + 1;
 
 //    protected SortedSet sortedEntries = new TreeSet(new PoolComparator());
     protected ClassPoolSet classPoolSet = new ClassPoolSet();
     public String toString() {
         return entries.toString();
     }
-    private List others = new ArrayList();
+    private final List others = new ArrayList();
 
     private List entries = new ArrayList();
 
@@ -106,7 +106,7 @@
         classPoolSet = new ClassPoolSet();
         Iterator it = entries.iterator();
         while(it.hasNext()) {
-            classPoolSet.add((ClassFileEntry)it.next());
+            classPoolSet.add(it.next());
         }
         entries = new ArrayList();
       Iterator sortedIterator = classPoolSet.iterator();

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
Tue Mar 11 09:07:09 2008
@@ -57,7 +57,7 @@
 	byte tag;
 
 	protected int domain = ClassConstantPool.DOMAIN_UNDEFINED;
-	public static int creationOrderCount = 100;
+	private static int creationOrderCount = 100;
 	public String comparisonString() {
 	    return toString();
 	}

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ExceptionsAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ExceptionsAttribute.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ExceptionsAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ExceptionsAttribute.java
Tue Mar 11 09:07:09 2008
@@ -39,7 +39,7 @@
 
 	private transient int[] exceptionIndexes;
 
-	private CPClass[] exceptions;
+	private final CPClass[] exceptions;
 
 	public ExceptionsAttribute(CPClass[] exceptions) {
 		super(attributeName);
@@ -89,7 +89,7 @@
 	}
 
 	public String toString() {
-		return "Exceptions:" + exceptions;
+		return "Exceptions: " + exceptions;
 	}
 
 	protected void writeBody(DataOutputStream dos) throws IOException {

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/InnerClassesAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/InnerClassesAttribute.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/InnerClassesAttribute.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/InnerClassesAttribute.java
Tue Mar 11 09:07:09 2008
@@ -31,7 +31,7 @@
             "InnerClasses", ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ); //$NON-NLS-1$
 
 
-    class InnerClassesEntry {
+    private static class InnerClassesEntry {
         CPClass inner_class_info;
         CPClass outer_class_info;
         CPUTF8 inner_class_name;
@@ -93,8 +93,8 @@
 
     }
 
-    private List innerClasses = new ArrayList();
-    private List nestedClassFileEntries = new ArrayList();
+    private final List innerClasses = new ArrayList();
+    private final List nestedClassFileEntries = new ArrayList();
 
     public InnerClassesAttribute(String name) {
         super(attributeName);

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassVersionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassVersionTest.java?rev=635991&r1=635990&r2=635991&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassVersionTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/ClassVersionTest.java
Tue Mar 11 09:07:09 2008
@@ -47,6 +47,7 @@
 		din.readShort(); // MINOR -- don't care
 		assertTrue("Class file has been compiled with Java 1.5 compatibility"
 				+ " instead of 1.4 or lower", din.readShort() < JAVA_15);
+		din.close();
 	}
 
 	public void testCorrectVersionOfAdapter() throws IOException {
@@ -61,6 +62,7 @@
 			din.readShort(); // MINOR -- don't care
 			assertTrue("Class file needs 1.5 compatibility",
 					din.readShort() >= JAVA_15);
+			din.close();
 		}
 	}
 }



Mime
View raw message