harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r609928 [4/5] - in /harmony/enhanced/classlib/branches/java6: ./ make/ modules/awt/src/main/java/unix/org/apache/harmony/awt/gl/linux/ modules/awt/src/main/java/windows/org/apache/harmony/awt/gl/windows/ modules/awt/src/main/native/gl/share...
Date Tue, 08 Jan 2008 10:55:41 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ByteCode.java Tue Jan  8 02:55:24 2008
@@ -36,7 +36,7 @@
 	private int[] rewrite;
 
     private int byteCodeOffset = -1;
-    private int byteCodeTarget = -1;
+    private int[] byteCodeTargets = null;
 
 	protected ByteCode(int opcode) {
 		this(opcode, ClassFileEntry.NONE);
@@ -69,14 +69,13 @@
 		return true;
 	}
 
-	public void extractOperands(OperandManager operandManager, Segment segment) {
+	public void extractOperands(OperandManager operandManager, Segment segment, int codeLength) {
 		// Given an OperandTable, figure out which operands
 		// the receiver needs and stuff them in operands.
 		// Later on the operands can be rewritten (But that's
 		// later, not now).
-
 		ByteCodeForm currentByteCodeForm = getByteCodeForm();
-		currentByteCodeForm.setByteCodeOperands(this, operandManager);
+		currentByteCodeForm.setByteCodeOperands(this, operandManager, codeLength);
 	}
 
 	protected ByteCodeForm getByteCodeForm() {
@@ -131,7 +130,7 @@
 					break;
 					
 				case 2: 
-					setOperandInt(pool.indexOf(nested[index]), getNestedPosition(index)[0]);
+					setOperand2Bytes(pool.indexOf(nested[index]), getNestedPosition(index)[0]);
 					break;
 				
 				case 4:
@@ -172,7 +171,7 @@
 			rewrite[index + firstOperandIndex] = operands[index] & 0xFF;
 		}
 	}
-	
+    
 	/**
 	 * Given an int operand, set the rewrite bytes for
 	 * that position and the one immediately following it
@@ -184,7 +183,7 @@
 	 *  position 0 is the first -1, position 1 is the second -1,
 	 *  etc.
 	 */
