From a4096978856a39dce1a1298d815509ddaad1b105 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 16 Apr 2010 21:15:34 +0000 Subject: [PATCH] 309336: faster isAssignableFrom --- .../aspectj/weaver/ReferenceTypeTestCase.java | 118 ++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/weaver5/java5-testsrc/org/aspectj/weaver/ReferenceTypeTestCase.java b/weaver5/java5-testsrc/org/aspectj/weaver/ReferenceTypeTestCase.java index da5fef342..5fbc530e7 100644 --- a/weaver5/java5-testsrc/org/aspectj/weaver/ReferenceTypeTestCase.java +++ b/weaver5/java5-testsrc/org/aspectj/weaver/ReferenceTypeTestCase.java @@ -11,11 +11,14 @@ * ******************************************************************/ package org.aspectj.weaver; +import java.rmi.RemoteException; import java.util.ArrayList; import java.util.List; +import java.util.Random; import junit.framework.TestCase; +import org.aspectj.util.PartialOrder; import org.aspectj.weaver.bcel.BcelWorld; // test cases for Adrian's additions to ReferenceType @@ -60,6 +63,7 @@ public class ReferenceTypeTestCase extends TestCase { BcelWorld world; + @Override public void setUp() throws Exception { super.setUp(); world = new BcelWorld(); @@ -555,7 +559,121 @@ public class ReferenceTypeTestCase extends TestCase { arrayListOfString = (ArrayList) listOfSomething; assertFalse(ajArrayListOfString.isAssignableFrom(ajListOfSomething)); assertTrue(ajArrayListOfString.isCoerceableFrom(ajListOfSomething)); + } + + // copy of the real one in BcelClassWeaver + public static class IfaceInitList implements PartialOrder.PartialComparable { + final ResolvedType onType; + List list = new ArrayList(); + + IfaceInitList(ResolvedType onType) { + this.onType = onType; + } + + public int compareTo(Object other) { + IfaceInitList o = (IfaceInitList) other; + if (onType.isAssignableFrom(o.onType)) { + return +1; + } else if (o.onType.isAssignableFrom(onType)) { + return -1; + } else { + return 0; + } + } + + public int fallbackCompareTo(Object other) { + return 0; + } + } + + public void testExpensiveAssignableChecks_309336() { + List objects = new ArrayList(); + ReferenceType rcb = resolve("Lorg/aspectj/weaver/ReferenceTypeTestCase$Foo;"); + ReferenceType i = (ReferenceType) rcb.getDeclaredInterfaces()[0]; + while (i != null && i.isInterface()) { + objects.add(Math.abs(new Random(12).nextInt(objects.size() + 1)), new IfaceInitList(i)); + ResolvedType[] rt = i.getDeclaredInterfaces(); + i = rt == null || rt.length == 0 ? null : (ReferenceType) rt[0]; + } + for (int loop = 0; loop < 10; loop++) { + // ReferenceType.r = 0; + long stime = System.nanoTime(); + for (int j = 0; j < 10; j++) { + List objects2 = new ArrayList(); + objects2.addAll(objects); + PartialOrder.sort(objects2); + } + long etime = System.nanoTime(); + System.err.println("Took " + ((etime - stime) / 1000000) + "ms: calls ");// + ReferenceType.r); + } + // could do with asserting something... basically we are just checking we didn't run out of memory doing the sorts above! + } + + public interface Operator14 { + T execute(String aArg) throws E1, E2, E3, E4, E5, E6, E7, E8, E9, E10, E11, E12, E13, E14, RemoteException; + } + + public interface Operator13 + extends Operator14 { + } + + public interface Operator12 + extends Operator13 { + } + + public interface Operator11 + extends Operator12 { + } + + public interface Operator10 + extends Operator11 { + + } + public interface Operator9 + extends Operator10 { + } + + public interface Operator8 + extends Operator9 { + } + + public interface Operator7 + extends Operator8 { + } + + public interface Operator6 + extends Operator7 { + + } + + public interface Operator5 + extends Operator6 { + } + + public interface Operator4 extends + Operator5 { + } + + public interface Operator3 extends + Operator4 { + } + + public interface Operator2 extends Operator3 { + + } + + public interface Operator1 extends Operator2 { + } + + public interface Operator extends Operator1 { + } + + class Foo implements Operator { + public String execute(String aArg) throws NullPointerException, RemoteException { + System.out.println("Doh!"); + return aArg; + } } // public void testAssignable_method_m5() { -- 2.39.5