You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2008/01/04 11:10:36 UTC
svn commit: r608790 [2/2] - in
/harmony/enhanced/classlib/trunk/modules/pack200/src:
main/java/org/apache/harmony/pack200/
main/java/org/apache/harmony/pack200/bytecode/
main/java/org/apache/harmony/pack200/bytecode/forms/
test/java/org/apache/harmony/...
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/forms/WideForm.java Fri Jan 4 02:10:32 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);
@@ -48,8 +48,98 @@
*/
public void setByteCodeOperands(ByteCode byteCode,
OperandManager operandManager, int codeLength) {
-//TODO: implement this. Removed the error message because
-// it causes failures in the JUnit tests.
-// throw new Error("Not implemented yet");
+ 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/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/BcBandsTest.java Fri Jan 4 02:10:32 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,21 +300,20 @@
* @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
- 0, 1, 0, 1, 2, 3, 4, // bc_case_value
+ 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);
+ 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/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/CodeAttributeTest.java Fri Jan 4 02:10:32 2008
@@ -78,7 +78,7 @@
public MockOperandManager() {
super(new int[] {}, // bcCaseCount
- new int[][] {}, // bcCaseValues
+ new int[] {}, // bcCaseValues
new int[] {}, // bcByte
new int[] {}, // bcShort
new int[] {}, // bcLocal
@@ -97,6 +97,7 @@
new int[] { 0 }, // bcThisMethod
new int[] {}, // bcSuperMethod
new int[] {} // bcInitRef
+, null
);
}
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/SegmentUtilsTest.java Fri Jan 4 02:10:32 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/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ClassFileEntryTest.java Fri Jan 4 02:10:32 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/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java?rev=608790&r1=608789&r2=608790&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/test/java/org/apache/harmony/pack200/tests/bytecode/ConstantPoolTest.java Fri Jan 4 02:10:32 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);