[jboss-cvs] JBossAS SVN: r61967 - in projects/aop/trunk/aop: src/main/org/jboss/aop and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Apr 1 13:55:33 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-04-01 13:55:33 -0400 (Sun, 01 Apr 2007)
New Revision: 61967

Modified:
   projects/aop/trunk/aop/build-tests-jdk50.xml
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
Log:
[JBAOP-378] Optimization of InstanceAdvisor creation. Manage the joinpointgenerators at class advisor level only, and make the instance advisors reuse the generators from the class advisor. This means we now need to pass in the JoinPointInfos when calling JoinPointGenerator.generateJoinPointClass()

Modified: projects/aop/trunk/aop/build-tests-jdk50.xml
===================================================================
--- projects/aop/trunk/aop/build-tests-jdk50.xml	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/build-tests-jdk50.xml	2007-04-01 17:55:33 UTC (rev 61967)
@@ -387,6 +387,10 @@
          <param name="exclude" value="**/OverrideTestCase.class"/>
       </antcall>
       <antcall target="_run-javaagent-test" inheritRefs="true">
+         <param name="test" value="dynamicgenadvisor"/>
+         <param name="caller" value="javaagent-genadvisor-tests"/>
+      </antcall>
+      <antcall target="_run-javaagent-test" inheritRefs="true">
          <param name="test" value="nameddomain"/>
          <param name="caller" value="javaagent-genadvisor-tests"/>
       </antcall>

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -75,11 +75,15 @@
 
    //TODO These are only needed for the class advisor really
    //All joinpoint generators apart from field reads and constructions go in here
-   ConcurrentReaderHashMap joinPoinGenerators = new ConcurrentReaderHashMap();
+   private ConcurrentReaderHashMap joinPoinGenerators = new ConcurrentReaderHashMap();
    //Needs its own map to avoid crashing with the field write generators
-   ConcurrentReaderHashMap fieldReadJoinPoinGenerators = new ConcurrentReaderHashMap();
+   private ConcurrentReaderHashMap fieldReadJoinPoinGenerators = new ConcurrentReaderHashMap();
    //Needs its own map to avoid crashing with the constructor generators
-   ConcurrentReaderHashMap constructionJoinPointGenerators = new ConcurrentReaderHashMap();
+   private ConcurrentReaderHashMap constructionJoinPointGenerators = new ConcurrentReaderHashMap();
+   
+   ConcurrentReaderHashMap oldInfos = new ConcurrentReaderHashMap();
+   ConcurrentReaderHashMap oldFieldReadInfos = new ConcurrentReaderHashMap();
+   ConcurrentReaderHashMap oldConstructionInfos = new ConcurrentReaderHashMap();
 
    boolean initialisedSuperClasses; 
 
@@ -309,7 +313,7 @@
          newMethodInfos.put(keys[i], info);
 
          MethodJoinPointGenerator generator = getJoinPointGenerator(info);
-         finalizeChainAndRebindJoinPoint(info, generator);
+         finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
       }
       methodInterceptors = newMethodInfos;
       
@@ -321,7 +325,7 @@
             MethodInfo info = (MethodInfo)it.next();
 
             MethodJoinPointGenerator generator = getJoinPointGenerator(info);
-            finalizeChainAndRebindJoinPoint(info, generator);
+            finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
          }
       }      
 
@@ -335,7 +339,7 @@
       {
          FieldInfo info = (FieldInfo)newFieldInfos.get(i);
          FieldJoinPointGenerator generator = getJoinPointGenerator(info);
-         finalizeChainAndRebindJoinPoint(info, generator);
+         finalizeChainAndRebindJoinPoint(oldFieldReadInfos, info, generator);
       }
    }
 
@@ -346,7 +350,7 @@
       {
          FieldInfo info = (FieldInfo)newFieldInfos.get(i);
          FieldJoinPointGenerator generator = getJoinPointGenerator(info);
-         finalizeChainAndRebindJoinPoint(info, generator);
+         finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
       }
    }
 
@@ -357,7 +361,7 @@
       {
          ConstructorInfo info = (ConstructorInfo) newConstructorInfos.get(i);
          ConstructorJoinPointGenerator generator = getJoinPointGenerator(info);
-         finalizeChainAndRebindJoinPoint(info, generator);
+         finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
       }
    }
 
@@ -368,7 +372,7 @@
       {
          ConstructionInfo info = (ConstructionInfo) newConstructionInfos.get(i);
          ConstructionJoinPointGenerator generator = getJoinPointGenerator(info);
-         finalizeChainAndRebindJoinPoint(info, generator);
+         finalizeChainAndRebindJoinPoint(oldConstructionInfos, info, generator);
       }
    }
 
@@ -376,21 +380,21 @@
    protected void finalizeMethodCalledByMethodInterceptorChain(MethodByMethodInfo info)
    {
       MethodByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
-      finalizeChainAndRebindJoinPoint(info, generator);
+      finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
    }
 
    @Override
    protected void finalizeConCalledByMethodInterceptorChain(ConByMethodInfo info)
    {
       ConByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
-      finalizeChainAndRebindJoinPoint(info, generator);
+      finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
    }
 
    @Override
    protected void finalizeConCalledByConInterceptorChain(ConByConInfo info)
    {
       ConByConJoinPointGenerator generator = getJoinPointGenerator(info);
-      finalizeChainAndRebindJoinPoint(info, generator);
+      finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
    }
 
    @Override
@@ -407,11 +411,18 @@
       }
 
       MethodByConJoinPointGenerator generator = getJoinPointGenerator(info);
-      finalizeChainAndRebindJoinPoint(info, generator);
+      finalizeChainAndRebindJoinPoint(oldInfos, info, generator);
    }
 
    protected MethodJoinPointGenerator getJoinPointGenerator(MethodInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       MethodJoinPointGenerator generator = (MethodJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
@@ -423,6 +434,13 @@
 
    protected FieldJoinPointGenerator getJoinPointGenerator(FieldInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       if (info.isRead())
       {
          FieldJoinPointGenerator generator = (FieldJoinPointGenerator)fieldReadJoinPoinGenerators.get(info.getJoinpoint());
@@ -444,14 +462,63 @@
          return generator;
       }
    }
-
-   protected void test123()
+   
+   private JoinPointGenerator getJoinPointGenerator(JoinPointInfo info)
    {
-
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
+      if (info instanceof MethodInfo)
+      {
+         return getJoinPointGenerator((MethodInfo)info);
+      }
+      else if (info instanceof FieldInfo)
+      {
+         return getJoinPointGenerator((FieldInfo)info);
+      }
+      else if (info instanceof ConstructionInfo)
+      {
+         return getJoinPointGenerator((ConstructionInfo)info);
+      }
+      else if (info instanceof ConstructorInfo)
+      {
+         return getJoinPointGenerator((ConstructorInfo)info);
+      }
+      else if (info instanceof ConByConInfo)
+      {
+         return getJoinPointGenerator((ConByConInfo)info);
+      }
+      else if (info instanceof ConByMethodInfo)
+      {
+         return getJoinPointGenerator((ConByMethodInfo)info);
+      }
+      else if (info instanceof MethodByMethodInfo)
+      {
+         return getJoinPointGenerator((MethodByMethodInfo)info);
+      }
+      else if (info instanceof MethodByConInfo)
+      {
+         return getJoinPointGenerator((MethodByConInfo)info);
+      }
+      else
+      {
+         throw new RuntimeException("Invalid JoinPointInfo passed in: " + info.getClass().getName());
+      }
    }
 
    protected ConstructorJoinPointGenerator getJoinPointGenerator(ConstructorInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       ConstructorJoinPointGenerator generator = (ConstructorJoinPointGenerator)constructionJoinPointGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
@@ -463,6 +530,13 @@
 
    protected ConstructionJoinPointGenerator getJoinPointGenerator(ConstructionInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       ConstructionJoinPointGenerator generator = (ConstructionJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
@@ -474,6 +548,14 @@
 
    protected MethodByMethodJoinPointGenerator getJoinPointGenerator(MethodByMethodInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
+
       //An extra level of indirection since we distinguish between callers of method depending on
       //where the called method is defined (sub/super interfaces)
       ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
@@ -496,6 +578,13 @@
 
    protected ConByMethodJoinPointGenerator getJoinPointGenerator(ConByMethodInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       ConByMethodJoinPointGenerator generator = (ConByMethodJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
@@ -507,6 +596,13 @@
 
    protected ConByConJoinPointGenerator getJoinPointGenerator(ConByConInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
       ConByConJoinPointGenerator generator = (ConByConJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
@@ -518,6 +614,14 @@
 
    protected MethodByConJoinPointGenerator getJoinPointGenerator(MethodByConInfo info)
    {
+      GeneratedClassAdvisor parent = getParentAdvisor();
+      if (parent != null)
+      {
+         //We are an instance advisor, get the generator from the class advisor
+         return parent.getJoinPointGenerator(info);
+      }
+      //We are the class advisor
+
       //An extra level of indirection since we distinguish between callers of method depending on
       //where the called method is defined (sub/super interfaces)
       ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
@@ -565,7 +669,7 @@
       }
    }
 
-   private void finalizeChainAndRebindJoinPoint(JoinPointInfo info, JoinPointGenerator generator)
+   private void finalizeChainAndRebindJoinPoint(Map oldInfos, JoinPointInfo info, JoinPointGenerator generator)
    {
       ArrayList list = info.getInterceptorChain();
       GeneratedAdvisorInterceptor[] factories = null;
@@ -575,7 +679,10 @@
       }
       info.setInterceptors(factories);
 
-      generator.rebindJoinpoint(info);
+      if (updateOldInfo(oldInfos, info))
+      {
+         generator.rebindJoinpoint(info);
+      }
    }
 
    @Override
@@ -731,4 +838,77 @@
       }
    }
    
+   /**
+    * Caches the old info and checks if the chains have been updated
+    */
+   private boolean updateOldInfo(Map oldInfos, JoinPointInfo newInfo)
+   {
+      JoinPointInfo oldInfo = (JoinPointInfo)oldInfos.get(newInfo.getJoinpoint());
+      if (oldInfo != null)
+      {
+         //We are not changing any of the bindings
+         if (oldInfo.equalChains(newInfo))
+         {
+            return false;
+         }
+      }
+      oldInfo = newInfo.copy();
+      oldInfos.put(newInfo.getJoinpoint(), oldInfo);
+      return true;
+   }
+
+   protected void generateJoinPointClass(MethodInfo info)
+   {
+      MethodJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(FieldInfo info)
+   {
+      FieldJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(ConstructorInfo info)
+   {
+      ConstructorJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(ConstructionInfo info)
+   {
+      ConstructionJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(MethodByMethodInfo info)
+   {
+      MethodByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(ConByMethodInfo info)
+   {
+      ConByMethodJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(ConByConInfo info)
+   {
+      ConByConJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+
+   protected void generateJoinPointClass(MethodByConInfo info)
+   {
+      MethodByConJoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
+   
+   protected void rebindJoinPointWithInstanceInformation(JoinPointInfo info)
+   {
+      JoinPointGenerator generator = getJoinPointGenerator(info);
+      generator.rebindJoinpoint(info);
+      generator.generateJoinPointClass(this.getClass().getClassLoader(), info);
+   }
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByConJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 
@@ -47,7 +48,6 @@
  */
 public class ConByConJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "CByC_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "CByC_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "CByC_";
 
@@ -65,39 +65,43 @@
       }
    }
 
+   private WeakReference returnType;
+
    public ConByConJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, JoinPointParameters.ONLY_ARGS,
             ((ConByConInfo) info).getConstructor().getParameterTypes().length);
+      returnType = new WeakReference(((ConByConInfo)info).getCalledClass());
    }
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               callingIndex(),
-               calledClass(),
-               calledConHash());
+      ConByConInfo cinfo = (ConByConInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               callingIndex(cinfo),
+               calledClass(cinfo),
+               calledConHash(cinfo));
 
-      joinpointFieldName = getInfoFieldName(
-            callingIndex(),
-            calledClass(),
-            calledConHash());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+            callingIndex(cinfo),
+            calledClass(cinfo),
+            calledConHash(cinfo));
 
    }
 
-   private int callingIndex()
+   private int callingIndex(ConByConInfo info)
    {
-      return ((ConByConInfo)info).getCallingIndex();
+      return info.getCallingIndex();
    }
 
-   private String calledClass()
+   private String calledClass(ConByConInfo info)
    {
-      return ((ConByConInfo)info).getCalledClass().getName();
+      return info.getCalledClass().getName();
    }
 
-   private long calledConHash()
+   private long calledConHash(ConByConInfo info)
    {
-      return ((ConByConInfo)info).getCalledConHash();
+      return info.getCalledConHash();
    }
 
 
@@ -108,10 +112,10 @@
 
    protected Class getReturnType()
    {
-      return ((ConByConInfo)info).getCalledClass();
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Constructor ctor = ((ConByConInfo)info).getConstructor();
       AdviceMethodProperties properties = new AdviceMethodProperties(
@@ -159,36 +163,20 @@
             long calledHash,
             String ciname) throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(callingIndex, classname, calledHash));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, callingClass, callingIndex, classname, targetCtor, calledHash, ciname);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointClassName(int callingIndex, String classname, long calledHash)
    {
-      return getJoinPointGeneratorFieldName(
-            callingIndex(),
-            calledClass(),
-            calledConHash());
-   }
-
-   protected static String getInfoClassName(int callingIndex, String classname, long calledHash)
-   {
       return JOINPOINT_CLASS_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
    }
 
-   protected static String getInfoFieldName(int callingIndex, String classname, long calledHash)
+   protected static String getGeneratedJoinPointFieldName(int callingIndex, String classname, long calledHash)
    {
       return JOINPOINT_FIELD_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
    }
 
-   protected static String getJoinPointGeneratorFieldName(int callingIndex, String classname, long calledHash)
-   {
-      return GENERATOR_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
-   }
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -243,7 +231,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(callingIndex, targetClass.getName(), calledHash);
+         String className = getGeneratedJoinPointClassName(callingIndex, targetClass.getName(), calledHash);
 
          //Create inner joinpoint class in advised class, super class is ConstructorInvocation
          jp = TransformerCommon.makeNestedClass(callingClass, className, true, Modifier.PUBLIC | Modifier.STATIC, INVOCATION_CT_TYPE);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConByMethodJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 
 import javassist.CannotCompileException;
@@ -48,7 +49,6 @@
  */
 public class ConByMethodJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "CByM_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "CByM_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "CByM_";
    private static final Class INVOCATION_TYPE = ConstructorCalledByMethodInvocation.class;
@@ -64,12 +64,16 @@
          throw new RuntimeException(e);
       }
    }
+   
+   private boolean hasCallingObject;
+   private WeakReference returnType;
 
-
    public ConByMethodJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, getParameters((ConByMethodInfo) info),
             ((ConByMethodInfo) info).getConstructor().getParameterTypes().length);
+      hasCallingObject = !java.lang.reflect.Modifier.isStatic(((ConByMethodInfo)info).getCallingMethod().getModifiers());
+      returnType = new WeakReference(((ConByMethodInfo)info).getCalledClass());
    }
    
    private static JoinPointParameters getParameters(ConByMethodInfo info)
@@ -81,33 +85,34 @@
       return JoinPointParameters.CALLER_ARGS;
    }
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               callingMethodHash(),
-               calledClass(),
-               calledConHash());
+      ConByMethodInfo cinfo = (ConByMethodInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               callingMethodHash(cinfo),
+               calledClass(cinfo),
+               calledConHash(cinfo));
 
