-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 
Author Message
 Post subject: Why is CGLIB class cache disabled on CGLIBLazyInitializer?
PostPosted: Wed Oct 25, 2006 8:49 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
Hibernate version:
3.1.3

We had Problems with upgrading to Hibernate 3.1 (from 2.1) on an Environment that uses 400+ Databases, all with the same mappings. We got "OutOfMemoryError: PermGen Space" and quickly found out that the permanent generation got filled up with CGLIB-enhanced entity classes. Each database generated their own (altho all used the same entities) bc. each database was accessed using a separate SessionFactory (as recommended).

Digging into the code that generated these classes we found that the CGLIB class cache, that would allow to reuse once generated glasses, is deactivated by default. Following code from CGLIBLazyInitializer.getProxyFactory():

try {
Enhancer en = new Enhancer();
en.setUseCache( false );
en.setInterceptDuringConstruction( false );
...

We activated the cache by changing the code to en.setUseCache(true) and found that this solves our problem. The classes are no longer generated per database but used across all databases.

Is there a special reason for the deactivation of the cache (it still is in hibernate 3.2)? Should we expect problems from enabling it?

At least in one thread of this forum someone recommended enabling the class cache to workaround serialization problems. So I assume it should be ok to do so. But I would like to know what considerations lead to the decision to disable it, so I can judge if it has implications in our situation.

Thanks for any thoughts!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:00 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It was changed to save resources for typical use cases (single session factory ) I see it was a bad idea, patch it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 5:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
what would/will this save for the typical use case baliukas ?

wouldn't enabling it leak memory in another way instead ? e.g. keeping references to undeployed classloaders ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 9:34 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
As I remember it was a problem with "hot deployment", but JVM unloads cached CGLIB classes in my tests. I can not reproduce any problems with this cache. SessionFactory scope proxies is more "safe" way (probably it was too paranoid decision).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 10:54 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
@baliukas: Thanks for your help!

@max: The CLIB class cache uses a WeakHashMap keyed with the ClassLoaders that "loaded" the generated classes, so classes from undeployed ClassLoaders should get gc'd.

Anyway, If this patch is too unsafe and not relevant to the typical usecase, why not make it configurable as sysproperty, so us untypical users do not have to patch the product to get what we want. It might be a seldom problem, but it is a showstopper if you have it.

Searching the forum for "PermGen" it seems that other people already encountered similar problems.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes i'm just curious on wether this is *the* permgen issue.

If cache=true allows for gc collection of unreferenced classes,
why does cache=false still result in permgen growing ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 3:31 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
The gc collection of unreferenced classes is dependent on the gc of their classloader. Only when the classloader is dropped the WeakHashMap will remove the cached classes.

In most cases, as in mine, this is the WebApp class loader. As our web application tries to connect 400+ DBs, all in the context initialisation, this loader of course remains, so the PermGen runs full.

I think some issues, found on the INet, with PermGen errors in development systems are quite similar, where the Appserver fails to dereference old WebApp class loaders after a hot deploy (like here: http://forum.springframework.org/showthread.php?t=21383)

I think enabling the cache will help in cases where many SessionFactories are created based on the same mapping, while the classloade remains (like here: http://forum.hibernate.org/viewtopic.ph ... emoryerror).

It will of course not help with PermGen errors from using mappings for 1900+ different tables like here: http://forum.hibernate.org/viewtopic.ph ... ht=permgen.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 3:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://opensource.atlassian.com/project ... e/HHH-2185

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 4:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
http://opensource.atlassian.com/project ... e/HHH-2185

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
guys, Hibernate 3.2 doesn't call this method anymore; could you check if life is easier on 3.2 for you ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 06, 2006 5:12 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
You are right. We checked hibernate 3.2 again and we don't see increasing permgen there any more. The cache is already enabled.

We thought we had already checked that, but obviously there was an error in our test. Sorry for the inconvenience and have a nice day.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 20, 2007 7:03 am 
Newbie

Joined: Fri Jul 20, 2007 6:02 pm
Posts: 12
Quote:
We got "OutOfMemoryError: PermGen Space"


You work with OC4j Application Server?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 22, 2007 10:23 am 
Newbie

Joined: Tue Jun 29, 2004 9:16 am
Posts: 7
Location: Germany
No, we used Tomcat 5.5.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 13 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.