[ 
https://issues.apache.org/jira/browse/XALANJ-2439?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12854145#action_12854145
 ] 

Eric Schwarzenbach commented on XALANJ-2439:
--------------------------------------------

I can tell you this patch does not fix all DTM "leaks". 

My own situation is of a template which makes many call-back to my system using 
a Java extension function which returns a DOM NodeList as a result. To simplify 
the scenario, it is more or less like the following: the document being 
transformed has a large number X elements. There is a template for element X in 
my XSLT that makes several such extension function calls, generating (as seen 
by debugging) a DTM for each of these; these are not released when the template 
is exited. I've applied this patch (manually) to the Xalan-J 2.7.1 release 
source, and it does not release the DTMs created in this way.

FWIW, here is a stack trace from the DTMManagerDefault.addDTM call (I simply 
created a RuntimeException in the code and logged it with log4j as a convenient 
way to get this):

org.apache.xml.dtm.ref.DTMManagerDefault : StackTrace for addDTM
java.lang.RuntimeException: fake exception for stacktrace
        at 
org.apache.xml.dtm.ref.DTMManagerDefault.addDTM(DTMManagerDefault.java:167)
        at 
org.apache.xml.dtm.ref.DTMManagerDefault.getDTM(DTMManagerDefault.java:276)
        at 
org.apache.xml.dtm.ref.DTMManagerDefault.getDTMHandleFromNode(DTMManagerDefault.java:579)
        at 
org.apache.xpath.XPathContext.getDTMHandleFromNode(XPathContext.java:189)
        at org.apache.xpath.NodeSetDTM.<init>(NodeSetDTM.java:171)
        at 
org.apache.xpath.objects.XNodeSetForDOM.<init>(XNodeSetForDOM.java:70)
        at 
org.apache.xpath.objects.XObjectFactory.create(XObjectFactory.java:148)
        at org.apache.xpath.objects.XObject.create(XObject.java:180)
        at 
org.apache.xpath.functions.FuncExtFunction.execute(FuncExtFunction.java:212)
        at org.apache.xpath.XPath.execute(XPath.java:337)
        at 
org.apache.xalan.templates.ElemVariable.getValue(ElemVariable.java:280)
        at 
org.apache.xalan.templates.ElemVariable.execute(ElemVariable.java:248)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at 
org.apache.xalan.templates.ElemElement.constructNode(ElemElement.java:341)
        at org.apache.xalan.templates.ElemElement.execute(ElemElement.java:290)
        at 
org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
        at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
        at 
org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
        at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
        at 
org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
        at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at org.apache.xalan.templates.ElemCopy.execute(ElemCopy.java:116)
        at 
org.apache.xalan.templates.ElemApplyTemplates.transformSelectedNodes(ElemApplyTemplates.java:395)
        at 
org.apache.xalan.templates.ElemApplyTemplates.execute(ElemApplyTemplates.java:178)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2458)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2328)
        at org.apache.xalan.lib.Redirect.write(Redirect.java:216)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at 
org.apache.xalan.extensions.ExtensionHandlerJavaClass.processElement(ExtensionHandlerJavaClass.java:517)
        at 
org.apache.xalan.templates.ElemExtensionCall.execute(ElemExtensionCall.java:234)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at org.apache.xalan.templates.ElemChoose.execute(ElemChoose.java:128)
        at 
org.apache.xalan.transformer.TransformerImpl.executeChildTemplates(TransformerImpl.java:2405)
        at 
org.apache.xalan.transformer.TransformerImpl.applyTemplateToNode(TransformerImpl.java:2275)
        at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1361)
        at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:711)
        at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1278)
        at 
org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1256)
        at 
com.wrycan.xms.publisher.transform.XSLTransformType.transform(XSLTransformType.java:92)

I'd note that the code path here seems to be going through none of the classes 
modified by the patch.

