[jboss-cvs] JBossAS SVN: r64582 - in branches: leaks/aop and 7 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 14 14:08:11 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-08-14 14:08:10 -0400 (Tue, 14 Aug 2007)
New Revision: 64582

Added:
   branches/leaks/
Modified:
   branches/leaks/aop/build-tests-jdk50.xml
   branches/leaks/aop/src/main/org/jboss/aop/Advisor.java
   branches/leaks/aop/src/main/org/jboss/aop/AspectManager.java
   branches/leaks/aop/src/main/org/jboss/aop/ClassAdvisor.java
   branches/leaks/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java
   branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
   branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
   branches/leaks/aop/src/main/org/jboss/aop/classpool/AOPClassPoolRepository.java
   branches/leaks/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
   branches/leaks/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
   branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsPOJO.java
   branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsTestCase.java
   branches/leaks/aop/src/test/org/jboss/test/aop/memoryleaks/MemoryLeakTestCase.java
Log:
made a copy

Copied: branches/leaks (from rev 64569, projects/aop/trunk)

Modified: branches/leaks/aop/build-tests-jdk50.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk50.xml	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/build-tests-jdk50.xml	2007-08-14 18:08:10 UTC (rev 64582)
@@ -249,7 +249,6 @@
          <src path="${source.tests.java}"/>
          <classpath refid="test.classpath"/>
          <include name="**/*.java"/>
-         <exclude name="org/jboss/test/aop/memoryleaks/**/*.java"/>
       </javac>
       <jar destfile="${build.tests.classes}/org/jboss/test/aop/jdk15/dynamic/common/scenario.jar"
         basedir="${build.tests.classes}" includes="org/jboss/test/aop/jdk15/dynamic/common/scenario/**"/>
@@ -1470,7 +1469,7 @@
 
    <target name="memory-tests" depends="compile-test-classes">
       <taskdef name="annotationc" classname="org.jboss.aop.ant.AnnotationC" classpathref="jboss.aop.classpath"/>
-
+<!--
       <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="annotatedcflow"/>
          <param name="case" value="AnnotatedCFlowTestCase"/>
@@ -1479,10 +1478,12 @@
          <param name="test" value="annotatedparams"/>
          <param name="case" value="AnnotatedParamsTester"/>
       </antcall>
+-->
       <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="args"/>
-         <param name="case" value="ArgsTestCase"/>
+         <param name="case" value="ArgumentsTestCase"/>
       </antcall>
+<!--
       <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="basic"/>
          <param name="case" value="AOPTester"/>
@@ -1492,6 +1493,57 @@
          <param name="case" value="ConfigTester"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafter"/>
+         <param name="case" value="BeforeAfterThrowingTestCase"/>
+      </antcall>
+-->
+      <echo>REMEMBER TO ENABLE THE REST OF THE TESTS</echo>
+      <!--
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="ArgsTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="ArgTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="CallerTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="JoinPointTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="OverloadedAdviceTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="ReturnTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="TargetTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterArgs"/>
+         <param name="case" value="ThrownTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterthrowingscoped"/>
+         <param name="case" value="BeforeAfterThrowingScopedTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="beforeafterthrowingstack"/>
+         <param name="case" value="BeforeAfterThrowingStackTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="bridgemethod"/>
+         <param name="case" value="BridgeMethodWeavingTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="callerargs"/>
          <param name="case" value="CallerArgsTestCase"/>
       </antcall>
@@ -1512,20 +1564,48 @@
          <param name="case" value="DotInPointcutNameTestCase"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="dynamicgenadvisor"/>
+         <param name="case" value="DynamicTester"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="extender"/>
+         <param name="case" value="ExtenderTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="field"/>
+         <param name="case" value="FieldTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="implementz"/>
          <param name="case" value="ImplementsTester"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="inforesolve"/>
+         <param name="case" value="InfoResolveAnnotationTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="instanceofannotated"/>
          <param name="case" value="InstanceOfAnnotatedTester"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="instanceofintroduced"/>
+         <param name="case" value="InstanceOfIntroducedTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="introduction"/>
          <param name="case" value="IntroductionTester"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="invoketarget"/>
+         <param name="case" value="InvokeTargetTestCase"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
+         <param name="test" value="marshalling"/>
+         <param name="case" value="MarshallingTester"/>
+      </antcall>
+      <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="override"/>
-         <param name="case" value="OverrideTestCase"/>
+         <param name="case" value="GenAdvisorOverrideTestCase"/>
       </antcall>
       <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="perjoinpoint"/>
@@ -1534,7 +1614,7 @@
       <antcall  target="memory-test" inheritRefs="true">
          <param name="test" value="scope"/>
          <param name="case" value="ScopeTestCase"/>
-      </antcall>
+      </antcall>-->
    </target>
 
    <target name="memory-test" depends="init">
@@ -1542,6 +1622,9 @@
       <property name="aoppath" value="${source.res}/test/${test}/jboss-aop.xml"/>
       <property name="testcase" value="org.jboss.test.aop.${test}.${case}"/>
 
+      <condition property="extra.classes" value="${extraClasses}" else="">
+         <isset property="extraClasses"/>
+      </condition>
 
       <aopc compilerclasspathref="aopc.task.classpath">
          <classpath refid="aopc.task.classpath"/>
