]> source.dussan.org Git - aspectj.git/commitdiff
update for temp fix 99861 for Ron
authoravasseur <avasseur>
Tue, 11 Oct 2005 14:39:33 +0000 (14:39 +0000)
committeravasseur <avasseur>
Tue, 11 Oct 2005 14:39:33 +0000 (14:39 +0000)
loadtime/src/org/aspectj/weaver/loadtime/Aj.java
loadtime/src/org/aspectj/weaver/loadtime/ClassLoaderWeavingAdaptor.java

index c340a2862ea65f392a939c4d8eb98ced388a9a33..a34fdd2a186631c51de50b45db41e4f445a6c759 100644 (file)
@@ -52,7 +52,7 @@ public class Aj implements ClassPreProcessor {
      * @param className
      * @param bytes
      * @param loader
-     * @return
+     * @return weaved bytes
      */
     public byte[] preProcess(String className, byte[] bytes, ClassLoader loader) {
         //TODO AV needs to doc that
@@ -85,16 +85,54 @@ public class Aj implements ClassPreProcessor {
         private static Map weavingAdaptors = new WeakHashMap();
 
         static WeavingAdaptor getWeaver(ClassLoader loader, IWeavingContext weavingContext) {
-            synchronized(loader) {//FIXME AV - temp fix for #99861
-                synchronized (weavingAdaptors) {
-                    WeavingAdaptor weavingAdaptor = (WeavingAdaptor) weavingAdaptors.get(loader);
-                    if (weavingAdaptor == null) {
-                        weavingAdaptor = new ClassLoaderWeavingAdaptor(loader, weavingContext);
-                        weavingAdaptors.put(loader, weavingAdaptor);
-                    }
-                    return weavingAdaptor;
+            ExplicitlyInitializedClassLaoderWeavingAdaptor adaptor = null;
+            synchronized(weavingAdaptors) {
+                adaptor = (ExplicitlyInitializedClassLaoderWeavingAdaptor) weavingAdaptors.get(loader);
+                if (adaptor == null) {
+                    // create it and put it back in the weavingAdaptors map but avoid any kind of instantiation
+                    // within the synchronized block
+                    ClassLoaderWeavingAdaptor weavingAdaptor = new ClassLoaderWeavingAdaptor(loader, weavingContext);
+                    adaptor = new ExplicitlyInitializedClassLaoderWeavingAdaptor(weavingAdaptor);
+                    weavingAdaptors.put(loader, adaptor);
                 }
             }
+            // perform the initialization
+            return adaptor.getWeavingAdaptor(loader, weavingContext);
+
+
+            // old version
+//            synchronized(loader) {//FIXME AV - temp fix for #99861
+//                synchronized (weavingAdaptors) {
+//                    WeavingAdaptor weavingAdaptor = (WeavingAdaptor) weavingAdaptors.get(loader);
+//                    if (weavingAdaptor == null) {
+//                        weavingAdaptor = new ClassLoaderWeavingAdaptor(loader, weavingContext);
+//                        weavingAdaptors.put(loader, weavingAdaptor);
+//                    }
+//                    return weavingAdaptor;
+//                }
+//            }
+        }
+    }
+
+    static class ExplicitlyInitializedClassLaoderWeavingAdaptor {
+        private final ClassLoaderWeavingAdaptor weavingAdaptor;
+        private boolean isInitialized;
+
+        public ExplicitlyInitializedClassLaoderWeavingAdaptor(ClassLoaderWeavingAdaptor weavingAdaptor) {
+            this.weavingAdaptor = weavingAdaptor;
+            this.isInitialized = false;
+        }
+
+        private void initialize(ClassLoader loader, IWeavingContext weavingContext) {
+            if (!isInitialized) {
+                isInitialized = true;
+                weavingAdaptor.initialize(loader, weavingContext);
+            }
+        }
+
+        public ClassLoaderWeavingAdaptor getWeavingAdaptor(ClassLoader loader, IWeavingContext weavingContext) {
+            initialize(loader, weavingContext);
+            return weavingAdaptor;
         }
     }
 
index 7e1d9f05a3d7b7501c096f5dc75a5c314b707e58..f314e19d5aaf7699520805085b71e3c1a5d848c3 100644 (file)
@@ -58,7 +58,11 @@ public class ClassLoaderWeavingAdaptor extends WeavingAdaptor {
     private IWeavingContext weavingContext;
 
     public ClassLoaderWeavingAdaptor(final ClassLoader loader, IWeavingContext wContext) {
-        super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures
+        super(null);
+    }
+    
+    void initialize(final ClassLoader loader, IWeavingContext wContext) {
+        //super(null);// at this stage we don't have yet a generatedClassHandler to define to the VM the closures
         this.generatedClassHandler = new GeneratedClassHandler() {
             /**
              * Callback when we need to define a Closure in the JVM