[hibernate-dev] Bytecode enhancement

Steve Ebersole steve at hibernate.org
Thu Oct 4 11:00:41 EDT 2012


See https://hibernate.onjira.com/browse/HHH-7667

I want to investigate expanding Hibernate's support for bytecode 
enhancement.  I can see 3 main fronts to this:

1) offloading map lookups from the PersistenceContext .  Currently we 
keep state associated with each entity in a map (a special type of map 
called IdentityMap) on the PersistenceContext, keyed by the entity. 
Profiling consistently shows these maps as a hot-spot.  The main thing 
we keep in the PersistenceContext in regards to the entity is called an 
EntityEntry, which is kept in an IdentityMap<Object,EntityEntry> (again, 
the entity is the key).  So the thought here is to invert this from 
`map.get( entity )` to something like `( (Enhanced) entity 
).getEntityEntry()`

2) More performant dirty-checking.  This already exists, to an extent, 
in the current Hibernate bytecode.  The idea being that we could use 
"interception" within the enhanced entity to know when it becomes dirty. 
  Well, almost.  What is missing is "deep checking of mutable state 
fields".  For example, an entity attribute of type Date that is 
"changed" via entity.getSomeDate().setTime( ... ).  The entity needs to 
be found dirty here, because its "someDate" attribute value has changed, 
but interception will not catch this.  And I think this should be 
configurable (whether the user wants us to perform "deep mutable state 
checking").  We have all the pieces in place to handle this already 
through Type.isMutable() as Hibernate already does a great job of 
finding dirty fields in the most flexible manner.  We just need to 
determine how to best wire that up into enhancement.

3) Alternative means for lazy loading of entity state, meaning an 
alternative to using proxies for the same purpose.  This is different, 
too, from the current enhancement capability of lazy loading of property 
state.  Lazy property loading is meant to delay loading of certain 
field(s) until they are accessed.


Looking for input about how to best design this.  First, is Javassist 
the best choice?  That is what we currently use for enhancement.  Beyond 
that, I am not a bytecode enhancement (by any stretch), so any 
ideas/pointers are welcome.

Thanks.


-- 
steve at hibernate.org
http://hibernate.org


More information about the hibernate-dev mailing list