Index: main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (revision 641594) +++ main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (working copy) @@ -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); + } } + 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(); - entries = new ArrayList(); while(it.hasNext()) { ClassFileEntry entry = (ClassFileEntry) it.next(); entries.add(entry); Index: main/java/org/apache/harmony/pack200/bytecode/CPString.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPString.java (revision 641594) +++ main/java/org/apache/harmony/pack200/bytecode/CPString.java (working copy) @@ -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; + } } \ No newline at end of file Index: main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java (revision 641594) +++ main/java/org/apache/harmony/pack200/bytecode/forms/StringRefForm.java (working copy) @@ -67,6 +67,7 @@ byteCode.setNestedPositions(new int[][]{{0, 2}}); } else { byteCode.setNestedPositions(new int[][]{{0, 1}}); + ((CPString)nested[0]).mustStartClassPool(true); } } } Index: main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java (revision 641594) +++ main/java/org/apache/harmony/pack200/bytecode/ClassFileEntry.java (working copy) @@ -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; + } }