@@ -1558,15 +1641,18 @@
       <echo>${testcase}</echo>
       <junit printsummary="yes" fork="yes" haltonfailure="no">
          <sysproperty key="jboss.aop.path" value="${aoppath}"/>
-         <sysproperty key="test.to.run" value="${testcase}"/>
+         <sysproperty key="test.to.run" value="${testcase}"/> 
          <sysproperty key="leak.report.dir" value="${report.dir}"/>
+         <sysproperty key="extraClasses" value="${extra.classes}"/>
          <classpath refid="test.classpath"/>
          <classpath path="${build.tests.classes}"/>
          <jvmarg value="-agentlib:jbossAgent"/>
-         <formatter usefile="true" type="xml" extension="-${testcase}.xml"/>
+         <sysproperty key="jboss-junit-configuration" value="${testcase}"/>
+         <formatter classname="org.jboss.ant.taskdefs.XMLJUnitMultipleResultFormatter" extension="-${testcase}.xml"/>
          <formatter usefile="true" type="plain" extension="-${testcase}.txt"/>
          <test fork="yes" name="org.jboss.test.aop.memoryleaks.MemoryLeakTestCase" todir="${report.dir}"/>
       </junit>
+
    </target>
 
 

Modified: branches/leaks/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/Advisor.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -1207,6 +1207,11 @@
             defs[i].unregisterAdvisor(this);
          }
       }
+      
+      if (methodInterceptors != null)
+      {
+         methodInterceptors.clear();
+      }
    }
    
    /**

Modified: branches/leaks/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/AspectManager.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -1987,6 +1987,11 @@
          subscribedSubDomains.remove(domain);
       }
    }
+   
+   public Map getSubscribedSubDomains()
+   {
+      return subscribedSubDomains;
+   }
 
    private Advisor getAdvisorFromAdvisorsKeySetIterator(Iterator it)
    {

Modified: branches/leaks/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/ClassAdvisor.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -1690,7 +1690,23 @@
       }
       throw new IllegalStateException("Unknown Invocation type: " + invocation.getClass().getName());
    }
-
+   
+   @Override
+   public void cleanup()
+   {
+      super.cleanup();
+      if (methodByMethodData != null)
+      {
+         methodByMethodData.cleanup();
+         methodByMethodData = null;
+      }
+      if (conByMethodData != null)
+      {
+         conByMethodData.cleanup();
+         conByMethodData = null;
+      }
+   }
+   
    // interceptor chain observer
    private InterceptorChainObserver interceptorChainObserver;
 
@@ -2220,6 +2236,13 @@
          MethodByMethodInfo info = (MethodByMethodInfo) calledMethods.get(calledMethodHash);
          return info;
       }
+
+      public void cleanup()
+      {
+         methodCalledByMethodBindings.clear();
+         backrefMethodCalledByMethodBindings.clear();
+         methodCalledByMethodInterceptors.clear();
+      }
    }
    
    private class ConByMethodData
@@ -2462,5 +2485,10 @@
          finalizeConCalledByMethodInterceptorChain(info);
       }
 
+      public void cleanup()
+      {
+         conCalledByMethodBindings.clear();
+         conCalledByMethodInterceptors.clear();
+      }
    }
 }
\ No newline at end of file

Modified: branches/leaks/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -110,6 +110,27 @@
       advisorStrategy = new InstanceAdvisorStrategy(parent);
    }
 
+   @Override
+   public void cleanup()
+   {
+      System.out.println("===========> CLeaning advisor " + this.getClazz().getName());
+      super.cleanup();
+      methodInfos = null;
+      advisorStrategy = null;
+      
+      Map subscribedSubDomains = getManager().getSubscribedSubDomains();
+      System.out.println("---> Domains: " + subscribedSubDomains.size());
+      synchronized (subscribedSubDomains)
+      {
+         for (Iterator it = subscribedSubDomains.values().iterator() ; it.hasNext() ; )
+         {
+            GeneratedAdvisorDomain manager = (GeneratedAdvisorDomain)it.next();
+            Map advisors = manager.getAdvisors();
+            System.out.println("---> Advisors: " + advisors);
+         }
+      }
+   }
+
    protected void initialise(Class clazz, AspectManager manager)
    {
       advisorStrategy.initialise(clazz, manager);
@@ -1679,4 +1700,5 @@
    enum OldInfoMaps{
       INFOS, FIELD_READ_INFOS, CONSTRUCTION_INFOS;
    }
+
 }

Modified: branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceInfo.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -1,10 +1,13 @@
 package org.jboss.aop.advice.annotation;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 
 import org.jboss.aop.advice.AdviceMethodProperties;
 import org.jboss.aop.advice.annotation.AdviceMethodFactory.ReturnType;
 import org.jboss.aop.advice.annotation.assignability.DegreeAlgorithm;
+import org.jboss.aop.util.reference.MethodPersistentReference;
+import org.jboss.aop.util.reference.PersistentReference;
 
 /**
  * Contains information about an advice method and its matching process.
@@ -17,10 +20,10 @@
    // the righest the rank the better this advice is
    protected int rank;
    // advice method
-   protected Method method;
+   private MethodPersistentReference method;
    // since method.getParameterTypes creates a vector, better store this information
    // instead of calling repeatedly getParameterTypes
-   protected Class<?>[] parameterTypes;
+   protected WeakReference<Class>[] parameterTypes;
    
    /**
     * Creates an advice info.
@@ -30,11 +33,21 @@
     */
    protected AdviceInfo(Method method, int rank)
    {
-      this.method = method;
+      this.method = new MethodPersistentReference(method, PersistentReference.REFERENCE_SOFT);
       this.rank = rank;
-      this.parameterTypes = method.getParameterTypes();
+      Class[] paramTypes = method.getParameterTypes();
+      this.parameterTypes = new WeakReference[paramTypes.length];
+      for (int i = 0 ; i < paramTypes.length ; i++)
+      {
+         parameterTypes[i] = new WeakReference(paramTypes[i]);
+      }
    }
    
