Index: main/java/org/apache/harmony/pack200/SegmentConstantPool.java =================================================================== --- main/java/org/apache/harmony/pack200/SegmentConstantPool.java (revision 643602) +++ main/java/org/apache/harmony/pack200/SegmentConstantPool.java (working copy) @@ -291,7 +291,9 @@ } } + protected ConstantPoolEntry cachedCpAll[] = {}; public ConstantPoolEntry[] getCpAll() throws Pack200Exception { + if(cachedCpAll.length == 0) { ArrayList cpAll = new ArrayList(); // TODO: this is 1.5-specific. Try to get rid // of it. @@ -325,11 +327,10 @@ for(int index=0; index < bands.getCpIMethodClass().length; index++) { cpAll.add(getConstantPoolEntry(CP_IMETHOD, index)); } - ConstantPoolEntry[] result = new ConstantPoolEntry[cpAll.size()]; cpAll.toArray(result); - return result; + cachedCpAll = result; } - - + return cachedCpAll; } +} \ No newline at end of file Index: main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPFieldRef.java (working copy) @@ -25,7 +25,6 @@ transient int classNameIndex; private CPNameAndType nameAndType; transient int nameAndTypeIndex; - private String cachedComparisonString = null; public CPFieldRef(CPClass className, CPNameAndType descriptor) { super(ConstantPoolEntry.CP_Fieldref); @@ -53,13 +52,6 @@ return "FieldRef: " + className + "#" + nameAndType; } - public String comparisonString() { - if(cachedComparisonString == null) { - cachedComparisonString = (className.getName() + Character.MAX_VALUE) + nameAndType.descriptor + Character.MAX_VALUE + nameAndType.name; - } - return cachedComparisonString; - } - public int hashCode() { final int PRIME = 31; int result = 1; Index: main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/ConstantPoolEntry.java (working copy) @@ -57,21 +57,9 @@ byte tag; protected int domain = ClassConstantPool.DOMAIN_UNDEFINED; - private static int creationOrderCount = 100; - protected String cachedConstantPoolComparisonString = null; - - public String comparisonString() { - if(cachedConstantPoolComparisonString == null) { - cachedConstantPoolComparisonString = toString(); - } - return cachedConstantPoolComparisonString; - } - - public int creationOrder = -1; ConstantPoolEntry(byte tag) { this.tag = tag; - this.creationOrder = creationOrderCount++; } public abstract boolean equals(Object obj); @@ -96,4 +84,25 @@ } protected abstract void writeBody(DataOutputStream dos) throws IOException; + + private boolean mustStartClassPool = false; + /** + * Set whether the receiver must be at the start of the + * class pool. Anything which is the target of a single- + * byte ldc (bytecode 18) command must be at the start + * of the class pool. + * + * @param b boolean true if the receiver must be at + * the start of the class pool, otherwise false. + */ + public void mustStartClassPool(boolean b) { + mustStartClassPool = b; + } + + /* (non-Javadoc) + * @see org.apache.harmony.pack200.bytecode.ClassFileEntry#mustStartClassPool() + */ + public boolean mustStartClassPool() { + return mustStartClassPool; + } } Index: main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/ClassConstantPool.java (working copy) @@ -44,7 +44,6 @@ public static final int DOMAIN_ATTRIBUTEASCIIZ = 12; public static final int NUM_DOMAINS = DOMAIN_ATTRIBUTEASCIIZ + 1; - protected ClassPoolSet classPoolSet = new ClassPoolSet(); protected HashSet entriesContainsSet = new HashSet(); protected HashSet othersContainsSet = new HashSet(); @@ -81,8 +80,6 @@ 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 (!othersContainsSet.contains(entry)) { @@ -112,17 +109,6 @@ } } - 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); - // If the entry isn't found, answer -1. Otherwise answer the entry. - if(entryIndex != -1) { - return entryIndex + 1; - } - return -1; - } - public int indexOf(ClassFileEntry entry) { if (!resolved) throw new IllegalStateException("Constant pool is not yet resolved; this does not make any sense"); @@ -148,48 +134,56 @@ } public void resolve(Segment segment) { - classPoolSet = new ClassPoolSet(); - Iterator it = entries.iterator(); - while(it.hasNext()) { - classPoolSet.add(it.next()); - } - entries = new ArrayList(entries.size()); - Iterator sortedIterator = classPoolSet.iterator(); - while(sortedIterator.hasNext()) { - ConstantPoolEntry entry = (ConstantPoolEntry)sortedIterator.next(); - entries.add(entry); - // need to do this both here and in the sort below - // so the indices are correct. - if (entry instanceof CPLong ||entry instanceof CPDouble) - entries.add(entry); //these get 2 slots because of their size + Iterator it; + resolved= true; + it = entries.iterator(); + while (it.hasNext()) { + ClassFileEntry entry = (ClassFileEntry) it.next(); + entry.resolve(this); } - resolve(); + it = others.iterator(); + while (it.hasNext()) { + ClassFileEntry entry = (ClassFileEntry) it.next(); + entry.resolve(this); + } + + sortClassPool(segment); } - public void resolve() { - resolved= true; + /** + * Answer the collection of CPClasses currently held + * by the ClassPoolSet. This is used to calculate relevant + * classes when generating the set of relevant inner + * classes (ic_relevant()) + * @return ArrayList collection of all classes. + * + * NOTE: when this list is answered, the classes may not + * yet be resolved. + */ + public List allClasses() { + List classesList = new ArrayList(); Iterator it = entries.iterator(); - while (it.hasNext()) { - ClassFileEntry entry = (ClassFileEntry) it.next(); - entry.resolve(this); + while(it.hasNext()) { + ConstantPoolEntry entry = (ConstantPoolEntry)it.next(); + if(entry.getDomain() == DOMAIN_CLASSREF) { + classesList.add(entry); + } } - it = others.iterator(); - while (it.hasNext()) { - ClassFileEntry entry = (ClassFileEntry) it.next(); - entry.resolve(this); - } - + return classesList; + } + + protected void sortClassPool(Segment segment) { // Now that everything has been resolved, do one // final sort of the class pool. This fixes up - // references, which are sorted by index in the - // class pool. + // references to objects which need to be at the + // start of the class pool // Since we resorted, need to initialize index cache initializeIndexCache(); - it = entries.iterator(); - ClassPoolSet startOfPool = new ClassPoolSet(); - ClassPoolSet finalSort = new ClassPoolSet(); + Iterator it = entries.iterator(); + ArrayList startOfPool = new ArrayList(); + ArrayList finalSort = new ArrayList(); while(it.hasNext()) { ClassFileEntry nextEntry = (ClassFileEntry)it.next(); if(nextEntry.mustStartClassPool()) { @@ -232,26 +226,4 @@ entry.resolve(this); } } - - /** - * Answer the collection of CPClasses currently held - * by the ClassPoolSet. This is used to calculate relevant - * classes when generating the set of relevant inner - * classes (ic_relevant()) - * @return ArrayList collection of all classes. - * - * NOTE: when this list is answered, the classes may not - * yet be resolved. - */ - public List allClasses() { - List classesList = new ArrayList(); - Iterator it = entries.iterator(); - while(it.hasNext()) { - ConstantPoolEntry entry = (ConstantPoolEntry)it.next(); - if(entry.getDomain() == DOMAIN_CLASSREF) { - classesList.add(entry); - } - } - return classesList; - } } Index: main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPUTF8.java (working copy) @@ -24,8 +24,6 @@ private String utf8; - private String cachedSignatureComparisonString = null; - public CPUTF8(String utf8, int domain) { super(ConstantPoolEntry.CP_UTF8); this.utf8 = utf8; @@ -82,48 +80,4 @@ public String underlyingString() { return utf8; } - - public String comparisonString() { - // Should use either normalComparisonString or signatureComparisonString. - // If we get here, that might indicate an error. - throw new Error("Should use specific kinds of comparisonString() on CPUTF8s"); - } - - public String normalComparisonString() { - // TODO: what to do about inner classes? - if(utf8==null) {return "null:utf8 (probably an inner class?)";}; - return utf8; - } - - public String signatureComparisonString() { - if(cachedSignatureComparisonString != null) { - return cachedSignatureComparisonString; - } - // TODO: what to do about inner classes? - if(utf8==null) {return "null:utf8 (probably an inner class?)";}; - StringBuffer alphaChars = new StringBuffer(); - StringBuffer extraChars = new StringBuffer(); - if(utf8.length() > 0){ - if(utf8.charAt(0) == '(') { - // Things with return values (which apparently - // always begin with '(') sort after things - // without return values. - // TODO: need a better way for this - possibly in the comparator? - alphaChars.append(Character.MAX_VALUE); - } - } - // TODO: need a better way for this - possibly in the comparator? - extraChars.append(Character.MAX_VALUE); - for(int index=0; index < utf8.length(); index++) { - if( (utf8.charAt(index) == '(') || (utf8.charAt(index) == ')') || (utf8.charAt(index) == '[') || (utf8.charAt(index) == ']') ) { - extraChars.append(utf8.charAt(index)); - } else { - alphaChars.append(utf8.charAt(index)); - } - } - extraChars.append(Character.MAX_VALUE); - extraChars.append(utf8); // make sure the chars are distinct - cachedSignatureComparisonString = alphaChars.toString() + extraChars.toString(); - return(cachedSignatureComparisonString); - } } \ No newline at end of file Index: main/java/org/apache/harmony/pack200/bytecode/CPConstant.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPConstant.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPConstant.java (working copy) @@ -53,7 +53,4 @@ protected Object getValue() { return value; } - - - } Index: main/java/org/apache/harmony/pack200/bytecode/CPClass.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPClass.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPClass.java (working copy) @@ -84,11 +84,4 @@ protected void writeBody(DataOutputStream dos) throws IOException { dos.writeShort(index); } - - public String comparisonString() { - // TODO: what to do about inner classes? - if(name==null) {return "null:name (probably an inner class?)";}; - return getName(); - } - } \ No newline at end of file Index: main/java/org/apache/harmony/pack200/bytecode/CPString.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPString.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPString.java (working copy) @@ -23,7 +23,6 @@ private transient int nameIndex; private CPUTF8 name; - private boolean mustStartClassPool = false; public CPString(CPUTF8 value) { super(ConstantPoolEntry.CP_String, value); @@ -53,29 +52,4 @@ protected ClassFileEntry[] getNestedClassFileEntries() { return new ClassFileEntry[] { name }; } - - public String comparisonString() { - return ((CPUTF8)getValue()).underlyingString(); - } - - /** - * Set whether the receiver must be at the start of the - * class pool. Anything which is the target of a single- - * byte ldc (bytecode 18, String) command must be at - * the start of the class pool. - * - * @param b boolean true if the receiver must be at - * the start of the class pool, otherwise false. - */ - public void mustStartClassPool(boolean b) { - mustStartClassPool = b; - } - - - /* (non-Javadoc) - * @see org.apache.harmony.pack200.bytecode.ClassFileEntry#mustStartClassPool() - */ - public boolean mustStartClassPool() { - return mustStartClassPool; - } } \ No newline at end of file Index: main/java/org/apache/harmony/pack200/bytecode/ByteCode.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ByteCode.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/ByteCode.java (working copy) @@ -133,13 +133,6 @@ setOperand2Bytes(pool.indexOf(nested[index]), getNestedPosition(index)[0]); break; - case 4: - // TODO: need to handle wides? - SegmentUtils.debug("Need to handle wides"); - throw new Error("Instruction argument not handled"); - // figure out and if so, handle and put a break here. - // break; - default: SegmentUtils.debug("Unhandled resolve " + this); } Index: main/java/org/apache/harmony/pack200/bytecode/CPRef.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPRef.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPRef.java (working copy) @@ -26,7 +26,6 @@ protected CPNameAndType nameAndType; transient int nameAndTypeIndex; - private String resolvedComparisonString = null; public CPRef(byte type, CPClass className, CPNameAndType descriptor) { super(type); @@ -81,54 +80,22 @@ classNameIndex = pool.indexOf(className); } - public String comparisonString() { - // This one is tricky. The sorting appears to be - // done based on the indices of the method descriptor - // and class name in the classpool *after* sorting them. - - // If we haven't yet been resolved, just do a normal - // compare (so things like .contains() work). - if(!isResolved()) { - return super.comparisonString(); - } - - // If we get here, the receiver has been resolved; there - // is a different sort order. - if(resolvedComparisonString != null) { - return resolvedComparisonString; - } - - StringBuffer result = new StringBuffer(); - // Pad all numbers to 6 digits so they sort correctly. - int padLength = 6; - int classIndexLength = ("" + classNameIndex).length(); - int nameAndTypeIndexLength = ("" + nameAndTypeIndex).length(); - - for(int index=0; index < (padLength - classIndexLength); index++) { - result.append('0'); - } - result.append("" + classNameIndex); - result.append(":"); - for(int index=0; index < (padLength - nameAndTypeIndexLength); index++) { - result.append('0'); - } - result.append("" + nameAndTypeIndex); - resolvedComparisonString = result.toString(); - return resolvedComparisonString; - } - + protected String cachedToString = null; public String toString() { - String type; - if (getTag() == ConstantPoolEntry.CP_Fieldref) { - type = "FieldRef"; //$NON-NLS-1$ - } else if (getTag() == ConstantPoolEntry.CP_Methodref) { - type = "MethoddRef"; //$NON-NLS-1$ - } else if (getTag() == ConstantPoolEntry.CP_InterfaceMethodref) { - type = "InterfaceMethodRef"; //$NON-NLS-1$ - } else { - type = "unknown"; //$NON-NLS-1$ - } - return type + ": " + className + "#" + nameAndType; //$NON-NLS-1$ //$NON-NLS-2$ + if(cachedToString == null) { + String type; + if (getTag() == ConstantPoolEntry.CP_Fieldref) { + type = "FieldRef"; //$NON-NLS-1$ + } else if (getTag() == ConstantPoolEntry.CP_Methodref) { + type = "MethoddRef"; //$NON-NLS-1$ + } else if (getTag() == ConstantPoolEntry.CP_InterfaceMethodref) { + type = "InterfaceMethodRef"; //$NON-NLS-1$ + } else { + type = "unknown"; //$NON-NLS-1$ + } + cachedToString = type + ": " + className + "#" + nameAndType; //$NON-NLS-1$ //$NON-NLS-2$ + } + return cachedToString; } protected void writeBody(DataOutputStream dos) throws IOException { Index: main/java/org/apache/harmony/pack200/bytecode/forms/NarrowClassRefForm.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/forms/NarrowClassRefForm.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/forms/NarrowClassRefForm.java (working copy) @@ -18,6 +18,7 @@ import org.apache.harmony.pack200.Pack200Exception; import org.apache.harmony.pack200.bytecode.ByteCode; +import org.apache.harmony.pack200.bytecode.CPClass; import org.apache.harmony.pack200.bytecode.OperandManager; /** @@ -40,6 +41,7 @@ super.setNestedEntries(byteCode, operandManager, offset); if(!widened) { byteCode.setNestedPositions(new int[][] {{0,1}}); + ((CPClass)byteCode.getNestedClassFileEntries()[0]).mustStartClassPool(true); } } } Index: main/java/org/apache/harmony/pack200/bytecode/forms/SingleByteReferenceForm.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/forms/SingleByteReferenceForm.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/forms/SingleByteReferenceForm.java (working copy) @@ -18,6 +18,7 @@ import org.apache.harmony.pack200.Pack200Exception; import org.apache.harmony.pack200.bytecode.ByteCode; +import org.apache.harmony.pack200.bytecode.ConstantPoolEntry; import org.apache.harmony.pack200.bytecode.OperandManager; /** @@ -45,6 +46,7 @@ byteCode.setNestedPositions(new int[][] {{0,2}}); } else { byteCode.setNestedPositions(new int[][] {{0,1}}); + ((ConstantPoolEntry)byteCode.getNestedClassFileEntries()[0]).mustStartClassPool(true); } } } Index: main/java/org/apache/harmony/pack200/bytecode/ClassPoolSet.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/ClassPoolSet.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/ClassPoolSet.java (working copy) @@ -1,235 +0,0 @@ -/* - * 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.bytecode; - -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.TreeSet; - -/** - * This class implements the special set (which is aware of - * domains) used when generating ClassConstantPools. - * It's called a Set, but isn't quite a Collection - it - * doesn't implement all the API required. - */ -public class ClassPoolSet { - - class GeneralComparator implements Comparator { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(Object o1, Object o2) { - if(o1.equals(o2)) { - return 0; - } - return o1.getClass().getName().compareTo(o2.getClass().getName()); - } - } - - class PoolComparator extends GeneralComparator { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(Object o1, Object o2) { - int classCompare = super.compare(o1, o2); - if(classCompare != 0) { - return classCompare; - } - // If we compare anything other than ConstantPoolEntries - // with this comparator, it is an error. - ConstantPoolEntry cpe1 = (ConstantPoolEntry)o1; - ConstantPoolEntry cpe2 = (ConstantPoolEntry)o2; - - // Domains must be the same, need to compare - // based on comparisonString. - String compare1 = cpe1.comparisonString(); - String compare2 = cpe2.comparisonString(); - return compare1.compareTo(compare2); - } - } - - class SignatureAsciizComparator extends GeneralComparator { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(Object o1, Object o2) { - int classCompare = super.compare(o1, o2); - if(classCompare != 0) { - return classCompare; - } - - // Now that we've reached this point, we're - // comparing objects of the same class. Since - // they have the same class, we can make the - // statement that they're UTF8s, since only - // UTF8s will be added to a TreeSet with - // the SignatureAsciizComparator. - CPUTF8 cpe1 = (CPUTF8)o1; - CPUTF8 cpe2 = (CPUTF8)o2; - - String compare1 = cpe1.signatureComparisonString(); - String compare2 = cpe2.signatureComparisonString(); - return compare1.compareTo(compare2); - } - } - - class NormalAsciizComparator extends GeneralComparator { - /* (non-Javadoc) - * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object) - */ - public int compare(Object o1, Object o2) { - int classCompare = super.compare(o1, o2); - if(classCompare != 0) { - return classCompare; - } - - // Now that we've reached this point, we're - // comparing objects of the same class. Since - // they have the same class, we can make the - // statement that they're UTF8s, since only - // UTF8s will be added to a TreeSet with - // the NormalAsciizComparator. - CPUTF8 cpe1 = (CPUTF8)o1; - CPUTF8 cpe2 = (CPUTF8)o2; - - String compare1 = cpe1.normalComparisonString(); - String compare2 = cpe2.normalComparisonString(); - return compare1.compareTo(compare2); - } - } - - protected Comparator[] comparators = new Comparator[ClassConstantPool.NUM_DOMAINS]; - protected TreeSet[] sets = new TreeSet[ClassConstantPool.NUM_DOMAINS]; - - public ClassPoolSet() { - // These are the comparators in numeric order. - comparators[ClassConstantPool.DOMAIN_UNDEFINED] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_INTEGER] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_FLOAT] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_STRING] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_NORMALASCIIZ] = new NormalAsciizComparator(); - comparators[ClassConstantPool.DOMAIN_LONG] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_DOUBLE] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_CLASSREF] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_SIGNATUREASCIIZ] = new SignatureAsciizComparator(); - comparators[ClassConstantPool.DOMAIN_NAMEANDTYPE] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_FIELD] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_METHOD] = new PoolComparator(); - comparators[ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ] = new NormalAsciizComparator(); - - for(int index=0; index < ClassConstantPool.NUM_DOMAINS; index++) { - sets[index] = new TreeSet(comparators[index]); - } - } - - - /** - * Answer the index of the first set which contains the entry - * passed in as the parameter. - * @param entry ConstantPoolEntry to test for (with .contains()) - * @return int index of the first set containing the entry - */ - protected int findFirstSetContaining(ConstantPoolEntry entry) { - for(int index=0; index < ClassConstantPool.NUM_DOMAINS; index++) { - if(sets[index].contains(entry)) { - return index; - } - } - return -1; - } - - /** - * @param set - * @param testEntry - * @return - */ - protected ConstantPoolEntry getStoredEntry(int set, ConstantPoolEntry testEntry) { - TreeSet searchSet = sets[set]; - Iterator iterator = searchSet.iterator(); - while(iterator.hasNext()) { - ConstantPoolEntry storedEntry = (ConstantPoolEntry)iterator.next(); - if(0 == (comparators[set].compare(storedEntry, testEntry))) { - return storedEntry; - } - } - // Not found. Should not happen. - throw new Error("Tried to find a stored entry which wasn't in the set"); - } - - /** - * Add the parameter to the receiver. If the parameter - * already exists in a higher precedence domain, answer - * that. If the parameter exists in a lower precedence - * domain, remove it from the lower domain and add it to - * the higher one. - * - * @param entry ConstantPoolEntry to add - * @return ConstantPoolEntry from the domain where it's stored - */ - public ConstantPoolEntry add(Object entry) { - ConstantPoolEntry cpEntry = (ConstantPoolEntry)entry; - int entryDomain = cpEntry.getDomain(); - int currentStoredDomain = findFirstSetContaining(cpEntry); - - if(currentStoredDomain < 0) { - // Entry is not currently stored; just store it. - sets[entryDomain].add(cpEntry); - return cpEntry; - } - - if(currentStoredDomain <= entryDomain) { - // Entry is either already in this place - // or in a higher-precedence (numerically lower) - // domain; answer the value in the stored - // domain. - return getStoredEntry(currentStoredDomain, cpEntry); - } - - // Entry is in a lower-precedence (numerically higher) - // domain. Need to remove it from the lower-precedence - // domain and add it to the higher precedence domain. - sets[currentStoredDomain].remove(cpEntry); - sets[entryDomain].add(cpEntry); - return cpEntry; - } - - - public Iterator iterator() { - return partialIterator(ClassConstantPool.DOMAIN_INTEGER, ClassConstantPool.DOMAIN_ATTRIBUTEASCIIZ); - } - - /** - * Answer an iterator which iterates over the sets - * from sets[start] to sets[stop] only. - * @param start int the first set over which iteration will occur. - * @param stop int the last set over which iteration will occur - * @return Iterator - */ - public Iterator partialIterator(int start, int stop) { - // Make sure there's nothing in the undefined domain - if(sets[ClassConstantPool.DOMAIN_UNDEFINED].size() > 0) { - throw new Error("Trying to get iterator but have undefined elements"); - } - List someElements = new ArrayList(); - for(int index=start; index <= stop; index++) { - someElements.addAll(sets[index]); - } - return someElements.iterator(); - } -} Index: main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java =================================================================== --- main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java (revision 643602) +++ main/java/org/apache/harmony/pack200/bytecode/CPNameAndType.java (working copy) @@ -31,8 +31,6 @@ transient int nameIndex; - protected String cachedComparisonString = null; - public CPNameAndType(CPUTF8 name, CPUTF8 descriptor, int domain) { super(ConstantPoolEntry.CP_NameAndType); this.name = name; @@ -106,47 +104,4 @@ public int invokeInterfaceCount() { return 1 + SegmentUtils.countInvokeInterfaceArgs(descriptor.underlyingString()); } - - - /* (non-Javadoc) - * @see org.apache.harmony.pack200.bytecode.ConstantPoolEntry#comparisonString() - */ - public String comparisonString() { - // First come those things which don't have an - // associated signature. Then come the native signatures, - // then finally the class signatures. - // TODO: I think Character.MAX_VALUE is no longer the - // biggest character, what with the weird codepage thing - // 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) { - // it's a variable reference - comparisonBuffer.append(descriptor.underlyingString()); - } else { - // it's a signature. Append something that will - // make the comparison buffer bigger than all - // non-signature references. - comparisonBuffer.append(Character.MAX_VALUE); - // do the natives first - if(descriptorString.length() <= 4) { - // it's a native signature - comparisonBuffer.append(descriptor.underlyingString()); - } else { - // it's a non-native signature. Append something - // that will make the comparison buffer bigger - // than all native signature references. - comparisonBuffer.append(Character.MAX_VALUE); - comparisonBuffer.append(descriptor.underlyingString()); - } - } - comparisonBuffer.append(name.underlyingString()); - cachedComparisonString = comparisonBuffer.toString(); - return cachedComparisonString; - } } \ No newline at end of file