harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r745887 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200: BcBands.java ClassBands.java IntList.java
Date Thu, 19 Feb 2009 14:45:54 GMT
Author: sjanuary
Date: Thu Feb 19 14:45:53 2009
New Revision: 745887

URL: http://svn.apache.org/viewvc?rev=745887&view=rev
Log:
Pack200 - performance improvement: use customised list instead of ArrayList for ints to reduce
Integer-int conversions and reduce memory usage.

Added:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/BcBands.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/ClassBands.java

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=745887&r1=745886&r2=745887&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
Thu Feb 19 14:45:53 2009
@@ -30,8 +30,6 @@
  */
 public class BcBands extends BandSet {
 
-    private static final Integer MULTIANEWARRAY = new Integer(197);
-    private static final Integer ALOAD_0 = new Integer(42);
     private final CpBands cpBands;
     private final Segment segment;
 
@@ -40,12 +38,12 @@
         this.segment = segment;
     }
 
-    private final List bcCodes = new ArrayList();
-    private final List bcCaseCount = new ArrayList();
-    private final List bcCaseValue = new ArrayList();
-    private final List bcByte = new ArrayList();
-    private final List bcShort = new ArrayList();
-    private final List bcLocal = new ArrayList();
+    private final IntList bcCodes = new IntList();
+    private final IntList bcCaseCount = new IntList();
+    private final IntList bcCaseValue = new IntList();
+    private final IntList bcByte = new IntList();
+    private final IntList bcShort = new IntList();
+    private final IntList bcLocal = new IntList();
     private final List bcLabel = new ArrayList();
     private final List bcIntref = new ArrayList();
     private final List bcFloatRef = new ArrayList();
@@ -64,18 +62,21 @@
 
     private String currentClass;
     private String superClass;
-    private static final Integer WIDE = new Integer(196);
-    private static final Integer INVOKEINTERFACE = new Integer(185);
-    private static final Integer TABLESWITCH = new Integer(170);
-    private static final Integer IINC = new Integer(132);
-    private static final Integer LOOKUPSWITCH = new Integer(171);
-    private static final Integer endMarker = new Integer(255);
 
-    private final List bciRenumbering = new ArrayList();
+    private static final int MULTIANEWARRAY = 197;
+    private static final int ALOAD_0 = 42;
+    private static final int WIDE = 196;
+    private static final int INVOKEINTERFACE = 185;
+    private static final int TABLESWITCH = 170;
+    private static final int IINC = 132;
+    private static final int LOOKUPSWITCH = 171;
+    private static final int endMarker = 255;
+
+    private final IntList bciRenumbering = new IntList();
     private final Map labelsToOffsets = new HashMap();
     private int byteCodeOffset;
     private int renumberedOffset;
