You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2008/03/27 16:28:12 UTC

svn commit: r641847 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode: CPString.java ClassConstantPool.java ClassFileEntry.java forms/StringRefForm.java

Author: sjanuary
Date: Thu Mar 27 08:28:11 2008
New Revision: 641847

URL: http://svn.apache.org/viewvc?rev=641847&view=rev
Log:
Apply patch for HARMONY-5655 ([classlib][pack200] Need to sort class pool per pack200 spec)

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.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/ClassFileEntry.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java?rev=641847&r1=641846&r2=641847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java Thu Mar 27 08:28:11 2008
@@ -23,6 +23,7 @@
 
     private transient int nameIndex;
 	private CPUTF8 name;
+	private boolean mustStartClassPool = false;
 
     public CPString(CPUTF8 value) {
 		super(ConstantPoolEntry.CP_String, value);
@@ -56,4 +57,25 @@
 	public String comparisonString() {
 	    return ((CPUTF8)getValue()).underlyingString();
 	}
+
+    /**
+     * Set whether the receiver must be at the start of the
+     * class pool. Anything which is the target of a single-
+     * byte ldc (bytecode 18, String) command must be at
+     * the start of the class pool.
+     *
+     * @param b boolean true if the receiver must be at
+     * the start of the class pool, otherwise false.
+     */
+    public void mustStartClassPool(boolean b) {
+        mustStartClassPool = b;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.ClassFileEntry#mustStartClassPool()
+     */
+    public boolean mustStartClassPool() {
+        return mustStartClassPool;
+    }
 }

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=641847&r1=641846&r2=641847&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 Thu Mar 27 08:28:11 2008
@@ -20,7 +20,9 @@
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.Segment;
+import org.apache.harmony.pack200.SegmentUtils;
 
 
 public class ClassConstantPool {
@@ -146,12 +148,25 @@
         // references, which are sorted by index in the
         // class pool.
         it = entries.iterator();
+        ClassPoolSet startOfPool = new ClassPoolSet();
         ClassPoolSet finalSort = new ClassPoolSet();
         while(it.hasNext()) {
-            finalSort.add(it.next());
+            ClassFileEntry nextEntry = (ClassFileEntry)it.next();
+            if(nextEntry.mustStartClassPool()) {
+                startOfPool.add(nextEntry);
+            } else {
+                finalSort.add(nextEntry);
+            }
         }
-        it = finalSort.iterator();
         entries = new ArrayList();
+        Iterator itStart = startOfPool.iterator();
+        while(itStart.hasNext()) {
+            ClassFileEntry entry = (ClassFileEntry) itStart.next();
+            entries.add(entry);
+            if (entry instanceof CPLong ||entry instanceof CPDouble)
+                entries.add(entry); //these get 2 slots because of their size
+        }
+        it = finalSort.iterator();
         while(it.hasNext()) {
             ClassFileEntry entry = (ClassFileEntry) it.next();
             entries.add(entry);

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java?rev=641847&r1=641846&r2=641847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java Thu Mar 27 08:28:11 2008
@@ -54,4 +54,15 @@
 		doWrite(dos);
 	}
 
+    /**
+     * Answer true if the receiver must be at the beginning
+     * of the class pool (because it is the target of a
+     * single-byte ldc command). Otherwise answer false.
+     *
+     * @return boolean true if the receiver must be under
+     *   256; otherwise false.
+     */
+    public boolean mustStartClassPool() {
+        return false;
+    }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java?rev=641847&r1=641846&r2=641847&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java Thu Mar 27 08:28:11 2008
@@ -67,6 +67,7 @@
             byteCode.setNestedPositions(new int[][]{{0, 2}});
         } else {
             byteCode.setNestedPositions(new int[][]{{0, 1}});
+            ((CPString)nested[0]).mustStartClassPool(true);
         }
     }
 }