+   protected Method getMethod()
+   {
+      return method.getMethod();
+   }
+   
    /**
     * Returns the distance in hierarchy between the annotated parameter identified by
     * <code>annotationIndex</code>, and the expected type of this parameter.
@@ -47,7 +60,7 @@
     */
    public final short getReturnAssignabilityDegree(AdviceMethodProperties properties)
    {
-      Class returnType = this.method.getReturnType();
+      Class returnType = getMethod().getReturnType();
       if (returnType == void.class)
       {
          return DegreeAlgorithm.NOT_ASSIGNABLE_DEGREE;

Modified: branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AdviceMethodFactory.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -133,13 +133,18 @@
                   public boolean matches(AdviceMethodProperties properties,
                         ReturnType adviceReturn)
                   {
-                     if(parameterTypes[0].isAssignableFrom(properties.getInvocationType()))
+                     Class param = parameterTypes[0].get();
+                     if (param == null)
                      {
+                        return false;
+                     }
+                     if(param.isAssignableFrom(properties.getInvocationType()))
+                     {
                         return true;
                      }
                      if (AspectManager.verbose)
                      {
-                        appendNewMatchingMessage(method, "argument 0 is not assignable from ");
+                        appendNewMatchingMessage(getMethod(), "argument 0 is not assignable from ");
                         appendMatchingMessage(properties.getInvocationType());
                      }
                      return false;
@@ -150,12 +155,12 @@
                   public short getAssignabilityDegree(int typeIndex,
                         boolean isContextRule, AdviceMethodProperties properties)
                   {
-                     return DEGREE.getAssignabilityDegree(properties.getInvocationType(), parameterTypes[0]);
+                     return DEGREE.getAssignabilityDegree(properties.getInvocationType(), parameterTypes[0].get());
                   }
                   
                   public void assignAdviceInfo(AdviceMethodProperties properties)
                   {
-                     properties.setFoundProperties(this.method, new int[]{
+                     properties.setFoundProperties(this.getMethod(), new int[]{
                            AdviceMethodProperties.INVOCATION_ARG});
                   }
                };
@@ -573,4 +578,4 @@
    {
       boolean matches(AdviceMethodProperties p);
    }
-}
\ No newline at end of file
+}

Modified: branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/advice/annotation/AnnotatedParameterAdviceInfo.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -135,6 +135,7 @@
          }
       }
       
+      Method method = getMethod();
       if (method.getReturnType() == void.class && returnType == ReturnType.NOT_VOID
             && properties.getJoinpointReturnType() != void.class)
       {
@@ -273,7 +274,7 @@
       {
          contextParamTypes[i].assignParameterInfo(args);
       }
-      properties.setFoundProperties(this.method, args);
+      properties.setFoundProperties(this.getMethod(), args);
    }
    
    /**
@@ -298,7 +299,7 @@
          else
          {
             types[i] = new MultipleParameterType(rules[i],
-                  method.getParameterTypes().length);
+                  getMethod().getParameterTypes().length);
          }
       }
       return types;
@@ -315,6 +316,7 @@
     */
    private void applyRules(AdviceMethodProperties properties) throws ParameterAnnotationRuleException
    {
+      Method method = getMethod();
       Annotation[][] paramAnnotations = method.getParameterAnnotations();
       ParameterAnnotationType typeFound;
       boolean nullifyRank = false;
@@ -463,12 +465,9 @@
       {
          if (rule.isMandatory() && !isSet())
          {
-            AdviceMethodFactory.appendNewMatchingMessage(method, "mandatory ");
+            AdviceMethodFactory.appendNewMatchingMessage(getMethod(), "mandatory ");
             AdviceMethodFactory.appendMatchingMessage(rule);
             AdviceMethodFactory.appendMatchingMessage("-annotated parameter  not found");
-//            throw new ParameterAnnotationRuleException(
-//                  "Mandatory " + rule + "-annotated parameter  not found on " +
-//                  adviceType + " advice method '" + method + "'");
             return false;
          }
          return internalValidate(properties);
@@ -545,7 +544,7 @@
             throw new ParameterAnnotationRuleException(
                   "Found more than one occurence of '"
                   + rule + "' on parameters of " + adviceType + " advice method '" +
-                  method + "'");
+                  getMethod() + "'");
          }
          this.index = parameterIndex;
          rank += rule.getRankGrade();
