[jboss-cvs] JBossAS SVN: r68509 - in projects/aop/trunk/aop/src/main/org/jboss/aop: instrument and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Dec 21 07:39:36 EST 2007
Author: flavia.rainone at jboss.com
Date: 2007-12-21 07:39:35 -0500 (Fri, 21 Dec 2007)
New Revision: 68509
Modified:
projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInfo.java
projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.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
Log:
[JBAOP-487] Joinpoint infos are now unique for method joinpoints
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Advisor.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -48,8 +48,6 @@
import org.jboss.aop.advice.AdviceBinding;
import org.jboss.aop.advice.AspectDefinition;
-import org.jboss.aop.advice.AspectFactory;
-import org.jboss.aop.advice.AspectFactoryWithClassLoaderSupport;
import org.jboss.aop.advice.CFlowInterceptor;
import org.jboss.aop.advice.Interceptor;
import org.jboss.aop.advice.InterceptorFactory;
@@ -89,7 +87,7 @@
{
public MethodInfo getMethodInfo(long hash)
{
- return (MethodInfo)methodInterceptors.get(hash);
+ return methodInfos.getMethodInfo(hash);
}
private class AdviceInterceptorKey
@@ -129,7 +127,7 @@
protected ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
protected Set<AdviceBinding> adviceBindings = new HashSet<AdviceBinding>();
- protected volatile ArrayList interfaceIntroductions = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+ protected volatile ArrayList<InterfaceIntroduction> interfaceIntroductions = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
protected volatile ArrayList<ClassMetaDataBinding> classMetaDataBindings = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
protected SimpleMetaData defaultMetaData = new SimpleMetaData();
protected MethodMetaData methodMetaData = new MethodMetaData();
@@ -152,7 +150,9 @@
// The method signatures are sorted at transformation and load time to
// make sure the tables line up.
//Common sense suggests that this should be lazily initialised for generated advisors, profiling shows that is a major performance hit...
+ /** @deprecated use methodInfos instead */
protected TLongObjectHashMap methodInterceptors = new TLongObjectHashMap();
+ protected MethodInterceptors methodInfos = new MethodInterceptors(this);;
protected AspectManager manager;
protected Class clazz = null;
protected Constructor[] constructors;
@@ -724,7 +724,7 @@
doesHaveAspects = adviceBindings.size() > 0;
}
- public ArrayList getInterfaceIntroductions()
+ public ArrayList<InterfaceIntroduction> getInterfaceIntroductions()
{
return interfaceIntroductions;
}
@@ -878,14 +878,14 @@
}
}
- protected void resolveMethodPointcut(MethodInterceptors newMethodInterceptors, AdviceBinding binding)
+ protected void resolveMethodPointcut(AdviceBinding binding)
{
- long[] keys = advisedMethods.keys();
+ long[] keys = methodInfos.keys();
for (int i = 0; i < keys.length; i++)
{
Method method = (Method) advisedMethods.get(keys[i]);
PointcutMethodMatch match = binding.getPointcut().matchesExecution(this, method);
-
+
if (match != null && match.isMatch())
{
adviceBindings.add(binding);
@@ -905,34 +905,46 @@
System.err.println("[debug] method matched binding: " + method.toString());
}
binding.addAdvisor(this);
- MethodMatchInfo info = newMethodInterceptors.getMatchInfo(keys[i]);
+ MethodMatchInfo info = methodInfos.getMatchInfo(keys[i]);
info.addMatchedBinding(binding, match);
}
}
}
- protected void finalizeMethodChain(MethodInterceptors newMethodInterceptors)
+ protected void resetChain(MethodInterceptors methodInterceptors)
{
- TLongObjectHashMap newMethodInfos = new TLongObjectHashMap();
-
- long[] keys = newMethodInterceptors.keys();
+ Object[] methodMatchInfos = methodInterceptors.infos.getValues();
+ for (int i = 0; i < methodMatchInfos.length; i++)
+ {
+ MethodMatchInfo methodMatchInfo = (MethodMatchInfo) methodMatchInfos[i];
+ if (methodMatchInfo.bindings != null)
+ {
+ methodMatchInfo.bindings.clear();
+ }
+ if (methodMatchInfo.pointcutMethodMatches != null)
+ {
+ methodMatchInfo.pointcutMethodMatches.clear();
+ }
+ methodMatchInfo.getInfo().clear();
+ }
+ }
+
+ protected void finalizeMethodChain()
+ {
+ long[] keys = methodInfos.keys();
for (int i = 0; i < keys.length; i++)
{
- MethodMatchInfo matchInfo = newMethodInterceptors.getMatchInfo(keys[i]);
+ MethodMatchInfo matchInfo = methodInfos.getMatchInfo(keys[i]);
matchInfo.populateBindings();
-
MethodInfo info = matchInfo.getInfo();
- newMethodInfos.put(keys[i], info);
-
- ArrayList list = info.getInterceptorChain();
+ ArrayList<Interceptor> list = info.getInterceptorChain();
Interceptor[] interceptors = null;
if (list.size() > 0)
{
- interceptors = applyPrecedence((Interceptor[]) list.toArray(new Interceptor[list.size()]));
+ interceptors = applyPrecedence(list.toArray(new Interceptor[list.size()]));
}
info.setInterceptors(interceptors);
}
- methodInterceptors = newMethodInfos;
}
public InvocationResponse dynamicInvoke(Object target, Invocation invocation)
@@ -944,7 +956,7 @@
Interceptor[] aspects = null;
MethodInvocation methodInvocation = (MethodInvocation) invocation;
long hash = methodInvocation.getMethodHash();
- MethodInfo info = (MethodInfo) methodInterceptors.get(hash);
+ MethodInfo info = (MethodInfo) methodInfos.getMethodInfo(hash);
aspects = info.getInterceptors();
if (aspects == null) aspects = new Interceptor[0];
if (target != null && target instanceof Advised)
@@ -986,14 +998,14 @@
return name.substring(lastIndex + 1);
}
- protected ConstructorInfo[] initializeConstructorChain()
+ protected void initializeConstructorChain()
{
if (clazz != null && constructors == null)
{
constructors = clazz.getDeclaredConstructors();
}
- ConstructorInfo[] newInfos = new ConstructorInfo[constructors.length];
+ this.constructorInfos = new ConstructorInfo[constructors.length];
for (int i = 0; i < constructors.length; i++)
{
final ConstructorInfo info = new ConstructorInfo();
@@ -1020,7 +1032,7 @@
}
info.setAdvisor(this);
- newInfos[i] = info;
+ constructorInfos[i] = info;
try
{
@@ -1043,20 +1055,18 @@
throw new NestedRuntimeException(e);
}
}
-
- return newInfos;
}
- protected ConstructionInfo[] initializeConstructionChain()
+ protected void initializeConstructionChain()
{
- ConstructionInfo[] newInfos = new ConstructionInfo[constructors.length];
+ this.constructionInfos = new ConstructionInfo[constructors.length];
for (int i = 0; i < constructors.length; i++)
{
ConstructionInfo info = new ConstructionInfo();
info.setConstructor(constructors[i]);
info.setIndex(i);
info.setAdvisor(this);
- newInfos[i] = info;
+ constructionInfos[i] = info;
try
{
@@ -1072,9 +1082,7 @@
{
throw new RuntimeException(e);
}
-
}
- return newInfos;
}
protected void finalizeChain(JoinPointInfo[] infos)
@@ -1091,6 +1099,16 @@
info.setInterceptors(interceptors);
}
}
+
+ protected void resetChain(JoinPointInfo[] infos)
+ {
+ for (int i = 0; i < infos.length; i++)
+ {
+ infos[i].clear();
+ }
+ }
+
+
// protected void finalizeConstructionChain(ArrayList newConstructionInfos)
// {
@@ -1283,9 +1301,9 @@
}
}
- if (methodInterceptors != null)
+ if (methodInfos != null)
{
- methodInterceptors.clear();
+ methodInfos. clear();
}
}
@@ -1314,7 +1332,7 @@
{
if (interfaceIntroductions == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
{
- interfaceIntroductions = new ArrayList();
+ interfaceIntroductions = new ArrayList<InterfaceIntroduction>();
}
}
finally
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassAdvisor.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -252,10 +252,10 @@
public TLongObjectHashMap getMethodInterceptors()
{
- return methodInterceptors;
+ return methodInfos.infos;
}
+
-
/**
* Constructs a new helper.
*/
@@ -444,10 +444,9 @@
}
}
}
-
- protected MethodInterceptors initializeMethodChain()
+
+ protected void initializeMethodChain()
{
- MethodInterceptors newInterceptors = new MethodInterceptors(this);
long[] keys = advisedMethods.keys();
for (int i = 0; i < keys.length; i++)
{
@@ -460,12 +459,12 @@
info.setUnadvisedMethod(umethod);
info.setHash(keys[i]);
info.setAdvisor(this);
- newInterceptors.put(keys[i], info);
+ methodInfos.put(keys[i], info);
try
{
Field infoField = clazz.getDeclaredField(MethodExecutionTransformer.getMethodInfoFieldName(amethod.getName(), keys[i]));
infoField.setAccessible(true);
- infoField.set(null, new WeakReference(info));
+ infoField.set(null, new WeakReference<MethodInfo>(info));
}
catch (NoSuchFieldException e)
{
@@ -476,12 +475,11 @@
throw new RuntimeException(e); //To change body of catch statement use Options | File Templates.
}
}
- return newInterceptors;
}
- protected FieldInfo[] initializeFieldReadChain()
+ protected void initializeFieldReadChain()
{
- FieldInfo[] chain = new FieldInfo[advisedFields.length];
+ this.fieldReadInfos = new FieldInfo[advisedFields.length];
for (int i = 0; i < advisedFields.length; i++)
{
FieldInfo info = new FieldInfo();
@@ -500,7 +498,7 @@
//Just means not advised
}
- chain[i] = info;
+ fieldReadInfos[i] = info;
try
{
@@ -517,12 +515,11 @@
throw new RuntimeException(e);
}
}
- return chain;
}
- protected FieldInfo[] initializeFieldWriteChain()
+ protected void initializeFieldWriteChain()
{
- FieldInfo[] chain = new FieldInfo[advisedFields.length];
+ this.fieldWriteInfos = new FieldInfo[advisedFields.length];
for (int i = 0; i < advisedFields.length; i++)
{
FieldInfo info = new FieldInfo();
@@ -541,7 +538,7 @@
//Just means not advised
}
- chain[i] = info;
+ fieldWriteInfos[i] = info;
try
{
@@ -559,7 +556,6 @@
}
}
- return chain;
}
// protected void finalizeChain(JoinPointInfo[] infos)
@@ -580,18 +576,19 @@
protected void createInterceptorChains() throws Exception
{
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Creating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
- MethodInterceptors newMethodInfos = initializeMethodChain();
// TODO flavia remove this
- boolean buildFieldConsChain = true;
+ // this if is here because the subclass GeneratedClassAdvisor shouldn't be calling
+ // this method anymore: the infos are already created during this class initalization (initalise method)
+ // we call this method because we have the method chains
if (fieldReadInfos == null)
{
- buildFieldConsChain = false;
- this.fieldReadInfos = initializeFieldReadChain();
- this.fieldWriteInfos = initializeFieldWriteChain();
+ initializeFieldReadChain();
+ initializeFieldWriteChain();
+ initializeMethodChain();
}
- this.constructorInfos = initializeConstructorChain();
- this.constructionInfos = initializeConstructionChain();
+ initializeConstructorChain();
+ initializeConstructionChain();
synchronized (manager.getBindings())
{
@@ -600,7 +597,7 @@
{
AdviceBinding binding = (AdviceBinding) it.next();
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName() + " " + binding.getPointcut().getExpr());
- resolveMethodPointcut(newMethodInfos, binding);
+ resolveMethodPointcut(binding);
resolveFieldPointcut(fieldReadInfos, binding, false);
resolveFieldPointcut(fieldWriteInfos, binding, true);
resolveConstructorPointcut(binding);
@@ -608,7 +605,7 @@
}
}
- finalizeChains(newMethodInfos);
+ finalizeChains();
populateInterceptorsFromInfos();
doesHaveAspects = adviceBindings.size() > 0;
@@ -620,21 +617,14 @@
}
}
- private void resetChain(JoinPointInfo[] infos)
- {
- for (int i = 0; i < infos.length; i++)
- {
- infos[i].getInterceptorChain().clear();
- }
- }
-
protected void updateInterceptorChains() throws Exception
{
if (AspectManager.verbose && logger.isDebugEnabled())
{
logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
}
- MethodInterceptors newMethodInfos = initializeMethodChain();
+ logger.debug("Updating chains for " + clazz + " " + ((clazz != null) ? clazz.getClassLoader() : null ));
+ resetChain(methodInfos);
resetChain(fieldReadInfos);
resetChain(fieldWriteInfos);
resetChain(constructorInfos);
@@ -647,7 +637,7 @@
{
AdviceBinding binding = (AdviceBinding) it.next();
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName() + " " + binding.getPointcut().getExpr());
- resolveMethodPointcut(newMethodInfos, binding);
+ resolveMethodPointcut(binding);
resolveFieldPointcut(fieldReadInfos, binding, false);
resolveFieldPointcut(fieldWriteInfos, binding, true);
resolveConstructorPointcut(binding);
@@ -655,7 +645,7 @@
}
}
- finalizeChains(newMethodInfos);
+ finalizeChains();
populateInterceptorsFromInfos();
doesHaveAspects = adviceBindings.size() > 0;
@@ -667,9 +657,9 @@
}
}
- protected void finalizeChains(MethodInterceptors newMethodInfos)
+ protected void finalizeChains()
{
- finalizeMethodChain(newMethodInfos);
+ finalizeMethodChain();
finalizeChain(fieldReadInfos);
finalizeChain(fieldWriteInfos);
finalizeChain(constructorInfos);
@@ -1475,7 +1465,7 @@
InstanceAdvised advised = (InstanceAdvised) target;
advisor = advised._getInstanceAdvisor();
}
- MethodInfo info = (MethodInfo) methodInterceptors.get(methodHash);
+ MethodInfo info = methodInfos.getMethodInfo(methodHash);
return invokeMethod(advisor, target, methodHash, arguments, info);
}
@@ -1483,7 +1473,7 @@
public Object invokeMethod(InstanceAdvisor instanceAdvisor, Object target, long methodHash, Object[] arguments)
throws Throwable
{
- MethodInfo info = (MethodInfo) methodInterceptors.get(methodHash);
+ MethodInfo info = (MethodInfo) methodInfos.getMethodInfo(methodHash);
if (info == null && logger.isDebugEnabled())
{
logger.debug("info is null for hash: " + methodHash + " of " + clazz.getName());
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -123,7 +123,14 @@
protected void rebuildInterceptors()
{
adviceBindings.clear();
- createInterceptorChains();
+ if (this.constructorInfos == null)
+ {
+ createInterceptorChains();
+ }
+ else
+ {
+ updateInterceptorChains();
+ }
}
public void addClassMetaData(ClassMetaDataBinding data)
@@ -208,9 +215,8 @@
}
}
- protected MethodInterceptors initializeMethodChain()
+ protected void initializeMethodChain()
{
- MethodInterceptors newInterceptors = new MethodInterceptors(this);
long[] keys = advisedMethods.keys();
for (int i = 0; i < keys.length; i++)
{
@@ -220,9 +226,8 @@
info.setUnadvisedMethod(amethod);
info.setHash(keys[i]);
info.setAdvisor(this);
- newInterceptors.put(keys[i], info);
+ methodInfos.put(keys[i], info);
}
- return newInterceptors;
}
protected void createConstructorTables()
@@ -241,8 +246,8 @@
protected void createInterceptorChains()
{
- MethodInterceptors newMethodInfos = initializeMethodChain();
- constructorInfos = initializeConstructorChain();
+ initializeMethodChain();
+ initializeConstructorChain();
LinkedHashMap bindings = manager.getBindings();
synchronized (bindings)
@@ -254,18 +259,45 @@
{
AdviceBinding binding = (AdviceBinding) it.next();
if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName());
- resolveMethodPointcut(newMethodInfos, binding);
+ resolveMethodPointcut(binding);
resolveConstructorPointcut(binding);
}
}
}
finalizeChain(constructorInfos);
- finalizeMethodChain(newMethodInfos);
+ finalizeMethodChain();
populateInterceptorsFromInfos();
doesHaveAspects = adviceBindings.size() > 0;
}
+
+ protected void updateInterceptorChains()
+ {
+ resetChain(this.methodInfos);
+ resetChain(this.constructorInfos);
+ LinkedHashMap bindings = manager.getBindings();
+ synchronized (bindings)
+ {
+ if (bindings.size() > 0)
+ {
+ Iterator it = bindings.values().iterator();
+ while (it.hasNext())
+ {
+ AdviceBinding binding = (AdviceBinding) it.next();
+ if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("iterate binding " + binding.getName());
+ resolveMethodPointcut(binding);
+ resolveConstructorPointcut(binding);
+ }
+ }
+ }
+ finalizeChain(constructorInfos);
+ finalizeMethodChain();
+ populateInterceptorsFromInfos();
+
+ doesHaveAspects = adviceBindings.size() > 0;
+ }
+
/**
* @return the value of chainOverridingForInheritedMethods
* @see Advisor#chainOverridingForInheritedMethods()
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -69,14 +69,14 @@
public static final String ADD_FIELD_WRITE_INFO = "addFieldWriteInfo";
public static final String GET_PARENT_ADVISOR = "getParentAdvisor";
- MethodInterceptors methodInfos = new MethodInterceptors(this);
+
// TODO Flavia
// ArrayList<ConstructorInfo> constructorInfos = new ArrayList();
// ArrayList<ConstructionInfo> constructionInfos = new ArrayList();
// ArrayList<FieldInfo> fieldReadInfos = new ArrayList();
// ArrayList<FieldInfo> fieldWriteInfos = new ArrayList();
/** Super class methods that have been overrridden - these need special handling in this weaving mode */
- ArrayList overriddenMethods = new ArrayList();
+ ArrayList<MethodInfo> overriddenMethods = new ArrayList<MethodInfo>();
//TODO These are only needed for the class advisor really
//All joinpoint generators apart from field reads and constructions go in here
@@ -281,13 +281,13 @@
}
@Override
- protected void resolveMethodPointcut(MethodInterceptors newMethodInterceptors, AdviceBinding binding)
+ protected void resolveMethodPointcut(AdviceBinding binding)
{
GeneratedClassAdvisor classAdvisor = getClassAdvisorIfInstanceAdvisorWithNoOwnDataWithEffectOnAdvices();
if (classAdvisor == null)
{
//We are either the class advisor or an instanceadvisor with own data so we need to do all the work
- super.resolveMethodPointcut(newMethodInterceptors, binding);
+ super.resolveMethodPointcut(binding);
handleOverriddenMethods(binding);
}
}
@@ -333,12 +333,11 @@
overriddenMethods.add(old);
}
methodInfos.put(mi.getHash(), mi);
-
advisorStrategy.makeAccessibleMethod(mi);
}
@Override
- protected MethodInterceptors initializeMethodChain()
+ protected void initializeMethodChain()
{
//We have all the advised methods here, need to get all the others here too
@@ -363,8 +362,6 @@
methodInfos.put(keys[i], info);
}
}
-
- return methodInfos;
}
@@ -388,7 +385,6 @@
@Override
protected void createInterceptorChains() throws Exception
{
- System.out.println("Creating interceptor chains on advisor " + this.getClass().getName());
advisorStrategy.createInterceptorChains();
}
@@ -454,32 +450,30 @@
// TODO Flavia remove this once the process is complete
@Override
- protected ConstructorInfo[] initializeConstructorChain()
+ protected void initializeConstructorChain()
{
// TODO remove this
- if (this.constructorInfos != null)
+ if (this.constructorInfos == null)
{
- return this.constructorInfos;
+ super.initializeConstructorChain();
}
- return super.initializeConstructorChain();
}
// TODO remove this once the process is complete
@Override
- protected ConstructionInfo[] initializeConstructionChain()
+ protected void initializeConstructionChain()
{
// TODO remove this
- if (this.constructionInfos != null)
+ if (this.constructionInfos == null)
{
- return this.constructionInfos;
+ super.initializeConstructionChain();
}
- return super.initializeConstructionChain();
}
@Override
- protected FieldInfo[] initializeFieldReadChain()
+ protected void initializeFieldReadChain()
{
- return mergeFieldInfos(fieldReadInfos, true);
+ this.fieldReadInfos = mergeFieldInfos(fieldReadInfos, true);
}
/**
@@ -500,9 +494,9 @@
}
@Override
- protected FieldInfo[] initializeFieldWriteChain()
+ protected void initializeFieldWriteChain()
{
- return mergeFieldInfos(fieldWriteInfos, false);
+ this.fieldWriteInfos = mergeFieldInfos(fieldWriteInfos, false);
}
/* Creates a full list of field infos for all fields, using the ones added by
@@ -540,7 +534,7 @@
}
@Override
- protected void finalizeChains(MethodInterceptors newMethodInfos)
+ protected void finalizeChains()
{
ClassAdvisor classAdvisor = getClassAdvisorIfInstanceAdvisorWithNoOwnDataWithEffectOnAdvices();
if (classAdvisor != null)
@@ -559,7 +553,7 @@
}
}
- finalizeMethodChain(newMethodInfos);
+ finalizeMethodChain();
finalizeFieldReadChain();
finalizeFieldWriteChain();
advisorStrategy.finalizeConstructorChain(constructorInfos);
@@ -567,18 +561,18 @@
}
@Override
- protected void finalizeMethodChain(MethodInterceptors newMethodInterceptors)
+ protected void finalizeMethodChain()
{
ClassAdvisor classAdvisor = getClassAdvisorIfInstanceAdvisorWithNoOwnDataWithEffectOnAdvices();
if (classAdvisor != null)
{
//We are an instance advisor with no own data influencing the chains, copy these from the parent advisor
- easyFinalizeMethodChainForInstance(classAdvisor, newMethodInterceptors);
+ easyFinalizeMethodChainForInstance(classAdvisor, methodInfos);
}
else
{
//We are either the class advisor or an instanceadvisor with own data so we need to do all the work
- fullWorkFinalizeMethodChain(newMethodInterceptors);
+ fullWorkFinalizeMethodChain(methodInfos);
}
}
@@ -815,7 +809,7 @@
@Override
protected void pointcutResolved(JoinPointInfo info, AdviceBinding binding, Joinpoint joinpoint)
{
- ArrayList curr = info.getInterceptorChain();
+ ArrayList<Interceptor> curr = info.getInterceptorChain();
if (binding.getCFlow() != null)
{
//TODO Handle CFlow
@@ -884,7 +878,8 @@
* Generated ClassAdvisors and InstanceAdvisors will be different instances,
* so keep track of what per_class_joinpoint aspects have been added where
*/
- ConcurrentHashMap perClassJoinpointAspectDefinitions = new ConcurrentHashMap();
+ ConcurrentHashMap<AspectDefinition,Map<Joinpoint, Object>> perClassJoinpointAspectDefinitions =
+ new ConcurrentHashMap<AspectDefinition, Map<Joinpoint, Object>>();
public Object getPerClassJoinpointAspect(AspectDefinition def, Joinpoint joinpoint)
@@ -894,10 +889,10 @@
public synchronized void addPerClassJoinpointAspect(AspectDefinition def, Joinpoint joinpoint)
{
- Map joinpoints = (Map)perClassJoinpointAspectDefinitions.get(def);
+ Map<Joinpoint, Object> joinpoints = perClassJoinpointAspectDefinitions.get(def);
if (joinpoints == null)
{
- joinpoints = new ConcurrentHashMap();
+ joinpoints = new ConcurrentHashMap<Joinpoint, Object>();
perClassJoinpointAspectDefinitions.put(def, joinpoints);
}
@@ -1246,6 +1241,7 @@
public void initialise(Class clazz, AspectManager manager)
{
+ methodInfos = new MethodInterceptors(GeneratedClassAdvisor.this);
initialiseMethods();
// initialise constructor info array
Collection<ConstructorInfo> constructorInfoCol = new ArrayList<ConstructorInfo>();
@@ -1537,7 +1533,6 @@
ConstructorJoinPointGenerator generator = getJoinPointGenerator(info);
Class clazz = info.getClazz();
if (clazz != null)
- System.out.println("Finalizing constructor chain for constructor of class " + clazz.getName());
finalizeChainAndRebindJoinPoint(oldInfos, info, generator, OldInfoMaps.INFOS);
}
}
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInfo.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInfo.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInfo.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -56,7 +56,6 @@
{
throw new RuntimeException(e);
}
-
}
/*
Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java 2007-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/MethodInterceptors.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -62,4 +62,9 @@
{
infos.put(hash, new MethodMatchInfo(advisor, info));
}
+
+ public void clear()
+ {
+ infos.clear();
+ }
}
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorCallerTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -91,7 +91,7 @@
joinpoint,
MethodByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
@@ -194,7 +194,7 @@
joinpoint,
MethodByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(md.callingHash, md.classname, md.calledHash),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
@@ -296,7 +296,7 @@
joinpoint,
ConByMethodJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingHash, cd.classname, cd.calledHash),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
@@ -388,7 +388,7 @@
joinpoint,
ConByConJoinPointGenerator.getGeneratedJoinPointFieldName(cd.callingIndex, cd.classname, cd.calledHash),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -71,7 +71,7 @@
joinpoint,
ConstructionJoinPointGenerator.getGeneratedJoinPointFieldName(clazz.getSimpleName(), index),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorConstructorExecutionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -81,7 +81,7 @@
joinpoint,
ConstructorJoinPointGenerator.getGeneratedJoinPointFieldName(clazz.getSimpleName(), index),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorFieldAccessTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -138,7 +138,7 @@
joinpoint,
FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), true),
genadvisor);
- jpfield.setModifiers(Modifier.PROTECTED);
+ jpfield.setModifiers(Modifier.PUBLIC);
genadvisor.addField(jpfield);
}
@@ -177,7 +177,7 @@
joinpoint,
FieldJoinPointGenerator.getGeneratedJoinPointFieldName(field.getName(), false),
genadvisor);
- jpfield.setModifiers(Modifier.PROTECTED);
+ jpfield.setModifiers(Modifier.PUBLIC);
genadvisor.addField(jpfield);
}
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorInstrumentor.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -31,6 +31,7 @@
import javassist.Modifier;
import javassist.NotFoundException;
+import org.jboss.aop.Advisor;
import org.jboss.aop.AspectManager;
import org.jboss.aop.ClassAdvisor;
import org.jboss.aop.ConByConInfo;
@@ -43,6 +44,7 @@
import org.jboss.aop.MethodInfo;
import org.jboss.aop.WeavingStrategySupport;
import org.jboss.aop.classpool.AOPClassPool;
+import org.jboss.aop.instrument.MethodExecutionTransformer.MethodTransformation;
/**
* Comment
@@ -164,6 +166,15 @@
{
return ((GeneratedAdvisorMethodExecutionTransformer)methodExecutionTransformer).addMixinWrappersAndInfo(this, clazz, mixinClass, initializer, genadvisor, method);
}
+
+ @Override
+ protected CtMethod addMixinMethod(Advisor advisor, CtMethod method, CtClass clazz, CtMethod delegate, long hash) throws Exception
+ {
+ //CtMethod newMethod = super.addMixinMethod(advisor, method, clazz, delegate, hash);
+ //((GeneratedAdvisorMethodExecutionTransformer) methodExecutionTransformer).
+ // addMethodIntroductionInfo(this, clazz, newMethod, hash);
+ return ((GeneratedAdvisorMethodExecutionTransformer) methodExecutionTransformer).addMixinWrappersAndInfo(this, clazz, genadvisor, method, delegate);
+ }
protected static String getAdvisorName(CtClass clazz)
{
@@ -641,6 +652,7 @@
StringBuffer initialiseInfosForInstanceCode = new StringBuffer();
initialiseInfosForInstanceCode.append("java.util.Collection fieldReadCol = new java.util.ArrayList();");
initialiseInfosForInstanceCode.append("java.util.Collection fieldWriteCol = new java.util.ArrayList();");
+ //initialiseInfosForInstanceCode.append("methodInfos = new org.jboss.aop.MethodInterceptors($0);");
while (true)
{
CtField[] fields = superAdvisor.getDeclaredFields();
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/GeneratedAdvisorMethodExecutionTransformer.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -46,7 +46,7 @@
super(instrumentor);
}
- private String addMethodInfoFieldToGenAdvisor(MethodTransformation trans)throws NotFoundException, CannotCompileException
+ protected String addMethodInfoFieldToGenAdvisor(MethodTransformation trans)throws NotFoundException, CannotCompileException
{
GeneratedAdvisorInstrumentor instrumentor = (GeneratedAdvisorInstrumentor)trans.getInstrumentor();
CtClass genadvisor = instrumentor.getGenadvisor();
@@ -79,7 +79,7 @@
joinpoint,
getJoinPointFieldName(trans),
genadvisor);
- field.setModifiers(Modifier.PROTECTED);
+ field.setModifiers(Modifier.PUBLIC);
genadvisor.addField(field);
}
@@ -149,6 +149,131 @@
return wmethod;
}
+ public CtMethod addMixinWrappersAndInfo(
+ GeneratedAdvisorInstrumentor instrumentor,
+ CtClass clazz,
+ CtClass genadvisor,
+ CtMethod mixinMethod,
+ CtMethod delegate) throws CannotCompileException, NotFoundException
+ {
+ String originalName = mixinMethod.getName();
+ String originalBody = "{ ";
+ CtClass returnType = mixinMethod.getReturnType();
+ if (!returnType.equals(CtClass.voidType))
+ {
+ if (returnType.isPrimitive())
+ {
+ if (returnType.equals(CtClass.booleanType))
+ {
+ originalBody += "return false;";
+ }
+ else if (returnType.equals(CtClass.byteType))
+ {
+ originalBody += "return (byte) 0;";
+ }
+ else if (returnType.equals(CtClass.charType))
+ {
+ originalBody += "return (char) 0;";
+ }
+ else if (returnType.equals(CtClass.doubleType))
+ {
+ originalBody += "return (double) 0.0;";
+ }
+ else if (returnType.equals(CtClass.floatType))
+ {
+ originalBody += "return (float) 0.0;";
+ }
+ else if (returnType.equals(CtClass.intType))
+ {
+ originalBody += "return 0;";
+ }
+ else if (returnType.equals(CtClass.longType))
+ {
+ originalBody += "return 0l;";
+ }
+ else if (returnType.equals(CtClass.shortType))
+ {
+ originalBody += "return (short) 0;";
+ }
+ else
+ {
+ throw new RuntimeException ("Unexpected primitive type: " + returnType.getName());
+ }
+ }
+ else
+ {
+ originalBody += "return null;";
+ }
+ }
+ originalBody += "}";
+
+ CtMethod original = CtNewMethod.make(
+ Modifier.PUBLIC,
+ mixinMethod.getReturnType(),
+ mixinMethod.getName(),
+ mixinMethod.getParameterTypes(),
+ mixinMethod.getExceptionTypes(),
+ originalBody,
+ clazz);
+ clazz.addMethod(original);
+ long hash = JavassistMethodHashing.methodHash(original);
+ moveAnnotationsAndCopySignature(mixinMethod, original);
+
+ String wrappedName = ClassAdvisor.notAdvisedMethodName(clazz.getName(), originalName);
+ CtMethod wmethod = CtNewMethod.copy(original, clazz, null);
+
+ wmethod.setName(wrappedName);
+ clazz.addMethod(wmethod);
+ moveAnnotationsAndCopySignature(original, wmethod);
+
+ original.setName(wrappedName);
+ wmethod.setName(originalName);
+
+ MethodTransformation trans = new MethodTransformation(instrumentor, clazz, original, originalName, wmethod, wrappedName, hash);
+
+ String methodInfoField = addMethodInfoFieldToGenAdvisor(trans);
+ //delegate = genadvisor.getSuperclass().getSuperclass().getDeclaredMethod("invokeMethod");
+ String body = "{ return ((org.jboss.aop.ClassAdvisor)this._getAdvisor()).invokeMethod($1, ";
+ body += trans.getHash() + "L";
+ for (int i = 0; i < mixinMethod.getParameterTypes().length; i++)
+ {
+ body += "$" + (i + 2);
+ }
+ body += ");}";
+ addMethodToGeneratedAdvisor(trans, methodInfoField, body);
+// CtMethod newMethod = CtNewMethod.wrapped(trans.getWMethod().getReturnType(),
+// getAdvisorMethodName(trans),
+// addTargetToParamsForNonStaticMethod(trans.getClazz(), trans.getWMethod()),
+// trans.getWMethod().getExceptionTypes(),
+// delegate,
+// CtMethod.ConstParameter.integer(hash),
+// clazz);
+// genadvisor.addMethod(newMethod);
+// newMethod.setModifiers(Modifier.setProtected(newMethod.getModifiers()));
+//
+ String wrapperBody =
+ "{" +
+ " " + getReturnStr(trans.getMethod()) + " ((" + GeneratedAdvisorInstrumentor.getAdvisorFQN(trans.getClazz()) + ")" + GeneratedAdvisorInstrumentor.GET_CURRENT_ADVISOR + ")." + getAdvisorMethodName(trans) + "(this,$$);" +
+ "}";
+ wmethod.setBody(wrapperBody);
+ return wmethod;
+ }
+
+ public void addMethodIntroductionInfo(
+ GeneratedAdvisorInstrumentor instrumentor,
+ CtClass clazz,
+ CtMethod introducedMethod,
+ long hash) throws CannotCompileException, NotFoundException
+ {
+ MethodTransformation trans = new MethodTransformation(instrumentor, clazz,
+ introducedMethod, introducedMethod.getName(), introducedMethod,
+ introducedMethod.getName(), hash);
+ String methodInfoField = addMethodInfoFieldToGenAdvisor(trans);
+ // TODO: this method is never called: we need to make interface introductions
+ // work in the new mode.
+ addMethodToGeneratedAdvisor(trans, methodInfoField);
+ }
+
protected void transformMethod(MethodTransformation trans, boolean wrap)
throws CannotCompileException, NotFoundException
{
@@ -258,6 +383,13 @@
private void addMethodToGeneratedAdvisor(MethodTransformation trans, String methodInfoField)throws CannotCompileException, NotFoundException
{
+ // TODO send methodInfoField value to createAdvisorMethodBody as a parameter
+ String code = createAdvisorMethodBody(trans);
+ this.addMethodToGeneratedAdvisor(trans, methodInfoField, code);
+ }
+
+ private void addMethodToGeneratedAdvisor(MethodTransformation trans, String methodInfoField, String body)throws CannotCompileException, NotFoundException
+ {
CtClass genadvisor = ((GeneratedAdvisorInstrumentor)trans.getInstrumentor()).getGenadvisor();
CtClass[] params = addTargetToParamsForNonStaticMethod(trans.getClazz(), trans.getWMethod());
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-12-21 12:33:32 UTC (rev 68508)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinPointGenerator.java 2007-12-21 12:39:35 UTC (rev 68509)
@@ -536,7 +536,7 @@
try
{
- joinpointField = advisorClass.getDeclaredField(joinpointFieldName);
+ joinpointField = advisorClass.getField(joinpointFieldName);
SecurityActions.setAccessible(joinpointField);
joinpointFqn = advisorClass.getDeclaringClass().getName() + "$" + joinpointClassName;
}
More information about the jboss-cvs-commits
mailing list