-    private final List bcLabelRelativeOffsets = new ArrayList();
+    private final IntList bcLabelRelativeOffsets = new IntList();
 
     public void setCurrentClass(String name) {
         currentClass = name;
@@ -91,14 +92,14 @@
     }
 
     public void pack(OutputStream out) throws IOException, Pack200Exception {
-        out.write(encodeBandInt("bcCodes", listToArray(bcCodes), Codec.BYTE1));
-        out.write(encodeBandInt("bcCaseCount", listToArray(bcCaseCount),
+        out.write(encodeBandInt("bcCodes", bcCodes.toArray(), Codec.BYTE1));
+        out.write(encodeBandInt("bcCaseCount", bcCaseCount.toArray(),
                 Codec.UNSIGNED5));
-        out.write(encodeBandInt("bcCaseValue", listToArray(bcCaseValue),
+        out.write(encodeBandInt("bcCaseValue", bcCaseValue.toArray(),
                 Codec.DELTA5));
-        out.write(encodeBandInt("bcByte", listToArray(bcByte), Codec.BYTE1));
-        out.write(encodeBandInt("bcShort", listToArray(bcShort), Codec.DELTA5));
-        out.write(encodeBandInt("bcLocal", listToArray(bcLocal),
+        out.write(encodeBandInt("bcByte", bcByte.toArray(), Codec.BYTE1));
+        out.write(encodeBandInt("bcShort", bcShort.toArray(), Codec.DELTA5));
+        out.write(encodeBandInt("bcLocal", bcLocal.toArray(),
                 Codec.UNSIGNED5));
         out
                 .write(encodeBandInt("bcLabel", listToArray(bcLabel),
@@ -149,9 +150,9 @@
 
     public void visitEnd() {
         for (int i = 0; i < bciRenumbering.size(); i++) {
-            if (bciRenumbering.get(i) == null) {
+            if (bciRenumbering.get(i) == -1) {
                 bciRenumbering.remove(i);
-                bciRenumbering.add(i, new Integer(++renumberedOffset));
+                bciRenumbering.add(i, ++renumberedOffset);
             }
         }
         if (renumberedOffset != 0) {
@@ -165,8 +166,8 @@
                 } else if (label instanceof Label) {
                     bcLabel.remove(i);
                     Integer offset = (Integer) labelsToOffsets.get(label);
-                    Integer relativeOffset = (Integer) bcLabelRelativeOffsets.get(i);
-                    bcLabel.add(i, new Integer(((Integer)bciRenumbering.get(offset.intValue())).intValue()
- ((Integer)bciRenumbering.get(relativeOffset.intValue())).intValue()));
+                    int relativeOffset = bcLabelRelativeOffsets.get(i);
+                    bcLabel.add(i, new Integer(bciRenumbering.get(offset.intValue()) - bciRenumbering.get(relativeOffset)));
                 }
             }
             bcCodes.add(endMarker);
@@ -189,7 +190,7 @@
         updateRenumbering();
         boolean aload_0 = false;
         if (bcCodes.size() > 0
-                && ((Integer) bcCodes.get(bcCodes.size() - 1)).equals(ALOAD_0)) {
+                && (bcCodes.get(bcCodes.size() - 1)) == ALOAD_0) {
             bcCodes.remove(bcCodes.size() - 1);
             aload_0 = true;
         }
@@ -213,18 +214,18 @@
             bcFieldRef.add(cpField);
         }
         aload_0 = false;
-        bcCodes.add(new Integer(opcode));
+        bcCodes.add(opcode);
     }
 
     private void updateRenumbering() {
         if(bciRenumbering.isEmpty()) {
-            bciRenumbering.add(new Integer(0));
+            bciRenumbering.add(0);
         }
         renumberedOffset ++;
         for (int i = bciRenumbering.size(); i < byteCodeOffset; i++) {
-            bciRenumbering.add(null);
+            bciRenumbering.add(-1);
         }
-        bciRenumbering.add(new Integer(renumberedOffset));
+        bciRenumbering.add(renumberedOffset);
     }
 
     public void visitIincInsn(int var, int increment) {
@@ -232,13 +233,13 @@
             byteCodeOffset += 6;
             bcCodes.add(WIDE);
             bcCodes.add(IINC);
-            bcLocal.add(new Integer(var));
-            bcShort.add(new Integer(increment));
+            bcLocal.add(var);
+            bcShort.add(increment);
         } else {
             byteCodeOffset += 3;
             bcCodes.add(IINC);
-            bcLocal.add(new Integer(var));
-            bcByte.add(new Integer(increment & 0xFF));
+            bcLocal.add(var);
+            bcByte.add(increment & 0xFF);
         }
         updateRenumbering();
     }
@@ -248,7 +249,7 @@
             throw new RuntimeException(
                     "Non-standard bytecode instructions not supported");
         } else {
-            bcCodes.add(new Integer(opcode));
+            bcCodes.add(opcode);
             byteCodeOffset++;
             updateRenumbering();
         }
@@ -257,23 +258,23 @@
     public void visitIntInsn(int opcode, int operand) {
         switch (opcode) {
         case 17: // sipush
-            bcCodes.add(new Integer(opcode));
-            bcShort.add(new Integer(operand));
+            bcCodes.add(opcode);
+            bcShort.add(operand);
             byteCodeOffset += 3;
             break;
         case 16: // bipush
         case 188: // newarray
-            bcCodes.add(new Integer(opcode));
-            bcByte.add(new Integer(operand & 0xFF));
+            bcCodes.add(opcode);
+            bcByte.add(operand & 0xFF);
             byteCodeOffset += 2;
         }
         updateRenumbering();
     }
 
     public void visitJumpInsn(int opcode, Label label) {
-        bcCodes.add(new Integer(opcode));
+        bcCodes.add(opcode);
         bcLabel.add(label);
-        bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
+        bcLabelRelativeOffsets.add(byteCodeOffset);
         byteCodeOffset += 3;
         updateRenumbering();
     }
@@ -284,22 +285,22 @@
                 || constant instanceof CPDouble) {
             byteCodeOffset += 3;
             if (constant instanceof CPInt) {
-                bcCodes.add(new Integer(237)); // ildc_w
+                bcCodes.add(237); // ildc_w
                 bcIntref.add(constant);
             } else if (constant instanceof CPFloat) {
-                bcCodes.add(new Integer(238)); // fldc
+                bcCodes.add(238); // fldc
                 bcFloatRef.add(constant);
             } else if (constant instanceof CPLong) {
-                bcCodes.add(new Integer(20)); // lldc2_w
+                bcCodes.add(20); // lldc2_w
                 bcLongRef.add(constant);
             } else if (constant instanceof CPDouble) {
-                bcCodes.add(new Integer(239)); // dldc2_w
+                bcCodes.add(239); // dldc2_w
                 bcDoubleRef.add(constant);
             } else if (constant instanceof CPString) {
-                bcCodes.add(new Integer(19)); // aldc
+                bcCodes.add(19); // aldc
                 bcStringRef.add(constant);
             } else if (constant instanceof CPClass) {
-                bcCodes.add(new Integer(236)); // cldc
+                bcCodes.add(236); // cldc
                 bcClassRef.add(constant);
             } else {
                 throw new RuntimeException("Constant should not be null");
@@ -307,16 +308,16 @@
         } else {
             byteCodeOffset += 2;
             if (constant instanceof CPInt) {
-                bcCodes.add(new Integer(234)); // ildc
+                bcCodes.add(234); // ildc
                 bcIntref.add(constant);
             } else if (constant instanceof CPFloat) {
-                bcCodes.add(new Integer(235)); // fldc
+                bcCodes.add(235); // fldc
                 bcFloatRef.add(constant);
             } else if (constant instanceof CPString) {
-                bcCodes.add(new Integer(18)); // aldc
+                bcCodes.add(18); // aldc
                 bcStringRef.add(constant);
             } else if (constant instanceof CPClass) {
-                bcCodes.add(new Integer(233)); // cldc
+                bcCodes.add(233); // cldc
                 bcClassRef.add(constant);
             }
         }
@@ -326,12 +327,12 @@
     public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
         bcCodes.add(LOOKUPSWITCH);
         bcLabel.add(dflt);
-        bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
-        bcCaseCount.add(new Integer(keys.length));
+        bcLabelRelativeOffsets.add(byteCodeOffset);
+        bcCaseCount.add(keys.length);
         for (int i = 0; i < labels.length; i++) {
-            bcCaseValue.add(new Integer(keys[i]));
+            bcCaseValue.add(keys[i]);
             bcLabel.add(labels[i]);
-            bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
+            bcLabelRelativeOffsets.add(byteCodeOffset);
         }
         int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
         byteCodeOffset += padding + 8 + 8 * keys.length;
@@ -348,8 +349,8 @@
         case 184: // invokestatic
             boolean aload_0 = false;
             if (bcCodes.size() > 0
-                    && ((Integer) bcCodes.get(bcCodes.size() - 1))
-                            .equals(ALOAD_0)) {
+                    && (bcCodes.get(bcCodes.size() - 1))
+                             == (ALOAD_0)) {
                 bcCodes.remove(bcCodes.size() - 1);
                 aload_0 = true;
                 opcode += 7;
@@ -381,7 +382,7 @@
                 }
                 bcMethodRef.add(cpBands.getCPMethod(owner, name, desc));
             }
-            bcCodes.add(new Integer(opcode));
+            bcCodes.add(opcode);
             break;
         case 185: // invokeinterface
             CPMethodOrField cpIMethod = cpBands.getCPIMethod(owner, name, desc);
@@ -396,20 +397,20 @@
         updateRenumbering();
         bcCodes.add(MULTIANEWARRAY);
         bcClassRef.add(cpBands.getCPClass(desc));
-        bcByte.add(new Integer(dimensions & 0xFF));
+        bcByte.add(dimensions & 0xFF);
     }
 
     public void visitTableSwitchInsn(int min, int max, Label dflt,
             Label[] labels) {
         bcCodes.add(TABLESWITCH);
         bcLabel.add(dflt);
-        bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
-        bcCaseValue.add(new Integer(min));
+        bcLabelRelativeOffsets.add(byteCodeOffset);
+        bcCaseValue.add(min);
         int count = labels.length;
-        bcCaseCount.add(new Integer(count));
+        bcCaseCount.add(count);
         for (int i = 0; i < count; i++) {
             bcLabel.add(labels[i]);
-            bcLabelRelativeOffsets.add(new Integer(byteCodeOffset));
+            bcLabelRelativeOffsets.add(byteCodeOffset);
         }
         int padding = (byteCodeOffset + 1) % 4 == 0 ? 0 : 4 - ((byteCodeOffset + 1) % 4);
         byteCodeOffset+= (padding + 12 + 4 * labels.length);
@@ -420,7 +421,7 @@
         // NEW, ANEWARRAY, CHECKCAST or INSTANCEOF
         byteCodeOffset += 3;
         updateRenumbering();
-        bcCodes.add(new Integer(opcode));
+        bcCodes.add(opcode);
         bcClassRef.add(cpBands.getCPClass(type));
     }
 
@@ -429,35 +430,35 @@
         if (var > Byte.MAX_VALUE) {
             byteCodeOffset += 4;
             bcCodes.add(WIDE);
-            bcCodes.add(new Integer(opcode));
-            bcLocal.add(new Integer(var));
+            bcCodes.add(opcode);
+            bcLocal.add(var);
         } else {
             if(var > 3 || opcode == 169 /* RET */) {
                 byteCodeOffset += 2;
-                bcCodes.add(new Integer(opcode));
-                bcLocal.add(new Integer(var));
+                bcCodes.add(opcode);
+                bcLocal.add(var);
             } else {
                 byteCodeOffset +=1;
                 switch(opcode) {
                 case 21: // ILOAD
                 case 54: // ISTORE
-                    bcCodes.add(new Integer(opcode + 5 + var));
+                    bcCodes.add(opcode + 5 + var);
                     break;
                 case 22: // LLOAD
                 case 55: // LSTORE
-                    bcCodes.add(new Integer(opcode + 8 + var));
+                    bcCodes.add(opcode + 8 + var);
                     break;
                 case 23: // FLOAD
                 case 56: // FSTORE
-                    bcCodes.add(new Integer(opcode + 11 + var));
+                    bcCodes.add(opcode + 11 + var);
                     break;
                 case 24: // DLOAD
                 case 57: // DSTORE
-                    bcCodes.add(new Integer(opcode + 14 + var));
+                    bcCodes.add(opcode + 14 + var);
                     break;
                 case 25: // A_LOAD
                 case 58: // A_STORE
-                    bcCodes.add(new Integer(opcode + 17 + var));
+                    bcCodes.add(opcode + 17 + var);
                     break;
                 }
             }

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=745887&r1=745886&r2=745887&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
Thu Feb 19 14:45:53 2009
@@ -33,7 +33,6 @@
 
 public class ClassBands extends BandSet {
 
-    private static final Integer ZERO = new Integer(0);
     private final SegmentHeader header;
     private final CpBands cpBands;
     private final AttributeDefinitionBands attrBands;
@@ -52,8 +51,8 @@
     private final List classEnclosingMethodDesc = new ArrayList();
     private final List classSignature = new ArrayList();
 
-    private final List classFileVersionMinor = new ArrayList();
-    private final List classFileVersionMajor = new ArrayList();
+    private final IntList classFileVersionMinor = new IntList();
+    private final IntList classFileVersionMajor = new IntList();
 
     private final int[] class_field_count;
     private final CPNameAndType[][] field_descr;
@@ -67,33 +66,33 @@
     private final long[][] method_flags;
     private int[] method_attr_calls;
     private final List methodSignature = new ArrayList();
-    private final List methodExceptionNumber = new ArrayList();
+    private final IntList methodExceptionNumber = new IntList();
     private final List methodExceptionClasses = new ArrayList();
 
     private int[] codeHeaders;
-    private final List codeMaxStack = new ArrayList();
-    private final List codeMaxLocals = new ArrayList();
-    private final List codeHandlerCount = new ArrayList();
+    private final IntList codeMaxStack = new IntList();
+    private final IntList codeMaxLocals = new IntList();
+    private final IntList codeHandlerCount = new IntList();
     private final List codeHandlerStartP = new ArrayList();
     private final List codeHandlerEndPO = new ArrayList();
     private final List codeHandlerCatchPO = new ArrayList();
     private final List codeHandlerClass = new ArrayList();
     private final List codeFlags = new ArrayList();
-    private final List codeLineNumberTableN = new ArrayList();
+    private final IntList codeLineNumberTableN = new IntList();
     private final List codeLineNumberTableBciP = new ArrayList();
-    private final List codeLineNumberTableLine = new ArrayList();
-    private final List codeLocalVariableTableN = new ArrayList();
+    private final IntList codeLineNumberTableLine = new IntList();
+    private final IntList codeLocalVariableTableN = new IntList();
     private final List codeLocalVariableTableBciP = new ArrayList();
     private final List codeLocalVariableTableSpanO = new ArrayList();
     private final List codeLocalVariableTableNameRU = new ArrayList();
     private final List codeLocalVariableTableTypeRS = new ArrayList();
-    private final List codeLocalVariableTableSlot = new ArrayList();
-    private final List codeLocalVariableTypeTableN = new ArrayList();
+    private final IntList codeLocalVariableTableSlot = new IntList();
+    private final IntList codeLocalVariableTypeTableN = new IntList();
     private final List codeLocalVariableTypeTableBciP = new ArrayList();
     private final List codeLocalVariableTypeTableSpanO = new ArrayList();
     private final List codeLocalVariableTypeTableNameRU = new ArrayList();
     private final List codeLocalVariableTypeTableTypeRS = new ArrayList();
-    private final List codeLocalVariableTypeTableSlot = new ArrayList();
+    private final IntList codeLocalVariableTypeTableSlot = new IntList();
 
     private final MetadataBandGroup class_RVA_bands;
     private final MetadataBandGroup class_RIA_bands;
@@ -235,19 +234,17 @@
             int major = major_versions[i];
             if (major != defaultMajorVersion) {
                 class_flags[i] |= 1 << 24;
-                classFileVersionMajor.add(new Integer(major));
-                classFileVersionMinor.add(ZERO);
+                classFileVersionMajor.add(major);
+                classFileVersionMinor.add(0);
             }
         }
         // Calculate code headers
         codeHeaders = new int[codeHandlerCount.size()];
         int removed = 0;
         for (int i = 0; i < codeHeaders.length; i++) {
-            int numHandlers = ((Integer) codeHandlerCount.get(i - removed))
-                    .intValue();
-            int maxLocals = ((Integer) codeMaxLocals.get(i - removed))
-                    .intValue();
-            int maxStack = ((Integer) codeMaxStack.get(i - removed)).intValue();
+            int numHandlers = codeHandlerCount.get(i - removed);
+            int maxLocals = codeMaxLocals.get(i - removed);
+            int maxStack = codeMaxStack.get(i - removed);
             if (numHandlers == 0) {
                 int header = maxLocals * 12 + maxStack + 1;
                 if (header < 145 && maxStack < 12) {
@@ -277,7 +274,7 @@
         }
 
         // Compute any required IcLocals
-        List innerClassesN = new ArrayList();
+        IntList innerClassesN = new IntList();
         List icLocal = new ArrayList();
         for (int i = 0; i < class_this.length; i++) {
             CPClass cpClass = class_this[i];
@@ -302,12 +299,12 @@
                     }
                 }
                 if(innerN != 0) {
-                    innerClassesN.add(new Integer(innerN));
+                    innerClassesN.add(innerN);
                     class_flags[i] |= (1 << 23);
                 }
             }
         }
-        class_InnerClasses_N = listToArray(innerClassesN);
+        class_InnerClasses_N = innerClassesN.toArray();
         class_InnerClasses_RC = new CPClass[icLocal.size()];
         class_InnerClasses_F = new int[icLocal.size()];
         classInnerClassesOuterRCN = new ArrayList();
@@ -328,39 +325,39 @@
             }
         }
         // Calculate any backwards calls from metadata bands
-        List classAttrCalls = new ArrayList();
-        List fieldAttrCalls = new ArrayList();
-        List methodAttrCalls = new ArrayList();
+        IntList classAttrCalls = new IntList();
+        IntList fieldAttrCalls = new IntList();
+        IntList methodAttrCalls = new IntList();
         if(class_RVA_bands.hasContent()) {
-            classAttrCalls.add(new Integer(class_RVA_bands.numBackwardsCalls()));
+            classAttrCalls.add(class_RVA_bands.numBackwardsCalls());
         }
         if(class_RIA_bands.hasContent()) {
-            classAttrCalls.add(new Integer(class_RIA_bands.numBackwardsCalls()));
+            classAttrCalls.add(class_RIA_bands.numBackwardsCalls());
         }
         if(field_RVA_bands.hasContent()) {
-            fieldAttrCalls.add(new Integer(field_RVA_bands.numBackwardsCalls()));
+            fieldAttrCalls.add(field_RVA_bands.numBackwardsCalls());
         }
         if(field_RIA_bands.hasContent()) {
-            fieldAttrCalls.add(new Integer(field_RIA_bands.numBackwardsCalls()));
+            fieldAttrCalls.add(field_RIA_bands.numBackwardsCalls());
         }
         if(method_RVA_bands.hasContent()) {
-            methodAttrCalls.add(new Integer(method_RVA_bands.numBackwardsCalls()));
+            methodAttrCalls.add(method_RVA_bands.numBackwardsCalls());
         }
         if(method_RIA_bands.hasContent()) {
-            methodAttrCalls.add(new Integer(method_RIA_bands.numBackwardsCalls()));
+            methodAttrCalls.add(method_RIA_bands.numBackwardsCalls());
         }
         if(method_RVPA_bands.hasContent()) {
-            methodAttrCalls.add(new Integer(method_RVPA_bands.numBackwardsCalls()));
+            methodAttrCalls.add(method_RVPA_bands.numBackwardsCalls());
         }
         if(method_RIPA_bands.hasContent()) {
-            methodAttrCalls.add(new Integer(method_RIPA_bands.numBackwardsCalls()));
+            methodAttrCalls.add(method_RIPA_bands.numBackwardsCalls());
         }
         if(method_AD_bands.hasContent()) {
-            methodAttrCalls.add(new Integer(method_AD_bands.numBackwardsCalls()));
+            methodAttrCalls.add(method_AD_bands.numBackwardsCalls());
         }
-        class_attr_calls = listToArray(classAttrCalls);
-        field_attr_calls = listToArray(fieldAttrCalls);
-        method_attr_calls = listToArray(methodAttrCalls);
+        class_attr_calls = classAttrCalls.toArray();
+        field_attr_calls = fieldAttrCalls.toArray();
+        method_attr_calls = methodAttrCalls.toArray();
     }
 
     public void pack(OutputStream out) throws IOException, Pack200Exception {
@@ -449,7 +446,7 @@
 //        *method_attr_indexes :UNSIGNED5 [SUM(*method_attr_count)]
         out.write(encodeBandInt("method_attr_calls", method_attr_calls, Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionNumber",
-                listToArray(methodExceptionNumber), Codec.UNSIGNED5));
+                methodExceptionNumber.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodExceptionClasses",
                 cpEntryListToArray(methodExceptionClasses), Codec.UNSIGNED5));
         out.write(encodeBandInt("methodSignature",
@@ -486,9 +483,9 @@
         out.write(encodeBandInt("class_InnerClasses_outer_RCN", cpEntryOrNullListToArray(classInnerClassesOuterRCN),
Codec.UNSIGNED5));
         out.write(encodeBandInt("class_InnerClasses_name_RUN", cpEntryOrNullListToArray(classInnerClassesNameRUN),
Codec.UNSIGNED5));
         out.write(encodeBandInt("classFileVersionMinor",
-                listToArray(classFileVersionMinor), Codec.UNSIGNED5));
+                classFileVersionMinor.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("classFileVersionMajor",
-                listToArray(classFileVersionMajor), Codec.UNSIGNED5));
+                classFileVersionMajor.toArray(), Codec.UNSIGNED5));
     }
 
     private int[] getInts(CPClass[] cpClasses) {
@@ -502,12 +499,12 @@
     private void writeCodeBands(OutputStream out) throws IOException,
             Pack200Exception {
         out.write(encodeBandInt("codeHeaders", codeHeaders, Codec.BYTE1));
-        out.write(encodeBandInt("codeMaxStack", listToArray(codeMaxStack),
+        out.write(encodeBandInt("codeMaxStack", codeMaxStack.toArray(),
                 Codec.UNSIGNED5));
-        out.write(encodeBandInt("codeMaxLocals", listToArray(codeMaxLocals),
+        out.write(encodeBandInt("codeMaxLocals", codeMaxLocals.toArray(),
                 Codec.UNSIGNED5));
         out.write(encodeBandInt("codeHandlerCount",
-                listToArray(codeHandlerCount), Codec.UNSIGNED5));
+                codeHandlerCount.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("codeHandlerStartP",
                 listToArray(codeHandlerStartP), Codec.BCI5));
         out.write(encodeBandInt("codeHandlerEndPO",
@@ -528,13 +525,13 @@
         // *code_attr_indexes :UNSIGNED5 [SUM(*code_attr_count)]
         // *code_attr_calls :UNSIGNED5 [...]
         out.write(encodeBandInt("code_LineNumberTable_N",
-                listToArray(codeLineNumberTableN), Codec.UNSIGNED5));
+                codeLineNumberTableN.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LineNumberTable_bci_P",
                 listToArray(codeLineNumberTableBciP), Codec.BCI5));
         out.write(encodeBandInt("code_LineNumberTable_line",
-                listToArray(codeLineNumberTableLine), Codec.UNSIGNED5));
+                codeLineNumberTableLine.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTable_N",
-                listToArray(codeLocalVariableTableN), Codec.UNSIGNED5));
+                codeLocalVariableTableN.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTable_bci_P",
                 listToArray(codeLocalVariableTableBciP), Codec.BCI5));
         out.write(encodeBandInt("code_LocalVariableTable_span_O",
@@ -546,9 +543,9 @@
                 cpEntryListToArray(codeLocalVariableTableTypeRS),
                 Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTable_slot",
-                listToArray(codeLocalVariableTableSlot), Codec.UNSIGNED5));
+                codeLocalVariableTableSlot.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTypeTable_N",
-                listToArray(codeLocalVariableTypeTableN), Codec.UNSIGNED5));
+                codeLocalVariableTypeTableN.toArray(), Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTypeTable_bci_P",
                 listToArray(codeLocalVariableTypeTableBciP), Codec.BCI5));
         out.write(encodeBandInt("code_LocalVariableTypeTable_span_O",
@@ -560,7 +557,7 @@
                 cpEntryListToArray(codeLocalVariableTypeTableTypeRS),
                 Codec.UNSIGNED5));
         out.write(encodeBandInt("code_LocalVariableTypeTable_slot",
-                listToArray(codeLocalVariableTypeTableSlot), Codec.UNSIGNED5));
+                codeLocalVariableTypeTableSlot.toArray(), Codec.UNSIGNED5));
 
     }
 
