[jboss-cvs] JBossAS SVN: r78946 - 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
Tue Sep 30 01:39:04 EDT 2008


Author: flavia.rainone at jboss.com
Date: 2008-09-30 01:39:03 -0400 (Tue, 30 Sep 2008)
New Revision: 78946

Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/util/AOPLock.java
Log:
[JBAOP-653] The lock of ClassifiedBindingAndPointcutcolleciton has been replaced by AOPLock.
For simplicity, support to nested locks has been removed. Instead, there is only one single lock for all
domain levels.

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-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -80,6 +80,7 @@
 import org.jboss.aop.pointcut.PointcutStats;
 import org.jboss.aop.pointcut.Typedef;
 import org.jboss.aop.pointcut.ast.ClassExpression;
+import org.jboss.aop.util.AOPLock;
 import org.jboss.aop.util.UnmodifiableEmptyCollections;
 import org.jboss.aop.util.logging.AOPLogger;
 import org.jboss.util.collection.WeakValueHashMap;
@@ -160,6 +161,7 @@
    /** ClassExpressions built from ignore. Maintained by top-level AspectManager */
    protected ClassExpression[] ignoreExpressions = new ClassExpression[0];
 
+   protected static AOPLock lock = new AOPLock();
 
    // these fields represent whether there are certain pointcut types.
    // for performance reasons the transformers and binders can make a lot of us of this.
@@ -712,7 +714,7 @@
       // as we know that the bindingCollection lock will be needed during the 
       // Advisor.attachClass method execution, we get the lock at this point
       // making sure we are avoiding the deadlock.
-      bindingCollection.lockRead();
+      lock.lockRead();
       try
       {
          synchronized (advisors)
@@ -730,7 +732,7 @@
       }
       finally
       {
-         bindingCollection.unlockRead(false);
+         lock.unlockRead();
       }
    }
 
@@ -1018,32 +1020,33 @@
          {
             return null;
          }
-         this.bindingCollection.lockRead();
+         lock.lockRead();
          try
          {
             synchronized(this){
-         if (weavingStrategy == null)
-         {
-            if (TransformerCommon.isCompileTime() || classicOrder)
-            {
-               weavingStrategy = new ClassicWeavingStrategy();
+               if (weavingStrategy == null)
+               {
+                  if (TransformerCommon.isCompileTime() || classicOrder)
+                  {
+                     weavingStrategy = new ClassicWeavingStrategy();
+                  }
+                  else if(InstrumentorFactory.getInstrumentor(this,dynamicStrategy.getJoinpointClassifier())
+                        instanceof GeneratedAdvisorInstrumentor)
+                  {
+                     weavingStrategy = new SuperClassesFirstWeavingStrategy();
+                  }
+                  else
+                  {
+                     weavingStrategy = new ClassicWeavingStrategy();
+                  }
+               }
+      
+               return weavingStrategy.translate(this, className, loader, classfileBuffer);
             }
-            else if(InstrumentorFactory.getInstrumentor(this,dynamicStrategy.getJoinpointClassifier())
-                  instanceof GeneratedAdvisorInstrumentor)
-            {
-               weavingStrategy = new SuperClassesFirstWeavingStrategy();
-            }
-            else
-            {
-               weavingStrategy = new ClassicWeavingStrategy();
-            }
          }
-
-         return weavingStrategy.translate(this, className, loader, classfileBuffer);
-         }}
          finally
          {
-            this.bindingCollection.unlockRead(false);
+            lock.unlockRead();
          }
       }
       catch (Exception e)
@@ -1351,7 +1354,7 @@
     */
    public synchronized void removeBinding(String name)
    {
-      bindingCollection.lockWrite();
+      lock.lockWrite();
       try
       {
          AdviceBinding binding = internalRemoveBinding(name);
@@ -1363,7 +1366,7 @@
       }
       finally
       {
-         bindingCollection.unlockWrite();
+         lock.unlockWrite();
       }
    }
 
@@ -1374,7 +1377,7 @@
       HashSet<Advisor> bindingAdvisors = new HashSet<Advisor>();
       ArrayList<AdviceBinding> removedBindings = null;
       
-      bindingCollection.lockWrite();
+      lock.lockWrite();
       try
       {
          removedBindings = this.bindingCollection.removeBindings(binds);
@@ -1388,7 +1391,7 @@
       }
       finally
       {
-         bindingCollection.unlockWrite();
+         lock.unlockWrite();
       }
       
       Iterator<Advisor> it = bindingAdvisors.iterator();
