Return-Path: Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: (qmail 13847 invoked from network); 23 Sep 2010 12:10:32 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Sep 2010 12:10:32 -0000 Received: (qmail 31035 invoked by uid 500); 23 Sep 2010 12:10:32 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 30931 invoked by uid 500); 23 Sep 2010 12:10:29 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 30923 invoked by uid 99); 23 Sep 2010 12:10:29 -0000 Received: from Unknown (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 12:10:29 +0000 X-ASF-Spam-Status: No, hits=-1998.7 required=10.0 tests=ALL_TRUSTED,URI_HEX X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 12:10:11 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id o8NC9ndL000760 for ; Thu, 23 Sep 2010 12:09:49 GMT Message-ID: <19773425.362811285243789524.JavaMail.jira@thor> Date: Thu, 23 Sep 2010 08:09:49 -0400 (EDT) From: "Sergey Beryozkin (JIRA)" To: issues@cxf.apache.org Subject: [jira] Commented: (CXF-2939) Permgen Leak in JAXB due to recreation of JAXBContexts in CXF In-Reply-To: <7696923.314291281648376861.JavaMail.jira@thor> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CXF-2939?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12913991#action_12913991 ] Sergey Beryozkin commented on CXF-2939: --------------------------------------- Hmm... So we've solved one problem but have introduced another one... To be honest - this is not the problem of the CXF but that of JAXBElementProvider - quickly rebuilding the one from source and replacing HashMap with WeakHashMap will do it if the weak map is expected. But there must be a better way to choose between HashMaps and WeakHashMaps if it is what is needed to help users to put the cxf into the shared lib > Permgen Leak in JAXB due to recreation of JAXBContexts in CXF > ------------------------------------------------------------- > > Key: CXF-2939 > URL: https://issues.apache.org/jira/browse/CXF-2939 > 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 http://cxf.547215.n5.nabble.com/REST-web-service-loading-many-classes-for-each-request-CXF-2-2-6-and-jaxb-impl-2-1-5-td2266472.html#a2266472: > 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 scratch. > 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.