@@ -574,7 +571,7 @@
             flags |= (1 << 19);
         }
         if (exceptions != null) {
-            methodExceptionNumber.add(new Integer(exceptions.length));
+            methodExceptionNumber.add(exceptions.length);
             for (int i = 0; i < exceptions.length; i++) {
                 methodExceptionClasses.add(cpBands.getCPClass(exceptions[i]));
             }
@@ -595,7 +592,7 @@
     public void endOfMethod() {
         if(codeFlags.size() > 0) {
             long latestCodeFlag = ((Long)codeFlags.get(codeFlags.size() - 1)).longValue();
-            int latestLocalVariableTableN = ((Integer)codeLocalVariableTableN.get(codeLocalVariableTableN.size()
- 1)).intValue();
+            int latestLocalVariableTableN = codeLocalVariableTableN.get(codeLocalVariableTableN.size()
- 1);
             if(latestCodeFlag == (1 << 2) && latestLocalVariableTableN == 0)
{
                 codeLocalVariableTableN.remove(codeLocalVariableTableN.size() - 1);
                 codeFlags.remove(codeFlags.size() - 1);
@@ -705,26 +702,26 @@
                 .remove(tempMethodFlags.size() - 1);
         Long newFlag = new Long(latestFlag.intValue() | (1 << 17));
         tempMethodFlags.add(newFlag);
-        codeMaxStack.add(new Integer(maxStack));
+        codeMaxStack.add(maxStack);
         if ((newFlag.longValue() & (1 << 3)) == 0) { // not static
             maxLocals--; // minus 'this' local
         }
         maxLocals -= numMethodArgs;
-        codeMaxLocals.add(new Integer(maxLocals));
+        codeMaxLocals.add(maxLocals);
     }
 
     public void addCode(boolean stripDebug) {
-        codeHandlerCount.add(ZERO);
+        codeHandlerCount.add(0);
         if(!stripDebug) {
             codeFlags.add(new Long((1 << 2))); // TODO: What if there's no debug information?
-            codeLocalVariableTableN.add(new Integer(0));
+            codeLocalVariableTableN.add(0);
         }
     }
 
     public void addHandler(Label start, Label end, Label handler, String type) {
-        Integer handlers = (Integer) codeHandlerCount.remove(codeHandlerCount
+        int handlers = codeHandlerCount.remove(codeHandlerCount
                 .size() - 1);
-        codeHandlerCount.add(new Integer(handlers.intValue() + 1));
+        codeHandlerCount.add(handlers + 1);
         codeHandlerStartP.add(start);
         codeHandlerEndPO.add(end);
         codeHandlerCatchPO.add(handler);
@@ -736,13 +733,12 @@
         if ((latestCodeFlag.intValue() & (1 << 1)) == 0) {
             codeFlags.remove(codeFlags.size() - 1);
             codeFlags.add(new Long(latestCodeFlag.intValue() | (1 << 1)));
-            codeLineNumberTableN.add(new Integer(1));
+            codeLineNumberTableN.add(1);
         } else {
-            Integer numLines = (Integer) codeLineNumberTableN
-                    .remove(codeLineNumberTableN.size() - 1);
-            codeLineNumberTableN.add(new Integer(numLines.intValue() + 1));
+            codeLineNumberTableN
+                    .increment(codeLineNumberTableN.size() - 1);
         }
-        codeLineNumberTableLine.add(new Integer(line));
+        codeLineNumberTableLine.add(line);
         codeLineNumberTableBciP.add(start);
         // TODO: bci renumbering
     }
@@ -754,32 +750,29 @@
             if ((latestCodeFlag.intValue() & (1 << 3)) == 0) {
                 codeFlags.remove(codeFlags.size() - 1);
                 codeFlags.add(new Long(latestCodeFlag.intValue() | (1 << 3)));
-                codeLocalVariableTypeTableN.add(new Integer(1));
+                codeLocalVariableTypeTableN.add(1);
             } else {
-                Integer numLocals = (Integer) codeLocalVariableTypeTableN
-                        .remove(codeLocalVariableTypeTableN.size() - 1);
-                codeLocalVariableTypeTableN.add(new Integer(numLocals
-                        .intValue() + 1));
+                codeLocalVariableTypeTableN
+                        .increment(codeLocalVariableTypeTableN.size() - 1);
             }
             codeLocalVariableTypeTableBciP.add(start);
             codeLocalVariableTypeTableSpanO.add(end);
             codeLocalVariableTypeTableNameRU.add(cpBands.getCPUtf8(name));
             codeLocalVariableTypeTableTypeRS.add(cpBands
                     .getCPSignature(signature));
-            codeLocalVariableTypeTableSlot.add(new Integer(indx));
+            codeLocalVariableTypeTableSlot.add(indx);
         }
         // LocalVariableTable attribute
-        Integer numLocals = (Integer) codeLocalVariableTableN
-                .remove(codeLocalVariableTableN.size() - 1);
-        codeLocalVariableTableN.add(new Integer(numLocals.intValue() + 1));
+        codeLocalVariableTableN
+                .increment(codeLocalVariableTableN.size() - 1);
         codeLocalVariableTableBciP.add(start);
         codeLocalVariableTableSpanO.add(end);
         codeLocalVariableTableNameRU.add(cpBands.getCPUtf8(name));
         codeLocalVariableTableTypeRS.add(cpBands.getCPSignature(desc));
-        codeLocalVariableTableSlot.add(new Integer(indx));
+        codeLocalVariableTableSlot.add(indx);
     }
 
-    public void doBciRenumbering(List bciRenumbering, Map labelsToOffsets) {
+    public void doBciRenumbering(IntList bciRenumbering, Map labelsToOffsets) {
         renumberBci(codeLineNumberTableBciP, bciRenumbering, labelsToOffsets);
         renumberBci(codeLocalVariableTableBciP, bciRenumbering, labelsToOffsets);
         renumberOffsetBci(codeLocalVariableTableBciP,
@@ -796,7 +789,7 @@
                 bciRenumbering, labelsToOffsets);
     }
 
-    private void renumberBci(List list, List bciRenumbering, Map labelsToOffsets) {
+    private void renumberBci(List list, IntList bciRenumbering, Map labelsToOffsets) {
         for (int i = list.size() - 1; i >= 0; i--) {
             Object label = list.get(i);
             if (label instanceof Integer) {
@@ -804,13 +797,13 @@
             } else if (label instanceof Label) {
                 list.remove(i);
                 Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
-                list.add(i, bciRenumbering.get(bytecodeIndex.intValue()));
+                list.add(i, new Integer(bciRenumbering.get(bytecodeIndex.intValue())));
             }
         }
     }
 
     private void renumberOffsetBci(List relative, List list,
-            List bciRenumbering, Map labelsToOffsets) {
+            IntList bciRenumbering, Map labelsToOffsets) {
         for (int i = list.size() - 1; i >= 0; i--) {
             Object label = list.get(i);
             if (label instanceof Integer) {
@@ -818,8 +811,8 @@
             } else if (label instanceof Label) {
                 list.remove(i);
                 Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
-                Integer renumberedOffset = new Integer(((Integer) bciRenumbering
-                        .get(bytecodeIndex.intValue())).intValue()
+                Integer renumberedOffset = new Integer(bciRenumbering
+                        .get(bytecodeIndex.intValue())
                         - ((Integer) relative.get(i)).intValue());
                 list.add(i, renumberedOffset);
             }
@@ -827,7 +820,7 @@
     }
 
     private void renumberDoubleOffsetBci(List relative, List firstOffset, List list,
-            List bciRenumbering, Map labelsToOffsets) {
+            IntList bciRenumbering, Map labelsToOffsets) {
         // TODO: There's probably a nicer way of doing this...
         for (int i = list.size() - 1; i >= 0; i--) {
             Object label = list.get(i);
@@ -836,8 +829,8 @@
             } else if (label instanceof Label) {
                 list.remove(i);
                 Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
-                Integer renumberedOffset = new Integer(((Integer) bciRenumbering
-                        .get(bytecodeIndex.intValue())).intValue()
+                Integer renumberedOffset = new Integer(bciRenumbering
+                        .get(bytecodeIndex.intValue())
                         - ((Integer) relative.get(i)).intValue() - ((Integer) firstOffset.get(i)).intValue());
                 list.add(i, renumberedOffset);
             }

Added: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java?rev=745887&view=auto
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
Thu Feb 19 14:45:53 2009
@@ -0,0 +1,253 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.harmony.pack200;
+
+import java.util.Arrays;
+
+/**
+ * IntList is based on java.util.ArrayList, but is written specifically for ints
+ * in order to reduce boxing and unboxing to Integers and reduce the memory
+ * required.
+ */
+public class IntList {
+
+    private int[] array;
+    private int firstIndex;
+    private int lastIndex;
+    private int modCount;
+
+    /**
+     * Constructs a new instance of IntList with capacity for ten elements.
+     */
+    public IntList() {
+        this(10);
+    }
+
+    /**
+     * Constructs a new instance of IntList with the specified capacity.
+     *
+     * @param capacity
+     *            the initial capacity of this IntList
+     */
+    public IntList(int capacity) {
+        if (capacity < 0) {
+            throw new IllegalArgumentException();
+        }
+        firstIndex = lastIndex = 0;
+        array = new int[capacity];
+    }
+
+    /**
+     * Adds the specified object at the end of this IntList.
+     *
+     * @param object
+     *            the object to add
+     * @return true
+     */
+    public boolean add(int object) {
+        if (lastIndex == array.length) {
+            growAtEnd(1);
+        }
+        array[lastIndex++] = object;
+        modCount++;
+        return true;
+    }
+
+    public void add(int location, int object) {
+        int size = lastIndex - firstIndex;
+        if (0 < location && location < size) {
+            if (firstIndex == 0 && lastIndex == array.length) {
+                growForInsert(location, 1);
+            } else if ((location < size / 2 && firstIndex > 0)
+                    || lastIndex == array.length) {
+                System.arraycopy(array, firstIndex, array, --firstIndex,
+                        location);
+            } else {
+                int index = location + firstIndex;
+                System.arraycopy(array, index, array, index + 1, size
+                        - location);
+                lastIndex++;
+            }
+            array[location + firstIndex] = object;
+        } else if (location == 0) {
+            if (firstIndex == 0) {
+                growAtFront(1);
+            }
+            array[--firstIndex] = object;
+        } else if (location == size) {
+            if (lastIndex == array.length) {
+                growAtEnd(1);
+            }
+            array[lastIndex++] = object;
+        } else {
+            throw new IndexOutOfBoundsException();
+        }
+
+        modCount++;
+    }
+
+    public void clear() {
+        if (firstIndex != lastIndex) {
+            Arrays.fill(array, firstIndex, lastIndex, -1);
+            firstIndex = lastIndex = 0;
+            modCount++;
+        }
+    }
+
+    public int get(int location) {
+        if (0 <= location && location < (lastIndex - firstIndex)) {
+            return array[firstIndex + location];
+        }
+        throw new IndexOutOfBoundsException("" + location);
+    }
+
+    private void growAtEnd(int required) {
+        int size = lastIndex - firstIndex;
+        if (firstIndex >= required - (array.length - lastIndex)) {
+            int newLast = lastIndex - firstIndex;
+            if (size > 0) {
+                System.arraycopy(array, firstIndex, array, 0, size);
+            }
+            firstIndex = 0;
+            lastIndex = newLast;
+        } else {
+            int increment = size / 2;
+            if (required > increment) {
+                increment = required;
+            }
+            if (increment < 12) {
+                increment = 12;
+            }
+            int[] newArray = new int[size + increment];
+            if (size > 0) {
+                System.arraycopy(array, firstIndex, newArray, 0, size);
+                firstIndex = 0;
+                lastIndex = size;
+            }
+            array = newArray;
+        }
+    }
+
+    private void growAtFront(int required) {
+        int size = lastIndex - firstIndex;
+        if (array.length - lastIndex + firstIndex >= required) {
+            int newFirst = array.length - size;
+            if (size > 0) {
+                System.arraycopy(array, firstIndex, array, newFirst, size);
+            }
+            firstIndex = newFirst;
+            lastIndex = array.length;
+        } else {
+            int increment = size / 2;
+            if (required > increment) {
+                increment = required;
+            }
+            if (increment < 12) {
+                increment = 12;
+            }
+            int[] newArray = new int[size + increment];
+            if (size > 0) {
+                System.arraycopy(array, firstIndex, newArray, newArray.length
+                        - size, size);
+            }
+            firstIndex = newArray.length - size;
+            lastIndex = newArray.length;
+            array = newArray;
+        }
+    }
+
+    private void growForInsert(int location, int required) {
+        int size = lastIndex - firstIndex;
+        int increment = size / 2;
+        if (required > increment) {
+            increment = required;
+        }
+        if (increment < 12) {
+            increment = 12;
+        }
+        int[] newArray = new int[size + increment];
+        int newFirst = increment - required;
+        // Copy elements after location to the new array skipping inserted
+        // elements
+        System.arraycopy(array, location + firstIndex, newArray, newFirst
+                + location + required, size - location);
+        // Copy elements before location to the new array from firstIndex
+        System.arraycopy(array, firstIndex, newArray, newFirst, location);
+        firstIndex = newFirst;
+        lastIndex = size + increment;
+
+        array = newArray;
+    }
+
+    public void increment(int location) {
+        if (0 <= location && location < (lastIndex - firstIndex)) {
+            array[firstIndex + location]++;
+        } else {
+            throw new IndexOutOfBoundsException("" + location);
+        }
+    }
+
+    public boolean isEmpty() {
+        return lastIndex == firstIndex;
+    }
+
+    public int remove(int location) {
+        int result;
+        int size = lastIndex - firstIndex;
+        if (0 <= location && location < size) {
+            if (location == size - 1) {
+                result = array[--lastIndex];
+                array[lastIndex] = 0;
+            } else if (location == 0) {
+                result = array[firstIndex];
+                array[firstIndex++] = 0;
+            } else {
+                int elementIndex = firstIndex + location;
+                result = array[elementIndex];
+                if (location < size / 2) {
+                    System.arraycopy(array, firstIndex, array, firstIndex + 1,
+                            location);
+                    array[firstIndex++] = 0;
+                } else {
+                    System.arraycopy(array, elementIndex + 1, array,
+                            elementIndex, size - location - 1);
+                    array[--lastIndex] = 0;
+                }
+            }
+            if (firstIndex == lastIndex) {
+                firstIndex = lastIndex = 0;
+            }
+        } else {
+            throw new IndexOutOfBoundsException();
+        }
+
+        modCount++;
+        return result;
+    }
+
+    public int size() {
+        return lastIndex - firstIndex;
+    }
+
+    public int[] toArray() {
+        int size = lastIndex - firstIndex;
+        int[] result = new int[size];
+        System.arraycopy(array, firstIndex, result, 0, size);
+        return result;
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/IntList.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message