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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 30 10:57:26 EDT 2007


Author: kabir.khan at jboss.com
Date: 2007-03-30 10:57:26 -0400 (Fri, 30 Mar 2007)
New Revision: 61888

Added:
   projects/aop/trunk/aop/src/main/org/jboss/aop/util/UnmodifiableEmptyCollections.java
Modified:
   projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByConstructorJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByMethodJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/FieldJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByConstructorJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByMethodJoinpoint.java
   projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodJoinpoint.java
Log:
[JBAOP-378] Optimization of InstanceAdvisor creation. Lazy initialize all the AspectManager maps for when actually needed, since each instance advisor has its own domain this is a hell of a lot of maps


Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/AspectManager.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -38,6 +38,7 @@
 import java.util.StringTokenizer;
 import java.util.WeakHashMap;
 import java.util.List;
+import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import org.jboss.aop.advice.AdviceBinding;
 import org.jboss.aop.advice.AdviceStack;
@@ -71,6 +72,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.UnmodifiableEmptyCollections;
 import org.jboss.util.collection.WeakValueHashMap;
 import org.jboss.util.loading.Translatable;
 import org.jboss.util.loading.Translator;
@@ -97,54 +99,57 @@
 public class AspectManager
         implements Translator
 {
+   /** Read/Write lock to be used when lazy creating the collections */
+   ReentrantReadWriteLock lock = new ReentrantReadWriteLock();
 
-   // Attributes ---------------------------------------------------
+   /** Advisors registered with this manager/domain */
    protected final WeakHashMap advisors = new WeakHashMap();
+   
    /** A map of domains by loader repository, maintaned by the top level AspectManager */
-   protected final WeakHashMap scopedClassLoaderDomains = new WeakHashMap();
+   protected WeakHashMap scopedClassLoaderDomains = UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP;
 
    /** A map of domains by class, maintaned by the top level AspectManager */
-   protected final WeakHashMap subDomainsPerClass = new WeakHashMap();
+   protected WeakHashMap subDomainsPerClass = UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP;
    
    /** A map of domains by name */
-   protected final WeakValueHashMap subDomainsByName = new WeakValueHashMap();
+   protected WeakValueHashMap subDomainsByName = UnmodifiableEmptyCollections.EMPTY_WEAK_VALUE_HASHMAP;
 
    /** Each domain may have sub domains interested in changes happening in this manager/domain */
-   protected final WeakHashMap subscribedSubDomains = new WeakHashMap();
+   protected WeakHashMap subscribedSubDomains = UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP;
 
    /** A queue for adding new subscribed subdomains to */
-   protected final WeakHashMap subscribedSubDomainsQueue = new WeakHashMap();
+   protected WeakHashMap subscribedSubDomainsQueue = UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP;
    protected int subscribedDomainQueueRef;
 
-   protected final LinkedHashMap interfaceIntroductions = new LinkedHashMap();
-   protected final LinkedHashMap annotationIntroductions = new LinkedHashMap();
-   protected final LinkedHashMap annotationOverrides = new LinkedHashMap();
-   protected final LinkedHashMap bindings = new LinkedHashMap();
-   protected final LinkedHashMap typedefs = new LinkedHashMap();
-   protected final HashMap interceptorFactories = new HashMap();
-   protected final Hashtable classMetaDataLoaders = new Hashtable();
-   protected final HashMap interceptorStacks = new HashMap();
-   protected final HashMap declares = new HashMap();
-   protected final ConcurrentReaderHashMap cflowStacks = new ConcurrentReaderHashMap();
-   protected final ConcurrentReaderHashMap dynamicCFlows = new ConcurrentReaderHashMap();
-   protected final ConcurrentReaderHashMap aspectDefinitions = new ConcurrentReaderHashMap();
-   protected final ConcurrentReaderHashMap perVMAspects = new ConcurrentReaderHashMap();
+   protected LinkedHashMap interfaceIntroductions = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+   protected LinkedHashMap annotationIntroductions =UnmodifiableEmptyCollections. EMPTY_LINKED_HASHMAP;
+   protected LinkedHashMap annotationOverrides = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+   protected LinkedHashMap bindings = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+   protected LinkedHashMap typedefs = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+   protected HashMap interceptorFactories = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
+   protected HashMap classMetaDataLoaders = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
+   protected HashMap interceptorStacks = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
+   protected HashMap declares = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
+   protected ConcurrentReaderHashMap cflowStacks = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP;
+   protected ConcurrentReaderHashMap dynamicCFlows = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP;
+   protected ConcurrentReaderHashMap aspectDefinitions = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP;
+   protected ConcurrentReaderHashMap perVMAspects = UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP;
 
    /** class name prefixes to explicitly exclude unless contained in include. Maintained by top-level AspectManager */
-   protected final ArrayList exclude = new ArrayList();
+   protected ArrayList exclude = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
 
    /** class name prefixes to explicitly include, this overrides whatever was set in exclude. Maintained by top-level AspectManager */
-   protected final ArrayList include = new ArrayList();
+   protected ArrayList include = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
 
    /** A set of wildcard enabled classnames that will be ignored no matter if they have been included. Maintained by top-level AspectManager */
-   protected final ArrayList ignore = new ArrayList();
+   protected ArrayList ignore = UnmodifiableEmptyCollections.EMPTY_ARRAYLIST;
 
    /** ClassExpressions built from ignore. Maintained by top-level AspectManager */
    protected ClassExpression[] ignoreExpressions = new ClassExpression[0];
 
-   protected final LinkedHashMap pointcuts = new LinkedHashMap();
+   protected LinkedHashMap pointcuts = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
    // contains pointcuts-binding association info
-   protected final LinkedHashMap pointcutInfos = new LinkedHashMap();
+   protected LinkedHashMap pointcutInfos = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
    // these fields represent whether there are certain pointcut types.
    // for performance reasons the transformers and binders can make a lot of us of this.
    protected boolean execution = false;
@@ -156,9 +161,9 @@
    protected boolean withincode = false;
    public static boolean classicOrder = false;
 
-   protected final LinkedHashMap classMetaData = new LinkedHashMap();
-   protected final HashMap containers = new HashMap();
-   protected final LinkedHashMap precedenceDefs = new LinkedHashMap();
+   protected LinkedHashMap classMetaData = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
+   protected HashMap containers = UnmodifiableEmptyCollections.EMPTY_HASHMAP;
+   protected LinkedHashMap precedenceDefs = UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP;
    protected PrecedenceDefEntry[] sortedPrecedenceDefEntries;
    protected WeavingStrategy weavingStrategy;
 
@@ -223,6 +228,13 @@
                   AOPClassPoolRepository.getInstance().setPrune((new Boolean(pruneit)).booleanValue());
                }
                manager = new AspectManager();