@@ -558,6 +557,7 @@
       
       public final boolean internalValidate(AdviceMethodProperties properties)
       {
+         Method method = getMethod();
          try
          {
          if (index != -1 && !AssignabilityAlgorithm.VARIABLE_TARGET.isAssignable(
@@ -597,7 +597,7 @@
             return -1;
          }
          return DEGREE.getAssignabilityDegree(
-               method.getGenericParameterTypes()[this.index],
+               getMethod().getGenericParameterTypes()[this.index],
                (Type) rule.getAssignableFrom(properties));
       }
       
@@ -635,7 +635,7 @@
          {
             throw new RuntimeException(
                   "Unexpected call to setIndex method during processing of '" +
-                  method + "'");
+                  getMethod() + "'");
          }
          indexes[indexesLength][0] = index;
          originalIndexValues[indexesLength] = ((Arg) annotation).index();
@@ -651,6 +651,7 @@
       
       public final boolean internalValidate(AdviceMethodProperties properties)
       {
+         Method method = getMethod();
          Type[] expectedTypes = (Type[]) rule.getAssignableFrom(properties);
          Type[] adviceTypes = null;
          try
@@ -797,6 +798,7 @@
          {
             return -1;
          }
+         Method method = getMethod();
          Type[] expectedTypes = (Type[]) rule.getAssignableFrom(properties);
          short level = 0;
          for (int i = 0; i < indexesLength; i++)

Modified: branches/leaks/aop/src/main/org/jboss/aop/classpool/AOPClassPoolRepository.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/classpool/AOPClassPoolRepository.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/classpool/AOPClassPoolRepository.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -33,6 +33,7 @@
 
 import org.jboss.aop.Advisor;
 import org.jboss.aop.AspectManager;
+import org.jboss.aop.instrument.GeneratedAdvisorInstrumentor;
 import org.jboss.aop.instrument.Instrumentor;
 import org.jboss.aop.util.logging.AOPLogger;
 import org.jboss.logging.Logger;
@@ -197,6 +198,7 @@
             while (it.hasNext())
             {
                Object clazz = it.next();
+
                synchronized (manager.getAdvisors())
                {
                   WeakReference ref = (WeakReference)manager.getAdvisors().get(clazz);
@@ -210,27 +212,55 @@
                      }
                   }
                   Class advisedClass = (Class)clazz;
-                  try
-                  {
-                     //The static advisor field should be the only remaining hard reference to the advisor
-                     Field f = advisedClass.getDeclaredField(Instrumentor.HELPER_FIELD_NAME);
-                     f.setAccessible(true);
-                     f.set(null, null);
-                  }
-                  catch(NoSuchFieldException e)
-                  {
-                     logger.warn("Error unsetting advisor for " + advisedClass.getName() + " " + e);
-                  }
-                  catch(IllegalAccessException e)
-                  {
-                     logger.warn("Error unsetting advisor for " + advisedClass.getName() + " " + e);
-                  }
+                  unsetAdvisorFieldAndCleanup(advisedClass, Instrumentor.HELPER_FIELD_NAME, true);
                }
             }
          }
       }
    }
 
