You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by zo...@apache.org on 2006/06/07 21:55:00 UTC
svn commit: r412509 - in
/xalan/java/trunk/src/org/apache/xalan/xsltc/compiler: FilterExpr.java
FilterParentPath.java
Author: zongaro
Date: Wed Jun 7 12:54:59 2006
New Revision: 412509
URL: http://svn.apache.org/viewvc?rev=412509&view=rev
Log:
Part of fix for XALANJ-2295. Allow a positional predicate on a reference to
the key function to be optimized using DTMAxisIterator.getNodeByPosition.
Reviewed by Christine Li (jycli () ca ! ibm ! com)
Modified:
xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterExpr.java
xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java
Modified: xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterExpr.java
URL: http://svn.apache.org/viewvc/xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterExpr.java?rev=412509&r1=412508&r2=412509&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterExpr.java (original)
+++ xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterExpr.java Wed Jun 7 12:54:59 2006
@@ -1,5 +1,5 @@
/*
- * Copyright 2001-2005 The Apache Software Foundation.
+ * Copyright 2001-2006 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -24,11 +24,12 @@
import org.apache.bcel.generic.ALOAD;
import org.apache.bcel.generic.ASTORE;
import org.apache.bcel.generic.ConstantPoolGen;
-import org.apache.bcel.generic.NEW;
+import org.apache.bcel.generic.ILOAD;
import org.apache.bcel.generic.INVOKEINTERFACE;
import org.apache.bcel.generic.INVOKESPECIAL;
import org.apache.bcel.generic.INVOKESTATIC;
import org.apache.bcel.generic.InstructionList;
+import org.apache.bcel.generic.ISTORE;
import org.apache.bcel.generic.LocalVariableGen;
import org.apache.bcel.generic.NEW;
import org.apache.xalan.xsltc.compiler.util.ClassGenerator;
@@ -95,6 +96,7 @@
*/
public Type typeCheck(SymbolTable stable) throws TypeCheckError {
Type ptype = _primary.typeCheck(stable);
+ boolean canOptimize = _primary instanceof KeyCall;
if (ptype instanceof NodeSetType == false) {
if (ptype instanceof ReferenceType) {
@@ -105,11 +107,14 @@
}
}
- // Type check predicates and turn all optimizations off
+ // Type check predicates and turn all optimizations off if appropriate
int n = _predicates.size();
for (int i = 0; i < n; i++) {
Predicate pred = (Predicate) _predicates.elementAt(i);
- pred.dontOptimize();
+
+ if (!canOptimize) {
+ pred.dontOptimize();
+ }
pred.typeCheck(stable);
}
return _type = Type.NodeSet;
@@ -142,24 +147,7 @@
// If not predicates left, translate primary expression
if (_predicates.size() == 0) {
translate(classGen, methodGen);
- }
- else {
- // Translate predicates from right to left
- final int initCNLI = cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
- "<init>",
- "("+NODE_ITERATOR_SIG+"Z"+
- CURRENT_NODE_LIST_FILTER_SIG +
- NODE_SIG+TRANSLET_SIG+")V");
-
- // Backwards branches are prohibited if an uninitialized object is
- // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
- // We don't know whether this code might contain backwards branches,
- // so we mustn't create the new object until after we've created
- // the suspect arguments to its constructor. Instead we calculate
- // the values of the arguments to the constructor first, store them
- // in temporary variables, create the object and reload the
- // arguments from the temporaries to avoid the problem.
-
+ } else {
// Remove the next predicate to be translated
Predicate predicate = (Predicate)_predicates.lastElement();
_predicates.remove(predicate);
@@ -167,32 +155,92 @@
// Translate the rest of the predicates from right to left
translatePredicates(classGen, methodGen);
- LocalVariableGen nodeIteratorTemp =
- methodGen.addLocalVariable("filter_expr_tmp1",
+ if (predicate.isNthPositionFilter()) {
+ int nthIteratorIdx = cpg.addMethodref(NTH_ITERATOR_CLASS,
+ "<init>",
+ "("+NODE_ITERATOR_SIG+"I)V");
+
+ // Backwards branches are prohibited if an uninitialized object
+ // is on the stack by section 4.9.4 of the JVM Specification,
+ // 2nd Ed. We don't know whether this code might contain
+ // backwards branches, so we mustn't create the new object unti
+
+ // after we've created the suspect arguments to its constructor
+
+ // Instead we calculate the values of the arguments to the
+ // constructor first, store them in temporary variables, create
+ // the object and reload the arguments from the temporaries to
+ // avoid the problem.
+ LocalVariableGen iteratorTemp
+ = methodGen.addLocalVariable("filter_expr_tmp1",
+ Util.getJCRefType(NODE_ITERATOR_SIG),
+ null, null);
+ iteratorTemp.setStart(
+ il.append(new ASTORE(iteratorTemp.getIndex())));
+
+ predicate.translate(classGen, methodGen);
+ LocalVariableGen predicateValueTemp
+ = methodGen.addLocalVariable("filter_expr_tmp2",
+ Util.getJCRefType("I"),
+ null, null);
+ predicateValueTemp.setStart(
+ il.append(new ISTORE(predicateValueTemp.getIndex())));
+
+ il.append(new NEW(cpg.addClass(NTH_ITERATOR_CLASS)));
+ il.append(DUP);
+ iteratorTemp.setEnd(
+ il.append(new ALOAD(iteratorTemp.getIndex())));
+ predicateValueTemp.setEnd(
+ il.append(new ILOAD(predicateValueTemp.getIndex())));
+ il.append(new INVOKESPECIAL(nthIteratorIdx));
+ } else {
+ // Translate predicates from right to left
+ final int initCNLI =
+ cpg.addMethodref(CURRENT_NODE_LIST_ITERATOR,
+ "<init>",
+ "("+NODE_ITERATOR_SIG+"Z"+
+ CURRENT_NODE_LIST_FILTER_SIG +
+ NODE_SIG+TRANSLET_SIG+")V");
+
+ // Backwards branches are prohibited if an uninitialized object
+ // is on the stack by section 4.9.4 of the JVM Specification,
+ // 2nd Ed. We don't know whether this code might contain
+ // backwards branches, so we mustn't create the new object
+ // until after we've created the suspect arguments to its
+ // constructor. Instead we calculate the values of the
+ // arguments to the constructor first, store them in temporary
+ // variables, create the object and reload the arguments from
+ // the temporaries to avoid the problem.
+
+
+ LocalVariableGen nodeIteratorTemp =
+ methodGen.addLocalVariable("filter_expr_tmp1",
Util.getJCRefType(NODE_ITERATOR_SIG),
null, null);
- nodeIteratorTemp.setStart(
- il.append(new ASTORE(nodeIteratorTemp.getIndex())));
+ nodeIteratorTemp.setStart(
+ il.append(new ASTORE(nodeIteratorTemp.getIndex())));
- predicate.translate(classGen, methodGen);
- LocalVariableGen filterTemp =
- methodGen.addLocalVariable("filter_expr_tmp2",
+ predicate.translate(classGen, methodGen);
+ LocalVariableGen filterTemp =
+ methodGen.addLocalVariable("filter_expr_tmp2",
Util.getJCRefType(CURRENT_NODE_LIST_FILTER_SIG),
null, null);
- filterTemp.setStart(il.append(new ASTORE(filterTemp.getIndex())));
+ filterTemp.setStart(
+ il.append(new ASTORE(filterTemp.getIndex())));
- // Create a CurrentNodeListIterator
- il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
- il.append(DUP);
+ // Create a CurrentNodeListIterator
+ il.append(new NEW(cpg.addClass(CURRENT_NODE_LIST_ITERATOR)));
+ il.append(DUP);
- // Initialize CurrentNodeListIterator
- nodeIteratorTemp.setEnd(
- il.append(new ALOAD(nodeIteratorTemp.getIndex())));
- il.append(ICONST_1);
- filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
- il.append(methodGen.loadCurrentNode());
- il.append(classGen.loadTranslet());
- il.append(new INVOKESPECIAL(initCNLI));
+ // Initialize CurrentNodeListIterator
+ nodeIteratorTemp.setEnd(
+ il.append(new ALOAD(nodeIteratorTemp.getIndex())));
+ il.append(ICONST_1);
+ filterTemp.setEnd(il.append(new ALOAD(filterTemp.getIndex())));
+ il.append(methodGen.loadCurrentNode());
+ il.append(classGen.loadTranslet());
+ il.append(new INVOKESPECIAL(initCNLI));
+ }
}
}
}
Modified: xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java
URL: http://svn.apache.org/viewvc/xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java?rev=412509&r1=412508&r2=412509&view=diff
==============================================================================
--- xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java (original)
+++ xalan/java/trunk/src/org/apache/xalan/xsltc/compiler/FilterParentPath.java Wed Jun 7 12:54:59 2006
@@ -150,8 +150,16 @@
il.append(new INVOKEVIRTUAL(incl));
}
- if (!(getParent() instanceof RelativeLocationPath) &&
- !(getParent() instanceof FilterParentPath)) {
+ SyntaxTreeNode parent = getParent();
+
+ boolean parentAlreadyOrdered =
+ (parent instanceof RelativeLocationPath)
+ || (parent instanceof FilterParentPath)
+ || (parent instanceof KeyCall)
+ || (parent instanceof CurrentCall)
+ || (parent instanceof DocumentCall);
+
+ if (!parentAlreadyOrdered) {
final int order = cpg.addInterfaceMethodref(DOM_INTF,
ORDER_ITERATOR,
ORDER_ITERATOR_SIG);
---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org