+               //Initialise frequently used fields needed by the top-level manager
+               manager.scopedClassLoaderDomains = new WeakHashMap();
+               manager.subDomainsPerClass = new WeakHashMap();
+               manager.exclude = new ArrayList();
+               manager.include = new ArrayList();
+               manager.ignore = new ArrayList();
+
                AOPClassPoolRepository.getInstance().setAspectManager(manager);
 
                if (!verbose)
@@ -308,6 +320,7 @@
                   }
                   scopedManager.setInheritsBindings(true);
                   scopedManager.setInheritsDeclarations(true);
+                  
                   manager.scopedClassLoaderDomains.put(loaderRepository, scopedManager);
                }
             }
@@ -339,6 +352,7 @@
 
    public void addCFlowStack(CFlowStack stack)
    {
+      initCflowStacksMap();
       cflowStacks.put(stack.getName(), stack);
    }
 
@@ -364,6 +378,7 @@
     */
    public void addDynamicCFlow(String name, DynamicCFlowDefinition cflow)
    {
+      initDynamicCflowsMap();
       dynamicCFlows.put(name, cflow);
    }
 
@@ -421,6 +436,7 @@
     */
    public void addClassMetaDataLoader(String group, ClassMetaDataLoader loader)
    {
+      initClassMetaDataLoadersMap();
       classMetaDataLoaders.put(group, loader);
    }
 