+   private void unsetAdvisorFieldAndCleanup(Class clazz, String fieldName, boolean warn)
+   {
+      Class advisedClass = (Class)clazz;
+      
+      Field f = null;
+      try
+      {
+         //The static advisor field should be the only remaining hard reference to the advisor
+         f = advisedClass.getDeclaredField(Instrumentor.HELPER_FIELD_NAME);
+         f.setAccessible(true);
+      }
+      catch(NoSuchFieldException e)
+      {
+         if (warn)
+         {
+            logger.warn("Error unsetting advisor for " + advisedClass.getName() + " " + e);
+         }
+      }
+
+      Advisor advisor = null;
+      try
+      {
+         advisor = (Advisor)f.get(null);
+         if (advisor != null)
+         {
+            advisor.cleanup();
+         }
+      }
+      catch(IllegalAccessException e)
+      {
+         logger.warn("Error getting advisor from field for " + advisedClass.getName() + " " + e);
+      }
+
+      try
+      {
+         f.set(null, null);
+      }
+      catch(IllegalAccessException e)
+      {
+         logger.warn("Error unsetting advisor for " + advisedClass.getName() + " " + e);
+      }
+   }
    
    interface UnregisterClassLoaderAction
    {

Modified: branches/leaks/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -52,8 +52,8 @@
 public class GeneratedAdvisorInstrumentor extends Instrumentor
 {
    //field names in advised class
-   private static final String CURRENT_ADVISOR = "currentAdvisor$aop";
-   private  static final String INSTANCE_ADVISOR = "instanceAdvisor$aop";
+   public static final String CURRENT_ADVISOR = "currentAdvisor$aop";
+   public  static final String INSTANCE_ADVISOR = "instanceAdvisor$aop";
    private static final String GET_CURRENT_ADVISOR_NAME = "getCurrentAdvisor$aop";
    public static final String GET_CURRENT_ADVISOR = GET_CURRENT_ADVISOR_NAME + "()";
 

Modified: branches/leaks/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/main/org/jboss/aop/proxy/container/ContainerProxyFactory.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -815,7 +815,7 @@
    private void copyAnnotations(CtMethod src, CtMethod dest) throws NotFoundException
    {
       javassist.bytecode.MethodInfo srcInfo = src.getMethodInfo2();
-      javassist.bytecode.MethodInfo destInfo = dest.getMethodInfo2();
+      javassist.bytecode.MethodInfo destInfo = dest.getMethodInfo();
       copyAnnotations(srcInfo, destInfo, AnnotationsAttribute.invisibleTag);
       copyAnnotations(srcInfo, destInfo, AnnotationsAttribute.visibleTag);
 
@@ -854,7 +854,7 @@
    private void copyAnnotations(CtClass src, CtClass dest) throws NotFoundException
    {
       ClassFile srcFile = src.getClassFile2();
-      ClassFile destFile = dest.getClassFile2();
+      ClassFile destFile = dest.getClassFile();
       copyAnnotations(srcFile, destFile, AnnotationsAttribute.invisibleTag);
       copyAnnotations(srcFile, destFile, AnnotationsAttribute.visibleTag);
    }
@@ -872,7 +872,7 @@
    private void copySignature(CtMethod src, CtMethod dest)
    {
       javassist.bytecode.MethodInfo srcInfo = src.getMethodInfo2();
-      javassist.bytecode.MethodInfo destInfo = dest.getMethodInfo2();
+      javassist.bytecode.MethodInfo destInfo = dest.getMethodInfo();
       
       SignatureAttribute sig = (SignatureAttribute)srcInfo.getAttribute(SignatureAttribute.tag);
       if (sig != null)
@@ -884,7 +884,7 @@
    private void copySignature(CtClass src, CtClass dest)
    {
       ClassFile srcFile = src.getClassFile2();
-      ClassFile destFile = dest.getClassFile2();
+      ClassFile destFile = dest.getClassFile();
       
       SignatureAttribute sig = (SignatureAttribute)srcFile.getAttribute(SignatureAttribute.tag);
       if (sig != null)

Modified: branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsPOJO.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgumentsPOJO.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsPOJO.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -89,7 +89,7 @@
    
    public ArgumentsPOJO2(Call call, int arg)
    {
-      this.arg = call.perform(arg);
+//      this.arg = call.perform(arg);
    }
    
    public int method(int arg)
@@ -122,32 +122,67 @@
 
 abstract class Call
 {
-   public static final Call CONSTRUCTOR = new Call("CONSTRUCTOR")
+   public static Call getConstructor()
    {
-      public int perform(int arg)
+      return new Call("CONSTRUCTOR")
       {
-         CalledPOJO pojo = new CalledPOJO(arg);
-         return pojo.arg;
-      }
-   };
+         public int perform(int arg)
+         {
+            CalledPOJO pojo = new CalledPOJO(arg);
+            return pojo.arg;
+         }
+      };
+   }
    
-   public static final Call METHOD = new Call("METHOD")
+   public static Call getMethod()
    {
-      public int perform(int arg)
+      return new Call("METHOD")
       {
-         CalledPOJO pojo = new CalledPOJO();
-         return pojo.method(arg);
-      }
-   };
+         public int perform(int arg)
+         {
+            CalledPOJO pojo = new CalledPOJO();
+            return pojo.method(arg);
+         }
+      };
+   }
    
-   public static final Call STATIC_METHOD = new Call("STATIC_METHOD")
+   public static final Call getStaticMethod() 
    {
-      public int perform(int arg)
+      return new Call("STATIC_METHOD")
       {
-         return CalledPOJO.staticMethod(arg);
-      }
-   };
+         public int perform(int arg)
+         {
+            return CalledPOJO.staticMethod(arg);
+         }
+      };
+   }
 
+//   public static final Call CONSTRUCTOR = new Call("CONSTRUCTOR")
+//   {
+//      public int perform(int arg)
+//      {
+//         CalledPOJO pojo = new CalledPOJO(arg);
+//         return pojo.arg;
+//      }
+//   };
+//   
+//   public static final Call METHOD = new Call("METHOD")
+//   {
+//      public int perform(int arg)
+//      {
+//         CalledPOJO pojo = new CalledPOJO();
+//         return pojo.method(arg);
+//      }
+//   };
+//   
+//   public static final Call STATIC_METHOD = new Call("STATIC_METHOD")
+//   {
+//      public int perform(int arg)
+//      {
+//         return CalledPOJO.staticMethod(arg);
+//      }
+//   };
+
    // TODO replace by enum
    private Call(String name) {}
    