-      joinpointFieldName = getInfoFieldName(
-            callingMethodHash(),
-            calledClass(),
-            calledConHash());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+            callingMethodHash(cinfo),
+            calledClass(cinfo),
+            calledConHash(cinfo));
 
    }
 
-   private long callingMethodHash()
+   private long callingMethodHash(ConByMethodInfo info)
    {
-      return ((ConByMethodInfo)info).getCallingMethodHash();
+      return info.getCallingMethodHash();
    }
 
-   private String calledClass()
+   private String calledClass(ConByMethodInfo info)
    {
-      return ((ConByMethodInfo)info).getCalledClass().getName();
+      return info.getCalledClass().getName();
    }
 
-   private long calledConHash()
+   private long calledConHash(ConByMethodInfo info)
    {
-      return ((ConByMethodInfo)info).getCalledConHash();
+      return info.getCalledConHash();
    }
 
    protected boolean isVoid()
@@ -117,10 +122,10 @@
 
    protected Class getReturnType()
    {
-      return ((ConByMethodInfo)info).getCalledClass();
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Constructor ctor = ((ConByMethodInfo)info).getConstructor();
       AdviceMethodProperties properties = new AdviceMethodProperties(
@@ -146,7 +151,7 @@
 
    protected boolean hasCallingObject()
    {
-      return !java.lang.reflect.Modifier.isStatic(((ConByMethodInfo)info).getCallingMethod().getModifiers());
+      return hasCallingObject;
    }
 
    protected boolean hasTargetObject()
@@ -169,36 +174,20 @@
             long calledHash,
             String ciname) throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(callingHash, classname, calledHash));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, callingClass, callingHash, hasCallingObject, classname, targetCtor, calledHash, ciname);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointClassName(long callingHash, String classname, long calledHash)
    {
-      return getJoinPointGeneratorFieldName(
-            callingMethodHash(),
-            calledClass(),
-            calledConHash());
-   }
-
-   protected static String getInfoClassName(long callingHash, String classname, long calledHash)
-   {
       return JOINPOINT_CLASS_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
    }
 
-   protected static String getInfoFieldName(long callingHash, String classname, long calledHash)
+   protected static String getGeneratedJoinPointFieldName(long callingHash, String classname, long calledHash)
    {
       return JOINPOINT_FIELD_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
    }
 
-   protected static String getJoinPointGeneratorFieldName(long callingHash, String classname, long calledHash)
-   {
-      return GENERATOR_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
-   }
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -256,7 +245,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(callingHash, targetClass.getName(), calledHash);
+         String className = getGeneratedJoinPointClassName(callingHash, targetClass.getName(), calledHash);
 
          //Create inner joinpoint class in advised class, super class is ConstructorInvocation
          jp = TransformerCommon.makeNestedClass(callingClass, className, true, Modifier.PUBLIC | Modifier.STATIC, INVOCATION_CT_TYPE);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -48,7 +48,6 @@
  */
 public class ConstructionJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "construction_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "construction_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "construction_";
    private static final Class INVOCATION_TYPE = ConstructionInvocation.class;
@@ -72,26 +71,27 @@
    }
 
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               classSimpleName(),
-               index());
+      ConstructionInfo cinfo = (ConstructionInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               classSimpleName(cinfo),
+               index(cinfo));
 
-      joinpointFieldName = getInfoFieldName(
-               classSimpleName(),
-               index());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+               classSimpleName(cinfo),
+               index(cinfo));
    }
 
-   private String classSimpleName()
+   private String classSimpleName(ConstructionInfo info)
    {
       Constructor ctor = ((ConstructionInfo)info).getConstructor();
       return Advisor.getSimpleName(ctor.getDeclaringClass());
    }
 
-   private int index()
+   private int index(ConstructionInfo info)
    {
-      return ((ConstructionInfo)info).getIndex();
+      return info.getIndex();
    }
 
    protected boolean isVoid()
@@ -104,7 +104,7 @@
       return null;
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Constructor ctor = ((ConstructionInfo)info).getConstructor();
       return new AdviceMethodProperties(
@@ -124,11 +124,11 @@
       return true;
    }
 
-   protected String getInfoName()
-   {
-      return ConstructionTransformer.getConstructionInfoFieldName(
-            Advisor.getSimpleName(advisor.getClazz()), ((ConstructionInfo)info).getIndex());
-   }
+//   protected String getInfoName()
+//   {
+//      return ConstructionTransformer.getConstructionInfoFieldName(
+//            Advisor.getSimpleName(advisor.getClazz()), ((ConstructionInfo)info).getIndex());
+//   }
 
 
    protected static CtClass createJoinpointBaseClass(
@@ -138,36 +138,20 @@
          String ciname,
          int index)throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(advisedClass.getSimpleName(), index));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, advisedClass, advisedCtor, ciname, index);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointFieldName(String className, int index)
    {
-      return getJoinPointGeneratorFieldName(
-            classSimpleName(),
-            index());
-   }
-
-   protected static String getInfoFieldName(String className, int index)
-   {
       return JOINPOINT_FIELD_PREFIX + className + "_" + index;
    }
 
-   private static String getInfoClassName(String className, int index)
+   private static String getGeneratedJoinPointClassName(String className, int index)
    {
       return JOINPOINT_CLASS_PREFIX + className + "_" + index;
    }
 
-   protected static String getJoinPointGeneratorFieldName(String className, int index)
-   {
-      return GENERATOR_PREFIX + className + "_" + index;
-   }
-
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -221,7 +205,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(advisedClass.getSimpleName(), index);
+         String className = getGeneratedJoinPointClassName(advisedClass.getSimpleName(), index);
 
          //Create inner joinpoint class in advised class, super class is jp
          jp = TransformerCommon.makeNestedClass(advisedClass, className, true, Modifier.PUBLIC | Modifier.STATIC, INVOCATION_CT_TYPE);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 
@@ -48,7 +49,6 @@
  */
 public class ConstructorJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "constructor_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "constructor_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "constructor_";
    private static final Class INVOCATION_TYPE = ConstructorInvocation.class;
@@ -65,34 +65,37 @@
       }
    }
 
+   WeakReference returnType;
 
    public ConstructorJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, JoinPointParameters.ONLY_ARGS,
             ((ConstructorInfo) info).getConstructor().getParameterTypes().length);
+      returnType = new WeakReference(((ConstructorInfo)info).getConstructor().getDeclaringClass());
    }
 
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               classSimpleName(),
-               index());
+      ConstructorInfo cinfo = (ConstructorInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               classSimpleName(cinfo),
+               index(cinfo));
 
-      joinpointFieldName = getInfoFieldName(
-               classSimpleName(),
-               index());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+               classSimpleName(cinfo),
+               index(cinfo));
    }
 
-   private String classSimpleName()
+   private String classSimpleName(ConstructorInfo info)
    {
-      Constructor ctor = ((ConstructorInfo)info).getConstructor();
+      Constructor ctor = info.getConstructor();
       return Advisor.getSimpleName(ctor.getDeclaringClass());
    }
 
-   private int index()
+   private int index(ConstructorInfo info)
    {
-      return ((ConstructorInfo)info).getIndex();
+      return info.getIndex();
    }
 
    protected boolean isVoid()
@@ -102,10 +105,10 @@
 
    protected Class getReturnType()
    {
-      return ((ConstructorInfo)super.info).getConstructor().getDeclaringClass();
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Constructor ctor = ((ConstructorInfo)info).getConstructor();
       return new AdviceMethodProperties(
@@ -130,33 +133,20 @@
          String ciname,
          int index)throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(advisedClass.getSimpleName(), index));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, advisedClass, advisedCtor, ciname, index);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointFieldName(String className, int index)
    {
-      return getJoinPointGeneratorFieldName(classSimpleName(), index());
-   }
-
-   protected static String getInfoFieldName(String className, int index)
-   {
       return JOINPOINT_FIELD_PREFIX + className + "_" + index;
    }
 
-   private static String getInfoClassName(String className, int index)
+   private static String getGeneratedJoinPointClassName(String className, int index)
    {
       return JOINPOINT_CLASS_PREFIX + className + "_" + index;
    }
 
-   protected static String getJoinPointGeneratorFieldName(String className, int index)
-   {
-      return GENERATOR_PREFIX + className + "_" + index;
-   }
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -203,7 +193,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(advisedClass.getSimpleName(), index);
+         String className = getGeneratedJoinPointClassName(advisedClass.getSimpleName(), index);
 
          //Create inner joinpoint class in advised class, super class is ConstructorInvocation
          jp = TransformerCommon.makeNestedClass(advisedClass, className, true, Modifier.PUBLIC | Modifier.STATIC, INVOCATION_CT_TYPE);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/FieldJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
 
@@ -49,8 +50,6 @@
  */
 public class FieldJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String WRITE_GENERATOR_PREFIX = GENERATOR_PREFIX + "w_";
-   public static final String READ_GENERATOR_PREFIX = GENERATOR_PREFIX + "r_";
    public static final String WRITE_JOINPOINT_FIELD_PREFIX = JOINPOINT_FIELD_PREFIX + "w_";
    public static final String READ_JOINPOINT_FIELD_PREFIX = JOINPOINT_FIELD_PREFIX + "r_";
    public static final String WRITE_JOINPOINT_CLASS_PREFIX = JOINPOINT_CLASS_PREFIX + "w_";
@@ -72,10 +71,21 @@
       }
    }
 
+   WeakReference returnType;
+   boolean read;
+   boolean hasTargetObject;
+   
    public FieldJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, getParameters((FieldInfo) info),
             ((FieldInfo) info).isRead()? 0: 1);
