cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stefan Schubert (JIRA)" <>
Subject [jira] Commented: (CXF-2939) Permgen Leak in JAXB due to recreation of JAXBContexts in CXF
Date Thu, 23 Sep 2010 15:05:48 GMT


Stefan Schubert commented on CXF-2939:

Does CXF work as a shared lib anyway? Can I deploy a second Webapp using CXF and it works
with the shared lib? If not, we should not do anything to enable this.

If yes, you can think about a shutdown or refresh hook. As far as I know CXF already listens
to Spring framework application events. If it is shutting down or refreshing, you could simply
evict the context specific caches. Just look at org.apache.cxf.transport.servlet.CXFServlet#onApplicationEvent
which is already doing maintenance work on refreshes. It could probably do more

> Permgen Leak in JAXB due to recreation of JAXBContexts in CXF
> -------------------------------------------------------------
>                 Key: CXF-2939
>                 URL:
>             Project: CXF
>          Issue Type: Bug
>          Components: JAX-RS
>    Affects Versions: 2.1.5
>            Reporter: Stefan Schubert
>            Assignee: Daniel Kulp
>             Fix For: 2.2.10
>         Attachments: removed_weak_hash_maps.patch
> From
> If a GC occurs, WeakRefs throw away the JAXBContext. So on the next occasion (where occasion
could be one of billions of calls to a CXF/JAXB api) the JAXBContext has to be rebuilt from
> JAXB (specifically com.sun.xml.bind.v2.runtime.reflect.opt.AccessorInjector) calls com.sun.xml.bind.v2.runtime.reflect.opt.Injector#find
to try, if it already created a field or method accessor class. If not it injects a new one
into the class loader via com.sun.xml.bind.v2.runtime.reflect.opt.Injector#inject. 
> The problem is now that #inject caches the generated accessor in the Injector and find
only looks into the Injector (and never again into the class loader, where it used to define
the class). But once a GC occurs the Injector throws itself away, too (caching itself in some
weak map). 
> So it happens that each REST api call after a GC occurred a hundred new classes are created
by JAXB - because JAXB on low-level forgets the classes it defines (and keeps them on high-level)
and CXF forgets the JAXBContext so that the high-level memory of JAXB is erased as well. 
> There are four possible solutions: 
>  - Fix the Injector: Actually very easy and my favorite solution. Just let the Injector
look into the class loader as well when it cannot find the class in its own memory. BUT to
have a bug fixed in JAXB actually sounds scary, how long would that take to get into a version?)

>  - Enable CXF to keep only one JAXB context (and not to throw it away) - do not know
how to do that 
>  - Use a workaround to disable bytecode generation by JAXB (-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true)
--> disables the whole bytecode magic Injector stuff and just does reflection - probably
with a slight performance impact 
>  - Do not use JAXB with CXF on a website with significant load 

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message