Modified: branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/args/ArgumentsTestCase.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/test/org/jboss/test/aop/args/ArgumentsTestCase.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -34,8 +34,8 @@
  */
 public class ArgumentsTestCase extends AOPTestWithSetup
 {
-   private ArgumentsPOJO1 pojo1;
-   private ArgumentsPOJO2 pojo2;
+//   private ArgumentsPOJO1 pojo1;
+//   private ArgumentsPOJO2 pojo2;
 
    public static void main(String[] args)
    {
@@ -57,222 +57,223 @@
    public void setUp() throws Exception
    {
       super.setUp();
-      pojo1 = new ArgumentsPOJO1();
-      pojo2 = new ArgumentsPOJO2();
+//      pojo1 = new ArgumentsPOJO1();
+//      pojo2 = new ArgumentsPOJO2();
       ArgumentsAspect.clear();
    }
-   
-   public void testConstructorInvocation1()
-   {
-      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(5);
-      
-      assertEquals(2, pojo.arg);
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(2, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testConstructorInvocation2()
-   {
-      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(23);
-      
-      assertEquals(37, pojo.arg);
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(23, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testMethod1()
-   {
-      assertEquals(0, pojo1.method(1));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(0, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testMethod2()
-   {
-      assertEquals(111, pojo2.method(1100));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(1100, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testStaticMethod1()
-   {
-      assertEquals(4193, pojo1.staticMethod(8347));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(4173, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testStaticMethod2()
-   {
-      assertEquals(57, pojo2.staticMethod(148));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(148, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testConCreatePOJO1()
-   {
-      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.CONSTRUCTOR, 2007);
-      assertEquals(1003, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(1003, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testConCreatePOJO2()
-   {
-      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.CONSTRUCTOR, 2037);
-      assertEquals(37, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(2037, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testMethodCreatePOJO1()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      CalledPOJO pojo = pojo1.createPOJO(16);
-      assertEquals(4, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(4, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testMethodCreatePOJO2()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      CalledPOJO pojo = pojo2.createPOJO(1791);
-      assertEquals(37, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testConCallPOJO1()
-   {
-      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.METHOD, 30);
-      assertEquals(105, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(15, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testConCallPOJO2()
-   {
-      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.METHOD, 56);
-      assertEquals(259, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(56, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testMethodCallPOJO1()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      assertEquals(665, pojo1.callPOJO(382));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(95, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testMethodCallPOJO2()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      assertEquals(259, pojo2.callPOJO(1203));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
-   
-   public void testConCallStaticPOJO1()
-   {
-      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.STATIC_METHOD, -2041);
-      assertEquals(36, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(-1020, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
+//   
+//   public void testConstructorInvocation1()
+//   {
+//      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(5);
+//      
+//      assertEquals(2, pojo.arg);
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(2, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testConstructorInvocation2()
+//   {
+//      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(23);
+//      
+//      assertEquals(37, pojo.arg);
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(23, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testMethod1()
+//   {
+//      assertEquals(0, pojo1.method(1));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(0, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testMethod2()
+//   {
+//      assertEquals(111, pojo2.method(1100));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(1100, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testStaticMethod1()
+//   {
+//      assertEquals(4193, pojo1.staticMethod(8347));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(4173, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testStaticMethod2()
+//   {
+//      assertEquals(57, pojo2.staticMethod(148));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(148, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testConCreatePOJO1()
+//   {
+//      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.getConstructor(), 2007);
+//      assertEquals(1003, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(1003, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testConCreatePOJO2()
+//   {
+//      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.getConstructor(), 2037);
+//      assertEquals(37, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(2037, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testMethodCreatePOJO1()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      CalledPOJO pojo = pojo1.createPOJO(16);
+//      assertEquals(4, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(4, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testMethodCreatePOJO2()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      CalledPOJO pojo = pojo2.createPOJO(1791);
+//      assertEquals(37, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testConCallPOJO1()
+//   {
+//      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.getMethod(), 30);
+//      assertEquals(105, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(15, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testConCallPOJO2()
+//   {
+//      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.getMethod(), 56);
+//      assertEquals(259, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(56, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testMethodCallPOJO1()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      assertEquals(665, pojo1.callPOJO(382));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(95, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testMethodCallPOJO2()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      assertEquals(259, pojo2.callPOJO(1203));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
+//   
+//   public void testConCallStaticPOJO1()
+//   {
+//      ArgumentsPOJO1 pojo = new ArgumentsPOJO1(Call.getStaticMethod(), -2041);
+//      assertEquals(36, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(-1020, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
    public void testConCallStaticPOJO2()
    {
-      ArgumentsPOJO2 pojo = new ArgumentsPOJO2(Call.STATIC_METHOD, -8);
-      assertEquals(17, pojo.arg);
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(-8, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(18, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+      System.out.println("============ Hello again");
+      /*ArgumentsPOJO2 pojo = new ArgumentsPOJO2(*/Call.getStaticMethod()/*, -8)*/;
+//      assertEquals(17, pojo.arg);
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(-8, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(18, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
    }
    
-   public void testMethodCallStaticPOJO1()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      assertEquals(36, pojo1.callPOJOStatic(123456));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(30864, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-   }
-   
-   public void testMethodCallStaticPOJO2()
-   {
-      // intercepted twice by each advice: once for caller, once for called
-      assertEquals(17, pojo2.callPOJOStatic(99999));
-      
-      assertNotNull(ArgumentsAspect.arguments1);
-      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
-      assertEquals(1, ArgumentsAspect.arguments1.length);
-      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
-      assertEquals(1, ArgumentsAspect.arguments2.length);
-      assertEquals(18, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
-   }
+//   public void testMethodCallStaticPOJO1()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      assertEquals(36, pojo1.callPOJOStatic(123456));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(30864, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//   }
+//   
+//   public void testMethodCallStaticPOJO2()
+//   {
+//      // intercepted twice by each advice: once for caller, once for called
+//      assertEquals(17, pojo2.callPOJOStatic(99999));
+//      
+//      assertNotNull(ArgumentsAspect.arguments1);
+//      assertNotSame(ArgumentsAspect.arguments1, ArgumentsAspect.arguments2);
+//      assertEquals(1, ArgumentsAspect.arguments1.length);
+//      assertEquals(37, ((Integer) ArgumentsAspect.arguments1[0]).intValue());
+//      assertEquals(1, ArgumentsAspect.arguments2.length);
+//      assertEquals(18, ((Integer) ArgumentsAspect.arguments2[0]).intValue());
+//   }
 }
\ No newline at end of file

Modified: branches/leaks/aop/src/test/org/jboss/test/aop/memoryleaks/MemoryLeakTestCase.java
===================================================================
--- projects/aop/trunk/aop/src/test/org/jboss/test/aop/memoryleaks/MemoryLeakTestCase.java	2007-08-14 10:12:31 UTC (rev 64569)
+++ branches/leaks/aop/src/test/org/jboss/test/aop/memoryleaks/MemoryLeakTestCase.java	2007-08-14 18:08:10 UTC (rev 64582)
@@ -42,6 +42,7 @@
 import junit.framework.TestCase;
 
 import org.jboss.profiler.jvmti.JVMTIInterface;
+import org.jboss.test.aop.AOPTestWithSetup;
 
 /**
  * 
@@ -50,6 +51,11 @@
  */
 public class MemoryLeakTestCase extends TestCase
 {
+   String jbossAopPath;
+   String extraClasses;
+   Method aspectXmkLoaderUndeployXmlMethod;
+   Method aspectManagerInstanceMethod;
+   Method aspectManagerUnregisterClassLoader;
    
    /**
     * Constructor for UndeployTester.
@@ -65,6 +71,21 @@
       super();
    }
 
+   public static void main(String[] args) throws Exception
+   {
+      MemoryLeakTestCase test = new MemoryLeakTestCase();
+      test.testWithClassLoader();
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      System.setProperty(AOPTestWithSetup.DISABLE_SECURITY_KEY, "true");
+      jbossAopPath = System.getProperty("jboss.aop.path");
+      extraClasses = System.getProperty("extraClasses", null);
+      super.setUp();
+   }
+
    public void testWithClassLoader() throws Exception
    {
 	  
@@ -77,12 +98,22 @@
       {
          String className = null;
          {
-            ClassLoader oldloader = Thread.currentThread().getContextClassLoader();
-            ClassLoader loader = newClassLoader();
+            final ClassLoader oldloader = Thread.currentThread().getContextClassLoader();
+            ClassLoader loader = newClassLoader(oldloader);
             weakReferenceOnLoader = new WeakReference(loader);
             
             Thread.currentThread().setContextClassLoader(loader);
-      
+            System.out.println("OLD Loader " + oldloader);
+            System.out.println("NEW Loader " + loader);
+            
+            ClassLoader parent = loader.getParent();
+            while (parent != null)
+            {
+               System.out.println("Parent " + parent);
+               parent = parent.getParent();
+            }
+            
+            
             Class testClass = getTestCaseClass(loader);
             className = testClass.getName();
             
@@ -92,6 +123,8 @@
             System.out.println("oldLoader");
    
             xmlLoader = loader.loadClass("org.jboss.aop.AspectXmlLoader");
+            initMethods(aspectManagerClass, xmlLoader);
+            
             assertNotSame(xmlLoader.getClassLoader(),loader);
    
             ArrayList methods = getTestMethods(testClass);
@@ -112,11 +145,34 @@
             testInstance = null;
             methods.clear();
             //xmlLoader = null; 
-            Thread.currentThread().setContextClassLoader(oldloader);
+            AccessController.doPrivileged(new PrivilegedAction()
+            {
+               public Object run()
+               {
+                  Thread.currentThread().setContextClassLoader(oldloader);
+                  return null;
+               }
+            });
          }
 
          assertEquals(1, countInstances("org.jboss.aop.AspectManager", true));
-         //checkUnload( weakReferenceOnLoader,"org.jboss.test.aop.memoryleaks.Test");
+         
+         if (extraClasses != null)
+         {
+            StringTokenizer tok = new StringTokenizer(extraClasses, ":;,");
+            while (tok.hasMoreTokens())
+            {
+               String clazz = tok.nextToken();
+               try
+               {
+                  reportInstanceReferences(weakReferenceOnLoader, clazz);
+               }
+               catch(Throwable t)
+               {
+               }
+            }
+         }
+         
          checkUnload( weakReferenceOnLoader, className);
          
          // I'm pretty sure nobody would clear that reference. I'm keeping this assertion here just to make it clear why we can't clear xmlLoader
@@ -262,7 +318,7 @@
       assertNotNull("Test to be run must be passed in test.to.run system property", className);
       
       Class testClass  = loader.loadClass(className);
-      assertSame("Fix your classpath, this test is not valid",loader, testClass.getClassLoader());
+      assertSame("Fix your classpath, this test is not valid", loader, testClass.getClassLoader());
       assertNotSame(testClass.getClassLoader(), this.getClass().getClassLoader());
       return testClass;
    }
@@ -283,7 +339,7 @@
             jvmti.heapSnapshot("snapshot", "mem");
             clazz=null;
             
-            String report =jvmti.exploreClassReferences(className, 15, true, false, false, false, false);
+            String report =jvmti.exploreClassReferences(className, 15, true, false, false, false, true);
             
             //System.out.println(report);
             String reportDir = System.getProperty("leak.report.dir");
@@ -299,6 +355,9 @@
             
             clazz = jvmti.getClassByName(className);
             
+            clearEverySingleFieldOnInstances("org.jboss.aop.AspectManager"); // This part is not intended to be commited. It could be used during debug, and you could use to release references on purpose, just to evaluate behavior
+
+            clazz = jvmti.getClassByName(className);
             if (clazz==null)
             {
                 System.out.println("Attention: After clearing every field on AspectManager, GC could release the classLoader");
@@ -307,9 +366,42 @@
             fail ("Class " + className + " still referenced. Look at report for more details");
          }
       }
-      assertNull("The classLoader is supposed to be released. Something is holding a reference. If you activate -agentlib:jbossAgent this testcase will generate a report with referenceHolders.",weakReferenceOnLoader.get());
    }
    
+   private void reportInstanceReferences(WeakReference weakReferenceOnLoader, String className) throws Exception
+   {
+      JVMTIInterface jvmti = new JVMTIInterface();
+      if (jvmti.isActive())
+      {
+         
+         jvmti.forceReleaseOnSoftReferences();
+         jvmti.forceGC();
+         Class clazz = jvmti.getClassByName(className);
+         if (clazz!=null)
+         {
+            jvmti.heapSnapshot("snapshot", "mem");
+            clazz=null;
+            Object[] objects = jvmti.getAllObjects(className);
+            System.out.println("============> Instances of " + className + " " + objects.length);
+            
+            //String report =jvmti.exploreClassReferences(className, 15, true, false, false, false, true);
+            String report = jvmti.exploreObjectReferences(className, 15, false);
+            
+            
+            
+            System.out.println("================= " + className + " ================");
+            System.out.println(report);
+            String reportDir = System.getProperty("leak.report.dir");
+            assertNotNull("You must pass in the directory for the reports as leak.report.dir", reportDir);
+            File outputfile = new File(reportDir + "/leak-report-instances" + className + ".html");
+            FileOutputStream outfile = new FileOutputStream(outputfile);
+            PrintStream realoutput = new PrintStream(outfile);
+            realoutput.println(report);
+            realoutput.close();            
+         }
+      }
+   }
+   
    public Field[] getDeclaredFields(Class clazz)
    {
       ArrayList list = new ArrayList();
@@ -392,11 +484,9 @@
    private void unregisterClassLoader(Class aspectManagerClass, ClassLoader loader) throws Exception
    {
       System.out.println("============ Unregistering ClassLoader");
-      Method instance = aspectManagerClass.getDeclaredMethod("instance", new Class[0]);
-      Object aspectManager = instance.invoke(null, new Object[0]);
+      Object aspectManager = aspectManagerInstanceMethod.invoke(null, new Object[0]);
       
-      Method unregisterClassLoader = aspectManagerClass.getDeclaredMethod("unregisterClassLoader", new Class[] {ClassLoader.class});
-      unregisterClassLoader.invoke(aspectManager, new Object[] {loader});
+      aspectManagerUnregisterClassLoader.invoke(aspectManager, new Object[] {loader});
    }
 
    private static void printVariables()
@@ -413,11 +503,13 @@
       }
    }
 
-   private static ClassLoader newClassLoader() throws Exception {
+   private static ClassLoader newClassLoader(ClassLoader parent) throws Exception {
        //printVariables();
-      URL classLocation =  MemoryLeakTestCase.class.getProtectionDomain().getCodeSource().getLocation();
+       URL classLocation =  MemoryLeakTestCase.class.getProtectionDomain().getCodeSource().getLocation();
        StringTokenizer tokenString = new StringTokenizer(System.getProperty("java.class.path"),File.pathSeparator);
+       System.out.println("java.class.path " + System.getProperty("java.class.path"));
        String pathIgnore = System.getProperty("path.ignore");
+       System.out.println("path.ignore " + pathIgnore);
        if (pathIgnore==null)
        {
           pathIgnore = classLocation.toString();
@@ -434,9 +526,12 @@
           URL itemLocation = new File(value).toURL();
           if (!itemLocation.equals(classLocation) && !itemLocation.toString().equals(pathIgnore))
           {
-             //System.out.println("Location:" + itemLocation);
              urls.add(itemLocation);
           }
+          else
+          {
+             System.out.println("Skipping " + classLocation);
+          }
        }
        
        URL[] urlArray= (URL[])urls.toArray(new URL[urls.size()]);
@@ -448,32 +543,26 @@
        
        return appClassLoader;
     }
-       
 
+   private void initMethods(Class aspectManagerClass, Class xmlLoader) throws Exception
+   {
+      aspectXmkLoaderUndeployXmlMethod = xmlLoader.getDeclaredMethod("undeployXML", new Class[] {URL.class});
+      aspectManagerInstanceMethod = aspectManagerClass.getDeclaredMethod("instance", new Class[0]);
+      aspectManagerUnregisterClassLoader = aspectManagerClass.getDeclaredMethod("unregisterClassLoader", new Class[] {ClassLoader.class});
+   }
+
    private void undeploy(Class xmlLoader) throws Exception
    {
-
-      String strurl = (String)AccessController.doPrivileged(new PrivilegedAction(){
-      
-         public Object run()
-         {
-            return System.getProperty("jboss.aop.path");
-         }
-      
-      });
-//      String strurl = System.getProperty("jboss.aop.path");
+      String strurl = jbossAopPath;
       assertNotNull("Property jboss.aop.path should be defined",strurl);
       strurl = strurl.replace('\\','/');
       URL url = new URL("file:/" + strurl);
       
-      Method method = xmlLoader.getDeclaredMethod("undeployXML", new Class[] {URL.class});
-      method.invoke(null, new Object[] {url});
+      aspectXmkLoaderUndeployXmlMethod.invoke(null, new Object[] {url});
       
       System.out.println("\n====================================================================");
       System.out.println("!!!! Undeployed " + url);
       System.out.println("=====================================================================\n");
-
-      //AspectXmlLoader.undeployXML(url); -- I need to use reflection operations as I don't want to take the chance on letting the JVM using a different classLoader
    }
    
 }




More information about the jboss-cvs-commits mailing list