You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by sj...@apache.org on 2008/05/01 10:19:41 UTC
svn commit: r652453 - in
/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200:
./ bytecode/ bytecode/forms/
Author: sjanuary
Date: Thu May 1 01:19:41 2008
New Revision: 652453
URL: http://svn.apache.org/viewvc?rev=652453&view=rev
Log:
Pack200 - fixed several bugs that caused the class constant pool ordering to be wrong
Modified:
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java
harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/BcBands.java Thu May 1 01:19:41 2008
@@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import org.apache.harmony.pack200.Codec;
@@ -28,8 +29,11 @@
import org.apache.harmony.unpack200.bytecode.ByteCode;
import org.apache.harmony.unpack200.bytecode.CPClass;
import org.apache.harmony.unpack200.bytecode.CodeAttribute;
+import org.apache.harmony.unpack200.bytecode.DeprecatedAttribute;
import org.apache.harmony.unpack200.bytecode.ExceptionTableEntry;
import org.apache.harmony.unpack200.bytecode.OperandManager;
+import org.apache.harmony.unpack200.bytecode.RuntimeVisibleorInvisibleAnnotationsAttribute;
+import org.apache.harmony.unpack200.bytecode.SignatureAttribute;
/**
* Bytecode bands
@@ -424,7 +428,21 @@
CodeAttribute codeAttr = new CodeAttribute(maxStack,
maxLocal, methodByteCodePacked[c][m], segment,
operandManager, exceptionTable);
- methodAttributes[c][m].add(codeAttr);
+ ArrayList methodAttributesList = methodAttributes[c][m];
+ // Make sure we add the code attribute in the right place
+ int indexForCodeAttr = 0;
+ for (Iterator iterator = methodAttributesList.iterator(); iterator
+ .hasNext();) {
+ Attribute attribute = (Attribute) iterator.next();
+ if(attribute instanceof SignatureAttribute ||
+ attribute instanceof DeprecatedAttribute ||
+ attribute instanceof RuntimeVisibleorInvisibleAnnotationsAttribute) {
+ indexForCodeAttr ++;
+ } else {
+ break;
+ }
+ }
+ methodAttributesList.add(indexForCodeAttr, codeAttr);
codeAttr.renumber(codeAttr.byteCodeOffsets);
ArrayList currentAttributes = (ArrayList) orderedCodeAttributes
.get(i);
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/CpBands.java Thu May 1 01:19:41 2008
@@ -356,6 +356,11 @@
}
cpSignature[i] = signature.toString();
}
+ for (int i = 0; i < cpSignatureInts.length; i++) {
+ if(cpSignatureInts[i] == -1) {
+ cpSignatureInts[i] = search(cpUTF8, cpSignature[i]);
+ }
+ }
}
/**
@@ -697,9 +702,11 @@
}
public CPUTF8 cpSignatureValue(int index, int domain) {
- int globalIndex = index + signatureOffset;
+ int globalIndex;
if(cpSignatureInts[index] != -1) {
globalIndex = cpSignatureInts[index];
+ } else {
+ globalIndex = index + signatureOffset;
}
if (stringsToCPUTF8[domain] == null) {
stringsToCPUTF8[domain] = new HashMap();
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/Segment.java Thu May 1 01:19:41 2008
@@ -220,14 +220,12 @@
.getMethodFlags()[classNum][i], classBands
.getMethodAttributes()[classNum][i]));
}
+ cp.addNestedEntries();
// add inner class attribute (if required)
boolean addInnerClassesAttr = false;
IcTuple[] ic_local = getClassBands().getIcLocal()[classNum];
- boolean ic_local_sent = false;
- if (ic_local != null) {
- ic_local_sent = true;
- }
+ boolean ic_local_sent = ic_local != null;
InnerClassesAttribute innerClassesAttribute = new InnerClassesAttribute(
"InnerClasses");
IcTuple[] ic_relevant = getIcBands().getRelevantIcTuples(fullName, cp);
@@ -288,9 +286,8 @@
}
newAttrs[newAttrs.length - 1] = innerClassesAttribute;
classFile.attributes = newAttrs;
- cp.add(innerClassesAttribute);
+ cp.addWithNestedEntries(innerClassesAttribute);
}
- cp.addNestedEntries();
// sort CP according to cp_All
cp.resolve(this);
// NOTE the indexOf is only valid after the cp.resolve()
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ByteCode.java Thu May 1 01:19:41 2008
@@ -373,4 +373,8 @@
public int[] getRewrite() {
return rewrite;
}
+
+ public boolean nestedMustStartClassPool() {
+ return byteCodeForm.nestedMustStartClassPool();
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassConstantPool.java Thu May 1 01:19:41 2008
@@ -52,6 +52,8 @@
protected HashSet entriesContainsSet = new HashSet();
protected HashSet othersContainsSet = new HashSet();
+ private final HashSet mustStartClassPool = new HashSet();
+
protected Map indexCache = null;
public String toString() {
@@ -117,6 +119,11 @@
ClassFileEntry entry = (ClassFileEntry) iterator.next();
ClassFileEntry[] nestedEntries = entry.getNestedClassFileEntries();
newEntries.addAll(Arrays.asList(nestedEntries));
+ if(entry instanceof ByteCode) {
+ if(((ByteCode)entry).nestedMustStartClassPool()) {
+ mustStartClassPool.addAll(Arrays.asList(nestedEntries));
+ }
+ }
}
for (Iterator iterator = newEntries.iterator(); iterator.hasNext();) {
add((ClassFileEntry) iterator.next());
@@ -256,7 +263,7 @@
ArrayList finalSort = new ArrayList();
while (it.hasNext()) {
ClassFileEntry nextEntry = (ClassFileEntry) it.next();
- if (nextEntry.mustStartClassPool()) {
+ if (mustStartClassPool.contains(nextEntry)) {
startOfPool.add(nextEntry);
} else {
finalSort.add(nextEntry);
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ClassFileEntry.java Thu May 1 01:19:41 2008
@@ -58,14 +58,4 @@
doWrite(dos);
}
- /**
- * Answer true if the receiver must be at the beginning of the class pool
- * (because it is the target of a single-byte ldc command). Otherwise answer
- * false.
- *
- * @return boolean true if the receiver must be under 256; otherwise false.
- */
- public boolean mustStartClassPool() {
- return false;
- }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/ConstantPoolEntry.java Thu May 1 01:19:41 2008
@@ -87,30 +87,6 @@
protected abstract void writeBody(DataOutputStream dos) throws IOException;
- private boolean mustStartClassPool = false;
-
- /**
- * Set whether the receiver must be at the start of the class pool. Anything
- * which is the target of a single- byte ldc (bytecode 18) command must be
- * at the start of the class pool.
- *
- * @param b
- * boolean true if the receiver must be at the start of the class
- * pool, otherwise false.
- */
- public void mustStartClassPool(boolean b) {
- mustStartClassPool = b;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.apache.harmony.unpack200.bytecode.ClassFileEntry#mustStartClassPool()
- */
- public boolean mustStartClassPool() {
- return mustStartClassPool;
- }
-
public int getGlobalIndex() {
return globalIndex;
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/LocalVariableTypeTableAttribute.java Thu May 1 01:19:41 2008
@@ -18,11 +18,15 @@
import java.io.DataOutputStream;
import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.harmony.unpack200.Pack200Exception;
/**
* Local variable type table.
*/
-public class LocalVariableTypeTableAttribute extends Attribute {
+public class LocalVariableTypeTableAttribute extends BCIRenumberedAttribute {
private int local_variable_type_table_length;
private final int[] start_pcs;
@@ -74,6 +78,83 @@
}
}
+ protected ClassFileEntry[] getNestedClassFileEntries() {
+ ArrayList nestedEntries = new ArrayList();
+ nestedEntries.add(getAttributeName());
+ for (int i = 0; i < local_variable_type_table_length; i++) {
+ nestedEntries.add(names[i]);
+ nestedEntries.add(signatures[i]);
+ }
+ ClassFileEntry[] nestedEntryArray = new ClassFileEntry[nestedEntries
+ .size()];
+ nestedEntries.toArray(nestedEntryArray);
+ return nestedEntryArray;
+ }
+
+ protected int[] getStartPCs() {
+ return start_pcs;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.apache.harmony.unpack200.bytecode.BCIRenumberedAttribute#renumber(java.util.List)
+ */
+ public void renumber(List byteCodeOffsets) throws Pack200Exception {
+ // 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);
+
+ // 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++) {
+ 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;
+ if (stopIndex < 0) {
+ throw new Pack200Exception("Error renumbering bytecode indexes");
+ }
+ // 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 (stopIndex == byteCodeOffsets.size()) {
+ // Pointing to one past the end of the byte code array
+ revisedLength = maxSize - start_pc;
+ } else {
+ // We're indexed into the byte code array
+ int stopValue = ((Integer) byteCodeOffsets.get(stopIndex))
+ .intValue();
+ revisedLength = stopValue - start_pc;
+ }
+ lengths[index] = revisedLength;
+ }
+ }
+
+
public String toString() {
return "LocalVariableTypeTable: " + +local_variable_type_table_length
+ " varaibles";
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/ByteCodeForm.java Thu May 1 01:19:41 2008
@@ -678,4 +678,8 @@
// Most ByteCodeForms don't have any fixing up to do.
return;
}
+
+ public boolean nestedMustStartClassPool() {
+ return false;
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/NarrowClassRefForm.java Thu May 1 01:19:41 2008
@@ -18,7 +18,6 @@
import org.apache.harmony.unpack200.Pack200Exception;
import org.apache.harmony.unpack200.bytecode.ByteCode;
-import org.apache.harmony.unpack200.bytecode.CPClass;
import org.apache.harmony.unpack200.bytecode.OperandManager;
/**
@@ -41,8 +40,10 @@
super.setNestedEntries(byteCode, operandManager, offset);
if (!widened) {
byteCode.setNestedPositions(new int[][] { { 0, 1 } });
- ((CPClass) byteCode.getNestedClassFileEntries()[0])
- .mustStartClassPool(true);
}
}
+
+ public boolean nestedMustStartClassPool() {
+ return !widened;
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/SingleByteReferenceForm.java Thu May 1 01:19:41 2008
@@ -18,7 +18,6 @@
import org.apache.harmony.unpack200.Pack200Exception;
import org.apache.harmony.unpack200.bytecode.ByteCode;
-import org.apache.harmony.unpack200.bytecode.ConstantPoolEntry;
import org.apache.harmony.unpack200.bytecode.OperandManager;
/**
@@ -44,8 +43,10 @@
byteCode.setNestedPositions(new int[][] { { 0, 2 } });
} else {
byteCode.setNestedPositions(new int[][] { { 0, 1 } });
- ((ConstantPoolEntry) byteCode.getNestedClassFileEntries()[0])
- .mustStartClassPool(true);
}
}
+
+ public boolean nestedMustStartClassPool() {
+ return !widened;
+ }
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java?rev=652453&r1=652452&r2=652453&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/unpack200/bytecode/forms/StringRefForm.java Thu May 1 01:19:41 2008
@@ -66,7 +66,6 @@
byteCode.setNestedPositions(new int[][] { { 0, 2 } });
} else {
byteCode.setNestedPositions(new int[][] { { 0, 1 } });
- ((CPString) nested[0]).mustStartClassPool(true);
}
}
}