+
+      if (read((FieldInfo)info))
+      {
+         read = true;
+         returnType = new WeakReference(((FieldInfo)info).getAdvisedField().getType());
+      }
+      hasTargetObject = !Modifier.isStatic(((FieldInfo)info).getAdvisedField().getModifiers());
    }
 
    private static JoinPointParameters getParameters(FieldInfo info)
@@ -87,74 +97,71 @@
       return JoinPointParameters.TARGET_ARGS;
    }
    
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
+      FieldInfo finfo = (FieldInfo)info;
       joinpointClassName =
-         getInfoClassName(fieldName(), read());
+         getGeneratedJoinPointClassName(fieldName(finfo), read(finfo));
 
       joinpointFieldName =
-         getInfoFieldName(fieldName(), read());
+         getGeneratedJoinPointFieldName(fieldName(finfo), read(finfo));
    }
 
-   private String fieldName()
+   private String fieldName(FieldInfo info)
    {
-      return ((FieldInfo)info).getAdvisedField().getName();
+      return info.getAdvisedField().getName();
    }
 
-   private boolean read()
+   private boolean read(FieldInfo info)
    {
-      return ((FieldInfo)info).isRead();
+      return info.isRead();
    }
 
    protected boolean isVoid()
    {
-      return !((FieldInfo)info).isRead();
+      return !read;
    }
 
    protected Class getReturnType()
    {
-      if (!read())
+      if (returnType != null)
       {
-         return null;
+         return (Class)returnType.get();
       }
-      return ((FieldInfo)super.info).getAdvisedField().getType();
+      return null;
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
-      Field field = ((FieldInfo)info).getAdvisedField();
+      FieldInfo finfo = (FieldInfo)info;
+      Field field = finfo.getAdvisedField();
       return new AdviceMethodProperties(
                setup.getAspectClass(),
                setup.getAdviceName(),
                info.getClass(),
-               (read()) ? READ_INVOCATION_TYPE : WRITE_INVOCATION_TYPE,
-               (read()) ? getReturnType() : Void.TYPE,
-               (read()) ? new Class[] {} : new Class[] {field.getType()},
+               (read(finfo)) ? READ_INVOCATION_TYPE : WRITE_INVOCATION_TYPE,
+               (read(finfo)) ? getReturnType() : Void.TYPE,
+               (read(finfo)) ? new Class[] {} : new Class[] {field.getType()},
                null,
                field.getDeclaringClass(),
                hasTargetObject());
    }
 
-   protected CtClass[] getJoinpointParameters() throws NotFoundException
-   {
-      if (isVoid()) return new CtClass[0];
+//   protected CtClass[] getJoinpointParameters() throws NotFoundException
+//   {
+//      if (isVoid()) return new CtClass[0];
+//
+//      CtClass type = ReflectToJavassist.fieldToJavassist(((FieldInfo)info).getAdvisedField()).getType();
+//      return new CtClass[] {type};
+//   }
 
-      CtClass type = ReflectToJavassist.fieldToJavassist(((FieldInfo)super.info).getAdvisedField()).getType();
-      return new CtClass[] {type};
-   }
-
    protected boolean hasTargetObject()
    {
-      return !Modifier.isStatic(((FieldInfo)info).getAdvisedField().getModifiers());
+      return hasTargetObject;
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointFieldName(String fieldName, boolean read)
    {
-      return getJoinPointGeneratorFieldName(fieldName(), read());
-   }
-
-   protected static String getInfoFieldName(String fieldName, boolean read)
-   {
       if (read)
       {
          return READ_JOINPOINT_FIELD_PREFIX + fieldName;
@@ -165,7 +172,7 @@
       }
    }
 
-   private static String getInfoClassName(String fieldName, boolean read)
+   private static String getGeneratedJoinPointClassName(String fieldName, boolean read)
    {
       if (read)
       {
@@ -177,18 +184,6 @@
       }
    }
 
-   public static String getJoinPointGeneratorFieldName(String fieldName, boolean read)
-   {
-      if (read)
-      {
-         return READ_GENERATOR_PREFIX + fieldName;
-      }
-      else
-      {
-         return WRITE_GENERATOR_PREFIX + fieldName;
-      }
-   }
-
    protected static CtClass createReadJoinpointBaseClass(
          GeneratedAdvisorInstrumentor instrumentor,
          CtClass advisedClass,
@@ -196,9 +191,6 @@
          String finame,
          int index)throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(advisedField.getName(), true));
-
       BaseClassGenerator factory = new ReadBaseClassGenerator(instrumentor, advisedClass, advisedField, finame, index);
       return factory.generate();
    }
@@ -210,9 +202,6 @@
          String finame,
          int index)throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(advisedField.getName(), false));
-
       BaseClassGenerator factory = new WriteBaseClassGenerator(instrumentor, advisedClass, advisedField, finame, index);
       return factory.generate();
    }
@@ -294,7 +283,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(advisedField.getName(), read);
+         String className = getGeneratedJoinPointClassName(advisedField.getName(), read);
 
          //Create inner joinpoint class in advised class, super class is
          CtClass superClass = (read) ? READ_INVOCATION_CT_TYPE : WRITE_INVOCATION_CT_TYPE;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -85,7 +85,7 @@
          CtClass genadvisor = getInstrumentor().getGenadvisor();
          CtField field = new CtField(
                joinpoint,
-               MethodByConJoinPointGenerator.getInfoFieldName(cd.callingIndex, cd.classname, cd.calledHash),
+               MethodByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash),
                genadvisor);
          field.setModifiers(Modifier.PROTECTED);
          genadvisor.addField(field);
@@ -134,21 +134,21 @@
             proceed = MethodExecutionTransformer.getAopReturnStr(cd.calledMethod) + cd.classname + "." + cd.calledMethod.getName() + "(" + getArguments(params.length, 1) + ");";
          }
 
-         String infoName = MethodByConJoinPointGenerator.getInfoFieldName(cd.callingIndex, cd.classname, cd.calledHash);
-         String generatorName = MethodByConJoinPointGenerator.getJoinPointGeneratorFieldName(cd.callingIndex, cd.classname, cd.calledHash);
+         String joinpointName = MethodByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash);
+         String infoName = cd.callerInfoField;
          String code =
                "{" +
-               "   if (" + infoName + " == null && " + generatorName + " != null)" +
+               "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
                "   {" +
-               "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+               "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
                "   }" +
-               "   if (" + infoName + " == null)" +
+               "   if (" + joinpointName + " == null)" +
                "   { " +
                "      " + proceed +
                "   }" +
                "   else" +
                "   {" +
-               "      return " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+               "      return " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
                "   }" +
                "}";
 
@@ -188,7 +188,7 @@
          CtClass genadvisor = getInstrumentor().getGenadvisor();
          CtField field = new CtField(
                joinpoint,
-               MethodByMethodJoinPointGenerator.getInfoFieldName(md.callingHash, md.classname, md.calledHash),
+               MethodByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(md.callingHash, md.classname, md.calledHash),
                genadvisor);
          field.setModifiers(Modifier.PROTECTED);
          genadvisor.addField(field);
@@ -236,21 +236,21 @@
             proceed = MethodExecutionTransformer.getAopReturnStr(md.calledMethod) + md.classname + "." + md.calledMethod.getName() + "(" + getArguments(params.length, hasCallingObject ? 1 : 0) +");";
          }
 
-         String infoName = MethodByMethodJoinPointGenerator.getInfoFieldName(md.callingHash, md.classname, md.calledHash);
-         String generatorName = MethodByMethodJoinPointGenerator.getJoinPointGeneratorFieldName(md.callingHash, md.classname, md.calledHash);
+         String joinpointName = MethodByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(md.callingHash, md.classname, md.calledHash);
+         String infoName = md.callerInfoField;
          String code =
                "{" +
-               "   if (" + infoName + " == null && " + generatorName + " != null)" +
+               "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
                "   {" +
-               "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+               "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
                "   }" +
-               "   if (" + infoName + " == null)" +
+               "   if (" + joinpointName + " == null)" +
                "   { " +
                "      " + proceed +
                "   }" +
                "   else" +
                "   {" +
-               "      " + MethodExecutionTransformer.getReturnStr(md.calledMethod) + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+               "      " + MethodExecutionTransformer.getReturnStr(md.calledMethod) + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
                "   }" +
                "}";
 
@@ -290,7 +290,7 @@
          CtClass genadvisor = getInstrumentor().getGenadvisor();
          CtField field = new CtField(
                joinpoint,
-               ConByMethodJoinPointGenerator.getInfoFieldName(cd.callingHash, cd.classname, cd.calledHash),
+               ConByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingHash, cd.classname, cd.calledHash),
                genadvisor);
          field.setModifiers(Modifier.PROTECTED);
          genadvisor.addField(field);
@@ -328,21 +328,21 @@
             params = cd.calledConstructor.getParameterTypes();
          }
 
-         String infoName = ConByMethodJoinPointGenerator.getInfoFieldName(cd.callingHash, cd.classname, cd.calledHash);
-         String generatorName = ConByMethodJoinPointGenerator.getJoinPointGeneratorFieldName(cd.callingHash, cd.classname, cd.calledHash);
+         String joinpointName = ConByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingHash, cd.classname, cd.calledHash);
+         String infoName = cd.callerInfoField;
          StringBuffer code = new StringBuffer();
          code.append("{");
-         code.append("   if (" + infoName + " == null && " + generatorName + " != null)");
+         code.append("   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())");
          code.append("   {");
-         code.append("   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());");
+         code.append("      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");");
          code.append("   }");
-         code.append("   if (" + infoName + " == null)");
+         code.append("   if (" + joinpointName + " == null)");
          code.append("   { ");
          code.append("      return new " + cd.calledConstructor.getDeclaringClass().getName() + "(" + getArguments(params.length, hasCallingObject ? 1 : 0) + "); ");
          code.append("   }");
          code.append("   else");
          code.append("   {");
-         code.append("      return " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);");
+         code.append("      return " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);");
          code.append("   }");
          code.append("}");
 
@@ -382,7 +382,7 @@
          CtClass genadvisor = getInstrumentor().getGenadvisor();
          CtField field = new CtField(
                joinpoint,
-               ConByConJoinPointGenerator.getInfoFieldName(cd.callingIndex, cd.classname, cd.calledHash),
+               ConByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash),
                genadvisor);
          field.setModifiers(Modifier.PROTECTED);
          genadvisor.addField(field);
@@ -409,21 +409,21 @@
          params[0] = callingClass;
          System.arraycopy(cd.calledConstructor.getParameterTypes(), 0, params, 1, originalLength);
          
-         String infoName = ConByConJoinPointGenerator.getInfoFieldName(cd.callingIndex, cd.classname, cd.calledHash);
-         String generatorName = ConByConJoinPointGenerator.getJoinPointGeneratorFieldName(cd.callingIndex, cd.classname, cd.calledHash);
+         String joinpointName = ConByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash);
+         String infoName = cd.callerInfoField;
          String code =
                "{" +
-               "   if (" + infoName + " == null && " + generatorName + " != null)" +
+               "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
                "   {" +
-               "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+               "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
                "   }" +
-               "   if (" + infoName + " == null)" +
+               "   if (" + joinpointName + " == null)" +
                "   { " +
                "      return new " + cd.calledConstructor.getDeclaringClass().getName() + "(" + getArguments(params.length, 1) + "); " +
                "   }" +
                "   else" +
                "   {" +
-               "      return " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+               "      return " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
                "   }" +
                "}";
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -69,7 +69,7 @@
       CtClass genadvisor = ((GeneratedAdvisorInstrumentor)instrumentor).getGenadvisor();
       CtField field = new CtField(
             joinpoint,
-            ConstructionJoinPointGenerator.getInfoFieldName(clazz.getSimpleName(), index),
+            ConstructionJoinPointGenerator.getGeneratedJoinPointFieldName(clazz.getSimpleName(), index),
             genadvisor);
       field.setModifiers(Modifier.PROTECTED);
       genadvisor.addField(field);