> [PATCH] XSLTC resource leak causes 'No more DTM IDs are available' error
> ------------------------------------------------------------------------
>
>                 Key: XALANJ-2439
>                 URL: https://issues.apache.org/jira/browse/XALANJ-2439
>             Project: XalanJ2
>          Issue Type: Bug
>          Components: XSLTC
>    Affects Versions: The Latest Development Code
>         Environment: Linux and Windows XP with Sun JRE 1.5.0_15 and 1.6.0_05
>            Reporter: Helge Schulz
>            Priority: Minor
>             Fix For: The Latest Development Code
>
>         Attachments: DOMLeak-4-NodeSetAndMultiDOM.xsl, 
> DOMLeak-Xalan-SVN-r584164.patch, DOMLeak-XSLT-Test-1.0.jar
>
>   Original Estimate: 4h
>  Remaining Estimate: 4h
>
> The Xalan XSLT compiler (XSLTC) has several resource leaks in handling
> result tree fragments in XSLT variables and parameters. If a variable
> or parameter declaration contains XML elements, a new DOM tree is created
> and a new internal integer id is reserved for it. The garbage collector can
> never retrieve this DOM tree, because the id registration holds a reference
> to it. This bug prevents the transformation of large input files, because
> complex templates creates many result tree fragments and exceeds often the
> absolute limit of possible DOM trees in XSLTC (2^16 = 65535). If this
> limit is reached, XSLTC throws the following exception: 
> DTMException: No more DTM IDs are available
> The attached patch adds a new release method to the DOM interface and calls
> it, when the scope of a variable or parameter is leaved.
> You can test this patch with the attached JAR file. This file can be
> called with
> java -Xmx800M -jar DOMLeak-XSLT-Test-X.Y.jar
> This file contains four test style sheets with expected output files.
> This bug exists also in *all* Sun JRE 1.5 and 1.6 versions, because the
> Xalan XSLTC source code is used in the 'com.sun.org.apache.xalan.internal'
> packages. The attached test JAR file contains also a patch for the current
> Sun JRE version 1.6.0_5 and a fix JAR file to be installed into the
> '../jre/lib/endorsed' directory of the JRE installation.
> Please add the attached test files to the Xalan test suite. I have
> released them under Apache license version 2.0. 
> Helge Schulz - http://OpenSHORE.org
> ----------
> Here is the output of running my test cases with several Java version:
> test:
> apply-with-all-versions:
>     [apply] Buildfile: build.xml
>     [apply] test-java:
>     [apply]      [echo] Test Sun Java 1.4.2_17 with integrated XSLT
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> Ok.
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... Ok.
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.4.2_17 with latest Xalan (SVN 
> revision 584164)
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... ERROR:  'No more DTM IDs are 
> available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... ERROR: 
>  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.4.2_17 with fixed Xalan
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> Ok.
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... Ok.
>     [apply] BUILD SUCCESSFUL
>     [apply] Total time: 1 minute 21 seconds
>     [apply] Buildfile: build.xml
>     [apply] test-java:
>     [apply]      [echo] Test Sun Java 1.5.0_15 with integrated XSLT
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... ERROR:  'No more DTM IDs are 
> available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... ERROR: 
>  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.5.0_15 with latest Xalan (SVN 
> revision 584164)
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... ERROR:  'No more DTM IDs are 
> available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... ERROR: 
>  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.5.0_15 with fixed Xalan
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> Ok.
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... Ok.
>     [apply] BUILD SUCCESSFUL
>     [apply] Total time: 2 minutes 13 seconds
>     [apply] Buildfile: build.xml
>     [apply] test-java:
>     [apply]      [echo] Test Sun Java 1.6.0_05 with integrated XSLT
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... ERROR:  'No more DTM IDs are 
> available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... ERROR: 
>  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> com.sun.org.apache.xml.internal.dtm.DTMException: No more DTM IDs are 
> available
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.6.0_05 with latest Xalan (SVN 
> revision 584164)
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> ERROR:  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... ERROR:  'No more DTM IDs are 
> available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... ERROR: 
>  'No more DTM IDs are available'
>     [apply]      [java]       XSLT Exception: 
> org.apache.xml.dtm.DTMException: No more DTM IDs are available
>     [apply]      [echo] 
>     [apply]      [echo] Test Sun Java 1.6.0_05 with fixed Xalan
>     [apply]      [java]    Testing DOMLeak-1-ResultTreeInVariable.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-2-ResultTreeInCallParameter.xsl... 
> Ok.
>     [apply]      [java]    Testing 
> DOMLeak-3-ResultTreeInApplyParameter.xsl... Ok.
>     [apply]      [java]    Testing DOMLeak-4-NodeSetAndMultiDOM.xsl... Ok.
>     [apply] BUILD SUCCESSFUL
>     [apply] Total time: 1 minute 42 seconds
> BUILD SUCCESSFUL
> Total time: 5 minutes 22 seconds

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


---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-dev-unsubscr...@xml.apache.org
For additional commands, e-mail: xalan-dev-h...@xml.apache.org

Reply via email to