harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjanu...@apache.org
Subject svn commit: r643321 - in /harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode: CPNameAndType.java CPRef.java ClassConstantPool.java ConstantPoolEntry.java
Date Tue, 01 Apr 2008 08:27:55 GMT
Author: sjanuary
Date: Tue Apr  1 01:27:51 2008
New Revision: 643321

URL: http://svn.apache.org/viewvc?rev=643321&view=rev
Log:
Apply patch for HARMONY-5672 ([classlib][pack200] Performance improvements for pack200)

Modified:
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
    harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java?rev=643321&r1=643320&r2=643321&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java
Tue Apr  1 01:27:51 2008
@@ -31,6 +31,8 @@
 
 	transient int nameIndex;
 
+	protected String cachedComparisonString = null;
+
 	public CPNameAndType(CPUTF8 name, CPUTF8 descriptor, int domain) {
 		super(ConstantPoolEntry.CP_NameAndType);
 		this.name = name;
@@ -118,6 +120,9 @@
         // going on. How to sort these things so that even if
         // they're in some oddball codepage they'll still end
         // up sorted correctly?
+        if(cachedComparisonString != null) {
+            return cachedComparisonString;
+        }
         String descriptorString = descriptor.underlyingString();
         StringBuffer comparisonBuffer = new StringBuffer();
         if((descriptorString.indexOf("(")) == -1) {
@@ -141,6 +146,7 @@
             }
         }
         comparisonBuffer.append(name.underlyingString());
-        return comparisonBuffer.toString();
+        cachedComparisonString = comparisonBuffer.toString();
+        return cachedComparisonString;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java?rev=643321&r1=643320&r2=643321&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/CPRef.java
Tue Apr  1 01:27:51 2008
@@ -41,6 +41,9 @@
 			return false;
 		if (getClass() != obj.getClass())
 			return false;
+		if (this.hashCode() != obj.hashCode()) {
+		    return false;
+		}
 		final CPRef other = (CPRef) obj;
 		if (className == null) {
 			if (other.className != null)

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java?rev=643321&r1=643320&r2=643321&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java
Tue Apr  1 01:27:51 2008
@@ -17,12 +17,13 @@
 package org.apache.harmony.pack200.bytecode;
 
 import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
-import org.apache.harmony.pack200.Pack200Exception;
 import org.apache.harmony.pack200.Segment;
-import org.apache.harmony.pack200.SegmentUtils;
 
 
 public class ClassConstantPool {
@@ -43,14 +44,17 @@
     public static final int DOMAIN_ATTRIBUTEASCIIZ = 12;
     public static final int NUM_DOMAINS = DOMAIN_ATTRIBUTEASCIIZ + 1;
 
-//    protected SortedSet sortedEntries = new TreeSet(new PoolComparator());
     protected ClassPoolSet classPoolSet = new ClassPoolSet();
+    protected HashSet entriesContainsSet = new HashSet();
+    protected HashSet othersContainsSet = new HashSet();
+
+    protected Map indexCache = null;
+
     public String toString() {
         return entries.toString();
     }
-    private final List others = new ArrayList();
-
-    private List entries = new ArrayList();
+    private List others = new ArrayList(500);
+    private List entries = new ArrayList(500);
 
     private boolean resolved;
 
@@ -74,14 +78,18 @@
 //          }
 //      }
         if (entry instanceof ConstantPoolEntry) {
-            if (!entries.contains(entry)) {
+          if (!entriesContainsSet.contains(entry)) {
+                entriesContainsSet.add(entry);
                 entries.add(entry);
                 if (entry instanceof CPLong ||entry instanceof CPDouble)
                     entries.add(entry); //these get 2 slots because of their size
             }
         } else {
-            if (!others.contains(entry))
+          if (!othersContainsSet.contains(entry)) {
+                othersContainsSet.add(entry);
                 others.add(entry);
+          }
+
         }
         ClassFileEntry[] nestedEntries = entry.getNestedClassFileEntries();
         for (int i = 0; i < nestedEntries.length; i++) {
@@ -90,7 +98,21 @@
         return entry;
     }
 
-    public int indexOf(ClassFileEntry entry) {
+    protected void initializeIndexCache() {
+        indexCache = new HashMap();
+        for(int index=0; index < entries.size(); index++) {
+            ClassFileEntry indexEntry = (ClassFileEntry)entries.get(index);
+            if(indexCache.containsKey(indexEntry)) {
+                // key is already in there - do nothing
+                // This will happen if a long or double
+                // is the entry - they take up 2 slots.
+            } else {
+                indexCache.put(indexEntry, new Integer(index));
+            }
+        }
+    }
+
+    public int indexOfOld(ClassFileEntry entry) {
         if (!resolved)
             throw new IllegalStateException("Constant pool is not yet resolved; this does
not make any sense");
         int entryIndex = entries.indexOf(entry);
@@ -101,6 +123,20 @@
         return -1;
     }
 
+    public int indexOf(ClassFileEntry entry) {
+        if (!resolved)
+            throw new IllegalStateException("Constant pool is not yet resolved; this does
not make any sense");
+        if(null == indexCache) {
+            initializeIndexCache();
+        }
+        Integer entryIndex = ((Integer)indexCache.get(entry));
+        // If the entry isn't found, answer -1. Otherwise answer the entry.
+        if(entryIndex != null) {
+            return entryIndex.intValue() + 1;
+        }
+        return -1;
+    }
+
     public int size() {
         return entries.size();
     }
@@ -117,7 +153,7 @@
         while(it.hasNext()) {
             classPoolSet.add(it.next());
         }
-        entries = new ArrayList();
+        entries = new ArrayList(entries.size());
       Iterator sortedIterator = classPoolSet.iterator();
       while(sortedIterator.hasNext()) {
           ConstantPoolEntry entry = (ConstantPoolEntry)sortedIterator.next();
@@ -147,6 +183,10 @@
         // final sort of the class pool. This fixes up
         // references, which are sorted by index in the
         // class pool.
+
+        // Since we resorted, need to initialize index cache
+        initializeIndexCache();
+
         it = entries.iterator();
         ClassPoolSet startOfPool = new ClassPoolSet();
         ClassPoolSet finalSort = new ClassPoolSet();
@@ -158,7 +198,7 @@
                 finalSort.add(nextEntry);
             }
         }
-        entries = new ArrayList();
+        entries = new ArrayList(entries.size());
         Iterator itStart = startOfPool.iterator();
         while(itStart.hasNext()) {
             ClassFileEntry entry = (ClassFileEntry) itStart.next();
@@ -173,6 +213,9 @@
             if (entry instanceof CPLong ||entry instanceof CPDouble)
                 entries.add(entry); //these get 2 slots because of their size
         }
+
+        // Since we resorted, need to initialize index cache
+        initializeIndexCache();
 
         // Now that the indices have been re-sorted, need
         // to re-resolve to update references. This should

Modified: harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java?rev=643321&r1=643320&r2=643321&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/pack200/src/main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java
Tue Apr  1 01:27:51 2008
@@ -58,9 +58,16 @@
 
 	protected int domain = ClassConstantPool.DOMAIN_UNDEFINED;
 	private static int creationOrderCount = 100;
+
+	protected String cachedConstantPoolComparisonString = null;
+
 	public String comparisonString() {
-	    return toString();
+	    if(cachedConstantPoolComparisonString == null) {
+	        cachedConstantPoolComparisonString = toString();
+	    }
+	    return cachedConstantPoolComparisonString;
 	}
+
 	public int creationOrder = -1;
 	ConstantPoolEntry(byte tag) {
 		this.tag = tag;



Mime
View raw message