@@ -141,17 +141,17 @@
 
    private String createInterceptingWrapperBody(CtConstructor constructor, int index)throws NotFoundException, CannotCompileException
    {
-      String infoName = ConstructionJoinPointGenerator.getInfoFieldName(constructor.getDeclaringClass().getSimpleName(), index);
-      String generatorName = ConstructionJoinPointGenerator.getJoinPointGeneratorFieldName(constructor.getDeclaringClass().getSimpleName(), index);
+      String joinpointName = ConstructionJoinPointGenerator.getGeneratedJoinPointFieldName(constructor.getDeclaringClass().getSimpleName(), index);
+      String infoName = getConstructionInfoFieldName(constructor.getDeclaringClass().getSimpleName(), index);
       String code =
          "{" +
-         "   if (" + infoName + " == null && " + generatorName + " != null)" +
+         "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
          "   {" +
-         "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+         "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
          "   }" +
-         "   if (" + infoName + " != null)" +
+         "   if (" + joinpointName + " != null)" +
          "   { " +
-         "    " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+         "    " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
          "   }" +
          "}";
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -76,7 +76,7 @@
       CtClass genadvisor = ((GeneratedAdvisorInstrumentor)getInstrumentor()).getGenadvisor();
       CtField field = new CtField(
             joinpoint,
-            ConstructorJoinPointGenerator.getInfoFieldName(clazz.getSimpleName(), index),
+            ConstructorJoinPointGenerator.getGeneratedJoinPointFieldName(clazz.getSimpleName(), index),
             genadvisor);
       field.setModifiers(Modifier.PROTECTED);
       genadvisor.addField(field);
@@ -208,27 +208,27 @@
 
       CtMethod innerWrapper = getInnerWrapperMethod(trans.getConstructor());
 
-      String infoName = ConstructorJoinPointGenerator.getInfoFieldName(
+      String joinpointName = ConstructorJoinPointGenerator.getGeneratedJoinPointFieldName(
             trans.getConstructor().getDeclaringClass().getSimpleName(),
             trans.getIndex());
 
-      String generatorName = ConstructorJoinPointGenerator.getJoinPointGeneratorFieldName(
+      String infoName = getConstructorInfoFieldName(            
             trans.getConstructor().getDeclaringClass().getSimpleName(),
             trans.getIndex());
 
       String code =
          "{" +
-         "   if (" + infoName + " == null && " + generatorName + " != null)" +
+         "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
          "   {" +
-         "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+         "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
          "   }" +
-         "   if (" + infoName + " == null)" +
+         "   if (" + joinpointName + " == null)" +
          "   { " +
          "      return new " + trans.getClassName() + "($$); " +
          "   }" +
          "   else" +
          "   {" +
-         "      return " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+         "      return " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
          "   }" +
          "}";
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -136,7 +136,7 @@
       CtClass genadvisor = ((GeneratedAdvisorInstrumentor)instrumentor).getGenadvisor();
       CtField jpfield = new CtField(
             joinpoint,
-            FieldJoinPointGenerator.getInfoFieldName(field.getName(), true),
+            FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), true),
             genadvisor);
       jpfield.setModifiers(Modifier.PROTECTED);
       genadvisor.addField(jpfield);
@@ -175,7 +175,7 @@
       CtClass genadvisor = ((GeneratedAdvisorInstrumentor)instrumentor).getGenadvisor();
       CtField jpfield = new CtField(
             joinpoint,
-            FieldJoinPointGenerator.getInfoFieldName(field.getName(), false),
+            FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), false),
             genadvisor);
       jpfield.setModifiers(Modifier.PROTECTED);
       genadvisor.addField(jpfield);
@@ -256,23 +256,23 @@
    {
       boolean isStatic = Modifier.isStatic(field.getModifiers());
       String code = null;
-      String infoName = FieldJoinPointGenerator.getInfoFieldName(field.getName(), true);
-      String generatorName = FieldJoinPointGenerator.getJoinPointGeneratorFieldName(field.getName(), true);
+      String joinpointName = FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), true);
+      String infoName = getFieldReadInfoFieldName(field.getName());
       if (isStatic)
       {
          code =
             "{" +
-            "   if (" + infoName + " == null && " + generatorName + " != null)" +
+            "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
             "   {" +
-            "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+            "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
             "   }" +
-            "   if (" + infoName + " == null)" +
+            "   if (" + joinpointName + " == null)" +
             "   { " +
             "       return " + clazz.getName() + "." + field.getName() + ";" +
             "   }" +
             "   else" +
             "   {" +
-            "    " + MethodExecutionTransformer.getAopReturnStr(false) + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "();" +
+            "    " + MethodExecutionTransformer.getAopReturnStr(false) + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "();" +
             "   }" +
             "}";
       }
@@ -280,17 +280,17 @@
       {
          code =
             "{" +
-            "   if (" + infoName + " == null && " + generatorName + " != null)" +
+            "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
             "   {" +
-            "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+            "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
             "   }" +
-            "   if (" + infoName + " == null)" +
+            "   if (" + joinpointName + " == null)" +
             "   { " +
             "       return ((" + clazz.getName() + ")$1)." + field.getName() + ";" +
             "   }" +
             "   else" +
             "   {" +
-            "    " + MethodExecutionTransformer.getAopReturnStr(false) + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "((" + clazz.getName() + ")$1);" +
+            "    " + MethodExecutionTransformer.getAopReturnStr(false) + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "((" + clazz.getName() + ")$1);" +
             "   }" +
             "}";
       }
@@ -303,23 +303,23 @@
    {
       boolean isStatic = Modifier.isStatic(field.getModifiers());
       String code = null;
-      String infoName = FieldJoinPointGenerator.getInfoFieldName(field.getName(), false);
-      String generatorName = FieldJoinPointGenerator.getJoinPointGeneratorFieldName(field.getName(), false);
+      String joinpointName = FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), false);
+      String infoName = getFieldWriteInfoFieldName(field.getName());
       if (isStatic)
       {
          code =
             "{" +
-            "   if (" + infoName + " == null && " + generatorName + " != null)" +
+            "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
             "   {" +
-            "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+            "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
             "   }" +
-            "   if (" + infoName + " == null)" +
+            "   if (" + joinpointName + " == null)" +
             "   { " +
             "   " + clazz.getName() + "." + field.getName() + " = $2;" +
             "   }" +
             "   else" +
             "   {" +
-            "   " + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($2);" +
+            "   " + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($2);" +
             "   }" +
             "}";
       }
@@ -327,17 +327,17 @@
       {
          code =
             "{" +
-            "   if (" + infoName + " == null && " + generatorName + " != null)" +
+            "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
             "   {" +
-            "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+            "      super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
             "   }" +
-            "   if (" + infoName + " == null)" +
+            "   if (" + joinpointName + " == null)" +
             "   { " +
             "   ((" + clazz.getName() + ")$1)." + field.getName() + " = $2;" +
             "   }" +
             "   else" +
             "   {" +
-            "   " + MethodExecutionTransformer.getAopReturnStr(false) + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "((" + clazz.getName() + ")$1, $2);" +
+            "   " + MethodExecutionTransformer.getAopReturnStr(false) + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "((" + clazz.getName() + ")$1, $2);" +
             "   }" +
             "}";
       }
@@ -352,7 +352,6 @@
       //Just delegate to method in advisor
       boolean isStatic = Modifier.isStatic(field.getModifiers());
 
-      String code;
       String advisor = isStatic ?
             "((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(clazz) + ")" + Instrumentor.HELPER_FIELD_NAME + ")" :
                "((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(clazz) + ")((" + clazz.getName() + ")$1)." + GeneratedAdvisorInstrumentor.GET_CURRENT_ADVISOR + ")";

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -693,13 +693,9 @@
             "   copy.setInterceptors( " + INSTANCE_ADVISOR_MIXIN + ".getWrappers(copy.getInterceptors()) );" +
             "   " + updatedAdvicesFieldName + " = false;" +
             "   " + names.getJoinPointField().getName() + " = null;" +
-            "   if (" + names.getGeneratorField().getName() + " == null)" +
-            "   {" +
-            "      " + names.getGeneratorField().getName() + " = super.getJoinPointGenerator(" + names.getInfoFieldName() + ");" +
-            "   }" +
-            "   " + names.getGeneratorField().getName() + ".rebindJoinpoint(copy);" +
+//            "   " + names.getInfoFieldName() + ".setInterceptors(copy.getInterceptors());" +  //We need a way to make this "transient" 
+            "   super.rebindJoinPointWithInstanceInformation(copy);" +
             "}";
-
          instanceAdvisorMethod.insertBefore(code);
          genInstanceAdvisor.addMethod(instanceAdvisorMethod);
       }
@@ -790,26 +786,18 @@
       }
    }
 
-   protected void addJoinPointGeneratorFieldToGenAdvisor(String name) throws CannotCompileException, NotFoundException
-   {
-      CtField field = new CtField(forName(JoinPointGenerator.class.getName()), name, genadvisor);
-      genadvisor.addField(field);
-   }
-
    private static class GeneratedAdvisorNameExtractor
    {
       //TODO This kind of sucks. We need a better way to link names of wrapper methods, generators, infos and joinpoints
       String infoName;
       CtMethod wrapper;
       CtField joinPointField;
-      CtField generatorField;
 
-      private GeneratedAdvisorNameExtractor(String infoName, CtMethod wrapper, CtField joinPointField, CtField generatorField)
+      private GeneratedAdvisorNameExtractor(String infoName, CtMethod wrapper, CtField joinPointField)
       {
          this.infoName = infoName;
          this.wrapper = wrapper;
          this.joinPointField = joinPointField;
-         this.generatorField = generatorField;
       }
 
       private static GeneratedAdvisorNameExtractor extractNames(CtClass genadvisor, CtField infoField) throws NotFoundException
@@ -836,13 +824,7 @@
                      FieldJoinPointGenerator.READ_JOINPOINT_FIELD_PREFIX + fieldName;
             CtField joinPointField = genadvisor.getDeclaredField(joinPointName);
 
-            String generatorName =
-               (isWrite) ?
-                     FieldJoinPointGenerator.WRITE_GENERATOR_PREFIX + fieldName :
-                        FieldJoinPointGenerator.READ_GENERATOR_PREFIX + fieldName;
-               CtField generatorField = genadvisor.getDeclaredField(generatorName);
-
-            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField, generatorField);
+            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField);
          }
          else if (infoField.getType().getName().equals(MethodInfo.class.getName()))
          {
@@ -856,10 +838,7 @@
             String joinPointName = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + methodNameHash;
             CtField joinPointField = genadvisor.getDeclaredField(joinPointName);
 
-            String generatorName = JoinPointGenerator.GENERATOR_PREFIX + methodNameHash;
-            CtField generatorField = genadvisor.getDeclaredField(generatorName);
-
-            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField, generatorField);
+            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField);
          }
          else if (infoField.getType().getName().equals(ConByMethodInfo.class.getName()))
          {
@@ -873,10 +852,7 @@
             String joinPointName = ConByMethodJoinPointGenerator.JOINPOINT_FIELD_PREFIX + infoName.substring("aop$constructorCall_".length());
             CtField joinPointField = genadvisor.getDeclaredField(joinPointName);
 
-            String generatorName = ConByMethodJoinPointGenerator.GENERATOR_PREFIX + infoName.substring("aop$constructorCall_".length());
-            CtField generatorField = genadvisor.getDeclaredField(generatorName);
-
-            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField, generatorField);
+            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField);
          }
          else if (infoField.getType().getName().equals(MethodByMethodInfo.class.getName()))
          {
@@ -890,10 +866,7 @@
             String joinPointName = MethodByMethodJoinPointGenerator.JOINPOINT_FIELD_PREFIX + infoName.substring("aop$methodCall_".length());
             CtField joinPointField = genadvisor.getDeclaredField(joinPointName);
 
-            String generatorName = MethodByMethodJoinPointGenerator.GENERATOR_PREFIX + infoName.substring("aop$methodCall_".length());
-            CtField generatorField = genadvisor.getDeclaredField(generatorName);
-
-            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField, generatorField);
+            return new GeneratedAdvisorNameExtractor(infoName, wrapper, joinPointField);
          }
 
          return null;
@@ -904,11 +877,6 @@
          return joinPointField;
       }
 
