[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Experimental ClassLoader optimization patch
From: |
Jeroen Frijters |
Subject: |
Experimental ClassLoader optimization patch |
Date: |
Tue, 31 Dec 2002 09:46:46 +0100 |
Hi,
I experimented with a way to reduce exception instantation in the
URLClassLoader, to make class loading faster.
I've since figured out a way to avoid creating the stack traces for these
exceptions, so the real need (for me) for these patches is gone, but it
might be an interesting optimization never the less.
Here are the two patches (part of the URLClassLoader patch is not relevant
to this, sorry):
Index: ClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/ClassLoader.java,v
retrieving revision 1.22
diff -r1.22 ClassLoader.java
291c291
< c = findClass(name);
---
> c = findClassFast(name, e);
342a343,346
> }
> protected Class findClassFast(String name, ClassNotFoundException e)
throws ClassNotFoundException
> {
> return findClass(name);
Index: URLClassLoader.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/net/URLClassLoader.java,v
retrieving revision 1.13
diff -r1.13 URLClassLoader.java
289,291c289,290
< String cf = file.toString();
< String sep = File.separator;
< if (f.endsWith(sep) && !cf.endsWith(sep))
---
> String cf = file.toString().replace(File.separatorChar,
'/');
> if ((f.endsWith(File.separator) || f.endsWith("/")) &&
!cf.endsWith("/"))
793,794c792,807
< protected Class findClass(final String className)
< throws ClassNotFoundException
---
> protected Class findClassFast(String name, ClassNotFoundException e)
throws ClassNotFoundException
> {
> if(getClass() == URLClassLoader.class)
> {
> return findClassImpl(name, e);
> }
> else
> {
> return findClass(name);
> }
> }
> protected Class findClass(String className) throws
ClassNotFoundException
> {
> return findClassImpl(className, null);
> }
> private Class findClassImpl(final String className,
ClassNotFoundException e) throws ClassNotFoundException
800c813,818
< throw new ClassNotFoundException(className + " not found in " +
urls);
---
> {
> if (e == null)
> throw new ClassNotFoundException(className + " not found in " +
urls);
> else
> throw e;
> }
Regards,
Jeroen
- Experimental ClassLoader optimization patch,
Jeroen Frijters <=