Patch for XALANJ-2377

VariableBase.removeReference was effectively being used to decrement a reference
counter for local variables.

At one time, XSLTC used to release JVM stack slots as soon as the last
reference to a local variable occurred, but that resulted in a bug if loops
were involved.  So the code was changed to release a local variable slot only
when the containing construct went out of scope - this was done with a call to
VariableBase.unmapRegister from SytaxTreeNode.translateContents.

However, VariableBase.unmapRegister still contained a vestige of the old
reference counting code - it was checking whether any references to the variable
still existed.  In the presence of "Closures," the number of calls to
VariableBase.addReference did not equal the number of calls to
VariableBase.removeReference (for no good reason), so the variable was not
marked by VariableBase.unmapRegister as going out of scope.  This caused later
problems for outlining in org.apache.xalan.xsltc.compiler.util.MethodGenerator.

The fix is to remove VariableBase.removeReference, since XSLTC should no longer
on that to determine whether it can release a variable slot.  The
VariableBase.addReference method remains, however, because XSLTC uses that to
determine whether a variable can be discarded completely.


Reviewed by Christine Li (jycli () ca ! ibm ! com).

diff --git a/src/org/apache/xalan/xsltc/compiler/ParameterRef.java b/src/org/apache/xalan/xsltc/compiler/ParameterRef.java
index 041ba3c..9644ad9 100644
--- a/src/org/apache/xalan/xsltc/compiler/ParameterRef.java
+++ b/src/org/apache/xalan/xsltc/compiler/ParameterRef.java
@@ -82,12 +82,10 @@
 		}
 		else {
 		    il.append(_variable.loadInstruction());
-		    _variable.removeReference(this);
 		}
 	    }
 	    else {
 		il.append(_variable.loadInstruction());
-		_variable.removeReference(this);
 	    }
 	}
 	else {
diff --git a/src/org/apache/xalan/xsltc/compiler/VariableBase.java b/src/org/apache/xalan/xsltc/compiler/VariableBase.java
index 1d6b478..c3f8391 100644
--- a/src/org/apache/xalan/xsltc/compiler/VariableBase.java
+++ b/src/org/apache/xalan/xsltc/compiler/VariableBase.java
@@ -82,14 +82,6 @@
     }
 
     /**
-     * Remove a reference to this variable. Called by VariableRef when this
-     * variable goes out of scope.
-     */
-    public void removeReference(VariableRefBase vref) {
-	_refs.remove(vref);
-    }
-
-    /**
      * Map this variable to a register
      */
     public void mapRegister(MethodGenerator methodGen) {
@@ -105,7 +97,7 @@
      * Called when we leave the AST scope of the variable's declaration
      */
     public void unmapRegister(MethodGenerator methodGen) {
-	if (_refs.isEmpty() && (_local != null)) {
+	if (_local != null) {
 	    _local.setEnd(methodGen.getInstructionList().getEnd());
 	    methodGen.removeLocalVariable(_local);
 	    _refs = null;
diff --git a/src/org/apache/xalan/xsltc/compiler/VariableRef.java b/src/org/apache/xalan/xsltc/compiler/VariableRef.java
index d71ef37..442cdad 100644
--- a/src/org/apache/xalan/xsltc/compiler/VariableRef.java
+++ b/src/org/apache/xalan/xsltc/compiler/VariableRef.java
@@ -68,12 +68,10 @@
 		}
 		else {
 		    il.append(_variable.loadInstruction());
-		    _variable.removeReference(this);
 		}
 	    }
 	    else {
 		il.append(_variable.loadInstruction());
-		_variable.removeReference(this);
 	    }
 	}
 	else {