-      public CtField getGeneratorField()
-      {
-         return generatorField;
-      }
-
       public CtMethod getWrapper()
       {
          return wrapper;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -68,14 +68,9 @@
 
    public static String getJoinPointFieldName(MethodTransformation trans)
    {
-      return MethodJoinPointGenerator.getInfoFieldName(trans.getOriginalName(), trans.getHash());
+      return MethodJoinPointGenerator.getGeneratedJoinPointFieldName(trans.getOriginalName(), trans.getHash());
    }
 
-   public static String getJoinPointGeneratorFieldName(MethodTransformation trans)
-   {
-      return MethodJoinPointGenerator.getJoinPointGeneratorFieldName(trans.getOriginalName(), trans.getHash());
-   }
-
    private void addJoinpoint(String miname, MethodTransformation trans)throws CannotCompileException, NotFoundException
    {
       CtClass joinpoint = createJoinpointClass(miname, trans);
@@ -302,21 +297,22 @@
 
    private String createStaticAdvisorMethodBody(MethodTransformation trans)throws NotFoundException
    {
-      String infoName = getJoinPointFieldName(trans);
-      String generatorName = getJoinPointGeneratorFieldName(trans);
+      String joinpointName = getJoinPointFieldName(trans);
+      String infoName = getMethodInfoFieldName(trans.getOriginalName(), trans.getHash());
+
       String code =
          "{" +
-         "   if (" + infoName + " == null && " + generatorName + " != null)" +
+         "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
          "   {" +
-         "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+         "       super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
          "   }" +
-         "   if (" + infoName + " == null)" +
+         "   if (" + joinpointName + " == null)" +
          "   { " +
          "      " + getReturnStr(trans.getWMethod()) + trans.getClazzName() + "." + trans.getWrappedName() +"($$);" +
          "   }" +
          "   else" +
          "   {" +
-         "    " + getAopReturnStr(trans.getWMethod()) + infoName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+         "    " + getAopReturnStr(trans.getWMethod()) + joinpointName + "." + JoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
          "   }" +
          "}";
 
@@ -325,21 +321,22 @@
 
    private String createNonStaticAdvisorMethodBody(MethodTransformation trans, CtClass ga/*kill*/)throws NotFoundException
    {
-      String infoName = getJoinPointFieldName(trans);
-      String generatorName = getJoinPointGeneratorFieldName(trans);
+      String joinpointName = getJoinPointFieldName(trans);
+      String infoName = getMethodInfoFieldName(trans.getOriginalName(), trans.getHash());
+
       String code =
          "{" +
-         "   if (" + infoName + " == null && " + generatorName + " != null)" +
+         "   if (" + joinpointName + " == null && " + infoName + " != null && " + infoName + ".hasAdvices())" +
          "   {" +
-         "   " + generatorName + "." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(this.getClass().getClassLoader());" +
+         "       super." + JoinPointGenerator.GENERATE_JOINPOINT_CLASS + "(" + infoName + ");" +
          "   }" +
-         "   if (" + infoName + " == null)" +
+         "   if (" + joinpointName + " == null)" +
          "   { " +
          "      " + getAopReturnStr(trans.getWMethod()) + "$1." + trans.getWrappedName() + "(" + getNonStaticJavasistParamString(trans.getWMethod().getParameterTypes().length) + ");" +
          "   }" +
          "   else" +
          "   {" +
-         "    " + getAopReturnStr(trans.getWMethod()) + infoName + "." + MethodJoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
+         "    " + getAopReturnStr(trans.getWMethod()) + joinpointName + "." + MethodJoinPointGenerator.INVOKE_JOINPOINT + "($$);" +
          "   }" +
          "}";
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -45,6 +45,7 @@
 
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.CallerConstructorInfo;
+import org.jboss.aop.ConByConInfo;
 import org.jboss.aop.GeneratedClassAdvisor;
 import org.jboss.aop.InstanceAdvisor;
 import org.jboss.aop.JoinPointInfo;
@@ -66,185 +67,6 @@
  */
 public abstract class JoinPointGenerator
 {
-   // TODO replace by enum
-   protected static class JoinPointParameters {
-      public static final JoinPointParameters ONLY_ARGS = new JoinPointParameters(false, -1, false, -1, 0, null);
-      public static final JoinPointParameters TARGET_ARGS = new JoinPointParameters(true, 1, false, -1, 1, "$1");
-      public static final JoinPointParameters CALLER_ARGS = new JoinPointParameters(false, -1, true, 1, 1, "$1");
-      public static final JoinPointParameters TARGET_CALLER_ARGS = new JoinPointParameters(true, 1, true, 2, 2, "$1, $2");
-      
-      private boolean target;
-      private boolean caller;
-      
-      private int targetIndex;
-      private int callerIndex;
-      private int firstArgIndex;
-      private String targetCallerList;
-      
-      private JoinPointParameters(boolean target, int targetIndex, boolean caller, int callerIndex, int firstArgIndex, String targetCallerList)
-      {
-         this.target = target;
-         this.targetIndex = targetIndex;
-         this.caller = caller;
-         this.callerIndex = callerIndex;
-         this.firstArgIndex = firstArgIndex + 1;
-         this.targetCallerList = targetCallerList;
-      }
-      
-      public final boolean hasTarget()
-      {
-         return target;
-      }
-      
-      public final int getTargetIndex()
-      {
-         return targetIndex;
-      }
-      
-      public final boolean hasCaller()
-      {
-         return caller;
-      }
-      
-      public final int getCallerIndex()
-      {
-         return callerIndex;
-      }
-      
-      public final int getFirstArgIndex()
-      {
-         return firstArgIndex;
-      }
-      
-      public final String declareArgsArray(int totalParameters)
-      {
-         StringBuffer buffer = new StringBuffer("Object[] ");
-         buffer.append(ARGUMENTS);
-         if (++totalParameters == firstArgIndex)
-         {
-            buffer.append(" = new Object[0];");
-         }
-         else
-         {
-            buffer.append(" = new Object[]{($w)$");
-            buffer.append(firstArgIndex);
-            for (int i = firstArgIndex + 1; i < totalParameters; i++)
-            {
-               buffer.append(", ($w)$");
-               buffer.append(i);
-            }
-            buffer.append("};");
-         }
-         return buffer.toString();
-      }
-      
-      public final void appendParameterList(StringBuffer code, CtClass[] parameterTypes)
-      {
-
-         int j = firstArgIndex - 1;
-         int totalParameters = parameterTypes.length - j;
-         if (targetCallerList != null)
-         {
-            code.append(targetCallerList);
-         }
-         if (totalParameters == 0)
-         {
-            return;
-         }
-         if (targetCallerList != null)
-         {
-            code.append(", ");
-         }
-
-         castArgument(code, parameterTypes[j++], 0);
-
-         for (int i = 1; i < totalParameters; i++, j++)
-         {
-            code.append(", ");
-            castArgument(code, parameterTypes[j], i);
-         }
-      }
-      
-      public final void appendParameterListWithoutArgs(StringBuffer code)
-      {
-         if (targetCallerList != null)
-         {
-            code.append(',');
-            code.append(targetCallerList);
-         }
-      }
-      
-      
-      private static final String[][] primitiveExtractions;
-
-      static{
-         primitiveExtractions = new String[][]{
-               {"((Boolean) " + ARGUMENTS + " [", "]).booleanValue()"},
-               {"((Integer) " + ARGUMENTS + "[", "]).intValue()"},
-               {"((Double) " + ARGUMENTS + "[", "]).doubleValue()"},
-               {"((Float) " + ARGUMENTS + "[", "]).floatValue()"},
-               {"((Character) " + ARGUMENTS + "[", "]).charValue()"},
-               {"((Byte) " + ARGUMENTS + " [", "]).byteValue()"},
-               {"((Long) " + ARGUMENTS + "[", "]).longValue()"},
-               {"((Short) " + ARGUMENTS + "[", "]).shortValue()"}
-         };
-      }
-      
-      public final void castArgument(StringBuffer code, CtClass expectedType, int i)
-      {
-
-         if (expectedType.isPrimitive())
-         {
-            String[] extraction = null;
-            if (expectedType == CtClass.booleanType)
-            {
-               extraction = primitiveExtractions[0];
-            }
-            else if (expectedType == CtClass.intType)
-            {
-               extraction = primitiveExtractions[1];
-            }
-            else if (expectedType == CtClass.doubleType)
-            {
-               extraction = primitiveExtractions[2];
-            }
-            else if (expectedType == CtClass.floatType)
-            {
-               extraction = primitiveExtractions[3];
-            }
-            else if (expectedType == CtClass.charType)
-            {
-               extraction = primitiveExtractions[4];
-            }
-            else if (expectedType == CtClass.byteType)
-            {
-               extraction = primitiveExtractions[5];
-            }
-            else if (expectedType == CtClass.longType)
-            {
-               extraction = primitiveExtractions[6];
-            }
-            else if (expectedType == CtClass.shortType)
-            {
-               extraction = primitiveExtractions[7];
-            }
-            code.append(extraction[0]);
-            code.append(i);
-            code.append(extraction[1]);
-         }
-         else
-         {
-            code.append("(");
-            code.append(expectedType.getName());
-            code.append(") ");
-            code.append(ARGUMENTS);
-            code.append("[");
-            code.append(i);
-            code.append("]");
-         }
-      }
-   }
-   
    public static final String INFO_FIELD = "info";
    public static final String INVOKE_JOINPOINT = "invokeJoinpoint";
    public static final String INVOKE_TARGET = "invokeTarget";
@@ -256,7 +78,6 @@
    private static final String CURRENT_ADVICE = "super.currentInterceptor";
    public static final String JOINPOINT_FIELD_PREFIX = "joinpoint_";
    public static final String JOINPOINT_CLASS_PREFIX = "JoinPoint_";
-   public static final String GENERATOR_PREFIX = "generator_";
    private static final String RETURN_VALUE = "ret";
    private static final String THROWABLE = "t";
    protected static final String ARGUMENTS= "arguments";
@@ -265,26 +86,23 @@
    private final ArrayList<Integer> joinPointArguments;
    
    
-   private JoinPointInfo oldInfo;
-   protected JoinPointInfo info;
    private JoinPointParameters parameters;
    private static int increment;
    private Class advisorClass;
-   protected GeneratedClassAdvisor advisor;
+   private String baseJoinPointClassName;
    protected String joinpointClassName;
    protected String joinpointFieldName;
    private String joinpointFqn;
    private Field joinpointField;
-   private Field generatorField;
    private boolean initialised;
    private ThreadLocal<Set<Integer>> inconsistentTypeArgs;
    
    protected JoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info,
          JoinPointParameters parameters, int argumentsSize)
    {
-      this.info = info;
+//      this.info = info;
       this.parameters = parameters;
-      this.advisor = advisor;
+//      this.advisor = advisor;
       this.advisorClass = advisor.getClass();
       Class[] interfaces = advisorClass.getInterfaces();
       
@@ -314,35 +132,33 @@
             return new HashSet<Integer>();
          }
       };
-      
-      initialiseJoinPointNames();
+    
+      initialiseJoinPointNames(info);
       findAdvisedField(advisorClass, info);
+      initBaseJoinPointClassName(advisor);
    }
    
+   private void initBaseJoinPointClassName(GeneratedClassAdvisor advisor)
+   {
+      Package pkg = advisor.getClass().getPackage();
+      
+      StringBuffer className = new StringBuffer();
+      if (pkg != null)
+      {
+         className.append(pkg.getName());
+         className.append(".");
+      }
+      className.append(joinpointClassName);
+      className.append("_");
+      baseJoinPointClassName = className.toString();
+   }
+   
    public void rebindJoinpoint(JoinPointInfo newInfo)
    {
       try
       {
          if (joinpointField == null) return;
-         if (initialised && oldInfo != null)
-         {
-            //We are not changing any of the bindings
-            if (oldInfo.equalChains(newInfo)) return;
-         }
-         oldInfo = info.copy();
-         info = newInfo;
-
-         joinpointField.set(advisor, null);
-
-         if (info.getInterceptors() == null)
-         {
-            //Turn off interceptions, by setting the generator to null
-            generatorField.set(advisor, null);
-         }
-         else
-         {
-            generatorField.set(advisor, this);
-         }
+         joinpointField.set(newInfo.getAdvisor(), null);
       }
       catch (Exception e)
       {
@@ -356,21 +172,25 @@
     */
    public void generateJoinPointClass()
    {
-      generateJoinPointClass(null);
+      generateJoinPointClass(null, null);
    }
    
    /**
     * Called by the joinpoint if a interceptors were regenereated
     */
-   public synchronized void generateJoinPointClass(ClassLoader classloader)
+   public synchronized void generateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
    {
+      if (info == null)
+      {
+         throw new RuntimeException("GeneratedAdvisor weaving in AOP 2.0.0.aplha5 and later is not compatible with that of previous versions");
+      }
       if (System.getSecurityManager() == null)
       {
-         GenerateJoinPointClassAction.NON_PRIVILEGED.generateJoinPointClass(classloader, this);
+         GenerateJoinPointClassAction.NON_PRIVILEGED.generateJoinPointClass(classloader, this, info);
       }
       else
       {
-         GenerateJoinPointClassAction.PRIVILEGED.generateJoinPointClass(classloader, this);
+         GenerateJoinPointClassAction.PRIVILEGED.generateJoinPointClass(classloader, this, info);
       }
    }
     
@@ -378,7 +198,7 @@
     * Does the work for generateJoinPointClass()
     * @see JoinPointGenerator#generateJoinPointClass()
     */
-   private void doGenerateJoinPointClass(ClassLoader classloader)
+   private void doGenerateJoinPointClass(ClassLoader classloader, JoinPointInfo info)
    {
       try
       {
@@ -394,9 +214,9 @@
          
          ProtectionDomain pd = advisorClass.getProtectionDomain();
          Class clazz = toClass(pool, generatedClass.getGenerated(), pd);
-         Object obj = instantiateClass(clazz, generatedClass.getAroundSetups());
+         Object obj = instantiateClass(clazz, generatedClass.getAroundSetups(), info);
          
-         joinpointField.set(advisor, obj);
+         joinpointField.set(info.getAdvisor(), obj);
       }
       catch (Throwable e)
       {
@@ -413,7 +233,7 @@
       return TransformerCommon.toClass(ctclass, pd);
    }
    
-   private Object instantiateClass(Class clazz, AdviceSetup[] aroundSetups) throws Exception
+   private Object instantiateClass(Class clazz, AdviceSetup[] aroundSetups, JoinPointInfo info) throws Exception
    {
       Constructor ctor = clazz.getConstructor(new Class[] {info.getClass()});
       Object obj;
@@ -463,7 +283,7 @@
       return ++increment;
    }
    
-   protected abstract void initialiseJoinPointNames();
+   protected abstract void initialiseJoinPointNames(JoinPointInfo info);
 
    private GeneratedClassInfo generateJoinpointClass(ClassPool pool, JoinPointInfo newInfo) throws NotFoundException,
    CannotCompileException, ClassNotFoundException
@@ -476,16 +296,17 @@
          clazz.setSuperclass(superClass);
          addUntransformableInterface(pool, clazz);
   
-         AdviceSetupsByType setups = initialiseAdviceInfosAndAddFields(pool, clazz);
+         AdviceSetupsByType setups = initialiseAdviceInfosAndAddFields(pool, clazz, newInfo);
          
          createConstructors(pool, superClass, clazz, setups);
          createJoinPointInvokeMethod(
                superClass, 
                clazz, 
                isVoid(),
-               setups);
+               setups,
+               newInfo);
   
-         createInvokeNextMethod(clazz, isVoid(), setups.getAroundSetups());
+         createInvokeNextMethod(clazz, isVoid(), setups.getAroundSetups(), newInfo);
   
          overrideDispatchMethods(superClass, clazz, newInfo);
          return new GeneratedClassInfo(clazz, setups.getAroundSetups());
@@ -509,24 +330,12 @@
 
    private String getJoinpointClassName()
    {
-      Package pkg = advisor.getClass().getPackage();
-      
-      StringBuffer className = new StringBuffer();
-      if (pkg != null)
-      {
-         className.append(pkg.getName());
-         className.append(".");
-      }
-      className.append(joinpointClassName);
-      className.append("_");
-      className.append(getIncrement());
-      
-      return className.toString();
+      return baseJoinPointClassName + getIncrement();
    }
 
    protected abstract boolean isVoid();
    protected abstract Class getReturnType(); 
-   protected abstract AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup);
+   protected abstract AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup);
    
    protected boolean isCaller()
    {
@@ -570,18 +379,6 @@
             joinpointField = advisorSuperClazz.getDeclaredField(joinpointFieldName);
             SecurityActions.setAccessible(joinpointField);
             joinpointFqn = advisorSuperClazz.getDeclaringClass().getName() + "$" + joinpointClassName;
-            
-            try
-            {
-               generatorField = advisorSuperClazz.getDeclaredField(getJoinPointGeneratorFieldName());
-               SecurityActions.setAccessible(generatorField);
-            }
-            catch(NoSuchFieldException e)
-            {
-               throw new RuntimeException("Found joinpoint field " + 
-                     joinpointField.getName() + " in " + advisorSuperClazz.getName() +
-                     " but no JoinPointGenerator field called " + getJoinPointGeneratorFieldName());
-            }
          }
          catch (NoSuchFieldException e)
          {
@@ -598,19 +395,19 @@
       }
    }
 
-   private AdviceSetupsByType initialiseAdviceInfosAndAddFields(ClassPool pool, CtClass clazz) throws ClassNotFoundException, NotFoundException, CannotCompileException
+   private AdviceSetupsByType initialiseAdviceInfosAndAddFields(ClassPool pool, CtClass clazz, JoinPointInfo info) throws ClassNotFoundException, NotFoundException, CannotCompileException
    {
       HashMap<String, Integer> cflows = new HashMap<String, Integer>();
       AdviceSetup[] setups = new AdviceSetup[info.getInterceptors().length];
 
       for (int i = 0 ; i < info.getInterceptors().length ; i++)
       {
-         setups[i] = new AdviceSetup(i, (GeneratedAdvisorInterceptor)info.getInterceptors()[i]);
+         setups[i] = new AdviceSetup(i, (GeneratedAdvisorInterceptor)info.getInterceptors()[i], info);
          addAspectFieldAndGetter(pool, clazz, setups[i]);
          addCFlowFieldsAndGetters(pool, setups[i], clazz, cflows);
       }
    
-      return new AdviceSetupsByType(setups);
+      return new AdviceSetupsByType(info, setups);
    }
    
    private void addAspectFieldAndGetter(ClassPool pool, CtClass clazz, AdviceSetup setup) throws NotFoundException, CannotCompileException
@@ -710,7 +507,7 @@
       }
    }
    
