8150704: XALAN: ERROR: 'No more DTM IDs are available' when transforming with lots of temporary result trees

Reviewed-by: joehw
This commit is contained in:
Christoph Langer 2016-03-09 16:09:55 -08:00 committed by Joe Wang
parent 7f3c7fe56b
commit 7b2839f9ee
25 changed files with 4916 additions and 396 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOM.java,v 1.2.4.1 2005/08/31 10:18:49 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc;
@ -102,4 +99,5 @@ public interface DOM {
public int getDocument();
public String getUnparsedEntityURI(String name);
public Map<String, Integer> getElementsWithIDs();
public void release();
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: ApplyTemplates.java,v 1.2.4.1 2005/09/12 09:59:21 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
@ -122,12 +119,10 @@ final class ApplyTemplates extends Instruction {
final int current = methodGen.getLocalIndex("current");
// check if sorting nodes is required
final Vector sortObjects = new Vector();
final Iterator<SyntaxTreeNode> children = elements();
while (children.hasNext()) {
final SyntaxTreeNode child = children.next();
final Vector<Sort> sortObjects = new Vector<>();
for (final SyntaxTreeNode child : getContents()) {
if (child instanceof Sort) {
sortObjects.addElement(child);
sortObjects.addElement((Sort)child);
}
}
@ -193,6 +188,13 @@ final class ApplyTemplates extends Instruction {
applyTemplatesSig);
il.append(new INVOKEVIRTUAL(applyTemplates));
// unmap parameters to release temporary result trees
for (final SyntaxTreeNode child : getContents()) {
if (child instanceof WithParam) {
((WithParam)child).releaseResultTree(classGen, methodGen);
}
}
// Pop parameter frame
if (stylesheet.hasLocalParams() || hasContents()) {
il.append(classGen.loadTranslet());

View file

@ -1,6 +1,5 @@
/*
* 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.
@ -17,18 +16,12 @@
* 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;
@ -56,7 +49,7 @@ final class CallTemplate extends Instruction {
* 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.
@ -147,11 +140,10 @@ final class CallTemplate extends Instruction {
// 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
@ -170,6 +162,15 @@ final class CallTemplate extends Instruction {
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())) {
@ -203,9 +204,9 @@ final class CallTemplate extends Instruction {
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);
}
@ -222,15 +223,15 @@ final class CallTemplate extends Instruction {
// 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;

View file

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 2001-2005 The Apache Software Foundation.
@ -17,32 +16,22 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: Sort.java,v 1.2.4.1 2005/09/12 11:08:12 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.text.Collator;
import java.util.ArrayList;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.Vector;
import com.sun.org.apache.bcel.internal.classfile.Field;
import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.ALOAD;
import com.sun.org.apache.bcel.internal.generic.ANEWARRAY;
import com.sun.org.apache.bcel.internal.generic.ASTORE;
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.GETFIELD;
import com.sun.org.apache.bcel.internal.generic.ICONST;
import com.sun.org.apache.bcel.internal.generic.ILOAD;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
@ -76,13 +65,10 @@ final class Sort extends Instruction implements Closure {
private AttributeValue _order;
private AttributeValue _caseOrder;
private AttributeValue _dataType;
private String _lang; // bug! see 26869
private String _data = null;
private String _lang; // bug! see 26869
private String _className = null;
private ArrayList _closureVars = null;
private ArrayList<VariableRefBase> _closureVars = null;
private boolean _needsSortRecordFactory = false;
// -- Begin Closure interface --------------------
@ -115,7 +101,7 @@ final class Sort extends Instruction implements Closure {
*/
public void addVariable(VariableRefBase variableRef) {
if (_closureVars == null) {
_closureVars = new ArrayList();
_closureVars = new ArrayList<>();
}
// Only one reference per variable
@ -246,7 +232,7 @@ final class Sort extends Instruction implements Closure {
public static void translateSortIterator(ClassGenerator classGen,
MethodGenerator methodGen,
Expression nodeSet,
Vector sortObjects)
Vector<Sort> sortObjects)
{
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
@ -312,7 +298,7 @@ final class Sort extends Instruction implements Closure {
* Compiles code that instantiates a NodeSortRecordFactory object which
* will produce NodeSortRecord objects of a specific type.
*/
public static void compileSortRecordFactory(Vector sortObjects,
public static void compileSortRecordFactory(Vector<Sort> sortObjects,
ClassGenerator classGen, MethodGenerator methodGen)
{
String sortRecordClass =
@ -321,7 +307,7 @@ final class Sort extends Instruction implements Closure {
boolean needsSortRecordFactory = false;
final int nsorts = sortObjects.size();
for (int i = 0; i < nsorts; i++) {
final Sort sort = (Sort) sortObjects.elementAt(i);
final Sort sort = sortObjects.elementAt(i);
needsSortRecordFactory |= sort._needsSortRecordFactory;
}
@ -429,7 +415,7 @@ final class Sort extends Instruction implements Closure {
+ "[" + STRING_SIG + ")V")));
// Initialize closure variables in sortRecordFactory
final ArrayList dups = new ArrayList();
final ArrayList<VariableRefBase> dups = new ArrayList<>();
for (int j = 0; j < nsorts; j++) {
final Sort sort = (Sort) sortObjects.get(j);
@ -437,7 +423,7 @@ final class Sort extends Instruction implements Closure {
sort._closureVars.size();
for (int i = 0; i < length; i++) {
VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
VariableRefBase varRef = sort._closureVars.get(i);
// Discard duplicate variable references
if (dups.contains(varRef)) continue;
@ -455,11 +441,11 @@ final class Sort extends Instruction implements Closure {
}
}
public static String compileSortRecordFactory(Vector sortObjects,
public static String compileSortRecordFactory(Vector<Sort> sortObjects,
ClassGenerator classGen, MethodGenerator methodGen,
String sortRecordClass)
{
final XSLTC xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
final XSLTC xsltc = (sortObjects.firstElement()).getXSLTC();
final String className = xsltc.getHelperClassName();
final NodeSortRecordFactGenerator sortRecordFactory =
@ -474,15 +460,15 @@ final class Sort extends Instruction implements Closure {
// Add a new instance variable for each var in closure
final int nsorts = sortObjects.size();
final ArrayList dups = new ArrayList();
final ArrayList<VariableRefBase> dups = new ArrayList<>();
for (int j = 0; j < nsorts; j++) {
final Sort sort = (Sort) sortObjects.get(j);
final Sort sort = sortObjects.get(j);
final int length = (sort._closureVars == null) ? 0 :
sort._closureVars.size();
for (int i = 0; i < length; i++) {
final VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);
final VariableRefBase varRef = sort._closureVars.get(i);
// Discard duplicate variable references
if (dups.contains(varRef)) continue;
@ -600,10 +586,10 @@ final class Sort extends Instruction implements Closure {
/**
* Create a new auxillary class extending NodeSortRecord.
*/
private static String compileSortRecord(Vector sortObjects,
private static String compileSortRecord(Vector<Sort> sortObjects,
ClassGenerator classGen,
MethodGenerator methodGen) {
final XSLTC xsltc = ((Sort)sortObjects.firstElement()).getXSLTC();
final XSLTC xsltc = sortObjects.firstElement().getXSLTC();
final String className = xsltc.getHelperClassName();
// This generates a new class for handling this specific sort
@ -619,10 +605,10 @@ final class Sort extends Instruction implements Closure {
// Add a new instance variable for each var in closure
final int nsorts = sortObjects.size();
final ArrayList dups = new ArrayList();
final ArrayList<VariableRefBase> dups = new ArrayList<>();
for (int j = 0; j < nsorts; j++) {
final Sort sort = (Sort) sortObjects.get(j);
final Sort sort = sortObjects.get(j);
// Set the name of the inner class in this sort object
sort.setInnerClassName(className);
@ -644,8 +630,7 @@ final class Sort extends Instruction implements Closure {
}
}
MethodGenerator init = compileInit(sortObjects, sortRecord,
cpg, className);
MethodGenerator init = compileInit(sortRecord, cpg, className);
MethodGenerator extract = compileExtract(sortObjects, sortRecord,
cpg, className);
sortRecord.addMethod(init);
@ -660,8 +645,7 @@ final class Sort extends Instruction implements Closure {
* collator in the super calls only when the stylesheet specifies a new
* language in xsl:sort.
*/
private static MethodGenerator compileInit(Vector sortObjects,
NodeSortRecordGenerator sortRecord,
private static MethodGenerator compileInit(NodeSortRecordGenerator sortRecord,
ConstantPoolGen cpg,
String className)
{
@ -688,7 +672,7 @@ final class Sort extends Instruction implements Closure {
/**
* Compiles a method that overloads NodeSortRecord.extractValueFromDOM()
*/
private static MethodGenerator compileExtract(Vector sortObjects,
private static MethodGenerator compileExtract(Vector<Sort> sortObjects,
NodeSortRecordGenerator sortRecord,
ConstantPoolGen cpg,
String className) {
@ -730,7 +714,7 @@ final class Sort extends Instruction implements Closure {
// Append all the cases for the switch statment
for (int level = 0; level < levels; level++) {
match[level] = level;
final Sort sort = (Sort)sortObjects.elementAt(level);
final Sort sort = sortObjects.elementAt(level);
target[level] = il.append(NOP);
sort.translateSelect(sortRecord, extractMethod);
il.append(ARETURN);

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SyntaxTreeNode.java,v 1.6 2006/06/06 22:34:33 spericas Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
@ -519,9 +516,9 @@ public abstract class SyntaxTreeNode implements Constants {
// references falling out-of-scope inside the for-each element.
// (the cause of which being 'lazy' register allocation for references)
for (int i = 0; i < n; i++) {
if( _contents.get(i) instanceof VariableBase) {
if ( _contents.get(i) instanceof VariableBase) {
final VariableBase var = (VariableBase)_contents.get(i);
var.unmapRegister(methodGen);
var.unmapRegister(classGen, methodGen);
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: Template.java,v 1.2.4.1 2005/09/12 11:30:11 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
@ -63,7 +60,7 @@ public final class Template extends TopLevelElement {
// The list of parameters in this template. This is only used
// for simple named templates.
private Vector _parameters = new Vector();
private Vector<Param> _parameters = new Vector<>();
public boolean hasParams() {
return _parameters.size() > 0;
@ -85,7 +82,7 @@ public final class Template extends TopLevelElement {
_parameters.addElement(param);
}
public Vector getParameters() {
public Vector<Param> getParameters() {
return _parameters;
}

View file

@ -1,6 +1,5 @@
/*
* 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.
@ -17,18 +16,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: VariableBase.java,v 1.5 2005/09/28 13:48:18 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.compiler;
import java.util.Vector;
import com.sun.org.apache.bcel.internal.generic.CHECKCAST;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.Instruction;
import com.sun.org.apache.bcel.internal.generic.InstructionList;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
import com.sun.org.apache.bcel.internal.generic.INVOKESPECIAL;
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
import com.sun.org.apache.bcel.internal.generic.NEW;
import com.sun.org.apache.bcel.internal.generic.PUSH;
@ -36,6 +35,7 @@ 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.NodeSetType;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ResultTreeType;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Type;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.Util;
import com.sun.org.apache.xml.internal.utils.XML11Char;
@ -49,21 +49,18 @@ import com.sun.org.apache.xml.internal.utils.XML11Char;
*/
class VariableBase extends TopLevelElement {
protected QName _name; // The name of the variable.
protected String _escapedName; // The escaped qname of the variable.
protected Type _type; // The type of this variable.
protected boolean _isLocal; // True if the variable is local.
protected LocalVariableGen _local; // Reference to JVM variable
protected Instruction _loadInstruction; // Instruction to load JVM variable
protected QName _name; // The name of the variable.
protected String _escapedName; // The escaped qname of the variable.
protected Type _type; // The type of this variable.
protected boolean _isLocal; // True if the variable is local.
protected LocalVariableGen _local; // Reference to JVM variable
protected Instruction _loadInstruction; // Instruction to load JVM variable
protected Instruction _storeInstruction; // Instruction to load JVM variable
protected Expression _select; // Reference to variable expression
protected String select; // Textual repr. of variable expr.
protected Expression _select; // Reference to variable expression
protected String select; // Textual repr. of variable expr.
// References to this variable (when local)
protected Vector _refs = new Vector(2);
// Dependencies to other variables/parameters (for globals only)
protected Vector _dependencies = null;
protected Vector<VariableRefBase> _refs = new Vector<>(2);
// Used to make sure parameter field is not added twice
protected boolean _ignore = false;
@ -92,7 +89,7 @@ class VariableBase extends TopLevelElement {
public void copyReferences(VariableBase var) {
final int size = _refs.size();
for (int i = 0; i < size; i++) {
var.addReference((VariableRefBase) _refs.get(i));
var.addReference(_refs.get(i));
}
}
@ -112,8 +109,24 @@ class VariableBase extends TopLevelElement {
* Remove the mapping of this variable to a register.
* Called when we leave the AST scope of the variable's declaration
*/
public void unmapRegister(MethodGenerator methodGen) {
public void unmapRegister(ClassGenerator classGen, MethodGenerator methodGen) {
if (_local != null) {
if (_type instanceof ResultTreeType) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
if (classGen.getStylesheet().callsNodeset() && classGen.getDOMClass().equals(MULTI_DOM_CLASS)) {
final int removeDA = cpg.addMethodref(MULTI_DOM_CLASS, "removeDOMAdapter", "(" + DOM_ADAPTER_SIG + ")V");
il.append(methodGen.loadDOM());
il.append(new CHECKCAST(cpg.addClass(MULTI_DOM_CLASS)));
il.append(loadInstruction());
il.append(new CHECKCAST(cpg.addClass(DOM_ADAPTER_CLASS)));
il.append(new INVOKEVIRTUAL(removeDA));
}
final int release = cpg.addInterfaceMethodref(DOM_IMPL_CLASS, "release", "()V");
il.append(loadInstruction());
il.append(new INVOKEINTERFACE(release, 1));
}
_local.setEnd(methodGen.getInstructionList().getEnd());
methodGen.removeLocalVariable(_local);
_refs = null;
@ -126,7 +139,6 @@ class VariableBase extends TopLevelElement {
* the JVM stack.
*/
public Instruction loadInstruction() {
final Instruction instr = _loadInstruction;
if (_loadInstruction == null) {
_loadInstruction = _type.LOAD(_local.getIndex());
}
@ -138,7 +150,6 @@ class VariableBase extends TopLevelElement {
* into this variable.
*/
public Instruction storeInstruction() {
final Instruction instr = _storeInstruction;
if (_storeInstruction == null) {
_storeInstruction = _type.STORE(_local.getIndex());
}

View file

@ -1,6 +1,5 @@
/*
* 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.
@ -17,15 +16,17 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: WithParam.java,v 1.2.4.1 2005/09/12 11:38:01 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.CHECKCAST;
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
import com.sun.org.apache.bcel.internal.generic.INVOKEINTERFACE;
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.bcel.internal.generic.PUSH;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg;
@ -59,6 +60,11 @@ final class WithParam extends Instruction {
*/
private Expression _select;
/**
* Reference to JVM variable holding temporary result tree.
*/
private LocalVariableGen _domAdapter;
/**
* %OPT% This is set to true when the WithParam is used in a CallTemplate
* for a simple named template. If this is true, the parameters are
@ -164,8 +170,13 @@ final class WithParam extends Instruction {
_select.startIterator(classGen, methodGen);
}
// If not, compile result tree from parameter body if present.
// Store result tree into local variable for releasing it later
else if (hasContents()) {
final InstructionList il = methodGen.getInstructionList();
compileResultTree(classGen, methodGen);
_domAdapter = methodGen.addLocalVariable2("@" + _escapedName, Type.ResultTree.toJCType(), il.getEnd());
il.append(DUP);
il.append(new ASTORE(_domAdapter.getIndex()));
}
// If neither are present then store empty string in parameter slot
else {
@ -208,4 +219,26 @@ final class WithParam extends Instruction {
ADD_PARAMETER_SIG)));
il.append(POP); // cleanup stack
}
/**
* Release the compiled result tree.
*/
public void releaseResultTree(ClassGenerator classGen, MethodGenerator methodGen) {
if (_domAdapter != null) {
final ConstantPoolGen cpg = classGen.getConstantPool();
final InstructionList il = methodGen.getInstructionList();
if (classGen.getStylesheet().callsNodeset() && classGen.getDOMClass().equals(MULTI_DOM_CLASS)) {
final int removeDA = cpg.addMethodref(MULTI_DOM_CLASS, "removeDOMAdapter", "(" + DOM_ADAPTER_SIG + ")V");
il.append(methodGen.loadDOM());
il.append(new CHECKCAST(cpg.addClass(MULTI_DOM_CLASS)));
il.append(new ALOAD(_domAdapter.getIndex()));
il.append(new CHECKCAST(cpg.addClass(DOM_ADAPTER_CLASS)));
il.append(new INVOKEVIRTUAL(removeDA));
}
final int release = cpg.addInterfaceMethodref(DOM_IMPL_CLASS, "release", "()V");
il.append(new ALOAD(_domAdapter.getIndex()));
il.append(new INVOKEINTERFACE(release, 1));
_domAdapter = null;
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: AdaptiveResultTreeImpl.java,v 1.2.4.1 2005/09/06 05:52:18 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
@ -1338,4 +1336,11 @@ public class AdaptiveResultTreeImpl extends SimpleResultTreeImpl
}
}
public void release() {
if (_dom != null) {
_dom.release();
_dom = null;
}
super.release();
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: DOMAdapter.java,v 1.2.4.1 2005/09/06 06:07:28 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
@ -56,8 +53,6 @@ public final class DOMAdapter implements DOM {
private short[] _NSmapping = null;
private short[] _NSreverse = null;
private StripFilter _filter = null;
private int _multiDOMMask;
public DOMAdapter(DOM dom,
@ -165,9 +160,7 @@ public final class DOMAdapter implements DOM {
}
}
public void setFilter(StripFilter filter) {
_filter = filter;
}
public void setFilter(StripFilter filter) {}
public DTMAxisIterator getTypedChildren(final int type) {
final int[] reverse = getReverse();
@ -464,4 +457,8 @@ public final class DOMAdapter implements DOM {
public Map<String, Integer> getElementsWithIDs() {
return _dom.getElementsWithIDs();
}
public void release() {
_dom.release();
}
}

View file

@ -1,7 +1,6 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@ -30,8 +29,8 @@ import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
import com.sun.org.apache.xml.internal.dtm.DTMManager;
import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIteratorBase;
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
import com.sun.org.apache.xml.internal.dtm.ref.DTMAxisIterNodeList;
import com.sun.org.apache.xml.internal.dtm.ref.DTMDefaultBase;
import com.sun.org.apache.xml.internal.serializer.SerializationHandler;
import com.sun.org.apache.xml.internal.utils.SuballocatedIntVector;
import java.util.HashMap;
@ -671,4 +670,51 @@ public final class MultiDOM implements DOM {
public Map<String, Integer> getElementsWithIDs() {
return _main.getElementsWithIDs();
}
public void release() {
_main.release();
}
private boolean isMatchingAdapterEntry(DOM entry, DOMAdapter adapter) {
DOM dom = adapter.getDOMImpl();
return (entry == adapter) || (
/*
* Method addDOMAdapter overwrites for AdaptiveResultTreeImpl
* objects the usual entry with an adapter to the nested
* DOM, so we must check this here. See last 'if' statement
* of addDOMAdapter.
*/
(dom instanceof AdaptiveResultTreeImpl) &&
(entry instanceof DOMAdapter) &&
(((AdaptiveResultTreeImpl)dom).getNestedDOM() == ((DOMAdapter)entry).getDOMImpl())
);
}
public void removeDOMAdapter(DOMAdapter adapter) {
_documents.remove(adapter.getDocumentURI(0));
DOM dom = adapter.getDOMImpl();
if (dom instanceof DTMDefaultBase) {
SuballocatedIntVector ids = ((DTMDefaultBase) dom).getDTMIDs();
int idsSize = ids.size();
for (int i = 0; i < idsSize; i++) {
_adapters[ids.elementAt(i) >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
}
} else {
int id = dom.getDocument() >>> DTMManager.IDENT_DTM_NODE_BITS;
if ((id > 0) && (id < _adapters.length) && isMatchingAdapterEntry(_adapters[id], adapter)) {
_adapters[id] = null;
} else {
boolean found = false;
for (int i = 0; i < _adapters.length; i++) {
if (isMatchingAdapterEntry(_adapters[id], adapter)) {
_adapters[i] = null;
found = true;
break;
}
}
}
}
}
}

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@ -17,9 +17,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SAXImpl.java,v 1.5 2005/09/28 13:48:37 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
@ -82,7 +79,7 @@ public final class SAXImpl extends SAX2DTM2
// Namespace prefix-to-uri mapping stuff
private int _uriCount = 0;
private int _prefixCount = 0;
// private int _prefixCount = 0;
// Stack used to keep track of what whitespace text nodes are protected
// by xml:space="preserve" attributes and which nodes that are not.
@ -90,11 +87,11 @@ public final class SAXImpl extends SAX2DTM2
private int _idx = 1;
private boolean _preserve = false;
private static final String XML_STRING = "xml:";
// private static final String XML_STRING = "xml:";
private static final String XML_PREFIX = "xml";
private static final String XMLSPACE_STRING = "xml:space";
private static final String PRESERVE_STRING = "preserve";
private static final String XMLNS_PREFIX = "xmlns";
// private static final String XMLNS_PREFIX = "xmlns";
private static final String XML_URI = "http://www.w3.org/XML/1998/namespace";
private boolean _escaping = true;
@ -123,7 +120,7 @@ public final class SAXImpl extends SAX2DTM2
private BitArray _dontEscape = null;
// The URI to this document
private String _documentURI = null;
// private String _documentURI = null;
static private int _documentURIIndex = 0;
// The owner Document when the input source is DOMSource.
@ -143,8 +140,7 @@ public final class SAXImpl extends SAX2DTM2
// Support for access/navigation through org.w3c.dom API
private Node[] _nodes;
private NodeList[] _nodeLists;
private final static String XML_LANG_ATTRIBUTE =
"http://www.w3.org/XML/1998/namespace:@lang";
// private final static String XML_LANG_ATTRIBUTE = "http://www.w3.org/XML/1998/namespace:@lang";
/**
* Define the origin of the document from which the tree was built
@ -491,6 +487,7 @@ public final class SAXImpl extends SAX2DTM2
/**
* Sets up a translet-to-dom type mapping table
*/
/*
private int[] setupMapping(String[] names, String[] uris, int[] types, int nNames) {
// Padding with number of names, because they
// may need to be added, i.e for RTFs. See copy03
@ -502,6 +499,7 @@ public final class SAXImpl extends SAX2DTM2
}
return result;
}
*/
/**
* Returns the internal type associated with an expanded QName
@ -1230,9 +1228,6 @@ public final class SAXImpl extends SAX2DTM2
*/
public DTMAxisIterator getNamespaceAxisIterator(int axis, int ns)
{
DTMAxisIterator iterator = null;
if (ns == NO_TYPE) {
return EMPTYITERATOR;
}
@ -1546,7 +1541,6 @@ public final class SAXImpl extends SAX2DTM2
*/
public DTMAxisIterator getNthDescendant(int type, int n, boolean includeself)
{
DTMAxisIterator source = (DTMAxisIterator) new TypedDescendantIterator(type);
return new NthDescendantIterator(n);
}
@ -1882,4 +1876,7 @@ public final class SAXImpl extends SAX2DTM2
}
}
public void release() {
_dtmManager.release(this, true);
}
}

View file

@ -1,6 +1,5 @@
/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
*/
/*
* Copyright 1999-2004 The Apache Software Foundation.
@ -17,15 +16,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* $Id: SimpleResultTreeImpl.java,v 1.2.4.1 2005/09/06 10:09:25 pvedula Exp $
*/
package com.sun.org.apache.xalan.internal.xsltc.dom;
import com.sun.org.apache.xalan.internal.xsltc.DOM;
import com.sun.org.apache.xalan.internal.xsltc.StripFilter;
import com.sun.org.apache.xalan.internal.xsltc.TransletException;
import com.sun.org.apache.xml.internal.dtm.Axis;
import com.sun.org.apache.xml.internal.dtm.DTM;
import com.sun.org.apache.xml.internal.dtm.DTMAxisIterator;
@ -1014,4 +1010,12 @@ public class SimpleResultTreeImpl extends EmptySerializer implements DOM, DTM
public void migrateTo(DTMManager manager)
{
}
public void release()
{
if (_documentID != 0) {
_dtmManager.release(this, true);
_documentID = 0;
}
}
}