@@ -1434,7 +1437,7 @@
          // we will end up with a deadlock
          synchronized(this)
          {
-            bindingCollection.lockWrite();
+            lock.lockWrite();
             locked = true;
             removedBinding = internalRemoveBinding(binding.getName());
             affectedAdvisors = removedBinding == null ? null : new HashSet<Advisor>(removedBinding.getAdvisors());         
@@ -1460,7 +1463,7 @@
       {
          if (locked)
          {
-            bindingCollection.unlockWrite();
+            lock.unlockWrite();
          }
       }
    }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java	2008-09-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ClassContainer.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -323,7 +323,7 @@
    private void makeInterceptorChains()
    {
       ClassifiedBindingAndPointcutCollection bindingCol = manager.getBindingCollection();
-      bindingCol.lockRead(true);
+      AspectManager.lock.lockRead();
       try
       {
          Collection<AdviceBinding> bindings = bindingCol.getConstructorExecutionBindings(); 
@@ -341,7 +341,7 @@
       }
       finally
       {
-         bindingCol.unlockRead(true);
+         AspectManager.lock.unlockRead();
       }
       finalizeChain(constructorInfos);
       finalizeMethodChain();

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-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/Domain.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -193,25 +193,49 @@
    @Override
    public synchronized void addBinding(AdviceBinding binding)
    {
-      hasOwnPointcuts = true;
-      hasOwnBindings = true;
-      super.addBinding(binding);
+      lock.lockWrite();
+      try
+      {
+         hasOwnPointcuts = true;
+         hasOwnBindings = true;
+         super.addBinding(binding);
+      }
+      finally
+      {
+         lock.unlockWrite();
+      }
    }
    
    @Override
    public synchronized void removeBinding(String name)
    {
-      super.removeBinding(name);
-      hasOwnBindings = !bindingCollection.isEmpty();
-      hasOwnPointcuts = !bindingCollection.hasPointcuts();
+      lock.lockWrite();
+      try
+      {
+         super.removeBinding(name);
+         hasOwnBindings = !bindingCollection.isEmpty();
+         hasOwnPointcuts = !bindingCollection.hasPointcuts();
+      }
+      finally
+      {
+         lock.unlockWrite();
+      }
    }
    
    @Override
    public synchronized void removeBindings(ArrayList<String> binds)
    {
-      super.removeBindings(binds);
-      hasOwnBindings = !bindingCollection.isEmpty();
-      hasOwnPointcuts = !bindingCollection.hasPointcuts();
+      lock.lockWrite();
+      try
+      {
+         super.removeBindings(binds);
+         hasOwnBindings = !bindingCollection.isEmpty();
+         hasOwnPointcuts = !bindingCollection.hasPointcuts();
+      }
+      finally
+      {
+         lock.unlockWrite();
+      }
    }
    
    @Override
@@ -1435,45 +1459,5 @@
          }
          return map1;
       }
-
-      @Override
-      public void lockRead(boolean lockParents)
-      {
-         if (lockParents)
-         {
-            parent.getBindingCollection().lockRead(lockParents);
-         }
-         super.lockRead();
-      }
-
-      @Override
-      public void lockWrite(boolean lockParents)
-      {
-         if (lockParents)
-         {
-            parent.getBindingCollection().lockWrite(lockParents);
-         }
-         super.lockWrite();
-      }
-
-      @Override
-      public void unlockRead(boolean lockParents)
-      {
-         super.unlockRead();
-         if (lockParents)
-         {
-            parent.getBindingCollection().unlockRead(lockParents);
-         }
-      }
-
-      @Override
-      public void unlockWrite(boolean lockParents)
-      {
-         super.unlockWrite();
-         if (lockParents)
-         {
-            parent.getBindingCollection().unlockWrite(lockParents);
-         }
-      }
    }
 }
\ No newline at end of file

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java	2008-09-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/ReflectiveAspectBinder.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -93,7 +93,7 @@
       if (!initialisedAspects)
       {
          ClassifiedBindingAndPointcutCollection bindingCol = advisor.getManager().getBindingCollection();
-         bindingCol.lockRead(true);
+         AspectManager.lock.lockRead();
          try
          {
             bindMethodAdvices(clazz, bindingCol);
@@ -102,7 +102,7 @@
          }
          finally
          {
-            bindingCol.unlockRead(true);
+            AspectManager.lock.unlockRead();
          }
       }
       return aspects;

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-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/advice/ClassifiedBindingAndPointcutCollection.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -26,7 +26,6 @@
 import java.util.LinkedHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.jboss.aop.AspectManager;
 import org.jboss.aop.pointcut.Pointcut;