-   private void createJoinPointInvokeMethod(CtClass superClass, CtClass clazz, boolean isVoid, AdviceSetupsByType setups) throws CannotCompileException, NotFoundException
+   private void createJoinPointInvokeMethod(CtClass superClass, CtClass clazz, boolean isVoid, AdviceSetupsByType setups, JoinPointInfo info) throws CannotCompileException, NotFoundException
    {
       CtMethod superInvoke = superClass.getDeclaredMethod(INVOKE_JOINPOINT);
       String code = null;
@@ -719,7 +516,7 @@
          code = createJoinpointInvokeBody(
                clazz, 
                setups,
-               superInvoke.getExceptionTypes(), superInvoke.getParameterTypes());
+               superInvoke.getExceptionTypes(), superInvoke.getParameterTypes(), info);
          CtMethod invoke = CtNewMethod.make(
                superInvoke.getReturnType(), 
                superInvoke.getName(), 
@@ -736,7 +533,7 @@
    }
    
    private String createJoinpointInvokeBody(CtClass joinpointClass,
-         AdviceSetupsByType setups, CtClass[] declaredExceptions, CtClass[] parameterTypes)throws NotFoundException
+         AdviceSetupsByType setups, CtClass[] declaredExceptions, CtClass[] parameterTypes, JoinPointInfo info)throws NotFoundException
    {
       StringBuffer code = new StringBuffer();
       code.append("{");
@@ -760,7 +557,7 @@
       code.append("   try");
       code.append("   {");
       boolean argsFoundBefore = DefaultAdviceCallStrategy.getInstance().
-         addInvokeCode(this, setups.getBeforeSetups(), code);
+         addInvokeCode(this, setups.getBeforeSetups(), code, info);
       
       // add around according to whether @Args were found before
       boolean joinPointCreated = addAroundInvokeCode(code, setups, joinpointClass,
@@ -769,12 +566,12 @@
       // generate after code
       StringBuffer afterCode = new StringBuffer();
       boolean argsFoundAfter = AfterAdviceCallStrategy.getInstance().addInvokeCode(
-            this, setups.getAfterSetups(), afterCode);
+            this, setups.getAfterSetups(), afterCode, info);
       afterCode.append("   }");
       afterCode.append("   catch(java.lang.Throwable " + THROWABLE + ")");
       afterCode.append("   {");
       argsFoundAfter = DefaultAdviceCallStrategy.getInstance().addInvokeCode(this,
-            setups.getThrowingSetups(), afterCode) || argsFoundAfter;
+            setups.getThrowingSetups(), afterCode, info) || argsFoundAfter;
       
       // if joinpoint has been created for around,
       // need to update arguments variable when this variable is used,
@@ -918,14 +715,14 @@
       code.append("throw new java.lang.RuntimeException(t);");
    }
 
