From 5197e98fb194c6fc24627bd9c6596afe555c98f1 Mon Sep 17 00:00:00 2001 From: Christian Date: Tue, 30 Oct 2012 21:17:17 -0400 Subject: [PATCH] Negatively cache failed class lookups, should help with @SideOnly performance issues. --- .../fml/relauncher/RelaunchClassLoader.java | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java b/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java index f0f8a68d7..ea33e45ff 100644 --- a/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java +++ b/fml/common/cpw/mods/fml/relauncher/RelaunchClassLoader.java @@ -27,6 +27,7 @@ public class RelaunchClassLoader extends URLClassLoader private List transformers; private Map cachedClasses; + private Set invalidClasses; private Set classLoaderExceptions = new HashSet(); private Set transformerExceptions = new HashSet(); @@ -37,6 +38,7 @@ public class RelaunchClassLoader extends URLClassLoader this.sources = new ArrayList(Arrays.asList(sources)); this.parent = getClass().getClassLoader(); this.cachedClasses = new HashMap(1000); + this.invalidClasses = new HashSet(1000); this.transformers = new ArrayList(2); // ReflectionHelper.setPrivateValue(ClassLoader.class, null, this, "scl"); Thread.currentThread().setContextClassLoader(this); @@ -69,6 +71,10 @@ public class RelaunchClassLoader extends URLClassLoader @Override public Class findClass(String name) throws ClassNotFoundException { + if (invalidClasses.contains(name)) + { + throw new ClassNotFoundException(name); + } // NEI/CCC compatibility code if (excludedPackages.length != 0) { @@ -98,9 +104,17 @@ public class RelaunchClassLoader extends URLClassLoader { if (name.startsWith(st)) { - Class cl = super.findClass(name); - cachedClasses.put(name, cl); - return cl; + try + { + Class cl = super.findClass(name); + cachedClasses.put(name, cl); + return cl; + } + catch (ClassNotFoundException e) + { + invalidClasses.add(name); + throw e; + } } } @@ -123,6 +137,7 @@ public class RelaunchClassLoader extends URLClassLoader } catch (Throwable e) { + invalidClasses.add(name); throw new ClassNotFoundException(name, e); } }