-	public void setOperandInt(int operand, int position) {
+	public void setOperand2Bytes(int operand, int position) {
 		int firstOperandIndex = getByteCodeForm().firstOperandIndex();
 		int byteCodeFormLength = getByteCodeForm().getRewrite().length;
 		if (firstOperandIndex < 1) {
@@ -206,12 +205,12 @@
 	 * @param operand int to set the rewrite bytes to
 	 * @param position int position of the operands in the rewrite bytes
 	 */
-	public void setOperandSignedInt(int operand, int position) {
+	public void setOperandSigned2Bytes(int operand, int position) {
 	    if(operand >= 0) {
-	        setOperandInt(operand, position);
+	        setOperand2Bytes(operand, position);
 	    } else {
 	        int twosComplementOperand = 0x10000 + operand;
-	        setOperandInt(twosComplementOperand, position);
+	        setOperand2Bytes(twosComplementOperand, position);
 	    }
 	}
 
@@ -315,31 +314,60 @@
     }
     
     /**
-     * Some ByteCodes (in particular, LabelForm bytecodes)
-     * have to keep track of a byteCodeTarget. This is
-     * initially an offset in the CodeAttribute array
-     * relative to the byteCodeOffset, but later gets fixed
+     * Some ByteCodes (in particular, those with labels)
+     * have to keep track of byteCodeTargets. These are
+     * initially offsets in the CodeAttribute array
+     * relative to the byteCodeOffset, but later get fixed
      * up to point to the absolute position in the CodeAttribute
-     * array. This method sets the target.
+     * array. This method sets the targets.
      * 
      * @param byteCodeTarget int index in array
      */
-    public void setByteCodeTarget(int byteCodeTarget) {
-        this.byteCodeTarget = byteCodeTarget;
+    public void setByteCodeTargets(int[] byteCodeTargets) {
+        this.byteCodeTargets = byteCodeTargets;
     }
     
-    public int getByteCodeTarget() {
-        return byteCodeTarget;
+    public int[] getByteCodeTargets() {
+        return byteCodeTargets;
     }
     
     /**
-     * Some ByteCodes (in particular, those with the Label
-     * form) need to be fixed up after all the bytecodes
-     * in the CodeAttribute have been added. (This can't
+     * Some ByteCodes (in particular, those with labels
+     * need to be fixed up after all the bytecodes in the
+     * CodeAttribute have been added. (This can't
      * be done beforehand because the CodeAttribute needs
      * to be complete before targets can be assigned.)
      */
     public void applyByteCodeTargetFixup(CodeAttribute codeAttribute) {
-        getByteCodeForm().fixUpByteCodeTarget(this, codeAttribute);
+        getByteCodeForm().fixUpByteCodeTargets(this, codeAttribute);
+    }
+
+    /**
+     * Some bytecodes (the ones with variable lengths) can't
+     * have a static rewrite array - they need the ability to
+     * update the array. This method permits that.
+     * 
+     * Note that this should not be called from bytecodes
+     * which have a static rewrite; use the table in ByteCodeForm
+     * instead to specify those rewrites.
+     * 
+     * @param rewrite
+     */
+    public void setRewrite(int[] rewrite) {
+        this.rewrite = rewrite;
+    }
+    
+    /**
+     * Some bytecodes (the ones with variable lengths) can't
+     * have a static rewrite array - they need the ability to
+     * update the array. This method permits their associated
+     * bytecode formst to query their rewrite array.
+     * 
+     * Note that this should not be called from bytecodes
+     * which have a static rewrite; use the table in ByteCodeForm
+     * instead to specify those rewrites.
+     */
+    public int[] getRewrite() {
+        return rewrite;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPClass.java Tue Jan  8 02:55:24 2008
@@ -30,7 +30,8 @@
 	public   CPClass(String name) {
 		super(ConstantPoolEntry.CP_Class);
 		this.name = name;
-		this.utf8 = new CPUTF8(name);
+		this.domain = ClassConstantPool.DOMAIN_CLASSREF;
+		this.utf8 = new CPUTF8(name, ClassConstantPool.DOMAIN_NORMALASCIIZ);
 	}
 
 	
@@ -84,4 +85,9 @@
 	protected void writeBody(DataOutputStream dos) throws IOException {
 		dos.writeShort(index);
 	}
+	
+   public String comparisonString() {
+        return getName();
+   }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPDouble.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPDouble.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPDouble.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPDouble.java Tue Jan  8 02:55:24 2008
@@ -22,6 +22,7 @@
 public class CPDouble extends CPConstantNumber {
 	public CPDouble(java.lang.Double value) {
 		super(ConstantPoolEntry.CP_Double,value);
+        this.domain = ClassConstantPool.DOMAIN_DOUBLE;
 	}
 
 	

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java Tue Jan  8 02:55:24 2008
@@ -30,6 +30,7 @@
 	transient int nameAndTypeIndex;
 	public CPFieldRef(String className, String descriptor) {
 		super(ConstantPoolEntry.CP_Fieldref);
+		this.domain = ClassConstantPool.DOMAIN_FIELD;
 		this.className = new CPClass(className);
 		this.nameAndType = new CPNameAndType(descriptor);
 	}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFloat.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFloat.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFloat.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPFloat.java Tue Jan  8 02:55:24 2008
@@ -22,6 +22,7 @@
 public class CPFloat extends CPConstantNumber {
 	public CPFloat(java.lang.Float value) {
 		super(ConstantPoolEntry.CP_Float,value);
+	      this.domain = ClassConstantPool.DOMAIN_FLOAT;
 	}
 
 	

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInteger.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInteger.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInteger.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInteger.java Tue Jan  8 02:55:24 2008
@@ -23,6 +23,7 @@
 
 	public CPInteger(java.lang.Integer value) {
 		super(ConstantPoolEntry.CP_Integer,value);
+		this.domain = ClassConstantPool.DOMAIN_INTEGER;
 	}
 
 	

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInterfaceMethodRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInterfaceMethodRef.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInterfaceMethodRef.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPInterfaceMethodRef.java Tue Jan  8 02:55:24 2008
@@ -20,6 +20,18 @@
 
 	public CPInterfaceMethodRef(String className, String descriptor) {
 		super(ConstantPoolEntry.CP_InterfaceMethodref, className, descriptor);
+		this.domain = ClassConstantPool.DOMAIN_METHOD;
 	}
 
+	/**
+	 * This method answers the value this method will use
+	 * for an invokeinterface call. This is equal to 1 + the
+	 * count of all the args, where longs and doubles count for
+	 * 2 and all others count for 1.
+	 * 
+	 * @return integer count
+	 */
+	public int invokeInterfaceCount() {
+	    return nameAndType.invokeInterfaceCount();
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPLong.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPLong.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPLong.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPLong.java Tue Jan  8 02:55:24 2008
@@ -23,6 +23,7 @@
 
 	public CPLong(java.lang.Long value) {
 		super(ConstantPoolEntry.CP_Long,value);
+        this.domain = ClassConstantPool.DOMAIN_LONG;
 	}
 
 	

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMember.java Tue Jan  8 02:55:24 2008
@@ -38,8 +38,8 @@
 	transient int descriptorIndex;
 	public CPMember(String descriptor, long flags, List attributes) {
 		int colon = descriptor.indexOf(':');
-		this.name = new CPUTF8(descriptor.substring(0,colon));
-		this.descriptor = new CPUTF8(descriptor.substring(colon+1));
+		this.name = new CPUTF8(descriptor.substring(0,colon), ClassConstantPool.DOMAIN_NORMALASCIIZ);
+		this.descriptor = new CPUTF8(descriptor.substring(colon+1), ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
 		this.flags = (short) flags;
 		this.attributes = (attributes == null ? new ArrayList() : attributes);
 	}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMethodRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMethodRef.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMethodRef.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPMethodRef.java Tue Jan  8 02:55:24 2008
@@ -25,6 +25,7 @@
 		super(ConstantPoolEntry.CP_Methodref, className, descriptor);
 		this.className = new CPClass(className);
 		this.descriptor = new CPNameAndType(descriptor);
+        this.domain = ClassConstantPool.DOMAIN_METHOD;
 	}
 
 	protected ClassFileEntry[] getNestedClassFileEntries() {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java Tue Jan  8 02:55:24 2008
@@ -19,6 +19,8 @@
 import java.io.DataOutputStream;
 import java.io.IOException;
 
+import org.apache.harmony.pack200.SegmentUtils;
+
 
 public class CPNameAndType extends ConstantPoolEntry {
 
@@ -32,9 +34,35 @@
 
 	public CPNameAndType(String descriptor) {
 		super(ConstantPoolEntry.CP_NameAndType);
+		int descriptorDomain = ClassConstantPool.DOMAIN_UNDEFINED;
 		int colon = descriptor.indexOf(':');
-		this.name = new CPUTF8(descriptor.substring(0,colon));
-		this.descriptor = new CPUTF8(descriptor.substring(colon+1));
+		String nameString = descriptor.substring(0,colon);
+		String descriptorString = descriptor.substring(colon+1);
+		// For some reason, descriptors which have just plain
+		// native types are stored in DOMAIN_NORMALASCIIZ rather
+		// than in DOMAIN_SIGNATUREASCIIZ. This might indicate
+		// that DOMAIN_SIGNATUREASCIIZ is poorly named.
+		boolean nativeDescriptor = true;
+		for(int index=0; index < descriptorString.length(); index++) {
+		    char currentChar = descriptorString.charAt(index);
+		    if(Character.isLetter(currentChar)) {
+		        if(currentChar == 'L') {
+		            nativeDescriptor = false;
+		        }
+		        break;
+		    }
+		}
+		this.domain = ClassConstantPool.DOMAIN_NAMEANDTYPE;
+		this.name = new CPUTF8(nameString, ClassConstantPool.DOMAIN_NORMALASCIIZ);
+		if((nameString.equals("<init>")) || (nameString.equals("<clinit>")) || nativeDescriptor ) {
+		    // Signatures for init methods are stored with the init methods.
+		    // Not sure why. Similarly, native signatures are stored
+		    // there as well.
+		    descriptorDomain = ClassConstantPool.DOMAIN_NORMALASCIIZ;
+		} else {
+		    descriptorDomain = ClassConstantPool.DOMAIN_SIGNATUREASCIIZ;
+		}
+		this.descriptor = new CPUTF8(descriptorString, descriptorDomain);
 	}
 
 	protected ClassFileEntry[] getNestedClassFileEntries() {
@@ -94,4 +122,14 @@
 		return true;
 	}
 
+	/**
+	 * Answers the invokeinterface count argument when the
+	 * receiver is treated as an invokeinterface target.
+	 * This value is not meaningful if the receiver is not
+     * an invokeinterface target.
+	 * @return count
+	 */
+	public int invokeInterfaceCount() {
+	    return 1 + SegmentUtils.countInvokeInterfaceArgs(descriptor.underlyingString());
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java Tue Jan  8 02:55:24 2008
@@ -24,7 +24,7 @@
 	CPClass className;
 	transient int classNameIndex;
 
-	private final CPNameAndType nameAndType;
+	protected final CPNameAndType nameAndType;
 	transient int nameAndTypeIndex;
 
 	public CPRef(byte type, String className, String descriptor) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPString.java Tue Jan  8 02:55:24 2008
@@ -25,7 +25,8 @@
 
 	public CPString(java.lang.String value) {
 		super(ConstantPoolEntry.CP_String,value);
-		this.name = new CPUTF8((String) getValue());
+		this.domain = ClassConstantPool.DOMAIN_STRING;
+		this.name = new CPUTF8((String) getValue(), ClassConstantPool.DOMAIN_NORMALASCIIZ);
 
 	}
 
@@ -53,4 +54,7 @@
 		return new ClassFileEntry[] { name };
  	}
 
+	public String comparisonString() {
+	    return (String)getValue();
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java Tue Jan  8 02:55:24 2008
@@ -23,9 +23,10 @@
 public class CPUTF8 extends ConstantPoolEntry {
 	private String utf8;
 
-	public CPUTF8(String utf8) {
+	public CPUTF8(String utf8, int domain) {
 		super(ConstantPoolEntry.CP_UTF8);
 		this.utf8 = utf8;
+		this.domain = domain;
 	}
 
 	
@@ -74,4 +75,25 @@
 		dos.write(bytes);
 	}
 
+	public String underlyingString() {
+	    return utf8;
+	}
+	
+	public String comparisonString() {
+	    String returnValue = utf8;
+	    if(utf8.endsWith(";")) {
+	        StringBuffer alphaChars = new StringBuffer();
+	        StringBuffer extraChars = new StringBuffer();
+	        extraChars.append((char)0xFFFF);
+	        for(int index=0; index < utf8.length(); index++) {
+	            if( (utf8.charAt(index) == '(') || (utf8.charAt(index) == ')') || (utf8.charAt(index) == '[') || (utf8.charAt(index) == ']') ) {
+	                extraChars.append(utf8.charAt(index));
+	            } else {
+	                alphaChars.append(utf8.charAt(index));
+	            }
+	        }
+	        returnValue = alphaChars.toString() + extraChars.toString();
+	    }
+	    return returnValue;
+	}
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java Tue Jan  8 02:55:24 2008
@@ -18,9 +18,13 @@
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import org.apache.harmony.pack200.bytecode.ConstantPoolEntry;
 
 import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.Segment;
@@ -28,6 +32,58 @@
 
 
 public class ClassConstantPool {
+    
+    class PoolComparator implements Comparator {
+        /* (non-Javadoc)
+         * Note: this comparator imposes orderings that are inconsistent with equals.
+         * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+         */
+        public int compare(Object o1, Object o2) {
+            // If we compare anything other than ConstantPoolEntries
+            // with this comparator, it is an error.
+            ConstantPoolEntry cpe1 = (ConstantPoolEntry)o1;
+            ConstantPoolEntry cpe2 = (ConstantPoolEntry)o2;
+
+            int domain1 = cpe1.getDomain();
+            int domain2 = cpe2.getDomain();
+            
+            if(domain1 < domain2) {
+                return -1;
+            }
+            if(domain1 > domain2) {
+                return 1;
+            }
+            
+            // Domains must be the same, need to compare
+            // based on name.
+            // TODO: what means name?
+            String compare1 = cpe1.comparisonString();
+            String compare2 = cpe2.comparisonString();
+            return compare1.compareTo(compare2);
+//            if(cpe1.creationOrder < cpe2.creationOrder) {
+//                return -1;
+//            } else {
+//                return 1;
+//            }
+        }
+    }
+    // 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;
+
+    protected SortedSet sortedEntries = new TreeSet(new PoolComparator());
+    
 	public String toString() {
 		return entries.toString();
 	}
@@ -38,15 +94,50 @@
 	private boolean resolved;
 
 	public ClassFileEntry add(ClassFileEntry entry) {
-		// TODO this should be a set - we don't want duplicates
+		// We don't want duplicates.
 		// Only add in constant pools, but resolve all types since they may
 		// introduce new constant pool entries
+// This is a handy way to see what's adding a ClassFileEntry - set a breakpoint on the print 
+//	    if(entry instanceof CPUTF8) {
+//	        System.out.println("AAH:" + ((CPUTF8)entry).comparisonString());
+//	        if (((CPUTF8)entry).comparisonString().matches("Ljava.*")) {
+//	            System.out.println("Adding");
+//	        }
+//	    }
 		if (entry instanceof ConstantPoolEntry) {
 			if (!entries.contains(entry)) {
 				entries.add(entry);
+				sortedEntries.add(entry);
 				// TODO This will be a bugger when they're sorted.
 				if (entry instanceof CPLong ||entry instanceof CPDouble)
 					entries.add(entry); //these get 2 slots because of their size
+			} else {
+			    // TODO: This is awful. If I'm presented with
+			    // an entry that has a lower domain than the
+			    // current entry but is otherwise the same,
+			    // change its domain and rebalance the tree.
+			    // And by "rebalance" I mean destroy and recreate
+			    // the tree.
+			    Iterator iterator = sortedEntries.iterator();
+			    boolean replaceTree = false;
+			    SortedSet newSortedSet = new TreeSet(new PoolComparator());
+			    while(iterator.hasNext()) {
+			        ConstantPoolEntry storedEntry = (ConstantPoolEntry)iterator.next();
+			        if(storedEntry.equals(entry)) {
+			            if(storedEntry.getDomain() > ((ConstantPoolEntry)entry).getDomain()) {
+			                // need to blow away the tree.
+			                replaceTree = true;
+			                newSortedSet.add(entry);
+			            } else {
+			                newSortedSet.add(storedEntry);
+			            }
+			        } else {
+			            newSortedSet.add(storedEntry);
+			        }
+			        if(replaceTree) {
+			            sortedEntries = newSortedSet;
+			        }
+			    }
 			}
 		} else {
 			if (!others.contains(entry))
@@ -82,34 +173,46 @@
 
 	public void resolve(Segment segment) {
 		SegmentUtils.debug("\n\nResolving (Segment.resolve(Segment)");
-		HashMap sortMap = new HashMap();
-		List cpAll = null;
-		// TODO: HACK - this is a 1.5 api.
-		// Need to do the right thing and do it with 1.4 API.
-		try {
-			cpAll = Arrays.asList(segment.getConstantPool().getCpAll());
-		} catch (Pack200Exception ex) {
-			ex.printStackTrace();
-		}
-		Iterator it = entries.iterator();
-		while(it.hasNext()) {
-			ClassFileEntry entry = (ClassFileEntry) it.next();
-			int indexInCpAll = cpAll.indexOf(entry);
-			if(indexInCpAll > 0) {
-				sortMap.put(new Integer(indexInCpAll), entry);
-			} else {
-				sortMap.put(new Integer(99999), entry);
-			}
-		}
-		ArrayList sortedList = new ArrayList();
-		for(int index=0; index < 99999; index++) {
-			if(sortMap.containsKey(new Integer(index))) {
-				sortedList.add((ClassFileEntry)sortMap.get(new Integer(index)));
-			}
-		}
-		for(int xindex=0; xindex < sortedList.size(); xindex++) {
-			SegmentUtils.debug(sortedList.get(xindex).toString());
-		}
+		// TODO: Be careful here, you're obliterating the original entries.
+		// In an ideal world, you wouldn't actually add to it unless you're
+		// sure.
+        entries = new ArrayList();
+//      entries.addAll(sortedEntries);
+      Iterator sortedIterator = sortedEntries.iterator();
+      while(sortedIterator.hasNext()) {
+          ConstantPoolEntry entry = (ConstantPoolEntry)sortedIterator.next();
+          entries.add(entry);
+          if (entry instanceof CPLong ||entry instanceof CPDouble)
+              entries.add(entry); //these get 2 slots because of their size
+      }
+//		HashMap sortMap = new HashMap();
+//		List cpAll = null;
+//		// TODO: HACK - this is a 1.5 api.
+//		// Need to do the right thing and do it with 1.4 API.
+//		try {
+//			cpAll = Arrays.asList(segment.getConstantPool().getCpAll());
+//		} catch (Pack200Exception ex) {
+//			ex.printStackTrace();
+//		}
+//		Iterator it = entries.iterator();
+//		while(it.hasNext()) {
+//			ClassFileEntry entry = (ClassFileEntry) it.next();
+//			int indexInCpAll = cpAll.indexOf(entry);
+//			if(indexInCpAll > 0) {
+//				sortMap.put(new Integer(indexInCpAll), entry);
+//			} else {
+//				sortMap.put(new Integer(99999), entry);
+//			}
+//		}
+//		ArrayList sortedList = new ArrayList();
+//		for(int index=0; index < 99999; index++) {
+//			if(sortMap.containsKey(new Integer(index))) {
+//				sortedList.add((ClassFileEntry)sortMap.get(new Integer(index)));
+//			}
+//		}
+//		for(int xindex=0; xindex < sortedList.size(); xindex++) {
+//			SegmentUtils.debug(sortedList.get(xindex).toString());
+//		}
 		resolve();
 	}
 	
@@ -124,7 +227,7 @@
 		while (it.hasNext()) {
 			ClassFileEntry entry = (ClassFileEntry) it.next();
 			entry.resolve(this);
-		}
+		}		
 	}
 
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CodeAttribute.java Tue Jan  8 02:55:24 2008
@@ -46,7 +46,7 @@
             // Setting the offset must happen before extracting operands
             // because label bytecodes need to know their offsets.
             byteCode.setByteCodeIndex(i);
-            byteCode.extractOperands(operandManager, segment);
+            byteCode.extractOperands(operandManager, segment, codeLength);
             byteCodes.add(byteCode);
             codeLength += byteCode.getLength();
             int lastBytecodePosition = ((Integer) byteCodeOffsets
@@ -64,13 +64,23 @@
                 byteCodeOffsets.add(new Integer(lastBytecodePosition
                         + byteCode.getLength()));
             }
+            if(byteCode.getOpcode() == 0xC4) {
+                // Special processing for wide bytecode - it knows what its
+                // instruction is from the opcode manager, so ignore the
+                // next instruction
+                i++;
+            }
         }
         // Now that all the bytecodes know their positions and
         // sizes, fix up the byte code targets
-        for (int i = 0; i < codePacked.length; i++) {
+        // At this point, byteCodes may be a different size than
+        // codePacked because of wide bytecodes.
+        for (int i = 0; i < byteCodes.size(); i++) {
             ByteCode byteCode = (ByteCode)byteCodes.get(i);
             byteCode.applyByteCodeTargetFixup(this);
         }
+        // TODO: By the time I get here, the input stream
+        // is somehow confused. 
     }
 
     protected int getLength() {
@@ -88,6 +98,9 @@
         ArrayList nestedEntries = new ArrayList();
         nestedEntries.add(getAttributeName());
         nestedEntries.addAll(byteCodes);
+        // TODO: Is this the right place to add code attribute
+        // attributes?
+        nestedEntries.addAll(attributes);
         ClassFileEntry[] nestedEntryArray = new ClassFileEntry[nestedEntries
                 .size()];
         nestedEntries.toArray(nestedEntryArray);
@@ -136,4 +149,11 @@
         }
     }
 
+    public void addAttribute(Attribute attribute) {
+        attributes.add(attribute);
+    }
+    
+    public List attributes() {
+        return attributes;
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java Tue Jan  8 02:55:24 2008
@@ -56,8 +56,15 @@
 
 	byte tag;
 
+	protected int domain = ClassConstantPool.DOMAIN_UNDEFINED;
+	public static int creationOrderCount = 100;
+	public String comparisonString() {
+	    return "" + creationOrder;
+	}
+	public int creationOrder = -1;
 	ConstantPoolEntry(byte tag) {
 		this.tag = tag;
+		this.creationOrder = creationOrderCount++;
 	}
 
 	public abstract boolean equals(Object obj);
@@ -66,6 +73,14 @@
 		return tag;
 	}
 
+	public int getDomain() {
+	    return domain;
+	}
+	
+	public void setDomain(int newDomain) {
+	    this.domain = newDomain;
+	}
+	
 	public abstract int hashCode();
 
 	public void doWrite(DataOutputStream dos) throws IOException {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/EnclosingMethodAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/EnclosingMethodAttribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/EnclosingMethodAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/EnclosingMethodAttribute.java Tue Jan  8 02:55:24 2008
@@ -24,12 +24,12 @@
     private int class_index;
     private int method_index;
     private CPClass cpClass;
-    private CPMethod cpMethod;
+    private CPNameAndType method;
 
-    public EnclosingMethodAttribute(CPClass cpClass, CPMethod cpMethod) {
+    public EnclosingMethodAttribute(CPClass cpClass, CPNameAndType method) {
         super("EnclosingMethod");
         this.cpClass = cpClass;
-        this.cpMethod = cpMethod;
+        this.method = method;
     }
 
     /* (non-Javadoc)
@@ -43,8 +43,8 @@
         super.resolve(pool);
         cpClass.resolve(pool);
         class_index = pool.indexOf(cpClass);
-        cpMethod.resolve(pool);
-        method_index = pool.indexOf(cpMethod);
+        method.resolve(pool);
+        method_index = pool.indexOf(method);
     }
 
     /* (non-Javadoc)

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LineNumberTableAttribute.java Tue Jan  8 02:55:24 2008
@@ -52,11 +52,17 @@
         return "LineNumberTable: " + line_number_table_length + " lines";
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.Attribute#getNestedClassFileEntries()
+     */
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        return new ClassFileEntry[] {getAttributeName()};
+    }
+    
 	/* (non-Javadoc)
 	 * @see org.apache.harmony.pack200.bytecode.Attribute#resolve(org.apache.harmony.pack200.bytecode.ClassConstantPool)
 	 */
 	protected void resolve(ClassConstantPool pool) {
-		pool.add(getAttributeName());
 		super.resolve(pool);
 	}
 

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/LocalVariableTableAttribute.java Tue Jan  8 02:55:24 2008
@@ -18,6 +18,7 @@
 
 import java.io.DataOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.List;
 
 public class LocalVariableTableAttribute extends BCIRenumberedAttribute {
@@ -58,17 +59,25 @@
         }
     }
 
+
+    protected ClassFileEntry[] getNestedClassFileEntries() {
+        ArrayList nestedEntries = new ArrayList();
+        nestedEntries.add(getAttributeName());
+        for (int i = 0; i < local_variable_table_length; i++) {
+            nestedEntries.add(names[i]);
+            nestedEntries.add(descriptors[i]);
+        }
+        ClassFileEntry[] nestedEntryArray = new ClassFileEntry[nestedEntries
+                .size()];
+        nestedEntries.toArray(nestedEntryArray);
+        return nestedEntryArray;        
+    }
+    
     protected void resolve(ClassConstantPool pool) {
         super.resolve(pool);
-        pool.add(getAttributeName());
         name_indexes = new int[local_variable_table_length];
         descriptor_indexes = new int[local_variable_table_length];
         for (int i = 0; i < local_variable_table_length; i++) {
-            // TODO: is this the right place to add the names and descriptors?
-            // Maybe some API to say where they should be added if they're not
-            // already in the cp?
-            pool.add(names[i]);
-            pool.add(descriptors[i]);
             names[i].resolve(pool);
             descriptors[i].resolve(pool);
             name_indexes[i] = pool.indexOf(names[i]);
@@ -88,22 +97,47 @@
      * @see org.apache.harmony.pack200.bytecode.BCIRenumberedAttribute#renumber(java.util.List)
      */
     public void renumber(List byteCodeOffsets) {
-        // First fix up the start_pcs
+        // Remember the unrenumbered start_pcs, since that's used later
+        // to calculate end position.
+        int[] unrenumbered_start_pcs = new int[start_pcs.length];
+        System.arraycopy(start_pcs, 0, unrenumbered_start_pcs, 0, start_pcs.length);
+
+        // Next renumber start_pcs in place
         super.renumber(byteCodeOffsets);
-        // Next fix up the lengths
-        int maxLength = ((Integer)byteCodeOffsets.get(byteCodeOffsets.size() - 1)).intValue();
+
+        // lengths are BRANCH5 encoded, not BCI-encoded.
+        // In other words:
+        //  start_pc is BCI5 start_pc
+        //  end_pc is byteCodeOffset[(index of start_pc in byteCodeOffset) + (encoded length)]
+        //  real length = end_pc - start_pc
+        // special case if end_pc is beyond end of bytecode array
+
+        // First figure out the maximum size of the byteCodeOffsets array
+        int lastInstruction = ((Integer)byteCodeOffsets.get(byteCodeOffsets.size() - 1)).intValue();
+        int maxSize = lastInstruction + 1;
+        
+        // Iterate through the lengths and update each in turn.
+        // This is done in place in the lengths array.
         for(int index=0; index < lengths.length; index++) {
-            // Need to special case when the length is greater than the size
+            int start_pc = start_pcs[index];
             int revisedLength = -1;
             int encodedLength = lengths[index];
+            
+            // First get the index of the start_pc in the byteCodeOffsets
+            int indexOfStartPC = unrenumbered_start_pcs[index];
+            // Given the index of the start_pc, we can now add
+            // the encodedLength to it to get the stop index.
+            int stopIndex = indexOfStartPC + encodedLength;
+            
             // Length can either be an index into the byte code offsets, or one beyond the
             // end of the byte code offsets. Need to determine which this is.
-            if(encodedLength == byteCodeOffsets.size()) {
+            if(stopIndex == byteCodeOffsets.size()) {
                 // Pointing to one past the end of the byte code array
-                revisedLength = maxLength - start_pcs[index] + 1;
+                revisedLength = maxSize - start_pc;
             } else {
                 // We're indexed into the byte code array
-                revisedLength = ((Integer)byteCodeOffsets.get(encodedLength)).intValue();                
+                int stopValue = ((Integer)byteCodeOffsets.get(stopIndex)).intValue();
+                revisedLength = stopValue - start_pc;                
             }
             lengths[index] = revisedLength;
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/OperandManager.java Tue Jan  8 02:55:24 2008
@@ -28,6 +28,8 @@
  */
 public class OperandManager {
 	
+    int[] bcCaseCount;
+    int[] bcCaseValue;
     int[] bcByte;
     int[] bcShort;
     int[] bcLocal;
@@ -46,7 +48,10 @@
 	int[] bcThisMethod;
 	int[] bcSuperMethod;
 	int[] bcInitRef;
+	int[] wideByteCodes;
     
+	int bcCaseCountIndex = 0;
+	int bcCaseValueIndex = 0;
 	int bcByteIndex = 0;
 	int bcShortIndex = 0;
 	int bcLocalIndex = 0;
@@ -65,6 +70,7 @@
 	int bcThisMethodIndex = 0;
 	int bcSuperMethodIndex = 0;
 	int bcInitRefIndex = 0;
+	int wideByteCodeIndex = 0;
     
 	Segment segment = null;
 	
@@ -72,7 +78,9 @@
 	String superClass = null;
 	String newClass = null;
 	
-	public OperandManager(int[] bcByte, int[]  bcShort, int[]  bcLocal, int[]  bcLabel, int[]  bcIntRef, int[]  bcFloatRef, int[]  bcLongRef, int[]  bcDoubleRef, int[]  bcStringRef, int[]  bcClassRef, int[]  bcFieldRef, int[]  bcMethodRef, int[] bcIMethodRef, int[] bcThisField, int[] bcSuperField, int[] bcThisMethod, int[] bcSuperMethod, int[] bcInitRef) {
+	public OperandManager(int[] bcCaseCount, int[] bcCaseValue, int[] bcByte, int[]  bcShort, int[]  bcLocal, int[]  bcLabel, int[]  bcIntRef, int[]  bcFloatRef, int[]  bcLongRef, int[]  bcDoubleRef, int[]  bcStringRef, int[]  bcClassRef, int[]  bcFieldRef, int[]  bcMethodRef, int[] bcIMethodRef, int[] bcThisField, int[] bcSuperField, int[] bcThisMethod, int[] bcSuperMethod, int[] bcInitRef, int[] wideByteCodes) {
+	    this.bcCaseCount = bcCaseCount;
+	    this.bcCaseValue = bcCaseValue;
 	    this.bcByte = bcByte;
 	    this.bcShort = bcShort;
 	    this.bcLocal = bcLocal;
@@ -92,8 +100,17 @@
 	    this.bcThisMethod = bcThisMethod;
 	    this.bcSuperMethod = bcSuperMethod;
 	    this.bcInitRef = bcInitRef;
+	    this.wideByteCodes = wideByteCodes;
 	}
     
+    public int nextCaseCount() {
+        return bcCaseCount[bcCaseCountIndex++];       
+    }
+    
+    public int nextCaseValues() {
+        return bcCaseValue[bcCaseValueIndex++];       
+    }
+    
 	public int nextByte() {
 		return bcByte[bcByteIndex++];		
 	}
@@ -166,6 +183,10 @@
 		return bcInitRef[bcInitRefIndex++];
 	}
 
+	public int nextWideByteCode() {
+	    return wideByteCodes[wideByteCodeIndex++];
+	}
+	
 	public void setSegment(Segment segment) {
 		this.segment = segment;
 	}

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/SourceFileAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/SourceFileAttribute.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/SourceFileAttribute.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/SourceFileAttribute.java Tue Jan  8 02:55:24 2008
@@ -27,7 +27,7 @@
 
 	public SourceFileAttribute(String name) {
 		super("SourceFile"); //$NON-NLS-1$
-		this.name = new CPUTF8(name);
+		this.name = new CPUTF8(name, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ);
 	}
 
 	public boolean equals(Object obj) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteCodeForm.java Tue Jan  8 02:55:24 2008
@@ -232,8 +232,8 @@
         byteCodeArray[167] = new LabelForm(167, "goto", new int[] {167, -1, -1});
         byteCodeArray[168] = new LabelForm(168, "jsr", new int[] {168, -1, -1});
         byteCodeArray[169] = new LocalForm(169, "ret", new int[] {169, -1});
-        byteCodeArray[170] = new SwitchForm(170, "tableswitch");
-        byteCodeArray[171] = new SwitchForm(171, "lookupswitch");
+        byteCodeArray[170] = new TableSwitchForm(170, "tableswitch");
+        byteCodeArray[171] = new LookupSwitchForm(171, "lookupswitch");
         byteCodeArray[172] = new NoArgumentForm(172, "ireturn");
         byteCodeArray[173] = new NoArgumentForm(173, "lreturn");
         byteCodeArray[174] = new NoArgumentForm(174, "freturn");
@@ -572,10 +572,13 @@
      * 
      * @param byteCode ByteCode to be updated (!)
      * @param operandManager OperandTable from which to draw info
-     * @param globalPool SegmentConstantPool used to index into
+     * @param codeLength Length of bytes (excluding this bytecode)
+     *      from the beginning of the method. Used in calculating
+     *      padding for some variable-length bytecodes (such as
+     *      lookupswitch, tableswitch).
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         throw new Error("My subclass should have implemented this");        
     }
 
@@ -587,7 +590,7 @@
      * @param codeAttribute a CodeAttribute used to determine how
      *   the ByteCode should be fixed up.
      */
-    public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) {
+    public void fixUpByteCodeTargets(ByteCode byteCode, CodeAttribute codeAttribute) {
         // Most ByteCodeForms don't have any fixing up to do.
         return;
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ByteForm.java Tue Jan  8 02:55:24 2008
@@ -41,7 +41,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         byteCode.setOperandByte(operandManager.nextByte() & 0xFF, 0);
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IMethodRefForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IMethodRefForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IMethodRefForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IMethodRefForm.java Tue Jan  8 02:55:24 2008
@@ -16,7 +16,9 @@
  */
 package org.apache.harmony.pack200.bytecode.forms;
 
+import org.apache.harmony.pack200.SegmentConstantPool;
 import org.apache.harmony.pack200.bytecode.ByteCode;
+import org.apache.harmony.pack200.bytecode.CPInterfaceMethodRef;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
 /**
@@ -24,7 +26,7 @@
  * bytecodes which have IMethod references (and only
  * IMethod references).
  */
-public class IMethodRefForm extends ByteCodeForm {
+public class IMethodRefForm extends ReferenceForm {
 
     public IMethodRefForm(int opcode, String name, 
             int[] rewrite) {
@@ -39,13 +41,21 @@
         return true;
     }
 
+    protected int getOffset(OperandManager operandManager) {
+        return operandManager.nextIMethodRef();
+    }
+
+    protected int getPoolID() {
+        return SegmentConstantPool.CP_IMETHOD;
+    }
+    
     /* (non-Javadoc)
-     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
+     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.Segment)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-//TODO: implement this. Removed the error message because
-//        it causes failures in the JUnit tests.
-//        throw new Error("Not implemented yet");        
+            OperandManager operandManager, int codeLength) {
+        super.setByteCodeOperands(byteCode, operandManager, codeLength);
+        int count=((CPInterfaceMethodRef)byteCode.getNestedClassFileEntries()[0]).invokeInterfaceCount();
+        byteCode.getRewrite()[3] = count;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IincForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IincForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IincForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/IincForm.java Tue Jan  8 02:55:24 2008
@@ -41,7 +41,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         int local = operandManager.nextLocal();
         int constant = operandManager.nextByte();
         byteCode.setOperandBytes(new int[]{local, constant});

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LabelForm.java Tue Jan  8 02:55:24 2008
@@ -50,9 +50,9 @@
     /* (non-Javadoc)
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#fixUpByteCodeTarget(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.CodeAttribute)
      */
-    public void fixUpByteCodeTarget(ByteCode byteCode, CodeAttribute codeAttribute) {
+    public void fixUpByteCodeTargets(ByteCode byteCode, CodeAttribute codeAttribute) {
         // LabelForms need to fix up the target of label operations
-        int originalTarget = byteCode.getByteCodeTarget();
+        int originalTarget = byteCode.getByteCodeTargets()[0];
         int sourceIndex = byteCode.getByteCodeIndex();
         int absoluteInstructionTargetIndex = sourceIndex + originalTarget;
         int targetValue = ((Integer)codeAttribute.byteCodeOffsets.get(absoluteInstructionTargetIndex)).intValue();
@@ -60,7 +60,7 @@
         // The operand is the difference between the source instruction
         // and the destination instruction.
         // TODO: Probably have to do something other than setOperandInt if this is widened.
-        byteCode.setOperandSignedInt(targetValue - sourceValue, 0);
+        byteCode.setOperandSigned2Bytes(targetValue - sourceValue, 0);
         if(widened) {
             byteCode.setNestedPositions(new int[][] {{0,4}});
         } else {
@@ -72,8 +72,8 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-        byteCode.setByteCodeTarget(operandManager.nextLabel());
+            OperandManager operandManager, int codeLength) {
+        byteCode.setByteCodeTargets(new int[] {operandManager.nextLabel()});
         // The byte code operands actually get set later -
         // once we have all the bytecodes - in fixUpByteCodeTarget().
         return;

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LocalForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LocalForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LocalForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/LocalForm.java Tue Jan  8 02:55:24 2008
@@ -48,7 +48,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         byteCode.setOperandBytes(new int[]{operandManager.nextLocal()});
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/MultiANewArrayForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/MultiANewArrayForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/MultiANewArrayForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/MultiANewArrayForm.java Tue Jan  8 02:55:24 2008
@@ -50,10 +50,10 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         // multianewarray has a class ref and a dimension.
         // The superclass handles the class ref.
-        super.setByteCodeOperands(byteCode, operandManager);
+        super.setByteCodeOperands(byteCode, operandManager, codeLength);
         
         // We have to handle the dimension.
         int dimension = operandManager.nextByte();

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NewClassRefForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NewClassRefForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NewClassRefForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NewClassRefForm.java Tue Jan  8 02:55:24 2008
@@ -44,7 +44,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ReferenceForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandManager)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         ClassFileEntry[] nested = null;
         int offset = getOffset(operandManager);
         if(offset == 0) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NoArgumentForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NoArgumentForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NoArgumentForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/NoArgumentForm.java Tue Jan  8 02:55:24 2008
@@ -44,7 +44,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         // Nothing to do for no-argument form
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ReferenceForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ReferenceForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ReferenceForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ReferenceForm.java Tue Jan  8 02:55:24 2008
@@ -50,7 +50,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.Segment)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
+            OperandManager operandManager, int codeLength) {
         int offset = getOffset(operandManager);
         try {
             setNestedEntries(byteCode, operandManager, offset);

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ShortForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ShortForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ShortForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/ShortForm.java Tue Jan  8 02:55:24 2008
@@ -42,7 +42,7 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-        byteCode.setOperandInt(operandManager.nextShort(), 0);
+            OperandManager operandManager, int codeLength) {
+        byteCode.setOperand2Bytes(operandManager.nextShort(), 0);
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/SwitchForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/SwitchForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/SwitchForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/SwitchForm.java Tue Jan  8 02:55:24 2008
@@ -17,9 +17,10 @@
 package org.apache.harmony.pack200.bytecode.forms;
 
 import org.apache.harmony.pack200.bytecode.ByteCode;
+import org.apache.harmony.pack200.bytecode.CodeAttribute;
 import org.apache.harmony.pack200.bytecode.OperandManager;
 
-public class SwitchForm extends ByteCodeForm {
+public abstract class SwitchForm extends VariableInstructionForm {
 
     public SwitchForm(int opcode, String name) {
         super(opcode, name);
@@ -43,9 +44,29 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-//TODO: implement this. Removed the error message because
-//        it causes failures in the JUnit tests.
-//        throw new Error("Not implemented yet");        
+            OperandManager operandManager, int codeLength) {
     }
+    
+    /* (non-Javadoc)
+     * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#fixUpByteCodeTargets(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.CodeAttribute)
+     */
+    public void fixUpByteCodeTargets(ByteCode byteCode, CodeAttribute codeAttribute) {
+        // SwitchForms need to fix up the target of label operations
+        int[] originalTargets = byteCode.getByteCodeTargets();
+        int numberOfLabels = originalTargets.length;
+        int[] replacementTargets = new int[numberOfLabels];
+        
+        int sourceIndex = byteCode.getByteCodeIndex();
+        int sourceValue = ((Integer)codeAttribute.byteCodeOffsets.get(sourceIndex)).intValue();
+        for(int index=0; index < numberOfLabels; index++) {
+            int absoluteInstructionTargetIndex = sourceIndex + originalTargets[index];
+            int targetValue = ((Integer)codeAttribute.byteCodeOffsets.get(absoluteInstructionTargetIndex)).intValue();
+            replacementTargets[index] = targetValue - sourceValue;
+        }
+        int[] rewriteArray = byteCode.getRewrite();
+        for(int index=0; index < numberOfLabels; index++) {
+            setRewrite4Bytes(replacementTargets[index], rewriteArray);
+        }
+    }
+
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java Tue Jan  8 02:55:24 2008
@@ -25,7 +25,7 @@
  * can take multiple forms, depending on what is being
  * widened.
  */
-public class WideForm extends ByteCodeForm {
+public class WideForm extends VariableInstructionForm {
 
     public WideForm(int opcode, String name) {
         super(opcode, name);
@@ -47,9 +47,99 @@
      * @see org.apache.harmony.pack200.bytecode.forms.ByteCodeForm#setByteCodeOperands(org.apache.harmony.pack200.bytecode.ByteCode, org.apache.harmony.pack200.bytecode.OperandTable, org.apache.harmony.pack200.SegmentConstantPool)
      */
     public void setByteCodeOperands(ByteCode byteCode,
-            OperandManager operandManager) {
-//TODO: implement this. Removed the error message because
-//      it causes failures in the JUnit tests.
-//      throw new Error("Not implemented yet");        
+            OperandManager operandManager, int codeLength) {
+        int instruction = operandManager.nextWideByteCode();
+        if(instruction == 132) {
+            setByteCodeOperandsFormat2(instruction, byteCode, operandManager, codeLength);
+        } else {
+            setByteCodeOperandsFormat1(instruction, byteCode, operandManager, codeLength);
+        }
+    }
+
+    /**
+     * This method sets the rewrite array for the bytecode
+     * using Format 1 of the JVM spec: an opcode and two index
+     * bytes. This is used for ?load/?store/ret
+     * @param instruction should be 132
+     * @param byteCode the byte code whose rewrite array should be updated
+     * @param operandManager the source of the operands
+     * @param codeLength ignored
+     */
+    protected void setByteCodeOperandsFormat1(int instruction, ByteCode byteCode,
+            OperandManager operandManager, int codeLength) {
+        
+        // Even though this code is really similar to the
+        // code for setByteCodeOperandsFormat2, I've left it
+        // distinct here. This is so changing one will
+        // not change the other - if there is a need to change,
+        // there's a good chance that the formats will
+        // differ, so an updater will not have to disentangle
+        // it.
+        int local = operandManager.nextLocal();
+        
+        // Unlike most byte codes, the wide bytecode is a
+        // variable-sized bytecode. Because of this, the
+        // rewrite array has to be defined here individually
+        // for each bytecode, rather than in the ByteCodeForm
+        // class.
+        
+        int[] newRewrite = new int[4];
+        int rewriteIndex = 0;
+        
+        // Fill in what we can now
+        // wide opcode
+        newRewrite[rewriteIndex++] = byteCode.getOpcode();
+        
+        // "real" instruction that is widened
+        newRewrite[rewriteIndex++] = instruction;
+
+        // Index bytes
+        setRewrite2Bytes(local, rewriteIndex, newRewrite);
+        rewriteIndex +=2;
+        
+        byteCode.setRewrite(newRewrite);
+    }
+
+    
+    /**
+     * This method sets the rewrite array for the bytecode
+     * using Format 2 of the JVM spec: an opcode, two index
+     * bytes, and two constant bytes. This is used for iinc.
+     * @param instruction int should be 132
+     * @param byteCode ByteCode whose rewrite array should be updated
+     * @param operandManager OperandManager source of the operands
+     * @param codeLength ignored
+     */
+    protected void setByteCodeOperandsFormat2(int instruction, ByteCode byteCode,
+            OperandManager operandManager, int codeLength) {
+    
+        int local = operandManager.nextLocal();        
+        int constWord = operandManager.nextShort();
+        
+        // Unlike most byte codes, the wide bytecode is a
+        // variable-sized bytecode. Because of this, the
+        // rewrite array has to be defined here individually
+        // for each bytecode, rather than in the ByteCodeForm
+        // class.
+        
+        int[] newRewrite = new int[6];
+        int rewriteIndex = 0;
+        
+        // Fill in what we can now
+        // wide opcode
+        newRewrite[rewriteIndex++] = byteCode.getOpcode();
+        
+        // "real" instruction that is widened
+        newRewrite[rewriteIndex++] = instruction;
+
+        // Index bytes
+        setRewrite2Bytes(local, rewriteIndex, newRewrite);
+        rewriteIndex +=2;
+        
+        // constant bytes
+        setRewrite2Bytes(constWord, rewriteIndex, newRewrite);
+        rewriteIndex += 2; // not strictly necessary, but just in case something comes along later
+        
+        byteCode.setRewrite(newRewrite);
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BandSetTest.java Tue Jan  8 02:55:24 2008
@@ -26,7 +26,6 @@
 import org.apache.harmony.pack200.BHSDCodec;
 import org.apache.harmony.pack200.BandSet;
 import org.apache.harmony.pack200.Codec;
-import org.apache.harmony.pack200.CodecEncoding;
 import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.Segment;
 import org.apache.harmony.pack200.SegmentHeader;

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java Tue Jan  8 02:55:24 2008
@@ -57,7 +57,7 @@
 	    public String[] getCpString() {
         	String[] classes = new String[100];
         	for(int index=0; index < 100; index++) {
-        		classes[index] = "java/lang/Stri:ng";
+        		classes[index] = "java/lang/Stri:ng(J)";
         	}
         	return classes;
 	    }
@@ -74,14 +74,22 @@
 	    	return getCpString();
 	    }
 	    
-	    public String[] getCpMethodClass() {
-	    	return getCpClass();
-	    }
-	    
-	    public String[] getCpMethodDescriptor() {
-	    	return getCpString();
-	    }
-	    
+        public String[] getCpMethodClass() {
+            return getCpClass();
+        }
+        
+        public String[] getCpMethodDescriptor() {
+            return getCpString();
+        }
+        
+        public String[] getCpIMethodClass() {
+            return getCpClass();
+        }
+        
+        public String[] getCpIMethodDescriptor() {
+            return getCpString();
+        }
+        
 	    public int[] getCpInt() {
         	int[] elements = new int[100];
         	for(int index=0; index < 100; index++) {
@@ -292,22 +300,21 @@
      * @throws IOException 
      */
     public void testBcCaseBands() throws IOException, Pack200Exception {
-        byte[] bytes = new byte[] {(byte)170,(byte)171, (byte)255,
+        byte[] bytes = new byte[] { (byte)170, (byte)171, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte)255, 
                 2, 5, // bc_case_count
-                8, 8, 8, 8, 8, 8, 8, // bc_case_value
-                8, 8}; // bc_label                
+                0, 0, 0, 0, 0, 0, 0, // bc_case_value
+                0, 0, 0, 0, 0, 0, 0, 0, 0}; // bc_label                
         InputStream in = new ByteArrayInputStream(bytes);
         bcBands.unpack(in);
-        assertEquals(2, bcBands.getMethodByteCodePacked()[0][0].length);
+        assertEquals(18, bcBands.getMethodByteCodePacked()[0][0].length);
         int[] bc_case_count = bcBands.getBcCaseCount();
         assertEquals(2, bc_case_count.length);
         assertEquals(2, bc_case_count[0]);
         assertEquals(5, bc_case_count[1]);
-        int[][] bc_case_value = bcBands.getBcCaseValue();
-        assertEquals(2, bc_case_value.length);
-        assertEquals(2, bc_case_value[0].length);
-        assertEquals(5, bc_case_value[1].length);
-        assertEquals(2, bcBands.getBcLabel().length);
+        int[] bc_case_value = bcBands.getBcCaseValue();
+        assertEquals(0, bc_case_value[0]);
+        assertEquals(0, bc_case_value[1]);
+        assertEquals(9, bcBands.getBcLabel().length);
     }
     
     /**
@@ -341,10 +348,9 @@
      */
     public void testBcShortBand() throws IOException, Pack200Exception {
     	//TODO: Need to fix this testcase so it has enough data to pass.
-    	if(true) return;
         byte[] bytes = new byte[] {17, (byte)196, (byte)132, (byte)255, 
                 8, 8,// bc_short band
-                8, 8}; // bc_locals band (required by wide iinc (196, 132))
+                8, 8, 8, 8}; // bc_locals band (required by wide iinc (196, 132))
         InputStream in = new ByteArrayInputStream(bytes);
         bcBands.unpack(in);
         assertEquals(3, bcBands.getMethodByteCodePacked()[0][0].length);
@@ -377,15 +383,29 @@
     public void testBcLabelBand() throws IOException, Pack200Exception {
         byte[] bytes = new byte[] {(byte) 159, (byte) 160, (byte) 161,
                 (byte) 162, (byte) 163, (byte) 164, (byte) 165, (byte) 166,
-                (byte) 167, (byte) 168, (byte) 170, (byte) 171, (byte) 198, (byte) 199, (byte) 200, (byte) 201, (byte) 255,
-                0, 0, // bc_case_count (required by tableswitch (170) and lookupswitch (171))
+                (byte) 167, (byte) 168,  (byte) 170, (byte) 171,  (byte) 198, (byte) 199, (byte) 200, (byte) 201, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, (byte) 255,
+                2, 2, // bc_case_count (required by tableswitch (170) and lookupswitch (171))
+                0, 0, 0, 0, // bc_case_value
 //                Now that we're actually doing real label lookup, need valid labels
 //                8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8 }; // bc_label band                
-                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // bc_label band
+                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; // bc_label band
         InputStream in = new ByteArrayInputStream(bytes);
         bcBands.unpack(in);
-        assertEquals(16, bcBands.getMethodByteCodePacked()[0][0].length);
-        assertEquals(16, bcBands.getBcLabel().length);
+        assertEquals(36, bcBands.getMethodByteCodePacked()[0][0].length);
+        assertEquals(20, bcBands.getBcLabel().length);
+    }
+    
+    public void testWideForms() throws IOException, Pack200Exception {
+        byte[] bytes = new byte[] {(byte) 196, (byte) 54, // wide istore
+                (byte) 196, (byte) 132, // wide iinc
+                (byte) 255, 
+                0, // bc_short band
+                0, 0, 0, 1}; // bc_locals band 
+        InputStream in = new ByteArrayInputStream(bytes);
+        bcBands.unpack(in);
+        assertEquals(4, bcBands.getMethodByteCodePacked()[0][0].length);
+        assertEquals(4, bcBands.getBcLocal().length);
+        assertEquals(1, bcBands.getBcShort().length);
     }
     
     /**

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java Tue Jan  8 02:55:24 2008
@@ -77,7 +77,9 @@
     public class MockOperandManager extends OperandManager {
 
         public MockOperandManager() {
-            super(new int[] {}, // bcByte
+            super(new int[] {}, // bcCaseCount
+                    new int[] {}, // bcCaseValues
+                    new int[] {}, // bcByte
                     new int[] {}, // bcShort
                     new int[] {}, // bcLocal
                     new int[] {}, // bcLabel
@@ -95,6 +97,7 @@
                     new int[] { 0 }, // bcThisMethod
                     new int[] {}, // bcSuperMethod
                     new int[] {} // bcInitRef
+, null
             );
         }
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java Tue Jan  8 02:55:24 2008
@@ -14,9 +14,9 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.apache.harmony.pack200.tests;
 
+
 import junit.framework.TestCase;
 
 import org.apache.harmony.pack200.IMatcher;
@@ -50,6 +50,17 @@
 		assertEquals(3, SegmentUtils.countArgs("(Lblah/blah;DLbLah;)V"));
 	}
 
+	public void testCountInvokeInterfaceArgs() {
+	    assertEquals(1, SegmentUtils.countInvokeInterfaceArgs("(Z)V"));
+        assertEquals(2, SegmentUtils.countInvokeInterfaceArgs("(D)V"));
+        assertEquals(2, SegmentUtils.countInvokeInterfaceArgs("(J)V"));
+        assertEquals(1, SegmentUtils.countInvokeInterfaceArgs("([D)V"));
+        assertEquals(1, SegmentUtils.countInvokeInterfaceArgs("([[D)V"));
+        assertEquals(4, SegmentUtils.countInvokeInterfaceArgs("(DD)V"));
+        assertEquals(3, SegmentUtils.countInvokeInterfaceArgs("(Lblah/blah;D)V"));
+        assertEquals(4, SegmentUtils.countInvokeInterfaceArgs("(Lblah/blah;DLbLah;)V"));
+        assertEquals(4, SegmentUtils.countInvokeInterfaceArgs("([Lblah/blah;DLbLah;)V"));
+	}
 	public void testMatches() {
 		long[] oneToTen = new long[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
 		assertEquals(6, SegmentUtils.countMatches(new long[][] { oneToTen,

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java Tue Jan  8 02:55:24 2008
@@ -25,13 +25,14 @@
 import org.apache.harmony.pack200.bytecode.CPMember;
 import org.apache.harmony.pack200.bytecode.CPString;
 import org.apache.harmony.pack200.bytecode.CPUTF8;
+import org.apache.harmony.pack200.bytecode.ClassConstantPool;
 import org.apache.harmony.pack200.bytecode.SourceFileAttribute;
 
 public class ClassFileEntryTest extends TestCase {
 	public void testUTF8() {
-		CPUTF8 u1 = new CPUTF8(new String("thing")); //$NON-NLS-1$
-		CPUTF8 u2 = new CPUTF8(new String("thing")); //$NON-NLS-1$
-		CPUTF8 u3 = new CPUTF8(new String("otherthing")); //$NON-NLS-1$
+		CPUTF8 u1 = new CPUTF8(new String("thing"), ClassConstantPool.DOMAIN_UNDEFINED); //$NON-NLS-1$
+		CPUTF8 u2 = new CPUTF8(new String("thing"), ClassConstantPool.DOMAIN_UNDEFINED); //$NON-NLS-1$
+		CPUTF8 u3 = new CPUTF8(new String("otherthing"), ClassConstantPool.DOMAIN_UNDEFINED); //$NON-NLS-1$
 		checkEquality(u1, u2, "thing", u3);
 	}
 	private void checkEquality(Object equal1, Object equal2, String toString, Object unequal) {

Modified: harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java Tue Jan  8 02:55:24 2008
@@ -29,8 +29,8 @@
 		pool = new ClassConstantPool();
 	}
 	public void testDuplicateUTF8() {
-		CPUTF8 u1 = new CPUTF8("thing");
-		CPUTF8 u2 = new CPUTF8("thing");
+		CPUTF8 u1 = new CPUTF8("thing", ClassConstantPool.DOMAIN_UNDEFINED);
+		CPUTF8 u2 = new CPUTF8("thing", ClassConstantPool.DOMAIN_UNDEFINED);
 		pool.add(u1);
 		pool.add(u2);
 		assertEquals(1,pool.size());
@@ -44,8 +44,8 @@
 		assertEquals(2,pool.size());
 	}
 	public void testIndex() {
-		pool.add(new CPUTF8("OtherThing"));
-		CPUTF8 u1 = new CPUTF8("thing");
+		pool.add(new CPUTF8("OtherThing", ClassConstantPool.DOMAIN_UNDEFINED));
+		CPUTF8 u1 = new CPUTF8("thing", ClassConstantPool.DOMAIN_UNDEFINED);
 		pool.add(u1);
 		pool.resolve();
 		assertTrue(pool.indexOf(u1) > 0);

Modified: harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/WinPrintJob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/WinPrintJob.java?rev=609928&r1=609927&r2=609928&view=diff
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/WinPrintJob.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/print/src/main/java/windows/org/apache/harmony/x/print/WinPrintJob.java Tue Jan  8 02:55:24 2008
@@ -364,7 +364,7 @@
                 startJob(pdc, getDocName(pageable, docAttrs, attributes),
                                 getDestinationPath(attributes));
 
-                for (int i = 0; i <= pages; i++) {
+                for (int i = 0; i < pages; i++) {
                     if ((ranges != null) && !ranges.contains(i)) {
                         continue;
                     }



Mime
View raw message