Hi Scott,

after testing resin 4.0.20 it seems that the reported bug has been fixed.
However, there's still another JPA classloader leak which prevents
the web application classloader being garbage collected.

Because I am not allowed to add a comment to bug 4628 at your mantis site,
I am going to report it here:

The cause of the issue is that resin loads the JPA implementation  
library included
within a web application (e.g. EclipseLink) with the global  
classloader instead of the
web application's classloader. (why?)
As a result, after stopping the web application these classes remain loaded.

What makes this even worse is that if a JPA implementation class
refers to a class of my web application which is quite common (if you  
think of hooks,
configuration classes etc.) the web application
classloader also remains referenced and prevents its garbage  
collection forever.

Best regards,
Patric


Quoting Patric Rufflar <pat...@rufflar.com>:

>>
>> Thanks. I've filed this as http://bugs.caucho.com/view.php?id=4628
>>
> Thank you for fixing the bug so quickly.
> Is it possible to backport it to 3.1 as well?
> (if not: is a workaround available?)
>
> Thanks.
>
> Patric
>
>>
>>> Please have a look at
>>> resin-3.1.10\modules\jpa\src\javax\persistence\Persistence.java
>>>
>>> On line 51 there's a WeakHashMap defined, which maps the classloader
>>> to the corresponding PersistenceProvider instances:
>>>
>>>      private static WeakHashMap<ClassLoader,PersistenceProvider[]>
>>>        _providerMap = new WeakHashMap<ClassLoader,PersistenceProvider[]>();
>>>
>>>
>>> The problem is that a PersistenceProvider instance may reference the
>>> key indirectly
>>> (which is at least true when not using Amber, e.g. EclipseLink)
>>> The loaded class will of course reference its classloader, which is
>>> the web application's classloader.
>>> However according to the javadocs this will prevent the removal of  
>>> the entry:
>>>
>>> "Thus care should be taken to ensure that value objects do not
>>> strongly refer to their own keys,
>>> either directly or indirectly, since that will prevent the keys from
>>> being discarded."
>>>
>>> With the consequence that the EnvironmentClassLoader cannot be garbage
>>> collected.
>>>
>>> When looking at the GC roots (for a classloader from a stopped application)
>>> this can be seen easily:
>>>
>>> Class Name
>>>                | Shallow Heap | Retained Heap
>>> ------------------------------------------------------------------------------------------------------------------
>>> com.caucho.loader.EnvironmentClassLoader @ 0xe68362d0
>>>                |          376 |   131.077.664
>>> '-<classloader>   class org.eclipse.persistence.jpa.PersistenceProvider
>>> @ 0xd3bda6d8|            0 |             0
>>>       '-<class>   org.eclipse.persistence.jpa.PersistenceProvider @
>>> 0xe7bb2010         |           24 |            40
>>>          '- [3] javax.persistence.spi.PersistenceProvider[4] @
>>> 0xe7bb2020             |           56 |           144
>>>             '- value java.util.WeakHashMap$Entry @ 0xe7c72ca8
>>>                 |           72 |           432
>>>                '- [11] java.util.WeakHashMap$Entry[16] @ 0xe118fc18
>>>                 |          152 |           800
>>>                   '- table java.util.WeakHashMap @ 0xe118fbe8
>>>                 |           72 |           928
>>>                      '- _providerMap class javax.persistence.Persistence
>>> @ 0xd1fc55a8 |           32 |           960
>>>                         '- [1152] java.lang.Object[1280] @ 0xe0b40378
>>>                 |       10.264 |     1.774.424
>>> ------------------------------------------------------------------------------------------------------------------
>>>
>>> As you can see, the second last line (_providerMap class
>>> javax.persistence.Persistence @ 0xd1fc55a8) which is actually
>>> a caucho class, references the old EnvironmentClassLoader.
>>> So in my case, 131 MB will not get released.
>>>
>>> If I am right - is there a workaround available?
>>> (Is it possible to configure the EnvironmentClassLoader that it  
>>> will not load
>>> the PersistenceProvider/Persistence class from Amber but from the JPA
>>> implementation which my application provides?)
>>>
>>> Thank you and best regards,
>>> Patric
>>>
>>>
>>>
>>>
>>> _______________________________________________
>>> resin-interest mailing list
>>> resin-interest@caucho.com
>>> http://maillist.caucho.com/mailman/listinfo/resin-interest
>>>
>>
>>
>>
>> _______________________________________________
>> resin-interest mailing list
>> resin-interest@caucho.com
>> http://maillist.caucho.com/mailman/listinfo/resin-interest
>
>
>
> _______________________________________________
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest





_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to