-   private void createInvokeNextMethod(CtClass jp, boolean isVoid, AdviceSetup[] aroundSetups) throws NotFoundException, CannotCompileException
+   private void createInvokeNextMethod(CtClass jp, boolean isVoid, AdviceSetup[] aroundSetups, JoinPointInfo info) throws NotFoundException, CannotCompileException
    {
       if (aroundSetups == null) return;
       
       CtMethod method = jp.getSuperclass().getSuperclass().getDeclaredMethod("invokeNext");
       CtMethod invokeNext = CtNewMethod.copy(method, jp, null);
       
-      String code = createInvokeNextMethodBody(jp, isVoid, aroundSetups);
+      String code = createInvokeNextMethodBody(jp, isVoid, aroundSetups, info);
       
       try
       {
@@ -939,7 +736,7 @@
       jp.addMethod(invokeNext);
    }
 
-   private String createInvokeNextMethodBody(CtClass jp, boolean isVoid, AdviceSetup[] aroundSetups) throws NotFoundException
+   private String createInvokeNextMethodBody(CtClass jp, boolean isVoid, AdviceSetup[] aroundSetups, JoinPointInfo info) throws NotFoundException
    {
       final String returnStr = (isVoid) ? "" : "return ($w)";
 
@@ -947,7 +744,7 @@
       body.append("{");
       body.append("   try{");
       body.append("      switch(++" + CURRENT_ADVICE + "){");
-      AroundAdviceCallStrategy.getInstance().addInvokeCode(this, aroundSetups, body);
+      AroundAdviceCallStrategy.getInstance().addInvokeCode(this, aroundSetups, body, info);
       body.append("      default:");
       body.append("         " + returnStr + "this.dispatch();");
       body.append("      }");
@@ -1300,7 +1097,6 @@
       clazz.addInterface(untransformable);
    }
 
-   protected abstract String getJoinPointGeneratorFieldName();
    protected static String getMethodString(CtClass joinpoint, String method, CtClass[] params)
    {
       StringBuffer sb = new StringBuffer();
@@ -1334,7 +1130,7 @@
       boolean isThrowing;
       AdviceMethodProperties adviceMethodProperties;
       
-      AdviceSetup(int index, GeneratedAdvisorInterceptor ifw) throws ClassNotFoundException, NotFoundException
+      AdviceSetup(int index, GeneratedAdvisorInterceptor ifw, JoinPointInfo info) throws ClassNotFoundException, NotFoundException
       {
          this.index = index;
          scope = ifw.getScope();
@@ -1549,7 +1345,7 @@
       AdviceSetup[] throwingSetups;
       AdviceSetup[] aroundSetups;
 
-      AdviceSetupsByType(AdviceSetup[] setups)
+      AdviceSetupsByType(JoinPointInfo info, AdviceSetup[] setups)
       {
          allSetups = setups;
          ArrayList<AdviceSetup> beforeAspects = null;
@@ -1563,7 +1359,7 @@
             {
                if (beforeAspects == null) beforeAspects = new ArrayList<AdviceSetup>();
                
-               AdviceMethodProperties properties = AdviceMethodFactory.BEFORE.findAdviceMethod(getAdviceMethodProperties(setups[i]));
+               AdviceMethodProperties properties = AdviceMethodFactory.BEFORE.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
                if (properties != null)
                {
                   setups[i].setAdviceMethodProperties(properties);
@@ -1574,7 +1370,7 @@
             else if (setups[i].isAfter())
             {
                if (afterAspects == null) afterAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.AFTER.findAdviceMethod(getAdviceMethodProperties(setups[i]));
+               AdviceMethodProperties properties = AdviceMethodFactory.AFTER.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
                if (properties != null)
                {
                   setups[i].setAdviceMethodProperties(properties);
@@ -1585,7 +1381,7 @@
             else if (setups[i].isThrowing())
             {
                if (throwingAspects == null) throwingAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.THROWING.findAdviceMethod(getAdviceMethodProperties(setups[i]));
+               AdviceMethodProperties properties = AdviceMethodFactory.THROWING.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
                if (properties != null)
                {
                   setups[i].setAdviceMethodProperties(properties);
@@ -1596,7 +1392,7 @@
             else
             {
                if (aroundAspects == null) aroundAspects = new ArrayList<AdviceSetup>();
-               AdviceMethodProperties properties = AdviceMethodFactory.AROUND.findAdviceMethod(getAdviceMethodProperties(setups[i]));
+               AdviceMethodProperties properties = AdviceMethodFactory.AROUND.findAdviceMethod(getAdviceMethodProperties(info, setups[i]));
                if (properties != null)
                {
                   setups[i].setAdviceMethodProperties(properties);
@@ -1647,11 +1443,11 @@
 
    private interface GenerateJoinPointClassAction
    {
-      void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator);
+      void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info);
       
       GenerateJoinPointClassAction PRIVILEGED = new GenerateJoinPointClassAction()
       {
-         public void generateJoinPointClass(final ClassLoader classloader, final JoinPointGenerator joinPointGenerator) 
+         public void generateJoinPointClass(final ClassLoader classloader, final JoinPointGenerator joinPointGenerator, final JoinPointInfo info) 
          {
             try
             {
@@ -1659,7 +1455,7 @@
                {
                   public Object run() throws Exception
                   {
-                     joinPointGenerator.doGenerateJoinPointClass(classloader);
+                     joinPointGenerator.doGenerateJoinPointClass(classloader, info);
                      return null;
                   }
                });
@@ -1678,9 +1474,9 @@
 
       GenerateJoinPointClassAction NON_PRIVILEGED = new GenerateJoinPointClassAction()
       {
-         public void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator)
+         public void generateJoinPointClass(ClassLoader classloader, JoinPointGenerator joinPointGenerator, JoinPointInfo info)
          {
-            joinPointGenerator.doGenerateJoinPointClass(classloader);
+            joinPointGenerator.doGenerateJoinPointClass(classloader, info);
          }
       };
    }
@@ -1689,7 +1485,7 @@
    private static abstract class AdviceCallStrategy
    {
       public boolean addInvokeCode(JoinPointGenerator generator,
-            AdviceSetup[] setups, StringBuffer code) throws NotFoundException
+            AdviceSetup[] setups, StringBuffer code, JoinPointInfo info) throws NotFoundException
       {
          StringBuffer call = new StringBuffer();
          if (setups == null || setups.length == 0)
@@ -1701,7 +1497,7 @@
          for (int i = 0 ; i < setups.length ; i++)
          {
             call.setLength(0);
-            argsFound = appendAdviceCall(setups[i], key, code, call, generator)
+            argsFound = appendAdviceCall(setups[i], key, code, call, generator, info)
                || argsFound;
             code.append(call);
             call.setLength(0);
@@ -1711,7 +1507,7 @@
       
       protected abstract String generateKey(JoinPointGenerator generator);
       protected abstract boolean appendAdviceCall(AdviceSetup setup, String key,
-           StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator) throws NotFoundException;
+           StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info) throws NotFoundException;
       
       private final boolean appendAdviceCall(AdviceSetup setup,
             StringBuffer beforeCall, StringBuffer call,
@@ -1928,7 +1724,7 @@
       }
       
       public boolean appendAdviceCall(AdviceSetup setup, String key,
-            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator)
+            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info)
       {
          if (!setup.shouldInvokeAspect())
          {
@@ -1938,7 +1734,7 @@
       
          boolean result = false;
          AdviceMethodProperties properties = AdviceMethodFactory.AROUND.
-            findAdviceMethod(generator.getAdviceMethodProperties(setup));
+            findAdviceMethod(generator.getAdviceMethodProperties(info, setup));
          if (properties == null || properties.getAdviceMethod() == null)
          {
             // throw new RuntimeException("DEBUG ONLY Properties was null " + 
@@ -2063,7 +1859,7 @@
       }
       
       public boolean appendAdviceCall(AdviceSetup setup, String key,
-            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator)
+            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info)
       {
          return super.appendAdviceCall(setup, beforeCall, call, false, generator);
       }
@@ -2091,7 +1887,7 @@
       }
 
       public boolean appendAdviceCall(AdviceSetup setup, String key,
-            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator) throws NotFoundException
+            StringBuffer beforeCall, StringBuffer call, JoinPointGenerator generator, JoinPointInfo info) throws NotFoundException
       {
          AdviceMethodProperties properties = setup.getAdviceMethodProperties();
          if (properties != null && !properties.isAdviceVoid())
@@ -2101,4 +1897,184 @@
          return super.appendAdviceCall(setup, beforeCall, call, false, generator);
       }
    }
+
+   // TODO replace by enum
+   protected static class JoinPointParameters {
+      public static final JoinPointParameters ONLY_ARGS = new JoinPointParameters(false, -1, false, -1, 0, null);
+      public static final JoinPointParameters TARGET_ARGS = new JoinPointParameters(true, 1, false, -1, 1, "$1");
+      public static final JoinPointParameters CALLER_ARGS = new JoinPointParameters(false, -1, true, 1, 1, "$1");
+      public static final JoinPointParameters TARGET_CALLER_ARGS = new JoinPointParameters(true, 1, true, 2, 2, "$1, $2");
+      
+      private boolean target;
+      private boolean caller;
+      
+      private int targetIndex;
+      private int callerIndex;
+      private int firstArgIndex;
+      private String targetCallerList;
+      
+      private JoinPointParameters(boolean target, int targetIndex, boolean caller, int callerIndex, int firstArgIndex, String targetCallerList)
+      {
+         this.target = target;
+         this.targetIndex = targetIndex;
+         this.caller = caller;
+         this.callerIndex = callerIndex;
+         this.firstArgIndex = firstArgIndex + 1;
+         this.targetCallerList = targetCallerList;
+      }
+      
+      public final boolean hasTarget()
+      {
+         return target;
+      }
+      
+      public final int getTargetIndex()
+      {
+         return targetIndex;
+      }
+      
+      public final boolean hasCaller()
+      {
+         return caller;
+      }
+      
+      public final int getCallerIndex()
+      {
+         return callerIndex;
+      }
+      
+      public final int getFirstArgIndex()
+      {
+         return firstArgIndex;
+      }
+      
+      public final String declareArgsArray(int totalParameters)
+      {
+         StringBuffer buffer = new StringBuffer("Object[] ");
+         buffer.append(ARGUMENTS);
+         if (++totalParameters == firstArgIndex)
+         {
+            buffer.append(" = new Object[0];");
+         }
+         else
+         {
+            buffer.append(" = new Object[]{($w)$");
+            buffer.append(firstArgIndex);
+            for (int i = firstArgIndex + 1; i < totalParameters; i++)
+            {
+               buffer.append(", ($w)$");
+               buffer.append(i);
+            }
+            buffer.append("};");
+         }
+         return buffer.toString();
+      }
+      
+      public final void appendParameterList(StringBuffer code, CtClass[] parameterTypes)
+      {
+
+         int j = firstArgIndex - 1;
+         int totalParameters = parameterTypes.length - j;
+         if (targetCallerList != null)
+         {
+            code.append(targetCallerList);
+         }
+         if (totalParameters == 0)
+         {
+            return;
+         }
+         if (targetCallerList != null)
+         {
+            code.append(", ");
+         }
+
+         castArgument(code, parameterTypes[j++], 0);
+
+         for (int i = 1; i < totalParameters; i++, j++)
+         {
+            code.append(", ");
+            castArgument(code, parameterTypes[j], i);
+         }
+      }
+      
+      public final void appendParameterListWithoutArgs(StringBuffer code)
+      {
+         if (targetCallerList != null)
+         {
+            code.append(',');
+            code.append(targetCallerList);
+         }
+      }
+      
+      
+      private static final String[][] primitiveExtractions;
+
+      static{
+         primitiveExtractions = new String[][]{
+               {"((Boolean) " + ARGUMENTS + " [", "]).booleanValue()"},
+               {"((Integer) " + ARGUMENTS + "[", "]).intValue()"},
+               {"((Double) " + ARGUMENTS + "[", "]).doubleValue()"},
+               {"((Float) " + ARGUMENTS + "[", "]).floatValue()"},
+               {"((Character) " + ARGUMENTS + "[", "]).charValue()"},
+               {"((Byte) " + ARGUMENTS + " [", "]).byteValue()"},
+               {"((Long) " + ARGUMENTS + "[", "]).longValue()"},
+               {"((Short) " + ARGUMENTS + "[", "]).shortValue()"}
+         };
+      }
+      
+      public final void castArgument(StringBuffer code, CtClass expectedType, int i)
+      {
+
+         if (expectedType.isPrimitive())
+         {
+            String[] extraction = null;
+            if (expectedType == CtClass.booleanType)
+            {
+               extraction = primitiveExtractions[0];
+            }
+            else if (expectedType == CtClass.intType)
+            {
+               extraction = primitiveExtractions[1];
+            }
+            else if (expectedType == CtClass.doubleType)
+            {
+               extraction = primitiveExtractions[2];
+            }
+            else if (expectedType == CtClass.floatType)
+            {
+               extraction = primitiveExtractions[3];
+            }
+            else if (expectedType == CtClass.charType)
+            {
+               extraction = primitiveExtractions[4];
+            }
+            else if (expectedType == CtClass.byteType)
+            {
+               extraction = primitiveExtractions[5];
+            }
+            else if (expectedType == CtClass.longType)
+            {
+               extraction = primitiveExtractions[6];
+            }
+            else if (expectedType == CtClass.shortType)
+            {
+               extraction = primitiveExtractions[7];
+            }
+            code.append(extraction[0]);
+            code.append(i);
+            code.append(extraction[1]);
+         }
+         else
+         {
+            code.append("(");
+            code.append(expectedType.getName());
+            code.append(") ");
+            code.append(ARGUMENTS);
+            code.append("[");
+            code.append(i);
+            code.append("]");
+         }
+      }
+   }
+   
 }
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByConJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 
 import javassist.CannotCompileException;
@@ -42,7 +43,6 @@
 
 public class MethodByConJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "MByC_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "MByC_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "MByC_";
    private static final Class INVOCATION_TYPE = MethodCalledByConstructorInvocation.class;
@@ -59,10 +59,18 @@
       }
    }
 
+   boolean hasTargetObject;
+   WeakReference returnType;
+   
    public MethodByConJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, getParameters((MethodByConInfo) info),
             ((MethodByConInfo) info).getMethod().getParameterTypes().length);
+      if (!((MethodByConInfo)info).getMethod().getReturnType().equals(Void.TYPE))
+      {
+         returnType = new WeakReference(((MethodByConInfo)info).getMethod().getReturnType());         
+      }
+      hasTargetObject = !java.lang.reflect.Modifier.isStatic(((MethodByConInfo)info).getMethod().getModifiers());
    }
    
    private static JoinPointParameters getParameters(MethodByConInfo info)
@@ -74,47 +82,51 @@
       return JoinPointParameters.TARGET_ARGS;
    }
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               callingIndex(),
-               calledClass(),
-               calledMethodHash());
+      MethodByConInfo minfo = (MethodByConInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               callingIndex(minfo),
+               calledClass(minfo),
+               calledMethodHash(minfo));
 
-      joinpointFieldName = getInfoFieldName(
-            callingIndex(),
-            calledClass(),
-            calledMethodHash());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+            callingIndex(minfo),
+            calledClass(minfo),
+            calledMethodHash(minfo));
    }
 
-   private int callingIndex()
+   private int callingIndex(MethodByConInfo info)
    {
-      return ((MethodByConInfo)info).getCallingIndex();
+      return info.getCallingIndex();
    }
 
-   private String calledClass()
+   private String calledClass(MethodByConInfo info)
    {
-      return ((MethodByConInfo)info).getCalledClass().getName();
+      return info.getCalledClass().getName();
    }
 
-   private long calledMethodHash()
+   private long calledMethodHash(MethodByConInfo info)
    {
-      return ((MethodByConInfo)info).getCalledMethodHash();
+      return info.getCalledMethodHash();
 
    }
 
    protected boolean isVoid()
    {
-      return ((MethodByConInfo)info).getMethod().getReturnType().equals(Void.TYPE);
+      return getReturnType() == null;
    }
 
    protected Class getReturnType()
    {
-      if (isVoid()) return null;
-      return ((MethodByConInfo)info).getMethod().getReturnType();
+      if (returnType == null)
+      {
+         return null;
+      }
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Method method = ((MethodByConInfo)info).getMethod();
       return new AdviceMethodProperties(
@@ -143,7 +155,7 @@
 
    protected boolean hasTargetObject()
    {
-      return !java.lang.reflect.Modifier.isStatic(((MethodByConInfo)info).getMethod().getModifiers());
+      return hasTargetObject;
    }
 
    protected static CtClass createJoinpointBaseClass(
@@ -155,33 +167,20 @@
             long calledHash,
             String ciname) throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(callingIndex, classname, calledHash));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, callingClass, callingIndex, classname, targetMethod, calledHash, ciname);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointClassName(int callingIndex, String classname, long calledHash)
    {
-      return getJoinPointGeneratorFieldName(callingIndex(), calledClass(), calledMethodHash());
-   }
-
-   protected static String getInfoClassName(int callingIndex, String classname, long calledHash)
-   {
       return JOINPOINT_CLASS_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
    }
 
