openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From strub...@apache.org
Subject svn commit: r993145 - in /openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: component/ container/ proxy/ util/
Date Mon, 06 Sep 2010 20:31:16 GMT
Author: struberg
Date: Mon Sep  6 20:31:15 2010
New Revision: 993145

URL: http://svn.apache.org/viewvc?rev=993145&view=rev
Log:
OWB-445 fix mem leaks by using javassist proxy class cache

This also removes ProxyFactory#setHandler and moves the handler 
to the created proxy instances instead. 

Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractOwbBean.java
Mon Sep  6 20:31:15 2010
@@ -689,5 +689,6 @@ public abstract class AbstractOwbBean<T>
             }            
         }
     }
+
     
 }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java
Mon Sep  6 20:31:15 2010
@@ -24,6 +24,7 @@ import javassist.util.proxy.ProxyFactory
 
 import javax.enterprise.context.spi.CreationalContext;
 
+import javassist.util.proxy.ProxyObject;
 import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.proxy.JavassistProxyFactory;
@@ -58,9 +59,9 @@ public class ResourceBean<X, T extends A
             
             ResourceInjectionService resourceService = ServiceLoader.getService(ResourceInjectionService.class);
             this.actualResourceReference = resourceService.getResourceReference(this.resourceReference);
-            proxyFactory.setHandler(new ResourceProxyHandler(this.actualResourceReference));
-            
+
             instance = (X)(JavassistProxyFactory.getInstance().getProxyClass(proxyFactory).newInstance());
+            ((ProxyObject)instance).setHandler(new ResourceProxyHandler(this.actualResourceReference));
         }
         catch (Exception e)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/BeanManagerImpl.java
Mon Sep  6 20:31:15 2010
@@ -76,6 +76,7 @@ import org.apache.webbeans.exception.inj
 import org.apache.webbeans.intercept.InterceptorComparator;
 import org.apache.webbeans.intercept.WebBeansInterceptorConfig;
 import org.apache.webbeans.intercept.webbeans.WebBeansInterceptor;
+import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.plugins.OpenWebBeansJmsPlugin;
 import org.apache.webbeans.plugins.PluginLoader;
 import org.apache.webbeans.portable.AnnotatedElementFactory;
@@ -169,6 +170,8 @@ public class BeanManagerImpl implements 
 
     private AnnotatedElementFactory annotatedElementFactory;
 
+    private WebBeansLogger logger = WebBeansLogger.getLogger(BeanManagerImpl.class);
+
     /**
      * Creates a new {@link BeanManager} instance.
      * Called by the system. Do not use outside of the
@@ -797,19 +800,19 @@ public class BeanManagerImpl implements 
             if(instance != null)
             {
                 return instance;
-            }            
+            }
             
-            if(this.cacheProxies.containsKey(bean))
+            instance = cacheProxies.get(bean);
+
+            if (instance == null)
             {
-                return this.cacheProxies.get(bean);
+                //Create Managed Bean Proxy
+                instance = JavassistProxyFactory.getInstance().createNormalScopedBeanProxy((AbstractOwbBean<?>)bean,creationalContext);
+
+                //Cached instance
+                cacheProxies.put(bean, instance);
             }
-            
-            //Create Managed Bean Proxy
-            instance = JavassistProxyFactory.getInstance().createNormalScopedBeanProxy((AbstractOwbBean<?>)bean,creationalContext);
-            
-            //Cached instance
-            this.cacheProxies.put(bean, instance);
-            
+
         }
         //Create Pseudo-Scope Bean Instance
         else

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/proxy/JavassistProxyFactory.java
Mon Sep  6 20:31:15 2010
@@ -148,7 +148,10 @@ public final class JavassistProxyFactory
         {
             ProxyFactory fact = createProxyFactory(bean);
             AbstractDecoratorMethodHandler handler = new AbstractDecoratorMethodHandler();
+
+            //X TODO we MUST NOT set the handler here! This causes mem leaks!
             fact.setHandler(handler);
+            
             clazz = SecurityUtil.doPrivilegedCreateClass(fact);
         }
         catch(Exception e)
@@ -339,11 +342,6 @@ public final class JavassistProxyFactory
         ProxyFactory fact = new ProxyFactory();        
         fact.setInterfaces(interfaceArray);
         fact.setSuperclass(superClass);        
-
-        // turn off caching since this is utterly broken
-        // this is a static field, but we do not know who else
-        // might turn it on again ...
-        ProxyFactory.useCache = false;
         
         return fact;
         
@@ -358,10 +356,9 @@ public final class JavassistProxyFactory
             ProxyFactory pf = new ProxyFactory();
             pf.setInterfaces(new Class<?>[] { annotationType, Annotation.class });
             pf.setSuperclass(WebBeansAnnotation.class);
-            pf.setHandler(new WebBeansAnnotation(annotationType));
 
             result = (WebBeansAnnotation) pf.create(new Class[] { Class.class }, new Object[]
{ annotationType });
-
+            ((ProxyObject)result).setHandler(new WebBeansAnnotation(annotationType));
         }
         catch (Exception e)
         {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansAnnotatedTypeUtil.java
Mon Sep  6 20:31:15 2010
@@ -765,7 +765,10 @@ public final class WebBeansAnnotatedType
     {
         
         ManagedBean<T> bean = defineManagedBean(type);
+
+        //X TODO move proxy instance creation into JavassistProxyFactory!
         Class clazz = JavassistProxyFactory.getInstance().createAbstractDecoratorProxyClass(bean);
+
         bean.setConstructor(WebBeansUtil.defineConstructor(clazz));
         return bean;
     }

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=993145&r1=993144&r2=993145&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
Mon Sep  6 20:31:15 2010
@@ -2997,7 +2997,10 @@ public final class WebBeansUtil
     {
 
         ManagedBean<T> bean = defineManagedBean(managedBeanCreator, processInjectionTargetEvent);
+
+        //X TODO move proxy instance creation into JavassistProxyFactory!
         Class clazz = JavassistProxyFactory.getInstance().createAbstractDecoratorProxyClass(bean);
+
         bean.setConstructor(WebBeansUtil.defineConstructor(clazz));
         return bean;
     }



Mime
View raw message