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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 11 15:53:09 EDT 2008


Author: kabir.khan at jboss.com
Date: 2008-09-11 15:53:09 -0400 (Thu, 11 Sep 2008)
New Revision: 78458

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointClassifier.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointFullClassifier.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java
Log:
[JBAOP-603] Use Pointcut Classification during Instrumentation

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -558,7 +558,7 @@
     * 
     * @return the classified binding collection
     */
-   ClassifiedBindingAndPointcutCollection getBindingCollection()
+   public ClassifiedBindingAndPointcutCollection getBindingCollection()
    {
       return bindingCollection;
    }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -52,7 +52,6 @@
 import org.jboss.aop.pointcut.Typedef;
 import org.jboss.aop.pointcut.ast.ClassExpression;
 import org.jboss.aop.util.UnmodifiableEmptyCollections;
-import org.jboss.aop.util.UnmodifiableLinkedHashMap;
 
 /**
  * Comment
@@ -1084,6 +1083,7 @@
    
    private class DomainClassifiedBindingAndPointcutCollection extends ClassifiedBindingAndPointcutCollection
    {
+      
       @Override
       public LinkedHashMap<String, AdviceBinding> getBindings()
       {
@@ -1107,8 +1107,55 @@
          }
 
       }  
-      
+
       @Override
+      public LinkedHashMap<String, Pointcut> getPointcuts()
+      {
+         lockRead(true);
+         try
+         {
+            LinkedHashMap<String, Pointcut> result = super.getPointcutsInternal();
+            LinkedHashMap<String, Pointcut> parentResult = 
+               inheritsBindings ? 
+                     parent.getBindingCollection().getPointcutsInternal() : UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+            LinkedHashMap<String, Pointcut> overall = unifyMaps(result, parentResult, parentFirst);
+            if (overall == result || overall == parentResult)
+            {
+               return new LinkedHashMap<String, Pointcut>(overall);
+            }
+            return overall;
+         }
+         finally
+         {
+            unlockRead(true);
+         }
+      }
+
+      @Override
+      public LinkedHashMap<String, PointcutInfo> getPointcutInfos()
+      {
+         lockRead(true);
+         try
+         {
+            LinkedHashMap<String, PointcutInfo> result = super.getPointcutInfosInternal();
+            LinkedHashMap<String, PointcutInfo> parentResult = 
+               inheritsBindings ?
+                     parent.getBindingCollection().getPointcutInfosInternal() : UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+            LinkedHashMap<String, PointcutInfo> overall = unifyMaps(result, parentResult, parentFirst);
+            if (overall == result || overall == parentResult)
+            {
+               return new LinkedHashMap<String, PointcutInfo>(overall);
+            }
+            return overall;
+         }
+         finally
+         {
+            unlockRead(true);
+         }
+      }
+
+
+      @Override
       public Collection<AdviceBinding> getFieldReadBindings()
       {
          lockRead(true);
@@ -1234,51 +1281,243 @@
          }
       }
 
-      @Override
-      public LinkedHashMap<String, Pointcut> getPointcuts()
+      public Collection<Pointcut> getFieldReadPointcuts()
       {
-         lockRead(true);
-         try
-         {
-            LinkedHashMap<String, Pointcut> result = super.getPointcutsInternal();
-            LinkedHashMap<String, Pointcut> parentResult = 
-               inheritsBindings ? 
-                     parent.getBindingCollection().getPointcutsInternal() : UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
-            LinkedHashMap<String, Pointcut> overall = unifyMaps(result, parentResult, parentFirst);
-            if (overall == result || overall == parentResult)
+            lockRead(true);
+            try
             {
-               return new LinkedHashMap<String, Pointcut>(overall);
+               Collection<Pointcut> result = super.getFieldReadPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getFieldReadPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
             }
-            return overall;
-         }
-         finally
-         {
-            unlockRead(true);
-         }
+            finally
+            { 
+               unlockRead(true);
+            }
       }
-
-      @Override
-      public LinkedHashMap<String, PointcutInfo> getPointcutInfos()
+      
+      public Collection<Pointcut> getFieldWritePointcuts()
       {
-         lockRead(true);
-         try
-         {
-            LinkedHashMap<String, PointcutInfo> result = super.getPointcutInfosInternal();
-            LinkedHashMap<String, PointcutInfo> parentResult = 
-               inheritsBindings ?
-                     parent.getBindingCollection().getPointcutInfosInternal() : UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
-            LinkedHashMap<String, PointcutInfo> overall = unifyMaps(result, parentResult, parentFirst);
-            if (overall == result || overall == parentResult)
+            lockRead(true);
+            try
             {
-               return new LinkedHashMap<String, PointcutInfo>(overall);
+               Collection<Pointcut> result = super.getFieldWritePointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getFieldWritePointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
             }
-            return overall;
-         }
-         finally
-         {
-            unlockRead(true);
-         }
+            finally
+            { 
+               unlockRead(true);
+            }
       }
+      
+      public Collection<Pointcut> getConstructionPointcuts()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<Pointcut> result = super.getConstructionPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructionPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<Pointcut> getConstructorExecutionPointcuts()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<Pointcut> result = super.getConstructorExecutionPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructorExecutionPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<Pointcut> getMethodExecutionPointcuts()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<Pointcut> result = super.getMethodExecutionPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getMethodExecutionPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<Pointcut> getConstructorCallPointcuts()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<Pointcut> result = super.getConstructorCallPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructorCallPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<Pointcut> getMethodCallPointcuts()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<Pointcut> result = super.getMethodCallPointcuts();
+               Collection<Pointcut> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getMethodCallPointcuts() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getFieldReadPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getFieldReadPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getFieldReadPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getFieldWritePointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getFieldWritePointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getFieldWritePointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getConstructionPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getConstructionPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructionPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getConstructorExecutionPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getConstructorExecutionPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructorExecutionPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getMethodExecutionPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getMethodExecutionPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getMethodExecutionPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getConstructorCallPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getConstructorCallPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getConstructorCallPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
+      
+      public Collection<PointcutInfo> getMethodCallPointcutInfos()
+      {
+            lockRead(true);
+            try
+            {
+               Collection<PointcutInfo> result = super.getMethodCallPointcutInfos();
+               Collection<PointcutInfo> parentResult = 
+                  inheritsBindings ?
+                        parent.getBindingCollection().getMethodCallPointcutInfos() : UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+               return unifyCollections(result, parentResult, parentFirst);
+            }
+            finally
+            { 
+               unlockRead(true);
+            }
+      }
 
       @Override
       public boolean isExecution()
@@ -1408,11 +1647,11 @@
       {
          if (map1.isEmpty())
          {
-            return new UnmodifiableLinkedHashMap<T, K>(map2);
+            return map2;
          }
          if (map2.isEmpty())
          {
-            return new UnmodifiableLinkedHashMap<T, K>(map1);
+            return map1;
          }
          if (prioritizeFirst)
          {

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -24,6 +24,7 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
@@ -64,9 +65,24 @@
    
    //Collections of pointcuts
    private volatile LinkedHashMap<String, Pointcut> pointcuts;
+   private volatile Collection<Pointcut> fieldReadPointcuts;
+   private volatile Collection<Pointcut> fieldWritePointcuts;
+   private volatile Collection<Pointcut> constructionPointcuts;
+   private volatile Collection<Pointcut> constructorExecutionPointcuts;
+   private volatile Collection<Pointcut> methodExecutionPointcuts;
+   private volatile Collection<Pointcut> constructorCallPointcuts;
+   private volatile Collection<Pointcut> methodCallPointcuts;
    
+   
    //Collections of pointcutInfos
    private volatile LinkedHashMap<String, PointcutInfo> pointcutInfos;
+   private volatile Collection<PointcutInfo> fieldReadPointcutInfos;
+   private volatile Collection<PointcutInfo> fieldWritePointcutInfos;
+   private volatile Collection<PointcutInfo> constructionPointcutInfos;
+   private volatile Collection<PointcutInfo> constructorExecutionPointcutInfos;
+   private volatile Collection<PointcutInfo> methodExecutionPointcutInfos;
+   private volatile Collection<PointcutInfo> constructorCallPointcutInfos;
+   private volatile Collection<PointcutInfo> methodCallPointcutInfos;
    
    //Pointcut stats 
    private boolean execution = false;
@@ -93,8 +109,22 @@
       this.methodCallBindings = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
       
       pointcuts = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+      this.fieldReadPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.fieldWritePointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructionPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructorExecutionPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.methodExecutionPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructorCallPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.methodCallPointcuts = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
       
       pointcutInfos = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+      this.fieldReadPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.fieldWritePointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructionPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructorExecutionPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.methodExecutionPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.constructorCallPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
+      this.methodCallPointcutInfos = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
    }
    
    /**
@@ -252,8 +282,304 @@
          unlockRead();
       }
    }
+
+   /**
+    * Returns only the pointcuts that may match successfully field read
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match field
+    *         read pointcuts
+    */
+   public Collection<Pointcut> getFieldReadPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.fieldReadPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
    
    /**
+    * Returns only the pointcuts that may match successfully field write
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match field
+    *         write pointcuts
+    */
+   public Collection<Pointcut> getFieldWritePointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.fieldWritePointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcuts that may match successfully construction
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match
+    *         construction pointcuts
+    */
+   public Collection<Pointcut> getConstructionPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.constructionPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcuts that may match successfully constructor
+    * execution joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match
+    *         constructor execution pointcuts
+    */
+   public Collection<Pointcut> getConstructorExecutionPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.constructorExecutionPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcuts that may match successfully method
+    * execution joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match
+    *         method execution pointcuts
+    */
+   public Collection<Pointcut> getMethodExecutionPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.methodExecutionPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcuts that may match successfully constructor
+    * call joinpoints.
+    * <p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match
+    *         constructor call pointcuts
+    */
+   public Collection<Pointcut> getConstructorCallPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.constructorCallPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcuts that may match successfully method
+    * call joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcuts that may match
+    *         method call pointcuts
+    */
+   public Collection<Pointcut> getMethodCallPointcuts()
+   {
+      lockRead();
+      try
+      {
+         return this.methodCallPointcuts;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully field read
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match field
+    *         read pointcuts
+    */
+   public Collection<PointcutInfo> getFieldReadPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.fieldReadPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully field write
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match field
+    *         write pointcuts
+    */
+   public Collection<PointcutInfo> getFieldWritePointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.fieldWritePointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully construction
+    * joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match
+    *         construction pointcuts
+    */
+   public Collection<PointcutInfo> getConstructionPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.constructionPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully constructor
+    * execution joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match
+    *         constructor execution pointcuts
+    */
+   public Collection<PointcutInfo> getConstructorExecutionPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.constructorExecutionPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully method
+    * execution joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match
+    *         method execution pointcuts
+    */
+   public Collection<PointcutInfo> getMethodExecutionPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.methodExecutionPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully constructor
+    * call joinpoints.
+    * <p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match
+    *         constructor call pointcuts
+    */
+   public Collection<PointcutInfo> getConstructorCallPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.constructorCallPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+   
+   /**
+    * Returns only the pointcut infos that may match successfully method
+    * call joinpoints.<p>
+    * <b>Attention:</b> this collection is not supposed to be edited.
+    * 
+    * @return a collection containing exclusively the pointcut infos that may match
+    *         method call pointcuts
+    */
+   public Collection<PointcutInfo> getMethodCallPointcutInfos()
+   {
+      lockRead();
+      try
+      {
+         return this.methodCallPointcutInfos;
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+
+   /**
     * Indicate whether this collection is empty.
     */
    public boolean isEmpty()
@@ -408,6 +734,7 @@
       {
          removePointcut(pointcut.getName());
          addPointcut(pointcut);
+
          updatePointcutStats(pointcut, manager);
       }
       finally
@@ -723,9 +1050,123 @@
       {
          pointcutInfos = new LinkedHashMap<String, PointcutInfo>();
       }
-      pointcutInfos.put(pointcut.getName(), new PointcutInfo(pointcut, AspectManager.hasTransformationStarted()));
+      PointcutInfo info = new PointcutInfo(pointcut, AspectManager.hasTransformationStarted());
+      pointcutInfos.put(pointcut.getName(), info);
+
+      addFieldReadPointcut(pointcut, info);
+      addFieldWritePointcut(pointcut, info);
+      addConstructionPointcut(pointcut, info);
+      addConstructorExecutionPointcut(pointcut, info);
+      addMethodExecutionPointcut(pointcut, info);
+      addConstructorCallPointcut(pointcut, info);
+      addMethodCallPointcut(pointcut, info);
    }
+
+   private void addFieldReadPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (fieldReadPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         fieldReadPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      fieldReadPointcuts.add(pointcut);
+
+      if (fieldReadPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         fieldReadPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      fieldReadPointcutInfos.add(info);
+   }
    
+   private void addFieldWritePointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (fieldWritePointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         fieldWritePointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      fieldWritePointcuts.add(pointcut);
+
+      if (fieldWritePointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         fieldWritePointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      fieldWritePointcutInfos.add(info);
+   }
+   
+   private void addConstructionPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (constructionPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructionPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      constructionPointcuts.add(pointcut);
+
+      if (constructionPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructionPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      constructionPointcutInfos.add(info);
+   }
+
+   private void addConstructorExecutionPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (constructorExecutionPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructorExecutionPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      constructorExecutionPointcuts.add(pointcut);
+
+      if (constructorExecutionPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructorExecutionPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      constructorExecutionPointcutInfos.add(info);
+   }
+
+   private void addMethodExecutionPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (methodExecutionPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         methodExecutionPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      methodExecutionPointcuts.add(pointcut);
+
+      if (methodExecutionPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         methodExecutionPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      methodExecutionPointcutInfos.add(info);
+   }
+
+   private void addConstructorCallPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (constructorCallPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructorCallPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      constructorCallPointcuts.add(pointcut);
+
+      if (constructorCallPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         constructorCallPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      constructorCallPointcutInfos.add(info);
+   }
+
+   private void addMethodCallPointcut(Pointcut pointcut, PointcutInfo info)
+   {
+      if (methodCallPointcuts == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         methodCallPointcuts = new CopyOnWriteArrayList<Pointcut>();
+      }
+      methodCallPointcuts.add(pointcut);
+
+      if (methodCallPointcutInfos == UnmodifiableEmptyCollections.EMPTY_ARRAYLIST)
+      {
+         methodCallPointcutInfos = new CopyOnWriteArrayList<PointcutInfo>();
+      }
+      methodCallPointcutInfos.add(info);
+   }
+
    private void updatePointcutStats(Pointcut pointcut, AspectManager manager)
    {
       // the following is for performance reasons.

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/CallerTransformer.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -21,9 +21,9 @@
   */
 package org.jboss.aop.instrument;
 
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.ClassAdvisor;
@@ -338,23 +338,20 @@
 
             DeclareChecker.checkDeclares(manager, call, advisor);
             
-            // todo shouldn't iterate every time.  must be a better way
-            Map<String, Pointcut> pointcuts = manager.getPointcuts();
-            synchronized (pointcuts)
+            Collection<Pointcut> pointcuts = manager.getBindingCollection().getMethodCallPointcuts();
+            for (Pointcut p : pointcuts)
             {
-               for (Pointcut p : pointcuts.values())
+               if (p.matchesCall(advisor, call))
                {
-                  if (p.matchesCall(advisor, call))
-                  {
-                     hasPointcut = true;
-                     break;
-                  }
-                  else
-                  {
-                     if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("MethodCall does not match: " + p.getExpr());
-                  }
+                  hasPointcut = true;
+                  break;
                }
+               else
+               {
+                  if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("MethodCall does not match: " + p.getExpr());
+               }
             }
+
             if (hasPointcut)
             {
                if (behavior instanceof CtMethod)
@@ -439,17 +436,13 @@
             
             boolean hasPointcut = false;
 
-            // todo shouldn't iterate every time.  must be a better way
-            Map<String, Pointcut> pointcuts = manager.getPointcuts();
-            synchronized (pointcuts)
+            Collection<Pointcut> pointcuts = manager.getBindingCollection().getConstructorCallPointcuts();
+            for (Pointcut p : pointcuts)
             {
-               for (Pointcut p : pointcuts.values())
+               if (p.matchesCall(advisor, call))
                {
-                  if (p.matchesCall(advisor, call))
-                  {
-                     hasPointcut = true;
-                     break;
-                  }
+                  hasPointcut = true;
+                  break;
                }
             }
             if (hasPointcut)

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructionTransformer.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -21,9 +21,9 @@
   */
 package org.jboss.aop.instrument;
 
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import org.jboss.aop.ClassAdvisor;
 import org.jboss.aop.pointcut.Pointcut;
@@ -155,15 +155,12 @@
    public static boolean isAdvisableConstructor(CtConstructor con, ClassAdvisor advisor) throws NotFoundException
    {
       
-      Map<String, Pointcut> pointcuts = advisor.getManager().getPointcuts();
-      synchronized (pointcuts)
+      Collection<Pointcut> pointcuts = advisor.getManager().getBindingCollection().getConstructionPointcuts();
+      for (Pointcut pointcut : pointcuts)
       {
-         for (Pointcut pointcut : pointcuts.values())
+         if (pointcut.matchesConstruction(advisor, con))
          {
-            if (pointcut.matchesConstruction(advisor, con))
-            {
-               return true;
-            }
+            return true;
          }
       }
       return false;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/ConstructorExecutionTransformer.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -25,7 +25,6 @@
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import javassist.CannotCompileException;
 import javassist.CtClass;
@@ -470,15 +469,12 @@
    // currently used by CallerTransformer
    public static boolean isAdvisableConstructor(CtConstructor con, ClassAdvisor advisor) throws NotFoundException
    {
-      Map<String, Pointcut> pointcuts = advisor.getManager().getPointcuts();
-      synchronized (pointcuts)
+      Collection<Pointcut> pointcuts = advisor.getManager().getBindingCollection().getConstructorExecutionPointcuts();
+      for (Pointcut pointcut : pointcuts)
       {
-         for (Pointcut pointcut : pointcuts.values())
+         if (pointcut.matchesExecution(advisor, con))
          {
-            if (pointcut.matchesExecution(advisor, con))
-            {
-               return true;
-            }
+            return true;
          }
       }
       return false;

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointClassifier.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointClassifier.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointClassifier.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -21,6 +21,8 @@
   */
 package org.jboss.aop.instrument;
 
+import java.util.Collection;
+
 import javassist.CtConstructor;
 import javassist.CtField;
 import javassist.CtMember;
@@ -29,6 +31,7 @@
 
 import org.jboss.aop.Advisor;
 import org.jboss.aop.pointcut.Pointcut;
+import org.jboss.aop.pointcut.PointcutInfo;
 
 /**
  * This class performs the joinpoint classifications. It is responsible for classifying
@@ -110,7 +113,65 @@
          return pointcut.matchesExecution(advisor, (CtMethod) member);
       }
    };
+
+   protected interface BindingCollectionAccessor
+   {
+      Collection<Pointcut> getPointcuts(Advisor advisor);
+      Collection<PointcutInfo> getPointcutInfos(Advisor advisor);
+   }
    
+   private BindingCollectionAccessor fieldGetAccessor = new BindingCollectionAccessor()
+   {
+      public Collection<PointcutInfo> getPointcutInfos(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getFieldReadPointcutInfos();
+      }
+
+      public Collection<Pointcut> getPointcuts(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getFieldReadPointcuts();
+      }
+   };
+
+   private BindingCollectionAccessor fieldSetAccessor = new BindingCollectionAccessor()
+   {
+      public Collection<PointcutInfo> getPointcutInfos(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getFieldWritePointcutInfos();
+      }
+
+      public Collection<Pointcut> getPointcuts(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getFieldWritePointcuts();
+      }
+   };
+   
+   private BindingCollectionAccessor constructorAccessor = new BindingCollectionAccessor()
+   {
+      public Collection<PointcutInfo> getPointcutInfos(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getConstructorExecutionPointcutInfos();
+      }
+
+      public Collection<Pointcut> getPointcuts(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getConstructorExecutionPointcuts();
+      }
+   };
+
+   private BindingCollectionAccessor methodAccessor = new BindingCollectionAccessor()
+   {
+      public Collection<PointcutInfo> getPointcutInfos(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getConstructorExecutionPointcutInfos();
+      }
+
+      public Collection<Pointcut> getPointcuts(Advisor advisor)
+      {
+         return advisor.getManager().getBindingCollection().getConstructorExecutionPointcuts();
+      }
+   };
+   
    /**
     * Classifies a joinpoint.
     * Subclasses must implement this method, which contains the
@@ -122,7 +183,7 @@
     * @return the joinpoint classification.
     * @throws NotFoundException thrown if the matching of pointcuts fails.
     */
-   protected abstract JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher) throws NotFoundException;
+   protected abstract JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher, BindingCollectionAccessor bindingCollectionAccessor) throws NotFoundException;
    
    /**
     * Classifies the reading of <code>field</code> value.
@@ -133,7 +194,7 @@
     */
    public JoinpointClassification classifyFieldGet(CtField field, Advisor advisor) throws NotFoundException
    {
-      return this.classifyJoinpoint(field, advisor, fieldGetMatcher);
+      return this.classifyJoinpoint(field, advisor, fieldGetMatcher, fieldGetAccessor);
    }
    
    /**
@@ -145,7 +206,7 @@
     */
    public JoinpointClassification classifyFieldSet(CtField field, Advisor advisor) throws NotFoundException
    {
-      return this.classifyJoinpoint(field, advisor, fieldSetMatcher);
+      return this.classifyJoinpoint(field, advisor, fieldSetMatcher, fieldSetAccessor);
    }
    
    /**
@@ -157,7 +218,7 @@
     */
    public JoinpointClassification classifyConstructorExecution(CtConstructor cons, Advisor advisor) throws NotFoundException
    {
-      return this.classifyJoinpoint(cons, advisor, constructorMatcher);
+      return this.classifyJoinpoint(cons, advisor, constructorMatcher, constructorAccessor);
    }
 
    /**
@@ -169,6 +230,6 @@
     */
    public JoinpointClassification classifyMethodExecution(CtMethod method, Advisor advisor) throws NotFoundException
    {
-      return this.classifyJoinpoint(method, advisor, methodMatcher);
+      return this.classifyJoinpoint(method, advisor, methodMatcher, methodAccessor);
    }
 }
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointFullClassifier.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointFullClassifier.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointFullClassifier.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -54,10 +54,10 @@
     * <code>NOT_INSTRUMENTED</code>.
     * @see org.jboss.aop.instrument.JoinpointClassifier#classifyJoinpoint(javassist.CtMember, org.jboss.aop.Advisor, org.jboss.aop.instrument.JoinpointClassifier.Matcher)
     */
-   protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher) throws NotFoundException
+   protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher, BindingCollectionAccessor bindingCollectionAccessor) throws NotFoundException
    {
       JoinpointClassification classification = JoinpointClassification.NOT_INSTRUMENTED;
-      Collection<PointcutInfo> pointcuts = advisor.getManager().getPointcutInfos().values();
+      Collection<PointcutInfo> pointcuts = bindingCollectionAccessor.getPointcutInfos(advisor);
       for (PointcutInfo pointcutInfo : pointcuts)
       {
          // won't check matching of preparation pointcuts unnecessarily

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java	2008-09-11 17:34:24 UTC (rev 78457)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/instrument/JoinpointSimpleClassifier.java	2008-09-11 19:53:09 UTC (rev 78458)
@@ -55,21 +55,18 @@
     * it is classified as <code>JoinpointClassification.NOT_INSTRUMENTED</code>.
     * @see org.jboss.aop.instrument.JoinpointClassifier#classifyJoinpoint(javassist.CtMember, org.jboss.aop.Advisor, org.jboss.aop.instrument.JoinpointClassifier.Matcher)
     */
-   protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher) throws NotFoundException
+   protected JoinpointClassification classifyJoinpoint(CtMember member, Advisor advisor, Matcher joinpointMatcher, BindingCollectionAccessor bindingCollectionAccessor) throws NotFoundException
    {
-      Collection<Pointcut> pointcuts = advisor.getManager().getPointcuts().values();
-      synchronized (pointcuts)
+      Collection<Pointcut> pointcuts = bindingCollectionAccessor.getPointcuts(advisor);
+      for (Pointcut pointcut : pointcuts)
       {
-         for (Pointcut pointcut : pointcuts)
+         if (joinpointMatcher.matches(pointcut, advisor, member))
          {
-            if (joinpointMatcher.matches(pointcut, advisor, member))
+            if (AspectManager.verbose && logger.isDebugEnabled())
             {
-               if (AspectManager.verbose && logger.isDebugEnabled())
-               {
-                  logger.debug(member + " matches pointcut: " + pointcut.getExpr());
-               }
-               return JoinpointClassification.WRAPPED;
+               logger.debug(member + " matches pointcut: " + pointcut.getExpr());
             }
+            return JoinpointClassification.WRAPPED;
          }
       }
       if (AspectManager.verbose && logger.isDebugEnabled())




More information about the jboss-cvs-commits mailing list