-   protected static String getInfoFieldName(int callingIndex, String classname, long calledHash)
+   protected static String getGeneratedJoinPointFieldName(int callingIndex, String classname, long calledHash)
    {
       return JOINPOINT_FIELD_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
    }
 
-   protected static String getJoinPointGeneratorFieldName(int callingIndex, String classname, long calledHash)
-   {
-      return GENERATOR_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingIndex, classname, calledHash);
-   }
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -242,7 +241,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(callingIndex, targetClass.getName(), calledHash);
+         String className = getGeneratedJoinPointClassName(callingIndex, targetClass.getName(), calledHash);
 
          //Create inner joinpoint class in advised class, super class is ConstructorInvocation
          jp = TransformerCommon.makeNestedClass(callingClass, className, true);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodByMethodJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 
 import javassist.CannotCompileException;
@@ -42,7 +43,6 @@
 
 public class MethodByMethodJoinPointGenerator extends JoinPointGenerator
 {
-   public static final String GENERATOR_PREFIX = JoinPointGenerator.GENERATOR_PREFIX + "MByM_";
    public static final String JOINPOINT_CLASS_PREFIX = JoinPointGenerator.JOINPOINT_CLASS_PREFIX + "MByM_";
    public static final String JOINPOINT_FIELD_PREFIX = JoinPointGenerator.JOINPOINT_FIELD_PREFIX + "MByM_";
    private static final Class INVOCATION_TYPE = MethodCalledByMethodInvocation.class;
@@ -59,10 +59,21 @@
       }
    }
 
+   WeakReference returnType;
+   boolean hasCallingObject;
+   boolean hasTargetObject;
+   
    public MethodByMethodJoinPointGenerator(GeneratedClassAdvisor advisor, JoinPointInfo info)
    {
       super(advisor, info, getParameters((MethodByMethodInfo) info),
             ((MethodByMethodInfo) info).getMethod().getParameterTypes().length);
+
+      if (!((MethodByMethodInfo)info).getMethod().getReturnType().equals(Void.TYPE))
+      {
+         returnType = new WeakReference(((MethodByMethodInfo)info).getMethod().getReturnType());         
+      }
+      hasCallingObject = !java.lang.reflect.Modifier.isStatic(((MethodByMethodInfo)info).getCallingMethod().getModifiers());
+      hasTargetObject = !java.lang.reflect.Modifier.isStatic(((MethodByMethodInfo)info).getMethod().getModifiers());
    }
 
    private static JoinPointParameters getParameters(MethodByMethodInfo info)
@@ -82,46 +93,50 @@
       return JoinPointParameters.TARGET_CALLER_ARGS;
    }
    
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               callingMethodHash(),
-               calledClass(),
-               calledMethodHash());
+      MethodByMethodInfo minfo = (MethodByMethodInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               callingMethodHash(minfo),
+               calledClass(minfo),
+               calledMethodHash(minfo));
 
-      joinpointFieldName = getInfoFieldName(
-            callingMethodHash(),
-            calledClass(),
-            calledMethodHash());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+            callingMethodHash(minfo),
+            calledClass(minfo),
+            calledMethodHash(minfo));
    }
 
-   private long callingMethodHash()
+   private long callingMethodHash(MethodByMethodInfo info)
    {
-      return ((MethodByMethodInfo)info).getCallingMethodHash();
+      return info.getCallingMethodHash();
    }
 
-   private String calledClass()
+   private String calledClass(MethodByMethodInfo info)
    {
-      return ((MethodByMethodInfo)info).getCalledClass().getName();
+      return info.getCalledClass().getName();
    }
 
-   private long calledMethodHash()
+   private long calledMethodHash(MethodByMethodInfo info)
    {
-      return ((MethodByMethodInfo)info).getCalledMethodHash();
+      return info.getCalledMethodHash();
    }
 
    protected boolean isVoid()
    {
-      return ((MethodByMethodInfo)info).getMethod().getReturnType().equals(Void.TYPE);
+      return getReturnType() == null;
    }
 
    protected Class getReturnType()
    {
-      if (isVoid()) return null;
-      return ((MethodByMethodInfo)info).getMethod().getReturnType();
+      if (returnType == null)
+      {
+         return null;
+      }
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Method method = ((MethodByMethodInfo)info).getMethod();
       return new AdviceMethodProperties(
@@ -145,12 +160,12 @@
 
    protected boolean hasCallingObject()
    {
-      return !java.lang.reflect.Modifier.isStatic(((MethodByMethodInfo)info).getCallingMethod().getModifiers());
+      return hasCallingObject;
    }
 
    protected boolean hasTargetObject()
    {
-      return !java.lang.reflect.Modifier.isStatic(((MethodByMethodInfo)info).getMethod().getModifiers());
+      return hasTargetObject;
    }
 
    protected static CtClass createJoinpointBaseClass(
@@ -163,33 +178,20 @@
          long calledHash,
          String ciname) throws NotFoundException, CannotCompileException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(callingHash, classname, calledHash));
-
       BaseClassGenerator generator = new BaseClassGenerator(instrumentor, callingClass, callingHash, hasCallingObject, classname, targetMethod, calledHash, ciname);
       return generator.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointClassName(long callingHash, String classname, long calledHash)
    {
-      return getJoinPointGeneratorFieldName(callingMethodHash(), calledClass(), calledMethodHash());
-   }
-
-   protected static String getInfoClassName(long callingHash, String classname, long calledHash)
-   {
       return JOINPOINT_CLASS_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
    }
 
-   protected static String getInfoFieldName(long callingHash, String classname, long calledHash)
+   protected static String getGeneratedJoinPointFieldName(long callingHash, String classname, long calledHash)
    {
       return JOINPOINT_FIELD_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
    }
 
-   protected static String getJoinPointGeneratorFieldName(long callingHash, String classname, long calledHash)
-   {
-      return GENERATOR_PREFIX + CallerTransformer.getUniqueInvocationFieldname(callingHash, classname, calledHash);
-   }
-
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor;
@@ -253,7 +255,7 @@
 
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(callingHash, targetClass.getName(), calledHash);
+         String className = getGeneratedJoinPointClassName(callingHash, targetClass.getName(), calledHash);
 
          //Create inner joinpoint class in advised class, super class is ConstructorInvocation
          jp = TransformerCommon.makeNestedClass(callingClass, className, true);

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java	2007-04-01 17:05:37 UTC (rev 61966)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/MethodJoinPointGenerator.java	2007-04-01 17:55:33 UTC (rev 61967)
@@ -21,6 +21,7 @@
   */
 package org.jboss.aop.instrument;
 
+import java.lang.ref.WeakReference;
 import java.lang.reflect.Method;
 import java.lang.reflect.Modifier;
 
@@ -34,6 +35,7 @@
 import javassist.NotFoundException;
 
 import org.jboss.aop.GeneratedClassAdvisor;
+import org.jboss.aop.JoinPointInfo;
 import org.jboss.aop.MethodInfo;
 import org.jboss.aop.advice.AdviceMethodProperties;
 import org.jboss.aop.joinpoint.MethodInvocation;
@@ -59,11 +61,19 @@
          throw new RuntimeException(e);
       }
    }
+   
+   WeakReference returnType;
+   boolean hasTargetObject;
 
    public MethodJoinPointGenerator(GeneratedClassAdvisor advisor, MethodInfo info)
    {
-      super(advisor, info, getParameters((MethodInfo) info),
-            ((MethodInfo) info).getAdvisedMethod().getParameterTypes().length);
+      super(advisor, info, getParameters(info),
+            info.getAdvisedMethod().getParameterTypes().length);
+      if (!info.getUnadvisedMethod().getReturnType().equals(Void.TYPE))
+      {
+         returnType = new WeakReference(info.getUnadvisedMethod().getReturnType());
+      }
+      hasTargetObject = !Modifier.isStatic(info.getAdvisedMethod().getModifiers());
    }
    
    private static JoinPointParameters getParameters(MethodInfo info)
@@ -75,39 +85,43 @@
       return JoinPointParameters.TARGET_ARGS;
    }
 
-   protected void initialiseJoinPointNames()
+   protected void initialiseJoinPointNames(JoinPointInfo info)
    {
-      joinpointClassName = getInfoClassName(
-               advisedMethodName(), 
-               methodHash());
+      MethodInfo minfo = (MethodInfo)info;
+      joinpointClassName = getGeneratedJoinPointClassName(
+               advisedMethodName(minfo), 
+               methodHash(minfo));
       
-      joinpointFieldName = getInfoFieldName(
-               advisedMethodName(), 
-               methodHash());
+      joinpointFieldName = getGeneratedJoinPointFieldName(
+               advisedMethodName(minfo), 
+               methodHash(minfo));
    }
    
-   private String advisedMethodName()
+   private String advisedMethodName(MethodInfo info)
    {
-      return ((MethodInfo)info).getAdvisedMethod().getName();
+      return info.getAdvisedMethod().getName();
    }
    
-   private long methodHash()
+   private long methodHash(MethodInfo info)
    {
-      return ((MethodInfo)info).getHash();
+      return info.getHash();
    }
       
    protected boolean isVoid()
    {
-      return ((MethodInfo)info).getUnadvisedMethod().getReturnType().equals(Void.TYPE);
+      return getReturnType() == null;
    }
 
    protected Class getReturnType()
    {
-      if (isVoid()) return null;
-      return ((MethodInfo)info).getUnadvisedMethod().getReturnType();
+      if (returnType == null)
+      {
+         return null;
+      }
+      return (Class)returnType.get();
    }
 
-   protected AdviceMethodProperties getAdviceMethodProperties(AdviceSetup setup)
+   protected AdviceMethodProperties getAdviceMethodProperties(JoinPointInfo info, AdviceSetup setup)
    {
       Method method = ((MethodInfo)info).getAdvisedMethod();
       return new AdviceMethodProperties(
@@ -125,14 +139,14 @@
 
    protected boolean hasTargetObject()
    {
-      return !Modifier.isStatic(((MethodInfo)info).getAdvisedMethod().getModifiers()); 
+      return hasTargetObject; 
    }
 
-   protected String getInfoName()
-   {
-      return MethodExecutionTransformer.getMethodInfoFieldName(
-            ((MethodInfo)info).getAdvisedMethod().getName(), ((MethodInfo)info).getHash());
-   }
+//   protected String getInfoName()
+//   {
+//      return MethodExecutionTransformer.getMethodInfoFieldName(
+//            ((MethodInfo)info).getAdvisedMethod().getName(), ((MethodInfo)info).getHash());
+//   }
 
    protected static CtClass createJoinpointBaseClass(
          GeneratedAdvisorInstrumentor instrumentor, 
@@ -144,33 +158,20 @@
          String wrappedMethodName, 
          long hash) throws CannotCompileException, NotFoundException
    {
-      instrumentor.addJoinPointGeneratorFieldToGenAdvisor(
-            getJoinPointGeneratorFieldName(originalMethodName, hash));
-
       BaseClassGenerator factory = new BaseClassGenerator(instrumentor, advisedClass, targetMethod, wMethod, miname, originalMethodName, wrappedMethodName, hash);
       return factory.generate();
    }
 
-   protected String getJoinPointGeneratorFieldName()
+   protected static String getGeneratedJoinPointFieldName(String methodName, long hash)
    {
-      return getJoinPointGeneratorFieldName(advisedMethodName(), methodHash());
-   }
-   
-   protected static String getInfoFieldName(String methodName, long hash)
-   {
       return JOINPOINT_FIELD_PREFIX + MethodExecutionTransformer.getMethodNameHash(methodName, hash);
    }
 
-   private static String getInfoClassName(String methodName, long hash)
+   private static String getGeneratedJoinPointClassName(String methodName, long hash)
    {
       return JOINPOINT_CLASS_PREFIX + MethodExecutionTransformer.getMethodNameHash(methodName, hash);
    }
    
-   protected static String getJoinPointGeneratorFieldName(String methodName, long hash)
-   {
-      return GENERATOR_PREFIX + MethodExecutionTransformer.getMethodNameHash(methodName, hash);
-   }
-   
    private static class BaseClassGenerator
    {
       GeneratedAdvisorInstrumentor instrumentor; 
@@ -232,7 +233,7 @@
       
       private CtClass setupClass()throws NotFoundException, CannotCompileException
       {
-         String className = getInfoClassName(originalMethodName, hash);
+         String className = getGeneratedJoinPointClassName(originalMethodName, hash);
          
          //Create inner joinpoint class in advised class, super class is MethodInvocation
          jp = TransformerCommon.makeNestedClass(advisedClass, className, true);




More information about the jboss-cvs-commits mailing list