ExplicitGCInvokesConcurrentAndUnloadsClasses leaks PermGen

Tony Printezis tprintezis at twitter.com
Tue Aug 27 12:20:15 UTC 2013


A STW Full GC will look at the entire heap and find everything that's 
unreachable at that particular time. A CMS cycle will only look at the 
old gen (and that incrementally, so some objects that become unreachable 
during the cycle might not be collected) and, as Mikael pointed out, 
also assume everything in the young gen is live (including objects that 
might not be). You really need to do a few cycles and maybe do some 
dummy allocations for a while to make sure that all weak refs that you 
are interested have been correctly processed by CMS.

General take-away from this: writing such tests is a royal PITA.


On 8/27/13 2:40 AM, Jungwoo Ha wrote:
> Hi Mikael,
> Does the implicit reference you mentioned should show up in the heap dump?
> My collaborator checked the heap dump, and he didn't find any pointers 
> to the older classloader other than the weak ref.
> Jungwoo
> On Mon, Aug 26, 2013 at 10:35 PM, Mikael Gerdin 
> <mikael.gerdin at oracle.com <mailto:mikael.gerdin at oracle.com>> wrote:
>     Hi Jungwoo,
>     The situation I described only affects concurrent collections with
>     CMS.
>     If the explicit GC is STW (and thereby recorded as a Full GC in
>     the log) then you should not be seeing any issues.
>     Please make sure that you don't leak classes as it is very easy to
>     miss due to the implicit reference from Java
>     object->Class->ClassLoader.
>     /Mikael
>     On 26 August 2013 23:26:12 Jungwoo Ha wrote:
>>     Hi Mikael,
>>     Does this also happen if the Explicit GC is STW?
>>     I have been reported that it also happens in STW Explicit GC.
>>     Much rarely though.
>>     Jungwoo
>>     On Wed, Aug 14, 2013 at 11:43 PM, Mikael Gerdin
>>     <mikael.gerdin at oracle.com <mailto:mikael.gerdin at oracle.com>> wrote:
>>         Hi,
>>         On 08/15/2013 02:37 AM, Jungwoo Ha wrote:
>>             Hi,
>>             Is ExplicitGCInvokesConcurrentAndUnloadsClasses
>>             guaranteed to unload all
>>             unused classes?
>>             We installed weak reference on the class objects to see
>>             none of the
>>             class objects are leaked.
>>             When using STW Explict GC all of the unused classes are
>>             unloaded,
>>             but when using above flag, only some are get unloaded.
>>             I double-checked the GC log and waited until the
>>             concurrent GC to finish
>>             its job.
>>             Is this an expected behavior or a bug?
>>             BTW, The leak detecting code using weak reference is used
>>             for a long time,
>>             which I think is quite stable.
>>             Any comments are appreciated!
>>         A caveat with CMS and class unloading is that CMS treats all
>>         objects in the young generation as strong roots. You need to
>>         make sure that you've triggered enough young GCs so that your
>>         weak references are promoted out of the young gen before
>>         triggering the explicit CMS cycle.
>>         If you have a small test case you can try reducing the young
>>         gen size and setting MaxTenuringThreshold=1 and see if all
>>         the classes get unloaded as you expected.
>>         /Mikael
>>             Thanks,
>>             Jungwoo Ha

Tony Printezis | Staff Software Engineer | Twitter

tprintezis at twitter.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/hotspot-gc-dev/attachments/20130827/c2046e29/attachment.htm>

More information about the hotspot-gc-dev mailing list