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/04/11 12:10:00 UTC
svn commit: r647100 [2/9] - 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/BcBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java Fri Apr 11 03:09:38 2008
@@ -35,11 +35,12 @@
*/
public class BcBands extends BandSet {
- // The bytecodes for each method in each class as they come (i.e. in their packed format)
+ // The bytecodes for each method in each class as they come (i.e. in their
+ // packed format)
private byte[][][] methodByteCodePacked;
// The bands
- // TODO: Haven't resolved references yet. Do we want to?
+ // TODO: Haven't resolved references yet. Do we want to?
private int[] bcCaseCount;
private int[] bcCaseValue;
private int[] bcByte;
@@ -72,238 +73,250 @@
super(segment);
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
*/
- public void unpack(InputStream in) throws IOException,
- Pack200Exception {
+ public void unpack(InputStream in) throws IOException, Pack200Exception {
- AttributeLayoutMap attributeDefinitionMap = segment.getAttrDefinitionBands().getAttributeDefinitionMap();
- int classCount = header.getClassCount();
- long[][] methodFlags = segment.getClassBands().getMethodFlags();
- int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
- int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
- ArrayList[][] methodAttributes = segment.getClassBands().getMethodAttributes();
- String[][] methodDescr = segment.getClassBands().getMethodDescr();
-
- int bcCaseCountCount = 0;
- int bcByteCount = 0;
- int bcShortCount = 0;
- int bcLocalCount = 0;
- int bcLabelCount = 0;
- int bcIntRefCount = 0;
- int bcFloatRefCount = 0;
- int bcLongRefCount = 0;
- int bcDoubleRefCount = 0;
- int bcStringRefCount = 0;
- int bcClassRefCount = 0;
- int bcFieldRefCount = 0;
- int bcMethodRefCount = 0;
- int bcIMethodRefCount = 0;
- int bcThisFieldCount = 0;
- int bcSuperFieldCount = 0;
- int bcThisMethodCount = 0;
- int bcSuperMethodCount = 0;
- int bcInitRefCount = 0;
- int bcEscCount = 0;
- int bcEscRefCount = 0;
-
- AttributeLayout abstractModifier = attributeDefinitionMap
- .getAttributeLayout(AttributeLayout.ACC_ABSTRACT,
- AttributeLayout.CONTEXT_METHOD);
- AttributeLayout nativeModifier = attributeDefinitionMap
- .getAttributeLayout(AttributeLayout.ACC_NATIVE,
- AttributeLayout.CONTEXT_METHOD);
- AttributeLayout staticModifier = attributeDefinitionMap
- .getAttributeLayout(AttributeLayout.ACC_STATIC,
- AttributeLayout.CONTEXT_METHOD);
- methodByteCodePacked = new byte[classCount][][];
- int bcParsed = 0;
-
- List switchIsTableSwitch = new ArrayList();
- List wideByteCodes = new ArrayList();
- for (int c = 0; c < classCount; c++) {
- int numberOfMethods = methodFlags[c].length;
- methodByteCodePacked[c] = new byte[numberOfMethods][];
- for (int m = 0; m < numberOfMethods; m++) {
- long methodFlag = methodFlags[c][m];
- if (!abstractModifier.matches(methodFlag)
- && !nativeModifier.matches(methodFlag)) {
- ByteArrayOutputStream codeBytes = new ByteArrayOutputStream();
- byte code;
- while ((code = (byte) (0xff & in.read())) != -1)
- codeBytes.write(code);
- methodByteCodePacked[c][m] = codeBytes.toByteArray();
- bcParsed += methodByteCodePacked[c][m].length;
- int[] codes = new int[methodByteCodePacked[c][m].length];
- for (int i = 0; i < codes.length; i++) {
- codes[i] = methodByteCodePacked[c][m][i] & 0xff;
- }
- for (int i = 0; i < methodByteCodePacked[c][m].length; i++) {
- int codePacked = 0xff & methodByteCodePacked[c][m][i];
- switch (codePacked) {
- case 16: // bipush
- case 188: // newarray
- bcByteCount++;
- break;
- case 17: // sipush
- bcShortCount++;
- break;
- case 18: // (a)ldc
- case 19: // aldc_w
- bcStringRefCount++;
- break;
- case 234: // ildc
- case 237: // ildc_w
- bcIntRefCount++;
- break;
- case 235: // fldc
- case 238: // fldc_w
- bcFloatRefCount++;
- break;
- case 197: // multianewarray
- bcByteCount++;
- // fallthrough intended
- case 233: // cldc
- case 236: // cldc_w
- case 187: // new
- case 189: // anewarray
- case 192: // checkcast
- case 193: // instanceof
- bcClassRefCount++;
- break;
- case 20: // lldc2_w
- bcLongRefCount++;
- break;
- case 239: // dldc2_w
- bcDoubleRefCount++;
- break;
- case 169: // ret
- bcLocalCount++;
- break;
- case 167: // goto
- case 168: // jsr
- case 200: // goto_w
- case 201: // jsr_w
- bcLabelCount++;
- break;
- case 170: // tableswitch
- switchIsTableSwitch.add(new Boolean(true));
- bcCaseCountCount++;
- bcLabelCount++;
- break;
- case 171: // lookupswitch
- switchIsTableSwitch.add(new Boolean(false));
- bcCaseCountCount++;
- bcLabelCount++;
- break;
- case 178: // getstatic
- case 179: // putstatic
- case 180: // getfield
- case 181: // putfield
- bcFieldRefCount++;
- break;
- case 182: // invokevirtual
- case 183: // invokespecial
- case 184: // invokestatic
- bcMethodRefCount++;
- break;
- case 185: // invokeinterface
- bcIMethodRefCount++;
- break;
- case 202: // getstatic_this
- case 203: // putstatic_this
- case 204: // getfield_this
- case 205: // putfield_this
- case 209: // aload_0_getstatic_this
- case 210: // aload_0_putstatic_this
- case 211: // aload_0_putfield_this
- case 212: // aload_0_putfield_this
- bcThisFieldCount++;
- break;
- case 206: // invokevirtual_this
- case 207: // invokespecial_this
- case 208: // invokestatic_this
- case 213: // aload_0_invokevirtual_this
- case 214: // aload_0_invokespecial_this
- case 215: // aload_0_invokestatic_this
- bcThisMethodCount++;
- break;
- case 216: // getstatic_super
- case 217: // putstatic_super
- case 218: // getfield_super
- case 219: // putfield_super
- case 223: // aload_0_getstatic_super
- case 224: // aload_0_putstatic_super
- case 225: // aload_0_getfield_super
- case 226: // aload_0_putfield_super
- bcSuperFieldCount++;
- break;
- case 220: // invokevirtual_super
- case 221: // invokespecial_super
- case 222: // invokestatic_super
- case 227: // aload_0_invokevirtual_super
- case 228: // aload_0_invokespecial_super
- case 229: // aload_0_invokestatic_super
- bcSuperMethodCount++;
- break;
- case 132: // iinc
- bcLocalCount++;
- bcByteCount++;
- break;
- case 196: // wide
- int nextInstruction = 0xff & methodByteCodePacked[c][m][i+1];
+ AttributeLayoutMap attributeDefinitionMap = segment
+ .getAttrDefinitionBands().getAttributeDefinitionMap();
+ int classCount = header.getClassCount();
+ long[][] methodFlags = segment.getClassBands().getMethodFlags();
+ int[] codeMaxNALocals = segment.getClassBands().getCodeMaxNALocals();
+ int[] codeMaxStack = segment.getClassBands().getCodeMaxStack();
+ ArrayList[][] methodAttributes = segment.getClassBands()
+ .getMethodAttributes();
+ String[][] methodDescr = segment.getClassBands().getMethodDescr();
+
+ int bcCaseCountCount = 0;
+ int bcByteCount = 0;
+ int bcShortCount = 0;
+ int bcLocalCount = 0;
+ int bcLabelCount = 0;
+ int bcIntRefCount = 0;
+ int bcFloatRefCount = 0;
+ int bcLongRefCount = 0;
+ int bcDoubleRefCount = 0;
+ int bcStringRefCount = 0;
+ int bcClassRefCount = 0;
+ int bcFieldRefCount = 0;
+ int bcMethodRefCount = 0;
+ int bcIMethodRefCount = 0;
+ int bcThisFieldCount = 0;
+ int bcSuperFieldCount = 0;
+ int bcThisMethodCount = 0;
+ int bcSuperMethodCount = 0;
+ int bcInitRefCount = 0;
+ int bcEscCount = 0;
+ int bcEscRefCount = 0;
+
+ AttributeLayout abstractModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_ABSTRACT,
+ AttributeLayout.CONTEXT_METHOD);
+ AttributeLayout nativeModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_NATIVE,
+ AttributeLayout.CONTEXT_METHOD);
+ AttributeLayout staticModifier = attributeDefinitionMap
+ .getAttributeLayout(AttributeLayout.ACC_STATIC,
+ AttributeLayout.CONTEXT_METHOD);
+ methodByteCodePacked = new byte[classCount][][];
+ int bcParsed = 0;
+
+ List switchIsTableSwitch = new ArrayList();
+ List wideByteCodes = new ArrayList();
+ for (int c = 0; c < classCount; c++) {
+ int numberOfMethods = methodFlags[c].length;
+ methodByteCodePacked[c] = new byte[numberOfMethods][];
+ for (int m = 0; m < numberOfMethods; m++) {
+ long methodFlag = methodFlags[c][m];
+ if (!abstractModifier.matches(methodFlag)
+ && !nativeModifier.matches(methodFlag)) {
+ ByteArrayOutputStream codeBytes = new ByteArrayOutputStream();
+ byte code;
+ while ((code = (byte) (0xff & in.read())) != -1)
+ codeBytes.write(code);
+ methodByteCodePacked[c][m] = codeBytes.toByteArray();
+ bcParsed += methodByteCodePacked[c][m].length;
+ int[] codes = new int[methodByteCodePacked[c][m].length];
+ for (int i = 0; i < codes.length; i++) {
+ codes[i] = methodByteCodePacked[c][m][i] & 0xff;
+ }
+ for (int i = 0; i < methodByteCodePacked[c][m].length; i++) {
+ int codePacked = 0xff & methodByteCodePacked[c][m][i];
+ switch (codePacked) {
+ case 16: // bipush
+ case 188: // newarray
+ bcByteCount++;
+ break;
+ case 17: // sipush
+ bcShortCount++;
+ break;
+ case 18: // (a)ldc
+ case 19: // aldc_w
+ bcStringRefCount++;
+ break;
+ case 234: // ildc
+ case 237: // ildc_w
+ bcIntRefCount++;
+ break;
+ case 235: // fldc
+ case 238: // fldc_w
+ bcFloatRefCount++;
+ break;
+ case 197: // multianewarray
+ bcByteCount++;
+ // fallthrough intended
+ case 233: // cldc
+ case 236: // cldc_w
+ case 187: // new
+ case 189: // anewarray
+ case 192: // checkcast
+ case 193: // instanceof
+ bcClassRefCount++;
+ break;
+ case 20: // lldc2_w
+ bcLongRefCount++;
+ break;
+ case 239: // dldc2_w
+ bcDoubleRefCount++;
+ break;
+ case 169: // ret
+ bcLocalCount++;
+ break;
+ case 167: // goto
+ case 168: // jsr
+ case 200: // goto_w
+ case 201: // jsr_w
+ bcLabelCount++;
+ break;
+ case 170: // tableswitch
+ switchIsTableSwitch.add(new Boolean(true));
+ bcCaseCountCount++;
+ bcLabelCount++;
+ break;
+ case 171: // lookupswitch
+ switchIsTableSwitch.add(new Boolean(false));
+ bcCaseCountCount++;
+ bcLabelCount++;
+ break;
+ case 178: // getstatic
+ case 179: // putstatic
+ case 180: // getfield
+ case 181: // putfield
+ bcFieldRefCount++;
+ break;
+ case 182: // invokevirtual
+ case 183: // invokespecial
+ case 184: // invokestatic
+ bcMethodRefCount++;
+ break;
+ case 185: // invokeinterface
+ bcIMethodRefCount++;
+ break;
+ case 202: // getstatic_this
+ case 203: // putstatic_this
+ case 204: // getfield_this
+ case 205: // putfield_this
+ case 209: // aload_0_getstatic_this
+ case 210: // aload_0_putstatic_this
+ case 211: // aload_0_putfield_this
+ case 212: // aload_0_putfield_this
+ bcThisFieldCount++;
+ break;
+ case 206: // invokevirtual_this
+ case 207: // invokespecial_this
+ case 208: // invokestatic_this
+ case 213: // aload_0_invokevirtual_this
+ case 214: // aload_0_invokespecial_this
+ case 215: // aload_0_invokestatic_this
+ bcThisMethodCount++;
+ break;
+ case 216: // getstatic_super
+ case 217: // putstatic_super
+ case 218: // getfield_super
+ case 219: // putfield_super
+ case 223: // aload_0_getstatic_super
+ case 224: // aload_0_putstatic_super
+ case 225: // aload_0_getfield_super
+ case 226: // aload_0_putfield_super
+ bcSuperFieldCount++;
+ break;
+ case 220: // invokevirtual_super
+ case 221: // invokespecial_super
+ case 222: // invokestatic_super
+ case 227: // aload_0_invokevirtual_super
+ case 228: // aload_0_invokespecial_super
+ case 229: // aload_0_invokestatic_super
+ bcSuperMethodCount++;
+ break;
+ case 132: // iinc
+ bcLocalCount++;
+ bcByteCount++;
+ break;
+ case 196: // wide
+ int nextInstruction = 0xff & methodByteCodePacked[c][m][i + 1];
wideByteCodes.add(new Integer(nextInstruction));
if (nextInstruction == 132) { // iinc
- bcLocalCount ++;
+ bcLocalCount++;
bcShortCount++;
} else if (endsWithLoad(nextInstruction)
|| endsWithStore(nextInstruction)
|| nextInstruction == 169) {
- bcLocalCount ++;
+ bcLocalCount++;
} else {
- segment.log(Segment.LOG_LEVEL_VERBOSE, "Found unhandled " + ByteCode.getByteCode(nextInstruction));
+ segment
+ .log(
+ Segment.LOG_LEVEL_VERBOSE,
+ "Found unhandled "
+ + ByteCode
+ .getByteCode(nextInstruction));
}
i++;
break;
- case 230: // invokespecial_this_init
- case 231: // invokespecial_super_init
- case 232: // invokespecial_new_init
- bcInitRefCount++;
- break;
- case 253: // ref_escape
+ case 230: // invokespecial_this_init
+ case 231: // invokespecial_super_init
+ case 232: // invokespecial_new_init
+ bcInitRefCount++;
+ break;
+ case 253: // ref_escape
bcEscRefCount++;
- break;
- case 254: // byte_escape
- bcEscCount++;
- break;
- default:
- if(endsWithLoad(codePacked) || endsWithStore(codePacked)) {
- bcLocalCount++;
- } else if (startsWithIf(codePacked)) {
- bcLabelCount++;
- }
- }
- }
- }
+ break;
+ case 254: // byte_escape
+ bcEscCount++;
+ break;
+ default:
+ if (endsWithLoad(codePacked)
+ || endsWithStore(codePacked)) {
+ bcLocalCount++;
+ } else if (startsWithIf(codePacked)) {
+ bcLabelCount++;
+ }
+ }
+ }
+ }
}
}
// other bytecode bands
- bcCaseCount = decodeBandInt("bc_case_count", in, Codec.UNSIGNED5, bcCaseCountCount);
+ bcCaseCount = decodeBandInt("bc_case_count", in, Codec.UNSIGNED5,
+ bcCaseCountCount);
int bcCaseValueCount = 0;
for (int i = 0; i < bcCaseCount.length; i++) {
- boolean isTableSwitch = ((Boolean)switchIsTableSwitch.get(i)).booleanValue();
- if(isTableSwitch) {
+ boolean isTableSwitch = ((Boolean) switchIsTableSwitch.get(i))
+ .booleanValue();
+ if (isTableSwitch) {
bcCaseValueCount += 1;
} else {
bcCaseValueCount += bcCaseCount[i];
}
}
- bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5, bcCaseValueCount );
+ bcCaseValue = decodeBandInt("bc_case_value", in, Codec.DELTA5,
+ bcCaseValueCount);
// Every case value needs a label. We weren't able to count these
// above, because we didn't know how many cases there were.
// Have to correct it now.
- for(int index=0; index < bcCaseCountCount; index++) {
+ for (int index = 0; index < bcCaseCountCount; index++) {
bcLabelCount += bcCaseCount[index];
}
bcByte = decodeBandInt("bc_byte", in, Codec.BYTE1, bcByteCount);
@@ -339,30 +352,37 @@
bcInitRefCount);
bcEscRef = decodeBandInt("bc_escref", in, Codec.UNSIGNED5,
bcEscRefCount);
- bcEscRefSize = decodeBandInt("bc_escrefsize", in, Codec.UNSIGNED5, bcEscRefCount);
+ bcEscRefSize = decodeBandInt("bc_escrefsize", in, Codec.UNSIGNED5,
+ bcEscRefCount);
bcEscSize = decodeBandInt("bc_escsize", in, Codec.UNSIGNED5, bcEscCount);
bcEscByte = decodeBandInt("bc_escbyte", in, Codec.BYTE1, bcEscSize);
int[] wideByteCodeArray = new int[wideByteCodes.size()];
- for(int index=0; index < wideByteCodeArray.length; index++) {
- wideByteCodeArray[index] = ((Integer)wideByteCodes.get(index)).intValue();
+ for (int index = 0; index < wideByteCodeArray.length; index++) {
+ wideByteCodeArray[index] = ((Integer) wideByteCodes.get(index))
+ .intValue();
}
- OperandManager operandManager = new OperandManager(bcCaseCount, bcCaseValue,
- bcByte, bcShort, bcLocal, bcLabel, bcIntRef, bcFloatRef, bcLongRef,
- bcDoubleRef, bcStringRef, bcClassRef, bcFieldRef, bcMethodRef,
- bcIMethodRef, bcThisField, bcSuperField, bcThisMethod, bcSuperMethod,
- bcInitRef, wideByteCodeArray);
+ OperandManager operandManager = new OperandManager(bcCaseCount,
+ bcCaseValue, bcByte, bcShort, bcLocal, bcLabel, bcIntRef,
+ bcFloatRef, bcLongRef, bcDoubleRef, bcStringRef, bcClassRef,
+ bcFieldRef, bcMethodRef, bcIMethodRef, bcThisField,
+ bcSuperField, bcThisMethod, bcSuperMethod, bcInitRef,
+ wideByteCodeArray);
operandManager.setSegment(segment);
int i = 0;
- ArrayList orderedCodeAttributes = segment.getClassBands().getOrderedCodeAttributes();
+ ArrayList orderedCodeAttributes = segment.getClassBands()
+ .getOrderedCodeAttributes();
// Exception table fields
int[] handlerCount = segment.getClassBands().getCodeHandlerCount();
- int[][] handlerStartPCs = segment.getClassBands().getCodeHandlerStartP();
+ int[][] handlerStartPCs = segment.getClassBands()
+ .getCodeHandlerStartP();
int[][] handlerEndPCs = segment.getClassBands().getCodeHandlerEndPO();
- int[][] handlerCatchPCs = segment.getClassBands().getCodeHandlerCatchPO();
- String[][] handlerClassTypes = segment.getClassBands().getCodeHandlerClassRCN();
+ int[][] handlerCatchPCs = segment.getClassBands()
+ .getCodeHandlerCatchPO();
+ String[][] handlerClassTypes = segment.getClassBands()
+ .getCodeHandlerClassRCN();
for (int c = 0; c < classCount; c++) {
int numberOfMethods = methodFlags[c].length;
@@ -375,21 +395,23 @@
if (!staticModifier.matches(methodFlag))
maxLocal++; // one for 'this' parameter
// I believe this has to take wide arguments into account
- maxLocal += SegmentUtils.countInvokeInterfaceArgs(methodDescr[c][m]);
+ maxLocal += SegmentUtils
+ .countInvokeInterfaceArgs(methodDescr[c][m]);
operandManager.setCurrentClass(segment.getClassBands()
.getClassThis()[c]);
operandManager.setSuperClass(segment.getClassBands()
.getClassSuper()[c]);
List exceptionTable = new ArrayList();
- if(handlerCount != null) {
+ if (handlerCount != null) {
for (int j = 0; j < handlerCount[i]; j++) {
String handlerClass = handlerClassTypes[i][j];
CPClass cpHandlerClass = null;
- if(handlerClass != null) {
+ if (handlerClass != null) {
// The handlerClass will be null if the
// catch is a finally (that is, the
// exception table catch_type should be 0
- cpHandlerClass = segment.getCpBands().cpClassValue(handlerClass);
+ cpHandlerClass = segment.getCpBands()
+ .cpClassValue(handlerClass);
}
ExceptionTableEntry entry = new ExceptionTableEntry(
handlerStartPCs[i][j], handlerEndPCs[i][j],
@@ -402,25 +424,27 @@
operandManager, exceptionTable);
methodAttributes[c][m].add(codeAttr);
codeAttr.renumber(codeAttr.byteCodeOffsets);
- ArrayList currentAttributes = (ArrayList)orderedCodeAttributes.get(i);
- for(int index=0;index < currentAttributes.size(); index++) {
- Attribute currentAttribute = (Attribute)currentAttributes.get(index);
- codeAttr.addAttribute(currentAttribute);
- // Fix up the line numbers if needed
- if(currentAttribute.hasBCIRenumbering()) {
- ((BCIRenumberedAttribute)currentAttribute).renumber(codeAttr.byteCodeOffsets);
- }
- }
- i++;
- }
- }
- }
+ ArrayList currentAttributes = (ArrayList) orderedCodeAttributes
+ .get(i);
+ for (int index = 0; index < currentAttributes.size(); index++) {
+ Attribute currentAttribute = (Attribute) currentAttributes
+ .get(index);
+ codeAttr.addAttribute(currentAttribute);
+ // Fix up the line numbers if needed
+ if (currentAttribute.hasBCIRenumbering()) {
+ ((BCIRenumberedAttribute) currentAttribute)
+ .renumber(codeAttr.byteCodeOffsets);
+ }
+ }
+ i++;
+ }
+ }
+ }
}
private boolean startsWithIf(int codePacked) {
- return (codePacked >= 153 && codePacked <= 166)
- || (codePacked == 198)
- || (codePacked == 199);
+ return (codePacked >= 153 && codePacked <= 166) || (codePacked == 198)
+ || (codePacked == 199);
}
private boolean endsWithLoad(int codePacked) {
@@ -530,6 +554,5 @@
public int[][] getBcEscByte() {
return bcEscByte;
}
-
}
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java Fri Apr 11 03:09:38 2008
@@ -47,7 +47,8 @@
private long[] classFlags;
- private long[] classAccessFlags; // Access flags for writing to the class file
+ private long[] classAccessFlags; // Access flags for writing to the class
+ // file
private String[][] classInterfaces;
@@ -122,7 +123,7 @@
/*
* (non-Javadoc)
- *
+ *
* @see org.apache.harmony.pack200.BandSet#unpack(java.io.InputStream)
*/
public void unpack(InputStream in) throws IOException, Pack200Exception {
@@ -153,7 +154,8 @@
parseFieldAttrBands(in);
}
- private void parseFieldAttrBands(InputStream in) throws IOException, Pack200Exception {
+ private void parseFieldAttrBands(InputStream in) throws IOException,
+ Pack200Exception {
fieldFlags = parseFlags("field_flags", in, classFieldCount,
Codec.UNSIGNED5, options.hasFieldFlagsHi());
int fieldAttrCount = SegmentUtils.countBit16(fieldFlags);
@@ -201,23 +203,26 @@
int[] counts = new int[limit + 1];
List[] otherAttributes = new List[limit + 1];
for (int i = 0; i < limit; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_FIELD);
- if(layout != null && !(layout.isDefaultLayout())) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_FIELD);
+ if (layout != null && !(layout.isDefaultLayout())) {
otherLayouts[i] = layout;
- counts[i] = SegmentUtils.countMatches(fieldFlags,
- layout);
+ counts[i] = SegmentUtils.countMatches(fieldFlags, layout);
}
}
for (int i = 0; i < counts.length; i++) {
- if(counts[i] > 0) {
- NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);
+ if (counts[i] > 0) {
+ NewAttributeBands bands = attrMap
+ .getAttributeBands(otherLayouts[i]);
otherAttributes[i] = bands.parseAttributes(in, counts[i]);
- int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
- if(numBackwardsCallables > 0) {
+ int numBackwardsCallables = otherLayouts[i]
+ .numBackwardsCallables();
+ if (numBackwardsCallables > 0) {
int[] backwardsCalls = new int[numBackwardsCallables];
- System.arraycopy(fieldAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+ System.arraycopy(fieldAttrCalls, backwardsCallIndex,
+ backwardsCalls, 0, numBackwardsCallables);
bands.setBackwardsCalls(backwardsCalls);
- backwardsCallIndex+= numBackwardsCallables;
+ backwardsCallIndex += numBackwardsCallables;
}
}
}
@@ -229,7 +234,7 @@
for (int i = 0; i < classCount; i++) {
for (int j = 0; j < fieldFlags[i].length; j++) {
long flag = fieldFlags[i][j];
- if(deprecatedLayout.matches(flag)) {
+ if (deprecatedLayout.matches(flag)) {
fieldAttributes[i][j].add(new DeprecatedAttribute());
}
if (constantValueLayout.matches(flag)) {
@@ -253,15 +258,16 @@
String desc = fieldDescr[i][j];
int colon = desc.indexOf(':');
String type = desc.substring(colon + 1);
- CPUTF8 value = cpBands.cpUTF8Value((String) signatureLayout.getValue(result, type,
- cpBands.getConstantPool()), ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
- fieldAttributes[i][j]
- .add(new SignatureAttribute(value));
+ CPUTF8 value = cpBands.cpUTF8Value((String) signatureLayout
+ .getValue(result, type, cpBands.getConstantPool()),
+ ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
+ fieldAttributes[i][j].add(new SignatureAttribute(value));
signatureIndex++;
}
// Non-predefined attributes
for (int k = 0; k < otherLayouts.length; k++) {
- if(otherLayouts[k] != null && otherLayouts[k].matches(flag)) {
+ if (otherLayouts[k] != null
+ && otherLayouts[k].matches(flag)) {
// Add the next attribute
fieldAttributes[i][j].add(otherAttributes[k].get(0));
otherAttributes[k].remove(0);
@@ -274,7 +280,7 @@
private ClassFileEntry getClassFileEntry(Object value) {
ClassFileEntry entry = null;
if (value instanceof ClassFileEntry) {
- entry = (ClassFileEntry)value;
+ entry = (ClassFileEntry) value;
} else if (value instanceof java.lang.Integer) {
entry = cpBands.cpIntegerValue((Integer) value);
} else if (value instanceof java.lang.Long) {
@@ -296,7 +302,8 @@
parseMethodAttrBands(in);
}
- private void parseMethodAttrBands(InputStream in) throws IOException, Pack200Exception {
+ private void parseMethodAttrBands(InputStream in) throws IOException,
+ Pack200Exception {
methodFlags = parseFlags("method_flags", in, classMethodCount,
Codec.UNSIGNED5, options.hasMethodFlagsHi());
int methodAttrCount = SegmentUtils.countBit16(methodFlags);
@@ -319,9 +326,11 @@
}
// Parse method exceptions attributes
- AttributeLayout methodExceptionsLayout = attrMap.getAttributeLayout(AttributeLayout.ATTRIBUTE_EXCEPTIONS,
+ AttributeLayout methodExceptionsLayout = attrMap.getAttributeLayout(
+ AttributeLayout.ATTRIBUTE_EXCEPTIONS,
AttributeLayout.CONTEXT_METHOD);
- int count = SegmentUtils.countMatches(methodFlags, methodExceptionsLayout);
+ int count = SegmentUtils.countMatches(methodFlags,
+ methodExceptionsLayout);
int[] numExceptions = decodeBandInt("method_Exceptions_n", in,
Codec.UNSIGNED5, count);
String[][] methodExceptionsRS = parseReferences("method_Exceptions_RC",
@@ -331,7 +340,8 @@
AttributeLayout methodSignatureLayout = attrMap.getAttributeLayout(
AttributeLayout.ATTRIBUTE_SIGNATURE,
AttributeLayout.CONTEXT_METHOD);
- int count1 = SegmentUtils.countMatches(methodFlags, methodSignatureLayout);
+ int count1 = SegmentUtils.countMatches(methodFlags,
+ methodSignatureLayout);
long[] methodSignatureRS = decodeBandLong("method_signature_RS", in,
Codec.UNSIGNED5, count1);
@@ -345,23 +355,26 @@
int[] counts = new int[limit + 1];
List[] otherAttributes = new List[limit + 1];
for (int i = 0; i < limit; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_METHOD);
- if(layout != null && !(layout.isDefaultLayout())) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_METHOD);
+ if (layout != null && !(layout.isDefaultLayout())) {
otherLayouts[i] = layout;
- counts[i] = SegmentUtils.countMatches(methodFlags,
- layout);
+ counts[i] = SegmentUtils.countMatches(methodFlags, layout);
}
}
for (int i = 0; i < counts.length; i++) {
- if(counts[i] > 0) {
- NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);
+ if (counts[i] > 0) {
+ NewAttributeBands bands = attrMap
+ .getAttributeBands(otherLayouts[i]);
otherAttributes[i] = bands.parseAttributes(in, counts[i]);
- int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
- if(numBackwardsCallables > 0) {
+ int numBackwardsCallables = otherLayouts[i]
+ .numBackwardsCallables();
+ if (numBackwardsCallables > 0) {
int[] backwardsCalls = new int[numBackwardsCallables];
- System.arraycopy(methodAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+ System.arraycopy(methodAttrCalls, backwardsCallIndex,
+ backwardsCalls, 0, numBackwardsCallables);
bands.setBackwardsCalls(backwardsCalls);
- backwardsCallIndex+= numBackwardsCallables;
+ backwardsCallIndex += numBackwardsCallables;
}
}
}
@@ -376,7 +389,7 @@
for (int i = 0; i < methodAttributes.length; i++) {
for (int j = 0; j < methodAttributes[i].length; j++) {
long flag = methodFlags[i][j];
- if(deprecatedLayout.matches(flag)) {
+ if (deprecatedLayout.matches(flag)) {
methodAttributes[i][j].add(new DeprecatedAttribute());
}
if (methodExceptionsLayout.matches(flag)) {
@@ -384,7 +397,8 @@
String[] exceptions = methodExceptionsRS[methodExceptionsIndex];
CPClass[] exceptionClasses = new CPClass[n];
for (int k = 0; k < n; k++) {
- exceptionClasses[k] = cpBands.cpClassValue(exceptions[k]);
+ exceptionClasses[k] = cpBands
+ .cpClassValue(exceptions[k]);
}
methodAttributes[i][j].add(new ExceptionsAttribute(
exceptionClasses));
@@ -400,15 +414,16 @@
// be e.g. KIB or KIH
if (type.equals("B") || type.equals("H"))
type = "I";
- Object value = methodSignatureLayout.getValue(result, type, cpBands
- .getConstantPool());
+ Object value = methodSignatureLayout.getValue(result, type,
+ cpBands.getConstantPool());
methodAttributes[i][j].add(new ConstantValueAttribute(
getClassFileEntry(value)));
methodSignatureIndex++;
}
// Non-predefined attributes
for (int k = 0; k < otherLayouts.length; k++) {
- if(otherLayouts[k] != null && otherLayouts[k].matches(flag)) {
+ if (otherLayouts[k] != null
+ && otherLayouts[k].matches(flag)) {
// Add the next attribute
methodAttributes[i][j].add(otherAttributes[k].get(0));
otherAttributes[k].remove(0);
@@ -462,8 +477,8 @@
Codec.UNSIGNED5, classAttrCount);
int[][] classAttrIndexes = decodeBandInt("class_attr_indexes", in,
Codec.UNSIGNED5, classAttrCounts);
- int callCount = getCallCount(classAttrIndexes, new long[][] {classFlags},
- AttributeLayout.CONTEXT_CLASS);
+ int callCount = getCallCount(classAttrIndexes,
+ new long[][] { classFlags }, AttributeLayout.CONTEXT_CLASS);
int[] classAttrCalls = decodeBandInt("class_attr_calls", in,
Codec.UNSIGNED5, callCount);
@@ -488,7 +503,8 @@
"class_EnclosingMethod_RC", in, Codec.UNSIGNED5,
enclosingMethodCount, cpClass);
String[] enclosingMethodRDN = parseReferences(
- "class_EnclosingMethod_RDN", in, Codec.UNSIGNED5, enclosingMethodCount, cpBands.getCpDescriptor());
+ "class_EnclosingMethod_RDN", in, Codec.UNSIGNED5,
+ enclosingMethodCount, cpBands.getCpDescriptor());
AttributeLayout signatureLayout = attrMap.getAttributeLayout(
AttributeLayout.ATTRIBUTE_SIGNATURE,
@@ -539,7 +555,6 @@
int defaultVersionMajor = header.getDefaultClassMajorVersion();
int defaultVersionMinor = header.getDefaultClassMinorVersion();
-
// Parse non-predefined attribute bands
int backwardsCallIndex = backwardsCallsUsed;
int limit = options.hasClassFlagsHi() ? 62 : 31;
@@ -547,23 +562,26 @@
int[] counts = new int[limit + 1];
List[] otherAttributes = new List[limit + 1];
for (int i = 0; i < limit; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_CLASS);
- if(layout != null && !(layout.isDefaultLayout())) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_CLASS);
+ if (layout != null && !(layout.isDefaultLayout())) {
otherLayouts[i] = layout;
- counts[i] = SegmentUtils.countMatches(classFlags,
- layout);
+ counts[i] = SegmentUtils.countMatches(classFlags, layout);
}
}
for (int i = 0; i < counts.length; i++) {
- if(counts[i] > 0) {
- NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);
+ if (counts[i] > 0) {
+ NewAttributeBands bands = attrMap
+ .getAttributeBands(otherLayouts[i]);
otherAttributes[i] = bands.parseAttributes(in, counts[i]);
- int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
- if(numBackwardsCallables > 0) {
+ int numBackwardsCallables = otherLayouts[i]
+ .numBackwardsCallables();
+ if (numBackwardsCallables > 0) {
int[] backwardsCalls = new int[numBackwardsCallables];
- System.arraycopy(classAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+ System.arraycopy(classAttrCalls, backwardsCallIndex,
+ backwardsCalls, 0, numBackwardsCallables);
bands.setBackwardsCalls(backwardsCalls);
- backwardsCallIndex+= numBackwardsCallables;
+ backwardsCallIndex += numBackwardsCallables;
}
}
}
@@ -578,7 +596,7 @@
icLocal = new IcTuple[classCount][];
for (int i = 0; i < classCount; i++) {
long flag = classFlags[i];
- if(deprecatedLayout.matches(classFlags[i])) {
+ if (deprecatedLayout.matches(classFlags[i])) {
classAttributes[i].add(new DeprecatedAttribute());
}
if (sourceFileLayout.matches(flag)) {
@@ -607,13 +625,18 @@
// Add .java to the end
value = className + ".java";
}
- classAttributes[i].add(new SourceFileAttribute(cpBands.cpUTF8Value(value, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ)));
+ classAttributes[i].add(new SourceFileAttribute(cpBands
+ .cpUTF8Value(value,
+ ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ)));
sourceFileIndex++;
}
if (enclosingMethodLayout.matches(flag)) {
- CPClass theClass = cpBands.cpClassValue(enclosingMethodRC[enclosingMethodIndex]);
- CPNameAndType theMethod = cpBands.cpNameAndTypeValue(enclosingMethodRDN[enclosingMethodIndex]);
- classAttributes[i].add(new EnclosingMethodAttribute(theClass, theMethod));
+ CPClass theClass = cpBands
+ .cpClassValue(enclosingMethodRC[enclosingMethodIndex]);
+ CPNameAndType theMethod = cpBands
+ .cpNameAndTypeValue(enclosingMethodRDN[enclosingMethodIndex]);
+ classAttributes[i].add(new EnclosingMethodAttribute(theClass,
+ theMethod));
enclosingMethodIndex++;
}
if (signatureLayout.matches(flag)) {
@@ -653,7 +676,8 @@
}
}
- IcTuple icTuple = new IcTuple(icTupleC, icTupleF, icTupleC2, icTupleN);
+ IcTuple icTuple = new IcTuple(icTupleC, icTupleF,
+ icTupleC2, icTupleN);
icLocal[i][j] = icTuple;
}
innerClassIndex++;
@@ -669,7 +693,7 @@
}
// Non-predefined attributes
for (int j = 0; j < otherLayouts.length; j++) {
- if(otherLayouts[j] != null && otherLayouts[j].matches(flag)) {
+ if (otherLayouts[j] != null && otherLayouts[j].matches(flag)) {
// Add the next attribute
classAttributes[i].add(otherAttributes[j].get(0));
otherAttributes[j].remove(0);
@@ -728,13 +752,13 @@
}
}
codeHandlerStartP = decodeBandInt("code_handler_start_P", in,
- Codec.BCI5, codeHandlerCount);
+ Codec.BCI5, codeHandlerCount);
codeHandlerEndPO = decodeBandInt("code_handler_end_PO", in,
- Codec.BRANCH5, codeHandlerCount);
+ Codec.BRANCH5, codeHandlerCount);
codeHandlerCatchPO = decodeBandInt("code_handler_catch_PO", in,
- Codec.BRANCH5, codeHandlerCount);
- int[][] codeHandlerClassRCNints = decodeBandInt("code_handler_class_RCN", in,
- Codec.UNSIGNED5, codeHandlerCount);
+ Codec.BRANCH5, codeHandlerCount);
+ int[][] codeHandlerClassRCNints = decodeBandInt(
+ "code_handler_class_RCN", in, Codec.UNSIGNED5, codeHandlerCount);
// The codeHandlerClassRCN band contains incremented references to
// cp_Class so we can't use parseReferences(..) here.
String[] cpClass = cpBands.getCpClass();
@@ -743,7 +767,7 @@
codeHandlerClassRCN[i] = new String[codeHandlerClassRCNints[i].length];
for (int j = 0; j < codeHandlerClassRCNints[i].length; j++) {
int handlerClassReference = codeHandlerClassRCNints[i][j];
- if(handlerClassReference == 0) {
+ if (handlerClassReference == 0) {
codeHandlerClassRCN[i][j] = null;
} else {
codeHandlerClassRCN[i][j] = cpClass[handlerClassReference - 1];
@@ -828,11 +852,12 @@
// native signatures end up in DOMAINNORMALASCIIZ
// while nonnatives end up in DOMAINSIGNATUREASCIIZ.
// TODO: is this the right thing to do?
- for(int x=0; x < localVariableTableTypeRS.length; x++) {
- for(int y=0; y < localVariableTableTypeRS[x].length; y++) {
+ for (int x = 0; x < localVariableTableTypeRS.length; x++) {
+ for (int y = 0; y < localVariableTableTypeRS[x].length; y++) {
CPUTF8 element = localVariableTableTypeRS[x][y];
- // TODO: come up with a better test for native vs nonnative signatures?
- if(element.underlyingString().length() > 2) {
+ // TODO: come up with a better test for native vs nonnative
+ // signatures?
+ if (element.underlyingString().length() > 2) {
element.setDomain(ClassConstantPool.DOMAIN_SIGNATUREASCIIZ);
} else {
element.setDomain(ClassConstantPool.DOMAIN_NORMALASCIIZ);
@@ -868,23 +893,26 @@
int[] counts = new int[limit + 1];
List[] otherAttributes = new List[limit + 1];
for (int i = 0; i < limit; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_CODE);
- if(layout != null && !(layout.isDefaultLayout())) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_CODE);
+ if (layout != null && !(layout.isDefaultLayout())) {
otherLayouts[i] = layout;
- counts[i] = SegmentUtils.countMatches(codeFlags,
- layout);
+ counts[i] = SegmentUtils.countMatches(codeFlags, layout);
}
}
for (int i = 0; i < counts.length; i++) {
- if(counts[i] > 0) {
- NewAttributeBands bands = attrMap.getAttributeBands(otherLayouts[i]);
+ if (counts[i] > 0) {
+ NewAttributeBands bands = attrMap
+ .getAttributeBands(otherLayouts[i]);
otherAttributes[i] = bands.parseAttributes(in, counts[i]);
- int numBackwardsCallables = otherLayouts[i].numBackwardsCallables();
- if(numBackwardsCallables > 0) {
+ int numBackwardsCallables = otherLayouts[i]
+ .numBackwardsCallables();
+ if (numBackwardsCallables > 0) {
int[] backwardsCalls = new int[numBackwardsCallables];
- System.arraycopy(codeAttrCalls, backwardsCallIndex, backwardsCalls, 0, numBackwardsCallables);
+ System.arraycopy(codeAttrCalls, backwardsCallIndex,
+ backwardsCalls, 0, numBackwardsCallables);
bands.setBackwardsCalls(backwardsCalls);
- backwardsCallIndex+= numBackwardsCallables;
+ backwardsCallIndex += numBackwardsCallables;
}
}
}
@@ -925,7 +953,8 @@
}
// Non-predefined attributes
for (int j = 0; j < otherLayouts.length; j++) {
- if(otherLayouts[j] != null && otherLayouts[j].matches(codeFlags[i])) {
+ if (otherLayouts[j] != null
+ && otherLayouts[j].matches(codeFlags[i])) {
// Add the next attribute
codeAttributes[i].add(otherAttributes[j].get(0));
otherAttributes[j].remove(0);
@@ -940,18 +969,18 @@
for (int i = 0; i < strings.length; i++) {
cpUTF8s[i] = new CPUTF8[strings[i].length];
for (int j = 0; j < strings[i].length; j++) {
- cpUTF8s[i][j] = cpBands.cpUTF8Value(strings[i][j], ClassConstantPool.DOMAIN_NORMALASCIIZ);
+ cpUTF8s[i][j] = cpBands.cpUTF8Value(strings[i][j],
+ ClassConstantPool.DOMAIN_NORMALASCIIZ);
}
}
return cpUTF8s;
}
-
-
private CPUTF8[] stringsToCPUTF8(String[] strings) {
CPUTF8[] cpUTF8s = new CPUTF8[strings.length];
for (int i = 0; i < strings.length; i++) {
- cpUTF8s[i] = cpBands.cpUTF8Value(strings[i], ClassConstantPool.DOMAIN_NORMALASCIIZ);
+ cpUTF8s[i] = cpBands.cpUTF8Value(strings[i],
+ ClassConstantPool.DOMAIN_NORMALASCIIZ);
}
return cpUTF8s;
}
@@ -971,11 +1000,11 @@
int rvaCount = SegmentUtils.countMatches(fieldFlags, rvaLayout);
int riaCount = SegmentUtils.countMatches(fieldFlags, riaLayout);
int[] RxACount = new int[] { rvaCount, riaCount };
- int[] backwardsCalls = new int[] {0, 0};
- if(rvaCount > 0) {
+ int[] backwardsCalls = new int[] { 0, 0 };
+ if (rvaCount > 0) {
backwardsCalls[0] = fieldAttrCalls[0];
backwardsCallsUsed++;
- if(riaCount > 0) {
+ if (riaCount > 0) {
backwardsCalls[1] = fieldAttrCalls[1];
backwardsCallsUsed++;
}
@@ -983,15 +1012,16 @@
backwardsCalls[1] = fieldAttrCalls[0];
backwardsCallsUsed++;
}
- MetadataBandGroup[] mb = parseMetadata(in, RxA, RxACount, backwardsCalls, "field");
+ MetadataBandGroup[] mb = parseMetadata(in, RxA, RxACount,
+ backwardsCalls, "field");
Iterator rvaAttributesIterator = mb[0].getAttributes().iterator();
Iterator riaAttributesIterator = mb[1].getAttributes().iterator();
for (int i = 0; i < fieldFlags.length; i++) {
for (int j = 0; j < fieldFlags[i].length; j++) {
- if(rvaLayout.matches(fieldFlags[i][j])) {
+ if (rvaLayout.matches(fieldFlags[i][j])) {
fieldAttributes[i][j].add(rvaAttributesIterator.next());
}
- if(riaLayout.matches(fieldFlags[i][j])) {
+ if (riaLayout.matches(fieldFlags[i][j])) {
fieldAttributes[i][j].add(riaAttributesIterator.next());
}
}
@@ -999,8 +1029,9 @@
return backwardsCallsUsed;
}
- private MetadataBandGroup[] parseMetadata(InputStream in, String[] RxA, int[] RxACount,
- int[] backwardsCallCounts, String contextName) throws IOException, Pack200Exception {
+ private MetadataBandGroup[] parseMetadata(InputStream in, String[] RxA,
+ int[] RxACount, int[] backwardsCallCounts, String contextName)
+ throws IOException, Pack200Exception {
MetadataBandGroup[] mbg = new MetadataBandGroup[RxA.length];
for (int i = 0; i < RxA.length; i++) {
mbg[i] = new MetadataBandGroup(RxA[i], cpBands);
@@ -1013,8 +1044,9 @@
if (!rxa.equals("AD")) {
mbg[i].anno_N = decodeBandInt(contextName + "_" + rxa
+ "_anno_N", in, Codec.UNSIGNED5, RxACount[i]);
- mbg[i].type_RS = stringsToCPUTF8(parseReferences(contextName + "_" + rxa
- + "_type_RS", in, Codec.UNSIGNED5, mbg[i].anno_N, cpBands.getCpSignature()));
+ mbg[i].type_RS = stringsToCPUTF8(parseReferences(contextName
+ + "_" + rxa + "_type_RS", in, Codec.UNSIGNED5,
+ mbg[i].anno_N, cpBands.getCpSignature()));
mbg[i].pair_N = decodeBandInt(contextName + "_" + rxa
+ "_pair_N", in, Codec.UNSIGNED5, mbg[i].anno_N);
for (int j = 0; j < mbg[i].pair_N.length; j++) {
@@ -1023,8 +1055,9 @@
}
}
- mbg[i].name_RU = stringsToCPUTF8(parseReferences(contextName + "_" + rxa
- + "_name_RU", in, Codec.UNSIGNED5, pairCount, cpBands.getCpUTF8()));
+ mbg[i].name_RU = stringsToCPUTF8(parseReferences(contextName
+ + "_" + rxa + "_name_RU", in, Codec.UNSIGNED5,
+ pairCount, cpBands.getCpUTF8()));
}
mbg[i].T = decodeBandInt(contextName + "_" + rxa + "_T", in,
Codec.BYTE1, pairCount + backwardsCallCounts[i]);
@@ -1076,9 +1109,11 @@
mbg[i].casec_RS = parseCPUTF8References(contextName + "_" + rxa
+ "_casec_RS", in, Codec.UNSIGNED5, cCount);
mbg[i].caseet_RS = parseReferences(contextName + "_" + rxa
- + "_caseet_RS", in, Codec.UNSIGNED5, eCount, cpBands.getCpSignature());
+ + "_caseet_RS", in, Codec.UNSIGNED5, eCount, cpBands
+ .getCpSignature());
mbg[i].caseec_RU = parseReferences(contextName + "_" + rxa
- + "_caseec_RU", in, Codec.UNSIGNED5, eCount, cpBands.getCpUTF8());
+ + "_caseec_RU", in, Codec.UNSIGNED5, eCount, cpBands
+ .getCpUTF8());
mbg[i].cases_RU = parseCPUTF8References(contextName + "_" + rxa
+ "_cases_RU", in, Codec.UNSIGNED5, sCount);
mbg[i].casearray_N = decodeBandInt(contextName + "_" + rxa
@@ -1105,7 +1140,7 @@
int[] backwardsCalls = new int[5];
int methodAttrIndex = 0;
for (int i = 0; i < backwardsCalls.length; i++) {
- if(rxaCounts[i] > 0) {
+ if (rxaCounts[i] > 0) {
backwardsCallsUsed++;
backwardsCalls[i] = methodAttrCalls[methodAttrIndex];
methodAttrIndex++;
@@ -1137,7 +1172,8 @@
rxaCounts[i] = SegmentUtils
.countMatches(methodFlags, rxaLayouts[i]);
}
- MetadataBandGroup[] mbgs = parseMetadata(in, RxA, rxaCounts, backwardsCalls, "method");
+ MetadataBandGroup[] mbgs = parseMetadata(in, RxA, rxaCounts,
+ backwardsCalls, "method");
Iterator[] attributeIterators = new Iterator[RxA.length];
for (int i = 0; i < mbgs.length; i++) {
attributeIterators[i] = mbgs[i].getAttributes().iterator();
@@ -1145,8 +1181,9 @@
for (int i = 0; i < methodFlags.length; i++) {
for (int j = 0; j < methodFlags[i].length; j++) {
for (int k = 0; k < rxaLayouts.length; k++) {
- if(rxaLayouts[k].matches(methodFlags[i][j])) {
- methodAttributes[i][j].add(attributeIterators[k].next());
+ if (rxaLayouts[k].matches(methodFlags[i][j])) {
+ methodAttributes[i][j]
+ .add(attributeIterators[k].next());
}
}
}
@@ -1155,14 +1192,17 @@
}
/**
- * Parse the class metadata bands and return the number of backwards callables
+ * Parse the class metadata bands and return the number of backwards
+ * callables
+ *
* @param in
* @param classAttrCalls
* @return
* @throws Pack200Exception
* @throws IOException
*/
- private int parseClassMetadataBands(InputStream in, int[] classAttrCalls) throws Pack200Exception, IOException {
+ private int parseClassMetadataBands(InputStream in, int[] classAttrCalls)
+ throws Pack200Exception, IOException {
int numBackwardsCalls = 0;
String[] RxA = new String[] { "RVA", "RIA" };
@@ -1175,11 +1215,11 @@
int rvaCount = SegmentUtils.countMatches(classFlags, rvaLayout);
int riaCount = SegmentUtils.countMatches(classFlags, riaLayout);
int[] RxACount = new int[] { rvaCount, riaCount };
- int[] backwardsCalls = new int[] {0, 0};
- if(rvaCount > 0) {
+ int[] backwardsCalls = new int[] { 0, 0 };
+ if (rvaCount > 0) {
numBackwardsCalls++;
backwardsCalls[0] = classAttrCalls[0];
- if(riaCount > 0) {
+ if (riaCount > 0) {
numBackwardsCalls++;
backwardsCalls[1] = classAttrCalls[1];
}
@@ -1187,14 +1227,15 @@
numBackwardsCalls++;
backwardsCalls[1] = classAttrCalls[0];
}
- MetadataBandGroup[] mbgs = parseMetadata(in, RxA, RxACount, backwardsCalls, "class");
+ MetadataBandGroup[] mbgs = parseMetadata(in, RxA, RxACount,
+ backwardsCalls, "class");
Iterator rvaAttributesIterator = mbgs[0].getAttributes().iterator();
Iterator riaAttributesIterator = mbgs[1].getAttributes().iterator();
for (int i = 0; i < classFlags.length; i++) {
- if(rvaLayout.matches(classFlags[i])) {
+ if (rvaLayout.matches(classFlags[i])) {
classAttributes[i].add(rvaAttributesIterator.next());
}
- if(riaLayout.matches(classFlags[i])) {
+ if (riaLayout.matches(classFlags[i])) {
classAttributes[i].add(riaAttributesIterator.next());
}
}
@@ -1214,19 +1255,20 @@
}
public long[] getClassFlags() throws Pack200Exception {
- if(classAccessFlags == null) {
- long mask = 0x7FFF;
- for (int i = 0; i < 16; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_CLASS);
- if(layout != null && !layout.isDefaultLayout()) {
- mask &= ~(1 << i);
- }
- }
- classAccessFlags = new long[classFlags.length];
- for (int i = 0; i < classFlags.length; i++) {
- classAccessFlags[i] = classFlags[i] & mask;
- }
- }
+ if (classAccessFlags == null) {
+ long mask = 0x7FFF;
+ for (int i = 0; i < 16; i++) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_CLASS);
+ if (layout != null && !layout.isDefaultLayout()) {
+ mask &= ~(1 << i);
+ }
+ }
+ classAccessFlags = new long[classFlags.length];
+ for (int i = 0; i < classFlags.length; i++) {
+ classAccessFlags[i] = classFlags[i] & mask;
+ }
+ }
return classAccessFlags;
}
@@ -1263,39 +1305,43 @@
}
public long[][] getFieldFlags() throws Pack200Exception {
- if(fieldAccessFlags == null) {
- long mask = 0x7FFF;
- for (int i = 0; i < 16; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_FIELD);
- if(layout != null && !layout.isDefaultLayout()) {
- mask &= ~(1 << i);
- }
- }
- fieldAccessFlags = new long[fieldFlags.length][];
- for (int i = 0; i < fieldFlags.length; i++) {
- fieldAccessFlags[i] = new long[fieldFlags[i].length];
- for (int j = 0; j < fieldFlags[i].length; j++) {
- fieldAccessFlags[i][j] = fieldFlags[i][j] & mask;
- }
- }
- }
+ if (fieldAccessFlags == null) {
+ long mask = 0x7FFF;
+ for (int i = 0; i < 16; i++) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_FIELD);
+ if (layout != null && !layout.isDefaultLayout()) {
+ mask &= ~(1 << i);
+ }
+ }
+ fieldAccessFlags = new long[fieldFlags.length][];
+ for (int i = 0; i < fieldFlags.length; i++) {
+ fieldAccessFlags[i] = new long[fieldFlags[i].length];
+ for (int j = 0; j < fieldFlags[i].length; j++) {
+ fieldAccessFlags[i][j] = fieldFlags[i][j] & mask;
+ }
+ }
+ }
return fieldAccessFlags;
}
/**
* Answer an ArrayList of ArrayLists which hold the the code attributes
* corresponding to all classes in order.
- *
+ *
* If a class doesn't have any attributes, the corresponding element in this
* list will be an empty ArrayList.
+ *
* @return ArrayList
*/
public ArrayList getOrderedCodeAttributes() {
ArrayList orderedAttributeList = new ArrayList();
- for(int classIndex=0; classIndex < codeAttributes.length; classIndex++) {
+ for (int classIndex = 0; classIndex < codeAttributes.length; classIndex++) {
ArrayList currentAttributes = new ArrayList();
- for(int attributeIndex = 0; attributeIndex < codeAttributes[classIndex].size(); attributeIndex++) {
- Attribute attribute = (Attribute)codeAttributes[classIndex].get(attributeIndex);
+ for (int attributeIndex = 0; attributeIndex < codeAttributes[classIndex]
+ .size(); attributeIndex++) {
+ Attribute attribute = (Attribute) codeAttributes[classIndex]
+ .get(attributeIndex);
currentAttributes.add(attribute);
}
orderedAttributeList.add(currentAttributes);
@@ -1312,22 +1358,23 @@
}
public long[][] getMethodFlags() throws Pack200Exception {
- if(methodAccessFlags == null) {
- long mask = 0x7FFF;
- for (int i = 0; i < 16; i++) {
- AttributeLayout layout = attrMap.getAttributeLayout(i, AttributeLayout.CONTEXT_METHOD);
- if(layout != null && !layout.isDefaultLayout()) {
- mask &= ~(1 << i);
- }
- }
- methodAccessFlags = new long[methodFlags.length][];
- for (int i = 0; i < methodFlags.length; i++) {
- methodAccessFlags[i] = new long[methodFlags[i].length];
- for (int j = 0; j < methodFlags[i].length; j++) {
- methodAccessFlags[i][j] = methodFlags[i][j] & mask;
- }
- }
- }
+ if (methodAccessFlags == null) {
+ long mask = 0x7FFF;
+ for (int i = 0; i < 16; i++) {
+ AttributeLayout layout = attrMap.getAttributeLayout(i,
+ AttributeLayout.CONTEXT_METHOD);
+ if (layout != null && !layout.isDefaultLayout()) {
+ mask &= ~(1 << i);
+ }
+ }
+ methodAccessFlags = new long[methodFlags.length][];
+ for (int i = 0; i < methodFlags.length; i++) {
+ methodAccessFlags[i] = new long[methodFlags[i].length];
+ for (int j = 0; j < methodFlags[i].length; j++) {
+ methodAccessFlags[i][j] = methodFlags[i][j] & mask;
+ }
+ }
+ }
return methodAccessFlags;
}
@@ -1335,7 +1382,7 @@
* Returns null if all classes should use the default major and minor
* version or an array of integers containing the major version numberss to
* use for each class in the segment
- *
+ *
* @return Class file major version numbers, or null if none specified
*/
public int[] getClassVersionMajor() {
@@ -1346,7 +1393,7 @@
* Returns null if all classes should use the default major and minor
* version or an array of integers containing the minor version numberss to
* use for each class in the segment
- *
+ *
* @return Class file minor version numbers, or null if none specified
*/
public int[] getClassVersionMinor() {
Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java?rev=647100&r1=647099&r2=647100&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java (original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/Codec.java Fri Apr 11 03:09:38 2008
@@ -22,7 +22,7 @@
/**
* A Codec allows a sequence of bytes to be decoded into integer values (or vice
* versa).
- *
+ *
* There are a number of standard Codecs ({@link #UDELTA5}, {@link #UNSIGNED5},
* {@link #BYTE1}, {@link #CHAR3}) that are used in the implementation of many
* bands; but there are a variety of other ones, and indeed the specification
@@ -32,6 +32,7 @@
* canonical number. {@link CodecEncoding#getCodec(int, InputStream, Codec)})
*/
public abstract class Codec {
+
/**
* BCI5 = (5,4): Used for storing branching information in bytecode.
*/
@@ -87,7 +88,7 @@
* Decode a sequence of bytes from the given input stream, returning the
* value as a long. Note that this method can only be applied for non-delta
* encodings.
- *
+ *
* @param in
* the input stream to read from
* @return the value as a long
@@ -106,15 +107,15 @@
* previous value must be passed in as a parameter. If it is a non-delta
* encoding, then it does not matter what value is passed in, so it makes
* sense for the value to be passed in by default using code similar to:
- *
+ *
* <pre>
* long last = 0;
* while (condition) {
- * last = codec.decode(in, last);
- * // do something with last
+ * last = codec.decode(in, last);
+ * // do something with last
* }
* </pre>
- *
+ *
* @param in
* the input stream to read from
* @param last
@@ -133,10 +134,11 @@
/**
* Decodes a sequence of <code>n</code> values from <code>in</code>.
- * This should probably be used in most cases, since some codecs
- * (such as @{link PopCodec}) only work when the number of values
- * to be read is known.
- *
+ * This should probably be used in most cases, since some codecs (such as
+ *
+ * @{link PopCodec}) only work when the number of values to be read is
+ * known.
+ *
* @param n
* the number of values to decode
* @param in
@@ -154,18 +156,19 @@
Pack200Exception {
long result[] = new long[n];
long last = 0;
- for(int i=0;i<n;i++) {
- result[i] = last = decode(in,last);
+ for (int i = 0; i < n; i++) {
+ result[i] = last = decode(in, last);
}
return result;
}
/**
* Decodes a sequence of <code>n</code> values from <code>in</code>.
- * This should probably be used in most cases, since some codecs
- * (such as @{link PopCodec}) only work when the number of values
- * to be read is known.
- *
+ * This should probably be used in most cases, since some codecs (such as
+ *
+ * @{link PopCodec}) only work when the number of values to be read is
+ * known.
+ *
* @param n
* the number of values to decode
* @param in
@@ -183,15 +186,15 @@
Pack200Exception {
int result[] = new int[n];
int last = 0;
- for(int i=0;i<n;i++) {
- result[i] = last = (int) decode(in,last);
+ for (int i = 0; i < n; i++) {
+ result[i] = last = (int) decode(in, last);
}
return result;
}
/**
* Decodes a sequence of <code>n</code> values from <code>in</code>.
- *
+ *
* @param n
* the number of values to decode
* @param in
@@ -207,20 +210,20 @@
* if there is a problem decoding the value or that the value is
* invalid
*/
- public long[] decode(int n, InputStream in, long firstValue) throws IOException,
- Pack200Exception {
+ public long[] decode(int n, InputStream in, long firstValue)
+ throws IOException, Pack200Exception {
long result[] = new long[n + 1];
result[0] = firstValue;
long last = firstValue;
- for(int i=1;i<n+1;i++) {
- result[i] = last = decode(in,last);
+ for (int i = 1; i < n + 1; i++) {
+ result[i] = last = decode(in, last);
}
return result;
}
/**
* Decodes a sequence of <code>n</code> values from <code>in</code>.
- *
+ *
* @param n
* the number of values to decode
* @param in
@@ -236,13 +239,13 @@
* if there is a problem decoding the value or that the value is
* invalid
*/
- public int[] decodeInts(int n, InputStream in, int firstValue) throws IOException,
- Pack200Exception {
+ public int[] decodeInts(int n, InputStream in, int firstValue)
+ throws IOException, Pack200Exception {
int result[] = new int[n + 1];
result[0] = firstValue;
int last = firstValue;
- for(int i=1;i<n+1;i++) {
- result[i] = last = (int) decode(in,last);
+ for (int i = 1; i < n + 1; i++) {
+ result[i] = last = (int) decode(in, last);
}
return result;
}