diff options
author | Andy Clement <aclement@pivotal.io> | 2017-09-28 16:03:17 -0700 |
---|---|---|
committer | Andy Clement <aclement@pivotal.io> | 2017-09-28 16:03:17 -0700 |
commit | ba551b09e4c873f30c0675193e70e0a0eb62c3ca (patch) | |
tree | b28159ecf6270fde24fc95c24db0f1dae35b6ec0 /weaver5/java5-testsrc | |
parent | b7e4aff1c15a0984d4ca772ffb82cdd9b0f6fa57 (diff) | |
download | aspectj-ba551b09e4c873f30c0675193e70e0a0eb62c3ca.tar.gz aspectj-ba551b09e4c873f30c0675193e70e0a0eb62c3ca.zip |
Fixes Bug 525293 - Spring AOP could be faster
Multiple changes here:
- annotation unpacking is smarter and if it only needs runtime
retention annotations it uses reflection and doesn't unpack the
bytes to discover class level retention annotations.
- Reflection worlds are shared if for the same classloader.
Diffstat (limited to 'weaver5/java5-testsrc')
-rw-r--r-- | weaver5/java5-testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java b/weaver5/java5-testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java index 6c65c1e64..db3e44711 100644 --- a/weaver5/java5-testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java +++ b/weaver5/java5-testsrc/org/aspectj/weaver/reflect/ReflectionWorldTest.java @@ -8,17 +8,21 @@ * ******************************************************************/ package org.aspectj.weaver.reflect; +import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Type; - +import java.net.URL; +import java.net.URLClassLoader; import java.util.List; +import java.util.Map; -import org.aspectj.weaver.ResolvedType; -import org.aspectj.weaver.UnresolvedType; -import org.aspectj.weaver.World; import org.aspectj.bridge.IMessageHandler; import org.aspectj.weaver.ReferenceType; import org.aspectj.weaver.ResolvedMember; +import org.aspectj.weaver.ResolvedType; +import org.aspectj.weaver.UnresolvedType; +import org.aspectj.weaver.WeakClassLoaderReference; +import org.aspectj.weaver.World; import org.aspectj.weaver.bcel.BcelWorld; import junit.framework.TestCase; @@ -35,6 +39,64 @@ public class ReflectionWorldTest extends TestCase { assertNotNull(rt); assertEquals("Ljava/lang/Object;", rt.getSignature()); } + + public void testReflectionWorldFactory() throws Exception { + ClassLoader parent = getClass().getClassLoader(); + ClassLoader cl1 = new URLClassLoader(new URL[] {}, parent); + ClassLoader cl2 = new URLClassLoader(new URL[] {}, parent); + + WeakClassLoaderReference wcl1 = new WeakClassLoaderReference(cl1); + WeakClassLoaderReference wcl2 = new WeakClassLoaderReference(cl2); + ReflectionWorld a = ReflectionWorld.getReflectionWorldFor(wcl1); + + ResolvedType stringClass1 = a.resolve(String.class); + assertNotNull(stringClass1); + + ReflectionWorld b = ReflectionWorld.getReflectionWorldFor(wcl1); + + // They should be the same because the classloader has not gone away + assertTrue(a==b); + + cl1 = null; + for (int i=0;i<100;i++) { + System.gc(); // How robust is it that this should be causing the reference to be collected? + } + b = ReflectionWorld.getReflectionWorldFor(wcl1); + + assertFalse(a==b); + + cl1 = new URLClassLoader(new URL[] {}, parent); + wcl1 = new WeakClassLoaderReference(cl1); + a = ReflectionWorld.getReflectionWorldFor(wcl1); + b = ReflectionWorld.getReflectionWorldFor(wcl2); + assertFalse(a==b); + + Field declaredField = ReflectionWorld.class.getDeclaredField("rworlds"); + declaredField.setAccessible(true); + Map worlds = (Map)declaredField.get(null); + assertEquals(2, worlds.size()); + + cl2 = null; + for (int i=0;i<100;i++) { + System.gc(); // How robust is it that this should be causing the reference to be collected? + } + ReflectionWorld.getReflectionWorldFor(wcl1); // need to call this to trigger tidyup + assertEquals(1, worlds.size()); + + cl1 = null; + for (int i=0;i<100;i++) { + System.gc(); // How robust is it that this should be causing the reference to be collected? + } + ReflectionWorld.getReflectionWorldFor(wcl1); // need to call this to trigger tidyup + assertEquals(0, worlds.size()); + + cl1 = new URLClassLoader(new URL[] {}, parent); + wcl1 = new WeakClassLoaderReference(cl1); + ReflectionWorld reflectionWorldFor = ReflectionWorld.getReflectionWorldFor(wcl1); + assertEquals(1, worlds.size()); + ReflectionWorld.cleanUpWorlds(); + assertEquals(0, worlds.size()); + } public void testArrayTypes() { IReflectionWorld world = new ReflectionWorld(getClass().getClassLoader()); |