< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/CallTemplate.java

Print this page
rev 886 : 8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees

@@ -1,8 +1,7 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
  */
 /*
  * Copyright 2001-2004 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");

@@ -15,22 +14,16 @@
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: CallTemplate.java,v 1.2.4.1 2005/09/12 10:02:41 pvedula Exp $
- */
 
 package com.sun.org.apache.xalan.internal.xsltc.compiler;
 
-import com.sun.org.apache.bcel.internal.generic.ALOAD;
-import com.sun.org.apache.bcel.internal.generic.ASTORE;
 import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
 import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
 import com.sun.org.apache.bcel.internal.generic.InstructionList;
-import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
 import com.sun.org.apache.xalan.internal.xsltc.compiler.util.TypeCheckError;

@@ -54,11 +47,11 @@
     /**
      * The array of effective parameters in this CallTemplate. An object in
      * this array can be either a WithParam or a Param if no WithParam
      * exists for a particular parameter.
      */
-    private Object[] _parameters = null;
+    private SyntaxTreeNode[] _parameters = null;
 
     /**
      * The corresponding template which this CallTemplate calls.
      */
     private Template _calleeTemplate = null;

@@ -145,15 +138,14 @@
         StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG
             + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG);
 
         // If calling a simply named template, push actual arguments
         if (_calleeTemplate != null) {
-            Vector calleeParams = _calleeTemplate.getParameters();
             int numParams = _parameters.length;
 
             for (int i = 0; i < numParams; i++) {
-                SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i];
+                SyntaxTreeNode node = _parameters[i];
                 methodSig.append(OBJECT_SIG);   // append Object to signature
 
                 // Push 'null' if Param to indicate no actual parameter specified
                 if (node instanceof Param) {
                     il.append(ACONST_NULL);

@@ -168,10 +160,19 @@
         methodSig.append(")V");
         il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                                                      methodName,
                                                      methodSig.toString())));
 
+        // release temporary result trees
+        if (_parameters != null) {
+            for (int i = 0; i < _parameters.length; i++) {
+                if (_parameters[i] instanceof WithParam) {
+                    ((WithParam)_parameters[i]).releaseResultTree(classGen, methodGen);
+                }
+            }
+        }
+
         // Do not need to call Translet.popParamFrame() if we are
         // calling a simple named template.
         if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) {
             // Pop parameter frame
             final int pop = cpg.addMethodref(TRANSLET_CLASS,

@@ -201,13 +202,13 @@
      * the Param with a corresponding WithParam having the same name.
      */
     private void buildParameterList() {
         // Put the parameters from the called template into the array first.
         // This is to ensure the order of the parameters.
-        Vector defaultParams = _calleeTemplate.getParameters();
+        Vector<Param> defaultParams = _calleeTemplate.getParameters();
         int numParams = defaultParams.size();
-        _parameters = new Object[numParams];
+        _parameters = new SyntaxTreeNode[numParams];
         for (int i = 0; i < numParams; i++) {
             _parameters[i] = defaultParams.elementAt(i);
         }
 
         // Replace a Param with a WithParam if they have the same name.

@@ -220,19 +221,19 @@
                 WithParam withParam = (WithParam)node;
                 QName name = withParam.getName();
 
                 // Search for a Param with the same name
                 for (int k = 0; k < numParams; k++) {
-                    Object object = _parameters[k];
-                    if (object instanceof Param
-                        && ((Param)object).getName().equals(name)) {
+                    SyntaxTreeNode parm = _parameters[k];
+                    if (parm instanceof Param
+                        && ((Param)parm).getName().equals(name)) {
                         withParam.setDoParameterOptimization(true);
                         _parameters[k] = withParam;
                         break;
                     }
-                    else if (object instanceof WithParam
-                        && ((WithParam)object).getName().equals(name)) {
+                    else if (parm instanceof WithParam
+                        && ((WithParam)parm).getName().equals(name)) {
                         withParam.setDoParameterOptimization(true);
                         _parameters[k] = withParam;
                         break;
                     }
                 }
< prev index next >