On 26/04/2008, Ian Rogers <[EMAIL PROTECTED]> wrote: > Hi, > > the attached patch moves exception handling code out of the common case for > elementAt of both java.util.Vector and java.util.elementAt, this helps JIT > compilation inline the common non-exception throwing case (and avoid expense > incurred by considering StringBuilders, etc.). Other than fixing coding > convention issues, are there any objections to this change? > > Thanks, > Ian > -- > http://www.cs.man.ac.uk/~irogers/ > > Index: java/util/ArrayList.java > =================================================================== > RCS file: > /sources/classpath/classpath/java/util/ArrayList.java,v > retrieving revision 1.31 > diff -u -r1.31 ArrayList.java > --- java/util/ArrayList.java 10 Dec 2006 20:25:46 -0000 1.31 > +++ java/util/ArrayList.java 23 Apr 2008 14:17:43 -0000 > @@ -472,8 +472,7 @@ > // use of a negative index will cause an > ArrayIndexOutOfBoundsException, > // a subclass of the required exception, with no effort on our part. > if (index > size) > - throw new IndexOutOfBoundsException("Index: " + > index + ", Size: " > - + size); > + raiseBoundsError(index); > } > > /** > @@ -488,11 +487,23 @@ > // use of a negative index will cause an > ArrayIndexOutOfBoundsException, > // a subclass of the required exception, with no effort on our part. > if (index >= size) > - throw new IndexOutOfBoundsException("Index: " + > index + ", Size: " > - + size); > + raiseBoundsError(index); > } > > /** > + * Raise the ArrayIndexOfOutBoundsException. > + * @param index the index of the access > + * @throws IndexOutOfBoundsException unconditionally > + */ > + private void raiseBoundsError(int index) > + { > + // Implementaion note: put in a separate method to make the JITs > job easier > + // (separate common from uncommon code at method boundaries when > trivial to do so). > + throw new IndexOutOfBoundsException("Index: " + > index + ", Size: " + size); > + } > + > + > + /** > * Remove from this list all elements contained in the given collection. > * This is not public, due to Sun's API, but this performs in linear > * time while the default behavior of AbstractList would be quadratic. > Index: java/util/Vector.java > =================================================================== > RCS file: > /sources/classpath/classpath/java/util/Vector.java,v > retrieving revision 1.31 > diff -u -r1.31 Vector.java > --- java/util/Vector.java 12 Mar 2008 23:39:51 -0000 1.31 > +++ java/util/Vector.java 23 Apr 2008 14:17:43 -0000 > @@ -909,7 +909,7 @@ > // use of a negative index will cause an ArrayIndexOutOfBoundsException > // with no effort on our part. > if (index > elementCount) > - throw new ArrayIndexOutOfBoundsException(index + " > > " + elementCount); > + raiseBoundsError(index, " > "); > } > > /** > @@ -924,10 +924,23 @@ > // use of a negative index will cause an ArrayIndexOutOfBoundsException > // with no effort on our part. > if (index >= elementCount) > - throw new ArrayIndexOutOfBoundsException(index + " > >= " + elementCount); > + raiseBoundsError(index, " >= "); > } > > /** > + * Raise the ArrayIndexOfOutBoundsException. > + * @param index the index of the access > + * @param operator the operator to include in the error message > + * @throws IndexOutOfBoundsException unconditionally > + */ > + private void raiseBoundsError(int index, String operator) > + { > + // Implementaion note: put in a separate method to make the JITs > job easier > + // (separate common from uncommon code at method boundaries when > trivial to do so). > + throw new ArrayIndexOutOfBoundsException(index + > operator + elementCount); > + } > + > + /** > * Serializes this object to the given stream. > * > * @param s the stream to write to > > >
Looks okay, overlooking the obvious formatting issues. Is there an overhead to the method call or would most VMs inline this? -- Andrew :-) Support Free Java! Contribute to GNU Classpath and the OpenJDK http://www.gnu.org/software/classpath http://openjdk.java.net PGP Key: 94EFD9D8 (http://subkeys.pgp.net) Fingerprint: F8EF F1EA 401E 2E60 15FA 7927 142C 2591 94EF D9D8