@@ -51,7 +50,7 @@
 {
    private static final AOPLogger logger = AOPLogger.getLogger(AspectManager.class);
    
-   private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
+   //private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
   
    //Collections of bindings
    private volatile LinkedHashMap<String, AdviceBinding> bindings;
@@ -440,7 +439,7 @@
    
    /**
     * Returns the pointcuts map.
-    * @return an unmodifiable map containing all the pointcuts
+    * @return an modifiable map containing all the pointcuts
     */
    public LinkedHashMap<String, Pointcut> getPointcuts()
    {
@@ -602,75 +601,7 @@
    {
       return set;
    }
-
-   /**
-    * Read-lock just this collection
-    */
-   public final void lockRead()
-   {
-      lock.readLock().lock();
-   }
    
-   /**
-    * Read-unlock just this collection
-    */
-   protected final void unlockRead()
-   {
-      lock.readLock().unlock();
-   }
-   
-   /**
-    * Write-lock just this collection
-    */
-   public final void lockWrite()
-   {
-      lock.writeLock().lock();
-   }
-   
-   /**
-    * Write-unlock this collection
-    */
-   public final void unlockWrite()
-   {
-      lock.writeLock().unlock();
-   }
-
-   /**
-    * Read-lock this collection
-    * @param if true, parent collections will be locked too
-    */
-   public void lockRead(boolean lockParents)
-   {
-      lockRead();
-   }
-   
-   /**
-    * Read-unlock this collection
-    * @param if true, parent collections will be unlocked too
-    */
-   public void unlockRead(boolean lockParents)
-   {
-      unlockRead();
-   }
-   
-   /**
-    * Write-lock this collection
-    * @param if true, parent collections will be locked too
-    */
-   public void lockWrite(boolean lockParents)
-   {
-      lockWrite();
-   }
-   
-   /**
-    * Write-unlock this collection
-    * @param if true, parent collections will be unlocked too
-    */
-   public void unlockWrite(boolean lockParents)
-   {
-      unlockWrite();
-   }
-   
    private void addBinding(AdviceBinding binding)
    {
       if (bindings == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
@@ -920,35 +851,27 @@
 
    public void updateStats(PointcutStats stats)
    {
-      lockWrite();
-      try
+      if (stats != null)
       {
-         if (stats != null)
-         {
-            construction |= stats.isConstruction();
-            execution |= stats.isExecution();
-            call |= stats.isCall();
-            within |= stats.isWithin();
-            get |= stats.isGet();
-            set |= stats.isSet();
-            withincode |= stats.isWithincode();
-         }
-         else
-         {
-            if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Setting all pointcut stats to true");
-            // can't be sure so set all
-            execution = true;
-            construction = true;
-            call = true;
-            within = true;
-            get = true;
-            set = true;
-            withincode = true;
-         }
+         construction |= stats.isConstruction();
+         execution |= stats.isExecution();
+         call |= stats.isCall();
+         within |= stats.isWithin();
+         get |= stats.isGet();
+         set |= stats.isSet();
+         withincode |= stats.isWithincode();
       }
-      finally
+      else
       {
-         unlockWrite();
+         if (AspectManager.verbose && logger.isDebugEnabled()) logger.debug("Setting all pointcut stats to true");
+         // can't be sure so set all
+         execution = true;
+         construction = true;
+         call = true;
+         within = true;
+         get = true;
+         set = true;
+         withincode = true;
       }
    }
 

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/util/AOPLock.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/AOPLock.java	2008-09-30 03:56:29 UTC (rev 78945)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/AOPLock.java	2008-09-30 05:39:03 UTC (rev 78946)
@@ -31,18 +31,7 @@
 public class AOPLock
 {
    private ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
-   AOPLock parent;
    
-   public AOPLock()
-   {
-      
-   }
-   
-   public AOPLock(AOPLock parent)
-   {
-      this.parent = parent;
-   }
-   
    /**
     * Read-lock just this level
     */
@@ -54,7 +43,7 @@
    /**
     * Read-unlock just this level
     */
-   protected final void unlockRead()
+   public final void unlockRead()
    {
       lock.readLock().unlock();
    }
@@ -74,58 +63,4 @@
    {
       lock.writeLock().unlock();
    }
-
-   /**
-    * Read-lock this level
-    * @param if true, parent levels will be locked too
-    */
-   public void lockRead(boolean lockParents)
-   {
-      if (lockParents && parent != null)
-      {
-         parent.lockRead(lockParents);
-      }
-      lockRead();
-   }
-   
-   /**
-    * Read-unlock this level
-    * @param if true, parent levels will be unlocked too
-    */
-   public void unlockRead(boolean lockParents)
-   {
-      unlockRead();
-      if (lockParents && parent != null)
-      {
-         parent.unlockRead(lockParents);
-      }
-   }
-   
-   /**
-    * Write-lock this level
-    * @param if true, parent levels will be locked too
-    */
-   public void lockWrite(boolean lockParents)
-   {
-      if (lockParents && parent != null)
-      {
-         parent.lockWrite(lockParents);
-      }
-      lockWrite();
-   }
-   
-   /**
-    * Write-unlock this level
-    * @param if true, parent levels will be unlocked too
-    */
-   public void unlockWrite(boolean lockParents)
-   {
-      unlockWrite();
-      if (lockParents && parent != null)
-      {
-         parent.unlockWrite(lockParents);
-      }
-   }
-
-
 }




More information about the jboss-cvs-commits mailing list