@@ -530,6 +546,7 @@
    
    protected void addSubDomainByName(Domain domain)
    {
+      initSubDomainsByNameMap();
       subDomainsByName.put(domain.getDomainName(), domain);
    }
    
@@ -904,12 +921,13 @@
     */
    public void addInterceptorFactory(String name, InterceptorFactory factory)
    {
+      initInterceptorFactoriesMap();
       synchronized (interceptorFactories)
       {
          interceptorFactories.put(name, factory);
       }
    }
-
+   
    /**
     * Remove an interceptor factory that can be referenced by name.
     */
@@ -940,6 +958,7 @@
 
    public void addPrecedence(PrecedenceDef precedenceDef)
    {
+      initPrecedenceDefsMap();
       synchronized (precedenceDefs)
       {
          precedenceDefs.put(precedenceDef.getName(), precedenceDef);
@@ -947,7 +966,6 @@
       forceResortPrecedenceDefs();
    }
 
-
    public void removePrecedence(String name)
    {
       synchronized (precedenceDefs)
@@ -1005,6 +1023,7 @@
     */
    public void addAdviceStack(AdviceStack stack)
    {
+      initInerceptorStacksMap();
       synchronized (interceptorStacks)
       {
          interceptorStacks.put(stack.getName(), stack);
@@ -1128,6 +1147,7 @@
 
    public void addContainer(DomainDefinition def)
    {
+      initContainersMap();
       containers.put(def.getName(), def);
    }
 
@@ -1165,6 +1185,8 @@
    public synchronized void addPointcut(Pointcut pointcut)
    {
       removePointcut(pointcut.getName());
+      initPointcutsMap();
+      initPointcutInfosMap();
       synchronized (pointcuts)
       {
          pointcuts.put(pointcut.getName(), pointcut);
@@ -1333,10 +1355,14 @@
    {
       AdviceBinding removedBinding = internalRemoveBinding(binding.getName());
       Set affectedAdvisors = removedBinding == null? new HashSet(): new HashSet(removedBinding.getAdvisors());
+      initBindingsMap();
       synchronized (bindings)
       {
          bindings.put(binding.getName(), binding);
       }
+      
+      initPointcutsMap();
+      initPointcutInfosMap();
       synchronized (pointcuts)
       {
          Pointcut pointcut = binding.getPointcut();
@@ -1426,6 +1452,7 @@
 
       updateAdvisorsForAddedClassMetaData(meta);
 
+      initClassMetaDataMap();
       synchronized (classMetaData)
       {
          classMetaData.put(meta.getName(), meta);
@@ -1501,6 +1528,7 @@
    public synchronized void addInterfaceIntroduction(InterfaceIntroduction pointcut)
    {
       removeInterfaceIntroduction(pointcut.getName());
+      initInterfaceIntroductionsMap();
       synchronized (interfaceIntroductions)
       {
          interfaceIntroductions.put(pointcut.getName(), pointcut);
@@ -1527,6 +1555,7 @@
    {
       String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression();
       removeAnnotationIntroduction(pointcut);
+      initAnnotationIntroductionsMap();
       synchronized (annotationIntroductions)
       {
          annotationIntroductions.put(name, pointcut);
@@ -1556,6 +1585,7 @@
    public synchronized void addDeclare(DeclareDef declare)
    {
       removeDeclare(declare.getName());
+      initDeclaresMap();
       synchronized (declares)
       {
          declares.put(declare.getName(), declare);
@@ -1623,6 +1653,7 @@
    public synchronized void addAnnotationOverride(AnnotationIntroduction pointcut)
    {
       String name = pointcut.getOriginalAnnotationExpr() + pointcut.getOriginalExpression();
+      initAnnotationOverridesMap();
       synchronized (annotationOverrides)
       {
          annotationOverrides.put(name, pointcut);
@@ -1712,6 +1743,7 @@
                ((AspectFactoryWithClassLoader)adef.getFactory()).pushScopedClassLoader(scopedClassLoader);
             }
             instance = adef.getFactory().createPerVM();
+            initPerVMAspectsMap();
             perVMAspects.put(def, instance);
          }
          finally
@@ -1730,8 +1762,10 @@
       removeAspectDefinition(def.getName());
       if (def.getScope() == Scope.PER_VM)
       {
+         initPerVMAspectsMap();
          perVMAspects.put(def.getName(), def);
       }
+      initAspectDefintitionsMap();
       aspectDefinitions.put(def.getName(), def);
    }
 
@@ -1764,6 +1798,7 @@
    public synchronized void addTypedef(Typedef def) throws Exception
    {
       removeTypedef(def.getName());
+      initTypedefsMap();
       synchronized (typedefs)
       {
          typedefs.put(def.getName(), def);
@@ -1870,6 +1905,7 @@
 
    public void setBindings(LinkedHashMap bindings)
    {
+      initBindingsMap();
       this.bindings.clear();
       this.bindings.putAll(bindings);
    }
@@ -1888,6 +1924,8 @@
     */
    public void subscribeSubDomain(Domain domain)
    {
+      initSubscribedSubDomainsMap();
+      initSubscribedSubDomainsQueueMap();
       synchronized (subscribedSubDomains)
       {
          subscribedSubDomainsQueue.put(domain, "Contents do not matter");
@@ -1929,6 +1967,7 @@
    private boolean copySubDomainsFromQueue(boolean increment)
    {
       boolean copied = false;
+      initSubscribedSubDomainsMap();
       synchronized (subscribedSubDomains)
       {
          if (!increment && subscribedDomainQueueRef > 0) subscribedDomainQueueRef--;
@@ -2014,4 +2053,424 @@
       for (int i = 0 ; i < indent ; i++) System.out.print(" ");
    }
 */
+   /**
+    * Lock for write
+    */
+   protected void lockWrite()
+   {
+//      StackTraceElement[] st = new Exception().getStackTrace();
+//      System.out.println("---> WL++" + lock.getReadLockCount() + " " + st[1]);
+      lock.writeLock().lock();
+   }
+
+   /**
+    * Unlock for write
+    */
+   protected void unlockWrite()
+   {
+//      StackTraceElement[] st = new Exception().getStackTrace();
+//      System.out.println("---> WL--" + lock.getReadLockCount() + " " + st[1]);
+      lock.writeLock().unlock();
+   }
+
+   private void initSubDomainsByNameMap()
+   {
+      if (subDomainsByName == UnmodifiableEmptyCollections.EMPTY_WEAK_VALUE_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (subDomainsByName == UnmodifiableEmptyCollections.EMPTY_WEAK_VALUE_HASHMAP)
+            {
+               subDomainsByName = new WeakValueHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initSubscribedSubDomainsMap()
+   {
+      if (subscribedSubDomains == UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (subscribedSubDomains == UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP)
+            {
+               subscribedSubDomains = new WeakHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }      
+   }
+   
+   private void initSubscribedSubDomainsQueueMap()
+   {
+      if (subscribedSubDomainsQueue == UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (subscribedSubDomainsQueue == UnmodifiableEmptyCollections.EMPTY_WEAK_HASHMAP)
+            {
+               subscribedSubDomainsQueue = new WeakHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initInterfaceIntroductionsMap()
+   {
+      if (interfaceIntroductions == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (interfaceIntroductions == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               interfaceIntroductions = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initAnnotationIntroductionsMap()
+   {
+      if (annotationIntroductions == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (annotationIntroductions == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               annotationIntroductions = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initAnnotationOverridesMap()
+   {
+      if (annotationOverrides == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (annotationOverrides == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               annotationOverrides = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+
+   private void initBindingsMap()
+   {
+      if (bindings == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (bindings == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               bindings = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+
+   private void initTypedefsMap()
+   {
+      if (typedefs == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (typedefs == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               typedefs = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+
+   private void initInterceptorFactoriesMap()
+   {
+      if (interceptorFactories == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (interceptorFactories == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+            {
+               interceptorFactories = new HashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initClassMetaDataLoadersMap()
+   {
+      if (classMetaDataLoaders == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (classMetaDataLoaders == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+            {
+               classMetaDataLoaders = new HashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initInerceptorStacksMap()
+   {
+      if (interceptorStacks == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (interceptorStacks == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+            {
+               interceptorStacks = new HashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   
+   private void initDeclaresMap()
+   {
+      if (declares == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (declares == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+            {
+               declares = new HashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initCflowStacksMap()
+   {
+      if (cflowStacks == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (cflowStacks == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+            {
+               cflowStacks = new ConcurrentReaderHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initDynamicCflowsMap()
+   {
+      if (dynamicCFlows == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (dynamicCFlows == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+            {
+               dynamicCFlows = new ConcurrentReaderHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initAspectDefintitionsMap()
+   {
+      if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (aspectDefinitions == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+            {
+               aspectDefinitions = new ConcurrentReaderHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initPerVMAspectsMap()
+   {
+      if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (perVMAspects == UnmodifiableEmptyCollections.EMPTY_CONCURRENT_READER_HASHMAP)
+            {
+               perVMAspects = new ConcurrentReaderHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initPointcutsMap()
+   {
+      if (pointcuts == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (pointcuts == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               pointcuts = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initPointcutInfosMap()
+   {
+      if (pointcutInfos == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (pointcutInfos == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               pointcutInfos = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   
+   private void initClassMetaDataMap()
+   {
+      if (classMetaData == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (classMetaData == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               classMetaData = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   private void initContainersMap()
+   {
+      if (containers == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (containers == UnmodifiableEmptyCollections.EMPTY_HASHMAP)
+            {
+               containers = new HashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+   
+   private void initPrecedenceDefsMap()
+   {
+      if (precedenceDefs == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+      {
+         lockWrite();
+         try
+         {
+            if (precedenceDefs == UnmodifiableEmptyCollections.EMPTY_LINKED_HASHMAP)
+            {
+               precedenceDefs = new LinkedHashMap();
+            }
+         }
+         finally
+         {
+            unlockWrite();
+         }
+      }
+   }
+
 }

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/GeneratedClassAdvisor.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -73,15 +73,13 @@
    /** Super class methods that have been overrridden - these need special handling in this weaving mode */
    ArrayList overriddenMethods = new ArrayList(); 
 
-   ConcurrentReaderHashMap constructorJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap constructionJoinPoinGenerators = new ConcurrentReaderHashMap();
+   //TODO These are only needed for the class advisor really
+   //All joinpoint generators apart from field reads and constructions go in here
+   ConcurrentReaderHashMap joinPoinGenerators = new ConcurrentReaderHashMap();
+   //Needs its own map to avoid crashing with the field write generators
    ConcurrentReaderHashMap fieldReadJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap fieldWriteJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap methodJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap methodByConJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap methodByMethodJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap conByConJoinPoinGenerators = new ConcurrentReaderHashMap();
-   ConcurrentReaderHashMap conByMethodJoinPoinGenerators = new ConcurrentReaderHashMap();
+   //Needs its own map to avoid crashing with the constructor generators
+   ConcurrentReaderHashMap constructionJoinPointGenerators = new ConcurrentReaderHashMap();
 
    boolean initialisedSuperClasses; 
 
@@ -400,12 +398,12 @@
    {
       //An extra level of indirection since we distinguish between callers of method depending on
       //where the called method is defined (sub/super interfaces)
-      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)methodByConJoinPoinGenerators.get(info.getJoinpoint());
+      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       if (map == null)
       {
          map = new ConcurrentReaderHashMap();
-         methodByConJoinPoinGenerators.put(info.getJoinpoint(), map);
-         map = (ConcurrentReaderHashMap)methodByConJoinPoinGenerators.get(info.getJoinpoint());
+         joinPoinGenerators.put(info.getJoinpoint(), map);
+         map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       }
 
       MethodByConJoinPointGenerator generator = getJoinPointGenerator(info);
@@ -414,11 +412,11 @@
 
    protected MethodJoinPointGenerator getJoinPointGenerator(MethodInfo info)
    {
-      MethodJoinPointGenerator generator = (MethodJoinPointGenerator)methodJoinPoinGenerators.get(info.getJoinpoint());
+      MethodJoinPointGenerator generator = (MethodJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
          generator = new MethodJoinPointGenerator(this, info);
-         methodJoinPoinGenerators.put(info.getJoinpoint(), generator);
+         joinPoinGenerators.put(info.getJoinpoint(), generator);
       }
       return generator;
    }
@@ -437,11 +435,11 @@
       }
       else
       {
-         FieldJoinPointGenerator generator = (FieldJoinPointGenerator)fieldWriteJoinPoinGenerators.get(info.getJoinpoint());
+         FieldJoinPointGenerator generator = (FieldJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
          if (generator == null)
          {
             generator = new FieldJoinPointGenerator(this, info);
-            fieldWriteJoinPoinGenerators.put(info.getJoinpoint(), generator);
+            joinPoinGenerators.put(info.getJoinpoint(), generator);
          }
          return generator;
       }
@@ -454,22 +452,22 @@
 
    protected ConstructorJoinPointGenerator getJoinPointGenerator(ConstructorInfo info)
    {
-      ConstructorJoinPointGenerator generator = (ConstructorJoinPointGenerator)constructorJoinPoinGenerators.get(info.getJoinpoint());
+      ConstructorJoinPointGenerator generator = (ConstructorJoinPointGenerator)constructionJoinPointGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
          generator = new ConstructorJoinPointGenerator(this, info);
-         constructorJoinPoinGenerators.put(info.getJoinpoint(), generator);
+         constructionJoinPointGenerators.put(info.getJoinpoint(), generator);
       }
       return generator;
    }
 
    protected ConstructionJoinPointGenerator getJoinPointGenerator(ConstructionInfo info)
    {
-      ConstructionJoinPointGenerator generator = (ConstructionJoinPointGenerator)constructionJoinPoinGenerators.get(info.getJoinpoint());
+      ConstructionJoinPointGenerator generator = (ConstructionJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
          generator = new ConstructionJoinPointGenerator(this, info);
-         constructionJoinPoinGenerators.put(info.getJoinpoint(), generator);
+         joinPoinGenerators.put(info.getJoinpoint(), generator);
       }
       return generator;
    }
@@ -478,12 +476,12 @@
    {
       //An extra level of indirection since we distinguish between callers of method depending on
       //where the called method is defined (sub/super interfaces)
-      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)methodByMethodJoinPoinGenerators.get(info.getJoinpoint());
+      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       if (map == null)
       {
          map = new ConcurrentReaderHashMap();
-         methodByMethodJoinPoinGenerators.put(info.getJoinpoint(), map);
-         map = (ConcurrentReaderHashMap)methodByMethodJoinPoinGenerators.get(info.getJoinpoint());
+         joinPoinGenerators.put(info.getJoinpoint(), map);
+         map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       }
 
       MethodByMethodJoinPointGenerator generator = (MethodByMethodJoinPointGenerator)map.get(info.getCalledClass());
@@ -498,22 +496,22 @@
 
    protected ConByMethodJoinPointGenerator getJoinPointGenerator(ConByMethodInfo info)
    {
-      ConByMethodJoinPointGenerator generator = (ConByMethodJoinPointGenerator)conByMethodJoinPoinGenerators.get(info.getJoinpoint());
+      ConByMethodJoinPointGenerator generator = (ConByMethodJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
          generator = new ConByMethodJoinPointGenerator(this, info);
-         conByMethodJoinPoinGenerators.put(info.getJoinpoint(), generator);
+         joinPoinGenerators.put(info.getJoinpoint(), generator);
       }
       return generator;
    }
 
    protected ConByConJoinPointGenerator getJoinPointGenerator(ConByConInfo info)
    {
-      ConByConJoinPointGenerator generator = (ConByConJoinPointGenerator)conByConJoinPoinGenerators.get(info.getJoinpoint());
+      ConByConJoinPointGenerator generator = (ConByConJoinPointGenerator)joinPoinGenerators.get(info.getJoinpoint());
       if (generator == null)
       {
          generator = new ConByConJoinPointGenerator(this, info);
-         conByConJoinPoinGenerators.put(info.getJoinpoint(), generator);
+         joinPoinGenerators.put(info.getJoinpoint(), generator);
       }
       return generator;
    }
@@ -522,12 +520,12 @@
    {
       //An extra level of indirection since we distinguish between callers of method depending on
       //where the called method is defined (sub/super interfaces)
-      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)methodByConJoinPoinGenerators.get(info.getJoinpoint());
+      ConcurrentReaderHashMap map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       if (map == null)
       {
          map = new ConcurrentReaderHashMap();
-         methodByConJoinPoinGenerators.put(info.getJoinpoint(), map);
-         map = (ConcurrentReaderHashMap)methodByConJoinPoinGenerators.get(info.getJoinpoint());
+         joinPoinGenerators.put(info.getJoinpoint(), map);
+         map = (ConcurrentReaderHashMap)joinPoinGenerators.get(info.getJoinpoint());
       }
 
       MethodByConJoinPointGenerator generator = (MethodByConJoinPointGenerator)map.get(info.getCalledClass());

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByConstructorJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByConstructorJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByConstructorJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -33,6 +33,7 @@
 {
    private final Constructor calling;
    private final Constructor called;
+   int hashCode;
 
    public ConstructorCalledByConstructorJoinpoint(Constructor calling, Constructor called)
    {
@@ -53,7 +54,11 @@
 
    public int hashCode()
    {
-      return calling.hashCode() + called.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = calling.hashCode() + called.hashCode();
+      }
+      return hashCode;
    }
 
    public Constructor getCalling()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByMethodJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByMethodJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorCalledByMethodJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -34,6 +34,7 @@
 {
    private final Method calling;
    private final Constructor called;
+   int hashCode;
 
    public ConstructorCalledByMethodJoinpoint(Method calling, Constructor called)
    {
@@ -54,7 +55,11 @@
 
    public int hashCode()
    {
-      return calling.hashCode() + called.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = calling.hashCode() + called.hashCode();
+      }
+      return hashCode;
    }
 
    public Method getCalling()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/ConstructorJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -32,6 +32,7 @@
 public class ConstructorJoinpoint implements Joinpoint
 {
    private final Constructor constructor;
+   int hashCode;
 
    public ConstructorJoinpoint(Constructor con)
    {
@@ -49,7 +50,11 @@
 
    public int hashCode()
    {
-      return constructor.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = constructor.hashCode();
+      }
+      return hashCode;
    }
 
    public Constructor getConstructor()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/FieldJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/FieldJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/FieldJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -32,6 +32,7 @@
 public class FieldJoinpoint implements Joinpoint
 {
    private final Field field;
+   int hashCode;
 
    public FieldJoinpoint(Field field)
    {
@@ -49,7 +50,11 @@
 
    public int hashCode()
    {
-      return field.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = field.hashCode();
+      }
+      return hashCode;
    }
 
    public Field getField()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByConstructorJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByConstructorJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByConstructorJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -34,6 +34,7 @@
 {
    private final Constructor calling;
    private final Method called;
+   int hashCode;
 
    public MethodCalledByConstructorJoinpoint(Constructor calling, Method called)
    {
@@ -54,7 +55,11 @@
 
    public int hashCode()
    {
-      return calling.hashCode() + called.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = calling.hashCode() + called.hashCode();
+      }
+      return hashCode;
    }
 
    public Constructor getCalling()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByMethodJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByMethodJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodCalledByMethodJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -33,6 +33,7 @@
 {
    private final Method calling;
    private final Method called;
+   int hashCode;
 
    public MethodCalledByMethodJoinpoint(Method calling, Method called)
    {
@@ -53,7 +54,11 @@
 
    public int hashCode()
    {
-      return calling.hashCode() + called.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = calling.hashCode() + called.hashCode();
+      }
+      return hashCode;
    }
 
    public Method getCalling()

Modified: projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodJoinpoint.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodJoinpoint.java	2007-03-30 14:39:54 UTC (rev 61887)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/joinpoint/MethodJoinpoint.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -32,6 +32,7 @@
 public class MethodJoinpoint implements Joinpoint
 {
    private final Method method;
+   int hashCode;
 
    public MethodJoinpoint(Method method)
    {
@@ -49,7 +50,11 @@
 
    public int hashCode()
    {
-      return method.hashCode();
+      if (hashCode == 0)
+      {
+         hashCode = method.hashCode();
+      }
+      return hashCode;
    }
 
    public Method getMethod()

Added: projects/aop/trunk/aop/src/main/org/jboss/aop/util/UnmodifiableEmptyCollections.java
===================================================================
--- projects/aop/trunk/aop/src/main/org/jboss/aop/util/UnmodifiableEmptyCollections.java	                        (rev 0)
+++ projects/aop/trunk/aop/src/main/org/jboss/aop/util/UnmodifiableEmptyCollections.java	2007-03-30 14:57:26 UTC (rev 61888)
@@ -0,0 +1,151 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors. 
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/ 
+package org.jboss.aop.util;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.util.collection.WeakValueHashMap;
+
+import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+
+
+/**
+ * Implementation of different types of maps, lists etc. that do not support modification.
+ * Collections.unmodifiableMap() returns an instanceof Collections$UnmodifiableMap
+ * which can only be cast to the Map interface and the same goes for lists
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class UnmodifiableEmptyCollections
+{
+   public static final LinkedHashMap EMPTY_LINKED_HASHMAP = new LockedLinkedHashMap();
+   public static final ConcurrentReaderHashMap EMPTY_CONCURRENT_READER_HASHMAP = new LockedConcurrentReaderHashMap();
+   public static final HashMap EMPTY_HASHMAP = new LockedHashMap();
+   public static final WeakHashMap EMPTY_WEAK_HASHMAP = new LockedWeakHashMap();
+   public static final WeakValueHashMap EMPTY_WEAK_VALUE_HASHMAP = new LockedWeakValueHashMap();
+   public static final ArrayList EMPTY_ARRAYLIST = new LockedArrayList();
+
+   private static class LockedHashMap<K,V> extends HashMap<K,V>
+   {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public V put(K key, V value) 
+      {
+         throw new UnsupportedOperationException();
+      }
+      @Override
+      public void putAll(Map<? extends K, ? extends V> t) 
+      {
+         throw new UnsupportedOperationException();
+      }
+   }
+
+   private static class LockedLinkedHashMap<K,V> extends LinkedHashMap<K,V>
+   {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public V put(K key, V value) 
+      {
+         throw new UnsupportedOperationException();
+      }
+      @Override
+      public void putAll(Map<? extends K, ? extends V> t) 
+      {
+         throw new UnsupportedOperationException();
+      }
+   }
+
+   private static class LockedConcurrentReaderHashMap extends ConcurrentReaderHashMap
+   {
+      private static final long serialVersionUID = 1L;
+
+      @Override
+      public Object put(Object arg0, Object arg1)
+      {
+         return super.put(arg0, arg1);
+      }
+      @Override
+      public synchronized void putAll(Map arg0)
+      {
+         super.putAll(arg0);
+      }
+   }
+   
+   private static class LockedWeakHashMap<K,V> extends WeakHashMap<K,V>
+   {
+      private static final long serialVersionUID = 1L;
+      @Override
+      public V put(K key, V value) 
+      {
+         throw new UnsupportedOperationException();
+      }
+      @Override
+      public void putAll(Map<? extends K, ? extends V> t) 
+      {
+         throw new UnsupportedOperationException();
+      }
+   }
+   
+   private static class LockedWeakValueHashMap extends WeakValueHashMap
+   {
+      private static final long serialVersionUID = 1L;
+      @Override
+      public Object put(Object arg0, Object arg1)
+      {
+         return super.put(arg0, arg1);
+      }
+      @Override
+      public synchronized void putAll(Map arg0)
+      {
+         super.putAll(arg0);
+      }
+   }
+   
+   private static class LockedArrayList<E> extends ArrayList<E>
+   {
+      private static final long serialVersionUID = 1L;
+      
+      @Override
+      public E set(int index, E element) 
+      {
+         throw new UnsupportedOperationException();
+      }
+      @Override
+      public void add(int index, E element) 
+      {
+         throw new UnsupportedOperationException();
+      }
+      @Override
+      public boolean addAll(int index, Collection<? extends E> c) 
+      {
+         throw new UnsupportedOperationException();
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list